!=======================================
! 2D cumulus model - kaminari
!  - subroutine jacobian (2D)
!
! Author    : TAKAHASHI Koko
! Date      : 2003/11/21 最終更新
!             2003/11/01 新規作成
!
!=======================================s
!--- 1 行目  : 入力変数
!--- 2,3 行目: 出力変数
subroutine jacobian(im,km,                              &
     &              g_sqrt,g_sqrt_x,g_sqrt_z,g_sqrt_xz,g13, &
     &              g13x,g13z,g13xz)

  implicit none

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

  real(8), intent(out) :: g_sqrt(-2:im+2,-2:km+2)    ! ヤコビアンの1/2乗
  real(8), intent(out) :: g_sqrt_x(-2:im+2,-2:km+2)
  real(8), intent(out) :: g_sqrt_z(-2:im+2,-2:km+2)
  real(8), intent(out) :: g_sqrt_xz(-2:im+2,-2:km+2)
  real(8), intent(out) :: g13(-2:im+2,-2:km+2)    ! ヤコビアンの13成分
  real(8), intent(out) :: g13x(-2:im+2,-2:km+2)
  real(8), intent(out) :: g13z(-2:im+2,-2:km+2)
  real(8), intent(out) :: g13xz(-2:im+2,-2:km+2)

!  real(8), intent(in) :: zs(-2:im+2)
!  real(8), intent(in) :: dx
!  real(8), intent(in) :: h

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

  integer(8)          :: i, k

  do k = 0, km
     do i = 0, im
        g_sqrt(i,k) = 1.0d0
        g13(i,k) = 0.0d0

        !  g_sqrt(i,k) =  (h - zs(i))/h

        !  g13(i,k) = (z(i,k) - h)/(h - zs(i))   &
        !       &     *(zs(i) - zs(i-1))/dx

        !--- g_sqrtのx平均操作: u(i,k) と同じ位置
        g_sqrt_x(i,k) = (g_sqrt(i,k) + g_sqrt(i-1,k))/2.0d0

        !--- g_sqrtのz平均操作: w(i,k) と同じ位置
        g_sqrt_z(i,k) = (g_sqrt(i,k) + g_sqrt(i,k-1))/2.0d0

        !--- g_sqrtのxz平均操作: g13(i,k) と同じ位置
        g_sqrt_xz(i,k) = (                                        &
             &            g_sqrt(i,k) + g_sqrt(i-1,k)             &
             &            + g_sqrt(i,k-1) + g_sqrt(i-1,k-1)       &
             &            )/4.0d0

        !--- g13のx平均操作: w(i,k) と同じ位置
        g13x(i,k) = (g13(i,k) + g13(i-1,k))/2.0d0

        !--- g13のz平均操作: u(i,k) と同じ位置
        g13z(i,k) = (g13(i,k) + g13(i,k-1))/2.0d0

        !--- g13のxz平均操作: スカラー量(i,k)と同じ位置
        g13xz(i,k) = (                               &
             &        g13(i+1,k+1) + g13(i+1,k)      &
             &        + g13(i,k+1) + g13(i,k)        &
             &       )/4.0d0

     end do
  end do

  g_sqrt(:,:) = 1.0d0
  g_sqrt_x(:,:) = 1.0d0
  g_sqrt_z(:,:) = 1.0d0
  g_sqrt_xz(:,:) = 1.0d0

end subroutine jacobian