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.29 by greg, Sat Feb 22 02:07:30 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 + /* ====================================================================
17 + * The Radiance Software License, Version 1.0
18 + *
19 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
20 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
21 + *
22 + * Redistribution and use in source and binary forms, with or without
23 + * modification, are permitted provided that the following conditions
24 + * are met:
25 + *
26 + * 1. Redistributions of source code must retain the above copyright
27 + *         notice, this list of conditions and the following disclaimer.
28 + *
29 + * 2. Redistributions in binary form must reproduce the above copyright
30 + *       notice, this list of conditions and the following disclaimer in
31 + *       the documentation and/or other materials provided with the
32 + *       distribution.
33 + *
34 + * 3. The end-user documentation included with the redistribution,
35 + *           if any, must include the following acknowledgment:
36 + *             "This product includes Radiance software
37 + *                 (http://radsite.lbl.gov/)
38 + *                 developed by the Lawrence Berkeley National Laboratory
39 + *               (http://www.lbl.gov/)."
40 + *       Alternately, this acknowledgment may appear in the software itself,
41 + *       if and wherever such third-party acknowledgments normally appear.
42 + *
43 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
44 + *       and "The Regents of the University of California" must
45 + *       not be used to endorse or promote products derived from this
46 + *       software without prior written permission. For written
47 + *       permission, please contact [email protected].
48 + *
49 + * 5. Products derived from this software may not be called "Radiance",
50 + *       nor may "Radiance" appear in their name, without prior written
51 + *       permission of Lawrence Berkeley National Laboratory.
52 + *
53 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
54 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
56 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
57 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
60 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
63 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 + * SUCH DAMAGE.
65 + * ====================================================================
66 + *
67 + * This software consists of voluntary contributions made by many
68 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
69 + * information on Lawrence Berkeley National Laboratory, please see
70 + * <http://www.lbl.gov/>.
71 + */
72 +
73   #include "standard.h"
74 < #include <sys/types.h>
74 > #include <ctype.h>
75   #include <sys/stat.h>
76   #include "view.h"
77   #include "vars.h"
78 <                                /* input variables */
79 < #define HOST            0               /* rendering host machine */
80 < #define RENDER          1               /* rendering options */
81 < #define PFILT           2               /* pfilt options */
82 < #define PINTERP         3               /* pinterp options */
83 < #define OCTREE          4               /* octree file name */
84 < #define DIRECTORY       5               /* working (sub)directory */
85 < #define BASENAME        6               /* output image base name */
86 < #define VIEWFILE        7               /* animation frame views */
87 < #define START           8               /* starting frame number */
88 < #define END             9               /* ending frame number */
89 < #define RIF             10              /* rad input file */
90 < #define NEXTANIM        11              /* next animation file */
91 < #define ANIMATE         12              /* animation command */
92 < #define TRANSFER        13              /* frame transfer command */
93 < #define ARCHIVE         14              /* archiving command */
94 < #define INTERP          15              /* # frames to interpolate */
95 < #define OVERSAMP        16              /* # times to oversample image */
96 < #define MBLUR           17              /* samples for motion blur */
97 < #define RTRACE          18              /* use rtrace with pinterp? */
98 < #define DISKSPACE       19              /* how much disk space to use */
99 < #define RESOLUTION      20              /* desired final resolution */
100 < #define EXPOSURE        21              /* how to compute exposure */
78 > #include "netproc.h"
79 >                                /* default blur samples */
80 > #ifndef DEF_NBLUR
81 > #define DEF_NBLUR       5
82 > #endif
83 >                                /* default remote shell */
84 > #ifdef _AUX_SOURCE
85 > #define REMSH           "remsh"
86 > #else
87 > #define REMSH           "rsh"
88 > #endif
89 >                                /* input variables (alphabetical by name) */
90 > #define ANIMATE         0               /* animation command */
91 > #define ARCHIVE         1               /* archiving command */
92 > #define BASENAME        2               /* output image base name */
93 > #define DIRECTORY       3               /* working (sub)directory */
94 > #define DISKSPACE       4               /* how much disk space to use */
95 > #define END             5               /* ending frame number */
96 > #define EXPOSURE        6               /* how to compute exposure */
97 > #define HOST            7               /* rendering host machine */
98 > #define INTERP          8               /* # frames to interpolate */
99 > #define MBLUR           9               /* motion blur parameters */
100 > #define NEXTANIM        10              /* next animation file */
101 > #define OCTREE          11              /* octree file name */
102 > #define OVERSAMP        12              /* # times to oversample image */
103 > #define PFILT           13              /* pfilt options */
104 > #define PINTERP         14              /* pinterp options */
105 > #define RENDER          15              /* rendering options */
106 > #define RESOLUTION      16              /* desired final resolution */
107 > #define RIF             17              /* rad input file */
108 > #define RSH             18              /* remote shell script or program */
109 > #define RTRACE          19              /* use rtrace with pinterp? */
110 > #define START           20              /* starting frame number */
111 > #define TRANSFER        21              /* frame transfer command */
112 > #define VIEWFILE        22              /* animation frame views */
113  
114 < int     NVARS = 22;             /* total number of variables */
114 > int     NVARS = 23;             /* total number of variables */
115  
116   VARIABLE        vv[] = {                /* variable-value pairs */
117 +        {"ANIMATE",     2,      0,      NULL,   onevalue},
118 +        {"ARCHIVE",     2,      0,      NULL,   onevalue},
119 +        {"BASENAME",    3,      0,      NULL,   onevalue},
120 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
121 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
122 +        {"END",         2,      0,      NULL,   intvalue},
123 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
124          {"host",        4,      0,      NULL,   NULL},
125 <        {"render",      3,      0,      NULL,   catvalues},
125 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
126 >        {"MBLUR",       2,      0,      NULL,   onevalue},
127 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
128 >        {"OCTREE",      3,      0,      NULL,   onevalue},
129 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
130          {"pfilt",       2,      0,      NULL,   catvalues},
131          {"pinterp",     2,      0,      NULL,   catvalues},
132 <        {"OCTREE",      3,      0,      NULL,   onevalue},
133 <        {"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},
132 >        {"render",      3,      0,      NULL,   catvalues},
133 >        {"RESOLUTION",  3,      0,      NULL,   onevalue},
134          {"RIF",         3,      0,      NULL,   onevalue},
135 <        {"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},
135 >        {"RSH",         3,      0,      NULL,   onevalue},
136          {"RTRACE",      2,      0,      NULL,   boolvalue},
137 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
138 <        {"RESOLUTION",  3,      0,      NULL,   onevalue},
139 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
137 >        {"START",       2,      0,      NULL,   intvalue},
138 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
139 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
140   };
141  
142   #define SFNAME  "STATUS"                /* status file name */
# Line 82 | Line 157 | int    nowarn = 0;             /* turn warnings off? */
157   int     silent = 0;             /* silent mode? */
158   int     noaction = 0;           /* take no action? */
159  
160 < char    rendopt[2048] = "";     /* rendering options */
160 > char    *remsh;                 /* remote shell program/script */
161 > char    rendopt[2048];          /* rendering options */
162   char    rresopt[32];            /* rendering resolution options */
163   char    fresopt[32];            /* filter resolution options */
164   int     pfiltalways;            /* always use pfilt? */
165  
166 + char    arcargs[10240];         /* files to archive */
167 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
168 +
169 + struct pslot {
170 +        int     pid;                    /* process ID (0 if empty) */
171 +        int     fout;                   /* output frame number */
172 +        int     (*rcvf)();              /* recover function */
173 + }       *pslot;                 /* process slots */
174 + int     npslots;                /* number of process slots */
175 +
176 + #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
177 +
178 + struct pslot    *findpslot();
179 +
180 + PSERVER *lastpserver;           /* last process server with error */
181 +
182   VIEW    *getview();
183 < char    *getexp();
183 > char    *getexp(), *dirfile();
184 > int     getblur();
185  
186 + extern time_t   time();
187  
188 +
189   main(argc, argv)
190   int     argc;
191   char    *argv[];
# Line 121 | Line 216 | char   *argv[];
216          cfname = argv[i];
217                                                  /* load variables */
218          loadvars(cfname);
219 +                                                /* check variables */
220 +        checkvalues();
221                                                  /* did we get DIRECTORY? */
222          checkdir();
223                                                  /* check status */
# Line 138 | Line 235 | char   *argv[];
235                                                  /* print variables */
236          if (explicate)
237                  printvars(stdout);
238 +                                                /* set up process servers */
239 +        sethosts();
240                                                  /* run animation */
241          animate();
242                                                  /* all done */
# Line 145 | Line 244 | char   *argv[];
244                  argv[i] = vval(NEXTANIM);       /* just change input file */
245                  if (!silent)
246                          printargs(argc, argv, stdout);
247 <                if (!noaction) {
248 <                        execvp(progname, argv);         /* pass to next */
249 <                        quit(1);                        /* shouldn't return */
250 <                }
247 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
248 >                        fprintf(stderr, "%s: command not found\n", progname);
249 >                else
250 >                        execv(progname, argv);
251 >                quit(1);
252          }
253          quit(0);
254   userr:
# Line 159 | Line 259 | userr:
259  
260   getastat()                      /* check/set animation status */
261   {
262 <        char    buf[256];
262 >        char    sfname[256];
263          FILE    *fp;
264  
265 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
266 <        if ((fp = fopen(buf, "r")) == NULL) {
265 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
266 >        if ((fp = fopen(sfname, "r")) == NULL) {
267                  if (errno != ENOENT) {
268 <                        perror(buf);
268 >                        perror(sfname);
269                          return(-1);
270                  }
271                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 185 | Line 285 | getastat()                     /* check/set animation status */
285                  goto fmterr;
286          fclose(fp);
287          if (astat.pid != 0) {                   /* thinks it's still running */
288 <                gethostname(buf, sizeof(buf));
189 <                if (strcmp(buf, astat.host)) {
288 >                if (strcmp(myhostname(), astat.host)) {
289                          fprintf(stderr,
290                          "%s: process %d may still be running on host %s\n",
291                                          progname, astat.pid, astat.host);
# Line 199 | Line 298 | getastat()                     /* check/set animation status */
298                  }
299                  /* assume it is dead */
300          }
301 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
301 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
302                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
303                                  progname, astat.cfname);
304                  return(-1);
305          }
306 +                                                /* check control file mods. */
307 +        if (!nowarn && fdate(cfname) > fdate(sfname))
308 +                fprintf(stderr,
309 +                        "%s: warning - control file modified since last run\n",
310 +                                progname);
311   setours:                                        /* set our values */
312 <        gethostname(astat.host, sizeof(astat.host));
312 >        strcpy(astat.host, myhostname());
313          astat.pid = getpid();
314          strcpy(astat.cfname, cfname);
315          return(0);
316   fmterr:
317          fprintf(stderr, "%s: format error in status file \"%s\"\n",
318 <                        progname, buf);
318 >                        progname, sfname);
319          fclose(fp);
320          return(-1);
321   }
# Line 222 | Line 326 | putastat()                     /* put out current status */
326          char    buf[256];
327          FILE    *fp;
328  
329 +        if (noaction)
330 +                return;
331          sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
332          if ((fp = fopen(buf, "w")) == NULL) {
333                  perror(buf);
# Line 261 | Line 367 | checkdir()                     /* make sure we have our directory */
367  
368   setdefaults()                   /* set default values */
369   {
370 +        extern char     *atos();
371 +        int     decades;
372          char    buf[256];
373  
374 <        if (vdef(OCTREE) == vdef(ANIMATE)) {
374 >        if (vdef(ANIMATE)) {
375 >                vval(OCTREE) = NULL;
376 >                vdef(OCTREE) = 0;
377 >        } else if (!vdef(OCTREE)) {
378                  fprintf(stderr, "%s: either %s or %s must be defined\n",
379                                  progname, vnam(OCTREE), vnam(ANIMATE));
380                  quit(1);
# Line 272 | Line 383 | setdefaults()                  /* set default values */
383                  fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE));
384                  quit(1);
385          }
386 +        if (!vdef(HOST)) {
387 +                vval(HOST) = LHOSTNAME;
388 +                vdef(HOST)++;
389 +        }
390          if (!vdef(START)) {
391                  vval(START) = "1";
392                  vdef(START)++;
393          }
394          if (!vdef(END)) {
395 <                sprintf(buf, "%d", countviews());
395 >                sprintf(buf, "%d", countviews()+vint(START)-1);
396                  vval(END) = savqstr(buf);
397                  vdef(END)++;
398          }
399 +        if (vint(END) < vint(START)) {
400 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
401 +                                progname);
402 +                quit(1);
403 +        }
404          if (!vdef(BASENAME)) {
405 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
405 >                decades = (int)log10((double)vint(END)) + 1;
406 >                if (decades < 3) decades = 3;
407 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
408                  vval(BASENAME) = savqstr(buf);
409                  vdef(BASENAME)++;
410          }
# Line 314 | Line 436 | setdefaults()                  /* set default values */
436                  vval(DISKSPACE) = "100";
437                  vdef(DISKSPACE)++;
438          }
439 +        if (!vdef(RSH)) {
440 +                vval(RSH) = REMSH;
441 +                vdef(RSH)++;
442 +        }
443 +                                /* locate remote shell program */
444 +        atos(buf, sizeof(buf), vval(RSH));
445 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
446 +                remsh = savqstr(remsh);
447 +        else
448 +                remsh = vval(RSH);      /* will generate error if used */
449 +
450                                  /* append rendering options */
451          if (vdef(RENDER))
452                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
453   }
454  
455  
456 < getradfile(rfname)              /* run rad and get needed variables */
324 < char    *rfname;
456 > sethosts()                      /* set up process servers */
457   {
458 +        extern char     *iskip();
459 +        char    buf[256], *dir, *uname;
460 +        int     np;
461 +        register char   *cp;
462 +        int     i;
463 +
464 +        npslots = 0;
465 +        if (noaction)
466 +                return;
467 +        for (i = 0; i < vdef(HOST); i++) {      /* add each host */
468 +                dir = uname = NULL;
469 +                np = 1;
470 +                strcpy(cp=buf, nvalue(HOST, i));        /* copy to buffer */
471 +                cp = sskip(cp);                         /* skip host name */
472 +                while (isspace(*cp))
473 +                        *cp++ = '\0';
474 +                if (*cp) {                              /* has # processes? */
475 +                        np = atoi(cp);
476 +                        if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp)))
477 +                                badvalue(HOST);
478 +                        while (isspace(*cp))
479 +                                cp++;
480 +                        if (*cp) {                      /* has directory? */
481 +                                dir = cp;
482 +                                cp = sskip(cp);                 /* skip dir. */
483 +                                while (isspace(*cp))
484 +                                        *cp++ = '\0';
485 +                                if (*cp) {                      /* has user? */
486 +                                        uname = cp;
487 +                                        if (*sskip(cp))
488 +                                                badvalue(HOST);
489 +                                }
490 +                        }
491 +                }
492 +                if (addpserver(buf, dir, uname, np) == NULL) {
493 +                        if (!nowarn)
494 +                                fprintf(stderr,
495 +                                        "%s: cannot execute on host \"%s\"\n",
496 +                                                progname, buf);
497 +                } else
498 +                        npslots += np;
499 +        }
500 +        if (npslots == 0) {
501 +                fprintf(stderr, "%s: no working process servers\n", progname);
502 +                quit(1);
503 +        }
504 +        pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot));
505 +        if (pslot == NULL) {
506 +                perror("malloc");
507 +                quit(1);
508 +        }
509 + }
510 +
511 +
512 + getradfile(rfargs)              /* run rad and get needed variables */
513 + char    *rfargs;
514 + {
515          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
516          char    combuf[256];
517          register int    i;
518          register char   *cp;
519 +        char    *pippt;
520                                          /* create rad command */
521          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
522          sprintf(combuf,
523          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
524 <                        rfname, rendopt+2);
524 >                        rfargs, rendopt+2);
525          cp = combuf;
526 <        while (*cp) cp++;               /* match unset variables */
526 >        while (*cp) {
527 >                if (*cp == '|') pippt = cp;
528 >                cp++;
529 >        }                               /* match unset variables */
530          for (i = 0; mvar[i] >= 0; i++)
531                  if (!vdef(mvar[i])) {
532                          *cp++ = '|';
533                          strcpy(cp, vnam(mvar[i]));
534                          while (*cp) cp++;
535 +                        pippt = NULL;
536                  }
537 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
538 <        cp += 11;                       /* point to file name */
539 <        if (system(combuf)) {
540 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
541 <                                progname, rfname);
348 <                quit(1);
537 >        if (pippt != NULL)
538 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
539 >        else {
540 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
541 >                cp += 11;               /* point to file name */
542          }
543 <        loadvars(cp);                   /* load variables and remove file */
544 <        unlink(cp);
543 >        system(combuf);                 /* ignore exit code */
544 >        if (pippt == NULL) {            /* load variables and remove file */
545 >                loadvars(cp);
546 >                unlink(cp);
547 >        }
548   }
549  
550  
# Line 363 | Line 559 | animate()                      /* run animation */
559          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
560          mult = vflt(OVERSAMP);
561          if (i == 3) {
562 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
562 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
563                                  (int)(mult*yres), pa);
564 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
564 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
565          } else if (i) {
566                  if (i == 1) yres = xres;
567                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 382 | Line 578 | animate()                      /* run animation */
578                                                  progname, vnam(INTERP));
579                          vval(INTERP) = "0";
580                  }
581 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
581 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
582                          if (!nowarn)
583                                  fprintf(stderr,
584                                          "%s: resetting %s=0 for animation\n",
# Line 392 | Line 588 | animate()                      /* run animation */
588          }
589                                          /* figure # frames per batch */
590          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
591 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
592 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
591 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
592 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
593          d2 = xres*yres*4;                       /* space for final picture */
594          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
595          if (frames_batch < i+2) {
# Line 401 | Line 597 | animate()                      /* run animation */
597                                  progname);
598                  quit(1);
599          }
600 +                                        /* initialize archive argument list */
601 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
602 +        arcnext = arcfirst = arcargs + i;
603                                          /* initialize status file */
604          if (astat.rnext == 0)
605                  astat.rnext = astat.fnext = astat.tnext = vint(START);
606          putastat();
607                                          /* render in batches */
608 <        while (astat.rnext <= vint(END)) {
608 >        while (astat.tnext <= vint(END)) {
609                  renderframes(frames_batch);
610                  filterframes();
611                  transferframes();
# Line 466 | Line 665 | int    nframes;
665                  }
666          }
667          if (vdef(ANIMATE))              /* wait for renderings to finish */
668 <                animwait(0);
668 >                bwait(0);
669          else {                          /* else if walk-through */
670                  fclose(fp);             /* close view file */
671                  walkwait(astat.rnext, lastframe, vfname);       /* walk it */
672                  unlink(vfname);         /* remove view file */
673          }
475        if (vdef(ARCHIVE))              /* archive results */
476                archive(astat.rnext, lastframe);
674          astat.rnext = i;                /* update status */
675          putastat();
676   }
# Line 494 | Line 691 | filterframes()                         /* catch up with filtering */
691                                          progname, i);
692                          quit(1);
693                  }
694 <                dofilt(i, vp, getexp(i));               /* filter frame */
694 >                dofilt(i, vp, getexp(i), 0);            /* filter frame */
695          }
696 <        filtwait(0);                    /* wait for filter processes */
696 >        bwait(0);                       /* wait for filter processes */
697 >        archive();                      /* archive originals */
698          astat.fnext = i;                /* update status */
699          putastat();
700   }
# Line 504 | Line 702 | filterframes()                         /* catch up with filtering */
702  
703   transferframes()                        /* catch up with picture transfers */
704   {
705 <        char    combuf[10240];
705 >        char    combuf[10240], *fbase;
706          register char   *cp;
707          register int    i;
708  
# Line 515 | Line 713 | transferframes()                       /* catch up with picture transfers
713                  putastat();             /* update status */
714                  return;
715          }
716 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
717 <        cp = combuf + strlen(combuf);
716 >        strcpy(combuf, "cd ");          /* start transfer command */
717 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
718 >        if (*cp) {
719 >                while (*++cp) ;
720 >                *cp++ = ';'; *cp++ = ' ';
721 >        } else
722 >                cp = combuf;
723 >        strcpy(cp, vval(TRANSFER));
724 >        while (*cp) cp++;
725                                          /* make argument list */
726          for (i = astat.tnext; i < astat.fnext; i++) {
727                  *cp++ = ' ';
728 <                sprintf(cp, vval(BASENAME), i);
728 >                sprintf(cp, fbase, i);
729                  while (*cp) cp++;
730                  strcpy(cp, ".pic");
731                  cp += 4;
# Line 539 | Line 744 | animrend(frame, vp)                    /* start animation frame */
744   int     frame;
745   VIEW    *vp;
746   {
747 +        extern int      recover();
748          char    combuf[2048];
749          char    fname[128];
750  
# Line 546 | Line 752 | VIEW   *vp;
752          strcat(fname, ".unf");
753          if (access(fname, F_OK) == 0)
754                  return;
755 <        sprintf(combuf, "%s %d | rpict%s%s %s > %s", vval(ANIMATE), frame,
755 >        sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame,
756                          rendopt, viewopt(vp), rresopt, fname);
757 <        if (runcom(combuf)) {
552 <                fprintf(stderr, "%s: error rendering frame %d\n",
553 <                                progname, frame);
554 <                quit(1);
555 <        }
757 >        bruncom(combuf, frame, recover);        /* run in background */
758   }
759  
760  
559 animwait(nwait)                         /* wait for renderings to finish */
560 int     nwait;
561 {
562        /* currently does nothing since parallel rendering not working */
563 }
564
565
761   walkwait(first, last, vfn)              /* walk-through frames */
762   int     first, last;
763   char    *vfn;
764   {
765 +        double  blurf;
766 +        int     nblur = getblur(&blurf);
767          char    combuf[2048];
768 +        register char   *inspoint;
769          register int    i;
770  
771          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 578 | Line 776 | char   *vfn;
776                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
777                          }
778                                          /* create command */
779 <        sprintf(combuf, "rpict%s ", rendopt);
780 <        if (vint(INTERP) || atoi(vval(MBLUR)))
781 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
782 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
783 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
784 <        if (runcom(combuf)) {
785 <                fprintf(stderr,
786 <                "%s: error rendering walk-through frames %d through %d\n",
779 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
780 >                        viewopt(getview(first>1 ? first-1 : 1)));
781 >        inspoint = combuf;
782 >        while (*inspoint) inspoint++;
783 >        if (nblur) {
784 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
785 >                while (*inspoint) inspoint++;
786 >        }
787 >        if (nblur > 1 || vint(INTERP)) {
788 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
789 >                while (*inspoint) inspoint++;
790 >        }
791 >        sprintf(inspoint, " -o %s.unf %s -S %d",
792 >                        vval(BASENAME), rresopt, first);
793 >        while (*inspoint) inspoint++;
794 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
795 >                                        /* run in parallel */
796 >        i = (last-first+1)/(vint(INTERP)+1);
797 >        if (i < 1) i = 1;
798 >        if (pruncom(combuf, inspoint, i)) {
799 >                fprintf(stderr, "%s: error rendering frames %d through %d\n",
800                                  progname, first, last);
801                  quit(1);
802          }
# Line 599 | Line 810 | char   *vfn;
810   }
811  
812  
813 + int
814   recover(frame)                          /* recover the specified frame */
815   int     frame;
816   {
817 +        static int      *rfrm;          /* list of recovered frames */
818 +        static int      nrfrms = 0;
819 +        double  blurf;
820 +        int     nblur = getblur(&blurf);
821          char    combuf[2048];
822          char    fname[128];
823          register char   *cp;
824 <
824 >        register int    i;
825 >                                        /* check to see if recovered already */
826 >        for (i = nrfrms; i--; )
827 >                if (rfrm[i] == frame)
828 >                        return(0);
829 >                                        /* build command */
830          sprintf(fname, vval(BASENAME), frame);
831          if (vdef(ANIMATE))
832 <                sprintf(combuf, "%s %d | rpict%s",
832 >                sprintf(combuf, "%s %d | rpict%s -w0",
833                                  vval(ANIMATE), frame, rendopt);
834          else
835 <                sprintf(combuf, "rpict%s", rendopt);
836 <        cp = combuf + strlen(combuf);
837 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
835 >                sprintf(combuf, "rpict%s -w0", rendopt);
836 >        cp = combuf;
837 >        while (*cp) cp++;
838 >        if (nblur) {
839 >                sprintf(cp, " -pm %.3f", blurf/nblur);
840 >                while (*cp) cp++;
841 >        }
842 >        if (nblur > 1 || vint(INTERP)) {
843                  sprintf(cp, " -z %s.zbf", fname);
844                  while (*cp) cp++;
845          }
# Line 623 | Line 849 | int    frame;
849                  *cp++ = ' ';
850                  strcpy(cp, vval(OCTREE));
851          }
852 <        if (runcom(combuf)) {
853 <                fprintf(stderr, "%s: error recovering frame %d\n",
854 <                                progname, frame);
852 >        if (runcom(combuf))             /* run command */
853 >                return(1);
854 >                                        /* add frame to recovered list */
855 >        if (nrfrms)
856 >                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
857 >        else
858 >                rfrm = (int *)malloc(sizeof(int));
859 >        if (rfrm == NULL) {
860 >                perror("malloc");
861                  quit(1);
862          }
863 +        rfrm[nrfrms++] = frame;
864 +        return(0);
865   }
866  
867  
868 < archive(first, last)                    /* archive finished renderings */
869 < int     first, last;
868 > int
869 > frecover(frame)                         /* recover filtered frame */
870 > int     frame;
871   {
872 <        char    combuf[10240];
873 <        int     offset;
639 <        struct stat     stb;
640 <        register char   *cp;
641 <        register int    i;
872 >        VIEW    *vp;
873 >        char    *ex;
874  
875 <        strcpy(cp=combuf, vval(ARCHIVE));
876 <        while (*cp) cp++;
877 <        offset = cp - combuf;
878 <        *cp++ = ' ';                            /* make argument list */
879 <        for (i = first; i <= last; i++) {
880 <                sprintf(cp, vval(BASENAME), i);
881 <                strcat(cp, ".unf");
882 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
883 <                        while (*cp) cp++;
884 <                        *cp++ = ' ';
885 <                        sprintf(cp, vval(BASENAME), i);
886 <                        strcat(cp, ".zbf");
887 <                        if (access(cp, F_OK) == 0) {            /* exists? */
888 <                                while (*cp) cp++;
889 <                                *cp++ = ' ';
890 <                        }
875 >        vp = getview(frame);
876 >        ex = getexp(frame);
877 >        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
878 >                return(1);
879 >        return(0);
880 > }
881 >
882 >
883 > archive()                       /* archive and remove renderings */
884 > {
885 > #define RMCOML  (sizeof(rmcom)-1)
886 >        static char     rmcom[] = "rm -f";
887 >        char    basedir[128];
888 >        int     dlen, alen;
889 >        register int    j;
890 >
891 >        if (arcnext == arcfirst)
892 >                return;                         /* nothing to do */
893 >        dirfile(basedir, vval(BASENAME));
894 >        dlen = strlen(basedir);
895 >        if (vdef(ARCHIVE)) {                    /* run archive command */
896 >                alen = strlen(vval(ARCHIVE));
897 >                if (dlen) {
898 >                        j = alen + dlen + 5;
899 >                        strncpy(arcfirst-j, "cd ", 3);
900 >                        strncpy(arcfirst-j+3, basedir, dlen);
901 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
902 >                } else
903 >                        j = alen;
904 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
905 >                if (runcom(arcfirst-j)) {
906 >                        fprintf(stderr, "%s: error running archive command\n",
907 >                                        progname);
908 >                        quit(1);
909                  }
910          }
911 <        *--cp = '\0';
912 <        if (cp <= combuf + offset)              /* no files? */
913 <                return;
914 <        if (runcom(combuf)) {                   /* run archive command */
915 <                fprintf(stderr,
916 <                "%s: error running archive command on frames %d through %d\n",
917 <                                progname, first, last);
918 <                quit(1);
919 <        }
911 >        if (dlen) {
912 >                j = RMCOML + dlen + 5;
913 >                strncpy(arcfirst-j, "cd ", 3);
914 >                strncpy(arcfirst-j+3, basedir, dlen);
915 >                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
916 >        } else
917 >                j = RMCOML;
918 >                                                /* run remove command */
919 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
920 >        runcom(arcfirst-j);
921 >        arcnext = arcfirst;                     /* reset argument list */
922 > #undef RMCOML
923   }
924  
925  
926 < dofilt(frame, vp, ep)                           /* filter frame */
926 > int
927 > dofilt(frame, vp, ep, rvr)                      /* filter frame */
928   int     frame;
929   VIEW    *vp;
930   char    *ep;
931 + int     rvr;
932   {
933 <        char    fnbefore[128], fnafter[128];
934 <        char    combuf[1024], fname[128];
935 <        int     usepinterp, usepfilt;
936 <        int     frbefore, frafter, triesleft;
933 >        extern int      frecover();
934 >        static int      iter = 0;
935 >        double  blurf;
936 >        int     nblur = getblur(&blurf);
937 >        char    fnbefore[128], fnafter[128], *fbase;
938 >        char    combuf[1024], fname0[128], fname1[128];
939 >        int     usepinterp, usepfilt, nora_rgbe;
940 >        int     frseq[2];
941                                                  /* check what is needed */
942 <        usepinterp = atoi(vval(MBLUR));
942 >        usepinterp = (nblur > 1);
943          usepfilt = pfiltalways | ep==NULL;
944 +        if (ep != NULL && !strcmp(ep, "1"))
945 +                ep = "+0";
946 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
947 +                        *ep != '+' || *ep != '-' || !isint(ep);
948                                                  /* compute rendered views */
949 <        frbefore = frame - ((frame-1) % (vint(INTERP)+1));
950 <        frafter = frbefore + vint(INTERP) + 1;
951 <        if (frafter > vint(END))
952 <                frafter = vint(END);
953 <        if (frafter == frame) {                 /* pfilt only */
954 <                frbefore = frafter;
949 >        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
950 >        frseq[1] = frseq[0] + vint(INTERP) + 1;
951 >        fbase = dirfile(NULL, vval(BASENAME));
952 >        if (frseq[1] > vint(END))
953 >                frseq[1] = vint(END);
954 >        if (frseq[1] == frame) {                        /* pfilt only */
955 >                frseq[0] = frseq[1];
956                  usepinterp = 0;                 /* update what's needed */
957 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
958 <                triesleft = 2;
959 <        } else if (frbefore == frame) {         /* no interpolation */
960 <                                                /* remove unneeded files */
961 <                if (frbefore-vint(INTERP)-1 >= 1) {
962 <                        sprintf(fname, vval(BASENAME), frbefore-vint(INTERP)-1);
963 <                        sprintf(combuf, "rm -f %s.unf %s.zbf", fname, fname);
964 <                        runcom(combuf);
957 >                usepfilt |= nora_rgbe;
958 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
959 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
960 >                        *arcnext++ = ' ';
961 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
962 >                        while (*arcnext) arcnext++;
963 >                        strcpy(arcnext, ".unf");
964 >                        arcnext += 4;
965 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
966 >                                *arcnext++ = ' ';
967 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
968 >                                while (*arcnext) arcnext++;
969 >                                strcpy(arcnext, ".zbf");
970 >                                arcnext += 4;
971 >                        }
972                  }
973 <                                                /* update what's needed */
974 <                if (usepinterp)
975 <                        triesleft = 3;
705 <                else {
706 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
707 <                        triesleft = 2;
708 <                }
709 <        } else {                                /* interpolation needed */
973 >                if (!usepinterp)                /* update what's needed */
974 >                        usepfilt |= nora_rgbe;
975 >        } else                                  /* interpolation needed */
976                  usepinterp++;
977 <                triesleft = 3;
978 <        }
979 <        if (frafter >= astat.rnext) {           /* next batch unavailable */
980 <                frafter = frbefore;
981 <                if (triesleft > 2)
982 <                        triesleft = 2;
983 <        }
718 <        sprintf(fnbefore, vval(BASENAME), frbefore);
719 <        sprintf(fnafter, vval(BASENAME), frafter);
720 < tryit:                                          /* generate command */
977 >        if (frseq[1] >= astat.rnext)            /* next batch unavailable */
978 >                frseq[1] = frseq[0];
979 >        sprintf(fnbefore, vval(BASENAME), frseq[0]);
980 >        sprintf(fnafter, vval(BASENAME), frseq[1]);
981 >        if (rvr == 1 && recover(frseq[0]))      /* recover before frame? */
982 >                return(1);
983 >                                                /* generate command */
984          if (usepinterp) {                       /* using pinterp */
985 <                if (atoi(vval(MBLUR))) {
986 <                        FILE    *fp;            /* motion blurring */
987 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
988 <                        if ((fp = fopen(fname, "w")) == NULL) {
989 <                                perror(fname); quit(1);
990 <                        }
991 <                        fputs(VIEWSTR, fp);
992 <                        fprintview(vp, fp);
993 <                        putc('\n', fp); fclose(fp);
994 <                        if ((vp = getview(frame+1)) == NULL) {
995 <                                fprintf(stderr,
985 >                if (rvr == 2 && recover(frseq[1]))      /* recover after? */
986 >                        return(1);
987 >                if (nblur > 1) {                /* with pmblur */
988 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
989 >                                        'a'+(iter%26));
990 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
991 >                                        'a'+(iter%26));
992 >                        if (!noaction) {
993 >                                FILE    *fp;            /* motion blurring */
994 >                                if ((fp = fopen(fname0, "w")) == NULL) {
995 >                                        perror(fname0); quit(1);
996 >                                }
997 >                                fputs(VIEWSTR, fp);
998 >                                fprintview(vp, fp);
999 >                                putc('\n', fp); fclose(fp);
1000 >                                if ((vp = getview(frame+1)) == NULL) {
1001 >                                        fprintf(stderr,
1002                          "%s: unexpected error reading view for frame %d\n",
1003 <                                                progname, frame+1);
1004 <                                quit(1);
1003 >                                                        progname, frame+1);
1004 >                                        quit(1);
1005 >                                }
1006 >                                if ((fp = fopen(fname1, "w")) == NULL) {
1007 >                                        perror(fname1); quit(1);
1008 >                                }
1009 >                                fputs(VIEWSTR, fp);
1010 >                                fprintview(vp, fp);
1011 >                                putc('\n', fp); fclose(fp);
1012                          }
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);
1013                          sprintf(combuf,
1014 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
1015 <                                *sskip(vval(MBLUR)) ? sskip(vval(MBLUR)) : "1",
1016 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
1017 <                                        vval(DIRECTORY), vval(DIRECTORY),
749 <                                        vval(DIRECTORY), vval(DIRECTORY));
1014 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B",
1015 >                                        blurf, nblur,
1016 >                                        fname0, fname1, fname0, fname1);
1017 >                        iter++;
1018                  } else                          /* no blurring */
1019                          strcpy(combuf, "pinterp");
1020                  strcat(combuf, viewopt(vp));
1021                  if (vbool(RTRACE))
1022 <                        sprintf(combuf+strlen(combuf), " -ff -fr '%s %s'",
1023 <                                        rendopt, vval(OCTREE));
1022 >                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1023 >                                        rendopt+1, vval(OCTREE));
1024                  if (vdef(PINTERP))
1025                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1026                  if (usepfilt)
# Line 762 | Line 1030 | tryit:                                         /* generate command */
1030                                          fresopt, ep);
1031                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1032                                  fnbefore, fnbefore);
1033 <                if (frafter != frbefore)
1033 >                if (frseq[1] != frseq[0])
1034                           sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1035                                          fnafter, fnafter);
1036                  if (usepfilt) {                 /* also pfilt */
# Line 778 | Line 1046 | tryit:                                         /* generate command */
1046                                  sprintf(combuf+strlen(combuf), " %s", fresopt);
1047                  }
1048          } else if (usepfilt) {                  /* pfilt only */
1049 +                if (rvr == 2)
1050 +                        return(1);
1051                  if (vdef(PFILT))
1052                          sprintf(combuf, "pfilt %s", vval(PFILT));
1053                  else
# Line 789 | Line 1059 | tryit:                                         /* generate command */
1059                          sprintf(combuf+strlen(combuf), " %s %s.unf",
1060                                          fresopt, fnbefore);
1061          } else {                                /* else just check it */
1062 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
1062 >                if (rvr == 2)
1063 >                        return(1);
1064 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1065          }
1066                                                  /* output file name */
1067 <        sprintf(fname, vval(BASENAME), frame);
1068 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
1069 <        if (runcom(combuf))                     /* run filter command */
1070 <                switch (--triesleft) {
1071 <                case 2:                         /* try to recover frafter */
1072 <                        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 <                }
1067 >        sprintf(fname0, vval(BASENAME), frame);
1068 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1069 >        if (rvr)                                /* in recovery */
1070 >                return(runcom(combuf));
1071 >        bruncom(combuf, frame, frecover);       /* else run in background */
1072 >        return(0);
1073   }
1074  
1075  
814 filtwait(nwait)                 /* wait for filtering processes to finish */
815 int     nwait;
816 {
817        /* currently does nothing since parallel filtering not working */
818 }
819
820
1076   VIEW *
1077   getview(n)                      /* get view number n */
1078   int     n;
# Line 836 | Line 1091 | int    n;
1091                  }
1092                  return(NULL);
1093          }
1094 <        if (viewfp == NULL) {           /* open file */
1094 >        if (viewfp == NULL) {                   /* open file */
1095                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1096                          perror(vval(VIEWFILE));
1097                          quit(1);
1098                  }
1099 <        } else if (n < viewnum) {       /* rewind file */
1099 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1100 >                if (viewnum == 1 && feof(viewfp))
1101 >                        return(&curview);               /* just one view */
1102                  if (fseek(viewfp, 0L, 0) == EOF) {
1103                          perror(vval(VIEWFILE));
1104                          quit(1);
# Line 849 | Line 1106 | int    n;
1106                  copystruct(&curview, &stdview);
1107                  viewnum = 0;
1108          }
1109 +        if (n < 0) {                            /* get next view */
1110 +                register int    c = getc(viewfp);
1111 +                if (c == EOF)
1112 +                        return((VIEW *)NULL);           /* that's it */
1113 +                ungetc(c, viewfp);
1114 +                n = viewnum + 1;
1115 +        }
1116          while (n > viewnum) {           /* scan to desired view */
1117                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1118 <                        return(NULL);
1118 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1119                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1120                          viewnum++;
1121          }
# Line 862 | Line 1126 | int    n;
1126   int
1127   countviews()                    /* count views in view file */
1128   {
1129 <        register int    n = 0;
1129 >        int     n;
1130  
1131 <        while (getview(n+1) != NULL)
1131 >        if (getview(n=1) == NULL)
1132 >                return(0);
1133 >        while (getview(-1) != NULL)
1134                  n++;
1135          return(n);
1136   }
# Line 884 | Line 1150 | int    n;
1150          if (n == 0) {                           /* signal to close file */
1151                  if (expfp != NULL) {
1152                          fclose(expfp);
1153 +                        free((void *)exppos);
1154                          expfp = NULL;
1155                  }
1156                  return(NULL);
1157 <        }
1157 >        } else if (n > vint(END))               /* request past end (error?) */
1158 >                return(NULL);
1159          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1160                  return(NULL);
1161          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 925 | Line 1193 | int    n;
1193                  }
1194                  curfrm++;
1195                  cp = fskip(expval);                     /* check format */
1196 <                if (cp == NULL || *cp != '\n') {
1196 >                if (cp != NULL)
1197 >                        while (isspace(*cp))
1198 >                                *cp++ = '\0';
1199 >                if (cp == NULL || *cp) {
1200                          fprintf(stderr,
1201                                  "%s: exposure format error on line %d\n",
1202                                          vval(EXPOSURE), curfrm);
1203                          quit(1);
1204                  }
934                *cp = '\0';
1205          }
1206          return(expval);                         /* return value */
1207   }
1208  
1209  
1210 < runcom(cs)                      /* run command */
1210 > struct pslot *
1211 > findpslot(pid)                  /* find or allocate a process slot */
1212 > int     pid;
1213 > {
1214 >        register struct pslot   *psempty = NULL;
1215 >        register int    i;
1216 >
1217 >        for (i = 0; i < npslots; i++) {         /* look for match */
1218 >                if (pslot[i].pid == pid)
1219 >                        return(pslot+i);
1220 >                if (psempty == NULL && pslot[i].pid == 0)
1221 >                        psempty = pslot+i;
1222 >        }
1223 >        return(psempty);                /* return emtpy slot (error if NULL) */
1224 > }
1225 >
1226 >
1227 > int
1228 > donecom(ps, pn, status)         /* clean up after finished process */
1229 > PSERVER *ps;
1230 > int     pn;
1231 > int     status;
1232 > {
1233 >        register PROC   *pp;
1234 >        register struct pslot   *psl;
1235 >
1236 >        pp = ps->proc + pn;
1237 >        if (pp->elen) {                 /* pass errors */
1238 >                if (ps->hostname[0])
1239 >                        fprintf(stderr, "%s: ", ps->hostname);
1240 >                fprintf(stderr, "Error output from: %s\n", pp->com);
1241 >                fputs(pp->errs, stderr);
1242 >                fflush(stderr);
1243 >                if (ps->hostname[0])
1244 >                        status = 1;     /* because rsh doesn't return status */
1245 >        }
1246 >        lastpserver = NULL;
1247 >        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1248 >        if (psl->pid) {
1249 >                if (status) {
1250 >                        if (psl->rcvf != NULL)  /* attempt recovery */
1251 >                                status = (*psl->rcvf)(psl->fout);
1252 >                        if (status) {
1253 >                                fprintf(stderr,
1254 >                                        "%s: error rendering frame %d\n",
1255 >                                                progname, psl->fout);
1256 >                                quit(1);
1257 >                        }
1258 >                        lastpserver = ps;
1259 >                }
1260 >                psl->pid = 0;                   /* free process slot */
1261 >        } else if (status)
1262 >                lastpserver = ps;
1263 >        freestr(pp->com);               /* free command string */
1264 >        return(status);
1265 > }
1266 >
1267 >
1268 > int
1269 > serverdown()                    /* check status of last process server */
1270 > {
1271 >        if (lastpserver == NULL || !lastpserver->hostname[0])
1272 >                return(0);
1273 >        if (pserverOK(lastpserver))     /* server still up? */
1274 >                return(0);
1275 >        delpserver(lastpserver);        /* else delete it */
1276 >        if (pslist == NULL) {
1277 >                fprintf(stderr, "%s: all process servers are down\n",
1278 >                                progname);
1279 >                quit(1);
1280 >        }
1281 >        return(1);
1282 > }
1283 >
1284 >
1285 > int
1286 > bruncom(com, fout, rf)          /* run a command in the background */
1287 > char    *com;
1288 > int     fout;
1289 > int     (*rf)();
1290 > {
1291 >        int     pid;
1292 >        register struct pslot   *psl;
1293 >
1294 >        if (noaction) {
1295 >                if (!silent)
1296 >                        printf("\t%s\n", com);  /* echo command */
1297 >                return(0);
1298 >        }
1299 >        com = savestr(com);             /* else start it when we can */
1300 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1301 >                bwait(1);
1302 >        if (!silent) {                          /* echo command */
1303 >                PSERVER *ps;
1304 >                int     psn = pid;
1305 >                ps = findjob(&psn);
1306 >                printf("\t%s\n", com);
1307 >                printf("\tProcess started on %s\n", phostname(ps));
1308 >                fflush(stdout);
1309 >        }
1310 >        psl = findpslot(pid);           /* record info. in appropriate slot */
1311 >        psl->pid = pid;
1312 >        psl->fout = fout;
1313 >        psl->rcvf = rf;
1314 >        return(pid);
1315 > }
1316 >
1317 >
1318 > bwait(ncoms)                            /* wait for batch job(s) to finish */
1319 > int     ncoms;
1320 > {
1321 >        int     status;
1322 >
1323 >        if (noaction)
1324 >                return;
1325 >        while ((status = wait4job(NULL, -1)) != -1) {
1326 >                serverdown();           /* update server status */
1327 >                if (--ncoms == 0)
1328 >                        break;          /* done enough */
1329 >        }
1330 > }
1331 >
1332 >
1333 > int
1334 > pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1335 > char    *com, *ppins;
1336 > int     maxcopies;
1337 > {
1338 >        int     retstatus = 0;
1339 >        int     hostcopies;
1340 >        char    buf[10240], *com1, *s;
1341 >        int     status;
1342 >        int     pfd;
1343 >        register int    n;
1344 >        register PSERVER        *ps;
1345 >
1346 >        if (!silent)
1347 >                printf("\t%s\n", com);  /* echo command */
1348 >        if (noaction)
1349 >                return(0);
1350 >        fflush(stdout);
1351 >                                        /* start jobs on each server */
1352 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1353 >                hostcopies = 0;
1354 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1355 >                        strcpy(com1=buf, com);  /* build -PP command */
1356 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1357 >                                        vval(DIRECTORY), phostname(ps));
1358 >                        strcat(com1, ppins);
1359 >                } else
1360 >                        com1 = com;
1361 >                while (maxcopies > 0) {
1362 >                        s = savestr(com1);
1363 >                        if (startjob(ps, s, donecom) != -1) {
1364 >                                sleep(20);
1365 >                                hostcopies++;
1366 >                                maxcopies--;
1367 >                        } else {
1368 >                                freestr(s);
1369 >                                break;
1370 >                        }
1371 >                }
1372 >                if (!silent && hostcopies) {
1373 >                        if (hostcopies > 1)
1374 >                                printf("\t%d duplicate processes", hostcopies);
1375 >                        else
1376 >                                printf("\tProcess");
1377 >                        printf(" started on %s\n", phostname(ps));
1378 >                        fflush(stdout);
1379 >                }
1380 >        }
1381 >                                        /* wait for jobs to finish */
1382 >        while ((status = wait4job(NULL, -1)) != -1)
1383 >                retstatus += status && !serverdown();
1384 >                                        /* terminate parallel rpict's */
1385 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1386 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1387 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1388 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1389 >                        buf[n] = '\0';
1390 >                        close(pfd);
1391 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1392 >                                ;
1393 >                                                                /* terminate */
1394 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1395 >                        wait4job(ps, startjob(ps, buf, NULL));
1396 >                }
1397 >        }
1398 >        return(retstatus);
1399 > }
1400 >
1401 >
1402 > runcom(cs)                      /* run a command locally and wait for it */
1403   char    *cs;
1404   {
1405          if (!silent)            /* echo it */
# Line 970 | Line 1432 | int    vc;
1432          fprintf(stderr, "%s: bad value for variable '%s'\n",
1433                          progname, vnam(vc));
1434          quit(1);
1435 + }
1436 +
1437 +
1438 + char *
1439 + dirfile(df, path)               /* separate path into directory and file */
1440 + char    *df;
1441 + register char   *path;
1442 + {
1443 +        register int    i;
1444 +        int     psep;
1445 +
1446 +        for (i = 0, psep = -1; path[i]; i++)
1447 +                if (path[i] == '/')
1448 +                        psep = i;
1449 +        if (df != NULL)
1450 +                if (psep == 0) {
1451 +                        df[0] = '/';
1452 +                        df[1] = '\0';
1453 +                } else if (psep > 0) {
1454 +                        strncpy(df, path, psep);
1455 +                        df[psep] = '\0';
1456 +                } else
1457 +                        df[0] = '\0';
1458 +        return(path+psep+1);
1459 + }
1460 +
1461 +
1462 + int
1463 + getblur(double *bf)             /* get # blur samples (and fraction) */
1464 + {
1465 +        double  blurf;
1466 +        int     nblur;
1467 +        char    *s;
1468 +
1469 +        if (!vdef(MBLUR)) {
1470 +                if (bf != NULL)
1471 +                        *bf = 0.0;
1472 +                return(0);
1473 +        }
1474 +        blurf = atof(vval(MBLUR));
1475 +        if (blurf < 0.0)
1476 +                blurf = 0.0;
1477 +        if (bf != NULL)
1478 +                *bf = blurf;
1479 +        if (blurf <= FTINY)
1480 +                return(0);
1481 +        s = sskip(vval(MBLUR));
1482 +        if (!*s)
1483 +                return(DEF_NBLUR);
1484 +        nblur = atoi(s);
1485 +        if (nblur <= 0)
1486 +                return(1);
1487 +        return(nblur);
1488   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines