ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ranimate.c
(Generate patch)

Comparing ray/src/util/ranimate.c (file contents):
Revision 2.1 by greg, Fri Jan 12 12:16:17 1996 UTC vs.
Revision 2.9 by greg, Wed Feb 7 16:42:41 1996 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include "standard.h"
12 + #include <ctype.h>
13   #include <sys/types.h>
14   #include <sys/stat.h>
15   #include "view.h"
16   #include "vars.h"
17 + #include "netproc.h"
18                                  /* input variables */
19   #define HOST            0               /* rendering host machine */
20   #define RENDER          1               /* rendering options */
# Line 55 | Line 57 | VARIABLE       vv[] = {                /* variable-value pairs */
57          {"ANIMATE",     2,      0,      NULL,   onevalue},
58          {"TRANSFER",    2,      0,      NULL,   onevalue},
59          {"ARCHIVE",     2,      0,      NULL,   onevalue},
60 <        {"INTERP",      3,      0,      NULL,   intvalue},
61 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
60 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
61 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
62          {"MBLUR",       2,      0,      NULL,   onevalue},
63          {"RTRACE",      2,      0,      NULL,   boolvalue},
64          {"DISKSPACE",   3,      0,      NULL,   fltvalue},
# Line 87 | Line 89 | char   rresopt[32];            /* rendering resolution options */
89   char    fresopt[32];            /* filter resolution options */
90   int     pfiltalways;            /* always use pfilt? */
91  
92 + char    arcargs[10240];         /* files to archive */
93 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
94 +
95 + struct pslot {
96 +        int     pid;                    /* process ID (0 if empty) */
97 +        int     fout;                   /* output frame number */
98 +        int     (*rcvf)();              /* recover function */
99 + }       *pslot;                 /* process slots */
100 + int     npslots;                /* number of process slots */
101 +
102 + int     lastpid;                /* ID of last completed background process */
103 + PSERVER *lastpserver;           /* last process server used */
104 +
105 + #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
106 +
107 + struct pslot    *findpslot();
108 +
109   VIEW    *getview();
110   char    *getexp();
111  
# Line 138 | Line 157 | char   *argv[];
157                                                  /* print variables */
158          if (explicate)
159                  printvars(stdout);
160 +                                                /* set up process servers */
161 +        sethosts();
162                                                  /* run animation */
163          animate();
164                                                  /* all done */
# Line 145 | Line 166 | char   *argv[];
166                  argv[i] = vval(NEXTANIM);       /* just change input file */
167                  if (!silent)
168                          printargs(argc, argv, stdout);
169 <                if (!noaction) {
170 <                        execvp(progname, argv);         /* pass to next */
150 <                        quit(1);                        /* shouldn't return */
151 <                }
169 >                execvp(progname, argv);         /* pass to next */
170 >                quit(1);                        /* shouldn't return */
171          }
172          quit(0);
173   userr:
# Line 185 | Line 204 | getastat()                     /* check/set animation status */
204                  goto fmterr;
205          fclose(fp);
206          if (astat.pid != 0) {                   /* thinks it's still running */
207 <                gethostname(buf, sizeof(buf));
189 <                if (strcmp(buf, astat.host)) {
207 >                if (strcmp(myhostname(), astat.host)) {
208                          fprintf(stderr,
209                          "%s: process %d may still be running on host %s\n",
210                                          progname, astat.pid, astat.host);
# Line 205 | Line 223 | getastat()                     /* check/set animation status */
223                  return(-1);
224          }
225   setours:                                        /* set our values */
226 <        gethostname(astat.host, sizeof(astat.host));
226 >        strcpy(astat.host, myhostname());
227          astat.pid = getpid();
228          strcpy(astat.cfname, cfname);
229          return(0);
# Line 222 | Line 240 | putastat()                     /* put out current status */
240          char    buf[256];
241          FILE    *fp;
242  
243 +        if (noaction)
244 +                return;
245          sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
246          if ((fp = fopen(buf, "w")) == NULL) {
247                  perror(buf);
# Line 263 | Line 283 | setdefaults()                  /* set default values */
283   {
284          char    buf[256];
285  
286 <        if (vdef(OCTREE) == vdef(ANIMATE)) {
286 >        if (vdef(ANIMATE)) {
287 >                vval(OCTREE) = NULL;
288 >                vdef(OCTREE) = 0;
289 >        } else if (!vdef(OCTREE)) {
290                  fprintf(stderr, "%s: either %s or %s must be defined\n",
291                                  progname, vnam(OCTREE), vnam(ANIMATE));
292                  quit(1);
# Line 272 | Line 295 | setdefaults()                  /* set default values */
295                  fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE));
296                  quit(1);
297          }
298 +        if (!vdef(HOST)) {
299 +                vval(HOST) = LHOSTNAME;
300 +                vdef(HOST)++;
301 +        }
302          if (!vdef(START)) {
303                  vval(START) = "1";
304                  vdef(START)++;
305          }
306          if (!vdef(END)) {
307 <                sprintf(buf, "%d", countviews());
307 >                sprintf(buf, "%d", countviews()+vint(START)-1);
308                  vval(END) = savqstr(buf);
309                  vdef(END)++;
310          }
311 +        if (vint(END) < vint(START)) {
312 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
313 +                                progname);
314 +                quit(1);
315 +        }
316          if (!vdef(BASENAME)) {
317                  sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
318                  vval(BASENAME) = savqstr(buf);
# Line 320 | Line 352 | setdefaults()                  /* set default values */
352   }
353  
354  
355 < getradfile(rfname)              /* run rad and get needed variables */
324 < char    *rfname;
355 > sethosts()                      /* set up process servers */
356   {
357 +        extern char     *iskip();
358 +        char    buf[256], *dir, *uname;
359 +        int     np;
360 +        register char   *cp;
361 +        int     i;
362 +
363 +        npslots = 0;
364 +        if (noaction)
365 +                return;
366 +        for (i = 0; i < vdef(HOST); i++) {      /* add each host */
367 +                dir = uname = NULL;
368 +                np = 1;
369 +                strcpy(cp=buf, nvalue(HOST, i));        /* copy to buffer */
370 +                cp = sskip(cp);                         /* skip host name */
371 +                while (isspace(*cp))
372 +                        *cp++ = '\0';
373 +                if (*cp) {                              /* has # processes? */
374 +                        np = atoi(cp);
375 +                        if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp)))
376 +                                badvalue(HOST);
377 +                        while (isspace(*cp))
378 +                                cp++;
379 +                        if (*cp) {                      /* has directory? */
380 +                                dir = cp;
381 +                                cp = sskip(cp);                 /* skip dir. */
382 +                                while (isspace(*cp))
383 +                                        *cp++ = '\0';
384 +                                if (*cp) {                      /* has user? */
385 +                                        uname = cp;
386 +                                        if (*sskip(cp))
387 +                                                badvalue(HOST);
388 +                                }
389 +                        }
390 +                }
391 +                if (addpserver(buf, dir, uname, np) == NULL) {
392 +                        if (!nowarn)
393 +                                fprintf(stderr,
394 +                                        "%s: cannot execute on host \"%s\"\n",
395 +                                                progname, buf);
396 +                } else
397 +                        npslots += np;
398 +        }
399 +        if (npslots == 0) {
400 +                fprintf(stderr, "%s: no working process servers\n", progname);
401 +                quit(1);
402 +        }
403 +        pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot));
404 +        if (pslot == NULL) {
405 +                perror("malloc");
406 +                quit(1);
407 +        }
408 + }
409 +
410 +
411 + getradfile(rfargs)              /* run rad and get needed variables */
412 + char    *rfargs;
413 + {
414          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
415          char    combuf[256];
416          register int    i;
# Line 331 | Line 419 | char   *rfname;
419          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
420          sprintf(combuf,
421          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
422 <                        rfname, rendopt+2);
422 >                        rfargs, rendopt+2);
423          cp = combuf;
424          while (*cp) cp++;               /* match unset variables */
425          for (i = 0; mvar[i] >= 0; i++)
# Line 343 | Line 431 | char   *rfname;
431          sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
432          cp += 11;                       /* point to file name */
433          if (system(combuf)) {
434 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
435 <                                progname, rfname);
434 >                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
435 >                                progname, combuf);
436                  quit(1);
437          }
438          loadvars(cp);                   /* load variables and remove file */
# Line 401 | Line 489 | animate()                      /* run animation */
489                                  progname);
490                  quit(1);
491          }
492 +                                        /* initialize archive argument list */
493 +        i = 16;
494 +        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
495 +                i = strlen(vval(ARCHIVE));
496 +        arcnext = arcfirst = arcargs + i;
497                                          /* initialize status file */
498          if (astat.rnext == 0)
499                  astat.rnext = astat.fnext = astat.tnext = vint(START);
500          putastat();
501                                          /* render in batches */
502 <        while (astat.rnext <= vint(END)) {
502 >        while (astat.tnext <= vint(END)) {
503                  renderframes(frames_batch);
504                  filterframes();
505                  transferframes();
# Line 466 | Line 559 | int    nframes;
559                  }
560          }
561          if (vdef(ANIMATE))              /* wait for renderings to finish */
562 <                animwait(0);
562 >                bwait(0);
563          else {                          /* else if walk-through */
564                  fclose(fp);             /* close view file */
565                  walkwait(astat.rnext, lastframe, vfname);       /* walk it */
566                  unlink(vfname);         /* remove view file */
567          }
475        if (vdef(ARCHIVE))              /* archive results */
476                archive(astat.rnext, lastframe);
568          astat.rnext = i;                /* update status */
569          putastat();
570   }
# Line 494 | Line 585 | filterframes()                         /* catch up with filtering */
585                                          progname, i);
586                          quit(1);
587                  }
588 <                dofilt(i, vp, getexp(i));               /* filter frame */
588 >                dofilt(i, vp, getexp(i), 0);            /* filter frame */
589          }
590 <        filtwait(0);                    /* wait for filter processes */
590 >        bwait(0);                       /* wait for filter processes */
591 >        archive();                      /* archive originals */
592          astat.fnext = i;                /* update status */
593          putastat();
594   }
# Line 539 | Line 631 | animrend(frame, vp)                    /* start animation frame */
631   int     frame;
632   VIEW    *vp;
633   {
634 +        extern int      recover();
635          char    combuf[2048];
636          char    fname[128];
637  
# Line 546 | Line 639 | VIEW   *vp;
639          strcat(fname, ".unf");
640          if (access(fname, F_OK) == 0)
641                  return;
642 <        sprintf(combuf, "%s %d | rpict%s%s %s > %s", vval(ANIMATE), frame,
642 >        sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame,
643                          rendopt, viewopt(vp), rresopt, fname);
644 <        if (runcom(combuf)) {
552 <                fprintf(stderr, "%s: error rendering frame %d\n",
553 <                                progname, frame);
554 <                quit(1);
555 <        }
644 >        bruncom(combuf, frame, recover);        /* run in background */
645   }
646  
647  
559 animwait(nwait)                         /* wait for renderings to finish */
560 int     nwait;
561 {
562        /* currently does nothing since parallel rendering not working */
563 }
564
565
648   walkwait(first, last, vfn)              /* walk-through frames */
649   int     first, last;
650   char    *vfn;
651   {
652          char    combuf[2048];
653 +        char    *inspoint;
654          register int    i;
655  
656          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 578 | Line 661 | char   *vfn;
661                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
662                          }
663                                          /* create command */
664 <        sprintf(combuf, "rpict%s ", rendopt);
664 >        sprintf(combuf, "rpict%s -w0", rendopt);
665          if (vint(INTERP) || atoi(vval(MBLUR)))
666 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
667 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
668 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
669 <        if (runcom(combuf)) {
670 <                fprintf(stderr,
671 <                "%s: error rendering walk-through frames %d through %d\n",
666 >                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
667 >        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
668 >                        vval(BASENAME), rresopt, first);
669 >        inspoint = combuf + strlen(combuf);
670 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
671 >                                        /* run in parallel */
672 >        i = (last-first+1)/(vint(INTERP)+1);
673 >        if (i < 1) i = 1;
674 >        if (pruncom(combuf, inspoint, i)) {
675 >                fprintf(stderr, "%s: error rendering frames %d through %d\n",
676                                  progname, first, last);
677                  quit(1);
678          }
# Line 599 | Line 686 | char   *vfn;
686   }
687  
688  
689 + int
690   recover(frame)                          /* recover the specified frame */
691   int     frame;
692   {
693 +        static int      *rfrm;          /* list of recovered frames */
694 +        static int      nrfrms = 0;
695          char    combuf[2048];
696          char    fname[128];
697          register char   *cp;
698 <
698 >        register int    i;
699 >                                        /* check to see if recovered already */
700 >        for (i = nrfrms; i--; )
701 >                if (rfrm[i] == frame)
702 >                        return(0);
703 >                                        /* build command */
704          sprintf(fname, vval(BASENAME), frame);
705          if (vdef(ANIMATE))
706 <                sprintf(combuf, "%s %d | rpict%s",
706 >                sprintf(combuf, "%s %d | rpict%s -w0",
707                                  vval(ANIMATE), frame, rendopt);
708          else
709 <                sprintf(combuf, "rpict%s", rendopt);
709 >                sprintf(combuf, "rpict%s -w0", rendopt);
710          cp = combuf + strlen(combuf);
711          if (vint(INTERP) || atoi(vval(MBLUR))) {
712                  sprintf(cp, " -z %s.zbf", fname);
# Line 623 | Line 718 | int    frame;
718                  *cp++ = ' ';
719                  strcpy(cp, vval(OCTREE));
720          }
721 <        if (runcom(combuf)) {
722 <                fprintf(stderr, "%s: error recovering frame %d\n",
723 <                                progname, frame);
721 >        if (runcom(combuf))             /* run command */
722 >                return(1);
723 >                                        /* add frame to recovered list */
724 >        if (nrfrms)
725 >                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
726 >        else
727 >                rfrm = (int *)malloc(sizeof(int));
728 >        if (rfrm == NULL) {
729 >                perror("malloc");
730                  quit(1);
731          }
732 +        rfrm[nrfrms++] = frame;
733 +        return(0);
734   }
735  
736  
737 < archive(first, last)                    /* archive finished renderings */
738 < int     first, last;
737 > int
738 > frecover(frame)                         /* recover filtered frame */
739 > int     frame;
740   {
741 <        char    combuf[10240];
742 <        int     offset;
743 <        struct stat     stb;
744 <        register char   *cp;
741 >        VIEW    *vp;
742 >        char    *ex;
743 >
744 >        vp = getview(frame);
745 >        ex = getexp(frame);
746 >        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
747 >                return(1);
748 >        return(0);
749 > }
750 >
751 >
752 > archive()                       /* archive and remove renderings */
753 > {
754 > #define RMCOML  (sizeof(rmcom)-1)
755 >        static char     rmcom[] = "rm -f";
756          register int    i;
757  
758 <        strcpy(cp=combuf, vval(ARCHIVE));
759 <        while (*cp) cp++;
760 <        offset = cp - combuf;
761 <        *cp++ = ' ';                            /* make argument list */
762 <        for (i = first; i <= last; i++) {
763 <                sprintf(cp, vval(BASENAME), i);
764 <                strcat(cp, ".unf");
765 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
766 <                        while (*cp) cp++;
652 <                        *cp++ = ' ';
653 <                        sprintf(cp, vval(BASENAME), i);
654 <                        strcat(cp, ".zbf");
655 <                        if (access(cp, F_OK) == 0) {            /* exists? */
656 <                                while (*cp) cp++;
657 <                                *cp++ = ' ';
658 <                        }
758 >        if (arcnext == arcfirst)
759 >                return;                         /* nothing to do */
760 >        if (vdef(ARCHIVE)) {                    /* run archive command */
761 >                i = strlen(vval(ARCHIVE));
762 >                strncpy(arcfirst-i, vval(ARCHIVE), i);
763 >                if (runcom(arcfirst-i)) {
764 >                        fprintf(stderr, "%s: error running archive command\n",
765 >                                        progname);
766 >                        quit(1);
767                  }
768          }
769 <        *--cp = '\0';
770 <        if (cp <= combuf + offset)              /* no files? */
771 <                return;
772 <        if (runcom(combuf)) {                   /* run archive command */
773 <                fprintf(stderr,
666 <                "%s: error running archive command on frames %d through %d\n",
667 <                                progname, first, last);
668 <                quit(1);
669 <        }
769 >                                                /* run remove command */
770 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
771 >        runcom(arcfirst-RMCOML);
772 >        arcnext = arcfirst;                     /* reset argument list */
773 > #undef RMCOML
774   }
775  
776  
777 < dofilt(frame, vp, ep)                           /* filter frame */
777 > int
778 > dofilt(frame, vp, ep, rvr)                      /* filter frame */
779   int     frame;
780   VIEW    *vp;
781   char    *ep;
782 + int     rvr;
783   {
784 +        extern int      frecover();
785 +        static int      iter = 0;
786          char    fnbefore[128], fnafter[128];
787 <        char    combuf[1024], fname[128];
788 <        int     usepinterp, usepfilt;
789 <        int     frbefore, frafter, triesleft;
787 >        char    combuf[1024], fname0[128], fname1[128];
788 >        int     usepinterp, usepfilt, nora_rgbe;
789 >        int     frseq[2];
790                                                  /* check what is needed */
791          usepinterp = atoi(vval(MBLUR));
792          usepfilt = pfiltalways | ep==NULL;
793 +        if (ep != NULL && !strcmp(ep, "1"))
794 +                ep = "+0";
795 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
796 +                        *ep != '+' || *ep != '-' || !isint(ep);
797                                                  /* compute rendered views */
798 <        frbefore = frame - ((frame-1) % (vint(INTERP)+1));
799 <        frafter = frbefore + vint(INTERP) + 1;
800 <        if (frafter > vint(END))
801 <                frafter = vint(END);
802 <        if (frafter == frame) {                 /* pfilt only */
803 <                frbefore = frafter;
798 >        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
799 >        frseq[1] = frseq[0] + vint(INTERP) + 1;
800 >        if (frseq[1] > vint(END))
801 >                frseq[1] = vint(END);
802 >        if (frseq[1] == frame) {                        /* pfilt only */
803 >                frseq[0] = frseq[1];
804                  usepinterp = 0;                 /* update what's needed */
805 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
806 <                triesleft = 2;
807 <        } else if (frbefore == frame) {         /* no interpolation */
808 <                                                /* remove unneeded files */
809 <                if (frbefore-vint(INTERP)-1 >= 1) {
810 <                        sprintf(fname, vval(BASENAME), frbefore-vint(INTERP)-1);
811 <                        sprintf(combuf, "rm -f %s.unf %s.zbf", fname, fname);
812 <                        runcom(combuf);
805 >                usepfilt |= nora_rgbe;
806 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
807 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
808 >                        *arcnext++ = ' ';
809 >                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
810 >                        while (*arcnext) arcnext++;
811 >                        strcpy(arcnext, ".unf");
812 >                        arcnext += 4;
813 >                        if (usepinterp || vint(INTERP)) {       /* and z-buf */
814 >                                *arcnext++ = ' ';
815 >                                sprintf(arcnext, vval(BASENAME),
816 >                                                frame-vint(INTERP)-1);
817 >                                while (*arcnext) arcnext++;
818 >                                strcpy(arcnext, ".zbf");
819 >                                arcnext += 4;
820 >                        }
821                  }
822 <                                                /* update what's needed */
823 <                if (usepinterp)
824 <                        triesleft = 3;
705 <                else {
706 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
707 <                        triesleft = 2;
708 <                }
709 <        } else {                                /* interpolation needed */
822 >                if (!usepinterp)                /* update what's needed */
823 >                        usepfilt |= nora_rgbe;
824 >        } else                                  /* interpolation needed */
825                  usepinterp++;
826 <                triesleft = 3;
827 <        }
828 <        if (frafter >= astat.rnext) {           /* next batch unavailable */
829 <                frafter = frbefore;
830 <                if (triesleft > 2)
831 <                        triesleft = 2;
832 <        }
718 <        sprintf(fnbefore, vval(BASENAME), frbefore);
719 <        sprintf(fnafter, vval(BASENAME), frafter);
720 < tryit:                                          /* generate command */
826 >        if (frseq[1] >= astat.rnext)            /* next batch unavailable */
827 >                frseq[1] = frseq[0];
828 >        sprintf(fnbefore, vval(BASENAME), frseq[0]);
829 >        sprintf(fnafter, vval(BASENAME), frseq[1]);
830 >        if (rvr == 1 && recover(frseq[0]))      /* recover before frame? */
831 >                return(1);
832 >                                                /* generate command */
833          if (usepinterp) {                       /* using pinterp */
834 +                if (rvr == 2 && recover(frseq[1]))      /* recover after? */
835 +                        return(1);
836                  if (atoi(vval(MBLUR))) {
837                          FILE    *fp;            /* motion blurring */
838 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
839 <                        if ((fp = fopen(fname, "w")) == NULL) {
840 <                                perror(fname); quit(1);
838 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
839 >                                        'a'+(iter%26));
840 >                        if ((fp = fopen(fname0, "w")) == NULL) {
841 >                                perror(fname0); quit(1);
842                          }
843                          fputs(VIEWSTR, fp);
844                          fprintview(vp, fp);
# Line 734 | Line 849 | tryit:                                         /* generate command */
849                                                  progname, frame+1);
850                                  quit(1);
851                          }
852 <                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
853 <                        if ((fp = fopen(fname, "w")) == NULL) {
854 <                                perror(fname); quit(1);
852 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
853 >                                        'a'+(iter%26));
854 >                        if ((fp = fopen(fname1, "w")) == NULL) {
855 >                                perror(fname1); quit(1);
856                          }
857                          fputs(VIEWSTR, fp);
858                          fprintview(vp, fp);
859                          putc('\n', fp); fclose(fp);
860                          sprintf(combuf,
861 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
862 <                                *sskip(vval(MBLUR)) ? sskip(vval(MBLUR)) : "1",
863 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
864 <                                        vval(DIRECTORY), vval(DIRECTORY),
865 <                                        vval(DIRECTORY), vval(DIRECTORY));
861 >                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
862 >                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
863 >                                        atoi(vval(MBLUR)),
864 >                                        fname0, fname1, fname0, fname1);
865 >                        iter++;
866                  } else                          /* no blurring */
867                          strcpy(combuf, "pinterp");
868                  strcat(combuf, viewopt(vp));
869                  if (vbool(RTRACE))
870 <                        sprintf(combuf+strlen(combuf), " -ff -fr '%s %s'",
870 >                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
871                                          rendopt, vval(OCTREE));
872                  if (vdef(PINTERP))
873                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
# Line 762 | Line 878 | tryit:                                         /* generate command */
878                                          fresopt, ep);
879                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
880                                  fnbefore, fnbefore);
881 <                if (frafter != frbefore)
881 >                if (frseq[1] != frseq[0])
882                           sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
883                                          fnafter, fnafter);
884                  if (usepfilt) {                 /* also pfilt */
# Line 778 | Line 894 | tryit:                                         /* generate command */
894                                  sprintf(combuf+strlen(combuf), " %s", fresopt);
895                  }
896          } else if (usepfilt) {                  /* pfilt only */
897 +                if (rvr == 2)
898 +                        return(1);
899                  if (vdef(PFILT))
900                          sprintf(combuf, "pfilt %s", vval(PFILT));
901                  else
# Line 789 | Line 907 | tryit:                                         /* generate command */
907                          sprintf(combuf+strlen(combuf), " %s %s.unf",
908                                          fresopt, fnbefore);
909          } else {                                /* else just check it */
910 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
910 >                if (rvr == 2)
911 >                        return(1);
912 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
913          }
914                                                  /* output file name */
915 <        sprintf(fname, vval(BASENAME), frame);
916 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
917 <        if (runcom(combuf))                     /* run filter command */
918 <                switch (--triesleft) {
919 <                case 2:                         /* try to recover frafter */
920 <                        recover(frafter);
801 <                        goto tryit;
802 <                case 1:                         /* try to recover frbefore */
803 <                        recover(frbefore);
804 <                        goto tryit;
805 <                default:                        /* we've really failed */
806 <                        fprintf(stderr,
807 <                        "%s: unrecoverable filtering error on frame %d\n",
808 <                                        progname, frame);
809 <                        quit(1);
810 <                }
915 >        sprintf(fname0, vval(BASENAME), frame);
916 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
917 >        if (rvr)                                /* in recovery */
918 >                return(runcom(combuf));
919 >        bruncom(combuf, frame, frecover);       /* else run in background */
920 >        return(0);
921   }
922  
923  
814 filtwait(nwait)                 /* wait for filtering processes to finish */
815 int     nwait;
816 {
817        /* currently does nothing since parallel filtering not working */
818 }
819
820
924   VIEW *
925   getview(n)                      /* get view number n */
926   int     n;
# Line 842 | Line 945 | int    n;
945                          quit(1);
946                  }
947          } else if (n < viewnum) {       /* rewind file */
948 +                if (viewnum == 1 && feof(viewfp))
949 +                        return(&curview);               /* just one view */
950                  if (fseek(viewfp, 0L, 0) == EOF) {
951                          perror(vval(VIEWFILE));
952                          quit(1);
# Line 851 | Line 956 | int    n;
956          }
957          while (n > viewnum) {           /* scan to desired view */
958                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
959 <                        return(NULL);
959 >                        return(viewnum==1 ? &curview : NULL);
960                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
961                          viewnum++;
962          }
# Line 937 | Line 1042 | int    n;
1042   }
1043  
1044  
1045 < runcom(cs)                      /* run command */
1045 > struct pslot *
1046 > findpslot(pid)                  /* find or allocate a process slot */
1047 > int     pid;
1048 > {
1049 >        register struct pslot   *psempty = NULL;
1050 >        register int    i;
1051 >
1052 >        for (i = 0; i < npslots; i++) {         /* look for match */
1053 >                if (pslot[i].pid == pid)
1054 >                        return(pslot+i);
1055 >                if (psempty == NULL && pslot[i].pid == 0)
1056 >                        psempty = pslot+i;
1057 >        }
1058 >        return(psempty);                /* return emtpy slot (error if NULL) */
1059 > }
1060 >
1061 >
1062 > int
1063 > donecom(ps, pn, status)         /* clean up after finished process */
1064 > PSERVER *ps;
1065 > int     pn;
1066 > int     status;
1067 > {
1068 >        register PROC   *pp;
1069 >
1070 >        pp = ps->proc + pn;
1071 >        if (pp->elen) {                 /* pass errors */
1072 >                if (ps->hostname[0])
1073 >                        fprintf(stderr, "%s: ", ps->hostname);
1074 >                fprintf(stderr, "Error output from: %s\n", pp->com);
1075 >                fputs(pp->errs, stderr);
1076 >                fflush(stderr);
1077 >                if (ps->hostname[0])
1078 >                        status = 1;     /* because rsh doesn't return status */
1079 >        }
1080 >        freestr(pp->com);               /* free command string */
1081 >        lastpid = pp->pid;              /* record PID for bwait() */
1082 >        lastpserver = ps;               /* record server for serverdown() */
1083 >        return(status);
1084 > }
1085 >
1086 >
1087 > int
1088 > serverdown()                    /* check status of last process server */
1089 > {
1090 >        if (pserverOK(lastpserver))     /* server still up? */
1091 >                return(0);
1092 >        delpserver(lastpserver);        /* else delete it */
1093 >        if (pslist == NULL) {
1094 >                fprintf(stderr, "%s: all process servers are down\n",
1095 >                                progname);
1096 >                quit(1);
1097 >        }
1098 >        return(1);
1099 > }
1100 >
1101 >
1102 > int
1103 > bruncom(com, fout, rf)          /* run a command in the background */
1104 > char    *com;
1105 > int     fout;
1106 > int     (*rf)();
1107 > {
1108 >        int     pid;
1109 >        register struct pslot   *psl;
1110 >
1111 >        if (noaction) {
1112 >                if (!silent)
1113 >                        printf("\t%s\n", com);  /* echo command */
1114 >                return(0);
1115 >        }
1116 >                                        /* else start it when we can */
1117 >        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1118 >                bwait(1);
1119 >        if (!silent) {                          /* echo command */
1120 >                PSERVER *ps;
1121 >                int     psn = pid;
1122 >                ps = findjob(&psn);
1123 >                printf("\t%s\n", com);
1124 >                printf("\tProcess started on %s\n", phostname(ps));
1125 >                fflush(stdout);
1126 >        }
1127 >        psl = findpslot(pid);           /* record info. in appropriate slot */
1128 >        psl->pid = pid;
1129 >        psl->fout = fout;
1130 >        psl->rcvf = rf;
1131 >        return(pid);
1132 > }
1133 >
1134 >
1135 > bwait(ncoms)                            /* wait for batch job(s) to finish */
1136 > int     ncoms;
1137 > {
1138 >        int     status;
1139 >        register struct pslot   *psl;
1140 >
1141 >        if (noaction)
1142 >                return;
1143 >        while ((status = wait4job(NULL, -1)) != -1) {
1144 >                psl = findpslot(lastpid);
1145 >                if (status) {           /* attempt recovery */
1146 >                        serverdown();   /* check server */
1147 >                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1148 >                                fprintf(stderr,
1149 >                                        "%s: error rendering frame %d\n",
1150 >                                                progname, psl->fout);
1151 >                                quit(1);
1152 >                        }
1153 >                }
1154 >                psl->pid = 0;           /* free process slot */
1155 >                if (!--ncoms)
1156 >                        return;         /* done enough */
1157 >        }
1158 > }
1159 >
1160 >
1161 > int
1162 > pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1163 > char    *com, *ppins;
1164 > int     maxcopies;
1165 > {
1166 >        int     retstatus = 0;
1167 >        int     hostcopies;
1168 >        char    com1buf[10240], *com1, *endcom1;
1169 >        int     status;
1170 >        register PSERVER        *ps;
1171 >
1172 >        if (!silent)
1173 >                printf("\t%s\n", com);  /* echo command */
1174 >        if (noaction)
1175 >                return(0);
1176 >        fflush(stdout);
1177 >                                        /* start jobs on each server */
1178 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1179 >                hostcopies = 0;
1180 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1181 >                        strcpy(com1=com1buf, com);      /* build -PP command */
1182 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1183 >                                        vval(DIRECTORY), phostname(ps));
1184 >                        strcat(com1, ppins);
1185 >                        endcom1 = com1 + strlen(com1);
1186 >                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1187 >                                        vval(DIRECTORY), phostname(ps));
1188 >                } else {
1189 >                        com1 = com;
1190 >                        endcom1 = NULL;
1191 >                }
1192 >                while (maxcopies > 0 &&
1193 >                                startjob(ps, savestr(com1), donecom) != -1) {
1194 >                        sleep(10);
1195 >                        hostcopies++;
1196 >                        maxcopies--;
1197 >                        if (endcom1 != NULL)
1198 >                                *endcom1 = '\0';
1199 >                }
1200 >                if (!silent && hostcopies) {
1201 >                        if (hostcopies > 1)
1202 >                                printf("\t%d duplicate processes", hostcopies);
1203 >                        else
1204 >                                printf("\tProcess");
1205 >                        printf(" started on %s\n", phostname(ps));
1206 >                        fflush(stdout);
1207 >                }
1208 >        }
1209 >                                        /* wait for jobs to finish */
1210 >        while ((status = wait4job(NULL, -1)) != -1)
1211 >                if (status)
1212 >                        retstatus += !serverdown();     /* check server */
1213 >        return(retstatus);
1214 > }
1215 >
1216 >
1217 > runcom(cs)                      /* run a command locally and wait for it */
1218   char    *cs;
1219   {
1220          if (!silent)            /* echo it */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines