From 93d7c89ba7497924238d8545c07ea54015709eb7 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Thu, 30 Nov 2023 18:22:32 +0100 Subject: [PATCH] Wrong if-test for deleting Grid if 1-D (#8112) Closes #8110. --- src/greenspline.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/greenspline.c b/src/greenspline.c index 5b3a6f8bca2..4593913e6ba 100644 --- a/src/greenspline.c +++ b/src/greenspline.c @@ -2075,13 +2075,15 @@ EXTERN_MSC int GMT_greenspline (void *V_API, int mode, void *args) { gmt_M_free (GMT, X); gmt_M_free (GMT, obs); Return (GMT_RUNTIME_ERROR); } - if (GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, NULL, Ctrl->T.file, Grid) == NULL) { /* Get data */ - gmt_M_free (GMT, X); gmt_M_free (GMT, obs); - Return (API->error); + if (!Ctrl->C.dryrun) { /* Only read the data if not a dry run */ + if (GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, NULL, Ctrl->T.file, Grid) == NULL) { /* Get data */ + gmt_M_free (GMT, X); gmt_M_free (GMT, obs); + Return (API->error); + } + (void)gmt_set_outgrid (GMT, Ctrl->T.file, false, 0, Grid, &Out); /* true if input is a read-only array; otherwise Out is just a pointer to Grid */ + n_ok = Grid->header->nm; + gmt_M_grd_loop (GMT, Grid, row, col, ij) if (gmt_M_is_fnan (Grid->data[ij])) n_ok--; } - (void)gmt_set_outgrid (GMT, Ctrl->T.file, false, 0, Grid, &Out); /* true if input is a read-only array; otherwise Out is just a pointer to Grid */ - n_ok = Grid->header->nm; - gmt_M_grd_loop (GMT, Grid, row, col, ij) if (gmt_M_is_fnan (Grid->data[ij])) n_ok--; } else if (Ctrl->N.active) { /* Read output locations from file */ gmt_disable_bghio_opts (GMT); /* Do not want any -b -g -h -i -o to affect the reading from -N file */ @@ -2111,7 +2113,8 @@ EXTERN_MSC int GMT_greenspline (void *V_API, int mode, void *args) { data = gmt_M_memory (GMT, NULL, Grid->header->n_columns, gmt_grdfloat); } else if (dimension == 2) { /* Need a full-fledged Grid creation since we are writing it to who knows where */ - if ((Grid = GMT_Create_Data (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, Ctrl->R3.range, Ctrl->I.inc, \ + unsigned int mode = (Ctrl->C.dryrun) ? GMT_CONTAINER_ONLY : GMT_CONTAINER_AND_DATA; /* Only allocate the data array if not a dry run */ + if ((Grid = GMT_Create_Data (API, GMT_IS_GRID, GMT_IS_SURFACE, mode, NULL, Ctrl->R3.range, Ctrl->I.inc, \ GMT->common.R.registration, GMT_NOTSET, NULL)) == NULL) Return (API->error); n_ok = Grid->header->nm; header = Grid->header; @@ -2121,7 +2124,8 @@ EXTERN_MSC int GMT_greenspline (void *V_API, int mode, void *args) { } } else { /* 3-D cube needed */ - if ((Cube = GMT_Create_Data (API, GMT_IS_CUBE, GMT_IS_VOLUME, GMT_CONTAINER_AND_DATA, NULL, Ctrl->R3.range, Ctrl->I.inc, \ + unsigned int mode = (Ctrl->C.dryrun) ? GMT_CONTAINER_ONLY : GMT_CONTAINER_AND_DATA; /* Only allocate the data array if not a dry run */ + if ((Cube = GMT_Create_Data (API, GMT_IS_CUBE, GMT_IS_VOLUME, mode, NULL, Ctrl->R3.range, Ctrl->I.inc, \ GMT->common.R.registration, GMT_NOTSET, NULL)) == NULL) Return (API->error); n_layers = Cube->header->n_bands; n_ok = Cube->header->nm * n_layers; @@ -2421,7 +2425,7 @@ EXTERN_MSC int GMT_greenspline (void *V_API, int mode, void *args) { gmt_M_free (GMT, v); gmt_M_free (GMT, A); gmt_M_free (GMT, obs); - if (dimension == 2) gmt_free_grid (GMT, &Grid, true); + if (dimension == 1) gmt_free_grid (GMT, &Grid, true); Return (GMT_NOERROR); } }