Skip to content

Commit

Permalink
Wrong if-test for deleting Grid if 1-D (#8112)
Browse files Browse the repository at this point in the history
Closes #8110.
  • Loading branch information
PaulWessel authored Nov 30, 2023
1 parent 5b617fe commit 93d7c89
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/greenspline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 93d7c89

Please sign in to comment.