!=======================================
! 2D cumulus model - kaminari
!  - subroutine vel_w
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/11/10
! Note      : $B1tD>B.EY(B w
! 
!=======================================
subroutine vel_w(i,k,im,km,dts,cp,alp,beta,dz,vptemp_bs,    &
     &           pi,pi_old,g_sqrt_z,div_z_w,div_z_w_old,w_adv,  &
     &           w_buoy,w_trb,w)

  implicit none

  integer(8), intent(in) :: i, k
  integer(8), intent(in) :: im, km
  real(8), intent(in) :: dts

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

  real(8), intent(in) :: vptemp_bs(0:im+1,0:km+1)

  real(8), intent(in) :: pi(0:im+1,0:km+1)
  real(8), intent(in) :: pi_old(0:im+1,0:km+1)

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

  real(8), intent(in) :: w_adv(0:im+1,0:km+1)
  real(8), intent(in) :: w_buoy(0:im+1,0:km+1)
  real(8), intent(in) :: w_trb(0:im+1,0:km+1)

  real(8), intent(inout) :: w(0:im+1,0:km+1)

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

end subroutine vel_w
