1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
19 |
|
#include "data.h" |
20 |
|
|
21 |
|
|
22 |
+ |
#define TABSIZ 97 /* table size (prime) */ |
23 |
+ |
|
24 |
+ |
#define hash(s) (shash(s)%TABSIZ) |
25 |
+ |
|
26 |
+ |
|
27 |
|
extern char *fgetword(); |
28 |
|
|
29 |
|
extern char *libpath; /* library search path */ |
30 |
|
|
31 |
< |
static DATARRAY *dlist = NULL; /* data array list */ |
31 |
> |
static DATARRAY *dtab[TABSIZ]; /* data array list */ |
32 |
|
|
33 |
< |
static DATARRAY *plist = NULL; /* picture list */ |
33 |
> |
static DATARRAY *ptab[TABSIZ]; /* picture list */ |
34 |
|
|
35 |
|
|
36 |
|
DATARRAY * |
44 |
|
register int i, j; |
45 |
|
register DATARRAY *dp; |
46 |
|
/* look for array in list */ |
47 |
< |
for (dp = dlist; dp != NULL; dp = dp->next) |
47 |
> |
for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next) |
48 |
|
if (!strcmp(dname, dp->name)) |
49 |
|
return(dp); /* found! */ |
50 |
|
|
51 |
|
/* |
52 |
|
* If we haven't loaded the data already, we will look |
53 |
< |
* for it in the directorys specified by the library path. |
53 |
> |
* for it in the directories specified by the library path. |
54 |
|
* |
55 |
|
* The file has the following format: |
56 |
|
* |
132 |
|
dp->arr[i] = atof(word); |
133 |
|
} |
134 |
|
fclose(fp); |
135 |
< |
dp->next = dlist; |
136 |
< |
return(dlist = dp); |
135 |
> |
i = hash(dname); |
136 |
> |
dp->next = dtab[i]; |
137 |
> |
return(dtab[i] = dp); |
138 |
|
|
139 |
|
memerr: |
140 |
|
error(SYSTEM, "out of memory in getdata"); |
145 |
|
} |
146 |
|
|
147 |
|
|
142 |
– |
static double inpaspect; /* aspect ratio of input picture */ |
143 |
– |
|
148 |
|
static |
149 |
< |
headaspect(s) /* check string for aspect ratio */ |
149 |
> |
headaspect(s, iap) /* check string for aspect ratio */ |
150 |
|
char *s; |
151 |
+ |
double *iap; |
152 |
|
{ |
153 |
|
if (isaspect(s)) |
154 |
< |
inpaspect *= aspectval(s); |
154 |
> |
*iap *= aspectval(s); |
155 |
|
} |
156 |
|
|
157 |
|
|
160 |
|
char *pname; |
161 |
|
{ |
162 |
|
extern char *libpath; |
163 |
+ |
double inpaspect; |
164 |
|
char *pfname; |
165 |
|
FILE *fp; |
166 |
|
COLOR *scanin; |
167 |
|
int sl, ns; |
168 |
< |
RESOLU inpres; |
168 |
> |
RESOLU inpres; |
169 |
|
FLOAT loc[2]; |
170 |
|
int y; |
171 |
|
register int x, i; |
172 |
|
register DATARRAY *pp; |
173 |
|
/* look for array in list */ |
174 |
< |
for (pp = plist; pp != NULL; pp = pp->next) |
174 |
> |
for (pp = ptab[hash(pname)]; pp != NULL; pp = pp->next) |
175 |
|
if (!strcmp(pname, pp->name)) |
176 |
|
return(pp); /* found! */ |
177 |
|
|
190 |
|
sprintf(errmsg, "cannot open picture file \"%s\"", pfname); |
191 |
|
error(SYSTEM, errmsg); |
192 |
|
} |
193 |
+ |
#ifdef MSDOS |
194 |
+ |
setmode(fileno(fp), O_BINARY); |
195 |
+ |
#endif |
196 |
|
/* get dimensions */ |
197 |
|
inpaspect = 1.0; |
198 |
< |
getheader(fp, headaspect); |
198 |
> |
getheader(fp, headaspect, &inpaspect); |
199 |
|
if (!fgetsresolu(&inpres, fp)) |
200 |
|
goto readerr; |
201 |
|
for (i = 0; i < 3; i++) { |
238 |
|
} |
239 |
|
free((char *)scanin); |
240 |
|
fclose(fp); |
241 |
+ |
i = hash(pname); |
242 |
|
pp[0].next = |
243 |
|
pp[1].next = |
244 |
< |
pp[2].next = plist; |
245 |
< |
return(plist = pp); |
244 |
> |
pp[2].next = ptab[i]; |
245 |
> |
return(ptab[i] = pp); |
246 |
|
|
247 |
|
memerr: |
248 |
|
error(SYSTEM, "out of memory in getpict"); |
255 |
|
freedata(dname) /* free memory associated with dname */ |
256 |
|
char *dname; |
257 |
|
{ |
258 |
+ |
DATARRAY head; |
259 |
+ |
int hval, nents; |
260 |
|
register DATARRAY *dp, *dpl; |
261 |
|
register int i; |
262 |
|
|
263 |
< |
for (dpl = NULL, dp = dlist; dp != NULL; dpl = dp, dp = dp->next) |
264 |
< |
if (!strcmp(dname, dp->name)) { |
265 |
< |
if (dpl == NULL) |
266 |
< |
dlist = dp->next; |
267 |
< |
else |
263 |
> |
if (dname == NULL) { /* free all if NULL */ |
264 |
> |
hval = 0; nents = TABSIZ; |
265 |
> |
} else { |
266 |
> |
hval = hash(dname); nents = 1; |
267 |
> |
} |
268 |
> |
while (nents--) { |
269 |
> |
head.next = dtab[hval]; |
270 |
> |
dpl = &head; |
271 |
> |
while ((dp = dpl->next) != NULL) |
272 |
> |
if (dname == NULL || !strcmp(dname, dp->name)) { |
273 |
|
dpl->next = dp->next; |
274 |
< |
free((char *)dp->arr); |
275 |
< |
for (i = 0; i < dp->nd; i++) |
276 |
< |
if (dp->dim[i].p != NULL) |
277 |
< |
free((char *)dp->dim[i].p); |
278 |
< |
freestr(dp->name); |
279 |
< |
free((char *)dp); |
280 |
< |
return; |
281 |
< |
} |
274 |
> |
free((char *)dp->arr); |
275 |
> |
for (i = 0; i < dp->nd; i++) |
276 |
> |
if (dp->dim[i].p != NULL) |
277 |
> |
free((char *)dp->dim[i].p); |
278 |
> |
freestr(dp->name); |
279 |
> |
free((char *)dp); |
280 |
> |
} else |
281 |
> |
dpl = dp; |
282 |
> |
dtab[hval++] = head.next; |
283 |
> |
} |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
freepict(pname) /* free memory associated with pname */ |
288 |
|
char *pname; |
289 |
|
{ |
290 |
+ |
DATARRAY head; |
291 |
+ |
int hval, nents; |
292 |
|
register DATARRAY *pp, *ppl; |
293 |
|
|
294 |
< |
for (ppl = NULL, pp = plist; pp != NULL; ppl = pp, pp = pp->next) |
295 |
< |
if (!strcmp(pname, pp->name)) { |
296 |
< |
if (ppl == NULL) |
297 |
< |
plist = pp->next; |
298 |
< |
else |
294 |
> |
if (pname == NULL) { /* free all if NULL */ |
295 |
> |
hval = 0; nents = TABSIZ; |
296 |
> |
} else { |
297 |
> |
hval = hash(pname); nents = 1; |
298 |
> |
} |
299 |
> |
while (nents--) { |
300 |
> |
head.next = ptab[hval]; |
301 |
> |
ppl = &head; |
302 |
> |
while ((pp = ppl->next) != NULL) |
303 |
> |
if (pname == NULL || !strcmp(pname, pp->name)) { |
304 |
|
ppl->next = pp->next; |
305 |
< |
free((char *)pp[0].arr); |
306 |
< |
free((char *)pp[1].arr); |
307 |
< |
free((char *)pp[2].arr); |
308 |
< |
freestr(pp[0].name); |
309 |
< |
free((char *)pp); |
310 |
< |
return; |
311 |
< |
} |
305 |
> |
free((char *)pp[0].arr); |
306 |
> |
free((char *)pp[1].arr); |
307 |
> |
free((char *)pp[2].arr); |
308 |
> |
freestr(pp[0].name); |
309 |
> |
free((char *)pp); |
310 |
> |
} else |
311 |
> |
ppl = pp; |
312 |
> |
ptab[hval++] = head.next; |
313 |
> |
} |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
double |
318 |
|
datavalue(dp, pt) /* interpolate data value at a point */ |
319 |
|
register DATARRAY *dp; |
320 |
< |
double *pt; |
320 |
> |
double *pt; |
321 |
|
{ |
322 |
|
DATARRAY sd; |
323 |
|
int asize; |
324 |
|
int lower, upper; |
325 |
|
register int i; |
326 |
< |
double x, y, y0, y1; |
326 |
> |
double x, y, y0, y1; |
327 |
|
/* set up dimensions for recursion */ |
328 |
|
sd.nd = dp->nd - 1; |
329 |
|
asize = 1; |