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

Function parse

src/gmtsimplify.c:99–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99static int parse (struct GMT_CTRL *GMT, struct GMTSIMPLIFY_CTRL *Ctrl, struct GMT_OPTION *options) {
100 /* This parses the options provided to gmtsimplify and sets parameters in CTRL.
101 * Any GMT common options will override values set previously by other commands.
102 * It also replaces any file names specified as input or output with the data ID
103 * returned when registering these sources/destinations with the API.
104 */
105
106 unsigned int n_errors = 0;
107 struct GMT_OPTION *opt = NULL;
108 struct GMTAPI_CTRL *API = GMT->parent;
109
110 for (opt = options; opt; opt = opt->next) {
111 switch (opt->option) {
112
113 case '<': /* Skip input files after checking they exist */
114 if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++;
115 break;
116 case '>': /* Write to named output file instead of stdout */
117 n_errors += gmt_M_repeated_module_option (API, Ctrl->Out.active);
118 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_DATASET, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->Out.file));
119 break;
120
121 /* Processes program-specific parameters */
122
123 case 'T': /* Set tolerance distance */
124 n_errors += gmt_M_repeated_module_option (API, Ctrl->T.active);
125 Ctrl->T.mode = gmt_get_distance (GMT, opt->arg, &(Ctrl->T.tolerance), &(Ctrl->T.unit));
126 break;
127
128 default: /* Report bad options */
129 n_errors += gmt_default_option_error (GMT, opt);
130 break;
131 }
132 }
133
134 n_errors += gmt_M_check_condition (GMT, Ctrl->T.mode == -1, "Option -T: Unrecognized unit.\n");
135 n_errors += gmt_M_check_condition (GMT, Ctrl->T.mode == -2, "Option -T: Unable to decode tolerance distance.\n");
136 n_errors += gmt_M_check_condition (GMT, Ctrl->T.mode == -3, "Option -T: Tolerance is negative.\n");
137 if (GMT->common.b.active[GMT_IN] && GMT->common.b.ncol[GMT_IN] == 0) GMT->common.b.ncol[GMT_IN] = 2;
138 n_errors += gmt_M_check_condition (GMT, GMT->common.b.active[GMT_IN] && GMT->common.b.ncol[GMT_IN] < 2, "Binary input data (-bi) must have at least 2 columns.\n");
139
140 return (n_errors ? GMT_PARSE_ERROR : GMT_NOERROR);
141}
142
143#define GMT_sqr(x) ((x)*(x))
144

Callers 1

GMT_gmtsimplifyFunction · 0.70

Calls 4

GMT_Get_FilePathFunction · 0.85
gmt_get_required_fileFunction · 0.85
gmt_get_distanceFunction · 0.85
gmt_default_option_errorFunction · 0.85

Tested by

no test coverage detected