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

Comparing ray/src/rt/rc2.c (file contents):
Revision 2.19 by greg, Mon Sep 12 20:31:34 2016 UTC vs.
Revision 2.24 by greg, Wed Sep 4 20:19:51 2019 UTC

# Line 116 | Line 116 | printheader(FILE *fout, const char *info)
116          fputs("NCOMP=3\n", fout);               /* always RGB */
117          if (info != NULL)                       /* add extra info if given */
118                  fputs(info, fout);
119 +        if ((outfmt == 'f') | (outfmt == 'd'))
120 +                fputendian(fout);
121          fputformat(formstr(outfmt), fout);
122          fputc('\n', fout);                      /* empty line ends header */
123   }
# Line 146 | Line 148 | getostream(const char *ospec, const char *mname, int b
148                  if (!noopen & !using_stdout) {
149                          if (outfmt != 'a')
150                                  SET_FILE_BINARY(stdout);
151 + #ifdef getc_unlocked
152 +                        flockfile(stdout);      /* avoid lock/unlock overhead */
153 + #endif
154                          if (header) {
155                                  cp = info;
156                                  if (yres > 0) {
# Line 162 | Line 167 | getostream(const char *ospec, const char *mname, int b
167                          if (waitflush > 0)
168                                  fflush(stdout);
169                          stdos.xr = xres; stdos.yr = yres;
165 #ifdef getc_unlocked
166                        flockfile(stdout);      /* avoid lock/unlock overhead */
167 #endif
170                          using_stdout = 1;
171                  }
172                  stdos.ofp = stdout;
# Line 445 | Line 447 | reload_output()
447          char            *outvfmt;
448          LUENT           *oent;
449          int             xr, yr;
450 <        STREAMOUT       sout;
450 >        STREAMOUT       *sop;
451          DCOLOR          rgbv;
452  
453          if (outfmt == 'a')
# Line 458 | Line 460 | reload_output()
460                          error(USER, "cannot reload from stdout");
461                  if (mp->outspec[0] == '!')
462                          error(USER, "cannot reload from command");
463 <                for (j = 0; ; j++) {            /* load each modifier bin */
464 <                        ofl = ofname(oname, mp->outspec, mp->modname, j);
463 >                for (j = 0; j < mp->nbins; j++) { /* load each modifier bin */
464 >                        ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j);
465                          if (ofl < 0)
466                                  error(USER, "bad output file specification");
467                          oent = lu_find(&ofiletab, oname);
468 <                        if (oent->data != NULL) {
469 <                                sout = *(STREAMOUT *)oent->data;
470 <                        } else {
471 <                                sout.reclen = 0;
472 <                                sout.outpipe = 0;
473 <                                sout.xr = xres; sout.yr = yres;
472 <                                sout.ofp = NULL;
473 <                        }
474 <                        if (sout.ofp == NULL) { /* open output as input */
475 <                                sout.ofp = fopen(oname, fmode);
476 <                                if (sout.ofp == NULL) {
477 <                                        if (j == mp->nbins)
478 <                                                break;  /* assume end of modifier */
468 >                        if (oent->data == NULL)
469 >                                error(INTERNAL, "unallocated stream in reload_output()");
470 >                        sop = (STREAMOUT *)oent->data;
471 >                        if (sop->ofp == NULL) { /* open output as input */
472 >                                sop->ofp = fopen(oname, fmode);
473 >                                if (sop->ofp == NULL) {
474                                          sprintf(errmsg, "missing reload file '%s'",
475                                                          oname);
476                                          error(WARNING, errmsg);
477                                          break;
478                                  }
479   #ifdef getc_unlocked
480 <                                flockfile(sout.ofp);
480 >                                flockfile(sop->ofp);
481   #endif
482 <                                if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) {
482 >                                if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) {
483                                          sprintf(errmsg, "format mismatch for '%s'",
484                                                          oname);
485                                          error(USER, errmsg);
486                                  }
487 <                                if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) &&
488 <                                                (!fscnresolu(&xr, &yr, sout.ofp) ||
489 <                                                        (xr != sout.xr) |
490 <                                                        (yr != sout.yr))) {
487 >                                if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) &&
488 >                                                (!fscnresolu(&xr, &yr, sop->ofp) ||
489 >                                                        (xr != sop->xr) |
490 >                                                        (yr != sop->yr))) {
491                                          sprintf(errmsg, "resolution mismatch for '%s'",
492                                                          oname);
493                                          error(USER, errmsg);
494                                  }
495                          }
496                                                          /* read in RGB value */
497 <                        if (!get_contrib(rgbv, sout.ofp)) {
497 >                        if (!get_contrib(rgbv, sop->ofp)) {
498                                  if (!j) {
499 <                                        fclose(sout.ofp);
499 >                                        fclose(sop->ofp);
500                                          break;          /* ignore empty file */
501                                  }
502                                  if (j < mp->nbins) {
# Line 510 | Line 505 | reload_output()
505                                          error(USER, errmsg);
506                                  }
507                                  break;
508 <                        }
514 <                        if (j >= mp->nbins) {           /* check modifier size */
515 <                                sprintf(errmsg,
516 <                                "mismatched -bn setting for reloading '%s'",
517 <                                                modname[i]);
518 <                                error(USER, errmsg);
519 <                        }
520 <                                
508 >                        }                              
509                          copycolor(mp->cbin[j], rgbv);
522                        if (oent->key == NULL)          /* new file entry */
523                                oent->key = strcpy((char *)
524                                                malloc(strlen(oname)+1), oname);
525                        if (oent->data == NULL)
526                                oent->data = (char *)malloc(sizeof(STREAMOUT));
527                        *(STREAMOUT *)oent->data = sout;
510                  }
511          }
512          lu_doall(&ofiletab, &myclose, NULL);    /* close all files */
# Line 539 | Line 521 | myseeko(const LUENT *e, void *p)
521          off_t           nbytes = *(off_t *)p;
522          
523          if (sop->reclen > 1)
524 <                nbytes = nbytes * sop->reclen;
524 >                nbytes *= (off_t)sop->reclen;
525          if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) {
526                  sprintf(errmsg, "seek error on file '%s'", e->key);
527                  error(SYSTEM, errmsg);
# Line 560 | Line 542 | recover_output()
542          int             ofl;
543          char            oname[1024];
544          LUENT           *oent;
545 <        STREAMOUT       sout;
545 >        STREAMOUT       *sop;
546          off_t           nvals;
547          int             xr, yr;
548  
# Line 589 | Line 571 | recover_output()
571                          error(USER, "cannot recover from stdout");
572                  if (mp->outspec[0] == '!')
573                          error(USER, "cannot recover from command");
574 <                for (j = 0; ; j++) {            /* check each bin's file */
575 <                        ofl = ofname(oname, mp->outspec, mp->modname, j);
574 >                for (j = 0; j < mp->nbins; j++) { /* check each bin's file */
575 >                        ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j);
576                          if (ofl < 0)
577                                  error(USER, "bad output file specification");
578                          oent = lu_find(&ofiletab, oname);
579 <                        if (oent->data != NULL) {
580 <                                sout = *(STREAMOUT *)oent->data;
581 <                        } else {
582 <                                sout.reclen = 0;
601 <                                sout.outpipe = 0;
602 <                                sout.xr = xres;
603 <                                sout.yr = yres;
604 <                                sout.ofp = NULL;
605 <                        }
606 <                        if (sout.ofp != NULL) { /* already open? */
579 >                        if (oent->data == NULL)
580 >                                error(INTERNAL, "unallocated stream in recover_output()");
581 >                        sop = (STREAMOUT *)oent->data;
582 >                        if (sop->ofp != NULL) { /* already open? */
583                                  if (ofl & OF_BIN)
584                                          continue;
585                                  break;
586                          }
587                                                  /* open output */
588 <                        sout.ofp = fopen(oname, "rb+");
589 <                        if (sout.ofp == NULL) {
614 <                                if (j == mp->nbins)
615 <                                        break;  /* assume end of modifier */
588 >                        sop->ofp = fopen(oname, "rb+");
589 >                        if (sop->ofp == NULL) {
590                                  sprintf(errmsg, "missing recover file '%s'",
591                                                  oname);
592                                  error(WARNING, errmsg);
593 +                                lastout = 0;
594                                  break;
595                          }
596 <                        nvals = lseek(fileno(sout.ofp), 0, SEEK_END);
596 >                        nvals = lseek(fileno(sop->ofp), 0, SEEK_END);
597                          if (nvals <= 0) {
598                                  lastout = 0;    /* empty output, quit here */
599 <                                fclose(sout.ofp);
599 >                                fclose(sop->ofp);
600                                  break;
601                          }
602 <                        if (!sout.reclen) {
628 <                                if (!(ofl & OF_BIN)) {
629 <                                        sprintf(errmsg,
630 <                                                "need -bn to recover file '%s'",
631 <                                                        oname);
632 <                                        error(USER, errmsg);
633 <                                }
634 <                                recsiz = outvsiz;
635 <                        } else
636 <                                recsiz = outvsiz * sout.reclen;
602 >                        recsiz = outvsiz * sop->reclen;
603  
604 <                        lseek(fileno(sout.ofp), 0, SEEK_SET);
605 <                        if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) {
604 >                        lseek(fileno(sop->ofp), 0, SEEK_SET);
605 >                        if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) {
606                                  sprintf(errmsg, "format mismatch for '%s'",
607                                                  oname);
608                                  error(USER, errmsg);
609                          }
610 <                        if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) &&
611 <                                        (!fscnresolu(&xr, &yr, sout.ofp) ||
612 <                                                (xr != sout.xr) |
613 <                                                (yr != sout.yr))) {
610 >                        if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) &&
611 >                                        (!fscnresolu(&xr, &yr, sop->ofp) ||
612 >                                                (xr != sop->xr) |
613 >                                                (yr != sop->yr))) {
614                                  sprintf(errmsg, "resolution mismatch for '%s'",
615                                                  oname);
616                                  error(USER, errmsg);
617                          }
618 <                        nvals = (nvals - (off_t)ftell(sout.ofp)) / recsiz;
618 >                        nvals = (nvals - (off_t)ftell(sop->ofp)) / recsiz;
619                          if ((lastout < 0) | (nvals < lastout))
620                                  lastout = nvals;
655                        if (oent->key == NULL)  /* new entry */
656                                oent->key = strcpy((char *)
657                                                malloc(strlen(oname)+1), oname);
658                        if (oent->data == NULL)
659                                oent->data = (char *)malloc(sizeof(STREAMOUT));
660                        *(STREAMOUT *)oent->data = sout;
621                          if (!(ofl & OF_BIN))
622                                  break;          /* no bin separation */
623                  }
624                  if (!lastout) {                 /* empty output */
625                          error(WARNING, "no previous data to recover");
626 <                        lu_done(&ofiletab);     /* reclose all outputs */
626 >                                                /* reclose all outputs */
627 >                        lu_doall(&ofiletab, &myclose, NULL);
628                          return;
668                }
669                if (j > mp->nbins) {            /* check modifier size */
670                        sprintf(errmsg,
671                                "mismatched -bn setting for recovering '%s'",
672                                        modname[i]);
673                        error(USER, errmsg);
629                  }
630          }
631          if (lastout < 0) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines