MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / parse

Function parse

src/subplot.c:290–820  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290static int parse (struct GMT_CTRL *GMT, struct SUBPLOT_CTRL *Ctrl, struct GMT_OPTION *options) {
291
292 /* This parses the options provided to grdcut and sets parameters in CTRL.
293 * Any GMT common options will override values set previously by other commands.
294 * It also replaces any file names specified as input or output with the data ID
295 * returned when registering these sources/destinations with the API.
296 */
297
298 unsigned int n_errors = 0, error, k, j, n = 0, pos, side;
299 bool B_args = false, noB = false;
300 char *c = NULL, add[2] = {0, 0}, string[GMT_LEN128] = {""}, p[GMT_LEN128] = {""};
301 struct GMT_OPTION *opt = NULL, *Bframe = NULL, *Bx = NULL, *By = NULL, *Bxy = NULL;
302 struct GMT_PEN pen; /* Only used to make sure any pen is given with correct syntax */
303 struct GMT_FILL fill; /* Only used to make sure any fill is given with correct syntax */
304 struct GMTAPI_CTRL *API = GMT->parent;
305
306 opt = options; /* The first argument is the subplot command */
307 if (opt->option != GMT_OPT_INFILE) {
308 GMT_Report (API, GMT_MSG_ERROR, "No subplot command given\n");
309 return GMT_PARSE_ERROR;
310 }
311 if (!strncmp (opt->arg, "begin", 5U)) { /* Initiate new subplot */
312 Ctrl->In.mode = SUBPLOT_BEGIN;
313 opt = opt->next; /* The required number of rows and columns */
314 if (opt->option != GMT_OPT_INFILE || (n = sscanf (opt->arg, "%dx%d", &Ctrl->N.dim[GMT_Y], &Ctrl->N.dim[GMT_X]) < 1)) {
315 GMT_Report (API, GMT_MSG_ERROR, "subplot begin: Unable to extract nrows and ncols from %s\n", opt->arg);
316 return GMT_PARSE_ERROR;
317 }
318 Ctrl->N.n_subplots = Ctrl->N.dim[GMT_X] * Ctrl->N.dim[GMT_Y];
319 Ctrl->N.active = true;
320 }
321 else if (!strncmp (opt->arg, "end", 3U)) /* End of the subplot */
322 Ctrl->In.mode = SUBPLOT_END;
323 else if (!strncmp (opt->arg, "set", 3U)) { /* Explicitly called set row,col or set index */
324 opt = opt->next; /* The row,col part */
325 if (opt && opt->option == GMT_OPT_INFILE) { /* There is an argument without a leading -? option (thus flagged as input file) */
326 if (isdigit (opt->arg[0]) && (n = sscanf (opt->arg, "%d,%d", &Ctrl->In.row, &Ctrl->In.col)) < 1) {
327 GMT_Report (API, GMT_MSG_ERROR, "Unable to parse row,col: %s\n", opt->arg);
328 return GMT_PARSE_ERROR;
329 }
330 if (n == 1) Ctrl->In.col = INT_MAX; /* Flag we gave the 1-D index only */
331 if (Ctrl->In.row == GMT_NOTSET || Ctrl->In.col == GMT_NOTSET) {
332 GMT_Report (API, GMT_MSG_ERROR, "Unable to parse row,col|index: %s\n", opt->arg);
333 return GMT_PARSE_ERROR;
334 }
335 }
336 else { /* Default to go to next subplot */
337 Ctrl->In.row = 0;
338 Ctrl->In.next = true;
339 if (opt) opt = opt->previous; /* Since we will advance below */
340 }
341 Ctrl->In.mode = SUBPLOT_SET;
342 }
343 else if (strchr (opt->arg, ',')) { /* Implicitly called set without using the word "set" */
344 if (sscanf (opt->arg, "%d,%d", &Ctrl->In.row, &Ctrl->In.col) < 2 || Ctrl->In.row < 0 || Ctrl->In.col < 0) {
345 GMT_Report (API, GMT_MSG_ERROR, "Not a subplot command: %s\n", opt->arg);
346 return GMT_PARSE_ERROR;
347 }

Callers 1

GMT_subplotFunction · 0.70

Calls 15

GMT_ReportFunction · 0.85
gmt_is_integerFunction · 0.85
gmt_validate_modifiersFunction · 0.85
gmt_get_modifierFunction · 0.85
gmt_just_validateFunction · 0.85
gmt_just_decodeFunction · 0.85
gmt_flip_justifyFunction · 0.85
gmt_just_to_codeFunction · 0.85
gmt_get_pairFunction · 0.85
gmt_getfillFunction · 0.85
gmt_getpenFunction · 0.85
gmt_get_no_argumentFunction · 0.85

Tested by

no test coverage detected