ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tcurve.c
Revision: 1.2
Committed: Mon Jun 30 14:59:12 2003 UTC (20 years, 11 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

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