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

Comparing ray/src/cal/rcalc.c (file contents):
Revision 1.12 by schorsch, Sun Mar 28 20:33:12 2004 UTC vs.
Revision 1.21 by greg, Sun Jun 14 00:33:16 2009 UTC

# Line 25 | Line 25 | static const char RCSid[] = "$Id$";
25  
26   #define  isblnk(c)      (igneol ? isspace(c) : (c)==' '||(c)=='\t')
27  
28 < #define  INBSIZ         4096    /* longest record */
28 > #define  INBSIZ         16384   /* longest record */
29   #define  MAXCOL         32      /* number of columns recorded */
30  
31                                  /* field type specifications */
# Line 78 | Line 78 | struct strvar  *svhead = NULL;  /* string variables */
78  
79   int  blnkeq = 1;                /* blanks compare equal? */
80   int  igneol = 0;                /* ignore end of line? */
81 + int  passive = 0;               /* passive mode (transmit unmatched input) */
82   char  sepchar = '\t';           /* input/output separator */
83   int  noinput = 0;               /* no input records? */
84 + int  itype = 'a';               /* input type (a/f/F/d/D) */
85   int  nbicols = 0;               /* number of binary input columns */
86 < int  bocols = 0;                /* produce binary output columns */
86 > int  otype = 'a';               /* output format (a/f/F/d/D) */
87   char  inpbuf[INBSIZ];           /* input buffer */
88   double  colval[MAXCOL];         /* input column values */
89   unsigned long  colflg = 0;      /* column retrieved flags */
# Line 124 | Line 126 | char  *argv[]
126                  case 'l':
127                          igneol = !igneol;
128                          break;
129 +                case 'p':
130 +                        passive = !passive;
131 +                        break;
132                  case 't':
133                          sepchar = argv[i][2];
134                          break;
# Line 142 | Line 147 | char  *argv[]
147                  case 'i':
148                          switch (argv[i][2]) {
149                          case '\0':
150 +                                itype = 'a';
151                                  nbicols = 0;
152                                  readfmt(argv[++i], 0);
153                                  break;
154                          case 'a':
155 +                                itype = 'a';
156                                  nbicols = 0;
157                                  break;
158                          case 'd':
159 +                        case 'D':
160 +                                itype = argv[i][2];
161                                  if (isdigit(argv[i][3]))
162                                          nbicols = atoi(argv[i]+3);
163                                  else
# Line 160 | Line 169 | char  *argv[]
169                                  }
170                                  break;
171                          case 'f':
172 +                        case 'F':
173 +                                itype = argv[i][2];
174                                  if (isdigit(argv[i][3]))
175 <                                        nbicols = -atoi(argv[i]+3);
175 >                                        nbicols = atoi(argv[i]+3);
176                                  else
177 <                                        nbicols = -1;
178 <                                if (-nbicols*sizeof(float) > INBSIZ) {
177 >                                        nbicols = 1;
178 >                                if (nbicols*sizeof(float) > INBSIZ) {
179                                          eputs(argv[0]);
180                                          eputs(": too many input columns\n");
181                                          quit(1);
# Line 177 | Line 188 | char  *argv[]
188                  case 'o':
189                          switch (argv[i][2]) {
190                          case '\0':
191 <                                bocols = 0;
191 >                                otype = 'a';
192                                  readfmt(argv[++i], 1);
193                                  break;
194                          case 'a':
195 <                                bocols = 0;
195 >                                otype = 'a';
196                                  break;
197                          case 'd':
198 <                                bocols = 1;
188 <                                break;
198 >                        case 'D':
199                          case 'f':
200 <                                bocols = -1;
200 >                        case 'F':
201 >                                otype = argv[i][2];
202                                  break;
203 +                        default:
204 +                                goto userr;
205                          }
206                          break;
207                  case 'w':
# Line 201 | Line 214 | char  *argv[]
214                  userr:
215                          eputs("Usage: ");
216                          eputs(argv[0]);
217 < eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
217 > eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
218                          quit(1);
219                  }
220 <
220 >        if (otype != 'a')
221 >                SET_FILE_BINARY(stdout);
222          if (noinput) {          /* produce a single output record */
223 +                if (i < argc) {
224 +                        eputs(argv[0]);
225 +                        eputs(": file argument(s) incompatible with -n\n");
226 +                        quit(1);
227 +                }
228                  eclock++;
229                  putout();
230                  quit(0);
231          }
232 +        if (itype != 'a')
233 +                SET_FILE_BINARY(stdin);
234  
235          if (blnkeq)             /* for efficiency */
236                  nbsynch();
# Line 244 | Line 265 | FILE  *fp
265   {
266          if (inpfmt != NULL)
267                  return(getrec());
268 <        if (nbicols > 0)
269 <                return(fread(inpbuf, sizeof(double),
270 <                                        nbicols, fp) == nbicols);
271 <        if (nbicols < 0)
272 <                return(fread(inpbuf, sizeof(float),
273 <                                        -nbicols, fp) == -nbicols);
268 >        if (tolower(itype) == 'd') {
269 >                if (fread(inpbuf, sizeof(double), nbicols, fp) != nbicols)
270 >                        return(0);
271 >                if (itype == 'D')
272 >                        swap64(inpbuf, nbicols);
273 >                return(1);
274 >        }
275 >        if (tolower(itype) == 'f') {
276 >                if (fread(inpbuf, sizeof(float), nbicols, fp) != nbicols)
277 >                        return(0);
278 >                if (itype == 'F')
279 >                        swap32(inpbuf, nbicols);
280 >                return(1);
281 >        }
282          return(fgets(inpbuf, INBSIZ, fp) != NULL);
283   }
284  
# Line 276 | Line 305 | char  *file
305          
306          while (getinputrec(fp)) {
307                  varset("recno", '=', (double)++nrecs);
308 +                varset("outno", '=', (double)(nout+1));
309                  colflg = 0;
310                  eclock++;
311                  if (!conditional || varvalue("cond") > 0.0) {
282                        varset("outno", '=', (double)++nout);
312                          putout();
313 +                        ++nout;
314                  }
315          }
316          fclose(fp);
# Line 294 | Line 324 | putout(void)                /* produce an output recor
324          colpos = 0;
325          if (outfmt != NULL)
326                  putrec();
327 <        else if (bocols)
298 <                chanout(bchanset);
299 <        else
327 >        else if (otype == 'a')
328                  chanout(chanset);
329 <        if (colpos && !bocols)
329 >        else
330 >                chanout(bchanset);
331 >        if (colpos && otype == 'a')
332                  putchar('\n');
333          if (unbuff)
334                  fflush(stdout);
# Line 317 | Line 347 | l_in(char *funame)     /* function call for $channel */
347                          /* determine number of channels */
348          if (noinput || inpfmt != NULL)
349                  return(0);
350 <        if (nbicols > 0)
350 >        if (nbicols)
351                  return(nbicols);
322        if (nbicols < 0)
323                return(-nbicols);
352          cp = inpbuf;    /* need to count */
353          for (n = 0; *cp; )
354                  if (blnkeq && isspace(sepchar)) {
# Line 353 | Line 381 | int  n
381                  eputs("illegal channel number\n");
382                  quit(1);
383          }
384 <        if (nbicols > 0) {
384 >        if (nbicols) {
385                  if (n > nbicols)
386                          return(0.0);
387 <                cp = inpbuf + (n-1)*sizeof(double);
388 <                return(*(double *)cp);
389 <        }
390 <        if (nbicols < 0) {
363 <                if (n > -nbicols)
364 <                        return(0.0);
387 >                if (tolower(itype) == 'd') {
388 >                        cp = inpbuf + (n-1)*sizeof(double);
389 >                        return(*(double *)cp);
390 >                }
391                  cp = inpbuf + (n-1)*sizeof(float);
392                  return(*(float *)cp);
393          }
# Line 413 | Line 439 | double  v
439   )
440   {
441          static char     zerobuf[sizeof(double)];
442 +        float   fval = v;
443  
444          while (++colpos < n)
445                  fwrite(zerobuf,
446 <                        bocols>0 ? sizeof(double) : sizeof(float),
446 >                        tolower(otype)=='d' ? sizeof(double) : sizeof(float),
447                          1, stdout);
448 <        if (bocols > 0)
448 >        switch (otype) {
449 >        case 'D':
450 >                swap64((char *)&v, 1);
451 >                /* fall through */
452 >        case 'd':
453                  fwrite(&v, sizeof(double), 1, stdout);
454 <        else {
455 <                float   fval = v;
454 >                break;
455 >        case 'F':
456 >                swap32((char *)&fval, 1);
457 >                /* fall through */
458 >        case 'f':
459                  fwrite(&fval, sizeof(float), 1, stdout);
460 +                break;
461          }
462   }
463  
# Line 450 | Line 485 | int  output
485                          eputs(": cannot open\n");
486                          quit(1);
487                  }
488 <                res = read(fd, inpbuf+1, INBSIZ-1);
488 >                res = read(fd, inpbuf+2, INBSIZ-2);
489                  if (res <= 0 || res >= INBSIZ-1) {
490                          eputs(spec);
491                          if (res < 0)
# Line 462 | Line 497 | int  output
497                          quit(1);
498                  }
499                  close(fd);
500 <                (inptr=inpbuf+1)[res] = '\0';
500 >                (inptr=inpbuf+2)[res] = '\0';
501          }
502          f = &fmt;                               /* get fields */
503          while ((res = readfield(&inptr)) != F_NUL) {
# Line 624 | Line 659 | clearrec(void)                 /* clear input record variables */
659  
660  
661   static int
662 < getrec(void)                                /* get next record from file */
662 > getrec(void)                            /* get next record from file */
663   {
664          int  eatline;
665          register struct field  *f;
666 <        
666 >
667          while (ipb.chr != EOF) {
668 <                eatline = !igneol && ipb.chr != '\n';
634 <                if (blnkeq)             /* beware of nbsynch() */
668 >                if (blnkeq) {           /* beware of nbsynch() */
669                          while (isblnk(ipb.chr))
670 <                                scaninp();
670 >                                resetinp();
671 >                        if (ipb.chr == EOF)
672 >                                return(0);
673 >                }
674 >                eatline = (!igneol && ipb.chr != '\n');
675                  clearrec();             /* start with fresh record */
676                  for (f = inpfmt; f != NULL; f = f->next)
677                          if (getfield(f) == -1)
678                                  break;
679                  if (f == NULL) {
680 <                        advinp();
680 >                        advinp();       /* got one! */
681                          return(1);
682                  }
683 <                resetinp();
683 >                resetinp();             /* eat false start */
684                  if (eatline) {          /* eat rest of line */
685                          while (ipb.chr != '\n') {
686                                  if (ipb.chr == EOF)
687                                          return(0);
688 <                                scaninp();
688 >                                resetinp();
689                          }
690 <                        scaninp();
653 <                        advinp();
690 >                        resetinp();
691                  }
692          }
693          return(0);
# Line 847 | Line 884 | resetinp(void)                      /* rewind position
884                  ipb.beg = ipb.end;
885          ipb.pos = ipb.beg;
886          ipb.chr = *ipb.pos;
887 +        if (passive)                    /* transmit unmatched character? */
888 +                fputc(ipb.chr, stdout);
889          if (++ipb.beg >= &inpbuf[INBSIZ])
890                  ipb.beg = inpbuf;
891          scaninp();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines