20 |
|
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
21 |
|
#endif |
22 |
|
|
23 |
< |
int treebufsiz = BUFSIZ; /* current tree buffer size */ |
23 |
> |
size_t treebufsiz = BUFSIZ; /* current tree buffer size */ |
24 |
|
|
25 |
|
typedef double DCOLOR[3]; /* double-precision color */ |
26 |
|
|
92 |
|
struct rtproc *next; /* next in list of processes */ |
93 |
|
SUBPROC pd; /* rtrace pipe descriptors */ |
94 |
|
unsigned long raynum; /* ray number for this tree */ |
95 |
< |
int bsiz; /* ray tree buffer length */ |
95 |
> |
size_t bsiz; /* ray tree buffer length */ |
96 |
|
char *buf; /* ray tree buffer */ |
97 |
< |
int nbr; /* number of bytes from rtrace */ |
97 |
> |
size_t nbr; /* number of bytes from rtrace */ |
98 |
|
}; /* rtrace process buffer */ |
99 |
|
|
100 |
|
/* rtrace command and defaults */ |
101 |
|
char *rtargv[256+2*MAXMODLIST] = { "rtrace", |
102 |
< |
"-dj", ".5", "-dr", "3", |
102 |
> |
"-dj", ".9", "-dr", "3", |
103 |
|
"-ab", "1", "-ad", "350", }; |
104 |
|
|
105 |
|
int rtargc = 9; |
107 |
|
char *myrtopts[] = { "-h-", "-x", "1", "-y", "0", |
108 |
|
"-dt", "0", "-as", "0", "-aa", "0", NULL }; |
109 |
|
|
110 |
< |
#define RTCOEFF "-o~~TmWdp" /* compute coefficients only */ |
111 |
< |
#define RTCONTRIB "-o~~TmVdp" /* compute ray contributions */ |
110 |
> |
#define RTCOEFF "-o~~~TmWdp" /* compute coefficients only */ |
111 |
> |
#define RTCONTRIB "-o~~~TmVdp" /* compute ray contributions */ |
112 |
|
|
113 |
|
struct rtproc rt0; /* head of rtrace process list */ |
114 |
|
|
131 |
|
int outfmt = 'a'; /* output format */ |
132 |
|
|
133 |
|
int header = 1; /* output header? */ |
134 |
– |
int accumulate = 0; /* accumulate ray values? */ |
134 |
|
int force_open = 0; /* truncate existing output? */ |
135 |
+ |
int recover = 0; /* recover previous output? */ |
136 |
+ |
int accumulate = 1; /* input rays per output record */ |
137 |
|
int xres = 0; /* horiz. output resolution */ |
138 |
|
int yres = 0; /* vert. output resolution */ |
139 |
|
|
140 |
+ |
int account; /* current accumulation count */ |
141 |
|
unsigned long raysleft; /* number of rays left to trace */ |
142 |
|
long waitflush; /* how long until next flush */ |
143 |
|
|
167 |
|
|
168 |
|
void put_contrib(const DCOLOR cnt, FILE *fout); |
169 |
|
void add_contrib(const char *modn); |
170 |
< |
void done_contrib(void); |
170 |
> |
void done_contrib(int navg); |
171 |
|
|
172 |
|
/* return number of open rtrace processes */ |
173 |
|
static int |
222 |
|
{ |
223 |
|
int contrib = 0; |
224 |
|
int nprocs = 1; |
223 |
– |
int recover = 0; |
225 |
|
char *curout = NULL; |
226 |
|
char *binval = NULL; |
227 |
|
int bincnt = 0; |
246 |
|
while ((j = expandarg(&argc, &argv, i)) > 0) |
247 |
|
; |
248 |
|
if (j < 0) { |
249 |
< |
fprintf(stderr, "%s: cannot expand '%s'", |
249 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
250 |
|
argv[0], argv[i]); |
251 |
|
exit(1); |
252 |
|
} |
275 |
|
continue; |
276 |
|
} |
277 |
|
break; |
278 |
< |
case 'c': /* accumulate ray values */ |
279 |
< |
switch (argv[i][2]) { |
280 |
< |
case '\0': |
281 |
< |
accumulate = !accumulate; |
281 |
< |
continue; |
282 |
< |
case '+': case '1': |
283 |
< |
case 'T': case 't': |
284 |
< |
case 'Y': case 'y': |
285 |
< |
accumulate = 1; |
286 |
< |
continue; |
287 |
< |
case '-': case '0': |
288 |
< |
case 'F': case 'f': |
289 |
< |
case 'N': case 'n': |
290 |
< |
accumulate = 0; |
291 |
< |
continue; |
292 |
< |
} |
293 |
< |
break; |
278 |
> |
case 'c': /* input rays per output */ |
279 |
> |
if (argv[i][2] || i >= argc-2) break; |
280 |
> |
accumulate = atoi(argv[++i]); |
281 |
> |
continue; |
282 |
|
case 'r': /* recover output */ |
283 |
|
if (argv[i][2]) break; |
284 |
< |
recover++; |
284 |
> |
recover = 1; |
285 |
|
continue; |
286 |
|
case 'h': /* output header? */ |
287 |
|
switch (argv[i][2]) { |
316 |
|
continue; |
317 |
|
} |
318 |
|
if (argv[i][2] == 'o') { |
319 |
< |
force_open++; |
319 |
> |
force_open = 1; |
320 |
|
continue; |
321 |
|
} |
322 |
|
setformat(argv[i]+2); |
340 |
|
case 'b': /* bin expression/count */ |
341 |
|
if (i >= argc-2) break; |
342 |
|
if (argv[i][2] == 'n') { |
343 |
< |
bincnt = atoi(argv[++i]); |
343 |
> |
bincnt = (int)(eval(argv[++i]) + .5); |
344 |
|
continue; |
345 |
|
} |
346 |
|
if (argv[i][2]) break; |
368 |
|
} |
369 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
370 |
|
} |
371 |
< |
if (accumulate) /* no output flushing for single record */ |
371 |
> |
if (accumulate <= 0) /* no output flushing for single record */ |
372 |
|
xres = yres = 0; |
373 |
|
/* set global argument list */ |
374 |
|
gargc = argc; gargv = argv; |
378 |
|
rtargv[rtargc++] = contrib ? RTCONTRIB : RTCOEFF; |
379 |
|
/* just asking for defaults? */ |
380 |
|
if (!strcmp(argv[i], "-defaults")) { |
381 |
< |
char sxres[16], syres[16]; |
381 |
> |
char nps[8], sxres[16], syres[16]; |
382 |
|
char *rtpath; |
383 |
< |
printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); |
383 |
> |
printf("-c %-5d\t\t\t# accumulated rays per record\n", |
384 |
> |
accumulate); |
385 |
|
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
386 |
|
contrib ? "contributions" : "coefficients"); |
398 |
– |
printf("-c%c\t\t\t\t# %s\n", accumulate ? '+' : '-', |
399 |
– |
accumulate ? "accumulate ray values" : |
400 |
– |
"one output record per ray"); |
387 |
|
fflush(stdout); /* report OUR options */ |
388 |
+ |
rtargv[rtargc++] = "-n"; |
389 |
+ |
sprintf(nps, "%d", nprocs); |
390 |
+ |
rtargv[rtargc++] = nps; |
391 |
|
rtargv[rtargc++] = header ? "-h+" : "-h-"; |
392 |
|
sprintf(fmt, "-f%c%c", inpfmt, outfmt); |
393 |
|
rtargv[rtargc++] = fmt; |
426 |
|
error(USER, "missing octree argument"); |
427 |
|
rtargv[rtargc++] = octree = argv[i]; |
428 |
|
rtargv[rtargc] = NULL; |
429 |
< |
/* start rtrace */ |
429 |
> |
/* start rtrace & recover if requested */ |
430 |
|
init(nprocs); |
431 |
< |
if (recover) /* perform recovery if requested */ |
432 |
< |
if ((force_open = accumulate)) |
433 |
< |
reload_output(); |
445 |
< |
else |
446 |
< |
recover_output(stdin); |
447 |
< |
trace_contribs(stdin); /* compute contributions */ |
431 |
> |
/* compute contributions */ |
432 |
> |
trace_contribs(stdin); |
433 |
> |
/* clean up */ |
434 |
|
quit(0); |
435 |
|
} |
436 |
|
|
543 |
|
raysleft = yres; |
544 |
|
} else |
545 |
|
raysleft = 0; |
546 |
< |
waitflush = xres; |
546 |
> |
if ((account = accumulate) > 0) |
547 |
> |
raysleft *= accumulate; |
548 |
> |
waitflush = (yres > 0) & (xres > 1) ? 0 : xres; |
549 |
> |
if (!recover) |
550 |
> |
return; |
551 |
> |
/* recover previous values */ |
552 |
> |
if (accumulate <= 0) |
553 |
> |
reload_output(); |
554 |
> |
else |
555 |
> |
recover_output(stdin); |
556 |
|
} |
557 |
|
|
558 |
|
/* grow modifier to accommodate more bins */ |
582 |
|
error(USER, errmsg); |
583 |
|
} |
584 |
|
if (nmods >= MAXMODLIST) |
585 |
< |
error(USER, "too many modifiers"); |
585 |
> |
error(INTERNAL, "too many modifiers"); |
586 |
|
modname[nmods++] = modn; /* XXX assumes static string */ |
587 |
|
lep->key = modn; /* XXX assumes static string */ |
588 |
|
mp = (MODCONT *)malloc(sizeof(MODCONT)); |
590 |
|
error(SYSTEM, "out of memory in addmodifier"); |
591 |
|
mp->outspec = outf; /* XXX assumes static string */ |
592 |
|
mp->modname = modn; /* XXX assumes static string */ |
593 |
< |
if (binv != NULL) |
594 |
< |
mp->binv = eparse(binv); |
595 |
< |
else |
596 |
< |
mp->binv = eparse("0"); |
597 |
< |
mp->nbins = 1; |
593 |
> |
if (binv == NULL) |
594 |
> |
binv = "0"; /* use single bin if unspecified */ |
595 |
> |
mp->binv = eparse(binv); |
596 |
> |
if (mp->binv->type == NUM) { /* check value if constant */ |
597 |
> |
bincnt = (int)(evalue(mp->binv) + 1.5); |
598 |
> |
if (bincnt != 1) { |
599 |
> |
sprintf(errmsg, "illegal non-zero constant for bin (%s)", |
600 |
> |
binv); |
601 |
> |
error(USER, errmsg); |
602 |
> |
} |
603 |
> |
} |
604 |
> |
mp->nbins = 1; /* initialize results holder */ |
605 |
|
setcolor(mp->cbin[0], 0., 0., 0.); |
606 |
< |
if (mp->binv->type == NUM) /* assume one bin if constant */ |
605 |
< |
bincnt = 1; |
606 |
< |
else if (bincnt > 1) |
606 |
> |
if (bincnt > 1) |
607 |
|
mp = growmodifier(mp, bincnt); |
608 |
|
lep->data = (char *)mp; |
609 |
|
/* allocate output streams */ |
666 |
|
mnp = cp; |
667 |
|
break; |
668 |
|
case 'd': |
669 |
+ |
case 'i': |
670 |
+ |
case 'o': |
671 |
+ |
case 'x': |
672 |
+ |
case 'X': |
673 |
|
if (bnp != NULL) |
674 |
|
return -1; |
675 |
|
bnp = cp; |
736 |
|
{ |
737 |
|
if ((xr > 0) & (yr > 0)) /* resolution string */ |
738 |
|
fprtresolu(xr, yr, fout); |
735 |
– |
if (xres > 0) /* global flush flag */ |
736 |
– |
fflush(fout); |
739 |
|
} |
740 |
|
|
741 |
|
/* Get output stream pointer (open and write header if new and noopen==0) */ |
756 |
|
if (header) |
757 |
|
printheader(stdout, NULL); |
758 |
|
printresolu(stdout, xres, yres); |
759 |
+ |
if (waitflush > 0) |
760 |
+ |
fflush(stdout); |
761 |
|
stdos.xr = xres; stdos.yr = yres; |
762 |
|
using_stdout = 1; |
763 |
|
} |
783 |
|
sop->ofp = NULL; /* open iff noopen==0 */ |
784 |
|
sop->xr = xres; sop->yr = yres; |
785 |
|
lep->data = (char *)sop; |
786 |
< |
if (!force_open && access(oname, F_OK) == 0) { |
786 |
> |
if (!sop->outpipe & !force_open & !recover && |
787 |
> |
access(oname, F_OK) == 0) { |
788 |
|
errno = EEXIST; /* file exists */ |
789 |
|
goto openerr; |
790 |
|
} |
813 |
|
*cp = '\0'; |
814 |
|
printheader(sop->ofp, info); |
815 |
|
} |
816 |
+ |
if (accumulate > 0) { /* global resolution */ |
817 |
+ |
sop->xr = xres; sop->yr = yres; |
818 |
+ |
} |
819 |
|
printresolu(sop->ofp, sop->xr, sop->yr); |
820 |
|
/* play catch-up */ |
821 |
< |
for (i = accumulate ? 0 : lastdone; i--; ) { |
821 |
> |
for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) { |
822 |
|
int j = sop->reclen; |
823 |
|
if (j <= 0) j = 1; |
824 |
|
while (j--) |
826 |
|
if (outfmt == 'a') |
827 |
|
putc('\n', sop->ofp); |
828 |
|
} |
829 |
< |
if (xres > 0) |
829 |
> |
if (waitflush > 0) |
830 |
|
fflush(sop->ofp); |
831 |
|
} |
832 |
|
sop->reclen += noopen; /* add to length if noopen */ |
943 |
|
fprintf(fout, "%.6e\t%.6e\t%.6e\t", cnt[0], cnt[1], cnt[2]); |
944 |
|
break; |
945 |
|
case 'f': |
946 |
< |
fv[0] = cnt[0]; |
939 |
< |
fv[1] = cnt[1]; |
940 |
< |
fv[2] = cnt[2]; |
946 |
> |
copycolor(fv, cnt); |
947 |
|
fwrite(fv, sizeof(float), 3, fout); |
948 |
|
break; |
949 |
|
case 'd': |
960 |
|
|
961 |
|
/* output ray tallies and clear for next accumulation */ |
962 |
|
void |
963 |
< |
done_contrib(void) |
963 |
> |
done_contrib(int navg) |
964 |
|
{ |
965 |
+ |
double sf = 1.; |
966 |
|
int i, j; |
967 |
|
MODCONT *mp; |
968 |
|
STREAMOUT *sop; |
969 |
+ |
/* set average scaling */ |
970 |
+ |
if (navg > 1) |
971 |
+ |
sf = 1. / (double)navg; |
972 |
|
/* output modifiers in order */ |
973 |
|
for (i = 0; i < nmods; i++) { |
974 |
|
mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; |
975 |
+ |
if (navg > 1) /* average scaling */ |
976 |
+ |
for (j = mp->nbins; j--; ) |
977 |
+ |
scalecolor(mp->cbin[j], sf); |
978 |
|
sop = getostream(mp->outspec, mp->modname, 0,0); |
979 |
|
put_contrib(mp->cbin[0], sop->ofp); |
980 |
|
if (mp->nbins > 3 && /* minor optimization */ |
993 |
|
if (using_stdout & (outfmt == 'a')) |
994 |
|
putc('\n', stdout); |
995 |
|
if (!waitflush) { |
996 |
< |
waitflush = xres; |
996 |
> |
waitflush = (yres > 0) & (xres > 1) ? 0 : xres; |
997 |
|
if (using_stdout) |
998 |
|
fflush(stdout); |
999 |
|
} |
1058 |
|
cp += sizeof(float)*9; n -= sizeof(float)*9; |
1059 |
|
add_contrib(modname); |
1060 |
|
} |
1061 |
< |
if (!accumulate) |
1062 |
< |
done_contrib(); /* sum up contributions & output */ |
1061 |
> |
/* time to produce record? */ |
1062 |
> |
if (account > 0 && !--account) |
1063 |
> |
done_contrib(account = accumulate); |
1064 |
|
lastdone = rtp->raynum; |
1065 |
|
if (rtp->buf != NULL) /* free up buffer space */ |
1066 |
|
free(rtp->buf); |
1075 |
|
{ |
1076 |
|
struct rtproc *rtfree = NULL; |
1077 |
|
fd_set readset, errset; |
1078 |
< |
int nr; |
1078 |
> |
ssize_t nr; |
1079 |
|
struct rtproc *rt; |
1080 |
|
int n; |
1081 |
|
|
1106 |
|
continue; |
1107 |
|
if (rt->buf == NULL) { |
1108 |
|
rt->bsiz = treebufsiz; |
1109 |
< |
rt->buf = (char *)malloc(treebufsiz); |
1109 |
> |
rt->buf = (char *)malloc(rt->bsiz); |
1110 |
|
} else if (rt->nbr + BUFSIZ > rt->bsiz) { |
1111 |
|
if (rt->bsiz + BUFSIZ <= treebufsiz) |
1112 |
|
rt->bsiz = treebufsiz; |
1120 |
|
if (nr <= 0) |
1121 |
|
error(USER, "rtrace process died"); |
1122 |
|
rt->nbr += nr; /* advance & check */ |
1123 |
< |
if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4, |
1124 |
< |
"~\t~\t", 4)) { |
1125 |
< |
rt->nbr -= 4; /* elide terminator */ |
1123 |
> |
if (rt->nbr >= 6 && !memcmp(rt->buf+rt->nbr-6, |
1124 |
> |
"~\t~\t~\t", 6)) { |
1125 |
> |
rt->nbr -= 6; /* elide terminator */ |
1126 |
|
queue_raytree(rt); |
1127 |
|
rtfree = rt; /* ready for next ray */ |
1128 |
|
} |
1147 |
|
void |
1148 |
|
trace_contribs(FILE *fin) |
1149 |
|
{ |
1150 |
+ |
static int ignore_warning_given = 0; |
1151 |
|
char inpbuf[128]; |
1152 |
|
int iblen; |
1153 |
|
struct rtproc *rtp; |
1154 |
|
/* loop over input */ |
1155 |
|
while ((iblen = getinp(inpbuf, fin)) >= 0) { |
1156 |
< |
if (!iblen || /* need reset? */ |
1156 |
> |
if (!iblen && accumulate != 1) { |
1157 |
> |
if (!ignore_warning_given++) |
1158 |
> |
error(WARNING, |
1159 |
> |
"dummy ray(s) ignored during accumulation\n"); |
1160 |
> |
continue; |
1161 |
> |
} |
1162 |
> |
if (!iblen || /* need flush/reset? */ |
1163 |
|
queue_length() > 10*nrtprocs() || |
1164 |
|
lastray+1 < lastray) { |
1165 |
|
while (wait_rproc() != NULL) |
1166 |
|
process_queue(); |
1167 |
< |
if (lastray+1 < lastray) |
1147 |
< |
lastdone = lastray = 0; |
1167 |
> |
lastdone = lastray = 0; |
1168 |
|
} |
1169 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
1170 |
|
rtp->raynum = ++lastray; /* assign ray */ |
1171 |
|
if (iblen) { /* trace ray if valid */ |
1172 |
|
writebuf(rtp->pd.w, inpbuf, iblen); |
1173 |
|
} else { /* else bypass dummy ray */ |
1174 |
< |
queue_raytree(rtp); /* empty tree */ |
1175 |
< |
if ((yres <= 0) | (waitflush > 1)) |
1176 |
< |
waitflush = 1; /* flush after this */ |
1174 |
> |
queue_raytree(rtp); /* queue empty ray/record */ |
1175 |
> |
if ((yres <= 0) | (xres <= 0)) |
1176 |
> |
waitflush = 1; /* flush right after */ |
1177 |
|
} |
1178 |
|
process_queue(); /* catch up with results */ |
1179 |
|
if (raysleft && !--raysleft) |
1181 |
|
} |
1182 |
|
while (wait_rproc() != NULL) /* process outstanding rays */ |
1183 |
|
process_queue(); |
1184 |
< |
if (accumulate) |
1185 |
< |
done_contrib(); /* output tallies */ |
1184 |
> |
if (accumulate <= 0) |
1185 |
> |
done_contrib(0); /* output tallies */ |
1186 |
> |
else if (account < accumulate) { |
1187 |
> |
error(WARNING, "partial accumulation in final record"); |
1188 |
> |
done_contrib(accumulate - account); |
1189 |
> |
} |
1190 |
|
if (raysleft) |
1191 |
|
error(USER, "unexpected EOF on input"); |
1192 |
|
lu_done(&ofiletab); /* close output files */ |
1193 |
|
} |
1194 |
|
|
1195 |
< |
/* seek on the given output file */ |
1195 |
> |
/* get ray contribution from previous file */ |
1196 |
|
static int |
1197 |
< |
myseeko(const LUENT *e, void *p) |
1197 |
> |
get_contrib(DCOLOR cnt, FILE *finp) |
1198 |
|
{ |
1199 |
+ |
COLOR fv; |
1200 |
+ |
COLR cv; |
1201 |
+ |
|
1202 |
+ |
switch (outfmt) { |
1203 |
+ |
case 'a': |
1204 |
+ |
return(fscanf(finp,"%lf %lf %lf",&cnt[0],&cnt[1],&cnt[2]) == 3); |
1205 |
+ |
case 'f': |
1206 |
+ |
if (fread(fv, sizeof(fv[0]), 3, finp) != 3) |
1207 |
+ |
return(0); |
1208 |
+ |
copycolor(cnt, fv); |
1209 |
+ |
return(1); |
1210 |
+ |
case 'd': |
1211 |
+ |
return(fread(cnt, sizeof(cnt[0]), 3, finp) == 3); |
1212 |
+ |
case 'c': |
1213 |
+ |
if (fread(cv, sizeof(cv), 1, finp) != 1) |
1214 |
+ |
return(0); |
1215 |
+ |
colr_color(fv, cv); |
1216 |
+ |
copycolor(cnt, fv); |
1217 |
+ |
return(1); |
1218 |
+ |
default: |
1219 |
+ |
error(INTERNAL, "botched output format"); |
1220 |
+ |
} |
1221 |
+ |
return(0); /* pro forma return */ |
1222 |
+ |
} |
1223 |
+ |
|
1224 |
+ |
/* close output file opened for input */ |
1225 |
+ |
static int |
1226 |
+ |
myclose(const LUENT *e, void *p) |
1227 |
+ |
{ |
1228 |
|
STREAMOUT *sop = (STREAMOUT *)e->data; |
1176 |
– |
off_t nbytes = *(off_t *)p; |
1229 |
|
|
1230 |
< |
if (sop->reclen > 1) |
1231 |
< |
nbytes = nbytes * sop->reclen; |
1232 |
< |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
1233 |
< |
sprintf(errmsg, "seek error on file '%s'", e->key); |
1234 |
< |
error(SYSTEM, errmsg); |
1183 |
< |
} |
1184 |
< |
return 0; |
1230 |
> |
if (sop->ofp == NULL) |
1231 |
> |
return(0); |
1232 |
> |
fclose(sop->ofp); |
1233 |
> |
sop->ofp = NULL; |
1234 |
> |
return(0); |
1235 |
|
} |
1236 |
|
|
1237 |
|
/* load previously accumulated values */ |
1245 |
|
char *fmode = "rb"; |
1246 |
|
char *outvfmt; |
1247 |
|
LUENT *ment, *oent; |
1248 |
+ |
int xr, yr; |
1249 |
|
STREAMOUT sout; |
1250 |
+ |
DCOLOR rgbv; |
1251 |
|
|
1200 |
– |
error(INTERNAL, "-r option not yet implemented with -c"); |
1201 |
– |
|
1252 |
|
switch (outfmt) { |
1253 |
|
case 'a': |
1254 |
|
outvfmt = "ascii"; |
1267 |
|
error(INTERNAL, "botched output format"); |
1268 |
|
return; |
1269 |
|
} |
1270 |
< |
/* check modifier outputs */ |
1270 |
> |
/* reload modifier values */ |
1271 |
|
for (i = 0; i < nmods; i++) { |
1272 |
|
ment = lu_find(&modconttab,modname[i]); |
1273 |
|
mp = (MODCONT *)ment->data; |
1275 |
|
error(USER, "cannot reload from stdout"); |
1276 |
|
if (mp->outspec[0] == '!') |
1277 |
|
error(USER, "cannot reload from command"); |
1278 |
< |
for (j = 0; ; j++) { /* check each bin's file */ |
1278 |
> |
for (j = 0; ; j++) { /* load each modifier bin */ |
1279 |
|
ofl = ofname(oname, mp->outspec, mp->modname, j); |
1280 |
|
if (ofl < 0) |
1281 |
|
error(USER, "bad output file specification"); |
1284 |
|
sout = *(STREAMOUT *)oent->data; |
1285 |
|
} else { |
1286 |
|
sout.reclen = 0; |
1287 |
+ |
sout.outpipe = 0; |
1288 |
+ |
sout.xr = xres; sout.yr = yres; |
1289 |
|
sout.ofp = NULL; |
1290 |
|
} |
1291 |
< |
if (sout.ofp != NULL) { /* already open? */ |
1292 |
< |
if (ofl & OF_BIN) |
1293 |
< |
continue; |
1294 |
< |
break; |
1291 |
> |
if (sout.ofp == NULL) { /* open output as input */ |
1292 |
> |
sout.ofp = fopen(oname, fmode); |
1293 |
> |
if (sout.ofp == NULL) { |
1294 |
> |
if (j) |
1295 |
> |
break; /* assume end of modifier */ |
1296 |
> |
sprintf(errmsg, "missing reload file '%s'", |
1297 |
> |
oname); |
1298 |
> |
error(WARNING, errmsg); |
1299 |
> |
break; |
1300 |
> |
} |
1301 |
> |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
1302 |
> |
sprintf(errmsg, "format mismatch for '%s'", |
1303 |
> |
oname); |
1304 |
> |
error(USER, errmsg); |
1305 |
> |
} |
1306 |
> |
if ((sout.xr > 0) & (sout.yr > 0) && |
1307 |
> |
(!fscnresolu(&xr, &yr, sout.ofp) || |
1308 |
> |
(xr != sout.xr) | |
1309 |
> |
(yr != sout.yr))) { |
1310 |
> |
sprintf(errmsg, "resolution mismatch for '%s'", |
1311 |
> |
oname); |
1312 |
> |
error(USER, errmsg); |
1313 |
> |
} |
1314 |
|
} |
1315 |
< |
/* open output */ |
1316 |
< |
sout.ofp = fopen(oname, fmode); |
1317 |
< |
if (sout.ofp == NULL) { |
1318 |
< |
if (j) |
1319 |
< |
break; /* assume end of modifier */ |
1320 |
< |
sprintf(errmsg, "missing reload file '%s'", |
1321 |
< |
oname); |
1322 |
< |
error(WARNING, errmsg); |
1315 |
> |
/* read in RGB value */ |
1316 |
> |
if (!get_contrib(rgbv, sout.ofp)) { |
1317 |
> |
if (!j) { |
1318 |
> |
fclose(sout.ofp); |
1319 |
> |
break; /* ignore empty file */ |
1320 |
> |
} |
1321 |
> |
if (j < mp->nbins) { |
1322 |
> |
sprintf(errmsg, "missing data in '%s'", |
1323 |
> |
oname); |
1324 |
> |
error(USER, errmsg); |
1325 |
> |
} |
1326 |
|
break; |
1327 |
|
} |
1328 |
< |
if (oent->key == NULL) /* new entry */ |
1328 |
> |
if (j >= mp->nbins) /* grow modifier size */ |
1329 |
> |
ment->data = (char *)(mp = growmodifier(mp, j+1)); |
1330 |
> |
copycolor(mp->cbin[j], rgbv); |
1331 |
> |
if (oent->key == NULL) /* new file entry */ |
1332 |
|
oent->key = strcpy((char *) |
1333 |
|
malloc(strlen(oname)+1), oname); |
1334 |
|
if (oent->data == NULL) |
1335 |
|
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
1336 |
|
*(STREAMOUT *)oent->data = sout; |
1260 |
– |
if (!(ofl & OF_BIN)) |
1261 |
– |
break; /* no bin separation */ |
1337 |
|
} |
1263 |
– |
if (j > mp->nbins) /* reallocate modifier bins */ |
1264 |
– |
ment->data = (char *)(mp = growmodifier(mp, j)); |
1338 |
|
} |
1339 |
< |
lu_done(&ofiletab); /* close all files */ |
1339 |
> |
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
1340 |
|
} |
1341 |
|
|
1342 |
+ |
/* seek on the given output file */ |
1343 |
+ |
static int |
1344 |
+ |
myseeko(const LUENT *e, void *p) |
1345 |
+ |
{ |
1346 |
+ |
STREAMOUT *sop = (STREAMOUT *)e->data; |
1347 |
+ |
off_t nbytes = *(off_t *)p; |
1348 |
+ |
|
1349 |
+ |
if (sop->reclen > 1) |
1350 |
+ |
nbytes = nbytes * sop->reclen; |
1351 |
+ |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
1352 |
+ |
sprintf(errmsg, "seek error on file '%s'", e->key); |
1353 |
+ |
error(SYSTEM, errmsg); |
1354 |
+ |
} |
1355 |
+ |
return 0; |
1356 |
+ |
} |
1357 |
+ |
|
1358 |
|
/* recover output if possible */ |
1359 |
|
void |
1360 |
|
recover_output(FILE *fin) |
1408 |
|
sout = *(STREAMOUT *)oent->data; |
1409 |
|
} else { |
1410 |
|
sout.reclen = 0; |
1411 |
+ |
sout.outpipe = 0; |
1412 |
|
sout.ofp = NULL; |
1413 |
|
} |
1414 |
|
if (sout.ofp != NULL) { /* already open? */ |
1449 |
|
oname); |
1450 |
|
error(USER, errmsg); |
1451 |
|
} |
1452 |
< |
if ((xres > 0) & (yres > 0) && |
1452 |
> |
sout.xr = xres; sout.yr = yres; |
1453 |
> |
if ((sout.xr > 0) & (sout.yr > 0) && |
1454 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
1455 |
< |
xr != xres || |
1456 |
< |
yr != yres)) { |
1455 |
> |
(xr != sout.xr) | |
1456 |
> |
(yr != sout.yr))) { |
1457 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
1458 |
|
oname); |
1459 |
|
error(USER, errmsg); |
1482 |
|
error(WARNING, "no output files to recover"); |
1483 |
|
return; |
1484 |
|
} |
1485 |
< |
if (raysleft && lastout >= raysleft) { |
1485 |
> |
if (raysleft && lastout >= raysleft/accumulate) { |
1486 |
|
error(WARNING, "output appears to be complete"); |
1487 |
|
/* XXX should read & discard input? */ |
1488 |
|
quit(0); |
1494 |
|
for (nvals = 0; nvals < lastout; nvals++) |
1495 |
|
if (getinp(oname, fin) < 0) |
1496 |
|
error(USER, "unexpected EOF on input"); |
1497 |
< |
lastray = lastdone = (unsigned long)lastout; |
1497 |
> |
lastray = lastdone = (unsigned long)lastout * accumulate; |
1498 |
|
if (raysleft) |
1499 |
|
raysleft -= lastray; |
1500 |
|
} |