!= å‡ºåŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã®åŸºæœ¬æƒ…å ±ç®¡ç†
!= Management basic information for output files
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: fileset.f90,v 1.3 2009/03/03 15:57:35 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module fileset
  !
  != å‡ºåŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã®åŸºæœ¬æƒ…å ±ç®¡ç†
  !
  != Management basic information for output files
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  !== Variables List
  !
  ! FileTitle        :: å‡ºåŠ›ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã®è¡¨é¡Œ
  ! FileSource       :: ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ä½œæˆã®æ‰‹æ®µ
  ! FileInstitution  :: ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã‚’æœ€çµ‚çš„ã«å¤‰æ›´ã—ãŸçµ„ç¹”/å€‹äºº
  ! ------------     :: ------------
  ! FileTitle        :: Title of output data files
  ! FileSource       :: Source of data file
  ! FileInstitution  :: Institution or person that changes data files for the last time
  !
  !
  !== Procedures List
  !
  ! FilesetInit   :: fileset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–
  ! ------------  :: ------------
  ! FilesetInit   :: Initialize "fileset" module
  !
  !
  !== NAMELIST
  !
  ! NAMELIST#fileset_nml
  !

  ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; USE statements
  !

  ! ç¨®åˆ¥åž‹ãƒ‘ãƒ©ãƒ¡ã‚¿
  ! Kind type parameter
  !
  use dc_types, only: STRING ! æ–‡å—åˆ—.       Strings.

  ! å®£è¨€æ–‡ ; Declaration statements
  !
  implicit none
  private

  ! å…¬é–‹æ‰‹ç¶šã
  ! Public procedure
  !
  public:: FilesetInit

  ! å…¬é–‹å¤‰æ•°
  ! Public variables
  !
  logical, save, public:: fileset_inited = .false.
                              ! åˆæœŸè¨å®šãƒ•ãƒ©ã‚°.
                              ! Initialization flag

  character(STRING), save, public:: FileTitle
                              ! å‡ºåŠ›ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã®è¡¨é¡Œ.
                              ! Title of output data files
  character(STRING), save, public:: FileSource
                              ! ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ä½œæˆã®æ‰‹æ®µ.
                              ! Source of data file
  character(STRING), save, public:: FileInstitution
                              ! ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã‚’æœ€çµ‚çš„ã«å¤‰æ›´ã—ãŸçµ„ç¹”/å€‹äºº.
                              ! Institution or person that changes data files for the last time

  ! éžå…¬é–‹å¤‰æ•°
  ! Private variables
  !

  character(*), parameter:: module_name = 'fileset'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: fileset.f90,v 1.3 2009/03/03 15:57:35 morikawa Exp $'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³
                              ! Module version

  ! INTERFACE æ–‡ ; INTERFACE statements
  !
  interface FilesetInit
    module procedure FilesetInit
  end interface

contains

  subroutine FilesetInit
    !
    ! fileset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–ã‚’è¡Œã„ã¾ã™.
    ! NAMELIST#fileset_nml ã®èªã¿è¾¼ã¿ã¯ã“ã®æ‰‹ç¶šãã§è¡Œã‚ã‚Œã¾ã™.
    !
    ! "fileset" module is initialized.
    ! NAMELIST#fileset_nml is loaded in this procedure.
    !

    ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; USE statements
    !

    ! 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

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    integer:: unit_nml        ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«ã‚ªãƒ¼ãƒ—ãƒ³ç”¨è£…ç½®ç•ªå·.
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST èªã¿è¾¼ã¿æ™‚ã® IOSTAT.
                              ! IOSTAT of NAMELIST read

    ! NAMELIST å¤‰æ•°ç¾¤
    ! NAMELIST group name
    !
    namelist /fileset_nml/ &
      & FileTitle, FileSource, FileInstitution
          !
          ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã«ã¤ã„ã¦ã¯åˆæœŸåŒ–æ‰‹ç¶š "fileset#FilesetInit"
          ! ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã®ã“ã¨.
          !
          ! Refer to source codes in the initialization procedure
          ! "fileset#FilesetInit" for the default values.
          !

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !

    if ( fileset_inited ) return
    call InitCheck

    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã®è¨å®š
    ! Default values settings
    !
    FileTitle  = 'dcpam5 test run'
    FileSource = 'dcpam5 $Name:  $ (http://www.gfd-dennou.org/library/dcpam)'
    FileInstitution = 'GFD Dennou Club (http://www.gfd-dennou.org)'

    ! NAMELIST ã®èªã¿è¾¼ã¿
    ! NAMELIST is input
    !
    if ( trim(namelist_filename) /= '' ) then
      call FileOpen( unit_nml, &          ! (out)
        & namelist_filename, mode = 'r' ) ! (in)

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

      call NmlutilMsg( iostat_nml, module_name ) ! (in)
      if ( iostat_nml == 0 ) write( STDOUT, nml = fileset_nml )
    end if

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, '  FileTitle       = %c', c1 = trim(FileTitle) )
    call MessageNotify( 'M', module_name, '  FileSource      = %c', c1 = trim(FileSource) )
    call MessageNotify( 'M', module_name, '  FileInstitution = %c', c1 = trim(FileInstitution) )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    fileset_inited = .true.
  end subroutine FilesetInit

  subroutine InitCheck
    !
    ! ä¾å˜ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–ãƒã‚§ãƒƒã‚¯
    !
    ! Check initialization of dependency modules

    ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; USE statements
    !

    ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«å…¥åŠ›ã«é–¢ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: namelist_util_inited

    ! ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸å‡ºåŠ›
    ! Message output
    !
    use dc_message, only: MessageNotify

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !

    if ( .not. namelist_util_inited ) &
      & call MessageNotify( 'E', module_name, '"namelist_util" module is not initialized.' )

  end subroutine InitCheck

end module fileset