--- ray/src/util/rtcontrib.c 2009/06/11 18:32:24 1.53 +++ ray/src/util/rtcontrib.c 2010/09/26 15:44:00 1.57 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.53 2009/06/11 18:32:24 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.57 2010/09/26 15:44:00 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -14,6 +14,7 @@ static const char RCSid[] = "$Id: rtcontrib.c,v 1.53 2 #include "color.h" #include "resolu.h" #include "lookup.h" +#include "random.h" #include "calcomp.h" #ifndef MAXMODLIST @@ -340,7 +341,7 @@ main(int argc, char *argv[]) case 'b': /* bin expression/count */ if (i >= argc-2) break; if (argv[i][2] == 'n') { - bincnt = atoi(argv[++i]); + bincnt = (int)(eval(argv[++i]) + .5); continue; } if (argv[i][2]) break; @@ -378,14 +379,16 @@ main(int argc, char *argv[]) rtargv[rtargc++] = contrib ? RTCONTRIB : RTCOEFF; /* just asking for defaults? */ if (!strcmp(argv[i], "-defaults")) { - char sxres[16], syres[16]; + char nps[8], sxres[16], syres[16]; char *rtpath; - printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); printf("-c %-5d\t\t\t# accumulated rays per record\n", accumulate); printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', contrib ? "contributions" : "coefficients"); fflush(stdout); /* report OUR options */ + rtargv[rtargc++] = "-n"; + sprintf(nps, "%d", nprocs); + rtargv[rtargc++] = nps; rtargv[rtargc++] = header ? "-h+" : "-h-"; sprintf(fmt, "-f%c%c", inpfmt, outfmt); rtargv[rtargc++] = fmt; @@ -543,7 +546,7 @@ init(int np) raysleft = 0; if ((account = accumulate) > 0) raysleft *= accumulate; - waitflush = xres; + waitflush = (yres > 0) & (xres > 1) ? 0 : xres; if (!recover) return; /* recover previous values */ @@ -580,7 +583,7 @@ addmodifier(char *modn, char *outf, char *binv, int bi error(USER, errmsg); } if (nmods >= MAXMODLIST) - error(USER, "too many modifiers"); + error(INTERNAL, "too many modifiers"); modname[nmods++] = modn; /* XXX assumes static string */ lep->key = modn; /* XXX assumes static string */ mp = (MODCONT *)malloc(sizeof(MODCONT)); @@ -588,15 +591,20 @@ addmodifier(char *modn, char *outf, char *binv, int bi error(SYSTEM, "out of memory in addmodifier"); mp->outspec = outf; /* XXX assumes static string */ mp->modname = modn; /* XXX assumes static string */ - if (binv != NULL) - mp->binv = eparse(binv); - else - mp->binv = eparse("0"); - mp->nbins = 1; + if (binv == NULL) + binv = "0"; /* use single bin if unspecified */ + mp->binv = eparse(binv); + if (mp->binv->type == NUM) { /* check value if constant */ + bincnt = (int)(evalue(mp->binv) + 1.5); + if (bincnt != 1) { + sprintf(errmsg, "illegal non-zero constant for bin (%s)", + binv); + error(USER, errmsg); + } + } + mp->nbins = 1; /* initialize results holder */ setcolor(mp->cbin[0], 0., 0., 0.); - if (mp->binv->type == NUM) /* assume one bin if constant */ - bincnt = 1; - else if (bincnt > 1) + if (bincnt > 1) mp = growmodifier(mp, bincnt); lep->data = (char *)mp; /* allocate output streams */ @@ -659,6 +667,10 @@ ofname(char *oname, const char *ospec, const char *mna mnp = cp; break; case 'd': + case 'i': + case 'o': + case 'x': + case 'X': if (bnp != NULL) return -1; bnp = cp; @@ -725,8 +737,6 @@ printresolu(FILE *fout, int xr, int yr) { if ((xr > 0) & (yr > 0)) /* resolution string */ fprtresolu(xr, yr, fout); - if (xres > 0) /* global flush flag */ - fflush(fout); } /* Get output stream pointer (open and write header if new and noopen==0) */ @@ -747,6 +757,8 @@ getostream(const char *ospec, const char *mname, int b if (header) printheader(stdout, NULL); printresolu(stdout, xres, yres); + if (waitflush > 0) + fflush(stdout); stdos.xr = xres; stdos.yr = yres; using_stdout = 1; } @@ -815,7 +827,7 @@ getostream(const char *ospec, const char *mname, int b if (outfmt == 'a') putc('\n', sop->ofp); } - if (xres > 0) + if (waitflush > 0) fflush(sop->ofp); } sop->reclen += noopen; /* add to length if noopen */ @@ -945,6 +957,8 @@ put_contrib(const DCOLOR cnt, FILE *fout) default: error(INTERNAL, "botched output format"); } + if (waitflush < 0 && frandom() < 0.001) + fflush(fout); /* staggers writes */ } /* output ray tallies and clear for next accumulation */ @@ -982,7 +996,7 @@ done_contrib(int navg) if (using_stdout & (outfmt == 'a')) putc('\n', stdout); if (!waitflush) { - waitflush = xres; + waitflush = (yres > 0) & (xres > 1) ? 0 : xres; if (using_stdout) fflush(stdout); }