subroutine ddz_w(dfdz,f)
!  First deriv in z direction for boundary layer (2nd order numerics)
!  F is on w nodes and dFdz is on uvp nodes
!    -23 January 1996
use types,only:rprec
use param,only:ld,nx,ny,nz,dz
implicit none
real(kind=rprec),dimension(ld,ny,nz),intent(in)::f
real(kind=rprec),dimension(ld,ny,nz),intent(inout)::dfdz
real(kind=rprec)::const
integer::jx,jy,jz

const=1._rprec/dz
do jz=1,nz-1
do jy=1,ny
do jx=1,nx
   dfdz(jx,jy,jz)=const*(f(jx,jy,jz+1)-f(jx,jy,jz))
end do
end do
end do

! Stress free lid (ubc)
!	if (ubc==0) then stop

!	else
dfdz(:,:,nz)=0._rprec !dfdz(:,:,Nz-1) ! c? any better ideas for sponge?
!     end if
end subroutine ddz_w
