From e1ea67a0a4a6640920ed7ad5426a4d57d6af29ee Mon Sep 17 00:00:00 2001 From: Joaquim Date: Fri, 17 Jan 2025 02:13:09 +0000 Subject: [PATCH] Fixes for #8677 --- src/gmt_support.c | 14 +++++++++----- src/seis/grdvs30.c | 29 +++++++++++++++-------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/gmt_support.c b/src/gmt_support.c index 6a337f96087..76b19b49878 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -12716,16 +12716,18 @@ int gmt_BC_init (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *h) { } else { /* Determine BC based on whether grid is geographic or not */ type = (gmt_M_x_is_lon (GMT, GMT_IN)) ? GMT_BC_IS_GEO : GMT_BC_IS_NATURAL; - for (i = 0; i < 4; i++) if (HH->BC[i] == GMT_BC_IS_NOTSET) HH->BC[i] = type; + for (i = 0; i < 4; i++) + if (HH->BC[i] == GMT_BC_IS_NOTSET) HH->BC[i] = type; } /* Check if geographic conditions can be used with this grid */ if (HH->gn && !gmt_grd_is_global (GMT, h)) { /* User has requested geographical conditions, but grid is not global */ - GMT_Report (GMT->parent, GMT_MSG_WARNING, "Longitude range too small; geographic boundary condition changed to natural.\n"); + GMT_Report(GMT->parent, GMT_MSG_INFORMATION, "Longitude range too small; geographic boundary condition changed to natural.\n"); HH->nxp = HH->nyp = 0; HH->gn = HH->gs = false; - for (i = 0; i < 4; i++) if (HH->BC[i] == GMT_BC_IS_NOTSET) HH->BC[i] = GMT_BC_IS_NATURAL; + for (i = 0; i < 4; i++) + if (HH->BC[i] == GMT_BC_IS_NOTSET) HH->BC[i] = GMT_BC_IS_NATURAL; } else if (gmt_grd_is_global (GMT, h)) { /* Grid is truly global */ double xtest = fmod (180.0, h->inc[GMT_X]) * HH->r_inc[GMT_X]; @@ -12733,11 +12735,13 @@ int gmt_BC_init (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *h) { if (GMT->parent->ignore_BC) xtest = 0.0; /* To bypass the checks below */ /* xtest should be within GMT_CONV4_LIMIT of zero or of one. */ if (xtest > GMT_CONV4_LIMIT && xtest < (1.0 - GMT_CONV4_LIMIT) && GMT->current.proj.projection_GMT == 0) { - /* Maybe error. We need it to divide into 180 so we can phase-shift at poles but not if we already projected the grid to Cartesian. */ + /* Maybe error. We need it to divide into 180 so we can phase-shift at poles but not if we + already projected the grid to Cartesian. */ GMT_Report (GMT->parent, GMT_MSG_WARNING, "x_inc does not divide 180; geographic boundary condition changed to natural.\n"); HH->nxp = HH->nyp = 0; HH->gn = HH->gs = false; - for (i = 0; i < 4; i++) if (HH->BC[i] == GMT_BC_IS_NOTSET) HH->BC[i] = GMT_BC_IS_NATURAL; + for (i = 0; i < 4; i++) + if (HH->BC[i] == GMT_BC_IS_NOTSET) HH->BC[i] = GMT_BC_IS_NATURAL; } else { HH->nxp = urint (360.0 * HH->r_inc[GMT_X]); diff --git a/src/seis/grdvs30.c b/src/seis/grdvs30.c index b86b156daca..3ce6a3ed713 100644 --- a/src/seis/grdvs30.c +++ b/src/seis/grdvs30.c @@ -161,6 +161,7 @@ static int parse (struct GMT_CTRL *GMT, struct VS30_CTRL *Ctrl, struct GMT_Z_IO unsigned int n_errors = 0, n_files = 0; char p[GMT_LEN16] = {""}, *pch; + float t; struct GMT_OPTION *opt = NULL; struct GMTAPI_CTRL *API = GMT->parent; @@ -186,21 +187,19 @@ static int parse (struct GMT_CTRL *GMT, struct VS30_CTRL *Ctrl, struct GMT_Z_IO if ((pch = strstr(opt->arg, "+g")) != NULL) Ctrl->C.is_grid = true; /* Useless if Ctrl->C.file = NULL is set below */ - if (!gmt_check_filearg (GMT, 'C', Ctrl->C.file, GMT_IN, GMT_IS_DATASET)) { + t = atof(opt->arg); + if (t >= 0 && t <= 1) { + Ctrl->C.val = t; Ctrl->C.file = NULL; - Ctrl->C.val = atof (opt->arg); - if (Ctrl->C.val < 0 || Ctrl->C.val > 1) { - GMT_Report (GMT->parent, GMT_MSG_NORMAL, "Errorn in -C. Must provide either a file name or a value in the [0 1] interval.\n", p); - n_errors++; - } + } + else if (!gmt_check_filearg(GMT, 'C', Ctrl->C.file, GMT_IN, GMT_IS_DATASET)) { + GMT_Report(GMT->parent, GMT_MSG_NORMAL, "Errorn in -C. Must provide either a file name or a value in the [0 1] interval.\n", p); + n_errors++; } break; case 'G': /* Output file */ - n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active); - if (!gmt_check_filearg (GMT, 'G', opt->arg, GMT_OUT, GMT_IS_GRID)) - Ctrl->G.file = strdup (opt->arg); - else - n_errors++; + n_errors += gmt_M_repeated_module_option(API, Ctrl->G.active); + n_errors += gmt_get_required_file(GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->G.file)); break; case 'W': Ctrl->W.water = (float)atof (opt->arg); @@ -211,7 +210,7 @@ static int parse (struct GMT_CTRL *GMT, struct VS30_CTRL *Ctrl, struct GMT_Z_IO } } - n_errors += gmt_M_check_condition (GMT, !Ctrl->G.file, "Syntax error -G option: Must specify output grid file\n"); + n_errors += gmt_M_check_condition (GMT, !Ctrl->G.active, "Syntax error -G option: Must specify output grid file\n"); n_errors += gmt_M_check_condition (GMT, !Ctrl->C.active, "Syntax error -C option: Must specify a value or a file name.\n"); return (n_errors ? GMT_PARSE_ERROR : GMT_NOERROR); @@ -260,7 +259,9 @@ EXTERN_MSC int GMT_grdvs30 (void *V_API, int mode, void *args) { uint64_t ij; int error = 0; char cmd[GMT_LEN256] = {""}; - char crat_grd[GMT_LEN16] = {""}, mask_grd[GMT_LEN16] = {""}, grad_grd[GMT_LEN16] = {""}; + char crat_grd[GMT_LEN32] = {""}, mask_grd[GMT_LEN32] = {""}, grad_grd[GMT_LEN32] = {""}; + /* + */ float crat, lg; double (*table)[4], tvs[2], vv, wesn[4]; @@ -312,7 +313,7 @@ EXTERN_MSC int GMT_grdvs30 (void *V_API, int mode, void *args) { Return (API->error); /* Prepare the grdlandmask arguments */ - sprintf (cmd, "-G%s -I%f/%f -Df -R%.16g/%.16g/%.16g/%.16g --GMT_HISTORY=false ", + sprintf (cmd, "-G%s -I%.16g/%.16g -Df -R%.16g/%.16g/%.16g/%.16g --GMT_HISTORY=false ", mask_grd, G->header->inc[GMT_X], G->header->inc[GMT_Y], wesn[XLO], wesn[XHI], wesn[YLO], wesn[YHI]); GMT_Report (API, GMT_MSG_LONG_VERBOSE, "Calling grdlandmask with args %s\n", cmd);