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

Function gmt_parse_vector

src/gmt_init.c:16809–17073  ·  view source on GitHub ↗

! Parser for -Sv|V, -S=, and -Sm */

Source from the content-addressed store, hash-verified

16807
16808/*! Parser for -Sv|V, -S=, and -Sm */
16809int gmt_parse_vector (struct GMT_CTRL *GMT, char symbol, char *text, struct GMT_SYMBOL *S) {
16810
16811 unsigned int pos = 0, k, f = 0, end, error = 0;
16812 bool p_opt = false, g_opt = false, is_grdvector = !strncmp (GMT->init.module_name, "grdvector", 9U);
16813 int j;
16814 char p[GMT_BUFSIZ], *c = NULL;
16815 double value[2];
16816
16817 S->v.pen = GMT->current.setting.map_default_pen;
16818 gmt_init_fill (GMT, &S->v.fill, -1.0, -1.0, -1.0); /* Default is no fill */
16819 S->v.status = 0; /* Start with no flags turned on */
16820 S->v.v_angle = 30.0f; /* Default apex angle */
16821 S->v.v_norm = -1.0f; /* No vector attribute shrinking with magnitude */
16822 S->v.v_norm_limit = 0.25; /* Terminal shrinkage if active */
16823 S->v.comp_scale = 1.0; /* Unity means no special scaling */
16824 S->v.v_kind[0] = S->v.v_kind[1] = PSL_VEC_ARROW;
16825 S->v.v_shape = (float)GMT->current.setting.map_vector_shape; /* Can be overridden with +h<shape> */
16826 for (k = 0; text[k] && text[k] != '+'; k++); /* Either find the first plus or run out or chars */
16827 strncpy (p, text, k); p[k] = 0;
16828
16829 while ((gmt_strtok (&text[k], "+", &pos, p))) { /* Parse any +<modifier> statements */
16830 switch (p[0]) {
16831 case 'a': /* Vector head opening angle [30] */
16832 S->v.v_angle = (float)atof (&p[1]);
16833 if (S->v.v_angle >= 180) { /* Bad apex angle */
16834 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Vector head angle cannot be >= 180 degrees\n");
16835 error++;
16836 }
16837 break;
16838 case 'b': /* Vector head at beginning point */
16839 S->v.status |= PSL_VEC_BEGIN;
16840 switch (p[1]) {
16841 case 'a': S->v.v_kind[0] = PSL_VEC_ARROW; break; /* Explicitly selected arrow head */
16842 case 'A': S->v.v_kind[0] = PSL_VEC_ARROW_PLAIN; break;
16843 case 'i': S->v.v_kind[0] = PSL_VEC_TAIL; break;
16844 case 'I': S->v.v_kind[0] = PSL_VEC_TAIL_PLAIN; break;
16845 case 'c': S->v.v_kind[0] = PSL_VEC_CIRCLE; break;
16846 case 's': S->v.v_kind[0] = PSL_VEC_SQUARE; break;
16847 case 't': S->v.v_kind[0] = PSL_VEC_TERMINAL; break;
16848 case 'l': S->v.v_kind[0] = PSL_VEC_ARROW; S->v.status |= PSL_VEC_BEGIN_L; break; /* Only left half of head requested */
16849 case 'r': S->v.v_kind[0] = PSL_VEC_ARROW; S->v.status |= PSL_VEC_BEGIN_R; break; /* Only right half of head requested */
16850 default: S->v.v_kind[0] = PSL_VEC_ARROW; break;
16851 }
16852 if (p[1] && p[2]) {
16853 if (p[2] == 'l') S->v.status |= PSL_VEC_BEGIN_L; /* Only left half of head requested */
16854 else if (p[2] == 'r') S->v.status |= PSL_VEC_BEGIN_R; /* Only right half of head requested */
16855 }
16856 break;
16857 case 'c': /* Use internal vector magnitude with CPT [MAP_VECTOR_SHAPE] */
16858 S->v.status |= PSL_VEC_MAGCPT;
16859 break;
16860 case 'e': /* Vector head at end point */
16861 S->v.status |= PSL_VEC_END;
16862 switch (p[1]) {
16863 case 'a': S->v.v_kind[1] = PSL_VEC_ARROW; break; /* Explicitly selected arrow head */
16864 case 'A': S->v.v_kind[1] = PSL_VEC_ARROW_PLAIN; break;
16865 case 'i': S->v.v_kind[1] = PSL_VEC_TAIL; break;
16866 case 'I': S->v.v_kind[1] = PSL_VEC_TAIL_PLAIN; break;

Callers 6

gmt_getpenFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
gmt_parse_symbol_optionFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85

Calls 9

gmt_init_fillFunction · 0.85
gmt_strtokFunction · 0.85
GMT_ReportFunction · 0.85
gmt_getfillFunction · 0.85
gmtinit_get_lengthFunction · 0.85
GMT_Get_ValuesFunction · 0.85
gmt_getpenFunction · 0.85
gmt_get_pairFunction · 0.85
gmt_init_vector_paramFunction · 0.85

Tested by

no test coverage detected