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

Function gmtapi_export_dataset

src/gmt_api.c:4284–4561  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

4282
4283/*! . */
4284GMT_LOCAL int gmtapi_export_dataset (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_DATASET *D_obj) {
4285 /* Does the actual work of writing out the specified data set to a single destination.
4286 * If object_ID == GMT_NOTSET we use the first registered output destination, otherwise we just use the one specified.
4287 * See the GMT API documentation for how mode is used to create multiple files from segments or tables of a dataset.
4288 */
4289 int item, error, default_method;
4290 unsigned int method, hdr;
4291 uint64_t tbl, col, kol, row_out, row, seg, ij, n_columns, n_rows;
4292 bool save, diff_types = false, toggle;
4293 double value;
4294 p_func_uint64_t GMT_2D_to_index = NULL;
4295 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
4296 struct GMT_DATASET *D_copy = NULL;
4297 struct GMT_MATRIX *M_obj = NULL;
4298 struct GMT_VECTOR *V_obj = NULL;
4299 struct GMT_MATRIX_HIDDEN *MH = NULL;
4300 struct GMT_VECTOR_HIDDEN *VH = NULL;
4301 struct GMT_DATASEGMENT *S = NULL;
4302 struct GMT_DATASET_HIDDEN *DH = NULL;
4303 struct GMT_CTRL *GMT = API->GMT;
4304 void *ptr = NULL;
4305 GMT_putfunction api_put_val = NULL;
4306
4307 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_dataset: Passed ID = %d and mode = %d\n", object_ID, mode);
4308
4309 if (object_ID == GMT_NOTSET) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET));
4310 if ((item = gmtlib_validate_id (API, GMT_IS_DATASET, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error));
4311
4312 S_obj = API->object[item]; /* S is the object whose data we will export */
4313 if (S_obj->family != GMT_IS_DATASET) return (gmtlib_report_error (API, GMT_NOT_A_VALID_FAMILY)); /* Called with wrong data type */
4314 if (S_obj->status != GMT_IS_UNUSED && !(mode & GMT_IO_RESET)) /* Only allow writing of a data set once unless overridden by mode */
4315 return (gmtlib_report_error (API, GMT_WRITTEN_ONCE));
4316 if (mode & GMT_IO_RESET) mode -= GMT_IO_RESET; /* Remove the reset bit */
4317 if (mode >= GMT_WRITE_TABLE && !S_obj->filename) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET)); /* Must have filename when segments are to be written */
4318 default_method = GMT_IS_FILE;
4319 if (S_obj->filename) /* Write to this file */
4320 ptr = S_obj->filename;
4321 else { /* No filename so we switch default method to writing to a stream or fdesc */
4322 default_method = (S_obj->method == GMT_IS_FILE) ? GMT_IS_STREAM : S_obj->method;
4323 ptr = S_obj->fp;
4324#ifdef SET_IO_MODE
4325 gmt_setmode (GMT, GMT_OUT); /* Windows may need to switch write mode from text to binary */
4326#endif
4327 }
4328 gmt_set_dataset_minmax (GMT, D_obj); /* Update all counters and min/max arrays */
4329 if (API->GMT->common.o.col.end || GMT->common.o.col.text) /* Asked for unspecified last column on input (e.g., -i3,2,5:), supply the missing last column number */
4330 gmt_reparse_o_option (GMT, (GMT->common.o.col.text) ? 0 : D_obj->n_columns);
4331 toggle = (GMT->current.setting.io_lonlat_toggle[GMT_OUT] && D_obj->n_columns >= 2);
4332 GMT->current.io.data_record_number_in_tbl[GMT_OUT] = GMT->current.io.data_record_number_in_seg[GMT_OUT] = 0;
4333 DH = gmt_get_DD_hidden (D_obj);
4334 DH->io_mode = mode; /* Handles if tables or segments should be written to separate files, according to mode */
4335 method = gmtapi_set_method (S_obj); /* Get the actual method to use */
4336 switch (method) { /* File, array, stream, etc. */
4337 case GMT_IS_STREAM:
4338#ifdef SET_IO_MODE
4339 gmt_setmode (GMT, GMT_OUT); /* Windows may need to switch write mode from text to binary */
4340#endif
4341 case GMT_IS_FILE:

Callers 1

gmtapi_export_dataFunction · 0.85

Calls 15

GMT_ReportFunction · 0.85
gmtlib_report_errorFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmt_setmodeFunction · 0.85
gmt_set_dataset_minmaxFunction · 0.85
gmt_reparse_o_optionFunction · 0.85
gmt_get_DD_hiddenFunction · 0.85
gmtapi_set_methodFunction · 0.85
gmtlib_write_datasetFunction · 0.85
gmt_duplicate_datasetFunction · 0.85
gmtapi_switch_colsFunction · 0.85

Tested by

no test coverage detected