--- ray/src/cal/total.c 2005/06/02 04:47:27 1.4 +++ ray/src/cal/total.c 2013/06/07 18:49:30 1.8 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: total.c,v 1.4 2005/06/02 04:47:27 greg Exp $"; +static const char RCSid[] = "$Id: total.c,v 1.8 2013/06/07 18:49:30 greg Exp $"; #endif /* * total.c - program to reduce columns of data. @@ -13,7 +13,7 @@ static const char RCSid[] = "$Id: total.c,v 1.4 2005/0 #include #include "platform.h" -#define MAXCOL 256 /* maximum number of columns */ +#define MAXCOL 8192 /* maximum number of columns */ #define ADD 0 /* add numbers */ #define MULT 1 /* multiply numbers */ @@ -226,8 +226,9 @@ char *fname { double inpval[MAXCOL]; double tally[MAXCOL]; + short rsign[MAXCOL]; double result[MAXCOL]; - register int n; + int n; int nread, ncol; long nlin, ltotal; FILE *fp; @@ -244,8 +245,10 @@ char *fname while (!feof(fp)) { if (ltotal == 0) { /* initialize */ if (func == MULT) /* special case */ - for (n = 0; n < MAXCOL; n++) + for (n = 0; n < MAXCOL; n++) { tally[n] = 0.0; + rsign[n] = 1; + } else for (n = 0; n < MAXCOL; n++) tally[n] = init_val[func]; @@ -267,8 +270,13 @@ char *fname break; case MULT: if (inpval[n] == 0.0) - break; - tally[n] += log(fabs(inpval[n])); + rsign[n] = 0; + else if (inpval[n] < 0.0) { + rsign[n] = -rsign[n]; + inpval[n] = -inpval[n]; + } + if (rsign[n]) + tally[n] += log(inpval[n]); break; case MAX: if (inpval[n] > tally[n]) @@ -294,7 +302,7 @@ char *fname result[n] = pow(result[n], 1.0/power); } if (func == MULT) - result[n] = exp(tally[n]); + result[n] = rsign[n] * exp(result[n]); } putrecord(result, ncol, stdout); if (!subtotal)