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