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.26 by gregl, Sat Dec 13 10:38:26 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 88 | Line 88 | char   *argv[];
88                  default:
89                          goto userr;
90                  }
91                                                /* do we have a job? */
92        if (outdev == NULL && ncprocs <= 0)
93                goto userr;
91                                                  /* get root file name */
92          rootname(froot, hdkfile=argv[i++]);
93                                                  /* load... */
# Line 106 | Line 103 | char   *argv[];
103                                                          /* check settings */
104                  checkvalues();
105                                                          /* load RIF if any */
106 <                if (vdef(RIF))
110 <                        getradfile(vval(RIF));
106 >                getradfile();
107                                                          /* set defaults */
108                  setdefaults(&hdg);
109                                                          /* holodeck exists? */
# Line 121 | Line 117 | char   *argv[];
117                                                          /* check settings */
118                  checkvalues();
119                                                          /* load RIF if any */
120 <                if (vdef(RIF))
125 <                        getradfile(vval(RIF));
120 >                getradfile();
121                                                          /* set defaults */
122                  setdefaults(NULL);
123          }
# Line 135 | Line 130 | char   *argv[];
130          quit(0);
131   userr:
132          fprintf(stderr,
133 < "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
133 > "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
134                          progname);
135          quit(1);
136   }
# Line 208 | Line 203 | initrholo()                    /* get our holodeck running */
203          if (!vdef(TIME) || vflt(TIME) <= FTINY)
204                  endtime = 0;
205          else
206 <                endtime = starttime + vflt(TIME)*3600.;
206 >                endtime = starttime + vflt(TIME)*3600. + .5;
207                                                  /* set up memory cache */
208          if (outdev == NULL)
209                  hdcachesize = 0;        /* manual flushing */
# Line 224 | Line 219 | initrholo()                    /* get our holodeck running */
219          if (ncprocs > 0) {
220                  i = start_rtrace();
221                  if (i < 1)
222 <                        error(USER, "cannot start rtrace process");
222 >                        error(USER, "cannot start rtrace process(es)");
223                  if (vdef(REPORT)) {             /* make first report */
224                          printargs(rtargc, rtargv, stderr);
225                          report(0);
# Line 235 | Line 230 | initrholo()                    /* get our holodeck running */
230                          goto memerr;
231                  freepacks[--i].nr = 0;
232                  freepacks[i].next = NULL;
233 <                if (!vbool(OBSTRUCTIONS)) {
233 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
234                          freepacks[i].offset = (float *)bmalloc(
235                                          RPACKSIZ*sizeof(float)*(i+1) );
236                          if (freepacks[i].offset == NULL)
# Line 279 | Line 274 | rholo()                                /* holodeck main loop */
274                  if (!disp_check(idle))
275                          return(0);
276                                          /* display only? */
277 <        if (ncprocs <= 0)
278 <                return(1);
277 >        if (nprocs <= 0)
278 >                return(outdev != NULL);
279                                          /* check file size */
280          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
281                  error(WARNING, "file limit exceeded");
282 <                return(0);
282 >                done_rtrace();
283 >                idle = 1;
284 >                return(1);      /* comes back */
285          }
286                                          /* check time */
287          if (endtime > 0 || reporttime > 0)
288                  t = time(NULL);
289          if (endtime > 0 && t >= endtime) {
290                  error(WARNING, "time limit exceeded");
291 <                return(0);
291 >                done_rtrace();
292 >                idle = 1;
293 >                return(1);      /* comes back */
294          }
295          if (reporttime > 0 && t >= reporttime)
296                  report(t);
# Line 300 | Line 299 | rholo()                                /* holodeck main loop */
299                  p = freepacks; freepacks = p->next; p->next = NULL;
300                  if (!next_packet(p)) {
301                          p->next = freepacks; freepacks = p;
302 +                        idle = 1;
303                          break;
304                  }
305                  if (pl == NULL) pl = p;
306                  else plend->next = p;
307                  plend = p;
308          }
309 <        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 */
309 >                                        /* process packets */
310          done_packets(do_packets(pl));
311          return(1);                      /* and continue */
312   }
313  
314  
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
315   setdefaults(gp)                 /* set default values */
316   register HDGRID *gp;
317   {
# Line 351 | Line 334 | register HDGRID        *gp;
334                  sprintf(vval(OCTREE), "%s.oct", froot);
335                  vdef(OCTREE)++;
336          }
354        if (!vdef(OBSTRUCTIONS)) {
355                vval(OBSTRUCTIONS) = "T";
356                vdef(OBSTRUCTIONS)++;
357        }
337          if (!vdef(VDIST)) {
338                  vval(VDIST) = "F";
339                  vdef(VDIST)++;
# Line 500 | Line 479 | PACKET *pl;
479                  p->next = freepacks;
480                  freepacks = p;
481          }
482 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
482 >        if (n2flush > 512*RPACKSIZ*nprocs) {
483                  hdflush(NULL);                  /* flush holodeck buffers */
484                  n2flush = 0;
485          }
486   }
487  
488  
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
489   rootname(rn, fn)                /* remove tail from end of fn */
490   register char   *rn, *fn;
491   {
492          char    *tp, *dp;
493  
494          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
495 <                if (ISDIRSEP(*rn))
495 >                if (*rn == '/')
496                          dp = rn;
497                  else if (*rn == '.')
498                          tp = rn;
# Line 609 | Line 541 | int    ec;
541   {
542          int     status = 0;
543  
544 <        if (hdlist[0] != NULL) {        /* flush holodeck */
545 <                if (ncprocs > 0) {
546 <                        done_packets(flush_queue());
547 <                        status = end_rtrace();  /* close rtrace */
548 <                        hdflush(NULL);
549 <                        if (vdef(REPORT)) {
550 <                                long    fsiz, fuse;
551 <                                report(0);
620 <                                fsiz = hdfilen(hdlist[0]->fd);
621 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
622 <                                fprintf(stderr,
544 >        if (hdlist[0] != NULL) {        /* close holodeck */
545 >                if (nprocs > 0)
546 >                        status = done_rtrace();         /* calls hdsync() */
547 >                if (ncprocs > 0 && vdef(REPORT)) {
548 >                        long    fsiz, fuse;
549 >                        fsiz = hdfilen(hdlist[0]->fd);
550 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
551 >                        fprintf(stderr,
552                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
553 <                                                hdkfile, fsiz/(1024.*1024.),
554 <                                                100.*(fsiz-fuse)/fsiz);
555 <                        }
627 <                } else
628 <                        hdflush(NULL);
553 >                                        hdkfile, fsiz/(1024.*1024.),
554 >                                        100.*(fsiz-fuse)/fsiz);
555 >                }
556          }
557          if (orig_mode >= 0)             /* reset holodeck access mode */
558                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines