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.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);
# Line 195 | Line 202 | rholo()                                /* holodeck main loop */
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 230 | Line 237 | time_t t;
237          fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
238                          progname, npacksdone, nraysdone, (t-starttime)/3600.);
239          fflush(stderr);
240 <        reporttime = t + (time_t)(vflt(REPORT)*60.);
240 >        if (vdef(REPORT))
241 >                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
242   }
243  
244  
# Line 290 | Line 298 | register HDGRID        *gp;
298                  vval(DISKSPACE) = "100";
299                  vdef(DISKSPACE)++;
300          }
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)++;
# Line 363 | 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 388 | 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 398 | 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                  }
402                nraysdone += p->nr;
403                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  
# Line 415 | Line 423 | char   *rfargs;
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 424 | 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 */
444 <        unlink(tf1);
462 >        unlink(tf1);                    /* clean up */
463   }
464  
465  
# Line 500 | 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 511 | 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