| 26 |
|
|
| 27 |
|
int nowarn = 0; /* turn warnings off? */ |
| 28 |
|
|
| 29 |
– |
double expval = 1.; /* global exposure value */ |
| 30 |
– |
|
| 29 |
|
int ncprocs = 0; /* desired number of compute processes */ |
| 30 |
|
|
| 31 |
|
char *outdev = NULL; /* output device name */ |
| 32 |
|
|
| 33 |
+ |
int readinp = 0; /* read commands from stdin */ |
| 34 |
+ |
|
| 35 |
|
time_t starttime; /* time we got started */ |
| 36 |
|
time_t endtime; /* time we should end by */ |
| 37 |
|
time_t reporttime; /* time for next report */ |
| 62 |
|
int force = 0; |
| 63 |
|
/* mark start time */ |
| 64 |
|
starttime = time(NULL); |
| 65 |
< |
initurand(10240); /* initialize urand */ |
| 65 |
> |
initurand(16384); /* initialize urand */ |
| 66 |
|
progname = argv[0]; /* get arguments */ |
| 67 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 68 |
|
switch (argv[i][1]) { |
| 72 |
|
case 'f': /* force overwrite */ |
| 73 |
|
force++; |
| 74 |
|
break; |
| 75 |
+ |
case 'i': /* read input from stdin */ |
| 76 |
+ |
readinp++; |
| 77 |
+ |
break; |
| 78 |
|
case 'n': /* compute processes */ |
| 79 |
|
if (i >= argc-2) |
| 80 |
|
goto userr; |
| 118 |
|
creatholo(&hdg); |
| 119 |
|
} else { /* else load holodeck */ |
| 120 |
|
loadholo(); |
| 121 |
< |
if (vdef(RIF)) /* load RIF if any */ |
| 121 |
> |
/* check settings */ |
| 122 |
> |
checkvalues(); |
| 123 |
> |
/* load RIF if any */ |
| 124 |
> |
if (vdef(RIF)) |
| 125 |
|
getradfile(vval(RIF)); |
| 126 |
+ |
/* set defaults */ |
| 127 |
+ |
setdefaults(NULL); |
| 128 |
|
} |
| 129 |
|
/* initialize */ |
| 130 |
|
initrholo(); |
| 131 |
< |
/* run */ |
| 131 |
> |
/* main loop */ |
| 132 |
|
while (rholo()) |
| 133 |
|
; |
| 134 |
|
/* done */ |
| 192 |
|
{ |
| 193 |
|
extern int global_packet(); |
| 194 |
|
register int i; |
| 195 |
+ |
/* close holodeck on exec() */ |
| 196 |
+ |
fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); |
| 197 |
|
|
| 198 |
|
if (outdev != NULL) /* open output device */ |
| 199 |
|
disp_open(outdev); |
| 279 |
|
if (!disp_check(idle)) |
| 280 |
|
return(0); |
| 281 |
|
/* display only? */ |
| 282 |
< |
if (ncprocs <= 0) |
| 282 |
> |
if (nprocs <= 0) |
| 283 |
|
return(1); |
| 284 |
|
/* check file size */ |
| 285 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
| 345 |
|
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
| 346 |
|
error(WARNING, errmsg); |
| 347 |
|
} |
| 338 |
– |
if (sscanf(vval(SECTION), |
| 339 |
– |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", |
| 340 |
– |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
| 341 |
– |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
| 342 |
– |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
| 343 |
– |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12) |
| 344 |
– |
badvalue(SECTION); |
| 345 |
– |
maxlen = 0.; |
| 346 |
– |
for (i = 0; i < 3; i++) |
| 347 |
– |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
| 348 |
– |
maxlen = len[i]; |
| 349 |
– |
if (!vdef(GRID)) { |
| 350 |
– |
sprintf(buf, "%.4f", maxlen/8.); |
| 351 |
– |
vval(GRID) = savqstr(buf); |
| 352 |
– |
vdef(GRID)++; |
| 353 |
– |
} |
| 354 |
– |
if ((d = vflt(GRID)) <= FTINY) |
| 355 |
– |
badvalue(GRID); |
| 356 |
– |
for (i = 0; i < 3; i++) |
| 357 |
– |
gp->grid[i] = len[i]/d + (1.-FTINY); |
| 358 |
– |
if (!vdef(EXPOSURE)) { |
| 359 |
– |
sprintf(errmsg, "%s must be defined", vnam(EXPOSURE)); |
| 360 |
– |
error(USER, errmsg); |
| 361 |
– |
} |
| 362 |
– |
expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ? |
| 363 |
– |
pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE); |
| 348 |
|
if (!vdef(OCTREE)) { |
| 349 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
| 350 |
|
error(SYSTEM, "out of memory"); |
| 366 |
|
/* append rendering options */ |
| 367 |
|
if (vdef(RENDER)) |
| 368 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
| 369 |
+ |
|
| 370 |
+ |
if (gp == NULL) /* already initialized? */ |
| 371 |
+ |
return; |
| 372 |
+ |
/* set grid parameters */ |
| 373 |
+ |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
| 374 |
+ |
if (sscanf(vval(SECTION), |
| 375 |
+ |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
| 376 |
+ |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
| 377 |
+ |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
| 378 |
+ |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
| 379 |
+ |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
| 380 |
+ |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
| 381 |
+ |
badvalue(SECTION); |
| 382 |
+ |
maxlen = 0.; |
| 383 |
+ |
for (i = 0; i < 3; i++) |
| 384 |
+ |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
| 385 |
+ |
maxlen = len[i]; |
| 386 |
+ |
if (!vdef(GRID)) { |
| 387 |
+ |
sprintf(buf, "%.4f", maxlen/8.); |
| 388 |
+ |
vval(GRID) = savqstr(buf); |
| 389 |
+ |
vdef(GRID)++; |
| 390 |
+ |
} |
| 391 |
+ |
if ((d = vflt(GRID)) <= FTINY) |
| 392 |
+ |
badvalue(GRID); |
| 393 |
+ |
for (i = 0; i < 3; i++) |
| 394 |
+ |
if (gp->grid[i] <= 0) |
| 395 |
+ |
gp->grid[i] = len[i]/d + (1.-FTINY); |
| 396 |
|
} |
| 397 |
|
|
| 398 |
|
|
| 500 |
|
p->next = freepacks; |
| 501 |
|
freepacks = p; |
| 502 |
|
} |
| 503 |
< |
if (n2flush > 512*RPACKSIZ*ncprocs) { |
| 503 |
> |
if (n2flush > 512*RPACKSIZ*nprocs) { |
| 504 |
|
hdflush(NULL); /* flush holodeck buffers */ |
| 505 |
|
n2flush = 0; |
| 506 |
|
} |
| 510 |
|
getradfile(rfargs) /* run rad and get needed variables */ |
| 511 |
|
char *rfargs; |
| 512 |
|
{ |
| 513 |
< |
static short mvar[] = {OCTREE,EXPOSURE,-1}; |
| 513 |
> |
static short mvar[] = {OCTREE,-1}; |
| 514 |
|
static char tf1[] = TEMPLATE; |
| 515 |
|
char tf2[64]; |
| 516 |
|
char combuf[256]; |
| 610 |
|
int status = 0; |
| 611 |
|
|
| 612 |
|
if (hdlist[0] != NULL) { /* flush holodeck */ |
| 613 |
< |
if (ncprocs > 0) { |
| 613 |
> |
if (nprocs > 0) { |
| 614 |
|
done_packets(flush_queue()); |
| 615 |
|
status = end_rtrace(); /* close rtrace */ |
| 616 |
< |
hdflush(NULL); |
| 617 |
< |
if (vdef(REPORT)) { |
| 618 |
< |
long fsiz, fuse; |
| 619 |
< |
report(0); |
| 620 |
< |
fsiz = hdfilen(hdlist[0]->fd); |
| 621 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
| 622 |
< |
fprintf(stderr, |
| 616 |
> |
} |
| 617 |
> |
hdflush(NULL); |
| 618 |
> |
if (ncprocs > 0 && vdef(REPORT)) { |
| 619 |
> |
long fsiz, fuse; |
| 620 |
> |
report(0); |
| 621 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
| 622 |
> |
fuse = hdfiluse(hdlist[0]->fd, 1); |
| 623 |
> |
fprintf(stderr, |
| 624 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
| 625 |
< |
hdkfile, fsiz/(1024.*1024.), |
| 626 |
< |
100.*(fsiz-fuse)/fsiz); |
| 627 |
< |
} |
| 616 |
< |
} else |
| 617 |
< |
hdflush(NULL); |
| 625 |
> |
hdkfile, fsiz/(1024.*1024.), |
| 626 |
> |
100.*(fsiz-fuse)/fsiz); |
| 627 |
> |
} |
| 628 |
|
} |
| 629 |
|
if (orig_mode >= 0) /* reset holodeck access mode */ |
| 630 |
|
fchmod(hdlist[0]->fd, orig_mode); |