From 82a925d62fee0afc264afd414ffd57a978a9ab13 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Sat, 29 May 2021 10:18:47 -1000 Subject: [PATCH] Need separate gmt.frame files per figure Otherwise information from one completed figure may leak into another, causing small differences. Tests pass, and no difference in the original post. Closes #5279. --- src/gmt_init.c | 4 +++- src/gmt_parse.c | 5 +++-- src/inset.c | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index dabe4b75443..0c3bcb79253 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -18956,6 +18956,7 @@ void gmt_auto_offsets_for_colorbar (struct GMT_CTRL *GMT, double offset[], int j struct GMT_OPTION *opt = NULL; char *c = NULL; unsigned int n_errors = 0; + int fig; FILE *fp = NULL; /* Initialize the default settings before considering any -B history */ gmt_set_undefined_defaults (GMT, 0.0, false); /* Must set undefined to their reference values for now */ @@ -18973,8 +18974,9 @@ void gmt_auto_offsets_for_colorbar (struct GMT_CTRL *GMT, double offset[], int j default: return; break; /* No auto-adjust for the rest */ } GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Determined colorbar side = %c and axis = %c\n", side, axis); + fig = gmt_get_current_figure (GMT->parent); /* Get current figure number */ - snprintf (file, PATH_MAX, "%s/gmt.frame", GMT->parent->gwf_dir); + snprintf (file, PATH_MAX, "%s/gmt.frame.%d", GMT->parent->gwf_dir, fig); if ((fp = fopen (file, "r")) == NULL) { GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "No file %s with frame information - no adjustments made\n", file); return; diff --git a/src/gmt_parse.c b/src/gmt_parse.c index a3050f142d4..33b807a8cf8 100644 --- a/src/gmt_parse.c +++ b/src/gmt_parse.c @@ -281,10 +281,11 @@ GMT_LOCAL int gmtparse_complete_options (struct GMT_CTRL *GMT, struct GMT_OPTION if (!strcmp (GMT_unique_option[k], "B")) B_id = k; /* B_id === 0 but just in case this changes we do this search anyway */ assert (B_id != GMT_NOTSET); /* Safety valve just in case */ check_B = (strncmp (GMT->init.module_name, "psscale", 7U) && strncmp (GMT->init.module_name, "docs", 4U)); - if (GMT->current.setting.run_mode == GMT_MODERN && n_B && check_B) { /* Write gmt.frame file unless module is psscale, overwriting any previous file */ + if (GMT->current.setting.run_mode == GMT_MODERN && n_B && check_B) { /* Write gmt.frame. file unless module is psscale, overwriting any previous file */ char file[PATH_MAX] = {""}; FILE *fp = NULL; - snprintf (file, PATH_MAX, "%s/gmt.frame", GMT->parent->gwf_dir); + int fig = gmt_get_current_figure (GMT->parent); /* Get current figure number */ + snprintf (file, PATH_MAX, "%s/gmt.frame.%d", GMT->parent->gwf_dir, fig); if ((fp = fopen (file, "w")) == NULL) { GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Unable to create file %s\n", file); return (-1); diff --git a/src/inset.c b/src/inset.c index 4f4c798e63f..b2717c256c7 100644 --- a/src/inset.c +++ b/src/inset.c @@ -282,7 +282,7 @@ EXTERN_MSC int GMT_inset (void *V_API, int mode, void *args) { PSL_setorigin (PSL, Ctrl->D.inset.refpoint->x + Ctrl->M.margin[XLO], Ctrl->D.inset.refpoint->y + Ctrl->M.margin[YLO], 0.0, PSL_FWD); /* Shift plot a bit */ /* First get the -B options in place before inset was called */ - sprintf (ffile, "%s/gmt.frame", API->gwf_dir); + sprintf (ffile, "%s/gmt.frame.%d", API->gwf_dir, fig); if ((fp = fopen (ffile, "r")) == NULL) GMT_Report (API, GMT_MSG_INFORMATION, "No file %s with frame information - no adjustments made\n", ffile); else { @@ -340,18 +340,18 @@ EXTERN_MSC int GMT_inset (void *V_API, int mode, void *args) { sprintf (ffile, "%s/%s.%s", API->gwf_dir, GMT_HISTORY_FILE, tag); gmt_remove_file (GMT, ffile); /* Restore the old frame B setting to what it was before inset begin was called, if any */ - if ((fp = fopen (file, "r"))) { /* There is a gmt.frame file */ + if ((fp = fopen (file, "r"))) { /* There is a gmt.frame. file */ while (fgets (Bopts, GMT_LEN256, fp) && strncmp (Bopts, "# FRAME: ", 9U)); /* Wind to reading the frame setting */ gmt_chop (Bopts); - fclose (fp); /* Done reading the gmt.frame file */ + fclose (fp); /* Done reading the gmt.frame. file */ if (!strncmp (Bopts, "# FRAME: ", 9U) && strlen (Bopts) > 9 && Bopts[9]) { /* Got a previously saved -B frame setting */ - sprintf (ffile, "%s/gmt.frame", API->gwf_dir); + sprintf (ffile, "%s/gmt.frame.%d", API->gwf_dir, fig); if ((fp = fopen (ffile, "w")) == NULL) { /* Not good */ GMT_Report (API, GMT_MSG_ERROR, "Cannot create frame file %s\n", ffile); Return (GMT_ERROR_ON_FOPEN); } GMT_Report (API, GMT_MSG_DEBUG, "inset: Restore previous frame in %s\n", ffile); - /* Restore the previous frame setting in gmt.frame */ + /* Restore the previous frame setting in gmt.frame. */ fprintf (fp, "%s\n", &Bopts[9]); fclose (fp); }