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.9 by greg, Sun Mar 9 20:07:27 2014 UTC vs.
Revision 1.13 by greg, Thu Aug 18 00:52:47 2016 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
12   #include  <ctype.h>
13   #include  <math.h>
14   #include  "platform.h"
15 + #include  "rtio.h"
16  
17   #define  MAXCOL         8192            /* maximum number of columns */
18  
# Line 22 | Line 23 | static const char      RCSid[] = "$Id$";
23  
24   double  init_val[] = {0., 1., -1e12, 1e12};     /* initial values */
25  
26 + long  incnt = 0;                        /* limit number of input records? */
27 + long  outcnt = 0;                       /* limit number of output records? */
28 +
29   int  func = ADD;                        /* default function */
30   double  power = 0.0;                    /* power for sum */
31   int  mean = 0;                          /* compute mean */
# Line 30 | Line 34 | int  nbicols = 0;                      /* number of binary input columns
34   int  bocols = 0;                        /* produce binary output columns */
35   int  tabc = '\t';                       /* default separator */
36   int  subtotal = 0;                      /* produce subtotals? */
37 + int  nrecsout = 0;                      /* number of records produced */
38  
39   static int execute(char *fname);
40  
# Line 72 | Line 77 | char  *argv[]
77                                          break;
78                                  case 'i':
79                                          switch (argv[a][2]) {
80 +                                        case 'n':
81 +                                                incnt = atol(argv[++a]);
82 +                                                break;
83                                          case 'a':
84                                                  nbicols = 0;
85                                                  break;
# Line 105 | Line 113 | char  *argv[]
113                                          break;
114                                  case 'o':
115                                          switch (argv[a][2]) {
116 +                                        case 'n':
117 +                                                outcnt = atol(argv[++a]);
118 +                                                break;
119                                          case 'a':
120                                                  bocols = 0;
121                                                  break;
# Line 143 | Line 154 | char  *argv[]
154          if (a >= argc)
155                  status = execute(NULL) == -1 ? 1 : status;
156          else
157 <                for ( ; a < argc; a++)
157 >                for ( ; a < argc && (outcnt <= 0 || nrecsout < outcnt); a++)
158                          status = execute(argv[a]) == -1 ? 2 : status;
159          exit(status);
160   }
# Line 160 | Line 171 | getrecord(                     /* read next input record */
171          int   nf;
172                                                  /* reading binary input? */
173          if (nbicols > 0)
174 <                return(fread(field, sizeof(double), nbicols, fp));
174 >                return(getbinary(field, sizeof(double), nbicols, fp));
175          if (nbicols < 0) {
176                  float   *fbuf = (float *)buf;
177                  int     i;
178 <                nf = fread(fbuf, sizeof(float), -nbicols, fp);
178 >                nf = getbinary(fbuf, sizeof(float), -nbicols, fp);
179                  for (i = nf; i-- > 0; )
180                          field[i] = fbuf[i];
181                  return(nf);
# Line 201 | Line 212 | putrecord(                     /* write out results record */
212   {
213                                                  /* binary output? */
214          if (bocols > 0) {
215 <                fwrite(field, sizeof(double), n, fp);
215 >                putbinary(field, sizeof(double), n, fp);
216                  return;
217          }
218          if (bocols < 0) {
219                  float   fv;
220                  while (n-- > 0) {
221                          fv = *field++;
222 <                        fwrite(&fv, sizeof(float), 1, fp);
222 >                        putbinary(&fv, sizeof(float), 1, fp);
223                  }
224                  return;
225          }
226                                                  /* ASCII output */
227 <        while (n-- > 0)
228 <                fprintf(fp, "%.9g%c", *field++, tabc);
227 >        while (n-- > 0) {
228 >                fprintf(fp, "%.9g", *field++);
229 >                if (n) fputc(tabc, fp);
230 >        }
231          fputc('\n', fp);
232   }
233  
# Line 259 | Line 272 | char  *fname
272                  }
273                  ncol = 0;
274                  for (nlin = 0; (count <= 0 || nlin < count) &&
275 +                                (incnt <= 0 || nlin < incnt) &&
276                                  (nread = getrecord(inpval, fp)) > 0;
277                                  nlin++) {
278                                                          /* compute */
# Line 309 | Line 323 | char  *fname
323                                  result[n] = rsign[n] * exp(result[n]);
324                  }
325                  putrecord(result, ncol, stdout);
326 +                ++nrecsout;
327 +                if (outcnt > 0 && nrecsout >= outcnt)
328 +                        break;
329                  if (!subtotal)
330                          ltotal = 0;
331 +                if (incnt > 0 && nlin >= incnt)
332 +                        break;
333          }
334                                                          /* close input */
335          return(fclose(fp));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines