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