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.20 by greg, Fri Jun 10 20:53:55 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 196 | Line 218 | main(int argc, char *argv[])
218                                  recover++;
219                                  continue;
220                          case 'n':               /* number of processes */
221 <                                if (argv[i][2] || i >= argc-1) break;
221 >                                if (argv[i][2] || i >= argc-2) break;
222                                  nprocs = atoi(argv[++i]);
223                                  if (nprocs <= 0)
224                                          error(USER, "illegal number of processes");
# Line 221 | Line 243 | main(int argc, char *argv[])
243                          case 'f':               /* file or i/o format */
244                                  if (!argv[i][2]) {
245                                          char    *fpath;
246 <                                        if (i >= argc-1) break;
246 >                                        if (i >= argc-2) break;
247                                          fpath = getpath(argv[++i],
248                                                          getrlibpath(), R_OK);
249                                          if (fpath == NULL) {
# Line 236 | Line 258 | main(int argc, char *argv[])
258                                  setformat(argv[i]+2);
259                                  continue;
260                          case 'e':               /* expression */
261 <                                if (argv[i][2] || i >= argc-1) break;
261 >                                if (argv[i][2] || i >= argc-2) break;
262                                  scompile(argv[++i], NULL, 0);
263                                  continue;
264                          case 'o':               /* output file spec. */
265 <                                if (argv[i][2] || i >= argc-1) break;
265 >                                if (argv[i][2] || i >= argc-2) break;
266                                  curout = argv[++i];
267                                  continue;
268                          case 'x':               /* horiz. output resolution */
269 <                                if (argv[i][2] || i >= argc-1) break;
269 >                                if (argv[i][2] || i >= argc-2) break;
270                                  xres = atoi(argv[++i]);
271                                  continue;
272                          case 'y':               /* vert. output resolution */
273 <                                if (argv[i][2] || i >= argc-1) break;
273 >                                if (argv[i][2] || i >= argc-2) break;
274                                  yres = atoi(argv[++i]);
275                                  continue;
276                          case 'b':               /* bin expression */
277 <                                if (argv[i][2] || i >= argc-1) break;
277 >                                if (argv[i][2] || i >= argc-2) break;
278                                  binval = argv[++i];
279                                  continue;
280                          case 'm':               /* modifier name */
281 <                                if (argv[i][2] || i >= argc-1) break;
281 >                                if (argv[i][2] || i >= argc-2) break;
282                                  rtargv[rtargc++] = "-ti";
283                                  rtargv[rtargc++] = argv[++i];
284                                  addmodifier(argv[i], curout, binval);
285                                  continue;
286                          case 'M':               /* modifier file */
287 <                                if (argv[i][2] || i >= argc-1) break;
287 >                                if (argv[i][2] || i >= argc-2) break;
288                                  rtargv[rtargc++] = "-tI";
289                                  rtargv[rtargc++] = argv[++i];
290                                  addmodfile(argv[i], curout, binval);
# 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 634 | 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 708 | 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 907 | 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 948 | 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 1032 | Line 1066 | recover_output(FILE *fin)
1066                                  error(USER, "cannot recover from command");
1067                                                  /* open output */
1068                          fp = fopen(oname, "rb+");
1069 <                        if (fp == NULL)
1070 <                                break;          /* must be end of modifier */
1069 >                        if (fp == NULL) {
1070 >                                if (j)
1071 >                                        break;  /* assume end of modifier */
1072 >                                sprintf(errmsg, "missing recover file '%s'",
1073 >                                                oname);
1074 >                                error(USER, errmsg);
1075 >                        }
1076                          nvals = lseek(fileno(fp), 0, SEEK_END);
1077                          if (nvals <= 0) {
1078                                  lastout = 0;    /* empty output, quit here */
# Line 1088 | 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