ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tbar.c
Revision: 1.2
Committed: Mon Jun 30 14:59:12 2003 UTC (20 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.1: +5 -1 lines
Log Message:
Replaced most outdated BSD function calls with their posix equivalents, and cleaned up a few other platform dependencies.

File Contents

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