!----------------------------------------------------------------------
!     Copyright (c) 2017 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  scee_module_fftj テストプログラム (正逆変換)
!
!履歴  2017/05/26  竹広真一
!
program scee_module_fftj_base_test

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

  !---- 空間解像度設定 ----
  integer, parameter :: im=32, jm=32, km=16       ! 格子点の設定(X,Y)
  integer, parameter :: lm=10, mm=10, nm=10       ! 切断波数の設定(X,Y)

  !---- 変数 ----
  real(8)            :: zyx_Data(0:km,0:jm-1,0:im-1)    ! 格子データ
  real(8)            :: see_Data(nm,-mm:mm,-lm:lm)      ! スペクトルデータ
  real(8)            :: cee_Data(0:nm,-mm:mm,-lm:lm)    ! スペクトルデータ  

  integer            :: l=2, m=5

  !---- 座標変数など ----
  real(8), parameter :: xmin = 0.0d0, xmax=2.0d0
  real(8), parameter :: ymin = 0.0d0, ymax=2.0d0
  real(8), parameter :: zmin = -1.0d0, zmax=1.0d0

  real(8), parameter :: pi=3.1415926535897932385D0

  real(8)            :: zyx_Xi(0:km,0:jm-1,0:im-1)    ! 格子データ

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

  call MessageNotify('M','scee_module_fftj_base_test', &
       'scee_module_fftj basic transform function tests')

  !---------------- 座標値の設定 ---------------------
  ! スペクトル初期化
  call scee_initial(im,jm,km,lm,mm,nm,xmin,xmax,ymin,ymax,zmin,zmax) 

  zyx_Xi = (zyx_Z - zmin)/(zmax-zmin)

  !------------------- 関数チェック ----------------------
  zyx_Data = sin(l*pi*zyx_X) * sin(m*pi*zyx_Y) * sin(Pi*zyx_Xi)
  see_Data = 0.0 ; see_Data(1,m,l) = -0.25 ; ; see_Data(1,-m,l) = 0.25

  call AssertEqual(&
    message='see_zyx with sin(k*pi*X)*sin(l*pi*Y)*sin(Z)',        &
    answer = see_Data,                                            &
    check = see_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_see with sin(k*pi*X)*sin(l*pi*Y)*sin(Z)',        &
    answer = zyx_Data,                                            &
    check = zyx_see(see_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zyx_Data = sin(l*pi*zyx_X) * sin(m*pi*zyx_Y) * cos(Pi*zyx_Xi)
  cee_Data = 0.0 ; cee_Data(1,m,l) = -0.25 ; ; cee_Data(1,-m,l) = 0.25

  call AssertEqual(&
    message='cee_zyx with sin(k*pi*X)*sin(l*pi*Y)*cos(Z)',        &
    answer = cee_Data,                                            &
    check = cee_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_cee with sin(k*pi*X)*sin(l*pi*Y)*cos(Z)',        &
    answer = zyx_Data,                                            &
    check = zyx_cee(cee_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zyx_Data = cos(l*pi*zyx_X) * cos(m*pi*zyx_Y) * sin(2*PI*zyx_Xi)
  see_Data = 0.0 ; see_Data(2,m,l) = 0.25  ; see_Data(2,-m,l) = 0.25  

  call AssertEqual(&
    message='see_zyx with cos(k*pi*X)*cos(l*pi*Y)*sin(2Z)',       &
    answer = see_Data,                                            &
    check = see_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_see with cos(k*pi*X)*cos(l*pi*Y)*sin(2Z)',       &
    answer = zyx_Data,                                            &
    check = zyx_see(see_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zyx_Data = cos(l*pi*zyx_X) * cos(m*pi*zyx_Y) * cos(2*PI*zyx_Xi)
  cee_Data = 0.0 ; cee_Data(2,m,l) = 0.25  ; cee_Data(2,-m,l) = 0.25  

  call AssertEqual(&
    message='cee_zyx with cos(k*pi*X)*cos(l*pi*Y)*cos(2Z)',       &
    answer = cee_Data,                                            &
    check = cee_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_cee with cos(k*pi*X)*cos(l*pi*Y)*cos(2Z)',       &
    answer = zyx_Data,                                            &
    check = zyx_cee(cee_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zyx_Data = sin(l*pi*zyx_X) * cos(m*pi*zyx_Y)/2.0D0
  cee_Data = 0.0 ; cee_Data(0,-m,-l) = -0.25  ; cee_Data(0,m,-l) = - 0.25  

  call AssertEqual(&
    message='cee_zyx with sin(k*pi*X)*cos(l*pi*Y)/2',             &
    answer = cee_Data,                                            &
    check = cee_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_cee with sin(k*pi*X)*cos(l*pi*Y)/2',             &
    answer = zyx_Data,                                            &
    check = zyx_cee(cee_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zyx_Data = cos(l*pi*zyx_X) * sin(m*pi*zyx_Y)*sin(3*PI*zyx_Xi)
  see_Data = 0.0 ; see_Data(3,-m,-l) = -0.25  ; see_Data(3,m,-l) = 0.25  

  call AssertEqual(&
    message='see_zyx with cos(k*pi*X)*sin(l*pi*Y)*sin(3Z)',       &
    answer = see_Data,                                            &
    check = see_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_see with cos(k*pi*X)*sin(l*pi*Y)*sin(3Z)',       &
    answer = zyx_Data,                                            &
    check = zyx_see(see_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  zyx_Data = cos(l*pi*zyx_X) * sin(m*pi*zyx_Y)*cos(3*PI*zyx_Xi)
  cee_Data = 0.0 ; cee_Data(3,-m,-l) = -0.25  ; cee_Data(3,m,-l) = 0.25  

  call AssertEqual(&
    message='cee_zyx with cos(k*pi*X)*sin(l*pi*Y)*cos(3Z)',       &
    answer = cee_Data,                                            &
    check = cee_zyx(zyx_Data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='zyx_cee with cos(k*pi*X)*sin(l*pi*Y)*cos(3Z)',       &
    answer = zyx_Data,                                            &
    check = zyx_cee(cee_zyx(zyx_Data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  call MessageNotify('M','scee_module_fftj_base_test', &
       'scee_module_fftj basic transform functions tests succeeded!')

end program scee_module_fftj_base_test
