ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tbar.c
Revision: 1.5
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 1.4: +28 -30 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: tbar.c,v 1.4 2003/08/01 14:14:24 schorsch Exp $";
3 #endif
4 /*
5 * PROGRAM TO PLOT TEL-A-GRAF POINTS TO METAFILE
6 *
7 * Greg Ward
8 * 12/12/84
9 *
10 * cc -o ../tbar tbar.c tgraph.o primout.o mfio.o syscalls.o misc.o -lm
11 */
12
13 #include "rtprocess.h" /* getpid() */
14 #include "tgraph.h"
15 #include "plot.h"
16
17
18 #define XLEGEND (XBEG+XSIZ+4*TSIZ) /* x start of legend */
19
20 #define YLEGEND (YBEG+2*YSIZ/3) /* y start of legend */
21
22 #define MAXBAR 1000 /* maximum bar width */
23
24 short usecurve[NCUR]; /* booleans for curve usage */
25
26 double xmin, ymin, xmax, ymax; /* domain */
27
28 double xsize, ysize; /* axis dimensions */
29
30 double xmnset = -FHUGE, xmxset = FHUGE, /* domain settings */
31 ymnset = -FHUGE, ymxset = FHUGE;
32
33 short logx = FALSE, logy = FALSE; /* flags for log plots */
34
35 short polar = FALSE; /* flag for polar plots */
36
37 short grid = FALSE; /* flag for grid */
38
39 int curtype[NCUR] = {0, 04, 010, 014, 01, 05, 011, 015,
40 02, 06, 012, 016, 03, 07, 013, 017};
41
42 int ncurves;
43
44 int xlegend,
45 ylegend; /* current legend position */
46
47 int symrad = SYMRAD; /* symbol radius */
48
49 char *progname;
50
51 static void barout(int cn, double x, double y);
52 static void boxout(int a0, int xmn, int ymn, int xmx, int ymx);
53
54
55 int
56 main(
57 int argc,
58 char **argv
59 )
60 /*
61 * Take Tel-A-Graf runnable files and convert them to
62 * metafile primitives to send to standard output
63 */
64 {
65 char tfname[MAXFNAME];
66 FILE *fp;
67 int axflag;
68
69 progname = *argv++;
70 argc--;
71
72 initialize();
73
74 for (; argc && (**argv == '-' || **argv == '+'); argc--, argv++)
75 option(*argv);
76
77 polar = FALSE; /* override stupid choices */
78 logx = FALSE;
79 axflag = BOX|ORIGIN|YTICS|YNUMS;
80 if (grid)
81 axflag |= YGRID;
82
83 if (argc)
84
85 for ( ; argc--; argv++) {
86
87 fp = efopen(*argv, "r");
88 normalize(fp, NULL);
89 if (ymin > 0)
90 ymin = 0;
91 else if (ymax < 0)
92 ymax = 0;
93 xmax++;
94 makeaxis(axflag);
95 fseek(fp, 0L, 0);
96 plot(fp);
97 fclose(fp);
98 }
99 else {
100
101 sprintf(tfname, "%stb%d", TDIR, getpid());
102 fp = efopen(tfname, "w+");
103 normalize(stdin, fp);
104 if (ymin > 0)
105 ymin = 0;
106 else if (ymax < 0)
107 ymax = 0;
108 xmax++;
109 makeaxis(axflag);
110 fseek(fp, 0L, 0);
111 plot(fp);
112 fclose(fp);
113 unlink(tfname);
114 }
115
116 pglob(PEOF, 0200, NULL);
117
118 return(0);
119 }
120
121
122
123 void
124 plot( /* read file and generate plot */
125 FILE *fp
126 )
127 {
128 int ncur = 0; /* curves seen so far */
129 char line[255], *s;
130 double x, y;
131
132 xlegend = XLEGEND;
133 ylegend = YLEGEND;
134
135 if (ncurves > 0) {
136 pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "Legend:");
137 pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "______");
138 }
139
140 while (fgets(line, sizeof line, fp) != NULL)
141
142 if (istitle(line)) {
143 s = snagquo(line);
144 boxstring(0, 0, YBEG+YSIZ+1000, XYSIZE-1, YBEG+YSIZ+1500, s);
145 }
146
147 else if (isdivlab(line)) {
148 s = line;
149 x = 1;
150 while ((s = snagquo(s)) != NULL) {
151 if (x >= xmin && x <= xmax)
152 boxstring(0, XCONV(x), YBEG-750, XCONV(x+0.66), YBEG-400, s);
153 s += strlen(s)+1;
154 x++;
155 }
156 }
157
158 else if (isxlabel(line)) {
159 s = snagquo(line);
160 boxstring(0, XBEG, YBEG-1250, XBEG+XSIZ, YBEG-900, s);
161 }
162
163 else if (isylabel(line)) {
164 s = snagquo(line);
165 boxstring(020, XBEG-1900, YBEG, XBEG-1550, YBEG+YSIZ, s);
166 }
167
168 else if (islabel(line)) {
169 if (++ncur < NCUR && usecurve[ncur]) {
170 boxout(curtype[ncur], xlegend-200, ylegend, xlegend+200, ylegend+250);
171 pprim(PMSTR, 020, xlegend+400, ylegend+200,
172 xlegend+400, ylegend+200, snagquo(line));
173 ylegend -= 500;
174 }
175 }
176
177 else if (usecurve[ncur] && isdata(line)) {
178
179 if (getdata(line, &x, &y) >= 0)
180 barout(ncur, x, y);
181
182 }
183
184 pglob(PEOP, 0200, NULL);
185
186 }
187
188
189 void
190 barout( /* output bar for curve cn, value (x,y) */
191 int cn,
192 double x,
193 double y
194 )
195 {
196 int barleft, barwidth;
197 int barlower, barheight;
198
199 barwidth = XSIZ/xsize/(ncurves+1)*0.66;
200 if (barwidth > MAXBAR)
201 barwidth = MAXBAR;
202
203 barleft = XCONV(x) + cn*barwidth;
204
205 if (y < 0.0) {
206 barlower = YCONV(y);
207 barheight = YCONV(0.0) - barlower;
208 } else {
209 barlower = YCONV(0.0);
210 barheight = YCONV(y) - barlower;
211 }
212 boxout(curtype[cn], barleft, barlower,
213 barleft+barwidth, barlower+barheight);
214 }
215
216
217 void
218 boxout( /* output a box */
219 int a0,
220 int xmn,
221 int ymn,
222 int xmx,
223 int ymx
224 )
225 {
226 pprim(PRFILL, a0, xmn, ymn, xmx, ymx, NULL);
227 plseg(0, xmn, ymn, xmx, ymn);
228 plseg(0, xmn, ymn, xmn, ymx);
229 plseg(0, xmn, ymx, xmx, ymx);
230 plseg(0, xmx, ymn, xmx, ymx);
231 }
232