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

Function gmtapi_get_record_vector

src/gmt_api.c:10133–10189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10131}
10132
10133GMT_LOCAL struct GMT_RECORD *gmtapi_get_record_vector (struct GMTAPI_CTRL *API, unsigned int mode, int *n_fields) {
10134 /* Gets next data record from current vector */
10135 struct GMTAPI_DATA_OBJECT *S = API->current_get_obj;
10136 struct GMT_CTRL *GMT = API->GMT;
10137 struct GMT_RECORD *record;
10138 uint64_t col;
10139
10140 if (S->rec == S->n_rows) { /* Our only way of knowing we are done is to quit when we reach the number of rows that was registered */
10141 S->status = (API->allow_reuse) ? GMT_IS_UNUSED : GMT_IS_USED; /* Mark as finished reading this guy unless we may reuse */
10142 if (gmtapi_next_data_object (API, S->family, GMT_IN) == EOF) { /* That was the last source, return */
10143 *n_fields = EOF; /* EOF is ONLY returned when we reach the end of the LAST data file */
10144 GMT->current.io.status = GMT_IO_EOF;
10145 }
10146 else if (mode & GMT_READ_FILEBREAK) { /* Return empty handed to indicate a break between files */
10147 *n_fields = GMT_IO_NEXT_FILE; /* We flag this situation with a special return value */
10148 GMT->current.io.status = GMT_IO_NEXT_FILE;
10149 }
10150 else { /* Get ready to read the next data file */
10151 S = API->current_get_obj = API->object[API->current_item[GMT_IN]]; /* Shorthand for the next data source to work on */
10152 API->get_next_record = true; /* Since we haven't read the next record yet */
10153 }
10154 API->current_get_V = gmtapi_get_vector_data (S->resource);
10155 API->current_get_n_columns = (GMT->common.i.col.select) ? GMT->common.i.col.n_cols : S->n_columns;
10156 API->current_get_V_val = gmt_M_memory (GMT, API->current_get_V_val, API->current_get_V->n_columns, GMT_getfunction); /* Array of functions */
10157 for (col = 0; col < API->current_get_V->n_columns; col++) /* We know the number of columns from registration */
10158 API->current_get_V_val[col] = gmtapi_select_get_function (API, API->current_get_V->type[col]);
10159 record = NULL;
10160 }
10161 else { /* Read from this resource */
10162 struct GMT_VECTOR *V = API->current_get_V;
10163 unsigned int n_use, col_pos_out, col_pos_in;
10164 int status;
10165 S->status = GMT_IS_USING; /* Mark as being read */
10166 n_use = gmtapi_n_cols_needed_for_gaps (GMT, S->n_columns);
10167 gmtapi_update_prev_rec (GMT, n_use);
10168
10169 for (col = 0; col < API->current_get_n_columns; col++) {
10170 col_pos_out = gmtlib_pick_in_col_number (GMT, (unsigned int)col, &col_pos_in);
10171 API->current_get_V_val[col_pos_in] (&(V->data[col_pos_in]), S->rec, &(GMT->current.io.curr_rec[col_pos_out]));
10172 GMT->current.io.curr_rec[col_pos_out] = gmt_M_convert_col (GMT->current.io.col[GMT_IN][col], GMT->current.io.curr_rec[col_pos_out]);
10173 }
10174
10175 S->rec++;
10176 if ((status = gmtapi_bin_input_memory (GMT, S->n_columns, n_use)) < 0) { /* Process the data record */
10177 if (status == GMTAPI_GOT_SEGGAP) /* Since we inserted a segment header we must revisit this record as first in next segment */
10178 S->rec--, API->current_rec[GMT_IN]--;
10179 record = NULL;
10180 }
10181 else { /* Valid data record */
10182 if (V->text) /* Also have text as part of record */
10183 strncpy (GMT->current.io.curr_trailing_text, V->text[S->rec-1], GMT_BUFSIZ-1);
10184 record = &GMT->current.io.record;
10185 *n_fields = (int)API->current_get_n_columns;
10186 }
10187 }
10188 return record;
10189}
10190

Callers

nothing calls this directly

Calls 7

gmtapi_next_data_objectFunction · 0.85
gmtapi_get_vector_dataFunction · 0.85
gmtapi_update_prev_recFunction · 0.85
gmtapi_bin_input_memoryFunction · 0.85

Tested by

no test coverage detected