| 638 | } |
| 639 | |
| 640 | static int parse (struct GMT_CTRL *GMT, struct GRDFFT_CTRL *Ctrl, struct F_INFO *f_info, struct GMT_OPTION *options) { |
| 641 | /* This parses the options provided to grdfft and sets parameters in Ctrl. |
| 642 | * Note Ctrl has already been initialized and non-zero default values set. |
| 643 | * Any GMT common options will override values set previously by other commands. |
| 644 | * It also replaces any file names specified as input or output with the data ID |
| 645 | * returned when registering these sources/destinations with the API. |
| 646 | */ |
| 647 | |
| 648 | unsigned int j, k, pos, n_errors = 0, filter_type = 0; |
| 649 | int n_scan; |
| 650 | double par[5]; |
| 651 | char combined[GMT_BUFSIZ] = {""}, argument[GMT_LEN16] = {""}, p[GMT_LEN64] = {""}, *c = NULL; |
| 652 | struct GMT_OPTION *opt = NULL, *ptr = NULL; |
| 653 | struct GMTAPI_CTRL *API = GMT->parent; |
| 654 | |
| 655 | if (gmt_M_compat_check (GMT, 4)) { |
| 656 | char *mod = NULL; |
| 657 | if ((ptr = GMT_Find_Option (API, 'L', options))) { /* Gave old -L */ |
| 658 | mod = ptr->arg; /* Gave old -L option */ |
| 659 | if (mod[0] == '\0') strcat (argument, "+l"); /* Leave trend alone -L */ |
| 660 | else if (mod[0] == 'm') strcat (argument, "+a"); /* Remove mean -Lm */ |
| 661 | else if (mod[0] == 'h') strcat (argument, "+h"); /* Remove mid-value -Lh */ |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | gmt_M_memset (f_info, 1, struct F_INFO); |
| 666 | for (j = 0; j < 3; j++) { |
| 667 | f_info->lc[j] = f_info->lp[j] = -1.0; /* Set negative, below valid frequency range */ |
| 668 | f_info->hp[j] = f_info->hc[j] = DBL_MAX; /* Set huge positive, above valid frequency range */ |
| 669 | } |
| 670 | |
| 671 | for (opt = options; opt; opt = opt->next) { /* Process -M first because we may need its value for -D and/or -I */ |
| 672 | switch (opt->option) { |
| 673 | case 'M': /* Geographic data */ |
| 674 | if (gmt_M_compat_check (GMT, 4)) { |
| 675 | if (sscanf(opt->arg, "%lf", &Ctrl->M.mgal_at_45)) |
| 676 | Ctrl->M.active = true; |
| 677 | else { |
| 678 | GMT_Report (API, GMT_MSG_COMPAT, "Option -M is deprecated; -fg was set instead, use this in the future.\n"); |
| 679 | if (gmt_M_is_cartesian (GMT, GMT_IN)) |
| 680 | gmt_parse_common_options (GMT, "f", 'f', "g"); /* Set -fg unless already set */ |
| 681 | } |
| 682 | } |
| 683 | else { |
| 684 | n_errors += gmt_M_repeated_module_option(API, Ctrl->M.active); |
| 685 | sscanf(opt->arg, "%lf", &Ctrl->M.mgal_at_45); |
| 686 | } |
| 687 | break; |
| 688 | } |
| 689 | } |
| 690 | if (!Ctrl->M.active) Ctrl->M.mgal_at_45 = 980619.9203; /* Moritz's 1980 IGF value for gravity in mGal at 45 degrees latitude */ |
| 691 | |
| 692 | for (opt = options; opt; opt = opt->next) { /* Process all the options given */ |
| 693 | gmt_M_memset (par, 5, double); |
| 694 | |
| 695 | switch (opt->option) { |
| 696 | case '<': /* Input file (only 1 or 2 are accepted) */ |
| 697 | Ctrl->In.active = true; |
no test coverage detected