--- ray/src/cal/tabfunc.c 2003/02/22 02:07:20 1.1 +++ ray/src/cal/tabfunc.c 2020/06/29 21:25:36 1.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tabfunc.c,v 1.1 2003/02/22 02:07:20 greg Exp $"; +static const char RCSid[] = "$Id: tabfunc.c,v 1.9 2020/06/29 21:25:36 greg Exp $"; #endif /* * Put tabular data into functions suitable for cal programs. @@ -7,16 +7,18 @@ static const char RCSid[] = "$Id: tabfunc.c,v 1.1 2003 * 2/2/95 Greg Ward */ -#include #include #include #include +#include "rtprocess.h" /* getpid() */ +#include "rtmath.h" +#include "rtio.h" + #define isdelim(c) (isspace(c) || (c)==',') -#define MAXTAB 1024 /* maximum number of data rows */ -#define MAXLINE 4096 /* maximum line width (characters) */ -#define FLOAT float /* real type (precision) */ +#define MAXTAB 8192 /* maximum number of data rows */ +#define MAXLINE 16384 /* maximum line width (characters) */ #define OUTFMT "%.7g" /* output format conversion string */ int interpolate = 0; @@ -24,17 +26,23 @@ char *progname; char **func; int nfuncs; -FLOAT abscissa[MAXTAB]; /* independent values (first column) */ -FLOAT (*ordinate)[MAXTAB]; /* dependent values (other columns) */ +RREAL abscissa[MAXTAB]; /* independent values (first column) */ +RREAL (*ordinate)[MAXTAB]; /* dependent values (other columns) */ int tabsize = 0; /* final table size (number of rows) */ char locID[16]; /* local identifier (for uniqueness) */ -extern char *fgets(), *fskip(), *absc_exp(); +/*extern char *fgets(), *fskip(), *absc_exp();*/ +static void load_data(FILE *fp); +static void print_funcs(char *xe); +static void putlist(register RREAL *av, int al, register int pos); +static char * absc_exp(void); -main(argc, argv) -int argc; -char **argv; +int +main( +int argc, +char **argv +) { progname = argv[0]; argv++; @@ -52,7 +60,7 @@ char **argv; } func = argv; nfuncs = argc; - ordinate = (FLOAT (*)[MAXTAB])malloc(nfuncs*MAXTAB*sizeof(FLOAT)); + ordinate = (RREAL (*)[MAXTAB])malloc(nfuncs*MAXTAB*sizeof(RREAL)); if (ordinate == NULL) { fprintf(stderr, "%s: not enough memory\n", progname); exit(1); @@ -64,8 +72,10 @@ char **argv; } -load_data(fp) /* load tabular data from fp */ -FILE *fp; +static void +load_data( /* load tabular data from fp */ +FILE *fp +) { int lineno; char *err; @@ -110,8 +120,8 @@ fatal: } -char * -absc_exp() /* produce expression for abscissa */ +static char * +absc_exp(void) /* produce expression for abscissa */ { static char ourexp[64]; double step, eps; @@ -138,22 +148,24 @@ absc_exp() /* produce expression for abscissa */ strcpy(ourexp, "x"); else sprintf(ourexp, "x-%g", abscissa[0]-1); - } else + } else if (fabs(abscissa[0]) < eps) + sprintf(ourexp, "x/%g+1", step); + else sprintf(ourexp, "(x-%g)/%g+1", abscissa[0], step); } else { printf("X`%s(i):select(i,", locID); putlist(abscissa, tabsize, 20); puts(");"); if (increasing) { + printf("fx2`%s(x,i):if(x-X`%s(i),\n", locID, locID); printf("fx`%s(x):if(x-%g,if(%g-x,fx2`%s(x,%d),%d),1);\n", locID, abscissa[0], abscissa[tabsize-1], locID, tabsize, tabsize); - printf("fx2`%s(x,i):if(x-X`%s(i),\n", locID, locID); } else { + printf("fx2`%s(x,i):if(X`%s(i)-x,\n", locID, locID); printf("fx`%s(x):if(%g-x,if(x-%g,fx2`%s(x,%d),%d),1);\n", locID, abscissa[0], abscissa[tabsize-1], locID, tabsize, tabsize); - printf("fx2`%s(x,i):if(X`%s(i)-x,\n", locID, locID); } printf("\ti+(x-X`%s(i))/(X`%s(i+1)-X`%s(i)),\n", locID, locID, locID); @@ -164,15 +176,17 @@ absc_exp() /* produce expression for abscissa */ } -print_funcs(xe) /* print functions */ -char *xe; +static void +print_funcs( /* print functions */ +char *xe +) { int xelen; register int i; xelen = strlen(xe); for (i = 0; i < nfuncs; i++) { - if (func[i][0] == '\0' | func[i][0] == '0') + if ((func[i][0] == '\0') | (func[i][0] == '0')) continue; if (interpolate) { printf("%s`%s(i):select(i,", func[i], locID); @@ -190,10 +204,12 @@ char *xe; } -putlist(av, al, pos) /* put out array of values */ -register FLOAT *av; -int al; -register int pos; +static void +putlist( /* put out array of values */ +register RREAL *av, +int al, +register int pos +) { char obuf[32]; int len;