--- ray/src/util/ranimate.c 1996/01/19 17:24:19 2.3 +++ ray/src/util/ranimate.c 1996/05/21 14:27:19 2.13 @@ -1,4 +1,4 @@ -/* Copyright (c) 1995 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -15,6 +15,12 @@ static char SCCSid[] = "$SunId$ LBL"; #include "view.h" #include "vars.h" #include "netproc.h" + /* default remote shell */ +#ifdef _AUX_SOURCE +#define REMSH "remsh" +#else +#define REMSH "rsh" +#endif /* input variables */ #define HOST 0 /* rendering host machine */ #define RENDER 1 /* rendering options */ @@ -38,8 +44,9 @@ static char SCCSid[] = "$SunId$ LBL"; #define DISKSPACE 19 /* how much disk space to use */ #define RESOLUTION 20 /* desired final resolution */ #define EXPOSURE 21 /* how to compute exposure */ +#define RSH 22 /* remote shell script or program */ -int NVARS = 22; /* total number of variables */ +int NVARS = 23; /* total number of variables */ VARIABLE vv[] = { /* variable-value pairs */ {"host", 4, 0, NULL, NULL}, @@ -57,13 +64,14 @@ VARIABLE vv[] = { /* variable-value pairs */ {"ANIMATE", 2, 0, NULL, onevalue}, {"TRANSFER", 2, 0, NULL, onevalue}, {"ARCHIVE", 2, 0, NULL, onevalue}, - {"INTERP", 3, 0, NULL, intvalue}, - {"OVERSAMP", 2, 0, NULL, fltvalue}, + {"INTERPOLATE", 3, 0, NULL, intvalue}, + {"OVERSAMPLE", 2, 0, NULL, fltvalue}, {"MBLUR", 2, 0, NULL, onevalue}, {"RTRACE", 2, 0, NULL, boolvalue}, {"DISKSPACE", 3, 0, NULL, fltvalue}, {"RESOLUTION", 3, 0, NULL, onevalue}, {"EXPOSURE", 3, 0, NULL, onevalue}, + {"RSH", 3, 0, NULL, onevalue}, }; #define SFNAME "STATUS" /* status file name */ @@ -84,11 +92,15 @@ int nowarn = 0; /* turn warnings off? */ int silent = 0; /* silent mode? */ int noaction = 0; /* take no action? */ +char *remsh; /* remote shell program/script */ char rendopt[2048] = ""; /* rendering options */ char rresopt[32]; /* rendering resolution options */ char fresopt[32]; /* filter resolution options */ int pfiltalways; /* always use pfilt? */ +char arcargs[10240]; /* files to archive */ +char *arcfirst, *arcnext; /* pointers to first and next argument */ + struct pslot { int pid; /* process ID (0 if empty) */ int fout; /* output frame number */ @@ -99,12 +111,16 @@ int npslots; /* number of process slots */ int lastpid; /* ID of last completed background process */ PSERVER *lastpserver; /* last process server used */ +#define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) + struct pslot *findpslot(); VIEW *getview(); char *getexp(); +extern time_t fdate(), time(); + main(argc, argv) int argc; char *argv[]; @@ -161,8 +177,11 @@ char *argv[]; argv[i] = vval(NEXTANIM); /* just change input file */ if (!silent) printargs(argc, argv, stdout); - execvp(progname, argv); /* pass to next */ - quit(1); /* shouldn't return */ + if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) + fprintf(stderr, "%s: command not found\n", progname); + else + execv(progname, argv); + quit(1); } quit(0); userr: @@ -173,13 +192,13 @@ userr: getastat() /* check/set animation status */ { - char buf[256]; + char sfname[256]; FILE *fp; - sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); - if ((fp = fopen(buf, "r")) == NULL) { + sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); + if ((fp = fopen(sfname, "r")) == NULL) { if (errno != ENOENT) { - perror(buf); + perror(sfname); return(-1); } astat.rnext = astat.fnext = astat.tnext = 0; @@ -199,8 +218,7 @@ getastat() /* check/set animation status */ goto fmterr; fclose(fp); if (astat.pid != 0) { /* thinks it's still running */ - gethostname(buf, sizeof(buf)); - if (strcmp(buf, astat.host)) { + if (strcmp(myhostname(), astat.host)) { fprintf(stderr, "%s: process %d may still be running on host %s\n", progname, astat.pid, astat.host); @@ -218,14 +236,19 @@ getastat() /* check/set animation status */ progname, astat.cfname); return(-1); } + /* check control file mods. */ + if (!nowarn && fdate(cfname) > fdate(sfname)) + fprintf(stderr, + "%s: warning - control file modified since last run\n", + progname); setours: /* set our values */ - gethostname(astat.host, sizeof(astat.host)); + strcpy(astat.host, myhostname()); astat.pid = getpid(); strcpy(astat.cfname, cfname); return(0); fmterr: fprintf(stderr, "%s: format error in status file \"%s\"\n", - progname, buf); + progname, sfname); fclose(fp); return(-1); } @@ -277,6 +300,7 @@ checkdir() /* make sure we have our directory */ setdefaults() /* set default values */ { + extern char *atos(); char buf[256]; if (vdef(ANIMATE)) { @@ -300,10 +324,15 @@ setdefaults() /* set default values */ vdef(START)++; } if (!vdef(END)) { - sprintf(buf, "%d", countviews()); + sprintf(buf, "%d", countviews()+vint(START)-1); vval(END) = savqstr(buf); vdef(END)++; } + if (vint(END) < vint(START)) { + fprintf(stderr, "%s: ending frame less than starting frame\n", + progname); + quit(1); + } if (!vdef(BASENAME)) { sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); vval(BASENAME) = savqstr(buf); @@ -337,6 +366,17 @@ setdefaults() /* set default values */ vval(DISKSPACE) = "100"; vdef(DISKSPACE)++; } + if (!vdef(RSH)) { + vval(RSH) = REMSH; + vdef(RSH)++; + } + /* locate remote shell program */ + atos(buf, sizeof(buf), vval(RSH)); + if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) + remsh = savqstr(remsh); + else + remsh = vval(RSH); /* will generate error if used */ + /* append rendering options */ if (vdef(RENDER)) sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); @@ -399,8 +439,8 @@ sethosts() /* set up process servers */ } -getradfile(rfname) /* run rad and get needed variables */ -char *rfname; +getradfile(rfargs) /* run rad and get needed variables */ +char *rfargs; { static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; char combuf[256]; @@ -410,7 +450,7 @@ char *rfname; sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); sprintf(combuf, "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", - rfname, rendopt+2); + rfargs, rendopt+2); cp = combuf; while (*cp) cp++; /* match unset variables */ for (i = 0; mvar[i] >= 0; i++) @@ -422,8 +462,8 @@ char *rfname; sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); cp += 11; /* point to file name */ if (system(combuf)) { - fprintf(stderr, "%s: bad rad input file \"%s\"\n", - progname, rfname); + fprintf(stderr, "%s: error executing rad command:\n\t%s\n", + progname, combuf); quit(1); } loadvars(cp); /* load variables and remove file */ @@ -472,7 +512,7 @@ animate() /* run animation */ /* figure # frames per batch */ d1 = mult*xres*mult*yres*4; /* space for orig. picture */ if ((i=vint(INTERP)) || atoi(vval(MBLUR))) - d1 += mult*xres*mult*yres*4; /* space for z-buffer */ + d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ d2 = xres*yres*4; /* space for final picture */ frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); if (frames_batch < i+2) { @@ -480,6 +520,11 @@ animate() /* run animation */ progname); quit(1); } + /* initialize archive argument list */ + i = 16; + if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) + i = strlen(vval(ARCHIVE)); + arcnext = arcfirst = arcargs + i; /* initialize status file */ if (astat.rnext == 0) astat.rnext = astat.fnext = astat.tnext = vint(START); @@ -574,7 +619,7 @@ filterframes() /* catch up with filtering */ dofilt(i, vp, getexp(i), 0); /* filter frame */ } bwait(0); /* wait for filter processes */ - archive(astat.fnext, i-1); /* archive originals */ + archive(); /* archive originals */ astat.fnext = i; /* update status */ putastat(); } @@ -636,6 +681,7 @@ int first, last; char *vfn; { char combuf[2048]; + char *inspoint; register int i; if (!noaction && vint(INTERP)) /* create dummy frames */ @@ -646,13 +692,17 @@ char *vfn; close(open(combuf, O_RDONLY|O_CREAT, 0666)); } /* create command */ - sprintf(combuf, "rpict%s -w0 ", rendopt); + sprintf(combuf, "rpict%s -w0", rendopt); if (vint(INTERP) || atoi(vval(MBLUR))) - sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME)); - sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s", - vval(BASENAME), rresopt, first, vval(OCTREE), vfn); + sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); + sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", + vval(BASENAME), rresopt, first); + inspoint = combuf + strlen(combuf); + sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); /* run in parallel */ - if (pruncom(combuf, (last-first+1)/(vint(INTERP)+1))) { + i = (last-first+1)/(vint(INTERP)+1); + if (i < 1) i = 1; + if (pruncom(combuf, inspoint, i)) { fprintf(stderr, "%s: error rendering frames %d through %d\n", progname, first, last); quit(1); @@ -730,53 +780,27 @@ int frame; } -archive(first, last) /* archive and remove renderings */ -int first, last; +archive() /* archive and remove renderings */ { #define RMCOML (sizeof(rmcom)-1) static char rmcom[] = "rm -f"; - int offset = RMCOML; - char combuf[10240]; - struct stat stb; - register char *cp; register int i; - if (noaction) - return; - if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset) - offset = strlen(vval(ARCHIVE)); - cp = combuf + offset; - *cp++ = ' '; /* make argument list */ - for (i = first; i <= last; i++) { - sprintf(cp, vval(BASENAME), i); - strcat(cp, ".unf"); - if (stat(cp, &stb) == 0 && stb.st_size > 0) { /* non-zero? */ - while (*cp) cp++; - *cp++ = ' '; - sprintf(cp, vval(BASENAME), i); - strcat(cp, ".zbf"); - if (access(cp, F_OK) == 0) { /* exists? */ - while (*cp) cp++; - *cp++ = ' '; - } - } - } - *--cp = '\0'; - if (cp <= combuf + offset) /* no files? */ - return; + if (arcnext == arcfirst) + return; /* nothing to do */ if (vdef(ARCHIVE)) { /* run archive command */ i = strlen(vval(ARCHIVE)); - strncpy(combuf+offset-i, vval(ARCHIVE), i); - if (runcom(combuf+offset-i)) { - fprintf(stderr, - "%s: error running archive command on frames %d through %d\n", - progname, first, last); + strncpy(arcfirst-i, vval(ARCHIVE), i); + if (runcom(arcfirst-i)) { + fprintf(stderr, "%s: error running archive command\n", + progname); quit(1); } } /* run remove command */ - strncpy(combuf+offset-RMCOML, rmcom, RMCOML); - runcom(combuf+offset-RMCOML); + strncpy(arcfirst-RMCOML, rmcom, RMCOML); + runcom(arcfirst-RMCOML); + arcnext = arcfirst; /* reset argument list */ #undef RMCOML } @@ -789,13 +813,18 @@ char *ep; int rvr; { extern int frecover(); + static int iter = 0; char fnbefore[128], fnafter[128]; - char combuf[1024], fname[128]; - int usepinterp, usepfilt; + char combuf[1024], fname0[128], fname1[128]; + int usepinterp, usepfilt, nora_rgbe; int frseq[2]; /* check what is needed */ usepinterp = atoi(vval(MBLUR)); usepfilt = pfiltalways | ep==NULL; + if (ep != NULL && !strcmp(ep, "1")) + ep = "+0"; + nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || + *ep != '+' || *ep != '-' || !isint(ep); /* compute rendered views */ frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); frseq[1] = frseq[0] + vint(INTERP) + 1; @@ -804,11 +833,25 @@ int rvr; if (frseq[1] == frame) { /* pfilt only */ frseq[0] = frseq[1]; usepinterp = 0; /* update what's needed */ - usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); - } else if (frseq[0] == frame) { /* no interpolation */ - /* update what's needed */ - if (!usepinterp) - usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); + usepfilt |= nora_rgbe; + } else if (frseq[0] == frame) { /* no interpolation needed */ + if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ + *arcnext++ = ' '; + sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); + while (*arcnext) arcnext++; + strcpy(arcnext, ".unf"); + arcnext += 4; + if (usepinterp || vint(INTERP)) { /* and Z-buf */ + *arcnext++ = ' '; + sprintf(arcnext, vval(BASENAME), + frame-vint(INTERP)-1); + while (*arcnext) arcnext++; + strcpy(arcnext, ".zbf"); + arcnext += 4; + } + } + if (!usepinterp) /* update what's needed */ + usepfilt |= nora_rgbe; } else /* interpolation needed */ usepinterp++; if (frseq[1] >= astat.rnext) /* next batch unavailable */ @@ -823,9 +866,10 @@ int rvr; return(1); if (atoi(vval(MBLUR))) { FILE *fp; /* motion blurring */ - sprintf(fname, "%s/vw0", vval(DIRECTORY)); - if ((fp = fopen(fname, "w")) == NULL) { - perror(fname); quit(1); + sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), + 'a'+(iter%26)); + if ((fp = fopen(fname0, "w")) == NULL) { + perror(fname0); quit(1); } fputs(VIEWSTR, fp); fprintview(vp, fp); @@ -836,19 +880,20 @@ int rvr; progname, frame+1); quit(1); } - sprintf(fname, "%s/vw1", vval(DIRECTORY)); - if ((fp = fopen(fname, "w")) == NULL) { - perror(fname); quit(1); + sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), + 'a'+(iter%26)); + if ((fp = fopen(fname1, "w")) == NULL) { + perror(fname1); quit(1); } fputs(VIEWSTR, fp); fprintview(vp, fp); putc('\n', fp); fclose(fp); sprintf(combuf, - "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B", + "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", - atoi(vval(MBLUR)), vval(DIRECTORY), - vval(DIRECTORY), vval(DIRECTORY), - vval(DIRECTORY), vval(DIRECTORY)); + atoi(vval(MBLUR)), + fname0, fname1, fname0, fname1); + iter++; } else /* no blurring */ strcpy(combuf, "pinterp"); strcat(combuf, viewopt(vp)); @@ -895,11 +940,11 @@ int rvr; } else { /* else just check it */ if (rvr == 2) return(1); - sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore); + sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); } /* output file name */ - sprintf(fname, vval(BASENAME), frame); - sprintf(combuf+strlen(combuf), " > %s.pic", fname); + sprintf(fname0, vval(BASENAME), frame); + sprintf(combuf+strlen(combuf), " > %s.pic", fname0); if (rvr) /* in recovery */ return(runcom(combuf)); bruncom(combuf, frame, frecover); /* else run in background */ @@ -931,6 +976,8 @@ int n; quit(1); } } else if (n < viewnum) { /* rewind file */ + if (viewnum == 1 && feof(viewfp)) + return(&curview); /* just one view */ if (fseek(viewfp, 0L, 0) == EOF) { perror(vval(VIEWFILE)); quit(1); @@ -940,7 +987,7 @@ int n; } while (n > viewnum) { /* scan to desired view */ if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) - return(NULL); + return(viewnum==1 ? &curview : NULL); if (isview(linebuf) && sscanview(&curview, linebuf) > 0) viewnum++; } @@ -1092,20 +1139,20 @@ int (*rf)(); int pid; register struct pslot *psl; - if (!silent) - printf("\t%s &\n", com); /* echo command */ - if (noaction) + if (noaction) { + if (!silent) + printf("\t%s\n", com); /* echo command */ return(0); - fflush(stdout); + } /* else start it when we can */ while ((pid = startjob(NULL, savestr(com), donecom)) == -1) bwait(1); - if (!silent) { + if (!silent) { /* echo command */ PSERVER *ps; int psn = pid; - ps = findpjob(&psn); - printf("\tProcess started on %s\n", - ps->hostname[0] ? ps->hostname : LHOSTNAME); + ps = findjob(&psn); + printf("\t%s\n", com); + printf("\tProcess started on %s\n", phostname(ps)); fflush(stdout); } psl = findpslot(pid); /* record info. in appropriate slot */ @@ -1143,36 +1190,50 @@ int ncoms; int -pruncom(com, maxcopies) /* run a command in parallel over network */ -char *com; +pruncom(com, ppins, maxcopies) /* run a command in parallel over network */ +char *com, *ppins; int maxcopies; { int retstatus = 0; int hostcopies; + char com1buf[10240], *com1, *endcom1; int status; register PSERVER *ps; if (!silent) - printf("\t%s &\n", com); /* echo command */ + printf("\t%s\n", com); /* echo command */ if (noaction) return(0); fflush(stdout); /* start jobs on each server */ for (ps = pslist; ps != NULL; ps = ps->next) { hostcopies = 0; + if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { + strcpy(com1=com1buf, com); /* build -PP command */ + sprintf(com1+(ppins-com), " -PP %s/%s.persist", + vval(DIRECTORY), phostname(ps)); + strcat(com1, ppins); + endcom1 = com1 + strlen(com1); + sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", + vval(DIRECTORY), phostname(ps)); + } else { + com1 = com; + endcom1 = NULL; + } while (maxcopies > 0 && - startjob(ps, savestr(com), donecom) != -1) { + startjob(ps, savestr(com1), donecom) != -1) { sleep(10); hostcopies++; maxcopies--; + if (endcom1 != NULL) + *endcom1 = '\0'; } if (!silent && hostcopies) { if (hostcopies > 1) printf("\t%d duplicate processes", hostcopies); else printf("\tProcess"); - printf(" started on %s\n", - ps->hostname[0] ? ps->hostname : LHOSTNAME); + printf(" started on %s\n", phostname(ps)); fflush(stdout); } }