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.2 by greg, Fri Feb 28 20:29:01 2003 UTC vs.
Revision 1.3 by greg, Sun Apr 27 06:08:03 2003 UTC

# Line 69 | Line 69 | int  blnkeq = 1;                /* blanks compare equa
69   int  igneol = 0;                /* ignore end of line? */
70   char  sepchar = '\t';           /* input/output separator */
71   int  noinput = 0;               /* no input records? */
72 + int  nbicols = 0;               /* number of binary input columns */
73 + int  bocols = 0;                /* produce binary output columns */
74   char  inpbuf[INBSIZ];           /* input buffer */
75   double  colval[MAXCOL];         /* input column values */
76   unsigned long  colflg = 0;      /* column retrieved flags */
# Line 124 | Line 126 | char  *argv[];
126                          noinput = 1;
127                          break;
128                  case 'i':
129 <                        readfmt(argv[++i], 0);
129 >                        switch (argv[i][2]) {
130 >                        case '\0':
131 >                                nbicols = 0;
132 >                                readfmt(argv[++i], 0);
133 >                                break;
134 >                        case 'a':
135 >                                nbicols = 0;
136 >                                break;
137 >                        case 'd':
138 >                                if (isdigit(argv[i][3]))
139 >                                        nbicols = atoi(argv[i]+3);
140 >                                else
141 >                                        nbicols = 1;
142 >                                break;
143 >                        case 'f':
144 >                                if (isdigit(argv[i][3]))
145 >                                        nbicols = -atoi(argv[i]+3);
146 >                                else
147 >                                        nbicols = -1;
148 >                                break;
149 >                        default:
150 >                                goto userr;
151 >                        }
152                          break;
153                  case 'o':
154 <                        readfmt(argv[++i], 1);
154 >                        switch (argv[i][2]) {
155 >                        case '\0':
156 >                                bocols = 0;
157 >                                readfmt(argv[++i], 1);
158 >                                break;
159 >                        case 'a':
160 >                                bocols = 0;
161 >                                break;
162 >                        case 'd':
163 >                                bocols = 1;
164 >                                break;
165 >                        case 'f':
166 >                                bocols = -1;
167 >                                break;
168 >                        }
169                          break;
170                  case 'w':
171                          nowarn = !nowarn;
# Line 135 | Line 173 | char  *argv[];
173                  case 'u':
174                          unbuff = !unbuff;
175                          break;
176 <                default:
176 >                default:;
177 >                userr:
178                          eputs("Usage: ");
179                          eputs(argv[0]);
180   eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
# Line 172 | Line 211 | nbsynch()               /* non-blank starting synch ch
211   }
212  
213  
214 + int
215 + getinputrec(fp)         /* get next input record */
216 + FILE  *fp;
217 + {
218 +        if (inpfmt != NULL)
219 +                return(getrec());
220 +        if (nbicols > 0)
221 +                return(fread(inpbuf, sizeof(double),
222 +                                        nbicols, fp) == nbicols);
223 +        if (nbicols < 0)
224 +                return(fread(inpbuf, sizeof(float),
225 +                                        -nbicols, fp) == -nbicols);
226 +        return(fgets(inpbuf, INBSIZ, fp) != NULL);
227 + }
228 +
229 +
230   execute(file)           /* process a file */
231   char  *file;
232   {
# Line 189 | Line 244 | char  *file;
244          }
245          if (inpfmt != NULL)
246                  initinp(fp);
247 <                
248 <        while (inpfmt != NULL ? getrec() : fgets(inpbuf, INBSIZ, fp) != NULL) {
247 >        
248 >        while (getinputrec(fp)) {
249                  varset("recno", '=', (double)++nrecs);
250                  colflg = 0;
251                  eclock++;
# Line 205 | Line 260 | char  *file;
260  
261   putout()                /* produce an output record */
262   {
263 <        extern int  chanset();
263 >        extern void  chanset(), bchanset();
264  
265          colpos = 0;
266          if (outfmt != NULL)
267                  putrec();
268 +        else if (bocols)
269 +                chanout(bchanset);
270          else
271                  chanout(chanset);
272 <        if (colpos)
272 >        if (colpos && !bchanset)
273                  putchar('\n');
274          if (unbuff)
275                  fflush(stdout);
# Line 234 | Line 291 | int  n;
291                  eputs("illegal channel number\n");
292                  quit(1);
293          }
294 +        if (nbicols > 0) {
295 +                if (n > nbicols)
296 +                        return(0.0);
297 +                cp = inpbuf + (n-1)*sizeof(double);
298 +                return(*(double *)cp);
299 +        }
300 +        if (nbicols < 0) {
301 +                if (n > -nbicols)
302 +                        return(0.0);
303 +                cp = inpbuf + (n-1)*sizeof(float);
304 +                return(*(float *)cp);
305 +        }
306          if (n <= MAXCOL && colflg & 1L<<(n-1))
307                  return(colval[n-1]);
308  
# Line 259 | Line 328 | int  n;
328   }
329  
330  
331 + void
332   chanset(n, v)                   /* output column n */
333   int  n;
334   double  v;
# Line 270 | Line 340 | double  v;
340                  colpos++;
341          }
342          printf("%.9g", v);
343 + }
344 +
345 +
346 + void
347 + bchanset(n, v)                   /* output binary channel n */
348 + int  n;
349 + double  v;
350 + {
351 +        static char     zerobuf[sizeof(double)];
352 +
353 +        while (++colpos < n)
354 +                fwrite(zerobuf,
355 +                        bocols>0 ? sizeof(double) : sizeof(float),
356 +                        1, stdout);
357 +        if (bocols > 0)
358 +                fwrite(&v, sizeof(double), 1, stdout);
359 +        else {
360 +                float   fval = v;
361 +                fwrite(&fval, sizeof(float), 1, stdout);
362 +        }
363   }
364  
365  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines