function GetHumRatioFromVapPres(VapPres, Pressure) result(HumRatio)
!+ Return humidity ratio given water vapor pressure and atmospheric pressure.
!+ Reference:
!+ ASHRAE Fundamentals (2005) ch. 6 eqn. 22;
!+ ASHRAE Fundamentals (2009) ch. 1 eqn. 22.
real, intent(in) :: VapPres
!+ Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]
real, intent(in) :: Pressure
!+ Atmospheric pressure in Psi [IP] or Pa [SI]
real :: HumRatio
!+ Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
if (VapPres < 0.0) then
error stop "Error: partial pressure of water vapor in moist air cannot be negative"
end if
HumRatio = 0.621945 * VapPres / (Pressure-VapPres)
! Validity check.
HumRatio = max(HumRatio, MIN_HUM_RATIO)
end function GetHumRatioFromVapPres