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.13 by gregl, Wed Dec 3 11:06:17 1997 UTC vs.
Revision 2.29 by greg, Tue May 12 16:37:53 2009 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  "standard.h"
8 > #include "copyright.h"
9  
10 < #include  "color.h"
10 > #include  <time.h>
11  
12 + #include  "platform.h"
13 + #include  "paths.h"
14 + #include  "standard.h"
15 + #include  "color.h"
16   #include  "resolu.h"
17 <
17 > #include  "view.h"
18   #include  "data.h"
19  
20                                  /* picture memory usage before warning */
21   #ifndef PSIZWARN
22 < #ifdef BIGMEM
23 < #define PSIZWARN        5000000
22 > #ifdef SMLMEM
23 > #define PSIZWARN        3000000
24   #else
25 < #define PSIZWARN        1500000
25 > #define PSIZWARN        10000000
26   #endif
27   #endif
28  
# Line 32 | Line 33 | static char SCCSid[] = "$SunId$ LBL";
33   #define hash(s)         (shash(s)%TABSIZ)
34  
35  
35 extern char  *getlibpath();             /* library search path */
36
36   static DATARRAY  *dtab[TABSIZ];         /* data array list */
37  
38 + static gethfunc headaspect;
39  
40 < DATARRAY *
41 < getdata(dname)                          /* get data array dname */
42 < char  *dname;
40 >
41 > extern DATARRAY *
42 > getdata(                                /* get data array dname */
43 >        char  *dname
44 > )
45   {
46          char  *dfname;
47          FILE  *fp;
# Line 50 | Line 52 | char  *dname;
52          for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next)
53                  if (!strcmp(dname, dp->name))
54                          return(dp);             /* found! */
53
55          /*
56           *      If we haven't loaded the data already, we will look
57           *  for it in the directories specified by the library path.
# Line 71 | Line 72 | char  *dname;
72           *              0 0 ni p0i p1i .. pni
73           */
74  
75 <        if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) {
75 >        if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) {
76                  sprintf(errmsg, "cannot find data file \"%s\"", dname);
77                  error(USER, errmsg);
78          }
# Line 80 | Line 81 | char  *dname;
81                  error(SYSTEM, errmsg);
82          }
83                                                          /* get dimensions */
84 <        if (fgetval(fp, 'i', &asize) <= 0)
84 >        if (fgetval(fp, 'i', (char *)&asize) <= 0)
85                  goto scanerr;
86 <        if (asize <= 0 | asize > MAXDDIM) {
86 >        if ((asize <= 0) | (asize > MAXDDIM)) {
87                  sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
88                  error(USER, errmsg);
89          }
# Line 93 | Line 94 | char  *dname;
94          dp->nd = asize;
95          asize = 1;
96          for (i = 0; i < dp->nd; i++) {
97 <                if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0)
97 >                if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0)
98                          goto scanerr;
99 <                if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0)
99 >                if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0)
100                          goto scanerr;
101 <                if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0)
101 >                if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0)
102                          goto scanerr;
103                  if (dp->dim[i].ne < 2)
104                          goto scanerr;
# Line 108 | Line 109 | char  *dname;
109                          if (dp->dim[i].p == NULL)
110                                  goto memerr;
111                          for (j = 0; j < dp->dim[i].ne; j++)
112 <                                if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0)
112 >                                if (fgetval(fp, DATATY,
113 >                                                (char *)&dp->dim[i].p[j]) <= 0)
114                                          goto scanerr;
115                          for (j = 1; j < dp->dim[i].ne-1; j++)
116                                  if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) !=
# Line 124 | Line 126 | char  *dname;
126                  goto memerr;
127          
128          for (i = 0; i < asize; i++)
129 <                if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0)
129 >                if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0)
130                          goto scanerr;
131          fclose(fp);
132          i = hash(dname);
# Line 137 | Line 139 | scanerr:
139          sprintf(errmsg, "%s in data file \"%s\"",
140                          feof(fp) ? "unexpected EOF" : "bad format", dfname);
141          error(USER, errmsg);
142 +        return NULL; /* pro forma return */
143   }
144  
145  
146 < static
147 < headaspect(s, iap)                      /* check string for aspect ratio */
148 < char  *s;
149 < double  *iap;
146 > static int
147 > headaspect(                     /* check string for aspect ratio */
148 >        char  *s,
149 >        void  *iap
150 > )
151   {
152 +        char    fmt[32];
153 +
154          if (isaspect(s))
155 <                *iap *= aspectval(s);
155 >                *(double*)iap *= aspectval(s);
156 >        else if (formatval(fmt, s) && !globmatch(PICFMT, fmt))
157 >                *(double*)iap = 0.0;
158 >        return(0);
159   }
160  
161  
162 < DATARRAY *
163 < getpict(pname)                          /* get picture pname */
164 < char  *pname;
162 > extern DATARRAY *
163 > getpict(                                /* get picture pname */
164 >        char  *pname
165 > )
166   {
167          double  inpaspect;
168          char  *pfname;
# Line 160 | Line 170 | char  *pname;
170          COLR  *scanin;
171          int  sl, ns;
172          RESOLU  inpres;
173 <        FLOAT  loc[2];
173 >        RREAL  loc[2];
174          int  y;
175          register int  x, i;
176          register DATARRAY  *pp;
# Line 169 | Line 179 | char  *pname;
179                  if (!strcmp(pname, pp->name))
180                          return(pp);             /* found! */
181  
182 <        if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) {
182 >        if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) {
183                  sprintf(errmsg, "cannot find picture file \"%s\"", pname);
184                  error(USER, errmsg);
185          }
# Line 182 | Line 192 | char  *pname;
192                  sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
193                  error(SYSTEM, errmsg);
194          }
195 < #ifdef MSDOS
186 <        setmode(fileno(fp), O_BINARY);
187 < #endif
195 >        SET_FILE_BINARY(fp);
196                                                  /* get dimensions */
197          inpaspect = 1.0;
198          getheader(fp, headaspect, &inpaspect);
199 <        if (!fgetsresolu(&inpres, fp))
199 >        if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp))
200                  goto readerr;
201          pp[0].nd = 2;
202          pp[0].dim[0].ne = inpres.yr;
# Line 210 | Line 218 | char  *pname;
218          i = ns*sl*sizeof(COLR);
219   #if PSIZWARN
220          if (i > PSIZWARN) {                             /* memory warning */
221 <                sprintf(errmsg, "picture file \"%s\" using %d bytes of memory",
222 <                                pname, i);
221 >                sprintf(errmsg, "picture file \"%s\" using %.1f MB of memory",
222 >                                pname, i*(1.0/(1024*1024)));
223                  error(WARNING, errmsg);
224          }
225   #endif
# Line 230 | Line 238 | char  *pname;
238                          copycolr(pp[0].arr.c[i], scanin[x]);
239                  }
240          }
241 <        free((char *)scanin);
241 >        free((void *)scanin);
242          fclose(fp);
243          i = hash(pname);
244          pp[0].next = dtab[i];           /* link into picture list */
245 <        copystruct(&pp[1], &pp[0]);
246 <        copystruct(&pp[2], &pp[0]);
245 >        pp[1] = pp[0];
246 >        pp[2] = pp[0];
247          pp[0].type = RED;               /* differentiate RGB records */
248          pp[1].type = GRN;
249          pp[2].type = BLU;
# Line 246 | Line 254 | memerr:
254   readerr:
255          sprintf(errmsg, "bad picture file \"%s\"", pfname);
256          error(USER, errmsg);
257 +        return NULL; /* pro forma return */
258   }
259  
260  
261 < freedata(dname)                 /* free memory associated with dname */
262 < char  *dname;
261 > extern void
262 > freedata(                       /* release data array reference */
263 >        DATARRAY  *dta
264 > )
265   {
266          DATARRAY  head;
267          int  hval, nents;
268 <        register DATARRAY  *dp, *dpl;
268 >        register DATARRAY  *dpl, *dp;
269          register int  i;
270  
271 <        if (dname == NULL) {                    /* free all if NULL */
271 >        if (dta == NULL) {                      /* free all if NULL */
272                  hval = 0; nents = TABSIZ;
273          } else {
274 <                hval = hash(dname); nents = 1;
274 >                hval = hash(dta->name); nents = 1;
275          }
276          while (nents--) {
277                  head.next = dtab[hval];
278                  dpl = &head;
279                  while ((dp = dpl->next) != NULL)
280 <                        if (dname == NULL || !strcmp(dname, dp->name)) {
280 >                        if ((dta == NULL) | (dta == dp)) {
281                                  dpl->next = dp->next;
282                                  if (dp->type == DATATY)
283 <                                        free((char *)dp->arr.d);
283 >                                        free((void *)dp->arr.d);
284                                  else
285 <                                        free((char *)dp->arr.c);
285 >                                        free((void *)dp->arr.c);
286                                  for (i = 0; i < dp->nd; i++)
287                                          if (dp->dim[i].p != NULL)
288 <                                                free((char *)dp->dim[i].p);
288 >                                                free((void *)dp->dim[i].p);
289                                  freestr(dp->name);
290 <                                free((char *)dp);
290 >                                free((void *)dp);
291                          } else
292                                  dpl = dp;
293                  dtab[hval++] = head.next;
# Line 284 | Line 295 | char  *dname;
295   }
296  
297  
298 < double
299 < datavalue(dp, pt)               /* interpolate data value at a point */
300 < register DATARRAY  *dp;
301 < double  *pt;
298 > extern double
299 > datavalue(              /* interpolate data value at a point */
300 >        register DATARRAY  *dp,
301 >        double  *pt
302 > )
303   {
304          DATARRAY  sd;
305          int  asize;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines