31 |
|
char *dfname; |
32 |
|
FILE *fp; |
33 |
|
int asize; |
34 |
< |
register int i; |
34 |
> |
register int i, j; |
35 |
|
register DATARRAY *dp; |
36 |
|
/* look for array in list */ |
37 |
|
for (dp = dlist; dp != NULL; dp = dp->next) |
44 |
|
* |
45 |
|
* The file has the following format: |
46 |
|
* |
47 |
< |
* #dimensions |
47 |
> |
* N |
48 |
|
* beg0 end0 n0 |
49 |
|
* beg1 end1 n1 |
50 |
|
* . . . |
51 |
+ |
* begN endN nN |
52 |
|
* data, later dimensions changing faster |
53 |
|
* . . . |
54 |
|
* |
55 |
+ |
* For irregularly spaced points, the following can be |
56 |
+ |
* substituted for begi endi ni: |
57 |
+ |
* |
58 |
+ |
* @ ni p0i p1i .. pni |
59 |
|
*/ |
60 |
|
|
61 |
|
if ((dfname = getpath(dname, libpath, R_OK)) == NULL) { |
82 |
|
for (i = 0; i < dp->nd; i++) { |
83 |
|
if (fscanf(fp, "%lf %lf %d", |
84 |
|
&dp->dim[i].org, &dp->dim[i].siz, |
85 |
< |
&dp->dim[i].ne) != 3) |
85 |
> |
&dp->dim[i].ne) == 3) { |
86 |
> |
dp->dim[i].siz -= dp->dim[i].org; |
87 |
> |
dp->dim[i].p = NULL; |
88 |
> |
} else if (fscanf(fp, "@ %d", &dp->dim[i].ne) == 1) { |
89 |
> |
dp->dim[i].p = (double *)malloc(dp->dim[i].ne*sizeof(double)); |
90 |
> |
if (dp->dim[i].p == NULL) |
91 |
> |
goto memerr; |
92 |
> |
for (j = 0; j < dp->dim[i].ne; j++) |
93 |
> |
if (fscanf(fp, "%lf", &dp->dim[i].p[j]) != 1) |
94 |
> |
goto scanerr; |
95 |
> |
for (j = 1; j < dp->dim[i].ne-1; j++) |
96 |
> |
if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) != |
97 |
> |
(dp->dim[i].p[j] < dp->dim[i].p[j+1])) |
98 |
> |
goto scanerr; |
99 |
> |
dp->dim[i].org = dp->dim[i].p[0]; |
100 |
> |
dp->dim[i].siz = dp->dim[i].p[dp->dim[i].ne-1] |
101 |
> |
- dp->dim[i].p[0]; |
102 |
> |
} else |
103 |
|
goto scanerr; |
104 |
< |
dp->dim[i].siz -= dp->dim[i].org; |
104 |
> |
if (dp->dim[i].siz == 0.0 || dp->dim[i].ne < 2) |
105 |
> |
goto scanerr; |
106 |
|
asize *= dp->dim[i].ne; |
107 |
|
} |
108 |
|
if ((dp->arr = (DATATYPE *)malloc(asize*sizeof(DATATYPE))) == NULL) |
207 |
|
char *dname; |
208 |
|
{ |
209 |
|
register DATARRAY *dp, *dpl; |
210 |
+ |
register int i; |
211 |
|
|
212 |
|
for (dpl = NULL, dp = dlist; dp != NULL; dpl = dp, dp = dp->next) |
213 |
|
if (!strcmp(dname, dp->name)) { |
216 |
|
else |
217 |
|
dpl->next = dp->next; |
218 |
|
free((char *)dp->arr); |
219 |
+ |
for (i = 0; i < dp->nd; i++) |
220 |
+ |
if (dp->dim[i].p != NULL) |
221 |
+ |
free((char *)dp->dim[i].p); |
222 |
|
freestr(dp->name); |
223 |
|
free((char *)dp); |
224 |
|
return; |
256 |
|
int asize; |
257 |
|
register int i; |
258 |
|
double x, y, y0, y1; |
259 |
< |
|
259 |
> |
/* set up dimensions for recursion */ |
260 |
|
sd.nd = dp->nd - 1; |
261 |
|
asize = 1; |
262 |
|
for (i = 0; i < sd.nd; i++) { |
263 |
|
sd.dim[i].org = dp->dim[i+1].org; |
264 |
|
sd.dim[i].siz = dp->dim[i+1].siz; |
265 |
+ |
sd.dim[i].p = dp->dim[i+1].p; |
266 |
|
asize *= sd.dim[i].ne = dp->dim[i+1].ne; |
267 |
|
} |
268 |
< |
|
269 |
< |
x = (pt[0] - dp->dim[0].org)/dp->dim[0].siz; |
270 |
< |
|
271 |
< |
x *= dp->dim[0].ne - 1; |
272 |
< |
|
273 |
< |
i = x; |
274 |
< |
if (i < 0) |
275 |
< |
i = 0; |
276 |
< |
else if (i > dp->dim[0].ne - 2) |
277 |
< |
i = dp->dim[0].ne - 2; |
278 |
< |
|
268 |
> |
/* get independent variable */ |
269 |
> |
if (dp->dim[0].p == NULL) { /* evenly spaced points */ |
270 |
> |
x = (pt[0] - dp->dim[0].org)/dp->dim[0].siz; |
271 |
> |
x = x * (dp->dim[0].ne - 1); |
272 |
> |
i = x; |
273 |
> |
if (i < 0) |
274 |
> |
i = 0; |
275 |
> |
else if (i > dp->dim[0].ne - 2) |
276 |
> |
i = dp->dim[0].ne - 2; |
277 |
> |
} else { /* unevenly spaced points */ |
278 |
> |
if (dp->dim[0].siz > 0.0) |
279 |
> |
for (i = 0; i < dp->dim[0].ne; i++) |
280 |
> |
if (pt[0] < dp->dim[0].p[i]) |
281 |
> |
break; |
282 |
> |
else |
283 |
> |
for (i = 0; i < dp->dim[0].ne; i++) |
284 |
> |
if (pt[0] >= dp->dim[0].p[i]) |
285 |
> |
break; |
286 |
> |
if (i <= 0) |
287 |
> |
i = 0; |
288 |
> |
else if (i >= dp->dim[0].ne) |
289 |
> |
i = dp->dim[0].ne - 2; |
290 |
> |
else |
291 |
> |
i--; |
292 |
> |
x = i + (pt[0] - dp->dim[0].p[i]) / |
293 |
> |
(dp->dim[0].p[i+1] - dp->dim[0].p[i]); |
294 |
> |
} |
295 |
> |
/* get dependent variable */ |
296 |
|
if (dp->nd == 1) { |
297 |
|
y0 = dp->arr[i]; |
298 |
|
y1 = dp->arr[i+1]; |
302 |
|
sd.arr = &dp->arr[(i+1)*asize]; |
303 |
|
y1 = datavalue(&sd, pt+1); |
304 |
|
} |
260 |
– |
|
305 |
|
/* |
306 |
|
* Extrapolate as far as one division, then |
307 |
|
* taper off harmonically to zero. |