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); |
157 |
|
putlist(abscissa, tabsize, 20); |
158 |
|
puts(");"); |
159 |
< |
if (increasing) { |
159 |
> |
if (increasing) |
160 |
> |
printf("fx2`%s(x,i):if(x-X`%s(i),\n", locID, locID); |
161 |
> |
else |
162 |
> |
printf("fx2`%s(x,i):if(X`%s(i)-x,\n", locID, locID); |
163 |
> |
printf("\ti+(x-X`%s(i))/(X`%s(i+1)-X`%s(i)),\n", |
164 |
> |
locID, locID, locID); |
165 |
> |
printf("\tfx2`%s(x,i-1));\n", locID); |
166 |
> |
if (increasing) |
167 |
|
printf("fx`%s(x):if(x-%g,if(%g-x,fx2`%s(x,%d),%d),1);\n", |
168 |
|
locID, abscissa[0], abscissa[tabsize-1], |
169 |
|
locID, tabsize, tabsize); |
170 |
< |
printf("fx2`%s(x,i):if(x-X`%s(i),\n", locID, locID); |
152 |
< |
} else { |
170 |
> |
else |
171 |
|
printf("fx`%s(x):if(%g-x,if(x-%g,fx2`%s(x,%d),%d),1);\n", |
172 |
|
locID, abscissa[0], abscissa[tabsize-1], |
173 |
|
locID, tabsize, tabsize); |
156 |
– |
printf("fx2`%s(x,i):if(X`%s(i)-x,\n", locID, locID); |
157 |
– |
} |
158 |
– |
printf("\ti+(x-X`%s(i))/(X`%s(i+1)-X`%s(i)),\n", |
159 |
– |
locID, locID, locID); |
160 |
– |
printf("\tfx2`%s(x,i-1));\n", locID); |
174 |
|
sprintf(ourexp, "fx`%s(x)", locID); |
175 |
|
} |
176 |
|
return(ourexp); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
< |
print_funcs(xe) /* print functions */ |
181 |
< |
char *xe; |
180 |
> |
static void |
181 |
> |
print_funcs( /* print functions */ |
182 |
> |
char *xe |
183 |
> |
) |
184 |
|
{ |
185 |
|
int xelen; |
186 |
|
register int i; |
187 |
|
|
188 |
|
xelen = strlen(xe); |
189 |
|
for (i = 0; i < nfuncs; i++) { |
190 |
< |
if (func[i][0] == '\0' | func[i][0] == '0') |
190 |
> |
if ((func[i][0] == '\0') | (func[i][0] == '0')) |
191 |
|
continue; |
192 |
|
if (interpolate) { |
193 |
|
printf("%s`%s(i):select(i,", func[i], locID); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
< |
putlist(av, al, pos) /* put out array of values */ |
209 |
< |
register FLOAT *av; |
210 |
< |
int al; |
211 |
< |
register int pos; |
208 |
> |
static void |
209 |
> |
putlist( /* put out array of values */ |
210 |
> |
register RREAL *av, |
211 |
> |
int al, |
212 |
> |
register int pos |
213 |
> |
) |
214 |
|
{ |
215 |
|
char obuf[32]; |
216 |
|
int len; |