!=======================================
! 2D cumulus model - kaminari
!  - subroutine vel_w_tb
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/11/11
! Note      : z $BJ}8~1?F0J}Dx<0$ND9$$;~4V(B
!             $B4V3V$G7W;;$9$kItJ,(B
! 
!=======================================
subroutine vel_w_tb(i,k,im,km,nuh,nuv,grv,dx,dz,ptemp_bs,   &
     &              qv_bs,u,w,omg,ptemp,qv,qc,qr,w_adv,     &
     &              w_buoy,w_trb)

  implicit none

  integer, intent(in) :: i, k
  integer, intent(in) :: im, km

  real(8), intent(in) :: nuh,nuv,grv
  real(8), intent(in) :: dx, dz

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

  real(8), intent(in) :: u(0:im+1,0:km+1)
  real(8), intent(in) :: w(0:im+1,0:km+1)
  real(8), intent(in) :: omg(0:im+1,0:km+1)
  real(8), intent(in) :: ptemp(0:im+1,0:km+1)
  real(8), intent(in) :: qv(0:im+1,0:km+1)
  real(8), intent(in) :: qc(0:im+1,0:km+1)
  real(8), intent(in) :: qr(0:im+1,0:km+1)

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

  real(8)             :: w_dif(0:im+1,0:km+1)

  !--- $B2;GH8:?j9`(B
  w_dif(i,k) = nuh*(w(i+1,k) - 2.0D0*w(i,k) + w(i-1,k))     &
       &       /dx**2.0D0                                   &
       &       + nuv*(w(i,k+1) - 2.0D0*w(i,k) + w(i,k-1))   &
       &         /dz**2.0D0

  !--- $B0\N.9`(B
  w_adv(i,k) = (                                            &
       &        u(i+1,k+1) + u(i+1,k-1)                     &
       &        + u(i-1,k+1) + u(i-1,k-1)                   &
       &       )/4.0D0*(w(i+1,k) - w(i-1,k))/(2.0D0*dx)     &
       &       + omg(i,k)*(w(i,k+1) - w(i,k-1))/(2.0D0*dz)  &
       &       - w_dif(i,k)

  !--- $BIbNO9`(B
  w_buoy(i,k) = grv*(                                       &
       &             (ptemp(i,k+1) + ptemp(i,k))/2.0D0      &
       &             /((ptemp_bs(i,k+1) + ptemp_bs(i,k))/2.0D0)&
       &             - 1.0D0                                &
       &             + 0.61D0*(                             &
       &                       (qv(i,k+1) + qv(i,k))/2.0D0  &
       &                       - (qv_bs(i,k+1) - qv_bs(i,k))&
       &                         /2.0D0                     &
       &                      )                             &
       &             - (qc(i,k+1) + qc(i,k))/2.0D0          &
       &             - (qr(i,k+1) + qr(i,k))/2.0D0          &
       &            )

  !--- $B3H;69`(B
  w_trb(i,k) = 0.0D0

end subroutine vel_w_tb
