From 2cd99cffa5c1f5c8989e6361947a5aad0e680657 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Fri, 26 Jun 2026 10:13:08 -0300 Subject: [PATCH 1/2] Update files --- doc/rst/source/explain_-T_rose.rst_ | 10 ++++++-- src/gmt_support.c | 39 ++++++++++++++++++++++++----- src/psbasemap.c | 2 ++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/doc/rst/source/explain_-T_rose.rst_ b/doc/rst/source/explain_-T_rose.rst_ index c6957202a2a..0d145cbfe5b 100644 --- a/doc/rst/source/explain_-T_rose.rst_ +++ b/doc/rst/source/explain_-T_rose.rst_ @@ -1,4 +1,4 @@ -**-Td**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+f**\|\ **F**\ [*level*]]\ [**+j**\ *justify*]\ +**-Td**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ [*refpoint*]\ [**+f**\|\ **F**\ [*level*]]\ [**+j**\ *justify*]\ [**+l**\ [*w,e,s,n*]][**+o**\ *dx*\ [/*dy*]]\ [**+w**\ *width*] Draw a map directional rose on the map at the location defined by the reference (*refpoint*) and anchor point @@ -7,6 +7,9 @@ .. include:: explain_refpoint.rst_ + If *refpoint* is omitted, the directional rose is placed by default in the upper-right corner of the map + (using **+jTR**). + The following optional modifiers can be appended to |-T|\ **d**, with additional explanation and examples provided in the :ref:`Placing-dir-map-roses` cookbook section. Optionally, use |-F| to place a panel behind the directional rose. @@ -29,7 +32,7 @@ For further information, see the Map Embellishment section on :ref:`Directional Roses `. -**-Tm**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+d**\ *dec*\ [/\ *dlabel*]]]\ [**+i**\ *pen*]\ +**-Tm**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ [*refpoint*]\ [**+d**\ *dec*\ [/\ *dlabel*]]]\ [**+i**\ *pen*]\ [**+j**\ *justify*][**+l**\ [*w,e,s,n*]][**+p**\ *pen*]\ [**+t**\ *ints*][**+o**\ *dx*\ [/*dy*]]\ [**+w**\ *width*] Draw a map magnetic rose on the map at the location defined by the reference (*refpoint*) and anchor point @@ -38,6 +41,9 @@ .. include:: explain_refpoint.rst_ + If *refpoint* is omitted, the directional rose is placed by default in the upper-right corner of the map + (using **+jTR**). + The following optional modifiers can be appended to |-T|\ **m**, with additional explanation and examples provided in the :ref:`Placing-mag-map-roses` cookbook section. Optionally, use |-F| to place a panel behind the magnetic rose. diff --git a/src/gmt_support.c b/src/gmt_support.c index b27d51e2a47..4d2c0899766 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -4973,8 +4973,17 @@ GMT_LOCAL int gmtsupport_getrose_old (struct GMT_CTRL *GMT, char option, char *t snprintf (string, GMT_LEN256, "x%s/%s", txt_a, txt_b); else /* Set up ancher in geographical coordinates */ snprintf (string, GMT_LEN256, "g%s/%s", txt_a, txt_b); - if ((ms->refpoint = gmt_get_refpoint (GMT, string, option)) == NULL) { - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map rose reference point was not accepted\n", option); + char default_ref[GMT_LEN256]; + /* If no reference point is provided (it starts with '+' or is empty), use jTR by default */ + if (text[1] == '+' || text[1] == '\0') { + snprintf(default_ref, GMT_LEN256, "jTR%s", &text[1]); + ms->refpoint = gmt_get_refpoint(GMT, default_ref, option); + } else { + ms->refpoint = gmt_get_refpoint(GMT, &text[1], option); + } + + if (ms->refpoint == NULL) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map rose reference point was not accepted\n", option); gmt_refpoint_syntax (GMT, "Td|m", NULL, GMT_ANCHOR_MAPROSE, 3); return (1); /* Failed basic parsing */ } @@ -14280,19 +14289,37 @@ int gmt_getrose (struct GMT_CTRL *GMT, char option, char *text, struct GMT_MAP_R char txt_a[GMT_LEN256] = {""}, string[GMT_LEN256] = {""}; struct GMT_MAP_PANEL *save_panel = ms->panel; /* In case it was set and we wipe it below with gmt_M_memset */ - /* SYNTAX is -Td|m[g|j|n|x][+w][+f|F[]][+i][+j][+l][+m[[/]]][+o[/]][+p][+t] + /* SYNTAX is -Td|m[g|j|n|x][][+w][+f|F[]][+i][+j][+l][+m[[/]]][+o[/]][+p][+t] * 1) +f: fancy direction rose, = 1,2,3 which is the level of directions [1]. Use +F to flip W/E/S/N so readable from south * 2) Tm: magnetic rose. Optionally, append +d[/], where is magnetic declination and dlabel its label [no declination info]. * If -Tm, optionally set annotation interval with +t */ if (!text || text[0] == '\0') { - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: No argument given\n", option); + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: No argument given\n ", option); return GMT_PARSE_ERROR; } gmt_M_memset (ms, 1, struct GMT_MAP_ROSE); ms->panel = save_panel; /* In case it is not NULL */ - 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 */ + + /* Inject default reference point (jTR) if omitted by user --- */ + char refpoint_str[GMT_LEN256]; + char *parse_text = text; + /* If the user omitted the reference point (e.g., -Td or -Tm), inject a default one (jTR = Top-Right inside) */ + if (text[0] == 'd' || text[0] == 'm') { + if (text[1] == '+' || text[1] == '\0') { + snprintf(refpoint_str, GMT_LEN256, "%cjTR%s", text[0], &text[1]); + parse_text = refpoint_str; + } + } + /* Determine if we should fallback to the old-style parser.*/ + if (parse_text[0] != 'd' && !strstr(parse_text, "+w")) { + char c = parse_text[1]; + /* Old syntax starts with f, m, x, or numeric coordinates */ + if (c == 'f' || c == 'm' || c == 'x' || isdigit((unsigned char)c) || c == '-' || c == '.') { + return gmtsupport_getrose_old(GMT, option, parse_text, ms); + } + } /* Assign default values */ 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 return (-1); break; } - if ((ms->refpoint = gmt_get_refpoint (GMT, &text[1], option)) == NULL) { + if ((ms->refpoint = gmt_get_refpoint (GMT, &parse_text[1], option)) == NULL) { GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map rose reference point was not accepted\n", option); gmt_refpoint_syntax (GMT, "Td|m", NULL, GMT_ANCHOR_MAPROSE, 3); return (1); /* Failed basic parsing */ diff --git a/src/psbasemap.c b/src/psbasemap.c index 77ecd5c0b81..f2ceae43645 100644 --- a/src/psbasemap.c +++ b/src/psbasemap.c @@ -126,7 +126,9 @@ static int usage (struct GMTAPI_CTRL *API, int level) { gmt_mapscale_syntax (API->GMT, 'L', "Draw a map scale at specified reference point."); GMT_Option (API, "O,P"); gmt_maprose_syntax (API->GMT, 'd', "Draw a north-pointing directional map rose at specified reference point."); + GMT_Usage (API, -2, "If is omitted, it defaults to the top-right corner inside the map frame."); gmt_maprose_syntax (API->GMT, 'm', "Draw a north-pointing magnetic map rose at specified reference point."); + GMT_Usage (API, -2, "If is omitted, it defaults to the top-right corner inside the map frame."); GMT_Option (API, "U,V,X,c,f,p,t,."); return (GMT_MODULE_USAGE); From 3828b7c565680fe8d7735f61663d6d8b8427be39 Mon Sep 17 00:00:00 2001 From: Federico Esteban Date: Fri, 26 Jun 2026 11:37:18 -0300 Subject: [PATCH 2/2] Update src/gmt_support.c Co-authored-by: Joaquim --- src/gmt_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gmt_support.c b/src/gmt_support.c index 4d2c0899766..07ddd9f631c 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -14308,7 +14308,7 @@ int gmt_getrose (struct GMT_CTRL *GMT, char option, char *text, struct GMT_MAP_R /* If the user omitted the reference point (e.g., -Td or -Tm), inject a default one (jTR = Top-Right inside) */ if (text[0] == 'd' || text[0] == 'm') { if (text[1] == '+' || text[1] == '\0') { - snprintf(refpoint_str, GMT_LEN256, "%cjTR%s", text[0], &text[1]); + snprintf(refpoint_str, GMT_LEN256-1, "%cjTR%s", text[0], &text[1]); parse_text = refpoint_str; } }