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.17 by gregl, Mon Dec 8 18:51:15 1997 UTC vs.
Revision 3.23 by gregl, Fri Dec 12 18:33:50 1997 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10  
11   #include "rholo.h"
12   #include "random.h"
13 #include "paths.h"
13   #include <signal.h>
14   #include <sys/types.h>
15   #include <sys/stat.h>
# Line 22 | Line 21 | VARIABLE       vv[] = RHVINIT;         /* variable-value pairs */
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  
# Line 32 | Line 31 | 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 */
# Line 59 | Line 60 | char   *argv[];
60   {
61          HDGRID  hdg;
62          int     i;
62        int     force = 0;
63                                                  /* mark start time */
64          starttime = time(NULL);
65 <        initurand(10240);                       /* initialize urand */
65 >        initurand(16384);                       /* initialize urand */
66          progname = argv[0];                     /* get arguments */
67          for (i = 1; i < argc && argv[i][0] == '-'; i++)
68                  switch (argv[i][1]) {
# Line 106 | Line 106 | char   *argv[];
106                                                          /* check settings */
107                  checkvalues();
108                                                          /* load RIF if any */
109 <                if (vdef(RIF))
110 <                        getradfile(vval(RIF));
109 >                getradfile();
110                                                          /* set defaults */
111                  setdefaults(&hdg);
112                                                          /* holodeck exists? */
# Line 121 | Line 120 | char   *argv[];
120                                                          /* check settings */
121                  checkvalues();
122                                                          /* load RIF if any */
123 <                if (vdef(RIF))
125 <                        getradfile(vval(RIF));
123 >                getradfile();
124                                                          /* set defaults */
125                  setdefaults(NULL);
126          }
# Line 208 | Line 206 | initrholo()                    /* get our holodeck running */
206          if (!vdef(TIME) || vflt(TIME) <= FTINY)
207                  endtime = 0;
208          else
209 <                endtime = starttime + vflt(TIME)*3600.;
209 >                endtime = starttime + vflt(TIME)*3600. + .5;
210                                                  /* set up memory cache */
211          if (outdev == NULL)
212                  hdcachesize = 0;        /* manual flushing */
# Line 224 | Line 222 | initrholo()                    /* get our holodeck running */
222          if (ncprocs > 0) {
223                  i = start_rtrace();
224                  if (i < 1)
225 <                        error(USER, "cannot start rtrace process");
225 >                        error(USER, "cannot start rtrace process(es)");
226                  if (vdef(REPORT)) {             /* make first report */
227                          printargs(rtargc, rtargv, stderr);
228                          report(0);
# Line 279 | Line 277 | rholo()                                /* holodeck main loop */
277                  if (!disp_check(idle))
278                          return(0);
279                                          /* display only? */
280 <        if (ncprocs <= 0)
281 <                return(1);
280 >        if (nprocs <= 0)
281 >                return(outdev != NULL);
282                                          /* check file size */
283          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
284                  error(WARNING, "file limit exceeded");
285 <                return(0);
285 >                done_rtrace();
286 >                idle = 1;
287 >                return(1);      /* comes back */
288          }
289                                          /* check time */
290          if (endtime > 0 || reporttime > 0)
291                  t = time(NULL);
292          if (endtime > 0 && t >= endtime) {
293                  error(WARNING, "time limit exceeded");
294 <                return(0);
294 >                done_rtrace();
295 >                idle = 1;
296 >                return(1);      /* comes back */
297          }
298          if (reporttime > 0 && t >= reporttime)
299                  report(t);
# Line 300 | Line 302 | rholo()                                /* holodeck main loop */
302                  p = freepacks; freepacks = p->next; p->next = NULL;
303                  if (!next_packet(p)) {
304                          p->next = freepacks; freepacks = p;
305 +                        idle = 1;
306                          break;
307                  }
308                  if (pl == NULL) pl = p;
309                  else plend->next = p;
310                  plend = p;
311          }
312 <        idle = pl == NULL && freepacks != NULL;
310 <                                        /* are we out of stuff to do? */
311 <        if (idle && outdev == NULL)
312 <                return(0);
313 <                                        /* else process packets */
312 >                                        /* process packets */
313          done_packets(do_packets(pl));
314          return(1);                      /* and continue */
315   }
316  
317  
319 report(t)                       /* report progress so far */
320 time_t  t;
321 {
322        if (t == 0)
323                t = time(NULL);
324        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
325                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
326        fflush(stderr);
327        if (vdef(REPORT))
328                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
329 }
330
331
318   setdefaults(gp)                 /* set default values */
319   register HDGRID *gp;
320   {
# Line 500 | Line 486 | PACKET *pl;
486                  p->next = freepacks;
487                  freepacks = p;
488          }
489 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
489 >        if (n2flush > 512*RPACKSIZ*nprocs) {
490                  hdflush(NULL);                  /* flush holodeck buffers */
491                  n2flush = 0;
492          }
493   }
494  
495  
510 getradfile(rfargs)              /* run rad and get needed variables */
511 char    *rfargs;
512 {
513        static short    mvar[] = {OCTREE,-1};
514        static char     tf1[] = TEMPLATE;
515        char    tf2[64];
516        char    combuf[256];
517        char    *pippt;
518        register int    i;
519        register char   *cp;
520                                        /* create rad command */
521        mktemp(tf1);
522        sprintf(tf2, "%s.rif", tf1);
523        sprintf(combuf,
524                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
525                        rfargs, tf1);
526        cp = combuf;
527        while (*cp){
528                if (*cp == '|') pippt = cp;
529                cp++;
530        }                               /* match unset variables */
531        for (i = 0; mvar[i] >= 0; i++)
532                if (!vdef(mvar[i])) {
533                        *cp++ = '|';
534                        strcpy(cp, vnam(mvar[i]));
535                        while (*cp) cp++;
536                        pippt = NULL;
537                }
538        if (pippt != NULL)
539                strcpy(pippt, "> /dev/null");   /* nothing to match */
540        else
541                sprintf(cp, ")[ \t]*=' > %s", tf2);
542        if (system(combuf)) {
543                error(SYSTEM, "cannot execute rad command");
544                unlink(tf2);                    /* clean up */
545                unlink(tf1);
546                quit(1);
547        }
548        if (pippt == NULL) {
549                loadvars(tf2);                  /* load variables */
550                unlink(tf2);
551        }
552        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
553        unlink(tf1);                    /* clean up */
554 }
555
556
496   rootname(rn, fn)                /* remove tail from end of fn */
497   register char   *rn, *fn;
498   {
499          char    *tp, *dp;
500  
501          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
502 <                if (ISDIRSEP(*rn))
502 >                if (*rn == '/')
503                          dp = rn;
504                  else if (*rn == '.')
505                          tp = rn;
# Line 610 | Line 549 | int    ec;
549          int     status = 0;
550  
551          if (hdlist[0] != NULL) {        /* flush holodeck */
552 <                if (ncprocs > 0) {
553 <                        done_packets(flush_queue());
554 <                        status = end_rtrace();  /* close rtrace */
555 <                        hdflush(NULL);
556 <                        if (vdef(REPORT)) {
557 <                                long    fsiz, fuse;
558 <                                report(0);
559 <                                fsiz = hdfilen(hdlist[0]->fd);
621 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
622 <                                fprintf(stderr,
552 >                if (nprocs > 0)
553 >                        status = done_rtrace();
554 >                hdflush(NULL);
555 >                if (ncprocs > 0 && vdef(REPORT)) {
556 >                        long    fsiz, fuse;
557 >                        fsiz = hdfilen(hdlist[0]->fd);
558 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
559 >                        fprintf(stderr,
560                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
561 <                                                hdkfile, fsiz/(1024.*1024.),
562 <                                                100.*(fsiz-fuse)/fsiz);
563 <                        }
627 <                } else
628 <                        hdflush(NULL);
561 >                                        hdkfile, fsiz/(1024.*1024.),
562 >                                        100.*(fsiz-fuse)/fsiz);
563 >                }
564          }
565          if (orig_mode >= 0)             /* reset holodeck access mode */
566                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines