Home | Research | For Students | Publications | Talks | PSNS | Codes | WebLog | Personal |
Following functions are provided by < interp.h > :
double bilinear_interp (double X, double Y, const double* TABLE,
const int NX, const int NY,
const double X_MIN, const double X_MAX,
const double Y_MIN, const double Y_MAX,
const int OUT_OF_DOMAIN_FLAG, const double OUT_OF_DOMAIN_VALUE );
double trilinear_interp (double X, double Y, double Z, const double* TABLE,
const int NX, const int NY, const NY
const double X_MIN, const double X_MAX,
const double Y_MIN, const double Y_MAX,
const double Z_MIN, const double Z_MAX,
const int OUT_OF_DOMAIN_FLAG, const double OUT_OF_DOMAIN_VALUE );
double bilinear_interp_arbitrary_grid (double X, double Y, const double* TABLE,
const double * Xtbl, const int NX,
const double * Ytbl, const int NY,
const int OUT_OF_DOMAIN_FLAG, const double OUT_OF_DOMAIN_VALUE );
double trilinear_interp_arbitrary_grid (double X, double Y, double Z, const double* TABLE,
const double * Xtbl, const int NX,
const double * Ytbl, const int NY,
const double * Ztbl, const int NZ,
const int OUT_OF_DOMAIN_FLAG, const double OUT_OF_DOMAIN_VALUE );
wget https://th.if.uj.edu.pl/~odrzywolek/homepage/codes/libinterp/source/libinterp-0.13.tar.gz
tar -xvf libinterp-0.13.tar.gz
cd libinterp-0.13
./configure
make
sudo make install
sudo ldconfig
./configure --prefix=$HOME CC=icc
make
make install
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;
}
libinterp
library has been installed
properly in system-wide location (default: /usr/local/ ), compile simply with:
gcc example2d.c -o example2d -linterp
./example2d >test2d.dat
You should get something like this:
TODO
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