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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines