From 510b9c16689d7323bcec01c4ee4e485d82a74d82 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Fri, 28 Aug 2026 13:07:15 -0300 Subject: [PATCH 1/2] gmtinit_get_region_from_data: Run the w==e/s==n safety valve before rounding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dataset branch of gmtinit_get_region_from_data() already guarded against a degenerate region (west==east and/or south==north, e.g. a single input point, or points that only vary in one dimension) by padding it to +/-1 (or +/-10%) — but that safety valve ran *after* gmt_round_wesn(), which is what -Ra (approximate/rounded region) uses to pick a "nice" region from the data. gmt_round_wesn() takes log10() of the (zero) range while choosing a rounding increment, which turns wesn into NaNs. By the time the safety valve runs, wesn[XLO] and wesn[XHI] are both NaN, and "NaN == NaN" is false, so the valve never fires and the NaN region is used as-is, e.g.: echo "0 0" | gmt plot -Sc0.1c -Gred -JX3c -Ba -Ra -Vd ... plot [ERROR]: Could not parse -nan into ... coordinates! plot [ERROR]: Offending option -R-nan/-nan/-nan/-nan Meanwhile -Re (exact region) was unaffected, since it skips gmt_round_wesn() entirely and lets the safety valve run on the original (non-NaN) degenerate range, giving -R-1/1/-1/1. Move the safety valve above the gmt_round_wesn() call so -Ra now sees the same already-padded, non-degenerate range that -Re does, and rounds *that* instead of the original zero-width box. Verified with the above command (now succeeds), a single point away from the origin (gives a region centered on the point), and that regular multi-point inputs are unaffected (still -0.2/5.2/-0.2/5.2 for two points 5 units apart). This affects every module that can determine -R from input data ("d"/"g" in THIS_MODULE_NEEDS), not just one module. Assisted-by: Claude Sonnet 5 (Medium effort) --- src/gmt_init.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index c1dcd450c02..a49920f860a 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -15101,8 +15101,9 @@ GMT_LOCAL int gmtinit_get_region_from_data(struct GMTAPI_CTRL *API, int family, if (GMT_Destroy_Data (API, &Out) != GMT_OK) return (API->error); geo = gmt_M_is_geographic (API->GMT, GMT_IN); - if (!exact) gmt_round_wesn (wesn, geo); /* Use data range to round to nearest reasonable multiples */ - /* Safety valve if w == e or s == n */ + /* Safety valve if w == e or s == n (e.g., a single data point, or points that only vary in + * one dimension) - must be done before gmt_round_wesn, which otherwise takes log10 of a + * zero range and turns wesn into NaNs. */ if (doubleAlmostEqualZero (wesn[XLO], wesn[XHI])) { if (gmt_M_is_zero (wesn[XLO])) /* No info to do anything other than this */ wesn[XLO] = -1.0, wesn[XHI] = +1.0; @@ -15115,6 +15116,7 @@ GMT_LOCAL int gmtinit_get_region_from_data(struct GMTAPI_CTRL *API, int family, else wesn[YLO] *= 0.9, wesn[YHI] *= 1.1; /* +/- 10% of values */ } + if (!exact) gmt_round_wesn (wesn, geo); /* Use data range to round to nearest reasonable multiples */ break; default: GMT_Report (API, GMT_MSG_DEBUG, "gmtinit_get_region_from_data: Family %d not supported", family); From dcb42e90af587bf5704c5da34739556895ae57dd Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Fri, 28 Aug 2026 13:22:08 -0300 Subject: [PATCH 2/2] Simplified comment --- src/gmt_init.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index a49920f860a..7d7fb9fb4bf 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -15101,9 +15101,7 @@ GMT_LOCAL int gmtinit_get_region_from_data(struct GMTAPI_CTRL *API, int family, if (GMT_Destroy_Data (API, &Out) != GMT_OK) return (API->error); geo = gmt_M_is_geographic (API->GMT, GMT_IN); - /* Safety valve if w == e or s == n (e.g., a single data point, or points that only vary in - * one dimension) - must be done before gmt_round_wesn, which otherwise takes log10 of a - * zero range and turns wesn into NaNs. */ + /* Safety valve if w == e or s == n */ if (doubleAlmostEqualZero (wesn[XLO], wesn[XHI])) { if (gmt_M_is_zero (wesn[XLO])) /* No info to do anything other than this */ wesn[XLO] = -1.0, wesn[XHI] = +1.0;