123 |
|
int outfmt = 'a'; /* output format */ |
124 |
|
|
125 |
|
int header = 1; /* output header? */ |
126 |
+ |
int force_open = 0; /* truncate existing output? */ |
127 |
|
int xres = 0; /* horiz. output resolution */ |
128 |
|
int yres = 0; /* vert. output resolution */ |
129 |
|
|
267 |
|
continue; |
268 |
|
} |
269 |
|
break; |
270 |
< |
case 'f': /* file or i/o format */ |
270 |
> |
case 'f': /* file or force or format */ |
271 |
|
if (!argv[i][2]) { |
272 |
|
char *fpath; |
273 |
|
if (i >= argc-2) break; |
282 |
|
fcompile(fpath); |
283 |
|
continue; |
284 |
|
} |
285 |
+ |
if (argv[i][2] == 'o') { |
286 |
+ |
force_open++; |
287 |
+ |
continue; |
288 |
+ |
} |
289 |
|
setformat(argv[i]+2); |
290 |
|
continue; |
291 |
|
case 'e': /* expression */ |
325 |
|
rtargv[rtargc++] = argv[++i]; |
326 |
|
addmodfile(argv[i], curout, binval, bincnt); |
327 |
|
continue; |
328 |
+ |
case 'P': /* persist file */ |
329 |
+ |
error(USER, "persist file is automatic"); |
330 |
+ |
break; |
331 |
|
} |
332 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
333 |
|
} |
710 |
|
sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); |
711 |
|
if (sop == NULL) |
712 |
|
error(SYSTEM, "out of memory in getostream"); |
713 |
< |
sop->reclen = oname[0] == '!' ? CNT_PIPE : 0; |
713 |
> |
sop->reclen = oname[0] == '!' ? CNT_PIPE : CNT_UNKNOWN; |
714 |
|
sop->ofp = NULL; /* open iff noopen==0 */ |
715 |
|
lep->data = (char *)sop; |
716 |
|
} |
717 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
718 |
< |
int i; |
718 |
> |
long i; |
719 |
|
if (oname[0] == '!') /* output to command */ |
720 |
|
sop->ofp = popen(oname+1, "w"); |
721 |
< |
else |
721 |
> |
else if (!force_open && access(oname, F_OK) == 0) |
722 |
> |
errno = EEXIST; /* file exists */ |
723 |
> |
else /* else open it */ |
724 |
|
sop->ofp = fopen(oname, "w"); |
725 |
|
if (sop->ofp == NULL) { |
726 |
|
sprintf(errmsg, "cannot open '%s' for writing", oname); |
744 |
|
} |
745 |
|
printresolu(sop->ofp); |
746 |
|
/* play catch-up */ |
747 |
< |
for (i = 0; i < lastdone; i++) { |
747 |
> |
for (i = sop->reclen > 1 ? sop->reclen*lastdone : lastdone; |
748 |
> |
i--; ) { |
749 |
|
static const DCOLOR nocontrib = BLKCOLOR; |
750 |
|
put_contrib(nocontrib, sop->ofp); |
751 |
|
if (outfmt == 'a') |
763 |
|
int |
764 |
|
getinp(char *buf, FILE *fp) |
765 |
|
{ |
766 |
+ |
double dv[3]; |
767 |
+ |
float fv[3]; |
768 |
|
char *cp; |
769 |
|
int i; |
770 |
|
|
773 |
|
cp = buf; /* make sure we get 6 floats */ |
774 |
|
for (i = 0; i < 6; i++) { |
775 |
|
if (fgetword(cp, buf+127-cp, fp) == NULL) |
776 |
< |
return 0; |
776 |
> |
return -1; |
777 |
> |
if (i >= 3) |
778 |
> |
dv[i-3] = atof(cp); |
779 |
|
if ((cp = fskip(cp)) == NULL || *cp) |
780 |
< |
return 0; |
780 |
> |
return -1; |
781 |
|
*cp++ = ' '; |
782 |
|
} |
783 |
|
getc(fp); /* get/put eol */ |
784 |
|
*cp-- = '\0'; *cp = '\n'; |
785 |
+ |
if (DOT(dv,dv) <= FTINY*FTINY) |
786 |
+ |
return 0; /* dummy ray */ |
787 |
|
return strlen(buf); |
788 |
|
case 'f': |
789 |
|
if (fread(buf, sizeof(float), 6, fp) < 6) |
790 |
< |
return 0; |
790 |
> |
return -1; |
791 |
> |
memcpy(fv, buf+3*sizeof(float), 3*sizeof(float)); |
792 |
> |
if (DOT(fv,fv) <= FTINY*FTINY) |
793 |
> |
return 0; /* dummy ray */ |
794 |
|
return sizeof(float)*6; |
795 |
|
case 'd': |
796 |
|
if (fread(buf, sizeof(double), 6, fp) < 6) |
797 |
< |
return 0; |
797 |
> |
return -1; |
798 |
> |
memcpy(dv, buf+3*sizeof(double), 3*sizeof(double)); |
799 |
> |
if (DOT(dv,dv) <= FTINY*FTINY) |
800 |
> |
return 0; /* dummy ray */ |
801 |
|
return sizeof(double)*6; |
802 |
|
} |
803 |
|
error(INTERNAL, "botched input format"); |
804 |
< |
return 0; /* pro forma return */ |
804 |
> |
return -1; /* pro forma return */ |
805 |
|
} |
806 |
|
|
807 |
|
static float rparams[9]; /* traced ray parameters */ |
975 |
|
} |
976 |
|
done_contrib(); /* sum up contributions & output */ |
977 |
|
lastdone = rtp->raynum; |
978 |
< |
free(rtp->buf); /* free up buffer space */ |
978 |
> |
if (rtp->buf != NULL) /* free up buffer space */ |
979 |
> |
free(rtp->buf); |
980 |
|
rt_unproc = rtp->next; |
981 |
|
free(rtp); /* done with this ray tree */ |
982 |
|
} |
1064 |
|
int iblen; |
1065 |
|
struct rtproc *rtp; |
1066 |
|
/* loop over input */ |
1067 |
< |
while ((iblen = getinp(inpbuf, fin)) > 0) { |
1068 |
< |
if (lastray+1 < lastray || /* need reset? */ |
1069 |
< |
queue_length() > 5*nrtprocs()) { |
1067 |
> |
while ((iblen = getinp(inpbuf, fin)) >= 0) { |
1068 |
> |
if (!iblen || /* need reset? */ |
1069 |
> |
queue_length() > 10*nrtprocs() || |
1070 |
> |
lastray+1 < lastray) { |
1071 |
|
while (wait_rproc() != NULL) |
1072 |
|
process_queue(); |
1073 |
< |
lastdone = lastray = 0; |
1073 |
> |
if (lastray+1 < lastray) |
1074 |
> |
lastdone = lastray = 0; |
1075 |
|
} |
1076 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
1077 |
< |
rtp->raynum = ++lastray; /* assign ray to it */ |
1078 |
< |
writebuf(rtp->pd.w, inpbuf, iblen); |
1079 |
< |
if (raysleft && !--raysleft) |
1080 |
< |
break; |
1077 |
> |
rtp->raynum = ++lastray; /* assign ray */ |
1078 |
> |
if (iblen) { /* trace ray if valid */ |
1079 |
> |
writebuf(rtp->pd.w, inpbuf, iblen); |
1080 |
> |
} else { /* else bypass dummy ray */ |
1081 |
> |
queue_raytree(rtp); /* empty tree */ |
1082 |
> |
if ((yres <= 0) | (waitflush > 1)) |
1083 |
> |
waitflush = 1; /* flush after this */ |
1084 |
> |
} |
1085 |
|
process_queue(); /* catch up with results */ |
1086 |
+ |
if (raysleft && !--raysleft) |
1087 |
+ |
break; /* preemptive EOI */ |
1088 |
|
} |
1089 |
|
while (wait_rproc() != NULL) /* process outstanding rays */ |
1090 |
|
process_queue(); |
1160 |
|
if (oent->data != NULL) { |
1161 |
|
sout = *(STREAMOUT *)oent->data; |
1162 |
|
} else { |
1163 |
< |
sout.reclen = 0; |
1163 |
> |
sout.reclen = CNT_UNKNOWN; |
1164 |
|
sout.ofp = NULL; |
1165 |
|
} |
1166 |
|
if (sout.ofp != NULL) { /* already open? */ |
1242 |
|
lu_doall(&ofiletab, myseeko, &nvals); |
1243 |
|
/* skip repeated input */ |
1244 |
|
for (nvals = 0; nvals < lastout; nvals++) |
1245 |
< |
if (getinp(oname, fin) <= 0) |
1245 |
> |
if (getinp(oname, fin) < 0) |
1246 |
|
error(USER, "unexpected EOF on input"); |
1247 |
|
lastray = lastdone = (unsigned long)lastout; |
1248 |
|
if (raysleft) |