\hypertarget{namespacemom__tidal__mixing}{}\doxysection{mom\+\_\+tidal\+\_\+mixing Module Reference}
\label{namespacemom__tidal__mixing}\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}}


\doxysubsection{Detailed Description}
Interface to vertical tidal mixing schemes including C\+V\+Mix tidal mixing. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure with parameters for the tidal mixing module. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__diags}{tidal\+\_\+mixing\+\_\+diags}}
\begin{DoxyCompactList}\small\item\em Containers for tidal mixing diagnostics. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__tidal__mixing_a6278fe41ef74ac23ba02ae1540104c5f}{tidal\+\_\+mixing\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initializes internal tidal dissipation scheme for diapycnal mixing. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_abf084268fd9c71f20880838d2bce7e3e}{calculate\+\_\+tidal\+\_\+mixing}} (h, N2\+\_\+bot, j, T\+K\+E\+\_\+to\+\_\+\+Kd, max\+\_\+\+T\+KE, G, GV, US, CS, N2\+\_\+lay, N2\+\_\+int, Kd\+\_\+lay, Kd\+\_\+int, Kd\+\_\+max, Kv)
\begin{DoxyCompactList}\small\item\em Depending on whether or not C\+V\+Mix is active, calls the associated subroutine to compute internal tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the layer or interface diffusivities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_af9e675f60c60606f767d4bb1321dba2c}{calculate\+\_\+cvmix\+\_\+tidal}} (h, j, G, GV, US, CS, N2\+\_\+int, Kd\+\_\+lay, Kd\+\_\+int, Kv)
\begin{DoxyCompactList}\small\item\em Calls the C\+V\+Mix routines to compute tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the interface diffusivities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_aa8f8da6657f71aaef15f3cbe4e5f521d}{add\+\_\+int\+\_\+tide\+\_\+diffusivity}} (h, N2\+\_\+bot, j, T\+K\+E\+\_\+to\+\_\+\+Kd, max\+\_\+\+T\+KE, G, GV, US, CS, N2\+\_\+lay, Kd\+\_\+lay, Kd\+\_\+int, Kd\+\_\+max)
\begin{DoxyCompactList}\small\item\em This subroutine adds the effect of internal-\/tide-\/driven mixing to the layer diffusivities. The mechanisms considered are (1) local dissipation of internal waves generated by the barotropic flow (\char`\"{}itidal\char`\"{}), (2) local dissipation of internal waves generated by the propagating low modes (rays) of the internal tide (\char`\"{}lowmode\char`\"{}), and (3) local dissipation of internal lee waves. Will eventually need to add diffusivity due to other wave-\/breaking processes (e.\+g. Bottom friction, Froude-\/number-\/depending breaking, P\+SI, etc.). \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_a7d2dfb64df35957d1252ce841c0cdf43}{setup\+\_\+tidal\+\_\+diagnostics}} (G, CS)
\begin{DoxyCompactList}\small\item\em Sets up diagnostics arrays for tidal mixing. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_af6fabb2bc6e4aabd3187938bda8098ec}{post\+\_\+tidal\+\_\+diagnostics}} (G, GV, h, CS)
\begin{DoxyCompactList}\small\item\em This subroutine offers up diagnostics of the tidal mixing. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_a31fc0b55d7766de2d21fb529e491de13}{tidal\+\_\+mixing\+\_\+h\+\_\+amp}} (h\+\_\+amp, G, j, CS)
\begin{DoxyCompactList}\small\item\em This subroutine returns a zonal slice of the topographic roughness amplitudes. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_adfd3a137ee6402fdcdfb7c46711e0e23}{read\+\_\+tidal\+\_\+energy}} (G, US, tidal\+\_\+energy\+\_\+type, tidal\+\_\+energy\+\_\+file, CS)
\begin{DoxyCompactList}\small\item\em This subroutine read tidal energy inputs from a file. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_a30a24b88982a5134253679d9484b3708}{read\+\_\+tidal\+\_\+constituents}} (G, US, tidal\+\_\+energy\+\_\+file, CS)
\begin{DoxyCompactList}\small\item\em This subroutine reads tidal input energy from a file by constituent. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_a4ec08e118dea2ecbac7e719ed73acc70}{tidal\+\_\+mixing\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clear pointers and deallocate memory. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tidal__mixing_aa8f8da6657f71aaef15f3cbe4e5f521d}\label{namespacemom__tidal__mixing_aa8f8da6657f71aaef15f3cbe4e5f521d}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!add\_int\_tide\_diffusivity@{add\_int\_tide\_diffusivity}}
\index{add\_int\_tide\_diffusivity@{add\_int\_tide\_diffusivity}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{add\_int\_tide\_diffusivity()}{add\_int\_tide\_diffusivity()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::add\+\_\+int\+\_\+tide\+\_\+diffusivity (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{N2\+\_\+bot,  }\item[{integer, intent(in)}]{j,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{T\+K\+E\+\_\+to\+\_\+\+Kd,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{max\+\_\+\+T\+KE,  }\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__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{N2\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, intent(in)}]{Kd\+\_\+max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine adds the effect of internal-\/tide-\/driven mixing to the layer diffusivities. The mechanisms considered are (1) local dissipation of internal waves generated by the barotropic flow (\char`\"{}itidal\char`\"{}), (2) local dissipation of internal waves generated by the propagating low modes (rays) of the internal tide (\char`\"{}lowmode\char`\"{}), and (3) local dissipation of internal lee waves. Will eventually need to add diffusivity due to other wave-\/breaking processes (e.\+g. Bottom friction, Froude-\/number-\/depending breaking, P\+SI, etc.). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s 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 h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+bot} & The near-\/bottom squared buoyancy frequency frequency \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+lay} & The squared buoyancy frequency of the layers \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em j} & The j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em tke\+\_\+to\+\_\+kd} & The conversion rate between the T\+KE dissipated within a layer and the diapycnal diffusivity within that layer, usually ($\sim$\+Rho\+\_\+0 / (G\+\_\+\+Earth $\ast$ d\+Rho\+\_\+lay)) \mbox{[}Z2 T-\/1 / Z3 T-\/3 = T2 Z-\/1 $\sim$$>$ s2 m-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+tke} & The energy required to for a layer to entrain to its maximum realizable thickness \mbox{[}Z3 T-\/3 $\sim$$>$ m3 s-\/3\mbox{]} \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+lay} & The diapycnal diffusivity in layers \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+int} & The diapycnal diffusivity at interfaces \\
\hline
\mbox{\texttt{ in}}  & {\em kd\+\_\+max} & The maximum increment for diapycnal diffusivity due to T\+K\+E-\/based processes \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. Set this to a negative value to have no limit. \\
\hline
\end{DoxyParams}


Definition at line 960 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{962   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< The ocean's grid structure}}
\DoxyCodeLine{963   \textcolor{keywordtype}{type}(verticalGrid\_type),          \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< The ocean's vertical grid structure}}
\DoxyCodeLine{964   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{965 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{966                                     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{967 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(in)}    :: N2\_bot\textcolor{comment}{ !< The near-\/bottom squared buoyancy frequency}}
\DoxyCodeLine{968 \textcolor{comment}{                                                            !! frequency [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{969 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: N2\_lay\textcolor{comment}{ !< The squared buoyancy frequency of the}}
\DoxyCodeLine{970 \textcolor{comment}{                                                            !! layers [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{971   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{      !< The j-\/index to work on}}
\DoxyCodeLine{972 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: TKE\_to\_Kd\textcolor{comment}{ !< The conversion rate between the TKE}}
\DoxyCodeLine{973 \textcolor{comment}{                                                            !! dissipated within a layer and the}}
\DoxyCodeLine{974 \textcolor{comment}{                                                            !! diapycnal diffusivity within that layer,}}
\DoxyCodeLine{975 \textcolor{comment}{                                                            !! usually (\string~Rho\_0 / (G\_Earth * dRho\_lay))}}
\DoxyCodeLine{976 \textcolor{comment}{                                                            !! [Z2 T-\/1 / Z3 T-\/3 = T2 Z-\/1 \string~> s2 m-\/1]}}
\DoxyCodeLine{977 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: max\_TKE\textcolor{comment}{ !< The energy required to for a layer to entrain}}
\DoxyCodeLine{978 \textcolor{comment}{                                                            !! to its maximum realizable thickness [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{979   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< The control structure for this module}}
\DoxyCodeLine{980 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{981                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{ !< The diapycnal diffusivity in layers [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{982 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{983                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{ !< The diapycnal diffusivity at interfaces}}
\DoxyCodeLine{984 \textcolor{comment}{                                                            !! [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{985 \textcolor{keywordtype}{  real},                             \textcolor{keywordtype}{intent(in)}    :: Kd\_max\textcolor{comment}{ !< The maximum increment for diapycnal}}
\DoxyCodeLine{986 \textcolor{comment}{                                                            !! diffusivity due to TKE-\/based processes}}
\DoxyCodeLine{987 \textcolor{comment}{                                                            !! [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{988 \textcolor{comment}{                                                            !! Set this to a negative value to have no limit.}}
\DoxyCodeLine{989 }
\DoxyCodeLine{990   \textcolor{comment}{! local}}
\DoxyCodeLine{991 }
\DoxyCodeLine{992 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{993     htot,             \& \textcolor{comment}{! total thickness above or below a layer, or the}}
\DoxyCodeLine{994                         \textcolor{comment}{! integrated thickness in the BBL [Z \string~> m].}}
\DoxyCodeLine{995     htot\_wkb,         \& \textcolor{comment}{! WKB scaled distance from top to bottom [Z \string~> m].}}
\DoxyCodeLine{996     tke\_itidal\_bot,   \& \textcolor{comment}{! internal tide TKE at ocean bottom [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{997     tke\_niku\_bot,     \& \textcolor{comment}{! lee-\/wave TKE at ocean bottom [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{998     tke\_lowmode\_bot,  \& \textcolor{comment}{! internal tide TKE at ocean bottom lost from all remote low modes [Z3 T-\/3 \string~> m3 s-\/3] (BDM)}}
\DoxyCodeLine{999     inv\_int,          \& \textcolor{comment}{! inverse of TKE decay for int tide over the depth of the ocean [nondim]}}
\DoxyCodeLine{1000     inv\_int\_lee,      \& \textcolor{comment}{! inverse of TKE decay for lee waves over the depth of the ocean [nondim]}}
\DoxyCodeLine{1001     inv\_int\_low,      \& \textcolor{comment}{! inverse of TKE decay for low modes over the depth of the ocean [nondim] (BDM)}}
\DoxyCodeLine{1002     z0\_polzin,        \& \textcolor{comment}{! TKE decay scale in Polzin formulation [Z \string~> m].}}
\DoxyCodeLine{1003     z0\_polzin\_scaled, \& \textcolor{comment}{! TKE decay scale in Polzin formulation [Z \string~> m].}}
\DoxyCodeLine{1004                         \textcolor{comment}{! multiplied by N2\_bot/N2\_meanz to be coherent with the WKB scaled z}}
\DoxyCodeLine{1005                         \textcolor{comment}{! z*=int(N2/N2\_bot) * N2\_bot/N2\_meanz = int(N2/N2\_meanz)}}
\DoxyCodeLine{1006                         \textcolor{comment}{! z0\_Polzin\_scaled = z0\_Polzin * N2\_bot/N2\_meanz}}
\DoxyCodeLine{1007     n2\_meanz,         \& \textcolor{comment}{! vertically averaged squared buoyancy frequency [T-\/2] for WKB scaling}}
\DoxyCodeLine{1008     tke\_itidal\_rem,   \& \textcolor{comment}{! remaining internal tide TKE (from barotropic source) [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{1009     tke\_niku\_rem,     \& \textcolor{comment}{! remaining lee-\/wave TKE [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{1010     tke\_lowmode\_rem,  \& \textcolor{comment}{! remaining internal tide TKE (from propagating low mode source) [Z3 T-\/3 \string~> m3 s-\/3] (BDM)}}
\DoxyCodeLine{1011     tke\_frac\_top,     \& \textcolor{comment}{! fraction of bottom TKE that should appear at top of a layer [nondim]}}
\DoxyCodeLine{1012     tke\_frac\_top\_lee, \& \textcolor{comment}{! fraction of bottom TKE that should appear at top of a layer [nondim]}}
\DoxyCodeLine{1013     tke\_frac\_top\_lowmode, \&}
\DoxyCodeLine{1014                         \textcolor{comment}{! fraction of bottom TKE that should appear at top of a layer [nondim] (BDM)}}
\DoxyCodeLine{1015     z\_from\_bot,       \& \textcolor{comment}{! distance from bottom [Z \string~> m].}}
\DoxyCodeLine{1016     z\_from\_bot\_wkb      \textcolor{comment}{! WKB scaled distance from bottom [Z \string~> m].}}
\DoxyCodeLine{1017 }
\DoxyCodeLine{1018 \textcolor{keywordtype}{  real} :: I\_rho0        \textcolor{comment}{! Inverse of the Boussinesq reference density, i.e. 1 / RHO0 [R-\/1 \string~> m3 kg-\/1]}}
\DoxyCodeLine{1019 \textcolor{keywordtype}{  real} :: Kd\_add        \textcolor{comment}{! diffusivity to add in a layer [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{1020 \textcolor{keywordtype}{  real} :: TKE\_itide\_lay \textcolor{comment}{! internal tide TKE imparted to a layer (from barotropic) [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{1021 \textcolor{keywordtype}{  real} :: TKE\_Niku\_lay  \textcolor{comment}{! lee-\/wave TKE imparted to a layer [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{1022 \textcolor{keywordtype}{  real} :: TKE\_lowmode\_lay \textcolor{comment}{! internal tide TKE imparted to a layer (from low mode) [Z3 T-\/3 \string~> m3 s-\/3] (BDM)}}
\DoxyCodeLine{1023 \textcolor{keywordtype}{  real} :: frac\_used     \textcolor{comment}{! fraction of TKE that can be used in a layer [nondim]}}
\DoxyCodeLine{1024 \textcolor{keywordtype}{  real} :: Izeta         \textcolor{comment}{! inverse of TKE decay scale [Z-\/1 \string~> m-\/1].}}
\DoxyCodeLine{1025 \textcolor{keywordtype}{  real} :: Izeta\_lee     \textcolor{comment}{! inverse of TKE decay scale for lee waves [Z-\/1 \string~> m-\/1].}}
\DoxyCodeLine{1026 \textcolor{keywordtype}{  real} :: z0Ps\_num      \textcolor{comment}{! The numerator of the unlimited z0\_Polzin\_scaled [Z T-\/3 \string~> m s-\/3].}}
\DoxyCodeLine{1027 \textcolor{keywordtype}{  real} :: z0Ps\_denom    \textcolor{comment}{! The denominator of the unlimited z0\_Polzin\_scaled [T-\/3 \string~> s-\/3].}}
\DoxyCodeLine{1028 \textcolor{keywordtype}{  real} :: z0\_psl        \textcolor{comment}{! temporary variable [Z \string~> m].}}
\DoxyCodeLine{1029 \textcolor{keywordtype}{  real} :: TKE\_lowmode\_tot \textcolor{comment}{! TKE from all low modes [R Z3 T-\/3 \string~> W m-\/2] (BDM)}}
\DoxyCodeLine{1030 }
\DoxyCodeLine{1031   \textcolor{keywordtype}{logical} :: use\_Polzin, use\_Simmons}
\DoxyCodeLine{1032   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{1033   \textcolor{keywordtype}{integer} :: i, k, is, ie, nz}
\DoxyCodeLine{1034   \textcolor{keywordtype}{integer} :: a, fr, m}
\DoxyCodeLine{1035   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()}
\DoxyCodeLine{1036 }
\DoxyCodeLine{1037   is = g\%isc ; ie = g\%iec ; nz = g\%ke}
\DoxyCodeLine{1038   dd => cs\%dd}
\DoxyCodeLine{1039 }
\DoxyCodeLine{1040   \textcolor{keywordflow}{if} (.not.(cs\%Int\_tide\_dissipation .or. cs\%Lee\_wave\_dissipation)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1041 }
\DoxyCodeLine{1042   \textcolor{keywordflow}{do} i=is,ie ; htot(i) = 0.0 ; inv\_int(i) = 0.0 ; inv\_int\_lee(i) = 0.0 ; inv\_int\_low(i) = 0.0 ;\textcolor{keywordflow}{enddo}}
\DoxyCodeLine{1043   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1044     htot(i) = htot(i) + gv\%H\_to\_Z*h(i,j,k)}
\DoxyCodeLine{1045 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1046 }
\DoxyCodeLine{1047   i\_rho0 = 1.0 / (gv\%Rho0)}
\DoxyCodeLine{1048 }
\DoxyCodeLine{1049   use\_polzin = ((cs\%Int\_tide\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09)) .or. \&}
\DoxyCodeLine{1050                 (cs\%lee\_wave\_dissipation .and. (cs\%lee\_wave\_profile == polzin\_09)) .or. \&}
\DoxyCodeLine{1051                 (cs\%Lowmode\_itidal\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09)))}
\DoxyCodeLine{1052   use\_simmons = ((cs\%Int\_tide\_dissipation .and. (cs\%int\_tide\_profile == stlaurent\_02)) .or. \&}
\DoxyCodeLine{1053                  (cs\%lee\_wave\_dissipation .and. (cs\%lee\_wave\_profile == stlaurent\_02)) .or. \&}
\DoxyCodeLine{1054                  (cs\%Lowmode\_itidal\_dissipation .and. (cs\%int\_tide\_profile == stlaurent\_02)))}
\DoxyCodeLine{1055 }
\DoxyCodeLine{1056   \textcolor{comment}{! Calculate parameters for vertical structure of dissipation}}
\DoxyCodeLine{1057   \textcolor{comment}{! Simmons:}}
\DoxyCodeLine{1058   \textcolor{keywordflow}{if} ( use\_simmons ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1059     izeta = 1.0 / max(cs\%Int\_tide\_decay\_scale, gv\%H\_subroundoff*gv\%H\_to\_Z)}
\DoxyCodeLine{1060     izeta\_lee = 1.0 / max(cs\%Int\_tide\_decay\_scale*cs\%Decay\_scale\_factor\_lee, \&}
\DoxyCodeLine{1061                           gv\%H\_subroundoff*gv\%H\_to\_Z)}
\DoxyCodeLine{1062     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1063       cs\%Nb(i,j) = sqrt(n2\_bot(i))}
\DoxyCodeLine{1064       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_bot)) dd\%N2\_bot(i,j) = n2\_bot(i)}
\DoxyCodeLine{1065       \textcolor{keywordflow}{if} ( cs\%Int\_tide\_dissipation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1066         \textcolor{keywordflow}{if} (izeta*htot(i) > 1.0e-\/14) \textcolor{keywordflow}{then} \textcolor{comment}{! L'Hospital's version of Adcroft's reciprocal rule.}}
\DoxyCodeLine{1067           inv\_int(i) = 1.0 / (1.0 -\/ exp(-\/izeta*htot(i)))}
\DoxyCodeLine{1068 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1069 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1070       \textcolor{keywordflow}{if} ( cs\%Lee\_wave\_dissipation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1071         \textcolor{keywordflow}{if} (izeta\_lee*htot(i) > 1.0e-\/14) \textcolor{keywordflow}{then}  \textcolor{comment}{! L'Hospital's version of Adcroft's reciprocal rule.}}
\DoxyCodeLine{1072           inv\_int\_lee(i) = 1.0 / (1.0 -\/ exp(-\/izeta\_lee*htot(i)))}
\DoxyCodeLine{1073 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1074 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1075       \textcolor{keywordflow}{if} ( cs\%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1076         \textcolor{keywordflow}{if} (izeta*htot(i) > 1.0e-\/14) \textcolor{keywordflow}{then} \textcolor{comment}{! L'Hospital's version of Adcroft's reciprocal rule.}}
\DoxyCodeLine{1077           inv\_int\_low(i) = 1.0 / (1.0 -\/ exp(-\/izeta*htot(i)))}
\DoxyCodeLine{1078 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1079 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1080       z\_from\_bot(i) = gv\%H\_to\_Z*h(i,j,nz)}
\DoxyCodeLine{1081 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1082 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Simmons}}
\DoxyCodeLine{1083 }
\DoxyCodeLine{1084   \textcolor{comment}{! Polzin:}}
\DoxyCodeLine{1085   \textcolor{keywordflow}{if} ( use\_polzin ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1086     \textcolor{comment}{! WKB scaling of the vertical coordinate}}
\DoxyCodeLine{1087     \textcolor{keywordflow}{do} i=is,ie ; n2\_meanz(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1088     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1089       n2\_meanz(i) = n2\_meanz(i) + n2\_lay(i,k) * gv\%H\_to\_Z * h(i,j,k)}
\DoxyCodeLine{1090 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1091     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1092       n2\_meanz(i) = n2\_meanz(i) / (htot(i) + gv\%H\_subroundoff*gv\%H\_to\_Z)}
\DoxyCodeLine{1093       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_meanz))  dd\%N2\_meanz(i,j) = n2\_meanz(i)}
\DoxyCodeLine{1094 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1095 }
\DoxyCodeLine{1096     \textcolor{comment}{! WKB scaled z*(z=H) z* at the surface using the modified Polzin WKB scaling}}
\DoxyCodeLine{1097     \textcolor{keywordflow}{do} i=is,ie ; htot\_wkb(i) = htot(i) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1098 \textcolor{comment}{!    do i=is,ie ; htot\_WKB(i) = 0.0 ; enddo}}
\DoxyCodeLine{1099 \textcolor{comment}{!    do k=1,nz ; do i=is,ie}}
\DoxyCodeLine{1100 \textcolor{comment}{!      htot\_WKB(i) = htot\_WKB(i) + GV\%H\_to\_Z*h(i,j,k) * N2\_lay(i,k) / N2\_meanz(i)}}
\DoxyCodeLine{1101 \textcolor{comment}{!    enddo ; enddo}}
\DoxyCodeLine{1102     \textcolor{comment}{! htot\_WKB(i) = htot(i) ! Nearly equivalent and simpler}}
\DoxyCodeLine{1103 }
\DoxyCodeLine{1104     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1105       cs\%Nb(i,j) = sqrt(n2\_bot(i))}
\DoxyCodeLine{1106       \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1107         \textcolor{keywordflow}{if} ((cs\%tideamp(i,j) > 0.0) .and. \&}
\DoxyCodeLine{1108             (cs\%kappa\_itides**2 * cs\%h2(i,j) * cs\%Nb(i,j)**3 > 1.0e-\/14*us\%T\_to\_s**3) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1109           z0\_polzin(i) = cs\%Polzin\_decay\_scale\_factor * cs\%Nu\_Polzin * \&}
\DoxyCodeLine{1110                          cs\%Nbotref\_Polzin**2 * cs\%tideamp(i,j) / \&}
\DoxyCodeLine{1111                        ( cs\%kappa\_itides**2 * cs\%h2(i,j) * cs\%Nb(i,j)**3 )}
\DoxyCodeLine{1112           \textcolor{keywordflow}{if} (z0\_polzin(i) < cs\%Polzin\_min\_decay\_scale) \&}
\DoxyCodeLine{1113             z0\_polzin(i) = cs\%Polzin\_min\_decay\_scale}
\DoxyCodeLine{1114           \textcolor{keywordflow}{if} (n2\_meanz(i) > 1.0e-\/14*us\%T\_to\_s**2  ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1115             z0\_polzin\_scaled(i) = z0\_polzin(i)*cs\%Nb(i,j)**2 / n2\_meanz(i)}
\DoxyCodeLine{1116           \textcolor{keywordflow}{else}}
\DoxyCodeLine{1117             z0\_polzin\_scaled(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1118 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1119           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) > (cs\%Polzin\_decay\_scale\_max\_factor * htot(i)) ) \&}
\DoxyCodeLine{1120             z0\_polzin\_scaled(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1121         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1122           z0\_polzin(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1123           z0\_polzin\_scaled(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1124 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1125       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1126         z0ps\_num = (cs\%Polzin\_decay\_scale\_factor * cs\%Nu\_Polzin * cs\%Nbotref\_Polzin**2) * cs\%tideamp(i,j)}
\DoxyCodeLine{1127         z0ps\_denom = ( cs\%kappa\_itides**2 * cs\%h2(i,j) * cs\%Nb(i,j) * n2\_meanz(i) )}
\DoxyCodeLine{1128         \textcolor{keywordflow}{if} ((cs\%tideamp(i,j) > 0.0) .and. \&}
\DoxyCodeLine{1129             (z0ps\_num < z0ps\_denom * cs\%Polzin\_decay\_scale\_max\_factor * htot(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1130           z0\_polzin\_scaled(i) = z0ps\_num / z0ps\_denom}
\DoxyCodeLine{1131 }
\DoxyCodeLine{1132           \textcolor{keywordflow}{if} (abs(n2\_meanz(i) * z0\_polzin\_scaled(i)) < \&}
\DoxyCodeLine{1133               cs\%Nb(i,j)**2 * (cs\%Polzin\_decay\_scale\_max\_factor * htot(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1134             z0\_polzin(i) = z0\_polzin\_scaled(i) * (n2\_meanz(i) / cs\%Nb(i,j)**2)}
\DoxyCodeLine{1135           \textcolor{keywordflow}{else}}
\DoxyCodeLine{1136             z0\_polzin(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1137 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1138         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1139           z0\_polzin(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1140           z0\_polzin\_scaled(i) = cs\%Polzin\_decay\_scale\_max\_factor * htot(i)}
\DoxyCodeLine{1141 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1142 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1143 }
\DoxyCodeLine{1144       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Polzin\_decay\_scale)) \&}
\DoxyCodeLine{1145         dd\%Polzin\_decay\_scale(i,j) = z0\_polzin(i)}
\DoxyCodeLine{1146       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Polzin\_decay\_scale\_scaled)) \&}
\DoxyCodeLine{1147         dd\%Polzin\_decay\_scale\_scaled(i,j) = z0\_polzin\_scaled(i)}
\DoxyCodeLine{1148       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_bot)) dd\%N2\_bot(i,j) = cs\%Nb(i,j)*cs\%Nb(i,j)}
\DoxyCodeLine{1149 }
\DoxyCodeLine{1150       \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1151         \textcolor{comment}{! These expressions use dimensional constants to avoid NaN values.}}
\DoxyCodeLine{1152         \textcolor{keywordflow}{if} ( cs\%Int\_tide\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1153           \textcolor{keywordflow}{if} (htot\_wkb(i) > 1.0e-\/14*us\%m\_to\_Z) \&}
\DoxyCodeLine{1154             inv\_int(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0}
\DoxyCodeLine{1155 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1156         \textcolor{keywordflow}{if} ( cs\%lee\_wave\_dissipation .and. (cs\%lee\_wave\_profile == polzin\_09) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1157           \textcolor{keywordflow}{if} (htot\_wkb(i) > 1.0e-\/14*us\%m\_to\_Z) \&}
\DoxyCodeLine{1158             inv\_int\_lee(i) = ( z0\_polzin\_scaled(i)*cs\%Decay\_scale\_factor\_lee / htot\_wkb(i) ) + 1.0}
\DoxyCodeLine{1159 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1160         \textcolor{keywordflow}{if} ( cs\%Lowmode\_itidal\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1161           \textcolor{keywordflow}{if} (htot\_wkb(i) > 1.0e-\/14*us\%m\_to\_Z) \&}
\DoxyCodeLine{1162             inv\_int\_low(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0}
\DoxyCodeLine{1163 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1164       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1165         \textcolor{comment}{! These expressions give values of Inv\_int < 10\string^14 using a variant of Adcroft's reciprocal rule.}}
\DoxyCodeLine{1166         inv\_int(i) = 0.0 ; inv\_int\_lee(i) = 0.0 ; inv\_int\_low(i) = 0.0}
\DoxyCodeLine{1167         \textcolor{keywordflow}{if} ( cs\%Int\_tide\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1168           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) < 1.0e14 * htot\_wkb(i)) \&}
\DoxyCodeLine{1169             inv\_int(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0}
\DoxyCodeLine{1170 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1171         \textcolor{keywordflow}{if} ( cs\%lee\_wave\_dissipation .and. (cs\%lee\_wave\_profile == polzin\_09) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1172           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) < 1.0e14 * htot\_wkb(i)) \&}
\DoxyCodeLine{1173             inv\_int\_lee(i) = ( z0\_polzin\_scaled(i)*cs\%Decay\_scale\_factor\_lee / htot\_wkb(i) ) + 1.0}
\DoxyCodeLine{1174 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1175         \textcolor{keywordflow}{if} ( cs\%Lowmode\_itidal\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1176           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) < 1.0e14 * htot\_wkb(i)) \&}
\DoxyCodeLine{1177             inv\_int\_low(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0}
\DoxyCodeLine{1178 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1179 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1180 }
\DoxyCodeLine{1181       z\_from\_bot(i) = gv\%H\_to\_Z*h(i,j,nz)}
\DoxyCodeLine{1182       \textcolor{comment}{! Use the new formulation for WKB scaling.  N2 is referenced to its vertical mean.}}
\DoxyCodeLine{1183       \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1184         \textcolor{keywordflow}{if} (n2\_meanz(i) > 1.0e-\/14*us\%T\_to\_s**2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1185           z\_from\_bot\_wkb(i) = gv\%H\_to\_Z*h(i,j,nz) * n2\_lay(i,nz) / n2\_meanz(i)}
\DoxyCodeLine{1186         \textcolor{keywordflow}{else} ; z\_from\_bot\_wkb(i) = 0 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1187       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1188         \textcolor{keywordflow}{if} (gv\%H\_to\_Z*h(i,j,nz) * n2\_lay(i,nz) < n2\_meanz(i) * (1.0e14 * htot\_wkb(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1189           z\_from\_bot\_wkb(i) = gv\%H\_to\_Z*h(i,j,nz) * n2\_lay(i,nz) / n2\_meanz(i)}
\DoxyCodeLine{1190         \textcolor{keywordflow}{else} ; z\_from\_bot\_wkb(i) = 0 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1191 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1192 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1193 \textcolor{keywordflow}{  endif}  \textcolor{comment}{! Polzin}}
\DoxyCodeLine{1194 }
\DoxyCodeLine{1195   \textcolor{comment}{! Calculate/get dissipation values at bottom}}
\DoxyCodeLine{1196   \textcolor{comment}{! Both Polzin and Simmons:}}
\DoxyCodeLine{1197   \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1198     \textcolor{comment}{! Dissipation of locally trapped internal tide (non-\/propagating high modes)}}
\DoxyCodeLine{1199     tke\_itidal\_bot(i) = min(cs\%TKE\_itidal(i,j)*cs\%Nb(i,j), cs\%TKE\_itide\_max)}
\DoxyCodeLine{1200     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%TKE\_itidal\_used)) \&}
\DoxyCodeLine{1201       dd\%TKE\_itidal\_used(i,j) = tke\_itidal\_bot(i)}
\DoxyCodeLine{1202     tke\_itidal\_bot(i) = (i\_rho0 * cs\%Mu\_itides * cs\%Gamma\_itides) * tke\_itidal\_bot(i)}
\DoxyCodeLine{1203     \textcolor{comment}{! Dissipation of locally trapped lee waves}}
\DoxyCodeLine{1204     tke\_niku\_bot(i) = 0.0}
\DoxyCodeLine{1205     \textcolor{keywordflow}{if} (cs\%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1206       tke\_niku\_bot(i) = (i\_rho0 * cs\%Mu\_itides * cs\%Gamma\_lee) * cs\%TKE\_Niku(i,j)}
\DoxyCodeLine{1207 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1208     \textcolor{comment}{! Dissipation of propagating internal tide (baroclinic low modes; rays) (BDM)}}
\DoxyCodeLine{1209     tke\_lowmode\_tot    = 0.0}
\DoxyCodeLine{1210     tke\_lowmode\_bot(i) = 0.0}
\DoxyCodeLine{1211     \textcolor{keywordflow}{if} (cs\%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1212       \textcolor{comment}{! get loss rate due to wave drag on low modes (already multiplied by q)}}
\DoxyCodeLine{1213 }
\DoxyCodeLine{1214       \textcolor{comment}{! TODO: uncomment the following call and fix it}}
\DoxyCodeLine{1215       \textcolor{comment}{!call get\_lowmode\_loss(i,j,G,CS\%int\_tide\_CSp,"{}WaveDrag"{},TKE\_lowmode\_tot)}}
\DoxyCodeLine{1216       \textcolor{keyword}{write} (mesg,*) \textcolor{stringliteral}{"{}========"{}}, \_\_file\_\_, \_\_line\_\_}
\DoxyCodeLine{1217       \textcolor{keyword}{call }mom\_error(fatal,trim(mesg)//\textcolor{stringliteral}{"{}: this block not supported yet. (aa)"{}})}
\DoxyCodeLine{1218 }
\DoxyCodeLine{1219       tke\_lowmode\_bot(i) = cs\%Mu\_itides * i\_rho0 * tke\_lowmode\_tot}
\DoxyCodeLine{1220 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1221     \textcolor{comment}{! Vertical energy flux at bottom}}
\DoxyCodeLine{1222     tke\_itidal\_rem(i)  = inv\_int(i)     * tke\_itidal\_bot(i)}
\DoxyCodeLine{1223     tke\_niku\_rem(i)    = inv\_int\_lee(i) * tke\_niku\_bot(i)}
\DoxyCodeLine{1224     tke\_lowmode\_rem(i) = inv\_int\_low(i) * tke\_lowmode\_bot(i)}
\DoxyCodeLine{1225 }
\DoxyCodeLine{1226     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_itidal)) dd\%Fl\_itidal(i,j,nz) = tke\_itidal\_rem(i) \textcolor{comment}{!why is this here? BDM}}
\DoxyCodeLine{1227 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1228 }
\DoxyCodeLine{1229   \textcolor{comment}{! Estimate the work that would be done by mixing in each layer.}}
\DoxyCodeLine{1230   \textcolor{comment}{! Simmons:}}
\DoxyCodeLine{1231   \textcolor{keywordflow}{if} ( use\_simmons ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1232     \textcolor{keywordflow}{do} k=nz-\/1,2,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1233       \textcolor{keywordflow}{if} (max\_tke(i,k) <= 0.0) cycle}
\DoxyCodeLine{1234       z\_from\_bot(i) = z\_from\_bot(i) + gv\%H\_to\_Z*h(i,j,k)}
\DoxyCodeLine{1235 }
\DoxyCodeLine{1236       \textcolor{comment}{! Fraction of bottom flux predicted to reach top of this layer}}
\DoxyCodeLine{1237       tke\_frac\_top(i)         = inv\_int(i)     * exp(-\/izeta * z\_from\_bot(i))}
\DoxyCodeLine{1238       tke\_frac\_top\_lee(i)     = inv\_int\_lee(i) * exp(-\/izeta\_lee * z\_from\_bot(i))}
\DoxyCodeLine{1239       tke\_frac\_top\_lowmode(i) = inv\_int\_low(i) * exp(-\/izeta * z\_from\_bot(i))}
\DoxyCodeLine{1240 }
\DoxyCodeLine{1241       \textcolor{comment}{! Actual influx at bottom of layer minus predicted outflux at top of layer to give}}
\DoxyCodeLine{1242       \textcolor{comment}{! predicted power expended}}
\DoxyCodeLine{1243       tke\_itide\_lay   = tke\_itidal\_rem(i)  -\/ tke\_itidal\_bot(i) * tke\_frac\_top(i)}
\DoxyCodeLine{1244       tke\_niku\_lay    = tke\_niku\_rem(i)    -\/ tke\_niku\_bot(i)   * tke\_frac\_top\_lee(i)}
\DoxyCodeLine{1245       tke\_lowmode\_lay = tke\_lowmode\_rem(i) -\/ tke\_lowmode\_bot(i)* tke\_frac\_top\_lowmode(i)}
\DoxyCodeLine{1246 }
\DoxyCodeLine{1247       \textcolor{comment}{! Actual power expended may be less than predicted if stratification is weak; adjust}}
\DoxyCodeLine{1248       \textcolor{keywordflow}{if} (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay > (max\_tke(i,k))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1249         frac\_used = (max\_tke(i,k)) / (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)}
\DoxyCodeLine{1250         tke\_itide\_lay   = frac\_used * tke\_itide\_lay}
\DoxyCodeLine{1251         tke\_niku\_lay    = frac\_used * tke\_niku\_lay}
\DoxyCodeLine{1252         tke\_lowmode\_lay = frac\_used * tke\_lowmode\_lay}
\DoxyCodeLine{1253 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1254 }
\DoxyCodeLine{1255       \textcolor{comment}{! Calculate vertical flux available to bottom of layer above}}
\DoxyCodeLine{1256       tke\_itidal\_rem(i)  = tke\_itidal\_rem(i)  -\/ tke\_itide\_lay}
\DoxyCodeLine{1257       tke\_niku\_rem(i)    = tke\_niku\_rem(i)    -\/ tke\_niku\_lay}
\DoxyCodeLine{1258       tke\_lowmode\_rem(i) = tke\_lowmode\_rem(i) -\/ tke\_lowmode\_lay}
\DoxyCodeLine{1259 }
\DoxyCodeLine{1260       \textcolor{comment}{! Convert power to diffusivity}}
\DoxyCodeLine{1261       kd\_add  = tke\_to\_kd(i,k) * (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)}
\DoxyCodeLine{1262 }
\DoxyCodeLine{1263       \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1264       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1265         kd\_lay(i,k) = kd\_lay(i,k) + kd\_add}
\DoxyCodeLine{1266 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1267 }
\DoxyCodeLine{1268       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1269         kd\_int(i,k)   = kd\_int(i,k)   + 0.5 * kd\_add}
\DoxyCodeLine{1270         kd\_int(i,k+1) = kd\_int(i,k+1) + 0.5 * kd\_add}
\DoxyCodeLine{1271 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1272 }
\DoxyCodeLine{1273       \textcolor{comment}{! diagnostics}}
\DoxyCodeLine{1274       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_itidal)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1275         \textcolor{comment}{! If at layers, dd\%Kd\_itidal is just TKE\_to\_Kd(i,k) * TKE\_itide\_lay}}
\DoxyCodeLine{1276         \textcolor{comment}{! The following sets the interface diagnostics.}}
\DoxyCodeLine{1277         kd\_add = tke\_to\_kd(i,k) * tke\_itide\_lay}
\DoxyCodeLine{1278         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1279         \textcolor{keywordflow}{if} (k>1)  dd\%Kd\_itidal(i,j,k)   = dd\%Kd\_itidal(i,j,k)   + 0.5*kd\_add}
\DoxyCodeLine{1280         \textcolor{keywordflow}{if} (k<nz) dd\%Kd\_itidal(i,j,k+1) = dd\%Kd\_itidal(i,j,k+1) + 0.5*kd\_add}
\DoxyCodeLine{1281 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1282       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Itidal\_work)) \&}
\DoxyCodeLine{1283         dd\%Kd\_itidal\_work(i,j,k) = gv\%Rho0 * tke\_itide\_lay}
\DoxyCodeLine{1284       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_itidal)) dd\%Fl\_itidal(i,j,k) = tke\_itidal\_rem(i)}
\DoxyCodeLine{1285 }
\DoxyCodeLine{1286       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Niku)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1287         \textcolor{comment}{! If at layers, dd\%Kd\_Niku(i,j,K) is just TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}}
\DoxyCodeLine{1288         \textcolor{comment}{! The following sets the interface diagnostics.}}
\DoxyCodeLine{1289         kd\_add = tke\_to\_kd(i,k) * tke\_niku\_lay}
\DoxyCodeLine{1290         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1291         \textcolor{keywordflow}{if} (k>1) dd\%Kd\_Niku(i,j,k)    = dd\%Kd\_Niku(i,j,k)   + 0.5*kd\_add}
\DoxyCodeLine{1292         \textcolor{keywordflow}{if} (k<nz) dd\%Kd\_Niku(i,j,k+1) = dd\%Kd\_Niku(i,j,k+1) + 0.5*kd\_add}
\DoxyCodeLine{1293 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1294 \textcolor{comment}{!     if (associated(dd\%Kd\_Niku)) dd\%Kd\_Niku(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}}
\DoxyCodeLine{1295       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Niku\_work)) \&}
\DoxyCodeLine{1296         dd\%Kd\_Niku\_work(i,j,k) = gv\%Rho0 * tke\_niku\_lay}
\DoxyCodeLine{1297 }
\DoxyCodeLine{1298       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_lowmode)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1299         \textcolor{comment}{! If at layers, dd\%Kd\_lowmode is just TKE\_to\_Kd(i,k) * TKE\_lowmode\_lay}}
\DoxyCodeLine{1300         \textcolor{comment}{! The following sets the interface diagnostics.}}
\DoxyCodeLine{1301         kd\_add = tke\_to\_kd(i,k) * tke\_lowmode\_lay}
\DoxyCodeLine{1302         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1303         \textcolor{keywordflow}{if} (k>1)  dd\%Kd\_lowmode(i,j,k)   = dd\%Kd\_lowmode(i,j,k)   + 0.5*kd\_add}
\DoxyCodeLine{1304         \textcolor{keywordflow}{if} (k<nz) dd\%Kd\_lowmode(i,j,k+1) = dd\%Kd\_lowmode(i,j,k+1) + 0.5*kd\_add}
\DoxyCodeLine{1305 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1306       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_lowmode\_work)) \&}
\DoxyCodeLine{1307         dd\%Kd\_lowmode\_work(i,j,k) = gv\%Rho0 * tke\_lowmode\_lay}
\DoxyCodeLine{1308       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_lowmode)) dd\%Fl\_lowmode(i,j,k) = tke\_lowmode\_rem(i)}
\DoxyCodeLine{1309 }
\DoxyCodeLine{1310 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1311 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Simmons}}
\DoxyCodeLine{1312 }
\DoxyCodeLine{1313   \textcolor{comment}{! Polzin:}}
\DoxyCodeLine{1314   \textcolor{keywordflow}{if} ( use\_polzin ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1315     \textcolor{keywordflow}{do} k=nz-\/1,2,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1316       \textcolor{keywordflow}{if} (max\_tke(i,k) <= 0.0) cycle}
\DoxyCodeLine{1317       z\_from\_bot(i) = z\_from\_bot(i) + gv\%H\_to\_Z*h(i,j,k)}
\DoxyCodeLine{1318       \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1319         \textcolor{keywordflow}{if} (n2\_meanz(i) > 1.0e-\/14*us\%T\_to\_s**2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1320           z\_from\_bot\_wkb(i) = z\_from\_bot\_wkb(i) \&}
\DoxyCodeLine{1321               + gv\%H\_to\_Z * h(i,j,k) * n2\_lay(i,k) / n2\_meanz(i)}
\DoxyCodeLine{1322         \textcolor{keywordflow}{else} ; z\_from\_bot\_wkb(i) = 0 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1323       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1324         \textcolor{keywordflow}{if} (gv\%H\_to\_Z*h(i,j,k) * n2\_lay(i,k) < (1.0e14 * htot\_wkb(i)) * n2\_meanz(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1325           z\_from\_bot\_wkb(i) = z\_from\_bot\_wkb(i) + \&}
\DoxyCodeLine{1326              gv\%H\_to\_Z*h(i,j,k) * n2\_lay(i,k) / n2\_meanz(i)}
\DoxyCodeLine{1327 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1328 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1329 }
\DoxyCodeLine{1330       \textcolor{comment}{! Fraction of bottom flux predicted to reach top of this layer}}
\DoxyCodeLine{1331       tke\_frac\_top(i)     = ( inv\_int(i) * z0\_polzin\_scaled(i) ) / \&}
\DoxyCodeLine{1332                             ( z0\_polzin\_scaled(i) + z\_from\_bot\_wkb(i) )}
\DoxyCodeLine{1333       z0\_psl = z0\_polzin\_scaled(i)*cs\%Decay\_scale\_factor\_lee}
\DoxyCodeLine{1334       tke\_frac\_top\_lee(i) = (inv\_int\_lee(i) * z0\_psl) / (z0\_psl + z\_from\_bot\_wkb(i))}
\DoxyCodeLine{1335       tke\_frac\_top\_lowmode(i) = ( inv\_int\_low(i) * z0\_polzin\_scaled(i) ) / \&}
\DoxyCodeLine{1336                             ( z0\_polzin\_scaled(i) + z\_from\_bot\_wkb(i) )}
\DoxyCodeLine{1337 }
\DoxyCodeLine{1338       \textcolor{comment}{! Actual influx at bottom of layer minus predicted outflux at top of layer to give}}
\DoxyCodeLine{1339       \textcolor{comment}{! predicted power expended}}
\DoxyCodeLine{1340       tke\_itide\_lay   = tke\_itidal\_rem(i)  -\/ tke\_itidal\_bot(i) *tke\_frac\_top(i)}
\DoxyCodeLine{1341       tke\_niku\_lay    = tke\_niku\_rem(i)    -\/ tke\_niku\_bot(i)   * tke\_frac\_top\_lee(i)}
\DoxyCodeLine{1342       tke\_lowmode\_lay = tke\_lowmode\_rem(i) -\/ tke\_lowmode\_bot(i)*tke\_frac\_top\_lowmode(i)}
\DoxyCodeLine{1343 }
\DoxyCodeLine{1344       \textcolor{comment}{! Actual power expended may be less than predicted if stratification is weak; adjust}}
\DoxyCodeLine{1345       \textcolor{keywordflow}{if} (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay > (max\_tke(i,k))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1346         frac\_used = (max\_tke(i,k)) / (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)}
\DoxyCodeLine{1347         tke\_itide\_lay   = frac\_used * tke\_itide\_lay}
\DoxyCodeLine{1348         tke\_niku\_lay    = frac\_used * tke\_niku\_lay}
\DoxyCodeLine{1349         tke\_lowmode\_lay = frac\_used * tke\_lowmode\_lay}
\DoxyCodeLine{1350 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1351 }
\DoxyCodeLine{1352       \textcolor{comment}{! Calculate vertical flux available to bottom of layer above}}
\DoxyCodeLine{1353       tke\_itidal\_rem(i)  = tke\_itidal\_rem(i)  -\/ tke\_itide\_lay}
\DoxyCodeLine{1354       tke\_niku\_rem(i)    = tke\_niku\_rem(i)    -\/ tke\_niku\_lay}
\DoxyCodeLine{1355       tke\_lowmode\_rem(i) = tke\_lowmode\_rem(i) -\/ tke\_lowmode\_lay}
\DoxyCodeLine{1356 }
\DoxyCodeLine{1357       \textcolor{comment}{! Convert power to diffusivity}}
\DoxyCodeLine{1358       kd\_add  = tke\_to\_kd(i,k) * (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)}
\DoxyCodeLine{1359 }
\DoxyCodeLine{1360       \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1361       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1362         kd\_lay(i,k) = kd\_lay(i,k) + kd\_add}
\DoxyCodeLine{1363 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1364 }
\DoxyCodeLine{1365       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1366         kd\_int(i,k)   = kd\_int(i,k)   + 0.5 * kd\_add}
\DoxyCodeLine{1367         kd\_int(i,k+1) = kd\_int(i,k+1) + 0.5 * kd\_add}
\DoxyCodeLine{1368 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1369 }
\DoxyCodeLine{1370       \textcolor{comment}{! diagnostics}}
\DoxyCodeLine{1371       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_itidal)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1372         \textcolor{comment}{! If at layers, this is just dd\%Kd\_itidal(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_itide\_lay}}
\DoxyCodeLine{1373         \textcolor{comment}{! The following sets the interface diagnostics.}}
\DoxyCodeLine{1374         kd\_add = tke\_to\_kd(i,k) * tke\_itide\_lay}
\DoxyCodeLine{1375         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1376         \textcolor{keywordflow}{if} (k>1)  dd\%Kd\_itidal(i,j,k)   = dd\%Kd\_itidal(i,j,k)   + 0.5*kd\_add}
\DoxyCodeLine{1377         \textcolor{keywordflow}{if} (k<nz) dd\%Kd\_itidal(i,j,k+1) = dd\%Kd\_itidal(i,j,k+1) + 0.5*kd\_add}
\DoxyCodeLine{1378 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1379       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Itidal\_work)) \&}
\DoxyCodeLine{1380         dd\%Kd\_itidal\_work(i,j,k) = gv\%Rho0 * tke\_itide\_lay}
\DoxyCodeLine{1381       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_itidal)) dd\%Fl\_itidal(i,j,k) = tke\_itidal\_rem(i)}
\DoxyCodeLine{1382 }
\DoxyCodeLine{1383       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Niku)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1384         \textcolor{comment}{! If at layers, this is just dd\%Kd\_Niku(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}}
\DoxyCodeLine{1385         \textcolor{comment}{! The following sets the interface diagnostics.}}
\DoxyCodeLine{1386         kd\_add = tke\_to\_kd(i,k) * tke\_niku\_lay}
\DoxyCodeLine{1387         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1388         \textcolor{keywordflow}{if} (k>1) dd\%Kd\_Niku(i,j,k)    = dd\%Kd\_Niku(i,j,k)   + 0.5*kd\_add}
\DoxyCodeLine{1389         \textcolor{keywordflow}{if} (k<nz) dd\%Kd\_Niku(i,j,k+1) = dd\%Kd\_Niku(i,j,k+1) + 0.5*kd\_add}
\DoxyCodeLine{1390 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1391    \textcolor{comment}{!  if (associated(dd\%Kd\_Niku)) dd\%Kd\_Niku(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}}
\DoxyCodeLine{1392       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Niku\_work)) dd\%Kd\_Niku\_work(i,j,k) = gv\%Rho0 * tke\_niku\_lay}
\DoxyCodeLine{1393 }
\DoxyCodeLine{1394       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_lowmode)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1395         \textcolor{comment}{! If at layers, dd\%Kd\_lowmode is just TKE\_to\_Kd(i,k) * TKE\_lowmode\_lay}}
\DoxyCodeLine{1396         \textcolor{comment}{! The following sets the interface diagnostics.}}
\DoxyCodeLine{1397         kd\_add = tke\_to\_kd(i,k) * tke\_lowmode\_lay}
\DoxyCodeLine{1398         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)}
\DoxyCodeLine{1399         \textcolor{keywordflow}{if} (k>1)  dd\%Kd\_lowmode(i,j,k)   = dd\%Kd\_lowmode(i,j,k)   + 0.5*kd\_add}
\DoxyCodeLine{1400         \textcolor{keywordflow}{if} (k<nz) dd\%Kd\_lowmode(i,j,k+1) = dd\%Kd\_lowmode(i,j,k+1) + 0.5*kd\_add}
\DoxyCodeLine{1401 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1402       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_lowmode\_work)) \&}
\DoxyCodeLine{1403         dd\%Kd\_lowmode\_work(i,j,k) = gv\%Rho0 * tke\_lowmode\_lay}
\DoxyCodeLine{1404       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_lowmode)) dd\%Fl\_lowmode(i,j,k) = tke\_lowmode\_rem(i)}
\DoxyCodeLine{1405 }
\DoxyCodeLine{1406 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1407 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Polzin}}
\DoxyCodeLine{1408 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_af9e675f60c60606f767d4bb1321dba2c}\label{namespacemom__tidal__mixing_af9e675f60c60606f767d4bb1321dba2c}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!calculate\_cvmix\_tidal@{calculate\_cvmix\_tidal}}
\index{calculate\_cvmix\_tidal@{calculate\_cvmix\_tidal}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{calculate\_cvmix\_tidal()}{calculate\_cvmix\_tidal()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::calculate\+\_\+cvmix\+\_\+tidal (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{integer, intent(in)}]{j,  }\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__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(in)}]{N2\+\_\+int,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{Kv }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the C\+V\+Mix routines to compute tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the interface diffusivities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em j} & The j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+int} & The squared buoyancy frequency at the interfaces \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+lay} & The diapycnal diffusivity in the layers \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+int} & The diapycnal diffusivity at interfaces \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
 & {\em kv} & The \char`\"{}slow\char`\"{} vertical viscosity at each interface (not layer!) \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 717 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{718   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{     !< The j-\/index to work on}}
\DoxyCodeLine{719   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< Grid structure.}}
\DoxyCodeLine{720   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< ocean vertical grid structure}}
\DoxyCodeLine{721   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{722   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< This module's control structure.}}
\DoxyCodeLine{723 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)} :: N2\_int\textcolor{comment}{ !< The squared buoyancy}}
\DoxyCodeLine{724 \textcolor{comment}{                                                  !! frequency at the interfaces [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{725 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{726                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{727 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{728                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{!< The diapycnal diffusivity in the layers [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{729 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{730                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{!< The diapycnal diffusivity at interfaces [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{731 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{pointer}       :: Kv\textcolor{comment}{    !< The "{}slow"{} vertical viscosity at each interface}}
\DoxyCodeLine{732 \textcolor{comment}{                                                  !! (not layer!) [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{733   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{734 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: Kd\_tidal    \textcolor{comment}{! tidal diffusivity [m2 s-\/1]}}
\DoxyCodeLine{735 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: Kv\_tidal    \textcolor{comment}{! tidal viscosity [m2 s-\/1]}}
\DoxyCodeLine{736 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: vert\_dep    \textcolor{comment}{! vertical deposition}}
\DoxyCodeLine{737 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: iFaceHeight \textcolor{comment}{! Height of interfaces [m]}}
\DoxyCodeLine{738 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: SchmittnerSocn}
\DoxyCodeLine{739 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: cellHeight  \textcolor{comment}{! Height of cell centers [m]}}
\DoxyCodeLine{740 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: tidal\_qe\_md \textcolor{comment}{! Tidal dissipation energy interpolated from 3d input}}
\DoxyCodeLine{741                                             \textcolor{comment}{! to model coordinates}}
\DoxyCodeLine{742 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: N2\_int\_i    \textcolor{comment}{! De-\/scaled interface buoyancy frequency [s-\/2]}}
\DoxyCodeLine{743 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: Schmittner\_coeff}
\DoxyCodeLine{744 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: h\_m         \textcolor{comment}{! Cell thickness [m]}}
\DoxyCodeLine{745 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: exp\_hab\_zetar}
\DoxyCodeLine{746 }
\DoxyCodeLine{747   \textcolor{keywordtype}{integer} :: i, k, is, ie}
\DoxyCodeLine{748 \textcolor{keywordtype}{  real} :: dh, hcorr, Simmons\_coeff}
\DoxyCodeLine{749 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: rho\_fw = 1000.0 \textcolor{comment}{! fresh water density [kg/m\string^3]}}
\DoxyCodeLine{750                                      \textcolor{comment}{! TODO: when coupled, get this from CESM (SHR\_CONST\_RHOFW)}}
\DoxyCodeLine{751   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()}
\DoxyCodeLine{752 }
\DoxyCodeLine{753   is  = g\%isc ; ie  = g\%iec}
\DoxyCodeLine{754   dd => cs\%dd}
\DoxyCodeLine{755 }
\DoxyCodeLine{756   \textcolor{keywordflow}{select case} (cs\%CVMix\_tidal\_scheme)}
\DoxyCodeLine{757   \textcolor{keywordflow}{case} (simmons)}
\DoxyCodeLine{758     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{759 }
\DoxyCodeLine{760       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)<1) cycle}
\DoxyCodeLine{761 }
\DoxyCodeLine{762       ifaceheight = 0.0 \textcolor{comment}{! BBL is all relative to the surface}}
\DoxyCodeLine{763       hcorr = 0.0}
\DoxyCodeLine{764       \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{765         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}}
\DoxyCodeLine{766         dh = h(i,j,k) * gv\%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment, rescaled to m for use by CVMix.}}
\DoxyCodeLine{767         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}}
\DoxyCodeLine{768         hcorr = min( dh -\/ cs\%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}}
\DoxyCodeLine{769         dh = max( dh, cs\%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}}
\DoxyCodeLine{770         cellheight(k)    = ifaceheight(k) -\/ 0.5 * dh}
\DoxyCodeLine{771         ifaceheight(k+1) = ifaceheight(k) -\/ dh}
\DoxyCodeLine{772 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{773 }
\DoxyCodeLine{774       \textcolor{keyword}{call }cvmix\_compute\_simmons\_invariant( nlev                    = g\%ke,                \&}
\DoxyCodeLine{775                                             energy\_flux             = cs\%tidal\_qe\_2d(i,j), \&}
\DoxyCodeLine{776                                             rho                     = rho\_fw,              \&}
\DoxyCodeLine{777                                             simmonscoeff            = simmons\_coeff,       \&}
\DoxyCodeLine{778                                             vertdep                 = vert\_dep,            \&}
\DoxyCodeLine{779                                             zw                      = ifaceheight,         \&}
\DoxyCodeLine{780                                             zt                      = cellheight,          \&}
\DoxyCodeLine{781                                             cvmix\_tidal\_params\_user = cs\%CVMix\_tidal\_params)}
\DoxyCodeLine{782 }
\DoxyCodeLine{783       \textcolor{comment}{! Since we pass tidal\_qe\_2d=(CS\%Gamma\_itides)*tidal\_energy\_flux\_2d, and not tidal\_energy\_flux\_2d in}}
\DoxyCodeLine{784       \textcolor{comment}{! above subroutine call, we divide Simmons\_coeff by CS\%Gamma\_itides as a corrective step:}}
\DoxyCodeLine{785       \textcolor{comment}{! TODO: (CS\%Gamma\_itides)*tidal\_energy\_flux\_2d is unnecessary, directly use tidal\_energy\_flux\_2d}}
\DoxyCodeLine{786       simmons\_coeff = simmons\_coeff / cs\%Gamma\_itides}
\DoxyCodeLine{787 }
\DoxyCodeLine{788 }
\DoxyCodeLine{789       \textcolor{comment}{! XXX: Temporary de-\/scaling of N2\_int(i,:) into a temporary variable}}
\DoxyCodeLine{790       \textcolor{keywordflow}{do} k=1,g\%ke+1}
\DoxyCodeLine{791         n2\_int\_i(k) = us\%s\_to\_T**2 * n2\_int(i,k)}
\DoxyCodeLine{792 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{793 }
\DoxyCodeLine{794       \textcolor{keyword}{call }cvmix\_coeffs\_tidal( mdiff\_out               = kv\_tidal,            \&}
\DoxyCodeLine{795                                tdiff\_out               = kd\_tidal,            \&}
\DoxyCodeLine{796                                nsqr                    = n2\_int\_i,            \&}
\DoxyCodeLine{797                                oceandepth              = -\/ifaceheight(g\%ke+1),\&}
\DoxyCodeLine{798                                simmonscoeff            = simmons\_coeff,       \&}
\DoxyCodeLine{799                                vert\_dep                = vert\_dep,            \&}
\DoxyCodeLine{800                                nlev                    = g\%ke,                \&}
\DoxyCodeLine{801                                max\_nlev                = g\%ke,                \&}
\DoxyCodeLine{802                                cvmix\_params            = cs\%CVMix\_glb\_params, \&}
\DoxyCodeLine{803                                cvmix\_tidal\_params\_user = cs\%CVMix\_tidal\_params)}
\DoxyCodeLine{804 }
\DoxyCodeLine{805       \textcolor{comment}{! Update diffusivity}}
\DoxyCodeLine{806       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{807         \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{808           kd\_lay(i,k) = kd\_lay(i,k) + 0.5 * us\%m2\_s\_to\_Z2\_T * (kd\_tidal(k) + kd\_tidal(k+1))}
\DoxyCodeLine{809 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{810 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{811       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{812         \textcolor{keywordflow}{do} k=1,g\%ke+1}
\DoxyCodeLine{813           kd\_int(i,k) = kd\_int(i,k) +  (us\%m2\_s\_to\_Z2\_T * kd\_tidal(k))}
\DoxyCodeLine{814 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{815 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{816       \textcolor{comment}{! Update viscosity with the proper unit conversion.}}
\DoxyCodeLine{817       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(kv)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{818         \textcolor{keywordflow}{do} k=1,g\%ke+1}
\DoxyCodeLine{819           kv(i,j,k) = kv(i,j,k) + us\%m2\_s\_to\_Z2\_T * kv\_tidal(k)  \textcolor{comment}{! Rescale from m2 s-\/1 to Z2 T-\/1.}}
\DoxyCodeLine{820 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{821 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{822 }
\DoxyCodeLine{823       \textcolor{comment}{! diagnostics}}
\DoxyCodeLine{824       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_itidal)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{825         dd\%Kd\_itidal(i,j,:) = us\%m2\_s\_to\_Z2\_T*kd\_tidal(:)}
\DoxyCodeLine{826 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{827       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{828         dd\%N2\_int(i,j,:) = n2\_int(i,:)}
\DoxyCodeLine{829 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{830       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Simmons\_coeff\_2d)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{831         dd\%Simmons\_coeff\_2d(i,j) = simmons\_coeff}
\DoxyCodeLine{832 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{833       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%vert\_dep\_3d)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{834         dd\%vert\_dep\_3d(i,j,:) = vert\_dep(:)}
\DoxyCodeLine{835 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{836 }
\DoxyCodeLine{837 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i=is,ie}}
\DoxyCodeLine{838 }
\DoxyCodeLine{839   \textcolor{keywordflow}{case} (schmittner)}
\DoxyCodeLine{840 }
\DoxyCodeLine{841     \textcolor{comment}{! TODO: correct exp\_hab\_zetar shapes in CVMix\_compute\_Schmittner\_invariant}}
\DoxyCodeLine{842     \textcolor{comment}{! and CVMix\_compute\_SchmittnerCoeff low subroutines}}
\DoxyCodeLine{843 }
\DoxyCodeLine{844     \textcolor{keyword}{allocate}(exp\_hab\_zetar(g\%ke+1,g\%ke+1))}
\DoxyCodeLine{845 }
\DoxyCodeLine{846     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{847 }
\DoxyCodeLine{848       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)<1) cycle}
\DoxyCodeLine{849 }
\DoxyCodeLine{850       ifaceheight = 0.0 \textcolor{comment}{! BBL is all relative to the surface}}
\DoxyCodeLine{851       hcorr = 0.0}
\DoxyCodeLine{852       \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{853         h\_m(k) = h(i,j,k)*gv\%H\_to\_m  \textcolor{comment}{! Rescale thicknesses to m for use by CVmix.}}
\DoxyCodeLine{854         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}}
\DoxyCodeLine{855         dh = h\_m(k) + hcorr \textcolor{comment}{! Nominal thickness less the accumulated error (could temporarily make dh<0)}}
\DoxyCodeLine{856         hcorr = min( dh -\/ cs\%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}}
\DoxyCodeLine{857         dh = max( dh, cs\%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}}
\DoxyCodeLine{858         cellheight(k)    = ifaceheight(k) -\/ 0.5 * dh}
\DoxyCodeLine{859         ifaceheight(k+1) = ifaceheight(k) -\/ dh}
\DoxyCodeLine{860 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{861 }
\DoxyCodeLine{862       schmittnersocn = 0.0 \textcolor{comment}{! TODO: compute this}}
\DoxyCodeLine{863 }
\DoxyCodeLine{864       \textcolor{comment}{! form the time-\/invariant part of Schmittner coefficient term}}
\DoxyCodeLine{865       \textcolor{keyword}{call }cvmix\_compute\_schmittner\_invariant(nlev                    = g\%ke,           \&}
\DoxyCodeLine{866                                               vertdep                 = vert\_dep,       \&}
\DoxyCodeLine{867                                               efficiency              = cs\%Mu\_itides,   \&}
\DoxyCodeLine{868                                               rho                     = rho\_fw,         \&}
\DoxyCodeLine{869                                               exp\_hab\_zetar           = exp\_hab\_zetar,  \&}
\DoxyCodeLine{870                                               zw                      = ifaceheight,    \&}
\DoxyCodeLine{871                                               cvmix\_tidal\_params\_user = cs\%CVMix\_tidal\_params)}
\DoxyCodeLine{872                   \textcolor{comment}{!TODO: in above call, there is no need to pass efficiency, since it gets}}
\DoxyCodeLine{873                   \textcolor{comment}{! passed via CVMix\_init\_tidal and stored in CVMix\_tidal\_params. Change}}
\DoxyCodeLine{874                   \textcolor{comment}{! CVMix API to prevent this redundancy.}}
\DoxyCodeLine{875 }
\DoxyCodeLine{876       \textcolor{comment}{! remap from input z coordinate to model coordinate:}}
\DoxyCodeLine{877       tidal\_qe\_md = 0.0}
\DoxyCodeLine{878       \textcolor{keyword}{call }remapping\_core\_h(cs\%remap\_cs, \textcolor{keyword}{size}(cs\%h\_src), cs\%h\_src, cs\%tidal\_qe\_3d\_in(i,j,:), \&}
\DoxyCodeLine{879                             g\%ke, h\_m, tidal\_qe\_md)}
\DoxyCodeLine{880 }
\DoxyCodeLine{881       \textcolor{comment}{! form the Schmittner coefficient that is based on 3D q*E, which is formed from}}
\DoxyCodeLine{882       \textcolor{comment}{! summing q\_i*TidalConstituent\_i over the number of constituents.}}
\DoxyCodeLine{883       \textcolor{keyword}{call }cvmix\_compute\_schmittnercoeff( nlev                    = g\%ke,               \&}
\DoxyCodeLine{884                                           energy\_flux             = tidal\_qe\_md(:),     \&}
\DoxyCodeLine{885                                           rho                     = rho\_fw,             \&}
\DoxyCodeLine{886                                           schmittnercoeff         = schmittner\_coeff,   \&}
\DoxyCodeLine{887                                           exp\_hab\_zetar           = exp\_hab\_zetar,      \&}
\DoxyCodeLine{888                                           cvmix\_tidal\_params\_user = cs\%CVMix\_tidal\_params)}
\DoxyCodeLine{889 }
\DoxyCodeLine{890       \textcolor{comment}{! XXX: Temporary de-\/scaling of N2\_int(i,:) into a temporary variable}}
\DoxyCodeLine{891       \textcolor{keywordflow}{do} k=1,g\%ke+1}
\DoxyCodeLine{892         n2\_int\_i(k) = us\%s\_to\_T**2 * n2\_int(i,k)}
\DoxyCodeLine{893 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{894 }
\DoxyCodeLine{895       \textcolor{keyword}{call }cvmix\_coeffs\_tidal\_schmittner( mdiff\_out               = kv\_tidal,             \&}
\DoxyCodeLine{896                                           tdiff\_out               = kd\_tidal,             \&}
\DoxyCodeLine{897                                           nsqr                    = n2\_int\_i,             \&}
\DoxyCodeLine{898                                           oceandepth              = -\/ifaceheight(g\%ke+1), \&}
\DoxyCodeLine{899                                           vert\_dep                = vert\_dep,             \&}
\DoxyCodeLine{900                                           nlev                    = g\%ke,                 \&}
\DoxyCodeLine{901                                           max\_nlev                = g\%ke,                 \&}
\DoxyCodeLine{902                                           schmittnercoeff         = schmittner\_coeff,     \&}
\DoxyCodeLine{903                                           schmittnersouthernocean = schmittnersocn,       \&}
\DoxyCodeLine{904                                           cvmix\_params            = cs\%CVMix\_glb\_params,  \&}
\DoxyCodeLine{905                                           cvmix\_tidal\_params\_user = cs\%CVMix\_tidal\_params)}
\DoxyCodeLine{906 }
\DoxyCodeLine{907       \textcolor{comment}{! Update diffusivity}}
\DoxyCodeLine{908       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{909         \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{910           kd\_lay(i,k) = kd\_lay(i,k) + 0.5 * us\%m2\_s\_to\_Z2\_T * (kd\_tidal(k) + kd\_tidal(k+1))}
\DoxyCodeLine{911 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{912 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{913       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{914         \textcolor{keywordflow}{do} k=1,g\%ke+1}
\DoxyCodeLine{915           kd\_int(i,k) = kd\_int(i,k) +  (us\%m2\_s\_to\_Z2\_T * kd\_tidal(k))}
\DoxyCodeLine{916 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{917 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{918 }
\DoxyCodeLine{919       \textcolor{comment}{! Update viscosity}}
\DoxyCodeLine{920       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(kv)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{921         \textcolor{keywordflow}{do} k=1,g\%ke+1}
\DoxyCodeLine{922           kv(i,j,k) = kv(i,j,k) + us\%m2\_s\_to\_Z2\_T * kv\_tidal(k)   \textcolor{comment}{! Rescale from m2 s-\/1 to Z2 T-\/1.}}
\DoxyCodeLine{923 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{924 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{925 }
\DoxyCodeLine{926       \textcolor{comment}{! diagnostics}}
\DoxyCodeLine{927       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_itidal)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{928         dd\%Kd\_itidal(i,j,:) = us\%m2\_s\_to\_Z2\_T*kd\_tidal(:)}
\DoxyCodeLine{929 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{930       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{931         dd\%N2\_int(i,j,:) = n2\_int(i,:)}
\DoxyCodeLine{932 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{933       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Schmittner\_coeff\_3d)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{934         dd\%Schmittner\_coeff\_3d(i,j,:) = schmittner\_coeff(:)}
\DoxyCodeLine{935 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{936       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%tidal\_qe\_md)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{937         dd\%tidal\_qe\_md(i,j,:) = tidal\_qe\_md(:)}
\DoxyCodeLine{938 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{939       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%vert\_dep\_3d)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{940         dd\%vert\_dep\_3d(i,j,:) = vert\_dep(:)}
\DoxyCodeLine{941 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{942 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i=is,ie}}
\DoxyCodeLine{943 }
\DoxyCodeLine{944     \textcolor{keyword}{deallocate}(exp\_hab\_zetar)}
\DoxyCodeLine{945 }
\DoxyCodeLine{946 \textcolor{keywordflow}{  case default}}
\DoxyCodeLine{947      \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Unrecognized setting "{}}// \&}
\DoxyCodeLine{948          \textcolor{stringliteral}{"{}\#define CVMIX\_TIDAL\_SCHEME found in input file."{}})}
\DoxyCodeLine{949 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{950 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_abf084268fd9c71f20880838d2bce7e3e}\label{namespacemom__tidal__mixing_abf084268fd9c71f20880838d2bce7e3e}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!calculate\_tidal\_mixing@{calculate\_tidal\_mixing}}
\index{calculate\_tidal\_mixing@{calculate\_tidal\_mixing}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{calculate\_tidal\_mixing()}{calculate\_tidal\_mixing()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::calculate\+\_\+tidal\+\_\+mixing (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{N2\+\_\+bot,  }\item[{integer, intent(in)}]{j,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{T\+K\+E\+\_\+to\+\_\+\+Kd,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{max\+\_\+\+T\+KE,  }\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__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{N2\+\_\+lay,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{N2\+\_\+int,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, intent(in)}]{Kd\+\_\+max,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{Kv }\end{DoxyParamCaption})}



Depending on whether or not C\+V\+Mix is active, calls the associated subroutine to compute internal tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the layer or interface diffusivities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s 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 h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+bot} & The near-\/bottom squared buoyancy frequency \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+lay} & The squared buoyancy frequency of the layers \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+int} & The squared buoyancy frequency at the interfaces \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em j} & The j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em tke\+\_\+to\+\_\+kd} & The conversion rate between the T\+KE dissipated within a layer and the diapycnal diffusivity within that layer, usually ($\sim$\+Rho\+\_\+0 / (G\+\_\+\+Earth $\ast$ d\+Rho\+\_\+lay)) \mbox{[}Z2 T-\/1 / Z3 T-\/3 = T2 Z-\/1 $\sim$$>$ s2 m-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+tke} & The energy required to for a layer to entrain to its maximum realizable thickness \mbox{[}Z3 T-\/3 $\sim$$>$ m3 s-\/3\mbox{]} \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+lay} & The diapycnal diffusivity in layers \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+int} & The diapycnal diffusivity at interfaces, \\
\hline
\mbox{\texttt{ in}}  & {\em kd\+\_\+max} & The maximum increment for diapycnal diffusivity due to T\+K\+E-\/based processes, \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. Set this to a negative value to have no limit. \\
\hline
 & {\em kv} & The \char`\"{}slow\char`\"{} vertical viscosity at each interface (not layer!) \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 670 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{672   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< The ocean's grid structure}}
\DoxyCodeLine{673   \textcolor{keywordtype}{type}(verticalGrid\_type),          \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< The ocean's vertical grid structure}}
\DoxyCodeLine{674   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{675 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{676                                     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{677 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(in)}    :: N2\_bot\textcolor{comment}{ !< The near-\/bottom squared buoyancy}}
\DoxyCodeLine{678 \textcolor{comment}{                                                            !! frequency [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{679 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: N2\_lay\textcolor{comment}{ !< The squared buoyancy frequency of the}}
\DoxyCodeLine{680 \textcolor{comment}{                                                            !! layers [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{681 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}  :: N2\_int\textcolor{comment}{ !< The squared buoyancy frequency at the}}
\DoxyCodeLine{682 \textcolor{comment}{                                                            !! interfaces [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{683   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{      !< The j-\/index to work on}}
\DoxyCodeLine{684 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: TKE\_to\_Kd\textcolor{comment}{ !< The conversion rate between the TKE}}
\DoxyCodeLine{685 \textcolor{comment}{                                                            !! dissipated within a layer and the}}
\DoxyCodeLine{686 \textcolor{comment}{                                                            !! diapycnal diffusivity within that layer,}}
\DoxyCodeLine{687 \textcolor{comment}{                                                            !! usually (\string~Rho\_0 / (G\_Earth * dRho\_lay))}}
\DoxyCodeLine{688 \textcolor{comment}{                                                            !! [Z2 T-\/1 / Z3 T-\/3 = T2 Z-\/1 \string~> s2 m-\/1]}}
\DoxyCodeLine{689 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: max\_TKE\textcolor{comment}{ !< The energy required to for a layer to entrain}}
\DoxyCodeLine{690 \textcolor{comment}{                                                            !! to its maximum realizable thickness [Z3 T-\/3 \string~> m3 s-\/3]}}
\DoxyCodeLine{691   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< The control structure for this module}}
\DoxyCodeLine{692 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{693                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{ !< The diapycnal diffusivity in layers [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{694 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{695                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{ !< The diapycnal diffusivity at interfaces,}}
\DoxyCodeLine{696 \textcolor{comment}{                                                            !! [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{697 \textcolor{keywordtype}{  real},                             \textcolor{keywordtype}{intent(in)}    :: Kd\_max\textcolor{comment}{ !< The maximum increment for diapycnal}}
\DoxyCodeLine{698 \textcolor{comment}{                                                            !! diffusivity due to TKE-\/based processes,}}
\DoxyCodeLine{699 \textcolor{comment}{                                                            !! [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{700 \textcolor{comment}{                                                            !! Set this to a negative value to have no limit.}}
\DoxyCodeLine{701 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},           \textcolor{keywordtype}{pointer}       :: Kv\textcolor{comment}{     !< The "{}slow"{} vertical viscosity at each interface}}
\DoxyCodeLine{702 \textcolor{comment}{                                                            !! (not layer!) [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{703 }
\DoxyCodeLine{704   \textcolor{keywordflow}{if} (cs\%Int\_tide\_dissipation .or. cs\%Lee\_wave\_dissipation .or. cs\%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{705     \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{706       \textcolor{keyword}{call }calculate\_cvmix\_tidal(h, j, g, gv, us, cs, n2\_int, kd\_lay, kd\_int, kv)}
\DoxyCodeLine{707     \textcolor{keywordflow}{else}}
\DoxyCodeLine{708       \textcolor{keyword}{call }add\_int\_tide\_diffusivity(h, n2\_bot, j, tke\_to\_kd, max\_tke, \&}
\DoxyCodeLine{709                                     g, gv, us, cs, n2\_lay, kd\_lay, kd\_int, kd\_max)}
\DoxyCodeLine{710 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{711 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_af6fabb2bc6e4aabd3187938bda8098ec}\label{namespacemom__tidal__mixing_af6fabb2bc6e4aabd3187938bda8098ec}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!post\_tidal\_diagnostics@{post\_tidal\_diagnostics}}
\index{post\_tidal\_diagnostics@{post\_tidal\_diagnostics}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{post\_tidal\_diagnostics()}{post\_tidal\_diagnostics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::post\+\_\+tidal\+\_\+diagnostics (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine offers up diagnostics of the tidal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1497 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1498   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}   :: G\textcolor{comment}{   !< The ocean's grid structure}}
\DoxyCodeLine{1499   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(in)}   :: GV\textcolor{comment}{  !< The ocean's vertical grid structure.}}
\DoxyCodeLine{1500 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{1501                             \textcolor{keywordtype}{intent(in)}   :: h\textcolor{comment}{   !< Layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{1502   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),    \textcolor{keywordtype}{pointer}      :: CS\textcolor{comment}{  !< The control structure for this module}}
\DoxyCodeLine{1503 }
\DoxyCodeLine{1504   \textcolor{comment}{! local}}
\DoxyCodeLine{1505   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()}
\DoxyCodeLine{1506 }
\DoxyCodeLine{1507   dd => cs\%dd}
\DoxyCodeLine{1508 }
\DoxyCodeLine{1509   \textcolor{keywordflow}{if} (cs\%Int\_tide\_dissipation .or. cs\%Lee\_wave\_dissipation .or. cs\%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1510     \textcolor{keywordflow}{if} (cs\%id\_TKE\_itidal  > 0) \textcolor{keyword}{call }post\_data(cs\%id\_TKE\_itidal,  dd\%TKE\_itidal\_used, cs\%diag)}
\DoxyCodeLine{1511     \textcolor{keywordflow}{if} (cs\%id\_TKE\_leewave > 0) \textcolor{keyword}{call }post\_data(cs\%id\_TKE\_leewave, cs\%TKE\_Niku,        cs\%diag)}
\DoxyCodeLine{1512     \textcolor{keywordflow}{if} (cs\%id\_Nb          > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Nb,      cs\%Nb,      cs\%diag)}
\DoxyCodeLine{1513     \textcolor{keywordflow}{if} (cs\%id\_N2\_bot      > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N2\_bot,  dd\%N2\_bot,  cs\%diag)}
\DoxyCodeLine{1514     \textcolor{keywordflow}{if} (cs\%id\_N2\_meanz    > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N2\_meanz,dd\%N2\_meanz,cs\%diag)}
\DoxyCodeLine{1515 }
\DoxyCodeLine{1516     \textcolor{keywordflow}{if} (cs\%id\_Fl\_itidal > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Fl\_itidal, dd\%Fl\_itidal, cs\%diag)}
\DoxyCodeLine{1517     \textcolor{keywordflow}{if} (cs\%id\_Kd\_itidal > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_itidal, dd\%Kd\_itidal, cs\%diag)}
\DoxyCodeLine{1518     \textcolor{keywordflow}{if} (cs\%id\_Kd\_Niku   > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_Niku,   dd\%Kd\_Niku,   cs\%diag)}
\DoxyCodeLine{1519     \textcolor{keywordflow}{if} (cs\%id\_Kd\_lowmode> 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_lowmode, dd\%Kd\_lowmode, cs\%diag)}
\DoxyCodeLine{1520     \textcolor{keywordflow}{if} (cs\%id\_Fl\_lowmode> 0) \textcolor{keyword}{call }post\_data(cs\%id\_Fl\_lowmode, dd\%Fl\_lowmode, cs\%diag)}
\DoxyCodeLine{1521 }
\DoxyCodeLine{1522     \textcolor{keywordflow}{if} (cs\%id\_N2\_int> 0)        \textcolor{keyword}{call }post\_data(cs\%id\_N2\_int, dd\%N2\_int, cs\%diag)}
\DoxyCodeLine{1523     \textcolor{keywordflow}{if} (cs\%id\_vert\_dep> 0)      \textcolor{keyword}{call }post\_data(cs\%id\_vert\_dep, dd\%vert\_dep\_3d, cs\%diag)}
\DoxyCodeLine{1524     \textcolor{keywordflow}{if} (cs\%id\_Simmons\_coeff> 0) \textcolor{keyword}{call }post\_data(cs\%id\_Simmons\_coeff, dd\%Simmons\_coeff\_2d, cs\%diag)}
\DoxyCodeLine{1525     \textcolor{keywordflow}{if} (cs\%id\_Schmittner\_coeff> 0) \textcolor{keyword}{call }post\_data(cs\%id\_Schmittner\_coeff, dd\%Schmittner\_coeff\_3d, cs\%diag)}
\DoxyCodeLine{1526     \textcolor{keywordflow}{if} (cs\%id\_tidal\_qe\_md> 0) \textcolor{keyword}{call }post\_data(cs\%id\_tidal\_qe\_md, dd\%tidal\_qe\_md, cs\%diag)}
\DoxyCodeLine{1527 }
\DoxyCodeLine{1528     \textcolor{keywordflow}{if} (cs\%id\_Kd\_Itidal\_Work > 0) \&}
\DoxyCodeLine{1529       \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_Itidal\_Work, dd\%Kd\_Itidal\_Work, cs\%diag)}
\DoxyCodeLine{1530     \textcolor{keywordflow}{if} (cs\%id\_Kd\_Niku\_Work > 0) \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_Niku\_Work, dd\%Kd\_Niku\_Work, cs\%diag)}
\DoxyCodeLine{1531     \textcolor{keywordflow}{if} (cs\%id\_Kd\_Lowmode\_Work > 0) \&}
\DoxyCodeLine{1532       \textcolor{keyword}{call }post\_data(cs\%id\_Kd\_Lowmode\_Work, dd\%Kd\_Lowmode\_Work, cs\%diag)}
\DoxyCodeLine{1533 }
\DoxyCodeLine{1534     \textcolor{keywordflow}{if} (cs\%id\_Polzin\_decay\_scale > 0 ) \&}
\DoxyCodeLine{1535       \textcolor{keyword}{call }post\_data(cs\%id\_Polzin\_decay\_scale, dd\%Polzin\_decay\_scale, cs\%diag)}
\DoxyCodeLine{1536     \textcolor{keywordflow}{if} (cs\%id\_Polzin\_decay\_scale\_scaled > 0 ) \&}
\DoxyCodeLine{1537       \textcolor{keyword}{call }post\_data(cs\%id\_Polzin\_decay\_scale\_scaled, dd\%Polzin\_decay\_scale\_scaled, cs\%diag)}
\DoxyCodeLine{1538 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1539 }
\DoxyCodeLine{1540   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_itidal)) \textcolor{keyword}{deallocate}(dd\%Kd\_itidal)}
\DoxyCodeLine{1541   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_lowmode)) \textcolor{keyword}{deallocate}(dd\%Kd\_lowmode)}
\DoxyCodeLine{1542   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_itidal)) \textcolor{keyword}{deallocate}(dd\%Fl\_itidal)}
\DoxyCodeLine{1543   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Fl\_lowmode)) \textcolor{keyword}{deallocate}(dd\%Fl\_lowmode)}
\DoxyCodeLine{1544   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Polzin\_decay\_scale)) \textcolor{keyword}{deallocate}(dd\%Polzin\_decay\_scale)}
\DoxyCodeLine{1545   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Polzin\_decay\_scale\_scaled)) \textcolor{keyword}{deallocate}(dd\%Polzin\_decay\_scale\_scaled)}
\DoxyCodeLine{1546   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_bot)) \textcolor{keyword}{deallocate}(dd\%N2\_bot)}
\DoxyCodeLine{1547   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_meanz)) \textcolor{keyword}{deallocate}(dd\%N2\_meanz)}
\DoxyCodeLine{1548   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Niku)) \textcolor{keyword}{deallocate}(dd\%Kd\_Niku)}
\DoxyCodeLine{1549   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Niku\_work)) \textcolor{keyword}{deallocate}(dd\%Kd\_Niku\_work)}
\DoxyCodeLine{1550   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Itidal\_Work))  \textcolor{keyword}{deallocate}(dd\%Kd\_Itidal\_Work)}
\DoxyCodeLine{1551   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Kd\_Lowmode\_Work)) \textcolor{keyword}{deallocate}(dd\%Kd\_Lowmode\_Work)}
\DoxyCodeLine{1552   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%TKE\_itidal\_used)) \textcolor{keyword}{deallocate}(dd\%TKE\_itidal\_used)}
\DoxyCodeLine{1553   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%N2\_int)) \textcolor{keyword}{deallocate}(dd\%N2\_int)}
\DoxyCodeLine{1554   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%vert\_dep\_3d)) \textcolor{keyword}{deallocate}(dd\%vert\_dep\_3d)}
\DoxyCodeLine{1555   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Simmons\_coeff\_2d)) \textcolor{keyword}{deallocate}(dd\%Simmons\_coeff\_2d)}
\DoxyCodeLine{1556   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%Schmittner\_coeff\_3d)) \textcolor{keyword}{deallocate}(dd\%Schmittner\_coeff\_3d)}
\DoxyCodeLine{1557   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd\%tidal\_qe\_md)) \textcolor{keyword}{deallocate}(dd\%tidal\_qe\_md)}
\DoxyCodeLine{1558 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a30a24b88982a5134253679d9484b3708}\label{namespacemom__tidal__mixing_a30a24b88982a5134253679d9484b3708}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!read\_tidal\_constituents@{read\_tidal\_constituents}}
\index{read\_tidal\_constituents@{read\_tidal\_constituents}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{read\_tidal\_constituents()}{read\_tidal\_constituents()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::read\+\_\+tidal\+\_\+constituents (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{character(len=200), intent(in)}]{tidal\+\_\+energy\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine reads tidal input energy from a file by constituent. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em tidal\+\_\+energy\+\_\+file} & The file from which to read tidal energy inputs \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1611 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1612   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1613   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1614   \textcolor{keywordtype}{character(len=200)},    \textcolor{keywordtype}{intent(in)} :: tidal\_energy\_file\textcolor{comment}{ !< The file from which to read tidal energy inputs}}
\DoxyCodeLine{1615   \textcolor{keywordtype}{type}(tidal\_mixing\_cs), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< The control structure for this module}}
\DoxyCodeLine{1616 }
\DoxyCodeLine{1617   \textcolor{comment}{! local variables}}
\DoxyCodeLine{1618 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_3 = 1.0/3.0}
\DoxyCodeLine{1619 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{1620     tidal\_qk1, \&  \textcolor{comment}{! qk1 coefficient used in Schmittner \& Egbert}}
\DoxyCodeLine{1621     tidal\_qo1     \textcolor{comment}{! qo1 coefficient used in Schmittner \& Egbert}}
\DoxyCodeLine{1622 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: \&}
\DoxyCodeLine{1623     z\_t, \&        \textcolor{comment}{! depth from surface to midpoint of input layer [Z]}}
\DoxyCodeLine{1624     z\_w           \textcolor{comment}{! depth from surface to top of input layer [Z]}}
\DoxyCodeLine{1625 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: \&}
\DoxyCodeLine{1626     tc\_m2, \&      \textcolor{comment}{! input lunar semidiurnal tidal energy flux [W/m\string^2]}}
\DoxyCodeLine{1627     tc\_s2, \&      \textcolor{comment}{! input solar semidiurnal tidal energy flux [W/m\string^2]}}
\DoxyCodeLine{1628     tc\_k1, \&      \textcolor{comment}{! input lunar diurnal tidal energy flux [W/m\string^2]}}
\DoxyCodeLine{1629     tc\_o1         \textcolor{comment}{! input lunar diurnal tidal energy flux [W/m\string^2]}}
\DoxyCodeLine{1630   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: nz\_in}
\DoxyCodeLine{1631   \textcolor{keywordtype}{integer}               :: k, is, ie, js, je, isd, ied, jsd, jed, i, j}
\DoxyCodeLine{1632 }
\DoxyCodeLine{1633   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{1634   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{1635 }
\DoxyCodeLine{1636   \textcolor{comment}{! get number of input levels:}}
\DoxyCodeLine{1637   \textcolor{keyword}{call }field\_size(tidal\_energy\_file, \textcolor{stringliteral}{'z\_t'}, nz\_in)}
\DoxyCodeLine{1638 }
\DoxyCodeLine{1639   \textcolor{comment}{! allocate local variables}}
\DoxyCodeLine{1640   \textcolor{keyword}{allocate}(z\_t(nz\_in(1)), z\_w(nz\_in(1)) )}
\DoxyCodeLine{1641   \textcolor{keyword}{allocate}(tc\_m2(isd:ied,jsd:jed,nz\_in(1)), \&}
\DoxyCodeLine{1642            tc\_s2(isd:ied,jsd:jed,nz\_in(1)), \&}
\DoxyCodeLine{1643            tc\_k1(isd:ied,jsd:jed,nz\_in(1)), \&}
\DoxyCodeLine{1644            tc\_o1(isd:ied,jsd:jed,nz\_in(1)) )}
\DoxyCodeLine{1645 }
\DoxyCodeLine{1646   \textcolor{comment}{! allocate CS variables associated with 3d tidal energy dissipation}}
\DoxyCodeLine{1647   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(cs\%tidal\_qe\_3d\_in)) \textcolor{keyword}{allocate}(cs\%tidal\_qe\_3d\_in(isd:ied,jsd:jed,nz\_in(1)))}
\DoxyCodeLine{1648   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(cs\%h\_src))          \textcolor{keyword}{allocate}(cs\%h\_src(nz\_in(1)))}
\DoxyCodeLine{1649 }
\DoxyCodeLine{1650   \textcolor{comment}{! read in tidal constituents}}
\DoxyCodeLine{1651   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'M2'}, tc\_m2, g\%domain)}
\DoxyCodeLine{1652   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'S2'}, tc\_s2, g\%domain)}
\DoxyCodeLine{1653   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'K1'}, tc\_k1, g\%domain)}
\DoxyCodeLine{1654   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'O1'}, tc\_o1, g\%domain)}
\DoxyCodeLine{1655   \textcolor{comment}{! Note the hard-\/coded assumption that z\_t and z\_w in the file are in centimeters.}}
\DoxyCodeLine{1656   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'z\_t'}, z\_t, scale=100.0*us\%m\_to\_Z)}
\DoxyCodeLine{1657   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'z\_w'}, z\_w, scale=100.0*us\%m\_to\_Z)}
\DoxyCodeLine{1658 }
\DoxyCodeLine{1659   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1660     \textcolor{keywordflow}{if} (abs(g\%geoLatT(i,j)) < 30.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1661       tidal\_qk1(i,j) = c1\_3}
\DoxyCodeLine{1662       tidal\_qo1(i,j) = c1\_3}
\DoxyCodeLine{1663     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1664       tidal\_qk1(i,j) = 1.0}
\DoxyCodeLine{1665       tidal\_qo1(i,j) = 1.0}
\DoxyCodeLine{1666 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1667 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1668 }
\DoxyCodeLine{1669   cs\%tidal\_qe\_3d\_in(:,:,:) = 0.0}
\DoxyCodeLine{1670   \textcolor{keywordflow}{do} k=1,nz\_in(1)}
\DoxyCodeLine{1671     \textcolor{comment}{! Store the input cell thickness in m for use with CVmix.}}
\DoxyCodeLine{1672     cs\%h\_src(k) = us\%Z\_to\_m*(z\_t(k)-\/z\_w(k))*2.0}
\DoxyCodeLine{1673     \textcolor{comment}{! form tidal\_qe\_3d\_in from weighted tidal constituents}}
\DoxyCodeLine{1674     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1675       \textcolor{keywordflow}{if} ((z\_t(k) <= g\%bathyT(i,j)) .and. (z\_w(k) > cs\%tidal\_diss\_lim\_tc)) \&}
\DoxyCodeLine{1676         cs\%tidal\_qe\_3d\_in(i,j,k) = c1\_3*tc\_m2(i,j,k) + c1\_3*tc\_s2(i,j,k) + \&}
\DoxyCodeLine{1677                 tidal\_qk1(i,j)*tc\_k1(i,j,k) + tidal\_qo1(i,j)*tc\_o1(i,j,k)}
\DoxyCodeLine{1678 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1679 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1680 }
\DoxyCodeLine{1681   \textcolor{comment}{!open(unit=1905,file="{}out\_1905.txt"{},access="{}APPEND"{})}}
\DoxyCodeLine{1682   \textcolor{comment}{!do j=G\%jsd,G\%jed}}
\DoxyCodeLine{1683   \textcolor{comment}{!  do i=isd,ied}}
\DoxyCodeLine{1684   \textcolor{comment}{!    if ( i+G\%idg\_offset .eq. 90 .and. j+G\%jdg\_offset .eq. 126) then}}
\DoxyCodeLine{1685   \textcolor{comment}{!      write(1905,*) "{}-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/"{}}}
\DoxyCodeLine{1686   \textcolor{comment}{!      do k=50,nz\_in(1)}}
\DoxyCodeLine{1687   \textcolor{comment}{!          write(1905,*) i,j,k}}
\DoxyCodeLine{1688   \textcolor{comment}{!          write(1905,*) CS\%tidal\_qe\_3d\_in(i,j,k), tc\_m2(i,j,k)}}
\DoxyCodeLine{1689   \textcolor{comment}{!          write(1905,*) z\_t(k), G\%bathyT(i,j), z\_w(k),CS\%tidal\_diss\_lim\_tc}}
\DoxyCodeLine{1690   \textcolor{comment}{!      end do}}
\DoxyCodeLine{1691   \textcolor{comment}{!    endif}}
\DoxyCodeLine{1692   \textcolor{comment}{!  enddo}}
\DoxyCodeLine{1693   \textcolor{comment}{!enddo}}
\DoxyCodeLine{1694   \textcolor{comment}{!close(1905)}}
\DoxyCodeLine{1695 }
\DoxyCodeLine{1696   \textcolor{comment}{! test if qE is positive}}
\DoxyCodeLine{1697   \textcolor{keywordflow}{if} (any(cs\%tidal\_qe\_3d\_in<0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1698     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}read\_tidal\_constituents: Negative tidal\_qe\_3d\_in terms."{}})}
\DoxyCodeLine{1699 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1700 }
\DoxyCodeLine{1701   \textcolor{comment}{!! collapse 3D q*E to 2D q*E}}
\DoxyCodeLine{1702   \textcolor{comment}{!CS\%tidal\_qe\_2d(:,:) = 0.0}}
\DoxyCodeLine{1703   \textcolor{comment}{!do k=1,nz\_in(1) ; do j=js,je ; do i=is,ie}}
\DoxyCodeLine{1704   \textcolor{comment}{!  if (z\_t(k) <= G\%bathyT(i,j)) \&}}
\DoxyCodeLine{1705   \textcolor{comment}{!    CS\%tidal\_qe\_2d(i,j) = CS\%tidal\_qe\_2d(i,j) + CS\%tidal\_qe\_3d\_in(i,j,k)}}
\DoxyCodeLine{1706   \textcolor{comment}{!enddo ; enddo ; enddo}}
\DoxyCodeLine{1707 }
\DoxyCodeLine{1708   \textcolor{comment}{! initialize input remapping:}}
\DoxyCodeLine{1709   \textcolor{keyword}{call }initialize\_remapping(cs\%remap\_cs, remapping\_scheme=\textcolor{stringliteral}{"{}PLM"{}}, \&}
\DoxyCodeLine{1710                             boundary\_extrapolation=.false., check\_remapping=cs\%debug, \&}
\DoxyCodeLine{1711                             answers\_2018=cs\%remap\_answers\_2018)}
\DoxyCodeLine{1712 }
\DoxyCodeLine{1713   \textcolor{keyword}{deallocate}(tc\_m2)}
\DoxyCodeLine{1714   \textcolor{keyword}{deallocate}(tc\_s2)}
\DoxyCodeLine{1715   \textcolor{keyword}{deallocate}(tc\_k1)}
\DoxyCodeLine{1716   \textcolor{keyword}{deallocate}(tc\_o1)}
\DoxyCodeLine{1717   \textcolor{keyword}{deallocate}(z\_t)}
\DoxyCodeLine{1718   \textcolor{keyword}{deallocate}(z\_w)}
\DoxyCodeLine{1719 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_adfd3a137ee6402fdcdfb7c46711e0e23}\label{namespacemom__tidal__mixing_adfd3a137ee6402fdcdfb7c46711e0e23}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!read\_tidal\_energy@{read\_tidal\_energy}}
\index{read\_tidal\_energy@{read\_tidal\_energy}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{read\_tidal\_energy()}{read\_tidal\_energy()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::read\+\_\+tidal\+\_\+energy (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{character(len=20), intent(in)}]{tidal\+\_\+energy\+\_\+type,  }\item[{character(len=200), intent(in)}]{tidal\+\_\+energy\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine read tidal energy inputs from a file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em tidal\+\_\+energy\+\_\+type} & The type of tidal energy inputs to read \\
\hline
\mbox{\texttt{ in}}  & {\em tidal\+\_\+energy\+\_\+file} & The file from which to read tidalinputs \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1581 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1582   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1583   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1584   \textcolor{keywordtype}{character(len=20)},       \textcolor{keywordtype}{intent(in)} :: tidal\_energy\_type\textcolor{comment}{ !< The type of tidal energy inputs to read}}
\DoxyCodeLine{1585   \textcolor{keywordtype}{character(len=200)},      \textcolor{keywordtype}{intent(in)} :: tidal\_energy\_file\textcolor{comment}{ !< The file from which to read tidalinputs}}
\DoxyCodeLine{1586   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< The control structure for this module}}
\DoxyCodeLine{1587   \textcolor{comment}{! local}}
\DoxyCodeLine{1588   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, nz}
\DoxyCodeLine{1589 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: tidal\_energy\_flux\_2d \textcolor{comment}{! input tidal energy flux at T-\/grid points [W m-\/2]}}
\DoxyCodeLine{1590 }
\DoxyCodeLine{1591   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed ; nz = g\%ke}
\DoxyCodeLine{1592 }
\DoxyCodeLine{1593   \textcolor{keywordflow}{select case} (uppercase(tidal\_energy\_type(1:4)))}
\DoxyCodeLine{1594   \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'JAYN'}) \textcolor{comment}{! Jayne 2009}}
\DoxyCodeLine{1595     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(cs\%tidal\_qe\_2d)) \textcolor{keyword}{allocate}(cs\%tidal\_qe\_2d(isd:ied,jsd:jed))}
\DoxyCodeLine{1596     \textcolor{keyword}{allocate}(tidal\_energy\_flux\_2d(isd:ied,jsd:jed))}
\DoxyCodeLine{1597     \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file,\textcolor{stringliteral}{'wave\_dissipation'},tidal\_energy\_flux\_2d, g\%domain)}
\DoxyCodeLine{1598     \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{1599       cs\%tidal\_qe\_2d(i,j) = cs\%Gamma\_itides * tidal\_energy\_flux\_2d(i,j)}
\DoxyCodeLine{1600 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1601     \textcolor{keyword}{deallocate}(tidal\_energy\_flux\_2d)}
\DoxyCodeLine{1602   \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'ER03'}) \textcolor{comment}{! Egbert \& Ray 2003}}
\DoxyCodeLine{1603     \textcolor{keyword}{call }read\_tidal\_constituents(g, us, tidal\_energy\_file, cs)}
\DoxyCodeLine{1604 \textcolor{keywordflow}{  case default}}
\DoxyCodeLine{1605     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}read\_tidal\_energy: Unknown tidal energy file type."{}})}
\DoxyCodeLine{1606 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{1607 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a7d2dfb64df35957d1252ce841c0cdf43}\label{namespacemom__tidal__mixing_a7d2dfb64df35957d1252ce841c0cdf43}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!setup\_tidal\_diagnostics@{setup\_tidal\_diagnostics}}
\index{setup\_tidal\_diagnostics@{setup\_tidal\_diagnostics}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{setup\_tidal\_diagnostics()}{setup\_tidal\_diagnostics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::setup\+\_\+tidal\+\_\+diagnostics (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Sets up diagnostics arrays for tidal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1412 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1413   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< The ocean's grid structure}}
\DoxyCodeLine{1414   \textcolor{keywordtype}{type}(tidal\_mixing\_cs), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure for this module}}
\DoxyCodeLine{1415 }
\DoxyCodeLine{1416   \textcolor{comment}{! local}}
\DoxyCodeLine{1417   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, nz}
\DoxyCodeLine{1418   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()}
\DoxyCodeLine{1419 }
\DoxyCodeLine{1420   isd = g\%isd; ied = g\%ied; jsd = g\%jsd; jed = g\%jed; nz = g\%ke}
\DoxyCodeLine{1421   dd => cs\%dd}
\DoxyCodeLine{1422 }
\DoxyCodeLine{1423   \textcolor{keywordflow}{if} ((cs\%id\_Kd\_itidal > 0) .or. (cs\%id\_Kd\_Itidal\_work > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1424     \textcolor{keyword}{allocate}(dd\%Kd\_itidal(isd:ied,jsd:jed,nz+1)) ; dd\%Kd\_itidal(:,:,:) = 0.0}
\DoxyCodeLine{1425 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1426   \textcolor{keywordflow}{if} ((cs\%id\_Kd\_lowmode > 0) .or. (cs\%id\_Kd\_lowmode\_work > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1427     \textcolor{keyword}{allocate}(dd\%Kd\_lowmode(isd:ied,jsd:jed,nz+1)) ; dd\%Kd\_lowmode(:,:,:) = 0.0}
\DoxyCodeLine{1428 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1429   \textcolor{keywordflow}{if} ( (cs\%id\_Fl\_itidal > 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1430     \textcolor{keyword}{allocate}(dd\%Fl\_itidal(isd:ied,jsd:jed,nz+1)) ; dd\%Fl\_itidal(:,:,:) = 0.0}
\DoxyCodeLine{1431 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1432   \textcolor{keywordflow}{if} ( (cs\%id\_Fl\_lowmode > 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1433     \textcolor{keyword}{allocate}(dd\%Fl\_lowmode(isd:ied,jsd:jed,nz+1)) ; dd\%Fl\_lowmode(:,:,:) = 0.0}
\DoxyCodeLine{1434 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1435   \textcolor{keywordflow}{if} ( (cs\%id\_Polzin\_decay\_scale > 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1436     \textcolor{keyword}{allocate}(dd\%Polzin\_decay\_scale(isd:ied,jsd:jed))}
\DoxyCodeLine{1437     dd\%Polzin\_decay\_scale(:,:) = 0.0}
\DoxyCodeLine{1438 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1439   \textcolor{keywordflow}{if} ( (cs\%id\_N2\_bot > 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1440     \textcolor{keyword}{allocate}(dd\%N2\_bot(isd:ied,jsd:jed)) ; dd\%N2\_bot(:,:) = 0.0}
\DoxyCodeLine{1441 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1442   \textcolor{keywordflow}{if} ( (cs\%id\_N2\_meanz > 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1443     \textcolor{keyword}{allocate}(dd\%N2\_meanz(isd:ied,jsd:jed)) ; dd\%N2\_meanz(:,:) = 0.0}
\DoxyCodeLine{1444 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1445   \textcolor{keywordflow}{if} ( (cs\%id\_Polzin\_decay\_scale\_scaled > 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1446     \textcolor{keyword}{allocate}(dd\%Polzin\_decay\_scale\_scaled(isd:ied,jsd:jed))}
\DoxyCodeLine{1447     dd\%Polzin\_decay\_scale\_scaled(:,:) = 0.0}
\DoxyCodeLine{1448 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1449   \textcolor{keywordflow}{if} ((cs\%id\_Kd\_Niku > 0) .or. (cs\%id\_Kd\_Niku\_work > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1450     \textcolor{keyword}{allocate}(dd\%Kd\_Niku(isd:ied,jsd:jed,nz+1)) ; dd\%Kd\_Niku(:,:,:) = 0.0}
\DoxyCodeLine{1451 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1452   \textcolor{keywordflow}{if} (cs\%id\_Kd\_Niku\_work > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1453     \textcolor{keyword}{allocate}(dd\%Kd\_Niku\_work(isd:ied,jsd:jed,nz)) ; dd\%Kd\_Niku\_work(:,:,:) = 0.0}
\DoxyCodeLine{1454 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1455   \textcolor{keywordflow}{if} (cs\%id\_Kd\_Itidal\_work > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1456     \textcolor{keyword}{allocate}(dd\%Kd\_Itidal\_work(isd:ied,jsd:jed,nz))}
\DoxyCodeLine{1457     dd\%Kd\_Itidal\_work(:,:,:) = 0.0}
\DoxyCodeLine{1458 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1459   \textcolor{keywordflow}{if} (cs\%id\_Kd\_Lowmode\_Work > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1460     \textcolor{keyword}{allocate}(dd\%Kd\_Lowmode\_Work(isd:ied,jsd:jed,nz))}
\DoxyCodeLine{1461     dd\%Kd\_Lowmode\_Work(:,:,:) = 0.0}
\DoxyCodeLine{1462 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1463   \textcolor{keywordflow}{if} (cs\%id\_TKE\_itidal > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1464     \textcolor{keyword}{allocate}(dd\%TKE\_Itidal\_used(isd:ied,jsd:jed)) ; dd\%TKE\_Itidal\_used(:,:) = 0.}
\DoxyCodeLine{1465 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1466   \textcolor{comment}{! additional diags for CVMix}}
\DoxyCodeLine{1467   \textcolor{keywordflow}{if} (cs\%id\_N2\_int > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1468     \textcolor{keyword}{allocate}(dd\%N2\_int(isd:ied,jsd:jed,nz+1)) ; dd\%N2\_int(:,:,:) = 0.0}
\DoxyCodeLine{1469 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1470   \textcolor{keywordflow}{if} (cs\%id\_Simmons\_coeff > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1471     \textcolor{keywordflow}{if} (cs\%CVMix\_tidal\_scheme .ne. simmons) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1472       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}setup\_tidal\_diagnostics: Simmons\_coeff diagnostics is available "{}}//\&}
\DoxyCodeLine{1473                             \textcolor{stringliteral}{"{}only when CVMix\_tidal\_scheme is Simmons"{}})}
\DoxyCodeLine{1474 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1475     \textcolor{keyword}{allocate}(dd\%Simmons\_coeff\_2d(isd:ied,jsd:jed)) ; dd\%Simmons\_coeff\_2d(:,:) = 0.0}
\DoxyCodeLine{1476 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1477   \textcolor{keywordflow}{if} (cs\%id\_vert\_dep > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1478     \textcolor{keyword}{allocate}(dd\%vert\_dep\_3d(isd:ied,jsd:jed,nz+1)) ; dd\%vert\_dep\_3d(:,:,:) = 0.0}
\DoxyCodeLine{1479 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1480   \textcolor{keywordflow}{if} (cs\%id\_Schmittner\_coeff > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1481     \textcolor{keywordflow}{if} (cs\%CVMix\_tidal\_scheme .ne. schmittner) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1482       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}setup\_tidal\_diagnostics: Schmittner\_coeff diagnostics is available "{}}//\&}
\DoxyCodeLine{1483                             \textcolor{stringliteral}{"{}only when CVMix\_tidal\_scheme is Schmittner."{}})}
\DoxyCodeLine{1484 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1485     \textcolor{keyword}{allocate}(dd\%Schmittner\_coeff\_3d(isd:ied,jsd:jed,nz)) ; dd\%Schmittner\_coeff\_3d(:,:,:) = 0.0}
\DoxyCodeLine{1486 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1487   \textcolor{keywordflow}{if} (cs\%id\_tidal\_qe\_md > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1488     \textcolor{keywordflow}{if} (cs\%CVMix\_tidal\_scheme .ne. schmittner) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1489       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}setup\_tidal\_diagnostics: tidal\_qe\_md diagnostics is available "{}}//\&}
\DoxyCodeLine{1490                             \textcolor{stringliteral}{"{}only when CVMix\_tidal\_scheme is Schmittner."{}})}
\DoxyCodeLine{1491 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1492     \textcolor{keyword}{allocate}(dd\%tidal\_qe\_md(isd:ied,jsd:jed,nz)) ; dd\%tidal\_qe\_md(:,:,:) = 0.0}
\DoxyCodeLine{1493 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a4ec08e118dea2ecbac7e719ed73acc70}\label{namespacemom__tidal__mixing_a4ec08e118dea2ecbac7e719ed73acc70}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!tidal\_mixing\_end@{tidal\_mixing\_end}}
\index{tidal\_mixing\_end@{tidal\_mixing\_end}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{tidal\_mixing\_end()}{tidal\_mixing\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::tidal\+\_\+mixing\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clear pointers and deallocate memory. 


\begin{DoxyParams}{Parameters}
{\em cs} & This module\textquotesingle{}s control structure, which will be deallocated in this routine. \\
\hline
\end{DoxyParams}


Definition at line 1723 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1724   \textcolor{keywordtype}{type}(tidal\_mixing\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< This module's control structure, which}}
\DoxyCodeLine{1725 \textcolor{comment}{                                       !! will be deallocated in this routine.}}
\DoxyCodeLine{1726 }
\DoxyCodeLine{1727   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1728 }
\DoxyCodeLine{1729   \textcolor{comment}{!TODO deallocate all the dynamically allocated members here ...}}
\DoxyCodeLine{1730   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%tidal\_qe\_2d))    \textcolor{keyword}{deallocate}(cs\%tidal\_qe\_2d)}
\DoxyCodeLine{1731   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%tidal\_qe\_3d\_in)) \textcolor{keyword}{deallocate}(cs\%tidal\_qe\_3d\_in)}
\DoxyCodeLine{1732   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%h\_src))          \textcolor{keyword}{deallocate}(cs\%h\_src)}
\DoxyCodeLine{1733   \textcolor{keyword}{deallocate}(cs\%dd)}
\DoxyCodeLine{1734   \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1735 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a31fc0b55d7766de2d21fb529e491de13}\label{namespacemom__tidal__mixing_a31fc0b55d7766de2d21fb529e491de13}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!tidal\_mixing\_h\_amp@{tidal\_mixing\_h\_amp}}
\index{tidal\_mixing\_h\_amp@{tidal\_mixing\_h\_amp}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{tidal\_mixing\_h\_amp()}{tidal\_mixing\_h\_amp()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::tidal\+\_\+mixing\+\_\+h\+\_\+amp (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied), intent(out)}]{h\+\_\+amp,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{integer, intent(in)}]{j,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine returns a zonal slice of the topographic roughness amplitudes. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+amp} & The topographic roughness amplitude \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em j} & j-\/index of the row to work on \\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1562 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1563   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{     !< The ocean's grid structure}}
\DoxyCodeLine{1564 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_amp\textcolor{comment}{ !< The topographic roughness amplitude [Z \string~> m]}}
\DoxyCodeLine{1565   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}  :: j\textcolor{comment}{     !< j-\/index of the row to work on}}
\DoxyCodeLine{1566   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),    \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{    !< The control structure for this module}}
\DoxyCodeLine{1567 }
\DoxyCodeLine{1568   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{1569 }
\DoxyCodeLine{1570   h\_amp(:) = 0.0}
\DoxyCodeLine{1571   \textcolor{keywordflow}{if} ( cs\%Int\_tide\_dissipation .and. .not. cs\%use\_CVMix\_tidal ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1572     \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{1573       h\_amp(i) = sqrt(cs\%h2(i,j))}
\DoxyCodeLine{1574 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1575 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1576 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a6278fe41ef74ac23ba02ae1540104c5f}\label{namespacemom__tidal__mixing_a6278fe41ef74ac23ba02ae1540104c5f}} 
\index{mom\_tidal\_mixing@{mom\_tidal\_mixing}!tidal\_mixing\_init@{tidal\_mixing\_init}}
\index{tidal\_mixing\_init@{tidal\_mixing\_init}!mom\_tidal\_mixing@{mom\_tidal\_mixing}}
\doxysubsubsection{\texorpdfstring{tidal\_mixing\_init()}{tidal\_mixing\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+tidal\+\_\+mixing\+::tidal\+\_\+mixing\+\_\+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__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initializes internal tidal dissipation scheme for diapycnal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current time. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & 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}}  & {\em param\+\_\+file} & Run-\/time parameter file handle \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics control structure. \\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}
T\+O\+DO\+: add units

Definition at line 212 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{213   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current time.}}
\DoxyCodeLine{214   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< Grid structure.}}
\DoxyCodeLine{215   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Vertical grid structure.}}
\DoxyCodeLine{216   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{217   \textcolor{keywordtype}{type}(param\_file\_type),    \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Run-\/time parameter file handle}}
\DoxyCodeLine{218   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},  \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics control structure.}}
\DoxyCodeLine{219   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),    \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< This module's control structure.}}
\DoxyCodeLine{220 }
\DoxyCodeLine{221   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{222   \textcolor{keywordtype}{logical} :: read\_tideamp}
\DoxyCodeLine{223   \textcolor{keywordtype}{logical} :: default\_2018\_answers}
\DoxyCodeLine{224   \textcolor{keywordtype}{character(len=20)}  :: tmpstr, int\_tide\_profile\_str}
\DoxyCodeLine{225   \textcolor{keywordtype}{character(len=20)}  :: CVMix\_tidal\_scheme\_str, tidal\_energy\_type}
\DoxyCodeLine{226   \textcolor{keywordtype}{character(len=200)} :: filename, h2\_file, Niku\_TKE\_input\_file}
\DoxyCodeLine{227   \textcolor{keywordtype}{character(len=200)} :: tidal\_energy\_file, tideamp\_file}
\DoxyCodeLine{228 \textcolor{keywordtype}{  real} :: utide, hamp, prandtl\_tidal, max\_frac\_rough}
\DoxyCodeLine{229 \textcolor{keywordtype}{  real} :: Niku\_scale \textcolor{comment}{! local variable for scaling the Nikurashin TKE flux data}}
\DoxyCodeLine{230   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{231   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed}
\DoxyCodeLine{232   \textcolor{comment}{! This include declares and sets the variable "{}version"{}.}}
\DoxyCodeLine{233 \textcolor{preprocessor}{\# include "{}version\_variable.h"{}}}
\DoxyCodeLine{234 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}MOM\_tidal\_mixing"{}}\textcolor{comment}{     !< This module's name.}}
\DoxyCodeLine{235 }
\DoxyCodeLine{236   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{237     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}tidal\_mixing\_init called when control structure "{}}// \&}
\DoxyCodeLine{238                             \textcolor{stringliteral}{"{}is already associated."{}})}
\DoxyCodeLine{239     \textcolor{keywordflow}{return}}
\DoxyCodeLine{240 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{241   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{242   \textcolor{keyword}{allocate}(cs\%dd)}
\DoxyCodeLine{243 }
\DoxyCodeLine{244   cs\%debug = cs\%debug.and.is\_root\_pe()}
\DoxyCodeLine{245 }
\DoxyCodeLine{246   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec}
\DoxyCodeLine{247   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{248 }
\DoxyCodeLine{249   cs\%diag => diag}
\DoxyCodeLine{250 }
\DoxyCodeLine{251   \textcolor{comment}{! Read parameters}}
\DoxyCodeLine{252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_CVMix\_TIDAL"{}}, cs\%use\_CVMix\_tidal, \&}
\DoxyCodeLine{253                  default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{254   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INT\_TIDE\_DISSIPATION"{}}, cs\%int\_tide\_dissipation, \&}
\DoxyCodeLine{255                  default=cs\%use\_CVMix\_tidal, do\_not\_log=.true.)}
\DoxyCodeLine{256   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \&}
\DoxyCodeLine{257                  \textcolor{stringliteral}{"{}Vertical Tidal Mixing Parameterization"{}}, \&}
\DoxyCodeLine{258                  all\_default=.not.(cs\%use\_CVMix\_tidal .or. cs\%int\_tide\_dissipation))}
\DoxyCodeLine{259   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_CVMix\_TIDAL"{}}, cs\%use\_CVMix\_tidal, \&}
\DoxyCodeLine{260                  \textcolor{stringliteral}{"{}If true, turns on tidal mixing via CVMix"{}}, \&}
\DoxyCodeLine{261                  default=.false.)}
\DoxyCodeLine{262 }
\DoxyCodeLine{263   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INPUTDIR"{}}, cs\%inputdir, default=\textcolor{stringliteral}{"{}."{}},do\_not\_log=.true.)}
\DoxyCodeLine{264   cs\%inputdir = slasher(cs\%inputdir)}
\DoxyCodeLine{265   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INT\_TIDE\_DISSIPATION"{}}, cs\%int\_tide\_dissipation, \&}
\DoxyCodeLine{266                  \textcolor{stringliteral}{"{}If true, use an internal tidal dissipation scheme to "{}}//\&}
\DoxyCodeLine{267                  \textcolor{stringliteral}{"{}drive diapycnal mixing, along the lines of St. Laurent "{}}//\&}
\DoxyCodeLine{268                  \textcolor{stringliteral}{"{}et al. (2002) and Simmons et al. (2004)."{}}, default=cs\%use\_CVMix\_tidal)}
\DoxyCodeLine{269 }
\DoxyCodeLine{270   \textcolor{comment}{! return if tidal mixing is inactive}}
\DoxyCodeLine{271   tidal\_mixing\_init = cs\%int\_tide\_dissipation}
\DoxyCodeLine{272   \textcolor{keywordflow}{if} (.not. tidal\_mixing\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{273 }
\DoxyCodeLine{274   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEFAULT\_2018\_ANSWERS"{}}, default\_2018\_answers, \&}
\DoxyCodeLine{275                  \textcolor{stringliteral}{"{}This sets the default value for the various \_2018\_ANSWERS parameters."{}}, \&}
\DoxyCodeLine{276                  default=.false.)}
\DoxyCodeLine{277   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDAL\_MIXING\_2018\_ANSWERS"{}}, cs\%answers\_2018, \&}
\DoxyCodeLine{278                  \textcolor{stringliteral}{"{}If true, use the order of arithmetic and expressions that recover the "{}}//\&}
\DoxyCodeLine{279                  \textcolor{stringliteral}{"{}answers from the end of 2018.  Otherwise, use updated and more robust "{}}//\&}
\DoxyCodeLine{280                  \textcolor{stringliteral}{"{}forms of the same expressions."{}}, default=default\_2018\_answers)}
\DoxyCodeLine{281   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}REMAPPING\_2018\_ANSWERS"{}}, cs\%remap\_answers\_2018, \&}
\DoxyCodeLine{282                  \textcolor{stringliteral}{"{}If true, use the order of arithmetic and expressions that recover the "{}}//\&}
\DoxyCodeLine{283                  \textcolor{stringliteral}{"{}answers from the end of 2018.  Otherwise, use updated and more robust "{}}//\&}
\DoxyCodeLine{284                  \textcolor{stringliteral}{"{}forms of the same expressions."{}}, default=default\_2018\_answers)}
\DoxyCodeLine{285 }
\DoxyCodeLine{286   \textcolor{keywordflow}{if} (cs\%int\_tide\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{287 }
\DoxyCodeLine{288     \textcolor{comment}{! Read in CVMix tidal scheme if CVMix tidal mixing is on}}
\DoxyCodeLine{289     \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{290       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CVMIX\_TIDAL\_SCHEME"{}}, cvmix\_tidal\_scheme\_str, \&}
\DoxyCodeLine{291                  \textcolor{stringliteral}{"{}CVMIX\_TIDAL\_SCHEME selects the CVMix tidal mixing "{}}//\&}
\DoxyCodeLine{292                  \textcolor{stringliteral}{"{}scheme with INT\_TIDE\_DISSIPATION. Valid values are:\(\backslash\)n"{}}//\&}
\DoxyCodeLine{293                  \textcolor{stringliteral}{"{}\(\backslash\)t SIMMONS -\/ Use the Simmons et al (2004) tidal \(\backslash\)n"{}}//\&}
\DoxyCodeLine{294                  \textcolor{stringliteral}{"{}\(\backslash\)t                mixing scheme.\(\backslash\)n"{}}//\&}
\DoxyCodeLine{295                  \textcolor{stringliteral}{"{}\(\backslash\)t SCHMITTNER -\/ Use the Schmittner et al (2014) tidal \(\backslash\)n"{}}//\&}
\DoxyCodeLine{296                  \textcolor{stringliteral}{"{}\(\backslash\)t                mixing scheme."{}}, \&}
\DoxyCodeLine{297                  default=simmons\_scheme\_string)}
\DoxyCodeLine{298       cvmix\_tidal\_scheme\_str = uppercase(cvmix\_tidal\_scheme\_str)}
\DoxyCodeLine{299 }
\DoxyCodeLine{300       \textcolor{keywordflow}{select case} (cvmix\_tidal\_scheme\_str)}
\DoxyCodeLine{301         \textcolor{keywordflow}{case} (simmons\_scheme\_string)    ; cs\%CVMix\_tidal\_scheme = simmons}
\DoxyCodeLine{302         \textcolor{keywordflow}{case} (schmittner\_scheme\_string) ; cs\%CVMix\_tidal\_scheme = schmittner}
\DoxyCodeLine{303 \textcolor{keywordflow}{        case default}}
\DoxyCodeLine{304         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Unrecognized setting "{}}// \&}
\DoxyCodeLine{305             \textcolor{stringliteral}{"{}\#define CVMIX\_TIDAL\_SCHEME "{}}//trim(cvmix\_tidal\_scheme\_str)//\textcolor{stringliteral}{"{} found in input file."{}})}
\DoxyCodeLine{306 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{307 \textcolor{keywordflow}{    endif} \textcolor{comment}{! CS\%use\_CVMix\_tidal}}
\DoxyCodeLine{308 }
\DoxyCodeLine{309     \textcolor{comment}{! Read in vertical profile of tidal energy dissipation}}
\DoxyCodeLine{310     \textcolor{keywordflow}{if} ( cs\%CVMix\_tidal\_scheme.eq.schmittner .or. .not. cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{311       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INT\_TIDE\_PROFILE"{}}, int\_tide\_profile\_str, \&}
\DoxyCodeLine{312                    \textcolor{stringliteral}{"{}INT\_TIDE\_PROFILE selects the vertical profile of energy "{}}//\&}
\DoxyCodeLine{313                    \textcolor{stringliteral}{"{}dissipation with INT\_TIDE\_DISSIPATION. Valid values are:\(\backslash\)n"{}}//\&}
\DoxyCodeLine{314                    \textcolor{stringliteral}{"{}\(\backslash\)t STLAURENT\_02 -\/ Use the St. Laurent et al exponential \(\backslash\)n"{}}//\&}
\DoxyCodeLine{315                    \textcolor{stringliteral}{"{}\(\backslash\)t                decay profile.\(\backslash\)n"{}}//\&}
\DoxyCodeLine{316                    \textcolor{stringliteral}{"{}\(\backslash\)t POLZIN\_09 -\/ Use the Polzin WKB-\/stretched algebraic \(\backslash\)n"{}}//\&}
\DoxyCodeLine{317                    \textcolor{stringliteral}{"{}\(\backslash\)t                decay profile."{}}, \&}
\DoxyCodeLine{318                    default=stlaurent\_profile\_string)}
\DoxyCodeLine{319       int\_tide\_profile\_str = uppercase(int\_tide\_profile\_str)}
\DoxyCodeLine{320 }
\DoxyCodeLine{321       \textcolor{keywordflow}{select case} (int\_tide\_profile\_str)}
\DoxyCodeLine{322         \textcolor{keywordflow}{case} (stlaurent\_profile\_string)   ; cs\%int\_tide\_profile = stlaurent\_02}
\DoxyCodeLine{323         \textcolor{keywordflow}{case} (polzin\_profile\_string)      ; cs\%int\_tide\_profile = polzin\_09}
\DoxyCodeLine{324 \textcolor{keywordflow}{        case default}}
\DoxyCodeLine{325           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Unrecognized setting "{}}// \&}
\DoxyCodeLine{326               \textcolor{stringliteral}{"{}\#define INT\_TIDE\_PROFILE "{}}//trim(int\_tide\_profile\_str)//\textcolor{stringliteral}{"{} found in input file."{}})}
\DoxyCodeLine{327 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{328 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{329 }
\DoxyCodeLine{330   \textcolor{keywordflow}{elseif} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{331         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Cannot set INT\_TIDE\_DISSIPATION to False "{}}// \&}
\DoxyCodeLine{332             \textcolor{stringliteral}{"{}when USE\_CVMix\_TIDAL is set to True."{}})}
\DoxyCodeLine{333 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{334 }
\DoxyCodeLine{335   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}LEE\_WAVE\_DISSIPATION"{}}, cs\%Lee\_wave\_dissipation, \&}
\DoxyCodeLine{336                  \textcolor{stringliteral}{"{}If true, use an lee wave driven dissipation scheme to "{}}//\&}
\DoxyCodeLine{337                  \textcolor{stringliteral}{"{}drive diapycnal mixing, along the lines of Nikurashin "{}}//\&}
\DoxyCodeLine{338                  \textcolor{stringliteral}{"{}(2010) and using the St. Laurent et al. (2002) "{}}//\&}
\DoxyCodeLine{339                  \textcolor{stringliteral}{"{}and Simmons et al. (2004) vertical profile"{}}, default=.false.)}
\DoxyCodeLine{340   \textcolor{keywordflow}{if} (cs\%lee\_wave\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{341     \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{342         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Lee wave driven dissipation scheme cannot "{}}// \&}
\DoxyCodeLine{343             \textcolor{stringliteral}{"{}be used when CVMix tidal mixing scheme is active."{}})}
\DoxyCodeLine{344 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{345     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}LEE\_WAVE\_PROFILE"{}}, tmpstr, \&}
\DoxyCodeLine{346                  \textcolor{stringliteral}{"{}LEE\_WAVE\_PROFILE selects the vertical profile of energy "{}}//\&}
\DoxyCodeLine{347                  \textcolor{stringliteral}{"{}dissipation with LEE\_WAVE\_DISSIPATION. Valid values are:\(\backslash\)n"{}}//\&}
\DoxyCodeLine{348                  \textcolor{stringliteral}{"{}\(\backslash\)t STLAURENT\_02 -\/ Use the St. Laurent et al exponential \(\backslash\)n"{}}//\&}
\DoxyCodeLine{349                  \textcolor{stringliteral}{"{}\(\backslash\)t                decay profile.\(\backslash\)n"{}}//\&}
\DoxyCodeLine{350                  \textcolor{stringliteral}{"{}\(\backslash\)t POLZIN\_09 -\/ Use the Polzin WKB-\/stretched algebraic \(\backslash\)n"{}}//\&}
\DoxyCodeLine{351                  \textcolor{stringliteral}{"{}\(\backslash\)t                decay profile."{}}, \&}
\DoxyCodeLine{352                  default=stlaurent\_profile\_string)}
\DoxyCodeLine{353     tmpstr = uppercase(tmpstr)}
\DoxyCodeLine{354     \textcolor{keywordflow}{select case} (tmpstr)}
\DoxyCodeLine{355       \textcolor{keywordflow}{case} (stlaurent\_profile\_string) ; cs\%lee\_wave\_profile = stlaurent\_02}
\DoxyCodeLine{356       \textcolor{keywordflow}{case} (polzin\_profile\_string) ; cs\%lee\_wave\_profile = polzin\_09}
\DoxyCodeLine{357 \textcolor{keywordflow}{      case default}}
\DoxyCodeLine{358         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Unrecognized setting "{}}// \&}
\DoxyCodeLine{359             \textcolor{stringliteral}{"{}\#define LEE\_WAVE\_PROFILE "{}}//trim(tmpstr)//\textcolor{stringliteral}{"{} found in input file."{}})}
\DoxyCodeLine{360 \textcolor{keywordflow}{    end select}}
\DoxyCodeLine{361 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{362 }
\DoxyCodeLine{363   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INT\_TIDE\_LOWMODE\_DISSIPATION"{}}, cs\%Lowmode\_itidal\_dissipation, \&}
\DoxyCodeLine{364                  \textcolor{stringliteral}{"{}If true, consider mixing due to breaking low modes that "{}}//\&}
\DoxyCodeLine{365                  \textcolor{stringliteral}{"{}have been remotely generated; as with itidal drag on the "{}}//\&}
\DoxyCodeLine{366                  \textcolor{stringliteral}{"{}barotropic tide, use an internal tidal dissipation scheme to "{}}//\&}
\DoxyCodeLine{367                  \textcolor{stringliteral}{"{}drive diapycnal mixing, along the lines of St. Laurent "{}}//\&}
\DoxyCodeLine{368                  \textcolor{stringliteral}{"{}et al. (2002) and Simmons et al. (2004)."{}}, default=.false.)}
\DoxyCodeLine{369 }
\DoxyCodeLine{370   \textcolor{keywordflow}{if} ((cs\%Int\_tide\_dissipation .and. (cs\%int\_tide\_profile == polzin\_09)) .or. \&}
\DoxyCodeLine{371       (cs\%lee\_wave\_dissipation .and. (cs\%lee\_wave\_profile == polzin\_09))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{372     \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{373         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Polzin scheme cannot "{}}// \&}
\DoxyCodeLine{374             \textcolor{stringliteral}{"{}be used when CVMix tidal mixing scheme is active."{}})}
\DoxyCodeLine{375 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{376     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NU\_POLZIN"{}}, cs\%Nu\_Polzin, \&}
\DoxyCodeLine{377                  \textcolor{stringliteral}{"{}When the Polzin decay profile is used, this is a "{}}//\&}
\DoxyCodeLine{378                  \textcolor{stringliteral}{"{}non-\/dimensional constant in the expression for the "{}}//\&}
\DoxyCodeLine{379                  \textcolor{stringliteral}{"{}vertical scale of decay for the tidal energy dissipation."{}}, \&}
\DoxyCodeLine{380                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.0697)}
\DoxyCodeLine{381     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NBOTREF\_POLZIN"{}}, cs\%Nbotref\_Polzin, \&}
\DoxyCodeLine{382                  \textcolor{stringliteral}{"{}When the Polzin decay profile is used, this is the "{}}//\&}
\DoxyCodeLine{383                  \textcolor{stringliteral}{"{}reference value of the buoyancy frequency at the ocean "{}}//\&}
\DoxyCodeLine{384                  \textcolor{stringliteral}{"{}bottom in the Polzin formulation for the vertical "{}}//\&}
\DoxyCodeLine{385                  \textcolor{stringliteral}{"{}scale of decay for the tidal energy dissipation."{}}, \&}
\DoxyCodeLine{386                  units=\textcolor{stringliteral}{"{}s-\/1"{}}, default=9.61e-\/4, scale=us\%T\_to\_s)}
\DoxyCodeLine{387     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}POLZIN\_DECAY\_SCALE\_FACTOR"{}}, \&}
\DoxyCodeLine{388                  cs\%Polzin\_decay\_scale\_factor, \&}
\DoxyCodeLine{389                  \textcolor{stringliteral}{"{}When the Polzin decay profile is used, this is a "{}}//\&}
\DoxyCodeLine{390                  \textcolor{stringliteral}{"{}scale factor for the vertical scale of decay of the tidal "{}}//\&}
\DoxyCodeLine{391                  \textcolor{stringliteral}{"{}energy dissipation."{}}, default=1.0, units=\textcolor{stringliteral}{"{}nondim"{}})}
\DoxyCodeLine{392     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}POLZIN\_SCALE\_MAX\_FACTOR"{}}, \&}
\DoxyCodeLine{393                  cs\%Polzin\_decay\_scale\_max\_factor, \&}
\DoxyCodeLine{394                  \textcolor{stringliteral}{"{}When the Polzin decay profile is used, this is a factor "{}}//\&}
\DoxyCodeLine{395                  \textcolor{stringliteral}{"{}to limit the vertical scale of decay of the tidal "{}}//\&}
\DoxyCodeLine{396                  \textcolor{stringliteral}{"{}energy dissipation to POLZIN\_DECAY\_SCALE\_MAX\_FACTOR "{}}//\&}
\DoxyCodeLine{397                  \textcolor{stringliteral}{"{}times the depth of the ocean."{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, default=1.0)}
\DoxyCodeLine{398     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}POLZIN\_MIN\_DECAY\_SCALE"{}}, cs\%Polzin\_min\_decay\_scale, \&}
\DoxyCodeLine{399                  \textcolor{stringliteral}{"{}When the Polzin decay profile is used, this is the "{}}//\&}
\DoxyCodeLine{400                  \textcolor{stringliteral}{"{}minimum vertical decay scale for the vertical profile\(\backslash\)n"{}}//\&}
\DoxyCodeLine{401                  \textcolor{stringliteral}{"{}of internal tide dissipation with the Polzin (2009) formulation"{}}, \&}
\DoxyCodeLine{402                  units=\textcolor{stringliteral}{"{}m"{}}, default=0.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{403 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{404 }
\DoxyCodeLine{405   \textcolor{keywordflow}{if} (cs\%Int\_tide\_dissipation .or. cs\%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{406     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INT\_TIDE\_DECAY\_SCALE"{}}, cs\%Int\_tide\_decay\_scale, \&}
\DoxyCodeLine{407                  \textcolor{stringliteral}{"{}The decay scale away from the bottom for tidal TKE with "{}}//\&}
\DoxyCodeLine{408                  \textcolor{stringliteral}{"{}the new coding when INT\_TIDE\_DISSIPATION is used."{}}, \&}
\DoxyCodeLine{409                  \textcolor{comment}{!units="{}m"{}, default=0.0)}}
\DoxyCodeLine{410                  units=\textcolor{stringliteral}{"{}m"{}}, default=500.0, scale=us\%m\_to\_Z)  \textcolor{comment}{! TODO: confirm this new default}}
\DoxyCodeLine{411     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}MU\_ITIDES"{}}, cs\%Mu\_itides, \&}
\DoxyCodeLine{412                  \textcolor{stringliteral}{"{}A dimensionless turbulent mixing efficiency used with "{}}//\&}
\DoxyCodeLine{413                  \textcolor{stringliteral}{"{}INT\_TIDE\_DISSIPATION, often 0.2."{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.2)}
\DoxyCodeLine{414     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}GAMMA\_ITIDES"{}}, cs\%Gamma\_itides, \&}
\DoxyCodeLine{415                  \textcolor{stringliteral}{"{}The fraction of the internal tidal energy that is "{}}//\&}
\DoxyCodeLine{416                  \textcolor{stringliteral}{"{}dissipated locally with INT\_TIDE\_DISSIPATION. "{}}//\&}
\DoxyCodeLine{417                  \textcolor{stringliteral}{"{}THIS NAME COULD BE BETTER."{}}, \&}
\DoxyCodeLine{418                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.3333)}
\DoxyCodeLine{419     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}MIN\_ZBOT\_ITIDES"{}}, cs\%min\_zbot\_itides, \&}
\DoxyCodeLine{420                  \textcolor{stringliteral}{"{}Turn off internal tidal dissipation when the total "{}}//\&}
\DoxyCodeLine{421                  \textcolor{stringliteral}{"{}ocean depth is less than this value."{}}, units=\textcolor{stringliteral}{"{}m"{}}, default=0.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{422 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{423 }
\DoxyCodeLine{424   \textcolor{keywordflow}{if} ( (cs\%Int\_tide\_dissipation .or. cs\%Lee\_wave\_dissipation) .and. \&}
\DoxyCodeLine{425         .not. cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{426 }
\DoxyCodeLine{427     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%Nb,isd,ied,jsd,jed)}
\DoxyCodeLine{428     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%h2,isd,ied,jsd,jed)}
\DoxyCodeLine{429     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%TKE\_itidal,isd,ied,jsd,jed)}
\DoxyCodeLine{430     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%mask\_itidal,isd,ied,jsd,jed) ; cs\%mask\_itidal(:,:) = 1.0}
\DoxyCodeLine{431 }
\DoxyCodeLine{432     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KAPPA\_ITIDES"{}}, cs\%kappa\_itides, \&}
\DoxyCodeLine{433                  \textcolor{stringliteral}{"{}A topographic wavenumber used with INT\_TIDE\_DISSIPATION. "{}}//\&}
\DoxyCodeLine{434                  \textcolor{stringliteral}{"{}The default is 2pi/10 km, as in St.Laurent et al. 2002."{}}, \&}
\DoxyCodeLine{435                  units=\textcolor{stringliteral}{"{}m-\/1"{}}, default=8.e-\/4*atan(1.0), scale=us\%Z\_to\_m)}
\DoxyCodeLine{436 }
\DoxyCodeLine{437     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}UTIDE"{}}, cs\%utide, \&}
\DoxyCodeLine{438                  \textcolor{stringliteral}{"{}The constant tidal amplitude used with INT\_TIDE\_DISSIPATION."{}}, \&}
\DoxyCodeLine{439                  units=\textcolor{stringliteral}{"{}m s-\/1"{}}, default=0.0, scale=us\%m\_to\_Z*us\%T\_to\_s)}
\DoxyCodeLine{440     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%tideamp,is,ie,js,je) ; cs\%tideamp(:,:) = cs\%utide}
\DoxyCodeLine{441 }
\DoxyCodeLine{442     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}KAPPA\_H2\_FACTOR"{}}, cs\%kappa\_h2\_factor, \&}
\DoxyCodeLine{443                  \textcolor{stringliteral}{"{}A scaling factor for the roughness amplitude with "{}}//\&}
\DoxyCodeLine{444                  \textcolor{stringliteral}{"{}INT\_TIDE\_DISSIPATION."{}},  units=\textcolor{stringliteral}{"{}nondim"{}}, default=1.0)}
\DoxyCodeLine{445     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TKE\_ITIDE\_MAX"{}}, cs\%TKE\_itide\_max, \&}
\DoxyCodeLine{446                  \textcolor{stringliteral}{"{}The maximum internal tide energy source available to mix "{}}//\&}
\DoxyCodeLine{447                  \textcolor{stringliteral}{"{}above the bottom boundary layer with INT\_TIDE\_DISSIPATION."{}}, \&}
\DoxyCodeLine{448                  units=\textcolor{stringliteral}{"{}W m-\/2"{}}, default=1.0e3, scale=us\%W\_m2\_to\_RZ3\_T3)}
\DoxyCodeLine{449 }
\DoxyCodeLine{450     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}READ\_TIDEAMP"{}}, read\_tideamp, \&}
\DoxyCodeLine{451                  \textcolor{stringliteral}{"{}If true, read a file (given by TIDEAMP\_FILE) containing "{}}//\&}
\DoxyCodeLine{452                  \textcolor{stringliteral}{"{}the tidal amplitude with INT\_TIDE\_DISSIPATION."{}}, default=.false.)}
\DoxyCodeLine{453     \textcolor{keywordflow}{if} (read\_tideamp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{454       \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{455           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Tidal amplitude files are "{}}// \&}
\DoxyCodeLine{456               \textcolor{stringliteral}{"{}not compatible with CVMix tidal mixing. "{}})}
\DoxyCodeLine{457 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{458       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDEAMP\_FILE"{}}, tideamp\_file, \&}
\DoxyCodeLine{459                  \textcolor{stringliteral}{"{}The path to the file containing the spatially varying "{}}//\&}
\DoxyCodeLine{460                  \textcolor{stringliteral}{"{}tidal amplitudes with INT\_TIDE\_DISSIPATION."{}}, default=\textcolor{stringliteral}{"{}tideamp.nc"{}})}
\DoxyCodeLine{461       filename = trim(cs\%inputdir) // trim(tideamp\_file)}
\DoxyCodeLine{462       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INPUTDIR/TIDEAMP\_FILE"{}}, filename)}
\DoxyCodeLine{463       \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'tideamp'}, cs\%tideamp, g\%domain, timelevel=1, scale=us\%m\_to\_Z*us\%T\_to\_s)}
\DoxyCodeLine{464 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{465 }
\DoxyCodeLine{466     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}H2\_FILE"{}}, h2\_file, \&}
\DoxyCodeLine{467                  \textcolor{stringliteral}{"{}The path to the file containing the sub-\/grid-\/scale "{}}//\&}
\DoxyCodeLine{468                  \textcolor{stringliteral}{"{}topographic roughness amplitude with INT\_TIDE\_DISSIPATION."{}}, \&}
\DoxyCodeLine{469                  fail\_if\_missing=(.not.cs\%use\_CVMix\_tidal))}
\DoxyCodeLine{470     filename = trim(cs\%inputdir) // trim(h2\_file)}
\DoxyCodeLine{471     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INPUTDIR/H2\_FILE"{}}, filename)}
\DoxyCodeLine{472     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'h2'}, cs\%h2, g\%domain, timelevel=1, scale=us\%m\_to\_Z**2)}
\DoxyCodeLine{473 }
\DoxyCodeLine{474     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}FRACTIONAL\_ROUGHNESS\_MAX"{}}, max\_frac\_rough, \&}
\DoxyCodeLine{475                  \textcolor{stringliteral}{"{}The maximum topographic roughness amplitude as a fraction of the mean depth, "{}}//\&}
\DoxyCodeLine{476                  \textcolor{stringliteral}{"{}or a negative value for no limitations on roughness."{}}, \&}
\DoxyCodeLine{477                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.1)}
\DoxyCodeLine{478 }
\DoxyCodeLine{479     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{480       \textcolor{keywordflow}{if} (g\%bathyT(i,j) < cs\%min\_zbot\_itides) cs\%mask\_itidal(i,j) = 0.0}
\DoxyCodeLine{481       cs\%tideamp(i,j) = cs\%tideamp(i,j) * cs\%mask\_itidal(i,j) * g\%mask2dT(i,j)}
\DoxyCodeLine{482 }
\DoxyCodeLine{483       \textcolor{comment}{! Restrict rms topo to a fraction (often 10 percent) of the column depth.}}
\DoxyCodeLine{484       \textcolor{keywordflow}{if} (cs\%answers\_2018 .and. (max\_frac\_rough >= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{485         hamp = min(max\_frac\_rough*g\%bathyT(i,j), sqrt(cs\%h2(i,j)))}
\DoxyCodeLine{486         cs\%h2(i,j) = hamp*hamp}
\DoxyCodeLine{487       \textcolor{keywordflow}{else}}
\DoxyCodeLine{488         \textcolor{keywordflow}{if} (max\_frac\_rough >= 0.0) \&}
\DoxyCodeLine{489           cs\%h2(i,j) = min((max\_frac\_rough*g\%bathyT(i,j))**2, cs\%h2(i,j))}
\DoxyCodeLine{490 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{491 }
\DoxyCodeLine{492       utide = cs\%tideamp(i,j)}
\DoxyCodeLine{493       \textcolor{comment}{! Compute the fixed part of internal tidal forcing.}}
\DoxyCodeLine{494       \textcolor{comment}{! The units here are [R Z3 T-\/2 \string~> J m-\/2 = kg s-\/2] here.}}
\DoxyCodeLine{495       cs\%TKE\_itidal(i,j) = 0.5 * cs\%kappa\_h2\_factor * gv\%Rho0 * \&}
\DoxyCodeLine{496            cs\%kappa\_itides * cs\%h2(i,j) * utide*utide}
\DoxyCodeLine{497 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{498 }
\DoxyCodeLine{499 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{500 }
\DoxyCodeLine{501   \textcolor{keywordflow}{if} (cs\%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{502 }
\DoxyCodeLine{503     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NIKURASHIN\_TKE\_INPUT\_FILE"{}},niku\_tke\_input\_file, \&}
\DoxyCodeLine{504                  \textcolor{stringliteral}{"{}The path to the file containing the TKE input from lee "{}}//\&}
\DoxyCodeLine{505                  \textcolor{stringliteral}{"{}wave driven mixing. Used with LEE\_WAVE\_DISSIPATION."{}}, \&}
\DoxyCodeLine{506                  fail\_if\_missing=.true.)}
\DoxyCodeLine{507     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NIKURASHIN\_SCALE"{}},niku\_scale, \&}
\DoxyCodeLine{508                  \textcolor{stringliteral}{"{}A non-\/dimensional factor by which to scale the lee-\/wave "{}}//\&}
\DoxyCodeLine{509                  \textcolor{stringliteral}{"{}driven TKE input. Used with LEE\_WAVE\_DISSIPATION."{}}, \&}
\DoxyCodeLine{510                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=1.0)}
\DoxyCodeLine{511 }
\DoxyCodeLine{512     filename = trim(cs\%inputdir) // trim(niku\_tke\_input\_file)}
\DoxyCodeLine{513     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INPUTDIR/NIKURASHIN\_TKE\_INPUT\_FILE"{}}, \&}
\DoxyCodeLine{514                    filename)}
\DoxyCodeLine{515     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%TKE\_Niku,is,ie,js,je) ; cs\%TKE\_Niku(:,:) = 0.0}
\DoxyCodeLine{516     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'TKE\_input'}, cs\%TKE\_Niku, g\%domain, timelevel=1, \&  \textcolor{comment}{! ??? timelevel -\/aja}}
\DoxyCodeLine{517                        scale=niku\_scale*us\%W\_m2\_to\_RZ3\_T3)}
\DoxyCodeLine{518 }
\DoxyCodeLine{519     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}GAMMA\_NIKURASHIN"{}},cs\%Gamma\_lee, \&}
\DoxyCodeLine{520                  \textcolor{stringliteral}{"{}The fraction of the lee wave energy that is dissipated "{}}//\&}
\DoxyCodeLine{521                  \textcolor{stringliteral}{"{}locally with LEE\_WAVE\_DISSIPATION."{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, \&}
\DoxyCodeLine{522                  default=0.3333)}
\DoxyCodeLine{523     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DECAY\_SCALE\_FACTOR\_LEE"{}},cs\%Decay\_scale\_factor\_lee, \&}
\DoxyCodeLine{524                  \textcolor{stringliteral}{"{}Scaling for the vertical decay scaleof the local "{}}//\&}
\DoxyCodeLine{525                  \textcolor{stringliteral}{"{}dissipation of lee waves dissipation."{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, \&}
\DoxyCodeLine{526                  default=1.0)}
\DoxyCodeLine{527   \textcolor{keywordflow}{else}}
\DoxyCodeLine{528     cs\%Decay\_scale\_factor\_lee = -\/9.e99 \textcolor{comment}{! This should never be used if CS\%Lee\_wave\_dissipation = False}}
\DoxyCodeLine{529 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{530 }
\DoxyCodeLine{531   \textcolor{comment}{! Configure CVMix}}
\DoxyCodeLine{532   \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{533 }
\DoxyCodeLine{534     \textcolor{comment}{! Read in CVMix params}}
\DoxyCodeLine{535     \textcolor{comment}{!call openParameterBlock(param\_file,'CVMix\_TIDAL')}}
\DoxyCodeLine{536     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDAL\_MAX\_COEF"{}}, cs\%tidal\_max\_coef, \&}
\DoxyCodeLine{537                    \textcolor{stringliteral}{"{}largest acceptable value for tidal diffusivity"{}}, \&}
\DoxyCodeLine{538                    units=\textcolor{stringliteral}{"{}m\string^2/s"{}}, default=50e-\/4) \textcolor{comment}{! the default is 50e-\/4 in CVMix, 100e-\/4 in POP.}}
\DoxyCodeLine{539     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDAL\_DISS\_LIM\_TC"{}}, cs\%tidal\_diss\_lim\_tc, \&}
\DoxyCodeLine{540                    \textcolor{stringliteral}{"{}Min allowable depth for dissipation for tidal-\/energy-\/constituent data. "{}}//\&}
\DoxyCodeLine{541                    \textcolor{stringliteral}{"{}No dissipation contribution is applied above TIDAL\_DISS\_LIM\_TC."{}}, \&}
\DoxyCodeLine{542                    units=\textcolor{stringliteral}{"{}m"{}}, default=0.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{543     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDAL\_ENERGY\_FILE"{}},tidal\_energy\_file, \&}
\DoxyCodeLine{544                  \textcolor{stringliteral}{"{}The path to the file containing tidal energy "{}}//\&}
\DoxyCodeLine{545                  \textcolor{stringliteral}{"{}dissipation. Used with CVMix tidal mixing schemes."{}}, \&}
\DoxyCodeLine{546                  fail\_if\_missing=.true.)}
\DoxyCodeLine{547     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'MIN\_THICKNESS'}, cs\%min\_thickness, default=0.001, \&}
\DoxyCodeLine{548                    do\_not\_log=.true.)}
\DoxyCodeLine{549     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}PRANDTL\_TIDAL"{}}, prandtl\_tidal, \&}
\DoxyCodeLine{550                    \textcolor{stringliteral}{"{}Prandtl number used by CVMix tidal mixing schemes "{}}//\&}
\DoxyCodeLine{551                    \textcolor{stringliteral}{"{}to convert vertical diffusivities into viscosities."{}}, \&}
\DoxyCodeLine{552                     units=\textcolor{stringliteral}{"{}nondim"{}}, default=1.0, \&}
\DoxyCodeLine{553                    do\_not\_log=.true.)}
\DoxyCodeLine{554     \textcolor{keyword}{call }cvmix\_put(cs\%CVMix\_glb\_params,\textcolor{stringliteral}{'Prandtl'},prandtl\_tidal)}
\DoxyCodeLine{555 }
\DoxyCodeLine{556     tidal\_energy\_file = trim(cs\%inputdir) // trim(tidal\_energy\_file)}
\DoxyCodeLine{557     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDAL\_ENERGY\_TYPE"{}},tidal\_energy\_type, \&}
\DoxyCodeLine{558                  \textcolor{stringliteral}{"{}The type of input tidal energy flux dataset. Valid values are"{}}//\&}
\DoxyCodeLine{559                    \textcolor{stringliteral}{"{}\(\backslash\)t Jayne\(\backslash\)n"{}}//\&}
\DoxyCodeLine{560                    \textcolor{stringliteral}{"{}\(\backslash\)t ER03 \(\backslash\)n"{}},\&}
\DoxyCodeLine{561                  fail\_if\_missing=.true.)}
\DoxyCodeLine{562     \textcolor{comment}{! Check whether tidal energy input format and CVMix tidal mixing scheme are consistent}}
\DoxyCodeLine{563     \textcolor{keywordflow}{if} ( .not. ( \&}
\DoxyCodeLine{564           (uppercase(tidal\_energy\_type(1:4)).eq.\textcolor{stringliteral}{'JAYN'} .and. cs\%CVMix\_tidal\_scheme.eq.simmons).or. \&}
\DoxyCodeLine{565           (uppercase(tidal\_energy\_type(1:4)).eq.\textcolor{stringliteral}{'ER03'} .and. cs\%CVMix\_tidal\_scheme.eq.schmittner) ) )\textcolor{keywordflow}{then}}
\DoxyCodeLine{566         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tidal\_mixing\_init: Tidal energy file type ("{}}//\&}
\DoxyCodeLine{567                       trim(tidal\_energy\_type)//\textcolor{stringliteral}{"{}) is incompatible with CVMix tidal "{}}//\&}
\DoxyCodeLine{568                       \textcolor{stringliteral}{"{} mixing scheme: "{}}//trim(cvmix\_tidal\_scheme\_str) )}
\DoxyCodeLine{569 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{570     cvmix\_tidal\_scheme\_str = lowercase(cvmix\_tidal\_scheme\_str)}
\DoxyCodeLine{571 }
\DoxyCodeLine{572     \textcolor{comment}{! Set up CVMix}}
\DoxyCodeLine{573     \textcolor{keyword}{call }cvmix\_init\_tidal(cvmix\_tidal\_params\_user = cs\%CVMix\_tidal\_params,    \&}
\DoxyCodeLine{574                           mix\_scheme              = cvmix\_tidal\_scheme\_str,   \&}
\DoxyCodeLine{575                           efficiency              = cs\%Mu\_itides,             \&}
\DoxyCodeLine{576                           vertical\_decay\_scale    = cs\%int\_tide\_decay\_scale*us\%Z\_to\_m,  \&}
\DoxyCodeLine{577                           max\_coefficient         = cs\%tidal\_max\_coef,        \&}
\DoxyCodeLine{578                           local\_mixing\_frac       = cs\%Gamma\_itides,          \&}
\DoxyCodeLine{579                           depth\_cutoff            = cs\%min\_zbot\_itides*us\%Z\_to\_m)}
\DoxyCodeLine{580 }
\DoxyCodeLine{581     \textcolor{keyword}{call }read\_tidal\_energy(g, us, tidal\_energy\_type, tidal\_energy\_file, cs)}
\DoxyCodeLine{582 }
\DoxyCodeLine{583     \textcolor{comment}{!call closeParameterBlock(param\_file)}}
\DoxyCodeLine{584 }
\DoxyCodeLine{585 \textcolor{keywordflow}{  endif} \textcolor{comment}{! CVMix on}}
\DoxyCodeLine{586 }
\DoxyCodeLine{587   \textcolor{comment}{! Register Diagnostics fields}}
\DoxyCodeLine{588 }
\DoxyCodeLine{589   \textcolor{keywordflow}{if} (cs\%Int\_tide\_dissipation .or. cs\%Lee\_wave\_dissipation .or. \&}
\DoxyCodeLine{590       cs\%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{591 }
\DoxyCodeLine{592     cs\%id\_Kd\_itidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_itides'},diag\%axesTi,time, \&}
\DoxyCodeLine{593          \textcolor{stringliteral}{'Internal Tide Driven Diffusivity'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{594 }
\DoxyCodeLine{595     \textcolor{keywordflow}{if} (cs\%use\_CVMix\_tidal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{596       cs\%id\_N2\_int = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'N2\_int'},diag\%axesTi,time, \&}
\DoxyCodeLine{597           \textcolor{stringliteral}{'Bouyancy frequency squared, at interfaces'}, \textcolor{stringliteral}{'s-\/2'}, conversion=us\%s\_to\_T**2)\textcolor{comment}{}}
\DoxyCodeLine{598 \textcolor{comment}{      !> TODO: add units}}
\DoxyCodeLine{599       cs\%id\_Simmons\_coeff = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Simmons\_coeff'},diag\%axesT1,time, \&}
\DoxyCodeLine{600            \textcolor{stringliteral}{'time-\/invariant portion of the tidal mixing coefficient using the Simmons'}, \textcolor{stringliteral}{''})}
\DoxyCodeLine{601       cs\%id\_Schmittner\_coeff = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Schmittner\_coeff'},diag\%axesTL,time, \&}
\DoxyCodeLine{602            \textcolor{stringliteral}{'time-\/invariant portion of the tidal mixing coefficient using the Schmittner'}, \textcolor{stringliteral}{''})}
\DoxyCodeLine{603       cs\%id\_tidal\_qe\_md = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'tidal\_qe\_md'},diag\%axesTL,time, \&}
\DoxyCodeLine{604            \textcolor{stringliteral}{'input tidal energy dissipated locally interpolated to model vertical coordinates'}, \textcolor{stringliteral}{''})}
\DoxyCodeLine{605       cs\%id\_vert\_dep = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'vert\_dep'},diag\%axesTi,time, \&}
\DoxyCodeLine{606            \textcolor{stringliteral}{'vertical deposition function needed for Simmons et al tidal  mixing'}, \textcolor{stringliteral}{''})}
\DoxyCodeLine{607 }
\DoxyCodeLine{608     \textcolor{keywordflow}{else}}
\DoxyCodeLine{609       cs\%id\_TKE\_itidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'TKE\_itidal'},diag\%axesT1,time, \&}
\DoxyCodeLine{610           \textcolor{stringliteral}{'Internal Tide Driven Turbulent Kinetic Energy'}, \&}
\DoxyCodeLine{611           \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{612       cs\%id\_Nb = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Nb'},diag\%axesT1,time, \&}
\DoxyCodeLine{613            \textcolor{stringliteral}{'Bottom Buoyancy Frequency'}, \textcolor{stringliteral}{'s-\/1'}, conversion=us\%s\_to\_T)}
\DoxyCodeLine{614 }
\DoxyCodeLine{615       cs\%id\_Kd\_lowmode = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_lowmode'},diag\%axesTi,time, \&}
\DoxyCodeLine{616            \textcolor{stringliteral}{'Internal Tide Driven Diffusivity (from propagating low modes)'}, \&}
\DoxyCodeLine{617            \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{618 }
\DoxyCodeLine{619       cs\%id\_Fl\_itidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Fl\_itides'},diag\%axesTi,time, \&}
\DoxyCodeLine{620           \textcolor{stringliteral}{'Vertical flux of tidal turbulent dissipation'}, \&}
\DoxyCodeLine{621           \textcolor{stringliteral}{'m3 s-\/3'}, conversion=(us\%Z\_to\_m**3*us\%s\_to\_T**3))}
\DoxyCodeLine{622 }
\DoxyCodeLine{623       cs\%id\_Fl\_lowmode = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Fl\_lowmode'},diag\%axesTi,time, \&}
\DoxyCodeLine{624            \textcolor{stringliteral}{'Vertical flux of tidal turbulent dissipation (from propagating low modes)'}, \&}
\DoxyCodeLine{625            \textcolor{stringliteral}{'m3 s-\/3'}, conversion=(us\%Z\_to\_m**3*us\%s\_to\_T**3))}
\DoxyCodeLine{626 }
\DoxyCodeLine{627       cs\%id\_Polzin\_decay\_scale = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Polzin\_decay\_scale'},diag\%axesT1,time, \&}
\DoxyCodeLine{628            \textcolor{stringliteral}{'Vertical decay scale for the tidal turbulent dissipation with Polzin scheme'}, \&}
\DoxyCodeLine{629            \textcolor{stringliteral}{'m'}, conversion=us\%Z\_to\_m)}
\DoxyCodeLine{630 }
\DoxyCodeLine{631       cs\%id\_Polzin\_decay\_scale\_scaled = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \&}
\DoxyCodeLine{632            \textcolor{stringliteral}{'Polzin\_decay\_scale\_scaled'}, diag\%axesT1, time, \&}
\DoxyCodeLine{633            \textcolor{stringliteral}{'Vertical decay scale for the tidal turbulent dissipation with Polzin scheme, '}// \&}
\DoxyCodeLine{634            \textcolor{stringliteral}{'scaled by N2\_bot/N2\_meanz'}, \textcolor{stringliteral}{'m'}, conversion=us\%Z\_to\_m)}
\DoxyCodeLine{635 }
\DoxyCodeLine{636       cs\%id\_N2\_bot = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'N2\_b'},diag\%axesT1,time, \&}
\DoxyCodeLine{637            \textcolor{stringliteral}{'Bottom Buoyancy frequency squared'}, \textcolor{stringliteral}{'s-\/2'}, conversion=us\%s\_to\_T**2)}
\DoxyCodeLine{638 }
\DoxyCodeLine{639       cs\%id\_N2\_meanz = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'N2\_meanz'}, diag\%axesT1, time, \&}
\DoxyCodeLine{640            \textcolor{stringliteral}{'Buoyancy frequency squared averaged over the water column'}, \textcolor{stringliteral}{'s-\/2'}, conversion=us\%s\_to\_T**2)}
\DoxyCodeLine{641 }
\DoxyCodeLine{642       cs\%id\_Kd\_Itidal\_Work = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Itidal\_Work'},diag\%axesTL,time, \&}
\DoxyCodeLine{643            \textcolor{stringliteral}{'Work done by Internal Tide Diapycnal Mixing'}, \&}
\DoxyCodeLine{644            \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{645 }
\DoxyCodeLine{646       cs\%id\_Kd\_Niku\_Work = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Nikurashin\_Work'},diag\%axesTL,time, \&}
\DoxyCodeLine{647            \textcolor{stringliteral}{'Work done by Nikurashin Lee Wave Drag Scheme'}, \&}
\DoxyCodeLine{648            \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{649 }
\DoxyCodeLine{650       cs\%id\_Kd\_Lowmode\_Work = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Lowmode\_Work'},diag\%axesTL,time, \&}
\DoxyCodeLine{651            \textcolor{stringliteral}{'Work done by Internal Tide Diapycnal Mixing (low modes)'}, \&}
\DoxyCodeLine{652            \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{653 }
\DoxyCodeLine{654       \textcolor{keywordflow}{if} (cs\%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{655         cs\%id\_TKE\_leewave = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'TKE\_leewave'},diag\%axesT1,time, \&}
\DoxyCodeLine{656             \textcolor{stringliteral}{'Lee wave Driven Turbulent Kinetic Energy'}, \&}
\DoxyCodeLine{657             \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{658         cs\%id\_Kd\_Niku = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Nikurashin'},diag\%axesTi,time, \&}
\DoxyCodeLine{659             \textcolor{stringliteral}{'Lee Wave Driven Diffusivity'}, \textcolor{stringliteral}{'m2 s-\/1'}, conversion=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{660 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{661 \textcolor{keywordflow}{    endif} \textcolor{comment}{! S\%use\_CVMix\_tidal}}
\DoxyCodeLine{662 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{663 }

\end{DoxyCode}
