--- ray/src/util/rad.c 2010/05/28 17:29:14 2.97 +++ ray/src/util/rad.c 2011/02/25 06:51:51 2.105 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rad.c,v 2.97 2010/05/28 17:29:14 greg Exp $"; +static const char RCSid[] = "$Id: rad.c,v 2.105 2011/02/25 06:51:51 greg Exp $"; #endif /* * Executive program for oconv, rpict and pfilt @@ -165,7 +165,7 @@ static int touch(char *fn); static int runcom(char *cs); static int rmfile(char *fn); static int mvfile(char *fold, char *fnew); -static int next_process(void); +static int next_process(int reserve); static void wait_process(int all); static void finish_process(void); static void badvalue(int vc); @@ -751,7 +751,7 @@ lowqopts( /* low quality rendering options */ op = addarg(op, "-ds .4"); else op = addarg(op, "-ds 0"); - op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5"); + op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5"); if (vdef(AMBFILE)) { sprintf(op, " -af %s", vval(AMBFILE)); op += strlen(op); @@ -772,7 +772,7 @@ lowqopts( /* low quality rendering options */ d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 6 -lw .01"); + op = addarg(op, "-lr 6 -lw .003"); } @@ -826,7 +826,7 @@ medqopts( /* medium quality rendering options */ op = addarg(op, "-ds .2 -dj .9"); else op = addarg(op, "-ds .3"); - op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); + op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1"); if ( (overture = vint(INDIRECT)) ) { sprintf(op, " -ab %d", overture); op += strlen(op); @@ -850,7 +850,7 @@ medqopts( /* medium quality rendering options */ d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 8 -lw .002"); + op = addarg(op, "-lr 8 -lw 1e-4"); } @@ -904,7 +904,7 @@ hiqopts( /* high quality rendering options */ op = addarg(op, "-ds .1 -dj .9"); else op = addarg(op, "-ds .2"); - op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); + op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01"); sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); op += strlen(op); if (vdef(AMBFILE)) { @@ -926,7 +926,7 @@ hiqopts( /* high quality rendering options */ d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 12 -lw .0005"); + op = addarg(op, "-lr 12 -lw 1e-5"); } @@ -1261,15 +1261,18 @@ rpict( /* run rpict and pfilt for each view */ ) { #define do_rpiece (sfile[0]!='\0') - char combuf[4*PATH_MAX+512]; + char combuf[5*PATH_MAX+512]; char rawfile[PATH_MAX], picfile[PATH_MAX]; char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; - char rppopt[128], sfile[64], *pfile = NULL; + char rppopt[32], sfile[PATH_MAX], *pfile = NULL; char pfopts[128]; char vs[32], *vw; int vn, mult; FILE *fp; time_t rfdt, pfdt; + int xres, yres; + double aspect; + int n; /* get pfilt options */ pfiltopts(pfopts); /* get resolution, reporting */ @@ -1284,24 +1287,19 @@ rpict( /* run rpict and pfilt for each view */ mult = 3; break; } - { - int xres, yres; - double aspect; - int n; - n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); - if (n == 3) - sprintf(res, "-x %d -y %d -pa %.3f", - mult*xres, mult*yres, aspect); - else if (n) { - if (n == 1) yres = xres; - sprintf(res, "-x %d -y %d", mult*xres, mult*yres); - } else - badvalue(RESOLUTION); - } + n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); + if (n == 3) + sprintf(res, "-x %d -y %d -pa %.3f", + mult*xres, mult*yres, aspect); + else if (n) { + aspect = 1.; + if (n == 1) yres = xres; + sprintf(res, "-x %d -y %d", mult*xres, mult*yres); + } else + badvalue(RESOLUTION); rep[0] = '\0'; if (vdef(REPORT)) { double minutes; - int n; n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); if (n == 2) sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); @@ -1316,7 +1314,9 @@ rpict( /* run rpict and pfilt for each view */ getview(0, vs) != NULL) { if (!strcmp(c_rpict, DEF_RPICT_PATH) && getview(1, NULL) == NULL) { - sprintf(sfile, "rpsync_%s.txt", vs); + sprintf(sfile, "%s_%s_rpsync.txt", + vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), + vs); strcpy(rppopt, "-PP pfXXXXXX"); } else { strcpy(rppopt, "-S 1 -PP pfXXXXXX"); @@ -1359,7 +1359,15 @@ rpict( /* run rpict and pfilt for each view */ if (do_rpiece) { if (rfdt < oct1date || !fdate(sfile)) { int xdiv = 8+nprocs/3, ydiv = 8+nprocs/3; - rfdt = 0; /* start fresh */ + if (rfdt >= oct1date) { + fprintf(stderr, + "%s: partial output not created with rpiece\n", rawfile); + quit(1); + } + if (rfdt) { /* start fresh */ + rmfile(rawfile); + rfdt = 0; + } if (!silent) printf("\techo %d %d > %s\n", xdiv, ydiv, sfile); @@ -1371,7 +1379,7 @@ rpict( /* run rpict and pfilt for each view */ fprintf(fp, "%d %d\n", xdiv, ydiv); fclose(fp); } - } else if (next_process()) { + } else if (next_process(0)) { if (pfile != NULL) sleep(10); continue; @@ -1384,8 +1392,7 @@ rpict( /* run rpict and pfilt for each view */ sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s", c_rpiece, sfile, rppopt, rep, vw, res, opts, po, rawfile, oct1name); - while (children_running < nprocs-1 && - next_process()) { + while (next_process(1)) { sleep(10); combuf[strlen(c_rpiece)+2] = 'F'; } @@ -1397,33 +1404,27 @@ rpict( /* run rpict and pfilt for each view */ } else { if (overture) { /* run overture calculation */ sprintf(combuf, - "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", + "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", c_rpict, rep, vw, opts, oct1name, overfile); - if (do_rpiece) - while (children_running < nprocs-1 && - next_process()) - sleep(5); - if (runcom(combuf)) { - fprintf(stderr, + if (!do_rpiece || !next_process(0)) { + if (runcom(combuf)) { + fprintf(stderr, "%s: error in overture for view %s\n", - progname, vs); - quit(1); - } - if (do_rpiece) { - finish_process(); - wait_process(1); - } + progname, vs); + quit(1); + } #ifndef NULL_DEVICE - rmfile(overfile); + rmfile(overfile); #endif + } else if (do_rpiece) + sleep(20); } if (do_rpiece) { sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s", c_rpiece, sfile, rppopt, rep, vw, res, opts, po, rawfile, oct1name); - while (children_running < nprocs-1 && - next_process()) + while (next_process(1)) sleep(10); } else { sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", @@ -1453,7 +1454,12 @@ rpict( /* run rpict and pfilt for each view */ } if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { /* build pfilt command */ - if (mult > 1) + if (do_rpiece) + sprintf(combuf, + "%s%s -x %d -y %d -p %.3f %s > %s", + c_pfilt, pfopts, xres, yres, aspect, + rawfile, picfile); + else if (mult > 1) sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", c_pfilt, pfopts, mult, mult, rawfile, picfile); @@ -1554,7 +1560,7 @@ mvfile( /* move a file */ #ifdef RHAS_FORK_EXEC static int -next_process(void) /* fork the next process (max. nprocs) */ +next_process(int reserve) /* fork the next process */ { RT_PID child_pid; @@ -1565,12 +1571,15 @@ next_process(void) /* fork the next process (max. np progname); quit(1); } + if (reserve > 0 && children_running >= nprocs-reserve) + return(0); /* caller holding back process(es) */ if (children_running >= nprocs) wait_process(0); /* wait for someone to finish */ fflush(NULL); /* flush output */ child_pid = fork(); /* split process */ if (child_pid == 0) { /* we're the child */ children_running = -1; + nprocs = 1; return(0); } if (child_pid > 0) { /* we're the parent */ @@ -1612,7 +1621,7 @@ wait_process( /* wait for process(es) to finish */ } #else /* ! RHAS_FORK_EXEC */ static int -next_process(void) +next_process(int reserve) { return(0); /* cannot start new process */ }