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 "standard.h" |
11 |
|
#include "color.h" |
14 |
– |
|
12 |
|
#include "resolu.h" |
16 |
– |
|
13 |
|
#include "data.h" |
14 |
|
|
15 |
|
/* picture memory usage before warning */ |
16 |
|
#ifndef PSIZWARN |
17 |
< |
#ifdef BIGMEM |
22 |
< |
#define PSIZWARN 5000000 |
23 |
< |
#else |
17 |
> |
#ifdef SMLMEM |
18 |
|
#define PSIZWARN 1500000 |
19 |
+ |
#else |
20 |
+ |
#define PSIZWARN 5000000 |
21 |
|
#endif |
22 |
|
#endif |
23 |
|
|
28 |
|
#define hash(s) (shash(s)%TABSIZ) |
29 |
|
|
30 |
|
|
35 |
– |
extern char *getlibpath(); /* library search path */ |
36 |
– |
|
31 |
|
static DATARRAY *dtab[TABSIZ]; /* data array list */ |
32 |
|
|
33 |
|
|
44 |
|
for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next) |
45 |
|
if (!strcmp(dname, dp->name)) |
46 |
|
return(dp); /* found! */ |
53 |
– |
|
47 |
|
/* |
48 |
|
* If we haven't loaded the data already, we will look |
49 |
|
* for it in the directories specified by the library path. |
64 |
|
* 0 0 ni p0i p1i .. pni |
65 |
|
*/ |
66 |
|
|
67 |
< |
if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) { |
67 |
> |
if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) { |
68 |
|
sprintf(errmsg, "cannot find data file \"%s\"", dname); |
69 |
|
error(USER, errmsg); |
70 |
|
} |
73 |
|
error(SYSTEM, errmsg); |
74 |
|
} |
75 |
|
/* get dimensions */ |
76 |
< |
if (fgetval(fp, 'i', &asize) <= 0) |
76 |
> |
if (fgetval(fp, 'i', (char *)&asize) <= 0) |
77 |
|
goto scanerr; |
78 |
|
if (asize <= 0 | asize > MAXDDIM) { |
79 |
|
sprintf(errmsg, "bad number of dimensions for \"%s\"", dname); |
86 |
|
dp->nd = asize; |
87 |
|
asize = 1; |
88 |
|
for (i = 0; i < dp->nd; i++) { |
89 |
< |
if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0) |
89 |
> |
if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0) |
90 |
|
goto scanerr; |
91 |
< |
if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0) |
91 |
> |
if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0) |
92 |
|
goto scanerr; |
93 |
< |
if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0) |
93 |
> |
if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0) |
94 |
|
goto scanerr; |
95 |
|
if (dp->dim[i].ne < 2) |
96 |
|
goto scanerr; |
101 |
|
if (dp->dim[i].p == NULL) |
102 |
|
goto memerr; |
103 |
|
for (j = 0; j < dp->dim[i].ne; j++) |
104 |
< |
if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0) |
104 |
> |
if (fgetval(fp, DATATY, |
105 |
> |
(char *)&dp->dim[i].p[j]) <= 0) |
106 |
|
goto scanerr; |
107 |
|
for (j = 1; j < dp->dim[i].ne-1; j++) |
108 |
|
if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) != |
118 |
|
goto memerr; |
119 |
|
|
120 |
|
for (i = 0; i < asize; i++) |
121 |
< |
if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0) |
121 |
> |
if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0) |
122 |
|
goto scanerr; |
123 |
|
fclose(fp); |
124 |
|
i = hash(dname); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
< |
static |
137 |
> |
static int |
138 |
|
headaspect(s, iap) /* check string for aspect ratio */ |
139 |
|
char *s; |
140 |
|
double *iap; |
141 |
|
{ |
142 |
+ |
char fmt[32]; |
143 |
+ |
|
144 |
|
if (isaspect(s)) |
145 |
|
*iap *= aspectval(s); |
146 |
+ |
else if (formatval(fmt, s) && !globmatch(PICFMT, fmt)) |
147 |
+ |
*iap = 0.0; |
148 |
+ |
return(0); |
149 |
|
} |
150 |
|
|
151 |
|
|
168 |
|
if (!strcmp(pname, pp->name)) |
169 |
|
return(pp); /* found! */ |
170 |
|
|
171 |
< |
if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) { |
171 |
> |
if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) { |
172 |
|
sprintf(errmsg, "cannot find picture file \"%s\"", pname); |
173 |
|
error(USER, errmsg); |
174 |
|
} |
181 |
|
sprintf(errmsg, "cannot open picture file \"%s\"", pfname); |
182 |
|
error(SYSTEM, errmsg); |
183 |
|
} |
184 |
< |
#ifdef MSDOS |
186 |
< |
setmode(fileno(fp), O_BINARY); |
187 |
< |
#endif |
184 |
> |
SET_FILE_BINARY(fp); |
185 |
|
/* get dimensions */ |
186 |
|
inpaspect = 1.0; |
187 |
< |
getheader(fp, headaspect, &inpaspect); |
188 |
< |
if (!fgetsresolu(&inpres, fp)) |
187 |
> |
getheader(fp, headaspect, (char *)&inpaspect); |
188 |
> |
if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp)) |
189 |
|
goto readerr; |
190 |
|
pp[0].nd = 2; |
191 |
|
pp[0].dim[0].ne = inpres.yr; |
227 |
|
copycolr(pp[0].arr.c[i], scanin[x]); |
228 |
|
} |
229 |
|
} |
230 |
< |
free((char *)scanin); |
230 |
> |
free((void *)scanin); |
231 |
|
fclose(fp); |
232 |
|
i = hash(pname); |
233 |
|
pp[0].next = dtab[i]; /* link into picture list */ |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
< |
freedata(dname) /* free memory associated with dname */ |
250 |
< |
char *dname; |
249 |
> |
void |
250 |
> |
freedata(dta) /* release data array reference */ |
251 |
> |
DATARRAY *dta; |
252 |
|
{ |
253 |
|
DATARRAY head; |
254 |
|
int hval, nents; |
255 |
< |
register DATARRAY *dp, *dpl; |
255 |
> |
register DATARRAY *dpl, *dp; |
256 |
|
register int i; |
257 |
|
|
258 |
< |
if (dname == NULL) { /* free all if NULL */ |
258 |
> |
if (dta == NULL) { /* free all if NULL */ |
259 |
|
hval = 0; nents = TABSIZ; |
260 |
|
} else { |
261 |
< |
hval = hash(dname); nents = 1; |
261 |
> |
hval = hash(dta->name); nents = 1; |
262 |
|
} |
263 |
|
while (nents--) { |
264 |
|
head.next = dtab[hval]; |
265 |
|
dpl = &head; |
266 |
|
while ((dp = dpl->next) != NULL) |
267 |
< |
if (dname == NULL || !strcmp(dname, dp->name)) { |
267 |
> |
if ((dta == NULL | dta == dp)) { |
268 |
|
dpl->next = dp->next; |
269 |
|
if (dp->type == DATATY) |
270 |
< |
free((char *)dp->arr.d); |
270 |
> |
free((void *)dp->arr.d); |
271 |
|
else |
272 |
< |
free((char *)dp->arr.c); |
272 |
> |
free((void *)dp->arr.c); |
273 |
|
for (i = 0; i < dp->nd; i++) |
274 |
|
if (dp->dim[i].p != NULL) |
275 |
< |
free((char *)dp->dim[i].p); |
275 |
> |
free((void *)dp->dim[i].p); |
276 |
|
freestr(dp->name); |
277 |
< |
free((char *)dp); |
277 |
> |
free((void *)dp); |
278 |
|
} else |
279 |
|
dpl = dp; |
280 |
|
dtab[hval++] = head.next; |