| 33 |
|
time_t endtime; /* time we should end by */ |
| 34 |
|
time_t reporttime; /* time for next report */ |
| 35 |
|
|
| 36 |
+ |
long maxdisk; /* maximum file space (bytes) */ |
| 37 |
+ |
|
| 38 |
|
int rtargc = 1; /* rtrace command */ |
| 39 |
|
char *rtargv[128] = {"rtrace", NULL}; |
| 40 |
|
|
| 129 |
|
{ |
| 130 |
|
extern int global_packet(); |
| 131 |
|
register int i; |
| 132 |
< |
/* check output device */ |
| 133 |
< |
if (outdev != NULL) |
| 134 |
< |
open_display(outdev); |
| 132 |
> |
|
| 133 |
> |
if (outdev != NULL) /* open output device */ |
| 134 |
> |
disp_open(outdev); |
| 135 |
|
else if (ncprocs > 0) /* else use global ray feed */ |
| 136 |
|
init_global(); |
| 137 |
+ |
/* record disk space limit */ |
| 138 |
+ |
if (!vdef(DISKSPACE)) |
| 139 |
+ |
maxdisk = 0; |
| 140 |
+ |
else |
| 141 |
+ |
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
| 142 |
|
/* record end time */ |
| 143 |
|
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
| 144 |
|
endtime = 0; |
| 145 |
|
else |
| 146 |
|
endtime = starttime + vflt(TIME)*3600.; |
| 147 |
|
/* set up memory cache */ |
| 148 |
< |
hdcachesize = 1024.*1024.*vflt(CACHE); |
| 148 |
> |
if (outdev == NULL) |
| 149 |
> |
hdcachesize = 0; /* manual flushing */ |
| 150 |
> |
else if (vdef(CACHE)) |
| 151 |
> |
hdcachesize = 1024.*1024.*vflt(CACHE); |
| 152 |
|
/* open report file */ |
| 153 |
|
if (vdef(REPORT)) { |
| 154 |
|
register char *s = sskip2(vval(REPORT), 1); |
| 197 |
|
register PACKET *p; |
| 198 |
|
time_t t; |
| 199 |
|
long l; |
| 200 |
< |
/* check display */ |
| 201 |
< |
if (outdev != NULL && !disp_check(idle)) |
| 202 |
< |
return(0); |
| 200 |
> |
|
| 201 |
> |
if (outdev != NULL) /* check display */ |
| 202 |
> |
if (!disp_check(idle)) |
| 203 |
> |
return(0); |
| 204 |
|
/* display only? */ |
| 205 |
|
if (ncprocs <= 0) |
| 206 |
|
return(1); |
| 207 |
|
/* check file size */ |
| 208 |
< |
if ((l = 1024.*1024.*vflt(DISKSPACE)) > 0 && |
| 209 |
< |
hdfiluse(hdlist[0]->fd, 0) + hdmemuse(0) >= l) |
| 208 |
> |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
| 209 |
> |
error(WARNING, "file limit exceeded"); |
| 210 |
|
return(0); |
| 211 |
+ |
} |
| 212 |
|
/* check time */ |
| 213 |
|
if (endtime > 0 || reporttime > 0) |
| 214 |
|
t = time(NULL); |
| 215 |
< |
if (endtime > 0 && t >= endtime) |
| 215 |
> |
if (endtime > 0 && t >= endtime) { |
| 216 |
> |
error(WARNING, "time limit exceeded"); |
| 217 |
|
return(0); |
| 218 |
+ |
} |
| 219 |
|
if (reporttime > 0 && t >= reporttime) |
| 220 |
|
report(t); |
| 221 |
|
/* get packets to process */ |
| 300 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
| 301 |
|
vdef(OCTREE)++; |
| 302 |
|
} |
| 289 |
– |
if (!vdef(DISKSPACE)) { |
| 290 |
– |
sprintf(errmsg, |
| 291 |
– |
"no %s setting, assuming 100 Mbytes available", |
| 292 |
– |
vnam(DISKSPACE)); |
| 293 |
– |
error(WARNING, errmsg); |
| 294 |
– |
vval(DISKSPACE) = "100"; |
| 295 |
– |
vdef(DISKSPACE)++; |
| 296 |
– |
} |
| 297 |
– |
if (!vdef(CACHE)) { |
| 298 |
– |
sprintf(errmsg, |
| 299 |
– |
"no %s setting, assuming 10 Mbytes available", |
| 300 |
– |
vnam(CACHE)); |
| 301 |
– |
error(WARNING, errmsg); |
| 302 |
– |
vval(CACHE) = "10"; |
| 303 |
– |
vdef(CACHE)++; |
| 304 |
– |
} |
| 303 |
|
if (!vdef(OBSTRUCTIONS)) { |
| 304 |
|
vval(OBSTRUCTIONS) = "T"; |
| 305 |
|
vdef(OBSTRUCTIONS)++; |
| 365 |
|
{ |
| 366 |
|
FILE *fp; |
| 367 |
|
long endloc; |
| 368 |
< |
/* open input file */ |
| 369 |
< |
if ((fp = fopen(hdkfile, "r+")) == NULL) { |
| 370 |
< |
sprintf(errmsg, "cannot open \"%s\" for appending", hdkfile); |
| 368 |
> |
/* open holodeck file */ |
| 369 |
> |
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
| 370 |
> |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
| 371 |
> |
ncprocs>0 ? "appending" : "reading"); |
| 372 |
|
error(SYSTEM, errmsg); |
| 373 |
|
} |
| 374 |
|
/* load variables from header */ |
| 391 |
|
done_packets(pl) /* handle finished packets */ |
| 392 |
|
PACKET *pl; |
| 393 |
|
{ |
| 394 |
+ |
static int nunflushed = 0; |
| 395 |
|
register PACKET *p; |
| 396 |
|
|
| 397 |
|
while (pl != NULL) { |
| 401 |
|
(char *)hdnewrays(hdlist[p->hd],p->bi,p->nr), |
| 402 |
|
p->nr*sizeof(RAYVAL)); |
| 403 |
|
if (outdev != NULL) /* display it */ |
| 404 |
< |
disp_packet(p); |
| 404 |
> |
disp_packet((PACKHEAD *)p); |
| 405 |
> |
else |
| 406 |
> |
nunflushed += p->nr; |
| 407 |
> |
nraysdone += p->nr; |
| 408 |
> |
npacksdone++; |
| 409 |
|
} |
| 406 |
– |
nraysdone += p->nr; |
| 407 |
– |
npacksdone++; |
| 410 |
|
p->nr = 0; /* push onto free list */ |
| 411 |
|
p->next = freepacks; |
| 412 |
|
freepacks = p; |
| 413 |
|
} |
| 414 |
+ |
if (nunflushed >= 256*RPACKSIZ) { |
| 415 |
+ |
hdflush(NULL); /* flush holodeck buffers */ |
| 416 |
+ |
nunflushed = 0; |
| 417 |
+ |
} |
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
|
| 421 |
|
getradfile(rfargs) /* run rad and get needed variables */ |
| 422 |
|
char *rfargs; |
| 423 |
|
{ |
| 424 |
< |
static short mvar[] = {VIEW,OCTREE,EXPOSURE,-1}; |
| 424 |
> |
static short mvar[] = {OCTREE,EXPOSURE,-1}; |
| 425 |
|
static char tf1[] = TEMPLATE; |
| 426 |
|
char tf2[64]; |
| 427 |
|
char combuf[256]; |
| 520 |
|
{ |
| 521 |
|
int status = 0; |
| 522 |
|
|
| 523 |
+ |
if (outdev != NULL) /* close display */ |
| 524 |
+ |
disp_close(); |
| 525 |
|
if (hdlist[0] != NULL) { /* flush holodeck */ |
| 526 |
|
if (ncprocs > 0) { |
| 527 |
|
done_packets(flush_queue()); |
| 530 |
|
if (vdef(REPORT)) { |
| 531 |
|
long fsiz, fuse; |
| 532 |
|
report(0); |
| 533 |
< |
fsiz = lseek(hdlist[0]->fd, 0L, 2); |
| 533 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
| 534 |
|
fuse = hdfiluse(hdlist[0]->fd, 1); |
| 535 |
|
fprintf(stderr, |
| 536 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |