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.20 by greg, Fri Sep 16 04:49:15 2016 UTC

# Line 445 | Line 445 | reload_output()
445          char            *outvfmt;
446          LUENT           *oent;
447          int             xr, yr;
448 <        STREAMOUT       sout;
448 >        STREAMOUT       *sop;
449          DCOLOR          rgbv;
450  
451          if (outfmt == 'a')
# Line 458 | Line 458 | reload_output()
458                          error(USER, "cannot reload from stdout");
459                  if (mp->outspec[0] == '!')
460                          error(USER, "cannot reload from command");
461 <                for (j = 0; ; j++) {            /* load each modifier bin */
462 <                        ofl = ofname(oname, mp->outspec, mp->modname, j);
461 >                for (j = 0; j < mp->nbins; j++) { /* load each modifier bin */
462 >                        ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j);
463                          if (ofl < 0)
464                                  error(USER, "bad output file specification");
465                          oent = lu_find(&ofiletab, oname);
466 <                        if (oent->data != NULL) {
467 <                                sout = *(STREAMOUT *)oent->data;
468 <                        } else {
469 <                                sout.reclen = 0;
470 <                                sout.outpipe = 0;
471 <                                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 */
466 >                        if (oent->data == NULL)
467 >                                error(INTERNAL, "unallocated stream in reload_output()");
468 >                        sop = (STREAMOUT *)oent->data;
469 >                        if (sop->ofp == NULL) { /* open output as input */
470 >                                sop->ofp = fopen(oname, fmode);
471 >                                if (sop->ofp == NULL) {
472                                          sprintf(errmsg, "missing reload file '%s'",
473                                                          oname);
474                                          error(WARNING, errmsg);
475                                          break;
476                                  }
477   #ifdef getc_unlocked
478 <                                flockfile(sout.ofp);
478 >                                flockfile(sop->ofp);
479   #endif
480 <                                if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) {
480 >                                if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) {
481                                          sprintf(errmsg, "format mismatch for '%s'",
482                                                          oname);
483                                          error(USER, errmsg);
484                                  }
485 <                                if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) &&
486 <                                                (!fscnresolu(&xr, &yr, sout.ofp) ||
487 <                                                        (xr != sout.xr) |
488 <                                                        (yr != sout.yr))) {
485 >                                if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) &&
486 >                                                (!fscnresolu(&xr, &yr, sop->ofp) ||
487 >                                                        (xr != sop->xr) |
488 >                                                        (yr != sop->yr))) {
489                                          sprintf(errmsg, "resolution mismatch for '%s'",
490                                                          oname);
491                                          error(USER, errmsg);
492                                  }
493                          }
494                                                          /* read in RGB value */
495 <                        if (!get_contrib(rgbv, sout.ofp)) {
495 >                        if (!get_contrib(rgbv, sop->ofp)) {
496                                  if (!j) {
497 <                                        fclose(sout.ofp);
497 >                                        fclose(sop->ofp);
498                                          break;          /* ignore empty file */
499                                  }
500                                  if (j < mp->nbins) {
# Line 510 | Line 503 | reload_output()
503                                          error(USER, errmsg);
504                                  }
505                                  break;
506 <                        }
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 <                                
506 >                        }                              
507                          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;
508                  }
509          }
510          lu_doall(&ofiletab, &myclose, NULL);    /* close all files */
# Line 560 | Line 540 | recover_output()
540          int             ofl;
541          char            oname[1024];
542          LUENT           *oent;
543 <        STREAMOUT       sout;
543 >        STREAMOUT       *sop;
544          off_t           nvals;
545          int             xr, yr;
546  
# Line 589 | Line 569 | recover_output()
569                          error(USER, "cannot recover from stdout");
570                  if (mp->outspec[0] == '!')
571                          error(USER, "cannot recover from command");
572 <                for (j = 0; ; j++) {            /* check each bin's file */
573 <                        ofl = ofname(oname, mp->outspec, mp->modname, j);
572 >                for (j = 0; j < mp->nbins; j++) { /* check each bin's file */
573 >                        ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j);
574                          if (ofl < 0)
575                                  error(USER, "bad output file specification");
576                          oent = lu_find(&ofiletab, oname);
577 <                        if (oent->data != NULL) {
578 <                                sout = *(STREAMOUT *)oent->data;
579 <                        } else {
580 <                                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? */
577 >                        if (oent->data == NULL)
578 >                                error(INTERNAL, "unallocated stream in recover_output()");
579 >                        sop = (STREAMOUT *)oent->data;
580 >                        if (sop->ofp != NULL) { /* already open? */
581                                  if (ofl & OF_BIN)
582                                          continue;
583                                  break;
584                          }
585                                                  /* open output */
586 <                        sout.ofp = fopen(oname, "rb+");
587 <                        if (sout.ofp == NULL) {
614 <                                if (j == mp->nbins)
615 <                                        break;  /* assume end of modifier */
586 >                        sop->ofp = fopen(oname, "rb+");
587 >                        if (sop->ofp == NULL) {
588                                  sprintf(errmsg, "missing recover file '%s'",
589                                                  oname);
590                                  error(WARNING, errmsg);
591                                  break;
592                          }
593 <                        nvals = lseek(fileno(sout.ofp), 0, SEEK_END);
593 >                        nvals = lseek(fileno(sop->ofp), 0, SEEK_END);
594                          if (nvals <= 0) {
595                                  lastout = 0;    /* empty output, quit here */
596 <                                fclose(sout.ofp);
596 >                                fclose(sop->ofp);
597                                  break;
598                          }
599 <                        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;
599 >                        recsiz = outvsiz * sop->reclen;
600  
601 <                        lseek(fileno(sout.ofp), 0, SEEK_SET);
602 <                        if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) {
601 >                        lseek(fileno(sop->ofp), 0, SEEK_SET);
602 >                        if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) {
603                                  sprintf(errmsg, "format mismatch for '%s'",
604                                                  oname);
605                                  error(USER, errmsg);
606                          }
607 <                        if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) &&
608 <                                        (!fscnresolu(&xr, &yr, sout.ofp) ||
609 <                                                (xr != sout.xr) |
610 <                                                (yr != sout.yr))) {
607 >                        if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) &&
608 >                                        (!fscnresolu(&xr, &yr, sop->ofp) ||
609 >                                                (xr != sop->xr) |
610 >                                                (yr != sop->yr))) {
611                                  sprintf(errmsg, "resolution mismatch for '%s'",
612                                                  oname);
613                                  error(USER, errmsg);
614                          }
615 <                        nvals = (nvals - (off_t)ftell(sout.ofp)) / recsiz;
615 >                        nvals = (nvals - (off_t)ftell(sop->ofp)) / recsiz;
616                          if ((lastout < 0) | (nvals < lastout))
617                                  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;
618                          if (!(ofl & OF_BIN))
619                                  break;          /* no bin separation */
620                  }
# Line 665 | Line 622 | recover_output()
622                          error(WARNING, "no previous data to recover");
623                          lu_done(&ofiletab);     /* reclose all outputs */
624                          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);
625                  }
626          }
627          if (lastout < 0) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines