!=======================================
! 2D cumulus model - kaminari
!  - subroutine vel_w_tb
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/12/06  $B:G=*99?7(B
!             2003/11/11  $B?75,:n@.(B
! Note      : z $BJ}8~1?F0J}Dx<0$ND9$$;~4V(B
!             $B4V3V$G7W;;$9$kItJ,(B
! 
!=======================================
!--- 1,2,3,4$B9TL\F~NOJQ?t(B, 5$B9TL\=PNOJQ?t(B
subroutine vel_w_tb(im,km,dx,dz,nuh,nuv,grv,ptemp_bs,ptemp, &
     &              u,w,omg,                                &
     &              w_adv,w_buoy,w_trb)

  implicit none

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

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

!  real(8), intent(in) :: g_sqrt(-2:im+2,-2:km+2)
!  real(8), intent(in) :: g_sqrt_z(-2:im+2,-2:km+2)
!  real(8), intent(in) :: g_sqrt_xz(-2:im+2,-2:km+2)
!  real(8), intent(in) :: g13(-2:im+2,-2:km+2)
!  real(8), intent(in) :: g13x(-2:im+2,-2:km+2)
!  real(8), intent(in) :: g13xz(-2:im+2,-2:km+2)

  real(8), intent(in) :: ptemp_bs(-2:im+2,-2:km+2)
!  real(8), intent(in) :: qv_bs(-2:im+2,-2:km+2)

  real(8), intent(in) :: u(-2:im+2,-2:km+2)
  real(8), intent(in) :: w(-2:im+2,-2:km+3)
  real(8), intent(in) :: omg(-2:im+2,-2:km+3)
!  real(8), intent(in) :: u_old(-2:im+2,-2:km+2)
!  real(8), intent(in) :: w_old(-2:im+2,-2:km+2)

  real(8), intent(in) :: ptemp(-2:im+2,-2:km+2)
!  real(8), intent(in) :: qv(-2:im+2,-2:km+2)
!  real(8), intent(in) :: qc(-2:im+2,-2:km+2)
!  real(8), intent(in) :: qr(-2:im+2,-2:km+2)
!  real(8), intent(in) :: km_sub(-2:im+2,-2:km+2)

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

  integer(8)          :: i, k

  real(8)              :: w_dif(-2:im+1,-2:km+1)

  do k = 1,km
     do i = 0,im
        !--- $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,k) + u(i,k-1)                           &
             &        + u(i+1,k) + 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)
        w_adv(i,k) = 0.0d0

        !--- $BIbNO9`(B
        w_buoy(i,k) = grv                                         &
             &        *(                                          &
             &          (ptemp(i,k) + ptemp(i,k-1))/2.0d0         &
             &          /((ptemp_bs(i,k) + ptemp_bs(i,k-1))/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             &
             &            )
        w_buoy(i,k) = 0.0d0

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

     end do
  end do

end subroutine vel_w_tb
