1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
18 |
|
|
19 |
|
#include "data.h" |
20 |
|
|
21 |
+ |
/* picture memory usage before warning */ |
22 |
+ |
#ifndef PSIZWARN |
23 |
+ |
#ifdef BIGMEM |
24 |
+ |
#define PSIZWARN 3000000 |
25 |
+ |
#else |
26 |
+ |
#define PSIZWARN 1000000 |
27 |
+ |
#endif |
28 |
+ |
#endif |
29 |
|
|
30 |
+ |
#ifndef TABSIZ |
31 |
+ |
#define TABSIZ 97 /* table size (prime) */ |
32 |
+ |
#endif |
33 |
+ |
|
34 |
+ |
#define hash(s) (shash(s)%TABSIZ) |
35 |
+ |
|
36 |
+ |
|
37 |
|
extern char *fgetword(); |
38 |
|
|
39 |
|
extern char *libpath; /* library search path */ |
40 |
|
|
41 |
< |
static DATARRAY *dlist = NULL; /* data array list */ |
41 |
> |
static DATARRAY *dtab[TABSIZ]; /* data array list */ |
42 |
|
|
43 |
< |
static DATARRAY *plist = NULL; /* picture list */ |
43 |
> |
static DATARRAY *ptab[TABSIZ]; /* picture list */ |
44 |
|
|
45 |
|
|
46 |
|
DATARRAY * |
54 |
|
register int i, j; |
55 |
|
register DATARRAY *dp; |
56 |
|
/* look for array in list */ |
57 |
< |
for (dp = dlist; dp != NULL; dp = dp->next) |
57 |
> |
for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next) |
58 |
|
if (!strcmp(dname, dp->name)) |
59 |
|
return(dp); /* found! */ |
60 |
|
|
61 |
|
/* |
62 |
|
* If we haven't loaded the data already, we will look |
63 |
< |
* for it in the directorys specified by the library path. |
63 |
> |
* for it in the directories specified by the library path. |
64 |
|
* |
65 |
|
* The file has the following format: |
66 |
|
* |
142 |
|
dp->arr[i] = atof(word); |
143 |
|
} |
144 |
|
fclose(fp); |
145 |
< |
dp->next = dlist; |
146 |
< |
return(dlist = dp); |
145 |
> |
i = hash(dname); |
146 |
> |
dp->next = dtab[i]; |
147 |
> |
return(dtab[i] = dp); |
148 |
|
|
149 |
|
memerr: |
150 |
|
error(SYSTEM, "out of memory in getdata"); |
181 |
|
register int x, i; |
182 |
|
register DATARRAY *pp; |
183 |
|
/* look for array in list */ |
184 |
< |
for (pp = plist; pp != NULL; pp = pp->next) |
184 |
> |
for (pp = ptab[hash(pname)]; pp != NULL; pp = pp->next) |
185 |
|
if (!strcmp(pname, pp->name)) |
186 |
|
return(pp); /* found! */ |
187 |
|
|
208 |
|
getheader(fp, headaspect, &inpaspect); |
209 |
|
if (!fgetsresolu(&inpres, fp)) |
210 |
|
goto readerr; |
211 |
+ |
#if PSIZWARN |
212 |
+ |
/* check memory usage */ |
213 |
+ |
i = 3*sizeof(DATATYPE)*inpres.xr*inpres.yr; |
214 |
+ |
if (i > PSIZWARN) { |
215 |
+ |
sprintf(errmsg, "picture file \"%s\" using %d bytes of memory", |
216 |
+ |
pname, i); |
217 |
+ |
error(WARNING, errmsg); |
218 |
+ |
} |
219 |
+ |
#endif |
220 |
|
for (i = 0; i < 3; i++) { |
221 |
|
pp[i].nd = 2; |
222 |
|
pp[i].dim[0].ne = inpres.yr; |
257 |
|
} |
258 |
|
free((char *)scanin); |
259 |
|
fclose(fp); |
260 |
+ |
i = hash(pname); |
261 |
|
pp[0].next = |
262 |
|
pp[1].next = |
263 |
< |
pp[2].next = plist; |
264 |
< |
return(plist = pp); |
263 |
> |
pp[2].next = ptab[i]; |
264 |
> |
return(ptab[i] = pp); |
265 |
|
|
266 |
|
memerr: |
267 |
|
error(SYSTEM, "out of memory in getpict"); |
274 |
|
freedata(dname) /* free memory associated with dname */ |
275 |
|
char *dname; |
276 |
|
{ |
277 |
+ |
DATARRAY head; |
278 |
+ |
int hval, nents; |
279 |
|
register DATARRAY *dp, *dpl; |
280 |
|
register int i; |
281 |
|
|
282 |
< |
for (dpl = NULL, dp = dlist; dp != NULL; dpl = dp, dp = dp->next) |
283 |
< |
if (!strcmp(dname, dp->name)) { |
284 |
< |
if (dpl == NULL) |
285 |
< |
dlist = dp->next; |
286 |
< |
else |
282 |
> |
if (dname == NULL) { /* free all if NULL */ |
283 |
> |
hval = 0; nents = TABSIZ; |
284 |
> |
} else { |
285 |
> |
hval = hash(dname); nents = 1; |
286 |
> |
} |
287 |
> |
while (nents--) { |
288 |
> |
head.next = dtab[hval]; |
289 |
> |
dpl = &head; |
290 |
> |
while ((dp = dpl->next) != NULL) |
291 |
> |
if (dname == NULL || !strcmp(dname, dp->name)) { |
292 |
|
dpl->next = dp->next; |
293 |
< |
free((char *)dp->arr); |
294 |
< |
for (i = 0; i < dp->nd; i++) |
295 |
< |
if (dp->dim[i].p != NULL) |
296 |
< |
free((char *)dp->dim[i].p); |
297 |
< |
freestr(dp->name); |
298 |
< |
free((char *)dp); |
299 |
< |
return; |
300 |
< |
} |
293 |
> |
free((char *)dp->arr); |
294 |
> |
for (i = 0; i < dp->nd; i++) |
295 |
> |
if (dp->dim[i].p != NULL) |
296 |
> |
free((char *)dp->dim[i].p); |
297 |
> |
freestr(dp->name); |
298 |
> |
free((char *)dp); |
299 |
> |
} else |
300 |
> |
dpl = dp; |
301 |
> |
dtab[hval++] = head.next; |
302 |
> |
} |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
freepict(pname) /* free memory associated with pname */ |
307 |
|
char *pname; |
308 |
|
{ |
309 |
+ |
DATARRAY head; |
310 |
+ |
int hval, nents; |
311 |
|
register DATARRAY *pp, *ppl; |
312 |
|
|
313 |
< |
for (ppl = NULL, pp = plist; pp != NULL; ppl = pp, pp = pp->next) |
314 |
< |
if (!strcmp(pname, pp->name)) { |
315 |
< |
if (ppl == NULL) |
316 |
< |
plist = pp->next; |
317 |
< |
else |
313 |
> |
if (pname == NULL) { /* free all if NULL */ |
314 |
> |
hval = 0; nents = TABSIZ; |
315 |
> |
} else { |
316 |
> |
hval = hash(pname); nents = 1; |
317 |
> |
} |
318 |
> |
while (nents--) { |
319 |
> |
head.next = ptab[hval]; |
320 |
> |
ppl = &head; |
321 |
> |
while ((pp = ppl->next) != NULL) |
322 |
> |
if (pname == NULL || !strcmp(pname, pp->name)) { |
323 |
|
ppl->next = pp->next; |
324 |
< |
free((char *)pp[0].arr); |
325 |
< |
free((char *)pp[1].arr); |
326 |
< |
free((char *)pp[2].arr); |
327 |
< |
freestr(pp[0].name); |
328 |
< |
free((char *)pp); |
329 |
< |
return; |
330 |
< |
} |
324 |
> |
free((char *)pp[0].arr); |
325 |
> |
free((char *)pp[1].arr); |
326 |
> |
free((char *)pp[2].arr); |
327 |
> |
freestr(pp[0].name); |
328 |
> |
free((char *)pp); |
329 |
> |
} else |
330 |
> |
ppl = pp; |
331 |
> |
ptab[hval++] = head.next; |
332 |
> |
} |
333 |
|
} |
334 |
|
|
335 |
|
|