Files

64 lines
2.2 KiB
Matlab

function T = Napp_T_ice(p_current)
%Napp_T_ice marks one or more vapour pressures in a plot of the vapour
% pressure of ice between 200-273 K and returns the corresponding ice
% temperature(s). It also displays the temperature (in K and dC) at each
% pressure in the command window.
%
% * Napp_T_ice(p_current)
% * T = Napp_T_ice([0.5, 1.0, 2.0])
%
% *input*
% p_current in mbar: vapour pressure of ice; (format: scalar, or row/column
% vector)
%
% *output*
% temperature of ice in K (same shape as p_current)
%
% The double + mustBePositive validation in the arguments block gives type
% checking and editor argument hints (autocomplete) for the input. Size is
% checked separately below so both row and column vectors are accepted.
arguments
p_current double {mustBePositive}
end
if ~isvector(p_current)
error('Napp_T_ice:InvalidInput','p_current must be a scalar or a vector (row or column).');
end
%% Water vapour pressure above the ice.
T_range = 200:0.2:273; % K, temperature range for the reference curve
% Marti, J., and K. Mauersberger, Geophys. Res. Lett., 20, 363-366, 1993.
% parameterization from 169 - 273K in Pa: log10(p[Pa]) = A1/T + B
A_1 = -2663.5;
B_1 = 12.537;
p_i = 10.^(A_1./T_range + B_1).*1E-5.*1E3; % mbar, reference curve
%% plot the reference curve (once)
figure( 'Name', 'vapour pressure over ice')
axes('Parent',gcf,'XDir','reverse','FontSize',16);
box on
hold on
% vapour pressure over ice
plot(p_i,T_range,'LineWidth',2)
xlim([0 6.5]);
ylim([220 275]);
xticks(0:0.5:6.5)
grid on
grid minor
title('vapour pressure over ice');
xlabel('p [mbar]');
ylabel('temperature [K]');
%% loop through each pressure: add marker to the same plot and write to command line
T = zeros(size(p_current)); % preallocate output
for i = 1:length(p_current)
% invert log10(p[Pa]) = A1/T + B1 -> T = A1 / (log10(p[Pa]) - B1)
% p_current is in mbar, so p[Pa] = p_current ./ (1E-5.*1E3)
T(i) = A_1 ./ (log10(p_current(i)./(1E-5.*1E3)) - B_1); % K
plot(p_current(i),T(i),'x','MarkerSize',25,'LineWidth',3);
text(p_current(i),T(i),[' <- ' num2str(p_current(i)) ' mbar'],'FontSize',12);
fprintf('The ice temperature at %.2f mbar is %.1f K (%.3f dC) \n',p_current(i),T(i),T(i)-273.15)
end
end