You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the -J question-mark for subplots and insets optional (#4758)
* Allow the ?-mark for unknow size to be optional
Given the issues with csh discussed in #3916, this PR makes the questionmark optional. It even allows for a lack of final slash.
* Update gmt_init.c
* Implement the more conservative scheme when ? is not present
Require a trailing / if at least one another argument, or otherwise have no numbers after the projection code. Adjusted the demonstration inset script and docs. added complement script that tests -JX without ?.
/* If this -J argument is like the '?' args (but with the '?' missing) and having trailing /, or missing an only arg, then
13810
+
* we append or insert the missing ? so that the gmtinit_build_new_J_option can work as is.
13811
+
* We assume newarg is completely blank. We only get here if there is no ? in arg. */
13812
+
size_t o = 0, i = 0, L = strlen (arg) - 1; /* Index of last character in arg (we know arg has at least length 1) */
13813
+
13814
+
/* Category 1 projections: Always has slashes and need to end in /? */
13815
+
if ((strchr ("cC", arg[0]) && !strncmp (&arg[1], "yl_stere", 8U)) || strchr ("aAbBcCdDeEfFgGlLoOsStT", arg[0])) { /* These projection all must end in / and if no ? then append it */
13816
+
if (arg[L] == '/') /* User followed instructions and left a trailing / */
13817
+
sprintf (newarg, "%s?", arg);
13818
+
else {
13819
+
GMT_Report (API, GMT_MSG_DEBUG, "gmtinit_replace_missing_with_questionmark: -J%s has no trailing slash. Assumed to be a complete geographic projection\n", arg);
13820
+
return false;
13821
+
}
13822
+
}
13823
+
else if ((strchr ("pP", arg[0]) && !strncmp (&arg[1], "oly", 3U)) || strchr ("hHiIjJkKmMnNqQrRvVwWyYuU", arg[0])) { /* These may or may not have a trailing slash */
13824
+
if (arg[L] == '/') { /* Multiple argument so left a trailing / */
13825
+
sprintf (newarg, "%s?", arg);
13826
+
}
13827
+
else { /* Used defaults so here we have things like -JM, -Jkf, or -Jpoly; otherwise it is -JM15c etc (i.e., with argument) */
13828
+
if (L == 0 || (L == 1 && strchr ("kK", arg[0]) && strchr ("fs", arg[1]))) /* No argument, just append ? */
13829
+
sprintf (newarg, "%s?", arg);
13830
+
else {
13831
+
GMT_Report (API, GMT_MSG_DEBUG, "gmtinit_replace_missing_with_questionmark: -J%s has no trailing slash. Assumed to be a complete geographic projection\n", arg);
13832
+
return false;
13833
+
}
13834
+
}
13835
+
}
13836
+
else if (strchr ("xX", arg[0])) { /* Cartesian projection, must worry about separate x and y settings if a slash is found */
13837
+
/* Look for Cartesian -Jx|X[-][d|l|p<pow>][/[-][d|l|p<pow>]] which needs one or two ?-marks to be inserted for the two dummy Cartesian scales.
13838
+
* But don't touch things like -Jx|X[+|-]<number> */
13839
+
newarg[o++] = arg[i++]; /* This is x or X */
13840
+
if (arg[i] && strchr ("-+", arg[i])) newarg[o++] = arg[i++]; /* Placing an optional sign (-Jx has no modifiers) */
13841
+
if (isdigit (arg[i]) || arg[i] == '.') { /* Got -Jx-.5, -JX3c, -JX-2 or similar, do nothing */
13842
+
GMT_Report (API, GMT_MSG_DEBUG, "gmtinit_replace_missing_with_questionmark: -J%s assumed to be a complete Cartesian projection\n", arg);
13843
+
return false;
13844
+
}
13845
+
/* Here we must insert or append one or two ? */
13846
+
newarg[o++] = '?'; /* Insert the first ?-mark */
13847
+
if (strchr (arg, '/')) { /* slash[0] == '/' means we got separate x and y scale args for linear[d]/log/power axes */
13848
+
while (arg[i] != '/') newarg[o++] = arg[i++]; /* Copying any linear[d]/log etc args for x-axis until the slash */
13849
+
newarg[o++] = arg[i++]; /* This is the / */
13850
+
if (arg[i] && strchr ("-+", arg[i])) newarg[o++] = arg[i++]; /* Placing the optional second sign */
13851
+
newarg[o++] = '?'; /* Insert the second ?-mark */
13852
+
while (arg[i]) newarg[o++] = arg[i++]; /* Copying any linear[d]/log etc args for y-axis until the end */
13853
+
}
13854
+
else { /* Just a single scale/width. With ? already appended, check for the log,power,degree args */
13855
+
while (arg[i]) newarg[o++] = arg[i++]; /* Copying any linear[d]/log etc args until the end */
13856
+
}
13857
+
}
13858
+
else if (strchr ("pP", arg[0])) { /* Polar (cylindrical) projection, must insert missing ?-mark if no scale/width given */
13859
+
newarg[o++] = arg[i++]; /* This is p or P */
13860
+
if (isdigit (arg[i]) || arg[i] == '.') { /* Got -Jp.5, -JP15c or similar (there are no signs here */
13861
+
GMT_Report (API, GMT_MSG_DEBUG, "gmtinit_replace_missing_with_questionmark: -J%s assumed to be a complete Polar projection\n", arg);
13862
+
return false;
13863
+
}
13864
+
newarg[o++] = '?'; /* Insert the ?-mark */
13865
+
while (arg[i]) newarg[o++] = arg[i++]; /* Copying any polar modifiers until the end */
13866
+
}
13867
+
GMT_Report (API, GMT_MSG_DEBUG, "Modern mode: First converted -J%s to -J%s.\n", arg, newarg);
if (opt_J == NULL) return false; /* No -J option to update */
13817
-
if ((c = strchr (opt_J->arg, '?')) == NULL) return false; /* No questionmark in the argument to update */
13818
-
strncpy (oldarg, opt_J->arg, GMT_LEN128-1);
13881
+
if (opt_J->arg == NULL || opt_J->arg[0] == '\0') return false; /* No argument to update */
13882
+
if (strchr (opt_J->arg, '?')) /* Found ?, we must go to work, make a copy of oldargs */
13883
+
strncpy (oldarg, opt_J->arg, GMT_LEN128-1);
13884
+
else if (!gmtinit_replace_missing_with_questionmark (API, opt_J->arg, oldarg)) /* Not an argument we should update */
13885
+
/* If an argument with nothing instead of ? then we insert ? so the rest of the function can work */
13886
+
return false;
13819
13887
13888
+
c = strchr (oldarg, '?'); /* Pointer to questionmark in the argument */
13820
13889
/* Here, c[0] is the first question mark (there may be one or two) */
13821
-
if (strchr ("xX", opt_J->arg[0])) { /* Cartesian projection, must worry about separate x and y settings if a slash is found */
13822
-
slash = strchr (opt_J->arg, '/'); /* slash[0] == '/' means we got separate x and y scale args for linear[d]/log/power axes */
13890
+
if (strchr ("xX", oldarg[0])) { /* Cartesian projection, must worry about separate x and y settings if a slash is found */
13891
+
slash = strchr (oldarg, '/'); /* slash[0] == '/' means we got separate x and y scale args for linear[d]/log/power axes */
13823
13892
if (slash && slash[1] == '-') { /* While any negative x-scale will automatically be included, for y we just make sure we scale by -1 if a hyphen is found after the slash */
13824
13893
if (P) P->dir[GMT_Y] = -1; else if (I) Iyscl = -1; /* Only use P or I if defined */
0 commit comments