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

Comparing ray/src/rt/data.c (file contents):
Revision 2.2 by greg, Thu Dec 19 14:54:58 1991 UTC vs.
Revision 2.8 by greg, Thu Apr 14 04:50:27 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1993 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "data.h"
20  
21 +                                /* picture memory usage before warning */
22 + #ifndef PSIZWARN
23 + #ifdef BIGMEM
24 + #define PSIZWARN        3000000
25 + #else
26 + #define PSIZWARN        1000000
27 + #endif
28 + #endif
29  
30 + #ifndef TABSIZ
31 + #define TABSIZ          97              /* table size (prime) */
32 + #endif
33 +
34 + #define hash(s)         (shash(s)%TABSIZ)
35 +
36 +
37   extern char  *fgetword();
38  
39 < extern char  *libpath;                  /* library search path */
39 > extern char  *getlibpath();             /* library search path */
40  
41 < static DATARRAY  *dlist = NULL;         /* data array list */
41 > static DATARRAY  *dtab[TABSIZ];         /* data array list */
42  
43 < static DATARRAY  *plist = NULL;         /* picture list */
43 > static DATARRAY  *ptab[TABSIZ];         /* picture list */
44  
45  
46   DATARRAY *
# Line 39 | Line 54 | char  *dname;
54          register int  i, j;
55          register DATARRAY  *dp;
56                                                  /* look for array in list */
57 <        for (dp = dlist; dp != NULL; dp = dp->next)
57 >        for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next)
58                  if (!strcmp(dname, dp->name))
59                          return(dp);             /* found! */
60  
61          /*
62           *      If we haven't loaded the data already, we will look
63 <         *  for it in the directorys specified by the library path.
63 >         *  for it in the directories specified by the library path.
64           *
65           *      The file has the following format:
66           *
# Line 63 | Line 78 | char  *dname;
78           *              0 0 ni p0i p1i .. pni
79           */
80  
81 <        if ((dfname = getpath(dname, libpath, R_OK)) == NULL) {
81 >        if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) {
82                  sprintf(errmsg, "cannot find data file \"%s\"", dname);
83                  error(USER, errmsg);
84          }
# Line 127 | Line 142 | char  *dname;
142                  dp->arr[i] = atof(word);
143          }
144          fclose(fp);
145 <        dp->next = dlist;
146 <        return(dlist = dp);
145 >        i = hash(dname);
146 >        dp->next = dtab[i];
147 >        return(dtab[i] = dp);
148  
149   memerr:
150          error(SYSTEM, "out of memory in getdata");
# Line 139 | Line 155 | scanerr:
155   }
156  
157  
142 static double  inpaspect;               /* aspect ratio of input picture */
143
158   static
159 < headaspect(s)                           /* check string for aspect ratio */
159 > headaspect(s, iap)                      /* check string for aspect ratio */
160   char  *s;
161 + double  *iap;
162   {
163          if (isaspect(s))
164 <                inpaspect *= aspectval(s);
164 >                *iap *= aspectval(s);
165   }
166  
167  
# Line 154 | Line 169 | DATARRAY *
169   getpict(pname)                          /* get picture pname */
170   char  *pname;
171   {
172 <        extern char  *libpath;
172 >        double  inpaspect;
173          char  *pfname;
174          FILE  *fp;
175          COLOR  *scanin;
176          int  sl, ns;
177 <        RESOLU  inpres;
177 >        RESOLU  inpres;
178          FLOAT  loc[2];
179          int  y;
180          register int  x, i;
181          register DATARRAY  *pp;
182                                                  /* look for array in list */
183 <        for (pp = plist; pp != NULL; pp = pp->next)
183 >        for (pp = ptab[hash(pname)]; pp != NULL; pp = pp->next)
184                  if (!strcmp(pname, pp->name))
185                          return(pp);             /* found! */
186  
187 <        if ((pfname = getpath(pname, libpath, R_OK)) == NULL) {
187 >        if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) {
188                  sprintf(errmsg, "cannot find picture file \"%s\"", pname);
189                  error(USER, errmsg);
190          }
# Line 184 | Line 199 | char  *pname;
199                  sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
200                  error(SYSTEM, errmsg);
201          }
202 + #ifdef MSDOS
203 +        setmode(fileno(fp), O_BINARY);
204 + #endif
205                                                  /* get dimensions */
206          inpaspect = 1.0;
207 <        getheader(fp, headaspect);
207 >        getheader(fp, headaspect, &inpaspect);
208          if (!fgetsresolu(&inpres, fp))
209                  goto readerr;
210 + #if PSIZWARN
211 +                                                /* check memory usage */
212 +        i = 3*sizeof(DATATYPE)*inpres.xr*inpres.yr;
213 +        if (i > PSIZWARN) {
214 +                sprintf(errmsg, "picture file \"%s\" using %d bytes of memory",
215 +                                pname, i);
216 +                error(WARNING, errmsg);
217 +        }
218 + #endif
219          for (i = 0; i < 3; i++) {
220                  pp[i].nd = 2;
221                  pp[i].dim[0].ne = inpres.yr;
# Line 229 | Line 256 | char  *pname;
256          }
257          free((char *)scanin);
258          fclose(fp);
259 +        i = hash(pname);
260          pp[0].next =
261          pp[1].next =
262 <        pp[2].next = plist;
263 <        return(plist = pp);
262 >        pp[2].next = ptab[i];
263 >        return(ptab[i] = pp);
264  
265   memerr:
266          error(SYSTEM, "out of memory in getpict");
# Line 245 | Line 273 | readerr:
273   freedata(dname)                 /* free memory associated with dname */
274   char  *dname;
275   {
276 +        DATARRAY  head;
277 +        int  hval, nents;
278          register DATARRAY  *dp, *dpl;
279          register int  i;
280  
281 <        for (dpl = NULL, dp = dlist; dp != NULL; dpl = dp, dp = dp->next)
282 <                if (!strcmp(dname, dp->name)) {
283 <                        if (dpl == NULL)
284 <                                dlist = dp->next;
285 <                        else
281 >        if (dname == NULL) {                    /* free all if NULL */
282 >                hval = 0; nents = TABSIZ;
283 >        } else {
284 >                hval = hash(dname); nents = 1;
285 >        }
286 >        while (nents--) {
287 >                head.next = dtab[hval];
288 >                dpl = &head;
289 >                while ((dp = dpl->next) != NULL)
290 >                        if (dname == NULL || !strcmp(dname, dp->name)) {
291                                  dpl->next = dp->next;
292 <                        free((char *)dp->arr);
293 <                        for (i = 0; i < dp->nd; i++)
294 <                                if (dp->dim[i].p != NULL)
295 <                                        free((char *)dp->dim[i].p);
296 <                        freestr(dp->name);
297 <                        free((char *)dp);
298 <                        return;
299 <                }
292 >                                free((char *)dp->arr);
293 >                                for (i = 0; i < dp->nd; i++)
294 >                                        if (dp->dim[i].p != NULL)
295 >                                                free((char *)dp->dim[i].p);
296 >                                freestr(dp->name);
297 >                                free((char *)dp);
298 >                        } else
299 >                                dpl = dp;
300 >                dtab[hval++] = head.next;
301 >        }
302   }
303  
304  
305   freepict(pname)                 /* free memory associated with pname */
306   char  *pname;
307   {
308 +        DATARRAY  head;
309 +        int  hval, nents;
310          register DATARRAY  *pp, *ppl;
311  
312 <        for (ppl = NULL, pp = plist; pp != NULL; ppl = pp, pp = pp->next)
313 <                if (!strcmp(pname, pp->name)) {
314 <                        if (ppl == NULL)
315 <                                plist = pp->next;
316 <                        else
312 >        if (pname == NULL) {                    /* free all if NULL */
313 >                hval = 0; nents = TABSIZ;
314 >        } else {
315 >                hval = hash(pname); nents = 1;
316 >        }
317 >        while (nents--) {
318 >                head.next = ptab[hval];
319 >                ppl = &head;
320 >                while ((pp = ppl->next) != NULL)
321 >                        if (pname == NULL || !strcmp(pname, pp->name)) {
322                                  ppl->next = pp->next;
323 <                        free((char *)pp[0].arr);
324 <                        free((char *)pp[1].arr);
325 <                        free((char *)pp[2].arr);
326 <                        freestr(pp[0].name);
327 <                        free((char *)pp);
328 <                        return;
329 <                }
323 >                                free((char *)pp[0].arr);
324 >                                free((char *)pp[1].arr);
325 >                                free((char *)pp[2].arr);
326 >                                freestr(pp[0].name);
327 >                                free((char *)pp);
328 >                        } else
329 >                                ppl = pp;
330 >                ptab[hval++] = head.next;
331 >        }
332   }
333  
334  
335   double
336   datavalue(dp, pt)               /* interpolate data value at a point */
337   register DATARRAY  *dp;
338 < double  *pt;
338 > double  *pt;
339   {
340          DATARRAY  sd;
341          int  asize;
342          int  lower, upper;
343          register int  i;
344 <        double  x, y, y0, y1;
344 >        double  x, y, y0, y1;
345                                          /* set up dimensions for recursion */
346          sd.nd = dp->nd - 1;
347          asize = 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines