| 179 | } |
| 180 | |
| 181 | static int parse (struct GMT_CTRL *GMT, struct GMTBINSTATS_CTRL *Ctrl, struct GMT_OPTION *options) { |
| 182 | /* This parses the options provided to gmtbinstats and sets parameters in CTRL. |
| 183 | * Any GMT common options will override values set previously by other commands. |
| 184 | * It also replaces any file names specified as input or output with the data ID |
| 185 | * returned when registering these sources/destinations with the API. |
| 186 | */ |
| 187 | |
| 188 | unsigned int n_errors = 0; |
| 189 | struct GMT_OPTION *opt = NULL; |
| 190 | struct GMTAPI_CTRL *API = GMT->parent; |
| 191 | |
| 192 | for (opt = options; opt; opt = opt->next) { |
| 193 | switch (opt->option) { |
| 194 | |
| 195 | case '<': /* Input file(s) */ |
| 196 | if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++; |
| 197 | break; |
| 198 | case '>': /* Output file */ |
| 199 | n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active); |
| 200 | n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->G.file)); |
| 201 | break; |
| 202 | |
| 203 | /* Processes program-specific parameters */ |
| 204 | |
| 205 | case 'E': /* NaN value */ |
| 206 | n_errors += gmt_M_repeated_module_option (API, Ctrl->E.active); |
| 207 | if (opt->arg[0]) |
| 208 | Ctrl->E.value = (opt->arg[0] == 'N' || opt->arg[0] == 'n') ? GMT->session.d_NaN : atof (opt->arg); |
| 209 | else { |
| 210 | n_errors++; |
| 211 | GMT_Report (API, GMT_MSG_ERROR, "Option -E: Must specify value or NaN\n"); |
| 212 | } |
| 213 | break; |
| 214 | case 'G': /* Output file */ |
| 215 | n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active); |
| 216 | n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->G.file)); |
| 217 | break; |
| 218 | case 'I': /* Grid spacings */ |
| 219 | n_errors += gmt_M_repeated_module_option (API, Ctrl->I.active); |
| 220 | n_errors += gmt_parse_inc_option (GMT, 'I', opt->arg); |
| 221 | break; |
| 222 | case 'C': /* -Ca|d|i|l|L|m|n|o|p|q[<val>]|r|s|u|U|z */ |
| 223 | n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active); |
| 224 | switch (opt->arg[0]) { |
| 225 | case 'a': Ctrl->C.mode = GMTBINSTATS_MEAN; break; |
| 226 | case 'd': Ctrl->C.mode = GMTBINSTATS_MAD; break; |
| 227 | case 'g': Ctrl->C.mode = GMTBINSTATS_ZRANGE; break; |
| 228 | case 'i': Ctrl->C.mode = GMTBINSTATS_IRANGE; break; |
| 229 | case 'l': Ctrl->C.mode = GMTBINSTATS_LOWER; break; |
| 230 | case 'L': Ctrl->C.mode = GMTBINSTATS_LOWERP; break; |
| 231 | case 'm': Ctrl->C.mode = GMTBINSTATS_MEDIAN; break; |
| 232 | case 'n': Ctrl->C.mode = GMTBINSTATS_COUNT; break; |
| 233 | case 'o': Ctrl->C.mode = GMTBINSTATS_LMSSCL; break; |
| 234 | case 'p': Ctrl->C.mode = GMTBINSTATS_MODE; break; |
| 235 | case 'q': Ctrl->C.mode = GMTBINSTATS_QUANT; |
| 236 | if (opt->arg[1]) Ctrl->C.quant = atof (&opt->arg[1]); |
| 237 | break; |
| 238 | case 'r': Ctrl->C.mode = GMTBINSTATS_RMS; break; |
no test coverage detected