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 |
|
/* the following must be consistent with rholo.h */ |
18 |
|
int NVARS = NRHVARS; /* total number of variables */ |
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 |
|
|
26 |
– |
double expval = 1.; /* global exposure value */ |
27 |
– |
|
28 |
|
int ncprocs = 0; /* desired number of compute processes */ |
29 |
|
|
30 |
|
char *outdev = NULL; /* output device name */ |
31 |
|
|
32 |
+ |
int readinp = 0; /* read commands from stdin */ |
33 |
+ |
|
34 |
+ |
int force = 0; /* allow overwrite of holodeck */ |
35 |
+ |
|
36 |
|
time_t starttime; /* time we got started */ |
37 |
|
time_t endtime; /* time we should end by */ |
38 |
|
time_t reporttime; /* time for next report */ |
42 |
|
int rtargc = 1; /* rtrace command */ |
43 |
|
char *rtargv[128] = {"rtrace", NULL}; |
44 |
|
|
45 |
+ |
int orig_mode = -1; /* original file mode (-1 if unchanged) */ |
46 |
+ |
|
47 |
|
long nraysdone = 0L; /* number of rays done */ |
48 |
|
long npacksdone = 0L; /* number of packets done */ |
49 |
|
|
50 |
|
PACKET *freepacks; /* available packets */ |
51 |
|
|
52 |
+ |
char *sigerr[NSIG]; /* signal error messages */ |
53 |
+ |
|
54 |
|
extern time_t time(); |
55 |
|
|
56 |
|
|
58 |
|
int argc; |
59 |
|
char *argv[]; |
60 |
|
{ |
53 |
– |
HDGRID hdg; |
61 |
|
int i; |
55 |
– |
int force = 0; |
62 |
|
/* mark start time */ |
63 |
|
starttime = time(NULL); |
64 |
+ |
initurand(16384); /* initialize urand */ |
65 |
|
progname = argv[0]; /* get arguments */ |
66 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
67 |
|
switch (argv[i][1]) { |
71 |
|
case 'f': /* force overwrite */ |
72 |
|
force++; |
73 |
|
break; |
74 |
+ |
case 'i': /* read input from stdin */ |
75 |
+ |
readinp++; |
76 |
+ |
break; |
77 |
|
case 'n': /* compute processes */ |
78 |
|
if (i >= argc-2) |
79 |
|
goto userr; |
87 |
|
default: |
88 |
|
goto userr; |
89 |
|
} |
80 |
– |
/* do we have a job? */ |
81 |
– |
if (outdev == NULL && ncprocs <= 0) |
82 |
– |
goto userr; |
90 |
|
/* get root file name */ |
91 |
|
rootname(froot, hdkfile=argv[i++]); |
92 |
< |
/* load... */ |
93 |
< |
if (i < argc) { /* variables */ |
94 |
< |
loadvars(argv[i++]); |
95 |
< |
/* cmdline settings */ |
96 |
< |
for ( ; i < argc; i++) |
97 |
< |
if (setvariable(argv[i], matchvar) < 0) { |
98 |
< |
sprintf(errmsg, "unknown variable: %s", |
99 |
< |
argv[i]); |
100 |
< |
error(USER, errmsg); |
101 |
< |
} |
102 |
< |
/* check settings */ |
103 |
< |
checkvalues(); |
104 |
< |
/* load RIF if any */ |
105 |
< |
if (vdef(RIF)) |
106 |
< |
getradfile(vval(RIF)); |
92 |
> |
/* load variables? */ |
93 |
> |
if (i < argc) |
94 |
> |
if (argv[i][0] != '-' && argv[i][0] != '+') |
95 |
> |
loadvars(argv[i]); /* load variables from file */ |
96 |
> |
|
97 |
> |
if (i >= argc || argv[i][0] == '+') |
98 |
> |
loadholo(); /* load existing holodeck */ |
99 |
> |
|
100 |
> |
while (++i < argc) /* get command line settings */ |
101 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
102 |
> |
sprintf(errmsg, "unknown variable: %s", argv[i]); |
103 |
> |
error(USER, errmsg); |
104 |
> |
} |
105 |
> |
/* check settings */ |
106 |
> |
checkvalues(); |
107 |
> |
/* load RIF if any */ |
108 |
> |
getradfile(); |
109 |
> |
|
110 |
> |
if (hdlist[0] == NULL) { /* create new holodeck */ |
111 |
> |
HDGRID hdg[HDMAX]; |
112 |
|
/* set defaults */ |
113 |
< |
setdefaults(&hdg); |
113 |
> |
setdefaults(hdg); |
114 |
|
/* holodeck exists? */ |
115 |
|
if (!force && access(hdkfile, R_OK|W_OK) == 0) |
116 |
|
error(USER, |
117 |
|
"holodeck file exists -- use -f to overwrite"); |
118 |
|
/* create holodeck */ |
119 |
< |
creatholo(&hdg); |
120 |
< |
} else { /* else load holodeck */ |
121 |
< |
loadholo(); |
110 |
< |
if (vdef(RIF)) /* load RIF if any */ |
111 |
< |
getradfile(vval(RIF)); |
112 |
< |
} |
119 |
> |
creatholo(hdg); |
120 |
> |
} else /* else just set defaults */ |
121 |
> |
setdefaults(NULL); |
122 |
|
/* initialize */ |
123 |
|
initrholo(); |
124 |
< |
/* run */ |
124 |
> |
/* main loop */ |
125 |
|
while (rholo()) |
126 |
|
; |
127 |
|
/* done */ |
128 |
|
quit(0); |
129 |
|
userr: |
130 |
|
fprintf(stderr, |
131 |
< |
"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
131 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
132 |
|
progname); |
133 |
|
quit(1); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
+ |
onsig(signo) /* fatal signal */ |
138 |
+ |
int signo; |
139 |
+ |
{ |
140 |
+ |
static int gotsig = 0; |
141 |
+ |
|
142 |
+ |
if (gotsig++) /* two signals and we're gone! */ |
143 |
+ |
_exit(signo); |
144 |
+ |
|
145 |
+ |
alarm(60); /* allow 60 seconds to clean up */ |
146 |
+ |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
147 |
+ |
eputs("signal - "); |
148 |
+ |
eputs(sigerr[signo]); |
149 |
+ |
eputs("\n"); |
150 |
+ |
quit(3); |
151 |
+ |
} |
152 |
+ |
|
153 |
+ |
|
154 |
+ |
sigdie(signo, msg) /* set fatal signal */ |
155 |
+ |
int signo; |
156 |
+ |
char *msg; |
157 |
+ |
{ |
158 |
+ |
if (signal(signo, onsig) == SIG_IGN) |
159 |
+ |
signal(signo, SIG_IGN); |
160 |
+ |
sigerr[signo] = msg; |
161 |
+ |
} |
162 |
+ |
|
163 |
+ |
|
164 |
+ |
int |
165 |
+ |
resfmode(fd, mod) /* restrict open file access mode */ |
166 |
+ |
int fd, mod; |
167 |
+ |
{ |
168 |
+ |
struct stat stbuf; |
169 |
+ |
/* get original mode */ |
170 |
+ |
if (fstat(fd, &stbuf) < 0) |
171 |
+ |
error(SYSTEM, "cannot stat open holodeck file"); |
172 |
+ |
mod &= stbuf.st_mode; /* always more restrictive */ |
173 |
+ |
if (mod == stbuf.st_mode) |
174 |
+ |
return(-1); /* already set */ |
175 |
+ |
/* else change it */ |
176 |
+ |
if (fchmod(fd, mod) < 0) { |
177 |
+ |
error(WARNING, "cannot change holodeck file access mode"); |
178 |
+ |
return(-1); |
179 |
+ |
} |
180 |
+ |
return(stbuf.st_mode); /* return original mode */ |
181 |
+ |
} |
182 |
+ |
|
183 |
+ |
|
184 |
|
initrholo() /* get our holodeck running */ |
185 |
|
{ |
186 |
|
extern int global_packet(); |
187 |
|
register int i; |
188 |
+ |
/* close holodeck on exec() */ |
189 |
+ |
fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); |
190 |
|
|
191 |
|
if (outdev != NULL) /* open output device */ |
192 |
|
disp_open(outdev); |
201 |
|
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
202 |
|
endtime = 0; |
203 |
|
else |
204 |
< |
endtime = starttime + vflt(TIME)*3600.; |
204 |
> |
endtime = starttime + vflt(TIME)*3600. + .5; |
205 |
|
/* set up memory cache */ |
206 |
|
if (outdev == NULL) |
207 |
|
hdcachesize = 0; /* manual flushing */ |
217 |
|
if (ncprocs > 0) { |
218 |
|
i = start_rtrace(); |
219 |
|
if (i < 1) |
220 |
< |
error(USER, "cannot start rtrace process"); |
220 |
> |
error(USER, "cannot start rtrace process(es)"); |
221 |
|
if (vdef(REPORT)) { /* make first report */ |
222 |
|
printargs(rtargc, rtargv, stderr); |
223 |
|
report(0); |
228 |
|
goto memerr; |
229 |
|
freepacks[--i].nr = 0; |
230 |
|
freepacks[i].next = NULL; |
231 |
< |
if (!vbool(OBSTRUCTIONS)) { |
231 |
> |
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
232 |
|
freepacks[i].offset = (float *)bmalloc( |
233 |
|
RPACKSIZ*sizeof(float)*(i+1) ); |
234 |
|
if (freepacks[i].offset == NULL) |
242 |
|
freepacks[i].next = &freepacks[i+1]; |
243 |
|
} |
244 |
|
} |
245 |
+ |
/* set up signal handling */ |
246 |
+ |
sigdie(SIGINT, "Interrupt"); |
247 |
+ |
sigdie(SIGHUP, "Hangup"); |
248 |
+ |
sigdie(SIGTERM, "Terminate"); |
249 |
+ |
sigdie(SIGPIPE, "Broken pipe"); |
250 |
+ |
sigdie(SIGALRM, "Alarm clock"); |
251 |
+ |
#ifdef SIGXCPU |
252 |
+ |
sigdie(SIGXCPU, "CPU limit exceeded"); |
253 |
+ |
sigdie(SIGXFSZ, "File size exceeded"); |
254 |
+ |
#endif |
255 |
+ |
/* protect holodeck file */ |
256 |
+ |
orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); |
257 |
|
return; |
258 |
|
memerr: |
259 |
|
error(SYSTEM, "out of memory in initrholo"); |
262 |
|
|
263 |
|
rholo() /* holodeck main loop */ |
264 |
|
{ |
265 |
< |
static int idle = 1; |
265 |
> |
static int idle = 0; |
266 |
|
PACKET *pl = NULL, *plend; |
267 |
|
register PACKET *p; |
268 |
|
time_t t; |
269 |
|
long l; |
270 |
< |
|
271 |
< |
if (outdev != NULL) /* check display */ |
270 |
> |
/* check display */ |
271 |
> |
if (nprocs <= 0) |
272 |
> |
idle = 1; |
273 |
> |
if (outdev != NULL) { |
274 |
|
if (!disp_check(idle)) |
275 |
< |
return(0); |
276 |
< |
/* display only? */ |
277 |
< |
if (ncprocs <= 0) |
278 |
< |
return(1); |
275 |
> |
return(0); /* quit request */ |
276 |
> |
if (nprocs <= 0) |
277 |
> |
return(1); |
278 |
> |
} else if (idle) |
279 |
> |
return(0); /* all done */ |
280 |
|
/* check file size */ |
281 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
282 |
|
error(WARNING, "file limit exceeded"); |
283 |
< |
return(0); |
283 |
> |
done_rtrace(); |
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 |
> |
return(1); /* comes back */ |
293 |
|
} |
294 |
|
if (reporttime > 0 && t >= reporttime) |
295 |
|
report(t); |
296 |
< |
/* get packets to process */ |
296 |
> |
idle = 0; /* get packets to process */ |
297 |
|
while (freepacks != NULL) { |
298 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
299 |
|
if (!next_packet(p)) { |
300 |
|
p->next = freepacks; freepacks = p; |
301 |
+ |
idle = 1; |
302 |
|
break; |
303 |
|
} |
304 |
|
if (pl == NULL) pl = p; |
305 |
|
else plend->next = p; |
306 |
|
plend = p; |
307 |
|
} |
308 |
< |
idle = pl == NULL && freepacks != NULL; |
233 |
< |
/* are we out of stuff to do? */ |
234 |
< |
if (idle && outdev == NULL) |
235 |
< |
return(0); |
236 |
< |
/* else process packets */ |
308 |
> |
/* process packets */ |
309 |
|
done_packets(do_packets(pl)); |
310 |
|
return(1); /* and continue */ |
311 |
|
} |
312 |
|
|
313 |
|
|
242 |
– |
report(t) /* report progress so far */ |
243 |
– |
time_t t; |
244 |
– |
{ |
245 |
– |
if (t == 0) |
246 |
– |
t = time(NULL); |
247 |
– |
fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", |
248 |
– |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
249 |
– |
fflush(stderr); |
250 |
– |
if (vdef(REPORT)) |
251 |
– |
reporttime = t + (time_t)(vflt(REPORT)*60.+.5); |
252 |
– |
} |
253 |
– |
|
254 |
– |
|
314 |
|
setdefaults(gp) /* set default values */ |
315 |
|
register HDGRID *gp; |
316 |
|
{ |
317 |
|
extern char *atos(); |
318 |
|
register int i; |
319 |
+ |
int n; |
320 |
|
double len[3], maxlen, d; |
321 |
|
char buf[64]; |
322 |
|
|
324 |
|
sprintf(errmsg, "%s must be defined", vnam(SECTION)); |
325 |
|
error(USER, errmsg); |
326 |
|
} |
267 |
– |
if (vdef(SECTION) > 1) { |
268 |
– |
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
269 |
– |
error(WARNING, errmsg); |
270 |
– |
} |
271 |
– |
if (sscanf(vval(SECTION), |
272 |
– |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", |
273 |
– |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
274 |
– |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
275 |
– |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
276 |
– |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12) |
277 |
– |
badvalue(SECTION); |
278 |
– |
maxlen = 0.; |
279 |
– |
for (i = 0; i < 3; i++) |
280 |
– |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
281 |
– |
maxlen = len[i]; |
282 |
– |
if (!vdef(GRID)) { |
283 |
– |
sprintf(buf, "%.4f", maxlen/8.); |
284 |
– |
vval(GRID) = savqstr(buf); |
285 |
– |
vdef(GRID)++; |
286 |
– |
} |
287 |
– |
if ((d = vflt(GRID)) <= FTINY) |
288 |
– |
badvalue(GRID); |
289 |
– |
for (i = 0; i < 3; i++) |
290 |
– |
gp->grid[i] = len[i]/d + (1.-FTINY); |
291 |
– |
if (!vdef(EXPOSURE)) { |
292 |
– |
sprintf(errmsg, "%s must be defined", vnam(EXPOSURE)); |
293 |
– |
error(USER, errmsg); |
294 |
– |
} |
295 |
– |
expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ? |
296 |
– |
pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE); |
327 |
|
if (!vdef(OCTREE)) { |
328 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
329 |
|
error(SYSTEM, "out of memory"); |
330 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
331 |
|
vdef(OCTREE)++; |
332 |
|
} |
333 |
< |
if (!vdef(OBSTRUCTIONS)) { |
334 |
< |
vval(OBSTRUCTIONS) = "T"; |
335 |
< |
vdef(OBSTRUCTIONS)++; |
333 |
> |
if (!vdef(VDIST)) { |
334 |
> |
vval(VDIST) = "F"; |
335 |
> |
vdef(VDIST)++; |
336 |
|
} |
307 |
– |
if (!vdef(OCCUPANCY)) { |
308 |
– |
vval(OCCUPANCY) = "U"; |
309 |
– |
vdef(OCCUPANCY)++; |
310 |
– |
} |
337 |
|
/* append rendering options */ |
338 |
|
if (vdef(RENDER)) |
339 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
340 |
+ |
|
341 |
+ |
if (gp == NULL) /* already initialized? */ |
342 |
+ |
return; |
343 |
+ |
/* set grid parameters */ |
344 |
+ |
for (n = 0; n < vdef(SECTION); n++, gp++) { |
345 |
+ |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
346 |
+ |
if (sscanf(nvalue(SECTION, n), |
347 |
+ |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
348 |
+ |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
349 |
+ |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
350 |
+ |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
351 |
+ |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
352 |
+ |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
353 |
+ |
badvalue(SECTION); |
354 |
+ |
maxlen = 0.; |
355 |
+ |
for (i = 0; i < 3; i++) |
356 |
+ |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
357 |
+ |
maxlen = len[i]; |
358 |
+ |
if (!vdef(GRID)) |
359 |
+ |
d = 0.125*maxlen; |
360 |
+ |
else if ((d = vflt(GRID)) <= FTINY) |
361 |
+ |
badvalue(GRID); |
362 |
+ |
for (i = 0; i < 3; i++) |
363 |
+ |
if (gp->grid[i] <= 0) |
364 |
+ |
gp->grid[i] = len[i]/d + (1.-FTINY); |
365 |
+ |
} |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
|
creatholo(gp) /* create a holodeck output file */ |
370 |
|
HDGRID *gp; |
371 |
|
{ |
372 |
< |
long endloc = 0; |
372 |
> |
extern char VersionID[]; |
373 |
> |
int4 lastloc, nextloc; |
374 |
> |
int n; |
375 |
> |
int fd; |
376 |
|
FILE *fp; |
377 |
|
/* open & truncate file */ |
378 |
|
if ((fp = fopen(hdkfile, "w+")) == NULL) { |
381 |
|
} |
382 |
|
/* write information header */ |
383 |
|
newheader("RADIANCE", fp); |
384 |
+ |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
385 |
|
printvars(fp); |
386 |
|
fputformat(HOLOFMT, fp); |
387 |
|
fputc('\n', fp); |
388 |
< |
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
389 |
< |
fwrite(&endloc, sizeof(long), 1, fp); |
390 |
< |
fflush(fp); /* flush buffer */ |
391 |
< |
hdinit(fileno(fp), gp); /* allocate and initialize index */ |
392 |
< |
/* we're dropping fp here.... */ |
388 |
> |
putw(HOLOMAGIC, fp); /* put magic number */ |
389 |
> |
fd = dup(fileno(fp)); |
390 |
> |
fclose(fp); /* flush and close stdio stream */ |
391 |
> |
lastloc = lseek(fd, 0L, 2); |
392 |
> |
for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ |
393 |
> |
nextloc = 0L; |
394 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
395 |
> |
hdinit(fd, gp); /* writes beam index */ |
396 |
> |
if (!n) |
397 |
> |
break; |
398 |
> |
nextloc = hdfilen(fd); /* write section pointer */ |
399 |
> |
if (lseek(fd, (long)lastloc, 0) < 0) |
400 |
> |
error(SYSTEM, |
401 |
> |
"cannot seek on holodeck file in creatholo"); |
402 |
> |
write(fd, (char *)&nextloc, sizeof(nextloc)); |
403 |
> |
lseek(fd, (long)(lastloc=nextloc), 0); |
404 |
> |
} |
405 |
|
} |
406 |
|
|
407 |
|
|
431 |
|
|
432 |
|
loadholo() /* start loading a holodeck from fname */ |
433 |
|
{ |
434 |
+ |
extern long ftell(); |
435 |
|
FILE *fp; |
436 |
< |
long endloc; |
436 |
> |
int fd; |
437 |
> |
int n; |
438 |
> |
int4 nextloc; |
439 |
|
/* open holodeck file */ |
440 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
441 |
|
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
450 |
|
hdkfile); |
451 |
|
error(USER, errmsg); |
452 |
|
} |
453 |
< |
fread(&endloc, sizeof(long), 1, fp); |
454 |
< |
if (endloc != 0) |
455 |
< |
error(WARNING, "ignoring multiple sections in holodeck file"); |
456 |
< |
fseek(fp, 0L, 1); /* align system file pointer */ |
457 |
< |
hdinit(fileno(fp), NULL); /* allocate and load index */ |
458 |
< |
/* we're dropping fp here.... */ |
453 |
> |
nextloc = ftell(fp); /* get stdio position */ |
454 |
> |
fd = dup(fileno(fp)); |
455 |
> |
fclose(fp); /* done with stdio */ |
456 |
> |
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
457 |
> |
lseek(fd, (long)nextloc, 0); |
458 |
> |
read(fd, (char *)&nextloc, sizeof(nextloc)); |
459 |
> |
hdinit(fd, NULL); |
460 |
> |
} |
461 |
> |
if (n != vdef(SECTION)) { |
462 |
> |
sprintf(errmsg, "number of sections does not match %s setting", |
463 |
> |
vnam(SECTION)); |
464 |
> |
error(WARNING, errmsg); |
465 |
> |
} |
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
|
done_packets(pl) /* handle finished packets */ |
470 |
|
PACKET *pl; |
471 |
|
{ |
472 |
< |
static int nunflushed = 0; |
472 |
> |
static int n2flush = 0; |
473 |
|
register PACKET *p; |
474 |
|
|
475 |
|
while (pl != NULL) { |
480 |
|
p->nr*sizeof(RAYVAL)); |
481 |
|
if (outdev != NULL) /* display it */ |
482 |
|
disp_packet((PACKHEAD *)p); |
483 |
< |
else |
484 |
< |
nunflushed += p->nr; |
483 |
> |
if (hdcachesize <= 0) /* manual flushing */ |
484 |
> |
n2flush += p->nr; |
485 |
|
nraysdone += p->nr; |
486 |
|
npacksdone++; |
487 |
|
} |
489 |
|
p->next = freepacks; |
490 |
|
freepacks = p; |
491 |
|
} |
492 |
< |
if (nunflushed >= 256*RPACKSIZ) { |
492 |
> |
if (n2flush > 1024*RPACKSIZ*nprocs) { |
493 |
|
hdflush(NULL); /* flush holodeck buffers */ |
494 |
< |
nunflushed = 0; |
494 |
> |
n2flush = 0; |
495 |
|
} |
496 |
|
} |
497 |
|
|
498 |
|
|
421 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
422 |
– |
char *rfargs; |
423 |
– |
{ |
424 |
– |
static short mvar[] = {OCTREE,EXPOSURE,-1}; |
425 |
– |
static char tf1[] = TEMPLATE; |
426 |
– |
char tf2[64]; |
427 |
– |
char combuf[256]; |
428 |
– |
char *pippt; |
429 |
– |
register int i; |
430 |
– |
register char *cp; |
431 |
– |
/* create rad command */ |
432 |
– |
mktemp(tf1); |
433 |
– |
sprintf(tf2, "%s.rif", tf1); |
434 |
– |
sprintf(combuf, |
435 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
436 |
– |
rfargs, tf1); |
437 |
– |
cp = combuf; |
438 |
– |
while (*cp){ |
439 |
– |
if (*cp == '|') pippt = cp; |
440 |
– |
cp++; |
441 |
– |
} /* match unset variables */ |
442 |
– |
for (i = 0; mvar[i] >= 0; i++) |
443 |
– |
if (!vdef(mvar[i])) { |
444 |
– |
*cp++ = '|'; |
445 |
– |
strcpy(cp, vnam(mvar[i])); |
446 |
– |
while (*cp) cp++; |
447 |
– |
pippt = NULL; |
448 |
– |
} |
449 |
– |
if (pippt != NULL) |
450 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
451 |
– |
else |
452 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
453 |
– |
if (system(combuf)) { |
454 |
– |
error(SYSTEM, "cannot execute rad command"); |
455 |
– |
unlink(tf2); /* clean up */ |
456 |
– |
unlink(tf1); |
457 |
– |
quit(1); |
458 |
– |
} |
459 |
– |
if (pippt == NULL) { |
460 |
– |
loadvars(tf2); /* load variables */ |
461 |
– |
unlink(tf2); |
462 |
– |
} |
463 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
464 |
– |
unlink(tf1); /* clean up */ |
465 |
– |
} |
466 |
– |
|
467 |
– |
|
499 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
500 |
|
register char *rn, *fn; |
501 |
|
{ |
502 |
|
char *tp, *dp; |
503 |
|
|
504 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
505 |
< |
if (ISDIRSEP(*rn)) |
505 |
> |
if (*rn == '/') |
506 |
|
dp = rn; |
507 |
|
else if (*rn == '.') |
508 |
|
tp = rn; |
551 |
|
{ |
552 |
|
int status = 0; |
553 |
|
|
554 |
< |
if (outdev != NULL) /* close display */ |
555 |
< |
disp_close(); |
556 |
< |
if (hdlist[0] != NULL) { /* flush holodeck */ |
557 |
< |
if (ncprocs > 0) { |
558 |
< |
done_packets(flush_queue()); |
559 |
< |
status = end_rtrace(); /* close rtrace */ |
560 |
< |
hdflush(NULL); |
561 |
< |
if (vdef(REPORT)) { |
531 |
< |
long fsiz, fuse; |
532 |
< |
report(0); |
533 |
< |
fsiz = hdfilen(hdlist[0]->fd); |
534 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
535 |
< |
fprintf(stderr, |
554 |
> |
if (hdlist[0] != NULL) { /* close holodeck */ |
555 |
> |
if (nprocs > 0) |
556 |
> |
status = done_rtrace(); /* calls hdsync() */ |
557 |
> |
if (ncprocs > 0 && vdef(REPORT)) { |
558 |
> |
long fsiz, fuse; |
559 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
560 |
> |
fuse = hdfiluse(hdlist[0]->fd, 1); |
561 |
> |
fprintf(stderr, |
562 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
563 |
< |
hdkfile, fsiz/(1024.*1024.), |
564 |
< |
100.*(fsiz-fuse)/fsiz); |
565 |
< |
} |
540 |
< |
} else |
541 |
< |
hdflush(NULL); |
563 |
> |
hdkfile, fsiz/(1024.*1024.), |
564 |
> |
100.*(fsiz-fuse)/fsiz); |
565 |
> |
} |
566 |
|
} |
567 |
+ |
if (orig_mode >= 0) /* reset holodeck access mode */ |
568 |
+ |
fchmod(hdlist[0]->fd, orig_mode); |
569 |
+ |
if (outdev != NULL) /* close display */ |
570 |
+ |
disp_close(); |
571 |
|
exit(ec ? ec : status); /* exit */ |
572 |
|
} |