| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: cgraph.c,v 1.1 2003/02/22 02:07:26 greg Exp $";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* cgraph.c - routines for sending graphs to tty's.
|
| 6 |
*
|
| 7 |
* Greg Ward
|
| 8 |
* 7/7/86
|
| 9 |
*/
|
| 10 |
|
| 11 |
|
| 12 |
#include <stdio.h>
|
| 13 |
|
| 14 |
#include "rterror.h"
|
| 15 |
#include "meta.h"
|
| 16 |
#include "mgvars.h"
|
| 17 |
|
| 18 |
|
| 19 |
#define FHUGE 1e10
|
| 20 |
|
| 21 |
#define MAXSIZE 10000 /* Maximum size in characters of output */
|
| 22 |
|
| 23 |
extern char *progname; /* argv[0] */
|
| 24 |
|
| 25 |
static char outcarr[MAXSIZE]; /* character output array */
|
| 26 |
|
| 27 |
static double xmin = XMAX, xmax = XMIN, /* extrema */
|
| 28 |
ymin = YMAX, ymax = YMIN;
|
| 29 |
|
| 30 |
static int dwidth, dlength; /* device width and length */
|
| 31 |
|
| 32 |
static int nplottable; /* number of plottable points */
|
| 33 |
|
| 34 |
static void climits(void);
|
| 35 |
static void cstretch(int c, double x, double y);
|
| 36 |
|
| 37 |
|
| 38 |
extern void
|
| 39 |
cgraph( /* do a character graph to stdout */
|
| 40 |
int width,
|
| 41 |
int length
|
| 42 |
)
|
| 43 |
{
|
| 44 |
if (width * length > MAXSIZE) {
|
| 45 |
fprintf(stderr, "%s: page too big\n", progname);
|
| 46 |
quit(1);
|
| 47 |
}
|
| 48 |
dwidth = width;
|
| 49 |
dlength = length;
|
| 50 |
climits(); /* get min & max values */
|
| 51 |
cplot(); /* do character plot */
|
| 52 |
}
|
| 53 |
|
| 54 |
|
| 55 |
static void
|
| 56 |
climits(void) /* get min & max values */
|
| 57 |
{
|
| 58 |
int i;
|
| 59 |
|
| 60 |
xmin = gparam[XMIN].flags & DEFINED ?
|
| 61 |
varvalue(gparam[XMIN].name) :
|
| 62 |
FHUGE ;
|
| 63 |
xmax = gparam[XMAX].flags & DEFINED ?
|
| 64 |
varvalue(gparam[XMAX].name) :
|
| 65 |
-FHUGE ;
|
| 66 |
ymin = gparam[YMIN].flags & DEFINED ?
|
| 67 |
varvalue(gparam[YMIN].name) :
|
| 68 |
FHUGE ;
|
| 69 |
ymax = gparam[YMAX].flags & DEFINED ?
|
| 70 |
varvalue(gparam[YMAX].name) :
|
| 71 |
-FHUGE ;
|
| 72 |
|
| 73 |
nplottable = 0;
|
| 74 |
for (i = 0; i < MAXCUR; i++)
|
| 75 |
mgcurve(i, cstretch);
|
| 76 |
|
| 77 |
if (nplottable == 0) {
|
| 78 |
fprintf(stderr, "%s: no plottable data\n", progname);
|
| 79 |
quit(1);
|
| 80 |
}
|
| 81 |
printf("XMIN= %f XMAX= %f YMIN= %f YMAX= %f\n",
|
| 82 |
xmin, xmax, ymin, ymax);
|
| 83 |
}
|
| 84 |
|
| 85 |
|
| 86 |
void
|
| 87 |
cstretch( /* stretch our boundaries */
|
| 88 |
int c,
|
| 89 |
double x,
|
| 90 |
double y
|
| 91 |
)
|
| 92 |
{
|
| 93 |
if (gparam[XMIN].flags & DEFINED &&
|
| 94 |
x < xmin)
|
| 95 |
return;
|
| 96 |
if (gparam[XMAX].flags & DEFINED &&
|
| 97 |
x > xmax)
|
| 98 |
return;
|
| 99 |
if (gparam[YMIN].flags & DEFINED &&
|
| 100 |
y < ymin)
|
| 101 |
return;
|
| 102 |
if (gparam[YMAX].flags & DEFINED &&
|
| 103 |
y > ymax)
|
| 104 |
return;
|
| 105 |
|
| 106 |
if (x < xmin)
|
| 107 |
xmin = x;
|
| 108 |
if (x > xmax)
|
| 109 |
xmax = x;
|
| 110 |
if (y < ymin)
|
| 111 |
ymin = y;
|
| 112 |
if (y > ymax)
|
| 113 |
ymax = y;
|
| 114 |
|
| 115 |
nplottable++;
|
| 116 |
}
|
| 117 |
|
| 118 |
|
| 119 |
extern void
|
| 120 |
cplot(void) /* do character plot */
|
| 121 |
{
|
| 122 |
int i, j;
|
| 123 |
register char *op;
|
| 124 |
|
| 125 |
for (op = outcarr+dlength*dwidth; op > outcarr; )
|
| 126 |
*--op = ' ';
|
| 127 |
|
| 128 |
for (i = 0; i < MAXCUR; i++)
|
| 129 |
mgcurve(i, cpoint);
|
| 130 |
|
| 131 |
for (i = 0; i < dlength; i++) {
|
| 132 |
for (j = 0; j < dwidth; j++)
|
| 133 |
putchar(*op++);
|
| 134 |
putchar('\n');
|
| 135 |
}
|
| 136 |
}
|
| 137 |
|
| 138 |
|
| 139 |
extern void
|
| 140 |
cpoint( /* store a point */
|
| 141 |
int c,
|
| 142 |
double x,
|
| 143 |
double y
|
| 144 |
)
|
| 145 |
{
|
| 146 |
register int ndx;
|
| 147 |
|
| 148 |
if (x < xmin || x > xmax || y < ymin || y > ymax)
|
| 149 |
return;
|
| 150 |
|
| 151 |
ndx = (dlength-1)*(1.0 - (y - ymin)/(ymax - ymin)) + 0.5;
|
| 152 |
ndx = dwidth*ndx + (dwidth-1)*(x-xmin)/(xmax-xmin) + 0.5;
|
| 153 |
|
| 154 |
if (outcarr[ndx] == ' ')
|
| 155 |
outcarr[ndx] = c+'A';
|
| 156 |
else if (outcarr[ndx] > '1' && outcarr[ndx] < '9')
|
| 157 |
outcarr[ndx]++;
|
| 158 |
else if (outcarr[ndx] == '9')
|
| 159 |
outcarr[ndx] = '*';
|
| 160 |
else if (outcarr[ndx] != '*')
|
| 161 |
outcarr[ndx] = '2';
|
| 162 |
}
|