58 |
|
int argc; |
59 |
|
char *argv[]; |
60 |
|
{ |
61 |
– |
HDGRID hdg; |
61 |
|
int i; |
62 |
|
/* mark start time */ |
63 |
|
starttime = time(NULL); |
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); |
119 |
> |
creatholo(hdg); |
120 |
|
} else /* else just set defaults */ |
121 |
|
setdefaults(NULL); |
122 |
|
/* initialize */ |
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 |
|
} |
325 |
– |
if (vdef(SECTION) > 1) { |
326 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
327 |
– |
error(WARNING, errmsg); |
328 |
– |
} |
326 |
|
if (!vdef(OCTREE)) { |
327 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
328 |
|
error(SYSTEM, "out of memory"); |
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 |
|
} |
364 |
– |
if ((d = vflt(GRID)) <= FTINY) |
365 |
– |
badvalue(GRID); |
366 |
– |
for (i = 0; i < 3; i++) |
367 |
– |
if (gp->grid[i] <= 0) |
368 |
– |
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 */ |
391 |
< |
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); |
443 |
< |
if (fpos != 0) |
444 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
445 |
< |
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 |
|
|