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.3 by greg, Fri Jan 19 17:24:19 1996 UTC vs.
Revision 2.51 by greg, Tue Feb 28 03:44:54 2006 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Radiance animation control program
6 + *
7 + * The main difference between this program and ranimove is that
8 + * we have many optimizations here for camera motion in static
9 + * environments, calling rpict and pinterp on multiple processors,
10 + * where ranimove puts its emphasis on object motion, and does
11 + * not use any external programs for image generation.
12 + *
13 + * See the ranimate(1) man page for further details.
14   */
15  
16 < #include "standard.h"
16 > #include "copyright.h"
17 >
18 > #include <stdio.h>
19   #include <ctype.h>
13 #include <sys/types.h>
20   #include <sys/stat.h>
21 + #include <time.h>
22 + #include <signal.h>
23 +
24 + #include "platform.h"
25 + #include "rtprocess.h"
26 + #include "paths.h"
27 + #include "standard.h"
28   #include "view.h"
29   #include "vars.h"
30   #include "netproc.h"
31 <                                /* input variables */
32 < #define HOST            0               /* rendering host machine */
33 < #define RENDER          1               /* rendering options */
34 < #define PFILT           2               /* pfilt options */
35 < #define PINTERP         3               /* pinterp options */
36 < #define OCTREE          4               /* octree file name */
37 < #define DIRECTORY       5               /* working (sub)directory */
38 < #define BASENAME        6               /* output image base name */
39 < #define VIEWFILE        7               /* animation frame views */
40 < #define START           8               /* starting frame number */
41 < #define END             9               /* ending frame number */
42 < #define RIF             10              /* rad input file */
31 >                                /* default blur samples */
32 > #ifndef DEF_NBLUR
33 > #define DEF_NBLUR       5
34 > #endif
35 >                                /* default remote shell */
36 > #ifndef REMSH
37 > #define REMSH           "ssh"
38 > #endif
39 >                                /* input variables (alphabetical by name) */
40 > #define ANIMATE         0               /* animation command */
41 > #define ARCHIVE         1               /* archiving command */
42 > #define BASENAME        2               /* output image base name */
43 > #define DBLUR           3               /* depth of field blur */
44 > #define DIRECTORY       4               /* working (sub)directory */
45 > #define DISKSPACE       5               /* how much disk space to use */
46 > #define END             6               /* ending frame number */
47 > #define EXPOSURE        7               /* how to compute exposure */
48 > #define HOST            8               /* rendering host machine */
49 > #define INTERP          9               /* # frames to interpolate */
50 > #define MBLUR           10              /* motion blur parameters */
51   #define NEXTANIM        11              /* next animation file */
52 < #define ANIMATE         12              /* animation command */
53 < #define TRANSFER        13              /* frame transfer command */
54 < #define ARCHIVE         14              /* archiving command */
55 < #define INTERP          15              /* # frames to interpolate */
56 < #define OVERSAMP        16              /* # times to oversample image */
57 < #define MBLUR           17              /* samples for motion blur */
58 < #define RTRACE          18              /* use rtrace with pinterp? */
59 < #define DISKSPACE       19              /* how much disk space to use */
60 < #define RESOLUTION      20              /* desired final resolution */
61 < #define EXPOSURE        21              /* how to compute exposure */
52 > #define OCTREE          12              /* octree file name */
53 > #define OVERSAMP        13              /* # times to oversample image */
54 > #define PFILT           14              /* pfilt options */
55 > #define PINTERP         15              /* pinterp options */
56 > #define RENDER          16              /* rendering options */
57 > #define RESOLUTION      17              /* desired final resolution */
58 > #define RIF             18              /* rad input file */
59 > #define RSH             19              /* remote shell script or program */
60 > #define RTRACE          20              /* use rtrace with pinterp? */
61 > #define START           21              /* starting frame number */
62 > #define TRANSFER        22              /* frame transfer command */
63 > #define VIEWFILE        23              /* animation frame views */
64  
65 < int     NVARS = 22;             /* total number of variables */
65 > int     NVARS = 24;             /* total number of variables */
66  
67   VARIABLE        vv[] = {                /* variable-value pairs */
68 +        {"ANIMATE",     2,      0,      NULL,   onevalue},
69 +        {"ARCHIVE",     2,      0,      NULL,   onevalue},
70 +        {"BASENAME",    3,      0,      NULL,   onevalue},
71 +        {"DBLUR",       2,      0,      NULL,   onevalue},
72 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
73 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
74 +        {"END",         2,      0,      NULL,   intvalue},
75 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
76          {"host",        4,      0,      NULL,   NULL},
77 <        {"render",      3,      0,      NULL,   catvalues},
77 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
78 >        {"MBLUR",       2,      0,      NULL,   onevalue},
79 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
80 >        {"OCTREE",      3,      0,      NULL,   onevalue},
81 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
82          {"pfilt",       2,      0,      NULL,   catvalues},
83          {"pinterp",     2,      0,      NULL,   catvalues},
84 <        {"OCTREE",      3,      0,      NULL,   onevalue},
85 <        {"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},
84 >        {"render",      3,      0,      NULL,   catvalues},
85 >        {"RESOLUTION",  3,      0,      NULL,   onevalue},
86          {"RIF",         3,      0,      NULL,   onevalue},
87 <        {"NEXTANIM",    3,      0,      NULL,   onevalue},
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},
62 <        {"MBLUR",       2,      0,      NULL,   onevalue},
87 >        {"RSH",         3,      0,      NULL,   onevalue},
88          {"RTRACE",      2,      0,      NULL,   boolvalue},
89 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
90 <        {"RESOLUTION",  3,      0,      NULL,   onevalue},
91 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
89 >        {"START",       2,      0,      NULL,   intvalue},
90 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
91 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
92   };
93  
94   #define SFNAME  "STATUS"                /* status file name */
95  
96   struct {
97          char    host[64];               /* control host name */
98 <        int     pid;                    /* control process id */
98 >        RT_PID  pid;                    /* control process id */
99          char    cfname[128];            /* control file name */
100          int     rnext;                  /* next frame to render */
101          int     fnext;                  /* next frame to filter */
# Line 84 | Line 109 | int    nowarn = 0;             /* turn warnings off? */
109   int     silent = 0;             /* silent mode? */
110   int     noaction = 0;           /* take no action? */
111  
112 < char    rendopt[2048] = "";     /* rendering options */
112 > char    *remsh;                 /* remote shell program/script */
113 > char    rendopt[2048];          /* rendering options */
114   char    rresopt[32];            /* rendering resolution options */
115   char    fresopt[32];            /* filter resolution options */
116   int     pfiltalways;            /* always use pfilt? */
117  
118 + char    arcargs[10240];         /* files to archive */
119 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
120 +
121   struct pslot {
122 <        int     pid;                    /* process ID (0 if empty) */
122 >        RT_PID  pid;                    /* process ID (0 if empty) */
123          int     fout;                   /* output frame number */
124          int     (*rcvf)();              /* recover function */
125   }       *pslot;                 /* process slots */
126   int     npslots;                /* number of process slots */
127  
128 < int     lastpid;                /* ID of last completed background process */
129 < PSERVER *lastpserver;           /* last process server used */
128 > #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
129 > PSERVER *lastpserver;           /* last process server with error */
130  
131 < struct pslot    *findpslot();
131 > static struct pslot * findpslot(RT_PID pid);
132 > static void checkdir(void);
133 > static VIEW * getview(int n);
134  
135 < VIEW    *getview();
136 < char    *getexp();
135 > static char * dirfile(char *df, register char *path);
136 > static char * getexp(int n);
137 > static int getblur(double *mbf, double *dbf);
138 > static int getastat(void);
139 > static void getradfile(char *rfargs);
140 > static void badvalue(int vc);
141 > static int rmfile(char *fn);
142 > static int runcom(char *cs);
143 > static int pruncom(char *com, char *ppins, int maxcopies);
144 > static void bwait(int ncoms);
145 > static RT_PID bruncom(char *com, int fout, int (*rf)());
146 > static int serverdown(void);
147 > static pscompfunc donecom;
148 > static int countviews(void);
149 > static int dofilt(int frame, int rvr);
150 > static void archive(void);
151 > static int frecover(int frame);
152 > static int recover(int frame);
153 > static void sethosts(void);
154 > static void walkwait(int first, int last, char *vfn);
155 > static void animrend(int frame, VIEW *vp);
156 > static void transferframes(void);
157 > static void filterframes(void);
158 > static void renderframes(int nframes);
159 > static void animate(void);
160 > static void setdefaults(void);
161 > static void putastat(void);
162  
163  
164 < main(argc, argv)
165 < int     argc;
166 < char    *argv[];
164 > int
165 > main(
166 >        int     argc,
167 >        char    *argv[]
168 > )
169   {
170          int     explicate = 0;
171          int     i;
# Line 135 | Line 193 | char   *argv[];
193          cfname = argv[i];
194                                                  /* load variables */
195          loadvars(cfname);
196 +                                                /* check variables */
197 +        checkvalues();
198                                                  /* did we get DIRECTORY? */
199          checkdir();
200                                                  /* check status */
# Line 158 | Line 218 | char   *argv[];
218          animate();
219                                                  /* all done */
220          if (vdef(NEXTANIM)) {
221 +                char    *fullp;
222                  argv[i] = vval(NEXTANIM);       /* just change input file */
223                  if (!silent)
224                          printargs(argc, argv, stdout);
225 <                execvp(progname, argv);         /* pass to next */
226 <                quit(1);                        /* shouldn't return */
225 >                fflush(stdout);
226 >                if ((fullp = getpath(argv[0],getenv("PATH"),X_OK)) == NULL)
227 >                        fprintf(stderr, "%s: command not found\n", argv[0]);
228 >                else
229 >                        execv(fullp, argv);
230 >                quit(1);
231          }
232          quit(0);
233 +        return(0); /* pro forma return */
234   userr:
235          fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
236          quit(1);
237 +        return 1; /* pro forma return */
238   }
239  
240  
241 < getastat()                      /* check/set animation status */
241 > static int
242 > getastat(void)                  /* check/set animation status */
243   {
244 <        char    buf[256];
244 >        char    sfname[256];
245          FILE    *fp;
246  
247 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
248 <        if ((fp = fopen(buf, "r")) == NULL) {
247 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
248 >        if ((fp = fopen(sfname, "r")) == NULL) {
249                  if (errno != ENOENT) {
250 <                        perror(buf);
250 >                        perror(sfname);
251                          return(-1);
252                  }
253                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 199 | Line 267 | getastat()                     /* check/set animation status */
267                  goto fmterr;
268          fclose(fp);
269          if (astat.pid != 0) {                   /* thinks it's still running */
270 <                gethostname(buf, sizeof(buf));
203 <                if (strcmp(buf, astat.host)) {
270 >                if (strcmp(myhostname(), astat.host)) {
271                          fprintf(stderr,
272                          "%s: process %d may still be running on host %s\n",
273                                          progname, astat.pid, astat.host);
# Line 213 | Line 280 | getastat()                     /* check/set animation status */
280                  }
281                  /* assume it is dead */
282          }
283 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
283 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
284                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
285                                  progname, astat.cfname);
286                  return(-1);
287          }
288 +                                                /* check control file mods. */
289 +        if (!nowarn && fdate(cfname) > fdate(sfname))
290 +                fprintf(stderr,
291 +                        "%s: warning - control file modified since last run\n",
292 +                                progname);
293   setours:                                        /* set our values */
294 <        gethostname(astat.host, sizeof(astat.host));
294 >        strcpy(astat.host, myhostname());
295          astat.pid = getpid();
296          strcpy(astat.cfname, cfname);
297          return(0);
298   fmterr:
299          fprintf(stderr, "%s: format error in status file \"%s\"\n",
300 <                        progname, buf);
300 >                        progname, sfname);
301          fclose(fp);
302          return(-1);
303   }
304  
305  
306 < putastat()                      /* put out current status */
306 > static void
307 > putastat(void)                  /* put out current status */
308   {
309          char    buf[256];
310          FILE    *fp;
# Line 253 | Line 326 | putastat()                     /* put out current status */
326   }
327  
328  
329 < checkdir()                      /* make sure we have our directory */
329 > static void
330 > checkdir(void)                  /* make sure we have our directory */
331   {
332          struct stat     stb;
333  
# Line 275 | Line 349 | checkdir()                     /* make sure we have our directory */
349   }
350  
351  
352 < setdefaults()                   /* set default values */
352 > static void
353 > setdefaults(void)                       /* set default values */
354   {
355 +        extern char     *atos();
356 +        int     decades;
357          char    buf[256];
358  
359          if (vdef(ANIMATE)) {
# Line 300 | Line 377 | setdefaults()                  /* set default values */
377                  vdef(START)++;
378          }
379          if (!vdef(END)) {
380 <                sprintf(buf, "%d", countviews());
380 >                sprintf(buf, "%d", countviews()+vint(START)-1);
381                  vval(END) = savqstr(buf);
382                  vdef(END)++;
383          }
384 +        if (vint(END) < vint(START)) {
385 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
386 +                                progname);
387 +                quit(1);
388 +        }
389          if (!vdef(BASENAME)) {
390 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
390 >                decades = (int)log10((double)vint(END)) + 1;
391 >                if (decades < 3) decades = 3;
392 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
393                  vval(BASENAME) = savqstr(buf);
394                  vdef(BASENAME)++;
395          }
# Line 337 | Line 421 | setdefaults()                  /* set default values */
421                  vval(DISKSPACE) = "100";
422                  vdef(DISKSPACE)++;
423          }
424 +        if (!vdef(RSH)) {
425 +                vval(RSH) = REMSH;
426 +                vdef(RSH)++;
427 +        }
428 +                                /* locate remote shell program */
429 +        atos(buf, sizeof(buf), vval(RSH));
430 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
431 +                remsh = savqstr(remsh);
432 +        else
433 +                remsh = vval(RSH);      /* will generate error if used */
434 +
435                                  /* append rendering options */
436          if (vdef(RENDER))
437                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
438   }
439  
440  
441 < sethosts()                      /* set up process servers */
441 > static void
442 > sethosts(void)                  /* set up process servers */
443   {
444          extern char     *iskip();
445          char    buf[256], *dir, *uname;
# Line 398 | Line 494 | sethosts()                     /* set up process servers */
494          }
495   }
496  
497 <
498 < getradfile(rfname)              /* run rad and get needed variables */
403 < char    *rfname;
497 > static void
498 > getradfile(char *rfargs)                /* run rad and get needed variables */
499   {
500          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
501          char    combuf[256];
502          register int    i;
503          register char   *cp;
504 +        char    *pippt = NULL;
505                                          /* create rad command */
506          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
507          sprintf(combuf,
508          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
509 <                        rfname, rendopt+2);
509 >                        rfargs, rendopt+2);
510          cp = combuf;
511 <        while (*cp) cp++;               /* match unset variables */
511 >        while (*cp) {
512 >                if (*cp == '|') pippt = cp;
513 >                cp++;
514 >        }                               /* match unset variables */
515          for (i = 0; mvar[i] >= 0; i++)
516                  if (!vdef(mvar[i])) {
517                          *cp++ = '|';
518                          strcpy(cp, vnam(mvar[i]));
519                          while (*cp) cp++;
520 +                        pippt = NULL;
521                  }
522 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
523 <        cp += 11;                       /* point to file name */
524 <        if (system(combuf)) {
525 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
526 <                                progname, rfname);
427 <                quit(1);
522 >        if (pippt != NULL)
523 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
524 >        else {
525 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
526 >                cp += 11;               /* point to file name */
527          }
528 <        loadvars(cp);                   /* load variables and remove file */
529 <        unlink(cp);
528 >        system(combuf);                 /* ignore exit code */
529 >        if (pippt == NULL) {            /* load variables and remove file */
530 >                loadvars(cp);
531 >                unlink(cp);
532 >        }
533   }
534  
535  
536 < animate()                       /* run animation */
536 > static void
537 > animate(void)                   /* run animation */
538   {
539          int     xres, yres;
540          float   pa, mult;
# Line 442 | Line 545 | animate()                      /* run animation */
545          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
546          mult = vflt(OVERSAMP);
547          if (i == 3) {
548 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
548 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
549                                  (int)(mult*yres), pa);
550 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
550 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
551          } else if (i) {
552                  if (i == 1) yres = xres;
553                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 461 | Line 564 | animate()                      /* run animation */
564                                                  progname, vnam(INTERP));
565                          vval(INTERP) = "0";
566                  }
567 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
567 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
568                          if (!nowarn)
569                                  fprintf(stderr,
570                                          "%s: resetting %s=0 for animation\n",
# Line 471 | Line 574 | animate()                      /* run animation */
574          }
575                                          /* figure # frames per batch */
576          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
577 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
578 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
577 >        if ((i=vint(INTERP)) || getblur(NULL, NULL) > 1)
578 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
579          d2 = xres*yres*4;                       /* space for final picture */
580          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
581          if (frames_batch < i+2) {
# Line 480 | Line 583 | animate()                      /* run animation */
583                                  progname);
584                  quit(1);
585          }
586 +                                        /* initialize archive argument list */
587 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
588 +        arcnext = arcfirst = arcargs + i;
589                                          /* initialize status file */
590          if (astat.rnext == 0)
591                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 499 | Line 605 | animate()                      /* run animation */
605   }
606  
607  
608 < renderframes(nframes)           /* render next nframes frames */
609 < int     nframes;
608 > static void
609 > renderframes(int nframes)               /* render next nframes frames */
610   {
611          static char     vendbuf[16];
612          VIEW    *vp;
# Line 556 | Line 662 | int    nframes;
662   }
663  
664  
665 < filterframes()                          /* catch up with filtering */
665 > static void
666 > filterframes(void)                              /* catch up with filtering */
667   {
561        VIEW    *vp;
668          register int    i;
669  
670          if (astat.tnext < astat.fnext)  /* other work to do first */
671                  return;
672                                          /* filter each view */
673 <        for (i = astat.fnext; i < astat.rnext; i++) {
674 <                if ((vp = getview(i)) == NULL) {        /* get view i */
675 <                        fprintf(stderr,
570 <                        "%s: unexpected error reading view for frame %d\n",
571 <                                        progname, i);
572 <                        quit(1);
573 <                }
574 <                dofilt(i, vp, getexp(i), 0);            /* filter frame */
575 <        }
673 >        for (i = astat.fnext; i < astat.rnext; i++)
674 >                dofilt(i, 0);
675 >
676          bwait(0);                       /* wait for filter processes */
677 <        archive(astat.fnext, i-1);      /* archive originals */
677 >        archive();                      /* archive originals */
678          astat.fnext = i;                /* update status */
679          putastat();
680   }
681  
682  
683 < transferframes()                        /* catch up with picture transfers */
683 > static void
684 > transferframes(void)                    /* catch up with picture transfers */
685   {
686 <        char    combuf[10240];
686 >        char    combuf[10240], *fbase;
687          register char   *cp;
688          register int    i;
689  
# Line 593 | Line 694 | transferframes()                       /* catch up with picture transfers
694                  putastat();             /* update status */
695                  return;
696          }
697 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
698 <        cp = combuf + strlen(combuf);
697 >        strcpy(combuf, "cd ");          /* start transfer command */
698 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
699 >        if (*cp) {
700 >                while (*++cp) ;
701 >                *cp++ = ';'; *cp++ = ' ';
702 >        } else
703 >                cp = combuf;
704 >        strcpy(cp, vval(TRANSFER));
705 >        while (*cp) cp++;
706                                          /* make argument list */
707          for (i = astat.tnext; i < astat.fnext; i++) {
708                  *cp++ = ' ';
709 <                sprintf(cp, vval(BASENAME), i);
709 >                sprintf(cp, fbase, i);
710                  while (*cp) cp++;
711                  strcpy(cp, ".pic");
712                  cp += 4;
# Line 613 | Line 721 | transferframes()                       /* catch up with picture transfers
721   }
722  
723  
724 < animrend(frame, vp)                     /* start animation frame */
725 < int     frame;
726 < VIEW    *vp;
724 > static void
725 > animrend(                       /* start animation frame */
726 > int     frame,
727 > VIEW    *vp
728 > )
729   {
620        extern int      recover();
730          char    combuf[2048];
731          char    fname[128];
732  
# Line 631 | Line 740 | VIEW   *vp;
740   }
741  
742  
743 < walkwait(first, last, vfn)              /* walk-through frames */
744 < int     first, last;
745 < char    *vfn;
743 > static void
744 > walkwait(               /* walk-through frames */
745 > int     first,
746 > int last,
747 > char    *vfn
748 > )
749   {
750 +        double  mblurf, dblurf;
751 +        int     nblur = getblur(&mblurf, &dblurf);
752          char    combuf[2048];
753 +        register char   *inspoint;
754          register int    i;
755  
756          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 646 | Line 761 | char   *vfn;
761                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
762                          }
763                                          /* create command */
764 <        sprintf(combuf, "rpict%s -w0 ", rendopt);
765 <        if (vint(INTERP) || atoi(vval(MBLUR)))
766 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
767 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
768 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
764 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
765 >                        viewopt(getview(first>1 ? first-1 : 1)));
766 >        inspoint = combuf;
767 >        while (*inspoint) inspoint++;
768 >        if (nblur) {
769 >                sprintf(inspoint, " -pm %.3f", mblurf/nblur);
770 >                while (*inspoint) inspoint++;
771 >                sprintf(inspoint, " -pd %.3f", dblurf/nblur);
772 >                while (*inspoint) inspoint++;
773 >        }
774 >        if (nblur > 1 || vint(INTERP)) {
775 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
776 >                while (*inspoint) inspoint++;
777 >        }
778 >        sprintf(inspoint, " -o %s.unf %s -S %d",
779 >                        vval(BASENAME), rresopt, first);
780 >        while (*inspoint) inspoint++;
781 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
782                                          /* run in parallel */
783 <        if (pruncom(combuf, (last-first+1)/(vint(INTERP)+1))) {
783 >        i = (last-first+1)/(vint(INTERP)+1);
784 >        if (i < 1) i = 1;
785 >        if (pruncom(combuf, inspoint, i)) {
786                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
787                                  progname, first, last);
788                  quit(1);
# Line 667 | Line 797 | char   *vfn;
797   }
798  
799  
800 < int
801 < recover(frame)                          /* recover the specified frame */
672 < int     frame;
800 > static int
801 > recover(int frame)                      /* recover the specified frame */
802   {
803          static int      *rfrm;          /* list of recovered frames */
804          static int      nrfrms = 0;
805 +        double  mblurf, dblurf;
806 +        int     nblur = getblur(&mblurf, &dblurf);
807          char    combuf[2048];
808          char    fname[128];
809          register char   *cp;
# Line 688 | Line 819 | int    frame;
819                                  vval(ANIMATE), frame, rendopt);
820          else
821                  sprintf(combuf, "rpict%s -w0", rendopt);
822 <        cp = combuf + strlen(combuf);
823 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
822 >        cp = combuf;
823 >        while (*cp) cp++;
824 >        if (nblur) {
825 >                sprintf(cp, " -pm %.3f", mblurf/nblur);
826 >                while (*cp) cp++;
827 >                sprintf(cp, " -pd %.3f", dblurf/nblur);
828 >                while (*cp) cp++;
829 >        }
830 >        if (nblur > 1 || vint(INTERP)) {
831                  sprintf(cp, " -z %s.zbf", fname);
832                  while (*cp) cp++;
833          }
# Line 703 | Line 841 | int    frame;
841                  return(1);
842                                          /* add frame to recovered list */
843          if (nrfrms)
844 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
844 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
845          else
846                  rfrm = (int *)malloc(sizeof(int));
847          if (rfrm == NULL) {
# Line 715 | Line 853 | int    frame;
853   }
854  
855  
856 < int
857 < frecover(frame)                         /* recover filtered frame */
720 < int     frame;
856 > static int
857 > frecover(int frame)                             /* recover filtered frame */
858   {
859 <        VIEW    *vp;
723 <        char    *ex;
724 <
725 <        vp = getview(frame);
726 <        ex = getexp(frame);
727 <        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
859 >        if (dofilt(frame, 2) && dofilt(frame, 1))
860                  return(1);
861          return(0);
862   }
863  
864  
865 < archive(first, last)                    /* archive and remove renderings */
866 < int     first, last;
865 > static void
866 > archive(void)                   /* archive and remove renderings */
867   {
868   #define RMCOML  (sizeof(rmcom)-1)
869          static char     rmcom[] = "rm -f";
870 <        int     offset = RMCOML;
871 <        char    combuf[10240];
872 <        struct stat     stb;
741 <        register char   *cp;
742 <        register int    i;
870 >        char    basedir[128];
871 >        int     dlen, alen;
872 >        register int    j;
873  
874 <        if (noaction)
875 <                return;
876 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
877 <                offset = strlen(vval(ARCHIVE));
748 <        cp = combuf + offset;
749 <        *cp++ = ' ';                            /* make argument list */
750 <        for (i = first; i <= last; i++) {
751 <                sprintf(cp, vval(BASENAME), i);
752 <                strcat(cp, ".unf");
753 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
754 <                        while (*cp) cp++;
755 <                        *cp++ = ' ';
756 <                        sprintf(cp, vval(BASENAME), i);
757 <                        strcat(cp, ".zbf");
758 <                        if (access(cp, F_OK) == 0) {            /* exists? */
759 <                                while (*cp) cp++;
760 <                                *cp++ = ' ';
761 <                        }
762 <                }
763 <        }
764 <        *--cp = '\0';
765 <        if (cp <= combuf + offset)              /* no files? */
766 <                return;
874 >        if (arcnext == arcfirst)
875 >                return;                         /* nothing to do */
876 >        dirfile(basedir, vval(BASENAME));
877 >        dlen = strlen(basedir);
878          if (vdef(ARCHIVE)) {                    /* run archive command */
879 <                i = strlen(vval(ARCHIVE));
880 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
881 <                if (runcom(combuf+offset-i)) {
882 <                        fprintf(stderr,
883 <                "%s: error running archive command on frames %d through %d\n",
884 <                                        progname, first, last);
879 >                alen = strlen(vval(ARCHIVE));
880 >                if (dlen) {
881 >                        j = alen + dlen + 5;
882 >                        strncpy(arcfirst-j, "cd ", 3);
883 >                        strncpy(arcfirst-j+3, basedir, dlen);
884 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
885 >                } else
886 >                        j = alen;
887 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
888 >                if (runcom(arcfirst-j)) {
889 >                        fprintf(stderr, "%s: error running archive command\n",
890 >                                        progname);
891                          quit(1);
892                  }
893          }
894 +        if (dlen) {
895 +                j = RMCOML + dlen + 5;
896 +                strncpy(arcfirst-j, "cd ", 3);
897 +                strncpy(arcfirst-j+3, basedir, dlen);
898 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
899 +        } else
900 +                j = RMCOML;
901                                                  /* run remove command */
902 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
903 <        runcom(combuf+offset-RMCOML);
902 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
903 >        runcom(arcfirst-j);
904 >        arcnext = arcfirst;                     /* reset argument list */
905   #undef RMCOML
906   }
907  
908  
909 < int
910 < dofilt(frame, vp, ep, rvr)                      /* filter frame */
911 < int     frame;
912 < VIEW    *vp;
913 < char    *ep;
789 < int     rvr;
909 > static int
910 > dofilt(                         /* filter frame */
911 > int     frame,
912 > int     rvr
913 > )
914   {
915 <        extern int      frecover();
916 <        char    fnbefore[128], fnafter[128];
917 <        char    combuf[1024], fname[128];
918 <        int     usepinterp, usepfilt;
915 >        static int      iter = 0;
916 >        double  mblurf, dblurf;
917 >        int     nblur = getblur(&mblurf, &dblurf);
918 >        VIEW    *vp = getview(frame);
919 >        char    *ep = getexp(frame);
920 >        char    fnbefore[128], fnafter[128], *fbase;
921 >        char    combuf[1024], fname0[128], fname1[128];
922 >        int     usepinterp, usepfilt, nora_rgbe;
923          int     frseq[2];
924                                                  /* check what is needed */
925 <        usepinterp = atoi(vval(MBLUR));
926 <        usepfilt = pfiltalways | ep==NULL;
925 >        if (vp == NULL) {
926 >                 fprintf(stderr,
927 >                        "%s: unexpected error reading view for frame %d\n",
928 >                                          progname, frame);
929 >                quit(1);
930 >        }
931 >        usepinterp = (nblur > 1);
932 >        usepfilt = pfiltalways | (ep==NULL);
933 >        if (ep != NULL && !strcmp(ep, "1"))
934 >                ep = "+0";
935 >        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
936 >                        *ep != '+' || *ep != '-' || !isint(ep);
937                                                  /* compute rendered views */
938          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
939          frseq[1] = frseq[0] + vint(INTERP) + 1;
940 +        fbase = dirfile(NULL, vval(BASENAME));
941          if (frseq[1] > vint(END))
942                  frseq[1] = vint(END);
943          if (frseq[1] == frame) {                        /* pfilt only */
944                  frseq[0] = frseq[1];
945                  usepinterp = 0;                 /* update what's needed */
946 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
947 <        } else if (frseq[0] == frame) {         /* no interpolation */
948 <                                                /* update what's needed */
949 <                if (!usepinterp)
950 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
946 >                usepfilt |= nora_rgbe;
947 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
948 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
949 >                        *arcnext++ = ' ';
950 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
951 >                        while (*arcnext) arcnext++;
952 >                        strcpy(arcnext, ".unf");
953 >                        arcnext += 4;
954 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
955 >                                *arcnext++ = ' ';
956 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
957 >                                while (*arcnext) arcnext++;
958 >                                strcpy(arcnext, ".zbf");
959 >                                arcnext += 4;
960 >                        }
961 >                }
962 >                if (!usepinterp)                /* update what's needed */
963 >                        usepfilt |= nora_rgbe;
964          } else                                  /* interpolation needed */
965                  usepinterp++;
966          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 821 | Line 973 | int    rvr;
973          if (usepinterp) {                       /* using pinterp */
974                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
975                          return(1);
976 <                if (atoi(vval(MBLUR))) {
977 <                        FILE    *fp;            /* motion blurring */
978 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
979 <                        if ((fp = fopen(fname, "w")) == NULL) {
980 <                                perror(fname); quit(1);
981 <                        }
982 <                        fputs(VIEWSTR, fp);
983 <                        fprintview(vp, fp);
984 <                        putc('\n', fp); fclose(fp);
985 <                        if ((vp = getview(frame+1)) == NULL) {
986 <                                fprintf(stderr,
976 >                if (nblur > 1) {                /* with pdmblur */
977 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
978 >                                        'a'+(iter%26));
979 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
980 >                                        'a'+(iter%26));
981 >                        if (!noaction) {
982 >                                FILE    *fp;            /* motion blurring */
983 >                                if ((fp = fopen(fname0, "w")) == NULL) {
984 >                                        perror(fname0); quit(1);
985 >                                }
986 >                                fputs(VIEWSTR, fp);
987 >                                fprintview(vp, fp);
988 >                                putc('\n', fp); fclose(fp);
989 >                                if ((vp = getview(frame+1)) == NULL) {
990 >                                        fprintf(stderr,
991                          "%s: unexpected error reading view for frame %d\n",
992 <                                                progname, frame+1);
993 <                                quit(1);
992 >                                                        progname, frame+1);
993 >                                        quit(1);
994 >                                }
995 >                                if ((fp = fopen(fname1, "w")) == NULL) {
996 >                                        perror(fname1); quit(1);
997 >                                }
998 >                                fputs(VIEWSTR, fp);
999 >                                fprintview(vp, fp);
1000 >                                putc('\n', fp); fclose(fp);
1001                          }
839                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
840                        if ((fp = fopen(fname, "w")) == NULL) {
841                                perror(fname); quit(1);
842                        }
843                        fputs(VIEWSTR, fp);
844                        fprintview(vp, fp);
845                        putc('\n', fp); fclose(fp);
1002                          sprintf(combuf,
1003 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
1004 <                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
1005 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
1006 <                                        vval(DIRECTORY), vval(DIRECTORY),
851 <                                        vval(DIRECTORY), vval(DIRECTORY));
1003 >                        "(pmdblur %.3f %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
1004 >                                        mblurf, dblurf, nblur,
1005 >                                        fname0, fname1, fname0, fname1);
1006 >                        iter++;
1007                  } else                          /* no blurring */
1008                          strcpy(combuf, "pinterp");
1009                  strcat(combuf, viewopt(vp));
1010                  if (vbool(RTRACE))
1011                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1012 <                                        rendopt, vval(OCTREE));
1012 >                                        rendopt+1, vval(OCTREE));
1013                  if (vdef(PINTERP))
1014                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1015                  if (usepfilt)
1016                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1017                  else
1018 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1018 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1019                                          fresopt, ep);
1020                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1021                                  fnbefore, fnbefore);
# Line 895 | Line 1050 | int    rvr;
1050          } else {                                /* else just check it */
1051                  if (rvr == 2)
1052                          return(1);
1053 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
1053 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1054          }
1055                                                  /* output file name */
1056 <        sprintf(fname, vval(BASENAME), frame);
1057 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
1056 >        sprintf(fname0, vval(BASENAME), frame);
1057 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1058          if (rvr)                                /* in recovery */
1059                  return(runcom(combuf));
1060          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 907 | Line 1062 | int    rvr;
1062   }
1063  
1064  
1065 < VIEW *
1066 < getview(n)                      /* get view number n */
912 < int     n;
1065 > static VIEW *
1066 > getview(int n)                  /* get view number n */
1067   {
1068          static FILE     *viewfp = NULL;         /* view file pointer */
1069          static int      viewnum = 0;            /* current view number */
# Line 921 | Line 1075 | int    n;
1075                          fclose(viewfp);
1076                          viewfp = NULL;
1077                          viewnum = 0;
1078 <                        copystruct(&curview, &stdview);
1078 >                        curview = stdview;
1079                  }
1080                  return(NULL);
1081          }
1082 <        if (viewfp == NULL) {           /* open file */
1082 >        if (viewfp == NULL) {                   /* open file */
1083                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1084                          perror(vval(VIEWFILE));
1085                          quit(1);
1086                  }
1087 <        } else if (n < viewnum) {       /* rewind file */
1087 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1088 >                if (viewnum == 1 && feof(viewfp))
1089 >                        return(&curview);               /* just one view */
1090                  if (fseek(viewfp, 0L, 0) == EOF) {
1091                          perror(vval(VIEWFILE));
1092                          quit(1);
1093                  }
1094 <                copystruct(&curview, &stdview);
1094 >                curview = stdview;
1095                  viewnum = 0;
1096          }
1097 +        if (n < 0) {                            /* get next view */
1098 +                register int    c = getc(viewfp);
1099 +                if (c == EOF)
1100 +                        return((VIEW *)NULL);           /* that's it */
1101 +                ungetc(c, viewfp);
1102 +                n = viewnum + 1;
1103 +        }
1104          while (n > viewnum) {           /* scan to desired view */
1105                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1106 <                        return(NULL);
1106 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1107                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1108                          viewnum++;
1109          }
# Line 948 | Line 1111 | int    n;
1111   }
1112  
1113  
1114 < int
1115 < countviews()                    /* count views in view file */
1114 > static int
1115 > countviews(void)                        /* count views in view file */
1116   {
1117 <        register int    n = 0;
1117 >        int     n;
1118  
1119 <        while (getview(n+1) != NULL)
1119 >        if (getview(n=1) == NULL)
1120 >                return(0);
1121 >        while (getview(-1) != NULL)
1122                  n++;
1123          return(n);
1124   }
1125  
1126  
1127 < char *
1128 < getexp(n)                       /* get exposure for nth frame */
964 < int     n;
1127 > static char *
1128 > getexp(int n)                   /* get exposure for nth frame */
1129   {
1130          extern char     *fskip();
1131          static char     expval[32];
# Line 973 | Line 1137 | int    n;
1137          if (n == 0) {                           /* signal to close file */
1138                  if (expfp != NULL) {
1139                          fclose(expfp);
1140 +                        free((void *)exppos);
1141                          expfp = NULL;
1142                  }
1143                  return(NULL);
1144 <        }
1144 >        } else if (n > vint(END))               /* request past end (error?) */
1145 >                return(NULL);
1146          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1147                  return(NULL);
1148          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1014 | Line 1180 | int    n;
1180                  }
1181                  curfrm++;
1182                  cp = fskip(expval);                     /* check format */
1183 <                if (cp == NULL || *cp != '\n') {
1183 >                if (cp != NULL)
1184 >                        while (isspace(*cp))
1185 >                                *cp++ = '\0';
1186 >                if (cp == NULL || *cp) {
1187                          fprintf(stderr,
1188                                  "%s: exposure format error on line %d\n",
1189                                          vval(EXPOSURE), curfrm);
1190                          quit(1);
1191                  }
1023                *cp = '\0';
1192          }
1193          return(expval);                         /* return value */
1194   }
1195  
1196  
1197 < struct pslot *
1198 < findpslot(pid)                  /* find or allocate a process slot */
1031 < int     pid;
1197 > static struct pslot *
1198 > findpslot(RT_PID pid)                   /* find or allocate a process slot */
1199   {
1200          register struct pslot   *psempty = NULL;
1201          register int    i;
# Line 1043 | Line 1210 | int    pid;
1210   }
1211  
1212  
1213 < int
1214 < donecom(ps, pn, status)         /* clean up after finished process */
1215 < PSERVER *ps;
1216 < int     pn;
1217 < int     status;
1213 > static int
1214 > donecom(                /* clean up after finished process */
1215 >        PSERVER *ps,
1216 >        int     pn,
1217 >        int     status
1218 > )
1219   {
1220 <        register PROC   *pp;
1220 >        register NETPROC        *pp;
1221 >        register struct pslot   *psl;
1222  
1223          pp = ps->proc + pn;
1224          if (pp->elen) {                 /* pass errors */
# Line 1061 | Line 1230 | int    status;
1230                  if (ps->hostname[0])
1231                          status = 1;     /* because rsh doesn't return status */
1232          }
1233 +        lastpserver = NULL;
1234 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1235 +        if (psl->pid) {
1236 +                if (status) {
1237 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1238 +                                status = (*psl->rcvf)(psl->fout);
1239 +                        if (status) {
1240 +                                fprintf(stderr,
1241 +                                        "%s: error rendering frame %d\n",
1242 +                                                progname, psl->fout);
1243 +                                quit(1);
1244 +                        }
1245 +                        lastpserver = ps;
1246 +                }
1247 +                psl->pid = 0;                   /* free process slot */
1248 +        } else if (status)
1249 +                lastpserver = ps;
1250          freestr(pp->com);               /* free command string */
1065        lastpid = pp->pid;              /* record PID for bwait() */
1066        lastpserver = ps;               /* record server for serverdown() */
1251          return(status);
1252   }
1253  
1254  
1255 < int
1256 < serverdown()                    /* check status of last process server */
1255 > static int
1256 > serverdown(void)                        /* check status of last process server */
1257   {
1258 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1259 +                return(0);
1260          if (pserverOK(lastpserver))     /* server still up? */
1261                  return(0);
1262          delpserver(lastpserver);        /* else delete it */
# Line 1083 | Line 1269 | serverdown()                   /* check status of last process server
1269   }
1270  
1271  
1272 < int
1273 < bruncom(com, fout, rf)          /* run a command in the background */
1274 < char    *com;
1275 < int     fout;
1276 < int     (*rf)();
1272 > static RT_PID
1273 > bruncom(                /* run a command in the background */
1274 > char    *com,
1275 > int     fout,
1276 > int     (*rf)()
1277 > )
1278   {
1279 <        int     pid;
1279 >        RT_PID  pid;
1280          register struct pslot   *psl;
1281  
1282 <        if (!silent)
1283 <                printf("\t%s &\n", com);        /* echo command */
1284 <        if (noaction)
1282 >        if (noaction) {
1283 >                if (!silent)
1284 >                        printf("\t%s\n", com);  /* echo command */
1285                  return(0);
1286 <        fflush(stdout);
1287 <                                        /* else start it when we can */
1288 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1286 >        }
1287 >        com = savestr(com);             /* else start it when we can */
1288 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1289                  bwait(1);
1290 <        if (!silent) {
1290 >        if (!silent) {                          /* echo command */
1291                  PSERVER *ps;
1292 <                int     psn = pid;
1293 <                ps = findpjob(&psn);
1294 <                printf("\tProcess started on %s\n",
1295 <                                ps->hostname[0] ? ps->hostname : LHOSTNAME);
1292 >                RT_PID  psn = pid;
1293 >                ps = findjob(&psn);
1294 >                printf("\t%s\n", com);
1295 >                printf("\tProcess started on %s\n", phostname(ps));
1296                  fflush(stdout);
1297          }
1298          psl = findpslot(pid);           /* record info. in appropriate slot */
# Line 1116 | Line 1303 | int    (*rf)();
1303   }
1304  
1305  
1306 < bwait(ncoms)                            /* wait for batch job(s) to finish */
1307 < int     ncoms;
1306 > static void
1307 > bwait(int ncoms)                                /* wait for batch job(s) to finish */
1308   {
1309          int     status;
1123        register struct pslot   *psl;
1310  
1311          if (noaction)
1312                  return;
1313          while ((status = wait4job(NULL, -1)) != -1) {
1314 <                psl = findpslot(lastpid);
1315 <                if (status) {           /* attempt recovery */
1316 <                        serverdown();   /* check server */
1131 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1132 <                                fprintf(stderr,
1133 <                                        "%s: error rendering frame %d\n",
1134 <                                                progname, psl->fout);
1135 <                                quit(1);
1136 <                        }
1137 <                }
1138 <                psl->pid = 0;           /* free process slot */
1139 <                if (!--ncoms)
1140 <                        return;         /* done enough */
1314 >                serverdown();           /* update server status */
1315 >                if (--ncoms == 0)
1316 >                        break;          /* done enough */
1317          }
1318   }
1319  
1320  
1321 < int
1322 < pruncom(com, maxcopies)         /* run a command in parallel over network */
1323 < char    *com;
1324 < int     maxcopies;
1321 > static int
1322 > pruncom(        /* run a command in parallel over network */
1323 > char    *com,
1324 > char    *ppins,
1325 > int     maxcopies
1326 > )
1327   {
1328          int     retstatus = 0;
1329          int     hostcopies;
1330 +        char    buf[10240], *com1, *s;
1331          int     status;
1332 +        int     pfd;
1333 +        register int    n;
1334          register PSERVER        *ps;
1335  
1336          if (!silent)
1337 <                printf("\t%s &\n", com);        /* echo command */
1337 >                printf("\t%s\n", com);  /* echo command */
1338          if (noaction)
1339                  return(0);
1340          fflush(stdout);
1341                                          /* start jobs on each server */
1342          for (ps = pslist; ps != NULL; ps = ps->next) {
1343                  hostcopies = 0;
1344 <                while (maxcopies > 0 &&
1345 <                                startjob(ps, savestr(com), donecom) != -1) {
1346 <                        sleep(10);
1347 <                        hostcopies++;
1348 <                        maxcopies--;
1344 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1345 >                        strcpy(com1=buf, com);  /* build -PP command */
1346 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1347 >                                        vval(DIRECTORY), phostname(ps));
1348 >                        unlink(com1+(ppins-com)+5);
1349 >                        strcat(com1, ppins);
1350 >                } else
1351 >                        com1 = com;
1352 >                while (maxcopies > 0) {
1353 >                        s = savestr(com1);
1354 >                        if (startjob(ps, s, donecom) != -1) {
1355 >                                sleep(20);
1356 >                                hostcopies++;
1357 >                                maxcopies--;
1358 >                        } else {
1359 >                                freestr(s);
1360 >                                break;
1361 >                        }
1362                  }
1363                  if (!silent && hostcopies) {
1364                          if (hostcopies > 1)
1365                                  printf("\t%d duplicate processes", hostcopies);
1366                          else
1367                                  printf("\tProcess");
1368 <                        printf(" started on %s\n",
1175 <                                ps->hostname[0] ? ps->hostname : LHOSTNAME);
1368 >                        printf(" started on %s\n", phostname(ps));
1369                          fflush(stdout);
1370                  }
1371          }
1372                                          /* wait for jobs to finish */
1373          while ((status = wait4job(NULL, -1)) != -1)
1374 <                if (status)
1375 <                        retstatus += !serverdown();     /* check server */
1374 >                retstatus += status && !serverdown();
1375 >                                        /* terminate parallel rpict's */
1376 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1377 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1378 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1379 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1380 >                        buf[n] = '\0';
1381 >                        close(pfd);
1382 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1383 >                                ;
1384 >                                                                /* terminate */
1385 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1386 >                        wait4job(ps, startjob(ps, buf, NULL));
1387 >                }
1388 >        }
1389          return(retstatus);
1390   }
1391  
1392  
1393 < runcom(cs)                      /* run a command locally and wait for it */
1394 < char    *cs;
1393 > static int
1394 > runcom(char *cs)                        /* run a command locally and wait for it */
1395   {
1396          if (!silent)            /* echo it */
1397                  printf("\t%s\n", cs);
# Line 1196 | Line 1402 | char   *cs;
1402   }
1403  
1404  
1405 < rmfile(fn)                      /* remove a file */
1406 < char    *fn;
1405 > static int
1406 > rmfile(char *fn)                        /* remove a file */
1407   {
1408          if (!silent)
1409 < #ifdef MSDOS
1409 > #ifdef _WIN32
1410                  printf("\tdel %s\n", fn);
1411   #else
1412                  printf("\trm -f %s\n", fn);
# Line 1211 | Line 1417 | char   *fn;
1417   }
1418  
1419  
1420 < badvalue(vc)                    /* report bad variable value and exit */
1421 < int     vc;
1420 > static void
1421 > badvalue(int vc)                        /* report bad variable value and exit */
1422   {
1423          fprintf(stderr, "%s: bad value for variable '%s'\n",
1424                          progname, vnam(vc));
1425          quit(1);
1426 + }
1427 +
1428 +
1429 + static char *
1430 + dirfile(                /* separate path into directory and file */
1431 + char    *df,
1432 + register char   *path
1433 + )
1434 + {
1435 +        register int    i;
1436 +        int     psep;
1437 +
1438 +        for (i = 0, psep = -1; path[i]; i++)
1439 +                if (path[i] == '/')
1440 +                        psep = i;
1441 +        if (df != NULL) {
1442 +                if (psep == 0) {
1443 +                        df[0] = '/';
1444 +                        df[1] = '\0';
1445 +                } else if (psep > 0) {
1446 +                        strncpy(df, path, psep);
1447 +                        df[psep] = '\0';
1448 +                } else
1449 +                        df[0] = '\0';
1450 +        }
1451 +        return(path+psep+1);
1452 + }
1453 +
1454 +
1455 + static int
1456 + getblur(double *mbf, double *dbf)       /* get # blur samples (and fraction) */
1457 + {
1458 +        double  mblurf, dblurf;
1459 +        int     nmblur, ndblur;
1460 +        char    *s;
1461 +                                        /* get motion blur */
1462 +        if (!vdef(MBLUR) || (mblurf = atof(vval(MBLUR))) < 0.0)
1463 +                mblurf = 0.0;
1464 +        if (mbf != NULL)
1465 +                *mbf = mblurf;
1466 +        if (mblurf <= FTINY)
1467 +                nmblur = 0;
1468 +        else if (!*(s = sskip(vval(MBLUR))))
1469 +                nmblur = DEF_NBLUR;
1470 +        else if ((nmblur = atoi(s)) <= 0)
1471 +                nmblur = 1;
1472 +                                        /* get depth-of-field blur */
1473 +        if (!vdef(DBLUR) || (dblurf = atof(vval(DBLUR))) < 0.0)
1474 +                dblurf = 0.0;
1475 +        if (dbf != NULL)
1476 +                *dbf = dblurf;
1477 +        if (dblurf <= FTINY)
1478 +                ndblur = 0;
1479 +        else if (!*(s = sskip(vval(DBLUR))))
1480 +                ndblur = DEF_NBLUR;
1481 +        else if ((ndblur = atoi(s)) <= 0)
1482 +                ndblur = 1;
1483 +        if ((nmblur == 1) & (ndblur == 1))
1484 +                return(1);
1485 +                                        /* return combined samples */
1486 +        return(nmblur + ndblur);
1487   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines