Skip to content

Commit 3e5eabb

Browse files
Esteban82joa-quim
andauthored
Add default reference point for map rose ( -Td and -Tm) (#9074)
* Update files * Update src/gmt_support.c Co-authored-by: Joaquim <jmfluis@gmail.com> --------- Co-authored-by: Joaquim <jmfluis@gmail.com>
1 parent 0644cf9 commit 3e5eabb

3 files changed

Lines changed: 43 additions & 8 deletions

File tree

doc/rst/source/explain_-T_rose.rst_

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**-Td**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+f**\|\ **F**\ [*level*]]\ [**+j**\ *justify*]\
1+
**-Td**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ [*refpoint*]\ [**+f**\|\ **F**\ [*level*]]\ [**+j**\ *justify*]\
22
[**+l**\ [*w,e,s,n*]][**+o**\ *dx*\ [/*dy*]]\ [**+w**\ *width*]
33

44
Draw a map directional rose on the map at the location defined by the reference (*refpoint*) and anchor point
@@ -7,6 +7,9 @@
77

88
.. include:: explain_refpoint.rst_
99

10+
If *refpoint* is omitted, the directional rose is placed by default in the upper-right corner of the map
11+
(using **+jTR**).
12+
1013
The following optional modifiers can be appended to |-T|\ **d**, with additional explanation and
1114
examples provided in the :ref:`Placing-dir-map-roses` cookbook section. Optionally, use |-F| to place a panel
1215
behind the directional rose.
@@ -29,7 +32,7 @@
2932

3033
For further information, see the Map Embellishment section on :ref:`Directional Roses <Placing-dir-map-roses>`.
3134

32-
**-Tm**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+d**\ *dec*\ [/\ *dlabel*]]]\ [**+i**\ *pen*]\
35+
**-Tm**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ [*refpoint*]\ [**+d**\ *dec*\ [/\ *dlabel*]]]\ [**+i**\ *pen*]\
3336
[**+j**\ *justify*][**+l**\ [*w,e,s,n*]][**+p**\ *pen*]\ [**+t**\ *ints*][**+o**\ *dx*\ [/*dy*]]\ [**+w**\ *width*]
3437

3538
Draw a map magnetic rose on the map at the location defined by the reference (*refpoint*) and anchor point
@@ -38,6 +41,9 @@
3841

3942
.. include:: explain_refpoint.rst_
4043

44+
If *refpoint* is omitted, the directional rose is placed by default in the upper-right corner of the map
45+
(using **+jTR**).
46+
4147
The following optional modifiers can be appended to |-T|\ **m**, with additional explanation and
4248
examples provided in the :ref:`Placing-mag-map-roses` cookbook section. Optionally, use |-F| to place a panel
4349
behind the magnetic rose.

src/gmt_support.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4973,8 +4973,17 @@ GMT_LOCAL int gmtsupport_getrose_old (struct GMT_CTRL *GMT, char option, char *t
49734973
snprintf (string, GMT_LEN256, "x%s/%s", txt_a, txt_b);
49744974
else /* Set up ancher in geographical coordinates */
49754975
snprintf (string, GMT_LEN256, "g%s/%s", txt_a, txt_b);
4976-
if ((ms->refpoint = gmt_get_refpoint (GMT, string, option)) == NULL) {
4977-
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map rose reference point was not accepted\n", option);
4976+
char default_ref[GMT_LEN256];
4977+
/* If no reference point is provided (it starts with '+' or is empty), use jTR by default */
4978+
if (text[1] == '+' || text[1] == '\0') {
4979+
snprintf(default_ref, GMT_LEN256, "jTR%s", &text[1]);
4980+
ms->refpoint = gmt_get_refpoint(GMT, default_ref, option);
4981+
} else {
4982+
ms->refpoint = gmt_get_refpoint(GMT, &text[1], option);
4983+
}
4984+
4985+
if (ms->refpoint == NULL) {
4986+
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map rose reference point was not accepted\n", option);
49784987
gmt_refpoint_syntax (GMT, "Td|m", NULL, GMT_ANCHOR_MAPROSE, 3);
49794988
return (1); /* Failed basic parsing */
49804989
}
@@ -14280,19 +14289,37 @@ int gmt_getrose (struct GMT_CTRL *GMT, char option, char *text, struct GMT_MAP_R
1428014289
char txt_a[GMT_LEN256] = {""}, string[GMT_LEN256] = {""};
1428114290
struct GMT_MAP_PANEL *save_panel = ms->panel; /* In case it was set and we wipe it below with gmt_M_memset */
1428214291

14283-
/* SYNTAX is -Td|m[g|j|n|x]<refpoint>[+w<width>][+f|F[<kind>]][+i<pen>][+j<justify>][+l<w,e,s,n>][+m[<dec>[/<dlabel>]]][+o<dx>[/<dy>]][+p<pen>][+t<ints>]
14292+
/* SYNTAX is -Td|m[g|j|n|x][<refpoint>][+w<width>][+f|F[<kind>]][+i<pen>][+j<justify>][+l<w,e,s,n>][+m[<dec>[/<dlabel>]]][+o<dx>[/<dy>]][+p<pen>][+t<ints>]
1428414293
* 1) +f: fancy direction rose, <kind> = 1,2,3 which is the level of directions [1]. Use +F to flip W/E/S/N so readable from south
1428514294
* 2) Tm: magnetic rose. Optionally, append +d<dec>[/<dlabel>], where <dec> is magnetic declination and dlabel its label [no declination info].
1428614295
* If -Tm, optionally set annotation interval with +t
1428714296
*/
1428814297

1428914298
if (!text || text[0] == '\0') {
14290-
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: No argument given\n", option);
14299+
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: No argument given\n ", option);
1429114300
return GMT_PARSE_ERROR;
1429214301
}
1429314302
gmt_M_memset (ms, 1, struct GMT_MAP_ROSE);
1429414303
ms->panel = save_panel; /* In case it is not NULL */
14295-
if (!strstr (text, "+w") && (strchr ("gjn", text[1]) == NULL || strchr ("fm", text[1]))) return gmtsupport_getrose_old (GMT, option, text, ms); /* Most likely old-style args */
14304+
14305+
/* Inject default reference point (jTR) if omitted by user --- */
14306+
char refpoint_str[GMT_LEN256];
14307+
char *parse_text = text;
14308+
/* If the user omitted the reference point (e.g., -Td or -Tm), inject a default one (jTR = Top-Right inside) */
14309+
if (text[0] == 'd' || text[0] == 'm') {
14310+
if (text[1] == '+' || text[1] == '\0') {
14311+
snprintf(refpoint_str, GMT_LEN256-1, "%cjTR%s", text[0], &text[1]);
14312+
parse_text = refpoint_str;
14313+
}
14314+
}
14315+
/* Determine if we should fallback to the old-style parser.*/
14316+
if (parse_text[0] != 'd' && !strstr(parse_text, "+w")) {
14317+
char c = parse_text[1];
14318+
/* Old syntax starts with f, m, x, or numeric coordinates */
14319+
if (c == 'f' || c == 'm' || c == 'x' || isdigit((unsigned char)c) || c == '-' || c == '.') {
14320+
return gmtsupport_getrose_old(GMT, option, parse_text, ms);
14321+
}
14322+
}
1429614323

1429714324
/* Assign default values */
1429814325
ms->type = GMT_ROSE_DIR_PLAIN;
@@ -14308,7 +14335,7 @@ int gmt_getrose (struct GMT_CTRL *GMT, char option, char *text, struct GMT_MAP_R
1430814335
return (-1);
1430914336
break;
1431014337
}
14311-
if ((ms->refpoint = gmt_get_refpoint (GMT, &text[1], option)) == NULL) {
14338+
if ((ms->refpoint = gmt_get_refpoint (GMT, &parse_text[1], option)) == NULL) {
1431214339
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map rose reference point was not accepted\n", option);
1431314340
gmt_refpoint_syntax (GMT, "Td|m", NULL, GMT_ANCHOR_MAPROSE, 3);
1431414341
return (1); /* Failed basic parsing */

src/psbasemap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
126126
gmt_mapscale_syntax (API->GMT, 'L', "Draw a map scale at specified reference point.");
127127
GMT_Option (API, "O,P");
128128
gmt_maprose_syntax (API->GMT, 'd', "Draw a north-pointing directional map rose at specified reference point.");
129+
GMT_Usage (API, -2, "If <refpoint> is omitted, it defaults to the top-right corner inside the map frame.");
129130
gmt_maprose_syntax (API->GMT, 'm', "Draw a north-pointing magnetic map rose at specified reference point.");
131+
GMT_Usage (API, -2, "If <refpoint> is omitted, it defaults to the top-right corner inside the map frame.");
130132
GMT_Option (API, "U,V,X,c,f,p,t,.");
131133

132134
return (GMT_MODULE_USAGE);

0 commit comments

Comments
 (0)