| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
|
|
static const char RCSid[] = "$Id$"; |
| 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 "tgraph.h" |
| 14 |
|
|
|
| 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 |
|
|
#define MAXBAR 1000 /* maximum bar width */ |
| 21 |
|
|
|
| 22 |
|
|
short usecurve[NCUR]; /* booleans for curve usage */ |
| 23 |
|
|
|
| 24 |
|
|
double xmin, ymin, xmax, ymax; /* domain */ |
| 25 |
|
|
|
| 26 |
|
|
double xsize, ysize; /* axis dimensions */ |
| 27 |
|
|
|
| 28 |
|
|
double xmnset = -FHUGE, xmxset = FHUGE, /* domain settings */ |
| 29 |
|
|
ymnset = -FHUGE, ymxset = FHUGE; |
| 30 |
|
|
|
| 31 |
|
|
short logx = FALSE, logy = FALSE; /* flags for log plots */ |
| 32 |
|
|
|
| 33 |
|
|
short polar = FALSE; /* flag for polar plots */ |
| 34 |
|
|
|
| 35 |
|
|
short grid = FALSE; /* flag for grid */ |
| 36 |
|
|
|
| 37 |
|
|
int curtype[NCUR] = {0, 04, 010, 014, 01, 05, 011, 015, |
| 38 |
|
|
02, 06, 012, 016, 03, 07, 013, 017}; |
| 39 |
|
|
|
| 40 |
|
|
int ncurves; |
| 41 |
|
|
|
| 42 |
|
|
int xlegend, |
| 43 |
|
|
ylegend; /* current legend position */ |
| 44 |
|
|
|
| 45 |
|
|
int symrad = SYMRAD; /* symbol radius */ |
| 46 |
|
|
|
| 47 |
|
|
char *progname; |
| 48 |
|
|
|
| 49 |
|
|
|
| 50 |
|
|
|
| 51 |
|
|
|
| 52 |
|
|
|
| 53 |
|
|
main(argc, argv) |
| 54 |
|
|
|
| 55 |
|
|
int argc; |
| 56 |
|
|
char **argv; |
| 57 |
|
|
|
| 58 |
|
|
/* |
| 59 |
|
|
* Take Tel-A-Graf runnable files and convert them to |
| 60 |
|
|
* metafile primitives to send to standard output |
| 61 |
|
|
*/ |
| 62 |
|
|
|
| 63 |
|
|
{ |
| 64 |
|
|
char tfname[MAXFNAME]; |
| 65 |
|
|
FILE *fp; |
| 66 |
|
|
int axflag; |
| 67 |
|
|
|
| 68 |
|
|
#ifdef CPM |
| 69 |
|
|
fixargs("tbar", &argc, &argv); |
| 70 |
|
|
#endif |
| 71 |
|
|
|
| 72 |
|
|
progname = *argv++; |
| 73 |
|
|
argc--; |
| 74 |
|
|
|
| 75 |
|
|
initialize(); |
| 76 |
|
|
|
| 77 |
|
|
for (; argc && (**argv == '-' || **argv == '+'); argc--, argv++) |
| 78 |
|
|
option(*argv); |
| 79 |
|
|
|
| 80 |
|
|
polar = FALSE; /* override stupid choices */ |
| 81 |
|
|
logx = FALSE; |
| 82 |
|
|
axflag = BOX|ORIGIN|YTICS|YNUMS; |
| 83 |
|
|
if (grid) |
| 84 |
|
|
axflag |= YGRID; |
| 85 |
|
|
|
| 86 |
|
|
if (argc) |
| 87 |
|
|
|
| 88 |
|
|
for ( ; argc--; argv++) { |
| 89 |
|
|
|
| 90 |
|
|
fp = efopen(*argv, "r"); |
| 91 |
|
|
normalize(fp, NULL); |
| 92 |
|
|
if (ymin > 0) |
| 93 |
|
|
ymin = 0; |
| 94 |
|
|
else if (ymax < 0) |
| 95 |
|
|
ymax = 0; |
| 96 |
|
|
xmax++; |
| 97 |
|
|
makeaxis(axflag); |
| 98 |
|
|
fseek(fp, 0L, 0); |
| 99 |
|
|
plot(fp); |
| 100 |
|
|
fclose(fp); |
| 101 |
|
|
} |
| 102 |
|
|
else { |
| 103 |
|
|
|
| 104 |
|
|
sprintf(tfname, "%stb%d", TDIR, getpid()); |
| 105 |
|
|
fp = efopen(tfname, "w+"); |
| 106 |
|
|
normalize(stdin, fp); |
| 107 |
|
|
if (ymin > 0) |
| 108 |
|
|
ymin = 0; |
| 109 |
|
|
else if (ymax < 0) |
| 110 |
|
|
ymax = 0; |
| 111 |
|
|
xmax++; |
| 112 |
|
|
makeaxis(axflag); |
| 113 |
|
|
fseek(fp, 0L, 0); |
| 114 |
|
|
plot(fp); |
| 115 |
|
|
fclose(fp); |
| 116 |
|
|
unlink(tfname); |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
pglob(PEOF, 0200, NULL); |
| 120 |
|
|
|
| 121 |
|
|
return(0); |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
|
|
|
| 125 |
|
|
|
| 126 |
|
|
|
| 127 |
|
|
|
| 128 |
|
|
plot(fp) /* read file and generate plot */ |
| 129 |
|
|
|
| 130 |
|
|
FILE *fp; |
| 131 |
|
|
|
| 132 |
|
|
{ |
| 133 |
|
|
int ncur = 0; /* curves seen so far */ |
| 134 |
|
|
char line[255], *s; |
| 135 |
|
|
double x, y; |
| 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 (isdivlab(line)) { |
| 153 |
|
|
s = line; |
| 154 |
|
|
x = 1; |
| 155 |
|
|
while ((s = snagquo(s)) != NULL) { |
| 156 |
|
|
if (x >= xmin && x <= xmax) |
| 157 |
|
|
boxstring(0, XCONV(x), YBEG-750, XCONV(x+0.66), YBEG-400, s); |
| 158 |
|
|
s += strlen(s)+1; |
| 159 |
|
|
x++; |
| 160 |
|
|
} |
| 161 |
|
|
} |
| 162 |
|
|
|
| 163 |
|
|
else if (isxlabel(line)) { |
| 164 |
|
|
s = snagquo(line); |
| 165 |
|
|
boxstring(0, XBEG, YBEG-1250, XBEG+XSIZ, YBEG-900, s); |
| 166 |
|
|
} |
| 167 |
|
|
|
| 168 |
|
|
else if (isylabel(line)) { |
| 169 |
|
|
s = snagquo(line); |
| 170 |
|
|
boxstring(020, XBEG-1900, YBEG, XBEG-1550, YBEG+YSIZ, s); |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
else if (islabel(line)) { |
| 174 |
|
|
if (++ncur < NCUR && usecurve[ncur]) { |
| 175 |
|
|
boxout(curtype[ncur], xlegend-200, ylegend, xlegend+200, ylegend+250); |
| 176 |
|
|
pprim(PMSTR, 020, xlegend+400, ylegend+200, |
| 177 |
|
|
xlegend+400, ylegend+200, snagquo(line)); |
| 178 |
|
|
ylegend -= 500; |
| 179 |
|
|
} |
| 180 |
|
|
} |
| 181 |
|
|
|
| 182 |
|
|
else if (usecurve[ncur] && isdata(line)) { |
| 183 |
|
|
|
| 184 |
|
|
if (getdata(line, &x, &y) >= 0) |
| 185 |
|
|
barout(ncur, x, y); |
| 186 |
|
|
|
| 187 |
|
|
} |
| 188 |
|
|
|
| 189 |
|
|
pglob(PEOP, 0200, NULL); |
| 190 |
|
|
|
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
|
| 194 |
|
|
|
| 195 |
|
|
barout(cn, x, y) /* output bar for curve cn, value (x,y) */ |
| 196 |
|
|
|
| 197 |
|
|
int cn; |
| 198 |
|
|
double x, y; |
| 199 |
|
|
|
| 200 |
|
|
{ |
| 201 |
|
|
int barleft, barwidth; |
| 202 |
|
|
int barlower, barheight; |
| 203 |
|
|
|
| 204 |
|
|
barwidth = XSIZ/xsize/(ncurves+1)*0.66; |
| 205 |
|
|
if (barwidth > MAXBAR) |
| 206 |
|
|
barwidth = MAXBAR; |
| 207 |
|
|
|
| 208 |
|
|
barleft = XCONV(x) + cn*barwidth; |
| 209 |
|
|
|
| 210 |
|
|
if (y < 0.0) { |
| 211 |
|
|
barlower = YCONV(y); |
| 212 |
|
|
barheight = YCONV(0.0) - barlower; |
| 213 |
|
|
} else { |
| 214 |
|
|
barlower = YCONV(0.0); |
| 215 |
|
|
barheight = YCONV(y) - barlower; |
| 216 |
|
|
} |
| 217 |
|
|
boxout(curtype[cn], barleft, barlower, |
| 218 |
|
|
barleft+barwidth, barlower+barheight); |
| 219 |
|
|
|
| 220 |
|
|
} |
| 221 |
|
|
|
| 222 |
|
|
|
| 223 |
|
|
|
| 224 |
|
|
boxout(a0, xmn, ymn, xmx, ymx) /* output a box */ |
| 225 |
|
|
|
| 226 |
|
|
int a0; |
| 227 |
|
|
int xmn, ymn, xmx, ymx; |
| 228 |
|
|
|
| 229 |
|
|
{ |
| 230 |
|
|
|
| 231 |
|
|
pprim(PRFILL, a0, xmn, ymn, xmx, ymx, NULL); |
| 232 |
|
|
plseg(0, xmn, ymn, xmx, ymn); |
| 233 |
|
|
plseg(0, xmn, ymn, xmn, ymx); |
| 234 |
|
|
plseg(0, xmn, ymx, xmx, ymx); |
| 235 |
|
|
plseg(0, xmx, ymn, xmx, ymx); |
| 236 |
|
|
|
| 237 |
|
|
} |