diff --git a/src/gmt_init.c b/src/gmt_init.c index dd0349d64a6..f6c47cde3b7 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -3588,6 +3588,8 @@ GMT_LOCAL int gmtinit_get_history (struct GMT_CTRL *GMT) { sscanf (value, "%lg %lg", &GMT->current.plot.gridline_spacing[GMT_X], &GMT->current.plot.gridline_spacing[GMT_Y]); else if (option[1] == 'L') /* Read PS layer */ GMT->current.ps.layer = atoi (value); + else if (option[1] == 'N') /* The -J in this history was given with fixed dimensions inside a subplot panel */ + GMT->current.plot.panel.fixed_J = atoi (value); else if (option[1] == 'S') /* Read next sequential color IDs */ sscanf (value, "%d %d", &GMT->current.plot.color_seq_id[0], &GMT->current.plot.color_seq_id[1]); continue; @@ -3668,6 +3670,7 @@ GMT_LOCAL int gmtinit_put_history (struct GMT_CTRL *GMT) { if (GMT->current.plot.gridline_spacing[GMT_X] > 0.0 || GMT->current.plot.gridline_spacing[GMT_Y] > 0.0) /* Save gridline spacing in history */ fprintf (fp, "@G\t%g %g\n", GMT->current.plot.gridline_spacing[GMT_X], GMT->current.plot.gridline_spacing[GMT_Y]); if (GMT->current.ps.layer) fprintf (fp, "@L\t%d\n", GMT->current.ps.layer); /* Write PS layer, if non-zero */ + if (GMT->current.plot.panel.fixed_J) fprintf (fp, "@N\t%d\n", GMT->current.plot.panel.fixed_J); /* Panel -J has fixed dimensions, if non-zero */ if (GMT->current.plot.color_seq_id[0] || GMT->current.plot.color_seq_id[1]) fprintf (fp, "@S\t%d %d\n", GMT->current.plot.color_seq_id[0], GMT->current.plot.color_seq_id[1]); /* Write next sequential color IDs, if non-zero */ fprintf (fp, "END\n"); @@ -3685,6 +3688,7 @@ void gmt_reset_history (struct GMT_CTRL *GMT) { for (int id = 0; id < GMT_N_UNIQUE; id++) { if (GMT->init.history[id]) gmt_M_str_free (GMT->init.history[id]); } + GMT->current.plot.panel.fixed_J = 0; /* Goes with the -J being forgotten */ } /*! . */ @@ -16198,8 +16202,10 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, if ((opt = GMT_Make_Option (API, 'Y', arg)) == NULL) return NULL; /* Failure to make option */ if ((*options = GMT_Append_Option (API, opt, *options)) == NULL) return NULL; /* Failure to append option */ if (gmtinit_build_new_J_option (API, opt_J, P, NULL, is_psrose)) /* Found ?-mark(s) and replaced them */ - GMT->current.plot.panel.no_scaling = 0; + GMT->current.plot.panel.no_scaling = GMT->current.plot.panel.fixed_J = 0; else if (opt_J && strchr (opt_J->arg, '?') == NULL) /* Do not auto-scale but use the given dimensions */ + GMT->current.plot.panel.no_scaling = GMT->current.plot.panel.fixed_J = 1; + else if (opt_J == NULL && GMT->current.plot.panel.fixed_J && !GMT->current.plot.inset.active) /* -J will come from history and was given with fixed dimensions */ GMT->current.plot.panel.no_scaling = 1; } } @@ -16741,6 +16747,7 @@ void gmt_end_module (struct GMT_CTRL *GMT, struct GMT_CTRL *Ccopy) { Ccopy->current.ps.initialize = GMT->current.ps.initialize; Ccopy->current.plot.color_seq_id[0] = GMT->current.plot.color_seq_id[0]; Ccopy->current.plot.color_seq_id[1] = GMT->current.plot.color_seq_id[1]; + Ccopy->current.plot.panel.fixed_J = GMT->current.plot.panel.fixed_J; /* Goes with the -J history above */ /* GMT_COMMON */ diff --git a/src/gmt_types.h b/src/gmt_types.h index 8247c82a9fb..6cad53a348a 100644 --- a/src/gmt_types.h +++ b/src/gmt_types.h @@ -181,6 +181,7 @@ struct GMT_SUBPLOT { unsigned int active; /* 1 if subplot is in effect */ unsigned int first; /* 1 the first time we reach panel, 0 later */ unsigned int no_scaling; /* 1 when we are plotting a scale, bar, etc and not map and don't want to auto-scale plot */ + unsigned int fixed_J; /* 1 if the panel's -J (as stored in history) was given with fixed dimensions, so it must not be rescaled */ unsigned int parallel; /* 1 for axis-parallel annotations [0 for standard] */ unsigned int inside; /* 1 if all annots/ticks are inside panels [0 for outside] */ unsigned int fixed_figure; /* 1 if subplot -Ff gave the figure dimensions, so contents must fit inside them */ diff --git a/test/subplot/fixedJoverlay.sh b/test/subplot/fixedJoverlay.sh new file mode 100644 index 00000000000..f7a88963090 --- /dev/null +++ b/test/subplot/fixedJoverlay.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# In a subplot panel whose map used a fixed-size -J, a module that takes -J from +# history must place a symbol at the same spot as one given the same -J explicitly. +# No baseline: we compare the final position (module origin + symbol) in the PS. +# gmtest gives any script that spells out the modern mode start command a $ps to compare, +# so we spell it via $start (as in subplot_3d_fit.sh). +start=begin +gmt $start fixedJoverlay ps + gmt subplot begin 1x1 -Fs15c/10c -B -BWSne + gmt coast -R10W/5E/35N/44N -JM15c -W1/faint -Dl -c0 + echo -9.14 38.72 | gmt plot -Sc0.3c -Gred -W0.5p -JM15c + echo -9.14 38.72 | gmt plot -Sc0.3c -Gred -W0.5p + gmt subplot end +gmt end +# Print x y of each plotted circle: origin shift (last TM before the module) + symbol position +awk '/ TM$/ {tx = $1; ty = $2} /^%@GMT: gmt plot/ {x0 = tx; y0 = ty} / Sc$/ {print x0 + $2, y0 + $3}' fixedJoverlay.ps > pos.txt +rm -f fixedJoverlay.ps +uniq pos.txt | awk 'END {if (NR != 1) print "circles not at the same place:", NR, "positions"}' > fail