#include "interpolator1d.h" using namespace INTERPOLATOR1D; // Get index position of xp in grid int regular_lookup(double xp, double min_x, double dx); int irregular_lookup(double xp, double *x,int nx); // low level single point interpolators double linear_scalar ( double x, double x1, double y1, double x2, double y2 ); void linear_vector (double x, double x1, double *y1, double x2, double *y2, int nv, double *y); // single point in a grid interpolators double linear_scalar_regular ( double xp, double x0, double dx, double *y, int nx); double linear_scalar_irregular(double xp,double *x, double *y, int nx); double *linear_vector_regular ( double xp, double x0, double dx,dmatrix& y); double *linear_vector_irregular(double xp,double *x, dmatrix& y); // Mappers from one grid to another void linear_scalar_regular_to_regular(int nin, double x0in, double dxin, double *yin, int nout, double x0out, double dxout, double *yout); void linear_scalar_irregular_to_regular(int nin, double *xin, double *yin, int nout, double x0out, double dxout, double *yout); void linear_scalar_regular_to_irregular(int nin, double x0in, double dxin, double *yin, int nout, double *xout, double *yout); void linear_scalar_irregular_to_irregular(int nin, double *xin, double *yin, int nout, double *xout, double *yout); void linear_vector_regular_to_regular(double x0in, double dxin, dmatrix& yin, double x0out, double dxout, dmatrix& yout); void linear_vector_irregular_to_regular(double *xin, dmatrix& yin, double x0out, double dxout, dmatrix& yout); void linear_vector_regular_to_irregular(double x0in, double dxin, dmatrix& yin, double *xout, dmatrix& yout); void linear_vector_irregular_to_irregular(double *xin, dmatrix& yin, double *xout, dmatrix& yout);
Interpolation is a standard numerical algorithm that is needed for a long list of scientific computing problems. This group of procedures provide a basic set of interpolator functions from one one-dimensional grid onto another. The primary assumption is that the input grid is ordered from smallest to largest. Chaos will result if this basic assumption is violated.
The library assumes the grid is one of two flavors: regular or irregular. Regular means the grid is uniformly sampled in the x axis (like a time series). An irregular grid means one where the sampling on the x axis varies. The names of the functions indicate the direction of conversion in a convention that should be obvious.
The functions are of three flavors:
The regular grid lookup functions will blindly return negative indices or an index larger than the grid size if asked. The caller must test this for an error condition. The irregular grid lookup function will return 0 if the requested point is smaller than the left side of the grid or nx-1 if the point is to the right of last grid point.
With the mappers when a point that is outside the edges of the grid is requested the point is filled with the last valid sample to the left or right as appropriate. This allows these functions to always return something, although the result will clearly be of limited use outside the range of input data.
dmatrix(3), http://geology.indiana.edu/pavlis/software/seispp/html/index.html
Gary L. Pavlis Indiana University