!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Module PhysSet
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: physset.f90,v 1.2.4.2 2006/01/13 06:55:05 sugiyama Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!物理定数設定用モジュール
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
                                                                 !=end

module physset

  implicit none
  save

  !== Public Interface
  real(8)  :: Grav          !重力
  real(8)  :: TempSfc       !標準温度               [K]
  real(8)  :: PressSfc      !標準圧力               [Pa]
  real(8)  :: GasRUniv      !普遍気体定数           [J/K mol]
  real(8)  :: Pi            !円周率                 []
  real(8)  :: TempRef       !標準温度               [K]
  real(8)  :: PressRef      !標準圧力               [Pa]
  real(8)  :: CpDryMol      !乾燥成分の平均定圧比熱 [J/K mol]
  real(8)  :: CpDry         !乾燥成分の平均定圧比熱 [J/K kg]
  real(8)  :: CvDry         !乾燥成分の平均定積比熱 [J/K kg]
  real(8)  :: MolWtDry      !乾燥成分の平均分子量   [kg/mol]
  real(8)  :: GasRDry       !乾燥成分の気体定数     [J/K mol]
  real(8)  :: CpWetMol      !乾燥成分の平均定圧比熱 [J/K mol]
  real(8)  :: CpWet         !乾燥成分の平均定圧比熱 [J/K kg]
  real(8)  :: CvWet         !乾燥成分の平均定積比熱 [J/K kg]
  real(8)  :: MolWtWet      !乾燥成分の平均分子量   [kg/mol]
  real(8)  :: GasRWet       !乾燥成分の気体定数     [J/K mol]
  real(8)  :: LatentHeatMol !モル当たりの潜熱       [J/mol]
  real(8)  :: LatentHeat    !潜熱                   [J/kg]
  real(8)  :: epsilon       ! 乾燥成分と湿潤成分の分子量比 []
                                                                 !=end
contains
  !== Procedure Interface 
  !
  !=== Initialize module and acquire NAMELIST
  !
  !NAMELIST から物理定数を読み込む
  !
  subroutine physset_init(cfgfile)
    !=== Dependency
    use dc_trace,      only: BeginSub, EndSub 

    character(*), intent(in) :: cfgfile

    !=== NAMELIST
    NAMELIST /physset/ Grav, TempSfc, PressSfc, &
         &             GasRUniv, Pi, TempRef, PressRef, &
         &             CpDryMol, CpWetMol, MolWtDry, MolWtWet, LatentHeatMol

    call BeginSub("physset_init", &
&                 fmt="%c",       &
&                 c1="Initialize parameters of physics. ")

    open (10, FILE=cfgfile)
    read(10, NML=physset)
    close(10)

    !=== 単位系を mol から kg へ変換
    !==== 気体定数 (乾燥成分)
    GasRDry = GasRUniv / MolWtDry 
    GasRWet = GasRUniv / MolWtWet
    
    !==== 比熱
    CpDry   =   CpDryMol / MolWtDry 
    CpWet   =   CpWetMol / MolWtWet

    CvDry   = ( CpDryMol - GasRUniv ) / MolWtDry
    CvWet   = ( CpWetMol - GasRUniv ) / MolWtWet

    !==== 潜熱 
    LatentHeat = LatentHeatMol / MolWtWet
    
    !==== 分子量比
    epsilon = MolWtWet / MolWtDry

    !==== 確認
    write(*,*) "Grav    ", Grav
    write(*,*) "Pi      ", Pi
    write(*,*) "TempRef ", TempRef
    write(*,*) "TempSfc ", TempSfc
    write(*,*) "PressRef", PressRef
    write(*,*) "PressSfc", PressSfc

    write(*,*) "CpDryMol", CpDryMol
    write(*,*) "CpDry   ", CpDry
    write(*,*) "CpWetMol", CpWetMol
    write(*,*) "CpWet   ", CpWet

    write(*,*) "CvDry   ", CvDry
    write(*,*) "CvWet   ", CvWet

    write(*,*) "MolWtDry", MolWtDry
    write(*,*) "MolWtWet", MolWtWet

    write(*,*) "GasRUniv", GasRUniv
    write(*,*) "GasRDry ", GasRDry
    write(*,*) "GasRWet ", GasRWet

    write(*,*) "LatentHeatMol", LatentHeatMol
    write(*,*) "LatentHeat   ", LatentHeat

    call EndSub("physset_init")

  end subroutine physset_init

end module physset


