!=======================================
! 2D cumulus model - kaminari
!  - subroutine vel_w
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/12/15  $B:G=*99?7(B
!             2003/11/10  $B?75,:n@.(B
! Note      : $B1tD>B.EY(B w
! 
!=======================================
!--- 1,2$B9TL\F~NOJQ?t(B, 3$B9TL\F~=PNOJQ?t(B
subroutine vel_w(im,km,dts,cp,alp,beta,dz,vptemp_bs,pi,     &
     &           pi_old,g_sqrt_z,div_z_w,w_adv,w_buoy,w_trb,&
     &           w)

  implicit none

  integer(8), intent(in) :: im, km

  real(8), intent(in) :: dts
  real(8), intent(in) :: dz
  real(8), intent(in) :: cp,alp,beta

  real(8), intent(in) :: vptemp_bs(-2:im+2,-2:km+2)

  real(8), intent(in) :: pi(-2:im+2,-2:km+2)
  real(8), intent(in) :: pi_old(-2:im+2,-2:km+2)

  real(8), intent(in) :: g_sqrt_z(-2:im+2,-2:km+2)
  real(8), intent(in) :: div_z_w(0:im+1,0:km+1)

  real(8), intent(in) :: w_adv(-2:im+2,-2:km+3)
  real(8), intent(in) :: w_buoy(-2:im+2,-2:km+3)
  real(8), intent(in) :: w_trb(-2:im+2,-2:km+3)

  real(8), intent(inout) :: w(-2:im+2,-2:km+3)

  integer(8)          :: i, k

  do k = 1,km
     do i = 0,im
        !--- $BB.EY(B w
        w(i,k) = w(i,k)                                           &
             &   - dts*cp/g_sqrt_z(i,k)                           &
             &     *(vptemp_bs(i,k) + vptemp_bs(i,k-1))/2.0d0     &
             &     *(                                             &
             &       - alp*div_z_w(i,k)                           &
             &       + (1.0D0 - beta)                             &
             &         *(pi_old(i,k) - pi_old(i,k-1))/dz          &
             &      )                                             &
             &   + dts*(- w_adv(i,k) + w_buoy(i,k) + w_trb(i,k))  &
             &   - dts*beta*cp/g_sqrt_z(i,k)                      &
             &     *(vptemp_bs(i,k) + vptemp_bs(i,k-1))/2.0d0     &
             &     *(pi(i,k) - pi(i,k-1))/dz
      end do
  end do

end subroutine vel_w
