1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
9 |
|
*/ |
10 |
|
|
11 |
|
#include "rholo.h" |
12 |
< |
#include "paths.h" |
12 |
> |
#include "random.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 |
|
|
26 |
– |
int nowarn = 0; /* turn warnings off? */ |
27 |
– |
|
28 |
– |
double expval = 1.; /* global exposure value */ |
29 |
– |
|
29 |
|
int ncprocs = 0; /* desired number of compute processes */ |
30 |
|
|
31 |
|
char *outdev = NULL; /* output device name */ |
32 |
|
|
33 |
+ |
int readinp = 0; /* read commands from stdin */ |
34 |
+ |
|
35 |
+ |
int force = 0; /* allow overwrite of holodeck */ |
36 |
+ |
|
37 |
|
time_t starttime; /* time we got started */ |
38 |
|
time_t endtime; /* time we should end by */ |
39 |
|
time_t reporttime; /* time for next report */ |
49 |
|
long npacksdone = 0L; /* number of packets done */ |
50 |
|
|
51 |
|
PACKET *freepacks; /* available packets */ |
52 |
+ |
int totqlen; /* maximum queue length when full */ |
53 |
|
|
54 |
|
char *sigerr[NSIG]; /* signal error messages */ |
55 |
|
|
56 |
+ |
extern int nowarn; /* turn warnings off? */ |
57 |
+ |
|
58 |
|
extern time_t time(); |
59 |
|
|
60 |
|
|
62 |
|
int argc; |
63 |
|
char *argv[]; |
64 |
|
{ |
59 |
– |
HDGRID hdg; |
65 |
|
int i; |
66 |
< |
int force = 0; |
67 |
< |
/* mark start time */ |
63 |
< |
starttime = time(NULL); |
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 |
|
} |
86 |
– |
/* do we have a job? */ |
87 |
– |
if (outdev == NULL && ncprocs <= 0) |
88 |
– |
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(); |
116 |
< |
if (vdef(RIF)) /* load RIF if any */ |
117 |
< |
getradfile(vval(RIF)); |
118 |
< |
} |
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); |
195 |
– |
/* record end time */ |
196 |
– |
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
197 |
– |
endtime = 0; |
198 |
– |
else |
199 |
– |
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(); |
225 |
> |
totqlen = 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); |
235 |
|
goto memerr; |
236 |
|
freepacks[--i].nr = 0; |
237 |
|
freepacks[i].next = NULL; |
238 |
< |
if (!vbool(OBSTRUCTIONS)) { |
238 |
> |
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
239 |
|
freepacks[i].offset = (float *)bmalloc( |
240 |
|
RPACKSIZ*sizeof(float)*(i+1) ); |
241 |
|
if (freepacks[i].offset == NULL) |
269 |
|
|
270 |
|
rholo() /* holodeck main loop */ |
271 |
|
{ |
272 |
< |
static int idle = 1; |
272 |
> |
static int idle = 0; |
273 |
|
PACKET *pl = NULL, *plend; |
274 |
+ |
int pksiz; |
275 |
|
register PACKET *p; |
276 |
|
time_t t; |
277 |
< |
long l; |
278 |
< |
|
279 |
< |
if (outdev != NULL) /* check display */ |
277 |
> |
/* check display */ |
278 |
> |
if (nprocs <= 0) |
279 |
> |
idle = 1; |
280 |
> |
if (outdev != NULL) { |
281 |
|
if (!disp_check(idle)) |
282 |
< |
return(0); |
283 |
< |
/* display only? */ |
284 |
< |
if (ncprocs <= 0) |
285 |
< |
return(1); |
282 |
> |
return(0); /* quit request */ |
283 |
> |
if (nprocs <= 0) |
284 |
> |
return(1); |
285 |
> |
} else if (idle) |
286 |
> |
return(0); /* all done */ |
287 |
|
/* check file size */ |
288 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
289 |
|
error(WARNING, "file limit exceeded"); |
290 |
< |
return(0); |
290 |
> |
done_rtrace(); |
291 |
> |
return(1); /* comes back */ |
292 |
|
} |
293 |
< |
/* check time */ |
278 |
< |
if (endtime > 0 || reporttime > 0) |
279 |
< |
t = time(NULL); |
293 |
> |
t = time(NULL); /* check time */ |
294 |
|
if (endtime > 0 && t >= endtime) { |
295 |
|
error(WARNING, "time limit exceeded"); |
296 |
< |
return(0); |
296 |
> |
done_rtrace(); |
297 |
> |
return(1); /* comes back */ |
298 |
|
} |
299 |
|
if (reporttime > 0 && t >= reporttime) |
300 |
|
report(t); |
301 |
< |
/* get packets to process */ |
301 |
> |
/* figure out good packet size */ |
302 |
> |
#if MAXQTIME |
303 |
> |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
304 |
> |
if (pksiz < 1) |
305 |
> |
pksiz = 1; |
306 |
> |
else if (pksiz > RPACKSIZ) |
307 |
> |
#endif |
308 |
> |
pksiz = RPACKSIZ; |
309 |
> |
idle = 0; /* get packets to process */ |
310 |
|
while (freepacks != NULL) { |
311 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
312 |
< |
if (!next_packet(p)) { |
312 |
> |
if (!next_packet(p, pksiz)) { |
313 |
|
p->next = freepacks; freepacks = p; |
314 |
+ |
idle = 1; |
315 |
|
break; |
316 |
|
} |
317 |
|
if (pl == NULL) pl = p; |
318 |
|
else plend->next = p; |
319 |
|
plend = p; |
320 |
|
} |
321 |
< |
idle = pl == NULL && freepacks != NULL; |
298 |
< |
/* are we out of stuff to do? */ |
299 |
< |
if (idle && outdev == NULL) |
300 |
< |
return(0); |
301 |
< |
/* else process packets */ |
321 |
> |
/* process packets */ |
322 |
|
done_packets(do_packets(pl)); |
323 |
|
return(1); /* and continue */ |
324 |
|
} |
325 |
|
|
326 |
|
|
307 |
– |
report(t) /* report progress so far */ |
308 |
– |
time_t t; |
309 |
– |
{ |
310 |
– |
if (t == 0) |
311 |
– |
t = time(NULL); |
312 |
– |
fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", |
313 |
– |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
314 |
– |
fflush(stderr); |
315 |
– |
if (vdef(REPORT)) |
316 |
– |
reporttime = t + (time_t)(vflt(REPORT)*60.+.5); |
317 |
– |
} |
318 |
– |
|
319 |
– |
|
327 |
|
setdefaults(gp) /* set default values */ |
328 |
|
register HDGRID *gp; |
329 |
|
{ |
330 |
|
extern char *atos(); |
331 |
|
register int i; |
332 |
< |
double len[3], maxlen, d; |
332 |
> |
int n; |
333 |
> |
double len[3], d; |
334 |
|
char buf[64]; |
335 |
|
|
336 |
|
if (!vdef(SECTION)) { |
337 |
|
sprintf(errmsg, "%s must be defined", vnam(SECTION)); |
338 |
|
error(USER, errmsg); |
339 |
|
} |
332 |
– |
if (vdef(SECTION) > 1) { |
333 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
334 |
– |
error(WARNING, errmsg); |
335 |
– |
} |
336 |
– |
if (sscanf(vval(SECTION), |
337 |
– |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", |
338 |
– |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
339 |
– |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
340 |
– |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
341 |
– |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12) |
342 |
– |
badvalue(SECTION); |
343 |
– |
maxlen = 0.; |
344 |
– |
for (i = 0; i < 3; i++) |
345 |
– |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
346 |
– |
maxlen = len[i]; |
347 |
– |
if (!vdef(GRID)) { |
348 |
– |
sprintf(buf, "%.4f", maxlen/8.); |
349 |
– |
vval(GRID) = savqstr(buf); |
350 |
– |
vdef(GRID)++; |
351 |
– |
} |
352 |
– |
if ((d = vflt(GRID)) <= FTINY) |
353 |
– |
badvalue(GRID); |
354 |
– |
for (i = 0; i < 3; i++) |
355 |
– |
gp->grid[i] = len[i]/d + (1.-FTINY); |
356 |
– |
if (!vdef(EXPOSURE)) { |
357 |
– |
sprintf(errmsg, "%s must be defined", vnam(EXPOSURE)); |
358 |
– |
error(USER, errmsg); |
359 |
– |
} |
360 |
– |
expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ? |
361 |
– |
pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE); |
340 |
|
if (!vdef(OCTREE)) { |
341 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
342 |
|
error(SYSTEM, "out of memory"); |
343 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
344 |
|
vdef(OCTREE)++; |
345 |
|
} |
346 |
< |
if (!vdef(OBSTRUCTIONS)) { |
347 |
< |
vval(OBSTRUCTIONS) = "T"; |
348 |
< |
vdef(OBSTRUCTIONS)++; |
346 |
> |
if (!vdef(VDIST)) { |
347 |
> |
vval(VDIST) = "F"; |
348 |
> |
vdef(VDIST)++; |
349 |
|
} |
372 |
– |
if (!vdef(OCCUPANCY)) { |
373 |
– |
vval(OCCUPANCY) = "U"; |
374 |
– |
vdef(OCCUPANCY)++; |
375 |
– |
} |
350 |
|
/* append rendering options */ |
351 |
|
if (vdef(RENDER)) |
352 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
353 |
+ |
|
354 |
+ |
if (gp == NULL) /* already initialized? */ |
355 |
+ |
return; |
356 |
+ |
/* set grid parameters */ |
357 |
+ |
for (n = 0; n < vdef(SECTION); n++, gp++) { |
358 |
+ |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
359 |
+ |
if (sscanf(nvalue(SECTION, n), |
360 |
+ |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
361 |
+ |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
362 |
+ |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
363 |
+ |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
364 |
+ |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
365 |
+ |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
366 |
+ |
badvalue(SECTION); |
367 |
+ |
for (i = 0; i < 3; i++) |
368 |
+ |
len[i] = VLEN(gp->xv[i]); |
369 |
+ |
if (!vdef(GRID)) { |
370 |
+ |
d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] + |
371 |
+ |
len[2]*len[2] + 4*len[1]*len[2]) |
372 |
+ |
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
373 |
+ |
+ 4*len[0]*len[1]*len[2]*len[2] ); |
374 |
+ |
d = sqrt(sqrt(d)); |
375 |
+ |
} else if ((d = vflt(GRID)) <= FTINY) |
376 |
+ |
badvalue(GRID); |
377 |
+ |
for (i = 0; i < 3; i++) |
378 |
+ |
if (gp->grid[i] <= 0) |
379 |
+ |
gp->grid[i] = len[i]/d + (1.-FTINY); |
380 |
+ |
} |
381 |
|
} |
382 |
|
|
383 |
|
|
385 |
|
HDGRID *gp; |
386 |
|
{ |
387 |
|
extern char VersionID[]; |
388 |
< |
long endloc = 0; |
388 |
> |
int4 lastloc, nextloc; |
389 |
> |
int n; |
390 |
|
int fd; |
391 |
|
FILE *fp; |
392 |
|
/* open & truncate file */ |
400 |
|
printvars(fp); |
401 |
|
fputformat(HOLOFMT, fp); |
402 |
|
fputc('\n', fp); |
403 |
< |
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
401 |
< |
fwrite(&endloc, sizeof(long), 1, fp); |
403 |
> |
putw(HOLOMAGIC, fp); /* put magic number */ |
404 |
|
fd = dup(fileno(fp)); |
405 |
|
fclose(fp); /* flush and close stdio stream */ |
406 |
< |
hdinit(fd, gp); /* allocate and initialize index */ |
406 |
> |
lastloc = lseek(fd, 0L, 2); |
407 |
> |
for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ |
408 |
> |
nextloc = 0L; |
409 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
410 |
> |
hdinit(fd, gp); /* writes beam index */ |
411 |
> |
if (!n) |
412 |
> |
break; |
413 |
> |
nextloc = hdfilen(fd); /* write section pointer */ |
414 |
> |
if (lseek(fd, (long)lastloc, 0) < 0) |
415 |
> |
error(SYSTEM, |
416 |
> |
"cannot seek on holodeck file in creatholo"); |
417 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
418 |
> |
lseek(fd, (long)(lastloc=nextloc), 0); |
419 |
> |
} |
420 |
|
} |
421 |
|
|
422 |
|
|
449 |
|
extern long ftell(); |
450 |
|
FILE *fp; |
451 |
|
int fd; |
452 |
< |
long fpos; |
452 |
> |
int n; |
453 |
> |
int4 nextloc; |
454 |
|
/* open holodeck file */ |
455 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
456 |
< |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
457 |
< |
ncprocs>0 ? "appending" : "reading"); |
456 |
> |
sprintf(errmsg, "cannot %s \"%s\"", |
457 |
> |
ncprocs>0 ? "append" : "read", hdkfile); |
458 |
|
error(SYSTEM, errmsg); |
459 |
|
} |
460 |
|
/* load variables from header */ |
465 |
|
hdkfile); |
466 |
|
error(USER, errmsg); |
467 |
|
} |
468 |
< |
fread(&fpos, sizeof(long), 1, fp); |
453 |
< |
if (fpos != 0) |
454 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
455 |
< |
fpos = ftell(fp); /* get stdio position */ |
468 |
> |
nextloc = ftell(fp); /* get stdio position */ |
469 |
|
fd = dup(fileno(fp)); |
470 |
|
fclose(fp); /* done with stdio */ |
471 |
< |
lseek(fd, fpos, 0); /* align system file pointer */ |
472 |
< |
hdinit(fd, NULL); /* allocate and load index */ |
471 |
> |
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
472 |
> |
lseek(fd, (long)nextloc, 0); |
473 |
> |
read(fd, (char *)&nextloc, sizeof(nextloc)); |
474 |
> |
hdinit(fd, NULL); |
475 |
> |
} |
476 |
> |
if (n != vdef(SECTION)) { |
477 |
> |
sprintf(errmsg, "number of sections does not match %s setting", |
478 |
> |
vnam(SECTION)); |
479 |
> |
error(WARNING, errmsg); |
480 |
> |
} |
481 |
|
} |
482 |
|
|
483 |
|
|
484 |
|
done_packets(pl) /* handle finished packets */ |
485 |
|
PACKET *pl; |
486 |
|
{ |
487 |
< |
static int nunflushed = 0; |
487 |
> |
static int n2flush = 0; |
488 |
|
register PACKET *p; |
489 |
|
|
490 |
|
while (pl != NULL) { |
495 |
|
p->nr*sizeof(RAYVAL)); |
496 |
|
if (outdev != NULL) /* display it */ |
497 |
|
disp_packet((PACKHEAD *)p); |
498 |
< |
else |
499 |
< |
nunflushed += p->nr; |
498 |
> |
if (hdcachesize <= 0) /* manual flushing */ |
499 |
> |
n2flush++; |
500 |
|
nraysdone += p->nr; |
501 |
|
npacksdone++; |
502 |
+ |
p->nr = 0; |
503 |
|
} |
504 |
< |
p->nr = 0; /* push onto free list */ |
483 |
< |
p->next = freepacks; |
504 |
> |
p->next = freepacks; /* push onto free list */ |
505 |
|
freepacks = p; |
506 |
|
} |
507 |
< |
if (nunflushed >= 256*RPACKSIZ) { |
507 |
> |
if (n2flush > 300/MAXQTIME*totqlen) { |
508 |
|
hdflush(NULL); /* flush holodeck buffers */ |
509 |
< |
nunflushed = 0; |
509 |
> |
n2flush = 0; |
510 |
|
} |
511 |
|
} |
512 |
|
|
513 |
|
|
493 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
494 |
– |
char *rfargs; |
495 |
– |
{ |
496 |
– |
static short mvar[] = {OCTREE,EXPOSURE,-1}; |
497 |
– |
static char tf1[] = TEMPLATE; |
498 |
– |
char tf2[64]; |
499 |
– |
char combuf[256]; |
500 |
– |
char *pippt; |
501 |
– |
register int i; |
502 |
– |
register char *cp; |
503 |
– |
/* create rad command */ |
504 |
– |
mktemp(tf1); |
505 |
– |
sprintf(tf2, "%s.rif", tf1); |
506 |
– |
sprintf(combuf, |
507 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
508 |
– |
rfargs, tf1); |
509 |
– |
cp = combuf; |
510 |
– |
while (*cp){ |
511 |
– |
if (*cp == '|') pippt = cp; |
512 |
– |
cp++; |
513 |
– |
} /* match unset variables */ |
514 |
– |
for (i = 0; mvar[i] >= 0; i++) |
515 |
– |
if (!vdef(mvar[i])) { |
516 |
– |
*cp++ = '|'; |
517 |
– |
strcpy(cp, vnam(mvar[i])); |
518 |
– |
while (*cp) cp++; |
519 |
– |
pippt = NULL; |
520 |
– |
} |
521 |
– |
if (pippt != NULL) |
522 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
523 |
– |
else |
524 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
525 |
– |
if (system(combuf)) { |
526 |
– |
error(SYSTEM, "cannot execute rad command"); |
527 |
– |
unlink(tf2); /* clean up */ |
528 |
– |
unlink(tf1); |
529 |
– |
quit(1); |
530 |
– |
} |
531 |
– |
if (pippt == NULL) { |
532 |
– |
loadvars(tf2); /* load variables */ |
533 |
– |
unlink(tf2); |
534 |
– |
} |
535 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
536 |
– |
unlink(tf1); /* clean up */ |
537 |
– |
} |
538 |
– |
|
539 |
– |
|
514 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
515 |
|
register char *rn, *fn; |
516 |
|
{ |
517 |
|
char *tp, *dp; |
518 |
|
|
519 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
520 |
< |
if (ISDIRSEP(*rn)) |
520 |
> |
if (*rn == '/') |
521 |
|
dp = rn; |
522 |
|
else if (*rn == '.') |
523 |
|
tp = rn; |
553 |
|
} |
554 |
|
|
555 |
|
|
582 |
– |
wputs(s) /* put warning string to stderr */ |
583 |
– |
char *s; |
584 |
– |
{ |
585 |
– |
if (!nowarn) |
586 |
– |
eputs(s); |
587 |
– |
} |
588 |
– |
|
589 |
– |
|
556 |
|
quit(ec) /* exit program gracefully */ |
557 |
|
int ec; |
558 |
|
{ |
559 |
|
int status = 0; |
560 |
|
|
561 |
< |
if (hdlist[0] != NULL) { /* flush holodeck */ |
562 |
< |
if (ncprocs > 0) { |
563 |
< |
done_packets(flush_queue()); |
564 |
< |
status = end_rtrace(); /* close rtrace */ |
565 |
< |
hdflush(NULL); |
566 |
< |
if (vdef(REPORT)) { |
567 |
< |
long fsiz, fuse; |
568 |
< |
report(0); |
603 |
< |
fsiz = hdfilen(hdlist[0]->fd); |
604 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
605 |
< |
fprintf(stderr, |
561 |
> |
if (hdlist[0] != NULL) { /* close holodeck */ |
562 |
> |
if (nprocs > 0) |
563 |
> |
status = done_rtrace(); /* calls hdsync() */ |
564 |
> |
if (ncprocs > 0 && vdef(REPORT)) { |
565 |
> |
long fsiz, fuse; |
566 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
567 |
> |
fuse = hdfiluse(hdlist[0]->fd, 1); |
568 |
> |
fprintf(stderr, |
569 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
570 |
< |
hdkfile, fsiz/(1024.*1024.), |
571 |
< |
100.*(fsiz-fuse)/fsiz); |
572 |
< |
} |
610 |
< |
} else |
611 |
< |
hdflush(NULL); |
570 |
> |
hdkfile, fsiz/(1024.*1024.), |
571 |
> |
100.*(fsiz-fuse)/fsiz); |
572 |
> |
} |
573 |
|
} |
574 |
|
if (orig_mode >= 0) /* reset holodeck access mode */ |
575 |
|
fchmod(hdlist[0]->fd, orig_mode); |