Files

52 lines
1.8 KiB
Matlab

function relHum = Napp_RH_p(T_current,partial_pressure_water)
%Napp_RH_p helper function that calculates the relative humidity for a given temperature and water pressure.
%
% With the relative humidity referenced
% to liquid water (RH_w) as opposed to ice (RH_i), the activity of water
% is: activity_w = RH_{water}/100
%
%
% * Napp_p_RH(T_current,RH)
% * Napp_p_RH([253.15, 263.15, 273.15],[60, 80, 90])
% * Napp_p_RH(273.15-20,80)
%
%
% *input*
% T_current in K: temperature; (format: scalar, or row/column vector)
% partial_pressure_water in mbar: same shape/length as T_current
%
% *output*
% relative humidity in % (RH_{water}), same shape as T_current
%% input validation
if ~isvector(T_current) || ~isvector(partial_pressure_water)
error('Napp_RH_p:InvalidInput','T_current and partial_pressure_water must be scalars or vectors (row or column).');
end
if numel(T_current) ~= numel(partial_pressure_water)
error('Napp_RH_p:InvalidInput','T_current and partial_pressure_water must have the same number of elements.');
end
%%
%
% *water*:
% NIST webbook: Bridgeman and Aldrich, 1964 give parametrisation from 273
% to 303 K in bar. log10(p) = A - B/ (T+C).
A = 5.40221;
B = 1838.675;
C = -31.737;
% work with linear-indexed vectors so mixed row/column orientations of
% T_current and partial_pressure_water don't trigger implicit expansion
p_w = 10.^(A - B./(T_current(:)+C)) .* 1E3; % mbar
RH = (partial_pressure_water(:).*100)./p_w; % elementwise, matches shape of T_current(:)
% return RH in the same shape as T_current
if isrow(T_current)
RH = RH.';
end
relHum = RH;
for i = 1:numel(T_current)
fprintf('RH of %.0f percent at %.1f K (%.1f dC) and %.2f mbar .\n',relHum(i),T_current(i),T_current(i)-273.15,partial_pressure_water(i))
end
end