FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/src/plot2d.c at pm3d · 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
/
plot2d.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
1573 lines (1376 loc) · 46.5 KB
Breadcrumbs
gnuplot-old
/
src
/
plot2d.c
Copy path
File metadata and controls
1573 lines (1376 loc) · 46.5 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: plot2d.c,v 1.26.2.5 2000/10/24 13:37:52 joze Exp $"
); }
#endif
/* GNUPLOT - plot2d.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.
]*/
#include
"plot2d.h"
#include
"alloc.h"
#include
"binary.h"
#include
"command.h"
#include
"datafile.h"
#include
"graphics.h"
#include
"fit.h"
#include
"interpol.h"
#include
"misc.h"
#include
"parse.h"
#include
"setshow.h"
#include
"tables.h"
#include
"term_api.h"
#include
"util.h"
#ifndef
_Windows
# include
"help.h"
#endif
/* static prototypes */
void
plot3drequest
__PROTO
((
void
));
void
define
__PROTO
((
void
));
static
int
get_data
__PROTO
((
struct
curve_points
*
));
static
void
store2d_point
__PROTO
((
struct
curve_points
*
,
int
i
,
double
x
,
double
y
,
double
xlow
,
double
xhigh
,
double
ylow
,
double
yhigh
,
double
width
));
static
void
print_table
__PROTO
((
struct
curve_points
*
first_plot
,
int
plot_num
));
static
void
eval_plots
__PROTO
((
void
));
static
void
parametric_fixup
__PROTO
((
struct
curve_points
*
start_plot
,
int
*
plot_num
));
/* the curves/surfaces of the plot */
struct
curve_points
*
first_plot
=
NULL
;
static
struct
udft_entry
plot_func
;
/* in order to support multiple axes, and to
* simplify ranging in parametric plots, we use
* arrays to store some things.
* Elements are z = 0, y1 = 1, x1 = 2, [z2 =4 ], y2 = 5, x2 = 6
* these are given symbolic names in plot.h
*/
/* if user specifies [10:-10] we use [-10:10] internally, and swap at end */
int
reverse_range
[
AXIS_ARRAY_SIZE
];
/*
* IMHO, code is getting too cluttered with repeated chunks of
* code. Some macros to simplify, I hope.
*
* do { } while(0) is comp.lang.c recommendation for complex macros
* also means that break can be specified as an action, and it will
*
*/
/* copy scalar data to arrays
* optimiser should optimise infinite away
* dont know we have to support ranges [10:-10] - lets reverse
* it for now, then fix it at the end.
*/
#define
INIT_ARRAYS
(
axis
,
min
,
max
,
auto
,
is_log
,
base
,
log_base
,
infinite
) \
do{auto_array[axis] = auto; \
min_array[axis] = (infinite && (auto&1)) ? VERYLARGE : min; \
max_array[axis] = (infinite && (auto&2)) ? -VERYLARGE : max; \
log_array[axis] = is_log; base_array[axis] = base; \
log_base_array[axis] = log_base; \
}while(0)
/* handle reversed ranges */
#define
CHECK_REVERSE
(
axis
) \
do{ \
if (auto_array[axis] == 0 && max_array[axis] < min_array[axis]) { \
double temp = min_array[axis]; \
min_array[axis] = max_array[axis]; \
max_array[axis] = temp; \
reverse_range[axis] = 1; \
} else \
reverse_range[axis] = (range_flags[axis]&RANGE_REVERSE); \
}while(0)
/* get optional [min:max] */
#define
LOAD_RANGE
(
axis
) \
do { \
if (equals(c_token, "[")) { \
c_token++; \
auto_array[axis] = load_range(axis,&min_array[axis], &max_array[axis], auto_array[axis]); \
if (!equals(c_token, "]")) \
int_error(c_token, "']' expected"); \
c_token++; \
} \
} while (0)
/* store VALUE or log(VALUE) in STORE, set TYPE as appropriate
* Do OUT_ACTION or UNDEF_ACTION as appropriate
* adjust range provided type is INRANGE (ie dont adjust y if x is outrange
* VALUE must not be same as STORE
*/
#define
STORE_WITH_LOG_AND_FIXUP_RANGE
(
STORE
,
VALUE
,
TYPE
,
AXIS
,
OUT_ACTION
,
UNDEF_ACTION
)\
do { \
if (log_array[AXIS]) { \
if (VALUE<0.0) { \
TYPE = UNDEFINED; \
UNDEF_ACTION; \
break; \
} else if (VALUE == 0.0) { \
STORE = -VERYLARGE; \
TYPE = OUTRANGE; \
OUT_ACTION; \
break; \
} else { \
STORE = log(VALUE)/log_base_array[AXIS]; \
} \
} else \
STORE = VALUE; \
if (TYPE != INRANGE) \
break;
/* dont set y range if x is outrange, for example */
\
if
(
VALUE
<
min_array
[
AXIS
] ) { \
if
(
auto_array
[
AXIS
]
&
1
) \
min_array
[
AXIS
]
=
VALUE
; \
else
{ \
TYPE
=
OUTRANGE
; \
OUT_ACTION
;
break
; \
} \
} \
if
(
VALUE
>
max_array
[
AXIS
] ) { \
if
(
auto_array
[
AXIS
]
&
2
) \
max_array
[
AXIS
]
=
VALUE
; \
else
{ \
TYPE
=
OUTRANGE
; \
OUT_ACTION
; \
} \
} \
}
while
(
0
)
/* use this instead empty macro arguments to work around NeXT cpp bug */
/* if this fails on any system, we might use ((void)0) */
#define
NOOP
/* */
/* check range and take logs of min and max if logscale
* this also restores min and max for ranges like [10:-10]
*/
#ifdef
HAVE_STRINGIZE
# define
LOG_MSG
(
x
) #x " range must be greater than 0 for log scale!"
#else
# define
LOG_MSG
(
x
) "x range must be greater than 0 for log scale!"
#endif
#define
FIXUP_RANGE_FOR_LOG
(
AXIS
,
WHICH
) \
do { \
if (reverse_range[AXIS]) { \
double temp = min_array[AXIS]; \
min_array[AXIS] = max_array[AXIS]; \
max_array[AXIS] = temp; \
} \
if (log_array[AXIS]) { \
if (min_array[AXIS] <= 0.0 || max_array[AXIS] <= 0.0) \
int_error(NO_CARET, LOG_MSG(WHICH)); \
min_array[AXIS] = log(min_array[AXIS])/log_base_array[AXIS]; \
max_array[AXIS] = log(max_array[AXIS])/log_base_array[AXIS]; \
} \
} while(0)
/*
* In the parametric case we can say plot [a= -4:4] [-2:2] [-1:1] sin(a),a**2
* while in the non-parametric case we would say only plot [b= -2:2] [-1:1]
* sin(b)
*/
void
plotrequest
()
{
int
dummy_token
=
-1
;
if
(!
term
)
/* unknown */
int_error
(
c_token
,
"use 'set term' to set terminal type first"
);
is_3d_plot
=
FALSE;
if
(
parametric
&&
strcmp
(
dummy_var
[
0
],
"u"
)
==
0
)
strcpy
(
dummy_var
[
0
],
"t"
);
/* initialise the arrays from the 'set' scalars */
INIT_ARRAYS
(
FIRST_X_AXIS
,
xmin
,
xmax
,
autoscale_x
,
is_log_x
,
base_log_x
,
log_base_log_x
,
0
);
INIT_ARRAYS
(
FIRST_Y_AXIS
,
ymin
,
ymax
,
autoscale_y
,
is_log_y
,
base_log_y
,
log_base_log_y
,
1
);
INIT_ARRAYS
(
SECOND_X_AXIS
,
x2min
,
x2max
,
autoscale_x2
,
is_log_x2
,
base_log_x2
,
log_base_log_x2
,
0
);
INIT_ARRAYS
(
SECOND_Y_AXIS
,
y2min
,
y2max
,
autoscale_y2
,
is_log_y2
,
base_log_y2
,
log_base_log_y2
,
1
);
min_array
[
T_AXIS
]
=
tmin
;
max_array
[
T_AXIS
]
=
tmax
;
if
(
equals
(
c_token
,
"["
)) {
c_token
++
;
if
(
isletter
(
c_token
)) {
if
(
equals
(
c_token
+
1
,
"="
)) {
dummy_token
=
c_token
;
c_token
+=
2
;
}
else
{
/* oops; probably an expression with a variable. */
/* Parse it as an xmin expression. */
/* used to be: int_error("'=' expected",c_token); */
}
} {
int
axis
=
(
parametric
||
polar
) ?
T_AXIS
:
FIRST_X_AXIS
;
auto_array
[
axis
]
=
load_range
(
axis
,
&
min_array
[
axis
],
&
max_array
[
axis
],
auto_array
[
axis
]);
if
(!
equals
(
c_token
,
"]"
))
int_error
(
c_token
,
"']' expected"
);
c_token
++
;
}
/* end of scope of 'axis' */
}
/* first '[' */
if
(
parametric
||
polar
)
/* set optional x ranges */
LOAD_RANGE
(
FIRST_X_AXIS
);
/* order of x range does matter, even if we're in parametric mode */
CHECK_REVERSE
(
FIRST_X_AXIS
);
LOAD_RANGE
(
FIRST_Y_AXIS
);
CHECK_REVERSE
(
FIRST_Y_AXIS
);
LOAD_RANGE
(
SECOND_X_AXIS
);
CHECK_REVERSE
(
SECOND_X_AXIS
);
LOAD_RANGE
(
SECOND_Y_AXIS
);
CHECK_REVERSE
(
SECOND_Y_AXIS
);
/* use the default dummy variable unless changed */
if
(
dummy_token
>=
0
)
copy_str
(
c_dummy_var
[
0
],
dummy_token
,
MAX_ID_LEN
);
else
(
void
)
strcpy
(
c_dummy_var
[
0
],
dummy_var
[
0
]);
eval_plots
();
}
/* Use up to 7 columns in data file at once -- originally it was 5 */
#define
NCOL
7
/* A quick note about boxes style. For boxwidth auto, we cannot
* calculate widths yet, since it may be sorted, etc. But if
* width is set, we must do it now, before logs of xmin/xmax
* are taken.
* We store -1 in point->z as a marker to mean width needs to be
* calculated, or 0 to mean that xmin/xmax are set correctly
*/
static
int
get_data
(
current_plot
)
struct
curve_points
*
current_plot
;
/* current_plot->token is after datafile spec, for error reporting
* it will later be moved passed title/with/linetype/pointtype
*/
{
int
i
/* num. points ! */
,
j
;
int
max_cols
,
min_cols
;
/* allowed range of column numbers */
double
v
[
NCOL
];
int
storetoken
=
current_plot
->
token
;
/* eval_plots has already opened file */
switch
(
current_plot
->
plot_style
) {
/* set maximum columns to scan */
case
XYERRORLINES
:
case
XYERRORBARS
:
case
BOXXYERROR
:
min_cols
=
4
;
max_cols
=
7
;
break
;
case
FINANCEBARS
:
case
CANDLESTICKS
:
min_cols
=
max_cols
=
5
;
break
;
case
BOXERROR
:
min_cols
=
4
;
max_cols
=
5
;
break
;
case
VECTOR
:
min_cols
=
max_cols
=
4
;
break
;
case
XERRORLINES
:
case
YERRORLINES
:
case
XERRORBARS
:
case
YERRORBARS
:
min_cols
=
3
;
max_cols
=
4
;
break
;
case
BOXES
:
min_cols
=
2
;
max_cols
=
4
;
break
;
default
:
min_cols
=
1
;
max_cols
=
2
;
break
;
}
if
(
current_plot
->
plot_smooth
==
SMOOTH_ACSPLINES
)
max_cols
=
3
;
if
(
df_no_use_specs
>
max_cols
)
int_error
(
NO_CARET
,
"Too many using specs for this style"
);
if
(
df_no_use_specs
>
0
&&
df_no_use_specs
<
min_cols
)
int_error
(
NO_CARET
,
"Not enough columns for this style"
);
i
=
0
;
while
((
j
=
df_readline
(
v
,
max_cols
))
!=
DF_EOF
) {
/* j <= max_cols */
if
(
i
>=
current_plot
->
p_max
) {
/*
* overflow about to occur. Extend size of points[] array. We
* either double the size, or add 1000 points, whichever is a
* smaller increment. Note i = p_max.
*/
cp_extend
(
current_plot
,
i
+
(
i
<
1000
?
i
:
1000
));
}
/* Limitation: No xerrorbars with boxes */
switch
(
j
) {
default
:
{
df_close
();
int_error
(
c_token
,
"internal error : df_readline returned %d : datafile line %d"
,
j
,
df_line_number
);
}
case
DF_UNDEFINED
:
/* bad result from extended using expression */
current_plot
->
points
[
i
].
type
=
UNDEFINED
;
i
++
;
continue
;
case
DF_FIRST_BLANK
:
/* break in data, make next point undefined */
current_plot
->
points
[
i
].
type
=
UNDEFINED
;
i
++
;
continue
;
case
DF_SECOND_BLANK
:
/* second blank line. We dont do anything
* (we did everything when we got FIRST one)
*/
continue
;
case
0
:
/* not blank line, but df_readline couldn't parse it */
{
df_close
();
int_error
(
current_plot
->
token
,
"Bad data on line %d"
,
df_line_number
);
}
case
1
:
{
/* only one number */
/* x is index, assign number to y */
v
[
1
]
=
v
[
0
];
v
[
0
]
=
df_datum
;
/* nobreak */
}
case
2
:
/* x, y */
/* ylow and yhigh are same as y */
if
(
current_plot
->
plot_style
==
BOXES
&&
boxwidth
>
0
) {
/* calc width now */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
]
-
boxwidth
/
2
,
v
[
0
]
+
boxwidth
/
2
,
v
[
1
],
v
[
1
],
0.0
);
}
else
{
/* xlow and xhigh are same as x */
/* auto width if boxes, else ignored */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
],
v
[
1
],
v
[
1
],
-1.0
);
}
break
;
case
3
:
/* x, y, ydelta OR x, y, xdelta OR x, y, width */
if
(
current_plot
->
plot_smooth
==
SMOOTH_ACSPLINES
)
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
],
v
[
1
],
v
[
1
],
v
[
2
]);
else
switch
(
current_plot
->
plot_style
) {
default
:
int_warn
(
storetoken
,
"This plot style not work with 3 cols. Setting to yerrorbars"
);
current_plot
->
plot_style
=
YERRORBARS
;
/* fall through */
case
YERRORLINES
:
case
YERRORBARS
:
case
BOXERROR
:
/* x, y, dy */
/* auto width if boxes, else ignored */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
],
v
[
1
]
-
v
[
2
],
v
[
1
]
+
v
[
2
],
-1.0
);
break
;
case
XERRORLINES
:
case
XERRORBARS
:
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
]
-
v
[
2
],
v
[
0
]
+
v
[
2
],
v
[
1
],
v
[
1
],
0.0
);
break
;
case
BOXES
:
/* calculate xmin and xmax here, so that logs are taken if
* if necessary
*/
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
]
-
v
[
2
] /
2
,
v
[
0
]
+
v
[
2
] /
2
,
v
[
1
],
v
[
1
],
0.0
);
break
;
}
/*inner switch */
break
;
case
4
:
/* x, y, ylow, yhigh OR
* x, y, xlow, xhigh OR
* x, y, xdelta, ydelta OR
* x, y, ydelta, width
*/
switch
(
current_plot
->
plot_style
) {
default
:
int_warn
(
storetoken
,
"This plot style does not work with 4 cols. Setting to yerrorbars"
);
current_plot
->
plot_style
=
YERRORBARS
;
/* fall through */
case
YERRORLINES
:
case
YERRORBARS
:
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
],
v
[
2
],
v
[
3
],
-1.0
);
break
;
case
BOXXYERROR
:
/* x, y, dx, dy */
case
XYERRORLINES
:
case
XYERRORBARS
:
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
]
-
v
[
2
],
v
[
0
]
+
v
[
2
],
v
[
1
]
-
v
[
3
],
v
[
1
]
+
v
[
3
],
0.0
);
break
;
case
BOXES
:
/* x, y, xmin, xmax */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
v
[
1
],
v
[
1
],
0.0
);
break
;
case
XERRORLINES
:
case
XERRORBARS
:
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
v
[
1
],
v
[
1
],
0.0
);
break
;
case
BOXERROR
:
/* x,y, xleft, xright */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
],
v
[
1
]
-
v
[
2
],
v
[
1
]
+
v
[
2
],
0.0
);
break
;
case
VECTOR
:
/* x,y,dx,dy */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
]
+
v
[
2
],
v
[
1
],
v
[
1
]
+
v
[
3
],
-1.0
);
break
;
}
/*inner switch */
break
;
case
5
:
{
/* x, y, ylow, yhigh, width or x open low high close */
switch
(
current_plot
->
plot_style
) {
default
:
int_warn
(
storetoken
,
"Five col. plot style must be boxerrorbars, financebars or candlesticks. Setting to boxerrorbars"
);
current_plot
->
plot_style
=
BOXERROR
;
/*fall through */
case
BOXERROR
:
/* x, y, ylow, yhigh, width */
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
]
-
v
[
4
] /
2
,
v
[
0
]
+
v
[
4
] /
2
,
v
[
2
],
v
[
3
],
0.0
);
break
;
case
FINANCEBARS
:
case
CANDLESTICKS
:
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
0
],
v
[
0
],
v
[
2
],
v
[
3
],
v
[
4
]);
break
;
}
break
;
}
case
7
:
/* same as six columns. Width ignored */
/* eh ? - fall through */
case
6
:
/* x, y, xlow, xhigh, ylow, yhigh */
switch
(
current_plot
->
plot_style
) {
default
:
int_warn
(
storetoken
,
"This plot style not work with 6 cols. Setting to xyerrorbars"
);
current_plot
->
plot_style
=
XYERRORBARS
;
/*fall through */
case
XYERRORLINES
:
case
XYERRORBARS
:
case
BOXXYERROR
:
store2d_point
(
current_plot
,
i
++
,
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
v
[
4
],
v
[
5
],
0.0
);
break
;
}
}
/*switch */
}
/*while */
current_plot
->
p_count
=
i
;
cp_extend
(
current_plot
,
i
);
/* shrink to fit */
df_close
();
return
i
;
/* i==0 indicates an 'empty' file */
}
/* called by get_data for each point */
static
void
store2d_point
(
current_plot
,
i
,
x
,
y
,
xlow
,
xhigh
,
ylow
,
yhigh
,
width
)
struct
curve_points
*
current_plot
;
int
i
;
/* point number */
double
x
,
y
;
double
ylow
,
yhigh
;
double
xlow
,
xhigh
;
double
width
;
/* -1 means autocalc, 0 means use xmin/xmax */
{
struct
coordinate
GPHUGE
*
cp
=
&
(
current_plot
->
points
[
i
]);
int
dummy_type
=
INRANGE
;
/* sometimes we dont care about outranging */
/* jev -- pass data values thru user-defined function */
/* div -- y is dummy variable 2 - copy value there */
if
(
ydata_func
.
at
) {
struct
value
val
;
(
void
)
Gcomplex
(
&
ydata_func
.
dummy_values
[
0
],
y
,
0.0
);
ydata_func
.
dummy_values
[
2
]
=
ydata_func
.
dummy_values
[
0
];
evaluate_at
(
ydata_func
.
at
,
&
val
);
y
=
undefined
?
0.0
:
real
(
&
val
);
(
void
)
Gcomplex
(
&
ydata_func
.
dummy_values
[
0
],
ylow
,
0.0
);
ydata_func
.
dummy_values
[
2
]
=
ydata_func
.
dummy_values
[
0
];
evaluate_at
(
ydata_func
.
at
,
&
val
);
ylow
=
undefined
?
0
:
real
(
&
val
);
(
void
)
Gcomplex
(
&
ydata_func
.
dummy_values
[
0
],
yhigh
,
0.0
);
ydata_func
.
dummy_values
[
2
]
=
ydata_func
.
dummy_values
[
0
];
evaluate_at
(
ydata_func
.
at
,
&
val
);
yhigh
=
undefined
?
0
:
real
(
&
val
);
}
dummy_type
=
cp
->
type
=
INRANGE
;
if
(
polar
) {
double
newx
,
newy
;
if
(!(
autoscale_r
&
2
)
&&
y
>
rmax
) {
cp
->
type
=
OUTRANGE
;
}
if
(!(
autoscale_r
&
1
)) {
/* we store internally as if plotting r(t)-rmin */
y
-=
rmin
;
}
newx
=
y
*
cos
(
x
*
ang2rad
);
newy
=
y
*
sin
(
x
*
ang2rad
);
#if
0
/* HBB 981118: added polar errorbars */
/* only lines and points supported with polar */
y
=
ylow
=
yhigh
=
newy
;
x
=
xlow
=
xhigh
=
newx
;
#else
y
=
newy
;
x
=
newx
;
if
(!(
autoscale_r
&
2
)
&&
yhigh
>
rmax
) {
cp
->
type
=
OUTRANGE
;
}
if
(!(
autoscale_r
&
1
)) {
/* we store internally as if plotting r(t)-rmin */
yhigh
-=
rmin
;
}
newx
=
yhigh
*
cos
(
xhigh
*
ang2rad
);
newy
=
yhigh
*
sin
(
xhigh
*
ang2rad
);
yhigh
=
newy
;
xhigh
=
newx
;
if
(!(
autoscale_r
&
2
)
&&
ylow
>
rmax
) {
cp
->
type
=
OUTRANGE
;
}
if
(!(
autoscale_r
&
1
)) {
/* we store internally as if plotting r(t)-rmin */
ylow
-=
rmin
;
}
newx
=
ylow
*
cos
(
xlow
*
ang2rad
);
newy
=
ylow
*
sin
(
xlow
*
ang2rad
);
ylow
=
newy
;
xlow
=
newx
;
#endif
}
/* return immediately if x or y are undefined
* we dont care if outrange for high/low.
* BUT if high/low undefined (ie log( < 0 ), no number is stored,
* but graphics.c doesn't know.
* explicitly store -VERYLARGE;
*/
STORE_WITH_LOG_AND_FIXUP_RANGE
(
cp
->
x
,
x
,
cp
->
type
,
current_plot
->
x_axis
,
NOOP
,
return
);
STORE_WITH_LOG_AND_FIXUP_RANGE
(
cp
->
xlow
,
xlow
,
dummy_type
,
current_plot
->
x_axis
,
NOOP
,
cp
->
xlow
=
-
VERYLARGE
);
STORE_WITH_LOG_AND_FIXUP_RANGE
(
cp
->
xhigh
,
xhigh
,
dummy_type
,
current_plot
->
x_axis
,
NOOP
,
cp
->
xhigh
=
-
VERYLARGE
);
STORE_WITH_LOG_AND_FIXUP_RANGE
(
cp
->
y
,
y
,
cp
->
type
,
current_plot
->
y_axis
,
NOOP
,
return
);
STORE_WITH_LOG_AND_FIXUP_RANGE
(
cp
->
ylow
,
ylow
,
dummy_type
,
current_plot
->
y_axis
,
NOOP
,
cp
->
ylow
=
-
VERYLARGE
);
STORE_WITH_LOG_AND_FIXUP_RANGE
(
cp
->
yhigh
,
yhigh
,
dummy_type
,
current_plot
->
y_axis
,
NOOP
,
cp
->
yhigh
=
-
VERYLARGE
);
cp
->
z
=
width
;
}
/* store2d_point */
/*
* print_points: a debugging routine to print out the points of a curve, and
* the curve structure. If curve<0, then we print the list of curves.
*/
#if
0
/* not used */
static
char
*
plot_type_names
[
4
]
=
{
"Function"
,
"Data"
,
"3D Function"
,
"3d data"
};
static
char
*
plot_style_names
[
14
]
=
{
"Lines"
,
"Points"
,
"Impulses"
,
"LinesPoints"
,
"Dots"
,
"XErrorbars"
,
"YErrorbars"
,
"XYErrorbars"
,
"BoxXYError"
,
"Boxes"
,
"Boxerror"
,
"Steps"
,
"FSteps"
,
"Vector"
,
"XErrorlines"
,
"YErrorlines"
,
"XYErrorlines"
};
static
char
*
plot_smooth_names
[
5
]
=
{
"None"
,
"Unique"
,
"CSplines"
,
"ACSplines"
,
"Bezier"
,
"SBezier"
};
static
void
print_points
(
curve
)
int
curve
;
/* which curve to print */
{
register
struct
curve_points
*
this_plot
;
int
i
;
if
(
curve
<
0
) {
for
(
this_plot
=
first_plot
,
i
=
0
;
this_plot
!=
NULL
;
i
++
,
this_plot
=
this_plot
->
next
) {
printf
(
"Curve %d:\n"
,
i
);
if
((
int
)
this_plot
->
plot_type
>=
0
&&
(
int
) (
this_plot
->
plot_type
)
<
4
)
printf
(
"Plot type %d: %s\n"
, (
int
) (
this_plot
->
plot_type
),
plot_type_names
[(
int
) (
this_plot
->
plot_type
)]);
else
printf
(
"Plot type %d: BAD\n"
, (
int
) (
this_plot
->
plot_type
));
if
((
int
)
this_plot
->
plot_style
>=
0
&&
(
int
) (
this_plot
->
plot_style
)
<
14
)
printf
(
"Plot style %d: %s\n"
, (
int
) (
this_plot
->
plot_style
),
plot_style_names
[(
int
) (
this_plot
->
plot_style
)]);
else
printf
(
"Plot style %d: BAD\n"
, (
int
) (
this_plot
->
plot_style
));
if
((
int
)
this_plot
->
plot_smooth
>=
0
&&
(
int
) (
this_plot
->
plot_smooth
)
<
6
)
printf
(
"Plot smooth style %d: %s\n"
, (
int
) (
this_plot
->
plot_style
),
plot_smooth_names
[(
int
) (
this_plot
->
plot_smooth
)]);
else
printf
(
"Plot smooth style %d: BAD\n"
, (
int
) (
this_plot
->
plot_smooth
));
printf
(
"\
Plot title: '%s'\n\
Line type %d\n\
Point type %d\n\
max points %d\n\
current points %d\n\n"
,
this_plot
->
title
,
this_plot
->
line_type
,
this_plot
->
point_type
,
this_plot
->
p_max
,
this_plot
->
p_count
);
}
}
else
{
for
(
this_plot
=
first_plot
,
i
=
0
;
i
<
curve
&&
this_plot
!=
NULL
;
i
++
,
this_plot
=
this_plot
->
next
);
if
(
this_plot
==
NULL
)
printf
(
"Curve %d does not exist; list has %d curves\n"
,
curve
,
i
);
else
{
printf
(
"Curve %d, %d points\n"
,
curve
,
this_plot
->
p_count
);
for
(
i
=
0
;
i
<
this_plot
->
p_count
;
i
++
) {
printf
(
"%c x=%g y=%g z=%g xlow=%g xhigh=%g ylow=%g yhigh=%g\n"
,
this_plot
->
points
[
i
].
type
==
INRANGE
?
'i'
:
this_plot
->
points
[
i
].
type
==
OUTRANGE
?
'o'
:
'u'
,
this_plot
->
points
[
i
].
x
,
this_plot
->
points
[
i
].
y
,
this_plot
->
points
[
i
].
z
,
this_plot
->
points
[
i
].
xlow
,
this_plot
->
points
[
i
].
xhigh
,
this_plot
->
points
[
i
].
ylow
,
this_plot
->
points
[
i
].
yhigh
);
}
printf
(
"\n"
);
}
}
}
#endif
/* not used */
static
void
print_table
(
current_plot
,
plot_num
)
struct
curve_points
*
current_plot
;
int
plot_num
;
{
int
i
,
curve
;
char
*
table_format
=
NULL
;
/* The data format is determined by the format of the axis labels.
* See 'set format'. Patch by Don Taber
*/
table_format
=
gp_alloc
(
strlen
(
xformat
)
+
strlen
(
yformat
)
+
5
,
"table format"
);
strcpy
(
table_format
,
xformat
);
strcat
(
table_format
,
" "
);
strcat
(
table_format
,
yformat
);
strcat
(
table_format
,
" %c\n"
);
for
(
curve
=
0
;
curve
<
plot_num
;
curve
++
,
current_plot
=
current_plot
->
next
) {
fprintf
(
gpoutfile
,
"#Curve %d, %d points\n#x y"
,
curve
,
current_plot
->
p_count
);
switch
(
current_plot
->
plot_style
) {
case
BOXES
:
case
XERRORBARS
:
fprintf
(
gpoutfile
,
" xlow xhigh"
);
break
;
case
BOXERROR
:
case
YERRORBARS
:
fprintf
(
gpoutfile
,
" ylow yhigh"
);
break
;
case
BOXXYERROR
:
case
XYERRORBARS
:
fprintf
(
gpoutfile
,
" xlow xhigh ylow yhigh"
);
break
;
case
FINANCEBARS
:
case
CANDLESTICKS
:
default
:
/* ? */
break
;
}
fprintf
(
gpoutfile
,
" type\n"
);
for
(
i
=
0
;
i
<
current_plot
->
p_count
;
i
++
) {
fprintf
(
gpoutfile
,
"%g %g"
,
current_plot
->
points
[
i
].
x
,
current_plot
->
points
[
i
].
y
);
switch
(
current_plot
->
plot_style
) {
case
BOXES
:
case
XERRORBARS
:
fprintf
(
gpoutfile
,
" %g %g"
,
current_plot
->
points
[
i
].
xlow
,
current_plot
->
points
[
i
].
xhigh
);
break
;
case
BOXERROR
:
case
YERRORBARS
:
fprintf
(
gpoutfile
,
" %g %g"
,
current_plot
->
points
[
i
].
ylow
,
current_plot
->
points
[
i
].
yhigh
);
break
;
case
BOXXYERROR
:
case
XYERRORBARS
:
fprintf
(
gpoutfile
,
" %g %g %g %g"
,
current_plot
->
points
[
i
].
xlow
,
current_plot
->
points
[
i
].
xhigh
,
current_plot
->
points
[
i
].
ylow
,
current_plot
->
points
[
i
].
yhigh
);
break
;
case
FINANCEBARS
:
case
CANDLESTICKS
:
default
:
/* ? */
break
;
}
fprintf
(
gpoutfile
,
" %c\n"
,
current_plot
->
points
[
i
].
type
==
INRANGE
?
'i'
:
current_plot
->
points
[
i
].
type
==
OUTRANGE
?
'o'
:
'u'
);
}
fputc
(
'\n'
,
gpoutfile
);
}
/* two blank lines between plots in table output */
fputc
(
'\n'
,
gpoutfile
);
fflush
(
gpoutfile
);
free
(
table_format
);
}
/*
* This parses the plot command after any range specifications. To support
* autoscaling on the x axis, we want any data files to define the x range,
* then to plot any functions using that range. We thus parse the input
* twice, once to pick up the data files, and again to pick up the functions.
* Definitions are processed twice, but that won't hurt.
* div - okay, it doesn't hurt, but every time an option as added for
* datafiles, code to parse it has to be added here. Change so that
* we store starting-token in the plot structure.
*/
static
void
eval_plots
()
{
register
int
i
;
register
struct
curve_points
*
this_plot
,
*
*
tp_ptr
;
int
some_functions
=
0
;
int
plot_num
,
line_num
,
point_num
,
xparam
=
0
;
char
*
xtitle
=
NULL
;
int
begin_token
=
c_token
;
/* so we can rewind for second pass */
int
uses_axis
[
AXIS_ARRAY_SIZE
];
uses_axis
[
FIRST_X_AXIS
]
=
uses_axis
[
FIRST_Y_AXIS
]
=
uses_axis
[
SECOND_X_AXIS
]
=
uses_axis
[
SECOND_Y_AXIS
]
=
0
;
/* Reset first_plot. This is usually done at the end of this function.
* If there is an error within this function, the memory is left allocated,
* since we cannot call cp_free if the list is incomplete. Making sure that
* the list structure is always vaild requires some rewriting */
first_plot
=
NULL
;
tp_ptr
=
&
(
first_plot
);
plot_num
=
0
;
line_num
=
0
;
/* default line type */
point_num
=
0
;
/* default point type */
/*** First Pass: Read through data files ***
* This pass serves to set the xrange and to parse the command, as well
* as filling in every thing except the function data. That is done after
* the xrange is defined.
*/
while
(TRUE) {
if
(
END_OF_COMMAND
)
int_error
(
c_token
,
"function to plot expected"
);
if
(
is_definition
(
c_token
)) {
define
();
}
else
{
int
x_axis
=
0
,
y_axis
=
0
;
int
specs
=
0
;
/* for datafile plot, record datafile spec for title */
int
start_token
=
c_token
,
end_token
;
plot_num
++
;
if
(
isstring
(
c_token
)) {
/* data file to plot */
if
(
parametric
&&
xparam
)
int_error
(
c_token
,
"previous parametric function not fully specified"
);
if
(
*
tp_ptr
)
this_plot
=
*
tp_ptr
;
else
{
/* no memory malloc()'d there yet */
this_plot
=
cp_alloc
(
MIN_CRV_POINTS
);
*
tp_ptr
=
this_plot
;
}
this_plot
->
plot_type
=
DATA
;
this_plot
->
plot_style
=
data_style
;
this_plot
->
plot_smooth
=
SMOOTH_NONE
;
specs
=
df_open
(
NCOL
);
/* up to NCOL cols */
/* this parses data-file-specific modifiers only */
/* we'll sort points when we know style, if necessary */
if
(
df_binary
)
int_error
(
c_token
,
"2d binary files not yet supported"
);
/* include modifiers in default title */
this_plot
->
token
=
end_token
=
c_token
-
1
;
}
else
{
/* function to plot */
some_functions
=
1
;
if
(
parametric
)
/* working on x parametric function */
xparam
=
1
-
xparam
;
if
(
*
tp_ptr
) {
this_plot
=
*
tp_ptr
;
cp_extend
(
this_plot
,
samples
+
1
);
}
else
{
/* no memory malloc()'d there yet */
this_plot
=
cp_alloc
(
samples
+
1
);
*
tp_ptr
=
this_plot
;
}
this_plot
->
plot_type
=
FUNC
;
this_plot
->
plot_style
=
func_style
;
dummy_func
=
&
plot_func
;
plot_func
.
at
=
temp_at
();
dummy_func
=
NULL
;
/* ignore it for now */
end_token
=
c_token
-
1
;
}
/* end of IS THIS A FILE OR A FUNC block */
/* axis defaults */
x_axis
=
FIRST_X_AXIS
;
y_axis
=
FIRST_Y_AXIS
;
/* deal with smooth */
if
(
almost_equals
(
c_token
,
"s$mooth"
)) {
c_token
++
;
switch
(
lookup_table
(
&
plot_smooth_tbl
[
0
],
c_token
)) {
case
SMOOTH_ACSPLINES
:
this_plot
->
plot_smooth
=
SMOOTH_ACSPLINES
;
break
;
case
SMOOTH_BEZIER
:
this_plot
->
plot_smooth
=
SMOOTH_BEZIER
;
break
;
case
SMOOTH_CSPLINES
:
this_plot
->
plot_smooth
=
SMOOTH_CSPLINES
;
break
;
case
SMOOTH_SBEZIER
:
this_plot
->
plot_smooth
=
SMOOTH_SBEZIER
;
break
;
case
SMOOTH_UNIQUE
:
this_plot
->
plot_smooth
=
SMOOTH_UNIQUE
;
break
;
case
SMOOTH_NONE
:
default
:
int_error
(
c_token
,
"expecting 'unique', 'acsplines', 'csplines', 'bezier' or 'sbezier'"
);
break
;
}
this_plot
->
plot_style
=
LINES
;
c_token
++
;
/* skip format */
}
/* look for axes/axis */
if
(
almost_equals
(
c_token
,
"ax$es"
)
||
almost_equals
(
c_token
,
"ax$is"
)) {
if
(
parametric
&&
xparam
)
int_error
(
c_token
,
"previous parametric function not fully specified"
);
c_token
++
;
switch
(
lookup_table
(
&
plot_axes_tbl
[
0
],
c_token
)) {
case
AXES_X1Y1
:
x_axis
=
FIRST_X_AXIS
;
y_axis
=
FIRST_Y_AXIS
;
++
c_token
;
break
;
case
AXES_X2Y2
:
x_axis
=
SECOND_X_AXIS
;
y_axis
=
SECOND_Y_AXIS
;
++
c_token
;
break
;
case
AXES_X1Y2
:
x_axis
=
FIRST_X_AXIS
;
y_axis
=
SECOND_Y_AXIS
;
++
c_token
;
break
;
case
AXES_X2Y1
:
x_axis
=
SECOND_X_AXIS
;
y_axis
=
FIRST_Y_AXIS
;
++
c_token
;
break
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL