!= 謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ (GFD 髮ｻ閼ｳ蛟ｶ讌ｽ驛ｨ髢狗匱縺ｮ謾ｾ蟆�Δ繝�Ν)
!
!= Radiation flux (radiation model developed by GFD Dennou Club)
!
! Authors::   Yoshiyuki O. Takahashi, Yasuhiro MORIKAWA, Yukiko YAMADA, Satoshi NODA
! Version::   $Id: rad_DennouAGCM.f90,v 1.3 2012/02/01 05:19:53 yot Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module rad_DennouAGCM
  !
  != 謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ (GFD 髮ｻ閼ｳ蛟ｶ讌ｽ驛ｨ髢狗匱縺ｮ謾ｾ蟆�Δ繝�Ν)
  !
  != Radiation flux (radiation model developed by GFD Dennou Club)
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! 貂ｩ蠎ｦ, 豈疲ｹｿ, 豌怜悸縺九ｉ, 謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ繧定ｨ育ｮ励☆繧区叛蟆�Δ繝�Ν縺ｧ縺�.
  !
  ! This is a radiation model that calculates radiation flux from
  ! temperature, specific humidity, and air pressure.
  !
  !== References
  !
  !  Numaguti, Atusi, 1992:
  !    辭ｱ蟶ｯ縺ｫ縺翫￠繧狗ｩ埼峇豢ｻ蜍輔�螟ｧ隕乗ｨ｡讒矩�縺ｫ髢｢縺吶ｋ謨ｰ蛟､螳滄ｨ�. Doctor thesis, 218pp. (Japanese)
  !
  !== Procedures List
  !
  ! RadDennouAGCMFlux     :: 謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ縺ｮ險育ｮ�
  ! RadDennouAGCMFinalize :: 邨ゆｺ��逅� (繝｢繧ｸ繝･繝ｼ繝ｫ蜀�Κ縺ｮ螟画焚縺ｮ蜑ｲ繧贋ｻ倥￠隗｣髯､)
  ! ------------                :: ------------
  ! RadDennouAGCMFlux     :: Calculate radiation flux
  ! RadDennouAGCMFinalize :: Termination (deallocate variables in this module)
  !
  !== NAMELIST
  !
  ! NAMELIST#rad_DennouAGCM_nml
  !

  ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
  !

  ! 譬ｼ蟄千せ險ｭ螳�
  ! Grid points settings
  !
  use gridset, only: imax, & ! 邨悟ｺｦ譬ｼ蟄千せ謨ｰ.
                             ! Number of grid points in longitude
    &                jmax, & ! 邱ｯ蠎ｦ譬ｼ蟄千せ謨ｰ.
                             ! Number of grid points in latitude
    &                kmax    ! 驩帷峩螻､謨ｰ.
                             ! Number of vertical level

  ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ蜈･蜃ｺ蜉�
  ! Restart data input/output
  !
  use restart_file_io, only: &
    & RstFileIntValue => IntValue, &
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ縺ｮ蜃ｺ蜉幃俣髫� (謨ｰ蛟､).
                              ! Interval of restart data output (numerical value)
    & RstFileIntUnit  => IntUnit, &
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ縺ｮ蜃ｺ蜉幃俣髫� (蜊倅ｽ�).
                              ! Interval of restart data output (unit)
    & RstFileIntTime  => IntTime
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ縺ｮ蜃ｺ蜉幃俣髫�.
                              ! Interval of restart data output

  ! 遞ｮ蛻･蝙九ヱ繝ｩ繝｡繧ｿ
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! 蛟咲ｲｾ蠎ｦ螳滓焚蝙�. Double precision.
    &                 STRING, &  ! 譁�ｭ怜�.       Strings.
    &                 TOKEN      ! 繧ｭ繝ｼ繝ｯ繝ｼ繝�.   Keywords.

  ! NAMELIST 繝輔ぃ繧､繝ｫ蜈･蜉帙↓髢｢縺吶ｋ繝ｦ繝ｼ繝�ぅ繝ｪ繝�ぅ
  ! Utilities for NAMELIST file input
  !
  use namelist_util, only: MaxNmlArySize
                              ! NAMELIST 縺九ｉ隱ｭ縺ｿ霎ｼ繧驟榊�縺ｮ譛螟ｧ繧ｵ繧､繧ｺ.
                              ! Maximum size of arrays loaded from NAMELIST

  ! 繝｡繝�そ繝ｼ繧ｸ蜃ｺ蜉�
  ! Message output
  !
  use dc_message, only: MessageNotify

  ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ蜃ｺ蜉�
  ! Restart data output
  !
  use gtool_history, only: GT_HISTORY

  ! 螳｣險譁� ; Declaration statements
  !
  implicit none
  private

  ! 蜈ｬ髢区焔邯壹″
  ! Public procedure
  !
  public:: RadDennouAGCMFlux
  public:: RadDennouAGCMInit
  public:: RadDennouAGCMFinalize

  ! 蜈ｬ髢句､画焚
  ! Public variables
  !
  logical, save :: rad_DennouAGCM_inited = .false.
                              ! 蛻晄悄險ｭ螳壹ヵ繝ｩ繧ｰ.
                              ! Initialization flag

  ! 髱槫�髢句､画焚
  ! Private variables
  !
  logical, save:: Old_Flux_saved = .false.
                              ! 荳蠎ｦ險育ｮ励＠縺溘ヵ繝ｩ繝�け繧ｹ繧剃ｿ晏ｭ倥＠縺溘％縺ｨ繧堤､ｺ縺吶ヵ繝ｩ繧ｰ.
                              ! Flag for saving of flux calculated once

  type(GT_HISTORY), save:: gthst_rst
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ逕ｨ gtool_history#GT_HISTORY 螟画焚.
                              ! "gtool_history#GT_HISTORY" variable for restart data
  real(DP), save:: PrevRstOutputTime
                              ! 蜑榊屓縺ｮ繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ蜃ｺ蜉帶凾髢�.
                              ! Previous output time of a restart file
  logical, save:: flag_rst_output_end
                              ! 險育ｮ玲怙邨よ凾蛻ｻ縺ｮ蜃ｺ蜉帛ｮ御ｺ��繝輔Λ繧ｰ.
                              ! Flag for completion of output at the end time of calculation
  logical, save:: flag_rst_input = .false.
                              ! 迴ｾ蝨ｨ縺ｮ菫晏ｭ伜､縺後Μ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺九ｉ隱ｭ縺ｿ霎ｼ縺ｾ繧後◆縺薙→繧堤､ｺ縺吶ヵ繝ｩ繧ｰ.
                              ! Flag that indicates that saved value is input from a restart file.

  ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ逕ｨ諠��ｱ
  ! Information for long wave flux
  !
  real(DP), save:: IntTimeLong
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励☆繧区凾髢馴俣髫�.
                              ! Interval time of long wave flux calculation
  real(DP), save:: PrevTimeLong
                              ! 蜑榊屓髟ｷ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励＠縺滓凾蛻ｻ.
                              ! Time when long wave flux is calculated
  real(DP), save:: DelTimeLongValue
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励☆繧区凾髢馴俣髫斐�謨ｰ蛟､.
                              ! Value of interval step of long wave flux calculation
  character(STRING), save:: DelTimeLongUnit
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励☆繧区凾髢馴俣髫斐�蜊倅ｽ�.
                              ! Unit of interval step of long wave flux calculation

  integer, save:: LongBandNum
                              ! 髟ｷ豕｢繝舌Φ繝画焚.
                              ! Number of long wave band
  real(DP), save:: LongAbsorpCoefQVap (1:MaxNmlArySize)
                              ! $ k_R $ . 豌ｴ縺ｮ蜷ｸ蜿惹ｿよ焚.
                              ! Absorption coefficient of water.
  real(DP), save:: LongAbsorpCoefDryAir (1:MaxNmlArySize)
                              ! $ \bar{k}_R $ . 遨ｺ豌励�蜷ｸ蜿惹ｿよ焚.
                              ! Absorption coefficient of air.
  real(DP), save:: LongBandWeight (1:MaxNmlArySize)
                              ! 繝舌Φ繝峨え繧ｧ繧､繝�.
                              ! Band weight.
  real(DP), save:: LongPathLengthFact
                              ! 蜈芽ｷｯ髟ｷ縺ｮ繝輔ぃ繧ｯ繧ｿ.
                              ! Factor of optical length

  real(DP), allocatable, save:: xy_TempSave (:,:)
                              ! $ T $ .     貂ｩ蠎ｦ (菫晏ｭ倡畑). Temperature (for save)
  real(DP), allocatable, save:: xyr_RadLUwFluxSave (:,:,:)
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ (菫晏ｭ倡畑).
                              ! Upward long wave flux (for save)
  real(DP), allocatable, save:: xyr_RadLDwFluxSave (:,:,:)
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ (菫晏ｭ倡畑).
                              ! Downward long wave flux (for save)
  real(DP), allocatable, save:: xyra_DelRadLUwFluxSave (:,:,:,:)
                              ! 髟ｷ豕｢蝨ｰ陦ｨ貂ｩ蠎ｦ螟牙喧 (菫晏ｭ倡畑).
                              !
  real(DP), allocatable, save:: xyra_DelRadLDwFluxSave (:,:,:,:)
                              ! 髟ｷ豕｢蝨ｰ陦ｨ貂ｩ蠎ｦ螟牙喧 (菫晏ｭ倡畑).
                              !

  ! 遏ｭ豕｢繝輔Λ繝�け繧ｹ逕ｨ諠��ｱ
  ! Information for short wave flux
  !
  real(DP), save:: SolarConst
                              ! 螟ｪ髯ｽ螳壽焚.
                              ! Solar constant.
  real(DP), save:: IntTimeShort
                              ! 遏ｭ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励☆繧区凾髢馴俣髫�.
                              ! Interval time of short wave flux calculation
  real(DP), save:: PrevTimeShort
                              ! 蜑榊屓遏ｭ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励＠縺滓凾蛻ｻ
                              ! Time when short wave flux is calculated
  real(DP), save:: DelTimeShortValue
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励☆繧区凾髢馴俣髫斐�謨ｰ蛟､.
                              ! Value of interval step of short wave (insolation) flux calculation
  character(STRING), save:: DelTimeShortUnit
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励☆繧区凾髢馴俣髫斐�蜊倅ｽ�.
                              ! Unit of interval step of short wave (insolation) flux calculation

  integer, save:: ShortBandNum
                              ! 遏ｭ豕｢繝舌Φ繝画焚.
                              ! Number of short wave band
  real(DP), save:: ShortAbsorpCoefQVap (1:MaxNmlArySize)
                              ! $ k_S $ . 豌ｴ縺ｮ蜷ｸ蜿惹ｿよ焚.
                              ! Absorption coefficient of water.
  real(DP), save:: ShortAbsorpCoefDryAir (1:MaxNmlArySize)
                              ! $ \bar{k}_S $ . 遨ｺ豌励�蜷ｸ蜿惹ｿよ焚.
                              ! Absorption coefficient of air.
  real(DP), save:: ShortBandWeight (1:MaxNmlArySize)
                              ! 繝舌Φ繝峨え繧ｧ繧､繝�.
                              ! Band weight.
  real(DP), save:: ShortSecScat
                              ! 謨｣荵ｱ縺ｮ $ \sec \zeta $ .
                              ! $ \sec \zeta $ of scattering
  real(DP), save:: ShortAtmosAlbedo
                              ! 螟ｧ豌励い繝ｫ繝吶ラ.
                              ! Albedo of air.

  real(DP), allocatable, save:: xyr_RadSUwFluxSave (:,:,:)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ (菫晏ｭ倡畑).
                              ! Upward short wave (insolation) flux (for save)
  real(DP), allocatable, save:: xyr_RadSDwFluxSave (:,:,:)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ (菫晏ｭ倡畑).
                              ! Downward short wave (insolation) flux (for save)

  ! 遏ｭ豕｢蜈･蟆�畑諠��ｱ
  ! Information for short wave incoming
  !
  real(DP), allocatable, save:: xy_IncomRadSFlux (:,:)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ.
                              ! Short wave (insolation) flux
  real(DP), allocatable, save:: xy_InAngle (:,:)
                              ! sec (蜈･蟆�ｧ�).
                              ! sec (angle of incidence)

  character(*), parameter:: module_name = 'rad_DennouAGCM'
                              ! 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ蜷咲ｧｰ.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: rad_DennouAGCM.f90,v 1.3 2012/02/01 05:19:53 yot Exp $'
                              ! 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ繝舌�繧ｸ繝ｧ繝ｳ
                              ! Module version

contains

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

  subroutine RadDennouAGCMFlux(                  &
    & xyz_Temp, xyz_QVap, xyr_Press,             & ! (in)
    & xy_SurfTemp, xy_SurfAlbedo,                & ! (in)
    & xyr_RadSUwFlux, xyr_RadSDwFlux,            & ! (out)
    & xyr_RadLUwFlux, xyr_RadLDwFlux,            & ! (out)
    & xyra_DelRadLUwFlux, xyra_DelRadLDwFlux     & ! (out)
    & )
    !
    ! 貂ｩ蠎ｦ, 豈疲ｹｿ, 豌怜悸縺九ｉ, 謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ繧定ｨ育ｮ励＠縺ｾ縺�.
    !
    ! Calculate radiation flux from temperature, specific humidity, and
    ! air pressure.
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 遏ｭ豕｢蜈･蟆� (螟ｪ髯ｽ蜈･蟆�)
    ! Short wave (insolation) incoming
    !
    use rad_short_income, only: RadShortIncome

    ! 迚ｩ逅�ｮ壽焚險ｭ螳�
    ! Physical constants settings
    !
    use constants, only: Grav ! $ g $ [m s-2].
                              ! 驥榊鴨蜉�騾溷ｺｦ.
                              ! Gravitational acceleration

    ! 譎ょ綾邂｡逅�
    ! Time control
    !
    use timeset, only: &
      & TimeN, &              ! 繧ｹ繝�ャ繝� $ t $ 縺ｮ譎ょ綾.
                              ! Time of step $ t $.
      & EndTime, &            ! 險育ｮ礼ｵゆｺ�凾蛻ｻ.
                              ! End time of calculation
      & TimesetClockStart, TimesetClockStop

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ蜃ｺ蜉�
    ! Restart data output
    !
    use gtool_history, only: HistoryPut, HistorySetTime

    ! 繝�ヰ繝�げ逕ｨ繝ｦ繝ｼ繝�ぅ繝ｪ繝�ぅ
    ! Utilities for debug
    !
    use dc_trace, only: DbgMessage, BeginSub, EndSub

    ! 螳｣險譁� ; Declaration statements
    !
    implicit none

    real(DP), intent(in):: xyz_Temp  (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T $ .     貂ｩ蠎ｦ. Temperature
    real(DP), intent(in):: xyz_QVap  (0:imax-1, 1:jmax, 1:kmax)
                              ! $ q $ .     豈疲ｹｿ. Specific humidity
    real(DP), intent(in):: xyr_Press (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \hat{p} $ . 豌怜悸 (蜊頑紛謨ｰ繝ｬ繝吶Ν).
                              ! Air pressure (half level)
    real(DP), intent(in):: xy_SurfTemp (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ.
                              ! Surface temperature
    real(DP), intent(in):: xy_SurfAlbedo (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ繧｢繝ｫ繝吶ラ.
                              ! Surface albedo

    real(DP), intent(out):: xyr_RadSUwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ.
                              ! Upward shortwave (insolation) flux
    real(DP), intent(out):: xyr_RadSDwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ.
                              ! Downward shortwave (insolation) flux

    real(DP), intent(out):: xyr_RadLUwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ.
                              ! Upward longwave flux
    real(DP), intent(out):: xyr_RadLDwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ.
                              ! Downward longwave flux
    real(DP), intent(out):: xyra_DelRadLUwFlux (0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! 髟ｷ豕｢蝨ｰ陦ｨ貂ｩ蠎ｦ螟牙喧.
                              !
    real(DP), intent(out):: xyra_DelRadLDwFlux (0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! 髟ｷ豕｢蝨ｰ陦ｨ貂ｩ蠎ｦ螟牙喧.
                              !

    ! 菴懈･ｭ螟画焚
    ! Work variables
    !
    real(DP):: xyr_ColDenQVap (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \int_z^{\infty} \rho q \, dz $ .
                              ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ豌ｴ闥ｸ豌励�繧ｫ繝ｩ繝�蟇�ｺｦ.
                              ! Column density of water vapor above vertical level k.
    real(DP):: xyr_ColDenDryAir (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \int_z^{\infty} \rho \, dz $ .
                              ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ遨ｺ豌励�繧ｫ繝ｩ繝�蟇�ｺｦ.
                              ! Column density of air above vertical level k.
    integer:: k               ! 驩帷峩譁ｹ蜷代↓蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in vertical direction
    logical:: flag_rst_output
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ蜃ｺ蜉帙�繝輔Λ繧ｰ.
                              ! Flag for output of a restart file

    real(DP) :: xy_CosSZA(0:imax-1, 1:jmax)
    real(DP) :: DistFromStarScld
    real(DP) :: DiurnalMeanFactor

    integer:: i
    integer:: j

    real(DP) :: MaxError

    ! 螳溯｡梧枚 ; Executable statement
    !

    ! 蛻晄悄蛹也｢ｺ隱�
    ! Initialization check
    !
    if ( .not. rad_DennouAGCM_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    ! 險育ｮ玲凾髢楢ｨ域ｸｬ髢句ｧ�
    ! Start measurement of computation time
    !
    call TimesetClockStart( module_name )

    ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ繧ｫ繝ｩ繝�蟇�ｺｦ縺ｮ險育ｮ�
    ! Calculate column density above vertical level k
    !
    xyr_ColDenQVap  (:,:,kmax) = 0.
    xyr_ColDenDryAir(:,:,kmax) = 0.

    do k = kmax-1, 0, -1
      xyr_ColDenQVap(:,:,k) = &
        &   xyr_ColDenQVap(:,:,k+1) &
        & + xyz_QVap(:,:,k+1) &
        &   * ( xyr_Press(:,:,k) - xyr_Press(:,:,k+1) ) / Grav

      xyr_ColDenDryAir(:,:,k) = &
        &   xyr_ColDenDryAir(:,:,k+1) &
        & + ( xyr_Press(:,:,k) - xyr_Press(:,:,k+1) ) / Grav
    end do

    ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ縺ｮ邂怜�
    ! Calculate long wave flux
    !
    if ( ( TimeN - PrevTimeLong >= IntTimeLong ) .or. ( .not. Old_Flux_saved ) ) then

      if ( .not. Old_Flux_saved ) then
        PrevTimeLong = TimeN
      else
        PrevTimeLong = PrevTimeLong + IntTimeLong
      end if

      call LongFlux( &
        & xyz_Temp, xy_SurfTemp, xyr_ColDenQVap, xyr_ColDenDryAir,                & ! (in)
        & xyr_RadLUwFlux, xyr_RadLDwFlux, xyra_DelRadLUwFlux, xyra_DelRadLDwFlux  & ! (out)
        & )

    ! 蜑榊屓縺ｮ蛟､繧貞茜逕ｨ
    ! Use values in last time
    !
    else

      xyr_RadLUwFlux     = xyr_RadLUwFluxSave
      xyr_RadLDwFlux     = xyr_RadLDwFluxSave
      xyra_DelRadLUwFlux = xyra_DelRadLUwFluxSave
      xyra_DelRadLDwFlux = xyra_DelRadLDwFluxSave

      if ( .not. flag_rst_input ) then
        do k = 0, kmax
          xyr_RadLUwFlux(:,:,k) = xyr_RadLUwFlux(:,:,k) &
            & + xyra_DelRadLUwFlux(:,:,k,1) * ( xyz_Temp(:,:,1) - xy_TempSave )
          xyr_RadLDwFlux(:,:,k) = xyr_RadLDwFlux(:,:,k) &
            & + xyra_DelRadLDwFlux(:,:,k,1) * ( xyz_Temp(:,:,1) - xy_TempSave )

          xyra_DelRadLUwFlux(:,:,k,1) = xyra_DelRadLUwFlux(:,:,k,1) &
            &     / ( xy_TempSave**3 ) * ( xyz_Temp(:,:,1)**3 )
          xyra_DelRadLDwFlux(:,:,k,1) = xyra_DelRadLDwFlux(:,:,k,1) &
            &     / ( xy_TempSave**3 ) * ( xyz_Temp(:,:,1)**3 )
        end do
      else
        flag_rst_input = .false.
        call DbgMessage( '%c: restart data is used. ', c1 = module_name )
      end if

    end if

    ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ縺ｮ邂怜�
    ! Calculate short wave (insolation)
    !
    if ( ( TimeN - PrevTimeShort >= IntTimeShort ) .or. ( .not. Old_Flux_saved ) ) then

      if ( .not. Old_Flux_saved ) then
        PrevTimeShort = TimeN
      else
        PrevTimeShort = PrevTimeShort + IntTimeShort
      end if

      ! 遏ｭ豕｢蜈･蟆��險育ｮ�
      ! Calculate short wave (insolation) incoming radiation
      !
      call RadShortIncome(                       &
        & xy_CosZet         = xy_CosSZA,         & ! (out) optional
        & xy_InAngle        = xy_InAngle,        & ! (out) optional
        & DistFromStarScld  = DistFromStarScld,  &
        & DiurnalMeanFactor = DiurnalMeanFactor  &
        & )

      ! 遏ｭ豕｢繝輔Λ繝�け繧ｹ縺ｮ險育ｮ�
      ! Calculate short wave (insolation) flux
      !

      do j = 1, jmax
        do i = 0, imax-1
          if ( xy_CosSZA(i,j) > 0.0_DP ) then
            xy_IncomRadSFlux(i,j) = SolarConst / DistFromStarScld**2 * xy_CosSZA(i,j)
          else
            xy_IncomRadSFlux(i,j) = 0.0_DP
          end if
        end do
      end do
      ! Correction of incoming solar flux when diurnal mean insolation is assumed.
      ! If diurnal mean insolation is assumed, DiurnalMeanFactor = 1 / PI.
      ! If diurnal mean insolation is not assumed, DiurnalMeanFactor = 1.
      xy_IncomRadSFlux = xy_IncomRadSFlux * DiurnalMeanFactor

      ! 螟ｧ豌励い繝ｫ繝吶ラ縺ｮ閠��
      ! Taking atmospheric albedo into consideration
      !
      xy_IncomRadSFlux = xy_IncomRadSFlux * ( 1.0d0 - ShortAtmosAlbedo )

      call ShortFlux(                                      &
        & xyr_ColDenQVap, xyr_ColDenDryAir, xy_SurfAlbedo, & ! (in)
        & xy_IncomRadSFlux,                                & ! (in)
        & xyr_RadSUwFlux, xyr_RadSDwFlux                   & ! (out)
        & )

    else
      ! 蜑榊屓縺ｮ蛟､繧貞茜逕ｨ
      ! Use values in last time

      xyr_RadSUwFlux = xyr_RadSUwFluxSave
      xyr_RadSDwFlux = xyr_RadSDwFluxSave
    end if

    ! 莉雁屓險育ｮ励＠縺溷､繧剃ｿ晏ｭ�
    ! Save calculated values in this time
    !
    xy_TempSave            = xyz_Temp (:,:,1)

    xyr_RadSUwFluxSave     = xyr_RadSUwFlux
    xyr_RadSDwFluxSave     = xyr_RadSDwFlux

    xyr_RadLUwFluxSave     = xyr_RadLUwFlux
    xyr_RadLDwFluxSave     = xyr_RadLDwFlux
    xyra_DelRadLUwFluxSave = xyra_DelRadLUwFlux
    xyra_DelRadLDwFluxSave = xyra_DelRadLDwFlux

    if ( .not. Old_Flux_saved ) Old_Flux_saved = .true.

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ蜃ｺ蜉帙ち繧､繝溘Φ繧ｰ縺ｮ繝√ぉ繝�け
    ! Check output timing of a restart file
    !
!!
!! old code to be deleted
!!
!    flag_rst_output = ( TimeN - PrevRstOutputTime >= RstFileIntTime )
!    if ( TimeN >= EndTime .and. .not. flag_rst_output_end ) then
!      flag_rst_output = .true.
!      flag_rst_output_end = .true.
!    end if
!    flag_rst_output = ( .not. TimeN == PrevRstOutputTime ) .and. flag_rst_output

    if ( TimeN - PrevRstOutputTime >= RstFileIntTime ) then
       flag_rst_output = .true.
    else
       flag_rst_output = .false.
    end if
    if ( TimeN >= EndTime .and. .not. flag_rst_output_end ) then
      flag_rst_output = .true.
      flag_rst_output_end = .true.
    end if
    if ( ( .not. TimeN == PrevRstOutputTime ) .and. flag_rst_output ) then
       flag_rst_output = .true.
    else
       flag_rst_output = .false.
    end if

    if ( flag_rst_output ) then
      ! 谺｡蝗樒畑縺ｫ, 莉雁屓縺ｮ蜃ｺ蜉� (蟶梧悍) 譎ょ綾 繧剃ｿ晏ｭ�
      ! Save output time (expected) in this time, for next time
      !
      PrevRstOutputTime = PrevRstOutputTime + RstFileIntTime

      ! 譎ょ綾縺ｮ險ｭ螳�
      ! Set time
      !
      call HistorySetTime( timed = TimeN, history = gthst_rst )

      ! 繝��繧ｿ蜃ｺ蜉�
      ! Data output
      !
      call HistoryPut( &
        & 'PrevTimeLong', PrevTimeLong, & ! (in)
        & history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'PrevTimeShort', PrevTimeShort, & ! (in)
        & history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'SurfTemp', xy_TempSave, history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'RadLUwFlux', xyr_RadLUwFluxSave, history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'RadLDwFlux', xyr_RadLDwFluxSave, history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'RadSUwFlux', xyr_RadSUwFluxSave, history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'RadSDwFlux', xyr_RadSDwFluxSave, history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'DelRadLUwFlux', xyra_DelRadLUwFluxSave, history = gthst_rst ) ! (in)
      call HistoryPut( &
        & 'DelRadLDwFlux', xyra_DelRadLDwFluxSave, history = gthst_rst ) ! (in)

    end if

    ! 險育ｮ玲凾髢楢ｨ域ｸｬ荳譎ょ●豁｢
    ! Pause measurement of computation time
    !
    call TimesetClockStop( module_name )

  end subroutine RadDennouAGCMFlux

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

  subroutine LongFlux( &
    & xyz_Temp, xy_SurfTemp, xyr_ColDenQVap, xyr_ColDenDryAir,                & ! (in)
    & xyr_RadLUwFlux, xyr_RadLDwFlux, xyra_DelRadLUwFlux, xyra_DelRadLDwFlux  & ! (out)
    & )
    !
    ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ縺ｮ險育ｮ�
    !
    ! Calculate long wave flux
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 迚ｩ逅��謨ｰ蟄ｦ螳壽焚險ｭ螳�
    ! Physical and mathematical constants settings
    !
    use constants0, only: &
      & StB                   ! $ \sigma_{SB} $ .
                              ! 繧ｹ繝�ヵ繧｡繝ｳ繝懊Ν繝��繝ｳ螳壽焚.
                              ! Stefan-Boltzmann constant

    ! 謨｣荵ｱ繧堤┌隕悶＠縺滓叛蟆�ｼ晞＃譁ｹ遞句ｼ�
    ! Radiative transfer equation without considering scattering
    !
    use rad_rte_nonscat, only : RadRTENonScat

    ! 螳｣險譁� ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xyz_Temp (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T $ .     貂ｩ蠎ｦ. Temperature

    real(DP), intent(in):: xy_SurfTemp (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ.
                              ! Surface temperature
    real(DP), intent(in):: xyr_ColDenQVap (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \int_z^{\infty} \rho q \, dz $ .
                              ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ豌ｴ闥ｸ豌励�繧ｫ繝ｩ繝�蟇�ｺｦ.
                              ! Column density of water vapor above vertical level k.
    real(DP), intent(in):: xyr_ColDenDryAir (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \int_z^{\infty} \rho \, dz $ .
                              ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ遨ｺ豌励�繧ｫ繝ｩ繝�蟇�ｺｦ.
                              ! Column density of air above vertical level k.
    real(DP), intent(out):: xyr_RadLUwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ.
                              ! Upward longwave flux
    real(DP), intent(out):: xyr_RadLDwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ.
                              ! Downward longwave flux
    real(DP), intent(out):: xyra_DelRadLUwFlux (0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! 髟ｷ豕｢蝨ｰ陦ｨ貂ｩ蠎ｦ螟牙喧.
                              !
    real(DP), intent(out):: xyra_DelRadLDwFlux (0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! 髟ｷ豕｢蝨ｰ陦ｨ貂ｩ蠎ｦ螟牙喧.
                              !

    ! 菴懈･ｭ螟画焚
    ! Work variables
    !
    real(DP):: xyrr_Trans(0:imax-1, 1:jmax, 0:kmax, 0:kmax)
                              ! 騾城℃菫よ焚.
                              ! Transmission coefficient
    real(DP):: xyz_PiB (0:imax-1, 1:jmax, 1:kmax)
                              ! $ \pi B = \sigma T^{4} $
    real(DP):: xy_SurfPiB (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ髱｢縺ｮ $ \pi B $ .
                              ! $ \pi B $ on surface
    real(DP):: xy_PiDBDT1    (0:imax-1, 1:jmax)
                              ! $ \pi DBDT = 4 \sigma T^{3} at lowest level$
    real(DP):: xy_SurfPiDBDT (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ髱｢縺ｮ $ \pi DBDT $ .
                              ! $ \pi B $ on surface

    real(DP):: BandWeightSum  ! 繝舌Φ繝峨え繧ｧ繧､繝医�蜥�
                              ! Sum of band weights

    integer:: k, kk           ! 驩帷峩譁ｹ蜷代↓蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in vertical direction
    integer:: bn              ! 豕｢髟ｷ縺ｫ縺､縺�※蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in wavenumber bands

    ! 螳溯｡梧枚 ; Executable statement
    !

    ! 騾城℃髢｢謨ｰ險育ｮ�
    ! Calculate transmission functions
    !
    !   Initialization
    !
    xyrr_Trans = 0.
    !
    do bn = 1, LongBandNum

      do k = 0, kmax
        do kk = k, kmax
          xyrr_Trans(:,:,k,kk) = &
            &   xyrr_Trans(:,:,k,kk) &
            & + LongBandWeight(bn) &
            &   * exp( - LongPathLengthFact &
            &            * (   LongAbsorpCoefQVap(bn) &
            &                  * abs(   xyr_ColDenQVap(:,:,kk) &
            &                         - xyr_ColDenQVap(:,:,k)  ) &
            &                + LongAbsorpCoefDryAir(bn) &
            &                  * abs(   xyr_ColDenDryAir(:,:,kk) &
            &                         - xyr_ColDenDryAir(:,:,k)  ) ) )
        end do
      end do

    end do

    do k = 0, kmax
      do kk = 0, k-1
        xyrr_Trans(:,:,k,kk) = xyrr_Trans(:,:,kk,k)
      end do
    end do

    ! $ \pi B $, $ \pi DBDT $ 縺ｮ險育ｮ�
    ! Calculate $ \pi B $ and $ \pi DBDT $
    !
    xyz_PiB       = StB * ( xyz_Temp**4 )
    xy_SurfPiB    = StB * ( xy_SurfTemp**4 )
    xy_PiDBDT1    = 4.0_DP * xyz_PiB(:,:,1) / xyz_Temp(:,:,1)
    xy_SurfPiDBDT = 4.0_DP * xy_SurfPiB / xy_SurfTemp

    call RadRTENonScat(                                 &
      & xyz_PiB, xy_SurfPiB, xy_PiDBDT1, xy_SurfPiDBDT, & ! (in)
      & xyrr_Trans,                                     & ! (in)
      & xyr_RadLUwFlux, xyr_RadLDwFlux,                 & ! (out)
      & xyra_DelRadLUwFlux, xyra_DelRadLDwFlux          & ! (out)
      & )

  end subroutine LongFlux

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

  subroutine ShortFlux(                                &
    & xyr_ColDenQVap, xyr_ColDenDryAir, xy_SurfAlbedo, & ! (in)
    & xy_TOARadSDwFlux,                                & ! (in)
    & xyr_RadSUwFlux, xyr_RadSDwFlux                   & ! (out)
    & )
    !
    ! 遏ｭ豕｢繝輔Λ繝�け繧ｹ繧定ｨ育ｮ励＠縺ｾ縺�.
    !
    ! Calculate short wave flux.
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 螳｣險譁� ; Declaration statements
    !
    implicit none

    real(DP), intent(in):: xyr_ColDenQVap (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \int_z^{\infty} \rho q \, dz $ .
                              ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ豌ｴ闥ｸ豌励�繧ｫ繝ｩ繝�蟇�ｺｦ.
                              ! Column density of water vapor above vertical level k.
    real(DP), intent(in):: xyr_ColDenDryAir (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \int_z^{\infty} \rho \, dz $ .
                              ! 驩帷峩螻､ k 繧医ｊ荳顔ｩｺ縺ｮ遨ｺ豌励�繧ｫ繝ｩ繝�蟇�ｺｦ.
                              ! Column density of air above vertical level k.
    real(DP), intent(in):: xy_SurfAlbedo (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ繧｢繝ｫ繝吶ラ.
                              ! Surface albedo
    real(DP), intent(in):: xy_TOARadSDwFlux (0:imax-1, 1:jmax)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ.
                              ! Shortwave (insolation) flux at the top of the atmosphere
    real(DP), intent(out):: xyr_RadSUwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ.
                              ! Upward shortwave (insolation) flux
    real(DP), intent(out):: xyr_RadSDwFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! 遏ｭ豕｢ (譌･蟆�) 繝輔Λ繝�け繧ｹ.
                              ! Downward shortwave (insolation) flux

    ! 菴懈･ｭ螟画焚
    ! Work variables
    !
    real(DP) :: xyr_TransForDwFlux(0:imax-1, 1:jmax, 0:kmax)
                              !
                              ! Transmittance from level k to top of the atmosphere
    real(DP) :: xyr_TransForUwFlux(0:imax-1, 1:jmax, 0:kmax)
                              !
                              ! Transmittance from surface to level k
    integer:: k               ! 驩帷峩譁ｹ蜷代↓蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in vertical direction
    integer:: bn              ! 豕｢髟ｷ縺ｫ縺､縺�※蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in wavenumber bands

    ! 螳溯｡梧枚 ; Executable statement
    !

    xyr_TransForDwFlux = 0.0_DP
    do k = 0, kmax
      do bn = 1, ShortBandNum
        xyr_TransForDwFlux(:,:,k) = xyr_TransForDwFlux(:,:,k)                      &
          & + ShortBandWeight(bn)                                                  &
          &   * exp( - xy_InAngle                                                  &
          &            * (   ShortAbsorpCoefQVap  (bn) * xyr_ColDenQVap  (:,:,k)   &
          &                + ShortAbsorpCoefDryAir(bn) * xyr_ColDenDryAir(:,:,k) ) &
          &        )
      end do
    end do
    !
    xyr_TransForUwFlux = 0.0_DP
    do k = 0, kmax
      do bn = 1, ShortBandNum
        xyr_TransForUwFlux(:,:,k) = xyr_TransForUwFlux(:,:,k)                        &
          & + ShortBandWeight(bn)                                                    &
          &   * exp( - xy_InAngle                                                    &
          &            * (   ShortAbsorpCoefQVap  (bn) * xyr_ColDenQVap  (:,:,0)     &
          &                + ShortAbsorpCoefDryAir(bn) * xyr_ColDenDryAir(:,:,0) )   &
          &        )                                                                 &
          &   * xy_SurfAlbedo                                                        &
          &   * exp( - ShortSecScat                                                  &
          &            * (   ShortAbsorpCoefQVap(bn)                                 &
          &                  * ( xyr_ColDenQVap  (:,:,0) - xyr_ColDenQVap  (:,:,k) ) &
          &                + ShortAbsorpCoefDryAir(bn)                               &
          &                  * ( xyr_ColDenDryAir(:,:,0) - xyr_ColDenDryAir(:,:,k) ) &
          &              )                                                           &
          &        )
      end do
    end do

    do k = 0, kmax
      xyr_RadSDwFlux(:,:,k) = xy_TOARadSDwFlux * xyr_TransForDwFlux(:,:,k)
      xyr_RadSUwFlux(:,:,k) = xy_TOARadSDwFlux * xyr_TransForUwFlux(:,:,k)
    end do

  end subroutine ShortFlux

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

  subroutine RadDennouAGCMInit( flag_rst )
    !
    ! rad_DennouAGCM 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ蛻晄悄蛹悶ｒ陦後＞縺ｾ縺�.
    ! NAMELIST#rad_DennouAGCM_nml 縺ｮ隱ｭ縺ｿ霎ｼ縺ｿ縺ｯ縺薙�謇狗ｶ壹″縺ｧ陦後ｏ繧後∪縺�.
    !
    ! "rad_DennouAGCM" module is initialized.
    ! "NAMELIST#rad_DennouAGCM_nml" is loaded in this procedure.
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 蜃ｺ蜉帙ヵ繧｡繧､繝ｫ縺ｮ蝓ｺ譛ｬ諠��ｱ
    ! Basic information for output files
    !
    use fileset, only: &
      & FileTitle, &
                              ! 蜃ｺ蜉帙ョ繝ｼ繧ｿ繝輔ぃ繧､繝ｫ縺ｮ陦ｨ鬘�.
                              ! Title of output data files
      & FileSource, &
                              ! 繝��繧ｿ繝輔ぃ繧､繝ｫ菴懈�縺ｮ謇区ｮｵ.
                              ! Source of data file
      & FileInstitution
                              ! 繝��繧ｿ繝輔ぃ繧､繝ｫ繧呈怙邨ら噪縺ｫ螟画峩縺励◆邨�ｹ�/蛟倶ｺｺ.
                              ! Institution or person that changes data files for the last time

    ! 迚ｩ逅��謨ｰ蟄ｦ螳壽焚險ｭ螳�
    ! Physical and mathematical constants settings
    !
    use constants0, only: &
      & PI                    ! $ \pi $ .
                              ! 蜀�捉邇�.  Circular constant

    ! 蠎ｧ讓吶ョ繝ｼ繧ｿ險ｭ螳�
    ! Axes data settings
    !
    use axesset, only: &
      & x_Lon, &
                              ! $ \lambda $ [rad.] . 邨悟ｺｦ. Longitude
      & x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! 邨悟ｺｦ蠎ｧ讓咎㍾縺ｿ.
                              ! Weight of longitude
      & y_Lat, &
                              ! $ \varphi $ [rad.] . 邱ｯ蠎ｦ. Latitude
      & y_Lat_Weight, &
                              ! $ \Delta \varphi $ [rad.] .
                              ! 邱ｯ蠎ｦ蠎ｧ讓咎㍾縺ｿ.
                              ! Weight of latitude
      & z_Sigma, &
                              ! $ \sigma $ 繝ｬ繝吶Ν (謨ｴ謨ｰ).
                              ! Full $ \sigma $ level
      & r_Sigma, &
                              ! $ \sigma $ 繝ｬ繝吶Ν (蜊頑紛謨ｰ).
                              ! Half $ \sigma $ level
      & z_DelSigma
                              ! $ \Delta \sigma $ (謨ｴ謨ｰ).
                              ! $ \Delta \sigma $ (Full)

    ! 譎ょ綾邂｡逅�
    ! Time control
    !
    use timeset, only: &
      & RestartTime           ! 繝ｪ繧ｹ繧ｿ繝ｼ繝磯幕蟋区凾蛻ｻ.
                              ! Retart time of calculation

    ! NAMELIST 繝輔ぃ繧､繝ｫ蜈･蜉帙↓髢｢縺吶ｋ繝ｦ繝ｼ繝�ぅ繝ｪ繝�ぅ
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: namelist_filename, NmlutilMsg, NmlutilAryValid

    ! 證ｦ縺ｨ譌･譎ゅ�蜿悶ｊ謇ｱ縺�
    ! Calendar and Date handler
    !
    use dc_calendar, only: DCCalConvertByUnit

    ! 繝輔ぃ繧､繝ｫ蜈･蜃ｺ蜉幄｣懷勧
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! 遞ｮ蛻･蝙九ヱ繝ｩ繝｡繧ｿ
    ! Kind type parameter
    !
    use dc_types, only: STDOUT ! 讓呎ｺ門�蜉帙�陬�ｽｮ逡ｪ蜿ｷ. Unit number of standard output

    ! 邨�∩霎ｼ縺ｿ髢｢謨ｰ PRESENT 縺ｮ諡｡蠑ｵ迚磯未謨ｰ
    ! Extended functions of intrinsic function "PRESENT"
    !
    use dc_present, only: present_and_true

    ! 譁�ｭ怜�謫堺ｽ�
    ! Character handling
    !
    use dc_string, only: toChar

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ蜈･蜃ｺ蜉�
    ! Restart data input/output
    !
    use gtool_history, only: HistoryCreate, HistoryAddAttr, &
      & HistoryAddVariable, HistoryPut, &
      & HistoryGet, HistoryGetAttr

    ! 遏ｭ豕｢蜈･蟆� (螟ｪ髯ｽ蜈･蟆�)
    ! Short wave (insolation) incoming
    !
    use rad_short_income, only : RadShortIncomeInit

    ! 謨｣荵ｱ繧堤┌隕悶＠縺滓叛蟆�ｼ晞＃譁ｹ遞句ｼ�
    ! Radiative transfer equation without considering scattering
    !
    use rad_rte_nonscat, only : RadRTENonScatInit

    ! 螳｣險譁� ; Declaration statements
    !
    implicit none
    logical, intent(in), optional:: flag_rst
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医〒縺ゅｋ縺薙→繧堤､ｺ縺吶ヵ繝ｩ繧ｰ.
                              ! .true. 縺御ｸ弱∴繧峨ｌ繧句�ｴ蜷�,
                              ! 髟ｷ豕｢謾ｾ蟆�, 遏ｭ豕｢謾ｾ蟆�↓髢｢縺吶ｋ繝ｪ繧ｹ繧ｿ繝ｼ繝�
                              ! 繝輔ぃ繧､繝ｫ縺悟ｿ�ｦ√↓縺ｪ繧翫∪縺�.
                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｫ髢｢縺吶ｋ諠��ｱ縺ｯ
                              ! NAMELIST#rad_DennouAGCM_nml
                              ! 縺ｧ謖�ｮ壹＆繧後∪縺�.
                              ! 繝�ヵ繧ｩ繝ｫ繝医� .false. 縺ｧ縺�.
                              !
                              ! Flag for restart.
                              ! If .true. is given,
                              ! a restart file for long radiation
                              ! and short radiation is needed.
                              ! Information about the restart file
                              ! is specified by "NAMELIST#rad_DennouAGCM_nml".
                              ! Default value is .false.
                              !

    character(STRING):: RstInputFile
                              ! 蜈･蜉帙☆繧九Μ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ縺ｮ繝輔ぃ繧､繝ｫ蜷�
                              ! Filename of input restart data

    character(STRING):: RstOutputFile
                              ! 蜃ｺ蜉帙☆繧九Μ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ縺ｮ繝輔ぃ繧､繝ｫ蜷�
                              ! Filename of output restart data
    character(STRING):: time_range
                              ! 譎ょ綾縺ｮ謖�ｮ�.
                              ! Specification of time

    character(TOKEN):: dummy_str
                              ! 蜈･蜉帙メ繧ｧ繝�け逕ｨ縺ｮ繝繝溘�螟画焚
                              ! Dummy variable for check of input
    logical:: get_err
                              ! 蜈･蜉帶凾縺ｮ繧ｨ繝ｩ繝ｼ繝輔Λ繧ｰ.
                              ! Error flag for input

    integer:: unit_nml        ! NAMELIST 繝輔ぃ繧､繝ｫ繧ｪ繝ｼ繝励Φ逕ｨ陬�ｽｮ逡ｪ蜿ｷ.
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST 隱ｭ縺ｿ霎ｼ縺ｿ譎ゅ� IOSTAT.
                              ! IOSTAT of NAMELIST read

    character(STRING):: title_msg
                              ! 陦ｨ鬘後↓莉伜刈縺吶ｋ繝｡繝�そ繝ｼ繧ｸ.
                              ! Message added to title

    real(DP):: origin_time
                              ! 險育ｮ鈴幕蟋区凾蛻ｻ.
                              ! Start time of calculation
    character(STRING):: time_unit
                              ! 譌･譎ゅ�蜊倅ｽ�. Units of date and time

    logical:: flag_mpi_init

    real(DP):: BandWeightSum  ! 繝舌Φ繝峨え繧ｧ繧､繝医�蜥�
                              ! Sum of band weights
    integer:: bn              ! 豕｢髟ｷ縺ｫ縺､縺�※蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in wavenumber bands

    ! NAMELIST 螟画焚鄒､
    ! NAMELIST group name
    !
    namelist /rad_DennouAGCM_nml/ &
      & SolarConst, &
!
      & DelTimeLongValue, DelTimeLongUnit, &
      & DelTimeShortValue, DelTimeShortUnit, &
!
      & LongBandNum, &
      & LongAbsorpCoefQVap, LongAbsorpCoefDryAir, &
      & LongBandWeight, LongPathLengthFact, &
!
      & ShortBandNum, &
      & ShortAbsorpCoefQVap, ShortAbsorpCoefDryAir, &
      & ShortBandWeight, ShortSecScat, &
      & ShortAtmosAlbedo, &
!
      & RstInputFile, RstOutputFile
          !
          ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｫ縺､縺�※縺ｯ蛻晄悄蛹匁焔邯� "rad_DennouAGCM#RadInit"
          ! 縺ｮ繧ｽ繝ｼ繧ｹ繧ｳ繝ｼ繝峨ｒ蜿ら�縺ｮ縺薙→.
          !
          ! Refer to source codes in the initialization procedure
          ! "rad_DennouAGCM#RadInit" for the default values.
          !

    ! 螳溯｡梧枚 ; Executable statement
    !

    if ( rad_DennouAGCM_inited ) return

!    flag_mpi_init = .false.
    flag_mpi_init = .true.

    ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｮ險ｭ螳�
    ! Default values settings
    !

    ! 髟ｷ豕｢繝輔Λ繝�け繧ｹ逕ｨ諠��ｱ
    ! Information for long wave flux
    !
    PrevTimeLong = RestartTime

    DelTimeLongValue = 3.0_DP
    DelTimeLongUnit  = 'hrs.'

    LongBandNum      = 4
    LongAbsorpCoefQVap     = -999.9_DP
    LongAbsorpCoefDryAir   = -999.9_DP
    LongBandWeight         = -999.9_DP
    LongAbsorpCoefQVap    (1:LongBandNum) = (/ 8.0_DP, 1.0_DP, 0.1_DP, 0.0_DP /)
    LongAbsorpCoefDryAir  (1:LongBandNum) = (/ 0.0_DP, 0.0_DP, 0.0_DP, 5.0e-5_DP /)
    LongBandWeight        (1:LongBandNum) = (/ 0.2_DP, 0.1_DP, 0.1_DP, 0.6_DP /)
    LongPathLengthFact = 1.5_DP

    ! 遏ｭ豕｢繝輔Λ繝�け繧ｹ逕ｨ諠��ｱ
    ! Information for short wave flux
    !
    SolarConst             = 1380.0_DP

    PrevTimeShort = RestartTime

    DelTimeShortValue = 1.0_DP
    DelTimeShortUnit  = 'hrs.'

    ShortBandNum = 1
    ShortAbsorpCoefQVap    = -999.9_DP
    ShortAbsorpCoefDryAir  = -999.9_DP
    ShortBandWeight        = -999.9_DP
    ShortAbsorpCoefQVap   (1:ShortBandNum) = (/ 0.002_DP /)
    ShortAbsorpCoefDryAir (1:ShortBandNum) = (/ 0.0_DP /)
    ShortBandWeight       (1:ShortBandNum) = (/ 1.0_DP /)
    ShortSecScat           = 1.66_DP
    ShortAtmosAlbedo       = 0.2_DP

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ諠��ｱ
    ! Information about a restart file
    !
    RstInputFile  = ''
    RstOutputFile = 'rst_rad.nc'

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

      call NmlutilMsg( iostat_nml, module_name ) ! (in)
    end if

    if ( LongBandNum <= 0 ) then
      call MessageNotify( 'E', module_name, 'LongBandNum has to be positive.' )
    end if
    if ( ShortBandNum <= 0 ) then
      call MessageNotify( 'E', module_name, 'ShortBandNum has to be positive.' )
    end if

    ! 繝舌Φ繝峨え繧ｧ繧､繝医�險ｭ螳�
    ! Configure band weight
    !
    BandWeightSum = 0.
    do bn = 1, LongBandNum
      BandWeightSum =  BandWeightSum + LongBandWeight(bn)
    end do
    do bn = 1, LongBandNum
      LongBandWeight(bn) = LongBandWeight(bn) / BandWeightSum
    end do
    !
    BandWeightSum = 0.
    do bn = 1, ShortBandNum
      BandWeightSum = BandWeightSum + ShortBandWeight(bn)
    end do
    do bn = 1, ShortBandNum
      ShortBandWeight(bn) = ShortBandWeight(bn) / BandWeightSum
    end do

    ! 譎る俣髢馴囈縺ｮ蜃ｦ逅�
    ! Handle interval time
    !
    IntTimeLong  = DCCalConvertByUnit( DelTimeLongValue,  DelTimeLongUnit,  'sec' ) ! (in)
    IntTimeShort = DCCalConvertByUnit( DelTimeShortValue, DelTimeShortUnit, 'sec' ) ! (in)

    ! 繝舌Φ繝画焚, 蜷ｸ蜿惹ｿよ焚, 繝舌Φ繝峨え繧ｧ繧､繝医�繝√ぉ繝�け
    ! Check number of band, absorption coefficients, band weight
    !
    call NmlutilAryValid( module_name, &            ! (in)
      & LongAbsorpCoefQVap, 'LongAbsorpCoefQVap', & ! (in)
      & LongBandNum,        'LongBandNum' )         ! (in)

    call NmlutilAryValid( module_name, &                ! (in)
      & LongAbsorpCoefDryAir, 'LongAbsorpCoefDryAir', & ! (in)
      & LongBandNum,          'LongBandNum' )           ! (in)

    call NmlutilAryValid( module_name, &     ! (in)
      & LongBandWeight, 'LongBandWeight', &  ! (in)
      & LongBandNum,    'LongBandNum' )      ! (in)

    call NmlutilAryValid( module_name, &              ! (in)
      & ShortAbsorpCoefQVap, 'ShortAbsorpCoefQVap', & ! (in)
      & ShortBandNum,        'ShortBandNum' )         ! (in)

    call NmlutilAryValid( module_name, &                  ! (in)
      & ShortAbsorpCoefDryAir, 'ShortAbsorpCoefDryAir', & ! (in)
      & ShortBandNum,          'ShortBandNum' )           ! (in)

    call NmlutilAryValid( module_name, &       ! (in)
      & ShortBandWeight, 'ShortBandWeight', &  ! (in)
      & ShortBandNum,    'ShortBandNum' )      ! (in)

    ! 遏ｭ豕｢蜈･蟆�畑螟画焚縺ｮ蜑ｲ莉�
    ! Allocate variables for short wave (insolation) incoming radiation
    !
    allocate( xy_IncomRadSFlux (0:imax-1, 1:jmax) )
    allocate( xy_InAngle (0:imax-1, 1:jmax) )

    ! 菫晏ｭ倡畑縺ｮ螟画焚縺ｮ蜑ｲ繧贋ｻ倥￠
    ! Allocate variables for saving
    !
    allocate( xy_TempSave            (0:imax-1, 1:jmax) )
    allocate( xyr_RadSUwFluxSave     (0:imax-1, 1:jmax, 0:kmax) )
    allocate( xyr_RadSDwFluxSave     (0:imax-1, 1:jmax, 0:kmax) )
    allocate( xyr_RadLUwFluxSave     (0:imax-1, 1:jmax, 0:kmax) )
    allocate( xyr_RadLDwFluxSave     (0:imax-1, 1:jmax, 0:kmax) )
    allocate( xyra_DelRadLUwFluxSave (0:imax-1, 1:jmax, 0:kmax, 0:1) )
    allocate( xyra_DelRadLDwFluxSave (0:imax-1, 1:jmax, 0:kmax, 0:1) )

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ蜈･蜉�
    ! Input restart file
    !
    if ( present_and_true( flag_rst ) ) then

      if ( trim(RstInputFile) == '' ) then
        call MessageNotify( 'E', module_name, &
          & 'a restart file is needed. ' // &
          & 'Specify the restart file to "RstInputFile" in NAMELIST "rad_DennouAGCM_nml"' )
      end if

      ! 譎ょ綾諠��ｱ縺ｮ蜿門ｾ�
      ! Get time information
      !
      time_range = 'time=' // toChar( RestartTime )

      ! 繝輔ぃ繧､繝ｫ縺ｮ譛臥┌繧堤｢ｺ隱�
      ! Conform an existence of an input file
      !
      call HistoryGetAttr( RstInputFile, 'lon', 'units', & ! (in)
        & dummy_str, &                                     ! (out)
        & flag_mpi_split = flag_mpi_init, &                ! (in) optional
        & err = get_err )                                  ! (out)

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

      ! 蜈･蜉�
      ! Input
      !
      call HistoryGet( &
        & RstInputFile, 'SurfTemp', &      ! (in)
        & xy_TempSave, &                   ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional
      call HistoryGet( &
        & RstInputFile, 'RadSUwFlux', &    ! (in)
        & xyr_RadSUwFluxSave, &            ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional
      call HistoryGet( &
        & RstInputFile, 'RadSDwFlux', &    ! (in)
        & xyr_RadSDwFluxSave, &            ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional
      call HistoryGet( &
        & RstInputFile, 'RadLUwFlux', &    ! (in)
        & xyr_RadLUwFluxSave, &            ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional
      call HistoryGet( &
        & RstInputFile, 'RadLDwFlux', &    ! (in)
        & xyr_RadLDwFluxSave, &            ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional
      call HistoryGet( &
        & RstInputFile, 'DelRadLUwFlux', & ! (in)
        & xyra_DelRadLUwFluxSave, &        ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional
      call HistoryGet( &
        & RstInputFile, 'DelRadLDwFlux', & ! (in)
        & xyra_DelRadLDwFluxSave, &        ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional

      call HistoryGet( &
        & RstInputFile, 'PrevTimeLong', &  ! (in)
        & PrevTimeLong, &                  ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional

      call HistoryGet( &
        & RstInputFile, 'PrevTimeShort', & ! (in)
        & PrevTimeShort, &                 ! (out)
        & range = time_range, &            ! (in) optional
        & flag_mpi_split = flag_mpi_init ) ! (in) optional

      flag_rst_input = .true.
      Old_Flux_saved = .true.
    else
      RstInputFile = ''
      flag_rst_input = .false.
      Old_Flux_saved = .false.
    end if

    ! 蜃ｺ蜉帶凾髢馴俣髫斐�險ｭ螳�
    ! Configure time interval of output
    !
    PrevRstOutputTime = RestartTime

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ菴懈�
    ! Create a restart file
    !
    title_msg = ' restart data for "' // module_name // '" module'
!!$    origin_time = EvalByUnit( RestartTime, RstFileIntUnit )
!!$    time_unit = RstFileIntUnit
    time_unit = 'sec'

    call HistoryCreate( &
      &      file = RstOutputFile, &                                ! (in)
      &     title = trim(FileTitle) // trim(title_msg), &           ! (in)
      &    source = FileSource, institution = FileInstitution, &    ! (in)
      &      dims = (/ 'lon  ', 'lat  ', 'sig  ', 'sigm ', &
      &                'sorbl', 'time ' /), &                       ! (in)
      &  dimsizes = (/ imax, jmax, kmax, kmax + 1, 2, 0 /), &       ! (in)
      & longnames = (/ 'longitude                             ', &
      &                'latitude                              ', &
      &                'sigma at layer midpoints              ', &
      &                'sigma at layer end-points (half level)', &
      &                'surface or bottom layer               ', &
      &                'time                                  ' /), & ! (in)
      &     units = (/ 'degrees_east ', 'degrees_north', &
      &                '1            ', '1            ', &
      &                '1            ', time_unit(1:13) /), &            ! (in)
      & xtypes = (/'double', 'double', 'double', &
      &            'double', 'int   ', 'double'/), &                  ! (in)
      &        origind = RestartTime, &         ! (in) optional
      &      intervald = RstFileIntValue, &     ! (in) optional
      & flag_mpi_split = flag_mpi_init, &       ! (in) optional
      &        history = gthst_rst )            ! (out) optional

    ! 蠎ｧ讓吶ョ繝ｼ繧ｿ縺ｮ險ｭ螳�
    ! Axes data settings
    !
    call HistoryAddAttr( &
      & 'lon', attrname = 'standard_name', &     ! (in)
      & value = 'longitude', &                   ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'lat', attrname = 'standard_name', &     ! (in)
      & value = 'latitude', &                    ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sig', attrname = 'standard_name', &     ! (in)
      & value = 'atmosphere_sigma_coordinate', & ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sigm', attrname = 'standard_name', &    ! (in)
      & value = 'atmosphere_sigma_coordinate', & ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'time', attrname = 'standard_name', &    ! (in)
      & value = 'time', &                        ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sig', attrname = 'positive', &          ! (in)
      & value = 'down', &                        ! (in)
      & history = gthst_rst )                    ! (inout)
    call HistoryAddAttr( &
      & 'sigm', attrname = 'positive', &         ! (in)
      & value = 'down', &                        ! (in)
      & history = gthst_rst )                    ! (inout)

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

    ! 蠎ｧ讓咎㍾縺ｿ縺ｮ險ｭ螳�
    ! Axes weights settings
    !
    call HistoryAddVariable( 'lon_weight', &               ! (in)
      & (/'lon'/), &                                       ! (in)
      & 'weight for integration in longitude', 'radian', & ! (in)
      & xtype = 'double', &                                ! (in)
      & history = gthst_rst )                              ! (inout)
    call HistoryAddAttr( &
      & 'lon', attrname = 'gt_calc_weight', &     ! (in)
      & value = 'lon_weight', &                   ! (in)
      & history = gthst_rst )                     ! (inout)
    call HistoryPut( &
      & 'lon_weight', x_Lon_Weight, &             ! (in)
      & history = gthst_rst )                     ! (inout)

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

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

    call HistoryAddVariable( 'PrevTimeLong', &      ! (in)
      & (/ 'time' /), &                             ! (in)
      & 'previous time at which longwave flux is calculated', & ! (in)
      & 'sec', &                                    ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)
    call HistoryAddVariable( 'PrevTimeShort', &     ! (in)
      & (/ 'time' /), &                             ! (in)
      & 'previous time at which shortwave flux is calculated', & ! (in)
      & 'sec', &                                    ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)

    call HistoryAddVariable( 'SurfTemp', &          ! (in)
      & (/ 'lon ', 'lat ', 'time' /), &             ! (in)
      & 'surface temperature', 'K', &               ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)
    call HistoryAddVariable( 'RadSUwFlux', &        ! (in)
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &     ! (in)
      & 'upward shortwave flux', 'W m-2', &         ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)
    call HistoryAddVariable( 'RadSDwFlux', &        ! (in)
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &     ! (in)
      & 'downward shortwave flux', 'W m-2', &       ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)
    call HistoryAddVariable( 'RadLUwFlux', &        ! (in)
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &     ! (in)
      & 'upward longwave flux', 'W m-2', &          ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)
    call HistoryAddVariable( 'RadLDwFlux', &        ! (in)
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &     ! (in)
      & 'downward longwave flux', 'W m-2', &        ! (in)
      & xtype = 'double', &                         ! (in)
      & history = gthst_rst )                       ! (inout)
    call HistoryAddVariable( 'DelRadLUwFlux', &                           ! (in)
      & (/ 'lon  ', 'lat  ', 'sigm ', 'sorbl', 'time ' /), &              ! (in)
      & 'longwave flux tendency with surface temperature', 'W m-2 K-1', & ! (in)
      & xtype = 'double', &                                               ! (in)
      & history = gthst_rst )                                             ! (inout)
    call HistoryAddVariable( 'DelRadLDwFlux', &                           ! (in)
      & (/ 'lon  ', 'lat  ', 'sigm ', 'sorbl', 'time ' /), &              ! (in)
      & 'longwave flux tendency with surface temperature', 'W m-2 K-1', & ! (in)
      & xtype = 'double', &                                               ! (in)
      & history = gthst_rst )                                             ! (inout)

    ! Initialization of modules used in this module
    !

    ! 遏ｭ豕｢蜈･蟆� (螟ｪ髯ｽ蜈･蟆�)
    ! Short wave (insolation) incoming
    !
    call RadShortIncomeInit

    ! 謨｣荵ｱ繧堤┌隕悶＠縺滓叛蟆�ｼ晞＃譁ｹ遞句ｼ�
    ! Radiative transfer equation without considering scattering
    !
    call RadRTENonScatInit

    ! 蜊ｰ蟄� ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, 'Restart:' )

    if ( trim(RstInputFile) == '' ) then
      call MessageNotify( 'M', module_name, '  InputFile  = <no input>', c1 = trim( RstInputFile ) )
    else
      call MessageNotify( 'M', module_name, '  InputFile       = %c', c1 = trim( RstInputFile ) )
      call MessageNotify( 'M', module_name, '    PrevTimeLong  = %f [%c]', &
      & d = (/ PrevTimeLong /), c1 = 'sec' )
      call MessageNotify( 'M', module_name, '    PrevTimeShort = %f [%c]', &
      & d = (/ PrevTimeShort /), c1 = 'sec' )
    end if

    call MessageNotify( 'M', module_name, '  OutputFile = %c', c1 = trim( RstOutputFile ) )
    call MessageNotify( 'M', module_name, '  IntTime    = %f [%c] (same as IntTime in "restart_file_io" module)', &
      & d = (/ RstFileIntValue /), c1 = trim( RstFileIntUnit ) )
!
    call MessageNotify( 'M', module_name, '  SolarConst   = %f', d = (/ SolarConst /) )
    call MessageNotify( 'M', module_name, 'DelTime:' )
    call MessageNotify( 'M', module_name, '  DelTimeLong  = %f [%c]', &
      & d = (/ DelTimeLongValue /), c1 = trim( DelTimeLongUnit ) )
    call MessageNotify( 'M', module_name, '  DelTimeShort = %f [%c]', &
      & d = (/ DelTimeShortValue /), c1 = trim( DelTimeShortUnit ) )
!
    call MessageNotify( 'M', module_name, 'LongFlux:' )
    call MessageNotify( 'M', module_name, '  LongBandNum            = %d', i = (/ LongBandNum /) )
    call MessageNotify( 'M', module_name, '  LongAbsorpCoefQVap     = (/ %*r /)', &
      & r = real( LongAbsorpCoefQVap(1:LongBandNum) ), n = (/ LongBandNum /) )
    call MessageNotify( 'M', module_name, '  LongAbsorpCoefDryAir   = (/ %*r /)', &
      & r = real( LongAbsorpCoefDryAir(1:LongBandNum) ), n = (/ LongBandNum /) )
    call MessageNotify( 'M', module_name, '  LongBandWeight         = (/ %*r /)', &
      & r = real( LongBandWeight(1:LongBandNum) ), n = (/ LongBandNum /) )
    call MessageNotify( 'M', module_name, '  LongPathLengthFact     = %f', d = (/ LongPathLengthFact /) )
!
    call MessageNotify( 'M', module_name, 'ShortFlux:' )
    call MessageNotify( 'M', module_name, '  ShortBandNum           = %d', i = (/ ShortBandNum /) )
    call MessageNotify( 'M', module_name, '  ShortAbsorpCoefQVap    = (/ %*r /)', &
      & r = real( ShortAbsorpCoefQVap(1:ShortBandNum) ), n = (/ ShortBandNum /) )
    call MessageNotify( 'M', module_name, '  ShortAbsorpCoefDryAir  = (/ %*r /)', &
      & r = real( ShortAbsorpCoefDryAir(1:ShortBandNum) ), n = (/ ShortBandNum /) )
    call MessageNotify( 'M', module_name, '  ShortBandWeight        = (/ %*r /)', &
      & r = real( ShortBandWeight(1:ShortBandNum) ), n = (/ ShortBandNum /) )
    call MessageNotify( 'M', module_name, '  ShortSecScat           = %f', d = (/ ShortSecScat /) )
    call MessageNotify( 'M', module_name, '  ShortAtmosAlbedo       = %f', d = (/ ShortAtmosAlbedo /) )

    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    rad_DennouAGCM_inited = .true.

  end subroutine RadDennouAGCMInit

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

  subroutine RadDennouAGCMFinalize
    !
    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ繧ｯ繝ｭ繝ｼ繧ｺ縺ｨ,
    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蜀�Κ縺ｮ螟画焚縺ｮ蜑ｲ繧贋ｻ倥￠隗｣髯､繧定｡後＞縺ｾ縺�.
    !
    ! Close a restart file, and
    ! deallocate variables in this module.
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ蜈･蜃ｺ蜉�
    ! Restart data input/output
    !
    use gtool_history, only: HistoryClose

    ! 螳｣險譁� ; Declaration statements
    !
    implicit none

    ! 螳溯｡梧枚 ; Executable statement
    !

    if ( .not. rad_DennouAGCM_inited ) return

    ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｸ謌ｻ縺�
    ! Return to default values
    !
    Old_Flux_saved = .false.

    ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ繧ｯ繝ｭ繝ｼ繧ｺ
    ! close a restart file
    !
    call HistoryClose( history = gthst_rst ) ! (inout)

    ! 蜑ｲ繧贋ｻ倥￠隗｣髯､
    ! Deallocation
    !
    if ( allocated( xy_IncomRadSFlux       ) ) deallocate( xy_IncomRadSFlux       )
    if ( allocated( xy_InAngle             ) ) deallocate( xy_InAngle             )
    if ( allocated( xy_TempSave            ) ) deallocate( xy_TempSave            )
    if ( allocated( xyr_RadSUwFluxSave     ) ) deallocate( xyr_RadSUwFluxSave     )
    if ( allocated( xyr_RadSDwFluxSave     ) ) deallocate( xyr_RadSDwFluxSave     )
    if ( allocated( xyr_RadLUwFluxSave     ) ) deallocate( xyr_RadLUwFluxSave     )
    if ( allocated( xyr_RadLDwFluxSave     ) ) deallocate( xyr_RadLDwFluxSave     )
    if ( allocated( xyra_DelRadLUwFluxSave ) ) deallocate( xyra_DelRadLUwFluxSave )
    if ( allocated( xyra_DelRadLDwFluxSave ) ) deallocate( xyra_DelRadLDwFluxSave )

    rad_DennouAGCM_inited = .false.

  end subroutine RadDennouAGCMFinalize

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

end module rad_DennouAGCM