!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2005. All rights reserved.
!---------------------------------------------------------------------
! physics_radiation_incoming.f90 
!
! History
!   2005/09/21 Yamada Yukiko     create
!

module physics_radiation_incoming_mod

  implicit none

  private
  public :: physics_radiation_incoming

contains

  subroutine physics_radiation_incoming( &
         & xy_IncomRadSFlux        , & ! (out) 長波フラックス
         & xy_InAngle              , &! (out) sec(入射角)
         & y_Lat                    )

    !==== Dependency
    use type_mod,    only: REKIND, DBKIND, INTKIND, TOKEN, STRING
    use grid_3d_mod, only: im, jm, km
    use constants_mod, only: PI  
    use dc_trace,    only: SetDebug, BeginSub, EndSub, DbgMessage, DataDump

    implicit none

    !==== Output
    !
    real(DBKIND), intent(out) :: &
         & xy_IncomRadSFlux(im,jm) , & ! (out) 長波フラックス
         & xy_InAngle(im,jm)           ! (out) sec(入射角)

    !==== Input
    !
    real(DBKIND), intent(in) :: y_Lat(jm)

    !----- 作業用内部変数 -----
    character(STRING),  parameter:: subname = "physics_radiation_incoming"

    ! do ループ用作業変数 (東西 i*、南北 j*、鉛直 k*、波数 l*用)
    integer(INTKIND)    :: i, j

    real(DBKIND), parameter :: SolarCoeff = 1380.0d0 !" 太陽定数
    real(DBKIND), parameter :: AtmosAlbedo = 0.2     !" 大気アルベド
    real(DBKIND), parameter :: EPSORB = 23.5          !" 赤道傾斜角
    real(DBKIND), parameter :: EQNORB = 110.         !" 昇降点黄経
    real(DBKIND), parameter :: AINS   = 0.127        !" 年平均入射の係数
    real(DBKIND), parameter :: BINS   = 0.183        !" 年平均入射の係数
    real(DBKIND), parameter :: AZET   = 0.410        !" 年平均入射角の係数
    real(DBKIND), parameter :: BZET   = 0.590        !" 年平均入射角の係数
    
    continue

    !----------------------------------------------------------------
    !   開始処理
    !----------------------------------------------------------------
    call BeginSub(subname)

    !----------------------------------------------------------------
    !   日射計算
    !----------------------------------------------------------------

    ! ---- 年・日平均日射 ----
    do i = 1, im
       do j = 1, jm
          xy_IncomRadSFlux(i,j) = - SolarCoeff * (1. - AtmosAlbedo ) &
               &  * ( AINS + BINS * Cos( y_Lat( J )*PI/180. )**2 )
          
          if ( xy_IncomRadSFlux(i,j) .LT. 0. ) then
             xy_InAngle(i,j) = &
                  & 1. / ( AZET + BZET * Cos( y_Lat( J )*PI/180. )**2 )
          else
             xy_IncomRadSFlux(i,j) = 0.0d0
             xy_InAngle(i,j) = 0.0d0
          ENDIF
       end do
    end do

    !----------------------------------------------------------------
    !   終了処理
    !----------------------------------------------------------------
    call EndSub(subname)

  end subroutine physics_radiation_incoming


end module physics_radiation_incoming_mod
















