| 7 |
|
* 2/2/95 Greg Ward |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
– |
#include <stdio.h> |
| 10 |
|
#include <stdlib.h> |
| 11 |
|
#include <math.h> |
| 12 |
|
#include <ctype.h> |
| 13 |
|
|
| 14 |
+ |
#include "rtprocess.h" /* getpid() */ |
| 15 |
+ |
#include "rtmath.h" |
| 16 |
+ |
#include "rtio.h" |
| 17 |
+ |
|
| 18 |
|
#define isdelim(c) (isspace(c) || (c)==',') |
| 19 |
|
|
| 20 |
< |
#define MAXTAB 1024 /* maximum number of data rows */ |
| 21 |
< |
#define MAXLINE 4096 /* maximum line width (characters) */ |
| 19 |
< |
#define FLOAT float /* real type (precision) */ |
| 20 |
> |
#define MAXTAB 8192 /* maximum number of data rows */ |
| 21 |
> |
#define MAXLINE 16384 /* maximum line width (characters) */ |
| 22 |
|
#define OUTFMT "%.7g" /* output format conversion string */ |
| 23 |
|
|
| 24 |
|
int interpolate = 0; |
| 26 |
|
char **func; |
| 27 |
|
int nfuncs; |
| 28 |
|
|
| 29 |
< |
FLOAT abscissa[MAXTAB]; /* independent values (first column) */ |
| 30 |
< |
FLOAT (*ordinate)[MAXTAB]; /* dependent values (other columns) */ |
| 29 |
> |
RREAL abscissa[MAXTAB]; /* independent values (first column) */ |
| 30 |
> |
RREAL (*ordinate)[MAXTAB]; /* dependent values (other columns) */ |
| 31 |
|
int tabsize = 0; /* final table size (number of rows) */ |
| 32 |
|
char locID[16]; /* local identifier (for uniqueness) */ |
| 33 |
|
|
| 34 |
< |
extern char *fgets(), *fskip(), *absc_exp(); |
| 34 |
> |
/*extern char *fgets(), *fskip(), *absc_exp();*/ |
| 35 |
|
|
| 36 |
+ |
static void load_data(FILE *fp); |
| 37 |
+ |
static void print_funcs(char *xe); |
| 38 |
+ |
static void putlist(register RREAL *av, int al, register int pos); |
| 39 |
+ |
static char * absc_exp(void); |
| 40 |
|
|
| 41 |
< |
main(argc, argv) |
| 42 |
< |
int argc; |
| 43 |
< |
char **argv; |
| 41 |
> |
int |
| 42 |
> |
main( |
| 43 |
> |
int argc, |
| 44 |
> |
char **argv |
| 45 |
> |
) |
| 46 |
|
{ |
| 47 |
|
progname = argv[0]; |
| 48 |
|
argv++; |
| 60 |
|
} |
| 61 |
|
func = argv; |
| 62 |
|
nfuncs = argc; |
| 63 |
< |
ordinate = (FLOAT (*)[MAXTAB])malloc(nfuncs*MAXTAB*sizeof(FLOAT)); |
| 63 |
> |
ordinate = (RREAL (*)[MAXTAB])malloc(nfuncs*MAXTAB*sizeof(RREAL)); |
| 64 |
|
if (ordinate == NULL) { |
| 65 |
|
fprintf(stderr, "%s: not enough memory\n", progname); |
| 66 |
|
exit(1); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
< |
load_data(fp) /* load tabular data from fp */ |
| 76 |
< |
FILE *fp; |
| 75 |
> |
static void |
| 76 |
> |
load_data( /* load tabular data from fp */ |
| 77 |
> |
FILE *fp |
| 78 |
> |
) |
| 79 |
|
{ |
| 80 |
|
int lineno; |
| 81 |
|
char *err; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
< |
char * |
| 124 |
< |
absc_exp() /* produce expression for abscissa */ |
| 123 |
> |
static char * |
| 124 |
> |
absc_exp(void) /* produce expression for abscissa */ |
| 125 |
|
{ |
| 126 |
|
static char ourexp[64]; |
| 127 |
|
double step, eps; |
| 148 |
|
strcpy(ourexp, "x"); |
| 149 |
|
else |
| 150 |
|
sprintf(ourexp, "x-%g", abscissa[0]-1); |
| 151 |
< |
} else |
| 151 |
> |
} else if (fabs(abscissa[0]) < eps) |
| 152 |
> |
sprintf(ourexp, "x/%g+1", step); |
| 153 |
> |
else |
| 154 |
|
sprintf(ourexp, "(x-%g)/%g+1", abscissa[0], step); |
| 155 |
|
} else { |
| 156 |
|
printf("X`%s(i):select(i,", locID); |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
|
| 179 |
< |
print_funcs(xe) /* print functions */ |
| 180 |
< |
char *xe; |
| 179 |
> |
static void |
| 180 |
> |
print_funcs( /* print functions */ |
| 181 |
> |
char *xe |
| 182 |
> |
) |
| 183 |
|
{ |
| 184 |
|
int xelen; |
| 185 |
|
register int i; |
| 186 |
|
|
| 187 |
|
xelen = strlen(xe); |
| 188 |
|
for (i = 0; i < nfuncs; i++) { |
| 189 |
< |
if (func[i][0] == '\0' | func[i][0] == '0') |
| 189 |
> |
if ((func[i][0] == '\0') | (func[i][0] == '0')) |
| 190 |
|
continue; |
| 191 |
|
if (interpolate) { |
| 192 |
|
printf("%s`%s(i):select(i,", func[i], locID); |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
|
| 207 |
< |
putlist(av, al, pos) /* put out array of values */ |
| 208 |
< |
register FLOAT *av; |
| 209 |
< |
int al; |
| 210 |
< |
register int pos; |
| 207 |
> |
static void |
| 208 |
> |
putlist( /* put out array of values */ |
| 209 |
> |
register RREAL *av, |
| 210 |
> |
int al, |
| 211 |
> |
register int pos |
| 212 |
> |
) |
| 213 |
|
{ |
| 214 |
|
char obuf[32]; |
| 215 |
|
int len; |