| 1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include "standard.h" |
| 12 |
+ |
#include <ctype.h> |
| 13 |
|
#include <sys/types.h> |
| 14 |
|
#include <sys/stat.h> |
| 15 |
|
#include "view.h" |
| 16 |
|
#include "vars.h" |
| 17 |
+ |
#include "netproc.h" |
| 18 |
+ |
/* default remote shell */ |
| 19 |
+ |
#ifdef _AUX_SOURCE |
| 20 |
+ |
#define REMSH "remsh" |
| 21 |
+ |
#else |
| 22 |
+ |
#define REMSH "rsh" |
| 23 |
+ |
#endif |
| 24 |
|
/* input variables */ |
| 25 |
|
#define HOST 0 /* rendering host machine */ |
| 26 |
|
#define RENDER 1 /* rendering options */ |
| 44 |
|
#define DISKSPACE 19 /* how much disk space to use */ |
| 45 |
|
#define RESOLUTION 20 /* desired final resolution */ |
| 46 |
|
#define EXPOSURE 21 /* how to compute exposure */ |
| 47 |
+ |
#define RSH 22 /* remote shell script or program */ |
| 48 |
|
|
| 49 |
< |
int NVARS = 22; /* total number of variables */ |
| 49 |
> |
int NVARS = 23; /* total number of variables */ |
| 50 |
|
|
| 51 |
|
VARIABLE vv[] = { /* variable-value pairs */ |
| 52 |
|
{"host", 4, 0, NULL, NULL}, |
| 64 |
|
{"ANIMATE", 2, 0, NULL, onevalue}, |
| 65 |
|
{"TRANSFER", 2, 0, NULL, onevalue}, |
| 66 |
|
{"ARCHIVE", 2, 0, NULL, onevalue}, |
| 67 |
< |
{"INTERP", 3, 0, NULL, intvalue}, |
| 68 |
< |
{"OVERSAMP", 2, 0, NULL, fltvalue}, |
| 67 |
> |
{"INTERPOLATE", 3, 0, NULL, intvalue}, |
| 68 |
> |
{"OVERSAMPLE", 2, 0, NULL, fltvalue}, |
| 69 |
|
{"MBLUR", 2, 0, NULL, onevalue}, |
| 70 |
|
{"RTRACE", 2, 0, NULL, boolvalue}, |
| 71 |
|
{"DISKSPACE", 3, 0, NULL, fltvalue}, |
| 72 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
| 73 |
|
{"EXPOSURE", 3, 0, NULL, onevalue}, |
| 74 |
+ |
{"RSH", 3, 0, NULL, onevalue}, |
| 75 |
|
}; |
| 76 |
|
|
| 77 |
|
#define SFNAME "STATUS" /* status file name */ |
| 92 |
|
int silent = 0; /* silent mode? */ |
| 93 |
|
int noaction = 0; /* take no action? */ |
| 94 |
|
|
| 95 |
< |
char rendopt[2048] = ""; /* rendering options */ |
| 95 |
> |
char *remsh; /* remote shell program/script */ |
| 96 |
> |
char rendopt[2048]; /* rendering options */ |
| 97 |
|
char rresopt[32]; /* rendering resolution options */ |
| 98 |
|
char fresopt[32]; /* filter resolution options */ |
| 99 |
|
int pfiltalways; /* always use pfilt? */ |
| 100 |
|
|
| 101 |
+ |
char arcargs[10240]; /* files to archive */ |
| 102 |
+ |
char *arcfirst, *arcnext; /* pointers to first and next argument */ |
| 103 |
+ |
|
| 104 |
+ |
struct pslot { |
| 105 |
+ |
int pid; /* process ID (0 if empty) */ |
| 106 |
+ |
int fout; /* output frame number */ |
| 107 |
+ |
int (*rcvf)(); /* recover function */ |
| 108 |
+ |
} *pslot; /* process slots */ |
| 109 |
+ |
int npslots; /* number of process slots */ |
| 110 |
+ |
|
| 111 |
+ |
#define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) |
| 112 |
+ |
|
| 113 |
+ |
struct pslot *findpslot(); |
| 114 |
+ |
|
| 115 |
+ |
PSERVER *lastpserver; /* last process server with error */ |
| 116 |
+ |
|
| 117 |
|
VIEW *getview(); |
| 118 |
< |
char *getexp(); |
| 118 |
> |
char *getexp(), *dirfile(); |
| 119 |
|
|
| 120 |
+ |
extern time_t fdate(), time(); |
| 121 |
|
|
| 122 |
+ |
|
| 123 |
|
main(argc, argv) |
| 124 |
|
int argc; |
| 125 |
|
char *argv[]; |
| 150 |
|
cfname = argv[i]; |
| 151 |
|
/* load variables */ |
| 152 |
|
loadvars(cfname); |
| 153 |
+ |
/* check variables */ |
| 154 |
+ |
checkvalues(); |
| 155 |
|
/* did we get DIRECTORY? */ |
| 156 |
|
checkdir(); |
| 157 |
|
/* check status */ |
| 169 |
|
/* print variables */ |
| 170 |
|
if (explicate) |
| 171 |
|
printvars(stdout); |
| 172 |
+ |
/* set up process servers */ |
| 173 |
+ |
sethosts(); |
| 174 |
|
/* run animation */ |
| 175 |
|
animate(); |
| 176 |
|
/* all done */ |
| 178 |
|
argv[i] = vval(NEXTANIM); /* just change input file */ |
| 179 |
|
if (!silent) |
| 180 |
|
printargs(argc, argv, stdout); |
| 181 |
< |
if (!noaction) { |
| 182 |
< |
execvp(progname, argv); /* pass to next */ |
| 183 |
< |
quit(1); /* shouldn't return */ |
| 184 |
< |
} |
| 181 |
> |
if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) |
| 182 |
> |
fprintf(stderr, "%s: command not found\n", progname); |
| 183 |
> |
else |
| 184 |
> |
execv(progname, argv); |
| 185 |
> |
quit(1); |
| 186 |
|
} |
| 187 |
|
quit(0); |
| 188 |
|
userr: |
| 193 |
|
|
| 194 |
|
getastat() /* check/set animation status */ |
| 195 |
|
{ |
| 196 |
< |
char buf[256]; |
| 196 |
> |
char sfname[256]; |
| 197 |
|
FILE *fp; |
| 198 |
|
|
| 199 |
< |
sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); |
| 200 |
< |
if ((fp = fopen(buf, "r")) == NULL) { |
| 199 |
> |
sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); |
| 200 |
> |
if ((fp = fopen(sfname, "r")) == NULL) { |
| 201 |
|
if (errno != ENOENT) { |
| 202 |
< |
perror(buf); |
| 202 |
> |
perror(sfname); |
| 203 |
|
return(-1); |
| 204 |
|
} |
| 205 |
|
astat.rnext = astat.fnext = astat.tnext = 0; |
| 219 |
|
goto fmterr; |
| 220 |
|
fclose(fp); |
| 221 |
|
if (astat.pid != 0) { /* thinks it's still running */ |
| 222 |
< |
gethostname(buf, sizeof(buf)); |
| 189 |
< |
if (strcmp(buf, astat.host)) { |
| 222 |
> |
if (strcmp(myhostname(), astat.host)) { |
| 223 |
|
fprintf(stderr, |
| 224 |
|
"%s: process %d may still be running on host %s\n", |
| 225 |
|
progname, astat.pid, astat.host); |
| 232 |
|
} |
| 233 |
|
/* assume it is dead */ |
| 234 |
|
} |
| 235 |
< |
if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ |
| 235 |
> |
if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */ |
| 236 |
|
fprintf(stderr, "%s: unfinished job \"%s\"\n", |
| 237 |
|
progname, astat.cfname); |
| 238 |
|
return(-1); |
| 239 |
|
} |
| 240 |
+ |
/* check control file mods. */ |
| 241 |
+ |
if (!nowarn && fdate(cfname) > fdate(sfname)) |
| 242 |
+ |
fprintf(stderr, |
| 243 |
+ |
"%s: warning - control file modified since last run\n", |
| 244 |
+ |
progname); |
| 245 |
|
setours: /* set our values */ |
| 246 |
< |
gethostname(astat.host, sizeof(astat.host)); |
| 246 |
> |
strcpy(astat.host, myhostname()); |
| 247 |
|
astat.pid = getpid(); |
| 248 |
|
strcpy(astat.cfname, cfname); |
| 249 |
|
return(0); |
| 250 |
|
fmterr: |
| 251 |
|
fprintf(stderr, "%s: format error in status file \"%s\"\n", |
| 252 |
< |
progname, buf); |
| 252 |
> |
progname, sfname); |
| 253 |
|
fclose(fp); |
| 254 |
|
return(-1); |
| 255 |
|
} |
| 260 |
|
char buf[256]; |
| 261 |
|
FILE *fp; |
| 262 |
|
|
| 263 |
+ |
if (noaction) |
| 264 |
+ |
return; |
| 265 |
|
sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); |
| 266 |
|
if ((fp = fopen(buf, "w")) == NULL) { |
| 267 |
|
perror(buf); |
| 301 |
|
|
| 302 |
|
setdefaults() /* set default values */ |
| 303 |
|
{ |
| 304 |
+ |
extern char *atos(); |
| 305 |
+ |
int decades; |
| 306 |
|
char buf[256]; |
| 307 |
|
|
| 308 |
< |
if (vdef(OCTREE) == vdef(ANIMATE)) { |
| 308 |
> |
if (vdef(ANIMATE)) { |
| 309 |
> |
vval(OCTREE) = NULL; |
| 310 |
> |
vdef(OCTREE) = 0; |
| 311 |
> |
} else if (!vdef(OCTREE)) { |
| 312 |
|
fprintf(stderr, "%s: either %s or %s must be defined\n", |
| 313 |
|
progname, vnam(OCTREE), vnam(ANIMATE)); |
| 314 |
|
quit(1); |
| 317 |
|
fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE)); |
| 318 |
|
quit(1); |
| 319 |
|
} |
| 320 |
+ |
if (!vdef(HOST)) { |
| 321 |
+ |
vval(HOST) = LHOSTNAME; |
| 322 |
+ |
vdef(HOST)++; |
| 323 |
+ |
} |
| 324 |
|
if (!vdef(START)) { |
| 325 |
|
vval(START) = "1"; |
| 326 |
|
vdef(START)++; |
| 327 |
|
} |
| 328 |
|
if (!vdef(END)) { |
| 329 |
< |
sprintf(buf, "%d", countviews()); |
| 329 |
> |
sprintf(buf, "%d", countviews()+vint(START)-1); |
| 330 |
|
vval(END) = savqstr(buf); |
| 331 |
|
vdef(END)++; |
| 332 |
|
} |
| 333 |
+ |
if (vint(END) < vint(START)) { |
| 334 |
+ |
fprintf(stderr, "%s: ending frame less than starting frame\n", |
| 335 |
+ |
progname); |
| 336 |
+ |
quit(1); |
| 337 |
+ |
} |
| 338 |
|
if (!vdef(BASENAME)) { |
| 339 |
< |
sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); |
| 339 |
> |
decades = (int)log10((double)vint(END)) + 1; |
| 340 |
> |
if (decades < 3) decades = 3; |
| 341 |
> |
sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); |
| 342 |
|
vval(BASENAME) = savqstr(buf); |
| 343 |
|
vdef(BASENAME)++; |
| 344 |
|
} |
| 370 |
|
vval(DISKSPACE) = "100"; |
| 371 |
|
vdef(DISKSPACE)++; |
| 372 |
|
} |
| 373 |
+ |
if (!vdef(RSH)) { |
| 374 |
+ |
vval(RSH) = REMSH; |
| 375 |
+ |
vdef(RSH)++; |
| 376 |
+ |
} |
| 377 |
+ |
/* locate remote shell program */ |
| 378 |
+ |
atos(buf, sizeof(buf), vval(RSH)); |
| 379 |
+ |
if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) |
| 380 |
+ |
remsh = savqstr(remsh); |
| 381 |
+ |
else |
| 382 |
+ |
remsh = vval(RSH); /* will generate error if used */ |
| 383 |
+ |
|
| 384 |
|
/* append rendering options */ |
| 385 |
|
if (vdef(RENDER)) |
| 386 |
|
sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
|
| 390 |
< |
getradfile(rfname) /* run rad and get needed variables */ |
| 324 |
< |
char *rfname; |
| 390 |
> |
sethosts() /* set up process servers */ |
| 391 |
|
{ |
| 392 |
+ |
extern char *iskip(); |
| 393 |
+ |
char buf[256], *dir, *uname; |
| 394 |
+ |
int np; |
| 395 |
+ |
register char *cp; |
| 396 |
+ |
int i; |
| 397 |
+ |
|
| 398 |
+ |
npslots = 0; |
| 399 |
+ |
if (noaction) |
| 400 |
+ |
return; |
| 401 |
+ |
for (i = 0; i < vdef(HOST); i++) { /* add each host */ |
| 402 |
+ |
dir = uname = NULL; |
| 403 |
+ |
np = 1; |
| 404 |
+ |
strcpy(cp=buf, nvalue(HOST, i)); /* copy to buffer */ |
| 405 |
+ |
cp = sskip(cp); /* skip host name */ |
| 406 |
+ |
while (isspace(*cp)) |
| 407 |
+ |
*cp++ = '\0'; |
| 408 |
+ |
if (*cp) { /* has # processes? */ |
| 409 |
+ |
np = atoi(cp); |
| 410 |
+ |
if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp))) |
| 411 |
+ |
badvalue(HOST); |
| 412 |
+ |
while (isspace(*cp)) |
| 413 |
+ |
cp++; |
| 414 |
+ |
if (*cp) { /* has directory? */ |
| 415 |
+ |
dir = cp; |
| 416 |
+ |
cp = sskip(cp); /* skip dir. */ |
| 417 |
+ |
while (isspace(*cp)) |
| 418 |
+ |
*cp++ = '\0'; |
| 419 |
+ |
if (*cp) { /* has user? */ |
| 420 |
+ |
uname = cp; |
| 421 |
+ |
if (*sskip(cp)) |
| 422 |
+ |
badvalue(HOST); |
| 423 |
+ |
} |
| 424 |
+ |
} |
| 425 |
+ |
} |
| 426 |
+ |
if (addpserver(buf, dir, uname, np) == NULL) { |
| 427 |
+ |
if (!nowarn) |
| 428 |
+ |
fprintf(stderr, |
| 429 |
+ |
"%s: cannot execute on host \"%s\"\n", |
| 430 |
+ |
progname, buf); |
| 431 |
+ |
} else |
| 432 |
+ |
npslots += np; |
| 433 |
+ |
} |
| 434 |
+ |
if (npslots == 0) { |
| 435 |
+ |
fprintf(stderr, "%s: no working process servers\n", progname); |
| 436 |
+ |
quit(1); |
| 437 |
+ |
} |
| 438 |
+ |
pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot)); |
| 439 |
+ |
if (pslot == NULL) { |
| 440 |
+ |
perror("malloc"); |
| 441 |
+ |
quit(1); |
| 442 |
+ |
} |
| 443 |
+ |
} |
| 444 |
+ |
|
| 445 |
+ |
|
| 446 |
+ |
getradfile(rfargs) /* run rad and get needed variables */ |
| 447 |
+ |
char *rfargs; |
| 448 |
+ |
{ |
| 449 |
|
static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; |
| 450 |
|
char combuf[256]; |
| 451 |
|
register int i; |
| 452 |
|
register char *cp; |
| 453 |
+ |
char *pippt; |
| 454 |
|
/* create rad command */ |
| 455 |
|
sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); |
| 456 |
|
sprintf(combuf, |
| 457 |
|
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
| 458 |
< |
rfname, rendopt+2); |
| 458 |
> |
rfargs, rendopt+2); |
| 459 |
|
cp = combuf; |
| 460 |
< |
while (*cp) cp++; /* match unset variables */ |
| 460 |
> |
while (*cp) { |
| 461 |
> |
if (*cp == '|') pippt = cp; |
| 462 |
> |
cp++; |
| 463 |
> |
} /* match unset variables */ |
| 464 |
|
for (i = 0; mvar[i] >= 0; i++) |
| 465 |
|
if (!vdef(mvar[i])) { |
| 466 |
|
*cp++ = '|'; |
| 467 |
|
strcpy(cp, vnam(mvar[i])); |
| 468 |
|
while (*cp) cp++; |
| 469 |
+ |
pippt = NULL; |
| 470 |
|
} |
| 471 |
< |
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
| 472 |
< |
cp += 11; /* point to file name */ |
| 471 |
> |
if (pippt != NULL) |
| 472 |
> |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
| 473 |
> |
else { |
| 474 |
> |
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
| 475 |
> |
cp += 11; /* point to file name */ |
| 476 |
> |
} |
| 477 |
|
if (system(combuf)) { |
| 478 |
< |
fprintf(stderr, "%s: bad rad input file \"%s\"\n", |
| 479 |
< |
progname, rfname); |
| 478 |
> |
fprintf(stderr, "%s: error executing rad command:\n\t%s\n", |
| 479 |
> |
progname, combuf); |
| 480 |
|
quit(1); |
| 481 |
|
} |
| 482 |
< |
loadvars(cp); /* load variables and remove file */ |
| 483 |
< |
unlink(cp); |
| 482 |
> |
if (pippt == NULL) { /* load variables and remove file */ |
| 483 |
> |
loadvars(cp); |
| 484 |
> |
unlink(cp); |
| 485 |
> |
} |
| 486 |
|
} |
| 487 |
|
|
| 488 |
|
|
| 497 |
|
i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa); |
| 498 |
|
mult = vflt(OVERSAMP); |
| 499 |
|
if (i == 3) { |
| 500 |
< |
sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres), |
| 500 |
> |
sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres), |
| 501 |
|
(int)(mult*yres), pa); |
| 502 |
< |
sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa); |
| 502 |
> |
sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa); |
| 503 |
|
} else if (i) { |
| 504 |
|
if (i == 1) yres = xres; |
| 505 |
|
sprintf(rresopt, "-x %d -y %d", (int)(mult*xres), |
| 527 |
|
/* figure # frames per batch */ |
| 528 |
|
d1 = mult*xres*mult*yres*4; /* space for orig. picture */ |
| 529 |
|
if ((i=vint(INTERP)) || atoi(vval(MBLUR))) |
| 530 |
< |
d1 += mult*xres*mult*yres*4; /* space for z-buffer */ |
| 530 |
> |
d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ |
| 531 |
|
d2 = xres*yres*4; /* space for final picture */ |
| 532 |
|
frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); |
| 533 |
|
if (frames_batch < i+2) { |
| 535 |
|
progname); |
| 536 |
|
quit(1); |
| 537 |
|
} |
| 538 |
+ |
/* initialize archive argument list */ |
| 539 |
+ |
i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; |
| 540 |
+ |
arcnext = arcfirst = arcargs + i; |
| 541 |
|
/* initialize status file */ |
| 542 |
|
if (astat.rnext == 0) |
| 543 |
|
astat.rnext = astat.fnext = astat.tnext = vint(START); |
| 544 |
|
putastat(); |
| 545 |
|
/* render in batches */ |
| 546 |
< |
while (astat.rnext <= vint(END)) { |
| 546 |
> |
while (astat.tnext <= vint(END)) { |
| 547 |
|
renderframes(frames_batch); |
| 548 |
|
filterframes(); |
| 549 |
|
transferframes(); |
| 603 |
|
} |
| 604 |
|
} |
| 605 |
|
if (vdef(ANIMATE)) /* wait for renderings to finish */ |
| 606 |
< |
animwait(0); |
| 606 |
> |
bwait(0); |
| 607 |
|
else { /* else if walk-through */ |
| 608 |
|
fclose(fp); /* close view file */ |
| 609 |
|
walkwait(astat.rnext, lastframe, vfname); /* walk it */ |
| 610 |
|
unlink(vfname); /* remove view file */ |
| 611 |
|
} |
| 475 |
– |
if (vdef(ARCHIVE)) /* archive results */ |
| 476 |
– |
archive(astat.rnext, lastframe); |
| 612 |
|
astat.rnext = i; /* update status */ |
| 613 |
|
putastat(); |
| 614 |
|
} |
| 629 |
|
progname, i); |
| 630 |
|
quit(1); |
| 631 |
|
} |
| 632 |
< |
dofilt(i, vp, getexp(i)); /* filter frame */ |
| 632 |
> |
dofilt(i, vp, getexp(i), 0); /* filter frame */ |
| 633 |
|
} |
| 634 |
< |
filtwait(0); /* wait for filter processes */ |
| 634 |
> |
bwait(0); /* wait for filter processes */ |
| 635 |
> |
archive(); /* archive originals */ |
| 636 |
|
astat.fnext = i; /* update status */ |
| 637 |
|
putastat(); |
| 638 |
|
} |
| 640 |
|
|
| 641 |
|
transferframes() /* catch up with picture transfers */ |
| 642 |
|
{ |
| 643 |
< |
char combuf[10240]; |
| 643 |
> |
char combuf[10240], *fbase; |
| 644 |
|
register char *cp; |
| 645 |
|
register int i; |
| 646 |
|
|
| 651 |
|
putastat(); /* update status */ |
| 652 |
|
return; |
| 653 |
|
} |
| 654 |
< |
strcpy(combuf, vval(TRANSFER)); /* start transfer command */ |
| 655 |
< |
cp = combuf + strlen(combuf); |
| 654 |
> |
strcpy(combuf, "cd "); /* start transfer command */ |
| 655 |
> |
fbase = dirfile(cp = combuf+3, vval(BASENAME)); |
| 656 |
> |
if (*cp) { |
| 657 |
> |
while (*++cp) ; |
| 658 |
> |
*cp++ = ';'; *cp++ = ' '; |
| 659 |
> |
} else |
| 660 |
> |
cp = combuf; |
| 661 |
> |
strcpy(cp, vval(TRANSFER)); |
| 662 |
> |
while (*cp) cp++; |
| 663 |
|
/* make argument list */ |
| 664 |
|
for (i = astat.tnext; i < astat.fnext; i++) { |
| 665 |
|
*cp++ = ' '; |
| 666 |
< |
sprintf(cp, vval(BASENAME), i); |
| 666 |
> |
sprintf(cp, fbase, i); |
| 667 |
|
while (*cp) cp++; |
| 668 |
|
strcpy(cp, ".pic"); |
| 669 |
|
cp += 4; |
| 682 |
|
int frame; |
| 683 |
|
VIEW *vp; |
| 684 |
|
{ |
| 685 |
+ |
extern int recover(); |
| 686 |
|
char combuf[2048]; |
| 687 |
|
char fname[128]; |
| 688 |
|
|
| 690 |
|
strcat(fname, ".unf"); |
| 691 |
|
if (access(fname, F_OK) == 0) |
| 692 |
|
return; |
| 693 |
< |
sprintf(combuf, "%s %d | rpict%s%s %s > %s", vval(ANIMATE), frame, |
| 693 |
> |
sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame, |
| 694 |
|
rendopt, viewopt(vp), rresopt, fname); |
| 695 |
< |
if (runcom(combuf)) { |
| 552 |
< |
fprintf(stderr, "%s: error rendering frame %d\n", |
| 553 |
< |
progname, frame); |
| 554 |
< |
quit(1); |
| 555 |
< |
} |
| 695 |
> |
bruncom(combuf, frame, recover); /* run in background */ |
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
|
| 559 |
– |
animwait(nwait) /* wait for renderings to finish */ |
| 560 |
– |
int nwait; |
| 561 |
– |
{ |
| 562 |
– |
/* currently does nothing since parallel rendering not working */ |
| 563 |
– |
} |
| 564 |
– |
|
| 565 |
– |
|
| 699 |
|
walkwait(first, last, vfn) /* walk-through frames */ |
| 700 |
|
int first, last; |
| 701 |
|
char *vfn; |
| 702 |
|
{ |
| 703 |
|
char combuf[2048]; |
| 704 |
+ |
char *inspoint; |
| 705 |
|
register int i; |
| 706 |
|
|
| 707 |
|
if (!noaction && vint(INTERP)) /* create dummy frames */ |
| 712 |
|
close(open(combuf, O_RDONLY|O_CREAT, 0666)); |
| 713 |
|
} |
| 714 |
|
/* create command */ |
| 715 |
< |
sprintf(combuf, "rpict%s ", rendopt); |
| 715 |
> |
sprintf(combuf, "rpict%s -w0", rendopt); |
| 716 |
|
if (vint(INTERP) || atoi(vval(MBLUR))) |
| 717 |
< |
sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME)); |
| 718 |
< |
sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s", |
| 719 |
< |
vval(BASENAME), rresopt, first, vval(OCTREE), vfn); |
| 720 |
< |
if (runcom(combuf)) { |
| 721 |
< |
fprintf(stderr, |
| 722 |
< |
"%s: error rendering walk-through frames %d through %d\n", |
| 717 |
> |
sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); |
| 718 |
> |
sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", |
| 719 |
> |
vval(BASENAME), rresopt, first); |
| 720 |
> |
inspoint = combuf + strlen(combuf); |
| 721 |
> |
sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); |
| 722 |
> |
/* run in parallel */ |
| 723 |
> |
i = (last-first+1)/(vint(INTERP)+1); |
| 724 |
> |
if (i < 1) i = 1; |
| 725 |
> |
if (pruncom(combuf, inspoint, i)) { |
| 726 |
> |
fprintf(stderr, "%s: error rendering frames %d through %d\n", |
| 727 |
|
progname, first, last); |
| 728 |
|
quit(1); |
| 729 |
|
} |
| 737 |
|
} |
| 738 |
|
|
| 739 |
|
|
| 740 |
+ |
int |
| 741 |
|
recover(frame) /* recover the specified frame */ |
| 742 |
|
int frame; |
| 743 |
|
{ |
| 744 |
+ |
static int *rfrm; /* list of recovered frames */ |
| 745 |
+ |
static int nrfrms = 0; |
| 746 |
|
char combuf[2048]; |
| 747 |
|
char fname[128]; |
| 748 |
|
register char *cp; |
| 749 |
< |
|
| 749 |
> |
register int i; |
| 750 |
> |
/* check to see if recovered already */ |
| 751 |
> |
for (i = nrfrms; i--; ) |
| 752 |
> |
if (rfrm[i] == frame) |
| 753 |
> |
return(0); |
| 754 |
> |
/* build command */ |
| 755 |
|
sprintf(fname, vval(BASENAME), frame); |
| 756 |
|
if (vdef(ANIMATE)) |
| 757 |
< |
sprintf(combuf, "%s %d | rpict%s", |
| 757 |
> |
sprintf(combuf, "%s %d | rpict%s -w0", |
| 758 |
|
vval(ANIMATE), frame, rendopt); |
| 759 |
|
else |
| 760 |
< |
sprintf(combuf, "rpict%s", rendopt); |
| 760 |
> |
sprintf(combuf, "rpict%s -w0", rendopt); |
| 761 |
|
cp = combuf + strlen(combuf); |
| 762 |
|
if (vint(INTERP) || atoi(vval(MBLUR))) { |
| 763 |
|
sprintf(cp, " -z %s.zbf", fname); |
| 769 |
|
*cp++ = ' '; |
| 770 |
|
strcpy(cp, vval(OCTREE)); |
| 771 |
|
} |
| 772 |
< |
if (runcom(combuf)) { |
| 773 |
< |
fprintf(stderr, "%s: error recovering frame %d\n", |
| 774 |
< |
progname, frame); |
| 772 |
> |
if (runcom(combuf)) /* run command */ |
| 773 |
> |
return(1); |
| 774 |
> |
/* add frame to recovered list */ |
| 775 |
> |
if (nrfrms) |
| 776 |
> |
rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); |
| 777 |
> |
else |
| 778 |
> |
rfrm = (int *)malloc(sizeof(int)); |
| 779 |
> |
if (rfrm == NULL) { |
| 780 |
> |
perror("malloc"); |
| 781 |
|
quit(1); |
| 782 |
|
} |
| 783 |
+ |
rfrm[nrfrms++] = frame; |
| 784 |
+ |
return(0); |
| 785 |
|
} |
| 786 |
|
|
| 787 |
|
|
| 788 |
< |
archive(first, last) /* archive finished renderings */ |
| 789 |
< |
int first, last; |
| 788 |
> |
int |
| 789 |
> |
frecover(frame) /* recover filtered frame */ |
| 790 |
> |
int frame; |
| 791 |
|
{ |
| 792 |
< |
char combuf[10240]; |
| 793 |
< |
int offset; |
| 639 |
< |
struct stat stb; |
| 640 |
< |
register char *cp; |
| 641 |
< |
register int i; |
| 792 |
> |
VIEW *vp; |
| 793 |
> |
char *ex; |
| 794 |
|
|
| 795 |
< |
strcpy(cp=combuf, vval(ARCHIVE)); |
| 796 |
< |
while (*cp) cp++; |
| 797 |
< |
offset = cp - combuf; |
| 798 |
< |
*cp++ = ' '; /* make argument list */ |
| 799 |
< |
for (i = first; i <= last; i++) { |
| 800 |
< |
sprintf(cp, vval(BASENAME), i); |
| 801 |
< |
strcat(cp, ".unf"); |
| 802 |
< |
if (stat(cp, &stb) == 0 && stb.st_size > 0) { /* non-zero? */ |
| 803 |
< |
while (*cp) cp++; |
| 804 |
< |
*cp++ = ' '; |
| 805 |
< |
sprintf(cp, vval(BASENAME), i); |
| 806 |
< |
strcat(cp, ".zbf"); |
| 807 |
< |
if (access(cp, F_OK) == 0) { /* exists? */ |
| 808 |
< |
while (*cp) cp++; |
| 809 |
< |
*cp++ = ' '; |
| 810 |
< |
} |
| 795 |
> |
vp = getview(frame); |
| 796 |
> |
ex = getexp(frame); |
| 797 |
> |
if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) |
| 798 |
> |
return(1); |
| 799 |
> |
return(0); |
| 800 |
> |
} |
| 801 |
> |
|
| 802 |
> |
|
| 803 |
> |
archive() /* archive and remove renderings */ |
| 804 |
> |
{ |
| 805 |
> |
#define RMCOML (sizeof(rmcom)-1) |
| 806 |
> |
static char rmcom[] = "rm -f"; |
| 807 |
> |
char basedir[128]; |
| 808 |
> |
int dlen, alen; |
| 809 |
> |
register int j; |
| 810 |
> |
|
| 811 |
> |
if (arcnext == arcfirst) |
| 812 |
> |
return; /* nothing to do */ |
| 813 |
> |
dirfile(basedir, vval(BASENAME)); |
| 814 |
> |
dlen = strlen(basedir); |
| 815 |
> |
if (vdef(ARCHIVE)) { /* run archive command */ |
| 816 |
> |
alen = strlen(vval(ARCHIVE)); |
| 817 |
> |
if (dlen) { |
| 818 |
> |
j = alen + dlen + 5; |
| 819 |
> |
strncpy(arcfirst-j, "cd ", 3); |
| 820 |
> |
strncpy(arcfirst-j+3, basedir, dlen); |
| 821 |
> |
(arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; |
| 822 |
> |
} else |
| 823 |
> |
j = alen; |
| 824 |
> |
strncpy(arcfirst-alen, vval(ARCHIVE), alen); |
| 825 |
> |
if (runcom(arcfirst-j)) { |
| 826 |
> |
fprintf(stderr, "%s: error running archive command\n", |
| 827 |
> |
progname); |
| 828 |
> |
quit(1); |
| 829 |
|
} |
| 830 |
|
} |
| 831 |
< |
*--cp = '\0'; |
| 832 |
< |
if (cp <= combuf + offset) /* no files? */ |
| 833 |
< |
return; |
| 834 |
< |
if (runcom(combuf)) { /* run archive command */ |
| 835 |
< |
fprintf(stderr, |
| 836 |
< |
"%s: error running archive command on frames %d through %d\n", |
| 837 |
< |
progname, first, last); |
| 838 |
< |
quit(1); |
| 839 |
< |
} |
| 831 |
> |
if (dlen) { |
| 832 |
> |
j = RMCOML + dlen + 5; |
| 833 |
> |
strncpy(arcfirst-j, "cd ", 3); |
| 834 |
> |
strncpy(arcfirst-j+3, basedir, dlen); |
| 835 |
> |
(arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; |
| 836 |
> |
} else |
| 837 |
> |
j = RMCOML; |
| 838 |
> |
/* run remove command */ |
| 839 |
> |
strncpy(arcfirst-RMCOML, rmcom, RMCOML); |
| 840 |
> |
runcom(arcfirst-j); |
| 841 |
> |
arcnext = arcfirst; /* reset argument list */ |
| 842 |
> |
#undef RMCOML |
| 843 |
|
} |
| 844 |
|
|
| 845 |
|
|
| 846 |
< |
dofilt(frame, vp, ep) /* filter frame */ |
| 846 |
> |
int |
| 847 |
> |
dofilt(frame, vp, ep, rvr) /* filter frame */ |
| 848 |
|
int frame; |
| 849 |
|
VIEW *vp; |
| 850 |
|
char *ep; |
| 851 |
+ |
int rvr; |
| 852 |
|
{ |
| 853 |
< |
char fnbefore[128], fnafter[128]; |
| 854 |
< |
char combuf[1024], fname[128]; |
| 855 |
< |
int usepinterp, usepfilt; |
| 856 |
< |
int frbefore, frafter, triesleft; |
| 853 |
> |
extern int frecover(); |
| 854 |
> |
static int iter = 0; |
| 855 |
> |
char fnbefore[128], fnafter[128], *fbase; |
| 856 |
> |
char combuf[1024], fname0[128], fname1[128]; |
| 857 |
> |
int usepinterp, usepfilt, nora_rgbe; |
| 858 |
> |
int frseq[2]; |
| 859 |
|
/* check what is needed */ |
| 860 |
|
usepinterp = atoi(vval(MBLUR)); |
| 861 |
|
usepfilt = pfiltalways | ep==NULL; |
| 862 |
+ |
if (ep != NULL && !strcmp(ep, "1")) |
| 863 |
+ |
ep = "+0"; |
| 864 |
+ |
nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || |
| 865 |
+ |
*ep != '+' || *ep != '-' || !isint(ep); |
| 866 |
|
/* compute rendered views */ |
| 867 |
< |
frbefore = frame - ((frame-1) % (vint(INTERP)+1)); |
| 868 |
< |
frafter = frbefore + vint(INTERP) + 1; |
| 869 |
< |
if (frafter > vint(END)) |
| 870 |
< |
frafter = vint(END); |
| 871 |
< |
if (frafter == frame) { /* pfilt only */ |
| 872 |
< |
frbefore = frafter; |
| 867 |
> |
frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); |
| 868 |
> |
frseq[1] = frseq[0] + vint(INTERP) + 1; |
| 869 |
> |
fbase = dirfile(NULL, vval(BASENAME)); |
| 870 |
> |
if (frseq[1] > vint(END)) |
| 871 |
> |
frseq[1] = vint(END); |
| 872 |
> |
if (frseq[1] == frame) { /* pfilt only */ |
| 873 |
> |
frseq[0] = frseq[1]; |
| 874 |
|
usepinterp = 0; /* update what's needed */ |
| 875 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
| 876 |
< |
triesleft = 2; |
| 877 |
< |
} else if (frbefore == frame) { /* no interpolation */ |
| 878 |
< |
/* remove unneeded files */ |
| 879 |
< |
if (frbefore-vint(INTERP)-1 >= 1) { |
| 880 |
< |
sprintf(fname, vval(BASENAME), frbefore-vint(INTERP)-1); |
| 881 |
< |
sprintf(combuf, "rm -f %s.unf %s.zbf", fname, fname); |
| 882 |
< |
runcom(combuf); |
| 875 |
> |
usepfilt |= nora_rgbe; |
| 876 |
> |
} else if (frseq[0] == frame) { /* no interpolation needed */ |
| 877 |
> |
if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ |
| 878 |
> |
*arcnext++ = ' '; |
| 879 |
> |
sprintf(arcnext, fbase, frame-vint(INTERP)-1); |
| 880 |
> |
while (*arcnext) arcnext++; |
| 881 |
> |
strcpy(arcnext, ".unf"); |
| 882 |
> |
arcnext += 4; |
| 883 |
> |
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
| 884 |
> |
*arcnext++ = ' '; |
| 885 |
> |
sprintf(arcnext, fbase, frame-vint(INTERP)-1); |
| 886 |
> |
while (*arcnext) arcnext++; |
| 887 |
> |
strcpy(arcnext, ".zbf"); |
| 888 |
> |
arcnext += 4; |
| 889 |
> |
} |
| 890 |
|
} |
| 891 |
< |
/* update what's needed */ |
| 892 |
< |
if (usepinterp) |
| 893 |
< |
triesleft = 3; |
| 705 |
< |
else { |
| 706 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
| 707 |
< |
triesleft = 2; |
| 708 |
< |
} |
| 709 |
< |
} else { /* interpolation needed */ |
| 891 |
> |
if (!usepinterp) /* update what's needed */ |
| 892 |
> |
usepfilt |= nora_rgbe; |
| 893 |
> |
} else /* interpolation needed */ |
| 894 |
|
usepinterp++; |
| 895 |
< |
triesleft = 3; |
| 896 |
< |
} |
| 897 |
< |
if (frafter >= astat.rnext) { /* next batch unavailable */ |
| 898 |
< |
frafter = frbefore; |
| 899 |
< |
if (triesleft > 2) |
| 900 |
< |
triesleft = 2; |
| 901 |
< |
} |
| 718 |
< |
sprintf(fnbefore, vval(BASENAME), frbefore); |
| 719 |
< |
sprintf(fnafter, vval(BASENAME), frafter); |
| 720 |
< |
tryit: /* generate command */ |
| 895 |
> |
if (frseq[1] >= astat.rnext) /* next batch unavailable */ |
| 896 |
> |
frseq[1] = frseq[0]; |
| 897 |
> |
sprintf(fnbefore, vval(BASENAME), frseq[0]); |
| 898 |
> |
sprintf(fnafter, vval(BASENAME), frseq[1]); |
| 899 |
> |
if (rvr == 1 && recover(frseq[0])) /* recover before frame? */ |
| 900 |
> |
return(1); |
| 901 |
> |
/* generate command */ |
| 902 |
|
if (usepinterp) { /* using pinterp */ |
| 903 |
+ |
if (rvr == 2 && recover(frseq[1])) /* recover after? */ |
| 904 |
+ |
return(1); |
| 905 |
|
if (atoi(vval(MBLUR))) { |
| 906 |
< |
FILE *fp; /* motion blurring */ |
| 907 |
< |
sprintf(fname, "%s/vw0", vval(DIRECTORY)); |
| 908 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
| 909 |
< |
perror(fname); quit(1); |
| 910 |
< |
} |
| 911 |
< |
fputs(VIEWSTR, fp); |
| 912 |
< |
fprintview(vp, fp); |
| 913 |
< |
putc('\n', fp); fclose(fp); |
| 914 |
< |
if ((vp = getview(frame+1)) == NULL) { |
| 915 |
< |
fprintf(stderr, |
| 906 |
> |
sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), |
| 907 |
> |
'a'+(iter%26)); |
| 908 |
> |
sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), |
| 909 |
> |
'a'+(iter%26)); |
| 910 |
> |
if (!noaction) { |
| 911 |
> |
FILE *fp; /* motion blurring */ |
| 912 |
> |
if ((fp = fopen(fname0, "w")) == NULL) { |
| 913 |
> |
perror(fname0); quit(1); |
| 914 |
> |
} |
| 915 |
> |
fputs(VIEWSTR, fp); |
| 916 |
> |
fprintview(vp, fp); |
| 917 |
> |
putc('\n', fp); fclose(fp); |
| 918 |
> |
if ((vp = getview(frame+1)) == NULL) { |
| 919 |
> |
fprintf(stderr, |
| 920 |
|
"%s: unexpected error reading view for frame %d\n", |
| 921 |
< |
progname, frame+1); |
| 922 |
< |
quit(1); |
| 921 |
> |
progname, frame+1); |
| 922 |
> |
quit(1); |
| 923 |
> |
} |
| 924 |
> |
if ((fp = fopen(fname1, "w")) == NULL) { |
| 925 |
> |
perror(fname1); quit(1); |
| 926 |
> |
} |
| 927 |
> |
fputs(VIEWSTR, fp); |
| 928 |
> |
fprintview(vp, fp); |
| 929 |
> |
putc('\n', fp); fclose(fp); |
| 930 |
|
} |
| 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); |
| 931 |
|
sprintf(combuf, |
| 932 |
< |
"(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B", |
| 933 |
< |
*sskip(vval(MBLUR)) ? sskip(vval(MBLUR)) : "1", |
| 934 |
< |
atoi(vval(MBLUR)), vval(DIRECTORY), |
| 935 |
< |
vval(DIRECTORY), vval(DIRECTORY), |
| 936 |
< |
vval(DIRECTORY), vval(DIRECTORY)); |
| 932 |
> |
"(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", |
| 933 |
> |
*sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", |
| 934 |
> |
atoi(vval(MBLUR)), |
| 935 |
> |
fname0, fname1, fname0, fname1); |
| 936 |
> |
iter++; |
| 937 |
|
} else /* no blurring */ |
| 938 |
|
strcpy(combuf, "pinterp"); |
| 939 |
|
strcat(combuf, viewopt(vp)); |
| 940 |
|
if (vbool(RTRACE)) |
| 941 |
< |
sprintf(combuf+strlen(combuf), " -ff -fr '%s %s'", |
| 942 |
< |
rendopt, vval(OCTREE)); |
| 941 |
> |
sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", |
| 942 |
> |
rendopt+1, vval(OCTREE)); |
| 943 |
|
if (vdef(PINTERP)) |
| 944 |
|
sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); |
| 945 |
|
if (usepfilt) |
| 949 |
|
fresopt, ep); |
| 950 |
|
sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", |
| 951 |
|
fnbefore, fnbefore); |
| 952 |
< |
if (frafter != frbefore) |
| 952 |
> |
if (frseq[1] != frseq[0]) |
| 953 |
|
sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", |
| 954 |
|
fnafter, fnafter); |
| 955 |
|
if (usepfilt) { /* also pfilt */ |
| 965 |
|
sprintf(combuf+strlen(combuf), " %s", fresopt); |
| 966 |
|
} |
| 967 |
|
} else if (usepfilt) { /* pfilt only */ |
| 968 |
+ |
if (rvr == 2) |
| 969 |
+ |
return(1); |
| 970 |
|
if (vdef(PFILT)) |
| 971 |
|
sprintf(combuf, "pfilt %s", vval(PFILT)); |
| 972 |
|
else |
| 978 |
|
sprintf(combuf+strlen(combuf), " %s %s.unf", |
| 979 |
|
fresopt, fnbefore); |
| 980 |
|
} else { /* else just check it */ |
| 981 |
< |
sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore); |
| 981 |
> |
if (rvr == 2) |
| 982 |
> |
return(1); |
| 983 |
> |
sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); |
| 984 |
|
} |
| 985 |
|
/* output file name */ |
| 986 |
< |
sprintf(fname, vval(BASENAME), frame); |
| 987 |
< |
sprintf(combuf+strlen(combuf), " > %s.pic", fname); |
| 988 |
< |
if (runcom(combuf)) /* run filter command */ |
| 989 |
< |
switch (--triesleft) { |
| 990 |
< |
case 2: /* try to recover frafter */ |
| 991 |
< |
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 |
< |
} |
| 986 |
> |
sprintf(fname0, vval(BASENAME), frame); |
| 987 |
> |
sprintf(combuf+strlen(combuf), " > %s.pic", fname0); |
| 988 |
> |
if (rvr) /* in recovery */ |
| 989 |
> |
return(runcom(combuf)); |
| 990 |
> |
bruncom(combuf, frame, frecover); /* else run in background */ |
| 991 |
> |
return(0); |
| 992 |
|
} |
| 993 |
|
|
| 994 |
|
|
| 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 |
– |
|
| 995 |
|
VIEW * |
| 996 |
|
getview(n) /* get view number n */ |
| 997 |
|
int n; |
| 1010 |
|
} |
| 1011 |
|
return(NULL); |
| 1012 |
|
} |
| 1013 |
< |
if (viewfp == NULL) { /* open file */ |
| 1013 |
> |
if (viewfp == NULL) { /* open file */ |
| 1014 |
|
if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { |
| 1015 |
|
perror(vval(VIEWFILE)); |
| 1016 |
|
quit(1); |
| 1017 |
|
} |
| 1018 |
< |
} else if (n < viewnum) { /* rewind file */ |
| 1018 |
> |
} else if (n > 0 && n < viewnum) { /* rewind file */ |
| 1019 |
> |
if (viewnum == 1 && feof(viewfp)) |
| 1020 |
> |
return(&curview); /* just one view */ |
| 1021 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
| 1022 |
|
perror(vval(VIEWFILE)); |
| 1023 |
|
quit(1); |
| 1025 |
|
copystruct(&curview, &stdview); |
| 1026 |
|
viewnum = 0; |
| 1027 |
|
} |
| 1028 |
+ |
if (n < 0) { /* get next view */ |
| 1029 |
+ |
register int c = getc(viewfp); |
| 1030 |
+ |
if (c == EOF) |
| 1031 |
+ |
return((VIEW *)NULL); /* that's it */ |
| 1032 |
+ |
ungetc(c, viewfp); |
| 1033 |
+ |
n = viewnum + 1; |
| 1034 |
+ |
} |
| 1035 |
|
while (n > viewnum) { /* scan to desired view */ |
| 1036 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
| 1037 |
< |
return(NULL); |
| 1037 |
> |
return(viewnum==1 ? &curview : (VIEW *)NULL); |
| 1038 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
| 1039 |
|
viewnum++; |
| 1040 |
|
} |
| 1045 |
|
int |
| 1046 |
|
countviews() /* count views in view file */ |
| 1047 |
|
{ |
| 1048 |
< |
register int n = 0; |
| 1048 |
> |
int n; |
| 1049 |
|
|
| 1050 |
< |
while (getview(n+1) != NULL) |
| 1050 |
> |
if (getview(n=1) == NULL) |
| 1051 |
> |
return(0); |
| 1052 |
> |
while (getview(-1) != NULL) |
| 1053 |
|
n++; |
| 1054 |
|
return(n); |
| 1055 |
|
} |
| 1069 |
|
if (n == 0) { /* signal to close file */ |
| 1070 |
|
if (expfp != NULL) { |
| 1071 |
|
fclose(expfp); |
| 1072 |
+ |
free((char *)exppos); |
| 1073 |
|
expfp = NULL; |
| 1074 |
|
} |
| 1075 |
|
return(NULL); |
| 1076 |
< |
} |
| 1076 |
> |
} else if (n > vint(END)) /* request past end (error?) */ |
| 1077 |
> |
return(NULL); |
| 1078 |
|
if (!vdef(EXPOSURE)) /* no setting (auto) */ |
| 1079 |
|
return(NULL); |
| 1080 |
|
if (isflt(vval(EXPOSURE))) /* always the same */ |
| 1112 |
|
} |
| 1113 |
|
curfrm++; |
| 1114 |
|
cp = fskip(expval); /* check format */ |
| 1115 |
< |
if (cp == NULL || *cp != '\n') { |
| 1115 |
> |
if (cp != NULL) |
| 1116 |
> |
while (isspace(*cp)) |
| 1117 |
> |
*cp++ = '\0'; |
| 1118 |
> |
if (cp == NULL || *cp) { |
| 1119 |
|
fprintf(stderr, |
| 1120 |
|
"%s: exposure format error on line %d\n", |
| 1121 |
|
vval(EXPOSURE), curfrm); |
| 1122 |
|
quit(1); |
| 1123 |
|
} |
| 934 |
– |
*cp = '\0'; |
| 1124 |
|
} |
| 1125 |
|
return(expval); /* return value */ |
| 1126 |
|
} |
| 1127 |
|
|
| 1128 |
|
|
| 1129 |
< |
runcom(cs) /* run command */ |
| 1129 |
> |
struct pslot * |
| 1130 |
> |
findpslot(pid) /* find or allocate a process slot */ |
| 1131 |
> |
int pid; |
| 1132 |
> |
{ |
| 1133 |
> |
register struct pslot *psempty = NULL; |
| 1134 |
> |
register int i; |
| 1135 |
> |
|
| 1136 |
> |
for (i = 0; i < npslots; i++) { /* look for match */ |
| 1137 |
> |
if (pslot[i].pid == pid) |
| 1138 |
> |
return(pslot+i); |
| 1139 |
> |
if (psempty == NULL && pslot[i].pid == 0) |
| 1140 |
> |
psempty = pslot+i; |
| 1141 |
> |
} |
| 1142 |
> |
return(psempty); /* return emtpy slot (error if NULL) */ |
| 1143 |
> |
} |
| 1144 |
> |
|
| 1145 |
> |
|
| 1146 |
> |
int |
| 1147 |
> |
donecom(ps, pn, status) /* clean up after finished process */ |
| 1148 |
> |
PSERVER *ps; |
| 1149 |
> |
int pn; |
| 1150 |
> |
int status; |
| 1151 |
> |
{ |
| 1152 |
> |
register PROC *pp; |
| 1153 |
> |
register struct pslot *psl; |
| 1154 |
> |
|
| 1155 |
> |
pp = ps->proc + pn; |
| 1156 |
> |
if (pp->elen) { /* pass errors */ |
| 1157 |
> |
if (ps->hostname[0]) |
| 1158 |
> |
fprintf(stderr, "%s: ", ps->hostname); |
| 1159 |
> |
fprintf(stderr, "Error output from: %s\n", pp->com); |
| 1160 |
> |
fputs(pp->errs, stderr); |
| 1161 |
> |
fflush(stderr); |
| 1162 |
> |
if (ps->hostname[0]) |
| 1163 |
> |
status = 1; /* because rsh doesn't return status */ |
| 1164 |
> |
} |
| 1165 |
> |
lastpserver = NULL; |
| 1166 |
> |
psl = findpslot(pp->pid); /* check for bruncom() slot */ |
| 1167 |
> |
if (psl->pid) { |
| 1168 |
> |
if (status) { |
| 1169 |
> |
if (psl->rcvf != NULL) /* attempt recovery */ |
| 1170 |
> |
status = (*psl->rcvf)(psl->fout); |
| 1171 |
> |
if (status) { |
| 1172 |
> |
fprintf(stderr, |
| 1173 |
> |
"%s: error rendering frame %d\n", |
| 1174 |
> |
progname, psl->fout); |
| 1175 |
> |
quit(1); |
| 1176 |
> |
} |
| 1177 |
> |
lastpserver = ps; |
| 1178 |
> |
} |
| 1179 |
> |
psl->pid = 0; /* free process slot */ |
| 1180 |
> |
} else if (status) |
| 1181 |
> |
lastpserver = ps; |
| 1182 |
> |
freestr(pp->com); /* free command string */ |
| 1183 |
> |
return(status); |
| 1184 |
> |
} |
| 1185 |
> |
|
| 1186 |
> |
|
| 1187 |
> |
int |
| 1188 |
> |
serverdown() /* check status of last process server */ |
| 1189 |
> |
{ |
| 1190 |
> |
if (lastpserver == NULL || !lastpserver->hostname[0]) |
| 1191 |
> |
return(0); |
| 1192 |
> |
if (pserverOK(lastpserver)) /* server still up? */ |
| 1193 |
> |
return(0); |
| 1194 |
> |
delpserver(lastpserver); /* else delete it */ |
| 1195 |
> |
if (pslist == NULL) { |
| 1196 |
> |
fprintf(stderr, "%s: all process servers are down\n", |
| 1197 |
> |
progname); |
| 1198 |
> |
quit(1); |
| 1199 |
> |
} |
| 1200 |
> |
return(1); |
| 1201 |
> |
} |
| 1202 |
> |
|
| 1203 |
> |
|
| 1204 |
> |
int |
| 1205 |
> |
bruncom(com, fout, rf) /* run a command in the background */ |
| 1206 |
> |
char *com; |
| 1207 |
> |
int fout; |
| 1208 |
> |
int (*rf)(); |
| 1209 |
> |
{ |
| 1210 |
> |
int pid; |
| 1211 |
> |
register struct pslot *psl; |
| 1212 |
> |
|
| 1213 |
> |
if (noaction) { |
| 1214 |
> |
if (!silent) |
| 1215 |
> |
printf("\t%s\n", com); /* echo command */ |
| 1216 |
> |
return(0); |
| 1217 |
> |
} |
| 1218 |
> |
com = savestr(com); /* else start it when we can */ |
| 1219 |
> |
while ((pid = startjob(NULL, com, donecom)) == -1) |
| 1220 |
> |
bwait(1); |
| 1221 |
> |
if (!silent) { /* echo command */ |
| 1222 |
> |
PSERVER *ps; |
| 1223 |
> |
int psn = pid; |
| 1224 |
> |
ps = findjob(&psn); |
| 1225 |
> |
printf("\t%s\n", com); |
| 1226 |
> |
printf("\tProcess started on %s\n", phostname(ps)); |
| 1227 |
> |
fflush(stdout); |
| 1228 |
> |
} |
| 1229 |
> |
psl = findpslot(pid); /* record info. in appropriate slot */ |
| 1230 |
> |
psl->pid = pid; |
| 1231 |
> |
psl->fout = fout; |
| 1232 |
> |
psl->rcvf = rf; |
| 1233 |
> |
return(pid); |
| 1234 |
> |
} |
| 1235 |
> |
|
| 1236 |
> |
|
| 1237 |
> |
bwait(ncoms) /* wait for batch job(s) to finish */ |
| 1238 |
> |
int ncoms; |
| 1239 |
> |
{ |
| 1240 |
> |
int status; |
| 1241 |
> |
|
| 1242 |
> |
if (noaction) |
| 1243 |
> |
return; |
| 1244 |
> |
while ((status = wait4job(NULL, -1)) != -1) { |
| 1245 |
> |
serverdown(); /* update server status */ |
| 1246 |
> |
if (--ncoms == 0) |
| 1247 |
> |
break; /* done enough */ |
| 1248 |
> |
} |
| 1249 |
> |
} |
| 1250 |
> |
|
| 1251 |
> |
|
| 1252 |
> |
int |
| 1253 |
> |
pruncom(com, ppins, maxcopies) /* run a command in parallel over network */ |
| 1254 |
> |
char *com, *ppins; |
| 1255 |
> |
int maxcopies; |
| 1256 |
> |
{ |
| 1257 |
> |
int retstatus = 0; |
| 1258 |
> |
int hostcopies; |
| 1259 |
> |
char buf[10240], *com1, *s; |
| 1260 |
> |
int status; |
| 1261 |
> |
int pfd; |
| 1262 |
> |
register int n; |
| 1263 |
> |
register PSERVER *ps; |
| 1264 |
> |
|
| 1265 |
> |
if (!silent) |
| 1266 |
> |
printf("\t%s\n", com); /* echo command */ |
| 1267 |
> |
if (noaction) |
| 1268 |
> |
return(0); |
| 1269 |
> |
fflush(stdout); |
| 1270 |
> |
/* start jobs on each server */ |
| 1271 |
> |
for (ps = pslist; ps != NULL; ps = ps->next) { |
| 1272 |
> |
hostcopies = 0; |
| 1273 |
> |
if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { |
| 1274 |
> |
strcpy(com1=buf, com); /* build -PP command */ |
| 1275 |
> |
sprintf(com1+(ppins-com), " -PP %s/%s.persist", |
| 1276 |
> |
vval(DIRECTORY), phostname(ps)); |
| 1277 |
> |
strcat(com1, ppins); |
| 1278 |
> |
} else |
| 1279 |
> |
com1 = com; |
| 1280 |
> |
while (maxcopies > 0) { |
| 1281 |
> |
s = savestr(com1); |
| 1282 |
> |
if (startjob(ps, s, donecom) != -1) { |
| 1283 |
> |
sleep(20); |
| 1284 |
> |
hostcopies++; |
| 1285 |
> |
maxcopies--; |
| 1286 |
> |
} else { |
| 1287 |
> |
freestr(s); |
| 1288 |
> |
break; |
| 1289 |
> |
} |
| 1290 |
> |
} |
| 1291 |
> |
if (!silent && hostcopies) { |
| 1292 |
> |
if (hostcopies > 1) |
| 1293 |
> |
printf("\t%d duplicate processes", hostcopies); |
| 1294 |
> |
else |
| 1295 |
> |
printf("\tProcess"); |
| 1296 |
> |
printf(" started on %s\n", phostname(ps)); |
| 1297 |
> |
fflush(stdout); |
| 1298 |
> |
} |
| 1299 |
> |
} |
| 1300 |
> |
/* wait for jobs to finish */ |
| 1301 |
> |
while ((status = wait4job(NULL, -1)) != -1) |
| 1302 |
> |
retstatus += status && !serverdown(); |
| 1303 |
> |
/* terminate parallel rpict's */ |
| 1304 |
> |
for (ps = pslist; ps != NULL; ps = ps->next) { |
| 1305 |
> |
sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); |
| 1306 |
> |
if ((pfd = open(buf, O_RDONLY)) >= 0) { |
| 1307 |
> |
n = read(pfd, buf, sizeof(buf)-1); /* get PID */ |
| 1308 |
> |
buf[n] = '\0'; |
| 1309 |
> |
close(pfd); |
| 1310 |
> |
for (n = 0; buf[n] && !isspace(buf[n]); n++) |
| 1311 |
> |
; |
| 1312 |
> |
/* terminate */ |
| 1313 |
> |
sprintf(buf, "kill -ALRM %d", atoi(buf+n)); |
| 1314 |
> |
wait4job(ps, startjob(ps, buf, NULL)); |
| 1315 |
> |
} |
| 1316 |
> |
} |
| 1317 |
> |
return(retstatus); |
| 1318 |
> |
} |
| 1319 |
> |
|
| 1320 |
> |
|
| 1321 |
> |
runcom(cs) /* run a command locally and wait for it */ |
| 1322 |
|
char *cs; |
| 1323 |
|
{ |
| 1324 |
|
if (!silent) /* echo it */ |
| 1351 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
| 1352 |
|
progname, vnam(vc)); |
| 1353 |
|
quit(1); |
| 1354 |
+ |
} |
| 1355 |
+ |
|
| 1356 |
+ |
|
| 1357 |
+ |
char * |
| 1358 |
+ |
dirfile(df, path) /* separate path into directory and file */ |
| 1359 |
+ |
char *df; |
| 1360 |
+ |
register char *path; |
| 1361 |
+ |
{ |
| 1362 |
+ |
register int i; |
| 1363 |
+ |
int psep; |
| 1364 |
+ |
|
| 1365 |
+ |
for (i = 0, psep = -1; path[i]; i++) |
| 1366 |
+ |
if (path[i] == '/') |
| 1367 |
+ |
psep = i; |
| 1368 |
+ |
if (df != NULL) |
| 1369 |
+ |
if (psep == 0) { |
| 1370 |
+ |
df[0] = '/'; |
| 1371 |
+ |
df[1] = '\0'; |
| 1372 |
+ |
} else if (psep > 0) { |
| 1373 |
+ |
strncpy(df, path, psep); |
| 1374 |
+ |
df[psep] = '\0'; |
| 1375 |
+ |
} else |
| 1376 |
+ |
df[0] = '\0'; |
| 1377 |
+ |
return(path+psep+1); |
| 1378 |
|
} |