!= 菴輔ｂ縺励↑縺�叛蟆�Δ繝�Ν
!
!= radiation model with no absorption and no scattering
!
! Authors::   Yoshiyuki O. Takahashi
! Version::   $Id: rad_none.f90,v 1.1 2015/01/31 06:17:21 yot Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!
module rad_none
  !
  != 菴輔ｂ縺励↑縺�叛蟆�Δ繝�Ν
  !
  != radiation model with no absorption and no scattering
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  !== References
  !
  !
  !== Procedures List
  !
  ! RadEarthV2Flux :: 謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ縺ｮ險育ｮ�
  ! ------------          :: ------------
  ! RadEarthV2Flux :: Calculate radiation flux
  !
  !== NAMELIST
  !
  ! NAMELIST#rad_Earth_V2_nml
  !

  ! USE statements
  !

  !
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! Double precision.
    &                 STRING, &  ! Strings.
    &                 TOKEN      ! Keywords.

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

  ! 譬ｼ蟄千せ險ｭ螳�
  ! 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

  implicit none

  private

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

  public :: RadNoneFlux
  public :: RadNoneInit

  character(*), parameter:: module_name = 'rad_none'
                              ! 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ蜷咲ｧｰ.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: rad_none.f90,v 1.1 2015/01/31 06:17:21 yot Exp $'
                              ! 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ繝舌�繧ｸ繝ｧ繝ｳ
                              ! Module version

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

contains

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

  subroutine RadNoneFlux(                                      &
    & xy_SurfAlbedo,                                           & ! (in)
    & xy_SurfTemp,                                             & ! (in)
    & xyr_RadSUwFlux, xyr_RadSDwFlux,                          & ! (out)
    & xyr_RadLUwFlux, xyr_RadLDwFlux,                          & ! (out)
    & xyra_DelRadLUwFlux, xyra_DelRadLDwFlux                   & ! (out)
    & )

    ! USE statements
    !

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

    ! 螟ｪ髯ｽ謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ縺ｮ險ｭ螳�
    ! Set solar constant
    !
    use set_solarconst, only : SetSolarConst

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

    real(DP), intent(in ) :: xy_SurfAlbedo   (0:imax-1, 1:jmax)
    real(DP), intent(in ) :: xy_SurfTemp     (0:imax-1, 1:jmax)
    real(DP), intent(out) :: xyr_RadSUwFlux    (0:imax-1, 1:jmax, 0:kmax)
    real(DP), intent(out) :: xyr_RadSDwFlux    (0:imax-1, 1:jmax, 0:kmax)
    real(DP), intent(out) :: xyr_RadLUwFlux    (0:imax-1, 1:jmax, 0:kmax)
    real(DP), intent(out) :: xyr_RadLDwFlux    (0:imax-1, 1:jmax, 0:kmax)
    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) :: SolarConst
    real(DP) :: DistFromStarScld
    real(DP) :: DiurnalMeanFactor
    real(DP) :: SolarFluxTOA
    real(DP) :: xy_CosSZA(0:imax-1, 1:jmax)

    integer :: i
    integer :: j
    integer :: k

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

    ! 螟ｪ髯ｽ謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ縺ｮ險ｭ螳�
    ! Set solar constant
    !
    call SetSolarConst( &
      & SolarConst      & ! (out)
      & )

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

    SolarFluxTOA = SolarConst / DistFromStarScld**2 * DiurnalMeanFactor

    do k = 0, kmax
      do j = 1, jmax
        do i = 0, imax-1
          if ( xy_CosSZA(i,j) >= 0.0_DP ) then
            xyr_RadSDwFlux(i,j,k) = SolarFluxTOA * xy_CosSZA(i,j)
          else
            xyr_RadSDwFlux(i,j,k) = 0.0_DP
          end if
        end do
      end do
    end do
    do k = 0, kmax
      xyr_RadSUwFlux(:,:,k) = xy_SurfAlbedo * xyr_RadSDwFlux(:,:,k)
    end do

    do k = 0, kmax
      xyr_RadLUwFlux(:,:,k) = StB * xy_SurfTemp**4
    end do
    xyr_RadLDwFlux     = 0.0_DP
    xyra_DelRadLUwFlux = 0.0_DP
    xyra_DelRadLDwFlux = 0.0_DP

    ! Output variables
    !

  end subroutine RadNoneFlux

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

  subroutine RadNoneInit

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

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

    ! 螟ｪ髯ｽ謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ縺ｮ險ｭ螳�
    ! Set solar constant
    !
    use set_solarconst, only : SetSolarConstInit

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

    ! 螳｣險譁� ; 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_Earth_V2_nml/ &
!!$      & CloudIceREffMethod,     &
!!$      & CloudWatREff,           &
!!$      & CloudIceREff

!!$      & SWVer, LWVer
          !
          ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｫ縺､縺�※縺ｯ蛻晄悄蛹匁焔邯� "rad_Earth_V2#RadEarthV2Init"
          ! 縺ｮ繧ｽ繝ｼ繧ｹ繧ｳ繝ｼ繝峨ｒ蜿ら�縺ｮ縺薙→.
          !
          ! Refer to source codes in the initialization procedure
          ! "rad_Earth_V2#RadEarthV2Init" for the default values.
          !

    if ( rad_none_inited ) return

    ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｮ險ｭ螳�
    ! Default values settings
    !
!!$    SWVer = 1
!!$    LWVer = 3

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

    ! 螟ｪ髯ｽ謾ｾ蟆�ヵ繝ｩ繝�け繧ｹ縺ｮ險ｭ螳�
    ! Set solar constant
    !
    call SetSolarConstInit

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

    ! 蜊ｰ蟄� ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
!!$    call MessageNotify( 'M', module_name, 'SWVer = %d', i = (/ SWVer /) )
!!$    call MessageNotify( 'M', module_name, 'LWVer = %d', i = (/ LWVer /) )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    rad_none_inited = .true.

  end subroutine RadNoneInit

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

end module rad_none