subroutine stepbl_w (ui, RHSi, RHSi_f,f)
use types,only:rprec
use param,only:ld,nx,ny,nz,dt
implicit none
! Modified on 3/14 to remove non-zero <W> rather than forcing <dw/dt>=0.
! This is because initial velocity field may have nonzero <w> which
!   persisted.      
integer::jx,jy,jz
real(kind=rprec),dimension(ld,ny,nz),intent(out)::ui
real(kind=rprec),dimension(ld,ny,nz),intent(in)::RHSi,RHSi_f,f
real(kind=rprec)::w_bar

do jz=2,nz
! step the velocity with zero horizontal mean
! horizontal mean what? oh--zero plane averaged velocity at each z ??
   ui(:,:,jz)=ui(:,:,jz)+&
        dt*((1.5*RHSi(:,:,jz)-0.5*RHSi_f(:,:,jz))+f(:,:,jz))
! compute mean vertical velocity 
   w_bar=0.
   do jy=1,ny
   do jx=1,nx
      w_bar= w_bar+ui(jx,jy,jz)
   end do
   end do
   w_bar=w_bar/(nx*ny)  
! and remove the mean vertical velocity  
! this is going to be very bad for flow over rough surfaces!
   ui(:,:,jz)=ui(:,:,jz)-w_bar
end do
	
! no slip wall and no flow through top
ui(:,:,1)=0.
ui(:,:,nz)=0.
end subroutine stepbl_w
