58 |
|
int argc; |
59 |
|
char *argv[]; |
60 |
|
{ |
61 |
– |
HDGRID hdg; |
61 |
|
int i; |
62 |
|
/* mark start time */ |
63 |
|
starttime = time(NULL); |
89 |
|
} |
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 */ |
116 |
< |
loadholo(); |
117 |
< |
/* check settings */ |
118 |
< |
checkvalues(); |
119 |
< |
/* load RIF if any */ |
120 |
< |
getradfile(); |
121 |
< |
/* set defaults */ |
119 |
> |
creatholo(hdg); |
120 |
> |
} else /* else just set defaults */ |
121 |
|
setdefaults(NULL); |
123 |
– |
} |
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]); |
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(); |
283 |
– |
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(); |
292 |
– |
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 |
|
} |
327 |
– |
if (vdef(SECTION) > 1) { |
328 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
329 |
– |
error(WARNING, errmsg); |
330 |
– |
} |
326 |
|
if (!vdef(OCTREE)) { |
327 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
328 |
|
error(SYSTEM, "out of memory"); |
333 |
|
vval(VDIST) = "F"; |
334 |
|
vdef(VDIST)++; |
335 |
|
} |
341 |
– |
if (!vdef(OCCUPANCY)) { |
342 |
– |
vval(OCCUPANCY) = "U"; |
343 |
– |
vdef(OCCUPANCY)++; |
344 |
– |
} |
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 |
|
} |
370 |
– |
if ((d = vflt(GRID)) <= FTINY) |
371 |
– |
badvalue(GRID); |
372 |
– |
for (i = 0; i < 3; i++) |
373 |
– |
if (gp->grid[i] <= 0) |
374 |
– |
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 */ |
397 |
< |
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); |
449 |
< |
if (fpos != 0) |
450 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
451 |
< |
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 |
|
|