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

Let the API be aware of modern mode #1142

Closed
PaulWessel opened this issue Jul 10, 2019 · 0 comments
Closed

Let the API be aware of modern mode #1142

PaulWessel opened this issue Jul 10, 2019 · 0 comments

Comments

@PaulWessel
Copy link
Member

How modern mode fails when using the API

It is interesting to simulate API sessions by using testgmtshell. What testgmtshell does is to call GMT_Create_Session, then execute all lines you give it (lines that starts with "gmt" are fed to GMT_Call_Module while the rest are fed to system), and then ends with a GMT_Destroy_Session call. For instance, a simple classic script like this (I called it classic.sh):

gmt pscoast -R0/30/0/30 -JM6i -P -K -Ggreen > t.ps
gmt psbasemap -R -J -O -Baf >> t.ps

can be run this way:

testgmtshell -v < classic.sh

and it will spit out

cmd = [gmt pscoast -R0/30/0/30 -JM6i -P -K -Ggreen > t.ps]
cmd = [gmt psbasemap -R -J -O -Baf >> t.ps]

and the plot t.ps is the same as you get if you run bash classic.sh. However, if we try the equivalent modern script (modern.sh):

gmt begin t ps
	gmt pscoast -R0/30/0/30 -JM6i -Ggreen
	gmt basemap -B
gmt end

then bash modern.sh gives the same plot but

testgmtshell -v < modern.sh

will print

cmd = [gmt begin t ps]
cmd = [ gmt pscoast -R0/30/0/30 -JM6i -Ggreen]
%!PS-Adobe-3.0
%%BoundingBox: 0 0 595 842
.....
end
%%EOF
cmd = [ gmt basemap -B]
TEST [ERROR]: Shared GMT module not found: basemap
TEST [ERROR]: basemap returned error 44

The reason is that GMT_Call_Module does not perform checks to detect that a modern session is running so it defaults to classic and hence the PostSCript goes to stdout and we get errors on modern names.

The API predates modern mode. I think this is @joa-quim issue with the Julia wrapper in a nutshell. We should discuss how we can address this issue. Perhaps we need another API function that can detect and set the right parameters so that a modern mode is detected. Alternatively, perhaps that bit of machinery should happen inside GMT_Call_Module.

PaulWessel added a commit that referenced this issue Jul 10, 2019
Most of ouir experience with GMT_Call_Module is in gmt.c, where it is sandwiched bewteen GMT_Create_Session and GMT_Destroy_Session.  However, direct users of the API, such as the GMT/MATLAB toolbox ,Julia, and potentially PyGMT, may issue many GMT_Call_Module commands between those Session calls. Thus, it is important that GMT_Call_Module can determine if we are in a classic or modern mode session.  Up until now it did not.  At least some of the trouble @joa-quim has in Julia is linked to the need to add extra calls to gmt_manage_session etc to make sure the modern run mode is set.  This PR does away with this and moves the test for modern mode, as well as those pesky one-liner modern mode commands, inside GMT_Call_Module.  ALl tests still pass.
The testgmtshell.c, which I updated a bit, was really helpful in figuring out the details since it can simulate an API multi-command session by being fed strings of GMT and UNIX commands.  Closes #1142.
obaney pushed a commit to obaney/gmt that referenced this issue Aug 18, 2021
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

1 participant