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.12 by greg, Thu Feb 15 18:46:54 1996 UTC vs.
Revision 2.18 by greg, Thu May 15 05:13:35 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  data.c - routines dealing with interpolated data.
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "standard.h"
11  
12   #include  "color.h"
# Line 18 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18                                  /* picture memory usage before warning */
19   #ifndef PSIZWARN
20 < #ifdef BIGMEM
21 < #define PSIZWARN        3000000
20 > #ifdef SMLMEM
21 > #define PSIZWARN        1500000
22   #else
23 < #define PSIZWARN        1000000
23 > #define PSIZWARN        5000000
24   #endif
25   #endif
26  
# Line 32 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31   #define hash(s)         (shash(s)%TABSIZ)
32  
33  
35 extern char  *getlibpath();             /* library search path */
36
34   static DATARRAY  *dtab[TABSIZ];         /* data array list */
35  
36  
# Line 50 | Line 47 | char  *dname;
47          for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next)
48                  if (!strcmp(dname, dp->name))
49                          return(dp);             /* found! */
53
50          /*
51           *      If we haven't loaded the data already, we will look
52           *  for it in the directories specified by the library path.
# Line 71 | Line 67 | char  *dname;
67           *              0 0 ni p0i p1i .. pni
68           */
69  
70 <        if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) {
70 >        if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) {
71                  sprintf(errmsg, "cannot find data file \"%s\"", dname);
72                  error(USER, errmsg);
73          }
# Line 80 | Line 76 | char  *dname;
76                  error(SYSTEM, errmsg);
77          }
78                                                          /* get dimensions */
79 <        if (fgetval(fp, 'i', &asize) <= 0)
79 >        if (fgetval(fp, 'i', (char *)&asize) <= 0)
80                  goto scanerr;
81          if (asize <= 0 | asize > MAXDDIM) {
82                  sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
# Line 93 | Line 89 | char  *dname;
89          dp->nd = asize;
90          asize = 1;
91          for (i = 0; i < dp->nd; i++) {
92 <                if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0)
92 >                if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0)
93                          goto scanerr;
94 <                if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0)
94 >                if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0)
95                          goto scanerr;
96 <                if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0)
96 >                if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0)
97                          goto scanerr;
98                  if (dp->dim[i].ne < 2)
99                          goto scanerr;
# Line 108 | Line 104 | char  *dname;
104                          if (dp->dim[i].p == NULL)
105                                  goto memerr;
106                          for (j = 0; j < dp->dim[i].ne; j++)
107 <                                if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0)
107 >                                if (fgetval(fp, DATATY,
108 >                                                (char *)&dp->dim[i].p[j]) <= 0)
109                                          goto scanerr;
110                          for (j = 1; j < dp->dim[i].ne-1; j++)
111                                  if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) !=
# Line 124 | Line 121 | char  *dname;
121                  goto memerr;
122          
123          for (i = 0; i < asize; i++)
124 <                if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0)
124 >                if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0)
125                          goto scanerr;
126          fclose(fp);
127          i = hash(dname);
# Line 140 | Line 137 | scanerr:
137   }
138  
139  
140 < static
140 > static int
141   headaspect(s, iap)                      /* check string for aspect ratio */
142   char  *s;
143   double  *iap;
144   {
145 +        char    fmt[32];
146 +
147          if (isaspect(s))
148                  *iap *= aspectval(s);
149 +        else if (formatval(fmt, s) && !globmatch(PICFMT, fmt))
150 +                *iap = 0.0;
151 +        return(0);
152   }
153  
154  
# Line 169 | Line 171 | char  *pname;
171                  if (!strcmp(pname, pp->name))
172                          return(pp);             /* found! */
173  
174 <        if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) {
174 >        if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) {
175                  sprintf(errmsg, "cannot find picture file \"%s\"", pname);
176                  error(USER, errmsg);
177          }
# Line 187 | Line 189 | char  *pname;
189   #endif
190                                                  /* get dimensions */
191          inpaspect = 1.0;
192 <        getheader(fp, headaspect, &inpaspect);
193 <        if (!fgetsresolu(&inpres, fp))
192 >        getheader(fp, headaspect, (char *)&inpaspect);
193 >        if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp))
194                  goto readerr;
195          pp[0].nd = 2;
196          pp[0].dim[0].ne = inpres.yr;
# Line 230 | Line 232 | char  *pname;
232                          copycolr(pp[0].arr.c[i], scanin[x]);
233                  }
234          }
235 <        free((char *)scanin);
235 >        free((void *)scanin);
236          fclose(fp);
237          i = hash(pname);
238          pp[0].next = dtab[i];           /* link into picture list */
# Line 249 | Line 251 | readerr:
251   }
252  
253  
254 < freedata(dname)                 /* free memory associated with dname */
255 < char  *dname;
254 > void
255 > freedata(dta)                   /* release data array reference */
256 > DATARRAY  *dta;
257   {
258          DATARRAY  head;
259          int  hval, nents;
260 <        register DATARRAY  *dp, *dpl;
260 >        register DATARRAY  *dpl, *dp;
261          register int  i;
262  
263 <        if (dname == NULL) {                    /* free all if NULL */
263 >        if (dta == NULL) {                      /* free all if NULL */
264                  hval = 0; nents = TABSIZ;
265          } else {
266 <                hval = hash(dname); nents = 1;
266 >                hval = hash(dta->name); nents = 1;
267          }
268          while (nents--) {
269                  head.next = dtab[hval];
270                  dpl = &head;
271                  while ((dp = dpl->next) != NULL)
272 <                        if (dname == NULL || !strcmp(dname, dp->name)) {
272 >                        if ((dta == NULL | dta == dp)) {
273                                  dpl->next = dp->next;
274                                  if (dp->type == DATATY)
275 <                                        free((char *)dp->arr.d);
275 >                                        free((void *)dp->arr.d);
276                                  else
277 <                                        free((char *)dp->arr.c);
277 >                                        free((void *)dp->arr.c);
278                                  for (i = 0; i < dp->nd; i++)
279                                          if (dp->dim[i].p != NULL)
280 <                                                free((char *)dp->dim[i].p);
280 >                                                free((void *)dp->dim[i].p);
281                                  freestr(dp->name);
282 <                                free((char *)dp);
282 >                                free((void *)dp);
283                          } else
284                                  dpl = dp;
285                  dtab[hval++] = head.next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines