!=======================================
! 2D cumulus model - kaminari
!  - subroutine div_diff_avr
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/11/26  $B:G=*99?7(B
!             2003/11/13  $B?75,:n@.(B
! Note      : $B2;GH8:?j9`(B div
!             x$BJ}8~1?F0J}Dx<0Cf$N(B
!              - $B2;GH8:?j9`$N(B x $BHyJ,(B:     div_x_u
!              - $B2;GH8:?j9`$N(B z^{*} $BHyJ,(B: div_z_u
!             z^{*}$BJ}8~1?F0J}Dx<0Cf$N(B
!              - $B2;GH8:?j9`$N(B z^{*} $BHyJ,(B: div_z_w
! 
!=======================================
!--- 1$B9TL\F~NOJQ?t(B, 2$B9TL\=PNOJQ?t(B
subroutine div_diff_avr(i,k,im,km,dx,dz,div,                &
     &                  div_x_u,div_z_u,div_z_w)

  implicit none

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

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

  real(8), intent(out) :: div_x_u(-2:im+1,-2:km+1)
  real(8), intent(out) :: div_z_u(-2:im+1,-2:km+1)
  real(8), intent(out) :: div_z_w(-2:im+1,-2:km+1)

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

  div_x_u(i,k) = (div(i,k) - div(i-1,k))/dx

  div_z_u(i,k) = (                                    &
       &          div(i,k+1) + div(i-1,k+1)           &
       &          - div(i,k-1) - div(i-1,k-1)         &
       &         )/(2.0d0*dz)
  
  div_z_w(i,k) = (div(i,k) - div(i,k-1))/dz

end subroutine div_diff_avr
