SF_INTERPOLATE
Description
SciFortran module for data interpolation
Quick access
- Types:
- Routines:
cinter(),cubic_spline(),delete_finter(),delete_finter2d(),finter(),finter2d(),init_finter(),init_finter2d(),linear_spline(),poly_spline()
Used modules
interpolate_nr
Types
- type sf_interpolate/finter_type
This derived type stores the tabulated data of a 1-dimensional function and the order of the local polynomial interpolation, and is used by
finterandcinter. It is initialized withinit_finterand released withdelete_finter. The components are not meant to be set directly.- Type fields:
x (•) [real, allocatable] – grid points, strictly increasing
f (•) [real, allocatable] – function values on the grid (real part for a complex function)
g (•) [real, allocatable] – imaginary part of the function values (allocated only for complex data)
imin [integer] – index of the first grid point used (set to 1 by init_finter)
imax [integer] – index of the last grid point used (set to size(X) by init_finter)
n [integer] – order of the local polynomial interpolation
status [logical] – T if the object has been initialized
- type sf_interpolate/finter2d_type
This derived type stores the tabulated data of a 2-dimensional function on a regular grid and the order of the local polynomial interpolation, and is used by
finter2d. It is initialized withinit_finter2dand released withdelete_finter2d. The components are not meant to be set directly.- Type fields:
x (•) [real, allocatable] – grid points along x, strictly increasing
y (•) [real, allocatable] – grid points along y, strictly increasing
f (•, •) [real, allocatable] – function values on the grid, F(i,j)=F(X(i),Y(j))
n [integer] – order of the local polynomial interpolation
imin [integer] – index of the first grid point used along x (set to 1 by init_finter2d)
imax [integer] – index of the last grid point used along x (set to size(X) by init_finter2d)
jmin [integer] – index of the first grid point used along y (set to 1 by init_finter2d)
jmax [integer] – index of the last grid point used along y (set to size(Y) by init_finter2d)
status [logical] – T if the object has been initialized
Subroutines and functions
- interface sf_interpolate/linear_spline(xin, fin, xout, fout, yin, yout)
This subroutine evaluates the piecewise linear interpolation of a real or complex function tabulated on a grid. The specific procedures cover
a function of one variable, evaluated at a single point (scalar
Xout) or at an array of pointsa function of two variables on a regular grid, evaluated at a single point or on the grid
Xout\(\times\)Yout
In 1 dimension the interpolation is carried out by the routine
interp_linear. The gridXinmust be strictly increasing, otherwise the program stops. Points outside the grid are extrapolated linearly. If the input and output grids have the same size and are identical the messagemsg: test_grid_equlity: Fout=Fin. Exit.is printed, and the result is the same.In 2 dimensions the interpolation is bilinear, see http://en.wikipedia.org/wiki/Bilinear_interpolation. The points must lie inside the input grid, extrapolation is not available.
- Parameters:
xin (•) [real, in,required] – input grid points (x axis in 2D), strictly increasing
fin (various shapes) [real/complex] – function values: F(Xin(i)) in 1D, F(Xin(i),Yin(j)) in 2D
xout (various shapes) [real] – points where to interpolate (x axis in 2D): scalar or array
fout (various shapes) [real/complex]
yin (•) [real, in,required] – input grid points along y (2D), strictly increasing
yout (various shapes) [real] – points along y where to interpolate (2D): scalar or array
- interface sf_interpolate/poly_spline(xin, fin, xout, fout, yin, yout[, n])
This subroutine evaluates the polynomial interpolation of a real or complex function tabulated on a grid, using the local polynomial of order
Nbuilt byfinter(1 dimension) orfinter2d(2 dimensions). The specific procedures covera function of one variable, evaluated at a single point (scalar
Xout) or at an array of pointsa function of two variables on a regular grid, evaluated at a single point or on the grid
Xout\(\times\)Yout
At each point the interpolating polynomial is built on a window of \(N+2\) neighbouring grid points (\((N+2)^2\) in 2 dimensions) using
polint(polin2). The window is shifted to stay inside the grid at its borders, so points outside the grid are extrapolated with the polynomial of the first or last window. The grid must have at least \(N+2\) points along each direction, and orders \(N>20\) are not recommended.- Parameters:
xin (•) [real, in,required] – input grid points (x axis in 2D), strictly increasing
fin (various shapes) [real/complex] – function values: F(Xin(i)) in 1D, F(Xin(i),Yin(j)) in 2D
xout (various shapes) [real] – points where to interpolate (x axis in 2D): scalar or array
fout (various shapes) [real/complex]
yin (•) [real, in,required] – input grid points along y (2D), strictly increasing
yout (various shapes) [real] – points along y where to interpolate (2D): scalar or array
- Options:
n [integer] – order of the local polynomial interpolation (default 5)
- interface sf_interpolate/cubic_spline(xin, fin, xout, fout)
This subroutine evaluates the cubic spline interpolation of a real or complex function of one variable tabulated on the grid
Xin, at a single point (scalarXout) or at an array of points. It is an interface to the routinesCUBSPLandPPVALUof C. de Boor, called with the not-a-knot condition at both ends, that is the first two and the last two cubic pieces coincide. This routine works well with imaginary time Green’s functions. The gridXinmust be strictly increasing and have at least 2 points. Points outside the grid are extrapolated with the first or last cubic piece. If the input and output grids have the same size and are identical the messagemsg: test_grid_equlity: Fout=Fin. Exit.is printed, and the result is the same.- Parameters:
xin (•) [real, in,required] – input grid points (x axis in 2D), strictly increasing
fin (size(xin)) [real/complex] – function values: F(Xin(i)) in 1D, F(Xin(i),Yin(j)) in 2D
xout (various shapes) [real] – points where to interpolate (x axis in 2D): scalar or array
fout (various shapes) [real/complex]
- interface sf_interpolate/init_finter(func, xin, fin, n)
This subroutine initializes a
finter_typeobject with the tabulated data of a real or complex function of one variable, so that it can be interpolated withfinter(real) orcinter(complex). The data are copied,funcdoes not keep a reference toXinandFin. Iffuncwas already initialized it is first released withdelete_finter. In the complex case the real and imaginary parts are stored separately, infunc%Fandfunc%G.- Parameters:
func [finter_type] – finter_type object to initialize (previous content is released)
xin (•) [real, in,required] – function values on the grid, F(Xin(i)): real or complex
fin (size(xin)) [real/complex]
n [integer] – order of the local polynomial interpolation (window of N+2 grid points)
- subroutine sf_interpolate/delete_finter(func)
This subroutine releases the memory of the
finter_typeobjectfuncand resets it to the uninitialized state:Imin=Imax=N=0andstatus=.false..- Parameters:
func [finter_type]
- function sf_interpolate/finter(func, x)
This function evaluates at the point
xthe real function stored in thefinter_typeobjectfunc. It finds the grid interval containingxwithlocateand interpolates withpolinton a window of \(N+2\) grid points around it, withN=func%N. The window is shifted to stay inside the grid, so points outside the grid are extrapolated with the polynomial of the first or last window. Iffuncwas initialized with a complex function, the real part is interpolated.- Parameters:
func [finter_type]
x [real]
- Result:
finter [real]
- function sf_interpolate/cinter(func, x)
This function is the complex counterpart of
finter. It evaluates at the pointxthe complex function stored in thefinter_typeobjectfunc, interpolating separately the real and the imaginary parts, stored infunc%Fandfunc%G. The object must have been initialized with a complex function, otherwisefunc%Gis not allocated.- Parameters:
func [finter_type]
x [real]
- Result:
cinter [complex]
- subroutine sf_interpolate/init_finter2d(func, xin, yin, fin, n)
This subroutine initializes a
finter2d_typeobject with the tabulated data of a real function of two variables on the regular gridXin\(\times\)Yin, so that it can be interpolated withfinter2d. The data are copied,funcdoes not keep a reference toXin,YinandFin. Iffuncwas already initialized its memory is first released.- Parameters:
func [finter2d_type]
xin (•) [real, in,required]
yin (•) [real, in,required]
fin (size(xin), size(yin)) [real]
n [integer]
- subroutine sf_interpolate/delete_finter2d(func)
This subroutine releases the memory of the
finter2d_typeobjectfuncand resets it to the uninitialized state:Imin=Imax=Jmin=Jmax=N=0andstatus=.false..- Parameters:
func [finter2d_type]
- function sf_interpolate/finter2d(func, x, y)
This function evaluates at the point (
x,y) the function stored in thefinter2d_typeobjectfunc. It finds the grid cell containing the point withlocatealong each direction and interpolates withpolin2on a window of \((N+2) \times (N+2)\) grid points around it, withN=func%N. The window is shifted to stay inside the grid, so points outside the grid are extrapolated with the polynomial of the first or last window.- Parameters:
func [finter2d_type]
x [real]
y [real]
- Result:
finter2d [real]