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

Function gmtapi_import_dataset

src/gmt_api.c:3783–4216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3781
3782/*! . */
3783GMT_LOCAL struct GMT_DATASET *gmtapi_import_dataset(struct GMTAPI_CTRL *API, int object_ID, unsigned int mode) {
3784 /* Does the actual work of loading in the entire virtual data set (possibly via many sources)
3785 * If object_ID == GMT_NOTSET we get all registered input tables, otherwise we just get the one requested.
3786 * Note: Memory is allocated for the Dataset except for method GMT_IS_REFERENCE.
3787 */
3788
3789 int item, first_item = 0, this_item = GMT_NOTSET, last_item, new_item, new_ID, status;
3790 unsigned int geometry = GMT_IS_PLP, n_used = 0, method, smode, type = GMT_READ_DATA, col_pos_out;
3791 bool allocate = false, update = false, diff_types, use_GMT_io, greenwich = true;
3792 bool via = false, got_data = false, check_col_switch = false, regit = false;
3793 size_t n_alloc, s_alloc = GMT_SMALL_CHUNK;
3794 uint64_t tbl = 0, tbl_in, row, seg, col, ij, n_records = 0, n_columns = 0, col_pos, n_use;
3795 p_func_uint64_t GMT_2D_to_index = NULL;
3796 GMT_getfunction api_get_val = NULL;
3797 struct GMT_DATASET *D_obj = NULL, *Din_obj = NULL;
3798 struct GMT_DATASEGMENT *S = NULL;
3799 struct GMT_MATRIX *M_obj = NULL;
3800 struct GMT_VECTOR *V_obj = NULL;
3801 struct GMT_DATASET_HIDDEN *DH = NULL, *DHi = NULL;
3802 struct GMT_DATATABLE_HIDDEN *TH = NULL;
3803 struct GMT_DATASEGMENT_HIDDEN *SH = NULL;
3804 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
3805 struct GMT_CTRL *GMT = API->GMT;
3806
3807 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_import_dataset: Passed ID = %d and mode = %d\n", object_ID, mode);
3808
3809 if (object_ID == GMT_NOTSET) { /* Means there is more than one source: Merge all registered data tables into a single virtual data set */
3810 last_item = API->n_objects - 1; /* Must check all registered objects */
3811 allocate = true;
3812 n_alloc = GMT_TINY_CHUNK; /* We don't expect that many files to be given initially */
3813 }
3814 else { /* Requested a single, specific data table/file */
3815 int flag = (API->module_input) ? GMTAPI_MODULE_INPUT : GMTAPI_OPTION_INPUT; /* Needed by Validate_ID */
3816 if ((first_item = gmtlib_validate_id (API, GMT_IS_DATASET, object_ID, GMT_IN, flag)) == GMT_NOTSET)
3817 return_null (API, API->error);
3818 last_item = first_item;
3819 n_alloc = 1;
3820 }
3821
3822 /* Allocate a single data set and an initial allocated list of n_alloc tables */
3823 if ((D_obj = gmt_get_dataset (GMT)) == NULL) return NULL;
3824 DH = gmt_get_DD_hidden (D_obj);
3825 if ((D_obj->table = gmt_M_memory (GMT, NULL, n_alloc, struct GMT_DATATABLE *)) == NULL) return NULL;
3826 DH->alloc_mode = GMT_ALLOC_INTERNALLY; /* So GMT_* modules can free this memory (may override below) */
3827 DH->alloc_level = GMT->hidden.func_level; /* So GMT_* modules can free this memory (may override below) */
3828 use_GMT_io = !(mode & GMT_IO_ASCII); /* false if we insist on ASCII reading */
3829 GMT->current.io.seg_no = GMT->current.io.rec_no = GMT->current.io.rec_in_tbl_no = GMT->current.io.data_record_number_in_tbl[GMT_IN] = GMT->current.io.data_record_number_in_seg[GMT_IN] = 0; /* Reset for each new dataset */
3830 if (GMT->common.R.active[RSET] && GMT->common.R.wesn[XLO] < -180.0 && GMT->common.R.wesn[XHI] > -180.0) greenwich = false;
3831
3832 for (item = first_item; item <= last_item; item++) { /* Look through all sources for registered inputs (or just one) */
3833 S_obj = API->object[item]; /* S_obj is the current data object */
3834 if (!S_obj) { /* Probably not a good sign. NOTE: Probably cannot happen since skipped in api_next_source, no? */
3835 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_import_dataset: Skipped empty object (item = %d)\n", item);
3836 continue;
3837 }
3838 if (!S_obj->selected) continue; /* Registered, but not selected */
3839 if (S_obj->direction == GMT_OUT) continue; /* We're doing reading here, so skip output objects */
3840 if (S_obj->family != GMT_IS_DATASET) continue; /* We're doing datasets here, so skip other data types */

Callers 1

gmtapi_import_dataFunction · 0.85

Calls 15

GMT_ReportFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmt_get_datasetFunction · 0.85
gmt_get_DD_hiddenFunction · 0.85
gmtapi_set_methodFunction · 0.85
gmt_setmodeFunction · 0.85
gmtapi_methodFunction · 0.85
gmtlib_read_tableFunction · 0.85
gmt_get_DT_hiddenFunction · 0.85
gmt_set_dataset_verifyFunction · 0.85
gmt_duplicate_datasetFunction · 0.85

Tested by

no test coverage detected