Linear interpolation of y(x) at x=r
Arrays x and y must be sorted
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | r | Position of desired value |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x | x values of data |
|
real(kind=wp), | intent(in), | dimension(size(x)) | :: | y | y values of data |
y(x=r) via linear interpolation
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
function linearInterp(r,x,y) result(o)
!! Linear interpolation of y(x) at x=r
!!
!! Arrays x and y must be sorted
real(wp),intent(in)::r
!! Position of desired value
real(wp),dimension(:),intent(in)::x
!! x values of data
real(wp),dimension(size(x)),intent(in)::y
!! y values of data
real(wp)::o
!! y(x=r) via linear interpolation
real(wp)::xi
integer::k
k = findInterval(r,x)
xi = ( r-x(k) )/( x(k+1)-x(k) )
o = y(k)+xi*( y(k+1)-y(k) )
end function linearInterp