| 18324 | } |
| 18325 | |
| 18326 | unsigned int gmt_create_array (struct GMT_CTRL *GMT, char option, struct GMT_ARRAY *T, double *min, double *max) { |
| 18327 | /* If min and max are not NULL then will override what T->min,max says */ char unit = GMT->current.setting.time_system.unit; |
| 18328 | double scale = GMT->current.setting.time_system.scale, inc = T->inc, t0, t1; |
| 18329 | |
| 18330 | if (T->array) gmt_M_free (GMT, T->array); /* Free if previously set */ |
| 18331 | |
| 18332 | if (T->file) { /* Got a file, read first column into the array; must be one segment only */ |
| 18333 | /* Temporarily change what data type col zero is */ |
| 18334 | struct GMT_DATASET *D = NULL; |
| 18335 | unsigned int save_coltype[2]; |
| 18336 | unsigned int save_trailing = GMT->current.io.trailing_text[GMT_IN]; |
| 18337 | unsigned int save_max_cols_to_read = GMT->current.io.max_cols_to_read; |
| 18338 | int error; |
| 18339 | |
| 18340 | save_coltype[GMT_IN] = gmt_get_column_type (GMT, GMT_IN, GMT_X); |
| 18341 | save_coltype[GMT_OUT] = gmt_get_column_type (GMT, GMT_OUT, GMT_X); |
| 18342 | if (T->temporal) gmt_set_column_type (GMT, GMT_IN, GMT_X, GMT_IS_ABSTIME); |
| 18343 | gmt_disable_bghio_opts (GMT); /* Do not want any -b -g -h -i -o to affect the reading this file */ |
| 18344 | GMT->current.io.record_type[GMT_IN] = GMT_READ_NORMAL; |
| 18345 | GMT->current.io.trailing_text[GMT_IN] = false; |
| 18346 | if ((error = GMT_Set_Columns (GMT->parent, GMT_IN, 1, GMT_COL_FIX_NO_TEXT)) != GMT_NOERROR) return (GMT_PARSE_ERROR); |
| 18347 | if ((D = GMT_Read_Data (GMT->parent, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_NONE, GMT_READ_NORMAL, NULL, T->file, NULL)) == NULL) { |
| 18348 | return (GMT_PARSE_ERROR); |
| 18349 | } |
| 18350 | if (gmt_get_column_type (GMT, GMT_IN, GMT_X) == GMT_IS_ABSTIME) T->temporal = true; /* We read absolute times from the file */ |
| 18351 | gmt_set_column_type (GMT, GMT_IN, GMT_X, save_coltype[GMT_IN]); |
| 18352 | gmt_set_column_type (GMT, GMT_OUT, GMT_X, save_coltype[GMT_OUT]); |
| 18353 | GMT->current.io.trailing_text[GMT_IN] = save_trailing; |
| 18354 | GMT->current.io.max_cols_to_read = save_max_cols_to_read; |
| 18355 | gmt_reenable_bghio_opts (GMT); /* Recover settings provided by user (if -b -g -h -i were used at all) */ |
| 18356 | if (D->n_segments > 1) { |
| 18357 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option %c: File %s has more than one segment\n", option, T->file); |
| 18358 | GMT_Destroy_Data (GMT->parent, &D); |
| 18359 | return GMT_PARSE_ERROR; |
| 18360 | } |
| 18361 | T->n = D->n_records; |
| 18362 | T->array = gmt_M_memory (GMT, NULL, T->n, double); |
| 18363 | gmt_M_memcpy (T->array, D->table[0]->segment[0]->data[GMT_X], T->n, double); |
| 18364 | if (D->table[0]->header && strstr (D->table[0]->header[0], "LIST")) { |
| 18365 | T->list = strdup ("LIST_GIVEN_AS_FILE"); |
| 18366 | GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Option %c: File %s will be parsed as the equivalent list\n", option, T->file); |
| 18367 | } |
| 18368 | GMT_Destroy_Data (GMT->parent, &D); |
| 18369 | if (T->unique) /* Must sort and eliminate duplicates */ |
| 18370 | T->array = gmtsupport_unique_array (GMT, T->array, &(T->n)); |
| 18371 | T->var_inc = gmtlib_var_inc (T->array, T->n); |
| 18372 | return GMT_NOERROR; |
| 18373 | } |
| 18374 | |
| 18375 | if (T->list) { /* Got a list, parse and make array */ |
| 18376 | if ((T->array = gmt_list_to_array (GMT, T->list, gmt_M_type (GMT, GMT_IN, T->col), T->unique, &(T->n))) == NULL) |
| 18377 | return GMT_PARSE_ERROR; |
| 18378 | T->var_inc = gmtlib_var_inc (T->array, T->n); |
| 18379 | T->min = T->array[0]; T->max = T->array[T->n-1]; |
| 18380 | if (T->n > 1) { /* Got at least min/max */ |
| 18381 | if (!T->var_inc) { /* Just did an alternate way to set an equidistant array */ |
| 18382 | T->inc = T->array[1] - T->array[0]; |
| 18383 | T->set = 3; |
no test coverage detected