Skip to content

Commit f4b6a41

Browse files
authored
Improve the auto -B settings under modern mode (#4001)
* Improve the auto -B settings under modern modew We already had -B meaning -Baf under modern mode, but several cases were left on the table: -Bz after -B was not processed and gave an error -Bp or -Bs were not recognized for -Bpaf and -Bsaf. Same with -Bsz since the same issue as above. THese cases are now considered. * Update gmt_init.c
1 parent 57d4e14 commit f4b6a41

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/gmt_init.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,7 +3832,7 @@ GMT_LOCAL int gmtinit_parse4_B_option (struct GMT_CTRL *GMT, char *in) {
38323832
}
38333833

38343834
if (out3[0] == '\0') continue; /* No intervals */
3835-
GMT->current.map.frame.set = true; /* Got here so we are setting intervals */
3835+
if (i < GMT_Z) GMT->current.map.frame.set = true; /* Got here so we are setting x/y intervals */
38363836

38373837
/* Parse the annotation/tick info string */
38383838
if (out3[0] == 'c')
@@ -4318,7 +4318,7 @@ GMT_LOCAL int gmtinit_parse5_B_option (struct GMT_CTRL *GMT, char *in) {
43184318
/* Now parse the annotation/tick info string */
43194319

43204320
if (orig_string[0] == '\0') continue; /* Got nothing */
4321-
GMT->current.map.frame.set = true; /* Got here so we are setting intervals */
4321+
if (no < GMT_Z) GMT->current.map.frame.set = true; /* Got here so we are setting intervals */
43224322
if (strstr (orig_string, "pi")) GMT->current.map.frame.axis[no].substitute_pi = true; /* Use pi in formatting labels */
43234323

43244324
gmt_M_memset (string, GMT_BUFSIZ, char);
@@ -15815,7 +15815,7 @@ GMT_LOCAL int gmtinit_parse_proj4 (struct GMT_CTRL *GMT, char *item, char *dest)
1581515815
*/
1581615816
int gmt_parse_common_options (struct GMT_CTRL *GMT, char *list, char option, char *item) {
1581715817

15818-
int error = 0, i = 0; /* The i and i+= GMT_more_than_once are there to avoid compiler warnings... */
15818+
int error = 0, i = 0, q = 0; /* The i and i+= GMT_more_than_once are there to avoid compiler warnings... */
1581915819

1582015820
if (!list || !strchr (list, option)) return (0); /* Not a common option we accept */
1582115821

@@ -15831,28 +15831,29 @@ int gmt_parse_common_options (struct GMT_CTRL *GMT, char *list, char option, cha
1583115831
switch (option) { /* Handle parsing of this option, if allowed here */
1583215832
case 'B':
1583315833
switch (item[0]) { /* Check for -B[p] and -Bs */
15834-
case 's': GMT->common.B.active[GMT_SECONDARY] = true; break;
15834+
case 'p': GMT->common.B.active[GMT_PRIMARY] = true; q = 1; break;
15835+
case 's': GMT->common.B.active[GMT_SECONDARY] = true; q = 1; break;
1583515836
default: GMT->common.B.active[GMT_PRIMARY] = true; break;
1583615837
}
1583715838
if (!error) {
15838-
if (GMT->current.setting.run_mode == GMT_MODERN && !GMT->current.map.frame.set) {
15839+
if (GMT->current.setting.run_mode == GMT_MODERN && (!GMT->current.map.frame.set || item[q] == 'z')) {
1583915840
char code[2], args[GMT_LEN256] = {""}, *c = strchr (item, '+'); /* Start of modifiers, if any */
15840-
if (item[0] && strstr (item, "+f")) GMT->current.plot.calclock.geo.wesn = 1; /* Got +f, so enable W|E|S|N suffices */
15841+
if (item[q] && strstr (item, "+f")) GMT->current.plot.calclock.geo.wesn = 1; /* Got +f, so enable W|E|S|N suffices */
1584115842
if (c && strchr ("aflLsSu", c[1])) /* We got the ones suitable for axes that we can chop off */
1584215843
c[0] = '\0'; /* Temporarily chop off these modifiers only */
15843-
code[0] = item[0]; code[1] = (item[0]) ? item[1] : '\0';
15844+
code[0] = item[q]; code[1] = (item[q]) ? item[q+1] : '\0';
1584415845
if (c) c[0] = '+'; /* Restore modifiers */
1584515846
if (code[0] == '\0') { /* Default is -Baf if nothing given */
15846-
strcpy (args, "af"); if (c) strcat (args, c);
15847+
if (q) args[0] = item[0]; strcat (args, "af"); if (c) strcat (args, c);
1584715848
}
1584815849
else if (code[0] == 'x' && code[1] == '\0') { /* If indicating x we do -Bxaf */
15849-
strcpy (args, "xaf"); if (c) strcat (args, c);
15850+
if (q) args[0] = item[0]; strcat (args, "xaf"); if (c) strcat (args, c);
1585015851
}
1585115852
else if (code[0] == 'y' && code[1] == '\0') { /* If indicating y we do -Byaf */
15852-
strcpy (args, "yaf"); if (c) strcat (args, c);
15853+
if (q) args[0] = item[0]; strcat (args, "yaf"); if (c) strcat (args, c);
1585315854
}
1585415855
else if (code[0] == 'z' && code[1] == '\0') { /* If indicating z we do -Bzaf */
15855-
strcpy (args, "zaf"); if (c) strcat (args, c);
15856+
if (q) args[0] = item[0]; strcat (args, "zaf"); if (c) strcat (args, c);
1585615857
}
1585715858
else /* Keep what we got */
1585815859
strcpy (args, item);

0 commit comments

Comments
 (0)