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.21 by gregl, Fri Dec 12 18:12:40 1997 UTC

# Line 32 | Line 32 | 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 224 | 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 279 | Line 280 | rholo()                                /* holodeck main loop */
280                  if (!disp_check(idle))
281                          return(0);
282                                          /* display only? */
283 <        if (ncprocs <= 0)
284 <                return(1);
283 >        if (nprocs <= 0)
284 >                return(outdev != NULL);
285                                          /* check file size */
286          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
287                  error(WARNING, "file limit exceeded");
288 <                return(0);
288 >                done_rtrace();
289 >                idle = 1;
290 >                return(1);      /* comes back */
291          }
292                                          /* check time */
293          if (endtime > 0 || reporttime > 0)
294                  t = time(NULL);
295          if (endtime > 0 && t >= endtime) {
296                  error(WARNING, "time limit exceeded");
297 <                return(0);
297 >                done_rtrace();
298 >                idle = 1;
299 >                return(1);      /* comes back */
300          }
301          if (reporttime > 0 && t >= reporttime)
302                  report(t);
# Line 300 | Line 305 | rholo()                                /* holodeck main loop */
305                  p = freepacks; freepacks = p->next; p->next = NULL;
306                  if (!next_packet(p)) {
307                          p->next = freepacks; freepacks = p;
308 +                        idle = 1;
309                          break;
310                  }
311                  if (pl == NULL) pl = p;
312                  else plend->next = p;
313                  plend = p;
314          }
315 <        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 */
315 >                                        /* process packets */
316          done_packets(do_packets(pl));
317          return(1);                      /* and continue */
318   }
# Line 319 | Line 321 | rholo()                                /* holodeck main loop */
321   report(t)                       /* report progress so far */
322   time_t  t;
323   {
324 <        if (t == 0)
324 >        static time_t   seconds2go = 1000000;
325 >
326 >        if (t == 0L)
327                  t = time(NULL);
328 <        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
329 <                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
330 <        fflush(stderr);
331 <        if (vdef(REPORT))
332 <                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
328 >        sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n",
329 >                        npacksdone, nraysdone, (t-starttime)/3600.);
330 >        eputs(errmsg);
331 >        if (seconds2go == 1000000)
332 >                seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L;
333 >        if (seconds2go)
334 >                reporttime = t + seconds2go;
335   }
336  
337  
# Line 500 | Line 506 | PACKET *pl;
506                  p->next = freepacks;
507                  freepacks = p;
508          }
509 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
509 >        if (n2flush > 512*RPACKSIZ*nprocs) {
510                  hdflush(NULL);                  /* flush holodeck buffers */
511                  n2flush = 0;
512          }
513   }
514  
515  
516 + int
517 + done_rtrace()                   /* clean up and close rtrace calculation */
518 + {
519 +        int     status;
520 +                                        /* already closed? */
521 +        if (!nprocs)
522 +                return;
523 +                                        /* report activity */
524 +        wputs("closing rtrace process...\n");
525 +                                        /* flush beam queue */
526 +        done_packets(flush_queue());
527 +                                        /* close rtrace */
528 +        if ((status = end_rtrace()))
529 +                error(WARNING, "bad exit status from rtrace");
530 +        if (vdef(REPORT))               /* report time */
531 +                report(0);
532 +        return(status);                 /* return status */
533 + }
534 +
535 +
536 + new_rtrace()                    /* restart rtrace calculation */
537 + {
538 +        char    combuf[128];
539 +
540 +        if (nprocs > 0)                 /* already running? */
541 +                return;
542 +        wputs("restarting rtrace process...\n");
543 +        if (vdef(RIF)) {                /* rerun rad to update octree */
544 +                sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
545 +                if (system(combuf))
546 +                        error(WARNING, "error running rad");
547 +        }
548 +        if (start_rtrace() < 1)         /* start rtrace */
549 +                error(WARNING, "cannot restart rtrace");
550 +        else if (vdef(REPORT))
551 +                report(0);
552 + }
553 +
554 +
555   getradfile(rfargs)              /* run rad and get needed variables */
556   char    *rfargs;
557   {
# Line 540 | Line 585 | char   *rfargs;
585          else
586                  sprintf(cp, ")[ \t]*=' > %s", tf2);
587          if (system(combuf)) {
543                error(SYSTEM, "cannot execute rad command");
588                  unlink(tf2);                    /* clean up */
589                  unlink(tf1);
590 <                quit(1);
590 >                error(SYSTEM, "cannot execute rad command");
591          }
592          if (pippt == NULL) {
593                  loadvars(tf2);                  /* load variables */
# Line 610 | Line 654 | int    ec;
654          int     status = 0;
655  
656          if (hdlist[0] != NULL) {        /* flush holodeck */
657 <                if (ncprocs > 0) {
658 <                        done_packets(flush_queue());
659 <                        status = end_rtrace();  /* close rtrace */
660 <                        hdflush(NULL);
661 <                        if (vdef(REPORT)) {
662 <                                long    fsiz, fuse;
663 <                                report(0);
664 <                                fsiz = hdfilen(hdlist[0]->fd);
621 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
622 <                                fprintf(stderr,
657 >                if (nprocs > 0)
658 >                        status = done_rtrace();
659 >                hdflush(NULL);
660 >                if (ncprocs > 0 && vdef(REPORT)) {
661 >                        long    fsiz, fuse;
662 >                        fsiz = hdfilen(hdlist[0]->fd);
663 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
664 >                        fprintf(stderr,
665                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
666 <                                                hdkfile, fsiz/(1024.*1024.),
667 <                                                100.*(fsiz-fuse)/fsiz);
668 <                        }
627 <                } else
628 <                        hdflush(NULL);
666 >                                        hdkfile, fsiz/(1024.*1024.),
667 >                                        100.*(fsiz-fuse)/fsiz);
668 >                }
669          }
670          if (orig_mode >= 0)             /* reset holodeck access mode */
671                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines