12 void interpn(
double *val,
double const *coor,
double const *
data,
13 double const *axis,
size_t const *len,
int ndim,
int nval) {
15 i1 =
locate(axis, *coor, *len);
22 }
else if (i1 == *len - 1) {
28 double *v1 = (
double *)malloc(nval *
sizeof(
double));
29 double *v2 = (
double *)malloc(nval *
sizeof(
double));
35 for (
int j = 0;
j < nval; ++
j) {
36 v1[
j] =
data[i1 * nval +
j];
37 v2[
j] =
data[i2 * nval +
j];
41 for (
int j = 1;
j < ndim; ++
j) s *= len[
j];
42 interpn(v1, coor + 1,
data + i1 * s, axis + *len, len + 1, ndim - 1, nval);
43 interpn(v2, coor + 1,
data + i2 * s, axis + *len, len + 1, ndim - 1, nval);
47 for (
int j = 0;
j < nval; ++
j)
48 val[
j] = ((*coor -
x1) * v2[
j] + (
x2 - *coor) * v1[
j]) / (
x2 -
x1);
50 for (
int j = 0;
j < nval; ++
j) val[
j] = (v1[
j] + v2[
j]) / 2.;
61 double interp1(
double x,
double const *
data,
double const *axis,
size_t len) {
double interp1(double x, double const *data, double const *axis, size_t len)
void interpn(double *val, double const *coor, double const *data, double const *axis, size_t const *len, int ndim, int nval)
int locate(double const *xx, double x, int n)