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

Function parse

src/grdimage.c:258–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256EXTERN_MSC int gmtlib_read_grd_info(struct GMT_CTRL *GMT, char *file, struct GMT_GRID_HEADER *header);
257
258static int parse(struct GMT_CTRL *GMT, struct GRDIMAGE_CTRL *Ctrl, struct GMT_OPTION *options) {
259 /* This parses the options provided to grdimage and sets parameters in Ctrl.
260 * Note Ctrl has already been initialized and non-zero default values set.
261 * Any GMT common options will override values set previously by other commands.
262 * It also replaces any file names specified as input or output with the data ID
263 * returned when registering these sources/destinations with the API.
264 */
265
266 unsigned int n_errors = 0, n_files = 0, ind, off, k;
267 char *c = NULL, *file[3] = {NULL, NULL, NULL}, *f = NULL;
268 struct GMT_OPTION *opt = NULL;
269 struct GMTAPI_CTRL *API = GMT->parent;
270 size_t n;
271 for (opt = options; opt; opt = opt->next) { /* Process all the options given */
272
273 switch (opt->option) {
274 case '<': /* Input file (only one or three is accepted) */
275 Ctrl->In.active = true;
276 if (n_files >= 3) {n_errors++; continue; }
277 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_GRID, GMT_IN, GMT_FILE_REMOTE, &(file[n_files]));
278 n_files++;
279 break;
280 case '>': /* Output file (probably for -A via external interface) */
281 n_errors += gmt_M_repeated_module_option (API, Ctrl->Out.active);
282 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_IMAGE, GMT_OUT, GMT_FILE_REMOTE, &(Ctrl->Out.file));
283 break;
284
285 /* Processes program-specific parameters */
286
287 case 'A': /* Get image file name plus driver name to write via GDAL */
288 n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active);
289 if (API->external) { /* External interface only */
290 if ((n = strlen (opt->arg)) > 0) {
291 GMT_Report (API, GMT_MSG_ERROR, "Option -A: No output argument allowed\n");
292 n_errors++;
293 }
294 Ctrl->A.return_image = true;
295 Ctrl->A.way = 1; /* Building image directly, use TRPa layout, no call to GDAL */
296 }
297 else if ((n = strlen (opt->arg)) == 0) {
298 GMT_Report (API, GMT_MSG_ERROR, "Option -A: No output name provided\n");
299 n_errors++;
300 }
301 else if (gmt_M_file_is_memory (opt->arg)) {
302 Ctrl->A.file = strdup (opt->arg);
303 Ctrl->A.way = 1; /* Building image directly, use TRPa layout, no call to GDAL */
304 }
305 else if ((c = gmt_get_ext (opt->arg)) && !strcmp (c, "ppm")) { /* Want a ppm image which we can do without GDAL */
306 Ctrl->A.file = strdup (opt->arg);
307 Ctrl->A.way = 1; /* Building image directly, use TRP layout, no call to GDAL, writing a PPM file */
308 }
309 else { /* Must give file and GDAL driver */
310 Ctrl->A.file = strdup (opt->arg);
311 while (Ctrl->A.file[n] != '=' && n > 0) n--;
312 if (n == 0) { /* Gave no driver, see if we requested one of the standard image formats */
313 n = strlen (Ctrl->A.file) - 1;
314 while (n && Ctrl->A.file[n] != '.') n--;
315 if (n == 0) { /* Gave no image extension either... */

Callers 1

GMT_grdimageFunction · 0.70

Calls 15

gmt_get_required_fileFunction · 0.85
GMT_ReportFunction · 0.85
strdupFunction · 0.85
gmt_get_extFunction · 0.85
gmt_strrstrFunction · 0.85
gmt_getrgbFunction · 0.85
gmt_rgb_syntaxFunction · 0.85
gmt_first_modifierFunction · 0.85
gmt_getmodoptFunction · 0.85
gmt_accessFunction · 0.85
gmt_is_floatFunction · 0.85

Tested by

no test coverage detected