--- ray/src/util/rtcontrib.c 2005/10/11 23:41:45 1.37 +++ ray/src/util/rtcontrib.c 2006/04/05 14:33:34 1.42 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.37 2005/10/11 23:41:45 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.42 2006/04/05 14:33:34 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -101,12 +101,16 @@ struct rtproc { /* rtrace command and defaults */ char *rtargv[256+2*MAXMODLIST] = { "rtrace", "-dj", ".5", "-dr", "3", - "-ab", "1", "-ad", "128", }; + "-ab", "1", "-ad", "350", }; + int rtargc = 9; /* overriding rtrace options */ -char *myrtopts[] = { "-o~~TmWdp", "-h-", "-x", "1", "-y", "0", +char *myrtopts[] = { "-h-", "-x", "1", "-y", "0", "-dt", "0", "-as", "0", "-aa", "0", NULL }; +#define RTCOEFF "-o~~TmWdp" /* compute coefficients only */ +#define RTCONTRIB "-o~~TmVdp" /* compute ray contributions */ + struct rtproc rt0; /* head of rtrace process list */ struct rtproc *rt_unproc = NULL; /* unprocessed ray trees */ @@ -208,6 +212,7 @@ fmterr: int main(int argc, char *argv[]) { + int contrib = 0; int nprocs = 1; int recover = 0; char *curout = NULL; @@ -218,7 +223,7 @@ main(int argc, char *argv[]) /* need at least one argument */ if (argc < 2) { fprintf(stderr, -"Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", +"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", argv[0]); exit(1); } @@ -240,16 +245,33 @@ main(int argc, char *argv[]) } if (argv[i][0] == '-') switch (argv[i][1]) { - case 'r': /* recover output */ - if (argv[i][2]) break; - recover++; - continue; case 'n': /* number of processes */ if (argv[i][2] || i >= argc-2) break; nprocs = atoi(argv[++i]); if (nprocs <= 0) error(USER, "illegal number of processes"); continue; + case 'V': /* output contributions */ + switch (argv[i][2]) { + case '\0': + contrib = !contrib; + continue; + case '+': case '1': + case 'T': case 't': + case 'Y': case 'y': + contrib = 1; + continue; + case '-': case '0': + case 'F': case 'f': + case 'N': case 'n': + contrib = 0; + continue; + } + break; + case 'r': /* recover output */ + if (argv[i][2]) break; + recover++; + continue; case 'h': /* output header? */ switch (argv[i][2]) { case '\0': @@ -325,6 +347,9 @@ main(int argc, char *argv[]) rtargv[rtargc++] = argv[++i]; addmodfile(argv[i], curout, binval, bincnt); continue; + case 'P': /* persist file */ + error(USER, "persist file is automatic"); + break; } rtargv[rtargc++] = argv[i]; /* assume rtrace option */ } @@ -333,11 +358,14 @@ main(int argc, char *argv[]) /* add "mandatory" rtrace settings */ for (j = 0; myrtopts[j] != NULL; j++) rtargv[rtargc++] = myrtopts[j]; + rtargv[rtargc++] = contrib ? RTCONTRIB : RTCOEFF; /* just asking for defaults? */ if (!strcmp(argv[i], "-defaults")) { char sxres[16], syres[16]; char *rtpath; printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); + printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', + contrib ? "contributions" : "coefficients"); fflush(stdout); /* report OUR options */ rtargv[rtargc++] = header ? "-h+" : "-h-"; sprintf(fmt, "-f%c%c", inpfmt, outfmt); @@ -348,7 +376,6 @@ main(int argc, char *argv[]) rtargv[rtargc++] = "-y"; sprintf(syres, "%d", yres); rtargv[rtargc++] = syres; - rtargv[rtargc++] = "-oTW"; rtargv[rtargc++] = "-defaults"; rtargv[rtargc] = NULL; rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); @@ -540,7 +567,7 @@ addmodifier(char *modn, char *outf, char *binv, int bi mp = growmodifier(mp, bincnt); lep->data = (char *)mp; /* allocate output streams */ - for (i = outf==NULL || outf[0]=='!' ? 0 : bincnt; i--; ) + for (i = outf==NULL || outf[0]=='!' ? 0 : bincnt; i-- > 0; ) getostream(mp->outspec, mp->modname, i, 1); return mp; } @@ -958,7 +985,9 @@ process_queue(void) if (!n || !(isalpha(*cp) | (*cp == '_'))) error(USER, "bad modifier name from rtrace"); /* get modifier name */ - while (n > 0 && *cp != '\t') { + while (n > 1 && *cp != '\t') { + if (mnp - modname >= sizeof(modname)-2) + error(INTERNAL, "modifier name too long"); *mnp++ = *cp++; n--; } *mnp = '\0'; @@ -1076,12 +1105,12 @@ trace_contribs(FILE *fin) writebuf(rtp->pd.w, inpbuf, iblen); } else { /* else bypass dummy ray */ queue_raytree(rtp); /* empty tree */ - if ((yres <= 0) | (waitflush > 0)) + if ((yres <= 0) | (waitflush > 1)) waitflush = 1; /* flush after this */ } - if (raysleft && !--raysleft) - break; process_queue(); /* catch up with results */ + if (raysleft && !--raysleft) + break; /* preemptive EOI */ } while (wait_rproc() != NULL) /* process outstanding rays */ process_queue();