!= 譎ょ綾邂｡逅�
!
!= 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    :: ﾎ杯 繧剃ｸ譎ら噪縺ｫ蜊雁�縺ｫ
  ! 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
    !
    ! 險育ｮ励�蛻晏屓縺�縺代�繧ｪ繧､繝ｩ繝ｼ豕輔ｒ逕ｨ縺�ｋ縺溘ａ,
    ! 荳譎ら噪縺ｫ ﾎ杯 繧貞濠蛻�↓縺励∪縺�.
    ! TimesetProgress 縺悟他縺ｰ繧後◆谿ｵ髫弱〒 ﾎ杯 縺ｯ蜈�↓謌ｻ繧翫∪縺�.
    !
    ! 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
    !

    ! ﾎ杯 繧貞�縺ｫ謌ｻ縺�.
    ! 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