!=======================================
! 2D cumulus model - kaminari
!  - subroutine div
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/11/04
! Note      : $B2;GH8:?j9`(B div
!             $B2;GH8:?j9`$N(B x $BJ?6Q(B divx
!             $B2;GH8:?j9`$N(B z $BJ?6Q(B divz
! 
!=======================================
subroutine div3(i,k,im,km,dx,dz,g12,g13xz,u,w,div,divx,divz)

  implicit none

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

  real(8), intent(inout) :: div(0:im+1,0:km+1)
  real(8), intent(inout) :: divx(0:im+1,0:km+1)
  real(8), intent(inout) :: divz(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) :: g12(0:im+1,0:km+1)
  real(8), intent(in) :: g13xz(0:im+1,0:km+1)

  real(8), intent(in) :: dx, dz

  div(i,k) = (u(i+1,k) - u(i,k))/(2*dx)            &
       &     + g13xz(i,k)                          &
       &       *(                                  &
       &         u(i+1,k+1) + u(i-1,k+1)           &
       &         - u(i+1,k+1) - u(i-1,k+1)         &
       &         )/(8*dz)                          &
       &     + 1/g12(i,k)*(w(i,k+1) - w(i,k))/(2*dz)

  divx(i,k) = (div(i+1,k) - div(i,k))/(2*dx)
  divz(i,k) = (div(i,k+1) - div(i,k))/(2*dz)

end subroutine div3
