!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine LatentHeat
!
!   * Developer: KITAMORI Taichi 
!   * Version: $Id: latentheat.f90,v 1.5 2011-10-25 08:24:02 yamasita Exp $
!   * Tag Name: $Name: arare4-20120511 $
!   * Change History: 
!
!== Overview 
!
! 凝結量から凝結熱を計算する. 
! 密度を全気相密度で評価. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!
!
!== Future Plans
!
                                                                 !=end
subroutine LatentHeat(xz_Masscond,         & !(in) 凝結量
  &                   xz_Exner,            & !(in) エクスナー関数擾乱成分
  &                   xz_PotTemp,          & !(in) 温位擾乱成分
  &                   xz_Qcond)              !(out) 凝結熱による温度変化率
                                                                 !=begin
  !==Dependency
  use dc_trace, only: BeginSub, EndSub  
  use gridset,  only: DimXMin, DimXMax, DimZMin, DimZMax
!  use physset,  only: GasR              ! 気体定数
!  use cloudset, only: SatPressB         ! Antoine の式の係数 B
!  use ChemData, only: ChemData_SVapPress_AntoineB, & ! Antoine の式の係数 B
!    &                 ChemData_Cp        ! 湿潤成分の定圧比熱
  use basicset, only: xz_DensBasicZ,  &  ! 密度基本場 
    &                 xz_ExnerBasicZ, &  ! 無次元圧力基本場
    &                 xz_PotTempBasicZ, &  ! 温位基本場
!    &                 ss_CpBasicZ, &    ! 定圧比熱
    &                 GasRDry, &         ! 気体定数
    &                 CpDry, &           ! 定圧比熱
    &                 CvDry, &           ! 定積比熱
    &                 PressSfc, &        ! 地表面圧力
    &                 LatHeatPerMass     ! CO2 の単位質量あたりの潜熱
  use StorePotTemp, only: StorePotTempCond
                                                                 !=end
  !==暗黙の型宣言を禁止
  implicit none
  
  !==Input
!  real(8)                :: xz_LatHeatPerMass(DimXMin:DimXMax, DimZMin:DimZMax)
!                                           ! 単位質量あたりの潜熱 [J/kg]
  real(8)                :: xz_Masscond(DimXMin:DimXMax, DimZMin:DimZMax) 
                                           ! 凝結量 [kg/m^3 s]
  real(8)                :: xz_DensAll(DimXMin:DimXMax, DimZMin:DimZMax) 
                                           ! 気相密度の全量 [kg/m^3]
  real(8)                :: xz_Exner(DimXMin:DimXMax, DimZMin:DimZMax)
                                           ! エクスナー関数擾乱成分
  real(8)                :: xz_PotTemp(DimXMin:DimXMax, DimZMin:DimZMax) 
                                           ! 温位擾乱成分 [K]

  !==Output
  real(8), intent(out)   :: xz_Qcond(DimXMin:DimXMax, DimZMin:DimZMax) 
                                           ! 凝結熱による温度変化率 [K/s]
  
  !==Work

  call BeginSub("LatentHeat", &
&           fmt="%c",        &
&           c1="Calculate potential temperature tendency bylatent heating.")

  xz_DensAll = &
   & ( PressSfc / GasRDry ) &
   & * (xz_Exner + xz_ExnerBasicZ) ** (CvDry / GasRDry) &
   & / (xz_PotTemp + xz_PotTempBasicZ)

  xz_Qcond = LatHeatPerMass * xz_Masscond &
    & / (CpDry * xz_DensAll * xz_ExnerBasicZ)

  call StorePotTempCond( xz_QCond )

  call EndSub("LatentHeat")

end subroutine LatentHeat
