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

Comparing ray/src/util/ranimate.c (file contents):
Revision 2.1 by greg, Fri Jan 12 12:16:17 1996 UTC vs.
Revision 2.43 by schorsch, Mon Oct 27 10:32:06 2003 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"
17 < #include <sys/types.h>
16 > #include "copyright.h"
17 >
18 > #include <stdio.h>
19 > #include <ctype.h>
20   #include <sys/stat.h>
21 + #include <time.h>
22 +
23 + /*#include "standard.h"*/
24 + #include "platform.h"
25 + #include "paths.h"
26 + #include "rtio.h"
27 + #include "rterror.h"
28   #include "view.h"
29   #include "vars.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 > #include "netproc.h"
31 >                                /* default blur samples */
32 > #ifndef DEF_NBLUR
33 > #define DEF_NBLUR       5
34 > #endif
35 >                                /* default remote shell */
36 > #define REMSH           "rsh"
37 >                                /* input variables (alphabetical by name) */
38 > #define ANIMATE         0               /* animation command */
39 > #define ARCHIVE         1               /* archiving command */
40 > #define BASENAME        2               /* output image base name */
41 > #define DIRECTORY       3               /* working (sub)directory */
42 > #define DISKSPACE       4               /* how much disk space to use */
43 > #define END             5               /* ending frame number */
44 > #define EXPOSURE        6               /* how to compute exposure */
45 > #define HOST            7               /* rendering host machine */
46 > #define INTERP          8               /* # frames to interpolate */
47 > #define MBLUR           9               /* motion blur parameters */
48 > #define NEXTANIM        10              /* next animation file */
49 > #define OCTREE          11              /* octree file name */
50 > #define OVERSAMP        12              /* # times to oversample image */
51 > #define PFILT           13              /* pfilt options */
52 > #define PINTERP         14              /* pinterp options */
53 > #define RENDER          15              /* rendering options */
54 > #define RESOLUTION      16              /* desired final resolution */
55 > #define RIF             17              /* rad input file */
56 > #define RSH             18              /* remote shell script or program */
57 > #define RTRACE          19              /* use rtrace with pinterp? */
58 > #define START           20              /* starting frame number */
59 > #define TRANSFER        21              /* frame transfer command */
60 > #define VIEWFILE        22              /* animation frame views */
61  
62 < int     NVARS = 22;             /* total number of variables */
62 > int     NVARS = 23;             /* total number of variables */
63  
64   VARIABLE        vv[] = {                /* variable-value pairs */
65 +        {"ANIMATE",     2,      0,      NULL,   onevalue},
66 +        {"ARCHIVE",     2,      0,      NULL,   onevalue},
67 +        {"BASENAME",    3,      0,      NULL,   onevalue},
68 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
69 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
70 +        {"END",         2,      0,      NULL,   intvalue},
71 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
72          {"host",        4,      0,      NULL,   NULL},
73 <        {"render",      3,      0,      NULL,   catvalues},
73 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
74 >        {"MBLUR",       2,      0,      NULL,   onevalue},
75 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
76 >        {"OCTREE",      3,      0,      NULL,   onevalue},
77 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
78          {"pfilt",       2,      0,      NULL,   catvalues},
79          {"pinterp",     2,      0,      NULL,   catvalues},
80 <        {"OCTREE",      3,      0,      NULL,   onevalue},
81 <        {"DIRECTORY",   3,      0,      NULL,   onevalue},
49 <        {"BASENAME",    3,      0,      NULL,   onevalue},
50 <        {"VIEWFILE",    2,      0,      NULL,   onevalue},
51 <        {"START",       2,      0,      NULL,   intvalue},
52 <        {"END",         2,      0,      NULL,   intvalue},
80 >        {"render",      3,      0,      NULL,   catvalues},
81 >        {"RESOLUTION",  3,      0,      NULL,   onevalue},
82          {"RIF",         3,      0,      NULL,   onevalue},
83 <        {"NEXTANIM",    3,      0,      NULL,   onevalue},
55 <        {"ANIMATE",     2,      0,      NULL,   onevalue},
56 <        {"TRANSFER",    2,      0,      NULL,   onevalue},
57 <        {"ARCHIVE",     2,      0,      NULL,   onevalue},
58 <        {"INTERP",      3,      0,      NULL,   intvalue},
59 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
60 <        {"MBLUR",       2,      0,      NULL,   onevalue},
83 >        {"RSH",         3,      0,      NULL,   onevalue},
84          {"RTRACE",      2,      0,      NULL,   boolvalue},
85 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
86 <        {"RESOLUTION",  3,      0,      NULL,   onevalue},
87 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
85 >        {"START",       2,      0,      NULL,   intvalue},
86 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
87 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
88   };
89  
90   #define SFNAME  "STATUS"                /* status file name */
# Line 82 | Line 105 | int    nowarn = 0;             /* turn warnings off? */
105   int     silent = 0;             /* silent mode? */
106   int     noaction = 0;           /* take no action? */
107  
108 < char    rendopt[2048] = "";     /* rendering options */
108 > char    *remsh;                 /* remote shell program/script */
109 > char    rendopt[2048];          /* rendering options */
110   char    rresopt[32];            /* rendering resolution options */
111   char    fresopt[32];            /* filter resolution options */
112   int     pfiltalways;            /* always use pfilt? */
113  
114 < VIEW    *getview();
115 < char    *getexp();
114 > char    arcargs[10240];         /* files to archive */
115 > char    *arcfirst, *arcnext;    /* pointers to first and next argument */
116  
117 + struct pslot {
118 +        int     pid;                    /* process ID (0 if empty) */
119 +        int     fout;                   /* output frame number */
120 +        int     (*rcvf)();              /* recover function */
121 + }       *pslot;                 /* process slots */
122 + int     npslots;                /* number of process slots */
123  
124 + #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
125 + PSERVER *lastpserver;           /* last process server with error */
126 +
127 + static struct pslot * findpslot(int pid);
128 + static void checkdir(void);
129 + static VIEW * getview(int n);
130 +
131 + static char * dirfile(char *df, register char *path);
132 + static char * getexp(int n);
133 + static int getblur(double *bf);
134 + static int getastat(void);
135 + static void getradfile(char *rfargs);
136 + static void badvalue(int vc);
137 + static int rmfile(char *fn);
138 + static int runcom(char *cs);
139 + static int pruncom(char *com, char *ppins, int maxcopies);
140 + static void bwait(int ncoms);
141 + static int bruncom(char *com, int fout, int (*rf)());
142 + static int serverdown(void);
143 + static int donecom(PSERVER *ps, int pn, int status);
144 + static int countviews(void);
145 + static int dofilt(int frame, int rvr);
146 + static void archive(void);
147 + static int frecover(int frame);
148 + static int recover(int frame);
149 + static void sethosts(void);
150 + static void walkwait(int first, int last, char *vfn);
151 + static void animrend(int frame, VIEW *vp);
152 + static void transferframes(void);
153 + static void filterframes(void);
154 + static void renderframes(int nframes);
155 + static void animate(void);
156 + static void setdefaults(void);
157 + static void putastat(void);
158 +
159 +
160   main(argc, argv)
161   int     argc;
162   char    *argv[];
# Line 121 | Line 187 | char   *argv[];
187          cfname = argv[i];
188                                                  /* load variables */
189          loadvars(cfname);
190 +                                                /* check variables */
191 +        checkvalues();
192                                                  /* did we get DIRECTORY? */
193          checkdir();
194                                                  /* check status */
# Line 138 | Line 206 | char   *argv[];
206                                                  /* print variables */
207          if (explicate)
208                  printvars(stdout);
209 +                                                /* set up process servers */
210 +        sethosts();
211                                                  /* run animation */
212          animate();
213                                                  /* all done */
# Line 145 | Line 215 | char   *argv[];
215                  argv[i] = vval(NEXTANIM);       /* just change input file */
216                  if (!silent)
217                          printargs(argc, argv, stdout);
218 <                if (!noaction) {
219 <                        execvp(progname, argv);         /* pass to next */
220 <                        quit(1);                        /* shouldn't return */
221 <                }
218 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
219 >                        fprintf(stderr, "%s: command not found\n", progname);
220 >                else
221 >                        execv(progname, argv);
222 >                quit(1);
223          }
224          quit(0);
225   userr:
# Line 157 | Line 228 | userr:
228   }
229  
230  
231 < getastat()                      /* check/set animation status */
231 > static int
232 > getastat(void)                  /* check/set animation status */
233   {
234 <        char    buf[256];
234 >        char    sfname[256];
235          FILE    *fp;
236  
237 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
238 <        if ((fp = fopen(buf, "r")) == NULL) {
237 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
238 >        if ((fp = fopen(sfname, "r")) == NULL) {
239                  if (errno != ENOENT) {
240 <                        perror(buf);
240 >                        perror(sfname);
241                          return(-1);
242                  }
243                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 185 | Line 257 | getastat()                     /* check/set animation status */
257                  goto fmterr;
258          fclose(fp);
259          if (astat.pid != 0) {                   /* thinks it's still running */
260 <                gethostname(buf, sizeof(buf));
189 <                if (strcmp(buf, astat.host)) {
260 >                if (strcmp(myhostname(), astat.host)) {
261                          fprintf(stderr,
262                          "%s: process %d may still be running on host %s\n",
263                                          progname, astat.pid, astat.host);
# Line 199 | Line 270 | getastat()                     /* check/set animation status */
270                  }
271                  /* assume it is dead */
272          }
273 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
273 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
274                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
275                                  progname, astat.cfname);
276                  return(-1);
277          }
278 +                                                /* check control file mods. */
279 +        if (!nowarn && fdate(cfname) > fdate(sfname))
280 +                fprintf(stderr,
281 +                        "%s: warning - control file modified since last run\n",
282 +                                progname);
283   setours:                                        /* set our values */
284 <        gethostname(astat.host, sizeof(astat.host));
284 >        strcpy(astat.host, myhostname());
285          astat.pid = getpid();
286          strcpy(astat.cfname, cfname);
287          return(0);
288   fmterr:
289          fprintf(stderr, "%s: format error in status file \"%s\"\n",
290 <                        progname, buf);
290 >                        progname, sfname);
291          fclose(fp);
292          return(-1);
293   }
294  
295  
296 < putastat()                      /* put out current status */
296 > static void
297 > putastat(void)                  /* put out current status */
298   {
299          char    buf[256];
300          FILE    *fp;
301  
302 +        if (noaction)
303 +                return;
304          sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
305          if ((fp = fopen(buf, "w")) == NULL) {
306                  perror(buf);
# Line 237 | Line 316 | putastat()                     /* put out current status */
316   }
317  
318  
319 < checkdir()                      /* make sure we have our directory */
319 > static void
320 > checkdir(void)                  /* make sure we have our directory */
321   {
322          struct stat     stb;
323  
# Line 259 | Line 339 | checkdir()                     /* make sure we have our directory */
339   }
340  
341  
342 < setdefaults()                   /* set default values */
342 > static void
343 > setdefaults(void)                       /* set default values */
344   {
345 +        extern char     *atos();
346 +        int     decades;
347          char    buf[256];
348  
349 <        if (vdef(OCTREE) == vdef(ANIMATE)) {
349 >        if (vdef(ANIMATE)) {
350 >                vval(OCTREE) = NULL;
351 >                vdef(OCTREE) = 0;
352 >        } else if (!vdef(OCTREE)) {
353                  fprintf(stderr, "%s: either %s or %s must be defined\n",
354                                  progname, vnam(OCTREE), vnam(ANIMATE));
355                  quit(1);
# Line 272 | Line 358 | setdefaults()                  /* set default values */
358                  fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE));
359                  quit(1);
360          }
361 +        if (!vdef(HOST)) {
362 +                vval(HOST) = LHOSTNAME;
363 +                vdef(HOST)++;
364 +        }
365          if (!vdef(START)) {
366                  vval(START) = "1";
367                  vdef(START)++;
368          }
369          if (!vdef(END)) {
370 <                sprintf(buf, "%d", countviews());
370 >                sprintf(buf, "%d", countviews()+vint(START)-1);
371                  vval(END) = savqstr(buf);
372                  vdef(END)++;
373          }
374 +        if (vint(END) < vint(START)) {
375 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
376 +                                progname);
377 +                quit(1);
378 +        }
379          if (!vdef(BASENAME)) {
380 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
380 >                decades = (int)log10((double)vint(END)) + 1;
381 >                if (decades < 3) decades = 3;
382 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
383                  vval(BASENAME) = savqstr(buf);
384                  vdef(BASENAME)++;
385          }
# Line 314 | Line 411 | setdefaults()                  /* set default values */
411                  vval(DISKSPACE) = "100";
412                  vdef(DISKSPACE)++;
413          }
414 +        if (!vdef(RSH)) {
415 +                vval(RSH) = REMSH;
416 +                vdef(RSH)++;
417 +        }
418 +                                /* locate remote shell program */
419 +        atos(buf, sizeof(buf), vval(RSH));
420 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
421 +                remsh = savqstr(remsh);
422 +        else
423 +                remsh = vval(RSH);      /* will generate error if used */
424 +
425                                  /* append rendering options */
426          if (vdef(RENDER))
427                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
428   }
429  
430  
431 < getradfile(rfname)              /* run rad and get needed variables */
432 < char    *rfname;
431 > static void
432 > sethosts(void)                  /* set up process servers */
433   {
434 +        extern char     *iskip();
435 +        char    buf[256], *dir, *uname;
436 +        int     np;
437 +        register char   *cp;
438 +        int     i;
439 +
440 +        npslots = 0;
441 +        if (noaction)
442 +                return;
443 +        for (i = 0; i < vdef(HOST); i++) {      /* add each host */
444 +                dir = uname = NULL;
445 +                np = 1;
446 +                strcpy(cp=buf, nvalue(HOST, i));        /* copy to buffer */
447 +                cp = sskip(cp);                         /* skip host name */
448 +                while (isspace(*cp))
449 +                        *cp++ = '\0';
450 +                if (*cp) {                              /* has # processes? */
451 +                        np = atoi(cp);
452 +                        if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp)))
453 +                                badvalue(HOST);
454 +                        while (isspace(*cp))
455 +                                cp++;
456 +                        if (*cp) {                      /* has directory? */
457 +                                dir = cp;
458 +                                cp = sskip(cp);                 /* skip dir. */
459 +                                while (isspace(*cp))
460 +                                        *cp++ = '\0';
461 +                                if (*cp) {                      /* has user? */
462 +                                        uname = cp;
463 +                                        if (*sskip(cp))
464 +                                                badvalue(HOST);
465 +                                }
466 +                        }
467 +                }
468 +                if (addpserver(buf, dir, uname, np) == NULL) {
469 +                        if (!nowarn)
470 +                                fprintf(stderr,
471 +                                        "%s: cannot execute on host \"%s\"\n",
472 +                                                progname, buf);
473 +                } else
474 +                        npslots += np;
475 +        }
476 +        if (npslots == 0) {
477 +                fprintf(stderr, "%s: no working process servers\n", progname);
478 +                quit(1);
479 +        }
480 +        pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot));
481 +        if (pslot == NULL) {
482 +                perror("malloc");
483 +                quit(1);
484 +        }
485 + }
486 +
487 + static void
488 + getradfile(char *rfargs)                /* run rad and get needed variables */
489 + {
490          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
491          char    combuf[256];
492          register int    i;
493          register char   *cp;
494 +        char    *pippt;
495                                          /* create rad command */
496          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
497          sprintf(combuf,
498          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
499 <                        rfname, rendopt+2);
499 >                        rfargs, rendopt+2);
500          cp = combuf;
501 <        while (*cp) cp++;               /* match unset variables */
501 >        while (*cp) {
502 >                if (*cp == '|') pippt = cp;
503 >                cp++;
504 >        }                               /* match unset variables */
505          for (i = 0; mvar[i] >= 0; i++)
506                  if (!vdef(mvar[i])) {
507                          *cp++ = '|';
508                          strcpy(cp, vnam(mvar[i]));
509                          while (*cp) cp++;
510 +                        pippt = NULL;
511                  }
512 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
513 <        cp += 11;                       /* point to file name */
514 <        if (system(combuf)) {
515 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
516 <                                progname, rfname);
348 <                quit(1);
512 >        if (pippt != NULL)
513 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
514 >        else {
515 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
516 >                cp += 11;               /* point to file name */
517          }
518 <        loadvars(cp);                   /* load variables and remove file */
519 <        unlink(cp);
518 >        system(combuf);                 /* ignore exit code */
519 >        if (pippt == NULL) {            /* load variables and remove file */
520 >                loadvars(cp);
521 >                unlink(cp);
522 >        }
523   }
524  
525  
526 < animate()                       /* run animation */
526 > static void
527 > animate(void)                   /* run animation */
528   {
529          int     xres, yres;
530          float   pa, mult;
# Line 363 | Line 535 | animate()                      /* run animation */
535          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
536          mult = vflt(OVERSAMP);
537          if (i == 3) {
538 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
538 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
539                                  (int)(mult*yres), pa);
540 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
540 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
541          } else if (i) {
542                  if (i == 1) yres = xres;
543                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 382 | Line 554 | animate()                      /* run animation */
554                                                  progname, vnam(INTERP));
555                          vval(INTERP) = "0";
556                  }
557 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
557 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
558                          if (!nowarn)
559                                  fprintf(stderr,
560                                          "%s: resetting %s=0 for animation\n",
# Line 392 | Line 564 | animate()                      /* run animation */
564          }
565                                          /* figure # frames per batch */
566          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
567 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
568 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
567 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
568 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
569          d2 = xres*yres*4;                       /* space for final picture */
570          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
571          if (frames_batch < i+2) {
# Line 401 | Line 573 | animate()                      /* run animation */
573                                  progname);
574                  quit(1);
575          }
576 +                                        /* initialize archive argument list */
577 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
578 +        arcnext = arcfirst = arcargs + i;
579                                          /* initialize status file */
580          if (astat.rnext == 0)
581                  astat.rnext = astat.fnext = astat.tnext = vint(START);
582          putastat();
583                                          /* render in batches */
584 <        while (astat.rnext <= vint(END)) {
584 >        while (astat.tnext <= vint(END)) {
585                  renderframes(frames_batch);
586                  filterframes();
587                  transferframes();
# Line 420 | Line 595 | animate()                      /* run animation */
595   }
596  
597  
598 < renderframes(nframes)           /* render next nframes frames */
599 < int     nframes;
598 > static void
599 > renderframes(int nframes)               /* render next nframes frames */
600   {
601          static char     vendbuf[16];
602          VIEW    *vp;
# Line 466 | Line 641 | int    nframes;
641                  }
642          }
643          if (vdef(ANIMATE))              /* wait for renderings to finish */
644 <                animwait(0);
644 >                bwait(0);
645          else {                          /* else if walk-through */
646                  fclose(fp);             /* close view file */
647                  walkwait(astat.rnext, lastframe, vfname);       /* walk it */
648                  unlink(vfname);         /* remove view file */
649          }
475        if (vdef(ARCHIVE))              /* archive results */
476                archive(astat.rnext, lastframe);
650          astat.rnext = i;                /* update status */
651          putastat();
652   }
653  
654  
655 < filterframes()                          /* catch up with filtering */
655 > static void
656 > filterframes(void)                              /* catch up with filtering */
657   {
658          VIEW    *vp;
659          register int    i;
# Line 487 | Line 661 | filterframes()                         /* catch up with filtering */
661          if (astat.tnext < astat.fnext)  /* other work to do first */
662                  return;
663                                          /* filter each view */
664 <        for (i = astat.fnext; i < astat.rnext; i++) {
665 <                if ((vp = getview(i)) == NULL) {        /* get view i */
666 <                        fprintf(stderr,
667 <                        "%s: unexpected error reading view for frame %d\n",
668 <                                        progname, i);
495 <                        quit(1);
496 <                }
497 <                dofilt(i, vp, getexp(i));               /* filter frame */
498 <        }
499 <        filtwait(0);                    /* wait for filter processes */
664 >        for (i = astat.fnext; i < astat.rnext; i++)
665 >                dofilt(i, 0);
666 >
667 >        bwait(0);                       /* wait for filter processes */
668 >        archive();                      /* archive originals */
669          astat.fnext = i;                /* update status */
670          putastat();
671   }
672  
673  
674 < transferframes()                        /* catch up with picture transfers */
674 > static void
675 > transferframes(void)                    /* catch up with picture transfers */
676   {
677 <        char    combuf[10240];
677 >        char    combuf[10240], *fbase;
678          register char   *cp;
679          register int    i;
680  
# Line 515 | Line 685 | transferframes()                       /* catch up with picture transfers
685                  putastat();             /* update status */
686                  return;
687          }
688 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
689 <        cp = combuf + strlen(combuf);
688 >        strcpy(combuf, "cd ");          /* start transfer command */
689 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
690 >        if (*cp) {
691 >                while (*++cp) ;
692 >                *cp++ = ';'; *cp++ = ' ';
693 >        } else
694 >                cp = combuf;
695 >        strcpy(cp, vval(TRANSFER));
696 >        while (*cp) cp++;
697                                          /* make argument list */
698          for (i = astat.tnext; i < astat.fnext; i++) {
699                  *cp++ = ' ';
700 <                sprintf(cp, vval(BASENAME), i);
700 >                sprintf(cp, fbase, i);
701                  while (*cp) cp++;
702                  strcpy(cp, ".pic");
703                  cp += 4;
# Line 535 | Line 712 | transferframes()                       /* catch up with picture transfers
712   }
713  
714  
715 < animrend(frame, vp)                     /* start animation frame */
716 < int     frame;
717 < VIEW    *vp;
715 > static void
716 > animrend(                       /* start animation frame */
717 > int     frame,
718 > VIEW    *vp
719 > )
720   {
721 +        extern int      recover();
722          char    combuf[2048];
723          char    fname[128];
724  
# Line 546 | Line 726 | VIEW   *vp;
726          strcat(fname, ".unf");
727          if (access(fname, F_OK) == 0)
728                  return;
729 <        sprintf(combuf, "%s %d | rpict%s%s %s > %s", vval(ANIMATE), frame,
729 >        sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame,
730                          rendopt, viewopt(vp), rresopt, fname);
731 <        if (runcom(combuf)) {
552 <                fprintf(stderr, "%s: error rendering frame %d\n",
553 <                                progname, frame);
554 <                quit(1);
555 <        }
731 >        bruncom(combuf, frame, recover);        /* run in background */
732   }
733  
734  
735 < animwait(nwait)                         /* wait for renderings to finish */
736 < int     nwait;
735 > static void
736 > walkwait(               /* walk-through frames */
737 > int     first,
738 > int last,
739 > char    *vfn
740 > )
741   {
742 <        /* currently does nothing since parallel rendering not working */
743 < }
564 <
565 <
566 < walkwait(first, last, vfn)              /* walk-through frames */
567 < int     first, last;
568 < char    *vfn;
569 < {
742 >        double  blurf;
743 >        int     nblur = getblur(&blurf);
744          char    combuf[2048];
745 +        register char   *inspoint;
746          register int    i;
747  
748          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 578 | Line 753 | char   *vfn;
753                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
754                          }
755                                          /* create command */
756 <        sprintf(combuf, "rpict%s ", rendopt);
757 <        if (vint(INTERP) || atoi(vval(MBLUR)))
758 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
759 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
760 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
761 <        if (runcom(combuf)) {
762 <                fprintf(stderr,
763 <                "%s: error rendering walk-through frames %d through %d\n",
756 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
757 >                        viewopt(getview(first>1 ? first-1 : 1)));
758 >        inspoint = combuf;
759 >        while (*inspoint) inspoint++;
760 >        if (nblur) {
761 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
762 >                while (*inspoint) inspoint++;
763 >        }
764 >        if (nblur > 1 || vint(INTERP)) {
765 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
766 >                while (*inspoint) inspoint++;
767 >        }
768 >        sprintf(inspoint, " -o %s.unf %s -S %d",
769 >                        vval(BASENAME), rresopt, first);
770 >        while (*inspoint) inspoint++;
771 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
772 >                                        /* run in parallel */
773 >        i = (last-first+1)/(vint(INTERP)+1);
774 >        if (i < 1) i = 1;
775 >        if (pruncom(combuf, inspoint, i)) {
776 >                fprintf(stderr, "%s: error rendering frames %d through %d\n",
777                                  progname, first, last);
778                  quit(1);
779          }
# Line 599 | Line 787 | char   *vfn;
787   }
788  
789  
790 < recover(frame)                          /* recover the specified frame */
791 < int     frame;
790 > static int
791 > recover(int frame)                              /* recover the specified frame */
792   {
793 +        static int      *rfrm;          /* list of recovered frames */
794 +        static int      nrfrms = 0;
795 +        double  blurf;
796 +        int     nblur = getblur(&blurf);
797          char    combuf[2048];
798          char    fname[128];
799          register char   *cp;
800 <
800 >        register int    i;
801 >                                        /* check to see if recovered already */
802 >        for (i = nrfrms; i--; )
803 >                if (rfrm[i] == frame)
804 >                        return(0);
805 >                                        /* build command */
806          sprintf(fname, vval(BASENAME), frame);
807          if (vdef(ANIMATE))
808 <                sprintf(combuf, "%s %d | rpict%s",
808 >                sprintf(combuf, "%s %d | rpict%s -w0",
809                                  vval(ANIMATE), frame, rendopt);
810          else
811 <                sprintf(combuf, "rpict%s", rendopt);
812 <        cp = combuf + strlen(combuf);
813 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
811 >                sprintf(combuf, "rpict%s -w0", rendopt);
812 >        cp = combuf;
813 >        while (*cp) cp++;
814 >        if (nblur) {
815 >                sprintf(cp, " -pm %.3f", blurf/nblur);
816 >                while (*cp) cp++;
817 >        }
818 >        if (nblur > 1 || vint(INTERP)) {
819                  sprintf(cp, " -z %s.zbf", fname);
820                  while (*cp) cp++;
821          }
# Line 623 | Line 825 | int    frame;
825                  *cp++ = ' ';
826                  strcpy(cp, vval(OCTREE));
827          }
828 <        if (runcom(combuf)) {
829 <                fprintf(stderr, "%s: error recovering frame %d\n",
830 <                                progname, frame);
828 >        if (runcom(combuf))             /* run command */
829 >                return(1);
830 >                                        /* add frame to recovered list */
831 >        if (nrfrms)
832 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
833 >        else
834 >                rfrm = (int *)malloc(sizeof(int));
835 >        if (rfrm == NULL) {
836 >                perror("malloc");
837                  quit(1);
838          }
839 +        rfrm[nrfrms++] = frame;
840 +        return(0);
841   }
842  
843  
844 < archive(first, last)                    /* archive finished renderings */
845 < int     first, last;
844 > static int
845 > frecover(int frame)                             /* recover filtered frame */
846   {
847 <        char    combuf[10240];
848 <        int     offset;
849 <        struct stat     stb;
850 <        register char   *cp;
641 <        register int    i;
847 >        if (dofilt(frame, 2) && dofilt(frame, 1))
848 >                return(1);
849 >        return(0);
850 > }
851  
852 <        strcpy(cp=combuf, vval(ARCHIVE));
853 <        while (*cp) cp++;
854 <        offset = cp - combuf;
855 <        *cp++ = ' ';                            /* make argument list */
856 <        for (i = first; i <= last; i++) {
857 <                sprintf(cp, vval(BASENAME), i);
858 <                strcat(cp, ".unf");
859 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
860 <                        while (*cp) cp++;
861 <                        *cp++ = ' ';
862 <                        sprintf(cp, vval(BASENAME), i);
863 <                        strcat(cp, ".zbf");
864 <                        if (access(cp, F_OK) == 0) {            /* exists? */
865 <                                while (*cp) cp++;
866 <                                *cp++ = ' ';
867 <                        }
852 >
853 > static void
854 > archive(void)                   /* archive and remove renderings */
855 > {
856 > #define RMCOML  (sizeof(rmcom)-1)
857 >        static char     rmcom[] = "rm -f";
858 >        char    basedir[128];
859 >        int     dlen, alen;
860 >        register int    j;
861 >
862 >        if (arcnext == arcfirst)
863 >                return;                         /* nothing to do */
864 >        dirfile(basedir, vval(BASENAME));
865 >        dlen = strlen(basedir);
866 >        if (vdef(ARCHIVE)) {                    /* run archive command */
867 >                alen = strlen(vval(ARCHIVE));
868 >                if (dlen) {
869 >                        j = alen + dlen + 5;
870 >                        strncpy(arcfirst-j, "cd ", 3);
871 >                        strncpy(arcfirst-j+3, basedir, dlen);
872 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
873 >                } else
874 >                        j = alen;
875 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
876 >                if (runcom(arcfirst-j)) {
877 >                        fprintf(stderr, "%s: error running archive command\n",
878 >                                        progname);
879 >                        quit(1);
880                  }
881          }
882 <        *--cp = '\0';
883 <        if (cp <= combuf + offset)              /* no files? */
884 <                return;
885 <        if (runcom(combuf)) {                   /* run archive command */
886 <                fprintf(stderr,
887 <                "%s: error running archive command on frames %d through %d\n",
888 <                                progname, first, last);
889 <                quit(1);
890 <        }
882 >        if (dlen) {
883 >                j = RMCOML + dlen + 5;
884 >                strncpy(arcfirst-j, "cd ", 3);
885 >                strncpy(arcfirst-j+3, basedir, dlen);
886 >                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
887 >        } else
888 >                j = RMCOML;
889 >                                                /* run remove command */
890 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
891 >        runcom(arcfirst-j);
892 >        arcnext = arcfirst;                     /* reset argument list */
893 > #undef RMCOML
894   }
895  
896  
897 < dofilt(frame, vp, ep)                           /* filter frame */
898 < int     frame;
899 < VIEW    *vp;
900 < char    *ep;
897 > static int
898 > dofilt(                         /* filter frame */
899 > int     frame,
900 > int     rvr
901 > )
902   {
903 <        char    fnbefore[128], fnafter[128];
904 <        char    combuf[1024], fname[128];
905 <        int     usepinterp, usepfilt;
906 <        int     frbefore, frafter, triesleft;
903 >        extern int      frecover();
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 >        if (ep == NULL) {
921 >                 fprintf(stderr,
922 >                        "%s: unexpected error reading exposure for frame %d\n",
923 >                                          progname, frame);
924 >                quit(1);
925 >        }
926 >        usepinterp = (nblur > 1);
927 >        usepfilt = pfiltalways | (ep==NULL);
928 >        if (ep != NULL && !strcmp(ep, "1"))
929 >                ep = "+0";
930 >        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
931 >                        *ep != '+' || *ep != '-' || !isint(ep);
932                                                  /* compute rendered views */
933 <        frbefore = frame - ((frame-1) % (vint(INTERP)+1));
934 <        frafter = frbefore + vint(INTERP) + 1;
935 <        if (frafter > vint(END))
936 <                frafter = vint(END);
937 <        if (frafter == frame) {                 /* pfilt only */
938 <                frbefore = frafter;
933 >        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
934 >        frseq[1] = frseq[0] + vint(INTERP) + 1;
935 >        fbase = dirfile(NULL, vval(BASENAME));
936 >        if (frseq[1] > vint(END))
937 >                frseq[1] = vint(END);
938 >        if (frseq[1] == frame) {                        /* pfilt only */
939 >                frseq[0] = frseq[1];
940                  usepinterp = 0;                 /* update what's needed */
941 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
942 <                triesleft = 2;
943 <        } else if (frbefore == frame) {         /* no interpolation */
944 <                                                /* remove unneeded files */
945 <                if (frbefore-vint(INTERP)-1 >= 1) {
946 <                        sprintf(fname, vval(BASENAME), frbefore-vint(INTERP)-1);
947 <                        sprintf(combuf, "rm -f %s.unf %s.zbf", fname, fname);
948 <                        runcom(combuf);
941 >                usepfilt |= nora_rgbe;
942 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
943 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
944 >                        *arcnext++ = ' ';
945 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
946 >                        while (*arcnext) arcnext++;
947 >                        strcpy(arcnext, ".unf");
948 >                        arcnext += 4;
949 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
950 >                                *arcnext++ = ' ';
951 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
952 >                                while (*arcnext) arcnext++;
953 >                                strcpy(arcnext, ".zbf");
954 >                                arcnext += 4;
955 >                        }
956                  }
957 <                                                /* update what's needed */
958 <                if (usepinterp)
959 <                        triesleft = 3;
705 <                else {
706 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
707 <                        triesleft = 2;
708 <                }
709 <        } else {                                /* interpolation needed */
957 >                if (!usepinterp)                /* update what's needed */
958 >                        usepfilt |= nora_rgbe;
959 >        } else                                  /* interpolation needed */
960                  usepinterp++;
961 <                triesleft = 3;
962 <        }
963 <        if (frafter >= astat.rnext) {           /* next batch unavailable */
964 <                frafter = frbefore;
965 <                if (triesleft > 2)
966 <                        triesleft = 2;
967 <        }
718 <        sprintf(fnbefore, vval(BASENAME), frbefore);
719 <        sprintf(fnafter, vval(BASENAME), frafter);
720 < tryit:                                          /* generate command */
961 >        if (frseq[1] >= astat.rnext)            /* next batch unavailable */
962 >                frseq[1] = frseq[0];
963 >        sprintf(fnbefore, vval(BASENAME), frseq[0]);
964 >        sprintf(fnafter, vval(BASENAME), frseq[1]);
965 >        if (rvr == 1 && recover(frseq[0]))      /* recover before frame? */
966 >                return(1);
967 >                                                /* generate command */
968          if (usepinterp) {                       /* using pinterp */
969 <                if (atoi(vval(MBLUR))) {
970 <                        FILE    *fp;            /* motion blurring */
971 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
972 <                        if ((fp = fopen(fname, "w")) == NULL) {
973 <                                perror(fname); 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,
969 >                if (rvr == 2 && recover(frseq[1]))      /* recover after? */
970 >                        return(1);
971 >                if (nblur > 1) {                /* with pmblur */
972 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
973 >                                        'a'+(iter%26));
974 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
975 >                                        'a'+(iter%26));
976 >                        if (!noaction) {
977 >                                FILE    *fp;            /* motion blurring */
978 >                                if ((fp = fopen(fname0, "w")) == NULL) {
979 >                                        perror(fname0); 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,
986                          "%s: unexpected error reading view for frame %d\n",
987 <                                                progname, frame+1);
988 <                                quit(1);
987 >                                                        progname, frame+1);
988 >                                        quit(1);
989 >                                }
990 >                                if ((fp = fopen(fname1, "w")) == NULL) {
991 >                                        perror(fname1); quit(1);
992 >                                }
993 >                                fputs(VIEWSTR, fp);
994 >                                fprintview(vp, fp);
995 >                                putc('\n', fp); fclose(fp);
996                          }
737                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
738                        if ((fp = fopen(fname, "w")) == NULL) {
739                                perror(fname); quit(1);
740                        }
741                        fputs(VIEWSTR, fp);
742                        fprintview(vp, fp);
743                        putc('\n', fp); fclose(fp);
997                          sprintf(combuf,
998 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
999 <                                *sskip(vval(MBLUR)) ? sskip(vval(MBLUR)) : "1",
1000 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
1001 <                                        vval(DIRECTORY), vval(DIRECTORY),
749 <                                        vval(DIRECTORY), vval(DIRECTORY));
998 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
999 >                                        blurf, nblur,
1000 >                                        fname0, fname1, fname0, fname1);
1001 >                        iter++;
1002                  } else                          /* no blurring */
1003                          strcpy(combuf, "pinterp");
1004                  strcat(combuf, viewopt(vp));
1005                  if (vbool(RTRACE))
1006 <                        sprintf(combuf+strlen(combuf), " -ff -fr '%s %s'",
1007 <                                        rendopt, vval(OCTREE));
1006 >                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1007 >                                        rendopt+1, vval(OCTREE));
1008                  if (vdef(PINTERP))
1009                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1010                  if (usepfilt)
1011                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1012                  else
1013 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1013 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1014                                          fresopt, ep);
1015                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1016                                  fnbefore, fnbefore);
1017 <                if (frafter != frbefore)
1017 >                if (frseq[1] != frseq[0])
1018                           sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1019                                          fnafter, fnafter);
1020                  if (usepfilt) {                 /* also pfilt */
# Line 778 | Line 1030 | tryit:                                         /* generate command */
1030                                  sprintf(combuf+strlen(combuf), " %s", fresopt);
1031                  }
1032          } else if (usepfilt) {                  /* pfilt only */
1033 +                if (rvr == 2)
1034 +                        return(1);
1035                  if (vdef(PFILT))
1036                          sprintf(combuf, "pfilt %s", vval(PFILT));
1037                  else
# Line 789 | Line 1043 | tryit:                                         /* generate command */
1043                          sprintf(combuf+strlen(combuf), " %s %s.unf",
1044                                          fresopt, fnbefore);
1045          } else {                                /* else just check it */
1046 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
1046 >                if (rvr == 2)
1047 >                        return(1);
1048 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1049          }
1050                                                  /* output file name */
1051 <        sprintf(fname, vval(BASENAME), frame);
1052 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
1053 <        if (runcom(combuf))                     /* run filter command */
1054 <                switch (--triesleft) {
1055 <                case 2:                         /* try to recover frafter */
1056 <                        recover(frafter);
801 <                        goto tryit;
802 <                case 1:                         /* try to recover frbefore */
803 <                        recover(frbefore);
804 <                        goto tryit;
805 <                default:                        /* we've really failed */
806 <                        fprintf(stderr,
807 <                        "%s: unrecoverable filtering error on frame %d\n",
808 <                                        progname, frame);
809 <                        quit(1);
810 <                }
1051 >        sprintf(fname0, vval(BASENAME), frame);
1052 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1053 >        if (rvr)                                /* in recovery */
1054 >                return(runcom(combuf));
1055 >        bruncom(combuf, frame, frecover);       /* else run in background */
1056 >        return(0);
1057   }
1058  
1059  
1060 < filtwait(nwait)                 /* wait for filtering processes to finish */
1061 < int     nwait;
1060 > static VIEW *
1061 > getview(int n)                  /* get view number n */
1062   {
817        /* currently does nothing since parallel filtering not working */
818 }
819
820
821 VIEW *
822 getview(n)                      /* get view number n */
823 int     n;
824 {
1063          static FILE     *viewfp = NULL;         /* view file pointer */
1064          static int      viewnum = 0;            /* current view number */
1065          static VIEW     curview = STDVIEW;      /* current view */
# Line 832 | Line 1070 | int    n;
1070                          fclose(viewfp);
1071                          viewfp = NULL;
1072                          viewnum = 0;
1073 <                        copystruct(&curview, &stdview);
1073 >                        curview = stdview;
1074                  }
1075                  return(NULL);
1076          }
1077 <        if (viewfp == NULL) {           /* open file */
1077 >        if (viewfp == NULL) {                   /* open file */
1078                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1079                          perror(vval(VIEWFILE));
1080                          quit(1);
1081                  }
1082 <        } else if (n < viewnum) {       /* rewind file */
1082 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1083 >                if (viewnum == 1 && feof(viewfp))
1084 >                        return(&curview);               /* just one view */
1085                  if (fseek(viewfp, 0L, 0) == EOF) {
1086                          perror(vval(VIEWFILE));
1087                          quit(1);
1088                  }
1089 <                copystruct(&curview, &stdview);
1089 >                curview = stdview;
1090                  viewnum = 0;
1091          }
1092 +        if (n < 0) {                            /* get next view */
1093 +                register int    c = getc(viewfp);
1094 +                if (c == EOF)
1095 +                        return((VIEW *)NULL);           /* that's it */
1096 +                ungetc(c, viewfp);
1097 +                n = viewnum + 1;
1098 +        }
1099          while (n > viewnum) {           /* scan to desired view */
1100                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1101 <                        return(NULL);
1101 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1102                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1103                          viewnum++;
1104          }
# Line 859 | Line 1106 | int    n;
1106   }
1107  
1108  
1109 < int
1110 < countviews()                    /* count views in view file */
1109 > static int
1110 > countviews(void)                        /* count views in view file */
1111   {
1112 <        register int    n = 0;
1112 >        int     n;
1113  
1114 <        while (getview(n+1) != NULL)
1114 >        if (getview(n=1) == NULL)
1115 >                return(0);
1116 >        while (getview(-1) != NULL)
1117                  n++;
1118          return(n);
1119   }
1120  
1121  
1122 < char *
1123 < getexp(n)                       /* get exposure for nth frame */
875 < int     n;
1122 > static char *
1123 > getexp(int n)                   /* get exposure for nth frame */
1124   {
1125          extern char     *fskip();
1126          static char     expval[32];
# Line 884 | Line 1132 | int    n;
1132          if (n == 0) {                           /* signal to close file */
1133                  if (expfp != NULL) {
1134                          fclose(expfp);
1135 +                        free((void *)exppos);
1136                          expfp = NULL;
1137                  }
1138                  return(NULL);
1139 <        }
1139 >        } else if (n > vint(END))               /* request past end (error?) */
1140 >                return(NULL);
1141          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1142                  return(NULL);
1143          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 925 | Line 1175 | int    n;
1175                  }
1176                  curfrm++;
1177                  cp = fskip(expval);                     /* check format */
1178 <                if (cp == NULL || *cp != '\n') {
1178 >                if (cp != NULL)
1179 >                        while (isspace(*cp))
1180 >                                *cp++ = '\0';
1181 >                if (cp == NULL || *cp) {
1182                          fprintf(stderr,
1183                                  "%s: exposure format error on line %d\n",
1184                                          vval(EXPOSURE), curfrm);
1185                          quit(1);
1186                  }
934                *cp = '\0';
1187          }
1188          return(expval);                         /* return value */
1189   }
1190  
1191  
1192 < runcom(cs)                      /* run command */
1193 < char    *cs;
1192 > static struct pslot *
1193 > findpslot(int pid)                      /* find or allocate a process slot */
1194   {
1195 +        register struct pslot   *psempty = NULL;
1196 +        register int    i;
1197 +
1198 +        for (i = 0; i < npslots; i++) {         /* look for match */
1199 +                if (pslot[i].pid == pid)
1200 +                        return(pslot+i);
1201 +                if (psempty == NULL && pslot[i].pid == 0)
1202 +                        psempty = pslot+i;
1203 +        }
1204 +        return(psempty);                /* return emtpy slot (error if NULL) */
1205 + }
1206 +
1207 +
1208 + static int
1209 + donecom(                /* clean up after finished process */
1210 + PSERVER *ps,
1211 + int     pn,
1212 + int     status
1213 + )
1214 + {
1215 +        register NETPROC        *pp;
1216 +        register struct pslot   *psl;
1217 +
1218 +        pp = ps->proc + pn;
1219 +        if (pp->elen) {                 /* pass errors */
1220 +                if (ps->hostname[0])
1221 +                        fprintf(stderr, "%s: ", ps->hostname);
1222 +                fprintf(stderr, "Error output from: %s\n", pp->com);
1223 +                fputs(pp->errs, stderr);
1224 +                fflush(stderr);
1225 +                if (ps->hostname[0])
1226 +                        status = 1;     /* because rsh doesn't return status */
1227 +        }
1228 +        lastpserver = NULL;
1229 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1230 +        if (psl->pid) {
1231 +                if (status) {
1232 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1233 +                                status = (*psl->rcvf)(psl->fout);
1234 +                        if (status) {
1235 +                                fprintf(stderr,
1236 +                                        "%s: error rendering frame %d\n",
1237 +                                                progname, psl->fout);
1238 +                                quit(1);
1239 +                        }
1240 +                        lastpserver = ps;
1241 +                }
1242 +                psl->pid = 0;                   /* free process slot */
1243 +        } else if (status)
1244 +                lastpserver = ps;
1245 +        freestr(pp->com);               /* free command string */
1246 +        return(status);
1247 + }
1248 +
1249 +
1250 + static int
1251 + serverdown(void)                        /* check status of last process server */
1252 + {
1253 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1254 +                return(0);
1255 +        if (pserverOK(lastpserver))     /* server still up? */
1256 +                return(0);
1257 +        delpserver(lastpserver);        /* else delete it */
1258 +        if (pslist == NULL) {
1259 +                fprintf(stderr, "%s: all process servers are down\n",
1260 +                                progname);
1261 +                quit(1);
1262 +        }
1263 +        return(1);
1264 + }
1265 +
1266 +
1267 + static int
1268 + bruncom(                /* run a command in the background */
1269 + char    *com,
1270 + int     fout,
1271 + int     (*rf)()
1272 + )
1273 + {
1274 +        int     pid;
1275 +        register struct pslot   *psl;
1276 +
1277 +        if (noaction) {
1278 +                if (!silent)
1279 +                        printf("\t%s\n", com);  /* echo command */
1280 +                return(0);
1281 +        }
1282 +        com = savestr(com);             /* else start it when we can */
1283 +        while ((pid = startjob(NULL, com, donecom)) == -1)
1284 +                bwait(1);
1285 +        if (!silent) {                          /* echo command */
1286 +                PSERVER *ps;
1287 +                int     psn = pid;
1288 +                ps = findjob(&psn);
1289 +                printf("\t%s\n", com);
1290 +                printf("\tProcess started on %s\n", phostname(ps));
1291 +                fflush(stdout);
1292 +        }
1293 +        psl = findpslot(pid);           /* record info. in appropriate slot */
1294 +        psl->pid = pid;
1295 +        psl->fout = fout;
1296 +        psl->rcvf = rf;
1297 +        return(pid);
1298 + }
1299 +
1300 +
1301 + static void
1302 + bwait(int ncoms)                                /* wait for batch job(s) to finish */
1303 + {
1304 +        int     status;
1305 +
1306 +        if (noaction)
1307 +                return;
1308 +        while ((status = wait4job(NULL, -1)) != -1) {
1309 +                serverdown();           /* update server status */
1310 +                if (--ncoms == 0)
1311 +                        break;          /* done enough */
1312 +        }
1313 + }
1314 +
1315 +
1316 + static int
1317 + pruncom(        /* run a command in parallel over network */
1318 + char    *com,
1319 + char    *ppins,
1320 + int     maxcopies
1321 + )
1322 + {
1323 +        int     retstatus = 0;
1324 +        int     hostcopies;
1325 +        char    buf[10240], *com1, *s;
1326 +        int     status;
1327 +        int     pfd;
1328 +        register int    n;
1329 +        register PSERVER        *ps;
1330 +
1331 +        if (!silent)
1332 +                printf("\t%s\n", com);  /* echo command */
1333 +        if (noaction)
1334 +                return(0);
1335 +        fflush(stdout);
1336 +                                        /* start jobs on each server */
1337 +        for (ps = pslist; ps != NULL; ps = ps->next) {
1338 +                hostcopies = 0;
1339 +                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1340 +                        strcpy(com1=buf, com);  /* build -PP command */
1341 +                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1342 +                                        vval(DIRECTORY), phostname(ps));
1343 +                        unlink(com1+(ppins-com)+5);
1344 +                        strcat(com1, ppins);
1345 +                } else
1346 +                        com1 = com;
1347 +                while (maxcopies > 0) {
1348 +                        s = savestr(com1);
1349 +                        if (startjob(ps, s, donecom) != -1) {
1350 +                                sleep(20);
1351 +                                hostcopies++;
1352 +                                maxcopies--;
1353 +                        } else {
1354 +                                freestr(s);
1355 +                                break;
1356 +                        }
1357 +                }
1358 +                if (!silent && hostcopies) {
1359 +                        if (hostcopies > 1)
1360 +                                printf("\t%d duplicate processes", hostcopies);
1361 +                        else
1362 +                                printf("\tProcess");
1363 +                        printf(" started on %s\n", phostname(ps));
1364 +                        fflush(stdout);
1365 +                }
1366 +        }
1367 +                                        /* wait for jobs to finish */
1368 +        while ((status = wait4job(NULL, -1)) != -1)
1369 +                retstatus += status && !serverdown();
1370 +                                        /* terminate parallel rpict's */
1371 +        for (ps = pslist; ps != NULL; ps = ps->next) {
1372 +                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1373 +                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1374 +                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1375 +                        buf[n] = '\0';
1376 +                        close(pfd);
1377 +                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1378 +                                ;
1379 +                                                                /* terminate */
1380 +                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1381 +                        wait4job(ps, startjob(ps, buf, NULL));
1382 +                }
1383 +        }
1384 +        return(retstatus);
1385 + }
1386 +
1387 +
1388 + static int
1389 + runcom(char *cs)                        /* run a command locally and wait for it */
1390 + {
1391          if (!silent)            /* echo it */
1392                  printf("\t%s\n", cs);
1393          if (noaction)
# Line 949 | Line 1397 | char   *cs;
1397   }
1398  
1399  
1400 < rmfile(fn)                      /* remove a file */
1401 < char    *fn;
1400 > static int
1401 > rmfile(char *fn)                        /* remove a file */
1402   {
1403          if (!silent)
1404 < #ifdef MSDOS
1404 > #ifdef _WIN32
1405                  printf("\tdel %s\n", fn);
1406   #else
1407                  printf("\trm -f %s\n", fn);
# Line 964 | Line 1412 | char   *fn;
1412   }
1413  
1414  
1415 < badvalue(vc)                    /* report bad variable value and exit */
1416 < int     vc;
1415 > static void
1416 > badvalue(int vc)                        /* report bad variable value and exit */
1417   {
1418          fprintf(stderr, "%s: bad value for variable '%s'\n",
1419                          progname, vnam(vc));
1420          quit(1);
1421 + }
1422 +
1423 +
1424 + static char *
1425 + dirfile(                /* separate path into directory and file */
1426 + char    *df,
1427 + register char   *path
1428 + )
1429 + {
1430 +        register int    i;
1431 +        int     psep;
1432 +
1433 +        for (i = 0, psep = -1; path[i]; i++)
1434 +                if (path[i] == '/')
1435 +                        psep = i;
1436 +        if (df != NULL) {
1437 +                if (psep == 0) {
1438 +                        df[0] = '/';
1439 +                        df[1] = '\0';
1440 +                } else if (psep > 0) {
1441 +                        strncpy(df, path, psep);
1442 +                        df[psep] = '\0';
1443 +                } else
1444 +                        df[0] = '\0';
1445 +        }
1446 +        return(path+psep+1);
1447 + }
1448 +
1449 +
1450 + static int
1451 + getblur(double *bf)             /* get # blur samples (and fraction) */
1452 + {
1453 +        double  blurf;
1454 +        int     nblur;
1455 +        char    *s;
1456 +
1457 +        if (!vdef(MBLUR)) {
1458 +                if (bf != NULL)
1459 +                        *bf = 0.0;
1460 +                return(0);
1461 +        }
1462 +        blurf = atof(vval(MBLUR));
1463 +        if (blurf < 0.0)
1464 +                blurf = 0.0;
1465 +        if (bf != NULL)
1466 +                *bf = blurf;
1467 +        if (blurf <= FTINY)
1468 +                return(0);
1469 +        s = sskip(vval(MBLUR));
1470 +        if (!*s)
1471 +                return(DEF_NBLUR);
1472 +        nblur = atoi(s);
1473 +        if (nblur <= 0)
1474 +                return(1);
1475 +        return(nblur);
1476   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines