\hypertarget{namespacemom__neutral__diffusion}{}\doxysection{mom\+\_\+neutral\+\_\+diffusion Module Reference}
\label{namespacemom__neutral__diffusion}\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}


\doxysubsection{Detailed Description}
A column-\/wise toolbox for implementing neutral diffusion. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the M\+O\+M\+\_\+neutral\+\_\+diffusion module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__neutral__diffusion_a39ce023f4b8ebc8d30f25a9b1ca93925}{neutral\+\_\+diffusion\+\_\+init}} (Time, G, US, param\+\_\+file, diag, E\+OS, diabatic\+\_\+\+C\+Sp, CS)
\begin{DoxyCompactList}\small\item\em Read parameters and allocate control structure for neutral\+\_\+diffusion module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__neutral__diffusion_abc3fd398047ffb61825ceced9ae5ff41}{neutral\+\_\+diffusion\+\_\+calc\+\_\+coeffs}} (G, GV, US, h, T, S, CS, p\+\_\+surf)
\begin{DoxyCompactList}\small\item\em Calculate remapping factors for u/v columns used to map adjoining columns to a shared coordinate space. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__neutral__diffusion_a5469b7be43f8c428f092b58dd5ca41c8}{neutral\+\_\+diffusion}} (G, GV, h, Coef\+\_\+x, Coef\+\_\+y, dt, Reg, US, CS)
\begin{DoxyCompactList}\small\item\em Update tracer concentration due to neutral diffusion; layer thickness unchanged by this update. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_aec9b89b6a5ddc81f102309b964a0b969}{interface\+\_\+scalar}} (nk, h, S, Si, i\+\_\+method, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Returns interface scalar, Si, for a column of layer values, S. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_ae931a15b9ab6a7672b005eb5fe382219}{ppm\+\_\+edge}} (hkm1, hk, hkp1, hkp2, Ak, Akp1, Pk, Pkp1, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Returns the P\+PM quasi-\/fourth order edge value at k+1/2 following equation 1.\+6 in Colella \& Woodward, 1984\+: J\+CP 54, 174-\/201. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a6931d9a07d09aa5d76d5abd2e47a54df}{ppm\+\_\+ave}} (xL, xR, aL, aR, a\+Mean)
\begin{DoxyCompactList}\small\item\em Returns the average of a P\+PM reconstruction between two fractional positions. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a118ace85483009d5b7a1841e3c745499}{signum}} (a, x)
\begin{DoxyCompactList}\small\item\em A true signum function that returns either -\/abs(a), when x$<$0; or abs(a) when x$>$0; or 0 when x=0. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_ac211ae488cb6e3c6685df85d24ecd0dd}{plm\+\_\+diff}} (nk, h, S, c\+\_\+method, b\+\_\+method, diff)
\begin{DoxyCompactList}\small\item\em Returns P\+LM slopes for a column where the slopes are the difference in value across each cell. The limiting follows equation 1.\+8 in Colella \& Woodward, 1984\+: J\+CP 54, 174-\/201. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a1c5ac28d7c54581cdd872fe58ef0b204}{fv\+\_\+diff}} (hkm1, hk, hkp1, Skm1, Sk, Skp1)
\begin{DoxyCompactList}\small\item\em Returns the cell-\/centered second-\/order finite volume (unlimited P\+LM) slope using three consecutive cell widths and average values. Slope is returned as a difference across the central cell (i.\+e. units of scalar S). Discretization follows equation 1.\+7 in Colella \& Woodward, 1984\+: J\+CP 54, 174-\/201. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a6ed3814088af470ad6fc4a3a80926fd7}{fvlsq\+\_\+slope}} (hkm1, hk, hkp1, Skm1, Sk, Skp1)
\begin{DoxyCompactList}\small\item\em Returns the cell-\/centered second-\/order weighted least squares slope using three consecutive cell widths and average values. Slope is returned as a gradient (i.\+e. units of scalar S over width units). \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_acb07c024cb6aa162a8789a4f50139aa5}{find\+\_\+neutral\+\_\+surface\+\_\+positions\+\_\+continuous}} (nk, Pl, Tl, Sl, d\+Rd\+Tl, d\+Rd\+Sl, Pr, Tr, Sr, d\+Rd\+Tr, d\+Rd\+Sr, PoL, PoR, KoL, KoR, h\+Eff, bl\+\_\+kl, bl\+\_\+kr, bl\+\_\+zl, bl\+\_\+zr)
\begin{DoxyCompactList}\small\item\em Returns positions within left/right columns of combined interfaces using continuous reconstructions of T/S. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a666836e70bdae7ef4ec271246cf91993}{interpolate\+\_\+for\+\_\+nondim\+\_\+position}} (d\+Rho\+Neg, Pneg, d\+Rho\+Pos, Ppos)
\begin{DoxyCompactList}\small\item\em Returns the non-\/dimensional position between Pneg and Ppos where the interpolated density difference equals zero. The result is always bounded to be between 0 and 1. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_a72eca09bc6cc25f8a3831ad8e2be91d4}{find\+\_\+neutral\+\_\+surface\+\_\+positions\+\_\+discontinuous}} (CS, nk, Pres\+\_\+l, hcol\+\_\+l, Tl, Sl, ppoly\+\_\+\+T\+\_\+l, ppoly\+\_\+\+S\+\_\+l, stable\+\_\+l, Pres\+\_\+r, hcol\+\_\+r, Tr, Sr, ppoly\+\_\+\+T\+\_\+r, ppoly\+\_\+\+S\+\_\+r, stable\+\_\+r, PoL, PoR, KoL, KoR, h\+Eff, zeta\+\_\+bot\+\_\+L, zeta\+\_\+bot\+\_\+R, k\+\_\+bot\+\_\+L, k\+\_\+bot\+\_\+R, hard\+\_\+fail\+\_\+heff)
\begin{DoxyCompactList}\small\item\em Higher order version of find\+\_\+neutral\+\_\+surface\+\_\+positions. Returns positions within left/right columns of combined interfaces using intracell reconstructions of T/S. Note that the polynomial reconstrcutions of T and S are optional to aid with unit testing, but will always be passed otherwise. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_a3ef7040590d6448a34013763e17edf47}{mark\+\_\+unstable\+\_\+cells}} (CS, nk, T, S, P, stable\+\_\+cell)
\begin{DoxyCompactList}\small\item\em Sweep down through the column and mark as stable if the bottom interface of a cell is denser than the top. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a2952cbcce84dbdae01fce09240f819c5}{search\+\_\+other\+\_\+column}} (CS, ksurf, pos\+\_\+last, T\+\_\+from, S\+\_\+from, P\+\_\+from, T\+\_\+top, S\+\_\+top, P\+\_\+top, T\+\_\+bot, S\+\_\+bot, P\+\_\+bot, T\+\_\+poly, S\+\_\+poly)
\begin{DoxyCompactList}\small\item\em Searches the \char`\"{}other\char`\"{} (searched) column for the position of the neutral surface. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_aa8a9c4a6e7e96ae356f913d4e8611f17}{increment\+\_\+interface}} (nk, kl, ki, reached\+\_\+bottom, searching\+\_\+this\+\_\+column, searching\+\_\+other\+\_\+column)
\begin{DoxyCompactList}\small\item\em Increments the interface which was just connected and also set flags if the bottom is reached. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a464e946951f3bbf7e2df500831c7afd4}{find\+\_\+neutral\+\_\+pos\+\_\+linear}} (CS, z0, T\+\_\+ref, S\+\_\+ref, d\+Rd\+T\+\_\+ref, d\+Rd\+S\+\_\+ref, d\+Rd\+T\+\_\+top, d\+Rd\+S\+\_\+top, d\+Rd\+T\+\_\+bot, d\+Rd\+S\+\_\+bot, ppoly\+\_\+T, ppoly\+\_\+S)
\begin{DoxyCompactList}\small\item\em Search a layer to find where delta\+\_\+rho = 0 based on a linear interpolation of alpha and beta of the top and bottom being searched and polynomial reconstructions of T and S. Compressibility is not needed because either, we are assuming incompressibility in the equation of state for this module or alpha and beta are calculated having been displaced to the average pressures of the two pressures We need Newton\textquotesingle{}s method because the T and S reconstructions make delta\+\_\+rho a polynomial function of z if using P\+PM or higher. If Newton\textquotesingle{}s method would search fall out of the interval \mbox{[}0,1\mbox{]}, a bisection step would be taken instead. Also this linearization of alpha, beta means that second derivatives of the E\+OS are not needed. Note that delta in variable names below refers to horizontal differences and \textquotesingle{}d\textquotesingle{} refers to vertical differences. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a8bef35a99b64bf7afad086a557ba7c1d}{find\+\_\+neutral\+\_\+pos\+\_\+full}} (CS, z0, T\+\_\+ref, S\+\_\+ref, P\+\_\+ref, P\+\_\+top, P\+\_\+bot, ppoly\+\_\+T, ppoly\+\_\+S)
\begin{DoxyCompactList}\small\item\em Use the full equation of state to calculate the difference in locally referenced potential density. The derivatives in this case are not trivial to calculate, so instead we use a regula falsi method. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_a096623adeec0973cbb99cb9048946ad3}{calc\+\_\+delta\+\_\+rho\+\_\+and\+\_\+derivs}} (CS, T1, S1, p1\+\_\+in, T2, S2, p2\+\_\+in, drho, drdt1\+\_\+out, drds1\+\_\+out, drdt2\+\_\+out, drds2\+\_\+out)
\begin{DoxyCompactList}\small\item\em Calculate the difference in density between two points in a variety of ways. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_ae0420673e01c23b26e87dc68317347a1}{delta\+\_\+rho\+\_\+from\+\_\+derivs}} (T1, S1, P1, d\+Rd\+T1, d\+Rd\+S1, T2, S2, P2, d\+Rd\+T2, d\+Rd\+S2)
\begin{DoxyCompactList}\small\item\em Calculate delta rho from derivatives and gradients of properties $ \Delta \rho = \frac{1}{2}\left[ (\alpha_1 + \alpha_2)*(T_1-T_2) + (\beta_1 + \beta_2)*(S_1-S_2) + (\gamma^{-1}_1 + \gamma^{-1}_2)*(P_1-P_2) \right] $. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__neutral__diffusion_a16279fc70f169ee1011030e7afecdd4e}{absolute\+\_\+position}} (n, ns, Pint, Karr, N\+Parr, k\+\_\+surface)
\begin{DoxyCompactList}\small\item\em Converts non-\/dimensional position within a layer to absolute position (for debugging) \end{DoxyCompactList}\item 
real function, dimension(ns) \mbox{\hyperlink{namespacemom__neutral__diffusion_a515d1738f61e410218b0c268c37807b3}{absolute\+\_\+positions}} (n, ns, Pint, Karr, N\+Parr)
\begin{DoxyCompactList}\small\item\em Converts non-\/dimensional positions within layers to absolute positions (for debugging) \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_aa394289328ee392cdb17000fb6fa90e8}{neutral\+\_\+surface\+\_\+flux}} (nk, nsurf, deg, hl, hr, Tl, Tr, PiL, PiR, KoL, KoR, h\+Eff, Flx, continuous, h\+\_\+neglect, remap\+\_\+\+CS, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Returns a single column of neutral diffusion fluxes of a tracer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_a005d759280cfcb84cafa23a984ffc818}{neutral\+\_\+surface\+\_\+t\+\_\+eval}} (nk, ns, k\+\_\+sub, Ks, Ps, T\+\_\+mean, T\+\_\+int, deg, i\+Method, T\+\_\+poly, T\+\_\+top, T\+\_\+bot, T\+\_\+sub, T\+\_\+top\+\_\+int, T\+\_\+bot\+\_\+int, T\+\_\+layer)
\begin{DoxyCompactList}\small\item\em Evaluate various parts of the reconstructions to calculate gradient-\/based flux limter. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__neutral__diffusion_a9b380e21dcc9c53efcec4712228b931f}{ppm\+\_\+left\+\_\+right\+\_\+edge\+\_\+values}} (nk, Tl, Ti, aL, aR)
\begin{DoxyCompactList}\small\item\em Discontinuous P\+PM reconstructions of the left/right edge values within a cell. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__neutral__diffusion_a6f91c93a6363fb39395796420f25fad2}{neutral\+\_\+diffusion\+\_\+unit\+\_\+tests}} (verbose)
\begin{DoxyCompactList}\small\item\em Returns true if unit tests of neutral\+\_\+diffusion functions fail. Otherwise returns false. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_a9aaf0988f76c9992d8f1db48ce23bf34}{ndiff\+\_\+unit\+\_\+tests\+\_\+continuous}} (verbose)
\begin{DoxyCompactList}\small\item\em Returns true if unit tests of neutral\+\_\+diffusion functions fail. Otherwise returns false. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_aa44f980bb24df5dc71913b32892b2f71}{ndiff\+\_\+unit\+\_\+tests\+\_\+discontinuous}} (verbose)
\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_ac51219df490c739774d70d9958bae047}{test\+\_\+fv\+\_\+diff}} (verbose, hkm1, hk, hkp1, Skm1, Sk, Skp1, Ptrue, title)
\begin{DoxyCompactList}\small\item\em Returns true if a test of \mbox{\hyperlink{namespacemom__neutral__diffusion_a1c5ac28d7c54581cdd872fe58ef0b204}{fv\+\_\+diff()}} fails, and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_ad964ab49cd5901b79dc32f2367d24aed}{test\+\_\+fvlsq\+\_\+slope}} (verbose, hkm1, hk, hkp1, Skm1, Sk, Skp1, Ptrue, title)
\begin{DoxyCompactList}\small\item\em Returns true if a test of \mbox{\hyperlink{namespacemom__neutral__diffusion_a6ed3814088af470ad6fc4a3a80926fd7}{fvlsq\+\_\+slope()}} fails, and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_a1a21234946c77d1e4ed852a4173503f1}{test\+\_\+ifndp}} (verbose, rho\+Neg, Pneg, rho\+Pos, Ppos, Ptrue, title)
\begin{DoxyCompactList}\small\item\em Returns true if a test of \mbox{\hyperlink{namespacemom__neutral__diffusion_a666836e70bdae7ef4ec271246cf91993}{interpolate\+\_\+for\+\_\+nondim\+\_\+position()}} fails, and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_a2870eae4b580e548577943e34321b8f0}{test\+\_\+data1d}} (verbose, nk, Po, Ptrue, title)
\begin{DoxyCompactList}\small\item\em Returns true if comparison of Po and Ptrue fails, and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_aaa2d682e80cdba470a09bcff6bda1767}{test\+\_\+data1di}} (verbose, nk, Po, Ptrue, title)
\begin{DoxyCompactList}\small\item\em Returns true if comparison of Po and Ptrue fails, and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_ab5eaa2002c1f6405f5037645bbca3101}{test\+\_\+nsp}} (verbose, ns, KoL, KoR, pL, pR, h\+Eff, Ko\+L0, Ko\+R0, p\+L0, p\+R0, h\+Eff0, title)
\begin{DoxyCompactList}\small\item\em Returns true if output of find\+\_\+neutral\+\_\+surface\+\_\+positions() does not match correct values, and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_a5725b17791c79900343532931ac04503}{compare\+\_\+nsp\+\_\+row}} (KoL, KoR, pL, pR, Ko\+L0, Ko\+R0, p\+L0, p\+R0)
\begin{DoxyCompactList}\small\item\em Compares a single row, k, of output from find\+\_\+neutral\+\_\+surface\+\_\+positions() \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__neutral__diffusion_ab75333897fa8800441d8eddc1720f631}{test\+\_\+rnp}} (expected\+\_\+pos, test\+\_\+pos, title)
\begin{DoxyCompactList}\small\item\em Compares output position from refine\+\_\+nondim\+\_\+position with an expected value. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__neutral__diffusion_ae8a313d25818dfa8c3bc056210fac76b}{neutral\+\_\+diffusion\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Deallocates neutral\+\_\+diffusion control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__neutral__diffusion_afdf44450544eb51e29afe3454ecbc0cc}\label{namespacemom__neutral__diffusion_afdf44450544eb51e29afe3454ecbc0cc}} 
character(len=40) \mbox{\hyperlink{namespacemom__neutral__diffusion_afdf44450544eb51e29afe3454ecbc0cc}{mdl}} = \char`\"{}M\+O\+M\+\_\+neutral\+\_\+diffusion\char`\"{}
\begin{DoxyCompactList}\small\item\em module name \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a16279fc70f169ee1011030e7afecdd4e}\label{namespacemom__neutral__diffusion_a16279fc70f169ee1011030e7afecdd4e}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!absolute\_position@{absolute\_position}}
\index{absolute\_position@{absolute\_position}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{absolute\_position()}{absolute\_position()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::absolute\+\_\+position (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n,  }\item[{integer, intent(in)}]{ns,  }\item[{real, dimension(n+1), intent(in)}]{Pint,  }\item[{integer, dimension(ns), intent(in)}]{Karr,  }\item[{real, dimension(ns), intent(in)}]{N\+Parr,  }\item[{integer, intent(in)}]{k\+\_\+surface }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Converts non-\/dimensional position within a layer to absolute position (for debugging) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em ns} & Number of neutral surfaces \\
\hline
\mbox{\texttt{ in}}  & {\em pint} & Position of interfaces \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em karr} & Index of interface above position \\
\hline
\mbox{\texttt{ in}}  & {\em nparr} & Non-\/dimensional position within layer Karr(\+:) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+surface} & k-\/interface to query \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The absolute position of a location \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units following Pint 
\end{DoxyReturn}


Definition at line 1836 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1837   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{            !< Number of levels}}
\DoxyCodeLine{1838   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: ns\textcolor{comment}{           !< Number of neutral surfaces}}
\DoxyCodeLine{1839 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: Pint(n+1)\textcolor{comment}{    !< Position of interfaces [R L2 T-\/2 \string~> Pa] or other units}}
\DoxyCodeLine{1840   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: Karr(ns)\textcolor{comment}{     !< Index of interface above position}}
\DoxyCodeLine{1841 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: NParr(ns)\textcolor{comment}{    !< Non-\/dimensional position within layer Karr(:) [nondim]}}
\DoxyCodeLine{1842   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: k\_surface\textcolor{comment}{    !< k-\/interface to query}}
\DoxyCodeLine{1843 \textcolor{keywordtype}{  real}                :: absolute\_position\textcolor{comment}{ !< The absolute position of a location [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1844 \textcolor{comment}{                                      !! or other units following Pint}}
\DoxyCodeLine{1845   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1846   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1847 }
\DoxyCodeLine{1848   k = karr(k\_surface)}
\DoxyCodeLine{1849   \textcolor{keywordflow}{if} (k>n) stop \textcolor{stringliteral}{'absolute\_position: k>nk is out of bounds!'}}
\DoxyCodeLine{1850   absolute\_position = pint(k) + nparr(k\_surface) * ( pint(k+1) -\/ pint(k) )}
\DoxyCodeLine{1851 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a515d1738f61e410218b0c268c37807b3}\label{namespacemom__neutral__diffusion_a515d1738f61e410218b0c268c37807b3}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!absolute\_positions@{absolute\_positions}}
\index{absolute\_positions@{absolute\_positions}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{absolute\_positions()}{absolute\_positions()}}
{\footnotesize\ttfamily real function, dimension(ns) mom\+\_\+neutral\+\_\+diffusion\+::absolute\+\_\+positions (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n,  }\item[{integer, intent(in)}]{ns,  }\item[{real, dimension(n+1), intent(in)}]{Pint,  }\item[{integer, dimension(ns), intent(in)}]{Karr,  }\item[{real, dimension(ns), intent(in)}]{N\+Parr }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Converts non-\/dimensional positions within layers to absolute positions (for debugging) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em ns} & Number of neutral surfaces \\
\hline
\mbox{\texttt{ in}}  & {\em pint} & Position of interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em karr} & Indexes of interfaces about positions \\
\hline
\mbox{\texttt{ in}}  & {\em nparr} & Non-\/dimensional positions within layers Karr(\+:) \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Absolute positions \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units following Pint 
\end{DoxyReturn}


Definition at line 1855 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1856   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{         !< Number of levels}}
\DoxyCodeLine{1857   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: ns\textcolor{comment}{        !< Number of neutral surfaces}}
\DoxyCodeLine{1858 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: Pint(n+1)\textcolor{comment}{ !< Position of interface [R L2 T-\/2 \string~> Pa] or other units}}
\DoxyCodeLine{1859   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: Karr(ns)\textcolor{comment}{  !< Indexes of interfaces about positions}}
\DoxyCodeLine{1860 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: NParr(ns)\textcolor{comment}{ !< Non-\/dimensional positions within layers Karr(:)}}
\DoxyCodeLine{1861 }
\DoxyCodeLine{1862 \textcolor{keywordtype}{  real},  \textcolor{keywordtype}{dimension(ns)} :: absolute\_positions\textcolor{comment}{ !< Absolute positions [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1863 \textcolor{comment}{                                   !! or other units following Pint}}
\DoxyCodeLine{1864 }
\DoxyCodeLine{1865   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1866   \textcolor{keywordtype}{integer} :: k\_surface, k}
\DoxyCodeLine{1867 }
\DoxyCodeLine{1868   \textcolor{keywordflow}{do} k\_surface = 1, ns}
\DoxyCodeLine{1869     absolute\_positions(k\_surface) = absolute\_position(n,ns,pint,karr,nparr,k\_surface)}
\DoxyCodeLine{1870 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1871 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a096623adeec0973cbb99cb9048946ad3}\label{namespacemom__neutral__diffusion_a096623adeec0973cbb99cb9048946ad3}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!calc\_delta\_rho\_and\_derivs@{calc\_delta\_rho\_and\_derivs}}
\index{calc\_delta\_rho\_and\_derivs@{calc\_delta\_rho\_and\_derivs}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{calc\_delta\_rho\_and\_derivs()}{calc\_delta\_rho\_and\_derivs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::calc\+\_\+delta\+\_\+rho\+\_\+and\+\_\+derivs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}})}]{CS,  }\item[{real, intent(in)}]{T1,  }\item[{real, intent(in)}]{S1,  }\item[{real, intent(in)}]{p1\+\_\+in,  }\item[{real, intent(in)}]{T2,  }\item[{real, intent(in)}]{S2,  }\item[{real, intent(in)}]{p2\+\_\+in,  }\item[{real, intent(out)}]{drho,  }\item[{real, intent(out), optional}]{drdt1\+\_\+out,  }\item[{real, intent(out), optional}]{drds1\+\_\+out,  }\item[{real, intent(out), optional}]{drdt2\+\_\+out,  }\item[{real, intent(out), optional}]{drds2\+\_\+out }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the difference in density between two points in a variety of ways. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Neutral diffusion control structure \\
\hline
\mbox{\texttt{ in}}  & {\em t1} & Temperature at point 1 \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s1} & Salinity at point 1 \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p1\+\_\+in} & Pressure at point 1 \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t2} & Temperature at point 2 \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s2} & Salinity at point 2 \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p2\+\_\+in} & Pressure at point 2 \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em drho} & Difference in density between the two points \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em drdt1\+\_\+out} & drho\+\_\+dt at point 1 \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em drds1\+\_\+out} & drho\+\_\+ds at point 1 \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em drdt2\+\_\+out} & drho\+\_\+dt at point 2 \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em drds2\+\_\+out} & drho\+\_\+ds at point 2 \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1754 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1756   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS)    :: CS\textcolor{comment}{        !< Neutral diffusion control structure}}
\DoxyCodeLine{1757 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in   )} :: T1\textcolor{comment}{        !< Temperature at point 1 [degC]}}
\DoxyCodeLine{1758 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in   )} :: S1\textcolor{comment}{        !< Salinity at point 1 [ppt]}}
\DoxyCodeLine{1759 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in   )} :: p1\_in\textcolor{comment}{     !< Pressure at point 1 [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1760 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in   )} :: T2\textcolor{comment}{        !< Temperature at point 2 [degC]}}
\DoxyCodeLine{1761 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in   )} :: S2\textcolor{comment}{        !< Salinity at point 2 [ppt]}}
\DoxyCodeLine{1762 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in   )} :: p2\_in\textcolor{comment}{     !< Pressure at point 2 [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1763 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(  out)} :: drho\textcolor{comment}{      !< Difference in density between the two points [R \string~> kg m-\/3]}}
\DoxyCodeLine{1764 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: dRdT1\_out\textcolor{comment}{ !< drho\_dt at point 1 [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1765 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: dRdS1\_out\textcolor{comment}{ !< drho\_ds at point 1 [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1766 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: dRdT2\_out\textcolor{comment}{ !< drho\_dt at point 2 [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1767 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: dRdS2\_out\textcolor{comment}{ !< drho\_ds at point 2 [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1768   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1769 \textcolor{keywordtype}{  real} :: rho1, rho2   \textcolor{comment}{! Densities [R \string~> kg m-\/3]}}
\DoxyCodeLine{1770 \textcolor{keywordtype}{  real} :: p1, p2, pmid \textcolor{comment}{! Pressures [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1771 \textcolor{keywordtype}{  real} :: drdt1, drdt2 \textcolor{comment}{! Partial derivatives of density with temperature [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1772 \textcolor{keywordtype}{  real} :: drds1, drds2 \textcolor{comment}{! Partial derivatives of density with salinity [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1773 \textcolor{keywordtype}{  real} :: drdp1, drdp2 \textcolor{comment}{! Partial derivatives of density with pressure [T2 L-\/2 \string~> s2 m-\/2]}}
\DoxyCodeLine{1774 }
\DoxyCodeLine{1775   \textcolor{comment}{! Use the same reference pressure or the in-\/situ pressure}}
\DoxyCodeLine{1776   \textcolor{keywordflow}{if} (cs\%ref\_pres > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1777     p1 = cs\%ref\_pres}
\DoxyCodeLine{1778     p2 = cs\%ref\_pres}
\DoxyCodeLine{1779   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1780     p1 = p1\_in}
\DoxyCodeLine{1781     p2 = p2\_in}
\DoxyCodeLine{1782 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1783 }
\DoxyCodeLine{1784   \textcolor{comment}{! Use the full linear equation of state to calculate the difference in density (expensive!)}}
\DoxyCodeLine{1785   \textcolor{keywordflow}{if}     (trim(cs\%delta\_rho\_form) == \textcolor{stringliteral}{'full'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1786     pmid = 0.5 * (p1 + p2)}
\DoxyCodeLine{1787     \textcolor{keyword}{call }calculate\_density( t1, s1, pmid, rho1, cs\%EOS)}
\DoxyCodeLine{1788     \textcolor{keyword}{call }calculate\_density( t2, s2, pmid, rho2, cs\%EOS)}
\DoxyCodeLine{1789     drho = rho1 -\/ rho2}
\DoxyCodeLine{1790   \textcolor{comment}{! Use the density derivatives at the average of pressures and the differentces int temperature}}
\DoxyCodeLine{1791   \textcolor{keywordflow}{elseif} (trim(cs\%delta\_rho\_form) == \textcolor{stringliteral}{'mid\_pressure'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1792     pmid = 0.5 * (p1 + p2)}
\DoxyCodeLine{1793     \textcolor{keywordflow}{if} (cs\%ref\_pres>=0) pmid = cs\%ref\_pres}
\DoxyCodeLine{1794     \textcolor{keyword}{call }calculate\_density\_derivs(t1, s1, pmid, drdt1, drds1, cs\%EOS)}
\DoxyCodeLine{1795     \textcolor{keyword}{call }calculate\_density\_derivs(t2, s2, pmid, drdt2, drds2, cs\%EOS)}
\DoxyCodeLine{1796     drho = delta\_rho\_from\_derivs( t1, s1, p1, drdt1, drds1, t2, s2, p2, drdt2, drds2)}
\DoxyCodeLine{1797   \textcolor{keywordflow}{elseif} (trim(cs\%delta\_rho\_form) == \textcolor{stringliteral}{'local\_pressure'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1798     \textcolor{keyword}{call }calculate\_density\_derivs(t1, s1, p1, drdt1, drds1, cs\%EOS)}
\DoxyCodeLine{1799     \textcolor{keyword}{call }calculate\_density\_derivs(t2, s2, p2, drdt2, drds2, cs\%EOS)}
\DoxyCodeLine{1800     drho = delta\_rho\_from\_derivs( t1, s1, p1, drdt1, drds1, t2, s2, p2, drdt2, drds2)}
\DoxyCodeLine{1801   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1802     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}delta\_rho\_form is not recognized"{}})}
\DoxyCodeLine{1803 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1804 }
\DoxyCodeLine{1805   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(drdt1\_out)) drdt1\_out = drdt1}
\DoxyCodeLine{1806   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(drds1\_out)) drds1\_out = drds1}
\DoxyCodeLine{1807   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(drdt2\_out)) drdt2\_out = drdt2}
\DoxyCodeLine{1808   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(drds2\_out)) drds2\_out = drds2}
\DoxyCodeLine{1809 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a5725b17791c79900343532931ac04503}\label{namespacemom__neutral__diffusion_a5725b17791c79900343532931ac04503}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!compare\_nsp\_row@{compare\_nsp\_row}}
\index{compare\_nsp\_row@{compare\_nsp\_row}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{compare\_nsp\_row()}{compare\_nsp\_row()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::compare\+\_\+nsp\+\_\+row (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{KoL,  }\item[{integer, intent(in)}]{KoR,  }\item[{real, intent(in)}]{pL,  }\item[{real, intent(in)}]{pR,  }\item[{integer, intent(in)}]{Ko\+L0,  }\item[{integer, intent(in)}]{Ko\+R0,  }\item[{real, intent(in)}]{p\+L0,  }\item[{real, intent(in)}]{p\+R0 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Compares a single row, k, of output from find\+\_\+neutral\+\_\+surface\+\_\+positions() 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em kol} & Index of first left interface above neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em kor} & Index of first right interface above neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em pl} & Fractional position of neutral surface within layer KoL of left column \\
\hline
\mbox{\texttt{ in}}  & {\em pr} & Fractional position of neutral surface within layer KoR of right column \\
\hline
\mbox{\texttt{ in}}  & {\em kol0} & Correct value for KoL \\
\hline
\mbox{\texttt{ in}}  & {\em kor0} & Correct value for KoR \\
\hline
\mbox{\texttt{ in}}  & {\em pl0} & Correct value for pL \\
\hline
\mbox{\texttt{ in}}  & {\em pr0} & Correct value for pR \\
\hline
\end{DoxyParams}


Definition at line 2828 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2829   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: KoL\textcolor{comment}{   !< Index of first left interface above neutral surface}}
\DoxyCodeLine{2830   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: KoR\textcolor{comment}{   !< Index of first right interface above neutral surface}}
\DoxyCodeLine{2831 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{intent(in)} :: pL\textcolor{comment}{    !< Fractional position of neutral surface within layer KoL of left column}}
\DoxyCodeLine{2832 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{intent(in)} :: pR\textcolor{comment}{    !< Fractional position of neutral surface within layer KoR of right column}}
\DoxyCodeLine{2833   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: KoL0\textcolor{comment}{  !< Correct value for KoL}}
\DoxyCodeLine{2834   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: KoR0\textcolor{comment}{  !< Correct value for KoR}}
\DoxyCodeLine{2835 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{intent(in)} :: pL0\textcolor{comment}{   !< Correct value for pL}}
\DoxyCodeLine{2836 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{intent(in)} :: pR0\textcolor{comment}{   !< Correct value for pR}}
\DoxyCodeLine{2837 }
\DoxyCodeLine{2838   compare\_nsp\_row = .false.}
\DoxyCodeLine{2839   \textcolor{keywordflow}{if} (kol /= kol0) compare\_nsp\_row = .true.}
\DoxyCodeLine{2840   \textcolor{keywordflow}{if} (kor /= kor0) compare\_nsp\_row = .true.}
\DoxyCodeLine{2841   \textcolor{keywordflow}{if} (pl /= pl0) compare\_nsp\_row = .true.}
\DoxyCodeLine{2842   \textcolor{keywordflow}{if} (pr /= pr0) compare\_nsp\_row = .true.}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ae0420673e01c23b26e87dc68317347a1}\label{namespacemom__neutral__diffusion_ae0420673e01c23b26e87dc68317347a1}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!delta\_rho\_from\_derivs@{delta\_rho\_from\_derivs}}
\index{delta\_rho\_from\_derivs@{delta\_rho\_from\_derivs}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{delta\_rho\_from\_derivs()}{delta\_rho\_from\_derivs()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::delta\+\_\+rho\+\_\+from\+\_\+derivs (\begin{DoxyParamCaption}\item[{real}]{T1,  }\item[{real}]{S1,  }\item[{real}]{P1,  }\item[{real}]{d\+Rd\+T1,  }\item[{real}]{d\+Rd\+S1,  }\item[{real}]{T2,  }\item[{real}]{S2,  }\item[{real}]{P2,  }\item[{real}]{d\+Rd\+T2,  }\item[{real}]{d\+Rd\+S2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate delta rho from derivatives and gradients of properties $ \Delta \rho = \frac{1}{2}\left[ (\alpha_1 + \alpha_2)*(T_1-T_2) + (\beta_1 + \beta_2)*(S_1-S_2) + (\gamma^{-1}_1 + \gamma^{-1}_2)*(P_1-P_2) \right] $. 


\begin{DoxyParams}{Parameters}
{\em t1} & Temperature at point 1 \mbox{[}degC\mbox{]} \\
\hline
{\em s1} & Salinity at point 1 \mbox{[}ppt\mbox{]} \\
\hline
{\em p1} & Pressure at point 1 \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
{\em drdt1} & The partial derivative of density with temperature at point 1 \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
{\em drds1} & The partial derivative of density with salinity at point 1 \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
{\em t2} & Temperature at point 2 \mbox{[}degC\mbox{]} \\
\hline
{\em s2} & Salinity at point 2 \mbox{[}ppt\mbox{]} \\
\hline
{\em p2} & Pressure at point 2 \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
{\em drdt2} & The partial derivative of density with temperature at point 2 \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
{\em drds2} & The partial derivative of density with salinity at point 2 \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1816 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1818 \textcolor{keywordtype}{  real} :: T1\textcolor{comment}{    !< Temperature at point 1 [degC]}}
\DoxyCodeLine{1819 \textcolor{keywordtype}{  real} :: S1\textcolor{comment}{    !< Salinity at point 1 [ppt]}}
\DoxyCodeLine{1820 \textcolor{keywordtype}{  real} :: P1\textcolor{comment}{    !< Pressure at point 1 [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1821 \textcolor{keywordtype}{  real} :: dRdT1\textcolor{comment}{ !< The partial derivative of density with temperature at point 1 [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1822 \textcolor{keywordtype}{  real} :: dRdS1\textcolor{comment}{ !< The partial derivative of density with salinity at point 1 [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1823 \textcolor{keywordtype}{  real} :: T2\textcolor{comment}{    !< Temperature at point 2 [degC]}}
\DoxyCodeLine{1824 \textcolor{keywordtype}{  real} :: S2\textcolor{comment}{    !< Salinity at point 2 [ppt]}}
\DoxyCodeLine{1825 \textcolor{keywordtype}{  real} :: P2\textcolor{comment}{    !< Pressure at point 2 [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1826 \textcolor{keywordtype}{  real} :: dRdT2\textcolor{comment}{ !< The partial derivative of density with temperature at point 2 [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1827 \textcolor{keywordtype}{  real} :: dRdS2\textcolor{comment}{ !< The partial derivative of density with salinity at point 2 [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1828   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1829 \textcolor{keywordtype}{  real} :: drho  \textcolor{comment}{! The density difference [R \string~> kg m-\/3]}}
\DoxyCodeLine{1830 }
\DoxyCodeLine{1831   drho = 0.5 * ( (drdt1+drdt2)*(t1-\/t2) + (drds1+drds2)*(s1-\/s2))}
\DoxyCodeLine{1832 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a8bef35a99b64bf7afad086a557ba7c1d}\label{namespacemom__neutral__diffusion_a8bef35a99b64bf7afad086a557ba7c1d}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!find\_neutral\_pos\_full@{find\_neutral\_pos\_full}}
\index{find\_neutral\_pos\_full@{find\_neutral\_pos\_full}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{find\_neutral\_pos\_full()}{find\_neutral\_pos\_full()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::find\+\_\+neutral\+\_\+pos\+\_\+full (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), intent(in)}]{CS,  }\item[{real, intent(in)}]{z0,  }\item[{real, intent(in)}]{T\+\_\+ref,  }\item[{real, intent(in)}]{S\+\_\+ref,  }\item[{real, intent(in)}]{P\+\_\+ref,  }\item[{real, intent(in)}]{P\+\_\+top,  }\item[{real, intent(in)}]{P\+\_\+bot,  }\item[{real, dimension(\+:), intent(in)}]{ppoly\+\_\+T,  }\item[{real, dimension(\+:), intent(in)}]{ppoly\+\_\+S }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Use the full equation of state to calculate the difference in locally referenced potential density. The derivatives in this case are not trivial to calculate, so instead we use a regula falsi method. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Control structure with parameters for this module \\
\hline
\mbox{\texttt{ in}}  & {\em z0} & Lower bound of position, also serves as the initial guess \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+ref} & Temperature at the searched from interface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+ref} & Salinity at the searched from interface \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+ref} & Pressure at the searched from interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+top} & Pressure at top of layer being searched \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+bot} & Pressure at bottom of layer being searched \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+t} & Coefficients of the polynomial reconstruction of T within the layer to be searched \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+s} & Coefficients of the polynomial reconstruction of T within the layer to be searched \mbox{[}ppt\mbox{]} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Position where drho = 0 \mbox{[}nondim\mbox{]} 
\end{DoxyReturn}


Definition at line 1661 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1662   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS),\textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{        !< Control structure with parameters for this module}}
\DoxyCodeLine{1663 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: z0\textcolor{comment}{        !< Lower bound of position, also serves as the}}
\DoxyCodeLine{1664 \textcolor{comment}{                                                     !! initial guess [nondim]}}
\DoxyCodeLine{1665 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: T\_ref\textcolor{comment}{     !< Temperature at the searched from interface [degC]}}
\DoxyCodeLine{1666 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: S\_ref\textcolor{comment}{     !< Salinity at the searched from interface [ppt]}}
\DoxyCodeLine{1667 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: P\_ref\textcolor{comment}{     !< Pressure at the searched from interface [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1668 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: P\_top\textcolor{comment}{     !< Pressure at top of layer being searched [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1669 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: P\_bot\textcolor{comment}{     !< Pressure at bottom of layer being searched [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1670 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},        \textcolor{keywordtype}{intent(in)} :: ppoly\_T\textcolor{comment}{   !< Coefficients of the polynomial reconstruction of T within}}
\DoxyCodeLine{1671 \textcolor{comment}{                                                     !! the layer to be searched [degC]}}
\DoxyCodeLine{1672 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},        \textcolor{keywordtype}{intent(in)} :: ppoly\_S\textcolor{comment}{   !< Coefficients of the polynomial reconstruction of T within}}
\DoxyCodeLine{1673 \textcolor{comment}{                                                     !! the layer to be searched [ppt]}}
\DoxyCodeLine{1674 \textcolor{keywordtype}{  real}                                  :: z\textcolor{comment}{         !< Position where drho = 0 [nondim]}}
\DoxyCodeLine{1675   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1676   \textcolor{keywordtype}{integer} :: iter}
\DoxyCodeLine{1677   \textcolor{keywordtype}{integer} :: nterm}
\DoxyCodeLine{1678 }
\DoxyCodeLine{1679 \textcolor{keywordtype}{  real} :: drho\_a, drho\_b, drho\_c \textcolor{comment}{! Density differences [R \string~> kg m-\/3]}}
\DoxyCodeLine{1680 \textcolor{keywordtype}{  real} :: a, b, c     \textcolor{comment}{! Fractional positions [nondim]}}
\DoxyCodeLine{1681 \textcolor{keywordtype}{  real} :: Ta, Tb, Tc  \textcolor{comment}{! Temperatures [degC]}}
\DoxyCodeLine{1682 \textcolor{keywordtype}{  real} :: Sa, Sb, Sc  \textcolor{comment}{! Salinities [ppt]}}
\DoxyCodeLine{1683 \textcolor{keywordtype}{  real} :: Pa, Pb, Pc  \textcolor{comment}{! Pressures [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1684   \textcolor{keywordtype}{integer} :: side}
\DoxyCodeLine{1685 }
\DoxyCodeLine{1686   side = 0}
\DoxyCodeLine{1687   \textcolor{comment}{! Set the first two evaluation to the endpoints of the interval}}
\DoxyCodeLine{1688   b = z0 ; c = 1}
\DoxyCodeLine{1689   nterm = \textcolor{keyword}{SIZE}(ppoly\_t)}
\DoxyCodeLine{1690 }
\DoxyCodeLine{1691   \textcolor{comment}{! Calculate drho at the minimum bound}}
\DoxyCodeLine{1692   tb = evaluation\_polynomial( ppoly\_t, nterm, b )}
\DoxyCodeLine{1693   sb = evaluation\_polynomial( ppoly\_s, nterm, b )}
\DoxyCodeLine{1694   pb = p\_top*(1.-\/b) + p\_bot*b}
\DoxyCodeLine{1695   \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, tb, sb, pb, t\_ref, s\_ref, p\_ref, drho\_b)}
\DoxyCodeLine{1696 }
\DoxyCodeLine{1697   \textcolor{comment}{! Calculate drho at the maximum bound}}
\DoxyCodeLine{1698   tc = evaluation\_polynomial( ppoly\_t, nterm, 1. )}
\DoxyCodeLine{1699   sc = evaluation\_polynomial( ppoly\_s, nterm, 1. )}
\DoxyCodeLine{1700   pc = p\_bot}
\DoxyCodeLine{1701   \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, tc, sc, pc, t\_ref, s\_ref, p\_ref, drho\_c)}
\DoxyCodeLine{1702 }
\DoxyCodeLine{1703   \textcolor{keywordflow}{if} (drho\_b >= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1704     z = z0}
\DoxyCodeLine{1705     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1706   \textcolor{keywordflow}{elseif} (drho\_c == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1707     z = 1.}
\DoxyCodeLine{1708     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1709 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1710   \textcolor{keywordflow}{if} ( sign(1.,drho\_b) == sign(1.,drho\_c) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1711     z = z0}
\DoxyCodeLine{1712     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1713 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1714 }
\DoxyCodeLine{1715   \textcolor{keywordflow}{do} iter = 1, cs\%max\_iter}
\DoxyCodeLine{1716     \textcolor{comment}{! Calculate new position and evaluate if we have converged}}
\DoxyCodeLine{1717     a = (drho\_b*c -\/ drho\_c*b)/(drho\_b-\/drho\_c)}
\DoxyCodeLine{1718     ta = evaluation\_polynomial( ppoly\_t, nterm, a )}
\DoxyCodeLine{1719     sa = evaluation\_polynomial( ppoly\_s, nterm, a )}
\DoxyCodeLine{1720     pa = p\_top*(1.-\/a) + p\_bot*a}
\DoxyCodeLine{1721     \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, ta, sa, pa, t\_ref, s\_ref, p\_ref, drho\_a)}
\DoxyCodeLine{1722     \textcolor{keywordflow}{if} (abs(drho\_a) < cs\%drho\_tol) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1723       z = a}
\DoxyCodeLine{1724       \textcolor{keywordflow}{return}}
\DoxyCodeLine{1725 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1726 }
\DoxyCodeLine{1727     \textcolor{keywordflow}{if} (drho\_a*drho\_c > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1728       \textcolor{keywordflow}{if} ( abs(a-\/c)<cs\%x\_tol) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1729         z = a}
\DoxyCodeLine{1730         \textcolor{keywordflow}{return}}
\DoxyCodeLine{1731 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1732       c = a ; drho\_c = drho\_a;}
\DoxyCodeLine{1733       \textcolor{keywordflow}{if} (side == -\/1) drho\_b = 0.5*drho\_b}
\DoxyCodeLine{1734       side = -\/1}
\DoxyCodeLine{1735     \textcolor{keywordflow}{elseif} ( drho\_b*drho\_a > 0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1736       \textcolor{keywordflow}{if} ( abs(a-\/b)<cs\%x\_tol) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1737         z = a}
\DoxyCodeLine{1738         \textcolor{keywordflow}{return}}
\DoxyCodeLine{1739 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1740       b = a ; drho\_b = drho\_a}
\DoxyCodeLine{1741       \textcolor{keywordflow}{if} (side == 1) drho\_c = 0.5*drho\_c}
\DoxyCodeLine{1742       side = 1}
\DoxyCodeLine{1743     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1744       z = a}
\DoxyCodeLine{1745       \textcolor{keywordflow}{return}}
\DoxyCodeLine{1746 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1747 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1748 }
\DoxyCodeLine{1749   z = a}
\DoxyCodeLine{1750 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a464e946951f3bbf7e2df500831c7afd4}\label{namespacemom__neutral__diffusion_a464e946951f3bbf7e2df500831c7afd4}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!find\_neutral\_pos\_linear@{find\_neutral\_pos\_linear}}
\index{find\_neutral\_pos\_linear@{find\_neutral\_pos\_linear}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{find\_neutral\_pos\_linear()}{find\_neutral\_pos\_linear()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::find\+\_\+neutral\+\_\+pos\+\_\+linear (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), intent(in)}]{CS,  }\item[{real, intent(in)}]{z0,  }\item[{real, intent(in)}]{T\+\_\+ref,  }\item[{real, intent(in)}]{S\+\_\+ref,  }\item[{real, intent(in)}]{d\+Rd\+T\+\_\+ref,  }\item[{real, intent(in)}]{d\+Rd\+S\+\_\+ref,  }\item[{real, intent(in)}]{d\+Rd\+T\+\_\+top,  }\item[{real, intent(in)}]{d\+Rd\+S\+\_\+top,  }\item[{real, intent(in)}]{d\+Rd\+T\+\_\+bot,  }\item[{real, intent(in)}]{d\+Rd\+S\+\_\+bot,  }\item[{real, dimension(\+:), intent(in)}]{ppoly\+\_\+T,  }\item[{real, dimension(\+:), intent(in)}]{ppoly\+\_\+S }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Search a layer to find where delta\+\_\+rho = 0 based on a linear interpolation of alpha and beta of the top and bottom being searched and polynomial reconstructions of T and S. Compressibility is not needed because either, we are assuming incompressibility in the equation of state for this module or alpha and beta are calculated having been displaced to the average pressures of the two pressures We need Newton\textquotesingle{}s method because the T and S reconstructions make delta\+\_\+rho a polynomial function of z if using P\+PM or higher. If Newton\textquotesingle{}s method would search fall out of the interval \mbox{[}0,1\mbox{]}, a bisection step would be taken instead. Also this linearization of alpha, beta means that second derivatives of the E\+OS are not needed. Note that delta in variable names below refers to horizontal differences and \textquotesingle{}d\textquotesingle{} refers to vertical differences. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Control structure with parameters for this module \\
\hline
\mbox{\texttt{ in}}  & {\em z0} & Lower bound of position, also serves as the initial guess \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+ref} & Temperature at the searched from interface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+ref} & Salinity at the searched from interface \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdt\+\_\+ref} & d\+Rho/dT at the searched from interface \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drds\+\_\+ref} & d\+Rho/dS at the searched from interface \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdt\+\_\+top} & d\+Rho/dT at top of layer being searched \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drds\+\_\+top} & d\+Rho/dS at top of layer being searched \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdt\+\_\+bot} & d\+Rho/dT at bottom of layer being searched \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drds\+\_\+bot} & d\+Rho/dS at bottom of layer being searched \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+t} & Coefficients of the polynomial reconstruction of T within the layer to be searched \mbox{[}degC\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+s} & Coefficients of the polynomial reconstruction of S within the layer to be searched \mbox{[}ppt\mbox{]}. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Position where drho = 0 \mbox{[}nondim\mbox{]} 
\end{DoxyReturn}


Definition at line 1540 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1542   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS),\textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{        !< Control structure with parameters for this module}}
\DoxyCodeLine{1543 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: z0\textcolor{comment}{        !< Lower bound of position, also serves as the}}
\DoxyCodeLine{1544 \textcolor{comment}{                                                     !! initial guess [nondim]}}
\DoxyCodeLine{1545 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: T\_ref\textcolor{comment}{     !< Temperature at the searched from interface [degC]}}
\DoxyCodeLine{1546 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: S\_ref\textcolor{comment}{     !< Salinity at the searched from interface [ppt]}}
\DoxyCodeLine{1547 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: dRdT\_ref\textcolor{comment}{  !< dRho/dT at the searched from interface}}
\DoxyCodeLine{1548 \textcolor{comment}{                                                     !! [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1549 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: dRdS\_ref\textcolor{comment}{  !< dRho/dS at the searched from interface}}
\DoxyCodeLine{1550 \textcolor{comment}{                                                     !! [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1551 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: dRdT\_top\textcolor{comment}{  !< dRho/dT at top of layer being searched}}
\DoxyCodeLine{1552 \textcolor{comment}{                                                     !! [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1553 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: dRdS\_top\textcolor{comment}{  !< dRho/dS at top of layer being searched}}
\DoxyCodeLine{1554 \textcolor{comment}{                                                     !! [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1555 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: dRdT\_bot\textcolor{comment}{  !< dRho/dT at bottom of layer being searched}}
\DoxyCodeLine{1556 \textcolor{comment}{                                                     !! [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1557 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: dRdS\_bot\textcolor{comment}{  !< dRho/dS at bottom of layer being searched}}
\DoxyCodeLine{1558 \textcolor{comment}{                                                     !! [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1559 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},        \textcolor{keywordtype}{intent(in)} :: ppoly\_T\textcolor{comment}{   !< Coefficients of the polynomial reconstruction of T within}}
\DoxyCodeLine{1560 \textcolor{comment}{                                                     !! the layer to be searched [degC].}}
\DoxyCodeLine{1561 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},        \textcolor{keywordtype}{intent(in)} :: ppoly\_S\textcolor{comment}{   !< Coefficients of the polynomial reconstruction of S within}}
\DoxyCodeLine{1562 \textcolor{comment}{                                                     !! the layer to be searched [ppt].}}
\DoxyCodeLine{1563 \textcolor{keywordtype}{  real}                                  :: z\textcolor{comment}{         !< Position where drho = 0 [nondim]}}
\DoxyCodeLine{1564   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1565 \textcolor{keywordtype}{  real} :: dRdT\_diff  \textcolor{comment}{! Difference in the partial derivative of density with temperature across the}}
\DoxyCodeLine{1566                      \textcolor{comment}{! layer [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1567 \textcolor{keywordtype}{  real} :: dRdS\_diff  \textcolor{comment}{! Difference in the partial derivative of density with salinity across the}}
\DoxyCodeLine{1568                      \textcolor{comment}{! layer [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1569 \textcolor{keywordtype}{  real} :: drho, drho\_dz \textcolor{comment}{! Density anomaly and its derivative with fracitonal position [R \string~> kg m-\/3]}}
\DoxyCodeLine{1570 \textcolor{keywordtype}{  real} :: dRdT\_z     \textcolor{comment}{! Partial derivative of density with temperature at a point [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1571 \textcolor{keywordtype}{  real} :: dRdS\_z     \textcolor{comment}{! Partial derivative of density with salinity at a point [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1572 \textcolor{keywordtype}{  real} :: T\_z, dT\_dz \textcolor{comment}{! Temperature at a point and its derivative with fractional position [degC]}}
\DoxyCodeLine{1573 \textcolor{keywordtype}{  real} :: S\_z, dS\_dz \textcolor{comment}{! Salinity at a point and its derivative with fractional position [ppt]}}
\DoxyCodeLine{1574 \textcolor{keywordtype}{  real} :: drho\_min, drho\_max \textcolor{comment}{! Bounds on density differences [R \string~> kg m-\/3]}}
\DoxyCodeLine{1575 \textcolor{keywordtype}{  real} :: ztest, zmin, zmax \textcolor{comment}{! Fractional positions in the cell [nondim]}}
\DoxyCodeLine{1576 \textcolor{keywordtype}{  real} :: dz         \textcolor{comment}{! Change in position in the cell [nondim]}}
\DoxyCodeLine{1577 \textcolor{keywordtype}{  real} :: a1, a2     \textcolor{comment}{! Fractional weights of the top and bottom values [nondim]}}
\DoxyCodeLine{1578   \textcolor{keywordtype}{integer} :: iter}
\DoxyCodeLine{1579   \textcolor{keywordtype}{integer} :: nterm}
\DoxyCodeLine{1580 }
\DoxyCodeLine{1581   nterm = \textcolor{keyword}{SIZE}(ppoly\_t)}
\DoxyCodeLine{1582 }
\DoxyCodeLine{1583   \textcolor{comment}{! Position independent quantities}}
\DoxyCodeLine{1584   drdt\_diff = drdt\_bot -\/ drdt\_top}
\DoxyCodeLine{1585   drds\_diff = drds\_bot -\/ drds\_top}
\DoxyCodeLine{1586   \textcolor{comment}{! Initial starting drho (used for bisection)}}
\DoxyCodeLine{1587   zmin = z0        \textcolor{comment}{! Lower bounding interval}}
\DoxyCodeLine{1588   zmax = 1.        \textcolor{comment}{! Maximum bounding interval (bottom of layer)}}
\DoxyCodeLine{1589   a1 = 1. -\/ zmin}
\DoxyCodeLine{1590   a2 = zmin}
\DoxyCodeLine{1591   t\_z = evaluation\_polynomial( ppoly\_t, nterm, zmin )}
\DoxyCodeLine{1592   s\_z = evaluation\_polynomial( ppoly\_s, nterm, zmin )}
\DoxyCodeLine{1593   drdt\_z = a1*drdt\_top + a2*drdt\_bot}
\DoxyCodeLine{1594   drds\_z = a1*drds\_top + a2*drds\_bot}
\DoxyCodeLine{1595   drho\_min = 0.5*((drdt\_z+drdt\_ref)*(t\_z-\/t\_ref) + (drds\_z+drds\_ref)*(s\_z-\/s\_ref))}
\DoxyCodeLine{1596 }
\DoxyCodeLine{1597   t\_z = evaluation\_polynomial( ppoly\_t, nterm, 1. )}
\DoxyCodeLine{1598   s\_z = evaluation\_polynomial( ppoly\_s, nterm, 1. )}
\DoxyCodeLine{1599   drho\_max = 0.5*((drdt\_bot+drdt\_ref)*(t\_z-\/t\_ref) + (drds\_bot+drds\_ref)*(s\_z-\/s\_ref))}
\DoxyCodeLine{1600 }
\DoxyCodeLine{1601   \textcolor{keywordflow}{if} (drho\_min >= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1602     z = z0}
\DoxyCodeLine{1603     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1604   \textcolor{keywordflow}{elseif} (drho\_max == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1605     z = 1.}
\DoxyCodeLine{1606     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1607 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1608   \textcolor{keywordflow}{if} ( sign(1.,drho\_min) == sign(1.,drho\_max) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1609     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}drho\_min is the same sign as dhro\_max"{}})}
\DoxyCodeLine{1610 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1611 }
\DoxyCodeLine{1612   z = z0}
\DoxyCodeLine{1613   ztest = z0}
\DoxyCodeLine{1614   \textcolor{keywordflow}{do} iter = 1, cs\%max\_iter}
\DoxyCodeLine{1615     \textcolor{comment}{! Calculate quantities at the current nondimensional position}}
\DoxyCodeLine{1616     a1 = 1.-\/z}
\DoxyCodeLine{1617     a2 = z}
\DoxyCodeLine{1618     drdt\_z    = a1*drdt\_top + a2*drdt\_bot}
\DoxyCodeLine{1619     drds\_z    = a1*drds\_top + a2*drds\_bot}
\DoxyCodeLine{1620     t\_z       = evaluation\_polynomial( ppoly\_t, nterm, z )}
\DoxyCodeLine{1621     s\_z       = evaluation\_polynomial( ppoly\_s, nterm, z )}
\DoxyCodeLine{1622     drho = 0.5*((drdt\_z+drdt\_ref)*(t\_z-\/t\_ref) + (drds\_z+drds\_ref)*(s\_z-\/s\_ref))}
\DoxyCodeLine{1623 }
\DoxyCodeLine{1624     \textcolor{comment}{! Check for convergence}}
\DoxyCodeLine{1625     \textcolor{keywordflow}{if} (abs(drho) <= cs\%drho\_tol) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1626     \textcolor{comment}{! Update bisection bracketing intervals}}
\DoxyCodeLine{1627     \textcolor{keywordflow}{if} (drho < 0. .and. drho > drho\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1628       drho\_min = drho}
\DoxyCodeLine{1629       zmin = z}
\DoxyCodeLine{1630     \textcolor{keywordflow}{elseif} (drho > 0. .and. drho < drho\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1631       drho\_max = drho}
\DoxyCodeLine{1632       zmax = z}
\DoxyCodeLine{1633 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1634 }
\DoxyCodeLine{1635     \textcolor{comment}{! Calculate a Newton step}}
\DoxyCodeLine{1636     dt\_dz = first\_derivative\_polynomial( ppoly\_t, nterm, z )}
\DoxyCodeLine{1637     ds\_dz = first\_derivative\_polynomial( ppoly\_s, nterm, z )}
\DoxyCodeLine{1638     drho\_dz = 0.5*( (drdt\_diff*(t\_z -\/ t\_ref) + (drdt\_ref+drdt\_z)*dt\_dz) + \&}
\DoxyCodeLine{1639                     (drds\_diff*(s\_z -\/ s\_ref) + (drds\_ref+drds\_z)*ds\_dz) )}
\DoxyCodeLine{1640 }
\DoxyCodeLine{1641     ztest = z -\/ drho/drho\_dz}
\DoxyCodeLine{1642     \textcolor{comment}{! Take a bisection if z falls out of [zmin,zmax]}}
\DoxyCodeLine{1643     \textcolor{keywordflow}{if} (ztest < zmin .or. ztest > zmax) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1644       \textcolor{keywordflow}{if} ( drho < 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1645         ztest = 0.5*(z + zmax)}
\DoxyCodeLine{1646       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1647         ztest = 0.5*(zmin + z)}
\DoxyCodeLine{1648 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1649 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1650 }
\DoxyCodeLine{1651     \textcolor{comment}{! Test to ensure we haven't stalled out}}
\DoxyCodeLine{1652     \textcolor{keywordflow}{if} ( abs(z-\/ztest) <= cs\%x\_tol ) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1653     \textcolor{comment}{! Reset for next iteration}}
\DoxyCodeLine{1654     z = ztest}
\DoxyCodeLine{1655 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1656 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_acb07c024cb6aa162a8789a4f50139aa5}\label{namespacemom__neutral__diffusion_acb07c024cb6aa162a8789a4f50139aa5}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!find\_neutral\_surface\_positions\_continuous@{find\_neutral\_surface\_positions\_continuous}}
\index{find\_neutral\_surface\_positions\_continuous@{find\_neutral\_surface\_positions\_continuous}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{find\_neutral\_surface\_positions\_continuous()}{find\_neutral\_surface\_positions\_continuous()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::find\+\_\+neutral\+\_\+surface\+\_\+positions\+\_\+continuous (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk+1), intent(in)}]{Pl,  }\item[{real, dimension(nk+1), intent(in)}]{Tl,  }\item[{real, dimension(nk+1), intent(in)}]{Sl,  }\item[{real, dimension(nk+1), intent(in)}]{d\+Rd\+Tl,  }\item[{real, dimension(nk+1), intent(in)}]{d\+Rd\+Sl,  }\item[{real, dimension(nk+1), intent(in)}]{Pr,  }\item[{real, dimension(nk+1), intent(in)}]{Tr,  }\item[{real, dimension(nk+1), intent(in)}]{Sr,  }\item[{real, dimension(nk+1), intent(in)}]{d\+Rd\+Tr,  }\item[{real, dimension(nk+1), intent(in)}]{d\+Rd\+Sr,  }\item[{real, dimension(2$\ast$nk+2), intent(inout)}]{PoL,  }\item[{real, dimension(2$\ast$nk+2), intent(inout)}]{PoR,  }\item[{integer, dimension(2$\ast$nk+2), intent(inout)}]{KoL,  }\item[{integer, dimension(2$\ast$nk+2), intent(inout)}]{KoR,  }\item[{real, dimension(2$\ast$nk+1), intent(inout)}]{h\+Eff,  }\item[{integer, intent(in), optional}]{bl\+\_\+kl,  }\item[{integer, intent(in), optional}]{bl\+\_\+kr,  }\item[{real, intent(in), optional}]{bl\+\_\+zl,  }\item[{real, intent(in), optional}]{bl\+\_\+zr }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns positions within left/right columns of combined interfaces using continuous reconstructions of T/S. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em pl} & Left-\/column interface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em tl} & Left-\/column interface potential temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em sl} & Left-\/column interface salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdtl} & Left-\/column d\+Rho/dT \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdsl} & Left-\/column d\+Rho/dS \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pr} & Right-\/column interface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em tr} & Right-\/column interface potential temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em sr} & Right-\/column interface salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdtr} & Left-\/column d\+Rho/dT \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drdsr} & Left-\/column d\+Rho/dS \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em pol} & Fractional position of neutral surface within layer KoL of left column \\
\hline
\mbox{\texttt{ in,out}}  & {\em por} & Fractional position of neutral surface within layer KoR of right column \\
\hline
\mbox{\texttt{ in,out}}  & {\em kol} & Index of first left interface above neutral surface \\
\hline
\mbox{\texttt{ in,out}}  & {\em kor} & Index of first right interface above neutral surface \\
\hline
\mbox{\texttt{ in,out}}  & {\em heff} & Effective thickness between two neutral surfaces \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or other units following Pl and Pr. \\
\hline
\mbox{\texttt{ in}}  & {\em bl\+\_\+kl} & Layer index of the boundary layer (left) \\
\hline
\mbox{\texttt{ in}}  & {\em bl\+\_\+kr} & Layer index of the boundary layer (right) \\
\hline
\mbox{\texttt{ in}}  & {\em bl\+\_\+zl} & Nondimensional position of the boundary layer (left) \\
\hline
\mbox{\texttt{ in}}  & {\em bl\+\_\+zr} & Nondimensional position of the boundary layer (right) \\
\hline
\end{DoxyParams}


Definition at line 931 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{933   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{    !< Number of levels}}
\DoxyCodeLine{934 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Pl\textcolor{comment}{    !< Left-\/column interface pressure [R L2 T-\/2 \string~> Pa] or other units}}
\DoxyCodeLine{935 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Tl\textcolor{comment}{    !< Left-\/column interface potential temperature [degC]}}
\DoxyCodeLine{936 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Sl\textcolor{comment}{    !< Left-\/column interface salinity [ppt]}}
\DoxyCodeLine{937 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: dRdTl\textcolor{comment}{ !< Left-\/column dRho/dT [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{938 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: dRdSl\textcolor{comment}{ !< Left-\/column dRho/dS [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{939 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Pr\textcolor{comment}{    !< Right-\/column interface pressure [R L2 T-\/2 \string~> Pa] or other units}}
\DoxyCodeLine{940 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Tr\textcolor{comment}{    !< Right-\/column interface potential temperature [degC]}}
\DoxyCodeLine{941 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Sr\textcolor{comment}{    !< Right-\/column interface salinity [ppt]}}
\DoxyCodeLine{942 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: dRdTr\textcolor{comment}{ !< Left-\/column dRho/dT [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{943 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: dRdSr\textcolor{comment}{ !< Left-\/column dRho/dS [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{944 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*nk+2)},    \textcolor{keywordtype}{intent(inout)} :: PoL\textcolor{comment}{   !< Fractional position of neutral surface within}}
\DoxyCodeLine{945 \textcolor{comment}{                                                     !! layer KoL of left column}}
\DoxyCodeLine{946 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*nk+2)},    \textcolor{keywordtype}{intent(inout)} :: PoR\textcolor{comment}{   !< Fractional position of neutral surface within}}
\DoxyCodeLine{947 \textcolor{comment}{                                                     !! layer KoR of right column}}
\DoxyCodeLine{948   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2*nk+2)}, \textcolor{keywordtype}{intent(inout)} :: KoL\textcolor{comment}{   !< Index of first left interface above neutral surface}}
\DoxyCodeLine{949   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2*nk+2)}, \textcolor{keywordtype}{intent(inout)} :: KoR\textcolor{comment}{   !< Index of first right interface above neutral surface}}
\DoxyCodeLine{950 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*nk+1)},    \textcolor{keywordtype}{intent(inout)} :: hEff\textcolor{comment}{  !< Effective thickness between two neutral surfaces}}
\DoxyCodeLine{951 \textcolor{comment}{                                                     !! [R L2 T-\/2 \string~> Pa] or other units following Pl and Pr.}}
\DoxyCodeLine{952   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: bl\_kl\textcolor{comment}{ !< Layer index of the boundary layer (left)}}
\DoxyCodeLine{953   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: bl\_kr\textcolor{comment}{ !< Layer index of the boundary layer (right)}}
\DoxyCodeLine{954 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},             \textcolor{keywordtype}{intent(in)}    :: bl\_zl\textcolor{comment}{ !< Nondimensional position of the boundary layer (left)}}
\DoxyCodeLine{955 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},             \textcolor{keywordtype}{intent(in)}    :: bl\_zr\textcolor{comment}{ !< Nondimensional position of the boundary layer (right)}}
\DoxyCodeLine{956 }
\DoxyCodeLine{957   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{958   \textcolor{keywordtype}{integer} :: ns                     \textcolor{comment}{! Number of neutral surfaces}}
\DoxyCodeLine{959   \textcolor{keywordtype}{integer} :: k\_surface              \textcolor{comment}{! Index of neutral surface}}
\DoxyCodeLine{960   \textcolor{keywordtype}{integer} :: kl                     \textcolor{comment}{! Index of left interface}}
\DoxyCodeLine{961   \textcolor{keywordtype}{integer} :: kr                     \textcolor{comment}{! Index of right interface}}
\DoxyCodeLine{962 \textcolor{keywordtype}{  real}    :: dRdT, dRdS             \textcolor{comment}{! dRho/dT [kg m-\/3 degC-\/1] and dRho/dS [kg m-\/3 ppt-\/1] for the neutral surface}}
\DoxyCodeLine{963   \textcolor{keywordtype}{logical} :: searching\_left\_column  \textcolor{comment}{! True if searching for the position of a right interface in the left column}}
\DoxyCodeLine{964   \textcolor{keywordtype}{logical} :: searching\_right\_column \textcolor{comment}{! True if searching for the position of a left interface in the right column}}
\DoxyCodeLine{965   \textcolor{keywordtype}{logical} :: reached\_bottom         \textcolor{comment}{! True if one of the bottom-\/most interfaces has been used as the target}}
\DoxyCodeLine{966   \textcolor{keywordtype}{integer} :: krm1, klm1}
\DoxyCodeLine{967 \textcolor{keywordtype}{  real}    :: dRho, dRhoTop, dRhoBot \textcolor{comment}{! Potential density differences at various points [R \string~> kg m-\/3]}}
\DoxyCodeLine{968 \textcolor{keywordtype}{  real}    :: hL, hR                 \textcolor{comment}{! Pressure thicknesses [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{969   \textcolor{keywordtype}{integer} :: lastK\_left, lastK\_right \textcolor{comment}{! Layers used during the last iteration}}
\DoxyCodeLine{970 \textcolor{keywordtype}{  real}    :: lastP\_left, lastP\_right \textcolor{comment}{! Fractional positions during the last iteration [nondim]}}
\DoxyCodeLine{971   \textcolor{keywordtype}{logical} :: interior\_limit}
\DoxyCodeLine{972 }
\DoxyCodeLine{973   ns = 2*nk+2}
\DoxyCodeLine{974 }
\DoxyCodeLine{975   \textcolor{comment}{! Initialize variables for the search}}
\DoxyCodeLine{976   kr = 1 ;}
\DoxyCodeLine{977   kl = 1 ;}
\DoxyCodeLine{978   lastp\_right = 0.}
\DoxyCodeLine{979   lastp\_left = 0.}
\DoxyCodeLine{980   lastk\_right = 1}
\DoxyCodeLine{981   lastk\_left  = 1}
\DoxyCodeLine{982   reached\_bottom = .false.}
\DoxyCodeLine{983 }
\DoxyCodeLine{984   \textcolor{comment}{! Check to see if we should limit the diffusion to the interior}}
\DoxyCodeLine{985   interior\_limit = \textcolor{keyword}{PRESENT}(bl\_kl) .and. \textcolor{keyword}{PRESENT}(bl\_kr) .and. \textcolor{keyword}{PRESENT}(bl\_zr) .and. \textcolor{keyword}{PRESENT}(bl\_zl)}
\DoxyCodeLine{986 }
\DoxyCodeLine{987   \textcolor{comment}{! Loop over each neutral surface, working from top to bottom}}
\DoxyCodeLine{988   neutral\_surfaces: \textcolor{keywordflow}{do} k\_surface = 1, ns}
\DoxyCodeLine{989     klm1 = max(kl-\/1, 1)}
\DoxyCodeLine{990     \textcolor{keywordflow}{if} (klm1>nk) stop \textcolor{stringliteral}{'find\_neutral\_surface\_positions(): klm1 went out of bounds!'}}
\DoxyCodeLine{991     krm1 = max(kr-\/1, 1)}
\DoxyCodeLine{992     \textcolor{keywordflow}{if} (krm1>nk) stop \textcolor{stringliteral}{'find\_neutral\_surface\_positions(): krm1 went out of bounds!'}}
\DoxyCodeLine{993 }
\DoxyCodeLine{994     \textcolor{comment}{! Potential density difference, rho(kr) -\/ rho(kl)}}
\DoxyCodeLine{995     drho = 0.5 * ( ( drdtr(kr) + drdtl(kl) ) * ( tr(kr) -\/ tl(kl) ) \&}
\DoxyCodeLine{996                  + ( drdsr(kr) + drdsl(kl) ) * ( sr(kr) -\/ sl(kl) ) )}
\DoxyCodeLine{997     \textcolor{comment}{! Which column has the lighter surface for the current indexes, kr and kl}}
\DoxyCodeLine{998     \textcolor{keywordflow}{if} (.not. reached\_bottom) \textcolor{keywordflow}{then}}
\DoxyCodeLine{999       \textcolor{keywordflow}{if} (drho < 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1000         searching\_left\_column = .true.}
\DoxyCodeLine{1001         searching\_right\_column = .false.}
\DoxyCodeLine{1002       \textcolor{keywordflow}{elseif} (drho > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1003         searching\_right\_column = .true.}
\DoxyCodeLine{1004         searching\_left\_column = .false.}
\DoxyCodeLine{1005       \textcolor{keywordflow}{else} \textcolor{comment}{! dRho == 0.}}
\DoxyCodeLine{1006         \textcolor{keywordflow}{if} (kl + kr == 2) \textcolor{keywordflow}{then} \textcolor{comment}{! Still at surface}}
\DoxyCodeLine{1007           searching\_left\_column = .true.}
\DoxyCodeLine{1008           searching\_right\_column = .false.}
\DoxyCodeLine{1009         \textcolor{keywordflow}{else} \textcolor{comment}{! Not the surface so we simply change direction}}
\DoxyCodeLine{1010           searching\_left\_column = .not.  searching\_left\_column}
\DoxyCodeLine{1011           searching\_right\_column = .not.  searching\_right\_column}
\DoxyCodeLine{1012 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1013 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1014 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1015 }
\DoxyCodeLine{1016     \textcolor{keywordflow}{if} (searching\_left\_column) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1017       \textcolor{comment}{! Interpolate for the neutral surface position within the left column, layer klm1}}
\DoxyCodeLine{1018       \textcolor{comment}{! Potential density difference, rho(kl-\/1) -\/ rho(kr) (should be negative)}}
\DoxyCodeLine{1019       drhotop = 0.5 * ( ( drdtl(klm1) + drdtr(kr) ) * ( tl(klm1) -\/ tr(kr) ) \&}
\DoxyCodeLine{1020                      + ( drdsl(klm1) + drdsr(kr) ) * ( sl(klm1) -\/ sr(kr) ) )}
\DoxyCodeLine{1021       \textcolor{comment}{! Potential density difference, rho(kl) -\/ rho(kr) (will be positive)}}
\DoxyCodeLine{1022       drhobot = 0.5 * ( ( drdtl(klm1+1) + drdtr(kr) ) * ( tl(klm1+1) -\/ tr(kr) ) \&}
\DoxyCodeLine{1023                       + ( drdsl(klm1+1) + drdsr(kr) ) * ( sl(klm1+1) -\/ sr(kr) ) )}
\DoxyCodeLine{1024 }
\DoxyCodeLine{1025       \textcolor{comment}{! Because we are looking left, the right surface, kr, is lighter than klm1+1 and should be denser than klm1}}
\DoxyCodeLine{1026       \textcolor{comment}{! unless we are still at the top of the left column (kl=1)}}
\DoxyCodeLine{1027       \textcolor{keywordflow}{if} (drhotop > 0. .or. kr+kl==2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1028         pol(k\_surface) = 0. \textcolor{comment}{! The right surface is lighter than anything in layer klm1}}
\DoxyCodeLine{1029       \textcolor{keywordflow}{elseif} (drhotop >= drhobot) \textcolor{keywordflow}{then} \textcolor{comment}{! Left layer is unstratified}}
\DoxyCodeLine{1030         pol(k\_surface) = 1.}
\DoxyCodeLine{1031       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1032         \textcolor{comment}{! Linearly interpolate for the position between Pl(kl-\/1) and Pl(kl) where the density difference}}
\DoxyCodeLine{1033         \textcolor{comment}{! between right and left is zero. The Pl here are only used to handle massless layers.}}
\DoxyCodeLine{1034         pol(k\_surface) = interpolate\_for\_nondim\_position( drhotop, pl(klm1), drhobot, pl(klm1+1) )}
\DoxyCodeLine{1035 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1036       \textcolor{keywordflow}{if} (pol(k\_surface)>=1. .and. klm1<nk) \textcolor{keywordflow}{then} \textcolor{comment}{! >= is really ==, when PoL==1 we point to the bottom of the cell}}
\DoxyCodeLine{1037         klm1 = klm1 + 1}
\DoxyCodeLine{1038         pol(k\_surface) = pol(k\_surface) -\/ 1.}
\DoxyCodeLine{1039 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1040       \textcolor{keywordflow}{if} (real(klm1-\/lastk\_left)+(pol(k\_surface)-\/lastp\_left)<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1041         pol(k\_surface) = lastp\_left}
\DoxyCodeLine{1042         klm1 = lastk\_left}
\DoxyCodeLine{1043 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1044       kol(k\_surface) = klm1}
\DoxyCodeLine{1045       \textcolor{keywordflow}{if} (kr <= nk) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1046         por(k\_surface) = 0.}
\DoxyCodeLine{1047         kor(k\_surface) = kr}
\DoxyCodeLine{1048       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1049         por(k\_surface) = 1.}
\DoxyCodeLine{1050         kor(k\_surface) = nk}
\DoxyCodeLine{1051 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1052       \textcolor{keywordflow}{if} (kr <= nk) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1053         kr = kr + 1}
\DoxyCodeLine{1054       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1055         reached\_bottom = .true.}
\DoxyCodeLine{1056         searching\_right\_column = .true.}
\DoxyCodeLine{1057         searching\_left\_column = .false.}
\DoxyCodeLine{1058 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1059     \textcolor{keywordflow}{elseif} (searching\_right\_column) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1060       \textcolor{comment}{! Interpolate for the neutral surface position within the right column, layer krm1}}
\DoxyCodeLine{1061       \textcolor{comment}{! Potential density difference, rho(kr-\/1) -\/ rho(kl) (should be negative)}}
\DoxyCodeLine{1062       drhotop = 0.5 * ( ( drdtr(krm1) + drdtl(kl) ) * ( tr(krm1) -\/ tl(kl) ) + \&}
\DoxyCodeLine{1063                         ( drdsr(krm1) + drdsl(kl) ) * ( sr(krm1) -\/ sl(kl) ) )}
\DoxyCodeLine{1064       \textcolor{comment}{! Potential density difference, rho(kr) -\/ rho(kl) (will be positive)}}
\DoxyCodeLine{1065       drhobot = 0.5 * ( ( drdtr(krm1+1) + drdtl(kl) ) * ( tr(krm1+1) -\/ tl(kl) ) + \&}
\DoxyCodeLine{1066                         ( drdsr(krm1+1) + drdsl(kl) ) * ( sr(krm1+1) -\/ sl(kl) ) )}
\DoxyCodeLine{1067 }
\DoxyCodeLine{1068       \textcolor{comment}{! Because we are looking right, the left surface, kl, is lighter than krm1+1 and should be denser than krm1}}
\DoxyCodeLine{1069       \textcolor{comment}{! unless we are still at the top of the right column (kr=1)}}
\DoxyCodeLine{1070       \textcolor{keywordflow}{if} (drhotop >= 0. .or. kr+kl==2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1071         por(k\_surface) = 0. \textcolor{comment}{! The left surface is lighter than anything in layer krm1}}
\DoxyCodeLine{1072       \textcolor{keywordflow}{elseif} (drhotop >= drhobot) \textcolor{keywordflow}{then} \textcolor{comment}{! Right layer is unstratified}}
\DoxyCodeLine{1073         por(k\_surface) = 1.}
\DoxyCodeLine{1074       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1075         \textcolor{comment}{! Linearly interpolate for the position between Pr(kr-\/1) and Pr(kr) where the density difference}}
\DoxyCodeLine{1076         \textcolor{comment}{! between right and left is zero. The Pr here are only used to handle massless layers.}}
\DoxyCodeLine{1077         por(k\_surface) = interpolate\_for\_nondim\_position( drhotop, pr(krm1), drhobot, pr(krm1+1) )}
\DoxyCodeLine{1078 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1079       \textcolor{keywordflow}{if} (por(k\_surface)>=1. .and. krm1<nk) \textcolor{keywordflow}{then} \textcolor{comment}{! >= is really ==, when PoR==1 we point to the bottom of the cell}}
\DoxyCodeLine{1080         krm1 = krm1 + 1}
\DoxyCodeLine{1081         por(k\_surface) = por(k\_surface) -\/ 1.}
\DoxyCodeLine{1082 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1083       \textcolor{keywordflow}{if} (real(krm1-\/lastk\_right)+(por(k\_surface)-\/lastp\_right)<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1084         por(k\_surface) = lastp\_right}
\DoxyCodeLine{1085         krm1 = lastk\_right}
\DoxyCodeLine{1086 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1087       kor(k\_surface) = krm1}
\DoxyCodeLine{1088       \textcolor{keywordflow}{if} (kl <= nk) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1089         pol(k\_surface) = 0.}
\DoxyCodeLine{1090         kol(k\_surface) = kl}
\DoxyCodeLine{1091       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1092         pol(k\_surface) = 1.}
\DoxyCodeLine{1093         kol(k\_surface) = nk}
\DoxyCodeLine{1094 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1095       \textcolor{keywordflow}{if} (kl <= nk) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1096         kl = kl + 1}
\DoxyCodeLine{1097       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1098         reached\_bottom = .true.}
\DoxyCodeLine{1099         searching\_right\_column = .false.}
\DoxyCodeLine{1100         searching\_left\_column = .true.}
\DoxyCodeLine{1101 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1102     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1103       stop \textcolor{stringliteral}{'Else what?'}}
\DoxyCodeLine{1104 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1105     \textcolor{keywordflow}{if} (interior\_limit) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1106       \textcolor{keywordflow}{if} (kol(k\_surface)<=bl\_kl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1107         kol(k\_surface) = bl\_kl}
\DoxyCodeLine{1108         \textcolor{keywordflow}{if} (pol(k\_surface)<bl\_zl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1109           pol(k\_surface) = bl\_zl}
\DoxyCodeLine{1110 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1111 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1112       \textcolor{keywordflow}{if} (kor(k\_surface)<=bl\_kr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1113         kor(k\_surface) = bl\_kr}
\DoxyCodeLine{1114         \textcolor{keywordflow}{if} (por(k\_surface)<bl\_zr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1115           por(k\_surface) = bl\_zr}
\DoxyCodeLine{1116 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1117 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1118 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1119 }
\DoxyCodeLine{1120     lastk\_left = kol(k\_surface) ; lastp\_left = pol(k\_surface)}
\DoxyCodeLine{1121     lastk\_right = kor(k\_surface) ; lastp\_right = por(k\_surface)}
\DoxyCodeLine{1122     \textcolor{comment}{! Effective thickness}}
\DoxyCodeLine{1123     \textcolor{comment}{! NOTE: This would be better expressed in terms of the layers thicknesses rather}}
\DoxyCodeLine{1124     \textcolor{comment}{! than as differences of position -\/ AJA}}
\DoxyCodeLine{1125     \textcolor{keywordflow}{if} (k\_surface>1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1126       hl = absolute\_position(nk,ns,pl,kol,pol,k\_surface) -\/ absolute\_position(nk,ns,pl,kol,pol,k\_surface-\/1)}
\DoxyCodeLine{1127       hr = absolute\_position(nk,ns,pr,kor,por,k\_surface) -\/ absolute\_position(nk,ns,pr,kor,por,k\_surface-\/1)}
\DoxyCodeLine{1128       \textcolor{keywordflow}{if} ( hl + hr > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1129         heff(k\_surface-\/1) = 2. * hl * hr / ( hl + hr ) \textcolor{comment}{! Harmonic mean of layer thicknesses}}
\DoxyCodeLine{1130       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1131         heff(k\_surface-\/1) = 0.}
\DoxyCodeLine{1132 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1133 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1134 }
\DoxyCodeLine{1135 \textcolor{keywordflow}{  enddo} neutral\_surfaces}
\DoxyCodeLine{1136 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a72eca09bc6cc25f8a3831ad8e2be91d4}\label{namespacemom__neutral__diffusion_a72eca09bc6cc25f8a3831ad8e2be91d4}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!find\_neutral\_surface\_positions\_discontinuous@{find\_neutral\_surface\_positions\_discontinuous}}
\index{find\_neutral\_surface\_positions\_discontinuous@{find\_neutral\_surface\_positions\_discontinuous}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{find\_neutral\_surface\_positions\_discontinuous()}{find\_neutral\_surface\_positions\_discontinuous()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::find\+\_\+neutral\+\_\+surface\+\_\+positions\+\_\+discontinuous (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), intent(inout)}]{CS,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk,2), intent(in)}]{Pres\+\_\+l,  }\item[{real, dimension(nk), intent(in)}]{hcol\+\_\+l,  }\item[{real, dimension(nk,2), intent(in)}]{Tl,  }\item[{real, dimension(nk,2), intent(in)}]{Sl,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly\+\_\+\+T\+\_\+l,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly\+\_\+\+S\+\_\+l,  }\item[{logical, dimension(nk), intent(in)}]{stable\+\_\+l,  }\item[{real, dimension(nk,2), intent(in)}]{Pres\+\_\+r,  }\item[{real, dimension(nk), intent(in)}]{hcol\+\_\+r,  }\item[{real, dimension(nk,2), intent(in)}]{Tr,  }\item[{real, dimension(nk,2), intent(in)}]{Sr,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly\+\_\+\+T\+\_\+r,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly\+\_\+\+S\+\_\+r,  }\item[{logical, dimension(nk), intent(in)}]{stable\+\_\+r,  }\item[{real, dimension(4$\ast$nk), intent(inout)}]{PoL,  }\item[{real, dimension(4$\ast$nk), intent(inout)}]{PoR,  }\item[{integer, dimension(4$\ast$nk), intent(inout)}]{KoL,  }\item[{integer, dimension(4$\ast$nk), intent(inout)}]{KoR,  }\item[{real, dimension(4$\ast$nk-\/1), intent(inout)}]{h\+Eff,  }\item[{real, intent(in), optional}]{zeta\+\_\+bot\+\_\+L,  }\item[{real, intent(in), optional}]{zeta\+\_\+bot\+\_\+R,  }\item[{integer, intent(in), optional}]{k\+\_\+bot\+\_\+L,  }\item[{integer, intent(in), optional}]{k\+\_\+bot\+\_\+R,  }\item[{logical, intent(in), optional}]{hard\+\_\+fail\+\_\+heff }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Higher order version of find\+\_\+neutral\+\_\+surface\+\_\+positions. Returns positions within left/right columns of combined interfaces using intracell reconstructions of T/S. Note that the polynomial reconstrcutions of T and S are optional to aid with unit testing, but will always be passed otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Neutral diffusion control structure \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em pres\+\_\+l} & Left-\/column interface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hcol\+\_\+l} & Left-\/column layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em tl} & Left-\/column top interface potential temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em sl} & Left-\/column top interface salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+t\+\_\+l} & Left-\/column coefficients of T reconstruction \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+s\+\_\+l} & Left-\/column coefficients of S reconstruction \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em stable\+\_\+l} & True where the left-\/column is stable \\
\hline
\mbox{\texttt{ in}}  & {\em pres\+\_\+r} & Right-\/column interface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hcol\+\_\+r} & Left-\/column layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em tr} & Right-\/column top interface potential temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em sr} & Right-\/column top interface salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+t\+\_\+r} & Right-\/column coefficients of T reconstruction \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly\+\_\+s\+\_\+r} & Right-\/column coefficients of S reconstruction \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em stable\+\_\+r} & True where the right-\/column is stable \\
\hline
\mbox{\texttt{ in,out}}  & {\em pol} & Fractional position of neutral surface within layer KoL of left column \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em por} & Fractional position of neutral surface within layer KoR of right column \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em kol} & Index of first left interface above neutral surface \\
\hline
\mbox{\texttt{ in,out}}  & {\em kor} & Index of first right interface above neutral surface \\
\hline
\mbox{\texttt{ in,out}}  & {\em heff} & Effective thickness between two neutral surfaces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} or other units taken from hcol\+\_\+l \\
\hline
\mbox{\texttt{ in}}  & {\em zeta\+\_\+bot\+\_\+l} & Non-\/dimensional distance to where the boundary layer intersetcs the cell (left) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em zeta\+\_\+bot\+\_\+r} & Non-\/dimensional distance to where the boundary layer intersetcs the cell (right) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+bot\+\_\+l} & k-\/index for the boundary layer (left) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+bot\+\_\+r} & k-\/index for the boundary layer (right) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hard\+\_\+fail\+\_\+heff} & If true (default) bring down the model if the neutral surfaces ever cross \mbox{[}logical\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1183 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1187 }
\DoxyCodeLine{1188   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS),     \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{        !< Neutral diffusion control structure}}
\DoxyCodeLine{1189   \textcolor{keywordtype}{integer},                        \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{        !< Number of levels}}
\DoxyCodeLine{1190 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},          \textcolor{keywordtype}{intent(in)}    :: Pres\_l\textcolor{comment}{    !< Left-\/column interface pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1191 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},            \textcolor{keywordtype}{intent(in)}    :: hcol\_l\textcolor{comment}{    !< Left-\/column layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1192 \textcolor{comment}{                                                             !! or other units}}
\DoxyCodeLine{1193 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},          \textcolor{keywordtype}{intent(in)}    :: Tl\textcolor{comment}{        !< Left-\/column top interface potential temperature [degC]}}
\DoxyCodeLine{1194 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},          \textcolor{keywordtype}{intent(in)}    :: Sl\textcolor{comment}{        !< Left-\/column top interface salinity [ppt]}}
\DoxyCodeLine{1195 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},           \textcolor{keywordtype}{intent(in)}    :: ppoly\_T\_l\textcolor{comment}{ !< Left-\/column coefficients of T reconstruction [degC]}}
\DoxyCodeLine{1196 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},           \textcolor{keywordtype}{intent(in)}    :: ppoly\_S\_l\textcolor{comment}{ !< Left-\/column coefficients of S reconstruction [ppt]}}
\DoxyCodeLine{1197   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nk)},         \textcolor{keywordtype}{intent(in)}    :: stable\_l\textcolor{comment}{  !< True where the left-\/column is stable}}
\DoxyCodeLine{1198 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},          \textcolor{keywordtype}{intent(in)}    :: Pres\_r\textcolor{comment}{    !< Right-\/column interface pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1199 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},            \textcolor{keywordtype}{intent(in)}    :: hcol\_r\textcolor{comment}{    !< Left-\/column layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1200 \textcolor{comment}{                                                             !! or other units}}
\DoxyCodeLine{1201 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},          \textcolor{keywordtype}{intent(in)}    :: Tr\textcolor{comment}{        !< Right-\/column top interface potential temperature [degC]}}
\DoxyCodeLine{1202 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},          \textcolor{keywordtype}{intent(in)}    :: Sr\textcolor{comment}{        !< Right-\/column top interface salinity [ppt]}}
\DoxyCodeLine{1203 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},           \textcolor{keywordtype}{intent(in)}    :: ppoly\_T\_r\textcolor{comment}{ !< Right-\/column coefficients of T reconstruction [degC]}}
\DoxyCodeLine{1204 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},           \textcolor{keywordtype}{intent(in)}    :: ppoly\_S\_r\textcolor{comment}{ !< Right-\/column coefficients of S reconstruction [ppt]}}
\DoxyCodeLine{1205   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nk)},         \textcolor{keywordtype}{intent(in)}    :: stable\_r\textcolor{comment}{  !< True where the right-\/column is stable}}
\DoxyCodeLine{1206 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(4*nk)},          \textcolor{keywordtype}{intent(inout)} :: PoL\textcolor{comment}{       !< Fractional position of neutral surface within}}
\DoxyCodeLine{1207 \textcolor{comment}{                                                             !! layer KoL of left column [nondim]}}
\DoxyCodeLine{1208 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(4*nk)},          \textcolor{keywordtype}{intent(inout)} :: PoR\textcolor{comment}{       !< Fractional position of neutral surface within}}
\DoxyCodeLine{1209 \textcolor{comment}{                                                             !! layer KoR of right column [nondim]}}
\DoxyCodeLine{1210   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4*nk)},       \textcolor{keywordtype}{intent(inout)} :: KoL\textcolor{comment}{       !< Index of first left interface above neutral surface}}
\DoxyCodeLine{1211   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4*nk)},       \textcolor{keywordtype}{intent(inout)} :: KoR\textcolor{comment}{       !< Index of first right interface above neutral surface}}
\DoxyCodeLine{1212 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(4*nk-\/1)},        \textcolor{keywordtype}{intent(inout)} :: hEff\textcolor{comment}{      !< Effective thickness between two neutral surfaces}}
\DoxyCodeLine{1213 \textcolor{comment}{                                                             !! [H \string~> m or kg m-\/2] or other units taken from hcol\_l}}
\DoxyCodeLine{1214 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}    :: zeta\_bot\_L\textcolor{comment}{!< Non-\/dimensional distance to where the boundary layer}}
\DoxyCodeLine{1215 \textcolor{comment}{                                                             !! intersetcs the cell (left) [nondim]}}
\DoxyCodeLine{1216 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}    :: zeta\_bot\_R\textcolor{comment}{!< Non-\/dimensional distance to where the boundary layer}}
\DoxyCodeLine{1217 \textcolor{comment}{                                                             !! intersetcs the cell (right) [nondim]}}
\DoxyCodeLine{1218 }
\DoxyCodeLine{1219   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},              \textcolor{keywordtype}{intent(in)}    :: k\_bot\_L\textcolor{comment}{   !< k-\/index for the boundary layer (left) [nondim]}}
\DoxyCodeLine{1220   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},              \textcolor{keywordtype}{intent(in)}    :: k\_bot\_R\textcolor{comment}{   !< k-\/index for the boundary layer (right) [nondim]}}
\DoxyCodeLine{1221   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},              \textcolor{keywordtype}{intent(in)}    :: hard\_fail\_heff\textcolor{comment}{ !< If true (default) bring down the model if the}}
\DoxyCodeLine{1222 \textcolor{comment}{                                                             !! neutral surfaces ever cross [logical]}}
\DoxyCodeLine{1223   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1224   \textcolor{keywordtype}{integer} :: ns                     \textcolor{comment}{! Number of neutral surfaces}}
\DoxyCodeLine{1225   \textcolor{keywordtype}{integer} :: k\_surface              \textcolor{comment}{! Index of neutral surface}}
\DoxyCodeLine{1226   \textcolor{keywordtype}{integer} :: kl\_left, kl\_right      \textcolor{comment}{! Index of layers on the left/right}}
\DoxyCodeLine{1227   \textcolor{keywordtype}{integer} :: ki\_left, ki\_right      \textcolor{comment}{! Index of interfaces on the left/right}}
\DoxyCodeLine{1228   \textcolor{keywordtype}{logical} :: searching\_left\_column  \textcolor{comment}{! True if searching for the position of a right interface in the left column}}
\DoxyCodeLine{1229   \textcolor{keywordtype}{logical} :: searching\_right\_column \textcolor{comment}{! True if searching for the position of a left interface in the right column}}
\DoxyCodeLine{1230   \textcolor{keywordtype}{logical} :: reached\_bottom         \textcolor{comment}{! True if one of the bottom-\/most interfaces has been used as the target}}
\DoxyCodeLine{1231   \textcolor{keywordtype}{logical} :: search\_layer}
\DoxyCodeLine{1232   \textcolor{keywordtype}{logical} :: fail\_heff              \textcolor{comment}{! Fail if negative thickness are encountered.  By default this}}
\DoxyCodeLine{1233                                     \textcolor{comment}{! is true, but it can take its value from hard\_fail\_heff.}}
\DoxyCodeLine{1234 \textcolor{keywordtype}{  real}    :: dRho                   \textcolor{comment}{! A density difference between columns [R \string~> kg m-\/3]}}
\DoxyCodeLine{1235 \textcolor{keywordtype}{  real}    :: hL, hR                 \textcolor{comment}{! Left and right layer thicknesses [H \string~> m or kg m-\/2] or units from hcol\_l}}
\DoxyCodeLine{1236 \textcolor{keywordtype}{  real}    :: lastP\_left, lastP\_right \textcolor{comment}{! Previous positions for left and right [nondim]}}
\DoxyCodeLine{1237   \textcolor{keywordtype}{integer} :: k\_init\_L, k\_init\_R      \textcolor{comment}{! Starting indices layers for left and right}}
\DoxyCodeLine{1238 \textcolor{keywordtype}{  real}    :: p\_init\_L, p\_init\_R      \textcolor{comment}{! Starting positions for left and right [nondim]}}
\DoxyCodeLine{1239   \textcolor{comment}{! Initialize variables for the search}}
\DoxyCodeLine{1240   ns = 4*nk}
\DoxyCodeLine{1241   ki\_right = 1}
\DoxyCodeLine{1242   ki\_left = 1}
\DoxyCodeLine{1243   kl\_left = 1}
\DoxyCodeLine{1244   kl\_right = 1}
\DoxyCodeLine{1245   lastp\_left = 0.}
\DoxyCodeLine{1246   lastp\_right = 0.}
\DoxyCodeLine{1247   reached\_bottom = .false.}
\DoxyCodeLine{1248   searching\_left\_column = .false.}
\DoxyCodeLine{1249   searching\_right\_column = .false.}
\DoxyCodeLine{1250 }
\DoxyCodeLine{1251   fail\_heff = .true.}
\DoxyCodeLine{1252   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(hard\_fail\_heff)) fail\_heff = hard\_fail\_heff}
\DoxyCodeLine{1253 }
\DoxyCodeLine{1254   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(k\_bot\_l) .and. \textcolor{keyword}{PRESENT}(k\_bot\_r) .and. \textcolor{keyword}{PRESENT}(zeta\_bot\_l) .and. \textcolor{keyword}{PRESENT}(zeta\_bot\_r)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1255     k\_init\_l = k\_bot\_l; k\_init\_r = k\_bot\_r}
\DoxyCodeLine{1256     p\_init\_l = zeta\_bot\_l; p\_init\_r = zeta\_bot\_r}
\DoxyCodeLine{1257     lastp\_left = zeta\_bot\_l; lastp\_right = zeta\_bot\_r}
\DoxyCodeLine{1258     kl\_left = k\_bot\_l; kl\_right = k\_bot\_r}
\DoxyCodeLine{1259   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1260     k\_init\_l = 1  ; k\_init\_r = 1}
\DoxyCodeLine{1261     p\_init\_l = 0. ; p\_init\_r = 0.}
\DoxyCodeLine{1262 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1263   \textcolor{comment}{! Loop over each neutral surface, working from top to bottom}}
\DoxyCodeLine{1264   neutral\_surfaces: \textcolor{keywordflow}{do} k\_surface = 1, ns}
\DoxyCodeLine{1265 }
\DoxyCodeLine{1266     \textcolor{keywordflow}{if} (k\_surface == ns) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1267         pol(k\_surface) = 1.}
\DoxyCodeLine{1268         por(k\_surface) = 1.}
\DoxyCodeLine{1269         kol(k\_surface) = nk}
\DoxyCodeLine{1270         kor(k\_surface) = nk}
\DoxyCodeLine{1271     \textcolor{comment}{! If the layers are unstable, then simply point the surface to the previous location}}
\DoxyCodeLine{1272     \textcolor{keywordflow}{elseif} (.not. stable\_l(kl\_left)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1273       \textcolor{keywordflow}{if} (k\_surface > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1274         pol(k\_surface) = ki\_left -\/ 1 \textcolor{comment}{! Top interface is at position = 0., Bottom is at position = 1}}
\DoxyCodeLine{1275         kol(k\_surface) = kl\_left}
\DoxyCodeLine{1276         por(k\_surface) = por(k\_surface-\/1)}
\DoxyCodeLine{1277         kor(k\_surface) = kor(k\_surface-\/1)}
\DoxyCodeLine{1278       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1279         por(k\_surface) = p\_init\_r}
\DoxyCodeLine{1280         kor(k\_surface) = k\_init\_r}
\DoxyCodeLine{1281         pol(k\_surface) = p\_init\_l}
\DoxyCodeLine{1282         kol(k\_surface) = k\_init\_l}
\DoxyCodeLine{1283 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1284       \textcolor{keyword}{call }increment\_interface(nk, kl\_left, ki\_left, reached\_bottom, searching\_left\_column, searching\_right\_column)}
\DoxyCodeLine{1285       searching\_left\_column = .true.}
\DoxyCodeLine{1286       searching\_right\_column = .false.}
\DoxyCodeLine{1287     \textcolor{keywordflow}{elseif} (.not. stable\_r(kl\_right)) \textcolor{keywordflow}{then} \textcolor{comment}{! Check the right layer for stability}}
\DoxyCodeLine{1288       \textcolor{keywordflow}{if} (k\_surface > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1289         por(k\_surface) = ki\_right -\/ 1 \textcolor{comment}{! Top interface is at position = 0., Bottom is at position = 1}}
\DoxyCodeLine{1290         kor(k\_surface) = kl\_right}
\DoxyCodeLine{1291         pol(k\_surface) = pol(k\_surface-\/1)}
\DoxyCodeLine{1292         kol(k\_surface) = kol(k\_surface-\/1)}
\DoxyCodeLine{1293       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1294         por(k\_surface) = 0.}
\DoxyCodeLine{1295         kor(k\_surface) = 1}
\DoxyCodeLine{1296         pol(k\_surface) = 0.}
\DoxyCodeLine{1297         kol(k\_surface) = 1}
\DoxyCodeLine{1298 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1299       \textcolor{keyword}{call }increment\_interface(nk, kl\_right, ki\_right, reached\_bottom, searching\_right\_column, searching\_left\_column)}
\DoxyCodeLine{1300       searching\_left\_column = .false.}
\DoxyCodeLine{1301       searching\_right\_column = .true.}
\DoxyCodeLine{1302     \textcolor{keywordflow}{else} \textcolor{comment}{! Layers are stable so need to figure out whether we need to search right or left}}
\DoxyCodeLine{1303       \textcolor{comment}{! For convenience, the left column uses the searched "{}from"{} interface variables, and the right column}}
\DoxyCodeLine{1304       \textcolor{comment}{! uses the searched 'to'. These will get reset in subsequent calc\_delta\_rho calls}}
\DoxyCodeLine{1305 }
\DoxyCodeLine{1306       \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs,                                                                        \&}
\DoxyCodeLine{1307                                      tr(kl\_right, ki\_right), sr(kl\_right, ki\_right), pres\_r(kl\_right,ki\_right), \&}
\DoxyCodeLine{1308                                      tl(kl\_left, ki\_left),   sl(kl\_left, ki\_left)  , pres\_l(kl\_left,ki\_left),   \&}
\DoxyCodeLine{1309                                      drho)}
\DoxyCodeLine{1310       \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(A,I2,A,E12.4,A,I2,A,I2,A,I2,A,I2)'}) \&}
\DoxyCodeLine{1311           \textcolor{stringliteral}{"{}k\_surface="{}},k\_surface, \textcolor{stringliteral}{"{}  dRho="{}},cs\%R\_to\_kg\_m3*drho, \&}
\DoxyCodeLine{1312           \textcolor{stringliteral}{"{}kl\_left="{}},kl\_left, \textcolor{stringliteral}{"{}  ki\_left="{}},ki\_left, \textcolor{stringliteral}{"{}  kl\_right="{}},kl\_right, \textcolor{stringliteral}{"{}  ki\_right="{}},ki\_right}
\DoxyCodeLine{1313       \textcolor{comment}{! Which column has the lighter surface for the current indexes, kr and kl}}
\DoxyCodeLine{1314       \textcolor{keywordflow}{if} (.not. reached\_bottom) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1315         \textcolor{keywordflow}{if} (drho < 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1316           searching\_left\_column  = .true.}
\DoxyCodeLine{1317           searching\_right\_column = .false.}
\DoxyCodeLine{1318         \textcolor{keywordflow}{elseif} (drho > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1319           searching\_left\_column  = .false.}
\DoxyCodeLine{1320           searching\_right\_column = .true.}
\DoxyCodeLine{1321         \textcolor{keywordflow}{else} \textcolor{comment}{! dRho == 0.}}
\DoxyCodeLine{1322           \textcolor{keywordflow}{if} (  ( kl\_left + kl\_right == 2 ) .and. (ki\_left + ki\_right == 2) ) \textcolor{keywordflow}{then} \textcolor{comment}{! Still at surface}}
\DoxyCodeLine{1323             searching\_left\_column  = .true.}
\DoxyCodeLine{1324             searching\_right\_column = .false.}
\DoxyCodeLine{1325           \textcolor{keywordflow}{else} \textcolor{comment}{! Not the surface so we simply change direction}}
\DoxyCodeLine{1326             searching\_left\_column = .not. searching\_left\_column}
\DoxyCodeLine{1327             searching\_right\_column = .not. searching\_right\_column}
\DoxyCodeLine{1328 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1329 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1330 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1331       \textcolor{keywordflow}{if} (searching\_left\_column) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1332         \textcolor{comment}{! Position of the right interface is known and all quantities are fixed}}
\DoxyCodeLine{1333         por(k\_surface) = ki\_right -\/ 1.}
\DoxyCodeLine{1334         kor(k\_surface) = kl\_right}
\DoxyCodeLine{1335         pol(k\_surface) = search\_other\_column(cs, k\_surface, lastp\_left,                                \&}
\DoxyCodeLine{1336                            tr(kl\_right, ki\_right), sr(kl\_right, ki\_right), pres\_r(kl\_right, ki\_right), \&}
\DoxyCodeLine{1337                            tl(kl\_left,1),          sl(kl\_left,1),          pres\_l(kl\_left,1),          \&}
\DoxyCodeLine{1338                            tl(kl\_left,2),          sl(kl\_left,2),          pres\_l(kl\_left,2),          \&}
\DoxyCodeLine{1339                            ppoly\_t\_l(kl\_left,:), ppoly\_s\_l(kl\_left,:))}
\DoxyCodeLine{1340         kol(k\_surface) = kl\_left}
\DoxyCodeLine{1341 }
\DoxyCodeLine{1342         \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1343           \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(A,I2)'}) \textcolor{stringliteral}{"{}Searching left layer "{}}, kl\_left}
\DoxyCodeLine{1344           \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(A,I2,X,I2)'}) \textcolor{stringliteral}{"{}Searching from right: "{}}, kl\_right, ki\_right}
\DoxyCodeLine{1345           \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{"{}Temp/Salt Reference: "{}}, tr(kl\_right,ki\_right), sr(kl\_right,ki\_right)}
\DoxyCodeLine{1346           \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{"{}Temp/Salt Top L: "{}}, tl(kl\_left,1), sl(kl\_left,1)}
\DoxyCodeLine{1347           \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{"{}Temp/Salt Bot L: "{}}, tl(kl\_left,2), sl(kl\_left,2)}
\DoxyCodeLine{1348 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1349         \textcolor{keyword}{call }increment\_interface(nk, kl\_right, ki\_right, reached\_bottom, searching\_right\_column, searching\_left\_column)}
\DoxyCodeLine{1350         lastp\_left = pol(k\_surface)}
\DoxyCodeLine{1351         \textcolor{comment}{! If the right layer increments, then we need to reset the last position on the right}}
\DoxyCodeLine{1352         \textcolor{keywordflow}{if} ( kl\_right == (kor(k\_surface) + 1) ) lastp\_right = 0.}
\DoxyCodeLine{1353 }
\DoxyCodeLine{1354       \textcolor{keywordflow}{elseif} (searching\_right\_column) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1355         \textcolor{comment}{! Position of the right interface is known and all quantities are fixed}}
\DoxyCodeLine{1356         pol(k\_surface) = ki\_left -\/ 1.}
\DoxyCodeLine{1357         kol(k\_surface) = kl\_left}
\DoxyCodeLine{1358         por(k\_surface) = search\_other\_column(cs, k\_surface, lastp\_right,                         \&}
\DoxyCodeLine{1359                            tl(kl\_left, ki\_left), sl(kl\_left, ki\_left), pres\_l(kl\_left, ki\_left), \&}
\DoxyCodeLine{1360                            tr(kl\_right,1),       sr(kl\_right,1),       pres\_r(kl\_right,1),       \&}
\DoxyCodeLine{1361                            tr(kl\_right,2),       sr(kl\_right,2),       pres\_r(kl\_right,2),       \&}
\DoxyCodeLine{1362                            ppoly\_t\_r(kl\_right,:), ppoly\_s\_r(kl\_right,:))}
\DoxyCodeLine{1363         kor(k\_surface) = kl\_right}
\DoxyCodeLine{1364 }
\DoxyCodeLine{1365         \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1366           \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(A,I2)'}) \textcolor{stringliteral}{"{}Searching right layer "{}}, kl\_right}
\DoxyCodeLine{1367           \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(A,I2,X,I2)'}) \textcolor{stringliteral}{"{}Searching from left: "{}}, kl\_left, ki\_left}
\DoxyCodeLine{1368           \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{"{}Temp/Salt Reference: "{}}, tl(kl\_left,ki\_left), sl(kl\_left,ki\_left)}
\DoxyCodeLine{1369           \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{"{}Temp/Salt Top L: "{}}, tr(kl\_right,1), sr(kl\_right,1)}
\DoxyCodeLine{1370           \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{"{}Temp/Salt Bot L: "{}}, tr(kl\_right,2), sr(kl\_right,2)}
\DoxyCodeLine{1371 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1372         \textcolor{keyword}{call }increment\_interface(nk, kl\_left, ki\_left, reached\_bottom, searching\_left\_column, searching\_right\_column)}
\DoxyCodeLine{1373         lastp\_right = por(k\_surface)}
\DoxyCodeLine{1374         \textcolor{comment}{! If the right layer increments, then we need to reset the last position on the right}}
\DoxyCodeLine{1375         \textcolor{keywordflow}{if} ( kl\_left == (kol(k\_surface) + 1) ) lastp\_left = 0.}
\DoxyCodeLine{1376       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1377         stop \textcolor{stringliteral}{'Else what?'}}
\DoxyCodeLine{1378 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1379       \textcolor{keywordflow}{if} (cs\%debug)  \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(A,I3,A,ES16.6,A,I2,A,ES16.6)'}) \textcolor{stringliteral}{"{}KoL:"{}}, kol(k\_surface), \textcolor{stringliteral}{"{} PoL:"{}}, pol(k\_surface), \&}
\DoxyCodeLine{1380                      \textcolor{stringliteral}{"{}     KoR:"{}}, kor(k\_surface), \textcolor{stringliteral}{"{} PoR:"{}}, por(k\_surface)}
\DoxyCodeLine{1381 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1382     \textcolor{comment}{! Effective thickness}}
\DoxyCodeLine{1383     \textcolor{keywordflow}{if} (k\_surface>1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1384       \textcolor{keywordflow}{if} ( kol(k\_surface) == kol(k\_surface-\/1) .and. kor(k\_surface) == kor(k\_surface-\/1) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1385         hl = (pol(k\_surface) -\/ pol(k\_surface-\/1))*hcol\_l(kol(k\_surface))}
\DoxyCodeLine{1386         hr = (por(k\_surface) -\/ por(k\_surface-\/1))*hcol\_r(kor(k\_surface))}
\DoxyCodeLine{1387         \textcolor{keywordflow}{if} (hl < 0. .or. hr < 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1388           \textcolor{keywordflow}{if} (fail\_heff) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1389             \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}Negative thicknesses in neutral diffusion"{}})}
\DoxyCodeLine{1390           \textcolor{keywordflow}{else}}
\DoxyCodeLine{1391             \textcolor{keywordflow}{if} (searching\_left\_column) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1392               pol(k\_surface) = pol(k\_surface-\/1)}
\DoxyCodeLine{1393               kol(k\_surface) = kol(k\_surface-\/1)}
\DoxyCodeLine{1394             \textcolor{keywordflow}{elseif} (searching\_right\_column) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1395               por(k\_surface) = por(k\_surface-\/1)}
\DoxyCodeLine{1396               kor(k\_surface) = kor(k\_surface-\/1)}
\DoxyCodeLine{1397 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1398 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1399         \textcolor{keywordflow}{elseif} ( hl + hr == 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1400           heff(k\_surface-\/1) = 0.}
\DoxyCodeLine{1401         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1402           heff(k\_surface-\/1) = 2. * ( (hl * hr) / ( hl + hr ) )\textcolor{comment}{! Harmonic mean}}
\DoxyCodeLine{1403           \textcolor{keywordflow}{if} ( kol(k\_surface) /= kol(k\_surface-\/1) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1404             \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}Neutral sublayer spans multiple layers"{}})}
\DoxyCodeLine{1405 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1406           \textcolor{keywordflow}{if} ( kor(k\_surface) /= kor(k\_surface-\/1) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1407             \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}Neutral sublayer spans multiple layers"{}})}
\DoxyCodeLine{1408 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1409 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1410       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1411         heff(k\_surface-\/1) = 0.}
\DoxyCodeLine{1412 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1413 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1414 \textcolor{keywordflow}{  enddo} neutral\_surfaces}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a1c5ac28d7c54581cdd872fe58ef0b204}\label{namespacemom__neutral__diffusion_a1c5ac28d7c54581cdd872fe58ef0b204}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!fv\_diff@{fv\_diff}}
\index{fv\_diff@{fv\_diff}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{fv\_diff()}{fv\_diff()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::fv\+\_\+diff (\begin{DoxyParamCaption}\item[{real, intent(in)}]{hkm1,  }\item[{real, intent(in)}]{hk,  }\item[{real, intent(in)}]{hkp1,  }\item[{real, intent(in)}]{Skm1,  }\item[{real, intent(in)}]{Sk,  }\item[{real, intent(in)}]{Skp1 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the cell-\/centered second-\/order finite volume (unlimited P\+LM) slope using three consecutive cell widths and average values. Slope is returned as a difference across the central cell (i.\+e. units of scalar S). Discretization follows equation 1.\+7 in Colella \& Woodward, 1984\+: J\+CP 54, 174-\/201. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hkm1} & Left cell width \\
\hline
\mbox{\texttt{ in}}  & {\em hk} & Center cell width \\
\hline
\mbox{\texttt{ in}}  & {\em hkp1} & Right cell width \\
\hline
\mbox{\texttt{ in}}  & {\em skm1} & Left cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em sk} & Center cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em skp1} & Right cell average value \\
\hline
\end{DoxyParams}


Definition at line 875 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{876 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkm1\textcolor{comment}{ !< Left cell width}}
\DoxyCodeLine{877 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hk\textcolor{comment}{   !< Center cell width}}
\DoxyCodeLine{878 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkp1\textcolor{comment}{ !< Right cell width}}
\DoxyCodeLine{879 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Skm1\textcolor{comment}{ !< Left cell average value}}
\DoxyCodeLine{880 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Sk\textcolor{comment}{   !< Center cell average value}}
\DoxyCodeLine{881 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Skp1\textcolor{comment}{ !< Right cell average value}}
\DoxyCodeLine{882 }
\DoxyCodeLine{883   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{884 \textcolor{keywordtype}{  real} :: h\_sum, hp, hm}
\DoxyCodeLine{885 }
\DoxyCodeLine{886   h\_sum = ( hkm1 + hkp1 ) + hk}
\DoxyCodeLine{887   \textcolor{keywordflow}{if} (h\_sum /= 0.) h\_sum = 1./ h\_sum}
\DoxyCodeLine{888   hm =  hkm1 + hk}
\DoxyCodeLine{889   \textcolor{keywordflow}{if} (hm /= 0.) hm = 1./ hm}
\DoxyCodeLine{890   hp =  hkp1 + hk}
\DoxyCodeLine{891   \textcolor{keywordflow}{if} (hp /= 0.) hp = 1./ hp}
\DoxyCodeLine{892   fv\_diff = ( hk * h\_sum ) * \&}
\DoxyCodeLine{893             (   ( 2. * hkm1 + hk ) * hp * ( skp1 -\/ sk ) \&}
\DoxyCodeLine{894               + ( 2. * hkp1 + hk ) * hm * ( sk -\/ skm1 ) )}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a6ed3814088af470ad6fc4a3a80926fd7}\label{namespacemom__neutral__diffusion_a6ed3814088af470ad6fc4a3a80926fd7}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!fvlsq\_slope@{fvlsq\_slope}}
\index{fvlsq\_slope@{fvlsq\_slope}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{fvlsq\_slope()}{fvlsq\_slope()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::fvlsq\+\_\+slope (\begin{DoxyParamCaption}\item[{real, intent(in)}]{hkm1,  }\item[{real, intent(in)}]{hk,  }\item[{real, intent(in)}]{hkp1,  }\item[{real, intent(in)}]{Skm1,  }\item[{real, intent(in)}]{Sk,  }\item[{real, intent(in)}]{Skp1 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the cell-\/centered second-\/order weighted least squares slope using three consecutive cell widths and average values. Slope is returned as a gradient (i.\+e. units of scalar S over width units). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hkm1} & Left cell width \\
\hline
\mbox{\texttt{ in}}  & {\em hk} & Center cell width \\
\hline
\mbox{\texttt{ in}}  & {\em hkp1} & Right cell width \\
\hline
\mbox{\texttt{ in}}  & {\em skm1} & Left cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em sk} & Center cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em skp1} & Right cell average value \\
\hline
\end{DoxyParams}


Definition at line 901 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{902 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkm1\textcolor{comment}{ !< Left cell width}}
\DoxyCodeLine{903 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hk\textcolor{comment}{   !< Center cell width}}
\DoxyCodeLine{904 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkp1\textcolor{comment}{ !< Right cell width}}
\DoxyCodeLine{905 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Skm1\textcolor{comment}{ !< Left cell average value}}
\DoxyCodeLine{906 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Sk\textcolor{comment}{   !< Center cell average value}}
\DoxyCodeLine{907 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Skp1\textcolor{comment}{ !< Right cell average value}}
\DoxyCodeLine{908 }
\DoxyCodeLine{909   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{910 \textcolor{keywordtype}{  real} :: xkm1, xkp1}
\DoxyCodeLine{911 \textcolor{keywordtype}{  real} :: h\_sum, hx\_sum, hxsq\_sum, hxy\_sum, hy\_sum, det}
\DoxyCodeLine{912 }
\DoxyCodeLine{913   xkm1 = -\/0.5 * ( hk + hkm1 )}
\DoxyCodeLine{914   xkp1 = 0.5 * ( hk + hkp1 )}
\DoxyCodeLine{915   h\_sum = ( hkm1 + hkp1 ) + hk}
\DoxyCodeLine{916   hx\_sum = hkm1*xkm1 + hkp1*xkp1}
\DoxyCodeLine{917   hxsq\_sum = hkm1*(xkm1**2) + hkp1*(xkp1**2)}
\DoxyCodeLine{918   hxy\_sum = hkm1*xkm1*skm1 + hkp1*xkp1*skp1}
\DoxyCodeLine{919   hy\_sum = ( hkm1*skm1 + hkp1*skp1 ) + hk*sk}
\DoxyCodeLine{920   det = h\_sum * hxsq\_sum -\/ hx\_sum**2}
\DoxyCodeLine{921   \textcolor{keywordflow}{if} (det /= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{922     \textcolor{comment}{!a = ( hxsq\_sum * hy\_sum -\/ hx\_sum*hxy\_sum ) / det ! a would be mean of straight line fit}}
\DoxyCodeLine{923     fvlsq\_slope = ( h\_sum * hxy\_sum -\/ hx\_sum*hy\_sum ) / det \textcolor{comment}{! Gradient of straight line fit}}
\DoxyCodeLine{924   \textcolor{keywordflow}{else}}
\DoxyCodeLine{925     fvlsq\_slope = 0. \textcolor{comment}{! Adcroft's reciprocal rule}}
\DoxyCodeLine{926 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_aa8a9c4a6e7e96ae356f913d4e8611f17}\label{namespacemom__neutral__diffusion_aa8a9c4a6e7e96ae356f913d4e8611f17}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!increment\_interface@{increment\_interface}}
\index{increment\_interface@{increment\_interface}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{increment\_interface()}{increment\_interface()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::increment\+\_\+interface (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{integer, intent(inout)}]{kl,  }\item[{integer, intent(inout)}]{ki,  }\item[{logical, intent(inout)}]{reached\+\_\+bottom,  }\item[{logical, intent(inout)}]{searching\+\_\+this\+\_\+column,  }\item[{logical, intent(inout)}]{searching\+\_\+other\+\_\+column }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Increments the interface which was just connected and also set flags if the bottom is reached. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of vertical levels \\
\hline
\mbox{\texttt{ in,out}}  & {\em kl} & Current layer (potentially updated) \\
\hline
\mbox{\texttt{ in,out}}  & {\em ki} & Current interface \\
\hline
\mbox{\texttt{ in,out}}  & {\em reached\+\_\+bottom} & Updated when kl == nk and ki == 2 \\
\hline
\mbox{\texttt{ in,out}}  & {\em searching\+\_\+this\+\_\+column} & Updated when kl == nk and ki == 2 \\
\hline
\mbox{\texttt{ in,out}}  & {\em searching\+\_\+other\+\_\+column} & Updated when kl == nk and ki == 2 \\
\hline
\end{DoxyParams}


Definition at line 1506 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1507   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in   )}                :: nk\textcolor{comment}{                     !< Number of vertical levels}}
\DoxyCodeLine{1508   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(inout)}                :: kl\textcolor{comment}{                     !< Current layer (potentially updated)}}
\DoxyCodeLine{1509   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(inout)}                :: ki\textcolor{comment}{                     !< Current interface}}
\DoxyCodeLine{1510   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(inout)}                :: reached\_bottom\textcolor{comment}{         !< Updated when kl == nk and ki == 2}}
\DoxyCodeLine{1511   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(inout)}                :: searching\_this\_column\textcolor{comment}{  !< Updated when kl == nk and ki == 2}}
\DoxyCodeLine{1512   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(inout)}                :: searching\_other\_column\textcolor{comment}{ !< Updated when kl == nk and ki == 2}}
\DoxyCodeLine{1513   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1514 }
\DoxyCodeLine{1515   reached\_bottom = .false.}
\DoxyCodeLine{1516   \textcolor{keywordflow}{if} (ki == 2) \textcolor{keywordflow}{then} \textcolor{comment}{! At the bottom interface}}
\DoxyCodeLine{1517     \textcolor{keywordflow}{if} ((ki == 2) .and. (kl < nk) ) \textcolor{keywordflow}{then} \textcolor{comment}{! Not at the bottom so just go to the next layer}}
\DoxyCodeLine{1518       kl = kl+1}
\DoxyCodeLine{1519       ki = 1}
\DoxyCodeLine{1520     \textcolor{keywordflow}{elseif} ((kl == nk) .and. (ki==2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1521       reached\_bottom = .true.}
\DoxyCodeLine{1522       searching\_this\_column = .false.}
\DoxyCodeLine{1523       searching\_other\_column = .true.}
\DoxyCodeLine{1524 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1525   \textcolor{keywordflow}{elseif} (ki==1) \textcolor{keywordflow}{then} \textcolor{comment}{! At the top interface}}
\DoxyCodeLine{1526     ki = 2 \textcolor{comment}{! Next interface is same layer, but bottom interface}}
\DoxyCodeLine{1527   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1528     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}Unanticipated eventuality in increment\_interface"{}})}
\DoxyCodeLine{1529 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_aec9b89b6a5ddc81f102309b964a0b969}\label{namespacemom__neutral__diffusion_aec9b89b6a5ddc81f102309b964a0b969}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!interface\_scalar@{interface\_scalar}}
\index{interface\_scalar@{interface\_scalar}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{interface\_scalar()}{interface\_scalar()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::interface\+\_\+scalar (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{h,  }\item[{real, dimension(nk), intent(in)}]{S,  }\item[{real, dimension(nk+1), intent(inout)}]{Si,  }\item[{integer, intent(in)}]{i\+\_\+method,  }\item[{real, intent(in)}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns interface scalar, Si, for a column of layer values, S. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Layer scalar (conc, e.\+g. ppt) \\
\hline
\mbox{\texttt{ in,out}}  & {\em si} & Interface scalar (conc, e.\+g. ppt) \\
\hline
\mbox{\texttt{ in}}  & {\em i\+\_\+method} & =1 use average of P\+LM edges =2 use continuous P\+PM edge interpolation \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 692 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{693   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{       !< Number of levels}}
\DoxyCodeLine{694 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{        !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{695 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{        !< Layer scalar (conc, e.g. ppt)}}
\DoxyCodeLine{696 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)}, \textcolor{keywordtype}{intent(inout)} :: Si\textcolor{comment}{       !< Interface scalar (conc, e.g. ppt)}}
\DoxyCodeLine{697   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: i\_method\textcolor{comment}{ !< =1 use average of PLM edges}}
\DoxyCodeLine{698 \textcolor{comment}{                                                   !! =2 use continuous PPM edge interpolation}}
\DoxyCodeLine{699 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{700   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{701   \textcolor{keywordtype}{integer} :: k, km2, kp1}
\DoxyCodeLine{702 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: diff}
\DoxyCodeLine{703 \textcolor{keywordtype}{  real} :: Sb, Sa}
\DoxyCodeLine{704 }
\DoxyCodeLine{705   \textcolor{keyword}{call }plm\_diff(nk, h, s, 2, 1, diff)}
\DoxyCodeLine{706   si(1) = s(1) -\/ 0.5 * diff(1)}
\DoxyCodeLine{707   \textcolor{keywordflow}{if} (i\_method==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{708     \textcolor{keywordflow}{do} k = 2, nk}
\DoxyCodeLine{709       \textcolor{comment}{! Average of the two edge values (will be bounded and,}}
\DoxyCodeLine{710       \textcolor{comment}{! when slopes are unlimited, notionally second-\/order accurate)}}
\DoxyCodeLine{711       sa = s(k-\/1) + 0.5 * diff(k-\/1) \textcolor{comment}{! Lower edge value of a PLM reconstruction for layer above}}
\DoxyCodeLine{712       sb = s(k) -\/ 0.5 * diff(k) \textcolor{comment}{! Upper edge value of a PLM reconstruction for layer below}}
\DoxyCodeLine{713       si(k) = 0.5 * ( sa + sb )}
\DoxyCodeLine{714 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{715   \textcolor{keywordflow}{elseif} (i\_method==2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{716     \textcolor{keywordflow}{do} k = 2, nk}
\DoxyCodeLine{717       \textcolor{comment}{! PPM quasi-\/fourth order interpolation for edge values following}}
\DoxyCodeLine{718       \textcolor{comment}{! equation 1.6 in Colella \& Woodward, 1984: JCP 54, 174-\/201.}}
\DoxyCodeLine{719       km2 = max(1, k-\/2)}
\DoxyCodeLine{720       kp1 = min(nk, k+1)}
\DoxyCodeLine{721       si(k) = ppm\_edge(h(km2), h(k-\/1), h(k), h(kp1),  s(k-\/1), s(k), diff(k-\/1), diff(k), h\_neglect)}
\DoxyCodeLine{722 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{723 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{724   si(nk+1) = s(nk) + 0.5 * diff(nk)}
\DoxyCodeLine{725 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a666836e70bdae7ef4ec271246cf91993}\label{namespacemom__neutral__diffusion_a666836e70bdae7ef4ec271246cf91993}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!interpolate\_for\_nondim\_position@{interpolate\_for\_nondim\_position}}
\index{interpolate\_for\_nondim\_position@{interpolate\_for\_nondim\_position}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{interpolate\_for\_nondim\_position()}{interpolate\_for\_nondim\_position()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::interpolate\+\_\+for\+\_\+nondim\+\_\+position (\begin{DoxyParamCaption}\item[{real, intent(in)}]{d\+Rho\+Neg,  }\item[{real, intent(in)}]{Pneg,  }\item[{real, intent(in)}]{d\+Rho\+Pos,  }\item[{real, intent(in)}]{Ppos }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the non-\/dimensional position between Pneg and Ppos where the interpolated density difference equals zero. The result is always bounded to be between 0 and 1. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em drhoneg} & Negative density difference \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pneg} & Position of negative density difference \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drhopos} & Positive density difference \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppos} & Position of positive density difference \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}nondim\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1142 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1143 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: dRhoNeg\textcolor{comment}{ !< Negative density difference [R \string~> kg m-\/3]}}
\DoxyCodeLine{1144 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Pneg\textcolor{comment}{    !< Position of negative density difference [R L2 T-\/2 \string~> Pa] or [nondim]}}
\DoxyCodeLine{1145 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: dRhoPos\textcolor{comment}{ !< Positive density difference [R \string~> kg m-\/3]}}
\DoxyCodeLine{1146 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Ppos\textcolor{comment}{    !< Position of positive density difference [R L2 T-\/2 \string~> Pa] or [nondim]}}
\DoxyCodeLine{1147 }
\DoxyCodeLine{1148   \textcolor{keywordtype}{character(len=120)} :: mesg}
\DoxyCodeLine{1149 }
\DoxyCodeLine{1150   \textcolor{keywordflow}{if} (ppos < pneg) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1151     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'interpolate\_for\_nondim\_position: Houston, we have a problem! Ppos<Pneg'})}
\DoxyCodeLine{1152   \textcolor{keywordflow}{elseif} (drhoneg>drhopos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1153     \textcolor{keyword}{write}(stderr,*) \textcolor{stringliteral}{'dRhoNeg, Pneg, dRhoPos, Ppos='},drhoneg, pneg, drhopos, ppos}
\DoxyCodeLine{1154     \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'dRhoNeg, Pneg, dRhoPos, Ppos='}, drhoneg, pneg, drhopos, ppos}
\DoxyCodeLine{1155     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'interpolate\_for\_nondim\_position: '}//trim(mesg))}
\DoxyCodeLine{1156   \textcolor{keywordflow}{elseif} (drhoneg>drhopos) \textcolor{keywordflow}{then} \textcolor{comment}{!\#\#\# Does this duplicated test belong here?}}
\DoxyCodeLine{1157     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'interpolate\_for\_nondim\_position: Houston, we have a problem! dRhoNeg>dRhoPos'})}
\DoxyCodeLine{1158 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1159   \textcolor{keywordflow}{if} (ppos<=pneg) \textcolor{keywordflow}{then} \textcolor{comment}{! Handle vanished or inverted layers}}
\DoxyCodeLine{1160     interpolate\_for\_nondim\_position = 0.5}
\DoxyCodeLine{1161   \textcolor{keywordflow}{elseif} ( drhopos -\/ drhoneg > 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1162     interpolate\_for\_nondim\_position = min( 1., max( 0., -\/drhoneg / ( drhopos -\/ drhoneg ) ) )}
\DoxyCodeLine{1163   \textcolor{keywordflow}{elseif} ( drhopos -\/ drhoneg == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1164     \textcolor{keywordflow}{if} (drhoneg>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1165       interpolate\_for\_nondim\_position = 0.}
\DoxyCodeLine{1166     \textcolor{keywordflow}{elseif} (drhoneg<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1167       interpolate\_for\_nondim\_position = 1.}
\DoxyCodeLine{1168     \textcolor{keywordflow}{else} \textcolor{comment}{! dRhoPos = dRhoNeg = 0}}
\DoxyCodeLine{1169       interpolate\_for\_nondim\_position = 0.5}
\DoxyCodeLine{1170 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1171   \textcolor{keywordflow}{else} \textcolor{comment}{! dRhoPos -\/ dRhoNeg < 0}}
\DoxyCodeLine{1172     interpolate\_for\_nondim\_position = 0.5}
\DoxyCodeLine{1173 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1174   \textcolor{keywordflow}{if} ( interpolate\_for\_nondim\_position < 0. ) \&}
\DoxyCodeLine{1175     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'interpolate\_for\_nondim\_position: Houston, we have a problem! Pint < Pneg'})}
\DoxyCodeLine{1176   \textcolor{keywordflow}{if} ( interpolate\_for\_nondim\_position > 1. ) \&}
\DoxyCodeLine{1177     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'interpolate\_for\_nondim\_position: Houston, we have a problem! Pint > Ppos'})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a3ef7040590d6448a34013763e17edf47}\label{namespacemom__neutral__diffusion_a3ef7040590d6448a34013763e17edf47}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!mark\_unstable\_cells@{mark\_unstable\_cells}}
\index{mark\_unstable\_cells@{mark\_unstable\_cells}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{mark\_unstable\_cells()}{mark\_unstable\_cells()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::mark\+\_\+unstable\+\_\+cells (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), intent(inout)}]{CS,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk,2), intent(in)}]{T,  }\item[{real, dimension(nk,2), intent(in)}]{S,  }\item[{real, dimension(nk,2), intent(in)}]{P,  }\item[{logical, dimension(nk), intent(out)}]{stable\+\_\+cell }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sweep down through the column and mark as stable if the bottom interface of a cell is denser than the top. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Neutral diffusion control structure \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of levels in a column \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Temperature at interfaces \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity at interfaces \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p} & Pressure at interfaces \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em stable\+\_\+cell} & True if this cell is unstably stratified \\
\hline
\end{DoxyParams}


Definition at line 1418 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1419   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{      !< Neutral diffusion control structure}}
\DoxyCodeLine{1420   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{          !< Number of levels in a column}}
\DoxyCodeLine{1421 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},  \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{           !< Temperature at interfaces [degC]}}
\DoxyCodeLine{1422 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},  \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{           !< Salinity at interfaces [ppt]}}
\DoxyCodeLine{1423 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},  \textcolor{keywordtype}{intent(in)}    :: P\textcolor{comment}{           !< Pressure at interfaces [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1424   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(  out)} :: stable\_cell\textcolor{comment}{ !< True if this cell is unstably stratified}}
\DoxyCodeLine{1425 }
\DoxyCodeLine{1426   \textcolor{keywordtype}{integer} :: k, first\_stable, prev\_stable}
\DoxyCodeLine{1427 \textcolor{keywordtype}{  real} :: delta\_rho \textcolor{comment}{! A density difference [R \string~> kg m-\/3]}}
\DoxyCodeLine{1428 }
\DoxyCodeLine{1429   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{1430     \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs( cs, t(k,2), s(k,2), max(p(k,2), cs\%ref\_pres), \&}
\DoxyCodeLine{1431                                         t(k,1), s(k,1), max(p(k,1), cs\%ref\_pres), delta\_rho )}
\DoxyCodeLine{1432     stable\_cell(k) = (delta\_rho > 0.)}
\DoxyCodeLine{1433 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a9aaf0988f76c9992d8f1db48ce23bf34}\label{namespacemom__neutral__diffusion_a9aaf0988f76c9992d8f1db48ce23bf34}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!ndiff\_unit\_tests\_continuous@{ndiff\_unit\_tests\_continuous}}
\index{ndiff\_unit\_tests\_continuous@{ndiff\_unit\_tests\_continuous}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{ndiff\_unit\_tests\_continuous()}{ndiff\_unit\_tests\_continuous()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::ndiff\+\_\+unit\+\_\+tests\+\_\+continuous (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if unit tests of neutral\+\_\+diffusion functions fail. Otherwise returns false. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\end{DoxyParams}


Definition at line 2088 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2089   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2090   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2091   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}         :: nk = 4}
\DoxyCodeLine{2092 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)}      :: TiL, TiR1, TiR2, TiR4, Tio \textcolor{comment}{! Test interface temperatures}}
\DoxyCodeLine{2093 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}        :: TL                         \textcolor{comment}{! Test layer temperatures}}
\DoxyCodeLine{2094 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)}      :: SiL                        \textcolor{comment}{! Test interface salinities}}
\DoxyCodeLine{2095 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)}      :: PiL, PiR4                  \textcolor{comment}{! Test interface positions}}
\DoxyCodeLine{2096 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*nk+2)}    :: PiLRo, PiRLo               \textcolor{comment}{! Test positions}}
\DoxyCodeLine{2097   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2*nk+2)} :: KoL, KoR                   \textcolor{comment}{! Test indexes}}
\DoxyCodeLine{2098 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*nk+1)}    :: hEff                       \textcolor{comment}{! Test positions}}
\DoxyCodeLine{2099 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*nk+1)}    :: Flx                        \textcolor{comment}{! Test flux}}
\DoxyCodeLine{2100   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{2101   \textcolor{keywordtype}{logical} :: v}
\DoxyCodeLine{2102 \textcolor{keywordtype}{  real} :: h\_neglect}
\DoxyCodeLine{2103 }
\DoxyCodeLine{2104   h\_neglect = 1.0e-\/30}
\DoxyCodeLine{2105 }
\DoxyCodeLine{2106   v = verbose}
\DoxyCodeLine{2107 }
\DoxyCodeLine{2108   ndiff\_unit\_tests\_continuous = .false. \textcolor{comment}{! Normally return false}}
\DoxyCodeLine{2109   \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{'==== MOM\_neutral\_diffusion: ndiff\_unit\_tests\_continuous ='}}
\DoxyCodeLine{2110 }
\DoxyCodeLine{2111   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2112     test\_fv\_diff(v,1.,1.,1., 0.,1.,2., 1., \textcolor{stringliteral}{'FV: Straight line on uniform grid'})}
\DoxyCodeLine{2113   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2114     test\_fv\_diff(v,1.,1.,0., 0.,4.,8., 7., \textcolor{stringliteral}{'FV: Vanished right cell'})}
\DoxyCodeLine{2115   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2116     test\_fv\_diff(v,0.,1.,1., 0.,4.,8., 7., \textcolor{stringliteral}{'FV: Vanished left cell'})}
\DoxyCodeLine{2117   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2118     test\_fv\_diff(v,1.,2.,4., 0.,3.,9., 4., \textcolor{stringliteral}{'FV: Stretched grid'})}
\DoxyCodeLine{2119   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2120     test\_fv\_diff(v,2.,0.,2., 0.,1.,2., 0., \textcolor{stringliteral}{'FV: Vanished middle cell'})}
\DoxyCodeLine{2121   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2122     test\_fv\_diff(v,0.,1.,0., 0.,1.,2., 2., \textcolor{stringliteral}{'FV: Vanished on both sides'})}
\DoxyCodeLine{2123   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2124     test\_fv\_diff(v,1.,0.,0., 0.,1.,2., 0., \textcolor{stringliteral}{'FV: Two vanished cell sides'})}
\DoxyCodeLine{2125   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2126     test\_fv\_diff(v,0.,0.,0., 0.,1.,2., 0., \textcolor{stringliteral}{'FV: All vanished cells'})}
\DoxyCodeLine{2127 }
\DoxyCodeLine{2128   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2129     test\_fvlsq\_slope(v,1.,1.,1., 0.,1.,2., 1., \textcolor{stringliteral}{'LSQ: Straight line on uniform grid'})}
\DoxyCodeLine{2130   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2131     test\_fvlsq\_slope(v,1.,1.,0., 0.,1.,2., 1., \textcolor{stringliteral}{'LSQ: Vanished right cell'})}
\DoxyCodeLine{2132   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2133     test\_fvlsq\_slope(v,0.,1.,1., 0.,1.,2., 1., \textcolor{stringliteral}{'LSQ: Vanished left cell'})}
\DoxyCodeLine{2134   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2135     test\_fvlsq\_slope(v,1.,2.,4., 0.,3.,9., 2., \textcolor{stringliteral}{'LSQ: Stretched grid'})}
\DoxyCodeLine{2136   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2137     test\_fvlsq\_slope(v,1.,0.,1., 0.,1.,2., 2., \textcolor{stringliteral}{'LSQ: Vanished middle cell'})}
\DoxyCodeLine{2138   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2139     test\_fvlsq\_slope(v,0.,1.,0., 0.,1.,2., 0., \textcolor{stringliteral}{'LSQ: Vanished on both sides'})}
\DoxyCodeLine{2140   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2141     test\_fvlsq\_slope(v,1.,0.,0., 0.,1.,2., 0., \textcolor{stringliteral}{'LSQ: Two vanished cell sides'})}
\DoxyCodeLine{2142   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2143     test\_fvlsq\_slope(v,0.,0.,0., 0.,1.,2., 0., \textcolor{stringliteral}{'LSQ: All vanished cells'})}
\DoxyCodeLine{2144 }
\DoxyCodeLine{2145   \textcolor{keyword}{call }interface\_scalar(4, (/10.,10.,10.,10./), (/24.,18.,12.,6./), tio, 1, h\_neglect)}
\DoxyCodeLine{2146   \textcolor{comment}{!ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}}
\DoxyCodeLine{2147   \textcolor{comment}{!  test\_data1d(5, Tio, (/27.,21.,15.,9.,3./), 'Linear profile, interface temperatures')}}
\DoxyCodeLine{2148   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2149     test\_data1d(v,5, tio, (/24.,22.5,15.,7.5,6./), \textcolor{stringliteral}{'Linear profile, linear interface temperatures'})}
\DoxyCodeLine{2150   \textcolor{keyword}{call }interface\_scalar(4, (/10.,10.,10.,10./), (/24.,18.,12.,6./), tio, 2, h\_neglect)}
\DoxyCodeLine{2151   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2152     test\_data1d(v,5, tio, (/24.,22.,15.,8.,6./), \textcolor{stringliteral}{'Linear profile, PPM interface temperatures'})}
\DoxyCodeLine{2153 }
\DoxyCodeLine{2154   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2155     test\_ifndp(v,-\/1.0, 0.,  1.0, 1.0, 0.5, \textcolor{stringliteral}{'Check mid-\/point'})}
\DoxyCodeLine{2156   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2157     test\_ifndp(v, 0.0, 0.,  1.0, 1.0, 0.0, \textcolor{stringliteral}{'Check bottom'})}
\DoxyCodeLine{2158   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2159     test\_ifndp(v, 0.1, 0.,  1.1, 1.0, 0.0, \textcolor{stringliteral}{'Check below'})}
\DoxyCodeLine{2160   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2161     test\_ifndp(v,-\/1.0, 0.,  0.0, 1.0, 1.0, \textcolor{stringliteral}{'Check top'})}
\DoxyCodeLine{2162   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2163     test\_ifndp(v,-\/1.0, 0., -\/0.1, 1.0, 1.0, \textcolor{stringliteral}{'Check above'})}
\DoxyCodeLine{2164   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2165     test\_ifndp(v,-\/1.0, 0.,  3.0, 1.0, 0.25, \textcolor{stringliteral}{'Check 1/4'})}
\DoxyCodeLine{2166   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2167     test\_ifndp(v,-\/3.0, 0.,  1.0, 1.0, 0.75, \textcolor{stringliteral}{'Check 3/4'})}
\DoxyCodeLine{2168   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2169     test\_ifndp(v, 1.0, 0.,  1.0, 1.0, 0.0, \textcolor{stringliteral}{'Check dRho=0 below'})}
\DoxyCodeLine{2170   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2171     test\_ifndp(v,-\/1.0, 0., -\/1.0, 1.0, 1.0, \textcolor{stringliteral}{'Check dRho=0 above'})}
\DoxyCodeLine{2172   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2173     test\_ifndp(v, 0.0, 0.,  0.0, 1.0, 0.5, \textcolor{stringliteral}{'Check dRho=0 mid'})}
\DoxyCodeLine{2174   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. \&}
\DoxyCodeLine{2175     test\_ifndp(v,-\/2.0, .5,  5.0, 0.5, 0.5, \textcolor{stringliteral}{'Check dP=0'})}
\DoxyCodeLine{2176 }
\DoxyCodeLine{2177   \textcolor{comment}{! Identical columns}}
\DoxyCodeLine{2178   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2179              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2180              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2181              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2182              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2183              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2184   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2185                                    (/1,1,2,2,3,3,3,3/), \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2186                                    (/1,1,2,2,3,3,3,3/), \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2187                                    (/0.,0.,0.,0.,0.,0.,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2188                                    (/0.,0.,0.,0.,0.,0.,1.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2189                                    (/0.,10.,0.,10.,0.,10.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2190                                    \textcolor{stringliteral}{'Identical columns'})}
\DoxyCodeLine{2191   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. test\_data1d(v, 8, \&}
\DoxyCodeLine{2192                                    absolute\_positions(3, 8, (/0.,10.,20.,30./), kol, pilro), \&}
\DoxyCodeLine{2193                                    (/0.,0.,10.,10.,20.,20.,30.,30./), \textcolor{stringliteral}{'... left positions'})}
\DoxyCodeLine{2194   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. test\_data1d(v, 8, \&}
\DoxyCodeLine{2195                                    absolute\_positions(3, 8, (/0.,10.,20.,30./), kor, pirlo), \&}
\DoxyCodeLine{2196                                    (/0.,0.,10.,10.,20.,20.,30.,30./), \textcolor{stringliteral}{'... right positions'})}
\DoxyCodeLine{2197   \textcolor{keyword}{call }neutral\_surface\_flux(3, 2*3+2, 2, (/10.,10.,10./), (/10.,10.,10./), \& \textcolor{comment}{! nk, hL, hR}}
\DoxyCodeLine{2198                                (/20.,16.,12./), (/20.,16.,12./), \& \textcolor{comment}{! Tl, Tr}}
\DoxyCodeLine{2199                                pilro, pirlo, kol, kor, heff, flx, .true., h\_neglect)}
\DoxyCodeLine{2200   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. test\_data1d(v, 7, flx, \&}
\DoxyCodeLine{2201               (/0.,0.,0.,0.,0.,0.,0./), \textcolor{stringliteral}{'Identical columns, rho flux (=0)'})}
\DoxyCodeLine{2202   \textcolor{keyword}{call }neutral\_surface\_flux(3, 2*3+2, 2, (/10.,10.,10./), (/10.,10.,10./), \& \textcolor{comment}{! nk, hL, hR}}
\DoxyCodeLine{2203                                (/-\/1.,-\/1.,-\/1./), (/1.,1.,1./), \& \textcolor{comment}{! Sl, Sr}}
\DoxyCodeLine{2204                                pilro, pirlo, kol, kor, heff, flx, .true., h\_neglect)}
\DoxyCodeLine{2205   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. test\_data1d(v, 7, flx, \&}
\DoxyCodeLine{2206               (/0.,20.,0.,20.,0.,20.,0./), \textcolor{stringliteral}{'Identical columns, S flux'})}
\DoxyCodeLine{2207 }
\DoxyCodeLine{2208   \textcolor{comment}{! Right column slightly cooler than left}}
\DoxyCodeLine{2209   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2210              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2211              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2212              (/0.,10.,20.,30./), (/20.,16.,12.,8./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2213              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2214              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2215   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2216                                    (/1,1,2,2,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2217                                    (/1,1,1,2,2,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2218                                    (/0.,0.5,0.,0.5,0.,0.5,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2219                                    (/0.,0.,0.5,0.,0.5,0.,0.5,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2220                                    (/0.,5.,5.,5.,5.,5.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2221                                    \textcolor{stringliteral}{'Right column slightly cooler'})}
\DoxyCodeLine{2222   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. test\_data1d(v, 8, \&}
\DoxyCodeLine{2223                                    absolute\_positions(3, 8, (/0.,10.,20.,30./), kol, pilro), \&}
\DoxyCodeLine{2224                                    (/0.,5.,10.,15.,20.,25.,30.,30./), \textcolor{stringliteral}{'... left positions'})}
\DoxyCodeLine{2225   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or. test\_data1d(v, 8, \&}
\DoxyCodeLine{2226                                    absolute\_positions(3, 8, (/0.,10.,20.,30./), kor, pirlo), \&}
\DoxyCodeLine{2227                                    (/0.,0.,5.,10.,15.,20.,25.,30./), \textcolor{stringliteral}{'... right positions'})}
\DoxyCodeLine{2228 }
\DoxyCodeLine{2229   \textcolor{comment}{! Right column slightly warmer than left}}
\DoxyCodeLine{2230   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2231              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2232              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2233              (/0.,10.,20.,30./), (/24.,20.,16.,12./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2234              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2235              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2236   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2237                                    (/1,1,1,2,2,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2238                                    (/1,1,2,2,3,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2239                                    (/0.,0.,0.5,0.,0.5,0.,0.5,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2240                                    (/0.,0.5,0.,0.5,0.,0.5,1.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2241                                    (/0.,5.,5.,5.,5.,5.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2242                                    \textcolor{stringliteral}{'Right column slightly warmer'})}
\DoxyCodeLine{2243 }
\DoxyCodeLine{2244   \textcolor{comment}{! Right column somewhat cooler than left}}
\DoxyCodeLine{2245   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2246              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2247              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2248              (/0.,10.,20.,30./), (/16.,12.,8.,4./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2249              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2250              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2251   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2252                                    (/1,2,2,3,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2253                                    (/1,1,1,1,2,2,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2254                                    (/0.,0.,0.5,0.,0.5,1.,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2255                                    (/0.,0.,0.,0.5,0.,0.5,0.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2256                                    (/0.,0.,5.,5.,5.,0.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2257                                    \textcolor{stringliteral}{'Right column somewhat cooler'})}
\DoxyCodeLine{2258 }
\DoxyCodeLine{2259   \textcolor{comment}{! Right column much colder than left with no overlap}}
\DoxyCodeLine{2260   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2261              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2262              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2263              (/0.,10.,20.,30./), (/9.,7.,5.,3./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2264              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2265              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2266   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2267                                    (/1,2,3,3,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2268                                    (/1,1,1,1,1,2,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2269                                    (/0.,0.,0.,1.,1.,1.,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2270                                    (/0.,0.,0.,0.,0.,0.,0.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2271                                    (/0.,0.,0.,0.,0.,0.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2272                                    \textcolor{stringliteral}{'Right column much cooler'})}
\DoxyCodeLine{2273 }
\DoxyCodeLine{2274   \textcolor{comment}{! Right column with mixed layer}}
\DoxyCodeLine{2275   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2276              (/0.,10.,20.,30./), (/22.,18.,14.,10./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2277              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2278              (/0.,10.,20.,30./), (/14.,14.,10.,2./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2279              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2280              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2281   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2282                                    (/1,2,3,3,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2283                                    (/1,1,1,1,2,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2284                                    (/0.,0.,0.,0.,0.,1.,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2285                                    (/0.,0.,0.,0.,0.,0.,0.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2286                                    (/0.,0.,0.,0.,10.,0.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2287                                    \textcolor{stringliteral}{'Right column with mixed layer'})}
\DoxyCodeLine{2288 }
\DoxyCodeLine{2289   \textcolor{comment}{! Identical columns with mixed layer}}
\DoxyCodeLine{2290   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2291              (/0.,10.,20.,30./), (/14.,14.,10.,2./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2292              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2293              (/0.,10.,20.,30./), (/14.,14.,10.,2./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2294              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2295              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2296   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2297                                    (/1,1,2,2,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2298                                    (/1,1,2,2,3,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2299                                    (/0.,0.,0.,0.,0.,0.,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2300                                    (/0.,0.,0.,0.,0.,0.,1.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2301                                    (/0.,10.,0.,10.,0.,10.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2302                                    \textcolor{stringliteral}{'Identical columns with mixed layer'})}
\DoxyCodeLine{2303 }
\DoxyCodeLine{2304   \textcolor{comment}{! Right column with unstable mixed layer}}
\DoxyCodeLine{2305   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2306              (/0.,10.,20.,30./), (/14.,14.,10.,2./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2307              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2308              (/0.,10.,20.,30./), (/10.,14.,12.,4./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2309              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2310              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2311   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2312                                    (/1,2,3,3,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2313                                    (/1,1,1,2,3,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2314                                    (/0.,0.,0.,0.,0.,0.,.75,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2315                                    (/0.,0.,0.,0.,0.,0.25,1.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2316                                    (/0.,0.,0.,0.,0.,7.5,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2317                                    \textcolor{stringliteral}{'Right column with unstable mixed layer'})}
\DoxyCodeLine{2318 }
\DoxyCodeLine{2319   \textcolor{comment}{! Left column with unstable mixed layer}}
\DoxyCodeLine{2320   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2321              (/0.,10.,20.,30./), (/10.,14.,12.,4./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2322              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2323              (/0.,10.,20.,30./), (/14.,14.,10.,2./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2324              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2325              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2326   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2327                                    (/1,1,1,2,3,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2328                                    (/1,2,3,3,3,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2329                                    (/0.,0.,0.,0.,0.,0.25,1.,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2330                                    (/0.,0.,0.,0.,0.,0.,.75,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2331                                    (/0.,0.,0.,0.,0.,7.5,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2332                                    \textcolor{stringliteral}{'Left column with unstable mixed layer'})}
\DoxyCodeLine{2333 }
\DoxyCodeLine{2334   \textcolor{comment}{! Two unstable mixed layers}}
\DoxyCodeLine{2335   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(3, \&}
\DoxyCodeLine{2336              (/0.,10.,20.,30./), (/8.,12.,10.,2./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Left positions, T and S}}
\DoxyCodeLine{2337              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Left dRdT and dRdS}}
\DoxyCodeLine{2338              (/0.,10.,20.,30./), (/10.,14.,12.,4./), (/0.,0.,0.,0./), \& \textcolor{comment}{! Right positions, T and S}}
\DoxyCodeLine{2339              (/-\/1.,-\/1.,-\/1.,-\/1./), (/1.,1.,1.,1./), \&\textcolor{comment}{! Right dRdT and dRdS}}
\DoxyCodeLine{2340              pilro, pirlo, kol, kor, heff)}
\DoxyCodeLine{2341   ndiff\_unit\_tests\_continuous = ndiff\_unit\_tests\_continuous .or.  test\_nsp(v, 8, kol, kor, pilro, pirlo, heff, \&}
\DoxyCodeLine{2342                                    (/1,1,1,1,2,3,3,3/), \& \textcolor{comment}{! kL}}
\DoxyCodeLine{2343                                    (/1,2,3,3,3,3,3,3/), \& \textcolor{comment}{! kR}}
\DoxyCodeLine{2344                                    (/0.,0.,0.,0.,0.,0.,0.75,1./), \& \textcolor{comment}{! pL}}
\DoxyCodeLine{2345                                    (/0.,0.,0.,0.5,0.5,0.5,1.,1./), \& \textcolor{comment}{! pR}}
\DoxyCodeLine{2346                                    (/0.,0.,0.,0.,0.,6.,0./), \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2347                                    \textcolor{stringliteral}{'Two unstable mixed layers'})}
\DoxyCodeLine{2348 }
\DoxyCodeLine{2349   \textcolor{keywordflow}{if} (.not. ndiff\_unit\_tests\_continuous) \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{'Pass'}}
\DoxyCodeLine{2350 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_aa44f980bb24df5dc71913b32892b2f71}\label{namespacemom__neutral__diffusion_aa44f980bb24df5dc71913b32892b2f71}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!ndiff\_unit\_tests\_discontinuous@{ndiff\_unit\_tests\_discontinuous}}
\index{ndiff\_unit\_tests\_discontinuous@{ndiff\_unit\_tests\_discontinuous}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{ndiff\_unit\_tests\_discontinuous()}{ndiff\_unit\_tests\_discontinuous()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::ndiff\+\_\+unit\+\_\+tests\+\_\+discontinuous (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & It true, write results to stdout \\
\hline
\end{DoxyParams}


Definition at line 2353 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2354   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< It true, write results to stdout}}
\DoxyCodeLine{2355   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2356   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}          :: nk = 3}
\DoxyCodeLine{2357   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}          :: ns = nk*4}
\DoxyCodeLine{2358 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}         :: Sl, Sr, Tl, Tr \textcolor{comment}{! Salinities [ppt] and temperatures [degC]}}
\DoxyCodeLine{2359 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}         :: hl, hr    \textcolor{comment}{! Thicknesses in pressure units [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{2360 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}       :: TiL, SiL, TiR, SiR \textcolor{comment}{! Cell edge salinities [ppt] and temperatures [degC]}}
\DoxyCodeLine{2361 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}       :: Pres\_l, Pres\_r \textcolor{comment}{! Interface pressures [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{2362   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(ns)}      :: KoL, KoR}
\DoxyCodeLine{2363 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns)}         :: PoL, PoR}
\DoxyCodeLine{2364 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns-\/1)}       :: hEff, Flx}
\DoxyCodeLine{2365   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS)  :: CS\textcolor{comment}{        !< Neutral diffusion control structure}}
\DoxyCodeLine{2366   \textcolor{keywordtype}{type}(EOS\_type),     \textcolor{keywordtype}{pointer} :: EOS\textcolor{comment}{       !< Structure for linear equation of state}}
\DoxyCodeLine{2367   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{pointer} :: remap\_CS\textcolor{comment}{  !< Remapping control structure (PLM)}}
\DoxyCodeLine{2368 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}       :: ppoly\_T\_l, ppoly\_T\_r \textcolor{comment}{! Linear reconstruction for T}}
\DoxyCodeLine{2369 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}       :: ppoly\_S\_l, ppoly\_S\_r \textcolor{comment}{! Linear reconstruction for S}}
\DoxyCodeLine{2370 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}       :: dRdT\textcolor{comment}{      !< Partial derivative of density with temperature at}}
\DoxyCodeLine{2371 \textcolor{comment}{                                           !! cell edges [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{2372 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}       :: dRdS\textcolor{comment}{      !< Partial derivative of density with salinity at}}
\DoxyCodeLine{2373 \textcolor{comment}{                                           !! cell edges [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{2374   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nk)}      :: stable\_l, stable\_r}
\DoxyCodeLine{2375   \textcolor{keywordtype}{integer}                     :: iMethod}
\DoxyCodeLine{2376   \textcolor{keywordtype}{integer}                     :: ns\_l, ns\_r}
\DoxyCodeLine{2377   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{2378   \textcolor{keywordtype}{logical} :: v}
\DoxyCodeLine{2379 }
\DoxyCodeLine{2380   v = verbose}
\DoxyCodeLine{2381   ndiff\_unit\_tests\_discontinuous = .false. \textcolor{comment}{! Normally return false}}
\DoxyCodeLine{2382   \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{'==== MOM\_neutral\_diffusion: ndiff\_unit\_tests\_discontinuous ='}}
\DoxyCodeLine{2383 }
\DoxyCodeLine{2384   \textcolor{comment}{! Unit tests for find\_neutral\_surface\_positions\_discontinuous}}
\DoxyCodeLine{2385   \textcolor{comment}{! Salinity is 0 for all these tests}}
\DoxyCodeLine{2386   \textcolor{keyword}{allocate}(cs\%EOS)}
\DoxyCodeLine{2387   \textcolor{keyword}{call }eos\_manual\_init(cs\%EOS, form\_of\_eos=eos\_linear, drho\_dt=-\/1., drho\_ds=0.)}
\DoxyCodeLine{2388   sl(:) = 0. ; sr(:) = 0. ; ; sil(:,:) = 0. ; sir(:,:) = 0.}
\DoxyCodeLine{2389   ppoly\_t\_l(:,:) = 0.; ppoly\_t\_r(:,:) = 0.}
\DoxyCodeLine{2390   ppoly\_s\_l(:,:) = 0.; ppoly\_s\_r(:,:) = 0.}
\DoxyCodeLine{2391   \textcolor{comment}{! Intialize any control structures needed for unit tests}}
\DoxyCodeLine{2392   cs\%ref\_pres = -\/1.}
\DoxyCodeLine{2393 }
\DoxyCodeLine{2394   hl = (/10.,10.,10./) ; hr = (/10.,10.,10./)}
\DoxyCodeLine{2395   pres\_l(1,1) = 0. ; pres\_l(1,2) = hl(1) ; pres\_r(1,1) = 0. ; pres\_r(1,2) = hr(1)}
\DoxyCodeLine{2396   \textcolor{keywordflow}{do} k = 2,nk}
\DoxyCodeLine{2397     pres\_l(k,1) = pres\_l(k-\/1,2)}
\DoxyCodeLine{2398     pres\_l(k,2) = pres\_l(k,1) + hl(k)}
\DoxyCodeLine{2399     pres\_r(k,1) = pres\_r(k-\/1,2)}
\DoxyCodeLine{2400     pres\_r(k,2) = pres\_r(k,1) + hr(k)}
\DoxyCodeLine{2401 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2402   cs\%delta\_rho\_form = \textcolor{stringliteral}{'mid\_pressure'}}
\DoxyCodeLine{2403   cs\%neutral\_pos\_method = 1}
\DoxyCodeLine{2404 }
\DoxyCodeLine{2405   til(1,:) = (/ 22.00, 18.00 /); til(2,:) = (/ 18.00, 14.00 /); til(3,:) = (/ 14.00, 10.00 /);}
\DoxyCodeLine{2406   tir(1,:) = (/ 22.00, 18.00 /); tir(2,:) = (/ 18.00, 14.00 /); tir(3,:) = (/ 14.00, 10.00 /);}
\DoxyCodeLine{2407   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2408   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2409   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2410            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2411   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2412     (/ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2413     (/ 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2414     (/ 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2415     (/ 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2416     (/ 0.00, 10.00, 0.00, 0.00, 0.00, 10.00, 0.00, 0.00, 0.00, 10.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2417     \textcolor{stringliteral}{'Identical Columns'})}
\DoxyCodeLine{2418 }
\DoxyCodeLine{2419   til(1,:) = (/ 22.00, 18.00 /); til(2,:) = (/ 18.00, 14.00 /); til(3,:) = (/ 14.00, 10.00 /);}
\DoxyCodeLine{2420   tir(1,:) = (/ 20.00, 16.00 /); tir(2,:) = (/ 16.00, 12.00 /); tir(3,:) = (/ 12.00, 8.00 /);}
\DoxyCodeLine{2421   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2422   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2423   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2424            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2425   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2426     (/ 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2427     (/ 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2428     (/ 0.00, 0.50, 1.00, 0.00, 0.50, 0.50, 1.00, 0.00, 0.50, 0.50, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2429     (/ 0.00, 0.00, 0.50, 0.50, 1.00, 0.00, 0.50, 0.50, 1.00, 0.00, 0.50, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2430     (/ 0.00, 5.00, 0.00, 5.00, 0.00, 5.00, 0.00, 5.00, 0.00, 5.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2431     \textcolor{stringliteral}{'Right slightly cooler'})}
\DoxyCodeLine{2432 }
\DoxyCodeLine{2433   til(1,:) = (/ 20.00, 16.00 /); til(2,:) = (/ 16.00, 12.00 /); til(3,:) = (/ 12.00, 8.00 /);}
\DoxyCodeLine{2434   tir(1,:) = (/ 22.00, 18.00 /); tir(2,:) = (/ 18.00, 14.00 /); tir(3,:) = (/ 14.00, 10.00 /);}
\DoxyCodeLine{2435   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2436   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2437   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2438            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2439   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2440     (/ 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2441     (/ 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2442     (/ 0.00, 0.00, 0.50, 0.50, 1.00, 0.00, 0.50, 0.50, 1.00, 0.00, 0.50, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2443     (/ 0.00, 0.50, 1.00, 0.00, 0.50, 0.50, 1.00, 0.00, 0.50, 0.50, 1.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2444     (/ 0.00, 5.00, 0.00, 5.00, 0.00, 5.00, 0.00, 5.00, 0.00, 5.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2445     \textcolor{stringliteral}{'Left slightly cooler'})}
\DoxyCodeLine{2446 }
\DoxyCodeLine{2447   til(1,:) = (/ 22.00, 20.00 /); til(2,:) = (/ 18.00, 16.00 /); til(3,:) = (/ 14.00, 12.00 /);}
\DoxyCodeLine{2448   tir(1,:) = (/ 32.00, 24.00 /); tir(2,:) = (/ 22.00, 14.00 /); tir(3,:) = (/ 12.00, 4.00 /);}
\DoxyCodeLine{2449   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2450   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2451   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2452            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2453   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2454     (/ 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2455     (/ 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2456     (/ 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 1.00, 0.00, 0.00, 1.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2457     (/ 0.00, 1.00, 0.00, 0.00, 0.25, 0.50, 0.75, 1.00, 0.00, 0.00, 0.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2458     (/ 0.00, 0.00, 0.00, 4.00, 0.00, 4.00, 0.00, 0.00, 0.00, 0.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2459     \textcolor{stringliteral}{'Right more strongly stratified'})}
\DoxyCodeLine{2460 }
\DoxyCodeLine{2461   til(1,:) = (/ 22.00, 18.00 /); til(2,:) = (/ 18.00, 14.00 /); til(3,:) = (/ 14.00, 10.00 /);}
\DoxyCodeLine{2462   tir(1,:) = (/ 14.00, 14.00 /); tir(2,:) = (/ 14.00, 14.00 /); tir(3,:) = (/ 12.00, 8.00 /);}
\DoxyCodeLine{2463   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2464   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2465   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2466            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2467   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2468     (/ 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2469     (/ 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2470     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 1.00, 0.00, 0.50, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2471     (/ 0.00, 1.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.50, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2472     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 5.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2473     \textcolor{stringliteral}{'Deep Mixed layer on the right'})}
\DoxyCodeLine{2474 }
\DoxyCodeLine{2475   til(1,:) = (/ 14.00, 14.00 /); til(2,:) = (/ 14.00, 12.00 /); til(3,:) = (/ 10.00, 8.00 /);}
\DoxyCodeLine{2476   tir(1,:) = (/ 14.00, 14.00 /); tir(2,:) = (/ 14.00, 14.00 /); tir(3,:) = (/ 14.00, 14.00 /);}
\DoxyCodeLine{2477   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2478   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2479   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2480            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2481   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2482     (/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2483     (/ 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2484     (/ 0.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2485     (/ 0.00, 0.00, 0.00, 1.00, 0.00, 1.00, 0.00, 1.00, 1.00, 1.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2486     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2487     \textcolor{stringliteral}{'Right unstratified column'})}
\DoxyCodeLine{2488 }
\DoxyCodeLine{2489   til(1,:) = (/ 14.00, 14.00 /); til(2,:) = (/ 14.00, 12.00 /); til(3,:) = (/ 10.00, 8.00 /);}
\DoxyCodeLine{2490   tir(1,:) = (/ 14.00, 14.00 /); tir(2,:) = (/ 14.00, 14.00 /); tir(3,:) = (/ 12.00, 4.00 /);}
\DoxyCodeLine{2491   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2492   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2493   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2494            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2495   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2496     (/ 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2497     (/ 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2498     (/ 0.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2499     (/ 0.00, 0.00, 0.00, 1.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.25, 0.50, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2500     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2501     \textcolor{stringliteral}{'Right unstratified column'})}
\DoxyCodeLine{2502 }
\DoxyCodeLine{2503   til(1,:) = (/ 14.00, 14.00 /); til(2,:) = (/ 14.00, 10.00 /); til(3,:) = (/ 10.00, 2.00 /);}
\DoxyCodeLine{2504   tir(1,:) = (/ 14.00, 14.00 /); tir(2,:) = (/ 14.00, 10.00 /); tir(3,:) = (/ 10.00, 2.00 /);}
\DoxyCodeLine{2505   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2506   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2507   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2508            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2509   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2510     (/ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2511     (/ 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2512     (/ 0.00, 1.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2513     (/ 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2514     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 10.00, 0.00, 0.00, 0.00, 10.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2515     \textcolor{stringliteral}{'Identical columns with mixed layer'})}
\DoxyCodeLine{2516 }
\DoxyCodeLine{2517   til(1,:) = (/ 14.00, 12.00 /); til(2,:) = (/ 10.00, 10.00 /); til(3,:) = (/ 8.00, 2.00 /);}
\DoxyCodeLine{2518   tir(1,:) = (/ 14.00, 12.00 /); tir(2,:) = (/ 12.00, 8.00 /); tir(3,:) = (/ 8.00, 2.00 /);}
\DoxyCodeLine{2519   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2520   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2521   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2522            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2523   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2524     (/ 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2525     (/ 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2526     (/ 0.00, 0.00, 1.00, 1.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2527     (/ 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 1.00, 1.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2528     (/ 0.00, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 10.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2529     \textcolor{stringliteral}{'Left interior unstratified'})}
\DoxyCodeLine{2530 }
\DoxyCodeLine{2531   til(1,:) = (/ 12.00, 12.00 /); til(2,:) = (/ 12.00, 10.00 /); til(3,:) = (/ 10.00, 6.00 /);}
\DoxyCodeLine{2532   tir(1,:) = (/ 12.00, 10.00 /); tir(2,:) = (/ 10.00, 12.00 /); tir(3,:) = (/ 8.00, 4.00 /);}
\DoxyCodeLine{2533   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2534   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2535   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2536            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2537   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2538     (/ 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2539     (/ 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2540     (/ 0.00, 1.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.50, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2541     (/ 0.00, 0.00, 0.00, 0.00, 1.00, 1.00, 0.00, 1.00, 0.00, 0.00, 0.50, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2542     (/ 0.00, 0.00, 0.00, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 5.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2543     \textcolor{stringliteral}{'Left mixed layer, Right unstable interior'})}
\DoxyCodeLine{2544 }
\DoxyCodeLine{2545   til(1,:) = (/ 14.00, 14.00 /); til(2,:) = (/ 10.00, 10.00 /); til(3,:) = (/ 8.00, 6.00 /);}
\DoxyCodeLine{2546   tir(1,:) = (/ 10.00, 14.00 /); tir(2,:) = (/ 16.00, 16.00 /); tir(3,:) = (/ 12.00, 4.00 /);}
\DoxyCodeLine{2547   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2548   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2549   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2550            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2551   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2552     (/ 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2553     (/ 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2554     (/ 0.00, 1.00, 0.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2555     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 1.00, 0.00, 0.50, 0.75, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2556     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2557     \textcolor{stringliteral}{'Left thick mixed layer, Right unstable mixed'})}
\DoxyCodeLine{2558 }
\DoxyCodeLine{2559   til(1,:) = (/ 8.00, 12.00 /); til(2,:) = (/ 12.00, 10.00 /); til(3,:) = (/ 8.00, 4.00 /);}
\DoxyCodeLine{2560   tir(1,:) = (/ 10.00, 14.00 /); tir(2,:) = (/ 14.00, 12.00 /); tir(3,:) = (/ 10.00, 6.00 /);}
\DoxyCodeLine{2561   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, til, sil, pres\_l, stable\_l )}
\DoxyCodeLine{2562   \textcolor{keyword}{call }mark\_unstable\_cells( cs, nk, tir, sir, pres\_r, stable\_r )}
\DoxyCodeLine{2563   \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, nk, pres\_l, hl, til, sil, ppoly\_t\_l, ppoly\_s\_l, stable\_l, \&}
\DoxyCodeLine{2564            pres\_r, hr, tir, sir, ppoly\_t\_r, ppoly\_s\_r, stable\_r, pol, por, kol, kor, heff)}
\DoxyCodeLine{2565   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or.  test\_nsp(v, 12, kol, kor, pol, por, heff, \&}
\DoxyCodeLine{2566     (/ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoL}}
\DoxyCodeLine{2567     (/ 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3 /),  \& \textcolor{comment}{! KoR}}
\DoxyCodeLine{2568     (/ 0.00, 1.00, 1.00, 1.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.50, 1.00 /),  \& \textcolor{comment}{! PoL}}
\DoxyCodeLine{2569     (/ 0.00, 0.00, 0.00, 1.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.50, 1.00, 1.00 /),  \& \textcolor{comment}{! PoR}}
\DoxyCodeLine{2570     (/ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 5.00, 0.00 /),  \& \textcolor{comment}{! hEff}}
\DoxyCodeLine{2571     \textcolor{stringliteral}{'Unstable mixed layers, left cooler'})}
\DoxyCodeLine{2572 }
\DoxyCodeLine{2573   \textcolor{keyword}{call }eos\_manual\_init(cs\%EOS, form\_of\_eos = eos\_linear, drho\_dt = -\/1., drho\_ds = 2.)}
\DoxyCodeLine{2574   \textcolor{comment}{! Tests for linearized version of searching the layer for neutral surface position}}
\DoxyCodeLine{2575   \textcolor{comment}{! EOS linear in T, uniform alpha}}
\DoxyCodeLine{2576   cs\%max\_iter = 10}
\DoxyCodeLine{2577   \textcolor{comment}{! Unit tests require explicit initialization of tolerance}}
\DoxyCodeLine{2578   cs\%Drho\_tol = 0.}
\DoxyCodeLine{2579   cs\%x\_tol = 0.}
\DoxyCodeLine{2580   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or. (test\_rnp(0.5, \&}
\DoxyCodeLine{2581              find\_neutral\_pos\_linear(cs, 0., 10., 35., -\/0.2, 0., \&}
\DoxyCodeLine{2582                                      -\/0.2, 0., -\/0.2, 0.,                     \&}
\DoxyCodeLine{2583                                      (/12.,-\/4./), (/34.,0./)), \textcolor{stringliteral}{"{}Temp Uniform Linearized Alpha/Beta"{}}))}
\DoxyCodeLine{2584   \textcolor{comment}{! EOS linear in S, uniform beta}}
\DoxyCodeLine{2585   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or. (test\_rnp(0.5, \&}
\DoxyCodeLine{2586              find\_neutral\_pos\_linear(cs, 0., 10., 35., 0., 0.8, \&}
\DoxyCodeLine{2587                                      0., 0.8, 0., 0.8,                \&}
\DoxyCodeLine{2588                                     (/12.,0./), (/34.,2./)), \textcolor{stringliteral}{"{}Salt Uniform Linearized Alpha/Beta"{}}))}
\DoxyCodeLine{2589   \textcolor{comment}{! EOS linear in T/S, uniform alpha/beta}}
\DoxyCodeLine{2590   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or. (test\_rnp(0.5,   \&}
\DoxyCodeLine{2591              find\_neutral\_pos\_linear(cs, 0., 10., 35., -\/0.5, 0.5,                \&}
\DoxyCodeLine{2592                                      -\/0.5, 0.5, -\/0.5, 0.5,  \&}
\DoxyCodeLine{2593                                      (/12.,-\/4./), (/34.,2./)), \textcolor{stringliteral}{"{}Temp/salt Uniform Linearized Alpha/Beta"{}}))}
\DoxyCodeLine{2594   \textcolor{comment}{! EOS linear in T, insensitive to So}}
\DoxyCodeLine{2595   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or. (test\_rnp(0.5, \&}
\DoxyCodeLine{2596              find\_neutral\_pos\_linear(cs, 0., 10., 35., -\/0.2, 0., \&}
\DoxyCodeLine{2597                                      -\/0.4, 0., -\/0.6, 0.,  \&}
\DoxyCodeLine{2598                                      (/12.,-\/4./), (/34.,0./)), \textcolor{stringliteral}{"{}Temp stratified Linearized Alpha/Beta"{}}))}
\DoxyCodeLine{2599   \textcolor{comment}{! EOS linear in S, insensitive to T}}
\DoxyCodeLine{2600   ndiff\_unit\_tests\_discontinuous = ndiff\_unit\_tests\_discontinuous .or. (test\_rnp(0.5, \&}
\DoxyCodeLine{2601              find\_neutral\_pos\_linear(cs, 0., 10., 35., 0., 0.8,  \&}
\DoxyCodeLine{2602                                       0., 1.0,  0., 0.5,  \&}
\DoxyCodeLine{2603                                      (/12.,0./), (/34.,2./)), \textcolor{stringliteral}{"{}Salt stratified Linearized Alpha/Beta"{}}))}
\DoxyCodeLine{2604   \textcolor{keywordflow}{if} (.not. ndiff\_unit\_tests\_discontinuous) \textcolor{keyword}{write}(stdout,*) \textcolor{stringliteral}{'Pass'}}
\DoxyCodeLine{2605 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a5469b7be43f8c428f092b58dd5ca41c8}\label{namespacemom__neutral__diffusion_a5469b7be43f8c428f092b58dd5ca41c8}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_diffusion@{neutral\_diffusion}}
\index{neutral\_diffusion@{neutral\_diffusion}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_diffusion()}{neutral\_diffusion()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+diffusion (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{Coef\+\_\+x,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{Coef\+\_\+y,  }\item[{real, intent(in)}]{dt,  }\item[{type(\mbox{\hyperlink{structmom__tracer__registry_1_1tracer__registry__type}{tracer\+\_\+registry\+\_\+type}}), pointer}]{Reg,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Update tracer concentration due to neutral diffusion; layer thickness unchanged by this update. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em coef\+\_\+x} & dt $\ast$ Kh $\ast$ dy / dx at u-\/points \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em coef\+\_\+y} & dt $\ast$ Kh $\ast$ dx / dy at v-\/points \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Tracer time step $\ast$ I\+\_\+numitts \mbox{[}T $\sim$$>$ s\mbox{]} (I\+\_\+numitts in tracer\+\_\+hordiff) \\
\hline
 & {\em reg} & Tracer registry \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & Neutral diffusion control structure \\
\hline
\end{DoxyParams}


Definition at line 529 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{530   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< Ocean grid structure}}
\DoxyCodeLine{531   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< ocean vertical grid structure}}
\DoxyCodeLine{532 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{533 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},         \textcolor{keywordtype}{intent(in)}    :: Coef\_x\textcolor{comment}{ !< dt * Kh * dy / dx at u-\/points [L2 \string~> m2]}}
\DoxyCodeLine{534 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(in)}    :: Coef\_y\textcolor{comment}{ !< dt * Kh * dx / dy at v-\/points [L2 \string~> m2]}}
\DoxyCodeLine{535 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Tracer time step * I\_numitts [T \string~> s]}}
\DoxyCodeLine{536 \textcolor{comment}{                                                                     !! (I\_numitts in tracer\_hordiff)}}
\DoxyCodeLine{537   \textcolor{keywordtype}{type}(tracer\_registry\_type),                \textcolor{keywordtype}{pointer}       :: Reg\textcolor{comment}{    !< Tracer registry}}
\DoxyCodeLine{538   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{539   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS),                \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Neutral diffusion control structure}}
\DoxyCodeLine{540 }
\DoxyCodeLine{541   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{542 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),CS\%nsurf-\/1)} :: uFlx        \textcolor{comment}{! Zonal flux of tracer [H conc \string~> m conc or conc kg m-\/2]}}
\DoxyCodeLine{543 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),CS\%nsurf-\/1)} :: vFlx        \textcolor{comment}{! Meridional flux of tracer}}
\DoxyCodeLine{544                                                               \textcolor{comment}{! [H conc \string~> m conc or conc kg m-\/2]}}
\DoxyCodeLine{545 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),G\%ke)}        :: tendency    \textcolor{comment}{! tendency array for diagn}}
\DoxyCodeLine{546 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}             :: tendency\_2d \textcolor{comment}{! depth integrated content tendency for diagn}}
\DoxyCodeLine{547 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}            :: trans\_x\_2d  \textcolor{comment}{! depth integrated diffusive tracer x-\/transport diagn}}
\DoxyCodeLine{548 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}            :: trans\_y\_2d  \textcolor{comment}{! depth integrated diffusive tracer y-\/transport diagn}}
\DoxyCodeLine{549 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%ke)}                        :: dTracer     \textcolor{comment}{! change in tracer concentration due to ndiffusion}}
\DoxyCodeLine{550 }
\DoxyCodeLine{551   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{pointer}                   :: Tracer => null() \textcolor{comment}{! Pointer to the current tracer}}
\DoxyCodeLine{552 }
\DoxyCodeLine{553   \textcolor{keywordtype}{integer} :: i, j, k, m, ks, nk}
\DoxyCodeLine{554 \textcolor{keywordtype}{  real} :: Idt  \textcolor{comment}{! The inverse of the time step [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{555 \textcolor{keywordtype}{  real} :: h\_neglect, h\_neglect\_edge}
\DoxyCodeLine{556 }
\DoxyCodeLine{557   \textcolor{keywordflow}{if} (.not.cs\%remap\_answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{558     h\_neglect = gv\%H\_subroundoff ; h\_neglect\_edge = gv\%H\_subroundoff}
\DoxyCodeLine{559   \textcolor{keywordflow}{else}}
\DoxyCodeLine{560     h\_neglect = gv\%m\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%m\_to\_H*1.0e-\/10}
\DoxyCodeLine{561 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{562 }
\DoxyCodeLine{563   nk = gv\%ke}
\DoxyCodeLine{564 }
\DoxyCodeLine{565   \textcolor{keywordflow}{do} m = 1,reg\%ntr \textcolor{comment}{! Loop over tracer registry}}
\DoxyCodeLine{566 }
\DoxyCodeLine{567     tracer => reg\%Tr(m)}
\DoxyCodeLine{568 }
\DoxyCodeLine{569     \textcolor{comment}{! for diagnostics}}
\DoxyCodeLine{570     \textcolor{keywordflow}{if} (tracer\%id\_dfxy\_conc > 0 .or. tracer\%id\_dfxy\_cont > 0 .or. tracer\%id\_dfxy\_cont\_2d > 0 .or. \&}
\DoxyCodeLine{571         tracer\%id\_dfx\_2d > 0 .or. tracer\%id\_dfy\_2d > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{572       idt = 1.0 / dt}
\DoxyCodeLine{573       tendency(:,:,:)  = 0.0}
\DoxyCodeLine{574 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{575 }
\DoxyCodeLine{576     uflx(:,:,:) = 0.}
\DoxyCodeLine{577     vflx(:,:,:) = 0.}
\DoxyCodeLine{578 }
\DoxyCodeLine{579     \textcolor{comment}{! x-\/flux}}
\DoxyCodeLine{580     \textcolor{keywordflow}{do} j = g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec}
\DoxyCodeLine{581       \textcolor{keywordflow}{if} (g\%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{582         \textcolor{keyword}{call }neutral\_surface\_flux(nk, cs\%nsurf, cs\%deg, h(i,j,:), h(i+1,j,:),       \&}
\DoxyCodeLine{583                                   tracer\%t(i,j,:), tracer\%t(i+1,j,:), \&}
\DoxyCodeLine{584                                   cs\%uPoL(i,j,:), cs\%uPoR(i,j,:), \&}
\DoxyCodeLine{585                                   cs\%uKoL(i,j,:), cs\%uKoR(i,j,:), \&}
\DoxyCodeLine{586                                   cs\%uhEff(i,j,:), uflx(i,j,:), \&}
\DoxyCodeLine{587                                   cs\%continuous\_reconstruction, h\_neglect, cs\%remap\_CS, h\_neglect\_edge)}
\DoxyCodeLine{588 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{589 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{590 }
\DoxyCodeLine{591     \textcolor{comment}{! y-\/flux}}
\DoxyCodeLine{592     \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc,g\%iec}
\DoxyCodeLine{593       \textcolor{keywordflow}{if} (g\%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{594         \textcolor{keyword}{call }neutral\_surface\_flux(nk, cs\%nsurf, cs\%deg, h(i,j,:), h(i,j+1,:),       \&}
\DoxyCodeLine{595                                   tracer\%t(i,j,:), tracer\%t(i,j+1,:), \&}
\DoxyCodeLine{596                                   cs\%vPoL(i,j,:), cs\%vPoR(i,j,:), \&}
\DoxyCodeLine{597                                   cs\%vKoL(i,j,:), cs\%vKoR(i,j,:), \&}
\DoxyCodeLine{598                                   cs\%vhEff(i,j,:), vflx(i,j,:),   \&}
\DoxyCodeLine{599                                   cs\%continuous\_reconstruction, h\_neglect, cs\%remap\_CS, h\_neglect\_edge)}
\DoxyCodeLine{600 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{601 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{602 }
\DoxyCodeLine{603     \textcolor{comment}{! Update the tracer concentration from divergence of neutral diffusive flux components}}
\DoxyCodeLine{604     \textcolor{keywordflow}{do} j = g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc,g\%iec}
\DoxyCodeLine{605       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{606 }
\DoxyCodeLine{607         dtracer(:) = 0.}
\DoxyCodeLine{608         \textcolor{keywordflow}{do} ks = 1,cs\%nsurf-\/1}
\DoxyCodeLine{609           k = cs\%uKoL(i,j,ks)}
\DoxyCodeLine{610           dtracer(k) = dtracer(k) + coef\_x(i,j)   * uflx(i,j,ks)}
\DoxyCodeLine{611           k = cs\%uKoR(i-\/1,j,ks)}
\DoxyCodeLine{612           dtracer(k) = dtracer(k) -\/ coef\_x(i-\/1,j) * uflx(i-\/1,j,ks)}
\DoxyCodeLine{613           k = cs\%vKoL(i,j,ks)}
\DoxyCodeLine{614           dtracer(k) = dtracer(k) + coef\_y(i,j)   * vflx(i,j,ks)}
\DoxyCodeLine{615           k = cs\%vKoR(i,j-\/1,ks)}
\DoxyCodeLine{616           dtracer(k) = dtracer(k) -\/ coef\_y(i,j-\/1) * vflx(i,j-\/1,ks)}
\DoxyCodeLine{617 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{618         \textcolor{keywordflow}{do} k = 1, gv\%ke}
\DoxyCodeLine{619           tracer\%t(i,j,k) = tracer\%t(i,j,k) + dtracer(k) * \&}
\DoxyCodeLine{620                           ( g\%IareaT(i,j) / ( h(i,j,k) + gv\%H\_subroundoff ) )}
\DoxyCodeLine{621 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{622 }
\DoxyCodeLine{623         \textcolor{keywordflow}{if} (tracer\%id\_dfxy\_conc > 0  .or. tracer\%id\_dfxy\_cont > 0 .or. tracer\%id\_dfxy\_cont\_2d > 0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{624           \textcolor{keywordflow}{do} k = 1, gv\%ke}
\DoxyCodeLine{625             tendency(i,j,k) = dtracer(k) * g\%IareaT(i,j) * idt}
\DoxyCodeLine{626 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{627 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{628 }
\DoxyCodeLine{629 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{630 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{631 }
\DoxyCodeLine{632     \textcolor{comment}{! Diagnose vertically summed zonal flux, giving zonal tracer transport from ndiff.}}
\DoxyCodeLine{633     \textcolor{comment}{! Note sign corresponds to downgradient flux convention.}}
\DoxyCodeLine{634     \textcolor{keywordflow}{if} (tracer\%id\_dfx\_2d > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{635       \textcolor{keywordflow}{do} j = g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec}
\DoxyCodeLine{636         trans\_x\_2d(i,j) = 0.}
\DoxyCodeLine{637         \textcolor{keywordflow}{if} (g\%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{638           \textcolor{keywordflow}{do} ks = 1,cs\%nsurf-\/1}
\DoxyCodeLine{639             trans\_x\_2d(i,j) = trans\_x\_2d(i,j) -\/ coef\_x(i,j) * uflx(i,j,ks)}
\DoxyCodeLine{640 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{641           trans\_x\_2d(i,j) = trans\_x\_2d(i,j) * idt}
\DoxyCodeLine{642 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{643 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{644       \textcolor{keyword}{call }post\_data(tracer\%id\_dfx\_2d, trans\_x\_2d(:,:), cs\%diag)}
\DoxyCodeLine{645 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{646 }
\DoxyCodeLine{647     \textcolor{comment}{! Diagnose vertically summed merid flux, giving meridional tracer transport from ndiff.}}
\DoxyCodeLine{648     \textcolor{comment}{! Note sign corresponds to downgradient flux convention.}}
\DoxyCodeLine{649     \textcolor{keywordflow}{if} (tracer\%id\_dfy\_2d > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{650       \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc,g\%iec}
\DoxyCodeLine{651         trans\_y\_2d(i,j) = 0.}
\DoxyCodeLine{652         \textcolor{keywordflow}{if} (g\%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{653           \textcolor{keywordflow}{do} ks = 1,cs\%nsurf-\/1}
\DoxyCodeLine{654             trans\_y\_2d(i,j) = trans\_y\_2d(i,j) -\/ coef\_y(i,j) * vflx(i,j,ks)}
\DoxyCodeLine{655 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{656           trans\_y\_2d(i,j) = trans\_y\_2d(i,j) * idt}
\DoxyCodeLine{657 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{658 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{659       \textcolor{keyword}{call }post\_data(tracer\%id\_dfy\_2d, trans\_y\_2d(:,:), cs\%diag)}
\DoxyCodeLine{660 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{661 }
\DoxyCodeLine{662     \textcolor{comment}{! post tendency of tracer content}}
\DoxyCodeLine{663     \textcolor{keywordflow}{if} (tracer\%id\_dfxy\_cont > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{664       \textcolor{keyword}{call }post\_data(tracer\%id\_dfxy\_cont, tendency(:,:,:), cs\%diag)}
\DoxyCodeLine{665 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{666 }
\DoxyCodeLine{667     \textcolor{comment}{! post depth summed tendency for tracer content}}
\DoxyCodeLine{668     \textcolor{keywordflow}{if} (tracer\%id\_dfxy\_cont\_2d > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{669       tendency\_2d(:,:) = 0.}
\DoxyCodeLine{670       \textcolor{keywordflow}{do} j = g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc,g\%iec}
\DoxyCodeLine{671         \textcolor{keywordflow}{do} k = 1, gv\%ke}
\DoxyCodeLine{672           tendency\_2d(i,j) = tendency\_2d(i,j) + tendency(i,j,k)}
\DoxyCodeLine{673 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{674 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{675       \textcolor{keyword}{call }post\_data(tracer\%id\_dfxy\_cont\_2d, tendency\_2d(:,:), cs\%diag)}
\DoxyCodeLine{676 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{677 }
\DoxyCodeLine{678     \textcolor{comment}{! post tendency of tracer concentration; this step must be}}
\DoxyCodeLine{679     \textcolor{comment}{! done after posting tracer content tendency, since we alter}}
\DoxyCodeLine{680     \textcolor{comment}{! the tendency array.}}
\DoxyCodeLine{681     \textcolor{keywordflow}{if} (tracer\%id\_dfxy\_conc > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{682       \textcolor{keywordflow}{do} k = 1, gv\%ke ; \textcolor{keywordflow}{do} j = g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i = g\%isc,g\%iec}
\DoxyCodeLine{683         tendency(i,j,k) =  tendency(i,j,k) / ( h(i,j,k) + gv\%H\_subroundoff )}
\DoxyCodeLine{684 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{685       \textcolor{keyword}{call }post\_data(tracer\%id\_dfxy\_conc, tendency, cs\%diag)}
\DoxyCodeLine{686 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{687 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! Loop over tracer registry}}
\DoxyCodeLine{688 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_abc3fd398047ffb61825ceced9ae5ff41}\label{namespacemom__neutral__diffusion_abc3fd398047ffb61825ceced9ae5ff41}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_diffusion\_calc\_coeffs@{neutral\_diffusion\_calc\_coeffs}}
\index{neutral\_diffusion\_calc\_coeffs@{neutral\_diffusion\_calc\_coeffs}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_diffusion\_calc\_coeffs()}{neutral\_diffusion\_calc\_coeffs()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+diffusion\+\_\+calc\+\_\+coeffs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{S,  }\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{p\+\_\+surf }\end{DoxyParamCaption})}



Calculate remapping factors for u/v columns used to map adjoining columns to a shared coordinate space. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Potential temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
 & {\em cs} & Neutral diffusion control structure \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+surf} & Surface pressure to include in pressures used for equation of state calculations \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 283 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{284   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{   !< Ocean grid structure}}
\DoxyCodeLine{285   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{  !< ocean vertical grid structure}}
\DoxyCodeLine{286   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{287 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{   !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{288 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: T\textcolor{comment}{   !< Potential temperature [degC]}}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: S\textcolor{comment}{   !< Salinity [ppt]}}
\DoxyCodeLine{290   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS),               \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{  !< Neutral diffusion control structure}}
\DoxyCodeLine{291 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: p\_surf\textcolor{comment}{ !< Surface pressure to include in pressures used}}
\DoxyCodeLine{292 \textcolor{comment}{                                                              !! for equation of state calculations [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{293 }
\DoxyCodeLine{294   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{295   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{296   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{297   \textcolor{comment}{! Variables used for reconstructions}}
\DoxyCodeLine{298 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G),2)} :: ppoly\_r\_S       \textcolor{comment}{! Reconstruction slopes}}
\DoxyCodeLine{299 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: hEff\_sum \textcolor{comment}{! Summed effective face thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{300 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: hbl      \textcolor{comment}{! Boundary layer depth [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{301   \textcolor{keywordtype}{integer} :: iMethod}
\DoxyCodeLine{302 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: ref\_pres \textcolor{comment}{! Reference pressure used to calculate alpha/beta [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{303 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rho\_tmp  \textcolor{comment}{! Routine to calculate drho\_dp, returns density which is not used}}
\DoxyCodeLine{304 \textcolor{keywordtype}{  real} :: h\_neglect, h\_neglect\_edge    \textcolor{comment}{! Negligible thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{305   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: k\_top  \textcolor{comment}{! Index of the first layer within the boundary}}
\DoxyCodeLine{306 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: zeta\_top \textcolor{comment}{! Distance from the top of a layer to the intersection of the}}
\DoxyCodeLine{307                                                    \textcolor{comment}{! top extent of the boundary layer (0 at top, 1 at bottom) [nondim]}}
\DoxyCodeLine{308   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: k\_bot    \textcolor{comment}{! Index of the last layer within the boundary}}
\DoxyCodeLine{309 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: zeta\_bot \textcolor{comment}{! Distance of the lower layer to the boundary layer depth}}
\DoxyCodeLine{310 \textcolor{keywordtype}{  real} :: pa\_to\_H                      \textcolor{comment}{! A conversion factor from pressure to H units [H T2 R-\/1 Z-\/2 \string~> m Pa-\/1 or s2 m-\/2]}}
\DoxyCodeLine{311 }
\DoxyCodeLine{312   pa\_to\_h = 1. / (gv\%H\_to\_RZ * gv\%g\_Earth)}
\DoxyCodeLine{313 }
\DoxyCodeLine{314   k\_top(:,:) = 1     ; k\_bot(:,:) = 1}
\DoxyCodeLine{315   zeta\_top(:,:) = 0. ; zeta\_bot(:,:) = 0.}
\DoxyCodeLine{316 }
\DoxyCodeLine{317   \textcolor{comment}{! Check if hbl needs to be extracted}}
\DoxyCodeLine{318   \textcolor{keywordflow}{if} (cs\%interior\_only) \textcolor{keywordflow}{then}}
\DoxyCodeLine{319     hbl(:,:) = 0.}
\DoxyCodeLine{320     \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs\%KPP\_CSp)) \textcolor{keyword}{call }kpp\_get\_bld(cs\%KPP\_CSp, hbl, g, us, m\_to\_bld\_units=gv\%m\_to\_H)}
\DoxyCodeLine{321     \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs\%energetic\_PBL\_CSp)) \&}
\DoxyCodeLine{322       \textcolor{keyword}{call }energetic\_pbl\_get\_mld(cs\%energetic\_PBL\_CSp, hbl, g, us, m\_to\_mld\_units=gv\%m\_to\_H)}
\DoxyCodeLine{323     \textcolor{keyword}{call }pass\_var(hbl, g\%Domain)}
\DoxyCodeLine{324     \textcolor{comment}{! get k-\/indices and zeta}}
\DoxyCodeLine{325     \textcolor{keywordflow}{do} j=g\%jsc-\/1, g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{326       \textcolor{keyword}{call }boundary\_k\_range(surface, g\%ke, h(i,j,:), hbl(i,j), k\_top(i,j), zeta\_top(i,j), k\_bot(i,j), zeta\_bot(i,j))}
\DoxyCodeLine{327     enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{328     \textcolor{comment}{! TODO: add similar code for BOTTOM boundary layer}}
\DoxyCodeLine{329 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{330 }
\DoxyCodeLine{331   \textcolor{keywordflow}{if} (.not.cs\%remap\_answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{332     h\_neglect = gv\%H\_subroundoff ; h\_neglect\_edge = gv\%H\_subroundoff}
\DoxyCodeLine{333   \textcolor{keywordflow}{elseif} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{334     h\_neglect = gv\%m\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%m\_to\_H*1.0e-\/10}
\DoxyCodeLine{335   \textcolor{keywordflow}{else}}
\DoxyCodeLine{336     h\_neglect = gv\%kg\_m2\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%kg\_m2\_to\_H*1.0e-\/10}
\DoxyCodeLine{337 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{338 }
\DoxyCodeLine{339   \textcolor{comment}{! If doing along isopycnal diffusion (as opposed to neutral diffusion, set the reference pressure)}}
\DoxyCodeLine{340   \textcolor{keywordflow}{if} (cs\%ref\_pres>=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{341     ref\_pres(:) = cs\%ref\_pres}
\DoxyCodeLine{342 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{343 }
\DoxyCodeLine{344   \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{345     cs\%dRdT(:,:,:) = 0.}
\DoxyCodeLine{346     cs\%dRdS(:,:,:) = 0.}
\DoxyCodeLine{347   \textcolor{keywordflow}{else}}
\DoxyCodeLine{348     cs\%T\_i(:,:,:,:) = 0.}
\DoxyCodeLine{349     cs\%S\_i(:,:,:,:) = 0.}
\DoxyCodeLine{350     cs\%dRdT\_i(:,:,:,:) = 0.}
\DoxyCodeLine{351     cs\%dRdS\_i(:,:,:,:) = 0.}
\DoxyCodeLine{352     cs\%ns(:,:) = 0.}
\DoxyCodeLine{353     cs\%stable\_cell(:,:,:) = .true.}
\DoxyCodeLine{354 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{355 }
\DoxyCodeLine{356   \textcolor{comment}{! Calculate pressure at interfaces and layer averaged alpha/beta}}
\DoxyCodeLine{357   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(p\_surf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{358      \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{359        cs\%Pint(i,j,1) = p\_surf(i,j)}
\DoxyCodeLine{360 \textcolor{keywordflow}{     enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{361   \textcolor{keywordflow}{else}}
\DoxyCodeLine{362     cs\%Pint(:,:,1) = 0.}
\DoxyCodeLine{363 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{364   \textcolor{keywordflow}{do} k=1,g\%ke ; \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{365     cs\%Pint(i,j,k+1) = cs\%Pint(i,j,k) + h(i,j,k)*(gv\%g\_Earth*gv\%H\_to\_RZ)}
\DoxyCodeLine{366 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{367 }
\DoxyCodeLine{368   \textcolor{comment}{! Pressures at the interfaces, this is redundant as P\_i(k,1) = P\_i(k-\/1,2) however retain this}}
\DoxyCodeLine{369   \textcolor{comment}{! for now to ensure consitency of indexing for diiscontinuous reconstructions}}
\DoxyCodeLine{370   \textcolor{keywordflow}{if} (.not. cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{371     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(p\_surf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{372       \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{373         cs\%P\_i(i,j,1,1) = p\_surf(i,j)}
\DoxyCodeLine{374         cs\%P\_i(i,j,1,2) = p\_surf(i,j) + h(i,j,1)*(gv\%H\_to\_RZ*gv\%g\_Earth)}
\DoxyCodeLine{375 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{376     \textcolor{keywordflow}{else}}
\DoxyCodeLine{377       \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{378         cs\%P\_i(i,j,1,1) = 0.}
\DoxyCodeLine{379         cs\%P\_i(i,j,1,2) = h(i,j,1)*(gv\%H\_to\_RZ*gv\%g\_Earth)}
\DoxyCodeLine{380 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{381 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{382     \textcolor{keywordflow}{do} k=2,g\%ke ; \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{383       cs\%P\_i(i,j,k,1) = cs\%P\_i(i,j,k-\/1,2)}
\DoxyCodeLine{384       cs\%P\_i(i,j,k,2) = cs\%P\_i(i,j,k-\/1,2) + h(i,j,k)*(gv\%H\_to\_RZ*gv\%g\_Earth)}
\DoxyCodeLine{385 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{386 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{387 }
\DoxyCodeLine{388   eosdom(:) = eos\_domain(g\%HI, halo=1)}
\DoxyCodeLine{389   \textcolor{keywordflow}{do} j = g\%jsc-\/1, g\%jec+1}
\DoxyCodeLine{390     \textcolor{comment}{! Interpolate state to interface}}
\DoxyCodeLine{391     \textcolor{keywordflow}{do} i = g\%isc-\/1, g\%iec+1}
\DoxyCodeLine{392       \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{393         \textcolor{keyword}{call }interface\_scalar(g\%ke, h(i,j,:), t(i,j,:), cs\%Tint(i,j,:), 2, h\_neglect)}
\DoxyCodeLine{394         \textcolor{keyword}{call }interface\_scalar(g\%ke, h(i,j,:), s(i,j,:), cs\%Sint(i,j,:), 2, h\_neglect)}
\DoxyCodeLine{395       \textcolor{keywordflow}{else}}
\DoxyCodeLine{396         \textcolor{keyword}{call }build\_reconstructions\_1d( cs\%remap\_CS, g\%ke, h(i,j,:), t(i,j,:), cs\%ppoly\_coeffs\_T(i,j,:,:), \&}
\DoxyCodeLine{397                                        cs\%T\_i(i,j,:,:), ppoly\_r\_s, imethod, h\_neglect, h\_neglect\_edge )}
\DoxyCodeLine{398         \textcolor{keyword}{call }build\_reconstructions\_1d( cs\%remap\_CS, g\%ke, h(i,j,:), s(i,j,:), cs\%ppoly\_coeffs\_S(i,j,:,:), \&}
\DoxyCodeLine{399                                        cs\%S\_i(i,j,:,:), ppoly\_r\_s, imethod, h\_neglect, h\_neglect\_edge )}
\DoxyCodeLine{400         \textcolor{comment}{! In the current ALE formulation, interface values are not exactly at the 0. or 1. of the}}
\DoxyCodeLine{401         \textcolor{comment}{! polynomial reconstructions}}
\DoxyCodeLine{402         \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{403            cs\%T\_i(i,j,k,1) = evaluation\_polynomial( cs\%ppoly\_coeffs\_T(i,j,k,:), cs\%deg+1, 0. )}
\DoxyCodeLine{404            cs\%T\_i(i,j,k,2) = evaluation\_polynomial( cs\%ppoly\_coeffs\_T(i,j,k,:), cs\%deg+1, 1. )}
\DoxyCodeLine{405            cs\%S\_i(i,j,k,1) = evaluation\_polynomial( cs\%ppoly\_coeffs\_S(i,j,k,:), cs\%deg+1, 0. )}
\DoxyCodeLine{406            cs\%S\_i(i,j,k,2) = evaluation\_polynomial( cs\%ppoly\_coeffs\_S(i,j,k,:), cs\%deg+1, 1. )}
\DoxyCodeLine{407 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{408 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{409 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{410 }
\DoxyCodeLine{411     \textcolor{comment}{! Continuous reconstruction}}
\DoxyCodeLine{412     \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{413       \textcolor{keywordflow}{do} k = 1, g\%ke+1}
\DoxyCodeLine{414         \textcolor{keywordflow}{if} (cs\%ref\_pres<0) ref\_pres(:) = cs\%Pint(:,j,k)}
\DoxyCodeLine{415         \textcolor{keyword}{call }calculate\_density\_derivs(cs\%Tint(:,j,k), cs\%Sint(:,j,k), ref\_pres, cs\%dRdT(:,j,k), \&}
\DoxyCodeLine{416                                       cs\%dRdS(:,j,k), cs\%EOS, eosdom)}
\DoxyCodeLine{417 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{418     \textcolor{keywordflow}{else} \textcolor{comment}{! Discontinuous reconstruction}}
\DoxyCodeLine{419       \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{420         \textcolor{keywordflow}{if} (cs\%ref\_pres<0) ref\_pres(:) = cs\%Pint(:,j,k)}
\DoxyCodeLine{421         \textcolor{comment}{! Calculate derivatives for the top interface}}
\DoxyCodeLine{422         \textcolor{keyword}{call }calculate\_density\_derivs(cs\%T\_i(:,j,k,1), cs\%S\_i(:,j,k,1), ref\_pres, cs\%dRdT\_i(:,j,k,1), \&}
\DoxyCodeLine{423                                       cs\%dRdS\_i(:,j,k,1), cs\%EOS, eosdom)}
\DoxyCodeLine{424         \textcolor{keywordflow}{if} (cs\%ref\_pres<0) ref\_pres(:) = cs\%Pint(:,j,k+1)}
\DoxyCodeLine{425         \textcolor{comment}{! Calculate derivatives at the bottom interface}}
\DoxyCodeLine{426         \textcolor{keyword}{call }calculate\_density\_derivs(cs\%T\_i(:,j,k,2), cs\%S\_i(:,j,k,2), ref\_pres, cs\%dRdT\_i(:,j,k,2), \&}
\DoxyCodeLine{427                                       cs\%dRdS\_i(:,j,k,2), cs\%EOS, eosdom)}
\DoxyCodeLine{428 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{429 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{430 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{431 }
\DoxyCodeLine{432   \textcolor{keywordflow}{if} (.not. cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{433     \textcolor{keywordflow}{do} j = g\%jsc-\/1, g\%jec+1 ; \textcolor{keywordflow}{do} i = g\%isc-\/1, g\%iec+1}
\DoxyCodeLine{434       \textcolor{keyword}{call }mark\_unstable\_cells( cs, g\%ke, cs\%T\_i(i,j,:,:), cs\%S\_i(i,j,:,:), cs\%P\_i(i,j,:,:), cs\%stable\_cell(i,j,:) )}
\DoxyCodeLine{435       \textcolor{keywordflow}{if} (cs\%interior\_only) \textcolor{keywordflow}{then}}
\DoxyCodeLine{436         \textcolor{keywordflow}{if} (.not. cs\%stable\_cell(i,j,k\_bot(i,j))) zeta\_bot(i,j) = -\/1.}
\DoxyCodeLine{437         \textcolor{comment}{! set values in the surface and bottom boundary layer to false.}}
\DoxyCodeLine{438         \textcolor{keywordflow}{do} k = 1, k\_bot(i,j)-\/1}
\DoxyCodeLine{439           cs\%stable\_cell(i,j,k) = .false.}
\DoxyCodeLine{440 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{441 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{442 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{443 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{444 }
\DoxyCodeLine{445   cs\%uhEff(:,:,:) = 0.}
\DoxyCodeLine{446   cs\%vhEff(:,:,:) = 0.}
\DoxyCodeLine{447   cs\%uPoL(:,:,:) = 0.}
\DoxyCodeLine{448   cs\%vPoL(:,:,:) = 0.}
\DoxyCodeLine{449   cs\%uPoR(:,:,:) = 0.}
\DoxyCodeLine{450   cs\%vPoR(:,:,:) = 0.}
\DoxyCodeLine{451   cs\%uKoL(:,:,:) = 1}
\DoxyCodeLine{452   cs\%vKoL(:,:,:) = 1}
\DoxyCodeLine{453   cs\%uKoR(:,:,:) = 1}
\DoxyCodeLine{454   cs\%vKoR(:,:,:) = 1}
\DoxyCodeLine{455 }
\DoxyCodeLine{456   \textcolor{comment}{! Neutral surface factors at U points}}
\DoxyCodeLine{457   \textcolor{keywordflow}{do} j = g\%jsc, g\%jec ; \textcolor{keywordflow}{do} i = g\%isc-\/1, g\%iec}
\DoxyCodeLine{458     \textcolor{keywordflow}{if} (g\%mask2dCu(i,j) > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{459       \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{460         \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(g\%ke,                                    \&}
\DoxyCodeLine{461                 cs\%Pint(i,j,:), cs\%Tint(i,j,:), cs\%Sint(i,j,:), cs\%dRdT(i,j,:), cs\%dRdS(i,j,:),            \&}
\DoxyCodeLine{462                 cs\%Pint(i+1,j,:), cs\%Tint(i+1,j,:), cs\%Sint(i+1,j,:), cs\%dRdT(i+1,j,:), cs\%dRdS(i+1,j,:),  \&}
\DoxyCodeLine{463                 cs\%uPoL(i,j,:), cs\%uPoR(i,j,:), cs\%uKoL(i,j,:), cs\%uKoR(i,j,:), cs\%uhEff(i,j,:),           \&}
\DoxyCodeLine{464                 k\_bot(i,j), k\_bot(i+1,j), zeta\_bot(i,j), zeta\_bot(i+1,j))}
\DoxyCodeLine{465       \textcolor{keywordflow}{else}}
\DoxyCodeLine{466         \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, g\%ke, \&}
\DoxyCodeLine{467             cs\%P\_i(i,j,:,:), h(i,j,:), cs\%T\_i(i,j,:,:), cs\%S\_i(i,j,:,:), cs\%ppoly\_coeffs\_T(i,j,:,:),           \&}
\DoxyCodeLine{468             cs\%ppoly\_coeffs\_S(i,j,:,:),cs\%stable\_cell(i,j,:),                                                  \&}
\DoxyCodeLine{469             cs\%P\_i(i+1,j,:,:), h(i+1,j,:), cs\%T\_i(i+1,j,:,:), cs\%S\_i(i+1,j,:,:), cs\%ppoly\_coeffs\_T(i+1,j,:,:), \&}
\DoxyCodeLine{470             cs\%ppoly\_coeffs\_S(i+1,j,:,:), cs\%stable\_cell(i+1,j,:),                                             \&}
\DoxyCodeLine{471             cs\%uPoL(i,j,:), cs\%uPoR(i,j,:), cs\%uKoL(i,j,:), cs\%uKoR(i,j,:), cs\%uhEff(i,j,:),                   \&}
\DoxyCodeLine{472             hard\_fail\_heff = cs\%hard\_fail\_heff)}
\DoxyCodeLine{473 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{474 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{475 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{476 }
\DoxyCodeLine{477   \textcolor{comment}{! Neutral surface factors at V points}}
\DoxyCodeLine{478   \textcolor{keywordflow}{do} j = g\%jsc-\/1, g\%jec ; \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{479     \textcolor{keywordflow}{if} (g\%mask2dCv(i,j) > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{480       \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{481         \textcolor{keyword}{call }find\_neutral\_surface\_positions\_continuous(g\%ke,                                              \&}
\DoxyCodeLine{482                 cs\%Pint(i,j,:), cs\%Tint(i,j,:), cs\%Sint(i,j,:), cs\%dRdT(i,j,:), cs\%dRdS(i,j,:),           \&}
\DoxyCodeLine{483                 cs\%Pint(i,j+1,:), cs\%Tint(i,j+1,:), cs\%Sint(i,j+1,:), cs\%dRdT(i,j+1,:), cs\%dRdS(i,j+1,:), \&}
\DoxyCodeLine{484                 cs\%vPoL(i,j,:), cs\%vPoR(i,j,:), cs\%vKoL(i,j,:), cs\%vKoR(i,j,:), cs\%vhEff(i,j,:), \&}
\DoxyCodeLine{485                 k\_bot(i,j), k\_bot(i,j+1), zeta\_bot(i,j), zeta\_bot(i,j+1))}
\DoxyCodeLine{486       \textcolor{keywordflow}{else}}
\DoxyCodeLine{487         \textcolor{keyword}{call }find\_neutral\_surface\_positions\_discontinuous(cs, g\%ke, \&}
\DoxyCodeLine{488             cs\%P\_i(i,j,:,:), h(i,j,:), cs\%T\_i(i,j,:,:), cs\%S\_i(i,j,:,:), cs\%ppoly\_coeffs\_T(i,j,:,:),           \&}
\DoxyCodeLine{489             cs\%ppoly\_coeffs\_S(i,j,:,:),cs\%stable\_cell(i,j,:),                                                  \&}
\DoxyCodeLine{490             cs\%P\_i(i,j+1,:,:), h(i,j+1,:), cs\%T\_i(i,j+1,:,:), cs\%S\_i(i,j+1,:,:), cs\%ppoly\_coeffs\_T(i,j+1,:,:), \&}
\DoxyCodeLine{491             cs\%ppoly\_coeffs\_S(i,j+1,:,:), cs\%stable\_cell(i,j+1,:),                                             \&}
\DoxyCodeLine{492             cs\%vPoL(i,j,:), cs\%vPoR(i,j,:), cs\%vKoL(i,j,:), cs\%vKoR(i,j,:), cs\%vhEff(i,j,:),                   \&}
\DoxyCodeLine{493             hard\_fail\_heff = cs\%hard\_fail\_heff)}
\DoxyCodeLine{494 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{495 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{496 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{497 }
\DoxyCodeLine{498   \textcolor{comment}{! Continuous reconstructions calculate hEff as the difference between the pressures of the}}
\DoxyCodeLine{499   \textcolor{comment}{! neutral surfaces which need to be reconverted to thickness units. The discontinuous version}}
\DoxyCodeLine{500   \textcolor{comment}{! calculates hEff from the nondimensional fraction of the layer spanned by adjacent neutral}}
\DoxyCodeLine{501   \textcolor{comment}{! surfaces, so hEff is already in thickness units.}}
\DoxyCodeLine{502   \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{503     \textcolor{keywordflow}{do} k = 1, cs\%nsurf-\/1 ; \textcolor{keywordflow}{do} j = g\%jsc, g\%jec ; \textcolor{keywordflow}{do} i = g\%isc-\/1, g\%iec}
\DoxyCodeLine{504       \textcolor{keywordflow}{if} (g\%mask2dCu(i,j) > 0.) cs\%uhEff(i,j,k) = cs\%uhEff(i,j,k) * pa\_to\_h}
\DoxyCodeLine{505 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{506     \textcolor{keywordflow}{do} k = 1, cs\%nsurf-\/1 ; \textcolor{keywordflow}{do} j = g\%jsc-\/1, g\%jec ; \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{507       \textcolor{keywordflow}{if} (g\%mask2dCv(i,j) > 0.) cs\%vhEff(i,j,k) = cs\%vhEff(i,j,k) * pa\_to\_h}
\DoxyCodeLine{508 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{509 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{510 }
\DoxyCodeLine{511   \textcolor{keywordflow}{if} (cs\%id\_uhEff\_2d>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{512     heff\_sum(:,:) = 0.}
\DoxyCodeLine{513     \textcolor{keywordflow}{do} k = 1,cs\%nsurf-\/1 ; \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec}
\DoxyCodeLine{514       heff\_sum(i,j) = heff\_sum(i,j) + cs\%uhEff(i,j,k)}
\DoxyCodeLine{515 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{516     \textcolor{keyword}{call }post\_data(cs\%id\_uhEff\_2d, heff\_sum, cs\%diag)}
\DoxyCodeLine{517 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{518   \textcolor{keywordflow}{if} (cs\%id\_vhEff\_2d>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{519     heff\_sum(:,:) = 0.}
\DoxyCodeLine{520     \textcolor{keywordflow}{do} k = 1,cs\%nsurf-\/1 ; \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{521       heff\_sum(i,j) = heff\_sum(i,j) + cs\%vhEff(i,j,k)}
\DoxyCodeLine{522 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{523     \textcolor{keyword}{call }post\_data(cs\%id\_vhEff\_2d, heff\_sum, cs\%diag)}
\DoxyCodeLine{524 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{525 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ae8a313d25818dfa8c3bc056210fac76b}\label{namespacemom__neutral__diffusion_ae8a313d25818dfa8c3bc056210fac76b}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_diffusion\_end@{neutral\_diffusion\_end}}
\index{neutral\_diffusion\_end@{neutral\_diffusion\_end}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_diffusion\_end()}{neutral\_diffusion\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+diffusion\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocates neutral\+\_\+diffusion control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & Neutral diffusion control structure \\
\hline
\end{DoxyParams}


Definition at line 2862 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2863   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< Neutral diffusion control structure}}
\DoxyCodeLine{2864 }
\DoxyCodeLine{2865   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{2866 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a39ce023f4b8ebc8d30f25a9b1ca93925}\label{namespacemom__neutral__diffusion_a39ce023f4b8ebc8d30f25a9b1ca93925}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_diffusion\_init@{neutral\_diffusion\_init}}
\index{neutral\_diffusion\_init@{neutral\_diffusion\_init}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_diffusion\_init()}{neutral\_diffusion\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+diffusion\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), intent(in), target}]{E\+OS,  }\item[{type(\mbox{\hyperlink{structmom__diabatic__driver_1_1diabatic__cs}{diabatic\+\_\+cs}}), pointer}]{diabatic\+\_\+\+C\+Sp,  }\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Read parameters and allocate control structure for neutral\+\_\+diffusion module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & Time structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics control structure \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em eos} & Equation of state \\
\hline
 & {\em diabatic\+\_\+csp} & K\+PP control structure needed to get B\+LD \\
\hline
 & {\em cs} & Neutral diffusion control structure \\
\hline
\end{DoxyParams}


Definition at line 116 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{117   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},    \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< Time structure}}
\DoxyCodeLine{118   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< Grid structure}}
\DoxyCodeLine{119   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{120   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},    \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics control structure}}
\DoxyCodeLine{121   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file structure}}
\DoxyCodeLine{122   \textcolor{keywordtype}{type}(EOS\_type),  \textcolor{keywordtype}{target},    \textcolor{keywordtype}{intent(in)}    :: EOS\textcolor{comment}{        !< Equation of state}}
\DoxyCodeLine{123   \textcolor{keywordtype}{type}(diabatic\_CS),          \textcolor{keywordtype}{pointer}       :: diabatic\_CSp\textcolor{comment}{!< KPP control structure needed to get BLD}}
\DoxyCodeLine{124   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< Neutral diffusion control structure}}
\DoxyCodeLine{125 }
\DoxyCodeLine{126   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{127   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}}
\DoxyCodeLine{128   \textcolor{keywordtype}{character(len=80)}  :: string  \textcolor{comment}{! Temporary strings}}
\DoxyCodeLine{129   \textcolor{keywordtype}{logical} :: default\_2018\_answers}
\DoxyCodeLine{130   \textcolor{keywordtype}{logical} :: boundary\_extrap}
\DoxyCodeLine{131 }
\DoxyCodeLine{132   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{133     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}neutral\_diffusion\_init called with associated control structure."{}})}
\DoxyCodeLine{134     \textcolor{keywordflow}{return}}
\DoxyCodeLine{135 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{136 }
\DoxyCodeLine{137   \textcolor{comment}{! Log this module and master switch for turning it on/off}}
\DoxyCodeLine{138   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_NEUTRAL\_DIFFUSION"{}}, neutral\_diffusion\_init, \&}
\DoxyCodeLine{139                  default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{140   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \&}
\DoxyCodeLine{141            \textcolor{stringliteral}{"{}This module implements neutral diffusion of tracers"{}}, \&}
\DoxyCodeLine{142            all\_default=.not.neutral\_diffusion\_init)}
\DoxyCodeLine{143   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_NEUTRAL\_DIFFUSION"{}}, neutral\_diffusion\_init, \&}
\DoxyCodeLine{144                  \textcolor{stringliteral}{"{}If true, enables the neutral diffusion module."{}}, \&}
\DoxyCodeLine{145                  default=.false.)}
\DoxyCodeLine{146 }
\DoxyCodeLine{147   \textcolor{keywordflow}{if} (.not.neutral\_diffusion\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{148 }
\DoxyCodeLine{149   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{150   cs\%diag => diag}
\DoxyCodeLine{151   cs\%EOS => eos}
\DoxyCodeLine{152  \textcolor{comment}{! call openParameterBlock(param\_file,'NEUTRAL\_DIFF')}}
\DoxyCodeLine{153 }
\DoxyCodeLine{154   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{155   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_CONTINUOUS"{}}, cs\%continuous\_reconstruction, \&}
\DoxyCodeLine{156                  \textcolor{stringliteral}{"{}If true, uses a continuous reconstruction of T and S when "{}}//\&}
\DoxyCodeLine{157                  \textcolor{stringliteral}{"{}finding neutral surfaces along which diffusion will happen. "{}}//\&}
\DoxyCodeLine{158                  \textcolor{stringliteral}{"{}If false, a PPM discontinuous reconstruction of T and S "{}}//\&}
\DoxyCodeLine{159                  \textcolor{stringliteral}{"{}is done which results in a higher order routine but exacts "{}}//\&}
\DoxyCodeLine{160                  \textcolor{stringliteral}{"{}a higher computational cost."{}}, default=.true.)}
\DoxyCodeLine{161   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_REF\_PRES"{}}, cs\%ref\_pres,                    \&}
\DoxyCodeLine{162                  \textcolor{stringliteral}{"{}The reference pressure (Pa) used for the derivatives of "{}}//\&}
\DoxyCodeLine{163                  \textcolor{stringliteral}{"{}the equation of state. If negative (default), local pressure is used."{}}, \&}
\DoxyCodeLine{164                  units=\textcolor{stringliteral}{"{}Pa"{}}, default = -\/1., scale=us\%kg\_m3\_to\_R*us\%m\_s\_to\_L\_T**2)}
\DoxyCodeLine{165   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_INTERIOR\_ONLY"{}}, cs\%interior\_only, \&}
\DoxyCodeLine{166                  \textcolor{stringliteral}{"{}If true, only applies neutral diffusion in the ocean interior."{}}//\&}
\DoxyCodeLine{167                  \textcolor{stringliteral}{"{}That is, the algorithm will exclude the surface and bottom"{}}//\&}
\DoxyCodeLine{168                  \textcolor{stringliteral}{"{}boundary layers."{}}, default = .false.)}
\DoxyCodeLine{169 }
\DoxyCodeLine{170   \textcolor{comment}{! Initialize and configure remapping}}
\DoxyCodeLine{171   \textcolor{keywordflow}{if} ( .not.cs\%continuous\_reconstruction ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{172     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_BOUNDARY\_EXTRAP"{}}, boundary\_extrap, \&}
\DoxyCodeLine{173                    \textcolor{stringliteral}{"{}Extrapolate at the top and bottommost cells, otherwise   \(\backslash\)n"{}}//  \&}
\DoxyCodeLine{174                    \textcolor{stringliteral}{"{}assume boundaries are piecewise constant"{}},                      \&}
\DoxyCodeLine{175                    default=.false.)}
\DoxyCodeLine{176     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_REMAPPING\_SCHEME"{}}, string, \&}
\DoxyCodeLine{177                    \textcolor{stringliteral}{"{}This sets the reconstruction scheme used "{}}//\&}
\DoxyCodeLine{178                    \textcolor{stringliteral}{"{}for vertical remapping for all variables. "{}}//\&}
\DoxyCodeLine{179                    \textcolor{stringliteral}{"{}It can be one of the following schemes: "{}}//\&}
\DoxyCodeLine{180                    trim(remappingschemesdoc), default=remappingdefaultscheme)}
\DoxyCodeLine{181     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEFAULT\_2018\_ANSWERS"{}}, default\_2018\_answers, \&}
\DoxyCodeLine{182                  \textcolor{stringliteral}{"{}This sets the default value for the various \_2018\_ANSWERS parameters."{}}, \&}
\DoxyCodeLine{183                  default=.false.)}
\DoxyCodeLine{184     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}REMAPPING\_2018\_ANSWERS"{}}, cs\%remap\_answers\_2018, \&}
\DoxyCodeLine{185                  \textcolor{stringliteral}{"{}If true, use the order of arithmetic and expressions that recover the "{}}//\&}
\DoxyCodeLine{186                  \textcolor{stringliteral}{"{}answers from the end of 2018.  Otherwise, use updated and more robust "{}}//\&}
\DoxyCodeLine{187                  \textcolor{stringliteral}{"{}forms of the same expressions."{}}, default=default\_2018\_answers)}
\DoxyCodeLine{188     \textcolor{keyword}{call }initialize\_remapping( cs\%remap\_CS, string, boundary\_extrapolation=boundary\_extrap, \&}
\DoxyCodeLine{189                                answers\_2018=cs\%remap\_answers\_2018 )}
\DoxyCodeLine{190     \textcolor{keyword}{call }extract\_member\_remapping\_cs(cs\%remap\_CS, degree=cs\%deg)}
\DoxyCodeLine{191     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NEUTRAL\_POS\_METHOD"{}}, cs\%neutral\_pos\_method,   \&}
\DoxyCodeLine{192                    \textcolor{stringliteral}{"{}Method used to find the neutral position                 \(\backslash\)n"{}}// \&}
\DoxyCodeLine{193                    \textcolor{stringliteral}{"{}1. Delta\_rho varies linearly, find 0 crossing            \(\backslash\)n"{}}// \&}
\DoxyCodeLine{194                    \textcolor{stringliteral}{"{}2. Alpha and beta vary linearly from top to bottom,      \(\backslash\)n"{}}// \&}
\DoxyCodeLine{195                    \textcolor{stringliteral}{"{}   Newton's method for neutral position                  \(\backslash\)n"{}}// \&}
\DoxyCodeLine{196                    \textcolor{stringliteral}{"{}3. Full nonlinear equation of state, use regula falsi    \(\backslash\)n"{}}// \&}
\DoxyCodeLine{197                    \textcolor{stringliteral}{"{}   for neutral position"{}}, default=3)}
\DoxyCodeLine{198     \textcolor{keywordflow}{if} (cs\%neutral\_pos\_method > 4 .or. cs\%neutral\_pos\_method < 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{199       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}Invalid option for NEUTRAL\_POS\_METHOD"{}})}
\DoxyCodeLine{200 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{201 }
\DoxyCodeLine{202     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DELTA\_RHO\_FORM"{}}, cs\%delta\_rho\_form,           \&}
\DoxyCodeLine{203                    \textcolor{stringliteral}{"{}Determine how the difference in density is calculated    \(\backslash\)n"{}}// \&}
\DoxyCodeLine{204                    \textcolor{stringliteral}{"{}  full       : Difference of in-\/situ densities           \(\backslash\)n"{}}// \&}
\DoxyCodeLine{205                    \textcolor{stringliteral}{"{}  no\_pressure: Calculated from dRdT, dRdS, but no        \(\backslash\)n"{}}// \&}
\DoxyCodeLine{206                    \textcolor{stringliteral}{"{}               pressure dependence"{}},                           \&}
\DoxyCodeLine{207                    default=\textcolor{stringliteral}{"{}mid\_pressure"{}})}
\DoxyCodeLine{208     \textcolor{keywordflow}{if} (cs\%neutral\_pos\_method > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{209       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_DRHO\_TOL"{}}, cs\%drho\_tol,            \&}
\DoxyCodeLine{210                      \textcolor{stringliteral}{"{}Sets the convergence criterion for finding the neutral\(\backslash\)n"{}}// \&}
\DoxyCodeLine{211                      \textcolor{stringliteral}{"{}position within a layer in kg m-\/3."{}},                        \&}
\DoxyCodeLine{212                      default=1.e-\/10, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{213       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_X\_TOL"{}}, cs\%x\_tol,            \&}
\DoxyCodeLine{214                      \textcolor{stringliteral}{"{}Sets the convergence criterion for a change in nondim\(\backslash\)n"{}}// \&}
\DoxyCodeLine{215                      \textcolor{stringliteral}{"{}position within a layer."{}},                        \&}
\DoxyCodeLine{216                      default=0.)}
\DoxyCodeLine{217       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_MAX\_ITER"{}}, cs\%max\_iter,              \&}
\DoxyCodeLine{218                     \textcolor{stringliteral}{"{}The maximum number of iterations to be done before \(\backslash\)n"{}}//     \&}
\DoxyCodeLine{219                      \textcolor{stringliteral}{"{}exiting the iterative loop to find the neutral surface"{}},    \&}
\DoxyCodeLine{220                      default=10)}
\DoxyCodeLine{221 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{222     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NDIFF\_DEBUG"{}}, cs\%debug,             \&}
\DoxyCodeLine{223                    \textcolor{stringliteral}{"{}Turns on verbose output for discontinuous neutral "{}}//\&}
\DoxyCodeLine{224                    \textcolor{stringliteral}{"{}diffusion routines."{}}, \&}
\DoxyCodeLine{225                    default = .false.)}
\DoxyCodeLine{226     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}HARD\_FAIL\_HEFF"{}}, cs\%hard\_fail\_heff, \&}
\DoxyCodeLine{227                   \textcolor{stringliteral}{"{}Bring down the model if a problem with heff is detected"{}},\&}
\DoxyCodeLine{228                    default = .true.)}
\DoxyCodeLine{229 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{230 }
\DoxyCodeLine{231   \textcolor{comment}{! Store a rescaling factor for use in diagnostic messages.}}
\DoxyCodeLine{232   cs\%R\_to\_kg\_m3 = us\%R\_to\_kg\_m3}
\DoxyCodeLine{233 }
\DoxyCodeLine{234   \textcolor{keywordflow}{if} (cs\%interior\_only) \textcolor{keywordflow}{then}}
\DoxyCodeLine{235     \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, kpp\_csp=cs\%KPP\_CSp)}
\DoxyCodeLine{236     \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, energetic\_pbl\_csp=cs\%energetic\_PBL\_CSp)}
\DoxyCodeLine{237     \textcolor{keywordflow}{if} ( .not. \textcolor{keyword}{ASSOCIATED}(cs\%energetic\_PBL\_CSp) .and. .not. \textcolor{keyword}{ASSOCIATED}(cs\%KPP\_CSp) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{238       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}NDIFF\_INTERIOR\_ONLY is true, but no valid boundary layer scheme was found"{}})}
\DoxyCodeLine{239 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{240 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{241 }
\DoxyCodeLine{242 \textcolor{comment}{! call get\_param(param\_file, mdl, "{}KHTR"{}, CS\%KhTr, \&}}
\DoxyCodeLine{243 \textcolor{comment}{!                "{}The background along-\/isopycnal tracer diffusivity."{}, \&}}
\DoxyCodeLine{244 \textcolor{comment}{!                units="{}m2 s-\/1"{}, default=0.0)}}
\DoxyCodeLine{245 \textcolor{comment}{!  call closeParameterBlock(param\_file)}}
\DoxyCodeLine{246   \textcolor{keywordflow}{if} (cs\%continuous\_reconstruction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{247     cs\%nsurf = 2*g\%ke+2 \textcolor{comment}{! Continuous reconstruction means that every interface has two connections}}
\DoxyCodeLine{248     \textcolor{keyword}{allocate}(cs\%dRdT(szi\_(g),szj\_(g),szk\_(g)+1)) ; cs\%dRdT(:,:,:) = 0.}
\DoxyCodeLine{249     \textcolor{keyword}{allocate}(cs\%dRdS(szi\_(g),szj\_(g),szk\_(g)+1)) ; cs\%dRdS(:,:,:) = 0.}
\DoxyCodeLine{250   \textcolor{keywordflow}{else}}
\DoxyCodeLine{251     cs\%nsurf = 4*g\%ke   \textcolor{comment}{! Discontinuous means that every interface has four connections}}
\DoxyCodeLine{252     \textcolor{keyword}{allocate}(cs\%T\_i(szi\_(g),szj\_(g),szk\_(g),2))    ; cs\%T\_i(:,:,:,:) = 0.}
\DoxyCodeLine{253     \textcolor{keyword}{allocate}(cs\%S\_i(szi\_(g),szj\_(g),szk\_(g),2))    ; cs\%S\_i(:,:,:,:) = 0.}
\DoxyCodeLine{254     \textcolor{keyword}{allocate}(cs\%P\_i(szi\_(g),szj\_(g),szk\_(g),2))    ; cs\%P\_i(:,:,:,:) = 0.}
\DoxyCodeLine{255     \textcolor{keyword}{allocate}(cs\%dRdT\_i(szi\_(g),szj\_(g),szk\_(g),2)) ; cs\%dRdT\_i(:,:,:,:) = 0.}
\DoxyCodeLine{256     \textcolor{keyword}{allocate}(cs\%dRdS\_i(szi\_(g),szj\_(g),szk\_(g),2)) ; cs\%dRdS\_i(:,:,:,:) = 0.}
\DoxyCodeLine{257     \textcolor{keyword}{allocate}(cs\%ppoly\_coeffs\_T(szi\_(g),szj\_(g),szk\_(g),cs\%deg+1)) ; cs\%ppoly\_coeffs\_T(:,:,:,:) = 0.}
\DoxyCodeLine{258     \textcolor{keyword}{allocate}(cs\%ppoly\_coeffs\_S(szi\_(g),szj\_(g),szk\_(g),cs\%deg+1)) ; cs\%ppoly\_coeffs\_S(:,:,:,:) = 0.}
\DoxyCodeLine{259     \textcolor{keyword}{allocate}(cs\%ns(szi\_(g),szj\_(g)))    ; cs\%ns(:,:) = 0.}
\DoxyCodeLine{260 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{261   \textcolor{comment}{! T-\/points}}
\DoxyCodeLine{262   \textcolor{keyword}{allocate}(cs\%Tint(szi\_(g),szj\_(g),szk\_(g)+1)) ; cs\%Tint(:,:,:) = 0.}
\DoxyCodeLine{263   \textcolor{keyword}{allocate}(cs\%Sint(szi\_(g),szj\_(g),szk\_(g)+1)) ; cs\%Sint(:,:,:) = 0.}
\DoxyCodeLine{264   \textcolor{keyword}{allocate}(cs\%Pint(szi\_(g),szj\_(g),szk\_(g)+1)) ; cs\%Pint(:,:,:) = 0.}
\DoxyCodeLine{265   \textcolor{keyword}{allocate}(cs\%stable\_cell(szi\_(g),szj\_(g),szk\_(g))) ; cs\%stable\_cell(:,:,:) = .true.}
\DoxyCodeLine{266   \textcolor{comment}{! U-\/points}}
\DoxyCodeLine{267   \textcolor{keyword}{allocate}(cs\%uPoL(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%uPoL(g\%isc-\/1:g\%iec,g\%jsc:g\%jec,:)   = 0.}
\DoxyCodeLine{268   \textcolor{keyword}{allocate}(cs\%uPoR(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%uPoR(g\%isc-\/1:g\%iec,g\%jsc:g\%jec,:)   = 0.}
\DoxyCodeLine{269   \textcolor{keyword}{allocate}(cs\%uKoL(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%uKoL(g\%isc-\/1:g\%iec,g\%jsc:g\%jec,:)   = 0}
\DoxyCodeLine{270   \textcolor{keyword}{allocate}(cs\%uKoR(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%uKoR(g\%isc-\/1:g\%iec,g\%jsc:g\%jec,:)   = 0}
\DoxyCodeLine{271   \textcolor{keyword}{allocate}(cs\%uHeff(g\%isd:g\%ied,g\%jsd:g\%jed,cs\%nsurf-\/1)); cs\%uHeff(g\%isc-\/1:g\%iec,g\%jsc:g\%jec,:) = 0}
\DoxyCodeLine{272   \textcolor{comment}{! V-\/points}}
\DoxyCodeLine{273   \textcolor{keyword}{allocate}(cs\%vPoL(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%vPoL(g\%isc:g\%iec,g\%jsc-\/1:g\%jec,:)   = 0.}
\DoxyCodeLine{274   \textcolor{keyword}{allocate}(cs\%vPoR(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%vPoR(g\%isc:g\%iec,g\%jsc-\/1:g\%jec,:)   = 0.}
\DoxyCodeLine{275   \textcolor{keyword}{allocate}(cs\%vKoL(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%vKoL(g\%isc:g\%iec,g\%jsc-\/1:g\%jec,:)   = 0}
\DoxyCodeLine{276   \textcolor{keyword}{allocate}(cs\%vKoR(g\%isd:g\%ied,g\%jsd:g\%jed, cs\%nsurf)); cs\%vKoR(g\%isc:g\%iec,g\%jsc-\/1:g\%jec,:)   = 0}
\DoxyCodeLine{277   \textcolor{keyword}{allocate}(cs\%vHeff(g\%isd:g\%ied,g\%jsd:g\%jed,cs\%nsurf-\/1)); cs\%vHeff(g\%isc:g\%iec,g\%jsc-\/1:g\%jec,:) = 0}
\DoxyCodeLine{278 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a6f91c93a6363fb39395796420f25fad2}\label{namespacemom__neutral__diffusion_a6f91c93a6363fb39395796420f25fad2}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_diffusion\_unit\_tests@{neutral\_diffusion\_unit\_tests}}
\index{neutral\_diffusion\_unit\_tests@{neutral\_diffusion\_unit\_tests}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_diffusion\_unit\_tests()}{neutral\_diffusion\_unit\_tests()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+diffusion\+\_\+unit\+\_\+tests (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose }\end{DoxyParamCaption})}



Returns true if unit tests of neutral\+\_\+diffusion functions fail. Otherwise returns false. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\end{DoxyParams}


Definition at line 2079 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2080   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2081 }
\DoxyCodeLine{2082   neutral\_diffusion\_unit\_tests = .false. .or. \&}
\DoxyCodeLine{2083     ndiff\_unit\_tests\_continuous(verbose) .or. ndiff\_unit\_tests\_discontinuous(verbose)}
\DoxyCodeLine{2084 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_aa394289328ee392cdb17000fb6fa90e8}\label{namespacemom__neutral__diffusion_aa394289328ee392cdb17000fb6fa90e8}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_surface\_flux@{neutral\_surface\_flux}}
\index{neutral\_surface\_flux@{neutral\_surface\_flux}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_surface\_flux()}{neutral\_surface\_flux()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+surface\+\_\+flux (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{integer, intent(in)}]{nsurf,  }\item[{integer, intent(in)}]{deg,  }\item[{real, dimension(nk), intent(in)}]{hl,  }\item[{real, dimension(nk), intent(in)}]{hr,  }\item[{real, dimension(nk), intent(in)}]{Tl,  }\item[{real, dimension(nk), intent(in)}]{Tr,  }\item[{real, dimension(nsurf), intent(in)}]{PiL,  }\item[{real, dimension(nsurf), intent(in)}]{PiR,  }\item[{integer, dimension(nsurf), intent(in)}]{KoL,  }\item[{integer, dimension(nsurf), intent(in)}]{KoR,  }\item[{real, dimension(nsurf-\/1), intent(in)}]{h\+Eff,  }\item[{real, dimension(nsurf-\/1), intent(inout)}]{Flx,  }\item[{logical, intent(in)}]{continuous,  }\item[{real, intent(in)}]{h\+\_\+neglect,  }\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in), optional}]{remap\+\_\+\+CS,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns a single column of neutral diffusion fluxes of a tracer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em nsurf} & Number of neutral surfaces \\
\hline
\mbox{\texttt{ in}}  & {\em deg} & Degree of polynomial reconstructions \\
\hline
\mbox{\texttt{ in}}  & {\em hl} & Left-\/column layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hr} & Right-\/column layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tl} & Left-\/column layer tracer (conc, e.\+g. degC) \\
\hline
\mbox{\texttt{ in}}  & {\em tr} & Right-\/column layer tracer (conc, e.\+g. degC) \\
\hline
\mbox{\texttt{ in}}  & {\em pil} & Fractional position of neutral surface within layer KoL of left column \\
\hline
\mbox{\texttt{ in}}  & {\em pir} & Fractional position of neutral surface within layer KoR of right column \\
\hline
\mbox{\texttt{ in}}  & {\em kol} & Index of first left interface above neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em kor} & Index of first right interface above neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em heff} & Effective thickness between two neutral surfaces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em flx} & Flux of tracer between pairs of neutral layers (conc H) \\
\hline
\mbox{\texttt{ in}}  & {\em continuous} & True if using continuous reconstruction \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em remap\+\_\+cs} & Remapping control structure used to create sublayers \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width used for edge value calculations if continuous is false \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1875 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1877   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{    !< Number of levels}}
\DoxyCodeLine{1878   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: nsurf\textcolor{comment}{ !< Number of neutral surfaces}}
\DoxyCodeLine{1879   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: deg\textcolor{comment}{   !< Degree of polynomial reconstructions}}
\DoxyCodeLine{1880 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},          \textcolor{keywordtype}{intent(in)}    :: hl\textcolor{comment}{    !< Left-\/column layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1881 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},          \textcolor{keywordtype}{intent(in)}    :: hr\textcolor{comment}{    !< Right-\/column layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1882 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},          \textcolor{keywordtype}{intent(in)}    :: Tl\textcolor{comment}{    !< Left-\/column layer tracer (conc, e.g. degC)}}
\DoxyCodeLine{1883 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},          \textcolor{keywordtype}{intent(in)}    :: Tr\textcolor{comment}{    !< Right-\/column layer tracer (conc, e.g. degC)}}
\DoxyCodeLine{1884 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nsurf)},       \textcolor{keywordtype}{intent(in)}    :: PiL\textcolor{comment}{   !< Fractional position of neutral surface}}
\DoxyCodeLine{1885 \textcolor{comment}{                                                       !! within layer KoL of left column}}
\DoxyCodeLine{1886 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nsurf)},       \textcolor{keywordtype}{intent(in)}    :: PiR\textcolor{comment}{   !< Fractional position of neutral surface}}
\DoxyCodeLine{1887 \textcolor{comment}{                                                       !! within layer KoR of right column}}
\DoxyCodeLine{1888   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nsurf)},    \textcolor{keywordtype}{intent(in)}    :: KoL\textcolor{comment}{   !< Index of first left interface above neutral surface}}
\DoxyCodeLine{1889   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nsurf)},    \textcolor{keywordtype}{intent(in)}    :: KoR\textcolor{comment}{   !< Index of first right interface above neutral surface}}
\DoxyCodeLine{1890 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nsurf-\/1)},     \textcolor{keywordtype}{intent(in)}    :: hEff\textcolor{comment}{  !< Effective thickness between two neutral}}
\DoxyCodeLine{1891 \textcolor{comment}{                                                       !! surfaces [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1892 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nsurf-\/1)},     \textcolor{keywordtype}{intent(inout)} :: Flx\textcolor{comment}{   !< Flux of tracer between pairs of neutral layers (conc H)}}
\DoxyCodeLine{1893   \textcolor{keywordtype}{logical},                      \textcolor{keywordtype}{intent(in)}    :: continuous\textcolor{comment}{ !< True if using continuous reconstruction}}
\DoxyCodeLine{1894 \textcolor{keywordtype}{  real},                         \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{1895 \textcolor{comment}{                                             !! purpose of cell reconstructions [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1896   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: remap\_CS\textcolor{comment}{ !< Remapping control structure used}}
\DoxyCodeLine{1897 \textcolor{comment}{                                             !! to create sublayers}}
\DoxyCodeLine{1898 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width used for}}
\DoxyCodeLine{1899 \textcolor{comment}{                                             !! edge value calculations if continuous is false [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1900   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1901   \textcolor{keywordtype}{integer} :: k\_sublayer, klb, klt, krb, krt, k}
\DoxyCodeLine{1902 \textcolor{keywordtype}{  real} :: T\_right\_top, T\_right\_bottom, T\_right\_layer, T\_right\_sub, T\_right\_top\_int, T\_right\_bot\_int}
\DoxyCodeLine{1903 \textcolor{keywordtype}{  real} :: T\_left\_top, T\_left\_bottom, T\_left\_layer, T\_left\_sub, T\_left\_top\_int, T\_left\_bot\_int}
\DoxyCodeLine{1904 \textcolor{keywordtype}{  real} :: dT\_top, dT\_bottom, dT\_layer, dT\_ave, dT\_sublayer, dT\_top\_int, dT\_bot\_int}
\DoxyCodeLine{1905 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)} :: Til\textcolor{comment}{ !< Left-\/column interface tracer (conc, e.g. degC)}}
\DoxyCodeLine{1906 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)} :: Tir\textcolor{comment}{ !< Right-\/column interface tracer (conc, e.g. degC)}}
\DoxyCodeLine{1907 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: aL\_l\textcolor{comment}{ !< Left-\/column left edge value of tracer (conc, e.g. degC)}}
\DoxyCodeLine{1908 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: aR\_l\textcolor{comment}{ !< Left-\/column right edge value of tracer (conc, e.g. degC)}}
\DoxyCodeLine{1909 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: aL\_r\textcolor{comment}{ !< Right-\/column left edge value of tracer (conc, e.g. degC)}}
\DoxyCodeLine{1910 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: aR\_r\textcolor{comment}{ !< Right-\/column right edge value of tracer (conc, e.g. degC)}}
\DoxyCodeLine{1911   \textcolor{comment}{! Discontinuous reconstruction}}
\DoxyCodeLine{1912   \textcolor{keywordtype}{integer}               :: iMethod}
\DoxyCodeLine{1913 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)} :: Tid\_l\textcolor{comment}{ !< Left-\/column interface tracer (conc, e.g. degC)}}
\DoxyCodeLine{1914 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)} :: Tid\_r\textcolor{comment}{ !< Right-\/column interface tracer (conc, e.g. degC)}}
\DoxyCodeLine{1915 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: ppoly\_r\_coeffs\_l}
\DoxyCodeLine{1916 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: ppoly\_r\_coeffs\_r}
\DoxyCodeLine{1917 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: ppoly\_r\_S\_l}
\DoxyCodeLine{1918 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: ppoly\_r\_S\_r}
\DoxyCodeLine{1919   \textcolor{keywordtype}{logical} :: down\_flux}
\DoxyCodeLine{1920   \textcolor{comment}{! Setup reconstruction edge values}}
\DoxyCodeLine{1921   \textcolor{keywordflow}{if} (continuous) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1922     \textcolor{keyword}{call }interface\_scalar(nk, hl, tl, til, 2, h\_neglect)}
\DoxyCodeLine{1923     \textcolor{keyword}{call }interface\_scalar(nk, hr, tr, tir, 2, h\_neglect)}
\DoxyCodeLine{1924     \textcolor{keyword}{call }ppm\_left\_right\_edge\_values(nk, tl, til, al\_l, ar\_l)}
\DoxyCodeLine{1925     \textcolor{keyword}{call }ppm\_left\_right\_edge\_values(nk, tr, tir, al\_r, ar\_r)}
\DoxyCodeLine{1926   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1927     ppoly\_r\_coeffs\_l(:,:) = 0.}
\DoxyCodeLine{1928     ppoly\_r\_coeffs\_r(:,:) = 0.}
\DoxyCodeLine{1929     tid\_l(:,:) = 0.}
\DoxyCodeLine{1930     tid\_r(:,:) = 0.}
\DoxyCodeLine{1931 }
\DoxyCodeLine{1932     \textcolor{keyword}{call }build\_reconstructions\_1d( remap\_cs, nk, hl, tl, ppoly\_r\_coeffs\_l, tid\_l, \&}
\DoxyCodeLine{1933                                    ppoly\_r\_s\_l, imethod, h\_neglect, h\_neglect\_edge )}
\DoxyCodeLine{1934     \textcolor{keyword}{call }build\_reconstructions\_1d( remap\_cs, nk, hr, tr, ppoly\_r\_coeffs\_r, tid\_r, \&}
\DoxyCodeLine{1935                                    ppoly\_r\_s\_r, imethod, h\_neglect, h\_neglect\_edge )}
\DoxyCodeLine{1936 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1937 }
\DoxyCodeLine{1938   \textcolor{keywordflow}{do} k\_sublayer = 1, nsurf-\/1}
\DoxyCodeLine{1939     \textcolor{keywordflow}{if} (heff(k\_sublayer) == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1940       flx(k\_sublayer) = 0.}
\DoxyCodeLine{1941     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1942       \textcolor{keywordflow}{if} (continuous) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1943         klb = kol(k\_sublayer+1)}
\DoxyCodeLine{1944         t\_left\_bottom = ( 1. -\/ pil(k\_sublayer+1) ) * til(klb) + pil(k\_sublayer+1) * til(klb+1)}
\DoxyCodeLine{1945         klt = kol(k\_sublayer)}
\DoxyCodeLine{1946         t\_left\_top = ( 1. -\/ pil(k\_sublayer) ) * til(klt) + pil(k\_sublayer) * til(klt+1)}
\DoxyCodeLine{1947         t\_left\_layer = ppm\_ave(pil(k\_sublayer), pil(k\_sublayer+1) + real(klb-\/klt), \&}
\DoxyCodeLine{1948                                al\_l(klt), ar\_l(klt), tl(klt))}
\DoxyCodeLine{1949 }
\DoxyCodeLine{1950         krb = kor(k\_sublayer+1)}
\DoxyCodeLine{1951         t\_right\_bottom = ( 1. -\/ pir(k\_sublayer+1) ) * tir(krb) + pir(k\_sublayer+1) * tir(krb+1)}
\DoxyCodeLine{1952         krt = kor(k\_sublayer)}
\DoxyCodeLine{1953         t\_right\_top = ( 1. -\/ pir(k\_sublayer) ) * tir(krt) + pir(k\_sublayer) * tir(krt+1)}
\DoxyCodeLine{1954         t\_right\_layer = ppm\_ave(pir(k\_sublayer), pir(k\_sublayer+1) + real(krb-\/krt), \&}
\DoxyCodeLine{1955                                 al\_r(krt), ar\_r(krt), tr(krt))}
\DoxyCodeLine{1956         dt\_top = t\_right\_top -\/ t\_left\_top}
\DoxyCodeLine{1957         dt\_bottom = t\_right\_bottom -\/ t\_left\_bottom}
\DoxyCodeLine{1958         dt\_ave = 0.5 * ( dt\_top + dt\_bottom )}
\DoxyCodeLine{1959         dt\_layer = t\_right\_layer -\/ t\_left\_layer}
\DoxyCodeLine{1960         \textcolor{keywordflow}{if} (signum(1.,dt\_top) * signum(1.,dt\_bottom) <= 0. .or. signum(1.,dt\_ave) * signum(1.,dt\_layer) <= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1961           dt\_ave = 0.}
\DoxyCodeLine{1962         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1963           dt\_ave = dt\_layer}
\DoxyCodeLine{1964 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1965         flx(k\_sublayer) = dt\_ave * heff(k\_sublayer)}
\DoxyCodeLine{1966       \textcolor{keywordflow}{else} \textcolor{comment}{! Discontinuous reconstruction}}
\DoxyCodeLine{1967         \textcolor{comment}{! Calculate tracer values on left and right side of the neutral surface}}
\DoxyCodeLine{1968         \textcolor{keyword}{call }neutral\_surface\_t\_eval(nk, nsurf, k\_sublayer, kol, pil, tl, tid\_l, deg, imethod, \&}
\DoxyCodeLine{1969                                     ppoly\_r\_coeffs\_l, t\_left\_top, t\_left\_bottom, t\_left\_sub, \&}
\DoxyCodeLine{1970                                     t\_left\_top\_int, t\_left\_bot\_int, t\_left\_layer)}
\DoxyCodeLine{1971         \textcolor{keyword}{call }neutral\_surface\_t\_eval(nk, nsurf, k\_sublayer, kor, pir, tr, tid\_r, deg, imethod, \&}
\DoxyCodeLine{1972                                     ppoly\_r\_coeffs\_r, t\_right\_top, t\_right\_bottom, t\_right\_sub, \&}
\DoxyCodeLine{1973                                     t\_right\_top\_int, t\_right\_bot\_int, t\_right\_layer)}
\DoxyCodeLine{1974 }
\DoxyCodeLine{1975         dt\_top      = t\_right\_top     -\/ t\_left\_top}
\DoxyCodeLine{1976         dt\_bottom   = t\_right\_bottom  -\/ t\_left\_bottom}
\DoxyCodeLine{1977         dt\_sublayer = t\_right\_sub     -\/ t\_left\_sub}
\DoxyCodeLine{1978         dt\_top\_int  = t\_right\_top\_int -\/ t\_left\_top\_int}
\DoxyCodeLine{1979         dt\_bot\_int  = t\_right\_bot\_int -\/ t\_left\_bot\_int}
\DoxyCodeLine{1980         \textcolor{comment}{! Enforcing the below criterion incorrectly zero out fluxes}}
\DoxyCodeLine{1981         \textcolor{comment}{!dT\_layer = T\_right\_layer -\/ T\_left\_layer}}
\DoxyCodeLine{1982 }
\DoxyCodeLine{1983         down\_flux = dt\_top <= 0. .and. dt\_bottom <= 0. .and.       \&}
\DoxyCodeLine{1984                     dt\_sublayer <= 0. .and. dt\_top\_int <= 0. .and. \&}
\DoxyCodeLine{1985                     dt\_bot\_int <= 0.}
\DoxyCodeLine{1986         down\_flux = down\_flux .or.                                 \&}
\DoxyCodeLine{1987                     (dt\_top >= 0. .and. dt\_bottom >= 0. .and.      \&}
\DoxyCodeLine{1988                     dt\_sublayer >= 0. .and. dt\_top\_int >= 0. .and. \&}
\DoxyCodeLine{1989                     dt\_bot\_int >= 0.)}
\DoxyCodeLine{1990         \textcolor{keywordflow}{if} (down\_flux) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1991           flx(k\_sublayer) = dt\_sublayer * heff(k\_sublayer)}
\DoxyCodeLine{1992         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1993           flx(k\_sublayer) = 0.}
\DoxyCodeLine{1994 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1995 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1996 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1997 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1998 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a005d759280cfcb84cafa23a984ffc818}\label{namespacemom__neutral__diffusion_a005d759280cfcb84cafa23a984ffc818}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!neutral\_surface\_t\_eval@{neutral\_surface\_t\_eval}}
\index{neutral\_surface\_t\_eval@{neutral\_surface\_t\_eval}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{neutral\_surface\_t\_eval()}{neutral\_surface\_t\_eval()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::neutral\+\_\+surface\+\_\+t\+\_\+eval (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{integer, intent(in)}]{ns,  }\item[{integer, intent(in)}]{k\+\_\+sub,  }\item[{integer, dimension(ns), intent(in)}]{Ks,  }\item[{real, dimension(ns), intent(in)}]{Ps,  }\item[{real, dimension(nk), intent(in)}]{T\+\_\+mean,  }\item[{real, dimension(nk,2), intent(in)}]{T\+\_\+int,  }\item[{integer, intent(in)}]{deg,  }\item[{integer, intent(in)}]{i\+Method,  }\item[{real, dimension(nk,deg+1), intent(in)}]{T\+\_\+poly,  }\item[{real, intent(out)}]{T\+\_\+top,  }\item[{real, intent(out)}]{T\+\_\+bot,  }\item[{real, intent(out)}]{T\+\_\+sub,  }\item[{real, intent(out)}]{T\+\_\+top\+\_\+int,  }\item[{real, intent(out)}]{T\+\_\+bot\+\_\+int,  }\item[{real, intent(out)}]{T\+\_\+layer }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluate various parts of the reconstructions to calculate gradient-\/based flux limter. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of cell everages \\
\hline
\mbox{\texttt{ in}}  & {\em ns} & Number of neutral surfaces \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+sub} & Index of current neutral layer \\
\hline
\mbox{\texttt{ in}}  & {\em ks} & List of the layers associated with each neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em ps} & List of the positions within a layer of each surface \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+mean} & Cell average of tracer \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+int} & Cell interface values of tracer from reconstruction \\
\hline
\mbox{\texttt{ in}}  & {\em deg} & Degree of reconstruction polynomial (e.\+g. 1 is linear) \\
\hline
\mbox{\texttt{ in}}  & {\em imethod} & Method of integration to use \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+poly} & Coefficients of polynomial reconstructions \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+top} & Tracer value at top (across discontinuity if necessary) \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+bot} & Tracer value at bottom (across discontinuity if necessary) \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+sub} & Average of the tracer value over the sublayer \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+top\+\_\+int} & Tracer value at top interface of neutral layer \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+bot\+\_\+int} & Tracer value at bottom interface of neutral layer \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+layer} & Cell-\/average that the the reconstruction belongs to \\
\hline
\end{DoxyParams}


Definition at line 2002 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2004   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )} :: nk\textcolor{comment}{        !< Number of cell everages}}
\DoxyCodeLine{2005   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )} :: ns\textcolor{comment}{        !< Number of neutral surfaces}}
\DoxyCodeLine{2006   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )} :: k\_sub\textcolor{comment}{     !< Index of current neutral layer}}
\DoxyCodeLine{2007   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(ns)},    \textcolor{keywordtype}{intent(in   )} :: Ks\textcolor{comment}{        !< List of the layers associated with each neutral surface}}
\DoxyCodeLine{2008 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns)},       \textcolor{keywordtype}{intent(in   )} :: Ps\textcolor{comment}{        !< List of the positions within a layer of each surface}}
\DoxyCodeLine{2009 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )} :: T\_mean\textcolor{comment}{    !< Cell average of tracer}}
\DoxyCodeLine{2010 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )} :: T\_int\textcolor{comment}{     !< Cell interface values of tracer from reconstruction}}
\DoxyCodeLine{2011   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )} :: deg\textcolor{comment}{       !< Degree of reconstruction polynomial (e.g. 1 is linear)}}
\DoxyCodeLine{2012   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )} :: iMethod\textcolor{comment}{   !< Method of integration to use}}
\DoxyCodeLine{2013 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )} :: T\_poly\textcolor{comment}{    !< Coefficients of polynomial reconstructions}}
\DoxyCodeLine{2014 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)} :: T\_top\textcolor{comment}{     !< Tracer value at top (across discontinuity if necessary)}}
\DoxyCodeLine{2015 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)} :: T\_bot\textcolor{comment}{     !< Tracer value at bottom (across discontinuity if necessary)}}
\DoxyCodeLine{2016 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)} :: T\_sub\textcolor{comment}{     !< Average of the tracer value over the sublayer}}
\DoxyCodeLine{2017 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)} :: T\_top\_int\textcolor{comment}{ !< Tracer value at top interface of neutral layer}}
\DoxyCodeLine{2018 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)} :: T\_bot\_int\textcolor{comment}{ !< Tracer value at bottom interface of neutral layer}}
\DoxyCodeLine{2019 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)} :: T\_layer\textcolor{comment}{   !< Cell-\/average that the the reconstruction belongs to}}
\DoxyCodeLine{2020 }
\DoxyCodeLine{2021   \textcolor{keywordtype}{integer} :: kl, ks\_top, ks\_bot}
\DoxyCodeLine{2022 }
\DoxyCodeLine{2023   ks\_top = k\_sub}
\DoxyCodeLine{2024   ks\_bot = k\_sub + 1}
\DoxyCodeLine{2025   \textcolor{keywordflow}{if} ( ks(ks\_top) /= ks(ks\_bot) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2026     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}Neutral surfaces span more than one layer"{}})}
\DoxyCodeLine{2027 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2028   kl = ks(k\_sub)}
\DoxyCodeLine{2029   \textcolor{comment}{! First if the neutral surfaces spans the entirety of a cell, then do not search across the discontinuity}}
\DoxyCodeLine{2030   \textcolor{keywordflow}{if} ( (ps(ks\_top) == 0.) .and. (ps(ks\_bot) == 1.)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2031     t\_top = t\_int(kl,1)}
\DoxyCodeLine{2032     t\_bot = t\_int(kl,2)}
\DoxyCodeLine{2033   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2034     \textcolor{comment}{! Search across potential discontinuity at top}}
\DoxyCodeLine{2035     \textcolor{keywordflow}{if} ( (kl > 1) .and. (ps(ks\_top) == 0.)  ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2036       t\_top = t\_int(kl-\/1,2)}
\DoxyCodeLine{2037     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2038       t\_top = evaluation\_polynomial( t\_poly(kl,:), deg+1, ps(ks\_top) )}
\DoxyCodeLine{2039 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2040     \textcolor{comment}{! Search across potential discontinuity at bottom}}
\DoxyCodeLine{2041     \textcolor{keywordflow}{if} ( (kl < nk) .and. (ps(ks\_bot) == 1.) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2042       t\_bot = t\_int(kl+1,1)}
\DoxyCodeLine{2043     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2044       t\_bot = evaluation\_polynomial( t\_poly(kl,:), deg+1, ps(ks\_bot) )}
\DoxyCodeLine{2045 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2046 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2047   t\_sub = average\_value\_ppoly(nk, t\_mean, t\_int, t\_poly, imethod, kl, ps(ks\_top), ps(ks\_bot))}
\DoxyCodeLine{2048   t\_top\_int = evaluation\_polynomial( t\_poly(kl,:), deg+1, ps(ks\_top))}
\DoxyCodeLine{2049   t\_bot\_int = evaluation\_polynomial( t\_poly(kl,:), deg+1, ps(ks\_bot))}
\DoxyCodeLine{2050   t\_layer = t\_mean(kl)}
\DoxyCodeLine{2051 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ac211ae488cb6e3c6685df85d24ecd0dd}\label{namespacemom__neutral__diffusion_ac211ae488cb6e3c6685df85d24ecd0dd}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!plm\_diff@{plm\_diff}}
\index{plm\_diff@{plm\_diff}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{plm\_diff()}{plm\_diff()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::plm\+\_\+diff (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{h,  }\item[{real, dimension(nk), intent(in)}]{S,  }\item[{integer, intent(in)}]{c\+\_\+method,  }\item[{integer, intent(in)}]{b\+\_\+method,  }\item[{real, dimension(nk), intent(inout)}]{diff }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns P\+LM slopes for a column where the slopes are the difference in value across each cell. The limiting follows equation 1.\+8 in Colella \& Woodward, 1984\+: J\+CP 54, 174-\/201. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Layer salinity (conc, e.\+g. ppt) \\
\hline
\mbox{\texttt{ in}}  & {\em c\+\_\+method} & Method to use for the centered difference \\
\hline
\mbox{\texttt{ in}}  & {\em b\+\_\+method} & =1, use P\+CM in first/last cell, =2 uses linear extrapolation \\
\hline
\mbox{\texttt{ in,out}}  & {\em diff} & Scalar difference across layer (conc, e.\+g. ppt) determined by the following values for c\+\_\+method\+:
\begin{DoxyEnumerate}
\item Second order finite difference (not recommended)
\item Second order finite volume (used in original P\+PM)
\item Finite-\/volume weighted least squares linear fit 
\end{DoxyEnumerate}\\
\hline
\end{DoxyParams}
\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000008}{Todo}}]The use of c\+\_\+method to choose a scheme is inefficient and should eventually be moved up the call tree. \end{DoxyRefDesc}


Definition at line 808 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{809   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{       !< Number of levels}}
\DoxyCodeLine{810 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{        !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{811 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{        !< Layer salinity (conc, e.g. ppt)}}
\DoxyCodeLine{812   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}    :: c\_method\textcolor{comment}{ !< Method to use for the centered difference}}
\DoxyCodeLine{813   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}    :: b\_method\textcolor{comment}{ !< =1, use PCM in first/last cell, =2 uses linear extrapolation}}
\DoxyCodeLine{814 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(inout)} :: diff\textcolor{comment}{     !< Scalar difference across layer (conc, e.g. ppt)}}
\DoxyCodeLine{815 \textcolor{comment}{                                                 !! determined by the following values for c\_method:}}
\DoxyCodeLine{816 \textcolor{comment}{                                                 !!   1. Second order finite difference (not recommended)}}
\DoxyCodeLine{817 \textcolor{comment}{                                                 !!   2. Second order finite volume (used in original PPM)}}
\DoxyCodeLine{818 \textcolor{comment}{                                                 !!   3. Finite-\/volume weighted least squares linear fit}}
\DoxyCodeLine{819 \textcolor{comment}{                                                 !! \(\backslash\)todo  The use of c\_method to choose a scheme is inefficient}}
\DoxyCodeLine{820 \textcolor{comment}{                                                 !! and should eventually be moved up the call tree.}}
\DoxyCodeLine{821 }
\DoxyCodeLine{822   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{823   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{824 \textcolor{keywordtype}{  real} :: hkm1, hk, hkp1, Skm1, Sk, Skp1, diff\_l, diff\_r, diff\_c}
\DoxyCodeLine{825 }
\DoxyCodeLine{826   \textcolor{keywordflow}{do} k = 2, nk-\/1}
\DoxyCodeLine{827     hkm1 = h(k-\/1)}
\DoxyCodeLine{828     hk = h(k)}
\DoxyCodeLine{829     hkp1 = h(k+1)}
\DoxyCodeLine{830 }
\DoxyCodeLine{831     \textcolor{keywordflow}{if} ( ( hkp1 + hk ) * ( hkm1 + hk ) > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{832       skm1 = s(k-\/1)}
\DoxyCodeLine{833       sk = s(k)}
\DoxyCodeLine{834       skp1 = s(k+1)}
\DoxyCodeLine{835       \textcolor{keywordflow}{if} (c\_method==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{836         \textcolor{comment}{! Simple centered diff (from White)}}
\DoxyCodeLine{837         \textcolor{keywordflow}{if} ( hk + 0.5 * (hkm1 + hkp1) /= 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{838           diff\_c = ( skp1 -\/ skm1 ) * ( hk / ( hk + 0.5 * (hkm1 + hkp1) ) )}
\DoxyCodeLine{839         \textcolor{keywordflow}{else}}
\DoxyCodeLine{840           diff\_c = 0.}
\DoxyCodeLine{841 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{842       \textcolor{keywordflow}{elseif} (c\_method==2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{843         \textcolor{comment}{! Second order accurate centered FV slope (from Colella and Woodward, JCP 1984)}}
\DoxyCodeLine{844         diff\_c = fv\_diff(hkm1, hk, hkp1, skm1, sk, skp1)}
\DoxyCodeLine{845       \textcolor{keywordflow}{elseif} (c\_method==3) \textcolor{keywordflow}{then}}
\DoxyCodeLine{846         \textcolor{comment}{! Second order accurate finite-\/volume least squares slope}}
\DoxyCodeLine{847         diff\_c = hk * fvlsq\_slope(hkm1, hk, hkp1, skm1, sk, skp1)}
\DoxyCodeLine{848 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{849       \textcolor{comment}{! Limit centered slope by twice the side differenced slopes}}
\DoxyCodeLine{850       diff\_l = 2. * ( sk -\/ skm1 )}
\DoxyCodeLine{851       diff\_r = 2. * ( skp1 -\/ sk )}
\DoxyCodeLine{852       \textcolor{keywordflow}{if} ( signum(1., diff\_l) * signum(1., diff\_r) <= 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{853         diff(k) = 0. \textcolor{comment}{! PCM for local extrema}}
\DoxyCodeLine{854       \textcolor{keywordflow}{else}}
\DoxyCodeLine{855         diff(k) = sign( min( abs(diff\_l), abs(diff\_c), abs(diff\_r) ), diff\_c )}
\DoxyCodeLine{856 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{857     \textcolor{keywordflow}{else}}
\DoxyCodeLine{858       diff(k) = 0. \textcolor{comment}{! PCM next to vanished layers}}
\DoxyCodeLine{859 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{860 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{861   \textcolor{keywordflow}{if} (b\_method==1) \textcolor{keywordflow}{then} \textcolor{comment}{! PCM for top and bottom layer}}
\DoxyCodeLine{862     diff(1) = 0.}
\DoxyCodeLine{863     diff(nk) = 0.}
\DoxyCodeLine{864   \textcolor{keywordflow}{elseif} (b\_method==2) \textcolor{keywordflow}{then} \textcolor{comment}{! Linear extrapolation for top and bottom interfaces}}
\DoxyCodeLine{865     diff(1) = ( s(2) -\/ s(1) ) * 2. * ( h(1) / ( h(1) + h(2) ) )}
\DoxyCodeLine{866     diff(nk) = s(nk) -\/ s(nk-\/1) * 2. * ( h(nk) / ( h(nk-\/1) + h(nk) ) )}
\DoxyCodeLine{867 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{868 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a6931d9a07d09aa5d76d5abd2e47a54df}\label{namespacemom__neutral__diffusion_a6931d9a07d09aa5d76d5abd2e47a54df}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!ppm\_ave@{ppm\_ave}}
\index{ppm\_ave@{ppm\_ave}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{ppm\_ave()}{ppm\_ave()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::ppm\+\_\+ave (\begin{DoxyParamCaption}\item[{real, intent(in)}]{xL,  }\item[{real, intent(in)}]{xR,  }\item[{real, intent(in)}]{aL,  }\item[{real, intent(in)}]{aR,  }\item[{real, intent(in)}]{a\+Mean }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the average of a P\+PM reconstruction between two fractional positions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em xl} & Fraction position of left bound (0,1) \\
\hline
\mbox{\texttt{ in}}  & {\em xr} & Fraction position of right bound (0,1) \\
\hline
\mbox{\texttt{ in}}  & {\em al} & Left edge scalar value, at x=0 \\
\hline
\mbox{\texttt{ in}}  & {\em ar} & Right edge scalar value, at x=1 \\
\hline
\mbox{\texttt{ in}}  & {\em amean} & Average scalar value of cell \\
\hline
\end{DoxyParams}


Definition at line 770 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{771 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: xL\textcolor{comment}{    !< Fraction position of left bound (0,1)}}
\DoxyCodeLine{772 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: xR\textcolor{comment}{    !< Fraction position of right bound (0,1)}}
\DoxyCodeLine{773 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: aL\textcolor{comment}{    !< Left edge scalar value, at x=0}}
\DoxyCodeLine{774 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: aR\textcolor{comment}{    !< Right edge scalar value, at x=1}}
\DoxyCodeLine{775 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: aMean\textcolor{comment}{ !< Average scalar value of cell}}
\DoxyCodeLine{776 }
\DoxyCodeLine{777   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{778 \textcolor{keywordtype}{  real} :: dx, xave, a6, a6o3}
\DoxyCodeLine{779 }
\DoxyCodeLine{780   dx = xr -\/ xl}
\DoxyCodeLine{781   xave = 0.5 * ( xr + xl )}
\DoxyCodeLine{782   a6o3 = 2. * amean -\/ ( al + ar ) \textcolor{comment}{! a6 / 3.}}
\DoxyCodeLine{783   a6 = 3. * a6o3}
\DoxyCodeLine{784 }
\DoxyCodeLine{785   \textcolor{keywordflow}{if} (dx<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{786     stop \textcolor{stringliteral}{'ppm\_ave: dx<0 should not happend!'}}
\DoxyCodeLine{787   \textcolor{keywordflow}{elseif} (dx>1.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{788     stop \textcolor{stringliteral}{'ppm\_ave: dx>1 should not happend!'}}
\DoxyCodeLine{789   \textcolor{keywordflow}{elseif} (dx==0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{790     ppm\_ave = al + ( ar -\/ al ) * xr + a6 * xr * ( 1. -\/ xr )}
\DoxyCodeLine{791   \textcolor{keywordflow}{else}}
\DoxyCodeLine{792     ppm\_ave = ( al + xave * ( ( ar -\/ al ) + a6 ) )  -\/ a6o3 * ( xr**2 + xr * xl + xl**2 )}
\DoxyCodeLine{793 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ae931a15b9ab6a7672b005eb5fe382219}\label{namespacemom__neutral__diffusion_ae931a15b9ab6a7672b005eb5fe382219}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!ppm\_edge@{ppm\_edge}}
\index{ppm\_edge@{ppm\_edge}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{ppm\_edge()}{ppm\_edge()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::ppm\+\_\+edge (\begin{DoxyParamCaption}\item[{real, intent(in)}]{hkm1,  }\item[{real, intent(in)}]{hk,  }\item[{real, intent(in)}]{hkp1,  }\item[{real, intent(in)}]{hkp2,  }\item[{real, intent(in)}]{Ak,  }\item[{real, intent(in)}]{Akp1,  }\item[{real, intent(in)}]{Pk,  }\item[{real, intent(in)}]{Pkp1,  }\item[{real, intent(in)}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the P\+PM quasi-\/fourth order edge value at k+1/2 following equation 1.\+6 in Colella \& Woodward, 1984\+: J\+CP 54, 174-\/201. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hkm1} & Width of cell k-\/1 \\
\hline
\mbox{\texttt{ in}}  & {\em hk} & Width of cell k \\
\hline
\mbox{\texttt{ in}}  & {\em hkp1} & Width of cell k+1 \\
\hline
\mbox{\texttt{ in}}  & {\em hkp2} & Width of cell k+2 \\
\hline
\mbox{\texttt{ in}}  & {\em ak} & Average scalar value of cell k \\
\hline
\mbox{\texttt{ in}}  & {\em akp1} & Average scalar value of cell k+1 \\
\hline
\mbox{\texttt{ in}}  & {\em pk} & P\+LM slope for cell k \\
\hline
\mbox{\texttt{ in}}  & {\em pkp1} & P\+LM slope for cell k+1 \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 730 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{731 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkm1\textcolor{comment}{ !< Width of cell k-\/1}}
\DoxyCodeLine{732 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hk\textcolor{comment}{   !< Width of cell k}}
\DoxyCodeLine{733 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkp1\textcolor{comment}{ !< Width of cell k+1}}
\DoxyCodeLine{734 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: hkp2\textcolor{comment}{ !< Width of cell k+2}}
\DoxyCodeLine{735 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Ak\textcolor{comment}{   !< Average scalar value of cell k}}
\DoxyCodeLine{736 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Akp1\textcolor{comment}{ !< Average scalar value of cell k+1}}
\DoxyCodeLine{737 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Pk\textcolor{comment}{   !< PLM slope for cell k}}
\DoxyCodeLine{738 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Pkp1\textcolor{comment}{ !< PLM slope for cell k+1}}
\DoxyCodeLine{739 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: h\_neglect\textcolor{comment}{ !< A negligibly small thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{740 }
\DoxyCodeLine{741   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{742 \textcolor{keywordtype}{  real} :: R\_hk\_hkp1, R\_2hk\_hkp1, R\_hk\_2hkp1, f1, f2, f3, f4}
\DoxyCodeLine{743 }
\DoxyCodeLine{744   r\_hk\_hkp1 = hk + hkp1}
\DoxyCodeLine{745   \textcolor{keywordflow}{if} (r\_hk\_hkp1 <= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{746     ppm\_edge = 0.5 * ( ak + akp1 )}
\DoxyCodeLine{747     \textcolor{keywordflow}{return}}
\DoxyCodeLine{748 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{749   r\_hk\_hkp1 = 1. / r\_hk\_hkp1}
\DoxyCodeLine{750   \textcolor{keywordflow}{if} (hk<hkp1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{751     ppm\_edge = ak + ( hk * r\_hk\_hkp1 ) * ( akp1 -\/ ak )}
\DoxyCodeLine{752   \textcolor{keywordflow}{else}}
\DoxyCodeLine{753     ppm\_edge = akp1 + ( hkp1 * r\_hk\_hkp1 ) * ( ak -\/ akp1 )}
\DoxyCodeLine{754 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{755 }
\DoxyCodeLine{756   r\_2hk\_hkp1 = 1. / ( ( 2. * hk + hkp1 ) + h\_neglect )}
\DoxyCodeLine{757   r\_hk\_2hkp1 = 1. / ( ( hk + 2. * hkp1 ) + h\_neglect )}
\DoxyCodeLine{758   f1 = 1./ ( ( hk + hkp1) + ( hkm1 + hkp2 ) )}
\DoxyCodeLine{759   f2 = 2. * ( hkp1 * hk ) * r\_hk\_hkp1 * \&}
\DoxyCodeLine{760             ( ( hkm1 + hk ) * r\_2hk\_hkp1  -\/ ( hkp2 + hkp1 ) * r\_hk\_2hkp1 )}
\DoxyCodeLine{761   f3 = hk * ( hkm1 + hk ) * r\_2hk\_hkp1}
\DoxyCodeLine{762   f4 = hkp1 * ( hkp1 + hkp2 ) * r\_hk\_2hkp1}
\DoxyCodeLine{763 }
\DoxyCodeLine{764   ppm\_edge = ppm\_edge + f1 * ( f2 * ( akp1 -\/ ak ) -\/ ( f3 * pkp1 -\/ f4 * pk ) )}
\DoxyCodeLine{765 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a9b380e21dcc9c53efcec4712228b931f}\label{namespacemom__neutral__diffusion_a9b380e21dcc9c53efcec4712228b931f}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!ppm\_left\_right\_edge\_values@{ppm\_left\_right\_edge\_values}}
\index{ppm\_left\_right\_edge\_values@{ppm\_left\_right\_edge\_values}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{ppm\_left\_right\_edge\_values()}{ppm\_left\_right\_edge\_values()}}
{\footnotesize\ttfamily subroutine mom\+\_\+neutral\+\_\+diffusion\+::ppm\+\_\+left\+\_\+right\+\_\+edge\+\_\+values (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{Tl,  }\item[{real, dimension(nk+1), intent(in)}]{Ti,  }\item[{real, dimension(nk), intent(inout)}]{aL,  }\item[{real, dimension(nk), intent(inout)}]{aR }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Discontinuous P\+PM reconstructions of the left/right edge values within a cell. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em tl} & Layer tracer (conc, e.\+g. degC) \\
\hline
\mbox{\texttt{ in}}  & {\em ti} & Interface tracer (conc, e.\+g. degC) \\
\hline
\mbox{\texttt{ in,out}}  & {\em al} & Left edge value of tracer (conc, e.\+g. degC) \\
\hline
\mbox{\texttt{ in,out}}  & {\em ar} & Right edge value of tracer (conc, e.\+g. degC) \\
\hline
\end{DoxyParams}


Definition at line 2055 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2056   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{ !< Number of levels}}
\DoxyCodeLine{2057 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},        \textcolor{keywordtype}{intent(in)}    :: Tl\textcolor{comment}{ !< Layer tracer (conc, e.g. degC)}}
\DoxyCodeLine{2058 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},      \textcolor{keywordtype}{intent(in)}    :: Ti\textcolor{comment}{ !< Interface tracer (conc, e.g. degC)}}
\DoxyCodeLine{2059 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},        \textcolor{keywordtype}{intent(inout)} :: aL\textcolor{comment}{ !< Left edge value of tracer (conc, e.g. degC)}}
\DoxyCodeLine{2060 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},        \textcolor{keywordtype}{intent(inout)} :: aR\textcolor{comment}{ !< Right edge value of tracer (conc, e.g. degC)}}
\DoxyCodeLine{2061 }
\DoxyCodeLine{2062   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{2063   \textcolor{comment}{! Setup reconstruction edge values}}
\DoxyCodeLine{2064   \textcolor{keywordflow}{do} k = 1, nk}
\DoxyCodeLine{2065     al(k) = ti(k)}
\DoxyCodeLine{2066     ar(k) = ti(k+1)}
\DoxyCodeLine{2067     \textcolor{keywordflow}{if} ( signum(1., ar(k) -\/ tl(k))*signum(1., tl(k) -\/ al(k)) <= 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2068       al(k) = tl(k)}
\DoxyCodeLine{2069       ar(k) = tl(k)}
\DoxyCodeLine{2070     \textcolor{keywordflow}{elseif} ( sign(3., ar(k) -\/ al(k)) * ( (tl(k) -\/ al(k)) + (tl(k) -\/ ar(k))) > abs(ar(k) -\/ al(k)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2071       al(k) = tl(k) + 2.0 * ( tl(k) -\/ ar(k) )}
\DoxyCodeLine{2072     \textcolor{keywordflow}{elseif} ( sign(3., ar(k) -\/ al(k)) * ( (tl(k) -\/ al(k)) + (tl(k) -\/ ar(k))) < -\/abs(ar(k) -\/ al(k)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2073       ar(k) = tl(k) + 2.0 * ( tl(k) -\/ al(k) )}
\DoxyCodeLine{2074 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2075 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a2952cbcce84dbdae01fce09240f819c5}\label{namespacemom__neutral__diffusion_a2952cbcce84dbdae01fce09240f819c5}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!search\_other\_column@{search\_other\_column}}
\index{search\_other\_column@{search\_other\_column}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{search\_other\_column()}{search\_other\_column()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::search\+\_\+other\+\_\+column (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__neutral__diffusion_1_1neutral__diffusion__cs}{neutral\+\_\+diffusion\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{ksurf,  }\item[{real, intent(in)}]{pos\+\_\+last,  }\item[{real, intent(in)}]{T\+\_\+from,  }\item[{real, intent(in)}]{S\+\_\+from,  }\item[{real, intent(in)}]{P\+\_\+from,  }\item[{real, intent(in)}]{T\+\_\+top,  }\item[{real, intent(in)}]{S\+\_\+top,  }\item[{real, intent(in)}]{P\+\_\+top,  }\item[{real, intent(in)}]{T\+\_\+bot,  }\item[{real, intent(in)}]{S\+\_\+bot,  }\item[{real, intent(in)}]{P\+\_\+bot,  }\item[{real, dimension(\+:), intent(in)}]{T\+\_\+poly,  }\item[{real, dimension(\+:), intent(in)}]{S\+\_\+poly }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Searches the \char`\"{}other\char`\"{} (searched) column for the position of the neutral surface. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Neutral diffusion control structure \\
\hline
\mbox{\texttt{ in}}  & {\em ksurf} & Current index of neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em pos\+\_\+last} & Last position within the current layer, used as the lower bound in the root finding algorithm \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+from} & Temperature at the searched from interface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+from} & Salinity at the searched from interface \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+from} & Pressure at the searched from interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+top} & Temperature at the searched to top interface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+top} & Salinity at the searched to top interface \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+top} & Pressure at the searched to top interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+bot} & Temperature at the searched to bottom interface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+bot} & Salinity at the searched to bottom interface \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+bot} & Pressure at the searched to bottom interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+poly} & Temperature polynomial reconstruction coefficients \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+poly} & Salinity polynomial reconstruction coefficients \mbox{[}ppt\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1437 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1439   \textcolor{keywordtype}{type}(neutral\_diffusion\_CS), \textcolor{keywordtype}{intent(in   )} :: CS\textcolor{comment}{       !< Neutral diffusion control structure}}
\DoxyCodeLine{1440   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in   )} :: ksurf\textcolor{comment}{    !< Current index of neutral surface}}
\DoxyCodeLine{1441 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: pos\_last\textcolor{comment}{ !< Last position within the current layer, used as the lower}}
\DoxyCodeLine{1442 \textcolor{comment}{                                                        !! bound in the root finding algorithm [nondim]}}
\DoxyCodeLine{1443 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: T\_from\textcolor{comment}{   !< Temperature at the searched from interface [degC]}}
\DoxyCodeLine{1444 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: S\_from\textcolor{comment}{   !< Salinity    at the searched from interface [ppt]}}
\DoxyCodeLine{1445 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: P\_from\textcolor{comment}{   !< Pressure at the searched from interface [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1446 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: T\_top\textcolor{comment}{    !< Temperature at the searched to top interface [degC]}}
\DoxyCodeLine{1447 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: S\_top\textcolor{comment}{    !< Salinity    at the searched to top interface [ppt]}}
\DoxyCodeLine{1448 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: P\_top\textcolor{comment}{    !< Pressure at the searched to top interface [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1449 \textcolor{comment}{                                                        !! interface [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1450 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: T\_bot\textcolor{comment}{    !< Temperature at the searched to bottom interface [degC]}}
\DoxyCodeLine{1451 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: S\_bot\textcolor{comment}{    !< Salinity    at the searched to bottom interface [ppt]}}
\DoxyCodeLine{1452 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in   )} :: P\_bot\textcolor{comment}{    !< Pressure at the searched to bottom}}
\DoxyCodeLine{1453 \textcolor{comment}{                                                        !! interface [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1454 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},         \textcolor{keywordtype}{intent(in   )} :: T\_poly\textcolor{comment}{   !< Temperature polynomial reconstruction coefficients [degC]}}
\DoxyCodeLine{1455 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},         \textcolor{keywordtype}{intent(in   )} :: S\_poly\textcolor{comment}{   !< Salinity    polynomial reconstruction coefficients [ppt]}}
\DoxyCodeLine{1456   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1457 \textcolor{keywordtype}{  real} :: dRhotop, dRhobot \textcolor{comment}{! Density differences [R \string~> kg m-\/3]}}
\DoxyCodeLine{1458 \textcolor{keywordtype}{  real} :: dRdT\_top, dRdT\_bot, dRdT\_from \textcolor{comment}{! Partial derivatives of density with temperature [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{1459 \textcolor{keywordtype}{  real} :: dRdS\_top, dRdS\_bot, dRdS\_from \textcolor{comment}{! Partial derivatives of density with salinity [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{1460 }
\DoxyCodeLine{1461   \textcolor{comment}{! Calculate the differencei in density at the tops or the bottom}}
\DoxyCodeLine{1462   \textcolor{keywordflow}{if} (cs\%neutral\_pos\_method == 1 .or. cs\%neutral\_pos\_method == 3) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1463     \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, t\_top, s\_top, p\_top, t\_from, s\_from, p\_from, drhotop)}
\DoxyCodeLine{1464     \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, t\_bot, s\_bot, p\_bot, t\_from, s\_from, p\_from, drhobot)}
\DoxyCodeLine{1465   \textcolor{keywordflow}{elseif} (cs\%neutral\_pos\_method == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1466     \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, t\_top, s\_top, p\_top, t\_from, s\_from, p\_from, drhotop, \&}
\DoxyCodeLine{1467                                    drdt\_top, drds\_top, drdt\_from, drds\_from)}
\DoxyCodeLine{1468     \textcolor{keyword}{call }calc\_delta\_rho\_and\_derivs(cs, t\_bot, s\_bot, p\_bot, t\_from, s\_from, p\_from, drhobot, \&}
\DoxyCodeLine{1469                                    drdt\_bot, drds\_bot, drdt\_from, drds\_from)}
\DoxyCodeLine{1470 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1471 }
\DoxyCodeLine{1472   \textcolor{comment}{! Handle all the special cases EXCEPT if it connects within the layer}}
\DoxyCodeLine{1473   \textcolor{keywordflow}{if} ( (drhotop > 0.) .or. (ksurf == 1) ) \textcolor{keywordflow}{then}      \textcolor{comment}{! First interface or lighter than anything in layer}}
\DoxyCodeLine{1474     pos = pos\_last}
\DoxyCodeLine{1475   \textcolor{keywordflow}{elseif} ( drhotop > drhobot ) \textcolor{keywordflow}{then}                 \textcolor{comment}{! Unstably stratified}}
\DoxyCodeLine{1476     pos = 1.}
\DoxyCodeLine{1477   \textcolor{keywordflow}{elseif} ( drhotop < 0. .and. drhobot < 0.) \textcolor{keywordflow}{then}    \textcolor{comment}{! Denser than anything in layer}}
\DoxyCodeLine{1478     pos = 1.}
\DoxyCodeLine{1479   \textcolor{keywordflow}{elseif} ( drhotop == 0. .and. drhobot == 0. ) \textcolor{keywordflow}{then} \textcolor{comment}{! Perfectly unstratified}}
\DoxyCodeLine{1480     pos = 1.}
\DoxyCodeLine{1481   \textcolor{keywordflow}{elseif} ( drhobot == 0. ) \textcolor{keywordflow}{then}                     \textcolor{comment}{! Matches perfectly at the Top}}
\DoxyCodeLine{1482     pos = 1.}
\DoxyCodeLine{1483   \textcolor{keywordflow}{elseif} ( drhotop == 0. ) \textcolor{keywordflow}{then}                     \textcolor{comment}{! Matches perfectly at the Bottom}}
\DoxyCodeLine{1484     pos = pos\_last}
\DoxyCodeLine{1485   \textcolor{keywordflow}{else}                                              \textcolor{comment}{! Neutral surface within layer}}
\DoxyCodeLine{1486     pos = -\/1}
\DoxyCodeLine{1487 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1488 }
\DoxyCodeLine{1489   \textcolor{comment}{! Can safely return if position is >= 0 otherwise will need to find the position within the layer}}
\DoxyCodeLine{1490   \textcolor{keywordflow}{if} (pos>=0) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1491 }
\DoxyCodeLine{1492   \textcolor{keywordflow}{if} (cs\%neutral\_pos\_method==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1493     pos = interpolate\_for\_nondim\_position( drhotop, p\_top, drhobot, p\_bot )}
\DoxyCodeLine{1494   \textcolor{comment}{! For the 'Linear' case of finding the neutral position, the fromerence pressure to use is the average}}
\DoxyCodeLine{1495   \textcolor{comment}{! of the midpoint of the layer being searched and the interface being searched from}}
\DoxyCodeLine{1496   \textcolor{keywordflow}{elseif} (cs\%neutral\_pos\_method == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1497     pos = find\_neutral\_pos\_linear( cs, pos\_last, t\_from, s\_from, drdt\_from, drds\_from, \&}
\DoxyCodeLine{1498                                    drdt\_top, drds\_top, drdt\_bot, drds\_bot, t\_poly, s\_poly )}
\DoxyCodeLine{1499   \textcolor{keywordflow}{elseif} (cs\%neutral\_pos\_method == 3) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1500     pos = find\_neutral\_pos\_full( cs, pos\_last, t\_from, s\_from, p\_from, p\_top, p\_bot, t\_poly, s\_poly)}
\DoxyCodeLine{1501 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1502 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a118ace85483009d5b7a1841e3c745499}\label{namespacemom__neutral__diffusion_a118ace85483009d5b7a1841e3c745499}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!signum@{signum}}
\index{signum@{signum}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{signum()}{signum()}}
{\footnotesize\ttfamily real function mom\+\_\+neutral\+\_\+diffusion\+::signum (\begin{DoxyParamCaption}\item[{real, intent(in)}]{a,  }\item[{real, intent(in)}]{x }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



A true signum function that returns either -\/abs(a), when x$<$0; or abs(a) when x$>$0; or 0 when x=0. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em a} & The magnitude argument \\
\hline
\mbox{\texttt{ in}}  & {\em x} & The sign (or zero) argument \\
\hline
\end{DoxyParams}


Definition at line 797 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{798 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: a\textcolor{comment}{ !< The magnitude argument}}
\DoxyCodeLine{799 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{ !< The sign (or zero) argument}}
\DoxyCodeLine{800 }
\DoxyCodeLine{801   signum = sign(a,x)}
\DoxyCodeLine{802   \textcolor{keywordflow}{if} (x==0.) signum = 0.}
\DoxyCodeLine{803 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a2870eae4b580e548577943e34321b8f0}\label{namespacemom__neutral__diffusion_a2870eae4b580e548577943e34321b8f0}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_data1d@{test\_data1d}}
\index{test\_data1d@{test\_data1d}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_data1d()}{test\_data1d()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+data1d (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{Po,  }\item[{real, dimension(nk), intent(in)}]{Ptrue,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if comparison of Po and Ptrue fails, and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers \\
\hline
\mbox{\texttt{ in}}  & {\em po} & Calculated answer \\
\hline
\mbox{\texttt{ in}}  & {\em ptrue} & True answer \\
\hline
\mbox{\texttt{ in}}  & {\em title} & Title for messages \\
\hline
\end{DoxyParams}


Definition at line 2705 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2706   \textcolor{keywordtype}{logical},             \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2707   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{    !< Number of layers}}
\DoxyCodeLine{2708 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in)} :: Po\textcolor{comment}{    !< Calculated answer}}
\DoxyCodeLine{2709 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in)} :: Ptrue\textcolor{comment}{ !< True answer}}
\DoxyCodeLine{2710   \textcolor{keywordtype}{character(len=*)},    \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{ !< Title for messages}}
\DoxyCodeLine{2711 }
\DoxyCodeLine{2712   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2713   \textcolor{keywordtype}{integer} :: k, stdunit}
\DoxyCodeLine{2714 }
\DoxyCodeLine{2715   test\_data1d = .false.}
\DoxyCodeLine{2716   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{2717     \textcolor{keywordflow}{if} (po(k) /= ptrue(k)) test\_data1d = .true.}
\DoxyCodeLine{2718 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2719 }
\DoxyCodeLine{2720   \textcolor{keywordflow}{if} (test\_data1d .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2721     stdunit = stdout}
\DoxyCodeLine{2722     \textcolor{keywordflow}{if} (test\_data1d) stdunit = stderr \textcolor{comment}{! In case of wrong results, write to error stream}}
\DoxyCodeLine{2723     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a)'}) title}
\DoxyCodeLine{2724     \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{2725       \textcolor{keywordflow}{if} (po(k) /= ptrue(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2726         test\_data1d = .true.}
\DoxyCodeLine{2727         \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a,i2,2(x,a,f20.16),x,a,1pe22.15,x,a)'}) \&}
\DoxyCodeLine{2728               \textcolor{stringliteral}{'k='},k,\textcolor{stringliteral}{'Po='},po(k),\textcolor{stringliteral}{'Ptrue='},ptrue(k),\textcolor{stringliteral}{'err='},po(k)-\/ptrue(k),\textcolor{stringliteral}{'WRONG!'}}
\DoxyCodeLine{2729       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2730         \textcolor{keywordflow}{if} (verbose) \&}
\DoxyCodeLine{2731           \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a,i2,2(x,a,f20.16),x,a,1pe22.15)'}) \&}
\DoxyCodeLine{2732                 \textcolor{stringliteral}{'k='},k,\textcolor{stringliteral}{'Po='},po(k),\textcolor{stringliteral}{'Ptrue='},ptrue(k),\textcolor{stringliteral}{'err='},po(k)-\/ptrue(k)}
\DoxyCodeLine{2733 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2734 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2735 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2736 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_aaa2d682e80cdba470a09bcff6bda1767}\label{namespacemom__neutral__diffusion_aaa2d682e80cdba470a09bcff6bda1767}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_data1di@{test\_data1di}}
\index{test\_data1di@{test\_data1di}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_data1di()}{test\_data1di()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+data1di (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{integer, intent(in)}]{nk,  }\item[{integer, dimension(nk), intent(in)}]{Po,  }\item[{integer, dimension(nk), intent(in)}]{Ptrue,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if comparison of Po and Ptrue fails, and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers \\
\hline
\mbox{\texttt{ in}}  & {\em po} & Calculated answer \\
\hline
\mbox{\texttt{ in}}  & {\em ptrue} & True answer \\
\hline
\mbox{\texttt{ in}}  & {\em title} & Title for messages \\
\hline
\end{DoxyParams}


Definition at line 2740 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2741   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2742   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{    !< Number of layers}}
\DoxyCodeLine{2743   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in)} :: Po\textcolor{comment}{    !< Calculated answer}}
\DoxyCodeLine{2744   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in)} :: Ptrue\textcolor{comment}{ !< True answer}}
\DoxyCodeLine{2745   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{ !< Title for messages}}
\DoxyCodeLine{2746 }
\DoxyCodeLine{2747   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2748   \textcolor{keywordtype}{integer} :: k, stdunit}
\DoxyCodeLine{2749 }
\DoxyCodeLine{2750   test\_data1di = .false.}
\DoxyCodeLine{2751   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{2752     \textcolor{keywordflow}{if} (po(k) /= ptrue(k)) test\_data1di = .true.}
\DoxyCodeLine{2753 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2754 }
\DoxyCodeLine{2755   \textcolor{keywordflow}{if} (test\_data1di .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2756     stdunit = stdout}
\DoxyCodeLine{2757     \textcolor{keywordflow}{if} (test\_data1di) stdunit = stderr \textcolor{comment}{! In case of wrong results, write to error stream}}
\DoxyCodeLine{2758     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a)'}) title}
\DoxyCodeLine{2759     \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{2760       \textcolor{keywordflow}{if} (po(k) /= ptrue(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2761         test\_data1di = .true.}
\DoxyCodeLine{2762         \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a,i2,2(x,a,i5),x,a)'}) \textcolor{stringliteral}{'k='},k,\textcolor{stringliteral}{'Io='},po(k),\textcolor{stringliteral}{'Itrue='},ptrue(k),\textcolor{stringliteral}{'WRONG!'}}
\DoxyCodeLine{2763       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2764         \textcolor{keywordflow}{if} (verbose) \&}
\DoxyCodeLine{2765           \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a,i2,2(x,a,i5))'}) \textcolor{stringliteral}{'k='},k,\textcolor{stringliteral}{'Io='},po(k),\textcolor{stringliteral}{'Itrue='},ptrue(k)}
\DoxyCodeLine{2766 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2767 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2768 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2769 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ac51219df490c739774d70d9958bae047}\label{namespacemom__neutral__diffusion_ac51219df490c739774d70d9958bae047}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_fv\_diff@{test\_fv\_diff}}
\index{test\_fv\_diff@{test\_fv\_diff}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_fv\_diff()}{test\_fv\_diff()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+fv\+\_\+diff (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{real, intent(in)}]{hkm1,  }\item[{real, intent(in)}]{hk,  }\item[{real, intent(in)}]{hkp1,  }\item[{real, intent(in)}]{Skm1,  }\item[{real, intent(in)}]{Sk,  }\item[{real, intent(in)}]{Skp1,  }\item[{real, intent(in)}]{Ptrue,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if a test of \mbox{\hyperlink{namespacemom__neutral__diffusion_a1c5ac28d7c54581cdd872fe58ef0b204}{fv\+\_\+diff()}} fails, and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em hkm1} & Left cell width \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hk} & Center cell width \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hkp1} & Right cell width \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em skm1} & Left cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em sk} & Center cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em skp1} & Right cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em ptrue} & True answer \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em title} & Title for messages \\
\hline
\end{DoxyParams}


Definition at line 2609 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2610   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2611 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: hkm1\textcolor{comment}{  !< Left cell width [nondim]}}
\DoxyCodeLine{2612 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: hk\textcolor{comment}{    !< Center cell width [nondim]}}
\DoxyCodeLine{2613 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: hkp1\textcolor{comment}{  !< Right cell width [nondim]}}
\DoxyCodeLine{2614 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Skm1\textcolor{comment}{  !< Left cell average value}}
\DoxyCodeLine{2615 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Sk\textcolor{comment}{    !< Center cell average value}}
\DoxyCodeLine{2616 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Skp1\textcolor{comment}{  !< Right cell average value}}
\DoxyCodeLine{2617 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Ptrue\textcolor{comment}{ !< True answer [nondim]}}
\DoxyCodeLine{2618   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{ !< Title for messages}}
\DoxyCodeLine{2619 }
\DoxyCodeLine{2620   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2621   \textcolor{keywordtype}{integer} :: stdunit}
\DoxyCodeLine{2622 \textcolor{keywordtype}{  real} :: Pret}
\DoxyCodeLine{2623 }
\DoxyCodeLine{2624   pret = fv\_diff(hkm1, hk, hkp1, skm1, sk, skp1)}
\DoxyCodeLine{2625   test\_fv\_diff = (pret /= ptrue)}
\DoxyCodeLine{2626 }
\DoxyCodeLine{2627   \textcolor{keywordflow}{if} (test\_fv\_diff .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2628     stdunit = stdout}
\DoxyCodeLine{2629     \textcolor{keywordflow}{if} (test\_fv\_diff) stdunit = stderr \textcolor{comment}{! In case of wrong results, write to error stream}}
\DoxyCodeLine{2630     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a)'}) title}
\DoxyCodeLine{2631     \textcolor{keywordflow}{if} (test\_fv\_diff) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2632       \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(2(x,a,f20.16),x,a)'}) \textcolor{stringliteral}{'pRet='},pret,\textcolor{stringliteral}{'pTrue='},ptrue,\textcolor{stringliteral}{'WRONG!'}}
\DoxyCodeLine{2633     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2634       \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(2(x,a,f20.16))'}) \textcolor{stringliteral}{'pRet='},pret,\textcolor{stringliteral}{'pTrue='},ptrue}
\DoxyCodeLine{2635 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2636 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2637 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ad964ab49cd5901b79dc32f2367d24aed}\label{namespacemom__neutral__diffusion_ad964ab49cd5901b79dc32f2367d24aed}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_fvlsq\_slope@{test\_fvlsq\_slope}}
\index{test\_fvlsq\_slope@{test\_fvlsq\_slope}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_fvlsq\_slope()}{test\_fvlsq\_slope()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+fvlsq\+\_\+slope (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{real, intent(in)}]{hkm1,  }\item[{real, intent(in)}]{hk,  }\item[{real, intent(in)}]{hkp1,  }\item[{real, intent(in)}]{Skm1,  }\item[{real, intent(in)}]{Sk,  }\item[{real, intent(in)}]{Skp1,  }\item[{real, intent(in)}]{Ptrue,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if a test of \mbox{\hyperlink{namespacemom__neutral__diffusion_a6ed3814088af470ad6fc4a3a80926fd7}{fvlsq\+\_\+slope()}} fails, and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em hkm1} & Left cell width \\
\hline
\mbox{\texttt{ in}}  & {\em hk} & Center cell width \\
\hline
\mbox{\texttt{ in}}  & {\em hkp1} & Right cell width \\
\hline
\mbox{\texttt{ in}}  & {\em skm1} & Left cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em sk} & Center cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em skp1} & Right cell average value \\
\hline
\mbox{\texttt{ in}}  & {\em ptrue} & True answer \\
\hline
\mbox{\texttt{ in}}  & {\em title} & Title for messages \\
\hline
\end{DoxyParams}


Definition at line 2641 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2642   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2643 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: hkm1\textcolor{comment}{  !< Left cell width}}
\DoxyCodeLine{2644 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: hk\textcolor{comment}{    !< Center cell width}}
\DoxyCodeLine{2645 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: hkp1\textcolor{comment}{  !< Right cell width}}
\DoxyCodeLine{2646 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Skm1\textcolor{comment}{  !< Left cell average value}}
\DoxyCodeLine{2647 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Sk\textcolor{comment}{    !< Center cell average value}}
\DoxyCodeLine{2648 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Skp1\textcolor{comment}{  !< Right cell average value}}
\DoxyCodeLine{2649 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Ptrue\textcolor{comment}{ !< True answer}}
\DoxyCodeLine{2650   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{ !< Title for messages}}
\DoxyCodeLine{2651 }
\DoxyCodeLine{2652   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2653   \textcolor{keywordtype}{integer} :: stdunit}
\DoxyCodeLine{2654 \textcolor{keywordtype}{  real} :: Pret}
\DoxyCodeLine{2655 }
\DoxyCodeLine{2656   pret = fvlsq\_slope(hkm1, hk, hkp1, skm1, sk, skp1)}
\DoxyCodeLine{2657   test\_fvlsq\_slope = (pret /= ptrue)}
\DoxyCodeLine{2658 }
\DoxyCodeLine{2659   \textcolor{keywordflow}{if} (test\_fvlsq\_slope .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2660     stdunit = stdout}
\DoxyCodeLine{2661     \textcolor{keywordflow}{if} (test\_fvlsq\_slope) stdunit = stderr \textcolor{comment}{! In case of wrong results, write to error stream}}
\DoxyCodeLine{2662     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a)'}) title}
\DoxyCodeLine{2663     \textcolor{keywordflow}{if} (test\_fvlsq\_slope) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2664       \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(2(x,a,f20.16),x,a)'}) \textcolor{stringliteral}{'pRet='},pret,\textcolor{stringliteral}{'pTrue='},ptrue,\textcolor{stringliteral}{'WRONG!'}}
\DoxyCodeLine{2665     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2666       \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(2(x,a,f20.16))'}) \textcolor{stringliteral}{'pRet='},pret,\textcolor{stringliteral}{'pTrue='},ptrue}
\DoxyCodeLine{2667 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2668 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2669 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_a1a21234946c77d1e4ed852a4173503f1}\label{namespacemom__neutral__diffusion_a1a21234946c77d1e4ed852a4173503f1}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_ifndp@{test\_ifndp}}
\index{test\_ifndp@{test\_ifndp}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_ifndp()}{test\_ifndp()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+ifndp (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{real, intent(in)}]{rho\+Neg,  }\item[{real, intent(in)}]{Pneg,  }\item[{real, intent(in)}]{rho\+Pos,  }\item[{real, intent(in)}]{Ppos,  }\item[{real, intent(in)}]{Ptrue,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if a test of \mbox{\hyperlink{namespacemom__neutral__diffusion_a666836e70bdae7ef4ec271246cf91993}{interpolate\+\_\+for\+\_\+nondim\+\_\+position()}} fails, and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em rhoneg} & Lighter density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pneg} & Interface position of lighter density \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rhopos} & Heavier density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppos} & Interface position of heavier density \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ptrue} & True answer \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em title} & Title for messages \\
\hline
\end{DoxyParams}


Definition at line 2673 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2674   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2675 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: rhoNeg\textcolor{comment}{ !< Lighter density [R \string~> kg m-\/3]}}
\DoxyCodeLine{2676 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Pneg\textcolor{comment}{   !< Interface position of lighter density [nondim]}}
\DoxyCodeLine{2677 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: rhoPos\textcolor{comment}{ !< Heavier density [R \string~> kg m-\/3]}}
\DoxyCodeLine{2678 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Ppos\textcolor{comment}{   !< Interface position of heavier density [nondim]}}
\DoxyCodeLine{2679 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: Ptrue\textcolor{comment}{  !< True answer [nondim]}}
\DoxyCodeLine{2680   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{  !< Title for messages}}
\DoxyCodeLine{2681 }
\DoxyCodeLine{2682   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2683   \textcolor{keywordtype}{integer} :: stdunit}
\DoxyCodeLine{2684 \textcolor{keywordtype}{  real} :: Pret}
\DoxyCodeLine{2685 }
\DoxyCodeLine{2686   pret = interpolate\_for\_nondim\_position(rhoneg, pneg, rhopos, ppos)}
\DoxyCodeLine{2687   test\_ifndp = (pret /= ptrue)}
\DoxyCodeLine{2688 }
\DoxyCodeLine{2689   \textcolor{keywordflow}{if} (test\_ifndp .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2690     stdunit = stdout}
\DoxyCodeLine{2691     \textcolor{keywordflow}{if} (test\_ifndp) stdunit = stderr \textcolor{comment}{! In case of wrong results, write to error stream}}
\DoxyCodeLine{2692     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a)'}) title}
\DoxyCodeLine{2693     \textcolor{keywordflow}{if} (test\_ifndp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2694       \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(4(x,a,f20.16),2(x,a,1pe22.15),x,a)'}) \&}
\DoxyCodeLine{2695             \textcolor{stringliteral}{'r1='},rhoneg,\textcolor{stringliteral}{'p1='},pneg,\textcolor{stringliteral}{'r2='},rhopos,\textcolor{stringliteral}{'p2='},ppos,\textcolor{stringliteral}{'pRet='},pret,\textcolor{stringliteral}{'pTrue='},ptrue,\textcolor{stringliteral}{'WRONG!'}}
\DoxyCodeLine{2696     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2697       \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(4(x,a,f20.16),2(x,a,1pe22.15))'}) \&}
\DoxyCodeLine{2698             \textcolor{stringliteral}{'r1='},rhoneg,\textcolor{stringliteral}{'p1='},pneg,\textcolor{stringliteral}{'r2='},rhopos,\textcolor{stringliteral}{'p2='},ppos,\textcolor{stringliteral}{'pRet='},pret,\textcolor{stringliteral}{'pTrue='},ptrue}
\DoxyCodeLine{2699 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2700 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2701 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ab5eaa2002c1f6405f5037645bbca3101}\label{namespacemom__neutral__diffusion_ab5eaa2002c1f6405f5037645bbca3101}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_nsp@{test\_nsp}}
\index{test\_nsp@{test\_nsp}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_nsp()}{test\_nsp()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+nsp (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{integer, intent(in)}]{ns,  }\item[{integer, dimension(ns), intent(in)}]{KoL,  }\item[{integer, dimension(ns), intent(in)}]{KoR,  }\item[{real, dimension(ns), intent(in)}]{pL,  }\item[{real, dimension(ns), intent(in)}]{pR,  }\item[{real, dimension(ns-\/1), intent(in)}]{h\+Eff,  }\item[{integer, dimension(ns), intent(in)}]{Ko\+L0,  }\item[{integer, dimension(ns), intent(in)}]{Ko\+R0,  }\item[{real, dimension(ns), intent(in)}]{p\+L0,  }\item[{real, dimension(ns), intent(in)}]{p\+R0,  }\item[{real, dimension(ns-\/1), intent(in)}]{h\+Eff0,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if output of find\+\_\+neutral\+\_\+surface\+\_\+positions() does not match correct values, and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em ns} & Number of surfaces \\
\hline
\mbox{\texttt{ in}}  & {\em kol} & Index of first left interface above neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em kor} & Index of first right interface above neutral surface \\
\hline
\mbox{\texttt{ in}}  & {\em pl} & Fractional position of neutral surface within layer KoL of left column \\
\hline
\mbox{\texttt{ in}}  & {\em pr} & Fractional position of neutral surface within layer KoR of right column \\
\hline
\mbox{\texttt{ in}}  & {\em heff} & Effective thickness between two neutral surfaces \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em kol0} & Correct value for KoL \\
\hline
\mbox{\texttt{ in}}  & {\em kor0} & Correct value for KoR \\
\hline
\mbox{\texttt{ in}}  & {\em pl0} & Correct value for pL \\
\hline
\mbox{\texttt{ in}}  & {\em pr0} & Correct value for pR \\
\hline
\mbox{\texttt{ in}}  & {\em heff0} & Correct value for h\+Eff \\
\hline
\mbox{\texttt{ in}}  & {\em title} & Title for messages \\
\hline
\end{DoxyParams}


Definition at line 2774 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2775   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{2776   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)} :: ns\textcolor{comment}{    !< Number of surfaces}}
\DoxyCodeLine{2777   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(ns)}, \textcolor{keywordtype}{intent(in)} :: KoL\textcolor{comment}{   !< Index of first left interface above neutral surface}}
\DoxyCodeLine{2778   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(ns)}, \textcolor{keywordtype}{intent(in)} :: KoR\textcolor{comment}{   !< Index of first right interface above neutral surface}}
\DoxyCodeLine{2779 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns)},    \textcolor{keywordtype}{intent(in)} :: pL\textcolor{comment}{    !< Fractional position of neutral surface within layer KoL of left column}}
\DoxyCodeLine{2780 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns)},    \textcolor{keywordtype}{intent(in)} :: pR\textcolor{comment}{    !< Fractional position of neutral surface within layer KoR of right column}}
\DoxyCodeLine{2781 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns-\/1)},  \textcolor{keywordtype}{intent(in)} :: hEff\textcolor{comment}{  !< Effective thickness between two neutral surfaces [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{2782   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(ns)}, \textcolor{keywordtype}{intent(in)} :: KoL0\textcolor{comment}{  !< Correct value for KoL}}
\DoxyCodeLine{2783   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(ns)}, \textcolor{keywordtype}{intent(in)} :: KoR0\textcolor{comment}{  !< Correct value for KoR}}
\DoxyCodeLine{2784 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns)},    \textcolor{keywordtype}{intent(in)} :: pL0\textcolor{comment}{   !< Correct value for pL}}
\DoxyCodeLine{2785 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns)},    \textcolor{keywordtype}{intent(in)} :: pR0\textcolor{comment}{   !< Correct value for pR}}
\DoxyCodeLine{2786 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(ns-\/1)},  \textcolor{keywordtype}{intent(in)} :: hEff0\textcolor{comment}{ !< Correct value for hEff}}
\DoxyCodeLine{2787   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{ !< Title for messages}}
\DoxyCodeLine{2788 }
\DoxyCodeLine{2789   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2790   \textcolor{keywordtype}{integer} :: k, stdunit}
\DoxyCodeLine{2791   \textcolor{keywordtype}{logical} :: this\_row\_failed}
\DoxyCodeLine{2792 }
\DoxyCodeLine{2793   test\_nsp = .false.}
\DoxyCodeLine{2794   \textcolor{keywordflow}{do} k = 1,ns}
\DoxyCodeLine{2795     test\_nsp = test\_nsp .or. compare\_nsp\_row(kol(k), kor(k), pl(k), pr(k), kol0(k), kor0(k), pl0(k), pr0(k))}
\DoxyCodeLine{2796     \textcolor{keywordflow}{if} (k < ns) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2797       \textcolor{keywordflow}{if} (heff(k) /= heff0(k)) test\_nsp = .true.}
\DoxyCodeLine{2798 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2799 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2800 }
\DoxyCodeLine{2801   \textcolor{keywordflow}{if} (test\_nsp .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2802     stdunit = stdout}
\DoxyCodeLine{2803     \textcolor{keywordflow}{if} (test\_nsp) stdunit = stderr \textcolor{comment}{! In case of wrong results, write to error stream}}
\DoxyCodeLine{2804     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(a)'}) title}
\DoxyCodeLine{2805     \textcolor{keywordflow}{do} k = 1,ns}
\DoxyCodeLine{2806       this\_row\_failed = compare\_nsp\_row(kol(k), kor(k), pl(k), pr(k), kol0(k), kor0(k), pl0(k), pr0(k))}
\DoxyCodeLine{2807       \textcolor{keywordflow}{if} (this\_row\_failed) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2808         \textcolor{keyword}{write}(stdunit,10) k,kol(k),pl(k),kor(k),pr(k),\textcolor{stringliteral}{' <-\/-\/ WRONG!'}}
\DoxyCodeLine{2809         \textcolor{keyword}{write}(stdunit,10) k,kol0(k),pl0(k),kor0(k),pr0(k),\textcolor{stringliteral}{' <-\/-\/ should be this'}}
\DoxyCodeLine{2810       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2811         \textcolor{keyword}{write}(stdunit,10) k,kol(k),pl(k),kor(k),pr(k)}
\DoxyCodeLine{2812 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2813       \textcolor{keywordflow}{if} (k < ns) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2814         \textcolor{keywordflow}{if} (heff(k) /= heff0(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2815           \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(i3,8x,"{}layer hEff ="{},2(f20.16,a))'}) k,heff(k),\textcolor{stringliteral}{"{} .neq. "{}},heff0(k),\textcolor{stringliteral}{' <-\/-\/ WRONG!'}}
\DoxyCodeLine{2816         \textcolor{keywordflow}{else}}
\DoxyCodeLine{2817           \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(i3,8x,"{}layer hEff ="{},f20.16)'}) k,heff(k)}
\DoxyCodeLine{2818 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2819 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2820 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2821 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2822   \textcolor{keywordflow}{if} (test\_nsp) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}test\_nsp failed"{}})}
\DoxyCodeLine{2823 }
\DoxyCodeLine{2824 10 \textcolor{keyword}{format}(\textcolor{stringliteral}{"{}ks="{}},i3,\textcolor{stringliteral}{"{} kL="{}},i3,\textcolor{stringliteral}{"{} pL="{}},f20.16,\textcolor{stringliteral}{"{} kR="{}},i3,\textcolor{stringliteral}{"{} pR="{}},f20.16,a)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__neutral__diffusion_ab75333897fa8800441d8eddc1720f631}\label{namespacemom__neutral__diffusion_ab75333897fa8800441d8eddc1720f631}} 
\index{mom\_neutral\_diffusion@{mom\_neutral\_diffusion}!test\_rnp@{test\_rnp}}
\index{test\_rnp@{test\_rnp}!mom\_neutral\_diffusion@{mom\_neutral\_diffusion}}
\doxysubsubsection{\texorpdfstring{test\_rnp()}{test\_rnp()}}
{\footnotesize\ttfamily logical function mom\+\_\+neutral\+\_\+diffusion\+::test\+\_\+rnp (\begin{DoxyParamCaption}\item[{real, intent(in)}]{expected\+\_\+pos,  }\item[{real, intent(in)}]{test\+\_\+pos,  }\item[{character(len=$\ast$), intent(in)}]{title }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Compares output position from refine\+\_\+nondim\+\_\+position with an expected value. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em expected\+\_\+pos} & The expected position \\
\hline
\mbox{\texttt{ in}}  & {\em test\+\_\+pos} & The position returned by the code \\
\hline
\mbox{\texttt{ in}}  & {\em title} & A label for this test \\
\hline
\end{DoxyParams}


Definition at line 2846 of file M\+O\+M\+\_\+neutral\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2847 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: expected\_pos\textcolor{comment}{ !< The expected position}}
\DoxyCodeLine{2848 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: test\_pos\textcolor{comment}{ !< The position returned by the code}}
\DoxyCodeLine{2849   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: title\textcolor{comment}{    !< A label for this test}}
\DoxyCodeLine{2850   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2851   \textcolor{keywordtype}{integer} :: stdunit}
\DoxyCodeLine{2852 }
\DoxyCodeLine{2853   stdunit = stdout \textcolor{comment}{! Output to standard error}}
\DoxyCodeLine{2854   test\_rnp = abs(expected\_pos -\/ test\_pos) > 2*epsilon(test\_pos)}
\DoxyCodeLine{2855   \textcolor{keywordflow}{if} (test\_rnp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2856     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(A, f20.16, "{} .neq. "{}, f20.16, "{} <-\/-\/ WRONG"{})'}) title, expected\_pos, test\_pos}
\DoxyCodeLine{2857   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2858     \textcolor{keyword}{write}(stdunit,\textcolor{stringliteral}{'(A, f20.16, "{} ==  "{}, f20.16)'}) title, expected\_pos, test\_pos}
\DoxyCodeLine{2859 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
