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

Comparing ray/src/util/rtcontrib.c (file contents):
Revision 1.31 by greg, Thu Oct 6 05:49:44 2005 UTC vs.
Revision 1.34 by greg, Tue Oct 11 04:27:41 2005 UTC

# Line 63 | Line 63 | static void
63   closestream(void *p)
64   {
65          STREAMOUT       *sop = (STREAMOUT *)p;
66 +        int             status;
67          if (sop->reclen == CNT_PIPE)
68 <                pclose(sop->ofp);
68 >                status = pclose(sop->ofp);
69          else
70 <                fclose(sop->ofp);
70 >                status = fclose(sop->ofp);
71 >        if (status)
72 >                error(SYSTEM, "error closing output stream");
73          free(p);
74   }
75  
# Line 75 | Line 78 | LUTAB  ofiletab = LU_SINIT(free,closestream);  /* output
78   #define OF_MODIFIER     01
79   #define OF_BIN          02
80  
81 < STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int bincnt);
81 > STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int noopen);
82   int ofname(char *oname, const char *ospec, const char *mname, int bn);
83   void printheader(FILE *fout, const char *info);
84   void printresolu(FILE *fout);
# Line 505 | Line 508 | addmodifier(char *modn, char *outf, char *binv, int bi
508   {
509          LUENT   *lep = lu_find(&modconttab, modn);
510          MODCONT *mp;
511 +        int     i;
512          
513          if (lep->data != NULL) {
514                  sprintf(errmsg, "duplicate modifier '%s'", modn);
# Line 517 | Line 521 | addmodifier(char *modn, char *outf, char *binv, int bi
521          mp = (MODCONT *)malloc(sizeof(MODCONT));
522          if (mp == NULL)
523                  error(SYSTEM, "out of memory in addmodifier");
520        lep->data = (char *)mp;
524          mp->outspec = outf;             /* XXX assumes static string */
525          mp->modname = modn;             /* XXX assumes static string */
526          if (binv != NULL)
# Line 530 | Line 533 | addmodifier(char *modn, char *outf, char *binv, int bi
533                  bincnt = 1;
534          else if (bincnt > 1)
535                  mp = growmodifier(mp, bincnt);
536 <        if (bincnt > 0)                 /* allocate output stream */
537 <                getostream(mp->outspec, mp->modname, 0, bincnt);
536 >        lep->data = (char *)mp;
537 >                                        /* allocate output streams */
538 >        for (i = outf==NULL || outf[0]=='!' ? 0 : bincnt; i--; )
539 >                getostream(mp->outspec, mp->modname, i, 1);
540          return mp;
541   }
542  
# Line 660 | Line 665 | printresolu(FILE *fout)
665          }
666   }
667  
668 < /* Get output stream pointer (open and write header if new and bincnt==0) */
668 > /* Get output stream pointer (open and write header if new and noopen==0) */
669   STREAMOUT *
670 < getostream(const char *ospec, const char *mname, int bn, int bincnt)
670 > getostream(const char *ospec, const char *mname, int bn, int noopen)
671   {
672          static STREAMOUT        stdos;
673          int                     ofl;
# Line 671 | Line 676 | getostream(const char *ospec, const char *mname, int b
676          STREAMOUT               *sop;
677          
678          if (ospec == NULL) {                    /* use stdout? */
679 <                if (!bincnt && !using_stdout) {
679 >                if (!noopen && !using_stdout) {
680                          stdos.reclen = 0;
681                          if (outfmt != 'a')
682                                  SET_FILE_BINARY(stdout);
# Line 681 | Line 686 | getostream(const char *ospec, const char *mname, int b
686                          using_stdout = 1;
687                  }
688                  stdos.ofp = stdout;
689 <                stdos.reclen += bincnt;
689 >                stdos.reclen += noopen;
690                  return &stdos;
691          }
692          ofl = ofname(oname, ospec, mname, bn);  /* get output name */
# Line 694 | Line 699 | getostream(const char *ospec, const char *mname, int b
699                  lep->key = strcpy((char *)malloc(strlen(oname)+1), oname);
700          sop = (STREAMOUT *)lep->data;
701          if (sop == NULL) {                      /* allocate stream */
697                if (ofl & OF_BIN && bincnt > 1) /* don't overcount bins */
698                        bincnt = 1;
702                  sop = (STREAMOUT *)malloc(sizeof(STREAMOUT));
703                  if (sop == NULL)
704                          error(SYSTEM, "out of memory in getostream");
705 <                sop->reclen = oname[0] == '!' ? CNT_PIPE : 0;
706 <                sop->ofp = NULL;                /* open iff bincnt==0 */
705 >                sop->reclen = oname[0] == '!' ? CNT_PIPE : CNT_UNKNOWN;
706 >                sop->ofp = NULL;                /* open iff noopen==0 */
707                  lep->data = (char *)sop;
708          }
709 <        if (!bincnt && sop->ofp == NULL) {      /* open output stream */
710 <                int             i;
709 >        if (!noopen && sop->ofp == NULL) {      /* open output stream */
710 >                long            i;
711                  if (oname[0] == '!')            /* output to command */
712                          sop->ofp = popen(oname+1, "w");
713                  else
# Line 718 | Line 721 | getostream(const char *ospec, const char *mname, int b
721                  if (header) {
722                          char    info[512];
723                          char    *cp = info;
724 <                        if (ofl & OF_MODIFIER) {
724 >                        if (ofl & OF_MODIFIER || sop->reclen == 1) {
725                                  sprintf(cp, "MODIFIER=%s\n", mname);
726                                  while (*cp) ++cp;
727                          }
# Line 731 | Line 734 | getostream(const char *ospec, const char *mname, int b
734                  }
735                  printresolu(sop->ofp);
736                                                  /* play catch-up */
737 <                for (i = 0; i < lastdone; i++) {
737 >                for (i = sop->reclen > 1 ? sop->reclen*lastdone : lastdone;
738 >                                                                i--; ) {
739                          static const DCOLOR     nocontrib = BLKCOLOR;
740                          put_contrib(nocontrib, sop->ofp);
741                          if (outfmt == 'a')
# Line 740 | Line 744 | getostream(const char *ospec, const char *mname, int b
744                  if (xres > 0)
745                          fflush(sop->ofp);
746          }
747 <        if (sop->reclen != CNT_PIPE)            /* add bincnt to count */
748 <                sop->reclen += bincnt;
747 >        if (sop->reclen != CNT_PIPE)            /* add to length if noopen */
748 >                sop->reclen += noopen;
749          return sop;                             /* return open stream */
750   }
751  
# Line 1039 | Line 1043 | trace_contribs(FILE *fin)
1043                                                  /* loop over input */
1044          while ((iblen = getinp(inpbuf, fin)) > 0) {
1045                  if (lastray+1 < lastray ||      /* need reset? */
1046 <                                queue_length() > 5*nrtprocs()) {
1046 >                                queue_length() > 10*nrtprocs()) {
1047                          while (wait_rproc() != NULL)
1048                                  process_queue();
1049 <                        lastdone = lastray = 0;
1049 >                        if (lastray+1 < lastray)
1050 >                                lastdone = lastray = 0;
1051                  }
1052                  rtp = get_rproc();              /* get avail. rtrace process */
1053                  rtp->raynum = ++lastray;        /* assign ray to it */
# Line 1125 | Line 1130 | recover_output(FILE *fin)
1130                          if (oent->data != NULL) {
1131                                  sout = *(STREAMOUT *)oent->data;
1132                          } else {
1133 <                                sout.reclen = 0;
1133 >                                sout.reclen = CNT_UNKNOWN;
1134                                  sout.ofp = NULL;
1135                          }
1136                          if (sout.ofp != NULL) { /* already open? */
# Line 1148 | Line 1153 | recover_output(FILE *fin)
1153                                  fclose(sout.ofp);
1154                                  break;
1155                          }
1156 <                        if (!sout.reclen) {     /* unspecified record length */
1156 >                        if (sout.reclen == CNT_UNKNOWN) {
1157                                  if (!(ofl & OF_BIN)) {
1158                                          sprintf(errmsg,
1159 <                                                "guessing 1 value per record in '%s'",
1159 >                                                "need -bn to recover file '%s'",
1160                                                          oname);
1161 <                                        error(WARNING, errmsg);
1161 >                                        error(USER, errmsg);
1162                                  }
1163                                  recsiz = outvsiz;
1164                          } else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines