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.47 by greg, Tue Jun 8 19:48:31 2004 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 */
42 < #define NEXTANIM        11              /* next animation file */
43 < #define ANIMATE         12              /* animation command */
44 < #define TRANSFER        13              /* frame transfer command */
45 < #define ARCHIVE         14              /* archiving command */
46 < #define INTERP          15              /* # frames to interpolate */
47 < #define OVERSAMP        16              /* # times to oversample image */
48 < #define MBLUR           17              /* samples for motion blur */
49 < #define RTRACE          18              /* use rtrace with pinterp? */
50 < #define DISKSPACE       19              /* how much disk space to use */
51 < #define RESOLUTION      20              /* desired final resolution */
52 < #define EXPOSURE        21              /* how to compute exposure */
30 >                                /* default blur samples */
31 > #ifndef DEF_NBLUR
32 > #define DEF_NBLUR       5
33 > #endif
34 >                                /* default remote shell */
35 > #define REMSH           "rsh"
36 >                                /* input variables (alphabetical by name) */
37 > #define ANIMATE         0               /* animation command */
38 > #define ARCHIVE         1               /* archiving command */
39 > #define BASENAME        2               /* output image base name */
40 > #define DIRECTORY       3               /* working (sub)directory */
41 > #define DISKSPACE       4               /* how much disk space to use */
42 > #define END             5               /* ending frame number */
43 > #define EXPOSURE        6               /* how to compute exposure */
44 > #define HOST            7               /* rendering host machine */
45 > #define INTERP          8               /* # frames to interpolate */
46 > #define MBLUR           9               /* motion blur parameters */
47 > #define NEXTANIM        10              /* next animation file */
48 > #define OCTREE          11              /* octree file name */
49 > #define OVERSAMP        12              /* # times to oversample image */
50 > #define PFILT           13              /* pfilt options */
51 > #define PINTERP         14              /* pinterp options */
52 > #define RENDER          15              /* rendering options */
53 > #define RESOLUTION      16              /* desired final resolution */
54 > #define RIF             17              /* rad input file */
55 > #define RSH             18              /* remote shell script or program */
56 > #define RTRACE          19              /* use rtrace with pinterp? */
57 > #define START           20              /* starting frame number */
58 > #define TRANSFER        21              /* frame transfer command */
59 > #define VIEWFILE        22              /* animation frame views */
60  
61 < int     NVARS = 22;             /* total number of variables */
61 > int     NVARS = 23;             /* total number of variables */
62  
63   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},
64          {"ANIMATE",     2,      0,      NULL,   onevalue},
58        {"TRANSFER",    2,      0,      NULL,   onevalue},
65          {"ARCHIVE",     2,      0,      NULL,   onevalue},
66 +        {"BASENAME",    3,      0,      NULL,   onevalue},
67 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
68 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
69 +        {"END",         2,      0,      NULL,   intvalue},
70 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
71 +        {"host",        4,      0,      NULL,   NULL},
72          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
61        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
73          {"MBLUR",       2,      0,      NULL,   onevalue},
74 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
75 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
74 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
75 >        {"OCTREE",      3,      0,      NULL,   onevalue},
76 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
77 >        {"pfilt",       2,      0,      NULL,   catvalues},
78 >        {"pinterp",     2,      0,      NULL,   catvalues},
79 >        {"render",      3,      0,      NULL,   catvalues},
80          {"RESOLUTION",  3,      0,      NULL,   onevalue},
81 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
81 >        {"RIF",         3,      0,      NULL,   onevalue},
82 >        {"RSH",         3,      0,      NULL,   onevalue},
83 >        {"RTRACE",      2,      0,      NULL,   boolvalue},
84 >        {"START",       2,      0,      NULL,   intvalue},
85 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
86 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
87   };
88  
89   #define SFNAME  "STATUS"                /* status file name */
# Line 84 | Line 104 | int    nowarn = 0;             /* turn warnings off? */
104   int     silent = 0;             /* silent mode? */
105   int     noaction = 0;           /* take no action? */
106  
107 < char    rendopt[2048] = "";     /* rendering options */
107 > char    *remsh;                 /* remote shell program/script */
108 > char    rendopt[2048];          /* rendering options */
109   char    rresopt[32];            /* rendering resolution options */
110   char    fresopt[32];            /* filter resolution options */
111   int     pfiltalways;            /* always use pfilt? */
112  
113 + char    arcargs[10240];         /* files to archive */
114 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
115 +
116   struct pslot {
117          int     pid;                    /* process ID (0 if empty) */
118          int     fout;                   /* output frame number */
# Line 96 | Line 120 | struct pslot {
120   }       *pslot;                 /* process slots */
121   int     npslots;                /* number of process slots */
122  
99 int     lastpid;                /* ID of last completed background process */
100 PSERVER *lastpserver;           /* last process server used */
101
123   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
124 + PSERVER *lastpserver;           /* last process server with error */
125  
126 < struct pslot    *findpslot();
126 > static struct pslot * findpslot(int pid);
127 > static void checkdir(void);
128 > static VIEW * getview(int n);
129  
130 < VIEW    *getview();
131 < char    *getexp();
130 > static char * dirfile(char *df, register char *path);
131 > static char * getexp(int n);
132 > static int getblur(double *bf);
133 > static int getastat(void);
134 > static void getradfile(char *rfargs);
135 > static void badvalue(int vc);
136 > static int rmfile(char *fn);
137 > static int runcom(char *cs);
138 > static int pruncom(char *com, char *ppins, int maxcopies);
139 > static void bwait(int ncoms);
140 > static int bruncom(char *com, int fout, int (*rf)());
141 > static int serverdown(void);
142 > static pscompfunc donecom;
143 > static int countviews(void);
144 > static int dofilt(int frame, int rvr);
145 > static void archive(void);
146 > static int frecover(int frame);
147 > static int recover(int frame);
148 > static void sethosts(void);
149 > static void walkwait(int first, int last, char *vfn);
150 > static void animrend(int frame, VIEW *vp);
151 > static void transferframes(void);
152 > static void filterframes(void);
153 > static void renderframes(int nframes);
154 > static void animate(void);
155 > static void setdefaults(void);
156 > static void putastat(void);
157  
158  
159 < main(argc, argv)
160 < int     argc;
161 < char    *argv[];
159 > int
160 > main(
161 >        int     argc,
162 >        char    *argv[]
163 > )
164   {
165          int     explicate = 0;
166          int     i;
# Line 137 | Line 188 | char   *argv[];
188          cfname = argv[i];
189                                                  /* load variables */
190          loadvars(cfname);
191 +                                                /* check variables */
192 +        checkvalues();
193                                                  /* did we get DIRECTORY? */
194          checkdir();
195                                                  /* check status */
# Line 163 | Line 216 | char   *argv[];
216                  argv[i] = vval(NEXTANIM);       /* just change input file */
217                  if (!silent)
218                          printargs(argc, argv, stdout);
219 <                execvp(progname, argv);         /* pass to next */
220 <                quit(1);                        /* shouldn't return */
219 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
220 >                        fprintf(stderr, "%s: command not found\n", progname);
221 >                else
222 >                        execv(progname, argv);
223 >                quit(1);
224          }
225          quit(0);
226 +        return 0; /* pro forma return */
227   userr:
228          fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
229          quit(1);
230 +        return 1; /* pro forma return */
231   }
232  
233  
234 < getastat()                      /* check/set animation status */
234 > static int
235 > getastat(void)                  /* check/set animation status */
236   {
237 <        char    buf[256];
237 >        char    sfname[256];
238          FILE    *fp;
239  
240 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
241 <        if ((fp = fopen(buf, "r")) == NULL) {
240 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
241 >        if ((fp = fopen(sfname, "r")) == NULL) {
242                  if (errno != ENOENT) {
243 <                        perror(buf);
243 >                        perror(sfname);
244                          return(-1);
245                  }
246                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 201 | Line 260 | getastat()                     /* check/set animation status */
260                  goto fmterr;
261          fclose(fp);
262          if (astat.pid != 0) {                   /* thinks it's still running */
263 <                gethostname(buf, sizeof(buf));
205 <                if (strcmp(buf, astat.host)) {
263 >                if (strcmp(myhostname(), astat.host)) {
264                          fprintf(stderr,
265                          "%s: process %d may still be running on host %s\n",
266                                          progname, astat.pid, astat.host);
# Line 215 | Line 273 | getastat()                     /* check/set animation status */
273                  }
274                  /* assume it is dead */
275          }
276 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
276 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
277                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
278                                  progname, astat.cfname);
279                  return(-1);
280          }
281 +                                                /* check control file mods. */
282 +        if (!nowarn && fdate(cfname) > fdate(sfname))
283 +                fprintf(stderr,
284 +                        "%s: warning - control file modified since last run\n",
285 +                                progname);
286   setours:                                        /* set our values */
287 <        gethostname(astat.host, sizeof(astat.host));
287 >        strcpy(astat.host, myhostname());
288          astat.pid = getpid();
289          strcpy(astat.cfname, cfname);
290          return(0);
291   fmterr:
292          fprintf(stderr, "%s: format error in status file \"%s\"\n",
293 <                        progname, buf);
293 >                        progname, sfname);
294          fclose(fp);
295          return(-1);
296   }
297  
298  
299 < putastat()                      /* put out current status */
299 > static void
300 > putastat(void)                  /* put out current status */
301   {
302          char    buf[256];
303          FILE    *fp;
# Line 255 | Line 319 | putastat()                     /* put out current status */
319   }
320  
321  
322 < checkdir()                      /* make sure we have our directory */
322 > static void
323 > checkdir(void)                  /* make sure we have our directory */
324   {
325          struct stat     stb;
326  
# Line 277 | Line 342 | checkdir()                     /* make sure we have our directory */
342   }
343  
344  
345 < setdefaults()                   /* set default values */
345 > static void
346 > setdefaults(void)                       /* set default values */
347   {
348 +        extern char     *atos();
349 +        int     decades;
350          char    buf[256];
351  
352          if (vdef(ANIMATE)) {
# Line 312 | Line 380 | setdefaults()                  /* set default values */
380                  quit(1);
381          }
382          if (!vdef(BASENAME)) {
383 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
383 >                decades = (int)log10((double)vint(END)) + 1;
384 >                if (decades < 3) decades = 3;
385 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
386                  vval(BASENAME) = savqstr(buf);
387                  vdef(BASENAME)++;
388          }
# Line 344 | Line 414 | setdefaults()                  /* set default values */
414                  vval(DISKSPACE) = "100";
415                  vdef(DISKSPACE)++;
416          }
417 +        if (!vdef(RSH)) {
418 +                vval(RSH) = REMSH;
419 +                vdef(RSH)++;
420 +        }
421 +                                /* locate remote shell program */
422 +        atos(buf, sizeof(buf), vval(RSH));
423 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
424 +                remsh = savqstr(remsh);
425 +        else
426 +                remsh = vval(RSH);      /* will generate error if used */
427 +
428                                  /* append rendering options */
429          if (vdef(RENDER))
430                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
431   }
432  
433  
434 < sethosts()                      /* set up process servers */
434 > static void
435 > sethosts(void)                  /* set up process servers */
436   {
437          extern char     *iskip();
438          char    buf[256], *dir, *uname;
# Line 405 | Line 487 | sethosts()                     /* set up process servers */
487          }
488   }
489  
490 <
491 < getradfile(rfname)              /* run rad and get needed variables */
410 < char    *rfname;
490 > static void
491 > getradfile(char *rfargs)                /* run rad and get needed variables */
492   {
493          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
494          char    combuf[256];
495          register int    i;
496          register char   *cp;
497 +        char    *pippt = NULL;
498                                          /* create rad command */
499          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
500          sprintf(combuf,
501          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
502 <                        rfname, rendopt+2);
502 >                        rfargs, rendopt+2);
503          cp = combuf;
504 <        while (*cp) cp++;               /* match unset variables */
504 >        while (*cp) {
505 >                if (*cp == '|') pippt = cp;
506 >                cp++;
507 >        }                               /* match unset variables */
508          for (i = 0; mvar[i] >= 0; i++)
509                  if (!vdef(mvar[i])) {
510                          *cp++ = '|';
511                          strcpy(cp, vnam(mvar[i]));
512                          while (*cp) cp++;
513 +                        pippt = NULL;
514                  }
515 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
516 <        cp += 11;                       /* point to file name */
517 <        if (system(combuf)) {
518 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
519 <                                progname, rfname);
434 <                quit(1);
515 >        if (pippt != NULL)
516 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
517 >        else {
518 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
519 >                cp += 11;               /* point to file name */
520          }
521 <        loadvars(cp);                   /* load variables and remove file */
522 <        unlink(cp);
521 >        system(combuf);                 /* ignore exit code */
522 >        if (pippt == NULL) {            /* load variables and remove file */
523 >                loadvars(cp);
524 >                unlink(cp);
525 >        }
526   }
527  
528  
529 < animate()                       /* run animation */
529 > static void
530 > animate(void)                   /* run animation */
531   {
532          int     xres, yres;
533          float   pa, mult;
# Line 449 | Line 538 | animate()                      /* run animation */
538          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
539          mult = vflt(OVERSAMP);
540          if (i == 3) {
541 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
541 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
542                                  (int)(mult*yres), pa);
543 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
543 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
544          } else if (i) {
545                  if (i == 1) yres = xres;
546                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 468 | Line 557 | animate()                      /* run animation */
557                                                  progname, vnam(INTERP));
558                          vval(INTERP) = "0";
559                  }
560 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
560 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
561                          if (!nowarn)
562                                  fprintf(stderr,
563                                          "%s: resetting %s=0 for animation\n",
# Line 478 | Line 567 | animate()                      /* run animation */
567          }
568                                          /* figure # frames per batch */
569          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
570 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
571 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
570 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
571 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
572          d2 = xres*yres*4;                       /* space for final picture */
573          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
574          if (frames_batch < i+2) {
# Line 487 | Line 576 | animate()                      /* run animation */
576                                  progname);
577                  quit(1);
578          }
579 +                                        /* initialize archive argument list */
580 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
581 +        arcnext = arcfirst = arcargs + i;
582                                          /* initialize status file */
583          if (astat.rnext == 0)
584                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 506 | Line 598 | animate()                      /* run animation */
598   }
599  
600  
601 < renderframes(nframes)           /* render next nframes frames */
602 < int     nframes;
601 > static void
602 > renderframes(int nframes)               /* render next nframes frames */
603   {
604          static char     vendbuf[16];
605          VIEW    *vp;
# Line 563 | Line 655 | int    nframes;
655   }
656  
657  
658 < filterframes()                          /* catch up with filtering */
658 > static void
659 > filterframes(void)                              /* catch up with filtering */
660   {
568        VIEW    *vp;
661          register int    i;
662  
663          if (astat.tnext < astat.fnext)  /* other work to do first */
664                  return;
665                                          /* filter each view */
666 <        for (i = astat.fnext; i < astat.rnext; i++) {
667 <                if ((vp = getview(i)) == NULL) {        /* get view i */
668 <                        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 <        }
666 >        for (i = astat.fnext; i < astat.rnext; i++)
667 >                dofilt(i, 0);
668 >
669          bwait(0);                       /* wait for filter processes */
670 <        archive(astat.fnext, i-1);      /* archive originals */
670 >        archive();                      /* archive originals */
671          astat.fnext = i;                /* update status */
672          putastat();
673   }
674  
675  
676 < transferframes()                        /* catch up with picture transfers */
676 > static void
677 > transferframes(void)                    /* catch up with picture transfers */
678   {
679 <        char    combuf[10240];
679 >        char    combuf[10240], *fbase;
680          register char   *cp;
681          register int    i;
682  
# Line 600 | Line 687 | transferframes()                       /* catch up with picture transfers
687                  putastat();             /* update status */
688                  return;
689          }
690 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
691 <        cp = combuf + strlen(combuf);
690 >        strcpy(combuf, "cd ");          /* start transfer command */
691 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
692 >        if (*cp) {
693 >                while (*++cp) ;
694 >                *cp++ = ';'; *cp++ = ' ';
695 >        } else
696 >                cp = combuf;
697 >        strcpy(cp, vval(TRANSFER));
698 >        while (*cp) cp++;
699                                          /* make argument list */
700          for (i = astat.tnext; i < astat.fnext; i++) {
701                  *cp++ = ' ';
702 <                sprintf(cp, vval(BASENAME), i);
702 >                sprintf(cp, fbase, i);
703                  while (*cp) cp++;
704                  strcpy(cp, ".pic");
705                  cp += 4;
# Line 620 | Line 714 | transferframes()                       /* catch up with picture transfers
714   }
715  
716  
717 < animrend(frame, vp)                     /* start animation frame */
718 < int     frame;
719 < VIEW    *vp;
717 > static void
718 > animrend(                       /* start animation frame */
719 > int     frame,
720 > VIEW    *vp
721 > )
722   {
627        extern int      recover();
723          char    combuf[2048];
724          char    fname[128];
725  
# Line 638 | Line 733 | VIEW   *vp;
733   }
734  
735  
736 < walkwait(first, last, vfn)              /* walk-through frames */
737 < int     first, last;
738 < char    *vfn;
736 > static void
737 > walkwait(               /* walk-through frames */
738 > int     first,
739 > int last,
740 > char    *vfn
741 > )
742   {
743 +        double  blurf;
744 +        int     nblur = getblur(&blurf);
745          char    combuf[2048];
746 <        char    *inspoint;
746 >        register char   *inspoint;
747          register int    i;
748  
749          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 654 | Line 754 | char   *vfn;
754                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
755                          }
756                                          /* create command */
757 <        sprintf(combuf, "rpict%s -w0", rendopt);
758 <        if (vint(INTERP) || atoi(vval(MBLUR)))
759 <                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
760 <        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
757 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
758 >                        viewopt(getview(first>1 ? first-1 : 1)));
759 >        inspoint = combuf;
760 >        while (*inspoint) inspoint++;
761 >        if (nblur) {
762 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
763 >                while (*inspoint) inspoint++;
764 >        }
765 >        if (nblur > 1 || vint(INTERP)) {
766 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
767 >                while (*inspoint) inspoint++;
768 >        }
769 >        sprintf(inspoint, " -o %s.unf %s -S %d",
770                          vval(BASENAME), rresopt, first);
771 <        inspoint = combuf + strlen(combuf);
771 >        while (*inspoint) inspoint++;
772          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
773                                          /* run in parallel */
774 <        if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) {
774 >        i = (last-first+1)/(vint(INTERP)+1);
775 >        if (i < 1) i = 1;
776 >        if (pruncom(combuf, inspoint, i)) {
777                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
778                                  progname, first, last);
779                  quit(1);
# Line 677 | Line 788 | char   *vfn;
788   }
789  
790  
791 < int
792 < recover(frame)                          /* recover the specified frame */
682 < int     frame;
791 > static int
792 > recover(int frame)                      /* recover the specified frame */
793   {
794          static int      *rfrm;          /* list of recovered frames */
795          static int      nrfrms = 0;
796 +        double  blurf;
797 +        int     nblur = getblur(&blurf);
798          char    combuf[2048];
799          char    fname[128];
800          register char   *cp;
# Line 698 | Line 810 | int    frame;
810                                  vval(ANIMATE), frame, rendopt);
811          else
812                  sprintf(combuf, "rpict%s -w0", rendopt);
813 <        cp = combuf + strlen(combuf);
814 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
813 >        cp = combuf;
814 >        while (*cp) cp++;
815 >        if (nblur) {
816 >                sprintf(cp, " -pm %.3f", blurf/nblur);
817 >                while (*cp) cp++;
818 >        }
819 >        if (nblur > 1 || vint(INTERP)) {
820                  sprintf(cp, " -z %s.zbf", fname);
821                  while (*cp) cp++;
822          }
# Line 713 | Line 830 | int    frame;
830                  return(1);
831                                          /* add frame to recovered list */
832          if (nrfrms)
833 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
833 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
834          else
835                  rfrm = (int *)malloc(sizeof(int));
836          if (rfrm == NULL) {
# Line 725 | Line 842 | int    frame;
842   }
843  
844  
845 < int
846 < frecover(frame)                         /* recover filtered frame */
730 < int     frame;
845 > static int
846 > frecover(int frame)                             /* recover filtered frame */
847   {
848 <        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))
848 >        if (dofilt(frame, 2) && dofilt(frame, 1))
849                  return(1);
850          return(0);
851   }
852  
853  
854 < archive(first, last)                    /* archive and remove renderings */
855 < int     first, last;
854 > static void
855 > archive(void)                   /* archive and remove renderings */
856   {
857   #define RMCOML  (sizeof(rmcom)-1)
858          static char     rmcom[] = "rm -f";
859 <        int     offset = RMCOML;
860 <        char    combuf[10240];
861 <        struct stat     stb;
751 <        register char   *cp;
752 <        register int    i;
859 >        char    basedir[128];
860 >        int     dlen, alen;
861 >        register int    j;
862  
863 <        if (noaction)
864 <                return;
865 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
866 <                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;
863 >        if (arcnext == arcfirst)
864 >                return;                         /* nothing to do */
865 >        dirfile(basedir, vval(BASENAME));
866 >        dlen = strlen(basedir);
867          if (vdef(ARCHIVE)) {                    /* run archive command */
868 <                i = strlen(vval(ARCHIVE));
869 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
870 <                if (runcom(combuf+offset-i)) {
871 <                        fprintf(stderr,
872 <                "%s: error running archive command on frames %d through %d\n",
873 <                                        progname, first, last);
868 >                alen = strlen(vval(ARCHIVE));
869 >                if (dlen) {
870 >                        j = alen + dlen + 5;
871 >                        strncpy(arcfirst-j, "cd ", 3);
872 >                        strncpy(arcfirst-j+3, basedir, dlen);
873 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
874 >                } else
875 >                        j = alen;
876 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
877 >                if (runcom(arcfirst-j)) {
878 >                        fprintf(stderr, "%s: error running archive command\n",
879 >                                        progname);
880                          quit(1);
881                  }
882          }
883 +        if (dlen) {
884 +                j = RMCOML + dlen + 5;
885 +                strncpy(arcfirst-j, "cd ", 3);
886 +                strncpy(arcfirst-j+3, basedir, dlen);
887 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
888 +        } else
889 +                j = RMCOML;
890                                                  /* run remove command */
891 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
892 <        runcom(combuf+offset-RMCOML);
891 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
892 >        runcom(arcfirst-j);
893 >        arcnext = arcfirst;                     /* reset argument list */
894   #undef RMCOML
895   }
896  
897  
898 < int
899 < dofilt(frame, vp, ep, rvr)                      /* filter frame */
900 < int     frame;
901 < VIEW    *vp;
902 < char    *ep;
799 < int     rvr;
898 > static int
899 > dofilt(                         /* filter frame */
900 > int     frame,
901 > int     rvr
902 > )
903   {
904 <        extern int      frecover();
905 <        char    fnbefore[128], fnafter[128];
906 <        char    combuf[1024], fname[128];
907 <        int     usepinterp, usepfilt;
904 >        static int      iter = 0;
905 >        double  blurf;
906 >        int     nblur = getblur(&blurf);
907 >        VIEW    *vp = getview(frame);
908 >        char    *ep = getexp(frame);
909 >        char    fnbefore[128], fnafter[128], *fbase;
910 >        char    combuf[1024], fname0[128], fname1[128];
911 >        int     usepinterp, usepfilt, nora_rgbe;
912          int     frseq[2];
913                                                  /* check what is needed */
914 <        usepinterp = atoi(vval(MBLUR));
915 <        usepfilt = pfiltalways | ep==NULL;
914 >        if (vp == NULL) {
915 >                 fprintf(stderr,
916 >                        "%s: unexpected error reading view for frame %d\n",
917 >                                          progname, frame);
918 >                quit(1);
919 >        }
920 >        usepinterp = (nblur > 1);
921 >        usepfilt = pfiltalways | (ep==NULL);
922 >        if (ep != NULL && !strcmp(ep, "1"))
923 >                ep = "+0";
924 >        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
925 >                        *ep != '+' || *ep != '-' || !isint(ep);
926                                                  /* compute rendered views */
927          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
928          frseq[1] = frseq[0] + vint(INTERP) + 1;
929 +        fbase = dirfile(NULL, vval(BASENAME));
930          if (frseq[1] > vint(END))
931                  frseq[1] = vint(END);
932          if (frseq[1] == frame) {                        /* pfilt only */
933                  frseq[0] = frseq[1];
934                  usepinterp = 0;                 /* update what's needed */
935 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
936 <        } else if (frseq[0] == frame) {         /* no interpolation */
937 <                                                /* update what's needed */
938 <                if (!usepinterp)
939 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
935 >                usepfilt |= nora_rgbe;
936 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
937 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
938 >                        *arcnext++ = ' ';
939 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
940 >                        while (*arcnext) arcnext++;
941 >                        strcpy(arcnext, ".unf");
942 >                        arcnext += 4;
943 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
944 >                                *arcnext++ = ' ';
945 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
946 >                                while (*arcnext) arcnext++;
947 >                                strcpy(arcnext, ".zbf");
948 >                                arcnext += 4;
949 >                        }
950 >                }
951 >                if (!usepinterp)                /* update what's needed */
952 >                        usepfilt |= nora_rgbe;
953          } else                                  /* interpolation needed */
954                  usepinterp++;
955          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 831 | Line 962 | int    rvr;
962          if (usepinterp) {                       /* using pinterp */
963                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
964                          return(1);
965 <                if (atoi(vval(MBLUR))) {
966 <                        FILE    *fp;            /* motion blurring */
967 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
968 <                        if (access(fname, F_OK) == 0)
969 <                                sleep(10);
970 <                        if ((fp = fopen(fname, "w")) == NULL) {
971 <                                perror(fname); quit(1);
972 <                        }
973 <                        fputs(VIEWSTR, fp);
974 <                        fprintview(vp, fp);
975 <                        putc('\n', fp); fclose(fp);
976 <                        if ((vp = getview(frame+1)) == NULL) {
977 <                                fprintf(stderr,
965 >                if (nblur > 1) {                /* with pmblur */
966 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
967 >                                        'a'+(iter%26));
968 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
969 >                                        'a'+(iter%26));
970 >                        if (!noaction) {
971 >                                FILE    *fp;            /* motion blurring */
972 >                                if ((fp = fopen(fname0, "w")) == NULL) {
973 >                                        perror(fname0); quit(1);
974 >                                }
975 >                                fputs(VIEWSTR, fp);
976 >                                fprintview(vp, fp);
977 >                                putc('\n', fp); fclose(fp);
978 >                                if ((vp = getview(frame+1)) == NULL) {
979 >                                        fprintf(stderr,
980                          "%s: unexpected error reading view for frame %d\n",
981 <                                                progname, frame+1);
982 <                                quit(1);
981 >                                                        progname, frame+1);
982 >                                        quit(1);
983 >                                }
984 >                                if ((fp = fopen(fname1, "w")) == NULL) {
985 >                                        perror(fname1); quit(1);
986 >                                }
987 >                                fputs(VIEWSTR, fp);
988 >                                fprintview(vp, fp);
989 >                                putc('\n', fp); fclose(fp);
990                          }
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);
991                          sprintf(combuf,
992 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
993 <                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
994 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
995 <                                        vval(DIRECTORY), vval(DIRECTORY),
863 <                                        vval(DIRECTORY), vval(DIRECTORY));
992 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
993 >                                        blurf, nblur,
994 >                                        fname0, fname1, fname0, fname1);
995 >                        iter++;
996                  } else                          /* no blurring */
997                          strcpy(combuf, "pinterp");
998                  strcat(combuf, viewopt(vp));
999                  if (vbool(RTRACE))
1000                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1001 <                                        rendopt, vval(OCTREE));
1001 >                                        rendopt+1, vval(OCTREE));
1002                  if (vdef(PINTERP))
1003                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1004                  if (usepfilt)
1005                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1006                  else
1007 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1007 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1008                                          fresopt, ep);
1009                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1010                                  fnbefore, fnbefore);
# Line 907 | Line 1039 | int    rvr;
1039          } else {                                /* else just check it */
1040                  if (rvr == 2)
1041                          return(1);
1042 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
1042 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1043          }
1044                                                  /* output file name */
1045 <        sprintf(fname, vval(BASENAME), frame);
1046 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
1045 >        sprintf(fname0, vval(BASENAME), frame);
1046 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1047          if (rvr)                                /* in recovery */
1048                  return(runcom(combuf));
1049          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 919 | Line 1051 | int    rvr;
1051   }
1052  
1053  
1054 < VIEW *
1055 < getview(n)                      /* get view number n */
924 < int     n;
1054 > static VIEW *
1055 > getview(int n)                  /* get view number n */
1056   {
1057          static FILE     *viewfp = NULL;         /* view file pointer */
1058          static int      viewnum = 0;            /* current view number */
# Line 933 | Line 1064 | int    n;
1064                          fclose(viewfp);
1065                          viewfp = NULL;
1066                          viewnum = 0;
1067 <                        copystruct(&curview, &stdview);
1067 >                        curview = stdview;
1068                  }
1069                  return(NULL);
1070          }
1071 <        if (viewfp == NULL) {           /* open file */
1071 >        if (viewfp == NULL) {                   /* open file */
1072                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1073                          perror(vval(VIEWFILE));
1074                          quit(1);
1075                  }
1076 <        } else if (n < viewnum) {       /* rewind file */
1076 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1077 >                if (viewnum == 1 && feof(viewfp))
1078 >                        return(&curview);               /* just one view */
1079                  if (fseek(viewfp, 0L, 0) == EOF) {
1080                          perror(vval(VIEWFILE));
1081                          quit(1);
1082                  }
1083 <                copystruct(&curview, &stdview);
1083 >                curview = stdview;
1084                  viewnum = 0;
1085          }
1086 +        if (n < 0) {                            /* get next view */
1087 +                register int    c = getc(viewfp);
1088 +                if (c == EOF)
1089 +                        return((VIEW *)NULL);           /* that's it */
1090 +                ungetc(c, viewfp);
1091 +                n = viewnum + 1;
1092 +        }
1093          while (n > viewnum) {           /* scan to desired view */
1094                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1095 <                        return(NULL);
1095 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1096                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1097                          viewnum++;
1098          }
# Line 960 | Line 1100 | int    n;
1100   }
1101  
1102  
1103 < int
1104 < countviews()                    /* count views in view file */
1103 > static int
1104 > countviews(void)                        /* count views in view file */
1105   {
1106 <        register int    n = 0;
1106 >        int     n;
1107  
1108 <        while (getview(n+1) != NULL)
1108 >        if (getview(n=1) == NULL)
1109 >                return(0);
1110 >        while (getview(-1) != NULL)
1111                  n++;
1112          return(n);
1113   }
1114  
1115  
1116 < char *
1117 < getexp(n)                       /* get exposure for nth frame */
976 < int     n;
1116 > static char *
1117 > getexp(int n)                   /* get exposure for nth frame */
1118   {
1119          extern char     *fskip();
1120          static char     expval[32];
# Line 985 | Line 1126 | int    n;
1126          if (n == 0) {                           /* signal to close file */
1127                  if (expfp != NULL) {
1128                          fclose(expfp);
1129 +                        free((void *)exppos);
1130                          expfp = NULL;
1131                  }
1132                  return(NULL);
1133 <        }
1133 >        } else if (n > vint(END))               /* request past end (error?) */
1134 >                return(NULL);
1135          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1136                  return(NULL);
1137          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1026 | Line 1169 | int    n;
1169                  }
1170                  curfrm++;
1171                  cp = fskip(expval);                     /* check format */
1172 <                if (cp == NULL || *cp != '\n') {
1172 >                if (cp != NULL)
1173 >                        while (isspace(*cp))
1174 >                                *cp++ = '\0';
1175 >                if (cp == NULL || *cp) {
1176                          fprintf(stderr,
1177                                  "%s: exposure format error on line %d\n",
1178                                          vval(EXPOSURE), curfrm);
1179                          quit(1);
1180                  }
1035                *cp = '\0';
1181          }
1182          return(expval);                         /* return value */
1183   }
1184  
1185  
1186 < struct pslot *
1187 < findpslot(pid)                  /* find or allocate a process slot */
1043 < int     pid;
1186 > static struct pslot *
1187 > findpslot(int pid)                      /* find or allocate a process slot */
1188   {
1189          register struct pslot   *psempty = NULL;
1190          register int    i;
# Line 1055 | Line 1199 | int    pid;
1199   }
1200  
1201  
1202 < int
1203 < donecom(ps, pn, status)         /* clean up after finished process */
1204 < PSERVER *ps;
1205 < int     pn;
1206 < int     status;
1202 > static int
1203 > donecom(                /* clean up after finished process */
1204 >        PSERVER *ps,
1205 >        int     pn,
1206 >        int     status
1207 > )
1208   {
1209 <        register PROC   *pp;
1209 >        register NETPROC        *pp;
1210 >        register struct pslot   *psl;
1211  
1212          pp = ps->proc + pn;
1213          if (pp->elen) {                 /* pass errors */
# Line 1073 | Line 1219 | int    status;
1219                  if (ps->hostname[0])
1220                          status = 1;     /* because rsh doesn't return status */
1221          }
1222 +        lastpserver = NULL;
1223 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1224 +        if (psl->pid) {
1225 +                if (status) {
1226 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1227 +                                status = (*psl->rcvf)(psl->fout);
1228 +                        if (status) {
1229 +                                fprintf(stderr,
1230 +                                        "%s: error rendering frame %d\n",
1231 +                                                progname, psl->fout);
1232 +                                quit(1);
1233 +                        }
1234 +                        lastpserver = ps;
1235 +                }
1236 +                psl->pid = 0;                   /* free process slot */
1237 +        } else if (status)
1238 +                lastpserver = ps;
1239          freestr(pp->com);               /* free command string */
1077        lastpid = pp->pid;              /* record PID for bwait() */
1078        lastpserver = ps;               /* record server for serverdown() */
1240          return(status);
1241   }
1242  
1243  
1244 < int
1245 < serverdown()                    /* check status of last process server */
1244 > static int
1245 > serverdown(void)                        /* check status of last process server */
1246   {
1247 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1248 +                return(0);
1249          if (pserverOK(lastpserver))     /* server still up? */
1250                  return(0);
1251          delpserver(lastpserver);        /* else delete it */
# Line 1095 | Line 1258 | serverdown()                   /* check status of last process server
1258   }
1259  
1260  
1261 < int
1262 < bruncom(com, fout, rf)          /* run a command in the background */
1263 < char    *com;
1264 < int     fout;
1265 < int     (*rf)();
1261 > static int
1262 > bruncom(                /* run a command in the background */
1263 > char    *com,
1264 > int     fout,
1265 > int     (*rf)()
1266 > )
1267   {
1268          int     pid;
1269          register struct pslot   *psl;
# Line 1109 | Line 1273 | int    (*rf)();
1273                          printf("\t%s\n", com);  /* echo command */
1274                  return(0);
1275          }
1276 <                                        /* else start it when we can */
1277 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1276 >        com = savestr(com);             /* else start it when we can */
1277 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1278                  bwait(1);
1279          if (!silent) {                          /* echo command */
1280                  PSERVER *ps;
# Line 1128 | Line 1292 | int    (*rf)();
1292   }
1293  
1294  
1295 < bwait(ncoms)                            /* wait for batch job(s) to finish */
1296 < int     ncoms;
1295 > static void
1296 > bwait(int ncoms)                                /* wait for batch job(s) to finish */
1297   {
1298          int     status;
1135        register struct pslot   *psl;
1299  
1300          if (noaction)
1301                  return;
1302          while ((status = wait4job(NULL, -1)) != -1) {
1303 <                psl = findpslot(lastpid);
1304 <                if (status) {           /* attempt recovery */
1305 <                        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 */
1303 >                serverdown();           /* update server status */
1304 >                if (--ncoms == 0)
1305 >                        break;          /* done enough */
1306          }
1307   }
1308  
1309  
1310 < int
1311 < pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1312 < char    *com, *ppins;
1313 < int     maxcopies;
1310 > static int
1311 > pruncom(        /* run a command in parallel over network */
1312 > char    *com,
1313 > char    *ppins,
1314 > int     maxcopies
1315 > )
1316   {
1317          int     retstatus = 0;
1318          int     hostcopies;
1319 <        char    com1buf[10240], *com1, *endcom1;
1319 >        char    buf[10240], *com1, *s;
1320          int     status;
1321 +        int     pfd;
1322 +        register int    n;
1323          register PSERVER        *ps;
1324  
1325          if (!silent)
1326 <                printf("\t%s &\n", com);        /* echo command */
1326 >                printf("\t%s\n", com);  /* echo command */
1327          if (noaction)
1328                  return(0);
1329          fflush(stdout);
# Line 1174 | Line 1331 | int    maxcopies;
1331          for (ps = pslist; ps != NULL; ps = ps->next) {
1332                  hostcopies = 0;
1333                  if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1334 <                        strcpy(com1=com1buf, com);      /* build -PP command */
1334 >                        strcpy(com1=buf, com);  /* build -PP command */
1335                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1336                                          vval(DIRECTORY), phostname(ps));
1337 +                        unlink(com1+(ppins-com)+5);
1338                          strcat(com1, ppins);
1339 <                        endcom1 = com1 + strlen(com1);
1182 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1183 <                                        vval(DIRECTORY), phostname(ps));
1184 <                } else {
1339 >                } else
1340                          com1 = com;
1341 <                        endcom1 = NULL;
1341 >                while (maxcopies > 0) {
1342 >                        s = savestr(com1);
1343 >                        if (startjob(ps, s, donecom) != -1) {
1344 >                                sleep(20);
1345 >                                hostcopies++;
1346 >                                maxcopies--;
1347 >                        } else {
1348 >                                freestr(s);
1349 >                                break;
1350 >                        }
1351                  }
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                }
1352                  if (!silent && hostcopies) {
1353                          if (hostcopies > 1)
1354                                  printf("\t%d duplicate processes", hostcopies);
# Line 1204 | Line 1360 | int    maxcopies;
1360          }
1361                                          /* wait for jobs to finish */
1362          while ((status = wait4job(NULL, -1)) != -1)
1363 <                if (status)
1364 <                        retstatus += !serverdown();     /* check server */
1363 >                retstatus += status && !serverdown();
1364 >                                        /* terminate parallel rpict's */
1365 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1366 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1367 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1368 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1369 >                        buf[n] = '\0';
1370 >                        close(pfd);
1371 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1372 >                                ;
1373 >                                                                /* terminate */
1374 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1375 >                        wait4job(ps, startjob(ps, buf, NULL));
1376 >                }
1377 >        }
1378          return(retstatus);
1379   }
1380  
1381  
1382 < runcom(cs)                      /* run a command locally and wait for it */
1383 < char    *cs;
1382 > static int
1383 > runcom(char *cs)                        /* run a command locally and wait for it */
1384   {
1385          if (!silent)            /* echo it */
1386                  printf("\t%s\n", cs);
# Line 1222 | Line 1391 | char   *cs;
1391   }
1392  
1393  
1394 < rmfile(fn)                      /* remove a file */
1395 < char    *fn;
1394 > static int
1395 > rmfile(char *fn)                        /* remove a file */
1396   {
1397          if (!silent)
1398 < #ifdef MSDOS
1398 > #ifdef _WIN32
1399                  printf("\tdel %s\n", fn);
1400   #else
1401                  printf("\trm -f %s\n", fn);
# Line 1237 | Line 1406 | char   *fn;
1406   }
1407  
1408  
1409 < badvalue(vc)                    /* report bad variable value and exit */
1410 < int     vc;
1409 > static void
1410 > badvalue(int vc)                        /* report bad variable value and exit */
1411   {
1412          fprintf(stderr, "%s: bad value for variable '%s'\n",
1413                          progname, vnam(vc));
1414          quit(1);
1415 + }
1416 +
1417 +
1418 + static char *
1419 + dirfile(                /* separate path into directory and file */
1420 + char    *df,
1421 + register char   *path
1422 + )
1423 + {
1424 +        register int    i;
1425 +        int     psep;
1426 +
1427 +        for (i = 0, psep = -1; path[i]; i++)
1428 +                if (path[i] == '/')
1429 +                        psep = i;
1430 +        if (df != NULL) {
1431 +                if (psep == 0) {
1432 +                        df[0] = '/';
1433 +                        df[1] = '\0';
1434 +                } else if (psep > 0) {
1435 +                        strncpy(df, path, psep);
1436 +                        df[psep] = '\0';
1437 +                } else
1438 +                        df[0] = '\0';
1439 +        }
1440 +        return(path+psep+1);
1441 + }
1442 +
1443 +
1444 + static int
1445 + getblur(double *bf)             /* get # blur samples (and fraction) */
1446 + {
1447 +        double  blurf;
1448 +        int     nblur;
1449 +        char    *s;
1450 +
1451 +        if (!vdef(MBLUR)) {
1452 +                if (bf != NULL)
1453 +                        *bf = 0.0;
1454 +                return(0);
1455 +        }
1456 +        blurf = atof(vval(MBLUR));
1457 +        if (blurf < 0.0)
1458 +                blurf = 0.0;
1459 +        if (bf != NULL)
1460 +                *bf = blurf;
1461 +        if (blurf <= FTINY)
1462 +                return(0);
1463 +        s = sskip(vval(MBLUR));
1464 +        if (!*s)
1465 +                return(DEF_NBLUR);
1466 +        nblur = atoi(s);
1467 +        if (nblur <= 0)
1468 +                return(1);
1469 +        return(nblur);
1470   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines