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

Function gmtapi_read_vector

src/gmt_api.c:7347–7469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7345}
7346
7347GMT_LOCAL struct GMT_VECTOR *gmtapi_read_vector (struct GMT_CTRL *GMT, void *source, unsigned int src_type, unsigned int mode) {
7348 /* We read the VECTOR from fp [or stdin].
7349 * src_type can be GMT_IS_[FILE|STREAM|FDESC]
7350 * mode is not used yet. We only do ascii file for now - later need to deal with -b
7351 */
7352
7353 bool close_file = false, first = true, add_first_segheader = false, in_header_section = true;
7354 unsigned int pos;
7355 uint64_t nt_alloc = 0, nh_alloc = 0, n_headers = 0, row = 0, n_col, col, dim[GMT_DIM_SIZE] = {0, 0, GMT->current.setting.export_type, 0};
7356 char V_file[PATH_MAX] = {""};
7357 char line[GMT_BUFSIZ] = {""};
7358 char **text = NULL, **header = NULL;
7359 FILE *fp = NULL;
7360 struct GMT_VECTOR *V = NULL;
7361 GMT_putfunction api_put_val = NULL;
7362 gmt_M_unused(mode);
7363
7364 if (GMT->common.b.active[GMT_IN]) {
7365 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Opening Vector file %s in binary mode not yet supported\n");
7366 return_null (GMT->parent, GMT_ERROR_ON_FOPEN);
7367 }
7368
7369 if (src_type == GMT_IS_FILE && !source) src_type = GMT_IS_STREAM; /* No filename given, default to stdin */
7370
7371 if (src_type == GMT_IS_FILE) { /* dest is a file name */
7372 strncpy (V_file, source, PATH_MAX-1);
7373 if ((fp = gmt_fopen (GMT, V_file, "r")) == NULL) {
7374 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Cannot open Vector file %s\n", V_file);
7375 return_null (GMT->parent, GMT_ERROR_ON_FOPEN);
7376 }
7377 close_file = true; /* We only close files we have opened here */
7378 }
7379 else if (src_type == GMT_IS_STREAM) { /* Open file pointer given, just copy */
7380 fp = (FILE *)source;
7381 if (fp == NULL) fp = GMT->session.std[GMT_IN]; /* Default destination */
7382 if (fp == GMT->session.std[GMT_IN])
7383 strcpy (V_file, "<stdin>");
7384 else
7385 strcpy (V_file, "<input stream>");
7386 }
7387 else if (src_type == GMT_IS_FDESC) { /* Open file descriptor given, just convert to file pointer */
7388 int *fd = source;
7389 if (fd && (fp = fdopen (*fd, "r")) == NULL) {
7390 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Cannot convert Vector file descriptor %d to stream in gmtapi_read_vector\n", *fd);
7391 return_null (GMT->parent, GMT_ERROR_ON_FDOPEN);
7392 }
7393 if (fd == NULL) fp = GMT->session.std[GMT_IN]; /* Default destination */
7394 if (fp == GMT->session.std[GMT_IN])
7395 strcpy (V_file, "<stdin>");
7396 else
7397 strcpy (V_file, "<input file descriptor>");
7398 close_file = true; /* since fdopen allocates space */
7399 }
7400 else {
7401 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Unrecognized source type %d in gmtapi_read_vector\n", src_type);
7402 return_null (GMT->parent, GMT_NOT_A_VALID_METHOD);
7403 }
7404 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Read Vector from %s\n", V_file);

Callers 1

gmtapi_import_vectorFunction · 0.85

Calls 11

GMT_ReportFunction · 0.85
gmt_fopenFunction · 0.85
gmt_chopFunction · 0.85
strdupFunction · 0.85
gmt_prep_tmp_arraysFunction · 0.85
gmtlib_conv_text2datarecFunction · 0.85
GMT_Create_DataFunction · 0.85
gmt_fcloseFunction · 0.85
gmt_get_V_hiddenFunction · 0.85
GMT_Put_StringsFunction · 0.85

Tested by

no test coverage detected