!= 力学過程: セミインプリシット時間積分用行列
!
!= Dynamical core: Matrices for semi-implicit time integration
!
! Authors:: Yasuhiro MORIKAWA
! Version:: $Id: dyn_matrix.f90,v 1.11 2007-09-08 20:36:41 morikawa Exp $
! Tag Name:: $Name: dcpam4-20080626 $
! Copyright:: Copyright (C) GFD Dennou Club, 2007. All rights reserved.
! License:: See COPYRIGHT[link:../../../COPYRIGHT]
!
module dyn_matrix
!
!= 力学過程: セミインプリシット時間積分用行列
!
!= Dynamical core: Matrices for semi-implicit time integration
!
! Note that Japanese and English are described in parallel.
!
! 力学過程におけるセミインプリシット時間積分に用いる LU 行列を作成し,
! その LU 行列によって連立 1 次方程式を解く.
!
! Generate LU matrix for semi-implicit time integration in dynamical core.
! And solve linear simultaneous equation with the LU matrix.
!
!== Procedures List
!
! Create :: DYNMTX 型変数の初期設定
! Solve :: 解の計算
! Close :: DYNMTX 型変数の終了処理
! PutLine :: DYNMTX 型変数に格納されている情報の印字
! initialized :: DYNMTX 型変数が初期設定されているか否か
! ------------ :: ------------
! Create :: Constructor of "DYNMTX"
! Solve :: Calculate the solution
! Close :: Deconstructor of "DYNMTX"
! PutLine :: Print information of "DYNMTX"
! initialized :: Check initialization of "DYNMTX"
!
!== Usage
!
! 始めに, DYNMTX 型の変数を定義し, Create で初期設定を行います.
! LU 行列は GetLU にて取得してください.
! 最後に, DYNMTX 型の変数の終了処理を Close にて行います.
!
! First, initialize "DYNMTX" by "Create".
! Get LU matrix by GetLU.
! Finally, terminate "DYNMTX" by "Close".
!
use dc_types, only: DP
implicit none
private
public:: DYNMTX, Create, Close, PutLine, initialized, Solve
type DYNMTX
!
! まず, Create で "DYNMTX" 型の変数を初期設定して下さい.
! 初期設定された "DYNMTX" 型の変数を再度利用する際には,
! Close によって終了処理を行ってください.
!
! Initialize "DYNMTX" variable by "Create" before usage.
! If you reuse "DYNMTX" variable again for another application,
! terminate by "Close".
!
logical:: initialized = .false. ! 初期設定フラグ.
! Initialization flag
integer:: nmax ! 最大全波数.
! Maximum truncated wavenumber
integer:: kmax ! 鉛直層数.
! Number of vertical level
real(DP), pointer:: wzz_siMtxLU(:,:,:) =>null()
! セミインプリシット行列の LU 分解.
! LU decomposition for semi-implicit matrix
integer, pointer:: wz_siMtxPiv(:,:) =>null()
! セミインプリシット行列のピボット.
! Pivot for semi-implicit matrix
end type DYNMTX
character(*), parameter:: version = &
& '$Name: dcpam4-20080626 $' // &
& '$Id: dyn_matrix.f90,v 1.11 2007-09-08 20:36:41 morikawa Exp $'
interface Create
module procedure DynMatrixCreate
end interface
interface Close
module procedure DynMatrixClose
end interface
interface PutLine
module procedure DynMatrixPutLine
end interface
interface initialized
module procedure DynMatrixInitialized
end interface
interface Solve
module procedure DynMatrixSolve
end interface
interface NmlRead
module procedure DynMatrixNmlRead
end interface
!!$ interface Sample
!!$ module procedure DynMatrixSample
!!$ end interface
contains
subroutine DynMatrixCreate( dyn_mtx, &
& nmax, kmax, nmo, &
& RPlanet, DelTime, &
& zz_siMtxWH, zz_siMtxGCt, &
& w_DiffVorDiv, w_DiffTherm, &
& nmlfile, err )
!
! DYNMTX 型の変数の初期設定を行います.
! 他のサブルーチンを使用する前に必ずこのサブルーチンによって
! DYNMTX 型の変数を初期設定してください.
! なお, 与えられた *dyn_mtx* が既に初期設定されている場合,
! プログラムはエラーを発生させます.
!
! NAMELIST を利用する場合には引数 *nmlfile* に NAMELIST ファイル名
! を与えてください. NAMELIST 変数群の詳細に関しては
! NAMELIST#dyn_matrix_nml を参照してください.
!
! Constructor of "DYNMTX".
! Initialize *dyn_mtx* by this subroutine,
! before other procedures are used,
! Note that if *dyn_mtx* is already initialized
! by this procedure, error is occurred.
!
! In order to use NAMELIST, specify a NAMELIST filename to
! argument *nmlfile*. See "NAMELIST#dyn_matrix_nml"
! for details about a NAMELIST group.
!
use dc_trace, only: BeginSub, EndSub
use dc_types, only: STRING, STDOUT
use dcpam_error, only: StoreError, DC_NOERR, DCPAM_EALREADYINIT, &
& DCPAM_ELMAXMISMATCH, DCPAM_ENEGATIVE
use dc_string, only: toChar, PutLine
use lumatrix, only: LUDecomp
implicit none
type(DYNMTX), intent(inout):: dyn_mtx
integer, intent(in):: nmax ! 最大全波数.
! Maximum truncated wavenumber
integer, intent(in):: kmax ! 鉛直層数.
! Number of vertical level
integer, intent(in):: nmo (1:2, 0:nmax, 0:nmax)
! スペクトルの添字順番.
! Spectral subscript expression
real(DP), intent(in):: RPlanet ! $ a $ . 惑星半径. Radius of planet
real(DP), intent(in):: DelTime ! $ \Delta t $ . タイムステップ. Time step
real(DP), intent(in):: zz_siMtxWH (0:kmax-1, 0:kmax-1)
! $ W h $
real(DP), intent(in):: zz_siMtxGCt (0:kmax-1, 0:kmax-1)
! $ G C^{T} $ ( $ C = \Delta \sigma $ )
real(DP), intent(in):: w_DiffVorDiv ((nmax+1)**2)
! $ -K_{HD} [(-1)^{N_D/2}\nabla^{N_D}- (2/a^2)^{N_D/2}] $ .
! 運動量水平拡散係数.
! Coefficient of horizontal momentum diffusion
real(DP), intent(in):: w_DiffTherm ((nmax+1)**2)
! $ -(-1)^{N_D/2}K_{HD}\nabla^{N_D} $ .
! 熱, 水水平拡散係数.
! Coefficient of horizontal thermal and water diffusion
character(*), intent(in), optional :: nmlfile
! NAMELIST ファイルの名称.
! この引数に空文字以外を与えた場合,
! 指定されたファイルから
! NAMELIST 変数群を読み込みます.
! ファイルを読み込めない場合にはエラーを
! 生じます.
!
! NAMELIST 変数群の詳細に関しては
! NAMELIST#dyn_matrix_nml
! を参照してください.
!
! NAMELIST file name.
! If nonnull character is specified to
! this argument,
! NAMELIST group name is loaded from the
! file.
! If the file can not be read,
! an error occurs.
!
! See "NAMELIST#dyn_matrix_nml"
! for details about a NAMELIST group.
!
logical, intent(out), optional:: err
! 例外処理用フラグ.
! デフォルトでは, この手続き内でエラーが
! 生じた場合, プログラムは強制終了します.
! 引数 *err* が与えられる場合,
! プログラムは強制終了せず, 代わりに
! *err* に .true. が代入されます.
!
! Exception handling flag.
! By default, when error occur in
! this procedure, the program aborts.
! If this *err* argument is given,
! .true. is substituted to *err* and
! the program does not abort.
!-----------------------------------
! 作業変数
! Work variables
real(DP):: zz_siMtxM (0:kmax-1, 0:kmax-1)
! 行列 $ \underline{M} $.
! Matrix $ \underline{M} $
integer:: z_siMtxPivWork(0:kmax-1)
! 行列のピボット作成の作業変数.
! Work variable for pivot
real(DP) :: flapla ! $ \nabla_{\sigma}^{2} $
integer:: mmax ! 最大東西波数.
! Maximum truncated zonal wavenumber
integer:: lmax ! 最大南北波数.
! Maximum truncated meridional wavenumber
integer:: n, m, l, nm, k, kk, mxnm
! DO ループ用作業変数
! Work variables for DO loop
integer:: stat
character(STRING):: cause_c
character(*), parameter:: subname = 'DynMatrixCreate'
continue
call BeginSub(subname, version)
stat = DC_NOERR
cause_c = ''
!-----------------------------------------------------------------
! 初期設定のチェック
! Check initialization
!-----------------------------------------------------------------
if (dyn_mtx % initialized) then
stat = DCPAM_EALREADYINIT
cause_c = 'DYNMTX'
goto 999
end if
!-----------------------------------------------------------------
! 引数の正当性のチェック
! Validation of arguments
!-----------------------------------------------------------------
if (nmax < 1) then
stat = DCPAM_ENEGATIVE
cause_c = 'nmax'
goto 999
end if
if (kmax < 1) then
stat = DCPAM_ENEGATIVE
cause_c = 'kmax'
goto 999
end if
!-----------------------------------------------------------------
! 波数・格子点の設定
! Configure wave number and grid point
!-----------------------------------------------------------------
dyn_mtx % nmax = nmax
dyn_mtx % kmax = kmax
!-------------------------
! NAMELIST からの値
! Values from NAMELIST
!!$ if ( present_and_not_empty(nmlfile) ) then
!!$ call MessageNotify( 'M', subname, &
!!$ & 'Loading NAMELIST file "%c" ...', &
!!$ & c1=trim(nmlfile) )
!!$ call NmlRead ( nmlfile = nmlfile, & ! (in)
!!$ & param_i = dyn_mtx % param_i, & ! (inout)
!!$ & param_r = dyn_mtx % param_r, & ! (inout)
!!$ & param_c_ = dyn_mtx % param_c, & ! (inout)
!!$ & err = err ) ! (out)
!!$ if ( present_and_true(err) ) then
!!$ call MessageNotify( 'W', subname, &
!!$ & '"%c" can not be read.', &
!!$ & c1=trim(nmlfile) )
!!$ stat = DC_ENOFILEREAD
!!$ cause_c = nmlfile
!!$ goto 999
!!$ end if
!!$ end if
!-----------------------------------------------------------------
! セミインプリシット行列の割付
! Allocate semi-implicit matrices
!-----------------------------------------------------------------
allocate( dyn_mtx % wzz_siMtxLU((nmax+1)**2, 0:kmax-1, 0:kmax-1) )
allocate( dyn_mtx % wz_siMtxPiv((nmax+1)**2, 0:kmax-1) )
mmax = nmax
lmax = nmax
mxnm = 0
Loop_n: do n = 0, nmax
flapla = - real(n) * real(n+1) / RPlanet**2
!---------------------------------------------------------------
! スペクトル添字順序の取り出し
! Fetch spectral subscript expression
!---------------------------------------------------------------
stat = DCPAM_ELMAXMISMATCH
do m = 0, min(n,mmax)
if ( n-m <= lmax ) then
nm = nmo(1,m,n-m)
stat = DC_NOERR
exit
endif
end do
if (stat /= DC_NOERR) then
cause_c = 'n-m=' // toChar(n-m) // ', lmax=' // toChar(lmax)
goto 999
end if
!---------------------------------------------------------------
! 行列 $ \underline{M} $ の計算
! Calculate matrix $ \underline{M} $
!---------------------------------------------------------------
do k = 0, kmax-1
do kk = 0, kmax-1
zz_siMtxM ( k,kk ) = &
& - DelTime**2 * flapla &
& * ( zz_siMtxWH( k,kk ) &
& + zz_siMtxGCt( k,kk ) &
& * ( 1.0_DP + DelTime * 2.0_DP * w_DiffTherm(nm) ) )
if ( k == kk ) then
zz_siMtxM ( k,kk ) = &
& zz_siMtxM ( k,kk ) &
& + ( 1.0_DP + DelTime * 2.0_DP * w_DiffVorDiv(nm) ) &
& * ( 1.0_DP + DelTime * 2.0_DP * w_DiffTherm(nm) )
endif
end do
end do
!---------------------------------------------------------------
! LU 行列計算
! LU matrix calculation
!---------------------------------------------------------------
call LUDecomp( &
& zz_siMtxM, & ! (inout)
& z_siMtxPivWork ) ! (out)
! ダミー値の代入. (位置 kmax-1 はまだ未定義なため).
! Dummy value is subtituted. (Position kmax-1 is undefined yet).
z_siMtxPivWork(kmax-1) = 0
!!$ write(*,*) 'n= ', n
!!$
!!$ do k = 0, kmax-1
!!$ do kk = 0, kmax-1
!!$ write(*,*) 'zz_siMtxM(', k+1, ',', kk+1, ')= ', zz_siMtxM(k,kk)
!!$ end do
!!$ end do
!!$ do k = 0, kmax-1
!!$ write(*,*) 'z_siMtxPivWork(', k, ')= ', z_siMtxPivWork(k)
!!$ end do
!---------------------------------------------------------------
! 配列の詰め替え
! Repack matrices
!---------------------------------------------------------------
do m = 0, mmax
l = n - m
if ( ( l >= 0 ) .and. ( l <= lmax ) ) then
do k = 0, kmax-1
do kk = 0, kmax-1
dyn_mtx % wzz_siMtxLU ( nmo(1,m,l),k,kk ) = zz_siMtxM ( k,kk )
dyn_mtx % wzz_siMtxLU ( nmo(2,m,l),k,kk ) = zz_siMtxM ( k,kk )
end do
dyn_mtx % wz_siMtxPiv ( nmo(1,m,l),k ) = z_siMtxPivWork ( k )
dyn_mtx % wz_siMtxPiv ( nmo(2,m,l),k ) = z_siMtxPivWork ( k )
mxnm = max( mxnm, nmo(1,m,l) )
mxnm = max( mxnm, nmo(2,m,l) )
end do
endif
end do
end do Loop_n
do nm = mxnm+1, (nmax+1)**2
do k = 0, kmax-1
do kk = 0, kmax-1
dyn_mtx % wzz_siMtxLU ( nm,k,kk ) = zz_siMtxM ( k,kk )
end do
dyn_mtx % wz_siMtxPiv ( nm,k ) = z_siMtxPivWork ( k )
end do
end do
!-----------------------------------------------------------------
! 終了処理, 例外処理
! Termination and Exception handling
!-----------------------------------------------------------------
dyn_mtx % initialized = .true.
999 continue
call StoreError(stat, subname, err, cause_c)
call EndSub(subname)
end subroutine DynMatrixCreate
subroutine DynMatrixClose( dyn_mtx, err )
!
! DYNMTX 型の変数の終了処理を行います.
! なお, 与えられた *dyn_mtx* が Create によって初期設定
! されていない場合, プログラムはエラーを発生させます.
!
! Deconstructor of "DYNMTX".
! Note that if *dyn_mtx* is not initialized by "Create" yet,
! error is occurred.
!
use dc_trace, only: BeginSub, EndSub
use dc_types, only: STRING, STDOUT
use dc_string, only: PutLine
use dcpam_error, only: StoreError, DC_NOERR, DCPAM_ENOTINIT
implicit none
type(DYNMTX), intent(inout):: dyn_mtx
logical, intent(out), optional:: err
! 例外処理用フラグ.
! デフォルトでは, この手続き内でエラーが
! 生じた場合, プログラムは強制終了します.
! 引数 *err* が与えられる場合,
! プログラムは強制終了せず, 代わりに
! *err* に .true. が代入されます.
!
! Exception handling flag.
! By default, when error occur in
! this procedure, the program aborts.
! If this *err* argument is given,
! .true. is substituted to *err* and
! the program does not abort.
integer:: stat
character(STRING):: cause_c
character(*), parameter:: subname = 'DynMatrixClose'
continue
call BeginSub(subname)
stat = DC_NOERR
cause_c = ''
!-----------------------------------------------------------------
! 初期設定のチェック
! Check initialization
!-----------------------------------------------------------------
if (.not. dyn_mtx % initialized) then
stat = DCPAM_ENOTINIT
cause_c = 'DYNMTX'
goto 999
end if
!-----------------------------------------------------------------
! "DYNMTX" の設定の消去
! Clear the settings for "DYNMTX"
!-----------------------------------------------------------------
deallocate( dyn_mtx % wzz_siMtxLU )
deallocate( dyn_mtx % wz_siMtxPiv )
!-----------------------------------------------------------------
! 終了処理, 例外処理
! Termination and Exception handling
!-----------------------------------------------------------------
dyn_mtx % initialized = .false.
999 continue
call StoreError(stat, subname, err, cause_c)
call EndSub(subname)
end subroutine DynMatrixClose
subroutine DynMatrixPutLine( dyn_mtx, unit, indent, err )
!
! 引数 *dyn_mtx* に設定されている情報を印字します.
! デフォルトではメッセージは標準出力に出力されます.
! *unit* に装置番号を指定することで, 出力先を変更することが可能です.
!
! Print information of *dyn_mtx*.
! By default messages are output to standard output.
! Unit number for output can be changed by *unit* argument.
!
use dc_trace, only: BeginSub, EndSub
use dc_types, only: STRING, STDOUT
use dcpam_error, only: StoreError, DC_NOERR, DCPAM_ENOTINIT
use dc_string, only: Printf, PutLine
implicit none
type(DYNMTX), intent(in):: dyn_mtx
integer, intent(in), optional:: unit
! 出力先の装置番号.
! デフォルトの出力先は標準出力.
!
! Unit number for output.
! Default value is standard output.
character(*), intent(in), optional:: indent
! 表示されるメッセージの字下げ.
!
! Indent of displayed messages.
logical, intent(out), optional:: err
! 例外処理用フラグ.
! デフォルトでは, この手続き内でエラーが
! 生じた場合, プログラムは強制終了します.
! 引数 *err* が与えられる場合,
! プログラムは強制終了せず, 代わりに
! *err* に .true. が代入されます.
!
! Exception handling flag.
! By default, when error occur in
! this procedure, the program aborts.
! If this *err* argument is given,
! .true. is substituted to *err* and
! the program does not abort.
integer:: stat
character(STRING):: cause_c
integer:: out_unit
integer:: indent_len
character(STRING):: indent_str
character(*), parameter:: subname = 'DynMatrixPutLine'
continue
call BeginSub(subname)
stat = DC_NOERR
cause_c = ''
!-----------------------------------------------------------------
! 初期設定のチェック
! Check initialization
!-----------------------------------------------------------------
if (present(unit)) then
out_unit = unit
else
out_unit = STDOUT
end if
indent_len = 0
indent_str = ''
if (present(indent)) then
if (len(indent) /= 0) then
indent_len = len(indent)
indent_str(1:indent_len) = indent
end if
end if
!-----------------------------------------------------------------
! "DYNMTX" の設定の印字
! Print the settings for "DYNMTX"
!-----------------------------------------------------------------
if (dyn_mtx % initialized) then
call Printf(out_unit, &
& indent_str(1:indent_len) // &
& '#', &
& l=(/dyn_mtx % initialized/))
else
call Printf(out_unit, &
& indent_str(1:indent_len) // &
& '#', &
& l=(/dyn_mtx % initialized/))
end if
!-----------------------------------------------------------------
! 終了処理, 例外処理
! Termination and Exception handling
!-----------------------------------------------------------------
999 continue
call StoreError(stat, subname, err, cause_c)
call EndSub(subname)
end subroutine DynMatrixPutLine
logical function DynMatrixInitialized( dyn_mtx ) result(result)
!
! *dyn_mtx* が初期設定されている場合には .true. が,
! 初期設定されていない場合には .false. が返ります.
!
! If *dyn_mtx* is initialized, .true. is returned.
! If *dyn_mtx* is not initialized, .false. is returned.
!
implicit none
type(DYNMTX), intent(in):: dyn_mtx
continue
result = dyn_mtx % initialized
end function DynMatrixInitialized
subroutine DynMatrixSolve( dyn_mtx, &
& wz_RSVector2Solution, &
& err )
!
! 右辺ベクトルとして受け取った *wz_RSVector2Solution* および
! Create の際に作成した LU 行列, ピボットから解の計算を行い,
! その解を *wz_RSVector2Solution* として返す.
!
! なお, 与えられた *dyn_mtx* が Create によって初期設定
! されていない場合, プログラムはエラーを発生させます.
!
! Calculate solution from given *wz_RSVector2Solution* as right hand
! vector and LU matrix and pivot that are created in "Create".
! The solution is returned to *wz_RSVector2Solution*.
!
! If *dyn_mtx* is not initialized by "Create" yet,
! error is occurred.
!
use dc_trace, only: BeginSub, EndSub
use dc_types, only: STRING, STDOUT, DP
use dc_string, only: PutLine
use dcpam_error, only: StoreError, DC_NOERR, DCPAM_ENOTINIT
use lumatrix, only: LUSolve
implicit none
type(DYNMTX), intent(inout):: dyn_mtx
real(DP), intent(inout):: wz_RSVector2Solution((dyn_mtx%nmax+1)**2, 0:dyn_mtx%kmax-1)
logical, intent(out), optional:: err
! 例外処理用フラグ.
! デフォルトでは, この手続き内でエラーが
! 生じた場合, プログラムは強制終了します.
! 引数 *err* が与えられる場合,
! プログラムは強制終了せず, 代わりに
! *err* に .true. が代入されます.
!
! Exception handling flag.
! By default, when error occur in
! this procedure, the program aborts.
! If this *err* argument is given,
! .true. is substituted to *err* and
! the program does not abort.
integer:: stat
character(STRING):: cause_c
character(*), parameter:: subname = 'DynMatrixSolve'
continue
call BeginSub(subname)
stat = DC_NOERR
cause_c = ''
!-----------------------------------------------------------------
! 初期設定のチェック
! Check initialization
!-----------------------------------------------------------------
if (.not. dyn_mtx % initialized) then
stat = DCPAM_ENOTINIT
cause_c = 'DYNMTX'
goto 999
end if
!-----------------------------------------------------------------
! 解の計算
! Caluculate solution
!-----------------------------------------------------------------
wz_RSVector2Solution = &
& LUSolve( dyn_mtx % wzz_siMtxLU, dyn_mtx % wz_siMtxPiv, &
& wz_RSVector2Solution )
!-----------------------------------------------------------------
! 終了処理, 例外処理
! Termination and Exception handling
!-----------------------------------------------------------------
999 continue
call StoreError(stat, subname, err, cause_c)
call EndSub(subname)
end subroutine DynMatrixSolve
subroutine DynMatrixNmlRead( nmlfile, &
!!$ & param_i, param_r, param_c_, &
& err )
!
! NAMELIST ファイル *nmlfile* から値を入力するための
! 内部サブルーチンです. Create 内で呼び出されることを
! 想定しています.
!
! 値が NAMELIST ファイル内で指定されていない場合には,
! 入力された値がそのまま返ります.
!
! なお, *nmlfile* に空文字が与えられた場合, または
! 与えられた *nmlfile* を読み込むことができない場合,
! プログラムはエラーを発生させます.
!
! This is an internal subroutine to input values from
! NAMELIST file *nmlfile*. This subroutine is expected to be
! called by "Create".
!
! A value not specified in NAMELIST file is returned
! without change.
!
! If *nmlfile* is empty, or *nmlfile* can not be read,
! error is occurred.
!
use dc_trace, only: BeginSub, EndSub
use dc_types, only: DP, STRING, TOKEN, STDOUT
use dc_string, only: PutLine
use dc_iounit, only: FileOpen
use dc_message, only: MessageNotify
use dc_present, only: present_and_true
use dc_error, only: StoreError, DC_NOERR, DC_ENOFILEREAD
implicit none
character(*), intent(in):: nmlfile
! NAMELIST ファイルの名称.
! NAMELIST file name
!!$ integer, intent(inout):: param_i
!!$ real(DP), intent(inout):: param_r
!!$ character(*), intent(inout):: param_c_
!!$ character(TOKEN):: param_c
logical, intent(out), optional:: err
! 例外処理用フラグ.
! デフォルトでは, この手続き内でエラーが
! 生じた場合, プログラムは強制終了します.
! 引数 *err* が与えられる場合,
! プログラムは強制終了せず, 代わりに
! *err* に .true. が代入されます.
!
! Exception handling flag.
! By default, when error occur in
! this procedure, the program aborts.
! If this *err* argument is given,
! .true. is substituted to *err* and
! the program does not abort.
!!$ namelist /dyn_matrix_nml/ &
!!$ & param_i, param_r, param_c
! dyn_matrix モジュール用
! NAMELIST 変数群名.
!
! dyn_matrix#Create を使用する際に,
! オプショナル引数 *nmlfile* へ NAMELIST
! ファイル名を指定することで, そのファイルから
! この NAMELIST 変数群を読み込みます.
!
! NAMELIST group name for
! "dyn_matrix" module.
!
! If a NAMELIST filename is specified to
! an optional argument *nmlfile*
! when "dyn_matrix#Create" is used,
! this NAMELIST group is loaded from
! the file.
!-----------------------------------
! 作業変数
! Work variables
integer:: stat
character(STRING):: cause_c
integer:: unit_nml ! NAMELIST ファイルオープン用装置番号.
! Unit number for NAMELIST file open
!!$ integer:: iostat_nml ! NAMELIST 読み込み時の IOSTAT.
!!$ ! IOSTAT of NAMELIST read
character(*), parameter:: subname = 'DynMatrixNmlRead'
continue
call BeginSub( subname )
stat = DC_NOERR
cause_c = ''
!-----------------------------------------------------------------
! 文字型引数を NAMELIST 変数群へ代入
! Substitute character arguments to NAMELIST group
!-----------------------------------------------------------------
!!$ param_c = param_c_
!----------------------------------------------------------------
! NAMELIST ファイルのオープン
! Open NAMELIST file
!----------------------------------------------------------------
call FileOpen( unit = unit_nml, & ! (out)
& file = nmlfile, mode = 'r', & ! (in)
& err = err ) ! (out)
if ( present_and_true(err) ) then
stat = DC_ENOFILEREAD
cause_c = nmlfile
goto 999
end if
!-----------------------------------------------------------------
! NAMELIST 変数群の取得
! Get NAMELIST group
!-----------------------------------------------------------------
!!$ read( unit = unit_nml, & ! (in)
!!$ & nml = dyn_matrix_nml, iostat = iostat_nml ) ! (out)
!!$ if ( iostat_nml == 0 ) then
!!$ call MessageNotify( 'M', subname, &
!!$ & 'NAMELIST group "%c" is loaded from "%c".', &
!!$ & c1='dyn_matrix_nml', c2=trim(nmlfile) )
!!$ write(STDOUT, nml = dyn_matrix_nml)
!!$ else
!!$ call MessageNotify( 'W', subname, &
!!$ & 'NAMELIST group "%c" is not found in "%c" (iostat=%d).', &
!!$ & c1='dyn_matrix_nml', c2=trim(nmlfile), &
!!$ & i=(/iostat_nml/) )
!!$ end if
close( unit_nml )
!-----------------------------------------------------------------
! NAMELIST 変数群を文字型引数へ代入
! Substitute NAMELIST group to character arguments
!-----------------------------------------------------------------
!!$ param_c_ = param_c
!-----------------------------------------------------------------
! 終了処理, 例外処理
! Termination and Exception handling
!-----------------------------------------------------------------
999 continue
call StoreError( stat, subname, err, cause_c )
call EndSub( subname )
end subroutine DynMatrixNmlRead
!!$ subroutine DynMatrixSample( dyn_mtx, err )
!!$ !--
!!$ ! DynMatrixSample の要約を記述してください.
!!$ !++
!!$ ! なお, 与えられた *dyn_mtx* が Create によって初期設定
!!$ ! されていない場合, プログラムはエラーを発生させます.
!!$ !--
!!$ ! Describe brief of DynMatrixSample
!!$ !++
!!$ ! If *dyn_mtx* is not initialized by "Create" yet,
!!$ ! error is occurred.
!!$ !
!!$ use dc_trace, only: BeginSub, EndSub
!!$ use dc_string, only: PutLine
!!$ use dc_types, only: STRING, STDOUT
!!$ use dcpam_error, only: StoreError, DC_NOERR, DCPAM_ENOTINIT
!!$ implicit none
!!$ type(DYNMTX), intent(inout):: dyn_mtx
!!$ logical, intent(out), optional:: err
!!$ ! 例外処理用フラグ.
!!$ ! デフォルトでは, この手続き内でエラーが
!!$ ! 生じた場合, プログラムは強制終了します.
!!$ ! 引数 *err* が与えられる場合,
!!$ ! プログラムは強制終了せず, 代わりに
!!$ ! *err* に .true. が代入されます.
!!$ !
!!$ ! Exception handling flag.
!!$ ! By default, when error occur in
!!$ ! this procedure, the program aborts.
!!$ ! If this *err* argument is given,
!!$ ! .true. is substituted to *err* and
!!$ ! the program does not abort.
!!$ integer:: stat
!!$ character(STRING):: cause_c
!!$ character(*), parameter:: subname = 'DynMatrixSample'
!!$ continue
!!$ call BeginSub(subname)
!!$ stat = DC_NOERR
!!$ cause_c = ''
!!$
!!$ !-----------------------------------------------------------------
!!$ ! 初期設定のチェック
!!$ ! Check initialization
!!$ !-----------------------------------------------------------------
!!$ if (.not. dyn_mtx % initialized) then
!!$ stat = DCPAM_ENOTINIT
!!$ cause_c = 'DYNMTX'
!!$ goto 999
!!$ end if
!!$
!!$
!!$
!!$ !-----------------------------------------------------------------
!!$ ! 終了処理, 例外処理
!!$ ! Termination and Exception handling
!!$ !-----------------------------------------------------------------
!!$999 continue
!!$ call StoreError(stat, subname, err, cause_c)
!!$ call EndSub(subname)
!!$ end subroutine DynMatrixSample
end module dyn_matrix