!----------------------------------------------------------------------
!     Copyright (c) 2013 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  wa_wave_module_sjpack テストプログラム :: 基本変換関数のテスト
!
!履歴  2013/06/15  竹広真一
!
program wa_wave_module_sjpack_base_test

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

  integer :: im(2)=(/ 2, 2/)
  integer :: jm(2)=(/16,32/)
  integer :: nm(2)=(/10,21/)
  integer ::  m(2)=(/ 1, 1/)
  integer :: km(2)=(/ 3, 3/)

  real(8), allocatable ::  xya_data(:,:,:)
  real(8), allocatable ::  wa_data(:,:)

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

  integer :: n

  call MessageNotify('M','wa_wave_module_sjpack_base_test', &
                         'wa_wave_module_sjpack basic functions tests') 

  do n=1,2

  call wa_Initial( nm(n), m(n), im(n), jm(n), km(n) )

  allocate(wa_data(2*(nm(n)-m(n)+1),km(n)))
  allocate(xya_data(0:im(n)-1,1:jm(n),km(n)))

  !---- P_*^1 のテスト ----
  wa_data= 0.0D0 
  xya_data(:,:,1) = sqrt(3.0D0/2.0D0)*cos(xy_Lat)             ! P_1^1
  wa_data(1:2,1)=1.0D0
  xya_data(:,:,2) = sqrt(5.0D0/6.0D0)*(3*sin(xy_Lat)*cos(xy_Lat))  ! P_2^1
  wa_data(3:4,2)=1.0D0
  xya_data(:,:,3) = sqrt(7.0D0/12.0D0)*(3.0/2)*(5*sin(xy_Lat)**2-1)*cos(xy_Lat)  ! P_3^1
  wa_data(5:6,3)=1.0D0

  call AssertEqual(&
    message='P_*^1 Test of wa_xya(xya_data)',                    &
    answer = wa_data,                                            &
    check = wa_xya(xya_data),                                    &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='P_*^1 Test of xya_wa(wa_xya(xya_data))',           &
    answer = xya_data,                                            &
    check = xya_wa(wa_xya(xya_data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='P_*^1 Test of xya_wa(wa_xya(xya_data))',           &
    answer = xya_data,                                            &
    check = xya_wa(wa_xya(xya_data)),                           &
    significant_digits = check_digits, ignore_digits = ignore     &
    )


  deallocate(wa_data)
  deallocate(xya_data)

  call wa_Finalize

  enddo

  call MessageNotify('M','wa_wave_module_sjpack_base_test', &
                         'wa_wave\module_sjpack basic functions tests succeeded!') 

end program wa_wave_module_sjpack_base_test

