\hypertarget{namespacemom__meke}{}\doxysection{mom\+\_\+meke Module Reference}
\label{namespacemom__meke}\index{mom\_meke@{mom\_meke}}


\doxysubsection{Detailed Description}
Implements the Mesoscale Eddy Kinetic Energy framework with topographic beta effect included in computing beta in Rhines scale. 

\hypertarget{namespacemom__meke_section_MEKE}{}\doxysubsection{The Mesoscale Eddy Kinetic Energy (\+M\+E\+K\+E) framework}\label{namespacemom__meke_section_MEKE}
The M\+E\+KE framework accounts for the mean potential energy removed by the first order closures used to parameterize mesoscale eddies. It requires closure at the second order, namely dissipation and transport of eddy energy.

Monitoring the sub-\/grid scale eddy energy budget provides a means to predict a sub-\/grid eddy-\/velocity scale which can be used in the lower order closures.\hypertarget{namespacemom__meke_section_MEKE_equations}{}\doxysubsubsection{M\+E\+K\+E equations}\label{namespacemom__meke_section_MEKE_equations}
The eddy kinetic energy equation is\+: \[ \partial_{\tilde{t}} E = \overbrace{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }^\text{sources} - \overbrace{ ( \lambda + C_d | U_d | \gamma_b^2 ) E }^\text{local dissipation} + \overbrace{ \nabla \cdot ( ( \kappa_E + \gamma_M \kappa_M ) \nabla E - \kappa_4 \nabla^3 E ) }^\text{smoothing} \] where $ E $ is the eddy kinetic energy (variable {\ttfamily M\+E\+KE}) with units of m\textsuperscript{2}s\textsuperscript{-\/2}, and $\tilde{t} = a t$ is a scaled time. The non-\/dimensional factor $ a\geq 1 $ is used to accelerate towards equilibrium.

The M\+E\+KE equation is two-\/dimensional and obtained by depth averaging the the three-\/dimensional eddy energy equation. In the following expressions $ \left< \phi \right> = \frac{1}{H} \int^\eta_{-D} \phi \, dz $ maps three dimensional terms into the two-\/dimensional quantities needed.\hypertarget{namespacemom__meke_section_MEKE_source_terms}{}\doxyparagraph{M\+E\+K\+E source terms}\label{namespacemom__meke_section_MEKE_source_terms}
The source term $ \dot{E}_b $ is a constant background source of energy intended to avoid the limit $E\rightarrow 0$.

The \char`\"{}\+G\+M\char`\"{} source term \[ \dot{E}_\eta = - \left< \overline{w^\prime b^\prime} \right> = \left< \kappa_h N^2S^2 \right> \approx \left< \kappa_h g\prime |\nabla_\sigma \eta|^2 \right>\] equals the mean potential energy removed by the Gent-\/\+Mc\+Williams closure, and is excluded/included in the M\+E\+KE budget by the efficiency parameter $ \gamma_\eta \in [0,1] $.

The \char`\"{}frictional\char`\"{} source term \[ \dot{E}_{v} = \left< \partial_i u_j \tau_{ij} \right> \] equals the mean kinetic energy removed by lateral viscous fluxes, and is excluded/included in the M\+E\+KE budget by the efficiency parameter $ \gamma_v \in [0,1] $.\hypertarget{namespacemom__meke_section_MEKE_dissipation_terms}{}\doxyparagraph{M\+E\+K\+E dissipation terms}\label{namespacemom__meke_section_MEKE_dissipation_terms}
The local dissipation of $ E $ is parameterized through a linear damping, $\lambda$, and bottom drag, $ C_d | U_d | \gamma_b^2 $. The $ \gamma_b $ accounts for the weak projection of the column-\/mean eddy velocty to the bottom. In other words, the bottom velocity is estimated as $ \gamma_b U_e $. The bottom drag coefficient, $ C_d $ is the same as that used in the bottom friction in the mean model equations.

The bottom drag velocity scale, $ U_d $, has contributions from the resolved state and $ E $\+: \[ U_d = \sqrt{ U_b^2 + |u|^2_{z=-D} + |\gamma_b U_e|^2 } .\] where the eddy velocity scale, $ U_e $, is given by\+: \[ U_e = \sqrt{ 2 E } .\] $ U_b $ is a constant background bottom velocity scale and is typically not used (i.\+e. set to zero).

Following Jansen et al., 2015, the projection of eddy energy on to the bottom is given by the ratio of bottom energy to column mean energy\+: \[ \gamma_b^2 = \frac{E_b}{E} = \gamma_{d0} + \left( 1 + c_{b} \frac{L_d}{L_f} \right)^{-\frac{4}{5}} , \] \[ \gamma_b^2 \leftarrow \max{\left( \gamma_b^2, \gamma_{min}^2 \right)} . \]\hypertarget{namespacemom__meke_section_MEKE_smoothing}{}\doxysubsubsection{M\+E\+K\+E smoothing terms}\label{namespacemom__meke_section_MEKE_smoothing}
$ E $ is laterally diffused by a diffusivity $ \kappa_E + \gamma_M \kappa_M $ where $ \kappa_E $ is a constant diffusivity and the term $ \gamma_M \kappa_M $ is a \char`\"{}self diffusion\char`\"{} using the diffusivity calculated in the section \mbox{\hyperlink{namespacemom__meke_section_MEKE_diffusivity}{Diffusivity derived from M\+E\+KE}}. $ \kappa_4 $ is a constant bi-\/harmonic diffusivity.\hypertarget{namespacemom__meke_section_MEKE_diffusivity}{}\doxysubsubsection{Diffusivity derived from M\+E\+KE}\label{namespacemom__meke_section_MEKE_diffusivity}
The predicted eddy velocity scale, $ U_e $, can be combined with a mixing length scale to form a diffusivity. The primary use of a M\+E\+KE derived diffusivity is for use in thickness diffusion (module \mbox{\hyperlink{namespacemom__thickness__diffuse}{mom\+\_\+thickness\+\_\+diffuse}}) and optionally in along isopycnal mixing of tracers (module \mbox{\hyperlink{namespacemom__tracer__hor__diff}{mom\+\_\+tracer\+\_\+hor\+\_\+diff}}). The original form used (enabled with M\+E\+K\+E\+\_\+\+O\+L\+D\+\_\+\+L\+S\+C\+A\+LE=True)\+:

\[ \kappa_M = \gamma_\kappa \sqrt{ \gamma_t^2 U_e^2 A_\Delta } \]

where $ A_\Delta $ is the area of the grid cell. Following Jansen et al., 2015, we now use

\[ \kappa_M = \gamma_\kappa l_M \sqrt{ \gamma_t^2 U_e^2 } \]

where $ \gamma_\kappa \in [0,1] $ is a non-\/dimensional factor and, following Jansen et al., 2015, $\gamma_t^2$ is the ratio of barotropic eddy energy to column mean eddy energy given by \[ \gamma_t^2 = \frac{E_t}{E} = \left( 1 + c_{t} \frac{L_d}{L_f} \right)^{-\frac{1}{4}} , \] \[ \gamma_t^2 \leftarrow \max{\left( \gamma_t^2, \gamma_{min}^2 \right)} . \]

The length-\/scale is a configurable combination of multiple length scales\+:

\[ l_M = \left( \frac{\alpha_d}{L_d} + \frac{\alpha_f}{L_f} + \frac{\alpha_R}{L_R} + \frac{\alpha_e}{L_e} + \frac{\alpha_\Delta}{L_\Delta} + \frac{\delta[L_c]}{L_c} \right)^{-1} \]

where

\begin{eqnarray*} L_d & = & \sqrt{\frac{c_g^2}{f^2+2\beta c_g}} \sim \frac{ c_g }{f} \\\\ L_R & = & \sqrt{\frac{U_e}{\beta^*}} \\\\ L_e & = & \frac{U_e}{|S| N} \\\\ L_f & = & \frac{H}{c_d} \\\\ L_\Delta & = & \sqrt{A_\Delta} . \end{eqnarray*}

$L_c$ is a constant and $\delta[L_c]$ is the impulse function so that the term $\frac{\delta[L_c]}{L_c}$ evaluates to $\frac{1}{L_c}$ when $L_c$ is non-\/zero but is dropped if $L_c=0$.

$\beta^*$ is the effective $\beta$ that combines both the planetary vorticity gradient (i.\+e. $\beta=\nabla f$) and the topographic $\beta$ effect, with the latter weighed by a weighting constant, $c_\beta$, that varies from 0 to 1, so that $c_\beta=0$ means the topographic $\beta$ effect is ignored, while $c_\beta=1$ means it is fully considered. The new $\beta^*$ therefore takes the form of

\[ \beta^* = \sqrt{( \partial_xf - c_\beta\frac{f}{D}\partial_xD )^2 + ( \partial_yf - c_\beta\frac{f}{D}\partial_yD )^2} \] where $D$ is water column depth at T points.\hypertarget{namespacemom__meke_section_MEKE_viscosity}{}\doxysubsubsection{Viscosity derived from M\+E\+KE}\label{namespacemom__meke_section_MEKE_viscosity}
As for $ \kappa_M $, the predicted eddy velocity scale can be used to form a harmonic eddy viscosity,

\[ \kappa_u = \gamma_u \sqrt{ U_e^2 A_\Delta } \]

as well as a biharmonic eddy viscosity,

\[ \kappa_4 = \gamma_4 \sqrt{ U_e^2 A_\Delta^3 } \]\hypertarget{namespacemom__meke_section_MEKE_limit_case}{}\doxysubsubsection{Limit cases for local source-\/dissipative balance}\label{namespacemom__meke_section_MEKE_limit_case}
Note that in steady-\/state (or when $ a>>1 $) and there is no diffusion of $ E $ then \[ \overline{E} \approx \frac{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }{ \lambda + C_d|U_d|\gamma_b^2 } . \]

In the linear drag limit, where $ U_e << \min(U_b, |u|_{z=-D}, C_d^{-1}\lambda) $, the equilibrium becomes $ \overline{E} \approx \frac{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }{ \lambda + C_d \sqrt{ U_b^2 + |u|^2_{z=-D} } } $.

In the nonlinear drag limit, where $ U_e >> \max(U_b, |u|_{z=-D}, C_d^{-1}\lambda) $, the equilibrium becomes $ \overline{E} \approx \left( \frac{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }{ \sqrt{2} C_d \gamma_b^3 } \right)^\frac{2}{3} $.\hypertarget{namespacemom__meke_section_MEKE_module_parameters}{}\doxyparagraph{M\+E\+K\+E module parameters}\label{namespacemom__meke_section_MEKE_module_parameters}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter  }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter  }\\\cline{1-2}
\endhead
-\/ &{\ttfamily U\+S\+E\+\_\+\+M\+E\+KE}  \\\cline{1-2}
$ a $ &{\ttfamily M\+E\+K\+E\+\_\+\+D\+T\+S\+C\+A\+LE}  \\\cline{1-2}
$ \dot{E}_b $ &{\ttfamily M\+E\+K\+E\+\_\+\+B\+G\+S\+RC}  \\\cline{1-2}
$ \gamma_\eta $ &{\ttfamily M\+E\+K\+E\+\_\+\+G\+M\+C\+O\+E\+FF}  \\\cline{1-2}
$ \gamma_v $ &{\ttfamily M\+E\+K\+E\+\_\+\+Fr\+C\+O\+E\+FF}  \\\cline{1-2}
$ \lambda $ &{\ttfamily M\+E\+K\+E\+\_\+\+D\+A\+M\+P\+I\+NG}  \\\cline{1-2}
$ U_b $ &{\ttfamily M\+E\+K\+E\+\_\+\+U\+S\+C\+A\+LE}  \\\cline{1-2}
$ \gamma_{d0} $ &{\ttfamily M\+E\+K\+E\+\_\+\+C\+D\+\_\+\+S\+C\+A\+LE}  \\\cline{1-2}
$ c_{b} $ &{\ttfamily M\+E\+K\+E\+\_\+\+CB}  \\\cline{1-2}
$ c_{t} $ &{\ttfamily M\+E\+K\+E\+\_\+\+CT}  \\\cline{1-2}
$ \kappa_E $ &{\ttfamily M\+E\+K\+E\+\_\+\+KH}  \\\cline{1-2}
$ \kappa_4 $ &{\ttfamily M\+E\+K\+E\+\_\+\+K4}  \\\cline{1-2}
$ \gamma_\kappa $ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+C\+O\+E\+FF}  \\\cline{1-2}
$ \gamma_M $ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+M\+E\+K\+E\+\_\+\+F\+AC}  \\\cline{1-2}
$ \gamma_u $ &{\ttfamily M\+E\+K\+E\+\_\+\+V\+I\+S\+C\+O\+S\+I\+T\+Y\+\_\+\+C\+O\+E\+F\+F\+\_\+\+KU}  \\\cline{1-2}
$ \gamma_4 $ &{\ttfamily M\+E\+K\+E\+\_\+\+V\+I\+S\+C\+O\+S\+I\+T\+Y\+\_\+\+C\+O\+E\+F\+F\+\_\+\+AU}  \\\cline{1-2}
$ \gamma_{min}^2 $ &{\ttfamily M\+E\+K\+E\+\_\+\+M\+I\+N\+\_\+\+G\+A\+M\+M\+A2}  \\\cline{1-2}
$ \alpha_d $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+D\+E\+F\+O\+RM}  \\\cline{1-2}
$ \alpha_f $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+F\+R\+I\+CT}  \\\cline{1-2}
$ \alpha_R $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+R\+H\+I\+N\+ES}  \\\cline{1-2}
$ \alpha_e $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+E\+A\+DY}  \\\cline{1-2}
$ \alpha_\Delta $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+G\+R\+ID}  \\\cline{1-2}
$ L_c $ &{\ttfamily M\+E\+K\+E\+\_\+\+F\+I\+X\+E\+D\+\_\+\+M\+I\+X\+I\+N\+G\+\_\+\+L\+E\+N\+G\+TH}  \\\cline{1-2}
$ c_\beta $ &{\ttfamily M\+E\+K\+E\+\_\+\+T\+O\+P\+O\+G\+R\+A\+P\+H\+I\+C\+\_\+\+B\+E\+TA}  \\\cline{1-2}
-\/ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+T\+H\+\_\+\+F\+AC}  \\\cline{1-2}
-\/ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+T\+R\+\_\+\+F\+AC}  \\\cline{1-2}
\end{longtabu}


\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Model parameter  }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Model parameter  }\\\cline{1-2}
\endhead
$ C_d $ &{\ttfamily C\+D\+R\+AG}  \\\cline{1-2}
\end{longtabu}
\hypertarget{namespacemom__meke_section_MEKE_references}{}\doxysubsubsection{References}\label{namespacemom__meke_section_MEKE_references}
Jansen, M. F., A. J. Adcroft, R. Hallberg, and I. M. Held, 2015\+: Parameterization of eddy fluxes based on a mesoscale energy budget. Ocean Modelling, 92, 28--41, \href{http://doi.org/10.1016/j.ocemod.2015.05.007}{\texttt{ http\+://doi.\+org/10.\+1016/j.\+ocemod.\+2015.\+05.\+007}} .

Marshall, D. P., and A. J. Adcroft, 2010\+: Parameterization of ocean eddies\+: Potential vorticity mixing, energetics and Arnold first stability theorem. Ocean Modelling, 32, 188--204, \href{http://doi.org/10.1016/j.ocemod.2010.02.001}{\texttt{ http\+://doi.\+org/10.\+1016/j.\+ocemod.\+2010.\+02.\+001}} . \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure that contains M\+E\+KE parameters and diagnostics handles. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\+\_\+forward\+\_\+meke}} (M\+E\+KE, h, S\+N\+\_\+u, S\+N\+\_\+v, visc, dt, G, GV, US, CS, hu, hv)
\begin{DoxyCompactList}\small\item\em Integrates forward-\/in-\/time the M\+E\+KE eddy energy equation. See \mbox{\hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}}. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\+\_\+equilibrium}} (CS, M\+E\+KE, G, GV, US, S\+N\+\_\+u, S\+N\+\_\+v, drag\+\_\+rate\+\_\+visc, I\+\_\+mass)
\begin{DoxyCompactList}\small\item\em Calculates the equilibrium solutino where the source depends only on M\+E\+KE diffusivity and there is no lateral diffusion of M\+E\+KE. Results is in M\+E\+KEM\+E\+KE. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\+\_\+equilibrium\+\_\+restoring}} (CS, G, US, S\+N\+\_\+u, S\+N\+\_\+v)
\item 
subroutine \mbox{\hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\+\_\+lengthscales}} (CS, M\+E\+KE, G, GV, US, S\+N\+\_\+u, S\+N\+\_\+v, E\+KE, bottom\+Fac2, barotr\+Fac2, Lmix\+Scale)
\begin{DoxyCompactList}\small\item\em Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \mbox{\hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}}. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\+\_\+lengthscales\+\_\+0d}} (CS, US, area, beta, depth, Rd\+\_\+dx, SN, E\+KE, bottom\+Fac2, barotr\+Fac2, Lmix\+Scale, Lrhines, Leady)
\begin{DoxyCompactList}\small\item\em Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \mbox{\hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}}. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\+\_\+init}} (Time, G, US, param\+\_\+file, diag, CS, M\+E\+KE, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Initializes the M\+O\+M\+\_\+\+M\+E\+KE module and reads parameters. Returns True if module is to be used, otherwise returns False. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{meke\+\_\+alloc\+\_\+register\+\_\+restart}} (HI, param\+\_\+file, M\+E\+KE, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Allocates memory and register restart fields for the M\+O\+M\+\_\+\+M\+E\+KE module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}{meke\+\_\+end}} (M\+E\+KE, CS)
\begin{DoxyCompactList}\small\item\em Deallocates any variables allocated in M\+E\+K\+E\+\_\+init or M\+E\+K\+E\+\_\+alloc\+\_\+register\+\_\+restart. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}\label{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}} 
\index{mom\_meke@{mom\_meke}!meke\_alloc\_register\_restart@{meke\_alloc\_register\_restart}}
\index{meke\_alloc\_register\_restart@{meke\_alloc\_register\_restart}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_alloc\_register\_restart()}{meke\_alloc\_register\_restart()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+meke\+::meke\+\_\+alloc\+\_\+register\+\_\+restart (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Allocates memory and register restart fields for the M\+O\+M\+\_\+\+M\+E\+KE module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & Horizontal index structure \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file parser structure. \\
\hline
 & {\em meke} & A structure with M\+E\+K\+E-\/related fields. \\
\hline
 & {\em restart\+\_\+cs} & Restart control structure for M\+O\+M\+\_\+\+M\+E\+KE. \\
\hline
\end{DoxyParams}


Definition at line 1346 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1347 \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1348   \textcolor{keywordtype}{type}(hor\_index\_type),  \textcolor{keywordtype}{intent(in)}    :: HI\textcolor{comment}{         !< Horizontal index structure}}
\DoxyCodeLine{1349   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file parser structure.}}
\DoxyCodeLine{1350   \textcolor{keywordtype}{type}(MEKE\_type),       \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{       !< A structure with MEKE-\/related fields.}}
\DoxyCodeLine{1351   \textcolor{keywordtype}{type}(MOM\_restart\_CS),  \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< Restart control structure for MOM\_MEKE.}}
\DoxyCodeLine{1352 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1353   \textcolor{keywordtype}{type}(vardesc) :: vd}
\DoxyCodeLine{1354 \textcolor{keywordtype}{  real} :: MEKE\_GMcoeff, MEKE\_FrCoeff, MEKE\_GMECoeff, MEKE\_KHCoeff, MEKE\_viscCoeff\_Ku, MEKE\_viscCoeff\_Au}
\DoxyCodeLine{1355   \textcolor{keywordtype}{logical} :: Use\_KH\_in\_MEKE}
\DoxyCodeLine{1356   \textcolor{keywordtype}{logical} :: useMEKE}
\DoxyCodeLine{1357   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed}
\DoxyCodeLine{1358 }
\DoxyCodeLine{1359 \textcolor{comment}{! Determine whether this module will be used}}
\DoxyCodeLine{1360   usemeke = .false.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"USE\_MEKE"},usemeke)}
\DoxyCodeLine{1361 }
\DoxyCodeLine{1362 \textcolor{comment}{! Read these parameters to determine what should be in the restarts}}
\DoxyCodeLine{1363   meke\_gmcoeff =-\/1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_GMCOEFF"},meke\_gmcoeff)}
\DoxyCodeLine{1364   meke\_frcoeff =-\/1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_FRCOEFF"},meke\_frcoeff)}
\DoxyCodeLine{1365   meke\_gmecoeff =-\/1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_GMECOEFF"},meke\_gmecoeff)}
\DoxyCodeLine{1366   meke\_khcoeff =1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_KHCOEFF"},meke\_khcoeff)}
\DoxyCodeLine{1367   meke\_visccoeff\_ku =0.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_KU"},meke\_visccoeff\_ku)}
\DoxyCodeLine{1368   meke\_visccoeff\_au =0.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_AU"},meke\_visccoeff\_au)}
\DoxyCodeLine{1369   use\_kh\_in\_meke = .false.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"USE\_KH\_IN\_MEKE"}, use\_kh\_in\_meke)}
\DoxyCodeLine{1370 \textcolor{comment}{! Allocate control structure}}
\DoxyCodeLine{1371   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1372     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MEKE\_alloc\_register\_restart called with an associated "}// \&}
\DoxyCodeLine{1373                              \textcolor{stringliteral}{"MEKE type."})}
\DoxyCodeLine{1374     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1375   else; \textcolor{keyword}{allocate}(meke);\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1376 }
\DoxyCodeLine{1377   \textcolor{keywordflow}{if} (.not. usemeke) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1378 }
\DoxyCodeLine{1379 \textcolor{comment}{! Allocate memory}}
\DoxyCodeLine{1380   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"MEKE\_alloc\_register\_restart: allocating and registering"}, 5)}
\DoxyCodeLine{1381   isd = hi\%isd ; ied = hi\%ied ; jsd = hi\%jsd ; jed = hi\%jed}
\DoxyCodeLine{1382   \textcolor{keyword}{allocate}(meke\%MEKE(isd:ied,jsd:jed)) ; meke\%MEKE(:,:) = 0.0}
\DoxyCodeLine{1383   vd = var\_desc(\textcolor{stringliteral}{"MEKE"}, \textcolor{stringliteral}{"m2 s-\/2"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, \&}
\DoxyCodeLine{1384            longname=\textcolor{stringliteral}{"Mesoscale Eddy Kinetic Energy"})}
\DoxyCodeLine{1385   \textcolor{keyword}{call }register\_restart\_field(meke\%MEKE, vd, .false., restart\_cs)}
\DoxyCodeLine{1386   \textcolor{keywordflow}{if} (meke\_gmcoeff>=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1387     \textcolor{keyword}{allocate}(meke\%GM\_src(isd:ied,jsd:jed)) ; meke\%GM\_src(:,:) = 0.0}
\DoxyCodeLine{1388 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1389   \textcolor{keywordflow}{if} (meke\_frcoeff>=0. .or. meke\_gmecoeff>=0.)  \textcolor{keywordflow}{then}}
\DoxyCodeLine{1390     \textcolor{keyword}{allocate}(meke\%mom\_src(isd:ied,jsd:jed)) ; meke\%mom\_src(:,:) = 0.0}
\DoxyCodeLine{1391 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1392   \textcolor{keywordflow}{if} (meke\_gmecoeff>=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1393     \textcolor{keyword}{allocate}(meke\%GME\_snk(isd:ied,jsd:jed)) ; meke\%GME\_snk(:,:) = 0.0}
\DoxyCodeLine{1394 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1395   \textcolor{keywordflow}{if} (meke\_khcoeff>=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1396     \textcolor{keyword}{allocate}(meke\%Kh(isd:ied,jsd:jed)) ; meke\%Kh(:,:) = 0.0}
\DoxyCodeLine{1397     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Kh"}, \textcolor{stringliteral}{"m2 s-\/1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, \&}
\DoxyCodeLine{1398              longname=\textcolor{stringliteral}{"Lateral diffusivity from Mesoscale Eddy Kinetic Energy"})}
\DoxyCodeLine{1399     \textcolor{keyword}{call }register\_restart\_field(meke\%Kh, vd, .false., restart\_cs)}
\DoxyCodeLine{1400 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1401   \textcolor{keyword}{allocate}(meke\%Rd\_dx\_h(isd:ied,jsd:jed)) ; meke\%Rd\_dx\_h(:,:) = 0.0}
\DoxyCodeLine{1402   \textcolor{keywordflow}{if} (meke\_visccoeff\_ku/=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1403     \textcolor{keyword}{allocate}(meke\%Ku(isd:ied,jsd:jed)) ; meke\%Ku(:,:) = 0.0}
\DoxyCodeLine{1404     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Ku"}, \textcolor{stringliteral}{"m2 s-\/1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, \&}
\DoxyCodeLine{1405              longname=\textcolor{stringliteral}{"Lateral viscosity from Mesoscale Eddy Kinetic Energy"})}
\DoxyCodeLine{1406     \textcolor{keyword}{call }register\_restart\_field(meke\%Ku, vd, .false., restart\_cs)}
\DoxyCodeLine{1407 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1408   \textcolor{keywordflow}{if} (use\_kh\_in\_meke) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1409     \textcolor{keyword}{allocate}(meke\%Kh\_diff(isd:ied,jsd:jed)) ; meke\%Kh\_diff(:,:) = 0.0}
\DoxyCodeLine{1410     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Kh\_diff"}, \textcolor{stringliteral}{"m2 s-\/1"},hor\_grid=\textcolor{stringliteral}{'h'},z\_grid=\textcolor{stringliteral}{'1'}, \&}
\DoxyCodeLine{1411              longname=\textcolor{stringliteral}{"Copy of thickness diffusivity for diffusing MEKE"})}
\DoxyCodeLine{1412     \textcolor{keyword}{call }register\_restart\_field(meke\%Kh\_diff, vd, .false., restart\_cs)}
\DoxyCodeLine{1413 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1414 }
\DoxyCodeLine{1415   \textcolor{keywordflow}{if} (meke\_visccoeff\_au/=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1416     \textcolor{keyword}{allocate}(meke\%Au(isd:ied,jsd:jed)) ; meke\%Au(:,:) = 0.0}
\DoxyCodeLine{1417     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Au"}, \textcolor{stringliteral}{"m4 s-\/1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, \&}
\DoxyCodeLine{1418              longname=\textcolor{stringliteral}{"Lateral biharmonic viscosity from Mesoscale Eddy Kinetic Energy"})}
\DoxyCodeLine{1419     \textcolor{keyword}{call }register\_restart\_field(meke\%Au, vd, .false., restart\_cs)}
\DoxyCodeLine{1420 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1421 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}\label{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}} 
\index{mom\_meke@{mom\_meke}!meke\_end@{meke\_end}}
\index{meke\_end@{meke\_end}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_end()}{meke\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+meke\+::meke\+\_\+end (\begin{DoxyParamCaption}\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocates any variables allocated in M\+E\+K\+E\+\_\+init or M\+E\+K\+E\+\_\+alloc\+\_\+register\+\_\+restart. 


\begin{DoxyParams}{Parameters}
{\em meke} & A structure with M\+E\+K\+E-\/related fields. \\
\hline
{\em cs} & The control structure for M\+O\+M\+\_\+\+M\+E\+KE. \\
\hline
\end{DoxyParams}


Definition at line 1426 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1427   \textcolor{keywordtype}{type}(MEKE\_type), \textcolor{keywordtype}{pointer} :: MEKE\textcolor{comment}{ !< A structure with MEKE-\/related fields.}}
\DoxyCodeLine{1428   \textcolor{keywordtype}{type}(MEKE\_CS),   \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< The control structure for MOM\_MEKE.}}
\DoxyCodeLine{1429 }
\DoxyCodeLine{1430   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1431 }
\DoxyCodeLine{1432   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1433 }
\DoxyCodeLine{1434   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%MEKE)) \textcolor{keyword}{deallocate}(meke\%MEKE)}
\DoxyCodeLine{1435   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%GM\_src)) \textcolor{keyword}{deallocate}(meke\%GM\_src)}
\DoxyCodeLine{1436   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%mom\_src)) \textcolor{keyword}{deallocate}(meke\%mom\_src)}
\DoxyCodeLine{1437   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%GME\_snk)) \textcolor{keyword}{deallocate}(meke\%GME\_snk)}
\DoxyCodeLine{1438   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh)) \textcolor{keyword}{deallocate}(meke\%Kh)}
\DoxyCodeLine{1439   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh\_diff)) \textcolor{keyword}{deallocate}(meke\%Kh\_diff)}
\DoxyCodeLine{1440   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Ku)) \textcolor{keyword}{deallocate}(meke\%Ku)}
\DoxyCodeLine{1441   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Au)) \textcolor{keyword}{deallocate}(meke\%Au)}
\DoxyCodeLine{1442   \textcolor{keyword}{deallocate}(meke)}
\DoxyCodeLine{1443 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}\label{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}} 
\index{mom\_meke@{mom\_meke}!meke\_equilibrium@{meke\_equilibrium}}
\index{meke\_equilibrium@{meke\_equilibrium}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_equilibrium()}{meke\_equilibrium()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+equilibrium (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{drag\+\_\+rate\+\_\+visc,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{I\+\_\+mass }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the equilibrium solutino where the source depends only on M\+E\+KE diffusivity and there is no lateral diffusion of M\+E\+KE. Results is in M\+E\+KEM\+E\+KE. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & M\+E\+KE control structure. \\
\hline
 & {\em meke} & A structure with M\+E\+KE data. \\
\hline
\mbox{\texttt{ in}}  & {\em sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em drag\+\_\+rate\+\_\+visc} & Mean flow velocity contribution to the M\+E\+KE drag rate \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em i\+\_\+mass} & Inverse of column mass \mbox{[}R-\/1 Z-\/1 $\sim$$>$ m2 kg-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 643 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{644   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}}
\DoxyCodeLine{645   \textcolor{keywordtype}{type}(verticalGrid\_type),           \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid structure.}}
\DoxyCodeLine{646   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{647   \textcolor{keywordtype}{type}(MEKE\_CS),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}}
\DoxyCodeLine{648   \textcolor{keywordtype}{type}(MEKE\_type),                   \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{ !< A structure with MEKE data.}}
\DoxyCodeLine{649 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{650 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{651 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: drag\_rate\_visc\textcolor{comment}{ !< Mean flow velocity contribution}}
\DoxyCodeLine{652 \textcolor{comment}{                                                           !! to the MEKE drag rate [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{653 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: I\_mass\textcolor{comment}{  !< Inverse of column mass [R-\/1 Z-\/1 \string~> m2 kg-\/1].}}
\DoxyCodeLine{654   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{655 \textcolor{keywordtype}{  real} :: beta \textcolor{comment}{! Combined topograpic and planetary vorticity gradient [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{656 \textcolor{keywordtype}{  real} :: SN   \textcolor{comment}{! The local Eady growth rate [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{657 \textcolor{keywordtype}{  real} :: bottomFac2, barotrFac2    \textcolor{comment}{! Vertical structure factors [nondim]}}
\DoxyCodeLine{658 \textcolor{keywordtype}{  real} :: LmixScale, LRhines, LEady \textcolor{comment}{! Various mixing length scales [L \string~> m]}}
\DoxyCodeLine{659 \textcolor{keywordtype}{  real} :: I\_H, KhCoeff}
\DoxyCodeLine{660 \textcolor{keywordtype}{  real} :: Kh    \textcolor{comment}{! A lateral diffusivity [L2 T-\/1 \string~> m2 s-\/1]}}
\DoxyCodeLine{661 \textcolor{keywordtype}{  real} :: Ubg2  \textcolor{comment}{! Background (tidal?) velocity squared [L2 T-\/2 \string~> m2 s-\/2]}}
\DoxyCodeLine{662 \textcolor{keywordtype}{  real} :: cd2}
\DoxyCodeLine{663 \textcolor{keywordtype}{  real} :: drag\_rate \textcolor{comment}{! The MEKE spindown timescale due to bottom drag [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{664 \textcolor{keywordtype}{  real} :: src   \textcolor{comment}{! The sum of MEKE sources [L2 T-\/3 \string~> W kg-\/1]}}
\DoxyCodeLine{665 \textcolor{keywordtype}{  real} :: ldamping  \textcolor{comment}{! The MEKE damping rate [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{666 \textcolor{keywordtype}{  real} :: EKE, EKEmin, EKEmax, EKEerr \textcolor{comment}{! [L2 T-\/2 \string~> m2 s-\/2]}}
\DoxyCodeLine{667 \textcolor{keywordtype}{  real} :: resid, ResMin, ResMax \textcolor{comment}{! Residuals [L2 T-\/3 \string~> W kg-\/1]}}
\DoxyCodeLine{668 \textcolor{keywordtype}{  real} :: FatH    \textcolor{comment}{! Coriolis parameter at h points; to compute topographic beta [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{669 \textcolor{keywordtype}{  real} :: beta\_topo\_x, beta\_topo\_y    \textcolor{comment}{! Topographic PV gradients in x and y [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{670   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, n1, n2}
\DoxyCodeLine{671 \textcolor{keywordtype}{  real} :: tolerance \textcolor{comment}{! Width of EKE bracket [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{672   \textcolor{keywordtype}{logical} :: useSecant, debugIteration}
\DoxyCodeLine{673 }
\DoxyCodeLine{674 \textcolor{keywordtype}{  real} :: Lgrid, Ldeform, Lfrict}
\DoxyCodeLine{675 }
\DoxyCodeLine{676   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{677 }
\DoxyCodeLine{678   debugiteration = .false.}
\DoxyCodeLine{679   khcoeff = cs\%MEKE\_KhCoeff}
\DoxyCodeLine{680   ubg2 = cs\%MEKE\_Uscale**2}
\DoxyCodeLine{681   cd2 = cs\%cdrag**2}
\DoxyCodeLine{682   tolerance = 1.0e-\/12*us\%m\_s\_to\_L\_T**2}
\DoxyCodeLine{683 }
\DoxyCodeLine{684 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{685   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{686     \textcolor{comment}{! SN = 0.25*max( (SN\_u(I,j) + SN\_u(I-\/1,j)) + (SN\_v(i,J) + SN\_v(i,J-\/1)), 0.)}}
\DoxyCodeLine{687     \textcolor{comment}{! This avoids extremes values in equilibrium solution due to bad values in SN\_u, SN\_v}}
\DoxyCodeLine{688     sn = min(sn\_u(i,j), sn\_u(i-\/1,j), sn\_v(i,j), sn\_v(i,j-\/1))}
\DoxyCodeLine{689 }
\DoxyCodeLine{690     \textcolor{keywordflow}{if} (cs\%MEKE\_equilibrium\_alt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{691       meke\%MEKE(i,j) = (cs\%MEKE\_GEOMETRIC\_alpha * sn * us\%Z\_to\_m*g\%bathyT(i,j))**2 / cd2}
\DoxyCodeLine{692     \textcolor{keywordflow}{else}}
\DoxyCodeLine{693       fath = 0.25*((g\%CoriolisBu(i,j) + g\%CoriolisBu(i-\/1,j-\/1)) + \&}
\DoxyCodeLine{694                    (g\%CoriolisBu(i-\/1,j) + g\%CoriolisBu(i,j-\/1))) \textcolor{comment}{! Coriolis parameter at h points}}
\DoxyCodeLine{695 }
\DoxyCodeLine{696       \textcolor{comment}{! Since zero-\/bathymetry cells are masked, this avoids calculations on land}}
\DoxyCodeLine{697       \textcolor{keywordflow}{if} (cs\%MEKE\_topographic\_beta == 0. .or. g\%bathyT(i,j) == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{698         beta\_topo\_x = 0. ; beta\_topo\_y = 0.}
\DoxyCodeLine{699       \textcolor{keywordflow}{else}}
\DoxyCodeLine{700         \textcolor{comment}{!\#\#\# Consider different combinations of these estimates of topographic beta, and the use}}
\DoxyCodeLine{701         \textcolor{comment}{!    of the water column thickness instead of the bathymetric depth.}}
\DoxyCodeLine{702         beta\_topo\_x = -\/cs\%MEKE\_topographic\_beta * fath * 0.5 * ( \&}
\DoxyCodeLine{703                       (g\%bathyT(i+1,j)-\/g\%bathyT(i,j)) * g\%IdxCu(i,j)  \&}
\DoxyCodeLine{704                   / max(g\%bathyT(i+1,j),g\%bathyT(i,j), gv\%H\_subroundoff) \&}
\DoxyCodeLine{705               +       (g\%bathyT(i,j)-\/g\%bathyT(i-\/1,j)) * g\%IdxCu(i-\/1,j) \&}
\DoxyCodeLine{706                   / max(g\%bathyT(i,j),g\%bathyT(i-\/1,j), gv\%H\_subroundoff) )}
\DoxyCodeLine{707         beta\_topo\_y = -\/cs\%MEKE\_topographic\_beta * fath * 0.5 * ( \&}
\DoxyCodeLine{708                       (g\%bathyT(i,j+1)-\/g\%bathyT(i,j)) * g\%IdyCv(i,j)  \&}
\DoxyCodeLine{709                   / max(g\%bathyT(i,j+1),g\%bathyT(i,j), gv\%H\_subroundoff) + \&}
\DoxyCodeLine{710                       (g\%bathyT(i,j)-\/g\%bathyT(i,j-\/1)) * g\%IdyCv(i,j-\/1) \&}
\DoxyCodeLine{711                   / max(g\%bathyT(i,j),g\%bathyT(i,j-\/1), gv\%H\_subroundoff) )}
\DoxyCodeLine{712 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{713       beta =  sqrt((g\%dF\_dx(i,j) + beta\_topo\_x)**2 + \&}
\DoxyCodeLine{714                    (g\%dF\_dy(i,j) + beta\_topo\_y)**2 )}
\DoxyCodeLine{715 }
\DoxyCodeLine{716       i\_h = us\%L\_to\_Z*gv\%Rho0 * i\_mass(i,j)}
\DoxyCodeLine{717 }
\DoxyCodeLine{718       \textcolor{keywordflow}{if} (khcoeff*sn*i\_h>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{719         \textcolor{comment}{! Solve resid(E) = 0, where resid = Kh(E) * (SN)\string^2 -\/ damp\_rate(E) E}}
\DoxyCodeLine{720         ekemin = 0.   \textcolor{comment}{! Use the trivial root as the left bracket}}
\DoxyCodeLine{721         resmin = 0.   \textcolor{comment}{! Need to detect direction of left residual}}
\DoxyCodeLine{722         ekemax = 0.01*us\%m\_s\_to\_L\_T**2 \textcolor{comment}{! First guess at right bracket}}
\DoxyCodeLine{723         usesecant = .false. \textcolor{comment}{! Start using a bisection method}}
\DoxyCodeLine{724 }
\DoxyCodeLine{725         \textcolor{comment}{! First find right bracket for which resid<0}}
\DoxyCodeLine{726         resid = 1.0*us\%m\_to\_L**2*us\%T\_to\_s**3 ; n1 = 0}
\DoxyCodeLine{727         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (resid>0.)}
\DoxyCodeLine{728           n1 = n1 + 1}
\DoxyCodeLine{729           eke = ekemax}
\DoxyCodeLine{730           \textcolor{keyword}{call }meke\_lengthscales\_0d(cs, us, g\%areaT(i,j), beta, g\%bathyT(i,j), \&}
\DoxyCodeLine{731                                     meke\%Rd\_dx\_h(i,j), sn, eke, \&}
\DoxyCodeLine{732                                     bottomfac2, barotrfac2, lmixscale, lrhines, leady)}
\DoxyCodeLine{733           \textcolor{comment}{! TODO: Should include resolution function in Kh}}
\DoxyCodeLine{734           kh = (khcoeff * sqrt(2.*barotrfac2*eke) * lmixscale)}
\DoxyCodeLine{735           src = kh * (sn * sn)}
\DoxyCodeLine{736           drag\_rate = i\_h * sqrt(drag\_rate\_visc(i,j)**2 + cd2 * ( 2.0*bottomfac2*eke + ubg2 ) )}
\DoxyCodeLine{737           ldamping = cs\%MEKE\_damping + drag\_rate * bottomfac2}
\DoxyCodeLine{738           resid = src -\/ ldamping * eke}
\DoxyCodeLine{739           \textcolor{comment}{! if (debugIteration) then}}
\DoxyCodeLine{740           \textcolor{comment}{!   write(0,*) n1, 'EKE=',EKE,'resid=',resid}}
\DoxyCodeLine{741           \textcolor{comment}{!   write(0,*) 'EKEmin=',EKEmin,'ResMin=',ResMin}}
\DoxyCodeLine{742           \textcolor{comment}{!   write(0,*) 'src=',src,'ldamping=',ldamping}}
\DoxyCodeLine{743           \textcolor{comment}{!   write(0,*) 'gamma-\/b=',bottomFac2,'gamma-\/t=',barotrFac2}}
\DoxyCodeLine{744           \textcolor{comment}{!   write(0,*) 'drag\_visc=',drag\_rate\_visc(i,j),'Ubg2=',Ubg2}}
\DoxyCodeLine{745           \textcolor{comment}{! endif}}
\DoxyCodeLine{746           \textcolor{keywordflow}{if} (resid>0.) \textcolor{keywordflow}{then}    \textcolor{comment}{! EKE is to the left of the root}}
\DoxyCodeLine{747             ekemin = eke        \textcolor{comment}{! so we move the left bracket here}}
\DoxyCodeLine{748             ekemax = 10. * eke  \textcolor{comment}{! and guess again for the right bracket}}
\DoxyCodeLine{749             \textcolor{keywordflow}{if} (resid<resmin) usesecant = .true.}
\DoxyCodeLine{750             resmin = resid}
\DoxyCodeLine{751             \textcolor{keywordflow}{if} (ekemax > 2.e17*us\%m\_s\_to\_L\_T**2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{752               \textcolor{keywordflow}{if} (debugiteration) stop \textcolor{stringliteral}{'Something has gone very wrong'}}
\DoxyCodeLine{753               debugiteration = .true.}
\DoxyCodeLine{754               resid = 1. ; n1 = 0}
\DoxyCodeLine{755               ekemin = 0. ; resmin = 0.}
\DoxyCodeLine{756               ekemax = 0.01*us\%m\_s\_to\_L\_T**2}
\DoxyCodeLine{757               usesecant = .false.}
\DoxyCodeLine{758 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{759 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{760 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! while(resid>0.) searching for right bracket}}
\DoxyCodeLine{761         resmax = resid}
\DoxyCodeLine{762 }
\DoxyCodeLine{763         \textcolor{comment}{! Bisect the bracket}}
\DoxyCodeLine{764         n2 = 0 ; ekeerr = ekemax -\/ ekemin}
\DoxyCodeLine{765         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (ekeerr > tolerance)}
\DoxyCodeLine{766           n2 = n2 + 1}
\DoxyCodeLine{767           \textcolor{keywordflow}{if} (usesecant) \textcolor{keywordflow}{then}}
\DoxyCodeLine{768             eke = ekemin + (ekemax -\/ ekemin) * (resmin / (resmin -\/ resmax))}
\DoxyCodeLine{769           \textcolor{keywordflow}{else}}
\DoxyCodeLine{770             eke = 0.5 * (ekemin + ekemax)}
\DoxyCodeLine{771 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{772           ekeerr = min( eke-\/ekemin, ekemax-\/eke )}
\DoxyCodeLine{773           \textcolor{comment}{! TODO: Should include resolution function in Kh}}
\DoxyCodeLine{774           kh = (khcoeff * sqrt(2.*barotrfac2*eke) * lmixscale)}
\DoxyCodeLine{775           src = kh * (sn * sn)}
\DoxyCodeLine{776           drag\_rate = i\_h * sqrt( drag\_rate\_visc(i,j)**2 + cd2 * ( 2.0*bottomfac2*eke + ubg2 ) )}
\DoxyCodeLine{777           ldamping = cs\%MEKE\_damping + drag\_rate * bottomfac2}
\DoxyCodeLine{778           resid = src -\/ ldamping * eke}
\DoxyCodeLine{779           \textcolor{keywordflow}{if} (usesecant .and. resid>resmin) usesecant = .false.}
\DoxyCodeLine{780           \textcolor{keywordflow}{if} (resid>0.) \textcolor{keywordflow}{then}              \textcolor{comment}{! EKE is to the left of the root}}
\DoxyCodeLine{781             ekemin = eke                  \textcolor{comment}{! so we move the left bracket here}}
\DoxyCodeLine{782             \textcolor{keywordflow}{if} (resid<resmin) usesecant = .true.}
\DoxyCodeLine{783             resmin = resid                \textcolor{comment}{! Save this for the secant method}}
\DoxyCodeLine{784           \textcolor{keywordflow}{elseif} (resid<0.) \textcolor{keywordflow}{then}          \textcolor{comment}{! EKE is to the right of the root}}
\DoxyCodeLine{785             ekemax = eke                  \textcolor{comment}{! so we move the right bracket here}}
\DoxyCodeLine{786             resmax = resid                \textcolor{comment}{! Save this for the secant method}}
\DoxyCodeLine{787           \textcolor{keywordflow}{else}}
\DoxyCodeLine{788             \textcolor{keywordflow}{exit}                          \textcolor{comment}{! resid=0 => EKE is exactly at the root}}
\DoxyCodeLine{789 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{790           \textcolor{keywordflow}{if} (n2>200) stop \textcolor{stringliteral}{'Failing to converge?'}}
\DoxyCodeLine{791 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! while(EKEmax-\/EKEmin>tolerance)}}
\DoxyCodeLine{792 }
\DoxyCodeLine{793       \textcolor{keywordflow}{else}}
\DoxyCodeLine{794         eke = 0.}
\DoxyCodeLine{795 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{796       meke\%MEKE(i,j) = eke}
\DoxyCodeLine{797 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{798 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{799 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a843244b0cc72a08489920dcda464b063}\label{namespacemom__meke_a843244b0cc72a08489920dcda464b063}} 
\index{mom\_meke@{mom\_meke}!meke\_equilibrium\_restoring@{meke\_equilibrium\_restoring}}
\index{meke\_equilibrium\_restoring@{meke\_equilibrium\_restoring}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_equilibrium\_restoring()}{meke\_equilibrium\_restoring()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+equilibrium\+\_\+restoring (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid.\\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type.\\
\hline
 & {\em cs} & M\+E\+KE control structure.\\
\hline
\mbox{\texttt{ in}}  & {\em sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\texttt{ in}}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 805 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{806   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}}
\DoxyCodeLine{807   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type.}}
\DoxyCodeLine{808   \textcolor{keywordtype}{type}(MEKE\_CS),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}}
\DoxyCodeLine{809 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{810 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{811   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{812 \textcolor{keywordtype}{  real} :: SN                      \textcolor{comment}{! The local Eady growth rate [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{813   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je \textcolor{comment}{! local indices}}
\DoxyCodeLine{814 \textcolor{keywordtype}{  real} :: cd2                     \textcolor{comment}{! bottom drag}}
\DoxyCodeLine{815 }
\DoxyCodeLine{816   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{817   cd2 = cs\%cdrag**2}
\DoxyCodeLine{818 }
\DoxyCodeLine{819   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%equilibrium\_value)) \textcolor{keyword}{allocate}(cs\%equilibrium\_value(szi\_(g),szj\_(g)))}
\DoxyCodeLine{820   cs\%equilibrium\_value(:,:) = 0.0}
\DoxyCodeLine{821 }
\DoxyCodeLine{822 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{823   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{824     \textcolor{comment}{! SN = 0.25*max( (SN\_u(I,j) + SN\_u(I-\/1,j)) + (SN\_v(i,J) + SN\_v(i,J-\/1)), 0.)}}
\DoxyCodeLine{825     \textcolor{comment}{! This avoids extremes values in equilibrium solution due to bad values in SN\_u, SN\_v}}
\DoxyCodeLine{826     sn = min(sn\_u(i,j), sn\_u(i-\/1,j), sn\_v(i,j), sn\_v(i,j-\/1))}
\DoxyCodeLine{827     cs\%equilibrium\_value(i,j) = (cs\%MEKE\_GEOMETRIC\_alpha * sn * us\%Z\_to\_m*g\%bathyT(i,j))**2 / cd2}
\DoxyCodeLine{828 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{829 }
\DoxyCodeLine{830   \textcolor{keywordflow}{if} (cs\%id\_MEKE\_equilibrium>0) \textcolor{keyword}{call }post\_data(cs\%id\_MEKE\_equilibrium, cs\%equilibrium\_value, cs\%diag)}
\DoxyCodeLine{831 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}\label{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}} 
\index{mom\_meke@{mom\_meke}!meke\_init@{meke\_init}}
\index{meke\_init@{meke\_init}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_init()}{meke\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+meke\+::meke\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Initializes the M\+O\+M\+\_\+\+M\+E\+KE module and reads parameters. Returns True if module is to be used, otherwise returns False. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file parser structure. \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics structure. \\
\hline
 & {\em cs} & M\+E\+KE control structure. \\
\hline
 & {\em meke} & M\+E\+K\+E-\/related fields. \\
\hline
 & {\em restart\+\_\+cs} & Restart control structure for M\+O\+M\+\_\+\+M\+E\+KE. \\
\hline
\end{DoxyParams}


Definition at line 983 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{984   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current model time.}}
\DoxyCodeLine{985   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{986   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{987   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file parser structure.}}
\DoxyCodeLine{988   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics structure.}}
\DoxyCodeLine{989   \textcolor{keywordtype}{type}(MEKE\_CS),           \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< MEKE control structure.}}
\DoxyCodeLine{990   \textcolor{keywordtype}{type}(MEKE\_type),         \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{       !< MEKE-\/related fields.}}
\DoxyCodeLine{991   \textcolor{keywordtype}{type}(MOM\_restart\_CS),    \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< Restart control structure for MOM\_MEKE.}}
\DoxyCodeLine{992 }
\DoxyCodeLine{993   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{994 \textcolor{keywordtype}{  real}    :: I\_T\_rescale   \textcolor{comment}{! A rescaling factor for time from the internal representation in this}}
\DoxyCodeLine{995                            \textcolor{comment}{! run to the representation in a restart file.}}
\DoxyCodeLine{996 \textcolor{keywordtype}{  real}    :: L\_rescale     \textcolor{comment}{! A rescaling factor for length from the internal representation in this}}
\DoxyCodeLine{997                            \textcolor{comment}{! run to the representation in a restart file.}}
\DoxyCodeLine{998 \textcolor{keywordtype}{  real}    :: MEKE\_restoring\_timescale \textcolor{comment}{! The timescale used to nudge MEKE toward its equilibrium value.}}
\DoxyCodeLine{999 \textcolor{keywordtype}{  real} :: cdrag            \textcolor{comment}{! The default bottom drag coefficient [nondim].}}
\DoxyCodeLine{1000   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, isd, ied, jsd, jed}
\DoxyCodeLine{1001   \textcolor{keywordtype}{logical} :: laplacian, biharmonic, useVarMix, coldStart}
\DoxyCodeLine{1002   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{1003 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{1004 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_MEKE"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{1005 }
\DoxyCodeLine{1006   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{1007   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{1008 }
\DoxyCodeLine{1009   \textcolor{comment}{! Determine whether this module will be used}}
\DoxyCodeLine{1010   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, meke\_init, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1011   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""}, all\_default=.not.meke\_init)}
\DoxyCodeLine{1012   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, meke\_init, \&}
\DoxyCodeLine{1013                  \textcolor{stringliteral}{"If true, turns on the MEKE scheme which calculates "}// \&}
\DoxyCodeLine{1014                  \textcolor{stringliteral}{"a sub-\/grid mesoscale eddy kinetic energy budget."}, \&}
\DoxyCodeLine{1015                  default=.false.)}
\DoxyCodeLine{1016   \textcolor{keywordflow}{if} (.not. meke\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1017 }
\DoxyCodeLine{1018   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1019     \textcolor{comment}{! The MEKE structure should have been allocated in MEKE\_alloc\_register\_restart()}}
\DoxyCodeLine{1020     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MEKE\_init called with NO associated "}// \&}
\DoxyCodeLine{1021                             \textcolor{stringliteral}{"MEKE-\/type structure."})}
\DoxyCodeLine{1022     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1023 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1024   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1025     \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1026       \textcolor{stringliteral}{"MEKE\_init called with an associated control structure."})}
\DoxyCodeLine{1027     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1028   \textcolor{keywordflow}{else} ; \textcolor{keyword}{allocate}(cs) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1029 }
\DoxyCodeLine{1030   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"MEKE\_init: reading parameters "}, 5)}
\DoxyCodeLine{1031 }
\DoxyCodeLine{1032   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{1033   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_DAMPING"}, cs\%MEKE\_damping, \&}
\DoxyCodeLine{1034                  \textcolor{stringliteral}{"The local depth-\/independent MEKE dissipation rate."}, \&}
\DoxyCodeLine{1035                  units=\textcolor{stringliteral}{"s-\/1"}, default=0.0, scale=us\%T\_to\_s)}
\DoxyCodeLine{1036   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CD\_SCALE"}, cs\%MEKE\_Cd\_scale, \&}
\DoxyCodeLine{1037                  \textcolor{stringliteral}{"The ratio of the bottom eddy velocity to the column mean "}//\&}
\DoxyCodeLine{1038                  \textcolor{stringliteral}{"eddy velocity, i.e. sqrt(2*MEKE). This should be less than 1 "}//\&}
\DoxyCodeLine{1039                  \textcolor{stringliteral}{"to account for the surface intensification of MEKE."}, \&}
\DoxyCodeLine{1040                  units=\textcolor{stringliteral}{"nondim"}, default=0.)}
\DoxyCodeLine{1041   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CB"}, cs\%MEKE\_Cb, \&}
\DoxyCodeLine{1042                  \textcolor{stringliteral}{"A coefficient in the expression for the ratio of bottom projected "}//\&}
\DoxyCodeLine{1043                  \textcolor{stringliteral}{"eddy energy and mean column energy (see Jansen et al. 2015)."},\&}
\DoxyCodeLine{1044                  units=\textcolor{stringliteral}{"nondim"}, default=25.)}
\DoxyCodeLine{1045   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_MIN\_GAMMA2"}, cs\%MEKE\_min\_gamma, \&}
\DoxyCodeLine{1046                  \textcolor{stringliteral}{"The minimum allowed value of gamma\_b\string^2."},\&}
\DoxyCodeLine{1047                  units=\textcolor{stringliteral}{"nondim"}, default=0.0001)}
\DoxyCodeLine{1048   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CT"}, cs\%MEKE\_Ct, \&}
\DoxyCodeLine{1049                  \textcolor{stringliteral}{"A coefficient in the expression for the ratio of barotropic "}//\&}
\DoxyCodeLine{1050                  \textcolor{stringliteral}{"eddy energy and mean column energy (see Jansen et al. 2015)."},\&}
\DoxyCodeLine{1051                  units=\textcolor{stringliteral}{"nondim"}, default=50.)}
\DoxyCodeLine{1052   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GMCOEFF"}, cs\%MEKE\_GMcoeff, \&}
\DoxyCodeLine{1053                  \textcolor{stringliteral}{"The efficiency of the conversion of potential energy "}//\&}
\DoxyCodeLine{1054                  \textcolor{stringliteral}{"into MEKE by the thickness mixing parameterization. "}//\&}
\DoxyCodeLine{1055                  \textcolor{stringliteral}{"If MEKE\_GMCOEFF is negative, this conversion is not "}//\&}
\DoxyCodeLine{1056                  \textcolor{stringliteral}{"used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-\/1.0)}
\DoxyCodeLine{1057   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GEOMETRIC"}, cs\%MEKE\_GEOMETRIC, \&}
\DoxyCodeLine{1058                  \textcolor{stringliteral}{"If MEKE\_GEOMETRIC is true, uses the GM coefficient formulation "}//\&}
\DoxyCodeLine{1059                  \textcolor{stringliteral}{"from the GEOMETRIC framework (Marshall et al., 2012)."}, default=.false.)}
\DoxyCodeLine{1060   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GEOMETRIC\_ALPHA"}, cs\%MEKE\_GEOMETRIC\_alpha, \&}
\DoxyCodeLine{1061                  \textcolor{stringliteral}{"The nondimensional coefficient governing the efficiency of the GEOMETRIC \(\backslash\)n"}//\&}
\DoxyCodeLine{1062                  \textcolor{stringliteral}{"thickness diffusion."}, units=\textcolor{stringliteral}{"nondim"}, default=0.05)}
\DoxyCodeLine{1063   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_EQUILIBRIUM\_ALT"}, cs\%MEKE\_equilibrium\_alt, \&}
\DoxyCodeLine{1064                  \textcolor{stringliteral}{"If true, use an alternative formula for computing the (equilibrium)"}//\&}
\DoxyCodeLine{1065                  \textcolor{stringliteral}{"initial value of MEKE."}, default=.false.)}
\DoxyCodeLine{1066   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_EQUILIBRIUM\_RESTORING"}, cs\%MEKE\_equilibrium\_restoring, \&}
\DoxyCodeLine{1067                  \textcolor{stringliteral}{"If true, restore MEKE back to its equilibrium value, which is calculated at "}//\&}
\DoxyCodeLine{1068                  \textcolor{stringliteral}{"each time step."}, default=.false.)}
\DoxyCodeLine{1069   \textcolor{keywordflow}{if} (cs\%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1070     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_RESTORING\_TIMESCALE"}, meke\_restoring\_timescale, \&}
\DoxyCodeLine{1071                    \textcolor{stringliteral}{"The timescale used to nudge MEKE toward its equilibrium value."}, units=\textcolor{stringliteral}{"s"}, \&}
\DoxyCodeLine{1072                    default=1e6, scale=us\%T\_to\_s)}
\DoxyCodeLine{1073     cs\%MEKE\_restoring\_rate = 1.0 / meke\_restoring\_timescale}
\DoxyCodeLine{1074 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1075 }
\DoxyCodeLine{1076   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_FRCOEFF"}, cs\%MEKE\_FrCoeff, \&}
\DoxyCodeLine{1077                  \textcolor{stringliteral}{"The efficiency of the conversion of mean energy into "}//\&}
\DoxyCodeLine{1078                  \textcolor{stringliteral}{"MEKE.  If MEKE\_FRCOEFF is negative, this conversion "}//\&}
\DoxyCodeLine{1079                  \textcolor{stringliteral}{"is not used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-\/1.0)}
\DoxyCodeLine{1080   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GMECOEFF"}, cs\%MEKE\_GMECoeff, \&}
\DoxyCodeLine{1081                  \textcolor{stringliteral}{"The efficiency of the conversion of MEKE into mean energy "}//\&}
\DoxyCodeLine{1082                  \textcolor{stringliteral}{"by GME.  If MEKE\_GMECOEFF is negative, this conversion "}//\&}
\DoxyCodeLine{1083                  \textcolor{stringliteral}{"is not used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-\/1.0)}
\DoxyCodeLine{1084   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BGSRC"}, cs\%MEKE\_BGsrc, \&}
\DoxyCodeLine{1085                  \textcolor{stringliteral}{"A background energy source for MEKE."}, units=\textcolor{stringliteral}{"W kg-\/1"}, \&}
\DoxyCodeLine{1086                  default=0.0, scale=us\%m\_to\_L**2*us\%T\_to\_s**3)}
\DoxyCodeLine{1087   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KH"}, cs\%MEKE\_Kh, \&}
\DoxyCodeLine{1088                  \textcolor{stringliteral}{"A background lateral diffusivity of MEKE. "}//\&}
\DoxyCodeLine{1089                  \textcolor{stringliteral}{"Use a negative value to not apply lateral diffusion to MEKE."}, \&}
\DoxyCodeLine{1090                  units=\textcolor{stringliteral}{"m2 s-\/1"}, default=-\/1.0, scale=us\%m\_to\_L**2*us\%T\_to\_s)}
\DoxyCodeLine{1091   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_K4"}, cs\%MEKE\_K4, \&}
\DoxyCodeLine{1092                  \textcolor{stringliteral}{"A lateral bi-\/harmonic diffusivity of MEKE. "}//\&}
\DoxyCodeLine{1093                  \textcolor{stringliteral}{"Use a negative value to not apply bi-\/harmonic diffusion to MEKE."}, \&}
\DoxyCodeLine{1094                  units=\textcolor{stringliteral}{"m4 s-\/1"}, default=-\/1.0, scale=us\%m\_to\_L**4*us\%T\_to\_s)}
\DoxyCodeLine{1095   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_DTSCALE"}, cs\%MEKE\_dtScale, \&}
\DoxyCodeLine{1096                  \textcolor{stringliteral}{"A scaling factor to accelerate the time evolution of MEKE."}, \&}
\DoxyCodeLine{1097                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{1098   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHCOEFF"}, cs\%MEKE\_KhCoeff, \&}
\DoxyCodeLine{1099                  \textcolor{stringliteral}{"A scaling factor in the expression for eddy diffusivity "}//\&}
\DoxyCodeLine{1100                  \textcolor{stringliteral}{"which is otherwise proportional to the MEKE velocity-\/ "}//\&}
\DoxyCodeLine{1101                  \textcolor{stringliteral}{"scale times an eddy mixing-\/length. This factor "}//\&}
\DoxyCodeLine{1102                  \textcolor{stringliteral}{"must be >0 for MEKE to contribute to the thickness/ "}//\&}
\DoxyCodeLine{1103                  \textcolor{stringliteral}{"and tracer diffusivity in the rest of the model."}, \&}
\DoxyCodeLine{1104                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{1105   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_USCALE"}, cs\%MEKE\_Uscale, \&}
\DoxyCodeLine{1106                  \textcolor{stringliteral}{"The background velocity that is combined with MEKE to "}//\&}
\DoxyCodeLine{1107                  \textcolor{stringliteral}{"calculate the bottom drag."}, units=\textcolor{stringliteral}{"m s-\/1"}, default=0.0, scale=us\%m\_s\_to\_L\_T)}
\DoxyCodeLine{1108   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GM\_SRC\_ALT"}, cs\%GM\_src\_alt, \&}
\DoxyCodeLine{1109                  \textcolor{stringliteral}{"If true, use the GM energy conversion form S\string^2*N\string^2*kappa rather "}//\&}
\DoxyCodeLine{1110                  \textcolor{stringliteral}{"than the streamfunction for the MEKE GM source term."}, default=.false.)}
\DoxyCodeLine{1111   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISC\_DRAG"}, cs\%visc\_drag, \&}
\DoxyCodeLine{1112                  \textcolor{stringliteral}{"If true, use the vertvisc\_type to calculate the bottom "}//\&}
\DoxyCodeLine{1113                  \textcolor{stringliteral}{"drag acting on MEKE."}, default=.true.)}
\DoxyCodeLine{1114   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHTH\_FAC"}, meke\%KhTh\_fac, \&}
\DoxyCodeLine{1115                  \textcolor{stringliteral}{"A factor that maps MEKE\%Kh to KhTh."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{1116                  default=0.0)}
\DoxyCodeLine{1117   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHTR\_FAC"}, meke\%KhTr\_fac, \&}
\DoxyCodeLine{1118                  \textcolor{stringliteral}{"A factor that maps MEKE\%Kh to KhTr."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{1119                  default=0.0)}
\DoxyCodeLine{1120   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHMEKE\_FAC"}, cs\%KhMEKE\_Fac, \&}
\DoxyCodeLine{1121                  \textcolor{stringliteral}{"A factor that maps MEKE\%Kh to Kh for MEKE itself."}, \&}
\DoxyCodeLine{1122                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1123   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_OLD\_LSCALE"}, cs\%use\_old\_lscale, \&}
\DoxyCodeLine{1124                  \textcolor{stringliteral}{"If true, use the old formula for length scale which is "}//\&}
\DoxyCodeLine{1125                  \textcolor{stringliteral}{"a function of grid spacing and deformation radius."},  \&}
\DoxyCodeLine{1126                  default=.false.)}
\DoxyCodeLine{1127   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_MIN\_LSCALE"}, cs\%use\_min\_lscale, \&}
\DoxyCodeLine{1128                  \textcolor{stringliteral}{"If true, use a strict minimum of provided length scales "}//\&}
\DoxyCodeLine{1129                  \textcolor{stringliteral}{"rather than harmonic mean."},  \&}
\DoxyCodeLine{1130                  default=.false.)}
\DoxyCodeLine{1131   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_RD\_MAX\_SCALE"}, cs\%Rd\_as\_max\_scale, \&}
\DoxyCodeLine{1132                  \textcolor{stringliteral}{"If true, the length scale used by MEKE is the minimum of "}//\&}
\DoxyCodeLine{1133                  \textcolor{stringliteral}{"the deformation radius or grid-\/spacing. Only used if "}//\&}
\DoxyCodeLine{1134                  \textcolor{stringliteral}{"MEKE\_OLD\_LSCALE=True"}, units=\textcolor{stringliteral}{"nondim"}, default=.false.)}
\DoxyCodeLine{1135   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_KU"}, cs\%viscosity\_coeff\_Ku, \&}
\DoxyCodeLine{1136                  \textcolor{stringliteral}{"If non-\/zero, is the scaling coefficient in the expression for"}//\&}
\DoxyCodeLine{1137                  \textcolor{stringliteral}{"viscosity used to parameterize harmonic lateral momentum mixing by"}//\&}
\DoxyCodeLine{1138                  \textcolor{stringliteral}{"unresolved eddies represented by MEKE. Can be negative to"}//\&}
\DoxyCodeLine{1139                  \textcolor{stringliteral}{"represent backscatter from the unresolved eddies."}, \&}
\DoxyCodeLine{1140                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1141   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_AU"}, cs\%viscosity\_coeff\_Au, \&}
\DoxyCodeLine{1142                  \textcolor{stringliteral}{"If non-\/zero, is the scaling coefficient in the expression for"}//\&}
\DoxyCodeLine{1143                  \textcolor{stringliteral}{"viscosity used to parameterize biharmonic lateral momentum mixing by"}//\&}
\DoxyCodeLine{1144                  \textcolor{stringliteral}{"unresolved eddies represented by MEKE. Can be negative to"}//\&}
\DoxyCodeLine{1145                  \textcolor{stringliteral}{"represent backscatter from the unresolved eddies."}, \&}
\DoxyCodeLine{1146                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1147   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_FIXED\_MIXING\_LENGTH"}, cs\%Lfixed, \&}
\DoxyCodeLine{1148                  \textcolor{stringliteral}{"If positive, is a fixed length contribution to the expression "}//\&}
\DoxyCodeLine{1149                  \textcolor{stringliteral}{"for mixing length used in MEKE-\/derived diffusivity."}, \&}
\DoxyCodeLine{1150                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us\%m\_to\_L)}
\DoxyCodeLine{1151   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_DEFORM"}, cs\%aDeform, \&}
\DoxyCodeLine{1152                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the deformation scale "}//\&}
\DoxyCodeLine{1153                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-\/derived diffusivity."}, \&}
\DoxyCodeLine{1154                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1155   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_RHINES"}, cs\%aRhines, \&}
\DoxyCodeLine{1156                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the Rhines scale "}//\&}
\DoxyCodeLine{1157                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-\/derived diffusivity."}, \&}
\DoxyCodeLine{1158                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1159   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_EADY"}, cs\%aEady, \&}
\DoxyCodeLine{1160                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the Eady length scale "}//\&}
\DoxyCodeLine{1161                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-\/derived diffusivity."}, \&}
\DoxyCodeLine{1162                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1163   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_FRICT"}, cs\%aFrict, \&}
\DoxyCodeLine{1164                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the frictional arrest scale "}//\&}
\DoxyCodeLine{1165                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-\/derived diffusivity."}, \&}
\DoxyCodeLine{1166                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1167   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_GRID"}, cs\%aGrid, \&}
\DoxyCodeLine{1168                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the grid-\/spacing as a scale "}//\&}
\DoxyCodeLine{1169                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-\/derived diffusivity."}, \&}
\DoxyCodeLine{1170                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1171   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_COLD\_START"}, coldstart, \&}
\DoxyCodeLine{1172                  \textcolor{stringliteral}{"If true, initialize EKE to zero. Otherwise a local equilibrium solution "}//\&}
\DoxyCodeLine{1173                  \textcolor{stringliteral}{"is used as an initial condition for EKE."}, default=.false.)}
\DoxyCodeLine{1174   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BACKSCAT\_RO\_C"}, meke\%backscatter\_Ro\_c, \&}
\DoxyCodeLine{1175                  \textcolor{stringliteral}{"The coefficient in the Rossby number function for scaling the biharmonic "}//\&}
\DoxyCodeLine{1176                  \textcolor{stringliteral}{"frictional energy source. Setting to non-\/zero enables the Rossby number function."}, \&}
\DoxyCodeLine{1177                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1178   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BACKSCAT\_RO\_POW"}, meke\%backscatter\_Ro\_pow, \&}
\DoxyCodeLine{1179                  \textcolor{stringliteral}{"The power in the Rossby number function for scaling the biharmonic "}//\&}
\DoxyCodeLine{1180                  \textcolor{stringliteral}{"frictional energy source."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1181   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ADVECTION\_FACTOR"}, cs\%MEKE\_advection\_factor, \&}
\DoxyCodeLine{1182                  \textcolor{stringliteral}{"A scale factor in front of advection of eddy energy. Zero turns advection off. "}//\&}
\DoxyCodeLine{1183                  \textcolor{stringliteral}{"Using unity would be normal but other values could accommodate a mismatch "}//\&}
\DoxyCodeLine{1184                  \textcolor{stringliteral}{"between the advecting barotropic flow and the vertical structure of MEKE."}, \&}
\DoxyCodeLine{1185                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1186   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_TOPOGRAPHIC\_BETA"}, cs\%MEKE\_topographic\_beta, \&}
\DoxyCodeLine{1187                  \textcolor{stringliteral}{"A scale factor to determine how much topographic beta is weighed in "} //\&}
\DoxyCodeLine{1188                  \textcolor{stringliteral}{"computing beta in the expression of Rhines scale. Use 1 if full "}//\&}
\DoxyCodeLine{1189                  \textcolor{stringliteral}{"topographic beta effect is considered; use 0 if it's completely ignored."}, \&}
\DoxyCodeLine{1190                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{1191 }
\DoxyCodeLine{1192   \textcolor{comment}{! Nonlocal module parameters}}
\DoxyCodeLine{1193   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CDRAG"}, cdrag, \&}
\DoxyCodeLine{1194                  \textcolor{stringliteral}{"CDRAG is the drag coefficient relating the magnitude of "}//\&}
\DoxyCodeLine{1195                  \textcolor{stringliteral}{"the velocity field to the bottom stress."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{1196                  default=0.003)}
\DoxyCodeLine{1197   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CDRAG"}, cs\%cdrag, \&}
\DoxyCodeLine{1198                  \textcolor{stringliteral}{"Drag coefficient relating the magnitude of the velocity "}//\&}
\DoxyCodeLine{1199                  \textcolor{stringliteral}{"field to the bottom stress in MEKE."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{1200                  default=cdrag)}
\DoxyCodeLine{1201   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAPLACIAN"}, laplacian, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1202   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BIHARMONIC"}, biharmonic, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1203 }
\DoxyCodeLine{1204   \textcolor{keywordflow}{if} (cs\%viscosity\_coeff\_Ku/=0. .and. .not. laplacian) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1205                  \textcolor{stringliteral}{"LAPLACIAN must be true if MEKE\_VISCOSITY\_COEFF\_KU is true."})}
\DoxyCodeLine{1206 }
\DoxyCodeLine{1207   \textcolor{keywordflow}{if} (cs\%viscosity\_coeff\_Au/=0. .and. .not. biharmonic) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1208                  \textcolor{stringliteral}{"BIHARMONIC must be true if MEKE\_VISCOSITY\_COEFF\_AU is true."})}
\DoxyCodeLine{1209 }
\DoxyCodeLine{1210   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs\%debug, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1211 }
\DoxyCodeLine{1212   \textcolor{comment}{! Identify if any lateral diffusive processes are active}}
\DoxyCodeLine{1213   cs\%kh\_flux\_enabled = .false.}
\DoxyCodeLine{1214   \textcolor{keywordflow}{if} ((cs\%MEKE\_KH >= 0.0)  .or. (cs\%KhMEKE\_FAC > 0.0) .or. (cs\%MEKE\_advection\_factor > 0.0)) \&}
\DoxyCodeLine{1215     cs\%kh\_flux\_enabled = .true.}
\DoxyCodeLine{1216 }
\DoxyCodeLine{1217 \textcolor{comment}{! Register fields for output from this module.}}
\DoxyCodeLine{1218   cs\%diag => diag}
\DoxyCodeLine{1219   cs\%id\_MEKE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1220      \textcolor{stringliteral}{'Mesoscale Eddy Kinetic Energy'}, \textcolor{stringliteral}{'m2 s-\/2'}, conversion=us\%L\_T\_to\_m\_s**2)}
\DoxyCodeLine{1221   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%MEKE)) cs\%id\_MEKE = -\/1}
\DoxyCodeLine{1222   cs\%id\_Kh = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_KH'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1223      \textcolor{stringliteral}{'MEKE derived diffusivity'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{1224   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%Kh)) cs\%id\_Kh = -\/1}
\DoxyCodeLine{1225   cs\%id\_Ku = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_KU'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1226      \textcolor{stringliteral}{'MEKE derived lateral viscosity'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{1227   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%Ku)) cs\%id\_Ku = -\/1}
\DoxyCodeLine{1228   cs\%id\_Au = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_AU'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1229      \textcolor{stringliteral}{'MEKE derived lateral biharmonic viscosity'}, \textcolor{stringliteral}{'m4 s-\/1'}, conversion=us\%L\_to\_m**4*us\%s\_to\_T)}
\DoxyCodeLine{1230   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%Au)) cs\%id\_Au = -\/1}
\DoxyCodeLine{1231   cs\%id\_Ue = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ue'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1232      \textcolor{stringliteral}{'MEKE derived eddy-\/velocity scale'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{1233   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%MEKE)) cs\%id\_Ue = -\/1}
\DoxyCodeLine{1234   cs\%id\_Ub = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ub'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1235      \textcolor{stringliteral}{'MEKE derived bottom eddy-\/velocity scale'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{1236   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%MEKE)) cs\%id\_Ub = -\/1}
\DoxyCodeLine{1237   cs\%id\_Ut = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ut'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1238      \textcolor{stringliteral}{'MEKE derived barotropic eddy-\/velocity scale'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{1239   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%MEKE)) cs\%id\_Ut = -\/1}
\DoxyCodeLine{1240   cs\%id\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_src'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1241      \textcolor{stringliteral}{'MEKE energy source'}, \textcolor{stringliteral}{'m2 s-\/3'}, conversion=(us\%L\_T\_to\_m\_s**2)*us\%s\_to\_T)}
\DoxyCodeLine{1242   cs\%id\_decay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_decay'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1243      \textcolor{stringliteral}{'MEKE decay rate'}, \textcolor{stringliteral}{'s-\/1'}, conversion=us\%s\_to\_T)}
\DoxyCodeLine{1244   cs\%id\_GM\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_GM\_src'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1245      \textcolor{stringliteral}{'MEKE energy available from thickness mixing'}, \&}
\DoxyCodeLine{1246      \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2*us\%L\_to\_Z**2)}
\DoxyCodeLine{1247   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%GM\_src)) cs\%id\_GM\_src = -\/1}
\DoxyCodeLine{1248   cs\%id\_mom\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_mom\_src'},diag\%axesT1, time, \&}
\DoxyCodeLine{1249      \textcolor{stringliteral}{'MEKE energy available from momentum'}, \&}
\DoxyCodeLine{1250      \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2*us\%L\_to\_Z**2)}
\DoxyCodeLine{1251   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%mom\_src)) cs\%id\_mom\_src = -\/1}
\DoxyCodeLine{1252   cs\%id\_GME\_snk = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_GME\_snk'},diag\%axesT1, time, \&}
\DoxyCodeLine{1253      \textcolor{stringliteral}{'MEKE energy lost to GME backscatter'}, \&}
\DoxyCodeLine{1254      \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2*us\%L\_to\_Z**2)}
\DoxyCodeLine{1255   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke\%GME\_snk)) cs\%id\_GME\_snk = -\/1}
\DoxyCodeLine{1256   cs\%id\_Le = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Le'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1257      \textcolor{stringliteral}{'Eddy mixing length used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us\%L\_to\_m)}
\DoxyCodeLine{1258   cs\%id\_Lrhines = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Lrhines'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1259      \textcolor{stringliteral}{'Rhines length scale used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us\%L\_to\_m)}
\DoxyCodeLine{1260   cs\%id\_Leady = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Leady'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1261      \textcolor{stringliteral}{'Eady length scale used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us\%L\_to\_m)}
\DoxyCodeLine{1262   cs\%id\_gamma\_b = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_gamma\_b'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1263      \textcolor{stringliteral}{'Ratio of bottom-\/projected eddy velocity to column-\/mean eddy velocity'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{1264   cs\%id\_gamma\_t = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_gamma\_t'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1265      \textcolor{stringliteral}{'Ratio of barotropic eddy velocity to column-\/mean eddy velocity'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{1266 }
\DoxyCodeLine{1267   \textcolor{keywordflow}{if} (cs\%kh\_flux\_enabled) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1268     cs\%id\_KhMEKE\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KHMEKE\_u'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{1269      \textcolor{stringliteral}{'Zonal diffusivity of MEKE'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{1270     cs\%id\_KhMEKE\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KHMEKE\_v'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{1271      \textcolor{stringliteral}{'Meridional diffusivity of MEKE'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{1272 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1273 }
\DoxyCodeLine{1274   \textcolor{keywordflow}{if} (cs\%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1275     cs\%id\_MEKE\_equilibrium = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_equilibrium'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1276      \textcolor{stringliteral}{'Equilibrated Mesoscale Eddy Kinetic Energy'}, \textcolor{stringliteral}{'m2 s-\/2'}, conversion=us\%L\_T\_to\_m\_s**2)}
\DoxyCodeLine{1277 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1278 }
\DoxyCodeLine{1279   cs\%id\_clock\_pass = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity halo updates)'}, grain=clock\_routine)}
\DoxyCodeLine{1280 }
\DoxyCodeLine{1281   \textcolor{comment}{! Detect whether this instance of MEKE\_init() is at the beginning of a run}}
\DoxyCodeLine{1282   \textcolor{comment}{! or after a restart. If at the beginning, we will initialize MEKE to a local}}
\DoxyCodeLine{1283   \textcolor{comment}{! equilibrium.}}
\DoxyCodeLine{1284   cs\%initialize = .not.query\_initialized(meke\%MEKE, \textcolor{stringliteral}{"MEKE"}, restart\_cs)}
\DoxyCodeLine{1285   \textcolor{keywordflow}{if} (coldstart) cs\%initialize = .false.}
\DoxyCodeLine{1286   \textcolor{keywordflow}{if} (cs\%initialize) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1287                        \textcolor{stringliteral}{"MEKE\_init: Initializing MEKE with a local equilibrium balance."})}
\DoxyCodeLine{1288 }
\DoxyCodeLine{1289   \textcolor{comment}{! Account for possible changes in dimensional scaling for variables that have been}}
\DoxyCodeLine{1290   \textcolor{comment}{! read from a restart file.}}
\DoxyCodeLine{1291   i\_t\_rescale = 1.0}
\DoxyCodeLine{1292   \textcolor{keywordflow}{if} ((us\%s\_to\_T\_restart /= 0.0) .and. (us\%s\_to\_T\_restart /= us\%s\_to\_T)) \&}
\DoxyCodeLine{1293     i\_t\_rescale = us\%s\_to\_T\_restart / us\%s\_to\_T}
\DoxyCodeLine{1294   l\_rescale = 1.0}
\DoxyCodeLine{1295   \textcolor{keywordflow}{if} ((us\%m\_to\_L\_restart /= 0.0) .and. (us\%m\_to\_L\_restart /= us\%m\_to\_L)) \&}
\DoxyCodeLine{1296     l\_rescale = us\%m\_to\_L / us\%m\_to\_L\_restart}
\DoxyCodeLine{1297 }
\DoxyCodeLine{1298   \textcolor{keywordflow}{if} (l\_rescale*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1299     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%MEKE)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke\%MEKE, \textcolor{stringliteral}{"MEKE\_MEKE"}, restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1300       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1301         meke\%MEKE(i,j) = l\_rescale*i\_t\_rescale * meke\%MEKE(i,j)}
\DoxyCodeLine{1302 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1303 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1304 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1305   \textcolor{keywordflow}{if} (l\_rescale**2*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1306     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke\%Kh, \textcolor{stringliteral}{"MEKE\_Kh"}, restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1307       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1308         meke\%Kh(i,j) = l\_rescale**2*i\_t\_rescale * meke\%Kh(i,j)}
\DoxyCodeLine{1309 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1310 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1311     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Ku)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke\%Ku, \textcolor{stringliteral}{"MEKE\_Ku"}, restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1312       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1313         meke\%Ku(i,j) = l\_rescale**2*i\_t\_rescale * meke\%Ku(i,j)}
\DoxyCodeLine{1314 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1315 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1316     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh\_diff)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke\%Kh, \textcolor{stringliteral}{"MEKE\_Kh\_diff"}, restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1317       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1318         meke\%Kh\_diff(i,j) = l\_rescale**2*i\_t\_rescale * meke\%Kh\_diff(i,j)}
\DoxyCodeLine{1319 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1320 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1321 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1322   \textcolor{keywordflow}{if} (l\_rescale**4*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1323     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Au)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke\%Au, \textcolor{stringliteral}{"MEKE\_Au"}, restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1324       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1325         meke\%Au(i,j) = l\_rescale**4*i\_t\_rescale * meke\%Au(i,j)}
\DoxyCodeLine{1326 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1327 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1328 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1329 }
\DoxyCodeLine{1330   \textcolor{comment}{! Set up group passes.  In the case of a restart, these fields need a halo update now.}}
\DoxyCodeLine{1331   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%MEKE)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1332     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_MEKE, meke\%MEKE, g\%Domain)}
\DoxyCodeLine{1333     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh\_diff)) \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_MEKE, meke\%Kh\_diff, g\%Domain)}
\DoxyCodeLine{1334     \textcolor{keywordflow}{if} (.not.cs\%initialize) \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_MEKE, g\%Domain)}
\DoxyCodeLine{1335 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1336   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh)) \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_Kh, meke\%Kh, g\%Domain)}
\DoxyCodeLine{1337   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Ku)) \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_Kh, meke\%Ku, g\%Domain)}
\DoxyCodeLine{1338   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Au)) \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_Kh, meke\%Au, g\%Domain)}
\DoxyCodeLine{1339 }
\DoxyCodeLine{1340   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh) .or. \textcolor{keyword}{associated}(meke\%Ku) .or. \textcolor{keyword}{associated}(meke\%Au)) \&}
\DoxyCodeLine{1341     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_Kh, g\%Domain)}
\DoxyCodeLine{1342 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}\label{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}} 
\index{mom\_meke@{mom\_meke}!meke\_lengthscales@{meke\_lengthscales}}
\index{meke\_lengthscales@{meke\_lengthscales}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_lengthscales()}{meke\_lengthscales()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+lengthscales (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{E\+KE,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{bottom\+Fac2,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{barotr\+Fac2,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{Lmix\+Scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \mbox{\hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}}. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+E\+KE control structure. \\
\hline
 & {\em meke} & M\+E\+KE data. \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid. \\
\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 sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eke} & Eddy kinetic energy \mbox{[}L2 T-\/2 $\sim$$>$ m2 s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em bottomfac2} & gamma\+\_\+b$^\wedge$2 \\
\hline
\mbox{\texttt{ out}}  & {\em barotrfac2} & gamma\+\_\+t$^\wedge$2 \\
\hline
\mbox{\texttt{ out}}  & {\em lmixscale} & Eddy mixing length \mbox{[}L $\sim$$>$ m\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 837 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{839   \textcolor{keywordtype}{type}(MEKE\_CS),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}}
\DoxyCodeLine{840   \textcolor{keywordtype}{type}(MEKE\_type),                   \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{ !< MEKE data.}}
\DoxyCodeLine{841   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}}
\DoxyCodeLine{842   \textcolor{keywordtype}{type}(verticalGrid\_type),           \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid structure.}}
\DoxyCodeLine{843   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{844 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{845 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{846 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: EKE\textcolor{comment}{  !< Eddy kinetic energy [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{847 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: bottomFac2\textcolor{comment}{ !< gamma\_b\string^2}}
\DoxyCodeLine{848 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: barotrFac2\textcolor{comment}{ !< gamma\_t\string^2}}
\DoxyCodeLine{849 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: LmixScale\textcolor{comment}{ !< Eddy mixing length [L \string~> m].}}
\DoxyCodeLine{850   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{851 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: LRhines, LEady  \textcolor{comment}{! Possible mixing length scales [L \string~> m]}}
\DoxyCodeLine{852 \textcolor{keywordtype}{  real} :: beta \textcolor{comment}{! Combined topograpic and planetary vorticity gradient [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{853 \textcolor{keywordtype}{  real} :: SN   \textcolor{comment}{! The local Eady growth rate [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{854 \textcolor{keywordtype}{  real} :: FatH \textcolor{comment}{! Coriolis parameter at h points [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{855 \textcolor{keywordtype}{  real} :: beta\_topo\_x, beta\_topo\_y  \textcolor{comment}{! Topographic PV gradients in x and y [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{856   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{857 }
\DoxyCodeLine{858   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{859 }
\DoxyCodeLine{860 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{861   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{862     \textcolor{keywordflow}{if} (.not.cs\%use\_old\_lscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{863       \textcolor{keywordflow}{if} (cs\%aEady > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{864         sn = 0.25 * ( (sn\_u(i,j) + sn\_u(i-\/1,j)) + (sn\_v(i,j) + sn\_v(i,j-\/1)) )}
\DoxyCodeLine{865       \textcolor{keywordflow}{else}}
\DoxyCodeLine{866         sn = 0.}
\DoxyCodeLine{867 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{868       fath = 0.25* ( ( g\%CoriolisBu(i,j) + g\%CoriolisBu(i-\/1,j-\/1) ) + \&}
\DoxyCodeLine{869                      ( g\%CoriolisBu(i-\/1,j) + g\%CoriolisBu(i,j-\/1) ) )  \textcolor{comment}{! Coriolis parameter at h points}}
\DoxyCodeLine{870 }
\DoxyCodeLine{871       \textcolor{comment}{! If bathyT is zero, then a division by zero FPE will be raised.  In this}}
\DoxyCodeLine{872       \textcolor{comment}{! case, we apply Adcroft's rule of reciprocals and set the term to zero.}}
\DoxyCodeLine{873       \textcolor{comment}{! Since zero-\/bathymetry cells are masked, this should not affect values.}}
\DoxyCodeLine{874       \textcolor{keywordflow}{if} (cs\%MEKE\_topographic\_beta == 0. .or. g\%bathyT(i,j) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{875         beta\_topo\_x = 0. ; beta\_topo\_y = 0.}
\DoxyCodeLine{876       \textcolor{keywordflow}{else}}
\DoxyCodeLine{877         \textcolor{comment}{!\#\#\# Consider different combinations of these estimates of topographic beta, and the use}}
\DoxyCodeLine{878         \textcolor{comment}{!    of the water column thickness instead of the bathymetric depth.}}
\DoxyCodeLine{879         beta\_topo\_x = -\/cs\%MEKE\_topographic\_beta * fath * 0.5 * ( \&}
\DoxyCodeLine{880                       (g\%bathyT(i+1,j)-\/g\%bathyT(i,j)) * g\%IdxCu(i,j)  \&}
\DoxyCodeLine{881                  / max(g\%bathyT(i+1,j),g\%bathyT(i,j), gv\%H\_subroundoff) \&}
\DoxyCodeLine{882               +       (g\%bathyT(i,j)-\/g\%bathyT(i-\/1,j)) * g\%IdxCu(i-\/1,j) \&}
\DoxyCodeLine{883                  / max(g\%bathyT(i,j),g\%bathyT(i-\/1,j), gv\%H\_subroundoff) )}
\DoxyCodeLine{884         beta\_topo\_y = -\/cs\%MEKE\_topographic\_beta * fath * 0.5 * ( \&}
\DoxyCodeLine{885                       (g\%bathyT(i,j+1)-\/g\%bathyT(i,j)) * g\%IdyCv(i,j)  \&}
\DoxyCodeLine{886                  / max(g\%bathyT(i,j+1),g\%bathyT(i,j), gv\%H\_subroundoff) + \&}
\DoxyCodeLine{887                       (g\%bathyT(i,j)-\/g\%bathyT(i,j-\/1)) * g\%IdyCv(i,j-\/1) \&}
\DoxyCodeLine{888                  / max(g\%bathyT(i,j),g\%bathyT(i,j-\/1), gv\%H\_subroundoff) )}
\DoxyCodeLine{889 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{890       beta =  sqrt((g\%dF\_dx(i,j) + beta\_topo\_x)**2 + \&}
\DoxyCodeLine{891                    (g\%dF\_dy(i,j) + beta\_topo\_y)**2 )}
\DoxyCodeLine{892 }
\DoxyCodeLine{893     \textcolor{keywordflow}{else}}
\DoxyCodeLine{894       beta = 0.}
\DoxyCodeLine{895 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{896     \textcolor{comment}{! Returns bottomFac2, barotrFac2 and LmixScale}}
\DoxyCodeLine{897     \textcolor{keyword}{call }meke\_lengthscales\_0d(cs, us, g\%areaT(i,j), beta, g\%bathyT(i,j),  \&}
\DoxyCodeLine{898                               meke\%Rd\_dx\_h(i,j), sn, meke\%MEKE(i,j), \&}
\DoxyCodeLine{899                               bottomfac2(i,j), barotrfac2(i,j), lmixscale(i,j), \&}
\DoxyCodeLine{900                               lrhines(i,j), leady(i,j))}
\DoxyCodeLine{901 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{902   \textcolor{keywordflow}{if} (cs\%id\_Lrhines>0) \textcolor{keyword}{call }post\_data(cs\%id\_LRhines, lrhines, cs\%diag)}
\DoxyCodeLine{903   \textcolor{keywordflow}{if} (cs\%id\_Leady>0) \textcolor{keyword}{call }post\_data(cs\%id\_LEady, leady, cs\%diag)}
\DoxyCodeLine{904 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}\label{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}} 
\index{mom\_meke@{mom\_meke}!meke\_lengthscales\_0d@{meke\_lengthscales\_0d}}
\index{meke\_lengthscales\_0d@{meke\_lengthscales\_0d}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{meke\_lengthscales\_0d()}{meke\_lengthscales\_0d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+lengthscales\+\_\+0d (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in)}]{area,  }\item[{real, intent(in)}]{beta,  }\item[{real, intent(in)}]{depth,  }\item[{real, intent(in)}]{Rd\+\_\+dx,  }\item[{real, intent(in)}]{SN,  }\item[{real, intent(in)}]{E\+KE,  }\item[{real, intent(out)}]{bottom\+Fac2,  }\item[{real, intent(out)}]{barotr\+Fac2,  }\item[{real, intent(out)}]{Lmix\+Scale,  }\item[{real, intent(out)}]{Lrhines,  }\item[{real, intent(out)}]{Leady }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \mbox{\hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}}. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+E\+KE control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em area} & Grid cell area \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em beta} & Planetary beta = $ \nabla f$ \mbox{[}T-\/1 L-\/1 $\sim$$>$ s-\/1 m-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em depth} & Ocean depth \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rd\+\_\+dx} & Resolution Ld/dx \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em sn} & Eady growth rate \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eke} & Eddy kinetic energy \mbox{[}L2 T-\/2 $\sim$$>$ m2 s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em bottomfac2} & gamma\+\_\+b$^\wedge$2 \\
\hline
\mbox{\texttt{ out}}  & {\em barotrfac2} & gamma\+\_\+t$^\wedge$2 \\
\hline
\mbox{\texttt{ out}}  & {\em lmixscale} & Eddy mixing length \mbox{[}L $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em lrhines} & Rhines length scale \mbox{[}L $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em leady} & Eady length scale \mbox{[}L $\sim$$>$ m\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 910 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{912   \textcolor{keywordtype}{type}(MEKE\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< MEKE control structure.}}
\DoxyCodeLine{913   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{914 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: area\textcolor{comment}{       !< Grid cell area [L2 \string~> m2]}}
\DoxyCodeLine{915 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: beta\textcolor{comment}{       !< Planetary beta = \(\backslash\)f\$ \(\backslash\)nabla f\(\backslash\)f\$  [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{916 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{      !< Ocean depth [Z \string~> m]}}
\DoxyCodeLine{917 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: Rd\_dx\textcolor{comment}{      !< Resolution Ld/dx [nondim].}}
\DoxyCodeLine{918 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: SN\textcolor{comment}{         !< Eady growth rate [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{919 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: EKE\textcolor{comment}{        !< Eddy kinetic energy [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{920 \textcolor{comment}{!  real,          intent(in)    :: Z\_to\_L     !< A conversion factor from depth units (Z) to}}
\DoxyCodeLine{921 \textcolor{comment}{!                                             !! the units for lateral distances (L).}}
\DoxyCodeLine{922 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(out)}   :: bottomFac2\textcolor{comment}{ !< gamma\_b\string^2}}
\DoxyCodeLine{923 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(out)}   :: barotrFac2\textcolor{comment}{ !< gamma\_t\string^2}}
\DoxyCodeLine{924 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(out)}   :: LmixScale\textcolor{comment}{  !< Eddy mixing length [L \string~> m].}}
\DoxyCodeLine{925 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(out)}   :: Lrhines\textcolor{comment}{    !< Rhines length scale [L \string~> m].}}
\DoxyCodeLine{926 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(out)}   :: Leady\textcolor{comment}{      !< Eady length scale [L \string~> m].}}
\DoxyCodeLine{927   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{928 \textcolor{keywordtype}{  real} :: Lgrid, Ldeform, Lfrict \textcolor{comment}{! Length scales [L \string~> m]}}
\DoxyCodeLine{929 \textcolor{keywordtype}{  real} :: Ue  \textcolor{comment}{! An eddy velocity [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{930 }
\DoxyCodeLine{931   \textcolor{comment}{! Length scale for MEKE derived diffusivity}}
\DoxyCodeLine{932   lgrid = sqrt(area)               \textcolor{comment}{! Grid scale}}
\DoxyCodeLine{933   ldeform = lgrid * rd\_dx          \textcolor{comment}{! Deformation scale}}
\DoxyCodeLine{934   lfrict = (us\%Z\_to\_L * depth) / cs\%cdrag  \textcolor{comment}{! Frictional arrest scale}}
\DoxyCodeLine{935   \textcolor{comment}{! gamma\_b\string^2 is the ratio of bottom eddy energy to mean column eddy energy}}
\DoxyCodeLine{936   \textcolor{comment}{! used in calculating bottom drag}}
\DoxyCodeLine{937   bottomfac2 = cs\%MEKE\_CD\_SCALE**2}
\DoxyCodeLine{938   \textcolor{keywordflow}{if} (lfrict*cs\%MEKE\_Cb>0.) bottomfac2 = bottomfac2 + 1./( 1. + cs\%MEKE\_Cb*(ldeform/lfrict) )**0.8}
\DoxyCodeLine{939   bottomfac2 = max(bottomfac2, cs\%MEKE\_min\_gamma)}
\DoxyCodeLine{940   \textcolor{comment}{! gamma\_t\string^2 is the ratio of barotropic eddy energy to mean column eddy energy}}
\DoxyCodeLine{941   \textcolor{comment}{! used in the velocity scale for diffusivity}}
\DoxyCodeLine{942   barotrfac2 = 1.}
\DoxyCodeLine{943   \textcolor{keywordflow}{if} (lfrict*cs\%MEKE\_Ct>0.) barotrfac2 = 1. / ( 1. + cs\%MEKE\_Ct*(ldeform/lfrict) )**0.25}
\DoxyCodeLine{944   barotrfac2 = max(barotrfac2, cs\%MEKE\_min\_gamma)}
\DoxyCodeLine{945   \textcolor{keywordflow}{if} (cs\%use\_old\_lscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{946     \textcolor{keywordflow}{if} (cs\%Rd\_as\_max\_scale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{947       lmixscale = min(ldeform, lgrid) \textcolor{comment}{! The smaller of Ld or dx}}
\DoxyCodeLine{948     \textcolor{keywordflow}{else}}
\DoxyCodeLine{949       lmixscale = lgrid}
\DoxyCodeLine{950 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{951   \textcolor{keywordflow}{else}}
\DoxyCodeLine{952     ue = sqrt( 2.0 * max( 0., barotrfac2*eke ) ) \textcolor{comment}{! Barotropic eddy flow scale}}
\DoxyCodeLine{953     lrhines = sqrt( ue / max( beta, 1.e-\/30*us\%T\_to\_s*us\%L\_to\_m ) )       \textcolor{comment}{! Rhines scale}}
\DoxyCodeLine{954     \textcolor{keywordflow}{if} (cs\%aEady > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{955       leady = ue / max( sn, 1.e-\/15*us\%T\_to\_s ) \textcolor{comment}{! Bound Eady time-\/scale < 1e15 seconds}}
\DoxyCodeLine{956     \textcolor{keywordflow}{else}}
\DoxyCodeLine{957       leady = 0.}
\DoxyCodeLine{958 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{959     \textcolor{keywordflow}{if} (cs\%use\_min\_lscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{960       lmixscale = 1.e7}
\DoxyCodeLine{961       \textcolor{keywordflow}{if} (cs\%aDeform*ldeform > 0.) lmixscale = min(lmixscale,cs\%aDeform*ldeform)}
\DoxyCodeLine{962       \textcolor{keywordflow}{if} (cs\%aFrict *lfrict  > 0.) lmixscale = min(lmixscale,cs\%aFrict *lfrict)}
\DoxyCodeLine{963       \textcolor{keywordflow}{if} (cs\%aRhines*lrhines > 0.) lmixscale = min(lmixscale,cs\%aRhines*lrhines)}
\DoxyCodeLine{964       \textcolor{keywordflow}{if} (cs\%aEady  *leady   > 0.) lmixscale = min(lmixscale,cs\%aEady  *leady)}
\DoxyCodeLine{965       \textcolor{keywordflow}{if} (cs\%aGrid  *lgrid   > 0.) lmixscale = min(lmixscale,cs\%aGrid  *lgrid)}
\DoxyCodeLine{966       \textcolor{keywordflow}{if} (cs\%Lfixed          > 0.) lmixscale = min(lmixscale,cs\%Lfixed)}
\DoxyCodeLine{967     \textcolor{keywordflow}{else}}
\DoxyCodeLine{968       lmixscale = 0.}
\DoxyCodeLine{969       \textcolor{keywordflow}{if} (cs\%aDeform*ldeform > 0.) lmixscale = lmixscale + 1./(cs\%aDeform*ldeform)}
\DoxyCodeLine{970       \textcolor{keywordflow}{if} (cs\%aFrict *lfrict  > 0.) lmixscale = lmixscale + 1./(cs\%aFrict *lfrict)}
\DoxyCodeLine{971       \textcolor{keywordflow}{if} (cs\%aRhines*lrhines > 0.) lmixscale = lmixscale + 1./(cs\%aRhines*lrhines)}
\DoxyCodeLine{972       \textcolor{keywordflow}{if} (cs\%aEady  *leady   > 0.) lmixscale = lmixscale + 1./(cs\%aEady  *leady)}
\DoxyCodeLine{973       \textcolor{keywordflow}{if} (cs\%aGrid  *lgrid   > 0.) lmixscale = lmixscale + 1./(cs\%aGrid  *lgrid)}
\DoxyCodeLine{974       \textcolor{keywordflow}{if} (cs\%Lfixed          > 0.) lmixscale = lmixscale + 1./cs\%Lfixed}
\DoxyCodeLine{975       \textcolor{keywordflow}{if} (lmixscale > 0.) lmixscale = 1. / lmixscale}
\DoxyCodeLine{976 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{977 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{978 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}\label{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}} 
\index{mom\_meke@{mom\_meke}!step\_forward\_meke@{step\_forward\_meke}}
\index{step\_forward\_meke@{step\_forward\_meke}!mom\_meke@{mom\_meke}}
\doxysubsubsection{\texorpdfstring{step\_forward\_meke()}{step\_forward\_meke()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+meke\+::step\+\_\+forward\+\_\+meke (\begin{DoxyParamCaption}\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\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)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v,  }\item[{type(vertvisc\+\_\+type), intent(in)}]{visc,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{hu,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{hv }\end{DoxyParamCaption})}



Integrates forward-\/in-\/time the M\+E\+KE eddy energy equation. See \mbox{\hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}}. 


\begin{DoxyParams}[1]{Parameters}
 & {\em meke} & M\+E\+KE data. \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid. \\
\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 sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em visc} & The vertical viscosity type. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Model(baroclinic) time-\/step \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
 & {\em cs} & M\+E\+KE control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em hu} & Accumlated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em hv} & Accumlated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 111 of file M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{112   \textcolor{keywordtype}{type}(MEKE\_type),                          \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{ !< MEKE data.}}
\DoxyCodeLine{113   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}}
\DoxyCodeLine{114   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid structure.}}
\DoxyCodeLine{115   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{116 \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{117 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},        \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{118 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},        \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{119   \textcolor{keywordtype}{type}(vertvisc\_type),                      \textcolor{keywordtype}{intent(in)}    :: visc\textcolor{comment}{ !< The vertical viscosity type.}}
\DoxyCodeLine{120 \textcolor{keywordtype}{  real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Model(baroclinic) time-\/step [T \string~> s].}}
\DoxyCodeLine{121   \textcolor{keywordtype}{type}(MEKE\_CS),                            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}}
\DoxyCodeLine{122 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}   :: hu\textcolor{comment}{   !< Accumlated zonal mass flux [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{123 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}   :: hv\textcolor{comment}{   !< Accumlated meridional mass flux [H L2 \string~> m3 or kg]}}
\DoxyCodeLine{124 }
\DoxyCodeLine{125   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{126 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{127     mass, \&         \textcolor{comment}{! The total mass of the water column [R Z \string~> kg m-\/2].}}
\DoxyCodeLine{128     I\_mass, \&       \textcolor{comment}{! The inverse of mass [R-\/1 Z-\/1 \string~> m2 kg-\/1].}}
\DoxyCodeLine{129     src, \&          \textcolor{comment}{! The sum of all MEKE sources [L2 T-\/3 \string~> W kg-\/1] (= m2 s-\/3).}}
\DoxyCodeLine{130     MEKE\_decay, \&   \textcolor{comment}{! A diagnostic of the MEKE decay timescale [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{131     drag\_rate\_visc, \& \textcolor{comment}{! Near-\/bottom velocity contribution to bottom dratg [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{132     drag\_rate, \&    \textcolor{comment}{! The MEKE spindown timescale due to bottom drag [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{133     drag\_rate\_J15, \&  \textcolor{comment}{! The MEKE spindown timescale due to bottom drag with the Jansen 2015 scheme.}}
\DoxyCodeLine{134                     \textcolor{comment}{! Unfortunately, as written the units seem inconsistent. [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{135     del2meke, \&     \textcolor{comment}{! Laplacian of MEKE, used for bi-\/harmonic diffusion [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{136     del4meke, \&     \textcolor{comment}{! Time-\/integrated MEKE tendency arising from the biharmonic of MEKE [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{137     lmixscale, \&    \textcolor{comment}{! Eddy mixing length [L \string~> m].}}
\DoxyCodeLine{138     barotrfac2, \&   \textcolor{comment}{! Ratio of EKE\_barotropic / EKE [nondim]}}
\DoxyCodeLine{139     bottomfac2, \&   \textcolor{comment}{! Ratio of EKE\_bottom / EKE [nondim]}}
\DoxyCodeLine{140     tmp             \textcolor{comment}{! Temporary variable for diagnostic computation}}
\DoxyCodeLine{141 }
\DoxyCodeLine{142 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{143     MEKE\_uflux, \&   \textcolor{comment}{! The zonal advective and diffusive flux of MEKE with units of [R Z L4 T-\/3 \string~> kg m-\/2 s-\/3].}}
\DoxyCodeLine{144                     \textcolor{comment}{! In one place, MEKE\_uflux is used as temporary work space with units of [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{145     kh\_u, \&         \textcolor{comment}{! The zonal diffusivity that is actually used [L2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{146     barohu, \&       \textcolor{comment}{! Depth integrated accumulated zonal mass flux [R Z L2 \string~> kg].}}
\DoxyCodeLine{147     drag\_vel\_u      \textcolor{comment}{! A (vertical) viscosity associated with bottom drag at}}
\DoxyCodeLine{148                     \textcolor{comment}{! u-\/points [Z T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{149 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{150     MEKE\_vflux, \&   \textcolor{comment}{! The meridional advective and diffusive flux of MEKE with units of [R Z L4 T-\/3 \string~> kg m-\/2 s-\/3].}}
\DoxyCodeLine{151                     \textcolor{comment}{! In one place, MEKE\_vflux is used as temporary work space with units of [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{152     kh\_v, \&         \textcolor{comment}{! The meridional diffusivity that is actually used [L2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{153     barohv, \&       \textcolor{comment}{! Depth integrated accumulated meridional mass flux [R Z L2 \string~> kg].}}
\DoxyCodeLine{154     drag\_vel\_v      \textcolor{comment}{! A (vertical) viscosity associated with bottom drag at}}
\DoxyCodeLine{155                     \textcolor{comment}{! v-\/points [Z T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{156 \textcolor{keywordtype}{  real} :: Kh\_here   \textcolor{comment}{! The local horizontal viscosity [L2 T-\/1 \string~> m2 s-\/1]}}
\DoxyCodeLine{157 \textcolor{keywordtype}{  real} :: Inv\_Kh\_max \textcolor{comment}{! The inverse of the local horizontal viscosity [T L-\/2 \string~> s m-\/2]}}
\DoxyCodeLine{158 \textcolor{keywordtype}{  real} :: K4\_here   \textcolor{comment}{! The local horizontal biharmonic viscosity [L4 T-\/1 \string~> m4 s-\/1]}}
\DoxyCodeLine{159 \textcolor{keywordtype}{  real} :: Inv\_K4\_max \textcolor{comment}{! The inverse of the local horizontal biharmonic viscosity [T L-\/4 \string~> s m-\/4]}}
\DoxyCodeLine{160 \textcolor{keywordtype}{  real} :: cdrag2}
\DoxyCodeLine{161 \textcolor{keywordtype}{  real} :: advFac    \textcolor{comment}{! The product of the advection scaling factor and 1/dt [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{162 \textcolor{keywordtype}{  real} :: mass\_neglect \textcolor{comment}{! A negligible mass [R Z \string~> kg m-\/2].}}
\DoxyCodeLine{163 \textcolor{keywordtype}{  real} :: ldamping  \textcolor{comment}{! The MEKE damping rate [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{164 \textcolor{keywordtype}{  real} :: Rho0      \textcolor{comment}{! A density used to convert mass to distance [R \string~> kg m-\/3].}}
\DoxyCodeLine{165 \textcolor{keywordtype}{  real} :: sdt       \textcolor{comment}{! dt to use locally [T \string~> s] (could be scaled to accelerate)}}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real} :: sdt\_damp  \textcolor{comment}{! dt for damping [T \string~> s] (sdt could be split).}}
\DoxyCodeLine{167   \textcolor{keywordtype}{logical} :: use\_drag\_rate \textcolor{comment}{! Flag to indicate drag\_rate is finite}}
\DoxyCodeLine{168   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz}
\DoxyCodeLine{169 }
\DoxyCodeLine{170   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{171   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{172 }
\DoxyCodeLine{173   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{174          \textcolor{stringliteral}{"MOM\_MEKE: Module must be initialized before it is used."})}
\DoxyCodeLine{175   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{176          \textcolor{stringliteral}{"MOM\_MEKE: MEKE must be initialized before it is used."})}
\DoxyCodeLine{177 }
\DoxyCodeLine{178   \textcolor{keywordflow}{if} ((cs\%MEKE\_damping > 0.0) .or. (cs\%MEKE\_Cd\_scale > 0.0) .or. (cs\%MEKE\_Cb>0.) \&}
\DoxyCodeLine{179       .or. cs\%visc\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{180     use\_drag\_rate = .true.}
\DoxyCodeLine{181   \textcolor{keywordflow}{else}}
\DoxyCodeLine{182     use\_drag\_rate = .false.}
\DoxyCodeLine{183 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{184 }
\DoxyCodeLine{185   \textcolor{comment}{! Only integrate the MEKE equations if MEKE is required.}}
\DoxyCodeLine{186   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke\%MEKE)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{187 \textcolor{comment}{!   call MOM\_error(FATAL, "MOM\_MEKE: MEKE\%MEKE is not associated!")}}
\DoxyCodeLine{188     \textcolor{keywordflow}{return}}
\DoxyCodeLine{189 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{190 }
\DoxyCodeLine{191     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{192       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%mom\_src)) \&}
\DoxyCodeLine{193         \textcolor{keyword}{call }hchksum(meke\%mom\_src, \textcolor{stringliteral}{'MEKE mom\_src'}, g\%HI, scale=us\%RZ3\_T3\_to\_W\_m2*us\%L\_to\_Z**2)}
\DoxyCodeLine{194       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%GME\_snk)) \&}
\DoxyCodeLine{195         \textcolor{keyword}{call }hchksum(meke\%GME\_snk, \textcolor{stringliteral}{'MEKE GME\_snk'}, g\%HI, scale=us\%RZ3\_T3\_to\_W\_m2*us\%L\_to\_Z**2)}
\DoxyCodeLine{196       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%GM\_src)) \&}
\DoxyCodeLine{197         \textcolor{keyword}{call }hchksum(meke\%GM\_src, \textcolor{stringliteral}{'MEKE GM\_src'}, g\%HI, scale=us\%RZ3\_T3\_to\_W\_m2*us\%L\_to\_Z**2)}
\DoxyCodeLine{198       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%MEKE)) \textcolor{keyword}{call }hchksum(meke\%MEKE, \textcolor{stringliteral}{'MEKE MEKE'}, g\%HI, scale=us\%L\_T\_to\_m\_s**2)}
\DoxyCodeLine{199       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE SN\_[uv]"}, sn\_u, sn\_v, g\%HI, scale=us\%s\_to\_T, \&}
\DoxyCodeLine{200                     scalar\_pair=.true.)}
\DoxyCodeLine{201       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE h[uv]"}, hu, hv, g\%HI, haloshift=1, \&}
\DoxyCodeLine{202                     scale=gv\%H\_to\_m*(us\%L\_to\_m**2))}
\DoxyCodeLine{203 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{204 }
\DoxyCodeLine{205     sdt = dt*cs\%MEKE\_dtScale \textcolor{comment}{! Scaled dt to use for time-\/stepping}}
\DoxyCodeLine{206     rho0 = gv\%Rho0}
\DoxyCodeLine{207     mass\_neglect = gv\%H\_to\_RZ * gv\%H\_subroundoff}
\DoxyCodeLine{208     cdrag2 = cs\%cdrag**2}
\DoxyCodeLine{209 }
\DoxyCodeLine{210     \textcolor{comment}{! With a depth-\/dependent (and possibly strong) damping, it seems}}
\DoxyCodeLine{211     \textcolor{comment}{! advisable to use Strang splitting between the damping and diffusion.}}
\DoxyCodeLine{212     sdt\_damp = sdt ; \textcolor{keywordflow}{if} (cs\%MEKE\_KH >= 0.0 .or. cs\%MEKE\_K4 >= 0.) sdt\_damp = 0.5*sdt}
\DoxyCodeLine{213 }
\DoxyCodeLine{214     \textcolor{comment}{! Calculate depth integrated mass exchange if doing advection [R Z L2 \string~> kg]}}
\DoxyCodeLine{215     \textcolor{keywordflow}{if} (cs\%MEKE\_advection\_factor>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{216       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{217         barohu(i,j) = 0.}
\DoxyCodeLine{218 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{219       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{220         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{221           barohu(i,j) = hu(i,j,k) * gv\%H\_to\_RZ}
\DoxyCodeLine{222 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{223 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{224       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{225         barohv(i,j) = 0.}
\DoxyCodeLine{226 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{227       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{228         \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{229           barohv(i,j) = hv(i,j,k) * gv\%H\_to\_RZ}
\DoxyCodeLine{230 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{231 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{232 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{233 }
\DoxyCodeLine{234     \textcolor{keywordflow}{if} (cs\%MEKE\_Cd\_scale == 0.0 .and. .not. cs\%visc\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{235       \textcolor{comment}{!\$OMP parallel do default(shared) private(ldamping)}}
\DoxyCodeLine{236       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{237         drag\_rate(i,j) = 0. ; drag\_rate\_j15(i,j) = 0.}
\DoxyCodeLine{238 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{239 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{240 }
\DoxyCodeLine{241     \textcolor{comment}{! Calculate drag\_rate\_visc(i,j) which accounts for the model bottom mean flow}}
\DoxyCodeLine{242     \textcolor{keywordflow}{if} (cs\%visc\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{243       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{244       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{245         drag\_vel\_u(i,j) = 0.0}
\DoxyCodeLine{246         \textcolor{keywordflow}{if} ((g\%mask2dCu(i,j) > 0.0) .and. (visc\%bbl\_thick\_u(i,j) > 0.0)) \&}
\DoxyCodeLine{247           drag\_vel\_u(i,j) = visc\%Kv\_bbl\_u(i,j) / visc\%bbl\_thick\_u(i,j)}
\DoxyCodeLine{248 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{249       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{250       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{251         drag\_vel\_v(i,j) = 0.0}
\DoxyCodeLine{252         \textcolor{keywordflow}{if} ((g\%mask2dCv(i,j) > 0.0) .and. (visc\%bbl\_thick\_v(i,j) > 0.0)) \&}
\DoxyCodeLine{253           drag\_vel\_v(i,j) = visc\%Kv\_bbl\_v(i,j) / visc\%bbl\_thick\_v(i,j)}
\DoxyCodeLine{254 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{255 }
\DoxyCodeLine{256       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{257       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{258         drag\_rate\_visc(i,j) = (0.25*g\%IareaT(i,j) * us\%Z\_to\_L * \&}
\DoxyCodeLine{259                 ((g\%areaCu(i-\/1,j)*drag\_vel\_u(i-\/1,j) + \&}
\DoxyCodeLine{260                   g\%areaCu(i,j)*drag\_vel\_u(i,j)) + \&}
\DoxyCodeLine{261                  (g\%areaCv(i,j-\/1)*drag\_vel\_v(i,j-\/1) + \&}
\DoxyCodeLine{262                   g\%areaCv(i,j)*drag\_vel\_v(i,j)) ) )}
\DoxyCodeLine{263 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{264     \textcolor{keywordflow}{else}}
\DoxyCodeLine{265       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{266       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{267         drag\_rate\_visc(i,j) = 0.}
\DoxyCodeLine{268 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{269 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{270 }
\DoxyCodeLine{271     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{272     \textcolor{keywordflow}{do} j=js-\/1,je+1}
\DoxyCodeLine{273       \textcolor{keywordflow}{do} i=is-\/1,ie+1 ; mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{274       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{275         mass(i,j) = mass(i,j) + g\%mask2dT(i,j) * (gv\%H\_to\_RZ * h(i,j,k)) \textcolor{comment}{! [R Z \string~> kg m-\/2]}}
\DoxyCodeLine{276 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{277       \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{278         i\_mass(i,j) = 0.0}
\DoxyCodeLine{279         \textcolor{keywordflow}{if} (mass(i,j) > 0.0) i\_mass(i,j) = 1.0 / mass(i,j) \textcolor{comment}{! [R-\/1 Z-\/1 \string~> m2 kg-\/1]}}
\DoxyCodeLine{280 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{281 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{282 }
\DoxyCodeLine{283     \textcolor{keywordflow}{if} (cs\%initialize) \textcolor{keywordflow}{then}}
\DoxyCodeLine{284       \textcolor{keyword}{call }meke\_equilibrium(cs, meke, g, gv, us, sn\_u, sn\_v, drag\_rate\_visc, i\_mass)}
\DoxyCodeLine{285       cs\%initialize = .false.}
\DoxyCodeLine{286 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{287 }
\DoxyCodeLine{288     \textcolor{comment}{! Calculates bottomFac2, barotrFac2 and LmixScale}}
\DoxyCodeLine{289     \textcolor{keyword}{call }meke\_lengthscales(cs, meke, g, gv, us, sn\_u, sn\_v, meke\%MEKE, bottomfac2, barotrfac2, lmixscale)}
\DoxyCodeLine{290     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{291       \textcolor{keywordflow}{if} (cs\%visc\_drag) \&}
\DoxyCodeLine{292         \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE drag\_vel\_[uv]"}, drag\_vel\_u, drag\_vel\_v, g\%HI, \&}
\DoxyCodeLine{293                       scale=us\%Z\_to\_m*us\%s\_to\_T, scalar\_pair=.true.)}
\DoxyCodeLine{294       \textcolor{keyword}{call }hchksum(mass, \textcolor{stringliteral}{'MEKE mass'},g\%HI,haloshift=1, scale=us\%RZ\_to\_kg\_m2)}
\DoxyCodeLine{295       \textcolor{keyword}{call }hchksum(drag\_rate\_visc, \textcolor{stringliteral}{'MEKE drag\_rate\_visc'}, g\%HI, scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{296       \textcolor{keyword}{call }hchksum(bottomfac2, \textcolor{stringliteral}{'MEKE bottomFac2'}, g\%HI)}
\DoxyCodeLine{297       \textcolor{keyword}{call }hchksum(barotrfac2, \textcolor{stringliteral}{'MEKE barotrFac2'}, g\%HI)}
\DoxyCodeLine{298       \textcolor{keyword}{call }hchksum(lmixscale, \textcolor{stringliteral}{'MEKE LmixScale'}, g\%HI,scale=us\%L\_to\_m)}
\DoxyCodeLine{299 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{300 }
\DoxyCodeLine{301     \textcolor{comment}{! Aggregate sources of MEKE (background, frictional and GM)}}
\DoxyCodeLine{302     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{303     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{304       src(i,j) = cs\%MEKE\_BGsrc}
\DoxyCodeLine{305 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{306 }
\DoxyCodeLine{307     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%mom\_src)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{308       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{309       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{310         src(i,j) = src(i,j) -\/ cs\%MEKE\_FrCoeff*i\_mass(i,j)*meke\%mom\_src(i,j)}
\DoxyCodeLine{311 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{312 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{313 }
\DoxyCodeLine{314     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%GME\_snk)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{315       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{316       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{317         src(i,j) = src(i,j) -\/ cs\%MEKE\_GMECoeff*i\_mass(i,j)*meke\%GME\_snk(i,j)}
\DoxyCodeLine{318 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{319 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{320 }
\DoxyCodeLine{321     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%GM\_src)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{322       \textcolor{keywordflow}{if} (cs\%GM\_src\_alt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{323         \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{324         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{325           src(i,j) = src(i,j) -\/ cs\%MEKE\_GMcoeff*meke\%GM\_src(i,j) / \&}
\DoxyCodeLine{326                      (gv\%Rho0 * max(1.0*us\%m\_to\_Z, g\%bathyT(i,j)))}
\DoxyCodeLine{327 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{328       \textcolor{keywordflow}{else}}
\DoxyCodeLine{329         \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{330         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{331           src(i,j) = src(i,j) -\/ cs\%MEKE\_GMcoeff*i\_mass(i,j)*meke\%GM\_src(i,j)}
\DoxyCodeLine{332 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{333 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{334 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{335 }
\DoxyCodeLine{336     \textcolor{keywordflow}{if} (cs\%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}}
\DoxyCodeLine{337       \textcolor{keyword}{call }meke\_equilibrium\_restoring(cs, g, us, sn\_u, sn\_v)}
\DoxyCodeLine{338       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{339         src(i,j) = src(i,j) -\/ cs\%MEKE\_restoring\_rate*(meke\%MEKE(i,j) -\/ cs\%equilibrium\_value(i,j))}
\DoxyCodeLine{340 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{341 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{342 }
\DoxyCodeLine{343     \textcolor{comment}{! Increase EKE by a full time-\/steps worth of source}}
\DoxyCodeLine{344     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{345     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{346       meke\%MEKE(i,j) = (meke\%MEKE(i,j) + sdt*src(i,j))*g\%mask2dT(i,j)}
\DoxyCodeLine{347 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{348 }
\DoxyCodeLine{349     \textcolor{keywordflow}{if} (use\_drag\_rate) \textcolor{keywordflow}{then}}
\DoxyCodeLine{350       \textcolor{comment}{! Calculate a viscous drag rate (includes BBL contributions from mean flow and eddies)}}
\DoxyCodeLine{351       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{352       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{353         drag\_rate(i,j) = (us\%L\_to\_Z*rho0 * i\_mass(i,j)) * sqrt( drag\_rate\_visc(i,j)**2 + \&}
\DoxyCodeLine{354                  cdrag2 * ( max(0.0, 2.0*bottomfac2(i,j)*meke\%MEKE(i,j)) + cs\%MEKE\_Uscale**2 ) )}
\DoxyCodeLine{355 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{356 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{357 }
\DoxyCodeLine{358     \textcolor{comment}{! First stage of Strang splitting}}
\DoxyCodeLine{359     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{360     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{361       ldamping = cs\%MEKE\_damping + drag\_rate(i,j) * bottomfac2(i,j)}
\DoxyCodeLine{362       \textcolor{keywordflow}{if} (meke\%MEKE(i,j) < 0.) ldamping = 0.}
\DoxyCodeLine{363       \textcolor{comment}{! notice that the above line ensures a damping only if MEKE is positive,}}
\DoxyCodeLine{364       \textcolor{comment}{! while leaving MEKE unchanged if it is negative}}
\DoxyCodeLine{365       meke\%MEKE(i,j) =  meke\%MEKE(i,j) / (1.0 + sdt\_damp*ldamping)}
\DoxyCodeLine{366       meke\_decay(i,j) = ldamping*g\%mask2dT(i,j)}
\DoxyCodeLine{367 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{368 }
\DoxyCodeLine{369     \textcolor{keywordflow}{if} (cs\%kh\_flux\_enabled .or. cs\%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{370       \textcolor{comment}{! Update MEKE in the halos for lateral or bi-\/harmonic diffusion}}
\DoxyCodeLine{371       \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_pass)}
\DoxyCodeLine{372       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_MEKE, g\%Domain)}
\DoxyCodeLine{373       \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_pass)}
\DoxyCodeLine{374 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{375 }
\DoxyCodeLine{376     \textcolor{keywordflow}{if} (cs\%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{377       \textcolor{comment}{! Calculate Laplacian of MEKE using MEKE\_uflux and MEKE\_vflux as temporary work space.}}
\DoxyCodeLine{378       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{379       \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/2,ie+1}
\DoxyCodeLine{380         \textcolor{comment}{! MEKE\_uflux is used here as workspace with units of [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{381         meke\_uflux(i,j) = ((g\%dy\_Cu(i,j)*g\%IdxCu(i,j)) * g\%mask2dCu(i,j)) * \&}
\DoxyCodeLine{382             (meke\%MEKE(i+1,j) -\/ meke\%MEKE(i,j))}
\DoxyCodeLine{383       \textcolor{comment}{! This would have units of [R Z L2 T-\/2 \string~> kg s-\/2]}}
\DoxyCodeLine{384       \textcolor{comment}{! MEKE\_uflux(I,j) = ((G\%dy\_Cu(I,j)*G\%IdxCu(I,j)) * \&}}
\DoxyCodeLine{385       \textcolor{comment}{!     ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * \&}}
\DoxyCodeLine{386       \textcolor{comment}{!     (MEKE\%MEKE(i+1,j) -\/ MEKE\%MEKE(i,j))}}
\DoxyCodeLine{387 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{388       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{389       \textcolor{keywordflow}{do} j=js-\/2,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{390         \textcolor{comment}{! MEKE\_vflux is used here as workspace with units of [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{391         meke\_vflux(i,j) = ((g\%dx\_Cv(i,j)*g\%IdyCv(i,j)) * g\%mask2dCv(i,j)) * \&}
\DoxyCodeLine{392             (meke\%MEKE(i,j+1) -\/ meke\%MEKE(i,j))}
\DoxyCodeLine{393       \textcolor{comment}{! This would have units of [R Z L2 T-\/2 \string~> kg s-\/2]}}
\DoxyCodeLine{394       \textcolor{comment}{! MEKE\_vflux(i,J) = ((G\%dx\_Cv(i,J)*G\%IdyCv(i,J)) * \&}}
\DoxyCodeLine{395       \textcolor{comment}{!     ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * \&}}
\DoxyCodeLine{396       \textcolor{comment}{!     (MEKE\%MEKE(i,j+1) -\/ MEKE\%MEKE(i,j))}}
\DoxyCodeLine{397 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{398 }
\DoxyCodeLine{399       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{400       \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1 \textcolor{comment}{! del2MEKE has units [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{401         del2meke(i,j) = g\%IareaT(i,j) * \&}
\DoxyCodeLine{402             ((meke\_uflux(i,j) -\/ meke\_uflux(i-\/1,j)) + (meke\_vflux(i,j) -\/ meke\_vflux(i,j-\/1)))}
\DoxyCodeLine{403 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{404 }
\DoxyCodeLine{405       \textcolor{comment}{! Bi-\/harmonic diffusion of MEKE}}
\DoxyCodeLine{406       \textcolor{comment}{!\$OMP parallel do default(shared) private(K4\_here,Inv\_K4\_max)}}
\DoxyCodeLine{407       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{408         k4\_here = cs\%MEKE\_K4 \textcolor{comment}{! [L4 T-\/1 \string~> m4 s-\/1]}}
\DoxyCodeLine{409         \textcolor{comment}{! Limit Kh to avoid CFL violations.}}
\DoxyCodeLine{410         inv\_k4\_max = 64.0 * sdt * ((g\%dy\_Cu(i,j)*g\%IdxCu(i,j)) * \&}
\DoxyCodeLine{411                      max(g\%IareaT(i,j), g\%IareaT(i+1,j)))**2}
\DoxyCodeLine{412         \textcolor{keywordflow}{if} (k4\_here*inv\_k4\_max > 0.3) k4\_here = 0.3 / inv\_k4\_max}
\DoxyCodeLine{413 }
\DoxyCodeLine{414         \textcolor{comment}{! Here the units of MEKE\_uflux are [R Z L4 T-\/3 \string~> kg m2 s-\/3].}}
\DoxyCodeLine{415         meke\_uflux(i,j) = ((k4\_here * (g\%dy\_Cu(i,j)*g\%IdxCu(i,j))) * \&}
\DoxyCodeLine{416             ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * \&}
\DoxyCodeLine{417             (del2meke(i+1,j) -\/ del2meke(i,j))}
\DoxyCodeLine{418 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{419       \textcolor{comment}{!\$OMP parallel do default(shared) private(K4\_here,Inv\_K4\_max)}}
\DoxyCodeLine{420       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{421         k4\_here = cs\%MEKE\_K4 \textcolor{comment}{! [L4 T-\/1 \string~> m4 s-\/1]}}
\DoxyCodeLine{422         inv\_k4\_max = 64.0 * sdt * ((g\%dx\_Cv(i,j)*g\%IdyCv(i,j)) * max(g\%IareaT(i,j), g\%IareaT(i,j+1)))**2}
\DoxyCodeLine{423         \textcolor{keywordflow}{if} (k4\_here*inv\_k4\_max > 0.3) k4\_here = 0.3 / inv\_k4\_max}
\DoxyCodeLine{424 }
\DoxyCodeLine{425         \textcolor{comment}{! Here the units of MEKE\_vflux are [R Z L4 T-\/3 \string~> kg m2 s-\/3].}}
\DoxyCodeLine{426         meke\_vflux(i,j) = ((k4\_here * (g\%dx\_Cv(i,j)*g\%IdyCv(i,j))) * \&}
\DoxyCodeLine{427             ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * \&}
\DoxyCodeLine{428             (del2meke(i,j+1) -\/ del2meke(i,j))}
\DoxyCodeLine{429 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{430       \textcolor{comment}{! Store change in MEKE arising from the bi-\/harmonic in del4MEKE [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{431       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{432       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{433         del4meke(i,j) = (sdt*(g\%IareaT(i,j)*i\_mass(i,j))) * \&}
\DoxyCodeLine{434             ((meke\_uflux(i-\/1,j) -\/ meke\_uflux(i,j)) + \&}
\DoxyCodeLine{435              (meke\_vflux(i,j-\/1) -\/ meke\_vflux(i,j)))}
\DoxyCodeLine{436 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{437 \textcolor{keywordflow}{    endif} \textcolor{comment}{!}}
\DoxyCodeLine{438 }
\DoxyCodeLine{439     \textcolor{keywordflow}{if} (cs\%kh\_flux\_enabled) \textcolor{keywordflow}{then}}
\DoxyCodeLine{440       \textcolor{comment}{! Lateral diffusion of MEKE}}
\DoxyCodeLine{441       kh\_here = max(0., cs\%MEKE\_Kh)}
\DoxyCodeLine{442       \textcolor{comment}{!\$OMP parallel do default(shared) firstprivate(Kh\_here) private(Inv\_Kh\_max)}}
\DoxyCodeLine{443       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{444         \textcolor{comment}{! Limit Kh to avoid CFL violations.}}
\DoxyCodeLine{445         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh)) \&}
\DoxyCodeLine{446           kh\_here = max(0., cs\%MEKE\_Kh) + \&}
\DoxyCodeLine{447               cs\%KhMEKE\_Fac*0.5*(meke\%Kh(i,j)+meke\%Kh(i+1,j))}
\DoxyCodeLine{448         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh\_diff)) \&}
\DoxyCodeLine{449           kh\_here = max(0.,cs\%MEKE\_Kh) + \&}
\DoxyCodeLine{450               cs\%KhMEKE\_Fac*0.5*(meke\%Kh\_diff(i,j)+meke\%Kh\_diff(i+1,j))}
\DoxyCodeLine{451         inv\_kh\_max = 2.0*sdt * ((g\%dy\_Cu(i,j)*g\%IdxCu(i,j)) * \&}
\DoxyCodeLine{452                      max(g\%IareaT(i,j),g\%IareaT(i+1,j)))}
\DoxyCodeLine{453         \textcolor{keywordflow}{if} (kh\_here*inv\_kh\_max > 0.25) kh\_here = 0.25 / inv\_kh\_max}
\DoxyCodeLine{454         kh\_u(i,j) = kh\_here}
\DoxyCodeLine{455 }
\DoxyCodeLine{456         \textcolor{comment}{! Here the units of MEKE\_uflux and MEKE\_vflux are [R Z L4 T-\/3 \string~> kg m2 s-\/3].}}
\DoxyCodeLine{457         meke\_uflux(i,j) = ((kh\_here * (g\%dy\_Cu(i,j)*g\%IdxCu(i,j))) * \&}
\DoxyCodeLine{458             ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * \&}
\DoxyCodeLine{459             (meke\%MEKE(i,j) -\/ meke\%MEKE(i+1,j))}
\DoxyCodeLine{460 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{461       \textcolor{comment}{!\$OMP parallel do default(shared) firstprivate(Kh\_here) private(Inv\_Kh\_max)}}
\DoxyCodeLine{462       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{463         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh)) \&}
\DoxyCodeLine{464           kh\_here = max(0.,cs\%MEKE\_Kh) + cs\%KhMEKE\_Fac * 0.5*(meke\%Kh(i,j)+meke\%Kh(i,j+1))}
\DoxyCodeLine{465         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh\_diff)) \&}
\DoxyCodeLine{466           kh\_here = max(0.,cs\%MEKE\_Kh) + cs\%KhMEKE\_Fac * 0.5*(meke\%Kh\_diff(i,j)+meke\%Kh\_diff(i,j+1))}
\DoxyCodeLine{467         inv\_kh\_max = 2.0*sdt * ((g\%dx\_Cv(i,j)*g\%IdyCv(i,j)) * max(g\%IareaT(i,j),g\%IareaT(i,j+1)))}
\DoxyCodeLine{468         \textcolor{keywordflow}{if} (kh\_here*inv\_kh\_max > 0.25) kh\_here = 0.25 / inv\_kh\_max}
\DoxyCodeLine{469         kh\_v(i,j) = kh\_here}
\DoxyCodeLine{470 }
\DoxyCodeLine{471         \textcolor{comment}{! Here the units of MEKE\_uflux and MEKE\_vflux are [R Z L4 T-\/3 \string~> kg m2 s-\/3].}}
\DoxyCodeLine{472         meke\_vflux(i,j) = ((kh\_here * (g\%dx\_Cv(i,j)*g\%IdyCv(i,j))) * \&}
\DoxyCodeLine{473             ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * \&}
\DoxyCodeLine{474             (meke\%MEKE(i,j) -\/ meke\%MEKE(i,j+1))}
\DoxyCodeLine{475 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{476       \textcolor{keywordflow}{if} (cs\%MEKE\_advection\_factor>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{477         advfac = cs\%MEKE\_advection\_factor / sdt \textcolor{comment}{! [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{478         \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{479         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{480           \textcolor{comment}{! Here the units of the quantities added to MEKE\_uflux are [R Z L4 T-\/3 \string~> kg m2 s-\/3].}}
\DoxyCodeLine{481           \textcolor{keywordflow}{if} (barohu(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{482             meke\_uflux(i,j) = meke\_uflux(i,j) + barohu(i,j)*meke\%MEKE(i,j)*advfac}
\DoxyCodeLine{483           \textcolor{keywordflow}{elseif} (barohu(i,j)<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{484             meke\_uflux(i,j) = meke\_uflux(i,j) + barohu(i,j)*meke\%MEKE(i+1,j)*advfac}
\DoxyCodeLine{485 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{486 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{487         \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{488         \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{489           \textcolor{comment}{! Here the units of the quantities added to MEKE\_vflux are [R Z L4 T-\/3 \string~> kg m2 s-\/3].}}
\DoxyCodeLine{490           \textcolor{keywordflow}{if} (barohv(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{491             meke\_vflux(i,j) = meke\_vflux(i,j) + barohv(i,j)*meke\%MEKE(i,j)*advfac}
\DoxyCodeLine{492           \textcolor{keywordflow}{elseif} (barohv(i,j)<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{493             meke\_vflux(i,j) = meke\_vflux(i,j) + barohv(i,j)*meke\%MEKE(i,j+1)*advfac}
\DoxyCodeLine{494 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{495 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{496 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{497 }
\DoxyCodeLine{498       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{499       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{500         meke\%MEKE(i,j) = meke\%MEKE(i,j) + (sdt*(g\%IareaT(i,j)*i\_mass(i,j))) * \&}
\DoxyCodeLine{501             ((meke\_uflux(i-\/1,j) -\/ meke\_uflux(i,j)) + \&}
\DoxyCodeLine{502              (meke\_vflux(i,j-\/1) -\/ meke\_vflux(i,j)))}
\DoxyCodeLine{503 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{504 \textcolor{keywordflow}{    endif} \textcolor{comment}{! MEKE\_KH>0}}
\DoxyCodeLine{505 }
\DoxyCodeLine{506     \textcolor{comment}{! Add on bi-\/harmonic tendency}}
\DoxyCodeLine{507     \textcolor{keywordflow}{if} (cs\%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{508       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{509       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{510         meke\%MEKE(i,j) = meke\%MEKE(i,j) + del4meke(i,j)}
\DoxyCodeLine{511 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{512 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{513 }
\DoxyCodeLine{514     \textcolor{comment}{! Second stage of Strang splitting}}
\DoxyCodeLine{515     \textcolor{keywordflow}{if} (cs\%MEKE\_KH >= 0.0 .or. cs\%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{516       \textcolor{keywordflow}{if} (sdt>sdt\_damp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{517         \textcolor{comment}{! Recalculate the drag rate, since MEKE has changed.}}
\DoxyCodeLine{518         \textcolor{keywordflow}{if} (use\_drag\_rate) \textcolor{keywordflow}{then}}
\DoxyCodeLine{519           \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{520           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{521             drag\_rate(i,j) = (us\%L\_to\_Z*rho0 * i\_mass(i,j)) * sqrt( drag\_rate\_visc(i,j)**2 + \&}
\DoxyCodeLine{522                    cdrag2 * ( max(0.0, 2.0*bottomfac2(i,j)*meke\%MEKE(i,j)) + cs\%MEKE\_Uscale**2 ) )}
\DoxyCodeLine{523 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{524           \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{525           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{526             ldamping = cs\%MEKE\_damping + drag\_rate(i,j) * bottomfac2(i,j)}
\DoxyCodeLine{527             \textcolor{keywordflow}{if} (meke\%MEKE(i,j) < 0.) ldamping = 0.}
\DoxyCodeLine{528             \textcolor{comment}{! notice that the above line ensures a damping only if MEKE is positive,}}
\DoxyCodeLine{529             \textcolor{comment}{! while leaving MEKE unchanged if it is negative}}
\DoxyCodeLine{530             meke\%MEKE(i,j) =  meke\%MEKE(i,j) / (1.0 + sdt\_damp*ldamping)}
\DoxyCodeLine{531             meke\_decay(i,j) = ldamping*g\%mask2dT(i,j)}
\DoxyCodeLine{532 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{533 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{534 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{535 \textcolor{keywordflow}{    endif} \textcolor{comment}{! MEKE\_KH>=0}}
\DoxyCodeLine{536 }
\DoxyCodeLine{537  \textcolor{comment}{!   do j=js,je ; do i=is,ie}}
\DoxyCodeLine{538  \textcolor{comment}{!     MEKE\%MEKE(i,j) =  MAX(MEKE\%MEKE(i,j),0.0)}}
\DoxyCodeLine{539  \textcolor{comment}{!   enddo ; enddo}}
\DoxyCodeLine{540 }
\DoxyCodeLine{541     \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_pass)}
\DoxyCodeLine{542     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_MEKE, g\%Domain)}
\DoxyCodeLine{543     \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_pass)}
\DoxyCodeLine{544 }
\DoxyCodeLine{545     \textcolor{comment}{! Calculate diffusivity for main model to use}}
\DoxyCodeLine{546     \textcolor{keywordflow}{if} (cs\%MEKE\_KhCoeff>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{547       \textcolor{keywordflow}{if} (.not.cs\%MEKE\_GEOMETRIC) \textcolor{keywordflow}{then}}
\DoxyCodeLine{548         \textcolor{keywordflow}{if} (cs\%use\_old\_lscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{549           \textcolor{keywordflow}{if} (cs\%Rd\_as\_max\_scale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{550             \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{551             \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{552               meke\%Kh(i,j) = (cs\%MEKE\_KhCoeff * \&}
\DoxyCodeLine{553                          sqrt(2.*max(0.,barotrfac2(i,j)*meke\%MEKE(i,j))*g\%areaT(i,j)) ) * \&}
\DoxyCodeLine{554                          min(meke\%Rd\_dx\_h(i,j), 1.0)}
\DoxyCodeLine{555 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{556           \textcolor{keywordflow}{else}}
\DoxyCodeLine{557             \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{558             \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{559               meke\%Kh(i,j) = cs\%MEKE\_KhCoeff * \&}
\DoxyCodeLine{560                   sqrt(2.*max(0., barotrfac2(i,j)*meke\%MEKE(i,j))*g\%areaT(i,j))}
\DoxyCodeLine{561 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{562 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{563         \textcolor{keywordflow}{else}}
\DoxyCodeLine{564           \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{565           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{566             meke\%Kh(i,j) = cs\%MEKE\_KhCoeff * \&}
\DoxyCodeLine{567                 sqrt(2.*max(0., barotrfac2(i,j)*meke\%MEKE(i,j))) * lmixscale(i,j)}
\DoxyCodeLine{568 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{569 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{570 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{571 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{572 }
\DoxyCodeLine{573     \textcolor{comment}{! Calculate viscosity for the main model to use}}
\DoxyCodeLine{574     \textcolor{keywordflow}{if} (cs\%viscosity\_coeff\_Ku /=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{575       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{576         meke\%Ku(i,j) = cs\%viscosity\_coeff\_Ku * sqrt(2.*max(0.,meke\%MEKE(i,j))) * lmixscale(i,j)}
\DoxyCodeLine{577 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{578 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{579 }
\DoxyCodeLine{580     \textcolor{keywordflow}{if} (cs\%viscosity\_coeff\_Au /=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{581       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{582         meke\%Au(i,j) = cs\%viscosity\_coeff\_Au * sqrt(2.*max(0.,meke\%MEKE(i,j))) * lmixscale(i,j)**3}
\DoxyCodeLine{583 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{584 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{585 }
\DoxyCodeLine{586     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke\%Kh) .or. \textcolor{keyword}{associated}(meke\%Ku) .or. \textcolor{keyword}{associated}(meke\%Au)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{587       \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_pass)}
\DoxyCodeLine{588       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_Kh, g\%Domain)}
\DoxyCodeLine{589       \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_pass)}
\DoxyCodeLine{590 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{591 }
\DoxyCodeLine{592     \textcolor{comment}{! Offer fields for averaging.}}
\DoxyCodeLine{593     \textcolor{keywordflow}{if} (any([cs\%id\_Ue, cs\%id\_Ub, cs\%id\_Ut] > 0)) \&}
\DoxyCodeLine{594       tmp(:,:) = 0.}
\DoxyCodeLine{595     \textcolor{keywordflow}{if} (cs\%id\_MEKE>0) \textcolor{keyword}{call }post\_data(cs\%id\_MEKE, meke\%MEKE, cs\%diag)}
\DoxyCodeLine{596     \textcolor{keywordflow}{if} (cs\%id\_Ue>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{597       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{598         tmp(i,j) = sqrt(max(0., 2. * meke\%MEKE(i,j)))}
\DoxyCodeLine{599 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{600       \textcolor{keyword}{call }post\_data(cs\%id\_Ue, tmp, cs\%diag)}
\DoxyCodeLine{601 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{602     \textcolor{keywordflow}{if} (cs\%id\_Ub>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{603       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{604         tmp(i,j) = sqrt(max(0., 2. * meke\%MEKE(i,j) * bottomfac2(i,j)))}
\DoxyCodeLine{605 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{606       \textcolor{keyword}{call }post\_data(cs\%id\_Ub, tmp, cs\%diag)}
\DoxyCodeLine{607 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{608     \textcolor{keywordflow}{if} (cs\%id\_Ut>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{609       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{610         tmp(i,j) = sqrt(max(0., 2. * meke\%MEKE(i,j) * barotrfac2(i,j)))}
\DoxyCodeLine{611 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{612       \textcolor{keyword}{call }post\_data(cs\%id\_Ut, tmp, cs\%diag)}
\DoxyCodeLine{613 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{614     \textcolor{keywordflow}{if} (cs\%id\_Kh>0) \textcolor{keyword}{call }post\_data(cs\%id\_Kh, meke\%Kh, cs\%diag)}
\DoxyCodeLine{615     \textcolor{keywordflow}{if} (cs\%id\_Ku>0) \textcolor{keyword}{call }post\_data(cs\%id\_Ku, meke\%Ku, cs\%diag)}
\DoxyCodeLine{616     \textcolor{keywordflow}{if} (cs\%id\_Au>0) \textcolor{keyword}{call }post\_data(cs\%id\_Au, meke\%Au, cs\%diag)}
\DoxyCodeLine{617     \textcolor{keywordflow}{if} (cs\%id\_KhMEKE\_u>0) \textcolor{keyword}{call }post\_data(cs\%id\_KhMEKE\_u, kh\_u, cs\%diag)}
\DoxyCodeLine{618     \textcolor{keywordflow}{if} (cs\%id\_KhMEKE\_v>0) \textcolor{keyword}{call }post\_data(cs\%id\_KhMEKE\_v, kh\_v, cs\%diag)}
\DoxyCodeLine{619     \textcolor{keywordflow}{if} (cs\%id\_src>0) \textcolor{keyword}{call }post\_data(cs\%id\_src, src, cs\%diag)}
\DoxyCodeLine{620     \textcolor{keywordflow}{if} (cs\%id\_decay>0) \textcolor{keyword}{call }post\_data(cs\%id\_decay, meke\_decay, cs\%diag)}
\DoxyCodeLine{621     \textcolor{keywordflow}{if} (cs\%id\_GM\_src>0) \textcolor{keyword}{call }post\_data(cs\%id\_GM\_src, meke\%GM\_src, cs\%diag)}
\DoxyCodeLine{622     \textcolor{keywordflow}{if} (cs\%id\_mom\_src>0) \textcolor{keyword}{call }post\_data(cs\%id\_mom\_src, meke\%mom\_src, cs\%diag)}
\DoxyCodeLine{623     \textcolor{keywordflow}{if} (cs\%id\_GME\_snk>0) \textcolor{keyword}{call }post\_data(cs\%id\_GME\_snk, meke\%GME\_snk, cs\%diag)}
\DoxyCodeLine{624     \textcolor{keywordflow}{if} (cs\%id\_Le>0) \textcolor{keyword}{call }post\_data(cs\%id\_Le, lmixscale, cs\%diag)}
\DoxyCodeLine{625     \textcolor{keywordflow}{if} (cs\%id\_gamma\_b>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{626       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{627         bottomfac2(i,j) = sqrt(bottomfac2(i,j))}
\DoxyCodeLine{628 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{629       \textcolor{keyword}{call }post\_data(cs\%id\_gamma\_b, bottomfac2, cs\%diag)}
\DoxyCodeLine{630 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{631     \textcolor{keywordflow}{if} (cs\%id\_gamma\_t>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{632       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{633         barotrfac2(i,j) = sqrt(barotrfac2(i,j))}
\DoxyCodeLine{634 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{635       \textcolor{keyword}{call }post\_data(cs\%id\_gamma\_t, barotrfac2, cs\%diag)}
\DoxyCodeLine{636 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{637 }

\end{DoxyCode}
