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 |
|
|
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 |
+ |
|
41 |
|
DATARRAY * |
42 |
< |
getdata(dname) /* get data array dname */ |
43 |
< |
char *dname; |
42 |
> |
getdata( /* get data array dname */ |
43 |
> |
char *dname |
44 |
> |
) |
45 |
|
{ |
46 |
|
char *dfname; |
47 |
|
FILE *fp; |
48 |
< |
int asize; |
49 |
< |
register int i, j; |
50 |
< |
register DATARRAY *dp; |
48 |
> |
int asize=0; |
49 |
> |
int i, j; |
50 |
> |
DATARRAY *dp; |
51 |
|
/* look for array in list */ |
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. |
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 |
|
} |
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 |
|
} |
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; |
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]) != |
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); |
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; |
163 |
> |
getpict( /* get picture pname */ |
164 |
> |
char *pname |
165 |
> |
) |
166 |
|
{ |
167 |
|
double inpaspect; |
168 |
|
char *pfname; |
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; |
175 |
> |
int x, i; |
176 |
> |
DATARRAY *pp; |
177 |
|
/* look for array in list */ |
178 |
|
for (pp = dtab[hash(pname)]; pp != NULL; pp = pp->next) |
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 |
|
} |
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; |
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 |
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; |
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 |
> |
void |
262 |
> |
freedata( /* release data array reference */ |
263 |
> |
DATARRAY *dta |
264 |
> |
) |
265 |
|
{ |
266 |
|
DATARRAY head; |
267 |
|
int hval, nents; |
268 |
< |
register DATARRAY *dp, *dpl; |
269 |
< |
register int i; |
268 |
> |
DATARRAY *dpl, *dp; |
269 |
> |
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; |
296 |
|
|
297 |
|
|
298 |
|
double |
299 |
< |
datavalue(dp, pt) /* interpolate data value at a point */ |
300 |
< |
register DATARRAY *dp; |
301 |
< |
double *pt; |
299 |
> |
datavalue( /* interpolate data value at a point */ |
300 |
> |
DATARRAY *dp, |
301 |
> |
double *pt |
302 |
> |
) |
303 |
|
{ |
304 |
|
DATARRAY sd; |
305 |
|
int asize; |
306 |
|
int lower, upper; |
307 |
< |
register int i; |
307 |
> |
int i; |
308 |
|
double x, y0, y1; |
309 |
|
/* set up dimensions for recursion */ |
310 |
|
if (dp->nd > 1) { |