! . */
| 8177 | |
| 8178 | /*! . */ |
| 8179 | struct GMT_DATATABLE *gmtlib_read_table(struct GMT_CTRL *GMT, void *source, unsigned int source_type, bool greenwich, unsigned int *geometry, unsigned int *data_type, bool use_GMT_io) { |
| 8180 | /* Reads an entire data set into a single table in memory with any number of segments */ |
| 8181 | |
| 8182 | bool ASCII, close_file = false, header = true, no_segments, first_seg = true, poly, this_is_poly = false; |
| 8183 | bool pol_check, check_geometry; |
| 8184 | int status = 0; |
| 8185 | uint64_t n_expected_fields, n_returned = 0; |
| 8186 | uint64_t n_read = 0, row = 0, seg = 0, col, n_poly_seg = 0, k; |
| 8187 | size_t n_head_alloc = GMT_TINY_CHUNK; |
| 8188 | char open_mode[4] = {""}, file[PATH_MAX] = {""}, line[GMT_LEN64] = {""}; |
| 8189 | double d; |
| 8190 | struct GMT_RECORD *In = NULL; |
| 8191 | FILE *fp = NULL; |
| 8192 | struct GMT_DATATABLE *T = NULL; |
| 8193 | struct GMT_DATASEGMENT *S = NULL; |
| 8194 | struct GMT_DATATABLE_HIDDEN *TH = NULL; |
| 8195 | struct GMT_DATASEGMENT_HIDDEN *SH = NULL; |
| 8196 | void * (*psave) (struct GMT_CTRL *, FILE *, uint64_t *, int *) = NULL; /* Pointer to function reading tables */ |
| 8197 | |
| 8198 | if (use_GMT_io) { /* Use GMT->current.io.info settings to determine if input is ASCII/binary, else it defaults to ASCII */ |
| 8199 | if (GMT->common.b.active[GMT_IN]) { /* May return fewer than # of binary columns if -i was set */ |
| 8200 | n_returned = (GMT->common.i.col.select) ? GMT->common.i.col.n_cols : GMT->common.b.ncol[GMT_IN]; |
| 8201 | n_expected_fields = GMT->common.b.ncol[GMT_IN]; |
| 8202 | } |
| 8203 | else |
| 8204 | n_expected_fields = GMT_MAX_COLUMNS; |
| 8205 | strcpy (open_mode, GMT->current.io.r_mode); |
| 8206 | ASCII = !GMT->common.b.active[GMT_IN]; |
| 8207 | } |
| 8208 | else { /* Force ASCII mode */ |
| 8209 | n_expected_fields = GMT_MAX_COLUMNS; /* GMT->current.io.input will return the number of columns */ |
| 8210 | strcpy (open_mode, "r"); |
| 8211 | ASCII = true; |
| 8212 | psave = GMT->current.io.input; /* Save the previous pointer since we need to change it back at the end */ |
| 8213 | GMT->current.io.input = GMT->session.input_ascii; /* Override and use ASCII mode */ |
| 8214 | } |
| 8215 | |
| 8216 | #ifdef SET_IO_MODE |
| 8217 | if (!ASCII) gmt_setmode (GMT, GMT_IN); |
| 8218 | #endif |
| 8219 | |
| 8220 | if (ASCII && *geometry == GMT_IS_TEXT) { |
| 8221 | psave = GMT->current.io.input; /* Save the previous pointer since we need to change it back at the end */ |
| 8222 | GMT->current.io.input = &gmtlib_ascii_textinput; /* Override and use ASCII text mode */ |
| 8223 | GMT->current.io.record_type[GMT_IN] = *data_type = GMT_READ_TEXT; |
| 8224 | } |
| 8225 | |
| 8226 | /* Determine input source */ |
| 8227 | |
| 8228 | if (source_type == GMT_IS_FILE) { /* source is a file name */ |
| 8229 | strncpy (file, source, PATH_MAX-1); |
| 8230 | if ((fp = gmt_fopen (GMT, file, open_mode)) == NULL) { |
| 8231 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "Cannot open file %s\n", file); |
| 8232 | if (!use_GMT_io) GMT->current.io.input = psave; /* Restore previous setting */ |
| 8233 | return (NULL); |
| 8234 | } |
| 8235 | close_file = true; /* We only close files we have opened here */ |
| 8236 | } |
no test coverage detected