From 5bc61377399c81366e9e69bdc9eb4abdc18f4f23 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Sat, 23 Apr 2022 11:13:47 +0100 Subject: [PATCH] set correct dimension when finding 3- or 4-D array While we correctly found a higher-dimensioned array than 2, we forgot to update ndims once selecting it. Closes #6588. --- src/gmt_nc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gmt_nc.c b/src/gmt_nc.c index 574c2b03d52..1cb781cd3b0 100644 --- a/src/gmt_nc.c +++ b/src/gmt_nc.c @@ -510,6 +510,7 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head if (z_id < 0) { /* No 2-D grid found, check if we found a higher dimension cube */ if (ID == GMT_NOTSET) return (GMT_GRDIO_NO_2DVAR); /* No we didn't */ z_id = ID; /* Pick the higher dimensioned cube instead, get its name, and warn */ + ndims = dim; /* Recall the dimensions of this ID */ nc_inq_varname (ncid, z_id, HH->varname); GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "No 2-D array in file %s. Selecting first 2-D slice in the %d-D array %s\n", HH->name, dim, HH->varname); } @@ -1557,6 +1558,7 @@ int gmtlib_is_nc_grid (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header) { if (z_id < 0) { /* No 2-D grid found, check if we found a higher dimension cube */ if (ID == GMT_NOTSET) return (GMT_GRDIO_NO_2DVAR); /* No we didn't */ z_id = ID; /* Pick the higher dimensioned cube instead, get its name, and warn */ + ndims = dim; /* Recall the dimensions of this ID */ nc_inq_varname (ncid, z_id, varname); GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "No 2-D array in file %s. Selecting first 2-D slice in the %d-D array %s\n", HH->name, dim, varname); }