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.14 by gregl, Mon Dec 1 16:34:21 1997 UTC vs.
Revision 3.25 by gregl, Sat Dec 13 10:30:56 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  
29 double  expval = 1.;            /* global exposure value */
30
28   int     ncprocs = 0;            /* desired number of compute processes */
29  
30   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 72 | Line 72 | char   *argv[];
72                  case 'f':                       /* force overwrite */
73                          force++;
74                          break;
75 +                case 'i':                       /* read input from stdin */
76 +                        readinp++;
77 +                        break;
78                  case 'n':                       /* compute processes */
79                          if (i >= argc-2)
80                                  goto userr;
# Line 103 | Line 106 | char   *argv[];
106                                                          /* check settings */
107                  checkvalues();
108                                                          /* load RIF if any */
109 <                if (vdef(RIF))
107 <                        getradfile(vval(RIF));
109 >                getradfile();
110                                                          /* set defaults */
111                  setdefaults(&hdg);
112                                                          /* holodeck exists? */
# Line 115 | Line 117 | char   *argv[];
117                  creatholo(&hdg);
118          } else {                                /* else load holodeck */
119                  loadholo();
120 <                if (vdef(RIF))                          /* load RIF if any */
121 <                        getradfile(vval(RIF));
120 >                                                        /* check settings */
121 >                checkvalues();
122 >                                                        /* load RIF if any */
123 >                getradfile();
124 >                                                        /* set defaults */
125 >                setdefaults(NULL);
126          }
127                                                  /* initialize */
128          initrholo();
129 <                                                /* run */
129 >                                                /* main loop */
130          while (rholo())
131                  ;
132                                                  /* done */
# Line 184 | Line 190 | initrholo()                    /* get our holodeck running */
190   {
191          extern int      global_packet();
192          register int    i;
193 +                                                /* close holodeck on exec() */
194 +        fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC);
195  
196          if (outdev != NULL)                     /* open output device */
197                  disp_open(outdev);
# Line 198 | 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 214 | 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 225 | Line 233 | initrholo()                    /* get our holodeck running */
233                          goto memerr;
234                  freepacks[--i].nr = 0;
235                  freepacks[i].next = NULL;
236 <                if (!vbool(OBSTRUCTIONS)) {
236 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
237                          freepacks[i].offset = (float *)bmalloc(
238                                          RPACKSIZ*sizeof(float)*(i+1) );
239                          if (freepacks[i].offset == NULL)
# Line 269 | 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 290 | 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;
300 <                                        /* are we out of stuff to do? */
301 <        if (idle && outdev == NULL)
302 <                return(0);
303 <                                        /* else process packets */
312 >                                        /* process packets */
313          done_packets(do_packets(pl));
314          return(1);                      /* and continue */
315   }
316  
317  
309 report(t)                       /* report progress so far */
310 time_t  t;
311 {
312        if (t == 0)
313                t = time(NULL);
314        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
315                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
316        fflush(stderr);
317        if (vdef(REPORT))
318                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
319 }
320
321
318   setdefaults(gp)                 /* set default values */
319   register HDGRID *gp;
320   {
# Line 335 | Line 331 | register HDGRID        *gp;
331                  sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
332                  error(WARNING, errmsg);
333          }
338        if (sscanf(vval(SECTION),
339                        "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
340                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
341                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
342                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
343                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12)
344                badvalue(SECTION);
345        maxlen = 0.;
346        for (i = 0; i < 3; i++)
347                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
348                        maxlen = len[i];
349        if (!vdef(GRID)) {
350                sprintf(buf, "%.4f", maxlen/8.);
351                vval(GRID) = savqstr(buf);
352                vdef(GRID)++;
353        }
354        if ((d = vflt(GRID)) <= FTINY)
355                badvalue(GRID);
356        for (i = 0; i < 3; i++)
357                gp->grid[i] = len[i]/d + (1.-FTINY);
358        if (!vdef(EXPOSURE)) {
359                sprintf(errmsg, "%s must be defined", vnam(EXPOSURE));
360                error(USER, errmsg);
361        }
362        expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ?
363                        pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE);
334          if (!vdef(OCTREE)) {
335                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
336                          error(SYSTEM, "out of memory");
337                  sprintf(vval(OCTREE), "%s.oct", froot);
338                  vdef(OCTREE)++;
339          }
370        if (!vdef(OBSTRUCTIONS)) {
371                vval(OBSTRUCTIONS) = "T";
372                vdef(OBSTRUCTIONS)++;
373        }
340          if (!vdef(VDIST)) {
341                  vval(VDIST) = "F";
342                  vdef(VDIST)++;
# Line 382 | Line 348 | register HDGRID        *gp;
348                                  /* append rendering options */
349          if (vdef(RENDER))
350                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
351 +        
352 +        if (gp == NULL)         /* already initialized? */
353 +                return;
354 +                                /* set grid parameters */
355 +        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
356 +        if (sscanf(vval(SECTION),
357 +                "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
358 +                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
359 +                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
360 +                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
361 +                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
362 +                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
363 +                badvalue(SECTION);
364 +        maxlen = 0.;
365 +        for (i = 0; i < 3; i++)
366 +                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
367 +                        maxlen = len[i];
368 +        if (!vdef(GRID)) {
369 +                sprintf(buf, "%.4f", maxlen/8.);
370 +                vval(GRID) = savqstr(buf);
371 +                vdef(GRID)++;
372 +        }
373 +        if ((d = vflt(GRID)) <= FTINY)
374 +                badvalue(GRID);
375 +        for (i = 0; i < 3; i++)
376 +                if (gp->grid[i] <= 0)
377 +                        gp->grid[i] = len[i]/d + (1.-FTINY);
378   }
379  
380  
# Line 489 | Line 482 | PACKET *pl;
482                  p->next = freepacks;
483                  freepacks = p;
484          }
485 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
485 >        if (n2flush > 512*RPACKSIZ*nprocs) {
486                  hdflush(NULL);                  /* flush holodeck buffers */
487                  n2flush = 0;
488          }
489   }
490  
491  
499 getradfile(rfargs)              /* run rad and get needed variables */
500 char    *rfargs;
501 {
502        static short    mvar[] = {OCTREE,EXPOSURE,-1};
503        static char     tf1[] = TEMPLATE;
504        char    tf2[64];
505        char    combuf[256];
506        char    *pippt;
507        register int    i;
508        register char   *cp;
509                                        /* create rad command */
510        mktemp(tf1);
511        sprintf(tf2, "%s.rif", tf1);
512        sprintf(combuf,
513                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
514                        rfargs, tf1);
515        cp = combuf;
516        while (*cp){
517                if (*cp == '|') pippt = cp;
518                cp++;
519        }                               /* match unset variables */
520        for (i = 0; mvar[i] >= 0; i++)
521                if (!vdef(mvar[i])) {
522                        *cp++ = '|';
523                        strcpy(cp, vnam(mvar[i]));
524                        while (*cp) cp++;
525                        pippt = NULL;
526                }
527        if (pippt != NULL)
528                strcpy(pippt, "> /dev/null");   /* nothing to match */
529        else
530                sprintf(cp, ")[ \t]*=' > %s", tf2);
531        if (system(combuf)) {
532                error(SYSTEM, "cannot execute rad command");
533                unlink(tf2);                    /* clean up */
534                unlink(tf1);
535                quit(1);
536        }
537        if (pippt == NULL) {
538                loadvars(tf2);                  /* load variables */
539                unlink(tf2);
540        }
541        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
542        unlink(tf1);                    /* clean up */
543 }
544
545
492   rootname(rn, fn)                /* remove tail from end of fn */
493   register char   *rn, *fn;
494   {
495          char    *tp, *dp;
496  
497          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
498 <                if (ISDIRSEP(*rn))
498 >                if (*rn == '/')
499                          dp = rn;
500                  else if (*rn == '.')
501                          tp = rn;
# Line 598 | Line 544 | int    ec;
544   {
545          int     status = 0;
546  
547 <        if (hdlist[0] != NULL) {        /* flush holodeck */
548 <                if (ncprocs > 0) {
549 <                        done_packets(flush_queue());
550 <                        status = end_rtrace();  /* close rtrace */
551 <                        hdflush(NULL);
552 <                        if (vdef(REPORT)) {
553 <                                long    fsiz, fuse;
554 <                                report(0);
609 <                                fsiz = hdfilen(hdlist[0]->fd);
610 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
611 <                                fprintf(stderr,
547 >        if (hdlist[0] != NULL) {        /* close holodeck */
548 >                if (nprocs > 0)
549 >                        status = done_rtrace();         /* calls hdsync() */
550 >                if (ncprocs > 0 && vdef(REPORT)) {
551 >                        long    fsiz, fuse;
552 >                        fsiz = hdfilen(hdlist[0]->fd);
553 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
554 >                        fprintf(stderr,
555                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
556 <                                                hdkfile, fsiz/(1024.*1024.),
557 <                                                100.*(fsiz-fuse)/fsiz);
558 <                        }
616 <                } else
617 <                        hdflush(NULL);
556 >                                        hdkfile, fsiz/(1024.*1024.),
557 >                                        100.*(fsiz-fuse)/fsiz);
558 >                }
559          }
560          if (orig_mode >= 0)             /* reset holodeck access mode */
561                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines