-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathgmt_io.c
More file actions
10343 lines (9476 loc) · 432 KB
/
gmt_io.c
File metadata and controls
10343 lines (9476 loc) · 432 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*--------------------------------------------------------------------
*
* Copyright (c) 1991-2026 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
* See LICENSE.TXT file for copying and redistribution conditions.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Contact info: www.generic-mapping-tools.org
*--------------------------------------------------------------------*/
/*
* Table input/output in GMT can be either ASCII, binary, or netCDF COARDS files
* and may consist of single or multiple segments. These files are accessed
* via the GMT->current.io.input function pointer which either points to the
* ASCII read (gmtio_ascii_input), the binary read (gmtio_bin_input), or the
* netCDF read (gmtio_nc_input) functions, depending on the -bi setting.
* Similarly, writing of such tables are done via the GMT->current.io.output
* function pointer which is set to either gmtio_ascii_output, gmtio_bin_output,
* or GMT_nc_output [not implemented yet].
* For special processing of z-data by xyz2grd & grd2xyz we also use the
* GMT->current.io.input/output functions but these are reset in those two
* programs to the corresponding read/write functions pointed to by the
* GMT_Z_IO member ->read_item or ->write_item as these can handle additional
* binary data types such as char, int, short etc.
* The structure GMT_IO holds parameters that are used during the reading
* and processing of ASCII tables. For compliance with a wide variety of
* binary data formats for grids and their internal nesting the GMT_Z_IO
* structure and associated functions are used (in xyz2grd and grd2xyz)
*
* The following functions are here:
*
* A) List of exported gmt_* functions available to modules and libraries via gmt_dev.h:
*
* gmt_access
* gmt_add_to_record
* gmt_adjust_dataset
* gmt_alloc_dataset
* gmt_alloc_segment
* gmt_ascii_format_col
* gmt_ascii_format_inc
* gmt_ascii_format_one
* gmt_ascii_output_col
* gmt_ascii_output_no_text
* gmt_byteswap_file
* gmt_cat_to_record
* gmt_check_abstime_format
* gmt_check_z_io
* gmt_convert_double
* gmt_create_table
* gmt_create_vector
* gmt_disable_bghio_opts
* gmt_duplicate_dataset
* gmt_duplicate_ogr_seg
* gmt_duplicate_segment
* gmt_eliminate_lon_jumps
* gmt_extract_label
* gmt_fclose
* gmt_fgets
* gmt_find_range
* gmt_fopen
* gmt_format_abstime_output
* gmt_free_dataset
* gmt_free_segment
* gmt_free_table
* gmt_free_vector
* gmt_get_aspatial_value
* gmt_get_cols
* gmt_get_dataset
* gmt_get_filename
* gmt_get_io_type
* gmt_get_ogr_id
* gmt_get_precision_width
* gmt_get_segment
* gmt_get_table
* gmt_getdatapath
* gmt_getsharepath
* gmt_increase_abstime_format_precision
* gmt_init_z_io
* gmt_input_col_is_nan_proxy
* gmt_insert_tableheader
* gmt_is_a_blank_line
* gmt_is_float
* gmt_list_aspatials
* gmt_load_aspatial_string
* gmt_lon_range_adjust
* gmt_not_numeric
* gmt_parse_segment_header
* gmt_parse_segment_item
* gmt_parse_z_io
* gmt_polygon_is_hole
* gmt_quad_add
* gmt_quad_finalize
* gmt_quad_init
* gmt_quad_reset
* gmt_quit_bad_record
* gmt_realloc_dataset
* gmt_reenable_bghio_opts
* gmt_remove_file
* gmt_rename_file
* gmt_replace_backslash_in_path
* gmt_scanf
* gmt_scanf_arg
* gmt_scanf_argtime
* gmt_scanf_float
* gmt_set_cartesian
* gmt_set_cols
* gmt_set_column_type
* gmt_set_column_types
* gmt_set_dataset_minmax
* gmt_set_dataset_verify
* gmt_set_geographic
* gmt_set_seg_minmax
* gmt_set_seg_polar
* gmt_set_segmentheader
* gmt_set_tableheader
* gmt_set_tbl_minmax
* gmt_set_xycolnames
* gmt_set_z_io
* gmt_skip_output
* gmt_skip_xy_duplicates
* gmt_strncpy
* gmt_transpose_dataset
* gmt_write_segmentheader
* gmt_z_input
* gmt_z_output
*
* B) List of exported gmtlib_* functions available to libraries via gmt_internals.h:
*
* gmtlib_alloc_univector
* gmtlib_alloc_vectors
* gmtlib_append_ogr_item
* gmtlib_ascii_output_trailing_text
* gmtlib_ascii_textinput
* gmtlib_assign_segment
* gmtlib_assign_vector
* gmtlib_change_out_dataset
* gmtlib_clock_C_format
* gmtlib_conv_text2datarec
* gmtlib_create_dataset
* gmtlib_create_image
* gmtlib_create_matrix
* gmtlib_date_C_format
* gmtlib_determine_pole
* gmtlib_duplicate_image
* gmtlib_duplicate_matrix
* gmtlib_duplicate_ogr
* gmtlib_duplicate_vector
* gmtlib_finalize_dataset
* gmtlib_free_dataset_misc
* gmtlib_free_dataset_ptr
* gmtlib_free_dir_list
* gmtlib_free_image
* gmtlib_free_image_ptr
* gmtlib_free_matrix
* gmtlib_free_matrix_ptr
* gmtlib_free_ogr
* gmtlib_free_vector_ptr
* gmtlib_gap_detected
* gmtlib_geo_C_format
* gmtlib_geo_to_dms
* gmtlib_get_dir_list
* gmtlib_get_dirs
* gmtlib_get_lon_minmax
* gmtlib_getuserpath
* gmtlib_io_banner
* gmtlib_io_binary_header
* gmtlib_io_init
* gmtlib_maybe_abstime
* gmtlib_modulo_time_calculator
* gmtlib_nc_get_att_text
* gmtlib_nc_get_att_vtext
* gmtlib_nc_put_att_vtext
* gmtlib_ogr_get_type
* gmtlib_plot_C_format
* gmtlib_process_binary_input
* gmtlib_read_table
* gmtlib_reset_input
* gmtlib_scanf_geodim
* gmtlib_set_bin_io
* gmtlib_set_gap
* gmtlib_union_transpose
* gmtlib_valid_filemodifiers
* gmtlib_write_dataset
* gmtlib_write_newheaders
* gmtlib_write_ogr_header
* gmtlib_write_tableheader
*
* Author: Paul Wessel
* Date: 1-JAN-2010
* Version: 5
* Now 64-bit enabled.
*/
/*!
* \file gmt_io.c
* \brief gmt_io.c Table input/output in GMT
*/
#include "gmt_dev.h"
#include "gmt_internals.h"
#ifdef HAVE_DIRENT_H_
# include <dirent.h>
#endif
#ifdef HAVE_SYS_DIR_H_
# include <sys/dir.h>
#endif
#ifndef DT_DIR
# define DT_DIR 4
#endif
#ifdef _WIN32
#include <windows.h>
#endif
#define return_null(GMT,err) { GMT->parent->error = err; return (NULL);}
static const char *GMT_type[GMT_N_TYPES] = {"byte", "byte", "integer", "integer", "integer", "integer",
"integer", "integer", "double", "double", "string", "datetime"};
static const char *GMT_coltype_name[] = {"String", "Number", "Latitude", "Longitude", "Geographic", "RelTime", "AbsTime", "Duration", "Dimension", "Length", "Azimuth", "Angle", "String"};
/* Byteswap widths used with gmt_byteswap_file */
typedef enum {
Int16len = 2,
Int32len = 4,
Int64len = 8
} SwapWidth;
/* Indices into the 4 proj strings possible in GMT/OGR files */
enum GMTIO_PROJS {
GMTIO_EPGS = 0,
GMTIO_GMT,
GMTIO_PROJ4,
GMTIO_WKT
};
/* These functions are defined and used below but not in any *.h file so we repeat them here */
int gmt_get_ogr_id (struct GMT_OGR *G, char *name);
void gmt_format_abstime_output (struct GMT_CTRL *GMT, double dt, char *text);
/* Local functions */
/*! Returns true if record is NaN NaN [NaN NaN] etc */
GMT_LOCAL bool gmtio_is_a_NaN_line (struct GMT_CTRL *GMT, char *line) {
unsigned int pos = 0;
char p[GMT_LEN256] = {""};
while ((gmt_strtok (line, GMT->current.io.scan_separators, &pos, p))) {
gmt_str_tolower (p);
if (strncmp (p, "nan", 3U)) return (false);
}
return (true);
}
/*! . */
GMT_LOCAL unsigned int gmtio_is_segment_header (struct GMT_CTRL *GMT, char *line) {
/* Returns 1 if this record is a GMT segment header;
* Returns 2 if this record is a segment breaker;
* Otherwise returns 0 */
if (GMT->current.setting.io_blankline[GMT_IN] && gmt_is_a_blank_line (line)) return (2); /* Treat blank line as segment break */
if (GMT->current.setting.io_nanline[GMT_IN] && gmtio_is_a_NaN_line (GMT, line)) return (2); /* Treat NaN-records as segment break */
if (line[0] == GMT->current.setting.io_seg_marker[GMT_IN]) return (1); /* Got a regular GMT segment header */
return (0); /* Not a segment header */
}
/*! . */
static inline bool gmtio_outside_in_row_range (struct GMT_CTRL *GMT, int64_t row) {
/* Returns true of this row should be skipped according to -qi[~]<rows>,...[+a|t|s] */
bool pass;
if (GMT->common.q.mode != GMT_RANGE_ROW_IN) return false; /* -qi<rows> not active */
pass = GMT->common.q.inverse[GMT_IN];
for (unsigned int k = 0; k < GMT->current.io.n_row_ranges[GMT_IN]; k++) {
if (row >= GMT->current.io.row_range[GMT_IN][k].first && row <= GMT->current.io.row_range[GMT_IN][k].last) { /* row is inside this range */
if (GMT->current.io.row_range[GMT_IN][k].inc == 1) return pass; /* Return if we want to use this row or not */
if ((row - GMT->current.io.row_range[GMT_IN][k].first) % GMT->current.io.row_range[GMT_IN][k].inc == 0) return pass; /* Hit one of the steps */
}
}
return !pass;
}
/*! . */
static inline bool gmtio_outside_out_row_range (struct GMT_CTRL *GMT, int64_t row) {
/* Returns true if this row should be skipped according to -qo[~]<rows>,...[+a|s] */
bool pass;
if (GMT->common.q.mode != GMT_RANGE_ROW_OUT) return false; /* -qo<rows> not active */
pass = GMT->common.q.inverse[GMT_OUT];
for (unsigned int k = 0; k < GMT->current.io.n_row_ranges[GMT_OUT]; k++) {
if (row >= GMT->current.io.row_range[GMT_OUT][k].first && row <= GMT->current.io.row_range[GMT_OUT][k].last) { /* row is inside this range */
if (GMT->current.io.row_range[GMT_OUT][k].inc == 1) return pass; /* Return if we want to use this row or not */
if ((row - GMT->current.io.row_range[GMT_OUT][k].first) % GMT->current.io.row_range[GMT_OUT][k].inc == 0) return pass; /* Hit one of the steps */
}
}
return !pass;
}
/*! . */
static inline bool gmtio_outside_in_data_range (struct GMT_CTRL *GMT, unsigned int col) {
/* Returns true if this row should be skipped according to -qi[~]<rangevalues>,...+c<col> */
bool pass;
if (GMT->common.q.mode != GMT_RANGE_DATA_IN) return false; /* -qi<data> not active */
pass = GMT->common.q.inverse[GMT_IN];
if (gmt_M_is_dnan (GMT->current.io.curr_rec[col])) return !pass; /* A NaN value is never in a range */
for (unsigned int k = 0; k < GMT->current.io.n_row_ranges[GMT_IN]; k++) {
if (GMT->current.io.curr_rec[col] >= GMT->current.io.data_range[GMT_IN][k].first && GMT->current.io.curr_rec[col] <= GMT->current.io.data_range[GMT_IN][k].last) return pass; /* Inside this range at least */
}
return !pass;
}
/*! . */
static inline bool gmtio_outside_out_data_range (struct GMT_CTRL *GMT, unsigned int col, double *data) {
/* Returns true of this row should be skipped according to -qo[~]<rangevalues>,...+c<col> */
bool pass = GMT->common.q.inverse[GMT_OUT];
for (unsigned int k = 0; k < GMT->current.io.n_row_ranges[GMT_OUT]; k++) {
if (data[col] >= GMT->current.io.data_range[GMT_OUT][k].first && data[col] <= GMT->current.io.data_range[GMT_OUT][k].last) return pass; /* Inside this range at least */
}
return !pass;
}
/*! . */
static inline uint64_t gmtio_n_cols_needed_for_gaps (struct GMT_CTRL *GMT, uint64_t n) {
/* Return the actual items needed (which may be more than n if gap testing demands it) */
if (GMT->common.g.active) return (MAX (n, GMT->common.g.n_col)); /* n or n_col (if larger) */
return (n); /* No gap checking, n it is */
}
/*! . */
static inline void gmtio_update_prev_rec (struct GMT_CTRL *GMT, uint64_t n_use) {
/* Update previous record before reading the new record*/
if (GMT->current.io.need_previous) gmt_M_memcpy (GMT->current.io.prev_rec, GMT->current.io.curr_rec, n_use, double);
}
/* Begin private functions used by gmt_byteswap_file() */
#define DEBUG_BYTESWAP
/*! . */
static inline bool gmtio_fwrite_check (struct GMT_CTRL *GMT, const void *ptr,
size_t size, size_t nitems, FILE *stream) {
if (fwrite (ptr, size, nitems, stream) != nitems) {
char message[GMT_LEN256] = {""};
snprintf (message, GMT_LEN256, "%s: error writing %" PRIuS " bytes to stream.\n", __func__, size * nitems);
GMT_Report (GMT->parent, GMT_MSG_ERROR, message);
return true;
}
return false;
}
/*! . */
static inline void gmtio_swap_uint16 (char *buffer, const size_t len) {
/* byteswap uint16_t in buffer of length 'len' bytes */
uint16_t u;
size_t n;
for (n = 0; n < len; n+=Int16len) {
memcpy (&u, &buffer[n], Int16len);
u = bswap16 (u);
memcpy (&buffer[n], &u, Int16len);
}
}
/*! . */
static inline void gmtio_swap_uint32 (char *buffer, const size_t len) {
/* byteswap uint32_t in buffer of length 'len' bytes */
uint32_t u;
size_t n;
for (n = 0; n < len; n+=Int32len) {
memcpy (&u, &buffer[n], Int32len);
u = bswap32 (u);
memcpy (&buffer[n], &u, Int32len);
}
}
/*! . */
static inline void gmtio_swap_uint64 (char *buffer, const size_t len) {
/* byteswap uint64_t in buffer of length 'len' bytes */
uint64_t u;
size_t n;
for (n = 0; n < len; n+=Int64len) {
memcpy (&u, &buffer[n], Int64len);
u = bswap64 (u);
memcpy (&buffer[n], &u, Int64len);
}
}
/* End private functions used by gmt_byteswap_file() */
#ifdef HAVE_DIRENT_H_
/*! . */
GMT_LOCAL bool gmtio_traverse_dir (const char *file, char *path) {
/* Look for file in the directory pointed to by path, recursively */
DIR *D = NULL;
struct dirent *F = NULL;
int len, d_namlen;
bool ok = false;
char savedpath[PATH_MAX];
if ((D = opendir (path)) == NULL) return (false); /* Unable to open directory listing */
len = (int)strlen (file);
strncpy (savedpath, path, PATH_MAX-1); /* Make copy of current directory path */
while (!ok && (F = readdir (D)) != NULL) { /* For each directory entry until end or ok becomes true */
d_namlen = (int)strlen (F->d_name);
if (d_namlen == 1 && F->d_name[0] == '.') continue; /* Skip current dir */
if (d_namlen == 2 && F->d_name[0] == '.' && F->d_name[1] == '.') continue; /* Skip parent dir */
#ifdef HAVE_SYS_DIR_H_
if (F->d_type == DT_DIR) { /* Entry is a directory; must search this directory recursively */
sprintf (path, "%s/%s", savedpath, F->d_name);
ok = gmtio_traverse_dir (file, path);
}
else if (d_namlen == len && !strcmp (F->d_name, file)) { /* Found the file in this dir (i.e., F_OK) */
sprintf (path, "%s/%s", savedpath, file);
ok = true;
}
#endif /* HAVE_SYS_DIR_H_ */
}
(void)closedir (D);
return (ok); /* did or did not find file */
}
#endif /* HAVE_DIRENT_H_ */
/*! . */
GMT_LOCAL char *gmtio_trim_segheader (struct GMT_CTRL *GMT, char *line) {
/* Trim trailing junk and return pointer to first non-space/tab/> part of segment header
* Do not try to free the returned pointer!
*/
gmt_strstrip (line, false); /* Strip trailing whitespace */
/* Skip over leading whitespace and segment marker */
while (*line && (isspace(*line) || *line == GMT->current.setting.io_seg_marker[GMT_IN]))
++line;
/* Return header string */
return (line);
}
/*! . */
GMT_LOCAL void gmtio_adjust_periodic_lon (struct GMT_CTRL *GMT, double *val) {
while (*val > GMT->common.R.wesn[XHI] && (*val - 360.0) >= GMT->common.R.wesn[XLO])
*val -= 360.0;
while (*val < GMT->common.R.wesn[XLO] && (*val + 360.0) <= GMT->common.R.wesn[XLO]) *val += 360.0;
/* If data is not inside the given range it will satisfy (lon > east) */
/* Now it will be outside the region on the same side it started out at */
}
/*! . */
GMT_LOCAL void gmtio_adjust_projected (struct GMT_CTRL *GMT) {
/* Case of incoming projected map coordinates that we wish to revert to lon/lat */
if (GMT->current.proj.inv_coord_unit != GMT_IS_METER) { /* Must first scale to meters */
GMT->current.io.curr_rec[GMT_X] *= GMT->current.proj.m_per_unit[GMT->current.proj.inv_coord_unit];
GMT->current.io.curr_rec[GMT_Y] *= GMT->current.proj.m_per_unit[GMT->current.proj.inv_coord_unit];
}
(*GMT->current.proj.inv) (GMT, &GMT->current.io.curr_rec[GMT_X], &GMT->current.io.curr_rec[GMT_Y],
GMT->current.io.curr_rec[GMT_X], GMT->current.io.curr_rec[GMT_Y]);
}
/*! . */
GMT_LOCAL uint64_t gmtio_bin_colselect (struct GMT_CTRL *GMT) {
/* When -i<cols> is used we must pull out and reset the current record */
unsigned int col;
int64_t order;
static double tmp[GMT_BUFSIZ];
struct GMT_COL_INFO *S = NULL;
for (col = 0; col < GMT->common.i.col.n_cols; col++) {
S = &(GMT->current.io.col[GMT_IN][col]);
order = S->order;
if (GMT->current.io.cycle_col == order)
gmtlib_modulo_time_calculator (GMT, &(tmp[order]));
tmp[order] = gmt_M_convert_col (GMT->current.io.col[GMT_IN][col], GMT->current.io.curr_rec[S->col]);
switch (gmt_M_type (GMT, GMT_IN, order)) {
case GMT_IS_LON: /* Must account for periodicity in 360 as per current rule */
gmtio_adjust_periodic_lon (GMT, &tmp[order]);
break;
case GMT_IS_LAT:
if (tmp[order] < -90.0 || tmp[order] > +90.0) {
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Latitude (%g) at line # %" PRIu64 " exceeds -|+ 90! - set to NaN\n", tmp[order], GMT->current.io.rec_no);
tmp[S->order] = GMT->session.d_NaN;
}
break;
case GMT_IS_DIMENSION: /* Convert to internal inches */
tmp[order] *= GMT->session.u2u[GMT->current.setting.proj_length_unit][GMT_INCH];
break;
default: /* Nothing to do */
break;
}
}
gmt_M_memcpy (GMT->current.io.curr_rec, tmp, GMT->common.i.col.n_cols, double);
return (GMT->common.i.col.n_cols);
}
/*! Return the floating point value associated with the aspatial value V given its type as a double */
GMT_LOCAL double gmtio_convert_aspatial_value (struct GMT_CTRL *GMT, unsigned int type, char *V) {
double value;
switch (type) {
case GMT_DOUBLE:
case GMT_FLOAT:
case GMT_ULONG:
case GMT_LONG:
case GMT_UINT:
case GMT_INT:
case GMT_USHORT:
case GMT_SHORT:
case GMT_CHAR:
case GMT_UCHAR:
value = atof (V);
break;
case GMT_DATETIME:
gmt_scanf_arg (GMT, V, GMT_IS_ABSTIME, false, &value);
break;
default: /* Give NaN */
value = GMT->session.d_NaN;
break;
}
return (value);
}
/*! . */
GMT_LOCAL void gmtio_handle_bars (struct GMT_CTRL *GMT, char *in, unsigned way) {
/* Way = 0: replace | inside quotes with ASCII 1, Way = 1: Replace ASCII 1 with | */
/* Need to handle cases like ...|"St. George's Channel"|... with a mix of quotes. */
char the_quote = '\0'; /* Don't know what type of quote is used */
gmt_M_unused(GMT);
if (in == NULL || in[0] == '\0') return; /* No string to check */
if (way == 0) { /* Replace | found inside quotes with a single ASCII 1 */
char *c = in;
bool replace = false;
while (*c && the_quote == '\0') { /* Find the first quote character which we assume is what is used for a sentence which may contain another quote */
if (*c == '\"' || *c == '\'') the_quote = *c;
++c;
}
if (the_quote == '\0') the_quote = '\"'; /* No quotes found so just set the default quote */
c = in; /* Start over */
while (*c) {
if (*c == the_quote)
replace = !replace;
else if (*c == '|' && replace)
*c = 1;
++c;
}
}
else /* way != 0: Replace single ASCII 1 with | */
gmt_strrepc (in, 1, '|');
}
/*! . */
GMT_LOCAL bool gmtio_skip_record (struct GMT_CTRL *GMT, struct GMT_TEXT_SELECTION *S, char *record) {
/* Return true if the pattern was found; see gmt_set_text_selection for details */
bool match = false;
if (S == NULL || S->n == 0) return (true); /* No selection criteria given, so can only return true */
/* Could be one or n patterns to check */
for (uint64_t k = 0; !match && k < S->n; k++) {
#if !defined(WIN32) || (defined(WIN32) && defined(HAVE_PCRE)) || (defined(WIN32) && defined(HAVE_PCRE2))
if (S->regexp[k])
match = gmtlib_regexp_match (GMT, record, S->pattern[k], S->caseless[k]); /* true if we matched */
else
#endif
match = (strstr (record, S->pattern[k]) != NULL);
}
/* Here, match == true if we found the pattern we specified. There are now two cases to consider:
1) invert is false, which means we want to skip records when match == false.
So if match == false and invert == false then we will skip.
2) invert == true, which means we want to skip recprds when match == true.
So if match == true and invert == true then we will skip
This means in either scenario, the test below is true if we want to skip. */
return (S->invert == match); /* Returns true if we should skip this record */
}
/*! . */
GMT_LOCAL unsigned int gmtio_ogr_decode_aspatial_values (struct GMT_CTRL *GMT, char *record, struct GMT_OGR *S) {
/* Parse @D<vals> aspatial values; this is done once per feature (segment). We store
* both the text representation (value) and attempt to convert to double in dvalue.
* We use S->n_aspatial to know how many values there are .*/
unsigned int col = 0;
char buffer[GMT_BUFSIZ] = {""}, *token, *stringp;
if (S->n_aspatial == 0) return (0); /* Nothing to do */
if (S->tvalue == NULL) { /* First time, allocate space */
if ((S->tvalue = gmt_M_memory (GMT, S->tvalue, S->n_aspatial, char *)) == NULL) return 0;
if ((S->dvalue = gmt_M_memory (GMT, S->dvalue, S->n_aspatial, double)) == NULL) return 0;
}
strncpy (buffer, record, GMT_BUFSIZ-1); /* working copy */
gmtio_handle_bars (GMT, buffer, 0); /* Replace vertical bars inside quotes with ASCII 1 */
stringp = buffer;
while ( (token = strsep (&stringp, "|")) != NULL ) {
if (col >= S->n_aspatial) {
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Bad OGR/GMT: @D record has more items than declared by @N\n");
continue;
}
gmtio_handle_bars (GMT, token, 1); /* Put back any vertical bars replaced above */
gmt_M_str_free (S->tvalue[col]); /* Free previous item */
S->tvalue[col] = strdup (token);
S->dvalue[col] = gmtio_convert_aspatial_value (GMT, S->type[col], token);
col++;
}
if (col == (S->n_aspatial-1)) { /* Last item was blank and hence not returned by strsep */
S->tvalue[col] = strdup (""); /* Allocate space for blank string */
}
return (col);
}
/*! Duplicate in to out, then find the first space not inside quotes and truncate string there */
GMT_LOCAL void gmtio_copy_and_truncate_quotes (char *out, char *in) {
bool quote = false;
while (*in && (quote || *in != ' ')) {
*out++ = *in; /* Copy char */
if (*in++ == '\"') quote = !quote; /* Wind to next space except skip if inside double quotes */
}
*out = '\0'; /* Terminate string */
}
GMT_LOCAL void gmtio_copy_and_truncate (char *out, char *in) {
if (strchr (in, ' ') && !strchr (in, '\"')) /* Has spaces yet no quotes... assume we can get the line as is */
strcpy (out, in);
else
gmtio_copy_and_truncate_quotes (out, in);
}
/*! Parse @T aspatial types; this is done once per dataset and follows @N */
GMT_LOCAL unsigned int gmtio_ogr_decode_aspatial_types (struct GMT_CTRL *GMT, char *record, struct GMT_OGR *S) {
unsigned int pos = 0, col = 0;
int t;
size_t n_alloc = 0;
char buffer[GMT_BUFSIZ] = {""}, p[GMT_BUFSIZ];
gmtio_copy_and_truncate (buffer, record);
while ((gmt_strtok (buffer, "|", &pos, p))) {
if (col >= S->n_aspatial) {
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Bad OGR/GMT: @T record has more items than declared by @N - skipping\n");
continue;
}
if (col == n_alloc) S->type = gmt_M_memory (GMT, S->type, n_alloc += GMT_TINY_CHUNK, enum GMT_enum_type);
if ((t = gmtlib_ogr_get_type (p)) < 0) {
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Bad OGR/GMT: @T: No such type: %s - skipping\n", p);
continue;
}
S->type[col] = t;
col++;
}
if (col < n_alloc) S->type = gmt_M_memory (GMT, S->type, col, enum GMT_enum_type);
return (col);
}
GMT_LOCAL unsigned int gmtio_select_all_ogr_if_requested (struct GMT_CTRL *GMT) {
/* If -a with no args was provided we select all available aspatial information to be added to input record */
unsigned int k, kn;
if (GMT->current.io.OGR == NULL) return (GMT_NOERROR); /* No can do */
if (GMT->current.io.OGR->n_aspatial == 0) return (GMT_NOERROR); /* No can do */
if (GMT->common.a.active == false) return (GMT_NOERROR); /* -a not given */
if (GMT->common.a.n_aspatial) { /* -a parsed and stuff was found; check if -a names are correct */
bool found;
for (k = 0; k < GMT->common.a.n_aspatial; k++) {
for (kn = 0, found = false; !found && kn < GMT->current.io.OGR->n_aspatial; kn++)
found = (!strcmp (GMT->common.a.name[k], GMT->current.io.OGR->name[kn]));
if (!found) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -a: No such named aspatial item: %s.\n", GMT->common.a.name[k]);
return (GMT_NOT_OUTPUT_OBJECT);
}
}
return (GMT_NOERROR);
}
GMT->common.a.n_aspatial = GMT->current.io.OGR->n_aspatial;
for (k = kn = 0; k < GMT->common.a.n_aspatial; k++) {
GMT->common.a.col[k] = 2 + kn;
GMT->common.a.ogr[k] = k;
GMT->common.a.type[k] = GMT->current.io.OGR->type[k];
gmt_M_str_free (GMT->common.a.name[k]); /* Just in case */
GMT->common.a.name[k] = strdup (GMT->current.io.OGR->name[k]);
if (GMT->common.a.type[k] != GMT_TEXT) kn++; /* Since that is the order in the numerical part of the record */
}
return (GMT_NOERROR);
}
/*! Decode @N aspatial names; this is done once per dataset */
GMT_LOCAL unsigned int gmtio_ogr_decode_aspatial_names (struct GMT_CTRL *GMT, char *record, struct GMT_OGR *S) {
unsigned int pos = 0, col = 0;
size_t n_alloc = 0;
char buffer[GMT_BUFSIZ] = {""}, p[GMT_BUFSIZ] = {""};
gmtio_copy_and_truncate (buffer, record);
while ((gmt_strtok (buffer, "|", &pos, p))) {
if (col == n_alloc) S->name = gmt_M_memory (GMT, S->name, n_alloc += GMT_TINY_CHUNK, char *);
S->name[col++] = strdup (p);
}
if (col < n_alloc) S->name = gmt_M_memory (GMT, S->name, col, char *);
return (col);
}
/*! Parsing of the GMT/OGR vector specification (v 1.0). See Appendix R */
GMT_LOCAL bool gmtio_ogr_parser (struct GMT_CTRL *GMT, char *record) {
return (GMT->current.io.ogr_parser (GMT, record)); /* We call either the header or data parser depending on pointer */
}
GMT_LOCAL bool gmtio_ogr_data_parser (struct GMT_CTRL *GMT, char *record) {
/* Parsing of the GMT/OGR vector specification (v 1.0) for data feature records.
* We KNOW GMT->current.io.ogr == GMT_OGR_TRUE, i.e., current file is a GMT/OGR file.
* We also KNOW that GMT->current.io.OGR has been allocated by gmtio_ogr_header_parser.
* For GMT/OGR files we must parse and store the metadata in GMT->current.io.OGR,
* from where higher-level functions can access it. GMT_End_IO will free the structure.
* This function returns true if we parsed a GMT/OGR record and false otherwise.
* If we encounter a parsing error we stop parsing any further by setting GMT->current.io.ogr = GMT_OGR_FALSE.
* We loop until all @<info> tags have been processed on this record.
*/
unsigned int n_aspatial;
bool quote;
char *p = NULL;
struct GMT_OGR *S = NULL;
if (record[0] != '#') return (false); /* Not a comment record so no point looking further */
if (!(p = strchr (record, '@'))) return (false); /* Not an OGR/GMT record since @ was not found */
/* Here we are reasonably sure that @? strings are OGR/GMT feature specifications */
gmt_chop (record); /* Get rid of linefeed etc */
S = GMT->current.io.OGR; /* Set S shorthand */
quote = false;
while (*p == '@') {
++p; /* Move to first char after @ */
switch (p[0]) { /* These are the feature tags only: @D, @P, @H */
case 'D': /* Aspatial data values, store in segment header */
if (!S->geometry) { GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @D given but no geometry set\n"); return (false);}
n_aspatial = gmtio_ogr_decode_aspatial_values (GMT, &p[1], S);
if (S->n_aspatial != n_aspatial) {
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "OGR/GMT: Some @D items not specified (set to NULL) near line %" PRIu64 "\n", GMT->current.io.rec_no);
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "OGR/GMT: Offending record: %s\n", record);
}
break;
case 'P': /* Polygon perimeter, store in segment header */
if (!(S->geometry == GMT_IS_POLYGON || S->geometry == GMT_IS_MULTIPOLYGON)) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @P only valid for polygons\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
S->pol_mode = GMT_IS_PERIMETER;
break;
case 'H': /* Polygon hole, store in segment header */
if (!(S->geometry == GMT_IS_POLYGON || S->geometry == GMT_IS_MULTIPOLYGON)) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @H only valid for polygons\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
S->pol_mode = GMT_IS_HOLE;
break;
default: /* Bad OGR record? */
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: Cannot have @%c after FEATURE_DATA\n", p[0]);
GMT->current.io.ogr = GMT_OGR_FALSE;
break;
}
while (*p && (quote || *p != '@')) if (*p++ == '\"') quote = !quote; /* Wind to next @ except skip if inside double quotes */
}
return (true);
}
/*! Simplify aspatial data grabbing when -a is used */
GMT_LOCAL void gmtio_align_ogr_values (struct GMT_CTRL *GMT) {
unsigned int k;
int id;
if (!GMT->common.a.active) return; /* Nothing selected with -a */
for (k = 0; k < GMT->common.a.n_aspatial; k++) { /* Process the requested columns */
id = gmt_get_ogr_id (GMT->current.io.OGR, GMT->common.a.name[k]); /* See what order in the OGR struct this -a column appear */
GMT->common.a.ogr[k] = id;
}
}
GMT_LOCAL void gmtio_ogr_check_if_geographic (struct GMT_CTRL *GMT) {
/* Determine if this OGR/GMT file contains plain geographic lon/lat or if there are projected data.
* If lon/lat then we use that information to call gmt_set_geographic (i.e., -fg) */
struct GMT_OGR *S = GMT->current.io.OGR;
if (S == NULL) return; /* Well, that was a non-starter*/
if (S->proj[GMTIO_PROJ4]) { /* Start with checking proj4 codes */
if (strstr (S->proj[GMTIO_PROJ4], "+proj=longlat") || strstr (S->proj[GMTIO_PROJ4], "+pronj=latlong")) { /* Means we have degree coordinates */
gmt_set_geographic (GMT, GMT_IN);
return;
}
}
if (S->proj[GMTIO_EPGS]) { /* See if we have EPGS codes */
if (strstr (S->proj[GMTIO_EPGS], "4326")) { /* 4326 means we have lon/lat degree coordinates*/
gmt_set_geographic (GMT, GMT_IN);
return;
}
}
if (S->proj[GMTIO_GMT]) { /* See if we have a GMT code for lonlat */
if (strstr (S->proj[GMTIO_GMT], "-Jx1d")) {
gmt_set_geographic (GMT, GMT_IN);
return;
}
}
/* If we get here we most likely have read projected data, so stick with Cartesian i/o */
}
/*! . */
GMT_LOCAL bool gmtio_ogr_header_parser (struct GMT_CTRL *GMT, char *record) {
/* Parsing of the GMT/OGR vector specification (v 1.0).
* GMT->current.io.ogr can have three states:
* GMT_OGR_UNKNOWN (-1) if not yet set [this is how it is initialized in GMTAPI_Begin_IO].
* GMT_OGR_FALSE (0) if file has been determined NOT to be a GMT/OGR file.
* GMT_OGR_TRUE (+1) if it has met the criteria and is a GMT/OGR file.
* For GMT/OGR files we must parse and store the metadata in GMT->current.io.OGR,
* from where higher-level functions can access it. GMT_End_IO will free the structure.
* This function returns true if we parsed a GMT/OGR record and false otherwise.
* If we encounter a parsing error we stop parsing any further by setting GMT->current.io.ogr = GMT_OGR_FALSE.
* We loop until all @<info> tags have been processed on this record.
* gmtio_ogr_parser will point to this function until the header has been parsed, then it is
* set to point to gmtio_ogr_data_parser instead, to speed up data record processing.
*/
unsigned int n_aspatial, k, geometry = 0, gap = 0;
bool quote;
char *p = NULL;
struct GMT_OGR *S = NULL;
if (GMT->current.io.ogr == GMT_OGR_FALSE) return (false); /* No point parsing further if we KNOW it is not OGR */
if (record[0] != '#') return (false); /* Not a comment record so no point looking any further */
if (GMT->current.io.ogr == GMT_OGR_TRUE && !strncmp (record, "# FEATURE_DATA", 14)) { /* It IS an OGR file and we found end of OGR header section and start of feature data */
GMT->current.io.ogr_parser = &gmtio_ogr_data_parser; /* From now on only parse for feature tags */
gmtio_align_ogr_values (GMT); /* Simplify copy from aspatial values to input columns as per -a option */
gmtio_ogr_check_if_geographic (GMT); /* Check if we should set -fg */
return (true);
}
if (!(p = strchr (record, '@'))) return (false); /* Not an OGR/GMT record since @ was not found */
if (GMT->current.io.ogr == GMT_OGR_UNKNOWN && !strncmp (p, "@VGMT", 5)) { /* Found the OGR version identifier, look for @G if on the same record */
if (GMT->common.a.output) { /* Cannot read OGR files when -a is used to define output */
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Cannot read OGR/GMT files when -a is used to define output format\n");
GMT->parent->error = GMT_NOT_OUTPUT_OBJECT;
return false;
}
GMT->current.io.ogr = GMT_OGR_TRUE; /* File is now known to be a GMT/OGR geospatial file */
if (!(p = strchr (&p[5], '@'))) return (true); /* No more @ codes; goto next record */
}
if (GMT->current.io.ogr != GMT_OGR_TRUE) return (false); /* No point parsing further since file is not GMT/OGR (at least not yet) */
/* Here we are reasonably sure that @? strings are OGR/GMT header specifications */
gmt_chop (record); /* Get rid of linefeed etc */
/* Allocate S the first time we get here */
if (!GMT->current.io.OGR) GMT->current.io.OGR = gmt_M_memory (GMT, NULL, 1, struct GMT_OGR);
S = GMT->current.io.OGR;
quote = false;
while (*p == '@') {
++p; /* Move to first char after @ */
switch (p[0]) { /* These are the header tags */
case 'G': /* Geometry */
if (!strncmp (&p[1], "LINESTRING", 10))
geometry = GMT_IS_LINESTRING;
else if (p[1] == 'P') {
if (!strncmp (&p[2], "OLYGON", 6))
geometry = GMT_IS_POLYGON;
else if (!strncmp (&p[2], "OINT", 4))
geometry = GMT_IS_POINT;
}
else if (!strncmp (&p[1], "MULTI", 5)) {
if (!strncmp (&p[6], "POINT", 5))
geometry = GMT_IS_MULTIPOINT;
else if (!strncmp (&p[6], "LINESTRING", 10))
geometry = GMT_IS_MULTILINESTRING;
else if (!strncmp (&p[6], "POLYGON", 7))
geometry = GMT_IS_MULTIPOLYGON;
else {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @G unrecognized geometry\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
}
if (!S->geometry)
S->geometry = geometry;
else if (S->geometry != geometry) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @G cannot have different geometries\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
}
break;
case 'N': /* Aspatial name fields, store in table header */
if (!S->geometry) {GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @N given but no geometry set\n"); return (false);}
if (S->name) { /* Already set */
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @N Cannot have more than one per segment\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
else
n_aspatial = gmtio_ogr_decode_aspatial_names (GMT, &p[1], S);
if (S->n_aspatial == 0)
S->n_aspatial = n_aspatial;
else if (S->n_aspatial != n_aspatial) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @N number of items vary\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
}
break;
case 'J': /* Dataset projection strings (one of 4 kinds) */
if (p[1] == '\0' || p[1] == ' ' || strchr ("egpw", p[1]) == NULL) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @J given unknown format (%c)\n", (int)p[1]);
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
switch (p[1]) {
case 'e': k = GMTIO_EPGS; break; /* EPSG code */
case 'g': k = GMTIO_GMT; break; /* GMT proj code. If given then data are projected */
case 'p': k = GMTIO_PROJ4; break; /* Proj.4 code */
case 'w': k = GMTIO_WKT; break; /* OGR WKT representation */
default: /* We already checked for this above so cannot get here */
break;
}
S->proj[k] = strdup (&p[2]);
break;
case 'R': /* Dataset region */
if (S->region) { /* Already set */
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @R can only appear once\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
S->region = strdup (&p[1]);
break;
case 'T': /* Aspatial field types, store in table header */
if (!S->geometry) { GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @T given but no geometry set\n"); return (false);}
if (S->type) { /* Already set */
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @T Cannot have more than one per segment\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
}
n_aspatial = gmtio_ogr_decode_aspatial_types (GMT, &p[1], S);
if (S->n_aspatial == 0)
S->n_aspatial = n_aspatial;
else if (S->n_aspatial != n_aspatial) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @T number of items vary\n");
GMT->current.io.ogr = GMT_OGR_FALSE;
}
break;
default: /* Just record, probably means this is NOT a GMT/OGR file after all */
gap = (unsigned int)(p - record);
if (gap < 3 && isupper (p[0])) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Bad OGR/GMT: @%c not allowed before FEATURE_DATA\n", (int)p[0]);
GMT->current.io.ogr = GMT_OGR_FALSE;
}
break;
}
while (*p && (quote || *p != '@')) if (*p++ == '\"') quote = !quote; /* Wind to next @ except skip if inside double quotes */
}
return (true);
}
/*! . */
GMT_LOCAL unsigned int gmtio_reconsider_rectype (struct GMT_CTRL *GMT) {
/* If any text aspatial field is selected the record type must change to mixed. */
unsigned int k, val = 0;
if (GMT->current.io.ogr != GMT_OGR_TRUE) return (0); /* No point checking further since file is not GMT/OGR */
for (k = 0; k < GMT->common.a.n_aspatial; k++) { /* For each item specified in -a */
if (GMT->common.a.col[k] < 0) continue; /* Not meant for data columns but for segment headers */
if (GMT->current.io.OGR->type[GMT->common.a.ogr[k]] == GMT_TEXT)
val |= GMT_READ_TEXT; /* Since it may not have been set */
}
return (val);
}
/*! . */
GMT_LOCAL unsigned int gmtio_assign_aspatial_cols (struct GMT_CTRL *GMT) {
/* This function will load input columns with aspatial data as requested by -a.
* It will then handle any possible -i scalings/offsets as well for those columns.
* This is how the @D values end up in the input data record we read
* Not: This applies to numerical aspatial columns. Any numerical aspatial
* columns will be appended to the current trailing text string. */
unsigned int k, n, nt;
if (GMT->current.io.ogr != GMT_OGR_TRUE) return (0); /* No point checking further since file is not GMT/OGR */
for (k = n = nt = 0; k < GMT->common.a.n_aspatial; k++) { /* For each item specified in -a */
if (GMT->common.a.col[k] < 0) continue; /* Not meant for data columns but for segment headers */
if (GMT->current.io.OGR->type[GMT->common.a.ogr[k]] == GMT_TEXT) { /* Text goes into trailing text */
char *tvalue = GMT->current.io.OGR->tvalue[GMT->common.a.ogr[k]];
size_t len = strlen (tvalue);
unsigned int pos = 0;
if (len && tvalue[0] == '\"' && tvalue[len-1] == '\"') { /* Eliminate quotes for quoted text */