!=======================================
! 2D cumulus model - kaminari
!  - subroutine vel_w
!
! Author    : TAKAHASHI Koko
! Date      : 2003/11/25  最終更新
!             2003/11/10  新規作成
! Note      : 鉛直速度 w
!
!=======================================
!--- 1,2行目入力変数, 3行目入出力変数
subroutine vel_w(i,k,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) :: 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(-2:im+1,-2:km+1)

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

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

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

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

  !--- 速度 w
  w(i,k) = w(i,k)                                           &
       &   - dts*cp/g_sqrt_z(i,k)                           &
       &     *(vptemp_bs(i,k+1) + vptemp_bs(i,k))/2.0D0     &
       &     *(                                             &
       &       - alp*div_z_w(i,k)                           &
       &       + (1.0D0 - beta)                             &
       &         *(pi_old(i,k+1) - pi_old(i,k))/dz          &
       &      )                                             &
       &   - dts*(w_adv(i,k) + w_buoy(i,k) + w_trb(i,k))    &
       &   - beta*dts*cp/g_sqrt_z(i,k)                      &
       &     *(vptemp_bs(i,k+1) + vptemp_bs(i,k))/2.0D0     &
       &     *(pi(i,k+1) - pi(i,k))/dz

end subroutine vel_w