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> |
21 |
|
|
22 |
|
char *progname; /* our program name */ |
23 |
|
char *hdkfile; /* holodeck file name */ |
24 |
< |
char froot[MAXPATH]; /* root file name */ |
24 |
> |
char froot[256]; /* root file name */ |
25 |
|
|
26 |
|
int nowarn = 0; /* turn warnings off? */ |
27 |
|
|
88 |
|
default: |
89 |
|
goto userr; |
90 |
|
} |
92 |
– |
/* do we have a job? */ |
93 |
– |
if (outdev == NULL && ncprocs <= 0) |
94 |
– |
goto userr; |
91 |
|
/* get root file name */ |
92 |
|
rootname(froot, hdkfile=argv[i++]); |
93 |
|
/* load... */ |
103 |
|
/* check settings */ |
104 |
|
checkvalues(); |
105 |
|
/* load RIF if any */ |
106 |
< |
if (vdef(RIF)) |
111 |
< |
getradfile(vval(RIF)); |
106 |
> |
getradfile(); |
107 |
|
/* set defaults */ |
108 |
|
setdefaults(&hdg); |
109 |
|
/* holodeck exists? */ |
117 |
|
/* check settings */ |
118 |
|
checkvalues(); |
119 |
|
/* load RIF if any */ |
120 |
< |
if (vdef(RIF)) |
126 |
< |
getradfile(vval(RIF)); |
120 |
> |
getradfile(); |
121 |
|
/* set defaults */ |
122 |
|
setdefaults(NULL); |
123 |
|
} |
130 |
|
quit(0); |
131 |
|
userr: |
132 |
|
fprintf(stderr, |
133 |
< |
"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
133 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
134 |
|
progname); |
135 |
|
quit(1); |
136 |
|
} |
203 |
|
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
204 |
|
endtime = 0; |
205 |
|
else |
206 |
< |
endtime = starttime + vflt(TIME)*3600.; |
206 |
> |
endtime = starttime + vflt(TIME)*3600. + .5; |
207 |
|
/* set up memory cache */ |
208 |
|
if (outdev == NULL) |
209 |
|
hdcachesize = 0; /* manual flushing */ |
230 |
|
goto memerr; |
231 |
|
freepacks[--i].nr = 0; |
232 |
|
freepacks[i].next = NULL; |
233 |
< |
if (!vbool(OBSTRUCTIONS)) { |
233 |
> |
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
234 |
|
freepacks[i].offset = (float *)bmalloc( |
235 |
|
RPACKSIZ*sizeof(float)*(i+1) ); |
236 |
|
if (freepacks[i].offset == NULL) |
275 |
|
return(0); |
276 |
|
/* display only? */ |
277 |
|
if (nprocs <= 0) |
278 |
< |
return(1); |
278 |
> |
return(outdev != NULL); |
279 |
|
/* check file size */ |
280 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
281 |
|
error(WARNING, "file limit exceeded"); |
282 |
< |
return(0); |
282 |
> |
done_rtrace(); |
283 |
> |
idle = 1; |
284 |
> |
return(1); /* comes back */ |
285 |
|
} |
286 |
|
/* check time */ |
287 |
|
if (endtime > 0 || reporttime > 0) |
288 |
|
t = time(NULL); |
289 |
|
if (endtime > 0 && t >= endtime) { |
290 |
|
error(WARNING, "time limit exceeded"); |
291 |
< |
return(0); |
291 |
> |
done_rtrace(); |
292 |
> |
idle = 1; |
293 |
> |
return(1); /* comes back */ |
294 |
|
} |
295 |
|
if (reporttime > 0 && t >= reporttime) |
296 |
|
report(t); |
299 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
300 |
|
if (!next_packet(p)) { |
301 |
|
p->next = freepacks; freepacks = p; |
302 |
+ |
idle = 1; |
303 |
|
break; |
304 |
|
} |
305 |
|
if (pl == NULL) pl = p; |
306 |
|
else plend->next = p; |
307 |
|
plend = p; |
308 |
|
} |
309 |
< |
idle = pl == NULL && freepacks != NULL; |
311 |
< |
/* are we out of stuff to do? */ |
312 |
< |
if (idle && outdev == NULL) |
313 |
< |
return(0); |
314 |
< |
/* else process packets */ |
309 |
> |
/* process packets */ |
310 |
|
done_packets(do_packets(pl)); |
311 |
|
return(1); /* and continue */ |
312 |
|
} |
313 |
|
|
314 |
|
|
320 |
– |
report(t) /* report progress so far */ |
321 |
– |
time_t t; |
322 |
– |
{ |
323 |
– |
if (t == 0) |
324 |
– |
t = time(NULL); |
325 |
– |
fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", |
326 |
– |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
327 |
– |
fflush(stderr); |
328 |
– |
if (vdef(REPORT)) |
329 |
– |
reporttime = t + (time_t)(vflt(REPORT)*60.+.5); |
330 |
– |
} |
331 |
– |
|
332 |
– |
|
315 |
|
setdefaults(gp) /* set default values */ |
316 |
|
register HDGRID *gp; |
317 |
|
{ |
334 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
335 |
|
vdef(OCTREE)++; |
336 |
|
} |
355 |
– |
if (!vdef(OBSTRUCTIONS)) { |
356 |
– |
vval(OBSTRUCTIONS) = "T"; |
357 |
– |
vdef(OBSTRUCTIONS)++; |
358 |
– |
} |
337 |
|
if (!vdef(VDIST)) { |
338 |
|
vval(VDIST) = "F"; |
339 |
|
vdef(VDIST)++; |
486 |
|
} |
487 |
|
|
488 |
|
|
511 |
– |
checkrad() /* check to make sure octree is up to date */ |
512 |
– |
{ |
513 |
– |
char combuf[128]; |
514 |
– |
|
515 |
– |
if (!vdef(RIF)) |
516 |
– |
return; |
517 |
– |
sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); |
518 |
– |
if (system(combuf)) |
519 |
– |
error(WARNING, "error running rad"); |
520 |
– |
} |
521 |
– |
|
522 |
– |
|
523 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
524 |
– |
char *rfargs; |
525 |
– |
{ |
526 |
– |
static short mvar[] = {OCTREE,-1}; |
527 |
– |
static char tf1[] = TEMPLATE; |
528 |
– |
char tf2[64]; |
529 |
– |
char combuf[256]; |
530 |
– |
char *pippt; |
531 |
– |
register int i; |
532 |
– |
register char *cp; |
533 |
– |
/* create rad command */ |
534 |
– |
mktemp(tf1); |
535 |
– |
sprintf(tf2, "%s.rif", tf1); |
536 |
– |
sprintf(combuf, |
537 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
538 |
– |
rfargs, tf1); |
539 |
– |
cp = combuf; |
540 |
– |
while (*cp){ |
541 |
– |
if (*cp == '|') pippt = cp; |
542 |
– |
cp++; |
543 |
– |
} /* match unset variables */ |
544 |
– |
for (i = 0; mvar[i] >= 0; i++) |
545 |
– |
if (!vdef(mvar[i])) { |
546 |
– |
*cp++ = '|'; |
547 |
– |
strcpy(cp, vnam(mvar[i])); |
548 |
– |
while (*cp) cp++; |
549 |
– |
pippt = NULL; |
550 |
– |
} |
551 |
– |
if (pippt != NULL) |
552 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
553 |
– |
else |
554 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
555 |
– |
if (system(combuf)) { |
556 |
– |
unlink(tf2); /* clean up */ |
557 |
– |
unlink(tf1); |
558 |
– |
error(SYSTEM, "cannot execute rad command"); |
559 |
– |
} |
560 |
– |
if (pippt == NULL) { |
561 |
– |
loadvars(tf2); /* load variables */ |
562 |
– |
unlink(tf2); |
563 |
– |
} |
564 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
565 |
– |
unlink(tf1); /* clean up */ |
566 |
– |
} |
567 |
– |
|
568 |
– |
|
489 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
490 |
|
register char *rn, *fn; |
491 |
|
{ |
492 |
|
char *tp, *dp; |
493 |
|
|
494 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
495 |
< |
if (ISDIRSEP(*rn)) |
495 |
> |
if (*rn == '/') |
496 |
|
dp = rn; |
497 |
|
else if (*rn == '.') |
498 |
|
tp = rn; |
541 |
|
{ |
542 |
|
int status = 0; |
543 |
|
|
544 |
< |
if (hdlist[0] != NULL) { /* flush holodeck */ |
545 |
< |
if (nprocs > 0) { |
546 |
< |
done_packets(flush_queue()); |
627 |
< |
status = end_rtrace(); /* close rtrace */ |
628 |
< |
} |
629 |
< |
hdflush(NULL); |
544 |
> |
if (hdlist[0] != NULL) { /* close holodeck */ |
545 |
> |
if (nprocs > 0) |
546 |
> |
status = done_rtrace(); /* calls hdsync() */ |
547 |
|
if (ncprocs > 0 && vdef(REPORT)) { |
548 |
|
long fsiz, fuse; |
632 |
– |
report(0); |
549 |
|
fsiz = hdfilen(hdlist[0]->fd); |
550 |
|
fuse = hdfiluse(hdlist[0]->fd, 1); |
551 |
|
fprintf(stderr, |