! . */
| 13107 | |
| 13108 | /*! . */ |
| 13109 | struct GMT_RESOURCE * GMT_Encode_Options (void *V_API, const char *module_name, int n_in, struct GMT_OPTION **head, unsigned int *n) { |
| 13110 | /* This function determines which input sources and output destinations are required given the module options. |
| 13111 | * It is only used to assist developers of external APIs, such as the MATLAB, Julia, Python, R, and others. |
| 13112 | * "Keys" referred to below is the unique combination given near the top of every module via the macro |
| 13113 | * THIS_MODULE_KEYS. For instance, here are the keys for grdtrack: |
| 13114 | * |
| 13115 | * #define THIS_MODULE_KEYS "<D{,DD),GG(,>D}" |
| 13116 | * |
| 13117 | * Here are the GMT_Encode_Options arguments: |
| 13118 | * API Controls all things within GMT. |
| 13119 | * module Name of the GMT module. |
| 13120 | * n_in Known number of objects given as input resources (-1 if not known). |
| 13121 | * head Linked list of GMT options passed for this module. We may hook on 1-2 additional options. |
| 13122 | * *n Number of structures returned by the function. Struct GMT_RESOURCE is defined in gmt.h |
| 13123 | * |
| 13124 | * We also return an array of structures with information about registered resources going to/from GMT. |
| 13125 | * Basically, given the module we look up the keys for that module, which tells us which options provide |
| 13126 | * the input and output selections and which ones are required and which ones are optional. We then |
| 13127 | * scan the given options and if file arguments to the options listed in the keys are missing we are |
| 13128 | * to insert ? as the filename. Some options may already have the question mark. After scanning |
| 13129 | * the options we examine the keys for any required input or output argument that have yet to be specified |
| 13130 | * explicitly. If so we create the missing options, with filename = ?, and append them to the end of |
| 13131 | * the option list (head). The API developers can then use this array of encoded options in concert with |
| 13132 | * the information passed back via the structure list to attach actual resources. |
| 13133 | * |
| 13134 | * For each option that may take a file we need to know what kind of file and if it is input or output. |
| 13135 | * We encode this information in a 3-character word XYZ, explained below. Note that each module may |
| 13136 | * need several comma-separated XYZ words and these are returned as one string via GMT_Get_Moduleinfo. |
| 13137 | * The X, Y, and Z letter position represent different information, as discussed below: |
| 13138 | * |
| 13139 | * X stands for the specific program OPTION (e.g., L for -L, F for -F). For tables or grids read from files or |
| 13140 | * tables processed via standard input we use '<', while '>' is used for standard (table) output. |
| 13141 | * Y stands for data TYPE (C = CPT, D = Dataset/Point, L = Dataset/Line, P = Dataset/Polygon, |
| 13142 | * G = Grid, I = Image, X = PostScript, ? = type specified via a module option [more later]), |
| 13143 | * while a hyphen (-) means there is NO data when this option is set (see Z for whether this is for in- or output). |
| 13144 | * Z stands for PRIMARY inputs '{', primary output '}' OR SECONDARY input '(', or secondary output ')'. |
| 13145 | * Primary inputs and outputs MUST be assigned, and if not explicitly given will result in |
| 13146 | * a syntax error. However, external APIs (mex, Python) can override this and supply the missing items |
| 13147 | * via any given left- and right-hand side arguments to supply inputs or accept outputs. |
| 13148 | * Secondary inputs means they are only assigned if an option is actually given. If the in|out designation |
| 13149 | * is irrelevant for an option we use '-'. |
| 13150 | * |
| 13151 | * There are a few special cases where X, Y, or Z take on "magic" behavior: |
| 13152 | * |
| 13153 | * A few modules with have X = - (hyphen). This means the primary input or output (determined by Z) |
| 13154 | * has a data type that is not known until runtime. A module option will tells us which type it is, and this |
| 13155 | * option is encoded in Y. So a -Y<type> option is _required_ and that is how we can update the primary |
| 13156 | * data type. Example: gmtread can read any GMT object but requires -T<type>. It thus has the keys |
| 13157 | * "<?{,>?},-T-". Hence, we examine -T<type> and replace ? with the dataset implied by <type> both for input |
| 13158 | * AND output (since Z was indeterminate). Use i|o if only input or output should have this treatment. |
| 13159 | * |
| 13160 | * A few modules will have Y = - which is another magic key: If the -X option is given then either the input |
| 13161 | * or output (depending on what Z is) will NOT be required. As an example of this behavior, consider psxy |
| 13162 | * which has a -T option that means "read no input, just write trailer". So the key "T-<" in psxy means that |
| 13163 | * when -T is used then NO input is required. This means the primary input key "<D{" is changed to "<D(" (secondary) |
| 13164 | * and no attempt is made to connect external input to the psxy input. If Z is none of () then we expect Z to |
| 13165 | * be one of the options with required input (or output) and we change that option to option input (or output). |
| 13166 | * Example: grdtrack has two required inputs (the grid(s) and the track/point file. However, if -E is set then |
no test coverage detected