ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo.c
(Generate patch)

Comparing ray/src/hd/rholo.c (file contents):
Revision 3.2 by gregl, Fri Oct 31 11:44:09 1997 UTC vs.
Revision 3.37 by gregl, Fri Jan 16 11:45:43 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 9 | Line 9 | 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  
# Line 19 | Line 24 | VARIABLE       vv[] = RHVINIT;         /* variable-value pairs */
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  
29   int     nowarn = 0;             /* turn warnings off? */
30  
26 double  expval = 1.;            /* global exposure value */
27
31   int     ncprocs = 0;            /* desired number of compute processes */
32  
33   char    *outdev = NULL;         /* output device name */
34  
35 + int     readinp = 0;            /* read commands from stdin */
36 +
37 + int     force = 0;              /* allow overwrite of holodeck */
38 +
39   time_t  starttime;              /* time we got started */
40   time_t  endtime;                /* time we should end by */
41   time_t  reporttime;             /* time for next report */
42  
43 + long    maxdisk;                /* maximum file space (bytes) */
44 +
45   int     rtargc = 1;             /* rtrace command */
46   char    *rtargv[128] = {"rtrace", NULL};
47  
48 + int     orig_mode = -1;         /* original file mode (-1 if unchanged) */
49 +
50   long    nraysdone = 0L;         /* number of rays done */
51   long    npacksdone = 0L;        /* number of packets done */
52  
53   PACKET  *freepacks;             /* available packets */
54 + int     avgqlen;                /* average queue length when full */
55  
56 + char  *sigerr[NSIG];            /* signal error messages */
57 +
58   extern time_t   time();
59  
60  
# Line 48 | Line 62 | main(argc, argv)
62   int     argc;
63   char    *argv[];
64   {
51        HDGRID  hdg;
65          int     i;
53        int     force = 0;
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]) {
# Line 61 | Line 74 | char   *argv[];
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;
# Line 74 | Line 90 | char   *argv[];
90                  default:
91                          goto userr;
92                  }
77                                                /* do we have a job? */
78        if (outdev == NULL && ncprocs <= 0)
79                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();
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   }
140  
141  
142 + onsig(signo)                            /* fatal signal */
143 + int  signo;
144 + {
145 +        static int  gotsig = 0;
146 +
147 +        if (gotsig++)                   /* two signals and we're gone! */
148 +                _exit(signo);
149 +
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]);
154 +        eputs("\n");
155 +        quit(3);
156 + }
157 +
158 +
159 + sigdie(signo, msg)                      /* set fatal signal */
160 + int  signo;
161 + char  *msg;
162 + {
163 +        if (signal(signo, onsig) == SIG_IGN)
164 +                signal(signo, SIG_IGN);
165 +        sigerr[signo] = msg;
166 + }
167 +
168 +
169 + int
170 + resfmode(fd, mod)               /* restrict open file access mode */
171 + int     fd, mod;
172 + {
173 +        struct stat     stbuf;
174 +                                        /* get original mode */
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 & 0777))
179 +                return(-1);             /* already set */
180 +                                        /* else change it */
181 +        if (fchmod(fd, mod) < 0) {
182 +                error(WARNING, "cannot change holodeck file access mode");
183 +                return(-1);
184 +        }
185 +        return(stbuf.st_mode);          /* return original mode */
186 + }
187 +
188 +
189   initrholo()                     /* get our holodeck running */
190   {
191          extern int      global_packet();
192          register int    i;
193 <                                                /* check output device */
194 <        if (outdev != NULL)
195 <                open_display(outdev);
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);
198          else if (ncprocs > 0)                   /* else use global ray feed */
199                  init_global();
200 <                                                /* record the time */
201 <        starttime = time(NULL);
202 <        if (!vdef(TIME) || vflt(TIME) <= FTINY)
134 <                endtime = 0;
200 >                                                /* record disk space limit */
201 >        if (!vdef(DISKSPACE))
202 >                maxdisk = 0;
203          else
204 <                endtime = starttime + vflt(TIME)*3600.;
204 >                maxdisk = 1024.*1024.*vflt(DISKSPACE);
205                                                  /* set up memory cache */
206 <        hdcachesize = 1024.*1024.*vflt(CACHE);
206 >        if (outdev == NULL)
207 >                hdcachesize = 0;        /* manual flushing */
208 >        else if (vdef(CACHE))
209 >                hdcachesize = 1024.*1024.*vflt(CACHE);
210                                                  /* open report file */
211          if (vdef(REPORT)) {
212                  register char   *s = sskip2(vval(REPORT), 1);
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();
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);
# Line 155 | Line 233 | initrholo()                    /* get our holodeck running */
233                  freepacks = (PACKET *)bmalloc(i*sizeof(PACKET));
234                  if (freepacks == NULL)
235                          goto memerr;
236 +                if (!(avgqlen = i/nprocs))      /* record mean queue length */
237 +                        avgqlen = 1;
238                  freepacks[--i].nr = 0;
239                  freepacks[i].next = NULL;
240 <                if (!vbool(OBSTRUCTIONS)) {
240 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
241                          freepacks[i].offset = (float *)bmalloc(
242                                          RPACKSIZ*sizeof(float)*(i+1) );
243                          if (freepacks[i].offset == NULL)
# Line 171 | Line 251 | initrholo()                    /* get our holodeck running */
251                          freepacks[i].next = &freepacks[i+1];
252                  }
253          }
254 +                                        /* set up signal handling */
255 +        sigdie(SIGINT, "Interrupt");
256 +        sigdie(SIGHUP, "Hangup");
257 +        sigdie(SIGTERM, "Terminate");
258 +        sigdie(SIGPIPE, "Broken pipe");
259 +        sigdie(SIGALRM, "Alarm clock");
260 + #ifdef  SIGXCPU
261 +        sigdie(SIGXCPU, "CPU limit exceeded");
262 +        sigdie(SIGXFSZ, "File size exceeded");
263 + #endif
264 +                                                /* protect holodeck file */
265 +        orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
266          return;
267   memerr:
268          error(SYSTEM, "out of memory in initrholo");
# Line 179 | Line 271 | memerr:
271  
272   rholo()                         /* holodeck main loop */
273   {
274 <        static int      idle = 1;
274 >        static int      idle = 0;
275          PACKET  *pl = NULL, *plend;
276 +        int     pksiz;
277          register PACKET *p;
278          time_t  t;
186        long    l;
279                                          /* check display */
280 <        if (outdev != NULL && !disp_check(idle))
281 <                return(0);
282 <                                        /* display only? */
283 <        if (ncprocs <= 0)
284 <                return(1);
280 >        if (nprocs <= 0)
281 >                idle = 1;
282 >        if (outdev != NULL) {
283 >                if (!disp_check(idle))
284 >                        return(0);      /* quit request */
285 >                if (nprocs <= 0)
286 >                        return(1);
287 >        } else if (idle)
288 >                return(0);              /* all done */
289                                          /* check file size */
290 <        if ((l = 1024.*1024.*vflt(DISKSPACE)) > 0 &&
291 <                        hdfiluse(hdlist[0]->fd, 0) + hdmemuse(0) >= l)
292 <                return(0);
293 <                                        /* check time */
294 <        if (endtime > 0 || vdef(REPORT))
295 <                t = time(NULL);
296 <        if (endtime > 0 && t >= endtime)
297 <                return(0);
298 <        if (vdef(REPORT) && t >= reporttime)
290 >        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
291 >                error(WARNING, "file limit exceeded");
292 >                done_rtrace();
293 >                return(1);      /* comes back */
294 >        }
295 >        t = time(NULL);                 /* check time */
296 >        if (endtime > 0 && t >= endtime) {
297 >                error(WARNING, "time limit exceeded");
298 >                done_rtrace();
299 >                return(1);      /* comes back */
300 >        }
301 >        if (reporttime > 0 && t >= reporttime)
302                  report(t);
303 <                                        /* get packets to process */
303 >                                        /* figure out good packet size */
304 > #if MAXQTIME
305 >        pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L));
306 >        if (pksiz < 1)
307 >                pksiz = 1;
308 >        else if (pksiz > RPACKSIZ)
309 > #endif
310 >                pksiz = RPACKSIZ;
311 >        idle = 0;                       /* get packets to process */
312          while (freepacks != NULL) {
313                  p = freepacks; freepacks = p->next; p->next = NULL;
314 <                if (!next_packet(p)) {
314 >                if (!next_packet(p, pksiz)) {
315                          p->next = freepacks; freepacks = p;
316 +                        idle = 1;
317                          break;
318                  }
319                  if (pl == NULL) pl = p;
320                  else plend->next = p;
321                  plend = p;
322          }
323 <        idle = pl == NULL && freepacks != NULL;
216 <                                        /* are we out of stuff to do? */
217 <        if (idle && outdev == NULL)
218 <                return(0);
219 <                                        /* else process packets */
323 >                                        /* process packets */
324          done_packets(do_packets(pl));
325          return(1);                      /* and continue */
326   }
327  
328  
225 report(t)                       /* report progress so far */
226 time_t  t;
227 {
228        if (t == 0)
229                t = time(NULL);
230        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
231                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
232        fflush(stderr);
233        reporttime = t + (time_t)(vflt(REPORT)*60.);
234 }
235
236
329   setdefaults(gp)                 /* set default values */
330   register HDGRID *gp;
331   {
332          extern char     *atos();
333          register int    i;
334 <        double  len[3], maxlen, d;
334 >        int     n;
335 >        double  len[3], d;
336          char    buf[64];
337  
338          if (!vdef(SECTION)) {
339                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
340                  error(USER, errmsg);
341          }
249        if (vdef(SECTION) > 1) {
250                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
251                error(WARNING, errmsg);
252        }
253        if (sscanf(vval(SECTION),
254                        "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
255                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
256                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
257                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
258                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12)
259                badvalue(SECTION);
260        maxlen = 0.;
261        for (i = 0; i < 3; i++)
262                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
263                        maxlen = len[i];
264        if (!vdef(GRID)) {
265                sprintf(buf, "%.4f", maxlen/8.);
266                vval(GRID) = savqstr(buf);
267                vdef(GRID)++;
268        }
269        if ((d = vflt(GRID)) <= FTINY)
270                badvalue(GRID);
271        for (i = 0; i < 3; i++)
272                gp->grid[i] = len[i]/d + (1.-FTINY);
273        if (!vdef(EXPOSURE)) {
274                sprintf(errmsg, "%s must be defined", vnam(EXPOSURE));
275                error(USER, errmsg);
276        }
277        expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ?
278                        pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE);
342          if (!vdef(OCTREE)) {
343                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
344                          error(SYSTEM, "out of memory");
345                  sprintf(vval(OCTREE), "%s.oct", froot);
346                  vdef(OCTREE)++;
347          }
348 <        if (!vdef(DISKSPACE)) {
349 <                sprintf(errmsg,
350 <                        "no %s setting, assuming 100 Mbytes available",
288 <                                vnam(DISKSPACE));
289 <                error(WARNING, errmsg);
290 <                vval(DISKSPACE) = "100";
291 <                vdef(DISKSPACE)++;
348 >        if (!vdef(VDIST)) {
349 >                vval(VDIST) = "F";
350 >                vdef(VDIST)++;
351          }
293        if (!vdef(CACHE)) {
294                sprintf(errmsg,
295                        "no %s setting, assuming 10 Mbytes available",
296                                vnam(CACHE));
297                error(WARNING, errmsg);
298                vval(CACHE) = "10";
299                vdef(CACHE)++;
300        }
301        if (!vdef(OBSTRUCTIONS)) {
302                vval(OBSTRUCTIONS) = "T";
303                vdef(OBSTRUCTIONS)++;
304        }
305        if (!vdef(OCCUPANCY)) {
306                vval(OCCUPANCY) = "U";
307                vdef(OCCUPANCY)++;
308        }
352                                  /* append rendering options */
353          if (vdef(RENDER))
354                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
355 +        
356 +        if (gp == NULL)         /* already initialized? */
357 +                return;
358 +                                /* set grid parameters */
359 +        for (n = 0; n < vdef(SECTION); n++, gp++) {
360 +                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
361 +                if (sscanf(nvalue(SECTION, n),
362 +                "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
363 +                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
364 +                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
365 +                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
366 +                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
367 +                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
368 +                        badvalue(SECTION);
369 +                for (i = 0; i < 3; i++)
370 +                        len[i] = VLEN(gp->xv[i]);
371 +                if (!vdef(GRID)) {
372 +                        d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] +
373 +                                        len[2]*len[2] + 4*len[1]*len[2])
374 +                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
375 +                                + 4*len[0]*len[1]*len[2]*len[2] );
376 +                        d = sqrt(sqrt(d));
377 +                } else if ((d = vflt(GRID)) <= FTINY)
378 +                        badvalue(GRID);
379 +                for (i = 0; i < 3; i++)
380 +                        if (gp->grid[i] <= 0)
381 +                                gp->grid[i] = len[i]/d + (1.-FTINY);
382 +        }
383   }
384  
385  
386   creatholo(gp)                   /* create a holodeck output file */
387   HDGRID  *gp;
388   {
389 <        long    endloc = 0;
389 >        extern char     VersionID[];
390 >        int4    lastloc, nextloc;
391 >        int     n;
392 >        int     fd;
393          FILE    *fp;
394                                          /* open & truncate file */
395          if ((fp = fopen(hdkfile, "w+")) == NULL) {
# Line 324 | Line 398 | HDGRID *gp;
398          }
399                                          /* write information header */
400          newheader("RADIANCE", fp);
401 +        fprintf(fp, "SOFTWARE= %s\n", VersionID);
402          printvars(fp);
403          fputformat(HOLOFMT, fp);
404          fputc('\n', fp);
405 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
406 <        fwrite(&endloc, sizeof(long), 1, fp);
407 <        fflush(fp);                     /* flush buffer */
408 <        hdinit(fileno(fp), gp);         /* allocate and initialize index */
409 <                        /* we're dropping fp here.... */
405 >        putw(HOLOMAGIC, fp);            /* put magic number */
406 >        fd = dup(fileno(fp));
407 >        fclose(fp);                     /* flush and close stdio stream */
408 >        lastloc = lseek(fd, 0L, 2);
409 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
410 >                nextloc = 0L;
411 >                write(fd, (char *)&nextloc, sizeof(nextloc));
412 >                hdinit(fd, gp);                 /* writes beam index */
413 >                if (!n)
414 >                        break;
415 >                nextloc = hdfilen(fd);          /* write section pointer */
416 >                if (lseek(fd, (long)lastloc, 0) < 0)
417 >                        error(SYSTEM,
418 >                                "cannot seek on holodeck file in creatholo");
419 >                write(fd, (char *)&nextloc, sizeof(nextloc));
420 >                lseek(fd, (long)(lastloc=nextloc), 0);
421 >        }
422   }
423  
424  
# Line 361 | Line 448 | char   *s;
448  
449   loadholo()                      /* start loading a holodeck from fname */
450   {
451 +        extern long     ftell();
452          FILE    *fp;
453 <        long    endloc;
454 <                                        /* open input file */
455 <        if ((fp = fopen(hdkfile, "r+")) == NULL) {
456 <                sprintf(errmsg, "cannot open \"%s\" for appending", hdkfile);
453 >        int     fd;
454 >        int     n;
455 >        int4    nextloc;
456 >                                        /* open holodeck file */
457 >        if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
458 >                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
459 >                                ncprocs>0 ? "appending" : "reading");
460                  error(SYSTEM, errmsg);
461          }
462                                          /* load variables from header */
# Line 376 | Line 467 | loadholo()                     /* start loading a holodeck from fname */
467                                  hdkfile);
468                  error(USER, errmsg);
469          }
470 <        fread(&endloc, sizeof(long), 1, fp);
471 <        if (endloc != 0)
472 <                error(WARNING, "ignoring multiple sections in holodeck file");
473 <        fseek(fp, 0L, 1);                       /* align system file pointer */
474 <        hdinit(fileno(fp), NULL);               /* allocate and load index */
475 <                        /* we're dropping fp here.... */
470 >        nextloc = ftell(fp);                    /* get stdio position */
471 >        fd = dup(fileno(fp));
472 >        fclose(fp);                             /* done with stdio */
473 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
474 >                lseek(fd, (long)nextloc, 0);
475 >                read(fd, (char *)&nextloc, sizeof(nextloc));
476 >                hdinit(fd, NULL);
477 >        }
478 >        if (n != vdef(SECTION)) {
479 >                sprintf(errmsg, "number of sections does not match %s setting",
480 >                                vnam(SECTION));
481 >                error(WARNING, errmsg);
482 >        }
483   }
484  
485  
486   done_packets(pl)                /* handle finished packets */
487   PACKET  *pl;
488   {
489 +        static int      n2flush = 0;
490          register PACKET *p;
491  
492          while (pl != NULL) {
# Line 397 | Line 496 | PACKET *pl;
496                                  (char *)hdnewrays(hdlist[p->hd],p->bi,p->nr),
497                                  p->nr*sizeof(RAYVAL));
498                          if (outdev != NULL)     /* display it */
499 <                                disp_packet(p);
499 >                                disp_packet((PACKHEAD *)p);
500 >                        if (hdcachesize <= 0)   /* manual flushing */
501 >                                n2flush++;
502 >                        nraysdone += p->nr;
503 >                        npacksdone++;
504 >                        p->nr = 0;
505                  }
506 <                nraysdone += p->nr;
403 <                npacksdone++;
404 <                p->nr = 0;                      /* push onto free list */
405 <                p->next = freepacks;
506 >                p->next = freepacks;            /* push onto free list */
507                  freepacks = p;
508          }
509 < }
510 <
511 <
411 < getradfile(rfargs)              /* run rad and get needed variables */
412 < char    *rfargs;
413 < {
414 <        static short    mvar[] = {VIEW,OCTREE,EXPOSURE,-1};
415 <        static char     tf1[] = TEMPLATE;
416 <        char    tf2[64];
417 <        char    combuf[256];
418 <        register int    i;
419 <        register char   *cp;
420 <                                        /* create rad command */
421 <        mktemp(tf1);
422 <        sprintf(tf2, "%s.rif", tf1);
423 <        sprintf(combuf,
424 <                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
425 <                        rfargs, tf1);
426 <        cp = combuf;
427 <        while (*cp) cp++;               /* match unset variables */
428 <        for (i = 0; mvar[i] >= 0; i++)
429 <                if (!vdef(mvar[i])) {
430 <                        *cp++ = '|';
431 <                        strcpy(cp, vnam(mvar[i]));
432 <                        while (*cp) cp++;
433 <                }
434 <        sprintf(cp, ")[ \t]*=' > %s", tf2);
435 <        if (system(combuf)) {
436 <                error(SYSTEM, "cannot execute rad command");
437 <                unlink(tf2);                    /* clean up */
438 <                unlink(tf1);
439 <                quit(1);
509 >        if (n2flush > 300/MAXQTIME*avgqlen*nprocs) {
510 >                hdflush(NULL);                  /* flush holodeck buffers */
511 >                n2flush = 0;
512          }
441        loadvars(tf2);                  /* load variables */
442        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
443        unlink(tf2);                    /* clean up */
444        unlink(tf1);
513   }
514  
515  
# Line 451 | Line 519 | register char  *rn, *fn;
519          char    *tp, *dp;
520  
521          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
522 <                if (ISDIRSEP(*rn))
522 >                if (*rn == '/')
523                          dp = rn;
524                  else if (*rn == '.')
525                          tp = rn;
# Line 500 | Line 568 | int    ec;
568   {
569          int     status = 0;
570  
571 <        if (hdlist[0] != NULL) {        /* flush holodeck */
572 <                if (ncprocs > 0) {
573 <                        done_packets(flush_queue());
574 <                        status = end_rtrace();  /* close rtrace */
575 <                        hdflush(NULL);
576 <                        if (vdef(REPORT)) {
577 <                                long    fsiz, fuse;
578 <                                report(0);
579 <                                fsiz = lseek(hdlist[0]->fd, 0L, 2);
580 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
581 <                                fprintf(stderr,
582 <                        "%s: %.1f Mbyte holodeck file, %.2f%% fragmentation\n",
515 <                                                hdkfile, fsiz/(1024.*1024.),
516 <                                                100.*(fsiz-fuse)/fsiz);
517 <                        }
518 <                } else
519 <                        hdflush(NULL);
571 >        if (hdlist[0] != NULL) {        /* close holodeck */
572 >                if (nprocs > 0)
573 >                        status = done_rtrace();         /* calls hdsync() */
574 >                if (ncprocs > 0 && vdef(REPORT)) {
575 >                        long    fsiz, fuse;
576 >                        fsiz = hdfilen(hdlist[0]->fd);
577 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
578 >                        fprintf(stderr,
579 >                        "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
580 >                                        hdkfile, fsiz/(1024.*1024.),
581 >                                        100.*(fsiz-fuse)/fsiz);
582 >                }
583          }
584 +        if (orig_mode >= 0)             /* reset holodeck access mode */
585 +                fchmod(hdlist[0]->fd, orig_mode);
586 +        if (outdev != NULL)             /* close display */
587 +                disp_close();
588          exit(ec ? ec : status);         /* exit */
589   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines