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.19 by greg, Tue Jun 14 01:25:02 2005 UTC vs.
Revision 1.22 by greg, Thu Dec 19 16:38:12 2013 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   */
9  
10   #include  <stdlib.h>
11 #include  <fcntl.h>
12 #include  <stdio.h>
13 #include  <string.h>
11   #include  <math.h>
12   #include  <ctype.h>
13  
# Line 81 | Line 78 | int  igneol = 0;                /* ignore end of line?
78   int  passive = 0;               /* passive mode (transmit unmatched input) */
79   char  sepchar = '\t';           /* input/output separator */
80   int  noinput = 0;               /* no input records? */
81 + int  itype = 'a';               /* input type (a/f/F/d/D) */
82   int  nbicols = 0;               /* number of binary input columns */
83 < int  bocols = 0;                /* produce binary output columns */
83 > int  otype = 'a';               /* output format (a/f/F/d/D) */
84   char  inpbuf[INBSIZ];           /* input buffer */
85   double  colval[MAXCOL];         /* input column values */
86   unsigned long  colflg = 0;      /* column retrieved flags */
# Line 106 | Line 104 | int  argc,
104   char  *argv[]
105   )
106   {
107 +        char  *fpath;
108          int  i;
109  
110          esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_OUTCHAN|E_RCONST;
# Line 135 | Line 134 | char  *argv[]
134                          svpreset(argv[++i]);
135                          break;
136                  case 'f':
137 <                        fcompile(argv[++i]);
137 >                        fpath = getpath(argv[++i], getrlibpath(), 0);
138 >                        if (fpath == NULL) {
139 >                                eputs(argv[0]);
140 >                                eputs(": cannot find file '");
141 >                                eputs(argv[i]);
142 >                                eputs("'\n");
143 >                                quit(1);
144 >                        }
145 >                        fcompile(fpath);
146                          break;
147                  case 'e':
148                          scompile(argv[++i], NULL, 0);
# Line 146 | Line 153 | char  *argv[]
153                  case 'i':
154                          switch (argv[i][2]) {
155                          case '\0':
156 +                                itype = 'a';
157                                  nbicols = 0;
158                                  readfmt(argv[++i], 0);
159                                  break;
160                          case 'a':
161 +                                itype = 'a';
162                                  nbicols = 0;
163                                  break;
164                          case 'd':
165 +                        case 'D':
166 +                                itype = argv[i][2];
167                                  if (isdigit(argv[i][3]))
168                                          nbicols = atoi(argv[i]+3);
169                                  else
# Line 164 | Line 175 | char  *argv[]
175                                  }
176                                  break;
177                          case 'f':
178 +                        case 'F':
179 +                                itype = argv[i][2];
180                                  if (isdigit(argv[i][3]))
181 <                                        nbicols = -atoi(argv[i]+3);
181 >                                        nbicols = atoi(argv[i]+3);
182                                  else
183 <                                        nbicols = -1;
184 <                                if (-nbicols*sizeof(float) > INBSIZ) {
183 >                                        nbicols = 1;
184 >                                if (nbicols*sizeof(float) > INBSIZ) {
185                                          eputs(argv[0]);
186                                          eputs(": too many input columns\n");
187                                          quit(1);
# Line 181 | Line 194 | char  *argv[]
194                  case 'o':
195                          switch (argv[i][2]) {
196                          case '\0':
197 <                                bocols = 0;
197 >                                otype = 'a';
198                                  readfmt(argv[++i], 1);
199                                  break;
200                          case 'a':
201 <                                bocols = 0;
201 >                                otype = 'a';
202                                  break;
203                          case 'd':
204 <                                bocols = 1;
192 <                                SET_FILE_BINARY(stdout);
193 <                                break;
204 >                        case 'D':
205                          case 'f':
206 <                                bocols = -1;
207 <                                SET_FILE_BINARY(stdout);
206 >                        case 'F':
207 >                                otype = argv[i][2];
208                                  break;
209                          default:
210                                  goto userr;
# Line 212 | Line 223 | char  *argv[]
223   eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
224                          quit(1);
225                  }
226 <        if (bocols)
226 >        if (otype != 'a')
227                  SET_FILE_BINARY(stdout);
228          if (noinput) {          /* produce a single output record */
229                  if (i < argc) {
# Line 224 | Line 235 | eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e
235                  putout();
236                  quit(0);
237          }
238 <        if (nbicols)
238 >        if (itype != 'a')
239                  SET_FILE_BINARY(stdin);
240  
241          if (blnkeq)             /* for efficiency */
# Line 260 | Line 271 | FILE  *fp
271   {
272          if (inpfmt != NULL)
273                  return(getrec());
274 <        if (nbicols > 0)
275 <                return(fread(inpbuf, sizeof(double),
276 <                                        nbicols, fp) == nbicols);
277 <        if (nbicols < 0)
278 <                return(fread(inpbuf, sizeof(float),
279 <                                        -nbicols, fp) == -nbicols);
274 >        if (tolower(itype) == 'd') {
275 >                if (fread(inpbuf, sizeof(double), nbicols, fp) != nbicols)
276 >                        return(0);
277 >                if (itype == 'D')
278 >                        swap64(inpbuf, nbicols);
279 >                return(1);
280 >        }
281 >        if (tolower(itype) == 'f') {
282 >                if (fread(inpbuf, sizeof(float), nbicols, fp) != nbicols)
283 >                        return(0);
284 >                if (itype == 'F')
285 >                        swap32(inpbuf, nbicols);
286 >                return(1);
287 >        }
288          return(fgets(inpbuf, INBSIZ, fp) != NULL);
289   }
290  
# Line 292 | Line 311 | char  *file
311          
312          while (getinputrec(fp)) {
313                  varset("recno", '=', (double)++nrecs);
314 +                varset("outno", '=', (double)(nout+1));
315                  colflg = 0;
316                  eclock++;
317                  if (!conditional || varvalue("cond") > 0.0) {
298                        varset("outno", '=', (double)++nout);
318                          putout();
319 +                        ++nout;
320                  }
321          }
322          fclose(fp);
# Line 310 | Line 330 | putout(void)                /* produce an output recor
330          colpos = 0;
331          if (outfmt != NULL)
332                  putrec();
333 <        else if (bocols)
314 <                chanout(bchanset);
315 <        else
333 >        else if (otype == 'a')
334                  chanout(chanset);
335 <        if (colpos && !bocols)
335 >        else
336 >                chanout(bchanset);
337 >        if (colpos && otype == 'a')
338                  putchar('\n');
339          if (unbuff)
340                  fflush(stdout);
# Line 333 | Line 353 | l_in(char *funame)     /* function call for $channel */
353                          /* determine number of channels */
354          if (noinput || inpfmt != NULL)
355                  return(0);
356 <        if (nbicols > 0)
356 >        if (nbicols)
357                  return(nbicols);
338        if (nbicols < 0)
339                return(-nbicols);
358          cp = inpbuf;    /* need to count */
359          for (n = 0; *cp; )
360                  if (blnkeq && isspace(sepchar)) {
# Line 369 | Line 387 | int  n
387                  eputs("illegal channel number\n");
388                  quit(1);
389          }
390 <        if (nbicols > 0) {
390 >        if (nbicols) {
391                  if (n > nbicols)
392                          return(0.0);
393 <                cp = inpbuf + (n-1)*sizeof(double);
394 <                return(*(double *)cp);
395 <        }
396 <        if (nbicols < 0) {
379 <                if (n > -nbicols)
380 <                        return(0.0);
393 >                if (tolower(itype) == 'd') {
394 >                        cp = inpbuf + (n-1)*sizeof(double);
395 >                        return(*(double *)cp);
396 >                }
397                  cp = inpbuf + (n-1)*sizeof(float);
398                  return(*(float *)cp);
399          }
# Line 429 | Line 445 | double  v
445   )
446   {
447          static char     zerobuf[sizeof(double)];
448 +        float   fval = v;
449  
450          while (++colpos < n)
451                  fwrite(zerobuf,
452 <                        bocols>0 ? sizeof(double) : sizeof(float),
452 >                        tolower(otype)=='d' ? sizeof(double) : sizeof(float),
453                          1, stdout);
454 <        if (bocols > 0)
454 >        switch (otype) {
455 >        case 'D':
456 >                swap64((char *)&v, 1);
457 >                /* fall through */
458 >        case 'd':
459                  fwrite(&v, sizeof(double), 1, stdout);
460 <        else {
461 <                float   fval = v;
460 >                break;
461 >        case 'F':
462 >                swap32((char *)&fval, 1);
463 >                /* fall through */
464 >        case 'f':
465                  fwrite(&fval, sizeof(float), 1, stdout);
466 +                break;
467          }
468   }
469  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines