FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/src/datafile.c at axis_branch_base · 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
1458 lines (1238 loc) · 38.3 KB
Breadcrumbs
gnuplot-old
/
src
/
datafile.c
Copy path
File metadata and controls
1458 lines (1238 loc) · 38.3 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.18.2.4 2000/07/26 18:52:58 broeker Exp $"
); }
#endif
/* GNUPLOT - datafile.c */
/*[
* Copyright 1986 - 1993, 1998 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.
*
* use a global array df_timecol[] - cleared by df_open, then
* columns needing time set by client.
*
* 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_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
* int df_timecol[] - client controls which cols read as time
*
* functions
* int df_open(int max_using)
* parses thru / index / using on command line
* max_using is max no of 'using' columns allowed
* 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_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
*
*/
/*}}} */
#include
"datafile.h"
#include
"alloc.h"
#include
"axis.h"
#include
"command.h"
#include
"binary.h"
#include
"gp_time.h"
#include
"graphics.h"
#include
"internal.h"
#include
"misc.h"
#include
"parse.h"
#include
"plot.h"
/* #include "setshow.h" */
#include
"util.h"
/* if you change this, change the scanf in readline */
#define
NCOL
7
/* max using specs */
/* test to see if the end of an inline datafile is reached */
#define
is_EOF
(
c
) ((c) == 'e' || (c) == 'E')
/*{{{ 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
*
));
/*}}} */
/*{{{ variables */
struct
use_spec_s
{
int
column
;
struct
at_type
*
at
;
};
/* 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 */
TBOOLEAN
df_matrix
=
FALSE;
/* is this a matrix splot */
int
df_eof
=
0
;
AXIS_INDEX
df_axis
[
NCOL
];
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
;
/* If any 'inline data' are in use for the current plot, flag this */
TBOOLEAN
plotted_data_from_stdin
=
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
;
static
TBOOLEAN
df_pipe_open
=
FALSE;
static
TBOOLEAN
mixed_data_fp
=
FALSE;
#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 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 */
/* parsing stuff */
static
struct
use_spec_s
use_spec
[
NCOL
];
static
char
df_format
[
MAX_LINE_LEN
+
1
];
/* rather than three arrays which all grow dynamically, make one
* dynamic array of this structure
*/
typedef
struct
df_column_struct
{
double
datum
;
enum
{
DF_MISSING
,
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 */
/* columns needing timefmt are passed in df_timecol[] after df_open */
/*}}} */
/*{{{ static char *df_gets() */
static
char
*
df_gets
()
{
int
len
=
0
;
/* HBB 20000526: prompt user for inline data, if in interactive mode */
if
(
mixed_data_fp
&&
interactive
)
fputs
(
"input data ('e' ends) > "
,
stderr
);
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
(
s
)
char
*
s
;
{
/* implement our own sscanf that takes 'missing' into account,
* and can understand fortran quad format
*/
df_no_cols
=
0
;
while
(
*
s
) {
/* check store - double max cols or add 20, whichever is greater */
if
(
df_max_cols
<=
df_no_cols
)
df_column
=
(
df_column_struct
*
)
gp_realloc
(
df_column
,
(
df_max_cols
+=
(
df_max_cols
<
20
?
20
:
df_max_cols
))
*
sizeof
(
df_column_struct
),
"datafile column"
);
/* have always skipped spaces at this point */
df_column
[
df_no_cols
].
position
=
s
;
if
(
check_missing
(
s
))
df_column
[
df_no_cols
].
good
=
DF_MISSING
;
else
{
#ifdef
OSK
/* apparently %n does not work. This implementation
* is just as good as the non-OSK one, but close
* to a release (at last) we make it os-9 specific
*/
int
count
;
char
*
p
=
strpbrk
(
s
,
"dqDQ"
);
if
(
p
!=
NULL
)
*
p
=
'e'
;
count
=
sscanf
(
s
,
"%lf"
,
&
df_column
[
df_no_cols
].
datum
);
#else
/* cannot trust strtod - eg strtod("-",&p) */
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
)
)
)
)
)
)
)
)
)
)
) {
#ifndef
NO_FORTRAN_NUMS
count
=
sscanf
(
s
,
"%lf%n"
,
&
df_column
[
df_no_cols
].
datum
,
&
used
);
#else
while
(
isspace
(
*
s
))
++
s
;
count
=
*
s
?
1
:
0
;
df_column
[
df_no_cols
].
datum
=
atof
(
s
);
#endif
/* NO_FORTRAN_NUMS */
}
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
))
++
s
;
count
=
*
s
?
1
:
0
;
/* skip chars to end of column */
used
=
0
;
while
(!
isspace
((
unsigned
char
)
*
s
)
&&
(
*
s
!=
NUL
))
++
s
;
}
/* it might be a fortran double or quad precision.
* 'used' is only safe if count is 1
*/
#ifndef
NO_FORTRAN_NUMS
if
(
count
==
1
&&
(
s
[
used
]
==
'd'
||
s
[
used
]
==
'D'
||
s
[
used
]
==
'q'
||
s
[
used
]
==
'Q'
)) {
/* might be fortran double */
s
[
used
]
=
'e'
;
/* and try again */
count
=
sscanf
(
s
,
"%lf"
,
&
df_column
[
df_no_cols
].
datum
);
}
#endif
/* NO_FORTRAN_NUMS */
#endif
/* OSK */
df_column
[
df_no_cols
].
good
=
count
==
1
?
DF_GOOD
:
DF_BAD
;
}
++
df_no_cols
;
/*{{{ skip chars to end of column */
while
((!
isspace
((
int
)
*
s
))
&&
(
*
s
!=
'\0'
))
++
s
;
/*}}} */
/*{{{ skip spaces to start of next column */
while
(
isspace
((
int
)
*
s
))
++
s
;
/*}}} */
}
return
df_no_cols
;
}
/*}}} */
/*{{{ static float **df_read_matrix() */
/* reads a matrix from a text file
* stores in same storage format as fread_matrix
*/
static
float
*
*
df_read_matrix
(
rows
,
cols
)
int
*
rows
,
*
cols
;
{
int
max_rows
=
0
;
int
c
;
float
*
*
rmatrix
=
NULL
;
char
*
s
;
*
rows
=
0
;
*
cols
=
0
;
for
(;;) {
if
(!(
s
=
df_gets
())) {
df_eof
=
1
;
return
rmatrix
;
/* NULL if we have not read anything yet */
}
while
(
isspace
((
int
)
*
s
))
++
s
;
if
(!
*
s
||
is_comment
(
*
s
)) {
if
(
rmatrix
)
return
rmatrix
;
else
continue
;
}
if
(
mixed_data_fp
&&
is_EOF
(
*
s
)) {
df_eof
=
1
;
return
rmatrix
;
}
c
=
df_tokenise
(
s
);
if
(!
c
)
return
rmatrix
;
if
(
*
cols
&&
c
!=
*
cols
) {
/* its not regular */
int_error
(
NO_CARET
,
"Matrix does not represent a grid"
);
}
*
cols
=
c
;
if
(
*
rows
>=
max_rows
) {
rmatrix
=
gp_realloc
(
rmatrix
, (
max_rows
+=
10
)
*
sizeof
(
float
*
),
"df_matrix"
);
}
/* allocate a row and store data */
{
int
i
;
float
*
row
=
rmatrix
[
*
rows
]
=
(
float
*
)
gp_alloc
(
c
*
sizeof
(
float
),
"df_matrix row"
);
for
(
i
=
0
;
i
<
c
;
++
i
) {
if
(
df_column
[
i
].
good
!=
DF_GOOD
)
int_error
(
NO_CARET
,
"Bad number in matrix"
);
row
[
i
]
=
(
float
)
df_column
[
i
].
datum
;
}
++
*
rows
;
}
}
}
/*}}} */
/*{{{ int df_open(max_using) */
int
df_open
(
max_using
)
int
max_using
;
/* open file, parsing using/thru/index stuff
* return number of using specs [well, we have to return something !]
*/
{
/* now allocated dynamically */
static
char
*
filename
=
NULL
;
int
i
;
int
name_token
;
fast_columns
=
1
;
/* corey@cac */
/*{{{ close file if necessary */
if
(
data_fp
)
df_close
();
/*}}} */
/*{{{ initialise static variables */
df_format
[
0
]
=
NUL
;
/* no format string */
df_no_use_specs
=
0
;
for
(
i
=
0
;
i
<
NCOL
;
++
i
) {
use_spec
[
i
].
column
=
i
+
1
;
/* default column */
use_spec
[
i
].
at
=
NULL
;
/* no expression */
df_axis
[
i
]
=
-1
;
/* no timefmt for this output column */
}
if
(
max_using
>
NCOL
)
max_using
=
NCOL
;
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
;
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_eof
=
0
;
df_binary
=
1
;
/*}}} */
assert
(
max_using
<=
NCOL
);
/* empty name means re-use last one */
if
(
isstring
(
c_token
)
&&
token_len
(
c_token
)
==
2
) {
if
(!
filename
||
!
*
filename
)
int_error
(
c_token
,
"No previous filename"
);
}
else
{
filename
=
gp_realloc
(
filename
,
token_len
(
c_token
),
"datafile name"
);
quote_str
(
filename
,
c_token
,
token_len
(
c_token
));
}
name_token
=
c_token
++
;
/* defer opening until we have parsed the modifiers... */
/*{{{ look for binary / matrix */
df_binary
=
df_matrix
=
FALSE;
if
(
almost_equals
(
c_token
,
"bin$ary"
)) {
++
c_token
;
df_binary
=
TRUE;
df_matrix
=
TRUE;
}
else
if
(
almost_equals
(
c_token
,
"mat$rix"
)) {
++
c_token
;
df_matrix
=
TRUE;
}
/*}}} */
/*{{{ deal with index */
if
(
almost_equals
(
c_token
,
"i$ndex"
)) {
plot_option_index
();
}
/*}}} */
/*{{{ deal with every */
if
(
almost_equals
(
c_token
,
"ev$ery"
)) {
plot_option_every
();
}
/*}}} */
/*{{{ deal with thru */
/* jev -- support for passing data from file thru user function */
if
(
ydata_func
.
at
)
free
(
ydata_func
.
at
);
ydata_func
.
at
=
NULL
;
if
(
almost_equals
(
c_token
,
"thru$"
)) {
plot_option_thru
();
}
/*}}} */
/*{{{ deal with using */
if
(
almost_equals
(
c_token
,
"u$sing"
)) {
plot_option_using
(
max_using
);
}
/*}}} */
/*{{{ more variable inits */
point_count
=
-1
;
/* we preincrement */
line_count
=
0
;
/* here so it's not done for every line in df_readline */
if
(
max_line_len
<
DATA_LINE_BUFSIZ
) {
max_line_len
=
DATA_LINE_BUFSIZ
;
line
=
(
char
*
)
gp_alloc
(
max_line_len
,
"datafile line buffer"
);
}
/*}}} */
/* filename cannot be static array! */
gp_expand_tilde
(
&
filename
);
/*{{{ open file */
#if
defined(
PIPES
)
if
(
*
filename
==
'<'
) {
if
((
data_fp
=
popen
(
filename
+
1
,
"r"
))
==
(
FILE
*
)
NULL
)
os_error
(
name_token
,
"cannot create pipe for data"
);
else
df_pipe_open
=
TRUE;
}
else
#endif
/* PIPES */
/* I don't want to call strcmp(). Does it make a difference? */
if
(
*
filename
==
'-'
&&
strlen
(
filename
)
==
1
) {
plotted_data_from_stdin
=
TRUE;
data_fp
=
lf_top
();
if
(!
data_fp
)
data_fp
=
stdin
;
mixed_data_fp
=
TRUE;
/* don't close command file */
}
else
{
#ifdef
HAVE_SYS_STAT_H
struct
stat
statbuf
;
if
((
stat
(
filename
,
&
statbuf
)
>
-1
)
&&
!
S_ISREG
(
statbuf
.
st_mode
)
&&
!
S_ISFIFO
(
statbuf
.
st_mode
)) {
os_error
(
name_token
,
"\"%s\" is not a regular file or pipe"
,
filename
);
}
#endif
/* HAVE_SYS_STAT_H */
if
((
data_fp
=
loadpath_fopen
(
filename
,
df_binary
?
"rb"
:
"r"
))
==
(
FILE
*
)
NULL
) {
os_error
(
name_token
,
"can't read data file \"%s\""
,
filename
);
}
}
/*}}} */
return
df_no_use_specs
;
}
/*}}} */
/*{{{ void df_close() */
void
df_close
()
{
int
i
;
/* paranoid - mark $n and column(n) as invalid */
df_no_cols
=
0
;
if
(!
data_fp
)
return
;
if
(
ydata_func
.
at
) {
free
(
ydata_func
.
at
);
ydata_func
.
at
=
NULL
;
}
/*{{{ free any use expression storage */
for
(
i
=
0
;
i
<
df_no_use_specs
;
++
i
)
if
(
use_spec
[
i
].
at
) {
free
(
use_spec
[
i
].
at
);
use_spec
[
i
].
at
=
NULL
;
}
/*}}} */
if
(!
mixed_data_fp
) {
#if
defined(
PIPES
)
if
(
df_pipe_open
) {
(
void
)
pclose
(
data_fp
);
df_pipe_open
=
FALSE;
}
else
#endif
/* PIPES */
(
void
)
fclose
(
data_fp
);
}
mixed_data_fp
=
FALSE;
data_fp
=
NULL
;
}
/*}}} */
static
void
plot_option_every
()
{
struct
value
a
;
fast_columns
=
0
;
/* corey@cac */
/* allow empty fields - every a:b:c::e
* we have already established the defaults
*/
if
(!
equals
(
++
c_token
,
":"
)) {
everypoint
=
(
int
)
real
(
const_express
(
&
a
));
if
(
everypoint
<
1
)
int_error
(
c_token
,
"Expected positive integer"
);
}
/* if it fails on first test, no more tests will succeed. If it
* fails on second test, next test will succeed with correct c_token
*/
if
(
equals
(
c_token
,
":"
)
&&
!
equals
(
++
c_token
,
":"
)) {
everyline
=
(
int
)
real
(
const_express
(
&
a
));
if
(
everyline
<
1
)
int_error
(
c_token
,
"Expected positive integer"
);
}
if
(
equals
(
c_token
,
":"
)
&&
!
equals
(
++
c_token
,
":"
)) {
firstpoint
=
(
int
)
real
(
const_express
(
&
a
));
if
(
firstpoint
<
0
)
int_error
(
c_token
,
"Expected non-negative integer"
);
}
if
(
equals
(
c_token
,
":"
)
&&
!
equals
(
++
c_token
,
":"
)) {
firstline
=
(
int
)
real
(
const_express
(
&
a
));
if
(
firstline
<
0
)
int_error
(
c_token
,
"Expected non-negative integer"
);
}
if
(
equals
(
c_token
,
":"
)
&&
!
equals
(
++
c_token
,
":"
)) {
lastpoint
=
(
int
)
real
(
const_express
(
&
a
));
if
(
lastpoint
<
firstpoint
)
int_error
(
c_token
,
"Last point must not be before first point"
);
}
if
(
equals
(
c_token
,
":"
)) {
++
c_token
;
lastline
=
(
int
)
real
(
const_express
(
&
a
));
if
(
lastline
<
firstline
)
int_error
(
c_token
,
"Last line must not be before first line"
);
}
}
static
void
plot_option_index
()
{
struct
value
a
;
if
(
df_binary
)
int_error
(
c_token
,
"Binary file format does not allow more than one surface per file"
);
++
c_token
;
df_lower_index
=
(
int
)
real
(
const_express
(
&
a
));
if
(
equals
(
c_token
,
":"
)) {
++
c_token
;
df_upper_index
=
(
int
)
magnitude
(
const_express
(
&
a
));
if
(
df_upper_index
<
df_lower_index
)
int_error
(
c_token
,
"Upper index should be bigger than lower index"
);
if
(
equals
(
c_token
,
":"
)) {
++
c_token
;
df_index_step
=
(
int
)
magnitude
(
const_express
(
&
a
));
if
(
df_index_step
<
1
)
int_error
(
c_token
,
"Index step must be positive"
);
}
}
else
df_upper_index
=
df_lower_index
;
}
static
void
plot_option_thru
()
{
c_token
++
;
strcpy
(
c_dummy_var
[
0
],
set_dummy_var
[
0
]);
/* allow y also as a dummy variable.
* during plot, c_dummy_var[0] and [1] are 'sacred'
* ie may be set by splot [u=1:2] [v=1:2], and these
* names are stored only in c_dummy_var[]
* so choose dummy var 2 - can anything vital be here ?
*/
dummy_func
=
&
ydata_func
;
strcpy
(
c_dummy_var
[
2
],
"y"
);
ydata_func
.
at
=
perm_at
();
dummy_func
=
NULL
;
}
static
void
plot_option_using
(
max_using
)
int
max_using
;
{
if
(!
END_OF_COMMAND
&&
!
isstring
(
++
c_token
)) {
struct
value
a
;
do
{
/* must be at least one */
if
(
df_no_use_specs
>=
max_using
)
int_error
(
c_token
,
"Too many columns in using specification"
);
if
(
equals
(
c_token
,
":"
)) {
/* empty specification - use default */
use_spec
[
df_no_use_specs
].
column
=
df_no_use_specs
;
++
df_no_use_specs
;
/* do not increment c+token ; let while() find the : */
}
else
if
(
equals
(
c_token
,
"("
)) {
fast_columns
=
0
;
/* corey@cac */
dummy_func
=
NULL
;
/* no dummy variables active */
use_spec
[
df_no_use_specs
++
].
at
=
perm_at
();
/* it will match ()'s */
}
else
{
int
col
=
(
int
)
real
(
const_express
(
&
a
));
if
(
col
<
-2
)
int_error
(
c_token
,
"Column must be >= -2"
);
use_spec
[
df_no_use_specs
++
].
column
=
col
;
}
}
while
(
equals
(
c_token
,
":"
)
&&
++
c_token
);
}
if
(!
END_OF_COMMAND
&&
isstring
(
c_token
)) {
if
(
df_binary
)
int_error
(
NO_CARET
,
"Format string meaningless with binary data"
);
quote_str
(
df_format
,
c_token
,
MAX_LINE_LEN
);
if
(!
valid_format
(
df_format
))
int_error
(
c_token
,
"Please use a double conversion %lf"
);
c_token
++
;
/* skip format */
}
}
/*{{{ int df_readline(v, max) */
/* do the hard work... read lines from file,
* - use blanks to get index number
* - ignore lines outside range of indices required
* - fill v[] based on using spec if given
*/
int
df_readline
(
v
,
max
)
double
v
[];
int
max
;
{
char
*
s
;
assert
(
data_fp
!=
NULL
);
assert
(!
df_binary
);
assert
(
max_line_len
);
/* alloc-ed in df_open() */
assert
(
max
<=
NCOL
);
/* catch attempt to read past EOF on mixed-input */
if
(
df_eof
)
return
DF_EOF
;
while
((
s
=
df_gets
())
!=
NULL
)
/*{{{ process line */
{
int
line_okay
=
1
;
int
output
=
0
;
/* how many numbers written to v[] */
++
df_line_number
;
df_no_cols
=
0
;
/*{{{ check for blank lines, and reject by index/every */
/*{{{ skip leading spaces */
while
(
isspace
((
int
)
*
s
))
++
s
;
/* will skip the \n too, to point at \0 */
/*}}} */
/*{{{ skip comments */
if
(
is_comment
(
*
s
))
continue
;
/* ignore comments */
/*}}} */
/*{{{ check EOF on mixed data */
if
(
mixed_data_fp
&&
is_EOF
(
*
s
)) {
df_eof
=
1
;
/* trap attempts to read past EOF */
return
DF_EOF
;
}
/*}}} */
/*{{{ its a blank line - update counters and continue or return */
if
(
*
s
==
0
) {
/* argh - this is complicated ! we need to
* ignore it if we haven't reached first index
* report EOF if passed last index
* report blank line unless we've already done 2 blank lines
*
* - I have probably missed some obvious way of doing all this,
* but its getting late
*/
point_count
=
-1
;
/* restart counter within line */
if
(
++
blank_count
==
1
) {
/* first blank line */
++
line_count
;
}
/* just reached end of a group/surface */
if
(
blank_count
==
2
) {
++
df_current_index
;
line_count
=
0
;
df_datum
=
-1
;
/* ignore line if current_index has just become
* first required one - client doesn't want this
* blank line. While we're here, check for <=
* - we need to do it outside this conditional, but
* probably no extra cost at assembler level
*/
if
(
df_current_index
<=
df_lower_index
)
continue
;
/* dont tell client */
/* df_upper_index is MAXINT-1 if we are not doing index */
if
(
df_current_index
>
df_upper_index
) {
/* oops - need to gobble rest of input if mixed */
if
(
mixed_data_fp
)
continue
;
else
{
df_eof
=
1
;
return
DF_EOF
;
/* no point continuing */
}
}
}
/* dont tell client if we haven't reached first index */
if
(
df_current_index
<
df_lower_index
)
continue
;
/* ignore blank lines after blank_index */
if
(
blank_count
>
2
)
continue
;
return
DF_FIRST_BLANK
-
(
blank_count
-
1
);
}
/*}}} */
/* get here => was not blank */
blank_count
=
0
;
/*{{{ ignore points outside range of index */
/* we try to return end-of-file as soon as we pass upper index,
* but for mixed input stream, we must skip garbage
*/
if
(
df_current_index
<
df_lower_index
||
df_current_index
>
df_upper_index
||
((
df_current_index
-
df_lower_index
) %
df_index_step
)
!=
0
)
continue
;
/*}}} */
/*{{{ reject points by every */
/* accept only lines with (line_count%everyline) == 0 */
if
(
line_count
<
firstline
||
line_count
>
lastline
||
(
line_count
-
firstline
) %
everyline
!=
0
)
continue
;
/* update point_count. ignore point if point_count%everypoint != 0 */
if
(
++
point_count
<
firstpoint
||
point_count
>
lastpoint
||
(
point_count
-
firstpoint
) %
everypoint
!=
0
)
continue
;
/*}}} */
/*}}} */
++
df_datum
;
/*{{{ do a sscanf */
if
(
*
df_format
) {
int
i
;
assert
(
NCOL
==
7
);
/* check we have room for at least 7 columns */
if
(
df_max_cols
<
7
) {
df_max_cols
=
7
;
df_column
=
(
df_column_struct
*
)
gp_realloc
(
df_column
,
df_max_cols
*
sizeof
(
df_column_struct
),
"datafile columns"
);
}
df_no_cols
=
sscanf
(
line
,
df_format
,
&
df_column
[
0
].
datum
,
&
df_column
[
1
].
datum
,
&
df_column
[
2
].
datum
,
&
df_column
[
3
].
datum
,
&
df_column
[
4
].
datum
,
&
df_column
[
5
].
datum
,
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL