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