ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambient.c
(Generate patch)

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.67 by greg, Sat Nov 17 06:21:58 2007 UTC vs.
Revision 2.68 by greg, Thu Oct 14 05:54:44 2010 UTC

# Line 188 | Line 188 | setambient(void)                               /* initialize calculation */
188                  }
189          } else if ((ambfp = fopen(ambfile, "w+")) != NULL) {
190                  initambfile(1);                 /* else create new file */
191 +                fflush(ambfp);
192                  lastpos = ftell(ambfp);
193          } else {
194                  sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile);
195                  error(SYSTEM, errmsg);
196          }
197 <        ambsync();                      /* load previous values */
197 > #ifdef  F_SETLKW
198 >        aflock(F_UNLCK);                        /* release file */
199 > #endif
200   }
201  
202  
# Line 508 | Line 511 | extambient(            /* extrapolate value at pv, nv */
511  
512   static void
513   initambfile(            /* initialize ambient file */
514 <        int  creat
514 >        int  cre8
515   )
516   {
517          extern char  *progname, *octname;
# Line 521 | Line 524 | initambfile(           /* initialize ambient file */
524          if (mybuf == NULL)
525                  mybuf = (char *)bmalloc(BUFSIZ+8);
526          setbuf(ambfp, mybuf);
527 <        if (creat) {                    /* new file */
527 >        if (cre8) {                     /* new file */
528                  newheader("RADIANCE", ambfp);
529                  fprintf(ambfp, "%s -av %g %g %g -aw %d -ab %d -aa %g ",
530                                  progname, colval(ambval,RED),
# Line 530 | Line 533 | initambfile(           /* initialize ambient file */
533                  fprintf(ambfp, "-ad %d -as %d -ar %d ",
534                                  ambdiv, ambssamp, ambres);
535                  if (octname != NULL)
536 <                        printargs(1, &octname, ambfp);
537 <                else
535 <                        fputc('\n', ambfp);
536 >                        fputs(octname, ambfp);
537 >                fputc('\n', ambfp);
538                  fprintf(ambfp, "SOFTWARE= %s\n", VersionID);
539                  fputnow(ambfp);
540                  fputformat(AMBFMT, ambfp);
541 <                putc('\n', ambfp);
541 >                fputc('\n', ambfp);
542                  putambmagic(ambfp);
543          } else if (checkheader(ambfp, AMBFMT, NULL) < 0 || !hasambmagic(ambfp))
544                  error(USER, "bad ambient file");
# Line 886 | Line 888 | ambsync(void)                  /* synchronize ambient file */
888                                  /* see if file has grown */
889          if ((flen = lseek(fileno(ambfp), (off_t)0, SEEK_END)) < 0)
890                  goto seekerr;
891 <        if ( (n = flen - lastpos) ) {           /* file has grown */
891 >        if ((n = flen - lastpos) > 0) {         /* file has grown */
892                  if (ambinp == NULL) {           /* use duplicate filedes */
893                          ambinp = fdopen(dup(fileno(ambfp)), "r");
894                          if (ambinp == NULL)
# Line 911 | Line 913 | ambsync(void)                  /* synchronize ambient file */
913                          if (lseek(fileno(ambfp), (off_t)lastpos, SEEK_SET) < 0)
914                                  goto seekerr;
915          }
914 #ifdef  DEBUG
915        if (ambfp->_ptr - ambfp->_base != nunflshed*AMBVALSIZ) {
916                sprintf(errmsg, "ambient file buffer at %d rather than %d",
917                                ambfp->_ptr - ambfp->_base,
918                                nunflshed*AMBVALSIZ);
919                error(CONSISTENCY, errmsg);
920        }
921 #endif
916          n = fflush(ambfp);                      /* calls write() at last */
917          if (n != EOF)
918                  lastpos += (long)nunflshed*AMBVALSIZ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines