FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/src/datafile.c at gnuplot-4-4-alpha · gnuplot/gnuplot-old · GitHub
gnuplot
gnuplot-old
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot-old
/
src
/
datafile.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
4677 lines (4062 loc) · 135 KB
Breadcrumbs
gnuplot-old
/
src
/
datafile.c
Copy path
File metadata and controls
4677 lines (4062 loc) · 135 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#ifndef
lint
static
char
*
RCSid
() {
return
RCSid
(
"$Id: datafile.c,v 1.172 2009/04/13 03:07:46 sfeam Exp $"
); }
#endif
/* GNUPLOT - datafile.c */
/*[
* Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/* AUTHOR : David Denholm */
/*
* this file provides the functions to handle data-file reading..
* takes care of all the pipe / stdin / index / using worries
*/
/*{{{ notes */
/* couldn't decide how to implement 'thru' only for 2d and 'index'
* for only 3d, so I did them for both - I can see a use for
* index in 2d, especially for fit.
*
* I keep thru for backwards compatibility, and extend it to allow
* more natural plot 'data' thru f(y) - I (personally) prefer
* my syntax, but then I'm biased...
*
* - because I needed it, I have added a range of indexes...
* (s)plot 'data' [index i[:j]]
*
* also every a:b:c:d:e:f - plot every a'th point from c to e,
* in every b lines from d to f
* ie for (line=d; line<=f; line+=b)
* for (point=c; point >=e; point+=a)
*
*
* I dont like mixing this with the time series hack... I am
* very into modular code, so I would prefer to not have to
* have _anything_ to do with time series... for example,
* we just look at columns in file, and that is independent
* of 2d/3d. I really dont want to have to pass a flag to
* this is plot or splot.
*
* Now that df_2dbinary() and df_3dbinary() are here, I am seriously
* tempted to move get_data() and get_3ddata() in here too
*
* public variables declared in this file.
* int df_no_use_specs - number of columns specified with 'using'
* int df_no_tic_specs - count of additional ticlabel columns
* int df_line_number - for error reporting
* int df_datum - increases with each data point
* TBOOLEAN df_binary - it's a binary file
* [ might change this to return value from df_open() ]
* int df_eof - end of file
*
* functions
* int df_open(char *file_name, int max_using, plot_header *plot)
* parses thru / index / using on command line
* max_using is max no of 'using' columns allowed (obsolete?)
* plot_header is NULL if called from fit or set_palette code
* returns number of 'using' cols specified, or -1 on error (?)
*
* int df_readline(double vector[], int max)
* reads a line, does all the 'index' and 'using' manipulation
* deposits values into vector[]
* returns
* number of columns parsed [0=not blank line, but no valid data],
* DF_EOF for EOF
* DF_UNDEFINED - undefined result during eval of extended using spec
* DF_MISSING - requested column matched that of 'set missing <foo>'
* DF_FIRST_BLANK for first consecutive blank line
* DF_SECOND_BLANK for second consecutive blank line
* will return FIRST before SECOND
*
* if a using spec was given, lines not fulfilling spec are ignored.
* we will always return exactly the number of items specified
*
* if no spec given, we return number of consecutive columns we parsed.
*
* if we are processing indexes, separated by 'n' blank lines,
* we will return n-1 blank lines before noticing the index change
*
* void df_close()
* closes a currently open file.
*
* void f_dollars(x)
* void f_column() actions for expressions using $i, column(j), etc
* void f_valid()
*
*
* line parsing slightly differently from previous versions of gnuplot...
* given a line containing fewer columns than asked for, gnuplot used to make
* up values... I say that if I have explicitly said 'using 1:2:3', then if
* column 3 doesn't exist, I dont want this point...
*
* a column number of 0 means generate a value... as before, this value
* is useful in 2d as an x value, and is reset at blank lines.
* a column number of -1 means the (data) line number (not the file line
* number). splot 'file' using 1 is equivalent to
* splot 'file' using 0:-1:1
* column number -2 is the index. It was put in to kludge multi-branch
* fitting.
*
* 20/5/95 : accept 1.23d4 in place of e (but not in scanf string)
* : autoextend data line buffer and MAX_COLS
*
* 11/8/96 : add 'columns' -1 for suggested y value, and -2 for
* current index.
* using 1:-1:-2 and column(-1) are supported.
* $-1 and $-2 are not yet supported, because of the
* way the parser works
*
*/
/*}}} */
/* Daniel Sebald: added general binary 2d data support. (20 August 2004)
*/
#include
"datafile.h"
#include
"alloc.h"
#include
"axis.h"
#include
"binary.h"
#include
"command.h"
#include
"eval.h"
#include
"gp_time.h"
#include
"graphics.h"
#include
"misc.h"
#include
"parse.h"
#include
"plot.h"
#include
"readline.h"
#include
"util.h"
#include
"breaders.h"
#include
"variable.h"
/* For locale handling */
/* test to see if the end of an inline datafile is reached */
#define
is_EOF
(
c
) ((c) == 'e' || (c) == 'E')
/* is it a comment line? */
#define
is_comment
(
c
) ((c) && (strchr(df_commentschars, (c)) != NULL))
/*{{{ static fns */
#if
0
/* not used */
static
int
get_time_cols
__PROTO
((
char
*
fmt
));
static
void
mod_def_usespec
__PROTO
((
int
specno
,
int
jump
));
#endif
static
int
check_missing
__PROTO
((
char
*
s
));
static
char
*
df_gets
__PROTO
((
void
));
static
int
df_tokenise
__PROTO
((
char
*
s
));
static
float
*
df_read_matrix
__PROTO
((
int
*
rows
,
int
*
columns
));
static
void
plot_option_every
__PROTO
((
void
));
static
void
plot_option_index
__PROTO
((
void
));
static
void
plot_option_thru
__PROTO
((
void
));
static
void
plot_option_using
__PROTO
((
int
));
static
TBOOLEAN
valid_format
__PROTO
((
const
char
*
));
static
void
plot_ticlabel_using
__PROTO
((
int
));
static
char
*
df_parse_string_field
__PROTO
((
char
*
));
static
void
add_key_entry
__PROTO
((
char
*
temp_string
,
int
df_datum
));
static
char
*
df_generate_pseudodata
__PROTO
((
void
));
static
int
df_skip_bytes
__PROTO
((
int
nbytes
));
/*}}} */
/*{{{ variables */
enum
COLUMN_TYPE
{
CT_DEFAULT
,
CT_STRING
,
CT_KEYLABEL
,
CT_XTICLABEL
,
CT_X2TICLABEL
,
CT_YTICLABEL
,
CT_Y2TICLABEL
,
CT_ZTICLABEL
,
CT_CBTICLABEL
};
/* public variables client might access */
int
df_no_use_specs
;
/* how many using columns were specified */
int
df_line_number
;
int
df_datum
;
/* suggested x value if none given */
AXIS_INDEX
df_axis
[
MAXDATACOLS
];
TBOOLEAN
df_matrix
=
FALSE;
/* indicates if data originated from a 2D or 3D format */
TBOOLEAN
df_binary
=
FALSE;
/* this is a binary file */
/* jev -- the 'thru' function --- NULL means no dummy vars active */
/* HBB 990829: moved this here, from command.c */
struct
udft_entry
ydata_func
;
/* string representing missing values in ascii datafiles */
char
*
missing_val
=
NULL
;
/* input field separator, NUL if whitespace is the separator */
char
df_separator
=
'\0'
;
/* comments chars */
char
*
df_commentschars
=
0
;
/* If any 'inline data' are in use for the current plot, flag this */
TBOOLEAN
plotted_data_from_stdin
=
FALSE;
/* Setting this allows the parser to recognize Fortran D or Q */
/* format constants in the input file. But it slows things down */
TBOOLEAN
df_fortran_constants
=
FALSE;
/* Setting this disables re-initialization of the floating point exception */
/* handler before every expression evaluation in a using spec. */
TBOOLEAN
df_nofpe_trap
=
FALSE;
/* private variables */
/* in order to allow arbitrary data line length, we need to use the heap
* might consider free-ing it in df_close, especially for small systems
*/
static
char
*
line
=
NULL
;
static
size_t
max_line_len
=
0
;
#define
DATA_LINE_BUFSIZ
160
static
FILE
*
data_fp
=
NULL
;
#if
defined(
PIPES
)
static
TBOOLEAN
df_pipe_open
=
FALSE;
#endif
static
TBOOLEAN
mixed_data_fp
=
FALSE;
/* inline data */
char
*
df_filename
;
/* name of data file */
static
int
df_eof
=
0
;
static
int
df_no_tic_specs
;
/* ticlabel columns not counted in df_no_use_specs */
#ifndef
MAXINT
/* should there be one already defined ? */
# ifdef
INT_MAX
/* in limits.h ? */
# define
MAXINT
INT_MAX
# else
# define
MAXINT
((~0)>>1)
# endif
#endif
/* stuff for implementing index */
static
int
blank_count
=
0
;
/* how many blank lines recently */
static
int
df_lower_index
=
0
;
/* first mesh required */
static
int
df_upper_index
=
MAXINT
;
static
int
df_index_step
=
1
;
/* 'every' for indices */
static
int
df_current_index
;
/* current mesh */
/* stuff for named index support */
static
char
*
indexname
=
NULL
;
static
TBOOLEAN
index_found
=
FALSE;
/* stuff for every point:line */
static
int
everypoint
=
1
;
static
int
firstpoint
=
0
;
static
int
lastpoint
=
MAXINT
;
static
int
everyline
=
1
;
static
int
firstline
=
0
;
static
int
lastline
=
MAXINT
;
static
int
point_count
=
-1
;
/* point counter - preincrement and test 0 */
static
int
line_count
=
0
;
/* line counter */
/* for pseudo-data (1 if filename = '+'; 2 if filename = '++') */
static
int
df_pseudodata
=
0
;
static
int
df_pseudorecord
=
0
;
static
int
df_pseudospan
=
0
;
/* parsing stuff */
struct
use_spec_s
use_spec
[
MAXDATACOLS
];
static
char
*
df_format
=
NULL
;
static
char
*
df_binary_format
=
NULL
;
TBOOLEAN
evaluate_inside_using
=
FALSE;
/* rather than three arrays which all grow dynamically, make one
* dynamic array of this structure
*/
typedef
struct
df_column_struct
{
double
datum
;
enum
{
DF_BAD
,
DF_GOOD
}
good
;
char
*
position
;
}
df_column_struct
;
static
df_column_struct
*
df_column
=
NULL
;
/* we'll allocate space as needed */
static
int
df_max_cols
=
0
;
/* space allocated */
static
int
df_no_cols
;
/* cols read */
static
int
fast_columns
;
/* corey@cac optimization */
char
*
df_tokens
[
MAXDATACOLS
];
/* filled in by df_tokenise */
static
char
*
df_stringexpression
[
MAXDATACOLS
]
=
{
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
};
#define
NO_COLUMN_HEADER
(-99)
/* some value that can never be a real column */
static
int
column_for_key_title
=
NO_COLUMN_HEADER
;
static
char
*
df_key_title
=
NULL
;
/* filled in from <col> in 1st row by df_tokenise */
static
struct
curve_points
*
df_current_plot
;
/* used to process histogram labels + key entries */
/* Binary *read* variables used by df_readbinary(). The difference between matrix
* binary and general binary is that matrix binary requires an extra first column
* and extra first row giving the sample coordinates. Furthermore, note that if
* ASCII matrix data is converted to floats (i.e., binary) then it really falls in
* the general binary class, not the matrix binary class.
*/
TBOOLEAN
df_read_binary
;
TBOOLEAN
df_matrix_binary
;
int
df_plot_mode
;
static
int
df_readascii
__PROTO
((
double
[],
int
));
static
int
df_readbinary
__PROTO
((
double
[],
int
));
static
void
initialize_use_spec
__PROTO
((
void
));
static
void
initialize_binary_vars
__PROTO
((
void
));
static
void
df_insert_scanned_use_spec
__PROTO
((
int
));
static
void
adjust_binary_use_spec
__PROTO
((
void
));
static
void
clear_binary_records
__PROTO
((
df_records_type
));
static
void
plot_option_binary_format
__PROTO
((
char
*
));
static
void
plot_option_binary
__PROTO
((
TBOOLEAN
,
TBOOLEAN
));
static
void
plot_option_array
__PROTO
((
void
));
static
TBOOLEAN
rotation_matrix_2D
__PROTO
((
double
R
[][
2
],
double
));
static
TBOOLEAN
rotation_matrix_3D
__PROTO
((
double
P
[][
3
],
double
*
));
static
int
token2tuple
__PROTO
((
double
*
,
int
));
static
void
df_determine_matrix_info
__PROTO
((
FILE
*
));
static
void
df_swap_bytes_by_endianess
__PROTO
((
char
*
,
int
,
int
));
typedef
enum
df_multivalue_type
{
DF_DELTA
,
DF_FLIP_AXIS
,
DF_FLIP
,
DF_SCAN
,
DF_ORIGIN
,
DF_CENTER
,
DF_ROTATION
,
DF_PERPENDICULAR
,
DF_SKIP
}
df_multivalue_type
;
static
void
plot_option_multivalued
__PROTO
((
df_multivalue_type
,
int
));
char
*
df_endian
[
DF_ENDIAN_TYPE_LENGTH
]
=
{
"little"
,
"pdp (middle)"
,
"swapped pdp (dimmle)"
,
"big"
};
#define
SUPPORT_MIDDLE_ENDIAN
1
#if
SUPPORT_MIDDLE_ENDIAN
/* To generate a swap, take the bit-wise complement of the lowest two bits. */
typedef
enum
df_byte_read_order_type
{
DF_0123
,
DF_1032
,
DF_2301
,
DF_3210
}
df_byte_read_order_type
;
/* First argument, this program's endianess. Second argument, file's endianess.
* Don't use directly. Use 'byte_read_order()' function instead.*/
static
char
df_byte_read_order_map
[
4
][
4
]
=
{
{
DF_0123
,
DF_1032
,
DF_2301
,
DF_3210
},
{
DF_1032
,
DF_0123
,
DF_1032
,
DF_2301
},
{
DF_2301
,
DF_1032
,
DF_0123
,
DF_1032
},
{
DF_3210
,
DF_2301
,
DF_1032
,
DF_0123
}
};
static
long
long_0x2468
=
0x2468
;
#define
TEST_BIG_PDP
( (((char *)&long_0x2468)[0] < 3) ? DF_BIG_ENDIAN : DF_PDP_ENDIAN )
#define
THIS_COMPILER_ENDIAN
( (((char *)&long_0x2468)[0] < 5) ? TEST_BIG_PDP : DF_LITTLE_ENDIAN )
/* Argument is file's endianess type. */
static
df_byte_read_order_type
byte_read_order
__PROTO
((
df_endianess_type
));
/* Logical variables indicating information about data file. */
TBOOLEAN
df_binary_file
;
TBOOLEAN
df_matrix_file
;
int
df_M_count
;
int
df_N_count
;
int
df_O_count
;
/* Initially set to default and then possibly altered by command line. */
df_binary_file_record_struct
*
df_bin_record
=
0
;
/* Default settings. */
df_binary_file_record_struct
*
df_bin_record_default
=
0
;
/* Settings that are transferred to default upon reset. */
df_binary_file_record_struct
df_bin_record_reset
=
{
{
-1
,
0
,
0
},
{
1
,
1
,
1
},
{
1
,
1
,
1
},
DF_TRANSLATE_DEFAULT
,
{
0
,
0
,
0
},
0
,
{
0
,
0
,
1
},
{
DF_SCAN_POINT
,
DF_SCAN_LINE
,
DF_SCAN_PLANE
},
FALSE,
{
0
,
0
,
0
},
{
0
,
0
,
0
},
{
1
,
1
,
1
},
{
0
,
0
,
0
},
DF_TRANSLATE_DEFAULT
,
{
0
,
0
,
0
},
NULL
};
int
df_max_num_bin_records
=
0
,
df_num_bin_records
,
df_bin_record_count
;
int
df_max_num_bin_records_default
=
0
,
df_num_bin_records_default
;
static
void
gpbin_filetype_function
__PROTO
((
void
));
static
void
raw_filetype_function
__PROTO
((
void
));
static
void
avs_filetype_function
__PROTO
((
void
));
static
void
(
*
binary_input_function
)(
void
);
/* Will point to one of the above */
static
void
auto_filetype_function
(
void
){};
/* Just a placeholder for auto */
struct
gen_ftable
df_bin_filetype_table
[]
=
{
{
"gpbin"
,
gpbin_filetype_function
},
{
"raw"
,
raw_filetype_function
},
{
"rgb"
,
raw_filetype_function
},
{
"bin"
,
raw_filetype_function
},
{
"avs"
,
avs_filetype_function
},
{
"edf"
,
edf_filetype_function
},
{
"ehf"
,
edf_filetype_function
},
{
"auto"
,
auto_filetype_function
},
{
NULL
,
NULL
}
};
#define
RAW_FILETYPE
1
/* Initially set to default and then possibly altered by command line. */
int
df_bin_filetype
;
df_endianess_type
df_bin_file_endianess
;
/* Default setting. */
int
df_bin_filetype_default
;
df_endianess_type
df_bin_file_endianess_default
;
/* Setting that is transferred to default upon reset. */
int
df_bin_filetype_reset
=
-1
;
#define
DF_BIN_FILE_ENDIANESS_RESET
THIS_COMPILER_ENDIAN
typedef
struct
df_bin_scan_table_2D_struct
{
char
*
string
;
df_sample_scan_type
scan
[
3
];
}
df_bin_scan_table_2D_struct
;
df_bin_scan_table_2D_struct
df_bin_scan_table_2D
[]
=
{
{
"xy"
, {
DF_SCAN_POINT
,
DF_SCAN_LINE
,
DF_SCAN_PLANE
}},
{
"yx"
, {
DF_SCAN_LINE
,
DF_SCAN_POINT
,
DF_SCAN_PLANE
}},
{
"tr"
, {
DF_SCAN_POINT
,
DF_SCAN_LINE
,
DF_SCAN_PLANE
}},
{
"rt"
, {
DF_SCAN_LINE
,
DF_SCAN_POINT
,
DF_SCAN_PLANE
}}
};
#define
TRANSPOSE_INDEX
1
typedef
struct
df_bin_scan_table_3D_struct
{
char
*
string
;
df_sample_scan_type
scan
[
3
];
}
df_bin_scan_table_3D_struct
;
df_bin_scan_table_3D_struct
df_bin_scan_table_3D
[]
=
{
{
"xyz"
, {
DF_SCAN_POINT
,
DF_SCAN_LINE
,
DF_SCAN_PLANE
}},
{
"zxy"
, {
DF_SCAN_LINE
,
DF_SCAN_PLANE
,
DF_SCAN_POINT
}},
{
"yzx"
, {
DF_SCAN_PLANE
,
DF_SCAN_POINT
,
DF_SCAN_LINE
}},
{
"yxz"
, {
DF_SCAN_LINE
,
DF_SCAN_POINT
,
DF_SCAN_PLANE
}},
{
"xzy"
, {
DF_SCAN_POINT
,
DF_SCAN_PLANE
,
DF_SCAN_LINE
}},
{
"zyx"
, {
DF_SCAN_PLANE
,
DF_SCAN_LINE
,
DF_SCAN_POINT
}},
{
"trz"
, {
DF_SCAN_POINT
,
DF_SCAN_LINE
,
DF_SCAN_PLANE
}},
{
"ztr"
, {
DF_SCAN_LINE
,
DF_SCAN_PLANE
,
DF_SCAN_POINT
}},
{
"rzt"
, {
DF_SCAN_PLANE
,
DF_SCAN_POINT
,
DF_SCAN_LINE
}},
{
"rtz"
, {
DF_SCAN_LINE
,
DF_SCAN_POINT
,
DF_SCAN_PLANE
}},
{
"tzr"
, {
DF_SCAN_POINT
,
DF_SCAN_PLANE
,
DF_SCAN_LINE
}},
{
"zrt"
, {
DF_SCAN_PLANE
,
DF_SCAN_LINE
,
DF_SCAN_POINT
}}
};
/* Names for machine dependent field sizes. */
char
*
ch_names
[]
=
{
"char"
,
"schar"
,
"c"
};
char
*
uc_names
[]
=
{
"uchar"
};
char
*
sh_names
[]
=
{
"short"
};
char
*
us_names
[]
=
{
"ushort"
};
char
*
in_names
[]
=
{
"int"
,
"sint"
,
"i"
,
"d"
};
char
*
ui_names
[]
=
{
"uint"
,
"u"
};
char
*
lo_names
[]
=
{
"long"
,
"ld"
};
char
*
ul_names
[]
=
{
"ulong"
,
"lu"
};
char
*
fl_names
[]
=
{
"float"
,
"f"
};
char
*
db_names
[]
=
{
"double"
,
"lf"
};
/* Machine independent names. */
char
*
byte_names
[]
=
{
"int8"
,
"byte"
};
char
*
ubyte_names
[]
=
{
"uint8"
,
"ubyte"
};
char
*
word_names
[]
=
{
"int16"
,
"word"
};
char
*
uword_names
[]
=
{
"uint16"
,
"uword"
};
char
*
word2_names
[]
=
{
"int32"
};
char
*
uword2_names
[]
=
{
"uint32"
};
char
*
word4_names
[]
=
{
"int64"
};
char
*
uword4_names
[]
=
{
"uint64"
};
char
*
float_names
[]
=
{
"float32"
};
char
*
float2_names
[]
=
{
"float64"
};
typedef
struct
df_binary_details_struct
{
char
*
*
name
;
unsigned short
no_names
;
df_binary_type_struct
type
;
}
df_binary_details_struct
;
typedef
struct
df_binary_tables_struct
{
df_binary_details_struct
*
group
;
unsigned short
group_length
;
}
df_binary_tables_struct
;
df_binary_details_struct
df_binary_details
[]
=
{
{
ch_names
,
sizeof
(
ch_names
)/
sizeof
(
ch_names
[
0
]),{
DF_CHAR
,
sizeof
(
char
)}},
{
uc_names
,
sizeof
(
uc_names
)/
sizeof
(
uc_names
[
0
]),{
DF_UCHAR
,
sizeof
(
unsigned
char
)}},
{
sh_names
,
sizeof
(
sh_names
)/
sizeof
(
sh_names
[
0
]),{
DF_SHORT
,
sizeof
(
short
)}},
{
us_names
,
sizeof
(
us_names
)/
sizeof
(
us_names
[
0
]),{
DF_USHORT
,
sizeof
(
unsigned short
)}},
{
in_names
,
sizeof
(
in_names
)/
sizeof
(
in_names
[
0
]),{
DF_INT
,
sizeof
(
int
)}},
{
ui_names
,
sizeof
(
ui_names
)/
sizeof
(
ui_names
[
0
]),{
DF_UINT
,
sizeof
(
unsigned
int
)}},
{
lo_names
,
sizeof
(
lo_names
)/
sizeof
(
lo_names
[
0
]),{
DF_LONG
,
sizeof
(
long
)}},
{
ul_names
,
sizeof
(
ul_names
)/
sizeof
(
ul_names
[
0
]),{
DF_ULONG
,
sizeof
(
unsigned long
)}},
{
fl_names
,
sizeof
(
fl_names
)/
sizeof
(
fl_names
[
0
]),{
DF_FLOAT
,
sizeof
(
float
)}},
{
db_names
,
sizeof
(
db_names
)/
sizeof
(
db_names
[
0
]),{
DF_DOUBLE
,
sizeof
(
double
)}}
};
df_binary_details_struct
df_binary_details_independent
[]
=
{
{
byte_names
,
sizeof
(
byte_names
)/
sizeof
(
byte_names
[
0
]),{
SIGNED_TEST
(
1
),
1
}},
{
ubyte_names
,
sizeof
(
ubyte_names
)/
sizeof
(
ubyte_names
[
0
]),{
UNSIGNED_TEST
(
1
),
1
}},
{
word_names
,
sizeof
(
word_names
)/
sizeof
(
word_names
[
0
]),{
SIGNED_TEST
(
2
),
2
}},
{
uword_names
,
sizeof
(
uword_names
)/
sizeof
(
uword_names
[
0
]),{
UNSIGNED_TEST
(
2
),
2
}},
{
word2_names
,
sizeof
(
word2_names
)/
sizeof
(
word2_names
[
0
]),{
SIGNED_TEST
(
4
),
4
}},
{
uword2_names
,
sizeof
(
uword2_names
)/
sizeof
(
uword2_names
[
0
]),{
UNSIGNED_TEST
(
4
),
4
}},
{
word4_names
,
sizeof
(
word4_names
)/
sizeof
(
word4_names
[
0
]),{
SIGNED_TEST
(
8
),
8
}},
{
uword4_names
,
sizeof
(
uword4_names
)/
sizeof
(
uword4_names
[
0
]),{
UNSIGNED_TEST
(
8
),
8
}},
{
float_names
,
sizeof
(
float_names
)/
sizeof
(
float_names
[
0
]),{
FLOAT_TEST
(
4
),
4
}},
{
float2_names
,
sizeof
(
float2_names
)/
sizeof
(
float2_names
[
0
]),{
FLOAT_TEST
(
8
),
8
}}
};
int
df_no_bin_cols
;
/* binary columns to read */
df_binary_tables_struct
df_binary_tables
[]
=
{
{
df_binary_details
,
sizeof
(
df_binary_details
)/
sizeof
(
df_binary_details
[
0
])},
{
df_binary_details_independent
,
sizeof
(
df_binary_details_independent
)/
sizeof
(
df_binary_details_independent
[
0
])}
};
/* Information about binary data structure, to be determined by the
* using and format options. This should be one greater than df_no_bin_cols.
*/
static
df_column_bininfo_struct
*
df_column_bininfo
=
NULL
;
/* allocate space as needed */
static
int
df_max_bininfo_cols
=
0
;
/* space allocated */
static
const
char
*
matrix_general_binary_conflict_msg
=
"Conflict between some matrix binary and general binary keywords"
;
#endif
/*}}} */
/*{{{ static char *df_gets() */
static
char
*
df_gets
()
{
int
len
=
0
;
/* HBB 20000526: prompt user for inline data, if in interactive mode */
/* EAM 08mar2008: we'd like to call readline(), but this only works
* if isatty(stdin). Do all platforms have an equivalent to isatty()?
*/
if
(
mixed_data_fp
&&
interactive
)
fputs
(
"input data ('e' ends) > "
,
stderr
);
/* Special pseudofiles '+' and '++' return coords of sample */
if
(
df_pseudodata
)
return
df_generate_pseudodata
();
if
(!
fgets
(
line
,
max_line_len
,
data_fp
))
return
NULL
;
if
(
mixed_data_fp
)
++
inline_num
;
for
(;;) {
len
+=
strlen
(
line
+
len
);
if
(
len
>
0
&&
line
[
len
-
1
]
==
'\n'
) {
/* we have read an entire text-file line.
* Strip the trailing linefeed and return
*/
line
[
len
-
1
]
=
0
;
return
line
;
}
/* buffer we provided may not be full - dont grab extra
* memory un-necessarily. This may trap a problem with last
* line in file not being properly terminated - each time
* through a replot loop, it was doubling buffer size
*/
if
((
max_line_len
-
len
)
<
32
)
line
=
gp_realloc
(
line
,
max_line_len
*=
2
,
"datafile line buffer"
);
if
(!
fgets
(
line
+
len
,
max_line_len
-
len
,
data_fp
))
return
line
;
/* unexpected end of file, but we have something to do */
}
/* NOTREACHED */
return
NULL
;
}
/*}}} */
/*{{{ static int df_tokenise(s) */
static
int
df_tokenise
(
char
*
s
)
{
/* implement our own sscanf that takes 'missing' into account,
* and can understand fortran quad format
*/
TBOOLEAN
in_string
;
int
i
;
for
(
i
=
0
;
i
<
MAXDATACOLS
;
i
++
)
df_tokens
[
i
]
=
NULL
;
#if
(
0
)
/* Mar 2009 */
/* This code was broken by moving the check for 'title columnheader' elsewhere.*/
/* Auto-titling of histograms is a bit tricky because the x coord did not come */
/* from an explicit input column. This means our previous guess of what column */
/* to take the title from was probably wrong. */
if
(
key_title_auto_col
&&
df_current_plot
&&
(
df_current_plot
->
plot_style
==
HISTOGRAMS
))
column_for_key_title
=
use_spec
[
0
].
column
;
#endif
#define
NOTSEP
(*s != df_separator)
df_no_cols
=
0
;
while
(
*
s
) {
/* check store - double max cols or add 20, whichever is greater */
if
(
df_max_cols
<=
df_no_cols
) {
int
new_max
=
df_max_cols
+
(
df_max_cols
<
20
?
20
:
df_max_cols
);
df_column
=
gp_realloc
(
df_column
,
new_max
*
sizeof
(
df_column_struct
),
"datafile column"
);
while
(
df_max_cols
<
new_max
)
df_column
[
df_max_cols
++
].
datum
=
0
;
}
/* have always skipped spaces at this point */
df_column
[
df_no_cols
].
position
=
s
;
in_string
=
FALSE;
/* Keep pointer to start of this token if user wanted it for
* anything, particularly if it is a string */
for
(
i
=
0
;
i
<
MAXDATACOLS
;
i
++
) {
if
(
df_no_cols
==
use_spec
[
i
].
column
-
1
) {
df_tokens
[
i
]
=
s
;
if
(
use_spec
[
i
].
expected_type
==
CT_STRING
)
df_column
[
df_no_cols
].
good
=
DF_GOOD
;
}
}
/* Particularly if it is supposed to be a key title */
if
(
df_no_cols
==
column_for_key_title
-
1
) {
free
(
df_key_title
);
df_key_title
=
gp_strdup
(
s
);
}
/* CSV files must accept numbers inside quotes also,
* so we step past the quote */
if
(
*
s
==
'"'
&&
df_separator
!=
'\0'
) {
in_string
=
TRUE;
df_column
[
df_no_cols
].
position
=
++
s
;
}
if
(
*
s
==
'"'
) {
/* treat contents of a quoted string as single column */
in_string
=
!
in_string
;
df_column
[
df_no_cols
].
good
=
DF_MISSING
;
/* Allow timedata input to be contained in quotes */
if
(
axis_array
[
df_axis
[
df_no_cols
]].
timefmt
)
df_column
[
df_no_cols
].
good
=
DF_STRINGDATA
;
}
else
if
(
check_missing
(
s
)) {
df_column
[
df_no_cols
].
good
=
DF_MISSING
;
df_column
[
df_no_cols
].
datum
=
atof
(
"NaN"
);
}
else
{
int
used
;
int
count
;
int
dfncp1
=
df_no_cols
+
1
;
/* optimizations by Corey Satten, corey@cac.washington.edu */
if
((
fast_columns
==
0
)
||
(
df_no_use_specs
==
0
)
||
((
df_no_use_specs
>
0
)
&&
(
use_spec
[
0
].
column
==
dfncp1
||
(
df_no_use_specs
>
1
&&
(
use_spec
[
1
].
column
==
dfncp1
||
(
df_no_use_specs
>
2
&&
(
use_spec
[
2
].
column
==
dfncp1
||
(
df_no_use_specs
>
3
&&
(
use_spec
[
3
].
column
==
dfncp1
||
(
df_no_use_specs
>
4
&&
(
use_spec
[
4
].
column
==
dfncp1
||
df_no_use_specs
>
5
)
)
)
)
)
)
)
)
)
)
) {
/* This was the [slow] code used through version 4.0
* count = sscanf(s, "%lf%n", &df_column[df_no_cols].datum, &used);
*/
/* Use strtod() because
* - it is faster than sscanf()
* - sscanf(... %n ...) may not be portable
* - it allows error checking
* - atof() does not return a count or new position
*/
char
*
next
;
df_column
[
df_no_cols
].
datum
=
gp_strtod
(
s
,
&
next
);
used
=
next
-
s
;
count
=
(
used
) ?
1
:
0
;
}
else
{
/* skip any space at start of column */
/* HBB tells me that the cast must be to
* unsigned char instead of int. */
while
(
isspace
((
unsigned
char
)
*
s
)
&&
NOTSEP
)
++
s
;
count
=
(
*
s
&&
NOTSEP
) ?
1
:
0
;
/* skip chars to end of column */
used
=
0
;
if
(
df_separator
!=
'\0'
&&
in_string
) {
do
++
s
;
while
(
*
s
&&
*
s
!=
'"'
);
in_string
=
FALSE;
}
while
(!
isspace
((
unsigned
char
)
*
s
)
&&
(
*
s
!=
NUL
)
&&
NOTSEP
)
++
s
;
}
/* it might be a fortran double or quad precision.
* 'used' is only safe if count is 1
*/
if
(
df_fortran_constants
&&
count
==
1
&&
(
s
[
used
]
==
'd'
||
s
[
used
]
==
'D'
||
s
[
used
]
==
'q'
||
s
[
used
]
==
'Q'
)) {
/* HBB 20001221: avoid breaking parsing of time/date
* strings like 01Dec2000 that would be caused by
* overwriting the 'D' with an 'e'... */
char
*
endptr
;
char
save_char
=
s
[
used
];
/* might be fortran double */
s
[
used
]
=
'e'
;
/* and try again */
df_column
[
df_no_cols
].
datum
=
gp_strtod
(
s
,
&
endptr
);
count
=
(
endptr
==
s
) ?
0
:
1
;
s
[
used
]
=
save_char
;
}
df_column
[
df_no_cols
].
good
=
count
==
1
?
DF_GOOD
:
DF_BAD
;
#ifdef
HAVE_ISNAN
if
(
isnan
(
df_column
[
df_no_cols
].
datum
))
df_column
[
df_no_cols
].
good
=
DF_BAD
;
#endif
}
++
df_no_cols
;
/* EAM - 19 Aug 2002 If we are in a quoted string, skip to end
* of quote */
if
(
in_string
) {
do
s
++
;
while
(
*
s
&&
(
unsigned
char
)
*
s
!=
'"'
);
}
/* skip to 1st character past next separator */
if
(
df_separator
!=
'\0'
) {
while
(
*
s
&&
NOTSEP
)
++
s
;
if
(
*
s
==
df_separator
)
/* skip leading whitespace in next field */
do
++
s
;
while
(
*
s
&&
isspace
((
unsigned
char
)
*
s
)
&&
NOTSEP
);
}
else
{
/* skip chars to end of column */
while
((!
isspace
((
unsigned
char
)
*
s
))
&&
(
*
s
!=
'\0'
))
++
s
;
/* skip spaces to start of next column */
while
(
isspace
((
unsigned
char
)
*
s
))
++
s
;
}
}
return
df_no_cols
;
#undef
NOTSEP
}
/*}}} */
/*{{{ static float *df_read_matrix() */
/* Reads a matrix from a text file and stores it as floats in allocated
* memory.
*
* IMPORTANT NOTE: The routine returns the memory pointer for that matrix,
* but does not retain the pointer. Maintenance of the memory is left to
* the calling code.
*/
static
float
*
df_read_matrix
(
int
*
rows
,
int
*
cols
)
{
int
max_rows
=
0
;
int
c
;
float
*
linearized_matrix
=
NULL
;
int
bad_data
=
0
;
char
*
s
;
int
index
=
0
;
*
rows
=
0
;
*
cols
=
0
;
for
(;;) {
if
(!(
s
=
df_gets
())) {
df_eof
=
1
;
/* NULL if we have not read anything yet */
return
linearized_matrix
;
}
while
(
isspace
((
unsigned
char
)
*
s
))
++
s
;
if
(!
*
s
||
is_comment
(
*
s
)) {
if
(
linearized_matrix
)
return
linearized_matrix
;
else
continue
;
}
if
(
mixed_data_fp
&&
is_EOF
(
*
s
)) {
df_eof
=
1
;
return
linearized_matrix
;
}
c
=
df_tokenise
(
s
);
if
(!
c
)
return
linearized_matrix
;
if
(
*
cols
&&
c
!=
*
cols
) {
/* its not regular */
if
(
linearized_matrix
)
free
(
linearized_matrix
);
int_error
(
NO_CARET
,
"Matrix does not represent a grid"
);
}
*
cols
=
c
;
++
*
rows
;
if
(
*
rows
>
max_rows
) {
max_rows
=
GPMAX
(
2
*
max_rows
,
1
);
linearized_matrix
=
gp_realloc
(
linearized_matrix
,
*
cols
*
max_rows
*
sizeof
(
float
),
"df_matrix"
);
}
/* store data */
{
int
i
;
for
(
i
=
0
;
i
<
c
;
++
i
) {
if
(
i
<
firstpoint
&&
df_column
[
i
].
good
!=
DF_GOOD
) {
/* It's going to be skipped anyhow, so... */
linearized_matrix
[
index
++
]
=
0
;
}
else
linearized_matrix
[
index
++
]
=
(
float
)
df_column
[
i
].
datum
;
if
(
df_column
[
i
].
good
!=
DF_GOOD
) {
if
(
bad_data
++
==
0
)
int_warn
(
NO_CARET
,
"matrix contains missing or undefined values"
);
}
}
}
}
}
/*}}} */
static
void
initialize_use_spec
()
{
int
i
;
df_no_use_specs
=
0
;
for
(
i
=
0
;
i
<
MAXDATACOLS
;
++
i
) {
use_spec
[
i
].
column
=
i
+
1
;
/* default column */
use_spec
[
i
].
expected_type
=
CT_DEFAULT
;
/* no particular expectation */
if
(
use_spec
[
i
].
at
) {
free_at
(
use_spec
[
i
].
at
);
use_spec
[
i
].
at
=
NULL
;
/* no expression */
}
df_axis
[
i
]
=
NO_AXIS
;
/* no timefmt for this output column */
}
}
/*{{{ int df_open(char *file_name, int max_using, plot_header *plot) */
/* open file, parsing using/thru/index stuff return number of using
* specs [well, we have to return something !]
*/
int
df_open
(
const
char
*
cmd_filename
,
int
max_using
,
struct
curve_points
*
plot
)
{
int
name_token
=
c_token
-
1
;
TBOOLEAN
duplication
=
FALSE;
TBOOLEAN
set_index
=
FALSE,
set_every
=
FALSE,
set_thru
=
FALSE;
TBOOLEAN
set_using
=
FALSE;
TBOOLEAN
set_matrix
=
FALSE;
fast_columns
=
1
;
/* corey@cac */
/* close file if necessary */
if
(
data_fp
) {
df_close
();
data_fp
=
NULL
;
}
/*{{{ initialise static variables */
free
(
df_format
);
df_format
=
NULL
;
/* no format string */
df_no_tic_specs
=
0
;
free
(
df_key_title
);
df_key_title
=
NULL
;
initialize_use_spec
();
df_datum
=
-1
;
/* it will be preincremented before use */
df_line_number
=
0
;
/* ditto */
df_lower_index
=
0
;
df_index_step
=
1
;
df_upper_index
=
MAXINT
;
free
(
indexname
);
indexname
=
NULL
;
df_current_index
=
0
;
blank_count
=
2
;
/* by initialising blank_count, leading blanks will be ignored */
everypoint
=
everyline
=
1
;
/* unless there is an every spec */
firstpoint
=
firstline
=
0
;
lastpoint
=
lastline
=
MAXINT
;
df_binary_file
=
df_matrix_file
=
FALSE;
df_eof
=
0
;
/* Save for use by df_readline(). */
/* Perhaps it should be a parameter to df_readline? */
df_current_plot
=
plot
;
column_for_key_title
=
NO_COLUMN_HEADER
;
/*}}} */
assert
(
max_using
<=
MAXDATACOLS
);
if
(!
cmd_filename
)
int_error
(
c_token
,
"missing filename"
);
if
(!
cmd_filename
[
0
]) {
if
(!
df_filename
||
!
*
df_filename
)
int_error
(
c_token
,
"No previous filename"
);
}
else
{
free
(
df_filename
);
df_filename
=
gp_strdup
(
cmd_filename
);
}
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL