From 6e11ade55f57f4872dca13193a2f0969bd08a627 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 12:05:04 -1000 Subject: [PATCH 1/9] Add simple Ctest to make basemap plot See #4518 fro background. --- src/testapi_map.c | 25 +++++++++++++++++++++++++ test/gmtest.in | 1 + 2 files changed, 26 insertions(+) create mode 100644 src/testapi_map.c diff --git a/src/testapi_map.c b/src/testapi_map.c new file mode 100644 index 00000000000..35af6632677 --- /dev/null +++ b/src/testapi_map.c @@ -0,0 +1,25 @@ +#include "gmt.h" +/* Used to examine https://github.com/GenericMappingTools/gmt/issues/4518 + * Set do_jpg = 1 to replicate that, otherwise we make a PS that can be + * compared with the original PS so the test can run as normal. + */ +int main () { + void *API; + int do_jpg = 0; + + /* Initialize the GMT session */ + if ((API = GMT_Create_Session ("GMT_plot", 2, 0, NULL)) == NULL) + return EXIT_FAILURE; + if (do_jpg) + GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "toto_api jpg"); + else + GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "toto_api ps"); + 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"); + if (do_jpg) + GMT_Call_Module (API, "end", GMT_MODULE_CMD, "show"); + else + GMT_Call_Module (API, "end", GMT_MODULE_CMD, NULL); + /* Destroy session */ + if (GMT_Destroy_Session (API)) + return EXIT_FAILURE; +} diff --git a/test/gmtest.in b/test/gmtest.in index 79b862f1a99..81e2be1a8a9 100755 --- a/test/gmtest.in +++ b/test/gmtest.in @@ -80,6 +80,7 @@ for apiprog in \ testapi_cube \ testapi_makecpt \ testapi_matrix \ + testapi_map \ testapi_matrix_plot \ testapi_mixmatrix \ testapi_userdataset \ From 6df3981fab5b9ef59b9d54d2772eb7445418feaf Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 12:18:24 -1000 Subject: [PATCH 2/9] Update gmt_init.c --- src/gmt_init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index c054ec0859d..e1d73e5f827 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -17264,19 +17264,20 @@ GMT_LOCAL int gmtinit_get_graphics_formats (struct GMT_CTRL *GMT, char *formats, } GMT_LOCAL bool gmtinit_check_if_autosize (struct GMTAPI_CTRL *API, int ID) { - /* Check if the BoundingBox line in the half-baked PostScript file has max dimension (32767x32767) + /* Check if the BoundingBox line in the half-baked PostScript file has max dimension (GMT_PAPER_DIM x GMT_PAPER_DIM) * which we used to enforce automatic cropping to actual size [and possible extra margins] */ - char file[PATH_MAX] = {""}; + char file[PATH_MAX] = {""}, def_dim[GMT_LEN32] = {""}; FILE *fp; snprintf (file, PATH_MAX, "%s/gmt_%d.ps-", API->gwf_dir, ID); /* Current half-baked PostScript file */ if ((fp = fopen (file, "r")) == NULL) { /* This is an unmitigated disaster */ GMT_Report (API, GMT_MSG_ERROR, "Failed to open half-baked PostScript file %s\n", file); return false; } + sprintf (def_dim, "%d %d", GMT_PAPER_DIM, GMT_PAPER_DIM); /* Create the comparison string */ gmt_fgets (API->GMT, file, PATH_MAX, fp); /* Skip first line */ gmt_fgets (API->GMT, file, PATH_MAX, fp); /* Get second line with BoundingBox code */ fclose (fp); - if (strstr (file, "32767 32767")) return true; /* Max paper size means auto-sized media */ + if (strstr (file, def_dim)) return true; /* Max paper size means auto-sized media */ return false; } From eae4252e27d221423eea6b17685ce0576e53d857 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 13:41:34 -1000 Subject: [PATCH 3/9] Update --- src/gmt_init.c | 4 ++-- src/testapi_map.c | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index e1d73e5f827..f2ea150b51c 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -16907,7 +16907,7 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign gmt_reload_settings (GMT); /* Initialize the standard GMT system default settings and overload with user's settings */ GMT_Report (API, GMT_MSG_DEBUG, "Exit: gmt_reload_settings\n"); - if (API->runmode) GMT->current.setting.run_mode = GMT_MODERN; /* Enforced at API Creation */ + if (API->runmode) GMT->current.setting.run_mode = GMT_MODERN; /* Enforced at API Creation but set AFTER gmt_reload_settings */ /* There is no longer a -m option in GMT so multi segments are now always true. However, in GMT_COMPAT mode the -mi and -mo options WILL turn off multi in the other direction. */ @@ -17935,7 +17935,7 @@ int gmt_manage_workflow (struct GMTAPI_CTRL *API, unsigned int mode, char *text) gmt_conf (API->GMT); /* Get the original system defaults */ if (!clean_start) gmt_getdefaults (API->GMT, NULL); /* Overload user defaults */ snprintf (dir, PATH_MAX, "%s/%s", API->gwf_dir, GMT_SETTINGS_FILE); /* Reuse dir string for saving gmt.conf to this dir */ - API->GMT->current.setting.run_mode = GMT_MODERN; /* Enable modern mode here so putdefaults can skip writing PS_MEDIA if not PostScript output */ + API->GMT->current.setting.run_mode = GMT_MODERN; /* Enable modern mode here AFTER gmt_conf call so putdefaults can skip writing PS_MEDIA if not PostScript output */ error = gmtinit_put_session_name (API, text); /* Store session name, possibly setting psconvert options */ gmt_putdefaults (API->GMT, dir); /* Write current GMT defaults to this sessions gmt.conf file in the workflow directory */ API->GMT->current.setting.history_orig = API->GMT->current.setting.history; /* Temporarily turn off history so nothing is copied into the workflow dir */ diff --git a/src/testapi_map.c b/src/testapi_map.c index 35af6632677..6100dbd440b 100644 --- a/src/testapi_map.c +++ b/src/testapi_map.c @@ -1,21 +1,20 @@ #include "gmt.h" /* Used to examine https://github.com/GenericMappingTools/gmt/issues/4518 - * Set do_jpg = 1 to replicate that, otherwise we make a PS that can be + * Give an argument to replicate that, otherwise we make a PS that can be * compared with the original PS so the test can run as normal. */ -int main () { +int main (char **argv, int argc) { void *API; - int do_jpg = 0; /* Initialize the GMT session */ - if ((API = GMT_Create_Session ("GMT_plot", 2, 0, NULL)) == NULL) + if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE, NULL)) == NULL) return EXIT_FAILURE; - if (do_jpg) + if (argc > 1) GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "toto_api jpg"); else GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "toto_api ps"); 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"); - if (do_jpg) + if (argc > 1) GMT_Call_Module (API, "end", GMT_MODULE_CMD, "show"); else GMT_Call_Module (API, "end", GMT_MODULE_CMD, NULL); From 17d88e859d59da640ff56a3c7eef3b35433795c5 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 13:42:25 -1000 Subject: [PATCH 4/9] Update testapi_map.c --- src/testapi_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testapi_map.c b/src/testapi_map.c index 6100dbd440b..54608a7ff75 100644 --- a/src/testapi_map.c +++ b/src/testapi_map.c @@ -3,7 +3,7 @@ * Give an argument to replicate that, otherwise we make a PS that can be * compared with the original PS so the test can run as normal. */ -int main (char **argv, int argc) { +int main (int argc, char *argv[]) { void *API; /* Initialize the GMT session */ From 561dbdcbaae5773a03efab2c824a97689faab8bd Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 13:49:08 -1000 Subject: [PATCH 5/9] Asd test script --- src/testapi_map.c | 13 ++++++++----- test/api/apimap.ps | Bin 0 -> 23033 bytes test/api/apimap.sh | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 test/api/apimap.ps create mode 100755 test/api/apimap.sh diff --git a/src/testapi_map.c b/src/testapi_map.c index 54608a7ff75..71fde2cde5f 100644 --- a/src/testapi_map.c +++ b/src/testapi_map.c @@ -1,6 +1,6 @@ #include "gmt.h" /* Used to examine https://github.com/GenericMappingTools/gmt/issues/4518 - * Give an argument to replicate that, otherwise we make a PS that can be + * Give an graphic extension to replicate that, otherwise we make a PS that can be * compared with the original PS so the test can run as normal. */ int main (int argc, char *argv[]) { @@ -9,10 +9,13 @@ int main (int argc, char *argv[]) { /* Initialize the GMT session */ if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE, NULL)) == NULL) return EXIT_FAILURE; - if (argc > 1) - GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "toto_api jpg"); - else - GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "toto_api ps"); + if (argc > 1) { /* Gave a particular graphics format */ + char string[64] = {""}; + sprintf (string, "apimap %s", argv[1]); + GMT_Call_Module (API, "begin", GMT_MODULE_CMD, string); + } + else /* Default to PostScript */ + GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "apimap ps"); 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"); if (argc > 1) GMT_Call_Module (API, "end", GMT_MODULE_CMD, "show"); diff --git a/test/api/apimap.ps b/test/api/apimap.ps new file mode 100644 index 0000000000000000000000000000000000000000..7523ac137b5334d71dd94d9ea4de0b605db45174 GIT binary patch literal 23033 zcmd5^>uwuIvi@y8MF$JxWMN3WQ<8xI$Fd~byO!igvVD?ZAq>fpG}ds2nIUB|g5P8x zVjuB*Usd;X4=;AI8yuWC6lc1wU0qdO-94PA-@Uusc`?q1@lJQQ)p+{!FrR1RB)dJ# z7tc)#{|4=j**oX}^g6kS%T4gz7XBlWTmbVbnWgb_^Xl}0PIKjHN} zyU+5^8EzffSsah!F%-<_#V9VHo0}ZGUdQP}JWEEAW0d6CQ8a^Yr+H@1@&^MI+TG{9 z{pa1bp;|zE8)dii=r(>EKg8*C!>&6ippBlJmuVbjdxyykknxpUJBxy>dS0I_>Fr1LQ7M6FVXZc22rqOH`7a0luE)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020 18:19:52 -1000 Subject: [PATCH 6/9] Let GMT know when in cmdline mode We ahd no wai of distinguishing external C from gmt.c driven module. --- src/gmt.c | 2 +- src/gmt_api.c | 16 +++++++++------- src/gmt_constants.h | 2 ++ src/gmt_init.c | 5 +++-- src/gmt_private.h | 1 + src/testapi_map.c | 4 ++-- test/api/apimap.ps | Bin 23033 -> 23024 bytes 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/gmt.c b/src/gmt.c index 0ea6743277e..ca4b534ae70 100644 --- a/src/gmt.c +++ b/src/gmt.c @@ -90,7 +90,7 @@ int main (int argc, char *argv[]) { gmt_main = !strcmp (module, PROGRAM_NAME); /* true if running the main program, false otherwise */ /* Initialize new GMT session */ - if ((api_ctrl = GMT_Create_Session (argv[0], GMT_PAD_DEFAULT, mode, NULL)) == NULL) + if ((api_ctrl = GMT_Create_Session (argv[0], GMT_PAD_DEFAULT, mode | GMT_SESSION_CMDLINE, NULL)) == NULL) return GMT_RUNTIME_ERROR; api_ctrl->internal = true; /* This is a proper GMT commandline session (external programs will default to false) */ diff --git a/src/gmt_api.c b/src/gmt_api.c index 4100a1ec730..a8201de5ef0 100644 --- a/src/gmt_api.c +++ b/src/gmt_api.c @@ -7739,14 +7739,16 @@ void * GMT_Create_Session (const char *session, unsigned int pad, unsigned int m char *dir = NULL; if ((API = calloc (1, sizeof (struct GMTAPI_CTRL))) == NULL) return_null (NULL, GMT_MEMORY_ERROR); /* Failed to allocate the structure */ - API->verbose = (mode >> 16); /* Pick up any -V settings from gmt.c */ - API->pad = pad; /* Preserve the default pad value for this session */ - API->print_func = (print_func == NULL) ? gmtapi_print_func : print_func; /* Pointer to the print function to use in GMT_Message|Report */ + API->verbose = (mode >> 16); /* Pick up any -V settings from gmt.c */ + API->pad = pad; /* Preserve the default pad value for this session */ + API->print_func = (print_func == NULL) ? gmtapi_print_func : print_func; /* Pointer to the print function to use in GMT_Message|Report */ API->do_not_exit = mode & GMT_SESSION_NOEXIT; /* Deprecated, we no longer call exit anywhere in the API (gmt_api.c) */ - API->external = mode & GMT_SESSION_EXTERNAL; /* if false|0 then we don't list read and write as modules */ - API->shape = (mode & GMT_SESSION_COLMAJOR) ? GMT_IS_COL_FORMAT : GMT_IS_ROW_FORMAT; /* if set then we must use column-major format [row-major] */ - API->runmode = mode & GMT_SESSION_RUNMODE; /* If nonzero we set up modern GMT run-mode, else classic */ - API->no_history = mode & GMT_SESSION_NOHISTORY; /* If nonzero we disable the gmt.history mechanism (shorthands) entirely */ + API->external = mode & GMT_SESSION_EXTERNAL; /* if false|0 then we don't list read and write as modules */ + API->cmdline = mode & GMT_SESSION_CMDLINE; /* if false then we know gmt.c is not involved (external use, such as custom C code) */ + API->shape = (mode & GMT_SESSION_COLMAJOR) ? GMT_IS_COL_FORMAT : GMT_IS_ROW_FORMAT; /* if set then we must use column-major format [row-major] */ + API->runmode = mode & GMT_SESSION_RUNMODE; /* If nonzero we set up modern GMT run-mode, else classic */ + API->no_history = mode & GMT_SESSION_NOHISTORY; /* If nonzero we disable the gmt.history mechanism (shorthands) entirely */ + if (API->internal) API->leave_grid_scaled = 1; /* Do NOT undo grid scaling after write since modules do not reuse grids we save some CPU */ if (session) { /* Pick up a tag for this session */ char *tmptag = strdup (session); diff --git a/src/gmt_constants.h b/src/gmt_constants.h index 2d13b08ffa0..b150e8e30e8 100644 --- a/src/gmt_constants.h +++ b/src/gmt_constants.h @@ -170,6 +170,8 @@ enum GMT_enum_basemap { GMT_BASEMAP_ANNOT_BEFORE = 0, GMT_BASEMAP_ANNOT_AFTER = 4}; +#define GMT_SESSION_CMDLINE 64 /* Passed when GMT_Create_Session is called from the command-line gmt.c driver only */ + /* Since -I is not a global option but we almost use it as such, we define the long-option for it here. * Modules that need it in their module_kw[] array can just add it to their list. */ #define GMT_INCREMENT_KW { '/', 'I', "increment", "", "", "e,n", "exact,number" } diff --git a/src/gmt_init.c b/src/gmt_init.c index f2ea150b51c..63e63a3804c 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -16780,7 +16780,7 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign char *path1 = NULL, *path2 = NULL, *paths[2] = {NULL, NULL}; int local_count = 0; #endif - + unsigned int mode; #ifdef __FreeBSD__ #ifdef _i386_ /* allow divide by zero -- Inf */ @@ -16866,7 +16866,8 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign } GMT_Report (API, GMT_MSG_DEBUG, "Enter: gmt_manage_workflow\n"); - if (gmt_manage_workflow (API, GMT_USE_WORKFLOW, NULL)) { + mode = (API->external && API->runmode) ? GMT_BEGIN_WORKFLOW : GMT_USE_WORKFLOW; /* IF external then no gmt.c driver and only one Create_Session so must init a new session here, if requested */ + if (gmt_manage_workflow (API, mode, NULL)) { GMT_Report (API, GMT_MSG_ERROR, "Could not initialize the GMT workflow - Aborting.\n"); gmtinit_free_GMT_ctrl (GMT); /* Deallocate control structure */ return NULL; diff --git a/src/gmt_private.h b/src/gmt_private.h index b4328553ae8..09edfe89f11 100644 --- a/src/gmt_private.h +++ b/src/gmt_private.h @@ -132,6 +132,7 @@ struct GMTAPI_CTRL { int current_item[2]; /* Array number of current dataset being processed (in and out)*/ unsigned int pad; /* Session default for number of rows/cols padding for grids [2] */ unsigned int external; /* 1 if called via external API (MATLAB, Python) [0] */ + unsigned int cmdline; /* 1 if called via gmt.c [0] */ unsigned int runmode; /* nonzero for GMT modern runmode [0 = classic] */ enum GMT_enum_fmt shape; /* GMT_IS_COL_FORMAT (2) if column-major (MATLAB, Fortran), GMT_IS_ROW_FORMAT (1) if row-major (Python, C/C++) [1] */ unsigned int leave_grid_scaled; /* 1 if we don't want to unpack a grid after we packed it for writing [0] */ diff --git a/src/testapi_map.c b/src/testapi_map.c index 71fde2cde5f..81edcd23c03 100644 --- a/src/testapi_map.c +++ b/src/testapi_map.c @@ -7,7 +7,7 @@ int main (int argc, char *argv[]) { void *API; /* Initialize the GMT session */ - if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE, NULL)) == NULL) + if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE | 458752, NULL)) == NULL) return EXIT_FAILURE; if (argc > 1) { /* Gave a particular graphics format */ char string[64] = {""}; @@ -16,7 +16,7 @@ int main (int argc, char *argv[]) { } else /* Default to PostScript */ GMT_Call_Module (API, "begin", GMT_MODULE_CMD, "apimap ps"); - 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, "basemap", GMT_MODULE_CMD, "-BWESN -Bxa30mg30m -Bya20mg20m -JM7.27/42.27/15c -R5.5/41.425/9.0/43.1r"); if (argc > 1) GMT_Call_Module (API, "end", GMT_MODULE_CMD, "show"); else diff --git a/test/api/apimap.ps b/test/api/apimap.ps index 7523ac137b5334d71dd94d9ea4de0b605db45174..951c6ca8c14b0cc6e718377a8f1728085952ee76 100644 GIT binary patch delta 2160 zcmZ`)yKWRQ6x9eRk%oc-$VxyYi)txWvd12Kk}gs@v@1kJHc)0$P(XvA&HO^pP|~3M zz)Jfad<1_$2^HLjALB6;)0}(GeP7S-UG;NU-Mrmzt-89r+I;?Wv*(T*b1Zjvt9#4c z;c8R$t+nE`KC6{fjgVqlOJM@m$fliQT531Nj5J46td+L#XQeX}USB)e6%M7at%6*< z4fB&iwXKlY8G2TMq-GvZX7A?%w0*rL;8kb0AG zLz6Ntfh9LIFXQSSTUwGsS2Hq!B{y_C;}TeM!xSR7$C3#x$Y=}MN>PPx3di9S z`%fr3w10>QPoaW0E}w2IiZBgdKObET6%ypC=*prhcw7m-z9~VQh;>?=7L_5y!!&7#P+I z*f7-RU+w^5_;!B3hh<$T>%iOGZl(PCOnlskH~haLC&_S$2A+3R=&0a#?>!+)GdU}INzWToU?W*~^oBi9(Ht+A+%Xd}V6wAvGSJ&UZf7#rrj!ko1 z?QYNRb+_!Za(A%0nDwo3>STU8FLdjaR^41HBUo9q)fB7BR!=cgHJP?HjhXUn-AuLp z+*y~2wQ|}*F5ZUuX;s*!nqsB38LzUnnevP^O^P+@Y`#*(@b%>Z^`L`f!T*UmMc6k3 zuw@ETZxXIFDd7^BbESC+x9YK_Ia#`zkO|DW((QyxV9u2(1a6Nd6PlA@0v3o^aqI+v zIoD5(h}w6OCP>4??g}cyWNJU=@|06DPdWGN@x(DtKj(Tp;qt3c53n*xjS@z~@bmSP z9y8}B;at)BMhIA_=g_#NDfzX6wS}iVqI2C5)P(I^$YTalh9~4Dcd!+c}Wby24XHreFy$ zxE%Syu%6F`VYdG9kO-Yx)Z0q`daB-Ds5kWI8Gf&i9>EVt>~^bz9S1%9Ssy;ezfmMa z2RPK>{@EejQ6adI2Oex;9VEYS9QqnVlOZaiOCG9MH0+8LWDtcnP!%xI9tsT-@ Date: Mon, 30 Nov 2020 20:40:28 -1000 Subject: [PATCH 7/9] Finalize --- src/gmt_init.c | 34 +++++++++++++++++++++------------- src/testapi_map.c | 5 +++-- test/api/apimap.ps | Bin 23024 -> 23029 bytes 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index 63e63a3804c..08ff04166fa 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -16865,8 +16865,28 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign return NULL; } + /* Set up hash table for GMT_keywords (used in gmt_conf) */ + + if (gmt_hash_init (GMT, keys_hashnode, GMT_keywords, GMT_N_KEYS, GMT_N_KEYS)) { /* Initialize hash table for GMT defaults */ + gmtinit_free_GMT_ctrl (GMT); /* Deallocate control structure */ + return NULL; + } + + /* Set up hash table for colornames (used to convert to ) */ + + if (gmt_hash_init (GMT, GMT->session.rgb_hashnode, gmt_M_color_name, GMT_N_COLOR_NAMES, GMT_N_COLOR_NAMES)) { + gmtinit_free_GMT_ctrl (GMT); /* Deallocate control structure */ + return NULL; + } + GMT_Report (API, GMT_MSG_DEBUG, "Enter: gmt_manage_workflow\n"); - mode = (API->external && API->runmode) ? GMT_BEGIN_WORKFLOW : GMT_USE_WORKFLOW; /* IF external then no gmt.c driver and only one Create_Session so must init a new session here, if requested */ + if (API->runmode && !API->external && !API->cmdline) { /* Special case */ + /* If external C call then there is no gmt.c driver and only one GMT_Create_Session, so we must init a new session here, if in modern mode */ + mode = GMT_BEGIN_WORKFLOW; + GMT->current.setting.run_mode = GMT_MODERN; /* Set here so we get the benefits of a "gmt module" initialization for PSL */ + } + else /* Regular use */ + mode = GMT_USE_WORKFLOW; if (gmt_manage_workflow (API, mode, NULL)) { GMT_Report (API, GMT_MSG_ERROR, "Could not initialize the GMT workflow - Aborting.\n"); gmtinit_free_GMT_ctrl (GMT); /* Deallocate control structure */ @@ -16892,18 +16912,6 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign gmtinit_init_unit_conversion (GMT); /* Set conversion factors from various units to meters */ - if (gmt_hash_init (GMT, keys_hashnode, GMT_keywords, GMT_N_KEYS, GMT_N_KEYS)) { /* Initialize hash table for GMT defaults */ - gmtinit_free_GMT_ctrl (GMT); /* Deallocate control structure */ - return NULL; - } - - /* Set up hash table for colornames (used to convert to ) */ - - if (gmt_hash_init (GMT, GMT->session.rgb_hashnode, gmt_M_color_name, GMT_N_COLOR_NAMES, GMT_N_COLOR_NAMES)) { - gmtinit_free_GMT_ctrl (GMT); /* Deallocate control structure */ - return NULL; - } - GMT_Report (API, GMT_MSG_DEBUG, "Enter: gmt_reload_settings\n"); gmt_reload_settings (GMT); /* Initialize the standard GMT system default settings and overload with user's settings */ GMT_Report (API, GMT_MSG_DEBUG, "Exit: gmt_reload_settings\n"); diff --git a/src/testapi_map.c b/src/testapi_map.c index 81edcd23c03..7e734dbd9c2 100644 --- a/src/testapi_map.c +++ b/src/testapi_map.c @@ -2,14 +2,15 @@ /* Used to examine https://github.com/GenericMappingTools/gmt/issues/4518 * Give an graphic extension to replicate that, otherwise we make a PS that can be * compared with the original PS so the test can run as normal. + * Run testapi_map jpg to show the result is properly cropped. */ int main (int argc, char *argv[]) { void *API; /* Initialize the GMT session */ if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE | 458752, NULL)) == NULL) - return EXIT_FAILURE; - if (argc > 1) { /* Gave a particular graphics format */ + return EXIT_FAILURE; + if (argc > 1) { /* Gave a particular graphics format (we hope - no checking here) */ char string[64] = {""}; sprintf (string, "apimap %s", argv[1]); GMT_Call_Module (API, "begin", GMT_MODULE_CMD, string); diff --git a/test/api/apimap.ps b/test/api/apimap.ps index 951c6ca8c14b0cc6e718377a8f1728085952ee76..8a68fe3e6ac3e44d012c1af28d70cda4644837fe 100644 GIT binary patch delta 122 zcmeycneppp#tBN=rk17(7A8hqs;VBDL8-+~`K5U&nR)3>`4v_Q20#du*E0YDprVPs z(!6FSsip>riMlD7MJ1IJ^ZPlB46KYzt&EH|voU`6mb0`pG*?JTP2wm4F)%jXEaQ8H2LRuAB+vi= delta 117 zcmeymneoGB#tBN=W`;%z=9WfWs;VBDL8-+~`K5U&nR)3>`4v_Q20#du*E0YDprVPs z((I;YhABxY$rDTaISkFMj7+Qy3^(&Ie)pC)G%x}xN=Z%Q(hmssi7!Y@PmQlE&a6sR OFf<0rY*zHW!UF&ivLe3# From 8e4909d53b2a52adcbf9e7eb68d320efec223181 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 20:47:27 -1000 Subject: [PATCH 8/9] Update testapi_map.c --- src/testapi_map.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/testapi_map.c b/src/testapi_map.c index 7e734dbd9c2..9b99f610577 100644 --- a/src/testapi_map.c +++ b/src/testapi_map.c @@ -3,12 +3,13 @@ * Give an graphic extension to replicate that, otherwise we make a PS that can be * compared with the original PS so the test can run as normal. * Run testapi_map jpg to show the result is properly cropped. + * [add "| 458752" to GMT_SESSION_RUNMODE to simulate -Vd ] */ int main (int argc, char *argv[]) { void *API; /* Initialize the GMT session */ - if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE | 458752, NULL)) == NULL) + if ((API = GMT_Create_Session ("GMT_plot", 2, GMT_SESSION_RUNMODE, NULL)) == NULL) return EXIT_FAILURE; if (argc > 1) { /* Gave a particular graphics format (we hope - no checking here) */ char string[64] = {""}; From e95bc9685b8b89af0368315fb4df254c3a2a2163 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Mon, 30 Nov 2020 21:17:19 -1000 Subject: [PATCH 9/9] Prevent modern mode only module in sessions started without gmt.c --- src/begin.c | 2 ++ src/end.c | 2 ++ src/figure.c | 2 ++ src/gmt_api.c | 9 +++++++++ src/gmt_prototypes.h | 1 + src/inset.c | 2 ++ src/subplot.c | 2 ++ 7 files changed, 20 insertions(+) diff --git a/src/begin.c b/src/begin.c index 88413e0f149..330a6c1959c 100644 --- a/src/begin.c +++ b/src/begin.c @@ -144,6 +144,8 @@ EXTERN_MSC int GMT_begin (void *V_API, int mode, void *args) { /*----------------------- Standard module initialization and parsing ----------------------*/ if (API == NULL) return (GMT_NOT_A_SESSION); + if (gmt_modern_in_classic_session (API, "begin")) /* If not command-line or external it means use of C API directly, so GMT_Create_Session needs to set modern mode first */ + return (GMT_RUNTIME_ERROR); if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ diff --git a/src/end.c b/src/end.c index 1da5ad04456..226f95bea8c 100644 --- a/src/end.c +++ b/src/end.c @@ -94,6 +94,8 @@ EXTERN_MSC int GMT_end (void *V_API, int mode, void *args) { /*----------------------- Standard module initialization and parsing ----------------------*/ if (API == NULL) return (GMT_NOT_A_SESSION); + if (gmt_modern_in_classic_session (API, "end")) /* If not command-line or external it means use of C API directly, so GMT_Create_Session needs to set modern mode first */ + return (GMT_RUNTIME_ERROR); if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ diff --git a/src/figure.c b/src/figure.c index c367c09fa6e..42d2eae9831 100644 --- a/src/figure.c +++ b/src/figure.c @@ -136,6 +136,8 @@ EXTERN_MSC int GMT_figure (void *V_API, int mode, void *args) { /*----------------------- Standard module initialization and parsing ----------------------*/ if (API == NULL) return (GMT_NOT_A_SESSION); + if (gmt_modern_in_classic_session (API, "figure")) /* If not command-line or external it means use of C API directly, so GMT_Create_Session needs to set modern mode first */ + return (GMT_RUNTIME_ERROR); if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ diff --git a/src/gmt_api.c b/src/gmt_api.c index a8201de5ef0..b1b1fb2e43d 100644 --- a/src/gmt_api.c +++ b/src/gmt_api.c @@ -15099,3 +15099,12 @@ int64_t gmt_eliminate_duplicates (struct GMTAPI_CTRL *API, struct GMT_DATASET *D return (n_dup); } + +bool gmt_modern_in_classic_session (struct GMTAPI_CTRL *API, const char *module) { + /* If not commandline or external it means use of C API directly, so GMT_Create_Session needs to set modern mode first */ + if (API->runmode) return false; /* Already in modern mode */ + if (API->external) return false; /* An external call from MATLAB, Julia, or Python */ + if (API->cmdline) return false; /* A standard command-line call via gmt program */ + GMT_Report (API, GMT_MSG_ERROR, "Cannot call module \"%s\" in a classic session created via a call to GMT_Create_Session\n", module); + return true; /* Sorry, calling a modern-mode only module from a classic session started from GMT_Create_Session in a C/C++ program is not allowed */ +} \ No newline at end of file diff --git a/src/gmt_prototypes.h b/src/gmt_prototypes.h index 64292042456..b7960860c0d 100644 --- a/src/gmt_prototypes.h +++ b/src/gmt_prototypes.h @@ -697,6 +697,7 @@ EXTERN_MSC void gmt_polar_to_cart (struct GMT_CTRL *GMT, double r, double theta, EXTERN_MSC void gmt_cart_to_polar (struct GMT_CTRL *GMT, double *r, double *theta, double *a, bool degrees); /* From gmt_api.c */ +EXTERN_MSC bool gmt_modern_in_classic_session (struct GMTAPI_CTRL *API, const char *module); EXTERN_MSC int64_t gmt_eliminate_duplicates (struct GMTAPI_CTRL *API, struct GMT_DATASET *D, uint64_t cols[], uint64_t ncols, bool text); EXTERN_MSC unsigned int gmt_whole_earth (struct GMT_CTRL *GMT, double we_in[], double we_out[]); EXTERN_MSC int gmt_copy (struct GMTAPI_CTRL *API, enum GMT_enum_family family, unsigned int direction, char *ifile, char *ofile); diff --git a/src/inset.c b/src/inset.c index 2d816194c3d..8d360e00342 100644 --- a/src/inset.c +++ b/src/inset.c @@ -225,6 +225,8 @@ EXTERN_MSC int GMT_inset (void *V_API, int mode, void *args) { /*----------------------- Standard module initialization and parsing ----------------------*/ if (API == NULL) return (GMT_NOT_A_SESSION); + if (gmt_modern_in_classic_session (API, "inset")) /* If not command-line or external it means use of C API directly, so GMT_Create_Session needs to set modern mode first */ + return (GMT_RUNTIME_ERROR); if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ diff --git a/src/subplot.c b/src/subplot.c index eb10f6f6d96..6b989d5ad8f 100644 --- a/src/subplot.c +++ b/src/subplot.c @@ -725,6 +725,8 @@ EXTERN_MSC int GMT_subplot (void *V_API, int mode, void *args) { /*----------------------- Standard module initialization and parsing ----------------------*/ if (API == NULL) return (GMT_NOT_A_SESSION); + if (gmt_modern_in_classic_session (API, "subplot")) /* If not command-line or external it means use of C API directly, so GMT_Create_Session needs to set modern mode first */ + return (GMT_RUNTIME_ERROR); if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */