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.20 by gregl, Fri Dec 12 11:13:16 1997 UTC

# Line 26 | Line 26 | char   froot[MAXPATH];         /* root file name */
26  
27   int     nowarn = 0;             /* turn warnings off? */
28  
29 double  expval = 1.;            /* global exposure value */
30
29   int     ncprocs = 0;            /* desired number of compute processes */
30  
31   char    *outdev = NULL;         /* output device name */
32  
33 + int     readinp = 0;            /* read commands from stdin */
34 +
35 + int     force = 0;              /* allow overwrite of holodeck */
36 +
37   time_t  starttime;              /* time we got started */
38   time_t  endtime;                /* time we should end by */
39   time_t  reporttime;             /* time for next report */
# Line 59 | Line 61 | char   *argv[];
61   {
62          HDGRID  hdg;
63          int     i;
62        int     force = 0;
64                                                  /* mark start time */
65          starttime = time(NULL);
66 <        initurand(10240);                       /* initialize urand */
66 >        initurand(16384);                       /* initialize urand */
67          progname = argv[0];                     /* get arguments */
68          for (i = 1; i < argc && argv[i][0] == '-'; i++)
69                  switch (argv[i][1]) {
# Line 72 | Line 73 | char   *argv[];
73                  case 'f':                       /* force overwrite */
74                          force++;
75                          break;
76 +                case 'i':                       /* read input from stdin */
77 +                        readinp++;
78 +                        break;
79                  case 'n':                       /* compute processes */
80                          if (i >= argc-2)
81                                  goto userr;
# Line 115 | Line 119 | char   *argv[];
119                  creatholo(&hdg);
120          } else {                                /* else load holodeck */
121                  loadholo();
122 <                if (vdef(RIF))                          /* load RIF if any */
122 >                                                        /* check settings */
123 >                checkvalues();
124 >                                                        /* load RIF if any */
125 >                if (vdef(RIF))
126                          getradfile(vval(RIF));
127 +                                                        /* set defaults */
128 +                setdefaults(NULL);
129          }
130                                                  /* initialize */
131          initrholo();
132 <                                                /* run */
132 >                                                /* main loop */
133          while (rholo())
134                  ;
135                                                  /* done */
# Line 184 | Line 193 | initrholo()                    /* get our holodeck running */
193   {
194          extern int      global_packet();
195          register int    i;
196 +                                                /* close holodeck on exec() */
197 +        fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC);
198  
199          if (outdev != NULL)                     /* open output device */
200                  disp_open(outdev);
# Line 214 | Line 225 | initrholo()                    /* get our holodeck running */
225          if (ncprocs > 0) {
226                  i = start_rtrace();
227                  if (i < 1)
228 <                        error(USER, "cannot start rtrace process");
228 >                        error(USER, "cannot start rtrace process(es)");
229                  if (vdef(REPORT)) {             /* make first report */
230                          printargs(rtargc, rtargv, stderr);
231                          report(0);
# Line 269 | Line 280 | rholo()                                /* holodeck main loop */
280                  if (!disp_check(idle))
281                          return(0);
282                                          /* display only? */
283 <        if (ncprocs <= 0)
283 >        if (nprocs <= 0)
284                  return(1);
285                                          /* check file size */
286          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
# Line 335 | Line 346 | register HDGRID        *gp;
346                  sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
347                  error(WARNING, errmsg);
348          }
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);
349          if (!vdef(OCTREE)) {
350                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
351                          error(SYSTEM, "out of memory");
# Line 382 | Line 367 | register HDGRID        *gp;
367                                  /* append rendering options */
368          if (vdef(RENDER))
369                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
370 +        
371 +        if (gp == NULL)         /* already initialized? */
372 +                return;
373 +                                /* set grid parameters */
374 +        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
375 +        if (sscanf(vval(SECTION),
376 +                "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
377 +                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
378 +                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
379 +                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
380 +                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
381 +                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
382 +                badvalue(SECTION);
383 +        maxlen = 0.;
384 +        for (i = 0; i < 3; i++)
385 +                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
386 +                        maxlen = len[i];
387 +        if (!vdef(GRID)) {
388 +                sprintf(buf, "%.4f", maxlen/8.);
389 +                vval(GRID) = savqstr(buf);
390 +                vdef(GRID)++;
391 +        }
392 +        if ((d = vflt(GRID)) <= FTINY)
393 +                badvalue(GRID);
394 +        for (i = 0; i < 3; i++)
395 +                if (gp->grid[i] <= 0)
396 +                        gp->grid[i] = len[i]/d + (1.-FTINY);
397   }
398  
399  
# Line 489 | Line 501 | PACKET *pl;
501                  p->next = freepacks;
502                  freepacks = p;
503          }
504 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
504 >        if (n2flush > 512*RPACKSIZ*nprocs) {
505                  hdflush(NULL);                  /* flush holodeck buffers */
506                  n2flush = 0;
507          }
508   }
509  
510  
511 + checkrad()                      /* check to make sure octree is up to date */
512 + {
513 +        char    combuf[128];
514 +
515 +        if (!vdef(RIF))
516 +                return;
517 +        sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
518 +        if (system(combuf))
519 +                error(WARNING, "error running rad");
520 + }
521 +
522 +
523   getradfile(rfargs)              /* run rad and get needed variables */
524   char    *rfargs;
525   {
526 <        static short    mvar[] = {OCTREE,EXPOSURE,-1};
526 >        static short    mvar[] = {OCTREE,-1};
527          static char     tf1[] = TEMPLATE;
528          char    tf2[64];
529          char    combuf[256];
# Line 529 | Line 553 | char   *rfargs;
553          else
554                  sprintf(cp, ")[ \t]*=' > %s", tf2);
555          if (system(combuf)) {
532                error(SYSTEM, "cannot execute rad command");
556                  unlink(tf2);                    /* clean up */
557                  unlink(tf1);
558 <                quit(1);
558 >                error(SYSTEM, "cannot execute rad command");
559          }
560          if (pippt == NULL) {
561                  loadvars(tf2);                  /* load variables */
# Line 599 | Line 622 | int    ec;
622          int     status = 0;
623  
624          if (hdlist[0] != NULL) {        /* flush holodeck */
625 <                if (ncprocs > 0) {
625 >                if (nprocs > 0) {
626                          done_packets(flush_queue());
627                          status = end_rtrace();  /* close rtrace */
628 <                        hdflush(NULL);
629 <                        if (vdef(REPORT)) {
630 <                                long    fsiz, fuse;
631 <                                report(0);
632 <                                fsiz = hdfilen(hdlist[0]->fd);
633 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
634 <                                fprintf(stderr,
628 >                }
629 >                hdflush(NULL);
630 >                if (ncprocs > 0 && vdef(REPORT)) {
631 >                        long    fsiz, fuse;
632 >                        report(0);
633 >                        fsiz = hdfilen(hdlist[0]->fd);
634 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
635 >                        fprintf(stderr,
636                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
637 <                                                hdkfile, fsiz/(1024.*1024.),
638 <                                                100.*(fsiz-fuse)/fsiz);
639 <                        }
616 <                } else
617 <                        hdflush(NULL);
637 >                                        hdkfile, fsiz/(1024.*1024.),
638 >                                        100.*(fsiz-fuse)/fsiz);
639 >                }
640          }
641          if (orig_mode >= 0)             /* reset holodeck access mode */
642                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines