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.45 by gwlarson, Wed Aug 12 18:16:07 1998 UTC vs.
Revision 2.46 by gwlarson, Sun Jan 10 12:45:19 1999 UTC

# Line 124 | Line 124 | double  newa;
124   setambient(afile)                       /* initialize calculation */
125   char  *afile;
126   {
127 +        int     readonly = 0;
128          long  pos, flen;
129          AMBVAL  amb;
130                                                  /* init ambient limits */
# Line 138 | Line 139 | char  *afile;
139                  return;
140          }
141                                                  /* open ambient file */
142 <        if ((ambfp = fopen(afile, "r+")) != NULL) {
143 <                initambfile(0);
142 >        if ((ambfp = fopen(afile, "r+")) == NULL)
143 >                readonly = (ambfp = fopen(afile, "r")) != NULL;
144 >        if (ambfp != NULL) {
145 >                initambfile(0);                 /* file exists */
146                  pos = ftell(ambfp);
147                  while (readambval(&amb, ambfp))
148                          avinsert(avstore(&amb));
149 <                                                /* align */
149 >                nambshare = nambvals;           /* share loaded values */
150 >                if (readonly) {
151 >                        sprintf(errmsg,
152 >                                "loaded %u values from read-only ambient file",
153 >                                        nambvals);
154 >                        error(WARNING, errmsg);
155 >                        fclose(ambfp);          /* close file so no writes */
156 >                        ambfp = NULL;
157 >                        return;                 /* avoid ambsync() */
158 >                }
159 >                                                /* align file pointer */
160                  pos += (long)nambvals*AMBVALSIZ;
161                  flen = lseek(fileno(ambfp), 0L, 2);
162                  if (flen != pos) {
# Line 154 | Line 167 | char  *afile;
167                          fseek(ambfp, pos, 0);
168                          ftruncate(fileno(ambfp), pos);
169                  }
170 <                nambshare = nambvals;
171 <        } else if ((ambfp = fopen(afile, "w+")) != NULL)
172 <                initambfile(1);
160 <        else {
170 >        } else if ((ambfp = fopen(afile, "w+")) != NULL) {
171 >                initambfile(1);                 /* else create new file */
172 >        } else {
173                  sprintf(errmsg, "cannot open ambient file \"%s\"", afile);
174                  error(SYSTEM, errmsg);
175          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines