%
% Calculate saturation mixing ratio for
%           given temperature and pressure
%           using function and subfunction
%
% Input:  T=Temperature [K] and P=Pressure [Pa]
% Output: Rs=Saturation mixing ratio [kg/kg]
%
% Author: Xin-Zhong Liang, 2012-08-25
%
function [Rs] = RsCalc (T, P)
Es = EsCalc(T);
Rs = 0.622 .* (Es ./ (P - Es));
end

% Output: Es=Saturation vapor pressure [Pa]
function [Es] = EsCalc (T)
Es = 611 * ( 10 .^ (7.5 * (T-273.15) ./ (T-35.85)) );
end