!----------------------------------------------------------------------
!     Copyright (c) 2024 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  w_zonal_module テストプログラム :: 基本変換関数のテスト
!
!履歴  2020/11/24  竹広真一
!
program w_zonal_module_base_test

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

  integer :: imm(2)=(/ 1, 1/)
  integer :: jmm(2)=(/16,32/)
  integer :: nmm(2)=(/10,21/)

  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_zonal_module_base_test', &
                         'w_zonal_module_ basic functions tests') 

  do n=1,2

  call w_Initial( nmm(n), imm(n), jmm(n) )

  allocate(w_data(nmm(n)+1))
  allocate(xy_data(0:imm(n)-1,1:jmm(n)))

  !---- P_1^0 のテスト ----
  xy_data = sqrt(3.0D0)*sin(xy_Lat)
  w_data= 0.0D0 ; w_data(l_nm(1,0))=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^0 のテスト ----
  xy_data = sqrt(5.0D0)*(3.0D0*sin(xy_Lat)**2-1.0D0)/2.0D0      ! P_2
  w_data= 0.0D0 ; w_data(l_nm(2,0))=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_zonal_module_lsbase_test', &
                         'w_zonal_module basic functions tests succeeded!') 

end program w_zonal_module_base_test
