!= dyn_spectral_as83 モジュールのテストプログラム
!
!= Test program for "dyn_spectral_as83"
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: dyn_spectral_as83_test.f90,v 1.3 2007/07/26 08:37:17 morikawa Exp $
! Tag Name::  $Name: dcpam4-20070730-2 $
! Copyright:: Copyright (C) GFD Dennou Club, 2007. All rights reserved.
! License::
!
! <b>Note that Japanese and English are described in parallel.</b>
!
! dyn_spectral_as83 モジュールの動作テストを行うためのプログラムです.
! このプログラムがコンパイルできること, および実行時に
! プログラムが正常終了することを確認してください.
!
! This program checks the operation of "dyn_spectral_as83" module.
! Confirm compilation and execution of this program.
!

program dyn_spectral_as83_test
  use constants, only: CONST, Create, Get
  use dc_types, only: DP, STRING
  use dyn_spectral_as83, only: DYNSPAS83, Create, Close, PutLine, initialized
  use dc_test, only: AssertEqual
  use dc_string, only: StoA
  use dc_args, only: ARGS, Open, HelpMsg, Option, Debug, Help, Strict, Close
  implicit none

  !---------------------------------------------------------
  !  実験の表題, モデルの名称, 所属機関名
  !  Title of a experiment, name of model, sub-organ
  !---------------------------------------------------------
  character(*), parameter:: title = &
    & 'dyn_spectral_as83_test $Name: dcpam4-20070730-2 $ :: ' // &
    & 'Test program of "dyn_spectral_as83" module'
  character(*), parameter:: source = &
    & 'dcpam4 ' // &
    & '(See http://www.gfd-dennou.org/library/dcpam)'
  character(*), parameter:: institution = &
    & 'GFD Dennou Club (See http://www.gfd-dennou.org)'

  !---------------------------------------------------------
  !  作業変数
  !  Work variables
  !---------------------------------------------------------
  type(ARGS):: arg            ! コマンドライン引数. 
                              ! Command line arguments
  logical:: OPT_namelist      ! -N, --namelist オプションの有無. 
                              ! Existence of '-N', '--namelist' option
  character(STRING):: VAL_namelist
                              ! -N, --namelist オプションの値. 
                              ! Value of '-N', '--namelist' option
  type(CONST):: const_earth
  real(DP):: PI         ! $ \pi $ .    円周率.         Circular constant
  real(DP):: RPlanet    ! $ a $ .      惑星半径.       Radius of planet
  real(DP):: Omega      ! $ \Omega $ . 回転角速度.     Angular velocity
  real(DP):: Grav       ! $ g $ .      重力加速度.     Gravitational acceleration
  real(DP):: Cp         ! $ C_p $ .    大気定圧比熱.   Specific heat of air at constant pressure
  real(DP):: RAir       ! $ R $ .      大気気体定数.   Gas constant of air
  real(DP):: EpsVT      ! $ 1/\epsilon_v - 1 $ .
  integer:: VisOrder    ! 超粘性の次数.  Order of hyper-viscosity
  real(DP):: EFoldTime  ! 最大波数に対する e-folding time. E-folding time for maximum wavenumber
  type(DYNSPAS83):: dyn_sp_as00, dyn_sp_as01
  real(DP):: DelTime
  logical:: err
continue

  !---------------------------------------------------------
  !  コマンドライン引数の処理
  !  Command line arguments handling
  !---------------------------------------------------------
  call Open( arg )
  call HelpMsg( arg, 'Title', title )
  call HelpMsg( arg, 'Usage', &
    & './dyn_spectral_as83_test [Options]' )
  call HelpMsg( arg, 'Source', source )
  call HelpMsg( arg, 'Institution', institution )
  call Option( arg, StoA('-N', '--namelist'), &
    & OPT_namelist, VAL_namelist, help = "NAMELIST filename" )
  call Debug( arg ) ; call Help( arg ) ; call Strict( arg, severe = .true. )
  call Close( arg )

  !---------------------------------------------------------
  !  物理定数の準備
  !  Prepare physical constants
  !---------------------------------------------------------
  call Create( const_earth ) ! (inout)

  DelTime = 180.0_DP

  call Get( constant = const_earth, &              ! (inout)
    & PI = PI, RPlanet = RPlanet, Grav = Grav, &   ! (out)
    & Omega = Omega, &                             ! (out)
    & Cp = Cp, RAir = RAir, EpsVT = EpsVT, &       ! (out)
    & VisOrder = VisOrder, EFoldTime = EFoldTime ) ! (out)

  !---------------------------------------------------------
  !  初期設定テスト
  !  Initialization test
  !---------------------------------------------------------
  call Create( dyn_sp_as00, &                       ! (inout)
    & nmax = 21, imax = 64, jmax = 32, kmax = 12, & ! (in)
    & PI = PI, RPlanet = RPlanet, Grav = Grav, &    ! (in)
    & Omega = Omega, Cp = Cp, RAir = RAir, &        ! (in)
    & EpsVT = EpsVT, &                              ! (in)
    & VisOrder = VisOrder, EFoldTime = EFoldTime, & ! (in)
    & DelTIme = DelTime )                           ! (in)
  call AssertEqual( 'initialization test 1', &
    & answer = .true., check = initialized(dyn_sp_as00) )
  call PutLine( dyn_sp_as00 ) ! (in)

!!$  call Create( dyn_sp_as00, err )
!!$  call AssertEqual( 'initialization test 2', &
!!$    & answer = .true., check = err )

  call Close( dyn_sp_as00 ) ! (inout)
  call AssertEqual( 'termination test 1', &
    & answer = .false., check = initialized(dyn_sp_as00) )
  call PutLine( dyn_sp_as00 )

  call Close( dyn_sp_as01, & ! (inout)
    & err )                  ! (out)
  call AssertEqual( 'termination test 2', &
    & answer = .true., check = err )

end program dyn_spectral_as83_test
