Psxy [ERROR]: Found no history for option -J

Hi,

After an upgrade of GMT to v. 6.1.0 I now get an error after executing the following commands:

~$ gmt pscoast -R-180/180/-90/90 -Dc -W -M > world_crude.txt
~$ gmt psxy world_crude.txt -J -R-180/180/-85/85 > test.ps

psxy [ERROR]: Found no history for option -J

For info I’m running GMT on Ubuntu 18.04.1 LTS.

Does anybody know what this may be caused by?

Update: When running the commands within an ordinary terminal window the error message is no longer present. However when running the commands within the RStudio terminal window and also through the RStudio command window (by using the “system()” command option, the error message still appears.

I don’t see any initial -J setting the projection, so the lone -J does not fine a previous setting. Do you have a previous command you are not showing that spell out -J?

Hi again,

No, there are no other -J setting. According to the GMT manual the -J is required for the psxy option, and by specifying the lone -J I presume the default WGS-84 is interpreted to the command? The case is that I have run these command lines with success both on the previous and latest installed versions of GMT (in linux terminal window only). However, I get the error when running the commands through the RStudio environment, which is the final destination for my data. My aim is to run the GMT input through the RStudio command window by utilising the system() option:

system(“gmt pscoast -R-180/180/-90/90 -Dc -W -M > world_crude.txt”,wait=FALSE)
system(“gmt psxy world_crude.txt -J -R-180/180/-85/85 > test.ps”,wait=FALSE)
psxy [ERROR]: Found no history for option -J

However, that gives me the mentioned error. The error is also obtained when running the GMT commands in the RStudio terminal window:

fg@fg-GE70-2PC:~$ gmt pscoast -R-180/180/-90/90 -Dc -W -M > world_crude.txt
fg@fg-GE70-2PC:~$ gmt psxy world_crude.txt -J -R-180/180/-85/85 > test.ps
psxy [ERROR]: Found no history for option -J

The way the -J works is that a -J with no arguments is a short-hand for “Find the most recently used -J option with arguments” in this directory - it does so via the gmt.history file. If there is no such file (they are created and updated by all gmt commands) it means there was no previous -Jargs option in this directory. If so, then you get the message (no history) you got. There has been no change to how the history machinery works. Perhaps you are running the R studio commands in another current directory and there simply is no history to draw on?

Ok, so a workaround for me in this case would be to include the -J default argument in the command line?

Yep, all GMT scripts (classic mode) should spell out the -J argument the first time they are used.

There is this JuliaCall package. It should make it possible to call the entire GMT.jl wrapper from R without any system calls.

Thank you very much for the clarification!

Joaquim, I didn’t know about the JuliaCall package and am curious about it’s use within the R environment:

  1. How is the GTM.jl wrapper activated through the JuliaCall package?
  2. I guess the general command syntax is different from the classic input, as described in your linked Git documentation? Is it possible to apply classic mode input too?
  3. If it is possible for you to show, what would my below example lines of input look like when applying the GMT.jl wrapper?

gmt pscoast -R-180/180/-90/90 -Dc -W -M > world_crude.txt
gmt psxy world_crude.txt -J -R-180/180/-85/85 > test.ps

  1. I don’t know how it works because I never used R. I guess you execute (eval?) a GMT command exactly as you would do by using the GMT.jl directly. That’s how it works when doing the equivalent from Python. But you’ll need to read the docs of the JuliaCall package.

  2. Yes. The Julia wrapper works both in classic and modern mode but the distinction here is more fuzzy since even the classic mode looks a lot like modern.

  3. Still about you example. It has an error like either GMT or Paul have told you. You cannot use -J without first having run another command that had set the projection that you want. There is no default value for -J (well, the Julia wrapper does a lot of guessing and might make you think there is one). In Julia your commands would look like

xy = coast(region=(-180,180,-90,90), res=:crude, shore=true, dump=true);
plot(xy, region=(-180,180,-90,90), proj=:equidist, show=true)

Hi Joaquim, thanks for your reply. I’m really grateful for your efforts to guide and help me out!

  1. I’m open to try out the modern GMT mode and yesterday I tried to install GMT.jl under my linux distribution, but unfortunately without success. Is there an easy way of installation of the package which I have not discovered yet (sudo apt install syntax or likewise)? I tried to follow the build procedure found under:
    https://travis-ci.org/GenericMappingTools/GMT.jl
    but the installation stopped and locked my computer when executing the command:
    make -j && make install
    It proceeded to the 67% mark where it halted:
    [ 67%] Building C object src/CMakeFiles/gmtlib.dir/pslegend.c.o

  2. From the Julia Packcage documentation in RStudio I suppose I have to install the link to the GMT.jl package from the following:
    julia_install_package(pkg_name_or_url)
    But which pkg_name_or_url do you think should be specified as input to the command (either from a download or url)? I tried some options but without success also here.

Frank, the things you need to have installed

  1. GMT. GMT5 still works but many things in GMT.jl are made for GMT6. See the GMT installing instructions to install it in your linux machine.

  2. Julia (install Julia from the generic binaries they serve).

  3. Once you have Julia installed, installing GMT.jl is as simple as doing ] add GMT in the Julia command window.

  4. The R part (JuliaCall) … don’t know but I’m trusting you know how to do that.

Hi again,
I think I’m now getting closer to a solution on my linux installation but get an error message when giving a test command:

julia> using GMT
julia> plot(“filename”, show=true)
ERROR: error compiling common_plot_xyz: error compiling gmt: could not load library “libgmt”
libgmt.so: cannot open shared object file: No such file or directory

Why unix has always to be so complicated?

The error means that the GMT libraries are not being found or some dependency of libgmt.so is broken. When one does using GMT it tests that GMT is available and if not a warning message is printed. Since you didn’t get that I assume it found GMT. Does this print the GMT version number (run it from the Julia command window)?

run(`gmt --version`)

julia> run(gmt --version)
6.1.0_88fbed1_2020.03.06
Process(gmt --version, ProcessExited(0))

So, yes, it does find GMT executable but seems to fail in finding the lib. Maybe a LD_LIBRRY_PATH issue? Does this help (from Julia and adapting for your GMT lib path)?

push!(Libdl.DL_LOAD_PATH, "/path/to/gmt6/lib")

When this is solved there will another thing to fix because 1 or 2 days ago GMT had a breaking change. But let’s leave it for later.

julia> push!(Libdl.DL_LOAD_PATH, “/home/fg/GMT/lib”)
ERROR: UndefVarError: Libdl not defined
Stacktrace:
[1] top-level scope at none:0

Ok, so that recipe no longer works (it did but probably before Julia v1.0). I still think the problem is that since you are installing GMT in a non-standard place linux does not find the library. Try setting LD_LIBRARY_PATH to point to /home/fg/GMT/lib. But you have to do it in a global way. I mean, when Julia is running it has to know the value of that environment variable.

Hi, thanks again. That helped but new issue :frowning::

julia> plot(“filename”, show=true)
gmtread [ERROR]: File filename not found
[Session GMT (0)]: Error returned from GMT API: GMT_FILE_NOT_FOUND (16)
ERROR: Something went wrong when calling the module. GMT error number = 16
Stacktrace:
[1] error(::String, ::Int32) at ./error.jl:42
[2] gmt(::String) at /home/fg/.julia/packages/GMT/IialV/src/gmt_main.jl:241
[3] read_data(::Dict{Symbol,Any}, ::String, ::String, ::Nothing, ::String, ::Bool, ::Bool) at /home/fg/.julia/packages/GMT/IialV/src/common_options.jl:2089
[4] read_data at /home/fg/.julia/packages/GMT/IialV/src/common_options.jl:2076 [inlined]
[5] common_plot_xyz(::String, ::Nothing, ::String, ::Bool, ::Bool, ::Pair{Symbol,Bool}) at /home/fg/.julia/packages/GMT/IialV/src/psxy.jl:49
[6] #plot at /home/fg/.julia/packages/GMT/IialV/src/plot.jl:113 [inlined]
[7] (::getfield(GMT, Symbol("#kw##plot")))(::NamedTuple{(:show,),Tuple{Bool}}, ::typeof(plot), ::String) at ./none:0
[8] top-level scope at none:0

Good.

OFC it errors. when you do that, "filename" must be a name of a file that exists.
Otherwise, you can test it with

plot(rand(10), show=true)

Remember that you need to have ghostscript installed. Here you may also get a Julia crash because GMT introduced a breaking change 2 days ago. I’m in the process of updating GMT.jl to v0.17 that will solve this case, but before that I think you can do
] add GMT#master
to get the master branch where that breaking change is already been taken into account.

It nearly works perfectly

> library(JuliaCall)
> julia <- julia_setup()
Julia version 1.3.0 at location c:\programs\julia-1.3\bin will be used.
Loading setup script for JuliaCall...
Finish loading setup script for JuliaCall.
Warning messages:
1: In readLines(rf) :
  incomplete final line found on 'C:\TMP\RtmpiwDUDr\filea49024533ddf'
2: In readLines(rf) :
  incomplete final line found on 'C:\TMP\RtmpiwDUDr\filea49059e1773c'
> julia_library("GMT")
> julia_eval("xy = coast(region=(-180,180,-90,90), res=:crude, shore=true, dump=true);");
25×2 Array{Float64,2}:
 20.0     79.1594
 18.2831  79.6211
 17.6718  79.3608
...
  • First issue. I can’t make it NOT print the content of the xy variable
> julia_eval("plot(xy, region=(-180,180,-90,90), proj=:equidist, show=true, fmt=:png)");
Error: Error happens in Julia.
IOError: could not spawn `explorer 'C:\TMP\GMTjl_tmp.png'`: bad file descriptor (EBADF)
  • Second issue. It does not display automatically the image, but the file C:\TMP\GMTjl_tmp.png was correctly generated.