| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 10 |
|
|
| 11 |
|
#include "rholo.h" |
| 12 |
|
#include "random.h" |
| 13 |
– |
#include "paths.h" |
| 13 |
|
#include <signal.h> |
| 14 |
|
#include <sys/types.h> |
| 15 |
|
#include <sys/stat.h> |
| 16 |
|
|
| 17 |
+ |
#ifndef MAXQTIME |
| 18 |
+ |
#define MAXQTIME 5 /* target maximum seconds in queue */ |
| 19 |
+ |
#endif |
| 20 |
|
/* the following must be consistent with rholo.h */ |
| 21 |
|
int NVARS = NRHVARS; /* total number of variables */ |
| 22 |
|
|
| 24 |
|
|
| 25 |
|
char *progname; /* our program name */ |
| 26 |
|
char *hdkfile; /* holodeck file name */ |
| 27 |
< |
char froot[MAXPATH]; /* root file name */ |
| 27 |
> |
char froot[256]; /* root file name */ |
| 28 |
|
|
| 29 |
|
int nowarn = 0; /* turn warnings off? */ |
| 30 |
|
|
| 29 |
– |
double expval = 1.; /* global exposure value */ |
| 30 |
– |
|
| 31 |
|
int ncprocs = 0; /* desired number of compute processes */ |
| 32 |
|
|
| 33 |
|
char *outdev = NULL; /* output device name */ |
| 34 |
|
|
| 35 |
+ |
int readinp = 0; /* read commands from stdin */ |
| 36 |
+ |
|
| 37 |
+ |
int force = 0; /* allow overwrite of holodeck */ |
| 38 |
+ |
|
| 39 |
|
time_t starttime; /* time we got started */ |
| 40 |
|
time_t endtime; /* time we should end by */ |
| 41 |
|
time_t reporttime; /* time for next report */ |
| 51 |
|
long npacksdone = 0L; /* number of packets done */ |
| 52 |
|
|
| 53 |
|
PACKET *freepacks; /* available packets */ |
| 54 |
+ |
int avgqlen; /* average queue length when full */ |
| 55 |
|
|
| 56 |
|
char *sigerr[NSIG]; /* signal error messages */ |
| 57 |
|
|
| 62 |
|
int argc; |
| 63 |
|
char *argv[]; |
| 64 |
|
{ |
| 60 |
– |
HDGRID hdg; |
| 65 |
|
int i; |
| 66 |
< |
int force = 0; |
| 67 |
< |
/* mark start time */ |
| 64 |
< |
starttime = time(NULL); |
| 65 |
< |
initurand(10240); /* initialize urand */ |
| 66 |
> |
|
| 67 |
> |
initurand(16384); /* initialize urand */ |
| 68 |
|
progname = argv[0]; /* get arguments */ |
| 69 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 70 |
|
switch (argv[i][1]) { |
| 74 |
|
case 'f': /* force overwrite */ |
| 75 |
|
force++; |
| 76 |
|
break; |
| 77 |
+ |
case 'i': /* read input from stdin */ |
| 78 |
+ |
readinp++; |
| 79 |
+ |
break; |
| 80 |
|
case 'n': /* compute processes */ |
| 81 |
|
if (i >= argc-2) |
| 82 |
|
goto userr; |
| 90 |
|
default: |
| 91 |
|
goto userr; |
| 92 |
|
} |
| 88 |
– |
/* do we have a job? */ |
| 89 |
– |
if (outdev == NULL && ncprocs <= 0) |
| 90 |
– |
goto userr; |
| 93 |
|
/* get root file name */ |
| 94 |
+ |
if (i >= argc) |
| 95 |
+ |
goto userr; |
| 96 |
|
rootname(froot, hdkfile=argv[i++]); |
| 97 |
< |
/* load... */ |
| 98 |
< |
if (i < argc) { /* variables */ |
| 99 |
< |
loadvars(argv[i++]); |
| 100 |
< |
/* cmdline settings */ |
| 101 |
< |
for ( ; i < argc; i++) |
| 102 |
< |
if (setvariable(argv[i], matchvar) < 0) { |
| 103 |
< |
sprintf(errmsg, "unknown variable: %s", |
| 104 |
< |
argv[i]); |
| 105 |
< |
error(USER, errmsg); |
| 106 |
< |
} |
| 107 |
< |
/* check settings */ |
| 108 |
< |
checkvalues(); |
| 109 |
< |
/* load RIF if any */ |
| 110 |
< |
if (vdef(RIF)) |
| 111 |
< |
getradfile(vval(RIF)); |
| 97 |
> |
/* load variables? */ |
| 98 |
> |
if (i < argc) |
| 99 |
> |
if (argv[i][0] != '-' && argv[i][0] != '+') |
| 100 |
> |
loadvars(argv[i]); /* load variables from file */ |
| 101 |
> |
|
| 102 |
> |
if (i >= argc || argv[i][0] == '+') |
| 103 |
> |
loadholo(); /* load existing holodeck */ |
| 104 |
> |
|
| 105 |
> |
while (++i < argc) /* get command line settings */ |
| 106 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
| 107 |
> |
sprintf(errmsg, "unknown variable: %s", argv[i]); |
| 108 |
> |
error(USER, errmsg); |
| 109 |
> |
} |
| 110 |
> |
/* check settings */ |
| 111 |
> |
checkvalues(); |
| 112 |
> |
/* load rad input file */ |
| 113 |
> |
getradfile(); |
| 114 |
> |
|
| 115 |
> |
if (hdlist[0] == NULL) { /* create new holodeck */ |
| 116 |
> |
HDGRID hdg[HDMAX]; |
| 117 |
|
/* set defaults */ |
| 118 |
< |
setdefaults(&hdg); |
| 118 |
> |
setdefaults(hdg); |
| 119 |
|
/* holodeck exists? */ |
| 120 |
|
if (!force && access(hdkfile, R_OK|W_OK) == 0) |
| 121 |
|
error(USER, |
| 122 |
|
"holodeck file exists -- use -f to overwrite"); |
| 123 |
|
/* create holodeck */ |
| 124 |
< |
creatholo(&hdg); |
| 125 |
< |
} else { /* else load holodeck */ |
| 126 |
< |
loadholo(); |
| 118 |
< |
if (vdef(RIF)) /* load RIF if any */ |
| 119 |
< |
getradfile(vval(RIF)); |
| 120 |
< |
} |
| 124 |
> |
creatholo(hdg); |
| 125 |
> |
} else /* else just set defaults */ |
| 126 |
> |
setdefaults(NULL); |
| 127 |
|
/* initialize */ |
| 128 |
|
initrholo(); |
| 129 |
< |
/* run */ |
| 129 |
> |
/* main loop */ |
| 130 |
|
while (rholo()) |
| 131 |
|
; |
| 132 |
|
/* done */ |
| 133 |
|
quit(0); |
| 134 |
|
userr: |
| 135 |
|
fprintf(stderr, |
| 136 |
< |
"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
| 136 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
| 137 |
|
progname); |
| 138 |
|
quit(1); |
| 139 |
|
} |
| 147 |
|
if (gotsig++) /* two signals and we're gone! */ |
| 148 |
|
_exit(signo); |
| 149 |
|
|
| 150 |
< |
alarm(30); /* allow 30 seconds to clean up */ |
| 150 |
> |
alarm(60); /* allow 60 seconds to clean up */ |
| 151 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 152 |
|
eputs("signal - "); |
| 153 |
|
eputs(sigerr[signo]); |
| 175 |
|
if (fstat(fd, &stbuf) < 0) |
| 176 |
|
error(SYSTEM, "cannot stat open holodeck file"); |
| 177 |
|
mod &= stbuf.st_mode; /* always more restrictive */ |
| 178 |
< |
if (mod == stbuf.st_mode) |
| 178 |
> |
if (mod == (stbuf.st_mode & 0777)) |
| 179 |
|
return(-1); /* already set */ |
| 180 |
|
/* else change it */ |
| 181 |
|
if (fchmod(fd, mod) < 0) { |
| 190 |
|
{ |
| 191 |
|
extern int global_packet(); |
| 192 |
|
register int i; |
| 193 |
+ |
/* close holodeck on exec() */ |
| 194 |
+ |
fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); |
| 195 |
|
|
| 196 |
|
if (outdev != NULL) /* open output device */ |
| 197 |
|
disp_open(outdev); |
| 202 |
|
maxdisk = 0; |
| 203 |
|
else |
| 204 |
|
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
| 197 |
– |
/* record end time */ |
| 198 |
– |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
| 199 |
– |
endtime = 0; |
| 200 |
– |
else |
| 201 |
– |
endtime = starttime + vflt(TIME)*3600.; |
| 205 |
|
/* set up memory cache */ |
| 206 |
|
if (outdev == NULL) |
| 207 |
|
hdcachesize = 0; /* manual flushing */ |
| 213 |
|
if (*s && freopen(s, "a", stderr) == NULL) |
| 214 |
|
quit(2); |
| 215 |
|
} |
| 216 |
+ |
/* mark the starting time */ |
| 217 |
+ |
starttime = time(NULL); |
| 218 |
+ |
/* compute end time */ |
| 219 |
+ |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
| 220 |
+ |
endtime = 0; |
| 221 |
+ |
else |
| 222 |
+ |
endtime = starttime + vflt(TIME)*3600. + .5; |
| 223 |
|
/* start rtrace */ |
| 224 |
|
if (ncprocs > 0) { |
| 225 |
|
i = start_rtrace(); |
| 226 |
|
if (i < 1) |
| 227 |
< |
error(USER, "cannot start rtrace process"); |
| 227 |
> |
error(USER, "cannot start rtrace process(es)"); |
| 228 |
|
if (vdef(REPORT)) { /* make first report */ |
| 229 |
|
printargs(rtargc, rtargv, stderr); |
| 230 |
|
report(0); |
| 233 |
|
freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); |
| 234 |
|
if (freepacks == NULL) |
| 235 |
|
goto memerr; |
| 236 |
+ |
if (!(avgqlen = i/nprocs)) /* record mean queue length */ |
| 237 |
+ |
avgqlen = 1; |
| 238 |
|
freepacks[--i].nr = 0; |
| 239 |
|
freepacks[i].next = NULL; |
| 240 |
< |
if (!vbool(OBSTRUCTIONS)) { |
| 240 |
> |
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
| 241 |
|
freepacks[i].offset = (float *)bmalloc( |
| 242 |
|
RPACKSIZ*sizeof(float)*(i+1) ); |
| 243 |
|
if (freepacks[i].offset == NULL) |
| 271 |
|
|
| 272 |
|
rholo() /* holodeck main loop */ |
| 273 |
|
{ |
| 274 |
< |
static int idle = 1; |
| 274 |
> |
static int idle = 0; |
| 275 |
|
PACKET *pl = NULL, *plend; |
| 276 |
+ |
int pksiz; |
| 277 |
|
register PACKET *p; |
| 278 |
|
time_t t; |
| 279 |
< |
long l; |
| 280 |
< |
|
| 281 |
< |
if (outdev != NULL) /* check display */ |
| 279 |
> |
/* check display */ |
| 280 |
> |
if (nprocs <= 0) |
| 281 |
> |
idle = 1; |
| 282 |
> |
if (outdev != NULL) { |
| 283 |
|
if (!disp_check(idle)) |
| 284 |
< |
return(0); |
| 285 |
< |
/* display only? */ |
| 286 |
< |
if (ncprocs <= 0) |
| 287 |
< |
return(1); |
| 284 |
> |
return(0); /* quit request */ |
| 285 |
> |
if (nprocs <= 0) |
| 286 |
> |
return(1); |
| 287 |
> |
} else if (idle) |
| 288 |
> |
return(0); /* all done */ |
| 289 |
|
/* check file size */ |
| 290 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
| 291 |
|
error(WARNING, "file limit exceeded"); |
| 292 |
< |
return(0); |
| 292 |
> |
done_rtrace(); |
| 293 |
> |
return(1); /* comes back */ |
| 294 |
|
} |
| 295 |
< |
/* check time */ |
| 280 |
< |
if (endtime > 0 || reporttime > 0) |
| 281 |
< |
t = time(NULL); |
| 295 |
> |
t = time(NULL); /* check time */ |
| 296 |
|
if (endtime > 0 && t >= endtime) { |
| 297 |
|
error(WARNING, "time limit exceeded"); |
| 298 |
< |
return(0); |
| 298 |
> |
done_rtrace(); |
| 299 |
> |
return(1); /* comes back */ |
| 300 |
|
} |
| 301 |
|
if (reporttime > 0 && t >= reporttime) |
| 302 |
|
report(t); |
| 303 |
< |
/* get packets to process */ |
| 303 |
> |
/* figure out good packet size */ |
| 304 |
> |
#if MAXQTIME |
| 305 |
> |
pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); |
| 306 |
> |
if (pksiz < 1) |
| 307 |
> |
pksiz = 1; |
| 308 |
> |
else if (pksiz > RPACKSIZ) |
| 309 |
> |
#endif |
| 310 |
> |
pksiz = RPACKSIZ; |
| 311 |
> |
idle = 0; /* get packets to process */ |
| 312 |
|
while (freepacks != NULL) { |
| 313 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
| 314 |
< |
if (!next_packet(p)) { |
| 314 |
> |
if (!next_packet(p, pksiz)) { |
| 315 |
|
p->next = freepacks; freepacks = p; |
| 316 |
+ |
idle = 1; |
| 317 |
|
break; |
| 318 |
|
} |
| 319 |
|
if (pl == NULL) pl = p; |
| 320 |
|
else plend->next = p; |
| 321 |
|
plend = p; |
| 322 |
|
} |
| 323 |
< |
idle = pl == NULL && freepacks != NULL; |
| 300 |
< |
/* are we out of stuff to do? */ |
| 301 |
< |
if (idle && outdev == NULL) |
| 302 |
< |
return(0); |
| 303 |
< |
/* else process packets */ |
| 323 |
> |
/* process packets */ |
| 324 |
|
done_packets(do_packets(pl)); |
| 325 |
|
return(1); /* and continue */ |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
|
| 309 |
– |
report(t) /* report progress so far */ |
| 310 |
– |
time_t t; |
| 311 |
– |
{ |
| 312 |
– |
if (t == 0) |
| 313 |
– |
t = time(NULL); |
| 314 |
– |
fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", |
| 315 |
– |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
| 316 |
– |
fflush(stderr); |
| 317 |
– |
if (vdef(REPORT)) |
| 318 |
– |
reporttime = t + (time_t)(vflt(REPORT)*60.+.5); |
| 319 |
– |
} |
| 320 |
– |
|
| 321 |
– |
|
| 329 |
|
setdefaults(gp) /* set default values */ |
| 330 |
|
register HDGRID *gp; |
| 331 |
|
{ |
| 332 |
|
extern char *atos(); |
| 333 |
|
register int i; |
| 334 |
< |
double len[3], maxlen, d; |
| 334 |
> |
int n; |
| 335 |
> |
double len[3], d; |
| 336 |
|
char buf[64]; |
| 337 |
|
|
| 338 |
|
if (!vdef(SECTION)) { |
| 339 |
|
sprintf(errmsg, "%s must be defined", vnam(SECTION)); |
| 340 |
|
error(USER, errmsg); |
| 341 |
|
} |
| 334 |
– |
if (vdef(SECTION) > 1) { |
| 335 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
| 336 |
– |
error(WARNING, errmsg); |
| 337 |
– |
} |
| 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); |
| 342 |
|
if (!vdef(OCTREE)) { |
| 343 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
| 344 |
|
error(SYSTEM, "out of memory"); |
| 345 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
| 346 |
|
vdef(OCTREE)++; |
| 347 |
|
} |
| 370 |
– |
if (!vdef(OBSTRUCTIONS)) { |
| 371 |
– |
vval(OBSTRUCTIONS) = "T"; |
| 372 |
– |
vdef(OBSTRUCTIONS)++; |
| 373 |
– |
} |
| 348 |
|
if (!vdef(VDIST)) { |
| 349 |
|
vval(VDIST) = "F"; |
| 350 |
|
vdef(VDIST)++; |
| 351 |
|
} |
| 378 |
– |
if (!vdef(OCCUPANCY)) { |
| 379 |
– |
vval(OCCUPANCY) = "U"; |
| 380 |
– |
vdef(OCCUPANCY)++; |
| 381 |
– |
} |
| 352 |
|
/* append rendering options */ |
| 353 |
|
if (vdef(RENDER)) |
| 354 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
| 355 |
+ |
|
| 356 |
+ |
if (gp == NULL) /* already initialized? */ |
| 357 |
+ |
return; |
| 358 |
+ |
/* set grid parameters */ |
| 359 |
+ |
for (n = 0; n < vdef(SECTION); n++, gp++) { |
| 360 |
+ |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
| 361 |
+ |
if (sscanf(nvalue(SECTION, n), |
| 362 |
+ |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
| 363 |
+ |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
| 364 |
+ |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
| 365 |
+ |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
| 366 |
+ |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
| 367 |
+ |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
| 368 |
+ |
badvalue(SECTION); |
| 369 |
+ |
for (i = 0; i < 3; i++) |
| 370 |
+ |
len[i] = VLEN(gp->xv[i]); |
| 371 |
+ |
if (!vdef(GRID)) { |
| 372 |
+ |
d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] + |
| 373 |
+ |
len[2]*len[2] + 4*len[1]*len[2]) |
| 374 |
+ |
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
| 375 |
+ |
+ 4*len[0]*len[1]*len[2]*len[2] ); |
| 376 |
+ |
d = sqrt(sqrt(d)); |
| 377 |
+ |
} else 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); |
| 382 |
+ |
} |
| 383 |
|
} |
| 384 |
|
|
| 385 |
|
|
| 387 |
|
HDGRID *gp; |
| 388 |
|
{ |
| 389 |
|
extern char VersionID[]; |
| 390 |
< |
long endloc = 0; |
| 390 |
> |
int4 lastloc, nextloc; |
| 391 |
> |
int n; |
| 392 |
|
int fd; |
| 393 |
|
FILE *fp; |
| 394 |
|
/* open & truncate file */ |
| 402 |
|
printvars(fp); |
| 403 |
|
fputformat(HOLOFMT, fp); |
| 404 |
|
fputc('\n', fp); |
| 405 |
< |
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
| 407 |
< |
fwrite(&endloc, sizeof(long), 1, fp); |
| 405 |
> |
putw(HOLOMAGIC, fp); /* put magic number */ |
| 406 |
|
fd = dup(fileno(fp)); |
| 407 |
|
fclose(fp); /* flush and close stdio stream */ |
| 408 |
< |
hdinit(fd, gp); /* allocate and initialize index */ |
| 408 |
> |
lastloc = lseek(fd, 0L, 2); |
| 409 |
> |
for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ |
| 410 |
> |
nextloc = 0L; |
| 411 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
| 412 |
> |
hdinit(fd, gp); /* writes beam index */ |
| 413 |
> |
if (!n) |
| 414 |
> |
break; |
| 415 |
> |
nextloc = hdfilen(fd); /* write section pointer */ |
| 416 |
> |
if (lseek(fd, (long)lastloc, 0) < 0) |
| 417 |
> |
error(SYSTEM, |
| 418 |
> |
"cannot seek on holodeck file in creatholo"); |
| 419 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
| 420 |
> |
lseek(fd, (long)(lastloc=nextloc), 0); |
| 421 |
> |
} |
| 422 |
|
} |
| 423 |
|
|
| 424 |
|
|
| 451 |
|
extern long ftell(); |
| 452 |
|
FILE *fp; |
| 453 |
|
int fd; |
| 454 |
< |
long fpos; |
| 454 |
> |
int n; |
| 455 |
> |
int4 nextloc; |
| 456 |
|
/* open holodeck file */ |
| 457 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
| 458 |
|
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
| 467 |
|
hdkfile); |
| 468 |
|
error(USER, errmsg); |
| 469 |
|
} |
| 470 |
< |
fread(&fpos, sizeof(long), 1, fp); |
| 459 |
< |
if (fpos != 0) |
| 460 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
| 461 |
< |
fpos = ftell(fp); /* get stdio position */ |
| 470 |
> |
nextloc = ftell(fp); /* get stdio position */ |
| 471 |
|
fd = dup(fileno(fp)); |
| 472 |
|
fclose(fp); /* done with stdio */ |
| 473 |
< |
lseek(fd, fpos, 0); /* align system file pointer */ |
| 474 |
< |
hdinit(fd, NULL); /* allocate and load index */ |
| 473 |
> |
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 474 |
> |
lseek(fd, (long)nextloc, 0); |
| 475 |
> |
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 476 |
> |
hdinit(fd, NULL); |
| 477 |
> |
} |
| 478 |
> |
if (n != vdef(SECTION)) { |
| 479 |
> |
sprintf(errmsg, "number of sections does not match %s setting", |
| 480 |
> |
vnam(SECTION)); |
| 481 |
> |
error(WARNING, errmsg); |
| 482 |
> |
} |
| 483 |
|
} |
| 484 |
|
|
| 485 |
|
|
| 498 |
|
if (outdev != NULL) /* display it */ |
| 499 |
|
disp_packet((PACKHEAD *)p); |
| 500 |
|
if (hdcachesize <= 0) /* manual flushing */ |
| 501 |
< |
n2flush += p->nr; |
| 501 |
> |
n2flush++; |
| 502 |
|
nraysdone += p->nr; |
| 503 |
|
npacksdone++; |
| 504 |
+ |
p->nr = 0; |
| 505 |
|
} |
| 506 |
< |
p->nr = 0; /* push onto free list */ |
| 489 |
< |
p->next = freepacks; |
| 506 |
> |
p->next = freepacks; /* push onto free list */ |
| 507 |
|
freepacks = p; |
| 508 |
|
} |
| 509 |
< |
if (n2flush > 512*RPACKSIZ*ncprocs) { |
| 509 |
> |
if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { |
| 510 |
|
hdflush(NULL); /* flush holodeck buffers */ |
| 511 |
|
n2flush = 0; |
| 512 |
|
} |
| 513 |
|
} |
| 514 |
|
|
| 515 |
|
|
| 499 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
| 500 |
– |
char *rfargs; |
| 501 |
– |
{ |
| 502 |
– |
static short mvar[] = {OCTREE,EXPOSURE,-1}; |
| 503 |
– |
static char tf1[] = TEMPLATE; |
| 504 |
– |
char tf2[64]; |
| 505 |
– |
char combuf[256]; |
| 506 |
– |
char *pippt; |
| 507 |
– |
register int i; |
| 508 |
– |
register char *cp; |
| 509 |
– |
/* create rad command */ |
| 510 |
– |
mktemp(tf1); |
| 511 |
– |
sprintf(tf2, "%s.rif", tf1); |
| 512 |
– |
sprintf(combuf, |
| 513 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
| 514 |
– |
rfargs, tf1); |
| 515 |
– |
cp = combuf; |
| 516 |
– |
while (*cp){ |
| 517 |
– |
if (*cp == '|') pippt = cp; |
| 518 |
– |
cp++; |
| 519 |
– |
} /* match unset variables */ |
| 520 |
– |
for (i = 0; mvar[i] >= 0; i++) |
| 521 |
– |
if (!vdef(mvar[i])) { |
| 522 |
– |
*cp++ = '|'; |
| 523 |
– |
strcpy(cp, vnam(mvar[i])); |
| 524 |
– |
while (*cp) cp++; |
| 525 |
– |
pippt = NULL; |
| 526 |
– |
} |
| 527 |
– |
if (pippt != NULL) |
| 528 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
| 529 |
– |
else |
| 530 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
| 531 |
– |
if (system(combuf)) { |
| 532 |
– |
error(SYSTEM, "cannot execute rad command"); |
| 533 |
– |
unlink(tf2); /* clean up */ |
| 534 |
– |
unlink(tf1); |
| 535 |
– |
quit(1); |
| 536 |
– |
} |
| 537 |
– |
if (pippt == NULL) { |
| 538 |
– |
loadvars(tf2); /* load variables */ |
| 539 |
– |
unlink(tf2); |
| 540 |
– |
} |
| 541 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
| 542 |
– |
unlink(tf1); /* clean up */ |
| 543 |
– |
} |
| 544 |
– |
|
| 545 |
– |
|
| 516 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
| 517 |
|
register char *rn, *fn; |
| 518 |
|
{ |
| 519 |
|
char *tp, *dp; |
| 520 |
|
|
| 521 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
| 522 |
< |
if (ISDIRSEP(*rn)) |
| 522 |
> |
if (*rn == '/') |
| 523 |
|
dp = rn; |
| 524 |
|
else if (*rn == '.') |
| 525 |
|
tp = rn; |
| 568 |
|
{ |
| 569 |
|
int status = 0; |
| 570 |
|
|
| 571 |
< |
if (hdlist[0] != NULL) { /* flush holodeck */ |
| 572 |
< |
if (ncprocs > 0) { |
| 573 |
< |
done_packets(flush_queue()); |
| 574 |
< |
status = end_rtrace(); /* close rtrace */ |
| 575 |
< |
hdflush(NULL); |
| 576 |
< |
if (vdef(REPORT)) { |
| 577 |
< |
long fsiz, fuse; |
| 578 |
< |
report(0); |
| 609 |
< |
fsiz = hdfilen(hdlist[0]->fd); |
| 610 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
| 611 |
< |
fprintf(stderr, |
| 571 |
> |
if (hdlist[0] != NULL) { /* close holodeck */ |
| 572 |
> |
if (nprocs > 0) |
| 573 |
> |
status = done_rtrace(); /* calls hdsync() */ |
| 574 |
> |
if (ncprocs > 0 && vdef(REPORT)) { |
| 575 |
> |
long fsiz, fuse; |
| 576 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
| 577 |
> |
fuse = hdfiluse(hdlist[0]->fd, 1); |
| 578 |
> |
fprintf(stderr, |
| 579 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
| 580 |
< |
hdkfile, fsiz/(1024.*1024.), |
| 581 |
< |
100.*(fsiz-fuse)/fsiz); |
| 582 |
< |
} |
| 616 |
< |
} else |
| 617 |
< |
hdflush(NULL); |
| 580 |
> |
hdkfile, fsiz/(1024.*1024.), |
| 581 |
> |
100.*(fsiz-fuse)/fsiz); |
| 582 |
> |
} |
| 583 |
|
} |
| 584 |
|
if (orig_mode >= 0) /* reset holodeck access mode */ |
| 585 |
|
fchmod(hdlist[0]->fd, orig_mode); |