Skip to content

Commit 24984c1

Browse files
authored
Fix error in indexing for matrix-to-grid input (#8554)
1 parent 425334f commit 24984c1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/gmt_api.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5522,6 +5522,10 @@ GMT_LOCAL struct GMT_GRID *gmtapi_import_grid (struct GMTAPI_CTRL *API, int obje
55225522
else if (S_obj->wesn[XHI] < G_obj->header->wesn[XLO]) { /* Must first wrap G_obj->header->wesn east to fit the data */
55235523
G_obj->header->wesn[XLO] -= 360.0; G_obj->header->wesn[XHI] -= 360.0;
55245524
}
5525+
if (S_obj->wesn[XLO] < G_obj->header->wesn[XLO]) {
5526+
/* 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 */
5527+
G_obj->header->wesn[XLO] -= 360.0; G_obj->header->wesn[XHI] -= 360.0;
5528+
}
55255529
}
55265530
j1 = (unsigned int)gmt_M_grd_y_to_row (GMT, S_obj->wesn[YLO]+dy, G_obj->header);
55275531
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
63416345
if (S_obj->wesn[XLO] > U_obj->header->wesn[XHI]) { /* Must first wrap U_obj->header->wesn west to fit the data */
63426346
U_obj->header->wesn[XLO] += 360.0; U_obj->header->wesn[XHI] += 360.0;
63436347
}
6344-
else if (S_obj->wesn[XHI] < U_obj->header->wesn[XLO]) { /* Must first wrap G_obj->header->wesn east to fit the data */
6348+
else if (S_obj->wesn[XHI] < U_obj->header->wesn[XLO]) { /* Must first wrap U_obj->header->wesn east to fit the data */
6349+
U_obj->header->wesn[XLO] -= 360.0; U_obj->header->wesn[XHI] -= 360.0;
6350+
}
6351+
if (S_obj->wesn[XLO] < U_obj->header->wesn[XLO]) {
6352+
/* 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 */
63456353
U_obj->header->wesn[XLO] -= 360.0; U_obj->header->wesn[XHI] -= 360.0;
63466354
}
63476355
}

0 commit comments

Comments
 (0)