API does not produce the same plot as script

Take this simple script:


gmt begin toto jpg
gmt basemap -BWESN -Bxa30mg30m -Bya20mg20m -JM7.266666666666667/42.266666666666666/16.24691358024691c -R5.5249999999999995/41.425/8.991666666666665/43.09166666666667r
gmt end show

resulting in this image:

The same instructions via the API:


int main () {
void *API;

/* Initialize the GMT session */
if ((API = GMT_Create_Session ("GMT_plot", 2, 0, NULL)) == NULL)
   return EXIT_FAILURE;
GMT_Call_Module(API, "begin", GMT_MODULE_CMD, "toto jpg");
GMT_Call_Module(API, "basemap", GMT_MODULE_CMD, "-BWESN -Bxa30mg30m -Bya20mg20m -JM7.27/42.27/16.25c -R5.5/41.425/9.0/43.1r");
GMT_Call_Module(API, "end", GMT_MODULE_CMD, "show");
/* Destroy session */
if (GMT_Destroy_Session (API)) 
  return EXIT_FAILURE;
}

produce a different image, not cropped:

Why? Am I doing anything wrong?

That is expected. In the script the show makes a call to psconvert -A that crops the white.

Thank you for your reply.
But the C program also calls gmt end with the show option (which works: the image appears as I show in my first post), so I still don’t understand why the figure is not cropped.
Furthermore, the doc says that a call to gmt end “finalizes the processing of all registered figures”, and that show just “opens all graphics produced by the session”.

Sorry, hadn’t look very careful to your C example. Can you add a -Vd to your command?
Apparently need to debug gmt_init.c #L1786-89 to see why strcat (cmd, " -A"); is not being set.

				if (not_PS && auto_size && !gmtinit_A_was_given (API->GMT->current.setting.ps_convert))	/* Must always add -A if not PostScript unless when media size is given */
					strcat (cmd, " -A");
			}
			else if (not_PS && auto_size) /* No specific settings but must always add -A if not PostScript unless when media size is given */
				strcat (cmd, " -A");

You are right, the -A option seems not to be caught, event if I add A in the gmt begin call (see the line starting with an arrow).


begin [INFORMATION]: Creating a workflow directory /home/sarzeaud/.gmt/sessions/gmt_session.1857
begin [DEBUG]: The PROJ_GEODESIC set to Vincenty
end [DEBUG]: End Workflow.  Session ID = 1857. Directory /home/sarzeaud/.gmt/sessions/gmt_session.1857 removed.
end [DEBUG]: No figure file /home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt.figures - nothing to do
end [DEBUG]: No figure file /home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt.figures - nothing to do
end [DEBUG]: Got session name as toto and default graphics formats as jpg
end [INFORMATION]: Process GMT figure queue: 1 figures found
end [INFORMATION]: Processing GMT figure #0 [toto jpg ]
end [DEBUG]: gmtlib_get_graphics_item: Fig: 0 Subplot: 2 Panel: () Inset: 0
--> end [DEBUG]: psconvert: '/home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt_0.ps-' -Tj -Ftoto
end [DEBUG]: GMT now running in modern mode [Session ID = 1857]
end [DEBUG]: Revised options: '/home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt_0.ps-' -Tj -Ftoto
end (gmtlib_free_tmp_arrays): tried to free unallocated memory
psconvert [DEBUG]: gmt_check_executable: Pass to popen: [gs --version 2> /dev/null]
psconvert [DEBUG]: gs --version 2> /dev/null was successful
psconvert [DEBUG]: Ghostscript version: 9.26
psconvert [DEBUG]: Complete partial PS file /home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt_0.ps-
psconvert [DEBUG]: Size of half-baked PS file = 23021.
psconvert [DEBUG]: Fattened up PS file /home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt_0.ps-
psconvert [INFORMATION]: Processing /home/sarzeaud/.gmt/sessions/gmt_session.1857/gmt_0.ps-...
psconvert [DEBUG]: Your gs is older than 9.53 so we must replace .setfillconstantalpha with .setopacityalpha.
psconvert [INFORMATION]: Convert to JPG...
psconvert [DEBUG]: Running: gs -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=4 -sDEVICE=jpeg -dJPEGQ=90 -g2480x3509 -r300 -sOutputFile='toto.jpg' '/home/sarzeaud/.gmt/sessions/gmt_session.1857/psconvert_12629d.eps'
psconvert [DEBUG]: Delete /home/sarzeaud/.gmt/sessions/gmt_session.1857/psconvert_12629d.eps
psconvert [DEBUG]: Final input buffer length was 256
psconvert (gmtlib_free_tmp_arrays): tried to free unallocated memory
end [DEBUG]: GMT now running in modern mode [Session ID = 1857]
end [DEBUG]: Revised options: toto.jpg
end (gmtlib_free_tmp_arrays): tried to free unallocated memory
docs [DEBUG]: Opening local file toto.jpg via xdg-open
docs (gmtlib_free_tmp_arrays): tried to free unallocated memory
end [INFORMATION]: Destroying the current workflow directory /home/sarzeaud/.gmt/sessions/gmt_session.1857
end [DEBUG]: Delete gmt.canvas.0
end [DEBUG]: Delete gmt.conf
end [DEBUG]: Delete gmt.frame
end [DEBUG]: Delete gmt.layers.0
end [DEBUG]: Delete gmt.session
end [DEBUG]: Delete gmt_0.ps-
end (gmtlib_free_tmp_arrays): tried to free unallocated memory

Thanks. Can you please open an issue with this case and info?

I have just opened an issue, thanks for the help.