!= æ—¥æ™‚ã®ç®—å‡º
!= Evaluate date
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: dccaldateeval.f90,v 1.6 2010-09-24 00:28:18 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2009-. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!
! ã“ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«è¨˜è¼‰ã•ã‚Œã‚‹æ‰‹ç¶šãç¾¤ã¯ dc_calendar ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‹ã‚‰æä¾›ã•ã‚Œã¾ã™.
!
! Procedures described in this file are provided from "dc_calendar" module.
!
subroutine DCCalDateEvalYMDHMS1( &
  & year, month, day, hour, min, sec, elapse_sec, cal, date, err )
  !
  ! æ—¥æ™‚ã®ç®—å‡ºã¨è¨å®šã‚’è¡Œã„ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹ "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°ã«æ—¥æ™‚ãŒ
  ! è¨å®šã•ã‚Œã¾ã™. ãã®å¾Œã®æ‰‹ç¶šãã§ *date* ã‚’çœç•¥ã—ãŸå ´åˆã«ã¯
  ! ã“ã®æ—¥æ™‚ãŒä½¿ç”¨ã•ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«æ—¥æ™‚ãŒè¨å®šã•ã‚Œã¾ã™.
  ! ãã®æ—¥æ™‚ã‚’ä½¿ç”¨ã™ã‚‹å ´åˆ, æ‰‹ç¶šãã«ãã® "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°
  ! ã‚’ä¸Žãˆã¦ãã ã•ã„.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽç§’æ•° *elapse_sec*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate and set date.
  !
  ! If an optional argument *date* is omitted,
  ! the date setting is stored to a "dc_calendar_types#DC_CAL_DATE"
  ! variable that is saved in the "dc_calendar".
  ! When *date* is omitted in subsequent procedures, the internal date
  ! is used.
  ! If *date* is not omitted, the settings is stored to the *date*.
  ! In order to use the date setting, use the "dc_calendar_types#DC_CAL_DATE"
  ! varieble to subsequent procedures.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed seconds *elapse_sec* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !

  use dc_calendar_types, only: DC_CAL, DC_CAL_DATE
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize
  use dc_calendar_generic, only: DCCalDateCreate, DCCalDateToChar, DCCalToChar
  use dc_message, only: MessageNotify
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, &
    & DC_EINCONSISTCALDATE, DC_EALREADYINIT, DC_EBADDATE, DC_ENEGATIVE
  use dc_types, only: STRING, DP, TOKEN
  use dc_types, only: DP
  implicit none
  integer, intent(in):: year  ! èµ·ç‚¹ã®å¹´. Year of origin.
  integer, intent(in):: month ! èµ·ç‚¹ã®æœˆ. Month of origin.
  integer, intent(in):: day   ! èµ·ç‚¹ã®æ—¥. Day of origin.
  integer, intent(in):: hour  ! èµ·ç‚¹ã®æ™‚. Hour of origin.
  integer, intent(in):: min   ! èµ·ç‚¹ã®åˆ†. Minute of origin.
  real(DP), intent(in):: sec  ! èµ·ç‚¹ã®ç§’. Second of origin.
  real(DP), intent(in):: elapse_sec
                              ! *year* ã€œ *sec* ã‹ã‚‰ã®çµŒéŽç§’æ•°.
                              ! Elapsed seconds from *year* -- *sec*
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  type(DC_CAL_DATE), intent(out), optional, target:: date
                              ! çµŒéŽæ™‚é–“å¾Œã®æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date and time after elapsed time.
  logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  integer:: wyear, wmonth, wday, whour, wmin
  real(DP):: wsec
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()
  character(STRING):: e_date_str, e_cal_str
  integer:: stat
  character(STRING):: cause_c
  character(*), parameter:: subname = 'DCCalDateEvalYMDHMS1'
continue
  call BeginSub( subname )
  stat = DC_NOERR
  cause_c = ''

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
!!$  if ( .not. datep % initialized ) then
!!$    stat = DC_ENOTINIT
!!$    cause_c = 'DC_CAL_DATE'
!!$    goto 999
!!$  end if

  if ( .not. calp % initialized ) then
    stat = DC_ENOTINIT
    cause_c = 'DC_CAL'
    goto 999
  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®å‚ç…§
  ! Refer elements
  !
  wyear  = year
  wmonth = month
  wday   = day
  whour  = hour
  wmin   = min
  wsec   = sec

  ! çµŒéŽæ™‚é–“(ç§’)ã®è¿½åŠ
  ! Add elapsed time (seconds)
  !
!!$  if ( elapse_sec < 0.0_DP ) then
!!$    stat = DC_ENEGATIVE
!!$    cause_c = 'elapse_sec'
!!$    goto 999
!!$  end if

  wsec = wsec + elapse_sec

  ! æ—¥æ™‚ã®æ£è¦åŒ–
  ! Normalize date and time
  !
  stat = dccaldate_normalize( wyear, wmonth, wday, whour, wmin, wsec, & ! (inout)
    &                         calp )                                    ! (in)
  if ( stat == DC_EINCONSISTCALDATE ) then
    e_cal_str = DCCalToChar( calp )
    e_date_str = DCCalDateToChar( wyear, wmonth, wday, whour, wmin, wsec, zone = "" )
    call MessageNotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
      & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
    goto 999
  end if

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ä½œæˆ
  ! Create an object
  !
  call DCCalDateCreate( &
    & wyear, wmonth, wday, whour, wmin, wsec, & ! (in)
    & datep, zone = "", err = err )             ! (out) optional
  if ( present(err) ) then
    if ( err ) then
      stat = DC_EBADDATE
      goto 999
    end if
  end if

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
999 continue
  nullify( calp, datep )
  call StoreError( stat, subname, err, cause_c )
  call EndSub( subname )
end subroutine DCCalDateEvalYMDHMS1

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

subroutine DCCalDateEvalYMDHMS2( &
  & year, month, day, hour, min, sec, elapse_time, units, cal, date, err )
  !
  ! æ—¥æ™‚ã®ç®—å‡ºã¨è¨å®šã‚’è¡Œã„ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹ "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°ã«æ—¥æ™‚ãŒ
  ! è¨å®šã•ã‚Œã¾ã™. ãã®å¾Œã®æ‰‹ç¶šãã§ *date* ã‚’çœç•¥ã—ãŸå ´åˆã«ã¯
  ! ã“ã®æ—¥æ™‚ãŒä½¿ç”¨ã•ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«æ—¥æ™‚ãŒè¨å®šã•ã‚Œã¾ã™.
  ! ãã®æ—¥æ™‚ã‚’ä½¿ç”¨ã™ã‚‹å ´åˆ, æ‰‹ç¶šãã«ãã® "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°
  ! ã‚’ä¸Žãˆã¦ãã ã•ã„.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽæ™‚é–“ *elapse_time*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate and set date.
  !
  ! If an optional argument *date* is omitted,
  ! the date setting is stored to a "dc_calendar_types#DC_CAL_DATE"
  ! variable that is saved in the "dc_calendar".
  ! When *date* is omitted in subsequent procedures, the internal date
  ! is used.
  ! If *date* is not omitted, the settings is stored to the *date*.
  ! In order to use the date setting, use the "dc_calendar_types#DC_CAL_DATE"
  ! varieble to subsequent procedures.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed time *elapse_time* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !

  use dc_calendar_types, only: DC_CAL, DC_CAL_DATE, &
    & UNIT_SYMBOL_DAY, UNIT_SYMBOL_HOUR, UNIT_SYMBOL_MIN, UNIT_SYMBOL_SEC
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize, dccaldate_str2usym
  use dc_calendar_generic, only: DCCalDateCreate, DCCalDateToChar, DCCalToChar
  use dc_message, only: MessageNotify
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, &
    & DC_EINCONSISTCALDATE, DC_EALREADYINIT, DC_EBADDATE, DC_EBADUNIT, &
    & DC_ENEGATIVE
  use dc_types, only: STRING, DP, TOKEN
  use dc_types, only: DP
  implicit none
  integer, intent(in):: year  ! èµ·ç‚¹ã®å¹´. Year of origin.
  integer, intent(in):: month ! èµ·ç‚¹ã®æœˆ. Month of origin.
  integer, intent(in):: day   ! èµ·ç‚¹ã®æ—¥. Day of origin.
  integer, intent(in):: hour  ! èµ·ç‚¹ã®æ™‚. Hour of origin.
  integer, intent(in):: min   ! èµ·ç‚¹ã®åˆ†. Minute of origin.
  real(DP), intent(in):: sec  ! èµ·ç‚¹ã®ç§’. Second of origin.
  real(DP), intent(in):: elapse_time
                              ! *year* ã€œ *sec* ã‹ã‚‰ã®çµŒéŽæ™‚é–“.
                              ! å˜ä½ã¯ *unit* ã§æŒ‡å®šã™ã‚‹.
                              !
                              ! Elapsed time from *year* -- *sec*
                              ! Unit is specified as *unit*.
  character(*), intent(in):: units
                              ! *elapse_time* ã®å˜ä½.
                              !
                              ! Unit of *elapse_time*.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  type(DC_CAL_DATE), intent(out), optional, target:: date
                              ! çµŒéŽæ™‚é–“å¾Œã®æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date and time after elapsed time.
  logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  integer:: wyear, wmonth, wday, whour, wmin
  real(DP):: wsec
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()
  character(STRING):: e_date_str, e_cal_str
  integer:: tusym
  integer:: stat
  character(STRING):: cause_c
  character(*), parameter:: subname = 'DCCalDateEvalYMDHMS2'
continue
  call BeginSub( subname )
  stat = DC_NOERR
  cause_c = ''

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
!!$  if ( .not. datep % initialized ) then
!!$    stat = DC_ENOTINIT
!!$    cause_c = 'DC_CAL_DATE'
!!$    goto 999
!!$  end if

  if ( .not. calp % initialized ) then
    stat = DC_ENOTINIT
    cause_c = 'DC_CAL'
    goto 999
  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®å‚ç…§
  ! Refer elements
  !
  wyear  = year
  wmonth = month
  wday   = day
  whour  = hour
  wmin   = min
  wsec   = sec

  ! çµŒéŽæ™‚é–“(ç§’)ã®è¿½åŠ
  ! Add elapsed time (seconds)
  !
!!$  if ( elapse_time < 0.0_DP ) then
!!$    stat = DC_ENEGATIVE
!!$    cause_c = 'elapse_time'
!!$    goto 999
!!$  end if

  tusym = dccaldate_str2usym(units)
  select case(tusym)
  case(UNIT_SYMBOL_DAY)
    wsec = wsec + elapse_time * calp % hour_in_day &
      &                       * calp % min_in_hour &
      &                       * calp % sec_in_min
  case(UNIT_SYMBOL_HOUR)
    wsec = wsec + elapse_time * calp % min_in_hour &
      &                       * calp % sec_in_min
  case(UNIT_SYMBOL_MIN)
    wsec = wsec + elapse_time * calp % sec_in_min
  case(UNIT_SYMBOL_SEC)
    wsec = wsec + elapse_time
  case default
    cause_c = units
    call MessageNotify('W', subname, 'units=<%c> is invalid. (ONLY day,hrs,min,sec are valid)', &
      & c1 = trim(units) )
    stat = DC_EBADUNIT
    goto 999
  end select

  ! æ—¥æ™‚ã®æ£è¦åŒ–
  ! Normalize date and time
  !
  stat = dccaldate_normalize( wyear, wmonth, wday, whour, wmin, wsec, & ! (inout)
    &                         calp )                                    ! (in)
  if ( stat == DC_EINCONSISTCALDATE ) then
    e_cal_str = DCCalToChar( calp )
    e_date_str = DCCalDateToChar( wyear, wmonth, wday, whour, wmin, wsec, zone = "" )
    call MessageNotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
      & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
    goto 999
  end if

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ä½œæˆ
  ! Create an object
  !
  call DCCalDateCreate( &
    & wyear, wmonth, wday, whour, wmin, wsec, & ! (in)
    & datep, zone = "", err = err )             ! (out) optional
  if ( present(err) ) then
    if ( err ) then
      stat = DC_EBADDATE
      goto 999
    end if
  end if

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
999 continue
  nullify( calp, datep )
  call StoreError( stat, subname, err, cause_c )
  call EndSub( subname )
end subroutine DCCalDateEvalYMDHMS2

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

subroutine DCCalDateEvalID1( init_date, elapse_sec, cal, date, err )
  !
  ! æ—¥æ™‚ã®ç®—å‡ºã¨è¨å®šã‚’è¡Œã„ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹ "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°ã«æ—¥æ™‚ãŒ
  ! è¨å®šã•ã‚Œã¾ã™. ãã®å¾Œã®æ‰‹ç¶šãã§ *date* ã‚’çœç•¥ã—ãŸå ´åˆã«ã¯
  ! ã“ã®æ—¥æ™‚ãŒä½¿ç”¨ã•ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«æ—¥æ™‚ãŒè¨å®šã•ã‚Œã¾ã™.
  ! ãã®æ—¥æ™‚ã‚’ä½¿ç”¨ã™ã‚‹å ´åˆ, æ‰‹ç¶šãã«ãã® "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°
  ! ã‚’ä¸Žãˆã¦ãã ã•ã„.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽç§’æ•° *elapse_sec*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate and set date.
  !
  ! If an optional argument *date* is omitted,
  ! the date setting is stored to a "dc_calendar_types#DC_CAL_DATE"
  ! variable that is saved in the "dc_calendar".
  ! When *date* is omitted in subsequent procedures, the internal date
  ! is used.
  ! If *date* is not omitted, the settings is stored to the *date*.
  ! In order to use the date setting, use the "dc_calendar_types#DC_CAL_DATE"
  ! varieble to subsequent procedures.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed seconds *elapse_sec* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !

  use dc_calendar_types, only: DC_CAL, DC_CAL_DATE
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize
  use dc_calendar_generic, only: DCCalDateCreate, DCCalDateToChar, DCCalToChar
  use dc_message, only: MessageNotify
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, &
    & DC_EINCONSISTCALDATE, DC_EALREADYINIT, DC_EBADDATE, DC_ENEGATIVE
  use dc_types, only: STRING, DP, TOKEN
  use dc_types, only: DP
  implicit none
  type(DC_CAL_DATE), intent(in):: init_date
                              ! èµ·ç‚¹ã¨ãªã‚‹æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date of origin.
  real(DP), intent(in):: elapse_sec
                              ! *init_date* ã‹ã‚‰ã®çµŒéŽç§’æ•°.
                              ! Elapsed seconds from *init_date*.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  type(DC_CAL_DATE), intent(out), optional, target:: date
                              ! çµŒéŽæ™‚é–“å¾Œã®æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date and time after elapsed time.
  logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  integer:: wyear, wmonth, wday, whour, wmin
  real(DP):: wsec
  character(TOKEN):: wzone
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()
  character(STRING):: e_date_str, e_cal_str
  integer:: stat
  character(STRING):: cause_c
  character(*), parameter:: subname = 'DCCalDateEvalID1'
continue
  call BeginSub( subname )
  stat = DC_NOERR
  cause_c = ''

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
!!$  if ( .not. datep % initialized ) then
!!$    stat = DC_ENOTINIT
!!$    cause_c = 'DC_CAL_DATE'
!!$    goto 999
!!$  end if

  if ( .not. calp % initialized ) then
    stat = DC_ENOTINIT
    cause_c = 'DC_CAL'
    goto 999
  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®å‚ç…§
  ! Refer elements
  !
  wyear  = init_date % year
  wmonth = init_date % month
  wday   = init_date % day
  whour  = init_date % hour
  wmin   = init_date % min
  wsec   = init_date % sec
  wzone  = init_date % zone

  ! çµŒéŽæ™‚é–“(ç§’)ã®è¿½åŠ
  ! Add elapsed time (seconds)
  !
!!$  if ( elapse_sec < 0.0_DP ) then
!!$    stat = DC_ENEGATIVE
!!$    cause_c = 'elapse_sec'
!!$    goto 999
!!$  end if

  wsec = wsec + elapse_sec

  ! æ—¥æ™‚ã®æ£è¦åŒ–
  ! Normalize date and time
  !
  stat = dccaldate_normalize( wyear, wmonth, wday, whour, wmin, wsec, & ! (inout)
    &                         calp )                                    ! (in)
  if ( stat == DC_EINCONSISTCALDATE ) then
    e_cal_str = DCCalToChar( calp )
    e_date_str = DCCalDateToChar( wyear, wmonth, wday, whour, wmin, wsec, zone = "" )
    call MessageNotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
      & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
    goto 999
  end if

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ä½œæˆ
  ! Create an object
  !
  call DCCalDateCreate( &
    & wyear, wmonth, wday, whour, wmin, wsec, & ! (in)
    & datep, zone = wzone, err = err )          ! (out) optional
  if ( present(err) ) then
    if ( err ) then
      stat = DC_EBADDATE
      goto 999
    end if
  end if

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
999 continue
  nullify( calp, datep )
  call StoreError( stat, subname, err, cause_c )
  call EndSub( subname )
end subroutine DCCalDateEvalID1

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

subroutine DCCalDateEvalID2( init_date, elapse_time, units, cal, date, err )
  !
  ! æ—¥æ™‚ã®ç®—å‡ºã¨è¨å®šã‚’è¡Œã„ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹ "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°ã«æ—¥æ™‚ãŒ
  ! è¨å®šã•ã‚Œã¾ã™. ãã®å¾Œã®æ‰‹ç¶šãã§ *date* ã‚’çœç•¥ã—ãŸå ´åˆã«ã¯
  ! ã“ã®æ—¥æ™‚ãŒä½¿ç”¨ã•ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«æ—¥æ™‚ãŒè¨å®šã•ã‚Œã¾ã™.
  ! ãã®æ—¥æ™‚ã‚’ä½¿ç”¨ã™ã‚‹å ´åˆ, æ‰‹ç¶šãã«ãã® "dc_calendar_types#DC_CAL_DATE" åž‹ã®å¤‰æ•°
  ! ã‚’ä¸Žãˆã¦ãã ã•ã„.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽæ™‚é–“ *elapse_time*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate and set date.
  !
  ! If an optional argument *date* is omitted,
  ! the date setting is stored to a "dc_calendar_types#DC_CAL_DATE"
  ! variable that is saved in the "dc_calendar".
  ! When *date* is omitted in subsequent procedures, the internal date
  ! is used.
  ! If *date* is not omitted, the settings is stored to the *date*.
  ! In order to use the date setting, use the "dc_calendar_types#DC_CAL_DATE"
  ! varieble to subsequent procedures.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed time *elapse_time* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !
  use dc_calendar_types, only: DC_CAL, DC_CAL_DATE, &
    & UNIT_SYMBOL_DAY, UNIT_SYMBOL_HOUR, UNIT_SYMBOL_MIN, UNIT_SYMBOL_SEC
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize, dccaldate_str2usym
  use dc_calendar_generic, only: DCCalDateCreate, DCCalDateToChar, DCCalToChar
  use dc_message, only: MessageNotify
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, &
    & DC_EINCONSISTCALDATE, DC_EALREADYINIT, DC_EBADDATE, DC_EBADUNIT, &
    & DC_ENEGATIVE
  use dc_types, only: STRING, DP, TOKEN
  use dc_types, only: DP
  implicit none
  type(DC_CAL_DATE), intent(in):: init_date
                              ! èµ·ç‚¹ã¨ãªã‚‹æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date of origin.
  real(DP), intent(in):: elapse_time
                              ! *init_date* ã‹ã‚‰ã®çµŒéŽæ™‚é–“.
                              ! å˜ä½ã¯ *unit* ã§æŒ‡å®šã™ã‚‹.
                              !
                              ! Elapsed time from *init_date*.
                              ! Unit is specified as *unit*.
  character(*), intent(in):: units
                              ! *elapse_time* ã®å˜ä½.
                              !
                              ! Unit of *elapse_time*.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  type(DC_CAL_DATE), intent(out), optional, target:: date
                              ! çµŒéŽæ™‚é–“å¾Œã®æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date and time after elapsed time.
  logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  integer:: wyear, wmonth, wday, whour, wmin
  real(DP):: wsec
  character(TOKEN):: wzone
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()
  character(STRING):: e_date_str, e_cal_str
  integer:: tusym
  integer:: stat
  character(STRING):: cause_c
  character(*), parameter:: subname = 'DCCalDateEvalID2'
continue
  call BeginSub( subname )
  stat = DC_NOERR
  cause_c = ''

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
!!$  if ( .not. datep % initialized ) then
!!$    stat = DC_ENOTINIT
!!$    cause_c = 'DC_CAL_DATE'
!!$    goto 999
!!$  end if

  if ( .not. calp % initialized ) then
    stat = DC_ENOTINIT
    cause_c = 'DC_CAL'
    goto 999
  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®å‚ç…§
  ! Refer elements
  !
  wyear  = init_date % year
  wmonth = init_date % month
  wday   = init_date % day
  whour  = init_date % hour
  wmin   = init_date % min
  wsec   = init_date % sec
  wzone  = init_date % zone

  ! çµŒéŽæ™‚é–“(ç§’)ã®è¿½åŠ
  ! Add elapsed time (seconds)
  !
!!$  if ( elapse_time < 0.0_DP ) then
!!$    stat = DC_ENEGATIVE
!!$    cause_c = 'elapse_time'
!!$    goto 999
!!$  end if

  tusym = dccaldate_str2usym(units)
  select case(tusym)
  case(UNIT_SYMBOL_DAY)
    wsec = wsec + elapse_time * calp % hour_in_day &
      &                       * calp % min_in_hour &
      &                       * calp % sec_in_min
  case(UNIT_SYMBOL_HOUR)
    wsec = wsec + elapse_time * calp % min_in_hour &
      &                       * calp % sec_in_min
  case(UNIT_SYMBOL_MIN)
    wsec = wsec + elapse_time * calp % sec_in_min
  case(UNIT_SYMBOL_SEC)
    wsec = wsec + elapse_time
  case default
    cause_c = units
    call MessageNotify('W', subname, 'units=<%c> is invalid. (ONLY day,hrs,min,sec are valid)', &
      & c1 = trim(units) )
    stat = DC_EBADUNIT
    goto 999
  end select

  ! æ—¥æ™‚ã®æ£è¦åŒ–
  ! Normalize date and time
  !
  stat = dccaldate_normalize( wyear, wmonth, wday, whour, wmin, wsec, & ! (inout)
    &                         calp )                                    ! (in)
  if ( stat == DC_EINCONSISTCALDATE ) then
    e_cal_str = DCCalToChar( calp )
    e_date_str = DCCalDateToChar( wyear, wmonth, wday, whour, wmin, wsec, zone = "" )
    call MessageNotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
      & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
    goto 999
  end if

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ä½œæˆ
  ! Create an object
  !
  call DCCalDateCreate( &
    & wyear, wmonth, wday, whour, wmin, wsec, & ! (in)
    & datep, zone = wzone, err = err )          ! (out) optional
  if ( present(err) ) then
    if ( err ) then
      stat = DC_EBADDATE
      goto 999
    end if
  end if

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
999 continue
  nullify( calp, datep )
  call StoreError( stat, subname, err, cause_c )
  call EndSub( subname )
end subroutine DCCalDateEvalID2

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

subroutine DCCalDateEvalYM2YM1( &
  & year1, month1, day1, hour1, min1, sec1, &
  & elapse_sec, &
  & year2, month2, day2, hour2, min2, sec2, &
  & cal, err )
  !
  ! æ—¥æ™‚ã®ç®—å‡ºã¨è¨å®šã‚’è¡Œã„ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽç§’æ•° *elapse_sec*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate and set date.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed seconds *elapse_sec* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !
  use dc_calendar_types, only: DC_CAL, DC_CAL_DATE
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize
  use dc_calendar_generic, only: DCCalDateCreate, DCCalDateToChar, DCCalToChar
  use dc_message, only: MessageNotify
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, &
    & DC_EINCONSISTCALDATE, DC_EALREADYINIT, DC_EBADDATE, DC_ENEGATIVE
  use dc_types, only: STRING, DP, TOKEN
  use dc_types, only: DP
  implicit none
  integer, intent(in):: year1  ! èµ·ç‚¹ã®å¹´. Year of origin.
  integer, intent(in):: month1 ! èµ·ç‚¹ã®æœˆ. Month of origin.
  integer, intent(in):: day1   ! èµ·ç‚¹ã®æ—¥. Day of origin.
  integer, intent(in):: hour1  ! èµ·ç‚¹ã®æ™‚. Hour of origin.
  integer, intent(in):: min1   ! èµ·ç‚¹ã®åˆ†. Minute of origin.
  real(DP), intent(in):: sec1  ! èµ·ç‚¹ã®ç§’. Second of origin.
  real(DP), intent(in):: elapse_sec
                              ! *year1* ã€œ *sec1* ã‹ã‚‰ã®çµŒéŽç§’æ•°.
                              ! Elapsed seconds from *year1* -- *sec1*
  integer, intent(out):: year2  ! çµŒéŽæ™‚é–“å¾Œã®å¹´. Year after elapsed time.
  integer, intent(out):: month2 ! çµŒéŽæ™‚é–“å¾Œã®æœˆ. Month after elapsed time.
  integer, intent(out):: day2   ! çµŒéŽæ™‚é–“å¾Œã®æ—¥. Day after elapsed time.
  integer, intent(out):: hour2  ! çµŒéŽæ™‚é–“å¾Œã®æ™‚. Hour after elapsed time.
  integer, intent(out):: min2   ! çµŒéŽæ™‚é–“å¾Œã®åˆ†. Minute after elapsed time.
  real(DP), intent(out):: sec2  ! çµŒéŽæ™‚é–“å¾Œã®ç§’. Second after elapsed time.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  type(DC_CAL), pointer:: calp =>null()
  character(STRING):: e_date_str, e_cal_str
  integer:: stat
  character(STRING):: cause_c
  character(*), parameter:: subname = 'DCCalDateEvalYM2YM1'
continue
  call BeginSub( subname )
  stat = DC_NOERR
  cause_c = ''

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
!!$  if ( .not. datep % initialized ) then
!!$    stat = DC_ENOTINIT
!!$    cause_c = 'DC_CAL_DATE'
!!$    goto 999
!!$  end if

  if ( .not. calp % initialized ) then
    stat = DC_ENOTINIT
    cause_c = 'DC_CAL'
    goto 999
  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®å‚ç…§
  ! Refer elements
  !
  year2  = year1
  month2 = month1
  day2   = day1
  hour2  = hour1
  min2   = min1
  sec2   = sec1

  ! çµŒéŽæ™‚é–“(ç§’)ã®è¿½åŠ
  ! Add elapsed time (seconds)
  !
!!$  if ( elapse_sec < 0.0_DP ) then
!!$    stat = DC_ENEGATIVE
!!$    cause_c = 'elapse_sec'
!!$    goto 999
!!$  end if

  sec2 = sec2 + elapse_sec

  ! æ—¥æ™‚ã®æ£è¦åŒ–
  ! Normalize date and time
  !
  stat = dccaldate_normalize( year2, month2, day2, hour2, min2, sec2, & ! (inout)
    &                         calp )                                    ! (in)
  if ( stat == DC_EINCONSISTCALDATE ) then
    e_cal_str = DCCalToChar( calp )
    e_date_str = DCCalDateToChar( year2, month2, day2, hour2, min2, sec2, zone = "" )
    call MessageNotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
      & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
    goto 999
  end if

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
999 continue
  nullify( calp )
  call StoreError( stat, subname, err, cause_c )
  call EndSub( subname )
end subroutine DCCalDateEvalYM2YM1

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

subroutine DCCalDateEvalYM2YM2( &
  & year1, month1, day1, hour1, min1, sec1, &
  & elapse_time, units, &
  & year2, month2, day2, hour2, min2, sec2, &
  & cal, err )
  !
  ! æ—¥æ™‚ã®ç®—å‡ºã¨è¨å®šã‚’è¡Œã„ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽæ™‚é–“ *elapse_time*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate and set date.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed time *elapse_time* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !
  use dc_calendar_types, only: DC_CAL, DC_CAL_DATE, &
    & UNIT_SYMBOL_DAY, UNIT_SYMBOL_HOUR, UNIT_SYMBOL_MIN, UNIT_SYMBOL_SEC
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize, dccaldate_str2usym
  use dc_calendar_generic, only: DCCalDateCreate, DCCalDateToChar, DCCalToChar
  use dc_message, only: MessageNotify
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, &
    & DC_EINCONSISTCALDATE, DC_EALREADYINIT, DC_EBADDATE, DC_EBADUNIT, &
    & DC_ENEGATIVE
  use dc_types, only: STRING, DP, TOKEN
  use dc_types, only: DP
  implicit none

  integer, intent(in):: year1  ! èµ·ç‚¹ã®å¹´. Year of origin.
  integer, intent(in):: month1 ! èµ·ç‚¹ã®æœˆ. Month of origin.
  integer, intent(in):: day1   ! èµ·ç‚¹ã®æ—¥. Day of origin.
  integer, intent(in):: hour1  ! èµ·ç‚¹ã®æ™‚. Hour of origin.
  integer, intent(in):: min1   ! èµ·ç‚¹ã®åˆ†. Minute of origin.
  real(DP), intent(in):: sec1  ! èµ·ç‚¹ã®ç§’. Second of origin.
  real(DP), intent(in):: elapse_time
                              ! *year1* ã€œ *sec1* ã‹ã‚‰ã®çµŒéŽæ™‚é–“.
                              ! å˜ä½ã¯ *unit* ã§æŒ‡å®šã™ã‚‹.
                              !
                              ! Elapsed time from *year1* -- *sec1*
                              ! Unit is specified as *unit*.
  character(*), intent(in):: units
                              ! *elapse_time* ã®å˜ä½.
                              !
                              ! Unit of *elapse_time*.
  integer, intent(out):: year2  ! çµŒéŽæ™‚é–“å¾Œã®å¹´. Year after elapsed time.
  integer, intent(out):: month2 ! çµŒéŽæ™‚é–“å¾Œã®æœˆ. Month after elapsed time.
  integer, intent(out):: day2   ! çµŒéŽæ™‚é–“å¾Œã®æ—¥. Day after elapsed time.
  integer, intent(out):: hour2  ! çµŒéŽæ™‚é–“å¾Œã®æ™‚. Hour after elapsed time.
  integer, intent(out):: min2   ! çµŒéŽæ™‚é–“å¾Œã®åˆ†. Minute after elapsed time.
  real(DP), intent(out):: sec2  ! çµŒéŽæ™‚é–“å¾Œã®ç§’. Second after elapsed time.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  type(DC_CAL), pointer:: calp =>null()
  character(STRING):: e_date_str, e_cal_str
  integer:: tusym
  integer:: stat
  character(STRING):: cause_c
  character(*), parameter:: subname = 'DCCalDateEvalYM2YM1'
continue
  call BeginSub( subname )
  stat = DC_NOERR
  cause_c = ''

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
!!$  if ( .not. datep % initialized ) then
!!$    stat = DC_ENOTINIT
!!$    cause_c = 'DC_CAL_DATE'
!!$    goto 999
!!$  end if

  if ( .not. calp % initialized ) then
    stat = DC_ENOTINIT
    cause_c = 'DC_CAL'
    goto 999
  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®å‚ç…§
  ! Refer elements
  !
  year2  = year1
  month2 = month1
  day2   = day1
  hour2  = hour1
  min2   = min1
  sec2   = sec1

  ! çµŒéŽæ™‚é–“(ç§’)ã®è¿½åŠ
  ! Add elapsed time (seconds)
  !
!!$  if ( elapse_time < 0.0_DP ) then
!!$    stat = DC_ENEGATIVE
!!$    cause_c = 'elapse_time'
!!$    goto 999
!!$  end if

  tusym = dccaldate_str2usym(units)
  select case(tusym)
  case(UNIT_SYMBOL_DAY)
    sec2 = sec2 + elapse_time * calp % hour_in_day &
      &                       * calp % min_in_hour &
      &                       * calp % sec_in_min
  case(UNIT_SYMBOL_HOUR)
    sec2 = sec2 + elapse_time * calp % min_in_hour &
      &                       * calp % sec_in_min
  case(UNIT_SYMBOL_MIN)
    sec2 = sec2 + elapse_time * calp % sec_in_min
  case(UNIT_SYMBOL_SEC)
    sec2 = sec2 + elapse_time
  case default
    cause_c = units
    call MessageNotify('W', subname, 'units=<%c> is invalid. (ONLY day,hour,min,sec are valid)', &
      & c1 = trim(units) )
    stat = DC_EBADUNIT
    goto 999
  end select

  ! æ—¥æ™‚ã®æ£è¦åŒ–
  ! Normalize date and time
  !
  stat = dccaldate_normalize( year2, month2, day2, hour2, min2, sec2, & ! (inout)
    &                         calp )                                    ! (in)
  if ( stat == DC_EINCONSISTCALDATE ) then
    e_cal_str = DCCalToChar( calp )
    e_date_str = DCCalDateToChar( year2, month2, day2, hour2, min2, sec2, zone = "" )
    call MessageNotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
      & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
    goto 999
  end if

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
999 continue
  nullify( calp )
  call StoreError( stat, subname, err, cause_c )
  call EndSub( subname )
end subroutine DCCalDateEvalYM2YM2

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

function DCCalDateEvalSecOfYear1( elapse_sec, date, cal ) result(result)
  ! å¹´å§‹ã‚ã‹ã‚‰ã®é€šç§’ã‚’ç®—å‡ºã—ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹æ—¥æ™‚ãŒèµ·ç‚¹ã®æ—¥æ™‚ã¨ã—ã¦ç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæ—¥æ™‚ãŒ
  ! èµ·ç‚¹ã®æ—¥æ™‚ã¨ã—ã¦ç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽç§’æ•° *elapse_sec*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate second of year.
  !
  ! If an optional argument *date* is omitted,
  ! information of date that is stored in the "dc_calendar"
  ! is used as date of origin,
  ! If *date* is not omitted, information of the variable is used as
  ! date of origin.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed seconds *elapse_sec* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !
  use dc_calendar_types, only: DC_CAL_DATE, DC_CAL
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize, dccaldate_ym2d
  use dc_calendar_generic, only: DCCalDateInquire, DCCalDateEvalDayOfYear
  use dc_types, only: DP
  implicit none
  real(DP), intent(in):: elapse_sec
                              ! *date* ã‹ã‚‰ã®çµŒéŽç§’æ•°.
                              ! Elapsed seconds from *date*.
  type(DC_CAL_DATE), intent(in), optional, target:: date
                              ! èµ·ç‚¹ã¨ãªã‚‹æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date of origin.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  real(DP):: result
                              ! å¹´å§‹ã‚ã‹ã‚‰ã®é€šç§’.
                              ! Second of year.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  real(DP):: day_of_year
  integer:: stat
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()
  integer:: year, month, day, hour, min
  real(DP):: sec
continue

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
  result = 0.0
  if ( .not. datep % initialized ) return
  if ( .not. calp % initialized ) return

  ! çµŒéŽæ™‚é–“ã‚’ä¸ŽãˆãŸå ´åˆã®æ—¥æ™‚ã‚’å–å¾—
  ! Inquire date and time when elapse time is given
  !
  call DCCalDateInquire( year, month, day, hour, min, sec, & ! (out)
      & elapse_sec = elapse_sec, date = date , cal = calp )  ! (in)

  ! å¹´åˆã‚ã‹ã‚‰ã®é€šæ—¥ã‚’å–å¾—
  ! Day of year is inquire
  !
  stat = dccaldate_ym2d( year, month, day, calp, & ! (in)
    &                    day_of_year )             ! (out)

  ! é€šç§’ã¸å¤‰æ›
  ! Convert into sec of year
  !
  result = ( day_of_year - 1 ) * calp % hour_in_day &
      &                        * calp % min_in_hour &
      &                        * calp % sec_in_min  &
      &                 + hour * calp % min_in_hour &
      &                        * calp % sec_in_min  &
      &                 + min  * calp % sec_in_min  &
      &                 + sec

end function DCCalDateEvalSecOfYear1

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

function DCCalDateEvalDayOfYear1( elapse_sec, date, cal ) result(result)
  ! å¹´å§‹ã‚ã‹ã‚‰ã®é€šæ—¥ã‚’ç®—å‡ºã—ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹æ—¥æ™‚ãŒèµ·ç‚¹ã®æ—¥æ™‚ã¨ã—ã¦ç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæ—¥æ™‚ãŒ
  ! èµ·ç‚¹ã®æ—¥æ™‚ã¨ã—ã¦ç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽç§’æ•° *elapse_sec*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate day of year.
  !
  ! If an optional argument *date* is omitted,
  ! information of date that is stored in the "dc_calendar"
  ! is used as date of origin,
  ! If *date* is not omitted, information of the variable is used as
  ! date of origin.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed seconds *elapse_sec* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !
  use dc_calendar_types, only: DC_CAL_DATE, DC_CAL
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize, dccaldate_ym2d
  use dc_calendar_generic, only: DCCalDateInquire
  use dc_types, only: DP
  implicit none
  real(DP), intent(in):: elapse_sec
                              ! *date* ã‹ã‚‰ã®çµŒéŽç§’æ•°.
                              ! Elapsed seconds from *date*.
  type(DC_CAL_DATE), intent(in), optional, target:: date
                              ! èµ·ç‚¹ã¨ãªã‚‹æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date of origin.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  real(DP):: result
                              ! å¹´å§‹ã‚ã‹ã‚‰ã®é€šæ—¥.
                              ! Day of year.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  integer:: year, month, day, hour, min
  real(DP):: sec
  integer:: stat
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()

continue

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
  result = 0.0
  if ( .not. datep % initialized ) return
  if ( .not. calp % initialized ) return

  ! çµŒéŽæ™‚é–“ã‚’ä¸ŽãˆãŸå ´åˆã®æ—¥æ™‚ã‚’å–å¾—
  ! Inquire date and time when elapse time is given
  !
  call DCCalDateInquire( year, month, day, hour, min, sec, & ! (out)
      & elapse_sec = elapse_sec, date = date , cal = calp )  ! (in)

  ! å¹´åˆã‚ã‹ã‚‰ã®é€šæ—¥ã‚’å–å¾—
  ! Day of year is inquire
  !
  stat = dccaldate_ym2d( year, month, day, calp, & ! (in)
    &                    result )                  ! (out)

end function DCCalDateEvalDayOfYear1

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

function DCCalDateEvalSecOfDay1( elapse_sec, date, cal ) result(result)
  ! æ—¥å§‹ã‚ã‹ã‚‰ã®é€šç§’ã‚’ç®—å‡ºã—ã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *date* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, dc_calendar å†…éƒ¨ã§
  ! ä¿æŒã•ã‚Œã‚‹æ—¥æ™‚ãŒèµ·ç‚¹ã®æ—¥æ™‚ã¨ã—ã¦ç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *date* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæ—¥æ™‚ãŒ
  ! èµ·ç‚¹ã®æ—¥æ™‚ã¨ã—ã¦ç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! çœç•¥å¯èƒ½å¼•æ•° *cal* ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã«ã¯, çµŒéŽç§’æ•° *elapse_sec*
  ! ã®å¹´æœˆæ—¥æ™‚åˆ†ã¸ã®å¤‰æ›ã« dc_calendar å†…éƒ¨ã§ä¿æŒã•ã‚Œã‚‹æš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  ! *cal* ãŒçœç•¥ã•ã‚Œãªã„å ´åˆã«ã¯ãã®å¤‰æ•°ã«è¨å®šã•ã‚ŒãŸæš¦ãŒç”¨ã„ã‚‰ã‚Œã¾ã™.
  !
  ! Evaluate second of day.
  !
  ! If an optional argument *date* is omitted,
  ! information of date that is stored in the "dc_calendar"
  ! is used as date of origin,
  ! If *date* is not omitted, information of the variable is used as
  ! date of origin.
  !
  ! If an optional argument *cal* is omitted,
  ! information of calendar that is stored in the "dc_calendar"
  ! is used for conversion of elapsed seconds *elapse_sec* into
  ! year-month-day etc.
  ! If *cal* is not omitted, information of the variable is used.
  !
  use dc_calendar_types, only: DC_CAL_DATE, DC_CAL
  use dc_calendar_internal, only: default_cal, default_cal_set, default_date, &
    & dccaldate_normalize, dccaldate_ym2d
  use dc_calendar_generic, only: DCCalDateInquire
  use dc_types, only: DP
  implicit none
  real(DP), intent(in):: elapse_sec
                              ! *date* ã‹ã‚‰ã®çµŒéŽç§’æ•°.
                              ! Elapsed seconds from *date*.
  type(DC_CAL_DATE), intent(in), optional, target:: date
                              ! èµ·ç‚¹ã¨ãªã‚‹æ—¥æ™‚æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! date of origin.
  type(DC_CAL), intent(in), optional, target:: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.
  real(DP):: result
                              ! æ—¥å§‹ã‚ã‹ã‚‰ã®é€šç§’.
                              ! Second of day.

  ! ä½œæ¥å¤‰æ•°
  ! Work variables
  !
  integer:: stat
  type(DC_CAL_DATE), pointer:: datep =>null()
  type(DC_CAL), pointer:: calp =>null()
  integer:: year, month, day, hour, min
  real(DP):: sec
continue

  ! ã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆã®ãƒã‚¤ãƒ³ã‚¿å‰²ä»˜
  ! Associate pointer of an object
  !
  if ( present( date ) ) then
    datep => date
  else
    datep => default_date
  end if

  if ( present( cal ) ) then
    calp => cal
  else
    calp => default_cal
    if ( .not. calp % initialized ) call default_cal_set
  end if

  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
  ! Check initialization
  !
  result = 0.0
  if ( .not. datep % initialized ) return
  if ( .not. calp % initialized ) return

  ! çµŒéŽæ™‚é–“ã‚’ä¸ŽãˆãŸå ´åˆã®æ—¥æ™‚ã‚’å–å¾—
  ! Inquire date and time when elapse time is given
  !
  call DCCalDateInquire( year, month, day, hour, min, sec, & ! (out)
      & elapse_sec = elapse_sec, date = date , cal = calp )  ! (in)

  ! é€šç§’ã¸å¤‰æ›
  ! Convert into sec of year
  !
  result = &
      &                   hour * calp % min_in_hour &
      &                        * calp % sec_in_min  &
      &                 + min  * calp % sec_in_min  &
      &                 + sec

end function DCCalDateEvalSecOfDay1