| 501 | } |
| 502 | |
| 503 | static int parse (struct GMT_CTRL *GMT, struct GRDVIEW_CTRL *Ctrl, struct GMT_OPTION *options) { |
| 504 | /* This parses the options provided to grdview and sets parameters in Ctrl. |
| 505 | * Note Ctrl has already been initialized and non-zero default values set. |
| 506 | * Any GMT common options will override values set previously by other commands. |
| 507 | * It also replaces any file names specified as input or output with the data ID |
| 508 | * returned when registering these sources/destinations with the API. |
| 509 | */ |
| 510 | |
| 511 | unsigned int n_errors = 0, q_set = 0, n_commas, j, k, n, id; |
| 512 | int sval; |
| 513 | bool no_cpt = false; |
| 514 | char *c = NULL, *f = NULL; |
| 515 | struct GMT_OPTION *opt = NULL; |
| 516 | struct GMTAPI_CTRL *API = GMT->parent; |
| 517 | |
| 518 | for (opt = options; opt; opt = opt->next) { /* Process all the options given */ |
| 519 | |
| 520 | switch (opt->option) { |
| 521 | /* Common parameters */ |
| 522 | case '<': /* Input file (only one is accepted) */ |
| 523 | n_errors += gmt_M_repeated_module_option (API, Ctrl->In.active); |
| 524 | n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->In.file)); |
| 525 | break; |
| 526 | |
| 527 | /* Processes program-specific parameters */ |
| 528 | |
| 529 | case 'C': /* Cpt file */ |
| 530 | n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active); |
| 531 | gmt_M_str_free (Ctrl->C.file); |
| 532 | if (opt->arg[0]) Ctrl->C.file = strdup (opt->arg); |
| 533 | if (opt->arg[0] && (f = gmt_strrstr (Ctrl->C.file, "+s")) != NULL) { /* Filename has a +s<outname>, extract that part */ |
| 534 | Ctrl->C.savecpt = &f[2]; |
| 535 | f[0] = '\0'; /* Remove the +s<outname> from Ctrl->C.file */ |
| 536 | } |
| 537 | gmt_cpt_interval_modifier (GMT, &(Ctrl->C.file), &(Ctrl->C.dz)); |
| 538 | break; |
| 539 | case 'G': /* One grid or image or three separate r,g,b grids */ |
| 540 | Ctrl->G.active = true; |
| 541 | for (k = 0, n_commas = 0; opt->arg[k]; k++) if (opt->arg[k] == ',') n_commas++; |
| 542 | if (n_commas == 2) { /* Old-style -Ga,b,c option */ |
| 543 | /* Three r,g,b grids for draping */ |
| 544 | char A[GMT_LEN256] = {""}, B[GMT_LEN256] = {""}, C[GMT_LEN256] = {""}; |
| 545 | sscanf (opt->arg, "%[^,],%[^,],%s", A, B, C); |
| 546 | n_errors += gmt_get_required_file (GMT, A, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->G.file[0])); |
| 547 | n_errors += gmt_get_required_file (GMT, B, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->G.file[1])); |
| 548 | n_errors += gmt_get_required_file (GMT, C, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->G.file[2])); |
| 549 | Ctrl->G.n = 3; |
| 550 | } |
| 551 | else if (n_commas == 0 && Ctrl->G.n < 3) { /* Just got another drape grid or image */ |
| 552 | Ctrl->G.file[Ctrl->G.n] = strdup (opt->arg); |
| 553 | if (GMT_Get_FilePath (API, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->G.file[Ctrl->G.n]))) n_errors++; |
| 554 | Ctrl->G.n++; |
| 555 | } |
| 556 | else { |
| 557 | GMT_Report (API, GMT_MSG_ERROR, "Option -G: Usage is -G<drapegrid|drapeimage>\n"); |
| 558 | n_errors++; |
| 559 | } |
| 560 | break; |
no test coverage detected