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

Comparing ray/src/util/dctimestep.c (file contents):
Revision 2.29 by greg, Mon Jan 20 22:18:29 2014 UTC vs.
Revision 2.30 by greg, Sat Feb 8 01:28:06 2014 UTC

# Line 59 | Line 59 | sum_images(const char *fspec, const CMATRIX *cv, FILE
59                          pmat = cm_alloc(myYR, myXR);
60                          memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR);
61                                                          /* finish header */
62 <                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout);
62 >                        fputformat((char *)cm_fmt_id[myDT], fout);
63                          fputc('\n', fout);
64                        fprtresolu(myXR, myYR, fout);
64                          fflush(fout);
65                  } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) {
66                          sprintf(errmsg, "picture '%s' format/size mismatch",
# Line 85 | Line 84 | sum_images(const char *fspec, const CMATRIX *cv, FILE
84                  fclose(fp);                             /* done this picture */
85          }
86          free(scanline);
87 <                                                        /* write scanlines */
88 <        for (y = 0; y < myYR; y++)
89 <                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0)
91 <                        return(0);
92 <        cm_free(pmat);                                  /* all done */
93 <        return(fflush(fout) == 0);
87 >        i = cm_write(pmat, myDT, fout);                 /* write picture */
88 >        cm_free(pmat);                                  /* free data */
89 >        return(i);
90   }
91  
92   /* check to see if a string contains a %d or %o specification */
# Line 122 | Line 118 | int
118   main(int argc, char *argv[])
119   {
120          int             skyfmt = DTascii;
121 +        int             outfmt = DTascii;
122          int             nsteps = 1;
123          char            *ofspec = NULL;
124          FILE            *ofp = stdout;
# Line 138 | Line 135 | main(int argc, char *argv[])
135                          if (nsteps <= 0)
136                                  goto userr;
137                          break;
141                case 'o':
142                        ofspec = argv[++a];
143                        break;
138                  case 'i':
139                          switch (argv[a][2]) {
140                          case 'f':
# Line 156 | Line 150 | main(int argc, char *argv[])
150                                  goto userr;
151                          }
152                          break;
153 +                case 'o':
154 +                        switch (argv[a][2]) {
155 +                        case '\0':      /* output specification (not format) */
156 +                                ofspec = argv[++a];
157 +                                break;
158 +                        case 'f':
159 +                                outfmt = DTfloat;
160 +                                break;
161 +                        case 'd':
162 +                                outfmt = DTdouble;
163 +                                break;
164 +                        case 'a':
165 +                                outfmt = DTascii;
166 +                                break;
167 +                        default:
168 +                                goto userr;
169 +                        }
170 +                        break;
171                  default:
172                          goto userr;
173                  }
# Line 235 | Line 247 | main(int argc, char *argv[])
247                  CMATRIX *Vmat = cm_load(argv[a], 0, cmtx->nrows, DTfromHeader);
248                  CMATRIX *rmtx = cm_multiply(Vmat, cmtx);
249                  cm_free(Vmat);
250 <                if (ofspec != NULL)             /* multiple vector files? */
250 >                if (ofspec != NULL) {           /* multiple vector files? */
251 >                        const char      *wtype = (outfmt==DTascii) ? "w" : "wb";
252                          for (i = 0; i < nsteps; i++) {
253                                  CMATRIX *rvec = cm_column(rmtx, i);
254                                  sprintf(fnbuf, ofspec, i+1);
255 <                                if ((ofp = fopen(fnbuf, "w")) == NULL) {
255 >                                if ((ofp = fopen(fnbuf, wtype)) == NULL) {
256                                          fprintf(stderr,
257                                          "%s: cannot open '%s' for output\n",
258                                                          progname, fnbuf);
259                                          return(1);
260                                  }
261 <                                cm_print(rvec, ofp);
261 >                                cm_write(rvec, outfmt, ofp);
262                                  if (fclose(ofp) == EOF) {
263                                          fprintf(stderr,
264                                                  "%s: error writing to '%s'\n",
# Line 255 | Line 268 | main(int argc, char *argv[])
268                                  ofp = stdout;
269                                  cm_free(rvec);
270                          }
271 <                else
272 <                        cm_print(rmtx, ofp);
271 >                } else {
272 >                        if (outfmt != DTascii)
273 >                                SET_FILE_BINARY(ofp);
274 >                        if (rmtx->ncols > 1) {  /* header if actual matrix */
275 >                                newheader("RADIANCE", ofp);
276 >                                printargs(argc, argv, ofp);
277 >                                fputnow(ofp);
278 >                                fputformat((char *)cm_fmt_id[outfmt], ofp);
279 >                                fputc('\n', ofp);
280 >                        }
281 >                        cm_write(rmtx, outfmt, ofp);
282 >                }
283                  cm_free(rmtx);
284          }
285          if (fflush(ofp) == EOF) {               /* final clean-up */
# Line 266 | Line 289 | main(int argc, char *argv[])
289          cm_free(cmtx);
290          return(0);
291   userr:
292 <        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}] DCspec [skyf]\n",
292 >        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] DCspec [skyf]\n",
293                                  progname);
294 <        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
294 >        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
295                                  progname);
296          return(1);
297   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines