!= 時刻管理
!
!= Time control
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: gridset.f90,v 1.5 2007/06/09 13:12:30 sugiyama Exp $ 
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!

module timeset
  !
  ! 格子点の設定および保管を行う. 
  !
  ! Grid points are set and stored. 
  !

  ! モジュール引用 ; USE statements
  !

  ! 種別型パラメタ
  ! Kind type parameter
  !
  use dc_types, only: DP     ! 倍精度実数型. Double precision. 

  ! 宣言文 ; Declaration statements
  !
  implicit none
  private

  ! 公開手続き
  ! Public procedure
  !
  public:: TimesetInit

  ! 公開変数
  ! Public variables
  !
  logical, save, public:: initialized = .false.
                              ! 初期設定フラグ. 
                              ! Initialization flag
  integer, save, public:: Nstep = 0
                               ! ループ回数. Number of times of loops



  ! 非公開変数
  ! Private variables
  !

  namelist /timeset_nml/ Nstep

  character(*), parameter:: module_name = 'timeset'
                              ! モジュールの名称. 
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id:  $'
                              ! モジュールのバージョン
                              ! Module version

  ! INTERFACE 文 ; INTERFACE statements
  !
  interface TimesetInit
    module procedure TimesetInit
  end interface

contains

  subroutine TimesetInit

    ! NAMELIST ファイル入力に関するユーティリティ
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: namelist_filename, NmlutilMsg

    ! ファイル入出力補助
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! 種別型パラメタ
    ! Kind type parameter
    !
    use dc_types, only: STDOUT ! 標準出力の装置番号. Unit number of standard output

    ! メッセージ出力
    ! Message output
    !
    use dc_message, only: MessageNotify

    implicit none

    integer:: unit_nml        ! NAMELIST ファイルオープン用装置番号. 
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST 読み込み時の IOSTAT. 
                              ! IOSTAT of NAMELIST read

    character(*), parameter:: subname = 'TimesetInit'
  continue
    if ( initialized ) return
    call InitDepmod

    ! 時刻の設定
    ! Set time
    !
    call FileOpen( unit_nml, &          ! (out)
      & namelist_filename, mode = 'r' ) ! (in)

    rewind( unit_nml )
    read( unit_nml, &         ! (in)
      & nml = timeset_nml, &  ! (out)
      & iostat = iostat_nml ) ! (out)

    call NmlutilMsg( iostat_nml, module_name ) ! (in)

    ! 印字 ; Print
    !
    call MessageNotify( 'M', subname, 'Nstep = %d', i = (/ Nstep /) )

    initialized = .true.
  end subroutine TimesetInit

  subroutine InitDepmod
    !
    ! 依存モジュールの初期化
    !
    ! Initialize dependency modules

    ! NAMELIST ファイル入力に関するユーティリティ
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: NmlutilInit

  continue

    call NmlutilInit

  end subroutine InitDepmod

end module timeset
