A C library to inter- and extrapolate values on regular N-dimensional grids.
- pure C — no dependencies
- multi-dimensional — up to 32 dimensions
- interpolation — hold, nearest, linear, Akima, Fritsch–Butland, Steffen
- extrapolation — hold, linear, none
- derivatives — partial derivatives w.r.t all dimensions
#include "NDTable.h"
int main(void) {
int ndims = 1;
int dims[] = { 3 };
double data[] = { 0.0, 1.0, 4.0 };
const double *scales[] = { (const double[]){ 0.0, 1.0, 2.0 } };
NDTable_h table = NDTable_create_table(ndims, dims, data, scales);
if (!table) {
return 1;
}
double params[] = { 1.5 };
double value = 0.0;
double derivative = 0.0;
if (NDTable_evaluate(table, params, 0, NDTABLE_INTERP_LINEAR, NDTABLE_EXTRAP_HOLD, &value, &derivative) == 0) {
/* value ≈ 2.5 at x = 1.5 with linear interpolation */
}
NDTable_free_table(table);
return 0;
}NDTable is released under the BSD-2-Clause license.