!= æ”¾å°„é–¢é€£ãƒ«ãƒ¼ãƒãƒ³
!
!= Routines for radiation calculation
!
! Authors::   Yasuhiro MORIKAWA, Yukiko YAMADA, Satoshi NODA, Yoshiyuki O. TAKAHASHI
! Version::   $Id: rad_utils.f90,v 1.7 2012/10/08 12:48:45 yot Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module rad_utils
  !
  != æ”¾å°„é–¢é€£ãƒ«ãƒ¼ãƒãƒ³
  !
  != Routines for radiation calculation
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  !
  !
  !
  !
  !== Procedures List
  !
  ! RadDTempDt        :: æ”¾å°„ãƒ•ãƒ©ãƒƒã‚¯ã‚¹ã«ã‚ˆã‚‹æ¸©åº¦å¤‰åŒ–ã®è¨ˆç®—
  ! RadFluxOutput     :: æ”¾å°„ãƒ•ãƒ©ãƒƒã‚¯ã‚¹ã®å‡ºåŠ›
  ! ------------            :: ------------
  ! RadDTempDt        :: Calculate temperature tendency with radiation flux
  ! RadFluxOutput     :: Output radiation fluxes
  !
  !== NAMELIST
  !
  ! NAMELIST#rad_utils_nml
  !

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

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

  ! ç‰©ç†ãƒ»æ•°å¦å®šæ•°è¨å®š
  ! Physical and mathematical constants settings
  !
  use constants0, only: &
    & PI, &                 ! $ \pi $.
                            ! å††å‘¨çŽ‡. Circular constant
    & StB
                            ! $ \sigma_{SB} $ .
                            ! ã‚¹ãƒ†ãƒ•ã‚¡ãƒ³ãƒœãƒ«ãƒ„ãƒžãƒ³å®šæ•°.
                            ! Stefan-Boltzmann constant

  ! ç‰©ç†å®šæ•°è¨å®š
  ! Physical constants settings
  !
  use constants, only: &
    & Grav, &
                            ! $ g $ [m s-2].
                            ! é‡åŠ›åŠ é€Ÿåº¦.
                            ! Gravitational acceleration
    & CpDry
                            ! $ C_p $ [J kg-1 K-1].
                            ! ä¹¾ç‡¥å¤§æ°—ã®å®šåœ§æ¯”ç†±.
                            ! Specific heat of air at constant pressure

  ! æ ¼åç‚¹è¨å®š
  ! 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

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

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

  ! å…¬é–‹æ‰‹ç¶šã
  ! Public procedure
  !
  public :: RadDTempDt
  public :: RadDTempDtforNHM2DWrapper
  public :: RadFluxOutput
  public :: RadUtilsInit

  ! å…¬é–‹å¤‰æ•°
  ! Public variables
  !
  logical, save, public:: rad_utils_inited = .false.
                              ! åˆæœŸè¨å®šãƒ•ãƒ©ã‚°.
                              ! Initialization flag

  ! éžå…¬é–‹å¤‰æ•°
  ! Private variables
  !

  character(*), parameter:: module_name = 'rad_utils'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: rad_utils.f90,v 1.7 2012/10/08 12:48:45 yot Exp $'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³
                              ! Module version

contains

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

  subroutine RadDTempDt( &
    & xyr_RadLFlux, xyr_RadSFlux, xyr_Press, & ! (in)
    & xyz_DTempDtRadL, xyz_DTempDtRadS &       ! (out)
    & )
    !
    ! æ”¾å°„ã«ã‚ˆã‚‹æ¸©åº¦å¤‰åŒ–çŽ‡ã‚’è¨ˆç®—ã—ã¾ã™.
    !
    ! Temperature tendency with radiation is calculated.
    !

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & TimeN, &              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ». Time of step $ t $.
      & TimesetClockStart, TimesetClockStop

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoPut

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xyr_RadLFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Longwave flux
    real(DP), intent(in):: xyr_RadSFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! çŸæ³¢ (æ—¥å°„) ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Shortwave (insolation) flux
    real(DP), intent(in):: xyr_Press    (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \hat{p} $ . æ°—åœ§ (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«).
                              ! Air pressure (half level)
    real(DP), intent(out):: xyz_DTempDtRadL (0:imax-1, 1:jmax, 1:kmax)
                              ! é•·æ³¢åŠ ç†±çŽ‡.
                              ! Temperature tendency with longwave
    real(DP), intent(out):: xyz_DTempDtRadS (0:imax-1, 1:jmax, 1:kmax)
                              ! çŸæ³¢åŠ ç†±çŽ‡.
                              ! Temperature tendency with shortwave

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: k               ! é‰›ç›´æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in vertical direction

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

    ! åˆæœŸåŒ–ç¢ºèª
    ! Initialization check
    !
    if ( .not. rad_utils_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬é–‹å§‹
    ! Start measurement of computation time
    !
    call TimesetClockStart( module_name )

    ! æ”¾å°„å†·å´çŽ‡ã®æ¼”ç®—
    ! Calculate radiation cooling rate
    !
    do k = 1, kmax
      xyz_DTempDtRadL(:,:,k) = &
        & (     xyr_RadLFlux(:,:,k-1) - xyr_RadLFlux(:,:,k) ) &
        &   / ( xyr_Press(:,:,k-1)    - xyr_Press(:,:,k) ) &
        &   / CpDry * Grav

      xyz_DTempDtRadS(:,:,k) = &
        & (     xyr_RadSFlux(:,:,k-1) - xyr_RadSFlux(:,:,k) ) &
        &   / ( xyr_Press(:,:,k-1)    - xyr_Press(:,:,k) ) &
        &   / CpDry * Grav
    end do

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'DTempDtRadL' , xyz_DTempDtRadL )
    call HistoryAutoPut( TimeN, 'DTempDtRadS' , xyz_DTempDtRadS )

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬ä¸€æ™‚åœæ¢
    ! Pause measurement of computation time
    !
    call TimesetClockStop( module_name )

  end subroutine RadDTempDt

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

  subroutine RadDTempDtforNHM(                        &
    & xyr_RadLFlux, xyr_RadSFlux, r_Height, xyz_Dens, & ! (in)
    & xyz_DTempDtRadL, xyz_DTempDtRadS                & ! (out)
    & )
    !
    ! éžé™åŠ›å¦ç³»ã«ãŠã‘ã‚‹æ”¾å°„ã«ã‚ˆã‚‹æ¸©åº¦å¤‰åŒ–çŽ‡ã‚’è¨ˆç®—ã—ã¾ã™.
    !
    ! Temperature tendency with radiation is calculated for non-hydrodynamic system.
    !

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & TimeN, &              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ». Time of step $ t $.
      & TimesetClockStart, TimesetClockStop

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoPut

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xyr_RadLFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Longwave flux
    real(DP), intent(in):: xyr_RadSFlux (0:imax-1, 1:jmax, 0:kmax)
                              ! çŸæ³¢ (æ—¥å°„) ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Shortwave (insolation) flux
    real(DP), intent(in):: r_Height                       (0:kmax)
                              ! $ \hat{p} $ . æ°—åœ§ (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«).
                              ! Air pressure (half level)
    real(DP), intent(in):: xyz_Dens     (0:imax-1, 1:jmax, 1:kmax)
    real(DP), intent(out):: xyz_DTempDtRadL (0:imax-1, 1:jmax, 1:kmax)
                              ! é•·æ³¢åŠ ç†±çŽ‡.
                              ! Temperature tendency with longwave
    real(DP), intent(out):: xyz_DTempDtRadS (0:imax-1, 1:jmax, 1:kmax)
                              ! çŸæ³¢åŠ ç†±çŽ‡.
                              ! Temperature tendency with shortwave

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: k               ! é‰›ç›´æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in vertical direction

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

    ! åˆæœŸåŒ–ç¢ºèª
    ! Initialization check
    !
    if ( .not. rad_utils_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬é–‹å§‹
    ! Start measurement of computation time
    !
    call TimesetClockStart( module_name )

    ! æ”¾å°„å†·å´çŽ‡ã®æ¼”ç®—
    ! Calculate radiation cooling rate
    !
    do k = 1, kmax
      xyz_DTempDtRadL(:,:,k) = &
        &   - ( xyr_RadLFlux(:,:,k) - xyr_RadLFlux(:,:,k-1) ) &
        &   / (   r_Height      (k) -   r_Height      (k-1) ) &
        &   / ( CpDry * xyz_Dens(:,:,k) )

      xyz_DTempDtRadS(:,:,k) = &
        &   - ( xyr_RadSFlux(:,:,k) - xyr_RadSFlux(:,:,k-1) ) &
        &   / (   r_Height      (k) -   r_Height      (k-1) ) &
        &   / ( CpDry * xyz_Dens(:,:,k) )
    end do

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'DTempDtRadL' , xyz_DTempDtRadL )
    call HistoryAutoPut( TimeN, 'DTempDtRadS' , xyz_DTempDtRadS )

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬ä¸€æ™‚åœæ¢
    ! Pause measurement of computation time
    !
    call TimesetClockStop( module_name )

  end subroutine RadDTempDtforNHM

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

  subroutine RadDTempDtforNHM2DWrapper(             &
    & xr_RadLFlux, xr_RadSFlux, r_Height, xz_Dens,  & ! (in)
    & xz_DTempDtRadL, xz_DTempDtRadS                & ! (out)
    & )
    !
    ! æ”¾å°„ã«ã‚ˆã‚‹æ¸©åº¦å¤‰åŒ–çŽ‡ã‚’è¨ˆç®—ã—ã¾ã™.
    !
    ! Temperature tendency with radiation is calculated.
    !

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

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xr_RadLFlux (0:imax-1, 0:kmax)
                              ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Longwave flux
    real(DP), intent(in):: xr_RadSFlux (0:imax-1, 0:kmax)
                              ! çŸæ³¢ (æ—¥å°„) ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Shortwave (insolation) flux
    real(DP), intent(in):: r_Height    (0:kmax)
                              ! $ \hat{p} $ . æ°—åœ§ (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«).
                              ! Air pressure (half level)
    real(DP), intent(in):: xz_Dens     (0:imax-1, 1:kmax)
    real(DP), intent(out):: xz_DTempDtRadL (0:imax-1, 1:kmax)
                              ! é•·æ³¢åŠ ç†±çŽ‡.
                              ! Temperature tendency with longwave
    real(DP), intent(out):: xz_DTempDtRadS (0:imax-1, 1:kmax)
                              ! çŸæ³¢åŠ ç†±çŽ‡.
                              ! Temperature tendency with shortwave

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    real(DP) :: xyr_RadLFlux   (0:imax-1, 1:jmax, 0:kmax)
    real(DP) :: xyr_RadSFlux   (0:imax-1, 1:jmax, 0:kmax)
    real(DP) :: xyz_Dens       (0:imax-1, 1:jmax, 1:kmax)
    real(DP) :: xyz_DTempDtRadL(0:imax-1, 1:jmax, 1:kmax)
    real(DP) :: xyz_DTempDtRadS(0:imax-1, 1:jmax, 1:kmax)

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

    ! åˆæœŸåŒ–ç¢ºèª
    ! Initialization check
    !
    if ( .not. rad_utils_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    xyr_RadLFlux(:,1,:) = xr_RadLFlux(:,:)
    xyr_RadSFlux(:,1,:) = xr_RadSFlux(:,:)
    xyz_Dens    (:,1,:) = xz_Dens    (:,:)

    call RadDTempDtforNHM(                              &
      & xyr_RadLFlux, xyr_RadSFlux, r_Height, xyz_Dens, & ! (in)
      & xyz_DTempDtRadL, xyz_DTempDtRadS                & ! (out)
      & )

    xz_DTempDtRadL(:,:) = xyz_DTempDtRadL(:,1,:)
    xz_DTempDtRadS(:,:) = xyz_DTempDtRadS(:,1,:)

  end subroutine RadDTempDtforNHM2DWrapper

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

  subroutine RadFluxOutput(                          &
    & xyr_RadSUwFlux, xyr_RadSDwFlux,                & ! (in)
    & xyr_RadLUwFlux, xyr_RadLDwFlux,                & ! (in)
    & xyra_DelRadLUwFlux, xyra_DelRadLDwFlux,        & ! (in)
    & xy_DSurfTempDt, xyz_DTempDt                    & ! (in)
    & )
    !
    ! æ”¾å°„ãƒ•ãƒ©ãƒƒã‚¯ã‚¹ (xyr_RadSFlux, xyr_RadLFlux)
    ! ã«ã¤ã„ã¦, ãã®ä»–ã®å¼•æ•°ã‚’ç”¨ã„ã¦è£œæ£ã—, å‡ºåŠ›ã‚’è¡Œã†.
    !
    ! Radiation fluxes (xyr_RadSFlux, xyr_RadLFlux) are
    ! corrected by using other arguments, and the corrected values are output.
    !

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

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & DelTime, &            ! $ \Delta t $ [s]
      & TimeN, &              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ». Time of step $ t $.
      & TimesetClockStart, TimesetClockStop

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoPut

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    real(DP), intent(in):: xyr_RadSUwFlux  (0:imax-1, 1:jmax, 0:kmax)
                              ! çŸæ³¢ (æ—¥å°„) ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Upward shortwave (insolation) flux
    real(DP), intent(in):: xyr_RadSDwFlux  (0:imax-1, 1:jmax, 0:kmax)
                              ! çŸæ³¢ (æ—¥å°„) ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Downward shortwave (insolation) flux

    real(DP), intent(in):: xyr_RadLUwFlux    (0:imax-1, 1:jmax, 0:kmax)
                              ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Upward longwave flux
    real(DP), intent(in):: xyr_RadLDwFlux    (0:imax-1, 1:jmax, 0:kmax)
                              ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Downward longwave flux
    real(DP), intent(in):: xyra_DelRadLUwFlux(0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! é•·æ³¢åœ°è¡¨æ¸©åº¦å¤‰åŒ–.
                              !
    real(DP), intent(in):: xyra_DelRadLDwFlux(0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! é•·æ³¢åœ°è¡¨æ¸©åº¦å¤‰åŒ–.
                              !

    real(DP), intent(in):: xy_DSurfTempDt  (0:imax-1, 1:jmax)
                              ! åœ°è¡¨é¢æ¸©åº¦å¤‰åŒ–çŽ‡.
                              ! Surface temperature tendency
    real(DP), intent(in):: xyz_DTempDt     (0:imax-1, 1:jmax, 1:kmax)
                              ! $ \DP{T}{t} $ . æ¸©åº¦å¤‰åŒ– (K s-1)
                              ! Temperature tendency (K s-1)

    ! å‡ºåŠ›ã®ãŸã‚ã®ä½œæ¥å¤‰æ•°
    ! Work variables for output
    !
    real(DP):: xyr_RadSFlux    (0:imax-1, 1:jmax, 0:kmax)
                              ! çŸæ³¢ (æ—¥å°„) ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Shortwave (insolation) flux
    real(DP):: xyr_RadLFlux    (0:imax-1, 1:jmax, 0:kmax)
                              ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Longwave flux
    real(DP):: xyra_DelRadLFlux(0:imax-1, 1:jmax, 0:kmax, 0:1)
                              ! é•·æ³¢åœ°è¡¨æ¸©åº¦å¤‰åŒ–.
                              ! Surface temperature tendency with longwave
    real(DP):: xyr_RadLUwFluxCor(0:imax-1, 1:jmax, 0:kmax)
                              ! è£œæ£ã•ã‚ŒãŸé•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Corrected longwave flux
    real(DP):: xyr_RadLDwFluxCor(0:imax-1, 1:jmax, 0:kmax)
                              ! è£œæ£ã•ã‚ŒãŸé•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Corrected longwave flux
    real(DP):: xyr_RadLFluxCor  (0:imax-1, 1:jmax, 0:kmax)
                              ! è£œæ£ã•ã‚ŒãŸé•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹.
                              ! Corrected longwave flux

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    integer:: k               ! é‰›ç›´æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in vertical direction
    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !

    ! åˆæœŸåŒ–ç¢ºèª
    ! Initialization check
    !
    if ( .not. rad_utils_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬é–‹å§‹
    ! Start measurement of computation time
    !
    call TimesetClockStart( module_name )

    xyr_RadSFlux     = xyr_RadSUwFlux     - xyr_RadSDwFlux
    xyr_RadLFlux     = xyr_RadLUwFlux     - xyr_RadLDwFlux
    xyra_DelRadLFlux = xyra_DelRadLUwFlux - xyra_DelRadLDwFlux

    ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹ã®è£œæ£ ( åœ°è¡¨ãƒ•ãƒ©ãƒƒã‚¯ã‚¹åˆ†ã®è£œæ£ )
    ! Correct longwave flux ( amount of surface flux )
    !
    ! Lines commented out below will be deleted soon (yot, 2010/10/31).
!!$    do k = 0, kmax
!!$      xyr_RadLFluxCor (:,:,k) = &
!!$        &     xyr_RadLFlux (:,:,k) &
!!$        &   + xyra_DelRadLFlux(:,:,k,0) * xy_DSurfTempDt (:,:) * DelTime
!!$    end do
!!$    do k = 0, kmax
!!$      xyr_RadLFluxCor(:,:,k) = &
!!$        &   xyr_RadLFlux(:,:,k) &
!!$        & + (   xy_DSurfTempDt     * xyra_DelRadLFlux(:,:,k,0)   &
!!$        &     + xyz_DTempDt(:,:,1) * xyra_DelRadLFlux(:,:,k,1) ) &
!!$        &   * DelTime
!!$    end do
    do k = 0, kmax
      xyr_RadLUwFluxCor(:,:,k) =                                   &
        &   xyr_RadLUwFlux(:,:,k)                                  &
        & + (   xy_DSurfTempDt     * xyra_DelRadLUwFlux(:,:,k,0)   &
        &     + xyz_DTempDt(:,:,1) * xyra_DelRadLUwFlux(:,:,k,1) ) &
        &   * DelTime
      xyr_RadLDwFluxCor(:,:,k) =                                   &
        &   xyr_RadLDwFlux(:,:,k)                                  &
        & + (   xy_DSurfTempDt     * xyra_DelRadLDwFlux(:,:,k,0)   &
        &     + xyz_DTempDt(:,:,1) * xyra_DelRadLDwFlux(:,:,k,1) ) &
        &   * DelTime
    end do
    xyr_RadLFluxCor = xyr_RadLUwFluxCor - xyr_RadLDwFluxCor

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'OLR', xyr_RadLFluxCor(:,:,kmax) )
    call HistoryAutoPut( TimeN, 'SLR', xyr_RadLFluxCor(:,:,0)    )
    call HistoryAutoPut( TimeN, 'OSR', xyr_RadSFlux   (:,:,kmax) )
    call HistoryAutoPut( TimeN, 'SSR', xyr_RadSFlux   (:,:,0)    )
    call HistoryAutoPut( TimeN, 'RadLUWFLX', xyr_RadLUwFluxCor )
    call HistoryAutoPut( TimeN, 'RadLDWFLX', xyr_RadLDwFluxCor )
    call HistoryAutoPut( TimeN, 'RadSUWFLX', xyr_RadSUwFlux    )
    call HistoryAutoPut( TimeN, 'RadSDWFLX', xyr_RadSDwFlux    )

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'OLRB', xyr_RadLFlux(:,:,kmax) )
    call HistoryAutoPut( TimeN, 'SLRB', xyr_RadLFlux(:,:,0)    )
    call HistoryAutoPut( TimeN, 'OSRB', xyr_RadSFlux(:,:,kmax) )
    call HistoryAutoPut( TimeN, 'SSRB', xyr_RadSFlux(:,:,0)    )
    call HistoryAutoPut( TimeN, 'RadLUWFLXB', xyr_RadLUwFlux )
    call HistoryAutoPut( TimeN, 'RadLDWFLXB', xyr_RadLDwFlux )
    call HistoryAutoPut( TimeN, 'RadSUWFLXB', xyr_RadSUwFlux )
    call HistoryAutoPut( TimeN, 'RadSDWFLXB', xyr_RadSDwFlux )

    ! é•·æ³¢ãƒ•ãƒ©ãƒƒã‚¯ã‚¹ã®è£œæ£ ( åœ°è¡¨ãƒ•ãƒ©ãƒƒã‚¯ã‚¹åˆ†ã®è£œæ£ )
    ! Correct longwave flux ( amount of surface flux )
    !
    ! Lines commented out below will be deleted soon (yot, 2010/10/31).
!!$    do k = 0, kmax
!!$      xyr_RadLFluxCor (:,:,k) = &
!!$        &     xyr_RadLFlux (:,:,k) &
!!$        &   + xyra_DelRadLFlux(:,:,k,0) * xy_DSurfTempDt (:,:) * 2.0d0 * DelTime
!!$    end do
!!$    do k = 0, kmax
!!$      xyr_RadLFluxCor(:,:,k) = &
!!$        &   xyr_RadLFlux(:,:,k) &
!!$        & + (   xy_DSurfTempDt     * xyra_DelRadLFlux(:,:,k,0)   &
!!$        &     + xyz_DTempDt(:,:,1) * xyra_DelRadLFlux(:,:,k,1) ) &
!!$        &   * 2.0_DP * DelTime
!!$    end do
    do k = 0, kmax
      xyr_RadLUwFluxCor(:,:,k) =                                   &
        &   xyr_RadLUwFlux(:,:,k)                                  &
        & + (   xy_DSurfTempDt     * xyra_DelRadLUwFlux(:,:,k,0)   &
        &     + xyz_DTempDt(:,:,1) * xyra_DelRadLUwFlux(:,:,k,1) ) &
        &   * 2.0_DP * DelTime
      xyr_RadLDwFluxCor(:,:,k) =                                   &
        &   xyr_RadLDwFlux(:,:,k)                                  &
        & + (   xy_DSurfTempDt     * xyra_DelRadLDwFlux(:,:,k,0)   &
        &     + xyz_DTempDt(:,:,1) * xyra_DelRadLDwFlux(:,:,k,1) ) &
        &   * 2.0_DP * DelTime
    end do
    xyr_RadLFluxCor = xyr_RadLUwFluxCor - xyr_RadLDwFluxCor

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'OLRA', xyr_RadLFluxCor(:,:,kmax) )
    call HistoryAutoPut( TimeN, 'SLRA', xyr_RadLFluxCor(:,:,0)    )
    call HistoryAutoPut( TimeN, 'OSRA', xyr_RadSFlux   (:,:,kmax) )
    call HistoryAutoPut( TimeN, 'SSRA', xyr_RadSFlux   (:,:,0)    )
    call HistoryAutoPut( TimeN, 'RadLUWFLXA', xyr_RadLUwFluxCor )
    call HistoryAutoPut( TimeN, 'RadLDWFLXA', xyr_RadLDwFluxCor )
    call HistoryAutoPut( TimeN, 'RadSUWFLXA', xyr_RadSUwFlux    )
    call HistoryAutoPut( TimeN, 'RadSDWFLXA', xyr_RadSDwFlux    )

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬ä¸€æ™‚åœæ¢
    ! Pause measurement of computation time
    !
    call TimesetClockStop( module_name )

  end subroutine RadFluxOutput

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

  subroutine RadUtilsInit
    !
    ! rad_utils ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–ã‚’è¡Œã„ã¾ã™.
    ! NAMELIST#rad_utils_nml ã®èªã¿è¾¼ã¿ã¯ã“ã®æ‰‹ç¶šãã§è¡Œã‚ã‚Œã¾ã™.
    !
    ! "rad_utils" module is initialized.
    ! "NAMELIST#rad_utils_nml" is loaded in this procedure.
    !

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

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

    ! ãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›è£œåŠ©
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoAddVariable

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

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

    integer:: unit_nml        ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«ã‚ªãƒ¼ãƒ—ãƒ³ç”¨è£…ç½®ç•ªå·.
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST èªã¿è¾¼ã¿æ™‚ã® IOSTAT.
                              ! IOSTAT of NAMELIST read

    ! NAMELIST å¤‰æ•°ç¾¤
    ! NAMELIST group name
    !
!!$    namelist /rad_utils_nml/ &
!!$      & DiffFact
!!$      & DelTimeLongValue, DelTimeLongUnit, &
!!$      & DelTimeShortValue, DelTimeShortUnit, &
!!$!
!!$      & LongBandNum, &
!!$      & LongAbsorpCoefQVap, LongAbsorpCoefDryAir, &
!!$      & LongBandWeight, LongPathLengthFact, &
!!$!
!!$      & ShortBandNum, &
!!$      & ShortAbsorpCoefQVap, ShortAbsorpCoefDryAir, &
!!$      & ShortBandWeight, ShortSecScat, &
!!$      & ShortAtmosAlbedo, &
!!$!
!!$      & RstInputFile, RstOutputFile
          !
          ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã«ã¤ã„ã¦ã¯åˆæœŸåŒ–æ‰‹ç¶š "rad_utils#RadInit"
          ! ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã®ã“ã¨.
          !
          ! Refer to source codes in the initialization procedure
          ! "rad_utils#RadInit" for the default values.
          !

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

    if ( rad_utils_inited ) return

    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã®è¨å®š
    ! Default values settings
    !

    ! 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_utils_nml,            & ! (out)
!!$        & iostat = iostat_nml )             ! (out)
!!$      close( unit_nml )
!!$
!!$      call NmlutilMsg( iostat_nml, module_name ) ! (in)
!!$    end if

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›ã®ãŸã‚ã®ã¸ã®å¤‰æ•°ç™»éŒ²
    ! Register of variables for history data output
    !
    call HistoryAutoAddVariable( 'OLR', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'outgoing longwave', 'W m-2' )
    call HistoryAutoAddVariable( 'SLR', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'surface longwave', 'W m-2' )
    call HistoryAutoAddVariable( 'OSR', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'outgoing shortwave', 'W m-2' )
    call HistoryAutoAddVariable( 'SSR', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'surface shortwave', 'W m-2' )

    call HistoryAutoAddVariable( 'RadLUWFLX', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'upward longwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadLDWFLX', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'downward longwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadSUWFLX', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'upward shortwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadSDWFLX', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'downward shortwave flux', 'W m-2' )

    call HistoryAutoAddVariable( 'OLRB', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'outgoing longwave', 'W m-2' )
    call HistoryAutoAddVariable( 'SLRB', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'surface longwave', 'W m-2' )
    call HistoryAutoAddVariable( 'OSRB', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'outgoing shortwave', 'W m-2' )
    call HistoryAutoAddVariable( 'SSRB', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'surface shortwave', 'W m-2' )

    call HistoryAutoAddVariable( 'RadLUWFLXB', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'upward longwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadLDWFLXB', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'downward longwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadSUWFLXB', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'upward shortwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadSDWFLXB', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'downward shortwave flux', 'W m-2' )

    call HistoryAutoAddVariable( 'OLRA', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'outgoing longwave', 'W m-2' )
    call HistoryAutoAddVariable( 'SLRA', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'surface longwave', 'W m-2' )
    call HistoryAutoAddVariable( 'OSRA', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'outgoing shortwave', 'W m-2' )
    call HistoryAutoAddVariable( 'SSRA', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'surface shortwave', 'W m-2' )

    call HistoryAutoAddVariable( 'RadLUWFLXA', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'upward longwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadLDWFLXA', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'downward longwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadSUWFLXA', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'upward shortwave flux', 'W m-2' )
    call HistoryAutoAddVariable( 'RadSDWFLXA', &
      & (/ 'lon ', 'lat ', 'sigm', 'time' /), &
      & 'downward shortwave flux', 'W m-2' )

    call HistoryAutoAddVariable( 'DTempDtRadL', &
      & (/ 'lon ', 'lat ', 'sig ', 'time' /), &
      & 'long wave radiative heating rate', 'K s-1' )
    call HistoryAutoAddVariable( 'DTempDtRadS', &
      & (/ 'lon ', 'lat ', 'sig ', 'time' /), &
      & 'short wave radiative heating rate', 'K s-1' )

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
!!$    call MessageNotify( 'M', module_name, 'DiffFact = %f', d = (/ DiffFact /) )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    rad_utils_inited = .true.

  end subroutine RadUtilsInit

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

end module rad_utils