| 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]); | 
| 228 |  | goto memerr; | 
| 229 |  | freepacks[--i].nr = 0; | 
| 230 |  | freepacks[i].next = NULL; | 
| 231 | < | if (!vbool(OBSTRUCTIONS)) { | 
| 231 | > | if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { | 
| 232 |  | freepacks[i].offset = (float *)bmalloc( | 
| 233 |  | RPACKSIZ*sizeof(float)*(i+1) ); | 
| 234 |  | if (freepacks[i].offset == NULL) | 
| 272 |  | if (!disp_check(idle)) | 
| 273 |  | return(0); | 
| 274 |  | /* display only? */ | 
| 275 | < | if (nprocs <= 0) | 
| 275 | > | if (nprocs <= 0) { | 
| 276 | > | idle = 1; | 
| 277 |  | return(outdev != NULL); | 
| 278 | + | } | 
| 279 |  | /* check file size */ | 
| 280 |  | if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { | 
| 281 |  | error(WARNING, "file limit exceeded"); | 
| 282 |  | done_rtrace(); | 
| 286 | – | idle = 1; | 
| 283 |  | return(1);      /* comes back */ | 
| 284 |  | } | 
| 285 |  | /* check time */ | 
| 288 |  | if (endtime > 0 && t >= endtime) { | 
| 289 |  | error(WARNING, "time limit exceeded"); | 
| 290 |  | done_rtrace(); | 
| 295 | – | idle = 1; | 
| 291 |  | return(1);      /* comes back */ | 
| 292 |  | } | 
| 293 |  | if (reporttime > 0 && t >= reporttime) | 
| 294 |  | report(t); | 
| 295 | < | /* get packets to process */ | 
| 295 | > | idle = 0;                       /* get packets to process */ | 
| 296 |  | while (freepacks != NULL) { | 
| 297 |  | p = freepacks; freepacks = p->next; p->next = NULL; | 
| 298 |  | if (!next_packet(p)) { | 
| 315 |  | { | 
| 316 |  | extern char     *atos(); | 
| 317 |  | register int    i; | 
| 318 | + | int     n; | 
| 319 |  | double  len[3], maxlen, d; | 
| 320 |  | char    buf[64]; | 
| 321 |  |  | 
| 323 |  | sprintf(errmsg, "%s must be defined", vnam(SECTION)); | 
| 324 |  | error(USER, errmsg); | 
| 325 |  | } | 
| 330 | – | if (vdef(SECTION) > 1) { | 
| 331 | – | sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); | 
| 332 | – | error(WARNING, errmsg); | 
| 333 | – | } | 
| 326 |  | if (!vdef(OCTREE)) { | 
| 327 |  | if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) | 
| 328 |  | error(SYSTEM, "out of memory"); | 
| 329 |  | sprintf(vval(OCTREE), "%s.oct", froot); | 
| 330 |  | vdef(OCTREE)++; | 
| 331 |  | } | 
| 340 | – | if (!vdef(OBSTRUCTIONS)) { | 
| 341 | – | vval(OBSTRUCTIONS) = "T"; | 
| 342 | – | vdef(OBSTRUCTIONS)++; | 
| 343 | – | } | 
| 332 |  | if (!vdef(VDIST)) { | 
| 333 |  | vval(VDIST) = "F"; | 
| 334 |  | vdef(VDIST)++; | 
| 335 |  | } | 
| 348 | – | if (!vdef(OCCUPANCY)) { | 
| 349 | – | vval(OCCUPANCY) = "U"; | 
| 350 | – | vdef(OCCUPANCY)++; | 
| 351 | – | } | 
| 336 |  | /* append rendering options */ | 
| 337 |  | if (vdef(RENDER)) | 
| 338 |  | rtargc += wordstring(rtargv+rtargc, vval(RENDER)); | 
| 340 |  | if (gp == NULL)         /* already initialized? */ | 
| 341 |  | return; | 
| 342 |  | /* set grid parameters */ | 
| 343 | < | gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; | 
| 344 | < | if (sscanf(vval(SECTION), | 
| 343 | > | for (n = 0; n < vdef(SECTION); n++, gp++) { | 
| 344 | > | gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; | 
| 345 | > | if (sscanf(nvalue(SECTION, n), | 
| 346 |  | "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", | 
| 347 | < | &gp->orig[0], &gp->orig[1], &gp->orig[2], | 
| 348 | < | &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], | 
| 349 | < | &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], | 
| 350 | < | &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], | 
| 351 | < | &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) | 
| 352 | < | badvalue(SECTION); | 
| 353 | < | maxlen = 0.; | 
| 354 | < | for (i = 0; i < 3; i++) | 
| 355 | < | if ((len[i] = VLEN(gp->xv[i])) > maxlen) | 
| 356 | < | maxlen = len[i]; | 
| 357 | < | if (!vdef(GRID)) { | 
| 358 | < | sprintf(buf, "%.4f", maxlen/8.); | 
| 359 | < | vval(GRID) = savqstr(buf); | 
| 360 | < | vdef(GRID)++; | 
| 347 | > | &gp->orig[0], &gp->orig[1], &gp->orig[2], | 
| 348 | > | &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], | 
| 349 | > | &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], | 
| 350 | > | &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], | 
| 351 | > | &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) | 
| 352 | > | badvalue(SECTION); | 
| 353 | > | maxlen = 0.; | 
| 354 | > | for (i = 0; i < 3; i++) | 
| 355 | > | if ((len[i] = VLEN(gp->xv[i])) > maxlen) | 
| 356 | > | maxlen = len[i]; | 
| 357 | > | if (!vdef(GRID)) | 
| 358 | > | d = 0.125*maxlen; | 
| 359 | > | else if ((d = vflt(GRID)) <= FTINY) | 
| 360 | > | badvalue(GRID); | 
| 361 | > | for (i = 0; i < 3; i++) | 
| 362 | > | if (gp->grid[i] <= 0) | 
| 363 | > | gp->grid[i] = len[i]/d + (1.-FTINY); | 
| 364 |  | } | 
| 377 | – | if ((d = vflt(GRID)) <= FTINY) | 
| 378 | – | badvalue(GRID); | 
| 379 | – | for (i = 0; i < 3; i++) | 
| 380 | – | if (gp->grid[i] <= 0) | 
| 381 | – | gp->grid[i] = len[i]/d + (1.-FTINY); | 
| 365 |  | } | 
| 366 |  |  | 
| 367 |  |  | 
| 369 |  | HDGRID  *gp; | 
| 370 |  | { | 
| 371 |  | extern char     VersionID[]; | 
| 372 | < | long    endloc = 0; | 
| 372 | > | int4    lastloc, nextloc; | 
| 373 | > | int     n; | 
| 374 |  | int     fd; | 
| 375 |  | FILE    *fp; | 
| 376 |  | /* open & truncate file */ | 
| 384 |  | printvars(fp); | 
| 385 |  | fputformat(HOLOFMT, fp); | 
| 386 |  | fputc('\n', fp); | 
| 387 | < | putw(HOLOMAGIC, fp);            /* put magic number & terminus */ | 
| 404 | < | fwrite(&endloc, sizeof(long), 1, fp); | 
| 387 | > | putw(HOLOMAGIC, fp);            /* put magic number */ | 
| 388 |  | fd = dup(fileno(fp)); | 
| 389 |  | fclose(fp);                     /* flush and close stdio stream */ | 
| 390 | < | hdinit(fd, gp);                 /* allocate and initialize index */ | 
| 390 | > | lastloc = lseek(fd, 0L, 2); | 
| 391 | > | for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */ | 
| 392 | > | nextloc = 0L; | 
| 393 | > | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 394 | > | hdinit(fd, gp);                 /* writes beam index */ | 
| 395 | > | if (!n) | 
| 396 | > | break; | 
| 397 | > | nextloc = hdfilen(fd);          /* write section pointer */ | 
| 398 | > | if (lseek(fd, (long)lastloc, 0) < 0) | 
| 399 | > | error(SYSTEM, | 
| 400 | > | "cannot seek on holodeck file in creatholo"); | 
| 401 | > | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 402 | > | lseek(fd, (long)(lastloc=nextloc), 0); | 
| 403 | > | } | 
| 404 |  | } | 
| 405 |  |  | 
| 406 |  |  | 
| 433 |  | extern long     ftell(); | 
| 434 |  | FILE    *fp; | 
| 435 |  | int     fd; | 
| 436 | < | long    fpos; | 
| 436 | > | int     n; | 
| 437 | > | int4    nextloc; | 
| 438 |  | /* open holodeck file */ | 
| 439 |  | if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { | 
| 440 |  | sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, | 
| 449 |  | hdkfile); | 
| 450 |  | error(USER, errmsg); | 
| 451 |  | } | 
| 452 | < | fread(&fpos, sizeof(long), 1, fp); | 
| 456 | < | if (fpos != 0) | 
| 457 | < | error(WARNING, "ignoring multiple sections in holodeck file"); | 
| 458 | < | fpos = ftell(fp);                       /* get stdio position */ | 
| 452 | > | nextloc = ftell(fp);                    /* get stdio position */ | 
| 453 |  | fd = dup(fileno(fp)); | 
| 454 |  | fclose(fp);                             /* done with stdio */ | 
| 455 | < | lseek(fd, fpos, 0);                     /* align system file pointer */ | 
| 456 | < | hdinit(fd, NULL);                       /* allocate and load index */ | 
| 455 | > | for (n = 0; nextloc > 0L; n++) {        /* initialize each section */ | 
| 456 | > | lseek(fd, (long)nextloc, 0); | 
| 457 | > | read(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 458 | > | hdinit(fd, NULL); | 
| 459 | > | } | 
| 460 | > | if (n != vdef(SECTION)) { | 
| 461 | > | sprintf(errmsg, "number of sections does not match %s setting", | 
| 462 | > | vnam(SECTION)); | 
| 463 | > | error(WARNING, errmsg); | 
| 464 | > | } | 
| 465 |  | } | 
| 466 |  |  | 
| 467 |  |  | 
| 550 |  | { | 
| 551 |  | int     status = 0; | 
| 552 |  |  | 
| 553 | < | if (hdlist[0] != NULL) {        /* flush holodeck */ | 
| 553 | > | if (hdlist[0] != NULL) {        /* close holodeck */ | 
| 554 |  | if (nprocs > 0) | 
| 555 | < | status = done_rtrace(); | 
| 554 | < | hdflush(NULL); | 
| 555 | > | status = done_rtrace();         /* calls hdsync() */ | 
| 556 |  | if (ncprocs > 0 && vdef(REPORT)) { | 
| 557 |  | long    fsiz, fuse; | 
| 558 |  | fsiz = hdfilen(hdlist[0]->fd); |