!= dcrtm flux 計算 主プログラム
!
!= dcrtm flux calculation main program
!
! Authors::   Masanori Onishi
! Version::   $Id: main_dcrtm.f90,v 1.00 onishi$
! Tag Name::  $Name: dcrtm-20160908 $
! Copyright:: Copyright (C) GFD Dennou Club, 2008-2015. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]

program main_flux
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !

  ! モジュール引用 ; USE statements
  !

  use flux, only : calc_flux

  use rad_ckd_utils, only : GetDimLen


  ! 宣言文 ; Declaration statements
  !
  implicit none

  ! 設定変数, 他
  ! setteing parameter, values
  !
  integer :: Flag_InputFormat
                          ! 入力物理量の指定フラグ
                          ! flag of input value 
                          ! 1: optical depth and single scattering albedo
                          ! 2: absorption, scattering coefficient
  character(99) :: InFileName
                          ! 入力 ファイル名
                          ! input file name
  character(99) :: OutFileFlux
                          ! 出力ファイル名
                          ! output file name
  real(8) :: SolTemp
                          ! 中心星表面温度 [K]
                          ! surface temperature of central star [K]
  real(8) :: SolConst
                          ! 太陽定数 [W m-2]
                          ! solar constant [W m-2]
  real(8) :: InAngle
                          ! sec (太陽光入射角) [1]
                          ! sec (angle of incidence) [1]
  real(8) :: SurfAlbedo
                          ! 地表面アルベド [1]
                          ! surface albedo [1]

  real(8), allocatable :: r_Press(:)
                          ! 気圧 (半整数レベル) [Pa]
                          ! pressure (half level) [Pa]

  real(8), allocatable :: r_RadUwFlux    (:)
                          ! upward flux
  real(8), allocatable :: r_RadDwFlux    (:)
                          ! downward flux


  integer :: kmax

  integer :: fnml = 50


  ! namelist file の設定
  ! setting of namelist file
  !
  namelist /flux_nml/ &
    & Flag_InputFormat,&
    & InFileName,      &
    & OutFileFlux,     &
    & SurfAlbedo,      & 
    & SolTemp,         & 
    & SolConst,        & 
    & InAngle


  ! namelist file の読み込み
  ! read namelist file
  !
  open(fnml, file='dcrtm.nml')
  read(fnml, nml=flux_nml)
  close(fnml)
  print *, SurfAlbedo, SolTemp, SolConst, InAngle


  kmax = GetDimLen( InFileName, 'r_Press' ) - 1

  allocate( r_Press(0:kmax) )
  allocate( r_RadUwFlux(0:kmax) )
  allocate( r_RadDwFlux(0:kmax) )

  call calc_flux( &
    & Flag_InputFormat, InFileName, OutFileFlux, &
    & SolTemp, SolConst, InAngle, SurfAlbedo, &
    & kmax, &
    & r_Press, r_RadUwFlux, r_RadDwFlux &
    & )

end program main_flux
