-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdplot.c
More file actions
2029 lines (1729 loc) · 50.4 KB
/
Copy pathstdplot.c
File metadata and controls
2029 lines (1729 loc) · 50.4 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
/* Setting up frames for a generic plot. */
/*
Copyright (C) 2004 University of Texas at Austin
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <rsf.h>
/*^*/
#include "stdplot.h"
#include "axis.h"
#include "vplot.h"
#include "plot.h"
static float min1,min2, max1,max2, mid1,mid2, inch1,inch2, orig1,orig2, inch3, tickscale, tickscale1, tickscale2, tickscale3, tickscale4;
static float labelsz, barlabelsz, barmin, barmax, bar0, dbar, sinth, costh, griddash;
static float d1, d2, d3, frame1, frame2, frame3, l1min, l1max, l2min, l2max, l3min, l3max;
static int framecol, gridcol, gridfat=1;
static int cubelinecol=VP_WHITE;
static int framelabelcol=VP_YELLOW;
static bool labelrot, transp, barmove, wheretics, scalebar, vertbar, wherebartics;
static bool cube=false, movie=false, flat, xreverse, yreverse;
static char blank[]=" ";
static const float aspect=0.8, ticksep=1.75;
static float larnersz;
static struct Label {
char where;
int fat;
float x, y, xpath, ypath, xup, yup, min, max;
char* text;
} /*@null@*/ *label1=NULL,
/*@null@*/ *label2=NULL,
/*@null@*/ *label3=NULL,
/*@null@*/ *label4=NULL,
/*@null@*/ *title=NULL,
/*@null@*/ *barlabel=NULL;
static struct Axis {
bool parallel;
int ntic, maxstrlen;
float orig, dnum, num0;
const char *format;
} /*@null@*/ *axis1=NULL,
/*@null@*/ *axis2=NULL,
/*@null@*/ *axis3=NULL,
/*@null@*/ *axis4=NULL,
/*@null@*/ *baraxis=NULL,
/*@null@*/ *grid1=NULL,
/*@null@*/ *grid2=NULL,
/*@null@*/ *grid3=NULL;
static void make_title (sf_file in, char wheret);
static void make_barlabel (sf_file in);
static void make_labels (sf_file in, char where1, char where2);
static void make_baraxis (float min, float max);
static void make_axes (void);
static void make_grid (bool grid);
static void swap(float*a,float*b);
static void swap(float*a,float*b)
{
float f;
f = *a; *a = *b; *b=f;
}
void vp_stdplot_init (float umin1, float umax1 /* user's frame for axis 1 */,
float umin2, float umax2 /* user's frame for axis 2 */,
bool transp1 /* default transpose flag */,
bool xreverse1 /* default x reverse flag */,
bool yreverse1 /* default y reverse flag */,
bool pad1 /* default padding */)
/*< Initializing standard plot >*/
{
bool pad, set;
int font;
float mid, off, crowd, barwd;
float xll, xur, yll, yur, screenratio, screenht, screenwd, marg;
char* bartype;
transp = transp1;
if (!sf_getbool ("xreverse",&xreverse)) xreverse = xreverse1;
/* reverse horizontal axis */
if (!sf_getbool ("yreverse",&yreverse)) yreverse = yreverse1;
/* reverse vertical axis */
if (!sf_getbool ("pad",&pad)) pad = pad1;
/* pad plotting area */
if (!sf_getbool ("wantscalebar",&scalebar) &&
!sf_getbool ("scalebar",&scalebar)) scalebar = false;
/* plot a scalebar */
if (!sf_getbool ("barmove", &barmove)) barmove = false;
/* adjust scalebar position, if bartype=h */
/* plot a scalebar */
if (pad) { /* 4% stretch */
mid = 0.5*(umin1+umax1);
off = 1.04*0.5*(umax1-umin1);
umin1 = mid-off;
umax1 = mid+off;
mid = 0.5*(umin2+umax2);
off = 1.04*0.5*(umax2-umin2);
umin2 = mid-off;
umax2 = mid+off;
}
if (!sf_getfloat ("tickscale",&tickscale)) tickscale=0.5;
/* ticks scaling */
if (!sf_getfloat ("tickscale1",&tickscale1)) tickscale1=tickscale;
/* ticks scaling on first axis */
if (!sf_getfloat ("tickscale2",&tickscale2)) tickscale2=tickscale;
/* ticks scaling on second axis */
if (!sf_getfloat ("tickscale3",&tickscale3)) tickscale3=tickscale;
/* ticks scaling on third axis */
if (!sf_getfloat ("tickscale4",&tickscale4)) tickscale4=tickscale;
/* ticks scaling on fourth axis */
/* get max and min */
if (!sf_getfloat ("min1",&min1)) min1=umin1;
/* minimum on the first axis */
if (!sf_getfloat ("min2",&min2)) min2=umin2;
/* minimum on the second axis */
if (!sf_getfloat ("max1",&max1)) max1=umax1;
/* maximum on the first axis */
if (!sf_getfloat ("max2",&max2)) max2=umax2;
/* maximum on the second axis */
if (transp) {
swap(&min1,&min2);
swap(&max1,&max2);
}
if (xreverse) swap(&min1,&max1);
if (yreverse) swap(&min2,&max2);
vp_style (VP_STANDARD);
if (!sf_getint("font",&font)) font=-1; /* font to use in text */
if (-1 != font) vp_tfont (font,VP_NO_CHANGE,VP_NO_CHANGE);
/* get screen size */
if (!sf_getfloat ("screenratio",&screenratio))
screenratio = VP_SCREEN_RATIO;
/* ratio of screen height to screen width */
if (!sf_getfloat ("screenht",&screenht))
screenht = VP_STANDARD_HEIGHT;
/* screen height (in "inches") */
if (!sf_getfloat ("screenwd",&screenwd))
screenwd = screenht / screenratio;
/* screen width (in "inches") */
/* get inches */
if (!sf_getfloat ("crowd",&crowd)) crowd = 0.75;
/* window size as ratio of the total area */
if (!sf_getfloat ("xinch",&inch1)) {
/* window width as ratio of the screen width */
if (!sf_getfloat ("crowd1",&inch1)) inch1 = crowd;
/* window width as ratio of the screen width */
inch1 *= screenwd;
}
if (!sf_getfloat ("yinch",&inch2)) {
/* window height as ratio of the screen height */
if (!sf_getfloat ("crowd2",&inch2)) inch2 = crowd;
/* window height as ratio of the screen height */
inch2 *= screenht;
}
/* get corners */
set = sf_getfloat ("xll",&xll);
/* lower left horizontal coordinate */
if (!sf_getfloat ("xur",&xur)) {
/* upper right horizontal coordinate */
if (set) {
xur = xll + inch1;
} else {
marg = screenwd - inch1;
xll = marg * 2./3.;
xur = screenwd - marg * 1./3.;
}
} else if (!set) {
xll = xur - inch1;
}
set = sf_getfloat ("yll",&yll);
/* lower left vertical coordinate */
if (!sf_getfloat ("yur",&yur)) {
/* upper right vertical coordinate */
if (set) {
yur = yll + inch2;
} else {
marg = screenht - inch2;
yll = marg * 1./2.;
yur = screenht - marg * 1./2.;
}
} else if (!set) {
yll = yur - inch2;
}
/* make frame smaller to accomodate scale bar */
if (scalebar) {
bartype = sf_getstring("bartype");
/* [v,h] vertical or horizontal bar (default is v) */
if (NULL == bartype) {
vertbar = true;
} else {
vertbar = (bool) (bartype[0] == 'v');
free (bartype);
}
if (!sf_getfloat("barwidth",&barwd)) barwd = 0.36;
/* scale bar size */
if (vertbar) {
xur -= (0.07*screenwd + barwd);
xll -= 0.5*barwd;
barmax = 0.88*screenwd;
barmin = barmax-barwd;
} else {
if (cube) {
if (!barmove) {
yll -= 0.4*barwd;
yur -= (0.04*screenht + barwd);
barmax = 0.98*screenht;
barmin = barmax-barwd;
} else {
barmin = yll - 0.05*screenht;
barmax = barmin+barwd;
yur += 0.4*barwd;
yll += (0.05*screenht + barwd);
}
} else {
barmin = barmove ? yll : 0.12*screenht;
barmax = barmin+barwd;
yur += 0.4*barwd;
yll += (0.04*screenht + barwd);
}
}
}
/* set origin */
if (xll != xur) {
inch1 = xur - xll;
orig1 = xll + (xur - xll)*0.5;
} else {
orig1 = screenwd*0.5;
}
if (yll != yur) {
inch2 = yur - yll;
orig2 = yll + (yur - yll)*0.5;
} else {
orig2 = screenht*0.5;
}
if (min1 == 0. && max1 == 0.) {
min1 = -1.;
max1 = 1.;
} else if (min1 == max1) {
max1 *= 1.04;
min1 *= 0.96;
}
if (min2 == 0. && max2 == 0.) {
min2 = -1.;
max2 = 1.;
} else if (min2 == max2) {
max2 *= 1.04;
min2 *= 0.96;
}
if (!sf_getint ("axiscol",&framecol)) framecol=VP_WHITE;
/* axes color */
if (!sf_getint ("framelabelcol",&framelabelcol)) framelabelcol=VP_YELLOW;
/* frame labels color */
if (!sf_getint ("cubelinecol",&cubelinecol)) cubelinecol=framelabelcol;
/* cube lines color */
vp_coordinates();
}
void vp_cubecoord (int side /* 1=top, 2=side, 3=front */,
float umin1, float umax1, float umin2, float umax2)
/*< setup the coordinate system for the cube front >*/
{
float scale1, scale2;
/* find scales and user origin */
switch (side) {
case 3: /* front */
scale1 = inch1 * (mid1 - min1) / (max1 - min1) / (umax1 - umin1);
scale2 = inch2 * (mid2 - min2) / (max2 - min2) / (umax2 - umin2);
vp_orig (orig1-0.5*inch1,orig2-0.5*inch2);
break;
case 2: /* side */
scale1 = inch1 * (max1 - mid1) / (max1 - min1) / (umax1 - umin1);
scale2 = inch2 * (mid2 - min2) / (max2 - min2) / (umax2 - umin2);
vp_orig (orig1+inch1*((mid1 - min1)/(max1 - min1)-0.5),
orig2-0.5*inch2);
break;
case 1:
default:
scale1 = inch1 * (mid1 - min1) / (max1 - min1) / (umax1 - umin1);
scale2 = inch2 * (max2 - mid2) / (max2 - min2) / (umax2 - umin2);
vp_orig (orig1-0.5*inch1,
orig2+inch2*((mid2 - min2)/(max2 - min2)-0.5));
}
/* setup the coordinate system */
vp_scale (scale1, scale2);
vp_uorig (umin1, umin2);
vp_uclip (umin1, umin2, umax1, umax2);
}
void vp_coordinates (void)
/*< setup the coordinate system >*/
{
float scale1, scale2, uorig1, uorig2;
/* find scales and user origin */
scale1 = inch1 / (max1 - min1);
scale2 = inch2 / (max2 - min2);
uorig2 = (min2 + max2)*0.5;
uorig1 = (min1 + max1)*0.5;
/* setup the coordinate system */
vp_scale (scale1, scale2);
vp_orig (orig1, orig2);
vp_uorig (uorig1, uorig2);
}
void vp_cubeplot_init (int n1pix, int n2pix, /* total pixels */
int n1front, int n2front, /* front face pixels */
bool flat1 /* flat flag */,
bool movie1 /* movie flag */)
/*< Initializing 3-D cube plot. >*/
{
min1 = -0.5;
max1 = n1pix-0.5;
mid1 = n1front-0.5;
min2 = -0.5;
max2 = n2pix-0.5;
mid2 = n2front-0.5;
cube = true;
flat = flat1;
movie = movie1;
vp_stdplot_init (min1,max1,min2,max2, true, false, false, false);
swap(&mid1,&mid2); /* transp=true */
}
static void make_labels (sf_file in, char where1, char where2)
{
int n1, n2, n3;
float vs, xc, yc, x1, y1, x2, y2, o1, o2, o3;
bool want;
char *where, *labl, *unit;
size_t len;
struct Label *label;
if (cube) {
if (!sf_histint(in,"n1",&n1)) n1=1;
if (!sf_histfloat(in,"o1",&o1)) o1=0.;
if (!sf_histfloat(in,"d1",&d1)) d1=1.;
l2max = o1-0.5*d1;
l2min = o1+(n1-0.5)*d1;
if (!sf_histint(in,"n2",&n2)) n2=1;
if (!sf_histfloat(in,"o2",&o2)) o2=0.;
if (!sf_histfloat(in,"d2",&d2)) d2=1.;
l1min = o2-0.5*d2;
l1max = o2+(n2-0.5)*d2;
if (!movie || !sf_histint(in,"n3",&n3)) n3 = sf_leftsize(in,2);
if (!sf_histfloat(in,"o3",&o3)) o3=0.;
if (!sf_histfloat(in,"d3",&d3)) d3=1.;
l3min = o3-0.5*d3;
l3max = o3+(n3-0.5)*d3;
}
if (sf_getbool ("wantaxis", &want) && !want) {
/*( wantaxis if draw axes )*/
label1 = NULL;
label2 = NULL;
if (cube) label3 = NULL;
return;
}
if (sf_getbool ("wantaxis1",&want) && !want) {
/*( wantaxis1 if draw first axis )*/
label1 = NULL;
} else if (NULL == label1) {
label1 = (struct Label*) sf_alloc(1,sizeof(struct Label));
}
if (sf_getbool ("wantaxis2",&want) && !want) {
/*( wantaxis2 if draw second axis )*/
label2 = NULL;
if (!cube && NULL == label1) return;
} else if (NULL == label2) {
label2 = (struct Label*) sf_alloc(1,sizeof(struct Label));
}
if (cube) {
if (sf_getbool ("wantaxis3",&want) && !want) {
/*( wantaxis3 if draw third axis in cube plots )*/
label3 = NULL;
if (NULL == label1 && NULL == label2) return;
} else if (NULL == label3) {
label3 = (struct Label*) sf_alloc(1,sizeof(struct Label));
}
}
if (transp) {
label = label1;
label1 = label2;
label2 = label;
}
if (cube && flat && NULL != label3 && NULL != label2) {
label4 = (struct Label*) sf_alloc(1,sizeof(struct Label));
} else {
label4 = NULL;
}
if (!sf_getfloat ("labelsz",&labelsz)) labelsz=8.;
if (!sf_getfloat ("larnersz",&larnersz)) larnersz=0.0f;
/* give the font size as a fraction of the total screen height,
this is based on Ken Larner's 1/20 rule.
Any positive larnersz value will overwrite labelsz with
the appropiate rule*/
if(larnersz >0.0f) labelsz = (72.0f)*orig2/larnersz; /* inches to pt conversion */
/* label size */
if (cube) {
labelsz *= 0.03; /* slightly smaller */
} else {
labelsz /= 33.;
}
vs = 2.5*labelsz;
if (!sf_getbool ("labelrot",&labelrot)) labelrot = false;
/* if rotate vertical label */
if (NULL != label1) { /* horizontal axis */
if (!cube && NULL != (where = sf_getstring("wherexlabel"))) {
/* where to put horizontal axis (top,bottom) */
label1->where = *where;
} else {
label1->where = where1;
}
if (!sf_getint ("labelfat",&(label1->fat))) label1->fat=0;
/*( labelfat label fatness )*/
if ((NULL == (labl=sf_getstring(transp? "label2":"label1"))) &&
(NULL == (labl=sf_histstring(in,
transp? "label2":"label1")))) {
label1->text = blank;
/*( label1 label on the first axis )*/
} else if (((NULL == (unit=sf_getstring(transp? "unit2":"unit1"))) &&
(NULL == (unit=sf_histstring(in,
transp? "unit2":"unit1")))) ||
*unit == '\0' || (*unit == ' ' && *(unit+1) == '\0')) {
label1->text = labl;
/*( unit1 unit on the first axis )*/
} else {
len = strlen(labl)+strlen(unit)+4;
label1->text = sf_charalloc(len);
snprintf(label1->text,len,"%s (%s)",labl,unit);
free(labl);
free(unit);
}
label1->xpath = labelsz;
label1->xup = 0.;
label1->ypath = 0.;
label1->yup = labelsz;
xc = cube? 0.5*(mid1 + min1) : 0.5*(max1 + min1);
yc = (label1->where == 't') ? max2: min2;
vp_umove (xc, yc);
vp_where (&xc, &yc);
label1->x = xc;
label1->y = (label1->where == 't') ? yc+vs: yc-vs;
if (cube) {
label1->min = l1min;
label1->max = l1max;
} else {
label1->min = min1;
label1->max = max1;
}
}
if (NULL != label3) { /* out of plane axis */
if (!sf_getint ("labelfat",&(label3->fat))) label3->fat=0;
/* label fatness */
if ((NULL == (labl=sf_getstring("label3"))) &&
(NULL == (labl=sf_histstring(in,"label3")))) {
label3->text = blank;
/*( label3 label on the third axis )*/
} else if (((NULL == (unit=sf_getstring("unit3"))) &&
(NULL == (unit=sf_histstring(in,"unit3")))) ||
*unit == '\0' || (*unit == ' ' && *(unit+1) == '\0')) {
label3->text = labl;
/*( unit3 unit on the third axis )*/
} else {
len = strlen(labl)+strlen(unit)+4;
label3->text = sf_charalloc(len);
snprintf(label3->text,len,"%s (%s)",labl,unit);
free(labl);
free(unit);
}
if (flat) {
vp_umove (mid1,min2);
vp_where (&x1, &y1);
vp_umove (max1,min2);
vp_where (&x2, &y1);
inch3 = fabsf(x2-x1);
label3->xpath = labelsz;
label3->xup = 0.;
label3->ypath = 0.;
label3->yup = labelsz;
xc = 0.5*(x2+x1);
yc = y1;
label3->y = yc-vs;
label3->x = xc;
} else {
vp_umove (mid1,min2);
vp_where (&x1, &y1);
vp_umove (max1,max2-mid2);
vp_where (&x2, &y2);
inch3 = hypotf(x2-x1,y2-y1);
costh = (x2-x1)/inch3;
sinth = (y2-y1)/inch3;
label3->xpath = labelsz*costh;
label3->xup = -labelsz*sinth;
label3->ypath = labelsz*sinth;
label3->yup = labelsz*costh;
xc = 0.5*(x1+x2);
yc = 0.5*(y1+y2);
label3->y = yc-vs*costh;
label3->x = xc+vs*sinth;
}
label3->min = l3min;
label3->max = l3max;
}
if (NULL != label2) { /* vertical axis */
if (!cube && NULL != (where = sf_getstring("whereylabel"))) {
/* where to put vertical label (left,right) */
label2->where = *where;
} else {
label2->where = where2;
}
if (!sf_getint ("labelfat",&(label2->fat))) label2->fat=0;
/* label fatness */
if ((NULL == (labl=sf_getstring(transp? "label1":"label2"))) &&
(NULL == (labl=sf_histstring(in,
transp? "label1":"label2")))) {
label2->text = blank;
/*( label2 label on the second axis )*/
} else if (((NULL == (unit=sf_getstring(transp? "unit1":"unit2"))) &&
(NULL == (unit=sf_histstring(in,
transp? "unit1":"unit2")))) ||
*unit == '\0' || (*unit == ' ' && *(unit+1) == '\0')) {
label2->text = labl;
/*( unit2 unit on the second axis )*/
} else {
len = strlen(labl)+strlen(unit)+4;
label2->text = sf_charalloc(len);
snprintf(label2->text,len,"%s (%s)",labl,unit);
free(labl);
free(unit);
}
label2->ypath = labelrot? -labelsz: labelsz;
label2->yup = 0.;
label2->xpath = 0.;
label2->xup = labelrot? labelsz: -labelsz;
xc = (label2->where == 'l')? min1: max1;
yc = cube? 0.5*(min2 + mid2) : 0.5*(min2 + max2);
vp_umove (xc, yc);
vp_where (&xc, &yc);
label2->y = yc;
label2->x = (label2->where == 'l')? xc-vs: xc+vs;
if (cube) {
label2->max = l2max;
label2->min = l2min;
} else {
label2->min = min2;
label2->max = max2;
}
}
if (NULL != label4) { /* vertical axis for the out of plane axis */
label4->where = label2->where;
label4->fat = label2->fat;
label4->text = label3->text;
label4->ypath = label2->ypath;
label4->yup = label2->yup;
label4->xpath = label2->xpath;
label4->xup = label2->xup;
xc = min1;
yc = 0.5*(max2 + mid2);
vp_umove (xc, yc);
vp_where (&xc, &yc);
label4->y = yc;
label4->x = label2->x;
label4->max = l3max;
label4->min = l3min;
}
}
static void make_baraxis (float min, float max)
{
char* where;
bool modify;
if (barlabel == NULL) return;
if (NULL == baraxis)
baraxis = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
if (!sf_getfloat ("axisorbar",&(baraxis->orig))) {
/* bar origin */
if (vertbar) {
baraxis->orig = (barlabel->where == 'l'? barmin: barmax);
} else {
baraxis->orig = (barlabel->where == 'b'? barmin: barmax);
}
}
if (!sf_getbool ("parallelbar",&(baraxis->parallel)) &&
(( vertbar && !sf_getbool ("parallel2",&(baraxis->parallel))) ||
(!vertbar && !sf_getbool ("parallel1",&(baraxis->parallel)))) &&
!sf_getbool ("parallel", &(baraxis->parallel))) baraxis->parallel=true;
/* tickmark labels parallel to the axis */
if (!sf_getint ("nbartic",&(baraxis->ntic)))
baraxis->ntic = 0.5 + (vertbar? inch2: inch1)/(aspect*labelsz);
/*( nbartic number of scalebar ticmarks )*/
if (NULL == (baraxis->format = sf_getstring("formatbar"))) {
/* format for ticmark labels in the scalebar */
if ((vertbar && NULL == (baraxis->format = sf_getstring("format2"))) ||
(!vertbar && NULL == (baraxis->format = sf_getstring("format1"))))
baraxis->format="%1.5g";
}
modify = (bool) (!sf_getfloat ("dbarnum", &(baraxis->dnum)) ||
/*( dbarnum scalebar tic increment )*/
!sf_getfloat ("obarnum", &(baraxis->num0)));
/*( obarnum scalebar tic origin )*/
baraxis->ntic = vp_optimal_scale(baraxis->ntic,
modify,
baraxis->parallel,
baraxis->format,
min, max,
&(baraxis->num0),
&(baraxis->dnum),
&(baraxis->maxstrlen));
if (fabsf(max-min) < SF_EPS) {
baraxis->ntic = 1;
bar0 = 0.0;
dbar = SF_EPS;
} else {
bar0 = (baraxis->num0-0.5*(min+max))/(max-min);
dbar = (baraxis->dnum)/(max-min);
}
if (vertbar) {
bar0 = orig2 + inch2*bar0;
dbar *= inch2;
} else {
bar0 = orig1 + inch1*bar0;
dbar *= inch1;
}
wherebartics = (bool) ((NULL != (where = sf_getstring ("wherebartics"))) &&
('a' == *where));
/*( wherebartics where to put scalebar ticmarks )*/
}
static void make_axes (void)
/* put tickmarks */
{
char *where;
bool modify;
if (label1 != NULL) { /* horizontal axis */
if (NULL == axis1)
axis1 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
if (!sf_getfloat ("axisor1",&(axis1->orig)))
axis1->orig = (label1->where == 'b'? min2: max2);
/* first axis origin */
if (!sf_getbool ("parallel1",&(axis1->parallel)) &&
!sf_getbool ("parallel", &(axis1->parallel))) axis1->parallel=true;
/* tickmark labels parallel to the axis */
if (NULL == (axis1->format = sf_getstring("format1")))
axis1->format = "%1.5g"; /* tick mark format */
if (!sf_getint ("n1tic",&(axis1->ntic)))
/*( n1tic axis1 number of ticmarks )*/
axis1->ntic = cube?
0.5 + inch1*(mid1-min1)/((max1-min1)*aspect*labelsz):
0.5 + inch1/(aspect*labelsz);
modify = (bool) (!sf_getfloat ("d1num", &(axis1->dnum)) ||
/*( d1num axis1 tic increment )*/
!sf_getfloat ("o1num", &(axis1->num0)));
/*( o1num axis1 tic origin )*/
axis1->ntic = vp_optimal_scale(axis1->ntic,
modify,
axis1->parallel,
axis1->format,
label1->min, label1->max,
&(axis1->num0),
&(axis1->dnum),
&(axis1->maxstrlen));
}
if (label2 != NULL) { /* vertical axis */
if (NULL == axis2)
axis2 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
if (!sf_getfloat ("axisor2",&(axis2->orig)))
axis2->orig = (label2->where == 'l'? min1: max1);
/* second axis origin */
if (!sf_getbool ("parallel2",&(axis2->parallel)) &&
!sf_getbool ("parallel", &(axis2->parallel))) axis2->parallel=true;
/* tickmark labels parallel to the axis */
if (NULL == (axis2->format = sf_getstring("format2")))
axis2->format = "%1.5g"; /* tickmark format */
if (!sf_getint ("n2tic",&(axis2->ntic)))
/*( n2tic axis2 number of ticmarks )*/
axis2->ntic = cube?
0.5 + inch2*(mid2-min2)/((max2-min2)*aspect*labelsz):
0.5 + inch2/(aspect*labelsz);
modify = (bool) (!sf_getfloat ("d2num", &(axis2->dnum)) ||
/*( d2num axis2 tic increment )*/
!sf_getfloat ("o2num", &(axis2->num0)));
/*( o2num axis2 tic origin )*/
axis2->ntic = vp_optimal_scale(axis2->ntic,
modify,
axis2->parallel,
axis2->format,
label2->min, label2->max,
&(axis2->num0),
&(axis2->dnum),
&(axis2->maxstrlen));
}
if (label3 != NULL) {
if (NULL == axis3)
axis3 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
if (!sf_getfloat ("axisor3",&(axis3->orig)))
axis3->orig = min1;
/* third axis origin */
if (!sf_getbool ("parallel3",&(axis3->parallel)) &&
!sf_getbool ("parallel", &(axis3->parallel))) axis3->parallel=true;
/* tickmark labels parallel to the axis */
if (NULL == (axis3->format = sf_getstring("format3")))
axis3->format = "%1.5g"; /* tickmark format */
if (!sf_getint ("n3tic",&(axis3->ntic)))
/*( n3tic axis3 number of ticmarks )*/
axis3->ntic = 0.5 + inch3/(aspect*labelsz);
modify = (bool) (!sf_getfloat ("d3num", &(axis3->dnum)) ||
/*( d3num axis3 tic increment )*/
!sf_getfloat ("o3num", &(axis3->num0)));
/*( o3num axis3 tic origin )*/
axis3->ntic = vp_optimal_scale(axis3->ntic,
modify,
axis3->parallel,
axis3->format,
label3->min, label3->max,
&(axis3->num0),
&(axis3->dnum),
&(axis3->maxstrlen));
}
if (label4 != NULL) { /* vertical axis for out of plane */
if (NULL == axis4)
axis4 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
axis4->orig = axis2->orig;
axis4->parallel = axis2->parallel;
axis4->format = axis2->format;
if (!sf_getint ("n4tic",&(axis4->ntic)))
/*( n4tic axis4 number of ticmarks )*/
axis4->ntic = 0.5+inch2*(max2-mid2)/((max2-min2)*aspect*labelsz);
modify = (bool) (!sf_getfloat ("d4num", &(axis4->dnum)) ||
/*( d4num axis4 tic increment )*/
!sf_getfloat ("o4num", &(axis4->num0)));
/*( o4num axis4 tic origin )*/
axis4->ntic = vp_optimal_scale(axis4->ntic,
modify,
axis4->parallel,
axis4->format,
label4->min, label4->max,
&(axis4->num0),
&(axis4->dnum),
&(axis4->maxstrlen));
}
wheretics = (bool) ((NULL != (where = sf_getstring ("wheretics"))) &&
('a' == *where));
/*( wheretics where to put ticmarks )*/
}
static void make_grid (bool grid)
{
bool need;
float num;
if (axis1 != NULL) {
if (!sf_getbool("grid",&need) && !sf_getbool("grid1",&need))
need = transp? false: grid;
/*( grid1 to draw grid on first axis )*/
if (need) {
grid1 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
if (!sf_getfloat ("g1num0",&(grid1->num0)))
grid1->num0 = axis1->num0;
/*( g1num0 grid mark origin on first axis )*/
grid1->orig = axis1->orig;
if (!sf_getfloat ("g1num",&(grid1->dnum))) {
/*( g1num grid mark sampling on first axis )*/
grid1->dnum = axis1->dnum;
grid1->ntic = axis1->ntic;
} else {
grid1->ntic=0;
if (xreverse) {
grid1->dnum = -grid1->dnum;
for (num=grid1->num0; num >= max1; num += grid1->dnum) {
grid1->ntic++;
}
} else {
for (num=grid1->num0; num <= max1; num += grid1->dnum) {
grid1->ntic++;
}
}
}
}
}
if (axis2 != NULL) {
if (!sf_getbool("grid",&need) && !sf_getbool("grid2",&need))
need = transp? grid: false;
/*( grid2 to draw grid on second axis )*/
if (need) {
grid2 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
if (!sf_getfloat ("g2num0",&(grid2->num0)))
grid2->num0 = axis2->num0;
/*( g2num0 grid mark origin on second axis )*/
grid2->orig = axis2->orig;
if (!sf_getfloat ("g2num",&(grid2->dnum))) {
/*( g2num grid mark sampling on second axis )*/
grid2->dnum = axis2->dnum;
grid2->ntic = axis2->ntic;
} else {
grid2->ntic=0;
if (yreverse) {
grid2->dnum = -grid2->dnum;
for (num=grid2->num0; num >= max2; num += grid2->dnum) {
grid2->ntic++;
}
} else {
for (num=grid2->num0; num <= max2; num += grid2->dnum) {
grid2->ntic++;
}
}
}
}
}
if ((axis3 != NULL) &&
((sf_getbool("grid",&need) && need) ||
(sf_getbool("grid3",&need) && need))) {
grid3 = (struct Axis*) sf_alloc(1,sizeof(struct Axis));
/* to draw grid */
grid3->num0 = axis3->num0;
grid3->orig = axis3->orig;
grid3->dnum = axis3->dnum;
grid3->ntic = axis3->ntic;
}
if (NULL != grid1 || NULL != grid2 || NULL != grid3) {
if (!sf_getint("gridcol",&gridcol)) gridcol=grid? VP_RED: framecol;
/* grid color */
if (!sf_getint("gridfat",&gridfat)) gridfat=1;
/* grid fatness */
if (!sf_getfloat("griddash",&griddash)) griddash=0.0f;
/* grid dash pattern */
}
}
static void make_title (sf_file in, char wheret)
{
bool want;
char* where;
float titlesz, vs, xc, yc;
if (sf_getbool ("wanttitle",&want) && !want) {
/* if include title */
title = NULL;
return;
}
if (NULL == title)
title = (struct Label*) sf_alloc(1,sizeof(struct Label));
if (!cube && NULL != (where = sf_getstring("wheretitle"))) {
/* where to put title (top,bottom,left,right) */
title->where = *where;
} else {
title->where = wheret;
}
if (!sf_getint ("titlefat",&(title->fat))) title->fat=0;
/* title fatness */
if (!sf_getfloat ("titlesz",&titlesz)) titlesz=10.;
/* title font size */
if (NULL == (title->text = sf_getstring("title")) &&
NULL == (title->text = sf_histstring(in,"title")) &&
NULL == (title->text = sf_histstring(in,"in")))
title->text = blank;
/*( title plot title )*/