!----------------------------------------------------------------------
!     Copyright (c) 2017 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  wsc_module_svpack テストプログラム :: 補間関数のテスト
!
!履歴  2017/05/20  竹広真一
!
program wsc_module_svpack_interpolate

  use dc_message, only : MessageNotify
  use dc_test, only : AssertEqual
  use wsc_module_svpack
  implicit none

  integer, parameter :: im=64, jm=32, km=16, nm=21, lm=10
  real(8), parameter :: ri = 0.5, ro= 1.5

  real(8), dimension((nm+1)**2,0:lm)       ::  wc_data
  real(8), dimension((nm+1)**2,lm)         ::  ws_data
  real(8), dimension(0:im-1,1:jm,0:km)     ::  xyz_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

  pi = atan(1.0D0)*4.0D0

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

  call wsc_Initial( im, jm, km, nm, lm, ri, ro )

  call MessageNotify('M','wsc_module_svpack_interpolate_test', &
                         'wsc_module_svpack interpolate tests') 


  !---- Interpolaate_ws のテスト ----
  xyz_data = sqrt(3.0D0/2)*cos(xyz_Lat)*cos(xyz_Lon) & ! Y_1^1
            * sin(PI*(xyz_Rad-ri)/(ro-ri))
  data_sol = sqrt(3.0D0/2)*cos(ALat)*cos(ALon) * sin(PI*(ARad-ri)/(ro-ri))

  ws_data = ws_xyz(xyz_data)

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

  !---- Interpolaate_wc のテスト ----
  xyz_data = sqrt(3.0D0/2)*cos(xyz_Lat)*cos(xyz_Lon) & ! Y_1^1
            * cos(PI*(xyz_Rad-ri)/(ro-ri))
  data_sol = sqrt(3.0D0/2)*cos(ALat)*cos(ALon) * cos(PI*(ARad-ri)/(ro-ri))

  wc_data = wc_xyz(xyz_data)

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

  call MessageNotify('M','wsc_module_svpack_interpolate_test',&
                         'wsc_module_svpack interpolate function test succeeded!') 

end program wsc_module_svpack_interpolate
