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

Function parse

src/grdconvert.c:141–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141static int parse (struct GMT_CTRL *GMT, struct GRDCONVERT_CTRL *Ctrl, struct GMT_OPTION *options) {
142 /* This parses the options provided to grdconvert and sets parameters in CTRL.
143 * Any GMT common options will override values set previously by other commands.
144 * It also replaces any file names specified as input or output with the data ID
145 * returned when registering these sources/destinations with the API.
146 */
147
148 unsigned int n_errors = 0, n_in = 0;
149 struct GMT_OPTION *opt = NULL;
150 struct GMTAPI_CTRL *API = GMT->parent;
151
152 for (opt = options; opt; opt = opt->next) {
153 switch (opt->option) {
154
155 case '<': /* Input and Output files */
156 /* Since grdconvert allowed output grid to be given without -G we must actually
157 * check for two input files and assign the 2nd as the actual output file */
158 if (n_in == 0) { /* First time we get the input grid */
159 n_errors += gmt_M_repeated_module_option (API, Ctrl->In.active);
160 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->In.file));
161 }
162 else if (n_in == 1) { /* 2nd time it is the output grid */
163 n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active);
164 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->G.file));
165 }
166 else { /* There is no 3rd time */
167 GMT_Report (API, GMT_MSG_ERROR, "Specify only one input file\n");
168 n_errors++;
169 }
170 n_in++;
171 break;
172 case '>': /* Output file may be set this way from the external API */
173 if (!Ctrl->G.active) { /* No output grid yet. This should be used when returning the output grid to Julia/Matlab */
174 n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active);
175 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->G.file));
176 n_in++;
177 }
178 break;
179
180 /* Processes program-specific parameters */
181
182 case 'C': /* Control history output */
183 n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active);
184 switch (opt->arg[0]) {
185 case 'b': Ctrl->C.mode = GMT_GRDHISTORY_BOTH; break;
186 case 'c': Ctrl->C.mode = GMT_GRDHISTORY_NEW; break;
187 case 'p': Ctrl->C.mode = GMT_GRDHISTORY_OLD; break;
188 case 'n': case '\0': Ctrl->C.mode = GMT_GRDHISTORY_NONE; break; /* Default */
189 default:
190 GMT_Report (API, GMT_MSG_ERROR, "Option -C: Unrecognized directive %s\n", opt->arg);
191 n_errors++;
192 break;
193 }
194 break;
195 case 'G':
196 n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active);
197 if (Ctrl->G.file) { /* Could happen if file was given on command line and via -G */
198 GMT_Report (API, GMT_MSG_ERROR, "Specify only one output file\n");

Callers 1

GMT_grdconvertFunction · 0.70

Calls 5

gmt_get_required_fileFunction · 0.85
GMT_ReportFunction · 0.85
gmt_get_no_argumentFunction · 0.85
grdconvert_parse_Z_optFunction · 0.85
gmt_default_option_errorFunction · 0.85

Tested by

no test coverage detected