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 */ |
39 |
> |
extern char *getlibpath(); /* 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 |
|
|
78 |
|
* 0 0 ni p0i p1i .. pni |
79 |
|
*/ |
80 |
|
|
81 |
< |
if ((dfname = getpath(dname, libpath, R_OK)) == NULL) { |
81 |
> |
if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) { |
82 |
|
sprintf(errmsg, "cannot find data file \"%s\"", dname); |
83 |
|
error(USER, errmsg); |
84 |
|
} |
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"); |
169 |
|
getpict(pname) /* get picture pname */ |
170 |
|
char *pname; |
171 |
|
{ |
156 |
– |
extern char *libpath; |
172 |
|
double inpaspect; |
173 |
|
char *pfname; |
174 |
|
FILE *fp; |
180 |
|
register int x, i; |
181 |
|
register DATARRAY *pp; |
182 |
|
/* look for array in list */ |
183 |
< |
for (pp = plist; pp != NULL; pp = pp->next) |
183 |
> |
for (pp = ptab[hash(pname)]; pp != NULL; pp = pp->next) |
184 |
|
if (!strcmp(pname, pp->name)) |
185 |
|
return(pp); /* found! */ |
186 |
|
|
187 |
< |
if ((pfname = getpath(pname, libpath, R_OK)) == NULL) { |
187 |
> |
if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) { |
188 |
|
sprintf(errmsg, "cannot find picture file \"%s\"", pname); |
189 |
|
error(USER, errmsg); |
190 |
|
} |
207 |
|
getheader(fp, headaspect, &inpaspect); |
208 |
|
if (!fgetsresolu(&inpres, fp)) |
209 |
|
goto readerr; |
210 |
+ |
#if PSIZWARN |
211 |
+ |
/* check memory usage */ |
212 |
+ |
i = 3*sizeof(DATATYPE)*inpres.xr*inpres.yr; |
213 |
+ |
if (i > PSIZWARN) { |
214 |
+ |
sprintf(errmsg, "picture file \"%s\" using %d bytes of memory", |
215 |
+ |
pname, i); |
216 |
+ |
error(WARNING, errmsg); |
217 |
+ |
} |
218 |
+ |
#endif |
219 |
|
for (i = 0; i < 3; i++) { |
220 |
|
pp[i].nd = 2; |
221 |
|
pp[i].dim[0].ne = inpres.yr; |
256 |
|
} |
257 |
|
free((char *)scanin); |
258 |
|
fclose(fp); |
259 |
+ |
i = hash(pname); |
260 |
|
pp[0].next = |
261 |
|
pp[1].next = |
262 |
< |
pp[2].next = plist; |
263 |
< |
return(plist = pp); |
262 |
> |
pp[2].next = ptab[i]; |
263 |
> |
return(ptab[i] = pp); |
264 |
|
|
265 |
|
memerr: |
266 |
|
error(SYSTEM, "out of memory in getpict"); |
274 |
|
char *dname; |
275 |
|
{ |
276 |
|
DATARRAY head; |
277 |
+ |
int hval, nents; |
278 |
|
register DATARRAY *dp, *dpl; |
279 |
|
register int i; |
280 |
|
|
281 |
< |
head.next = dlist; |
282 |
< |
dpl = &head; |
283 |
< |
while ((dp = dpl->next) != NULL) |
284 |
< |
if (dname == NULL || !strcmp(dname, dp->name)) { |
285 |
< |
dpl->next = dp->next; |
286 |
< |
free((char *)dp->arr); |
287 |
< |
for (i = 0; i < dp->nd; i++) |
288 |
< |
if (dp->dim[i].p != NULL) |
289 |
< |
free((char *)dp->dim[i].p); |
290 |
< |
freestr(dp->name); |
291 |
< |
free((char *)dp); |
292 |
< |
} else |
293 |
< |
dpl = dp; |
294 |
< |
dlist = head.next; |
281 |
> |
if (dname == NULL) { /* free all if NULL */ |
282 |
> |
hval = 0; nents = TABSIZ; |
283 |
> |
} else { |
284 |
> |
hval = hash(dname); nents = 1; |
285 |
> |
} |
286 |
> |
while (nents--) { |
287 |
> |
head.next = dtab[hval]; |
288 |
> |
dpl = &head; |
289 |
> |
while ((dp = dpl->next) != NULL) |
290 |
> |
if (dname == NULL || !strcmp(dname, dp->name)) { |
291 |
> |
dpl->next = dp->next; |
292 |
> |
free((char *)dp->arr); |
293 |
> |
for (i = 0; i < dp->nd; i++) |
294 |
> |
if (dp->dim[i].p != NULL) |
295 |
> |
free((char *)dp->dim[i].p); |
296 |
> |
freestr(dp->name); |
297 |
> |
free((char *)dp); |
298 |
> |
} else |
299 |
> |
dpl = dp; |
300 |
> |
dtab[hval++] = head.next; |
301 |
> |
} |
302 |
|
} |
303 |
|
|
304 |
|
|
306 |
|
char *pname; |
307 |
|
{ |
308 |
|
DATARRAY head; |
309 |
+ |
int hval, nents; |
310 |
|
register DATARRAY *pp, *ppl; |
311 |
|
|
312 |
< |
head.next = plist; |
313 |
< |
ppl = &head; |
314 |
< |
while ((pp = ppl->next) != NULL) |
315 |
< |
if (pname == NULL || !strcmp(pname, pp->name)) { |
316 |
< |
ppl->next = pp->next; |
317 |
< |
free((char *)pp[0].arr); |
318 |
< |
free((char *)pp[1].arr); |
319 |
< |
free((char *)pp[2].arr); |
320 |
< |
freestr(pp[0].name); |
321 |
< |
free((char *)pp); |
322 |
< |
} else |
323 |
< |
ppl = pp; |
324 |
< |
plist = head.next; |
312 |
> |
if (pname == NULL) { /* free all if NULL */ |
313 |
> |
hval = 0; nents = TABSIZ; |
314 |
> |
} else { |
315 |
> |
hval = hash(pname); nents = 1; |
316 |
> |
} |
317 |
> |
while (nents--) { |
318 |
> |
head.next = ptab[hval]; |
319 |
> |
ppl = &head; |
320 |
> |
while ((pp = ppl->next) != NULL) |
321 |
> |
if (pname == NULL || !strcmp(pname, pp->name)) { |
322 |
> |
ppl->next = pp->next; |
323 |
> |
free((char *)pp[0].arr); |
324 |
> |
free((char *)pp[1].arr); |
325 |
> |
free((char *)pp[2].arr); |
326 |
> |
freestr(pp[0].name); |
327 |
> |
free((char *)pp); |
328 |
> |
} else |
329 |
> |
ppl = pp; |
330 |
> |
ptab[hval++] = head.next; |
331 |
> |
} |
332 |
|
} |
333 |
|
|
334 |
|
|