ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tcurve.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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