!= 蠕ｮ蛻�ｼ皮ｮ励Δ繧ｸ繝･繝ｼ繝ｫ (2 谺｡邊ｾ蠎ｦ荳ｭ螟ｮ蟾ｮ蛻�)
!
! Authors::   SUGIYAMA Ko-ichiro
! Version::   $Id: differentiate_center2.f90,v 1.4 2007-04-11 11:59:58 sugiyama Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2006. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]

module differentiate_center2
  !
  ! 2 谺｡邊ｾ蠎ｦ縺ｮ蠕ｮ蛻�ｼ皮ｮ励ｒ陦後≧縺溘ａ縺ｮ髢｢謨ｰ鄒､繧偵∪縺ｨ繧√◆繝代ャ繧ｱ繝ｼ繧ｸ蝙九Δ繧ｸ繝･繝ｼ繝ｫ
  ! 豌ｴ蟷ｳ Arakawa-C, 驩帷峩 Lorentz 繧ｰ繝ｪ繝�ラ縺ｧ縺ｮ蠕ｮ蛻�ｨ育ｮ�
  !

  !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
  implicit none

  !private 螻樊ｧ
  private

  !蜈ｬ髢玖ｦ∫ｴ�
  public xz_dx_pz, xr_dx_pr
  public pz_dx_xz, pr_dx_xr
  public xz_dz_xr, pz_dz_pr
  public xr_dz_xz, pr_dz_pz

  !--------------------------------------------
  interface xz_dx_pz
    module procedure xa_dx_pa
  end interface xz_dx_pz

  interface xr_dx_pr
    module procedure xa_dx_pa
  end interface xr_dx_pr
  !--------------------------------------------
  interface pz_dx_xz
    module procedure pa_dx_xa
  end interface pz_dx_xz

  interface pr_dx_xr
    module procedure pa_dx_xa
  end interface pr_dx_xr
  !--------------------------------------------
  interface xz_dz_xr
    module procedure az_dz_ar
  end interface xz_dz_xr

  interface pz_dz_pr
    module procedure az_dz_ar
  end interface pz_dz_pr
  !--------------------------------------------
  interface xr_dz_xz
    module procedure ar_dz_az
  end interface xr_dz_xz

  interface pr_dz_pz
    module procedure ar_dz_az
  end interface pr_dz_pz
  !--------------------------------------------

contains

!!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function xa_dx_pa( pa_var )
    !
    ! x 蠕ｮ蛻�: 蜊頑紛謨ｰ譬ｼ蟄千せ荳翫�蠕ｮ蛻�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use dc_types,  only : DP
    use gridset,   only : imin, imax, kmin, kmax
                                !驟榊�繧ｵ繧､繧ｺ
    use axesset,   only : dx    !譬ｼ蟄千せ髢馴囈

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pa_var(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�ｼ皮ｮ励�蟇ｾ雎｡縺ｨ縺ｪ繧句､画焚
    real(DP)             :: xa_dx_pa(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�､
    integer             :: ix

    ! 1 髫主ｾｮ蛻��險育ｮ�
    !
    do ix = imin+1, imax
      xa_dx_pa(ix,:) = ( pa_Var(ix,:) - pa_Var(ix-1,:) ) / dx
    end do

    xa_dx_pa(imin,:) = xa_dx_pa(imin+1,:)

  end function xa_dx_pa

!!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function pa_dx_xa( xa_var )
    !
    ! x 蠕ｮ蛻�: 謨ｴ謨ｰ譬ｼ蟄千せ荳翫�蠕ｮ蛻�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use dc_types,  only : DP
    use gridset,   only : imin, imax, kmin, kmax
                                !驟榊�繧ｵ繧､繧ｺ
    use axesset,   only : dx    !譬ｼ蟄千せ髢馴囈

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: xa_var(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�ｼ皮ｮ励�蟇ｾ雎｡縺ｨ縺ｪ繧句､画焚
    real(DP)             :: pa_dx_xa(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�､
    integer             :: ix

    ! 1 髫主ｾｮ蛻��險育ｮ�
    !
    do ix = imin, imax-1
      pa_dx_xa(ix,:) = (xa_Var(ix+1,:) - xa_Var(ix,:))/dx
    end do

    pa_dx_xa(imax,:) = pa_dx_xa(imax-1,:)

  end function pa_dx_xa

!!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function az_dz_ar(ar_var)
    !
    ! z 蠕ｮ蛻�: 蜊頑紛謨ｰ譬ｼ蟄千せ荳翫�蠕ｮ蛻�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use dc_types,  only : DP
    use gridset,   only : imin, imax, kmin, kmax
                                !驟榊�繧ｵ繧､繧ｺ
    use axesset,   only : dz    !譬ｼ蟄千せ髢馴囈

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: ar_var(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�ｼ皮ｮ励�蟇ｾ雎｡縺ｨ縺ｪ繧句､画焚
    real(DP)             :: az_dz_ar(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�､
    integer             :: kz

    ! 1 髫主ｾｮ蛻��險育ｮ�
    !
    do kz = kmin+1, kmax
      az_dz_ar(:,kz) = ( ar_Var(:,kz) - ar_Var(:,kz-1) ) / dz
    end do

    az_dz_ar(:,kmin) = az_dz_ar(:,kmin+1)

  end function az_dz_ar

!!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function ar_dz_az( az_var )
    !
    ! z 蠕ｮ蛻�: 謨ｴ謨ｰ譬ｼ蟄千せ荳翫�蠕ｮ蛻�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use dc_types,  only : DP
    use gridset,   only : imin, imax, kmin, kmax
                                !驟榊�繧ｵ繧､繧ｺ
    use axesset,   only : dz    !譬ｼ蟄千せ髢馴囈

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: az_var(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�ｼ皮ｮ励�蟇ｾ雎｡縺ｨ縺ｪ繧句､画焚
    real(DP)             :: ar_dz_az(imin:imax, kmin:kmax)
                                     !蠕ｮ蛻�､
    integer             :: kz

    do kz = kmin, kmax-1
      ar_dz_az(:,kz) = ( az_Var(:,kz+1) - az_Var(:,kz) ) / dz
    end do

    ar_dz_az(:,kmax) = ar_dz_az(:,kmax-1)

  end function ar_dz_az

!!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

end module differentiate_center2