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.11 by greg, Thu Mar 24 18:48:28 2016 UTC vs.
Revision 1.16 by greg, Thu Mar 24 22:26:50 2022 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *      5/18/88
8   */
9  
10 #include  <stdio.h>
10   #include  <stdlib.h>
11   #include  <ctype.h>
12   #include  <math.h>
13   #include  "platform.h"
14 + #include  "rtio.h"
15  
16   #define  MAXCOL         8192            /* maximum number of columns */
17  
# Line 59 | Line 59 | char  *argv[]
59                                          func = MULT;
60                                          break;
61                                  case 's':
62                                        func = ADD;
62                                          power = atof(argv[a]+2);
63                                          break;
64                                  case 'u':
# Line 137 | Line 136 | char  *argv[]
136                                  }
137                  else
138                          break;
139 +        if ((power != 0.0) & (func != ADD)) {
140 +                fprintf(stderr, "%s: -sE option requires summation\n", argv[0]);
141 +                exit(1);
142 +        }
143          if (mean) {
144                  if (func == MAX) {
145                          fprintf(stderr, "%s: average maximum?!\n", argv[0]);
# Line 170 | Line 173 | getrecord(                     /* read next input record */
173          int   nf;
174                                                  /* reading binary input? */
175          if (nbicols > 0)
176 <                return(fread(field, sizeof(double), nbicols, fp));
176 >                return(getbinary(field, sizeof(double), nbicols, fp));
177          if (nbicols < 0) {
178                  float   *fbuf = (float *)buf;
179                  int     i;
180 <                nf = fread(fbuf, sizeof(float), -nbicols, fp);
180 >                nf = getbinary(fbuf, sizeof(float), -nbicols, fp);
181                  for (i = nf; i-- > 0; )
182                          field[i] = fbuf[i];
183                  return(nf);
# Line 211 | Line 214 | putrecord(                     /* write out results record */
214   {
215                                                  /* binary output? */
216          if (bocols > 0) {
217 <                fwrite(field, sizeof(double), n, fp);
217 >                putbinary(field, sizeof(double), n, fp);
218                  return;
219          }
220          if (bocols < 0) {
221                  float   fv;
222                  while (n-- > 0) {
223                          fv = *field++;
224 <                        fwrite(&fv, sizeof(float), 1, fp);
224 >                        putbinary(&fv, sizeof(float), 1, fp);
225                  }
226                  return;
227          }
# Line 228 | Line 231 | putrecord(                     /* write out results record */
231                  if (n) fputc(tabc, fp);
232          }
233          fputc('\n', fp);
234 +        if (!subtotal)
235 +                fflush(fp);                     /* flush unless -r */
236   }
237  
238  
# Line 280 | Line 285 | char  *fname
285                                  case ADD:
286                                          if (inpval[n] == 0.0)
287                                                  break;
288 <                                        if (power != 0.0)
284 <                                                tally[n] += pow(fabs(inpval[n]),power);
285 <                                        else
288 >                                        if (power == 0.0)
289                                                  tally[n] += inpval[n];
290 +                                        else if (power == 1.0)
291 +                                                tally[n] += fabs(inpval[n]);
292 +                                        else if (power == -1.0)
293 +                                                tally[n] += 1.0/fabs(inpval[n]);
294 +                                        else
295 +                                                tally[n] += pow(fabs(inpval[n]), power);
296                                          break;
297                                  case MULT:
298                                          if (inpval[n] == 0.0)
# Line 327 | Line 336 | char  *fname
336                          break;
337                  if (!subtotal)
338                          ltotal = 0;
339 +                if (incnt > 0 && nlin >= incnt)
340 +                        break;
341          }
342                                                          /* close input */
343 <        return(fclose(fp));
343 >        return(fclose(fp) == EOF ? 1 : 0);
344   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines