ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tcurve.c
Revision: 1.3
Committed: Mon Jul 14 20:02:29 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -5 lines
Log Message:
Moved some more platform dependencies to common header files.
Included a few necessary system headers.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: tcurve.c,v 1.2 2003/06/30 14:59:12 schorsch Exp $";
3 #endif
4 /*
5 * PROGRAM TO PLOT TEL-A-GRAF CURVES TO METAFILE
6 *
7 * Greg Ward
8 * 12/12/84
9 *
10 * cc -o ../tcurve tcurve.c tgraph.o primout.o mfio.o syscalls.o misc.o -lm
11 */
12
13 #include "rtprocess.h" /* getpid() */
14 #include "tgraph.h"
15
16 #define XLEGEND (XBEG+XSIZ+4*TSIZ) /* x start of legend */
17
18 #define YLEGEND (YBEG+2*YSIZ/3) /* y start of legend */
19
20 short usecurve[NCUR]; /* booleans for curve usage */
21
22 double xmin, ymin, xmax, ymax; /* domain */
23
24 double xsize, ysize; /* axis dimensions */
25
26 double xmnset = -FHUGE, xmxset = FHUGE, /* domain settings */
27 ymnset = -FHUGE, ymxset = FHUGE;
28
29 short logx = FALSE, logy = FALSE; /* flags for log plots */
30
31 short polar = FALSE; /* flag for polar plot */
32
33 short grid = FALSE; /* flag for grid */
34
35 int curtype[NCUR] = {0, 020, 040, 060, 01, 021, 041, 061,
36 02, 022, 042, 062, 03, 023, 043, 063};
37
38 char *sym[NCUR] = {"ex", "triangle", "square", "triangle2", "diamond",
39 "cross", "octagon", "crosssquare", "exsquare",
40 "trianglesquare", "triangle2square", "crossdiamond",
41 "crossoctagon", "exoctagon", "block", "bullet"};
42
43 int ncurves;
44
45 int xlegend,
46 ylegend; /* current legend position */
47
48 int symrad = SYMRAD; /* symbol radius */
49
50 char *progname;
51
52
53
54
55
56 main(argc, argv)
57
58 int argc;
59 char **argv;
60
61 /*
62 * Take Tel-A-Graf runnable files and convert them to
63 * metafile primitives to send to standard output
64 */
65
66 {
67 char tfname[MAXFNAME];
68 FILE *fp;
69 int axflag;
70
71 #ifdef CPM
72 fixargs("tcurve", &argc, &argv);
73 #endif
74
75 progname = *argv++;
76 argc--;
77
78 initialize();
79
80 for (; argc && (**argv == '-' || **argv == '+'); argc--, argv++)
81 option(*argv);
82
83 if (polar) /* avoid dumb choices */
84 logx = FALSE;
85
86 axflag = XTICS|XNUMS|YTICS|YNUMS;
87 if (grid)
88 axflag |= XGRID|YGRID;
89 if (polar)
90 axflag |= ORIGIN;
91 else
92 axflag |= BOX;
93
94 pglob(PINCL, 2, "symbols.mta");
95
96 if (argc)
97
98 for ( ; argc--; argv++) {
99
100 fp = efopen(*argv, "r");
101 normalize(fp, NULL);
102 makeaxis(axflag);
103 fseek(fp, 0L, 0);
104 plot(fp);
105 fclose(fp);
106 }
107 else {
108
109 sprintf(tfname, "%stc%d", TDIR, getpid());
110 fp = efopen(tfname, "w+");
111 normalize(stdin, fp);
112 makeaxis(axflag);
113 fseek(fp, 0L, 0);
114 plot(fp);
115 fclose(fp);
116 unlink(tfname);
117 }
118
119 pglob(PEOF, 0200, NULL);
120
121 return(0);
122 }
123
124
125
126
127
128
129 plot(fp) /* read file and generate plot */
130
131 FILE *fp;
132
133 {
134 int ncur = 0; /* curves seen so far */
135 int cur = 0; /* current curve pattern */
136 char line[255], *s;
137 double x, y;
138 double lastx, lasty;
139 short oobounds = FALSE, firstpoint = TRUE;
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 (isxlabel(line)) {
157 s = snagquo(line);
158 boxstring(0, XBEG, YBEG-1250, XBEG+XSIZ, YBEG-900, s);
159 }
160
161 else if (isylabel(line)) {
162 s = snagquo(line);
163 boxstring(020, XBEG-1900, YBEG, XBEG-1550, YBEG+YSIZ, s);
164 }
165
166 else if (islabel(line)) {
167 if (++ncur < NCUR && usecurve[ncur]) {
168 oobounds = FALSE;
169 firstpoint = TRUE;
170 cur++;
171 plseg(curtype[cur], xlegend, ylegend, xlegend+2000, ylegend);
172 symout(curtype[cur] & 03, xlegend, ylegend, sym[ncur]);
173 pprim(PMSTR, 020, xlegend+400, ylegend+200,
174 xlegend+400, ylegend+200, snagquo(line));
175 ylegend -= 500;
176 }
177 }
178
179 else if (isdata(line) && usecurve[ncur]) {
180
181 if (getdata(line, &x, &y) >= 0) {
182
183 if (oobounds) {
184 oobounds = FALSE;
185 limline(curtype[cur], x, y, lastx, lasty, sym[ncur]);
186 }
187 else if (firstpoint) {
188 firstpoint = FALSE;
189 limline(curtype[cur], x, y, x, y, sym[ncur]);
190 }
191 else
192 plseg(curtype[cur], XCONV(lastx), YCONV(lasty),
193 XCONV(x), YCONV(y));
194
195 lastx = x;
196 lasty = y;
197
198 }
199 else {
200 if (!oobounds) {
201 oobounds = TRUE;
202 if (firstpoint)
203 firstpoint = FALSE;
204 else
205 limline(curtype[cur], lastx, lasty, x, y, NULL);
206 }
207 lastx = x;
208 lasty = y;
209 }
210
211 }
212
213 pglob(PEOP, 0200, NULL);
214
215 }
216
217
218
219
220
221 limline(a0, x, y, xout, yout, s) /* print line from/to out of bounds */
222
223 int a0;
224 double x, y, xout, yout;
225 char *s;
226
227 {
228
229 for ( ; ; )
230 if (xout < xmin) {
231 yout = (yout - y)*(xmin - x)/(xout - x) + y;
232 xout = xmin;
233 } else if (yout < ymin) {
234 xout = (xout - x)*(ymin - y)/(yout - y) + x;
235 yout = ymin;
236 } else if (xout > xmax) {
237 yout = (yout - y)*(xmax - x)/(xout - x) + y;
238 xout = xmax;
239 } else if (yout > ymax) {
240 xout = (xout - x)*(ymax - y)/(yout - y) + x;
241 yout = ymax;
242 } else {
243 if (s != NULL)
244 symout(a0 & 03, XCONV(xout), YCONV(yout), s);
245 plseg(a0, XCONV(x), YCONV(y), XCONV(xout), YCONV(yout));
246 return;
247 }
248
249 }