Skip to content

Need separate gmt.frame files per figure #5280

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

Merged
merged 1 commit into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/gmt_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.<fig> 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);
Expand Down
10 changes: 5 additions & 5 deletions src/inset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.<fig> 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.<fig> 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.<fig> */
fprintf (fp, "%s\n", &Bopts[9]);
fclose (fp);
}
Expand Down