function [rh, rw, ew_salt] = get_rh(q, t, p)
  
% get_rh returns rh, the relative humidity of air above sea-water as a
% percentage, given q, the specific humidity in kg/kg, t, the air temperature
% in degrees Celsius, and p, the air pressure in millibars. The derivation is
% found from Appendix 4 of Gill. The input quantities must all be of the same
% dimensions. rw is the mixing ration in kg/kg and ew_salt is the Kraus
% corrected vapor partial pressure in mb.

% $Id: get_rh.m,v 1.1 2000/03/14 04:32:26 mansbrid Exp $
% Copyright J. V. Mansbridge, CSIRO, Wednesday March  1 17:45:14 EST 2000
  
% Note the correction near the sea surface. We use the 2% given by Gill while
% the CRC Handbook says the correction should be 0.981205

sw_correction = 0.98;

fw = 1 + 1.e-6*p./(4.5 + 0.0006*t.*t);
exponent = (0.7859 + 0.03477*t)./(1 + 0.00412*t);
ew = 10.^exponent;
ew_salt = sw_correction*fw.*ew;
epsilon = 0.62197;
rw = ew_salt*epsilon./(p - ew_salt);
r = q./(1 - q);
rh = 100*r./rw; % convert to percentage
