MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / parse

Function parse

src/grdvolume.c:345–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345static int parse (struct GMT_CTRL *GMT, struct GRDVOLUME_CTRL *Ctrl, struct GMT_OPTION *options) {
346 /* This parses the options provided to grdvolume and sets parameters in Ctrl.
347 * Note Ctrl has already been initialized and non-zero default values set.
348 * Any GMT common options will override values set previously by other commands.
349 * It also replaces any file names specified as input or output with the data ID
350 * returned when registering these sources/destinations with the API.
351 */
352
353 unsigned int n_errors = 0;
354 int n = 0;
355 struct GMT_OPTION *opt = NULL;
356 struct GMTAPI_CTRL *API = GMT->parent;
357
358 for (opt = options; opt; opt = opt->next) { /* Process all the options given */
359
360 switch (opt->option) {
361 case '<': /* Input file (only one is accepted) */
362 n_errors += gmt_M_repeated_module_option (API, Ctrl->In.active);
363 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->In.file));
364 break;
365
366 /* Processes program-specific parameters */
367
368 case 'C':
369 n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active);
370 if (opt->arg[0] == 'r') {
371 Ctrl->C.reverse = true;
372 n = sscanf (&opt->arg[1], "%lf/%lf", &Ctrl->C.low, &Ctrl->C.high);
373 if (n == 1) { /* -Cr<cval> used */
374 Ctrl->C.high = Ctrl->C.low;
375 Ctrl->C.low = -DBL_MAX;
376 Ctrl->C.reverse_min = true;
377 n = 2; /* To cheat the sanity test on -Cr option below */
378 }
379 n_errors += gmt_M_check_condition (GMT, Ctrl->C.low >= Ctrl->C.high,
380 "Option -C: high must exceed low\n");
381 /* Now apply the trick that makes this option work. Swap and change signs of low/high */
382 Ctrl->C.inc = Ctrl->C.low; /* Use inc as the buble sort tmp variable */
383 Ctrl->C.low = -Ctrl->C.high;
384 Ctrl->C.high = -Ctrl->C.inc;
385 Ctrl->C.inc = Ctrl->C.high - Ctrl->C.low;
386 Ctrl->Z.scale = -1;
387 }
388 else {
389 n = sscanf (opt->arg, "%lf/%lf/%lf", &Ctrl->C.low, &Ctrl->C.high, &Ctrl->C.inc);
390 if (n == 3) {
391 n_errors += gmt_M_check_condition (GMT, Ctrl->C.low >= Ctrl->C.high || Ctrl->C.inc <= 0.0,
392 "Option -C: high must exceed low and delta must be positive\n");
393 }
394 else
395 Ctrl->C.high = Ctrl->C.low, Ctrl->C.inc = 1.0; /* So calculation of ncontours will yield 1 */
396 }
397 break;
398 case 'D':
399 n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active);
400 n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0);
401 break;
402 case 'L':

Callers 1

GMT_grdvolumeFunction · 0.70

Calls 5

gmt_get_required_fileFunction · 0.85
gmt_get_no_argumentFunction · 0.85
gmt_get_required_charFunction · 0.85
GMT_ReportFunction · 0.85
gmt_default_option_errorFunction · 0.85

Tested by

no test coverage detected