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.28 by gregl, Mon Dec 15 20:43:01 1997 UTC vs.
Revision 3.32 by gregl, Mon Dec 22 11:06:53 1997 UTC

# Line 58 | Line 58 | main(argc, argv)
58   int     argc;
59   char    *argv[];
60   {
61        HDGRID  hdg;
61          int     i;
62                                                  /* mark start time */
63          starttime = time(NULL);
# Line 89 | Line 88 | char   *argv[];
88                          goto userr;
89                  }
90                                                  /* get root file name */
91 +        if (i >= argc)
92 +                goto userr;
93          rootname(froot, hdkfile=argv[i++]);
94                                                  /* load variables? */
95          if (i < argc)
# Line 109 | Line 110 | char   *argv[];
110          getradfile();
111  
112          if (hdlist[0] == NULL) {                /* create new holodeck */
113 +                HDGRID  hdg[HDMAX];
114                                                          /* set defaults */
115 <                setdefaults(&hdg);
115 >                setdefaults(hdg);
116                                                          /* holodeck exists? */
117                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
118                          error(USER,
119                                  "holodeck file exists -- use -f to overwrite");
120                                                          /* create holodeck */
121 <                creatholo(&hdg);
121 >                creatholo(hdg);
122          } else                                  /* else just set defaults */
123                  setdefaults(NULL);
124                                                  /* initialize */
# Line 262 | Line 264 | memerr:
264  
265   rholo()                         /* holodeck main loop */
266   {
267 <        static int      idle = 1;
267 >        static int      idle = 0;
268          PACKET  *pl = NULL, *plend;
269          register PACKET *p;
270          time_t  t;
271          long    l;
272 <
273 <        if (outdev != NULL)             /* check display */
272 <                if (!disp_check(idle))
273 <                        return(0);
274 <                                        /* display only? */
275 <        if (nprocs <= 0) {
272 >                                        /* check display */
273 >        if (nprocs <= 0)
274                  idle = 1;
275 <                return(outdev != NULL);
276 <        }
275 >        if (outdev != NULL) {
276 >                if (!disp_check(idle))
277 >                        return(0);      /* quit request */
278 >                if (nprocs <= 0)
279 >                        return(1);
280 >        } else if (idle)
281 >                return(0);              /* all done */
282                                          /* check file size */
283          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
284                  error(WARNING, "file limit exceeded");
# Line 315 | Line 318 | register HDGRID        *gp;
318   {
319          extern char     *atos();
320          register int    i;
321 +        int     n;
322          double  len[3], maxlen, d;
323          char    buf[64];
324  
# Line 322 | Line 326 | register HDGRID        *gp;
326                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
327                  error(USER, errmsg);
328          }
325        if (vdef(SECTION) > 1) {
326                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
327                error(WARNING, errmsg);
328        }
329          if (!vdef(OCTREE)) {
330                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
331                          error(SYSTEM, "out of memory");
# Line 343 | Line 343 | register HDGRID        *gp;
343          if (gp == NULL)         /* already initialized? */
344                  return;
345                                  /* set grid parameters */
346 <        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
347 <        if (sscanf(vval(SECTION),
346 >        for (n = 0; n < vdef(SECTION); n++, gp++) {
347 >                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
348 >                if (sscanf(nvalue(SECTION, n),
349                  "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
350 <                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
351 <                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
352 <                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
353 <                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
354 <                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
355 <                badvalue(SECTION);
356 <        maxlen = 0.;
357 <        for (i = 0; i < 3; i++)
358 <                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
359 <                        maxlen = len[i];
360 <        if (!vdef(GRID)) {
361 <                sprintf(buf, "%.4f", maxlen/8.);
362 <                vval(GRID) = savqstr(buf);
363 <                vdef(GRID)++;
350 >                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
351 >                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
352 >                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
353 >                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
354 >                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
355 >                        badvalue(SECTION);
356 >                maxlen = 0.;
357 >                for (i = 0; i < 3; i++)
358 >                        if ((len[i] = VLEN(gp->xv[i])) > maxlen)
359 >                                maxlen = len[i];
360 >                if (!vdef(GRID))
361 >                        d = 0.125*maxlen;
362 >                else if ((d = vflt(GRID)) <= FTINY)
363 >                        badvalue(GRID);
364 >                for (i = 0; i < 3; i++)
365 >                        if (gp->grid[i] <= 0)
366 >                                gp->grid[i] = len[i]/d + (1.-FTINY);
367          }
364        if ((d = vflt(GRID)) <= FTINY)
365                badvalue(GRID);
366        for (i = 0; i < 3; i++)
367                if (gp->grid[i] <= 0)
368                        gp->grid[i] = len[i]/d + (1.-FTINY);
368   }
369  
370  
# Line 373 | Line 372 | creatholo(gp)                  /* create a holodeck output file */
372   HDGRID  *gp;
373   {
374          extern char     VersionID[];
375 <        long    endloc = 0;
375 >        int4    lastloc, nextloc;
376 >        int     n;
377          int     fd;
378          FILE    *fp;
379                                          /* open & truncate file */
# Line 387 | Line 387 | HDGRID *gp;
387          printvars(fp);
388          fputformat(HOLOFMT, fp);
389          fputc('\n', fp);
390 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
391 <        fwrite(&endloc, sizeof(long), 1, fp);
390 >        putw(HOLOMAGIC, fp);            /* put magic number */
391          fd = dup(fileno(fp));
392          fclose(fp);                     /* flush and close stdio stream */
393 <        hdinit(fd, gp);                 /* allocate and initialize index */
393 >        lastloc = lseek(fd, 0L, 2);
394 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
395 >                nextloc = 0L;
396 >                write(fd, (char *)&nextloc, sizeof(nextloc));
397 >                hdinit(fd, gp);                 /* writes beam index */
398 >                if (!n)
399 >                        break;
400 >                nextloc = hdfilen(fd);          /* write section pointer */
401 >                if (lseek(fd, (long)lastloc, 0) < 0)
402 >                        error(SYSTEM,
403 >                                "cannot seek on holodeck file in creatholo");
404 >                write(fd, (char *)&nextloc, sizeof(nextloc));
405 >                lseek(fd, (long)(lastloc=nextloc), 0);
406 >        }
407   }
408  
409  
# Line 424 | Line 436 | loadholo()                     /* start loading a holodeck from fname */
436          extern long     ftell();
437          FILE    *fp;
438          int     fd;
439 <        long    fpos;
439 >        int     n;
440 >        int4    nextloc;
441                                          /* open holodeck file */
442          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
443                  sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
# Line 439 | Line 452 | loadholo()                     /* start loading a holodeck from fname */
452                                  hdkfile);
453                  error(USER, errmsg);
454          }
455 <        fread(&fpos, sizeof(long), 1, fp);
443 <        if (fpos != 0)
444 <                error(WARNING, "ignoring multiple sections in holodeck file");
445 <        fpos = ftell(fp);                       /* get stdio position */
455 >        nextloc = ftell(fp);                    /* get stdio position */
456          fd = dup(fileno(fp));
457          fclose(fp);                             /* done with stdio */
458 <        lseek(fd, fpos, 0);                     /* align system file pointer */
459 <        hdinit(fd, NULL);                       /* allocate and load index */
458 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
459 >                lseek(fd, (long)nextloc, 0);
460 >                read(fd, (char *)&nextloc, sizeof(nextloc));
461 >                hdinit(fd, NULL);
462 >        }
463 >        if (n != vdef(SECTION)) {
464 >                sprintf(errmsg, "number of sections does not match %s setting",
465 >                                vnam(SECTION));
466 >                error(WARNING, errmsg);
467 >        }
468   }
469  
470  
# Line 473 | Line 491 | PACKET *pl;
491                  p->next = freepacks;
492                  freepacks = p;
493          }
494 <        if (n2flush > 512*RPACKSIZ*nprocs) {
494 >        if (n2flush > 1024*RPACKSIZ*nprocs) {
495                  hdflush(NULL);                  /* flush holodeck buffers */
496                  n2flush = 0;
497          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines