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

Function GMT_Get_Values

src/gmt_api.c:14368–14442  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

14366
14367/*! . */
14368int GMT_Get_Values (void *V_API, const char *arg, double par[], int maxpar) {
14369 /* Parse any number of comma, space, tab, semi-colon or slash-separated values.
14370 * The array par must have enough space to hold a maximum of maxpar items.
14371 * Function returns the number of items, or GMT_NOTSET if there was an error.
14372 * When there are more than maxpar items, only the first maxpar are stored, and
14373 * the value of maxpar is returned.
14374 * We can handle dimension units (c|i|p), distance units (d|m|s|e|f|k|M|n|u),
14375 * geographic coordinates, absolute dateTtime strings, and regular floats.
14376 *
14377 * Dimensions are returned in the current length unit [inch or cm].
14378 * Distances are returned in meters.
14379 * Arc distances are returned in degrees.
14380 * Geographic dd:mm:ss[W|E|S|N] coordinates are returned in decimal degrees.
14381 * DateTtime moments are returned in time in chosen units [sec] since chosen epoch [1970] */
14382
14383 bool f_active[2], f_is_geo[2], f_is_cart[2];
14384 unsigned int pos = 0, mode, col_type_save[2][2];
14385 int npar = 0;
14386 size_t len;
14387 char p[GMT_BUFSIZ] = {""}, unit, col_set_save[2][2], f_string[GMT_LEN64];
14388
14389 double value;
14390 struct GMTAPI_CTRL *API = NULL;
14391 struct GMT_CTRL *GMT = NULL;
14392 static const char separators[] = " \t,;/";
14393
14394 if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION);
14395 if (arg == NULL || arg[0] == '\0') return_value (V_API, GMT_NO_PARAMETERS, GMT_NOTSET);
14396 API = gmtapi_get_api_ptr (V_API);
14397 GMT = API->GMT;
14398 API->error = GMT_NOERROR;
14399
14400 /* Because gmt_init_distaz and possibly gmt_scanf_arg may decide to change the GMT col_type
14401 * for x and y we make a copy here and reset when done. */
14402 gmt_M_memcpy (col_type_save[GMT_IN], GMT->current.io.col_type[GMT_IN], 2, unsigned int);
14403 gmt_M_memcpy (col_type_save[GMT_OUT], GMT->current.io.col_type[GMT_OUT], 2, unsigned int);
14404 gmt_M_memcpy (col_set_save[GMT_IN], GMT->current.io.col_set[GMT_IN], 2, char);
14405 gmt_M_memcpy (col_set_save[GMT_OUT], GMT->current.io.col_set[GMT_OUT], 2, char);
14406 /* Same goes for -f since gmt_set_geographic may be called */
14407 gmt_M_memcpy (f_active, GMT->common.f.active, 2, bool);
14408 gmt_M_memcpy (f_is_geo, GMT->common.f.is_geo, 2, bool);
14409 gmt_M_memcpy (f_is_cart, GMT->common.f.is_cart, 2, bool);
14410 gmt_M_memcpy (f_string, GMT->common.f.string, GMT_LEN64, char);
14411
14412 while (gmt_strtok (arg, separators, &pos, p)) { /* Loop over input arguments */
14413 if ((len = strlen (p)) == 0) continue;
14414 if (npar >= maxpar) { /* Bail out when already maxpar values are stored */
14415 gmtlib_report_error (API, GMT_DIM_TOO_LARGE);
14416 break;
14417 }
14418 len--; /* Position of last char, possibly a unit */
14419 if (strchr (GMT_DIM_UNITS, p[len])) /* Dimension unit (c|i|p), return distance in GMT default length unit [inch or cm] */
14420 value = gmt_convert_units (GMT, p, GMT->current.setting.proj_length_unit, GMT->current.setting.proj_length_unit);
14421 else if (strchr (GMT_LEN_UNITS, p[len])) { /* Distance units, return as meters [or degrees if arc] */
14422 mode = gmt_get_distance (GMT, p, &value, &unit);
14423 if (gmt_init_distaz (GMT, unit, mode, GMT_MAP_DIST) == GMT_NOT_A_VALID_TYPE) return_value (V_API, GMT_NOT_A_VALID_TYPE, GMT_NOTSET);
14424 value /= GMT->current.map.dist[GMT_MAP_DIST].scale; /* Convert to default unit */
14425 }

Callers 15

GMT_gmtconvertFunction · 0.85
gmt_get_pairFunction · 0.85
gmt_getpanelFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
GMT_Get_Values_Function · 0.85
parseFunction · 0.85
gmtinit_trend_modifiersFunction · 0.85
gmt_parse_vectorFunction · 0.85
parseFunction · 0.85

Calls 7

gmtapi_get_api_ptrFunction · 0.85
gmt_strtokFunction · 0.85
gmtlib_report_errorFunction · 0.85
gmt_convert_unitsFunction · 0.85
gmt_get_distanceFunction · 0.85
gmt_init_distazFunction · 0.85
gmt_scanf_argFunction · 0.85

Tested by

no test coverage detected