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.4 by gregl, Mon Nov 3 18:33:12 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
# Line 184 | Line 187 | rholo()                                /* holodeck main loop */
187          register PACKET *p;
188          time_t  t;
189          long    l;
190 <                                        /* check display */
191 <        if (outdev != NULL && !disp_check(idle))
192 <                return(0);
190 >
191 >        if (outdev != NULL)             /* check display */
192 >                if (!disp_check(idle))
193 >                        return(0);
194                                          /* display only? */
195          if (ncprocs <= 0)
196                  return(1);
197                                          /* check file size */
198 <        if (l = 1024.*1024.*vflt(DISKSPACE) > 0 &&
198 >        if ((l = 1024.*1024.*vflt(DISKSPACE)) > 0 &&
199                          hdfiluse(hdlist[0]->fd, 0) + hdmemuse(0) >= l)
200                  return(0);
201                                          /* check time */
202 <        if (endtime > 0 || vdef(REPORT))
202 >        if (endtime > 0 || reporttime > 0)
203                  t = time(NULL);
204          if (endtime > 0 && t >= endtime)
205                  return(0);
206 <        if (vdef(REPORT) && t >= reporttime)
206 >        if (reporttime > 0 && t >= reporttime)
207                  report(t);
208                                          /* get packets to process */
209          while (freepacks != NULL) {
# Line 227 | Line 231 | time_t t;
231   {
232          if (t == 0)
233                  t = time(NULL);
234 <        fprintf(stderr, "%s: %ld packets done (%ld rays) after %.2f hours\n",
234 >        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
235                          progname, npacksdone, nraysdone, (t-starttime)/3600.);
236 +        fflush(stderr);
237 +        if (vdef(REPORT))
238 +                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
239   }
240  
241  
# Line 260 | Line 267 | register HDGRID        *gp;
267                  if ((len[i] = VLEN(gp->xv[i])) > maxlen)
268                          maxlen = len[i];
269          if (!vdef(GRID)) {
270 <                sprintf(buf, "%.4f", maxlen/16.);
270 >                sprintf(buf, "%.4f", maxlen/8.);
271                  vval(GRID) = savqstr(buf);
272                  vdef(GRID)++;
273          }
# Line 328 | Line 335 | HDGRID *gp;
335          putw(HOLOMAGIC, fp);            /* put magic number & terminus */
336          fwrite(&endloc, sizeof(long), 1, fp);
337          fflush(fp);                     /* flush buffer */
338 <        initholo(fileno(fp), gp);       /* allocate and initialize index */
338 >        hdinit(fileno(fp), gp);         /* allocate and initialize index */
339                          /* we're dropping fp here.... */
340   }
341  
# Line 340 | Line 347 | char   *s;
347          register char   *cp;
348          char    fmt[32];
349  
350 <        if (headidval(fmt, s)) {
350 >        if (formatval(fmt, s)) {
351                  if (strcmp(fmt, HOLOFMT)) {
352                          sprintf(errmsg, "%s file \"%s\" has %s%s",
353                                          HOLOFMT, hdkfile, FMTSTR, fmt);
# Line 361 | Line 368 | loadholo()                     /* start loading a holodeck from fname */
368   {
369          FILE    *fp;
370          long    endloc;
371 <                                        /* open input file */
372 <        if ((fp = fopen(hdkfile, "r+")) == NULL) {
373 <                sprintf(errmsg, "cannot open \"%s\" for appending", hdkfile);
371 >                                        /* open holodeck file */
372 >        if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
373 >                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
374 >                                ncprocs>0 ? "appending" : "reading");
375                  error(SYSTEM, errmsg);
376          }
377                                          /* load variables from header */
# Line 378 | Line 386 | loadholo()                     /* start loading a holodeck from fname */
386          if (endloc != 0)
387                  error(WARNING, "ignoring multiple sections in holodeck file");
388          fseek(fp, 0L, 1);                       /* align system file pointer */
389 <        initholo(fileno(fp), NULL);             /* allocate and load index */
389 >        hdinit(fileno(fp), NULL);               /* allocate and load index */
390                          /* we're dropping fp here.... */
391   }
392  
# Line 409 | Line 417 | PACKET *pl;
417   getradfile(rfargs)              /* run rad and get needed variables */
418   char    *rfargs;
419   {
420 <        static short    mvar[] = {VIEW,OCTREE,EXPOSURE,REPORT,-1};
420 >        static short    mvar[] = {VIEW,OCTREE,EXPOSURE,-1};
421          static char     tf1[] = TEMPLATE;
422          char    tf2[64];
423          char    combuf[256];
424 +        char    *pippt;
425          register int    i;
426          register char   *cp;
427                                          /* create rad command */
# Line 422 | Line 431 | char   *rfargs;
431                  "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
432                          rfargs, tf1);
433          cp = combuf;
434 <        while (*cp) cp++;               /* match unset variables */
434 >        while (*cp){
435 >                if (*cp == '|') pippt = cp;
436 >                cp++;
437 >        }                               /* match unset variables */
438          for (i = 0; mvar[i] >= 0; i++)
439                  if (!vdef(mvar[i])) {
440                          *cp++ = '|';
441                          strcpy(cp, vnam(mvar[i]));
442                          while (*cp) cp++;
443 +                        pippt = NULL;
444                  }
445 <        sprintf(cp, ")[ \t]*=' > %s", tf2);
445 >        if (pippt != NULL)
446 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
447 >        else
448 >                sprintf(cp, ")[ \t]*=' > %s", tf2);
449          if (system(combuf)) {
450                  error(SYSTEM, "cannot execute rad command");
451                  unlink(tf2);                    /* clean up */
452                  unlink(tf1);
453                  quit(1);
454          }
455 <        loadvars(tf2);                  /* load variables */
455 >        if (pippt == NULL) {
456 >                loadvars(tf2);                  /* load variables */
457 >                unlink(tf2);
458 >        }
459          rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
460 <        unlink(tf2);                    /* clean up */
442 <        unlink(tf1);
460 >        unlink(tf1);                    /* clean up */
461   }
462  
463  
# Line 498 | Line 516 | int    ec;
516   {
517          int     status = 0;
518  
519 +        if (outdev != NULL)             /* close display */
520 +                disp_close();
521          if (hdlist[0] != NULL) {        /* flush holodeck */
522                  if (ncprocs > 0) {
523                          done_packets(flush_queue());
# Line 509 | Line 529 | int    ec;
529                                  fsiz = lseek(hdlist[0]->fd, 0L, 2);
530                                  fuse = hdfiluse(hdlist[0]->fd, 1);
531                                  fprintf(stderr,
532 <                        "%s: %.1f Mbyte holodeck file, %.2f%% fragmentation\n",
532 >                        "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
533                                                  hdkfile, fsiz/(1024.*1024.),
534                                                  100.*(fsiz-fuse)/fsiz);
535                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines