Bilinear interpolation coefficients and indicies for a 2D grid z(x,y)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in) | :: | xmin | Minimum abscissa |
||
real(kind=Float64), | intent(in) | :: | dx | Abscissa spacing |
||
integer, | intent(in) | :: | nx | Number of abscissa |
||
real(kind=Float64), | intent(in) | :: | ymin | Minimum ordinate |
||
real(kind=Float64), | intent(in) | :: | dy | Ordinate spacing |
||
integer, | intent(in) | :: | ny | Number of ordinates points |
||
real(kind=Float64), | intent(in) | :: | xout | Abscissa value to interpolate |
||
real(kind=Float64), | intent(in) | :: | yout | Ordinate value to interpolate |
||
type(InterpolCoeffs2D), | intent(out) | :: | c | Interpolation Coefficients |
||
integer, | intent(out), | optional | :: | err | Error code |
subroutine interpol2D_coeff(xmin,dx,nx,ymin,dy,ny,xout,yout,c,err)
!+ Bilinear interpolation coefficients and indicies for a 2D grid z(x,y)
real(Float64), intent(in) :: xmin
!+ Minimum abscissa
real(Float64), intent(in) :: dx
!+ Abscissa spacing
integer, intent(in) :: nx
!+ Number of abscissa
real(Float64), intent(in) :: ymin
!+ Minimum ordinate
real(Float64), intent(in) :: dy
!+ Ordinate spacing
integer, intent(in) :: ny
!+ Number of ordinates points
real(Float64), intent(in) :: xout
!+ Abscissa value to interpolate
real(Float64), intent(in) :: yout
!+ Ordinate value to interpolate
type(InterpolCoeffs2D), intent(out) :: c
!+ Interpolation Coefficients
integer, intent(out), optional :: err
!+ Error code
real(Float64) :: x1, x2, y1, y2, xp, yp
integer :: i, j, err_status
err_status = 1
xp = max(xout,xmin)
yp = max(yout,ymin)
i = floor((xp-xmin)/dx)+1
j = floor((yp-ymin)/dy)+1
if (((i.gt.0).and.(i.le.(nx-1))).and.((j.gt.0).and.(j.le.(ny-1)))) then
x1 = xmin + (i-1)*dx
x2 = x1 + dx
y1 = ymin + (j-1)*dy
y2 = y1 + dy
c%b11 = ((x2 - xp) * (y2 - yp))/(dx*dy)
c%b21 = ((xp - x1) * (y2 - yp))/(dx*dy)
c%b12 = ((x2 - xp) * (yp - y1))/(dx*dy)
c%b22 = ((xp - x1) * (yp - y1))/(dx*dy)
c%i = i
c%j = j
err_status = 0
endif
if(present(err)) err = err_status
end subroutine interpol2D_coeff