8 |
|
|
9 |
|
#include "rcontrib.h" |
10 |
|
#include "resolu.h" |
11 |
– |
#include "platform.h" |
11 |
|
|
12 |
+ |
/* Close output stream and free record */ |
13 |
+ |
static void |
14 |
+ |
closestream(void *p) |
15 |
+ |
{ |
16 |
+ |
STREAMOUT *sop = (STREAMOUT *)p; |
17 |
+ |
|
18 |
+ |
if (sop->ofp != NULL) { |
19 |
+ |
int status = 0; |
20 |
+ |
if (sop->outpipe) |
21 |
+ |
status = pclose(sop->ofp); |
22 |
+ |
else if (sop->ofp != stdout) |
23 |
+ |
status = fclose(sop->ofp); |
24 |
+ |
if (status) |
25 |
+ |
error(SYSTEM, "error closing output stream"); |
26 |
+ |
} |
27 |
+ |
free(p); |
28 |
+ |
} |
29 |
+ |
|
30 |
+ |
LUTAB ofiletab = LU_SINIT(free,closestream); /* output file table */ |
31 |
+ |
|
32 |
|
#define OF_MODIFIER 01 |
33 |
|
#define OF_BIN 02 |
34 |
|
|
102 |
|
if (octname[strlen(octname)-1] != '\n') |
103 |
|
fputc('\n', fout); |
104 |
|
} else { |
105 |
< |
FILE *fin = fopen(octname, "r"); |
105 |
> |
FILE *fin = fopen(octname, (outfmt=='a') ? "r" : "rb"); |
106 |
|
if (fin == NULL) |
107 |
|
quit(1); |
108 |
< |
checkheader(fin, "ignore", fout); |
108 |
> |
checkheader(fin, OCTFMT, fout); |
109 |
|
fclose(fin); |
110 |
|
} |
111 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
139 |
|
STREAMOUT *sop; |
140 |
|
|
141 |
|
if (ospec == NULL) { /* use stdout? */ |
142 |
< |
if (!noopen && !using_stdout) { |
142 |
> |
if (!noopen & !using_stdout) { |
143 |
|
if (outfmt != 'a') |
144 |
|
SET_FILE_BINARY(stdout); |
145 |
|
if (header) |
275 |
|
put_contrib(const DCOLOR cnt, FILE *fout) |
276 |
|
{ |
277 |
|
double sf = 1; |
278 |
< |
float fv[3]; |
278 |
> |
COLOR fv; |
279 |
|
COLR cv; |
280 |
|
|
281 |
|
if (accumulate > 1) |
291 |
|
break; |
292 |
|
case 'f': |
293 |
|
if (accumulate > 1) { |
294 |
< |
fv[0] = sf*cnt[0]; fv[1] = sf*cnt[1]; fv[2] = sf*cnt[2]; |
294 |
> |
copycolor(fv, cnt); |
295 |
> |
scalecolor(fv, sf); |
296 |
|
} else |
297 |
|
copycolor(fv, cnt); |
298 |
|
fwrite(fv, sizeof(float), 3, fout); |
299 |
|
break; |
300 |
|
case 'd': |
301 |
|
if (accumulate > 1) { |
302 |
< |
double dv[3]; |
303 |
< |
dv[0] = sf*cnt[0]; dv[1] = sf*cnt[1]; dv[2] = sf*cnt[2]; |
302 |
> |
DCOLOR dv; |
303 |
> |
copycolor(dv, cnt); |
304 |
> |
scalecolor(dv, sf); |
305 |
|
fwrite(dv, sizeof(double), 3, fout); |
306 |
|
} else |
307 |
|
fwrite(cnt, sizeof(double), 3, fout); |
323 |
|
void |
324 |
|
mod_output(MODCONT *mp) |
325 |
|
{ |
326 |
< |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0,0); |
326 |
> |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0, 0); |
327 |
|
int j; |
328 |
|
|
329 |
|
put_contrib(mp->cbin[0], sop->ofp); |
330 |
|
if (mp->nbins > 3 && /* minor optimization */ |
331 |
< |
sop == getostream(mp->outspec, mp->modname, 1,0)) |
331 |
> |
sop == getostream(mp->outspec, mp->modname, 1, 0)) { |
332 |
|
for (j = 1; j < mp->nbins; j++) |
333 |
|
put_contrib(mp->cbin[j], sop->ofp); |
334 |
< |
else |
334 |
> |
} else { |
335 |
|
for (j = 1; j < mp->nbins; j++) { |
336 |
< |
sop = getostream(mp->outspec, mp->modname,j,0); |
336 |
> |
sop = getostream(mp->outspec, mp->modname, j, 0); |
337 |
|
put_contrib(mp->cbin[j], sop->ofp); |
338 |
|
} |
339 |
+ |
} |
340 |
|
} |
341 |
|
|
342 |
|
|
671 |
|
nvals = lastout * outvsiz; |
672 |
|
lu_doall(&ofiletab, myseeko, &nvals); |
673 |
|
/* skip repeated input */ |
674 |
+ |
lastout *= accumulate; |
675 |
|
for (nvals = 0; nvals < lastout; nvals++) { |
676 |
|
FVECT vdummy; |
677 |
|
if (getvec(vdummy) < 0 || getvec(vdummy) < 0) |
678 |
|
error(USER, "unexpected EOF on input"); |
679 |
|
} |
680 |
< |
lastray = lastdone = lastout * accumulate; |
680 |
> |
lastray = lastdone = (RNUMBER)lastout; |
681 |
|
if (raysleft) |
682 |
|
raysleft -= lastray; |
683 |
|
} |