From 5737716743da7b940c20a16555f1a1e5ac4b3748 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Tue, 14 Nov 2023 10:59:58 +0100 Subject: [PATCH] Allow +p as per docs (#8039) Also clarify that +p takes optional argument [0] and allow +p with no args for setting the default. See #7746. --- doc/rst/source/gmtspatial.rst | 6 +++--- src/gmtspatial.c | 15 ++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/doc/rst/source/gmtspatial.rst b/doc/rst/source/gmtspatial.rst index 5a58f576523..7f452ee9857 100644 --- a/doc/rst/source/gmtspatial.rst +++ b/doc/rst/source/gmtspatial.rst @@ -20,7 +20,7 @@ Synopsis [ |-F|\ [**l**] ] [ |-I|\ [**e**\|\ **i**] ] [ |-L|\ *dist*\ /*noise*\ /*offset* ] -[ |-N|\ *pfile*\ [**+a**][**+i**][**+p**\ *start*][**+r**][**+z**] ] +[ |-N|\ *pfile*\ [**+a**][**+i**][**+p**\ [*start*]][**+r**][**+z**] ] [ |-Q|\ [*unit*][**+c**\ *min*\ [/*max*]][**+h**][**+l**][**+p**][**+s**\ [**a**\|\ **d**]] ] [ |SYN_OPT-R| ] [ |-S|\ **b**\ *width*\|\ **h**\|\ **i**\|\ **u**\|\ **s**\|\ **j** ] @@ -143,13 +143,13 @@ Optional Arguments .. _-N: -**-N**\ *pfile*\ [**+a**][**+i**][**+p**\ *start*][**+r**][**+z**] +**-N**\ *pfile*\ [**+a**][**+i**][**+p**\ [*start*]][**+r**][**+z**] Lines and polygons: Determine if one (or all, with **+a**) points of each feature in the input data are inside any of the polygons given in the *pfile*. If inside, then report which polygon it is; the polygon ID is either taken from the aspatial value assigned to Z, the segment header (first |-Z|, then |-L| are scanned), or it is assigned the - running number that is initialized to *start* [0]. By default the + running number that is initialized via **+p** to *start* [0]. By default the input segments that are found to be inside a polygon are written to standard output with the polygon ID encoded in the segment header as **-Z**\ *ID*. Alternatively, append **+r** to just report which diff --git a/src/gmtspatial.c b/src/gmtspatial.c index b7e215abc24..d4bc9117d18 100644 --- a/src/gmtspatial.c +++ b/src/gmtspatial.c @@ -767,7 +767,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE); if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR); GMT_Usage (API, 0, "usage: %s [] [-A[a]] [-C] [-D[+a][+c|C][+d][+f][+p][+s]] [-E+n|p] " - "[-F[l]] [-I[i|e]] [-L%s//] [-N[+a][+i][+p][+r][+z]] [-Q[][+c[/]][+h][+l][+p][+s[a|d]]] [%s] " + "[-F[l]] [-I[i|e]] [-L%s//] [-N[+a][+i][+p[]][+r][+z]] [-Q[][+c[/]][+h][+l][+p][+s[a|d]]] [%s] " "[-Sb|h|i|j|s|u] [-T[]] [-W[][+f|l]] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]\n", name, GMT_DIST_OPT, GMT_Rgeo_OPT, GMT_V_OPT, GMT_a_OPT, GMT_b_OPT, GMT_d_OPT, GMT_e_OPT, GMT_f_OPT, GMT_g_OPT, GMT_h_OPT, GMT_i_OPT, GMT_j_OPT, GMT_o_OPT, GMT_q_OPT, GMT_s_OPT, GMT_colon_OPT, GMT_PAR_OPT); @@ -811,7 +811,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { GMT_Usage (API, 1, "\n-L%s//", GMT_DIST_OPT); GMT_Usage (API, -2, "Remove tile Lines. These are superfluous lines along the -R border. " "Append (in m) [0], coordinate noise [1e-10], and max offset from gridline [1e-10]."); - GMT_Usage (API, 1, "\n-N[+a][+i][+p][+r][+z]"); + GMT_Usage (API, 1, "\n-N[+a][+i][+p[]][+r][+z]"); GMT_Usage (API, -2, "Determine ID of polygon (in ) enclosing each input feature (or point if +i). By default, " "the ID starts at 0 and auto-increments. Alternatively, the ID is set as follows:"); GMT_Usage (API, 3, "%s If shapefile or OGR/GMT polygons, get polygon ID via -a for Z column.", GMT_LINE_BULLET); @@ -1006,14 +1006,11 @@ static int parse (struct GMT_CTRL *GMT, struct GMTSPATIAL_CTRL *Ctrl, struct GMT got_i = true; got_n++; break; case 'p': /* Set start of running numbers [0] */ - if (txt_a[1]) { + Ctrl->N.p_set = true; + if (txt_a[1]) Ctrl->N.ID = atoi (&txt_a[1]); - Ctrl->N.p_set = true; - } - else { - GMT_Report (API, GMT_MSG_ERROR, "Option -N: Modifier +p given no value\n"); - n_errors++; - } + else /* Set the default value of 0 */ + Ctrl->N.ID = 0; break; case 'r': /* Just give a report */ Ctrl->N.mode = GMT_N_MODE_REPORT; got_n++;