| 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 |
|
|
| 106 |
|
/* check settings */ |
| 107 |
|
checkvalues(); |
| 108 |
|
/* load RIF if any */ |
| 109 |
< |
if (vdef(RIF)) |
| 111 |
< |
getradfile(vval(RIF)); |
| 109 |
> |
getradfile(); |
| 110 |
|
/* set defaults */ |
| 111 |
|
setdefaults(&hdg); |
| 112 |
|
/* holodeck exists? */ |
| 120 |
|
/* check settings */ |
| 121 |
|
checkvalues(); |
| 122 |
|
/* load RIF if any */ |
| 123 |
< |
if (vdef(RIF)) |
| 126 |
< |
getradfile(vval(RIF)); |
| 123 |
> |
getradfile(); |
| 124 |
|
/* set defaults */ |
| 125 |
|
setdefaults(NULL); |
| 126 |
|
} |
| 206 |
|
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
| 207 |
|
endtime = 0; |
| 208 |
|
else |
| 209 |
< |
endtime = starttime + vflt(TIME)*3600.; |
| 209 |
> |
endtime = starttime + vflt(TIME)*3600. + .5; |
| 210 |
|
/* set up memory cache */ |
| 211 |
|
if (outdev == NULL) |
| 212 |
|
hdcachesize = 0; /* manual flushing */ |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 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 |
– |
|
| 318 |
|
setdefaults(gp) /* set default values */ |
| 319 |
|
register HDGRID *gp; |
| 320 |
|
{ |
| 493 |
|
} |
| 494 |
|
|
| 495 |
|
|
| 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 |
– |
|
| 496 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
| 497 |
|
register char *rn, *fn; |
| 498 |
|
{ |
| 499 |
|
char *tp, *dp; |
| 500 |
|
|
| 501 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
| 502 |
< |
if (ISDIRSEP(*rn)) |
| 502 |
> |
if (*rn == '/') |
| 503 |
|
dp = rn; |
| 504 |
|
else if (*rn == '.') |
| 505 |
|
tp = rn; |