Bilinear and trilinear interpolation library on equidistant and user-supplied grids

Library description

Following functions are provided by < interp.h > :

Download

Installation

Standard installation procedure should work:

wget https://th.if.uj.edu.pl/~odrzywolek/homepage/codes/libinterp/source/libinterp-0.12.tar.gz
tar -xvf libinterp-0.12.tar.gz
cd libinterp-0.12
./configure
make
sudo make install

To change default C compiler and install in home directory:

./configure --prefix=$HOME CC=icc
make
make install

Example of use

Go to doc/ directory where you can find example2d.c file:


#include <interp.h>
#include <stdio.h>
#include <math.h>

int main()
{
/* Example 3x3 equidistant grid.

 1---0---1
 |   |   |
 1---2---3
 |   |   |
-1---1---1

*/
const double dat[3][3] = {{-1.0,1.0,1.0},{1.0,2.0,0.0},{1.0,3.0,1.0}};
double x, y;
double f;
int i,j;
for(i=-20;i<=20;i++)
for(j=-20;j<=20;j++)
{
x=0.1*i;
y=0.1*j;
f = bilinear_interp(x,y,dat,3,3,-1.0,1.0,-1.0,1.0,0,0.0);
printf("%lf\t%lf\t%lf\n",x,y,f);
}
return 0;
}

If the libinterp library has been installed properly in system-wide location (default: /usr/local/ ), compile simply with:

gcc example2d.c -o example2d -linterp

and run code:

./example2d >test2d.dat

You should get something like this:

Documentation

TODO

Known bugs

Function bilinear_interp on regular grids sometimes selects WRONG (neighbouring one) data point, especially if the values are very close to grid boundaries. This is probably due to round-off errors and suspicious use of ceil function from < math.h > . Interpolation is contiunuous, so this should not lead to catastrophic errors.

Last modified 2012-08-07 17:23