diff --git a/src/gmt_api.c b/src/gmt_api.c index 369fa8ee3c9..c864ddcaec1 100644 --- a/src/gmt_api.c +++ b/src/gmt_api.c @@ -5522,6 +5522,10 @@ GMT_LOCAL struct GMT_GRID *gmtapi_import_grid (struct GMTAPI_CTRL *API, int obje else if (S_obj->wesn[XHI] < G_obj->header->wesn[XLO]) { /* Must first wrap G_obj->header->wesn east to fit the data */ G_obj->header->wesn[XLO] -= 360.0; G_obj->header->wesn[XHI] -= 360.0; } + if (S_obj->wesn[XLO] < G_obj->header->wesn[XLO]) { + /* Must wrap G_obj->header.wesn so the left bound in S_obj is smaller larger than that in G_obj, otherwise i0 is negative (but it's defined as unsigned int */ + G_obj->header->wesn[XLO] -= 360.0; G_obj->header->wesn[XHI] -= 360.0; + } } j1 = (unsigned int)gmt_M_grd_y_to_row (GMT, S_obj->wesn[YLO]+dy, G_obj->header); j0 = (unsigned int)gmt_M_grd_y_to_row (GMT, S_obj->wesn[YHI]-dy, G_obj->header); @@ -6341,7 +6345,11 @@ GMT_LOCAL struct GMT_CUBE * gmtapi_import_cube (struct GMTAPI_CTRL *API, int obj if (S_obj->wesn[XLO] > U_obj->header->wesn[XHI]) { /* Must first wrap U_obj->header->wesn west to fit the data */ U_obj->header->wesn[XLO] += 360.0; U_obj->header->wesn[XHI] += 360.0; } - else if (S_obj->wesn[XHI] < U_obj->header->wesn[XLO]) { /* Must first wrap G_obj->header->wesn east to fit the data */ + else if (S_obj->wesn[XHI] < U_obj->header->wesn[XLO]) { /* Must first wrap U_obj->header->wesn east to fit the data */ + U_obj->header->wesn[XLO] -= 360.0; U_obj->header->wesn[XHI] -= 360.0; + } + if (S_obj->wesn[XLO] < U_obj->header->wesn[XLO]) { + /* Must wrap U_obj->header.wesn so the left bound in S_obj is smaller larger than that in U_obj, otherwise i0 is negative (but it's defined as unsigned int */ U_obj->header->wesn[XLO] -= 360.0; U_obj->header->wesn[XHI] -= 360.0; } }