!-------------------------------------------------------------------------
! Copyright (c) 2017 SPMODEL Development Group. All rights reserved.!
!-------------------------------------------------------------------------
!
!表題  asc_module テストプログラム
!
!      補間関数のテスト
!
!履歴  2017/05/17  竹広真一
!
!
program asc_test_interpolate

  use asc_module
  use dc_test
  implicit none

  integer, parameter :: im = 16,  km=10
  real(8), parameter :: xmin=0.0, xmax=1.0
  
  real(8)            :: g_Data(0:im)
  real(8)            :: s_Data(km)
  real(8)            :: c_Data(0:km)

  real(8)            :: ag_Data(2,0:im)
  real(8)            :: as_Data(2,km)
  real(8)            :: ac_Data(2,0:km)  

  real(8)            :: xobs   = 0.3d0
  real(8)            :: answer(2)
  real(8)            :: PI

  ! 判定誤差設定
  integer, parameter :: check_digits = 16
  integer, parameter :: ignore = -14

  PI = 4.0D0 * atan(1.0D0)

  call asc_Initial(im,km,xmin,xmax)

  !
  ! ----------- cos 変換補間テスト -------------
  !
  g_Data = sin(PI*g_X)**2
  c_Data = c_g(g_Data)

  call AssertEqual(&
    message = '1-dim Interpolation (cos transform)',            &
    answer = sin(PI*xobs)**2,                                   &
    check =  Interpolate_c(c_Data,xobs),                        &
    significant_digits = check_digits, ignore_digits = ignore   &
  )

  ag_Data(1,:) = cos(PI*g_X)**2
  ag_Data(2,:) = sin(PI*g_X)**4
  ac_Data      = ac_ag(ag_Data)

  answer(1) = cos(PI*xobs)**2
  answer(2) = sin(PI*xobs)**4

  call AssertEqual(&
    message = '2-dim Interpolation (cos transform)',            &
    answer = answer,                                            &
    check =  a_Interpolate_ac(ac_Data,xobs),                    &
    significant_digits = check_digits, ignore_digits = ignore   &
    )
  
  !
  ! ----------- sin 変換補間テスト -------------
  !
  g_Data = sin(PI*g_X)
  s_Data = s_g(g_Data)

  call AssertEqual(&
    message = '1-dim Interpolation (sin transform)',            &
    answer = sin(PI*xobs),                                      &
    check =  Interpolate_s(s_Data,xobs),                        &
    significant_digits = check_digits, ignore_digits = ignore   &
  )

  ag_Data(1,:) = sin(2*PI*g_X)
  ag_Data(2,:) = sin(4*PI*g_X)
  as_Data      = as_ag(ag_Data)

  answer(1) = sin(2*PI*xobs)
  answer(2) = sin(4*PI*xobs)

  call AssertEqual(&
    message = '2-dim Interpolation (sin transform)',            &
    answer = answer,                                            &
    check =  a_Interpolate_as(as_Data,xobs),                    &
    significant_digits = check_digits, ignore_digits = ignore   &
  )

end program asc_test_interpolate
