!= æ™‚åˆ»ç®¡ç†
!
!= Time control
!
! Authors::   Yoshiyuki O. Takahashi, Yasuhiro MORIKAWA
! Version::   $Id: timeset.f90,v 1.24 2012/01/20 00:17:14 yot Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2010. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module timeset
  !
  != æ™‚åˆ»ç®¡ç†
  !
  != Time control
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! æ™‚åˆ»æƒ…å ±ã®ç®¡ç†ã‚’è¡Œã„ã¾ã™.
  !
  ! Information of time is controlled.
  !
  !== Variables List
  !
  ! TimeB                  :: ã‚¹ãƒ†ãƒƒãƒ— $ t - \Delta t $ ã®æ™‚åˆ»
  ! TimeN                  :: ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ»
  ! TimeA                  :: ã‚¹ãƒ†ãƒƒãƒ— $ t + \Delta t $ ã®æ™‚åˆ»
  ! DelTime                :: $ \Delta t $ [s] (å®Ÿæ•°åž‹ã®æ•°å€¤)
  ! RestartTime            :: ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ»
  ! EndTime                :: è¨ˆç®—çµ‚äº†æ™‚åˆ»
  ! InitialDate            :: è¨ˆç®—é–‹å§‹æ—¥æ™‚
  ! ------------           :: ------------
  ! TimeB                  :: Time of step $ t - \Delta t $
  ! TimeN                  :: Time of step $ t $
  ! TimeA                  :: Time of step $ t + \Delta t $
  ! DelTime                :: $ \Delta t $ [s] (numerical value of float type)
  ! RestartTime            :: Restart time of calculation
  ! EndTime                :: End time of calculation
  ! InitialDate            :: Start date of calculation
  !
  !== Procedures List
  !
  ! TimesetInit           :: timeset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–
  ! TimesetDelTimeHalf    :: Î”t ã‚’ä¸€æ™‚çš„ã«åŠåˆ†ã«
  ! TimesetProgress       :: æ™‚åˆ»ã®é€²è¡Œ
  ! TimesetSetTimeN       :: TimeN ã®è¨å®š
  ! TimesetSetInitialDate :: è¨ˆç®—é–‹å§‹æ—¥æ™‚ã®è¨å®š
  ! TimesetClockStart     :: è¨ˆç®—æ™‚é–“è¨ˆæ¸¬é–‹å§‹
  ! TimesetClockStop      :: è¨ˆç®—æ™‚é–“è¨ˆä¸€æ™‚åœæ¢
  ! TimesetClose          :: timeset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®çµ‚äº†å‡¦ç†
  ! ------------          :: ------------
  ! TimesetInit           :: Initialize "timeset" module
  ! TimesetDelTimeHalf    :: Reduce delta t to half temporarily
  ! TimesetProgress       :: Progress time
  ! TimesetSetTimeN       :: Set TimeN
  ! TimesetSetInitialDate :: Set start date
  ! TimesetClockStart     :: Start measurement of computation time
  ! TimesetClockStop      :: Pause measurement of computation time
  ! TimesetClose          :: Terminate "timeset" module
  !
  !== NAMELIST
  !
  ! NAMELIST#timeset_nml
  !

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

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

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

  ! CPU æ™‚é–“è¨ˆæ¸¬
  ! CPU time monitor
  !
  use dc_clock, only: CLOCK

  ! æš¦ã¨æ—¥æ™‚ã®å–ã‚Šæ‰±ã„
  ! Calendar and Date handler
  !
  use dc_calendar, only: &
    & DC_CAL, &               ! æš¦ã‚’è¡¨ç¾ã™ã‚‹ãƒ‡ãƒ¼ã‚¿åž‹.
                              ! Data type for calendar
    & DC_CAL_DATE             ! æ—¥æ™‚ã‚’è¡¨ç¾ã™ã‚‹ãƒ‡ãƒ¼ã‚¿åž‹.
                              ! Data type for date and time

  ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«å…¥åŠ›ã«é–¢ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£
  ! Utilities for NAMELIST file input
  !
  use namelist_util, only: MaxNmlArySize
                              ! NAMELIST ã‹ã‚‰èªã¿è¾¼ã‚€é…åˆ—ã®æœ€å¤§ã‚µã‚¤ã‚º.
                              ! Maximum size of arrays loaded from NAMELIST

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

  ! å…¬é–‹æ‰‹ç¶šã
  ! Public procedure
  !
  public:: TimesetInit, TimesetClose, TimesetProgress, TimesetDelTimeHalf
  public:: TimesetClockStart, TimesetClockStop
  public:: TimesetSetTimeN, TimesetSetInitialDate, TimesetSetCalendar

  ! å…¬é–‹å¤‰æ•°
  ! Public variables
  !
  logical, save, public:: timeset_inited = .false.
                              ! åˆæœŸè¨å®šãƒ•ãƒ©ã‚°.
                              ! Initialization flag
  real(DP), save, public:: TimeB
                              ! ã‚¹ãƒ†ãƒƒãƒ— $ t - \Delta t $ ã®æ™‚åˆ».
                              ! Time of step $ t - \Delta t $.
  real(DP), save, public:: TimeN
                              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ».
                              ! Time of step $ t $.
  real(DP), save, public:: TimeA
                              ! ã‚¹ãƒ†ãƒƒãƒ— $ t + \Delta t $ ã®æ™‚åˆ».
                              ! Time of step $ t + \Delta t $.
  real(DP), save, public:: DelTime
                              ! $ \Delta t $ [s]
  real(DP), save:: IntegPeriod
                              ! ç©åˆ†æ™‚é–“. å˜ä½ã¯ç§’.
                              ! Unit is second.
  real(DP), save, public:: RestartTime
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ».
                              ! Restart time of calculation
                              !--
                              ! å‚™è€ƒ:
                              !
                              ! å®Ÿè³ªçš„ãªè¨ˆç®—é–‹å§‹æ™‚åˆ»ã¯åˆæœŸå€¤ãƒ‡ãƒ¼ã‚¿ä½¿ç”¨æ™‚ãªã‚‰ã°
                              ! 0, ãƒªã‚¹ã‚¿ãƒ¼ãƒˆãƒ‡ãƒ¼ã‚¿ä½¿ç”¨æ™‚ã§ã‚ã‚Œã°ãƒªã‚¹ã‚¿ãƒ¼ãƒˆ
                              ! ãƒ‡ãƒ¼ã‚¿ã«æ ¼ç´ã•ã‚ŒãŸã‚‚ã®ãŒä½¿ç”¨ã•ã‚Œã‚‹.
                              ! ï¼ˆDelTime ã®å€¤ã«ã‚ˆã£ã¦æ™‚åˆ»ãŒå¿…ãšã—ã‚‚åˆ‡ã‚Šã®ï¼‰
                              ! è‰¯ã„æ•°å—ã«ãªã‚‰ãªã„ã“ã¨ã‚’æƒ³å®šã—ã¦ã„ã‚‹ï¼‰ã€‚
                              !
                              ! ã“ã®å€¤ã¯ãƒ¢ãƒ‡ãƒ«ã‚’å‹•ã‹ã™ãƒ¦ãƒ¼ã‚¶ãŒè¨ˆç®—é–‹å§‹ã‚’
                              ! æœŸå¾…ã—ã¦ã„ã‚‹æ™‚åˆ»ã§ã‚ã‚Šã€ã“ã®å€¤ã‚’å…ƒã«
                              ! è¨ˆç®—çµ‚äº†æ™‚åˆ»ãŒè¨å®šã•ã‚Œ, ã¾ãŸã“ã®å€¤ãŒãƒªã‚¹ã‚¿ãƒ¼ãƒˆ
                              ! ãƒ•ã‚¡ã‚¤ãƒ«ã®å‡ºåŠ›é–‹å§‹æ™‚åˆ»ã¨ã—ã¦ã‚‚ç”¨ã„ã‚‰ã‚Œã‚‹.
                              !++
  real(DP), save, public:: EndTime
                              ! è¨ˆç®—çµ‚äº†æ™‚åˆ».
                              ! End time of calculation

  type(DC_CAL_DATE), save, public:: InitialDate
                              ! è¨ˆç®—é–‹å§‹æ—¥æ™‚.
                              ! Start date of calculation
  type(DC_CAL_DATE), save, public:: EndDate
                              ! è¨ˆç®—çµ‚äº†ã®æ—¥æ™‚

  ! éžå…¬é–‹å¤‰æ•°
  ! Private variables
  !
  character(TOKEN), save:: cal_type
                              ! æš¦æƒ…å ±.
                              ! Type of calendar used for an experiment

  integer         , save:: month_in_year
                              ! Number of months in a year which is used
                              ! when cal_type = "user_defined"
  integer         , save:: day_in_month(1:MaxNmlArySize)
                              ! Number of days in a month which is used
                              ! when cal_type = "user_defined"
  integer         , save:: hour_in_day
                              ! Number of hours in a day which is used
                              ! when cal_type = "user_defined"
  integer         , save:: min_in_hour
                              ! Number of minutes in a hour which is used
                              ! when cal_type = "user_defined"
  real(DP)        , save:: sec_in_min
                              ! Number of seconds in a minute which is used
                              ! when cal_type = "user_defined"

  real(DP)        , save:: RestartTimeValue
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ».
                              ! Restart time of calculation
  character(TOKEN), save:: RestartTimeUnit
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ»ã®å˜ä½.
                              ! Unit of restart time of calculation
  real(DP)        , save:: DelTimeValue
                              ! $ \Delta t $ .  å˜ä½ã¯ DelTimeUnit ã«ã¦æŒ‡å®š.
                              ! Unit is specified by "DelTimeUnit".
  character(TOKEN), save:: DelTimeUnit
                              ! $ \Delta t $ ã®å˜ä½.
                              ! Unit of $ \Delta t $

  logical         , save:: flag_half
                              ! TimesetDelTimeHalf ã«ã‚ˆã£ã¦ $ \Delta t $ ãŒ
                              ! åŠåˆ†ã«ãªã£ã¦ã„ã‚‹ã“ã¨ã‚’ç¤ºã™ãƒ•ãƒ©ã‚°.
                              !
                              ! Flag that shows $ \Delta t $ is reduced to
                              ! half by "TimesetDelTimeHalf"
  real(DP)        , save:: DelTimeSave
                              ! $ \Delta t $ [s] ã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤.
                              ! ("TimesetDelTimeHalf" ã§ä½¿ç”¨ã•ã‚Œã‚‹)
                              !
                              ! Default value of $ \Delta t $ [s].
                              ! (for "TimesetDelTimeHalf")

  real(DP)        , save:: PredictIntTime
                              ! çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºæ™‚é–“é–“éš”.
                              ! Interval time of predicted end time output
  real(DP)        , save:: PredictPrevTime
                              ! å‰å›žã®çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºæ™‚é–“.
                              ! Time when predicted end time is output previously
  real(DP)        , save:: PredictIntValue
                              ! çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºé–“éš”.
                              ! Interval of predicted end time output
  character(TOKEN), save:: PredictIntUnit
                              ! çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºé–“éš” (å˜ä½).
                              ! Unit for interval of predicted end time output

  logical         , save:: CpuTimeMoniter
                              ! CPU æ™‚é–“è¨ˆæ¸¬ã®ã‚ªãƒ³ã‚ªãƒ•
                              ! On/off of CPU time monitoring

  integer         , parameter:: clkmax = 64
                              ! CPU æ™‚é–“è¨ˆæ¸¬ã‚’è¡Œã†ãƒ—ãƒã‚»ã‚¹ã®æœ€å¤§æ•°.
                              ! Maximum number of processes monitored CPU time
  integer         , save:: clk_proc_num = 0
                              ! CPU æ™‚é–“è¨ˆæ¸¬ã‚’è¡Œã£ã¦ã„ã‚‹ãƒ—ãƒã‚»ã‚¹ã®æ•°.
                              ! Number of processes monitored CPU time
  type(CLOCK)     , save:: clocks(1:clkmax)
                              ! CPU æ™‚é–“è¨ˆæ¸¬ç”¨æ§‹é€ ä½“
                              ! Derived type for monitoring CPU time
  character(TOKEN), save:: clocks_name(1:clkmax) = ''
                              ! CPU æ™‚é–“è¨ˆæ¸¬ã‚’è¡Œã£ã¦ã„ã‚‹ãƒ—ãƒã‚»ã‚¹ã®åç§°
                              ! Names of processes monitored CPU time

  character(*), parameter:: module_name = 'timeset'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: timeset.f90,v 1.24 2012/01/20 00:17:14 yot Exp $'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³
                              ! Module version

contains

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

  subroutine TimesetInit
    !
    ! timeset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–ã‚’è¡Œã„ã¾ã™.
    ! NAMELIST#timeset_nml ã®èªã¿è¾¼ã¿ã¯ã“ã®æ‰‹ç¶šãã§è¡Œã‚ã‚Œã¾ã™.
    !
    ! "timeset" module is initialized.
    ! NAMELIST#timeset_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

    ! æš¦ã¨æ—¥æ™‚ã®å–ã‚Šæ‰±ã„
    ! Calendar and Date handler
    !
    use dc_calendar, only: DCCalCreate, DCCalConvertByUnit, DCCalToChar, DCCalInquire, &
      & DCCalDateCreate, DCCalDateDifference, DCCalDateToChar, DCCalDateInquire, &
      & DCCalDefault

    ! CPU æ™‚é–“è¨ˆæ¸¬
    ! CPU time monitor
    !
    use dc_clock, only: DCClockCreate, DCClockStart

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

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

    integer:: InitialYear, InitialMonth, InitialDay, InitialHour, InitialMin
                              ! è¨ˆç®—é–‹å§‹æ—¥æ™‚ (å¹´æœˆæ—¥æ™‚åˆ†)
                              ! Start date of calculation (year, month, day, hour, minute)
    real(DP):: InitialSec
                              ! è¨ˆç®—é–‹å§‹æ—¥æ™‚ (ç§’)
                              ! Start date of calculation (second)
    real(DP):: IntegPeriodValue
                              ! ç©åˆ†æ™‚é–“.
                              ! Integral time.
    character(TOKEN):: IntegPeriodUnit
                              ! "IntegPeriodValue" ã®å˜ä½.
                              ! Unit of "IntegPeriodValue".
    integer:: EndYear, EndMonth, EndDay, EndHour, EndMin
                              ! è¨ˆç®—çµ‚äº†æ—¥æ™‚ (å¹´æœˆæ—¥æ™‚åˆ†).
                              ! "IntegPeriodValue" ãŒè² ã®å ´åˆã«ã“ã¡ã‚‰ãŒä½¿ç”¨ã•ã‚Œã‚‹.
                              !
                              ! End date of calculation (year, month, day, hour, minute)
                              ! These are used when "IntegPeriodValue" is negative
    real(DP):: EndSec
                              ! è¨ˆç®—çµ‚äº†æ—¥æ™‚ (ç§’).
                              ! "IntegPeriodValue" ãŒè² ã®å ´åˆã«ã“ã¡ã‚‰ãŒä½¿ç”¨ã•ã‚Œã‚‹.
                              !
                              ! End date of calculation (second)
                              ! These are used when "IntegPeriodValue" is negative

    ! å°å—ç”¨ä½œæ¥å¤‰æ•°
    ! Work variables for print
    !
    type(DC_CAL):: cal_print
    real(DP):: EndTimeValue_print
    character(TOKEN):: date_print

    ! ä½œæ¥å¤‰æ•°
    ! 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 /timeset_nml/ &
      & cal_type, &
      & month_in_year, day_in_month, hour_in_day, min_in_hour, sec_in_min, &
      !
      & DelTimeValue,    DelTimeUnit, &
      & RestartTimeValue,  RestartTimeUnit, &
      & InitialYear, InitialMonth, InitialDay, InitialHour, InitialMin, InitialSec, &
      & EndYear, EndMonth, EndDay, EndHour, EndMin, EndSec, &
      & IntegPeriodValue, IntegPeriodUnit, &
      !
      & PredictIntValue,  PredictIntUnit, &
      & CpuTimeMoniter
          !
          ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã«ã¤ã„ã¦ã¯åˆæœŸåŒ–æ‰‹ç¶š "timeset#TimesetInit"
          ! ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã®ã“ã¨.
          !
          ! Refer to source codes in the initialization procedure
          ! "timeset#TimesetInit" for the default values.
          !

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

    if ( timeset_inited ) return
    call InitCheck

    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã®è¨å®š
    ! Default values settings
    !
    cal_type                      = 'noleap'
    month_in_year                 =   -1
    day_in_month(1:MaxNmlArySize) =   -1
    hour_in_day                   =   -1
    min_in_hour                   =   -1
    sec_in_min                    =   -1.0_DP

    ! Sample value for the Earth
    !
!!$    cal_type                      = 'gregorian'
!!$    month_in_year                 =   -1
!!$    day_in_month(1:MaxNmlArySize) =   -1
!!$    hour_in_day                   =   -1
!!$    min_in_hour                   =   -1
!!$    sec_in_min                    =   -1.0_DP

    ! Sample value for the Mars
    !   Number of days in a year and Mars solar day in second are obtained from
    !   Allison (1997).
    !   Allison, M, Geophys. Res. Lett., 24, 1967-1970, 1997.
    !
!!$    cal_type                      = 'user_defined'
!!$    month_in_year                 =    1
!!$    day_in_month(1:MaxNmlArySize) =  669
!!$    hour_in_day                   =   24
!!$    min_in_hour                   =    1
!!$    sec_in_min                    = 3700.0_DP    ! 3699.0_DP

    DelTimeValue                  =   30.0_DP
    DelTimeUnit                   = 'min'
    flag_half                     = .false.

    RestartTimeValue              =    0.0_DP
    RestartTimeUnit               = 'sec'

    InitialYear                   = 2000
    InitialMonth                  =    1
    InitialDay                    =    1
    InitialHour                   =    0
    InitialMin                    =    0
    InitialSec                    =    0.0

    IntegPeriodValue              =   -1.0
                                   ! If IntegPeriodValue is negative, EndXXX are used.
    IntegPeriodUnit               = 'sec'

    EndYear                       = 2000
    EndMonth                      =    1
    EndDay                        =    2
    EndHour                       =    0
    EndMin                        =    0
    EndSec                        =    0.0

    PredictIntValue               =    1.0_DP
    PredictIntUnit                = 'day'

    CpuTimeMoniter                 = .true.

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

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

    ! æš¦ã®æƒ…å ±ã‚’è¨å®š
    ! Set calendar
    !
    if ( cal_type == "user_defined" ) then
      call DCCalCreate(                                                &
        &               month_in_year = month_in_year                , & ! (in)
        &               day_in_month  = day_in_month(1:month_in_year), & ! (in)
        &               hour_in_day   = hour_in_day                  , & ! (in)
        &               min_in_hour   = min_in_hour                  , & ! (in)
        &               sec_in_min    = sec_in_min                     & ! (in)
        & )
    else
      call DCCalCreate( cal_type = cal_type ) ! (in)
    end if

    ! Lines below will be deleted. (yot, 2010/08/12)
    !

    ! æš¦ã®æƒ…å ±ã‚’è¨å®š (ã‚µãƒ³ãƒ—ãƒ«ã¨ã—ã¦ã„ãã¤ã‹ã® case ã‚’è¨˜è¼‰)
    !
    ! case 1:
    ! dc_calendar ã§ç”¨æ„ã•ã‚Œã‚‹å…¸åž‹çš„ãªæš¦ã‚’ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®æš¦ã¨ã—ã¦è¨å®š
    !
!!$    call DCCalCreate( cal_type = 'gregorian' ) ! (in)  ! ã‚°ãƒ¬ã‚´ãƒªã‚ªæš¦
!!$    call DCCalCreate( cal_type = 'julian'    ) ! (in)  ! ãƒ¦ãƒªã‚¦ã‚¹æš¦
!!$    call DCCalCreate( cal_type = 'noleap'    ) ! (in)  ! é–å¹´ç„¡ã—ã®æš¦
!!$    call DCCalCreate( cal_type = '360day'    ) ! (in)  ! 1ãƒ¶æœˆãŒ 30 æ—¥ã®æš¦
!!$    call DCCalCreate( cal_type = 'cyclic'    ) ! (in)  ! ã‚ã‚‹æœˆã®æ—¥æ•°ã‚’ ã€Œ30.6 Ã— æœˆæ•° âˆ’ å‰æœˆã¾ã§ã®ç·æ—¥æ•°ã€ã®å°æ•°ç‚¹ä»¥ä¸‹åˆ‡æ¨ã¨ã™ã‚‹æš¦

!!$    ! case 2:
!!$    ! æ±ºã¾ã‚Šåˆ‡ã£ãŸæš¦ (ä»¥ä¸‹ã¯ãƒ¦ãƒªã‚¦ã‚¹æš¦) ã‚’è¨å®š
!!$    !
!!$    call DCCalCreate( cal_type = 'Julian' ) ! (in)
!!$
!!$    ! case 3:
!!$    ! åœ°çƒã£ã½ã„æš¦ã‚’åˆ©ç”¨è€…ãŒæ˜Žç¤ºçš„ã«æŒ‡å®š
!!$    !
!!$    call DCCalCreate( month_in_year = 12 , &   ! (in)
!!$      &               day_in_month  = (/31, 28, 31, 30, 31, 30,   &
!!$      &                                 31, 31, 30, 31, 30, 31/), & ! (in)
!!$      &               hour_in_day = 24,     &  ! (in)
!!$      &               min_in_hour = 60 ,    &  ! (in)
!!$      &               sec_in_min  = 60.0d0 )   ! (in)
!!$
!!$    ! case 3:
!!$    ! ç«æ˜Ÿã£ã½ã„æš¦ã‚’åˆ©ç”¨è€…ãŒæ˜Žç¤ºçš„ã«æŒ‡å®š.
!!$    ! â€» ã€Œæš¦ã«æœˆãŒãªã„ã€å ´åˆã«ã¯, month_in_year = 1 ã¨ã™ã‚‹.
!!$    !
!!$    call DCCalCreate( month_in_year = 1 , &      ! (in)
!!$      &               day_in_month  = (/669/), & ! (in)
!!$      &               hour_in_day = 24, &        ! (in)
!!$      &               min_in_hour = 1 , &        ! (in)
!!$      &               sec_in_min  = 3694.0d0  )  ! (in)

    ! æ™‚é–“å¤‰æ•° (ç§’) ã®è¨å®š
    ! Calculate time variable (sec)
    !
    DelTime        = DCCalConvertByUnit( DelTimeValue,     DelTimeUnit,     'sec' ) !(in)
    RestartTime    = DCCalConvertByUnit( RestartTimeValue, RestartTimeUnit, 'sec' ) !(in)

    ! é–‹å§‹æ—¥æ™‚ã®æƒ…å ±ã‚’è¨å®š
    !
    ! å†è¨ˆç®—æ™‚ã«ã¯ restart_file_io ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã«ã‚ˆã‚‹ TimesetSetInitialDate
    ! å‘¼ã³å‡ºã—ã«ã‚ˆã£ã¦ä¸Šæ›¸ãã•ã‚Œã‚‹ã“ã¨ã‚’æƒ³å®š.
    !
    if ( ( .not. ( InitialMonth < 0      ) ) .and. &
      &  ( .not. ( InitialDay   < 0      ) ) .and. &
      &  ( .not. ( InitialHour  < 0      ) ) .and. &
      &  ( .not. ( InitialMin   < 0      ) ) .and. &
      &  ( .not. ( InitialSec   < 0.0_DP ) ) ) then

      call DCCalDateCreate( &
        & year  = InitialYear,   & ! (in)
        & month = InitialMonth,  & ! (in)
        & day   = InitialDay,    & ! (in)
        & hour  = InitialHour,   & ! (in)
        & min   = InitialMin,    & ! (in)
        & sec   = InitialSec,    & ! (in)
        & date  = InitialDate )  ! (out) optional
    else
      call MessageNotify('W', module_name, 'InitialMonth/Day/Hour/Min/Sec is negative.' )
    end if

    ! çµ‚äº†æ—¥æ™‚ (é–‹å§‹æ—¥æ™‚ã‹ã‚‰ã®çµŒéŽæ™‚é–“ã§è¡¨ç¾) ã‚’è¨å®š
    !
    if ( IntegPeriodValue < 0.0 ) then

      IntegPeriod = IntegPeriodValue

      ! case 1
      ! çµ‚äº†æ—¥æ™‚ã‚’ä½¿ã†å ´åˆ
      !
      call DCCalDateCreate( &
        & year  = EndYear,   & ! (in)
        & month = EndMonth,  & ! (in)
        & day   = EndDay,    & ! (in)
        & hour  = EndHour,   & ! (in)
        & min   = EndMin,    & ! (in)
        & sec   = EndSec,    & ! (in)
        & date  = EndDate )    ! (out) optional

      EndTime = DCCalDateDifference( &
        &         start_date = InitialDate, &  ! (in)
        &         end_date   = EndDate )       ! (in)

      if ( .not. EndTime > 0.0 ) then
        call DCCalDateInquire( date_print, date = InitialDate )
        call MessageNotify('W', module_name, 'InitialDate=<%c>', c1 = trim(date_print) )
        call DCCalDateInquire( date_print, date = EndDate )
        call MessageNotify('W', module_name, 'EndDate=<%c>', c1 = trim(date_print) )
        call MessageNotify('E', module_name, '"EndTime" must be positive.')
      end if

    else
      ! case 2
      ! ç©åˆ†æ™‚é–“ã‚’ä½¿ã†å ´åˆ
      !
      IntegPeriod = DCCalConvertByUnit( IntegPeriodValue, IntegPeriodUnit, 'sec' ) !(in)

      EndTime = RestartTime + IntegPeriod
    end if

    ! çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºæ™‚é–“ã®åˆæœŸè¨å®š
    ! Initialize Time when predicted end time is output
    !
    PredictIntTime  = DCCalConvertByUnit( PredictIntValue, PredictIntUnit, 'sec' ) !(in)
    PredictPrevTime = RestartTime - DelTime

    ! æ™‚åˆ»ã®æ£å½“æ€§ã®ãƒã‚§ãƒƒã‚¯
    ! Check validation of time
    !
    call TimeValidCheck( RestartTime, EndTime, DelTime, PredictIntTime ) ! (in)

    ! å„ã‚¿ã‚¤ãƒ ã‚¹ãƒ†ãƒƒãƒ—ã®æ™‚åˆ»ã®è¨å®š
    ! Configure time on each time step
    !
    ! å†è¨ˆç®—æ™‚ã«ã¯ restart_file_io ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã«ã‚ˆã‚‹ TimesetSetTimeN
    ! å‘¼ã³å‡ºã—ã«ã‚ˆã£ã¦ä¸Šæ›¸ãã•ã‚Œã‚‹ã“ã¨ã‚’æƒ³å®š.
    !
    TimeN = RestartTime
    TimeB = TimeN - DelTime
    TimeA = TimeN + DelTime

    ! $ \Delta t $ [s] ã‚’ä¿å˜
    ! Save $ \Delta t $ [s]
    !
    DelTimeSave = DelTime

    ! CPU æ™‚é–“è¨ˆæ¸¬é–‹å§‹ (ãƒ¢ãƒ‡ãƒ«å…¨ä½“)
    ! Start CPU time monitoring (for entire model)
    !
    if ( CpuTimeMoniter ) then
      call DCClockCreate( clocks(clk_proc_num + 1), 'total' ) ! (in)
      call DCClockStart( clocks(clk_proc_num + 1) ) ! (in)
      clocks_name(clk_proc_num + 1) = 'total'
      clk_proc_num = clk_proc_num + 1
    end if

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, '  RestartTime  = %f [%c]', &
      & d = (/ RestartTimeValue /), c1 = trim(RestartTimeUnit) )
    call DCCalDateInquire( date_print, date = InitialDate )
    call MessageNotify( 'M', module_name, '  InitialDate  = %c', &
      & c1 = trim(date_print) )
    if ( IntegPeriodValue < 0.0 ) then
      call DCCalDateInquire( date_print, date = EndDate )
      call MessageNotify( 'M', module_name, '  EndDate      = %c', &
        & c1 = trim(date_print) )
    end if
    EndTimeValue_print = DCCalConvertByUnit( EndTime, 'sec', RestartTimeUnit ) ! (in)
    call MessageNotify( 'M', module_name, '  EndTime      = %f [%c]', &
      & d = (/ EndTimeValue_print /), c1 = trim(RestartTimeUnit) )
    call MessageNotify( 'M', module_name, '  DelTime      = %f [%c]', &
      & d = (/ DelTimeValue /), c1 = trim(DelTimeUnit) )
    call MessageNotify( 'M', module_name, '               = %f [%c]', &
      & d = (/ DelTime /), c1 = 'sec' )
    if ( cal_type /= 'user_defined' ) then
      call MessageNotify( 'M', module_name, '  Calendar     = %c', &
        & c1 = trim(cal_type) )
    else
      call DCCalDefault( cal_print ) ! (out)
      call MessageNotify( 'M', module_name, '  Calendar     = %c', &
        & c1 = trim(DCCalToChar(cal_print)) )
    end if
    call MessageNotify( 'M', module_name, '  PredictInt = %f [%c]', &
      & d = (/ PredictIntValue /), c1 = trim(PredictIntUnit) )
    call MessageNotify( 'M', module_name, '  CpuTimeMoniter = %b', &
      & l = (/ CpuTimeMoniter /) )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    timeset_inited = .true.
  end subroutine TimesetInit

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

  subroutine TimesetDelTimeHalf
    !
    ! è¨ˆç®—ã®åˆå›žã ã‘ã¯ã‚ªã‚¤ãƒ©ãƒ¼æ³•ã‚’ç”¨ã„ã‚‹ãŸã‚,
    ! ä¸€æ™‚çš„ã« Î”t ã‚’åŠåˆ†ã«ã—ã¾ã™.
    ! TimesetProgress ãŒå‘¼ã°ã‚ŒãŸæ®µéšŽã§ Î”t ã¯å…ƒã«æˆ»ã‚Šã¾ã™.
    !
    ! Delta t is reduced to half temporarily
    ! in order to use Euler method at initial step.
    ! Delta t is returned to default, when "TimesetProgress" is called.
    !

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

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

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !
    if ( flag_half ) return
    DelTime = DelTime / 2.0_DP
    flag_half = .true.

  end subroutine TimesetDelTimeHalf

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

  subroutine TimesetProgress
    !
    ! timeset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å†…ã®æ™‚åˆ»ã‚’é€²ã‚ã¾ã™.
    ! ã¾ãŸ, TimesetProgress#PredictIntStep ã§è¨å®šã•ã‚ŒãŸå€¤ã«å¿œã˜ã¦,
    ! ç¾åœ¨ã¾ã§ã®è¨ˆç®—æ™‚é–“ã¨è¨ˆç®—çµ‚äº†äºˆæ¸¬æ™‚åˆ»ã‚’è¡¨ç¤ºã—ã¾ã™.
    !
    ! Progress time configured in "timeset" module.
    ! And, computation time until now and
    ! predicted end of computation time are printed
    ! according to configured "TimesetProgress#PredictIntStep"
    !

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

    ! CPU æ™‚é–“è¨ˆæ¸¬
    ! CPU time monitor
    !
    use dc_clock, only: DCClockPredict, DCClockStop, DCClockClose, &
      & operator(+), operator(-)

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

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    type(CLOCK):: clock_tmp

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

    ! Î”t ã‚’å…ƒã«æˆ»ã™.
    ! Delta t is returned to default
    !
    if ( flag_half ) then
      DelTime = DelTimeSave
      flag_half = .false.
    end if

    ! çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤º
    ! Print predicted end time
    !
    if ( .not. TimeA - PredictPrevTime < PredictIntTime ) then
      PredictPrevTime = PredictPrevTime + PredictIntTime
      if ( CpuTimeMoniter ) then
        clock_tmp = clocks(1)
        call DCClockStop( clock_tmp ) ! (in)
        call DCClockPredict( &
          & clock_tmp, &
          & real( ( TimeA - RestartTime ) / ( ( EndTime + DelTimeSave ) - RestartTime ) ) ) ! (in)
        call DCClockClose( clock_tmp ) ! (in)
      end if
    end if

    ! æ™‚åˆ»ã®é€²è¡Œ
    ! Progress time
    !
    TimeB = TimeB + DelTime
    TimeN = TimeN + DelTime
    TimeA = TimeA + DelTime
  end subroutine TimesetProgress

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

  subroutine TimesetClose
    !
    ! è¨ˆç®—æ™‚é–“ã®ç·è¨ˆã‚’è¡¨ç¤ºã—ã¾ã™.
    !
    ! Total computation time is printed.

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

    ! CPU æ™‚é–“è¨ˆæ¸¬
    ! CPU time monitor
    !
    use dc_clock, only: DCClockStop, DCClockResult, DCClockSetName, &
      & operator(+), operator(-)

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    integer:: i               ! clocks, clocks_name ç”¨ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop for "clocks", "clocks_name"

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

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

    if ( .not. CpuTimeMoniter ) return

    ! CPU æ™‚é–“è¨ˆæ¸¬çµ‚äº† (ãƒ¢ãƒ‡ãƒ«å…¨ä½“)
    ! Stop CPU time monitoring (for entire model)
    !
    call DCClockStop( clocks(1) ) ! (in)

    ! ã€Œãã®ä»–ã€ã® CPU æ™‚é–“ã‚’ç®—å‡º
    ! Calculate CPU time of "Others"
    !
    clocks(clk_proc_num + 1) = clocks(1)
    do i = 2, clk_proc_num
      clocks(clk_proc_num + 1) = clocks(clk_proc_num + 1) - clocks(i)
    end do
    call DCClockSetName( clocks(clk_proc_num + 1), 'others' )

    ! CPU æ™‚é–“ã®ç·è¨ˆã‚’è¡¨ç¤º
    ! Print total CPU time
    !
    call DCClockResult( &
      & clocks(2:clk_proc_num + 1), total_auto = .true. ) ! (in)

  end subroutine TimesetClose

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

  subroutine TimesetSetTimeN(TimeNSet)
    !
    ! TimeN ã®å†è¨å®šã‚’è¡Œã„ã¾ã™.
    ! è‡ªå‹•çš„ã« TimeB, TimeA, EndTime ã«ã¤ã„ã¦ã‚‚
    ! å†è¨å®šã‚’è¡Œã„ã¾ã™.
    !
    ! TimesetInit ãŒæ—¢ã«å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒå‰æã§ã™.
    ! TimesetInit ãŒå‘¼ã°ã‚Œã‚‹å‰ã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ãŒå‘¼ã°ã‚ŒãŸå ´åˆ,
    ! ä½•ã‚‚ã›ãšã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã¯çµ‚äº†ã—ã¾ã™.
    !
    ! "TimeN" is reconfigured.
    ! "TimeB", "TimeA", "EndTime" are reconfigured automatically.
    !
    ! "TimesetInit" must be called before this subroutine is called.
    ! If "TimesetInit" is not called previously, this subroutine
    ! is finished with no changes.
    !

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

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

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

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

    real(DP), intent(in):: TimeNSet
                              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ».
                              ! Time of step $ t $.

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    real(DP):: EndTimeValue_print

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

    if ( .not. timeset_inited ) return

    ! TimeN ãŒè² ã®å ´åˆã€ã‚¨ãƒ©ãƒ¼ã‚’ç™ºç”Ÿ
    ! Cause an error, if TimeN is negative
    !
    if ( TimeN < 0.0 ) then
      call MessageNotify( 'E', module_name, &
        & 'TimeN=<%f [sec]> must be positive', &
        & d = (/ TimeNSet /) )
    end if

    ! å„ã‚¿ã‚¤ãƒ ã‚¹ãƒ†ãƒƒãƒ—ã®æ™‚åˆ»ã®è¨å®š
    ! Reconfigure time on each time step
    !
    TimeN = TimeNSet
    TimeB = TimeN - DelTime
    TimeA = TimeN + DelTime

    ! å‰å›žã®çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºæ™‚é–“ã®å†è¨å®š
    ! Reconfigure Time when predicted end time is output previously
    !
    PredictPrevTime = TimeN - DelTime

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Reconfigure Time Messages -----' )
    call MessageNotify( 'M', module_name, '  TimeB  = %f [sec]', &
      & d = (/ TimeB /) )
    call MessageNotify( 'M', module_name, '  TimeN  = %f [sec]', &
      & d = (/ TimeN /) )
    call MessageNotify( 'M', module_name, '  TimeA  = %f [sec]', &
      & d = (/ TimeA /) )
    if ( IntegPeriod > 0.0 ) then
      EndTimeValue_print = DCCalConvertByUnit( EndTime, 'sec', RestartTimeUnit ) ! (in)
      call MessageNotify( 'M', module_name, '  EndTime    = %f [%c]', &
        & d = (/ EndTimeValue_print /), c1 = trim(RestartTimeUnit) )
    end if

  end subroutine TimesetSetTimeN

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

  subroutine TimesetSetInitialDate( &
    & InitialYear, InitialMonth, InitialDay, InitialHour, InitialMin, InitialSec )
    !
    ! é–‹å§‹æ—¥æ™‚ã®å†è¨å®šã‚’è¡Œã„ã¾ã™.
    !
    ! TimesetInit ãŒæ—¢ã«å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒå‰æã§ã™.
    ! TimesetInit ãŒå‘¼ã°ã‚Œã‚‹å‰ã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ãŒå‘¼ã°ã‚ŒãŸå ´åˆ,
    ! ä½•ã‚‚ã›ãšã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã¯çµ‚äº†ã—ã¾ã™.
    !
    ! Start date is reconfigured.
    !
    ! "TimesetInit" must be called before this subroutine is called.
    ! If "TimesetInit" is not called previously, this subroutine
    ! is finished with no changes.
    !

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

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

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

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

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

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    real(DP):: EndTimeValue_print
    character(TOKEN):: date_print

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

    if ( .not. timeset_inited ) return

    ! "InitialDate" ã‚’å†è¨å®š
    ! Reconfigure "InitialDate"
    !
    call DCCalDateCreate( &
      & year  = InitialYear,   & ! (in)
      & month = InitialMonth,  & ! (in)
      & day   = InitialDay,    & ! (in)
      & hour  = InitialHour,   & ! (in)
      & min   = InitialMin,    & ! (in)
      & sec   = InitialSec,    & ! (in)
      & date  = InitialDate )  ! (out) optional

    ! "EndTime" ã®å†è¨å®š
    ! Reconfigure "EndTime"
    !
    if ( IntegPeriod < 0.0 ) then
      EndTime = DCCalDateDifference( &
        &         start_date = InitialDate, &  ! (in)
        &         end_date = EndDate )         ! (in)

      if ( .not. EndTime > 0.0 ) then
        call DCCalDateInquire( date_print, date = InitialDate )
        call MessageNotify('W', module_name, 'InitialDate=<%c>', c1 = trim(date_print) )
        call DCCalDateInquire( date_print, date = EndDate )
        call MessageNotify('W', module_name, 'EndDate=<%c>', c1 = trim(date_print) )
        call MessageNotify('E', module_name, '"EndTime" must be positive.')
      end if

    end if

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Reconfigure InitialDate Messages -----' )
    call DCCalDateInquire( date_print, date = InitialDate )
    call MessageNotify( 'M', module_name, '  InitialDate  = %c', &
      & c1 = trim(date_print) )
    if ( IntegPeriod < 0.0 ) then
      call DCCalDateInquire( date_print, date = EndDate )
      call MessageNotify( 'M', module_name, '  EndDate    = %c', &
        & c1 = trim(date_print) )

      EndTimeValue_print = DCCalConvertByUnit( EndTime, 'sec', RestartTimeUnit ) ! (in)
      call MessageNotify( 'M', module_name, '  EndTime    = %f [%c]', &
        & d = (/ EndTimeValue_print /), c1 = trim(RestartTimeUnit) )
    end if

  end subroutine TimesetSetInitialDate

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

  subroutine TimesetSetCalendar( cal_type, &       ! (in)
    & month_in_year, day_in_month, &               ! (in)
    & hour_in_day, min_in_hour, sec_in_min )       ! (in)
    !
    ! æš¦ã®å†è¨å®šã‚’è¡Œã„ã¾ã™.
    !
    ! TimesetInit ãŒæ—¢ã«å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒå‰æã§ã™.
    ! TimesetInit ãŒå‘¼ã°ã‚Œã‚‹å‰ã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ãŒå‘¼ã°ã‚ŒãŸå ´åˆ,
    ! ä½•ã‚‚ã›ãšã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã¯çµ‚äº†ã—ã¾ã™.
    !
    ! Calendar is reconfigured.
    !
    ! "TimesetInit" must be called before this subroutine is called.
    ! If "TimesetInit" is not called previously, this subroutine
    ! is finished with no changes.
    !

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

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

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

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

    character(*), intent(in):: cal_type
                              ! æš¦ã®ã‚¿ã‚¤ãƒ—.
    integer, intent(in):: month_in_year, day_in_month(:), hour_in_day, min_in_hour
    real(DP), intent(in):: sec_in_min
                              ! æš¦æƒ…å ±.
                              ! Information of Calendar.

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    character(TOKEN):: cal_type_print
    type(DC_CAL):: cal_print

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

    if ( .not. timeset_inited ) return

    ! é–‹å§‹æ—¥æ™‚ã®æƒ…å ±ã‚’è¨å®š
    !
    if ( cal_type /= 'user_defined' ) then
      call DCCalCreate( cal_type = cal_type )  ! (in)
    else
      call DCCalCreate( month_in_year, & ! (in)
        &               day_in_month , & ! (in)
        &               hour_in_day,   & ! (in)
        &               min_in_hour ,  & ! (in)
        &               sec_in_min )     ! (in)
    end if

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Reconfigure Calendar Messages -----' )
    call DCCalInquire( cal_type = cal_type_print ) ! (out) optional
    if ( cal_type_print /= 'user_defined' ) then
      call MessageNotify( 'M', module_name, '  Calendar   = %c', &
        & c1 = trim(cal_type_print) )
    else
      call DCCalDefault( cal_print ) ! (out)
      call MessageNotify( 'M', module_name, '  Calendar   = %c', &
        & c1 = trim(DCCalToChar(cal_print)) )
    end if

  end subroutine TimesetSetCalendar

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

  subroutine TimesetClockStart( name & ! (in)
    & )
    !
    ! ãƒ—ãƒã‚°ãƒ©ãƒ å˜ä½ (ä¸»ã«ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‚’æƒ³å®š) ã”ã¨ã®æ™‚é–“è¨ˆæ¸¬ã‚’é–‹å§‹ã—ã¾ã™.
    !
    ! Start measurement of computation time by program unit
    ! (expected modules).

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

    ! CPU æ™‚é–“è¨ˆæ¸¬
    ! CPU time monitor
    !
    use dc_clock, only: DCClockCreate, DCClockStart

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    character(*), intent(in):: name
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Name of module

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: i               ! clocks, clocks_name ç”¨ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop for "clocks", "clocks_name"

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

    if ( .not. CpuTimeMoniter ) return

    do i = 1, clk_proc_num
      if ( trim(clocks_name(i)) == trim(name) ) then
        call DCClockStart( clocks(i) ) ! (in)
        return
      end if
    end do

    call DCClockCreate( clocks(clk_proc_num + 1), name ) ! (in)
    call DCClockStart( clocks(clk_proc_num + 1) ) ! (in)
    clocks_name(clk_proc_num + 1) = name
    clk_proc_num = clk_proc_num + 1

  end subroutine TimesetClockStart

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

  subroutine TimesetClockStop( name & ! (in)
    & )
    !
    ! ãƒ—ãƒã‚°ãƒ©ãƒ å˜ä½ (ä¸»ã«ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‚’æƒ³å®š) ã”ã¨ã®æ™‚é–“è¨ˆæ¸¬ã‚’ä¸€æ™‚åœæ¢ã—ã¾ã™.
    !
    ! Pause measurement of computation time by program unit
    ! (expected modules).

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

    ! CPU æ™‚é–“è¨ˆæ¸¬
    ! CPU time monitor
    !
    use dc_clock, only: DCClockStop

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    character(*), intent(in):: name
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Name of module

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: i               ! clocks, clocks_name ç”¨ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop for "clocks", "clocks_name"

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

    if ( .not. CpuTimeMoniter ) return

    do i = 1, clk_proc_num
      if ( trim(clocks_name(i)) == trim(name) ) then
        call DCClockStop( clocks(i) ) ! (in)
        return
      end if
    end do

    call MessageNotify( 'W', module_name, ' name "%c" is not found in "TimesetClockStop"', c1 = trim(name) )

  end subroutine TimesetClockStop

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

  subroutine TimeValidCheck( &
    & RestartTimeChk, EndTimeChk, DelTimeChk, PredictIntTimeChk & ! (in)
    & )
    !
    ! æ™‚åˆ»æƒ…å ±ã«ã¤ã„ã¦ã®æœ‰åŠ¹æ€§ã‚’ãƒã‚§ãƒƒã‚¯ã—ã¾ã™.
    !
    ! Check validation about infomation time
    !

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

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

    real(DP), intent(in):: RestartTimeChk
                              ! ãƒªã‚¹ã‚¿ãƒ¼ãƒˆé–‹å§‹æ™‚åˆ».
                              ! Restart time of calculation
    real(DP), intent(in):: EndTimeChk
                              ! è¨ˆç®—çµ‚äº†æ™‚åˆ».
                              ! End time of calculation
    real(DP), intent(in):: DelTimeChk
                              ! $ \Delta t $ [s]
    real(DP), intent(in):: PredictIntTimeChk
                              ! çµ‚äº†äºˆæ¸¬æ—¥æ™‚è¡¨ç¤ºé–“éš”.
                              ! Interval of predicted end time output

    ! å°å—ç”¨ä½œæ¥å¤‰æ•°
    ! Work variables for print
    !
    real(DP):: RestartTimeValue_print
    real(DP):: EndTimeValue_print
    real(DP):: DelTimeValue_print
    real(DP):: PredictIntValue_print

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

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

    if ( .not. 0.0_DP < ( EndTimeChk - RestartTimeChk ) ) then
      RestartTimeValue_print = DCCalConvertByUnit( RestartTimeChk, 'sec', RestartTimeUnit ) ! (in)
      EndTimeValue_print = DCCalConvertByUnit( EndTimeChk, 'sec', RestartTimeUnit ) ! (in)

      call MessageNotify( 'E', module_name, &
        & 'RestartTime=<%f[%c]> is later than EndTime=<%f[%c]>', &
        & d = (/ RestartTimeValue_print, EndTimeValue_print /), &
        & c1 = trim(RestartTimeUnit), c2 = trim(RestartTimeUnit) )
    end if

    if ( DelTimeChk > ( EndTimeChk - RestartTimeChk ) ) then
      RestartTimeValue_print = DCCalConvertByUnit( RestartTimeChk, 'sec', RestartTimeUnit ) ! (in)
      EndTimeValue_print = DCCalConvertByUnit( EndTimeChk, 'sec', RestartTimeUnit ) ! (in)
      DelTimeValue_print = DCCalConvertByUnit( DelTimeChk, 'sec', DelTimeUnit ) ! (in)
      call MessageNotify( 'E', module_name, &
        & 'DelTime=<%f[%c]> is larger than ' // &
        & 'EndTime=<%f[%c]> - RestartTime=<%f[%c]>.', &
        & d = (/ DelTimeValue_print, EndTimeValue_print, RestartTimeValue_print /), &
        & c1 = trim(DelTimeUnit), &
        & c2 = trim(RestartTimeUnit), c3 = trim(RestartTimeUnit) )
    end if

    if ( .not. DelTimeChk > 0.0_DP ) then
      DelTimeValue_print = DCCalConvertByUnit( DelTimeChk, 'sec', DelTimeUnit ) ! (in)
      call MessageNotify( 'E', module_name, &
        & 'DelTime=<%f[%c]> must be more than 0.', &
        & d = (/ DelTimeValue_print /), &
        & c1 = trim(DelTimeUnit) )
    end if

    if ( .not. PredictIntTimeChk > 0.0_DP ) then
      PredictIntValue_print = DCCalConvertByUnit( PredictIntTimeChk, 'sec', PredictIntUnit ) ! (in)
      call MessageNotify( 'E', module_name, &
        & 'PredictInt=<%f[%c]> must be more than 0.', &
        & d = (/ PredictIntValue_print /), &
        & c1 = trim(PredictIntUnit) )
    end if

  end subroutine TimeValidCheck

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

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

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

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

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

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

  end subroutine InitCheck

end module timeset