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 */ |
213 |
|
goto fmterr; |
214 |
|
fclose(fp); |
215 |
|
if (astat.pid != 0) { /* thinks it's still running */ |
216 |
< |
gethostname(buf, sizeof(buf)); |
205 |
< |
if (strcmp(buf, astat.host)) { |
216 |
> |
if (strcmp(myhostname(), astat.host)) { |
217 |
|
fprintf(stderr, |
218 |
|
"%s: process %d may still be running on host %s\n", |
219 |
|
progname, astat.pid, astat.host); |
232 |
|
return(-1); |
233 |
|
} |
234 |
|
setours: /* set our values */ |
235 |
< |
gethostname(astat.host, sizeof(astat.host)); |
235 |
> |
strcpy(astat.host, myhostname()); |
236 |
|
astat.pid = getpid(); |
237 |
|
strcpy(astat.cfname, cfname); |
238 |
|
return(0); |
290 |
|
|
291 |
|
setdefaults() /* set default values */ |
292 |
|
{ |
293 |
+ |
extern char *atos(); |
294 |
|
char buf[256]; |
295 |
|
|
296 |
|
if (vdef(ANIMATE)) { |
356 |
|
vval(DISKSPACE) = "100"; |
357 |
|
vdef(DISKSPACE)++; |
358 |
|
} |
359 |
+ |
if (!vdef(RSH)) { |
360 |
+ |
vval(RSH) = REMSH; |
361 |
+ |
vdef(RSH)++; |
362 |
+ |
} |
363 |
+ |
/* locate remote shell program */ |
364 |
+ |
atos(buf, sizeof(buf), vval(RSH)); |
365 |
+ |
if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) |
366 |
+ |
remsh = savqstr(remsh); |
367 |
+ |
else |
368 |
+ |
remsh = vval(RSH); /* will generate error if used */ |
369 |
+ |
|
370 |
|
/* append rendering options */ |
371 |
|
if (vdef(RENDER)) |
372 |
|
sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
< |
getradfile(rfname) /* run rad and get needed variables */ |
433 |
< |
char *rfname; |
432 |
> |
getradfile(rfargs) /* run rad and get needed variables */ |
433 |
> |
char *rfargs; |
434 |
|
{ |
435 |
|
static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; |
436 |
|
char combuf[256]; |
440 |
|
sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); |
441 |
|
sprintf(combuf, |
442 |
|
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
443 |
< |
rfname, rendopt+2); |
443 |
> |
rfargs, rendopt+2); |
444 |
|
cp = combuf; |
445 |
|
while (*cp) cp++; /* match unset variables */ |
446 |
|
for (i = 0; mvar[i] >= 0; i++) |
452 |
|
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
453 |
|
cp += 11; /* point to file name */ |
454 |
|
if (system(combuf)) { |
455 |
< |
fprintf(stderr, "%s: bad rad input file \"%s\"\n", |
456 |
< |
progname, rfname); |
455 |
> |
fprintf(stderr, "%s: error executing rad command:\n\t%s\n", |
456 |
> |
progname, combuf); |
457 |
|
quit(1); |
458 |
|
} |
459 |
|
loadvars(cp); /* load variables and remove file */ |
510 |
|
progname); |
511 |
|
quit(1); |
512 |
|
} |
513 |
+ |
/* initialize archive argument list */ |
514 |
+ |
i = 16; |
515 |
+ |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) |
516 |
+ |
i = strlen(vval(ARCHIVE)); |
517 |
+ |
arcnext = arcfirst = arcargs + i; |
518 |
|
/* initialize status file */ |
519 |
|
if (astat.rnext == 0) |
520 |
|
astat.rnext = astat.fnext = astat.tnext = vint(START); |
609 |
|
dofilt(i, vp, getexp(i), 0); /* filter frame */ |
610 |
|
} |
611 |
|
bwait(0); /* wait for filter processes */ |
612 |
< |
archive(astat.fnext, i-1); /* archive originals */ |
612 |
> |
archive(); /* archive originals */ |
613 |
|
astat.fnext = i; /* update status */ |
614 |
|
putastat(); |
615 |
|
} |
690 |
|
inspoint = combuf + strlen(combuf); |
691 |
|
sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); |
692 |
|
/* run in parallel */ |
693 |
< |
if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) { |
693 |
> |
i = (last-first+1)/(vint(INTERP)+1); |
694 |
> |
if (i < 1) i = 1; |
695 |
> |
if (pruncom(combuf, inspoint, i)) { |
696 |
|
fprintf(stderr, "%s: error rendering frames %d through %d\n", |
697 |
|
progname, first, last); |
698 |
|
quit(1); |
770 |
|
} |
771 |
|
|
772 |
|
|
773 |
< |
archive(first, last) /* archive and remove renderings */ |
744 |
< |
int first, last; |
773 |
> |
archive() /* archive and remove renderings */ |
774 |
|
{ |
775 |
|
#define RMCOML (sizeof(rmcom)-1) |
776 |
|
static char rmcom[] = "rm -f"; |
748 |
– |
int offset = RMCOML; |
749 |
– |
char combuf[10240]; |
750 |
– |
struct stat stb; |
751 |
– |
register char *cp; |
777 |
|
register int i; |
778 |
|
|
779 |
< |
if (noaction) |
780 |
< |
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; |
779 |
> |
if (arcnext == arcfirst) |
780 |
> |
return; /* nothing to do */ |
781 |
|
if (vdef(ARCHIVE)) { /* run archive command */ |
782 |
|
i = strlen(vval(ARCHIVE)); |
783 |
< |
strncpy(combuf+offset-i, vval(ARCHIVE), i); |
784 |
< |
if (runcom(combuf+offset-i)) { |
785 |
< |
fprintf(stderr, |
786 |
< |
"%s: error running archive command on frames %d through %d\n", |
783 |
< |
progname, first, last); |
783 |
> |
strncpy(arcfirst-i, vval(ARCHIVE), i); |
784 |
> |
if (runcom(arcfirst-i)) { |
785 |
> |
fprintf(stderr, "%s: error running archive command\n", |
786 |
> |
progname); |
787 |
|
quit(1); |
788 |
|
} |
789 |
|
} |
790 |
|
/* run remove command */ |
791 |
< |
strncpy(combuf+offset-RMCOML, rmcom, RMCOML); |
792 |
< |
runcom(combuf+offset-RMCOML); |
791 |
> |
strncpy(arcfirst-RMCOML, rmcom, RMCOML); |
792 |
> |
runcom(arcfirst-RMCOML); |
793 |
> |
arcnext = arcfirst; /* reset argument list */ |
794 |
|
#undef RMCOML |
795 |
|
} |
796 |
|
|
806 |
|
static int iter = 0; |
807 |
|
char fnbefore[128], fnafter[128]; |
808 |
|
char combuf[1024], fname0[128], fname1[128]; |
809 |
< |
int usepinterp, usepfilt; |
809 |
> |
int usepinterp, usepfilt, nora_rgbe; |
810 |
|
int frseq[2]; |
811 |
|
/* check what is needed */ |
812 |
|
usepinterp = atoi(vval(MBLUR)); |
813 |
|
usepfilt = pfiltalways | ep==NULL; |
814 |
+ |
if (ep != NULL && !strcmp(ep, "1")) |
815 |
+ |
ep = "+0"; |
816 |
+ |
nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || |
817 |
+ |
*ep != '+' || *ep != '-' || !isint(ep); |
818 |
|
/* compute rendered views */ |
819 |
|
frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); |
820 |
|
frseq[1] = frseq[0] + vint(INTERP) + 1; |
823 |
|
if (frseq[1] == frame) { /* pfilt only */ |
824 |
|
frseq[0] = frseq[1]; |
825 |
|
usepinterp = 0; /* update what's needed */ |
826 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
827 |
< |
} else if (frseq[0] == frame) { /* no interpolation */ |
828 |
< |
/* update what's needed */ |
829 |
< |
if (!usepinterp) |
830 |
< |
usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); |
826 |
> |
usepfilt |= nora_rgbe; |
827 |
> |
} else if (frseq[0] == frame) { /* no interpolation needed */ |
828 |
> |
if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ |
829 |
> |
*arcnext++ = ' '; |
830 |
> |
sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); |
831 |
> |
while (*arcnext) arcnext++; |
832 |
> |
strcpy(arcnext, ".unf"); |
833 |
> |
arcnext += 4; |
834 |
> |
if (usepinterp || vint(INTERP)) { /* and z-buf */ |
835 |
> |
*arcnext++ = ' '; |
836 |
> |
sprintf(arcnext, vval(BASENAME), |
837 |
> |
frame-vint(INTERP)-1); |
838 |
> |
while (*arcnext) arcnext++; |
839 |
> |
strcpy(arcnext, ".zbf"); |
840 |
> |
arcnext += 4; |
841 |
> |
} |
842 |
> |
} |
843 |
> |
if (!usepinterp) /* update what's needed */ |
844 |
> |
usepfilt |= nora_rgbe; |
845 |
|
} else /* interpolation needed */ |
846 |
|
usepinterp++; |
847 |
|
if (frseq[1] >= astat.rnext) /* next batch unavailable */ |
930 |
|
} else { /* else just check it */ |
931 |
|
if (rvr == 2) |
932 |
|
return(1); |
933 |
< |
sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore); |
933 |
> |
sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); |
934 |
|
} |
935 |
|
/* output file name */ |
936 |
|
sprintf(fname0, vval(BASENAME), frame); |
966 |
|
quit(1); |
967 |
|
} |
968 |
|
} else if (n < viewnum) { /* rewind file */ |
969 |
+ |
if (viewnum == 1 && feof(viewfp)) |
970 |
+ |
return(&curview); /* just one view */ |
971 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
972 |
|
perror(vval(VIEWFILE)); |
973 |
|
quit(1); |
977 |
|
} |
978 |
|
while (n > viewnum) { /* scan to desired view */ |
979 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
980 |
< |
return(NULL); |
980 |
> |
return(viewnum==1 ? &curview : NULL); |
981 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
982 |
|
viewnum++; |
983 |
|
} |