\hypertarget{namespacemom__lateral__mixing__coeffs}{}\doxysection{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs Module Reference}
\label{namespacemom__lateral__mixing__coeffs}\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}


\doxysubsection{Detailed Description}
Variable mixing coefficients. 

This module provides a container for various factors used in prescribing diffusivities, that are a function of the state (in particular the stratification and isoneutral slopes).\hypertarget{namespacemom__lateral__mixing__coeffs_section_Resolution_Function}{}\doxysubsection{The resolution function}\label{namespacemom__lateral__mixing__coeffs_section_Resolution_Function}
The resolution function is expressed in terms of the ratio of grid-\/spacing to deformation radius. The square of the resolution parameter is

\[ R^2 = \frac{L_d^2}{\Delta^2} = \frac{ c_g^2 }{ f^2 \Delta^2 + c_g \beta \Delta^2 } \]

where the grid spacing is calculated as

\[ \Delta^2 = \Delta x^2 + \Delta y^2 . \]

\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000002}{Todo}}]Check this reference to Bob on/off paper. The resolution function used in scaling diffusivities (Hallberg, 2010) is\end{DoxyRefDesc}


\[ r(\Delta,L_d) = \frac{1}{1+(\alpha R)^p} \]

The resolution function can be applied independently to thickness diffusion (module \mbox{\hyperlink{namespacemom__thickness__diffuse}{mom\+\_\+thickness\+\_\+diffuse}}), tracer diffusion (mom\+\_\+tracer\+\_\+hordiff) lateral viscosity (\mbox{\hyperlink{namespacemom__hor__visc}{mom\+\_\+hor\+\_\+visc}}).

Robert Hallberg, 2013\+: Using a resolution function to regulate parameterizations of oceanic mesoscale eddy effects. Ocean Modelling, 71, pp 92-\/103. \href{http://dx.doi.org/10.1016/j.ocemod.2013.08.007}{\texttt{ http\+://dx.\+doi.\+org/10.\+1016/j.\+ocemod.\+2013.\+08.\+007}}

\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol  }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter   }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol  }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter   }\\\cline{1-2}
\endhead
-\/  &{\ttfamily U\+S\+E\+\_\+\+V\+A\+R\+I\+A\+B\+L\+E\+\_\+\+M\+I\+X\+I\+NG}   \\\cline{1-2}
-\/  &{\ttfamily R\+E\+S\+O\+L\+N\+\_\+\+S\+C\+A\+L\+E\+D\+\_\+\+KH}   \\\cline{1-2}
-\/  &{\ttfamily R\+E\+S\+O\+L\+N\+\_\+\+S\+C\+A\+L\+E\+D\+\_\+\+K\+H\+TH}   \\\cline{1-2}
-\/  &{\ttfamily R\+E\+S\+O\+L\+N\+\_\+\+S\+C\+A\+L\+E\+D\+\_\+\+K\+H\+TR}   \\\cline{1-2}
$ \alpha $  &{\ttfamily K\+H\+\_\+\+R\+E\+S\+\_\+\+S\+C\+A\+L\+E\+\_\+\+C\+O\+EF} (for thickness and tracer diffusivity)   \\\cline{1-2}
$ p $  &{\ttfamily K\+H\+\_\+\+R\+E\+S\+\_\+\+F\+N\+\_\+\+P\+O\+W\+ER} (for thickness and tracer diffusivity)   \\\cline{1-2}
$ \alpha $  &{\ttfamily V\+I\+S\+C\+\_\+\+R\+E\+S\+\_\+\+S\+C\+A\+L\+E\+\_\+\+C\+O\+EF} (for lateral viscosity)   \\\cline{1-2}
$ p $  &{\ttfamily V\+I\+S\+C\+\_\+\+R\+E\+S\+\_\+\+F\+N\+\_\+\+P\+O\+W\+ER} (for lateral viscosity)   \\\cline{1-2}
-\/  &{\ttfamily G\+I\+L\+L\+\_\+\+E\+Q\+U\+A\+T\+O\+R\+I\+A\+L\+\_\+\+LD}   \\\cline{1-2}
\end{longtabu}
\hypertarget{namespacemom__lateral__mixing__coeffs_section_Vicbeck}{}\doxysubsection{Visbeck diffusivity}\label{namespacemom__lateral__mixing__coeffs_section_Vicbeck}
This module also calculates factors used in setting the thickness diffusivity similar to a Visbeck et al., 1997, scheme. The factors are combined in \mbox{\hyperlink{namespacemom__thickness__diffuse_a8a538b778a567f489bfd9c5eadeeebef}{mom\+\_\+thickness\+\_\+diffuse\+::thickness\+\_\+diffuse()}} but calculated in this module.

\[ \kappa_h = \alpha_s L_s^2 S N \]

where $S$ is the magnitude of the isoneutral slope and $N$ is the Brunt-\/\+Vaisala frequency.

Visbeck, Marshall, Haine and Spall, 1997\+: Specification of Eddy Transfer Coefficients in Coarse-\/\+Resolution Ocean Circulation Models. J. Phys. Oceanogr. \href{http://dx.doi.org/10.1175/1520-0485(1997)027\%3C0381:SOETCI\%3E2.0.CO;2}{\texttt{ http\+://dx.\+doi.\+org/10.\+1175/1520-\/0485(1997)027\%3\+C0381\+:\+S\+O\+E\+T\+C\+I\%3\+E2.\+0.\+C\+O;2}}

\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol  }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter   }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol  }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter   }\\\cline{1-2}
\endhead
-\/  &{\ttfamily U\+S\+E\+\_\+\+V\+A\+R\+I\+A\+B\+L\+E\+\_\+\+M\+I\+X\+I\+NG}   \\\cline{1-2}
$ \alpha_s $  &{\ttfamily K\+H\+T\+H\+\_\+\+S\+L\+O\+P\+E\+\_\+\+C\+FF} (for \mbox{\hyperlink{namespacemom__thickness__diffuse}{mom\+\_\+thickness\+\_\+diffuse}} module)   \\\cline{1-2}
$ \alpha_s $  &{\ttfamily K\+H\+T\+R\+\_\+\+S\+L\+O\+P\+E\+\_\+\+C\+FF} (for mom\+\_\+tracer\+\_\+hordiff module)   \\\cline{1-2}
$ L_{s} $  &{\ttfamily V\+I\+S\+B\+E\+C\+K\+\_\+\+L\+\_\+\+S\+C\+A\+LE}   \\\cline{1-2}
$ S_{max} $  &{\ttfamily V\+I\+S\+B\+E\+C\+K\+\_\+\+M\+A\+X\+\_\+\+S\+L\+O\+PE}   \\\cline{1-2}
\end{longtabu}
\hypertarget{namespacemom__lateral__mixing__coeffs_section_vertical_structure_khth}{}\doxysubsection{Vertical structure function for Kh\+Th}\label{namespacemom__lateral__mixing__coeffs_section_vertical_structure_khth}
The thickness diffusivity can be prescribed a vertical distribution with the shape of the equivalent barotropic velocity mode. The structure function is stored in the control structure for thie module (\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}) but is calculated using subroutines in \mbox{\hyperlink{namespacemom__wave__speed}{mom\+\_\+wave\+\_\+speed}}.

\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol  }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter   }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Symbol  }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Module parameter   }\\\cline{1-2}
\endhead
-\/  &{\ttfamily K\+H\+T\+H\+\_\+\+U\+S\+E\+\_\+\+E\+B\+T\+\_\+\+S\+T\+R\+U\+CT}   \\\cline{1-2}
\end{longtabu}
\doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Variable mixing coefficients. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a6e09cc5b57817576a6ba61b9c630f608}{calc\+\_\+depth\+\_\+function}} (G, CS)
\begin{DoxyCompactList}\small\item\em Calculates the non-\/dimensional depth functions. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a8652c5651033573cfd6f09b789d64713}{calc\+\_\+resoln\+\_\+function}} (h, tv, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates and stores the non-\/dimensional resolution functions. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a1afa768a2df4c937842247cea00d184a}{calc\+\_\+slope\+\_\+functions}} (h, tv, dt, G, GV, US, CS, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates and stores functions of isopycnal slopes, e.\+g. Sx, Sy, S$\ast$N, mostly used in the Visbeck et al. style scaling of diffusivity. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_ac7307f59d005a7b45a642f94eee7c8be}{calc\+\_\+visbeck\+\_\+coeffs}} (h, slope\+\_\+x, slope\+\_\+y, N2\+\_\+u, N2\+\_\+v, G, GV, US, CS, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates factors used when setting diffusivity coefficients similar to Visbeck et al. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a9947860318104ed1662ff4f9d671f92d}{calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e}} (h, G, GV, US, CS, e, calculate\+\_\+slopes, O\+BC)
\begin{DoxyCompactList}\small\item\em The original calc\+\_\+slope\+\_\+function() that calculated slopes using interface positions only, not accounting for density variations. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a212e9e850d4db8f321e0398f4090fee0}{calc\+\_\+qg\+\_\+leith\+\_\+viscosity}} (CS, G, GV, US, h, k, div\+\_\+xx\+\_\+dx, div\+\_\+xx\+\_\+dy, vort\+\_\+xy\+\_\+dx, vort\+\_\+xy\+\_\+dy)
\begin{DoxyCompactList}\small\item\em Calculates the Leith Laplacian and bi-\/harmonic viscosity coefficients. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a1070a864ca570c00f483a8617afca133}{varmix\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initializes the variables mixing coefficients container. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a6e09cc5b57817576a6ba61b9c630f608}\label{namespacemom__lateral__mixing__coeffs_a6e09cc5b57817576a6ba61b9c630f608}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!calc\_depth\_function@{calc\_depth\_function}}
\index{calc\_depth\_function@{calc\_depth\_function}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{calc\_depth\_function()}{calc\_depth\_function()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+depth\+\_\+function (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Calculates the non-\/dimensional depth functions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\end{DoxyParams}


Definition at line 156 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{157   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{158   \textcolor{keywordtype}{type}(VarMix\_CS),                          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}}
\DoxyCodeLine{159 }
\DoxyCodeLine{160   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{161   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq}
\DoxyCodeLine{162   \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{163 \textcolor{keywordtype}{  real}    :: H0 \textcolor{comment}{! local variable for reference depth}}
\DoxyCodeLine{164 \textcolor{keywordtype}{  real}    :: expo \textcolor{comment}{! exponent used in the depth dependent scaling}}
\DoxyCodeLine{165   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{166   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{167 }
\DoxyCodeLine{168   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_depth\_function:"{}}// \&}
\DoxyCodeLine{169          \textcolor{stringliteral}{"{}Module must be initialized before it is used."{}})}
\DoxyCodeLine{170   \textcolor{keywordflow}{if} (.not. cs\%calculate\_depth\_fns) \textcolor{keywordflow}{return}}
\DoxyCodeLine{171   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Depth\_fn\_u)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{172     \textcolor{stringliteral}{"{}calc\_depth\_function: \%Depth\_fn\_u is not associated with Depth\_scaled\_KhTh."{}})}
\DoxyCodeLine{173   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Depth\_fn\_v)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{174     \textcolor{stringliteral}{"{}calc\_depth\_function: \%Depth\_fn\_v is not associated with Depth\_scaled\_KhTh."{}})}
\DoxyCodeLine{175 }
\DoxyCodeLine{176   h0 = cs\%depth\_scaled\_khth\_h0}
\DoxyCodeLine{177   expo = cs\%depth\_scaled\_khth\_exp}
\DoxyCodeLine{178 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{179   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{180     cs\%Depth\_fn\_u(i,j) = (min(1.0, 0.5*(g\%bathyT(i,j) + g\%bathyT(i+1,j))/h0))**expo}
\DoxyCodeLine{181 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{182 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{183   \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{184     cs\%Depth\_fn\_v(i,j) = (min(1.0, 0.5*(g\%bathyT(i,j) + g\%bathyT(i,j+1))/h0))**expo}
\DoxyCodeLine{185 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{186 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a212e9e850d4db8f321e0398f4090fee0}\label{namespacemom__lateral__mixing__coeffs_a212e9e850d4db8f321e0398f4090fee0}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!calc\_qg\_leith\_viscosity@{calc\_qg\_leith\_viscosity}}
\index{calc\_qg\_leith\_viscosity@{calc\_qg\_leith\_viscosity}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{calc\_qg\_leith\_viscosity()}{calc\_qg\_leith\_viscosity()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+qg\+\_\+leith\+\_\+viscosity (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{integer, intent(in)}]{k,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g)), intent(in)}]{div\+\_\+xx\+\_\+dx,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(in)}]{div\+\_\+xx\+\_\+dy,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(inout)}]{vort\+\_\+xy\+\_\+dx,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{vort\+\_\+xy\+\_\+dy }\end{DoxyParamCaption})}



Calculates the Leith Laplacian and bi-\/harmonic viscosity coefficients. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Variable mixing coefficients \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em k} & Layer for which to calculate vorticity magnitude \\
\hline
\mbox{\texttt{ in}}  & {\em div\+\_\+xx\+\_\+dx} & x-\/derivative of horizontal divergence (d/dx(du/dx + dv/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em div\+\_\+xx\+\_\+dy} & y-\/derivative of horizontal divergence (d/dy(du/dx + dv/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vort\+\_\+xy\+\_\+dx} & x-\/derivative of vertical vorticity (d/dx(dv/dx -\/ du/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vort\+\_\+xy\+\_\+dy} & y-\/derivative of vertical vorticity (d/dy(dv/dx -\/ du/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 807 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{808   \textcolor{keywordtype}{type}(VarMix\_CS),                           \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{ !< Variable mixing coefficients}}
\DoxyCodeLine{809   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{810   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{ !< The ocean's vertical grid structure.}}
\DoxyCodeLine{811   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{812 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{ !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{813   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}  :: k\textcolor{comment}{  !< Layer for which to calculate vorticity magnitude}}
\DoxyCodeLine{814 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},         \textcolor{keywordtype}{intent(in)}  :: div\_xx\_dx\textcolor{comment}{  !< x-\/derivative of horizontal divergence}}
\DoxyCodeLine{815 \textcolor{comment}{                                                                 !! (d/dx(du/dx + dv/dy)) [L-\/1 T-\/1 \string~> m-\/1 s-\/1]}}
\DoxyCodeLine{816 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(in)}  :: div\_xx\_dy\textcolor{comment}{  !< y-\/derivative of horizontal divergence}}
\DoxyCodeLine{817 \textcolor{comment}{                                                                 !! (d/dy(du/dx + dv/dy)) [L-\/1 T-\/1 \string~> m-\/1 s-\/1]}}
\DoxyCodeLine{818 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vort\_xy\_dx\textcolor{comment}{ !< x-\/derivative of vertical vorticity}}
\DoxyCodeLine{819 \textcolor{comment}{                                                                 !! (d/dx(dv/dx -\/ du/dy)) [L-\/1 T-\/1 \string~> m-\/1 s-\/1]}}
\DoxyCodeLine{820 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vort\_xy\_dy\textcolor{comment}{ !< y-\/derivative of vertical vorticity}}
\DoxyCodeLine{821 \textcolor{comment}{                                                                 !! (d/dy(dv/dx -\/ du/dy)) [L-\/1 T-\/1 \string~> m-\/1 s-\/1]}}
\DoxyCodeLine{822   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{823 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{824     dslopey\_dz, \& \textcolor{comment}{! z-\/derivative of y-\/slope at v-\/points [Z-\/1 \string~> m-\/1]}}
\DoxyCodeLine{825     h\_at\_v,     \& \textcolor{comment}{! Thickness at v-\/points [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{826     beta\_v,     \& \textcolor{comment}{! Beta at v-\/points [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{827     grad\_vort\_mag\_v, \& \textcolor{comment}{! Magnitude of vorticity gradient at v-\/points [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{828     grad\_div\_mag\_v     \textcolor{comment}{! Magnitude of divergence gradient at v-\/points [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{829 }
\DoxyCodeLine{830 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{831     dslopex\_dz, \& \textcolor{comment}{! z-\/derivative of x-\/slope at u-\/points [Z-\/1 \string~> m-\/1]}}
\DoxyCodeLine{832     h\_at\_u,     \& \textcolor{comment}{! Thickness at u-\/points [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{833     beta\_u,     \& \textcolor{comment}{! Beta at u-\/points [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{834     grad\_vort\_mag\_u, \& \textcolor{comment}{! Magnitude of vorticity gradient at u-\/points [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{835     grad\_div\_mag\_u     \textcolor{comment}{! Magnitude of divergence gradient at u-\/points [T-\/1 L-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{836 \textcolor{keywordtype}{  real} :: h\_at\_slope\_above \textcolor{comment}{! The thickness above [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{837 \textcolor{keywordtype}{  real} :: h\_at\_slope\_below \textcolor{comment}{! The thickness below [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{838 \textcolor{keywordtype}{  real} :: Ih \textcolor{comment}{! The inverse of a combination of thicknesses [H-\/1 \string~> m-\/1 or m2 kg-\/1]}}
\DoxyCodeLine{839 \textcolor{keywordtype}{  real} :: f  \textcolor{comment}{! A copy of the Coriolis parameter [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{840   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, Isq, Ieq, Jsq, Jeq,nz}
\DoxyCodeLine{841 \textcolor{keywordtype}{  real} :: inv\_PI3}
\DoxyCodeLine{842 }
\DoxyCodeLine{843   is  = g\%isc  ; ie  = g\%iec  ; js  = g\%jsc  ; je  = g\%jec}
\DoxyCodeLine{844   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{845   nz = g\%ke}
\DoxyCodeLine{846 }
\DoxyCodeLine{847   inv\_pi3 = 1.0/((4.0*atan(1.0))**3)}
\DoxyCodeLine{848 }
\DoxyCodeLine{849   \textcolor{keywordflow}{if} ((k > 1) .and. (k < nz)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{850 }
\DoxyCodeLine{851     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/2,ieq+1}
\DoxyCodeLine{852       h\_at\_slope\_above = 2. * ( h(i,j,k-\/1) * h(i+1,j,k-\/1) ) * ( h(i,j,k) * h(i+1,j,k) ) / \&}
\DoxyCodeLine{853                          ( ( h(i,j,k-\/1) * h(i+1,j,k-\/1) ) * ( h(i,j,k) + h(i+1,j,k) ) \&}
\DoxyCodeLine{854                          + ( h(i,j,k) * h(i+1,j,k) ) * ( h(i,j,k-\/1) + h(i+1,j,k-\/1) ) + gv\%H\_subroundoff )}
\DoxyCodeLine{855       h\_at\_slope\_below = 2. * ( h(i,j,k) * h(i+1,j,k) ) * ( h(i,j,k+1) * h(i+1,j,k+1) ) / \&}
\DoxyCodeLine{856                          ( ( h(i,j,k) * h(i+1,j,k) ) * ( h(i,j,k+1) + h(i+1,j,k+1) ) \&}
\DoxyCodeLine{857                          + ( h(i,j,k+1) * h(i+1,j,k+1) ) * ( h(i,j,k) + h(i+1,j,k) ) + gv\%H\_subroundoff )}
\DoxyCodeLine{858       ih = 1./ ( ( h\_at\_slope\_above + h\_at\_slope\_below + gv\%H\_subroundoff ) * gv\%H\_to\_Z )}
\DoxyCodeLine{859       dslopex\_dz(i,j) = 2. * ( cs\%slope\_x(i,j,k) -\/ cs\%slope\_x(i,j,k+1) ) * ih}
\DoxyCodeLine{860       h\_at\_u(i,j) = 2. * ( h\_at\_slope\_above * h\_at\_slope\_below ) * ih}
\DoxyCodeLine{861 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{862 }
\DoxyCodeLine{863     \textcolor{keywordflow}{do} j=js-\/2,jeq+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{864       h\_at\_slope\_above = 2. * ( h(i,j,k-\/1) * h(i,j+1,k-\/1) ) * ( h(i,j,k) * h(i,j+1,k) ) / \&}
\DoxyCodeLine{865                          ( ( h(i,j,k-\/1) * h(i,j+1,k-\/1) ) * ( h(i,j,k) + h(i,j+1,k) ) \&}
\DoxyCodeLine{866                          + ( h(i,j,k) * h(i,j+1,k) ) * ( h(i,j,k-\/1) + h(i,j+1,k-\/1) ) + gv\%H\_subroundoff )}
\DoxyCodeLine{867       h\_at\_slope\_below = 2. * ( h(i,j,k) * h(i,j+1,k) ) * ( h(i,j,k+1) * h(i,j+1,k+1) ) / \&}
\DoxyCodeLine{868                          ( ( h(i,j,k) * h(i,j+1,k) ) * ( h(i,j,k+1) + h(i,j+1,k+1) ) \&}
\DoxyCodeLine{869                          + ( h(i,j,k+1) * h(i,j+1,k+1) ) * ( h(i,j,k) + h(i,j+1,k) ) + gv\%H\_subroundoff )}
\DoxyCodeLine{870       ih = 1./ ( ( h\_at\_slope\_above + h\_at\_slope\_below + gv\%H\_subroundoff ) * gv\%H\_to\_Z )}
\DoxyCodeLine{871       dslopey\_dz(i,j) = 2. * ( cs\%slope\_y(i,j,k) -\/ cs\%slope\_y(i,j,k+1) ) * ih}
\DoxyCodeLine{872       h\_at\_v(i,j) = 2. * ( h\_at\_slope\_above * h\_at\_slope\_below ) * ih}
\DoxyCodeLine{873 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{874 }
\DoxyCodeLine{875     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq+1}
\DoxyCodeLine{876       f = 0.5 * ( g\%CoriolisBu(i,j) + g\%CoriolisBu(i-\/1,j) )}
\DoxyCodeLine{877       vort\_xy\_dx(i,j) = vort\_xy\_dx(i,j) -\/ f * us\%L\_to\_Z * \&}
\DoxyCodeLine{878             ( ( h\_at\_u(i,j) * dslopex\_dz(i,j) + h\_at\_u(i-\/1,j+1) * dslopex\_dz(i-\/1,j+1) ) \&}
\DoxyCodeLine{879             + ( h\_at\_u(i-\/1,j) * dslopex\_dz(i-\/1,j) + h\_at\_u(i,j+1) * dslopex\_dz(i,j+1) ) ) / \&}
\DoxyCodeLine{880               ( ( h\_at\_u(i,j) + h\_at\_u(i-\/1,j+1) ) + ( h\_at\_u(i-\/1,j) + h\_at\_u(i,j+1) ) + gv\%H\_subroundoff)}
\DoxyCodeLine{881 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{882 }
\DoxyCodeLine{883     \textcolor{keywordflow}{do} j=js-\/1,jeq+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{884       f = 0.5 * ( g\%CoriolisBu(i,j) + g\%CoriolisBu(i,j-\/1) )}
\DoxyCodeLine{885       vort\_xy\_dy(i,j) = vort\_xy\_dy(i,j) -\/ f * us\%L\_to\_Z * \&}
\DoxyCodeLine{886             ( ( h\_at\_v(i,j) * dslopey\_dz(i,j) + h\_at\_v(i+1,j-\/1) * dslopey\_dz(i+1,j-\/1) ) \&}
\DoxyCodeLine{887             + ( h\_at\_v(i,j-\/1) * dslopey\_dz(i,j-\/1) + h\_at\_v(i+1,j) * dslopey\_dz(i+1,j) ) ) / \&}
\DoxyCodeLine{888               ( ( h\_at\_v(i,j) + h\_at\_v(i+1,j-\/1) ) + ( h\_at\_v(i,j-\/1) + h\_at\_v(i+1,j) ) + gv\%H\_subroundoff)}
\DoxyCodeLine{889 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{890 \textcolor{keywordflow}{  endif} \textcolor{comment}{! k > 1}}
\DoxyCodeLine{891 }
\DoxyCodeLine{892   \textcolor{keywordflow}{if} (cs\%use\_QG\_Leith\_GM) \textcolor{keywordflow}{then}}
\DoxyCodeLine{893 }
\DoxyCodeLine{894     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{895       grad\_vort\_mag\_u(i,j) = sqrt(vort\_xy\_dy(i,j)**2  + (0.25*((vort\_xy\_dx(i,j) + vort\_xy\_dx(i+1,j-\/1)) \&}
\DoxyCodeLine{896                                                              + (vort\_xy\_dx(i+1,j) + vort\_xy\_dx(i,j-\/1))))**2)}
\DoxyCodeLine{897       grad\_div\_mag\_u(i,j) = sqrt(div\_xx\_dx(i,j)**2  + (0.25*((div\_xx\_dy(i,j) + div\_xx\_dy(i+1,j-\/1)) \&}
\DoxyCodeLine{898                                                            + (div\_xx\_dy(i+1,j) + div\_xx\_dy(i,j-\/1))))**2)}
\DoxyCodeLine{899       \textcolor{keywordflow}{if} (cs\%use\_beta\_in\_QG\_Leith) \textcolor{keywordflow}{then}}
\DoxyCodeLine{900         beta\_u(i,j) = sqrt((0.5*(g\%dF\_dx(i,j)+g\%dF\_dx(i+1,j))**2) + \&}
\DoxyCodeLine{901                           (0.5*(g\%dF\_dy(i,j)+g\%dF\_dy(i+1,j))**2))}
\DoxyCodeLine{902         cs\%KH\_u\_QG(i,j,k) = min(grad\_vort\_mag\_u(i,j) + grad\_div\_mag\_u(i,j), 3.0*beta\_u(i,j)) * \&}
\DoxyCodeLine{903                             cs\%Laplac3\_const\_u(i,j) * inv\_pi3}
\DoxyCodeLine{904       \textcolor{keywordflow}{else}}
\DoxyCodeLine{905         cs\%KH\_u\_QG(i,j,k) = (grad\_vort\_mag\_u(i,j) + grad\_div\_mag\_u(i,j)) * \&}
\DoxyCodeLine{906                             cs\%Laplac3\_const\_u(i,j) * inv\_pi3}
\DoxyCodeLine{907 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{908 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{909 }
\DoxyCodeLine{910     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{911       grad\_vort\_mag\_v(i,j) = sqrt(vort\_xy\_dx(i,j)**2  + (0.25*((vort\_xy\_dy(i,j) + vort\_xy\_dy(i-\/1,j+1)) \&}
\DoxyCodeLine{912                                                              + (vort\_xy\_dy(i,j+1) + vort\_xy\_dy(i-\/1,j))))**2)}
\DoxyCodeLine{913       grad\_div\_mag\_v(i,j) = sqrt(div\_xx\_dy(i,j)**2  + (0.25*((div\_xx\_dx(i,j) + div\_xx\_dx(i-\/1,j+1)) \&}
\DoxyCodeLine{914                                                            + (div\_xx\_dx(i,j+1) + div\_xx\_dx(i-\/1,j))))**2)}
\DoxyCodeLine{915       \textcolor{keywordflow}{if} (cs\%use\_beta\_in\_QG\_Leith) \textcolor{keywordflow}{then}}
\DoxyCodeLine{916         beta\_v(i,j) = sqrt((0.5*(g\%dF\_dx(i,j)+g\%dF\_dx(i,j+1))**2) + \&}
\DoxyCodeLine{917                           (0.5*(g\%dF\_dy(i,j)+g\%dF\_dy(i,j+1))**2))}
\DoxyCodeLine{918         cs\%KH\_v\_QG(i,j,k) = min(grad\_vort\_mag\_v(i,j) + grad\_div\_mag\_v(i,j), 3.0*beta\_v(i,j)) * \&}
\DoxyCodeLine{919                             cs\%Laplac3\_const\_v(i,j) * inv\_pi3}
\DoxyCodeLine{920       \textcolor{keywordflow}{else}}
\DoxyCodeLine{921         cs\%KH\_v\_QG(i,j,k) = (grad\_vort\_mag\_v(i,j) + grad\_div\_mag\_v(i,j)) * \&}
\DoxyCodeLine{922                             cs\%Laplac3\_const\_v(i,j) * inv\_pi3}
\DoxyCodeLine{923 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{924 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{925     \textcolor{comment}{! post diagnostics}}
\DoxyCodeLine{926 }
\DoxyCodeLine{927     \textcolor{keywordflow}{if} (k==nz) \textcolor{keywordflow}{then}}
\DoxyCodeLine{928       \textcolor{keywordflow}{if} (cs\%id\_KH\_v\_QG > 0)  \textcolor{keyword}{call }post\_data(cs\%id\_KH\_v\_QG, cs\%KH\_v\_QG, cs\%diag)}
\DoxyCodeLine{929       \textcolor{keywordflow}{if} (cs\%id\_KH\_u\_QG > 0)  \textcolor{keyword}{call }post\_data(cs\%id\_KH\_u\_QG, cs\%KH\_u\_QG, cs\%diag)}
\DoxyCodeLine{930 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{931 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{932 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a8652c5651033573cfd6f09b789d64713}\label{namespacemom__lateral__mixing__coeffs_a8652c5651033573cfd6f09b789d64713}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!calc\_resoln\_function@{calc\_resoln\_function}}
\index{calc\_resoln\_function@{calc\_resoln\_function}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{calc\_resoln\_function()}{calc\_resoln\_function()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+resoln\+\_\+function (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1thermo__var__ptrs}{thermo\+\_\+var\+\_\+ptrs}}), intent(in)}]{tv,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Calculates and stores the non-\/dimensional resolution functions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\end{DoxyParams}


Definition at line 190 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{191   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{192 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{193   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamic variables}}
\DoxyCodeLine{194   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{195   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{196   \textcolor{keywordtype}{type}(VarMix\_CS),                          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}}
\DoxyCodeLine{197 }
\DoxyCodeLine{198   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{199   \textcolor{comment}{! Depending on the power-\/function being used, dimensional rescaling may be limited, so some}}
\DoxyCodeLine{200   \textcolor{comment}{! of the following variables have units that depend on that power.}}
\DoxyCodeLine{201 \textcolor{keywordtype}{  real} :: cg1\_q  \textcolor{comment}{! The gravity wave speed interpolated to q points [L T-\/1 \string~> m s-\/1] or [m s-\/1].}}
\DoxyCodeLine{202 \textcolor{keywordtype}{  real} :: cg1\_u  \textcolor{comment}{! The gravity wave speed interpolated to u points [L T-\/1 \string~> m s-\/1] or [m s-\/1].}}
\DoxyCodeLine{203 \textcolor{keywordtype}{  real} :: cg1\_v  \textcolor{comment}{! The gravity wave speed interpolated to v points [L T-\/1 \string~> m s-\/1] or [m s-\/1].}}
\DoxyCodeLine{204 \textcolor{keywordtype}{  real} :: dx\_term \textcolor{comment}{! A term in the denominator [L2 T-\/2 \string~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{205   \textcolor{keywordtype}{integer} :: power\_2}
\DoxyCodeLine{206   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz}
\DoxyCodeLine{207   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{208   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{209   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{210 }
\DoxyCodeLine{211   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_resoln\_function:"{}}// \&}
\DoxyCodeLine{212          \textcolor{stringliteral}{"{}Module must be initialized before it is used."{}})}
\DoxyCodeLine{213   \textcolor{keywordflow}{if} (cs\%calculate\_cg1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{214     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%cg1)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{215       \textcolor{stringliteral}{"{}calc\_resoln\_function: \%cg1 is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{216     \textcolor{keywordflow}{if} (cs\%khth\_use\_ebt\_struct) \textcolor{keywordflow}{then}}
\DoxyCodeLine{217       \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%ebt\_struct)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{218         \textcolor{stringliteral}{"{}calc\_resoln\_function: \%ebt\_struct is not associated with RESOLN\_USE\_EBT."{}})}
\DoxyCodeLine{219       \textcolor{keywordflow}{if} (cs\%Resoln\_use\_ebt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{220         \textcolor{comment}{! Both resolution fn and vertical structure are using EBT}}
\DoxyCodeLine{221         \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs\%cg1, cs\%wave\_speed\_CSp, modal\_structure=cs\%ebt\_struct)}
\DoxyCodeLine{222       \textcolor{keywordflow}{else}}
\DoxyCodeLine{223         \textcolor{comment}{! Use EBT to get vertical structure first and then re-\/calculate cg1 using first baroclinic mode}}
\DoxyCodeLine{224         \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs\%cg1, cs\%wave\_speed\_CSp, modal\_structure=cs\%ebt\_struct, \&}
\DoxyCodeLine{225                         use\_ebt\_mode=.true.)}
\DoxyCodeLine{226         \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs\%cg1, cs\%wave\_speed\_CSp)}
\DoxyCodeLine{227 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{228       \textcolor{keyword}{call }pass\_var(cs\%ebt\_struct, g\%Domain)}
\DoxyCodeLine{229     \textcolor{keywordflow}{else}}
\DoxyCodeLine{230       \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs\%cg1, cs\%wave\_speed\_CSp)}
\DoxyCodeLine{231 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{232 }
\DoxyCodeLine{233     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_cg1, cs\%cg1, g\%Domain)}
\DoxyCodeLine{234     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_cg1, g\%Domain)}
\DoxyCodeLine{235 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{236 }
\DoxyCodeLine{237   \textcolor{comment}{! Calculate and store the ratio between deformation radius and grid-\/spacing}}
\DoxyCodeLine{238   \textcolor{comment}{! at h-\/points [nondim].}}
\DoxyCodeLine{239   \textcolor{keywordflow}{if} (cs\%calculate\_rd\_dx) \textcolor{keywordflow}{then}}
\DoxyCodeLine{240     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Rd\_dx\_h)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{241       \textcolor{stringliteral}{"{}calc\_resoln\_function: \%Rd\_dx\_h is not associated with calculate\_rd\_dx."{}})}
\DoxyCodeLine{242     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{243     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{244       cs\%Rd\_dx\_h(i,j) = cs\%cg1(i,j) / \&}
\DoxyCodeLine{245             (sqrt(cs\%f2\_dx2\_h(i,j) + cs\%cg1(i,j)*cs\%beta\_dx2\_h(i,j)))}
\DoxyCodeLine{246 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{247     \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{248       \textcolor{keywordflow}{if} (cs\%id\_Rd\_dx > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Rd\_dx, cs\%Rd\_dx\_h, cs\%diag)}
\DoxyCodeLine{249 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{250 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{251 }
\DoxyCodeLine{252   \textcolor{keywordflow}{if} (.not. cs\%calculate\_res\_fns) \textcolor{keywordflow}{return}}
\DoxyCodeLine{253 }
\DoxyCodeLine{254   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Res\_fn\_h)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{255     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%Res\_fn\_h is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{256   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Res\_fn\_q)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{257     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%Res\_fn\_q is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{258   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Res\_fn\_u)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{259     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%Res\_fn\_u is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{260   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%Res\_fn\_v)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{261     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%Res\_fn\_v is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{262   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%f2\_dx2\_h)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{263     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%f2\_dx2\_h is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{264   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%f2\_dx2\_q)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{265     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%f2\_dx2\_q is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{266   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%f2\_dx2\_u)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{267     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%f2\_dx2\_u is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{268   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%f2\_dx2\_v)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{269     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%f2\_dx2\_v is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{270   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%beta\_dx2\_h)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{271     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%beta\_dx2\_h is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{272   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%beta\_dx2\_q)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{273     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%beta\_dx2\_q is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{274   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%beta\_dx2\_u)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{275     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%beta\_dx2\_u is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{276   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%beta\_dx2\_v)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{277     \textcolor{stringliteral}{"{}calc\_resoln\_function: \%beta\_dx2\_v is not associated with Resoln\_scaled\_Kh."{}})}
\DoxyCodeLine{278 }
\DoxyCodeLine{279   \textcolor{comment}{!   Do this calculation on the extent used in MOM\_hor\_visc.F90, and}}
\DoxyCodeLine{280   \textcolor{comment}{! MOM\_tracer.F90 so that no halo update is needed.}}
\DoxyCodeLine{281 }
\DoxyCodeLine{282 \textcolor{comment}{!\$OMP parallel default(none) shared(is,ie,js,je,Ieq,Jeq,CS,US) \&}}
\DoxyCodeLine{283 \textcolor{comment}{!\$OMP                       private(dx\_term,cg1\_q,power\_2,cg1\_u,cg1\_v)}}
\DoxyCodeLine{284   \textcolor{keywordflow}{if} (cs\%Res\_fn\_power\_visc >= 100) \textcolor{keywordflow}{then}}
\DoxyCodeLine{285 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{286     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{287       dx\_term = cs\%f2\_dx2\_h(i,j) + cs\%cg1(i,j)*cs\%beta\_dx2\_h(i,j)}
\DoxyCodeLine{288       \textcolor{keywordflow}{if} ((cs\%Res\_coef\_visc * cs\%cg1(i,j))**2 > dx\_term) \textcolor{keywordflow}{then}}
\DoxyCodeLine{289         cs\%Res\_fn\_h(i,j) = 0.0}
\DoxyCodeLine{290       \textcolor{keywordflow}{else}}
\DoxyCodeLine{291         cs\%Res\_fn\_h(i,j) = 1.0}
\DoxyCodeLine{292 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{293 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{294 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{295     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{296       cg1\_q = 0.25 * ((cs\%cg1(i,j) + cs\%cg1(i+1,j+1)) + (cs\%cg1(i+1,j) + cs\%cg1(i,j+1)))}
\DoxyCodeLine{297       dx\_term = cs\%f2\_dx2\_q(i,j) +  cg1\_q * cs\%beta\_dx2\_q(i,j)}
\DoxyCodeLine{298       \textcolor{keywordflow}{if} ((cs\%Res\_coef\_visc * cg1\_q)**2 > dx\_term) \textcolor{keywordflow}{then}}
\DoxyCodeLine{299         cs\%Res\_fn\_q(i,j) = 0.0}
\DoxyCodeLine{300       \textcolor{keywordflow}{else}}
\DoxyCodeLine{301         cs\%Res\_fn\_q(i,j) = 1.0}
\DoxyCodeLine{302 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{303 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{304   \textcolor{keywordflow}{elseif} (cs\%Res\_fn\_power\_visc == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{305 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{306     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{307       dx\_term = cs\%f2\_dx2\_h(i,j) + cs\%cg1(i,j)*cs\%beta\_dx2\_h(i,j)}
\DoxyCodeLine{308       cs\%Res\_fn\_h(i,j) = dx\_term / (dx\_term + (cs\%Res\_coef\_visc * cs\%cg1(i,j))**2)}
\DoxyCodeLine{309 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{310 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{311     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{312       cg1\_q = 0.25 * ((cs\%cg1(i,j) + cs\%cg1(i+1,j+1)) + (cs\%cg1(i+1,j) + cs\%cg1(i,j+1)))}
\DoxyCodeLine{313       dx\_term = cs\%f2\_dx2\_q(i,j) +  cg1\_q * cs\%beta\_dx2\_q(i,j)}
\DoxyCodeLine{314       cs\%Res\_fn\_q(i,j) = dx\_term / (dx\_term + (cs\%Res\_coef\_visc * cg1\_q)**2)}
\DoxyCodeLine{315 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{316   \textcolor{keywordflow}{elseif} (mod(cs\%Res\_fn\_power\_visc, 2) == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{317     power\_2 = cs\%Res\_fn\_power\_visc / 2}
\DoxyCodeLine{318 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{319     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{320       dx\_term = (us\%L\_T\_to\_m\_s**2*(cs\%f2\_dx2\_h(i,j) + cs\%cg1(i,j)*cs\%beta\_dx2\_h(i,j)))**power\_2}
\DoxyCodeLine{321       cs\%Res\_fn\_h(i,j) = dx\_term / \&}
\DoxyCodeLine{322           (dx\_term + (cs\%Res\_coef\_visc * us\%L\_T\_to\_m\_s*cs\%cg1(i,j))**cs\%Res\_fn\_power\_visc)}
\DoxyCodeLine{323 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{324 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{325     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{326       cg1\_q = 0.25 * ((cs\%cg1(i,j) + cs\%cg1(i+1,j+1)) + (cs\%cg1(i+1,j) + cs\%cg1(i,j+1)))}
\DoxyCodeLine{327       dx\_term = (us\%L\_T\_to\_m\_s**2*(cs\%f2\_dx2\_q(i,j) + cg1\_q * cs\%beta\_dx2\_q(i,j)))**power\_2}
\DoxyCodeLine{328       cs\%Res\_fn\_q(i,j) = dx\_term / \&}
\DoxyCodeLine{329           (dx\_term + (cs\%Res\_coef\_visc * us\%L\_T\_to\_m\_s*cg1\_q)**cs\%Res\_fn\_power\_visc)}
\DoxyCodeLine{330 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{331   \textcolor{keywordflow}{else}}
\DoxyCodeLine{332 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{333     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{334       dx\_term = (us\%L\_T\_to\_m\_s*sqrt(cs\%f2\_dx2\_h(i,j) + \&}
\DoxyCodeLine{335                                     cs\%cg1(i,j)*cs\%beta\_dx2\_h(i,j)))**cs\%Res\_fn\_power\_visc}
\DoxyCodeLine{336       cs\%Res\_fn\_h(i,j) = dx\_term / \&}
\DoxyCodeLine{337          (dx\_term + (cs\%Res\_coef\_visc * us\%L\_T\_to\_m\_s*cs\%cg1(i,j))**cs\%Res\_fn\_power\_visc)}
\DoxyCodeLine{338 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{339 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{340     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{341       cg1\_q = 0.25 * ((cs\%cg1(i,j) + cs\%cg1(i+1,j+1)) + (cs\%cg1(i+1,j) + cs\%cg1(i,j+1)))}
\DoxyCodeLine{342       dx\_term = (us\%L\_T\_to\_m\_s*sqrt(cs\%f2\_dx2\_q(i,j) + \&}
\DoxyCodeLine{343                                     cg1\_q * cs\%beta\_dx2\_q(i,j)))**cs\%Res\_fn\_power\_visc}
\DoxyCodeLine{344       cs\%Res\_fn\_q(i,j) = dx\_term / \&}
\DoxyCodeLine{345           (dx\_term + (cs\%Res\_coef\_visc * us\%L\_T\_to\_m\_s*cg1\_q)**cs\%Res\_fn\_power\_visc)}
\DoxyCodeLine{346 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{347 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{348 }
\DoxyCodeLine{349   \textcolor{keywordflow}{if} (cs\%interpolate\_Res\_fn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{350     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{351       cs\%Res\_fn\_u(i,j) = 0.5*(cs\%Res\_fn\_h(i,j) + cs\%Res\_fn\_h(i+1,j))}
\DoxyCodeLine{352 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{353     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{354       cs\%Res\_fn\_v(i,j) = 0.5*(cs\%Res\_fn\_h(i,j) + cs\%Res\_fn\_h(i,j+1))}
\DoxyCodeLine{355 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{356   \textcolor{keywordflow}{else} \textcolor{comment}{! .not.CS\%interpolate\_Res\_fn}}
\DoxyCodeLine{357     \textcolor{keywordflow}{if} (cs\%Res\_fn\_power\_khth >= 100) \textcolor{keywordflow}{then}}
\DoxyCodeLine{358 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{359       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{360         cg1\_u = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i+1,j))}
\DoxyCodeLine{361         dx\_term = cs\%f2\_dx2\_u(i,j) + cg1\_u * cs\%beta\_dx2\_u(i,j)}
\DoxyCodeLine{362         \textcolor{keywordflow}{if} ((cs\%Res\_coef\_khth * cg1\_u)**2 > dx\_term) \textcolor{keywordflow}{then}}
\DoxyCodeLine{363           cs\%Res\_fn\_u(i,j) = 0.0}
\DoxyCodeLine{364         \textcolor{keywordflow}{else}}
\DoxyCodeLine{365           cs\%Res\_fn\_u(i,j) = 1.0}
\DoxyCodeLine{366 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{367 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{368 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{369       \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{370         cg1\_v = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i,j+1))}
\DoxyCodeLine{371         dx\_term = cs\%f2\_dx2\_v(i,j) + cg1\_v * cs\%beta\_dx2\_v(i,j)}
\DoxyCodeLine{372         \textcolor{keywordflow}{if} ((cs\%Res\_coef\_khth * cg1\_v)**2 > dx\_term) \textcolor{keywordflow}{then}}
\DoxyCodeLine{373           cs\%Res\_fn\_v(i,j) = 0.0}
\DoxyCodeLine{374         \textcolor{keywordflow}{else}}
\DoxyCodeLine{375           cs\%Res\_fn\_v(i,j) = 1.0}
\DoxyCodeLine{376 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{377 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{378     \textcolor{keywordflow}{elseif} (cs\%Res\_fn\_power\_khth == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{379 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{380       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{381         cg1\_u = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i+1,j))}
\DoxyCodeLine{382         dx\_term = cs\%f2\_dx2\_u(i,j) + cg1\_u * cs\%beta\_dx2\_u(i,j)}
\DoxyCodeLine{383         cs\%Res\_fn\_u(i,j) = dx\_term / (dx\_term + (cs\%Res\_coef\_khth * cg1\_u)**2)}
\DoxyCodeLine{384 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{385 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{386       \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{387         cg1\_v = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i,j+1))}
\DoxyCodeLine{388         dx\_term = cs\%f2\_dx2\_v(i,j) + cg1\_v * cs\%beta\_dx2\_v(i,j)}
\DoxyCodeLine{389         cs\%Res\_fn\_v(i,j) = dx\_term / (dx\_term + (cs\%Res\_coef\_khth * cg1\_v)**2)}
\DoxyCodeLine{390 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{391     \textcolor{keywordflow}{elseif} (mod(cs\%Res\_fn\_power\_khth, 2) == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{392       power\_2 = cs\%Res\_fn\_power\_khth / 2}
\DoxyCodeLine{393 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{394       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{395         cg1\_u = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i+1,j))}
\DoxyCodeLine{396         dx\_term = (us\%L\_T\_to\_m\_s**2 * (cs\%f2\_dx2\_u(i,j) + cg1\_u * cs\%beta\_dx2\_u(i,j)))**power\_2}
\DoxyCodeLine{397         cs\%Res\_fn\_u(i,j) = dx\_term / \&}
\DoxyCodeLine{398             (dx\_term + (cs\%Res\_coef\_khth * us\%L\_T\_to\_m\_s*cg1\_u)**cs\%Res\_fn\_power\_khth)}
\DoxyCodeLine{399 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{400 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{401       \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{402         cg1\_v = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i,j+1))}
\DoxyCodeLine{403         dx\_term = (us\%L\_T\_to\_m\_s**2 * (cs\%f2\_dx2\_v(i,j) + cg1\_v * cs\%beta\_dx2\_v(i,j)))**power\_2}
\DoxyCodeLine{404         cs\%Res\_fn\_v(i,j) = dx\_term / \&}
\DoxyCodeLine{405             (dx\_term + (cs\%Res\_coef\_khth * us\%L\_T\_to\_m\_s*cg1\_v)**cs\%Res\_fn\_power\_khth)}
\DoxyCodeLine{406 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{407     \textcolor{keywordflow}{else}}
\DoxyCodeLine{408 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{409       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{410         cg1\_u = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i+1,j))}
\DoxyCodeLine{411         dx\_term = (us\%L\_T\_to\_m\_s*sqrt(cs\%f2\_dx2\_u(i,j) + \&}
\DoxyCodeLine{412                                       cg1\_u * cs\%beta\_dx2\_u(i,j)))**cs\%Res\_fn\_power\_khth}
\DoxyCodeLine{413         cs\%Res\_fn\_u(i,j) = dx\_term / \&}
\DoxyCodeLine{414             (dx\_term + (cs\%Res\_coef\_khth * us\%L\_T\_to\_m\_s*cg1\_u)**cs\%Res\_fn\_power\_khth)}
\DoxyCodeLine{415 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{416 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{417       \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{418         cg1\_v = 0.5 * (cs\%cg1(i,j) + cs\%cg1(i,j+1))}
\DoxyCodeLine{419         dx\_term = (us\%L\_T\_to\_m\_s*sqrt(cs\%f2\_dx2\_v(i,j) + \&}
\DoxyCodeLine{420                                       cg1\_v * cs\%beta\_dx2\_v(i,j)))**cs\%Res\_fn\_power\_khth}
\DoxyCodeLine{421         cs\%Res\_fn\_v(i,j) = dx\_term / \&}
\DoxyCodeLine{422             (dx\_term + (cs\%Res\_coef\_khth * us\%L\_T\_to\_m\_s*cg1\_v)**cs\%Res\_fn\_power\_khth)}
\DoxyCodeLine{423 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{424 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{425 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{426 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{427 }
\DoxyCodeLine{428   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{429     \textcolor{keywordflow}{if} (cs\%id\_Res\_fn > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Res\_fn, cs\%Res\_fn\_h, cs\%diag)}
\DoxyCodeLine{430 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{431 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a1afa768a2df4c937842247cea00d184a}\label{namespacemom__lateral__mixing__coeffs_a1afa768a2df4c937842247cea00d184a}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!calc\_slope\_functions@{calc\_slope\_functions}}
\index{calc\_slope\_functions@{calc\_slope\_functions}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{calc\_slope\_functions()}{calc\_slope\_functions()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+slope\+\_\+functions (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1thermo__var__ptrs}{thermo\+\_\+var\+\_\+ptrs}}), intent(in)}]{tv,  }\item[{real, intent(in)}]{dt,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), optional, pointer}]{O\+BC }\end{DoxyParamCaption})}



Calculates and stores functions of isopycnal slopes, e.\+g. Sx, Sy, S$\ast$N, mostly used in the Visbeck et al. style scaling of diffusivity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 436 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{437   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{438   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{439   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{440 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{441   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamic variables}}
\DoxyCodeLine{442 \textcolor{keywordtype}{  real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T \string~> s]}}
\DoxyCodeLine{443   \textcolor{keywordtype}{type}(VarMix\_CS),                          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}}
\DoxyCodeLine{444   \textcolor{keywordtype}{type}(ocean\_OBC\_type),           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{445   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{446 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G), SZK\_(G)+1)} :: \&}
\DoxyCodeLine{447     e             \textcolor{comment}{! The interface heights relative to mean sea level [Z \string~> m].}}
\DoxyCodeLine{448 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G), SZJ\_(G), SZK\_(G)+1)} :: N2\_u \textcolor{comment}{! Square of Brunt-\/Vaisala freq at u-\/points [T-\/2 \string~> s-\/2]}}
\DoxyCodeLine{449 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJB\_(G), SZK\_(G)+1)} :: N2\_v \textcolor{comment}{! Square of Brunt-\/Vaisala freq at v-\/points [T-\/2 \string~> s-\/2]}}
\DoxyCodeLine{450 }
\DoxyCodeLine{451   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}MOM\_lateral\_mixing\_coeffs.F90, calc\_slope\_functions:"{}}//\&}
\DoxyCodeLine{452          \textcolor{stringliteral}{"{}Module must be initialized before it is used."{}})}
\DoxyCodeLine{453 }
\DoxyCodeLine{454   \textcolor{keywordflow}{if} (cs\%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{then}}
\DoxyCodeLine{455     \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, e, halo\_size=2)}
\DoxyCodeLine{456     \textcolor{keywordflow}{if} (cs\%use\_stored\_slopes) \textcolor{keywordflow}{then}}
\DoxyCodeLine{457       \textcolor{keyword}{call }calc\_isoneutral\_slopes(g, gv, us, h, e, tv, dt*cs\%kappa\_smooth, \&}
\DoxyCodeLine{458                                   cs\%slope\_x, cs\%slope\_y, n2\_u, n2\_v, 1, obc=obc)}
\DoxyCodeLine{459       \textcolor{keyword}{call }calc\_visbeck\_coeffs(h, cs\%slope\_x, cs\%slope\_y, n2\_u, n2\_v, g, gv, us, cs, obc=obc)}
\DoxyCodeLine{460 \textcolor{comment}{!     call calc\_slope\_functions\_using\_just\_e(h, G, CS, e, .false.)}}
\DoxyCodeLine{461     \textcolor{keywordflow}{else}}
\DoxyCodeLine{462       \textcolor{comment}{!call calc\_isoneutral\_slopes(G, GV, h, e, tv, dt*CS\%kappa\_smooth, CS\%slope\_x, CS\%slope\_y)}}
\DoxyCodeLine{463       \textcolor{keyword}{call }calc\_slope\_functions\_using\_just\_e(h, g, gv, us, cs, e, .true., obc=obc)}
\DoxyCodeLine{464 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{465 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{466 }
\DoxyCodeLine{467   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{468     \textcolor{keywordflow}{if} (cs\%id\_SN\_u > 0) \textcolor{keyword}{call }post\_data(cs\%id\_SN\_u, cs\%SN\_u, cs\%diag)}
\DoxyCodeLine{469     \textcolor{keywordflow}{if} (cs\%id\_SN\_v > 0) \textcolor{keyword}{call }post\_data(cs\%id\_SN\_v, cs\%SN\_v, cs\%diag)}
\DoxyCodeLine{470     \textcolor{keywordflow}{if} (cs\%id\_L2u > 0)  \textcolor{keyword}{call }post\_data(cs\%id\_L2u, cs\%L2u, cs\%diag)}
\DoxyCodeLine{471     \textcolor{keywordflow}{if} (cs\%id\_L2v > 0)  \textcolor{keyword}{call }post\_data(cs\%id\_L2v, cs\%L2v, cs\%diag)}
\DoxyCodeLine{472     \textcolor{keywordflow}{if} (cs\%calculate\_Eady\_growth\_rate .and. cs\%use\_stored\_slopes) \textcolor{keywordflow}{then}}
\DoxyCodeLine{473       \textcolor{keywordflow}{if} (cs\%id\_N2\_u > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N2\_u, n2\_u, cs\%diag)}
\DoxyCodeLine{474       \textcolor{keywordflow}{if} (cs\%id\_N2\_v > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N2\_v, n2\_v, cs\%diag)}
\DoxyCodeLine{475 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{476 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{477 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a9947860318104ed1662ff4f9d671f92d}\label{namespacemom__lateral__mixing__coeffs_a9947860318104ed1662ff4f9d671f92d}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!calc\_slope\_functions\_using\_just\_e@{calc\_slope\_functions\_using\_just\_e}}
\index{calc\_slope\_functions\_using\_just\_e@{calc\_slope\_functions\_using\_just\_e}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{calc\_slope\_functions\_using\_just\_e()}{calc\_slope\_functions\_using\_just\_e()}}
{\footnotesize\ttfamily subroutine mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{e,  }\item[{logical, intent(in)}]{calculate\+\_\+slopes,  }\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The original calc\+\_\+slope\+\_\+function() that calculated slopes using interface positions only, not accounting for density variations. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\mbox{\texttt{ in}}  & {\em e} & Interface position \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em calculate\+\_\+slopes} & If true, calculate slopes internally otherwise use slopes stored in CS \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 646 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{647   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{648 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{649   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{650   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{651   \textcolor{keywordtype}{type}(VarMix\_CS),                            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}}
\DoxyCodeLine{652 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: e\textcolor{comment}{  !< Interface position [Z \string~> m]}}
\DoxyCodeLine{653   \textcolor{keywordtype}{logical},                                    \textcolor{keywordtype}{intent(in)}    :: calculate\_slopes\textcolor{comment}{ !< If true, calculate slopes internally}}
\DoxyCodeLine{654 \textcolor{comment}{                                                                  !! otherwise use slopes stored in CS}}
\DoxyCodeLine{655   \textcolor{keywordtype}{type}(ocean\_OBC\_type),             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{656   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{657 \textcolor{keywordtype}{  real} :: E\_x(SZIB\_(G), SZJ\_(G))  \textcolor{comment}{! X-\/slope of interface at u points [nondim] (for diagnostics)}}
\DoxyCodeLine{658 \textcolor{keywordtype}{  real} :: E\_y(SZI\_(G), SZJB\_(G))  \textcolor{comment}{! Y-\/slope of interface at v points [nondim] (for diagnostics)}}
\DoxyCodeLine{659 \textcolor{keywordtype}{  real} :: H\_cutoff      \textcolor{comment}{! Local estimate of a minimum thickness for masking [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{660 \textcolor{keywordtype}{  real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{661                         \textcolor{comment}{! in roundoff and can be neglected [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{662 \textcolor{keywordtype}{  real} :: S2            \textcolor{comment}{! Interface slope squared [nondim]}}
\DoxyCodeLine{663 \textcolor{keywordtype}{  real} :: N2            \textcolor{comment}{! Brunt-\/Vaisala frequency squared [T-\/2 \string~> s-\/2]}}
\DoxyCodeLine{664 \textcolor{keywordtype}{  real} :: Hup, Hdn      \textcolor{comment}{! Thickness from above, below [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{665 \textcolor{keywordtype}{  real} :: H\_geom        \textcolor{comment}{! The geometric mean of Hup*Hdn [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{666 \textcolor{keywordtype}{  real} :: one\_meter     \textcolor{comment}{! One meter in thickness units [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{667   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz}
\DoxyCodeLine{668   \textcolor{keywordtype}{integer} :: i, j, k, kb\_max}
\DoxyCodeLine{669   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{670 \textcolor{keywordtype}{  real}    :: S2N2\_u\_local(SZIB\_(G), SZJ\_(G),SZK\_(G))}
\DoxyCodeLine{671 \textcolor{keywordtype}{  real}    :: S2N2\_v\_local(SZI\_(G), SZJB\_(G),SZK\_(G))}
\DoxyCodeLine{672   \textcolor{keywordtype}{logical} :: local\_open\_u\_BC, local\_open\_v\_BC}
\DoxyCodeLine{673 }
\DoxyCodeLine{674   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_slope\_function:"{}}// \&}
\DoxyCodeLine{675          \textcolor{stringliteral}{"{}Module must be initialized before it is used."{}})}
\DoxyCodeLine{676   \textcolor{keywordflow}{if} (.not. cs\%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{return}}
\DoxyCodeLine{677   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%SN\_u)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_slope\_function:"{}}// \&}
\DoxyCodeLine{678          \textcolor{stringliteral}{"{}\%SN\_u is not associated with use\_variable\_mixing."{}})}
\DoxyCodeLine{679   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%SN\_v)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_slope\_function:"{}}// \&}
\DoxyCodeLine{680          \textcolor{stringliteral}{"{}\%SN\_v is not associated with use\_variable\_mixing."{}})}
\DoxyCodeLine{681 }
\DoxyCodeLine{682   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{683 }
\DoxyCodeLine{684   local\_open\_u\_bc = .false.}
\DoxyCodeLine{685   local\_open\_v\_bc = .false.}
\DoxyCodeLine{686   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{687     local\_open\_u\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{688     local\_open\_v\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{689 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{690 }
\DoxyCodeLine{691   one\_meter = 1.0 * gv\%m\_to\_H}
\DoxyCodeLine{692   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{693   h\_cutoff = real(2*nz) * (gv\%Angstrom\_H + h\_neglect)}
\DoxyCodeLine{694 }
\DoxyCodeLine{695   \textcolor{comment}{! To set the length scale based on the deformation radius, use wave\_speed to}}
\DoxyCodeLine{696   \textcolor{comment}{! calculate the first-\/mode gravity wave speed and then blend the equatorial}}
\DoxyCodeLine{697   \textcolor{comment}{! and midlatitude deformation radii, using calc\_resoln\_function as a template.}}
\DoxyCodeLine{698 }
\DoxyCodeLine{699   \textcolor{comment}{!\$OMP parallel do default(shared) private(E\_x,E\_y,S2,Hdn,Hup,H\_geom,N2)}}
\DoxyCodeLine{700   \textcolor{keywordflow}{do} k=nz,cs\%VarMix\_Ktop,-\/1}
\DoxyCodeLine{701 }
\DoxyCodeLine{702     \textcolor{keywordflow}{if} (calculate\_slopes) \textcolor{keywordflow}{then}}
\DoxyCodeLine{703       \textcolor{comment}{! Calculate the interface slopes E\_x and E\_y and u-\/ and v-\/ points respectively}}
\DoxyCodeLine{704       \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{705         e\_x(i,j) = us\%Z\_to\_L*(e(i+1,j,k)-\/e(i,j,k))*g\%IdxCu(i,j)}
\DoxyCodeLine{706         \textcolor{comment}{! Mask slopes where interface intersects topography}}
\DoxyCodeLine{707         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i+1,j,k)) < h\_cutoff) e\_x(i,j) = 0.}
\DoxyCodeLine{708 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{709       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{710         e\_y(i,j) = us\%Z\_to\_L*(e(i,j+1,k)-\/e(i,j,k))*g\%IdyCv(i,j)}
\DoxyCodeLine{711         \textcolor{comment}{! Mask slopes where interface intersects topography}}
\DoxyCodeLine{712         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i,j+1,k)) < h\_cutoff) e\_y(i,j) = 0.}
\DoxyCodeLine{713 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{714     \textcolor{keywordflow}{else}}
\DoxyCodeLine{715       \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{716         e\_x(i,j) = cs\%slope\_x(i,j,k)}
\DoxyCodeLine{717         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i+1,j,k)) < h\_cutoff) e\_x(i,j) = 0.}
\DoxyCodeLine{718 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{719       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{720         e\_y(i,j) = cs\%slope\_y(i,j,k)}
\DoxyCodeLine{721         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i,j+1,k)) < h\_cutoff) e\_y(i,j) = 0.}
\DoxyCodeLine{722 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{723 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{724 }
\DoxyCodeLine{725     \textcolor{comment}{! Calculate N*S*h from this layer and add to the sum}}
\DoxyCodeLine{726     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{727       s2 = ( e\_x(i,j)**2  + 0.25*( \&}
\DoxyCodeLine{728             (e\_y(i,j)**2+e\_y(i+1,j-\/1)**2)+(e\_y(i+1,j)**2+e\_y(i,j-\/1)**2) ) )}
\DoxyCodeLine{729       hdn = 2.*h(i,j,k)*h(i,j,k-\/1) / (h(i,j,k) + h(i,j,k-\/1) + h\_neglect)}
\DoxyCodeLine{730       hup = 2.*h(i+1,j,k)*h(i+1,j,k-\/1) / (h(i+1,j,k) + h(i+1,j,k-\/1) + h\_neglect)}
\DoxyCodeLine{731       h\_geom = sqrt(hdn*hup)}
\DoxyCodeLine{732       n2 = gv\%g\_prime(k)*us\%L\_to\_Z**2 / (gv\%H\_to\_Z * max(hdn,hup,one\_meter))}
\DoxyCodeLine{733       \textcolor{keywordflow}{if} (min(h(i,j,k-\/1), h(i+1,j,k-\/1), h(i,j,k), h(i+1,j,k)) < h\_cutoff) \&}
\DoxyCodeLine{734         s2 = 0.0}
\DoxyCodeLine{735       s2n2\_u\_local(i,j,k) = (h\_geom * gv\%H\_to\_Z) * s2 * n2}
\DoxyCodeLine{736 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{737     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{738       s2 = ( e\_y(i,j)**2  + 0.25*( \&}
\DoxyCodeLine{739             (e\_x(i,j)**2+e\_x(i-\/1,j+1)**2)+(e\_x(i,j+1)**2+e\_x(i-\/1,j)**2) ) )}
\DoxyCodeLine{740       hdn = 2.*h(i,j,k)*h(i,j,k-\/1) / (h(i,j,k) + h(i,j,k-\/1) + h\_neglect)}
\DoxyCodeLine{741       hup = 2.*h(i,j+1,k)*h(i,j+1,k-\/1) / (h(i,j+1,k) + h(i,j+1,k-\/1) + h\_neglect)}
\DoxyCodeLine{742       h\_geom = sqrt(hdn*hup)}
\DoxyCodeLine{743       n2 = gv\%g\_prime(k)*us\%L\_to\_Z**2 / (gv\%H\_to\_Z * max(hdn,hup,one\_meter))}
\DoxyCodeLine{744       \textcolor{keywordflow}{if} (min(h(i,j,k-\/1), h(i,j+1,k-\/1), h(i,j,k), h(i,j+1,k)) < h\_cutoff) \&}
\DoxyCodeLine{745         s2 = 0.0}
\DoxyCodeLine{746       s2n2\_v\_local(i,j,k) = (h\_geom * gv\%H\_to\_Z) * s2 * n2}
\DoxyCodeLine{747 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{748 }
\DoxyCodeLine{749 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! k}}
\DoxyCodeLine{750   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{751   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{752     \textcolor{keywordflow}{do} i=is-\/1,ie ; cs\%SN\_u(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{753     \textcolor{keywordflow}{do} k=nz,cs\%VarMix\_Ktop,-\/1 ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{754       cs\%SN\_u(i,j) = cs\%SN\_u(i,j) + s2n2\_u\_local(i,j,k)}
\DoxyCodeLine{755 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{756     \textcolor{comment}{! SN above contains S\string^2*N\string^2*H, convert to vertical average of S*N}}
\DoxyCodeLine{757     \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{758       \textcolor{comment}{!SN\_u(I,j) = sqrt( SN\_u(I,j) / ( max(G\%bathyT(I,j), G\%bathyT(I+1,j)) + GV\%Angstrom\_Z ) ))}}
\DoxyCodeLine{759       \textcolor{comment}{!The code below behaves better than the line above. Not sure why? AJA}}
\DoxyCodeLine{760       \textcolor{keywordflow}{if} ( min(g\%bathyT(i,j), g\%bathyT(i+1,j)) > h\_cutoff*gv\%H\_to\_Z ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{761         cs\%SN\_u(i,j) = g\%mask2dCu(i,j) * sqrt( cs\%SN\_u(i,j) / \&}
\DoxyCodeLine{762                                                (max(g\%bathyT(i,j), g\%bathyT(i+1,j))) )}
\DoxyCodeLine{763       \textcolor{keywordflow}{else}}
\DoxyCodeLine{764         cs\%SN\_u(i,j) = 0.0}
\DoxyCodeLine{765 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{766       \textcolor{keywordflow}{if} (local\_open\_u\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{767         l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{768 }
\DoxyCodeLine{769         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{770           \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{771             cs\%SN\_u(i,j) = 0.}
\DoxyCodeLine{772 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{773 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{774 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{775 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{776 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{777   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{778   \textcolor{keywordflow}{do} j=js-\/1,je}
\DoxyCodeLine{779     \textcolor{keywordflow}{do} i=is,ie ; cs\%SN\_v(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{780     \textcolor{keywordflow}{do} k=nz,cs\%VarMix\_Ktop,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{781       cs\%SN\_v(i,j) = cs\%SN\_v(i,j) + s2n2\_v\_local(i,j,k)}
\DoxyCodeLine{782 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{783     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{784       \textcolor{comment}{!SN\_v(i,J) = sqrt( SN\_v(i,J) / ( max(G\%bathyT(i,J), G\%bathyT(i,J+1)) + GV\%Angstrom\_Z ) ))}}
\DoxyCodeLine{785       \textcolor{comment}{!The code below behaves better than the line above. Not sure why? AJA}}
\DoxyCodeLine{786       \textcolor{keywordflow}{if} ( min(g\%bathyT(i,j), g\%bathyT(i+1,j)) > h\_cutoff*gv\%H\_to\_Z ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{787         cs\%SN\_v(i,j) = g\%mask2dCv(i,j) * sqrt( cs\%SN\_v(i,j) / \&}
\DoxyCodeLine{788                                                (max(g\%bathyT(i,j), g\%bathyT(i,j+1))) )}
\DoxyCodeLine{789       \textcolor{keywordflow}{else}}
\DoxyCodeLine{790         cs\%SN\_v(i,j) = 0.0}
\DoxyCodeLine{791 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{792       \textcolor{keywordflow}{if} (local\_open\_v\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{793         l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{794 }
\DoxyCodeLine{795         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{796           \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{797             cs\%SN\_v(i,j) = 0.}
\DoxyCodeLine{798 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{799 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{800 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{801 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{802 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{803 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_ac7307f59d005a7b45a642f94eee7c8be}\label{namespacemom__lateral__mixing__coeffs_ac7307f59d005a7b45a642f94eee7c8be}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!calc\_visbeck\_coeffs@{calc\_visbeck\_coeffs}}
\index{calc\_visbeck\_coeffs@{calc\_visbeck\_coeffs}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{calc\_visbeck\_coeffs()}{calc\_visbeck\_coeffs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+visbeck\+\_\+coeffs (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{slope\+\_\+x,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke+1), intent(in)}]{slope\+\_\+y,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{N2\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke+1), intent(in)}]{N2\+\_\+v,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates factors used when setting diffusivity coefficients similar to Visbeck et al. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em slope\+\_\+x} & Zonal isoneutral slope \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+u} & Buoyancy (Brunt-\/\+Vaisala) frequency at u-\/points \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em slope\+\_\+y} & Meridional isoneutral slope \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+v} & Buoyancy (Brunt-\/\+Vaisala) frequency at v-\/points \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 481 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{482   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{483   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{484 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},    \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{485 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: slope\_x\textcolor{comment}{ !< Zonal isoneutral slope}}
\DoxyCodeLine{486 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: N2\_u\textcolor{comment}{    !< Buoyancy (Brunt-\/Vaisala) frequency}}
\DoxyCodeLine{487 \textcolor{comment}{                                                                        !! at u-\/points [T-\/2 \string~> s-\/2]}}
\DoxyCodeLine{488 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: slope\_y\textcolor{comment}{ !< Meridional isoneutral slope}}
\DoxyCodeLine{489 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: N2\_v\textcolor{comment}{    !< Buoyancy (Brunt-\/Vaisala) frequency}}
\DoxyCodeLine{490 \textcolor{comment}{                                                                        !! at v-\/points [T-\/2 \string~> s-\/2]}}
\DoxyCodeLine{491   \textcolor{keywordtype}{type}(unit\_scale\_type),                       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{492   \textcolor{keywordtype}{type}(VarMix\_CS),                             \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}}
\DoxyCodeLine{493   \textcolor{keywordtype}{type}(ocean\_OBC\_type),              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{494 }
\DoxyCodeLine{495   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{496 \textcolor{keywordtype}{  real} :: S2            \textcolor{comment}{! Interface slope squared [nondim]}}
\DoxyCodeLine{497 \textcolor{keywordtype}{  real} :: N2            \textcolor{comment}{! Positive buoyancy frequency or zero [T-\/2 \string~> s-\/2]}}
\DoxyCodeLine{498 \textcolor{keywordtype}{  real} :: Hup, Hdn      \textcolor{comment}{! Thickness from above, below [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{499 \textcolor{keywordtype}{  real} :: H\_geom        \textcolor{comment}{! The geometric mean of Hup*Hdn [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{500   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz}
\DoxyCodeLine{501   \textcolor{keywordtype}{integer} :: i, j, k, kb\_max}
\DoxyCodeLine{502   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{503 \textcolor{keywordtype}{  real} :: S2max, wNE, wSE, wSW, wNW}
\DoxyCodeLine{504 \textcolor{keywordtype}{  real} :: H\_u(SZIB\_(G)), H\_v(SZI\_(G))}
\DoxyCodeLine{505 \textcolor{keywordtype}{  real} :: S2\_u(SZIB\_(G), SZJ\_(G))}
\DoxyCodeLine{506 \textcolor{keywordtype}{  real} :: S2\_v(SZI\_(G), SZJB\_(G))}
\DoxyCodeLine{507   \textcolor{keywordtype}{logical} :: local\_open\_u\_BC, local\_open\_v\_BC}
\DoxyCodeLine{508 }
\DoxyCodeLine{509   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_slope\_function:"{}}// \&}
\DoxyCodeLine{510          \textcolor{stringliteral}{"{}Module must be initialized before it is used."{}})}
\DoxyCodeLine{511   \textcolor{keywordflow}{if} (.not. cs\%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{return}}
\DoxyCodeLine{512   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%SN\_u)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_slope\_function:"{}}// \&}
\DoxyCodeLine{513          \textcolor{stringliteral}{"{}\%SN\_u is not associated with use\_variable\_mixing."{}})}
\DoxyCodeLine{514   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs\%SN\_v)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}calc\_slope\_function:"{}}// \&}
\DoxyCodeLine{515          \textcolor{stringliteral}{"{}\%SN\_v is not associated with use\_variable\_mixing."{}})}
\DoxyCodeLine{516 }
\DoxyCodeLine{517   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{518 }
\DoxyCodeLine{519   local\_open\_u\_bc = .false.}
\DoxyCodeLine{520   local\_open\_v\_bc = .false.}
\DoxyCodeLine{521   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{522     local\_open\_u\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{523     local\_open\_v\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{524 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{525 }
\DoxyCodeLine{526   s2max = cs\%Visbeck\_S\_max**2}
\DoxyCodeLine{527 }
\DoxyCodeLine{528   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{529   \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{530     cs\%SN\_u(i,j) = 0.0}
\DoxyCodeLine{531     cs\%SN\_v(i,j) = 0.0}
\DoxyCodeLine{532 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{533 }
\DoxyCodeLine{534   \textcolor{comment}{! To set the length scale based on the deformation radius, use wave\_speed to}}
\DoxyCodeLine{535   \textcolor{comment}{! calculate the first-\/mode gravity wave speed and then blend the equatorial}}
\DoxyCodeLine{536   \textcolor{comment}{! and midlatitude deformation radii, using calc\_resoln\_function as a template.}}
\DoxyCodeLine{537 }
\DoxyCodeLine{538   \textcolor{comment}{!\$OMP parallel do default(shared) private(S2,H\_u,Hdn,Hup,H\_geom,N2,wNE,wSE,wSW,wNW)}}
\DoxyCodeLine{539   \textcolor{keywordflow}{do} j = js,je}
\DoxyCodeLine{540     \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{541       cs\%SN\_u(i,j) = 0. ; h\_u(i) = 0. ; s2\_u(i,j) = 0.}
\DoxyCodeLine{542 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{543     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{544       hdn = sqrt( h(i,j,k) * h(i+1,j,k) )}
\DoxyCodeLine{545       hup = sqrt( h(i,j,k-\/1) * h(i+1,j,k-\/1) )}
\DoxyCodeLine{546       h\_geom = sqrt( hdn * hup )}
\DoxyCodeLine{547      \textcolor{comment}{!H\_geom = H\_geom * sqrt(N2) ! WKB-\/ish}}
\DoxyCodeLine{548      \textcolor{comment}{!H\_geom = H\_geom * N2       ! WKB-\/ish}}
\DoxyCodeLine{549       wse = g\%mask2dCv(i+1,j-\/1) * ( (h(i+1,j,k)*h(i+1,j-\/1,k)) * (h(i+1,j,k-\/1)*h(i+1,j-\/1,k-\/1)) )}
\DoxyCodeLine{550       wnw = g\%mask2dCv(i  ,j  ) * ( (h(i  ,j,k)*h(i  ,j+1,k)) * (h(i  ,j,k-\/1)*h(i  ,j+1,k-\/1)) )}
\DoxyCodeLine{551       wne = g\%mask2dCv(i+1,j  ) * ( (h(i+1,j,k)*h(i+1,j+1,k)) * (h(i+1,j,k-\/1)*h(i+1,j+1,k-\/1)) )}
\DoxyCodeLine{552       wsw = g\%mask2dCv(i  ,j-\/1) * ( (h(i  ,j,k)*h(i  ,j-\/1,k)) * (h(i  ,j,k-\/1)*h(i  ,j-\/1,k-\/1)) )}
\DoxyCodeLine{553       s2 =  slope\_x(i,j,k)**2 + \&}
\DoxyCodeLine{554               ((wnw*slope\_y(i,j,k)**2 + wse*slope\_y(i+1,j-\/1,k)**2) + \&}
\DoxyCodeLine{555                (wne*slope\_y(i+1,j,k)**2 + wsw*slope\_y(i,j-\/1,k)**2) ) / \&}
\DoxyCodeLine{556               ( ((wse+wnw) + (wne+wsw)) + gv\%H\_subroundoff**4 )}
\DoxyCodeLine{557       \textcolor{keywordflow}{if} (s2max>0.) s2 = s2 * s2max / (s2 + s2max) \textcolor{comment}{! Limit S2}}
\DoxyCodeLine{558 }
\DoxyCodeLine{559       n2 = max(0., n2\_u(i,j,k))}
\DoxyCodeLine{560       cs\%SN\_u(i,j) = cs\%SN\_u(i,j) + sqrt( s2*n2 )*h\_geom}
\DoxyCodeLine{561       s2\_u(i,j) = s2\_u(i,j) + s2*h\_geom}
\DoxyCodeLine{562       h\_u(i) = h\_u(i) + h\_geom}
\DoxyCodeLine{563 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{564     \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{565       \textcolor{keywordflow}{if} (h\_u(i)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{566         cs\%SN\_u(i,j) = g\%mask2dCu(i,j) * cs\%SN\_u(i,j) / h\_u(i)}
\DoxyCodeLine{567         s2\_u(i,j) =  g\%mask2dCu(i,j) * s2\_u(i,j) / h\_u(i)}
\DoxyCodeLine{568       \textcolor{keywordflow}{else}}
\DoxyCodeLine{569         cs\%SN\_u(i,j) = 0.}
\DoxyCodeLine{570 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{571       \textcolor{keywordflow}{if} (local\_open\_u\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{572         l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{573 }
\DoxyCodeLine{574         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{575           \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{576             cs\%SN\_u(i,j) = 0.}
\DoxyCodeLine{577 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{578 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{579 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{580 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{581 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{582 }
\DoxyCodeLine{583   \textcolor{comment}{!\$OMP parallel do default(shared) private(S2,H\_v,Hdn,Hup,H\_geom,N2,wNE,wSE,wSW,wNW)}}
\DoxyCodeLine{584   \textcolor{keywordflow}{do} j = js-\/1,je}
\DoxyCodeLine{585     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{586       cs\%SN\_v(i,j) = 0. ; h\_v(i) = 0. ; s2\_v(i,j) = 0.}
\DoxyCodeLine{587 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{588     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{589       hdn = sqrt( h(i,j,k) * h(i,j+1,k) )}
\DoxyCodeLine{590       hup = sqrt( h(i,j,k-\/1) * h(i,j+1,k-\/1) )}
\DoxyCodeLine{591       h\_geom = sqrt( hdn * hup )}
\DoxyCodeLine{592      \textcolor{comment}{!H\_geom = H\_geom * sqrt(N2) ! WKB-\/ish}}
\DoxyCodeLine{593      \textcolor{comment}{!H\_geom = H\_geom * N2       ! WKB-\/ish}}
\DoxyCodeLine{594       wse = g\%mask2dCu(i,j)     * ( (h(i,j  ,k)*h(i+1,j  ,k)) * (h(i,j  ,k-\/1)*h(i+1,j  ,k-\/1)) )}
\DoxyCodeLine{595       wnw = g\%mask2dCu(i-\/1,j+1) * ( (h(i,j+1,k)*h(i-\/1,j+1,k)) * (h(i,j+1,k-\/1)*h(i-\/1,j+1,k-\/1)) )}
\DoxyCodeLine{596       wne = g\%mask2dCu(i,j+1)   * ( (h(i,j+1,k)*h(i+1,j+1,k)) * (h(i,j+1,k-\/1)*h(i+1,j+1,k-\/1)) )}
\DoxyCodeLine{597       wsw = g\%mask2dCu(i-\/1,j)   * ( (h(i,j  ,k)*h(i-\/1,j  ,k)) * (h(i,j  ,k-\/1)*h(i-\/1,j  ,k-\/1)) )}
\DoxyCodeLine{598       s2 = slope\_y(i,j,k)**2 + \&}
\DoxyCodeLine{599              ((wse*slope\_x(i,j,k)**2 + wnw*slope\_x(i-\/1,j+1,k)**2) + \&}
\DoxyCodeLine{600               (wne*slope\_x(i,j+1,k)**2 + wsw*slope\_x(i-\/1,j,k)**2) ) / \&}
\DoxyCodeLine{601              ( ((wse+wnw) + (wne+wsw)) + gv\%H\_subroundoff**4 )}
\DoxyCodeLine{602       \textcolor{keywordflow}{if} (s2max>0.) s2 = s2 * s2max / (s2 + s2max) \textcolor{comment}{! Limit S2}}
\DoxyCodeLine{603 }
\DoxyCodeLine{604       n2 = max(0., n2\_v(i,j,k))}
\DoxyCodeLine{605       cs\%SN\_v(i,j) = cs\%SN\_v(i,j) + sqrt( s2*n2 )*h\_geom}
\DoxyCodeLine{606       s2\_v(i,j) = s2\_v(i,j) + s2*h\_geom}
\DoxyCodeLine{607       h\_v(i) = h\_v(i) + h\_geom}
\DoxyCodeLine{608 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{609     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{610       \textcolor{keywordflow}{if} (h\_v(i)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{611         cs\%SN\_v(i,j) = g\%mask2dCv(i,j) * cs\%SN\_v(i,j) / h\_v(i)}
\DoxyCodeLine{612         s2\_v(i,j) = g\%mask2dCv(i,j) * s2\_v(i,j) / h\_v(i)}
\DoxyCodeLine{613       \textcolor{keywordflow}{else}}
\DoxyCodeLine{614         cs\%SN\_v(i,j) = 0.}
\DoxyCodeLine{615 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{616       \textcolor{keywordflow}{if} (local\_open\_v\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{617         l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{618 }
\DoxyCodeLine{619         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{620           \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{621             cs\%SN\_v(i,j) = 0.}
\DoxyCodeLine{622 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{623 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{624 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{625 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{626 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{627 }
\DoxyCodeLine{628 \textcolor{comment}{! Offer diagnostic fields for averaging.}}
\DoxyCodeLine{629   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{630     \textcolor{keywordflow}{if} (cs\%id\_S2\_u > 0) \textcolor{keyword}{call }post\_data(cs\%id\_S2\_u, s2\_u, cs\%diag)}
\DoxyCodeLine{631     \textcolor{keywordflow}{if} (cs\%id\_S2\_v > 0) \textcolor{keyword}{call }post\_data(cs\%id\_S2\_v, s2\_v, cs\%diag)}
\DoxyCodeLine{632 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{633 }
\DoxyCodeLine{634   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{635     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}calc\_Visbeck\_coeffs slope\_[xy]"{}}, slope\_x, slope\_y, g\%HI, haloshift=1)}
\DoxyCodeLine{636     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}calc\_Visbeck\_coeffs N2\_u, N2\_v"{}}, n2\_u, n2\_v, g\%HI, \&}
\DoxyCodeLine{637                   scale=us\%s\_to\_T**2, scalar\_pair=.true.)}
\DoxyCodeLine{638     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}calc\_Visbeck\_coeffs SN\_[uv]"{}}, cs\%SN\_u, cs\%SN\_v, g\%HI, \&}
\DoxyCodeLine{639                   scale=us\%s\_to\_T, scalar\_pair=.true.)}
\DoxyCodeLine{640 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{641 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a1070a864ca570c00f483a8617afca133}\label{namespacemom__lateral__mixing__coeffs_a1070a864ca570c00f483a8617afca133}} 
\index{mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}!varmix\_init@{varmix\_init}}
\index{varmix\_init@{varmix\_init}!mom\_lateral\_mixing\_coeffs@{mom\_lateral\_mixing\_coeffs}}
\doxysubsubsection{\texorpdfstring{varmix\_init()}{varmix\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::varmix\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initializes the variables mixing coefficients container. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & Current model time \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file handles \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics control structure \\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\end{DoxyParams}


Definition at line 936 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{937   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{intent(in)} :: Time\textcolor{comment}{ !< Current model time}}
\DoxyCodeLine{938   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< Ocean grid structure}}
\DoxyCodeLine{939   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{940   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{941   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< Parameter file handles}}
\DoxyCodeLine{942   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< Diagnostics control structure}}
\DoxyCodeLine{943   \textcolor{keywordtype}{type}(VarMix\_CS),               \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< Variable mixing coefficients}}
\DoxyCodeLine{944   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{945 \textcolor{keywordtype}{  real} :: KhTr\_Slope\_Cff, KhTh\_Slope\_Cff, oneOrTwo}
\DoxyCodeLine{946 \textcolor{keywordtype}{  real} :: N2\_filter\_depth  \textcolor{comment}{! A depth below which stratification is treated as monotonic when}}
\DoxyCodeLine{947                            \textcolor{comment}{! calculating the first-\/mode wave speed [Z \string~> m]}}
\DoxyCodeLine{948 \textcolor{keywordtype}{  real} :: KhTr\_passivity\_coeff}
\DoxyCodeLine{949 \textcolor{keywordtype}{  real} :: absurdly\_small\_freq  \textcolor{comment}{! A miniscule frequency that is used to avoid division by 0 [T-\/1 \string~> s-\/1].  The}}
\DoxyCodeLine{950              \textcolor{comment}{! default value is roughly (pi / (the age of the universe)).}}
\DoxyCodeLine{951   \textcolor{keywordtype}{logical} :: Gill\_equatorial\_Ld, use\_FGNV\_streamfn, use\_MEKE, in\_use}
\DoxyCodeLine{952   \textcolor{keywordtype}{logical} :: default\_2018\_answers, remap\_answers\_2018}
\DoxyCodeLine{953 \textcolor{keywordtype}{  real} :: MLE\_front\_length}
\DoxyCodeLine{954 \textcolor{keywordtype}{  real} :: Leith\_Lap\_const      \textcolor{comment}{! The non-\/dimensional coefficient in the Leith viscosity}}
\DoxyCodeLine{955 \textcolor{keywordtype}{  real} :: grid\_sp\_u2, grid\_sp\_v2 \textcolor{comment}{! Intermediate quantities for Leith metrics [L2 \string~> m2]}}
\DoxyCodeLine{956 \textcolor{keywordtype}{  real} :: grid\_sp\_u3, grid\_sp\_v3 \textcolor{comment}{! Intermediate quantities for Leith metrics [L3 \string~> m3]}}
\DoxyCodeLine{957 \textcolor{keywordtype}{  real} :: wave\_speed\_min      \textcolor{comment}{! A floor in the first mode speed below which 0 is returned [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{958 \textcolor{keywordtype}{  real} :: wave\_speed\_tol      \textcolor{comment}{! The fractional tolerance for finding the wave speeds [nondim]}}
\DoxyCodeLine{959   \textcolor{keywordtype}{logical} :: better\_speed\_est \textcolor{comment}{! If true, use a more robust estimate of the first}}
\DoxyCodeLine{960                               \textcolor{comment}{! mode wave speed as the starting point for iterations.}}
\DoxyCodeLine{961 \textcolor{comment}{! This include declares and sets the variable "{}version"{}.}}
\DoxyCodeLine{962 \textcolor{preprocessor}{\# include "{}version\_variable.h"{}}}
\DoxyCodeLine{963 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}MOM\_lateral\_mixing\_coeffs"{}} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{964   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, i, j}
\DoxyCodeLine{965   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{966   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{967   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{968   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{969   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{970 }
\DoxyCodeLine{971   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{972     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}VarMix\_init called with an associated "{}}// \&}
\DoxyCodeLine{973                              \textcolor{stringliteral}{"{}control structure."{}})}
\DoxyCodeLine{974     \textcolor{keywordflow}{return}}
\DoxyCodeLine{975 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{976 }
\DoxyCodeLine{977   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{978   in\_use = .false. \textcolor{comment}{! Set to true to avoid deallocating}}
\DoxyCodeLine{979   cs\%diag => diag \textcolor{comment}{! Diagnostics pointer}}
\DoxyCodeLine{980   cs\%calculate\_cg1 = .false.}
\DoxyCodeLine{981   cs\%calculate\_Rd\_dx = .false.}
\DoxyCodeLine{982   cs\%calculate\_res\_fns = .false.}
\DoxyCodeLine{983   cs\%calculate\_Eady\_growth\_rate = .false.}
\DoxyCodeLine{984   cs\%calculate\_depth\_fns = .false.}
\DoxyCodeLine{985   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{986   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{"{}"{}})}
\DoxyCodeLine{987   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_VARIABLE\_MIXING"{}}, cs\%use\_variable\_mixing,\&}
\DoxyCodeLine{988                  \textcolor{stringliteral}{"{}If true, the variable mixing code will be called.  This "{}}//\&}
\DoxyCodeLine{989                  \textcolor{stringliteral}{"{}allows diagnostics to be created even if the scheme is "{}}//\&}
\DoxyCodeLine{990                  \textcolor{stringliteral}{"{}not used.  If KHTR\_SLOPE\_CFF>0 or  KhTh\_Slope\_Cff>0, "{}}//\&}
\DoxyCodeLine{991                  \textcolor{stringliteral}{"{}this is set to true regardless of what is in the "{}}//\&}
\DoxyCodeLine{992                  \textcolor{stringliteral}{"{}parameter file."{}}, default=.false.)}
\DoxyCodeLine{993   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_VISBECK"{}}, cs\%use\_Visbeck,\&}
\DoxyCodeLine{994                  \textcolor{stringliteral}{"{}If true, use the Visbeck et al. (1997) formulation for \(\backslash\)n"{}}//\&}
\DoxyCodeLine{995                  \textcolor{stringliteral}{"{}thickness diffusivity."{}}, default=.false.)}
\DoxyCodeLine{996   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}RESOLN\_SCALED\_KH"{}}, cs\%Resoln\_scaled\_Kh, \&}
\DoxyCodeLine{997                  \textcolor{stringliteral}{"{}If true, the Laplacian lateral viscosity is scaled away "{}}//\&}
\DoxyCodeLine{998                  \textcolor{stringliteral}{"{}when the first baroclinic deformation radius is well "{}}//\&}
\DoxyCodeLine{999                  \textcolor{stringliteral}{"{}resolved."{}}, default=.false.)}
\DoxyCodeLine{1000   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEPTH\_SCALED\_KHTH"{}}, cs\%Depth\_scaled\_KhTh, \&}
\DoxyCodeLine{1001                  \textcolor{stringliteral}{"{}If true, KHTH is scaled away when the depth is shallower"{}}//\&}
\DoxyCodeLine{1002                  \textcolor{stringliteral}{"{}than a reference depth: KHTH = MIN(1,H/H0)**N * KHTH, "{}}//\&}
\DoxyCodeLine{1003                  \textcolor{stringliteral}{"{}where H0 is a reference depth, controlled via DEPTH\_SCALED\_KHTH\_H0, "{}}//\&}
\DoxyCodeLine{1004                  \textcolor{stringliteral}{"{}and the exponent (N) is controlled via DEPTH\_SCALED\_KHTH\_EXP."{}},\&}
\DoxyCodeLine{1005                  default=.false.)}
\DoxyCodeLine{1006   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}RESOLN\_SCALED\_KHTH"{}}, cs\%Resoln\_scaled\_KhTh, \&}
\DoxyCodeLine{1007                  \textcolor{stringliteral}{"{}If true, the interface depth diffusivity is scaled away "{}}//\&}
\DoxyCodeLine{1008                  \textcolor{stringliteral}{"{}when the first baroclinic deformation radius is well "{}}//\&}
\DoxyCodeLine{1009                  \textcolor{stringliteral}{"{}resolved."{}}, default=.false.)}
\DoxyCodeLine{1010   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}RESOLN\_SCALED\_KHTR"{}}, cs\%Resoln\_scaled\_KhTr, \&}
\DoxyCodeLine{1011                  \textcolor{stringliteral}{"{}If true, the epipycnal tracer diffusivity is scaled "{}}//\&}
\DoxyCodeLine{1012                  \textcolor{stringliteral}{"{}away when the first baroclinic deformation radius is "{}}//\&}
\DoxyCodeLine{1013                  \textcolor{stringliteral}{"{}well resolved."{}}, default=.false.)}
\DoxyCodeLine{1014   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}RESOLN\_USE\_EBT"{}}, cs\%Resoln\_use\_ebt, \&}
\DoxyCodeLine{1015                  \textcolor{stringliteral}{"{}If true, uses the equivalent barotropic wave speed instead "{}}//\&}
\DoxyCodeLine{1016                  \textcolor{stringliteral}{"{}of first baroclinic wave for calculating the resolution fn."{}},\&}
\DoxyCodeLine{1017                  default=.false.)}
\DoxyCodeLine{1018   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KHTH\_USE\_EBT\_STRUCT"{}}, cs\%khth\_use\_ebt\_struct, \&}
\DoxyCodeLine{1019                  \textcolor{stringliteral}{"{}If true, uses the equivalent barotropic structure "{}}//\&}
\DoxyCodeLine{1020                  \textcolor{stringliteral}{"{}as the vertical structure of thickness diffusivity."{}},\&}
\DoxyCodeLine{1021                  default=.false.)}
\DoxyCodeLine{1022   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KHTH\_SLOPE\_CFF"{}}, khth\_slope\_cff, \&}
\DoxyCodeLine{1023                  \textcolor{stringliteral}{"{}The nondimensional coefficient in the Visbeck formula "{}}//\&}
\DoxyCodeLine{1024                  \textcolor{stringliteral}{"{}for the interface depth diffusivity"{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, \&}
\DoxyCodeLine{1025                  default=0.0)}
\DoxyCodeLine{1026   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KHTR\_SLOPE\_CFF"{}}, khtr\_slope\_cff, \&}
\DoxyCodeLine{1027                  \textcolor{stringliteral}{"{}The nondimensional coefficient in the Visbeck formula "{}}//\&}
\DoxyCodeLine{1028                  \textcolor{stringliteral}{"{}for the epipycnal tracer diffusivity"{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, \&}
\DoxyCodeLine{1029                  default=0.0)}
\DoxyCodeLine{1030   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_STORED\_SLOPES"{}}, cs\%use\_stored\_slopes,\&}
\DoxyCodeLine{1031                  \textcolor{stringliteral}{"{}If true, the isopycnal slopes are calculated once and "{}}//\&}
\DoxyCodeLine{1032                  \textcolor{stringliteral}{"{}stored for re-\/use. This uses more memory but avoids calling "{}}//\&}
\DoxyCodeLine{1033                  \textcolor{stringliteral}{"{}the equation of state more times than should be necessary."{}}, \&}
\DoxyCodeLine{1034                  default=.false.)}
\DoxyCodeLine{1035   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VERY\_SMALL\_FREQUENCY"{}}, absurdly\_small\_freq, \&}
\DoxyCodeLine{1036                  \textcolor{stringliteral}{"{}A miniscule frequency that is used to avoid division by 0.  The default "{}}//\&}
\DoxyCodeLine{1037                  \textcolor{stringliteral}{"{}value is roughly (pi / (the age of the universe))."{}}, \&}
\DoxyCodeLine{1038                  default=1.0e-\/17, units=\textcolor{stringliteral}{"{}s-\/1"{}}, scale=us\%T\_to\_s)}
\DoxyCodeLine{1039   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KHTH\_USE\_FGNV\_STREAMFUNCTION"{}}, use\_fgnv\_streamfn, \&}
\DoxyCodeLine{1040                  default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1041   cs\%calculate\_cg1 = cs\%calculate\_cg1 .or. use\_fgnv\_streamfn}
\DoxyCodeLine{1042   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_MEKE"{}}, use\_meke, \&}
\DoxyCodeLine{1043                  default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1044   cs\%calculate\_Rd\_dx = cs\%calculate\_Rd\_dx .or. use\_meke}
\DoxyCodeLine{1045   cs\%calculate\_Eady\_growth\_rate = cs\%calculate\_Eady\_growth\_rate .or. use\_meke}
\DoxyCodeLine{1046   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KHTR\_PASSIVITY\_COEFF"{}}, khtr\_passivity\_coeff, \&}
\DoxyCodeLine{1047                  default=0., do\_not\_log=.true.)}
\DoxyCodeLine{1048   cs\%calculate\_Rd\_dx = cs\%calculate\_Rd\_dx .or. (khtr\_passivity\_coeff>0.)}
\DoxyCodeLine{1049   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}MLE\_FRONT\_LENGTH"{}}, mle\_front\_length, \&}
\DoxyCodeLine{1050                  default=0., do\_not\_log=.true.)}
\DoxyCodeLine{1051   cs\%calculate\_Rd\_dx = cs\%calculate\_Rd\_dx .or. (mle\_front\_length>0.)}
\DoxyCodeLine{1052 }
\DoxyCodeLine{1053   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEBUG"{}}, cs\%debug, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{1054 }
\DoxyCodeLine{1055 }
\DoxyCodeLine{1056   \textcolor{keywordflow}{if} (cs\%Resoln\_use\_ebt .or. cs\%khth\_use\_ebt\_struct) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1057     in\_use = .true.}
\DoxyCodeLine{1058     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}RESOLN\_N2\_FILTER\_DEPTH"{}}, n2\_filter\_depth, \&}
\DoxyCodeLine{1059                  \textcolor{stringliteral}{"{}The depth below which N2 is monotonized to avoid stratification "{}}//\&}
\DoxyCodeLine{1060                  \textcolor{stringliteral}{"{}artifacts from altering the equivalent barotropic mode structure."{}},\&}
\DoxyCodeLine{1061                  units=\textcolor{stringliteral}{"{}m"{}}, default=2000., scale=us\%m\_to\_Z)}
\DoxyCodeLine{1062     \textcolor{keyword}{allocate}(cs\%ebt\_struct(isd:ied,jsd:jed,g\%ke)) ; cs\%ebt\_struct(:,:,:) = 0.0}
\DoxyCodeLine{1063 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1064 }
\DoxyCodeLine{1065   \textcolor{keywordflow}{if} (khtr\_slope\_cff>0. .or. khth\_slope\_cff>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1066     cs\%calculate\_Eady\_growth\_rate = .true.}
\DoxyCodeLine{1067     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VISBECK\_MAX\_SLOPE"{}}, cs\%Visbeck\_S\_max, \&}
\DoxyCodeLine{1068           \textcolor{stringliteral}{"{}If non-\/zero, is an upper bound on slopes used in the "{}}//\&}
\DoxyCodeLine{1069           \textcolor{stringliteral}{"{}Visbeck formula for diffusivity. This does not affect the "{}}//\&}
\DoxyCodeLine{1070           \textcolor{stringliteral}{"{}isopycnal slope calculation used within thickness diffusion."{}},  \&}
\DoxyCodeLine{1071           units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.0)}
\DoxyCodeLine{1072 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1073 }
\DoxyCodeLine{1074   \textcolor{keywordflow}{if} (cs\%use\_stored\_slopes) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1075     in\_use = .true.}
\DoxyCodeLine{1076     \textcolor{keyword}{allocate}(cs\%slope\_x(isdb:iedb,jsd:jed,g\%ke+1)) ; cs\%slope\_x(:,:,:) = 0.0}
\DoxyCodeLine{1077     \textcolor{keyword}{allocate}(cs\%slope\_y(isd:ied,jsdb:jedb,g\%ke+1)) ; cs\%slope\_y(:,:,:) = 0.0}
\DoxyCodeLine{1078     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KD\_SMOOTH"{}}, cs\%kappa\_smooth, \&}
\DoxyCodeLine{1079                  \textcolor{stringliteral}{"{}A diapycnal diffusivity that is used to interpolate "{}}//\&}
\DoxyCodeLine{1080                  \textcolor{stringliteral}{"{}more sensible values of T \& S into thin layers."{}}, \&}
\DoxyCodeLine{1081                  units=\textcolor{stringliteral}{"{}m2 s-\/1"{}}, default=1.0e-\/6, scale=us\%m\_to\_Z**2*us\%T\_to\_s)}
\DoxyCodeLine{1082 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1083 }
\DoxyCodeLine{1084   \textcolor{keywordflow}{if} (cs\%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1085     in\_use = .true.}
\DoxyCodeLine{1086     \textcolor{keyword}{allocate}(cs\%SN\_u(isdb:iedb,jsd:jed)) ; cs\%SN\_u(:,:) = 0.0}
\DoxyCodeLine{1087     \textcolor{keyword}{allocate}(cs\%SN\_v(isd:ied,jsdb:jedb)) ; cs\%SN\_v(:,:) = 0.0}
\DoxyCodeLine{1088     cs\%id\_SN\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SN\_u'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{1089        \textcolor{stringliteral}{'Inverse eddy time-\/scale, S*N, at u-\/points'}, \textcolor{stringliteral}{'s-\/1'}, conversion=us\%s\_to\_T)}
\DoxyCodeLine{1090     cs\%id\_SN\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SN\_v'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{1091        \textcolor{stringliteral}{'Inverse eddy time-\/scale, S*N, at v-\/points'}, \textcolor{stringliteral}{'s-\/1'}, conversion=us\%s\_to\_T)}
\DoxyCodeLine{1092     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VARMIX\_KTOP"{}}, cs\%VarMix\_Ktop, \&}
\DoxyCodeLine{1093                  \textcolor{stringliteral}{"{}The layer number at which to start vertical integration "{}}//\&}
\DoxyCodeLine{1094                  \textcolor{stringliteral}{"{}of S*N for purposes of finding the Eady growth rate."{}}, \&}
\DoxyCodeLine{1095                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=2)}
\DoxyCodeLine{1096 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1097 }
\DoxyCodeLine{1098   \textcolor{keywordflow}{if} (khtr\_slope\_cff>0. .or. khth\_slope\_cff>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1099     in\_use = .true.}
\DoxyCodeLine{1100     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VISBECK\_L\_SCALE"{}}, cs\%Visbeck\_L\_scale, \&}
\DoxyCodeLine{1101                  \textcolor{stringliteral}{"{}The fixed length scale in the Visbeck formula."{}}, units=\textcolor{stringliteral}{"{}m"{}}, \&}
\DoxyCodeLine{1102                  default=0.0)}
\DoxyCodeLine{1103     \textcolor{keyword}{allocate}(cs\%L2u(isdb:iedb,jsd:jed)) ; cs\%L2u(:,:) = 0.0}
\DoxyCodeLine{1104     \textcolor{keyword}{allocate}(cs\%L2v(isd:ied,jsdb:jedb)) ; cs\%L2v(:,:) = 0.0}
\DoxyCodeLine{1105     \textcolor{keywordflow}{if} (cs\%Visbeck\_L\_scale<0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1106       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{1107         cs\%L2u(i,j) = cs\%Visbeck\_L\_scale**2 * g\%areaCu(i,j)}
\DoxyCodeLine{1108       enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1109       \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1110         cs\%L2v(i,j) = cs\%Visbeck\_L\_scale**2 * g\%areaCv(i,j)}
\DoxyCodeLine{1111       enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1112     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1113       cs\%L2u(:,:) = us\%m\_to\_L**2*cs\%Visbeck\_L\_scale**2}
\DoxyCodeLine{1114       cs\%L2v(:,:) = us\%m\_to\_L**2*cs\%Visbeck\_L\_scale**2}
\DoxyCodeLine{1115 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1116 }
\DoxyCodeLine{1117     cs\%id\_L2u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'L2u'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{1118        \textcolor{stringliteral}{'Length scale squared for mixing coefficient, at u-\/points'}, \&}
\DoxyCodeLine{1119        \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m**2)}
\DoxyCodeLine{1120     cs\%id\_L2v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'L2v'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{1121        \textcolor{stringliteral}{'Length scale squared for mixing coefficient, at v-\/points'}, \&}
\DoxyCodeLine{1122        \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m**2)}
\DoxyCodeLine{1123 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1124 }
\DoxyCodeLine{1125   \textcolor{keywordflow}{if} (cs\%calculate\_Eady\_growth\_rate .and. cs\%use\_stored\_slopes) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1126     cs\%id\_N2\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'N2\_u'}, diag\%axesCui, time, \&}
\DoxyCodeLine{1127          \textcolor{stringliteral}{'Square of Brunt-\/Vaisala frequency, N\string^2, at u-\/points, as used in Visbeck et al.'}, \&}
\DoxyCodeLine{1128          \textcolor{stringliteral}{'s-\/2'}, conversion=us\%s\_to\_T**2)}
\DoxyCodeLine{1129     cs\%id\_N2\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'N2\_v'}, diag\%axesCvi, time, \&}
\DoxyCodeLine{1130          \textcolor{stringliteral}{'Square of Brunt-\/Vaisala frequency, N\string^2, at v-\/points, as used in Visbeck et al.'}, \&}
\DoxyCodeLine{1131          \textcolor{stringliteral}{'s-\/2'}, conversion=us\%s\_to\_T**2)}
\DoxyCodeLine{1132 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1133   \textcolor{keywordflow}{if} (cs\%use\_stored\_slopes) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1134     cs\%id\_S2\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'S2\_u'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{1135          \textcolor{stringliteral}{'Depth average square of slope magnitude, S\string^2, at u-\/points, as used in Visbeck et al.'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{1136     cs\%id\_S2\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'S2\_v'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{1137          \textcolor{stringliteral}{'Depth average square of slope magnitude, S\string^2, at v-\/points, as used in Visbeck et al.'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{1138 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1139 }
\DoxyCodeLine{1140   oneortwo = 1.0}
\DoxyCodeLine{1141   \textcolor{keywordflow}{if} (cs\%Resoln\_scaled\_Kh .or. cs\%Resoln\_scaled\_KhTh .or. cs\%Resoln\_scaled\_KhTr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1142     cs\%calculate\_Rd\_dx = .true.}
\DoxyCodeLine{1143     cs\%calculate\_res\_fns = .true.}
\DoxyCodeLine{1144     \textcolor{keyword}{allocate}(cs\%Res\_fn\_h(isd:ied,jsd:jed))       ; cs\%Res\_fn\_h(:,:) = 0.0}
\DoxyCodeLine{1145     \textcolor{keyword}{allocate}(cs\%Res\_fn\_q(isdb:iedb,jsdb:jedb))   ; cs\%Res\_fn\_q(:,:) = 0.0}
\DoxyCodeLine{1146     \textcolor{keyword}{allocate}(cs\%Res\_fn\_u(isdb:iedb,jsd:jed))     ; cs\%Res\_fn\_u(:,:) = 0.0}
\DoxyCodeLine{1147     \textcolor{keyword}{allocate}(cs\%Res\_fn\_v(isd:ied,jsdb:jedb))     ; cs\%Res\_fn\_v(:,:) = 0.0}
\DoxyCodeLine{1148     \textcolor{keyword}{allocate}(cs\%beta\_dx2\_q(isdb:iedb,jsdb:jedb)) ; cs\%beta\_dx2\_q(:,:) = 0.0}
\DoxyCodeLine{1149     \textcolor{keyword}{allocate}(cs\%beta\_dx2\_u(isdb:iedb,jsd:jed))   ; cs\%beta\_dx2\_u(:,:) = 0.0}
\DoxyCodeLine{1150     \textcolor{keyword}{allocate}(cs\%beta\_dx2\_v(isd:ied,jsdb:jedb))   ; cs\%beta\_dx2\_v(:,:) = 0.0}
\DoxyCodeLine{1151     \textcolor{keyword}{allocate}(cs\%f2\_dx2\_q(isdb:iedb,jsdb:jedb))   ; cs\%f2\_dx2\_q(:,:) = 0.0}
\DoxyCodeLine{1152     \textcolor{keyword}{allocate}(cs\%f2\_dx2\_u(isdb:iedb,jsd:jed))     ; cs\%f2\_dx2\_u(:,:) = 0.0}
\DoxyCodeLine{1153     \textcolor{keyword}{allocate}(cs\%f2\_dx2\_v(isd:ied,jsdb:jedb))     ; cs\%f2\_dx2\_v(:,:) = 0.0}
\DoxyCodeLine{1154 }
\DoxyCodeLine{1155     cs\%id\_Res\_fn = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Res\_fn'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1156        \textcolor{stringliteral}{'Resolution function for scaling diffusivities'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{1157 }
\DoxyCodeLine{1158     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KH\_RES\_SCALE\_COEF"{}}, cs\%Res\_coef\_khth, \&}
\DoxyCodeLine{1159                  \textcolor{stringliteral}{"{}A coefficient that determines how KhTh is scaled away if "{}}//\&}
\DoxyCodeLine{1160                  \textcolor{stringliteral}{"{}RESOLN\_SCALED\_... is true, as "{}}//\&}
\DoxyCodeLine{1161                  \textcolor{stringliteral}{"{}F = 1 / (1 + (KH\_RES\_SCALE\_COEF*Rd/dx)\string^KH\_RES\_FN\_POWER)."{}}, \&}
\DoxyCodeLine{1162                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=1.0)}
\DoxyCodeLine{1163     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KH\_RES\_FN\_POWER"{}}, cs\%Res\_fn\_power\_khth, \&}
\DoxyCodeLine{1164                  \textcolor{stringliteral}{"{}The power of dx/Ld in the Kh resolution function.  Any "{}}//\&}
\DoxyCodeLine{1165                  \textcolor{stringliteral}{"{}positive integer may be used, although even integers "{}}//\&}
\DoxyCodeLine{1166                  \textcolor{stringliteral}{"{}are more efficient to calculate.  Setting this greater "{}}//\&}
\DoxyCodeLine{1167                  \textcolor{stringliteral}{"{}than 100 results in a step-\/function being used."{}}, \&}
\DoxyCodeLine{1168                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=2)}
\DoxyCodeLine{1169     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VISC\_RES\_SCALE\_COEF"{}}, cs\%Res\_coef\_visc, \&}
\DoxyCodeLine{1170                  \textcolor{stringliteral}{"{}A coefficient that determines how Kh is scaled away if "{}}//\&}
\DoxyCodeLine{1171                  \textcolor{stringliteral}{"{}RESOLN\_SCALED\_... is true, as "{}}//\&}
\DoxyCodeLine{1172                  \textcolor{stringliteral}{"{}F = 1 / (1 + (KH\_RES\_SCALE\_COEF*Rd/dx)\string^KH\_RES\_FN\_POWER). "{}}//\&}
\DoxyCodeLine{1173                  \textcolor{stringliteral}{"{}This function affects lateral viscosity, Kh, and not KhTh."{}}, \&}
\DoxyCodeLine{1174                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=cs\%Res\_coef\_khth)}
\DoxyCodeLine{1175     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VISC\_RES\_FN\_POWER"{}}, cs\%Res\_fn\_power\_visc, \&}
\DoxyCodeLine{1176                  \textcolor{stringliteral}{"{}The power of dx/Ld in the Kh resolution function.  Any "{}}//\&}
\DoxyCodeLine{1177                  \textcolor{stringliteral}{"{}positive integer may be used, although even integers "{}}//\&}
\DoxyCodeLine{1178                  \textcolor{stringliteral}{"{}are more efficient to calculate.  Setting this greater "{}}//\&}
\DoxyCodeLine{1179                  \textcolor{stringliteral}{"{}than 100 results in a step-\/function being used. "{}}//\&}
\DoxyCodeLine{1180                  \textcolor{stringliteral}{"{}This function affects lateral viscosity, Kh, and not KhTh."{}}, \&}
\DoxyCodeLine{1181                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=cs\%Res\_fn\_power\_khth)}
\DoxyCodeLine{1182     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INTERPOLATE\_RES\_FN"{}}, cs\%interpolate\_Res\_fn, \&}
\DoxyCodeLine{1183                  \textcolor{stringliteral}{"{}If true, interpolate the resolution function to the "{}}//\&}
\DoxyCodeLine{1184                  \textcolor{stringliteral}{"{}velocity points from the thickness points; otherwise "{}}//\&}
\DoxyCodeLine{1185                  \textcolor{stringliteral}{"{}interpolate the wave speed and calculate the resolution "{}}//\&}
\DoxyCodeLine{1186                  \textcolor{stringliteral}{"{}function independently at each point."{}}, default=.false.)}
\DoxyCodeLine{1187     \textcolor{keywordflow}{if} (cs\%interpolate\_Res\_fn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1188       \textcolor{keywordflow}{if} (cs\%Res\_coef\_visc /= cs\%Res\_coef\_khth) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1189            \textcolor{stringliteral}{"{}MOM\_lateral\_mixing\_coeffs.F90, VarMix\_init:"{}}//\&}
\DoxyCodeLine{1190            \textcolor{stringliteral}{"{}When INTERPOLATE\_RES\_FN=True, VISC\_RES\_FN\_POWER must equal KH\_RES\_SCALE\_COEF."{}})}
\DoxyCodeLine{1191       \textcolor{keywordflow}{if} (cs\%Res\_fn\_power\_visc /= cs\%Res\_fn\_power\_khth) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1192            \textcolor{stringliteral}{"{}MOM\_lateral\_mixing\_coeffs.F90, VarMix\_init:"{}}//\&}
\DoxyCodeLine{1193            \textcolor{stringliteral}{"{}When INTERPOLATE\_RES\_FN=True, VISC\_RES\_FN\_POWER must equal KH\_RES\_FN\_POWER."{}})}
\DoxyCodeLine{1194 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1195     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}GILL\_EQUATORIAL\_LD"{}}, gill\_equatorial\_ld, \&}
\DoxyCodeLine{1196                  \textcolor{stringliteral}{"{}If true, uses Gill's definition of the baroclinic "{}}//\&}
\DoxyCodeLine{1197                  \textcolor{stringliteral}{"{}equatorial deformation radius, otherwise, if false, use "{}}//\&}
\DoxyCodeLine{1198                  \textcolor{stringliteral}{"{}Pedlosky's definition. These definitions differ by a factor "{}}//\&}
\DoxyCodeLine{1199                  \textcolor{stringliteral}{"{}of 2 in front of the beta term in the denominator. Gill's "{}}//\&}
\DoxyCodeLine{1200                  \textcolor{stringliteral}{"{}is the more appropriate definition."{}}, default=.true.)}
\DoxyCodeLine{1201     \textcolor{keywordflow}{if} (gill\_equatorial\_ld) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1202       oneortwo = 2.0}
\DoxyCodeLine{1203 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1204 }
\DoxyCodeLine{1205     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{1206       cs\%f2\_dx2\_q(i,j) = (g\%dxBu(i,j)**2 + g\%dyBu(i,j)**2) * \&}
\DoxyCodeLine{1207                          max(g\%CoriolisBu(i,j)**2, absurdly\_small\_freq**2)}
\DoxyCodeLine{1208       cs\%beta\_dx2\_q(i,j) = oneortwo * ((g\%dxBu(i,j))**2 + (g\%dyBu(i,j))**2) * (sqrt(0.5 * \&}
\DoxyCodeLine{1209           ( (((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i-\/1,j)) * g\%IdxCv(i,j))**2 + \&}
\DoxyCodeLine{1210              ((g\%CoriolisBu(i+1,j)-\/g\%CoriolisBu(i,j)) * g\%IdxCv(i+1,j))**2) + \&}
\DoxyCodeLine{1211             (((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i,j-\/1)) * g\%IdyCu(i,j))**2 + \&}
\DoxyCodeLine{1212              ((g\%CoriolisBu(i,j+1)-\/g\%CoriolisBu(i,j)) * g\%IdyCu(i,j+1))**2) ) ))}
\DoxyCodeLine{1213 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1214 }
\DoxyCodeLine{1215     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{1216       cs\%f2\_dx2\_u(i,j) = (g\%dxCu(i,j)**2 + g\%dyCu(i,j)**2) * \&}
\DoxyCodeLine{1217           max(0.5* (g\%CoriolisBu(i,j)**2+g\%CoriolisBu(i,j-\/1)**2), absurdly\_small\_freq**2)}
\DoxyCodeLine{1218       cs\%beta\_dx2\_u(i,j) = oneortwo * ((g\%dxCu(i,j))**2 + (g\%dyCu(i,j))**2) * (sqrt( \&}
\DoxyCodeLine{1219           0.25*( (((g\%CoriolisBu(i,j-\/1)-\/g\%CoriolisBu(i-\/1,j-\/1)) * g\%IdxCv(i,j-\/1))**2 + \&}
\DoxyCodeLine{1220                   ((g\%CoriolisBu(i+1,j)-\/g\%CoriolisBu(i,j)) * g\%IdxCv(i+1,j))**2) + \&}
\DoxyCodeLine{1221                  (((g\%CoriolisBu(i+1,j-\/1)-\/g\%CoriolisBu(i,j-\/1)) * g\%IdxCv(i+1,j-\/1))**2 + \&}
\DoxyCodeLine{1222                   ((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i-\/1,j)) * g\%IdxCv(i,j))**2) ) + \&}
\DoxyCodeLine{1223                   ((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i,j-\/1)) * g\%IdyCu(i,j))**2 ))}
\DoxyCodeLine{1224 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1225 }
\DoxyCodeLine{1226     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1227       cs\%f2\_dx2\_v(i,j) = ((g\%dxCv(i,j))**2 + (g\%dyCv(i,j))**2) * \&}
\DoxyCodeLine{1228           max(0.5*(g\%CoriolisBu(i,j)**2+g\%CoriolisBu(i-\/1,j)**2), absurdly\_small\_freq**2)}
\DoxyCodeLine{1229       cs\%beta\_dx2\_v(i,j) = oneortwo * ((g\%dxCv(i,j))**2 + (g\%dyCv(i,j))**2) * (sqrt( \&}
\DoxyCodeLine{1230           ((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i-\/1,j)) * g\%IdxCv(i,j))**2 + \&}
\DoxyCodeLine{1231           0.25*( (((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i,j-\/1)) * g\%IdyCu(i,j))**2 + \&}
\DoxyCodeLine{1232                   ((g\%CoriolisBu(i-\/1,j+1)-\/g\%CoriolisBu(i-\/1,j)) * g\%IdyCu(i-\/1,j+1))**2) + \&}
\DoxyCodeLine{1233                  (((g\%CoriolisBu(i,j+1)-\/g\%CoriolisBu(i,j)) * g\%IdyCu(i,j+1))**2 + \&}
\DoxyCodeLine{1234                   ((g\%CoriolisBu(i-\/1,j)-\/g\%CoriolisBu(i-\/1,j-\/1)) * g\%IdyCu(i-\/1,j))**2) ) ))}
\DoxyCodeLine{1235 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1236 }
\DoxyCodeLine{1237 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1238 }
\DoxyCodeLine{1239   \textcolor{keywordflow}{if} (cs\%Depth\_scaled\_KhTh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1240     cs\%calculate\_depth\_fns = .true.}
\DoxyCodeLine{1241     \textcolor{keyword}{allocate}(cs\%Depth\_fn\_u(isdb:iedb,jsd:jed))     ; cs\%Depth\_fn\_u(:,:) = 0.0}
\DoxyCodeLine{1242     \textcolor{keyword}{allocate}(cs\%Depth\_fn\_v(isd:ied,jsdb:jedb))     ; cs\%Depth\_fn\_v(:,:) = 0.0}
\DoxyCodeLine{1243     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEPTH\_SCALED\_KHTH\_H0"{}}, cs\%depth\_scaled\_khth\_h0, \&}
\DoxyCodeLine{1244     \textcolor{stringliteral}{"{}The depth above which KHTH is scaled away."{}},\&}
\DoxyCodeLine{1245     units=\textcolor{stringliteral}{"{}m"{}}, default=1000.)}
\DoxyCodeLine{1246     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEPTH\_SCALED\_KHTH\_EXP"{}}, cs\%depth\_scaled\_khth\_exp, \&}
\DoxyCodeLine{1247     \textcolor{stringliteral}{"{}The exponent used in the depth dependent scaling function for KHTH."{}},\&}
\DoxyCodeLine{1248     units=\textcolor{stringliteral}{"{}nondim"{}}, default=3.0)}
\DoxyCodeLine{1249 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1250 }
\DoxyCodeLine{1251   \textcolor{comment}{! Resolution \%Rd\_dx\_h}}
\DoxyCodeLine{1252   cs\%id\_Rd\_dx = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Rd\_dx'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1253        \textcolor{stringliteral}{'Ratio between deformation radius and grid spacing'}, \textcolor{stringliteral}{'m m-\/1'})}
\DoxyCodeLine{1254   cs\%calculate\_Rd\_dx = cs\%calculate\_Rd\_dx .or. (cs\%id\_Rd\_dx>0)}
\DoxyCodeLine{1255 }
\DoxyCodeLine{1256   \textcolor{keywordflow}{if} (cs\%calculate\_Rd\_dx) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1257     cs\%calculate\_cg1 = .true. \textcolor{comment}{! We will need \%cg1}}
\DoxyCodeLine{1258     \textcolor{keyword}{allocate}(cs\%Rd\_dx\_h(isd:ied,jsd:jed))   ; cs\%Rd\_dx\_h(:,:) = 0.0}
\DoxyCodeLine{1259     \textcolor{keyword}{allocate}(cs\%beta\_dx2\_h(isd:ied,jsd:jed)); cs\%beta\_dx2\_h(:,:) = 0.0}
\DoxyCodeLine{1260     \textcolor{keyword}{allocate}(cs\%f2\_dx2\_h(isd:ied,jsd:jed))  ; cs\%f2\_dx2\_h(:,:) = 0.0}
\DoxyCodeLine{1261     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{1262       cs\%f2\_dx2\_h(i,j) = (g\%dxT(i,j)**2 + g\%dyT(i,j)**2) * \&}
\DoxyCodeLine{1263           max(0.25 * ((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-\/1,j-\/1)**2) + \&}
\DoxyCodeLine{1264                       (g\%CoriolisBu(i-\/1,j)**2 + g\%CoriolisBu(i,j-\/1)**2)), \&}
\DoxyCodeLine{1265               absurdly\_small\_freq**2)}
\DoxyCodeLine{1266       cs\%beta\_dx2\_h(i,j) = oneortwo * ((g\%dxT(i,j))**2 + (g\%dyT(i,j))**2) * (sqrt(0.5 * \&}
\DoxyCodeLine{1267           ( (((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i-\/1,j)) * g\%IdxCv(i,j))**2 + \&}
\DoxyCodeLine{1268              ((g\%CoriolisBu(i,j-\/1)-\/g\%CoriolisBu(i-\/1,j-\/1)) * g\%IdxCv(i,j-\/1))**2) + \&}
\DoxyCodeLine{1269             (((g\%CoriolisBu(i,j)-\/g\%CoriolisBu(i,j-\/1)) * g\%IdyCu(i,j))**2 + \&}
\DoxyCodeLine{1270              ((g\%CoriolisBu(i-\/1,j)-\/g\%CoriolisBu(i-\/1,j-\/1)) * g\%IdyCu(i-\/1,j))**2) ) ))}
\DoxyCodeLine{1271 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1272 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1273 }
\DoxyCodeLine{1274   \textcolor{keywordflow}{if} (cs\%calculate\_cg1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1275     in\_use = .true.}
\DoxyCodeLine{1276     \textcolor{keyword}{allocate}(cs\%cg1(isd:ied,jsd:jed)) ; cs\%cg1(:,:) = 0.0}
\DoxyCodeLine{1277     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEFAULT\_2018\_ANSWERS"{}}, default\_2018\_answers, \&}
\DoxyCodeLine{1278                  \textcolor{stringliteral}{"{}This sets the default value for the various \_2018\_ANSWERS parameters."{}}, \&}
\DoxyCodeLine{1279                  default=.false.)}
\DoxyCodeLine{1280     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}REMAPPING\_2018\_ANSWERS"{}}, remap\_answers\_2018, \&}
\DoxyCodeLine{1281                  \textcolor{stringliteral}{"{}If true, use the order of arithmetic and expressions that recover the "{}}//\&}
\DoxyCodeLine{1282                  \textcolor{stringliteral}{"{}answers from the end of 2018.  Otherwise, use updated and more robust "{}}//\&}
\DoxyCodeLine{1283                  \textcolor{stringliteral}{"{}forms of the same expressions."{}}, default=default\_2018\_answers)}
\DoxyCodeLine{1284     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INTERNAL\_WAVE\_SPEED\_TOL"{}}, wave\_speed\_tol, \&}
\DoxyCodeLine{1285                  \textcolor{stringliteral}{"{}The fractional tolerance for finding the wave speeds."{}}, \&}
\DoxyCodeLine{1286                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.001)}
\DoxyCodeLine{1287     \textcolor{comment}{!\#\#\# Set defaults so that wave\_speed\_min*wave\_speed\_tol >= 1e-\/9 m s-\/1}}
\DoxyCodeLine{1288     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INTERNAL\_WAVE\_SPEED\_MIN"{}}, wave\_speed\_min, \&}
\DoxyCodeLine{1289                  \textcolor{stringliteral}{"{}A floor in the first mode speed below which 0 used instead."{}}, \&}
\DoxyCodeLine{1290                  units=\textcolor{stringliteral}{"{}m s-\/1"{}}, default=0.0, scale=us\%m\_s\_to\_L\_T)}
\DoxyCodeLine{1291     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INTERNAL\_WAVE\_SPEED\_BETTER\_EST"{}}, better\_speed\_est, \&}
\DoxyCodeLine{1292                  \textcolor{stringliteral}{"{}If true, use a more robust estimate of the first mode wave speed as the "{}}//\&}
\DoxyCodeLine{1293                  \textcolor{stringliteral}{"{}starting point for iterations."{}}, default=.false.) \textcolor{comment}{!\#\#\# Change the default.}}
\DoxyCodeLine{1294     \textcolor{keyword}{call }wave\_speed\_init(cs\%wave\_speed\_CSp, use\_ebt\_mode=cs\%Resoln\_use\_ebt, \&}
\DoxyCodeLine{1295                          mono\_n2\_depth=n2\_filter\_depth, remap\_answers\_2018=remap\_answers\_2018, \&}
\DoxyCodeLine{1296                          better\_speed\_est=better\_speed\_est, min\_speed=wave\_speed\_min, \&}
\DoxyCodeLine{1297                          wave\_speed\_tol=wave\_speed\_tol)}
\DoxyCodeLine{1298 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1299 }
\DoxyCodeLine{1300   \textcolor{comment}{! Leith parameters}}
\DoxyCodeLine{1301   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_QG\_LEITH\_GM"{}}, cs\%use\_QG\_Leith\_GM, \&}
\DoxyCodeLine{1302                \textcolor{stringliteral}{"{}If true, use the QG Leith viscosity as the GM coefficient."{}}, \&}
\DoxyCodeLine{1303                default=.false.)}
\DoxyCodeLine{1304 }
\DoxyCodeLine{1305   \textcolor{keywordflow}{if} (cs\%Use\_QG\_Leith\_GM) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1306     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}LEITH\_LAP\_CONST"{}}, leith\_lap\_const, \&}
\DoxyCodeLine{1307                \textcolor{stringliteral}{"{}The nondimensional Laplacian Leith constant, \(\backslash\)n"{}}//\&}
\DoxyCodeLine{1308                \textcolor{stringliteral}{"{}often set to 1.0"{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.0)}
\DoxyCodeLine{1309 }
\DoxyCodeLine{1310     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_BETA\_IN\_LEITH"{}}, cs\%use\_beta\_in\_QG\_Leith, \&}
\DoxyCodeLine{1311                \textcolor{stringliteral}{"{}If true, include the beta term in the Leith nonlinear eddy viscosity."{}}, \&}
\DoxyCodeLine{1312                default=.true.)}
\DoxyCodeLine{1313 }
\DoxyCodeLine{1314     alloc\_(cs\%Laplac3\_const\_u(isdb:iedb,jsd:jed)) ; cs\%Laplac3\_const\_u(:,:) = 0.0}
\DoxyCodeLine{1315     alloc\_(cs\%Laplac3\_const\_v(isd:ied,jsdb:jedb)) ; cs\%Laplac3\_const\_v(:,:) = 0.0}
\DoxyCodeLine{1316     alloc\_(cs\%KH\_u\_QG(isdb:iedb,jsd:jed,g\%ke)) ; cs\%KH\_u\_QG(:,:,:) = 0.0}
\DoxyCodeLine{1317     alloc\_(cs\%KH\_v\_QG(isd:ied,jsdb:jedb,g\%ke)) ; cs\%KH\_v\_QG(:,:,:) = 0.0}
\DoxyCodeLine{1318     \textcolor{comment}{! register diagnostics}}
\DoxyCodeLine{1319 }
\DoxyCodeLine{1320     cs\%id\_KH\_u\_QG = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KH\_u\_QG'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{1321        \textcolor{stringliteral}{'Horizontal viscosity from Leith QG, at u-\/points'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{1322     cs\%id\_KH\_v\_QG = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KH\_v\_QG'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{1323        \textcolor{stringliteral}{'Horizontal viscosity from Leith QG, at v-\/points'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{1324 }
\DoxyCodeLine{1325     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=is-\/1,ieq}
\DoxyCodeLine{1326       \textcolor{comment}{! Static factors in the Leith schemes}}
\DoxyCodeLine{1327       grid\_sp\_u2 = g\%dyCu(i,j)*g\%dxCu(i,j)}
\DoxyCodeLine{1328       grid\_sp\_u3 = grid\_sp\_u2*sqrt(grid\_sp\_u2)}
\DoxyCodeLine{1329       cs\%Laplac3\_const\_u(i,j) = leith\_lap\_const * grid\_sp\_u3}
\DoxyCodeLine{1330 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1331     \textcolor{keywordflow}{do} j=js-\/1,jeq ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{1332       \textcolor{comment}{! Static factors in the Leith schemes}}
\DoxyCodeLine{1333       grid\_sp\_v2 = g\%dyCv(i,j)*g\%dxCv(i,j)}
\DoxyCodeLine{1334       grid\_sp\_v3 = grid\_sp\_v2*sqrt(grid\_sp\_v2)}
\DoxyCodeLine{1335       cs\%Laplac3\_const\_v(i,j) = leith\_lap\_const * grid\_sp\_v3}
\DoxyCodeLine{1336 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1337 }
\DoxyCodeLine{1338     \textcolor{keywordflow}{if} (.not. cs\%use\_stored\_slopes) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1339            \textcolor{stringliteral}{"{}MOM\_lateral\_mixing\_coeffs.F90, VarMix\_init:"{}}//\&}
\DoxyCodeLine{1340            \textcolor{stringliteral}{"{}USE\_STORED\_SLOPES must be True when using QG Leith."{}})}
\DoxyCodeLine{1341 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1342 }
\DoxyCodeLine{1343   \textcolor{comment}{! If nothing is being stored in this class then deallocate}}
\DoxyCodeLine{1344   \textcolor{keywordflow}{if} (in\_use) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1345     cs\%use\_variable\_mixing = .true.}
\DoxyCodeLine{1346   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1347     \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1348     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1349 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1350 }

\end{DoxyCode}
