!= ä½•ã‚‚ã—ãªã„æ”¾å°„ãƒ¢ãƒ‡ãƒ«
!
!= 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