ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/total.c
(Generate patch)

Comparing ray/src/cal/total.c (file contents):
Revision 1.5 by greg, Sat Oct 8 04:18:16 2005 UTC vs.
Revision 1.10 by greg, Tue Mar 25 05:36:22 2014 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13   #include  <math.h>
14   #include  "platform.h"
15  
16 < #define  MAXCOL         256             /* maximum number of columns */
16 > #define  MAXCOL         8192            /* maximum number of columns */
17  
18   #define  ADD            0               /* add numbers */
19   #define  MULT           1               /* multiply numbers */
# Line 213 | Line 213 | putrecord(                     /* write out results record */
213                  return;
214          }
215                                                  /* ASCII output */
216 <        while (n-- > 0)
217 <                fprintf(fp, "%.9g%c", *field++, tabc);
216 >        while (n-- > 0) {
217 >                fprintf(fp, "%.9g", *field++);
218 >                if (n) fputc(tabc, fp);
219 >        }
220          fputc('\n', fp);
221   }
222  
# Line 226 | Line 228 | char  *fname
228   {
229          double  inpval[MAXCOL];
230          double  tally[MAXCOL];
231 +        short   rsign[MAXCOL];
232          double  result[MAXCOL];
233 <        register int  n;
233 >        int  n;
234          int  nread, ncol;
235          long  nlin, ltotal;
236          FILE  *fp;
# Line 240 | Line 243 | char  *fname
243          }
244          if (nbicols)
245                  SET_FILE_BINARY(fp);
246 + #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
247 +        flockfile(fp);
248 + #endif
249 +
250          ltotal = 0;
251          while (!feof(fp)) {
252                  if (ltotal == 0) {                      /* initialize */
253                          if (func == MULT)       /* special case */
254 <                                for (n = 0; n < MAXCOL; n++)
254 >                                for (n = 0; n < MAXCOL; n++) {
255                                          tally[n] = 0.0;
256 +                                        rsign[n] = 1;
257 +                                }
258                          else
259                                  for (n = 0; n < MAXCOL; n++)
260                                          tally[n] = init_val[func];
# Line 267 | Line 276 | char  *fname
276                                          break;
277                                  case MULT:
278                                          if (inpval[n] == 0.0)
279 <                                                break;
280 <                                        tally[n] += log(fabs(inpval[n]));
279 >                                                rsign[n] = 0;
280 >                                        else if (inpval[n] < 0.0) {
281 >                                                rsign[n] = -rsign[n];
282 >                                                inpval[n] = -inpval[n];
283 >                                        }
284 >                                        if (rsign[n])
285 >                                                tally[n] += log(inpval[n]);
286                                          break;
287                                  case MAX:
288                                          if (inpval[n] > tally[n])
# Line 294 | Line 308 | char  *fname
308                                          result[n] = pow(result[n], 1.0/power);
309                          }
310                          if (func == MULT)
311 <                                result[n] = exp(result[n]);
311 >                                result[n] = rsign[n] * exp(result[n]);
312                  }
313                  putrecord(result, ncol, stdout);
314                  if (!subtotal)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines