| 193 | } |
| 194 | |
| 195 | static int parse (struct GMT_CTRL *GMT, struct GRDGRADIENT_CTRL *Ctrl, struct GMT_OPTION *options) { |
| 196 | /* This parses the options provided to grdgradient and sets parameters in Ctrl. |
| 197 | * Note Ctrl has already been initialized and non-zero default values set. |
| 198 | * Any GMT common options will override values set previously by other commands. |
| 199 | * It also replaces any file names specified as input or output with the data ID |
| 200 | * returned when registering these sources/destinations with the API. |
| 201 | */ |
| 202 | |
| 203 | unsigned int n_errors = 0, j, entry, pos; |
| 204 | char p[GMT_BUFSIZ] = {""}, *c = NULL; |
| 205 | struct GMT_OPTION *opt = NULL; |
| 206 | struct GMTAPI_CTRL *API = GMT->parent; |
| 207 | |
| 208 | for (opt = options; opt; opt = opt->next) { /* Process all the options given */ |
| 209 | |
| 210 | switch (opt->option) { |
| 211 | case '<': /* Input file (only one is accepted) */ |
| 212 | n_errors += gmt_M_repeated_module_option (API, Ctrl->In.active); |
| 213 | n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->In.file)); |
| 214 | break; |
| 215 | |
| 216 | /* Processes program-specific parameters */ |
| 217 | |
| 218 | case 'A': /* Set azimuth(s) */ |
| 219 | n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active); |
| 220 | if (!gmt_access (GMT, opt->arg, F_OK)) { /* file with variable azimuths exists */ |
| 221 | Ctrl->A.file = strdup (opt->arg); |
| 222 | Ctrl->A.mode = GRDGRADIENT_VAR; |
| 223 | } |
| 224 | else { /* Get one or two fixed azimuths */ |
| 225 | j = sscanf (opt->arg, "%lf/%lf", &Ctrl->A.azimuth[0], &Ctrl->A.azimuth[1]); |
| 226 | Ctrl->A.two = (j == 2); |
| 227 | Ctrl->A.mode = GRDGRADIENT_FIX; |
| 228 | } |
| 229 | break; |
| 230 | case 'D': /* Find direction of grad|z| */ |
| 231 | n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active); |
| 232 | j = 0; |
| 233 | while (opt->arg[j]) { |
| 234 | switch (opt->arg[j]) { |
| 235 | case 'c': Ctrl->D.mode |= 1; break; |
| 236 | case 'o': Ctrl->D.mode |= 2; break; |
| 237 | case 'n': Ctrl->D.mode |= 4; break; |
| 238 | case 'a': Ctrl->D.mode |= 8; break; |
| 239 | default: |
| 240 | GMT_Report (API, GMT_MSG_ERROR, "Option -D: Unrecognized modifier\n"); |
| 241 | n_errors++; |
| 242 | break; |
| 243 | } |
| 244 | j++; |
| 245 | } |
| 246 | break; |
| 247 | case 'E': /* Lambertian family radiance */ |
| 248 | n_errors += gmt_M_repeated_module_option (API, Ctrl->E.active); |
| 249 | switch (opt->arg[0]) { |
| 250 | case 'p': /* Peucker */ |
| 251 | Ctrl->E.mode = 1; |
| 252 | break; |
no test coverage detected