From 893041070c07418badf7351cb315be7ca18b23f1 Mon Sep 17 00:00:00 2001 From: Joaquim Date: Thu, 19 Mar 2026 00:25:33 +0000 Subject: [PATCH 1/2] Add a patch to fix the errors in coordinates of the NASA MODIS L3 files --- src/gmt_nc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gmt_nc.c b/src/gmt_nc.c index 19b96a478f3..f852cab1b46 100644 --- a/src/gmt_nc.c +++ b/src/gmt_nc.c @@ -913,6 +913,22 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head gmt_M_free (GMT, xy); /* Done with the array */ + /* This bit is a hack to deal with extremly annoying fact that NASA MODIS grids keep having wrong coordinates. + The difference are minute, probably originated from a flot64/float32 roundoff shit, but the fact is that their + coordinates are wrong and the difference overflows the [-90 90] lat interval and as a consequece projections + breake because they fail sanity checks. See issue https://github.com/GenericMappingTools/gmt/issues/8930 + */ + if (((header->wesn[YHI] - header->wesn[YLO] - 180) < header->inc[GMT_Y] * 1e-2) && + ((header->wesn[XHI] - header->wesn[XLO] - 360) < header->inc[GMT_X] * 1e-2) && + (fabs(header->wesn[YHI] - 90.0) < header->inc[GMT_Y] * 1e-4 || fabs(90.0 - header->wesn[YLO]) < header->inc[GMT_Y] * 1e-4)) { + header->wesn[YLO] = -90.0, header->wesn[YHI] = 90.0; + /* If any case of this happens to not fall into the [-180 180] or [0 360] range, the shit in longituds will remain. */ + if (rint(header->wesn[XLO]) == -180.0) {header->wesn[XLO] = -180.0; header->wesn[XHI] = 180.0;} + if (rint(header->wesn[XHI]) == 0.0) {header->wesn[XLO] = 0.0; header->wesn[XHI] = 360.0;} + header->inc[GMT_Y] = (header->wesn[YHI] - header->wesn[YLO]) / (header->n_rows - !header->registration); + header->inc[GMT_X] = (header->wesn[XHI] - header->wesn[XLO]) / (header->n_columns - !header->registration); + } + /* Get information about z variable */ gmtnc_get_units (GMT, ncid, z_id, header->z_units); if (nc_get_att_double (ncid, z_id, "scale_factor", &header->z_scale_factor)) header->z_scale_factor = 1.0; From 4ad0c4a9824ee33252c98bdda78e703b76076148 Mon Sep 17 00:00:00 2001 From: Joaquim Date: Thu, 19 Mar 2026 01:16:57 +0000 Subject: [PATCH 2/2] Fix the tests if coords can be global geogs --- src/gmt_nc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gmt_nc.c b/src/gmt_nc.c index f852cab1b46..5436de92245 100644 --- a/src/gmt_nc.c +++ b/src/gmt_nc.c @@ -918,8 +918,8 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head coordinates are wrong and the difference overflows the [-90 90] lat interval and as a consequece projections breake because they fail sanity checks. See issue https://github.com/GenericMappingTools/gmt/issues/8930 */ - if (((header->wesn[YHI] - header->wesn[YLO] - 180) < header->inc[GMT_Y] * 1e-2) && - ((header->wesn[XHI] - header->wesn[XLO] - 360) < header->inc[GMT_X] * 1e-2) && + if ((fabs(header->wesn[YHI] - header->wesn[YLO] - 180) < header->inc[GMT_Y] * 1e-2) && + (fabs(header->wesn[XHI] - header->wesn[XLO] - 360) < header->inc[GMT_X] * 1e-2) && (fabs(header->wesn[YHI] - 90.0) < header->inc[GMT_Y] * 1e-4 || fabs(90.0 - header->wesn[YLO]) < header->inc[GMT_Y] * 1e-4)) { header->wesn[YLO] = -90.0, header->wesn[YHI] = 90.0; /* If any case of this happens to not fall into the [-180 180] or [0 360] range, the shit in longituds will remain. */