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.5 by greg, Tue Jan 23 16:14:28 1996 UTC vs.
Revision 2.28 by gwlarson, Mon Jul 6 18:17:39 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
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 */
21 < #define PFILT           2               /* pfilt options */
22 < #define PINTERP         3               /* pinterp options */
23 < #define OCTREE          4               /* octree file name */
24 < #define DIRECTORY       5               /* working (sub)directory */
25 < #define BASENAME        6               /* output image base name */
26 < #define VIEWFILE        7               /* animation frame views */
27 < #define START           8               /* starting frame number */
28 < #define END             9               /* ending frame number */
29 < #define RIF             10              /* rad input file */
30 < #define NEXTANIM        11              /* next animation file */
31 < #define ANIMATE         12              /* animation command */
32 < #define TRANSFER        13              /* frame transfer command */
33 < #define ARCHIVE         14              /* archiving command */
34 < #define INTERP          15              /* # frames to interpolate */
35 < #define OVERSAMP        16              /* # times to oversample image */
36 < #define MBLUR           17              /* samples for motion blur */
37 < #define RTRACE          18              /* use rtrace with pinterp? */
38 < #define DISKSPACE       19              /* how much disk space to use */
39 < #define RESOLUTION      20              /* desired final resolution */
40 < #define EXPOSURE        21              /* how to compute exposure */
18 >                                /* default remote shell */
19 > #ifdef _AUX_SOURCE
20 > #define REMSH           "remsh"
21 > #else
22 > #define REMSH           "rsh"
23 > #endif
24 >                                /* input variables (alphabetical by name) */
25 > #define ANIMATE         0               /* animation command */
26 > #define ARCHIVE         1               /* archiving command */
27 > #define BASENAME        2               /* output image base name */
28 > #define DIRECTORY       3               /* working (sub)directory */
29 > #define DISKSPACE       4               /* how much disk space to use */
30 > #define END             5               /* ending frame number */
31 > #define EXPOSURE        6               /* how to compute exposure */
32 > #define HOST            7               /* rendering host machine */
33 > #define INTERP          8               /* # frames to interpolate */
34 > #define MBLUR           9               /* samples for motion blur */
35 > #define NEXTANIM        10              /* next animation file */
36 > #define OCTREE          11              /* octree file name */
37 > #define OVERSAMP        12              /* # times to oversample image */
38 > #define PFILT           13              /* pfilt options */
39 > #define PINTERP         14              /* pinterp options */
40 > #define RENDER          15              /* rendering options */
41 > #define RESOLUTION      16              /* desired final resolution */
42 > #define RIF             17              /* rad input file */
43 > #define RSH             18              /* remote shell script or program */
44 > #define RTRACE          19              /* use rtrace with pinterp? */
45 > #define START           20              /* starting frame number */
46 > #define TRANSFER        21              /* frame transfer command */
47 > #define VIEWFILE        22              /* animation frame views */
48  
49 < int     NVARS = 22;             /* total number of variables */
49 > int     NVARS = 23;             /* total number of variables */
50  
51   VARIABLE        vv[] = {                /* variable-value pairs */
45        {"host",        4,      0,      NULL,   NULL},
46        {"render",      3,      0,      NULL,   catvalues},
47        {"pfilt",       2,      0,      NULL,   catvalues},
48        {"pinterp",     2,      0,      NULL,   catvalues},
49        {"OCTREE",      3,      0,      NULL,   onevalue},
50        {"DIRECTORY",   3,      0,      NULL,   onevalue},
51        {"BASENAME",    3,      0,      NULL,   onevalue},
52        {"VIEWFILE",    2,      0,      NULL,   onevalue},
53        {"START",       2,      0,      NULL,   intvalue},
54        {"END",         2,      0,      NULL,   intvalue},
55        {"RIF",         3,      0,      NULL,   onevalue},
56        {"NEXTANIM",    3,      0,      NULL,   onevalue},
52          {"ANIMATE",     2,      0,      NULL,   onevalue},
58        {"TRANSFER",    2,      0,      NULL,   onevalue},
53          {"ARCHIVE",     2,      0,      NULL,   onevalue},
54 +        {"BASENAME",    3,      0,      NULL,   onevalue},
55 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
56 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
57 +        {"END",         2,      0,      NULL,   intvalue},
58 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
59 +        {"host",        4,      0,      NULL,   NULL},
60          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
61        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
61          {"MBLUR",       2,      0,      NULL,   onevalue},
62 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
63 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
62 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
63 >        {"OCTREE",      3,      0,      NULL,   onevalue},
64 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
65 >        {"pfilt",       2,      0,      NULL,   catvalues},
66 >        {"pinterp",     2,      0,      NULL,   catvalues},
67 >        {"render",      3,      0,      NULL,   catvalues},
68          {"RESOLUTION",  3,      0,      NULL,   onevalue},
69 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
69 >        {"RIF",         3,      0,      NULL,   onevalue},
70 >        {"RSH",         3,      0,      NULL,   onevalue},
71 >        {"RTRACE",      2,      0,      NULL,   boolvalue},
72 >        {"START",       2,      0,      NULL,   intvalue},
73 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
74 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
75   };
76  
77   #define SFNAME  "STATUS"                /* status file name */
# Line 84 | Line 92 | int    nowarn = 0;             /* turn warnings off? */
92   int     silent = 0;             /* silent mode? */
93   int     noaction = 0;           /* take no action? */
94  
95 < char    rendopt[2048] = "";     /* rendering options */
95 > char    *remsh;                 /* remote shell program/script */
96 > char    rendopt[2048];          /* rendering options */
97   char    rresopt[32];            /* rendering resolution options */
98   char    fresopt[32];            /* filter resolution options */
99   int     pfiltalways;            /* always use pfilt? */
100  
101 + char    arcargs[10240];         /* files to archive */
102 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
103 +
104   struct pslot {
105          int     pid;                    /* process ID (0 if empty) */
106          int     fout;                   /* output frame number */
# Line 96 | Line 108 | struct pslot {
108   }       *pslot;                 /* process slots */
109   int     npslots;                /* number of process slots */
110  
99 int     lastpid;                /* ID of last completed background process */
100 PSERVER *lastpserver;           /* last process server used */
101
111   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
112  
113   struct pslot    *findpslot();
114  
115 + PSERVER *lastpserver;           /* last process server with error */
116 +
117   VIEW    *getview();
118 < char    *getexp();
118 > char    *getexp(), *dirfile();
119  
120 + extern time_t   fdate(), time();
121  
122 +
123   main(argc, argv)
124   int     argc;
125   char    *argv[];
# Line 137 | Line 150 | char   *argv[];
150          cfname = argv[i];
151                                                  /* load variables */
152          loadvars(cfname);
153 +                                                /* check variables */
154 +        checkvalues();
155                                                  /* did we get DIRECTORY? */
156          checkdir();
157                                                  /* check status */
# Line 163 | Line 178 | char   *argv[];
178                  argv[i] = vval(NEXTANIM);       /* just change input file */
179                  if (!silent)
180                          printargs(argc, argv, stdout);
181 <                execvp(progname, argv);         /* pass to next */
182 <                quit(1);                        /* shouldn't return */
181 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
182 >                        fprintf(stderr, "%s: command not found\n", progname);
183 >                else
184 >                        execv(progname, argv);
185 >                quit(1);
186          }
187          quit(0);
188   userr:
# Line 175 | Line 193 | userr:
193  
194   getastat()                      /* check/set animation status */
195   {
196 <        char    buf[256];
196 >        char    sfname[256];
197          FILE    *fp;
198  
199 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
200 <        if ((fp = fopen(buf, "r")) == NULL) {
199 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
200 >        if ((fp = fopen(sfname, "r")) == NULL) {
201                  if (errno != ENOENT) {
202 <                        perror(buf);
202 >                        perror(sfname);
203                          return(-1);
204                  }
205                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 201 | Line 219 | getastat()                     /* check/set animation status */
219                  goto fmterr;
220          fclose(fp);
221          if (astat.pid != 0) {                   /* thinks it's still running */
222 <                gethostname(buf, sizeof(buf));
205 <                if (strcmp(buf, astat.host)) {
222 >                if (strcmp(myhostname(), astat.host)) {
223                          fprintf(stderr,
224                          "%s: process %d may still be running on host %s\n",
225                                          progname, astat.pid, astat.host);
# Line 215 | Line 232 | getastat()                     /* check/set animation status */
232                  }
233                  /* assume it is dead */
234          }
235 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
235 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
236                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
237                                  progname, astat.cfname);
238                  return(-1);
239          }
240 +                                                /* check control file mods. */
241 +        if (!nowarn && fdate(cfname) > fdate(sfname))
242 +                fprintf(stderr,
243 +                        "%s: warning - control file modified since last run\n",
244 +                                progname);
245   setours:                                        /* set our values */
246 <        gethostname(astat.host, sizeof(astat.host));
246 >        strcpy(astat.host, myhostname());
247          astat.pid = getpid();
248          strcpy(astat.cfname, cfname);
249          return(0);
250   fmterr:
251          fprintf(stderr, "%s: format error in status file \"%s\"\n",
252 <                        progname, buf);
252 >                        progname, sfname);
253          fclose(fp);
254          return(-1);
255   }
# Line 279 | Line 301 | checkdir()                     /* make sure we have our directory */
301  
302   setdefaults()                   /* set default values */
303   {
304 +        extern char     *atos();
305 +        int     decades;
306          char    buf[256];
307  
308          if (vdef(ANIMATE)) {
# Line 312 | Line 336 | setdefaults()                  /* set default values */
336                  quit(1);
337          }
338          if (!vdef(BASENAME)) {
339 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
339 >                decades = (int)log10((double)vint(END)) + 1;
340 >                if (decades < 3) decades = 3;
341 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
342                  vval(BASENAME) = savqstr(buf);
343                  vdef(BASENAME)++;
344          }
# Line 344 | Line 370 | setdefaults()                  /* set default values */
370                  vval(DISKSPACE) = "100";
371                  vdef(DISKSPACE)++;
372          }
373 +        if (!vdef(RSH)) {
374 +                vval(RSH) = REMSH;
375 +                vdef(RSH)++;
376 +        }
377 +                                /* locate remote shell program */
378 +        atos(buf, sizeof(buf), vval(RSH));
379 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
380 +                remsh = savqstr(remsh);
381 +        else
382 +                remsh = vval(RSH);      /* will generate error if used */
383 +
384                                  /* append rendering options */
385          if (vdef(RENDER))
386                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
# Line 406 | Line 443 | sethosts()                     /* set up process servers */
443   }
444  
445  
446 < getradfile(rfname)              /* run rad and get needed variables */
447 < char    *rfname;
446 > getradfile(rfargs)              /* run rad and get needed variables */
447 > char    *rfargs;
448   {
449          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
450          char    combuf[256];
451          register int    i;
452          register char   *cp;
453 +        char    *pippt;
454                                          /* create rad command */
455          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
456          sprintf(combuf,
457          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
458 <                        rfname, rendopt+2);
458 >                        rfargs, rendopt+2);
459          cp = combuf;
460 <        while (*cp) cp++;               /* match unset variables */
460 >        while (*cp) {
461 >                if (*cp == '|') pippt = cp;
462 >                cp++;
463 >        }                               /* match unset variables */
464          for (i = 0; mvar[i] >= 0; i++)
465                  if (!vdef(mvar[i])) {
466                          *cp++ = '|';
467                          strcpy(cp, vnam(mvar[i]));
468                          while (*cp) cp++;
469 +                        pippt = NULL;
470                  }
471 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
472 <        cp += 11;                       /* point to file name */
473 <        if (system(combuf)) {
474 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
475 <                                progname, rfname);
434 <                quit(1);
471 >        if (pippt != NULL)
472 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
473 >        else {
474 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
475 >                cp += 11;               /* point to file name */
476          }
477 <        loadvars(cp);                   /* load variables and remove file */
478 <        unlink(cp);
477 >        system(combuf);                 /* ignore exit code */
478 >        if (pippt == NULL) {            /* load variables and remove file */
479 >                loadvars(cp);
480 >                unlink(cp);
481 >        }
482   }
483  
484  
# Line 449 | Line 493 | animate()                      /* run animation */
493          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
494          mult = vflt(OVERSAMP);
495          if (i == 3) {
496 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
496 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
497                                  (int)(mult*yres), pa);
498 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
498 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
499          } else if (i) {
500                  if (i == 1) yres = xres;
501                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 479 | Line 523 | animate()                      /* run animation */
523                                          /* figure # frames per batch */
524          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
525          if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
526 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
526 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
527          d2 = xres*yres*4;                       /* space for final picture */
528          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
529          if (frames_batch < i+2) {
# Line 487 | Line 531 | animate()                      /* run animation */
531                                  progname);
532                  quit(1);
533          }
534 +                                        /* initialize archive argument list */
535 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
536 +        arcnext = arcfirst = arcargs + i;
537                                          /* initialize status file */
538          if (astat.rnext == 0)
539                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 581 | Line 628 | filterframes()                         /* catch up with filtering */
628                  dofilt(i, vp, getexp(i), 0);            /* filter frame */
629          }
630          bwait(0);                       /* wait for filter processes */
631 <        archive(astat.fnext, i-1);      /* archive originals */
631 >        archive();                      /* archive originals */
632          astat.fnext = i;                /* update status */
633          putastat();
634   }
# Line 589 | Line 636 | filterframes()                         /* catch up with filtering */
636  
637   transferframes()                        /* catch up with picture transfers */
638   {
639 <        char    combuf[10240];
639 >        char    combuf[10240], *fbase;
640          register char   *cp;
641          register int    i;
642  
# Line 600 | Line 647 | transferframes()                       /* catch up with picture transfers
647                  putastat();             /* update status */
648                  return;
649          }
650 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
651 <        cp = combuf + strlen(combuf);
650 >        strcpy(combuf, "cd ");          /* start transfer command */
651 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
652 >        if (*cp) {
653 >                while (*++cp) ;
654 >                *cp++ = ';'; *cp++ = ' ';
655 >        } else
656 >                cp = combuf;
657 >        strcpy(cp, vval(TRANSFER));
658 >        while (*cp) cp++;
659                                          /* make argument list */
660          for (i = astat.tnext; i < astat.fnext; i++) {
661                  *cp++ = ' ';
662 <                sprintf(cp, vval(BASENAME), i);
662 >                sprintf(cp, fbase, i);
663                  while (*cp) cp++;
664                  strcpy(cp, ".pic");
665                  cp += 4;
# Line 654 | Line 708 | char   *vfn;
708                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
709                          }
710                                          /* create command */
711 <        sprintf(combuf, "rpict%s -w0", rendopt);
711 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
712 >                        viewopt(getview(first>1 ? first-1 : 1)));
713          if (vint(INTERP) || atoi(vval(MBLUR)))
714                  sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
715          sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
# Line 662 | Line 717 | char   *vfn;
717          inspoint = combuf + strlen(combuf);
718          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
719                                          /* run in parallel */
720 <        if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) {
720 >        i = (last-first+1)/(vint(INTERP)+1);
721 >        if (i < 1) i = 1;
722 >        if (pruncom(combuf, inspoint, i)) {
723                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
724                                  progname, first, last);
725                  quit(1);
# Line 740 | Line 797 | int    frame;
797   }
798  
799  
800 < archive(first, last)                    /* archive and remove renderings */
744 < int     first, last;
800 > archive()                       /* archive and remove renderings */
801   {
802   #define RMCOML  (sizeof(rmcom)-1)
803          static char     rmcom[] = "rm -f";
804 <        int     offset = RMCOML;
805 <        char    combuf[10240];
806 <        struct stat     stb;
751 <        register char   *cp;
752 <        register int    i;
804 >        char    basedir[128];
805 >        int     dlen, alen;
806 >        register int    j;
807  
808 <        if (noaction)
809 <                return;
810 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
811 <                offset = strlen(vval(ARCHIVE));
758 <        cp = combuf + offset;
759 <        *cp++ = ' ';                            /* make argument list */
760 <        for (i = first; i <= last; i++) {
761 <                sprintf(cp, vval(BASENAME), i);
762 <                strcat(cp, ".unf");
763 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
764 <                        while (*cp) cp++;
765 <                        *cp++ = ' ';
766 <                        sprintf(cp, vval(BASENAME), i);
767 <                        strcat(cp, ".zbf");
768 <                        if (access(cp, F_OK) == 0) {            /* exists? */
769 <                                while (*cp) cp++;
770 <                                *cp++ = ' ';
771 <                        }
772 <                }
773 <        }
774 <        *--cp = '\0';
775 <        if (cp <= combuf + offset)              /* no files? */
776 <                return;
808 >        if (arcnext == arcfirst)
809 >                return;                         /* nothing to do */
810 >        dirfile(basedir, vval(BASENAME));
811 >        dlen = strlen(basedir);
812          if (vdef(ARCHIVE)) {                    /* run archive command */
813 <                i = strlen(vval(ARCHIVE));
814 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
815 <                if (runcom(combuf+offset-i)) {
816 <                        fprintf(stderr,
817 <                "%s: error running archive command on frames %d through %d\n",
818 <                                        progname, first, last);
813 >                alen = strlen(vval(ARCHIVE));
814 >                if (dlen) {
815 >                        j = alen + dlen + 5;
816 >                        strncpy(arcfirst-j, "cd ", 3);
817 >                        strncpy(arcfirst-j+3, basedir, dlen);
818 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
819 >                } else
820 >                        j = alen;
821 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
822 >                if (runcom(arcfirst-j)) {
823 >                        fprintf(stderr, "%s: error running archive command\n",
824 >                                        progname);
825                          quit(1);
826                  }
827          }
828 +        if (dlen) {
829 +                j = RMCOML + dlen + 5;
830 +                strncpy(arcfirst-j, "cd ", 3);
831 +                strncpy(arcfirst-j+3, basedir, dlen);
832 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
833 +        } else
834 +                j = RMCOML;
835                                                  /* run remove command */
836 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
837 <        runcom(combuf+offset-RMCOML);
836 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
837 >        runcom(arcfirst-j);
838 >        arcnext = arcfirst;                     /* reset argument list */
839   #undef RMCOML
840   }
841  
# Line 799 | Line 848 | char   *ep;
848   int     rvr;
849   {
850          extern int      frecover();
851 <        char    fnbefore[128], fnafter[128];
852 <        char    combuf[1024], fname[128];
853 <        int     usepinterp, usepfilt;
851 >        static int      iter = 0;
852 >        char    fnbefore[128], fnafter[128], *fbase;
853 >        char    combuf[1024], fname0[128], fname1[128];
854 >        int     usepinterp, usepfilt, nora_rgbe;
855          int     frseq[2];
856                                                  /* check what is needed */
857          usepinterp = atoi(vval(MBLUR));
858          usepfilt = pfiltalways | ep==NULL;
859 +        if (ep != NULL && !strcmp(ep, "1"))
860 +                ep = "+0";
861 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
862 +                        *ep != '+' || *ep != '-' || !isint(ep);
863                                                  /* compute rendered views */
864          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
865          frseq[1] = frseq[0] + vint(INTERP) + 1;
866 +        fbase = dirfile(NULL, vval(BASENAME));
867          if (frseq[1] > vint(END))
868                  frseq[1] = vint(END);
869          if (frseq[1] == frame) {                        /* pfilt only */
870                  frseq[0] = frseq[1];
871                  usepinterp = 0;                 /* update what's needed */
872 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
873 <        } else if (frseq[0] == frame) {         /* no interpolation */
874 <                                                /* update what's needed */
875 <                if (!usepinterp)
876 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
872 >                usepfilt |= nora_rgbe;
873 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
874 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
875 >                        *arcnext++ = ' ';
876 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
877 >                        while (*arcnext) arcnext++;
878 >                        strcpy(arcnext, ".unf");
879 >                        arcnext += 4;
880 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
881 >                                *arcnext++ = ' ';
882 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
883 >                                while (*arcnext) arcnext++;
884 >                                strcpy(arcnext, ".zbf");
885 >                                arcnext += 4;
886 >                        }
887 >                }
888 >                if (!usepinterp)                /* update what's needed */
889 >                        usepfilt |= nora_rgbe;
890          } else                                  /* interpolation needed */
891                  usepinterp++;
892          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 832 | Line 900 | int    rvr;
900                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
901                          return(1);
902                  if (atoi(vval(MBLUR))) {
903 <                        FILE    *fp;            /* motion blurring */
904 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
905 <                        if (access(fname, F_OK) == 0)
906 <                                sleep(10);
907 <                        if ((fp = fopen(fname, "w")) == NULL) {
908 <                                perror(fname); quit(1);
909 <                        }
910 <                        fputs(VIEWSTR, fp);
911 <                        fprintview(vp, fp);
912 <                        putc('\n', fp); fclose(fp);
913 <                        if ((vp = getview(frame+1)) == NULL) {
914 <                                fprintf(stderr,
903 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
904 >                                        'a'+(iter%26));
905 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
906 >                                        'a'+(iter%26));
907 >                        if (!noaction) {
908 >                                FILE    *fp;            /* motion blurring */
909 >                                if ((fp = fopen(fname0, "w")) == NULL) {
910 >                                        perror(fname0); quit(1);
911 >                                }
912 >                                fputs(VIEWSTR, fp);
913 >                                fprintview(vp, fp);
914 >                                putc('\n', fp); fclose(fp);
915 >                                if ((vp = getview(frame+1)) == NULL) {
916 >                                        fprintf(stderr,
917                          "%s: unexpected error reading view for frame %d\n",
918 <                                                progname, frame+1);
919 <                                quit(1);
918 >                                                        progname, frame+1);
919 >                                        quit(1);
920 >                                }
921 >                                if ((fp = fopen(fname1, "w")) == NULL) {
922 >                                        perror(fname1); quit(1);
923 >                                }
924 >                                fputs(VIEWSTR, fp);
925 >                                fprintview(vp, fp);
926 >                                putc('\n', fp); fclose(fp);
927                          }
851                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
852                        if ((fp = fopen(fname, "w")) == NULL) {
853                                perror(fname); quit(1);
854                        }
855                        fputs(VIEWSTR, fp);
856                        fprintview(vp, fp);
857                        putc('\n', fp); fclose(fp);
928                          sprintf(combuf,
929 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
929 >                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
930                          *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
931 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
932 <                                        vval(DIRECTORY), vval(DIRECTORY),
933 <                                        vval(DIRECTORY), vval(DIRECTORY));
931 >                                        atoi(vval(MBLUR)),
932 >                                        fname0, fname1, fname0, fname1);
933 >                        iter++;
934                  } else                          /* no blurring */
935                          strcpy(combuf, "pinterp");
936                  strcat(combuf, viewopt(vp));
937                  if (vbool(RTRACE))
938                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
939 <                                        rendopt, vval(OCTREE));
939 >                                        rendopt+1, vval(OCTREE));
940                  if (vdef(PINTERP))
941                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
942                  if (usepfilt)
# Line 907 | Line 977 | int    rvr;
977          } else {                                /* else just check it */
978                  if (rvr == 2)
979                          return(1);
980 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
980 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
981          }
982                                                  /* output file name */
983 <        sprintf(fname, vval(BASENAME), frame);
984 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
983 >        sprintf(fname0, vval(BASENAME), frame);
984 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
985          if (rvr)                                /* in recovery */
986                  return(runcom(combuf));
987          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 937 | Line 1007 | int    n;
1007                  }
1008                  return(NULL);
1009          }
1010 <        if (viewfp == NULL) {           /* open file */
1010 >        if (viewfp == NULL) {                   /* open file */
1011                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1012                          perror(vval(VIEWFILE));
1013                          quit(1);
1014                  }
1015 <        } else if (n < viewnum) {       /* rewind file */
1015 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1016 >                if (viewnum == 1 && feof(viewfp))
1017 >                        return(&curview);               /* just one view */
1018                  if (fseek(viewfp, 0L, 0) == EOF) {
1019                          perror(vval(VIEWFILE));
1020                          quit(1);
# Line 950 | Line 1022 | int    n;
1022                  copystruct(&curview, &stdview);
1023                  viewnum = 0;
1024          }
1025 +        if (n < 0) {                            /* get next view */
1026 +                register int    c = getc(viewfp);
1027 +                if (c == EOF)
1028 +                        return((VIEW *)NULL);           /* that's it */
1029 +                ungetc(c, viewfp);
1030 +                n = viewnum + 1;
1031 +        }
1032          while (n > viewnum) {           /* scan to desired view */
1033                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1034 <                        return(NULL);
1034 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1035                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1036                          viewnum++;
1037          }
# Line 963 | Line 1042 | int    n;
1042   int
1043   countviews()                    /* count views in view file */
1044   {
1045 <        register int    n = 0;
1045 >        int     n;
1046  
1047 <        while (getview(n+1) != NULL)
1047 >        if (getview(n=1) == NULL)
1048 >                return(0);
1049 >        while (getview(-1) != NULL)
1050                  n++;
1051          return(n);
1052   }
# Line 985 | Line 1066 | int    n;
1066          if (n == 0) {                           /* signal to close file */
1067                  if (expfp != NULL) {
1068                          fclose(expfp);
1069 +                        free((char *)exppos);
1070                          expfp = NULL;
1071                  }
1072                  return(NULL);
1073 <        }
1073 >        } else if (n > vint(END))               /* request past end (error?) */
1074 >                return(NULL);
1075          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1076                  return(NULL);
1077          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1026 | Line 1109 | int    n;
1109                  }
1110                  curfrm++;
1111                  cp = fskip(expval);                     /* check format */
1112 <                if (cp == NULL || *cp != '\n') {
1112 >                if (cp != NULL)
1113 >                        while (isspace(*cp))
1114 >                                *cp++ = '\0';
1115 >                if (cp == NULL || *cp) {
1116                          fprintf(stderr,
1117                                  "%s: exposure format error on line %d\n",
1118                                          vval(EXPOSURE), curfrm);
1119                          quit(1);
1120                  }
1035                *cp = '\0';
1121          }
1122          return(expval);                         /* return value */
1123   }
# Line 1062 | Line 1147 | int    pn;
1147   int     status;
1148   {
1149          register PROC   *pp;
1150 +        register struct pslot   *psl;
1151  
1152          pp = ps->proc + pn;
1153          if (pp->elen) {                 /* pass errors */
# Line 1073 | Line 1159 | int    status;
1159                  if (ps->hostname[0])
1160                          status = 1;     /* because rsh doesn't return status */
1161          }
1162 +        lastpserver = NULL;
1163 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1164 +        if (psl->pid) {
1165 +                if (status) {
1166 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1167 +                                status = (*psl->rcvf)(psl->fout);
1168 +                        if (status) {
1169 +                                fprintf(stderr,
1170 +                                        "%s: error rendering frame %d\n",
1171 +                                                progname, psl->fout);
1172 +                                quit(1);
1173 +                        }
1174 +                        lastpserver = ps;
1175 +                }
1176 +                psl->pid = 0;                   /* free process slot */
1177 +        } else if (status)
1178 +                lastpserver = ps;
1179          freestr(pp->com);               /* free command string */
1077        lastpid = pp->pid;              /* record PID for bwait() */
1078        lastpserver = ps;               /* record server for serverdown() */
1180          return(status);
1181   }
1182  
# Line 1083 | Line 1184 | int    status;
1184   int
1185   serverdown()                    /* check status of last process server */
1186   {
1187 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1188 +                return(0);
1189          if (pserverOK(lastpserver))     /* server still up? */
1190                  return(0);
1191          delpserver(lastpserver);        /* else delete it */
# Line 1109 | Line 1212 | int    (*rf)();
1212                          printf("\t%s\n", com);  /* echo command */
1213                  return(0);
1214          }
1215 <                                        /* else start it when we can */
1216 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1215 >        com = savestr(com);             /* else start it when we can */
1216 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1217                  bwait(1);
1218          if (!silent) {                          /* echo command */
1219                  PSERVER *ps;
# Line 1132 | Line 1235 | bwait(ncoms)                           /* wait for batch job(s) to finish */
1235   int     ncoms;
1236   {
1237          int     status;
1135        register struct pslot   *psl;
1238  
1239          if (noaction)
1240                  return;
1241          while ((status = wait4job(NULL, -1)) != -1) {
1242 <                psl = findpslot(lastpid);
1243 <                if (status) {           /* attempt recovery */
1244 <                        serverdown();   /* check server */
1143 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1144 <                                fprintf(stderr,
1145 <                                        "%s: error rendering frame %d\n",
1146 <                                                progname, psl->fout);
1147 <                                quit(1);
1148 <                        }
1149 <                }
1150 <                psl->pid = 0;           /* free process slot */
1151 <                if (!--ncoms)
1152 <                        return;         /* done enough */
1242 >                serverdown();           /* update server status */
1243 >                if (--ncoms == 0)
1244 >                        break;          /* done enough */
1245          }
1246   }
1247  
# Line 1161 | Line 1253 | int    maxcopies;
1253   {
1254          int     retstatus = 0;
1255          int     hostcopies;
1256 <        char    com1buf[10240], *com1, *endcom1;
1256 >        char    buf[10240], *com1, *s;
1257          int     status;
1258 +        int     pfd;
1259 +        register int    n;
1260          register PSERVER        *ps;
1261  
1262          if (!silent)
1263 <                printf("\t%s &\n", com);        /* echo command */
1263 >                printf("\t%s\n", com);  /* echo command */
1264          if (noaction)
1265                  return(0);
1266          fflush(stdout);
# Line 1174 | Line 1268 | int    maxcopies;
1268          for (ps = pslist; ps != NULL; ps = ps->next) {
1269                  hostcopies = 0;
1270                  if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1271 <                        strcpy(com1=com1buf, com);      /* build -PP command */
1271 >                        strcpy(com1=buf, com);  /* build -PP command */
1272                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1273                                          vval(DIRECTORY), phostname(ps));
1274                          strcat(com1, ppins);
1275 <                        endcom1 = com1 + strlen(com1);
1182 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1183 <                                        vval(DIRECTORY), phostname(ps));
1184 <                } else {
1275 >                } else
1276                          com1 = com;
1277 <                        endcom1 = NULL;
1277 >                while (maxcopies > 0) {
1278 >                        s = savestr(com1);
1279 >                        if (startjob(ps, s, donecom) != -1) {
1280 >                                sleep(20);
1281 >                                hostcopies++;
1282 >                                maxcopies--;
1283 >                        } else {
1284 >                                freestr(s);
1285 >                                break;
1286 >                        }
1287                  }
1188                while (maxcopies > 0 &&
1189                                startjob(ps, savestr(com1), donecom) != -1) {
1190                        sleep(10);
1191                        hostcopies++;
1192                        maxcopies--;
1193                        if (endcom1 != NULL)
1194                                *endcom1 = '\0';
1195                }
1288                  if (!silent && hostcopies) {
1289                          if (hostcopies > 1)
1290                                  printf("\t%d duplicate processes", hostcopies);
# Line 1204 | Line 1296 | int    maxcopies;
1296          }
1297                                          /* wait for jobs to finish */
1298          while ((status = wait4job(NULL, -1)) != -1)
1299 <                if (status)
1300 <                        retstatus += !serverdown();     /* check server */
1299 >                retstatus += status && !serverdown();
1300 >                                        /* terminate parallel rpict's */
1301 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1302 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1303 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1304 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1305 >                        buf[n] = '\0';
1306 >                        close(pfd);
1307 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1308 >                                ;
1309 >                                                                /* terminate */
1310 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1311 >                        wait4job(ps, startjob(ps, buf, NULL));
1312 >                }
1313 >        }
1314          return(retstatus);
1315   }
1316  
# Line 1243 | Line 1348 | int    vc;
1348          fprintf(stderr, "%s: bad value for variable '%s'\n",
1349                          progname, vnam(vc));
1350          quit(1);
1351 + }
1352 +
1353 +
1354 + char *
1355 + dirfile(df, path)               /* separate path into directory and file */
1356 + char    *df;
1357 + register char   *path;
1358 + {
1359 +        register int    i;
1360 +        int     psep;
1361 +
1362 +        for (i = 0, psep = -1; path[i]; i++)
1363 +                if (path[i] == '/')
1364 +                        psep = i;
1365 +        if (df != NULL)
1366 +                if (psep == 0) {
1367 +                        df[0] = '/';
1368 +                        df[1] = '\0';
1369 +                } else if (psep > 0) {
1370 +                        strncpy(df, path, psep);
1371 +                        df[psep] = '\0';
1372 +                } else
1373 +                        df[0] = '\0';
1374 +        return(path+psep+1);
1375   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines