subroutine energy (ke)
use types,only:rprec
use param,only:ld,nx,ny,nz
use sim_param,only:u,v,w
implicit none
integer::jx,jy,jz
real(kind=rprec)::KE,denom,temp_w
ke=0._rprec
denom=2._rprec*(nx*ny*(nz-1))
do jz=2,nz
do jy=1,ny
do jx=1,nx
   temp_w=.5_rprec*(w(jx,jy,jz)+w(jx,jy,jz-1))
   ke=ke+(u(jx,jy,jz)**2+v(jx,jy,jz)**2+temp_w**2)/denom
end do
end do
end do
end subroutine energy
