subroutine divstress_w(divt, tx, ty, tz)
use types,only:rprec
use param,only:ld,nx,ny,nz
implicit none
real(kind=rprec),dimension(ld,ny,nz),intent(out)::divt
real(kind=rprec),dimension(ld,ny,nz),intent(in)::tx,ty,tz
real(kind=rprec),dimension(ld,ny,nz)::dtxdx,dtydy, dtzdz
integer::jx,jy,jz

! compute stress gradients      
call ddx(dtxdx, tx)
call ddy(dtydy, ty)
call ddz_uv(dtzdz, tz)
! note ddz_uv does not return values for k=1 level.
do jz=2,nz
do jy=1,ny
do jx=1,nx              
   divt(jx,jy,jz)=dtxdx(jx,jy,jz)+dtydy(jx,jy,jz)+dtzdz(jx,jy,jz)
end do
end do
end do
! at wall we have to assume that dz(tzz)=0.0.  Any better ideas?
do jy=1,ny
do jx=1,nx
! in old version, it looks like some people tried some stuff with dwdz here
! but they were zeroed out, so they were left out of this version
   divt(jx,jy,1)=dtxdx(jx,jy,1)+dtydy(jx,jy,1)
end do
end do
end subroutine divstress_w
