<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://gfi.wiki.uib.no/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ywe041</id>
	<title>gfi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://gfi.wiki.uib.no/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ywe041"/>
	<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/Special:Contributions/Ywe041"/>
	<updated>2026-11-15T02:03:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1401</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1401"/>
		<updated>2020-10-19T15:44:36Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process by only taking into account of the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions. The transport resistance is here assumed to be purely due to diffusion (i.e.  &amp;lt;math&amp;gt;\rho \propto D^{-1} &amp;lt;/math&amp;gt;).  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;4&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_{lv}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{lv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{1+\delta_0}{f+\alpha(1-f)}-1 &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| C--G model&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{\alpha-1} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = (1+\delta_0)f^{\alpha-1}-1 &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{\alpha_{vl}-h\frac{R_a}{R_l}}{(1-h)\frac{D}{D&#039;}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{vl} &amp;lt; 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_{sv} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2_CG.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. &lt;br /&gt;
&lt;br /&gt;
Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). In addition, the result of C--G evaporation model (i.e. open system including feedback from a &amp;quot;free atmosphere&amp;quot; which has fixed isotope compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰) and a fixed relative humidity (RH = 75 %)) is also presented (red). &lt;br /&gt;
&lt;br /&gt;
Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.&lt;br /&gt;
 &lt;br /&gt;
The equations used in this figure can be found in Table 1.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil);&lt;br /&gt;
%                  system: closed system = 0, open system = 1, C--G model = 2; &lt;br /&gt;
%                  optional: relative humidity (default = 1), d18Oa (permil), d2Ha (permil)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included the case of kinetic effect &lt;br /&gt;
% and the case of C--G model, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h,d18Oa,d2Ha)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% relative humidity&lt;br /&gt;
if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
    h = 1;&lt;br /&gt;
end&lt;br /&gt;
% isotope composition of &amp;quot;free atmosphere&amp;quot;&lt;br /&gt;
% if not existing, default it to the equilibrium vapour of global average precipitation &lt;br /&gt;
if ~exist(&#039;d18Oa&#039;,&#039;var&#039;)&lt;br /&gt;
    d18Oa = -13;  &lt;br /&gt;
end&lt;br /&gt;
if ~exist(&#039;d2Ha&#039;,&#039;var&#039;)&lt;br /&gt;
    d2Ha = -94;  &lt;br /&gt;
end&lt;br /&gt;
R18Oa = (d18Oa/1000+1)*R18std;&lt;br /&gt;
R2Ha = (d2Ha/1000+1)*R2std;&lt;br /&gt;
&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (0) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1; % iteration steps&lt;br /&gt;
    n = 1; % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
       &lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        ak_18O = 1/(1/D18^n*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/D2^n*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(i) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(i) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(i) = data.d2Hv_acc2(i)-8*data.d18Ov_acc2(i);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in a &amp;quot;free atmosphere&amp;quot; of fixed humidity and isotope composition (C--G model)&lt;br /&gt;
if system == 2&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    % n~0.5 for an open water body under natural conditions, n~0.58 for a falling raindrop (Stewart1975), n~1 for soils and leaves &lt;br /&gt;
    n = 1; &lt;br /&gt;
    df = 0.02;&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    &lt;br /&gt;
    for f = 1:-df:0 % remaining liquid fraction&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        if i==1&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/R18O0) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/R2H0) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1;&lt;br /&gt;
            R18Ol = R18O0*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
        else&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/data.R18Ol(i-1)) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/data.R2Hl(i-1)) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1-df; % fraction remaining relative to previous stage&lt;br /&gt;
            R18Ol = data.R18Ol(i-1)*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = data.R2Hl(i-1)*f1^(aeff_2H-1);&lt;br /&gt;
        end&lt;br /&gt;
       &lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
%         % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
%         R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
%         R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
%         % delta value of the accumulated removed vapour&lt;br /&gt;
%         d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
%         d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
%         dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
        % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
        % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
        R18Ov_acc = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
        R2Hv_acc = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
        &lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies at each step during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
% - therefore, the isotope ratio is calculated as: R(n+1) = R(n)(q(n+1)/q(n))^(a-1)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18O0;&lt;br /&gt;
    data.R2H(n) = R2H0;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(a18O(T)-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(a2H(T)-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(a18O(T)-1);  % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(a2H(T)-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
        &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1), and Jouzel and Merlivat, 1984&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(aeff_2H-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaining vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
de_CG = rayleigh_evaporation(T0,d18O0,d2H0,2,h); % C--G model&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(10) = plot(de_CG.f,de_CG.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(11) = plot(de_CG.f,de_CG.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(12) = plot(de_CG.f,de_CG.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-30 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% lgd1.Visible = &#039;off&#039;;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
% lgd2 = legend(a2,pe(4:6),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
% lgd2.FontSize = fs;&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.58 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.79 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% % 4th axes&lt;br /&gt;
a4 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd4 = legend(a4,pe(10:12),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd4_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.88 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd4,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd4_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.41,8.5,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,30)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.60,-3,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.48,-0.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
text(h(1),0.8,1.5,&#039;C-G model&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15)&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsl,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-60 70]);&lt;br /&gt;
set(h(3),&#039;ytick&#039;,-60:20:65);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
% lg = legend(h(2),pc(4:6),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 +lg_pos(4)*0.02 0 lg_pos(4)*0.117]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),1300,-36,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,65)&lt;br /&gt;
text(h(2),2150,-27.5,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50)&lt;br /&gt;
text(h(2),1200,-25,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1400</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1400"/>
		<updated>2020-10-19T00:23:00Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process by only taking into account of the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions. The transport resistance is here assumed to be purely due to diffusion (i.e.  &amp;lt;math&amp;gt;\rho \propto D^{-1} &amp;lt;/math&amp;gt;).  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;4&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_{lv}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{lv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| C--G model&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{\alpha-1} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = (1+\delta_0)f^{\alpha-1}-1 &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{\alpha_{vl}-h\frac{R_a}{R_l}}{(1-h)\frac{D}{D&#039;}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{vl} &amp;lt; 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_{sv} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2_CG.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. &lt;br /&gt;
&lt;br /&gt;
Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). In addition, the result of C--G evaporation model (i.e. open system including feedback from a &amp;quot;free atmosphere&amp;quot; which has fixed isotope compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰) and a fixed relative humidity (RH = 75 %)) is also presented (red). &lt;br /&gt;
&lt;br /&gt;
Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.&lt;br /&gt;
 &lt;br /&gt;
The equations used in this figure can be found in Table 1.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil);&lt;br /&gt;
%                  system: closed system = 0, open system = 1, C--G model = 2; &lt;br /&gt;
%                  optional: relative humidity (default = 1), d18Oa (permil), d2Ha (permil)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included the case of kinetic effect &lt;br /&gt;
% and the case of C--G model, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h,d18Oa,d2Ha)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% relative humidity&lt;br /&gt;
if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
    h = 1;&lt;br /&gt;
end&lt;br /&gt;
% isotope composition of &amp;quot;free atmosphere&amp;quot;&lt;br /&gt;
% if not existing, default it to the equilibrium vapour of global average precipitation &lt;br /&gt;
if ~exist(&#039;d18Oa&#039;,&#039;var&#039;)&lt;br /&gt;
    d18Oa = -13;  &lt;br /&gt;
end&lt;br /&gt;
if ~exist(&#039;d2Ha&#039;,&#039;var&#039;)&lt;br /&gt;
    d2Ha = -94;  &lt;br /&gt;
end&lt;br /&gt;
R18Oa = (d18Oa/1000+1)*R18std;&lt;br /&gt;
R2Ha = (d2Ha/1000+1)*R2std;&lt;br /&gt;
&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (0) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1; % iteration steps&lt;br /&gt;
    n = 1; % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
       &lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        ak_18O = 1/(1/D18^n*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/D2^n*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(i) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(i) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(i) = data.d2Hv_acc2(i)-8*data.d18Ov_acc2(i);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in a &amp;quot;free atmosphere&amp;quot; of fixed humidity and isotope composition (C--G model)&lt;br /&gt;
if system == 2&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    % n~0.5 for an open water body under natural conditions, n~0.58 for a falling raindrop (Stewart1975), n~1 for soils and leaves &lt;br /&gt;
    n = 1; &lt;br /&gt;
    df = 0.02;&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    &lt;br /&gt;
    for f = 1:-df:0 % remaining liquid fraction&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        if i==1&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/R18O0) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/R2H0) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1;&lt;br /&gt;
            R18Ol = R18O0*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
        else&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/data.R18Ol(i-1)) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/data.R2Hl(i-1)) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1-df; % fraction remaining relative to previous stage&lt;br /&gt;
            R18Ol = data.R18Ol(i-1)*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = data.R2Hl(i-1)*f1^(aeff_2H-1);&lt;br /&gt;
        end&lt;br /&gt;
       &lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
%         % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
%         R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
%         R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
%         % delta value of the accumulated removed vapour&lt;br /&gt;
%         d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
%         d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
%         dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
        % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
        % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
        R18Ov_acc = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
        R2Hv_acc = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
        &lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies at each step during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
% - therefore, the isotope ratio is calculated as: R(n+1) = R(n)(q(n+1)/q(n))^(a-1)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18O0;&lt;br /&gt;
    data.R2H(n) = R2H0;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(a18O(T)-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(a2H(T)-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(a18O(T)-1);  % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(a2H(T)-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
        &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1), and Jouzel and Merlivat, 1984&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(aeff_2H-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaining vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
de_CG = rayleigh_evaporation(T0,d18O0,d2H0,2,h); % C--G model&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(10) = plot(de_CG.f,de_CG.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(11) = plot(de_CG.f,de_CG.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(12) = plot(de_CG.f,de_CG.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-30 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% lgd1.Visible = &#039;off&#039;;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
% lgd2 = legend(a2,pe(4:6),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
% lgd2.FontSize = fs;&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.58 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.79 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% % 4th axes&lt;br /&gt;
a4 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd4 = legend(a4,pe(10:12),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd4_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.88 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd4,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd4_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.41,8.5,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,30)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.60,-3,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.48,-0.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
text(h(1),0.8,1.5,&#039;C-G model&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15)&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsl,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-60 70]);&lt;br /&gt;
set(h(3),&#039;ytick&#039;,-60:20:65);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
% lg = legend(h(2),pc(4:6),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 +lg_pos(4)*0.02 0 lg_pos(4)*0.117]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),1300,-36,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,65)&lt;br /&gt;
text(h(2),2150,-27.5,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50)&lt;br /&gt;
text(h(2),1200,-25,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1399</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1399"/>
		<updated>2020-10-19T00:19:52Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process by only taking into account of the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions. The transport resistance is here assumed to be purely due to diffusion (i.e.  &amp;lt;math&amp;gt;\rho \propto D^{-1} &amp;lt;/math&amp;gt;).  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;4&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_{lv}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{lv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| C--G model&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{\alpha-1} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = (1+\delta_0)f^{\alpha-1}-1 &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{\alpha_{vl}-h\frac{R_a}{R_l}}{(1-h)\frac{D}{D&#039;}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{vl} &amp;lt; 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_{sv} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2_CG.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. &lt;br /&gt;
&lt;br /&gt;
Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). In addition, the result of C--G evaporation model (i.e. open system including feedback from a &amp;quot;free atmosphere&amp;quot; which has fixed isotope compositions of $\delta^{18}$O = -13 \permil\ and $\delta$D = -94 \permil\ (\textit{d} = 10 \permil) and a fixed relative humidity (RH = 75 \%)) is also presented (red). &lt;br /&gt;
&lt;br /&gt;
Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.&lt;br /&gt;
 &lt;br /&gt;
The equations used in this figure can be found in Table 1.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil);&lt;br /&gt;
%                  system: closed system = 0, open system = 1, C--G model = 2; &lt;br /&gt;
%                  optional: relative humidity (default = 1), d18Oa (permil), d2Ha (permil)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included the case of kinetic effect &lt;br /&gt;
% and the case of C--G model, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h,d18Oa,d2Ha)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% relative humidity&lt;br /&gt;
if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
    h = 1;&lt;br /&gt;
end&lt;br /&gt;
% isotope composition of &amp;quot;free atmosphere&amp;quot;&lt;br /&gt;
% if not existing, default it to the equilibrium vapour of global average precipitation &lt;br /&gt;
if ~exist(&#039;d18Oa&#039;,&#039;var&#039;)&lt;br /&gt;
    d18Oa = -13;  &lt;br /&gt;
end&lt;br /&gt;
if ~exist(&#039;d2Ha&#039;,&#039;var&#039;)&lt;br /&gt;
    d2Ha = -94;  &lt;br /&gt;
end&lt;br /&gt;
R18Oa = (d18Oa/1000+1)*R18std;&lt;br /&gt;
R2Ha = (d2Ha/1000+1)*R2std;&lt;br /&gt;
&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (0) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1; % iteration steps&lt;br /&gt;
    n = 1; % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
       &lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        ak_18O = 1/(1/D18^n*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/D2^n*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(i) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(i) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(i) = data.d2Hv_acc2(i)-8*data.d18Ov_acc2(i);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in a &amp;quot;free atmosphere&amp;quot; of fixed humidity and isotope composition (C--G model)&lt;br /&gt;
if system == 2&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    % n~0.5 for an open water body under natural conditions, n~0.58 for a falling raindrop (Stewart1975), n~1 for soils and leaves &lt;br /&gt;
    n = 1; &lt;br /&gt;
    df = 0.02;&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    &lt;br /&gt;
    for f = 1:-df:0 % remaining liquid fraction&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        if i==1&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/R18O0) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/R2H0) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1;&lt;br /&gt;
            R18Ol = R18O0*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
        else&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/data.R18Ol(i-1)) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/data.R2Hl(i-1)) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1-df; % fraction remaining relative to previous stage&lt;br /&gt;
            R18Ol = data.R18Ol(i-1)*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = data.R2Hl(i-1)*f1^(aeff_2H-1);&lt;br /&gt;
        end&lt;br /&gt;
       &lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
%         % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
%         R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
%         R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
%         % delta value of the accumulated removed vapour&lt;br /&gt;
%         d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
%         d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
%         dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
        % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
        % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
        R18Ov_acc = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
        R2Hv_acc = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
        &lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies at each step during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
% - therefore, the isotope ratio is calculated as: R(n+1) = R(n)(q(n+1)/q(n))^(a-1)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18O0;&lt;br /&gt;
    data.R2H(n) = R2H0;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(a18O(T)-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(a2H(T)-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(a18O(T)-1);  % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(a2H(T)-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
        &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1), and Jouzel and Merlivat, 1984&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(aeff_2H-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaining vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
de_CG = rayleigh_evaporation(T0,d18O0,d2H0,2,h); % C--G model&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(10) = plot(de_CG.f,de_CG.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(11) = plot(de_CG.f,de_CG.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(12) = plot(de_CG.f,de_CG.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-30 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% lgd1.Visible = &#039;off&#039;;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
% lgd2 = legend(a2,pe(4:6),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
% lgd2.FontSize = fs;&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.58 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.79 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% % 4th axes&lt;br /&gt;
a4 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd4 = legend(a4,pe(10:12),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd4_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.88 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd4,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd4_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.41,8.5,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,30)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.60,-3,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.48,-0.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
text(h(1),0.8,1.5,&#039;C-G model&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15)&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsl,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-60 70]);&lt;br /&gt;
set(h(3),&#039;ytick&#039;,-60:20:65);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
% lg = legend(h(2),pc(4:6),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 +lg_pos(4)*0.02 0 lg_pos(4)*0.117]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),1300,-36,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,65)&lt;br /&gt;
text(h(2),2150,-27.5,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50)&lt;br /&gt;
text(h(2),1200,-25,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1398</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1398"/>
		<updated>2020-10-19T00:17:12Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process by only taking into account of the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions. The transport resistance is here assumed to be purely due to diffusion (i.e.  &amp;lt;math&amp;gt;\rho \propto D^{-1} &amp;lt;/math&amp;gt;).  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;4&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_{lv}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{lv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{vl}&amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| C--G model&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{\alpha-1} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = (1+\delta_0)f^{\alpha-1}-1 &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{\alpha_{vl}-h\frac{R_a}{R_l}}{(1-h)\frac{D}{D&#039;}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{vl} &amp;lt; 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_{sv} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{sv}&amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2_CG.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. &lt;br /&gt;
Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). In addition, the result of C--G evaporation model (i.e. open system including feedback from a &amp;quot;free atmosphere&amp;quot; which has fixed isotope compositions of $\delta^{18}$O = -13 \permil\ and $\delta$D = -94 \permil\ (\textit{d} = 10 \permil) and a fixed relative humidity (RH = 75 \%)) is also presented (red). &lt;br /&gt;
Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used. &lt;br /&gt;
The equations used in this figure can be found in Table 1.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil);&lt;br /&gt;
%                  system: closed system = 0, open system = 1, C--G model = 2; &lt;br /&gt;
%                  optional: relative humidity (default = 1), d18Oa (permil), d2Ha (permil)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included the case of kinetic effect &lt;br /&gt;
% and the case of C--G model, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h,d18Oa,d2Ha)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% relative humidity&lt;br /&gt;
if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
    h = 1;&lt;br /&gt;
end&lt;br /&gt;
% isotope composition of &amp;quot;free atmosphere&amp;quot;&lt;br /&gt;
% if not existing, default it to the equilibrium vapour of global average precipitation &lt;br /&gt;
if ~exist(&#039;d18Oa&#039;,&#039;var&#039;)&lt;br /&gt;
    d18Oa = -13;  &lt;br /&gt;
end&lt;br /&gt;
if ~exist(&#039;d2Ha&#039;,&#039;var&#039;)&lt;br /&gt;
    d2Ha = -94;  &lt;br /&gt;
end&lt;br /&gt;
R18Oa = (d18Oa/1000+1)*R18std;&lt;br /&gt;
R2Ha = (d2Ha/1000+1)*R2std;&lt;br /&gt;
&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (0) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1; % iteration steps&lt;br /&gt;
    n = 1; % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
       &lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        ak_18O = 1/(1/D18^n*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/D2^n*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(i) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(i) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(i) = data.d2Hv_acc2(i)-8*data.d18Ov_acc2(i);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in a &amp;quot;free atmosphere&amp;quot; of fixed humidity and isotope composition (C--G model)&lt;br /&gt;
if system == 2&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    % n~0.5 for an open water body under natural conditions, n~0.58 for a falling raindrop (Stewart1975), n~1 for soils and leaves &lt;br /&gt;
    n = 1; &lt;br /&gt;
    df = 0.02;&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    &lt;br /&gt;
    for f = 1:-df:0 % remaining liquid fraction&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        if i==1&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/R18O0) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/R2H0) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1;&lt;br /&gt;
            R18Ol = R18O0*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
        else&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/data.R18Ol(i-1)) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/data.R2Hl(i-1)) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1-df; % fraction remaining relative to previous stage&lt;br /&gt;
            R18Ol = data.R18Ol(i-1)*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = data.R2Hl(i-1)*f1^(aeff_2H-1);&lt;br /&gt;
        end&lt;br /&gt;
       &lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
%         % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
%         R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
%         R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
%         % delta value of the accumulated removed vapour&lt;br /&gt;
%         d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
%         d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
%         dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
        % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
        % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
        R18Ov_acc = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
        R2Hv_acc = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
        &lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies at each step during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
% - therefore, the isotope ratio is calculated as: R(n+1) = R(n)(q(n+1)/q(n))^(a-1)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18O0;&lt;br /&gt;
    data.R2H(n) = R2H0;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(a18O(T)-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(a2H(T)-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(a18O(T)-1);  % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(a2H(T)-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
        &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1), and Jouzel and Merlivat, 1984&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(aeff_2H-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaining vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
de_CG = rayleigh_evaporation(T0,d18O0,d2H0,2,h); % C--G model&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(10) = plot(de_CG.f,de_CG.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(11) = plot(de_CG.f,de_CG.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(12) = plot(de_CG.f,de_CG.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-30 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% lgd1.Visible = &#039;off&#039;;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
% lgd2 = legend(a2,pe(4:6),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
% lgd2.FontSize = fs;&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.58 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.79 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% % 4th axes&lt;br /&gt;
a4 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd4 = legend(a4,pe(10:12),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd4_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.88 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd4,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd4_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.41,8.5,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,30)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.60,-3,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.48,-0.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
text(h(1),0.8,1.5,&#039;C-G model&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15)&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsl,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-60 70]);&lt;br /&gt;
set(h(3),&#039;ytick&#039;,-60:20:65);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
% lg = legend(h(2),pc(4:6),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 +lg_pos(4)*0.02 0 lg_pos(4)*0.117]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),1300,-36,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,65)&lt;br /&gt;
text(h(2),2150,-27.5,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50)&lt;br /&gt;
text(h(2),1200,-25,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1397</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1397"/>
		<updated>2020-10-19T00:10:06Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process by only taking into account of the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;4&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_l = \frac{R_l}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| C--G model&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{\alpha-1} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = (1+\delta_0)f^{\alpha-1}-1 &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{\alpha_{vl}-h\frac{R_a}{R_l}}{(1-h)\frac{D}{D&#039;}} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_{vl} &amp;lt; 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2_CG.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil);&lt;br /&gt;
%                  system: closed system = 0, open system = 1, C--G model = 2; &lt;br /&gt;
%                  optional: relative humidity (default = 1), d18Oa (permil), d2Ha (permil)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included the case of kinetic effect &lt;br /&gt;
% and the case of C--G model, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h,d18Oa,d2Ha)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% relative humidity&lt;br /&gt;
if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
    h = 1;&lt;br /&gt;
end&lt;br /&gt;
% isotope composition of &amp;quot;free atmosphere&amp;quot;&lt;br /&gt;
% if not existing, default it to the equilibrium vapour of global average precipitation &lt;br /&gt;
if ~exist(&#039;d18Oa&#039;,&#039;var&#039;)&lt;br /&gt;
    d18Oa = -13;  &lt;br /&gt;
end&lt;br /&gt;
if ~exist(&#039;d2Ha&#039;,&#039;var&#039;)&lt;br /&gt;
    d2Ha = -94;  &lt;br /&gt;
end&lt;br /&gt;
R18Oa = (d18Oa/1000+1)*R18std;&lt;br /&gt;
R2Ha = (d2Ha/1000+1)*R2std;&lt;br /&gt;
&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (0) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    i = 1; % iteration steps&lt;br /&gt;
    n = 1; % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
       &lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        ak_18O = 1/(1/D18^n*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/D2^n*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(i) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(i) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(i) = data.d2Hv_acc2(i)-8*data.d18Ov_acc2(i);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in a &amp;quot;free atmosphere&amp;quot; of fixed humidity and isotope composition (C--G model)&lt;br /&gt;
if system == 2&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    % turbulent exponent in D^n, [0 1], controls the ratio of diffusive transport over turbulent transport of water molecules (Pfahl and Wernli, 2009)&lt;br /&gt;
    % n~0.5 for an open water body under natural conditions, n~0.58 for a falling raindrop (Stewart1975), n~1 for soils and leaves &lt;br /&gt;
    n = 1; &lt;br /&gt;
    df = 0.02;&lt;br /&gt;
    i = 1;   % iteration steps&lt;br /&gt;
    &lt;br /&gt;
    for f = 1:-df:0 % remaining liquid fraction&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        D18 = 0.9723;  % D&#039;/D&lt;br /&gt;
        D2 = 0.9755;   % D&#039;/D&lt;br /&gt;
        if i==1&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/R18O0) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/R2H0) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1;&lt;br /&gt;
            R18Ol = R18O0*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
        else&lt;br /&gt;
            aeff_18O = (a18O(T0) - h*R18Oa/data.R18Ol(i-1)) / ((1-h)*1/D18^n);&lt;br /&gt;
            aeff_2H = (a2H(T0) - h*R2Ha/data.R2Hl(i-1)) / ((1-h)*1/D2^n);&lt;br /&gt;
            % isotope ratio of remaining liquid&lt;br /&gt;
            f1 = 1-df; % fraction remaining relative to previous stage&lt;br /&gt;
            R18Ol = data.R18Ol(i-1)*f1^(aeff_18O-1);&lt;br /&gt;
            R2Hl = data.R2Hl(i-1)*f1^(aeff_2H-1);&lt;br /&gt;
        end&lt;br /&gt;
       &lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
%         % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
%         R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
%         R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
%         % delta value of the accumulated removed vapour&lt;br /&gt;
%         d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
%         d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
%         dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
        % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
        % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
        R18Ov_acc = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
        R2Hv_acc = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(i) = T0;&lt;br /&gt;
        data.f(i) = f;&lt;br /&gt;
        data.R18Ol(i) = R18Ol;&lt;br /&gt;
        data.d18Ol(i) = d18Ol;&lt;br /&gt;
        data.d18Ov(i) = d18Ov;&lt;br /&gt;
        data.R2Hl(i) = R2Hl;&lt;br /&gt;
        data.d2Hl(i) = d2Hl;&lt;br /&gt;
        data.d2Hv(i) = d2Hv;&lt;br /&gt;
        data.dxsl(i) = dxsl;&lt;br /&gt;
        data.dxsv(i) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(i) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(i) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(i) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        i = i+1;&lt;br /&gt;
        &lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies at each step during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
% - therefore, the isotope ratio is calculated as: R(n+1) = R(n)(q(n+1)/q(n))^(a-1)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18O0;&lt;br /&gt;
    data.R2H(n) = R2H0;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(a18O(T)-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(a2H(T)-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(a18O(T)-1);  % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(a2H(T)-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
        &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    if n == 1&lt;br /&gt;
        f1 = ws/ws0;&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = R18O0*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1)&lt;br /&gt;
        R2Hv = R2H0*f1^(aeff_2H-1);&lt;br /&gt;
    else&lt;br /&gt;
        f1 = wconc/data.Wconc(n-1); % q(n)/q(n-1)&lt;br /&gt;
        % isotope ratio of remaining vapour&lt;br /&gt;
        R18Ov = data.R18O(n-1)*f1^(aeff_18O-1); % R(n) = R(n-1)(q(n)/q(n-1))^(a-1), and Jouzel and Merlivat, 1984&lt;br /&gt;
        R2Hv = data.R2H(n-1)*f1^(aeff_2H-1);&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaining vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.R18O(n) = R18Ov;&lt;br /&gt;
    data.R2H(n) = R2Hv;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
de_CG = rayleigh_evaporation(T0,d18O0,d2H0,2,h); % C--G model&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(10) = plot(de_CG.f,de_CG.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(11) = plot(de_CG.f,de_CG.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(12) = plot(de_CG.f,de_CG.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-30 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% lgd1.Visible = &#039;off&#039;;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
% lgd2 = legend(a2,pe(4:6),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
% lgd2.FontSize = fs;&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.58 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.79 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% % 4th axes&lt;br /&gt;
a4 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd4 = legend(a4,pe(10:12),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd4_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.88 0 lgd1_pos(4)*0.5]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd4,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd4_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.41,8.5,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,30)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.60,-3,&#039;open&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.48,-0.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
text(h(1),0.8,1.5,&#039;C-G model&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;FontSize&#039;,fs,&#039;Rotation&#039;,15)&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsl,&#039;-&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv,&#039;--&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_CG.f,de_CG.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.8500 0.3250 0.0980],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-60 70]);&lt;br /&gt;
set(h(3),&#039;ytick&#039;,-60:20:65);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-20 50]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
% lg = legend(h(2),pc(4:6),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 +lg_pos(4)*0.02 0 lg_pos(4)*0.117]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),1300,-36,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,65)&lt;br /&gt;
text(h(2),2150,-27.5,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50)&lt;br /&gt;
text(h(2),1200,-25,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,50,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=File:Rayleigh_model_plot_v2_CG.png&amp;diff=1396</id>
		<title>File:Rayleigh model plot v2 CG.png</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=File:Rayleigh_model_plot_v2_CG.png&amp;diff=1396"/>
		<updated>2020-10-19T00:03:56Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1369</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1369"/>
		<updated>2020-09-07T03:45:05Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process by only taking into account of the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_l = \frac{R_l}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1368</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1368"/>
		<updated>2020-09-07T03:13:07Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phases, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_l = \frac{R_l}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1367</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1367"/>
		<updated>2020-09-07T01:22:24Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_l = \frac{R_l}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{α-1} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{α-1}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1366</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1366"/>
		<updated>2020-09-06T15:26:46Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_l = \frac{R_l}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt; \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt; \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1 &amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt; S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1365</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1365"/>
		<updated>2020-09-06T14:52:42Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the calculated isotopic evolution profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1364</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1364"/>
		<updated>2020-09-06T14:50:38Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, following the equation above, the total liquid removal is calculated as &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the ongoing formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1363</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1363"/>
		<updated>2020-09-06T14:44:25Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, the formed liquid removal is calculated following the equation above, i.e., &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the formation of solid phase. Following the same reasoning as above, the isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally and again, using mass conservation of rare isotopes, we obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1362</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1362"/>
		<updated>2020-09-06T14:42:02Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, the formed liquid removal is calculated following the equation above, i.e., &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-fR_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider a separated Rayleigh process considering only the formation of solid phase. The isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally, using mass conservation of rare isotopes, we can obtain the isotope ratio of the total accumulation of the removal by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + f(1-f_i)R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1361</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1361"/>
		<updated>2020-09-06T14:39:54Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, the formed liquid removal is calculated following the equation above, i.e., &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-f*R_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider an independent Rayleigh process considering only the formation of solid phase. The isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_\text{i,v} + (1-f_i)R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;R_\text{i,v}&amp;lt;/math&amp;gt; are the isotope ratio of the remaining vapour at the start and the calculating point of the solid condensation stage, respectively, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally, using mass conservation of rare isotopes, we can obtain the isotope ratio of the total accumulation by &amp;lt;math&amp;gt; (1-ff_i)R_\text{acc} = (1-f)R_\text{l,acc} + (f(1-f_i))R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1360</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1360"/>
		<updated>2020-09-06T14:26:07Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The isotope ratio of the accumulated removal can be derived using mass conservation of rare isotopes between the reservoir and formed removal: &amp;lt;math&amp;gt; fR_\text{remain} + (1-f)R_\text{remove,acc} = R_0 &amp;lt;/math&amp;gt;. In the case of condensation involving both liquid and solid phase, the accumulation is a combination of the formed removal of both phases. First, the formed liquid removal is calculated following the equation above, i.e., &amp;lt;math&amp;gt; R_\text{l,acc} = (R_0-f*R_v)/(1-f) &amp;lt;/math&amp;gt;. Then, we consider an independent Rayleigh process considering only the formation of solid phase. The isotope ratio of the accumulated solid removal is calculated by &amp;lt;math&amp;gt; f_iR_v + (1-f_i)*R_\text{i,acc} = R_\text{v0} &amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R_\text{v0}&amp;lt;/math&amp;gt; is the isotope ratio of the remaining vapour after liquid condensation stage, and &amp;lt;math&amp;gt;f_i&amp;lt;/math&amp;gt; the fraction of remaining vapour within the solid condensation stage. Finally, the total accumulation is a weighting sum of the liquid and solid condensate: &amp;lt;math&amp;gt; (1-f_0*f_i)R_\text{acc} = (1-f_0)R_\text{l,acc} + (f_0(1-f_i))R_\text{i,acc} &amp;lt;/math&amp;gt;. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1359</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1359"/>
		<updated>2020-09-06T13:44:51Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The Rayleigh equations that are used to describe isotopic evolution of the remaining reservoir under different conditions are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations to describe isotopic evolution of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1358</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1358"/>
		<updated>2020-09-06T13:41:16Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The equations that used to describe Rayleigh processes under different conditions are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; colspan=&amp;quot;2&amp;quot;| Equation (&#039;&#039;R&#039;&#039; and &#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1357</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1357"/>
		<updated>2020-09-06T13:39:41Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The equations that used to describe Rayleigh processes under different conditions are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations of the remaining reservoir under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;R&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1356</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1356"/>
		<updated>2020-09-06T04:17:04Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phase system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The functions used to describe different Rayleigh processes are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;R&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1355</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1355"/>
		<updated>2020-09-06T04:15:36Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The functions used to describe different Rayleigh processes are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;R&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1354</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1354"/>
		<updated>2020-09-06T04:14:46Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The functions used to describe different Rayleigh processes are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;R&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing &#039;&#039;N&#039;&#039; abundant isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;68&amp;lt;/sup&amp;gt;O) and &#039;&#039;N&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; rare isotopologues (e.g. H&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O or HD&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1353</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1353"/>
		<updated>2020-09-06T04:10:56Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The functions used to describe different Rayleigh processes are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;R&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H&amp;lt;math&amp;gt;_2^{16}&amp;lt;/math&amp;gt;O) and N_i rare isotopologues (e.g. H&amp;lt;math&amp;gt;_2^{18}&amp;lt;/math&amp;gt;O or HD&amp;lt;math&amp;gt;^{16}&amp;lt;/math&amp;gt;O) small amounts of both species, &amp;lt;math&amp;gt;dN&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;dN_i&amp;lt;/math&amp;gt; respectively, are being removed under equilibrium fractionation conditions: &amp;lt;math&amp;gt; dN_i/dN = αR &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; RN = (R-dR)(N-dN) + αRdN &amp;lt;/math&amp;gt;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &amp;lt;math&amp;gt; R_0N_0 = R(N_0-dN) + αRdN &amp;lt;/math&amp;gt;, with the remaining fraction &amp;lt;math&amp;gt; f = (N_0-dN)/N_0 &amp;lt;/math&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;*e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;. &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039; is the defined saturation ratio, as &#039;&#039;e&amp;lt;sub&amp;gt;v&amp;lt;/sub&amp;gt;/e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&#039;&#039;, and here takes the form &#039;&#039;S&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 1-0.004T&#039;&#039; after Risi &#039;&#039;et al&#039;&#039; (2010a). In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1352</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1352"/>
		<updated>2020-09-06T04:02:20Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The functions used to describe different Rayleigh processes are summarized in Table 1. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ &#039;&#039;Table 1&#039;&#039; Rayleigh equations under different conditions.  &lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| &lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Conditions&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;R&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Equation (&#039;&#039;δ&#039;&#039; notation)&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Fractionation factor used&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot;| Evaporation&lt;br /&gt;
| open system saturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_l = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| open system undersaturated&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \frac{1}{\alpha_k \alpha_l},\quad\text{where}\quad \alpha_l = \frac{R_l}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{D}{D&#039;}(1-h)+h &amp;gt; 1, \quad\text{with}\quad h = \frac{e_v}{e_l} &amp;lt;/math&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
| closed system&lt;br /&gt;
| &amp;lt;math&amp;gt; R = \frac{R_0}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; \delta = \frac{\delta_0-(\alpha-1)(1-f)}{f+\alpha(1-f)} &amp;lt;/math&amp;gt; &lt;br /&gt;
| &amp;lt;math&amp;gt; α = \frac{R_v}{R_l} &amp;lt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;2&amp;quot;| Condensation&lt;br /&gt;
| saturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; α = \alpha_s = \frac{R_s}{R_v} &amp;gt;1 &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| supersaturation over ice&lt;br /&gt;
| &amp;lt;math&amp;gt; R = R_0f^{(α-1)} &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; δ = (1+δ_0)f^{(α-1)}-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; \alpha = \alpha_k \alpha_s, \quad\text{where}\quad \alpha_s = \frac{R_s}{R_v} &amp;gt;1, \quad\text{and}\quad \alpha_k = \frac{S_i}{\alpha_s \frac{D}{D&#039;}(S_i-1)+1} &amp;lt; 1, \quad\text{with}\quad S_i = \frac{e_v}{e_i} &amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 °C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 °C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 °C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1351</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1351"/>
		<updated>2020-09-06T02:38:05Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1). The functions used to describe different Rayleigh processes are summerized in the table below. The examples of the corresponding Rayleigh profiles are shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1350</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1350"/>
		<updated>2020-09-06T02:28:16Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model visualization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1349</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1349"/>
		<updated>2020-09-06T02:27:18Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Example of usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1348</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1348"/>
		<updated>2020-09-06T02:27:01Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Example of usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Generate the desired data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles.&#039;&#039;&#039;&lt;br /&gt;
As an example, Fig. 2 is created using the data sets generated from the above step and using the plotting codes from below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1347</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1347"/>
		<updated>2020-09-06T02:24:40Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Example of usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Create data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profiles. Example of the plots using the data sets generated from the above step is shown in Fig. 2.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1346</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1346"/>
		<updated>2020-09-06T02:22:54Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Example of usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Create data sets&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Plot Rayleigh evaporation and condensation profile. An example of plot is shown in Fig. 2.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1345</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1345"/>
		<updated>2020-09-06T02:21:23Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Example of usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
# Create data sets&lt;br /&gt;
&lt;br /&gt;
The mergetime command will create one new output file with a common time axis. Therefore, all inputfiles must have a common time axis, and the same variables, essentially they must have the same netcdf file format.&lt;br /&gt;
&lt;br /&gt;
Here is an example for how to create a monthly file from the daily TPS-3100 (Hotplate) data files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% create data sets&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
d2H0 = -70;&lt;br /&gt;
h = 0.75; % relative humidity&lt;br /&gt;
de_ok = rayleigh_evaporation(T0,d18O0,d2H0,1,h); % in an open system, unsaturated (including kinetic effect)&lt;br /&gt;
de_oe = rayleigh_evaporation(T0,d18O0,d2H0,1);   % in an open system, saturated (equilibrium)&lt;br /&gt;
de_cl = rayleigh_evaporation(T0,d18O0,d2H0,0);   % in a closed system&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
T0 = 20+273.15;&lt;br /&gt;
RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
d18O0 = -13;&lt;br /&gt;
d2H0 = -94;&lt;br /&gt;
% &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
% = 1: &lt;br /&gt;
% = 0: &lt;br /&gt;
dc_ln = rayleigh_condensation(T0,RH0,d18O0,d2H0,0);   % using linear formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
dc_no = rayleigh_condensation(T0,RH0,d18O0,d2H0,1);   % meaning alpha_k = 1, thus no supersaturation, e = e_ice&lt;br /&gt;
dc_11 = rayleigh_condensation(T0,RH0,d18O0,d2H0,1.1); % using the constant supersaturation as given&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Plot Rayleigh evaporation and condensation profile. An example of plot is shown in Fig. 2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%% plot Rayleigh evaporation and condensation model&lt;br /&gt;
fs = 14;&lt;br /&gt;
&lt;br /&gt;
clear h&lt;br /&gt;
figure&lt;br /&gt;
set(gcf,&#039;color&#039;,&#039;white&#039;,&#039;position&#039;,[0 0 1200 1150],&#039;PaperPositionMode&#039;,&#039;auto&#039;);&lt;br /&gt;
% left_color = [0 0 0]; % black&lt;br /&gt;
% right_color = [0 0.4470 0.7410]; % blueish % blue [0 0 1];&lt;br /&gt;
% set(gcf,&#039;defaultAxesColorOrder&#039;,[left_color; right_color]);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh evaporation&lt;br /&gt;
h(1) = subplot(2,2,1);&lt;br /&gt;
% set(h(1),&#039;Position&#039;, [0.1 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pe(1) = plot(de_ok.f,de_ok.d18Ol,&#039;k-&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(2) = plot(de_ok.f,de_ok.d18Ov,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(3) = plot(de_ok.f,de_ok.d18Ov_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pe(4) = plot(de_oe.f,de_oe.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); %&#039;color&#039;,[0.3010 0.7450 0.9330],&lt;br /&gt;
pe(5) = plot(de_oe.f,de_oe.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(6) = plot(de_oe.f,de_oe.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(7) = plot(de_cl.f,de_cl.d18Ol,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
pe(8) = plot(de_cl.f,de_cl.d18Ov,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
pe(9) = plot(de_cl.f,de_cl.d18Ov_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(h(1),[-27 40]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
lgd1 = legend(h(1),pe(1:3),&#039;residual water&#039;,&#039;instant vapour&#039;,&#039;total vapour removed&#039;,&#039;Location&#039;,&#039;northwest&#039;);&lt;br /&gt;
lgd1_pos = lgd1.Position;&lt;br /&gt;
lgd1.FontSize = fs;&lt;br /&gt;
% 2nd axes&lt;br /&gt;
a2 = axes(&#039;position&#039;,get(h(1),&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd2 = legend(a2,pe(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd2_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.72 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd2_pos);&lt;br /&gt;
% 3rd axes&lt;br /&gt;
a3 = axes(&#039;position&#039;,get(gca,&#039;position&#039;),&#039;visible&#039;,&#039;off&#039;); % create the same axes but set it invisible&lt;br /&gt;
lgd3 = legend(a3,pe(7:9),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;northwest&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lgd3_pos = lgd1_pos+[-lgd1_pos(3)*0.304 -lgd1_pos(4)*0.94 0 lgd1_pos(4)*0.8]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lgd3,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lgd3_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(1),0.58,2,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,27)&lt;br /&gt;
text(h(1),0.30,13.2,&#039;(unsaturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,53)&lt;br /&gt;
text(h(1),0.55,-2.1,&#039;open system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,20,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.26,6.5,&#039;(saturated)&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,45,&#039;color&#039;,[0.6 0.6 0.6])&lt;br /&gt;
text(h(1),0.75,-10,&#039;closed system&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,7,&#039;Color&#039;,[0.3010 0.7450 0.9330])&lt;br /&gt;
&lt;br /&gt;
h(3) = subplot(2,2,3);&lt;br /&gt;
% set(h(3),&#039;Position&#039;, [0.1 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
plot(de_ok.f,de_ok.dxsl,&#039;k-&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv,&#039;k--&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_ok.f,de_ok.dxsv_acc,&#039;k:&#039;,&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsl,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_oe.f,de_oe.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsl,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
plot(de_cl.f,de_cl.dxsv_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2)&lt;br /&gt;
ylim(h(3),[-30 65]);&lt;br /&gt;
xlabel(&#039;Residual water fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
&lt;br /&gt;
% Rayleigh condensation&lt;br /&gt;
h(4) = subplot(2,2,4);&lt;br /&gt;
% set(h(4),&#039;Position&#039;, [0.56 0.1 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.dxsc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); &lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.dxs,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\itd / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.dxsc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.dxs,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.dxs_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.dxsc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.dxs,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.dxs_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 0 0 -ax1_pos(4)],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;,&#039;TickDir&#039;,&#039;out&#039;,&#039;FontSize&#039;,fs); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,20*ones(size(dc_ln.Wconc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-18 20]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15])&lt;br /&gt;
&lt;br /&gt;
h(2) = subplot(2,2,2);&lt;br /&gt;
% set(h(2),&#039;Position&#039;, [0.56 0.56 0.38 0.38]);&lt;br /&gt;
hold on&lt;br /&gt;
pc(4) = plot(dc_no.Wconc,dc_no.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2); % [0 0.4470 0.7410]&lt;br /&gt;
pc(5) = plot(dc_no.Wconc,dc_no.d18O,&#039;--&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);&lt;br /&gt;
pc(6) = plot(dc_no.Wconc,dc_no.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.6 0.6 0.6],&#039;linewidth&#039;,2);  &lt;br /&gt;
ylim(h(2),[-60 -2]);&lt;br /&gt;
xlabel(&#039;Water mixing ratio / ppmv&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,2000:3000:16000);&lt;br /&gt;
ylabel([&#039;\delta^{18}O / &#039;,char(8240)],&#039;fontsize&#039;,fs);&lt;br /&gt;
% 2nd axis&lt;br /&gt;
ax1_pos = get(gca,&#039;position&#039;); % position of first axes&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos,&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YAxisLocation&#039;,&#039;right&#039;,&#039;Color&#039;,&#039;none&#039;,&#039;YTickLabel&#039;,&#039;&#039;,&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
hold on&lt;br /&gt;
pc(1) = plot(dc_ln.f,dc_ln.d18Oc,&#039;k-&#039;,&#039;linewidth&#039;,2); % [0.3010 0.7450 0.9330]&lt;br /&gt;
pc(2) = plot(dc_ln.f,dc_ln.d18O,&#039;k--&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
pc(3) = plot(dc_ln.f,dc_ln.d18O_acc,&#039;k:&#039;,&#039;linewidth&#039;,2);&lt;br /&gt;
% pc(7) = plot(dc_11.f,dc_11.d18Oc,&#039;-&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(8) = plot(dc_11.f,dc_11.d18O,&#039;--&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2); &lt;br /&gt;
% pc(9) = plot(dc_11.f,dc_11.d18O_acc,&#039;:&#039;,&#039;color&#039;,[0.3010 0.7450 0.9330],&#039;linewidth&#039;,2);&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;Residual vapour fraction&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
lg = legend(h(2),pc(1:3),&#039;instant liquid/ice&#039;,&#039;residual vapour&#039;,&#039;total liquid/ice removed&#039;);&lt;br /&gt;
set(lg,&#039;Position&#039;,[0.69 0.66 0.20 0.06],&#039;FontSize&#039;,fs);&lt;br /&gt;
lg_pos = lg.Position;&lt;br /&gt;
% 3rd axis&lt;br /&gt;
axes(&#039;Position&#039;,ax1_pos+[0 -ax1_pos(4)*0.2 0 -ax1_pos(4)*0.8],&#039;XAxisLocation&#039;,&#039;top&#039;,&#039;YColor&#039;,&#039;w&#039;,&#039;YTick&#039;,[],&#039;Color&#039;,&#039;none&#039;); &lt;br /&gt;
hold on&lt;br /&gt;
pc(7) = plot(dc_ln.Wconc,-2+zeros(size(dc_ln.d18Oc)),&#039;k-&#039;); % [0.3010 0.7450 0.9330]&lt;br /&gt;
ylim(gca,[-60 -2]);&lt;br /&gt;
xlabel(&#039;T / °C&#039;,&#039;fontsize&#039;,fs);&lt;br /&gt;
set(gca,&#039;XTick&#039;,[dc_ln.Wconc(81) dc_ln.Wconc(61:-10:11)],&#039;XTickLabel&#039;,[-20 -10:5:15],&#039;FontSize&#039;,fs,&#039;TickDir&#039;,&#039;out&#039;);&lt;br /&gt;
lg2 = legend(gca,pc(4:6),&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;location&#039;,&#039;east&#039;,&#039;box&#039;,&#039;off&#039;);&lt;br /&gt;
lg2_pos = lg_pos+[-lg_pos(3)*0.405 -lg_pos(4)*0.05 0 lg_pos(4)*0.26]; % move the 2nd legend to the desired position&lt;br /&gt;
set(lg2,&#039;box&#039;,&#039;off&#039;,&#039;Position&#039;,lg2_pos);&lt;br /&gt;
% add text&lt;br /&gt;
text(h(2),250,-36.9,&#039;super&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,70)&lt;br /&gt;
text(h(2),950,-28,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,55)&lt;br /&gt;
text(h(2),1300,-39,&#039;saturation&#039;,&#039;FontSize&#039;,fs,&#039;Rotation&#039;,68,&#039;Color&#039;,0.6*[1 1 1])&lt;br /&gt;
&lt;br /&gt;
set([h(1) h(3)],&#039;XDir&#039;,&#039;reverse&#039;,&#039;box&#039;,&#039;on&#039;);&lt;br /&gt;
set(h(:),&#039;color&#039;,&#039;none&#039;,&#039;FontSize&#039;,fs,&#039;tickdir&#039;,&#039;out&#039;); % ,&#039;YAxisLocation&#039;,&#039;left&#039;,&#039;ticklength&#039;,[0 0],&#039;ygrid&#039;,&#039;on&#039;,&#039;xgrid&#039;,&#039;on&#039;&lt;br /&gt;
&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.96 0.02 0.02],&#039;String&#039;,&#039;(a)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.96 0.02 0.02],&#039;String&#039;,&#039;(b)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.05 0.48 0.02 0.02],&#039;String&#039;,&#039;(c)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
annotation(&#039;textbox&#039;,[0.49 0.48 0.02 0.02],&#039;String&#039;,&#039;(d)&#039;,&#039;FitBoxToText&#039;,&#039;on&#039;,&#039;FontSize&#039;,fs+6,&#039;LineStyle&#039;,&#039;none&#039;);&lt;br /&gt;
&lt;br /&gt;
% print(&#039;-depsc&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
% print(&#039;-dpng&#039;,&#039;-r300&#039;,&#039;/scratch/home/figs/thesis/Rayleigh_model_plot&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1344</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1344"/>
		<updated>2020-09-06T02:15:51Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: /* Model description codes in MATLAB */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_evaporation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% simple Rayleigh evaporation model, after Stern and Blisniuk, 2002&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), d18O0 (permil), d2H0 (permil), &lt;br /&gt;
% system (open system = 1, closed system = 0), varargin (relative humidity)&lt;br /&gt;
% run example: rayleigh_evaporation(20+273.15,-10,-70,1,0.75)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,1)&lt;br /&gt;
%              rayleigh_evaporation(20+273.15,-10,-70,0)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_evaporation(T0,d18O0,d2H0,system,h)&lt;br /&gt;
&lt;br /&gt;
% %% dubugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% d18O0 = -10; % close to Bergen precipitation average&lt;br /&gt;
% d2H0 = -70;&lt;br /&gt;
% system = 1;&lt;br /&gt;
% h = 0.75;&lt;br /&gt;
&lt;br /&gt;
%% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 ◦ C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in K&lt;br /&gt;
        d = 1/exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in K&lt;br /&gt;
        d = 1/exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_vapour/R_liquid &amp;lt; 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
% % ouput variables&lt;br /&gt;
% data.T = [];&lt;br /&gt;
% data.f = [];&lt;br /&gt;
% data.d18Ov = [];&lt;br /&gt;
% data.d18Ol = [];&lt;br /&gt;
% data.d2Hv = [];&lt;br /&gt;
% data.d2Hl = [];&lt;br /&gt;
% data.dxsv = [];&lt;br /&gt;
% data.dxsl = [];&lt;br /&gt;
% data.d18Ov_acc = [];&lt;br /&gt;
% data.d2Hv_acc = [];&lt;br /&gt;
% data.dxsv_acc = [];&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (1) in an open system (material is immediately removed)&lt;br /&gt;
% e.g., condensation of vapour to droplets and falls immediately from a cloud (precipitation occurs)&lt;br /&gt;
if system == 1&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        &lt;br /&gt;
        % relative humidity&lt;br /&gt;
        if ~exist(&#039;h&#039;,&#039;var&#039;)&lt;br /&gt;
            h = 1;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % modified Rayleigh evaporation model including kinectic effct&lt;br /&gt;
        % during the vapour formation at undersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
        % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
        % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
        % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
        ak_18O = 1/(1/0.9723*(1-h)+h);&lt;br /&gt;
        ak_2H = 1/(1/0.9755*(1-h)+h);&lt;br /&gt;
        aeff_18O = a18O(T0) * ak_18O;&lt;br /&gt;
        aeff_2H = a2H(T0) * ak_2H;&lt;br /&gt;
        &lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0*f^(aeff_18O-1);&lt;br /&gt;
        R2Hl = R2H0*f^(aeff_2H-1);&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        &lt;br /&gt;
        % (3) isotope ratio of the accumulated removed vapour&lt;br /&gt;
        R18Ov_acc = R18O0*(1-f^aeff_18O)/(1-f); % Mook 2001, Page 38&lt;br /&gt;
        R2Hv_acc = R2H0*(1-f^aeff_2H)/(1-f);&lt;br /&gt;
        % delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = (R18Ov_acc/R18std-1)*1000;&lt;br /&gt;
        d2Hv_acc = (R2Hv_acc/R2std-1)*1000;&lt;br /&gt;
        dxsv_acc = d2Hv_acc-8*d18Ov_acc;&lt;br /&gt;
%         % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
%         % mass conservation of rare isotopes between the reservoir and formed removal: f*Rl+(1-f)*Rv_acc=R0,&lt;br /&gt;
%         % after rearranging, we have: Rv_acc=(R0-f*Rl)/(1-f)&lt;br /&gt;
%         R18Ov_acc2 = (R18O0-f*R18Ol)/(1-f);&lt;br /&gt;
%         R2Hv_acc2 = (R2H0-f*R2Hl)/(1-f);&lt;br /&gt;
%         data.d18Ov_acc2(n) = (R18Ov_acc2/R18std-1)*1000;&lt;br /&gt;
%         data.d2Hv_acc2(n) = (R2Hv_acc2/R2std-1)*1000;&lt;br /&gt;
%         data.dxsv_acc2(n) = data.d2Hv_acc2(n)-8*data.d18Ov_acc2(n);&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
&lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% Rayleigh evaporation process: (2) in closed system (material maintained under two-phase equilibrium)&lt;br /&gt;
% i.e., the material removed stays in the closed system and stays in equilibrium with the reservoir&lt;br /&gt;
% e.g., condensation of vapour to droplets in a cloud (only cloud is formed, but precipitation does not occur)&lt;br /&gt;
if system == 0&lt;br /&gt;
    fprintf(&#039;Rayleigh evaporation process: in an closed system (material maintained under two-phase equilibrium) \n&#039;);&lt;br /&gt;
    fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
    fprintf(&#039;       f    d18Ol    d18Ov     d2Hl     d2Hv     dxsl     dxsv d18Ov_acc dxsv_acc \n&#039;);&lt;br /&gt;
    n = 1;   % iteration steps&lt;br /&gt;
    for f = 1:-0.02:0 % remaining liquid fraction&lt;br /&gt;
        % isotope ratio of remaining liquid&lt;br /&gt;
        R18Ol = R18O0/(a18O(T0) - f*(a18O(T0)-1)); % Gat1996&lt;br /&gt;
        R2Hl = R2H0/(a2H(T0) - f*(a2H(T0)-1));     % Gat1996&lt;br /&gt;
        % (1) delta value of remaining liquid&lt;br /&gt;
        d18Ol = (R18Ol/R18std-1)*1000;&lt;br /&gt;
        d2Hl = (R2Hl/R2std-1)*1000;&lt;br /&gt;
        dxsl = d2Hl-8*d18Ol;&lt;br /&gt;
        &lt;br /&gt;
        % (2) delta value of the instantaneously removed vapour (in equilibrium with the current remaining liquid)&lt;br /&gt;
        d18Ov = ((d18Ol/1000+1)*a18O(T0)-1)*1000;&lt;br /&gt;
        d2Hv = ((d2Hl/1000+1)*a2H(T0)-1)*1000;&lt;br /&gt;
        dxsv = d2Hv-8*d18Ov;&lt;br /&gt;
        % (3) delta value of the accumulated removed vapour&lt;br /&gt;
        d18Ov_acc = d18Ov;&lt;br /&gt;
        d2Hv_acc = d2Hv;&lt;br /&gt;
        dxsv_acc = dxsv;&lt;br /&gt;
        &lt;br /&gt;
        fprintf(&#039;%8.4f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n&#039;,f,d18Ol,d18Ov,d2Hl,d2Hv,dxsl,dxsv,d18Ov_acc,dxsv_acc);&lt;br /&gt;
        &lt;br /&gt;
        % assign to output&lt;br /&gt;
        data.T(n) = T0;&lt;br /&gt;
        data.f(n) = f;&lt;br /&gt;
        data.d18Ol(n) = d18Ol;&lt;br /&gt;
        data.d18Ov(n) = d18Ov;&lt;br /&gt;
        data.d2Hl(n) = d2Hl;&lt;br /&gt;
        data.d2Hv(n) = d2Hv;&lt;br /&gt;
        data.dxsl(n) = dxsl;&lt;br /&gt;
        data.dxsv(n) = dxsv;&lt;br /&gt;
        data.d18Ov_acc(n) = d18Ov_acc;&lt;br /&gt;
        data.d2Hv_acc(n) = d2Hv_acc;&lt;br /&gt;
        data.dxsv_acc(n) = dxsv_acc;&lt;br /&gt;
        &lt;br /&gt;
        % iterate to next step&lt;br /&gt;
        n = n+1;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rayleigh_condensation.m&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Description:&lt;br /&gt;
% - simple Rayleigh condensation model, after Stern and Blisniuk, 2002&lt;br /&gt;
% - temperature dependent fractionation factor varies during cooling process&lt;br /&gt;
%   (1) isobaric cooling: e.g., air parcel advects to cold regions&lt;br /&gt;
%   (2) or pseudoadiabatic cooling: e.g., updraft or lift of surface air parcel&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% input variables: T0 (Kelvin), RH0 (%), d18O0 (permil), d2H0 (permil),&lt;br /&gt;
%                  sice: saturation conditions over ice when temperature &amp;lt;0 degree&lt;br /&gt;
%                        &amp;gt; 1: using the constant supersaturation given as sice;&lt;br /&gt;
%                        = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%                        = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
% run example: rayleigh_condensation(20+273.15,0.75,-13,-94,0)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1)&lt;br /&gt;
%              rayleigh_condensation(20+273.15,0.75,-13,-94,1.2)&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% HS, Do 12 Dez 2013 15:43:28 CET&lt;br /&gt;
% YW, structured and included kinetic effect, 29 Aug 2020&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% YW, 26 Mar 2020&lt;br /&gt;
% limitation:&lt;br /&gt;
% Rayleigh condensation model only reflects the process of water vapor removing&lt;br /&gt;
% and ignores: mixing of air masses, cloud water-vapor isotope exchange,&lt;br /&gt;
% subcloud droplet evaporation, and radiative cooling or heating.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
&lt;br /&gt;
function data = rayleigh_condensation(T0,RH0,d18O0,d2H0,sice)&lt;br /&gt;
&lt;br /&gt;
% %% for debugging&lt;br /&gt;
% T0 = 20+273.15;&lt;br /&gt;
% RH0 = 0.75; % Craig-Gordon, 1965 (Fig. 15)&lt;br /&gt;
% d18O0 = -13;&lt;br /&gt;
% d2H0 = -94;&lt;br /&gt;
% sice = 0;&lt;br /&gt;
&lt;br /&gt;
% RH0 = 0.91;  % 20161207 AR event at Bergen&lt;br /&gt;
% d18O0 = -12.5;&lt;br /&gt;
% d2H0 = -100;&lt;br /&gt;
&lt;br /&gt;
%% functions adopted&lt;br /&gt;
% fractionation factors&lt;br /&gt;
%--------------------------------&lt;br /&gt;
% Majoube, M., 1971a: Fractionnement en oxyg`ene-18 entre la glace et la vapeur d’eau. J.&lt;br /&gt;
% Chim. Phys., 68, 625–636.&lt;br /&gt;
&lt;br /&gt;
% Majoube, M., 1971b: Fractionnement en oxyg`ene 18 et deut ́erium entre l’eau et sa vapeur. J. Chim.&lt;br /&gt;
% Phys., 68, 1423–1436.&lt;br /&gt;
&lt;br /&gt;
% Merlivat, L. and G. Nief, 1967: Fractionnement isotopique lors des changements d‘ ́etat&lt;br /&gt;
% solide-vapeur et liquide-vapeur de l’eau `a des temp ́eratures inf ́erieures a ` 0 °C. Tellus,&lt;br /&gt;
% 19, 122–127.&lt;br /&gt;
%--------------------------------&lt;br /&gt;
    function d = a2H(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(24.844e3/(T^2)-76.248/T+52.612e-3); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(16289./T.^2 - 0.0945);   % Merlivat &amp;amp; Nief 1967, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    function d = a18O(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15 % above 0 celsius&lt;br /&gt;
            d = exp(1137/(T^2)-0.4156/T-0.0020667); % Majoube 1971b, R_liquid/R_vapour &amp;gt; 1&lt;br /&gt;
        else&lt;br /&gt;
            d = exp(11.839./T - 0.028224); % Majoube 1971a, R_solid/R_vapour &amp;gt; 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% supersaturation with respect to ice&lt;br /&gt;
% Si = 1 − λT, with λ = 0.004. From Graf 2017 dissertation, page 53, Fig 3.1&lt;br /&gt;
% (as in Risi et al., 2010b, after Jouzel and Merlivat 1984.)&lt;br /&gt;
% Risi, C., S. Bony, F. Vimeux, and J. Jouzel, 2010b: Water-stable isotopes in the LMDZ4&lt;br /&gt;
% general circulation model: Model evaluation for present-day and past climates and&lt;br /&gt;
% applications to climatic interpretations of tropical isotopic records.&lt;br /&gt;
% sice: &amp;gt; 1: using the constant supersaturation given here;&lt;br /&gt;
%       = 1: meaning alpha_k = 1, thus no supersaturation;&lt;br /&gt;
%       = 0: using formula Si = 1-0.004*T (in Celsius)&lt;br /&gt;
    function s = si(T)&lt;br /&gt;
        if sice &amp;gt;= 1&lt;br /&gt;
            s = sice;&lt;br /&gt;
        else  % elseif sice == 0&lt;br /&gt;
            s = 1-0.004*(T-273.15);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% vapour saturation pressure&lt;br /&gt;
    function es = esat(T) % T in Kelvin&lt;br /&gt;
        if T &amp;gt;= 273.15&lt;br /&gt;
            % es = 611*exp((17.27*T)/(273+T)); % T in celsius&lt;br /&gt;
            es = 611*exp(17.27*(T-273.15)/T); % T in Kelvin&lt;br /&gt;
        else&lt;br /&gt;
            % Saturation vapour pressure over ice (Murphy and Koop, 2005) for T &amp;gt; 110 K:&lt;br /&gt;
            es_ice = exp(9.550426 - 5723.265/T + 3.53068*log(T) - 0.00728332*T);&lt;br /&gt;
            % the actual saturation vapour pressure&lt;br /&gt;
            es = es_ice * si(T);&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% saturated vapour mixing ratio&lt;br /&gt;
    function ws = wsat(es,p)&lt;br /&gt;
        ws = 0.622*es/(p-es);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% pressure at height of z&lt;br /&gt;
    function p = pressure(z)&lt;br /&gt;
        p0 = 101325; % Pa&lt;br /&gt;
        z0 = 8000;   % m scale height&lt;br /&gt;
        p = p0*exp(-z/z0);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
% moist adiabatic lapse rate [Curry and Webster,1999] (cited after Stern and Blisniuk, 2002)&lt;br /&gt;
    function lr = gamma(ws,T) % T in Kelvin&lt;br /&gt;
        % physical constants&lt;br /&gt;
        g = 9.80665;     % m/s^2  the gravitational acceleration&lt;br /&gt;
        Cpd = 1.00464e3; % J/kg/K the specific heat capacity of dry air at constant pressure&lt;br /&gt;
        L = 2.5104e6;    % J/kg   the latent heat of vaporization or sublimation&lt;br /&gt;
        Rd = 287.04;     % J/kg/K the specific gas constant for dry air&lt;br /&gt;
        lr = g/Cpd*(1+L*ws/Rd/T)/(1+0.622*L*L*ws/Rd/Cpd/T/T); % [°C/m]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
%% initialization&lt;br /&gt;
% isotope ratios of VSMOW reference water&lt;br /&gt;
R2std = 155.76e-6;&lt;br /&gt;
R18std = 2005.20e-6;&lt;br /&gt;
% initial isotope ratio&lt;br /&gt;
R18O0 = (d18O0/1000+1)*R18std;&lt;br /&gt;
R2H0 = (d2H0/1000+1)*R2std;&lt;br /&gt;
dxs0 = R2H0-8*R18O0;&lt;br /&gt;
&lt;br /&gt;
% initial conditions&lt;br /&gt;
f = 1.0;  % remaining vapour fractionation&lt;br /&gt;
z = 0.0;  % elevation&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
w0 = RH0*wsat(esat(T0),p); % kg/kg&lt;br /&gt;
% convert water mixing ratio unit&lt;br /&gt;
md = 28.97; % [g/mol] dry air molar mass&lt;br /&gt;
mv = 18.02; % [g/mol] water vapour molar mass&lt;br /&gt;
wconc0 = w0*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
rh = RH0;&lt;br /&gt;
dt = 0.5;  % temperature step&lt;br /&gt;
T = T0+dt;&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of isobaric cooling&lt;br /&gt;
%% (1) cool to saturation&lt;br /&gt;
fprintf(&#039;Rayleigh condensation process: in an open system (material is immediately removed) \n&#039;);&lt;br /&gt;
fprintf(&#039;T0 = %6.2f K (%4.2f °C) \n&#039;, T0, T0-273.15);&lt;br /&gt;
fprintf(&#039;   T (°C)   d18Ov     d2Hv     dxsv       rh        f WConc[ppmv] \n&#039;);&lt;br /&gt;
n = 1;  % iteration number&lt;br /&gt;
while rh &amp;lt; 0.99&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    rh = w0/ws;                 % RH at each iteration&lt;br /&gt;
    wconc = wconc0; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18O0,d2H0,dxs0,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18O0;&lt;br /&gt;
    data.dD(n) = d2H0;&lt;br /&gt;
    data.dxs(n) = d2H0-8*d18O0;&lt;br /&gt;
    data.d18Oc(n) = NaN; % condensate&lt;br /&gt;
    data.d2Hc(n) = NaN;&lt;br /&gt;
    data.dxsc(n) = NaN;&lt;br /&gt;
    data.d18O_acc(n) = NaN; % accumulated condensate (liquid+solid)&lt;br /&gt;
    data.d2H_acc(n) = NaN;&lt;br /&gt;
    data.dxs_acc(n) = NaN;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Reached saturation now\n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0 = w0;&lt;br /&gt;
&lt;br /&gt;
%% (2) continue to cool and form liquid condensate&lt;br /&gt;
while T &amp;gt; 273.15 % isobaric cooling with condensation to 0 °C&lt;br /&gt;
    T = T-dt; % decrease temperature by dt °C at each iteration&lt;br /&gt;
    ws = wsat(esat(T),p); % saturated water mixing ratio at each iteration&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*f^(a18O(T)-1);&lt;br /&gt;
    R2Hv = R2H0*f^(a2H(T)-1);&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*a18O(T)-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*a2H(T)-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % mass conservation of rare isotopes between the reservoir and formed removal: f*Rv + (1-f)*Rl_acc = R0,&lt;br /&gt;
    % after rearranging, we have: Rl_acc = (R0-f*Rv)/(1-f)&lt;br /&gt;
    R18Ol_acc = (R18O0-f*R18Ov)/(1-f);&lt;br /&gt;
    R2Hl_acc = (R2H0-f*R2Hv)/(1-f);&lt;br /&gt;
    d18Ol_acc = (R18Ol_acc/R18std-1)*1000;&lt;br /&gt;
    d2Hl_acc = (R2Hl_acc/R2std-1)*1000;&lt;br /&gt;
    dxsl_acc = d2Hl_acc-8*d18Ol_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18Ol_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2Hl_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxsl_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;Have cooled to 0 celcius now \n&#039;);&lt;br /&gt;
&lt;br /&gt;
ws0_ice = ws;&lt;br /&gt;
R18O0 = R18Ov;&lt;br /&gt;
R2H0 = R2Hv;&lt;br /&gt;
f0 = f;&lt;br /&gt;
&lt;br /&gt;
%% (3) continue to cool and form solid condensate&lt;br /&gt;
% considering mixed-phase cloud: subsaturated over liquid droplets and supersaturated over ice crystals&lt;br /&gt;
&lt;br /&gt;
% closure assumption: liquid droplets --&amp;gt; evaporate to vapour --&amp;gt; deposite on ice crystals&lt;br /&gt;
% therefore: when T&amp;lt;0 celsius, the reduced fraction of vapour is due to its deposit on ice crystals with a fractionation&lt;br /&gt;
% factor alpha_eff = alpha_eq*alpha_k taking into account the kinetic effct under the supersaturation condition.&lt;br /&gt;
% i.e.: we start a new Rayleigh condensation model starting with the remaining vapour&lt;br /&gt;
% after the liquid condensation stage above, and use the new factionation factor alpha_eff&lt;br /&gt;
&lt;br /&gt;
while T &amp;gt; -60+273.15&lt;br /&gt;
    T = T-dt;&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    wconc = ws*md/mv*1e6; % [kg/kg] --&amp;gt; [ppmv]&lt;br /&gt;
    f = ws/ws0;      % the total fraction of remaining vapour through all stages&lt;br /&gt;
    fi = ws/ws0_ice; % the fraction of remaing vapour in the ice condensation stage only&lt;br /&gt;
    &lt;br /&gt;
    % modified Rayleigh condensation model including kinectic effct&lt;br /&gt;
    % during the ice formation at supersaturated conditions (Jouzel and Merlivat 1984)&lt;br /&gt;
    % Diffusivities D adopted from Merlivat 1978:&lt;br /&gt;
    % D_H18O/D_H16O = 0.9723 ± 0.0007&lt;br /&gt;
    % D_HD16O/D_H216O = 0.9755 ± 0.0009&lt;br /&gt;
    ak_18O = si(T)/(a18O(T)*1/0.9723*(si(T)-1) + 1);&lt;br /&gt;
    ak_2H = si(T)/(a2H(T)*1/0.9755*(si(T)-1) + 1);&lt;br /&gt;
    aeff_18O = a18O(T) * ak_18O;&lt;br /&gt;
    aeff_2H = a2H(T) * ak_2H;&lt;br /&gt;
    &lt;br /&gt;
    % isotope ratio of remaining vapour&lt;br /&gt;
    R18Ov = R18O0*fi^(aeff_18O-1); % Jouzel and Merlivat, 1984&lt;br /&gt;
    R2Hv = R2H0*fi^(aeff_2H-1);    % Jouzel and Merlivat, 1984&lt;br /&gt;
    % (1) delta value of remaining vapour&lt;br /&gt;
    d18Ov = (R18Ov/R18std-1)*1000;&lt;br /&gt;
    d2Hv = (R2Hv/R2std-1)*1000;&lt;br /&gt;
    dxsv = d2Hv - 8*d18Ov;&lt;br /&gt;
    &lt;br /&gt;
    % (2) delta value of the instantaneously removed condensate (in equilibrium with the current remaining vapour)&lt;br /&gt;
    d18Oc = ((d18Ov/1000+1)*aeff_18O-1)*1000;&lt;br /&gt;
    d2Hc = ((d2Hv/1000+1)*aeff_2H-1)*1000;&lt;br /&gt;
    dxsc = d2Hc-8*d18Oc;&lt;br /&gt;
    &lt;br /&gt;
    % (3) Calculating the isotope ratio of the accumulated removal using mass conservation approach&lt;br /&gt;
    % (i) mass conservation of rare isotopes between the reservoir and formed removal:&lt;br /&gt;
    % fi*Rv + (1-fi)*Ri_acc = Rv0,&lt;br /&gt;
    % where fi is the fraction of remaing vapour in the ice condensation stage, and&lt;br /&gt;
    % Rv0 is the isotope ratio of the remaining vapour after liquid condensation stage&lt;br /&gt;
    % after rearranging, we have: Ri_acc = (Rv0-fi*Rv)/(1-fi)&lt;br /&gt;
    R18Oi_acc = (R18O0-fi*R18Ov)/(1-fi);&lt;br /&gt;
    R2Hi_acc = (R2H0-fi*R2H0)/(1-fi);&lt;br /&gt;
    %         d18Oi_acc = (R18Oi_acc/R18std-1)*1000;&lt;br /&gt;
    %         d2Hi_acc = (R2Hi_acc/R2std-1)*1000;&lt;br /&gt;
    %         dxsi_acc = d2Hi_acc-8*d18Oi_acc;&lt;br /&gt;
    % (ii) the total accumulation is sum of the liquid (1-f0) and solid condensate (f0*(1-fi))&lt;br /&gt;
    % (1-f0*fi)*R_acc = (1-f0)*Rl_acc + (f0*(1-fi))*Ri_acc&lt;br /&gt;
    R18O_acc = ((1-f0)*R18Ol_acc + (f0*(1-fi))*R18Oi_acc)/(1-f0*fi);&lt;br /&gt;
    R2H_acc = ((1-f0)*R2Hl_acc + (f0*(1-fi))*R2Hi_acc)/(1-f0*fi);&lt;br /&gt;
    d18O_acc = (R18O_acc/R18std-1)*1000;&lt;br /&gt;
    d2H_acc = (R2H_acc/R2std-1)*1000;&lt;br /&gt;
    dxs_acc = d2H_acc-8*d18O_acc;&lt;br /&gt;
    &lt;br /&gt;
    fprintf(&#039;%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n&#039;,T-273.15,d18Ov,d2Hv,dxsv,rh,f,wconc);&lt;br /&gt;
    &lt;br /&gt;
    % assign to output&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.f(n) = f;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.Wconc(n) = wconc;&lt;br /&gt;
    data.d18O(n) = d18Ov;&lt;br /&gt;
    data.dD(n) = d2Hv;&lt;br /&gt;
    data.dxs(n) = dxsv;&lt;br /&gt;
    data.rh(n) = rh;&lt;br /&gt;
    data.d18Oc(n) = d18Oc;&lt;br /&gt;
    data.d2Hc(n) = d2Hc;&lt;br /&gt;
    data.dxsc(n) = dxsc;&lt;br /&gt;
    data.d18O_acc(n) = d18O_acc;&lt;br /&gt;
    data.d2H_acc(n) = d2H_acc;&lt;br /&gt;
    data.dxs_acc(n) = dxs_acc;&lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
%% for the circumstance of pseudoadiabatic cooling&lt;br /&gt;
% - establish the relationship between T and z&lt;br /&gt;
z = 0;&lt;br /&gt;
p = pressure(z);&lt;br /&gt;
n = 1;&lt;br /&gt;
for T = T0:-dt:-60+273.15&lt;br /&gt;
    data.T(n) = T;&lt;br /&gt;
    data.z(n) = z;&lt;br /&gt;
    data.p(n) = p;&lt;br /&gt;
    % the elevation change&lt;br /&gt;
    ws = wsat(esat(T),p);&lt;br /&gt;
    lr = gamma(ws,T); % lapse rate&lt;br /&gt;
    dz = dt/lr;   % dt = lr*dz&lt;br /&gt;
    % the new elevation and pressure&lt;br /&gt;
    z = z+dz;&lt;br /&gt;
    p = pressure(z);&lt;br /&gt;
    data.lr(n) = lr;   &lt;br /&gt;
    &lt;br /&gt;
    % iterate to next step&lt;br /&gt;
    n = n+1;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
% fin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The mergetime command will create one new output file with a common time axis. Therefore, all inputfiles must have a common time axis, and the same variables, essentially they must have the same netcdf file format.&lt;br /&gt;
&lt;br /&gt;
Here is an example for how to create a monthly file from the daily TPS-3100 (Hotplate) data files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1343</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1343"/>
		<updated>2020-09-06T02:13:32Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipitation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; Gat, (1996)), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs. An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig. 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 1&#039;&#039;&#039;&#039;&#039; Schematic presentation of the mathematical approaches of the Rayleigh model in open system &#039;&#039;&#039;(a, b)&#039;&#039;&#039; and closed system &#039;&#039;&#039;(c)&#039;&#039;&#039;. Adapted from Gat &#039;&#039;et al&#039;&#039; (2001). &lt;br /&gt;
&#039;&#039;&#039;(a)&#039;&#039;&#039; From a reservoir containing N abundant isotopologues (e.g. H_2{16}O) and N_i rare isotopologues (e.g. H_2{18}O or HD{16}O) small amounts of both species, &#039;&#039;dN&#039;&#039; and &#039;&#039;dN_i&#039;&#039; respectively, are being removed under equilibrium fractionation conditions: &#039;&#039;dN_i/dN = α*R&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(b)&#039;&#039;&#039; The changing isotopic composition of the reservoir is calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R*N = (R-dR)*(N-dN) + α*R*dN&#039;&#039;. &lt;br /&gt;
&#039;&#039;&#039;(c)&#039;&#039;&#039; In closed system, the changing isotopic composition of the reservoir can be calculated from a mass balance consideration for the rare isotopologues: &#039;&#039;R_0*N_0 = R*(N_0-dN) + α*R*dN&#039;&#039;, with the remaining fraction &#039;&#039;f = (N_0-dN)/N_0&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|thumb|800px|&#039;&#039;&#039;&#039;&#039;Figure 2&#039;&#039;&#039;&#039;&#039; Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of δ18O = -10 ‰ and δD = -70 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 C and RH = 75 %. The initial vapour compositions are δ18O = -13 ‰ and δD = -94 ‰ (&#039;&#039;d&#039;&#039; = 10 ‰). For the condensation to ice below 0 C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice (&#039;&#039;e_i&#039;&#039;). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is &#039;&#039;e_v = S_i*e_i&#039;&#039;. &#039;&#039;S_i&#039;&#039; is the defined saturation ratio, as &#039;&#039;e_v/e_i&#039;&#039;, and here takes the form &#039;&#039;S_i = 1-0.004*T&#039;&#039; after Risi et al 2010a. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by Jouzel &amp;amp; Merlivat (1984) is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model description codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The mergetime command will create one new output file with a common time axis. Therefore, all inputfiles must have a common time axis, and the same variables, essentially they must have the same netcdf file format.&lt;br /&gt;
&lt;br /&gt;
Here is an example for how to create a monthly file from the daily TPS-3100 (Hotplate) data files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1342</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1342"/>
		<updated>2020-09-06T01:38:42Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipiation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; \cite{Gat1996}), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs (Fig.~\ref{fig:Rayleigh_box}c). An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig.~\ref{fig:Rayleigh_box}).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png|border|600px|caption]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|frame|500px|Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of \delta^{18}O = -10 \permil\ and \delta D = -70 \permil\ (\textit{d} = 10 \permil), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 \degree C and RH = 75 %. The initial vapour compositions are $\delta^{18}$O = -13 \permil\ and $\delta$D = -94 \permil\ (\textit{d} = 10 \permil). For the condensation to ice below 0 \degree C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice ($e_i$). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is $e_v = S_ie_i$. $S_i$ is the defined saturation ratio, as $e_v$/$e_i$, and here takes the form $S_i = 1-0.004T$ after \cite{Risi2010a}. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by \cite{Jouzel1984} is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model description codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh evaporation ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rayleigh condensation ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The mergetime command will create one new output file with a common time axis. Therefore, all inputfiles must have a common time axis, and the same variables, essentially they must have the same netcdf file format.&lt;br /&gt;
&lt;br /&gt;
Here is an example for how to create a monthly file from the daily TPS-3100 (Hotplate) data files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1341</id>
		<title>Rayleigh model</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Rayleigh_model&amp;diff=1341"/>
		<updated>2020-09-06T01:16:23Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: Created page with &amp;quot;  Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Rayleigh distillation model describes the evolution of a multiple-phases system in which one phase is continuously removed to the other phase through fractional distillation. Despite its simplicity, it is a powerful framework to describe in particular the isotopic enrichment or depletion as material moves between reservoirs in an equilibrium process. &lt;br /&gt;
&lt;br /&gt;
== Model description ==&lt;br /&gt;
&lt;br /&gt;
The system applying the Rayleigh equation is normally an open system from which the formed material is immediately removed. For example, the evaporation of the natural water bodies, and the formation of falling precipiation can be regarded as open systems. However, the  Rayleigh equation can be also applied to other systems. One such system is a closed system (or two-phase equilibrium model; \cite{Gat1996}), where the material removed from one reservoir accumulates in a second reservoir in such a manner that isotopic equilibrium is maintained between the two reservoirs (Fig.~\ref{fig:Rayleigh_box}c). An example would be the condensation of vapour to droplets in a cloud (with no falling precipitation).&lt;br /&gt;
&lt;br /&gt;
The isotopic enrichment or depletion by the Rayleigh process for both open and closed systems can be mathematically established by different approaches (Fig.~\ref{fig:Rayleigh_box}).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_box_sketch_v2.png]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Item&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Quantity&lt;br /&gt;
! scope=&amp;quot;col&amp;quot;| Price&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Bread&lt;br /&gt;
| 0.3 kg&lt;br /&gt;
| $0.65&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot;| Butter&lt;br /&gt;
| 0.125 kg&lt;br /&gt;
| $1.25&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; colspan=&amp;quot;2&amp;quot;| Total&lt;br /&gt;
| $1.90&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Model visualization ==&lt;br /&gt;
&lt;br /&gt;
[[File:Rayleigh_model_plot_v2.png|Isotopic change during &#039;&#039;&#039;(a), (c)&#039;&#039;&#039; Rayleigh evaporation, and &#039;&#039;&#039;(b), (d)&#039;&#039;&#039; Rayleigh condensation. Rayleigh evaporation occurs at 20 C (thus a constant fractionation factor) for initial liquid compositions of \delta^{18}O = -10 \permil\ and \delta D = -70 \permil\ (\textit{d} = 10 \permil), in open system with unsaturated (RH = 75 %; black) or saturated (grey) environment, and closed system (blue). Rayleigh condensation occurs under continuous cooling (thus also a contentiously changing fractionation factor) from T = 20 \degree C and RH = 75 %. The initial vapour compositions are $\delta^{18}$O = -13 \permil\ and $\delta$D = -94 \permil\ (\textit{d} = 10 \permil). For the condensation to ice below 0 \degree C, two circumstances are presented. The saturation circumstance (grey) is a classical Rayleigh process where vapour forms ice crystals under equilibrium conditions, using the saturation pressure over ice ($e_i$). The supersaturation circumstance (black) takes into account the supersaturation over ice where the ambient vapour pressure is $e_v = S_ie_i$. $S_i$ is the defined saturation ratio, as $e_v$/$e_i$, and here takes the form $S_i = 1-0.004T$ after \cite{Risi2010a}. In this circumstance, the fractionation factor combining equilibrium and kinetic effects given by \cite{Jouzel1984} is used.]]&lt;br /&gt;
&lt;br /&gt;
== Model description codes in MATLAB ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example of usage ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module load CDO&lt;br /&gt;
cdo mergetime &amp;lt;inputfiles.nc&amp;gt; &amp;lt;outputfile.nc&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mergetime command will create one new output file with a common time axis. Therefore, all inputfiles must have a common time axis, and the same variables, essentially they must have the same netcdf file format.&lt;br /&gt;
&lt;br /&gt;
Here is an example for how to create a monthly file from the daily TPS-3100 (Hotplate) data files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /Data/gfi/scratch/metdata/hotplate/netcdf/2019/01&lt;br /&gt;
cdo mergetime TPS_201901* ../TPS_201901.nc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=File:Rayleigh_model_plot_v2.png&amp;diff=1340</id>
		<title>File:Rayleigh model plot v2.png</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=File:Rayleigh_model_plot_v2.png&amp;diff=1340"/>
		<updated>2020-09-06T01:02:09Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=File:Rayleigh_model_box_sketch_v2.png&amp;diff=1339</id>
		<title>File:Rayleigh model box sketch v2.png</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=File:Rayleigh_model_box_sketch_v2.png&amp;diff=1339"/>
		<updated>2020-09-06T01:01:16Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Main_Page&amp;diff=1338</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Main_Page&amp;diff=1338"/>
		<updated>2020-09-03T14:03:39Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Geophysical Institute ==&lt;br /&gt;
&lt;br /&gt;
[[File:GFI.jpg]]&lt;br /&gt;
&lt;br /&gt;
==[[Teaching]]==&lt;br /&gt;
&lt;br /&gt;
==Research and PhD/Postdoc Groups==&lt;br /&gt;
===[[Meteorology]]===&lt;br /&gt;
===[[ResClim Bergen subgroup]]===&lt;br /&gt;
===[[Physical Oceanography group]]===&lt;br /&gt;
&lt;br /&gt;
==Observations==&lt;br /&gt;
===[[ITAS Automatic Weather Stations]]===&lt;br /&gt;
===[[MRR Micro Rain Radar]]===&lt;br /&gt;
===[[TPS-3100 Hotplate pluviometer]]===&lt;br /&gt;
===[[Parsivel2 Disdrometer]]===&lt;br /&gt;
===[[HOBO rain gauges]]===&lt;br /&gt;
===[[EasyLog temperature logger]]===&lt;br /&gt;
===[[iMet UAV sonde package]]===&lt;br /&gt;
===[[Kristine Bonnevie shiplog data]]===&lt;br /&gt;
===[[Joining several data files with CDO and IsoFuse]]===&lt;br /&gt;
&lt;br /&gt;
==Shared data sets==&lt;br /&gt;
===[[ERA5 reanalysis data]]===&lt;br /&gt;
&lt;br /&gt;
==IT (Hardware and Software)==&lt;br /&gt;
===[[The GFI computing system]]===&lt;br /&gt;
===[[Using cyclone]]===&lt;br /&gt;
===[[Using modules on cyclone]]===&lt;br /&gt;
===[[Best practices when using cyclone]]===&lt;br /&gt;
===[[Bedymo]]===&lt;br /&gt;
===[[Dynlib]]===&lt;br /&gt;
===[[Forecast plotting]]===&lt;br /&gt;
===[[Git]]===&lt;br /&gt;
===[[NCL]]===&lt;br /&gt;
===[[Python]]===&lt;br /&gt;
===[[WRF]]===&lt;br /&gt;
===[[OpenIFS]]===&lt;br /&gt;
===[[GFI&amp;amp;SKD Storage]]===&lt;br /&gt;
===(outdated) [[Using the queue system on skd-cyclone]]===&lt;br /&gt;
&lt;br /&gt;
==IsoMet Tools==&lt;br /&gt;
===[[FLEXPART]]===&lt;br /&gt;
===[[Lagranto]]===&lt;br /&gt;
===[[WaterSip]]===&lt;br /&gt;
===[[Flextract]]===&lt;br /&gt;
===[[Joining several data files with CDO and IsoFuse|IsoFuse]]===&lt;br /&gt;
===[[Rayleigh model]]===&lt;br /&gt;
&lt;br /&gt;
==Social Activities and Groups==&lt;br /&gt;
===[[Football]]===&lt;br /&gt;
===[[Gale Brewing Club]]===&lt;br /&gt;
===[[Geosupen]]===&lt;br /&gt;
===[[GFI-social]]===&lt;br /&gt;
===[[Kakeklubben]]===&lt;br /&gt;
===[[Music]]===&lt;br /&gt;
===[[PhD Forum]]===&lt;br /&gt;
===[[Schafkopf]]===&lt;br /&gt;
===[[Volleyball]]===&lt;br /&gt;
&lt;br /&gt;
[[Category:IT]]&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Forecast_plotting&amp;diff=1184</id>
		<title>Forecast plotting</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Forecast_plotting&amp;diff=1184"/>
		<updated>2019-10-08T12:38:11Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: updated the directory for the example scripts&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Both the forecast plotting script and the website creation script is based on python. The plotting script uses [[dynlib]], the website creating script uses [https://www.djangoproject.com django] the same library that also drives [https://plikt.gfi.uib.no plikt.org].&lt;br /&gt;
&lt;br /&gt;
== Preparations ==&lt;br /&gt;
&lt;br /&gt;
=== Prepare dynlib ===&lt;br /&gt;
&lt;br /&gt;
To get started, make sure you have followed the procedures to setup dynlib. Use the [[dynlib#Use_the_centrally_installed_dynlib|Guide to use the centrally installed dynlib]]. If you want to start developing own diagnostics, follow also the [[dynlib#Quick_start_to_developing_with_dynlib|Quick start to developing with dynlib]].&lt;br /&gt;
&lt;br /&gt;
=== Obtain the example scripts ===&lt;br /&gt;
&lt;br /&gt;
Example scripts as well as the actual forecast scripts currently used are available in a tar archive:&lt;br /&gt;
&amp;lt;code&amp;gt;/Data/gfi/users/csp001/prj/forecast_plotting.tar.bz2&amp;lt;/code&amp;gt;. In that archive there are three folders called &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;production&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;website&amp;lt;/code&amp;gt;. &lt;br /&gt;
# &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt; contains a thoroughly documented plot script and the necessary settings file that sets up the right paths and file name structure used for the forecasts.&lt;br /&gt;
# &amp;lt;code&amp;gt;production&amp;lt;/code&amp;gt; contains the currently used plot script. The settings file also contains the colormaps developed by Franziska Menzel.&lt;br /&gt;
# &amp;lt;code&amp;gt;website&amp;lt;/code&amp;gt; contains the script and the template file used to create web pages fitting to the plots.&lt;br /&gt;
&lt;br /&gt;
== The workflow ==&lt;br /&gt;
&lt;br /&gt;
# Create a folder in which the plots should be created, and set &amp;lt;code&amp;gt;conf.opath&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;settings.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
# Create a folder which contains the contents of the folder &amp;lt;code&amp;gt;website&amp;lt;/code&amp;gt;. The website will be created in this folder. The website expects an folder &amp;lt;code&amp;gt;plots&amp;lt;/code&amp;gt; in that folder, so either create the folder in step 1 as a subfolder of this folder, or symlink the plot folder here.&lt;br /&gt;
# Follow the examples in &amp;lt;code&amp;gt;example_plot2.py&amp;lt;/code&amp;gt; to develop a new plot.&lt;br /&gt;
# Contain the plot in the structure &amp;lt;code&amp;gt;plot_forecasts.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
# When the forecasts are created, adapt the script &amp;lt;code&amp;gt;render_vaerkart.py&amp;lt;/code&amp;gt; to include your new variables/plots in the list starting around line 30.&lt;br /&gt;
# Create the website and open it in a browser!&lt;br /&gt;
&lt;br /&gt;
== Plotconf options ==&lt;br /&gt;
&lt;br /&gt;
Many properties of the plots can be configured. The following list is a (hopefully complete) list of what is currently available for the dynlib plotting routines. Contact Clemens Spensberger in case you&#039;re missing an option. The implementation will be much easier and quicker if you check first such an option is available in the underlying plotting library [http://matplotlib.org matplotlib].&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Name&lt;br /&gt;
! Line&lt;br /&gt;
! Fill&lt;br /&gt;
! Type&lt;br /&gt;
! Default&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| cb_orientation	&lt;br /&gt;
|      &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| string &lt;br /&gt;
| &#039;vertical&#039; &lt;br /&gt;
| Orientation of the color bar.&lt;br /&gt;
|-&lt;br /&gt;
| cmap			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|      &lt;br /&gt;
| mpl-colormap &lt;br /&gt;
| &lt;br /&gt;
| Color map for the contours.&lt;br /&gt;
|-&lt;br /&gt;
| cmap			&lt;br /&gt;
|      &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| mpl-colormap &lt;br /&gt;
| cm.gist_ncar &lt;br /&gt;
| Color map.&lt;br /&gt;
|-&lt;br /&gt;
| coastcolor		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| mpl-color &lt;br /&gt;
| black &lt;br /&gt;
| Color of the coastlines.&lt;br /&gt;
|-&lt;br /&gt;
| colors		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|      &lt;br /&gt;
| list of mpl-color &lt;br /&gt;
| black &lt;br /&gt;
| Presribe color of the contours, instead of using color map.&lt;br /&gt;
|-&lt;br /&gt;
| colors		&lt;br /&gt;
|      &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| list of mpl-color &lt;br /&gt;
| &lt;br /&gt;
| Prescribe colors directly instead of using color map.&lt;br /&gt;
|-&lt;br /&gt;
| contour_labels	&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|      &lt;br /&gt;
| bool 	&lt;br /&gt;
| False	&lt;br /&gt;
| Label the contours within the plot.&lt;br /&gt;
|-&lt;br /&gt;
| contour_labels_fontsize &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|  &lt;br /&gt;
| int/string &lt;br /&gt;
| 12 &lt;br /&gt;
| Font size in point, or a string like &#039;smaller&#039;.&lt;br /&gt;
|-&lt;br /&gt;
| contour_labels_inline &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|    &lt;br /&gt;
| bool &lt;br /&gt;
| True &lt;br /&gt;
| Remove the contour under the label?&lt;br /&gt;
|-&lt;br /&gt;
| contour_labels_inline_spacing &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|    &lt;br /&gt;
| int &lt;br /&gt;
| 2 &lt;br /&gt;
| Space in pixels around the label where the contour is removed as well.&lt;br /&gt;
|-&lt;br /&gt;
| contour_labels_format &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|    &lt;br /&gt;
| string/list of string &lt;br /&gt;
| &#039;%1.1f&#039; &lt;br /&gt;
| How to format the numbers, or list of strings used as labels.&lt;br /&gt;
|-&lt;br /&gt;
| disable_cb		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| bool	&lt;br /&gt;
| False &lt;br /&gt;
| Do not plot add a colorbar.&lt;br /&gt;
|-&lt;br /&gt;
| extend		&lt;br /&gt;
|      &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| string	&lt;br /&gt;
| &#039;both&#039; &lt;br /&gt;
| Extend the color bar on the upper and lower boundaries? Possible values are: &#039;neither&#039;, &#039;upper&#039;, &#039;lower&#039; and &#039;both&#039;. &lt;br /&gt;
|-&lt;br /&gt;
| gridcolor		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| mpl-color &lt;br /&gt;
| black &lt;br /&gt;
| Color lat/lon grid lines.&lt;br /&gt;
|-&lt;br /&gt;
| hook 			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| callable &lt;br /&gt;
| 	&lt;br /&gt;
| Function to apply to the data before plotting.&lt;br /&gt;
|-&lt;br /&gt;
| linestyles		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|      &lt;br /&gt;
| string &lt;br /&gt;
| 	&lt;br /&gt;
| Line styles for contours.&lt;br /&gt;
|-&lt;br /&gt;
| linewidths		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
|      &lt;br /&gt;
| int/list &lt;br /&gt;
| 	&lt;br /&gt;
| Line widths for contours.&lt;br /&gt;
|-&lt;br /&gt;
| m			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| Basemap	&lt;br /&gt;
| worldmap &lt;br /&gt;
| Map projection.&lt;br /&gt;
|-&lt;br /&gt;
| maskcolor		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| mpl-color &lt;br /&gt;
| light grey &lt;br /&gt;
| Color of the parts below orography.&lt;br /&gt;
|-&lt;br /&gt;
| mark			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| tuple of list &lt;br /&gt;
| &lt;br /&gt;
| Tuple containing list of x-coordinates and y-coordinates to be marked on the map with circles.&lt;br /&gt;
|-&lt;br /&gt;
| oroalpha		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| float &lt;br /&gt;
| 0.4 &lt;br /&gt;
| Transparency of the orography isolines, which 0 being entirely translucent.&lt;br /&gt;
|-&lt;br /&gt;
| orocolor		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| mpl-color &lt;br /&gt;
| black &lt;br /&gt;
| Color of the orography isolines.&lt;br /&gt;
|-&lt;br /&gt;
| oroscale		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| int/list &lt;br /&gt;
| &amp;amp;Delta;=1000 m &lt;br /&gt;
| Anything matplotlib accepts as a scale.&lt;br /&gt;
|-&lt;br /&gt;
| overlays		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| list of overlay &lt;br /&gt;
| &lt;br /&gt;
| List of overlays (being fronts or countours) to plot on top.&lt;br /&gt;
|-&lt;br /&gt;
| plev			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| string/int &lt;br /&gt;
| 	&lt;br /&gt;
| Vertical level of the plot. Used to auto-mask intersections with orography using the ERA-Interim average height of the level.&lt;br /&gt;
|-&lt;br /&gt;
| scale			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| list/int/string &lt;br /&gt;
| &#039;auto&#039; &lt;br /&gt;
| If &#039;auto&#039;, use the configurable autoscaling (see scale*-properties), otherwise anything &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; accepts.&lt;br /&gt;
|-&lt;br /&gt;
| scale_exceed_percentiles &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| tuple of float&lt;br /&gt;
| (0.02, 0.98) &lt;br /&gt;
| Percentiles giving the minimal displayed data coverage of the colorbar. For the default values, the lowermost and uppermost inverval cuts of maximally 2% of the data values.&lt;br /&gt;
|-&lt;br /&gt;
| scale_intervals 	&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| list of int &lt;br /&gt;
| [1,2,3,5,10]	&lt;br /&gt;
| Which intervals are considered to be &amp;quot;round&amp;quot;? By default it is this list for any order of magnitude.&lt;br /&gt;
|-&lt;br /&gt;
| scale_intervals_periodic &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| bool &lt;br /&gt;
| True &lt;br /&gt;
| Which intervals are considered to be &amp;quot;round&amp;quot;? If set to &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt; the above list applies only for the given order of magnitude.&lt;br /&gt;
|-&lt;br /&gt;
| scale_target_steps &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| int 	&lt;br /&gt;
| 7 	&lt;br /&gt;
| If &amp;lt;code&amp;gt;scale=&#039;auto&#039;&amp;lt;/code&amp;gt;, how many intervals are desired? The actual intervals might be a few more/less, to allow for a &amp;quot;round&amp;quot; interval value.&lt;br /&gt;
|-&lt;br /&gt;
| scale_symmetric_zero &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| bool 	&lt;br /&gt;
| False &lt;br /&gt;
| If &amp;lt;code&amp;gt;scale=&#039;auto&#039;&amp;lt;/code&amp;gt;, force the scale to be symmetric around zero.&lt;br /&gt;
|-&lt;br /&gt;
| save			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| string 	&lt;br /&gt;
| 	&lt;br /&gt;
| If not &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;, save plot as the given file name with full path.&lt;br /&gt;
|-&lt;br /&gt;
| show			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| bool 	&lt;br /&gt;
| True 	&lt;br /&gt;
| Show the plot in a window.&lt;br /&gt;
|-&lt;br /&gt;
| ticks			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| list 	&lt;br /&gt;
|  	&lt;br /&gt;
| Where to put the ticks on the colorbar.&lt;br /&gt;
|-&lt;br /&gt;
| ticklabels		&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| list 	&lt;br /&gt;
|  	&lt;br /&gt;
| How to label the ticks.&lt;br /&gt;
|-&lt;br /&gt;
| title			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| string 	&lt;br /&gt;
|  	&lt;br /&gt;
| Title for the plot.&lt;br /&gt;
|-&lt;br /&gt;
| Zdata			&lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| &amp;amp;#10003; &lt;br /&gt;
| numpy.ndarray &lt;br /&gt;
| &lt;br /&gt;
| 2D geopotential height field, used for masking intersections with orography.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=761</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=761"/>
		<updated>2016-11-17T09:18:56Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || Olafur Rognvaldsson || || Some python software solutions (&amp;quot;wiski&amp;quot;,&amp;quot;DropDigits&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || Patrik Bohlinger || || Some results on trends in extreme precipitation in Nepal&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || Tobias Wolf-Grosse || || Trial lecture: Rossby waves in a warmer climate &amp;lt;p&amp;gt;(Auditorium, kl. 12:15)&amp;lt;/p&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || John Cassano &amp;lt;p&amp;gt;(University of Colorado)&amp;lt;/p&amp;gt; || || Observations of the Antarctic Boundary Layer Using SUMO UAVs&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=760</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=760"/>
		<updated>2016-11-10T09:19:05Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || Olafur Rognvaldsson || || Some python software solutions (&amp;quot;wiski&amp;quot;,&amp;quot;DropDigits&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || Patrik Bohlinger || || Some results on trends in extreme precipitation in Nepal&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || Tobias Wolf || || Trial lecture: Rossby waves in a warmer climate &amp;lt;p&amp;gt;(Auditorium, kl. 12:15)&amp;lt;/p&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || John Cassano &amp;lt;p&amp;gt;(University of Colorado)&amp;lt;/p&amp;gt; || || Observations of the Antarctic Boundary Layer Using SUMO UAVs&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=704</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=704"/>
		<updated>2016-11-03T14:27:11Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || Olafur Rognvaldsson || || Some python software solutions (&amp;quot;wiski&amp;quot;,&amp;quot;DropDigits&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || Tobias Wolf || || Trial lecture: Rossby waves in a warmer climate &amp;lt;p&amp;gt;(Auditorium, kl. 12:15)&amp;lt;/p&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || John Cassano &amp;lt;p&amp;gt;(University of Colorado)&amp;lt;/p&amp;gt; || || Observations of the Antarctic Boundary Layer Using SUMO UAVs&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=627</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=627"/>
		<updated>2016-10-31T14:58:05Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || Olafur Rognvaldsson || || Some python software solutions (&amp;quot;wiski&amp;quot;,&amp;quot;DropDigits&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || Tobias Wolf || || Trial lecture&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || John Cassano &amp;lt;p&amp;gt;(University of Colorado)&amp;lt;/p&amp;gt; || || Observations of the Antarctic Boundary Layer Using SUMO UAVs&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=608</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=608"/>
		<updated>2016-10-20T09:25:13Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || Olafur Rognvaldsson || || Some python software solutions (&amp;quot;wiski&amp;quot;,&amp;quot;DropDigits&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || John Cassano &amp;lt;p&amp;gt;(University of Colorado)&amp;lt;/p&amp;gt; || || Observations of the Antarctic Boundary Layer Using SUMO UAVs&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=607</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=607"/>
		<updated>2016-10-20T09:01:38Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || John Cassano &amp;lt;p&amp;gt;(University of Colorado)&amp;lt;/p&amp;gt; || || Observations of the Antarctic Boundary Layer Using SUMO UAVs&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=606</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=606"/>
		<updated>2016-10-13T11:57:54Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || Oscar Esli Jurado de Larios || || Applications of atmospheric modelling for storm surge forecast in Africa&lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=605</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=605"/>
		<updated>2016-10-05T07:09:45Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~20 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=604</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=604"/>
		<updated>2016-10-05T07:08:12Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || Kristine Haualand || ~15 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || Kristine Haualand || ~15 min|| Introduction to &amp;quot;Euro forecasting contest&amp;quot; (2)&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=603</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=603"/>
		<updated>2016-10-04T23:40:29Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || Katharina Lehner || || Isotope gradient in Southern Norway&lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
	<entry>
		<id>http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=602</id>
		<title>Meteorology Calendar Autumn 2016</title>
		<link rel="alternate" type="text/html" href="http://gfi.wiki.uib.no/index.php?title=Meteorology_Calendar_Autumn_2016&amp;diff=602"/>
		<updated>2016-09-09T09:19:36Z</updated>

		<summary type="html">&lt;p&gt;Ywe041: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Meteorology Group Lunch Meeting takes usually place on Thursday, starting 12:05 in the Helland Hansen meeting room on the third floor of the GFI main building.&lt;br /&gt;
&lt;br /&gt;
At the start of each meeting we will have an information exchange of 5-10 minutes to have updates on subjects such as recent and upcoming conferences or past weather events.&lt;br /&gt;
&lt;br /&gt;
For the Autumn semester 2016 [mailto:Yongbiao.Weng@uib.no Yongbiao Weng] and [mailto:Astrid.Fremme@uib.no Astrid Kristine Fremme] are in charge for organizing the seminar speakers. So please send them an email if you would like to present something.&lt;br /&gt;
&lt;br /&gt;
For presentations please keep contributions between &#039;&#039;&#039;15&#039;&#039;&#039; and max. &#039;&#039;&#039;25&#039;&#039;&#039; minutes to leave enough time for discussion of the material. We will have maximum one long presentation per meeting and can accommodate an additional couple of shorter ones, which can be project presentations or other group related issues.&lt;br /&gt;
&lt;br /&gt;
Back to [[Meteorology_Calendar|main Calendar]]&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;text-align:left&amp;quot;| Itinerary: &lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;100&amp;quot; | Date &lt;br /&gt;
! width=&amp;quot;180&amp;quot; | Who&lt;br /&gt;
! width=&amp;quot;120&amp;quot; | Length&lt;br /&gt;
! width=&amp;quot;600&amp;quot; | Title&lt;br /&gt;
|-&lt;br /&gt;
| 18.08.16 || ! colspan=&amp;quot;3&amp;quot; | Information Exchange &lt;br /&gt;
|-&lt;br /&gt;
| 25.08.16 || Line Båserud || || PhD mid‐term evaluation&lt;br /&gt;
|-&lt;br /&gt;
| 01.09.16 || Sentia Goursaud &amp;lt;p&amp;gt;(LGGE &amp;amp; LSCE, France)&amp;lt;/p&amp;gt; || || Recent variability of climate in East Antarctica from the analysis of proxy records and atmospheric modelling&lt;br /&gt;
|-&lt;br /&gt;
| 08.09.16 || ! colspan=&amp;quot;3&amp;quot; | GFI Institute Seminar&lt;br /&gt;
|-&lt;br /&gt;
| 15.09.16 || Omar El Guernaoui || || Surface inhomogeneities effects on the daytime convective boundary layer&lt;br /&gt;
|-&lt;br /&gt;
| 22.09.16 || Mathew Stiller-Reeve || || Working with an artist in a community-based climate research project in Bangladesh&lt;br /&gt;
|-&lt;br /&gt;
| 29.09.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 06.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 13.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 20.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 27.10.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 03.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 10.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 17.11.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 24.11.16 || || || &lt;br /&gt;
|-&lt;br /&gt;
| 01.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 08.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 15.12.16 || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 22.12.16 || || || &lt;br /&gt;
|-}&lt;/div&gt;</summary>
		<author><name>Ywe041</name></author>
	</entry>
</feed>