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.24 by greg, Fri Jan 11 05:07:47 2013 UTC vs.
Revision 2.25 by greg, Fri Jan 11 17:21:39 2013 UTC

# Line 107 | Line 107 | getDTfromHeader(FILE *fp)
107   static CMATRIX *
108   cm_load(const char *fname, int nrows, int ncols, int dtype)
109   {
110        CMATRIX *cm;
110          FILE    *fp = stdin;
111 +        CMATRIX *cm;
112  
113          if (ncols <= 0)
114                  error(USER, "Non-positive number of columns");
# Line 118 | Line 118 | cm_load(const char *fname, int nrows, int ncols, int d
118                  sprintf(errmsg, "cannot open file '%s'", fname);
119                  error(SYSTEM, errmsg);
120          }
121 + #ifdef getc_unlocked
122 +        flockfile(fp);
123 + #endif
124          if (dtype != DTascii)
125                  SET_FILE_BINARY(fp);
126          if (dtype == DTfromHeader)
# Line 158 | Line 161 | cm_load(const char *fname, int nrows, int ncols, int d
161                  cm = cm_alloc(guessrows, ncols);
162          } else
163                  cm = cm_alloc(nrows, ncols);
164 <        if (cm == NULL)
164 >        if (cm == NULL)                                 /* XXX never happens */
165                  return(NULL);
166          if (dtype == DTascii) {                         /* read text file */
167                  int     maxrow = (nrows > 0 ? nrows : 32000);
# Line 233 | Line 236 | cm_load(const char *fname, int nrows, int ncols, int d
236                                  cvp += 3;
237                          }
238                  }
239 <                if (getc(fp) != EOF) {
239 >                if (fgetc(fp) != EOF) {
240                                  sprintf(errmsg,
241                                  "unexpected data at end of binary file %s",
242                                                  fname);
# Line 242 | Line 245 | cm_load(const char *fname, int nrows, int ncols, int d
245          }
246          if (fp != stdin)
247                  fclose(fp);
248 + #ifdef getc_unlocked
249 +        else
250 +                funlockfile(fp);
251 + #endif
252          return(cm);
253   EOFerror:
254 <        sprintf(errmsg, "unexpected EOF reading %s",
248 <                        fname);
254 >        sprintf(errmsg, "unexpected EOF reading %s", fname);
255          error(USER, errmsg);
256   not_handled:
257          error(INTERNAL, "unhandled data size or length in cm_load()");
# Line 587 | Line 593 | hasNumberFormat(const char *s)
593   int
594   main(int argc, char *argv[])
595   {
596 +        int             skyfmt = DTascii;
597          int             nsteps = 1;
598          char            *ofspec = NULL;
599          FILE            *ofp = stdout;
# Line 596 | Line 603 | main(int argc, char *argv[])
603  
604          progname = argv[0];
605                                          /* get options */
606 <        for (a = 1; a < argc-1 && argv[a][0] == '-'; a++)
607 <                switch (argv[0][1]) {
606 >        for (a = 1; a < argc && argv[a][0] == '-'; a++)
607 >                switch (argv[a][1]) {
608                  case 'n':
609                          nsteps = atoi(argv[++a]);
610                          if (nsteps <= 0)
# Line 606 | Line 613 | main(int argc, char *argv[])
613                  case 'o':
614                          ofspec = argv[++a];
615                          break;
616 +                case 'i':
617 +                        switch (argv[a][2]) {
618 +                        case 'f':
619 +                                skyfmt = DTfloat;
620 +                                break;
621 +                        case 'd':
622 +                                skyfmt = DTdouble;
623 +                                break;
624 +                        case 'a':
625 +                                skyfmt = DTascii;
626 +                                break;
627 +                        default:
628 +                                goto userr;
629 +                        }
630 +                        break;
631                  default:
632                          goto userr;
633                  }
# Line 616 | Line 638 | main(int argc, char *argv[])
638                  CMATRIX *smtx, *Dmat, *Tmat, *imtx;
639                  COLOR   tLamb;
640                                                  /* get sky vector/matrix */
641 <                smtx = cm_load(argv[a+3], 0, nsteps, DTascii);
641 >                smtx = cm_load(argv[a+3], 0, nsteps, skyfmt);
642                                                  /* load BSDF */
643                  Tmat = cm_loadBSDF(argv[a+1], tLamb);
644                                                  /* load Daylight matrix */
# Line 633 | Line 655 | main(int argc, char *argv[])
655                  }
656                  cm_free(imtx);
657          } else {                                /* sky vector/matrix only */
658 <                cmtx = cm_load(argv[a+1], 0, nsteps, DTascii);
658 >                cmtx = cm_load(argv[a+1], 0, nsteps, skyfmt);
659          }
660                                                  /* prepare output stream */
661          if ((ofspec != NULL) & (nsteps == 1) && hasNumberFormat(ofspec)) {
# Line 721 | Line 743 | main(int argc, char *argv[])
743          cm_free(cmtx);
744          return(0);
745   userr:
746 <        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec] DCspec [skyf]\n",
746 >        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}] DCspec [skyf]\n",
747                                  progname);
748 <        fprintf(stderr, "   or: %s [-n nsteps][-o ospec] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
748 >        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
749                                  progname);
750          return(1);
751   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines