| 277 | #define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);} |
| 278 | |
| 279 | EXTERN_MSC int GMT_gmtsimplify (void *V_API, int mode, void *args) { |
| 280 | int error; |
| 281 | unsigned int smode = GMT_NO_STRINGS; |
| 282 | bool geo, poly, skip; |
| 283 | uint64_t tbl, col, row, seg_in, seg_out, np_out, ns_in = 0, ns_out = 0, n_in_tbl, *index = NULL; |
| 284 | uint64_t dim_out[4] = {1, 0, 0, 0}, n_saved; |
| 285 | |
| 286 | double tolerance; |
| 287 | |
| 288 | struct GMT_DATASET *D[2] = {NULL, NULL}; |
| 289 | struct GMT_DATASEGMENT *S[2] = {NULL, NULL}; |
| 290 | struct GMTSIMPLIFY_CTRL *Ctrl = NULL; |
| 291 | struct GMT_CTRL *GMT = NULL, *GMT_cpy = NULL; |
| 292 | struct GMT_OPTION *options = NULL; |
| 293 | struct GMTAPI_CTRL *API = gmt_get_api_ptr (V_API); /* Cast from void to GMTAPI_CTRL pointer */ |
| 294 | |
| 295 | /*----------------------- Standard module initialization and parsing ----------------------*/ |
| 296 | |
| 297 | if (API == NULL) return (GMT_NOT_A_SESSION); |
| 298 | if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ |
| 299 | options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ |
| 300 | |
| 301 | if ((error = gmt_report_usage (API, options, 0, usage)) != GMT_NOERROR) bailout (error); /* Give usage if requested */ |
| 302 | |
| 303 | /* Parse the command-line arguments */ |
| 304 | |
| 305 | if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, module_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */ |
| 306 | if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error); |
| 307 | Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */ |
| 308 | if ((error = parse (GMT, Ctrl, options)) != 0) Return (error); |
| 309 | |
| 310 | /*---------------------------- This is the gmtsimplify main code ----------------------------*/ |
| 311 | |
| 312 | GMT_Report (API, GMT_MSG_INFORMATION, "Processing input table data\n"); |
| 313 | if (Ctrl->T.mode > 1) { |
| 314 | GMT_Report (API, GMT_MSG_INFORMATION, "gmtsimplify only implemented using Flat-Earth calculations.\n"); |
| 315 | Ctrl->T.mode = 1; /* Limited to Flat Earth calculations for now */ |
| 316 | } |
| 317 | |
| 318 | /* Now we are ready to take on some input values */ |
| 319 | /* Allocate memory and read in all the files; each file can have many lines */ |
| 320 | |
| 321 | /* We read as lines even though some/all segments could be polygons. */ |
| 322 | if (GMT_Init_IO (API, GMT_IS_DATASET, GMT_IS_LINE, GMT_IN, GMT_ADD_DEFAULT, 0, options) != GMT_NOERROR) { /* Establishes data input */ |
| 323 | Return (API->error); |
| 324 | } |
| 325 | if ((D[GMT_IN] = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, 0, GMT_READ_NORMAL, NULL, NULL, NULL)) == NULL) { |
| 326 | Return (API->error); |
| 327 | } |
| 328 | if (D[GMT_IN]->n_columns < 2) { |
| 329 | GMT_Report (API, GMT_MSG_ERROR, "Input data have %d column(s) but at least 2 are needed\n", (int)D[GMT_IN]->n_columns); |
| 330 | Return (GMT_DIM_TOO_SMALL); |
| 331 | } |
| 332 | geo = gmt_M_is_geographic (GMT, GMT_IN); /* true for lon/lat coordinates */ |
| 333 | if (!geo && strchr (GMT_LEN_UNITS, (int)Ctrl->T.unit)) geo = true; /* Used units but did not set -fg; implicitly set -fg via geo */ |
| 334 | |
| 335 | if (gmt_init_distaz (GMT, Ctrl->T.unit, Ctrl->T.mode, GMT_MAP_DIST) == GMT_NOT_A_VALID_TYPE) /* Initialize distance scalings according to unit selected */ |
| 336 | Return (GMT_NOT_A_VALID_TYPE); |
nothing calls this directly
no test coverage detected