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.17 by greg, Fri Jun 10 16:42:11 2005 UTC vs.
Revision 1.25 by greg, Tue Sep 13 22:58:22 2005 UTC

# Line 16 | Line 16 | static const char RCSid[] = "$Id$";
16   #include  "lookup.h"
17   #include  "calcomp.h"
18  
19 + #ifndef MAXMODLIST
20   #define MAXMODLIST      1024            /* maximum modifiers we'll track */
21 + #endif
22  
23   int     treebufsiz = BUFSIZ;            /* current tree buffer size */
24  
# Line 72 | Line 74 | struct rtproc {
74   };                              /* rtrace process buffer */
75  
76                                          /* rtrace command and defaults */
77 < char            *rtargv[256] = { "rtrace", "-dj", ".5", "-dr", "3",
77 > char            *rtargv[256+2*MAXMODLIST] = { "rtrace",
78 >                                "-dj", ".5", "-dr", "3",
79                                  "-ab", "1", "-ad", "128", };
80   int  rtargc = 9;
81                                          /* overriding rtrace options */
# Line 170 | Line 173 | main(int argc, char *argv[])
173          char    *binval = NULL;
174          char    fmt[8];
175          int     i, j;
176 +                                /* need at least one argument */
177 +        if (argc < 2) {
178 +                fprintf(stderr,
179 + "Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n",
180 +                        argv[0]);
181 +                exit(1);
182 +        }
183                                  /* global program name */
184          gargv = argv;
185                                  /* initialize calcomp routines */
# Line 193 | Line 203 | main(int argc, char *argv[])
203                                  recover++;
204                                  continue;
205                          case 'n':               /* number of processes */
206 <                                if (argv[i][2] || i >= argc-1) break;
206 >                                if (argv[i][2] || i >= argc-2) break;
207                                  nprocs = atoi(argv[++i]);
208                                  if (nprocs <= 0)
209                                          error(USER, "illegal number of processes");
# Line 218 | Line 228 | main(int argc, char *argv[])
228                          case 'f':               /* file or i/o format */
229                                  if (!argv[i][2]) {
230                                          char    *fpath;
231 <                                        if (i >= argc-1) break;
231 >                                        if (i >= argc-2) break;
232                                          fpath = getpath(argv[++i],
233                                                          getrlibpath(), R_OK);
234                                          if (fpath == NULL) {
# Line 233 | Line 243 | main(int argc, char *argv[])
243                                  setformat(argv[i]+2);
244                                  continue;
245                          case 'e':               /* expression */
246 <                                if (argv[i][2] || i >= argc-1) break;
246 >                                if (argv[i][2] || i >= argc-2) break;
247                                  scompile(argv[++i], NULL, 0);
248                                  continue;
249                          case 'o':               /* output file spec. */
250 <                                if (argv[i][2] || i >= argc-1) break;
250 >                                if (argv[i][2] || i >= argc-2) break;
251                                  curout = argv[++i];
252                                  continue;
253                          case 'x':               /* horiz. output resolution */
254 <                                if (argv[i][2] || i >= argc-1) break;
254 >                                if (argv[i][2] || i >= argc-2) break;
255                                  xres = atoi(argv[++i]);
256                                  continue;
257                          case 'y':               /* vert. output resolution */
258 <                                if (argv[i][2] || i >= argc-1) break;
258 >                                if (argv[i][2] || i >= argc-2) break;
259                                  yres = atoi(argv[++i]);
260                                  continue;
261                          case 'b':               /* bin expression */
262 <                                if (argv[i][2] || i >= argc-1) break;
262 >                                if (argv[i][2] || i >= argc-2) break;
263                                  binval = argv[++i];
264                                  continue;
265                          case 'm':               /* modifier name */
266 <                                if (argv[i][2] || i >= argc-1) break;
266 >                                if (argv[i][2] || i >= argc-2) break;
267                                  rtargv[rtargc++] = "-ti";
268                                  rtargv[rtargc++] = argv[++i];
269                                  addmodifier(argv[i], curout, binval);
270                                  continue;
271                          case 'M':               /* modifier file */
272 <                                if (argv[i][2] || i >= argc-1) break;
273 <                                addmodfile(argv[++i], curout, binval);
272 >                                if (argv[i][2] || i >= argc-2) break;
273 >                                rtargv[rtargc++] = "-tI";
274 >                                rtargv[rtargc++] = argv[++i];
275 >                                addmodfile(argv[i], curout, binval);
276                                  continue;
277                          }
278                  rtargv[rtargc++] = argv[i];     /* assume rtrace option */
# Line 310 | Line 322 | main(int argc, char *argv[])
322                  error(USER, "missing octree argument");
323          rtargv[rtargc++] = octree = argv[i];
324          rtargv[rtargc] = NULL;
325 <                                /* start rtrace & compute contributions */
325 >                                /* start rtrace */
326          init(nprocs);
327          if (recover)            /* perform recovery if requested */
328                  recover_output(stdin);
329 <        trace_contribs(stdin);
329 >        trace_contribs(stdin);  /* compute contributions */
330          quit(0);
331   }
332  
# Line 463 | Line 475 | addmodfile(char *fname, char *outf, char *binv)
475   {
476          char    *mname[MAXMODLIST];
477          int     i;
478 <                                        /* load the file & store strings */
479 <        wordfile(mname, fname);
478 >                                        /* find the file & store strings */
479 >        if (wordfile(mname, getpath(fname, getrlibpath(), R_OK)) < 0) {
480 >                sprintf(errmsg, "cannot find modifier file '%s'", fname);
481 >                error(SYSTEM, errmsg);
482 >        }
483          for (i = 0; mname[i]; i++)      /* add each one */
484                  addmodifier(mname[i], outf, binv);
485   }
# Line 615 | Line 630 | getofile(const char *ospec, const char *mname, int bn)
630                  if (header) {
631                          char    info[512];
632                          char    *cp = info;
633 <                        if (ofl & OF_MODIFIER) {
634 <                                sprintf(cp, "MODIFIER=%s\n", mname);
620 <                                while (*cp) ++cp;
621 <                        }
633 >                        sprintf(cp, "MODIFIER=%s\n", mname);
634 >                        while (*cp) ++cp;
635                          if (ofl & OF_BIN) {
636                                  sprintf(cp, "BIN=%d\n", bn);
637                                  while (*cp) ++cp;
# Line 1024 | Line 1037 | recover_output(FILE *fin)
1037                                  error(USER, "cannot recover from command");
1038                                                  /* open output */
1039                          fp = fopen(oname, "rb+");
1040 <                        if (fp == NULL)
1041 <                                break;          /* must be end of modifier */
1040 >                        if (fp == NULL) {
1041 >                                if (j)
1042 >                                        break;  /* assume end of modifier */
1043 >                                sprintf(errmsg, "missing recover file '%s'",
1044 >                                                oname);
1045 >                                error(USER, errmsg);
1046 >                        }
1047                          nvals = lseek(fileno(fp), 0, SEEK_END);
1048                          if (nvals <= 0) {
1049                                  lastout = 0;    /* empty output, quit here */
# Line 1079 | Line 1097 | recover_output(FILE *fin)
1097          if (lastout < 0) {
1098                  error(WARNING, "no output files to recover");
1099                  return;
1100 +        }
1101 +        if (raysleft && lastout >= raysleft) {
1102 +                error(WARNING, "output appears to be complete");
1103 +                /* XXX should read & discard input? */
1104 +                quit(0);
1105          }
1106                                                  /* seek on all files */
1107          nvals = lastout * outvsiz;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines