1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: tbar.c,v 1.2 2003/06/30 14:59:12 schorsch Exp $"; |
3 |
#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 |
|
13 |
#include "rtprocess.h" /* getpid() */ |
14 |
#include "tgraph.h" |
15 |
|
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 |
#ifdef CPM |
70 |
fixargs("tbar", &argc, &argv); |
71 |
#endif |
72 |
|
73 |
progname = *argv++; |
74 |
argc--; |
75 |
|
76 |
initialize(); |
77 |
|
78 |
for (; argc && (**argv == '-' || **argv == '+'); argc--, argv++) |
79 |
option(*argv); |
80 |
|
81 |
polar = FALSE; /* override stupid choices */ |
82 |
logx = FALSE; |
83 |
axflag = BOX|ORIGIN|YTICS|YNUMS; |
84 |
if (grid) |
85 |
axflag |= YGRID; |
86 |
|
87 |
if (argc) |
88 |
|
89 |
for ( ; argc--; argv++) { |
90 |
|
91 |
fp = efopen(*argv, "r"); |
92 |
normalize(fp, NULL); |
93 |
if (ymin > 0) |
94 |
ymin = 0; |
95 |
else if (ymax < 0) |
96 |
ymax = 0; |
97 |
xmax++; |
98 |
makeaxis(axflag); |
99 |
fseek(fp, 0L, 0); |
100 |
plot(fp); |
101 |
fclose(fp); |
102 |
} |
103 |
else { |
104 |
|
105 |
sprintf(tfname, "%stb%d", TDIR, getpid()); |
106 |
fp = efopen(tfname, "w+"); |
107 |
normalize(stdin, fp); |
108 |
if (ymin > 0) |
109 |
ymin = 0; |
110 |
else if (ymax < 0) |
111 |
ymax = 0; |
112 |
xmax++; |
113 |
makeaxis(axflag); |
114 |
fseek(fp, 0L, 0); |
115 |
plot(fp); |
116 |
fclose(fp); |
117 |
unlink(tfname); |
118 |
} |
119 |
|
120 |
pglob(PEOF, 0200, NULL); |
121 |
|
122 |
return(0); |
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 |
char line[255], *s; |
136 |
double x, y; |
137 |
|
138 |
xlegend = XLEGEND; |
139 |
ylegend = YLEGEND; |
140 |
|
141 |
if (ncurves > 0) { |
142 |
pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "Legend:"); |
143 |
pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "______"); |
144 |
} |
145 |
|
146 |
while (fgets(line, sizeof line, fp) != NULL) |
147 |
|
148 |
if (istitle(line)) { |
149 |
s = snagquo(line); |
150 |
boxstring(0, 0, YBEG+YSIZ+1000, XYSIZE-1, YBEG+YSIZ+1500, s); |
151 |
} |
152 |
|
153 |
else if (isdivlab(line)) { |
154 |
s = line; |
155 |
x = 1; |
156 |
while ((s = snagquo(s)) != NULL) { |
157 |
if (x >= xmin && x <= xmax) |
158 |
boxstring(0, XCONV(x), YBEG-750, XCONV(x+0.66), YBEG-400, s); |
159 |
s += strlen(s)+1; |
160 |
x++; |
161 |
} |
162 |
} |
163 |
|
164 |
else if (isxlabel(line)) { |
165 |
s = snagquo(line); |
166 |
boxstring(0, XBEG, YBEG-1250, XBEG+XSIZ, YBEG-900, s); |
167 |
} |
168 |
|
169 |
else if (isylabel(line)) { |
170 |
s = snagquo(line); |
171 |
boxstring(020, XBEG-1900, YBEG, XBEG-1550, YBEG+YSIZ, s); |
172 |
} |
173 |
|
174 |
else if (islabel(line)) { |
175 |
if (++ncur < NCUR && usecurve[ncur]) { |
176 |
boxout(curtype[ncur], xlegend-200, ylegend, xlegend+200, ylegend+250); |
177 |
pprim(PMSTR, 020, xlegend+400, ylegend+200, |
178 |
xlegend+400, ylegend+200, snagquo(line)); |
179 |
ylegend -= 500; |
180 |
} |
181 |
} |
182 |
|
183 |
else if (usecurve[ncur] && isdata(line)) { |
184 |
|
185 |
if (getdata(line, &x, &y) >= 0) |
186 |
barout(ncur, x, y); |
187 |
|
188 |
} |
189 |
|
190 |
pglob(PEOP, 0200, NULL); |
191 |
|
192 |
} |
193 |
|
194 |
|
195 |
|
196 |
barout(cn, x, y) /* output bar for curve cn, value (x,y) */ |
197 |
|
198 |
int cn; |
199 |
double x, y; |
200 |
|
201 |
{ |
202 |
int barleft, barwidth; |
203 |
int barlower, barheight; |
204 |
|
205 |
barwidth = XSIZ/xsize/(ncurves+1)*0.66; |
206 |
if (barwidth > MAXBAR) |
207 |
barwidth = MAXBAR; |
208 |
|
209 |
barleft = XCONV(x) + cn*barwidth; |
210 |
|
211 |
if (y < 0.0) { |
212 |
barlower = YCONV(y); |
213 |
barheight = YCONV(0.0) - barlower; |
214 |
} else { |
215 |
barlower = YCONV(0.0); |
216 |
barheight = YCONV(y) - barlower; |
217 |
} |
218 |
boxout(curtype[cn], barleft, barlower, |
219 |
barleft+barwidth, barlower+barheight); |
220 |
|
221 |
} |
222 |
|
223 |
|
224 |
|
225 |
boxout(a0, xmn, ymn, xmx, ymx) /* output a box */ |
226 |
|
227 |
int a0; |
228 |
int xmn, ymn, xmx, ymx; |
229 |
|
230 |
{ |
231 |
|
232 |
pprim(PRFILL, a0, xmn, ymn, xmx, ymx, NULL); |
233 |
plseg(0, xmn, ymn, xmx, ymn); |
234 |
plseg(0, xmn, ymn, xmn, ymx); |
235 |
plseg(0, xmn, ymx, xmx, ymx); |
236 |
plseg(0, xmx, ymn, xmx, ymx); |
237 |
|
238 |
} |