8 |
|
|
9 |
|
#include "rcontrib.h" |
10 |
|
#include "resolu.h" |
11 |
< |
#include "platform.h" |
11 |
> |
#include <ctype.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 */ |
113 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
114 |
|
fputnow(fout); |
115 |
+ |
fputs("NCOMP=3\n", fout); /* always RGB */ |
116 |
|
if (info != NULL) /* add extra info if given */ |
117 |
|
fputs(info, fout); |
118 |
|
fputformat(formstr(outfmt), fout); |
133 |
|
STREAMOUT * |
134 |
|
getostream(const char *ospec, const char *mname, int bn, int noopen) |
135 |
|
{ |
115 |
– |
/* static const DCOLOR nocontrib = BLKCOLOR; */ |
136 |
|
static STREAMOUT stdos; |
137 |
+ |
char info[1024]; |
138 |
|
int ofl; |
139 |
|
char oname[1024]; |
140 |
|
LUENT *lep; |
141 |
|
STREAMOUT *sop; |
142 |
|
|
143 |
|
if (ospec == NULL) { /* use stdout? */ |
144 |
< |
if (!noopen && !using_stdout) { |
144 |
> |
if (!noopen & !using_stdout) { |
145 |
|
if (outfmt != 'a') |
146 |
|
SET_FILE_BINARY(stdout); |
147 |
< |
if (header) |
148 |
< |
printheader(stdout, NULL); |
147 |
> |
if (header) { |
148 |
> |
sprintf(info, "NCOLS=%d\n", stdos.reclen); |
149 |
> |
printheader(stdout, info); |
150 |
> |
} |
151 |
|
printresolu(stdout, xres, yres); |
152 |
|
if (waitflush > 0) |
153 |
|
fflush(stdout); |
186 |
|
} |
187 |
|
} |
188 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
166 |
– |
long i; |
189 |
|
if (oname[0] == '!') /* output to command */ |
190 |
|
sop->ofp = popen(oname+1, "w"); |
191 |
|
else /* else open file */ |
198 |
|
flockfile(sop->ofp); /* avoid lock/unlock overhead */ |
199 |
|
#endif |
200 |
|
if (header) { |
179 |
– |
char info[512]; |
201 |
|
char *cp = info; |
202 |
|
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
203 |
|
sprintf(cp, "MODIFIER=%s\n", mname); |
207 |
|
sprintf(cp, "BIN=%d\n", bn); |
208 |
|
while (*cp) ++cp; |
209 |
|
} |
210 |
< |
*cp = '\0'; |
210 |
> |
sprintf(cp, "NCOLS=%d\n", sop->reclen); |
211 |
|
printheader(sop->ofp, info); |
212 |
|
} |
213 |
|
if (accumulate > 0) { /* global resolution */ |
214 |
|
sop->xr = xres; sop->yr = yres; |
215 |
|
} |
216 |
|
printresolu(sop->ofp, sop->xr, sop->yr); |
196 |
– |
#if 0 |
197 |
– |
/* play catch-up */ |
198 |
– |
for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) { |
199 |
– |
int j = sop->reclen; |
200 |
– |
if (j <= 0) j = 1; |
201 |
– |
while (j--) |
202 |
– |
put_contrib(nocontrib, sop->ofp); |
203 |
– |
if (outfmt == 'a') |
204 |
– |
putc('\n', sop->ofp); |
205 |
– |
} |
206 |
– |
#endif |
217 |
|
if (waitflush > 0) |
218 |
|
fflush(sop->ofp); |
219 |
|
} |
266 |
|
put_contrib(const DCOLOR cnt, FILE *fout) |
267 |
|
{ |
268 |
|
double sf = 1; |
269 |
< |
float fv[3]; |
269 |
> |
COLOR fv; |
270 |
|
COLR cv; |
271 |
|
|
272 |
|
if (accumulate > 1) |
282 |
|
break; |
283 |
|
case 'f': |
284 |
|
if (accumulate > 1) { |
285 |
< |
fv[0] = sf*cnt[0]; fv[1] = sf*cnt[1]; fv[2] = sf*cnt[2]; |
285 |
> |
copycolor(fv, cnt); |
286 |
> |
scalecolor(fv, sf); |
287 |
|
} else |
288 |
|
copycolor(fv, cnt); |
289 |
|
fwrite(fv, sizeof(float), 3, fout); |
290 |
|
break; |
291 |
|
case 'd': |
292 |
|
if (accumulate > 1) { |
293 |
< |
double dv[3]; |
294 |
< |
dv[0] = sf*cnt[0]; dv[1] = sf*cnt[1]; dv[2] = sf*cnt[2]; |
293 |
> |
DCOLOR dv; |
294 |
> |
copycolor(dv, cnt); |
295 |
> |
scalecolor(dv, sf); |
296 |
|
fwrite(dv, sizeof(double), 3, fout); |
297 |
|
} else |
298 |
|
fwrite(cnt, sizeof(double), 3, fout); |
314 |
|
void |
315 |
|
mod_output(MODCONT *mp) |
316 |
|
{ |
317 |
< |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0,0); |
317 |
> |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0, 0); |
318 |
|
int j; |
319 |
|
|
320 |
|
put_contrib(mp->cbin[0], sop->ofp); |
321 |
|
if (mp->nbins > 3 && /* minor optimization */ |
322 |
< |
sop == getostream(mp->outspec, mp->modname, 1,0)) |
322 |
> |
sop == getostream(mp->outspec, mp->modname, 1, 0)) { |
323 |
|
for (j = 1; j < mp->nbins; j++) |
324 |
|
put_contrib(mp->cbin[j], sop->ofp); |
325 |
< |
else |
325 |
> |
} else { |
326 |
|
for (j = 1; j < mp->nbins; j++) { |
327 |
< |
sop = getostream(mp->outspec, mp->modname,j,0); |
327 |
> |
sop = getostream(mp->outspec, mp->modname, j, 0); |
328 |
|
put_contrib(mp->cbin[j], sop->ofp); |
329 |
|
} |
330 |
+ |
} |
331 |
|
} |
332 |
|
|
333 |
|
|
354 |
|
end_record() |
355 |
|
{ |
356 |
|
--waitflush; |
357 |
< |
lu_doall(&ofiletab, puteol, NULL); |
357 |
> |
lu_doall(&ofiletab, &puteol, NULL); |
358 |
|
if (using_stdout & (outfmt == 'a')) |
359 |
|
putc('\n', stdout); |
360 |
|
if (!waitflush) { |
504 |
|
*(STREAMOUT *)oent->data = sout; |
505 |
|
} |
506 |
|
} |
507 |
< |
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
507 |
> |
lu_doall(&ofiletab, &myclose, NULL); /* close all files */ |
508 |
|
} |
509 |
|
|
510 |
|
|
660 |
|
} |
661 |
|
/* seek on all files */ |
662 |
|
nvals = lastout * outvsiz; |
663 |
< |
lu_doall(&ofiletab, myseeko, &nvals); |
663 |
> |
lu_doall(&ofiletab, &myseeko, &nvals); |
664 |
|
/* skip repeated input */ |
665 |
+ |
lastout *= accumulate; |
666 |
|
for (nvals = 0; nvals < lastout; nvals++) { |
667 |
|
FVECT vdummy; |
668 |
|
if (getvec(vdummy) < 0 || getvec(vdummy) < 0) |
669 |
|
error(USER, "unexpected EOF on input"); |
670 |
|
} |
671 |
< |
lastray = lastdone = lastout * accumulate; |
671 |
> |
lastray = lastdone = (RNUMBER)lastout; |
672 |
|
if (raysleft) |
673 |
|
raysleft -= lastray; |
674 |
|
} |