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