93 |
|
int noaction = 0; /* take no action? */ |
94 |
|
|
95 |
|
char *remsh; /* remote shell program/script */ |
96 |
< |
char rendopt[2048] = ""; /* rendering options */ |
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? */ |
108 |
|
} *pslot; /* process slots */ |
109 |
|
int npslots; /* number of process slots */ |
110 |
|
|
111 |
– |
int lastpid; /* ID of last completed background process */ |
112 |
– |
PSERVER *lastpserver; /* last process server used */ |
113 |
– |
|
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(); |
119 |
|
|
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 */ |
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); |
302 |
|
setdefaults() /* set default values */ |
303 |
|
{ |
304 |
|
extern char *atos(); |
305 |
+ |
int decades; |
306 |
|
char buf[256]; |
307 |
|
|
308 |
|
if (vdef(ANIMATE)) { |
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 |
|
} |
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 |
|
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: 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) { |
856 |
|
while (*arcnext) arcnext++; |
857 |
|
strcpy(arcnext, ".unf"); |
858 |
|
arcnext += 4; |
859 |
< |
if (usepinterp || vint(INTERP)) { /* and z-buf */ |
859 |
> |
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
860 |
|
*arcnext++ = ' '; |
861 |
|
sprintf(arcnext, vval(BASENAME), |
862 |
|
frame-vint(INTERP)-1); |
914 |
|
strcat(combuf, viewopt(vp)); |
915 |
|
if (vbool(RTRACE)) |
916 |
|
sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", |
917 |
< |
rendopt, vval(OCTREE)); |
917 |
> |
rendopt+1, vval(OCTREE)); |
918 |
|
if (vdef(PINTERP)) |
919 |
|
sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); |
920 |
|
if (usepfilt) |
1002 |
|
} |
1003 |
|
while (n > viewnum) { /* scan to desired view */ |
1004 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
1005 |
< |
return(viewnum==1 ? &curview : NULL); |
1005 |
> |
return(viewnum==1 ? &curview : (VIEW *)NULL); |
1006 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
1007 |
|
viewnum++; |
1008 |
|
} |
1035 |
|
if (n == 0) { /* signal to close file */ |
1036 |
|
if (expfp != NULL) { |
1037 |
|
fclose(expfp); |
1038 |
+ |
free((char *)exppos); |
1039 |
|
expfp = NULL; |
1040 |
|
} |
1041 |
|
return(NULL); |
1042 |
< |
} |
1042 |
> |
} else if (n > vint(END)) /* request past end (error?) */ |
1043 |
> |
return(NULL); |
1044 |
|
if (!vdef(EXPOSURE)) /* no setting (auto) */ |
1045 |
|
return(NULL); |
1046 |
|
if (isflt(vval(EXPOSURE))) /* always the same */ |
1078 |
|
} |
1079 |
|
curfrm++; |
1080 |
|
cp = fskip(expval); /* check format */ |
1081 |
< |
if (cp == NULL || *cp != '\n') { |
1081 |
> |
if (cp != NULL) |
1082 |
> |
while (isspace(*cp)) |
1083 |
> |
*cp++ = '\0'; |
1084 |
> |
if (cp == NULL || *cp) { |
1085 |
|
fprintf(stderr, |
1086 |
|
"%s: exposure format error on line %d\n", |
1087 |
|
vval(EXPOSURE), curfrm); |
1088 |
|
quit(1); |
1089 |
|
} |
1070 |
– |
*cp = '\0'; |
1090 |
|
} |
1091 |
|
return(expval); /* return value */ |
1092 |
|
} |
1116 |
|
int status; |
1117 |
|
{ |
1118 |
|
register PROC *pp; |
1119 |
+ |
register struct pslot *psl; |
1120 |
|
|
1121 |
|
pp = ps->proc + pn; |
1122 |
|
if (pp->elen) { /* pass errors */ |
1128 |
|
if (ps->hostname[0]) |
1129 |
|
status = 1; /* because rsh doesn't return status */ |
1130 |
|
} |
1131 |
+ |
lastpserver = NULL; |
1132 |
+ |
psl = findpslot(pp->pid); /* check for bruncom() slot */ |
1133 |
+ |
if (psl->pid) { |
1134 |
+ |
if (status) { |
1135 |
+ |
if (psl->rcvf != NULL) /* attempt recovery */ |
1136 |
+ |
status = (*psl->rcvf)(psl->fout); |
1137 |
+ |
if (status) { |
1138 |
+ |
fprintf(stderr, |
1139 |
+ |
"%s: error rendering frame %d\n", |
1140 |
+ |
progname, psl->fout); |
1141 |
+ |
quit(1); |
1142 |
+ |
} |
1143 |
+ |
lastpserver = ps; |
1144 |
+ |
} |
1145 |
+ |
psl->pid = 0; /* free process slot */ |
1146 |
+ |
} else if (status) |
1147 |
+ |
lastpserver = ps; |
1148 |
|
freestr(pp->com); /* free command string */ |
1112 |
– |
lastpid = pp->pid; /* record PID for bwait() */ |
1113 |
– |
lastpserver = ps; /* record server for serverdown() */ |
1149 |
|
return(status); |
1150 |
|
} |
1151 |
|
|
1153 |
|
int |
1154 |
|
serverdown() /* check status of last process server */ |
1155 |
|
{ |
1156 |
+ |
if (lastpserver == NULL || !lastpserver->hostname[0]) |
1157 |
+ |
return(0); |
1158 |
|
if (pserverOK(lastpserver)) /* server still up? */ |
1159 |
|
return(0); |
1160 |
|
delpserver(lastpserver); /* else delete it */ |
1181 |
|
printf("\t%s\n", com); /* echo command */ |
1182 |
|
return(0); |
1183 |
|
} |
1184 |
< |
/* else start it when we can */ |
1185 |
< |
while ((pid = startjob(NULL, savestr(com), donecom)) == -1) |
1184 |
> |
com = savestr(com); /* else start it when we can */ |
1185 |
> |
while ((pid = startjob(NULL, com, donecom)) == -1) |
1186 |
|
bwait(1); |
1187 |
|
if (!silent) { /* echo command */ |
1188 |
|
PSERVER *ps; |
1204 |
|
int ncoms; |
1205 |
|
{ |
1206 |
|
int status; |
1170 |
– |
register struct pslot *psl; |
1207 |
|
|
1208 |
|
if (noaction) |
1209 |
|
return; |
1210 |
|
while ((status = wait4job(NULL, -1)) != -1) { |
1211 |
< |
psl = findpslot(lastpid); |
1212 |
< |
if (status) { /* attempt recovery */ |
1213 |
< |
serverdown(); /* check server */ |
1178 |
< |
if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { |
1179 |
< |
fprintf(stderr, |
1180 |
< |
"%s: error rendering frame %d\n", |
1181 |
< |
progname, psl->fout); |
1182 |
< |
quit(1); |
1183 |
< |
} |
1184 |
< |
} |
1185 |
< |
psl->pid = 0; /* free process slot */ |
1186 |
< |
if (!--ncoms) |
1187 |
< |
return; /* done enough */ |
1211 |
> |
serverdown(); /* update server status */ |
1212 |
> |
if (--ncoms == 0) |
1213 |
> |
break; /* done enough */ |
1214 |
|
} |
1215 |
|
} |
1216 |
|
|
1222 |
|
{ |
1223 |
|
int retstatus = 0; |
1224 |
|
int hostcopies; |
1225 |
< |
char com1buf[10240], *com1, *endcom1; |
1225 |
> |
char buf[10240], *com1, *s; |
1226 |
|
int status; |
1227 |
+ |
int pfd; |
1228 |
+ |
register int n; |
1229 |
|
register PSERVER *ps; |
1230 |
|
|
1231 |
|
if (!silent) |
1237 |
|
for (ps = pslist; ps != NULL; ps = ps->next) { |
1238 |
|
hostcopies = 0; |
1239 |
|
if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { |
1240 |
< |
strcpy(com1=com1buf, com); /* build -PP command */ |
1240 |
> |
strcpy(com1=buf, com); /* build -PP command */ |
1241 |
|
sprintf(com1+(ppins-com), " -PP %s/%s.persist", |
1242 |
|
vval(DIRECTORY), phostname(ps)); |
1243 |
|
strcat(com1, ppins); |
1244 |
< |
endcom1 = com1 + strlen(com1); |
1217 |
< |
sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", |
1218 |
< |
vval(DIRECTORY), phostname(ps)); |
1219 |
< |
} else { |
1244 |
> |
} else |
1245 |
|
com1 = com; |
1246 |
< |
endcom1 = NULL; |
1246 |
> |
while (maxcopies > 0) { |
1247 |
> |
s = savestr(com1); |
1248 |
> |
if (startjob(ps, s, donecom) != -1) { |
1249 |
> |
sleep(20); |
1250 |
> |
hostcopies++; |
1251 |
> |
maxcopies--; |
1252 |
> |
} else { |
1253 |
> |
freestr(s); |
1254 |
> |
break; |
1255 |
> |
} |
1256 |
|
} |
1223 |
– |
while (maxcopies > 0 && |
1224 |
– |
startjob(ps, savestr(com1), donecom) != -1) { |
1225 |
– |
sleep(10); |
1226 |
– |
hostcopies++; |
1227 |
– |
maxcopies--; |
1228 |
– |
if (endcom1 != NULL) |
1229 |
– |
*endcom1 = '\0'; |
1230 |
– |
} |
1257 |
|
if (!silent && hostcopies) { |
1258 |
|
if (hostcopies > 1) |
1259 |
|
printf("\t%d duplicate processes", hostcopies); |
1265 |
|
} |
1266 |
|
/* wait for jobs to finish */ |
1267 |
|
while ((status = wait4job(NULL, -1)) != -1) |
1268 |
< |
if (status) |
1269 |
< |
retstatus += !serverdown(); /* check server */ |
1268 |
> |
retstatus += status && !serverdown(); |
1269 |
> |
/* terminate parallel rpict's */ |
1270 |
> |
for (ps = pslist; ps != NULL; ps = ps->next) { |
1271 |
> |
sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); |
1272 |
> |
if ((pfd = open(buf, O_RDONLY)) >= 0) { |
1273 |
> |
n = read(pfd, buf, sizeof(buf)-1); /* get PID */ |
1274 |
> |
buf[n] = '\0'; |
1275 |
> |
close(pfd); |
1276 |
> |
for (n = 0; buf[n] && !isspace(buf[n]); n++) |
1277 |
> |
; |
1278 |
> |
/* terminate */ |
1279 |
> |
sprintf(buf, "kill -ALRM %d", atoi(buf+n)); |
1280 |
> |
wait4job(ps, startjob(ps, buf, NULL)); |
1281 |
> |
} |
1282 |
> |
} |
1283 |
|
return(retstatus); |
1284 |
|
} |
1285 |
|
|