| 58 |
|
int argc; |
| 59 |
|
char *argv[]; |
| 60 |
|
{ |
| 61 |
– |
HDGRID hdg; |
| 61 |
|
int i; |
| 62 |
|
/* mark start time */ |
| 63 |
|
starttime = time(NULL); |
| 87 |
|
default: |
| 88 |
|
goto userr; |
| 89 |
|
} |
| 91 |
– |
/* do we have a job? */ |
| 92 |
– |
if (outdev == NULL && ncprocs <= 0) |
| 93 |
– |
goto userr; |
| 90 |
|
/* get root file name */ |
| 91 |
|
rootname(froot, hdkfile=argv[i++]); |
| 92 |
< |
/* load... */ |
| 93 |
< |
if (i < argc) { /* variables */ |
| 94 |
< |
loadvars(argv[i++]); |
| 95 |
< |
/* cmdline settings */ |
| 96 |
< |
for ( ; i < argc; i++) |
| 97 |
< |
if (setvariable(argv[i], matchvar) < 0) { |
| 98 |
< |
sprintf(errmsg, "unknown variable: %s", |
| 99 |
< |
argv[i]); |
| 100 |
< |
error(USER, errmsg); |
| 101 |
< |
} |
| 102 |
< |
/* check settings */ |
| 103 |
< |
checkvalues(); |
| 104 |
< |
/* load RIF if any */ |
| 105 |
< |
getradfile(); |
| 92 |
> |
/* load variables? */ |
| 93 |
> |
if (i < argc) |
| 94 |
> |
if (argv[i][0] != '-' && argv[i][0] != '+') |
| 95 |
> |
loadvars(argv[i]); /* load variables from file */ |
| 96 |
> |
|
| 97 |
> |
if (i >= argc || argv[i][0] == '+') |
| 98 |
> |
loadholo(); /* load existing holodeck */ |
| 99 |
> |
|
| 100 |
> |
while (++i < argc) /* get command line settings */ |
| 101 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
| 102 |
> |
sprintf(errmsg, "unknown variable: %s", argv[i]); |
| 103 |
> |
error(USER, errmsg); |
| 104 |
> |
} |
| 105 |
> |
/* check settings */ |
| 106 |
> |
checkvalues(); |
| 107 |
> |
/* load RIF if any */ |
| 108 |
> |
getradfile(); |
| 109 |
> |
|
| 110 |
> |
if (hdlist[0] == NULL) { /* create new holodeck */ |
| 111 |
> |
HDGRID hdg[HDMAX]; |
| 112 |
|
/* set defaults */ |
| 113 |
< |
setdefaults(&hdg); |
| 113 |
> |
setdefaults(hdg); |
| 114 |
|
/* holodeck exists? */ |
| 115 |
|
if (!force && access(hdkfile, R_OK|W_OK) == 0) |
| 116 |
|
error(USER, |
| 117 |
|
"holodeck file exists -- use -f to overwrite"); |
| 118 |
|
/* create holodeck */ |
| 119 |
< |
creatholo(&hdg); |
| 120 |
< |
} else { /* else load holodeck */ |
| 119 |
< |
loadholo(); |
| 120 |
< |
/* check settings */ |
| 121 |
< |
checkvalues(); |
| 122 |
< |
/* load RIF if any */ |
| 123 |
< |
getradfile(); |
| 124 |
< |
/* set defaults */ |
| 119 |
> |
creatholo(hdg); |
| 120 |
> |
} else /* else just set defaults */ |
| 121 |
|
setdefaults(NULL); |
| 126 |
– |
} |
| 122 |
|
/* initialize */ |
| 123 |
|
initrholo(); |
| 124 |
|
/* main loop */ |
| 128 |
|
quit(0); |
| 129 |
|
userr: |
| 130 |
|
fprintf(stderr, |
| 131 |
< |
"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
| 131 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
| 132 |
|
progname); |
| 133 |
|
quit(1); |
| 134 |
|
} |
| 142 |
|
if (gotsig++) /* two signals and we're gone! */ |
| 143 |
|
_exit(signo); |
| 144 |
|
|
| 145 |
< |
alarm(30); /* allow 30 seconds to clean up */ |
| 145 |
> |
alarm(60); /* allow 60 seconds to clean up */ |
| 146 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 147 |
|
eputs("signal - "); |
| 148 |
|
eputs(sigerr[signo]); |
| 262 |
|
|
| 263 |
|
rholo() /* holodeck main loop */ |
| 264 |
|
{ |
| 265 |
< |
static int idle = 1; |
| 265 |
> |
static int idle = 0; |
| 266 |
|
PACKET *pl = NULL, *plend; |
| 267 |
|
register PACKET *p; |
| 268 |
|
time_t t; |
| 269 |
|
long l; |
| 270 |
< |
|
| 276 |
< |
if (outdev != NULL) /* check display */ |
| 277 |
< |
if (!disp_check(idle)) |
| 278 |
< |
return(0); |
| 279 |
< |
/* display only? */ |
| 270 |
> |
/* check display */ |
| 271 |
|
if (nprocs <= 0) |
| 272 |
< |
return(outdev != NULL); |
| 272 |
> |
idle = 1; |
| 273 |
> |
if (outdev != NULL) { |
| 274 |
> |
if (!disp_check(idle)) |
| 275 |
> |
return(0); /* quit request */ |
| 276 |
> |
if (nprocs <= 0) |
| 277 |
> |
return(1); |
| 278 |
> |
} else if (idle) |
| 279 |
> |
return(0); /* all done */ |
| 280 |
|
/* check file size */ |
| 281 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
| 282 |
|
error(WARNING, "file limit exceeded"); |
| 283 |
|
done_rtrace(); |
| 286 |
– |
idle = 1; |
| 284 |
|
return(1); /* comes back */ |
| 285 |
|
} |
| 286 |
|
/* check time */ |
| 289 |
|
if (endtime > 0 && t >= endtime) { |
| 290 |
|
error(WARNING, "time limit exceeded"); |
| 291 |
|
done_rtrace(); |
| 295 |
– |
idle = 1; |
| 292 |
|
return(1); /* comes back */ |
| 293 |
|
} |
| 294 |
|
if (reporttime > 0 && t >= reporttime) |
| 295 |
|
report(t); |
| 296 |
< |
/* get packets to process */ |
| 296 |
> |
idle = 0; /* get packets to process */ |
| 297 |
|
while (freepacks != NULL) { |
| 298 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
| 299 |
|
if (!next_packet(p)) { |
| 316 |
|
{ |
| 317 |
|
extern char *atos(); |
| 318 |
|
register int i; |
| 319 |
+ |
int n; |
| 320 |
|
double len[3], maxlen, d; |
| 321 |
|
char buf[64]; |
| 322 |
|
|
| 324 |
|
sprintf(errmsg, "%s must be defined", vnam(SECTION)); |
| 325 |
|
error(USER, errmsg); |
| 326 |
|
} |
| 330 |
– |
if (vdef(SECTION) > 1) { |
| 331 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
| 332 |
– |
error(WARNING, errmsg); |
| 333 |
– |
} |
| 327 |
|
if (!vdef(OCTREE)) { |
| 328 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
| 329 |
|
error(SYSTEM, "out of memory"); |
| 334 |
|
vval(VDIST) = "F"; |
| 335 |
|
vdef(VDIST)++; |
| 336 |
|
} |
| 344 |
– |
if (!vdef(OCCUPANCY)) { |
| 345 |
– |
vval(OCCUPANCY) = "U"; |
| 346 |
– |
vdef(OCCUPANCY)++; |
| 347 |
– |
} |
| 337 |
|
/* append rendering options */ |
| 338 |
|
if (vdef(RENDER)) |
| 339 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
| 341 |
|
if (gp == NULL) /* already initialized? */ |
| 342 |
|
return; |
| 343 |
|
/* set grid parameters */ |
| 344 |
< |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
| 345 |
< |
if (sscanf(vval(SECTION), |
| 344 |
> |
for (n = 0; n < vdef(SECTION); n++, gp++) { |
| 345 |
> |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
| 346 |
> |
if (sscanf(nvalue(SECTION, n), |
| 347 |
|
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
| 348 |
< |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
| 349 |
< |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
| 350 |
< |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
| 351 |
< |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
| 352 |
< |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
| 353 |
< |
badvalue(SECTION); |
| 354 |
< |
maxlen = 0.; |
| 355 |
< |
for (i = 0; i < 3; i++) |
| 356 |
< |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
| 357 |
< |
maxlen = len[i]; |
| 358 |
< |
if (!vdef(GRID)) { |
| 359 |
< |
sprintf(buf, "%.4f", maxlen/8.); |
| 360 |
< |
vval(GRID) = savqstr(buf); |
| 361 |
< |
vdef(GRID)++; |
| 348 |
> |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
| 349 |
> |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
| 350 |
> |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
| 351 |
> |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
| 352 |
> |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
| 353 |
> |
badvalue(SECTION); |
| 354 |
> |
maxlen = 0.; |
| 355 |
> |
for (i = 0; i < 3; i++) |
| 356 |
> |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
| 357 |
> |
maxlen = len[i]; |
| 358 |
> |
if (!vdef(GRID)) |
| 359 |
> |
d = 0.125*maxlen; |
| 360 |
> |
else if ((d = vflt(GRID)) <= FTINY) |
| 361 |
> |
badvalue(GRID); |
| 362 |
> |
for (i = 0; i < 3; i++) |
| 363 |
> |
if (gp->grid[i] <= 0) |
| 364 |
> |
gp->grid[i] = len[i]/d + (1.-FTINY); |
| 365 |
|
} |
| 373 |
– |
if ((d = vflt(GRID)) <= FTINY) |
| 374 |
– |
badvalue(GRID); |
| 375 |
– |
for (i = 0; i < 3; i++) |
| 376 |
– |
if (gp->grid[i] <= 0) |
| 377 |
– |
gp->grid[i] = len[i]/d + (1.-FTINY); |
| 366 |
|
} |
| 367 |
|
|
| 368 |
|
|
| 370 |
|
HDGRID *gp; |
| 371 |
|
{ |
| 372 |
|
extern char VersionID[]; |
| 373 |
< |
long endloc = 0; |
| 373 |
> |
int4 lastloc, nextloc; |
| 374 |
> |
int n; |
| 375 |
|
int fd; |
| 376 |
|
FILE *fp; |
| 377 |
|
/* open & truncate file */ |
| 385 |
|
printvars(fp); |
| 386 |
|
fputformat(HOLOFMT, fp); |
| 387 |
|
fputc('\n', fp); |
| 388 |
< |
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
| 400 |
< |
fwrite(&endloc, sizeof(long), 1, fp); |
| 388 |
> |
putw(HOLOMAGIC, fp); /* put magic number */ |
| 389 |
|
fd = dup(fileno(fp)); |
| 390 |
|
fclose(fp); /* flush and close stdio stream */ |
| 391 |
< |
hdinit(fd, gp); /* allocate and initialize index */ |
| 391 |
> |
lastloc = lseek(fd, 0L, 2); |
| 392 |
> |
for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ |
| 393 |
> |
nextloc = 0L; |
| 394 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
| 395 |
> |
hdinit(fd, gp); /* writes beam index */ |
| 396 |
> |
if (!n) |
| 397 |
> |
break; |
| 398 |
> |
nextloc = hdfilen(fd); /* write section pointer */ |
| 399 |
> |
if (lseek(fd, (long)lastloc, 0) < 0) |
| 400 |
> |
error(SYSTEM, |
| 401 |
> |
"cannot seek on holodeck file in creatholo"); |
| 402 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
| 403 |
> |
lseek(fd, (long)(lastloc=nextloc), 0); |
| 404 |
> |
} |
| 405 |
|
} |
| 406 |
|
|
| 407 |
|
|
| 434 |
|
extern long ftell(); |
| 435 |
|
FILE *fp; |
| 436 |
|
int fd; |
| 437 |
< |
long fpos; |
| 437 |
> |
int n; |
| 438 |
> |
int4 nextloc; |
| 439 |
|
/* open holodeck file */ |
| 440 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
| 441 |
|
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
| 450 |
|
hdkfile); |
| 451 |
|
error(USER, errmsg); |
| 452 |
|
} |
| 453 |
< |
fread(&fpos, sizeof(long), 1, fp); |
| 452 |
< |
if (fpos != 0) |
| 453 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
| 454 |
< |
fpos = ftell(fp); /* get stdio position */ |
| 453 |
> |
nextloc = ftell(fp); /* get stdio position */ |
| 454 |
|
fd = dup(fileno(fp)); |
| 455 |
|
fclose(fp); /* done with stdio */ |
| 456 |
< |
lseek(fd, fpos, 0); /* align system file pointer */ |
| 457 |
< |
hdinit(fd, NULL); /* allocate and load index */ |
| 456 |
> |
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 457 |
> |
lseek(fd, (long)nextloc, 0); |
| 458 |
> |
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 459 |
> |
hdinit(fd, NULL); |
| 460 |
> |
} |
| 461 |
> |
if (n != vdef(SECTION)) { |
| 462 |
> |
sprintf(errmsg, "number of sections does not match %s setting", |
| 463 |
> |
vnam(SECTION)); |
| 464 |
> |
error(WARNING, errmsg); |
| 465 |
> |
} |
| 466 |
|
} |
| 467 |
|
|
| 468 |
|
|