\hypertarget{namespacemom__continuity__ppm}{}\section{mom\+\_\+continuity\+\_\+ppm Module Reference}
\label{namespacemom__continuity__ppm}\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}}


\subsection{Detailed Description}
Solve the layer continuity equation using the P\+PM method for layer fluxes. 

This module contains the subroutines that advect layer thickness. The scheme here uses a Piecewise-\/\+Parabolic method with a positive definite limiter. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for \mbox{\hyperlink{namespacemom__continuity__ppm}{mom\+\_\+continuity\+\_\+ppm}}. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}
\begin{DoxyCompactList}\small\item\em A container for loop bounds. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__continuity__ppm_a665851a49a4bde77b4ef5e25332947f6}{continuity\+\_\+ppm}} (u, v, hin, h, uh, vh, dt, G, GV, US, CS, uhbt, vhbt, O\+BC, visc\+\_\+rem\+\_\+u, visc\+\_\+rem\+\_\+v, u\+\_\+cor, v\+\_\+cor, B\+T\+\_\+cont)
\begin{DoxyCompactList}\small\item\em Time steps the layer thicknesses, using a monotonically limit, directionally split P\+PM scheme, based on Lin (1994). \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a5f5d6764ed315043d3b91b209db5c0a0}{zonal\+\_\+mass\+\_\+flux}} (u, h\+\_\+in, uh, dt, G, GV, US, CS, LB, uhbt, O\+BC, visc\+\_\+rem\+\_\+u, u\+\_\+cor, B\+T\+\_\+cont)
\begin{DoxyCompactList}\small\item\em Calculates the mass or volume fluxes through the zonal faces, and other related quantities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a713196d0cfe6cb4cc8a91239a8dba02d}{zonal\+\_\+flux\+\_\+layer}} (u, h, h\+\_\+L, h\+\_\+R, uh, duhdu, visc\+\_\+rem, dt, G, US, j, ish, ieh, do\+\_\+I, vol\+\_\+\+C\+FL, O\+BC)
\begin{DoxyCompactList}\small\item\em Evaluates the zonal mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a9e76825c96ffca1ae0e84469ab46029b}{zonal\+\_\+face\+\_\+thickness}} (u, h, h\+\_\+L, h\+\_\+R, h\+\_\+u, dt, G, US, LB, vol\+\_\+\+C\+FL, marginal, visc\+\_\+rem\+\_\+u, O\+BC)
\begin{DoxyCompactList}\small\item\em Sets the effective interface thickness at each zonal velocity point. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_afad3f82b9824a13d3fe8792496e9b769}{zonal\+\_\+flux\+\_\+adjust}} (u, h\+\_\+in, h\+\_\+L, h\+\_\+R, uhbt, uh\+\_\+tot\+\_\+0, duhdu\+\_\+tot\+\_\+0, du, du\+\_\+max\+\_\+\+C\+FL, du\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, j, ish, ieh, do\+\_\+\+I\+\_\+in, full\+\_\+precision, uh\+\_\+3d, O\+BC)
\begin{DoxyCompactList}\small\item\em Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a30e5aef71acbeef6afe5f6cf1ea30dcc}{set\+\_\+zonal\+\_\+bt\+\_\+cont}} (u, h\+\_\+in, h\+\_\+L, h\+\_\+R, B\+T\+\_\+cont, uh\+\_\+tot\+\_\+0, duhdu\+\_\+tot\+\_\+0, du\+\_\+max\+\_\+\+C\+FL, du\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, visc\+\_\+rem\+\_\+max, j, ish, ieh, do\+\_\+I)
\begin{DoxyCompactList}\small\item\em Sets a structure that describes the zonal barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_ae64c4b7cd1756aa3c121fbcf637d5cae}{meridional\+\_\+mass\+\_\+flux}} (v, h\+\_\+in, vh, dt, G, GV, US, CS, LB, vhbt, O\+BC, visc\+\_\+rem\+\_\+v, v\+\_\+cor, B\+T\+\_\+cont)
\begin{DoxyCompactList}\small\item\em Calculates the mass or volume fluxes through the meridional faces, and other related quantities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_ac00aefda40cb9e22013e99cad342bb63}{merid\+\_\+flux\+\_\+layer}} (v, h, h\+\_\+L, h\+\_\+R, vh, dvhdv, visc\+\_\+rem, dt, G, US, J, ish, ieh, do\+\_\+I, vol\+\_\+\+C\+FL, O\+BC)
\begin{DoxyCompactList}\small\item\em Evaluates the meridional mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a293f7ab5bfd8f3f6a5a50903b05b6411}{merid\+\_\+face\+\_\+thickness}} (v, h, h\+\_\+L, h\+\_\+R, h\+\_\+v, dt, G, US, LB, vol\+\_\+\+C\+FL, marginal, visc\+\_\+rem\+\_\+v, O\+BC)
\begin{DoxyCompactList}\small\item\em Sets the effective interface thickness at each meridional velocity point. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a6deb1b7de418a17cacd60dabc262ba29}{meridional\+\_\+flux\+\_\+adjust}} (v, h\+\_\+in, h\+\_\+L, h\+\_\+R, vhbt, vh\+\_\+tot\+\_\+0, dvhdv\+\_\+tot\+\_\+0, dv, dv\+\_\+max\+\_\+\+C\+FL, dv\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, j, ish, ieh, do\+\_\+\+I\+\_\+in, full\+\_\+precision, vh\+\_\+3d, O\+BC)
\begin{DoxyCompactList}\small\item\em Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a77c6806e82a3634fff7b7480f77c2f02}{set\+\_\+merid\+\_\+bt\+\_\+cont}} (v, h\+\_\+in, h\+\_\+L, h\+\_\+R, B\+T\+\_\+cont, vh\+\_\+tot\+\_\+0, dvhdv\+\_\+tot\+\_\+0, dv\+\_\+max\+\_\+\+C\+FL, dv\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, visc\+\_\+rem\+\_\+max, j, ish, ieh, do\+\_\+I)
\begin{DoxyCompactList}\small\item\em Sets of a structure that describes the meridional barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a9a7eac2a9b17d0e9ee9ca0a27d2f8fb6}{ppm\+\_\+reconstruction\+\_\+x}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, G, LB, h\+\_\+min, monotonic, simple\+\_\+2nd, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge values for P\+PM reconstruction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_af71fa5f7f4b849ec735e2049df2d0693}{ppm\+\_\+reconstruction\+\_\+y}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, G, LB, h\+\_\+min, monotonic, simple\+\_\+2nd, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge values for P\+PM reconstruction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a870edb0c5b2cb0464899430b6651260c}{ppm\+\_\+limit\+\_\+pos}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, h\+\_\+min, G, iis, iie, jis, jie)
\begin{DoxyCompactList}\small\item\em This subroutine limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_ab03786fff2550dd61282356608fc1352}{ppm\+\_\+limit\+\_\+cw84}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, G, iis, iie, jis, jie)
\begin{DoxyCompactList}\small\item\em This subroutine limits the left/right edge values of the P\+PM reconstruction according to the monotonic prescription of Colella and Woodward, 1984. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__continuity__ppm_adf02002cf5951d7610b8643d2d401585}{ratio\+\_\+max}} (a, b, maxrat)
\begin{DoxyCompactList}\small\item\em Return the maximum ratio of a/b or maxrat. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__continuity__ppm_a832c506364bca555b36409a91e0f5906}{continuity\+\_\+ppm\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initializes \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. \end{DoxyCompactList}\item 
integer function, public \mbox{\hyperlink{namespacemom__continuity__ppm_a3e3ee193ee52b65a1413808eea703aee}{continuity\+\_\+ppm\+\_\+stencil}} (CS)
\begin{DoxyCompactList}\small\item\em continuity\+\_\+\+P\+P\+M\+\_\+stencil returns the continuity solver stencil size \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__continuity__ppm_a38ffbfd81e4bef4c789429fb843ed7cc}{continuity\+\_\+ppm\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Destructor for \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__continuity__ppm_a6002197c46343ec4d08cab937db87586}\label{namespacemom__continuity__ppm_a6002197c46343ec4d08cab937db87586}} 
integer \mbox{\hyperlink{namespacemom__continuity__ppm_a6002197c46343ec4d08cab937db87586}{id\+\_\+clock\+\_\+update}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__continuity__ppm_a4b409d0d89dbdbbea05f4a3ade088902}\label{namespacemom__continuity__ppm_a4b409d0d89dbdbbea05f4a3ade088902}} 
integer \mbox{\hyperlink{namespacemom__continuity__ppm_a4b409d0d89dbdbbea05f4a3ade088902}{id\+\_\+clock\+\_\+correct}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a665851a49a4bde77b4ef5e25332947f6}\label{namespacemom__continuity__ppm_a665851a49a4bde77b4ef5e25332947f6}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!continuity\_ppm@{continuity\_ppm}}
\index{continuity\_ppm@{continuity\_ppm}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{continuity\_ppm()}{continuity\_ppm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{hin,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{uh,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{vh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in), optional}]{uhbt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in), optional}]{vhbt,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{visc\+\_\+rem\+\_\+u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{visc\+\_\+rem\+\_\+v,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{u\+\_\+cor,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out), optional}]{v\+\_\+cor,  }\item[{type(bt\+\_\+cont\+\_\+type), optional, pointer}]{B\+T\+\_\+cont }\end{DoxyParamCaption})}



Time steps the layer thicknesses, using a monotonically limit, directionally split P\+PM scheme, based on Lin (1994). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
 & {\em cs} & Module\textquotesingle{}s control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em hin} & Initial layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Final layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em uh} & Zonal volume flux, u$\ast$h$\ast$dy \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em vh} & Meridional volume flux, v$\ast$h$\ast$dx \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\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 uhbt} & The summed volume flux through zonal faces \\
\hline
\mbox{\texttt{ in}}  & {\em vhbt} & The summed volume flux through meridional faces \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+u} & The fraction of zonal momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+v} & The fraction of meridional momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ out}}  & {\em u\+\_\+cor} & The zonal velocities that give uhbt as the depth-\/integrated transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em v\+\_\+cor} & The meridional velocities that give vhbt as the depth-\/integrated transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\end{DoxyParams}


Definition at line 78 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{78   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{   !< The ocean's grid structure.}}
\DoxyCodeLine{79   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< Module's control structure.}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{81                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{   !< Zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{82 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{83                            \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{   !< Meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{84 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{85                            \textcolor{keywordtype}{intent(in)}    :: hin\textcolor{comment}{ !< Initial layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{86 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{87                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Final layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{88 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{89                            \textcolor{keywordtype}{intent(out)}   :: uh\textcolor{comment}{  !< Zonal volume flux, u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{90 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{91                            \textcolor{keywordtype}{intent(out)}   :: vh\textcolor{comment}{  !< Meridional volume flux, v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{92 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{  !< Time increment [T ~> s].}}
\DoxyCodeLine{93   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< Vertical grid structure.}}
\DoxyCodeLine{94   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{95 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{96                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: uhbt\textcolor{comment}{ !< The summed volume flux through zonal faces}}
\DoxyCodeLine{97 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{98 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \&}
\DoxyCodeLine{99                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: vhbt\textcolor{comment}{ !< The summed volume flux through meridional faces}}
\DoxyCodeLine{100 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{101   \textcolor{keywordtype}{type}(ocean\_OBC\_type),  \&}
\DoxyCodeLine{102                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{103 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{104                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_u}
\DoxyCodeLine{105                              \textcolor{comment}{!< The fraction of zonal momentum originally}}
\DoxyCodeLine{106 \textcolor{comment}{                             !! in a layer that remains after a time-step of viscosity, and the}}
\DoxyCodeLine{107 \textcolor{comment}{                             !! fraction of a time-step's worth of a barotropic acceleration that}}
\DoxyCodeLine{108 \textcolor{comment}{                             !! a layer experiences after viscosity is applied.}}
\DoxyCodeLine{109 \textcolor{comment}{                             !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{110 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{111                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_v}
\DoxyCodeLine{112                              \textcolor{comment}{!< The fraction of meridional momentum originally}}
\DoxyCodeLine{113 \textcolor{comment}{                             !! in a layer that remains after a time-step of viscosity, and the}}
\DoxyCodeLine{114 \textcolor{comment}{                             !! fraction of a time-step's worth of a barotropic acceleration that}}
\DoxyCodeLine{115 \textcolor{comment}{                             !! a layer experiences after viscosity is applied.}}
\DoxyCodeLine{116 \textcolor{comment}{                             !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{117 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{118                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: u\_cor}
\DoxyCodeLine{119                              \textcolor{comment}{!< The zonal velocities that give uhbt as the depth-integrated transport [L T-1 ~> m s-1].}}
\DoxyCodeLine{120 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{121                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: v\_cor}
\DoxyCodeLine{122                              \textcolor{comment}{!< The meridional velocities that give vhbt as the depth-integrated}}
\DoxyCodeLine{123 \textcolor{comment}{                             !! transport [L T-1 ~> m s-1].}}
\DoxyCodeLine{124   \textcolor{keywordtype}{type}(BT\_cont\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}  :: BT\_cont\textcolor{comment}{ !< A structure with elements that describe}}
\DoxyCodeLine{125 \textcolor{comment}{                             !!  the effective open face areas as a function of barotropic flow.}}
\DoxyCodeLine{126 }
\DoxyCodeLine{127   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{128 \textcolor{keywordtype}{  real} :: h\_min  \textcolor{comment}{! The minimum layer thickness [H ~> m or kg m-2].  h\_min could be 0.}}
\DoxyCodeLine{129   \textcolor{keywordtype}{type}(loop\_bounds\_type) :: LB}
\DoxyCodeLine{130   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz, stencil}
\DoxyCodeLine{131   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{132 }
\DoxyCodeLine{133   \textcolor{keywordtype}{logical} :: x\_first}
\DoxyCodeLine{134   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{135 }
\DoxyCodeLine{136   h\_min = gv\%Angstrom\_H}
\DoxyCodeLine{137 }
\DoxyCodeLine{138   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{139          \textcolor{stringliteral}{"MOM\_continuity\_PPM: Module must be initialized before it is used."})}
\DoxyCodeLine{140   x\_first = (mod(g\%first\_direction,2) == 0)}
\DoxyCodeLine{141 }
\DoxyCodeLine{142   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u) .neqv. \textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{143       \textcolor{stringliteral}{"MOM\_continuity\_PPM: Either both visc\_rem\_u and visc\_rem\_v or neither"}// \&}
\DoxyCodeLine{144       \textcolor{stringliteral}{" one must be present in call to continuity\_PPM."})}
\DoxyCodeLine{145 }
\DoxyCodeLine{146   stencil = 3 ; \textcolor{keywordflow}{if} (cs\%simple\_2nd) stencil = 2 ; \textcolor{keywordflow}{if} (cs\%upwind\_1st) stencil = 1}
\DoxyCodeLine{147 }
\DoxyCodeLine{148   \textcolor{keywordflow}{if} (x\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{149   \textcolor{comment}{!    First, advect zonally.}}
\DoxyCodeLine{150     lb\%ish = g\%isc ; lb\%ieh = g\%iec}
\DoxyCodeLine{151     lb\%jsh = g\%jsc-stencil ; lb\%jeh = g\%jec+stencil}
\DoxyCodeLine{152     \textcolor{keyword}{call }zonal\_mass\_flux(u, hin, uh, dt, g, gv, us, cs, lb, uhbt, obc, visc\_rem\_u, u\_cor, bt\_cont)}
\DoxyCodeLine{153 }
\DoxyCodeLine{154     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)}
\DoxyCodeLine{155     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{156     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb\%jsh,lb\%jeh ; \textcolor{keywordflow}{do} i=lb\%ish,lb\%ieh}
\DoxyCodeLine{157       h(i,j,k) = hin(i,j,k) - dt * g\%IareaT(i,j) * (uh(i,j,k) - uh(i-1,j,k))}
\DoxyCodeLine{158   \textcolor{comment}{!   Uncomment this line to prevent underflow.}}
\DoxyCodeLine{159   \textcolor{comment}{!   if (h(i,j,k) < h\_min) h(i,j,k) = h\_min}}
\DoxyCodeLine{160 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{161     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)}
\DoxyCodeLine{162 }
\DoxyCodeLine{163     lb\%ish = g\%isc ; lb\%ieh = g\%iec ; lb\%jsh = g\%jsc ; lb\%jeh = g\%jec}
\DoxyCodeLine{164 }
\DoxyCodeLine{165     \textcolor{comment}{!    Now advect meridionally, using the updated thicknesses to determine}}
\DoxyCodeLine{166     \textcolor{comment}{!  the fluxes.}}
\DoxyCodeLine{167     \textcolor{keyword}{call }meridional\_mass\_flux(v, h, vh, dt, g, gv, us, cs, lb, vhbt, obc, visc\_rem\_v, v\_cor, bt\_cont)}
\DoxyCodeLine{168 }
\DoxyCodeLine{169     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)}
\DoxyCodeLine{170     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{171     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb\%jsh,lb\%jeh ; \textcolor{keywordflow}{do} i=lb\%ish,lb\%ieh}
\DoxyCodeLine{172       h(i,j,k) = h(i,j,k) - dt * g\%IareaT(i,j) * (vh(i,j,k) - vh(i,j-1,k))}
\DoxyCodeLine{173   \textcolor{comment}{!   This line prevents underflow.}}
\DoxyCodeLine{174       \textcolor{keywordflow}{if} (h(i,j,k) < h\_min) h(i,j,k) = h\_min}
\DoxyCodeLine{175 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{176     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)}
\DoxyCodeLine{177 }
\DoxyCodeLine{178   \textcolor{keywordflow}{else}  \textcolor{comment}{! .not. x\_first}}
\DoxyCodeLine{179   \textcolor{comment}{!    First, advect meridionally, so set the loop bounds accordingly.}}
\DoxyCodeLine{180     lb\%ish = g\%isc-stencil ; lb\%ieh = g\%iec+stencil}
\DoxyCodeLine{181     lb\%jsh = g\%jsc ; lb\%jeh = g\%jec}
\DoxyCodeLine{182 }
\DoxyCodeLine{183     \textcolor{keyword}{call }meridional\_mass\_flux(v, hin, vh, dt, g, gv, us, cs, lb, vhbt, obc, visc\_rem\_v, v\_cor, bt\_cont)}
\DoxyCodeLine{184 }
\DoxyCodeLine{185     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)}
\DoxyCodeLine{186     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{187     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb\%jsh,lb\%jeh ; \textcolor{keywordflow}{do} i=lb\%ish,lb\%ieh}
\DoxyCodeLine{188       h(i,j,k) = hin(i,j,k) - dt * g\%IareaT(i,j) * (vh(i,j,k) - vh(i,j-1,k))}
\DoxyCodeLine{189 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{190     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)}
\DoxyCodeLine{191 }
\DoxyCodeLine{192   \textcolor{comment}{!    Now advect zonally, using the updated thicknesses to determine}}
\DoxyCodeLine{193   \textcolor{comment}{!  the fluxes.}}
\DoxyCodeLine{194     lb\%ish = g\%isc ; lb\%ieh = g\%iec ; lb\%jsh = g\%jsc ; lb\%jeh = g\%jec}
\DoxyCodeLine{195     \textcolor{keyword}{call }zonal\_mass\_flux(u, h, uh, dt, g, gv, us, cs, lb, uhbt, obc, visc\_rem\_u, u\_cor, bt\_cont)}
\DoxyCodeLine{196 }
\DoxyCodeLine{197     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)}
\DoxyCodeLine{198     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{199     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb\%jsh,lb\%jeh ; \textcolor{keywordflow}{do} i=lb\%ish,lb\%ieh}
\DoxyCodeLine{200       h(i,j,k) = h(i,j,k) - dt * g\%IareaT(i,j) * (uh(i,j,k) - uh(i-1,j,k))}
\DoxyCodeLine{201       \textcolor{comment}{! This line prevents underflow.}}
\DoxyCodeLine{202       \textcolor{keywordflow}{if} (h(i,j,k) < h\_min) h(i,j,k) = h\_min}
\DoxyCodeLine{203 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{204     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)}
\DoxyCodeLine{205 }
\DoxyCodeLine{206 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{207 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a38ffbfd81e4bef4c789429fb843ed7cc}\label{namespacemom__continuity__ppm_a38ffbfd81e4bef4c789429fb843ed7cc}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!continuity\_ppm\_end@{continuity\_ppm\_end}}
\index{continuity\_ppm\_end@{continuity\_ppm\_end}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{continuity\_ppm\_end()}{continuity\_ppm\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Destructor for \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. 


\begin{DoxyParams}{Parameters}
{\em cs} & Module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}


Definition at line 2335 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2335   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< Module's control structure.}}
\DoxyCodeLine{2336   \textcolor{keyword}{deallocate}(cs)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a832c506364bca555b36409a91e0f5906}\label{namespacemom__continuity__ppm_a832c506364bca555b36409a91e0f5906}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!continuity\_ppm\_init@{continuity\_ppm\_init}}
\index{continuity\_ppm\_init@{continuity\_ppm\_init}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{continuity\_ppm\_init()}{continuity\_ppm\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initializes \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s 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} & A structure indicating the open file to parse for model parameter values. \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & A structure that is used to regulate diagnostic output. \\
\hline
 & {\em cs} & Module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}
This include declares and sets the variable \char`\"{}version\char`\"{}. 

Definition at line 2230 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2230   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< The current model time.}}
\DoxyCodeLine{2231   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{2232   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Vertical grid structure.}}
\DoxyCodeLine{2233   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{2234   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure indicating}}
\DoxyCodeLine{2235 \textcolor{comment}{                  !! the open file to parse for model parameter values.}}
\DoxyCodeLine{2236   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< A structure that is used to}}
\DoxyCodeLine{2237 \textcolor{comment}{                  !! regulate diagnostic output.}}
\DoxyCodeLine{2238   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< Module's control structure.}}
\DoxyCodeLine{2239 \textcolor{comment}{!> This include declares and sets the variable "version".}}
\DoxyCodeLine{2240 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{2241 \textcolor{preprocessor}{}\textcolor{keywordtype}{  real} :: tol\_eta\_m  \textcolor{comment}{! An unscaled version of tol\_eta [m].}}
\DoxyCodeLine{2242   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_continuity\_PPM"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{2243 }
\DoxyCodeLine{2244   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2245     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"continuity\_PPM\_init called with associated control structure."})}
\DoxyCodeLine{2246     \textcolor{keywordflow}{return}}
\DoxyCodeLine{2247 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2248   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{2249 }
\DoxyCodeLine{2250 \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{2251   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{2252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MONOTONIC\_CONTINUITY"}, cs\%monotonic, \&}
\DoxyCodeLine{2253                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM uses the Colella and Woodward "}//\&}
\DoxyCodeLine{2254                  \textcolor{stringliteral}{"monotonic limiter.  The default (false) is to use a "}//\&}
\DoxyCodeLine{2255                  \textcolor{stringliteral}{"simple positive definite limiter."}, default=.false.)}
\DoxyCodeLine{2256   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SIMPLE\_2ND\_PPM\_CONTINUITY"}, cs\%simple\_2nd, \&}
\DoxyCodeLine{2257                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM uses a simple 2nd order "}//\&}
\DoxyCodeLine{2258                  \textcolor{stringliteral}{"(arithmetic mean) interpolation of the edge values. "}//\&}
\DoxyCodeLine{2259                  \textcolor{stringliteral}{"This may give better PV conservation properties. While "}//\&}
\DoxyCodeLine{2260                  \textcolor{stringliteral}{"it formally reduces the accuracy of the continuity "}//\&}
\DoxyCodeLine{2261                  \textcolor{stringliteral}{"solver itself in the strongly advective limit, it does "}//\&}
\DoxyCodeLine{2262                  \textcolor{stringliteral}{"not reduce the overall order of accuracy of the dynamic "}//\&}
\DoxyCodeLine{2263                  \textcolor{stringliteral}{"core."}, default=.false.)}
\DoxyCodeLine{2264   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"UPWIND\_1ST\_CONTINUITY"}, cs\%upwind\_1st, \&}
\DoxyCodeLine{2265                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM becomes a 1st-order upwind "}//\&}
\DoxyCodeLine{2266                  \textcolor{stringliteral}{"continuity solver.  This scheme is highly diffusive "}//\&}
\DoxyCodeLine{2267                  \textcolor{stringliteral}{"but may be useful for debugging or in single-column "}//\&}
\DoxyCodeLine{2268                  \textcolor{stringliteral}{"mode where its minimal stencil is useful."}, default=.false.)}
\DoxyCodeLine{2269   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ETA\_TOLERANCE"}, cs\%tol\_eta, \&}
\DoxyCodeLine{2270                  \textcolor{stringliteral}{"The tolerance for the differences between the "}//\&}
\DoxyCodeLine{2271                  \textcolor{stringliteral}{"barotropic and baroclinic estimates of the sea surface "}//\&}
\DoxyCodeLine{2272                  \textcolor{stringliteral}{"height due to the fluxes through each face.  The total "}//\&}
\DoxyCodeLine{2273                  \textcolor{stringliteral}{"tolerance for SSH is 4 times this value.  The default "}//\&}
\DoxyCodeLine{2274                  \textcolor{stringliteral}{"is 0.5*NK*ANGSTROM, and this should not be set less "}//\&}
\DoxyCodeLine{2275                  \textcolor{stringliteral}{"than about 10\string^-15*MAXIMUM\_DEPTH."}, units=\textcolor{stringliteral}{"m"}, scale=gv\%m\_to\_H, \&}
\DoxyCodeLine{2276                  default=0.5*g\%ke*gv\%Angstrom\_m, unscaled=tol\_eta\_m)}
\DoxyCodeLine{2277 }
\DoxyCodeLine{2278   \textcolor{comment}{!\#\#\# ETA\_TOLERANCE\_AUX can be obsoleted.}}
\DoxyCodeLine{2279   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ETA\_TOLERANCE\_AUX"}, cs\%tol\_eta\_aux, \&}
\DoxyCodeLine{2280                  \textcolor{stringliteral}{"The tolerance for free-surface height discrepancies "}//\&}
\DoxyCodeLine{2281                  \textcolor{stringliteral}{"between the barotropic solution and the sum of the "}//\&}
\DoxyCodeLine{2282                  \textcolor{stringliteral}{"layer thicknesses when calculating the auxiliary "}//\&}
\DoxyCodeLine{2283                  \textcolor{stringliteral}{"corrected velocities. By default, this is the same as "}//\&}
\DoxyCodeLine{2284                  \textcolor{stringliteral}{"ETA\_TOLERANCE, but can be made larger for efficiency."}, \&}
\DoxyCodeLine{2285                  units=\textcolor{stringliteral}{"m"}, default=tol\_eta\_m, scale=gv\%m\_to\_H)}
\DoxyCodeLine{2286   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VELOCITY\_TOLERANCE"}, cs\%tol\_vel, \&}
\DoxyCodeLine{2287                  \textcolor{stringliteral}{"The tolerance for barotropic velocity discrepancies "}//\&}
\DoxyCodeLine{2288                  \textcolor{stringliteral}{"between the barotropic solution and  the sum of the "}//\&}
\DoxyCodeLine{2289                  \textcolor{stringliteral}{"layer thicknesses."}, units=\textcolor{stringliteral}{"m s-1"}, default=3.0e8, scale=us\%m\_s\_to\_L\_T)}
\DoxyCodeLine{2290                  \textcolor{comment}{! The speed of light is the default.}}
\DoxyCodeLine{2291 }
\DoxyCodeLine{2292   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_AGGRESS\_ADJUST"}, cs\%aggress\_adjust,\&}
\DoxyCodeLine{2293                  \textcolor{stringliteral}{"If true, allow the adjusted velocities to have a "}//\&}
\DoxyCodeLine{2294                  \textcolor{stringliteral}{"relative CFL change up to 0.5."}, default=.false.)}
\DoxyCodeLine{2295   cs\%vol\_CFL = cs\%aggress\_adjust}
\DoxyCodeLine{2296   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_VOLUME\_BASED\_CFL"}, cs\%vol\_CFL, \&}
\DoxyCodeLine{2297                  \textcolor{stringliteral}{"If true, use the ratio of the open face lengths to the "}//\&}
\DoxyCodeLine{2298                  \textcolor{stringliteral}{"tracer cell areas when estimating CFL numbers.  The "}//\&}
\DoxyCodeLine{2299                  \textcolor{stringliteral}{"default is set by CONT\_PPM\_AGGRESS\_ADJUST."}, \&}
\DoxyCodeLine{2300                  default=cs\%aggress\_adjust, do\_not\_read=cs\%aggress\_adjust)}
\DoxyCodeLine{2301   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONTINUITY\_CFL\_LIMIT"}, cs\%CFL\_limit\_adjust, \&}
\DoxyCodeLine{2302                  \textcolor{stringliteral}{"The maximum CFL of the adjusted velocities."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{2303                  default=0.5)}
\DoxyCodeLine{2304   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_BETTER\_ITER"}, cs\%better\_iter, \&}
\DoxyCodeLine{2305                  \textcolor{stringliteral}{"If true, stop corrective iterations using a velocity "}//\&}
\DoxyCodeLine{2306                  \textcolor{stringliteral}{"based criterion and only stop if the iteration is "}//\&}
\DoxyCodeLine{2307                  \textcolor{stringliteral}{"better than all predecessors."}, default=.true.)}
\DoxyCodeLine{2308   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_USE\_VISC\_REM\_MAX"}, \&}
\DoxyCodeLine{2309                                  cs\%use\_visc\_rem\_max, \&}
\DoxyCodeLine{2310                  \textcolor{stringliteral}{"If true, use more appropriate limiting bounds for "}//\&}
\DoxyCodeLine{2311                  \textcolor{stringliteral}{"corrections in strongly viscous columns."}, default=.true.)}
\DoxyCodeLine{2312   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_MARGINAL\_FACE\_AREAS"}, cs\%marginal\_faces, \&}
\DoxyCodeLine{2313                  \textcolor{stringliteral}{"If true, use the marginal face areas from the continuity "}//\&}
\DoxyCodeLine{2314                  \textcolor{stringliteral}{"solver for use as the weights in the barotropic solver. "}//\&}
\DoxyCodeLine{2315                  \textcolor{stringliteral}{"Otherwise use the transport averaged areas."}, default=.true.)}
\DoxyCodeLine{2316 }
\DoxyCodeLine{2317   cs\%diag => diag}
\DoxyCodeLine{2318 }
\DoxyCodeLine{2319   id\_clock\_update = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity update)'}, grain=clock\_routine)}
\DoxyCodeLine{2320   id\_clock\_correct = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity correction)'}, grain=clock\_routine)}
\DoxyCodeLine{2321 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a3e3ee193ee52b65a1413808eea703aee}\label{namespacemom__continuity__ppm_a3e3ee193ee52b65a1413808eea703aee}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!continuity\_ppm\_stencil@{continuity\_ppm\_stencil}}
\index{continuity\_ppm\_stencil@{continuity\_ppm\_stencil}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{continuity\_ppm\_stencil()}{continuity\_ppm\_stencil()}}
{\footnotesize\ttfamily integer function, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm\+\_\+stencil (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



continuity\+\_\+\+P\+P\+M\+\_\+stencil returns the continuity solver stencil size 


\begin{DoxyParams}{Parameters}
{\em cs} & Module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The continuity solver stencil size with the current settings. 
\end{DoxyReturn}


Definition at line 2326 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2326   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< Module's control structure.}}
\DoxyCodeLine{2327   \textcolor{keywordtype}{integer} ::  stencil\textcolor{comment}{ !< The continuity solver stencil size with the current settings.}}
\DoxyCodeLine{2328 }
\DoxyCodeLine{2329   stencil = 3 ; \textcolor{keywordflow}{if} (cs\%simple\_2nd) stencil = 2 ; \textcolor{keywordflow}{if} (cs\%upwind\_1st) stencil = 1}
\DoxyCodeLine{2330 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a293f7ab5bfd8f3f6a5a50903b05b6411}\label{namespacemom__continuity__ppm_a293f7ab5bfd8f3f6a5a50903b05b6411}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!merid\_face\_thickness@{merid\_face\_thickness}}
\index{merid\_face\_thickness@{merid\_face\_thickness}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{merid\_face\_thickness()}{merid\_face\_thickness()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::merid\+\_\+face\+\_\+thickness (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h\+\_\+v,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{logical, intent(in)}]{marginal,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{visc\+\_\+rem\+\_\+v,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the effective interface thickness at each meridional velocity point. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness used to calculate fluxes, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+v} & Thickness at meridional faces, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & Loop bounds structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
\mbox{\texttt{ in}}  & {\em marginal} & If true, report the marginal face thicknesses; otherwise report transport-\/averaged thicknesses. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+v} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1428 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1428   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{1429 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1430 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thickness used to calculate fluxes,}}
\DoxyCodeLine{1431 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1432 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}}
\DoxyCodeLine{1433 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1434 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction,}}
\DoxyCodeLine{1435 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1436 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\_v\textcolor{comment}{  !< Thickness at meridional faces,}}
\DoxyCodeLine{1437 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1438 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{1439   \textcolor{keywordtype}{type}(loop\_bounds\_type),                    \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}}
\DoxyCodeLine{1440   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1441   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{ !< If true, rescale the ratio}}
\DoxyCodeLine{1442 \textcolor{comment}{                          !! of face areas to the cell areas when estimating the CFL number.}}
\DoxyCodeLine{1443   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: marginal\textcolor{comment}{ !< If true, report the marginal}}
\DoxyCodeLine{1444 \textcolor{comment}{                          !! face thicknesses; otherwise report transport-averaged thicknesses.}}
\DoxyCodeLine{1445 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: visc\_rem\_v\textcolor{comment}{ !< Both the fraction}}
\DoxyCodeLine{1446 \textcolor{comment}{                          !! of the momentum originally in a layer that remains after a time-step of}}
\DoxyCodeLine{1447 \textcolor{comment}{                          !! viscosity, and the fraction of a time-step's worth of a barotropic}}
\DoxyCodeLine{1448 \textcolor{comment}{                          !! acceleration that a layer experiences after viscosity is applied.}}
\DoxyCodeLine{1449 \textcolor{comment}{                          !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{1450   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{1451 }
\DoxyCodeLine{1452   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1453 \textcolor{keywordtype}{  real} :: CFL \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}}
\DoxyCodeLine{1454 \textcolor{keywordtype}{  real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}}
\DoxyCodeLine{1455                  \textcolor{comment}{! with the same units as h [H ~> m or kg m-2] .}}
\DoxyCodeLine{1456 \textcolor{keywordtype}{  real} :: h\_avg  \textcolor{comment}{! The average thickness of a flux [H ~> m or kg m-2].}}
\DoxyCodeLine{1457 \textcolor{keywordtype}{  real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}}
\DoxyCodeLine{1458   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{1459   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, n, nz}
\DoxyCodeLine{1460   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh ; nz = g\%ke}
\DoxyCodeLine{1461 }
\DoxyCodeLine{1462   \textcolor{comment}{!\$OMP parallel do default(shared) private(CFL,curv\_3,h\_marg,h\_avg)}}
\DoxyCodeLine{1463   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1464     \textcolor{keywordflow}{if} (v(i,j,k) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1465       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (v(i,j,k) * dt) * (g\%dx\_Cv(i,j) * g\%IareaT(i,j))}
\DoxyCodeLine{1466       \textcolor{keywordflow}{else} ; cfl = v(i,j,k) * dt * g\%IdyT(i,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1467       curv\_3 = h\_l(i,j,k) + h\_r(i,j,k) - 2.0*h(i,j,k)}
\DoxyCodeLine{1468       h\_avg = h\_r(i,j,k) + cfl * (0.5*(h\_l(i,j,k) - h\_r(i,j,k)) + curv\_3*(cfl - 1.5))}
\DoxyCodeLine{1469       h\_marg = h\_r(i,j,k) + cfl * ((h\_l(i,j,k) - h\_r(i,j,k)) + \&}
\DoxyCodeLine{1470                                 3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{1471     \textcolor{keywordflow}{elseif} (v(i,j,k) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1472       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-v(i,j,k)*dt) * (g\%dx\_Cv(i,j) * g\%IareaT(i,j+1))}
\DoxyCodeLine{1473       \textcolor{keywordflow}{else} ; cfl = -v(i,j,k) * dt * g\%IdyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1474       curv\_3 = h\_l(i,j+1,k) + h\_r(i,j+1,k) - 2.0*h(i,j+1,k)}
\DoxyCodeLine{1475       h\_avg = h\_l(i,j+1,k) + cfl * (0.5*(h\_r(i,j+1,k)-h\_l(i,j+1,k)) + curv\_3*(cfl - 1.5))}
\DoxyCodeLine{1476       h\_marg = h\_l(i,j+1,k) + cfl * ((h\_r(i,j+1,k)-h\_l(i,j+1,k)) + \&}
\DoxyCodeLine{1477                                     3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{1478     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1479       h\_avg = 0.5 * (h\_l(i,j+1,k) + h\_r(i,j,k))}
\DoxyCodeLine{1480       \textcolor{comment}{!   The choice to use the arithmetic mean here is somewhat arbitrariy, but}}
\DoxyCodeLine{1481       \textcolor{comment}{! it should be noted that h\_L(i+1,j,k) and h\_R(i,j,k) are usually the same.}}
\DoxyCodeLine{1482       h\_marg = 0.5 * (h\_l(i,j+1,k) + h\_r(i,j,k))}
\DoxyCodeLine{1483  \textcolor{comment}{!    h\_marg = (2.0 * h\_L(i,j+1,k) * h\_R(i,j,k)) / \&}}
\DoxyCodeLine{1484  \textcolor{comment}{!             (h\_L(i,j+1,k) + h\_R(i,j,k) + GV\%H\_subroundoff)}}
\DoxyCodeLine{1485 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1486 }
\DoxyCodeLine{1487     \textcolor{keywordflow}{if} (marginal) \textcolor{keywordflow}{then} ; h\_v(i,j,k) = h\_marg}
\DoxyCodeLine{1488     \textcolor{keywordflow}{else} ; h\_v(i,j,k) = h\_avg ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1489 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1490 }
\DoxyCodeLine{1491   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1492     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1493     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1494       h\_v(i,j,k) = h\_v(i,j,k) * visc\_rem\_v(i,j,k)}
\DoxyCodeLine{1495 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1496 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1497 }
\DoxyCodeLine{1498   local\_open\_bc = .false.}
\DoxyCodeLine{1499   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1500     local\_open\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{1501 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1502   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1503     \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{1504       \textcolor{keywordflow}{if} (obc\%segment(n)\%open .and. obc\%segment(n)\%is\_N\_or\_S) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1505         j = obc\%segment(n)\%HI\%JsdB}
\DoxyCodeLine{1506         \textcolor{keywordflow}{if} (obc\%segment(n)\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1507           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1508             \textcolor{keywordflow}{do} i = obc\%segment(n)\%HI\%isd, obc\%segment(n)\%HI\%ied}
\DoxyCodeLine{1509               h\_v(i,j,k) = h(i,j,k) * visc\_rem\_v(i,j,k)}
\DoxyCodeLine{1510 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{1511 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1512             \textcolor{keywordflow}{do} i = obc\%segment(n)\%HI\%isd, obc\%segment(n)\%HI\%ied}
\DoxyCodeLine{1513               h\_v(i,j,k) = h(i,j,k)}
\DoxyCodeLine{1514 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{1515 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1516         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1517           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1518             \textcolor{keywordflow}{do} i = obc\%segment(n)\%HI\%isd, obc\%segment(n)\%HI\%ied}
\DoxyCodeLine{1519               h\_v(i,j,k) = h(i,j+1,k) * visc\_rem\_v(i,j,k)}
\DoxyCodeLine{1520 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{1521 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1522             \textcolor{keywordflow}{do} i = obc\%segment(n)\%HI\%isd, obc\%segment(n)\%HI\%ied}
\DoxyCodeLine{1523               h\_v(i,j,k) = h(i,j+1,k)}
\DoxyCodeLine{1524 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{1525 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1526 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1527 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1528 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1529 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1530 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_ac00aefda40cb9e22013e99cad342bb63}\label{namespacemom__continuity__ppm_ac00aefda40cb9e22013e99cad342bb63}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!merid\_flux\_layer@{merid\_flux\_layer}}
\index{merid\_flux\_layer@{merid\_flux\_layer}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{merid\_flux\_layer()}{merid\_flux\_layer()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::merid\+\_\+flux\+\_\+layer (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+R,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(inout)}]{vh,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(inout)}]{dvhdv,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{visc\+\_\+rem,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{J,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension( g \%isd\+: g \%ied), intent(in)}]{do\+\_\+I,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the meridional mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness used to calculate fluxes, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em vh} & Meridional mass or volume transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em dvhdv} & Partial derivative of vh with v \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em j} & Spatial index. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & Start of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & End of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+i} & Which i values to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1342 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1342   \textcolor{keywordtype}{type}(ocean\_grid\_type),        \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{        !< Ocean's grid structure.}}
\DoxyCodeLine{1343 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{        !< Meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1344 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}}
\DoxyCodeLine{1345 \textcolor{comment}{         !! momentum originally in a layer that remains after a time-step}}
\DoxyCodeLine{1346 \textcolor{comment}{         !! of viscosity, and the fraction of a time-step's worth of a barotropic}}
\DoxyCodeLine{1347 \textcolor{comment}{         !! acceleration that a layer experiences after viscosity is applied.}}
\DoxyCodeLine{1348 \textcolor{comment}{         !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{1349 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{      !< Layer thickness used to calculate fluxes,}}
\DoxyCodeLine{1350 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1351 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\_L\textcolor{comment}{    !< Left thickness in the reconstruction}}
\DoxyCodeLine{1352 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1353 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\_R\textcolor{comment}{    !< Right thickness in the reconstruction}}
\DoxyCodeLine{1354 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1355 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{       !< Meridional mass or volume transport}}
\DoxyCodeLine{1356 \textcolor{comment}{                                                          !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1357 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(inout)} :: dvhdv\textcolor{comment}{    !< Partial derivative of vh with v}}
\DoxyCodeLine{1358 \textcolor{comment}{                                                          !! [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1359 \textcolor{keywordtype}{  real},                         \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{       !< Time increment [T ~> s].}}
\DoxyCodeLine{1360   \textcolor{keywordtype}{type}(unit\_scale\_type),        \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{       !< A dimensional unit scaling type}}
\DoxyCodeLine{1361   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}}
\DoxyCodeLine{1362   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}}
\DoxyCodeLine{1363   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}}
\DoxyCodeLine{1364   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< Which i values to work on.}}
\DoxyCodeLine{1365   \textcolor{keywordtype}{logical},                      \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{  !< If true, rescale the}}
\DoxyCodeLine{1366 \textcolor{comment}{         !! ratio of face areas to the cell areas when estimating the CFL number.}}
\DoxyCodeLine{1367   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{1368   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1369 \textcolor{keywordtype}{  real} :: CFL \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}}
\DoxyCodeLine{1370 \textcolor{keywordtype}{  real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}}
\DoxyCodeLine{1371                  \textcolor{comment}{! with the same units as h, i.e. [H ~> m or kg m-2].}}
\DoxyCodeLine{1372 \textcolor{keywordtype}{  real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}}
\DoxyCodeLine{1373   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{1374   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{1375   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{1376 }
\DoxyCodeLine{1377   local\_open\_bc = .false.}
\DoxyCodeLine{1378   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1379     local\_open\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{1380 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1381 }
\DoxyCodeLine{1382   \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1383     \textcolor{keywordflow}{if} (v(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1384       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (v(i) * dt) * (g\%dx\_Cv(i,j) * g\%IareaT(i,j))}
\DoxyCodeLine{1385       \textcolor{keywordflow}{else} ; cfl = v(i) * dt * g\%IdyT(i,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1386       curv\_3 = h\_l(i,j) + h\_r(i,j) - 2.0*h(i,j)}
\DoxyCodeLine{1387       vh(i) = g\%dx\_Cv(i,j) * v(i) * ( h\_r(i,j) + cfl * \&}
\DoxyCodeLine{1388           (0.5*(h\_l(i,j) - h\_r(i,j)) + curv\_3*(cfl - 1.5)) )}
\DoxyCodeLine{1389       h\_marg = h\_r(i,j) + cfl * ((h\_l(i,j) - h\_r(i,j)) + \&}
\DoxyCodeLine{1390                                   3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{1391     \textcolor{keywordflow}{elseif} (v(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1392       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-v(i) * dt) * (g\%dx\_Cv(i,j) * g\%IareaT(i,j+1))}
\DoxyCodeLine{1393       \textcolor{keywordflow}{else} ; cfl = -v(i) * dt * g\%IdyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1394       curv\_3 = h\_l(i,j+1) + h\_r(i,j+1) - 2.0*h(i,j+1)}
\DoxyCodeLine{1395       vh(i) = g\%dx\_Cv(i,j) * v(i) * ( h\_l(i,j+1) + cfl * \&}
\DoxyCodeLine{1396           (0.5*(h\_r(i,j+1)-h\_l(i,j+1)) + curv\_3*(cfl - 1.5)) )}
\DoxyCodeLine{1397       h\_marg = h\_l(i,j+1) + cfl * ((h\_r(i,j+1)-h\_l(i,j+1)) + \&}
\DoxyCodeLine{1398                                     3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{1399     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1400       vh(i) = 0.0}
\DoxyCodeLine{1401       h\_marg = 0.5 * (h\_l(i,j+1) + h\_r(i,j))}
\DoxyCodeLine{1402 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1403     dvhdv(i) = g\%dx\_Cv(i,j) * h\_marg * visc\_rem(i)}
\DoxyCodeLine{1404 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1405 }
\DoxyCodeLine{1406   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1407     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1408       l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{1409 }
\DoxyCodeLine{1410       \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1411         \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1412           \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1413             vh(i) = g\%dx\_Cv(i,j) * v(i) * h(i,j)}
\DoxyCodeLine{1414             dvhdv(i) = g\%dx\_Cv(i,j) * h(i,j) * visc\_rem(i)}
\DoxyCodeLine{1415           \textcolor{keywordflow}{else}}
\DoxyCodeLine{1416             vh(i) = g\%dx\_Cv(i,j) * v(i) * h(i,j+1)}
\DoxyCodeLine{1417             dvhdv(i) = g\%dx\_Cv(i,j) * h(i,j+1) * visc\_rem(i)}
\DoxyCodeLine{1418 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1419 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1420 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1421 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1422 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a6deb1b7de418a17cacd60dabc262ba29}\label{namespacemom__continuity__ppm_a6deb1b7de418a17cacd60dabc262ba29}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!meridional\_flux\_adjust@{meridional\_flux\_adjust}}
\index{meridional\_flux\_adjust@{meridional\_flux\_adjust}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{meridional\_flux\_adjust()}{meridional\_flux\_adjust()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::meridional\+\_\+flux\+\_\+adjust (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in), optional}]{vhbt,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{vh\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{dvhdv\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(out)}]{dv,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{dv\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{dv\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{visc\+\_\+rem,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension(szi\+\_\+(g)), intent(in)}]{do\+\_\+\+I\+\_\+in,  }\item[{logical, intent(in), optional}]{full\+\_\+precision,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout), optional}]{vh\+\_\+3d,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em vhbt} & The summed volume flux through meridional faces \\
\hline
\mbox{\texttt{ in}}  & {\em dv\+\_\+max\+\_\+cfl} & Maximum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dv\+\_\+min\+\_\+cfl} & Minimum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dvhdv\+\_\+tot\+\_\+0} & The partial derivative of dv\+\_\+err with dv at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em dv} & The barotropic velocity adjustment \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\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 j} & Spatial index. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & Start of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & End of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+i\+\_\+in} & A flag indicating which I values to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em full\+\_\+precision} & A flag indicating how carefully to iterate. The default is .true. (more accurate). \\
\hline
\mbox{\texttt{ in,out}}  & {\em vh\+\_\+3d} & Volume flux through meridional \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1537 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1537   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{   !< Ocean's grid structure.}}
\DoxyCodeLine{1538 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1539                          \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1540 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1541                          \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to calculate fluxes [H ~> m or kg m-2].}}
\DoxyCodeLine{1542 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},\&}
\DoxyCodeLine{1543                          \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{1544 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1545                          \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{1546 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: visc\_rem}
\DoxyCodeLine{1547                              \textcolor{comment}{!< Both the fraction of the momentum originally}}
\DoxyCodeLine{1548 \textcolor{comment}{                             !! in a layer that remains after a time-step of viscosity, and the}}
\DoxyCodeLine{1549 \textcolor{comment}{                             !! fraction of a time-step's worth of a barotropic acceleration that}}
\DoxyCodeLine{1550 \textcolor{comment}{                             !! a layer experiences after viscosity is applied. Non-dimensional}}
\DoxyCodeLine{1551 \textcolor{comment}{                             !! between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{1552 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \&}
\DoxyCodeLine{1553                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: vhbt\textcolor{comment}{ !< The summed volume flux through meridional faces}}
\DoxyCodeLine{1554 \textcolor{comment}{                                                  !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1555 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: dv\_max\_CFL\textcolor{comment}{ !< Maximum acceptable value of dv [L T-1 ~> m s-1].}}
\DoxyCodeLine{1556 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: dv\_min\_CFL\textcolor{comment}{ !< Minimum acceptable value of dv [L T-1 ~> m s-1].}}
\DoxyCodeLine{1557 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: vh\_tot\_0\textcolor{comment}{   !< The summed transport with 0 adjustment}}
\DoxyCodeLine{1558 \textcolor{comment}{                                                        !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1559 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: dvhdv\_tot\_0\textcolor{comment}{ !< The partial derivative of dv\_err with}}
\DoxyCodeLine{1560 \textcolor{comment}{                                                         !! dv at 0 adjustment [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1561 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(out)}   :: dv\textcolor{comment}{   !< The barotropic velocity adjustment [L T-1 ~> m s-1].}}
\DoxyCodeLine{1562 \textcolor{keywordtype}{  real},                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{1563   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1564   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}}
\DoxyCodeLine{1565   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{    !< Spatial index.}}
\DoxyCodeLine{1566   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{  !< Start of index range.}}
\DoxyCodeLine{1567   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{  !< End of index range.}}
\DoxyCodeLine{1568   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \&}
\DoxyCodeLine{1569                             \textcolor{keywordtype}{intent(in)}    :: do\_I\_in\textcolor{comment}{  !< A flag indicating which I values to work on.}}
\DoxyCodeLine{1570   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: full\_precision\textcolor{comment}{ !< A flag indicating how carefully to}}
\DoxyCodeLine{1571 \textcolor{comment}{                             !! iterate.  The default is .true. (more accurate).}}
\DoxyCodeLine{1572 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1573                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: vh\_3d\textcolor{comment}{ !< Volume flux through meridional}}
\DoxyCodeLine{1574 \textcolor{comment}{                             !! faces = v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1575   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{1576   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1577 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{1578     vh\_aux, \&  \textcolor{comment}{! An auxiliary meridional volume flux [H L2 s-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1579     dvhdv      \textcolor{comment}{! Partial derivative of vh with v [H m ~> m2 or kg m-1].}}
\DoxyCodeLine{1580 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{1581     vh\_err, \&  \textcolor{comment}{! Difference between vhbt and the summed vh [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1582     vh\_err\_best, \& \textcolor{comment}{! The smallest value of vh\_err found so far [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1583     v\_new, \&   \textcolor{comment}{! The velocity with the correction added [L T-1 ~> m s-1].}}
\DoxyCodeLine{1584     dvhdv\_tot,\&\textcolor{comment}{! Summed partial derivative of vh with u [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1585     dv\_min, \&  \textcolor{comment}{! Min/max limits on dv correction based on CFL limits}}
\DoxyCodeLine{1586     dv\_max     \textcolor{comment}{! and previous iterations [L T-1 ~> m s-1].}}
\DoxyCodeLine{1587 \textcolor{keywordtype}{  real} :: dv\_prev \textcolor{comment}{! The previous value of dv [L T-1 ~> m s-1].}}
\DoxyCodeLine{1588 \textcolor{keywordtype}{  real} :: ddv    \textcolor{comment}{! The change in dv from the previous iteration [L T-1 ~> m s-1].}}
\DoxyCodeLine{1589 \textcolor{keywordtype}{  real} :: tol\_eta \textcolor{comment}{! The tolerance for the current iteration [H ~> m or kg m-2].}}
\DoxyCodeLine{1590 \textcolor{keywordtype}{  real} :: tol\_vel \textcolor{comment}{! The tolerance for velocity in the current iteration [L T-1 ~> m s-1].}}
\DoxyCodeLine{1591   \textcolor{keywordtype}{integer} :: i, k, nz, itt, max\_itts = 20}
\DoxyCodeLine{1592   \textcolor{keywordtype}{logical} :: full\_prec, domore, do\_I(SZI\_(G))}
\DoxyCodeLine{1593 }
\DoxyCodeLine{1594   nz = g\%ke}
\DoxyCodeLine{1595   full\_prec = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(full\_precision)) full\_prec = full\_precision}
\DoxyCodeLine{1596 }
\DoxyCodeLine{1597   vh\_aux(:,:) = 0.0 ; dvhdv(:,:) = 0.0}
\DoxyCodeLine{1598 }
\DoxyCodeLine{1599   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1600     vh\_aux(i,k) = vh\_3d(i,j,k)}
\DoxyCodeLine{1601 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1602 }
\DoxyCodeLine{1603   \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1604     dv(i) = 0.0 ; do\_i(i) = do\_i\_in(i)}
\DoxyCodeLine{1605     dv\_max(i) = dv\_max\_cfl(i) ; dv\_min(i) = dv\_min\_cfl(i)}
\DoxyCodeLine{1606     vh\_err(i) = vh\_tot\_0(i) - vhbt(i) ; dvhdv\_tot(i) = dvhdv\_tot\_0(i)}
\DoxyCodeLine{1607     vh\_err\_best(i) = abs(vh\_err(i))}
\DoxyCodeLine{1608 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1609 }
\DoxyCodeLine{1610   \textcolor{keywordflow}{do} itt=1,max\_itts}
\DoxyCodeLine{1611     \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1612       \textcolor{keywordflow}{select case} (itt)}
\DoxyCodeLine{1613         \textcolor{keywordflow}{case} (:1) ; tol\_eta = 1e-6 * cs\%tol\_eta}
\DoxyCodeLine{1614         \textcolor{keywordflow}{case} (2)  ; tol\_eta = 1e-4 * cs\%tol\_eta}
\DoxyCodeLine{1615         \textcolor{keywordflow}{case} (3)  ; tol\_eta = 1e-2 * cs\%tol\_eta}
\DoxyCodeLine{1616 \textcolor{keywordflow}{        case default} ; tol\_eta = cs\%tol\_eta}
\DoxyCodeLine{1617 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{1618     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1619       tol\_eta = cs\%tol\_eta\_aux ; \textcolor{keywordflow}{if} (itt<=1) tol\_eta = 1e-6 * cs\%tol\_eta\_aux}
\DoxyCodeLine{1620 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1621     tol\_vel = cs\%tol\_vel}
\DoxyCodeLine{1622 }
\DoxyCodeLine{1623     \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1624       \textcolor{keywordflow}{if} (vh\_err(i) > 0.0) \textcolor{keywordflow}{then} ; dv\_max(i) = dv(i)}
\DoxyCodeLine{1625       \textcolor{keywordflow}{elseif} (vh\_err(i) < 0.0) \textcolor{keywordflow}{then} ; dv\_min(i) = dv(i)}
\DoxyCodeLine{1626       \textcolor{keywordflow}{else} ; do\_i(i) = .false. ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1627 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1628     domore = .false.}
\DoxyCodeLine{1629     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1630       \textcolor{keywordflow}{if} ((dt * min(g\%IareaT(i,j),g\%IareaT(i,j+1))*abs(vh\_err(i)) > tol\_eta) .or. \&}
\DoxyCodeLine{1631           (cs\%better\_iter .and. ((abs(vh\_err(i)) > tol\_vel * dvhdv\_tot(i)) .or. \&}
\DoxyCodeLine{1632                                  (abs(vh\_err(i)) > vh\_err\_best(i))) )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1633         \textcolor{comment}{!   Use Newton's method, provided it stays bounded.  Otherwise bisect}}
\DoxyCodeLine{1634         \textcolor{comment}{! the value with the appropriate bound.}}
\DoxyCodeLine{1635         \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1636           ddv = -vh\_err(i) / dvhdv\_tot(i)}
\DoxyCodeLine{1637           dv\_prev = dv(i)}
\DoxyCodeLine{1638           dv(i) = dv(i) + ddv}
\DoxyCodeLine{1639           \textcolor{keywordflow}{if} (abs(ddv) < 1.0e-15*abs(dv(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1640             do\_i(i) = .false. \textcolor{comment}{! ddv is small enough to quit.}}
\DoxyCodeLine{1641           \textcolor{keywordflow}{elseif} (ddv > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1642             \textcolor{keywordflow}{if} (dv(i) >= dv\_max(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1643               dv(i) = 0.5*(dv\_prev + dv\_max(i))}
\DoxyCodeLine{1644               \textcolor{keywordflow}{if} (dv\_max(i) - dv\_prev < 1.0e-15*abs(dv(i))) do\_i(i) = .false.}
\DoxyCodeLine{1645 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1646           \textcolor{keywordflow}{else} \textcolor{comment}{! dvv(i) < 0.0}}
\DoxyCodeLine{1647             \textcolor{keywordflow}{if} (dv(i) <= dv\_min(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1648               dv(i) = 0.5*(dv\_prev + dv\_min(i))}
\DoxyCodeLine{1649               \textcolor{keywordflow}{if} (dv\_prev - dv\_min(i) < 1.0e-15*abs(dv(i))) do\_i(i) = .false.}
\DoxyCodeLine{1650 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1651 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1652         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1653           \textcolor{comment}{!   Use Newton's method, provided it stays bounded, just like above.}}
\DoxyCodeLine{1654           dv(i) = dv(i) - vh\_err(i) / dvhdv\_tot(i)}
\DoxyCodeLine{1655           \textcolor{keywordflow}{if} ((dv(i) >= dv\_max(i)) .or. (dv(i) <= dv\_min(i))) \&}
\DoxyCodeLine{1656             dv(i) = 0.5*(dv\_max(i) + dv\_min(i))}
\DoxyCodeLine{1657 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1658         \textcolor{keywordflow}{if} (do\_i(i)) domore = .true.}
\DoxyCodeLine{1659       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1660         do\_i(i) = .false.}
\DoxyCodeLine{1661 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1662 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1663     \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1664 }
\DoxyCodeLine{1665     \textcolor{keywordflow}{if} ((itt < max\_itts) .or. \textcolor{keyword}{present}(vh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1666       \textcolor{keywordflow}{do} i=ish,ieh ; v\_new(i) = v(i,j,k) + dv(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1667       \textcolor{keyword}{call }merid\_flux\_layer(v\_new, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), \&}
\DoxyCodeLine{1668                             vh\_aux(:,k), dvhdv(:,k), visc\_rem(:,k), \&}
\DoxyCodeLine{1669                             dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL, obc)}
\DoxyCodeLine{1670 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1671 }
\DoxyCodeLine{1672     \textcolor{keywordflow}{if} (itt < max\_itts) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1673       \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1674         vh\_err(i) = -vhbt(i) ; dvhdv\_tot(i) = 0.0}
\DoxyCodeLine{1675 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1676       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1677         vh\_err(i) = vh\_err(i) + vh\_aux(i,k)}
\DoxyCodeLine{1678         dvhdv\_tot(i) = dvhdv\_tot(i) + dvhdv(i,k)}
\DoxyCodeLine{1679 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1680       \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1681         vh\_err\_best(i) = min(vh\_err\_best(i), abs(vh\_err(i)))}
\DoxyCodeLine{1682 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1683 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1684 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! itt-loop}}
\DoxyCodeLine{1685   \textcolor{comment}{! If there are any faces which have not converged to within the tolerance,}}
\DoxyCodeLine{1686   \textcolor{comment}{! so-be-it, or else use a final upwind correction?}}
\DoxyCodeLine{1687   \textcolor{comment}{! This never seems to happen with 20 iterations as max\_itt.}}
\DoxyCodeLine{1688 }
\DoxyCodeLine{1689   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1690     vh\_3d(i,j,k) = vh\_aux(i,k)}
\DoxyCodeLine{1691 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1692 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_ae64c4b7cd1756aa3c121fbcf637d5cae}\label{namespacemom__continuity__ppm_ae64c4b7cd1756aa3c121fbcf637d5cae}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!meridional\_mass\_flux@{meridional\_mass\_flux}}
\index{meridional\_mass\_flux@{meridional\_mass\_flux}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{meridional\_mass\_flux()}{meridional\_mass\_flux()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::meridional\+\_\+mass\+\_\+flux (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out)}]{vh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(in), optional}]{vhbt,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in), optional}]{visc\+\_\+rem\+\_\+v,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{v\+\_\+cor,  }\item[{type(bt\+\_\+cont\+\_\+type), optional, pointer}]{B\+T\+\_\+cont }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the mass or volume fluxes through the meridional faces, and other related quantities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em vh} & Volume flux through meridional faces = v$\ast$h$\ast$dx \mbox{[}H m2 s-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\+G \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & Loop bounds structure. \\
\hline
 & {\em obc} & Open boundary condition type specifies whether, where, and what open boundary conditions are used. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+v} & Both the fraction of the momentum \\
\hline
\mbox{\texttt{ in}}  & {\em vhbt} & The summed volume flux through meridional faces \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em v\+\_\+cor} & The meridional velocitiess (v with a barotropic correction) that give vhbt as the depth-\/integrated transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\end{DoxyParams}


Definition at line 1039 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1039   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{1040   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean's vertical grid structure.}}
\DoxyCodeLine{1041 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1042 \textcolor{keywordtype}{  real},  \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to}}
\DoxyCodeLine{1043 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}}
\DoxyCodeLine{1044 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)}   :: vh\textcolor{comment}{   !< Volume flux through meridional}}
\DoxyCodeLine{1045 \textcolor{comment}{                                                                   !! faces = v*h*dx [H m2 s-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1046 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{1047   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1048   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.G}}
\DoxyCodeLine{1049   \textcolor{keywordtype}{type}(loop\_bounds\_type),                    \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}}
\DoxyCodeLine{1050   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{  !< Open boundary condition type}}
\DoxyCodeLine{1051 \textcolor{comment}{                                   !! specifies whether, where, and what open boundary conditions are used.}}
\DoxyCodeLine{1052 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1053                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_v\textcolor{comment}{ !< Both the fraction of the momentum}}
\DoxyCodeLine{1054 \textcolor{comment}{                                   !! originally in a layer that remains after a time-step of viscosity,}}
\DoxyCodeLine{1055 \textcolor{comment}{                                   !! and the fraction of a time-step's worth of a barotropic acceleration}}
\DoxyCodeLine{1056 \textcolor{comment}{                                   !! that a layer experiences after viscosity is applied.  Nondimensional between}}
\DoxyCodeLine{1057 \textcolor{comment}{                                   !! 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{1058 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: vhbt\textcolor{comment}{  !< The summed volume flux through}}
\DoxyCodeLine{1059 \textcolor{comment}{                                   !< meridional faces [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1060 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1061                                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: v\_cor}
\DoxyCodeLine{1062                                    \textcolor{comment}{!< The meridional velocitiess (v with a barotropic correction)}}
\DoxyCodeLine{1063 \textcolor{comment}{                                   !! that give vhbt as the depth-integrated transport [L T-1 ~> m s-1].}}
\DoxyCodeLine{1064   \textcolor{keywordtype}{type}(BT\_cont\_type),              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: BT\_cont\textcolor{comment}{ !< A structure with elements that describe}}
\DoxyCodeLine{1065 \textcolor{comment}{                                   !! the effective open face areas as a function of barotropic flow.}}
\DoxyCodeLine{1066   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1067 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{1068     dvhdv      \textcolor{comment}{! Partial derivative of vh with v [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1069 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{1070     h\_L, h\_R   \textcolor{comment}{! Left and right face thicknesses [H ~> m or kg m-2].}}
\DoxyCodeLine{1071 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{1072     dv, \&      \textcolor{comment}{! Corrective barotropic change in the velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1073     dv\_min\_CFL, \& \textcolor{comment}{! Min/max limits on dv correction}}
\DoxyCodeLine{1074     dv\_max\_CFL, \& \textcolor{comment}{! to avoid CFL violations}}
\DoxyCodeLine{1075     dvhdv\_tot\_0, \& \textcolor{comment}{! Summed partial derivative of vh with v [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1076     vh\_tot\_0, \&   \textcolor{comment}{! Summed transport with no barotropic correction [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1077     visc\_rem\_max  \textcolor{comment}{! The column maximum of visc\_rem.}}
\DoxyCodeLine{1078   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: do\_I}
\DoxyCodeLine{1079 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: FAvi  \textcolor{comment}{! A list of sums of meridional face areas [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1080 \textcolor{keywordtype}{  real} :: FA\_v    \textcolor{comment}{! A sum of meridional face areas [H m ~> m2 or kg m-1].}}
\DoxyCodeLine{1081 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{1082     visc\_rem      \textcolor{comment}{! A 2-D copy of visc\_rem\_v or an array of 1's.}}
\DoxyCodeLine{1083 \textcolor{keywordtype}{  real} :: I\_vrm   \textcolor{comment}{! 1.0 / visc\_rem\_max, nondim.}}
\DoxyCodeLine{1084 \textcolor{keywordtype}{  real} :: CFL\_dt  \textcolor{comment}{! The maximum CFL ratio of the adjusted velocities divided by}}
\DoxyCodeLine{1085                   \textcolor{comment}{! the time step [T-1 ~> s-1].}}
\DoxyCodeLine{1086 \textcolor{keywordtype}{  real} :: I\_dt    \textcolor{comment}{! 1.0 / dt [T-1 ~> s-1].}}
\DoxyCodeLine{1087 \textcolor{keywordtype}{  real} :: dv\_lim  \textcolor{comment}{! The velocity change that give a relative CFL of 1 [L T-1 ~> m s-1].}}
\DoxyCodeLine{1088 \textcolor{keywordtype}{  real} :: dy\_N, dy\_S \textcolor{comment}{! Effective y-grid spacings to the north and south [L ~> m].}}
\DoxyCodeLine{1089   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, n, nz}
\DoxyCodeLine{1090   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{1091   \textcolor{keywordtype}{logical} :: local\_specified\_BC, use\_visc\_rem, set\_BT\_cont, any\_simple\_OBC}
\DoxyCodeLine{1092   \textcolor{keywordtype}{logical} :: local\_Flather\_OBC, is\_simple, local\_open\_BC}
\DoxyCodeLine{1093   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()}
\DoxyCodeLine{1094 }
\DoxyCodeLine{1095   use\_visc\_rem = \textcolor{keyword}{present}(visc\_rem\_v)}
\DoxyCodeLine{1096   local\_specified\_bc = .false. ; set\_bt\_cont = .false. ; local\_flather\_obc = .false.}
\DoxyCodeLine{1097   local\_open\_bc = .false.}
\DoxyCodeLine{1098   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bt\_cont)) set\_bt\_cont = (\textcolor{keyword}{associated}(bt\_cont))}
\DoxyCodeLine{1099   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc\%OBC\_pe) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1100     local\_specified\_bc = obc\%specified\_v\_BCs\_exist\_globally}
\DoxyCodeLine{1101     local\_flather\_obc = obc\%Flather\_v\_BCs\_exist\_globally}
\DoxyCodeLine{1102     local\_open\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{1103 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1104   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh ; nz = g\%ke}
\DoxyCodeLine{1105 }
\DoxyCodeLine{1106   cfl\_dt = cs\%CFL\_limit\_adjust / dt}
\DoxyCodeLine{1107   i\_dt = 1.0 / dt}
\DoxyCodeLine{1108   \textcolor{keywordflow}{if} (cs\%aggress\_adjust) cfl\_dt = i\_dt}
\DoxyCodeLine{1109 }
\DoxyCodeLine{1110   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)}
\DoxyCodeLine{1111 \textcolor{comment}{!\$OMP parallel do default(none) shared(nz,ish,ieh,jsh,jeh,h\_in,h\_L,h\_R,G,GV,LB,CS,visc\_rem,OBC)}}
\DoxyCodeLine{1112   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1113     \textcolor{comment}{! This sets h\_L and h\_R.}}
\DoxyCodeLine{1114     \textcolor{keywordflow}{if} (cs\%upwind\_1st) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1115       \textcolor{keywordflow}{do} j=jsh-1,jeh+1 ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1116         h\_l(i,j,k) = h\_in(i,j,k) ; h\_r(i,j,k) = h\_in(i,j,k)}
\DoxyCodeLine{1117 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1118     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1119       \textcolor{keyword}{call }ppm\_reconstruction\_y(h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), g, lb, \&}
\DoxyCodeLine{1120                                 2.0*gv\%Angstrom\_H, cs\%monotonic, simple\_2nd=cs\%simple\_2nd, obc=obc)}
\DoxyCodeLine{1121 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1122     \textcolor{keywordflow}{do} i=ish,ieh ; visc\_rem(i,k) = 1.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1123 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1124   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)}
\DoxyCodeLine{1125 }
\DoxyCodeLine{1126   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_correct)}
\DoxyCodeLine{1127 \textcolor{comment}{!\$OMP parallel do default(none) shared(ish,ieh,jsh,jeh,nz,v,h\_in,h\_L,h\_R,vh,use\_visc\_rem, \&}}
\DoxyCodeLine{1128 \textcolor{comment}{!\$OMP                                  visc\_rem\_v,dt,US,G,GV,CS,local\_specified\_BC,OBC,vhbt, \&}}
\DoxyCodeLine{1129 \textcolor{comment}{!\$OMP                                  set\_BT\_cont,CFL\_dt,I\_dt,v\_cor,BT\_cont, local\_Flather\_OBC ) \&}}
\DoxyCodeLine{1130 \textcolor{comment}{!\$OMP                          private(do\_I,dvhdv,dv,dv\_max\_CFL,dv\_min\_CFL,vh\_tot\_0,    \&}}
\DoxyCodeLine{1131 \textcolor{comment}{!\$OMP                                  dvhdv\_tot\_0,visc\_rem\_max,I\_vrm,dv\_lim,dy\_N,      \&}}
\DoxyCodeLine{1132 \textcolor{comment}{!\$OMP                                  is\_simple,FAvi,dy\_S,any\_simple\_OBC,l\_seg) \&}}
\DoxyCodeLine{1133 \textcolor{comment}{!\$OMP                     firstprivate(visc\_rem)}}
\DoxyCodeLine{1134   \textcolor{keywordflow}{do} j=jsh-1,jeh}
\DoxyCodeLine{1135     \textcolor{keywordflow}{do} i=ish,ieh ; do\_i(i) = .true. ; visc\_rem\_max(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1136     \textcolor{comment}{! This sets vh and dvhdv.}}
\DoxyCodeLine{1137     \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1138       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1139         visc\_rem(i,k) = visc\_rem\_v(i,j,k)}
\DoxyCodeLine{1140         visc\_rem\_max(i) = max(visc\_rem\_max(i), visc\_rem(i,k))}
\DoxyCodeLine{1141 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1142       \textcolor{keyword}{call }merid\_flux\_layer(v(:,j,k), h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), \&}
\DoxyCodeLine{1143                             vh(:,j,k), dvhdv(:,k), visc\_rem(:,k), \&}
\DoxyCodeLine{1144                             dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL, obc)}
\DoxyCodeLine{1145       \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1146         \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1147           l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{1148 }
\DoxyCodeLine{1149           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1150             \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%specified) \&}
\DoxyCodeLine{1151               vh(i,j,k) = obc\%segment(l\_seg)\%normal\_trans(i,j,k)}
\DoxyCodeLine{1152 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1153 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1154 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1155 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-loop}}
\DoxyCodeLine{1156     \textcolor{keywordflow}{if} ((.not.use\_visc\_rem) .or. (.not.cs\%use\_visc\_rem\_max)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1157       visc\_rem\_max(i) = 1.0}
\DoxyCodeLine{1158 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1159 }
\DoxyCodeLine{1160     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1161       \textcolor{comment}{!   Set limits on dv that will keep the CFL number between -1 and 1.}}
\DoxyCodeLine{1162       \textcolor{comment}{! This should be adequate to keep the root bracketed in all cases.}}
\DoxyCodeLine{1163       \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1164         i\_vrm = 0.0}
\DoxyCodeLine{1165         \textcolor{keywordflow}{if} (visc\_rem\_max(i) > 0.0) i\_vrm = 1.0 / visc\_rem\_max(i)}
\DoxyCodeLine{1166         \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1167           dy\_s = ratio\_max(g\%areaT(i,j), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j))}
\DoxyCodeLine{1168           dy\_n = ratio\_max(g\%areaT(i,j+1), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j+1))}
\DoxyCodeLine{1169         \textcolor{keywordflow}{else} ; dy\_s = g\%dyT(i,j) ; dy\_n = g\%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1170         dv\_max\_cfl(i) = 2.0 * (cfl\_dt * dy\_s) * i\_vrm}
\DoxyCodeLine{1171         dv\_min\_cfl(i) = -2.0 * (cfl\_dt * dy\_n) * i\_vrm}
\DoxyCodeLine{1172         vh\_tot\_0(i) = 0.0 ; dvhdv\_tot\_0(i) = 0.0}
\DoxyCodeLine{1173 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1174       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1175         dvhdv\_tot\_0(i) = dvhdv\_tot\_0(i) + dvhdv(i,k)}
\DoxyCodeLine{1176         vh\_tot\_0(i) = vh\_tot\_0(i) + vh(i,j,k)}
\DoxyCodeLine{1177 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1178 }
\DoxyCodeLine{1179       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1180         \textcolor{keywordflow}{if} (cs\%aggress\_adjust) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1181           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1182             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1183               dy\_s = ratio\_max(g\%areaT(i,j), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j))}
\DoxyCodeLine{1184               dy\_n = ratio\_max(g\%areaT(i,j+1), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j+1))}
\DoxyCodeLine{1185             \textcolor{keywordflow}{else} ; dy\_s = g\%dyT(i,j) ; dy\_n = g\%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1186             dv\_lim = 0.499*((dy\_s*i\_dt - v(i,j,k)) + min(0.0,v(i,j-1,k)))}
\DoxyCodeLine{1187             \textcolor{keywordflow}{if} (dv\_max\_cfl(i) * visc\_rem(i,k) > dv\_lim) \&}
\DoxyCodeLine{1188               dv\_max\_cfl(i) = dv\_lim / visc\_rem(i,k)}
\DoxyCodeLine{1189 }
\DoxyCodeLine{1190             dv\_lim = 0.499*((-dy\_n*cfl\_dt - v(i,j,k)) + max(0.0,v(i,j+1,k)))}
\DoxyCodeLine{1191             \textcolor{keywordflow}{if} (dv\_min\_cfl(i) * visc\_rem(i,k) < dv\_lim) \&}
\DoxyCodeLine{1192               dv\_min\_cfl(i) = dv\_lim / visc\_rem(i,k)}
\DoxyCodeLine{1193 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1194         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1195           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1196             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1197               dy\_s = ratio\_max(g\%areaT(i,j), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j))}
\DoxyCodeLine{1198               dy\_n = ratio\_max(g\%areaT(i,j+1), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j+1))}
\DoxyCodeLine{1199             \textcolor{keywordflow}{else} ; dy\_s = g\%dyT(i,j) ; dy\_n = g\%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1200             \textcolor{keywordflow}{if} (dv\_max\_cfl(i) * visc\_rem(i,k) > dy\_s*cfl\_dt - v(i,j,k)) \&}
\DoxyCodeLine{1201               dv\_max\_cfl(i) = (dy\_s*cfl\_dt - v(i,j,k)) / visc\_rem(i,k)}
\DoxyCodeLine{1202             \textcolor{keywordflow}{if} (dv\_min\_cfl(i) * visc\_rem(i,k) < -dy\_n*cfl\_dt - v(i,j,k)) \&}
\DoxyCodeLine{1203               dv\_min\_cfl(i) = -(dy\_n*cfl\_dt + v(i,j,k)) / visc\_rem(i,k)}
\DoxyCodeLine{1204 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1205 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1206       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1207         \textcolor{keywordflow}{if} (cs\%aggress\_adjust) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1208           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1209             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1210               dy\_s = ratio\_max(g\%areaT(i,j), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j))}
\DoxyCodeLine{1211               dy\_n = ratio\_max(g\%areaT(i,j+1), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j+1))}
\DoxyCodeLine{1212             \textcolor{keywordflow}{else} ; dy\_s = g\%dyT(i,j) ; dy\_n = g\%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1213             dv\_max\_cfl(i) = min(dv\_max\_cfl(i), 0.499 * \&}
\DoxyCodeLine{1214                         ((dy\_s*i\_dt - v(i,j,k)) + min(0.0,v(i,j-1,k))) )}
\DoxyCodeLine{1215             dv\_min\_cfl(i) = max(dv\_min\_cfl(i), 0.499 * \&}
\DoxyCodeLine{1216                         ((-dy\_n*i\_dt - v(i,j,k)) + max(0.0,v(i,j+1,k))) )}
\DoxyCodeLine{1217 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1218         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1219           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1220             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1221               dy\_s = ratio\_max(g\%areaT(i,j), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j))}
\DoxyCodeLine{1222               dy\_n = ratio\_max(g\%areaT(i,j+1), g\%dx\_Cv(i,j), 1000.0*g\%dyT(i,j+1))}
\DoxyCodeLine{1223             \textcolor{keywordflow}{else} ; dy\_s = g\%dyT(i,j) ; dy\_n = g\%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1224             dv\_max\_cfl(i) = min(dv\_max\_cfl(i), dy\_s*cfl\_dt - v(i,j,k))}
\DoxyCodeLine{1225             dv\_min\_cfl(i) = max(dv\_min\_cfl(i), -(dy\_n*cfl\_dt + v(i,j,k)))}
\DoxyCodeLine{1226 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1227 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1228 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1229       \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1230         dv\_max\_cfl(i) = max(dv\_max\_cfl(i),0.0)}
\DoxyCodeLine{1231         dv\_min\_cfl(i) = min(dv\_min\_cfl(i),0.0)}
\DoxyCodeLine{1232 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1233 }
\DoxyCodeLine{1234       any\_simple\_obc = .false.}
\DoxyCodeLine{1235       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1236         \textcolor{keywordflow}{if} (local\_specified\_bc .or. local\_flather\_obc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1237           l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{1238 }
\DoxyCodeLine{1239           \textcolor{comment}{! Avoid reconciling barotropic/baroclinic transports if transport is specified}}
\DoxyCodeLine{1240           is\_simple = .false.}
\DoxyCodeLine{1241           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \&}
\DoxyCodeLine{1242             is\_simple = obc\%segment(l\_seg)\%specified}
\DoxyCodeLine{1243           do\_i(i) = .not.(l\_seg /= obc\_none .and. is\_simple)}
\DoxyCodeLine{1244           any\_simple\_obc = any\_simple\_obc .or. is\_simple}
\DoxyCodeLine{1245 \textcolor{keywordflow}{        enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1246           do\_i(i) = .true.}
\DoxyCodeLine{1247 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1248 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1249 }
\DoxyCodeLine{1250       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhbt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1251         \textcolor{keyword}{call }meridional\_flux\_adjust(v, h\_in, h\_l, h\_r, vhbt(:,j), vh\_tot\_0, dvhdv\_tot\_0, dv, \&}
\DoxyCodeLine{1252                                dv\_max\_cfl, dv\_min\_cfl, dt, g, us, cs, visc\_rem, \&}
\DoxyCodeLine{1253                                j, ish, ieh, do\_i, .true., vh, obc=obc)}
\DoxyCodeLine{1254 }
\DoxyCodeLine{1255         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(v\_cor)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1256           \textcolor{keywordflow}{do} i=ish,ieh ; v\_cor(i,j,k) = v(i,j,k) + dv(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1257           \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1258             l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{1259 }
\DoxyCodeLine{1260             \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1261               \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%specified) \&}
\DoxyCodeLine{1262                 v\_cor(i,j,k) = obc\%segment(obc\%segnum\_v(i,j))\%normal\_vel(i,j,k)}
\DoxyCodeLine{1263 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1264 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1265 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif} \textcolor{comment}{! v-corrected}}
\DoxyCodeLine{1266 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1267 }
\DoxyCodeLine{1268       \textcolor{keywordflow}{if} (set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1269         \textcolor{keyword}{call }set\_merid\_bt\_cont(v, h\_in, h\_l, h\_r, bt\_cont, vh\_tot\_0, dvhdv\_tot\_0,\&}
\DoxyCodeLine{1270                                dv\_max\_cfl, dv\_min\_cfl, dt, g, us, cs, visc\_rem, \&}
\DoxyCodeLine{1271                                visc\_rem\_max, j, ish, ieh, do\_i)}
\DoxyCodeLine{1272         \textcolor{keywordflow}{if} (any\_simple\_obc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1273           \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1274             l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{1275 }
\DoxyCodeLine{1276             do\_i(i) = .false.}
\DoxyCodeLine{1277             \textcolor{keywordflow}{if}(l\_seg /= obc\_none) \&}
\DoxyCodeLine{1278               do\_i(i) = (obc\%segment(l\_seg)\%specified)}
\DoxyCodeLine{1279 }
\DoxyCodeLine{1280             \textcolor{keywordflow}{if} (do\_i(i)) favi(i) = gv\%H\_subroundoff*g\%dx\_Cv(i,j)}
\DoxyCodeLine{1281 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1282           \textcolor{comment}{! NOTE: do\_I(I) should prevent access to segment OBC\_NONE}}
\DoxyCodeLine{1283           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1284             \textcolor{keywordflow}{if} ((abs(obc\%segment(obc\%segnum\_v(i,j))\%normal\_vel(i,j,k)) > 0.0) .and. \&}
\DoxyCodeLine{1285                 (obc\%segment(obc\%segnum\_v(i,j))\%specified)) \&}
\DoxyCodeLine{1286               favi(i) = favi(i) + obc\%segment(obc\%segnum\_v(i,j))\%normal\_trans(i,j,k) / \&}
\DoxyCodeLine{1287                                   obc\%segment(obc\%segnum\_v(i,j))\%normal\_vel(i,j,k)}
\DoxyCodeLine{1288 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1289           \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1290             bt\_cont\%FA\_v\_S0(i,j) = favi(i) ; bt\_cont\%FA\_v\_N0(i,j) = favi(i)}
\DoxyCodeLine{1291             bt\_cont\%FA\_v\_SS(i,j) = favi(i) ; bt\_cont\%FA\_v\_NN(i,j) = favi(i)}
\DoxyCodeLine{1292             bt\_cont\%vBT\_SS(i,j) = 0.0 ; bt\_cont\%vBT\_NN(i,j) = 0.0}
\DoxyCodeLine{1293 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1294 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1295 \textcolor{keywordflow}{      endif} \textcolor{comment}{! set\_BT\_cont}}
\DoxyCodeLine{1296 }
\DoxyCodeLine{1297 \textcolor{keywordflow}{    endif} \textcolor{comment}{! present(vhbt) or set\_BT\_cont}}
\DoxyCodeLine{1298 }
\DoxyCodeLine{1299 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}
\DoxyCodeLine{1300 }
\DoxyCodeLine{1301   \textcolor{keywordflow}{if} (local\_open\_bc .and. set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1302     \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{1303       \textcolor{keywordflow}{if} (obc\%segment(n)\%open .and. obc\%segment(n)\%is\_N\_or\_S) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1304         j = obc\%segment(n)\%HI\%JsdB}
\DoxyCodeLine{1305         \textcolor{keywordflow}{if} (obc\%segment(n)\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1306           \textcolor{keywordflow}{do} i = obc\%segment(n)\%HI\%Isd, obc\%segment(n)\%HI\%Ied}
\DoxyCodeLine{1307             fa\_v = 0.0}
\DoxyCodeLine{1308             \textcolor{keywordflow}{do} k=1,nz ; fa\_v = fa\_v + h\_in(i,j,k)*g\%dx\_Cv(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1309             bt\_cont\%FA\_v\_S0(i,j) = fa\_v ; bt\_cont\%FA\_v\_N0(i,j) = fa\_v}
\DoxyCodeLine{1310             bt\_cont\%FA\_v\_SS(i,j) = fa\_v ; bt\_cont\%FA\_v\_NN(i,j) = fa\_v}
\DoxyCodeLine{1311             bt\_cont\%vBT\_SS(i,j) = 0.0 ; bt\_cont\%vBT\_NN(i,j) = 0.0}
\DoxyCodeLine{1312 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1313         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1314           \textcolor{keywordflow}{do} i = obc\%segment(n)\%HI\%Isd, obc\%segment(n)\%HI\%Ied}
\DoxyCodeLine{1315             fa\_v = 0.0}
\DoxyCodeLine{1316             \textcolor{keywordflow}{do} k=1,nz ; fa\_v = fa\_v + h\_in(i,j+1,k)*g\%dx\_Cv(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1317             bt\_cont\%FA\_v\_S0(i,j) = fa\_v ; bt\_cont\%FA\_v\_N0(i,j) = fa\_v}
\DoxyCodeLine{1318             bt\_cont\%FA\_v\_SS(i,j) = fa\_v ; bt\_cont\%FA\_v\_NN(i,j) = fa\_v}
\DoxyCodeLine{1319             bt\_cont\%vBT\_SS(i,j) = 0.0 ; bt\_cont\%vBT\_NN(i,j) = 0.0}
\DoxyCodeLine{1320 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1321 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1322 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1323 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1324 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1325   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_correct)}
\DoxyCodeLine{1326 }
\DoxyCodeLine{1327   \textcolor{keywordflow}{if} (set\_bt\_cont) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(bt\_cont\%h\_v)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1328     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(v\_cor)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1329       \textcolor{keyword}{call }merid\_face\_thickness(v\_cor, h\_in, h\_l, h\_r, bt\_cont\%h\_v, dt, g, us, lb, \&}
\DoxyCodeLine{1330                                 cs\%vol\_CFL, cs\%marginal\_faces, visc\_rem\_v, obc)}
\DoxyCodeLine{1331     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1332       \textcolor{keyword}{call }merid\_face\_thickness(v, h\_in, h\_l, h\_r, bt\_cont\%h\_v, dt, g, us, lb, \&}
\DoxyCodeLine{1333                                 cs\%vol\_CFL, cs\%marginal\_faces, visc\_rem\_v, obc)}
\DoxyCodeLine{1334 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1335 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1336 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_ab03786fff2550dd61282356608fc1352}\label{namespacemom__continuity__ppm_ab03786fff2550dd61282356608fc1352}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!ppm\_limit\_cw84@{ppm\_limit\_cw84}}
\index{ppm\_limit\_cw84@{ppm\_limit\_cw84}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{ppm\_limit\_cw84()}{ppm\_limit\_cw84()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+limit\+\_\+cw84 (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+R,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{iis,  }\item[{integer, intent(in)}]{iie,  }\item[{integer, intent(in)}]{jis,  }\item[{integer, intent(in)}]{jie }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine limits the left/right edge values of the P\+PM reconstruction according to the monotonic prescription of Colella and Woodward, 1984. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em iis} & Start of i index range. \\
\hline
\mbox{\texttt{ in}}  & {\em iie} & End of i index range. \\
\hline
\mbox{\texttt{ in}}  & {\em jis} & Start of j index range. \\
\hline
\mbox{\texttt{ in}}  & {\em jie} & End of j index range. \\
\hline
\end{DoxyParams}


Definition at line 2179 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2179   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{     !< Ocean's grid structure.}}
\DoxyCodeLine{2180 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{2181 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_L\textcolor{comment}{ !< Left thickness in the reconstruction,}}
\DoxyCodeLine{2182 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}}
\DoxyCodeLine{2183 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_R\textcolor{comment}{ !< Right thickness in the reconstruction,}}
\DoxyCodeLine{2184 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}}
\DoxyCodeLine{2185   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iis\textcolor{comment}{   !< Start of i index range.}}
\DoxyCodeLine{2186   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iie\textcolor{comment}{   !< End of i index range.}}
\DoxyCodeLine{2187   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jis\textcolor{comment}{   !< Start of j index range.}}
\DoxyCodeLine{2188   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jie\textcolor{comment}{   !< End of j index range.}}
\DoxyCodeLine{2189 }
\DoxyCodeLine{2190   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2191 \textcolor{keywordtype}{  real}    :: h\_i, RLdiff, RLdiff2, RLmean, FunFac}
\DoxyCodeLine{2192   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{2193   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{2194 }
\DoxyCodeLine{2195   \textcolor{keywordflow}{do} j=jis,jie ; \textcolor{keywordflow}{do} i=iis,iie}
\DoxyCodeLine{2196     \textcolor{comment}{! This limiter monotonizes the parabola following}}
\DoxyCodeLine{2197     \textcolor{comment}{! Colella and Woodward, 1984, Eq. 1.10}}
\DoxyCodeLine{2198     h\_i = h\_in(i,j)}
\DoxyCodeLine{2199     \textcolor{keywordflow}{if} ( ( h\_r(i,j) - h\_i ) * ( h\_i - h\_l(i,j) ) <= 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2200       h\_l(i,j) = h\_i ; h\_r(i,j) = h\_i}
\DoxyCodeLine{2201     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2202       rldiff = h\_r(i,j) - h\_l(i,j)            \textcolor{comment}{! Difference of edge values}}
\DoxyCodeLine{2203       rlmean = 0.5 * ( h\_r(i,j) + h\_l(i,j) )  \textcolor{comment}{! Mean of edge values}}
\DoxyCodeLine{2204       funfac = 6. * rldiff * ( h\_i - rlmean ) \textcolor{comment}{! Some funny factor}}
\DoxyCodeLine{2205       rldiff2 = rldiff * rldiff               \textcolor{comment}{! Square of difference}}
\DoxyCodeLine{2206       \textcolor{keywordflow}{if} ( funfac >  rldiff2 ) h\_l(i,j) = 3. * h\_i - 2. * h\_r(i,j)}
\DoxyCodeLine{2207       \textcolor{keywordflow}{if} ( funfac < -rldiff2 ) h\_r(i,j) = 3. * h\_i - 2. * h\_l(i,j)}
\DoxyCodeLine{2208 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2209 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2210 }
\DoxyCodeLine{2211   \textcolor{keywordflow}{return}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a870edb0c5b2cb0464899430b6651260c}\label{namespacemom__continuity__ppm_a870edb0c5b2cb0464899430b6651260c}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!ppm\_limit\_pos@{ppm\_limit\_pos}}
\index{ppm\_limit\_pos@{ppm\_limit\_pos}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{ppm\_limit\_pos()}{ppm\_limit\_pos()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+limit\+\_\+pos (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+R,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{iis,  }\item[{integer, intent(in)}]{iie,  }\item[{integer, intent(in)}]{jis,  }\item[{integer, intent(in)}]{jie }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit. \\
\hline
\mbox{\texttt{ in}}  & {\em iis} & Start of i index range. \\
\hline
\mbox{\texttt{ in}}  & {\em iie} & End of i index range. \\
\hline
\mbox{\texttt{ in}}  & {\em jis} & Start of j index range. \\
\hline
\mbox{\texttt{ in}}  & {\em jie} & End of j index range. \\
\hline
\end{DoxyParams}


Definition at line 2138 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2138   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{2139 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{2140 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_L\textcolor{comment}{ !< Left thickness in the reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{2141 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_R\textcolor{comment}{ !< Right thickness in the reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{2142 \textcolor{keywordtype}{  real},                              \textcolor{keywordtype}{intent(in)}  :: h\_min\textcolor{comment}{ !< The minimum thickness}}
\DoxyCodeLine{2143 \textcolor{comment}{                    !! that can be obtained by a concave parabolic fit.}}
\DoxyCodeLine{2144   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iis\textcolor{comment}{      !< Start of i index range.}}
\DoxyCodeLine{2145   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iie\textcolor{comment}{      !< End of i index range.}}
\DoxyCodeLine{2146   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jis\textcolor{comment}{      !< Start of j index range.}}
\DoxyCodeLine{2147   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jie\textcolor{comment}{      !< End of j index range.}}
\DoxyCodeLine{2148 }
\DoxyCodeLine{2149 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2150 \textcolor{keywordtype}{  real}    :: curv, dh, scale}
\DoxyCodeLine{2151   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{2152   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{2153 }
\DoxyCodeLine{2154   \textcolor{keywordflow}{do} j=jis,jie ; \textcolor{keywordflow}{do} i=iis,iie}
\DoxyCodeLine{2155     \textcolor{comment}{! This limiter prevents undershooting minima within the domain with}}
\DoxyCodeLine{2156     \textcolor{comment}{! values less than h\_min.}}
\DoxyCodeLine{2157     curv = 3.0*(h\_l(i,j) + h\_r(i,j) - 2.0*h\_in(i,j))}
\DoxyCodeLine{2158     \textcolor{keywordflow}{if} (curv > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Only minima are limited.}}
\DoxyCodeLine{2159       dh = h\_r(i,j) - h\_l(i,j)}
\DoxyCodeLine{2160       \textcolor{keywordflow}{if} (abs(dh) < curv) \textcolor{keywordflow}{then} \textcolor{comment}{! The parabola's minimum is within the cell.}}
\DoxyCodeLine{2161         \textcolor{keywordflow}{if} (h\_in(i,j) <= h\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2162           h\_l(i,j) = h\_in(i,j) ; h\_r(i,j) = h\_in(i,j)}
\DoxyCodeLine{2163         \textcolor{keywordflow}{elseif} (12.0*curv*(h\_in(i,j) - h\_min) < (curv**2 + 3.0*dh**2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2164           \textcolor{comment}{! The minimum value is h\_in - (curv\string^2 + 3*dh\string^2)/(12*curv), and must}}
\DoxyCodeLine{2165           \textcolor{comment}{! be limited in this case.  0 < scale < 1.}}
\DoxyCodeLine{2166           scale = 12.0*curv*(h\_in(i,j) - h\_min) / (curv**2 + 3.0*dh**2)}
\DoxyCodeLine{2167           h\_l(i,j) = h\_in(i,j) + scale*(h\_l(i,j) - h\_in(i,j))}
\DoxyCodeLine{2168           h\_r(i,j) = h\_in(i,j) + scale*(h\_r(i,j) - h\_in(i,j))}
\DoxyCodeLine{2169 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2170 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2171 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2172 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2173 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a9a7eac2a9b17d0e9ee9ca0a27d2f8fb6}\label{namespacemom__continuity__ppm_a9a7eac2a9b17d0e9ee9ca0a27d2f8fb6}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!ppm\_reconstruction\_x@{ppm\_reconstruction\_x}}
\index{ppm\_reconstruction\_x@{ppm\_reconstruction\_x}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{ppm\_reconstruction\_x()}{ppm\_reconstruction\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+reconstruction\+\_\+x (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+R,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{logical, intent(in), optional}]{monotonic,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge values for P\+PM reconstruction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & Active loop bounds structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit. \\
\hline
\mbox{\texttt{ in}}  & {\em monotonic} & If true, use the Colella \& Woodward monotonic limiter. Otherwise use a simple positive-\/definite limiter. \\
\hline
\mbox{\texttt{ in}}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean thicknesses as the default edge values for a simple 2nd order scheme. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1859 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1859   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{1860 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{1861 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}}
\DoxyCodeLine{1862 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1863 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction,}}
\DoxyCodeLine{1864 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1865   \textcolor{keywordtype}{type}(loop\_bounds\_type),            \textcolor{keywordtype}{intent(in)}  :: LB\textcolor{comment}{   !< Active loop bounds structure.}}
\DoxyCodeLine{1866 \textcolor{keywordtype}{  real},                              \textcolor{keywordtype}{intent(in)}  :: h\_min\textcolor{comment}{ !< The minimum thickness}}
\DoxyCodeLine{1867 \textcolor{comment}{                    !! that can be obtained by a concave parabolic fit.}}
\DoxyCodeLine{1868   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: monotonic\textcolor{comment}{ !< If true, use the}}
\DoxyCodeLine{1869 \textcolor{comment}{                    !! Colella \& Woodward monotonic limiter.}}
\DoxyCodeLine{1870 \textcolor{comment}{                    !! Otherwise use a simple positive-definite limiter.}}
\DoxyCodeLine{1871   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the}}
\DoxyCodeLine{1872 \textcolor{comment}{                    !! arithmetic mean thicknesses as the default edge values}}
\DoxyCodeLine{1873 \textcolor{comment}{                    !! for a simple 2nd order scheme.}}
\DoxyCodeLine{1874   \textcolor{keywordtype}{type}(ocean\_OBC\_type),    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{1875 }
\DoxyCodeLine{1876   \textcolor{comment}{! Local variables with useful mnemonic names.}}
\DoxyCodeLine{1877 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}}
\DoxyCodeLine{1878 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1./6.}
\DoxyCodeLine{1879 \textcolor{keywordtype}{  real} :: h\_ip1, h\_im1}
\DoxyCodeLine{1880 \textcolor{keywordtype}{  real} :: dMx, dMn}
\DoxyCodeLine{1881   \textcolor{keywordtype}{logical} :: use\_CW84, use\_2nd}
\DoxyCodeLine{1882   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{1883   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, n, stencil}
\DoxyCodeLine{1884   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{1885   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()}
\DoxyCodeLine{1886 }
\DoxyCodeLine{1887   use\_cw84 = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(monotonic)) use\_cw84 = monotonic}
\DoxyCodeLine{1888   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd}
\DoxyCodeLine{1889 }
\DoxyCodeLine{1890   local\_open\_bc = .false.}
\DoxyCodeLine{1891   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1892     local\_open\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{1893 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1894 }
\DoxyCodeLine{1895   isl = lb\%ish-1 ; iel = lb\%ieh+1 ; jsl = lb\%jsh ; jel = lb\%jeh}
\DoxyCodeLine{1896 }
\DoxyCodeLine{1897   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}}
\DoxyCodeLine{1898   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1}
\DoxyCodeLine{1899 }
\DoxyCodeLine{1900   \textcolor{keywordflow}{if} ((isl-stencil < g\%isd) .or. (iel+stencil > g\%ied)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1901     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_x called with a ", \&}}
\DoxyCodeLine{1902 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "x-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{1903                stencil + max(g\%isd-isl,iel-g\%ied)}
\DoxyCodeLine{1904     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{1905 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1906   \textcolor{keywordflow}{if} ((jsl < g\%jsd) .or. (jel > g\%jed)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1907     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_x called with a ", \&}}
\DoxyCodeLine{1908 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "y-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{1909                max(g\%jsd-jsl,jel-g\%jed)}
\DoxyCodeLine{1910     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{1911 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1912 }
\DoxyCodeLine{1913   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1914     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{1915       h\_im1 = g\%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g\%mask2dT(i-1,j)) * h\_in(i,j)}
\DoxyCodeLine{1916       h\_ip1 = g\%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g\%mask2dT(i+1,j)) * h\_in(i,j)}
\DoxyCodeLine{1917       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) )}
\DoxyCodeLine{1918       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) )}
\DoxyCodeLine{1919 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1920   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1921     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl-1,iel+1}
\DoxyCodeLine{1922       \textcolor{keywordflow}{if} ((g\%mask2dT(i-1,j) * g\%mask2dT(i,j) * g\%mask2dT(i+1,j)) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1923         slp(i,j) = 0.0}
\DoxyCodeLine{1924       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1925         \textcolor{comment}{! This uses a simple 2nd order slope.}}
\DoxyCodeLine{1926         slp(i,j) = 0.5 * (h\_in(i+1,j) - h\_in(i-1,j))}
\DoxyCodeLine{1927         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{1928         dmx = max(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j)) - h\_in(i,j)}
\DoxyCodeLine{1929         dmn = h\_in(i,j) - min(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j))}
\DoxyCodeLine{1930         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))}
\DoxyCodeLine{1931                 \textcolor{comment}{! * (G\%mask2dT(i-1,j) * G\%mask2dT(i,j) * G\%mask2dT(i+1,j))}}
\DoxyCodeLine{1932 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1933 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1934 }
\DoxyCodeLine{1935     \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1936       \textcolor{keywordflow}{do} n=1, obc\%number\_of\_segments}
\DoxyCodeLine{1937         segment => obc\%segment(n)}
\DoxyCodeLine{1938         \textcolor{keywordflow}{if} (.not. segment\%on\_pe) cycle}
\DoxyCodeLine{1939         \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_e .or. \&}
\DoxyCodeLine{1940             segment\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1941           i=segment\%HI\%IsdB}
\DoxyCodeLine{1942           \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed}
\DoxyCodeLine{1943             slp(i+1,j) = 0.0}
\DoxyCodeLine{1944             slp(i,j) = 0.0}
\DoxyCodeLine{1945 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{1946 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1947 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1948 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1949 }
\DoxyCodeLine{1950     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{1951       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}}
\DoxyCodeLine{1952       \textcolor{comment}{! following sets of expressions are equivalent.}}
\DoxyCodeLine{1953     \textcolor{comment}{! h\_im1 = h\_in(i-1,j,k) ; if (G\%mask2dT(i-1,j) < 0.5) h\_im1 = h\_in(i,j)}}
\DoxyCodeLine{1954     \textcolor{comment}{! h\_ip1 = h\_in(i+1,j,k) ; if (G\%mask2dT(i+1,j) < 0.5) h\_ip1 = h\_in(i,j)}}
\DoxyCodeLine{1955       h\_im1 = g\%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g\%mask2dT(i-1,j)) * h\_in(i,j)}
\DoxyCodeLine{1956       h\_ip1 = g\%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g\%mask2dT(i+1,j)) * h\_in(i,j)}
\DoxyCodeLine{1957       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{1958       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) ) + onesixth*( slp(i-1,j) - slp(i,j) )}
\DoxyCodeLine{1959       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i+1,j) )}
\DoxyCodeLine{1960 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1961 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1962 }
\DoxyCodeLine{1963   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1964     \textcolor{keywordflow}{do} n=1, obc\%number\_of\_segments}
\DoxyCodeLine{1965       segment => obc\%segment(n)}
\DoxyCodeLine{1966       \textcolor{keywordflow}{if} (.not. segment\%on\_pe) cycle}
\DoxyCodeLine{1967       \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1968         i=segment\%HI\%IsdB}
\DoxyCodeLine{1969         \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed}
\DoxyCodeLine{1970           h\_l(i+1,j) = h\_in(i,j)}
\DoxyCodeLine{1971           h\_r(i+1,j) = h\_in(i,j)}
\DoxyCodeLine{1972           h\_l(i,j) = h\_in(i,j)}
\DoxyCodeLine{1973           h\_r(i,j) = h\_in(i,j)}
\DoxyCodeLine{1974 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1975       \textcolor{keywordflow}{elseif} (segment\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1976         i=segment\%HI\%IsdB}
\DoxyCodeLine{1977         \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed}
\DoxyCodeLine{1978           h\_l(i,j) = h\_in(i+1,j)}
\DoxyCodeLine{1979           h\_r(i,j) = h\_in(i+1,j)}
\DoxyCodeLine{1980           h\_l(i+1,j) = h\_in(i+1,j)}
\DoxyCodeLine{1981           h\_r(i+1,j) = h\_in(i+1,j)}
\DoxyCodeLine{1982 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1983 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1984 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1985 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1986 }
\DoxyCodeLine{1987   \textcolor{keywordflow}{if} (use\_cw84) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1988     \textcolor{keyword}{call }ppm\_limit\_cw84(h\_in, h\_l, h\_r, g, isl, iel, jsl, jel)}
\DoxyCodeLine{1989   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1990     \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, h\_min, g, isl, iel, jsl, jel)}
\DoxyCodeLine{1991 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1992 }
\DoxyCodeLine{1993   \textcolor{keywordflow}{return}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_af71fa5f7f4b849ec735e2049df2d0693}\label{namespacemom__continuity__ppm_af71fa5f7f4b849ec735e2049df2d0693}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!ppm\_reconstruction\_y@{ppm\_reconstruction\_y}}
\index{ppm\_reconstruction\_y@{ppm\_reconstruction\_y}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{ppm\_reconstruction\_y()}{ppm\_reconstruction\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+reconstruction\+\_\+y (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+R,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{logical, intent(in), optional}]{monotonic,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge values for P\+PM reconstruction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & Active loop bounds structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit. \\
\hline
\mbox{\texttt{ in}}  & {\em monotonic} & If true, use the Colella \& Woodward monotonic limiter. Otherwise use a simple positive-\/definite limiter. \\
\hline
\mbox{\texttt{ in}}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean thicknesses as the default edge values for a simple 2nd order scheme. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1998 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1998   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{1999 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{2000 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}}
\DoxyCodeLine{2001 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}}
\DoxyCodeLine{2002 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction,}}
\DoxyCodeLine{2003 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}}
\DoxyCodeLine{2004   \textcolor{keywordtype}{type}(loop\_bounds\_type),            \textcolor{keywordtype}{intent(in)}  :: LB\textcolor{comment}{   !< Active loop bounds structure.}}
\DoxyCodeLine{2005 \textcolor{keywordtype}{  real},                              \textcolor{keywordtype}{intent(in)}  :: h\_min\textcolor{comment}{ !< The minimum thickness}}
\DoxyCodeLine{2006 \textcolor{comment}{                    !! that can be obtained by a concave parabolic fit.}}
\DoxyCodeLine{2007   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: monotonic\textcolor{comment}{ !< If true, use the}}
\DoxyCodeLine{2008 \textcolor{comment}{                    !! Colella \& Woodward monotonic limiter.}}
\DoxyCodeLine{2009 \textcolor{comment}{                    !! Otherwise use a simple positive-definite limiter.}}
\DoxyCodeLine{2010   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the}}
\DoxyCodeLine{2011 \textcolor{comment}{                    !! arithmetic mean thicknesses as the default edge values}}
\DoxyCodeLine{2012 \textcolor{comment}{                    !! for a simple 2nd order scheme.}}
\DoxyCodeLine{2013   \textcolor{keywordtype}{type}(ocean\_OBC\_type),    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{2014 }
\DoxyCodeLine{2015   \textcolor{comment}{! Local variables with useful mnemonic names.}}
\DoxyCodeLine{2016 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}}
\DoxyCodeLine{2017 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1./6.}
\DoxyCodeLine{2018 \textcolor{keywordtype}{  real} :: h\_jp1, h\_jm1}
\DoxyCodeLine{2019 \textcolor{keywordtype}{  real} :: dMx, dMn}
\DoxyCodeLine{2020   \textcolor{keywordtype}{logical} :: use\_CW84, use\_2nd}
\DoxyCodeLine{2021   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{2022   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, n, stencil}
\DoxyCodeLine{2023   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{2024   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()}
\DoxyCodeLine{2025 }
\DoxyCodeLine{2026   use\_cw84 = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(monotonic)) use\_cw84 = monotonic}
\DoxyCodeLine{2027   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd}
\DoxyCodeLine{2028 }
\DoxyCodeLine{2029   local\_open\_bc = .false.}
\DoxyCodeLine{2030   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2031     local\_open\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{2032 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2033 }
\DoxyCodeLine{2034   isl = lb\%ish ; iel = lb\%ieh ; jsl = lb\%jsh-1 ; jel = lb\%jeh+1}
\DoxyCodeLine{2035 }
\DoxyCodeLine{2036   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}}
\DoxyCodeLine{2037   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1}
\DoxyCodeLine{2038 }
\DoxyCodeLine{2039   \textcolor{keywordflow}{if} ((isl < g\%isd) .or. (iel > g\%ied)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2040     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_y called with a ", \&}}
\DoxyCodeLine{2041 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "x-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{2042                max(g\%isd-isl,iel-g\%ied)}
\DoxyCodeLine{2043     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{2044 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2045   \textcolor{keywordflow}{if} ((jsl-stencil < g\%jsd) .or. (jel+stencil > g\%jed)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2046     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_y called with a ", \&}}
\DoxyCodeLine{2047 \textcolor{stringliteral}{}\textcolor{stringliteral}{                 \& "y-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{2048                  stencil + max(g\%jsd-jsl,jel-g\%jed)}
\DoxyCodeLine{2049     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{2050 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2051 }
\DoxyCodeLine{2052   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2053     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{2054       h\_jm1 = g\%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g\%mask2dT(i,j-1)) * h\_in(i,j)}
\DoxyCodeLine{2055       h\_jp1 = g\%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g\%mask2dT(i,j+1)) * h\_in(i,j)}
\DoxyCodeLine{2056       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) )}
\DoxyCodeLine{2057       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) )}
\DoxyCodeLine{2058 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2059   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2060     \textcolor{keywordflow}{do} j=jsl-1,jel+1 ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{2061       \textcolor{keywordflow}{if} ((g\%mask2dT(i,j-1) * g\%mask2dT(i,j) * g\%mask2dT(i,j+1)) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2062         slp(i,j) = 0.0}
\DoxyCodeLine{2063       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2064         \textcolor{comment}{! This uses a simple 2nd order slope.}}
\DoxyCodeLine{2065         slp(i,j) = 0.5 * (h\_in(i,j+1) - h\_in(i,j-1))}
\DoxyCodeLine{2066         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{2067         dmx = max(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j)) - h\_in(i,j)}
\DoxyCodeLine{2068         dmn = h\_in(i,j) - min(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j))}
\DoxyCodeLine{2069         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))}
\DoxyCodeLine{2070                 \textcolor{comment}{! * (G\%mask2dT(i,j-1) * G\%mask2dT(i,j) * G\%mask2dT(i,j+1))}}
\DoxyCodeLine{2071 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2072 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2073 }
\DoxyCodeLine{2074     \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2075       \textcolor{keywordflow}{do} n=1, obc\%number\_of\_segments}
\DoxyCodeLine{2076         segment => obc\%segment(n)}
\DoxyCodeLine{2077         \textcolor{keywordflow}{if} (.not. segment\%on\_pe) cycle}
\DoxyCodeLine{2078         \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_s .or. \&}
\DoxyCodeLine{2079             segment\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2080           j=segment\%HI\%JsdB}
\DoxyCodeLine{2081           \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{2082             slp(i,j+1) = 0.0}
\DoxyCodeLine{2083             slp(i,j) = 0.0}
\DoxyCodeLine{2084 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{2085 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2086 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{2087 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2088 }
\DoxyCodeLine{2089     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{2090       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}}
\DoxyCodeLine{2091       \textcolor{comment}{! following sets of expressions are equivalent.}}
\DoxyCodeLine{2092       h\_jm1 = g\%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g\%mask2dT(i,j-1)) * h\_in(i,j)}
\DoxyCodeLine{2093       h\_jp1 = g\%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g\%mask2dT(i,j+1)) * h\_in(i,j)}
\DoxyCodeLine{2094       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{2095       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) ) + onesixth*( slp(i,j-1) - slp(i,j) )}
\DoxyCodeLine{2096       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i,j+1) )}
\DoxyCodeLine{2097 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2098 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2099 }
\DoxyCodeLine{2100   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2101     \textcolor{keywordflow}{do} n=1, obc\%number\_of\_segments}
\DoxyCodeLine{2102       segment => obc\%segment(n)}
\DoxyCodeLine{2103       \textcolor{keywordflow}{if} (.not. segment\%on\_pe) cycle}
\DoxyCodeLine{2104       \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2105         j=segment\%HI\%JsdB}
\DoxyCodeLine{2106         \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{2107           h\_l(i,j+1) = h\_in(i,j)}
\DoxyCodeLine{2108           h\_r(i,j+1) = h\_in(i,j)}
\DoxyCodeLine{2109           h\_l(i,j) = h\_in(i,j)}
\DoxyCodeLine{2110           h\_r(i,j) = h\_in(i,j)}
\DoxyCodeLine{2111 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{2112       \textcolor{keywordflow}{elseif} (segment\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2113         j=segment\%HI\%JsdB}
\DoxyCodeLine{2114         \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{2115           h\_l(i,j) = h\_in(i,j+1)}
\DoxyCodeLine{2116           h\_r(i,j) = h\_in(i,j+1)}
\DoxyCodeLine{2117           h\_l(i,j+1) = h\_in(i,j+1)}
\DoxyCodeLine{2118           h\_r(i,j+1) = h\_in(i,j+1)}
\DoxyCodeLine{2119 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{2120 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2121 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2122 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2123 }
\DoxyCodeLine{2124   \textcolor{keywordflow}{if} (use\_cw84) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2125     \textcolor{keyword}{call }ppm\_limit\_cw84(h\_in, h\_l, h\_r, g, isl, iel, jsl, jel)}
\DoxyCodeLine{2126   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2127     \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, h\_min, g, isl, iel, jsl, jel)}
\DoxyCodeLine{2128 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2129 }
\DoxyCodeLine{2130   \textcolor{keywordflow}{return}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_adf02002cf5951d7610b8643d2d401585}\label{namespacemom__continuity__ppm_adf02002cf5951d7610b8643d2d401585}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!ratio\_max@{ratio\_max}}
\index{ratio\_max@{ratio\_max}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{ratio\_max()}{ratio\_max()}}
{\footnotesize\ttfamily real function mom\+\_\+continuity\+\_\+ppm\+::ratio\+\_\+max (\begin{DoxyParamCaption}\item[{real, intent(in)}]{a,  }\item[{real, intent(in)}]{b,  }\item[{real, intent(in)}]{maxrat }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Return the maximum ratio of a/b or maxrat. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em a} & Numerator \\
\hline
\mbox{\texttt{ in}}  & {\em b} & Denominator \\
\hline
\mbox{\texttt{ in}}  & {\em maxrat} & Maximum value of ratio. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


Definition at line 2216 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2216 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: a\textcolor{comment}{       !< Numerator}}
\DoxyCodeLine{2217 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: b\textcolor{comment}{       !< Denominator}}
\DoxyCodeLine{2218 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: maxrat\textcolor{comment}{  !< Maximum value of ratio.}}
\DoxyCodeLine{2219 \textcolor{keywordtype}{  real} :: ratio\textcolor{comment}{               !< Return value.}}
\DoxyCodeLine{2220 }
\DoxyCodeLine{2221   \textcolor{keywordflow}{if} (abs(a) > abs(maxrat*b)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2222     ratio = maxrat}
\DoxyCodeLine{2223   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2224     ratio = a / b}
\DoxyCodeLine{2225 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a77c6806e82a3634fff7b7480f77c2f02}\label{namespacemom__continuity__ppm_a77c6806e82a3634fff7b7480f77c2f02}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!set\_merid\_bt\_cont@{set\_merid\_bt\_cont}}
\index{set\_merid\_bt\_cont@{set\_merid\_bt\_cont}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{set\_merid\_bt\_cont()}{set\_merid\_bt\_cont()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::set\+\_\+merid\+\_\+bt\+\_\+cont (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{type(bt\+\_\+cont\+\_\+type), intent(inout)}]{B\+T\+\_\+cont,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{vh\+\_\+tot\+\_\+0,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{dvhdv\+\_\+tot\+\_\+0,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{dv\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{dv\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{visc\+\_\+rem,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{visc\+\_\+rem\+\_\+max,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension(szi\+\_\+(g)), intent(in)}]{do\+\_\+I }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets of a structure that describes the meridional barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\mbox{\texttt{ in}}  & {\em vh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dvhdv\+\_\+tot\+\_\+0} & The partial derivative of du\+\_\+err with dv at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dv\+\_\+max\+\_\+cfl} & Maximum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dv\+\_\+min\+\_\+cfl} & Minimum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\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 visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+max} & Maximum allowable visc\+\_\+rem. \\
\hline
\mbox{\texttt{ in}}  & {\em j} & Spatial index. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & Start of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & End of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+i} & A logical flag indicating which I values to work on. \\
\hline
\end{DoxyParams}


Definition at line 1700 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1700   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{1701 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1702 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to calculate fluxes,}}
\DoxyCodeLine{1703 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1704 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}}
\DoxyCodeLine{1705 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1706 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction,}}
\DoxyCodeLine{1707 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}}
\DoxyCodeLine{1708   \textcolor{keywordtype}{type}(BT\_cont\_type),                        \textcolor{keywordtype}{intent(inout)} :: BT\_cont\textcolor{comment}{ !< A structure with elements}}
\DoxyCodeLine{1709 \textcolor{comment}{                       !! that describe the effective open face areas as a function of barotropic flow.}}
\DoxyCodeLine{1710 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: vh\_tot\_0\textcolor{comment}{    !< The summed transport}}
\DoxyCodeLine{1711 \textcolor{comment}{                       !! with 0 adjustment [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1712 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: dvhdv\_tot\_0\textcolor{comment}{ !< The partial derivative}}
\DoxyCodeLine{1713 \textcolor{comment}{                       !! of du\_err with dv at 0 adjustment [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1714 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: dv\_max\_CFL\textcolor{comment}{ !< Maximum acceptable value}}
\DoxyCodeLine{1715 \textcolor{comment}{                                                                   !!  of dv [L T-1 ~> m s-1].}}
\DoxyCodeLine{1716 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: dv\_min\_CFL\textcolor{comment}{ !< Minimum acceptable value}}
\DoxyCodeLine{1717 \textcolor{comment}{                                                                   !!  of dv [L T-1 ~> m s-1].}}
\DoxyCodeLine{1718 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{1719   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1720   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}}
\DoxyCodeLine{1721 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))},          \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}}
\DoxyCodeLine{1722 \textcolor{comment}{                       !! momentum originally in a layer that remains after a time-step}}
\DoxyCodeLine{1723 \textcolor{comment}{                       !! of viscosity, and the fraction of a time-step's worth of a barotropic}}
\DoxyCodeLine{1724 \textcolor{comment}{                       !! acceleration that a layer experiences after viscosity is applied.}}
\DoxyCodeLine{1725 \textcolor{comment}{                       !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{1726 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_max\textcolor{comment}{ !< Maximum allowable visc\_rem.}}
\DoxyCodeLine{1727   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}}
\DoxyCodeLine{1728   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}}
\DoxyCodeLine{1729   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}}
\DoxyCodeLine{1730   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))},               \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< A logical flag indicating}}
\DoxyCodeLine{1731 \textcolor{comment}{                       !! which I values to work on.}}
\DoxyCodeLine{1732   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1733 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{1734     dv0, \&        \textcolor{comment}{! The barotropic velocity increment that gives 0 transport [L T-1 ~> m s-1].}}
\DoxyCodeLine{1735     dvL, dvR, \&   \textcolor{comment}{! The barotropic velocity increments that give the southerly}}
\DoxyCodeLine{1736                   \textcolor{comment}{! (dvL) and northerly (dvR) test velocities [L T-1 ~> m s-1].}}
\DoxyCodeLine{1737     zeros, \&      \textcolor{comment}{! An array of full of 0's.}}
\DoxyCodeLine{1738     dv\_cfl, \&     \textcolor{comment}{! The velocity increment that corresponds to CFL\_min [L T-1 ~> m s-1].}}
\DoxyCodeLine{1739     v\_l, v\_r, \&   \textcolor{comment}{! The southerly (v\_L), northerly (v\_R), and zero-barotropic}}
\DoxyCodeLine{1740     v\_0, \&        \textcolor{comment}{! transport (v\_0) layer test velocities [L T-1 ~> m s-1].}}
\DoxyCodeLine{1741     dvhdv\_l, \&    \textcolor{comment}{! The effective layer marginal face areas with the southerly}}
\DoxyCodeLine{1742     dvhdv\_r, \&    \textcolor{comment}{! (\_L), northerly (\_R), and zero-barotropic (\_0) test}}
\DoxyCodeLine{1743     dvhdv\_0, \&    \textcolor{comment}{! velocities [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1744     vh\_l, vh\_r, \& \textcolor{comment}{! The layer transports with the southerly (\_L), northerly (\_R)}}
\DoxyCodeLine{1745     vh\_0, \&       \textcolor{comment}{! and zero-barotropic (\_0) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1746     famt\_l, famt\_r, \& \textcolor{comment}{! The summed effective marginal face areas for the 3}}
\DoxyCodeLine{1747     famt\_0, \&     \textcolor{comment}{! test velocities [H m ~> m2 or kg m-1].}}
\DoxyCodeLine{1748     vhtot\_l, \&    \textcolor{comment}{! The summed transport with the southerly (vhtot\_L) and}}
\DoxyCodeLine{1749     vhtot\_r       \textcolor{comment}{! and northerly (vhtot\_R) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{1750 \textcolor{keywordtype}{  real} :: FA\_0    \textcolor{comment}{! The effective face area with 0 barotropic transport [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{1751 \textcolor{keywordtype}{  real} :: FA\_avg  \textcolor{comment}{! The average effective face area [H L ~> m2 or kg m-1], nominally given by}}
\DoxyCodeLine{1752                   \textcolor{comment}{! the realized transport divided by the barotropic velocity.}}
\DoxyCodeLine{1753 \textcolor{keywordtype}{  real} :: visc\_rem\_lim \textcolor{comment}{! The larger of visc\_rem and min\_visc\_rem [nondim]  This}}
\DoxyCodeLine{1754                        \textcolor{comment}{! limiting is necessary to keep the inverse of visc\_rem}}
\DoxyCodeLine{1755                        \textcolor{comment}{! from leading to large CFL numbers.}}
\DoxyCodeLine{1756 \textcolor{keywordtype}{  real} :: min\_visc\_rem \textcolor{comment}{! The smallest permitted value for visc\_rem that is used}}
\DoxyCodeLine{1757                        \textcolor{comment}{! in finding the barotropic velocity that changes the}}
\DoxyCodeLine{1758                        \textcolor{comment}{! flow direction.  This is necessary to keep the inverse}}
\DoxyCodeLine{1759                        \textcolor{comment}{! of visc\_rem from leading to large CFL numbers.}}
\DoxyCodeLine{1760 \textcolor{keywordtype}{  real} :: CFL\_min \textcolor{comment}{! A minimal increment in the CFL to try to ensure that the}}
\DoxyCodeLine{1761                   \textcolor{comment}{! flow is truly upwind [nondim]}}
\DoxyCodeLine{1762 \textcolor{keywordtype}{  real} :: Idt     \textcolor{comment}{! The inverse of the time step [T-1 ~> s-1].}}
\DoxyCodeLine{1763   \textcolor{keywordtype}{logical} :: domore}
\DoxyCodeLine{1764   \textcolor{keywordtype}{integer} :: i, k, nz}
\DoxyCodeLine{1765 }
\DoxyCodeLine{1766   nz = g\%ke ; idt = 1.0 / dt}
\DoxyCodeLine{1767   min\_visc\_rem = 0.1 ; cfl\_min = 1e-6}
\DoxyCodeLine{1768 }
\DoxyCodeLine{1769  \textcolor{comment}{! Diagnose the zero-transport correction, dv0.}}
\DoxyCodeLine{1770   \textcolor{keywordflow}{do} i=ish,ieh ; zeros(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1771   \textcolor{keyword}{call }meridional\_flux\_adjust(v, h\_in, h\_l, h\_r, zeros, vh\_tot\_0, dvhdv\_tot\_0, dv0, \&}
\DoxyCodeLine{1772                          dv\_max\_cfl, dv\_min\_cfl, dt, g, us, cs, visc\_rem, \&}
\DoxyCodeLine{1773                          j, ish, ieh, do\_i, .true.)}
\DoxyCodeLine{1774 }
\DoxyCodeLine{1775   \textcolor{comment}{!   Determine the southerly- and northerly- fluxes.  Choose a sufficiently}}
\DoxyCodeLine{1776   \textcolor{comment}{! negative velocity correction for the northerly-flux, and a sufficiently}}
\DoxyCodeLine{1777   \textcolor{comment}{! positive correction for the southerly-flux.}}
\DoxyCodeLine{1778   domore = .false.}
\DoxyCodeLine{1779   \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1780     domore = .true.}
\DoxyCodeLine{1781     dv\_cfl(i) = (cfl\_min * idt) * g\%dyCv(i,j)}
\DoxyCodeLine{1782     dvr(i) = min(0.0,dv0(i) - dv\_cfl(i))}
\DoxyCodeLine{1783     dvl(i) = max(0.0,dv0(i) + dv\_cfl(i))}
\DoxyCodeLine{1784     famt\_l(i) = 0.0 ; famt\_r(i) = 0.0 ; famt\_0(i) = 0.0}
\DoxyCodeLine{1785     vhtot\_l(i) = 0.0 ; vhtot\_r(i) = 0.0}
\DoxyCodeLine{1786 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1787 }
\DoxyCodeLine{1788   \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1789     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1790       bt\_cont\%FA\_v\_S0(i,j) = 0.0 ; bt\_cont\%FA\_v\_SS(i,j) = 0.0}
\DoxyCodeLine{1791       bt\_cont\%vBT\_SS(i,j) = 0.0}
\DoxyCodeLine{1792       bt\_cont\%FA\_v\_N0(i,j) = 0.0 ; bt\_cont\%FA\_v\_NN(i,j) = 0.0}
\DoxyCodeLine{1793       bt\_cont\%vBT\_NN(i,j) = 0.0}
\DoxyCodeLine{1794 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1795     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1796 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1797 }
\DoxyCodeLine{1798   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1799     visc\_rem\_lim = max(visc\_rem(i,k), min\_visc\_rem*visc\_rem\_max(i))}
\DoxyCodeLine{1800     \textcolor{keywordflow}{if} (visc\_rem\_lim > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! This is almost always true for ocean points.}}
\DoxyCodeLine{1801       \textcolor{keywordflow}{if} (v(i,j,k) + dvr(i)*visc\_rem\_lim > -dv\_cfl(i)*visc\_rem(i,k)) \&}
\DoxyCodeLine{1802         dvr(i) = -(v(i,j,k) + dv\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim}
\DoxyCodeLine{1803       \textcolor{keywordflow}{if} (v(i,j,k) + dvl(i)*visc\_rem\_lim < dv\_cfl(i)*visc\_rem(i,k)) \&}
\DoxyCodeLine{1804         dvl(i) = -(v(i,j,k) - dv\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim}
\DoxyCodeLine{1805 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1806 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1807   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1808     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1809       v\_l(i) = v(i,j,k) + dvl(i) * visc\_rem(i,k)}
\DoxyCodeLine{1810       v\_r(i) = v(i,j,k) + dvr(i) * visc\_rem(i,k)}
\DoxyCodeLine{1811       v\_0(i) = v(i,j,k) + dv0(i) * visc\_rem(i,k)}
\DoxyCodeLine{1812 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1813     \textcolor{keyword}{call }merid\_flux\_layer(v\_0, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), vh\_0, dvhdv\_0, \&}
\DoxyCodeLine{1814                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL)}
\DoxyCodeLine{1815     \textcolor{keyword}{call }merid\_flux\_layer(v\_l, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), vh\_l, dvhdv\_l, \&}
\DoxyCodeLine{1816                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL)}
\DoxyCodeLine{1817     \textcolor{keyword}{call }merid\_flux\_layer(v\_r, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), vh\_r, dvhdv\_r, \&}
\DoxyCodeLine{1818                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL)}
\DoxyCodeLine{1819     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1820       famt\_0(i) = famt\_0(i) + dvhdv\_0(i)}
\DoxyCodeLine{1821       famt\_l(i) = famt\_l(i) + dvhdv\_l(i)}
\DoxyCodeLine{1822       famt\_r(i) = famt\_r(i) + dvhdv\_r(i)}
\DoxyCodeLine{1823       vhtot\_l(i) = vhtot\_l(i) + vh\_l(i)}
\DoxyCodeLine{1824       vhtot\_r(i) = vhtot\_r(i) + vh\_r(i)}
\DoxyCodeLine{1825 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1826 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1827   \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1828     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)}
\DoxyCodeLine{1829     \textcolor{keywordflow}{if} ((dvl(i) - dv0(i)) /= 0.0) \&}
\DoxyCodeLine{1830       fa\_avg = vhtot\_l(i) / (dvl(i) - dv0(i))}
\DoxyCodeLine{1831     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_l(i))}
\DoxyCodeLine{1832     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1833     bt\_cont\%FA\_v\_S0(i,j) = fa\_0 ; bt\_cont\%FA\_v\_SS(i,j) = famt\_l(i)}
\DoxyCodeLine{1834     \textcolor{keywordflow}{if} (abs(fa\_0-famt\_l(i)) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont\%vBT\_SS(i,j) = 0.0 ; \textcolor{keywordflow}{else}}
\DoxyCodeLine{1835       bt\_cont\%vBT\_SS(i,j) = (1.5 * (dvl(i) - dv0(i))) * \&}
\DoxyCodeLine{1836                    ((famt\_l(i) - fa\_avg) / (famt\_l(i) - fa\_0))}
\DoxyCodeLine{1837 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1838 }
\DoxyCodeLine{1839     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)}
\DoxyCodeLine{1840     \textcolor{keywordflow}{if} ((dvr(i) - dv0(i)) /= 0.0) \&}
\DoxyCodeLine{1841       fa\_avg = vhtot\_r(i) / (dvr(i) - dv0(i))}
\DoxyCodeLine{1842     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_r(i))}
\DoxyCodeLine{1843     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1844     bt\_cont\%FA\_v\_N0(i,j) = fa\_0 ; bt\_cont\%FA\_v\_NN(i,j) = famt\_r(i)}
\DoxyCodeLine{1845     \textcolor{keywordflow}{if} (abs(famt\_r(i) - fa\_0) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont\%vBT\_NN(i,j) = 0.0 ; \textcolor{keywordflow}{else}}
\DoxyCodeLine{1846       bt\_cont\%vBT\_NN(i,j) = (1.5 * (dvr(i) - dv0(i))) * \&}
\DoxyCodeLine{1847                    ((famt\_r(i) - fa\_avg) / (famt\_r(i) - fa\_0))}
\DoxyCodeLine{1848 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1849   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1850     bt\_cont\%FA\_v\_S0(i,j) = 0.0 ; bt\_cont\%FA\_v\_SS(i,j) = 0.0}
\DoxyCodeLine{1851     bt\_cont\%FA\_v\_N0(i,j) = 0.0 ; bt\_cont\%FA\_v\_NN(i,j) = 0.0}
\DoxyCodeLine{1852     bt\_cont\%vBT\_SS(i,j) = 0.0 ; bt\_cont\%vBT\_NN(i,j) = 0.0}
\DoxyCodeLine{1853 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1854 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a30e5aef71acbeef6afe5f6cf1ea30dcc}\label{namespacemom__continuity__ppm_a30e5aef71acbeef6afe5f6cf1ea30dcc}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!set\_zonal\_bt\_cont@{set\_zonal\_bt\_cont}}
\index{set\_zonal\_bt\_cont@{set\_zonal\_bt\_cont}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{set\_zonal\_bt\_cont()}{set\_zonal\_bt\_cont()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::set\+\_\+zonal\+\_\+bt\+\_\+cont (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+R,  }\item[{type(bt\+\_\+cont\+\_\+type), intent(inout)}]{B\+T\+\_\+cont,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{uh\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{duhdu\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{du\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{du\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szib\+\_\+(g),szk\+\_\+(g)), intent(in)}]{visc\+\_\+rem,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{visc\+\_\+rem\+\_\+max,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension( g \%isdb\+: g \%iedb), intent(in)}]{do\+\_\+I }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets a structure that describes the zonal barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\mbox{\texttt{ in}}  & {\em uh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em duhdu\+\_\+tot\+\_\+0} & The partial derivative of du\+\_\+err with du at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em du\+\_\+max\+\_\+cfl} & Maximum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em du\+\_\+min\+\_\+cfl} & Minimum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\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 visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+max} & Maximum allowable visc\+\_\+rem. \\
\hline
\mbox{\texttt{ in}}  & {\em j} & Spatial index. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & Start of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & End of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+i} & A logical flag indicating which I values to work on. \\
\hline
\end{DoxyParams}


Definition at line 877 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{877   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{878 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{879 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to}}
\DoxyCodeLine{880 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}}
\DoxyCodeLine{881 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the}}
\DoxyCodeLine{882 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{883 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the}}
\DoxyCodeLine{884 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{885   \textcolor{keywordtype}{type}(BT\_cont\_type),                        \textcolor{keywordtype}{intent(inout)} :: BT\_cont\textcolor{comment}{ !< A structure with elements}}
\DoxyCodeLine{886 \textcolor{comment}{                       !! that describe the effective open face areas as a function of barotropic flow.}}
\DoxyCodeLine{887 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: uh\_tot\_0\textcolor{comment}{    !< The summed transport}}
\DoxyCodeLine{888 \textcolor{comment}{                       !! with 0 adjustment [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{889 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: duhdu\_tot\_0\textcolor{comment}{ !< The partial derivative}}
\DoxyCodeLine{890 \textcolor{comment}{                       !! of du\_err with du at 0 adjustment [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{891 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_max\_CFL\textcolor{comment}{  !< Maximum acceptable}}
\DoxyCodeLine{892 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}}
\DoxyCodeLine{893 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_min\_CFL\textcolor{comment}{  !< Minimum acceptable}}
\DoxyCodeLine{894 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}}
\DoxyCodeLine{895 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{896   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{897   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}}
\DoxyCodeLine{898 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))},         \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}}
\DoxyCodeLine{899 \textcolor{comment}{                       !! momentum originally in a layer that remains after a time-step of viscosity, and}}
\DoxyCodeLine{900 \textcolor{comment}{                       !! the fraction of a time-step's worth of a barotropic acceleration that a layer}}
\DoxyCodeLine{901 \textcolor{comment}{                       !! experiences after viscosity is applied.}}
\DoxyCodeLine{902 \textcolor{comment}{                       !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{903 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_max\textcolor{comment}{ !< Maximum allowable visc\_rem.}}
\DoxyCodeLine{904   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}}
\DoxyCodeLine{905   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}}
\DoxyCodeLine{906   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}}
\DoxyCodeLine{907   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))},              \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< A logical flag indicating}}
\DoxyCodeLine{908 \textcolor{comment}{                       !! which I values to work on.}}
\DoxyCodeLine{909   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{910 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{911     du0, \&        \textcolor{comment}{! The barotropic velocity increment that gives 0 transport [L T-1 ~> m s-1].}}
\DoxyCodeLine{912     duL, duR, \&   \textcolor{comment}{! The barotropic velocity increments that give the westerly}}
\DoxyCodeLine{913                   \textcolor{comment}{! (duL) and easterly (duR) test velocities [L T-1 ~> m s-1].}}
\DoxyCodeLine{914     zeros, \&      \textcolor{comment}{! An array of full of 0's.}}
\DoxyCodeLine{915     du\_cfl, \&     \textcolor{comment}{! The velocity increment that corresponds to CFL\_min [L T-1 ~> m s-1].}}
\DoxyCodeLine{916     u\_l, u\_r, \&   \textcolor{comment}{! The westerly (u\_L), easterly (u\_R), and zero-barotropic}}
\DoxyCodeLine{917     u\_0, \&        \textcolor{comment}{! transport (u\_0) layer test velocities [L T-1 ~> m s-1].}}
\DoxyCodeLine{918     duhdu\_l, \&    \textcolor{comment}{! The effective layer marginal face areas with the westerly}}
\DoxyCodeLine{919     duhdu\_r, \&    \textcolor{comment}{! (\_L), easterly (\_R), and zero-barotropic (\_0) test}}
\DoxyCodeLine{920     duhdu\_0, \&    \textcolor{comment}{! velocities [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{921     uh\_l, uh\_r, \& \textcolor{comment}{! The layer transports with the westerly (\_L), easterly (\_R),}}
\DoxyCodeLine{922     uh\_0, \&       \textcolor{comment}{! and zero-barotropic (\_0) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{923     famt\_l, famt\_r, \& \textcolor{comment}{! The summed effective marginal face areas for the 3}}
\DoxyCodeLine{924     famt\_0, \&     \textcolor{comment}{! test velocities [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{925     uhtot\_l, \&    \textcolor{comment}{! The summed transport with the westerly (uhtot\_L) and}}
\DoxyCodeLine{926     uhtot\_r       \textcolor{comment}{! and easterly (uhtot\_R) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{927 \textcolor{keywordtype}{  real} :: FA\_0    \textcolor{comment}{! The effective face area with 0 barotropic transport [L H ~> m2 or kg m].}}
\DoxyCodeLine{928 \textcolor{keywordtype}{  real} :: FA\_avg  \textcolor{comment}{! The average effective face area [L H ~> m2 or kg m], nominally given by}}
\DoxyCodeLine{929                   \textcolor{comment}{! the realized transport divided by the barotropic velocity.}}
\DoxyCodeLine{930 \textcolor{keywordtype}{  real} :: visc\_rem\_lim \textcolor{comment}{! The larger of visc\_rem and min\_visc\_rem [nondim]  This}}
\DoxyCodeLine{931                        \textcolor{comment}{! limiting is necessary to keep the inverse of visc\_rem}}
\DoxyCodeLine{932                        \textcolor{comment}{! from leading to large CFL numbers.}}
\DoxyCodeLine{933 \textcolor{keywordtype}{  real} :: min\_visc\_rem \textcolor{comment}{! The smallest permitted value for visc\_rem that is used}}
\DoxyCodeLine{934                        \textcolor{comment}{! in finding the barotropic velocity that changes the}}
\DoxyCodeLine{935                        \textcolor{comment}{! flow direction.  This is necessary to keep the inverse}}
\DoxyCodeLine{936                        \textcolor{comment}{! of visc\_rem from leading to large CFL numbers.}}
\DoxyCodeLine{937 \textcolor{keywordtype}{  real} :: CFL\_min \textcolor{comment}{! A minimal increment in the CFL to try to ensure that the}}
\DoxyCodeLine{938                   \textcolor{comment}{! flow is truly upwind [nondim]}}
\DoxyCodeLine{939 \textcolor{keywordtype}{  real} :: Idt     \textcolor{comment}{! The inverse of the time step [T-1 ~> s-1].}}
\DoxyCodeLine{940   \textcolor{keywordtype}{logical} :: domore}
\DoxyCodeLine{941   \textcolor{keywordtype}{integer} :: i, k, nz}
\DoxyCodeLine{942 }
\DoxyCodeLine{943   nz = g\%ke ; idt = 1.0 / dt}
\DoxyCodeLine{944   min\_visc\_rem = 0.1 ; cfl\_min = 1e-6}
\DoxyCodeLine{945 }
\DoxyCodeLine{946  \textcolor{comment}{! Diagnose the zero-transport correction, du0.}}
\DoxyCodeLine{947   \textcolor{keywordflow}{do} i=ish-1,ieh ; zeros(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{948   \textcolor{keyword}{call }zonal\_flux\_adjust(u, h\_in, h\_l, h\_r, zeros, uh\_tot\_0, duhdu\_tot\_0, du0, \&}
\DoxyCodeLine{949                          du\_max\_cfl, du\_min\_cfl, dt, g, us, cs, visc\_rem, \&}
\DoxyCodeLine{950                          j, ish, ieh, do\_i, .true.)}
\DoxyCodeLine{951 }
\DoxyCodeLine{952   \textcolor{comment}{! Determine the westerly- and easterly- fluxes.  Choose a sufficiently}}
\DoxyCodeLine{953   \textcolor{comment}{! negative velocity correction for the easterly-flux, and a sufficiently}}
\DoxyCodeLine{954   \textcolor{comment}{! positive correction for the westerly-flux.}}
\DoxyCodeLine{955   domore = .false.}
\DoxyCodeLine{956   \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{957     \textcolor{keywordflow}{if} (do\_i(i)) domore = .true.}
\DoxyCodeLine{958     du\_cfl(i) = (cfl\_min * idt) * g\%dxCu(i,j)}
\DoxyCodeLine{959     dur(i) = min(0.0,du0(i) - du\_cfl(i))}
\DoxyCodeLine{960     dul(i) = max(0.0,du0(i) + du\_cfl(i))}
\DoxyCodeLine{961     famt\_l(i) = 0.0 ; famt\_r(i) = 0.0 ; famt\_0(i) = 0.0}
\DoxyCodeLine{962     uhtot\_l(i) = 0.0 ; uhtot\_r(i) = 0.0}
\DoxyCodeLine{963 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{964 }
\DoxyCodeLine{965   \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{then}}
\DoxyCodeLine{966     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{967       bt\_cont\%FA\_u\_W0(i,j) = 0.0 ; bt\_cont\%FA\_u\_WW(i,j) = 0.0}
\DoxyCodeLine{968       bt\_cont\%FA\_u\_E0(i,j) = 0.0 ; bt\_cont\%FA\_u\_EE(i,j) = 0.0}
\DoxyCodeLine{969       bt\_cont\%uBT\_WW(i,j) = 0.0 ; bt\_cont\%uBT\_EE(i,j) = 0.0}
\DoxyCodeLine{970 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{971     \textcolor{keywordflow}{return}}
\DoxyCodeLine{972 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{973 }
\DoxyCodeLine{974   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{975     visc\_rem\_lim = max(visc\_rem(i,k), min\_visc\_rem*visc\_rem\_max(i))}
\DoxyCodeLine{976     \textcolor{keywordflow}{if} (visc\_rem\_lim > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! This is almost always true for ocean points.}}
\DoxyCodeLine{977       \textcolor{keywordflow}{if} (u(i,j,k) + dur(i)*visc\_rem\_lim > -du\_cfl(i)*visc\_rem(i,k)) \&}
\DoxyCodeLine{978         dur(i) = -(u(i,j,k) + du\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim}
\DoxyCodeLine{979       \textcolor{keywordflow}{if} (u(i,j,k) + dul(i)*visc\_rem\_lim < du\_cfl(i)*visc\_rem(i,k)) \&}
\DoxyCodeLine{980         dul(i) = -(u(i,j,k) - du\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim}
\DoxyCodeLine{981 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{982 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{983 }
\DoxyCodeLine{984   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{985     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{986       u\_l(i) = u(i,j,k) + dul(i) * visc\_rem(i,k)}
\DoxyCodeLine{987       u\_r(i) = u(i,j,k) + dur(i) * visc\_rem(i,k)}
\DoxyCodeLine{988       u\_0(i) = u(i,j,k) + du0(i) * visc\_rem(i,k)}
\DoxyCodeLine{989 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{990     \textcolor{keyword}{call }zonal\_flux\_layer(u\_0, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), uh\_0, duhdu\_0, \&}
\DoxyCodeLine{991                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL)}
\DoxyCodeLine{992     \textcolor{keyword}{call }zonal\_flux\_layer(u\_l, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), uh\_l, duhdu\_l, \&}
\DoxyCodeLine{993                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL)}
\DoxyCodeLine{994     \textcolor{keyword}{call }zonal\_flux\_layer(u\_r, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), uh\_r, duhdu\_r, \&}
\DoxyCodeLine{995                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL)}
\DoxyCodeLine{996     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{997       famt\_0(i) = famt\_0(i) + duhdu\_0(i)}
\DoxyCodeLine{998       famt\_l(i) = famt\_l(i) + duhdu\_l(i)}
\DoxyCodeLine{999       famt\_r(i) = famt\_r(i) + duhdu\_r(i)}
\DoxyCodeLine{1000       uhtot\_l(i) = uhtot\_l(i) + uh\_l(i)}
\DoxyCodeLine{1001       uhtot\_r(i) = uhtot\_r(i) + uh\_r(i)}
\DoxyCodeLine{1002 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1003 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1004   \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1005     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)}
\DoxyCodeLine{1006     \textcolor{keywordflow}{if} ((dul(i) - du0(i)) /= 0.0) \&}
\DoxyCodeLine{1007       fa\_avg = uhtot\_l(i) / (dul(i) - du0(i))}
\DoxyCodeLine{1008     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_l(i))}
\DoxyCodeLine{1009     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1010 }
\DoxyCodeLine{1011     bt\_cont\%FA\_u\_W0(i,j) = fa\_0 ; bt\_cont\%FA\_u\_WW(i,j) = famt\_l(i)}
\DoxyCodeLine{1012     \textcolor{keywordflow}{if} (abs(fa\_0-famt\_l(i)) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont\%uBT\_WW(i,j) = 0.0 ; \textcolor{keywordflow}{else}}
\DoxyCodeLine{1013       bt\_cont\%uBT\_WW(i,j) = (1.5 * (dul(i) - du0(i))) * \&}
\DoxyCodeLine{1014                             ((famt\_l(i) - fa\_avg) / (famt\_l(i) - fa\_0))}
\DoxyCodeLine{1015 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1016 }
\DoxyCodeLine{1017     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)}
\DoxyCodeLine{1018     \textcolor{keywordflow}{if} ((dur(i) - du0(i)) /= 0.0) \&}
\DoxyCodeLine{1019       fa\_avg = uhtot\_r(i) / (dur(i) - du0(i))}
\DoxyCodeLine{1020     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_r(i))}
\DoxyCodeLine{1021     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1022 }
\DoxyCodeLine{1023     bt\_cont\%FA\_u\_E0(i,j) = fa\_0 ; bt\_cont\%FA\_u\_EE(i,j) = famt\_r(i)}
\DoxyCodeLine{1024     \textcolor{keywordflow}{if} (abs(famt\_r(i) - fa\_0) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont\%uBT\_EE(i,j) = 0.0 ; \textcolor{keywordflow}{else}}
\DoxyCodeLine{1025       bt\_cont\%uBT\_EE(i,j) = (1.5 * (dur(i) - du0(i))) * \&}
\DoxyCodeLine{1026                             ((famt\_r(i) - fa\_avg) / (famt\_r(i) - fa\_0))}
\DoxyCodeLine{1027 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1028   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1029     bt\_cont\%FA\_u\_W0(i,j) = 0.0 ; bt\_cont\%FA\_u\_WW(i,j) = 0.0}
\DoxyCodeLine{1030     bt\_cont\%FA\_u\_E0(i,j) = 0.0 ; bt\_cont\%FA\_u\_EE(i,j) = 0.0}
\DoxyCodeLine{1031     bt\_cont\%uBT\_WW(i,j) = 0.0 ; bt\_cont\%uBT\_EE(i,j) = 0.0}
\DoxyCodeLine{1032 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1033 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a9e76825c96ffca1ae0e84469ab46029b}\label{namespacemom__continuity__ppm_a9e76825c96ffca1ae0e84469ab46029b}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!zonal\_face\_thickness@{zonal\_face\_thickness}}
\index{zonal\_face\_thickness@{zonal\_face\_thickness}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{zonal\_face\_thickness()}{zonal\_face\_thickness()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+face\+\_\+thickness (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+R,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h\+\_\+u,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{logical, intent(in)}]{marginal,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{visc\+\_\+rem\+\_\+u,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the effective interface thickness at each zonal velocity point. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+u} & Thickness at zonal faces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & Loop bounds structure. \\
\hline
\mbox{\texttt{ in}}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
\mbox{\texttt{ in}}  & {\em marginal} & If true, report the marginal face thicknesses; otherwise report transport-\/averaged thicknesses. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+u} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 605 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{605   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{606 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{607 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thickness used to}}
\DoxyCodeLine{608 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}}
\DoxyCodeLine{609 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the}}
\DoxyCodeLine{610 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{611 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the}}
\DoxyCodeLine{612 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{613 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\_u\textcolor{comment}{  !< Thickness at zonal faces [H ~> m or kg m-2].}}
\DoxyCodeLine{614 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{615   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{616   \textcolor{keywordtype}{type}(loop\_bounds\_type),                    \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}}
\DoxyCodeLine{617   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{ !< If true, rescale the ratio}}
\DoxyCodeLine{618 \textcolor{comment}{                          !! of face areas to the cell areas when estimating the CFL number.}}
\DoxyCodeLine{619   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: marginal\textcolor{comment}{ !< If true, report the}}
\DoxyCodeLine{620 \textcolor{comment}{                          !! marginal face thicknesses; otherwise report transport-averaged thicknesses.}}
\DoxyCodeLine{621 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{622                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_u}
\DoxyCodeLine{623                           \textcolor{comment}{!< Both the fraction of the momentum originally in a layer that remains after}}
\DoxyCodeLine{624 \textcolor{comment}{                          !! a time-step of viscosity, and the fraction of a time-step's worth of a}}
\DoxyCodeLine{625 \textcolor{comment}{                          !! barotropic acceleration that a layer experiences after viscosity is applied.}}
\DoxyCodeLine{626 \textcolor{comment}{                          !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{627   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{628 }
\DoxyCodeLine{629   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{630 \textcolor{keywordtype}{  real} :: CFL  \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}}
\DoxyCodeLine{631 \textcolor{keywordtype}{  real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}}
\DoxyCodeLine{632                  \textcolor{comment}{! with the same units as h\_in.}}
\DoxyCodeLine{633 \textcolor{keywordtype}{  real} :: h\_avg  \textcolor{comment}{! The average thickness of a flux [H ~> m or kg m-2].}}
\DoxyCodeLine{634 \textcolor{keywordtype}{  real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}}
\DoxyCodeLine{635   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{636   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, nz, n}
\DoxyCodeLine{637   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh ; nz = g\%ke}
\DoxyCodeLine{638 }
\DoxyCodeLine{639   \textcolor{comment}{!\$OMP parallel do default(shared) private(CFL,curv\_3,h\_marg,h\_avg)}}
\DoxyCodeLine{640   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{641     \textcolor{keywordflow}{if} (u(i,j,k) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{642       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (u(i,j,k) * dt) * (g\%dy\_Cu(i,j) * g\%IareaT(i,j))}
\DoxyCodeLine{643       \textcolor{keywordflow}{else} ; cfl = u(i,j,k) * dt * g\%IdxT(i,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{644       curv\_3 = h\_l(i,j,k) + h\_r(i,j,k) - 2.0*h(i,j,k)}
\DoxyCodeLine{645       h\_avg = h\_r(i,j,k) + cfl * (0.5*(h\_l(i,j,k) - h\_r(i,j,k)) + curv\_3*(cfl - 1.5))}
\DoxyCodeLine{646       h\_marg = h\_r(i,j,k) + cfl * ((h\_l(i,j,k) - h\_r(i,j,k)) + 3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{647     \textcolor{keywordflow}{elseif} (u(i,j,k) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{648       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-u(i,j,k)*dt) * (g\%dy\_Cu(i,j) * g\%IareaT(i+1,j))}
\DoxyCodeLine{649       \textcolor{keywordflow}{else} ; cfl = -u(i,j,k) * dt * g\%IdxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{650       curv\_3 = h\_l(i+1,j,k) + h\_r(i+1,j,k) - 2.0*h(i+1,j,k)}
\DoxyCodeLine{651       h\_avg = h\_l(i+1,j,k) + cfl * (0.5*(h\_r(i+1,j,k)-h\_l(i+1,j,k)) + curv\_3*(cfl - 1.5))}
\DoxyCodeLine{652       h\_marg = h\_l(i+1,j,k) + cfl * ((h\_r(i+1,j,k)-h\_l(i+1,j,k)) + \&}
\DoxyCodeLine{653                                     3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{654     \textcolor{keywordflow}{else}}
\DoxyCodeLine{655       h\_avg = 0.5 * (h\_l(i+1,j,k) + h\_r(i,j,k))}
\DoxyCodeLine{656       \textcolor{comment}{!   The choice to use the arithmetic mean here is somewhat arbitrariy, but}}
\DoxyCodeLine{657       \textcolor{comment}{! it should be noted that h\_L(i+1,j,k) and h\_R(i,j,k) are usually the same.}}
\DoxyCodeLine{658       h\_marg = 0.5 * (h\_l(i+1,j,k) + h\_r(i,j,k))}
\DoxyCodeLine{659  \textcolor{comment}{!    h\_marg = (2.0 * h\_L(i+1,j,k) * h\_R(i,j,k)) / \&}}
\DoxyCodeLine{660  \textcolor{comment}{!             (h\_L(i+1,j,k) + h\_R(i,j,k) + GV\%H\_subroundoff)}}
\DoxyCodeLine{661 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{662 }
\DoxyCodeLine{663     \textcolor{keywordflow}{if} (marginal) \textcolor{keywordflow}{then} ; h\_u(i,j,k) = h\_marg}
\DoxyCodeLine{664     \textcolor{keywordflow}{else} ; h\_u(i,j,k) = h\_avg ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{665 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{666   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{667     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{668     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{669       h\_u(i,j,k) = h\_u(i,j,k) * visc\_rem\_u(i,j,k)}
\DoxyCodeLine{670 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{671 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{672 }
\DoxyCodeLine{673   local\_open\_bc = .false.}
\DoxyCodeLine{674   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{675     local\_open\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{676 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{677   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{678     \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{679       \textcolor{keywordflow}{if} (obc\%segment(n)\%open .and. obc\%segment(n)\%is\_E\_or\_W) \textcolor{keywordflow}{then}}
\DoxyCodeLine{680         i = obc\%segment(n)\%HI\%IsdB}
\DoxyCodeLine{681         \textcolor{keywordflow}{if} (obc\%segment(n)\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{682           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{683             \textcolor{keywordflow}{do} j = obc\%segment(n)\%HI\%jsd, obc\%segment(n)\%HI\%jed}
\DoxyCodeLine{684               h\_u(i,j,k) = h(i,j,k) * visc\_rem\_u(i,j,k)}
\DoxyCodeLine{685 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{686 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{687             \textcolor{keywordflow}{do} j = obc\%segment(n)\%HI\%jsd, obc\%segment(n)\%HI\%jed}
\DoxyCodeLine{688               h\_u(i,j,k) = h(i,j,k)}
\DoxyCodeLine{689 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{690 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{691         \textcolor{keywordflow}{else}}
\DoxyCodeLine{692           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{693             \textcolor{keywordflow}{do} j = obc\%segment(n)\%HI\%jsd, obc\%segment(n)\%HI\%jed}
\DoxyCodeLine{694               h\_u(i,j,k) = h(i+1,j,k) * visc\_rem\_u(i,j,k)}
\DoxyCodeLine{695 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{696 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{697             \textcolor{keywordflow}{do} j = obc\%segment(n)\%HI\%jsd, obc\%segment(n)\%HI\%jed}
\DoxyCodeLine{698               h\_u(i,j,k) = h(i+1,j,k)}
\DoxyCodeLine{699 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{700 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{701 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{702 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{703 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{704 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{705 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_afad3f82b9824a13d3fe8792496e9b769}\label{namespacemom__continuity__ppm_afad3f82b9824a13d3fe8792496e9b769}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!zonal\_flux\_adjust@{zonal\_flux\_adjust}}
\index{zonal\_flux\_adjust@{zonal\_flux\_adjust}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{zonal\_flux\_adjust()}{zonal\_flux\_adjust()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+flux\+\_\+adjust (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+R,  }\item[{real, dimension(szib\+\_\+(g)), intent(in), optional}]{uhbt,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{uh\+\_\+tot\+\_\+0,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{duhdu\+\_\+tot\+\_\+0,  }\item[{real, dimension(szib\+\_\+(g)), intent(out)}]{du,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{du\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{du\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%ke), intent(in)}]{visc\+\_\+rem,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension( g \%isdb\+: g \%iedb), intent(in)}]{do\+\_\+\+I\+\_\+in,  }\item[{logical, intent(in), optional}]{full\+\_\+precision,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout), optional}]{uh\+\_\+3d,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em uhbt} & The summed volume flux through zonal faces \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em du\+\_\+max\+\_\+cfl} & Maximum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em du\+\_\+min\+\_\+cfl} & Minimum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em uh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em duhdu\+\_\+tot\+\_\+0} & The partial derivative of du\+\_\+err with du at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em du} & The barotropic velocity adjustment \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\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 j} & Spatial index. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & Start of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & End of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+i\+\_\+in} & A logical flag indicating which I values to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em full\+\_\+precision} & A flag indicating how carefully to iterate. The default is .true. (more accurate). \\
\hline
\mbox{\texttt{ in,out}}  & {\em uh\+\_\+3d} & Volume flux through zonal faces = u$\ast$h$\ast$dy \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 713 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{713   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{714 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{715 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to}}
\DoxyCodeLine{716 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}}
\DoxyCodeLine{717 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the}}
\DoxyCodeLine{718 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{719 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the}}
\DoxyCodeLine{720 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}}
\DoxyCodeLine{721 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))},         \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}}
\DoxyCodeLine{722 \textcolor{comment}{                       !! momentum originally in a layer that remains after a time-step of viscosity, and}}
\DoxyCodeLine{723 \textcolor{comment}{                       !! the fraction of a time-step's worth of a barotropic acceleration that a layer}}
\DoxyCodeLine{724 \textcolor{comment}{                       !! experiences after viscosity is applied.}}
\DoxyCodeLine{725 \textcolor{comment}{                       !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{726 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: uhbt\textcolor{comment}{ !< The summed volume flux}}
\DoxyCodeLine{727 \textcolor{comment}{                       !! through zonal faces [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{728 }
\DoxyCodeLine{729 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_max\_CFL\textcolor{comment}{  !< Maximum acceptable}}
\DoxyCodeLine{730 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}}
\DoxyCodeLine{731 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_min\_CFL\textcolor{comment}{  !< Minimum acceptable}}
\DoxyCodeLine{732 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}}
\DoxyCodeLine{733 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: uh\_tot\_0\textcolor{comment}{    !< The summed transport}}
\DoxyCodeLine{734 \textcolor{comment}{                       !! with 0 adjustment [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{735 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: duhdu\_tot\_0\textcolor{comment}{ !< The partial derivative}}
\DoxyCodeLine{736 \textcolor{comment}{                       !! of du\_err with du at 0 adjustment [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{737 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(out)}   :: du\textcolor{comment}{ !<}}
\DoxyCodeLine{738 \textcolor{comment}{                       !! The barotropic velocity adjustment [L T-1 ~> m s-1].}}
\DoxyCodeLine{739 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{740   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{741   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}}
\DoxyCodeLine{742   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{    !< Spatial index.}}
\DoxyCodeLine{743   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{  !< Start of index range.}}
\DoxyCodeLine{744   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{  !< End of index range.}}
\DoxyCodeLine{745   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))},              \textcolor{keywordtype}{intent(in)}    :: do\_I\_in\textcolor{comment}{     !<}}
\DoxyCodeLine{746 \textcolor{comment}{                       !! A logical flag indicating which I values to work on.}}
\DoxyCodeLine{747   \textcolor{keywordtype}{logical},                         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: full\_precision\textcolor{comment}{ !<}}
\DoxyCodeLine{748 \textcolor{comment}{                       !! A flag indicating how carefully to iterate.  The}}
\DoxyCodeLine{749 \textcolor{comment}{                       !! default is .true. (more accurate).}}
\DoxyCodeLine{750 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: uh\_3d\textcolor{comment}{ !<}}
\DoxyCodeLine{751 \textcolor{comment}{                       !! Volume flux through zonal faces = u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{752   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{753   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{754 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{755     uh\_aux, \&  \textcolor{comment}{! An auxiliary zonal volume flux [H L2 s-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{756     duhdu      \textcolor{comment}{! Partial derivative of uh with u [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{757 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{758     uh\_err, \&  \textcolor{comment}{! Difference between uhbt and the summed uh [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{759     uh\_err\_best, \& \textcolor{comment}{! The smallest value of uh\_err found so far [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{760     u\_new, \&   \textcolor{comment}{! The velocity with the correction added [L T-1 ~> m s-1].}}
\DoxyCodeLine{761     duhdu\_tot,\&\textcolor{comment}{! Summed partial derivative of uh with u [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{762     du\_min, \&  \textcolor{comment}{! Min/max limits on du correction based on CFL limits}}
\DoxyCodeLine{763     du\_max     \textcolor{comment}{! and previous iterations [L T-1 ~> m s-1].}}
\DoxyCodeLine{764 \textcolor{keywordtype}{  real} :: du\_prev \textcolor{comment}{! The previous value of du [L T-1 ~> m s-1].}}
\DoxyCodeLine{765 \textcolor{keywordtype}{  real} :: ddu    \textcolor{comment}{! The change in du from the previous iteration [L T-1 ~> m s-1].}}
\DoxyCodeLine{766 \textcolor{keywordtype}{  real} :: tol\_eta \textcolor{comment}{! The tolerance for the current iteration [H ~> m or kg m-2].}}
\DoxyCodeLine{767 \textcolor{keywordtype}{  real} :: tol\_vel \textcolor{comment}{! The tolerance for velocity in the current iteration [L T-1 ~> m s-1].}}
\DoxyCodeLine{768   \textcolor{keywordtype}{integer} :: i, k, nz, itt, max\_itts = 20}
\DoxyCodeLine{769   \textcolor{keywordtype}{logical} :: full\_prec, domore, do\_I(SZIB\_(G))}
\DoxyCodeLine{770 }
\DoxyCodeLine{771   nz = g\%ke}
\DoxyCodeLine{772   full\_prec = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(full\_precision)) full\_prec = full\_precision}
\DoxyCodeLine{773 }
\DoxyCodeLine{774   uh\_aux(:,:) = 0.0 ; duhdu(:,:) = 0.0}
\DoxyCodeLine{775 }
\DoxyCodeLine{776   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{777     uh\_aux(i,k) = uh\_3d(i,j,k)}
\DoxyCodeLine{778 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{779 }
\DoxyCodeLine{780   \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{781     du(i) = 0.0 ; do\_i(i) = do\_i\_in(i)}
\DoxyCodeLine{782     du\_max(i) = du\_max\_cfl(i) ; du\_min(i) = du\_min\_cfl(i)}
\DoxyCodeLine{783     uh\_err(i) = uh\_tot\_0(i) - uhbt(i) ; duhdu\_tot(i) = duhdu\_tot\_0(i)}
\DoxyCodeLine{784     uh\_err\_best(i) = abs(uh\_err(i))}
\DoxyCodeLine{785 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{786 }
\DoxyCodeLine{787   \textcolor{keywordflow}{do} itt=1,max\_itts}
\DoxyCodeLine{788     \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{789       \textcolor{keywordflow}{select case} (itt)}
\DoxyCodeLine{790         \textcolor{keywordflow}{case} (:1) ; tol\_eta = 1e-6 * cs\%tol\_eta}
\DoxyCodeLine{791         \textcolor{keywordflow}{case} (2)  ; tol\_eta = 1e-4 * cs\%tol\_eta}
\DoxyCodeLine{792         \textcolor{keywordflow}{case} (3)  ; tol\_eta = 1e-2 * cs\%tol\_eta}
\DoxyCodeLine{793 \textcolor{keywordflow}{        case default} ; tol\_eta = cs\%tol\_eta}
\DoxyCodeLine{794 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{795     \textcolor{keywordflow}{else}}
\DoxyCodeLine{796       tol\_eta = cs\%tol\_eta\_aux ; \textcolor{keywordflow}{if} (itt<=1) tol\_eta = 1e-6 * cs\%tol\_eta\_aux}
\DoxyCodeLine{797 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{798     tol\_vel = cs\%tol\_vel}
\DoxyCodeLine{799 }
\DoxyCodeLine{800     \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{801       \textcolor{keywordflow}{if} (uh\_err(i) > 0.0) \textcolor{keywordflow}{then} ; du\_max(i) = du(i)}
\DoxyCodeLine{802       \textcolor{keywordflow}{elseif} (uh\_err(i) < 0.0) \textcolor{keywordflow}{then} ; du\_min(i) = du(i)}
\DoxyCodeLine{803       \textcolor{keywordflow}{else} ; do\_i(i) = .false. ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{804 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{805     domore = .false.}
\DoxyCodeLine{806     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{807       \textcolor{keywordflow}{if} ((dt * min(g\%IareaT(i,j),g\%IareaT(i+1,j))*abs(uh\_err(i)) > tol\_eta) .or. \&}
\DoxyCodeLine{808           (cs\%better\_iter .and. ((abs(uh\_err(i)) > tol\_vel * duhdu\_tot(i)) .or. \&}
\DoxyCodeLine{809                                  (abs(uh\_err(i)) > uh\_err\_best(i))) )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{810         \textcolor{comment}{!   Use Newton's method, provided it stays bounded.  Otherwise bisect}}
\DoxyCodeLine{811         \textcolor{comment}{! the value with the appropriate bound.}}
\DoxyCodeLine{812         \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{813           ddu = -uh\_err(i) / duhdu\_tot(i)}
\DoxyCodeLine{814           du\_prev = du(i)}
\DoxyCodeLine{815           du(i) = du(i) + ddu}
\DoxyCodeLine{816           \textcolor{keywordflow}{if} (abs(ddu) < 1.0e-15*abs(du(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{817             do\_i(i) = .false. \textcolor{comment}{! ddu is small enough to quit.}}
\DoxyCodeLine{818           \textcolor{keywordflow}{elseif} (ddu > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{819             \textcolor{keywordflow}{if} (du(i) >= du\_max(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{820               du(i) = 0.5*(du\_prev + du\_max(i))}
\DoxyCodeLine{821               \textcolor{keywordflow}{if} (du\_max(i) - du\_prev < 1.0e-15*abs(du(i))) do\_i(i) = .false.}
\DoxyCodeLine{822 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{823           \textcolor{keywordflow}{else} \textcolor{comment}{! ddu < 0.0}}
\DoxyCodeLine{824             \textcolor{keywordflow}{if} (du(i) <= du\_min(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{825               du(i) = 0.5*(du\_prev + du\_min(i))}
\DoxyCodeLine{826               \textcolor{keywordflow}{if} (du\_prev - du\_min(i) < 1.0e-15*abs(du(i))) do\_i(i) = .false.}
\DoxyCodeLine{827 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{828 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{829         \textcolor{keywordflow}{else}}
\DoxyCodeLine{830           \textcolor{comment}{!   Use Newton's method, provided it stays bounded, just like above.}}
\DoxyCodeLine{831           du(i) = du(i) - uh\_err(i) / duhdu\_tot(i)}
\DoxyCodeLine{832           \textcolor{keywordflow}{if} ((du(i) >= du\_max(i)) .or. (du(i) <= du\_min(i))) \&}
\DoxyCodeLine{833             du(i) = 0.5*(du\_max(i) + du\_min(i))}
\DoxyCodeLine{834 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{835         \textcolor{keywordflow}{if} (do\_i(i)) domore = .true.}
\DoxyCodeLine{836       \textcolor{keywordflow}{else}}
\DoxyCodeLine{837         do\_i(i) = .false.}
\DoxyCodeLine{838 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{839 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{840     \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{841 }
\DoxyCodeLine{842     \textcolor{keywordflow}{if} ((itt < max\_itts) .or. \textcolor{keyword}{present}(uh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{843       \textcolor{keywordflow}{do} i=ish-1,ieh ; u\_new(i) = u(i,j,k) + du(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{844       \textcolor{keyword}{call }zonal\_flux\_layer(u\_new, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), \&}
\DoxyCodeLine{845                             uh\_aux(:,k), duhdu(:,k), visc\_rem(:,k), \&}
\DoxyCodeLine{846                             dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL, obc)}
\DoxyCodeLine{847 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{848 }
\DoxyCodeLine{849     \textcolor{keywordflow}{if} (itt < max\_itts) \textcolor{keywordflow}{then}}
\DoxyCodeLine{850       \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{851         uh\_err(i) = -uhbt(i) ; duhdu\_tot(i) = 0.0}
\DoxyCodeLine{852 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{853       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{854         uh\_err(i) = uh\_err(i) + uh\_aux(i,k)}
\DoxyCodeLine{855         duhdu\_tot(i) = duhdu\_tot(i) + duhdu(i,k)}
\DoxyCodeLine{856 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{857       \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{858         uh\_err\_best(i) = min(uh\_err\_best(i), abs(uh\_err(i)))}
\DoxyCodeLine{859 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{860 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{861 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! itt-loop}}
\DoxyCodeLine{862   \textcolor{comment}{! If there are any faces which have not converged to within the tolerance,}}
\DoxyCodeLine{863   \textcolor{comment}{! so-be-it, or else use a final upwind correction?}}
\DoxyCodeLine{864   \textcolor{comment}{! This never seems to happen with 20 iterations as max\_itt.}}
\DoxyCodeLine{865 }
\DoxyCodeLine{866   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{867     uh\_3d(i,j,k) = uh\_aux(i,k)}
\DoxyCodeLine{868 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{869 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a713196d0cfe6cb4cc8a91239a8dba02d}\label{namespacemom__continuity__ppm_a713196d0cfe6cb4cc8a91239a8dba02d}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!zonal\_flux\_layer@{zonal\_flux\_layer}}
\index{zonal\_flux\_layer@{zonal\_flux\_layer}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{zonal\_flux\_layer()}{zonal\_flux\_layer()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+flux\+\_\+layer (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{real, dimension(szib\+\_\+(g)), intent(inout)}]{uh,  }\item[{real, dimension(szib\+\_\+(g)), intent(inout)}]{duhdu,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{visc\+\_\+rem,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension(szib\+\_\+(g)), intent(in)}]{do\+\_\+I,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the zonal mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Left thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Right thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em uh} & Zonal mass or volume transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em duhdu} & Partial derivative of uh with u \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em j} & Spatial index. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & Start of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & End of index range. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+i} & Which i values to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 523 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{523   \textcolor{keywordtype}{type}(ocean\_grid\_type),        \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{        !< Ocean's grid structure.}}
\DoxyCodeLine{524 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{        !< Zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{525 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}}
\DoxyCodeLine{526 \textcolor{comment}{                        !! momentum originally in a layer that remains after a time-step}}
\DoxyCodeLine{527 \textcolor{comment}{                        !! of viscosity, and the fraction of a time-step's worth of a barotropic}}
\DoxyCodeLine{528 \textcolor{comment}{                        !! acceleration that a layer experiences after viscosity is applied.}}
\DoxyCodeLine{529 \textcolor{comment}{                        !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{530 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{        !< Layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{531 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{      !< Left thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{532 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{      !< Right thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{533 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{       !< Zonal mass or volume}}
\DoxyCodeLine{534 \textcolor{comment}{                                                          !! transport [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{535 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(inout)} :: duhdu\textcolor{comment}{    !< Partial derivative of uh}}
\DoxyCodeLine{536 \textcolor{comment}{                                                          !! with u [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{537 \textcolor{keywordtype}{  real},                         \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{  !< Time increment [T ~> s].}}
\DoxyCodeLine{538   \textcolor{keywordtype}{type}(unit\_scale\_type),        \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{       !< A dimensional unit scaling type}}
\DoxyCodeLine{539   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}}
\DoxyCodeLine{540   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}}
\DoxyCodeLine{541   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}}
\DoxyCodeLine{542   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< Which i values to work on.}}
\DoxyCodeLine{543   \textcolor{keywordtype}{logical},                      \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{  !< If true, rescale the}}
\DoxyCodeLine{544 \textcolor{comment}{          !! ratio of face areas to the cell areas when estimating the CFL number.}}
\DoxyCodeLine{545   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{546   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{547 \textcolor{keywordtype}{  real} :: CFL  \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}}
\DoxyCodeLine{548 \textcolor{keywordtype}{  real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}}
\DoxyCodeLine{549                  \textcolor{comment}{! with the same units as h\_in.}}
\DoxyCodeLine{550 \textcolor{keywordtype}{  real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}}
\DoxyCodeLine{551   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{552   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{553   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{554 }
\DoxyCodeLine{555   local\_open\_bc = .false.}
\DoxyCodeLine{556   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{557     local\_open\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{558 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{559 }
\DoxyCodeLine{560   \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{561     \textcolor{comment}{! Set new values of uh and duhdu.}}
\DoxyCodeLine{562     \textcolor{keywordflow}{if} (u(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{563       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (u(i) * dt) * (g\%dy\_Cu(i,j) * g\%IareaT(i,j))}
\DoxyCodeLine{564       \textcolor{keywordflow}{else} ; cfl = u(i) * dt * g\%IdxT(i,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{565       curv\_3 = h\_l(i) + h\_r(i) - 2.0*h(i)}
\DoxyCodeLine{566       uh(i) = g\%dy\_Cu(i,j) * u(i) * \&}
\DoxyCodeLine{567           (h\_r(i) + cfl * (0.5*(h\_l(i) - h\_r(i)) + curv\_3*(cfl - 1.5)))}
\DoxyCodeLine{568       h\_marg = h\_r(i) + cfl * ((h\_l(i) - h\_r(i)) + 3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{569     \textcolor{keywordflow}{elseif} (u(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{570       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-u(i) * dt) * (g\%dy\_Cu(i,j) * g\%IareaT(i+1,j))}
\DoxyCodeLine{571       \textcolor{keywordflow}{else} ; cfl = -u(i) * dt * g\%IdxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{572       curv\_3 = h\_l(i+1) + h\_r(i+1) - 2.0*h(i+1)}
\DoxyCodeLine{573       uh(i) = g\%dy\_Cu(i,j) * u(i) * \&}
\DoxyCodeLine{574           (h\_l(i+1) + cfl * (0.5*(h\_r(i+1)-h\_l(i+1)) + curv\_3*(cfl - 1.5)))}
\DoxyCodeLine{575       h\_marg = h\_l(i+1) + cfl * ((h\_r(i+1)-h\_l(i+1)) + 3.0*curv\_3*(cfl - 1.0))}
\DoxyCodeLine{576     \textcolor{keywordflow}{else}}
\DoxyCodeLine{577       uh(i) = 0.0}
\DoxyCodeLine{578       h\_marg = 0.5 * (h\_l(i+1) + h\_r(i))}
\DoxyCodeLine{579 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{580     duhdu(i) = g\%dy\_Cu(i,j) * h\_marg * visc\_rem(i)}
\DoxyCodeLine{581 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{582 }
\DoxyCodeLine{583   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{584     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{585       l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{586 }
\DoxyCodeLine{587       \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{588         \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{589           \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{590             uh(i) = g\%dy\_Cu(i,j) * u(i) * h(i)}
\DoxyCodeLine{591             duhdu(i) = g\%dy\_Cu(i,j) * h(i) * visc\_rem(i)}
\DoxyCodeLine{592           \textcolor{keywordflow}{else}}
\DoxyCodeLine{593             uh(i) = g\%dy\_Cu(i,j) * u(i) * h(i+1)}
\DoxyCodeLine{594             duhdu(i) = g\%dy\_Cu(i,j) * h(i+1) * visc\_rem(i)}
\DoxyCodeLine{595 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{596 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{597 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{598 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{599 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a5f5d6764ed315043d3b91b209db5c0a0}\label{namespacemom__continuity__ppm_a5f5d6764ed315043d3b91b209db5c0a0}} 
\index{mom\_continuity\_ppm@{mom\_continuity\_ppm}!zonal\_mass\_flux@{zonal\_mass\_flux}}
\index{zonal\_mass\_flux@{zonal\_mass\_flux}!mom\_continuity\_ppm@{mom\_continuity\_ppm}}
\subsubsection{\texorpdfstring{zonal\_mass\_flux()}{zonal\_mass\_flux()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+mass\+\_\+flux (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{uh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in), optional}]{uhbt,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{visc\+\_\+rem\+\_\+u,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{u\+\_\+cor,  }\item[{type(bt\+\_\+cont\+\_\+type), optional, pointer}]{B\+T\+\_\+cont }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the mass or volume fluxes through the zonal faces, and other related quantities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em uh} & Volume flux through zonal faces = u$\ast$h$\ast$dy \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\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 lb} & Loop bounds structure. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+u} & The fraction of zonal momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em uhbt} & The summed volume flux through zonal faces \\
\hline
\mbox{\texttt{ out}}  & {\em u\+\_\+cor} & The zonal velocitiess (u with a barotropic correction) that give uhbt as the depth-\/integrated transport, m s-\/1. \\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\end{DoxyParams}


Definition at line 213 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{213   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}}
\DoxyCodeLine{214   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean's vertical grid structure.}}
\DoxyCodeLine{215 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{216                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{217 \textcolor{keywordtype}{  real},  \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{218                            \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to calculate fluxes [H ~> m or kg m-2].}}
\DoxyCodeLine{219 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{220                            \textcolor{keywordtype}{intent(out)}   :: uh\textcolor{comment}{   !< Volume flux through zonal faces = u*h*dy}}
\DoxyCodeLine{221 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{222 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}}
\DoxyCodeLine{223   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{224   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}}
\DoxyCodeLine{225   \textcolor{keywordtype}{type}(loop\_bounds\_type),  \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}}
\DoxyCodeLine{226   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \&}
\DoxyCodeLine{227                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{  !< Open boundaries control structure.}}
\DoxyCodeLine{228 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{229                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_u}
\DoxyCodeLine{230                      \textcolor{comment}{!< The fraction of zonal momentum originally in a layer that remains after a}}
\DoxyCodeLine{231 \textcolor{comment}{                     !! time-step of viscosity, and the fraction of a time-step's worth of a barotropic}}
\DoxyCodeLine{232 \textcolor{comment}{                     !! acceleration that a layer experiences after viscosity is applied.}}
\DoxyCodeLine{233 \textcolor{comment}{                     !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{234 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{235                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: uhbt\textcolor{comment}{ !< The summed volume flux through zonal faces}}
\DoxyCodeLine{236 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{237 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{238                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: u\_cor}
\DoxyCodeLine{239                      \textcolor{comment}{!< The zonal velocitiess (u with a barotropic correction)}}
\DoxyCodeLine{240 \textcolor{comment}{                     !! that give uhbt as the depth-integrated transport, m s-1.}}
\DoxyCodeLine{241   \textcolor{keywordtype}{type}(BT\_cont\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}  :: BT\_cont\textcolor{comment}{ !< A structure with elements that describe the}}
\DoxyCodeLine{242 \textcolor{comment}{                     !! effective open face areas as a function of barotropic flow.}}
\DoxyCodeLine{243 }
\DoxyCodeLine{244   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{245 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))} :: duhdu \textcolor{comment}{! Partial derivative of uh with u [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{246 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: h\_L, h\_R \textcolor{comment}{! Left and right face thicknesses [H ~> m or kg m-2].}}
\DoxyCodeLine{247 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{248     du, \&      \textcolor{comment}{! Corrective barotropic change in the velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{249     du\_min\_CFL, \& \textcolor{comment}{! Min/max limits on du correction}}
\DoxyCodeLine{250     du\_max\_CFL, \& \textcolor{comment}{! to avoid CFL violations}}
\DoxyCodeLine{251     duhdu\_tot\_0, \& \textcolor{comment}{! Summed partial derivative of uh with u [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{252     uh\_tot\_0, \& \textcolor{comment}{! Summed transport with no barotropic correction [H L2 T-1 ~> m3 s-1 or kg s-1].}}
\DoxyCodeLine{253     visc\_rem\_max  \textcolor{comment}{! The column maximum of visc\_rem.}}
\DoxyCodeLine{254   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: do\_I}
\DoxyCodeLine{255 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{256     visc\_rem      \textcolor{comment}{! A 2-D copy of visc\_rem\_u or an array of 1's.}}
\DoxyCodeLine{257 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: FAuI  \textcolor{comment}{! A list of sums of zonal face areas [H L ~> m2 or kg m-1].}}
\DoxyCodeLine{258 \textcolor{keywordtype}{  real} :: FA\_u    \textcolor{comment}{! A sum of zonal face areas [H m ~> m2 or kg m-1].}}
\DoxyCodeLine{259 \textcolor{keywordtype}{  real} :: I\_vrm   \textcolor{comment}{! 1.0 / visc\_rem\_max, nondim.}}
\DoxyCodeLine{260 \textcolor{keywordtype}{  real} :: CFL\_dt  \textcolor{comment}{! The maximum CFL ratio of the adjusted velocities divided by}}
\DoxyCodeLine{261                   \textcolor{comment}{! the time step [T-1 ~> s-1].}}
\DoxyCodeLine{262 \textcolor{keywordtype}{  real} :: I\_dt    \textcolor{comment}{! 1.0 / dt [T-1 ~> s-1].}}
\DoxyCodeLine{263 \textcolor{keywordtype}{  real} :: du\_lim  \textcolor{comment}{! The velocity change that give a relative CFL of 1 [L T-1 ~> m s-1].}}
\DoxyCodeLine{264 \textcolor{keywordtype}{  real} :: dx\_E, dx\_W \textcolor{comment}{! Effective x-grid spacings to the east and west [L ~> m].}}
\DoxyCodeLine{265   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, n, nz}
\DoxyCodeLine{266   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{267   \textcolor{keywordtype}{logical} :: local\_specified\_BC, use\_visc\_rem, set\_BT\_cont, any\_simple\_OBC}
\DoxyCodeLine{268   \textcolor{keywordtype}{logical} :: local\_Flather\_OBC, local\_open\_BC, is\_simple}
\DoxyCodeLine{269   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()}
\DoxyCodeLine{270 }
\DoxyCodeLine{271   use\_visc\_rem = \textcolor{keyword}{present}(visc\_rem\_u)}
\DoxyCodeLine{272   local\_specified\_bc = .false. ; set\_bt\_cont = .false. ; local\_flather\_obc = .false.}
\DoxyCodeLine{273   local\_open\_bc = .false.}
\DoxyCodeLine{274   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bt\_cont)) set\_bt\_cont = (\textcolor{keyword}{associated}(bt\_cont))}
\DoxyCodeLine{275   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{276     local\_specified\_bc = obc\%specified\_u\_BCs\_exist\_globally}
\DoxyCodeLine{277     local\_flather\_obc = obc\%Flather\_u\_BCs\_exist\_globally}
\DoxyCodeLine{278     local\_open\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{279 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{280   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh ; nz = g\%ke}
\DoxyCodeLine{281 }
\DoxyCodeLine{282   cfl\_dt = cs\%CFL\_limit\_adjust / dt}
\DoxyCodeLine{283   i\_dt = 1.0 / dt}
\DoxyCodeLine{284   \textcolor{keywordflow}{if} (cs\%aggress\_adjust) cfl\_dt = i\_dt}
\DoxyCodeLine{285 }
\DoxyCodeLine{286   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)}
\DoxyCodeLine{287 \textcolor{comment}{!\$OMP parallel do default(none) shared(ish,ieh,jsh,jeh,nz,CS,h\_L,h\_in,h\_R,G,GV,LB,visc\_rem,OBC)}}
\DoxyCodeLine{288   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{289     \textcolor{comment}{! This sets h\_L and h\_R.}}
\DoxyCodeLine{290     \textcolor{keywordflow}{if} (cs\%upwind\_1st) \textcolor{keywordflow}{then}}
\DoxyCodeLine{291       \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh+1}
\DoxyCodeLine{292         h\_l(i,j,k) = h\_in(i,j,k) ; h\_r(i,j,k) = h\_in(i,j,k)}
\DoxyCodeLine{293 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{294     \textcolor{keywordflow}{else}}
\DoxyCodeLine{295       \textcolor{keyword}{call }ppm\_reconstruction\_x(h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), g, lb, \&}
\DoxyCodeLine{296                                 2.0*gv\%Angstrom\_H, cs\%monotonic, simple\_2nd=cs\%simple\_2nd, obc=obc)}
\DoxyCodeLine{297 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{298     \textcolor{keywordflow}{do} i=ish-1,ieh ; visc\_rem(i,k) = 1.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{299 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{300   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)}
\DoxyCodeLine{301 }
\DoxyCodeLine{302   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_correct)}
\DoxyCodeLine{303 \textcolor{comment}{!\$OMP parallel do default(none) shared(ish,ieh,jsh,jeh,nz,u,h\_in,h\_L,h\_R,use\_visc\_rem,visc\_rem\_u,  \&}}
\DoxyCodeLine{304 \textcolor{comment}{!\$OMP                                  uh,dt,US,G,GV,CS,local\_specified\_BC,OBC,uhbt,set\_BT\_cont,    \&}}
\DoxyCodeLine{305 \textcolor{comment}{!\$OMP                                  CFL\_dt,I\_dt,u\_cor,BT\_cont, local\_Flather\_OBC) \&}}
\DoxyCodeLine{306 \textcolor{comment}{!\$OMP                          private(do\_I,duhdu,du,du\_max\_CFL,du\_min\_CFL,uh\_tot\_0,duhdu\_tot\_0, \&}}
\DoxyCodeLine{307 \textcolor{comment}{!\$OMP                                  is\_simple,FAuI,visc\_rem\_max,I\_vrm,du\_lim,dx\_E,dx\_W, \&}}
\DoxyCodeLine{308 \textcolor{comment}{!\$OMP                                  any\_simple\_OBC,l\_seg) \&}}
\DoxyCodeLine{309 \textcolor{comment}{!\$OMP      firstprivate(visc\_rem)}}
\DoxyCodeLine{310   \textcolor{keywordflow}{do} j=jsh,jeh}
\DoxyCodeLine{311     \textcolor{keywordflow}{do} i=ish-1,ieh ; do\_i(i) = .true. ; visc\_rem\_max(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{312     \textcolor{comment}{! Set uh and duhdu.}}
\DoxyCodeLine{313     \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{314       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{315         visc\_rem(i,k) = visc\_rem\_u(i,j,k)}
\DoxyCodeLine{316         visc\_rem\_max(i) = max(visc\_rem\_max(i), visc\_rem(i,k))}
\DoxyCodeLine{317 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{318       \textcolor{keyword}{call }zonal\_flux\_layer(u(:,j,k), h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), \&}
\DoxyCodeLine{319                             uh(:,j,k), duhdu(:,k), visc\_rem(:,k), \&}
\DoxyCodeLine{320                             dt, g, us, j, ish, ieh, do\_i, cs\%vol\_CFL, obc)}
\DoxyCodeLine{321       \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{322         \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{323           l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{324 }
\DoxyCodeLine{325           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{326             \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%specified) \&}
\DoxyCodeLine{327               uh(i,j,k) = obc\%segment(l\_seg)\%normal\_trans(i,j,k)}
\DoxyCodeLine{328 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{329 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{330 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{331 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{332 }
\DoxyCodeLine{333     \textcolor{keywordflow}{if} ((.not.use\_visc\_rem).or.(.not.cs\%use\_visc\_rem\_max)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{334       visc\_rem\_max(i) = 1.0}
\DoxyCodeLine{335 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{336 }
\DoxyCodeLine{337     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{338       \textcolor{comment}{!   Set limits on du that will keep the CFL number between -1 and 1.}}
\DoxyCodeLine{339       \textcolor{comment}{! This should be adequate to keep the root bracketed in all cases.}}
\DoxyCodeLine{340       \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{341         i\_vrm = 0.0}
\DoxyCodeLine{342         \textcolor{keywordflow}{if} (visc\_rem\_max(i) > 0.0) i\_vrm = 1.0 / visc\_rem\_max(i)}
\DoxyCodeLine{343         \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{344           dx\_w = ratio\_max(g\%areaT(i,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i,j))}
\DoxyCodeLine{345           dx\_e = ratio\_max(g\%areaT(i+1,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i+1,j))}
\DoxyCodeLine{346         \textcolor{keywordflow}{else} ; dx\_w = g\%dxT(i,j) ; dx\_e = g\%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{347         du\_max\_cfl(i) = 2.0* (cfl\_dt * dx\_w) * i\_vrm}
\DoxyCodeLine{348         du\_min\_cfl(i) = -2.0 * (cfl\_dt * dx\_e) * i\_vrm}
\DoxyCodeLine{349         uh\_tot\_0(i) = 0.0 ; duhdu\_tot\_0(i) = 0.0}
\DoxyCodeLine{350 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{351       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{352         duhdu\_tot\_0(i) = duhdu\_tot\_0(i) + duhdu(i,k)}
\DoxyCodeLine{353         uh\_tot\_0(i) = uh\_tot\_0(i) + uh(i,j,k)}
\DoxyCodeLine{354 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{355       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then}}
\DoxyCodeLine{356         \textcolor{keywordflow}{if} (cs\%aggress\_adjust) \textcolor{keywordflow}{then}}
\DoxyCodeLine{357           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{358             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{359               dx\_w = ratio\_max(g\%areaT(i,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i,j))}
\DoxyCodeLine{360               dx\_e = ratio\_max(g\%areaT(i+1,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i+1,j))}
\DoxyCodeLine{361             \textcolor{keywordflow}{else} ; dx\_w = g\%dxT(i,j) ; dx\_e = g\%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{362 }
\DoxyCodeLine{363             du\_lim = 0.499*((dx\_w*i\_dt - u(i,j,k)) + min(0.0,u(i-1,j,k)))}
\DoxyCodeLine{364             \textcolor{keywordflow}{if} (du\_max\_cfl(i) * visc\_rem(i,k) > du\_lim) \&}
\DoxyCodeLine{365               du\_max\_cfl(i) = du\_lim / visc\_rem(i,k)}
\DoxyCodeLine{366 }
\DoxyCodeLine{367             du\_lim = 0.499*((-dx\_e*i\_dt - u(i,j,k)) + max(0.0,u(i+1,j,k)))}
\DoxyCodeLine{368             \textcolor{keywordflow}{if} (du\_min\_cfl(i) * visc\_rem(i,k) < du\_lim) \&}
\DoxyCodeLine{369               du\_min\_cfl(i) = du\_lim / visc\_rem(i,k)}
\DoxyCodeLine{370 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{371         \textcolor{keywordflow}{else}}
\DoxyCodeLine{372           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{373             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{374               dx\_w = ratio\_max(g\%areaT(i,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i,j))}
\DoxyCodeLine{375               dx\_e = ratio\_max(g\%areaT(i+1,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i+1,j))}
\DoxyCodeLine{376             \textcolor{keywordflow}{else} ; dx\_w = g\%dxT(i,j) ; dx\_e = g\%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{377 }
\DoxyCodeLine{378             \textcolor{keywordflow}{if} (du\_max\_cfl(i) * visc\_rem(i,k) > dx\_w*cfl\_dt - u(i,j,k)) \&}
\DoxyCodeLine{379               du\_max\_cfl(i) = (dx\_w*cfl\_dt - u(i,j,k)) / visc\_rem(i,k)}
\DoxyCodeLine{380             \textcolor{keywordflow}{if} (du\_min\_cfl(i) * visc\_rem(i,k) < -dx\_e*cfl\_dt - u(i,j,k)) \&}
\DoxyCodeLine{381               du\_min\_cfl(i) = -(dx\_e*cfl\_dt + u(i,j,k)) / visc\_rem(i,k)}
\DoxyCodeLine{382 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{383 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{384       \textcolor{keywordflow}{else}}
\DoxyCodeLine{385         \textcolor{keywordflow}{if} (cs\%aggress\_adjust) \textcolor{keywordflow}{then}}
\DoxyCodeLine{386           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{387             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{388               dx\_w = ratio\_max(g\%areaT(i,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i,j))}
\DoxyCodeLine{389               dx\_e = ratio\_max(g\%areaT(i+1,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i+1,j))}
\DoxyCodeLine{390             \textcolor{keywordflow}{else} ; dx\_w = g\%dxT(i,j) ; dx\_e = g\%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{391 }
\DoxyCodeLine{392             du\_max\_cfl(i) = min(du\_max\_cfl(i), 0.499 * \&}
\DoxyCodeLine{393                         ((dx\_w*i\_dt - u(i,j,k)) + min(0.0,u(i-1,j,k))) )}
\DoxyCodeLine{394             du\_min\_cfl(i) = max(du\_min\_cfl(i), 0.499 * \&}
\DoxyCodeLine{395                         ((-dx\_e*i\_dt - u(i,j,k)) + max(0.0,u(i+1,j,k))) )}
\DoxyCodeLine{396 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{397         \textcolor{keywordflow}{else}}
\DoxyCodeLine{398           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{399             \textcolor{keywordflow}{if} (cs\%vol\_CFL) \textcolor{keywordflow}{then}}
\DoxyCodeLine{400               dx\_w = ratio\_max(g\%areaT(i,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i,j))}
\DoxyCodeLine{401               dx\_e = ratio\_max(g\%areaT(i+1,j), g\%dy\_Cu(i,j), 1000.0*g\%dxT(i+1,j))}
\DoxyCodeLine{402             \textcolor{keywordflow}{else} ; dx\_w = g\%dxT(i,j) ; dx\_e = g\%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{403 }
\DoxyCodeLine{404             du\_max\_cfl(i) = min(du\_max\_cfl(i), dx\_w*cfl\_dt - u(i,j,k))}
\DoxyCodeLine{405             du\_min\_cfl(i) = max(du\_min\_cfl(i), -(dx\_e*cfl\_dt + u(i,j,k)))}
\DoxyCodeLine{406 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{407 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{408 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{409       \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{410         du\_max\_cfl(i) = max(du\_max\_cfl(i),0.0)}
\DoxyCodeLine{411         du\_min\_cfl(i) = min(du\_min\_cfl(i),0.0)}
\DoxyCodeLine{412 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{413 }
\DoxyCodeLine{414       any\_simple\_obc = .false.}
\DoxyCodeLine{415       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{416         \textcolor{keywordflow}{if} (local\_specified\_bc .or. local\_flather\_obc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{417           l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{418 }
\DoxyCodeLine{419           \textcolor{comment}{! Avoid reconciling barotropic/baroclinic transports if transport is specified}}
\DoxyCodeLine{420           is\_simple = .false.}
\DoxyCodeLine{421           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \&}
\DoxyCodeLine{422             is\_simple = obc\%segment(l\_seg)\%specified}
\DoxyCodeLine{423           do\_i(i) = .not. (l\_seg /= obc\_none .and. is\_simple)}
\DoxyCodeLine{424           any\_simple\_obc = any\_simple\_obc .or. is\_simple}
\DoxyCodeLine{425 \textcolor{keywordflow}{        enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{426           do\_i(i) = .true.}
\DoxyCodeLine{427 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{428 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{429 }
\DoxyCodeLine{430       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhbt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{431         \textcolor{keyword}{call }zonal\_flux\_adjust(u, h\_in, h\_l, h\_r, uhbt(:,j), uh\_tot\_0, duhdu\_tot\_0, du, \&}
\DoxyCodeLine{432                                du\_max\_cfl, du\_min\_cfl, dt, g, us, cs, visc\_rem, \&}
\DoxyCodeLine{433                                j, ish, ieh, do\_i, .true., uh, obc=obc)}
\DoxyCodeLine{434 }
\DoxyCodeLine{435         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(u\_cor)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{436           \textcolor{keywordflow}{do} i=ish-1,ieh ; u\_cor(i,j,k) = u(i,j,k) + du(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{437           \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{438             l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{439 }
\DoxyCodeLine{440             \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{441               \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%specified) \&}
\DoxyCodeLine{442                 u\_cor(i,j,k) = obc\%segment(l\_seg)\%normal\_vel(i,j,k)}
\DoxyCodeLine{443 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{444 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{445 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif} \textcolor{comment}{! u-corrected}}
\DoxyCodeLine{446 }
\DoxyCodeLine{447 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{448 }
\DoxyCodeLine{449       \textcolor{keywordflow}{if} (set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{450         \textcolor{keyword}{call }set\_zonal\_bt\_cont(u, h\_in, h\_l, h\_r, bt\_cont, uh\_tot\_0, duhdu\_tot\_0,\&}
\DoxyCodeLine{451                                du\_max\_cfl, du\_min\_cfl, dt, g, us, cs, visc\_rem, \&}
\DoxyCodeLine{452                                visc\_rem\_max, j, ish, ieh, do\_i)}
\DoxyCodeLine{453         \textcolor{keywordflow}{if} (any\_simple\_obc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{454           \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{455             l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{456 }
\DoxyCodeLine{457             do\_i(i) = .false.}
\DoxyCodeLine{458             \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \&}
\DoxyCodeLine{459               do\_i(i) = obc\%segment(l\_seg)\%specified}
\DoxyCodeLine{460 }
\DoxyCodeLine{461             \textcolor{keywordflow}{if} (do\_i(i)) faui(i) = gv\%H\_subroundoff*g\%dy\_Cu(i,j)}
\DoxyCodeLine{462 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{463           \textcolor{comment}{! NOTE: do\_I(I) should prevent access to segment OBC\_NONE}}
\DoxyCodeLine{464           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{465             \textcolor{keywordflow}{if} ((abs(obc\%segment(obc\%segnum\_u(i,j))\%normal\_vel(i,j,k)) > 0.0) .and. \&}
\DoxyCodeLine{466                 (obc\%segment(obc\%segnum\_u(i,j))\%specified)) \&}
\DoxyCodeLine{467               faui(i) = faui(i) + obc\%segment(obc\%segnum\_u(i,j))\%normal\_trans(i,j,k) / \&}
\DoxyCodeLine{468                                   obc\%segment(obc\%segnum\_u(i,j))\%normal\_vel(i,j,k)}
\DoxyCodeLine{469 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{470           \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{471             bt\_cont\%FA\_u\_W0(i,j) = faui(i) ; bt\_cont\%FA\_u\_E0(i,j) = faui(i)}
\DoxyCodeLine{472             bt\_cont\%FA\_u\_WW(i,j) = faui(i) ; bt\_cont\%FA\_u\_EE(i,j) = faui(i)}
\DoxyCodeLine{473             bt\_cont\%uBT\_WW(i,j) = 0.0 ; bt\_cont\%uBT\_EE(i,j) = 0.0}
\DoxyCodeLine{474 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{475 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{476 \textcolor{keywordflow}{      endif} \textcolor{comment}{! set\_BT\_cont}}
\DoxyCodeLine{477 }
\DoxyCodeLine{478 \textcolor{keywordflow}{    endif} \textcolor{comment}{! present(uhbt) or set\_BT\_cont}}
\DoxyCodeLine{479 }
\DoxyCodeLine{480 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}
\DoxyCodeLine{481 }
\DoxyCodeLine{482   \textcolor{keywordflow}{if} (local\_open\_bc .and. set\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483     \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{484       \textcolor{keywordflow}{if} (obc\%segment(n)\%open .and. obc\%segment(n)\%is\_E\_or\_W) \textcolor{keywordflow}{then}}
\DoxyCodeLine{485         i = obc\%segment(n)\%HI\%IsdB}
\DoxyCodeLine{486         \textcolor{keywordflow}{if} (obc\%segment(n)\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{487           \textcolor{keywordflow}{do} j = obc\%segment(n)\%HI\%Jsd, obc\%segment(n)\%HI\%Jed}
\DoxyCodeLine{488             fa\_u = 0.0}
\DoxyCodeLine{489             \textcolor{keywordflow}{do} k=1,nz ; fa\_u = fa\_u + h\_in(i,j,k)*g\%dy\_Cu(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{490             bt\_cont\%FA\_u\_W0(i,j) = fa\_u ; bt\_cont\%FA\_u\_E0(i,j) = fa\_u}
\DoxyCodeLine{491             bt\_cont\%FA\_u\_WW(i,j) = fa\_u ; bt\_cont\%FA\_u\_EE(i,j) = fa\_u}
\DoxyCodeLine{492             bt\_cont\%uBT\_WW(i,j) = 0.0 ; bt\_cont\%uBT\_EE(i,j) = 0.0}
\DoxyCodeLine{493 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{494         \textcolor{keywordflow}{else}}
\DoxyCodeLine{495           \textcolor{keywordflow}{do} j = obc\%segment(n)\%HI\%Jsd, obc\%segment(n)\%HI\%Jed}
\DoxyCodeLine{496             fa\_u = 0.0}
\DoxyCodeLine{497             \textcolor{keywordflow}{do} k=1,nz ; fa\_u = fa\_u + h\_in(i+1,j,k)*g\%dy\_Cu(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{498             bt\_cont\%FA\_u\_W0(i,j) = fa\_u ; bt\_cont\%FA\_u\_E0(i,j) = fa\_u}
\DoxyCodeLine{499             bt\_cont\%FA\_u\_WW(i,j) = fa\_u ; bt\_cont\%FA\_u\_EE(i,j) = fa\_u}
\DoxyCodeLine{500             bt\_cont\%uBT\_WW(i,j) = 0.0 ; bt\_cont\%uBT\_EE(i,j) = 0.0}
\DoxyCodeLine{501 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{502 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{503 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{504 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{505 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{506   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_correct)}
\DoxyCodeLine{507 }
\DoxyCodeLine{508   \textcolor{keywordflow}{if}  (set\_bt\_cont) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(bt\_cont\%h\_u)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{509     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(u\_cor)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{510       \textcolor{keyword}{call }zonal\_face\_thickness(u\_cor, h\_in, h\_l, h\_r, bt\_cont\%h\_u, dt, g, us, lb, \&}
\DoxyCodeLine{511                                 cs\%vol\_CFL, cs\%marginal\_faces, visc\_rem\_u, obc)}
\DoxyCodeLine{512     \textcolor{keywordflow}{else}}
\DoxyCodeLine{513       \textcolor{keyword}{call }zonal\_face\_thickness(u, h\_in, h\_l, h\_r, bt\_cont\%h\_u, dt, g, us, lb, \&}
\DoxyCodeLine{514                                 cs\%vol\_CFL, cs\%marginal\_faces, visc\_rem\_u, obc)}
\DoxyCodeLine{515 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{516 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{517 }

\end{DoxyCode}
