! Prepare options if missing and initialize module */
| 15643 | |
| 15644 | /*! Prepare options if missing and initialize module */ |
| 15645 | struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, const char *keys, const char *in_required, struct GMT_KEYWORD_DICTIONARY *this_module_kw, struct GMT_OPTION **options, struct GMT_CTRL **Ccopy) { |
| 15646 | /* For modern runmode only - otherwise we simply call gmtinit_begin_module_sub. |
| 15647 | * We must consult the required string. It may contain options that we need to set implicitly. |
| 15648 | * Possible letters in the required string are: |
| 15649 | * R The -R option is required for this program and if missing we will hunt for the last region in the history. |
| 15650 | * r The -R option may be required depending on other settings. If it becomes required and no -R<region> was |
| 15651 | * given then we hunt for one in the history. This happens after GMT_Parse_Common has been called. |
| 15652 | * g The region is required but if none is given the we simply use -R<grid>. This applies to those modules that |
| 15653 | * have a required grid for input (e.g., modules like grdimage). |
| 15654 | * d If no -R<region> is given AND there are no region in the history, then determine a suitable region |
| 15655 | * from the input dataset. This enables automatic region determination via gmtinfo. |
| 15656 | * J The -J option is required and if missing we will hunt for the last region in the history. |
| 15657 | * j The -J option may be required depending on other settings. If it becomes required and no -J<info> was |
| 15658 | * given then we hunt for one in the history. This happens after GMT_Parse_Common has been called. |
| 15659 | * |
| 15660 | * Note: 1. If no -J can be found in the history we provide either -JQ15c (geographic data) or -JX15c (Cartesian). |
| 15661 | * |
| 15662 | * Modules like pslegend has "rj" since -R -J are not required if -Dx is used but required for other settings. |
| 15663 | * Modules like blockmean, surface has "R" since it is never cool to auto-determine grid domains as this also |
| 15664 | * depends on grid spacing, for instance. |
| 15665 | * Modules like grdview has "g" since they always have a grid domain to fall back on in the absence of -R. |
| 15666 | * Modules like psxy has "d" so we can make a quick map without specifying -R. |
| 15667 | */ |
| 15668 | |
| 15669 | bool is_PS, is_psrose = false, is_D_module = false, remote_first = true; |
| 15670 | char *required = (char *)in_required; |
| 15671 | unsigned int k; |
| 15672 | static char *D_module[4] = {"gmtlogo", "psimage", "pslegend", "psscale"}; /* These all may take -Dx and thus may not need -R -J */ |
| 15673 | struct GMT_OPTION *E = NULL, *opt = NULL, *opt_R = NULL; |
| 15674 | struct GMT_CTRL *GMT = API->GMT; |
| 15675 | API->error = GMT_NOERROR; |
| 15676 | |
| 15677 | gmtinit_translate_to_short_options (API, this_module_kw, options); /* Replace --long-option syntax with equivalent -onechar options */ |
| 15678 | |
| 15679 | is_PS = gmtinit_is_PS_module (API, mod_name, keys, options); /* true if module will produce PS */ |
| 15680 | if (!is_PS) { /* Override API default since module is a data processor */ |
| 15681 | API->use_gridline_registration = true; |
| 15682 | API->use_gridline_registration_warn = (strcmp (mod_name, "grd2cpt") && strcmp (mod_name, "grd2kml")); /* Give warning unless it is these two clowns */ |
| 15683 | } |
| 15684 | |
| 15685 | /* First handle any halfhearted naming of remote datasets where _g or _p should be appended */ |
| 15686 | |
| 15687 | if (options) { |
| 15688 | unsigned int err_code; |
| 15689 | /* Treat -V in advance because gmt_set_unspecified_remote_registration needs to already know about it.*/ |
| 15690 | for (opt = *options; opt; opt = opt->next) { |
| 15691 | if (opt->option == 'V') |
| 15692 | gmt_parse_common_options (API->GMT, "V", opt->option, opt->arg); |
| 15693 | } |
| 15694 | for (opt = *options; opt; opt = opt->next) { /* Loop over all options */ |
| 15695 | if (strchr (opt->arg, '@') == NULL) continue;/* Cannot be a remote file */ |
| 15696 | if ((err_code = gmtinit_might_be_remotefile (API->GMT, opt->arg)) == 0) continue; |
| 15697 | if (err_code == 2) { |
| 15698 | GMT_Report (API, GMT_MSG_ERROR, "File %s is not a file and looks like pstext strings.\n", opt->arg); |
| 15699 | return NULL; |
| 15700 | } |
| 15701 | if (remote_first) { |
| 15702 | gmt_refresh_server (API); /* Refresh hash and info tables as needed */ |