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

Function gmt_get_refpoint

src/gmt_support.c:17315–17460  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

17313
17314/*! . */
17315struct GMT_REFPOINT * gmt_get_refpoint (struct GMT_CTRL *GMT, char *arg_in, char option) {
17316 /* Used to decipher option -D in psscale, pslegend, and psimage:
17317 * -D[g|j|n|x]<refpoint>[/<remainder]
17318 * where g means map coordinates, n means normalized coordinates, and x means plot coordinates.
17319 * For j we instead spacify a 2-char justification code and get the reference point from the corresponding
17320 * plot box coordinates; the <refpoint> point is the coordinate pair <x0>/<y0>.
17321 * All -D flavors except -Dx require -R -J.
17322 * Remaining arguments are returned as well via the string A->args.
17323 * also used to parse refpoint in scales -L and -T hence the option argument.
17324 */
17325 unsigned int n_errors = 0, k = 1; /* Assume 1st character tells us the mode */
17326 int n, justify = 0;
17327 enum GMT_enum_refpoint mode = GMT_REFPOINT_NOTSET;
17328 char txt_x[GMT_LEN256] = {""}, txt_y[GMT_LEN256] = {""}, the_rest[GMT_LEN256] = {""};
17329 static char *kind = GMT_REFPOINT_CODES; /* The five types of refpoint specifications */
17330 char *arg = strdup (arg_in); /* Since it may be a constant */
17331 struct GMT_REFPOINT *A = NULL;
17332
17333 switch (arg[0]) {
17334 case 'n': mode = GMT_REFPOINT_NORM; break; /* Normalized coordinates */
17335 case 'g': mode = GMT_REFPOINT_MAP; break; /* Map coordinates */
17336 case 'j': mode = GMT_REFPOINT_JUST; break; /* Map box with justification code */
17337 case 'J': mode = GMT_REFPOINT_JUST_FLIP; break; /* Map box with mirrored justification code */
17338 case 'x': mode = GMT_REFPOINT_PLOT; break; /* Plot coordinates */
17339 default: k = 0; break; /* None given, reset first arg to be at position 0 */
17340 }
17341 if (mode == GMT_REFPOINT_JUST || mode == GMT_REFPOINT_JUST_FLIP) { /* Here we know k == 1 */
17342 n = gmtsupport_find_mod_syntax_start (arg, k); /* Returns position of first modifier +? */
17343 if (arg[n]) { /* Separated via +modifiers (or nothing follows), but here we know just is 2 chars */
17344 strncpy (txt_x, &arg[k], 2); txt_x[2] = 0;
17345 strncpy (the_rest, &arg[n], GMT_LEN256-1);
17346 }
17347 else { /* Old syntax with no +modifier and with things separated by slashes */
17348 if ((n = sscanf (&arg[k], "%[^/]/%s", txt_x, the_rest)) < 1) {
17349 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Parsing of arguments (%s) failed \n", option, &arg[k]);
17350 gmt_M_str_free (arg);
17351 return NULL; /* Not so good */
17352 }
17353 }
17354 justify = gmt_just_decode (GMT, txt_x, PSL_MC);
17355 }
17356 else { /* Must worry about leading + signs in the numbers that might confuse us w.r.t. modifiers */
17357 /* E.g., -Dg123.3/+19+jTL we don't want to trip up on +19 as modifier! */
17358 n = gmtsupport_find_mod_syntax_start (arg, k);
17359 if (arg[n]) { /* Separated via +modifiers (or nothing follows) */
17360 int n2;
17361 strncpy (the_rest, &arg[n], GMT_LEN256-1);
17362 arg[n] = 0; /* Chop off modifiers temporarily */
17363 if (mode == GMT_REFPOINT_NOTSET && strlen (arg) == 2 && strchr ("LMRBCT", toupper(arg[GMT_X])) && strchr ("LMRBCT", toupper(arg[GMT_Y]))) { /* Apparently a 2-char justification code */
17364 mode = GMT_REFPOINT_JUST;
17365 GMT_Report (GMT->parent, GMT_MSG_WARNING, "Your -%c option was interpreted to mean -%c%c\n", option, option, kind[mode]);
17366 }
17367 else if (n == 0) { /* Got no reference point, default to x0/0 */
17368 strcpy (txt_x, "0"); strcpy (txt_y, "0");
17369 mode = GMT_REFPOINT_PLOT;
17370 }
17371 else if ((n2 = sscanf (&arg[k], "%[^/]/%s", txt_x, txt_y)) < 2) {
17372 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Parsing of reference point (%s) failed - expected slash-separated pair of coordinates\n", option, &arg[k]);

Callers 11

gmt_draw_map_insetFunction · 0.85
gmtsupport_getscale_oldFunction · 0.85
gmtsupport_getrose_oldFunction · 0.85
gmt_getinsetFunction · 0.85
gmt_getscaleFunction · 0.85
gmt_getroseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85

Calls 9

strdupFunction · 0.85
GMT_ReportFunction · 0.85
gmt_just_decodeFunction · 0.85
gmt_count_charFunction · 0.85
gmt_set_missing_optionsFunction · 0.85
gmt_verify_expectationsFunction · 0.85
gmt_scanfFunction · 0.85
gmt_free_refpointFunction · 0.85

Tested by

no test coverage detected