!= ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®æš¦æƒ…å ±ã®å–å¾—
!= Get information of default calendar
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: dccaldefault.f90,v 1.2 2009-10-17 14:08:58 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 DCCalDefault1( cal )
  !
  ! dc_calendar ã«ãŠã„ã¦ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆè¨å®šã¨ãªã£ã¦ã„ã‚‹æš¦ã‚’è¿”ã—ã¾ã™.
  ! ã“ã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®æš¦ã¯, dc_calendar_generic#DCCalCreate
  ! ã«ãŠã„ã¦çœç•¥å¯èƒ½å¼•æ•° *cal* ã‚’çœç•¥ã—ã¦æŒ‡å®šã•ã‚ŒãŸæš¦ãŒè©²å½“ã—ã¾ã™.
  ! ãŸã ã— DCCalCreate ãŒå‘¼ã³å‡ºã•ã‚Œã¦ã„ãªã„å ´åˆã«ã¯ã‚°ãƒ¬ã‚´ãƒªã‚ªæš¦ã¨ãªã‚Šã¾ã™.
  !
  ! Default calender in "dc_calendar" is returned.
  ! The default calender is set by dc_calendar_generic#DCCalCreate
  ! without optional argument *cal*.
  ! If the DCCalCreate is called, the calendar becomes Gregorian calendar.
  !
  use dc_calendar_types, only: DC_CAL, &
    & CAL_CYCLIC, CAL_NOLEAP, CAL_JULIAN, CAL_GREGORIAN, CAL_360DAY
  use dc_calendar_internal, only: default_cal, default_cal_set
  use dc_message, only: MessageNotify
  use dc_string, only: LChar
  use dc_trace, only: BeginSub, EndSub
  use dc_error, only: StoreError, DC_NOERR, DC_EALREADYINIT, DC_EBADCALTYPE
  use dc_types, only: STRING, DP
  implicit none
  type(DC_CAL), intent(out):: cal
                              ! æš¦æƒ…å ±ã‚’åŽã‚ãŸã‚ªãƒ–ã‚¸ã‚§ã‚¯ãƒˆ.
                              !
                              ! An object that stores information of
                              ! calendar.

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

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

!!$  ! åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
!!$  ! Check initialization
!!$  !
!!$  if ( calp % initialized ) then
!!$    stat = DC_EALREADYINIT
!!$    cause_c = 'DC_CAL'
!!$    goto 999
!!$  end if

  ! å„è¦ç´ ã¸ã®å€¤ã®è¨å®š
  ! Configure elements
  !
  cal % cal_type = calp % cal_type

  allocate( cal % day_in_month( calp % month_in_year ) )
  cal % month_in_year = calp % month_in_year
  cal % day_in_month  = calp % day_in_month
  cal % hour_in_day   = calp % hour_in_day
  cal % min_in_hour   = calp % min_in_hour
  cal % sec_in_min    = calp % sec_in_min

  ! çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
  ! Termination and Exception handling
  !
  cal % initialized = .true.
999 continue
  nullify( calp )
  call EndSub( subname )
end subroutine DCCalDefault1