!= IGModel ベースライブラリのテスト用プログラム. 
! 
! Authors::   Yuta Kawai
! Version::   $Id: IGMBaseLib_Core_test.f90,v 1.1 2011-04-22 16:56:21 ykawai Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2011-12. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

program IGMBaseLib_Core_test
  use dc_types, only: DP
  use dc_test, only: AssertEqual
  implicit none
  
  !
  write(*,*) 'icgrid module test'
  
  write(*,*) '* create grid: glevel5_l1'
  call test_icgrid_module( &
    & glevel=5, z_divNum=1 &
    & )

  write(*,*) '* create grid: glevel6_l3'
  call test_icgrid_module( &
    & glevel=6, z_divNum=3 &
    & )

contains
subroutine test_icgrid_module(glevel, z_divNum)
  !
  !
  !
  use IcGrid, only: rcs_layers, &
    &               init_icgrid, &
    &                dispose_icgrid

  implicit none

  integer, intent(in) :: glevel
  integer, intent(in) :: z_divNum
  
  real(DP) zLvRadii(z_divNum)
  real(DP) :: r0 = 6.4d07      ! 最下層における球中心からの半径
  real(DP) :: H = 1.0d04       ! 最下層から上端まで 10 km
  real(DP) DelH
  integer zLv
  integer sg_array_sizes(2)
  integer cv_array_sizes(2)

  zLvRadii(1) = r0

  if ( z_divNum > 1 ) then
    DelH = H / ( z_divNum - 1.0d00 ) 
  
    !
    do  zLv=2, z_divNum
      zLvRadii(zLv) = r0 + DelH * ( zLv - 1.0d00 ) 
    end do
  end if

  call init_icgrid( &
    & hGridLevel=glevel, zLevelNum=z_divNum, & ! (in) 
    & zLv_radii=zLvRadii & ! (in)
    & )

  sg_array_sizes = (/ (2**glevel+1)+2, (2**glevel+1)+2 /)  
  cv_array_sizes = (/ sg_array_sizes(1)-1, 2*(sg_array_sizes(2)-1) /)  
  
  ! 
  do zLv=1, z_divNum
    call AssertEqual( message='Check array size of rect region STD grid', &
      & answer=sg_array_sizes,                                  &
      & check=(/ size(rcs_layers(zLv)%SG_Pos, 2), size(rcs_layers(zLv)%SG_Pos, 3) /) )

    call AssertEqual( message='Check array size of rect region CV grid', &
      & answer=cv_array_sizes,                                  &
      & check=(/ size(rcs_layers(zLv)%CV_Pos, 2), size(rcs_layers(zLv)%CV_Pos, 3) /) )
    
    call AssertEqual( message='Check raidius', &
        & answer=zLvRadii(zLv), check=rcs_layers(zLv)%radius )
  end do

  !
  call dispose_icgrid()

end subroutine

end program IGMBaseLib_Core_test
