function y=rh2q(t,rh,p,label)

%Compute H2O in mmol/mol for spanning Wade's closed path Licors.
% % y=rh2q(t,h,p)
% % t %air temp in degC
% % rh %rel hum (%) 
% % p %pressure mb

e=6.112.*exp(17.67.*t./(t+243.5)).*rh/100; %partial pressure in mb
q=e*622./(p-.378*e);   %air specific humidity (g/kg)

rho_air=p*100./(273.15+t)./287;   %density of dry air (kg/m3)
% rho_air=p*100./((273.15+t).*287.*(1+0.61.*q));   %density of moist air (kg/m3)

switch lower(label)
    case 'mmol/m3'
        disp('Water vapor in mmol/m3: ')
        w=q.*rho_air*1000/18;  %water vapor in mmol/m3
        y=w;
    case 'g/m3'
        disp('Water vapor in g/m3: ')
        w=q.*rho_air; %water vapor in mmol/m3
        y=w;    
    case 'mmol/mol'
        w=q.*rho_air*1000/18;  %water vapor in mmol/m3
        disp('Water vapor in mmol/mol: ')
        wf=(w.*8.314.*(t+273.15))./(1000.*(p./10)); %water vapor in mmol/mol;
        y=wf;
end;


