Linear interpolation coefficients and index for a 1D grid y(x)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in) | :: | xmin | Minimum abscissa value |
||
real(kind=Float64), | intent(in) | :: | dx | Absissa spacing |
||
integer, | intent(in) | :: | nx | Number of abscissa |
||
real(kind=Float64), | intent(in) | :: | xout | Abscissa value to interpolate |
||
type(InterpolCoeffs1D), | intent(out) | :: | c | Interpolation Coefficients |
||
integer, | intent(out), | optional | :: | err | Error code |
subroutine interpol1D_coeff(xmin,dx,nx,xout,c,err)
!+ Linear interpolation coefficients and index for a 1D grid y(x)
real(Float64), intent(in) :: xmin
!+ Minimum abscissa value
real(Float64), intent(in) :: dx
!+ Absissa spacing
integer, intent(in) :: nx
!+ Number of abscissa
real(Float64), intent(in) :: xout
!+ Abscissa value to interpolate
type(InterpolCoeffs1D), intent(out) :: c
!+ Interpolation Coefficients
integer, intent(out), optional :: err
!+ Error code
real(Float64) :: x1, xp, b1, b2
integer :: i, err_status
err_status = 1
xp = max(xout,xmin)
i = floor((xp - xmin)/dx)+1
if ((i.gt.0).and.(i.le.(nx-1))) then
x1 = xmin + (i-1)*dx
b2 = (xp - x1)/dx
b1 = (1.0 - b2)
c%i = i
c%b1 = b1
c%b2 = b2
err_status = 0
endif
if(present(err)) err = err_status
end subroutine interpol1D_coeff