!= ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿, åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿å…¥å‡ºåŠ›
!
!= Restart data, initial data input/output
!
! Authors::   Yasuhiro Morikawa, Yoshiyuki O. Takahashi
! Version::   $Id: restart_file_io.f90,v 1.26 2013/09/30 03:03:42 yot Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2010. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module restart_file_io
  !
  != ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿, åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿å…¥å‡ºåŠ›
  !
  != Restart data, initial data input/output
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã‚‚ã—ãã¯åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã®å…¥å‡ºåŠ›ã‚’è¡Œã„ã¾ã™.
  ! å…¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«, å‡ºåŠ›ãƒ•ã‚¡ã‚¤ãƒ«, ãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›ã®é–“éš”ã¯
  ! NAMELIST#restart_file_io_nml ã§è¨å®šã—ã¾ã™.
  !
  ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®å…¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«ãŒæŒ‡å®šã•ã‚Œãªã„å ´åˆ,
  ! initial_data ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§ç”Ÿæˆã•ã‚ŒãŸåˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‚’å–å¾—ã—ã¾ã™.
  !
  ! Restart data or initial data is input/output.
  ! Settings of input file, output file, and interval of data output
  ! is configured by "NAMELIST#restart_file_io_nml".
  !
  ! If input file of restart data is not set,
  ! initial data is generated in "initial_data" module, and
  ! obtained data from the module.
  !
  !== Procedures List
  !
  ! RestartFileOpen   :: ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚ªãƒ¼ãƒ—ãƒ³
  ! RestartFileOutput :: ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ•ã‚¡ã‚¤ãƒ«ã¸ã®ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
  ! InitialFileOutput :: åˆæœŸå€¤ãƒ•ã‚¡ã‚¤ãƒ«ã¸ã®ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
  ! RestartFileClose  :: ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚¯ãƒãƒ¼ã‚º
  ! RestartFileGet    :: ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ•ã‚¡ã‚¤ãƒ«ã®å…¥åŠ›
  ! ------------      :: ------------
  ! RestartFileOpen   :: Open restart/initial file
  ! RestartFileOutput :: Data output to restart/initial file
  ! InitialFileOutput :: Data output to initial file
  ! RestartFileClose  :: Close restart/initial file
  ! RestartFileGet    :: Input restart/initial file
  !
  !== NAMELIST
  !
  ! NAMELIST#restart_file_io_nml
  !

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

  ! æ ¼åç‚¹è¨å®š
  ! Grid points settings
  !
  use gridset, only: imax, & ! çµŒåº¦æ ¼åç‚¹æ•°.
                             ! Number of grid points in longitude
    &                jmax, & ! ç·¯åº¦æ ¼åç‚¹æ•°.
                             ! Number of grid points in latitude
    &                kmax    ! é‰›ç›´å±¤æ•°.
                             ! Number of vertical level

  ! çµ„æˆã«é–¢ã‚ã‚‹é…åˆ—ã®è¨å®š
  ! Settings of array for atmospheric composition
  !
  use composition, only: &
    &                    ncmax, &
                              ! æˆåˆ†ã®æ•°
                              ! Number of composition
    &                    a_QMixName, &
                              ! æˆåˆ†ã®å¤‰æ•°å
                              ! Name of variables for composition
    &                    a_QMixLongName, &
                              ! æˆåˆ†ã®é•·ã„å¤‰æ•°å
                              ! Long name of variables for composition
    &                    IndexH2OVap
                              ! æ°´è’¸æ°—ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹
                              ! Index for water vapor

  ! ç¨®åˆ¥åž‹ãƒ‘ãƒ©ãƒ¡ã‚¿
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! å€ç²¾åº¦å®Ÿæ•°åž‹. Double precision.
    &                 STRING, &  ! æ–‡å—åˆ—.       Strings.
    &                 TOKEN      ! ã‚ãƒ¼ãƒ¯ãƒ¼ãƒ‰.   Keywords.

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

  ! gtool4 ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
  ! Gtool4 data output
  !
  use gtool_history, only: GT_HISTORY

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

  ! å…¬é–‹æ‰‹ç¶šã
  ! Public procedure
  !
  public :: RestartFileInit
  public :: RestartFileOpen, RestartFileClose, RestartFileOutPut, InitialFileOutput
  public :: RestartFileGet

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

  logical, save, public:: restart_file_opened = .false.
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚ªãƒ¼ãƒ—ãƒ³ã«é–¢ã™ã‚‹ãƒ•ãƒ©ã‚°.
                              ! Flag of restart file open

  character(STRING), save, public:: InputFile
                              ! å…¥åŠ›ã™ã‚‹ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®ãƒ•ã‚¡ã‚¤ãƒ«å
                              ! Filename of input restart data

  character(STRING), save, public:: OutputFile
                              ! å‡ºåŠ›ã™ã‚‹ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®ãƒ•ã‚¡ã‚¤ãƒ«å
                              ! Filename of output restart data
  real(DP), save, public:: IntValue
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›é–“éš” (æ•°å€¤).
                              ! Interval of restart data output (numerical value)
  character(TOKEN), save, public:: IntUnit
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›é–“éš” (å˜ä½).
                              ! Interval of restart data output (unit)
  real(DP), save, public:: IntTime
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›é–“éš” [ç§’].
                              ! Interval of restart data output [sec]

  ! éžå…¬é–‹å¤‰æ•°
  ! Private variables
  !
  logical, save:: flag_init_data_save
                              ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‚’ä½œæˆã™ã‚‹å ´åˆã¯,
                              ! ã“ã®å¼•æ•°ã« .true. ã‚’ä¸Žãˆã¾ã™.
                              !
                              ! If initial data is created,
                              ! give ".true." to this argument.

  type(GT_HISTORY), save:: gthst_rst
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ç”¨ gtool_history#GT_HISTORY å¤‰æ•°
                              ! "gtool_history#GT_HISTORY" variable for restart data

  real(DP), save:: PrevOutputTime
                              ! å‰å›žã®å‡ºåŠ›æ™‚é–“.
                              ! Previous output time
  logical, save:: flag_output_end
                              ! è¨ˆç®—æœ€çµ‚æ™‚åˆ»ã®å‡ºåŠ›å®Œäº†ã®ãƒ•ãƒ©ã‚°.
                              ! Flag for completion of output at the end time of calculation

  character(*), parameter:: module_name = 'restart_file_io'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: restart_file_io.f90,v 1.26 2013/09/30 03:03:42 yot Exp $'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³
                              ! Module version

contains

  !--------------------------------------------------------------------------------------

  subroutine RestartFileOpen( flag_init_data )
    !
    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ã‚ªãƒ¼ãƒ—ãƒ³ã—ã¾ã™.
    !
    ! A restart/initial data file is opened.
    !

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

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

    ! ç‰©ç†ãƒ»æ•°å¦å®šæ•°è¨å®š
    ! Physical and mathematical constants settings
    !
    use constants0, only: &
      & PI                    ! $ \pi $.
                              ! å††å‘¨çŽ‡. Circular constant

    ! åº§æ¨™ãƒ‡ãƒ¼ã‚¿è¨å®š
    ! Axes data settings
    !
    use axesset, only: &
      & x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & y_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & y_Lat_Weight, &
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
      & z_Sigma, &
                              ! $ \sigma $ ãƒ¬ãƒ™ãƒ« (æ•´æ•°).
                              ! Full $ \sigma $ level
      & r_Sigma, &
                              ! $ \sigma $ ãƒ¬ãƒ™ãƒ« (åŠæ•´æ•°).
                              ! Half $ \sigma $ level
      & z_DelSigma
                              ! $ \Delta \sigma $ (æ•´æ•°).
                              ! $ \Delta \sigma $ (Full)

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & DelTime, &            ! $ \Delta t $ [s]
      & RestartTime, &        ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ».
                              ! Restart time of calculation
      & InitialDate           ! è¨ˆç®—é–‹å§‹æ—¥æ™‚.
                              ! Start date of calculation

    ! gtool4 ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! Gtool4 data output
    !
    use gtool_history, only: HistoryCreate, HistoryAddVariable, &
      & HistoryPut, HistoryAddAttr

    ! æš¦ã¨æ—¥æ™‚ã®å–ã‚Šæ‰±ã„
    ! Calendar and Date handler
    !
    use dc_calendar, only: DCCalInquire, DCCalDateInquire

    ! æ–‡å—åˆ—æ“ä½œ
    ! Character handling
    !
    use dc_string, only: CPrintf, LChar

    ! çµ„ã¿è¾¼ã¿é–¢æ•° PRESENT ã®æ‹¡å¼µç‰ˆé–¢æ•°
    ! Extended functions of intrinsic function "PRESENT"
    !
    use dc_present, only: present_and_true

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    logical, intent(in), optional:: flag_init_data
                              ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‚’ä½œæˆã™ã‚‹å ´åˆã¯,
                              ! ã“ã®å¼•æ•°ã« .true. ã‚’ä¸Žãˆã¾ã™.
                              !
                              ! If initial data is created,
                              ! give ".true." to this argument.

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    character(STRING):: title_msg
                              ! è¡¨é¡Œã«ä»˜åŠ ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸.
                              ! Message added to title
    real(DP):: origin_time
                              ! è¨ˆç®—é–‹å§‹æ™‚åˆ».
                              ! Start time of calculation

    integer:: InitialYear, InitialMonth, InitialDay, InitialHour, InitialMin
                              ! è¨ˆç®—é–‹å§‹ã®å¹´æœˆæ—¥æ™‚åˆ†.
    real(DP):: InitialSec
                              ! è¨ˆç®—é–‹å§‹ã®ç§’.

    character(TOKEN):: cal_type
                              ! æš¦ã®ã‚¿ã‚¤ãƒ—.
    integer:: month_in_year, hour_in_day, min_in_hour
    integer, pointer:: day_in_month_ptr(:) => null()
    real(DP):: sec_in_min
                              ! æš¦ã®è©³ç´°æƒ…å ±

    logical:: flag_mpi_init

    integer :: n

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

    ! åˆæœŸåŒ–
    ! Initialization
    !
    flag_init_data_save = present_and_true( flag_init_data )

    if ( .not. restart_file_io_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    if ( restart_file_opened ) return

    ! è¡¨é¡Œã«ä»˜åŠ ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã®è¨å®š
    ! Configure message added to title
    !
    if ( .not. flag_init_data_save ) then
      title_msg = ' restart data'
    else
      title_msg = ' initial data'
    end if

    ! æ™‚åˆ»æƒ…å ±ã®å–å¾—
    ! Get time information
    !
    if ( .not. flag_init_data_save ) then
      origin_time = RestartTime + IntTime
    else
      origin_time = RestartTime
    end if

    flag_mpi_init = .false.

    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚ªãƒ¼ãƒ—ãƒ³
    ! Open a restart file
    !
    call HistoryCreate( &
      &      file = OutputFile, &                                   ! (in)
      &     title = trim(FileTitle) // trim(title_msg), &           ! (in)
      &    source = FileSource, institution = FileInstitution, &    ! (in)
      &      dims = (/ 'lon    ', 'lat    ', 'sig    ', 'sigm   ', &
      &                'timestr', 'time   ' /), &                   ! (in)
      &  dimsizes = (/ imax, jmax, kmax, kmax + 1, TOKEN, 0 /), &   ! (in)
      & longnames = (/ 'longitude                             ', &
      &                'latitude                              ', &
      &                'sigma at layer midpoints              ', &
      &                'sigma at layer end-points (half level)', &
      &                'number of characters for datetime     ', &    ! (in)
      &                'time                                  ' /), & ! (in)
      &     units = (/ 'degree_east ', 'degree_north', &
      &                '1           ', '1           ', &
      &                '1           ',                 &
      &                'sec         ' /), &                           ! (in)
      & xtypes = (/'double', 'double', 'double', &
      &            'double', 'int   ', 'double'/), &                  ! (in)
      &        origind = origin_time, &       ! (in) optional
      &      intervald = IntTime, &           ! (in) optional
!!$      & flag_mpi_split = flag_mpi_init, &     ! (in) optional
      & flag_mpi_split = .true., &            ! (in) optional
      &        history = gthst_rst )          ! (out) optional

    ! â€» å…ƒã€…å†è¨ˆç®—ãƒ‡ãƒ¼ã‚¿ã‹ã©ã†ã‹ã®ãƒã‚§ãƒƒã‚¯ã®ãŸã‚ã®ãƒ•ãƒ©ã‚°ã¨ã—ã¦
    !    ä½œæˆã—ãŸã‚‚ã®ã§ã‚ã‚‹ãŸã‚ã€ä¸‹è¨˜ flag_rst è¨å®šå®Œäº†å¾Œ
    !    å‰Šé™¤äºˆå®š (morikawa  2010/06/13)
    !
    ! $ \Delta t $ ã«é–¢ã™ã‚‹æƒ…å ±ã‚’è¿½åŠ .
    ! Add information about $ \Delta t $.
    !
!!$    if ( .not. flag_init_data_save ) then
!!$      call HistoryAddVariable( &
!!$        & varname = 'deltime', &             ! (in)
!!$        & dims = (/''/), &                   ! (in)
!!$        & longname = 'delta time', &         ! (in)
!!$        & units = 'sec', xtype = 'double', & ! (in)
!!$        & history = gthst_rst )              ! (inout)
!!$      call HistoryPut( &
!!$        & varname = 'deltime', &            ! (in)
!!$        & array = (/ DelTime /), &          ! (in)
!!$        & history = gthst_rst )             ! (inout)
!!$    end if

    ! é–‹å§‹æ—¥æ™‚æƒ…å ±ã‚’ "time" ã®å±žæ€§ã¨ã—ã¦è¨å®š
    ! Set start date information as attributes of "time"
    !
    call DCCalDateInquire( &
      & InitialYear, InitialMonth, InitialDay, & ! (out)
      & InitialHour, InitialMin,   InitialSec, & ! (out)
      & date = InitialDate )               ! (in)

    call HistoryAddAttr( &
      & 'time', attrname = 'origin', &     ! (in)
      & value = 'origin_year origin_month origin_day origin_hour origin_min origin_sec', &
                                           ! (in)
      & history = gthst_rst )              ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'origin_year', & ! (in)
      & value = InitialYear, &                ! (in)
      & history = gthst_rst )               ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'origin_month', & ! (in)
      & value = InitialMonth, &                ! (in)
      & history = gthst_rst )                ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'origin_day', &  ! (in)
      & value = InitialDay, &                 ! (in)
      & history = gthst_rst )               ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'origin_hour', &  ! (in)
      & value = InitialHour, &                 ! (in)
      & history = gthst_rst )                ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'origin_min', &  ! (in)
      & value = InitialMin, &                 ! (in)
      & history = gthst_rst )               ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'origin_sec', &  ! (in)
      & value = InitialSec, &                 ! (in)
      & history = gthst_rst )               ! (inout)

    ! æš¦æƒ…å ±ã‚’ "time" ã®å±žæ€§ã¨ã—ã¦è¨å®š
    ! Set calendar information as attributes of "time"
    !
    call DCCalInquire( &
      & cal_type         = cal_type, &          ! (out)
      & month_in_year    = month_in_year, &     ! (out)
      & day_in_month_ptr = day_in_month_ptr , & ! (out)
      & hour_in_day      = hour_in_day  , &     ! (out)
      & min_in_hour      = min_in_hour  , &     ! (out)
      & sec_in_min       = sec_in_min )         ! (out)

    call HistoryAddAttr( &
      & 'time', attrname = 'calendar', & ! (in)
      & value = cal_type, &              ! (in)
      & history = gthst_rst )            ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'month_in_year', & ! (in)
      & value = month_in_year, &              ! (in)
      & history = gthst_rst )                 ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'day_in_month', & ! (in)
      & value = day_in_month_ptr, &          ! (in)
      & history = gthst_rst )                ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'hour_in_day', & ! (in)
      & value = hour_in_day, &              ! (in)
      & history = gthst_rst )               ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'min_in_hour', & ! (in)
      & value = min_in_hour, &              ! (in)
      & history = gthst_rst )               ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'sec_in_min', & ! (in)
      & value = sec_in_min, &              ! (in)
      & history = gthst_rst )              ! (inout)

    deallocate( day_in_month_ptr )

    ! å†è¨ˆç®—ãƒ‡ãƒ¼ã‚¿ç”¨ã®ãƒ•ãƒ©ã‚°è¨å®š
    ! Set flag for a restart data file.
    !
    call HistoryAddVariable( &
      & varname = 'flag_rst', &               ! (in)
      & dims = (/''/), &                      ! (in)
      & longname = 'flag for restart data', & ! (in)
      & units = '1', xtype = 'int', &         ! (in)
      & history = gthst_rst )                 ! (inout)
    call HistoryAddAttr( &
      & varname = 'flag_rst', &               ! (in)
      & attrname = 'comment', &               ! (in)
      & value = 'If this value is nonzero, this file provides restart data', &
                                                ! (in)
      & history = gthst_rst )                 ! (inout)

    if ( flag_init_data_save ) then
      call HistoryPut( &
        & varname = 'flag_rst', &               ! (in)
        & array = (/ 0 /), &                    ! (in)
        & history = gthst_rst )                 ! (inout)
    else
      call HistoryPut( &
        & varname = 'flag_rst', &               ! (in)
        & array = (/ 1 /), &                    ! (in)
        & history = gthst_rst )                 ! (inout)
    end if

    ! å¹´æœˆæ—¥æ™‚åˆ†ç§’å½¢å¼ã®æ—¥æ™‚æƒ…å ±å¤‰æ•°ã®è¨å®š
    ! Set a date information variable with year-month-day hour:minute:second format
    !
    call HistoryAddVariable( &
      & varname = 'datetime', &                     ! (in)
      & dims =  (/'timestr', 'time   ' /), &        ! (in)
      & longname = 'time represented as strings', & ! (in)
      & units = '1', xtype = 'char', &              ! (in)
      & history = gthst_rst )                       ! (inout) optional

    ! åº§æ¨™ãƒ‡ãƒ¼ã‚¿ã®è¨å®š
    ! Axes data settings
    !
    call HistoryAddAttr( &
      & 'lon', attrname = 'standard_name', &     ! (in)
      & value = 'longitude', &                   ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'lat', attrname = 'standard_name', &     ! (in)
      & value = 'latitude', &                    ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sig', attrname = 'standard_name', &     ! (in)
      & value = 'atmosphere_sigma_coordinate', & ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sigm', attrname = 'standard_name', &    ! (in)
      & value = 'atmosphere_sigma_coordinate', & ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'standard_name', &    ! (in)
      & value = 'time', &                        ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sig', attrname = 'positive', &          ! (in)
      & value = 'down', &                        ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sigm', attrname = 'positive', &         ! (in)
      & value = 'down', &                        ! (in)
      & history = gthst_rst )                    ! (inout)

    call HistoryPut( &
      & 'lon', x_Lon / PI * 180.0_DP, & ! (in)
      & history = gthst_rst )           ! (inout)
    call HistoryPut( &
      & 'lat', y_Lat / PI * 180.0_DP, & ! (in)
      & history = gthst_rst )           ! (inout)
    call HistoryPut( &
      & 'sig', z_Sigma, &               ! (in)
      & history = gthst_rst )           ! (inout)
    call HistoryPut( &
      & 'sigm', r_Sigma, &              ! (in)
      & history = gthst_rst )           ! (inout)

    ! åº§æ¨™é‡ã¿ã®è¨å®š
    ! Axes weights settings
    !
    call HistoryAddVariable( 'lon_weight', &               ! (in)
      & (/'lon'/), &                                       ! (in)
      & 'weight for integration in longitude', 'radian', & ! (in)
      & xtype = 'double', &                                ! (in)
      & history = gthst_rst )                              ! (inout)
    call HistoryAddAttr( &
      & 'lon', attrname = 'gt_calc_weight', &     ! (in)
      & value = 'lon_weight', &                   ! (in)
      & history = gthst_rst )                     ! (inout)
    call HistoryPut( &
      & 'lon_weight', x_Lon_Weight, &             ! (in)
      & history = gthst_rst )                     ! (inout)

    call HistoryAddVariable( 'lat_weight', &                      ! (in)
      & (/'lat'/), &                                              ! (in)
      & 'weight for integration in latitude', units = 'radian', & ! (in)
      & xtype = 'double', &                                       ! (in)
      & history = gthst_rst )                                     ! (inout)
    call HistoryAddAttr( &
      & 'lat', attrname = 'gt_calc_weight', &     ! (in)
      & value = 'lat_weight', &                   ! (in)
      & history = gthst_rst )                     ! (inout)
    call HistoryPut( &
      & 'lat_weight', y_Lat_Weight, &             ! (in)
      & history = gthst_rst )                     ! (inout)

    call HistoryAddVariable( 'sig_weight', &      ! (in)
      & (/'sig'/), &                              ! (in)
      & 'weight for integration in sigma', '1', & ! (in)
      & xtype = 'double', &                       ! (in)
      & history = gthst_rst )                     ! (inout)
    call HistoryAddAttr( &
      & 'sig', attrname = 'gt_calc_weight', &     ! (in)
      & value = 'sig_weight', &                   ! (in)
      & history = gthst_rst )                     ! (inout)
    call HistoryPut( &
      & 'sig_weight', z_DelSigma, &               ! (in)
      & history = gthst_rst )                     ! (inout)

    ! äºˆå ±å¤‰æ•°ã®è¨å®š
    ! Predictional variables settings
    !
    if ( flag_init_data_save ) then

      ! åˆæœŸãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ç”¨
      ! For initial data file
      !
      call HistoryAddVariable( 'U', &                         ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'eastward wind', 'm s-1', &                         ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      call HistoryAddVariable( 'V', &                         ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'northward wind', 'm s-1', &                        ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      call HistoryAddVariable( 'Temp', &                      ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'temperature', 'K', &                               ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      do n = 1, ncmax
        call HistoryAddVariable( a_QMixName(n),                & ! (in)
          & (/ 'lon ', 'lat ', 'sig ', 'time' /),              & ! (in)
          & a_QMixLongName(n), 'kg kg-1',                      & ! (in)
          & xtype = 'double',                                  & ! (in)
          & history = gthst_rst                                & ! (inout)
          & )
      end do
      call HistoryAddVariable( 'Ps', &                        ! (in)
        & (/ 'lon ', 'lat ', 'time' /), &                     ! (in)
        & 'surface pressure', 'Pa', &                         ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)

    else

      ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ç”¨
      ! For restart data file
      !
      call HistoryAddVariable( 'UB', &                        ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'eastward wind (at t-\Delta t)', 'm s-1', &         ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      call HistoryAddVariable( 'VB', &                        ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'northward wind (at t-\Delta t)', 'm s-1', &        ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      call HistoryAddVariable( 'TempB', &                     ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'temperature (at t-\Delta t)', 'K', &               ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      do n = 1, ncmax
        call HistoryAddVariable( trim(a_QMixName(n))//'B',    & ! (in)
          & (/ 'lon ', 'lat ', 'sig ', 'time' /),             & ! (in)
          & a_QMixLongName(n), 'kg kg-1',                     & ! (in)
          & xtype = 'double',                                 & ! (in)
          & history = gthst_rst                               & ! (inout)
          & )
      end do
      call HistoryAddVariable( 'PsB', &                       ! (in)
        & (/ 'lon ', 'lat ', 'time' /), &                     ! (in)
        & 'surface pressure (at t-\Delta t)', 'Pa', &         ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)

      call HistoryAddVariable( 'UN', &                        ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'eastward wind (at t)', 'm s-1', &                  ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      call HistoryAddVariable( 'VN', &                        ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'northward wind (at t)', 'm s-1', &                 ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      call HistoryAddVariable( 'TempN', &                     ! (in)
        & (/ 'lon ', 'lat ', 'sig ', 'time' /), &             ! (in)
        & 'temperature (at t)', 'K', &                        ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
      do n = 1, ncmax
        call HistoryAddVariable( trim(a_QMixName(n))//'N',    & ! (in)
          & (/ 'lon ', 'lat ', 'sig ', 'time' /),             & ! (in)
          & a_QMixLongName(n), 'kg kg-1',                     & ! (in)
          & xtype = 'double',                                 & ! (in)
          & history = gthst_rst                               & ! (inout)
          & )
      end do
      call HistoryAddVariable( 'PsN', &                       ! (in)
        & (/ 'lon ', 'lat ', 'time' /), &                     ! (in)
        & 'surface pressure (at t)', 'Pa', &                  ! (in)
        & xtype = 'double', &                                 ! (in)
        & history = gthst_rst )                               ! (inout)
    end if

    restart_file_opened = .true.
  end subroutine RestartFileOpen

  !--------------------------------------------------------------------------------------

  subroutine RestartFileOutput(                      &
    & xyz_UB, xyz_VB, xyz_TempB, xyzf_QMixB, xy_PsB, &   ! (in)
    & xyz_UN, xyz_VN, xyz_TempN, xyzf_QMixN, xy_PsN  &   ! (in)
    & )
    !
    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›ã‚’è¡Œã„ã¾ã™.
    !
    ! Output restart data

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & TimeN, &              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ».
                              ! Time of step $ t $.
      & EndTime, &            ! è¨ˆç®—çµ‚äº†æ™‚åˆ».
                              ! End time of calculation
      & InitialDate           ! è¨ˆç®—é–‹å§‹æ—¥æ™‚.
                              ! Start date of calculation

    ! gtool4 ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! Gtool4 data output
    !
    use gtool_history, only: HistoryPut, HistorySetTime

    ! æš¦ã¨æ—¥æ™‚ã®å–ã‚Šæ‰±ã„
    ! Calendar and Date handler
    !
    use dc_calendar, only: DCCalDateInquire

    ! çµ„ã¿è¾¼ã¿é–¢æ•° PRESENT ã®æ‹¡å¼µç‰ˆé–¢æ•°
    ! Extended functions of intrinsic function "PRESENT"
    !
    use dc_present, only: present_and_true

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xyz_UB     (0:imax-1, 1:jmax, 1:kmax)
                              ! $ u (t-\Delta t) $ .   æ±è¥¿é¢¨é€Ÿ. Eastward wind
    real(DP), intent(in):: xyz_VB     (0:imax-1, 1:jmax, 1:kmax)
                              ! $ v (t-\Delta t) $ .   å—åŒ—é¢¨é€Ÿ. Northward wind
    real(DP), intent(in):: xyz_TempB  (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T (t-\Delta t) $ .   æ¸©åº¦. Temperature
    real(DP), intent(in):: xyzf_QMixB (0:imax-1, 1:jmax, 1:kmax, 1:ncmax)
                              ! $ q (t-\Delta t) $ .   æ¯”æ¹¿. Specific humidity
    real(DP), intent(in):: xy_PsB     (0:imax-1, 1:jmax)
                              ! $ p_s (t-\Delta t) $ . åœ°è¡¨é¢æ°—åœ§. Surface pressure
    real(DP), intent(in):: xyz_UN     (0:imax-1, 1:jmax, 1:kmax)
                              ! $ u (t) $ .     æ±è¥¿é¢¨é€Ÿ. Eastward wind
    real(DP), intent(in):: xyz_VN     (0:imax-1, 1:jmax, 1:kmax)
                              ! $ v (t) $ .     å—åŒ—é¢¨é€Ÿ. Northward wind
    real(DP), intent(in):: xyz_TempN  (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T (t) $ .     æ¸©åº¦. Temperature
    real(DP), intent(in):: xyzf_QMixN (0:imax-1, 1:jmax, 1:kmax, 1:ncmax)
                              ! $ q (t) $ .     æ¯”æ¹¿. Specific humidity
    real(DP), intent(in):: xy_PsN     (0:imax-1, 1:jmax)
                              ! $ p_s (t) $ .   åœ°è¡¨é¢æ°—åœ§. Surface pressure

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    logical:: flag_output
                              ! å‡ºåŠ›ã®ãƒ•ãƒ©ã‚°.
                              ! Flag for output
    character(TOKEN):: date_str         ! æ—¥æ™‚ã®å¹´æœˆæ—¥æ™‚åˆ†ç§’å½¢å¼.
                                        ! Date with year-month-day hour:minute:second format
    integer :: n

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !
    if ( .not. restart_file_opened ) call RestartFileOpen

    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿å‡ºåŠ›ã§ã‚ã‚‹ã“ã¨ã®ãƒã‚§ãƒƒã‚¯
    ! Check restart data output
    !
    if ( flag_init_data_save ) then
      call MessageNotify( 'E', module_name, &
        & 'Now, initial data output mode.' )
    end if

    ! å‡ºåŠ›ã‚¿ã‚¤ãƒŸãƒ³ã‚°ã®ãƒã‚§ãƒƒã‚¯
    ! Check output timing
    !
    flag_output = TimeN - PrevOutputTime >= IntTime
    if ( TimeN >= EndTime .and. .not. flag_output_end ) then
      flag_output = .true.
      flag_output_end = .true.
    end if
    flag_output = ( .not. TimeN == PrevOutputTime ) .and. flag_output
    flag_output = flag_init_data_save .or. flag_output

    if ( .not. flag_output ) return

    ! æ¬¡å›žç”¨ã«, ä»Šå›žã®å‡ºåŠ› (å¸Œæœ›) æ™‚åˆ» ã‚’ä¿å˜
    ! Save output time (expected) in this time, for next time
    !
    PrevOutputTime = PrevOutputTime + IntTime

    ! æ™‚åˆ»ã®è¨å®š
    ! Set time
    !
    call HistorySetTime( timed = TimeN, history = gthst_rst )

    ! "TimeN" ã‚’å¹´æœˆæ—¥æ™‚åˆ†ç§’è¡¨è¨˜ã«ã—ã¦ "datetime" å¤‰æ•°ã¸å‡ºåŠ›
    ! Put "TimeN" on "datetime" variable with year-month-day hour:minute:second format
    !
    call DCCalDateInquire( &
      & date_str   = date_str, &   ! (out)
      & elapse_sec = TimeN, &      ! (in) optional
      & date       = InitialDate ) ! (in) optional

    call HistoryPut( 'datetime', date_str, &  ! (in)
      &              history = gthst_rst )    ! (inout) optional

    ! ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! Data output
    !
    call HistoryPut( &
      & 'UB', xyz_UB, history = gthst_rst ) ! (in)
    call HistoryPut( &
      & 'VB', xyz_VB, history = gthst_rst ) ! (in)
    call HistoryPut( &
      & 'TempB', xyz_TempB, history = gthst_rst ) ! (in)
    do n = 1, ncmax
      call HistoryPut( &
        & trim(a_QMixName(n))//'B', xyzf_QMixB(:,:,:,n), history = gthst_rst ) ! (in)
    end do
    call HistoryPut( &
      & 'PsB', xy_PsB, history = gthst_rst ) ! (in)

    call HistoryPut( &
      & 'UN', xyz_UN, history = gthst_rst ) ! (in)
    call HistoryPut( &
      & 'VN', xyz_VN, history = gthst_rst ) ! (in)
    call HistoryPut( &
      & 'TempN', xyz_TempN, history = gthst_rst ) ! (in)
    do n = 1, ncmax
      call HistoryPut( &
        & trim(a_QMixName(n))//'N', xyzf_QMixN(:,:,:,n), history = gthst_rst ) ! (in)
    end do
    call HistoryPut( &
      & 'PsN', xy_PsN, history = gthst_rst ) ! (in)

  end subroutine RestartFileOutput

  !--------------------------------------------------------------------------------------

  subroutine InitialFileOutput(                 &
    & xyz_U, xyz_V, xyz_Temp, xyzf_QMix, xy_Ps  &   ! (in)
    & )
    !
    ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›ã‚’è¡Œã„ã¾ã™.
    !
    ! Output initial data

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & TimeN, &              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ».
                              ! Time of step $ t $.
      & EndTime, &            ! è¨ˆç®—çµ‚äº†æ™‚åˆ».
                              ! End time of calculation
      & InitialDate           ! è¨ˆç®—é–‹å§‹æ—¥æ™‚.
                              ! Start date of calculation

    ! gtool4 ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! Gtool4 data output
    !
    use gtool_history, only: HistoryPut, HistorySetTime

    ! æš¦ã¨æ—¥æ™‚ã®å–ã‚Šæ‰±ã„
    ! Calendar and Date handler
    !
    use dc_calendar, only: DCCalDateInquire

    ! çµ„ã¿è¾¼ã¿é–¢æ•° PRESENT ã®æ‹¡å¼µç‰ˆé–¢æ•°
    ! Extended functions of intrinsic function "PRESENT"
    !
    use dc_present, only: present_and_true

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xyz_U    (0:imax-1, 1:jmax, 1:kmax)
                              ! $ u $ .     æ±è¥¿é¢¨é€Ÿ. Eastward wind
    real(DP), intent(in):: xyz_V    (0:imax-1, 1:jmax, 1:kmax)
                              ! $ v $ .     å—åŒ—é¢¨é€Ÿ. Northward wind
    real(DP), intent(in):: xyz_Temp (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T $ .     æ¸©åº¦. Temperature
    real(DP), intent(in):: xyzf_QMix(0:imax-1, 1:jmax, 1:kmax, 1:ncmax)
                              ! $ q $ .     æ¯”æ¹¿. Specific humidity
    real(DP), intent(in):: xy_Ps    (0:imax-1, 1:jmax)
                              ! $ p_s $ .   åœ°è¡¨é¢æ°—åœ§. Surface pressure

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    character(STRING):: date_str        ! æ—¥æ™‚ã®å¹´æœˆæ—¥æ™‚åˆ†ç§’å½¢å¼.
                                        ! Date with year-month-day hour:minute:second format
    integer          :: n

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !
    if ( .not. restart_file_opened ) call RestartFileOpen( flag_init_data = .true. )

    ! åˆæœŸå€¤å‡ºåŠ›ã§ã‚ã‚‹ã“ã¨ã®ãƒã‚§ãƒƒã‚¯
    ! Check initial data output
    !
    if ( .not. flag_init_data_save ) then
      call MessageNotify( 'E', module_name, &
        & 'Now, restart data output mode.' )
    end if

    ! æ™‚åˆ»ã®è¨å®š
    ! Set time
    !
    call HistorySetTime( timed = TimeN, history = gthst_rst )

    ! "TimeN" ã‚’å¹´æœˆæ—¥æ™‚åˆ†ç§’è¡¨è¨˜ã«ã—ã¦ "datetime" å¤‰æ•°ã¸å‡ºåŠ›
    ! Put "TimeN" on "datetime" variable with year-month-day hour:minute:second format
    !
    call DCCalDateInquire( &
      & date_str   = date_str, &   ! (out)
      & elapse_sec = TimeN, &      ! (in) optional
      & date       = InitialDate ) ! (in) optional

    call HistoryPut( 'datetime', date_str, &  ! (in)
      &              history = gthst_rst )    ! (inout) optional

    ! ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! Data output
    !
    call HistoryPut( &
      & 'U', xyz_U, history = gthst_rst )       ! (in)
    call HistoryPut( &
      & 'V', xyz_V, history = gthst_rst )       ! (in)
    call HistoryPut( &
      & 'Temp', xyz_Temp, history = gthst_rst ) ! (in)
    do n = 1, ncmax
      call HistoryPut( &
        & a_QMixName(n), xyzf_QMix(:,:,:,n), history = gthst_rst ) ! (in)
    end do
    call HistoryPut( &
      & 'Ps', xy_Ps, history = gthst_rst )      ! (in)

  end subroutine InitialFileOutput

  !--------------------------------------------------------------------------------------

  subroutine RestartFileClose
    !
    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«å‡ºåŠ›ã®çµ‚äº†å‡¦ç†ã‚’è¡Œã„ã¾ã™.
    !
    ! Terminate restart data files output.

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

    ! gtool4 ãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! Gtool4 data output
    !
    use gtool_history, only: HistoryClose

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

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !
    if ( .not. restart_file_opened ) return

    call HistoryClose( history = gthst_rst ) ! (inout)

    restart_file_opened = .false.
  end subroutine RestartFileClose

  !--------------------------------------------------------------------------------------

  subroutine RestartFileGet( &
    & xyz_UB, xyz_VB, xyz_TempB, xyzf_QMixB, xy_PsB, & ! (out)
    & xyz_UN, xyz_VN, xyz_TempN, xyzf_QMixN, xy_PsN, & ! (out)
    & flag_initial                                   & ! (out) optional
    & )
    !
    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã®å…¥åŠ›ã‚’è¡Œã„ã¾ã™.
    ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ/åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ãŒå˜åœ¨ã—ãªã„å ´åˆã«ã¯,
    ! initial_data ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‚’ç”¨ã„ã¦, åˆæœŸå€¤ç”Ÿæˆã‚’è¡Œã„ã¾ã™.
    !
    ! Input restart/initial data.
    ! If a restart/initial data file is not exist,
    ! initial data is created by "initial_data".

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & DelTime               ! $ \Delta t $ [s]

    ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ (ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿) æä¾›
    ! Prepare initial data (restart data)
    !
    use initial_data, only: SetInitData

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: TimesetSetInitialDate, TimesetSetTimeN, TimesetSetCalendar, &
      & RestartTime           ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ».
                              ! Restart time of calculation

    ! gtool4 ãƒ‡ãƒ¼ã‚¿å…¥åŠ›
    ! Gtool4 data input
    !
    use gtool_history, only: HistoryGet, HistoryGetAttr

    ! æ–‡å—åˆ—æ“ä½œ
    ! Character handling
    !
    use dc_string, only: toChar

    ! ãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›è£œåŠ©
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(out):: xyz_UB      (0:imax-1, 1:jmax, 1:kmax)
                              ! $ u (t-\Delta t) $ .   æ±è¥¿é¢¨é€Ÿ. Eastward wind
    real(DP), intent(out):: xyz_VB      (0:imax-1, 1:jmax, 1:kmax)
                              ! $ v (t-\Delta t) $ .   å—åŒ—é¢¨é€Ÿ. Northward wind
    real(DP), intent(out):: xyz_TempB   (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T (t-\Delta t) $ .   æ¸©åº¦. Temperature
    real(DP), intent(out):: xyzf_QMixB  (0:imax-1, 1:jmax, 1:kmax, 1:ncmax)
                              ! $ q (t-\Delta t) $ .   æ¯”æ¹¿. Specific humidity
    real(DP), intent(out):: xy_PsB      (0:imax-1, 1:jmax)
                              ! $ p_s (t-\Delta t) $ . åœ°è¡¨é¢æ°—åœ§. Surface pressure
    real(DP), intent(out):: xyz_UN      (0:imax-1, 1:jmax, 1:kmax)
                              ! $ u (t) $ .     æ±è¥¿é¢¨é€Ÿ. Eastward wind
    real(DP), intent(out):: xyz_VN      (0:imax-1, 1:jmax, 1:kmax)
                              ! $ v (t) $ .     å—åŒ—é¢¨é€Ÿ. Northward wind
    real(DP), intent(out):: xyz_TempN   (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T (t) $ .     æ¸©åº¦. Temperature
    real(DP), intent(out):: xyzf_QMixN  (0:imax-1, 1:jmax, 1:kmax, 1:ncmax)
                              ! $ q (t) $ .     æ¯”æ¹¿. Specific humidity
    real(DP), intent(out):: xy_PsN      (0:imax-1, 1:jmax)
                              ! $ p_s (t) $ .   åœ°è¡¨é¢æ°—åœ§. Surface pressure
    logical , intent(out), optional:: flag_initial
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã‚’èªã¿è¾¼ã‚€å ´åˆã«ã¯,
                              ! .false. ãŒ, åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‚’èªã¿è¾¼ã‚€å ´åˆã«ã¯
                              ! .true. ãŒè¿”ã‚Šã¾ã™.
                              !
                              ! If restart data is loaded, .false. is returned.
                              ! On the other hand, if initial data is loaded,
                              ! .true. is returned.

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: flag_rst        ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¥åŠ›æ™‚ã¯ 0,
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿å…¥åŠ›æ™‚ã¯ 1.
                              !
                              ! If initial data is input, this value is 0.
                              ! If restart data is input, this value is 1.

    character(STRING):: time_range
                              ! æ™‚åˆ»ã®æŒ‡å®š.
                              ! Specification of time
    character(TOKEN):: dummy_str
                              ! å…¥åŠ›ãƒã‚§ãƒƒã‚¯ç”¨ã®ãƒ€ãƒŸãƒ¼å¤‰æ•°
                              ! Dummy variable for check of input
    logical:: get_err
                              ! å…¥åŠ›æ™‚ã®ã‚¨ãƒ©ãƒ¼ãƒ•ãƒ©ã‚°.
                              ! Error flag for input
    real(DP):: returned_time
                              ! å…¥åŠ›ãƒ‡ãƒ¼ã‚¿ã®æ™‚åˆ».
                              ! Time of input data.
    logical:: flag_time_exist
                              ! å…¥åŠ›ãƒ‡ãƒ¼ã‚¿ã®æ™‚åˆ»ç”¨ã®ãƒ•ãƒ©ã‚°.
                              ! Flag for time of input data.

    integer:: origin_year, origin_month, origin_day, origin_hour, origin_min
                              ! è¨ˆç®—é–‹å§‹ã®å¹´æœˆæ—¥æ™‚åˆ†.
    real(DP):: origin_sec
                              ! è¨ˆç®—é–‹å§‹ã®ç§’.
    character(TOKEN):: cal_type
                              ! æš¦ã®ã‚¿ã‚¤ãƒ—.
    integer:: month_in_year, hour_in_day, min_in_hour
    integer, pointer:: day_in_month_ptr(:) => null()
    real(DP):: sec_in_min
                              ! æš¦ã®è©³ç´°æƒ…å ±
    real(DP):: rst_time
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã‹ã‚‰å¾—ã‚‰ã‚Œã‚‹æ™‚åˆ»å¤‰æ•°
                              ! Time variable from a restart data file

    logical:: flag_mpi_init

    integer :: n

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

    if ( .not. restart_file_io_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    ! ãƒ‡ãƒ¼ã‚¿ã‚’ initial_data ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‹ã‚‰å–å¾—
    ! Data is input from "initial_data" module
    !
    if ( trim(InputFile) == '' ) then
      call SetInitData( &
        & xyz_UB, xyz_VB, xyz_TempB, xyzf_QMixB(:,:,:,IndexH2OVap), xy_PsB )   ! (out)

      ! The variables below are initialized here, temporarily.
      !
      xyzf_QMixB(:,:,:,1:IndexH2OVap-1)     = 0.0_DP
      xyzf_QMixB(:,:,:,IndexH2OVap+1:ncmax) = 0.0_DP

      call MessageNotify( 'M', module_name, &
        & 'Initial data (not restart data) is input ' // &
        & 'from a module "initial_data". ' // &
        & '*B (t-dt) and *N (t) are same.' )

      xyz_UN     = xyz_UB
      xyz_VN     = xyz_VB
      xyz_TempN  = xyz_TempB
      xyzf_QMixN = xyzf_QMixB
      xy_PsN     = xy_PsB

      if ( present(flag_initial) ) flag_initial = .true.

    ! ãƒ‡ãƒ¼ã‚¿ã‚’ InputFile ã‹ã‚‰å–å¾—
    ! Data is input from InputFile
    !
    else

!!$      flag_mpi_init = .false.
      flag_mpi_init = .true.

      ! ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ‰ç„¡ã‚’ç¢ºèª
      ! Conform an existence of an input file
      !
      call HistoryGetAttr( InputFile, 'lon', 'units', & ! (in)
        & dummy_str, &                                  ! (out)
        & flag_mpi_split = flag_mpi_init, &             ! (in) optional
        & err = get_err )                               ! (out)

      if ( get_err ) then
        call MessageNotify( 'E', module_name, &
          & 'restart/initial data file "%c" is not found.', &
          & c1 = trim(InputFile) )
      end if

      ! æ™‚åˆ»æƒ…å ±ã®å–å¾—
      ! Get time information
      !
      time_range = 'time=' // toChar( RestartTime )

      ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‹ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ã‹ã®ãƒã‚§ãƒƒã‚¯
      ! Check whether input data is initial data or restart data
      !
      call HistoryGet( &
        & InputFile, 'flag_rst', &                ! (in)
        & flag_rst, &                             ! (out)
        & err = get_err, &                        ! (out) optional
        & quiet = .true., &                       ! (in) optional
        & flag_mpi_split = flag_mpi_init )        ! (in) optional

      if ( get_err ) then
        ! flag_rst å¤‰æ•°ãŒèªã¿è¾¼ã‚ãªã„å ´åˆã€ã¨ã‚Šã‚ãˆãšåˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã¨è¦‹ãªã™
        !
        flag_rst = 0
        if ( present(flag_initial) ) flag_initial = .true.

      else if ( flag_rst == 0 ) then
        if ( present(flag_initial) ) flag_initial = .true.

      else
        if ( present(flag_initial) ) flag_initial = .false.
      end if

      ! ç‰©ç†é‡ãƒ‡ãƒ¼ã‚¿ã®æœ‰ç„¡ã®ãƒã‚§ãƒƒã‚¯ ("U", "UB" ã®ã¿)
      ! Check existence or nonexistence of physical data (only "U", "UB")
      !
      if ( flag_rst == 0 ) then
        call HistoryGet( &
          & InputFile, 'U', &                       ! (in)
          & xyz_UB, &                               ! (out)
          & err = get_err, &                        ! (out) optional
          & quiet = .true., &                       ! (in) optional
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        if ( get_err ) then
          call MessageNotify( 'E', module_name, &
            & 'One of necessary variables "U" for start of calculation ' // &
            & 'cannot be read from "%c"', &
            & c1 = trim(InputFile) )
        end if

      else

        call HistoryGet( &
          & InputFile, 'UB', &                      ! (in)
          & xyz_UB, &                               ! (out)
          & range = time_range, &                   ! (in) optional
          & quiet = .true., &                       ! (in) optional
          & err = get_err, &                        ! (out) optional
          & returned_time = returned_time, &        ! (out) optional
          & flag_time_exist = flag_time_exist, &    ! (out) optional
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        if ( get_err ) then
          call MessageNotify( 'E', module_name, &
            & 'One of necessary variables "UB" for restart ' // &
            & 'cannot be read from "%c"', &
            & c1 = trim(InputFile) )
        end if
      end if

      ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ã‚’å…¥åŠ›ã™ã‚‹å ´åˆã€çµŒéŽæ™‚é–“ã‚’ 0 ã«è¨å®š
      ! Set 0 to elapsed time, when initial data is input
      !
      if ( flag_rst == 0 ) then
        call TimesetSetTimeN( 0.0_DP )
      end if

      ! æš¦ã€é–‹å§‹æ—¥æ™‚ã€çµŒéŽæ™‚åˆ»ã®èªã¿è¾¼ã¿ã¨ä¸Šæ›¸ãè¨å®š
      ! Input and overwrite calendar, start date, and elapsed time
      !
      if ( flag_rst /= 0 ) then

        ! æš¦ã®èªã¿è¾¼ã¿
        ! Input calendar
        !
        call HistoryGetAttr( &
          & InputFile, 'time', 'calendar', &          ! (in)
          & cal_type, &                               ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'month_in_year', &     ! (in)
          & month_in_year, &                          ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        allocate( day_in_month_ptr(month_in_year) )
        call HistoryGetAttr( &
          & InputFile, 'time', 'day_in_month', &      ! (in)
          & day_in_month_ptr, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'hour_in_day', &       ! (in)
          & hour_in_day, &                            ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'min_in_hour', &       ! (in)
          & min_in_hour, &                            ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'sec_in_min', &        ! (in)
          & sec_in_min, &                             ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        ! æš¦ã®ä¸Šæ›¸ãè¨å®š
        ! Overwrite calendar
        !
        call TimesetSetCalendar( cal_type, &       ! (in)
          & month_in_year, day_in_month_ptr, &     ! (in)
          & hour_in_day, min_in_hour, sec_in_min ) ! (in)

        deallocate( day_in_month_ptr )

        ! é–‹å§‹æ—¥æ™‚ã®èªã¿è¾¼ã¿
        ! Input start date
        !
        call HistoryGetAttr( &
          & InputFile, 'time', 'origin_year', &     ! (in)
          & origin_year, &                          ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'origin_month', &    ! (in)
          & origin_month, &                         ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'origin_day', &      ! (in)
          & origin_day, &                           ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'origin_hour', &     ! (in)
          & origin_hour, &                          ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'origin_min', &      ! (in)
          & origin_min, &                           ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        call HistoryGetAttr( &
          & InputFile, 'time', 'origin_sec', &      ! (in)
          & origin_sec, &                           ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional

        ! é–‹å§‹æ—¥æ™‚ã®ä¸Šæ›¸ãè¨å®š
        ! Overwrite start date
        !
        call TimesetSetInitialDate( &
          & origin_year, origin_month, origin_day, & ! (in)
          & origin_hour, origin_min,   origin_sec )  ! (in)

        ! çµŒéŽæ™‚é–“ã®èªã¿è¾¼ã¿
        ! Input elapsed time
        !
        call HistoryGet( &
          & InputFile, 'time', range = time_range, &  ! (in)
          & array = rst_time, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )          ! (in) optional

        call MessageNotify( 'M', module_name, &
          & '  Specified RestartTime from a NAMELIST file            = <%f>, ', &
          & d = (/ RestartTime /) )
        call MessageNotify( 'M', module_name, &
          & '  Actual initial value of TimeN  from a restart file  = <%f>', &
          & d = (/ rst_time /) )

        ! çµŒéŽæ™‚é–“ã®ä¸Šæ›¸ãè¨å®š
        ! Overwrite elapsed time
        !
        call TimesetSetTimeN( rst_time )

      end if

      ! ãƒ‡ãƒ¼ã‚¿å…¥åŠ›
      ! Data input
      !
      if ( flag_rst == 0 ) then
        call HistoryGet( &
          & InputFile, 'U', &                 ! (in)
          & array = xyz_UB, &                 ! (out)
          & flag_mpi_split = flag_mpi_init )  ! (in) optional
        call HistoryGet( &
          & InputFile, 'V', &                 ! (in)
          & array = xyz_VB, &                 ! (out)
          & flag_mpi_split = flag_mpi_init )  ! (in) optional
        call HistoryGet( &
          & InputFile, 'Temp', &              ! (in)
          & array = xyz_TempB, &              ! (out)
          & flag_mpi_split = flag_mpi_init )  ! (in) optional
        do n = 1, ncmax
          call HistoryGet(                           &
            & InputFile, trim(a_QMixName(n)),        &              ! (in)
            & array = xyzf_QMixB(:,:,:,n),           &              ! (out)
            & flag_mpi_split = flag_mpi_init         &              ! (in) optional
            & )
        end do
        call HistoryGet( &
          & InputFile, 'Ps', &                ! (in)
          & array = xy_PsB, &                 ! (out)
          & flag_mpi_split = flag_mpi_init )  ! (in) optional

        call MessageNotify( 'M', module_name, &
          & 'Initial data (not restart data) is input ' // &
          & 'from a data file "%c". ' // &
          & '*B (t-dt) and *N (t) are same.', &
          & c1 = trim(InputFile) )

        xyz_UN     = xyz_UB
        xyz_VN     = xyz_VB
        xyz_TempN  = xyz_TempB
        xyzf_QMixN = xyzf_QMixB
        xy_PsN     = xy_PsB

      else
        call HistoryGet( &
          & InputFile, 'UB', range = time_range, &  ! (in)
          & array = xyz_UB, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional
        call HistoryGet( &
          & InputFile, 'VB', range = time_range, &  ! (in)
          & array = xyz_VB, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional
        call HistoryGet( &
          & InputFile, 'TempB', range = time_range, &  ! (in)
          & array = xyz_TempB, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )           ! (in) optional
        do n = 1, ncmax
          call HistoryGet(                                             &
            & InputFile, trim(a_QMixName(n))//'B', range = time_range, & ! (in)
            & array = xyzf_QMixB(:,:,:,n),                             & ! (out)
            & flag_mpi_split = flag_mpi_init                           & ! (in) optional
            & )
        end do
        call HistoryGet( &
          & InputFile, 'PsB', range = time_range, &  ! (in)
          & array = xy_PsB, &                        ! (out)
          & flag_mpi_split = flag_mpi_init )         ! (in) optional

        call HistoryGet( &
          & InputFile, 'UN', range = time_range, &  ! (in)
          & array = xyz_UN, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional
        call HistoryGet( &
          & InputFile, 'VN', range = time_range, &  ! (in)
          & array = xyz_VN, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )        ! (in) optional
        call HistoryGet( &
          & InputFile, 'TempN', range = time_range, &  ! (in)
          & array = xyz_TempN, &                       ! (out)
          & flag_mpi_split = flag_mpi_init )           ! (in) optional
        do n = 1, ncmax
          call HistoryGet(                                             &
            & InputFile, trim(a_QMixName(n))//'N', range = time_range, & ! (in)
            & array = xyzf_QMixN(:,:,:,n),                             & ! (out)
            & flag_mpi_split = flag_mpi_init                           & ! (in) optional
            & )
        end do
        call HistoryGet( &
          & InputFile, 'PsN', range = time_range, &  ! (in)
          & array = xy_PsN, &                        ! (out)
          & flag_mpi_split = flag_mpi_init )         ! (in) optional

        call MessageNotify( 'M', module_name, &
          & 'Restart data (not initial data) is input ' // &
          & 'from a data file "%c". ', &
          & c1 = trim(InputFile) )
      end if

    end if

  end subroutine RestartFileGet

  !--------------------------------------------------------------------------------------

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

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & RestartTime           ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ».
                              ! Restart time of calculation

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

    ! æš¦ã¨æ—¥æ™‚ã®å–ã‚Šæ‰±ã„
    ! Calendar and Date handler
    !
    use dc_calendar, only: DCCalConvertByUnit

    ! ãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›è£œåŠ©
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! ç¨®åˆ¥åž‹ãƒ‘ãƒ©ãƒ¡ã‚¿
    ! Kind type parameter
    !
    use dc_types, only: STDOUT ! æ¨™æº–å‡ºåŠ›ã®è£…ç½®ç•ªå·. Unit number of standard output

    ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ (ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿) æä¾›
    ! Prepare initial data (restart data)
    !
    use initial_data, only: InitDataInit

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

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: unit_nml        ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«ã‚ªãƒ¼ãƒ—ãƒ³ç”¨è£…ç½®ç•ªå·.
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST èªã¿è¾¼ã¿æ™‚ã® IOSTAT.
                              ! IOSTAT of NAMELIST read

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

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

    if ( restart_file_io_inited ) return

    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã®è¨å®š
    ! Default values settings
    !
    InputFile  = ''
    if ( .not. flag_init_data_save ) then
      OutputFile = 'rst.nc'
    else
      OutputFile = 'init.nc'
    end if
    IntValue   = 365.0d0
    IntUnit    = 'day'

    ! 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 = restart_file_io_nml, &  ! (out)
        & iostat = iostat_nml ) ! (out)
      close( unit_nml )

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

    ! å‡ºåŠ›æ™‚é–“é–“éš”ã®è¨å®š
    ! Configure time interval of output
    !
    IntTime = DCCalConvertByUnit( IntValue, IntUnit, 'sec' ) ! (in)
    PrevOutputTime = RestartTime

    ! ãƒ•ãƒ©ã‚°ã®åˆæœŸåŒ–
    ! Initialize flag
    !
    flag_output_end = .false.

    ! Initialization of modules used in this module

    ! åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ (ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿) æä¾›
    ! Prepare initial data (restart data)
    !
    call InitDataInit

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, 'Input:: ' )
    if ( trim(InputFile) /= '' ) then
      call MessageNotify( 'M', module_name, '  InputFile  = %c', c1 = trim(InputFile) )
    else
      call MessageNotify( 'M', module_name, '  InputFile  = <Non>' )
      call MessageNotify( 'M', module_name, '  ** Initial data is generated in "initial_data" module' )
    end if
    call MessageNotify( 'M', module_name, 'Output:: ' )
    call MessageNotify( 'M', module_name, '  OutputFile = %c', c1 = trim(OutputFile) )
    call MessageNotify( 'M', module_name, '  IntTime    = %f [%c]', d = (/ IntValue /), c1 = trim(IntUnit) )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    restart_file_io_inited = .true.

  end subroutine RestartFileInit

  !--------------------------------------------------------------------------------------

end module restart_file_io