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.23 by greg, Thu Jun 16 19:37:26 2005 UTC vs.
Revision 1.30 by greg, Wed Oct 5 19:44:17 2005 UTC

# Line 57 | Line 57 | LUTAB  ofiletab = LU_SINIT(free,closefile);    /* output f
57   FILE *getofile(const char *ospec, const char *mname, int bn);
58   int ofname(char *oname, const char *ospec, const char *mname, int bn);
59   void printheader(FILE *fout, const char *info);
60 + void printresolu(FILE *fout);
61  
62   /*
63   * The rcont structure is used to manage i/o with a particular
# Line 112 | Line 113 | int            using_stdout = 0;       /* are we using stdout? */
113   const char      *modname[MAXMODLIST];   /* ordered modifier name list */
114   int             nmods = 0;              /* number of modifiers */
115  
116 + #define queue_length()          (lastray - lastdone)
117 +
118   MODCONT *addmodifier(char *modn, char *outf, char *binv);
119   void addmodfile(char *fname, char *outf, char *binv);
120  
# Line 128 | Line 131 | void put_contrib(const DCOLOR cnt, FILE *fout);
131   void add_contrib(const char *modn);
132   void done_contrib(void);
133  
134 + /* return number of open rtrace processes */
135 + static int
136 + nrtprocs(void)
137 + {
138 +        int     nrtp = 0;
139 +        struct rtproc   *rtp;
140 +
141 +        for (rtp = &rt0; rtp != NULL; rtp = rtp->next)
142 +                nrtp += rtp->pd.running;
143 +        return(nrtp);
144 + }
145 +
146   /* set input/output format */
147   static void
148   setformat(const char *fmt)
# Line 173 | Line 188 | main(int argc, char *argv[])
188          char    *binval = NULL;
189          char    fmt[8];
190          int     i, j;
191 +                                /* need at least one argument */
192 +        if (argc < 2) {
193 +                fprintf(stderr,
194 + "Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n",
195 +                        argv[0]);
196 +                exit(1);
197 +        }
198                                  /* global program name */
199          gargv = argv;
200                                  /* initialize calcomp routines */
# Line 315 | Line 337 | main(int argc, char *argv[])
337                  error(USER, "missing octree argument");
338          rtargv[rtargc++] = octree = argv[i];
339          rtargv[rtargc] = NULL;
340 <                                /* start rtrace & compute contributions */
340 >                                /* start rtrace */
341          init(nprocs);
342          if (recover)            /* perform recovery if requested */
343                  recover_output(stdin);
344 <        trace_contribs(stdin);
344 >        trace_contribs(stdin);  /* compute contributions */
345          quit(0);
346   }
347  
348 + #ifndef SIGALRM
349 + #define SIGALRM SIGTERM
350 + #endif
351   /* kill persistent rtrace process */
352   static void
353   killpersist(void)
354   {
355          FILE    *fp = fopen(persistfn, "r");
356 <        int     pid;
356 >        RT_PID  pid;
357  
358          if (fp == NULL)
359                  return;
# Line 574 | Line 599 | printheader(FILE *fout, const char *info)
599                  break;
600          }
601          fputc('\n', fout);
602 + }
603 +
604 + /* write resolution string to given output stream */
605 + void
606 + printresolu(FILE *fout)
607 + {
608          if (xres > 0) {
609                  if (yres > 0)                   /* resolution string */
610                          fprtresolu(xres, yres, fout);
# Line 595 | Line 626 | getofile(const char *ospec, const char *mname, int bn)
626                                  SET_FILE_BINARY(stdout);
627                          if (header)
628                                  printheader(stdout, NULL);
629 +                        printresolu(stdout);
630                  }
631                  using_stdout = 1;
632                  return stdout;
# Line 623 | Line 655 | getofile(const char *ospec, const char *mname, int bn)
655                  if (header) {
656                          char    info[512];
657                          char    *cp = info;
658 <                        sprintf(cp, "MODIFIER=%s\n", mname);
659 <                        while (*cp) ++cp;
658 >                        if (ofl & OF_MODIFIER) {
659 >                                sprintf(cp, "MODIFIER=%s\n", mname);
660 >                                while (*cp) ++cp;
661 >                        }
662                          if (ofl & OF_BIN) {
663                                  sprintf(cp, "BIN=%d\n", bn);
664                                  while (*cp) ++cp;
# Line 632 | Line 666 | getofile(const char *ospec, const char *mname, int bn)
666                          *cp = '\0';
667                          printheader(fp, info);
668                  }
669 +                printresolu(fp);
670                                                  /* play catch-up */
671                  for (i = 0; i < lastdone; i++) {
672                          static const DCOLOR     nocontrib = BLKCOLOR;
# Line 706 | Line 741 | add_contrib(const char *modn)
741          bn = (int)(evalue(mp->binv) + .5);
742          if (bn <= 0)
743                  bn = 0;
744 <        else if (bn > mp->nbins) {      /* new bin */
744 >        else if (bn >= mp->nbins) {     /* new bin */
745                  mp = (MODCONT *)realloc(mp, sizeof(MODCONT) +
746                                                  bn*sizeof(DCOLOR));
747                  if (mp == NULL)
# Line 905 | Line 940 | wait_rproc(void)
940                                  if (rt->bsiz + BUFSIZ <= treebufsiz)
941                                          rt->bsiz = treebufsiz;
942                                  else
943 <                                        rt->bsiz = treebufsiz += BUFSIZ;
943 >                                        treebufsiz = rt->bsiz += BUFSIZ;
944                                  rt->buf = (char *)realloc(rt->buf, rt->bsiz);
945                          }
946                          if (rt->buf == NULL)
# Line 946 | Line 981 | trace_contribs(FILE *fin)
981          struct rtproc   *rtp;
982                                                  /* loop over input */
983          while ((iblen = getinp(inpbuf, fin)) > 0) {
984 <                if (lastray+1 < lastray) {      /* counter rollover? */
984 >                if (lastray+1 < lastray ||      /* need reset? */
985 >                                queue_length() > 5*nrtprocs()) {
986                          while (wait_rproc() != NULL)
987                                  process_queue();
988                          lastdone = lastray = 0;
# Line 1091 | Line 1127 | recover_output(FILE *fin)
1127                  error(WARNING, "no output files to recover");
1128                  return;
1129          }
1130 +        if (raysleft && lastout >= raysleft) {
1131 +                error(WARNING, "output appears to be complete");
1132 +                /* XXX should read & discard input? */
1133 +                quit(0);
1134 +        }
1135                                                  /* seek on all files */
1136          nvals = lastout * outvsiz;
1137          lu_doall(&ofiletab, myseeko, &nvals);
1138 <                                                /* discard input */
1138 >                                                /* skip repeated input */
1139          for (nvals = 0; nvals < lastout; nvals++)
1140                  if (getinp(oname, fin) <= 0)
1141                          error(USER, "unexpected EOF on input");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines