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