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.1 by gregl, Fri Oct 31 10:23:29 1997 UTC vs.
Revision 3.6 by gregl, Thu Nov 6 09:49:24 1997 UTC

# Line 51 | Line 51 | char   *argv[];
51          HDGRID  hdg;
52          int     i;
53          int     force = 0;
54 <
54 >                                                /* mark start time */
55 >        starttime = time(NULL);
56          progname = argv[0];                     /* get arguments */
57          for (i = 1; i < argc && argv[i][0] == '-'; i++)
58                  switch (argv[i][1]) {
# Line 102 | Line 103 | char   *argv[];
103                                  "holodeck file exists -- use -f to overwrite");
104                                                          /* create holodeck */
105                  creatholo(&hdg);
106 <        } else                                  /* else load holodeck */
106 >        } else {                                /* else load holodeck */
107                  loadholo();
108 +                if (vdef(RIF))                          /* load RIF if any */
109 +                        getradfile(vval(RIF));
110 +        }
111                                                  /* initialize */
112          initrholo();
113                                                  /* run */
# Line 123 | Line 127 | initrholo()                    /* get our holodeck running */
127   {
128          extern int      global_packet();
129          register int    i;
130 <                                                /* check output device */
131 <        if (outdev != NULL)
132 <                open_display(outdev);
130 >
131 >        if (outdev != NULL)                     /* open output device */
132 >                disp_open(outdev);
133          else if (ncprocs > 0)                   /* else use global ray feed */
134                  init_global();
135 <                                                /* record the time */
132 <        starttime = time(NULL);
135 >                                                /* record end time */
136          if (!vdef(TIME) || vflt(TIME) <= FTINY)
137                  endtime = 0;
138          else
139                  endtime = starttime + vflt(TIME)*3600.;
140                                                  /* set up memory cache */
141 <        hdcachesize = 1024.*1024.*vflt(CACHE);
141 >        if (outdev == NULL)
142 >                hdcachesize = 0;        /* manual flushing */
143 >        else if (vdef(CACHE))
144 >                hdcachesize = 1024.*1024.*vflt(CACHE);
145                                                  /* open report file */
146          if (vdef(REPORT)) {
147                  register char   *s = sskip2(vval(REPORT), 1);
# Line 184 | Line 190 | rholo()                                /* holodeck main loop */
190          register PACKET *p;
191          time_t  t;
192          long    l;
193 <                                        /* check display */
194 <        if (outdev != NULL && !disp_check(idle))
195 <                return(0);
193 >
194 >        if (outdev != NULL)             /* check display */
195 >                if (!disp_check(idle))
196 >                        return(0);
197                                          /* display only? */
198          if (ncprocs <= 0)
199                  return(1);
200                                          /* check file size */
201 <        if (l = 1024.*1024.*vflt(DISKSPACE) > 0 &&
201 >        if ((l = 1024.*1024.*vflt(DISKSPACE)) > 0 &&
202                          hdfiluse(hdlist[0]->fd, 0) + hdmemuse(0) >= l)
203                  return(0);
204                                          /* check time */
205 <        if (endtime > 0 || vdef(REPORT))
205 >        if (endtime > 0 || reporttime > 0)
206                  t = time(NULL);
207          if (endtime > 0 && t >= endtime)
208                  return(0);
209 <        if (vdef(REPORT) && t >= reporttime)
209 >        if (reporttime > 0 && t >= reporttime)
210                  report(t);
211                                          /* get packets to process */
212          while (freepacks != NULL) {
# Line 227 | Line 234 | time_t t;
234   {
235          if (t == 0)
236                  t = time(NULL);
237 <        fprintf(stderr, "%s: %ld packets done (%ld rays) after %.2f hours\n",
237 >        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
238                          progname, npacksdone, nraysdone, (t-starttime)/3600.);
239 +        fflush(stderr);
240 +        if (vdef(REPORT))
241 +                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
242   }
243  
244  
# Line 260 | Line 270 | register HDGRID        *gp;
270                  if ((len[i] = VLEN(gp->xv[i])) > maxlen)
271                          maxlen = len[i];
272          if (!vdef(GRID)) {
273 <                sprintf(buf, "%.4f", maxlen/16.);
273 >                sprintf(buf, "%.4f", maxlen/8.);
274                  vval(GRID) = savqstr(buf);
275                  vdef(GRID)++;
276          }
# Line 288 | Line 298 | register HDGRID        *gp;
298                  vval(DISKSPACE) = "100";
299                  vdef(DISKSPACE)++;
300          }
291        if (!vdef(CACHE)) {
292                sprintf(errmsg,
293                        "no %s setting, assuming 10 Mbytes available",
294                                vnam(CACHE));
295                error(WARNING, errmsg);
296                vval(CACHE) = "10";
297                vdef(CACHE)++;
298        }
301          if (!vdef(OBSTRUCTIONS)) {
302                  vval(OBSTRUCTIONS) = "T";
303                  vdef(OBSTRUCTIONS)++;
# Line 328 | Line 330 | HDGRID *gp;
330          putw(HOLOMAGIC, fp);            /* put magic number & terminus */
331          fwrite(&endloc, sizeof(long), 1, fp);
332          fflush(fp);                     /* flush buffer */
333 <        initholo(fileno(fp), gp);       /* allocate and initialize index */
333 >        hdinit(fileno(fp), gp);         /* allocate and initialize index */
334                          /* we're dropping fp here.... */
335   }
336  
# Line 340 | Line 342 | char   *s;
342          register char   *cp;
343          char    fmt[32];
344  
345 <        if (headidval(fmt, s)) {
345 >        if (formatval(fmt, s)) {
346                  if (strcmp(fmt, HOLOFMT)) {
347                          sprintf(errmsg, "%s file \"%s\" has %s%s",
348                                          HOLOFMT, hdkfile, FMTSTR, fmt);
# Line 361 | Line 363 | loadholo()                     /* start loading a holodeck from fname */
363   {
364          FILE    *fp;
365          long    endloc;
366 <                                        /* open input file */
367 <        if ((fp = fopen(hdkfile, "r+")) == NULL) {
368 <                sprintf(errmsg, "cannot open \"%s\" for appending", hdkfile);
366 >                                        /* open holodeck file */
367 >        if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
368 >                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
369 >                                ncprocs>0 ? "appending" : "reading");
370                  error(SYSTEM, errmsg);
371          }
372                                          /* load variables from header */
# Line 378 | Line 381 | loadholo()                     /* start loading a holodeck from fname */
381          if (endloc != 0)
382                  error(WARNING, "ignoring multiple sections in holodeck file");
383          fseek(fp, 0L, 1);                       /* align system file pointer */
384 <        initholo(fileno(fp), NULL);             /* allocate and load index */
384 >        hdinit(fileno(fp), NULL);               /* allocate and load index */
385                          /* we're dropping fp here.... */
386   }
387  
# Line 386 | Line 389 | loadholo()                     /* start loading a holodeck from fname */
389   done_packets(pl)                /* handle finished packets */
390   PACKET  *pl;
391   {
392 +        static int      nunflushed = 0;
393          register PACKET *p;
394  
395          while (pl != NULL) {
# Line 396 | Line 400 | PACKET *pl;
400                                  p->nr*sizeof(RAYVAL));
401                          if (outdev != NULL)     /* display it */
402                                  disp_packet(p);
403 +                        else
404 +                                nunflushed += p->nr;
405 +                        nraysdone += p->nr;
406 +                        npacksdone++;
407                  }
400                nraysdone += p->nr;
401                npacksdone++;
408                  p->nr = 0;                      /* push onto free list */
409                  p->next = freepacks;
410                  freepacks = p;
411          }
412 +        if (nunflushed >= 256*RPACKSIZ) {
413 +                hdflush(NULL);                  /* flush holodeck buffers */
414 +                nunflushed = 0;
415 +        }
416   }
417  
418  
419   getradfile(rfargs)              /* run rad and get needed variables */
420   char    *rfargs;
421   {
422 <        static short    mvar[] = {VIEW,OCTREE,EXPOSURE,REPORT,-1};
422 >        static short    mvar[] = {VIEW,OCTREE,EXPOSURE,-1};
423          static char     tf1[] = TEMPLATE;
424          char    tf2[64];
425          char    combuf[256];
426 +        char    *pippt;
427          register int    i;
428          register char   *cp;
429                                          /* create rad command */
# Line 422 | Line 433 | char   *rfargs;
433                  "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
434                          rfargs, tf1);
435          cp = combuf;
436 <        while (*cp) cp++;               /* match unset variables */
436 >        while (*cp){
437 >                if (*cp == '|') pippt = cp;
438 >                cp++;
439 >        }                               /* match unset variables */
440          for (i = 0; mvar[i] >= 0; i++)
441                  if (!vdef(mvar[i])) {
442                          *cp++ = '|';
443                          strcpy(cp, vnam(mvar[i]));
444                          while (*cp) cp++;
445 +                        pippt = NULL;
446                  }
447 <        sprintf(cp, ")[ \t]*=' > %s", tf2);
447 >        if (pippt != NULL)
448 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
449 >        else
450 >                sprintf(cp, ")[ \t]*=' > %s", tf2);
451          if (system(combuf)) {
452                  error(SYSTEM, "cannot execute rad command");
453                  unlink(tf2);                    /* clean up */
454                  unlink(tf1);
455                  quit(1);
456          }
457 <        loadvars(tf2);                  /* load variables */
457 >        if (pippt == NULL) {
458 >                loadvars(tf2);                  /* load variables */
459 >                unlink(tf2);
460 >        }
461          rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
462 <        unlink(tf2);                    /* clean up */
442 <        unlink(tf1);
462 >        unlink(tf1);                    /* clean up */
463   }
464  
465  
# Line 498 | Line 518 | int    ec;
518   {
519          int     status = 0;
520  
521 +        if (outdev != NULL)             /* close display */
522 +                disp_close();
523          if (hdlist[0] != NULL) {        /* flush holodeck */
524                  if (ncprocs > 0) {
525                          done_packets(flush_queue());
# Line 509 | Line 531 | int    ec;
531                                  fsiz = lseek(hdlist[0]->fd, 0L, 2);
532                                  fuse = hdfiluse(hdlist[0]->fd, 1);
533                                  fprintf(stderr,
534 <                        "%s: %.1f Mbyte holodeck file, %.2f%% fragmentation\n",
534 >                        "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
535                                                  hdkfile, fsiz/(1024.*1024.),
536                                                  100.*(fsiz-fuse)/fsiz);
537                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines