Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pslegend fail ghostscript conversion when using paragraph text mode #486

Closed
RobertVattenfall opened this issue Dec 16, 2020 · 5 comments
Closed

Comments

@RobertVattenfall
Copy link

RobertVattenfall commented Dec 16, 2020

In Julia 1.5.3, and 1.2, and 0.6, with GMT 5.4 or GMT 6.1.1: pslegend produces PS code lacking some function definitions when text is displayed wih paragraph mode (P). This causes Ghostscript to fail. I have traced the errors and missing PS definitions. The errors only occur with Julia-GMT, not with GMT alone. The simple example below only works when gmt_fixpslegend() is added before the pslegend in Julia-GMT (see also attached files):
using GMT

# Fix an error in the PS code when using paragraph mode in pslegend (explanation inside gmt_pslegend_codes_fix.ps)
function gmt_fixpslegend()
   ps_code = open(f -> read(f, String), "gmt_pslegend_codes_fix.ps") # PS code that is missing
   ps_io = open(psfile, "a") # Opens the standard GMT psfile for appending
   write(ps_io, ps_code) # Appends the code
   close(ps_io)
end

psfile = "legend.ps"
gmt("psbasemap -JX20/15 -R0/1/0/1 -BWSNE+t\"Paragraph testing\" -Y2 -X2 -K > $psfile") # Begin map
gmt_fixpslegend()
gmt("pslegend legendtext.dat -JX -R -Dx2/2c+jLB+w10.0c/0 -F+c4p+ggray -O --FONT_ANNOT_PRIMARY=8 >> $psfile")

gmt("psconvert -P -Tf $psfile")

legendtest.zip

I suspect that the issue applies to pstext too, but have not tested this.

@joa-quim
Copy link
Member

Thanks. I'll look at this when I have a bit more time. Note that in modern mode GMT has this l global option to build automatic legends. That should work from GMT.jl but I never tested it (GMT is so huge that I can't test all of it features in Julia wrapper).

@joa-quim
Copy link
Member

Hmm, rather stange. Can reproduce the error, but on the otherend this works fine

psbasemap(J="X20/15", R="0/1/0/1", title="Paragraph testing", P=false)
pslegend!("legendtext.dat", D="x2/2c+jLB+w10.0c/0", F="+c4p+ggray",par=(FONT_ANNOT_PRIMARY=8,), fmt=:pdf, show=1)

@joa-quim
Copy link
Member

OK, if you do this, it works

gmt("psbasemap -JX20/15 -R0/1/0/1 -BWSEN+t\"Paragraph testing\" -K > legend.ps")

gmt("destroy")

gmt("pslegend legendtext.dat -JX20/15 -R0/1/0/1 -Dx2/2c+jLB+w10.0c/0 -F+c4p+ggray -O --FONT_ANNOT_PRIMARY=8 >> legend.ps")

There is something in the pslegend call that does not gets reset at the end of the module (inside the GMT lib) which screws the next time it is called. The gmt("destroy") cleans the GMT lib memory state and so makes it work. The reason why calling pslegend(....) works is because I must have crossed with shit before and have a call to gmt("destroy") at the end of pslegend.jl

@RobertVattenfall
Copy link
Author

That did the trick. I cannot understand why the GMT lib state needs cleaning but at least there is a workaround.
Thanks again.

@joa-quim
Copy link
Member

Think on all the defaults in GMT and how they cam be changed by calls to gmtset or using the --VAR online options. All of that is stored internally in memory. On normal shell calls at the end the program ends and all of it goes away. However, when the lib is called from external programs like, Julia or Matlab, the lib stays in memory and all those defaults charged. At the end of each module call we try to reset the structures that need too but something must be failing and next time one run pslegend its defaults are not initialized to what they should be and error follows. The brute force solution is to call gmr("destroy") that kills the session. And next module will rebuild one but loosing some info that may be interesting to pass between module calls (last value of -R for example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants