| 1 | 
greg | 
2.1 | 
#ifndef lint | 
| 2 | 
schorsch | 
2.37 | 
static const char RCSid[] = "$Id: ranimate.c,v 2.36 2003/06/01 15:21:57 greg Exp $"; | 
| 3 | 
greg | 
2.1 | 
#endif | 
| 4 | 
  | 
  | 
/* | 
| 5 | 
  | 
  | 
 * Radiance animation control program | 
| 6 | 
greg | 
2.29 | 
 * | 
| 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 | 
greg | 
2.31 | 
#include "copyright.h" | 
| 17 | 
greg | 
2.1 | 
 | 
| 18 | 
  | 
  | 
#include "standard.h" | 
| 19 | 
greg | 
2.2 | 
#include <ctype.h> | 
| 20 | 
greg | 
2.1 | 
#include <sys/stat.h> | 
| 21 | 
  | 
  | 
#include "view.h" | 
| 22 | 
  | 
  | 
#include "vars.h" | 
| 23 | 
greg | 
2.2 | 
#include "netproc.h" | 
| 24 | 
greg | 
2.29 | 
                                /* default blur samples */ | 
| 25 | 
  | 
  | 
#ifndef DEF_NBLUR | 
| 26 | 
  | 
  | 
#define DEF_NBLUR       5 | 
| 27 | 
  | 
  | 
#endif | 
| 28 | 
greg | 
2.10 | 
                                /* default remote shell */ | 
| 29 | 
  | 
  | 
#ifdef _AUX_SOURCE | 
| 30 | 
  | 
  | 
#define REMSH           "remsh" | 
| 31 | 
  | 
  | 
#else | 
| 32 | 
  | 
  | 
#define REMSH           "rsh" | 
| 33 | 
  | 
  | 
#endif | 
| 34 | 
gwlarson | 
2.27 | 
                                /* input variables (alphabetical by name) */ | 
| 35 | 
  | 
  | 
#define ANIMATE         0               /* animation command */ | 
| 36 | 
  | 
  | 
#define ARCHIVE         1               /* archiving command */ | 
| 37 | 
  | 
  | 
#define BASENAME        2               /* output image base name */ | 
| 38 | 
  | 
  | 
#define DIRECTORY       3               /* working (sub)directory */ | 
| 39 | 
  | 
  | 
#define DISKSPACE       4               /* how much disk space to use */ | 
| 40 | 
  | 
  | 
#define END             5               /* ending frame number */ | 
| 41 | 
  | 
  | 
#define EXPOSURE        6               /* how to compute exposure */ | 
| 42 | 
  | 
  | 
#define HOST            7               /* rendering host machine */ | 
| 43 | 
  | 
  | 
#define INTERP          8               /* # frames to interpolate */ | 
| 44 | 
greg | 
2.29 | 
#define MBLUR           9               /* motion blur parameters */ | 
| 45 | 
gwlarson | 
2.27 | 
#define NEXTANIM        10              /* next animation file */ | 
| 46 | 
  | 
  | 
#define OCTREE          11              /* octree file name */ | 
| 47 | 
  | 
  | 
#define OVERSAMP        12              /* # times to oversample image */ | 
| 48 | 
  | 
  | 
#define PFILT           13              /* pfilt options */ | 
| 49 | 
  | 
  | 
#define PINTERP         14              /* pinterp options */ | 
| 50 | 
  | 
  | 
#define RENDER          15              /* rendering options */ | 
| 51 | 
  | 
  | 
#define RESOLUTION      16              /* desired final resolution */ | 
| 52 | 
  | 
  | 
#define RIF             17              /* rad input file */ | 
| 53 | 
  | 
  | 
#define RSH             18              /* remote shell script or program */ | 
| 54 | 
  | 
  | 
#define RTRACE          19              /* use rtrace with pinterp? */ | 
| 55 | 
  | 
  | 
#define START           20              /* starting frame number */ | 
| 56 | 
  | 
  | 
#define TRANSFER        21              /* frame transfer command */ | 
| 57 | 
  | 
  | 
#define VIEWFILE        22              /* animation frame views */ | 
| 58 | 
greg | 
2.1 | 
 | 
| 59 | 
greg | 
2.10 | 
int     NVARS = 23;             /* total number of variables */ | 
| 60 | 
greg | 
2.1 | 
 | 
| 61 | 
  | 
  | 
VARIABLE        vv[] = {                /* variable-value pairs */ | 
| 62 | 
gwlarson | 
2.27 | 
        {"ANIMATE",     2,      0,      NULL,   onevalue}, | 
| 63 | 
  | 
  | 
        {"ARCHIVE",     2,      0,      NULL,   onevalue}, | 
| 64 | 
  | 
  | 
        {"BASENAME",    3,      0,      NULL,   onevalue}, | 
| 65 | 
greg | 
2.1 | 
        {"DIRECTORY",   3,      0,      NULL,   onevalue}, | 
| 66 | 
gwlarson | 
2.27 | 
        {"DISKSPACE",   3,      0,      NULL,   fltvalue}, | 
| 67 | 
greg | 
2.1 | 
        {"END",         2,      0,      NULL,   intvalue}, | 
| 68 | 
gwlarson | 
2.27 | 
        {"EXPOSURE",    3,      0,      NULL,   onevalue}, | 
| 69 | 
  | 
  | 
        {"host",        4,      0,      NULL,   NULL}, | 
| 70 | 
  | 
  | 
        {"INTERPOLATE", 3,      0,      NULL,   intvalue}, | 
| 71 | 
  | 
  | 
        {"MBLUR",       2,      0,      NULL,   onevalue}, | 
| 72 | 
greg | 
2.1 | 
        {"NEXTANIM",    3,      0,      NULL,   onevalue}, | 
| 73 | 
gwlarson | 
2.27 | 
        {"OCTREE",      3,      0,      NULL,   onevalue}, | 
| 74 | 
greg | 
2.5 | 
        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue}, | 
| 75 | 
gwlarson | 
2.27 | 
        {"pfilt",       2,      0,      NULL,   catvalues}, | 
| 76 | 
  | 
  | 
        {"pinterp",     2,      0,      NULL,   catvalues}, | 
| 77 | 
  | 
  | 
        {"render",      3,      0,      NULL,   catvalues}, | 
| 78 | 
greg | 
2.1 | 
        {"RESOLUTION",  3,      0,      NULL,   onevalue}, | 
| 79 | 
gwlarson | 
2.27 | 
        {"RIF",         3,      0,      NULL,   onevalue}, | 
| 80 | 
greg | 
2.10 | 
        {"RSH",         3,      0,      NULL,   onevalue}, | 
| 81 | 
gwlarson | 
2.27 | 
        {"RTRACE",      2,      0,      NULL,   boolvalue}, | 
| 82 | 
  | 
  | 
        {"START",       2,      0,      NULL,   intvalue}, | 
| 83 | 
  | 
  | 
        {"TRANSFER",    2,      0,      NULL,   onevalue}, | 
| 84 | 
  | 
  | 
        {"VIEWFILE",    2,      0,      NULL,   onevalue}, | 
| 85 | 
greg | 
2.1 | 
}; | 
| 86 | 
  | 
  | 
 | 
| 87 | 
  | 
  | 
#define SFNAME  "STATUS"                /* status file name */ | 
| 88 | 
  | 
  | 
 | 
| 89 | 
  | 
  | 
struct { | 
| 90 | 
  | 
  | 
        char    host[64];               /* control host name */ | 
| 91 | 
  | 
  | 
        int     pid;                    /* control process id */ | 
| 92 | 
  | 
  | 
        char    cfname[128];            /* control file name */ | 
| 93 | 
  | 
  | 
        int     rnext;                  /* next frame to render */ | 
| 94 | 
  | 
  | 
        int     fnext;                  /* next frame to filter */ | 
| 95 | 
  | 
  | 
        int     tnext;                  /* next frame to transfer */ | 
| 96 | 
  | 
  | 
}       astat;                  /* animation status */ | 
| 97 | 
  | 
  | 
 | 
| 98 | 
  | 
  | 
char    *progname;              /* our program name */ | 
| 99 | 
  | 
  | 
char    *cfname;                /* our control file name */ | 
| 100 | 
  | 
  | 
 | 
| 101 | 
  | 
  | 
int     nowarn = 0;             /* turn warnings off? */ | 
| 102 | 
  | 
  | 
int     silent = 0;             /* silent mode? */ | 
| 103 | 
  | 
  | 
int     noaction = 0;           /* take no action? */ | 
| 104 | 
  | 
  | 
 | 
| 105 | 
greg | 
2.10 | 
char    *remsh;                 /* remote shell program/script */ | 
| 106 | 
greg | 
2.21 | 
char    rendopt[2048];          /* rendering options */ | 
| 107 | 
greg | 
2.1 | 
char    rresopt[32];            /* rendering resolution options */ | 
| 108 | 
  | 
  | 
char    fresopt[32];            /* filter resolution options */ | 
| 109 | 
  | 
  | 
int     pfiltalways;            /* always use pfilt? */ | 
| 110 | 
  | 
  | 
 | 
| 111 | 
greg | 
2.7 | 
char    arcargs[10240];         /* files to archive */ | 
| 112 | 
  | 
  | 
char    *arcfirst, *arcnext;    /* pointers to first and next argument */ | 
| 113 | 
  | 
  | 
 | 
| 114 | 
greg | 
2.2 | 
struct pslot { | 
| 115 | 
  | 
  | 
        int     pid;                    /* process ID (0 if empty) */ | 
| 116 | 
  | 
  | 
        int     fout;                   /* output frame number */ | 
| 117 | 
  | 
  | 
        int     (*rcvf)();              /* recover function */ | 
| 118 | 
  | 
  | 
}       *pslot;                 /* process slots */ | 
| 119 | 
  | 
  | 
int     npslots;                /* number of process slots */ | 
| 120 | 
  | 
  | 
 | 
| 121 | 
greg | 
2.4 | 
#define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host) | 
| 122 | 
  | 
  | 
 | 
| 123 | 
greg | 
2.2 | 
struct pslot    *findpslot(); | 
| 124 | 
  | 
  | 
 | 
| 125 | 
greg | 
2.18 | 
PSERVER *lastpserver;           /* last process server with error */ | 
| 126 | 
  | 
  | 
 | 
| 127 | 
greg | 
2.1 | 
VIEW    *getview(); | 
| 128 | 
gwlarson | 
2.25 | 
char    *getexp(), *dirfile(); | 
| 129 | 
greg | 
2.29 | 
int     getblur(); | 
| 130 | 
greg | 
2.1 | 
 | 
| 131 | 
greg | 
2.29 | 
extern time_t   time(); | 
| 132 | 
greg | 
2.1 | 
 | 
| 133 | 
greg | 
2.12 | 
 | 
| 134 | 
greg | 
2.1 | 
main(argc, argv) | 
| 135 | 
  | 
  | 
int     argc; | 
| 136 | 
  | 
  | 
char    *argv[]; | 
| 137 | 
  | 
  | 
{ | 
| 138 | 
  | 
  | 
        int     explicate = 0; | 
| 139 | 
  | 
  | 
        int     i; | 
| 140 | 
  | 
  | 
 | 
| 141 | 
  | 
  | 
        progname = argv[0];                     /* get arguments */ | 
| 142 | 
  | 
  | 
        for (i = 1; i < argc && argv[i][0] == '-'; i++) | 
| 143 | 
  | 
  | 
                switch (argv[i][1]) { | 
| 144 | 
  | 
  | 
                case 'e':                       /* print variables */ | 
| 145 | 
  | 
  | 
                        explicate++; | 
| 146 | 
  | 
  | 
                        break; | 
| 147 | 
  | 
  | 
                case 'w':                       /* turn off warnings */ | 
| 148 | 
  | 
  | 
                        nowarn++; | 
| 149 | 
  | 
  | 
                        break; | 
| 150 | 
  | 
  | 
                case 's':                       /* silent mode */ | 
| 151 | 
  | 
  | 
                        silent++; | 
| 152 | 
  | 
  | 
                        break; | 
| 153 | 
  | 
  | 
                case 'n':                       /* take no action */ | 
| 154 | 
  | 
  | 
                        noaction++; | 
| 155 | 
  | 
  | 
                        break; | 
| 156 | 
  | 
  | 
                default: | 
| 157 | 
  | 
  | 
                        goto userr; | 
| 158 | 
  | 
  | 
                } | 
| 159 | 
  | 
  | 
        if (i != argc-1) | 
| 160 | 
  | 
  | 
                goto userr; | 
| 161 | 
  | 
  | 
        cfname = argv[i]; | 
| 162 | 
  | 
  | 
                                                /* load variables */ | 
| 163 | 
  | 
  | 
        loadvars(cfname); | 
| 164 | 
greg | 
2.22 | 
                                                /* check variables */ | 
| 165 | 
  | 
  | 
        checkvalues(); | 
| 166 | 
greg | 
2.1 | 
                                                /* did we get DIRECTORY? */ | 
| 167 | 
  | 
  | 
        checkdir(); | 
| 168 | 
  | 
  | 
                                                /* check status */ | 
| 169 | 
  | 
  | 
        if (getastat() < 0) { | 
| 170 | 
  | 
  | 
                fprintf(stderr, "%s: exiting\n", progname); | 
| 171 | 
  | 
  | 
                quit(1); | 
| 172 | 
  | 
  | 
        } | 
| 173 | 
  | 
  | 
                                                /* pfilt always if options given */ | 
| 174 | 
  | 
  | 
        pfiltalways = vdef(PFILT); | 
| 175 | 
  | 
  | 
                                                /* load RIF if any */ | 
| 176 | 
  | 
  | 
        if (vdef(RIF)) | 
| 177 | 
  | 
  | 
                getradfile(vval(RIF)); | 
| 178 | 
  | 
  | 
                                                /* set defaults */ | 
| 179 | 
  | 
  | 
        setdefaults(); | 
| 180 | 
  | 
  | 
                                                /* print variables */ | 
| 181 | 
  | 
  | 
        if (explicate) | 
| 182 | 
  | 
  | 
                printvars(stdout); | 
| 183 | 
greg | 
2.2 | 
                                                /* set up process servers */ | 
| 184 | 
  | 
  | 
        sethosts(); | 
| 185 | 
greg | 
2.1 | 
                                                /* run animation */ | 
| 186 | 
  | 
  | 
        animate(); | 
| 187 | 
  | 
  | 
                                                /* all done */ | 
| 188 | 
  | 
  | 
        if (vdef(NEXTANIM)) { | 
| 189 | 
  | 
  | 
                argv[i] = vval(NEXTANIM);       /* just change input file */ | 
| 190 | 
  | 
  | 
                if (!silent) | 
| 191 | 
  | 
  | 
                        printargs(argc, argv, stdout); | 
| 192 | 
greg | 
2.11 | 
                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) | 
| 193 | 
  | 
  | 
                        fprintf(stderr, "%s: command not found\n", progname); | 
| 194 | 
  | 
  | 
                else | 
| 195 | 
  | 
  | 
                        execv(progname, argv); | 
| 196 | 
  | 
  | 
                quit(1); | 
| 197 | 
greg | 
2.1 | 
        } | 
| 198 | 
  | 
  | 
        quit(0); | 
| 199 | 
  | 
  | 
userr: | 
| 200 | 
  | 
  | 
        fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname); | 
| 201 | 
  | 
  | 
        quit(1); | 
| 202 | 
  | 
  | 
} | 
| 203 | 
  | 
  | 
 | 
| 204 | 
  | 
  | 
 | 
| 205 | 
  | 
  | 
getastat()                      /* check/set animation status */ | 
| 206 | 
  | 
  | 
{ | 
| 207 | 
greg | 
2.12 | 
        char    sfname[256]; | 
| 208 | 
greg | 
2.1 | 
        FILE    *fp; | 
| 209 | 
  | 
  | 
 | 
| 210 | 
greg | 
2.12 | 
        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); | 
| 211 | 
  | 
  | 
        if ((fp = fopen(sfname, "r")) == NULL) { | 
| 212 | 
greg | 
2.1 | 
                if (errno != ENOENT) { | 
| 213 | 
greg | 
2.12 | 
                        perror(sfname); | 
| 214 | 
greg | 
2.1 | 
                        return(-1); | 
| 215 | 
  | 
  | 
                } | 
| 216 | 
  | 
  | 
                astat.rnext = astat.fnext = astat.tnext = 0; | 
| 217 | 
  | 
  | 
                goto setours; | 
| 218 | 
  | 
  | 
        } | 
| 219 | 
  | 
  | 
        if (fscanf(fp, "Control host: %s\n", astat.host) != 1) | 
| 220 | 
  | 
  | 
                goto fmterr; | 
| 221 | 
  | 
  | 
        if (fscanf(fp, "Control PID: %d\n", &astat.pid) != 1) | 
| 222 | 
  | 
  | 
                goto fmterr; | 
| 223 | 
  | 
  | 
        if (fscanf(fp, "Control file: %s\n", astat.cfname) != 1) | 
| 224 | 
  | 
  | 
                goto fmterr; | 
| 225 | 
  | 
  | 
        if (fscanf(fp, "Next render: %d\n", &astat.rnext) != 1) | 
| 226 | 
  | 
  | 
                goto fmterr; | 
| 227 | 
  | 
  | 
        if (fscanf(fp, "Next filter: %d\n", &astat.fnext) != 1) | 
| 228 | 
  | 
  | 
                goto fmterr; | 
| 229 | 
  | 
  | 
        if (fscanf(fp, "Next transfer: %d\n", &astat.tnext) != 1) | 
| 230 | 
  | 
  | 
                goto fmterr; | 
| 231 | 
  | 
  | 
        fclose(fp); | 
| 232 | 
  | 
  | 
        if (astat.pid != 0) {                   /* thinks it's still running */ | 
| 233 | 
greg | 
2.9 | 
                if (strcmp(myhostname(), astat.host)) { | 
| 234 | 
greg | 
2.1 | 
                        fprintf(stderr, | 
| 235 | 
  | 
  | 
                        "%s: process %d may still be running on host %s\n", | 
| 236 | 
  | 
  | 
                                        progname, astat.pid, astat.host); | 
| 237 | 
  | 
  | 
                        return(-1); | 
| 238 | 
  | 
  | 
                } | 
| 239 | 
  | 
  | 
                if (kill(astat.pid, 0) != -1 || errno != ESRCH) { | 
| 240 | 
  | 
  | 
                        fprintf(stderr, "%s: process %d is still running\n", | 
| 241 | 
  | 
  | 
                                        progname, astat.pid); | 
| 242 | 
  | 
  | 
                        return(-1); | 
| 243 | 
  | 
  | 
                } | 
| 244 | 
  | 
  | 
                /* assume it is dead */ | 
| 245 | 
  | 
  | 
        } | 
| 246 | 
greg | 
2.20 | 
        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */ | 
| 247 | 
greg | 
2.1 | 
                fprintf(stderr, "%s: unfinished job \"%s\"\n", | 
| 248 | 
  | 
  | 
                                progname, astat.cfname); | 
| 249 | 
  | 
  | 
                return(-1); | 
| 250 | 
  | 
  | 
        } | 
| 251 | 
greg | 
2.12 | 
                                                /* check control file mods. */ | 
| 252 | 
  | 
  | 
        if (!nowarn && fdate(cfname) > fdate(sfname)) | 
| 253 | 
  | 
  | 
                fprintf(stderr, | 
| 254 | 
  | 
  | 
                        "%s: warning - control file modified since last run\n", | 
| 255 | 
  | 
  | 
                                progname); | 
| 256 | 
greg | 
2.1 | 
setours:                                        /* set our values */ | 
| 257 | 
greg | 
2.9 | 
        strcpy(astat.host, myhostname()); | 
| 258 | 
greg | 
2.1 | 
        astat.pid = getpid(); | 
| 259 | 
  | 
  | 
        strcpy(astat.cfname, cfname); | 
| 260 | 
  | 
  | 
        return(0); | 
| 261 | 
  | 
  | 
fmterr: | 
| 262 | 
  | 
  | 
        fprintf(stderr, "%s: format error in status file \"%s\"\n", | 
| 263 | 
greg | 
2.12 | 
                        progname, sfname); | 
| 264 | 
greg | 
2.1 | 
        fclose(fp); | 
| 265 | 
  | 
  | 
        return(-1); | 
| 266 | 
  | 
  | 
} | 
| 267 | 
  | 
  | 
 | 
| 268 | 
  | 
  | 
 | 
| 269 | 
  | 
  | 
putastat()                      /* put out current status */ | 
| 270 | 
  | 
  | 
{ | 
| 271 | 
  | 
  | 
        char    buf[256]; | 
| 272 | 
  | 
  | 
        FILE    *fp; | 
| 273 | 
  | 
  | 
 | 
| 274 | 
greg | 
2.2 | 
        if (noaction) | 
| 275 | 
  | 
  | 
                return; | 
| 276 | 
greg | 
2.1 | 
        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); | 
| 277 | 
  | 
  | 
        if ((fp = fopen(buf, "w")) == NULL) { | 
| 278 | 
  | 
  | 
                perror(buf); | 
| 279 | 
  | 
  | 
                quit(1); | 
| 280 | 
  | 
  | 
        } | 
| 281 | 
  | 
  | 
        fprintf(fp, "Control host: %s\n", astat.host); | 
| 282 | 
  | 
  | 
        fprintf(fp, "Control PID: %d\n", astat.pid); | 
| 283 | 
  | 
  | 
        fprintf(fp, "Control file: %s\n", astat.cfname); | 
| 284 | 
  | 
  | 
        fprintf(fp, "Next render: %d\n", astat.rnext); | 
| 285 | 
  | 
  | 
        fprintf(fp, "Next filter: %d\n", astat.fnext); | 
| 286 | 
  | 
  | 
        fprintf(fp, "Next transfer: %d\n", astat.tnext); | 
| 287 | 
  | 
  | 
        fclose(fp); | 
| 288 | 
  | 
  | 
} | 
| 289 | 
  | 
  | 
 | 
| 290 | 
  | 
  | 
 | 
| 291 | 
  | 
  | 
checkdir()                      /* make sure we have our directory */ | 
| 292 | 
  | 
  | 
{ | 
| 293 | 
  | 
  | 
        struct stat     stb; | 
| 294 | 
  | 
  | 
 | 
| 295 | 
  | 
  | 
        if (!vdef(DIRECTORY)) { | 
| 296 | 
  | 
  | 
                fprintf(stderr, "%s: %s undefined\n", | 
| 297 | 
  | 
  | 
                                progname, vnam(DIRECTORY)); | 
| 298 | 
  | 
  | 
                quit(1); | 
| 299 | 
  | 
  | 
        } | 
| 300 | 
  | 
  | 
        if (stat(vval(DIRECTORY), &stb) == -1) { | 
| 301 | 
  | 
  | 
                if (errno == ENOENT && mkdir(vval(DIRECTORY), 0777) == 0) | 
| 302 | 
  | 
  | 
                        return; | 
| 303 | 
  | 
  | 
                perror(vval(DIRECTORY)); | 
| 304 | 
  | 
  | 
                quit(1); | 
| 305 | 
  | 
  | 
        } | 
| 306 | 
  | 
  | 
        if (!(stb.st_mode & S_IFDIR)) { | 
| 307 | 
  | 
  | 
                fprintf(stderr, "%s: not a directory\n", vval(DIRECTORY)); | 
| 308 | 
  | 
  | 
                quit(1); | 
| 309 | 
  | 
  | 
        } | 
| 310 | 
  | 
  | 
} | 
| 311 | 
  | 
  | 
 | 
| 312 | 
  | 
  | 
 | 
| 313 | 
  | 
  | 
setdefaults()                   /* set default values */ | 
| 314 | 
  | 
  | 
{ | 
| 315 | 
greg | 
2.10 | 
        extern char     *atos(); | 
| 316 | 
greg | 
2.19 | 
        int     decades; | 
| 317 | 
greg | 
2.1 | 
        char    buf[256]; | 
| 318 | 
  | 
  | 
 | 
| 319 | 
greg | 
2.2 | 
        if (vdef(ANIMATE)) { | 
| 320 | 
  | 
  | 
                vval(OCTREE) = NULL; | 
| 321 | 
  | 
  | 
                vdef(OCTREE) = 0; | 
| 322 | 
  | 
  | 
        } else if (!vdef(OCTREE)) { | 
| 323 | 
greg | 
2.1 | 
                fprintf(stderr, "%s: either %s or %s must be defined\n", | 
| 324 | 
  | 
  | 
                                progname, vnam(OCTREE), vnam(ANIMATE)); | 
| 325 | 
  | 
  | 
                quit(1); | 
| 326 | 
  | 
  | 
        } | 
| 327 | 
  | 
  | 
        if (!vdef(VIEWFILE)) { | 
| 328 | 
  | 
  | 
                fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE)); | 
| 329 | 
  | 
  | 
                quit(1); | 
| 330 | 
  | 
  | 
        } | 
| 331 | 
greg | 
2.2 | 
        if (!vdef(HOST)) { | 
| 332 | 
  | 
  | 
                vval(HOST) = LHOSTNAME; | 
| 333 | 
  | 
  | 
                vdef(HOST)++; | 
| 334 | 
  | 
  | 
        } | 
| 335 | 
greg | 
2.1 | 
        if (!vdef(START)) { | 
| 336 | 
  | 
  | 
                vval(START) = "1"; | 
| 337 | 
  | 
  | 
                vdef(START)++; | 
| 338 | 
  | 
  | 
        } | 
| 339 | 
  | 
  | 
        if (!vdef(END)) { | 
| 340 | 
greg | 
2.5 | 
                sprintf(buf, "%d", countviews()+vint(START)-1); | 
| 341 | 
greg | 
2.1 | 
                vval(END) = savqstr(buf); | 
| 342 | 
  | 
  | 
                vdef(END)++; | 
| 343 | 
  | 
  | 
        } | 
| 344 | 
greg | 
2.5 | 
        if (vint(END) < vint(START)) { | 
| 345 | 
  | 
  | 
                fprintf(stderr, "%s: ending frame less than starting frame\n", | 
| 346 | 
  | 
  | 
                                progname); | 
| 347 | 
  | 
  | 
                quit(1); | 
| 348 | 
  | 
  | 
        } | 
| 349 | 
greg | 
2.1 | 
        if (!vdef(BASENAME)) { | 
| 350 | 
greg | 
2.19 | 
                decades = (int)log10((double)vint(END)) + 1; | 
| 351 | 
  | 
  | 
                if (decades < 3) decades = 3; | 
| 352 | 
  | 
  | 
                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); | 
| 353 | 
greg | 
2.1 | 
                vval(BASENAME) = savqstr(buf); | 
| 354 | 
  | 
  | 
                vdef(BASENAME)++; | 
| 355 | 
  | 
  | 
        } | 
| 356 | 
  | 
  | 
        if (!vdef(RESOLUTION)) { | 
| 357 | 
  | 
  | 
                vval(RESOLUTION) = "640"; | 
| 358 | 
  | 
  | 
                vdef(RESOLUTION)++; | 
| 359 | 
  | 
  | 
        } | 
| 360 | 
  | 
  | 
        if (!vdef(OVERSAMP)) { | 
| 361 | 
  | 
  | 
                vval(OVERSAMP) = "2"; | 
| 362 | 
  | 
  | 
                vdef(OVERSAMP)++; | 
| 363 | 
  | 
  | 
        } | 
| 364 | 
  | 
  | 
        if (!vdef(INTERP)) { | 
| 365 | 
  | 
  | 
                vval(INTERP) = "0"; | 
| 366 | 
  | 
  | 
                vdef(INTERP)++; | 
| 367 | 
  | 
  | 
        } | 
| 368 | 
  | 
  | 
        if (!vdef(MBLUR)) { | 
| 369 | 
  | 
  | 
                vval(MBLUR) = "0"; | 
| 370 | 
  | 
  | 
                vdef(MBLUR)++; | 
| 371 | 
  | 
  | 
        } | 
| 372 | 
  | 
  | 
        if (!vdef(RTRACE)) { | 
| 373 | 
  | 
  | 
                vval(RTRACE) = "F"; | 
| 374 | 
  | 
  | 
                vdef(RTRACE)++; | 
| 375 | 
  | 
  | 
        } | 
| 376 | 
  | 
  | 
        if (!vdef(DISKSPACE)) { | 
| 377 | 
  | 
  | 
                if (!nowarn) | 
| 378 | 
  | 
  | 
                        fprintf(stderr, | 
| 379 | 
  | 
  | 
                "%s: warning - no %s setting, assuming 100 Mbytes available\n", | 
| 380 | 
  | 
  | 
                                        progname, vnam(DISKSPACE)); | 
| 381 | 
  | 
  | 
                vval(DISKSPACE) = "100"; | 
| 382 | 
  | 
  | 
                vdef(DISKSPACE)++; | 
| 383 | 
  | 
  | 
        } | 
| 384 | 
greg | 
2.10 | 
        if (!vdef(RSH)) { | 
| 385 | 
  | 
  | 
                vval(RSH) = REMSH; | 
| 386 | 
  | 
  | 
                vdef(RSH)++; | 
| 387 | 
  | 
  | 
        } | 
| 388 | 
  | 
  | 
                                /* locate remote shell program */ | 
| 389 | 
  | 
  | 
        atos(buf, sizeof(buf), vval(RSH)); | 
| 390 | 
  | 
  | 
        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) | 
| 391 | 
  | 
  | 
                remsh = savqstr(remsh); | 
| 392 | 
  | 
  | 
        else | 
| 393 | 
  | 
  | 
                remsh = vval(RSH);      /* will generate error if used */ | 
| 394 | 
  | 
  | 
 | 
| 395 | 
greg | 
2.1 | 
                                /* append rendering options */ | 
| 396 | 
  | 
  | 
        if (vdef(RENDER)) | 
| 397 | 
  | 
  | 
                sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); | 
| 398 | 
  | 
  | 
} | 
| 399 | 
  | 
  | 
 | 
| 400 | 
  | 
  | 
 | 
| 401 | 
greg | 
2.2 | 
sethosts()                      /* set up process servers */ | 
| 402 | 
  | 
  | 
{ | 
| 403 | 
  | 
  | 
        extern char     *iskip(); | 
| 404 | 
  | 
  | 
        char    buf[256], *dir, *uname; | 
| 405 | 
  | 
  | 
        int     np; | 
| 406 | 
  | 
  | 
        register char   *cp; | 
| 407 | 
  | 
  | 
        int     i; | 
| 408 | 
  | 
  | 
 | 
| 409 | 
  | 
  | 
        npslots = 0; | 
| 410 | 
  | 
  | 
        if (noaction) | 
| 411 | 
  | 
  | 
                return; | 
| 412 | 
  | 
  | 
        for (i = 0; i < vdef(HOST); i++) {      /* add each host */ | 
| 413 | 
  | 
  | 
                dir = uname = NULL; | 
| 414 | 
  | 
  | 
                np = 1; | 
| 415 | 
  | 
  | 
                strcpy(cp=buf, nvalue(HOST, i));        /* copy to buffer */ | 
| 416 | 
  | 
  | 
                cp = sskip(cp);                         /* skip host name */ | 
| 417 | 
  | 
  | 
                while (isspace(*cp)) | 
| 418 | 
  | 
  | 
                        *cp++ = '\0'; | 
| 419 | 
  | 
  | 
                if (*cp) {                              /* has # processes? */ | 
| 420 | 
  | 
  | 
                        np = atoi(cp); | 
| 421 | 
  | 
  | 
                        if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp))) | 
| 422 | 
  | 
  | 
                                badvalue(HOST); | 
| 423 | 
  | 
  | 
                        while (isspace(*cp)) | 
| 424 | 
  | 
  | 
                                cp++; | 
| 425 | 
  | 
  | 
                        if (*cp) {                      /* has directory? */ | 
| 426 | 
  | 
  | 
                                dir = cp; | 
| 427 | 
  | 
  | 
                                cp = sskip(cp);                 /* skip dir. */ | 
| 428 | 
  | 
  | 
                                while (isspace(*cp)) | 
| 429 | 
  | 
  | 
                                        *cp++ = '\0'; | 
| 430 | 
  | 
  | 
                                if (*cp) {                      /* has user? */ | 
| 431 | 
  | 
  | 
                                        uname = cp; | 
| 432 | 
  | 
  | 
                                        if (*sskip(cp)) | 
| 433 | 
  | 
  | 
                                                badvalue(HOST); | 
| 434 | 
  | 
  | 
                                } | 
| 435 | 
  | 
  | 
                        } | 
| 436 | 
  | 
  | 
                } | 
| 437 | 
  | 
  | 
                if (addpserver(buf, dir, uname, np) == NULL) { | 
| 438 | 
  | 
  | 
                        if (!nowarn) | 
| 439 | 
  | 
  | 
                                fprintf(stderr, | 
| 440 | 
  | 
  | 
                                        "%s: cannot execute on host \"%s\"\n", | 
| 441 | 
  | 
  | 
                                                progname, buf); | 
| 442 | 
  | 
  | 
                } else | 
| 443 | 
  | 
  | 
                        npslots += np; | 
| 444 | 
  | 
  | 
        } | 
| 445 | 
  | 
  | 
        if (npslots == 0) { | 
| 446 | 
  | 
  | 
                fprintf(stderr, "%s: no working process servers\n", progname); | 
| 447 | 
  | 
  | 
                quit(1); | 
| 448 | 
  | 
  | 
        } | 
| 449 | 
  | 
  | 
        pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot)); | 
| 450 | 
  | 
  | 
        if (pslot == NULL) { | 
| 451 | 
  | 
  | 
                perror("malloc"); | 
| 452 | 
  | 
  | 
                quit(1); | 
| 453 | 
  | 
  | 
        } | 
| 454 | 
  | 
  | 
} | 
| 455 | 
  | 
  | 
 | 
| 456 | 
  | 
  | 
 | 
| 457 | 
greg | 
2.7 | 
getradfile(rfargs)              /* run rad and get needed variables */ | 
| 458 | 
  | 
  | 
char    *rfargs; | 
| 459 | 
greg | 
2.1 | 
{ | 
| 460 | 
  | 
  | 
        static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; | 
| 461 | 
  | 
  | 
        char    combuf[256]; | 
| 462 | 
  | 
  | 
        register int    i; | 
| 463 | 
  | 
  | 
        register char   *cp; | 
| 464 | 
gregl | 
2.23 | 
        char    *pippt; | 
| 465 | 
greg | 
2.1 | 
                                        /* create rad command */ | 
| 466 | 
  | 
  | 
        sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); | 
| 467 | 
  | 
  | 
        sprintf(combuf, | 
| 468 | 
  | 
  | 
        "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", | 
| 469 | 
greg | 
2.7 | 
                        rfargs, rendopt+2); | 
| 470 | 
greg | 
2.1 | 
        cp = combuf; | 
| 471 | 
gregl | 
2.23 | 
        while (*cp) { | 
| 472 | 
  | 
  | 
                if (*cp == '|') pippt = cp; | 
| 473 | 
  | 
  | 
                cp++; | 
| 474 | 
  | 
  | 
        }                               /* match unset variables */ | 
| 475 | 
greg | 
2.1 | 
        for (i = 0; mvar[i] >= 0; i++) | 
| 476 | 
  | 
  | 
                if (!vdef(mvar[i])) { | 
| 477 | 
  | 
  | 
                        *cp++ = '|'; | 
| 478 | 
  | 
  | 
                        strcpy(cp, vnam(mvar[i])); | 
| 479 | 
  | 
  | 
                        while (*cp) cp++; | 
| 480 | 
gregl | 
2.23 | 
                        pippt = NULL; | 
| 481 | 
greg | 
2.1 | 
                } | 
| 482 | 
gregl | 
2.23 | 
        if (pippt != NULL) | 
| 483 | 
  | 
  | 
                strcpy(pippt, "> /dev/null");   /* nothing to match */ | 
| 484 | 
  | 
  | 
        else { | 
| 485 | 
  | 
  | 
                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); | 
| 486 | 
  | 
  | 
                cp += 11;               /* point to file name */ | 
| 487 | 
  | 
  | 
        } | 
| 488 | 
gwlarson | 
2.28 | 
        system(combuf);                 /* ignore exit code */ | 
| 489 | 
gregl | 
2.23 | 
        if (pippt == NULL) {            /* load variables and remove file */ | 
| 490 | 
  | 
  | 
                loadvars(cp); | 
| 491 | 
  | 
  | 
                unlink(cp); | 
| 492 | 
  | 
  | 
        } | 
| 493 | 
greg | 
2.1 | 
} | 
| 494 | 
  | 
  | 
 | 
| 495 | 
  | 
  | 
 | 
| 496 | 
  | 
  | 
animate()                       /* run animation */ | 
| 497 | 
  | 
  | 
{ | 
| 498 | 
  | 
  | 
        int     xres, yres; | 
| 499 | 
  | 
  | 
        float   pa, mult; | 
| 500 | 
  | 
  | 
        int     frames_batch; | 
| 501 | 
  | 
  | 
        register int    i; | 
| 502 | 
  | 
  | 
        double  d1, d2; | 
| 503 | 
  | 
  | 
                                        /* compute rpict resolution */ | 
| 504 | 
  | 
  | 
        i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa); | 
| 505 | 
  | 
  | 
        mult = vflt(OVERSAMP); | 
| 506 | 
  | 
  | 
        if (i == 3) { | 
| 507 | 
greg | 
2.16 | 
                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres), | 
| 508 | 
greg | 
2.1 | 
                                (int)(mult*yres), pa); | 
| 509 | 
greg | 
2.16 | 
                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa); | 
| 510 | 
greg | 
2.1 | 
        } else if (i) { | 
| 511 | 
  | 
  | 
                if (i == 1) yres = xres; | 
| 512 | 
  | 
  | 
                sprintf(rresopt, "-x %d -y %d", (int)(mult*xres), | 
| 513 | 
  | 
  | 
                                (int)(mult*yres)); | 
| 514 | 
  | 
  | 
                sprintf(fresopt, "-x %d -y %d -pa 1", xres, yres); | 
| 515 | 
  | 
  | 
        } else | 
| 516 | 
  | 
  | 
                badvalue(RESOLUTION); | 
| 517 | 
  | 
  | 
                                        /* consistency checks */ | 
| 518 | 
  | 
  | 
        if (vdef(ANIMATE)) { | 
| 519 | 
  | 
  | 
                if (vint(INTERP)) { | 
| 520 | 
  | 
  | 
                        if (!nowarn) | 
| 521 | 
  | 
  | 
                                fprintf(stderr, | 
| 522 | 
  | 
  | 
                                        "%s: resetting %s=0 for animation\n", | 
| 523 | 
  | 
  | 
                                                progname, vnam(INTERP)); | 
| 524 | 
  | 
  | 
                        vval(INTERP) = "0"; | 
| 525 | 
  | 
  | 
                } | 
| 526 | 
greg | 
2.29 | 
                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */ | 
| 527 | 
greg | 
2.1 | 
                        if (!nowarn) | 
| 528 | 
  | 
  | 
                                fprintf(stderr, | 
| 529 | 
  | 
  | 
                                        "%s: resetting %s=0 for animation\n", | 
| 530 | 
  | 
  | 
                                                progname, vnam(MBLUR)); | 
| 531 | 
  | 
  | 
                        vval(MBLUR) = "0"; | 
| 532 | 
  | 
  | 
                } | 
| 533 | 
  | 
  | 
        } | 
| 534 | 
  | 
  | 
                                        /* figure # frames per batch */ | 
| 535 | 
  | 
  | 
        d1 = mult*xres*mult*yres*4;             /* space for orig. picture */ | 
| 536 | 
greg | 
2.29 | 
        if ((i=vint(INTERP)) || getblur(NULL) > 1) | 
| 537 | 
greg | 
2.13 | 
                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */ | 
| 538 | 
greg | 
2.1 | 
        d2 = xres*yres*4;                       /* space for final picture */ | 
| 539 | 
  | 
  | 
        frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); | 
| 540 | 
  | 
  | 
        if (frames_batch < i+2) { | 
| 541 | 
  | 
  | 
                fprintf(stderr, "%s: insufficient disk space allocated\n", | 
| 542 | 
  | 
  | 
                                progname); | 
| 543 | 
  | 
  | 
                quit(1); | 
| 544 | 
  | 
  | 
        } | 
| 545 | 
greg | 
2.7 | 
                                        /* initialize archive argument list */ | 
| 546 | 
gwlarson | 
2.25 | 
        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; | 
| 547 | 
greg | 
2.7 | 
        arcnext = arcfirst = arcargs + i; | 
| 548 | 
greg | 
2.1 | 
                                        /* initialize status file */ | 
| 549 | 
  | 
  | 
        if (astat.rnext == 0) | 
| 550 | 
  | 
  | 
                astat.rnext = astat.fnext = astat.tnext = vint(START); | 
| 551 | 
  | 
  | 
        putastat(); | 
| 552 | 
  | 
  | 
                                        /* render in batches */ | 
| 553 | 
greg | 
2.2 | 
        while (astat.tnext <= vint(END)) { | 
| 554 | 
greg | 
2.1 | 
                renderframes(frames_batch); | 
| 555 | 
  | 
  | 
                filterframes(); | 
| 556 | 
  | 
  | 
                transferframes(); | 
| 557 | 
  | 
  | 
        } | 
| 558 | 
  | 
  | 
                                        /* mark status as finished */ | 
| 559 | 
  | 
  | 
        astat.pid = 0; | 
| 560 | 
  | 
  | 
        putastat(); | 
| 561 | 
  | 
  | 
                                        /* close open files */ | 
| 562 | 
  | 
  | 
        getview(0); | 
| 563 | 
  | 
  | 
        getexp(0); | 
| 564 | 
  | 
  | 
} | 
| 565 | 
  | 
  | 
 | 
| 566 | 
  | 
  | 
 | 
| 567 | 
  | 
  | 
renderframes(nframes)           /* render next nframes frames */ | 
| 568 | 
  | 
  | 
int     nframes; | 
| 569 | 
  | 
  | 
{ | 
| 570 | 
  | 
  | 
        static char     vendbuf[16]; | 
| 571 | 
  | 
  | 
        VIEW    *vp; | 
| 572 | 
  | 
  | 
        FILE    *fp = NULL; | 
| 573 | 
  | 
  | 
        char    vfname[128]; | 
| 574 | 
  | 
  | 
        int     lastframe; | 
| 575 | 
  | 
  | 
        register int    i; | 
| 576 | 
  | 
  | 
 | 
| 577 | 
  | 
  | 
        if (astat.tnext < astat.rnext)  /* other work to do first */ | 
| 578 | 
  | 
  | 
                return; | 
| 579 | 
  | 
  | 
                                        /* create batch view file */ | 
| 580 | 
  | 
  | 
        if (!vdef(ANIMATE)) { | 
| 581 | 
  | 
  | 
                sprintf(vfname, "%s/anim.vf", vval(DIRECTORY)); | 
| 582 | 
  | 
  | 
                if ((fp = fopen(vfname, "w")) == NULL) { | 
| 583 | 
  | 
  | 
                        perror(vfname); | 
| 584 | 
  | 
  | 
                        quit(1); | 
| 585 | 
  | 
  | 
                } | 
| 586 | 
  | 
  | 
        } | 
| 587 | 
  | 
  | 
                                        /* bound batch properly */ | 
| 588 | 
  | 
  | 
        lastframe = astat.rnext + nframes - 1; | 
| 589 | 
  | 
  | 
        if ((lastframe-1) % (vint(INTERP)+1))   /* need even interval */ | 
| 590 | 
  | 
  | 
                lastframe += vint(INTERP)+1 - ((lastframe-1)%(vint(INTERP)+1)); | 
| 591 | 
  | 
  | 
        if (lastframe > vint(END))              /* check for end */ | 
| 592 | 
  | 
  | 
                lastframe = vint(END); | 
| 593 | 
  | 
  | 
                                        /* render each view */ | 
| 594 | 
  | 
  | 
        for (i = astat.rnext; i <= lastframe; i++) { | 
| 595 | 
  | 
  | 
                if ((vp = getview(i)) == NULL) { | 
| 596 | 
  | 
  | 
                        if (!nowarn) | 
| 597 | 
  | 
  | 
                                fprintf(stderr, | 
| 598 | 
  | 
  | 
                                "%s: ran out of views before last frame\n", | 
| 599 | 
  | 
  | 
                                        progname); | 
| 600 | 
  | 
  | 
                        sprintf(vval(END)=vendbuf, "%d", i-1); | 
| 601 | 
  | 
  | 
                        lastframe = i - 1; | 
| 602 | 
  | 
  | 
                        break; | 
| 603 | 
  | 
  | 
                } | 
| 604 | 
  | 
  | 
                if (vdef(ANIMATE))              /* animate frame */ | 
| 605 | 
  | 
  | 
                        animrend(i, vp); | 
| 606 | 
  | 
  | 
                else {                          /* else record it */ | 
| 607 | 
  | 
  | 
                        fputs(VIEWSTR, fp); | 
| 608 | 
  | 
  | 
                        fprintview(vp, fp); | 
| 609 | 
  | 
  | 
                        putc('\n', fp); | 
| 610 | 
  | 
  | 
                } | 
| 611 | 
  | 
  | 
        } | 
| 612 | 
  | 
  | 
        if (vdef(ANIMATE))              /* wait for renderings to finish */ | 
| 613 | 
greg | 
2.2 | 
                bwait(0); | 
| 614 | 
greg | 
2.1 | 
        else {                          /* else if walk-through */ | 
| 615 | 
  | 
  | 
                fclose(fp);             /* close view file */ | 
| 616 | 
  | 
  | 
                walkwait(astat.rnext, lastframe, vfname);       /* walk it */ | 
| 617 | 
  | 
  | 
                unlink(vfname);         /* remove view file */ | 
| 618 | 
  | 
  | 
        } | 
| 619 | 
  | 
  | 
        astat.rnext = i;                /* update status */ | 
| 620 | 
  | 
  | 
        putastat(); | 
| 621 | 
  | 
  | 
} | 
| 622 | 
  | 
  | 
 | 
| 623 | 
  | 
  | 
 | 
| 624 | 
  | 
  | 
filterframes()                          /* catch up with filtering */ | 
| 625 | 
  | 
  | 
{ | 
| 626 | 
  | 
  | 
        VIEW    *vp; | 
| 627 | 
  | 
  | 
        register int    i; | 
| 628 | 
  | 
  | 
 | 
| 629 | 
  | 
  | 
        if (astat.tnext < astat.fnext)  /* other work to do first */ | 
| 630 | 
  | 
  | 
                return; | 
| 631 | 
  | 
  | 
                                        /* filter each view */ | 
| 632 | 
  | 
  | 
        for (i = astat.fnext; i < astat.rnext; i++) { | 
| 633 | 
  | 
  | 
                if ((vp = getview(i)) == NULL) {        /* get view i */ | 
| 634 | 
  | 
  | 
                        fprintf(stderr, | 
| 635 | 
  | 
  | 
                        "%s: unexpected error reading view for frame %d\n", | 
| 636 | 
  | 
  | 
                                        progname, i); | 
| 637 | 
  | 
  | 
                        quit(1); | 
| 638 | 
  | 
  | 
                } | 
| 639 | 
greg | 
2.2 | 
                dofilt(i, vp, getexp(i), 0);            /* filter frame */ | 
| 640 | 
greg | 
2.1 | 
        } | 
| 641 | 
greg | 
2.2 | 
        bwait(0);                       /* wait for filter processes */ | 
| 642 | 
greg | 
2.7 | 
        archive();                      /* archive originals */ | 
| 643 | 
greg | 
2.1 | 
        astat.fnext = i;                /* update status */ | 
| 644 | 
  | 
  | 
        putastat(); | 
| 645 | 
  | 
  | 
} | 
| 646 | 
  | 
  | 
 | 
| 647 | 
  | 
  | 
 | 
| 648 | 
  | 
  | 
transferframes()                        /* catch up with picture transfers */ | 
| 649 | 
  | 
  | 
{ | 
| 650 | 
gwlarson | 
2.25 | 
        char    combuf[10240], *fbase; | 
| 651 | 
greg | 
2.1 | 
        register char   *cp; | 
| 652 | 
  | 
  | 
        register int    i; | 
| 653 | 
  | 
  | 
 | 
| 654 | 
  | 
  | 
        if (astat.tnext >= astat.fnext) /* nothing to do, yet */ | 
| 655 | 
  | 
  | 
                return; | 
| 656 | 
  | 
  | 
        if (!vdef(TRANSFER)) {          /* no transfer function -- leave 'em */ | 
| 657 | 
  | 
  | 
                astat.tnext = astat.fnext; | 
| 658 | 
  | 
  | 
                putastat();             /* update status */ | 
| 659 | 
  | 
  | 
                return; | 
| 660 | 
  | 
  | 
        } | 
| 661 | 
gwlarson | 
2.25 | 
        strcpy(combuf, "cd ");          /* start transfer command */ | 
| 662 | 
  | 
  | 
        fbase = dirfile(cp = combuf+3, vval(BASENAME)); | 
| 663 | 
  | 
  | 
        if (*cp) { | 
| 664 | 
  | 
  | 
                while (*++cp) ; | 
| 665 | 
  | 
  | 
                *cp++ = ';'; *cp++ = ' '; | 
| 666 | 
  | 
  | 
        } else | 
| 667 | 
  | 
  | 
                cp = combuf; | 
| 668 | 
  | 
  | 
        strcpy(cp, vval(TRANSFER)); | 
| 669 | 
  | 
  | 
        while (*cp) cp++; | 
| 670 | 
greg | 
2.1 | 
                                        /* make argument list */ | 
| 671 | 
  | 
  | 
        for (i = astat.tnext; i < astat.fnext; i++) { | 
| 672 | 
  | 
  | 
                *cp++ = ' '; | 
| 673 | 
gwlarson | 
2.25 | 
                sprintf(cp, fbase, i); | 
| 674 | 
greg | 
2.1 | 
                while (*cp) cp++; | 
| 675 | 
  | 
  | 
                strcpy(cp, ".pic"); | 
| 676 | 
  | 
  | 
                cp += 4; | 
| 677 | 
  | 
  | 
        } | 
| 678 | 
  | 
  | 
        if (runcom(combuf)) {           /* transfer frames */ | 
| 679 | 
  | 
  | 
                fprintf(stderr, "%s: error running transfer command\n", | 
| 680 | 
  | 
  | 
                                progname); | 
| 681 | 
  | 
  | 
                quit(1); | 
| 682 | 
  | 
  | 
        } | 
| 683 | 
  | 
  | 
        astat.tnext = i;                /* update status */ | 
| 684 | 
  | 
  | 
        putastat(); | 
| 685 | 
  | 
  | 
} | 
| 686 | 
  | 
  | 
 | 
| 687 | 
  | 
  | 
 | 
| 688 | 
  | 
  | 
animrend(frame, vp)                     /* start animation frame */ | 
| 689 | 
  | 
  | 
int     frame; | 
| 690 | 
  | 
  | 
VIEW    *vp; | 
| 691 | 
  | 
  | 
{ | 
| 692 | 
greg | 
2.2 | 
        extern int      recover(); | 
| 693 | 
greg | 
2.1 | 
        char    combuf[2048]; | 
| 694 | 
  | 
  | 
        char    fname[128]; | 
| 695 | 
  | 
  | 
 | 
| 696 | 
  | 
  | 
        sprintf(fname, vval(BASENAME), frame); | 
| 697 | 
  | 
  | 
        strcat(fname, ".unf"); | 
| 698 | 
  | 
  | 
        if (access(fname, F_OK) == 0) | 
| 699 | 
  | 
  | 
                return; | 
| 700 | 
greg | 
2.2 | 
        sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame, | 
| 701 | 
greg | 
2.1 | 
                        rendopt, viewopt(vp), rresopt, fname); | 
| 702 | 
greg | 
2.2 | 
        bruncom(combuf, frame, recover);        /* run in background */ | 
| 703 | 
greg | 
2.1 | 
} | 
| 704 | 
  | 
  | 
 | 
| 705 | 
  | 
  | 
 | 
| 706 | 
  | 
  | 
walkwait(first, last, vfn)              /* walk-through frames */ | 
| 707 | 
  | 
  | 
int     first, last; | 
| 708 | 
  | 
  | 
char    *vfn; | 
| 709 | 
  | 
  | 
{ | 
| 710 | 
greg | 
2.29 | 
        double  blurf; | 
| 711 | 
  | 
  | 
        int     nblur = getblur(&blurf); | 
| 712 | 
greg | 
2.1 | 
        char    combuf[2048]; | 
| 713 | 
greg | 
2.29 | 
        register char   *inspoint; | 
| 714 | 
greg | 
2.1 | 
        register int    i; | 
| 715 | 
  | 
  | 
 | 
| 716 | 
  | 
  | 
        if (!noaction && vint(INTERP))          /* create dummy frames */ | 
| 717 | 
  | 
  | 
                for (i = first; i <= last; i++) | 
| 718 | 
  | 
  | 
                        if (i < vint(END) && (i-1) % (vint(INTERP)+1)) { | 
| 719 | 
  | 
  | 
                                sprintf(combuf, vval(BASENAME), i); | 
| 720 | 
  | 
  | 
                                strcat(combuf, ".unf"); | 
| 721 | 
  | 
  | 
                                close(open(combuf, O_RDONLY|O_CREAT, 0666)); | 
| 722 | 
  | 
  | 
                        } | 
| 723 | 
  | 
  | 
                                        /* create command */ | 
| 724 | 
greg | 
2.35 | 
        sprintf(combuf, "rpict%s%s -w0", rendopt, | 
| 725 | 
  | 
  | 
                        viewopt(getview(first>1 ? first-1 : 1))); | 
| 726 | 
greg | 
2.29 | 
        inspoint = combuf; | 
| 727 | 
  | 
  | 
        while (*inspoint) inspoint++; | 
| 728 | 
  | 
  | 
        if (nblur) { | 
| 729 | 
  | 
  | 
                sprintf(inspoint, " -pm %.3f", blurf/nblur); | 
| 730 | 
  | 
  | 
                while (*inspoint) inspoint++; | 
| 731 | 
  | 
  | 
        } | 
| 732 | 
  | 
  | 
        if (nblur > 1 || vint(INTERP)) { | 
| 733 | 
  | 
  | 
                sprintf(inspoint, " -z %s.zbf", vval(BASENAME)); | 
| 734 | 
  | 
  | 
                while (*inspoint) inspoint++; | 
| 735 | 
  | 
  | 
        } | 
| 736 | 
  | 
  | 
        sprintf(inspoint, " -o %s.unf %s -S %d", | 
| 737 | 
greg | 
2.4 | 
                        vval(BASENAME), rresopt, first); | 
| 738 | 
greg | 
2.29 | 
        while (*inspoint) inspoint++; | 
| 739 | 
greg | 
2.4 | 
        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); | 
| 740 | 
greg | 
2.2 | 
                                        /* run in parallel */ | 
| 741 | 
greg | 
2.7 | 
        i = (last-first+1)/(vint(INTERP)+1); | 
| 742 | 
  | 
  | 
        if (i < 1) i = 1; | 
| 743 | 
  | 
  | 
        if (pruncom(combuf, inspoint, i)) { | 
| 744 | 
greg | 
2.2 | 
                fprintf(stderr, "%s: error rendering frames %d through %d\n", | 
| 745 | 
greg | 
2.1 | 
                                progname, first, last); | 
| 746 | 
  | 
  | 
                quit(1); | 
| 747 | 
  | 
  | 
        } | 
| 748 | 
  | 
  | 
        if (!noaction && vint(INTERP))          /* remove dummy frames */ | 
| 749 | 
  | 
  | 
                for (i = first; i <= last; i++) | 
| 750 | 
  | 
  | 
                        if (i < vint(END) && (i-1) % (vint(INTERP)+1)) { | 
| 751 | 
  | 
  | 
                                sprintf(combuf, vval(BASENAME), i); | 
| 752 | 
  | 
  | 
                                strcat(combuf, ".unf"); | 
| 753 | 
  | 
  | 
                                unlink(combuf); | 
| 754 | 
  | 
  | 
                        } | 
| 755 | 
  | 
  | 
} | 
| 756 | 
  | 
  | 
 | 
| 757 | 
  | 
  | 
 | 
| 758 | 
greg | 
2.2 | 
int | 
| 759 | 
greg | 
2.1 | 
recover(frame)                          /* recover the specified frame */ | 
| 760 | 
  | 
  | 
int     frame; | 
| 761 | 
  | 
  | 
{ | 
| 762 | 
greg | 
2.2 | 
        static int      *rfrm;          /* list of recovered frames */ | 
| 763 | 
  | 
  | 
        static int      nrfrms = 0; | 
| 764 | 
greg | 
2.29 | 
        double  blurf; | 
| 765 | 
  | 
  | 
        int     nblur = getblur(&blurf); | 
| 766 | 
greg | 
2.1 | 
        char    combuf[2048]; | 
| 767 | 
  | 
  | 
        char    fname[128]; | 
| 768 | 
  | 
  | 
        register char   *cp; | 
| 769 | 
greg | 
2.2 | 
        register int    i; | 
| 770 | 
  | 
  | 
                                        /* check to see if recovered already */ | 
| 771 | 
  | 
  | 
        for (i = nrfrms; i--; ) | 
| 772 | 
  | 
  | 
                if (rfrm[i] == frame) | 
| 773 | 
  | 
  | 
                        return(0); | 
| 774 | 
  | 
  | 
                                        /* build command */ | 
| 775 | 
greg | 
2.1 | 
        sprintf(fname, vval(BASENAME), frame); | 
| 776 | 
  | 
  | 
        if (vdef(ANIMATE)) | 
| 777 | 
greg | 
2.2 | 
                sprintf(combuf, "%s %d | rpict%s -w0", | 
| 778 | 
greg | 
2.1 | 
                                vval(ANIMATE), frame, rendopt); | 
| 779 | 
  | 
  | 
        else | 
| 780 | 
greg | 
2.2 | 
                sprintf(combuf, "rpict%s -w0", rendopt); | 
| 781 | 
greg | 
2.29 | 
        cp = combuf; | 
| 782 | 
  | 
  | 
        while (*cp) cp++; | 
| 783 | 
  | 
  | 
        if (nblur) { | 
| 784 | 
  | 
  | 
                sprintf(cp, " -pm %.3f", blurf/nblur); | 
| 785 | 
  | 
  | 
                while (*cp) cp++; | 
| 786 | 
  | 
  | 
        } | 
| 787 | 
  | 
  | 
        if (nblur > 1 || vint(INTERP)) { | 
| 788 | 
greg | 
2.1 | 
                sprintf(cp, " -z %s.zbf", fname); | 
| 789 | 
  | 
  | 
                while (*cp) cp++; | 
| 790 | 
  | 
  | 
        } | 
| 791 | 
  | 
  | 
        sprintf(cp, " -ro %s.unf", fname); | 
| 792 | 
  | 
  | 
        while (*cp) cp++; | 
| 793 | 
  | 
  | 
        if (!vdef(ANIMATE)) { | 
| 794 | 
  | 
  | 
                *cp++ = ' '; | 
| 795 | 
  | 
  | 
                strcpy(cp, vval(OCTREE)); | 
| 796 | 
  | 
  | 
        } | 
| 797 | 
greg | 
2.2 | 
        if (runcom(combuf))             /* run command */ | 
| 798 | 
  | 
  | 
                return(1); | 
| 799 | 
  | 
  | 
                                        /* add frame to recovered list */ | 
| 800 | 
  | 
  | 
        if (nrfrms) | 
| 801 | 
greg | 
2.32 | 
                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int)); | 
| 802 | 
greg | 
2.2 | 
        else | 
| 803 | 
  | 
  | 
                rfrm = (int *)malloc(sizeof(int)); | 
| 804 | 
  | 
  | 
        if (rfrm == NULL) { | 
| 805 | 
  | 
  | 
                perror("malloc"); | 
| 806 | 
greg | 
2.1 | 
                quit(1); | 
| 807 | 
  | 
  | 
        } | 
| 808 | 
greg | 
2.2 | 
        rfrm[nrfrms++] = frame; | 
| 809 | 
  | 
  | 
        return(0); | 
| 810 | 
greg | 
2.1 | 
} | 
| 811 | 
  | 
  | 
 | 
| 812 | 
  | 
  | 
 | 
| 813 | 
greg | 
2.2 | 
int | 
| 814 | 
  | 
  | 
frecover(frame)                         /* recover filtered frame */ | 
| 815 | 
  | 
  | 
int     frame; | 
| 816 | 
  | 
  | 
{ | 
| 817 | 
  | 
  | 
        VIEW    *vp; | 
| 818 | 
  | 
  | 
        char    *ex; | 
| 819 | 
  | 
  | 
 | 
| 820 | 
  | 
  | 
        vp = getview(frame); | 
| 821 | 
  | 
  | 
        ex = getexp(frame); | 
| 822 | 
  | 
  | 
        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) | 
| 823 | 
  | 
  | 
                return(1); | 
| 824 | 
  | 
  | 
        return(0); | 
| 825 | 
  | 
  | 
} | 
| 826 | 
  | 
  | 
 | 
| 827 | 
  | 
  | 
 | 
| 828 | 
greg | 
2.7 | 
archive()                       /* archive and remove renderings */ | 
| 829 | 
greg | 
2.1 | 
{ | 
| 830 | 
greg | 
2.2 | 
#define RMCOML  (sizeof(rmcom)-1) | 
| 831 | 
  | 
  | 
        static char     rmcom[] = "rm -f"; | 
| 832 | 
gwlarson | 
2.25 | 
        char    basedir[128]; | 
| 833 | 
  | 
  | 
        int     dlen, alen; | 
| 834 | 
  | 
  | 
        register int    j; | 
| 835 | 
greg | 
2.1 | 
 | 
| 836 | 
greg | 
2.7 | 
        if (arcnext == arcfirst) | 
| 837 | 
  | 
  | 
                return;                         /* nothing to do */ | 
| 838 | 
gwlarson | 
2.25 | 
        dirfile(basedir, vval(BASENAME)); | 
| 839 | 
  | 
  | 
        dlen = strlen(basedir); | 
| 840 | 
greg | 
2.2 | 
        if (vdef(ARCHIVE)) {                    /* run archive command */ | 
| 841 | 
gwlarson | 
2.25 | 
                alen = strlen(vval(ARCHIVE)); | 
| 842 | 
  | 
  | 
                if (dlen) { | 
| 843 | 
  | 
  | 
                        j = alen + dlen + 5; | 
| 844 | 
  | 
  | 
                        strncpy(arcfirst-j, "cd ", 3); | 
| 845 | 
  | 
  | 
                        strncpy(arcfirst-j+3, basedir, dlen); | 
| 846 | 
  | 
  | 
                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; | 
| 847 | 
  | 
  | 
                } else | 
| 848 | 
  | 
  | 
                        j = alen; | 
| 849 | 
  | 
  | 
                strncpy(arcfirst-alen, vval(ARCHIVE), alen); | 
| 850 | 
  | 
  | 
                if (runcom(arcfirst-j)) { | 
| 851 | 
greg | 
2.7 | 
                        fprintf(stderr, "%s: error running archive command\n", | 
| 852 | 
  | 
  | 
                                        progname); | 
| 853 | 
greg | 
2.2 | 
                        quit(1); | 
| 854 | 
  | 
  | 
                } | 
| 855 | 
greg | 
2.1 | 
        } | 
| 856 | 
gwlarson | 
2.25 | 
        if (dlen) { | 
| 857 | 
  | 
  | 
                j = RMCOML + dlen + 5; | 
| 858 | 
  | 
  | 
                strncpy(arcfirst-j, "cd ", 3); | 
| 859 | 
  | 
  | 
                strncpy(arcfirst-j+3, basedir, dlen); | 
| 860 | 
  | 
  | 
                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; | 
| 861 | 
  | 
  | 
        } else | 
| 862 | 
  | 
  | 
                j = RMCOML; | 
| 863 | 
greg | 
2.2 | 
                                                /* run remove command */ | 
| 864 | 
greg | 
2.7 | 
        strncpy(arcfirst-RMCOML, rmcom, RMCOML); | 
| 865 | 
gwlarson | 
2.25 | 
        runcom(arcfirst-j); | 
| 866 | 
greg | 
2.7 | 
        arcnext = arcfirst;                     /* reset argument list */ | 
| 867 | 
greg | 
2.2 | 
#undef RMCOML | 
| 868 | 
greg | 
2.1 | 
} | 
| 869 | 
  | 
  | 
 | 
| 870 | 
  | 
  | 
 | 
| 871 | 
greg | 
2.2 | 
int | 
| 872 | 
  | 
  | 
dofilt(frame, vp, ep, rvr)                      /* filter frame */ | 
| 873 | 
greg | 
2.1 | 
int     frame; | 
| 874 | 
  | 
  | 
VIEW    *vp; | 
| 875 | 
  | 
  | 
char    *ep; | 
| 876 | 
greg | 
2.2 | 
int     rvr; | 
| 877 | 
greg | 
2.1 | 
{ | 
| 878 | 
greg | 
2.2 | 
        extern int      frecover(); | 
| 879 | 
greg | 
2.6 | 
        static int      iter = 0; | 
| 880 | 
greg | 
2.29 | 
        double  blurf; | 
| 881 | 
  | 
  | 
        int     nblur = getblur(&blurf); | 
| 882 | 
gwlarson | 
2.25 | 
        char    fnbefore[128], fnafter[128], *fbase; | 
| 883 | 
greg | 
2.6 | 
        char    combuf[1024], fname0[128], fname1[128]; | 
| 884 | 
greg | 
2.7 | 
        int     usepinterp, usepfilt, nora_rgbe; | 
| 885 | 
greg | 
2.2 | 
        int     frseq[2]; | 
| 886 | 
greg | 
2.1 | 
                                                /* check what is needed */ | 
| 887 | 
greg | 
2.29 | 
        usepinterp = (nblur > 1); | 
| 888 | 
greg | 
2.1 | 
        usepfilt = pfiltalways | ep==NULL; | 
| 889 | 
greg | 
2.7 | 
        if (ep != NULL && !strcmp(ep, "1")) | 
| 890 | 
  | 
  | 
                ep = "+0"; | 
| 891 | 
  | 
  | 
        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || | 
| 892 | 
  | 
  | 
                        *ep != '+' || *ep != '-' || !isint(ep); | 
| 893 | 
greg | 
2.1 | 
                                                /* compute rendered views */ | 
| 894 | 
greg | 
2.2 | 
        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); | 
| 895 | 
  | 
  | 
        frseq[1] = frseq[0] + vint(INTERP) + 1; | 
| 896 | 
gwlarson | 
2.25 | 
        fbase = dirfile(NULL, vval(BASENAME)); | 
| 897 | 
greg | 
2.2 | 
        if (frseq[1] > vint(END)) | 
| 898 | 
  | 
  | 
                frseq[1] = vint(END); | 
| 899 | 
  | 
  | 
        if (frseq[1] == frame) {                        /* pfilt only */ | 
| 900 | 
  | 
  | 
                frseq[0] = frseq[1]; | 
| 901 | 
greg | 
2.1 | 
                usepinterp = 0;                 /* update what's needed */ | 
| 902 | 
greg | 
2.7 | 
                usepfilt |= nora_rgbe; | 
| 903 | 
  | 
  | 
        } else if (frseq[0] == frame) {         /* no interpolation needed */ | 
| 904 | 
  | 
  | 
                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */ | 
| 905 | 
  | 
  | 
                        *arcnext++ = ' '; | 
| 906 | 
gwlarson | 
2.25 | 
                        sprintf(arcnext, fbase, frame-vint(INTERP)-1); | 
| 907 | 
greg | 
2.7 | 
                        while (*arcnext) arcnext++; | 
| 908 | 
  | 
  | 
                        strcpy(arcnext, ".unf"); | 
| 909 | 
  | 
  | 
                        arcnext += 4; | 
| 910 | 
greg | 
2.13 | 
                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */ | 
| 911 | 
greg | 
2.7 | 
                                *arcnext++ = ' '; | 
| 912 | 
gwlarson | 
2.25 | 
                                sprintf(arcnext, fbase, frame-vint(INTERP)-1); | 
| 913 | 
greg | 
2.7 | 
                                while (*arcnext) arcnext++; | 
| 914 | 
  | 
  | 
                                strcpy(arcnext, ".zbf"); | 
| 915 | 
  | 
  | 
                                arcnext += 4; | 
| 916 | 
  | 
  | 
                        } | 
| 917 | 
  | 
  | 
                } | 
| 918 | 
  | 
  | 
                if (!usepinterp)                /* update what's needed */ | 
| 919 | 
  | 
  | 
                        usepfilt |= nora_rgbe; | 
| 920 | 
greg | 
2.2 | 
        } else                                  /* interpolation needed */ | 
| 921 | 
greg | 
2.1 | 
                usepinterp++; | 
| 922 | 
greg | 
2.2 | 
        if (frseq[1] >= astat.rnext)            /* next batch unavailable */ | 
| 923 | 
  | 
  | 
                frseq[1] = frseq[0]; | 
| 924 | 
  | 
  | 
        sprintf(fnbefore, vval(BASENAME), frseq[0]); | 
| 925 | 
  | 
  | 
        sprintf(fnafter, vval(BASENAME), frseq[1]); | 
| 926 | 
  | 
  | 
        if (rvr == 1 && recover(frseq[0]))      /* recover before frame? */ | 
| 927 | 
  | 
  | 
                return(1); | 
| 928 | 
  | 
  | 
                                                /* generate command */ | 
| 929 | 
greg | 
2.1 | 
        if (usepinterp) {                       /* using pinterp */ | 
| 930 | 
greg | 
2.2 | 
                if (rvr == 2 && recover(frseq[1]))      /* recover after? */ | 
| 931 | 
  | 
  | 
                        return(1); | 
| 932 | 
greg | 
2.29 | 
                if (nblur > 1) {                /* with pmblur */ | 
| 933 | 
greg | 
2.6 | 
                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), | 
| 934 | 
  | 
  | 
                                        'a'+(iter%26)); | 
| 935 | 
  | 
  | 
                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), | 
| 936 | 
  | 
  | 
                                        'a'+(iter%26)); | 
| 937 | 
gwlarson | 
2.25 | 
                        if (!noaction) { | 
| 938 | 
  | 
  | 
                                FILE    *fp;            /* motion blurring */ | 
| 939 | 
  | 
  | 
                                if ((fp = fopen(fname0, "w")) == NULL) { | 
| 940 | 
  | 
  | 
                                        perror(fname0); quit(1); | 
| 941 | 
  | 
  | 
                                } | 
| 942 | 
  | 
  | 
                                fputs(VIEWSTR, fp); | 
| 943 | 
  | 
  | 
                                fprintview(vp, fp); | 
| 944 | 
  | 
  | 
                                putc('\n', fp); fclose(fp); | 
| 945 | 
  | 
  | 
                                if ((vp = getview(frame+1)) == NULL) { | 
| 946 | 
  | 
  | 
                                        fprintf(stderr, | 
| 947 | 
  | 
  | 
                        "%s: unexpected error reading view for frame %d\n", | 
| 948 | 
  | 
  | 
                                                        progname, frame+1); | 
| 949 | 
  | 
  | 
                                        quit(1); | 
| 950 | 
  | 
  | 
                                } | 
| 951 | 
  | 
  | 
                                if ((fp = fopen(fname1, "w")) == NULL) { | 
| 952 | 
  | 
  | 
                                        perror(fname1); quit(1); | 
| 953 | 
  | 
  | 
                                } | 
| 954 | 
  | 
  | 
                                fputs(VIEWSTR, fp); | 
| 955 | 
  | 
  | 
                                fprintview(vp, fp); | 
| 956 | 
  | 
  | 
                                putc('\n', fp); fclose(fp); | 
| 957 | 
greg | 
2.1 | 
                        } | 
| 958 | 
  | 
  | 
                        sprintf(combuf, | 
| 959 | 
greg | 
2.30 | 
                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", | 
| 960 | 
greg | 
2.29 | 
                                        blurf, nblur, | 
| 961 | 
greg | 
2.6 | 
                                        fname0, fname1, fname0, fname1); | 
| 962 | 
  | 
  | 
                        iter++; | 
| 963 | 
greg | 
2.1 | 
                } else                          /* no blurring */ | 
| 964 | 
  | 
  | 
                        strcpy(combuf, "pinterp"); | 
| 965 | 
  | 
  | 
                strcat(combuf, viewopt(vp)); | 
| 966 | 
  | 
  | 
                if (vbool(RTRACE)) | 
| 967 | 
greg | 
2.2 | 
                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", | 
| 968 | 
greg | 
2.21 | 
                                        rendopt+1, vval(OCTREE)); | 
| 969 | 
greg | 
2.1 | 
                if (vdef(PINTERP)) | 
| 970 | 
  | 
  | 
                        sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); | 
| 971 | 
  | 
  | 
                if (usepfilt) | 
| 972 | 
  | 
  | 
                        sprintf(combuf+strlen(combuf), " %s", rresopt); | 
| 973 | 
  | 
  | 
                else | 
| 974 | 
greg | 
2.33 | 
                        sprintf(combuf+strlen(combuf), " -a %s -e %s", | 
| 975 | 
greg | 
2.1 | 
                                        fresopt, ep); | 
| 976 | 
  | 
  | 
                sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", | 
| 977 | 
  | 
  | 
                                fnbefore, fnbefore); | 
| 978 | 
greg | 
2.2 | 
                if (frseq[1] != frseq[0]) | 
| 979 | 
greg | 
2.1 | 
                         sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", | 
| 980 | 
  | 
  | 
                                        fnafter, fnafter); | 
| 981 | 
  | 
  | 
                if (usepfilt) {                 /* also pfilt */ | 
| 982 | 
  | 
  | 
                        if (vdef(PFILT)) | 
| 983 | 
  | 
  | 
                                sprintf(combuf+strlen(combuf), " | pfilt %s", | 
| 984 | 
  | 
  | 
                                                vval(PFILT)); | 
| 985 | 
  | 
  | 
                        else | 
| 986 | 
  | 
  | 
                                strcat(combuf, " | pfilt"); | 
| 987 | 
  | 
  | 
                        if (ep != NULL) | 
| 988 | 
  | 
  | 
                                sprintf(combuf+strlen(combuf), " -1 -e %s %s", | 
| 989 | 
  | 
  | 
                                                ep, fresopt); | 
| 990 | 
  | 
  | 
                        else | 
| 991 | 
  | 
  | 
                                sprintf(combuf+strlen(combuf), " %s", fresopt); | 
| 992 | 
  | 
  | 
                } | 
| 993 | 
  | 
  | 
        } else if (usepfilt) {                  /* pfilt only */ | 
| 994 | 
greg | 
2.2 | 
                if (rvr == 2) | 
| 995 | 
  | 
  | 
                        return(1); | 
| 996 | 
greg | 
2.1 | 
                if (vdef(PFILT)) | 
| 997 | 
  | 
  | 
                        sprintf(combuf, "pfilt %s", vval(PFILT)); | 
| 998 | 
  | 
  | 
                else | 
| 999 | 
  | 
  | 
                        strcpy(combuf, "pfilt"); | 
| 1000 | 
  | 
  | 
                if (ep != NULL) | 
| 1001 | 
  | 
  | 
                        sprintf(combuf+strlen(combuf), " -1 -e %s %s %s.unf", | 
| 1002 | 
  | 
  | 
                                ep, fresopt, fnbefore); | 
| 1003 | 
  | 
  | 
                else | 
| 1004 | 
  | 
  | 
                        sprintf(combuf+strlen(combuf), " %s %s.unf", | 
| 1005 | 
  | 
  | 
                                        fresopt, fnbefore); | 
| 1006 | 
  | 
  | 
        } else {                                /* else just check it */ | 
| 1007 | 
greg | 
2.2 | 
                if (rvr == 2) | 
| 1008 | 
  | 
  | 
                        return(1); | 
| 1009 | 
greg | 
2.7 | 
                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); | 
| 1010 | 
greg | 
2.1 | 
        } | 
| 1011 | 
  | 
  | 
                                                /* output file name */ | 
| 1012 | 
greg | 
2.6 | 
        sprintf(fname0, vval(BASENAME), frame); | 
| 1013 | 
  | 
  | 
        sprintf(combuf+strlen(combuf), " > %s.pic", fname0); | 
| 1014 | 
greg | 
2.2 | 
        if (rvr)                                /* in recovery */ | 
| 1015 | 
  | 
  | 
                return(runcom(combuf)); | 
| 1016 | 
  | 
  | 
        bruncom(combuf, frame, frecover);       /* else run in background */ | 
| 1017 | 
  | 
  | 
        return(0); | 
| 1018 | 
greg | 
2.1 | 
} | 
| 1019 | 
  | 
  | 
 | 
| 1020 | 
  | 
  | 
 | 
| 1021 | 
  | 
  | 
VIEW * | 
| 1022 | 
  | 
  | 
getview(n)                      /* get view number n */ | 
| 1023 | 
  | 
  | 
int     n; | 
| 1024 | 
  | 
  | 
{ | 
| 1025 | 
  | 
  | 
        static FILE     *viewfp = NULL;         /* view file pointer */ | 
| 1026 | 
  | 
  | 
        static int      viewnum = 0;            /* current view number */ | 
| 1027 | 
  | 
  | 
        static VIEW     curview = STDVIEW;      /* current view */ | 
| 1028 | 
  | 
  | 
        char    linebuf[256]; | 
| 1029 | 
  | 
  | 
 | 
| 1030 | 
  | 
  | 
        if (n == 0) {                   /* signal to close file and clean up */ | 
| 1031 | 
  | 
  | 
                if (viewfp != NULL) { | 
| 1032 | 
  | 
  | 
                        fclose(viewfp); | 
| 1033 | 
  | 
  | 
                        viewfp = NULL; | 
| 1034 | 
  | 
  | 
                        viewnum = 0; | 
| 1035 | 
  | 
  | 
                        copystruct(&curview, &stdview); | 
| 1036 | 
  | 
  | 
                } | 
| 1037 | 
  | 
  | 
                return(NULL); | 
| 1038 | 
  | 
  | 
        } | 
| 1039 | 
gwlarson | 
2.24 | 
        if (viewfp == NULL) {                   /* open file */ | 
| 1040 | 
greg | 
2.1 | 
                if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { | 
| 1041 | 
  | 
  | 
                        perror(vval(VIEWFILE)); | 
| 1042 | 
  | 
  | 
                        quit(1); | 
| 1043 | 
  | 
  | 
                } | 
| 1044 | 
gwlarson | 
2.24 | 
        } else if (n > 0 && n < viewnum) {      /* rewind file */ | 
| 1045 | 
greg | 
2.8 | 
                if (viewnum == 1 && feof(viewfp)) | 
| 1046 | 
  | 
  | 
                        return(&curview);               /* just one view */ | 
| 1047 | 
greg | 
2.1 | 
                if (fseek(viewfp, 0L, 0) == EOF) { | 
| 1048 | 
  | 
  | 
                        perror(vval(VIEWFILE)); | 
| 1049 | 
  | 
  | 
                        quit(1); | 
| 1050 | 
  | 
  | 
                } | 
| 1051 | 
  | 
  | 
                copystruct(&curview, &stdview); | 
| 1052 | 
  | 
  | 
                viewnum = 0; | 
| 1053 | 
  | 
  | 
        } | 
| 1054 | 
gwlarson | 
2.24 | 
        if (n < 0) {                            /* get next view */ | 
| 1055 | 
  | 
  | 
                register int    c = getc(viewfp); | 
| 1056 | 
  | 
  | 
                if (c == EOF) | 
| 1057 | 
  | 
  | 
                        return((VIEW *)NULL);           /* that's it */ | 
| 1058 | 
  | 
  | 
                ungetc(c, viewfp); | 
| 1059 | 
  | 
  | 
                n = viewnum + 1; | 
| 1060 | 
  | 
  | 
        } | 
| 1061 | 
greg | 
2.1 | 
        while (n > viewnum) {           /* scan to desired view */ | 
| 1062 | 
  | 
  | 
                if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) | 
| 1063 | 
greg | 
2.15 | 
                        return(viewnum==1 ? &curview : (VIEW *)NULL); | 
| 1064 | 
greg | 
2.1 | 
                if (isview(linebuf) && sscanview(&curview, linebuf) > 0) | 
| 1065 | 
  | 
  | 
                        viewnum++; | 
| 1066 | 
  | 
  | 
        } | 
| 1067 | 
  | 
  | 
        return(&curview);               /* return it */ | 
| 1068 | 
  | 
  | 
} | 
| 1069 | 
  | 
  | 
 | 
| 1070 | 
  | 
  | 
 | 
| 1071 | 
  | 
  | 
int | 
| 1072 | 
  | 
  | 
countviews()                    /* count views in view file */ | 
| 1073 | 
  | 
  | 
{ | 
| 1074 | 
gwlarson | 
2.24 | 
        int     n; | 
| 1075 | 
greg | 
2.1 | 
 | 
| 1076 | 
gwlarson | 
2.24 | 
        if (getview(n=1) == NULL) | 
| 1077 | 
  | 
  | 
                return(0); | 
| 1078 | 
  | 
  | 
        while (getview(-1) != NULL) | 
| 1079 | 
greg | 
2.1 | 
                n++; | 
| 1080 | 
  | 
  | 
        return(n); | 
| 1081 | 
  | 
  | 
} | 
| 1082 | 
  | 
  | 
 | 
| 1083 | 
  | 
  | 
 | 
| 1084 | 
  | 
  | 
char * | 
| 1085 | 
  | 
  | 
getexp(n)                       /* get exposure for nth frame */ | 
| 1086 | 
  | 
  | 
int     n; | 
| 1087 | 
  | 
  | 
{ | 
| 1088 | 
  | 
  | 
        extern char     *fskip(); | 
| 1089 | 
  | 
  | 
        static char     expval[32]; | 
| 1090 | 
  | 
  | 
        static FILE     *expfp = NULL; | 
| 1091 | 
  | 
  | 
        static long     *exppos; | 
| 1092 | 
  | 
  | 
        static int      curfrm; | 
| 1093 | 
  | 
  | 
        register char   *cp; | 
| 1094 | 
  | 
  | 
 | 
| 1095 | 
  | 
  | 
        if (n == 0) {                           /* signal to close file */ | 
| 1096 | 
  | 
  | 
                if (expfp != NULL) { | 
| 1097 | 
  | 
  | 
                        fclose(expfp); | 
| 1098 | 
greg | 
2.29 | 
                        free((void *)exppos); | 
| 1099 | 
greg | 
2.1 | 
                        expfp = NULL; | 
| 1100 | 
  | 
  | 
                } | 
| 1101 | 
  | 
  | 
                return(NULL); | 
| 1102 | 
greg | 
2.14 | 
        } else if (n > vint(END))               /* request past end (error?) */ | 
| 1103 | 
  | 
  | 
                return(NULL); | 
| 1104 | 
greg | 
2.1 | 
        if (!vdef(EXPOSURE))                    /* no setting (auto) */ | 
| 1105 | 
  | 
  | 
                return(NULL); | 
| 1106 | 
  | 
  | 
        if (isflt(vval(EXPOSURE)))              /* always the same */ | 
| 1107 | 
  | 
  | 
                return(vval(EXPOSURE)); | 
| 1108 | 
  | 
  | 
        if (expfp == NULL) {                    /* open exposure file */ | 
| 1109 | 
  | 
  | 
                if ((expfp = fopen(vval(EXPOSURE), "r")) == NULL) { | 
| 1110 | 
  | 
  | 
                        fprintf(stderr, | 
| 1111 | 
  | 
  | 
                        "%s: cannot open exposure file \"%s\"\n", | 
| 1112 | 
  | 
  | 
                                        progname, vval(EXPOSURE)); | 
| 1113 | 
  | 
  | 
                        quit(1); | 
| 1114 | 
  | 
  | 
                } | 
| 1115 | 
  | 
  | 
                curfrm = vint(END) + 1;         /* init lookup tab. */ | 
| 1116 | 
  | 
  | 
                exppos = (long *)malloc(curfrm*sizeof(long *)); | 
| 1117 | 
  | 
  | 
                if (exppos == NULL) { | 
| 1118 | 
  | 
  | 
                        perror(progname); | 
| 1119 | 
  | 
  | 
                        quit(1); | 
| 1120 | 
  | 
  | 
                } | 
| 1121 | 
  | 
  | 
                while (curfrm--) | 
| 1122 | 
  | 
  | 
                        exppos[curfrm] = -1L; | 
| 1123 | 
  | 
  | 
                curfrm = 0; | 
| 1124 | 
  | 
  | 
        } | 
| 1125 | 
  | 
  | 
                                                /* find position in file */ | 
| 1126 | 
  | 
  | 
        if (n-1 != curfrm && n != curfrm && exppos[n-1] >= 0 && | 
| 1127 | 
  | 
  | 
                                fseek(expfp, exppos[curfrm=n-1], 0) == EOF) { | 
| 1128 | 
  | 
  | 
                fprintf(stderr, "%s: seek error on exposure file\n", progname); | 
| 1129 | 
  | 
  | 
                quit(1); | 
| 1130 | 
  | 
  | 
        } | 
| 1131 | 
  | 
  | 
        while (n > curfrm) {                    /* read exposure */ | 
| 1132 | 
  | 
  | 
                if (exppos[curfrm] < 0) | 
| 1133 | 
  | 
  | 
                        exppos[curfrm] = ftell(expfp); | 
| 1134 | 
  | 
  | 
                if (fgets(expval, sizeof(expval), expfp) == NULL) { | 
| 1135 | 
  | 
  | 
                        fprintf(stderr, "%s: too few exposures\n", | 
| 1136 | 
  | 
  | 
                                        vval(EXPOSURE)); | 
| 1137 | 
  | 
  | 
                        quit(1); | 
| 1138 | 
  | 
  | 
                } | 
| 1139 | 
  | 
  | 
                curfrm++; | 
| 1140 | 
  | 
  | 
                cp = fskip(expval);                     /* check format */ | 
| 1141 | 
greg | 
2.14 | 
                if (cp != NULL) | 
| 1142 | 
  | 
  | 
                        while (isspace(*cp)) | 
| 1143 | 
  | 
  | 
                                *cp++ = '\0'; | 
| 1144 | 
  | 
  | 
                if (cp == NULL || *cp) { | 
| 1145 | 
greg | 
2.1 | 
                        fprintf(stderr, | 
| 1146 | 
  | 
  | 
                                "%s: exposure format error on line %d\n", | 
| 1147 | 
  | 
  | 
                                        vval(EXPOSURE), curfrm); | 
| 1148 | 
  | 
  | 
                        quit(1); | 
| 1149 | 
  | 
  | 
                } | 
| 1150 | 
  | 
  | 
        } | 
| 1151 | 
  | 
  | 
        return(expval);                         /* return value */ | 
| 1152 | 
  | 
  | 
} | 
| 1153 | 
  | 
  | 
 | 
| 1154 | 
  | 
  | 
 | 
| 1155 | 
greg | 
2.2 | 
struct pslot * | 
| 1156 | 
  | 
  | 
findpslot(pid)                  /* find or allocate a process slot */ | 
| 1157 | 
  | 
  | 
int     pid; | 
| 1158 | 
  | 
  | 
{ | 
| 1159 | 
  | 
  | 
        register struct pslot   *psempty = NULL; | 
| 1160 | 
  | 
  | 
        register int    i; | 
| 1161 | 
  | 
  | 
 | 
| 1162 | 
  | 
  | 
        for (i = 0; i < npslots; i++) {         /* look for match */ | 
| 1163 | 
  | 
  | 
                if (pslot[i].pid == pid) | 
| 1164 | 
  | 
  | 
                        return(pslot+i); | 
| 1165 | 
  | 
  | 
                if (psempty == NULL && pslot[i].pid == 0) | 
| 1166 | 
  | 
  | 
                        psempty = pslot+i; | 
| 1167 | 
  | 
  | 
        } | 
| 1168 | 
  | 
  | 
        return(psempty);                /* return emtpy slot (error if NULL) */ | 
| 1169 | 
  | 
  | 
} | 
| 1170 | 
  | 
  | 
 | 
| 1171 | 
  | 
  | 
 | 
| 1172 | 
  | 
  | 
int | 
| 1173 | 
  | 
  | 
donecom(ps, pn, status)         /* clean up after finished process */ | 
| 1174 | 
  | 
  | 
PSERVER *ps; | 
| 1175 | 
  | 
  | 
int     pn; | 
| 1176 | 
  | 
  | 
int     status; | 
| 1177 | 
  | 
  | 
{ | 
| 1178 | 
  | 
  | 
        register PROC   *pp; | 
| 1179 | 
greg | 
2.18 | 
        register struct pslot   *psl; | 
| 1180 | 
greg | 
2.2 | 
 | 
| 1181 | 
  | 
  | 
        pp = ps->proc + pn; | 
| 1182 | 
greg | 
2.3 | 
        if (pp->elen) {                 /* pass errors */ | 
| 1183 | 
greg | 
2.2 | 
                if (ps->hostname[0]) | 
| 1184 | 
greg | 
2.3 | 
                        fprintf(stderr, "%s: ", ps->hostname); | 
| 1185 | 
  | 
  | 
                fprintf(stderr, "Error output from: %s\n", pp->com); | 
| 1186 | 
greg | 
2.2 | 
                fputs(pp->errs, stderr); | 
| 1187 | 
  | 
  | 
                fflush(stderr); | 
| 1188 | 
  | 
  | 
                if (ps->hostname[0]) | 
| 1189 | 
  | 
  | 
                        status = 1;     /* because rsh doesn't return status */ | 
| 1190 | 
  | 
  | 
        } | 
| 1191 | 
greg | 
2.18 | 
        lastpserver = NULL; | 
| 1192 | 
  | 
  | 
        psl = findpslot(pp->pid);       /* check for bruncom() slot */ | 
| 1193 | 
  | 
  | 
        if (psl->pid) { | 
| 1194 | 
  | 
  | 
                if (status) { | 
| 1195 | 
  | 
  | 
                        if (psl->rcvf != NULL)  /* attempt recovery */ | 
| 1196 | 
  | 
  | 
                                status = (*psl->rcvf)(psl->fout); | 
| 1197 | 
  | 
  | 
                        if (status) { | 
| 1198 | 
  | 
  | 
                                fprintf(stderr, | 
| 1199 | 
  | 
  | 
                                        "%s: error rendering frame %d\n", | 
| 1200 | 
  | 
  | 
                                                progname, psl->fout); | 
| 1201 | 
  | 
  | 
                                quit(1); | 
| 1202 | 
  | 
  | 
                        } | 
| 1203 | 
  | 
  | 
                        lastpserver = ps; | 
| 1204 | 
  | 
  | 
                } | 
| 1205 | 
  | 
  | 
                psl->pid = 0;                   /* free process slot */ | 
| 1206 | 
  | 
  | 
        } else if (status) | 
| 1207 | 
  | 
  | 
                lastpserver = ps; | 
| 1208 | 
greg | 
2.2 | 
        freestr(pp->com);               /* free command string */ | 
| 1209 | 
  | 
  | 
        return(status); | 
| 1210 | 
  | 
  | 
} | 
| 1211 | 
  | 
  | 
 | 
| 1212 | 
  | 
  | 
 | 
| 1213 | 
  | 
  | 
int | 
| 1214 | 
  | 
  | 
serverdown()                    /* check status of last process server */ | 
| 1215 | 
  | 
  | 
{ | 
| 1216 | 
greg | 
2.18 | 
        if (lastpserver == NULL || !lastpserver->hostname[0]) | 
| 1217 | 
  | 
  | 
                return(0); | 
| 1218 | 
greg | 
2.2 | 
        if (pserverOK(lastpserver))     /* server still up? */ | 
| 1219 | 
  | 
  | 
                return(0); | 
| 1220 | 
  | 
  | 
        delpserver(lastpserver);        /* else delete it */ | 
| 1221 | 
  | 
  | 
        if (pslist == NULL) { | 
| 1222 | 
  | 
  | 
                fprintf(stderr, "%s: all process servers are down\n", | 
| 1223 | 
  | 
  | 
                                progname); | 
| 1224 | 
  | 
  | 
                quit(1); | 
| 1225 | 
  | 
  | 
        } | 
| 1226 | 
  | 
  | 
        return(1); | 
| 1227 | 
  | 
  | 
} | 
| 1228 | 
  | 
  | 
 | 
| 1229 | 
  | 
  | 
 | 
| 1230 | 
  | 
  | 
int | 
| 1231 | 
  | 
  | 
bruncom(com, fout, rf)          /* run a command in the background */ | 
| 1232 | 
  | 
  | 
char    *com; | 
| 1233 | 
  | 
  | 
int     fout; | 
| 1234 | 
  | 
  | 
int     (*rf)(); | 
| 1235 | 
  | 
  | 
{ | 
| 1236 | 
  | 
  | 
        int     pid; | 
| 1237 | 
  | 
  | 
        register struct pslot   *psl; | 
| 1238 | 
  | 
  | 
 | 
| 1239 | 
greg | 
2.5 | 
        if (noaction) { | 
| 1240 | 
  | 
  | 
                if (!silent) | 
| 1241 | 
  | 
  | 
                        printf("\t%s\n", com);  /* echo command */ | 
| 1242 | 
greg | 
2.2 | 
                return(0); | 
| 1243 | 
greg | 
2.5 | 
        } | 
| 1244 | 
greg | 
2.18 | 
        com = savestr(com);             /* else start it when we can */ | 
| 1245 | 
  | 
  | 
        while ((pid = startjob(NULL, com, donecom)) == -1) | 
| 1246 | 
greg | 
2.2 | 
                bwait(1); | 
| 1247 | 
greg | 
2.5 | 
        if (!silent) {                          /* echo command */ | 
| 1248 | 
greg | 
2.3 | 
                PSERVER *ps; | 
| 1249 | 
  | 
  | 
                int     psn = pid; | 
| 1250 | 
greg | 
2.4 | 
                ps = findjob(&psn); | 
| 1251 | 
greg | 
2.5 | 
                printf("\t%s\n", com); | 
| 1252 | 
greg | 
2.4 | 
                printf("\tProcess started on %s\n", phostname(ps)); | 
| 1253 | 
greg | 
2.3 | 
                fflush(stdout); | 
| 1254 | 
  | 
  | 
        } | 
| 1255 | 
greg | 
2.2 | 
        psl = findpslot(pid);           /* record info. in appropriate slot */ | 
| 1256 | 
  | 
  | 
        psl->pid = pid; | 
| 1257 | 
  | 
  | 
        psl->fout = fout; | 
| 1258 | 
  | 
  | 
        psl->rcvf = rf; | 
| 1259 | 
  | 
  | 
        return(pid); | 
| 1260 | 
  | 
  | 
} | 
| 1261 | 
  | 
  | 
 | 
| 1262 | 
  | 
  | 
 | 
| 1263 | 
  | 
  | 
bwait(ncoms)                            /* wait for batch job(s) to finish */ | 
| 1264 | 
  | 
  | 
int     ncoms; | 
| 1265 | 
  | 
  | 
{ | 
| 1266 | 
  | 
  | 
        int     status; | 
| 1267 | 
  | 
  | 
 | 
| 1268 | 
  | 
  | 
        if (noaction) | 
| 1269 | 
  | 
  | 
                return; | 
| 1270 | 
  | 
  | 
        while ((status = wait4job(NULL, -1)) != -1) { | 
| 1271 | 
greg | 
2.18 | 
                serverdown();           /* update server status */ | 
| 1272 | 
  | 
  | 
                if (--ncoms == 0) | 
| 1273 | 
  | 
  | 
                        break;          /* done enough */ | 
| 1274 | 
greg | 
2.2 | 
        } | 
| 1275 | 
  | 
  | 
} | 
| 1276 | 
  | 
  | 
 | 
| 1277 | 
  | 
  | 
 | 
| 1278 | 
  | 
  | 
int | 
| 1279 | 
greg | 
2.4 | 
pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */ | 
| 1280 | 
  | 
  | 
char    *com, *ppins; | 
| 1281 | 
greg | 
2.2 | 
int     maxcopies; | 
| 1282 | 
  | 
  | 
{ | 
| 1283 | 
  | 
  | 
        int     retstatus = 0; | 
| 1284 | 
greg | 
2.3 | 
        int     hostcopies; | 
| 1285 | 
greg | 
2.18 | 
        char    buf[10240], *com1, *s; | 
| 1286 | 
greg | 
2.2 | 
        int     status; | 
| 1287 | 
greg | 
2.17 | 
        int     pfd; | 
| 1288 | 
  | 
  | 
        register int    n; | 
| 1289 | 
greg | 
2.2 | 
        register PSERVER        *ps; | 
| 1290 | 
  | 
  | 
 | 
| 1291 | 
greg | 
2.3 | 
        if (!silent) | 
| 1292 | 
greg | 
2.6 | 
                printf("\t%s\n", com);  /* echo command */ | 
| 1293 | 
greg | 
2.3 | 
        if (noaction) | 
| 1294 | 
greg | 
2.2 | 
                return(0); | 
| 1295 | 
greg | 
2.3 | 
        fflush(stdout); | 
| 1296 | 
greg | 
2.2 | 
                                        /* start jobs on each server */ | 
| 1297 | 
greg | 
2.3 | 
        for (ps = pslist; ps != NULL; ps = ps->next) { | 
| 1298 | 
  | 
  | 
                hostcopies = 0; | 
| 1299 | 
greg | 
2.4 | 
                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { | 
| 1300 | 
greg | 
2.17 | 
                        strcpy(com1=buf, com);  /* build -PP command */ | 
| 1301 | 
greg | 
2.4 | 
                        sprintf(com1+(ppins-com), " -PP %s/%s.persist", | 
| 1302 | 
  | 
  | 
                                        vval(DIRECTORY), phostname(ps)); | 
| 1303 | 
greg | 
2.36 | 
                        unlink(com1+(ppins-com)+5); | 
| 1304 | 
greg | 
2.4 | 
                        strcat(com1, ppins); | 
| 1305 | 
greg | 
2.17 | 
                } else | 
| 1306 | 
greg | 
2.4 | 
                        com1 = com; | 
| 1307 | 
greg | 
2.18 | 
                while (maxcopies > 0) { | 
| 1308 | 
  | 
  | 
                        s = savestr(com1); | 
| 1309 | 
  | 
  | 
                        if (startjob(ps, s, donecom) != -1) { | 
| 1310 | 
  | 
  | 
                                sleep(20); | 
| 1311 | 
  | 
  | 
                                hostcopies++; | 
| 1312 | 
  | 
  | 
                                maxcopies--; | 
| 1313 | 
  | 
  | 
                        } else { | 
| 1314 | 
  | 
  | 
                                freestr(s); | 
| 1315 | 
  | 
  | 
                                break; | 
| 1316 | 
  | 
  | 
                        } | 
| 1317 | 
greg | 
2.2 | 
                } | 
| 1318 | 
greg | 
2.3 | 
                if (!silent && hostcopies) { | 
| 1319 | 
  | 
  | 
                        if (hostcopies > 1) | 
| 1320 | 
  | 
  | 
                                printf("\t%d duplicate processes", hostcopies); | 
| 1321 | 
  | 
  | 
                        else | 
| 1322 | 
  | 
  | 
                                printf("\tProcess"); | 
| 1323 | 
greg | 
2.4 | 
                        printf(" started on %s\n", phostname(ps)); | 
| 1324 | 
greg | 
2.3 | 
                        fflush(stdout); | 
| 1325 | 
  | 
  | 
                } | 
| 1326 | 
  | 
  | 
        } | 
| 1327 | 
greg | 
2.2 | 
                                        /* wait for jobs to finish */ | 
| 1328 | 
  | 
  | 
        while ((status = wait4job(NULL, -1)) != -1) | 
| 1329 | 
greg | 
2.18 | 
                retstatus += status && !serverdown(); | 
| 1330 | 
greg | 
2.17 | 
                                        /* terminate parallel rpict's */ | 
| 1331 | 
greg | 
2.18 | 
        for (ps = pslist; ps != NULL; ps = ps->next) { | 
| 1332 | 
  | 
  | 
                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); | 
| 1333 | 
greg | 
2.17 | 
                if ((pfd = open(buf, O_RDONLY)) >= 0) { | 
| 1334 | 
  | 
  | 
                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */ | 
| 1335 | 
  | 
  | 
                        buf[n] = '\0'; | 
| 1336 | 
  | 
  | 
                        close(pfd); | 
| 1337 | 
  | 
  | 
                        for (n = 0; buf[n] && !isspace(buf[n]); n++) | 
| 1338 | 
  | 
  | 
                                ; | 
| 1339 | 
  | 
  | 
                                                                /* terminate */ | 
| 1340 | 
  | 
  | 
                        sprintf(buf, "kill -ALRM %d", atoi(buf+n)); | 
| 1341 | 
greg | 
2.18 | 
                        wait4job(ps, startjob(ps, buf, NULL)); | 
| 1342 | 
greg | 
2.17 | 
                } | 
| 1343 | 
  | 
  | 
        } | 
| 1344 | 
greg | 
2.2 | 
        return(retstatus); | 
| 1345 | 
  | 
  | 
} | 
| 1346 | 
  | 
  | 
 | 
| 1347 | 
  | 
  | 
 | 
| 1348 | 
  | 
  | 
runcom(cs)                      /* run a command locally and wait for it */ | 
| 1349 | 
greg | 
2.1 | 
char    *cs; | 
| 1350 | 
  | 
  | 
{ | 
| 1351 | 
  | 
  | 
        if (!silent)            /* echo it */ | 
| 1352 | 
  | 
  | 
                printf("\t%s\n", cs); | 
| 1353 | 
  | 
  | 
        if (noaction) | 
| 1354 | 
  | 
  | 
                return(0); | 
| 1355 | 
  | 
  | 
        fflush(stdout);         /* flush output and pass to shell */ | 
| 1356 | 
  | 
  | 
        return(system(cs)); | 
| 1357 | 
  | 
  | 
} | 
| 1358 | 
  | 
  | 
 | 
| 1359 | 
  | 
  | 
 | 
| 1360 | 
  | 
  | 
rmfile(fn)                      /* remove a file */ | 
| 1361 | 
  | 
  | 
char    *fn; | 
| 1362 | 
  | 
  | 
{ | 
| 1363 | 
  | 
  | 
        if (!silent) | 
| 1364 | 
schorsch | 
2.37 | 
#ifdef _WIN32 | 
| 1365 | 
greg | 
2.1 | 
                printf("\tdel %s\n", fn); | 
| 1366 | 
  | 
  | 
#else | 
| 1367 | 
  | 
  | 
                printf("\trm -f %s\n", fn); | 
| 1368 | 
  | 
  | 
#endif | 
| 1369 | 
  | 
  | 
        if (noaction) | 
| 1370 | 
  | 
  | 
                return(0); | 
| 1371 | 
  | 
  | 
        return(unlink(fn)); | 
| 1372 | 
  | 
  | 
} | 
| 1373 | 
  | 
  | 
 | 
| 1374 | 
  | 
  | 
 | 
| 1375 | 
  | 
  | 
badvalue(vc)                    /* report bad variable value and exit */ | 
| 1376 | 
  | 
  | 
int     vc; | 
| 1377 | 
  | 
  | 
{ | 
| 1378 | 
  | 
  | 
        fprintf(stderr, "%s: bad value for variable '%s'\n", | 
| 1379 | 
  | 
  | 
                        progname, vnam(vc)); | 
| 1380 | 
  | 
  | 
        quit(1); | 
| 1381 | 
gwlarson | 
2.25 | 
} | 
| 1382 | 
  | 
  | 
 | 
| 1383 | 
  | 
  | 
 | 
| 1384 | 
  | 
  | 
char * | 
| 1385 | 
  | 
  | 
dirfile(df, path)               /* separate path into directory and file */ | 
| 1386 | 
  | 
  | 
char    *df; | 
| 1387 | 
  | 
  | 
register char   *path; | 
| 1388 | 
  | 
  | 
{ | 
| 1389 | 
  | 
  | 
        register int    i; | 
| 1390 | 
  | 
  | 
        int     psep; | 
| 1391 | 
  | 
  | 
 | 
| 1392 | 
  | 
  | 
        for (i = 0, psep = -1; path[i]; i++) | 
| 1393 | 
  | 
  | 
                if (path[i] == '/') | 
| 1394 | 
  | 
  | 
                        psep = i; | 
| 1395 | 
  | 
  | 
        if (df != NULL) | 
| 1396 | 
  | 
  | 
                if (psep == 0) { | 
| 1397 | 
  | 
  | 
                        df[0] = '/'; | 
| 1398 | 
  | 
  | 
                        df[1] = '\0'; | 
| 1399 | 
  | 
  | 
                } else if (psep > 0) { | 
| 1400 | 
  | 
  | 
                        strncpy(df, path, psep); | 
| 1401 | 
  | 
  | 
                        df[psep] = '\0'; | 
| 1402 | 
  | 
  | 
                } else | 
| 1403 | 
  | 
  | 
                        df[0] = '\0'; | 
| 1404 | 
  | 
  | 
        return(path+psep+1); | 
| 1405 | 
greg | 
2.29 | 
} | 
| 1406 | 
  | 
  | 
 | 
| 1407 | 
  | 
  | 
 | 
| 1408 | 
  | 
  | 
int | 
| 1409 | 
  | 
  | 
getblur(double *bf)             /* get # blur samples (and fraction) */ | 
| 1410 | 
  | 
  | 
{ | 
| 1411 | 
  | 
  | 
        double  blurf; | 
| 1412 | 
  | 
  | 
        int     nblur; | 
| 1413 | 
  | 
  | 
        char    *s; | 
| 1414 | 
  | 
  | 
 | 
| 1415 | 
  | 
  | 
        if (!vdef(MBLUR)) { | 
| 1416 | 
  | 
  | 
                if (bf != NULL) | 
| 1417 | 
  | 
  | 
                        *bf = 0.0; | 
| 1418 | 
  | 
  | 
                return(0); | 
| 1419 | 
  | 
  | 
        } | 
| 1420 | 
  | 
  | 
        blurf = atof(vval(MBLUR)); | 
| 1421 | 
  | 
  | 
        if (blurf < 0.0) | 
| 1422 | 
  | 
  | 
                blurf = 0.0; | 
| 1423 | 
  | 
  | 
        if (bf != NULL) | 
| 1424 | 
  | 
  | 
                *bf = blurf; | 
| 1425 | 
  | 
  | 
        if (blurf <= FTINY) | 
| 1426 | 
  | 
  | 
                return(0); | 
| 1427 | 
  | 
  | 
        s = sskip(vval(MBLUR)); | 
| 1428 | 
  | 
  | 
        if (!*s) | 
| 1429 | 
  | 
  | 
                return(DEF_NBLUR); | 
| 1430 | 
  | 
  | 
        nblur = atoi(s); | 
| 1431 | 
  | 
  | 
        if (nblur <= 0) | 
| 1432 | 
  | 
  | 
                return(1); | 
| 1433 | 
  | 
  | 
        return(nblur); | 
| 1434 | 
greg | 
2.1 | 
} |