!----------------------------------------------------------------------
!     Copyright (c) 2018 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  ut_mpi_module_sypack テストプログラム :: 補間関数のテスト
!
!履歴  2018/06/0  竹広真一
!
program ut_mpi_module_sypack_interpol

  use dc_message, only : MessageNotify
  use dc_test, only : AssertEqual
  use ut_mpi_module_sypack
  use mampi
  implicit none

  integer, parameter :: im=128, jm=64, km=16, nm=42, lm=16
  real(8), parameter :: ri = 0.5, ro= 1.5
  integer :: npv = 2
  integer :: iproc, np, ierr
  
  real(8), allocatable  ::  ut_data(:,:)
  real(8), allocatable  ::  xvh_data(:,:,:)

  ! 判定誤差設定
  integer, parameter :: check_digits = 10
  integer, parameter :: ignore = -11

  real(8) :: Alon
  real(8) :: Alat
  real(8) :: Arad
  real(8) :: data_sol
  real(8) :: pi

  !---------------- MPI スタート ---------------------
  !call get_ENV_INT('NPV',npv)

  call MPI_INIT(IERR)
  call MPI_COMM_RANK(MPI_COMM_WORLD,IPROC,IERR)
  call MPI_COMM_SIZE(MPI_COMM_WORLD,NP,IERR)

  call MessageNotify('M','ut_mpi_module_sypack_interpolate_test', &
                         'ut_mpi_module_sypack interpolate tests') 

  pi = atan(1.0D0)*4.0D0

  Alon = pi/3
  Alat = pi/3
  Arad = 0.75
!!$  Alon =pi/4
!!$  Alat =pi/5
!!$  Arad =0.99
!!$  Alon = 3*pi/5
!!$  Alat = -pi/7
!!$  Arad = 1.333 

  call ut_mpi_Initial( im, jm, km, nm, lm, ri, ro, npv=npv )

  allocate(ut_data(nmc,0:lm))
  allocate(xvh_data(0:im-1,1:jc,kc))

  !---- Interpolaate_array000_ut のテスト ----
  xvh_data = sqrt(3.0D0/2)*cos(xvh_Lat)*cos(xvh_Lon) & ! Y_1^1
            * (xvh_Rad-ri) *  (xvh_Rad-ro)

  data_sol = sqrt(3.0D0/2)*cos(ALat)*cos(ALon) * (ARad-ri) *  (ARad-ro)

  ut_data = ut_xvh(xvh_data)

  call AssertEqual(&
       message='Interpolate_ut Y_1^-1',                              &
       answer = data_sol,                                            &
       check = Interpolate_ut(ut_data,alon,alat,arad),      &
       significant_digits = check_digits, ignore_digits = ignore     &
       )

  call MessageNotify('M','ut_mpi_module_sypack_interpolate_test',&
                         'ut_mpi_module_sypack interpolate function test succeeded!') 

  !------ MPIの終了 ------
  call MPI_FINALIZE(IERR)
  
end program ut_mpi_module_sypack_interpol

