1 function q = q_from_rh( rh, P, T)
3 % rh - relative humidity [1]
4 % P - atmospheric pressure [pa]
5 % T - atmospheric temperature [K]
7 % q - water vapor mixing ratio [kg/kg]
9 epsilon = 0.622; % Molecular weight of water (18.02 g/mol) to molecular weight of dry air (28.97 g/mol)
11 % saturation vapor pressure [Pa]
12 Pws= exp( 54.842763 - 6763.22/T - 4.210 * log(T) + 0.000367*T + ...
13 tanh(0.0415*(T - 218.8)) * (53.878 - 1331.22/T - 9.44523 * log(T) + 0.014025*T));
15 Pw = rh*Pws; % vapor pressure [Pa]
18 % Pw=q*P/(epsilon+(1-epsilon)*q);
20 rPw = Pw/P; % relative vapor pressure
22 % rPw = q*/(epsilon+(1-epsilon)*q)
23 % rPw*epsilon+rPw*(1-epsilon)*q = q
24 % rPw*epsilon = -rPw*(1-epsilon)*q + q
26 q = rPw*epsilon/(1-rPw*(1-epsilon));