!----------------------------------------------------------------------
!     Copyright (c) 2017 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  w_wave_module_svpack テストプログラム :: 基本変換関数のテスト
!
!履歴  2017/03/09  竹広真一
!
program w_wave_module_svpack_base_test

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

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

  real(8), allocatable :: w_data(:)
  real(8), allocatable :: xy_data(:,:)

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

  integer :: n

  call MessageNotify('M','w_wave_module_svpack_base_test', &
                         'w_wave_module_svpack basic functions tests') 

  do n=1,2

  call w_Initial( nm(n), m(n), im(n), jm(n) )

  allocate(w_data(2*(nm(n)-m(n)+1)))
  allocate(xy_data(0:im(n)-1,1:jm(n)))

  !---- P_1^1 のテスト ----
  xy_data = sqrt(3.0D0/2.0D0)*cos(xy_Lat)
  w_data= 0.0D0 ; w_data(1:2)=1.0D0

  call AssertEqual(&
    message='P_1 Test of w_xy(xy_data)',                         &
    answer = w_data,                                             &
    check = w_xy(xy_data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='P_1 Test of xy_w(w_xy(xy_data))',                  &
    answer = xy_data,                                             &
    check = xy_w(w_xy(xy_data)),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  !---- P_2^1 のテスト ----
  xy_data = sqrt(5.0D0/6.0D0)*(3*sin(xy_Lat)*cos(xy_Lat))       ! P_2
  w_data= 0.0D0 ; w_data(3:4)=1.0D0

  call AssertEqual(&
    message='P_2 Test of w_xy(xy_data)',                         &
    answer = w_data,                                             &
    check = w_xy(xy_data),                                       &
    significant_digits = check_digits, ignore_digits = ignore     &
    )
  call AssertEqual(&
    message='P_2 Test of xy_w(w_xy(xy_data))',                  &
    answer = xy_data,                                             &
    check = xy_w(w_xy(xy_data)),                                &
    significant_digits = check_digits, ignore_digits = ignore     &
    )

  deallocate(w_data)
  deallocate(xy_data)

  call w_Finalize

  enddo

  call MessageNotify('M','w_wave_module_svpack_base_test', &
                         'w_wave_module_svpack basic functions tests succeeded!') 

end program w_wave_module_svpack_base_test
