Skip to content

Commit 2436de9

Browse files
PaulWesselseisman
andauthored
Prevent subplot tag changes if not initiated (#4975)
* Check that subplot set -A is overriding a subplot begin -A setup Since subplto set -A is used to override a specific tag for the specified panel, there has to be someting to override, i.e., subplot begin -A must have been set. Closes #4972. * Update subplot.c * Oopos, change of plan and forgot to reinstate * Update doc/rst/source/subplot.rst Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
1 parent 3b399d3 commit 2436de9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

doc/rst/source/subplot.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ Optional Arguments (set mode)
202202
**-A**\ *fixedlabel*
203203
Overrides the automatic labeling with the given string. No modifiers are allowed.
204204
Placement, justification, etc. are all inherited from how **-A** was specified by the
205-
initial **subplot begin** command.
205+
initial **subplot begin** command. **Note**: Overriding means you initiate the tag
206+
machinery with **-A** when **subplot begin** was called, otherwise the option is ignored.
206207

207208
.. _subplot_set-C2:
208209

src/subplot.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,16 @@ EXTERN_MSC int GMT_subplot (void *V_API, int mode, void *args) {
12191219
fclose (fp);
12201220
GMT_Report (API, GMT_MSG_DEBUG, "Subplot: Wrote subplot order to information file %s\n", file);
12211221

1222+
if (Ctrl->A.active) { /* Place an empty file to signal we set up -A */
1223+
sprintf (file, "%s/gmt.tags.%d", API->gwf_dir, fig);
1224+
if ((fp = fopen (file, "w")) == NULL) { /* Not good */
1225+
GMT_Report (API, GMT_MSG_ERROR, "Cannot create file %s\n", file);
1226+
Return (GMT_ERROR_ON_FOPEN);
1227+
}
1228+
fclose (fp);
1229+
GMT_Report (API, GMT_MSG_DEBUG, "Subplot: Wrote tag file %s\n", file);
1230+
}
1231+
12221232
if (Ctrl->F.Lpen[0]) { /* Must draw divider lines between subplots so we need to allocate a dataset */
12231233
uint64_t dim[4] = {1, last_row + last_col, 2, 2}; /* One segment line per interior row/col */
12241234
if ((L = GMT_Create_Data (API, GMT_IS_DATASET, GMT_IS_LINE, 0, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
@@ -1337,6 +1347,13 @@ EXTERN_MSC int GMT_subplot (void *V_API, int mode, void *args) {
13371347
char legend_justification[4] = {""}, pen[GMT_LEN32] = {""}, fill[GMT_LEN32] = {""}, off[GMT_LEN32] = {""};
13381348
double gap[4], legend_width = 0.0, legend_scale = 1.0;
13391349

1350+
if (Ctrl->A.active) { /* Can only override tag settings if subplot begin -A was used */
1351+
sprintf (file, "%s/gmt.tags.%d", API->gwf_dir, fig);
1352+
if (access (file, F_OK)) { /* No such file */
1353+
GMT_Report (API, GMT_MSG_ERROR, "Cannot override tags with -A if it was not set during gmt subplot begin. -A ignored\n");
1354+
Ctrl->A.format[0] = '\0';
1355+
}
1356+
}
13401357
if (gmt_get_legend_info (API, &legend_width, &legend_scale, legend_justification, pen, fill, off)) { /* Unplaced legend file */
13411358
char cmd[GMT_LEN128] = {""};
13421359
if ((P = gmt_subplot_info (API, fig)) == NULL) {
@@ -1411,6 +1428,8 @@ EXTERN_MSC int GMT_subplot (void *V_API, int mode, void *args) {
14111428
gmt_remove_file (GMT, file);
14121429
sprintf (file, "%s/gmt.panel.%d", API->gwf_dir, fig);
14131430
gmt_remove_file (GMT, file);
1431+
sprintf (file, "%s/gmt.tags.%d", API->gwf_dir, fig);
1432+
gmt_remove_file (GMT, file);
14141433
for (row = 0; row < P->nrows; row++) {
14151434
for (col = 0; col < P->ncolumns; col++) {
14161435
gmtlib_panel_B_file (API, fig, row, col, file);

0 commit comments

Comments
 (0)