\hypertarget{namespacemom__mixed__layer__restrat}{}\doxysection{mom\+\_\+mixed\+\_\+layer\+\_\+restrat Module Reference}
\label{namespacemom__mixed__layer__restrat}\index{mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}}


\doxysubsection{Detailed Description}
Parameterization of mixed layer restratification by unresolved mixed-\/layer eddies. 

\hypertarget{namespacemom__mixed__layer__restrat_section_mle}{}\doxysubsection{Mixed-\/layer eddy parameterization module}\label{namespacemom__mixed__layer__restrat_section_mle}
The subroutines in this file implement a parameterization of unresolved viscous mixed layer restratification of the mixed layer as described in Fox-\/\+Kemper et al., 2008, and whose impacts are described in Fox-\/\+Kemper et al., 2011. This is derived in part from the older parameterization that is described in Hallberg (Aha Hulikoa, 2003), which this new parameterization surpasses, which in turn is based on the sub-\/inertial mixed layer theory of Young (J\+PO, 1994). There is no net horizontal volume transport due to this parameterization, and no direct effect below the mixed layer.

This parameterization sets the restratification timescale to agree with high-\/resolution studies of mixed layer restratification.

The run-\/time parameter F\+O\+X\+\_\+\+K\+E\+M\+P\+E\+R\+\_\+\+M\+L\+\_\+\+R\+E\+S\+T\+R\+A\+T\+\_\+\+C\+O\+EF is a non-\/dimensional number of order a few tens, proportional to the ratio of the deformation radius or the grid scale (whichever is smaller to the dominant horizontal length-\/scale of the sub-\/meso-\/scale mixed layer instabilities.\hypertarget{namespacemom__mixed__layer__restrat_section_mle_nutshell}{}\doxysubsubsection{\char`\"{}\+Sub-\/meso\char`\"{} in a nutshell}\label{namespacemom__mixed__layer__restrat_section_mle_nutshell}
The parameterization is colloquially referred to as \char`\"{}sub-\/meso\char`\"{}.

The original Fox-\/\+Kemper et al., (2008b) paper proposed a quasi-\/\+Stokes advection described by the stream function (eq. 5 of Fox-\/\+Kemper et al., 2011)\+: \[ {\bf \Psi}_o = C_e \frac{ H^2 \nabla \bar{b} \times \hat{\bf z} }{ |f| } \mu(z) \]

where the vertical profile function is \[ \mu(z) = \max \left\{ 0, \left[ 1 - \left(\frac{2z}{H}+1\right)^2 \right] \left[ 1 + \frac{5}{21} \left(\frac{2z}{H}+1\right)^2 \right] \right\} \] and $ H $ is the mixed-\/layer depth, $ f $ is the local Coriolis parameter, $ C_e \sim 0.06-0.08 $ and $ \nabla \bar{b} $ is a depth mean buoyancy gradient averaged over the mixed layer.

For use in coarse-\/resolution models, an upscaling of the buoyancy gradients and adaption for the equator leads to the following parameterization (eq. 6 of Fox-\/\+Kemper et al., 2011)\+: \[ {\bf \Psi} = C_e \Gamma_\Delta \frac{\Delta s}{l_f} \frac{ H^2 \nabla \bar{b} \times \hat{\bf z} } { \sqrt{ f^2 + \tau^{-2}} } \mu(z) \] where $ \Delta s $ is the minimum of grid-\/scale and deformation radius, $ l_f $ is the width of the mixed-\/layer fronts, and $ \Gamma_\Delta=1 $. $ \tau $ is a time-\/scale for mixing momentum across the mixed layer. $ l_f $ is thought to be of order hundreds of meters.

The upscaling factor $ \frac{\Delta s}{l_f} $ can be a global constant, model parameter F\+O\+X\+\_\+\+K\+E\+M\+P\+E\+R\+\_\+\+M\+L\+\_\+\+R\+E\+S\+T\+R\+AT, so that in practice the parameterization is\+: \[ {\bf \Psi} = C_e \Gamma_\Delta \frac{ H^2 \nabla \bar{b} \times \hat{\bf z} }{ \sqrt{ f^2 + \tau^{-2}} } \mu(z) \] with non-\/unity $ \Gamma_\Delta $.

$ C_e $ is hard-\/coded as 0.\+0625. $ \tau $ is calculated from the surface friction velocity $ u^* $. \begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000003}{Todo}}]Explain expression for momentum mixing time-\/scale.\end{DoxyRefDesc}
\hypertarget{namespacemom__mixed__layer__restrat_section_mle_filtering}{}\doxysubsubsection{Time-\/filtering of mixed-\/layer depth}\label{namespacemom__mixed__layer__restrat_section_mle_filtering}
Using the instantaneous mixed-\/layer depth is inconsistent with the finite life-\/time of mixed-\/layer instabilities. We provide a one-\/sided running-\/mean filter of mixed-\/layer depth, $ H $, of the form\+: \[ \bar{H} \leftarrow \max \left( H, \frac{ \Delta t H + \tau_h \bar{H} }{ \Delta t + \tau_h } \right) \] which allows the effective mixed-\/layer depth seen by the parameterization, $\bar{H}$, to instantaneously deepen but to decay with time-\/scale $ \tau_h $. $ \bar{H} $ is substituted for $ H $ in the above equations.\hypertarget{namespacemom__mixed__layer__restrat_section_mle_mld}{}\doxysubsubsection{Defining the mixed-\/layer-\/depth}\label{namespacemom__mixed__layer__restrat_section_mle_mld}
If the parameter M\+L\+E\+\_\+\+U\+S\+E\+\_\+\+P\+B\+L\+\_\+\+M\+LD=True then the mixed-\/layer depth is defined/diagnosed by the boundary-\/layer parameterization (e.\+g. e\+P\+BL, K\+PP, etc.).

If the parameter M\+L\+E\+\_\+\+U\+S\+E\+\_\+\+P\+B\+L\+\_\+\+M\+LD=False then the mixed-\/layer depth is diagnosed in this module as the depth of a given density difference, $ \Delta \rho $, with the surface where the density difference is the parameter M\+L\+E\+\_\+\+D\+E\+N\+S\+I\+T\+Y\+\_\+\+D\+I\+FF.\hypertarget{namespacemom__mixed__layer__restrat_section_mle_ref}{}\doxysubsubsection{References}\label{namespacemom__mixed__layer__restrat_section_mle_ref}
Fox-\/\+Kemper, B., Ferrari, R. and Hallberg, R., 2008\+: Parameterization of Mixed Layer Eddies. Part I\+: Theory and Diagnosis J. Phys. Oceangraphy, 38 (6), p1145-\/1165. \href{https://doi.org/10.1175/2007JPO3792.1}{\texttt{ https\+://doi.\+org/10.\+1175/2007\+J\+P\+O3792.\+1}}

Fox-\/\+Kemper, B. and Ferrari, R. 2008\+: Parameterization of Mixed Layer Eddies. Part II\+: Prognosis and Impact J. Phys. Oceangraphy, 38 (6), p1166-\/1179. \href{https://doi.org/10.1175/2007JPO3788.1}{\texttt{ https\+://doi.\+org/10.\+1175/2007\+J\+P\+O3788.\+1}}

B. Fox-\/\+Kemper, G. Danabasoglu, R. Ferrari, S.\+M. Griffies, R.\+W. Hallberg, M.\+M. Holland, M.\+E. Maltrud, S. Peacock, and B.\+L. Samuels, 2011\+: Parameterization of mixed layer eddies. I\+II\+: Implementation and impact in global ocean climate simulations. Ocean Modell., 39(1), p61-\/78. \href{https://doi.org/10.1016/j.ocemod.2010.09.002}{\texttt{ https\+://doi.\+org/10.\+1016/j.\+ocemod.\+2010.\+09.\+002}}

\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
$ \Gamma_\Delta $  &F\+O\+X\+\_\+\+K\+E\+M\+P\+E\+R\+\_\+\+M\+L\+\_\+\+R\+E\+S\+T\+R\+AT   \\\cline{1-2}
$ l_f $  &M\+L\+E\+\_\+\+F\+R\+O\+N\+T\+\_\+\+L\+E\+N\+G\+TH   \\\cline{1-2}
$ \tau_h $  &M\+L\+E\+\_\+\+M\+L\+D\+\_\+\+D\+E\+C\+A\+Y\+\_\+\+T\+I\+ME   \\\cline{1-2}
$ \Delta \rho $  &M\+L\+E\+\_\+\+D\+E\+N\+S\+I\+T\+Y\+\_\+\+D\+I\+FF   \\\cline{1-2}
\end{longtabu}
\doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for \mbox{\hyperlink{namespacemom__mixed__layer__restrat}{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a9dfb1879cd5a1ef890f3fc329f961ea0}{mixedlayer\+\_\+restrat}} (h, uhtr, vhtr, tv, forces, dt, M\+LD, Var\+Mix, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Driver for the mixed-\/layer restratification parameterization. The code branches between two different implementations depending on whether the bulk-\/mixed layer or a general coordinate are in use. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a9c6bee98536870b0b6c2bd317c00c684}{mixedlayer\+\_\+restrat\+\_\+general}} (h, uhtr, vhtr, tv, forces, dt, M\+L\+D\+\_\+in, Var\+Mix, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates a restratifying flow in the mixed layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__mixed__layer__restrat_ac01281bf39b6fa7e469919c30c26aedb}{mixedlayer\+\_\+restrat\+\_\+bml}} (h, uhtr, vhtr, tv, forces, dt, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates a restratifying flow assuming a 2-\/layer bulk mixed layer. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a89b89663722cc9047a3bb238a4bfa09a}{mixedlayer\+\_\+restrat\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Initialize the mixed layer restratification module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__mixed__layer__restrat_aea597553dfa98cc7c972784f476ad3fc}{mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts}} (HI, param\+\_\+file, CS, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Allocate and register fields in the mixed layer restratification structure for restarts. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a0524d9152be26e538ed4da505942ebd2}\label{namespacemom__mixed__layer__restrat_a0524d9152be26e538ed4da505942ebd2}} 
character(len=40) \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a0524d9152be26e538ed4da505942ebd2}{mdl}} = \char`\"{}M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a9dfb1879cd5a1ef890f3fc329f961ea0}\label{namespacemom__mixed__layer__restrat_a9dfb1879cd5a1ef890f3fc329f961ea0}} 
\index{mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}!mixedlayer\_restrat@{mixedlayer\_restrat}}
\index{mixedlayer\_restrat@{mixedlayer\_restrat}!mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}}
\doxysubsubsection{\texorpdfstring{mixedlayer\_restrat()}{mixedlayer\_restrat()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension(\+:,\+:), pointer}]{M\+LD,  }\item[{type(varmix\+\_\+cs), pointer}]{Var\+Mix,  }\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__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Driver for the mixed-\/layer restratification parameterization. The code branches between two different implementations depending on whether the bulk-\/mixed layer or a general coordinate are in use. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Accumulated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Accumulated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables structure \\
\hline
\mbox{\texttt{ in}}  & {\em forces} & A structure with the driving mechanical forces \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
 & {\em mld} & Mixed layer depth provided by the P\+BL scheme \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
 & {\em varmix} & Container for derived fields \\
\hline
 & {\em cs} & Module control structure \\
\hline
\end{DoxyParams}


Definition at line 91 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{91   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< Ocean grid structure}}
\DoxyCodeLine{92   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}}
\DoxyCodeLine{93   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{94 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{95 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Accumulated zonal mass flux}}
\DoxyCodeLine{96 \textcolor{comment}{                                                                     !! [H L2 ~> m3 or kg]}}
\DoxyCodeLine{97 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Accumulated meridional mass flux}}
\DoxyCodeLine{98 \textcolor{comment}{                                                                     !! [H L2 ~> m3 or kg]}}
\DoxyCodeLine{99   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{     !< Thermodynamic variables structure}}
\DoxyCodeLine{100   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{ !< A structure with the driving mechanical forces}}
\DoxyCodeLine{101 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time increment [T ~> s]}}
\DoxyCodeLine{102 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                      \textcolor{keywordtype}{pointer}       :: MLD\textcolor{comment}{    !< Mixed layer depth provided by the}}
\DoxyCodeLine{103 \textcolor{comment}{                                                                     !! PBL scheme [Z ~> m]}}
\DoxyCodeLine{104   \textcolor{keywordtype}{type}(VarMix\_CS),                           \textcolor{keywordtype}{pointer}       :: VarMix\textcolor{comment}{ !< Container for derived fields}}
\DoxyCodeLine{105   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Module control structure}}
\DoxyCodeLine{106 }
\DoxyCodeLine{107   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{108          \textcolor{stringliteral}{"Module must be initialized before it is used."})}
\DoxyCodeLine{109 }
\DoxyCodeLine{110   \textcolor{keywordflow}{if} (gv\%nkml>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{111     \textcolor{keyword}{call }mixedlayer\_restrat\_bml(h, uhtr, vhtr, tv, forces, dt, g, gv, us, cs)}
\DoxyCodeLine{112   \textcolor{keywordflow}{else}}
\DoxyCodeLine{113     \textcolor{keyword}{call }mixedlayer\_restrat\_general(h, uhtr, vhtr, tv, forces, dt, mld, varmix, g, gv, us, cs)}
\DoxyCodeLine{114 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{115 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_ac01281bf39b6fa7e469919c30c26aedb}\label{namespacemom__mixed__layer__restrat_ac01281bf39b6fa7e469919c30c26aedb}} 
\index{mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}!mixedlayer\_restrat\_bml@{mixedlayer\_restrat\_bml}}
\index{mixedlayer\_restrat\_bml@{mixedlayer\_restrat\_bml}!mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}}
\doxysubsubsection{\texorpdfstring{mixedlayer\_restrat\_bml()}{mixedlayer\_restrat\_bml()}}
{\footnotesize\ttfamily subroutine mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+bml (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates a restratifying flow assuming a 2-\/layer bulk mixed layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Accumulated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Accumulated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables structure \\
\hline
\mbox{\texttt{ in}}  & {\em forces} & A structure with the driving mechanical forces \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
 & {\em cs} & Module control structure \\
\hline
\end{DoxyParams}


Definition at line 563 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{563   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< Ocean grid structure}}
\DoxyCodeLine{564   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}}
\DoxyCodeLine{565   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{566 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{567 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Accumulated zonal mass flux}}
\DoxyCodeLine{568 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}}
\DoxyCodeLine{569 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Accumulated meridional mass flux}}
\DoxyCodeLine{570 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}}
\DoxyCodeLine{571   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{     !< Thermodynamic variables structure}}
\DoxyCodeLine{572   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{ !< A structure with the driving mechanical forces}}
\DoxyCodeLine{573 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time increment [T ~> s]}}
\DoxyCodeLine{574   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Module control structure}}
\DoxyCodeLine{575   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{576 \textcolor{keywordtype}{  real} :: uhml(SZIB\_(G),SZJ\_(G),SZK\_(G)) \textcolor{comment}{! zonal mixed layer transport [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1]}}
\DoxyCodeLine{577 \textcolor{keywordtype}{  real} :: vhml(SZI\_(G),SZJB\_(G),SZK\_(G)) \textcolor{comment}{! merid mixed layer transport [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1]}}
\DoxyCodeLine{578 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{579     h\_avail               \textcolor{comment}{! The volume available for diffusion out of each face of each}}
\DoxyCodeLine{580                           \textcolor{comment}{! sublayer of the mixed layer, divided by dt [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{581 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{582     htot, \&               \textcolor{comment}{! The sum of the thicknesses of layers in the mixed layer [H ~> m or kg m-\/2]}}
\DoxyCodeLine{583     Rml\_av                \textcolor{comment}{! g\_Rho0 times the average mixed layer density [L2 Z-\/1 T-\/2 ~> m s-\/2]}}
\DoxyCodeLine{584 \textcolor{keywordtype}{  real} :: g\_Rho0          \textcolor{comment}{! G\_Earth/Rho0 [L2 Z-\/1 T-\/2 R-\/1 ~> m4 s-\/2 kg-\/1]}}
\DoxyCodeLine{585 \textcolor{keywordtype}{  real} :: Rho0(SZI\_(G))   \textcolor{comment}{! Potential density relative to the surface [R ~> kg m-\/3]}}
\DoxyCodeLine{586 \textcolor{keywordtype}{  real} :: p0(SZI\_(G))     \textcolor{comment}{! A pressure of 0 [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{587 }
\DoxyCodeLine{588 \textcolor{keywordtype}{  real} :: h\_vel           \textcolor{comment}{! htot interpolated onto velocity points [Z ~> m]. (The units are not H.)}}
\DoxyCodeLine{589 \textcolor{keywordtype}{  real} :: absf            \textcolor{comment}{! absolute value of f, interpolated to velocity points [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{590 \textcolor{keywordtype}{  real} :: u\_star          \textcolor{comment}{! surface friction velocity, interpolated to velocity points [Z T-\/1 ~> m s-\/1].}}
\DoxyCodeLine{591 \textcolor{keywordtype}{  real} :: mom\_mixrate     \textcolor{comment}{! rate at which momentum is homogenized within mixed layer [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{592 \textcolor{keywordtype}{  real} :: timescale       \textcolor{comment}{! mixing growth timescale [T ~> s]}}
\DoxyCodeLine{593 \textcolor{keywordtype}{  real} :: h\_neglect       \textcolor{comment}{! tiny thickness usually lost in roundoff and can be neglected [H ~> m or kg m-\/2]}}
\DoxyCodeLine{594 \textcolor{keywordtype}{  real} :: dz\_neglect      \textcolor{comment}{! tiny thickness that usually lost in roundoff and can be neglected [Z ~> m]}}
\DoxyCodeLine{595 \textcolor{keywordtype}{  real} :: I4dt            \textcolor{comment}{! 1/(4 dt) [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{596 \textcolor{keywordtype}{  real} :: I2htot          \textcolor{comment}{! Twice the total mixed layer thickness at velocity points [H ~> m or kg m-\/2]}}
\DoxyCodeLine{597 \textcolor{keywordtype}{  real} :: z\_topx2         \textcolor{comment}{! depth of the top of a layer at velocity points [H ~> m or kg m-\/2]}}
\DoxyCodeLine{598 \textcolor{keywordtype}{  real} :: hx2             \textcolor{comment}{! layer thickness at velocity points [H ~> m or kg m-\/2]}}
\DoxyCodeLine{599 \textcolor{keywordtype}{  real} :: a(SZK\_(G))      \textcolor{comment}{! A non-\/dimensional value relating the overall flux}}
\DoxyCodeLine{600                           \textcolor{comment}{! magnitudes (uDml \& vDml) to the realized flux in a}}
\DoxyCodeLine{601                           \textcolor{comment}{! layer.  The vertical sum of a() through the pieces of}}
\DoxyCodeLine{602                           \textcolor{comment}{! the mixed layer must be 0.}}
\DoxyCodeLine{603 \textcolor{keywordtype}{  real} :: uDml(SZIB\_(G))  \textcolor{comment}{! The zonal and meridional volume fluxes in the upper}}
\DoxyCodeLine{604 \textcolor{keywordtype}{  real} :: vDml(SZI\_(G))   \textcolor{comment}{! half of the mixed layer [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{605 \textcolor{keywordtype}{  real} :: utimescale\_diag(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! The restratification timescales}}
\DoxyCodeLine{606 \textcolor{keywordtype}{  real} :: vtimescale\_diag(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! in the zonal and meridional}}
\DoxyCodeLine{607                                             \textcolor{comment}{! directions [T ~> s], stored in 2-\/D}}
\DoxyCodeLine{608                                             \textcolor{comment}{! arrays for diagnostic purposes.}}
\DoxyCodeLine{609 \textcolor{keywordtype}{  real} :: uDml\_diag(SZIB\_(G),SZJ\_(G)), vDml\_diag(SZI\_(G),SZJB\_(G))}
\DoxyCodeLine{610   \textcolor{keywordtype}{logical} :: use\_EOS    \textcolor{comment}{! If true, density is calculated from T \& S using an equation of state.}}
\DoxyCodeLine{611 }
\DoxyCodeLine{612   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{613   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, nkml}
\DoxyCodeLine{614   is  = g\%isc  ; ie  = g\%iec  ; js  = g\%jsc  ; je  = g\%jec ; nz = g\%ke}
\DoxyCodeLine{615   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB ; nkml = gv\%nkml}
\DoxyCodeLine{616 }
\DoxyCodeLine{617   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{618          \textcolor{stringliteral}{"Module must be initialized before it is used."})}
\DoxyCodeLine{619   \textcolor{keywordflow}{if} ((nkml<2) .or. (cs\%ml\_restrat\_coef<=0.0)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{620 }
\DoxyCodeLine{621   udml(:)    = 0.0 ; vdml(:) = 0.0}
\DoxyCodeLine{622   i4dt       = 0.25 / dt}
\DoxyCodeLine{623   g\_rho0     = gv\%g\_Earth / gv\%Rho0}
\DoxyCodeLine{624   use\_eos    = \textcolor{keyword}{associated}(tv\%eqn\_of\_state)}
\DoxyCodeLine{625   h\_neglect  = gv\%H\_subroundoff}
\DoxyCodeLine{626   dz\_neglect = gv\%H\_subroundoff*gv\%H\_to\_Z}
\DoxyCodeLine{627 }
\DoxyCodeLine{628   \textcolor{keywordflow}{if} (.not.use\_eos) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{629          \textcolor{stringliteral}{"An equation of state must be used with this module."})}
\DoxyCodeLine{630 }
\DoxyCodeLine{631   \textcolor{comment}{! Fix this later for nkml >= 3.}}
\DoxyCodeLine{632 }
\DoxyCodeLine{633   p0(:) = 0.0}
\DoxyCodeLine{634   eosdom(:) = eos\_domain(g\%HI, halo=1)}
\DoxyCodeLine{635 \textcolor{comment}{!\$OMP parallel default(none) shared(is,ie,js,je,G,GV,US,htot,Rml\_av,tv,p0,h,h\_avail,EOSdom, \&}}
\DoxyCodeLine{636 \textcolor{comment}{!\$OMP                               h\_neglect,g\_Rho0,I4dt,CS,uhml,uhtr,dt,vhml,vhtr,   \&}}
\DoxyCodeLine{637 \textcolor{comment}{!\$OMP                               utimescale\_diag,vtimescale\_diag,forces,dz\_neglect, \&}}
\DoxyCodeLine{638 \textcolor{comment}{!\$OMP                               uDml\_diag,vDml\_diag,nkml)                          \&}}
\DoxyCodeLine{639 \textcolor{comment}{!\$OMP                       private(Rho0,h\_vel,u\_star,absf,mom\_mixrate,timescale,      \&}}
\DoxyCodeLine{640 \textcolor{comment}{!\$OMP                               I2htot,z\_topx2,hx2,a)                              \&}}
\DoxyCodeLine{641 \textcolor{comment}{!\$OMP                       firstprivate(uDml,vDml)}}
\DoxyCodeLine{642 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{643   \textcolor{keywordflow}{do} j=js-\/1,je+1}
\DoxyCodeLine{644     \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{645       htot(i,j) = 0.0 ; rml\_av(i,j) = 0.0}
\DoxyCodeLine{646 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{647     \textcolor{keywordflow}{do} k=1,nkml}
\DoxyCodeLine{648       \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,k), tv\%S(:,j,k), p0, rho0(:), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{649       \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{650         rml\_av(i,j) = rml\_av(i,j) + h(i,j,k)*rho0(i)}
\DoxyCodeLine{651         htot(i,j) = htot(i,j) + h(i,j,k)}
\DoxyCodeLine{652         h\_avail(i,j,k) = max(i4dt*g\%areaT(i,j)*(h(i,j,k)-\/gv\%Angstrom\_H),0.0)}
\DoxyCodeLine{653 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{654 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{655 }
\DoxyCodeLine{656     \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{657       rml\_av(i,j) = (g\_rho0*rml\_av(i,j)) / (htot(i,j) + h\_neglect)}
\DoxyCodeLine{658 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{659 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{660 }
\DoxyCodeLine{661 \textcolor{comment}{! TO DO:}}
\DoxyCodeLine{662 \textcolor{comment}{!   1. Mixing extends below the mixing layer to the mixed layer.  Find it!}}
\DoxyCodeLine{663 \textcolor{comment}{!   2. Add exponential tail to stream-\/function?}}
\DoxyCodeLine{664 }
\DoxyCodeLine{665 \textcolor{comment}{!   U -\/ Component}}
\DoxyCodeLine{666 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{667   \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{668     h\_vel = 0.5*(htot(i,j) + htot(i+1,j)) * gv\%H\_to\_Z}
\DoxyCodeLine{669 }
\DoxyCodeLine{670     u\_star = 0.5*(forces\%ustar(i,j) + forces\%ustar(i+1,j))}
\DoxyCodeLine{671     absf = 0.5*(abs(g\%CoriolisBu(i,j-\/1)) + abs(g\%CoriolisBu(i,j)))}
\DoxyCodeLine{672     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}}
\DoxyCodeLine{673     \textcolor{comment}{! momentum mixing rate: pi\string^2*visc/h\_ml\string^2}}
\DoxyCodeLine{674     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi\string^2.}}
\DoxyCodeLine{675     mom\_mixrate = (0.41*9.8696)*u\_star**2 / \&}
\DoxyCodeLine{676                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)}
\DoxyCodeLine{677     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)}
\DoxyCodeLine{678 }
\DoxyCodeLine{679     timescale = timescale * cs\%ml\_restrat\_coef}
\DoxyCodeLine{680 \textcolor{comment}{!      timescale = timescale*(2?)*(L\_def/L\_MLI) * min(EKE/MKE,1.0 + (G\%dyCv(i,j)/L\_def)**2)}}
\DoxyCodeLine{681 }
\DoxyCodeLine{682     udml(i) = timescale * g\%mask2dCu(i,j)*g\%dyCu(i,j)*g\%IdxCu(i,j) * \&}
\DoxyCodeLine{683         (rml\_av(i+1,j)-\/rml\_av(i,j)) * (h\_vel**2 * gv\%Z\_to\_H)}
\DoxyCodeLine{684 }
\DoxyCodeLine{685     \textcolor{keywordflow}{if} (udml(i) == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{686       \textcolor{keywordflow}{do} k=1,nkml ; uhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{687     \textcolor{keywordflow}{else}}
\DoxyCodeLine{688       i2htot = 1.0 / (htot(i,j) + htot(i+1,j) + h\_neglect)}
\DoxyCodeLine{689       z\_topx2 = 0.0}
\DoxyCodeLine{690       \textcolor{comment}{! a(k) relates the sublayer transport to uDml with a linear profile.}}
\DoxyCodeLine{691       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}}
\DoxyCodeLine{692       \textcolor{keywordflow}{do} k=1,nkml}
\DoxyCodeLine{693         hx2 = (h(i,j,k) + h(i+1,j,k) + h\_neglect)}
\DoxyCodeLine{694         a(k) = (hx2 * i2htot) * (2.0 -\/ 4.0*(z\_topx2+0.5*hx2)*i2htot)}
\DoxyCodeLine{695         z\_topx2 = z\_topx2 + hx2}
\DoxyCodeLine{696         \textcolor{keywordflow}{if} (a(k)*udml(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{697           \textcolor{keywordflow}{if} (a(k)*udml(i) > h\_avail(i,j,k)) udml(i) = h\_avail(i,j,k) / a(k)}
\DoxyCodeLine{698         \textcolor{keywordflow}{else}}
\DoxyCodeLine{699           \textcolor{keywordflow}{if} (-\/a(k)*udml(i) > h\_avail(i+1,j,k)) udml(i) = -\/h\_avail(i+1,j,k)/a(k)}
\DoxyCodeLine{700 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{701 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{702       \textcolor{keywordflow}{do} k=1,nkml}
\DoxyCodeLine{703         uhml(i,j,k) = a(k)*udml(i)}
\DoxyCodeLine{704         uhtr(i,j,k) = uhtr(i,j,k) + uhml(i,j,k)*dt}
\DoxyCodeLine{705 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{706 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{707 }
\DoxyCodeLine{708     udml\_diag(i,j) = udml(i)}
\DoxyCodeLine{709     utimescale\_diag(i,j) = timescale}
\DoxyCodeLine{710   enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{711 }
\DoxyCodeLine{712 \textcolor{comment}{!  V-\/ component}}
\DoxyCodeLine{713 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{714   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{715     h\_vel = 0.5*(htot(i,j) + htot(i,j+1)) * gv\%H\_to\_Z}
\DoxyCodeLine{716 }
\DoxyCodeLine{717     u\_star = 0.5*(forces\%ustar(i,j) + forces\%ustar(i,j+1))}
\DoxyCodeLine{718     absf = 0.5*(abs(g\%CoriolisBu(i-\/1,j)) + abs(g\%CoriolisBu(i,j)))}
\DoxyCodeLine{719     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}}
\DoxyCodeLine{720     \textcolor{comment}{! momentum mixing rate: pi\string^2*visc/h\_ml\string^2}}
\DoxyCodeLine{721     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi\string^2.}}
\DoxyCodeLine{722     mom\_mixrate = (0.41*9.8696)*u\_star**2 / \&}
\DoxyCodeLine{723                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)}
\DoxyCodeLine{724     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)}
\DoxyCodeLine{725 }
\DoxyCodeLine{726     timescale = timescale * cs\%ml\_restrat\_coef}
\DoxyCodeLine{727 \textcolor{comment}{!     timescale = timescale*(2?)*(L\_def/L\_MLI) * min(EKE/MKE,1.0 + (G\%dyCv(i,j)/L\_def)**2)}}
\DoxyCodeLine{728 }
\DoxyCodeLine{729     vdml(i) = timescale * g\%mask2dCv(i,j)*g\%dxCv(i,j)*g\%IdyCv(i,j) * \&}
\DoxyCodeLine{730         (rml\_av(i,j+1)-\/rml\_av(i,j)) * (h\_vel**2 * gv\%Z\_to\_H)}
\DoxyCodeLine{731     \textcolor{keywordflow}{if} (vdml(i) == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{732       \textcolor{keywordflow}{do} k=1,nkml ; vhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{733     \textcolor{keywordflow}{else}}
\DoxyCodeLine{734       i2htot = 1.0 / (htot(i,j) + htot(i,j+1) + h\_neglect)}
\DoxyCodeLine{735       z\_topx2 = 0.0}
\DoxyCodeLine{736       \textcolor{comment}{! a(k) relates the sublayer transport to vDml with a linear profile.}}
\DoxyCodeLine{737       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}}
\DoxyCodeLine{738       \textcolor{keywordflow}{do} k=1,nkml}
\DoxyCodeLine{739         hx2 = (h(i,j,k) + h(i,j+1,k) + h\_neglect)}
\DoxyCodeLine{740         a(k) = (hx2 * i2htot) * (2.0 -\/ 4.0*(z\_topx2+0.5*hx2)*i2htot)}
\DoxyCodeLine{741         z\_topx2 = z\_topx2 + hx2}
\DoxyCodeLine{742         \textcolor{keywordflow}{if} (a(k)*vdml(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{743           \textcolor{keywordflow}{if} (a(k)*vdml(i) > h\_avail(i,j,k)) vdml(i) = h\_avail(i,j,k) / a(k)}
\DoxyCodeLine{744         \textcolor{keywordflow}{else}}
\DoxyCodeLine{745           \textcolor{keywordflow}{if} (-\/a(k)*vdml(i) > h\_avail(i,j+1,k)) vdml(i) = -\/h\_avail(i,j+1,k)/a(k)}
\DoxyCodeLine{746 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{747 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{748       \textcolor{keywordflow}{do} k=1,nkml}
\DoxyCodeLine{749         vhml(i,j,k) = a(k)*vdml(i)}
\DoxyCodeLine{750         vhtr(i,j,k) = vhtr(i,j,k) + vhml(i,j,k)*dt}
\DoxyCodeLine{751 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{752 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{753 }
\DoxyCodeLine{754     vtimescale\_diag(i,j) = timescale}
\DoxyCodeLine{755     vdml\_diag(i,j) = vdml(i)}
\DoxyCodeLine{756   enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{757 }
\DoxyCodeLine{758 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{759   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nkml ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{760     h(i,j,k) = h(i,j,k) -\/ dt*g\%IareaT(i,j) * \&}
\DoxyCodeLine{761         ((uhml(i,j,k) -\/ uhml(i-\/1,j,k)) + (vhml(i,j,k) -\/ vhml(i,j-\/1,k)))}
\DoxyCodeLine{762 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{763 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{764 }
\DoxyCodeLine{765   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}}
\DoxyCodeLine{766   \textcolor{comment}{! for vertical remapping may need to be regenerated.}}
\DoxyCodeLine{767   \textcolor{keywordflow}{if} (cs\%id\_uhml > 0 .or. cs\%id\_vhml > 0) \&}
\DoxyCodeLine{768     \textcolor{comment}{! Remapped uhml and vhml require east/north halo updates of h}}
\DoxyCodeLine{769     \textcolor{keyword}{call }pass\_var(h, g\%domain, to\_west+to\_south+omit\_corners, halo=1)}
\DoxyCodeLine{770   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{771 }
\DoxyCodeLine{772   \textcolor{comment}{! Offer diagnostic fields for averaging.}}
\DoxyCodeLine{773   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag) .and. \&}
\DoxyCodeLine{774     ((cs\%id\_urestrat\_time > 0)  .or. (cs\%id\_vrestrat\_time > 0))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{775     \textcolor{keyword}{call }post\_data(cs\%id\_urestrat\_time, utimescale\_diag, cs\%diag)}
\DoxyCodeLine{776     \textcolor{keyword}{call }post\_data(cs\%id\_vrestrat\_time, vtimescale\_diag, cs\%diag)}
\DoxyCodeLine{777 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{778   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag) .and. \&}
\DoxyCodeLine{779       ((cs\%id\_uhml>0) .or. (cs\%id\_vhml>0))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{780     \textcolor{keywordflow}{do} k=nkml+1,nz}
\DoxyCodeLine{781       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq ; uhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{782       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie ; vhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{783 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{784     \textcolor{keywordflow}{if} (cs\%id\_uhml > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uhml, uhml,      cs\%diag)}
\DoxyCodeLine{785     \textcolor{keywordflow}{if} (cs\%id\_vhml > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vhml, vhml,      cs\%diag)}
\DoxyCodeLine{786     \textcolor{keywordflow}{if} (cs\%id\_MLD  > 0) \textcolor{keyword}{call }post\_data(cs\%id\_MLD,  htot,      cs\%diag)}
\DoxyCodeLine{787     \textcolor{keywordflow}{if} (cs\%id\_Rml  > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Rml,  rml\_av,    cs\%diag)}
\DoxyCodeLine{788     \textcolor{keywordflow}{if} (cs\%id\_uDml > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uDml, udml\_diag, cs\%diag)}
\DoxyCodeLine{789     \textcolor{keywordflow}{if} (cs\%id\_vDml > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vDml, vdml\_diag, cs\%diag)}
\DoxyCodeLine{790 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{791 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a9c6bee98536870b0b6c2bd317c00c684}\label{namespacemom__mixed__layer__restrat_a9c6bee98536870b0b6c2bd317c00c684}} 
\index{mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}!mixedlayer\_restrat\_general@{mixedlayer\_restrat\_general}}
\index{mixedlayer\_restrat\_general@{mixedlayer\_restrat\_general}!mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}}
\doxysubsubsection{\texorpdfstring{mixedlayer\_restrat\_general()}{mixedlayer\_restrat\_general()}}
{\footnotesize\ttfamily subroutine mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+general (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension(\+:,\+:), pointer}]{M\+L\+D\+\_\+in,  }\item[{type(varmix\+\_\+cs), pointer}]{Var\+Mix,  }\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__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates a restratifying flow in the mixed layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Accumulated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Accumulated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables structure \\
\hline
\mbox{\texttt{ in}}  & {\em forces} & A structure with the driving mechanical forces \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
 & {\em mld\+\_\+in} & Mixed layer depth provided by the P\+BL scheme \mbox{[}Z $\sim$$>$ m\mbox{]} (not H) \\
\hline
 & {\em varmix} & Container for derived fields \\
\hline
 & {\em cs} & Module control structure \\
\hline
\end{DoxyParams}


Definition at line 120 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{120   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{121   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< Ocean grid structure}}
\DoxyCodeLine{122   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}}
\DoxyCodeLine{123   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{124 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{125 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Accumulated zonal mass flux}}
\DoxyCodeLine{126 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}}
\DoxyCodeLine{127 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Accumulated meridional mass flux}}
\DoxyCodeLine{128 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}}
\DoxyCodeLine{129   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{     !< Thermodynamic variables structure}}
\DoxyCodeLine{130   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{ !< A structure with the driving mechanical forces}}
\DoxyCodeLine{131 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time increment [T ~> s]}}
\DoxyCodeLine{132 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                      \textcolor{keywordtype}{pointer}       :: MLD\_in\textcolor{comment}{ !< Mixed layer depth provided by the}}
\DoxyCodeLine{133 \textcolor{comment}{                                                                     !! PBL scheme [Z ~> m] (not H)}}
\DoxyCodeLine{134   \textcolor{keywordtype}{type}(VarMix\_CS),                           \textcolor{keywordtype}{pointer}       :: VarMix\textcolor{comment}{ !< Container for derived fields}}
\DoxyCodeLine{135   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Module control structure}}
\DoxyCodeLine{136   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{137 \textcolor{keywordtype}{  real} :: uhml(SZIB\_(G),SZJ\_(G),SZK\_(G)) \textcolor{comment}{! zonal mixed layer transport [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1]}}
\DoxyCodeLine{138 \textcolor{keywordtype}{  real} :: vhml(SZI\_(G),SZJB\_(G),SZK\_(G)) \textcolor{comment}{! merid mixed layer transport [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1]}}
\DoxyCodeLine{139 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{140     h\_avail               \textcolor{comment}{! The volume available for diffusion out of each face of each}}
\DoxyCodeLine{141                           \textcolor{comment}{! sublayer of the mixed layer, divided by dt [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{142 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{143     MLD\_fast, \&           \textcolor{comment}{! Mixed layer depth actually used in MLE restratification parameterization [H ~> m or kg m-\/2]}}
\DoxyCodeLine{144     htot\_fast, \&          \textcolor{comment}{! The sum of the thicknesses of layers in the mixed layer [H ~> m or kg m-\/2]}}
\DoxyCodeLine{145     Rml\_av\_fast, \&        \textcolor{comment}{! g\_Rho0 times the average mixed layer density [L2 Z-\/1 T-\/2 ~> m s-\/2]}}
\DoxyCodeLine{146     MLD\_slow, \&           \textcolor{comment}{! Mixed layer depth actually used in MLE restratification parameterization [H ~> m or kg m-\/2]}}
\DoxyCodeLine{147     htot\_slow, \&          \textcolor{comment}{! The sum of the thicknesses of layers in the mixed layer [H ~> m or kg m-\/2]}}
\DoxyCodeLine{148     Rml\_av\_slow           \textcolor{comment}{! g\_Rho0 times the average mixed layer density [L2 Z-\/1 T-\/2 ~> m s-\/2]}}
\DoxyCodeLine{149 \textcolor{keywordtype}{  real} :: g\_Rho0          \textcolor{comment}{! G\_Earth/Rho0 [L2 Z-\/1 T-\/2 R-\/1 ~> m4 s-\/2 kg-\/1]}}
\DoxyCodeLine{150 \textcolor{keywordtype}{  real} :: rho\_ml(SZI\_(G)) \textcolor{comment}{! Potential density relative to the surface [R ~> kg m-\/3]}}
\DoxyCodeLine{151 \textcolor{keywordtype}{  real} :: p0(SZI\_(G))     \textcolor{comment}{! A pressure of 0 [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{152 }
\DoxyCodeLine{153 \textcolor{keywordtype}{  real} :: h\_vel           \textcolor{comment}{! htot interpolated onto velocity points [Z ~> m] (not H).}}
\DoxyCodeLine{154 \textcolor{keywordtype}{  real} :: absf            \textcolor{comment}{! absolute value of f, interpolated to velocity points [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{155 \textcolor{keywordtype}{  real} :: u\_star          \textcolor{comment}{! surface friction velocity, interpolated to velocity points [Z T-\/1 ~> m s-\/1].}}
\DoxyCodeLine{156 \textcolor{keywordtype}{  real} :: mom\_mixrate     \textcolor{comment}{! rate at which momentum is homogenized within mixed layer [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{157 \textcolor{keywordtype}{  real} :: timescale       \textcolor{comment}{! mixing growth timescale [T ~> s]}}
\DoxyCodeLine{158 \textcolor{keywordtype}{  real} :: h\_neglect       \textcolor{comment}{! tiny thickness usually lost in roundoff so can be neglected [H ~> m or kg m-\/2]}}
\DoxyCodeLine{159 \textcolor{keywordtype}{  real} :: dz\_neglect      \textcolor{comment}{! A tiny thickness that is usually lost in roundoff so can be neglected [Z ~> m]}}
\DoxyCodeLine{160 \textcolor{keywordtype}{  real} :: I4dt            \textcolor{comment}{! 1/(4 dt) [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{161 \textcolor{keywordtype}{  real} :: Ihtot,Ihtot\_slow\textcolor{comment}{! Inverses of the total mixed layer thickness [H-\/1 ~> m-\/1 or m2 kg-\/1]}}
\DoxyCodeLine{162 \textcolor{keywordtype}{  real} :: a(SZK\_(G))      \textcolor{comment}{! A non-\/dimensional value relating the overall flux}}
\DoxyCodeLine{163                           \textcolor{comment}{! magnitudes (uDml \& vDml) to the realized flux in a}}
\DoxyCodeLine{164                           \textcolor{comment}{! layer.  The vertical sum of a() through the pieces of}}
\DoxyCodeLine{165                           \textcolor{comment}{! the mixed layer must be 0.}}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real} :: b(SZK\_(G))      \textcolor{comment}{! As for a(k) but for the slow-\/filtered MLD}}
\DoxyCodeLine{167 \textcolor{keywordtype}{  real} :: uDml(SZIB\_(G))  \textcolor{comment}{! The zonal and meridional volume fluxes in the upper}}
\DoxyCodeLine{168 \textcolor{keywordtype}{  real} :: vDml(SZI\_(G))   \textcolor{comment}{! half of the mixed layer [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{169 \textcolor{keywordtype}{  real} :: uDml\_slow(SZIB\_(G))  \textcolor{comment}{! The zonal and meridional volume fluxes in the upper}}
\DoxyCodeLine{170 \textcolor{keywordtype}{  real} :: vDml\_slow(SZI\_(G))   \textcolor{comment}{! half of the mixed layer [H L2 T-\/1 ~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{171 \textcolor{keywordtype}{  real} :: utimescale\_diag(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! restratification timescales in the zonal and}}
\DoxyCodeLine{172 \textcolor{keywordtype}{  real} :: vtimescale\_diag(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! meridional directions [T ~> s], stored in 2-\/D arrays}}
\DoxyCodeLine{173                                             \textcolor{comment}{! for diagnostic purposes.}}
\DoxyCodeLine{174 \textcolor{keywordtype}{  real} :: uDml\_diag(SZIB\_(G),SZJ\_(G)), vDml\_diag(SZI\_(G),SZJB\_(G))}
\DoxyCodeLine{175 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rhoSurf, deltaRhoAtKm1, deltaRhoAtK \textcolor{comment}{! Densities [R ~> kg m-\/3]}}
\DoxyCodeLine{176 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: dK, dKm1 \textcolor{comment}{! Depths of layer centers [H ~> m or kg m-\/2].}}
\DoxyCodeLine{177 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: pRef\_MLD \textcolor{comment}{! A reference pressure for calculating the mixed layer}}
\DoxyCodeLine{178                                        \textcolor{comment}{! densities [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{179 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rhoAtK, rho1, d1, pRef\_N2 \textcolor{comment}{! Used for N2}}
\DoxyCodeLine{180 \textcolor{keywordtype}{  real} :: aFac, bFac \textcolor{comment}{! Nondimensional ratios [nondim]}}
\DoxyCodeLine{181 \textcolor{keywordtype}{  real} :: ddRho    \textcolor{comment}{! A density difference [R ~> kg m-\/3]}}
\DoxyCodeLine{182 \textcolor{keywordtype}{  real} :: hAtVel, zpa, zpb, dh, res\_scaling\_fac}
\DoxyCodeLine{183 \textcolor{keywordtype}{  real} :: I\_LFront \textcolor{comment}{! The inverse of the frontal length scale [L-\/1 ~> m-\/1]}}
\DoxyCodeLine{184   \textcolor{keywordtype}{logical} :: line\_is\_empty, keep\_going, res\_upscale}
\DoxyCodeLine{185   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{186   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz}
\DoxyCodeLine{187 }
\DoxyCodeLine{188 \textcolor{keywordtype}{  real} :: PSI, PSI1, z, BOTTOP, XP, DD \textcolor{comment}{! For the following statement functions}}
\DoxyCodeLine{189   \textcolor{comment}{! Stream function as a function of non-\/dimensional position within mixed-\/layer (F77 statement function)}}
\DoxyCodeLine{190   \textcolor{comment}{!PSI1(z) = max(0., (1. -\/ (2.*z+1.)**2 ) )}}
\DoxyCodeLine{191   psi1(z) = max(0., (1. -\/ (2.*z+1.)**2 ) * (1. + (5./21.)*(2.*z+1.)**2) )}
\DoxyCodeLine{192   bottop(z) = 0.5*(1.-\/sign(1.,z+0.5)) \textcolor{comment}{! =0 for z>-\/0.5, =1 for z<-\/0.5}}
\DoxyCodeLine{193   xp(z) = max(0., min(1., (-\/z-\/0.5)*2./(1.+2.*cs\%MLE\_tail\_dh) ) )}
\DoxyCodeLine{194   dd(z) = (1.-\/3.*(xp(z)**2)+2.*(xp(z)**3))**(1.+2.*cs\%MLE\_tail\_dh)}
\DoxyCodeLine{195   psi(z) = max( psi1(z), dd(z)*bottop(z) ) \textcolor{comment}{! Combines original PSI1 with tail}}
\DoxyCodeLine{196 }
\DoxyCodeLine{197   is  = g\%isc  ; ie  = g\%iec  ; js  = g\%jsc  ; je  = g\%jec ; nz = g\%ke}
\DoxyCodeLine{198   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{199 }
\DoxyCodeLine{200   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv\%eqn\_of\_state)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{201          \textcolor{stringliteral}{"An equation of state must be used with this module."})}
\DoxyCodeLine{202   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(varmix) .and. cs\%front\_length>0.) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{203          \textcolor{stringliteral}{"The resolution argument, Rd/dx, was not associated."})}
\DoxyCodeLine{204 }
\DoxyCodeLine{205   \textcolor{keywordflow}{if} (cs\%MLE\_density\_diff > 0.) \textcolor{keywordflow}{then} \textcolor{comment}{! We need to calculate a mixed layer depth, MLD.}}
\DoxyCodeLine{206     \textcolor{comment}{!! TODO: use derivatives and mid-\/MLD pressure. Currently this is sigma-\/0. -\/AJA}}
\DoxyCodeLine{207     pref\_mld(:) = 0.}
\DoxyCodeLine{208     eosdom(:) = eos\_domain(g\%HI, halo=1)}
\DoxyCodeLine{209     \textcolor{keywordflow}{do} j = js-\/1, je+1}
\DoxyCodeLine{210       dk(:) = 0.5 * h(:,j,1) \textcolor{comment}{! Depth of center of surface layer}}
\DoxyCodeLine{211       \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,1), tv\%S(:,j,1), pref\_mld, rhosurf, tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{212       deltarhoatk(:) = 0.}
\DoxyCodeLine{213       mld\_fast(:,j) = 0.}
\DoxyCodeLine{214       \textcolor{keywordflow}{do} k = 2, nz}
\DoxyCodeLine{215         dkm1(:) = dk(:) \textcolor{comment}{! Depth of center of layer K-\/1}}
\DoxyCodeLine{216         dk(:) = dk(:) + 0.5 * ( h(:,j,k) + h(:,j,k-\/1) ) \textcolor{comment}{! Depth of center of layer K}}
\DoxyCodeLine{217         \textcolor{comment}{! Mixed-\/layer depth, using sigma-\/0 (surface reference pressure)}}
\DoxyCodeLine{218         deltarhoatkm1(:) = deltarhoatk(:) \textcolor{comment}{! Store value from previous iteration of K}}
\DoxyCodeLine{219         \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,k), tv\%S(:,j,k), pref\_mld, deltarhoatk, tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{220         \textcolor{keywordflow}{do} i = is-\/1,ie+1}
\DoxyCodeLine{221           deltarhoatk(i) = deltarhoatk(i) -\/ rhosurf(i) \textcolor{comment}{! Density difference between layer K and surface}}
\DoxyCodeLine{222 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{223         \textcolor{keywordflow}{do} i = is-\/1, ie+1}
\DoxyCodeLine{224           ddrho = deltarhoatk(i) -\/ deltarhoatkm1(i)}
\DoxyCodeLine{225           \textcolor{keywordflow}{if} ((mld\_fast(i,j)==0.) .and. (ddrho>0.) .and. \&}
\DoxyCodeLine{226               (deltarhoatkm1(i)<cs\%MLE\_density\_diff) .and. (deltarhoatk(i)>=cs\%MLE\_density\_diff)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{227             afac = ( cs\%MLE\_density\_diff -\/ deltarhoatkm1(i) ) / ddrho}
\DoxyCodeLine{228             mld\_fast(i,j) = dk(i) * afac + dkm1(i) * (1. -\/ afac)}
\DoxyCodeLine{229 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{230 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{231 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-\/loop}}
\DoxyCodeLine{232       \textcolor{keywordflow}{do} i = is-\/1, ie+1}
\DoxyCodeLine{233         mld\_fast(i,j) = cs\%MLE\_MLD\_stretch * mld\_fast(i,j)}
\DoxyCodeLine{234         \textcolor{keywordflow}{if} ((mld\_fast(i,j)==0.) .and. (deltarhoatk(i)<cs\%MLE\_density\_diff)) \&}
\DoxyCodeLine{235           mld\_fast(i,j) = dk(i) \textcolor{comment}{! Assume mixing to the bottom}}
\DoxyCodeLine{236 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{237 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! j-\/loop}}
\DoxyCodeLine{238   \textcolor{keywordflow}{elseif} (cs\%MLE\_use\_PBL\_MLD) \textcolor{keywordflow}{then}}
\DoxyCodeLine{239     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(mld\_in)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{240          \textcolor{stringliteral}{"Argument MLD\_in was not associated!"})}
\DoxyCodeLine{241     \textcolor{keywordflow}{do} j = js-\/1, je+1 ; \textcolor{keywordflow}{do} i = is-\/1, ie+1}
\DoxyCodeLine{242       mld\_fast(i,j) = (cs\%MLE\_MLD\_stretch * gv\%Z\_to\_H) * mld\_in(i,j)}
\DoxyCodeLine{243 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{244   \textcolor{keywordflow}{else}}
\DoxyCodeLine{245     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// \&}
\DoxyCodeLine{246          \textcolor{stringliteral}{"No MLD to use for MLE parameterization."})}
\DoxyCodeLine{247 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{248 }
\DoxyCodeLine{249   \textcolor{comment}{! Apply time filter (to remove diurnal cycle)}}
\DoxyCodeLine{250   \textcolor{keywordflow}{if} (cs\%MLE\_MLD\_decay\_time>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{251     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{252       \textcolor{keyword}{call }hchksum(cs\%MLD\_filtered, \textcolor{stringliteral}{'mixed\_layer\_restrat: MLD\_filtered'}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{253       \textcolor{keyword}{call }hchksum(mld\_in, \textcolor{stringliteral}{'mixed\_layer\_restrat: MLD in'}, g\%HI, haloshift=1, scale=us\%Z\_to\_m)}
\DoxyCodeLine{254 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{255     afac = cs\%MLE\_MLD\_decay\_time / ( dt + cs\%MLE\_MLD\_decay\_time )}
\DoxyCodeLine{256     bfac = dt / ( dt + cs\%MLE\_MLD\_decay\_time )}
\DoxyCodeLine{257     \textcolor{keywordflow}{do} j = js-\/1, je+1 ; \textcolor{keywordflow}{do} i = is-\/1, ie+1}
\DoxyCodeLine{258       \textcolor{comment}{! Expression bFac*MLD\_fast(i,j) + aFac*CS\%MLD\_filtered(i,j) is the time-\/filtered}}
\DoxyCodeLine{259       \textcolor{comment}{! (running mean) of MLD. The max() allows the "running mean" to be reset}}
\DoxyCodeLine{260       \textcolor{comment}{! instantly to a deeper MLD.}}
\DoxyCodeLine{261       cs\%MLD\_filtered(i,j) = max( mld\_fast(i,j), bfac*mld\_fast(i,j) + afac*cs\%MLD\_filtered(i,j) )}
\DoxyCodeLine{262       mld\_fast(i,j) = cs\%MLD\_filtered(i,j)}
\DoxyCodeLine{263 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{264 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{265 }
\DoxyCodeLine{266   \textcolor{comment}{! Apply slower time filter (to remove seasonal cycle) on already filtered MLD\_fast}}
\DoxyCodeLine{267   \textcolor{keywordflow}{if} (cs\%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{268     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{269       \textcolor{keyword}{call }hchksum(cs\%MLD\_filtered\_slow,\textcolor{stringliteral}{'mixed\_layer\_restrat: MLD\_filtered\_slow'},g\%HI,haloshift=1,scale=gv\%H\_to\_m)}
\DoxyCodeLine{270       \textcolor{keyword}{call }hchksum(mld\_fast,\textcolor{stringliteral}{'mixed\_layer\_restrat: MLD fast'},g\%HI,haloshift=1,scale=gv\%H\_to\_m)}
\DoxyCodeLine{271 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{272     afac = cs\%MLE\_MLD\_decay\_time2 / ( dt + cs\%MLE\_MLD\_decay\_time2 )}
\DoxyCodeLine{273     bfac = dt / ( dt + cs\%MLE\_MLD\_decay\_time2 )}
\DoxyCodeLine{274     \textcolor{keywordflow}{do} j = js-\/1, je+1 ; \textcolor{keywordflow}{do} i = is-\/1, ie+1}
\DoxyCodeLine{275       \textcolor{comment}{! Expression bFac*MLD\_fast(i,j) + aFac*CS\%MLD\_filtered(i,j) is the time-\/filtered}}
\DoxyCodeLine{276       \textcolor{comment}{! (running mean) of MLD. The max() allows the "running mean" to be reset}}
\DoxyCodeLine{277       \textcolor{comment}{! instantly to a deeper MLD.}}
\DoxyCodeLine{278       cs\%MLD\_filtered\_slow(i,j) = max( mld\_fast(i,j), bfac*mld\_fast(i,j) + afac*cs\%MLD\_filtered\_slow(i,j) )}
\DoxyCodeLine{279       mld\_slow(i,j) = cs\%MLD\_filtered\_slow(i,j)}
\DoxyCodeLine{280 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{281   \textcolor{keywordflow}{else}}
\DoxyCodeLine{282     \textcolor{keywordflow}{do} j = js-\/1, je+1 ; \textcolor{keywordflow}{do} i = is-\/1, ie+1}
\DoxyCodeLine{283       mld\_slow(i,j) = mld\_fast(i,j)}
\DoxyCodeLine{284 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{285 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{286 }
\DoxyCodeLine{287   udml(:) = 0.0 ; vdml(:) = 0.0}
\DoxyCodeLine{288   udml\_slow(:) = 0.0 ; vdml\_slow(:) = 0.0}
\DoxyCodeLine{289   i4dt = 0.25 / dt}
\DoxyCodeLine{290   g\_rho0 = gv\%g\_Earth / gv\%Rho0}
\DoxyCodeLine{291   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{292   dz\_neglect = gv\%H\_subroundoff*gv\%H\_to\_Z}
\DoxyCodeLine{293   \textcolor{keywordflow}{if} (cs\%front\_length>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{294     res\_upscale = .true.}
\DoxyCodeLine{295     i\_lfront = 1. / cs\%front\_length}
\DoxyCodeLine{296   \textcolor{keywordflow}{else}}
\DoxyCodeLine{297     res\_upscale = .false.}
\DoxyCodeLine{298 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{299 }
\DoxyCodeLine{300   p0(:) = 0.0}
\DoxyCodeLine{301   eosdom(:) = eos\_domain(g\%HI, halo=1)}
\DoxyCodeLine{302 \textcolor{comment}{!\$OMP parallel default(none) shared(is,ie,js,je,G,GV,US,htot\_fast,Rml\_av\_fast,tv,p0,h,h\_avail,\&}}
\DoxyCodeLine{303 \textcolor{comment}{!\$OMP                               h\_neglect,g\_Rho0,I4dt,CS,uhml,uhtr,dt,vhml,vhtr,EOSdom,   \&}}
\DoxyCodeLine{304 \textcolor{comment}{!\$OMP                               utimescale\_diag,vtimescale\_diag,forces,dz\_neglect, \&}}
\DoxyCodeLine{305 \textcolor{comment}{!\$OMP                               htot\_slow,MLD\_slow,Rml\_av\_slow,VarMix,I\_LFront,    \&}}
\DoxyCodeLine{306 \textcolor{comment}{!\$OMP                               res\_upscale, nz,MLD\_fast,uDml\_diag,vDml\_diag)      \&}}
\DoxyCodeLine{307 \textcolor{comment}{!\$OMP                       private(rho\_ml,h\_vel,u\_star,absf,mom\_mixrate,timescale,    \&}}
\DoxyCodeLine{308 \textcolor{comment}{!\$OMP                               line\_is\_empty, keep\_going,res\_scaling\_fac,         \&}}
\DoxyCodeLine{309 \textcolor{comment}{!\$OMP                               a,IhTot,b,Ihtot\_slow,zpb,hAtVel,zpa,dh)            \&}}
\DoxyCodeLine{310 \textcolor{comment}{!\$OMP                       firstprivate(uDml,vDml,uDml\_slow,vDml\_slow)}}
\DoxyCodeLine{311 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{312   \textcolor{keywordflow}{do} j=js-\/1,je+1}
\DoxyCodeLine{313     \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{314       htot\_fast(i,j) = 0.0 ; rml\_av\_fast(i,j) = 0.0}
\DoxyCodeLine{315       htot\_slow(i,j) = 0.0 ; rml\_av\_slow(i,j) = 0.0}
\DoxyCodeLine{316 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{317     keep\_going = .true.}
\DoxyCodeLine{318     \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{319       \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{320         h\_avail(i,j,k) = max(i4dt*g\%areaT(i,j)*(h(i,j,k)-\/gv\%Angstrom\_H),0.0)}
\DoxyCodeLine{321 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{322       \textcolor{keywordflow}{if} (keep\_going) \textcolor{keywordflow}{then}}
\DoxyCodeLine{323         \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,k), tv\%S(:,j,k), p0, rho\_ml(:), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{324         line\_is\_empty = .true.}
\DoxyCodeLine{325         \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{326           \textcolor{keywordflow}{if} (htot\_fast(i,j) < mld\_fast(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{327             dh = min( h(i,j,k), mld\_fast(i,j)-\/htot\_fast(i,j) )}
\DoxyCodeLine{328             rml\_av\_fast(i,j) = rml\_av\_fast(i,j) + dh*rho\_ml(i)}
\DoxyCodeLine{329             htot\_fast(i,j) = htot\_fast(i,j) + dh}
\DoxyCodeLine{330             line\_is\_empty = .false.}
\DoxyCodeLine{331 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{332           \textcolor{keywordflow}{if} (htot\_slow(i,j) < mld\_slow(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{333             dh = min( h(i,j,k), mld\_slow(i,j)-\/htot\_slow(i,j) )}
\DoxyCodeLine{334             rml\_av\_slow(i,j) = rml\_av\_slow(i,j) + dh*rho\_ml(i)}
\DoxyCodeLine{335             htot\_slow(i,j) = htot\_slow(i,j) + dh}
\DoxyCodeLine{336             line\_is\_empty = .false.}
\DoxyCodeLine{337 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{338 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{339         \textcolor{keywordflow}{if} (line\_is\_empty) keep\_going=.false.}
\DoxyCodeLine{340 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{341 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{342 }
\DoxyCodeLine{343     \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{344       rml\_av\_fast(i,j) = -\/(g\_rho0*rml\_av\_fast(i,j)) / (htot\_fast(i,j) + h\_neglect)}
\DoxyCodeLine{345       rml\_av\_slow(i,j) = -\/(g\_rho0*rml\_av\_slow(i,j)) / (htot\_slow(i,j) + h\_neglect)}
\DoxyCodeLine{346 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{347 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{348 }
\DoxyCodeLine{349   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{350     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{'mixed\_layer\_restrat: h'}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{351     \textcolor{keyword}{call }hchksum(forces\%ustar,\textcolor{stringliteral}{'mixed\_layer\_restrat: u*'}, g\%HI, haloshift=1, scale=us\%Z\_to\_m*us\%s\_to\_T)}
\DoxyCodeLine{352     \textcolor{keyword}{call }hchksum(mld\_fast,\textcolor{stringliteral}{'mixed\_layer\_restrat: MLD'}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{353     \textcolor{keyword}{call }hchksum(rml\_av\_fast,\textcolor{stringliteral}{'mixed\_layer\_restrat: rml'}, g\%HI, haloshift=1, \&}
\DoxyCodeLine{354                  scale=us\%m\_to\_Z*us\%L\_T\_to\_m\_s**2)}
\DoxyCodeLine{355 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{356 }
\DoxyCodeLine{357 \textcolor{comment}{! TO DO:}}
\DoxyCodeLine{358 \textcolor{comment}{!   1. Mixing extends below the mixing layer to the mixed layer.  Find it!}}
\DoxyCodeLine{359 \textcolor{comment}{!   2. Add exponential tail to stream-\/function?}}
\DoxyCodeLine{360 }
\DoxyCodeLine{361 \textcolor{comment}{!   U -\/ Component}}
\DoxyCodeLine{362 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{363   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{364     u\_star = 0.5*(forces\%ustar(i,j) + forces\%ustar(i+1,j))}
\DoxyCodeLine{365     absf = 0.5*(abs(g\%CoriolisBu(i,j-\/1)) + abs(g\%CoriolisBu(i,j)))}
\DoxyCodeLine{366     \textcolor{comment}{! If needed, res\_scaling\_fac = min( ds, L\_d ) / l\_f}}
\DoxyCodeLine{367     \textcolor{keywordflow}{if} (res\_upscale) res\_scaling\_fac = \&}
\DoxyCodeLine{368           ( sqrt( 0.5 * ( g\%dxCu(i,j)**2 + g\%dyCu(i,j)**2 ) ) * i\_lfront ) \&}
\DoxyCodeLine{369           * min( 1., 0.5*( varmix\%Rd\_dx\_h(i,j) + varmix\%Rd\_dx\_h(i+1,j) ) )}
\DoxyCodeLine{370 }
\DoxyCodeLine{371     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}}
\DoxyCodeLine{372     \textcolor{comment}{! momentum mixing rate: pi\string^2*visc/h\_ml\string^2}}
\DoxyCodeLine{373     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi\string^2.}}
\DoxyCodeLine{374     h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i+1,j)) + h\_neglect) * gv\%H\_to\_Z}
\DoxyCodeLine{375     mom\_mixrate = (0.41*9.8696)*u\_star**2 / \&}
\DoxyCodeLine{376                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)}
\DoxyCodeLine{377     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)}
\DoxyCodeLine{378     timescale = timescale * cs\%ml\_restrat\_coef}
\DoxyCodeLine{379     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac}
\DoxyCodeLine{380     udml(i) = timescale * g\%mask2dCu(i,j)*g\%dyCu(i,j)*g\%IdxCu(i,j) * \&}
\DoxyCodeLine{381         (rml\_av\_fast(i+1,j)-\/rml\_av\_fast(i,j)) * (h\_vel**2 * gv\%Z\_to\_H)}
\DoxyCodeLine{382     \textcolor{comment}{! As above but using the slow filtered MLD}}
\DoxyCodeLine{383     h\_vel = 0.5*((htot\_slow(i,j) + htot\_slow(i+1,j)) + h\_neglect) * gv\%H\_to\_Z}
\DoxyCodeLine{384     mom\_mixrate = (0.41*9.8696)*u\_star**2 / \&}
\DoxyCodeLine{385                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)}
\DoxyCodeLine{386     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)}
\DoxyCodeLine{387     timescale = timescale * cs\%ml\_restrat\_coef2}
\DoxyCodeLine{388     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac}
\DoxyCodeLine{389     udml\_slow(i) = timescale * g\%mask2dCu(i,j)*g\%dyCu(i,j)*g\%IdxCu(i,j) * \&}
\DoxyCodeLine{390         (rml\_av\_slow(i+1,j)-\/rml\_av\_slow(i,j)) * (h\_vel**2 * gv\%Z\_to\_H)}
\DoxyCodeLine{391 }
\DoxyCodeLine{392     \textcolor{keywordflow}{if} (udml(i) + udml\_slow(i) == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{393       \textcolor{keywordflow}{do} k=1,nz ; uhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{394     \textcolor{keywordflow}{else}}
\DoxyCodeLine{395       ihtot = 2.0 / ((htot\_fast(i,j) + htot\_fast(i+1,j)) + h\_neglect)}
\DoxyCodeLine{396       ihtot\_slow = 2.0 / ((htot\_slow(i,j) + htot\_slow(i+1,j)) + h\_neglect)}
\DoxyCodeLine{397       zpa = 0.0 ; zpb = 0.0}
\DoxyCodeLine{398       \textcolor{comment}{! a(k) relates the sublayer transport to uDml with a linear profile.}}
\DoxyCodeLine{399       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}}
\DoxyCodeLine{400       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{401         hatvel = 0.5*(h(i,j,k) + h(i+1,j,k))}
\DoxyCodeLine{402         a(k) = psi(zpa)                     \textcolor{comment}{! Psi(z/MLD) for upper interface}}
\DoxyCodeLine{403         zpa = zpa -\/ (hatvel * ihtot)        \textcolor{comment}{! z/H for lower interface}}
\DoxyCodeLine{404         a(k) = a(k) -\/ psi(zpa)              \textcolor{comment}{! Transport profile}}
\DoxyCodeLine{405         \textcolor{comment}{! Limit magnitude (uDml) if it would violate CFL}}
\DoxyCodeLine{406         \textcolor{keywordflow}{if} (a(k)*udml(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{407           \textcolor{keywordflow}{if} (a(k)*udml(i) > h\_avail(i,j,k)) udml(i) = h\_avail(i,j,k) / a(k)}
\DoxyCodeLine{408         \textcolor{keywordflow}{elseif} (a(k)*udml(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{409           \textcolor{keywordflow}{if} (-\/a(k)*udml(i) > h\_avail(i+1,j,k)) udml(i) = -\/h\_avail(i+1,j,k) / a(k)}
\DoxyCodeLine{410 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{411 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{412       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{413         \textcolor{comment}{! Transport for slow-\/filtered MLD}}
\DoxyCodeLine{414         hatvel = 0.5*(h(i,j,k) + h(i+1,j,k))}
\DoxyCodeLine{415         b(k) = psi(zpb)                     \textcolor{comment}{! Psi(z/MLD) for upper interface}}
\DoxyCodeLine{416         zpb = zpb -\/ (hatvel * ihtot\_slow)   \textcolor{comment}{! z/H for lower interface}}
\DoxyCodeLine{417         b(k) = b(k) -\/ psi(zpb)              \textcolor{comment}{! Transport profile}}
\DoxyCodeLine{418         \textcolor{comment}{! Limit magnitude (uDml\_slow) if it would violate CFL when added to uDml}}
\DoxyCodeLine{419         \textcolor{keywordflow}{if} (b(k)*udml\_slow(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{420           \textcolor{keywordflow}{if} (b(k)*udml\_slow(i) > h\_avail(i,j,k) -\/ a(k)*udml(i)) \&}
\DoxyCodeLine{421              udml\_slow(i) = max( 0., h\_avail(i,j,k) -\/ a(k)*udml(i) ) / b(k)}
\DoxyCodeLine{422         \textcolor{keywordflow}{elseif} (b(k)*udml\_slow(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{423           \textcolor{keywordflow}{if} (-\/b(k)*udml\_slow(i) > h\_avail(i+1,j,k) + a(k)*udml(i)) \&}
\DoxyCodeLine{424              udml\_slow(i) = -\/max( 0., h\_avail(i+1,j,k) + a(k)*udml(i) ) / b(k)}
\DoxyCodeLine{425 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{426 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{427       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{428         uhml(i,j,k) = a(k)*udml(i) + b(k)*udml\_slow(i)}
\DoxyCodeLine{429         uhtr(i,j,k) = uhtr(i,j,k) + uhml(i,j,k)*dt}
\DoxyCodeLine{430 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{431 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{432 }
\DoxyCodeLine{433     utimescale\_diag(i,j) = timescale}
\DoxyCodeLine{434     udml\_diag(i,j) = udml(i)}
\DoxyCodeLine{435 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{436 }
\DoxyCodeLine{437 \textcolor{comment}{!  V-\/ component}}
\DoxyCodeLine{438 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{439   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{440     u\_star = 0.5*(forces\%ustar(i,j) + forces\%ustar(i,j+1))}
\DoxyCodeLine{441     absf = 0.5*(abs(g\%CoriolisBu(i-\/1,j)) + abs(g\%CoriolisBu(i,j)))}
\DoxyCodeLine{442     \textcolor{comment}{! If needed, res\_scaling\_fac = min( ds, L\_d ) / l\_f}}
\DoxyCodeLine{443     \textcolor{keywordflow}{if} (res\_upscale) res\_scaling\_fac = \&}
\DoxyCodeLine{444           ( sqrt( 0.5 * ( (g\%dxCv(i,j))**2 + (g\%dyCv(i,j))**2 ) ) * i\_lfront ) \&}
\DoxyCodeLine{445           * min( 1., 0.5*( varmix\%Rd\_dx\_h(i,j) + varmix\%Rd\_dx\_h(i,j+1) ) )}
\DoxyCodeLine{446 }
\DoxyCodeLine{447     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}}
\DoxyCodeLine{448     \textcolor{comment}{! momentum mixing rate: pi\string^2*visc/h\_ml\string^2}}
\DoxyCodeLine{449     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi\string^2.}}
\DoxyCodeLine{450     h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i,j+1)) + h\_neglect) * gv\%H\_to\_Z}
\DoxyCodeLine{451     mom\_mixrate = (0.41*9.8696)*u\_star**2 / \&}
\DoxyCodeLine{452                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)}
\DoxyCodeLine{453     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)}
\DoxyCodeLine{454     timescale = timescale * cs\%ml\_restrat\_coef}
\DoxyCodeLine{455     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac}
\DoxyCodeLine{456     vdml(i) = timescale * g\%mask2dCv(i,j)*g\%dxCv(i,j)*g\%IdyCv(i,j) * \&}
\DoxyCodeLine{457         (rml\_av\_fast(i,j+1)-\/rml\_av\_fast(i,j)) * (h\_vel**2 * gv\%Z\_to\_H)}
\DoxyCodeLine{458     \textcolor{comment}{! As above but using the slow filtered MLD}}
\DoxyCodeLine{459     h\_vel = 0.5*((htot\_slow(i,j) + htot\_slow(i,j+1)) + h\_neglect) * gv\%H\_to\_Z}
\DoxyCodeLine{460     mom\_mixrate = (0.41*9.8696)*u\_star**2 / \&}
\DoxyCodeLine{461                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)}
\DoxyCodeLine{462     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)}
\DoxyCodeLine{463     timescale = timescale * cs\%ml\_restrat\_coef2}
\DoxyCodeLine{464     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac}
\DoxyCodeLine{465     vdml\_slow(i) = timescale * g\%mask2dCv(i,j)*g\%dxCv(i,j)*g\%IdyCv(i,j) * \&}
\DoxyCodeLine{466         (rml\_av\_slow(i,j+1)-\/rml\_av\_slow(i,j)) * (h\_vel**2 * gv\%Z\_to\_H)}
\DoxyCodeLine{467 }
\DoxyCodeLine{468     \textcolor{keywordflow}{if} (vdml(i) + vdml\_slow(i) == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{469       \textcolor{keywordflow}{do} k=1,nz ; vhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{470     \textcolor{keywordflow}{else}}
\DoxyCodeLine{471       ihtot = 2.0 / ((htot\_fast(i,j) + htot\_fast(i,j+1)) + h\_neglect)}
\DoxyCodeLine{472       ihtot\_slow = 2.0 / ((htot\_slow(i,j) + htot\_slow(i,j+1)) + h\_neglect)}
\DoxyCodeLine{473       zpa = 0.0 ; zpb = 0.0}
\DoxyCodeLine{474       \textcolor{comment}{! a(k) relates the sublayer transport to vDml with a linear profile.}}
\DoxyCodeLine{475       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}}
\DoxyCodeLine{476       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{477         hatvel = 0.5*(h(i,j,k) + h(i,j+1,k))}
\DoxyCodeLine{478         a(k) = psi( zpa )                   \textcolor{comment}{! Psi(z/MLD) for upper interface}}
\DoxyCodeLine{479         zpa = zpa -\/ (hatvel * ihtot)        \textcolor{comment}{! z/H for lower interface}}
\DoxyCodeLine{480         a(k) = a(k) -\/ psi( zpa )            \textcolor{comment}{! Transport profile}}
\DoxyCodeLine{481         \textcolor{comment}{! Limit magnitude (vDml) if it would violate CFL}}
\DoxyCodeLine{482         \textcolor{keywordflow}{if} (a(k)*vdml(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483           \textcolor{keywordflow}{if} (a(k)*vdml(i) > h\_avail(i,j,k)) vdml(i) = h\_avail(i,j,k) / a(k)}
\DoxyCodeLine{484         \textcolor{keywordflow}{elseif} (a(k)*vdml(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{485           \textcolor{keywordflow}{if} (-\/a(k)*vdml(i) > h\_avail(i,j+1,k)) vdml(i) = -\/h\_avail(i,j+1,k) / a(k)}
\DoxyCodeLine{486 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{487 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{488       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{489         \textcolor{comment}{! Transport for slow-\/filtered MLD}}
\DoxyCodeLine{490         hatvel = 0.5*(h(i,j,k) + h(i,j+1,k))}
\DoxyCodeLine{491         b(k) = psi(zpb)                     \textcolor{comment}{! Psi(z/MLD) for upper interface}}
\DoxyCodeLine{492         zpb = zpb -\/ (hatvel * ihtot\_slow)   \textcolor{comment}{! z/H for lower interface}}
\DoxyCodeLine{493         b(k) = b(k) -\/ psi(zpb)              \textcolor{comment}{! Transport profile}}
\DoxyCodeLine{494         \textcolor{comment}{! Limit magnitude (vDml\_slow) if it would violate CFL when added to vDml}}
\DoxyCodeLine{495         \textcolor{keywordflow}{if} (b(k)*vdml\_slow(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{496           \textcolor{keywordflow}{if} (b(k)*vdml\_slow(i) > h\_avail(i,j,k) -\/ a(k)*vdml(i)) \&}
\DoxyCodeLine{497              vdml\_slow(i) = max( 0., h\_avail(i,j,k) -\/ a(k)*vdml(i) ) / b(k)}
\DoxyCodeLine{498         \textcolor{keywordflow}{elseif} (b(k)*vdml\_slow(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{499           \textcolor{keywordflow}{if} (-\/b(k)*vdml\_slow(i) > h\_avail(i,j+1,k) + a(k)*vdml(i)) \&}
\DoxyCodeLine{500              vdml\_slow(i) = -\/max( 0., h\_avail(i,j+1,k) + a(k)*vdml(i) ) / b(k)}
\DoxyCodeLine{501 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{502 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{503       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{504         vhml(i,j,k) = a(k)*vdml(i) + b(k)*vdml\_slow(i)}
\DoxyCodeLine{505         vhtr(i,j,k) = vhtr(i,j,k) + vhml(i,j,k)*dt}
\DoxyCodeLine{506 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{507 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{508 }
\DoxyCodeLine{509     vtimescale\_diag(i,j) = timescale}
\DoxyCodeLine{510     vdml\_diag(i,j) = vdml(i)}
\DoxyCodeLine{511 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{512 }
\DoxyCodeLine{513 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{514   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{515     h(i,j,k) = h(i,j,k) -\/ dt*g\%IareaT(i,j) * \&}
\DoxyCodeLine{516         ((uhml(i,j,k) -\/ uhml(i-\/1,j,k)) + (vhml(i,j,k) -\/ vhml(i,j-\/1,k)))}
\DoxyCodeLine{517 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{518 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{519 }
\DoxyCodeLine{520   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}}
\DoxyCodeLine{521   \textcolor{comment}{! for vertical remapping may need to be regenerated.}}
\DoxyCodeLine{522   \textcolor{keywordflow}{if} (cs\%id\_uhml > 0 .or. cs\%id\_vhml > 0) \&}
\DoxyCodeLine{523     \textcolor{comment}{! Remapped uhml and vhml require east/north halo updates of h}}
\DoxyCodeLine{524     \textcolor{keyword}{call }pass\_var(h, g\%domain, to\_west+to\_south+omit\_corners, halo=1)}
\DoxyCodeLine{525   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{526 }
\DoxyCodeLine{527   \textcolor{comment}{! Offer diagnostic fields for averaging.}}
\DoxyCodeLine{528   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{529     \textcolor{keywordflow}{if} (cs\%id\_urestrat\_time > 0) \textcolor{keyword}{call }post\_data(cs\%id\_urestrat\_time, utimescale\_diag, cs\%diag)}
\DoxyCodeLine{530     \textcolor{keywordflow}{if} (cs\%id\_vrestrat\_time > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vrestrat\_time, vtimescale\_diag, cs\%diag)}
\DoxyCodeLine{531     \textcolor{keywordflow}{if} (cs\%id\_uhml          > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uhml, uhml, cs\%diag)}
\DoxyCodeLine{532     \textcolor{keywordflow}{if} (cs\%id\_vhml          > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vhml, vhml, cs\%diag)}
\DoxyCodeLine{533     \textcolor{keywordflow}{if} (cs\%id\_MLD           > 0) \textcolor{keyword}{call }post\_data(cs\%id\_MLD, mld\_fast, cs\%diag)}
\DoxyCodeLine{534     \textcolor{keywordflow}{if} (cs\%id\_Rml           > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Rml, rml\_av\_fast, cs\%diag)}
\DoxyCodeLine{535     \textcolor{keywordflow}{if} (cs\%id\_uDml          > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uDml, udml\_diag, cs\%diag)}
\DoxyCodeLine{536     \textcolor{keywordflow}{if} (cs\%id\_vDml          > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vDml, vdml\_diag, cs\%diag)}
\DoxyCodeLine{537 }
\DoxyCodeLine{538     \textcolor{keywordflow}{if} (cs\%id\_uml > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{539       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{540         h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i+1,j)) + h\_neglect)}
\DoxyCodeLine{541         udml\_diag(i,j) = udml\_diag(i,j) / (0.01*h\_vel) * g\%IdyCu(i,j) * (psi(0.)-\/psi(-\/.01))}
\DoxyCodeLine{542 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{543       \textcolor{keyword}{call }post\_data(cs\%id\_uml, udml\_diag, cs\%diag)}
\DoxyCodeLine{544 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{545     \textcolor{keywordflow}{if} (cs\%id\_vml > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{546       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{547         h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i,j+1)) + h\_neglect)}
\DoxyCodeLine{548         vdml\_diag(i,j) = vdml\_diag(i,j) / (0.01*h\_vel) * g\%IdxCv(i,j) * (psi(0.)-\/psi(-\/.01))}
\DoxyCodeLine{549 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{550       \textcolor{keyword}{call }post\_data(cs\%id\_vml, vdml\_diag, cs\%diag)}
\DoxyCodeLine{551 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{552 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{553   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}}
\DoxyCodeLine{554   \textcolor{comment}{! for vertical remapping may need to be regenerated.}}
\DoxyCodeLine{555   \textcolor{comment}{! This needs to happen after the H update and before the next post\_data.}}
\DoxyCodeLine{556   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{557 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a89b89663722cc9047a3bb238a4bfa09a}\label{namespacemom__mixed__layer__restrat_a89b89663722cc9047a3bb238a4bfa09a}} 
\index{mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}!mixedlayer\_restrat\_init@{mixedlayer\_restrat\_init}}
\index{mixedlayer\_restrat\_init@{mixedlayer\_restrat\_init}!mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}}
\doxysubsubsection{\texorpdfstring{mixedlayer\_restrat\_init()}{mixedlayer\_restrat\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\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(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Initialize the mixed layer restratification module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & Current model time \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file to parse \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Regulate diagnostics \\
\hline
 & {\em cs} & Module control structure \\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure \\
\hline
\end{DoxyParams}


Definition at line 797 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{797   \textcolor{keywordtype}{type}(time\_type),             \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< Current model time}}
\DoxyCodeLine{798   \textcolor{keywordtype}{type}(ocean\_grid\_type),       \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< Ocean grid structure}}
\DoxyCodeLine{799   \textcolor{keywordtype}{type}(verticalGrid\_type),     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Ocean vertical grid structure}}
\DoxyCodeLine{800   \textcolor{keywordtype}{type}(unit\_scale\_type),       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{801   \textcolor{keywordtype}{type}(param\_file\_type),       \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file to parse}}
\DoxyCodeLine{802   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},     \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Regulate diagnostics}}
\DoxyCodeLine{803   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< Module control structure}}
\DoxyCodeLine{804   \textcolor{keywordtype}{type}(MOM\_restart\_CS),        \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}}
\DoxyCodeLine{805 }
\DoxyCodeLine{806   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{807 \textcolor{keywordtype}{  real} :: H\_rescale  \textcolor{comment}{! A rescaling factor for thicknesses from the representation in}}
\DoxyCodeLine{808                      \textcolor{comment}{! a restart file to the internal representation in this run.}}
\DoxyCodeLine{809 \textcolor{keywordtype}{  real} :: flux\_to\_kg\_per\_s \textcolor{comment}{! A unit conversion factor for fluxes.}}
\DoxyCodeLine{810   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{811 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{812 \textcolor{preprocessor}{}  \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{813 }
\DoxyCodeLine{814   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{815   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIXEDLAYER\_RESTRAT"}, mixedlayer\_restrat\_init, \&}
\DoxyCodeLine{816              default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{817   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""}, all\_default=.not.mixedlayer\_restrat\_init)}
\DoxyCodeLine{818   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIXEDLAYER\_RESTRAT"}, mixedlayer\_restrat\_init, \&}
\DoxyCodeLine{819              \textcolor{stringliteral}{"If true, a density-\/gradient dependent re-\/stratifying "}//\&}
\DoxyCodeLine{820              \textcolor{stringliteral}{"flow is imposed in the mixed layer. Can be used in ALE mode "}//\&}
\DoxyCodeLine{821              \textcolor{stringliteral}{"without restriction but in layer mode can only be used if "}//\&}
\DoxyCodeLine{822              \textcolor{stringliteral}{"BULKMIXEDLAYER is true."}, default=.false.)}
\DoxyCodeLine{823   \textcolor{keywordflow}{if} (.not. mixedlayer\_restrat\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{824 }
\DoxyCodeLine{825   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{826     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"mixedlayer\_restrat\_init called without an associated control structure."})}
\DoxyCodeLine{827 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{828 }
\DoxyCodeLine{829   \textcolor{comment}{! Nonsense values to cause problems when these parameters are not used}}
\DoxyCodeLine{830   cs\%MLE\_MLD\_decay\_time = -\/9.e9*us\%s\_to\_T}
\DoxyCodeLine{831   cs\%MLE\_density\_diff = -\/9.e9*us\%kg\_m3\_to\_R}
\DoxyCodeLine{832   cs\%MLE\_tail\_dh = -\/9.e9}
\DoxyCodeLine{833   cs\%MLE\_use\_PBL\_MLD = .false.}
\DoxyCodeLine{834   cs\%MLE\_MLD\_stretch = -\/9.e9}
\DoxyCodeLine{835 }
\DoxyCodeLine{836   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs\%debug, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{837   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FOX\_KEMPER\_ML\_RESTRAT\_COEF"}, cs\%ml\_restrat\_coef, \&}
\DoxyCodeLine{838              \textcolor{stringliteral}{"A nondimensional coefficient that is proportional to "}//\&}
\DoxyCodeLine{839              \textcolor{stringliteral}{"the ratio of the deformation radius to the dominant "}//\&}
\DoxyCodeLine{840              \textcolor{stringliteral}{"lengthscale of the submesoscale mixed layer "}//\&}
\DoxyCodeLine{841              \textcolor{stringliteral}{"instabilities, times the minimum of the ratio of the "}//\&}
\DoxyCodeLine{842              \textcolor{stringliteral}{"mesoscale eddy kinetic energy to the large-\/scale "}//\&}
\DoxyCodeLine{843              \textcolor{stringliteral}{"geostrophic kinetic energy or 1 plus the square of the "}//\&}
\DoxyCodeLine{844              \textcolor{stringliteral}{"grid spacing over the deformation radius, as detailed "}//\&}
\DoxyCodeLine{845              \textcolor{stringliteral}{"by Fox-\/Kemper et al. (2010)"}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{846   \textcolor{comment}{! We use GV\%nkml to distinguish between the old and new implementation of MLE.}}
\DoxyCodeLine{847   \textcolor{comment}{! The old implementation only works for the layer model with nkml>0.}}
\DoxyCodeLine{848   \textcolor{keywordflow}{if} (gv\%nkml==0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{849     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FOX\_KEMPER\_ML\_RESTRAT\_COEF2"}, cs\%ml\_restrat\_coef2, \&}
\DoxyCodeLine{850              \textcolor{stringliteral}{"As for FOX\_KEMPER\_ML\_RESTRAT\_COEF but used in a second application "}//\&}
\DoxyCodeLine{851              \textcolor{stringliteral}{"of the MLE restratification parameterization."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{852     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_FRONT\_LENGTH"}, cs\%front\_length, \&}
\DoxyCodeLine{853              \textcolor{stringliteral}{"If non-\/zero, is the frontal-\/length scale used to calculate the "}//\&}
\DoxyCodeLine{854              \textcolor{stringliteral}{"upscaling of buoyancy gradients that is otherwise represented "}//\&}
\DoxyCodeLine{855              \textcolor{stringliteral}{"by the parameter FOX\_KEMPER\_ML\_RESTRAT\_COEF. If MLE\_FRONT\_LENGTH is "}//\&}
\DoxyCodeLine{856              \textcolor{stringliteral}{"non-\/zero, it is recommended to set FOX\_KEMPER\_ML\_RESTRAT\_COEF=1.0."},\&}
\DoxyCodeLine{857              units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us\%m\_to\_L)}
\DoxyCodeLine{858     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_USE\_PBL\_MLD"}, cs\%MLE\_use\_PBL\_MLD, \&}
\DoxyCodeLine{859              \textcolor{stringliteral}{"If true, the MLE parameterization will use the mixed-\/layer "}//\&}
\DoxyCodeLine{860              \textcolor{stringliteral}{"depth provided by the active PBL parameterization. If false, "}//\&}
\DoxyCodeLine{861              \textcolor{stringliteral}{"MLE will estimate a MLD based on a density difference with the "}//\&}
\DoxyCodeLine{862              \textcolor{stringliteral}{"surface using the parameter MLE\_DENSITY\_DIFF."}, default=.false.)}
\DoxyCodeLine{863     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME"}, cs\%MLE\_MLD\_decay\_time, \&}
\DoxyCodeLine{864              \textcolor{stringliteral}{"The time-\/scale for a running-\/mean filter applied to the mixed-\/layer "}//\&}
\DoxyCodeLine{865              \textcolor{stringliteral}{"depth used in the MLE restratification parameterization. When "}//\&}
\DoxyCodeLine{866              \textcolor{stringliteral}{"the MLD deepens below the current running-\/mean the running-\/mean "}//\&}
\DoxyCodeLine{867              \textcolor{stringliteral}{"is instantaneously set to the current MLD."}, units=\textcolor{stringliteral}{"s"}, default=0., scale=us\%s\_to\_T)}
\DoxyCodeLine{868     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME2"}, cs\%MLE\_MLD\_decay\_time2, \&}
\DoxyCodeLine{869              \textcolor{stringliteral}{"The time-\/scale for a running-\/mean filter applied to the filtered "}//\&}
\DoxyCodeLine{870              \textcolor{stringliteral}{"mixed-\/layer depth used in a second MLE restratification parameterization. "}//\&}
\DoxyCodeLine{871              \textcolor{stringliteral}{"When the MLD deepens below the current running-\/mean the running-\/mean "}//\&}
\DoxyCodeLine{872              \textcolor{stringliteral}{"is instantaneously set to the current MLD."}, units=\textcolor{stringliteral}{"s"}, default=0., scale=us\%s\_to\_T)}
\DoxyCodeLine{873     \textcolor{keywordflow}{if} (.not. cs\%MLE\_use\_PBL\_MLD) \textcolor{keywordflow}{then}}
\DoxyCodeLine{874       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_DENSITY\_DIFF"}, cs\%MLE\_density\_diff, \&}
\DoxyCodeLine{875              \textcolor{stringliteral}{"Density difference used to detect the mixed-\/layer "}//\&}
\DoxyCodeLine{876              \textcolor{stringliteral}{"depth used for the mixed-\/layer eddy parameterization "}//\&}
\DoxyCodeLine{877              \textcolor{stringliteral}{"by Fox-\/Kemper et al. (2010)"}, units=\textcolor{stringliteral}{"kg/m3"}, default=0.03, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{878 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{879     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_TAIL\_DH"}, cs\%MLE\_tail\_dh, \&}
\DoxyCodeLine{880              \textcolor{stringliteral}{"Fraction by which to extend the mixed-\/layer restratification "}//\&}
\DoxyCodeLine{881              \textcolor{stringliteral}{"depth used for a smoother stream function at the base of "}//\&}
\DoxyCodeLine{882              \textcolor{stringliteral}{"the mixed-\/layer."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{883     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_STRETCH"}, cs\%MLE\_MLD\_stretch, \&}
\DoxyCodeLine{884              \textcolor{stringliteral}{"A scaling coefficient for stretching/shrinking the MLD "}//\&}
\DoxyCodeLine{885              \textcolor{stringliteral}{"used in the MLE scheme. This simply multiplies MLD wherever used."},\&}
\DoxyCodeLine{886              units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{887 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{888 }
\DoxyCodeLine{889   cs\%diag => diag}
\DoxyCodeLine{890 }
\DoxyCodeLine{891   flux\_to\_kg\_per\_s = gv\%H\_to\_kg\_m2 * us\%L\_to\_m**2 * us\%s\_to\_T}
\DoxyCodeLine{892 }
\DoxyCodeLine{893   cs\%id\_uhml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhml'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{894       \textcolor{stringliteral}{'Zonal Thickness Flux to Restratify Mixed Layer'}, \textcolor{stringliteral}{'kg s-\/1'}, \&}
\DoxyCodeLine{895       conversion=flux\_to\_kg\_per\_s, y\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true.)}
\DoxyCodeLine{896   cs\%id\_vhml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhml'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{897       \textcolor{stringliteral}{'Meridional Thickness Flux to Restratify Mixed Layer'}, \textcolor{stringliteral}{'kg s-\/1'}, \&}
\DoxyCodeLine{898       conversion=flux\_to\_kg\_per\_s, x\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true.)}
\DoxyCodeLine{899   cs\%id\_urestrat\_time = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MLu\_restrat\_time'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{900       \textcolor{stringliteral}{'Mixed Layer Zonal Restratification Timescale'}, \textcolor{stringliteral}{'s'}, conversion=us\%T\_to\_s)}
\DoxyCodeLine{901   cs\%id\_vrestrat\_time = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MLv\_restrat\_time'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{902       \textcolor{stringliteral}{'Mixed Layer Meridional Restratification Timescale'}, \textcolor{stringliteral}{'s'}, conversion=us\%T\_to\_s)}
\DoxyCodeLine{903   cs\%id\_MLD = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MLD\_restrat'}, diag\%axesT1, time, \&}
\DoxyCodeLine{904       \textcolor{stringliteral}{'Mixed Layer Depth as used in the mixed-\/layer restratification parameterization'}, \textcolor{stringliteral}{'m'}, \&}
\DoxyCodeLine{905       conversion=gv\%H\_to\_m)}
\DoxyCodeLine{906   cs\%id\_Rml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ML\_buoy\_restrat'}, diag\%axesT1, time, \&}
\DoxyCodeLine{907       \textcolor{stringliteral}{'Mixed Layer Buoyancy as used in the mixed-\/layer restratification parameterization'}, \&}
\DoxyCodeLine{908       \textcolor{stringliteral}{'m s2'}, conversion=us\%m\_to\_Z*(us\%L\_to\_m**2)*(us\%s\_to\_T**2))}
\DoxyCodeLine{909   cs\%id\_uDml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'udml\_restrat'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{910       \textcolor{stringliteral}{'Transport stream function amplitude for zonal restratification of mixed layer'}, \&}
\DoxyCodeLine{911       \textcolor{stringliteral}{'m3 s-\/1'}, conversion=gv\%H\_to\_m*(us\%L\_to\_m**2)*us\%s\_to\_T)}
\DoxyCodeLine{912   cs\%id\_vDml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vdml\_restrat'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{913       \textcolor{stringliteral}{'Transport stream function amplitude for meridional restratification of mixed layer'}, \&}
\DoxyCodeLine{914       \textcolor{stringliteral}{'m3 s-\/1'}, conversion=gv\%H\_to\_m*(us\%L\_to\_m**2)*us\%s\_to\_T)}
\DoxyCodeLine{915   cs\%id\_uml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uml\_restrat'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{916       \textcolor{stringliteral}{'Surface zonal velocity component of mixed layer restratification'}, \&}
\DoxyCodeLine{917       \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{918   cs\%id\_vml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vml\_restrat'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{919       \textcolor{stringliteral}{'Surface meridional velocity component of mixed layer restratification'}, \&}
\DoxyCodeLine{920       \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{921 }
\DoxyCodeLine{922   \textcolor{comment}{! Rescale variables from restart files if the internal dimensional scalings have changed.}}
\DoxyCodeLine{923   \textcolor{keywordflow}{if} (cs\%MLE\_MLD\_decay\_time>0. .or. cs\%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{924     \textcolor{keywordflow}{if} (query\_initialized(cs\%MLD\_filtered, \textcolor{stringliteral}{"MLD\_MLE\_filtered"}, restart\_cs) .and. \&}
\DoxyCodeLine{925         (gv\%m\_to\_H\_restart /= 0.0) .and. (gv\%m\_to\_H\_restart /= gv\%m\_to\_H)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{926       h\_rescale = gv\%m\_to\_H / gv\%m\_to\_H\_restart}
\DoxyCodeLine{927       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{928         cs\%MLD\_filtered(i,j) = h\_rescale * cs\%MLD\_filtered(i,j)}
\DoxyCodeLine{929 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{930 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{931 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{932   \textcolor{keywordflow}{if} (cs\%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{933     \textcolor{keywordflow}{if} (query\_initialized(cs\%MLD\_filtered\_slow, \textcolor{stringliteral}{"MLD\_MLE\_filtered\_slow"}, restart\_cs) .and. \&}
\DoxyCodeLine{934         (gv\%m\_to\_H\_restart /= 0.0) .and. (gv\%m\_to\_H\_restart /= gv\%m\_to\_H)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{935       h\_rescale = gv\%m\_to\_H / gv\%m\_to\_H\_restart}
\DoxyCodeLine{936       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{937         cs\%MLD\_filtered\_slow(i,j) = h\_rescale * cs\%MLD\_filtered\_slow(i,j)}
\DoxyCodeLine{938 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{939 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{940 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{941 }
\DoxyCodeLine{942   \textcolor{comment}{! If MLD\_filtered is being used, we need to update halo regions after a restart}}
\DoxyCodeLine{943   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%MLD\_filtered)) \textcolor{keyword}{call }pass\_var(cs\%MLD\_filtered, g\%domain)}
\DoxyCodeLine{944 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_aea597553dfa98cc7c972784f476ad3fc}\label{namespacemom__mixed__layer__restrat_aea597553dfa98cc7c972784f476ad3fc}} 
\index{mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}!mixedlayer\_restrat\_register\_restarts@{mixedlayer\_restrat\_register\_restarts}}
\index{mixedlayer\_restrat\_register\_restarts@{mixedlayer\_restrat\_register\_restarts}!mom\_mixed\_layer\_restrat@{mom\_mixed\_layer\_restrat}}
\doxysubsubsection{\texorpdfstring{mixedlayer\_restrat\_register\_restarts()}{mixedlayer\_restrat\_register\_restarts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Allocate and register fields in the mixed layer restratification structure for restarts. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & Horizontal index structure \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file to parse \\
\hline
 & {\em cs} & Module control structure \\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure \\
\hline
\end{DoxyParams}


Definition at line 949 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{949   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{950   \textcolor{keywordtype}{type}(hor\_index\_type),        \textcolor{keywordtype}{intent(in)}    :: HI\textcolor{comment}{         !< Horizontal index structure}}
\DoxyCodeLine{951   \textcolor{keywordtype}{type}(param\_file\_type),       \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file to parse}}
\DoxyCodeLine{952   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< Module control structure}}
\DoxyCodeLine{953   \textcolor{keywordtype}{type}(MOM\_restart\_CS),        \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}}
\DoxyCodeLine{954   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{955   \textcolor{keywordtype}{type}(vardesc) :: vd}
\DoxyCodeLine{956   \textcolor{keywordtype}{logical} :: mixedlayer\_restrat\_init}
\DoxyCodeLine{957 }
\DoxyCodeLine{958   \textcolor{comment}{! Check to see if this module will be used}}
\DoxyCodeLine{959   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIXEDLAYER\_RESTRAT"}, mixedlayer\_restrat\_init, \&}
\DoxyCodeLine{960              default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{961   \textcolor{keywordflow}{if} (.not. mixedlayer\_restrat\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{962 }
\DoxyCodeLine{963   \textcolor{comment}{! Allocate the control structure. CS will be later populated by mixedlayer\_restrat\_init()}}
\DoxyCodeLine{964   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{965        \textcolor{stringliteral}{"mixedlayer\_restrat\_register\_restarts called with an associated control structure."})}
\DoxyCodeLine{966   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{967 }
\DoxyCodeLine{968   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME"}, cs\%MLE\_MLD\_decay\_time, \&}
\DoxyCodeLine{969                  default=0., do\_not\_log=.true.)}
\DoxyCodeLine{970   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME2"}, cs\%MLE\_MLD\_decay\_time2, \&}
\DoxyCodeLine{971                  default=0., do\_not\_log=.true.)}
\DoxyCodeLine{972   \textcolor{keywordflow}{if} (cs\%MLE\_MLD\_decay\_time>0. .or. cs\%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{973     \textcolor{comment}{! CS\%MLD\_filtered is used to keep a running mean of the PBL's actively mixed MLD.}}
\DoxyCodeLine{974     \textcolor{keyword}{allocate}(cs\%MLD\_filtered(hi\%isd:hi\%ied,hi\%jsd:hi\%jed)) ; cs\%MLD\_filtered(:,:) = 0.}
\DoxyCodeLine{975     vd = var\_desc(\textcolor{stringliteral}{"MLD\_MLE\_filtered"},\textcolor{stringliteral}{"m"},\textcolor{stringliteral}{"Time-\/filtered MLD for use in MLE"}, \&}
\DoxyCodeLine{976                   hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{977     \textcolor{keyword}{call }register\_restart\_field(cs\%MLD\_filtered, vd, .false., restart\_cs)}
\DoxyCodeLine{978 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{979   \textcolor{keywordflow}{if} (cs\%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{980     \textcolor{comment}{! CS\%MLD\_filtered\_slow is used to keep a running mean of the PBL's seasonal or winter MLD.}}
\DoxyCodeLine{981     \textcolor{keyword}{allocate}(cs\%MLD\_filtered\_slow(hi\%isd:hi\%ied,hi\%jsd:hi\%jed)) ; cs\%MLD\_filtered\_slow(:,:) = 0.}
\DoxyCodeLine{982     vd = var\_desc(\textcolor{stringliteral}{"MLD\_MLE\_filtered\_slow"},\textcolor{stringliteral}{"m"},\textcolor{stringliteral}{"c Slower time-\/filtered MLD for use in MLE"}, \&}
\DoxyCodeLine{983                   hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{984     \textcolor{keyword}{call }register\_restart\_field(cs\%MLD\_filtered\_slow, vd, .false., restart\_cs)}
\DoxyCodeLine{985 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{986 }

\end{DoxyCode}
