function [w,q,rh] = psychrometric (t,tw,p)
% computes mixing ratio, specific humidity and RH from the wet bulb
% depression and pressure

Mw=18.01528;    % molar mass of H20 g/mol
Md=28.964;      % mean molar mass dry air g/mol
epsilon=Mw/Md;  % mass of water to mass of dry air 0.622
Lv=(2.501-0.00237*t)*1e6;  % Latent heat of vaporization
Cp=1005.6+0.0172*t+0.000392*t.^2; % specific heat (J/kg/degC)

es=svp(t,p);    % saturation vapor pressure (mv)
e=svp(tw,p)-[(Md*Cp)./(Mw*Lv)].*(t-tw).*p; % saturation vapor pressure at wet-bulb temperature (mb)

w=(epsilon*e)./(p-e);  % mixing ratio (g/kg)
q=epsilon.*1000.*(e./(p-(1-epsilon).*e));  % specific humidity (g/kg)
rh=100*(e./es);  % relative humidity (%)