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