\hypertarget{namespacemom__cvmix__kpp}{}\doxysection{mom\+\_\+cvmix\+\_\+kpp Module Reference}
\label{namespacemom__cvmix__kpp}\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}


\doxysubsection{Detailed Description}
Provides the K-\/\+Profile Parameterization (K\+PP) of Large et al., 1994, via C\+V\+Mix. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for containing K\+PP parameters/data. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__cvmix__kpp_ada767f6da63b74348a7461eb1d12c5d6}{kpp\+\_\+init}} (param\+File, G, GV, US, diag, Time, CS, passive, Waves)
\begin{DoxyCompactList}\small\item\em Initialize the C\+V\+Mix K\+PP module and set up diagnostics Returns True if K\+PP is to be used, False otherwise. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__kpp_a94d77471726028da980fd9f998b4173f}{kpp\+\_\+calculate}} (CS, G, GV, US, h, u\+Star, buoy\+Flux, Kt, Ks, Kv, non\+Local\+Trans\+Heat, non\+Local\+Trans\+Scalar, waves)
\begin{DoxyCompactList}\small\item\em K\+PP vertical diffusivity/viscosity and non-\/local tracer transport. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__kpp_aa91f493f6da97da3536d0f4d47cb442c}{kpp\+\_\+compute\+\_\+bld}} (CS, G, GV, US, h, Temp, Salt, u, v, tv, u\+Star, buoy\+Flux, Waves)
\begin{DoxyCompactList}\small\item\em Compute O\+BL depth. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__cvmix__kpp_a8662fdd6328fdec67691ced27f03e049}{kpp\+\_\+smooth\+\_\+bld}} (CS, G, GV, h)
\begin{DoxyCompactList}\small\item\em Apply a 1-\/1-\/4-\/1-\/1 Laplacian filter one time on B\+LD to reduce any horizontal two-\/grid-\/point noise. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__kpp_abcb80984f564e5aaf4567aaead111734}{kpp\+\_\+get\+\_\+bld}} (CS, B\+LD, G, US, m\+\_\+to\+\_\+\+B\+L\+D\+\_\+units)
\begin{DoxyCompactList}\small\item\em Copies K\+PP surface boundary layer depth into B\+LD, in units of \mbox{[}Z $\sim$$>$ m\mbox{]} unless other units are specified. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__kpp_a54093ca1cac897785c965c00efa12fe6}{kpp\+\_\+nonlocaltransport\+\_\+temp}} (CS, G, GV, h, non\+Local\+Trans, surf\+Flux, dt, scalar, C\+\_\+p)
\begin{DoxyCompactList}\small\item\em Apply K\+PP non-\/local transport of surface fluxes for temperature. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__kpp_abebacc1ae8c13149d816a60ff2e824b6}{kpp\+\_\+nonlocaltransport\+\_\+saln}} (CS, G, GV, h, non\+Local\+Trans, surf\+Flux, dt, scalar)
\begin{DoxyCompactList}\small\item\em Apply K\+PP non-\/local transport of surface fluxes for salinity. This routine is a useful prototype for other material tracers. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__kpp_ab64722f48cd1d20a4c5bfc74ad602326}{kpp\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clear pointers, deallocate memory. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_afe095f912beb51eb5710dbd68cc42dab}\label{namespacemom__cvmix__kpp_afe095f912beb51eb5710dbd68cc42dab}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_afe095f912beb51eb5710dbd68cc42dab}{nlt\+\_\+shape\+\_\+cvmix}} = 0
\begin{DoxyCompactList}\small\item\em Use the C\+V\+Mix profile. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a306be669f441bd2b242e1303f59dfa5e}\label{namespacemom__cvmix__kpp_a306be669f441bd2b242e1303f59dfa5e}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a306be669f441bd2b242e1303f59dfa5e}{nlt\+\_\+shape\+\_\+linear}} = 1
\begin{DoxyCompactList}\small\item\em Linear, $ G(\sigma) = 1-\sigma $. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a82f43a1532d552db2ba495d16d3928a0}\label{namespacemom__cvmix__kpp_a82f43a1532d552db2ba495d16d3928a0}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a82f43a1532d552db2ba495d16d3928a0}{nlt\+\_\+shape\+\_\+parabolic}} = 2
\begin{DoxyCompactList}\small\item\em Parabolic, $ G(\sigma) = (1-\sigma)^2 $. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a70bd2978b36d6b3aa9aa625c03c03f0a}\label{namespacemom__cvmix__kpp_a70bd2978b36d6b3aa9aa625c03c03f0a}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a70bd2978b36d6b3aa9aa625c03c03f0a}{nlt\+\_\+shape\+\_\+cubic}} = 3
\begin{DoxyCompactList}\small\item\em Cubic, $ G(\sigma) = 1 + (2\sigma-3) \sigma^2$. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a9b5190793b228cf859a34c4a173fbe77}\label{namespacemom__cvmix__kpp_a9b5190793b228cf859a34c4a173fbe77}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a9b5190793b228cf859a34c4a173fbe77}{nlt\+\_\+shape\+\_\+cubic\+\_\+lmd}} = 4
\begin{DoxyCompactList}\small\item\em Original shape, $ G(\sigma) = \frac{27}{4} \sigma (1-\sigma)^2 $. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a16884cc2e9d4bdb9c5fedc0bc3f23056}\label{namespacemom__cvmix__kpp_a16884cc2e9d4bdb9c5fedc0bc3f23056}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a16884cc2e9d4bdb9c5fedc0bc3f23056}{sw\+\_\+method\+\_\+all\+\_\+sw}} = 0
\begin{DoxyCompactList}\small\item\em Use all shortwave radiation. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_afbc1dc214273291361c246545118665b}\label{namespacemom__cvmix__kpp_afbc1dc214273291361c246545118665b}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_afbc1dc214273291361c246545118665b}{sw\+\_\+method\+\_\+mxl\+\_\+sw}} = 1
\begin{DoxyCompactList}\small\item\em Use shortwave radiation absorbed in mixing layer. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a8577785b93b4c59c3d16c920af7a9064}\label{namespacemom__cvmix__kpp_a8577785b93b4c59c3d16c920af7a9064}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a8577785b93b4c59c3d16c920af7a9064}{sw\+\_\+method\+\_\+lv1\+\_\+sw}} = 2
\begin{DoxyCompactList}\small\item\em Use shortwave radiation absorbed in layer 1. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a31fec7101872773e8704b39fbab011ed}\label{namespacemom__cvmix__kpp_a31fec7101872773e8704b39fbab011ed}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a31fec7101872773e8704b39fbab011ed}{lt\+\_\+k\+\_\+constant}} = 1
\begin{DoxyCompactList}\small\item\em Constant enhance K through column. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_aabd55e341dc321fac17b08fdadff4451}\label{namespacemom__cvmix__kpp_aabd55e341dc321fac17b08fdadff4451}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_aabd55e341dc321fac17b08fdadff4451}{lt\+\_\+k\+\_\+scaled}} = 2
\begin{DoxyCompactList}\small\item\em Enhance K scales with G(sigma) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ac38b6557079872047ac625d722546fee}\label{namespacemom__cvmix__kpp_ac38b6557079872047ac625d722546fee}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_ac38b6557079872047ac625d722546fee}{lt\+\_\+k\+\_\+mode\+\_\+constant}} = 1
\begin{DoxyCompactList}\small\item\em Prescribed enhancement for K. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a6dbc98c4e4582ea2cc4c3f2253bbd5e7}\label{namespacemom__cvmix__kpp_a6dbc98c4e4582ea2cc4c3f2253bbd5e7}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a6dbc98c4e4582ea2cc4c3f2253bbd5e7}{lt\+\_\+k\+\_\+mode\+\_\+vr12}} = 2
\begin{DoxyCompactList}\small\item\em Enhancement for K based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ac917e24dabaab72de04483c5b5813741}\label{namespacemom__cvmix__kpp_ac917e24dabaab72de04483c5b5813741}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_ac917e24dabaab72de04483c5b5813741}{lt\+\_\+k\+\_\+mode\+\_\+rw16}} = 3
\begin{DoxyCompactList}\small\item\em Enhancement for K based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ad15c2df92a8faefdf658ed817298b460}\label{namespacemom__cvmix__kpp_ad15c2df92a8faefdf658ed817298b460}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_ad15c2df92a8faefdf658ed817298b460}{lt\+\_\+vt2\+\_\+mode\+\_\+constant}} = 1
\begin{DoxyCompactList}\small\item\em Prescribed enhancement for Vt2. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a6cb86c81a9d5827900ec5167bb5bac27}\label{namespacemom__cvmix__kpp_a6cb86c81a9d5827900ec5167bb5bac27}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a6cb86c81a9d5827900ec5167bb5bac27}{lt\+\_\+vt2\+\_\+mode\+\_\+vr12}} = 2
\begin{DoxyCompactList}\small\item\em Enhancement for Vt2 based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a28ed11256ee4b98cb15530e600e558cf}\label{namespacemom__cvmix__kpp_a28ed11256ee4b98cb15530e600e558cf}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_a28ed11256ee4b98cb15530e600e558cf}{lt\+\_\+vt2\+\_\+mode\+\_\+rw16}} = 3
\begin{DoxyCompactList}\small\item\em Enhancement for Vt2 based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_acfee181fef7d13f856d2135e52936144}\label{namespacemom__cvmix__kpp_acfee181fef7d13f856d2135e52936144}} 
integer, parameter, private \mbox{\hyperlink{namespacemom__cvmix__kpp_acfee181fef7d13f856d2135e52936144}{lt\+\_\+vt2\+\_\+mode\+\_\+lf17}} = 4
\begin{DoxyCompactList}\small\item\em Enhancement for Vt2 based on. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a94d77471726028da980fd9f998b4173f}\label{namespacemom__cvmix__kpp_a94d77471726028da980fd9f998b4173f}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_calculate@{kpp\_calculate}}
\index{kpp\_calculate@{kpp\_calculate}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_calculate()}{kpp\_calculate()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+calculate (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{u\+Star,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{buoy\+Flux,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Kt,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Ks,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Kv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{non\+Local\+Trans\+Heat,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{non\+Local\+Trans\+Scalar,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{waves }\end{DoxyParamCaption})}



K\+PP vertical diffusivity/viscosity and non-\/local tracer transport. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em waves} & Wave CS \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer/level thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ustar} & Surface friction velocity \mbox{[}Z T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em buoyflux} & Surface buoyancy flux \mbox{[}L2 T-\/3 $\sim$$>$ m2 s-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em kt} & (in) Vertical diffusivity of heat w/o K\+PP (out) Vertical diffusivity including K\+PP \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em ks} & (in) Vertical diffusivity of salt w/o K\+PP (out) Vertical diffusivity including K\+PP \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em kv} & (in) Vertical viscosity w/o K\+PP (out) Vertical viscosity including K\+PP \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em nonlocaltransheat} & Temp non-\/local transport \mbox{[}m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em nonlocaltransscalar} & scalar non-\/local transport \mbox{[}m s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 601 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{604 }
\DoxyCodeLine{605   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{606   \textcolor{keywordtype}{type}(KPP\_CS),                               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< Control structure}}
\DoxyCodeLine{607   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< Ocean grid}}
\DoxyCodeLine{608   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< Ocean vertical grid}}
\DoxyCodeLine{609   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{610   \textcolor{keywordtype}{type}(wave\_parameters\_CS),         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{ !< Wave CS}}
\DoxyCodeLine{611 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer/level thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{612 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: uStar\textcolor{comment}{ !< Surface friction velocity [Z T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{613 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: buoyFlux\textcolor{comment}{ !< Surface buoyancy flux [L2 T-\/3 \string~> m2 s-\/3]}}
\DoxyCodeLine{614 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: Kt\textcolor{comment}{   !< (in)  Vertical diffusivity of heat w/o KPP}}
\DoxyCodeLine{615 \textcolor{comment}{                                                                    !! (out) Vertical diffusivity including KPP}}
\DoxyCodeLine{616 \textcolor{comment}{                                                                    !!       [Z2 T-\/1 \string~> m2 s-\/1]}}
\DoxyCodeLine{617 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: Ks\textcolor{comment}{   !< (in)  Vertical diffusivity of salt w/o KPP}}
\DoxyCodeLine{618 \textcolor{comment}{                                                                    !! (out) Vertical diffusivity including KPP}}
\DoxyCodeLine{619 \textcolor{comment}{                                                                    !!       [Z2 T-\/1 \string~> m2 s-\/1]}}
\DoxyCodeLine{620 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: Kv\textcolor{comment}{   !< (in)  Vertical viscosity w/o KPP}}
\DoxyCodeLine{621 \textcolor{comment}{                                                                    !! (out) Vertical viscosity including KPP}}
\DoxyCodeLine{622 \textcolor{comment}{                                                                    !!       [Z2 T-\/1 \string~> m2 s-\/1]}}
\DoxyCodeLine{623 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: nonLocalTransHeat\textcolor{comment}{   !< Temp non-\/local transport [m s-\/1]}}
\DoxyCodeLine{624 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: nonLocalTransScalar\textcolor{comment}{ !< scalar non-\/local transport [m s-\/1]}}
\DoxyCodeLine{625 }
\DoxyCodeLine{626 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{627   \textcolor{keywordtype}{integer} :: i, j, k                             \textcolor{comment}{! Loop indices}}
\DoxyCodeLine{628 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: cellHeight      \textcolor{comment}{! Cell center heights referenced to surface [m] (negative in ocean)}}
\DoxyCodeLine{629 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1 )}   :: iFaceHeight     \textcolor{comment}{! Interface heights referenced to surface [m] (negative in ocean)}}
\DoxyCodeLine{630 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1, 2)} :: Kdiffusivity    \textcolor{comment}{! Vertical diffusivity at interfaces [m2 s-\/1]}}
\DoxyCodeLine{631 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1 )}   :: Kviscosity      \textcolor{comment}{! Vertical viscosity at interfaces [m2 s-\/1]}}
\DoxyCodeLine{632 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1, 2)} :: nonLocalTrans   \textcolor{comment}{! Non-\/local transport for heat/salt at interfaces [nondim]}}
\DoxyCodeLine{633 }
\DoxyCodeLine{634 \textcolor{keywordtype}{  real} :: surfFricVel, surfBuoyFlux}
\DoxyCodeLine{635 \textcolor{keywordtype}{  real} :: sigma, sigmaRatio}
\DoxyCodeLine{636 \textcolor{keywordtype}{  real} :: buoy\_scale \textcolor{comment}{! A unit conversion factor for buoyancy fluxes [m2 T3 L-\/2 s-\/3 \string~> nondim]}}
\DoxyCodeLine{637 \textcolor{keywordtype}{  real} :: dh    \textcolor{comment}{! The local thickness used for calculating interface positions [m]}}
\DoxyCodeLine{638 \textcolor{keywordtype}{  real} :: hcorr \textcolor{comment}{! A cumulative correction arising from inflation of vanished layers [m]}}
\DoxyCodeLine{639 }
\DoxyCodeLine{640   \textcolor{comment}{! For Langmuir Calculations}}
\DoxyCodeLine{641 \textcolor{keywordtype}{  real} :: LangEnhK     \textcolor{comment}{! Langmuir enhancement for mixing coefficient}}
\DoxyCodeLine{642 }
\DoxyCodeLine{643 }
\DoxyCodeLine{644   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{645     \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"KPP in: h"},g\%HI,haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{646     \textcolor{keyword}{call }hchksum(ustar, \textcolor{stringliteral}{"KPP in: uStar"},g\%HI,haloshift=0, scale=us\%Z\_to\_m*us\%s\_to\_T)}
\DoxyCodeLine{647     \textcolor{keyword}{call }hchksum(buoyflux, \textcolor{stringliteral}{"KPP in: buoyFlux"},g\%HI,haloshift=0)}
\DoxyCodeLine{648     \textcolor{keyword}{call }hchksum(kt, \textcolor{stringliteral}{"KPP in: Kt"},g\%HI,haloshift=0, scale=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{649     \textcolor{keyword}{call }hchksum(ks, \textcolor{stringliteral}{"KPP in: Ks"},g\%HI,haloshift=0, scale=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{650 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{651 }
\DoxyCodeLine{652   nonlocaltrans(:,:) = 0.0}
\DoxyCodeLine{653 }
\DoxyCodeLine{654   \textcolor{keywordflow}{if} (cs\%id\_Kd\_in > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_in, kt, cs\%diag)}
\DoxyCodeLine{655 }
\DoxyCodeLine{656   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_kpp\_calc)}
\DoxyCodeLine{657   buoy\_scale = us\%L\_to\_m**2*us\%s\_to\_T**3}
\DoxyCodeLine{658 }
\DoxyCodeLine{659   \textcolor{comment}{!\$OMP parallel do default(none) firstprivate(nonLocalTrans)                               \&}}
\DoxyCodeLine{660   \textcolor{comment}{!\$OMP                           private(surfFricVel, iFaceHeight, hcorr, dh, cellHeight,  \&}}
\DoxyCodeLine{661   \textcolor{comment}{!\$OMP                           surfBuoyFlux, Kdiffusivity, Kviscosity, LangEnhK, sigma,  \&}}
\DoxyCodeLine{662   \textcolor{comment}{!\$OMP                           sigmaRatio)                                               \&}}
\DoxyCodeLine{663   \textcolor{comment}{!\$OMP                           shared(G, GV, CS, US, uStar, h, buoy\_scale, buoyFlux, Kt, \&}}
\DoxyCodeLine{664   \textcolor{comment}{!\$OMP                           Ks, Kv, nonLocalTransHeat, nonLocalTransScalar, waves)}}
\DoxyCodeLine{665   \textcolor{comment}{! loop over horizontal points on processor}}
\DoxyCodeLine{666   \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{667     \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{668 }
\DoxyCodeLine{669       \textcolor{comment}{! skip calling KPP for land points}}
\DoxyCodeLine{670       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)==0.) cycle}
\DoxyCodeLine{671 }
\DoxyCodeLine{672       \textcolor{comment}{! things independent of position within the column}}
\DoxyCodeLine{673       surffricvel = us\%Z\_to\_m*us\%s\_to\_T * ustar(i,j)}
\DoxyCodeLine{674 }
\DoxyCodeLine{675       ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}}
\DoxyCodeLine{676       hcorr = 0.}
\DoxyCodeLine{677       \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{678 }
\DoxyCodeLine{679         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}}
\DoxyCodeLine{680         dh = h(i,j,k) * gv\%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment}}
\DoxyCodeLine{681         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}}
\DoxyCodeLine{682         hcorr = min( dh -\/ cs\%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}}
\DoxyCodeLine{683         dh = max( dh, cs\%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}}
\DoxyCodeLine{684         cellheight(k)    = ifaceheight(k) -\/ 0.5 * dh}
\DoxyCodeLine{685         ifaceheight(k+1) = ifaceheight(k) -\/ dh}
\DoxyCodeLine{686 }
\DoxyCodeLine{687 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-\/loop finishes}}
\DoxyCodeLine{688 }
\DoxyCodeLine{689       surfbuoyflux = buoy\_scale*buoyflux(i,j,1) \textcolor{comment}{! This is only used in kpp\_compute\_OBL\_depth to limit}}
\DoxyCodeLine{690                                      \textcolor{comment}{! h to Monin-\/Obukov (default is false, ie. not used)}}
\DoxyCodeLine{691 }
\DoxyCodeLine{692       \textcolor{comment}{! Call CVMix/KPP to obtain OBL diffusivities, viscosities and non-\/local transports}}
\DoxyCodeLine{693 }
\DoxyCodeLine{694       \textcolor{comment}{! Unlike LMD94, we do not match to interior diffusivities. If using the original}}
\DoxyCodeLine{695       \textcolor{comment}{! LMD94 shape function, not matching is equivalent to matching to a zero diffusivity.}}
\DoxyCodeLine{696 }
\DoxyCodeLine{697       \textcolor{comment}{!BGR/ Add option for use of surface buoyancy flux with total sw flux.}}
\DoxyCodeLine{698       \textcolor{keywordflow}{if} (cs\%SW\_METHOD == sw\_method\_all\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{699          surfbuoyflux = buoy\_scale * buoyflux(i,j,1)}
\DoxyCodeLine{700       \textcolor{keywordflow}{elseif} (cs\%SW\_METHOD == sw\_method\_mxl\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{701          \textcolor{comment}{! We know the actual buoyancy flux into the OBL}}
\DoxyCodeLine{702          surfbuoyflux  = buoy\_scale * (buoyflux(i,j,1) -\/ buoyflux(i,j,int(cs\%kOBL(i,j))+1))}
\DoxyCodeLine{703       \textcolor{keywordflow}{elseif} (cs\%SW\_METHOD == sw\_method\_lv1\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{704          surfbuoyflux  = buoy\_scale * (buoyflux(i,j,1) -\/ buoyflux(i,j,2))}
\DoxyCodeLine{705 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{706 }
\DoxyCodeLine{707       \textcolor{comment}{! If option "MatchBoth" is selected in CVMix, MOM should be capable of matching.}}
\DoxyCodeLine{708       \textcolor{keywordflow}{if} (.not. (cs\%MatchTechnique == \textcolor{stringliteral}{'MatchBoth'})) \textcolor{keywordflow}{then}}
\DoxyCodeLine{709          kdiffusivity(:,:) = 0. \textcolor{comment}{! Diffusivities for heat and salt [m2 s-\/1]}}
\DoxyCodeLine{710          kviscosity(:)     = 0. \textcolor{comment}{! Viscosity [m2 s-\/1]}}
\DoxyCodeLine{711       \textcolor{keywordflow}{else}}
\DoxyCodeLine{712          kdiffusivity(:,1) = us\%Z2\_T\_to\_m2\_s * kt(i,j,:)}
\DoxyCodeLine{713          kdiffusivity(:,2) = us\%Z2\_T\_to\_m2\_s * ks(i,j,:)}
\DoxyCodeLine{714          kviscosity(:) = us\%Z2\_T\_to\_m2\_s * kv(i,j,:)}
\DoxyCodeLine{715 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{716 }
\DoxyCodeLine{717       \textcolor{keyword}{call }cvmix\_coeffs\_kpp(kviscosity(:),        \& \textcolor{comment}{! (inout) Total viscosity [m2 s-\/1]}}
\DoxyCodeLine{718                             kdiffusivity(:,1), \& \textcolor{comment}{! (inout) Total heat diffusivity [m2 s-\/1]}}
\DoxyCodeLine{719                             kdiffusivity(:,2), \& \textcolor{comment}{! (inout) Total salt diffusivity [m2 s-\/1]}}
\DoxyCodeLine{720                             ifaceheight,       \& \textcolor{comment}{! (in) Height of interfaces [m]}}
\DoxyCodeLine{721                             cellheight,        \& \textcolor{comment}{! (in) Height of level centers [m]}}
\DoxyCodeLine{722                             kviscosity(:),        \& \textcolor{comment}{! (in) Original viscosity [m2 s-\/1]}}
\DoxyCodeLine{723                             kdiffusivity(:,1), \& \textcolor{comment}{! (in) Original heat diffusivity [m2 s-\/1]}}
\DoxyCodeLine{724                             kdiffusivity(:,2), \& \textcolor{comment}{! (in) Original salt diffusivity [m2 s-\/1]}}
\DoxyCodeLine{725                             cs\%OBLdepth(i,j),  \& \textcolor{comment}{! (in) OBL depth [m]}}
\DoxyCodeLine{726                             cs\%kOBL(i,j),      \& \textcolor{comment}{! (in) level (+fraction) of OBL extent}}
\DoxyCodeLine{727                             nonlocaltrans(:,1),\& \textcolor{comment}{! (out) Non-\/local heat transport [nondim]}}
\DoxyCodeLine{728                             nonlocaltrans(:,2),\& \textcolor{comment}{! (out) Non-\/local salt transport [nondim]}}
\DoxyCodeLine{729                             surffricvel,       \& \textcolor{comment}{! (in) Turbulent friction velocity at surface [m s-\/1]}}
\DoxyCodeLine{730                             surfbuoyflux,      \& \textcolor{comment}{! (in) Buoyancy flux at surface [m2 s-\/3]}}
\DoxyCodeLine{731                             g\%ke,              \& \textcolor{comment}{! (in) Number of levels to compute coeffs for}}
\DoxyCodeLine{732                             g\%ke,              \& \textcolor{comment}{! (in) Number of levels in array shape}}
\DoxyCodeLine{733                             cvmix\_kpp\_params\_user=cs\%KPP\_params )}
\DoxyCodeLine{734 }
\DoxyCodeLine{735       \textcolor{comment}{! safety check, Kviscosity and Kdiffusivity must be >= 0}}
\DoxyCodeLine{736       \textcolor{keywordflow}{do} k=1, g\%ke+1}
\DoxyCodeLine{737         \textcolor{keywordflow}{if} (kviscosity(k) < 0. .or. kdiffusivity(k,1) < 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{738           \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_calculate, after CVMix\_coeffs\_kpp: "}// \&}
\DoxyCodeLine{739                    \textcolor{stringliteral}{"Negative vertical viscosity or diffusivity has been detected. "} // \&}
\DoxyCodeLine{740                    \textcolor{stringliteral}{"This is likely related to the choice of MATCH\_TECHNIQUE and INTERP\_TYPE2."} //\&}
\DoxyCodeLine{741                    \textcolor{stringliteral}{"You might consider using the default options for these parameters."} )}
\DoxyCodeLine{742 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{743 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{744 }
\DoxyCodeLine{745       \textcolor{keywordflow}{IF} (cs\%LT\_K\_ENHANCEMENT) \textcolor{keywordflow}{then}}
\DoxyCodeLine{746         \textcolor{keywordflow}{if} (cs\%LT\_K\_METHOD==lt\_k\_mode\_constant) \textcolor{keywordflow}{then}}
\DoxyCodeLine{747            langenhk = cs\%KPP\_K\_ENH\_FAC}
\DoxyCodeLine{748         \textcolor{keywordflow}{elseif} (cs\%LT\_K\_METHOD==lt\_k\_mode\_vr12) \textcolor{keywordflow}{then}}
\DoxyCodeLine{749            \textcolor{comment}{! Added minimum value for La\_SL, so removed maximum value for LangEnhK.}}
\DoxyCodeLine{750            langenhk = sqrt(1.+(1.5*cs\%La\_SL(i,j))**(-\/2) + \&}
\DoxyCodeLine{751                 (5.4*cs\%La\_SL(i,j))**(-\/4))}
\DoxyCodeLine{752         \textcolor{keywordflow}{elseif} (cs\%LT\_K\_METHOD==lt\_k\_mode\_rw16) \textcolor{keywordflow}{then}}
\DoxyCodeLine{753           \textcolor{comment}{!This maximum value is proposed in Reichl et al., 2016 JPO formula}}
\DoxyCodeLine{754           langenhk = min(2.25, 1. + 1./cs\%La\_SL(i,j))}
\DoxyCodeLine{755         \textcolor{keywordflow}{else}}
\DoxyCodeLine{756            \textcolor{comment}{!This shouldn't be reached.}}
\DoxyCodeLine{757            \textcolor{comment}{!call MOM\_error(WARNING,"Unexpected behavior in MOM\_CVMix\_KPP, see error in LT\_K\_ENHANCEMENT")}}
\DoxyCodeLine{758            langenhk = 1.0}
\DoxyCodeLine{759 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{760         \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{761           \textcolor{keywordflow}{if} (cs\%LT\_K\_SHAPE== lt\_k\_constant) \textcolor{keywordflow}{then}}
\DoxyCodeLine{762             \textcolor{keywordflow}{if} (cs\%id\_EnhK > 0) cs\%EnhK(i,j,:) = langenhk}
\DoxyCodeLine{763             kdiffusivity(k,1) = kdiffusivity(k,1) * langenhk}
\DoxyCodeLine{764             kdiffusivity(k,2) = kdiffusivity(k,2) * langenhk}
\DoxyCodeLine{765             kviscosity(k)     = kviscosity(k)   * langenhk}
\DoxyCodeLine{766           \textcolor{keywordflow}{elseif} (cs\%LT\_K\_SHAPE == lt\_k\_scaled) \textcolor{keywordflow}{then}}
\DoxyCodeLine{767             sigma = min(1.0,-\/ifaceheight(k)/cs\%OBLdepth(i,j))}
\DoxyCodeLine{768             sigmaratio = sigma * (1. -\/ sigma)**2 / 0.148148037}
\DoxyCodeLine{769             \textcolor{keywordflow}{if} (cs\%id\_EnhK > 0) cs\%EnhK(i,j,k) = (1.0 + (langenhk -\/ 1.)*sigmaratio)}
\DoxyCodeLine{770             kdiffusivity(k,1) = kdiffusivity(k,1) * ( 1. + \&}
\DoxyCodeLine{771                                 ( langenhk -\/ 1.)*sigmaratio)}
\DoxyCodeLine{772             kdiffusivity(k,2) = kdiffusivity(k,2) * ( 1. + \&}
\DoxyCodeLine{773                                 ( langenhk -\/ 1.)*sigmaratio)}
\DoxyCodeLine{774             kviscosity(k) = kviscosity(k) * ( 1. + \&}
\DoxyCodeLine{775                                 ( langenhk -\/ 1.)*sigmaratio)}
\DoxyCodeLine{776 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{777 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{778 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{779 }
\DoxyCodeLine{780       \textcolor{comment}{! Over-\/write CVMix NLT shape function with one of the following choices.}}
\DoxyCodeLine{781       \textcolor{comment}{! The CVMix code has yet to update for thse options, so we compute in MOM6.}}
\DoxyCodeLine{782       \textcolor{comment}{! Note that nonLocalTrans = Cs * G(sigma) (LMD94 notation), with}}
\DoxyCodeLine{783       \textcolor{comment}{! Cs = 6.32739901508.}}
\DoxyCodeLine{784       \textcolor{comment}{! Start do-\/loop at k=2, since k=1 is ocean surface (sigma=0)}}
\DoxyCodeLine{785       \textcolor{comment}{! and we do not wish to double-\/count the surface forcing.}}
\DoxyCodeLine{786       \textcolor{comment}{! Only compute nonlocal transport for 0 <= sigma <= 1.}}
\DoxyCodeLine{787       \textcolor{comment}{! MOM6 recommended shape is the parabolic; it gives deeper boundary layer}}
\DoxyCodeLine{788       \textcolor{comment}{! and no spurious extrema.}}
\DoxyCodeLine{789       \textcolor{keywordflow}{if} (surfbuoyflux < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{790         \textcolor{keywordflow}{if} (cs\%NLT\_shape == nlt\_shape\_cubic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{791           \textcolor{keywordflow}{do} k = 2, g\%ke}
\DoxyCodeLine{792             sigma = min(1.0,-\/ifaceheight(k)/cs\%OBLdepth(i,j))}
\DoxyCodeLine{793             nonlocaltrans(k,1) = (1.0 -\/ sigma)**2 * (1.0 + 2.0*sigma) \textcolor{comment}{!*}}
\DoxyCodeLine{794             nonlocaltrans(k,2) = nonlocaltrans(k,1)}
\DoxyCodeLine{795 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{796         \textcolor{keywordflow}{elseif} (cs\%NLT\_shape == nlt\_shape\_parabolic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{797           \textcolor{keywordflow}{do} k = 2, g\%ke}
\DoxyCodeLine{798             sigma = min(1.0,-\/ifaceheight(k)/cs\%OBLdepth(i,j))}
\DoxyCodeLine{799             nonlocaltrans(k,1) = (1.0 -\/ sigma)**2 \textcolor{comment}{!*CS\%CS2}}
\DoxyCodeLine{800             nonlocaltrans(k,2) = nonlocaltrans(k,1)}
\DoxyCodeLine{801 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{802         \textcolor{keywordflow}{elseif} (cs\%NLT\_shape == nlt\_shape\_linear) \textcolor{keywordflow}{then}}
\DoxyCodeLine{803           \textcolor{keywordflow}{do} k = 2, g\%ke}
\DoxyCodeLine{804             sigma = min(1.0,-\/ifaceheight(k)/cs\%OBLdepth(i,j))}
\DoxyCodeLine{805             nonlocaltrans(k,1) = (1.0 -\/ sigma)\textcolor{comment}{!*CS\%CS2}}
\DoxyCodeLine{806             nonlocaltrans(k,2) = nonlocaltrans(k,1)}
\DoxyCodeLine{807 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{808         \textcolor{keywordflow}{elseif} (cs\%NLT\_shape == nlt\_shape\_cubic\_lmd) \textcolor{keywordflow}{then}}
\DoxyCodeLine{809           \textcolor{comment}{! Sanity check (should agree with CVMix result using simple matching)}}
\DoxyCodeLine{810           \textcolor{keywordflow}{do} k = 2, g\%ke}
\DoxyCodeLine{811             sigma = min(1.0,-\/ifaceheight(k)/cs\%OBLdepth(i,j))}
\DoxyCodeLine{812             nonlocaltrans(k,1) = cs\%CS2 * sigma*(1.0 -\/sigma)**2}
\DoxyCodeLine{813             nonlocaltrans(k,2) = nonlocaltrans(k,1)}
\DoxyCodeLine{814 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{815 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{816 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{817 }
\DoxyCodeLine{818       \textcolor{comment}{! we apply nonLocalTrans in subroutines}}
\DoxyCodeLine{819       \textcolor{comment}{! KPP\_NonLocalTransport\_temp and KPP\_NonLocalTransport\_saln}}
\DoxyCodeLine{820       nonlocaltransheat(i,j,:)   = nonlocaltrans(:,1) \textcolor{comment}{! temp}}
\DoxyCodeLine{821       nonlocaltransscalar(i,j,:) = nonlocaltrans(:,2) \textcolor{comment}{! saln}}
\DoxyCodeLine{822 }
\DoxyCodeLine{823       \textcolor{comment}{! set the KPP diffusivity and viscosity to zero for testing purposes}}
\DoxyCodeLine{824       \textcolor{keywordflow}{if} (cs\%KPPzeroDiffusivity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{825          kdiffusivity(:,1) = 0.0}
\DoxyCodeLine{826          kdiffusivity(:,2) = 0.0}
\DoxyCodeLine{827          kviscosity(:)     = 0.0}
\DoxyCodeLine{828 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{829 }
\DoxyCodeLine{830 }
\DoxyCodeLine{831       \textcolor{comment}{! compute unresolved squared velocity for diagnostics}}
\DoxyCodeLine{832       \textcolor{keywordflow}{if} (cs\%id\_Vt2 > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{833 \textcolor{comment}{!BGR Now computing VT2 above so can modify for LT}}
\DoxyCodeLine{834 \textcolor{comment}{!    therefore, don't repeat this operation here}}
\DoxyCodeLine{835 \textcolor{comment}{!        CS\%Vt2(i,j,:) = CVmix\_kpp\_compute\_unresolved\_shear( \&}}
\DoxyCodeLine{836 \textcolor{comment}{!                    cellHeight(1:G\%ke),                 \& ! Depth of cell center [m]}}
\DoxyCodeLine{837 \textcolor{comment}{!                    ws\_cntr=Ws\_1d,                      \& ! Turbulent velocity scale profile, at centers [m s-\/1]}}
\DoxyCodeLine{838 \textcolor{comment}{!                    N\_iface=CS\%N(i,j,:),                \& ! Buoyancy frequency at interface [s-\/1]}}
\DoxyCodeLine{839 \textcolor{comment}{!                    CVmix\_kpp\_params\_user=CS\%KPP\_params ) ! KPP parameters}}
\DoxyCodeLine{840 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{841 }
\DoxyCodeLine{842       \textcolor{comment}{! Copy 1d data into 3d diagnostic arrays}}
\DoxyCodeLine{843       \textcolor{comment}{!/ grabbing obldepth\_0d for next time step.}}
\DoxyCodeLine{844       cs\%OBLdepthprev(i,j)=cs\%OBLdepth(i,j)}
\DoxyCodeLine{845       \textcolor{keywordflow}{if} (cs\%id\_sigma > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{846         cs\%sigma(i,j,:)  = 0.}
\DoxyCodeLine{847         \textcolor{keywordflow}{if} (cs\%OBLdepth(i,j)>0.)   cs\%sigma(i,j,:)  = -\/ifaceheight/cs\%OBLdepth(i,j)}
\DoxyCodeLine{848 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{849       \textcolor{keywordflow}{if} (cs\%id\_Kt\_KPP > 0)   cs\%Kt\_KPP(i,j,:) = kdiffusivity(:,1)}
\DoxyCodeLine{850       \textcolor{keywordflow}{if} (cs\%id\_Ks\_KPP > 0)   cs\%Ks\_KPP(i,j,:) = kdiffusivity(:,2)}
\DoxyCodeLine{851       \textcolor{keywordflow}{if} (cs\%id\_Kv\_KPP > 0)   cs\%Kv\_KPP(i,j,:) = kviscosity(:)}
\DoxyCodeLine{852 }
\DoxyCodeLine{853       \textcolor{comment}{! Update output of routine}}
\DoxyCodeLine{854       \textcolor{keywordflow}{if} (.not. cs\%passiveMode) \textcolor{keywordflow}{then}}
\DoxyCodeLine{855         \textcolor{keywordflow}{if} (cs\%KPPisAdditive) \textcolor{keywordflow}{then}}
\DoxyCodeLine{856           \textcolor{keywordflow}{do} k=1, g\%ke+1}
\DoxyCodeLine{857             kt(i,j,k) = kt(i,j,k) + us\%m2\_s\_to\_Z2\_T * kdiffusivity(k,1)}
\DoxyCodeLine{858             ks(i,j,k) = ks(i,j,k) + us\%m2\_s\_to\_Z2\_T * kdiffusivity(k,2)}
\DoxyCodeLine{859             kv(i,j,k) = kv(i,j,k) + us\%m2\_s\_to\_Z2\_T * kviscosity(k)}
\DoxyCodeLine{860             \textcolor{keywordflow}{if} (cs\%Stokes\_Mixing) waves\%KvS(i,j,k) = kv(i,j,k)}
\DoxyCodeLine{861 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{862         \textcolor{keywordflow}{else} \textcolor{comment}{! KPP replaces prior diffusivity when former is non-\/zero}}
\DoxyCodeLine{863           \textcolor{keywordflow}{do} k=1, g\%ke+1}
\DoxyCodeLine{864             \textcolor{keywordflow}{if} (kdiffusivity(k,1) /= 0.) kt(i,j,k) = us\%m2\_s\_to\_Z2\_T * kdiffusivity(k,1)}
\DoxyCodeLine{865             \textcolor{keywordflow}{if} (kdiffusivity(k,2) /= 0.) ks(i,j,k) = us\%m2\_s\_to\_Z2\_T * kdiffusivity(k,2)}
\DoxyCodeLine{866             \textcolor{keywordflow}{if} (kviscosity(k) /= 0.) kv(i,j,k) = us\%m2\_s\_to\_Z2\_T * kviscosity(k)}
\DoxyCodeLine{867             \textcolor{keywordflow}{if} (cs\%Stokes\_Mixing) waves\%KvS(i,j,k) = kv(i,j,k)}
\DoxyCodeLine{868 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{869 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{870 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{871 }
\DoxyCodeLine{872 }
\DoxyCodeLine{873     \textcolor{comment}{! end of the horizontal do-\/loops over the vertical columns}}
\DoxyCodeLine{874 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i}}
\DoxyCodeLine{875 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j}}
\DoxyCodeLine{876 }
\DoxyCodeLine{877   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_kpp\_calc)}
\DoxyCodeLine{878 }
\DoxyCodeLine{879   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{880     \textcolor{keyword}{call }hchksum(kt, \textcolor{stringliteral}{"KPP out: Kt"}, g\%HI, haloshift=0, scale=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{881     \textcolor{keyword}{call }hchksum(ks, \textcolor{stringliteral}{"KPP out: Ks"}, g\%HI, haloshift=0, scale=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{882 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{883 }
\DoxyCodeLine{884   \textcolor{comment}{! send diagnostics to post\_data}}
\DoxyCodeLine{885   \textcolor{keywordflow}{if} (cs\%id\_OBLdepth > 0) \textcolor{keyword}{call }post\_data(cs\%id\_OBLdepth, cs\%OBLdepth,        cs\%diag)}
\DoxyCodeLine{886   \textcolor{keywordflow}{if} (cs\%id\_OBLdepth\_original > 0) \textcolor{keyword}{call }post\_data(cs\%id\_OBLdepth\_original,cs\%OBLdepth\_original,cs\%diag)}
\DoxyCodeLine{887   \textcolor{keywordflow}{if} (cs\%id\_sigma    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_sigma,    cs\%sigma,           cs\%diag)}
\DoxyCodeLine{888   \textcolor{keywordflow}{if} (cs\%id\_Ws       > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Ws,       cs\%Ws,              cs\%diag)}
\DoxyCodeLine{889   \textcolor{keywordflow}{if} (cs\%id\_Vt2      > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Vt2,      cs\%Vt2,             cs\%diag)}
\DoxyCodeLine{890   \textcolor{keywordflow}{if} (cs\%id\_uStar    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uStar,    ustar,              cs\%diag)}
\DoxyCodeLine{891   \textcolor{keywordflow}{if} (cs\%id\_buoyFlux > 0) \textcolor{keyword}{call }post\_data(cs\%id\_buoyFlux, buoyflux,           cs\%diag)}
\DoxyCodeLine{892   \textcolor{keywordflow}{if} (cs\%id\_Kt\_KPP   > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kt\_KPP,   cs\%Kt\_KPP,          cs\%diag)}
\DoxyCodeLine{893   \textcolor{keywordflow}{if} (cs\%id\_Ks\_KPP   > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Ks\_KPP,   cs\%Ks\_KPP,          cs\%diag)}
\DoxyCodeLine{894   \textcolor{keywordflow}{if} (cs\%id\_Kv\_KPP   > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kv\_KPP,   cs\%Kv\_KPP,          cs\%diag)}
\DoxyCodeLine{895   \textcolor{keywordflow}{if} (cs\%id\_NLTt     > 0) \textcolor{keyword}{call }post\_data(cs\%id\_NLTt,     nonlocaltransheat,  cs\%diag)}
\DoxyCodeLine{896   \textcolor{keywordflow}{if} (cs\%id\_NLTs     > 0) \textcolor{keyword}{call }post\_data(cs\%id\_NLTs,     nonlocaltransscalar,cs\%diag)}
\DoxyCodeLine{897 }
\DoxyCodeLine{898 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_aa91f493f6da97da3536d0f4d47cb442c}\label{namespacemom__cvmix__kpp_aa91f493f6da97da3536d0f4d47cb442c}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_compute\_bld@{kpp\_compute\_bld}}
\index{kpp\_compute\_bld@{kpp\_compute\_bld}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_compute\_bld()}{kpp\_compute\_bld()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+compute\+\_\+bld (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{Temp,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{Salt,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{u\+Star,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{buoy\+Flux,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves }\end{DoxyParamCaption})}



Compute O\+BL depth. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer/level thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em temp} & potential/cons temp \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em salt} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Velocity i-\/component \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Velocity j-\/component \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamics structure. \\
\hline
\mbox{\texttt{ in}}  & {\em ustar} & Surface friction velocity \mbox{[}Z T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em buoyflux} & Surface buoyancy flux \mbox{[}L2 T-\/3 $\sim$$>$ m2 s-\/3\mbox{]} \\
\hline
 & {\em waves} & Wave CS \\
\hline
\end{DoxyParams}


Definition at line 903 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{904 }
\DoxyCodeLine{905   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{906   \textcolor{keywordtype}{type}(KPP\_CS),                               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< Control structure}}
\DoxyCodeLine{907   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{     !< Ocean grid}}
\DoxyCodeLine{908   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< Ocean vertical grid}}
\DoxyCodeLine{909   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{910 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer/level thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{911 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: Temp\textcolor{comment}{  !< potential/cons temp [degC]}}
\DoxyCodeLine{912 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: Salt\textcolor{comment}{  !< Salinity [ppt]}}
\DoxyCodeLine{913 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{     !< Velocity i-\/component [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{914 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{     !< Velocity j-\/component [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{915   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                      \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{    !< Thermodynamics structure.}}
\DoxyCodeLine{916 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: uStar\textcolor{comment}{ !< Surface friction velocity [Z T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{917 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: buoyFlux\textcolor{comment}{ !< Surface buoyancy flux [L2 T-\/3 \string~> m2 s-\/3]}}
\DoxyCodeLine{918   \textcolor{keywordtype}{type}(wave\_parameters\_CS),         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{ !< Wave CS}}
\DoxyCodeLine{919 }
\DoxyCodeLine{920   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{921   \textcolor{keywordtype}{integer} :: i, j, k, km1                        \textcolor{comment}{! Loop indices}}
\DoxyCodeLine{922 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: cellHeight      \textcolor{comment}{! Cell center heights referenced to surface [m] (negative in ocean)}}
\DoxyCodeLine{923 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1 )}   :: iFaceHeight     \textcolor{comment}{! Interface heights referenced to surface [m] (negative in ocean)}}
\DoxyCodeLine{924 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1 )}   :: N2\_1d           \textcolor{comment}{! Brunt-\/Vaisala frequency squared, at interfaces [s-\/2]}}
\DoxyCodeLine{925 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: Ws\_1d           \textcolor{comment}{! Profile of vertical velocity scale for scalars [m s-\/1]}}
\DoxyCodeLine{926 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: deltaRho        \textcolor{comment}{! delta Rho in numerator of Bulk Ri number [R \string~> kg m-\/3]}}
\DoxyCodeLine{927 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: deltaU2         \textcolor{comment}{! square of delta U (shear) in denominator of Bulk Ri [m2 s-\/2]}}
\DoxyCodeLine{928 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: surfBuoyFlux2}
\DoxyCodeLine{929 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}     :: BulkRi\_1d       \textcolor{comment}{! Bulk Richardson number for each layer}}
\DoxyCodeLine{930 }
\DoxyCodeLine{931   \textcolor{comment}{! for EOS calculation}}
\DoxyCodeLine{932 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( 3*G\%ke )}   :: rho\_1D   \textcolor{comment}{! A column of densities [R \string~> kg m-\/3]}}
\DoxyCodeLine{933 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( 3*G\%ke )}   :: pres\_1D  \textcolor{comment}{! A column of pressures [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{934 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( 3*G\%ke )}   :: Temp\_1D}
\DoxyCodeLine{935 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( 3*G\%ke )}   :: Salt\_1D}
\DoxyCodeLine{936 }
\DoxyCodeLine{937 \textcolor{keywordtype}{  real} :: surfFricVel, surfBuoyFlux, Coriolis}
\DoxyCodeLine{938 \textcolor{keywordtype}{  real} :: GoRho  \textcolor{comment}{! Gravitational acceleration divided by density in MKS units [m R-\/1 s-\/2 \string~> m4 kg-\/1 s-\/2]}}
\DoxyCodeLine{939 \textcolor{keywordtype}{  real} :: pRef   \textcolor{comment}{! The interface pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{940 \textcolor{keywordtype}{  real} :: rho1, rhoK, Uk, Vk, sigma, sigmaRatio}
\DoxyCodeLine{941 }
\DoxyCodeLine{942 \textcolor{keywordtype}{  real} :: zBottomMinusOffset   \textcolor{comment}{! Height of bottom plus a little bit [m]}}
\DoxyCodeLine{943 \textcolor{keywordtype}{  real} :: SLdepth\_0d           \textcolor{comment}{! Surface layer depth = surf\_layer\_ext*OBLdepth.}}
\DoxyCodeLine{944 \textcolor{keywordtype}{  real} :: hTot                 \textcolor{comment}{! Running sum of thickness used in the surface layer average [m]}}
\DoxyCodeLine{945 \textcolor{keywordtype}{  real} :: buoy\_scale           \textcolor{comment}{! A unit conversion factor for buoyancy fluxes [m2 T3 L-\/2 s-\/3 \string~> nondim]}}
\DoxyCodeLine{946 \textcolor{keywordtype}{  real} :: delH                 \textcolor{comment}{! Thickness of a layer [m]}}
\DoxyCodeLine{947 \textcolor{keywordtype}{  real} :: surfHtemp, surfTemp  \textcolor{comment}{! Integral and average of temp over the surface layer}}
\DoxyCodeLine{948 \textcolor{keywordtype}{  real} :: surfHsalt, surfSalt  \textcolor{comment}{! Integral and average of saln over the surface layer}}
\DoxyCodeLine{949 \textcolor{keywordtype}{  real} :: surfHu, surfU        \textcolor{comment}{! Integral and average of u over the surface layer}}
\DoxyCodeLine{950 \textcolor{keywordtype}{  real} :: surfHv, surfV        \textcolor{comment}{! Integral and average of v over the surface layer}}
\DoxyCodeLine{951 \textcolor{keywordtype}{  real} :: dh    \textcolor{comment}{! The local thickness used for calculating interface positions [m]}}
\DoxyCodeLine{952 \textcolor{keywordtype}{  real} :: hcorr \textcolor{comment}{! A cumulative correction arising from inflation of vanished layers [m]}}
\DoxyCodeLine{953   \textcolor{keywordtype}{integer} :: kk, ksfc, ktmp}
\DoxyCodeLine{954 }
\DoxyCodeLine{955   \textcolor{comment}{! For Langmuir Calculations}}
\DoxyCodeLine{956 \textcolor{keywordtype}{  real} :: LangEnhW     \textcolor{comment}{! Langmuir enhancement for turbulent velocity scale}}
\DoxyCodeLine{957 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%ke)} :: LangEnhVt2   \textcolor{comment}{! Langmuir enhancement for unresolved shear}}
\DoxyCodeLine{958 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%ke)} :: U\_H, V\_H}
\DoxyCodeLine{959 \textcolor{keywordtype}{  real} :: MLD\_GUESS, LA}
\DoxyCodeLine{960 \textcolor{keywordtype}{  real} :: surfHuS, surfHvS, surfUs, surfVs, wavedir, currentdir}
\DoxyCodeLine{961 \textcolor{keywordtype}{  real} :: VarUp, VarDn, M, VarLo, VarAvg}
\DoxyCodeLine{962 \textcolor{keywordtype}{  real} :: H10pct, H20pct,CMNFACT, USx20pct, USy20pct, enhvt2}
\DoxyCodeLine{963   \textcolor{keywordtype}{integer} :: B}
\DoxyCodeLine{964 \textcolor{keywordtype}{  real} :: WST}
\DoxyCodeLine{965 }
\DoxyCodeLine{966 }
\DoxyCodeLine{967   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{968     \textcolor{keyword}{call }hchksum(salt, \textcolor{stringliteral}{"KPP in: S"},g\%HI,haloshift=0)}
\DoxyCodeLine{969     \textcolor{keyword}{call }hchksum(temp, \textcolor{stringliteral}{"KPP in: T"},g\%HI,haloshift=0)}
\DoxyCodeLine{970     \textcolor{keyword}{call }hchksum(u, \textcolor{stringliteral}{"KPP in: u"},g\%HI,haloshift=0)}
\DoxyCodeLine{971     \textcolor{keyword}{call }hchksum(v, \textcolor{stringliteral}{"KPP in: v"},g\%HI,haloshift=0)}
\DoxyCodeLine{972 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{973 }
\DoxyCodeLine{974   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_kpp\_compute\_bld)}
\DoxyCodeLine{975 }
\DoxyCodeLine{976   \textcolor{comment}{! some constants}}
\DoxyCodeLine{977   gorho = us\%L\_T\_to\_m\_s**2*us\%m\_to\_Z * gv\%g\_Earth / gv\%Rho0}
\DoxyCodeLine{978   buoy\_scale = us\%L\_to\_m**2*us\%s\_to\_T**3}
\DoxyCodeLine{979 }
\DoxyCodeLine{980   \textcolor{comment}{! loop over horizontal points on processor}}
\DoxyCodeLine{981   \textcolor{comment}{!\$OMP parallel do default(none) private(surfFricVel, iFaceHeight, hcorr, dh, cellHeight,  \&}}
\DoxyCodeLine{982   \textcolor{comment}{!\$OMP                           surfBuoyFlux, U\_H, V\_H, Coriolis, pRef, SLdepth\_0d,       \&}}
\DoxyCodeLine{983   \textcolor{comment}{!\$OMP                           ksfc, surfHtemp, surfHsalt, surfHu, surfHv, surfHuS,      \&}}
\DoxyCodeLine{984   \textcolor{comment}{!\$OMP                           surfHvS, hTot, delH, surftemp, surfsalt, surfu, surfv,    \&}}
\DoxyCodeLine{985   \textcolor{comment}{!\$OMP                           surfUs, surfVs, Uk, Vk, deltaU2, km1, kk, pres\_1D,        \&}}
\DoxyCodeLine{986   \textcolor{comment}{!\$OMP                           Temp\_1D, salt\_1D, surfBuoyFlux2, MLD\_GUESS, LA, rho\_1D,   \&}}
\DoxyCodeLine{987   \textcolor{comment}{!\$OMP                           deltarho, N2\_1d, ws\_1d, LangEnhVT2, enhvt2, wst,          \&}}
\DoxyCodeLine{988   \textcolor{comment}{!\$OMP                           BulkRi\_1d, zBottomMinusOffset) \&}}
\DoxyCodeLine{989   \textcolor{comment}{!\$OMP                           shared(G, GV, CS, US, uStar, h, buoy\_scale, buoyFlux,     \&}}
\DoxyCodeLine{990   \textcolor{comment}{!\$OMP                           Temp, Salt, waves, tv, GoRho, u, v)}}
\DoxyCodeLine{991   \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{992     \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{993 }
\DoxyCodeLine{994       \textcolor{comment}{! skip calling KPP for land points}}
\DoxyCodeLine{995       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)==0.) cycle}
\DoxyCodeLine{996 }
\DoxyCodeLine{997       \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{998         u\_h(k) = 0.5 * us\%L\_T\_to\_m\_s*(u(i,j,k)+u(i-\/1,j,k))}
\DoxyCodeLine{999         v\_h(k) = 0.5 * us\%L\_T\_to\_m\_s*(v(i,j,k)+v(i,j-\/1,k))}
\DoxyCodeLine{1000 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1001 }
\DoxyCodeLine{1002       \textcolor{comment}{! things independent of position within the column}}
\DoxyCodeLine{1003       coriolis = 0.25*us\%s\_to\_T*( (g\%CoriolisBu(i,j)   + g\%CoriolisBu(i-\/1,j-\/1)) + \&}
\DoxyCodeLine{1004                                   (g\%CoriolisBu(i-\/1,j) + g\%CoriolisBu(i,j-\/1)) )}
\DoxyCodeLine{1005       surffricvel = us\%Z\_to\_m*us\%s\_to\_T * ustar(i,j)}
\DoxyCodeLine{1006 }
\DoxyCodeLine{1007       \textcolor{comment}{! Bullk Richardson number computed for each cell in a column,}}
\DoxyCodeLine{1008       \textcolor{comment}{! assuming OBLdepth = grid cell depth. After Rib(k) is}}
\DoxyCodeLine{1009       \textcolor{comment}{! known for the column, then CVMix interpolates to find}}
\DoxyCodeLine{1010       \textcolor{comment}{! the actual OBLdepth. This approach avoids need to iterate}}
\DoxyCodeLine{1011       \textcolor{comment}{! on the OBLdepth calculation. It follows that used in MOM5}}
\DoxyCodeLine{1012       \textcolor{comment}{! and POP.}}
\DoxyCodeLine{1013       ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}}
\DoxyCodeLine{1014       pref = 0. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%p\_surf)) pref = tv\%p\_surf(i,j)}
\DoxyCodeLine{1015       hcorr = 0.}
\DoxyCodeLine{1016       \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1017 }
\DoxyCodeLine{1018         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}}
\DoxyCodeLine{1019         dh = h(i,j,k) * gv\%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment}}
\DoxyCodeLine{1020         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}}
\DoxyCodeLine{1021         hcorr = min( dh -\/ cs\%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}}
\DoxyCodeLine{1022         dh = max( dh, cs\%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}}
\DoxyCodeLine{1023         cellheight(k)    = ifaceheight(k) -\/ 0.5 * dh}
\DoxyCodeLine{1024         ifaceheight(k+1) = ifaceheight(k) -\/ dh}
\DoxyCodeLine{1025 }
\DoxyCodeLine{1026         \textcolor{comment}{! find ksfc for cell where "surface layer" sits}}
\DoxyCodeLine{1027         sldepth\_0d = cs\%surf\_layer\_ext*max( max(-\/cellheight(k),-\/ifaceheight(2) ), cs\%minOBLdepth )}
\DoxyCodeLine{1028         ksfc = k}
\DoxyCodeLine{1029         \textcolor{keywordflow}{do} ktmp = 1,k}
\DoxyCodeLine{1030           \textcolor{keywordflow}{if} (-\/1.0*ifaceheight(ktmp+1) >= sldepth\_0d) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1031             ksfc = ktmp}
\DoxyCodeLine{1032             \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1033 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1034 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1035 }
\DoxyCodeLine{1036         \textcolor{comment}{! average temp, saln, u, v over surface layer}}
\DoxyCodeLine{1037         \textcolor{comment}{! use C-\/grid average to get u,v on T-\/points.}}
\DoxyCodeLine{1038         surfhtemp=0.0}
\DoxyCodeLine{1039         surfhsalt=0.0}
\DoxyCodeLine{1040         surfhu   =0.0}
\DoxyCodeLine{1041         surfhv   =0.0}
\DoxyCodeLine{1042         surfhus  =0.0}
\DoxyCodeLine{1043         surfhvs  =0.0}
\DoxyCodeLine{1044         htot     =0.0}
\DoxyCodeLine{1045         \textcolor{keywordflow}{do} ktmp = 1,ksfc}
\DoxyCodeLine{1046 }
\DoxyCodeLine{1047           \textcolor{comment}{! SLdepth\_0d can be between cell interfaces}}
\DoxyCodeLine{1048           delh = min( max(0.0, sldepth\_0d -\/ htot), h(i,j,ktmp)*gv\%H\_to\_m )}
\DoxyCodeLine{1049 }
\DoxyCodeLine{1050           \textcolor{comment}{! surface layer thickness}}
\DoxyCodeLine{1051           htot = htot + delh}
\DoxyCodeLine{1052 }
\DoxyCodeLine{1053           \textcolor{comment}{! surface averaged fields}}
\DoxyCodeLine{1054           surfhtemp = surfhtemp + temp(i,j,ktmp) * delh}
\DoxyCodeLine{1055           surfhsalt = surfhsalt + salt(i,j,ktmp) * delh}
\DoxyCodeLine{1056           surfhu    = surfhu + 0.5*us\%L\_T\_to\_m\_s*(u(i,j,ktmp)+u(i-\/1,j,ktmp)) * delh}
\DoxyCodeLine{1057           surfhv    = surfhv + 0.5*us\%L\_T\_to\_m\_s*(v(i,j,ktmp)+v(i,j-\/1,ktmp)) * delh}
\DoxyCodeLine{1058           \textcolor{keywordflow}{if} (cs\%Stokes\_Mixing) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1059             surfhus = surfhus + 0.5*(waves\%US\_x(i,j,ktmp)+waves\%US\_x(i-\/1,j,ktmp)) * delh}
\DoxyCodeLine{1060             surfhvs = surfhvs + 0.5*(waves\%US\_y(i,j,ktmp)+waves\%US\_y(i,j-\/1,ktmp)) * delh}
\DoxyCodeLine{1061 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1062 }
\DoxyCodeLine{1063 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1064         surftemp = surfhtemp / htot}
\DoxyCodeLine{1065         surfsalt = surfhsalt / htot}
\DoxyCodeLine{1066         surfu    = surfhu    / htot}
\DoxyCodeLine{1067         surfv    = surfhv    / htot}
\DoxyCodeLine{1068         surfus   = surfhus   / htot}
\DoxyCodeLine{1069         surfvs   = surfhvs   / htot}
\DoxyCodeLine{1070 }
\DoxyCodeLine{1071         \textcolor{comment}{! vertical shear between present layer and}}
\DoxyCodeLine{1072         \textcolor{comment}{! surface layer averaged surfU,surfV.}}
\DoxyCodeLine{1073         \textcolor{comment}{! C-\/grid average to get Uk and Vk on T-\/points.}}
\DoxyCodeLine{1074         uk         = 0.5*us\%L\_T\_to\_m\_s*(u(i,j,k)+u(i-\/1,j,k)) -\/ surfu}
\DoxyCodeLine{1075         vk         = 0.5*us\%L\_T\_to\_m\_s*(v(i,j,k)+v(i,j-\/1,k)) -\/ surfv}
\DoxyCodeLine{1076 }
\DoxyCodeLine{1077         \textcolor{keywordflow}{if} (cs\%Stokes\_Mixing) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1078           \textcolor{comment}{! If momentum is mixed down the Stokes drift gradient, then}}
\DoxyCodeLine{1079           \textcolor{comment}{!  the Stokes drift must be included in the bulk Richardson number}}
\DoxyCodeLine{1080           \textcolor{comment}{!  calculation.}}
\DoxyCodeLine{1081           uk =  uk + (0.5*(waves\%Us\_x(i,j,k)+waves\%US\_x(i-\/1,j,k)) -\/surfus )}
\DoxyCodeLine{1082           vk =  vk + (0.5*(waves\%Us\_y(i,j,k)+waves\%Us\_y(i,j-\/1,k)) -\/surfvs )}
\DoxyCodeLine{1083 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1084 }
\DoxyCodeLine{1085         deltau2(k) = uk**2 + vk**2}
\DoxyCodeLine{1086 }
\DoxyCodeLine{1087         \textcolor{comment}{! pressure, temp, and saln for EOS}}
\DoxyCodeLine{1088         \textcolor{comment}{! kk+1 = surface fields}}
\DoxyCodeLine{1089         \textcolor{comment}{! kk+2 = k fields}}
\DoxyCodeLine{1090         \textcolor{comment}{! kk+3 = km1 fields}}
\DoxyCodeLine{1091         km1  = max(1, k-\/1)}
\DoxyCodeLine{1092         kk   = 3*(k-\/1)}
\DoxyCodeLine{1093         pres\_1d(kk+1) = pref}
\DoxyCodeLine{1094         pres\_1d(kk+2) = pref}
\DoxyCodeLine{1095         pres\_1d(kk+3) = pref}
\DoxyCodeLine{1096         temp\_1d(kk+1) = surftemp}
\DoxyCodeLine{1097         temp\_1d(kk+2) = temp(i,j,k)}
\DoxyCodeLine{1098         temp\_1d(kk+3) = temp(i,j,km1)}
\DoxyCodeLine{1099         salt\_1d(kk+1) = surfsalt}
\DoxyCodeLine{1100         salt\_1d(kk+2) = salt(i,j,k)}
\DoxyCodeLine{1101         salt\_1d(kk+3) = salt(i,j,km1)}
\DoxyCodeLine{1102 }
\DoxyCodeLine{1103         \textcolor{comment}{! pRef is pressure at interface between k and km1 [R L2 T-\/2 \string~> Pa].}}
\DoxyCodeLine{1104         \textcolor{comment}{! iterate pRef for next pass through k-\/loop.}}
\DoxyCodeLine{1105         pref = pref + (gv\%g\_Earth * gv\%H\_to\_RZ) * h(i,j,k)}
\DoxyCodeLine{1106 }
\DoxyCodeLine{1107         \textcolor{comment}{! this difference accounts for penetrating SW}}
\DoxyCodeLine{1108         surfbuoyflux2(k) = buoy\_scale * (buoyflux(i,j,1) -\/ buoyflux(i,j,k+1))}
\DoxyCodeLine{1109 }
\DoxyCodeLine{1110 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-\/loop finishes}}
\DoxyCodeLine{1111 }
\DoxyCodeLine{1112       \textcolor{keywordflow}{if} (cs\%LT\_K\_ENHANCEMENT .or. cs\%LT\_VT2\_ENHANCEMENT) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1113         mld\_guess = max( 1.*us\%m\_to\_Z, abs(us\%m\_to\_Z*cs\%OBLdepthprev(i,j) ) )}
\DoxyCodeLine{1114         \textcolor{keyword}{call }get\_langmuir\_number(la, g, gv, us, mld\_guess, ustar(i,j), i, j, \&}
\DoxyCodeLine{1115                                  h=h(i,j,:), u\_h=u\_h, v\_h=v\_h, waves=waves)}
\DoxyCodeLine{1116         cs\%La\_SL(i,j)=la}
\DoxyCodeLine{1117 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1118 }
\DoxyCodeLine{1119 }
\DoxyCodeLine{1120       \textcolor{comment}{! compute in-\/situ density}}
\DoxyCodeLine{1121       \textcolor{keyword}{call }calculate\_density(temp\_1d, salt\_1d, pres\_1d, rho\_1d, tv\%eqn\_of\_state)}
\DoxyCodeLine{1122 }
\DoxyCodeLine{1123       \textcolor{comment}{! N2 (can be negative) and N (non-\/negative) on interfaces.}}
\DoxyCodeLine{1124       \textcolor{comment}{! deltaRho is non-\/local rho difference used for bulk Richardson number.}}
\DoxyCodeLine{1125       \textcolor{comment}{! CS\%N is local N (with floor) used for unresolved shear calculation.}}
\DoxyCodeLine{1126       \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1127         km1 = max(1, k-\/1)}
\DoxyCodeLine{1128         kk = 3*(k-\/1)}
\DoxyCodeLine{1129         deltarho(k) = rho\_1d(kk+2) -\/ rho\_1d(kk+1)}
\DoxyCodeLine{1130         n2\_1d(k)    = (gorho * (rho\_1d(kk+2) -\/ rho\_1d(kk+3)) ) / \&}
\DoxyCodeLine{1131                       ((0.5*(h(i,j,km1) + h(i,j,k))+gv\%H\_subroundoff)*gv\%H\_to\_m)}
\DoxyCodeLine{1132         cs\%N(i,j,k)     = sqrt( max( n2\_1d(k), 0.) )}
\DoxyCodeLine{1133 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1134       n2\_1d(g\%ke+1 ) = 0.0}
\DoxyCodeLine{1135       cs\%N(i,j,g\%ke+1 )  = 0.0}
\DoxyCodeLine{1136 }
\DoxyCodeLine{1137       \textcolor{comment}{! turbulent velocity scales w\_s and w\_m computed at the cell centers.}}
\DoxyCodeLine{1138       \textcolor{comment}{! Note that if sigma > CS\%surf\_layer\_ext, then CVMix\_kpp\_compute\_turbulent\_scales}}
\DoxyCodeLine{1139       \textcolor{comment}{! computes w\_s and w\_m velocity scale at sigma=CS\%surf\_layer\_ext. So we only pass}}
\DoxyCodeLine{1140       \textcolor{comment}{! sigma=CS\%surf\_layer\_ext for this calculation.}}
\DoxyCodeLine{1141       \textcolor{keyword}{call }cvmix\_kpp\_compute\_turbulent\_scales( \&}
\DoxyCodeLine{1142         cs\%surf\_layer\_ext, \& \textcolor{comment}{! (in)  Normalized surface layer depth; sigma = CS\%surf\_layer\_ext}}
\DoxyCodeLine{1143         -\/cellheight,       \& \textcolor{comment}{! (in)  Assume here that OBL depth [m] = -\/cellHeight(k)}}
\DoxyCodeLine{1144         surfbuoyflux2,     \& \textcolor{comment}{! (in)  Buoyancy flux at surface [m2 s-\/3]}}
\DoxyCodeLine{1145         surffricvel,       \& \textcolor{comment}{! (in)  Turbulent friction velocity at surface [m s-\/1]}}
\DoxyCodeLine{1146         w\_s=ws\_1d,         \& \textcolor{comment}{! (out) Turbulent velocity scale profile [m s-\/1]}}
\DoxyCodeLine{1147         cvmix\_kpp\_params\_user=cs\%KPP\_params )}
\DoxyCodeLine{1148 }
\DoxyCodeLine{1149       \textcolor{comment}{!Compute CVMix VT2}}
\DoxyCodeLine{1150       cs\%Vt2(i,j,:) = cvmix\_kpp\_compute\_unresolved\_shear( \&}
\DoxyCodeLine{1151                       zt\_cntr=cellheight(1:g\%ke),         \& \textcolor{comment}{! Depth of cell center [m]}}
\DoxyCodeLine{1152                       ws\_cntr=ws\_1d,                      \& \textcolor{comment}{! Turbulent velocity scale profile, at centers [m s-\/1]}}
\DoxyCodeLine{1153                       n\_iface=cs\%N(i,j,:),                \& \textcolor{comment}{! Buoyancy frequency at interface [s-\/1]}}
\DoxyCodeLine{1154                     cvmix\_kpp\_params\_user=cs\%KPP\_params ) \textcolor{comment}{! KPP parameters}}
\DoxyCodeLine{1155 }
\DoxyCodeLine{1156       \textcolor{comment}{!Modify CVMix VT2}}
\DoxyCodeLine{1157       \textcolor{keywordflow}{IF} (cs\%LT\_VT2\_ENHANCEMENT) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1158         \textcolor{keywordflow}{IF} (cs\%LT\_VT2\_METHOD==lt\_vt2\_mode\_constant) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1159           \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1160             langenhvt2(k) = cs\%KPP\_VT2\_ENH\_FAC}
\DoxyCodeLine{1161 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1162         \textcolor{keywordflow}{elseif} (cs\%LT\_VT2\_METHOD==lt\_vt2\_mode\_vr12) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1163           \textcolor{comment}{!Introduced minimum value for La\_SL, so maximum value for enhvt2 is removed.}}
\DoxyCodeLine{1164           enhvt2 = sqrt(1.+(1.5*cs\%La\_SL(i,j))**(-\/2) + \&}
\DoxyCodeLine{1165                    (5.4*cs\%La\_SL(i,j))**(-\/4))}
\DoxyCodeLine{1166           \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1167              langenhvt2(k) = enhvt2}
\DoxyCodeLine{1168 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1169         \textcolor{keywordflow}{elseif} (cs\%LT\_VT2\_METHOD==lt\_vt2\_mode\_rw16) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1170           \textcolor{comment}{!Introduced minimum value for La\_SL, so maximum value for enhvt2 is removed.}}
\DoxyCodeLine{1171           enhvt2 = 1. + 2.3*cs\%La\_SL(i,j)**(-\/0.5)}
\DoxyCodeLine{1172           \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1173             langenhvt2(k) = enhvt2}
\DoxyCodeLine{1174 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1175         \textcolor{keywordflow}{elseif} (cs\%LT\_VT2\_METHOD==lt\_vt2\_mode\_lf17) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1176           cs\%CS=cvmix\_get\_kpp\_real(\textcolor{stringliteral}{'c\_s'},cs\%KPP\_params)}
\DoxyCodeLine{1177           \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1178             wst = (max(0.,-\/buoy\_scale*buoyflux(i,j,1))*(-\/cellheight(k)))**(1./3.)}
\DoxyCodeLine{1179             langenhvt2(k) = sqrt((0.15*wst**3. + 0.17*surffricvel**3.* \&}
\DoxyCodeLine{1180                  (1.+0.49*cs\%La\_SL(i,j)**(-\/2.)))  / \&}
\DoxyCodeLine{1181                  (0.2*ws\_1d(k)**3/(cs\%cs*cs\%surf\_layer\_ext*cs\%vonKarman**4.)))}
\DoxyCodeLine{1182 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1183         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1184            \textcolor{comment}{!This shouldn't be reached.}}
\DoxyCodeLine{1185            \textcolor{comment}{!call MOM\_error(WARNING,"Unexpected behavior in MOM\_CVMix\_KPP, see error in Vt2")}}
\DoxyCodeLine{1186            langenhvt2(:) = 1.0}
\DoxyCodeLine{1187 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1188       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1189         langenhvt2(:) = 1.0}
\DoxyCodeLine{1190 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1191 }
\DoxyCodeLine{1192       \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1193         cs\%Vt2(i,j,k)=cs\%Vt2(i,j,k)*langenhvt2(k)}
\DoxyCodeLine{1194         \textcolor{keywordflow}{if} (cs\%id\_EnhVt2 > 0) cs\%EnhVt2(i,j,k)=langenhvt2(k)}
\DoxyCodeLine{1195 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1196 }
\DoxyCodeLine{1197       \textcolor{comment}{! Calculate Bulk Richardson number from eq (21) of LMD94}}
\DoxyCodeLine{1198       bulkri\_1d = cvmix\_kpp\_compute\_bulk\_richardson( \&}
\DoxyCodeLine{1199                   zt\_cntr = cellheight(1:g\%ke),      \& \textcolor{comment}{! Depth of cell center [m]}}
\DoxyCodeLine{1200                   delta\_buoy\_cntr=gorho*deltarho,    \& \textcolor{comment}{! Bulk buoyancy difference, Br-\/B(z) [s-\/1]}}
\DoxyCodeLine{1201                   delta\_vsqr\_cntr=deltau2,           \& \textcolor{comment}{! Square of resolved velocity difference [m2 s-\/2]}}
\DoxyCodeLine{1202                   vt\_sqr\_cntr=cs\%Vt2(i,j,:),         \&}
\DoxyCodeLine{1203                   ws\_cntr=ws\_1d,                     \& \textcolor{comment}{! Turbulent velocity scale profile [m s-\/1]}}
\DoxyCodeLine{1204                   n\_iface=cs\%N(i,j,:))               \textcolor{comment}{! Buoyancy frequency [s-\/1]}}
\DoxyCodeLine{1205 }
\DoxyCodeLine{1206 }
\DoxyCodeLine{1207       surfbuoyflux = buoy\_scale * buoyflux(i,j,1) \textcolor{comment}{! This is only used in kpp\_compute\_OBL\_depth to limit}}
\DoxyCodeLine{1208                                      \textcolor{comment}{! h to Monin-\/Obukov (default is false, ie. not used)}}
\DoxyCodeLine{1209 }
\DoxyCodeLine{1210       \textcolor{keyword}{call }cvmix\_kpp\_compute\_obl\_depth( \&}
\DoxyCodeLine{1211         bulkri\_1d,              \& \textcolor{comment}{! (in) Bulk Richardson number}}
\DoxyCodeLine{1212         ifaceheight,            \& \textcolor{comment}{! (in) Height of interfaces [m]}}
\DoxyCodeLine{1213         cs\%OBLdepth(i,j),       \& \textcolor{comment}{! (out) OBL depth [m]}}
\DoxyCodeLine{1214         cs\%kOBL(i,j),           \& \textcolor{comment}{! (out) level (+fraction) of OBL extent}}
\DoxyCodeLine{1215         zt\_cntr=cellheight,     \& \textcolor{comment}{! (in) Height of cell centers [m]}}
\DoxyCodeLine{1216         surf\_fric=surffricvel,  \& \textcolor{comment}{! (in) Turbulent friction velocity at surface [m s-\/1]}}
\DoxyCodeLine{1217         surf\_buoy=surfbuoyflux, \& \textcolor{comment}{! (in) Buoyancy flux at surface [m2 s-\/3]}}
\DoxyCodeLine{1218         coriolis=coriolis,      \& \textcolor{comment}{! (in) Coriolis parameter [s-\/1]}}
\DoxyCodeLine{1219         cvmix\_kpp\_params\_user=cs\%KPP\_params ) \textcolor{comment}{! KPP parameters}}
\DoxyCodeLine{1220 }
\DoxyCodeLine{1221       \textcolor{comment}{! A hack to avoid KPP reaching the bottom. It was needed during development}}
\DoxyCodeLine{1222       \textcolor{comment}{! because KPP was unable to handle vanishingly small layers near the bottom.}}
\DoxyCodeLine{1223       \textcolor{keywordflow}{if} (cs\%deepOBLoffset>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1224         zbottomminusoffset = ifaceheight(g\%ke+1) + min(cs\%deepOBLoffset,-\/0.1*ifaceheight(g\%ke+1))}
\DoxyCodeLine{1225         cs\%OBLdepth(i,j) = min( cs\%OBLdepth(i,j), -\/zbottomminusoffset )}
\DoxyCodeLine{1226 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1227 }
\DoxyCodeLine{1228       \textcolor{comment}{! apply some constraints on OBLdepth}}
\DoxyCodeLine{1229       \textcolor{keywordflow}{if}(cs\%fixedOBLdepth)  cs\%OBLdepth(i,j) = cs\%fixedOBLdepth\_value}
\DoxyCodeLine{1230       cs\%OBLdepth(i,j) = max( cs\%OBLdepth(i,j), -\/ifaceheight(2) )      \textcolor{comment}{! no shallower than top layer}}
\DoxyCodeLine{1231       cs\%OBLdepth(i,j) = min( cs\%OBLdepth(i,j), -\/ifaceheight(g\%ke+1) ) \textcolor{comment}{! no deeper than bottom}}
\DoxyCodeLine{1232       cs\%kOBL(i,j)     = cvmix\_kpp\_compute\_kobl\_depth( ifaceheight, cellheight, cs\%OBLdepth(i,j) )}
\DoxyCodeLine{1233 }
\DoxyCodeLine{1234 }
\DoxyCodeLine{1235       \textcolor{comment}{! recompute wscale for diagnostics, now that we in fact know boundary layer depth}}
\DoxyCodeLine{1236       \textcolor{comment}{!BGR consider if LTEnhancement is wanted for diagnostics}}
\DoxyCodeLine{1237       \textcolor{keywordflow}{if} (cs\%id\_Ws > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1238           \textcolor{keyword}{call }cvmix\_kpp\_compute\_turbulent\_scales( \&}
\DoxyCodeLine{1239             -\/cellheight/cs\%OBLdepth(i,j),          \& \textcolor{comment}{! (in)  Normalized boundary layer coordinate}}
\DoxyCodeLine{1240             cs\%OBLdepth(i,j),                      \& \textcolor{comment}{! (in)  OBL depth [m]}}
\DoxyCodeLine{1241             surfbuoyflux,                          \& \textcolor{comment}{! (in)  Buoyancy flux at surface [m2 s-\/3]}}
\DoxyCodeLine{1242             surffricvel,                           \& \textcolor{comment}{! (in)  Turbulent friction velocity at surface [m s-\/1]}}
\DoxyCodeLine{1243             w\_s=ws\_1d,                             \& \textcolor{comment}{! (out) Turbulent velocity scale profile [m s-\/1]}}
\DoxyCodeLine{1244             cvmix\_kpp\_params\_user=cs\%KPP\_params)     \textcolor{comment}{!       KPP parameters}}
\DoxyCodeLine{1245           cs\%Ws(i,j,:) = ws\_1d(:)}
\DoxyCodeLine{1246 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1247 }
\DoxyCodeLine{1248       \textcolor{comment}{! Diagnostics}}
\DoxyCodeLine{1249       \textcolor{keywordflow}{if} (cs\%id\_N2     > 0)   cs\%N2(i,j,:)     = n2\_1d(:)}
\DoxyCodeLine{1250       \textcolor{keywordflow}{if} (cs\%id\_BulkDrho > 0) cs\%dRho(i,j,:)   = deltarho(:)}
\DoxyCodeLine{1251       \textcolor{keywordflow}{if} (cs\%id\_BulkRi > 0)   cs\%BulkRi(i,j,:) = bulkri\_1d(:)}
\DoxyCodeLine{1252       \textcolor{keywordflow}{if} (cs\%id\_BulkUz2 > 0)  cs\%Uz2(i,j,:)    = deltau2(:)}
\DoxyCodeLine{1253       \textcolor{keywordflow}{if} (cs\%id\_Tsurf  > 0)   cs\%Tsurf(i,j)    = surftemp}
\DoxyCodeLine{1254       \textcolor{keywordflow}{if} (cs\%id\_Ssurf  > 0)   cs\%Ssurf(i,j)    = surfsalt}
\DoxyCodeLine{1255       \textcolor{keywordflow}{if} (cs\%id\_Usurf  > 0)   cs\%Usurf(i,j)    = surfu}
\DoxyCodeLine{1256       \textcolor{keywordflow}{if} (cs\%id\_Vsurf  > 0)   cs\%Vsurf(i,j)    = surfv}
\DoxyCodeLine{1257 }
\DoxyCodeLine{1258 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1259 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1260 }
\DoxyCodeLine{1261   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_kpp\_compute\_bld)}
\DoxyCodeLine{1262 }
\DoxyCodeLine{1263   \textcolor{comment}{! send diagnostics to post\_data}}
\DoxyCodeLine{1264   \textcolor{keywordflow}{if} (cs\%id\_BulkRi   > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BulkRi,   cs\%BulkRi,          cs\%diag)}
\DoxyCodeLine{1265   \textcolor{keywordflow}{if} (cs\%id\_N        > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N,        cs\%N,               cs\%diag)}
\DoxyCodeLine{1266   \textcolor{keywordflow}{if} (cs\%id\_N2       > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N2,       cs\%N2,              cs\%diag)}
\DoxyCodeLine{1267   \textcolor{keywordflow}{if} (cs\%id\_Tsurf    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Tsurf,    cs\%Tsurf,           cs\%diag)}
\DoxyCodeLine{1268   \textcolor{keywordflow}{if} (cs\%id\_Ssurf    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Ssurf,    cs\%Ssurf,           cs\%diag)}
\DoxyCodeLine{1269   \textcolor{keywordflow}{if} (cs\%id\_Usurf    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Usurf,    cs\%Usurf,           cs\%diag)}
\DoxyCodeLine{1270   \textcolor{keywordflow}{if} (cs\%id\_Vsurf    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Vsurf,    cs\%Vsurf,           cs\%diag)}
\DoxyCodeLine{1271   \textcolor{keywordflow}{if} (cs\%id\_BulkDrho > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BulkDrho, cs\%dRho,            cs\%diag)}
\DoxyCodeLine{1272   \textcolor{keywordflow}{if} (cs\%id\_BulkUz2  > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BulkUz2,  cs\%Uz2,             cs\%diag)}
\DoxyCodeLine{1273   \textcolor{keywordflow}{if} (cs\%id\_EnhK     > 0) \textcolor{keyword}{call }post\_data(cs\%id\_EnhK,     cs\%EnhK,            cs\%diag)}
\DoxyCodeLine{1274   \textcolor{keywordflow}{if} (cs\%id\_EnhVt2   > 0) \textcolor{keyword}{call }post\_data(cs\%id\_EnhVt2,   cs\%EnhVt2,          cs\%diag)}
\DoxyCodeLine{1275   \textcolor{keywordflow}{if} (cs\%id\_La\_SL    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_La\_SL,    cs\%La\_SL,           cs\%diag)}
\DoxyCodeLine{1276 }
\DoxyCodeLine{1277   \textcolor{comment}{! BLD smoothing:}}
\DoxyCodeLine{1278   \textcolor{keywordflow}{if} (cs\%n\_smooth > 0) \textcolor{keyword}{call }kpp\_smooth\_bld(cs,g,gv,h)}
\DoxyCodeLine{1279 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ab64722f48cd1d20a4c5bfc74ad602326}\label{namespacemom__cvmix__kpp_ab64722f48cd1d20a4c5bfc74ad602326}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_end@{kpp\_end}}
\index{kpp\_end@{kpp\_end}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_end()}{kpp\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clear pointers, deallocate memory. 


\begin{DoxyParams}{Parameters}
{\em cs} & Control structure \\
\hline
\end{DoxyParams}


Definition at line 1513 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1514   \textcolor{keywordtype}{type}(KPP\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Control structure}}
\DoxyCodeLine{1515 }
\DoxyCodeLine{1516   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1517 }
\DoxyCodeLine{1518   \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1519 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_abcb80984f564e5aaf4567aaead111734}\label{namespacemom__cvmix__kpp_abcb80984f564e5aaf4567aaead111734}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_get\_bld@{kpp\_get\_bld}}
\index{kpp\_get\_bld@{kpp\_get\_bld}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_get\_bld()}{kpp\_get\_bld()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+get\+\_\+bld (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{B\+LD,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in), optional}]{m\+\_\+to\+\_\+\+B\+L\+D\+\_\+units }\end{DoxyParamCaption})}



Copies K\+PP surface boundary layer depth into B\+LD, in units of \mbox{[}Z $\sim$$>$ m\mbox{]} unless other units are specified. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure for this module \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em bld} & Boundary layer depth \mbox{[}Z $\sim$$>$ m\mbox{]} or other units \\
\hline
\mbox{\texttt{ in}}  & {\em m\+\_\+to\+\_\+bld\+\_\+units} & A conversion factor from meters to the desired units for B\+LD \\
\hline
\end{DoxyParams}


Definition at line 1366 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1367   \textcolor{keywordtype}{type}(KPP\_CS),                     \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{  !< Control structure for}}
\DoxyCodeLine{1368 \textcolor{comment}{                                                       !! this module}}
\DoxyCodeLine{1369   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{   !< Grid structure}}
\DoxyCodeLine{1370   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{1371 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: BLD\textcolor{comment}{ !< Boundary layer depth [Z \string~> m] or other units}}
\DoxyCodeLine{1372 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: m\_to\_BLD\_units\textcolor{comment}{ !< A conversion factor from meters}}
\DoxyCodeLine{1373 \textcolor{comment}{                                                       !! to the desired units for BLD}}
\DoxyCodeLine{1374   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1375 \textcolor{keywordtype}{  real} :: scale  \textcolor{comment}{! A dimensional rescaling factor}}
\DoxyCodeLine{1376   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{1377 }
\DoxyCodeLine{1378   scale = us\%m\_to\_Z ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(m\_to\_bld\_units)) scale = m\_to\_bld\_units}
\DoxyCodeLine{1379 }
\DoxyCodeLine{1380   \textcolor{comment}{!\$OMP parallel do default(none) shared(BLD, CS, G, scale)}}
\DoxyCodeLine{1381   \textcolor{keywordflow}{do} j = g\%jsc, g\%jec ; \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1382     bld(i,j) = scale * cs\%OBLdepth(i,j)}
\DoxyCodeLine{1383 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1384 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ada767f6da63b74348a7461eb1d12c5d6}\label{namespacemom__cvmix__kpp_ada767f6da63b74348a7461eb1d12c5d6}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_init@{kpp\_init}}
\index{kpp\_init@{kpp\_init}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_init()}{kpp\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+init (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+File,  }\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(diag\+\_\+ctrl), intent(in), target}]{diag,  }\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), pointer}]{CS,  }\item[{logical, intent(out), optional}]{passive,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves }\end{DoxyParamCaption})}



Initialize the C\+V\+Mix K\+PP module and set up diagnostics Returns True if K\+PP is to be used, False otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em paramfile} & File parser \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em diag} & Diagnostics \\
\hline
\mbox{\texttt{ in}}  & {\em time} & Model time \\
\hline
 & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ out}}  & {\em passive} & Copy of passive\+Mode \\
\hline
 & {\em waves} & Wave CS \\
\hline
\end{DoxyParams}


Definition at line 184 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{185 }
\DoxyCodeLine{186   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{187   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: paramFile\textcolor{comment}{ !< File parser}}
\DoxyCodeLine{188   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{         !< Ocean grid}}
\DoxyCodeLine{189   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{        !< Vertical grid structure.}}
\DoxyCodeLine{190   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{        !< A dimensional unit scaling type}}
\DoxyCodeLine{191   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: diag\textcolor{comment}{      !< Diagnostics}}
\DoxyCodeLine{192   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{      !< Model time}}
\DoxyCodeLine{193   \textcolor{keywordtype}{type}(KPP\_CS),            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{        !< Control structure}}
\DoxyCodeLine{194   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: passive\textcolor{comment}{   !< Copy of \%passiveMode}}
\DoxyCodeLine{195   \textcolor{keywordtype}{type}(wave\_parameters\_CS), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: Waves\textcolor{comment}{ !< Wave CS}}
\DoxyCodeLine{196 }
\DoxyCodeLine{197   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{198 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{199 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)} :: mdl = \textcolor{stringliteral}{'MOM\_CVMix\_KPP'}\textcolor{comment}{ !< name of this module}}
\DoxyCodeLine{200   \textcolor{keywordtype}{character(len=20)} :: string\textcolor{comment}{          !< local temporary string}}
\DoxyCodeLine{201   \textcolor{keywordtype}{logical} :: CS\_IS\_ONE=.false.         \textcolor{comment}{!< Logical for setting Cs based on Non-\/local}}
\DoxyCodeLine{202   \textcolor{keywordtype}{logical} :: lnoDGat1=.false.          \textcolor{comment}{!< True => G'(1) = 0 (shape function)}}
\DoxyCodeLine{203 \textcolor{comment}{                                       !! False => compute G'(1) as in LMD94}}
\DoxyCodeLine{204   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'MOM\_CVMix\_KPP, KPP\_init: '}// \&}
\DoxyCodeLine{205            \textcolor{stringliteral}{'Control structure has already been initialized'})}
\DoxyCodeLine{206 }
\DoxyCodeLine{207   \textcolor{comment}{! Read parameters}}
\DoxyCodeLine{208   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP"}, kpp\_init, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{209   \textcolor{keyword}{call }log\_version(paramfile, mdl, version, \textcolor{stringliteral}{'This is the MOM wrapper to CVMix:KPP\(\backslash\)n'} // \&}
\DoxyCodeLine{210             \textcolor{stringliteral}{'See http://cvmix.github.io/'}, all\_default=.not.kpp\_init)}
\DoxyCodeLine{211   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP"}, kpp\_init, \&}
\DoxyCodeLine{212                  \textcolor{stringliteral}{"If true, turns on the [CVMix] KPP scheme of Large et al., 1994, "}// \&}
\DoxyCodeLine{213                  \textcolor{stringliteral}{"to calculate diffusivities and non-\/local transport in the OBL."},     \&}
\DoxyCodeLine{214                  default=.false.)}
\DoxyCodeLine{215   \textcolor{comment}{! Forego remainder of initialization if not using this scheme}}
\DoxyCodeLine{216   \textcolor{keywordflow}{if} (.not. kpp\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{217   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{218 }
\DoxyCodeLine{219   \textcolor{keyword}{call }openparameterblock(paramfile,\textcolor{stringliteral}{'KPP'})}
\DoxyCodeLine{220   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'PASSIVE'}, cs\%passiveMode,           \&}
\DoxyCodeLine{221                  \textcolor{stringliteral}{'If True, puts KPP into a passive-\/diagnostic mode.'}, \&}
\DoxyCodeLine{222                   default=.false.)}
\DoxyCodeLine{223   \textcolor{comment}{!BGR: Note using PASSIVE for KPP creates warning for PASSIVE from Convection}}
\DoxyCodeLine{224   \textcolor{comment}{!     should we create a separate flag?}}
\DoxyCodeLine{225   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(passive)) passive=cs\%passiveMode \textcolor{comment}{! This is passed back to the caller so}}
\DoxyCodeLine{226                                                \textcolor{comment}{! the caller knows to not use KPP output}}
\DoxyCodeLine{227   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'APPLY\_NONLOCAL\_TRANSPORT'}, cs\%applyNonLocalTrans,  \&}
\DoxyCodeLine{228                  \textcolor{stringliteral}{'If True, applies the non-\/local transport to heat and scalars. '}//  \&}
\DoxyCodeLine{229                  \textcolor{stringliteral}{'If False, calculates the non-\/local transport and tendencies but '}//\&}
\DoxyCodeLine{230                  \textcolor{stringliteral}{'purely for diagnostic purposes.'},                                   \&}
\DoxyCodeLine{231                  default=.not. cs\%passiveMode)}
\DoxyCodeLine{232   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'N\_SMOOTH'}, cs\%n\_smooth,  \&}
\DoxyCodeLine{233                  \textcolor{stringliteral}{'The number of times the 1-\/1-\/4-\/1-\/1 Laplacian filter is applied on '}//  \&}
\DoxyCodeLine{234                  \textcolor{stringliteral}{'OBL depth.'},   \&}
\DoxyCodeLine{235                  default=0)}
\DoxyCodeLine{236   \textcolor{keywordflow}{if} (cs\%n\_smooth > g\%domain\%nihalo) \textcolor{keywordflow}{then}}
\DoxyCodeLine{237     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'KPP smoothing number (N\_SMOOTH) cannot be greater than NIHALO.'})}
\DoxyCodeLine{238   \textcolor{keywordflow}{elseif} (cs\%n\_smooth > g\%domain\%njhalo) \textcolor{keywordflow}{then}}
\DoxyCodeLine{239     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'KPP smoothing number (N\_SMOOTH) cannot be greater than NJHALO.'})}
\DoxyCodeLine{240 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{241   \textcolor{keywordflow}{if} (cs\%n\_smooth > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{242     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'DEEPEN\_ONLY\_VIA\_SMOOTHING'}, cs\%deepen\_only,  \&}
\DoxyCodeLine{243                    \textcolor{stringliteral}{'If true, apply OBLdepth smoothing at a cell only if the OBLdepth '}// \&}
\DoxyCodeLine{244                    \textcolor{stringliteral}{'gets deeper via smoothing.'},   \&}
\DoxyCodeLine{245                    default=.false.)}
\DoxyCodeLine{246     id\_clock\_kpp\_smoothing = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean KPP BLD smoothing)'}, grain=clock\_routine)}
\DoxyCodeLine{247 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{248   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'RI\_CRIT'}, cs\%Ri\_crit,                            \&}
\DoxyCodeLine{249                  \textcolor{stringliteral}{'Critical bulk Richardson number used to define depth of the '}// \&}
\DoxyCodeLine{250                  \textcolor{stringliteral}{'surface Ocean Boundary Layer (OBL).'},                            \&}
\DoxyCodeLine{251                  units=\textcolor{stringliteral}{'nondim'}, default=0.3)}
\DoxyCodeLine{252   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'VON\_KARMAN'}, cs\%vonKarman, \&}
\DoxyCodeLine{253                  \textcolor{stringliteral}{'von Karman constant.'},                     \&}
\DoxyCodeLine{254                  units=\textcolor{stringliteral}{'nondim'}, default=0.40)}
\DoxyCodeLine{255   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'ENHANCE\_DIFFUSION'}, cs\%enhance\_diffusion,              \&}
\DoxyCodeLine{256                  \textcolor{stringliteral}{'If True, adds enhanced diffusion at the based of the boundary layer.'}, \&}
\DoxyCodeLine{257                  default=.true.)}
\DoxyCodeLine{258   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'INTERP\_TYPE'}, cs\%interpType,           \&}
\DoxyCodeLine{259                  \textcolor{stringliteral}{'Type of interpolation to determine the OBL depth.\(\backslash\)n'}// \&}
\DoxyCodeLine{260                  \textcolor{stringliteral}{'Allowed types are: linear, quadratic, cubic.'},         \&}
\DoxyCodeLine{261                  default=\textcolor{stringliteral}{'quadratic'})}
\DoxyCodeLine{262   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'INTERP\_TYPE2'}, cs\%interpType2,           \&}
\DoxyCodeLine{263                  \textcolor{stringliteral}{'Type of interpolation to compute diff and visc at OBL\_depth.\(\backslash\)n'}// \&}
\DoxyCodeLine{264                  \textcolor{stringliteral}{'Allowed types are: linear, quadratic, cubic or LMD94.'},         \&}
\DoxyCodeLine{265                  default=\textcolor{stringliteral}{'LMD94'})}
\DoxyCodeLine{266   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'COMPUTE\_EKMAN'}, cs\%computeEkman,             \&}
\DoxyCodeLine{267                  \textcolor{stringliteral}{'If True, limit OBL depth to be no deeper than Ekman depth.'}, \&}
\DoxyCodeLine{268                  default=.false.)}
\DoxyCodeLine{269   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'COMPUTE\_MONIN\_OBUKHOV'}, cs\%computeMoninObukhov, \&}
\DoxyCodeLine{270                  \textcolor{stringliteral}{'If True, limit the OBL depth to be no deeper than '}//          \&}
\DoxyCodeLine{271                  \textcolor{stringliteral}{'Monin-\/Obukhov depth.'},                                          \&}
\DoxyCodeLine{272                  default=.false.)}
\DoxyCodeLine{273   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CS'}, cs\%cs,                        \&}
\DoxyCodeLine{274                  \textcolor{stringliteral}{'Parameter for computing velocity scale function.'}, \&}
\DoxyCodeLine{275                  units=\textcolor{stringliteral}{'nondim'}, default=98.96)}
\DoxyCodeLine{276   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CS2'}, cs\%cs2,                        \&}
\DoxyCodeLine{277                  \textcolor{stringliteral}{'Parameter for computing non-\/local term.'}, \&}
\DoxyCodeLine{278                  units=\textcolor{stringliteral}{'nondim'}, default=6.32739901508)}
\DoxyCodeLine{279   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'DEEP\_OBL\_OFFSET'}, cs\%deepOBLoffset,                             \&}
\DoxyCodeLine{280                  \textcolor{stringliteral}{'If non-\/zero, the distance above the bottom to which the OBL is clipped '}//     \&}
\DoxyCodeLine{281                  \textcolor{stringliteral}{'if it would otherwise reach the bottom. The smaller of this and 0.1D is used.'}, \&}
\DoxyCodeLine{282                  units=\textcolor{stringliteral}{'m'},default=0.)}
\DoxyCodeLine{283   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'FIXED\_OBLDEPTH'}, cs\%fixedOBLdepth,       \&}
\DoxyCodeLine{284                  \textcolor{stringliteral}{'If True, fix the OBL depth to FIXED\_OBLDEPTH\_VALUE '}//  \&}
\DoxyCodeLine{285                  \textcolor{stringliteral}{'rather than using the OBL depth from CVMix. '}//         \&}
\DoxyCodeLine{286                  \textcolor{stringliteral}{'This option is just for testing purposes.'},              \&}
\DoxyCodeLine{287                  default=.false.)}
\DoxyCodeLine{288   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'FIXED\_OBLDEPTH\_VALUE'}, cs\%fixedOBLdepth\_value,  \&}
\DoxyCodeLine{289                  \textcolor{stringliteral}{'Value for the fixed OBL depth when fixedOBLdepth==True. '}//   \&}
\DoxyCodeLine{290                  \textcolor{stringliteral}{'This parameter is for just for testing purposes. '}//          \&}
\DoxyCodeLine{291                  \textcolor{stringliteral}{'It will over-\/ride the OBLdepth computed from CVMix.'},           \&}
\DoxyCodeLine{292                  units=\textcolor{stringliteral}{'m'},default=30.0)}
\DoxyCodeLine{293   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'SURF\_LAYER\_EXTENT'}, cs\%surf\_layer\_ext,   \&}
\DoxyCodeLine{294                  \textcolor{stringliteral}{'Fraction of OBL depth considered in the surface layer.'}, \&}
\DoxyCodeLine{295                  units=\textcolor{stringliteral}{'nondim'},default=0.10)}
\DoxyCodeLine{296   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'MINIMUM\_OBL\_DEPTH'}, cs\%minOBLdepth,                            \&}
\DoxyCodeLine{297                  \textcolor{stringliteral}{'If non-\/zero, a minimum depth to use for KPP OBL depth. Independent of '}//     \&}
\DoxyCodeLine{298                  \textcolor{stringliteral}{'this parameter, the OBL depth is always at least as deep as the first layer.'}, \&}
\DoxyCodeLine{299                  units=\textcolor{stringliteral}{'m'},default=0.)}
\DoxyCodeLine{300   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'MINIMUM\_VT2'}, cs\%minVtsqr,                                   \&}
\DoxyCodeLine{301                  \textcolor{stringliteral}{'Min of the unresolved velocity Vt2 used in Rib CVMix calculation.\(\backslash\)n'}//  \&}
\DoxyCodeLine{302                  \textcolor{stringliteral}{'Scaling: MINIMUM\_VT2 = const1*d*N*ws, with d=1m, N=1e-\/5/s, ws=1e-\/6 m/s.'},    \&}
\DoxyCodeLine{303                  units=\textcolor{stringliteral}{'m2/s2'},default=1e-\/10)}
\DoxyCodeLine{304 }
\DoxyCodeLine{305 \textcolor{comment}{! smg: for removal below}}
\DoxyCodeLine{306   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CORRECT\_SURFACE\_LAYER\_AVERAGE'}, cs\%correctSurfLayerAvg,   \&}
\DoxyCodeLine{307                  \textcolor{stringliteral}{'If true, applies a correction step to the averaging of surface layer '}// \&}
\DoxyCodeLine{308                  \textcolor{stringliteral}{'properties. This option is obsolete.'}, default=.false.)}
\DoxyCodeLine{309   \textcolor{keywordflow}{if} (cs\%correctSurfLayerAvg) \&}
\DoxyCodeLine{310     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'Correct surface layer average disabled in code.  To recover \(\backslash\)n'}// \&}
\DoxyCodeLine{311                        \textcolor{stringliteral}{' feature will require code intervention.'})}
\DoxyCodeLine{312   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'FIRST\_GUESS\_SURFACE\_LAYER\_DEPTH'}, cs\%surfLayerDepth,              \&}
\DoxyCodeLine{313                  \textcolor{stringliteral}{'The first guess at the depth of the surface layer used for averaging '}//         \&}
\DoxyCodeLine{314                  \textcolor{stringliteral}{'the surface layer properties. If =0, the top model level properties '}//          \&}
\DoxyCodeLine{315                  \textcolor{stringliteral}{'will be used for the surface layer. If CORRECT\_SURFACE\_LAYER\_AVERAGE=True, a '}// \&}
\DoxyCodeLine{316                  \textcolor{stringliteral}{'subsequent correction is applied. This parameter is obsolete'}, units=\textcolor{stringliteral}{'m'}, default=0.)}
\DoxyCodeLine{317 \textcolor{comment}{! smg: for removal above}}
\DoxyCodeLine{318 }
\DoxyCodeLine{319   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'NLT\_SHAPE'}, string, \&}
\DoxyCodeLine{320                  \textcolor{stringliteral}{'MOM6 method to set nonlocal transport profile. '}//                          \&}
\DoxyCodeLine{321                  \textcolor{stringliteral}{'Over-\/rides the result from CVMix.  Allowed values are: \(\backslash\)n'}//                 \&}
\DoxyCodeLine{322                  \textcolor{stringliteral}{'\(\backslash\)t CVMix     -\/ Uses the profiles from CVMix specified by MATCH\_TECHNIQUE\(\backslash\)n'}//\&}
\DoxyCodeLine{323                  \textcolor{stringliteral}{'\(\backslash\)t LINEAR    -\/ A linear profile, 1-\/sigma\(\backslash\)n'}//                                \&}
\DoxyCodeLine{324                  \textcolor{stringliteral}{'\(\backslash\)t PARABOLIC -\/ A parablic profile, (1-\/sigma)\string^2\(\backslash\)n'}//                          \&}
\DoxyCodeLine{325                  \textcolor{stringliteral}{'\(\backslash\)t CUBIC     -\/ A cubic profile, (1-\/sigma)\string^2(1+2*sigma)\(\backslash\)n'}//                  \&}
\DoxyCodeLine{326                  \textcolor{stringliteral}{'\(\backslash\)t CUBIC\_LMD -\/ The original KPP profile'},                                    \&}
\DoxyCodeLine{327                  default=\textcolor{stringliteral}{'CVMix'})}
\DoxyCodeLine{328   \textcolor{keywordflow}{select case} ( trim(string) )}
\DoxyCodeLine{329     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CVMix"})     ; cs\%NLT\_shape = nlt\_shape\_cvmix}
\DoxyCodeLine{330     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"LINEAR"})    ; cs\%NLT\_shape = nlt\_shape\_linear}
\DoxyCodeLine{331     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PARABOLIC"}) ; cs\%NLT\_shape = nlt\_shape\_parabolic}
\DoxyCodeLine{332     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CUBIC"})     ; cs\%NLT\_shape = nlt\_shape\_cubic}
\DoxyCodeLine{333     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CUBIC\_LMD"}) ; cs\%NLT\_shape = nlt\_shape\_cubic\_lmd}
\DoxyCodeLine{334 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}// \&}
\DoxyCodeLine{335                    \textcolor{stringliteral}{"Unrecognized NLT\_SHAPE option"}//trim(string))}
\DoxyCodeLine{336 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{337   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'MATCH\_TECHNIQUE'}, cs\%MatchTechnique,                                    \&}
\DoxyCodeLine{338                  \textcolor{stringliteral}{'CVMix method to set profile function for diffusivity and NLT, '}//                      \&}
\DoxyCodeLine{339                  \textcolor{stringliteral}{'as well as matching across OBL base. Allowed values are: \(\backslash\)n'}//                          \&}
\DoxyCodeLine{340                  \textcolor{stringliteral}{'\(\backslash\)t SimpleShapes      = sigma*(1-\/sigma)\string^2 for both diffusivity and NLT\(\backslash\)n'}//              \&}
\DoxyCodeLine{341                  \textcolor{stringliteral}{'\(\backslash\)t MatchGradient     = sigma*(1-\/sigma)\string^2 for NLT; diffusivity profile from matching\(\backslash\)n'}//\&}
\DoxyCodeLine{342                  \textcolor{stringliteral}{'\(\backslash\)t MatchBoth         = match gradient for both diffusivity and NLT\(\backslash\)n'}//                 \&}
\DoxyCodeLine{343                  \textcolor{stringliteral}{'\(\backslash\)t ParabolicNonLocal = sigma*(1-\/sigma)\string^2 for diffusivity; (1-\/sigma)\string^2 for NLT'},         \&}
\DoxyCodeLine{344                  default=\textcolor{stringliteral}{'SimpleShapes'})}
\DoxyCodeLine{345   \textcolor{keywordflow}{if} (cs\%MatchTechnique == \textcolor{stringliteral}{'ParabolicNonLocal'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{346     \textcolor{comment}{! This forces Cs2 (Cs in non-\/local computation) to equal 1 for parabolic non-\/local option.}}
\DoxyCodeLine{347     \textcolor{comment}{!  May be used during CVMix initialization.}}
\DoxyCodeLine{348     cs\_is\_one=.true.}
\DoxyCodeLine{349 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{350   \textcolor{keywordflow}{if} (cs\%MatchTechnique == \textcolor{stringliteral}{'ParabolicNonLocal'} .or. cs\%MatchTechnique == \textcolor{stringliteral}{'SimpleShapes'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{351     \textcolor{comment}{! if gradient won't be matched, lnoDGat1=.true.}}
\DoxyCodeLine{352     lnodgat1=.true.}
\DoxyCodeLine{353 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{354 }
\DoxyCodeLine{355   \textcolor{comment}{! safety check to avoid negative diff/visc}}
\DoxyCodeLine{356   \textcolor{keywordflow}{if} (cs\%MatchTechnique == \textcolor{stringliteral}{'MatchBoth'} .and. (cs\%interpType2 == \textcolor{stringliteral}{'cubic'} .or. \&}
\DoxyCodeLine{357       cs\%interpType2 == \textcolor{stringliteral}{'quadratic'})) \textcolor{keywordflow}{then}}
\DoxyCodeLine{358     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"If MATCH\_TECHNIQUE=MatchBoth, INTERP\_TYPE2 must be set to \(\backslash\)n"}//\&}
\DoxyCodeLine{359                \textcolor{stringliteral}{"linear or LMD94 (recommended) to avoid negative viscosity and diffusivity.\(\backslash\)n"}//\&}
\DoxyCodeLine{360                \textcolor{stringliteral}{"Please select one of these valid options."} )}
\DoxyCodeLine{361 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{362 }
\DoxyCodeLine{363   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_ZERO\_DIFFUSIVITY'}, cs\%KPPzeroDiffusivity,            \&}
\DoxyCodeLine{364                  \textcolor{stringliteral}{'If True, zeroes the KPP diffusivity and viscosity; for testing purpose.'},\&}
\DoxyCodeLine{365                  default=.false.)}
\DoxyCodeLine{366   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_IS\_ADDITIVE'}, cs\%KPPisAdditive,                \&}
\DoxyCodeLine{367                  \textcolor{stringliteral}{'If true, adds KPP diffusivity to diffusivity from other schemes.\(\backslash\)n'}//\&}
\DoxyCodeLine{368                  \textcolor{stringliteral}{'If false, KPP is the only diffusivity wherever KPP is non-\/zero.'},  \&}
\DoxyCodeLine{369                  default=.true.)}
\DoxyCodeLine{370   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_SHORTWAVE\_METHOD'},string,                      \&}
\DoxyCodeLine{371                  \textcolor{stringliteral}{'Determines contribution of shortwave radiation to KPP surface '}// \&}
\DoxyCodeLine{372                  \textcolor{stringliteral}{'buoyancy flux.  Options include:\(\backslash\)n'}//                             \&}
\DoxyCodeLine{373                  \textcolor{stringliteral}{'  ALL\_SW: use total shortwave radiation\(\backslash\)n'}//                      \&}
\DoxyCodeLine{374                  \textcolor{stringliteral}{'  MXL\_SW: use shortwave radiation absorbed by mixing layer\(\backslash\)n'}//  \&}
\DoxyCodeLine{375                  \textcolor{stringliteral}{'  LV1\_SW: use shortwave radiation absorbed by top model layer'},  \&}
\DoxyCodeLine{376                  default=\textcolor{stringliteral}{'MXL\_SW'})}
\DoxyCodeLine{377   \textcolor{keywordflow}{select case} ( trim(string) )}
\DoxyCodeLine{378     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"ALL\_SW"}) ; cs\%SW\_METHOD = sw\_method\_all\_sw}
\DoxyCodeLine{379     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"MXL\_SW"}) ; cs\%SW\_METHOD = sw\_method\_mxl\_sw}
\DoxyCodeLine{380     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"LV1\_SW"}) ; cs\%SW\_METHOD = sw\_method\_lv1\_sw}
\DoxyCodeLine{381 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}// \&}
\DoxyCodeLine{382                    \textcolor{stringliteral}{"Unrecognized KPP\_SHORTWAVE\_METHOD option"}//trim(string))}
\DoxyCodeLine{383 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{384   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CVMix\_ZERO\_H\_WORK\_AROUND'}, cs\%min\_thickness,                           \&}
\DoxyCodeLine{385                  \textcolor{stringliteral}{'A minimum thickness used to avoid division by small numbers in the vicinity '}//       \&}
\DoxyCodeLine{386                  \textcolor{stringliteral}{'of vanished layers. This is independent of MIN\_THICKNESS used in other parts of MOM.'}, \&}
\DoxyCodeLine{387                  units=\textcolor{stringliteral}{'m'}, default=0.)}
\DoxyCodeLine{388 }
\DoxyCodeLine{389 \textcolor{comment}{!/BGR: New options for including Langmuir effects}}
\DoxyCodeLine{390 \textcolor{comment}{!/ 1. Options related to enhancing the mixing coefficient}}
\DoxyCodeLine{391   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP\_LT\_K"}, cs\%LT\_K\_Enhancement, \&}
\DoxyCodeLine{392        \textcolor{stringliteral}{'Flag for Langmuir turbulence enhancement of turbulent'}//\&}
\DoxyCodeLine{393        \textcolor{stringliteral}{'mixing coefficient.'}, units=\textcolor{stringliteral}{""}, default=.false.)}
\DoxyCodeLine{394   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"STOKES\_MIXING"}, cs\%STOKES\_MIXING, \&}
\DoxyCodeLine{395        \textcolor{stringliteral}{'Flag for Langmuir turbulence enhancement of turbulent'}//\&}
\DoxyCodeLine{396        \textcolor{stringliteral}{'mixing coefficient.'}, units=\textcolor{stringliteral}{""}, default=.false.)}
\DoxyCodeLine{397   \textcolor{keywordflow}{if} (cs\%LT\_K\_Enhancement) \textcolor{keywordflow}{then}}
\DoxyCodeLine{398     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_LT\_K\_SHAPE'}, string,                 \&}
\DoxyCodeLine{399                  \textcolor{stringliteral}{'Vertical dependence of LT enhancement of mixing. '}//     \&}
\DoxyCodeLine{400                  \textcolor{stringliteral}{'Valid options are: \(\backslash\)n'}//                                   \&}
\DoxyCodeLine{401                  \textcolor{stringliteral}{'\(\backslash\)t CONSTANT = Constant value for full OBL\(\backslash\)n'}//             \&}
\DoxyCodeLine{402                  \textcolor{stringliteral}{'\(\backslash\)t SCALED   = Varies based on normalized shape function.'}, \&}
\DoxyCodeLine{403                  default=\textcolor{stringliteral}{'CONSTANT'})}
\DoxyCodeLine{404     \textcolor{keywordflow}{select case} ( trim(string))}
\DoxyCodeLine{405       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CONSTANT"}) ; cs\%LT\_K\_SHAPE = lt\_k\_constant}
\DoxyCodeLine{406       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"SCALED"})   ; cs\%LT\_K\_SHAPE = lt\_k\_scaled}
\DoxyCodeLine{407 \textcolor{keywordflow}{      case default} ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}//\&}
\DoxyCodeLine{408                     \textcolor{stringliteral}{"Unrecognized KPP\_LT\_K\_SHAPE option: "}//trim(string))}
\DoxyCodeLine{409 \textcolor{keywordflow}{    end select}}
\DoxyCodeLine{410     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_LT\_K\_METHOD"}, string ,                   \&}
\DoxyCodeLine{411                    \textcolor{stringliteral}{'Method to enhance mixing coefficient in KPP. '}//           \&}
\DoxyCodeLine{412                    \textcolor{stringliteral}{'Valid options are: \(\backslash\)n'}//                                     \&}
\DoxyCodeLine{413                    \textcolor{stringliteral}{'\(\backslash\)t CONSTANT = Constant value (KPP\_K\_ENH\_FAC) \(\backslash\)n'}//           \&}
\DoxyCodeLine{414                    \textcolor{stringliteral}{'\(\backslash\)t VR12     = Function of Langmuir number based on VR12\(\backslash\)n'}// \&}
\DoxyCodeLine{415                    \textcolor{stringliteral}{'\(\backslash\)t RW16     = Function of Langmuir number based on RW16'},    \&}
\DoxyCodeLine{416                    default=\textcolor{stringliteral}{'CONSTANT'})}
\DoxyCodeLine{417     \textcolor{keywordflow}{select case} ( trim(string))}
\DoxyCodeLine{418       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CONSTANT"}) ; cs\%LT\_K\_METHOD = lt\_k\_mode\_constant}
\DoxyCodeLine{419       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"VR12"})     ; cs\%LT\_K\_METHOD = lt\_k\_mode\_vr12}
\DoxyCodeLine{420       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"RW16"})     ; cs\%LT\_K\_METHOD = lt\_k\_mode\_rw16}
\DoxyCodeLine{421 \textcolor{keywordflow}{      case default}      ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}//\&}
\DoxyCodeLine{422                     \textcolor{stringliteral}{"Unrecognized KPP\_LT\_K\_METHOD option: "}//trim(string))}
\DoxyCodeLine{423 \textcolor{keywordflow}{    end select}}
\DoxyCodeLine{424     \textcolor{keywordflow}{if} (cs\%LT\_K\_METHOD==lt\_k\_mode\_constant) \textcolor{keywordflow}{then}}
\DoxyCodeLine{425       \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_K\_ENH\_FAC"},cs\%KPP\_K\_ENH\_FAC ,     \&}
\DoxyCodeLine{426                    \textcolor{stringliteral}{'Constant value to enhance mixing coefficient in KPP.'},  \&}
\DoxyCodeLine{427                    default=1.0)}
\DoxyCodeLine{428 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{429 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{430 \textcolor{comment}{!/ 2. Options related to enhancing the unresolved Vt2/entrainment in Rib}}
\DoxyCodeLine{431   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP\_LT\_VT2"}, cs\%LT\_Vt2\_Enhancement, \&}
\DoxyCodeLine{432        \textcolor{stringliteral}{'Flag for Langmuir turbulence enhancement of Vt2'}//\&}
\DoxyCodeLine{433        \textcolor{stringliteral}{'in Bulk Richardson Number.'}, units=\textcolor{stringliteral}{""}, default=.false.)}
\DoxyCodeLine{434   \textcolor{keywordflow}{if} (cs\%LT\_Vt2\_Enhancement) \textcolor{keywordflow}{then}}
\DoxyCodeLine{435     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_LT\_VT2\_METHOD"},string ,                  \&}
\DoxyCodeLine{436                    \textcolor{stringliteral}{'Method to enhance Vt2 in KPP. '}//                          \&}
\DoxyCodeLine{437                    \textcolor{stringliteral}{'Valid options are: \(\backslash\)n'}//                                     \&}
\DoxyCodeLine{438                    \textcolor{stringliteral}{'\(\backslash\)t CONSTANT = Constant value (KPP\_VT2\_ENH\_FAC) \(\backslash\)n'}//         \&}
\DoxyCodeLine{439                    \textcolor{stringliteral}{'\(\backslash\)t VR12     = Function of Langmuir number based on VR12\(\backslash\)n'}// \&}
\DoxyCodeLine{440                    \textcolor{stringliteral}{'\(\backslash\)t RW16     = Function of Langmuir number based on RW16\(\backslash\)n'}// \&}
\DoxyCodeLine{441                    \textcolor{stringliteral}{'\(\backslash\)t LF17     = Function of Langmuir number based on LF17'},    \&}
\DoxyCodeLine{442                    default=\textcolor{stringliteral}{'CONSTANT'})}
\DoxyCodeLine{443     \textcolor{keywordflow}{select case} ( trim(string))}
\DoxyCodeLine{444       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CONSTANT"}) ; cs\%LT\_VT2\_METHOD = lt\_vt2\_mode\_constant}
\DoxyCodeLine{445       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"VR12"})     ; cs\%LT\_VT2\_METHOD = lt\_vt2\_mode\_vr12}
\DoxyCodeLine{446       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"RW16"})     ; cs\%LT\_VT2\_METHOD = lt\_vt2\_mode\_rw16}
\DoxyCodeLine{447       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"LF17"})     ; cs\%LT\_VT2\_METHOD = lt\_vt2\_mode\_lf17}
\DoxyCodeLine{448 \textcolor{keywordflow}{      case default}      ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}//\&}
\DoxyCodeLine{449                     \textcolor{stringliteral}{"Unrecognized KPP\_LT\_VT2\_METHOD option: "}//trim(string))}
\DoxyCodeLine{450 \textcolor{keywordflow}{    end select}}
\DoxyCodeLine{451     \textcolor{keywordflow}{if} (cs\%LT\_VT2\_METHOD==lt\_vt2\_mode\_constant) \textcolor{keywordflow}{then}}
\DoxyCodeLine{452       \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_VT2\_ENH\_FAC"},cs\%KPP\_VT2\_ENH\_FAC ,     \&}
\DoxyCodeLine{453                    \textcolor{stringliteral}{'Constant value to enhance VT2 in KPP.'},  \&}
\DoxyCodeLine{454                    default=1.0)}
\DoxyCodeLine{455 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{456 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{457 }
\DoxyCodeLine{458   \textcolor{keyword}{call }closeparameterblock(paramfile)}
\DoxyCodeLine{459   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'DEBUG'}, cs\%debug, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{460 }
\DoxyCodeLine{461   \textcolor{keyword}{call }cvmix\_init\_kpp( ri\_crit=cs\%Ri\_crit,                 \&}
\DoxyCodeLine{462                        minobldepth=cs\%minOBLdepth,         \&}
\DoxyCodeLine{463                        minvtsqr=cs\%minVtsqr,               \&}
\DoxyCodeLine{464                        vonkarman=cs\%vonKarman,             \&}
\DoxyCodeLine{465                        surf\_layer\_ext=cs\%surf\_layer\_ext,   \&}
\DoxyCodeLine{466                        interp\_type=cs\%interpType,          \&}
\DoxyCodeLine{467                        interp\_type2=cs\%interpType2,        \&}
\DoxyCodeLine{468                        lekman=cs\%computeEkman,             \&}
\DoxyCodeLine{469                        lmonob=cs\%computeMoninObukhov,      \&}
\DoxyCodeLine{470                        matchtechnique=cs\%MatchTechnique,   \&}
\DoxyCodeLine{471                        lenhanced\_diff=cs\%enhance\_diffusion,\&}
\DoxyCodeLine{472                        lnonzero\_surf\_nonlocal=cs\_is\_one   ,\&}
\DoxyCodeLine{473                        lnodgat1=lnodgat1                  ,\&}
\DoxyCodeLine{474                        cvmix\_kpp\_params\_user=cs\%KPP\_params )}
\DoxyCodeLine{475 }
\DoxyCodeLine{476   \textcolor{comment}{! Register diagnostics}}
\DoxyCodeLine{477   cs\%diag => diag}
\DoxyCodeLine{478   cs\%id\_OBLdepth = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_OBLdepth'}, diag\%axesT1, time, \&}
\DoxyCodeLine{479       \textcolor{stringliteral}{'Thickness of the surface Ocean Boundary Layer calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'meter'}, \&}
\DoxyCodeLine{480       cmor\_field\_name=\textcolor{stringliteral}{'oml'}, cmor\_long\_name=\textcolor{stringliteral}{'ocean\_mixed\_layer\_thickness\_defined\_by\_mixing\_scheme'}, \&}
\DoxyCodeLine{481       cmor\_units=\textcolor{stringliteral}{'m'}, cmor\_standard\_name=\textcolor{stringliteral}{'Ocean Mixed Layer Thickness Defined by Mixing Scheme'})}
\DoxyCodeLine{482       \textcolor{comment}{! CMOR names are placeholders; must be modified by time period}}
\DoxyCodeLine{483       \textcolor{comment}{! for CMOR compliance. Diag manager will be used for omlmax and}}
\DoxyCodeLine{484       \textcolor{comment}{! omldamax.}}
\DoxyCodeLine{485   \textcolor{keywordflow}{if} (cs\%n\_smooth > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{486     cs\%id\_OBLdepth\_original = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_OBLdepth\_original'}, diag\%axesT1, time, \&}
\DoxyCodeLine{487         \textcolor{stringliteral}{'Thickness of the surface Ocean Boundary Layer without smoothing calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'meter'}, \&}
\DoxyCodeLine{488         cmor\_field\_name=\textcolor{stringliteral}{'oml'}, cmor\_long\_name=\textcolor{stringliteral}{'ocean\_mixed\_layer\_thickness\_defined\_by\_mixing\_scheme'}, \&}
\DoxyCodeLine{489         cmor\_units=\textcolor{stringliteral}{'m'}, cmor\_standard\_name=\textcolor{stringliteral}{'Ocean Mixed Layer Thickness Defined by Mixing Scheme'})}
\DoxyCodeLine{490 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{491   cs\%id\_BulkDrho = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_BulkDrho'}, diag\%axesTL, time, \&}
\DoxyCodeLine{492       \textcolor{stringliteral}{'Bulk difference in density used in Bulk Richardson number, as used by [CVMix] KPP'}, \&}
\DoxyCodeLine{493       \textcolor{stringliteral}{'kg/m3'}, conversion=us\%R\_to\_kg\_m3)}
\DoxyCodeLine{494   cs\%id\_BulkUz2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_BulkUz2'}, diag\%axesTL, time, \&}
\DoxyCodeLine{495       \textcolor{stringliteral}{'Square of bulk difference in resolved velocity used in Bulk Richardson number via [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s2'})}
\DoxyCodeLine{496   cs\%id\_BulkRi = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_BulkRi'}, diag\%axesTL, time, \&}
\DoxyCodeLine{497       \textcolor{stringliteral}{'Bulk Richardson number used to find the OBL depth used by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{498   cs\%id\_Sigma = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_sigma'}, diag\%axesTi, time, \&}
\DoxyCodeLine{499       \textcolor{stringliteral}{'Sigma coordinate used by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{500   cs\%id\_Ws = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Ws'}, diag\%axesTL, time, \&}
\DoxyCodeLine{501       \textcolor{stringliteral}{'Turbulent vertical velocity scale for scalars used by [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'})}
\DoxyCodeLine{502   cs\%id\_N = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_N'}, diag\%axesTi, time, \&}
\DoxyCodeLine{503       \textcolor{stringliteral}{'(Adjusted) Brunt-\/Vaisala frequency used by [CVMix] KPP'}, \textcolor{stringliteral}{'1/s'})}
\DoxyCodeLine{504   cs\%id\_N2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_N2'}, diag\%axesTi, time, \&}
\DoxyCodeLine{505       \textcolor{stringliteral}{'Square of Brunt-\/Vaisala frequency used by [CVMix] KPP'}, \textcolor{stringliteral}{'1/s2'})}
\DoxyCodeLine{506   cs\%id\_Vt2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Vt2'}, diag\%axesTL, time, \&}
\DoxyCodeLine{507       \textcolor{stringliteral}{'Unresolved shear turbulence used by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s2'})}
\DoxyCodeLine{508   cs\%id\_uStar = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_uStar'}, diag\%axesT1, time, \&}
\DoxyCodeLine{509       \textcolor{stringliteral}{'Friction velocity, u*, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'}, conversion=us\%Z\_to\_m*us\%s\_to\_T)}
\DoxyCodeLine{510   cs\%id\_buoyFlux = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_buoyFlux'}, diag\%axesTi, time, \&}
\DoxyCodeLine{511       \textcolor{stringliteral}{'Surface (and penetrating) buoyancy flux, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s3'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T**3)}
\DoxyCodeLine{512   cs\%id\_QminusSW = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_QminusSW'}, diag\%axesT1, time, \&}
\DoxyCodeLine{513       \textcolor{stringliteral}{'Net temperature flux ignoring short-\/wave, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'K m/s'})}
\DoxyCodeLine{514   cs\%id\_netS = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_netSalt'}, diag\%axesT1, time, \&}
\DoxyCodeLine{515       \textcolor{stringliteral}{'Effective net surface salt flux, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'ppt m/s'})}
\DoxyCodeLine{516   cs\%id\_Kt\_KPP = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Kheat'}, diag\%axesTi, time, \&}
\DoxyCodeLine{517       \textcolor{stringliteral}{'Heat diffusivity due to KPP, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s'})}
\DoxyCodeLine{518   cs\%id\_Kd\_in = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Kd\_in'}, diag\%axesTi, time, \&}
\DoxyCodeLine{519       \textcolor{stringliteral}{'Diffusivity passed to KPP'}, \textcolor{stringliteral}{'m2/s'}, conversion=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{520   cs\%id\_Ks\_KPP = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Ksalt'}, diag\%axesTi, time, \&}
\DoxyCodeLine{521       \textcolor{stringliteral}{'Salt diffusivity due to KPP, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s'})}
\DoxyCodeLine{522   cs\%id\_Kv\_KPP = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Kv'}, diag\%axesTi, time, \&}
\DoxyCodeLine{523       \textcolor{stringliteral}{'Vertical viscosity due to KPP, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s'})}
\DoxyCodeLine{524   cs\%id\_NLTt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLtransport\_heat'}, diag\%axesTi, time, \&}
\DoxyCodeLine{525       \textcolor{stringliteral}{'Non-\/local transport (Cs*G(sigma)) for heat, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{526   cs\%id\_NLTs = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLtransport\_salt'}, diag\%axesTi, time, \&}
\DoxyCodeLine{527       \textcolor{stringliteral}{'Non-\/local tranpsort (Cs*G(sigma)) for scalars, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{528   cs\%id\_NLT\_dTdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_dTdt'}, diag\%axesTL, time, \&}
\DoxyCodeLine{529       \textcolor{stringliteral}{'Temperature tendency due to non-\/local transport of heat, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'K/s'})}
\DoxyCodeLine{530   cs\%id\_NLT\_dSdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_dSdt'}, diag\%axesTL, time, \&}
\DoxyCodeLine{531       \textcolor{stringliteral}{'Salinity tendency due to non-\/local transport of salt, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'ppt/s'})}
\DoxyCodeLine{532   cs\%id\_NLT\_temp\_budget = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_temp\_budget'}, diag\%axesTL, time, \&}
\DoxyCodeLine{533       \textcolor{stringliteral}{'Heat content change due to non-\/local transport, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'W/m\string^2'})}
\DoxyCodeLine{534   cs\%id\_NLT\_saln\_budget = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_saln\_budget'}, diag\%axesTL, time, \&}
\DoxyCodeLine{535       \textcolor{stringliteral}{'Salt content change due to non-\/local transport, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'kg/(sec*m\string^2)'})}
\DoxyCodeLine{536   cs\%id\_Tsurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Tsurf'}, diag\%axesT1, time, \&}
\DoxyCodeLine{537       \textcolor{stringliteral}{'Temperature of surface layer (10\% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'C'})}
\DoxyCodeLine{538   cs\%id\_Ssurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Ssurf'}, diag\%axesT1, time, \&}
\DoxyCodeLine{539       \textcolor{stringliteral}{'Salinity of surface layer (10\% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'ppt'})}
\DoxyCodeLine{540   cs\%id\_Usurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Usurf'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{541       \textcolor{stringliteral}{'i-\/component flow of surface layer (10\% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'})}
\DoxyCodeLine{542   cs\%id\_Vsurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Vsurf'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{543       \textcolor{stringliteral}{'j-\/component flow of surface layer (10\% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'})}
\DoxyCodeLine{544   cs\%id\_EnhK = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'EnhK'}, diag\%axesTI, time, \&}
\DoxyCodeLine{545       \textcolor{stringliteral}{'Langmuir number enhancement to K as used by [CVMix] KPP'},\textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{546   cs\%id\_EnhVt2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'EnhVt2'}, diag\%axesTL, time, \&}
\DoxyCodeLine{547       \textcolor{stringliteral}{'Langmuir number enhancement to Vt2 as used by [CVMix] KPP'},\textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{548   cs\%id\_La\_SL = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_La\_SL'}, diag\%axesT1, time, \&}
\DoxyCodeLine{549       \textcolor{stringliteral}{'Surface-\/layer Langmuir number computed in [CVMix] KPP'},\textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{550 }
\DoxyCodeLine{551   \textcolor{keyword}{allocate}( cs\%N( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{552   cs\%N(:,:,:) = 0.}
\DoxyCodeLine{553   \textcolor{keyword}{allocate}( cs\%OBLdepth( szi\_(g), szj\_(g) ) )}
\DoxyCodeLine{554   cs\%OBLdepth(:,:) = 0.}
\DoxyCodeLine{555   \textcolor{keyword}{allocate}( cs\%kOBL( szi\_(g), szj\_(g) ) )}
\DoxyCodeLine{556   cs\%kOBL(:,:) = 0.}
\DoxyCodeLine{557   \textcolor{keyword}{allocate}( cs\%La\_SL( szi\_(g), szj\_(g) ) )}
\DoxyCodeLine{558   cs\%La\_SL(:,:) = 0.}
\DoxyCodeLine{559   \textcolor{keyword}{allocate}( cs\%Vt2( szi\_(g), szj\_(g), szk\_(g) ) )}
\DoxyCodeLine{560   cs\%Vt2(:,:,:) = 0.}
\DoxyCodeLine{561   \textcolor{keywordflow}{if} (cs\%id\_OBLdepth\_original > 0) \textcolor{keyword}{allocate}( cs\%OBLdepth\_original( szi\_(g), szj\_(g) ) )}
\DoxyCodeLine{562 }
\DoxyCodeLine{563   \textcolor{keyword}{allocate}( cs\%OBLdepthprev( szi\_(g), szj\_(g) ) ) ; cs\%OBLdepthprev(:,:) = 0.0}
\DoxyCodeLine{564   \textcolor{keywordflow}{if} (cs\%id\_BulkDrho > 0) \textcolor{keyword}{allocate}( cs\%dRho( szi\_(g), szj\_(g), szk\_(g) ) )}
\DoxyCodeLine{565   \textcolor{keywordflow}{if} (cs\%id\_BulkDrho > 0) cs\%dRho(:,:,:) = 0.}
\DoxyCodeLine{566   \textcolor{keywordflow}{if} (cs\%id\_BulkUz2 > 0)  \textcolor{keyword}{allocate}( cs\%Uz2( szi\_(g), szj\_(g), szk\_(g) ) )}
\DoxyCodeLine{567   \textcolor{keywordflow}{if} (cs\%id\_BulkUz2 > 0)  cs\%Uz2(:,:,:) = 0.}
\DoxyCodeLine{568   \textcolor{keywordflow}{if} (cs\%id\_BulkRi > 0)   \textcolor{keyword}{allocate}( cs\%BulkRi( szi\_(g), szj\_(g), szk\_(g) ) )}
\DoxyCodeLine{569   \textcolor{keywordflow}{if} (cs\%id\_BulkRi > 0)   cs\%BulkRi(:,:,:) = 0.}
\DoxyCodeLine{570   \textcolor{keywordflow}{if} (cs\%id\_Sigma > 0)    \textcolor{keyword}{allocate}( cs\%sigma( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{571   \textcolor{keywordflow}{if} (cs\%id\_Sigma > 0)    cs\%sigma(:,:,:) = 0.}
\DoxyCodeLine{572   \textcolor{keywordflow}{if} (cs\%id\_Ws > 0)       \textcolor{keyword}{allocate}( cs\%Ws( szi\_(g), szj\_(g), szk\_(g) ) )}
\DoxyCodeLine{573   \textcolor{keywordflow}{if} (cs\%id\_Ws > 0)       cs\%Ws(:,:,:) = 0.}
\DoxyCodeLine{574   \textcolor{keywordflow}{if} (cs\%id\_N2 > 0)       \textcolor{keyword}{allocate}( cs\%N2( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{575   \textcolor{keywordflow}{if} (cs\%id\_N2 > 0)       cs\%N2(:,:,:) = 0.}
\DoxyCodeLine{576   \textcolor{keywordflow}{if} (cs\%id\_Kt\_KPP > 0)   \textcolor{keyword}{allocate}( cs\%Kt\_KPP( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{577   \textcolor{keywordflow}{if} (cs\%id\_Kt\_KPP > 0)   cs\%Kt\_KPP(:,:,:) = 0.}
\DoxyCodeLine{578   \textcolor{keywordflow}{if} (cs\%id\_Ks\_KPP > 0)   \textcolor{keyword}{allocate}( cs\%Ks\_KPP( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{579   \textcolor{keywordflow}{if} (cs\%id\_Ks\_KPP > 0)   cs\%Ks\_KPP(:,:,:) = 0.}
\DoxyCodeLine{580   \textcolor{keywordflow}{if} (cs\%id\_Kv\_KPP > 0)   \textcolor{keyword}{allocate}( cs\%Kv\_KPP( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{581   \textcolor{keywordflow}{if} (cs\%id\_Kv\_KPP > 0)   cs\%Kv\_KPP(:,:,:) = 0.}
\DoxyCodeLine{582   \textcolor{keywordflow}{if} (cs\%id\_Tsurf > 0)    \textcolor{keyword}{allocate}( cs\%Tsurf( szi\_(g), szj\_(g)) )}
\DoxyCodeLine{583   \textcolor{keywordflow}{if} (cs\%id\_Tsurf > 0)    cs\%Tsurf(:,:) = 0.}
\DoxyCodeLine{584   \textcolor{keywordflow}{if} (cs\%id\_Ssurf > 0)    \textcolor{keyword}{allocate}( cs\%Ssurf( szi\_(g), szj\_(g)) )}
\DoxyCodeLine{585   \textcolor{keywordflow}{if} (cs\%id\_Ssurf > 0)    cs\%Ssurf(:,:) = 0.}
\DoxyCodeLine{586   \textcolor{keywordflow}{if} (cs\%id\_Usurf > 0)    \textcolor{keyword}{allocate}( cs\%Usurf( szib\_(g), szj\_(g)) )}
\DoxyCodeLine{587   \textcolor{keywordflow}{if} (cs\%id\_Usurf > 0)    cs\%Usurf(:,:) = 0.}
\DoxyCodeLine{588   \textcolor{keywordflow}{if} (cs\%id\_Vsurf > 0)    \textcolor{keyword}{allocate}( cs\%Vsurf( szi\_(g), szjb\_(g)) )}
\DoxyCodeLine{589   \textcolor{keywordflow}{if} (cs\%id\_Vsurf > 0)    cs\%Vsurf(:,:) = 0.}
\DoxyCodeLine{590   \textcolor{keywordflow}{if} (cs\%id\_EnhVt2 > 0)    \textcolor{keyword}{allocate}( cs\%EnhVt2( szi\_(g), szj\_(g), szk\_(g)) )}
\DoxyCodeLine{591   \textcolor{keywordflow}{if} (cs\%id\_EnhVt2 > 0)    cs\%EnhVt2(:,:,:) = 0.}
\DoxyCodeLine{592   \textcolor{keywordflow}{if} (cs\%id\_EnhK > 0)    \textcolor{keyword}{allocate}( cs\%EnhK( szi\_(g), szj\_(g), szk\_(g)+1 ) )}
\DoxyCodeLine{593   \textcolor{keywordflow}{if} (cs\%id\_EnhK > 0)    cs\%EnhK(:,:,:) = 0.}
\DoxyCodeLine{594 }
\DoxyCodeLine{595   id\_clock\_kpp\_calc = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean KPP calculate)'}, grain=clock\_module)}
\DoxyCodeLine{596   id\_clock\_kpp\_compute\_bld = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean KPP comp BLD)'}, grain=clock\_routine)}
\DoxyCodeLine{597 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_abebacc1ae8c13149d816a60ff2e824b6}\label{namespacemom__cvmix__kpp_abebacc1ae8c13149d816a60ff2e824b6}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_nonlocaltransport\_saln@{kpp\_nonlocaltransport\_saln}}
\index{kpp\_nonlocaltransport\_saln@{kpp\_nonlocaltransport\_saln}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_nonlocaltransport\_saln()}{kpp\_nonlocaltransport\_saln()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+nonlocaltransport\+\_\+saln (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{non\+Local\+Trans,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{surf\+Flux,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{scalar }\end{DoxyParamCaption})}



Apply K\+PP non-\/local transport of surface fluxes for salinity. This routine is a useful prototype for other material tracers. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer/level thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nonlocaltrans} & Non-\/local transport \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em surfflux} & Surface flux of scalar \mbox{[}conc H s-\/1 $\sim$$>$ conc m s-\/1 or conc kg m-\/2 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time-\/step \mbox{[}s\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em scalar} & Scalar (scalar units \mbox{[}conc\mbox{]}) \\
\hline
\end{DoxyParams}


Definition at line 1451 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1452 }
\DoxyCodeLine{1453   \textcolor{keywordtype}{type}(KPP\_CS),                               \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{            !< Control structure}}
\DoxyCodeLine{1454   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{             !< Ocean grid}}
\DoxyCodeLine{1455   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{            !< Ocean vertical grid}}
\DoxyCodeLine{1456 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{             !< Layer/level thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1457 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: nonLocalTrans\textcolor{comment}{ !< Non-\/local transport [nondim]}}
\DoxyCodeLine{1458 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: surfFlux\textcolor{comment}{      !< Surface flux of scalar}}
\DoxyCodeLine{1459 \textcolor{comment}{                                                                        !! [conc H s-\/1 \string~> conc m s-\/1 or conc kg m-\/2 s-\/1]}}
\DoxyCodeLine{1460 \textcolor{keywordtype}{  real},                                       \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{            !< Time-\/step [s]}}
\DoxyCodeLine{1461 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: scalar\textcolor{comment}{        !< Scalar (scalar units [conc])}}
\DoxyCodeLine{1462 }
\DoxyCodeLine{1463   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{1464 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( SZI\_(G), SZJ\_(G), SZK\_(G) )} :: dtracer}
\DoxyCodeLine{1465 }
\DoxyCodeLine{1466 }
\DoxyCodeLine{1467   dtracer(:,:,:) = 0.0}
\DoxyCodeLine{1468   \textcolor{comment}{!\$OMP parallel do default(none) shared(dtracer, nonLocalTrans, h, G, GV, surfFlux)}}
\DoxyCodeLine{1469   \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1470     \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1471       \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1472         dtracer(i,j,k) = ( nonlocaltrans(i,j,k) -\/ nonlocaltrans(i,j,k+1) ) / \&}
\DoxyCodeLine{1473                          ( h(i,j,k) + gv\%H\_subroundoff ) * surfflux(i,j)}
\DoxyCodeLine{1474 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1475 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1476 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1477 }
\DoxyCodeLine{1478   \textcolor{comment}{!  Update tracer due to non-\/local redistribution of surface flux}}
\DoxyCodeLine{1479   \textcolor{keywordflow}{if} (cs\%applyNonLocalTrans) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1480     \textcolor{comment}{!\$OMP parallel do default(none) shared(G, dt, scalar, dtracer)}}
\DoxyCodeLine{1481     \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1482       \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1483         \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1484           scalar(i,j,k) = scalar(i,j,k) + dt * dtracer(i,j,k)}
\DoxyCodeLine{1485 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1486 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1487 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1488 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1489 }
\DoxyCodeLine{1490   \textcolor{comment}{! Diagnostics}}
\DoxyCodeLine{1491   \textcolor{keywordflow}{if} (cs\%id\_netS            > 0) \textcolor{keyword}{call }post\_data(cs\%id\_netS,     surfflux, cs\%diag)}
\DoxyCodeLine{1492   \textcolor{keywordflow}{if} (cs\%id\_NLT\_dSdt        > 0) \textcolor{keyword}{call }post\_data(cs\%id\_NLT\_dSdt, dtracer,  cs\%diag)}
\DoxyCodeLine{1493   \textcolor{keywordflow}{if} (cs\%id\_NLT\_saln\_budget > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1494     dtracer(:,:,:) = 0.0}
\DoxyCodeLine{1495     \textcolor{comment}{!\$OMP parallel do default(none) shared(G, GV, dtracer, nonLocalTrans, surfFlux)}}
\DoxyCodeLine{1496     \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1497       \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1498         \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1499           dtracer(i,j,k) = (nonlocaltrans(i,j,k) -\/ nonlocaltrans(i,j,k+1)) * \&}
\DoxyCodeLine{1500                            surfflux(i,j) * gv\%H\_to\_kg\_m2}
\DoxyCodeLine{1501 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1502 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1503 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1504     \textcolor{keyword}{call }post\_data(cs\%id\_NLT\_saln\_budget, dtracer, cs\%diag)}
\DoxyCodeLine{1505 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1506 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a54093ca1cac897785c965c00efa12fe6}\label{namespacemom__cvmix__kpp_a54093ca1cac897785c965c00efa12fe6}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_nonlocaltransport\_temp@{kpp\_nonlocaltransport\_temp}}
\index{kpp\_nonlocaltransport\_temp@{kpp\_nonlocaltransport\_temp}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_nonlocaltransport\_temp()}{kpp\_nonlocaltransport\_temp()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+nonlocaltransport\+\_\+temp (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{non\+Local\+Trans,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{surf\+Flux,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{scalar,  }\item[{real, intent(in)}]{C\+\_\+p }\end{DoxyParamCaption})}



Apply K\+PP non-\/local transport of surface fluxes for temperature. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer/level thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nonlocaltrans} & Non-\/local transport \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em surfflux} & Surface flux of scalar \mbox{[}conc H s-\/1 $\sim$$>$ conc m s-\/1 or conc kg m-\/2 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time-\/step \mbox{[}s\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em scalar} & temperature \\
\hline
\mbox{\texttt{ in}}  & {\em c\+\_\+p} & Seawater specific heat capacity \mbox{[}J kg-\/1 deg\+C-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1388 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1390 }
\DoxyCodeLine{1391   \textcolor{keywordtype}{type}(KPP\_CS),                               \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{     !< Control structure}}
\DoxyCodeLine{1392   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< Ocean grid}}
\DoxyCodeLine{1393   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid}}
\DoxyCodeLine{1394 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer/level thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1395 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: nonLocalTrans\textcolor{comment}{ !< Non-\/local transport [nondim]}}
\DoxyCodeLine{1396 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: surfFlux\textcolor{comment}{  !< Surface flux of scalar}}
\DoxyCodeLine{1397 \textcolor{comment}{                                                                      !! [conc H s-\/1 \string~> conc m s-\/1 or conc kg m-\/2 s-\/1]}}
\DoxyCodeLine{1398 \textcolor{keywordtype}{  real},                                       \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time-\/step [s]}}
\DoxyCodeLine{1399 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: scalar\textcolor{comment}{ !< temperature}}
\DoxyCodeLine{1400 \textcolor{keywordtype}{  real},                                       \textcolor{keywordtype}{intent(in)}    :: C\_p\textcolor{comment}{    !< Seawater specific heat capacity [J kg-\/1 degC-\/1]}}
\DoxyCodeLine{1401 }
\DoxyCodeLine{1402   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{1403 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( SZI\_(G), SZJ\_(G), SZK\_(G) )} :: dtracer}
\DoxyCodeLine{1404 }
\DoxyCodeLine{1405 }
\DoxyCodeLine{1406   dtracer(:,:,:) = 0.0}
\DoxyCodeLine{1407   \textcolor{comment}{!\$OMP parallel do default(none) shared(dtracer, nonLocalTrans, h, G, GV, surfFlux)}}
\DoxyCodeLine{1408   \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1409     \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1410       \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1411         dtracer(i,j,k) = ( nonlocaltrans(i,j,k) -\/ nonlocaltrans(i,j,k+1) ) / \&}
\DoxyCodeLine{1412                          ( h(i,j,k) + gv\%H\_subroundoff ) * surfflux(i,j)}
\DoxyCodeLine{1413 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1414 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1415 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1416 }
\DoxyCodeLine{1417   \textcolor{comment}{!  Update tracer due to non-\/local redistribution of surface flux}}
\DoxyCodeLine{1418   \textcolor{keywordflow}{if} (cs\%applyNonLocalTrans) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1419     \textcolor{comment}{!\$OMP parallel do default(none) shared(dt, scalar, dtracer, G)}}
\DoxyCodeLine{1420     \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1421       \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1422         \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1423           scalar(i,j,k) = scalar(i,j,k) + dt * dtracer(i,j,k)}
\DoxyCodeLine{1424 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1425 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1426 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1427 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1428 }
\DoxyCodeLine{1429   \textcolor{comment}{! Diagnostics}}
\DoxyCodeLine{1430   \textcolor{keywordflow}{if} (cs\%id\_QminusSW        > 0) \textcolor{keyword}{call }post\_data(cs\%id\_QminusSW, surfflux, cs\%diag)}
\DoxyCodeLine{1431   \textcolor{keywordflow}{if} (cs\%id\_NLT\_dTdt        > 0) \textcolor{keyword}{call }post\_data(cs\%id\_NLT\_dTdt, dtracer,  cs\%diag)}
\DoxyCodeLine{1432   \textcolor{keywordflow}{if} (cs\%id\_NLT\_temp\_budget > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1433     dtracer(:,:,:) = 0.0}
\DoxyCodeLine{1434     \textcolor{comment}{!\$OMP parallel do default(none) shared(dtracer, nonLocalTrans, surfFlux, C\_p, G, GV)}}
\DoxyCodeLine{1435     \textcolor{keywordflow}{do} k = 1, g\%ke}
\DoxyCodeLine{1436       \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1437         \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1438           dtracer(i,j,k) = (nonlocaltrans(i,j,k) -\/ nonlocaltrans(i,j,k+1)) * \&}
\DoxyCodeLine{1439                            surfflux(i,j) * c\_p * gv\%H\_to\_kg\_m2}
\DoxyCodeLine{1440 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1441 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1442 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1443     \textcolor{keyword}{call }post\_data(cs\%id\_NLT\_temp\_budget, dtracer, cs\%diag)}
\DoxyCodeLine{1444 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1445 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a8662fdd6328fdec67691ced27f03e049}\label{namespacemom__cvmix__kpp_a8662fdd6328fdec67691ced27f03e049}} 
\index{mom\_cvmix\_kpp@{mom\_cvmix\_kpp}!kpp\_smooth\_bld@{kpp\_smooth\_bld}}
\index{kpp\_smooth\_bld@{kpp\_smooth\_bld}!mom\_cvmix\_kpp@{mom\_cvmix\_kpp}}
\doxysubsubsection{\texorpdfstring{kpp\_smooth\_bld()}{kpp\_smooth\_bld()}}
{\footnotesize\ttfamily subroutine mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+smooth\+\_\+bld (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Apply a 1-\/1-\/4-\/1-\/1 Laplacian filter one time on B\+LD to reduce any horizontal two-\/grid-\/point noise. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer/level thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1284 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1285   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1286   \textcolor{keywordtype}{type}(KPP\_CS),                           \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< Control structure}}
\DoxyCodeLine{1287   \textcolor{keywordtype}{type}(ocean\_grid\_type),                  \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid}}
\DoxyCodeLine{1288   \textcolor{keywordtype}{type}(verticalGrid\_type),                \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid}}
\DoxyCodeLine{1289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{    !< Layer/level thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1290 }
\DoxyCodeLine{1291   \textcolor{comment}{! local}}
\DoxyCodeLine{1292 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: OBLdepth\_prev     \textcolor{comment}{! OBLdepth before s.th smoothing iteration}}
\DoxyCodeLine{1293 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke )}          :: cellHeight        \textcolor{comment}{! Cell center heights referenced to surface [m]}}
\DoxyCodeLine{1294                                                         \textcolor{comment}{! (negative in the ocean)}}
\DoxyCodeLine{1295 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension( G\%ke+1 )}        :: iFaceHeight       \textcolor{comment}{! Interface heights referenced to surface [m]}}
\DoxyCodeLine{1296                                                         \textcolor{comment}{! (negative in the ocean)}}
\DoxyCodeLine{1297 \textcolor{keywordtype}{  real} :: wc, ww, we, wn, ws \textcolor{comment}{! averaging weights for smoothing}}
\DoxyCodeLine{1298 \textcolor{keywordtype}{  real} :: dh                 \textcolor{comment}{! The local thickness used for calculating interface positions [m]}}
\DoxyCodeLine{1299 \textcolor{keywordtype}{  real} :: hcorr              \textcolor{comment}{! A cumulative correction arising from inflation of vanished layers [m]}}
\DoxyCodeLine{1300   \textcolor{keywordtype}{integer} :: i, j, k, s}
\DoxyCodeLine{1301 }
\DoxyCodeLine{1302   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_kpp\_smoothing)}
\DoxyCodeLine{1303 }
\DoxyCodeLine{1304   \textcolor{comment}{! Update halos}}
\DoxyCodeLine{1305   \textcolor{keyword}{call }pass\_var(cs\%OBLdepth, g\%Domain, halo=cs\%n\_smooth)}
\DoxyCodeLine{1306 }
\DoxyCodeLine{1307   \textcolor{keywordflow}{if} (cs\%id\_OBLdepth\_original > 0) cs\%OBLdepth\_original = cs\%OBLdepth}
\DoxyCodeLine{1308 }
\DoxyCodeLine{1309   \textcolor{keywordflow}{do} s=1,cs\%n\_smooth}
\DoxyCodeLine{1310 }
\DoxyCodeLine{1311     obldepth\_prev = cs\%OBLdepth}
\DoxyCodeLine{1312 }
\DoxyCodeLine{1313     \textcolor{comment}{! apply smoothing on OBL depth}}
\DoxyCodeLine{1314     \textcolor{comment}{!\$OMP parallel do default(none) shared(G, GV, CS, h, OBLdepth\_prev) \&}}
\DoxyCodeLine{1315     \textcolor{comment}{!\$OMP                           private(wc, ww, we, wn, ws, dh, hcorr, cellHeight, iFaceHeight)}}
\DoxyCodeLine{1316     \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{1317       \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{1318 }
\DoxyCodeLine{1319          \textcolor{comment}{! skip land points}}
\DoxyCodeLine{1320         \textcolor{keywordflow}{if} (g\%mask2dT(i,j)==0.) cycle}
\DoxyCodeLine{1321 }
\DoxyCodeLine{1322         ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}}
\DoxyCodeLine{1323         hcorr = 0.}
\DoxyCodeLine{1324         \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1325 }
\DoxyCodeLine{1326           \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}}
\DoxyCodeLine{1327           dh = h(i,j,k) * gv\%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment}}
\DoxyCodeLine{1328           dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}}
\DoxyCodeLine{1329           hcorr = min( dh -\/ cs\%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}}
\DoxyCodeLine{1330           dh = max( dh, cs\%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}}
\DoxyCodeLine{1331           cellheight(k)    = ifaceheight(k) -\/ 0.5 * dh}
\DoxyCodeLine{1332           ifaceheight(k+1) = ifaceheight(k) -\/ dh}
\DoxyCodeLine{1333 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1334 }
\DoxyCodeLine{1335         \textcolor{comment}{! compute weights}}
\DoxyCodeLine{1336         ww = 0.125 * g\%mask2dT(i-\/1,j)}
\DoxyCodeLine{1337         we = 0.125 * g\%mask2dT(i+1,j)}
\DoxyCodeLine{1338         ws = 0.125 * g\%mask2dT(i,j-\/1)}
\DoxyCodeLine{1339         wn = 0.125 * g\%mask2dT(i,j+1)}
\DoxyCodeLine{1340         wc = 1.0 -\/ (ww+we+wn+ws)}
\DoxyCodeLine{1341 }
\DoxyCodeLine{1342         cs\%OBLdepth(i,j) =  wc * obldepth\_prev(i,j)   \&}
\DoxyCodeLine{1343                           + ww * obldepth\_prev(i-\/1,j) \&}
\DoxyCodeLine{1344                           + we * obldepth\_prev(i+1,j) \&}
\DoxyCodeLine{1345                           + ws * obldepth\_prev(i,j-\/1) \&}
\DoxyCodeLine{1346                           + wn * obldepth\_prev(i,j+1)}
\DoxyCodeLine{1347 }
\DoxyCodeLine{1348         \textcolor{comment}{! Apply OBLdepth smoothing at a cell only if the OBLdepth gets deeper via smoothing.}}
\DoxyCodeLine{1349         \textcolor{keywordflow}{if} (cs\%deepen\_only) cs\%OBLdepth(i,j) = max(cs\%OBLdepth(i,j), obldepth\_prev(i,j))}
\DoxyCodeLine{1350 }
\DoxyCodeLine{1351         \textcolor{comment}{! prevent OBL depths deeper than the bathymetric depth}}
\DoxyCodeLine{1352         cs\%OBLdepth(i,j) = min( cs\%OBLdepth(i,j), -\/ifaceheight(g\%ke+1) ) \textcolor{comment}{! no deeper than bottom}}
\DoxyCodeLine{1353         cs\%kOBL(i,j)     = cvmix\_kpp\_compute\_kobl\_depth( ifaceheight, cellheight, cs\%OBLdepth(i,j) )}
\DoxyCodeLine{1354 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1355 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1356 }
\DoxyCodeLine{1357 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! s-\/loop}}
\DoxyCodeLine{1358 }
\DoxyCodeLine{1359   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_kpp\_smoothing)}
\DoxyCodeLine{1360 }

\end{DoxyCode}
