9 |
|
*/ |
10 |
|
|
11 |
|
#include "rholo.h" |
12 |
+ |
#include "paths.h" |
13 |
|
#include "random.h" |
14 |
|
|
15 |
|
|
62 |
|
rvl += 4; |
63 |
|
} |
64 |
|
p->nc += p->nr; |
65 |
+ |
} |
66 |
+ |
|
67 |
+ |
|
68 |
+ |
int |
69 |
+ |
done_rtrace() /* clean up and close rtrace calculation */ |
70 |
+ |
{ |
71 |
+ |
int status; |
72 |
+ |
/* already closed? */ |
73 |
+ |
if (!nprocs) |
74 |
+ |
return; |
75 |
+ |
wputs("closing rtrace process...\n"); |
76 |
+ |
/* flush beam queue */ |
77 |
+ |
done_packets(flush_queue()); |
78 |
+ |
/* close rtrace */ |
79 |
+ |
if ((status = end_rtrace())) |
80 |
+ |
error(WARNING, "bad exit status from rtrace"); |
81 |
+ |
if (vdef(REPORT)) /* report time */ |
82 |
+ |
report(0); |
83 |
+ |
return(status); /* return status */ |
84 |
+ |
} |
85 |
+ |
|
86 |
+ |
|
87 |
+ |
new_rtrace() /* restart rtrace calculation */ |
88 |
+ |
{ |
89 |
+ |
char combuf[128]; |
90 |
+ |
|
91 |
+ |
if (nprocs > 0) /* already running? */ |
92 |
+ |
return; |
93 |
+ |
wputs("restarting rtrace process...\n"); |
94 |
+ |
starttime = time(NULL); /* reset start time and counts */ |
95 |
+ |
npacksdone = nraysdone = 0L; |
96 |
+ |
if (vdef(TIME)) /* reset end time */ |
97 |
+ |
endtime = starttime + vflt(TIME)*3600. + .5; |
98 |
+ |
if (vdef(RIF)) { /* rerun rad to update octree */ |
99 |
+ |
sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); |
100 |
+ |
if (system(combuf)) |
101 |
+ |
error(WARNING, "error running rad"); |
102 |
+ |
} |
103 |
+ |
if (start_rtrace() < 1) /* start rtrace */ |
104 |
+ |
error(WARNING, "cannot restart rtrace"); |
105 |
+ |
else if (vdef(REPORT)) |
106 |
+ |
report(0); |
107 |
+ |
} |
108 |
+ |
|
109 |
+ |
|
110 |
+ |
getradfile() /* run rad and get needed variables */ |
111 |
+ |
{ |
112 |
+ |
static short mvar[] = {OCTREE,-1}; |
113 |
+ |
static char tf1[] = TEMPLATE; |
114 |
+ |
char tf2[64]; |
115 |
+ |
char combuf[256]; |
116 |
+ |
char *pippt; |
117 |
+ |
register int i; |
118 |
+ |
register char *cp; |
119 |
+ |
/* check if rad file specified */ |
120 |
+ |
if (!vdef(RIF)) |
121 |
+ |
return; |
122 |
+ |
/* create rad command */ |
123 |
+ |
mktemp(tf1); |
124 |
+ |
sprintf(tf2, "%s.rif", tf1); |
125 |
+ |
sprintf(combuf, |
126 |
+ |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
127 |
+ |
vval(RIF), tf1); |
128 |
+ |
cp = combuf; |
129 |
+ |
while (*cp){ |
130 |
+ |
if (*cp == '|') pippt = cp; |
131 |
+ |
cp++; |
132 |
+ |
} /* match unset variables */ |
133 |
+ |
for (i = 0; mvar[i] >= 0; i++) |
134 |
+ |
if (!vdef(mvar[i])) { |
135 |
+ |
*cp++ = '|'; |
136 |
+ |
strcpy(cp, vnam(mvar[i])); |
137 |
+ |
while (*cp) cp++; |
138 |
+ |
pippt = NULL; |
139 |
+ |
} |
140 |
+ |
if (pippt != NULL) |
141 |
+ |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
142 |
+ |
else |
143 |
+ |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
144 |
+ |
if (system(combuf)) { |
145 |
+ |
unlink(tf2); /* clean up */ |
146 |
+ |
unlink(tf1); |
147 |
+ |
error(SYSTEM, "cannot execute rad command"); |
148 |
+ |
} |
149 |
+ |
if (pippt == NULL) { |
150 |
+ |
loadvars(tf2); /* load variables */ |
151 |
+ |
unlink(tf2); |
152 |
+ |
} |
153 |
+ |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
154 |
+ |
unlink(tf1); /* clean up */ |
155 |
+ |
} |
156 |
+ |
|
157 |
+ |
|
158 |
+ |
report(t) /* report progress so far */ |
159 |
+ |
time_t t; |
160 |
+ |
{ |
161 |
+ |
static time_t seconds2go = 1000000; |
162 |
+ |
|
163 |
+ |
if (t == 0L) |
164 |
+ |
t = time(NULL); |
165 |
+ |
sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n", |
166 |
+ |
npacksdone, nraysdone, (t-starttime)/3600.); |
167 |
+ |
eputs(errmsg); |
168 |
+ |
if (seconds2go == 1000000) |
169 |
+ |
seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L; |
170 |
+ |
if (seconds2go) |
171 |
+ |
reporttime = t + seconds2go; |
172 |
|
} |