subroutine zinterpolatew(input,output)
use modglobal, only : jb,je,kb,ke,zh,nstore
implicit none
real, dimension(jb:je,kbin:kein+1,1:nstore), intent(in) :: input
real, dimension(jb:je,kb:ke+1,1:nstore), intent(inout) :: output
integer k
do k=kb,ke+1
if (linuh(k) == kein+2) then ! indicator for extrapolation!
output(:,k,:) = input(:,kein+1,:)
elseif (linlh(k) == kbin-1) then ! interprets this as extrapolation to bottom (use u=0 at z+=0)
output(:,k,:) = input(:,kbin,:) ! =0
! output(:,k,:) = input(:,kbin,:)/zhin(kbin) * zh(k)
! output(:,k,:) = input(:,kbin,:) ! temeperature is not zero at the wall, so line above is wrong
else ! normal interpolation
output(:,k,:) = input(:,linlh(k),:) + (input(:,linuh(k),:) - input(:,linlh(k),:)) / (zhin(linuh(k)) - zhin(linlh(k))) * (zh(k) - zhin(linlh(k)))
if ((zh(k) .gt. zhin(linuh(k))) .or. (zh(k) .lt. zhin(linlh(k)))) then
write(6,*) '!!!Mistake in zinterpolatew !!!!'
end if
end if
end do
end subroutine zinterpolatew