| 600 | } |
| 601 | |
| 602 | static int parse (struct GMT_CTRL *GMT, struct SPECTRUM1D_CTRL *Ctrl, struct GMT_OPTION *options) { |
| 603 | /* This parses the options provided to spectrum1d and sets parameters in CTRL. |
| 604 | * Any GMT common options will override values set previously by other commands. |
| 605 | * It also replaces any file names specified as input or output with the data ID |
| 606 | * returned when registering these sources/destinations with the API. |
| 607 | */ |
| 608 | |
| 609 | int sval; |
| 610 | unsigned int n_errors = 0, j, window_test = 2, n_files = 0; |
| 611 | struct GMT_OPTION *opt = NULL; |
| 612 | struct GMTAPI_CTRL *API = GMT->parent; |
| 613 | |
| 614 | for (opt = options; opt; opt = opt->next) { |
| 615 | switch (opt->option) { |
| 616 | |
| 617 | case '<': /* Skip input files */ |
| 618 | if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++; |
| 619 | break; |
| 620 | |
| 621 | case '>': /* Got named output file */ |
| 622 | n_errors += gmt_M_repeated_module_option (API, Ctrl->Out.active); |
| 623 | n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_DATASET, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->Out.file)); |
| 624 | n_files++; |
| 625 | break; |
| 626 | |
| 627 | /* Processes program-specific parameters */ |
| 628 | |
| 629 | case 'C': |
| 630 | n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active); |
| 631 | if (!opt->arg[0]) break; /* Stay with the default order of output */ |
| 632 | gmt_M_memset (Ctrl->C.col, SPECTRUM1D_N_OUTPUT_CHOICES, char); /* Reset and read options */ |
| 633 | for (j = 0; opt->arg[j]; j++) { |
| 634 | if (j < SPECTRUM1D_N_OUTPUT_CHOICES) { |
| 635 | Ctrl->C.col[j] = opt->arg[j]; |
| 636 | if (!strchr ("xycnpago", Ctrl->C.col[j])) { |
| 637 | GMT_Report (API, GMT_MSG_ERROR, "Option -C: Unrecognized output choice %c\n", Ctrl->C.col[j]); |
| 638 | n_errors++; |
| 639 | } |
| 640 | } |
| 641 | else { |
| 642 | GMT_Report (API, GMT_MSG_ERROR, "Option -C: Too many output columns selected: Choose from -Cxycnpago\n"); |
| 643 | n_errors++; |
| 644 | } |
| 645 | } |
| 646 | break; |
| 647 | case 'D': |
| 648 | n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active); |
| 649 | n_errors += gmt_get_required_double (GMT, opt->arg, opt->option, 0, &Ctrl->D.inc); |
| 650 | break; |
| 651 | case 'L': /* Leave trend alone, or just remove a constant */ |
| 652 | n_errors += gmt_M_repeated_module_option (API, Ctrl->L.active); |
| 653 | switch (opt->arg[0]) { |
| 654 | case 'm': Ctrl->L.mode = SPECTRUM1D_MEANVAL_REMOVE; break; |
| 655 | case 'h': Ctrl->L.mode = SPECTRUM1D_MIDVAL_REMOVE; break; |
| 656 | case '\0': Ctrl->L.mode = SPECTRUM1D_NO_TREND_REMOVE; break; |
| 657 | default: |
| 658 | GMT_Report (API, GMT_MSG_ERROR, "Option -L: Unrecognized directive %s\n", &(opt->arg[1])); |
| 659 | n_errors++; |
no test coverage detected