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