1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1999 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> |
15 |
– |
#include <sys/types.h> |
14 |
|
#include <sys/stat.h> |
15 |
|
|
16 |
+ |
#ifndef FRAGWARN |
17 |
+ |
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
18 |
+ |
#endif |
19 |
+ |
#ifndef MAXQTIME |
20 |
+ |
#define MAXQTIME 5 /* target maximum seconds in queue */ |
21 |
+ |
#endif |
22 |
+ |
/* manual cache flushing frequency */ |
23 |
+ |
#ifndef RTFLUSH |
24 |
+ |
#if MAXQTIME |
25 |
+ |
#define RTFLUSH (300/MAXQTIME*totqlen) /* <= 5 minutes */ |
26 |
+ |
#else |
27 |
+ |
#define RTFLUSH (50*totqlen) /* just guess */ |
28 |
+ |
#endif |
29 |
+ |
#endif |
30 |
|
/* the following must be consistent with rholo.h */ |
31 |
|
int NVARS = NRHVARS; /* total number of variables */ |
32 |
|
|
34 |
|
|
35 |
|
char *progname; /* our program name */ |
36 |
|
char *hdkfile; /* holodeck file name */ |
37 |
< |
char froot[MAXPATH]; /* root file name */ |
37 |
> |
char froot[256]; /* root file name */ |
38 |
|
|
27 |
– |
int nowarn = 0; /* turn warnings off? */ |
28 |
– |
|
39 |
|
int ncprocs = 0; /* desired number of compute processes */ |
40 |
|
|
41 |
|
char *outdev = NULL; /* output device name */ |
59 |
|
long npacksdone = 0L; /* number of packets done */ |
60 |
|
|
61 |
|
PACKET *freepacks; /* available packets */ |
62 |
+ |
int totqlen; /* maximum queue length (number of packets) */ |
63 |
|
|
64 |
|
char *sigerr[NSIG]; /* signal error messages */ |
65 |
|
|
66 |
+ |
extern int nowarn; /* turn warnings off? */ |
67 |
+ |
|
68 |
|
extern time_t time(); |
69 |
|
|
70 |
|
|
72 |
|
int argc; |
73 |
|
char *argv[]; |
74 |
|
{ |
62 |
– |
HDGRID hdg; |
75 |
|
int i; |
76 |
< |
/* mark start time */ |
65 |
< |
starttime = time(NULL); |
76 |
> |
|
77 |
|
initurand(16384); /* initialize urand */ |
78 |
|
progname = argv[0]; /* get arguments */ |
79 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
100 |
|
default: |
101 |
|
goto userr; |
102 |
|
} |
92 |
– |
/* do we have a job? */ |
93 |
– |
if (outdev == NULL && ncprocs <= 0) |
94 |
– |
goto userr; |
103 |
|
/* get root file name */ |
104 |
+ |
if (i >= argc) |
105 |
+ |
goto userr; |
106 |
|
rootname(froot, hdkfile=argv[i++]); |
107 |
< |
/* load... */ |
108 |
< |
if (i < argc) { /* variables */ |
109 |
< |
loadvars(argv[i++]); |
110 |
< |
/* cmdline settings */ |
111 |
< |
for ( ; i < argc; i++) |
112 |
< |
if (setvariable(argv[i], matchvar) < 0) { |
113 |
< |
sprintf(errmsg, "unknown variable: %s", |
114 |
< |
argv[i]); |
115 |
< |
error(USER, errmsg); |
116 |
< |
} |
117 |
< |
/* check settings */ |
118 |
< |
checkvalues(); |
119 |
< |
/* load RIF if any */ |
120 |
< |
if (vdef(RIF)) |
121 |
< |
getradfile(vval(RIF)); |
107 |
> |
/* load variables? */ |
108 |
> |
if (i < argc) |
109 |
> |
if (argv[i][0] != '-' && argv[i][0] != '+') |
110 |
> |
loadvars(argv[i]); /* load variables from file */ |
111 |
> |
|
112 |
> |
if (i >= argc || argv[i][0] == '+') |
113 |
> |
loadholo(); /* load existing holodeck */ |
114 |
> |
|
115 |
> |
while (++i < argc) /* get command line settings */ |
116 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
117 |
> |
sprintf(errmsg, "unknown variable: %s", argv[i]); |
118 |
> |
error(USER, errmsg); |
119 |
> |
} |
120 |
> |
/* check settings */ |
121 |
> |
checkvalues(); |
122 |
> |
/* load rad input file */ |
123 |
> |
getradfile(); |
124 |
> |
|
125 |
> |
if (hdlist[0] == NULL) { /* create new holodeck */ |
126 |
> |
HDGRID hdg[HDMAX]; |
127 |
|
/* set defaults */ |
128 |
< |
setdefaults(&hdg); |
128 |
> |
setdefaults(hdg); |
129 |
|
/* holodeck exists? */ |
130 |
|
if (!force && access(hdkfile, R_OK|W_OK) == 0) |
131 |
|
error(USER, |
132 |
|
"holodeck file exists -- use -f to overwrite"); |
133 |
|
/* create holodeck */ |
134 |
< |
creatholo(&hdg); |
135 |
< |
} else { /* else load holodeck */ |
121 |
< |
loadholo(); |
122 |
< |
/* check settings */ |
123 |
< |
checkvalues(); |
124 |
< |
/* load RIF if any */ |
125 |
< |
if (vdef(RIF)) |
126 |
< |
getradfile(vval(RIF)); |
127 |
< |
/* set defaults */ |
134 |
> |
creatholo(hdg); |
135 |
> |
} else /* else just set defaults */ |
136 |
|
setdefaults(NULL); |
129 |
– |
} |
137 |
|
/* initialize */ |
138 |
|
initrholo(); |
139 |
|
/* main loop */ |
143 |
|
quit(0); |
144 |
|
userr: |
145 |
|
fprintf(stderr, |
146 |
< |
"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
146 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
147 |
|
progname); |
148 |
|
quit(1); |
149 |
|
} |
154 |
|
{ |
155 |
|
static int gotsig = 0; |
156 |
|
|
157 |
< |
if (gotsig++) /* two signals and we're gone! */ |
157 |
> |
if (gotsig > 1) /* we're going as fast as we can! */ |
158 |
> |
return; |
159 |
> |
if (gotsig++) { /* two signals and we split */ |
160 |
> |
hdsync(NULL, 0); /* don't leave w/o saying goodbye */ |
161 |
|
_exit(signo); |
162 |
< |
|
163 |
< |
alarm(30); /* allow 30 seconds to clean up */ |
154 |
< |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
162 |
> |
} |
163 |
> |
alarm(300); /* allow 5 minutes to clean up */ |
164 |
|
eputs("signal - "); |
165 |
|
eputs(sigerr[signo]); |
166 |
|
eputs("\n"); |
187 |
|
if (fstat(fd, &stbuf) < 0) |
188 |
|
error(SYSTEM, "cannot stat open holodeck file"); |
189 |
|
mod &= stbuf.st_mode; /* always more restrictive */ |
190 |
< |
if (mod == stbuf.st_mode) |
190 |
> |
if (mod == (stbuf.st_mode & 0777)) |
191 |
|
return(-1); /* already set */ |
192 |
|
/* else change it */ |
193 |
|
if (fchmod(fd, mod) < 0) { |
214 |
|
maxdisk = 0; |
215 |
|
else |
216 |
|
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
208 |
– |
/* record end time */ |
209 |
– |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
210 |
– |
endtime = 0; |
211 |
– |
else |
212 |
– |
endtime = starttime + vflt(TIME)*3600.; |
217 |
|
/* set up memory cache */ |
218 |
|
if (outdev == NULL) |
219 |
< |
hdcachesize = 0; /* manual flushing */ |
219 |
> |
hdcachesize = 0; /* manual flushing */ |
220 |
|
else if (vdef(CACHE)) |
221 |
|
hdcachesize = 1024.*1024.*vflt(CACHE); |
222 |
|
/* open report file */ |
225 |
|
if (*s && freopen(s, "a", stderr) == NULL) |
226 |
|
quit(2); |
227 |
|
} |
228 |
+ |
/* mark the starting time */ |
229 |
+ |
starttime = time(NULL); |
230 |
+ |
/* compute end time */ |
231 |
+ |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
232 |
+ |
endtime = 0; |
233 |
+ |
else |
234 |
+ |
endtime = starttime + vflt(TIME)*3600. + .5; |
235 |
|
/* start rtrace */ |
236 |
|
if (ncprocs > 0) { |
237 |
< |
i = start_rtrace(); |
237 |
> |
totqlen = i = start_rtrace(); |
238 |
|
if (i < 1) |
239 |
|
error(USER, "cannot start rtrace process(es)"); |
240 |
|
if (vdef(REPORT)) { /* make first report */ |
247 |
|
goto memerr; |
248 |
|
freepacks[--i].nr = 0; |
249 |
|
freepacks[i].next = NULL; |
250 |
< |
if (!vbool(OBSTRUCTIONS)) { |
250 |
> |
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
251 |
|
freepacks[i].offset = (float *)bmalloc( |
252 |
|
RPACKSIZ*sizeof(float)*(i+1) ); |
253 |
|
if (freepacks[i].offset == NULL) |
271 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
272 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
273 |
|
#endif |
274 |
< |
/* protect holodeck file */ |
274 |
> |
/* protect holodeck file */ |
275 |
|
orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); |
276 |
|
return; |
277 |
|
memerr: |
281 |
|
|
282 |
|
rholo() /* holodeck main loop */ |
283 |
|
{ |
284 |
< |
static int idle = 1; |
284 |
> |
static long nextfragwarn = 100*(1L<<20); |
285 |
> |
static int idle = 0; |
286 |
|
PACKET *pl = NULL, *plend; |
287 |
+ |
long fsiz; |
288 |
+ |
int pksiz; |
289 |
|
register PACKET *p; |
290 |
|
time_t t; |
291 |
< |
long l; |
278 |
< |
|
279 |
< |
if (outdev != NULL) /* check display */ |
280 |
< |
if (!disp_check(idle)) |
281 |
< |
return(0); |
282 |
< |
/* display only? */ |
291 |
> |
/* check display */ |
292 |
|
if (nprocs <= 0) |
293 |
< |
return(outdev != NULL); |
294 |
< |
/* check file size */ |
295 |
< |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
293 |
> |
idle = 1; |
294 |
> |
if (outdev != NULL) { |
295 |
> |
if (!disp_check(idle)) |
296 |
> |
return(0); /* quit request */ |
297 |
> |
if (nprocs <= 0) |
298 |
> |
return(1); |
299 |
> |
} else if (idle) |
300 |
> |
return(0); /* all done */ |
301 |
> |
fsiz = hdfilen(hdlist[0]->fd); /* check file size */ |
302 |
> |
if (maxdisk > 0 && fsiz >= maxdisk) { |
303 |
|
error(WARNING, "file limit exceeded"); |
304 |
|
done_rtrace(); |
289 |
– |
idle = 1; |
305 |
|
return(1); /* comes back */ |
306 |
|
} |
307 |
< |
/* check time */ |
308 |
< |
if (endtime > 0 || reporttime > 0) |
309 |
< |
t = time(NULL); |
307 |
> |
#if FRAGWARN |
308 |
> |
if (fsiz >= nextfragwarn && |
309 |
> |
(fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { |
310 |
> |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
311 |
> |
100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); |
312 |
> |
error(WARNING, errmsg); |
313 |
> |
nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ |
314 |
> |
} |
315 |
> |
#endif |
316 |
> |
t = time(NULL); /* check time */ |
317 |
|
if (endtime > 0 && t >= endtime) { |
318 |
|
error(WARNING, "time limit exceeded"); |
319 |
|
done_rtrace(); |
298 |
– |
idle = 1; |
320 |
|
return(1); /* comes back */ |
321 |
|
} |
322 |
|
if (reporttime > 0 && t >= reporttime) |
323 |
|
report(t); |
324 |
< |
/* get packets to process */ |
324 |
> |
/* figure out good packet size */ |
325 |
> |
pksiz = RPACKSIZ; |
326 |
> |
#if MAXQTIME |
327 |
> |
if (!chunkycmp) { |
328 |
> |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
329 |
> |
if (pksiz < 1) pksiz = 1; |
330 |
> |
else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ; |
331 |
> |
} |
332 |
> |
#endif |
333 |
> |
idle = 0; /* get packets to process */ |
334 |
|
while (freepacks != NULL) { |
335 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
336 |
< |
if (!next_packet(p)) { |
336 |
> |
if (!next_packet(p, pksiz)) { |
337 |
|
p->next = freepacks; freepacks = p; |
338 |
|
idle = 1; |
339 |
|
break; |
348 |
|
} |
349 |
|
|
350 |
|
|
321 |
– |
report(t) /* report progress so far */ |
322 |
– |
time_t t; |
323 |
– |
{ |
324 |
– |
static time_t seconds2go = 1000000; |
325 |
– |
|
326 |
– |
if (t == 0L) |
327 |
– |
t = time(NULL); |
328 |
– |
sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n", |
329 |
– |
npacksdone, nraysdone, (t-starttime)/3600.); |
330 |
– |
eputs(errmsg); |
331 |
– |
if (seconds2go == 1000000) |
332 |
– |
seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L; |
333 |
– |
if (seconds2go) |
334 |
– |
reporttime = t + seconds2go; |
335 |
– |
} |
336 |
– |
|
337 |
– |
|
351 |
|
setdefaults(gp) /* set default values */ |
352 |
|
register HDGRID *gp; |
353 |
|
{ |
354 |
|
extern char *atos(); |
355 |
|
register int i; |
356 |
< |
double len[3], maxlen, d; |
356 |
> |
int n; |
357 |
> |
double len[3], d; |
358 |
|
char buf[64]; |
359 |
|
|
360 |
|
if (!vdef(SECTION)) { |
361 |
|
sprintf(errmsg, "%s must be defined", vnam(SECTION)); |
362 |
|
error(USER, errmsg); |
363 |
|
} |
350 |
– |
if (vdef(SECTION) > 1) { |
351 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
352 |
– |
error(WARNING, errmsg); |
353 |
– |
} |
364 |
|
if (!vdef(OCTREE)) { |
365 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
366 |
|
error(SYSTEM, "out of memory"); |
367 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
368 |
|
vdef(OCTREE)++; |
369 |
|
} |
360 |
– |
if (!vdef(OBSTRUCTIONS)) { |
361 |
– |
vval(OBSTRUCTIONS) = "T"; |
362 |
– |
vdef(OBSTRUCTIONS)++; |
363 |
– |
} |
370 |
|
if (!vdef(VDIST)) { |
371 |
|
vval(VDIST) = "F"; |
372 |
|
vdef(VDIST)++; |
373 |
|
} |
368 |
– |
if (!vdef(OCCUPANCY)) { |
369 |
– |
vval(OCCUPANCY) = "U"; |
370 |
– |
vdef(OCCUPANCY)++; |
371 |
– |
} |
374 |
|
/* append rendering options */ |
375 |
|
if (vdef(RENDER)) |
376 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
378 |
|
if (gp == NULL) /* already initialized? */ |
379 |
|
return; |
380 |
|
/* set grid parameters */ |
381 |
< |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
382 |
< |
if (sscanf(vval(SECTION), |
381 |
> |
for (n = 0; n < vdef(SECTION); n++, gp++) { |
382 |
> |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
383 |
> |
if (sscanf(nvalue(SECTION, n), |
384 |
|
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
385 |
< |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
386 |
< |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
387 |
< |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
388 |
< |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
389 |
< |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
390 |
< |
badvalue(SECTION); |
391 |
< |
maxlen = 0.; |
392 |
< |
for (i = 0; i < 3; i++) |
393 |
< |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
394 |
< |
maxlen = len[i]; |
395 |
< |
if (!vdef(GRID)) { |
396 |
< |
sprintf(buf, "%.4f", maxlen/8.); |
397 |
< |
vval(GRID) = savqstr(buf); |
398 |
< |
vdef(GRID)++; |
385 |
> |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
386 |
> |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
387 |
> |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
388 |
> |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
389 |
> |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
390 |
> |
badvalue(SECTION); |
391 |
> |
for (i = 0; i < 3; i++) |
392 |
> |
len[i] = VLEN(gp->xv[i]); |
393 |
> |
if (!vdef(GRID)) { |
394 |
> |
d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] + |
395 |
> |
len[2]*len[2] + 4*len[1]*len[2]) |
396 |
> |
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
397 |
> |
+ 4*len[0]*len[1]*len[2]*len[2] ); |
398 |
> |
d = sqrt(sqrt(d)); |
399 |
> |
} else if ((d = vflt(GRID)) <= FTINY) |
400 |
> |
badvalue(GRID); |
401 |
> |
for (i = 0; i < 3; i++) |
402 |
> |
if (gp->grid[i] <= 0) |
403 |
> |
gp->grid[i] = len[i]/d + (1.-FTINY); |
404 |
|
} |
397 |
– |
if ((d = vflt(GRID)) <= FTINY) |
398 |
– |
badvalue(GRID); |
399 |
– |
for (i = 0; i < 3; i++) |
400 |
– |
if (gp->grid[i] <= 0) |
401 |
– |
gp->grid[i] = len[i]/d + (1.-FTINY); |
405 |
|
} |
406 |
|
|
407 |
|
|
409 |
|
HDGRID *gp; |
410 |
|
{ |
411 |
|
extern char VersionID[]; |
412 |
< |
long endloc = 0; |
412 |
> |
int4 lastloc, nextloc; |
413 |
> |
int n; |
414 |
|
int fd; |
415 |
|
FILE *fp; |
416 |
|
/* open & truncate file */ |
424 |
|
printvars(fp); |
425 |
|
fputformat(HOLOFMT, fp); |
426 |
|
fputc('\n', fp); |
427 |
< |
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
424 |
< |
fwrite(&endloc, sizeof(long), 1, fp); |
427 |
> |
putw(HOLOMAGIC, fp); /* put magic number */ |
428 |
|
fd = dup(fileno(fp)); |
429 |
|
fclose(fp); /* flush and close stdio stream */ |
430 |
< |
hdinit(fd, gp); /* allocate and initialize index */ |
430 |
> |
lastloc = lseek(fd, 0L, 2); |
431 |
> |
for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ |
432 |
> |
nextloc = 0L; |
433 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
434 |
> |
hdinit(fd, gp); /* writes beam index */ |
435 |
> |
if (!n) |
436 |
> |
break; |
437 |
> |
nextloc = hdfilen(fd); /* write section pointer */ |
438 |
> |
if (lseek(fd, (long)lastloc, 0) < 0) |
439 |
> |
error(SYSTEM, |
440 |
> |
"cannot seek on holodeck file in creatholo"); |
441 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
442 |
> |
lseek(fd, (long)(lastloc=nextloc), 0); |
443 |
> |
} |
444 |
|
} |
445 |
|
|
446 |
|
|
447 |
+ |
int |
448 |
|
headline(s) /* process information header line */ |
449 |
|
char *s; |
450 |
|
{ |
458 |
|
HOLOFMT, hdkfile, FMTSTR, fmt); |
459 |
|
error(USER, errmsg); |
460 |
|
} |
461 |
< |
return; |
461 |
> |
return(0); |
462 |
|
} |
463 |
|
for (cp = s; *cp; cp++) /* take off any comments */ |
464 |
|
if (*cp == '#') { |
466 |
|
break; |
467 |
|
} |
468 |
|
setvariable(s, matchvar); /* don't flag errors */ |
469 |
+ |
return(0); |
470 |
|
} |
471 |
|
|
472 |
|
|
475 |
|
extern long ftell(); |
476 |
|
FILE *fp; |
477 |
|
int fd; |
478 |
< |
long fpos; |
478 |
> |
int n; |
479 |
> |
int4 nextloc; |
480 |
|
/* open holodeck file */ |
481 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
482 |
< |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
483 |
< |
ncprocs>0 ? "appending" : "reading"); |
482 |
> |
sprintf(errmsg, "cannot %s \"%s\"", |
483 |
> |
ncprocs>0 ? "append" : "read", hdkfile); |
484 |
|
error(SYSTEM, errmsg); |
485 |
|
} |
486 |
|
/* load variables from header */ |
491 |
|
hdkfile); |
492 |
|
error(USER, errmsg); |
493 |
|
} |
494 |
< |
fread(&fpos, sizeof(long), 1, fp); |
476 |
< |
if (fpos != 0) |
477 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
478 |
< |
fpos = ftell(fp); /* get stdio position */ |
494 |
> |
nextloc = ftell(fp); /* get stdio position */ |
495 |
|
fd = dup(fileno(fp)); |
496 |
|
fclose(fp); /* done with stdio */ |
497 |
< |
lseek(fd, fpos, 0); /* align system file pointer */ |
498 |
< |
hdinit(fd, NULL); /* allocate and load index */ |
497 |
> |
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
498 |
> |
lseek(fd, (long)nextloc, 0); |
499 |
> |
read(fd, (char *)&nextloc, sizeof(nextloc)); |
500 |
> |
hdinit(fd, NULL); |
501 |
> |
} |
502 |
> |
if (n != vdef(SECTION)) { |
503 |
> |
sprintf(errmsg, "number of sections does not match %s setting", |
504 |
> |
vnam(SECTION)); |
505 |
> |
error(WARNING, errmsg); |
506 |
> |
} |
507 |
|
} |
508 |
|
|
509 |
|
|
521 |
|
p->nr*sizeof(RAYVAL)); |
522 |
|
if (outdev != NULL) /* display it */ |
523 |
|
disp_packet((PACKHEAD *)p); |
524 |
< |
if (hdcachesize <= 0) /* manual flushing */ |
525 |
< |
n2flush += p->nr; |
524 |
> |
if (hdcachesize <= 0) |
525 |
> |
n2flush++; |
526 |
|
nraysdone += p->nr; |
527 |
|
npacksdone++; |
528 |
+ |
p->nr = 0; |
529 |
|
} |
530 |
< |
p->nr = 0; /* push onto free list */ |
506 |
< |
p->next = freepacks; |
530 |
> |
p->next = freepacks; /* push onto free list */ |
531 |
|
freepacks = p; |
532 |
|
} |
533 |
< |
if (n2flush > 512*RPACKSIZ*nprocs) { |
534 |
< |
hdflush(NULL); /* flush holodeck buffers */ |
533 |
> |
if (n2flush >= RTFLUSH) { |
534 |
> |
if (outdev != NULL) |
535 |
> |
hdsync(NULL, 1); |
536 |
> |
else |
537 |
> |
hdflush(NULL); |
538 |
|
n2flush = 0; |
539 |
|
} |
540 |
|
} |
541 |
|
|
542 |
|
|
516 |
– |
int |
517 |
– |
done_rtrace() /* clean up and close rtrace calculation */ |
518 |
– |
{ |
519 |
– |
int status; |
520 |
– |
/* already closed? */ |
521 |
– |
if (!nprocs) |
522 |
– |
return; |
523 |
– |
/* report activity */ |
524 |
– |
wputs("closing rtrace process...\n"); |
525 |
– |
/* flush beam queue */ |
526 |
– |
done_packets(flush_queue()); |
527 |
– |
/* close rtrace */ |
528 |
– |
if ((status = end_rtrace())) |
529 |
– |
error(WARNING, "bad exit status from rtrace"); |
530 |
– |
if (vdef(REPORT)) /* report time */ |
531 |
– |
report(0); |
532 |
– |
return(status); /* return status */ |
533 |
– |
} |
534 |
– |
|
535 |
– |
|
536 |
– |
new_rtrace() /* restart rtrace calculation */ |
537 |
– |
{ |
538 |
– |
char combuf[128]; |
539 |
– |
|
540 |
– |
if (nprocs > 0) /* already running? */ |
541 |
– |
return; |
542 |
– |
wputs("restarting rtrace process...\n"); |
543 |
– |
if (vdef(RIF)) { /* rerun rad to update octree */ |
544 |
– |
sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); |
545 |
– |
if (system(combuf)) |
546 |
– |
error(WARNING, "error running rad"); |
547 |
– |
} |
548 |
– |
if (start_rtrace() < 1) /* start rtrace */ |
549 |
– |
error(WARNING, "cannot restart rtrace"); |
550 |
– |
else if (vdef(REPORT)) |
551 |
– |
report(0); |
552 |
– |
} |
553 |
– |
|
554 |
– |
|
555 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
556 |
– |
char *rfargs; |
557 |
– |
{ |
558 |
– |
static short mvar[] = {OCTREE,-1}; |
559 |
– |
static char tf1[] = TEMPLATE; |
560 |
– |
char tf2[64]; |
561 |
– |
char combuf[256]; |
562 |
– |
char *pippt; |
563 |
– |
register int i; |
564 |
– |
register char *cp; |
565 |
– |
/* create rad command */ |
566 |
– |
mktemp(tf1); |
567 |
– |
sprintf(tf2, "%s.rif", tf1); |
568 |
– |
sprintf(combuf, |
569 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
570 |
– |
rfargs, tf1); |
571 |
– |
cp = combuf; |
572 |
– |
while (*cp){ |
573 |
– |
if (*cp == '|') pippt = cp; |
574 |
– |
cp++; |
575 |
– |
} /* match unset variables */ |
576 |
– |
for (i = 0; mvar[i] >= 0; i++) |
577 |
– |
if (!vdef(mvar[i])) { |
578 |
– |
*cp++ = '|'; |
579 |
– |
strcpy(cp, vnam(mvar[i])); |
580 |
– |
while (*cp) cp++; |
581 |
– |
pippt = NULL; |
582 |
– |
} |
583 |
– |
if (pippt != NULL) |
584 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
585 |
– |
else |
586 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
587 |
– |
if (system(combuf)) { |
588 |
– |
unlink(tf2); /* clean up */ |
589 |
– |
unlink(tf1); |
590 |
– |
error(SYSTEM, "cannot execute rad command"); |
591 |
– |
} |
592 |
– |
if (pippt == NULL) { |
593 |
– |
loadvars(tf2); /* load variables */ |
594 |
– |
unlink(tf2); |
595 |
– |
} |
596 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
597 |
– |
unlink(tf1); /* clean up */ |
598 |
– |
} |
599 |
– |
|
600 |
– |
|
543 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
544 |
|
register char *rn, *fn; |
545 |
|
{ |
546 |
|
char *tp, *dp; |
547 |
|
|
548 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
549 |
< |
if (ISDIRSEP(*rn)) |
549 |
> |
if (*rn == '/') |
550 |
|
dp = rn; |
551 |
|
else if (*rn == '.') |
552 |
|
tp = rn; |
582 |
|
} |
583 |
|
|
584 |
|
|
643 |
– |
wputs(s) /* put warning string to stderr */ |
644 |
– |
char *s; |
645 |
– |
{ |
646 |
– |
if (!nowarn) |
647 |
– |
eputs(s); |
648 |
– |
} |
649 |
– |
|
650 |
– |
|
585 |
|
quit(ec) /* exit program gracefully */ |
586 |
|
int ec; |
587 |
|
{ |
588 |
|
int status = 0; |
589 |
|
|
590 |
< |
if (hdlist[0] != NULL) { /* flush holodeck */ |
590 |
> |
if (hdlist[0] != NULL) { /* close holodeck */ |
591 |
|
if (nprocs > 0) |
592 |
< |
status = done_rtrace(); |
659 |
< |
hdflush(NULL); |
592 |
> |
status = done_rtrace(); /* calls hdsync() */ |
593 |
|
if (ncprocs > 0 && vdef(REPORT)) { |
594 |
|
long fsiz, fuse; |
595 |
|
fsiz = hdfilen(hdlist[0]->fd); |