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"; |
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}, |
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 *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 */ |
118 |
|
VIEW *getview(); |
119 |
|
char *getexp(); |
120 |
|
|
121 |
+ |
extern time_t fdate(), time(); |
122 |
|
|
123 |
+ |
|
124 |
|
main(argc, argv) |
125 |
|
int argc; |
126 |
|
char *argv[]; |
177 |
|
argv[i] = vval(NEXTANIM); /* just change input file */ |
178 |
|
if (!silent) |
179 |
|
printargs(argc, argv, stdout); |
180 |
< |
execvp(progname, argv); /* pass to next */ |
181 |
< |
quit(1); /* shouldn't return */ |
180 |
> |
if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) |
181 |
> |
fprintf(stderr, "%s: command not found\n", progname); |
182 |
> |
else |
183 |
> |
execv(progname, argv); |
184 |
> |
quit(1); |
185 |
|
} |
186 |
|
quit(0); |
187 |
|
userr: |
192 |
|
|
193 |
|
getastat() /* check/set animation status */ |
194 |
|
{ |
195 |
< |
char buf[256]; |
195 |
> |
char sfname[256]; |
196 |
|
FILE *fp; |
197 |
|
|
198 |
< |
sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); |
199 |
< |
if ((fp = fopen(buf, "r")) == NULL) { |
198 |
> |
sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); |
199 |
> |
if ((fp = fopen(sfname, "r")) == NULL) { |
200 |
|
if (errno != ENOENT) { |
201 |
< |
perror(buf); |
201 |
> |
perror(sfname); |
202 |
|
return(-1); |
203 |
|
} |
204 |
|
astat.rnext = astat.fnext = astat.tnext = 0; |
218 |
|
goto fmterr; |
219 |
|
fclose(fp); |
220 |
|
if (astat.pid != 0) { /* thinks it's still running */ |
221 |
< |
gethostname(buf, sizeof(buf)); |
205 |
< |
if (strcmp(buf, astat.host)) { |
221 |
> |
if (strcmp(myhostname(), astat.host)) { |
222 |
|
fprintf(stderr, |
223 |
|
"%s: process %d may still be running on host %s\n", |
224 |
|
progname, astat.pid, astat.host); |
236 |
|
progname, astat.cfname); |
237 |
|
return(-1); |
238 |
|
} |
239 |
+ |
/* check control file mods. */ |
240 |
+ |
if (!nowarn && fdate(cfname) > fdate(sfname)) |
241 |
+ |
fprintf(stderr, |
242 |
+ |
"%s: warning - control file modified since last run\n", |
243 |
+ |
progname); |
244 |
|
setours: /* set our values */ |
245 |
< |
gethostname(astat.host, sizeof(astat.host)); |
245 |
> |
strcpy(astat.host, myhostname()); |
246 |
|
astat.pid = getpid(); |
247 |
|
strcpy(astat.cfname, cfname); |
248 |
|
return(0); |
249 |
|
fmterr: |
250 |
|
fprintf(stderr, "%s: format error in status file \"%s\"\n", |
251 |
< |
progname, buf); |
251 |
> |
progname, sfname); |
252 |
|
fclose(fp); |
253 |
|
return(-1); |
254 |
|
} |
300 |
|
|
301 |
|
setdefaults() /* set default values */ |
302 |
|
{ |
303 |
+ |
extern char *atos(); |
304 |
|
char buf[256]; |
305 |
|
|
306 |
|
if (vdef(ANIMATE)) { |
366 |
|
vval(DISKSPACE) = "100"; |
367 |
|
vdef(DISKSPACE)++; |
368 |
|
} |
369 |
+ |
if (!vdef(RSH)) { |
370 |
+ |
vval(RSH) = REMSH; |
371 |
+ |
vdef(RSH)++; |
372 |
+ |
} |
373 |
+ |
/* locate remote shell program */ |
374 |
+ |
atos(buf, sizeof(buf), vval(RSH)); |
375 |
+ |
if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) |
376 |
+ |
remsh = savqstr(remsh); |
377 |
+ |
else |
378 |
+ |
remsh = vval(RSH); /* will generate error if used */ |
379 |
+ |
|
380 |
|
/* append rendering options */ |
381 |
|
if (vdef(RENDER)) |
382 |
|
sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
< |
getradfile(rfname) /* run rad and get needed variables */ |
443 |
< |
char *rfname; |
442 |
> |
getradfile(rfargs) /* run rad and get needed variables */ |
443 |
> |
char *rfargs; |
444 |
|
{ |
445 |
|
static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; |
446 |
|
char combuf[256]; |
450 |
|
sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); |
451 |
|
sprintf(combuf, |
452 |
|
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
453 |
< |
rfname, rendopt+2); |
453 |
> |
rfargs, rendopt+2); |
454 |
|
cp = combuf; |
455 |
|
while (*cp) cp++; /* match unset variables */ |
456 |
|
for (i = 0; mvar[i] >= 0; i++) |
462 |
|
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
463 |
|
cp += 11; /* point to file name */ |
464 |
|
if (system(combuf)) { |
465 |
< |
fprintf(stderr, "%s: bad rad input file \"%s\"\n", |
466 |
< |
progname, rfname); |
465 |
> |
fprintf(stderr, "%s: error executing rad command:\n\t%s\n", |
466 |
> |
progname, combuf); |
467 |
|
quit(1); |
468 |
|
} |
469 |
|
loadvars(cp); /* load variables and remove file */ |
512 |
|
/* figure # frames per batch */ |
513 |
|
d1 = mult*xres*mult*yres*4; /* space for orig. picture */ |
514 |
|
if ((i=vint(INTERP)) || atoi(vval(MBLUR))) |
515 |
< |
d1 += mult*xres*mult*yres*4; /* space for z-buffer */ |
515 |
> |
d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ |
516 |
|
d2 = xres*yres*4; /* space for final picture */ |
517 |
|
frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); |
518 |
|
if (frames_batch < i+2) { |
520 |
|
progname); |
521 |
|
quit(1); |
522 |
|
} |
523 |
+ |
/* initialize archive argument list */ |
524 |
+ |
i = 16; |
525 |
+ |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) |
526 |
+ |
i = strlen(vval(ARCHIVE)); |
527 |
+ |
arcnext = arcfirst = arcargs + i; |
528 |
|
/* initialize status file */ |
529 |
|
if (astat.rnext == 0) |
530 |
|
astat.rnext = astat.fnext = astat.tnext = vint(START); |
619 |
|
dofilt(i, vp, getexp(i), 0); /* filter frame */ |
620 |
|
} |
621 |
|
bwait(0); /* wait for filter processes */ |
622 |
< |
archive(astat.fnext, i-1); /* archive originals */ |
622 |
> |
archive(); /* archive originals */ |
623 |
|
astat.fnext = i; /* update status */ |
624 |
|
putastat(); |
625 |
|
} |
700 |
|
inspoint = combuf + strlen(combuf); |
701 |
|
sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); |
702 |
|
/* run in parallel */ |
703 |
< |
if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) { |
703 |
> |
i = (last-first+1)/(vint(INTERP)+1); |
704 |
> |
if (i < 1) i = 1; |
705 |
> |
if (pruncom(combuf, inspoint, i)) { |
706 |
|
fprintf(stderr, "%s: error rendering frames %d through %d\n", |
707 |
|
progname, first, last); |
708 |
|
quit(1); |
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
< |
archive(first, last) /* archive and remove renderings */ |
744 |
< |
int first, last; |
783 |
> |
archive() /* archive and remove renderings */ |
784 |
|
{ |
785 |
|
#define RMCOML (sizeof(rmcom)-1) |
786 |
|
static char rmcom[] = "rm -f"; |
748 |
– |
int offset = RMCOML; |
749 |
– |
char combuf[10240]; |
750 |
– |
struct stat stb; |
751 |
– |
register char *cp; |
787 |
|
register int i; |
788 |
|
|
789 |
< |
if (noaction) |
790 |
< |
return; |
756 |
< |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset) |
757 |
< |
offset = strlen(vval(ARCHIVE)); |
758 |
< |
cp = combuf + offset; |
759 |
< |
*cp++ = ' '; /* make argument list */ |
760 |
< |
for (i = first; i <= last; i++) { |
761 |
< |
sprintf(cp, vval(BASENAME), i); |
762 |
< |
strcat(cp, ".unf"); |
763 |
< |
if (stat(cp, &stb) == 0 && stb.st_size > 0) { /* non-zero? */ |
764 |
< |
while (*cp) cp++; |
765 |
< |
*cp++ = ' '; |
766 |
< |
sprintf(cp, vval(BASENAME), i); |
767 |
< |
strcat(cp, ".zbf"); |
768 |
< |
if (access(cp, F_OK) == 0) { /* exists? */ |
769 |
< |
while (*cp) cp++; |
770 |
< |
*cp++ = ' '; |
771 |
< |
} |
772 |
< |
} |
773 |
< |
} |
774 |
< |
*--cp = '\0'; |
775 |
< |
if (cp <= combuf + offset) /* no files? */ |
776 |
< |
return; |
789 |
> |
if (arcnext == arcfirst) |
790 |
> |
return; /* nothing to do */ |
791 |
|
if (vdef(ARCHIVE)) { /* run archive command */ |
792 |
|
i = strlen(vval(ARCHIVE)); |
793 |
< |
strncpy(combuf+offset-i, vval(ARCHIVE), i); |
794 |
< |
if (runcom(combuf+offset-i)) { |
795 |
< |
fprintf(stderr, |
796 |
< |
"%s: error running archive command on frames %d through %d\n", |
783 |
< |
progname, first, last); |
793 |
> |
strncpy(arcfirst-i, vval(ARCHIVE), i); |
794 |
> |
if (runcom(arcfirst-i)) { |
795 |
> |
fprintf(stderr, "%s: error running archive command\n", |
796 |
> |
progname); |
797 |
|
quit(1); |
798 |
|
} |
799 |
|
} |
800 |
|
/* run remove command */ |
801 |
< |
strncpy(combuf+offset-RMCOML, rmcom, RMCOML); |
802 |
< |
runcom(combuf+offset-RMCOML); |
801 |
> |
strncpy(arcfirst-RMCOML, rmcom, RMCOML); |
802 |
> |
runcom(arcfirst-RMCOML); |
803 |
> |
arcnext = arcfirst; /* reset argument list */ |
804 |
|
#undef RMCOML |
805 |
|
} |
806 |
|
|
816 |
|
static int iter = 0; |
817 |
|
char fnbefore[128], fnafter[128]; |
818 |
|
char combuf[1024], fname0[128], fname1[128]; |
819 |
< |
int usepinterp, usepfilt; |
819 |
> |
int usepinterp, usepfilt, nora_rgbe; |
820 |
|
int frseq[2]; |
821 |
|
/* check what is needed */ |
822 |
|
usepinterp = atoi(vval(MBLUR)); |
823 |
|
usepfilt = pfiltalways | ep==NULL; |
824 |
+ |
if (ep != NULL && !strcmp(ep, "1")) |
825 |
+ |
ep = "+0"; |
826 |
+ |
nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || |
827 |
+ |
*ep != '+' || *ep != '-' || !isint(ep); |
828 |
|
/* compute rendered views */ |
829 |
|
frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); |
830 |
|
frseq[1] = frseq[0] + vint(INTERP) + 1; |
833 |
|
if (frseq[1] == frame) { /* pfilt only */ |
834 |
|
frseq[0] = frseq[1]; |
835 |
|
usepinterp = 0; /* update what's needed */ |
836 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
837 |
< |
} else if (frseq[0] == frame) { /* no interpolation */ |
838 |
< |
/* update what's needed */ |
839 |
< |
if (!usepinterp) |
840 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
836 |
> |
usepfilt |= nora_rgbe; |
837 |
> |
} else if (frseq[0] == frame) { /* no interpolation needed */ |
838 |
> |
if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ |
839 |
> |
*arcnext++ = ' '; |
840 |
> |
sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); |
841 |
> |
while (*arcnext) arcnext++; |
842 |
> |
strcpy(arcnext, ".unf"); |
843 |
> |
arcnext += 4; |
844 |
> |
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
845 |
> |
*arcnext++ = ' '; |
846 |
> |
sprintf(arcnext, vval(BASENAME), |
847 |
> |
frame-vint(INTERP)-1); |
848 |
> |
while (*arcnext) arcnext++; |
849 |
> |
strcpy(arcnext, ".zbf"); |
850 |
> |
arcnext += 4; |
851 |
> |
} |
852 |
> |
} |
853 |
> |
if (!usepinterp) /* update what's needed */ |
854 |
> |
usepfilt |= nora_rgbe; |
855 |
|
} else /* interpolation needed */ |
856 |
|
usepinterp++; |
857 |
|
if (frseq[1] >= astat.rnext) /* next batch unavailable */ |
940 |
|
} else { /* else just check it */ |
941 |
|
if (rvr == 2) |
942 |
|
return(1); |
943 |
< |
sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore); |
943 |
> |
sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); |
944 |
|
} |
945 |
|
/* output file name */ |
946 |
|
sprintf(fname0, vval(BASENAME), frame); |
976 |
|
quit(1); |
977 |
|
} |
978 |
|
} else if (n < viewnum) { /* rewind file */ |
979 |
+ |
if (viewnum == 1 && feof(viewfp)) |
980 |
+ |
return(&curview); /* just one view */ |
981 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
982 |
|
perror(vval(VIEWFILE)); |
983 |
|
quit(1); |
987 |
|
} |
988 |
|
while (n > viewnum) { /* scan to desired view */ |
989 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
990 |
< |
return(NULL); |
990 |
> |
return(viewnum==1 ? &curview : (VIEW *)NULL); |
991 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
992 |
|
viewnum++; |
993 |
|
} |
1020 |
|
if (n == 0) { /* signal to close file */ |
1021 |
|
if (expfp != NULL) { |
1022 |
|
fclose(expfp); |
1023 |
+ |
free((char *)exppos); |
1024 |
|
expfp = NULL; |
1025 |
|
} |
1026 |
|
return(NULL); |
1027 |
< |
} |
1027 |
> |
} else if (n > vint(END)) /* request past end (error?) */ |
1028 |
> |
return(NULL); |
1029 |
|
if (!vdef(EXPOSURE)) /* no setting (auto) */ |
1030 |
|
return(NULL); |
1031 |
|
if (isflt(vval(EXPOSURE))) /* always the same */ |
1063 |
|
} |
1064 |
|
curfrm++; |
1065 |
|
cp = fskip(expval); /* check format */ |
1066 |
< |
if (cp == NULL || *cp != '\n') { |
1066 |
> |
if (cp != NULL) |
1067 |
> |
while (isspace(*cp)) |
1068 |
> |
*cp++ = '\0'; |
1069 |
> |
if (cp == NULL || *cp) { |
1070 |
|
fprintf(stderr, |
1071 |
|
"%s: exposure format error on line %d\n", |
1072 |
|
vval(EXPOSURE), curfrm); |
1073 |
|
quit(1); |
1074 |
|
} |
1036 |
– |
*cp = '\0'; |
1075 |
|
} |
1076 |
|
return(expval); /* return value */ |
1077 |
|
} |