!= Module FileSet
!
! Authors::   SUGIYAMA Ko-ichiro
! Version::   $Id: fileset.f90,v 1.8 2011-06-21 06:14:52 sugiyama Exp $ 
! Tag Name::  $Name: arare5-20111010 $
! Copyright:: Copyright (C) GFD Dennou Club, 2006. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!
!== Overview 
!
!引数に与えられた NAMELIST ファイルから, 実験名等の情報を取得し
!保管するための変数参照型モジュール
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!

module fileset
  !
  !引数に与えられた NAMELIST ファイルから, I/O ファイル名を取得し, 
  !保管するための変数参照型モジュール
  !

  !モジュール読み込み
  use dc_types,    only : STRING        
  use dc_iounit,   only : FileOpen      
  use dc_message,  only : MessageNotify 
  use mpi_wrapper, only: myrank         
  use namelist_util, only: namelist_filename

  !暗黙の型宣言禁止
  implicit none

  private

  !公開変数
  character(STRING), save, public :: FileTitle = 'cloud moist convection experiment'
                              ! 実験名.
                              ! Title of experiment
!!$  character(STRING), save, public :: FileSource = 'deepconv/arare5 $Name: arare5-20111010 $ (http://www.gfd-dennou.org/library/deepconv)'
  character(STRING), save, public :: FileSource = 'deepconv/arare5 $Name: arare5-20111010 $'
                              ! データファイル作成プログラム名. 
                              ! Source of data file
  character(STRING), save, public :: FileInstitution = 'GFD Dennou Club (http://www.gfd-dennou.org)'
                              ! データファイル作成者/グループ.
                              ! Institution or person that changes data files for the last time

  public fileset_init

contains

  subroutine fileset_init
    !
    !設定ファイルから出力ファイルに記載する情報を読み込む
    !
    
    !暗黙の型宣言禁止
    implicit none
    
    !内部変数
    integer                       :: unit     !設定ファイル用装置番号
  
    
    !設定ファイルから読み込む出力ファイル情報
    NAMELIST /fileset_nml/ FileTitle, FileSource, FileInstitution
    
    !設定ファイルから出力ファイルに記載する情報を読み込む
    call FileOpen(unit, file=namelist_filename, mode='r')
    read(unit, NML=fileset_nml)
    close(unit)
    
    !"myrank == 0" に該当する計算ノードが, 読み込んだ情報を出力
    if (myrank == 0) then 
      call MessageNotify( "M", &
        & "fileset_init", "FileTitle = %c",    c1=trim(FileTitle) )
      call MessageNotify( "M", &
        & "fileset_init", "FileSource = %c",   c1=trim(FileSource) )
      call MessageNotify( "M", &
        & "fileset_init", "FileInstitution = %c", c1=trim(FileInstitution) )
    end if

  end subroutine fileset_init

end module fileset
