-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathplot2d.c
More file actions
3650 lines (3213 loc) · 117 KB
/
plot2d.c
File metadata and controls
3650 lines (3213 loc) · 117 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef lint
static char *RCSid() { return RCSid("$Id: plot2d.c,v 1.461 2017-11-01 18:06:53 sfeam Exp $"); }
#endif
/* GNUPLOT - plot2d.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.
]*/
#include "gp_types.h"
#include "plot2d.h"
#include "alloc.h"
#include "axis.h"
#include "command.h"
#include "datafile.h"
#include "datablock.h"
#include "eval.h"
#include "fit.h"
#include "graphics.h"
#include "interpol.h"
#include "misc.h"
#include "parse.h"
#include "pm3d.h" /* for is_plot_with_palette */
#include "setshow.h"
#include "tables.h"
#include "tabulate.h"
#include "term_api.h"
#include "util.h"
#include "variable.h" /* For locale handling */
#ifndef _WIN32
# include "help.h"
#endif
/* minimum size of points[] in curve_points */
#define MIN_CRV_POINTS 100
/* static prototypes */
static struct curve_points * cp_alloc __PROTO((int num));
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 eval_plots __PROTO((void));
static void parametric_fixup __PROTO((struct curve_points * start_plot, int *plot_num));
static void box_range_fiddling __PROTO((struct curve_points *plot));
static void boxplot_range_fiddling __PROTO((struct curve_points *plot));
static void histogram_range_fiddling __PROTO((struct curve_points *plot));
static void impulse_range_fiddling __PROTO((struct curve_points *plot));
static int check_or_add_boxplot_factor __PROTO((struct curve_points *plot, char* string, double x));
static void add_tics_boxplot_factors __PROTO((struct curve_points *plot));
/* internal and external variables */
/* the curves/surfaces of the plot */
struct curve_points *first_plot = NULL;
static struct udft_entry plot_func;
/* box width (automatic) */
double boxwidth = -1.0;
/* whether box width is absolute (default) or relative */
TBOOLEAN boxwidth_is_absolute = TRUE;
static double histogram_rightmost = 0.0; /* Highest x-coord of histogram so far */
static text_label histogram_title; /* Subtitle for this histogram */
static int stack_count = 0; /* counter for stackheight */
static struct coordinate GPHUGE *stackheight = NULL; /* Scratch space for y autoscale */
/* function implementations */
/*
* cp_alloc() allocates a curve_points structure that can hold 'num'
* points. Initialize all fields to NULL.
*/
static struct curve_points *
cp_alloc(int num)
{
struct curve_points *cp;
struct lp_style_type default_lp_properties = DEFAULT_LP_STYLE_TYPE;
cp = (struct curve_points *) gp_alloc(sizeof(struct curve_points), "curve");
memset(cp,0,sizeof(struct curve_points));
cp->p_max = (num >= 0 ? num : 0);
if (num > 0)
cp->points = (struct coordinate GPHUGE *)
gp_alloc(num * sizeof(struct coordinate), "curve points");
/* Initialize various fields */
cp->lp_properties = default_lp_properties;
default_arrow_style(&(cp->arrow_properties));
cp->fill_properties = default_fillstyle;
cp->filledcurves_options = filledcurves_opts_data;
return (cp);
}
/*
* cp_extend() reallocates a curve_points structure to hold "num"
* points. This will either expand or shrink the storage.
*/
void
cp_extend(struct curve_points *cp, int num)
{
if (num == cp->p_max)
return;
if (num > 0) {
if (cp->points == NULL) {
cp->points = gp_alloc(num * sizeof(cp->points[0]),
"curve points");
} else {
cp->points = gp_realloc(cp->points, num * sizeof(cp->points[0]),
"expanding curve points");
if (cp->varcolor)
cp->varcolor = gp_realloc(cp->varcolor, num * sizeof(double),
"expanding curve variable colors");
if (cp->z_n) {
int i;
for (i = 0; i < cp->n_par_axes; i++)
cp->z_n[i] = gp_realloc(cp->z_n[i], num * sizeof(double),
"expanding curve z_n[i]");
}
}
cp->p_max = num;
cp->p_max -= 1; /* Set trigger point for reallocation ahead of */
/* true end in case two slots are used at once */
/* (e.g. redundant final point of closed curve) */
} else {
free(cp->points);
cp->points = NULL;
cp->p_max = 0;
free(cp->varcolor);
cp->varcolor = NULL;
if (cp->z_n) {
int i;
for (i = 0; i < cp->n_par_axes; i++)
free(cp->z_n[i]);
free(cp->z_n);
cp->n_par_axes = 0;
cp->z_n = NULL;
}
}
}
/*
* cp_free() releases any memory which was previously malloc()'d to hold
* curve points (and recursively down the linked list).
*/
void
cp_free(struct curve_points *cp)
{
while (cp) {
struct curve_points *next = cp->next;
free(cp->title);
cp->title = NULL;
free(cp->title_position);
cp->title_position = NULL;
free(cp->points);
cp->points = NULL;
free(cp->varcolor);
cp->varcolor = NULL;
if (cp->labels)
free_labels(cp->labels);
cp->labels = NULL;
if (cp->z_n) {
int i;
for (i = 0; i < cp->n_par_axes; i++)
free(cp->z_n[i]);
free(cp->z_n);
cp->n_par_axes = 0;
cp->z_n = NULL;
}
free(cp);
cp = next;
}
}
/*
* 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 = 0;
AXIS_INDEX axis;
if (!term) /* unknown */
int_error(c_token, "use 'set term' to set terminal type first");
is_3d_plot = FALSE;
/* Deactivate if 'set view map' is still running after the previous 'splot': */
/* EAM Jan 2012 - this should no longer be necessary, but it doesn't hurt. */
splot_map_deactivate();
if (parametric && strcmp(set_dummy_var[0], "u") == 0)
strcpy(set_dummy_var[0], "t");
/* initialise the arrays from the 'set' scalars */
AXIS_INIT2D(FIRST_X_AXIS, 0);
AXIS_INIT2D(FIRST_Y_AXIS, 1);
AXIS_INIT2D(SECOND_X_AXIS, 0);
AXIS_INIT2D(SECOND_Y_AXIS, 1);
AXIS_INIT2D(T_AXIS, 0);
AXIS_INIT2D(U_AXIS, 0);
AXIS_INIT2D(V_AXIS, 0);
AXIS_INIT2D(POLAR_AXIS, 1);
AXIS_INIT2D(COLOR_AXIS, 1);
/* Nonlinear mapping of x or y via linkage to a hidden primary axis. */
/* The user set autoscale for the visible axis; apply it also to the hidden axis. */
for (axis = 0; axis < NUMBER_OF_MAIN_VISIBLE_AXES; axis++) {
AXIS *secondary = &axis_array[axis];
if (axis == SAMPLE_AXIS)
continue;
if (secondary->linked_to_primary
&& secondary->linked_to_primary->index == -secondary->index) {
AXIS *primary = secondary->linked_to_primary;
primary->set_autoscale = secondary->set_autoscale;
axis_init(primary, 1);
}
}
/* If we are called from a mouse zoom operation we should ignore */
/* any range limits because otherwise the zoom won't zoom. */
if (inside_zoom) {
while (equals(c_token,"["))
parse_skip_range();
}
/* Range limits for the entire plot are optional but must be given */
/* in a fixed order. The keyword 'sample' terminates range parsing. */
if (parametric || polar) {
dummy_token = parse_range(T_AXIS);
parse_range(FIRST_X_AXIS);
} else {
dummy_token = parse_range(FIRST_X_AXIS);
}
parse_range(FIRST_Y_AXIS);
parse_range(SECOND_X_AXIS);
parse_range(SECOND_Y_AXIS);
if (equals(c_token,"sample") && equals(c_token+1,"["))
c_token++;
/* Clear out any tick labels read from data files in previous plot */
for (axis=0; axis<AXIS_ARRAY_SIZE; axis++) {
struct ticdef *ticdef = &axis_array[axis].ticdef;
if (ticdef->def.user)
ticdef->def.user = prune_dataticks(ticdef->def.user);
if (!ticdef->def.user && ticdef->type == TIC_USER)
ticdef->type = TIC_COMPUTED;
}
/* use the default dummy variable unless changed */
if (dummy_token > 0)
copy_str(c_dummy_var[0], dummy_token, MAX_ID_LEN);
else
strcpy(c_dummy_var[0], set_dummy_var[0]);
eval_plots();
}
/* Helper function for refresh command. Reexamine each data point and update the
* flags for INRANGE/OUTRANGE/UNDEFINED based on the current limits for that axis.
* Normally the axis limits are already known at this point. But if the user has
* forced "set autoscale" since the previous plot or refresh, we need to reset the
* axis limits and try to approximate the full auto-scaling behaviour.
*/
void
refresh_bounds(struct curve_points *first_plot, int nplots)
{
struct curve_points *this_plot = first_plot;
int iplot; /* plot index */
for (iplot = 0; iplot < nplots; iplot++, this_plot = this_plot->next) {
int i; /* point index */
struct axis *x_axis = &axis_array[this_plot->x_axis];
struct axis *y_axis = &axis_array[this_plot->y_axis];
/* IMAGE clipping is done elsewhere, so we don't need INRANGE/OUTRANGE checks */
if (this_plot->plot_style == IMAGE || this_plot->plot_style == RGBIMAGE) {
if (x_axis->set_autoscale || y_axis->set_autoscale)
process_image(this_plot, IMG_UPDATE_AXES);
continue;
}
/* FIXME: I don't think this test does what the comment says. */
/*
* If the state has been set to autoscale since the last plot,
* mark everything INRANGE and re-evaluate the axis limits now.
* Otherwise test INRANGE/OUTRANGE against previous data limits.
*/
if (!this_plot->noautoscale) {
if (x_axis->set_autoscale & AUTOSCALE_MIN && x_axis->data_min < x_axis->min)
x_axis->min = x_axis->data_min;
if (x_axis->set_autoscale & AUTOSCALE_MAX && x_axis->data_max > x_axis->max)
x_axis->max = x_axis->data_max;
}
for (i=0; i<this_plot->p_count; i++) {
struct coordinate GPHUGE *point = &this_plot->points[i];
if (point->type == UNDEFINED)
continue;
else
point->type = INRANGE;
/* This autoscaling logic is identical to that in
* refresh_3dbounds() in plot3d.c
*/
if (!this_plot->noautoscale) {
autoscale_one_point(x_axis, point->x);
if (this_plot->plot_style == VECTOR)
autoscale_one_point(x_axis, point->xhigh);
}
if (!inrange(point->x, x_axis->min, x_axis->max)) {
point->type = OUTRANGE;
continue;
}
if (!this_plot->noautoscale) {
autoscale_one_point(y_axis, point->y);
if (this_plot->plot_style == VECTOR)
autoscale_one_point(y_axis, point->yhigh);
}
if (!inrange(point->y, y_axis->min, y_axis->max)) {
point->type = OUTRANGE;
continue;
}
}
if (this_plot->plot_style == BOXES || this_plot->plot_style == IMPULSES)
impulse_range_fiddling(this_plot);
}
this_plot = first_plot;
for (iplot = 0; iplot < nplots; iplot++, this_plot = this_plot->next) {
/* handle 'reverse' ranges */
axis_check_range( this_plot->x_axis );
axis_check_range( this_plot->y_axis );
/* Make sure the bounds are reasonable, and tweak them if they aren't */
axis_checked_extend_empty_range(this_plot->x_axis, NULL);
axis_checked_extend_empty_range(this_plot->y_axis, NULL);
}
}
/* 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
*/
/* current_plot->token is after datafile spec, for error reporting
* it will later be moved passed title/with/linetype/pointtype
*/
static int
get_data(struct curve_points *current_plot)
{
int i /* num. points ! */ , j;
int ngood;
int max_cols, min_cols; /* allowed range of column numbers */
int storetoken = current_plot->token;
struct coordinate GPHUGE *cp;
double v[MAXDATACOLS];
memset(v, 0, sizeof(v));
if (current_plot->varcolor == NULL) {
TBOOLEAN variable_color = FALSE;
if ((current_plot->lp_properties.pm3d_color.type == TC_RGB)
&& (current_plot->lp_properties.pm3d_color.value < 0))
variable_color = TRUE;
if (current_plot->lp_properties.pm3d_color.type == TC_Z)
variable_color = TRUE;
if (current_plot->lp_properties.l_type == LT_COLORFROMCOLUMN)
variable_color = TRUE;
if (current_plot->plot_smooth != SMOOTH_NONE) {
/* FIXME: It would be possible to support smooth cspline lc palette */
/* but it would require expanding and interpolating plot->varcolor */
/* in parallel with the y values. */
variable_color = FALSE;
}
if (variable_color)
current_plot->varcolor = gp_alloc(current_plot->p_max * sizeof(double),
"varcolor array");
if (variable_color && current_plot->plot_style == PARALLELPLOT) {
/* Oops, we reserved one column of data too many */
free(current_plot->z_n[--(current_plot->n_par_axes)]);
}
}
/* eval_plots has already opened file */
/* HBB 2000504: For most 2D plot styles the 'z' coordinate is unused.
* Set it to NO_AXIS to account for that. For styles that use
* the z coordinate as a real coordinate (i.e. not a width or
* 'delta' component, change the setting inside the switch: */
current_plot->z_axis = NO_AXIS;
/* HBB NEW 20060427: if there's only one, explicit using column,
* it's y data. df_axis[] has to reflect that, so df_readline()
* will expect time/date input. */
if (df_no_use_specs == 1)
df_axis[0] = df_axis[1];
switch (current_plot->plot_style) { /* set maximum columns to scan */
case XYERRORLINES:
case XYERRORBARS:
case BOXXYERROR:
min_cols = 4;
max_cols = 7;
if (df_no_use_specs >= 6) {
/* HBB 20060427: signal 3rd and 4th column are absolute x
* data --- needed so time/date parsing works */
df_axis[2] = df_axis[3] = df_axis[0];
/* and 5th and 6th are absolute y data */
df_axis[4] = df_axis[5] = df_axis[1];
}
break;
case FINANCEBARS:
/* HBB 20000504: use 'z' coordinate for y-axis quantity */
current_plot->z_axis = current_plot->y_axis;
min_cols = 5;
max_cols = 6;
/* HBB 20060427: signal 3rd and 4th column are absolute y data
* --- needed so time/date parsing works */
df_axis[2] = df_axis[3] = df_axis[4] = df_axis[1];
break;
case BOXPLOT:
min_cols = 2; /* fixed x, lots of y data points */
max_cols = 4; /* optional width, optional factor */
expect_string( 4 );
break;
case CANDLESTICKS:
current_plot->z_axis = current_plot->y_axis;
min_cols = 5;
max_cols = 7;
df_axis[2] = df_axis[3] = df_axis[4] = df_axis[1];
break;
case BOXERROR:
min_cols = 3;
max_cols = 6;
/* There are four possible cases: */
/* 3 cols --> (x,y,dy), auto dx */
/* 4 cols, boxwidth==-2 --> (x,y,ylow,yhigh), auto dx */
/* 4 cols, boxwidth!=-2 --> (x,y,dy,dx) */
/* 5 cols --> (x,y,ylow,yhigh,dx) */
/* In each case an additional column may hold variable color */
if ((df_no_use_specs == 4 && boxwidth == -2)
|| df_no_use_specs >= 5)
/* HBB 20060427: signal 3rd and 4th column are absolute y
* data --- needed so time/date parsing works */
df_axis[2] = df_axis[3] = df_axis[1];
break;
case VECTOR: /* x, y, dx, dy, variable color or arrow style */
min_cols = 4;
max_cols = 5;
break;
case XERRORLINES:
case XERRORBARS:
min_cols = 3;
max_cols = 5;
if (df_no_use_specs >= 4)
/* HBB 20060427: signal 3rd and 4th column are absolute x
* data --- needed so time/date parsing works */
df_axis[2] = df_axis[3] = df_axis[0];
break;
case YERRORLINES:
case YERRORBARS:
min_cols = 2;
max_cols = 5;
if (df_no_use_specs >= 4)
/* HBB 20060427: signal 3rd and 4th column are absolute y
* data --- needed so time/date parsing works */
df_axis[2] = df_axis[3] = df_axis[1];
break;
case HISTOGRAMS:
min_cols = 1;
max_cols = 3;
break;
case BOXES:
min_cols = 1;
max_cols = 4;
break;
case FILLEDCURVES:
min_cols = 1;
max_cols = 3;
df_axis[2] = df_axis[1]; /* Both curves use same y axis */
break;
case IMPULSES: /* 2 + possible variable color */
case LINES:
case DOTS:
min_cols = 1;
max_cols = 3;
break;
case LABELPOINTS:
/* 3 column data: X Y Label */
/* extra columns allow variable pointsize and/or rotation */
min_cols = 3;
max_cols = 5;
expect_string( 3 );
break;
case IMAGE:
min_cols = 3;
max_cols = 3;
break;
case RGBIMAGE:
min_cols = 5;
max_cols = 6;
break;
case RGBA_IMAGE:
min_cols = 6;
max_cols = 6;
break;
#ifdef EAM_OBJECTS
case CIRCLES: /* 3 + possible variable color, or 5 + possible variable color */
min_cols = 2;
max_cols = 6;
break;
case ELLIPSES:
min_cols = 2; /* x, y, major axis, minor axis */
max_cols = 6; /* + optional angle, possible variable color */
break;
#endif
case POINTSTYLE:
case LINESPOINTS:
/* 1 column: y coordinate only */
/* 2 columns x and y coordinates */
/* Allow 1 extra column because of 'pointsize variable' */
/* Allow 1 extra column because of 'pointtype variable' */
/* Allow 1 extra column because of 'lc rgb variable' */
min_cols = 1;
max_cols = 5;
break;
case PARALLELPLOT:
/* Maximum number of parallel axes is fixed at compile time */
if (current_plot->n_par_axes > num_parallel_axes)
extend_parallel_axis(current_plot->n_par_axes);
/* First N columns are data; one more is optional varcolor */
min_cols = current_plot->n_par_axes;
max_cols = current_plot->n_par_axes + 1;
/* We have not yet read in any data, so we cannot do complete initialization */
for (j = 0; j < current_plot->n_par_axes; j++) {
struct axis *this_axis = ¶llel_axis[j];
axis_init(this_axis, 1);
}
break;
case TABLESTYLE:
min_cols = 1;
max_cols = MAXDATACOLS;
break;
default:
min_cols = 1;
max_cols = 2;
break;
}
/* Restictions on plots with "smooth" option */
switch (current_plot->plot_smooth) {
case SMOOTH_NONE:
break;
case SMOOTH_ACSPLINES:
max_cols = 3;
current_plot->z_axis = FIRST_Z_AXIS;
df_axis[2] = FIRST_Z_AXIS;
break;
default:
if (df_no_use_specs > 2)
int_warn(NO_CARET, "extra columns ignored by smoothing option");
break;
}
/* EXPERIMENTAL May 2013 - Treating timedata columns as strings allows */
/* functions column(N) and column("HEADER") to work on time data. */
/* Sep 2014: But the column count is wrong for HISTOGRAMS */
if (current_plot->plot_style != HISTOGRAMS) {
if (axis_array[current_plot->x_axis].datatype == DT_TIMEDATE)
expect_string(1);
if (axis_array[current_plot->y_axis].datatype == DT_TIMEDATE)
expect_string(2);
}
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; ngood = 0;
/* If the user has set an explicit locale for numeric input, apply it */
/* here so that it affects data fields read from the input file. */
set_numeric_locale();
/* Initial state */
df_warn_on_missing_columnheader = TRUE;
while ((j = df_readline(v, max_cols)) != DF_EOF) {
if (i >= current_plot->p_max) {
/* overflow about to occur. Extend size of points[]
* array. Double the size, and add 1000 points, to avoid
* needlessly small steps. */
cp_extend(current_plot, i + i + 1000);
}
/* Version 5
* We are now trying to pass back all available info even if one of the requested
* columns was missing or undefined. This check replaces the DF_UNDEFINED case in
* the main switch statement below.
*/
if (j == DF_UNDEFINED) {
current_plot->points[i].type = UNDEFINED;
if (missing_val && !strcmp(missing_val, "NaN"))
j = DF_MISSING;
else
j = df_no_use_specs;
} else {
/* Assume range is OK; we will check later */
current_plot->points[i].type = INRANGE;
}
if (j > 0) {
ngood++;
/* June 2010 - New mechanism for variable color */
/* If variable color is requested, take the color value from the */
/* final column of input and decrement the column count by one. */
if (current_plot->varcolor) {
static char *errmsg = "Not enough columns for variable color";
switch (current_plot->plot_style) {
case CANDLESTICKS:
case FINANCEBARS:
if (j < 6) int_error(NO_CARET,errmsg);
break;
case XYERRORLINES:
case XYERRORBARS:
case BOXXYERROR:
if (j != 7 && j != 5) int_error(NO_CARET,errmsg);
break;
case VECTOR:
if (j < 5) int_error(NO_CARET,errmsg);
break;
case LABELPOINTS:
case BOXERROR:
case XERRORLINES:
case XERRORBARS:
case YERRORLINES:
case YERRORBARS:
if (j < 4) int_error(NO_CARET,errmsg);
break;
#ifdef EAM_OBJECTS
case CIRCLES:
if (j == 5 || j < 3) int_error(NO_CARET,errmsg);
break;
case ELLIPSES:
#endif
case BOXES:
case POINTSTYLE:
case LINESPOINTS:
case IMPULSES:
case LINES:
case DOTS:
if (j < 3) int_error(NO_CARET,errmsg);
break;
case PARALLELPLOT:
if (j < 4) int_error(NO_CARET,errmsg);
break;
case BOXPLOT:
/* Only the key sample uses this value */
v[j++] = current_plot->base_linetype + 1;
break;
default:
break;
}
current_plot->varcolor[i] = v[--j];
}
if (current_plot->plot_style == TABLESTYLE) {
/* tabulate_one_line() applies an input data filter and
* returns TRUE if the line was accepted and written out
*/
tabulate_one_line(v, df_strings, j);
continue;
}
}
/* TODO: It would make more sense to organize the switch below by plot */
/* type rather than by number of columns in use. The mis-organization */
/* is particularly evident for parallel axis plots, to the point where */
/* I decided the only reasonable option is to handle it separately. */
if (current_plot->plot_style == PARALLELPLOT && j > 0) {
int iaxis;
if (j != current_plot->n_par_axes)
int_error(NO_CARET, "Expecting %d input columns, got %d\n",
current_plot->n_par_axes, j);
/* Primary coordinate structure holds only x range and 1st y value. */
/* The x range brackets the parallel axes by 0.5 on either side. */
store2d_point(current_plot, i, 1.0, v[0],
0.5, (double)(current_plot->n_par_axes)+0.5,
v[0], v[0], 0.0);
/* The parallel axis data is stored in separate arrays */
for (iaxis = 0; iaxis < current_plot->n_par_axes; iaxis++) {
int dummy_type = INRANGE;
ACTUAL_STORE_AND_UPDATE_RANGE( current_plot->z_n[iaxis][i],
v[iaxis], dummy_type, ¶llel_axis[iaxis],
current_plot->noautoscale, NOOP );
}
i++;
} else {
/* This "else" block currently handles all plot styles other than PARALLEL_AXES */
switch (j) {
default:
{
df_close();
int_error(c_token, "internal error : df_readline returned %d : datafile line %d", j, df_line_number);
}
case DF_MISSING:
/* Plot type specific handling of missing points goes here. */
if (current_plot->plot_style == HISTOGRAMS) {
current_plot->points[i].type = UNDEFINED;
i++;
continue;
}
/* Jun 2006 - Return to behavior of 3.7 and current docs:
* do not interrupt plotted line because of missing data
*/
FPRINTF((stderr,"Missing datum %d\n", i));
continue;
case DF_UNDEFINED:
/* Version 5: can't get here because we trapped DF_UNDEFINED above */
continue;
case DF_FIRST_BLANK:
/* The binary input routines generate DF_FIRST_BLANK at the end
* of scan lines, so that the data may be used for the isometric
* splots. Rather than turning that off inside the binary
* reading routine based upon the plot mode, DF_FIRST_BLANK is
* ignored for certain plot types requiring 3D coordinates in
* MODE_PLOT.
*/
if (current_plot->plot_style == IMAGE
|| current_plot->plot_style == RGBIMAGE
|| current_plot->plot_style == RGBA_IMAGE)
continue;
/* make type of next point undefined, but recognizable */
current_plot->points[i] = blank_data_line;
i++;
continue;
case DF_SECOND_BLANK:
/* second blank line. We dont do anything
* (we did everything when we got FIRST one)
*/
continue;
case DF_FOUND_KEY_TITLE:
df_set_key_title(current_plot);
continue;
case DF_KEY_TITLE_MISSING:
fprintf(stderr,"get_data: key title not found in requested column\n");
continue;
case DF_COLUMN_HEADERS:
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 of file %s",
df_line_number, df_filename ? df_filename : "");
}
case 1:
/* only one number */
if (default_smooth_weight(current_plot->plot_smooth)) {
v[1] = 1.0;
} else {
/* x is index, assign number to y */
v[1] = v[0];
v[0] = df_datum;
/* nobreak */
}
case 2:
H_ERR_BARS:
if (current_plot->plot_style == HISTOGRAMS) {
if (histogram_opts.type == HT_ERRORBARS) {
/* The code is a tangle, but we can get here with j = 1, 2, or 3 */
if (j == 1)
int_error(c_token, "Not enough columns in using specification");
else if (j == 2) {
v[3] = v[0] + v[1];
v[2] = v[0] - v[1];
} else {
v[3] = v[2];
v[2] = v[1];
}
v[1] = v[0];
v[0] = df_datum;
} else if (j >= 2)
int_error(c_token, "Too many columns in using specification");
else
v[2] = v[3] = v[1];
if (histogram_opts.type == HT_STACKED_IN_TOWERS) {
histogram_rightmost = current_plot->histogram_sequence
+ current_plot->histogram->start;
current_plot->histogram->end = histogram_rightmost;
} else if (v[0] + current_plot->histogram->start > histogram_rightmost) {
histogram_rightmost = v[0] + current_plot->histogram->start;
current_plot->histogram->end = histogram_rightmost;
}
/* Histogram boxwidths are always absolute */
if (boxwidth > 0)
store2d_point(current_plot, i++, v[0], v[1],
v[0] - boxwidth / 2, v[0] + boxwidth / 2,
v[2], v[3], 0.0);
else
store2d_point(current_plot, i++, v[0], v[1],
v[0] - 0.5, v[0] + 0.5,
v[2], v[3], 0.0);
/* x, y */
/* ylow and yhigh are same as y */
} else if ( (current_plot->plot_style == BOXES)
&& boxwidth > 0 && boxwidth_is_absolute) {
/* calculate width now */
if (axis_array[current_plot->x_axis].log) {
double base = axis_array[current_plot->x_axis].base;
store2d_point(current_plot, i++, v[0], v[1],
v[0] * pow(base, -boxwidth/2.), v[0] * pow(base, boxwidth/2.),
v[1], v[1], 0.0);
} else
store2d_point(current_plot, i++, v[0], v[1],
v[0] - boxwidth / 2, v[0] + boxwidth / 2,
v[1], v[1], 0.0);
#ifdef EAM_OBJECTS
} else if (current_plot->plot_style == CIRCLES) {
/* x, y, default radius, full circle */
store2d_point(current_plot, i++, v[0], v[1], v[0], v[0],
0., 360., DEFAULT_RADIUS);
} else if (current_plot->plot_style == ELLIPSES) {
/* x, y, major axis = minor axis = default, default orientation */
store2d_point(current_plot, i++, v[0], v[1], 0.0, 0.0,
0.0, 0.0, DEFAULT_ELLIPSE);
#endif
} else if (current_plot->plot_style == YERRORBARS) {
/* x is index, assign number to y */
v[2] = v[1];
v[1] = v[0];
v[0] = df_datum;
store2d_point(current_plot, i++, v[0], v[1], v[0], v[0],
v[1] - v[2], v[1] + v[2], -1.0);
} else if (current_plot->plot_style == BOXPLOT) {
store2d_point(current_plot, i++, v[0], v[1], v[0], v[0], v[1], v[1],
DEFAULT_BOXPLOT_FACTOR);
} else if (current_plot->plot_style == FILLEDCURVES) {
v[2] = current_plot->filledcurves_options.at;
store2d_point(current_plot, i++, v[0], v[1], v[0], v[0],
v[1], v[2], -1.0);
} else {
double w;
if (current_plot->plot_style == CANDLESTICKS
|| current_plot->plot_style == FINANCEBARS) {
int_warn(storetoken, "This plot style does not work with 1 or 2 cols. Setting to points");
current_plot->plot_style = POINTSTYLE;
}
if (current_plot->plot_smooth == SMOOTH_ACSPLINES)
w = 1.0; /* Unit weights */
else
w = -1.0; /* Auto-width boxes in some styles */
/* Set x/y high/low to exactly [x,y] */
store2d_point(current_plot, i++, v[0], v[1],
v[0], v[0], v[1], v[1], w);
}
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) {
case HISTOGRAMS:
if (histogram_opts.type == HT_ERRORBARS)
goto H_ERR_BARS;
else
/* fall through */
default:
int_warn(storetoken, "This plot style does not work with 3 cols. Setting to yerrorbars");
current_plot->plot_style = YERRORBARS;
/* fall through */
case FILLEDCURVES:
if (current_plot->filledcurves_options.closeto == FILLEDCURVES_DEFAULT)
current_plot->filledcurves_options.closeto = FILLEDCURVES_BETWEEN;
store2d_point(current_plot, i++, v[0], v[1], v[0], v[0],
v[1], v[2], -1.0);
break;
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;
case LABELPOINTS:
/* Load the coords just as we would have for a point plot */