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.20 by gregl, Fri Dec 12 11:13:16 1997 UTC vs.
Revision 3.27 by gregl, Sun Dec 14 09:46:52 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 89 | Line 88 | char   *argv[];
88                  default:
89                          goto userr;
90                  }
92                                                /* do we have a job? */
93        if (outdev == NULL && ncprocs <= 0)
94                goto userr;
91                                                  /* get root file name */
92          rootname(froot, hdkfile=argv[i++]);
93 <                                                /* load... */
94 <        if (i < argc) {                         /* variables */
95 <                loadvars(argv[i++]);
96 <                                                        /* cmdline settings */
97 <                for ( ; i < argc; i++)
98 <                        if (setvariable(argv[i], matchvar) < 0) {
99 <                                sprintf(errmsg, "unknown variable: %s",
100 <                                                argv[i]);
101 <                                error(USER, errmsg);
102 <                        }
103 <                                                        /* check settings */
104 <                checkvalues();
105 <                                                        /* load RIF if any */
106 <                if (vdef(RIF))
107 <                        getradfile(vval(RIF));
93 >                                                /* load variables? */
94 >        if (i < argc)
95 >                if (argv[i][0] != '-' && argv[i][0] != '+')
96 >                        loadvars(argv[i]);      /* load variables from file */
97 >
98 >        if (i >= argc || argv[i][0] == '+')
99 >                loadholo();                     /* load existing holodeck */
100 >
101 >        while (++i < argc)                      /* get command line settings */
102 >                if (setvariable(argv[i], matchvar) < 0) {
103 >                        sprintf(errmsg, "unknown variable: %s", argv[i]);
104 >                        error(USER, errmsg);
105 >                }
106 >                                                /* check settings */
107 >        checkvalues();
108 >                                                /* load RIF if any */
109 >        getradfile();
110 >
111 >        if (hdlist[i] == NULL) {                /* create new holodeck */
112                                                          /* set defaults */
113                  setdefaults(&hdg);
114                                                          /* holodeck exists? */
# Line 117 | Line 117 | char   *argv[];
117                                  "holodeck file exists -- use -f to overwrite");
118                                                          /* create holodeck */
119                  creatholo(&hdg);
120 <        } else {                                /* else load holodeck */
121 <                loadholo();
122 <                                                        /* check settings */
123 <                checkvalues();
124 <                                                        /* load RIF if any */
125 <                if (vdef(RIF))
126 <                        getradfile(vval(RIF));
127 <                                                        /* set defaults */
120 >        } else                                  /* else just set defaults */
121                  setdefaults(NULL);
129        }
122                                                  /* initialize */
123          initrholo();
124                                                  /* main loop */
# Line 136 | Line 128 | char   *argv[];
128          quit(0);
129   userr:
130          fprintf(stderr,
131 < "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
131 > "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
132                          progname);
133          quit(1);
134   }
# Line 209 | Line 201 | initrholo()                    /* get our holodeck running */
201          if (!vdef(TIME) || vflt(TIME) <= FTINY)
202                  endtime = 0;
203          else
204 <                endtime = starttime + vflt(TIME)*3600.;
204 >                endtime = starttime + vflt(TIME)*3600. + .5;
205                                                  /* set up memory cache */
206          if (outdev == NULL)
207                  hdcachesize = 0;        /* manual flushing */
# Line 236 | Line 228 | initrholo()                    /* get our holodeck running */
228                          goto memerr;
229                  freepacks[--i].nr = 0;
230                  freepacks[i].next = NULL;
231 <                if (!vbool(OBSTRUCTIONS)) {
231 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
232                          freepacks[i].offset = (float *)bmalloc(
233                                          RPACKSIZ*sizeof(float)*(i+1) );
234                          if (freepacks[i].offset == NULL)
# Line 281 | Line 273 | rholo()                                /* holodeck main loop */
273                          return(0);
274                                          /* display only? */
275          if (nprocs <= 0)
276 <                return(1);
276 >                return(outdev != NULL);
277                                          /* check file size */
278          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
279                  error(WARNING, "file limit exceeded");
280 <                return(0);
280 >                done_rtrace();
281 >                idle = 1;
282 >                return(1);      /* comes back */
283          }
284                                          /* check time */
285          if (endtime > 0 || reporttime > 0)
286                  t = time(NULL);
287          if (endtime > 0 && t >= endtime) {
288                  error(WARNING, "time limit exceeded");
289 <                return(0);
289 >                done_rtrace();
290 >                idle = 1;
291 >                return(1);      /* comes back */
292          }
293          if (reporttime > 0 && t >= reporttime)
294                  report(t);
# Line 301 | Line 297 | rholo()                                /* holodeck main loop */
297                  p = freepacks; freepacks = p->next; p->next = NULL;
298                  if (!next_packet(p)) {
299                          p->next = freepacks; freepacks = p;
300 +                        idle = 1;
301                          break;
302                  }
303                  if (pl == NULL) pl = p;
304                  else plend->next = p;
305                  plend = p;
306          }
307 <        idle = pl == NULL && freepacks != NULL;
311 <                                        /* are we out of stuff to do? */
312 <        if (idle && outdev == NULL)
313 <                return(0);
314 <                                        /* else process packets */
307 >                                        /* process packets */
308          done_packets(do_packets(pl));
309          return(1);                      /* and continue */
310   }
311  
312  
320 report(t)                       /* report progress so far */
321 time_t  t;
322 {
323        if (t == 0)
324                t = time(NULL);
325        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
326                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
327        fflush(stderr);
328        if (vdef(REPORT))
329                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
330 }
331
332
313   setdefaults(gp)                 /* set default values */
314   register HDGRID *gp;
315   {
# Line 352 | Line 332 | register HDGRID        *gp;
332                  sprintf(vval(OCTREE), "%s.oct", froot);
333                  vdef(OCTREE)++;
334          }
355        if (!vdef(OBSTRUCTIONS)) {
356                vval(OBSTRUCTIONS) = "T";
357                vdef(OBSTRUCTIONS)++;
358        }
335          if (!vdef(VDIST)) {
336                  vval(VDIST) = "F";
337                  vdef(VDIST)++;
# Line 508 | Line 484 | PACKET *pl;
484   }
485  
486  
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,-1};
527        static char     tf1[] = TEMPLATE;
528        char    tf2[64];
529        char    combuf[256];
530        char    *pippt;
531        register int    i;
532        register char   *cp;
533                                        /* create rad command */
534        mktemp(tf1);
535        sprintf(tf2, "%s.rif", tf1);
536        sprintf(combuf,
537                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
538                        rfargs, tf1);
539        cp = combuf;
540        while (*cp){
541                if (*cp == '|') pippt = cp;
542                cp++;
543        }                               /* match unset variables */
544        for (i = 0; mvar[i] >= 0; i++)
545                if (!vdef(mvar[i])) {
546                        *cp++ = '|';
547                        strcpy(cp, vnam(mvar[i]));
548                        while (*cp) cp++;
549                        pippt = NULL;
550                }
551        if (pippt != NULL)
552                strcpy(pippt, "> /dev/null");   /* nothing to match */
553        else
554                sprintf(cp, ")[ \t]*=' > %s", tf2);
555        if (system(combuf)) {
556                unlink(tf2);                    /* clean up */
557                unlink(tf1);
558                error(SYSTEM, "cannot execute rad command");
559        }
560        if (pippt == NULL) {
561                loadvars(tf2);                  /* load variables */
562                unlink(tf2);
563        }
564        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
565        unlink(tf1);                    /* clean up */
566 }
567
568
487   rootname(rn, fn)                /* remove tail from end of fn */
488   register char   *rn, *fn;
489   {
490          char    *tp, *dp;
491  
492          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
493 <                if (ISDIRSEP(*rn))
493 >                if (*rn == '/')
494                          dp = rn;
495                  else if (*rn == '.')
496                          tp = rn;
# Line 621 | Line 539 | int    ec;
539   {
540          int     status = 0;
541  
542 <        if (hdlist[0] != NULL) {        /* flush holodeck */
543 <                if (nprocs > 0) {
544 <                        done_packets(flush_queue());
627 <                        status = end_rtrace();  /* close rtrace */
628 <                }
629 <                hdflush(NULL);
542 >        if (hdlist[0] != NULL) {        /* close holodeck */
543 >                if (nprocs > 0)
544 >                        status = done_rtrace();         /* calls hdsync() */
545                  if (ncprocs > 0 && vdef(REPORT)) {
546                          long    fsiz, fuse;
632                        report(0);
547                          fsiz = hdfilen(hdlist[0]->fd);
548                          fuse = hdfiluse(hdlist[0]->fd, 1);
549                          fprintf(stderr,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines