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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines