function GetHumRatioFromSpecificHum(SpecificHum) result(HumRatio)
!+ Return the humidity ratio (aka mixing ratio) from specific humidity.
!+ Reference:
!+ ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 9b (solved for humidity ratio)
real, intent(in) :: SpecificHum
!+ Specific humidity in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
real :: HumRatio
!+ Humidity ratio in lb_H₂O lb_Dry_Air⁻¹ [IP] or kg_H₂O kg_Dry_Air⁻¹ [SI]
if (SpecificHum < 0.0 .or. SpecificHum >= 1.0) then
error stop "Error: specific humidity is outside range [0, 1)"
end if
HumRatio = SpecificHum / (1.0 - SpecificHum)
! Validity check.
HumRatio = max(HumRatio, MIN_HUM_RATIO)
end function GetHumRatioFromSpecificHum