!----------------------------------------------------------------------
!     Copyright (c) 2013 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  wt_module テストプログラム :: 基本変換関数のテスト
!
!履歴  2013/07/03  竹広真一   wt_module_sjpack_base_test.f90 より改造
!
program wt_wave_module_sjpack_base_test

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

  integer,parameter  :: im=2,  jm=16, km=16  ! 格子点の設定(経度, 緯度, 動径)
  integer,parameter  :: nm=10, lm=16         ! 切断波数の設定(水平, 動径)
  integer,parameter  :: m=1                  ! 東西波数の設定
  real(8),parameter  :: ri=0.5, ro=1.5       ! 内外半径

  real(8), dimension(2*(nm-m+1),0:lm)        ::  wt_data
  real(8), dimension(0:im-1,1:jm,0:km)       ::  xyz_data
  real(8), dimension(0:im-1,1:jm,0:km)       ::  xyz_xi

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

  call MessageNotify('M','wt_wave_module_sjpack_base_test', &
                         'wt_wave_module_sjpack basic transformation functions tests') 

  call wt_Initial(im,jm,km,nm,m,lm,ri,ro)

  xyz_xi = (xyz_Rad - (ro+ri)/2 )*2/(ro-ri)

  !---- P_1^1 のテスト ----
  xyz_data = sqrt(3.0D0/2.0D0)*cos(xyz_Lat)*xyz_xi            ! P_1^1 T_1
  wt_data= 0.0D0 ; wt_data(1:2,1)=1.0D0

  call AssertEqual(&
    message='wt_xyz with P_1^1 T_1',                             &
    answer = wt_data,                                            &
    check = wt_xyz(xyz_data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='xyz_wt with P_1^1 T_1',                             &
    answer = xyz_data,                                            &
    check = xyz_wt(wt_xyz(xyz_data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  xyz_data =sqrt(3.0D0/2)*cos(xyz_Lat)*(2*xyz_xi**2-1) !P_1^1T_2
  wt_data= 0.0D0 ;  wt_data(1:2,2)=1.0D0

  call AssertEqual(&
    message='wt_xyz with P_1^1 T_2',                             &
    answer = wt_data,                                            &
    check = wt_xyz(xyz_data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='xyz_wt with P_1^1 T_2',                              &
    answer = xyz_data,                                            &
    check = xyz_wt(wt_xyz(xyz_data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  !---- Y_2^* のテスト ----
  ! P_2^1 T_4
  xyz_data = sqrt(5.0D0/6)*3.0*sin(xyz_Lat)*cos(xyz_Lat) &
            *(8*xyz_xi**4 - 8*xyz_xi**2 + 1 )
  wt_data= 0.0D0 ; wt_data(3:4,4)=1.0D0

  call AssertEqual(&
    message='wt_xyz with P_2^1 T_4',                             &
    answer = wt_data,                                            &
    check = wt_xyz(xyz_data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='xyz_wt with p_2^1 T_4',                             &
    answer = xyz_data,                                            &
    check = xyz_wt(wt_xyz(xyz_data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  ! P_2^ T_5
  xyz_data = sqrt(5.0D0/6)*3.0*sin(xyz_Lat)*cos(xyz_Lat) &
            *(16*xyz_xi**5-20*xyz_xi**3+5*xyz_xi)
  wt_data= 0.0D0 ; wt_data(3:4,5)=1.0D0

  call AssertEqual(&
    message='wt_xyz with P_2^1 T_5',                             &
    answer = wt_data,                                            &
    check = wt_xyz(xyz_data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='xyz_wt with P_2^1 T_5',                             &
    answer = xyz_data,                                            &
    check = xyz_wt(wt_xyz(xyz_data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  call MessageNotify('M','wt_wave_module_sjpack_base_test_base', &
                         'wt_wave_module_sjpack basic functions tests succeeded!') 

end program wt_wave_module_sjpack_base_test

