ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tcurve.c
Revision: 1.4
Committed: Fri Aug 1 14:14:24 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -5 lines
Log Message:
Eliminated CPM, MAC, and UNIX conditional compiles.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.4 static const char RCSid[] = "$Id: tcurve.c,v 1.3 2003/07/14 20:02:29 schorsch 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 schorsch 1.3 #include "rtprocess.h" /* getpid() */
14 greg 1.1 #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     progname = *argv++;
72     argc--;
73    
74     initialize();
75    
76     for (; argc && (**argv == '-' || **argv == '+'); argc--, argv++)
77     option(*argv);
78    
79     if (polar) /* avoid dumb choices */
80     logx = FALSE;
81    
82     axflag = XTICS|XNUMS|YTICS|YNUMS;
83     if (grid)
84     axflag |= XGRID|YGRID;
85     if (polar)
86     axflag |= ORIGIN;
87     else
88     axflag |= BOX;
89    
90     pglob(PINCL, 2, "symbols.mta");
91    
92     if (argc)
93    
94     for ( ; argc--; argv++) {
95    
96     fp = efopen(*argv, "r");
97     normalize(fp, NULL);
98     makeaxis(axflag);
99     fseek(fp, 0L, 0);
100     plot(fp);
101     fclose(fp);
102     }
103     else {
104    
105     sprintf(tfname, "%stc%d", TDIR, getpid());
106     fp = efopen(tfname, "w+");
107     normalize(stdin, fp);
108     makeaxis(axflag);
109     fseek(fp, 0L, 0);
110     plot(fp);
111     fclose(fp);
112     unlink(tfname);
113     }
114    
115     pglob(PEOF, 0200, NULL);
116    
117     return(0);
118     }
119    
120    
121    
122    
123    
124    
125     plot(fp) /* read file and generate plot */
126    
127     FILE *fp;
128    
129     {
130     int ncur = 0; /* curves seen so far */
131     int cur = 0; /* current curve pattern */
132     char line[255], *s;
133     double x, y;
134     double lastx, lasty;
135     short oobounds = FALSE, firstpoint = TRUE;
136    
137     xlegend = XLEGEND;
138     ylegend = YLEGEND;
139    
140     if (ncurves > 0) {
141     pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "Legend:");
142     pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "______");
143     }
144    
145     while (fgets(line, sizeof line, fp) != NULL)
146    
147     if (istitle(line)) {
148     s = snagquo(line);
149     boxstring(0, 0, YBEG+YSIZ+1000, XYSIZE-1, YBEG+YSIZ+1500, s);
150     }
151    
152     else if (isxlabel(line)) {
153     s = snagquo(line);
154     boxstring(0, XBEG, YBEG-1250, XBEG+XSIZ, YBEG-900, s);
155     }
156    
157     else if (isylabel(line)) {
158     s = snagquo(line);
159     boxstring(020, XBEG-1900, YBEG, XBEG-1550, YBEG+YSIZ, s);
160     }
161    
162     else if (islabel(line)) {
163     if (++ncur < NCUR && usecurve[ncur]) {
164     oobounds = FALSE;
165     firstpoint = TRUE;
166     cur++;
167     plseg(curtype[cur], xlegend, ylegend, xlegend+2000, ylegend);
168     symout(curtype[cur] & 03, xlegend, ylegend, sym[ncur]);
169     pprim(PMSTR, 020, xlegend+400, ylegend+200,
170     xlegend+400, ylegend+200, snagquo(line));
171     ylegend -= 500;
172     }
173     }
174    
175     else if (isdata(line) && usecurve[ncur]) {
176    
177     if (getdata(line, &x, &y) >= 0) {
178    
179     if (oobounds) {
180     oobounds = FALSE;
181     limline(curtype[cur], x, y, lastx, lasty, sym[ncur]);
182     }
183     else if (firstpoint) {
184     firstpoint = FALSE;
185     limline(curtype[cur], x, y, x, y, sym[ncur]);
186     }
187     else
188     plseg(curtype[cur], XCONV(lastx), YCONV(lasty),
189     XCONV(x), YCONV(y));
190    
191     lastx = x;
192     lasty = y;
193    
194     }
195     else {
196     if (!oobounds) {
197     oobounds = TRUE;
198     if (firstpoint)
199     firstpoint = FALSE;
200     else
201     limline(curtype[cur], lastx, lasty, x, y, NULL);
202     }
203     lastx = x;
204     lasty = y;
205     }
206    
207     }
208    
209     pglob(PEOP, 0200, NULL);
210    
211     }
212    
213    
214    
215    
216    
217     limline(a0, x, y, xout, yout, s) /* print line from/to out of bounds */
218    
219     int a0;
220     double x, y, xout, yout;
221     char *s;
222    
223     {
224    
225     for ( ; ; )
226     if (xout < xmin) {
227     yout = (yout - y)*(xmin - x)/(xout - x) + y;
228     xout = xmin;
229     } else if (yout < ymin) {
230     xout = (xout - x)*(ymin - y)/(yout - y) + x;
231     yout = ymin;
232     } else if (xout > xmax) {
233     yout = (yout - y)*(xmax - x)/(xout - x) + y;
234     xout = xmax;
235     } else if (yout > ymax) {
236     xout = (xout - x)*(ymax - y)/(yout - y) + x;
237     yout = ymax;
238     } else {
239     if (s != NULL)
240     symout(a0 & 03, XCONV(xout), YCONV(yout), s);
241     plseg(a0, XCONV(x), YCONV(y), XCONV(xout), YCONV(yout));
242     return;
243     }
244    
245     }