| 1 |
#ifndef lint |
| 2 |
static const char RCSid[] = "$Id: tscat.c,v 1.4 2003/11/15 02:13:37 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 ../tscat tscat.c tgraph.o primout.o mfio.o syscalls.o misc.o -lm |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "tgraph.h" |
| 14 |
#include "paths.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 plots */ |
| 33 |
|
| 34 |
short grid = FALSE; /* flag for grid */ |
| 35 |
|
| 36 |
char *sym[NCUR] = {"ex", "triangle", "square", "triangle2", "diamond", |
| 37 |
"cross", "octagon", "crosssquare", "exsquare", |
| 38 |
"trianglesquare", "triangle2square", "crossdiamond", |
| 39 |
"crossoctagon", "exoctagon", "block", "bullet"}; |
| 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 |
int |
| 53 |
main( |
| 54 |
int argc, |
| 55 |
char **argv |
| 56 |
) |
| 57 |
/* |
| 58 |
* Take Tel-A-Graf runnable files and convert them to |
| 59 |
* metafile primitives to send to standard output |
| 60 |
*/ |
| 61 |
|
| 62 |
{ |
| 63 |
char tfname[MAXFNAME]; |
| 64 |
FILE *fp; |
| 65 |
int axflag; |
| 66 |
|
| 67 |
progname = *argv++; |
| 68 |
argc--; |
| 69 |
|
| 70 |
initialize(); |
| 71 |
|
| 72 |
for (; argc && (**argv == '-' || **argv == '+'); argc--, argv++) |
| 73 |
option(*argv); |
| 74 |
|
| 75 |
if (polar) /* avoid dumb choices */ |
| 76 |
logx = FALSE; |
| 77 |
|
| 78 |
axflag = XTICS|XNUMS|YTICS|YNUMS; |
| 79 |
if (grid) |
| 80 |
axflag |= XGRID|YGRID; |
| 81 |
if (polar) |
| 82 |
axflag |= ORIGIN; |
| 83 |
else |
| 84 |
axflag |= BOX; |
| 85 |
|
| 86 |
pglob(PINCL, 2, "symbols.mta"); |
| 87 |
|
| 88 |
if (argc) |
| 89 |
|
| 90 |
for ( ; argc--; argv++) { |
| 91 |
|
| 92 |
fp = efopen(*argv, "r"); |
| 93 |
normalize(fp, NULL); |
| 94 |
makeaxis(axflag); |
| 95 |
fseek(fp, 0L, 0); |
| 96 |
plot(fp); |
| 97 |
fclose(fp); |
| 98 |
} |
| 99 |
else { |
| 100 |
|
| 101 |
/*sprintf(tfname, "%sts%d", TDIR, getpid());*/ |
| 102 |
temp_filename(tfname, sizeof(tfname), NULL); |
| 103 |
fp = efopen(tfname, "w+"); |
| 104 |
normalize(stdin, fp); |
| 105 |
makeaxis(axflag); |
| 106 |
fseek(fp, 0L, 0); |
| 107 |
plot(fp); |
| 108 |
fclose(fp); |
| 109 |
unlink(tfname); |
| 110 |
} |
| 111 |
|
| 112 |
pglob(PEOF, 0200, NULL); |
| 113 |
|
| 114 |
return(0); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
void |
| 121 |
plot( /* read file and generate plot */ |
| 122 |
FILE *fp |
| 123 |
) |
| 124 |
{ |
| 125 |
int ncur = 0; /* curves seen so far */ |
| 126 |
char line[255], *s; |
| 127 |
double x, y; |
| 128 |
|
| 129 |
xlegend = XLEGEND; |
| 130 |
ylegend = YLEGEND; |
| 131 |
|
| 132 |
if (ncurves > 0) { |
| 133 |
pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "Legend:"); |
| 134 |
pprim(PMSTR, 0100, xlegend, ylegend+800, xlegend, ylegend+800, "______"); |
| 135 |
} |
| 136 |
|
| 137 |
while (fgets(line, sizeof line, fp) != NULL) |
| 138 |
|
| 139 |
if (istitle(line)) { |
| 140 |
s = snagquo(line); |
| 141 |
boxstring(0, 0, YBEG+YSIZ+1000, XYSIZE-1, YBEG+YSIZ+1500, s); |
| 142 |
} |
| 143 |
|
| 144 |
else if (isxlabel(line)) { |
| 145 |
s = snagquo(line); |
| 146 |
boxstring(0, XBEG, YBEG-1250, XBEG+XSIZ, YBEG-900, s); |
| 147 |
} |
| 148 |
|
| 149 |
else if (isylabel(line)) { |
| 150 |
s = snagquo(line); |
| 151 |
boxstring(020, XBEG-1900, YBEG, XBEG-1550, YBEG+YSIZ, s); |
| 152 |
} |
| 153 |
|
| 154 |
else if (islabel(line)) { |
| 155 |
if (++ncur < NCUR && usecurve[ncur]) { |
| 156 |
symout(0, xlegend, ylegend+symrad, sym[ncur]); |
| 157 |
pprim(PMSTR, 020, xlegend+400, ylegend+200, |
| 158 |
xlegend+400, ylegend+200, snagquo(line)); |
| 159 |
ylegend -= 500; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
else if (usecurve[ncur] && isdata(line)) { |
| 164 |
|
| 165 |
if (getdata(line, &x, &y) >= 0) |
| 166 |
symout(0, XCONV(x), YCONV(y), sym[ncur]); |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
pglob(PEOP, 0200, NULL); |
| 171 |
|
| 172 |
} |
| 173 |
|