\hypertarget{namespacemom__barotropic}{}\doxysection{mom\+\_\+barotropic Module Reference}
\label{namespacemom__barotropic}\index{mom\_barotropic@{mom\_barotropic}}


\doxysubsection{Detailed Description}
Baropotric solver. 

By Robert Hallberg, April 1994 -\/ January 2007.

This program contains the subroutines that time steps the linearized barotropic equations. btstep is used to actually time step the barotropic equations, and contains most of the substance of this module.

btstep uses a forwards-\/backwards based scheme to time step the barotropic equations, returning the layers\textquotesingle{} accelerations due to the barotropic changes in the ocean state, the final free surface height (or column mass), and the volume (or mass) fluxes summed through the layers and averaged over the baroclinic time step. As input, btstep takes the initial 3-\/D velocities, the inital free surface height, the 3-\/D accelerations of the layers, and the external forcing. Everything in btstep is cast in terms of anomalies, so if everything is in balance, there is explicitly no acceleration due to btstep.

The spatial discretization of the continuity equation is second order accurate. A flux conservative form is used to guarantee global conservation of volume. The spatial discretization of the momentum equation is second order accurate. The Coriolis force is written in a form which does not contribute to the energy tendency and which conserves linearized potential vorticity, f/D. These terms are exactly removed from the baroclinic momentum equations, so the linearization of vorticity advection will not degrade the overall solution.

btcalc calculates the fractional thickness of each layer at the velocity points, for later use in calculating the barotropic velocities and the averaged accelerations. Harmonic mean thicknesses (i.\+e. 2$\ast$h\+\_\+\+L$\ast$h\+\_\+\+R/(h\+\_\+L + h\+\_\+R)) are used to avoid overly strong weighting of overly thin layers. This may later be relaxed to use thicknesses determined from the continuity equations.

bt\+\_\+mass\+\_\+source determines the real mass sources for the barotropic solver, along with the corrective pseudo-\/fluxes that keep the barotropic and baroclinic estimates of the free surface height close to each other. Given the layer thicknesses and the free surface height that correspond to each other, it calculates a corrective mass source that is added to the barotropic continuity$\ast$ equation, and optionally adjusts a slowly varying correction rate. Newer algorithmic changes have deemphasized the need for this, but it is still here to add net water sources to the barotropic solver.$\ast$

barotropic\+\_\+init allocates and initializes any barotropic arrays that have not been read from a restart file, reads parameters from the inputfile, and sets up diagnostic fields.

barotropic\+\_\+end deallocates anything allocated in barotropic\+\_\+init or register\+\_\+barotropic\+\_\+restarts.

register\+\_\+barotropic\+\_\+restarts is used to indicate any fields that are private to the barotropic solver that need to be included in the restart files, and to ensure that they are read. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The barotropic stepping control stucture. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__barotropic_1_1bt__obc__type}{bt\+\_\+obc\+\_\+type}}
\begin{DoxyCompactList}\small\item\em The barotropic stepping open boundary condition type. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}
\begin{DoxyCompactList}\small\item\em A desciption of the functional dependence of transport at a u-\/point. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}
\begin{DoxyCompactList}\small\item\em A desciption of the functional dependence of transport at a v-\/point. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}
\begin{DoxyCompactList}\small\item\em A container for passing around active tracer point memory limits. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_ac60353f002de5980317d117a3db1a075}{btstep}} (U\+\_\+in, V\+\_\+in, eta\+\_\+in, dt, bc\+\_\+accel\+\_\+u, bc\+\_\+accel\+\_\+v, forces, pbce, eta\+\_\+\+P\+F\+\_\+in, U\+\_\+\+Cor, V\+\_\+\+Cor, accel\+\_\+layer\+\_\+u, accel\+\_\+layer\+\_\+v, eta\+\_\+out, uhbtav, vhbtav, G, GV, US, CS, visc\+\_\+rem\+\_\+u, visc\+\_\+rem\+\_\+v, etaav, A\+Dp, O\+BC, B\+T\+\_\+cont, eta\+\_\+\+P\+F\+\_\+start, taux\+\_\+bot, tauy\+\_\+bot, uh0, vh0, u\+\_\+uh0, v\+\_\+vh0)
\begin{DoxyCompactList}\small\item\em This subroutine time steps the barotropic equations explicitly. For gravity waves, anything between a forwards-\/backwards scheme and a simulated backwards Euler scheme is used, with bebt between 0.\+0 and 1.\+0 determining the scheme. In practice, bebt must be of order 0.\+2 or greater. A forwards-\/backwards treatment of the Coriolis terms is always used. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_a486257b675aa4e81c2d1634b5288a67f}{set\+\_\+dtbt}} (G, GV, US, CS, eta, pbce, B\+T\+\_\+cont, gtot\+\_\+est, S\+S\+H\+\_\+add)
\begin{DoxyCompactList}\small\item\em This subroutine automatically determines an optimal value for dtbt based on some state of the ocean. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_ac9d3db838f0cbee31785077b261c0ad1}{apply\+\_\+velocity\+\_\+obcs}} (O\+BC, ubt, vbt, uhbt, vhbt, ubt\+\_\+trans, vbt\+\_\+trans, eta, ubt\+\_\+old, vbt\+\_\+old, B\+T\+\_\+\+O\+BC, G, MS, US, halo, dtbt, bebt, use\+\_\+\+B\+T\+\_\+cont, integral\+\_\+\+B\+T\+\_\+cont, dt\+\_\+elapsed, Datu, Datv, B\+T\+C\+L\+\_\+u, B\+T\+C\+L\+\_\+v, uhbt0, vhbt0, ubt\+\_\+int, vbt\+\_\+int, uhbt\+\_\+int, vhbt\+\_\+int)
\begin{DoxyCompactList}\small\item\em The following 4 subroutines apply the open boundary conditions. This subroutine applies the open boundary conditions on barotropic velocities and mass transports, as developed by Mehmet Ilicak. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_af8296e1b2f7a24a091c7ad563393edb0}{set\+\_\+up\+\_\+bt\+\_\+obc}} (O\+BC, eta, B\+T\+\_\+\+O\+BC, B\+T\+\_\+\+Domain, G, GV, US, MS, halo, use\+\_\+\+B\+T\+\_\+cont, integral\+\_\+\+B\+T\+\_\+cont, dt\+\_\+baroclinic, Datu, Datv, B\+T\+C\+L\+\_\+u, B\+T\+C\+L\+\_\+v)
\begin{DoxyCompactList}\small\item\em This subroutine sets up the private structure used to apply the open boundary conditions, as developed by Mehmet Ilicak. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_ac8250401fa646cce0f3108587caf19be}{destroy\+\_\+bt\+\_\+obc}} (B\+T\+\_\+\+O\+BC)
\begin{DoxyCompactList}\small\item\em Clean up the B\+T\+\_\+\+O\+BC memory. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_aa60ee766449413de40cdbc19964a6556}{btcalc}} (h, G, GV, CS, h\+\_\+u, h\+\_\+v, may\+\_\+use\+\_\+default, O\+BC)
\begin{DoxyCompactList}\small\item\em btcalc calculates the barotropic velocities from the full velocity and thickness fields, determines the fraction of the total water column in each layer at velocity points, and determines a corrective fictitious mass source that will drive the barotropic estimate of the free surface height toward the baroclinic estimate. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__barotropic_a8ad2b12e885746401a97fd65ad189722}{find\+\_\+uhbt}} (u, B\+TC)
\begin{DoxyCompactList}\small\item\em The function find\+\_\+uhbt determines the zonal transport for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True it determines the time-\/integrated zonal transport for a given time-\/integrated velocity. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__barotropic_abcc5b7bef6e5c17630b05962d61995e3}{find\+\_\+duhbt\+\_\+du}} (u, B\+TC)
\begin{DoxyCompactList}\small\item\em The function find\+\_\+duhbt\+\_\+du determines the marginal zonal face area for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True for a given time-\/integrated velocity. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__barotropic_a0311f0f3d4e27f4017582d6a8c01298c}{uhbt\+\_\+to\+\_\+ubt}} (uhbt, B\+TC, guess)
\begin{DoxyCompactList}\small\item\em This function inverts the transport function to determine the barotopic velocity that is consistent with a given transport, or if I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True this finds the time-\/integrated velocity that is consistent with a time-\/integrated transport. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__barotropic_ae96b701027f6f77feed0f68515b31e55}{find\+\_\+vhbt}} (v, B\+TC)
\begin{DoxyCompactList}\small\item\em The function find\+\_\+vhbt determines the meridional transport for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True it determines the time-\/integrated meridional transport for a given time-\/integrated velocity. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__barotropic_a951d827a745c277e8950a091c060ee86}{find\+\_\+dvhbt\+\_\+dv}} (v, B\+TC)
\begin{DoxyCompactList}\small\item\em The function find\+\_\+dvhbt\+\_\+dv determines the marginal meridional face area for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True for a given time-\/integrated velocity. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__barotropic_aeed3e618781611b448105a122e1a358c}{vhbt\+\_\+to\+\_\+vbt}} (vhbt, B\+TC, guess)
\begin{DoxyCompactList}\small\item\em This function inverts the transport function to determine the barotopic velocity that is consistent with a given transport, or if I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True this finds the time-\/integrated velocity that is consistent with a time-\/integrated transport. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_a2be327af11ae54368acd32a3ba360ac4}{set\+\_\+local\+\_\+bt\+\_\+cont\+\_\+types}} (B\+T\+\_\+cont, B\+T\+C\+L\+\_\+u, B\+T\+C\+L\+\_\+v, G, US, MS, B\+T\+\_\+\+Domain, halo, dt\+\_\+baroclinic)
\begin{DoxyCompactList}\small\item\em This subroutine sets up reordered versions of the B\+T\+\_\+cont type in the local\+\_\+\+B\+T\+\_\+cont types, which have wide halos properly filled in. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_a6cf9cc852f7d2fb328fae4cad1c287c1}{adjust\+\_\+local\+\_\+bt\+\_\+cont\+\_\+types}} (ubt, uhbt, vbt, vhbt, B\+T\+C\+L\+\_\+u, B\+T\+C\+L\+\_\+v, G, US, MS, halo, dt\+\_\+baroclinic)
\begin{DoxyCompactList}\small\item\em Adjust\+\_\+local\+\_\+\+B\+T\+\_\+cont\+\_\+types expands the range of velocities with a cubic curve translating velocities into transports to match the inital values of velocities and summed transports when the velocities are larger than the first guesses of the cubic transition velocities used to set up the local\+\_\+\+B\+T\+\_\+cont types. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_ac7100cec548b4bf6d69d4a52e074a04f}{bt\+\_\+cont\+\_\+to\+\_\+face\+\_\+areas}} (B\+T\+\_\+cont, Datu, Datv, G, US, MS, halo, maximize)
\begin{DoxyCompactList}\small\item\em This subroutine uses the B\+T\+CL types to find typical or maximum face areas, which can then be used for finding wave speeds, etc. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_af1813744cf2034c2413ef904bf628263}{swap}} (a, b)
\begin{DoxyCompactList}\small\item\em Swap the values of two real variables. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__barotropic_aba29d11dc2530622be997c069fb932ae}{find\+\_\+face\+\_\+areas}} (Datu, Datv, G, GV, US, CS, MS, eta, halo, add\+\_\+max)
\begin{DoxyCompactList}\small\item\em This subroutine determines the open face areas of cells for calculating the barotropic transport. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_a856387dc8ee2b7b50ea2bd9fca16db78}{bt\+\_\+mass\+\_\+source}} (h, eta, set\+\_\+cor, G, GV, CS)
\begin{DoxyCompactList}\small\item\em bt\+\_\+mass\+\_\+source determines the appropriately limited mass source for the barotropic solver, along with a corrective fictitious mass source that will drive the barotropic estimate of the free surface height toward the baroclinic estimate. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_a59244968890766632554a6d271ec4499}{barotropic\+\_\+init}} (u, v, h, eta, Time, G, GV, US, param\+\_\+file, diag, CS, restart\+\_\+\+CS, calc\+\_\+dtbt, B\+T\+\_\+cont, tides\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em barotropic\+\_\+init initializes a number of time-\/invariant fields used in the barotropic calculation and initializes any barotropic fields that have not already been initialized. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_aa059fdf7e6002b13d942f96ef17a5db6}{barotropic\+\_\+get\+\_\+tav}} (CS, ubtav, vbtav, G, US)
\begin{DoxyCompactList}\small\item\em Copies ubtav and vbtav from private type into arrays. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_aee694cdef3a20b960aff1ec4fa5da28f}{barotropic\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clean up the barotropic control structure. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__barotropic_a28fa2e7600a471735c3b827ac08ed94b}{register\+\_\+barotropic\+\_\+restarts}} (HI, GV, param\+\_\+file, CS, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em This subroutine is used to register any fields from \mbox{\hyperlink{MOM__barotropic_8F90_source}{M\+O\+M\+\_\+barotropic.\+F90}} that should be written to or read from the restart file. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__barotropic_a6cf9cc852f7d2fb328fae4cad1c287c1}\label{namespacemom__barotropic_a6cf9cc852f7d2fb328fae4cad1c287c1}} 
\index{mom\_barotropic@{mom\_barotropic}!adjust\_local\_bt\_cont\_types@{adjust\_local\_bt\_cont\_types}}
\index{adjust\_local\_bt\_cont\_types@{adjust\_local\_bt\_cont\_types}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{adjust\_local\_bt\_cont\_types()}{adjust\_local\_bt\_cont\_types()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::adjust\+\_\+local\+\_\+bt\+\_\+cont\+\_\+types (\begin{DoxyParamCaption}\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{ubt,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{uhbt,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{vbt,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{vhbt,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(out)}]{B\+T\+C\+L\+\_\+u,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(out)}]{B\+T\+C\+L\+\_\+v,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}), intent(in)}]{MS,  }\item[{integer, intent(in), optional}]{halo,  }\item[{real, intent(in), optional}]{dt\+\_\+baroclinic }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adjust\+\_\+local\+\_\+\+B\+T\+\_\+cont\+\_\+types expands the range of velocities with a cubic curve translating velocities into transports to match the inital values of velocities and summed transports when the velocities are larger than the first guesses of the cubic transition velocities used to set up the local\+\_\+\+B\+T\+\_\+cont types. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ms} & A type that describes the memory sizes of the argument arrays. \\
\hline
\mbox{\texttt{ in}}  & {\em ubt} & The linearization zonal barotropic velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em uhbt} & The linearization zonal barotropic transport \\
\hline
\mbox{\texttt{ in}}  & {\em vbt} & The linearization meridional barotropic velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vhbt} & The linearization meridional barotropic transport \\
\hline
\mbox{\texttt{ out}}  & {\em btcl\+\_\+u} & A structure with the u information from B\+T\+\_\+cont. \\
\hline
\mbox{\texttt{ out}}  & {\em btcl\+\_\+v} & A structure with the v information from B\+T\+\_\+cont. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & The extra halo size to use here. \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+baroclinic} & The baroclinic time step \mbox{[}T $\sim$$>$ s\mbox{]}, which is provided if I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+N\+T\+I\+N\+U\+I\+TY is true. \\
\hline
\end{DoxyParams}


Definition at line 3895 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3897   \textcolor{keywordtype}{type}(memory\_size\_type), \textcolor{keywordtype}{intent(in)}  :: MS\textcolor{comment}{   !< A type that describes the memory sizes of the argument arrays.}}
\DoxyCodeLine{3898 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \&}
\DoxyCodeLine{3899                           \textcolor{keywordtype}{intent(in)}  :: ubt\textcolor{comment}{  !< The linearization zonal barotropic velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{3900 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \&}
\DoxyCodeLine{3901                           \textcolor{keywordtype}{intent(in)}  :: uhbt\textcolor{comment}{ !< The linearization zonal barotropic transport}}
\DoxyCodeLine{3902 \textcolor{comment}{                                              !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{3903 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \&}
\DoxyCodeLine{3904                           \textcolor{keywordtype}{intent(in)}  :: vbt\textcolor{comment}{  !< The linearization meridional barotropic velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{3905 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \&}
\DoxyCodeLine{3906                           \textcolor{keywordtype}{intent(in)}  :: vhbt\textcolor{comment}{ !< The linearization meridional barotropic transport}}
\DoxyCodeLine{3907 \textcolor{comment}{                                              !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{3908   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \&}
\DoxyCodeLine{3909                           \textcolor{keywordtype}{intent(out)} :: BTCL\_u\textcolor{comment}{ !< A structure with the u information from BT\_cont.}}
\DoxyCodeLine{3910   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \&}
\DoxyCodeLine{3911                           \textcolor{keywordtype}{intent(out)} :: BTCL\_v\textcolor{comment}{ !< A structure with the v information from BT\_cont.}}
\DoxyCodeLine{3912   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{3913   \textcolor{keywordtype}{type}(unit\_scale\_type),  \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{3914   \textcolor{keywordtype}{integer},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\textcolor{comment}{ !< The extra halo size to use here.}}
\DoxyCodeLine{3915 \textcolor{keywordtype}{  real},         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dt\_baroclinic\textcolor{comment}{ !< The baroclinic time step [T \string~> s], which is}}
\DoxyCodeLine{3916 \textcolor{comment}{                                                       !! provided if INTEGRAL\_BT\_CONTINUITY is true.}}
\DoxyCodeLine{3917 }
\DoxyCodeLine{3918   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3919 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))} :: \&}
\DoxyCodeLine{3920     u\_polarity, uBT\_EE, uBT\_WW, FA\_u\_EE, FA\_u\_E0, FA\_u\_W0, FA\_u\_WW}
\DoxyCodeLine{3921 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))} :: \&}
\DoxyCodeLine{3922     v\_polarity, vBT\_NN, vBT\_SS, FA\_v\_NN, FA\_v\_N0, FA\_v\_S0, FA\_v\_SS}
\DoxyCodeLine{3923 \textcolor{keywordtype}{  real} :: dt \textcolor{comment}{! The baroclinic timestep [T \string~> s] or 1.0 [nondim]}}
\DoxyCodeLine{3924 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_3 = 1.0/3.0}
\DoxyCodeLine{3925   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, hs}
\DoxyCodeLine{3926 }
\DoxyCodeLine{3927   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{3928   hs = 1 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) hs = max(halo,0)}
\DoxyCodeLine{3929   dt = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dt\_baroclinic)) dt = dt\_baroclinic}
\DoxyCodeLine{3930 }
\DoxyCodeLine{3931   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3932   \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs-\/1,ie+hs}
\DoxyCodeLine{3933     \textcolor{keywordflow}{if} ((dt*ubt(i,j) > btcl\_u(i,j)\%uBT\_WW) .and. (dt*uhbt(i,j) > btcl\_u(i,j)\%uh\_WW)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3934       \textcolor{comment}{! Expand the cubic fit to use this new point.  ubt is negative.}}
\DoxyCodeLine{3935       btcl\_u(i,j)\%ubt\_WW = dt * ubt(i,j)}
\DoxyCodeLine{3936       \textcolor{keywordflow}{if} (3.0*uhbt(i,j) < 2.0*ubt(i,j) * btcl\_u(i,j)\%FA\_u\_W0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3937         \textcolor{comment}{! No further bounding is needed.}}
\DoxyCodeLine{3938         btcl\_u(i,j)\%uh\_crvW = (uhbt(i,j) -\/ ubt(i,j) * btcl\_u(i,j)\%FA\_u\_W0) / (dt**2 * ubt(i,j)**3)}
\DoxyCodeLine{3939       \textcolor{keywordflow}{else} \textcolor{comment}{! This should not happen often!}}
\DoxyCodeLine{3940         btcl\_u(i,j)\%FA\_u\_W0 = 1.5*uhbt(i,j) / ubt(i,j)}
\DoxyCodeLine{3941         btcl\_u(i,j)\%uh\_crvW = -\/0.5*uhbt(i,j) / (dt**2 * ubt(i,j)**3)}
\DoxyCodeLine{3942 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3943       btcl\_u(i,j)\%uh\_WW = dt * uhbt(i,j)}
\DoxyCodeLine{3944       \textcolor{comment}{! I don't know whether this is helpful.}}
\DoxyCodeLine{3945 \textcolor{comment}{!     BTCL\_u(I,j)\%FA\_u\_WW = min(BTCL\_u(I,j)\%FA\_u\_WW, uhbt(I,j) / ubt(I,j))}}
\DoxyCodeLine{3946     \textcolor{keywordflow}{elseif} ((dt*ubt(i,j) < btcl\_u(i,j)\%uBT\_EE) .and. (dt*uhbt(i,j) < btcl\_u(i,j)\%uh\_EE)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3947       \textcolor{comment}{! Expand the cubic fit to use this new point.  ubt is negative.}}
\DoxyCodeLine{3948       btcl\_u(i,j)\%ubt\_EE = dt * ubt(i,j)}
\DoxyCodeLine{3949       \textcolor{keywordflow}{if} (3.0*uhbt(i,j) < 2.0*ubt(i,j) * btcl\_u(i,j)\%FA\_u\_E0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3950         \textcolor{comment}{! No further bounding is needed.}}
\DoxyCodeLine{3951         btcl\_u(i,j)\%uh\_crvE = (uhbt(i,j) -\/ ubt(i,j) * btcl\_u(i,j)\%FA\_u\_E0) / (dt**2 * ubt(i,j)**3)}
\DoxyCodeLine{3952       \textcolor{keywordflow}{else} \textcolor{comment}{! This should not happen often!}}
\DoxyCodeLine{3953         btcl\_u(i,j)\%FA\_u\_E0 = 1.5*uhbt(i,j) / ubt(i,j)}
\DoxyCodeLine{3954         btcl\_u(i,j)\%uh\_crvE = -\/0.5*uhbt(i,j) / (dt**2 * ubt(i,j)**3)}
\DoxyCodeLine{3955 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3956       btcl\_u(i,j)\%uh\_EE = dt * uhbt(i,j)}
\DoxyCodeLine{3957       \textcolor{comment}{! I don't know whether this is helpful.}}
\DoxyCodeLine{3958 \textcolor{comment}{!     BTCL\_u(I,j)\%FA\_u\_EE = min(BTCL\_u(I,j)\%FA\_u\_EE, uhbt(I,j) / ubt(I,j))}}
\DoxyCodeLine{3959 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3960 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3961   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3962   \textcolor{keywordflow}{do} j=js-\/hs-\/1,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{3963     \textcolor{keywordflow}{if} ((dt*vbt(i,j) > btcl\_v(i,j)\%vBT\_SS) .and. (dt*vhbt(i,j) > btcl\_v(i,j)\%vh\_SS)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3964       \textcolor{comment}{! Expand the cubic fit to use this new point.  vbt is negative.}}
\DoxyCodeLine{3965       btcl\_v(i,j)\%vbt\_SS = dt * vbt(i,j)}
\DoxyCodeLine{3966       \textcolor{keywordflow}{if} (3.0*vhbt(i,j) < 2.0*vbt(i,j) * btcl\_v(i,j)\%FA\_v\_S0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3967         \textcolor{comment}{! No further bounding is needed.}}
\DoxyCodeLine{3968         btcl\_v(i,j)\%vh\_crvS = (vhbt(i,j) -\/ vbt(i,j) * btcl\_v(i,j)\%FA\_v\_S0) /  (dt**2 * vbt(i,j)**3)}
\DoxyCodeLine{3969       \textcolor{keywordflow}{else} \textcolor{comment}{! This should not happen often!}}
\DoxyCodeLine{3970         btcl\_v(i,j)\%FA\_v\_S0 = 1.5*vhbt(i,j) / (vbt(i,j))}
\DoxyCodeLine{3971         btcl\_v(i,j)\%vh\_crvS = -\/0.5*vhbt(i,j) /  (dt**2 * vbt(i,j)**3)}
\DoxyCodeLine{3972 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3973       btcl\_v(i,j)\%vh\_SS = dt * vhbt(i,j)}
\DoxyCodeLine{3974       \textcolor{comment}{! I don't know whether this is helpful.}}
\DoxyCodeLine{3975 \textcolor{comment}{!     BTCL\_v(i,J)\%FA\_v\_SS = min(BTCL\_v(i,J)\%FA\_v\_SS, vhbt(i,J) / vbt(i,J))}}
\DoxyCodeLine{3976     \textcolor{keywordflow}{elseif} ((dt*vbt(i,j) < btcl\_v(i,j)\%vBT\_NN) .and. (dt*vhbt(i,j) < btcl\_v(i,j)\%vh\_NN)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3977       \textcolor{comment}{! Expand the cubic fit to use this new point.  vbt is negative.}}
\DoxyCodeLine{3978       btcl\_v(i,j)\%vbt\_NN = dt * vbt(i,j)}
\DoxyCodeLine{3979       \textcolor{keywordflow}{if} (3.0*vhbt(i,j) < 2.0*vbt(i,j) * btcl\_v(i,j)\%FA\_v\_N0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3980         \textcolor{comment}{! No further bounding is needed.}}
\DoxyCodeLine{3981         btcl\_v(i,j)\%vh\_crvN = (vhbt(i,j) -\/ vbt(i,j) * btcl\_v(i,j)\%FA\_v\_N0) /  (dt**2 * vbt(i,j)**3)}
\DoxyCodeLine{3982       \textcolor{keywordflow}{else} \textcolor{comment}{! This should not happen often!}}
\DoxyCodeLine{3983         btcl\_v(i,j)\%FA\_v\_N0 = 1.5*vhbt(i,j) / (vbt(i,j))}
\DoxyCodeLine{3984         btcl\_v(i,j)\%vh\_crvN = -\/0.5*vhbt(i,j) /  (dt**2 * vbt(i,j)**3)}
\DoxyCodeLine{3985 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3986       btcl\_v(i,j)\%vh\_NN = dt * vhbt(i,j)}
\DoxyCodeLine{3987       \textcolor{comment}{! I don't know whether this is helpful.}}
\DoxyCodeLine{3988 \textcolor{comment}{!     BTCL\_v(i,J)\%FA\_v\_NN = min(BTCL\_v(i,J)\%FA\_v\_NN, vhbt(i,J) / vbt(i,J))}}
\DoxyCodeLine{3989 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3990 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3991 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_ac9d3db838f0cbee31785077b261c0ad1}\label{namespacemom__barotropic_ac9d3db838f0cbee31785077b261c0ad1}} 
\index{mom\_barotropic@{mom\_barotropic}!apply\_velocity\_obcs@{apply\_velocity\_obcs}}
\index{apply\_velocity\_obcs@{apply\_velocity\_obcs}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{apply\_velocity\_obcs()}{apply\_velocity\_obcs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::apply\+\_\+velocity\+\_\+obcs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), pointer}]{O\+BC,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(inout)}]{ubt,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(inout)}]{vbt,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(inout)}]{uhbt,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(inout)}]{vhbt,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(inout)}]{ubt\+\_\+trans,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(inout)}]{vbt\+\_\+trans,  }\item[{real, dimension(sziw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{eta,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{ubt\+\_\+old,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{vbt\+\_\+old,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1bt__obc__type}{bt\+\_\+obc\+\_\+type}}), intent(in)}]{B\+T\+\_\+\+O\+BC,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}), intent(in)}]{MS,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{integer, intent(in)}]{halo,  }\item[{real, intent(in)}]{dtbt,  }\item[{real, intent(in)}]{bebt,  }\item[{logical, intent(in)}]{use\+\_\+\+B\+T\+\_\+cont,  }\item[{logical, intent(in)}]{integral\+\_\+\+B\+T\+\_\+cont,  }\item[{real, intent(in)}]{dt\+\_\+elapsed,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{Datu,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{Datv,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{B\+T\+C\+L\+\_\+u,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{B\+T\+C\+L\+\_\+v,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{uhbt0,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{vhbt0,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{ubt\+\_\+int,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{vbt\+\_\+int,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{uhbt\+\_\+int,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{vhbt\+\_\+int }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The following 4 subroutines apply the open boundary conditions. This subroutine applies the open boundary conditions on barotropic velocities and mass transports, as developed by Mehmet Ilicak. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & An associated pointer to an O\+BC type. \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em ms} & A type that describes the memory sizes of the argument arrays. \\
\hline
\mbox{\texttt{ in,out}}  & {\em ubt} & the zonal barotropic velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhbt} & the zonal barotropic transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em ubt\+\_\+trans} & The zonal barotropic velocity used in transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em vbt} & The meridional barotropic velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhbt} & the meridional barotropic transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em vbt\+\_\+trans} & the meridional BT velocity used in transports \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & The barotropic free surface height anomaly or column mass anomaly \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ubt\+\_\+old} & The starting value of ubt in a barotropic step \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vbt\+\_\+old} & The starting value of vbt in a barotropic step \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em bt\+\_\+obc} & A structure with the private barotropic arrays related to the open boundary conditions, set by set\+\_\+up\+\_\+\+B\+T\+\_\+\+O\+BC. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & The extra halo size to use here. \\
\hline
\mbox{\texttt{ in}}  & {\em dtbt} & The time step \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em bebt} & The fractional weighting of the future velocity in determining the transport. \\
\hline
\mbox{\texttt{ in}}  & {\em use\+\_\+bt\+\_\+cont} & If true, use the B\+T\+\_\+cont\+\_\+types to calculate transports. \\
\hline
\mbox{\texttt{ in}}  & {\em integral\+\_\+bt\+\_\+cont} & If true, update the barotropic continuity equation directly from the initial condition using the time-\/integrated barotropic velocity. \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+elapsed} & The amount of time in the barotropic stepping that will have elapsed \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em datu} & A fixed estimate of the face areas at u points \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em datv} & A fixed estimate of the face areas at v points \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em btcl\+\_\+u} & Structure of information used for a dynamic estimate of the face areas at u-\/points. \\
\hline
\mbox{\texttt{ in}}  & {\em btcl\+\_\+v} & Structure of information used for a dynamic estimate of the face areas at v-\/points. \\
\hline
\mbox{\texttt{ in}}  & {\em uhbt0} & A correction to the zonal transport so that the barotropic functions agree with the sum of the layer transports \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vhbt0} & A correction to the meridional transport so that the barotropic functions agree with the sum of the layer transports \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ubt\+\_\+int} & The time-\/integrated zonal barotropic velocity before this update \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em uhbt\+\_\+int} & The time-\/integrated zonal barotropic transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vbt\+\_\+int} & The time-\/integrated meridional barotropic velocity before this update \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vhbt\+\_\+int} & The time-\/integrated meridional barotropic transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 2762 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2766   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                  \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{     !< An associated pointer to an OBC type.}}
\DoxyCodeLine{2767   \textcolor{keywordtype}{type}(ocean\_grid\_type),                 \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{       !< The ocean's grid structure.}}
\DoxyCodeLine{2768   \textcolor{keywordtype}{type}(memory\_size\_type),                \textcolor{keywordtype}{intent(in)}    :: MS\textcolor{comment}{      !< A type that describes the memory sizes of}}
\DoxyCodeLine{2769 \textcolor{comment}{                                                                  !! the argument arrays.}}
\DoxyCodeLine{2770 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(inout)} :: ubt\textcolor{comment}{     !< the zonal barotropic velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2771 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(inout)} :: uhbt\textcolor{comment}{    !< the zonal barotropic transport}}
\DoxyCodeLine{2772 \textcolor{comment}{                                                                  !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{2773 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(inout)} :: ubt\_trans\textcolor{comment}{ !< The zonal barotropic velocity used in}}
\DoxyCodeLine{2774 \textcolor{comment}{                                                                  !! transport [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2775 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(inout)} :: vbt\textcolor{comment}{     !< The meridional barotropic velocity}}
\DoxyCodeLine{2776 \textcolor{comment}{                                                                  !! [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2777 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(inout)} :: vhbt\textcolor{comment}{    !< the meridional barotropic transport}}
\DoxyCodeLine{2778 \textcolor{comment}{                                                                  !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{2779 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(inout)} :: vbt\_trans\textcolor{comment}{ !< the meridional BT velocity used in}}
\DoxyCodeLine{2780 \textcolor{comment}{                                                                  !! transports [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2781 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJW\_(MS))},  \textcolor{keywordtype}{intent(in)}    :: eta\textcolor{comment}{     !< The barotropic free surface height anomaly or}}
\DoxyCodeLine{2782 \textcolor{comment}{                                                                  !! column mass anomaly [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2783 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: ubt\_old\textcolor{comment}{ !< The starting value of ubt in a barotropic}}
\DoxyCodeLine{2784 \textcolor{comment}{                                                                  !! step [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2785 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: vbt\_old\textcolor{comment}{ !< The starting value of vbt in a barotropic}}
\DoxyCodeLine{2786 \textcolor{comment}{                                                                  !! step [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2787   \textcolor{keywordtype}{type}(BT\_OBC\_type),                     \textcolor{keywordtype}{intent(in)}    :: BT\_OBC\textcolor{comment}{  !< A structure with the private barotropic arrays}}
\DoxyCodeLine{2788 \textcolor{comment}{                                                                  !! related to the open boundary conditions,}}
\DoxyCodeLine{2789 \textcolor{comment}{                                                                  !! set by set\_up\_BT\_OBC.}}
\DoxyCodeLine{2790   \textcolor{keywordtype}{type}(unit\_scale\_type),                 \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{      !< A dimensional unit scaling type}}
\DoxyCodeLine{2791   \textcolor{keywordtype}{integer},                               \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{    !< The extra halo size to use here.}}
\DoxyCodeLine{2792 \textcolor{keywordtype}{  real},                                  \textcolor{keywordtype}{intent(in)}    :: dtbt\textcolor{comment}{    !< The time step [T \string~> s].}}
\DoxyCodeLine{2793 \textcolor{keywordtype}{  real},                                  \textcolor{keywordtype}{intent(in)}    :: bebt\textcolor{comment}{    !< The fractional weighting of the future velocity}}
\DoxyCodeLine{2794 \textcolor{comment}{                                                                  !! in determining the transport.}}
\DoxyCodeLine{2795   \textcolor{keywordtype}{logical},                               \textcolor{keywordtype}{intent(in)}    :: use\_BT\_cont\textcolor{comment}{ !< If true, use the BT\_cont\_types to calculate}}
\DoxyCodeLine{2796 \textcolor{comment}{                                                                  !! transports.}}
\DoxyCodeLine{2797   \textcolor{keywordtype}{logical},                               \textcolor{keywordtype}{intent(in)}    :: integral\_BT\_cont\textcolor{comment}{ !< If true, update the barotropic continuity}}
\DoxyCodeLine{2798 \textcolor{comment}{                                                                  !! equation directly from the initial condition}}
\DoxyCodeLine{2799 \textcolor{comment}{                                                                  !! using the time-\/integrated barotropic velocity.}}
\DoxyCodeLine{2800 \textcolor{keywordtype}{  real},                                  \textcolor{keywordtype}{intent(in)}    :: dt\_elapsed\textcolor{comment}{ !< The amount of time in the barotropic stepping}}
\DoxyCodeLine{2801 \textcolor{comment}{                                                                  !! that will have elapsed [T \string~> s].}}
\DoxyCodeLine{2802 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: Datu\textcolor{comment}{    !< A fixed estimate of the face areas at u points}}
\DoxyCodeLine{2803 \textcolor{comment}{                                                                  !! [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{2804 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: Datv\textcolor{comment}{    !< A fixed estimate of the face areas at v points}}
\DoxyCodeLine{2805 \textcolor{comment}{                                                                  !! [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{2806   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: BTCL\_u\textcolor{comment}{ !< Structure of information used}}
\DoxyCodeLine{2807 \textcolor{comment}{                                                                  !! for a dynamic estimate of the face areas at}}
\DoxyCodeLine{2808 \textcolor{comment}{                                                                  !! u-\/points.}}
\DoxyCodeLine{2809   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: BTCL\_v\textcolor{comment}{ !< Structure of information used}}
\DoxyCodeLine{2810 \textcolor{comment}{                                                                  !! for a dynamic estimate of the face areas at}}
\DoxyCodeLine{2811 \textcolor{comment}{                                                                  !! v-\/points.}}
\DoxyCodeLine{2812 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: uhbt0\textcolor{comment}{   !< A correction to the zonal transport so that}}
\DoxyCodeLine{2813 \textcolor{comment}{                                                                  !! the barotropic functions agree with the sum}}
\DoxyCodeLine{2814 \textcolor{comment}{                                                                  !! of the layer transports}}
\DoxyCodeLine{2815 \textcolor{comment}{                                                                  !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{2816 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: vhbt0\textcolor{comment}{   !< A correction to the meridional transport so that}}
\DoxyCodeLine{2817 \textcolor{comment}{                                                                  !! the barotropic functions agree with the sum}}
\DoxyCodeLine{2818 \textcolor{comment}{                                                                  !! of the layer transports}}
\DoxyCodeLine{2819 \textcolor{comment}{                                                                  !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{2820 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: ubt\_int\textcolor{comment}{    !< The time-\/integrated zonal barotropic}}
\DoxyCodeLine{2821 \textcolor{comment}{                                                                  !! velocity before this update [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2822 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: uhbt\_int\textcolor{comment}{   !< The time-\/integrated zonal barotropic}}
\DoxyCodeLine{2823 \textcolor{comment}{                                                                  !! transport [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{2824 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: vbt\_int\textcolor{comment}{    !< The time-\/integrated meridional barotropic}}
\DoxyCodeLine{2825 \textcolor{comment}{                                                                  !! velocity before this update [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2826 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: vhbt\_int\textcolor{comment}{   !< The time-\/integrated meridional barotropic}}
\DoxyCodeLine{2827 \textcolor{comment}{                                                                  !! transport [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{2828 }
\DoxyCodeLine{2829   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2830 \textcolor{keywordtype}{  real} :: vel\_prev    \textcolor{comment}{! The previous velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2831 \textcolor{keywordtype}{  real} :: vel\_trans   \textcolor{comment}{! The combination of the previous and current velocity}}
\DoxyCodeLine{2832                       \textcolor{comment}{! that does the mass transport [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{2833 \textcolor{keywordtype}{  real} :: H\_u         \textcolor{comment}{! The total thickness at the u-\/point [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2834 \textcolor{keywordtype}{  real} :: H\_v         \textcolor{comment}{! The total thickness at the v-\/point [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2835 \textcolor{keywordtype}{  real} :: cfl         \textcolor{comment}{! The CFL number at the point in question [nondim]}}
\DoxyCodeLine{2836 \textcolor{keywordtype}{  real} :: u\_inlet     \textcolor{comment}{! The zonal inflow velocity [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{2837 \textcolor{keywordtype}{  real} :: v\_inlet     \textcolor{comment}{! The meridional inflow velocity [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{2838 \textcolor{keywordtype}{  real} :: uhbt\_int\_new \textcolor{comment}{! The updated time-\/integrated zonal transport [H L2 \string~> m3]}}
\DoxyCodeLine{2839 \textcolor{keywordtype}{  real} :: vhbt\_int\_new \textcolor{comment}{! The updated time-\/integrated meridional transport [H L2 \string~> m3]}}
\DoxyCodeLine{2840 \textcolor{keywordtype}{  real} :: h\_in        \textcolor{comment}{! The inflow thickess [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2841 \textcolor{keywordtype}{  real} :: cff, Cx, Cy, tau}
\DoxyCodeLine{2842 \textcolor{keywordtype}{  real} :: dhdt, dhdx, dhdy}
\DoxyCodeLine{2843 \textcolor{keywordtype}{  real} :: Idtbt       \textcolor{comment}{! The inverse of the barotropic time step [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{2844   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{2845 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJB\_(G))} :: grad}
\DoxyCodeLine{2846 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: eps = 1.0e-\/20}
\DoxyCodeLine{2847   is = g\%isc-\/halo ; ie = g\%iec+halo ; js = g\%jsc-\/halo ; je = g\%jec+halo}
\DoxyCodeLine{2848 }
\DoxyCodeLine{2849   \textcolor{keywordflow}{if} (.not.(bt\_obc\%apply\_u\_OBCs .or. bt\_obc\%apply\_v\_OBCs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{2850 }
\DoxyCodeLine{2851   idtbt = 1.0 / dtbt}
\DoxyCodeLine{2852 }
\DoxyCodeLine{2853   \textcolor{keywordflow}{if} (bt\_obc\%apply\_u\_OBCs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2854     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2855       \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_u(i,j))\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2856         uhbt(i,j) = bt\_obc\%uhbt(i,j)}
\DoxyCodeLine{2857         ubt(i,j) = bt\_obc\%ubt\_outer(i,j)}
\DoxyCodeLine{2858         vel\_trans = ubt(i,j)}
\DoxyCodeLine{2859       \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_u(i,j))\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2860         \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_u(i,j))\%Flather) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2861           cfl = dtbt * bt\_obc\%Cg\_u(i,j) * g\%IdxCu(i,j) \textcolor{comment}{! CFL}}
\DoxyCodeLine{2862           u\_inlet = cfl*ubt\_old(i-\/1,j) + (1.0-\/cfl)*ubt\_old(i,j)  \textcolor{comment}{! Valid for cfl<1}}
\DoxyCodeLine{2863           h\_in = eta(i,j) + (0.5-\/cfl)*(eta(i,j)-\/eta(i-\/1,j))      \textcolor{comment}{! internal}}
\DoxyCodeLine{2864           h\_u = bt\_obc\%H\_u(i,j)}
\DoxyCodeLine{2865           vel\_prev = ubt(i,j)}
\DoxyCodeLine{2866           ubt(i,j) = 0.5*((u\_inlet + bt\_obc\%ubt\_outer(i,j)) + \&}
\DoxyCodeLine{2867               (bt\_obc\%Cg\_u(i,j)/h\_u) * (h\_in-\/bt\_obc\%eta\_outer\_u(i,j)))}
\DoxyCodeLine{2868           vel\_trans = (1.0-\/bebt)*vel\_prev + bebt*ubt(i,j)}
\DoxyCodeLine{2869         \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_u(i,j))\%gradient) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2870           ubt(i,j) = ubt(i-\/1,j)}
\DoxyCodeLine{2871           vel\_trans = ubt(i,j)}
\DoxyCodeLine{2872 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2873       \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_u(i,j))\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2874         \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_u(i,j))\%Flather) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2875           cfl = dtbt * bt\_obc\%Cg\_u(i,j) * g\%IdxCu(i,j) \textcolor{comment}{! CFL}}
\DoxyCodeLine{2876           u\_inlet = cfl*ubt\_old(i+1,j) + (1.0-\/cfl)*ubt\_old(i,j)  \textcolor{comment}{! Valid for cfl<1}}
\DoxyCodeLine{2877           h\_in = eta(i+1,j) + (0.5-\/cfl)*(eta(i+1,j)-\/eta(i+2,j))  \textcolor{comment}{! external}}
\DoxyCodeLine{2878 }
\DoxyCodeLine{2879           h\_u = bt\_obc\%H\_u(i,j)}
\DoxyCodeLine{2880           vel\_prev = ubt(i,j)}
\DoxyCodeLine{2881           ubt(i,j) = 0.5*((u\_inlet + bt\_obc\%ubt\_outer(i,j)) + \&}
\DoxyCodeLine{2882               (bt\_obc\%Cg\_u(i,j)/h\_u) * (bt\_obc\%eta\_outer\_u(i,j)-\/h\_in))}
\DoxyCodeLine{2883 }
\DoxyCodeLine{2884           vel\_trans = (1.0-\/bebt)*vel\_prev + bebt*ubt(i,j)}
\DoxyCodeLine{2885         \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_u(i,j))\%gradient) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2886           ubt(i,j) = ubt(i+1,j)}
\DoxyCodeLine{2887           vel\_trans = ubt(i,j)}
\DoxyCodeLine{2888 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2889 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2890 }
\DoxyCodeLine{2891       \textcolor{keywordflow}{if} (.not. obc\%segment(obc\%segnum\_u(i,j))\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2892         \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2893           uhbt\_int\_new = find\_uhbt(ubt\_int(i,j) + dtbt*vel\_trans, btcl\_u(i,j)) + \&}
\DoxyCodeLine{2894                          dt\_elapsed*uhbt0(i,j)}
\DoxyCodeLine{2895           uhbt(i,j) = (uhbt\_int\_new -\/ uhbt\_int(i,j)) * idtbt}
\DoxyCodeLine{2896         \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2897           uhbt(i,j) = find\_uhbt(vel\_trans, btcl\_u(i,j)) + uhbt0(i,j)}
\DoxyCodeLine{2898         \textcolor{keywordflow}{else}}
\DoxyCodeLine{2899           uhbt(i,j) = datu(i,j)*vel\_trans + uhbt0(i,j)}
\DoxyCodeLine{2900 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2901 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2902 }
\DoxyCodeLine{2903       ubt\_trans(i,j) = vel\_trans}
\DoxyCodeLine{2904 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2905 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2906 }
\DoxyCodeLine{2907   \textcolor{keywordflow}{if} (bt\_obc\%apply\_v\_OBCs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2908     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2909       \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2910         vhbt(i,j) = bt\_obc\%vhbt(i,j)}
\DoxyCodeLine{2911         vbt(i,j) = bt\_obc\%vbt\_outer(i,j)}
\DoxyCodeLine{2912         vel\_trans = vbt(i,j)}
\DoxyCodeLine{2913       \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_v(i,j))\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2914         \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%Flather) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2915           cfl = dtbt * bt\_obc\%Cg\_v(i,j) * g\%IdyCv(i,j) \textcolor{comment}{! CFL}}
\DoxyCodeLine{2916           v\_inlet = cfl*vbt\_old(i,j-\/1) + (1.0-\/cfl)*vbt\_old(i,j)  \textcolor{comment}{! Valid for cfl<1}}
\DoxyCodeLine{2917           h\_in = eta(i,j) + (0.5-\/cfl)*(eta(i,j)-\/eta(i,j-\/1))      \textcolor{comment}{! internal}}
\DoxyCodeLine{2918 }
\DoxyCodeLine{2919           h\_v = bt\_obc\%H\_v(i,j)}
\DoxyCodeLine{2920           vel\_prev = vbt(i,j)}
\DoxyCodeLine{2921           vbt(i,j) = 0.5*((v\_inlet + bt\_obc\%vbt\_outer(i,j)) + \&}
\DoxyCodeLine{2922               (bt\_obc\%Cg\_v(i,j)/h\_v) * (h\_in-\/bt\_obc\%eta\_outer\_v(i,j)))}
\DoxyCodeLine{2923 }
\DoxyCodeLine{2924           vel\_trans = (1.0-\/bebt)*vel\_prev + bebt*vbt(i,j)}
\DoxyCodeLine{2925         \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_v(i,j))\%gradient) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2926           vbt(i,j) = vbt(i,j-\/1)}
\DoxyCodeLine{2927           vel\_trans = vbt(i,j)}
\DoxyCodeLine{2928 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2929       \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_v(i,j))\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2930         \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%Flather) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2931           cfl = dtbt * bt\_obc\%Cg\_v(i,j) * g\%IdyCv(i,j) \textcolor{comment}{! CFL}}
\DoxyCodeLine{2932           v\_inlet = cfl*vbt\_old(i,j+1) + (1.0-\/cfl)*vbt\_old(i,j)  \textcolor{comment}{! Valid for cfl <1}}
\DoxyCodeLine{2933           h\_in = eta(i,j+1) + (0.5-\/cfl)*(eta(i,j+1)-\/eta(i,j+2))  \textcolor{comment}{! internal}}
\DoxyCodeLine{2934 }
\DoxyCodeLine{2935           h\_v = bt\_obc\%H\_v(i,j)}
\DoxyCodeLine{2936           vel\_prev = vbt(i,j)}
\DoxyCodeLine{2937           vbt(i,j) = 0.5*((v\_inlet + bt\_obc\%vbt\_outer(i,j)) + \&}
\DoxyCodeLine{2938               (bt\_obc\%Cg\_v(i,j)/h\_v) * (bt\_obc\%eta\_outer\_v(i,j)-\/h\_in))}
\DoxyCodeLine{2939 }
\DoxyCodeLine{2940           vel\_trans = (1.0-\/bebt)*vel\_prev + bebt*vbt(i,j)}
\DoxyCodeLine{2941         \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_v(i,j))\%gradient) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2942           vbt(i,j) = vbt(i,j+1)}
\DoxyCodeLine{2943           vel\_trans = vbt(i,j)}
\DoxyCodeLine{2944 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2945 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2946 }
\DoxyCodeLine{2947       \textcolor{keywordflow}{if} (.not. obc\%segment(obc\%segnum\_v(i,j))\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2948         \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2949           vhbt\_int\_new = find\_vhbt(vbt\_int(i,j) + dtbt*vel\_trans, btcl\_v(i,j)) + \&}
\DoxyCodeLine{2950                          dt\_elapsed*vhbt0(i,j)}
\DoxyCodeLine{2951           vhbt(i,j) = (vhbt\_int\_new -\/ vhbt\_int(i,j)) * idtbt}
\DoxyCodeLine{2952         \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2953           vhbt(i,j) = find\_vhbt(vel\_trans, btcl\_v(i,j)) + vhbt0(i,j)}
\DoxyCodeLine{2954         \textcolor{keywordflow}{else}}
\DoxyCodeLine{2955           vhbt(i,j) = vel\_trans*datv(i,j) + vhbt0(i,j)}
\DoxyCodeLine{2956 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2957 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2958 }
\DoxyCodeLine{2959       vbt\_trans(i,j) = vel\_trans}
\DoxyCodeLine{2960 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2961 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2962 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_aee694cdef3a20b960aff1ec4fa5da28f}\label{namespacemom__barotropic_aee694cdef3a20b960aff1ec4fa5da28f}} 
\index{mom\_barotropic@{mom\_barotropic}!barotropic\_end@{barotropic\_end}}
\index{barotropic\_end@{barotropic\_end}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{barotropic\_end()}{barotropic\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::barotropic\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clean up the barotropic control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & Control structure to clear out. \\
\hline
\end{DoxyParams}


Definition at line 4946 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4947   \textcolor{keywordtype}{type}(barotropic\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< Control structure to clear out.}}
\DoxyCodeLine{4948   dealloc\_(cs\%frhatu)   ; dealloc\_(cs\%frhatv)}
\DoxyCodeLine{4949   dealloc\_(cs\%IDatu)    ; dealloc\_(cs\%IDatv)}
\DoxyCodeLine{4950   dealloc\_(cs\%ubtav)    ; dealloc\_(cs\%vbtav)}
\DoxyCodeLine{4951   dealloc\_(cs\%eta\_cor)}
\DoxyCodeLine{4952   dealloc\_(cs\%ua\_polarity) ; dealloc\_(cs\%va\_polarity)}
\DoxyCodeLine{4953   \textcolor{keywordflow}{if} (cs\%bound\_BT\_corr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4954     dealloc\_(cs\%eta\_cor\_bound)}
\DoxyCodeLine{4955 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4956 }
\DoxyCodeLine{4957   \textcolor{keyword}{call }destroy\_bt\_obc(cs\%BT\_OBC)}
\DoxyCodeLine{4958 }
\DoxyCodeLine{4959   \textcolor{keyword}{deallocate}(cs)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_aa059fdf7e6002b13d942f96ef17a5db6}\label{namespacemom__barotropic_aa059fdf7e6002b13d942f96ef17a5db6}} 
\index{mom\_barotropic@{mom\_barotropic}!barotropic\_get\_tav@{barotropic\_get\_tav}}
\index{barotropic\_get\_tav@{barotropic\_get\_tav}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{barotropic\_get\_tav()}{barotropic\_get\_tav()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::barotropic\+\_\+get\+\_\+tav (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(inout)}]{ubtav,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(inout)}]{vbtav,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US }\end{DoxyParamCaption})}



Copies ubtav and vbtav from private type into arrays. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure for this module \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em ubtav} & Zonal barotropic velocity averaged over a baroclinic timestep \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vbtav} & Meridional barotropic velocity averaged over a baroclinic timestep \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 4923 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4924   \textcolor{keywordtype}{type}(barotropic\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< Control structure for this module}}
\DoxyCodeLine{4925   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< Grid structure}}
\DoxyCodeLine{4926 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: ubtav\textcolor{comment}{ !< Zonal barotropic velocity averaged}}
\DoxyCodeLine{4927 \textcolor{comment}{                                                            !! over a baroclinic timestep [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{4928 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vbtav\textcolor{comment}{ !< Meridional barotropic velocity averaged}}
\DoxyCodeLine{4929 \textcolor{comment}{                                                            !! over a baroclinic timestep [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{4930   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{4931   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{4932   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{4933 }
\DoxyCodeLine{4934   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc-\/1,g\%iec}
\DoxyCodeLine{4935     ubtav(i,j) = cs\%ubtav(i,j)}
\DoxyCodeLine{4936 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4937 }
\DoxyCodeLine{4938   \textcolor{keywordflow}{do} j=g\%jsc-\/1,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{4939     vbtav(i,j) = cs\%vbtav(i,j)}
\DoxyCodeLine{4940 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4941 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a59244968890766632554a6d271ec4499}\label{namespacemom__barotropic_a59244968890766632554a6d271ec4499}} 
\index{mom\_barotropic@{mom\_barotropic}!barotropic\_init@{barotropic\_init}}
\index{barotropic\_init@{barotropic\_init}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{barotropic\_init()}{barotropic\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::barotropic\+\_\+init (\begin{DoxyParamCaption}\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{eta,  }\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__restart_1_1mom__restart__cs}{mom\+\_\+restart\+\_\+cs}}), pointer}]{restart\+\_\+\+CS,  }\item[{logical, intent(out)}]{calc\+\_\+dtbt,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1bt__cont__type}{bt\+\_\+cont\+\_\+type}}), optional, pointer}]{B\+T\+\_\+cont,  }\item[{type(\mbox{\hyperlink{structmom__tidal__forcing_1_1tidal__forcing__cs}{tidal\+\_\+forcing\+\_\+cs}}), optional, pointer}]{tides\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



barotropic\+\_\+init initializes a number of time-\/invariant fields used in the barotropic calculation and initializes any barotropic fields that have not already been initialized. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & Free surface height or column mass anomaly \\
\hline
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters. \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & A structure that is used to regulate diagnostic output. \\
\hline
 & {\em cs} & A pointer to the control structure for this module that is set in register\+\_\+barotropic\+\_\+restarts. \\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure. \\
\hline
\mbox{\texttt{ out}}  & {\em calc\+\_\+dtbt} & If true, the barotropic time step must be recalculated before stepping. \\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the \\
\hline
 & {\em tides\+\_\+csp} & A pointer to the control structure of the \\
\hline
\end{DoxyParams}


Definition at line 4204 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4206   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{4207   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure.}}
\DoxyCodeLine{4208   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{4209 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{4210                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< The zonal velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{4211 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{4212                            \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< The meridional velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{4213 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{4214                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4215 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{4216                            \textcolor{keywordtype}{intent(in)}    :: eta\textcolor{comment}{  !< Free surface height or column mass anomaly}}
\DoxyCodeLine{4217 \textcolor{comment}{                                                 !! [Z \string~> m] or [H \string~> kg m-\/2].}}
\DoxyCodeLine{4218   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< The current model time.}}
\DoxyCodeLine{4219   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-\/time parameters.}}
\DoxyCodeLine{4220   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< A structure that is used to regulate diagnostic}}
\DoxyCodeLine{4221 \textcolor{comment}{                                                 !! output.}}
\DoxyCodeLine{4222   \textcolor{keywordtype}{type}(barotropic\_CS),     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< A pointer to the control structure for this module}}
\DoxyCodeLine{4223 \textcolor{comment}{                                                 !! that is set in register\_barotropic\_restarts.}}
\DoxyCodeLine{4224   \textcolor{keywordtype}{type}(MOM\_restart\_CS),    \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure.}}
\DoxyCodeLine{4225   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(out)}   :: calc\_dtbt\textcolor{comment}{  !< If true, the barotropic time step must}}
\DoxyCodeLine{4226 \textcolor{comment}{                                                 !! be recalculated before stepping.}}
\DoxyCodeLine{4227   \textcolor{keywordtype}{type}(BT\_cont\_type), \textcolor{keywordtype}{optional}, \&}
\DoxyCodeLine{4228                            \textcolor{keywordtype}{pointer}       :: BT\_cont\textcolor{comment}{    !< A structure with elements that describe the}}
\DoxyCodeLine{4229 \textcolor{comment}{                                                 !! effective open face areas as a function of}}
\DoxyCodeLine{4230 \textcolor{comment}{                                                 !! barotropic flow.}}
\DoxyCodeLine{4231   \textcolor{keywordtype}{type}(tidal\_forcing\_CS), \textcolor{keywordtype}{optional}, \&}
\DoxyCodeLine{4232                            \textcolor{keywordtype}{pointer}       :: tides\_CSp\textcolor{comment}{  !< A pointer to the control structure of the}}
\DoxyCodeLine{4233 \textcolor{comment}{                                                 !! tide module.}}
\DoxyCodeLine{4234 }
\DoxyCodeLine{4235 \textcolor{comment}{! This include declares and sets the variable "{}version"{}.}}
\DoxyCodeLine{4236 \textcolor{preprocessor}{\#include "{}version\_variable.h"{}}}
\DoxyCodeLine{4237 \textcolor{preprocessor}{}  \textcolor{comment}{! Local variables}}
\DoxyCodeLine{4238   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}MOM\_barotropic"{}}  \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{4239 \textcolor{keywordtype}{  real} :: Datu(SZIBS\_(G),SZJ\_(G))   \textcolor{comment}{! Zonal open face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{4240 \textcolor{keywordtype}{  real} :: Datv(SZI\_(G),SZJBS\_(G))   \textcolor{comment}{! Meridional open face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{4241 \textcolor{keywordtype}{  real} :: gtot\_estimate \textcolor{comment}{! Summed GV\%g\_prime [L2 Z-\/1 T-\/2 \string~> m s-\/2], to give an upper-\/bound estimate for pbce.}}
\DoxyCodeLine{4242 \textcolor{keywordtype}{  real} :: SSH\_extra     \textcolor{comment}{! An estimate of how much higher SSH might get, for use}}
\DoxyCodeLine{4243                         \textcolor{comment}{! in calculating the safe external wave speed [Z \string~> m].}}
\DoxyCodeLine{4244 \textcolor{keywordtype}{  real} :: dtbt\_input    \textcolor{comment}{! The input value of DTBT, [nondim] if negative or [s] if positive.}}
\DoxyCodeLine{4245 \textcolor{keywordtype}{  real} :: dtbt\_tmp      \textcolor{comment}{! A temporary copy of CS\%dtbt read from a restart file [T \string~> s]}}
\DoxyCodeLine{4246 \textcolor{keywordtype}{  real} :: wave\_drag\_scale \textcolor{comment}{! A scaling factor for the barotropic linear wave drag}}
\DoxyCodeLine{4247                           \textcolor{comment}{! piston velocities.}}
\DoxyCodeLine{4248   \textcolor{keywordtype}{character(len=200)} :: inputdir       \textcolor{comment}{! The directory in which to find input files.}}
\DoxyCodeLine{4249   \textcolor{keywordtype}{character(len=200)} :: wave\_drag\_file \textcolor{comment}{! The file from which to read the wave}}
\DoxyCodeLine{4250                                        \textcolor{comment}{! drag piston velocity.}}
\DoxyCodeLine{4251   \textcolor{keywordtype}{character(len=80)}  :: wave\_drag\_var  \textcolor{comment}{! The wave drag piston velocity variable}}
\DoxyCodeLine{4252                                        \textcolor{comment}{! name in wave\_drag\_file.}}
\DoxyCodeLine{4253 \textcolor{keywordtype}{  real} :: vel\_rescale \textcolor{comment}{! A rescaling factor for horizontal velocity from the representation in}}
\DoxyCodeLine{4254                       \textcolor{comment}{! a restart file to the internal representation in this run.}}
\DoxyCodeLine{4255 \textcolor{keywordtype}{  real} :: uH\_rescale  \textcolor{comment}{! A rescaling factor for thickness transports from the representation in}}
\DoxyCodeLine{4256                       \textcolor{comment}{! a restart file to the internal representation in this run.}}
\DoxyCodeLine{4257 \textcolor{keywordtype}{  real} :: mean\_SL     \textcolor{comment}{! The mean sea level that is used along with the bathymetry to estimate the}}
\DoxyCodeLine{4258                       \textcolor{comment}{! geometry when LINEARIZED\_BT\_CORIOLIS is true or BT\_NONLIN\_STRESS is false [Z \string~> m].}}
\DoxyCodeLine{4259 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: lin\_drag\_h}
\DoxyCodeLine{4260   \textcolor{keywordtype}{type}(memory\_size\_type) :: MS}
\DoxyCodeLine{4261   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_static\_data, pass\_q\_D\_Cor}
\DoxyCodeLine{4262   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_bt\_hbt\_btav, pass\_a\_polarity}
\DoxyCodeLine{4263   \textcolor{keywordtype}{logical} :: default\_2018\_answers \textcolor{comment}{! The default setting for the various 2018\_ANSWERS flags.}}
\DoxyCodeLine{4264   \textcolor{keywordtype}{logical} :: apply\_bt\_drag, use\_BT\_cont\_type}
\DoxyCodeLine{4265   \textcolor{keywordtype}{character(len=48)} :: thickness\_units, flux\_units}
\DoxyCodeLine{4266   \textcolor{keywordtype}{character*(40)} :: hvel\_str}
\DoxyCodeLine{4267   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz}
\DoxyCodeLine{4268   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{4269   \textcolor{keywordtype}{integer} :: isdw, iedw, jsdw, jedw}
\DoxyCodeLine{4270   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{4271   \textcolor{keywordtype}{integer} :: wd\_halos(2), bt\_halo\_sz}
\DoxyCodeLine{4272   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{4273   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{4274   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{4275   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{4276   ms\%isdw = g\%isd ; ms\%iedw = g\%ied ; ms\%jsdw = g\%jsd ; ms\%jedw = g\%jed}
\DoxyCodeLine{4277 }
\DoxyCodeLine{4278   \textcolor{keywordflow}{if} (cs\%module\_is\_initialized) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4279     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}barotropic\_init called with a control structure "{}}// \&}
\DoxyCodeLine{4280                             \textcolor{stringliteral}{"{}that has already been initialized."{}})}
\DoxyCodeLine{4281     \textcolor{keywordflow}{return}}
\DoxyCodeLine{4282 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4283   cs\%module\_is\_initialized = .true.}
\DoxyCodeLine{4284 }
\DoxyCodeLine{4285   cs\%diag => diag ; cs\%Time => time}
\DoxyCodeLine{4286   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tides\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4287     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tides\_csp)) cs\%tides\_CSp => tides\_csp}
\DoxyCodeLine{4288 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4289 }
\DoxyCodeLine{4290   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{4291   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}SPLIT"{}}, cs\%split, default=.true., do\_not\_log=.true.)}
\DoxyCodeLine{4292   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{"{}"{}}, log\_to\_all=.true., layout=cs\%split, \&}
\DoxyCodeLine{4293                    debugging=cs\%split, all\_default=.not.cs\%split)}
\DoxyCodeLine{4294   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}SPLIT"{}}, cs\%split, \&}
\DoxyCodeLine{4295                  \textcolor{stringliteral}{"{}Use the split time stepping if true."{}}, default=.true.)}
\DoxyCodeLine{4296   \textcolor{keywordflow}{if} (.not.cs\%split) \textcolor{keywordflow}{return}}
\DoxyCodeLine{4297 }
\DoxyCodeLine{4298   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USE\_BT\_CONT\_TYPE"{}}, use\_bt\_cont\_type, \&}
\DoxyCodeLine{4299                  \textcolor{stringliteral}{"{}If true, use a structure with elements that describe "{}}//\&}
\DoxyCodeLine{4300                  \textcolor{stringliteral}{"{}effective face areas from the summed continuity solver "{}}//\&}
\DoxyCodeLine{4301                  \textcolor{stringliteral}{"{}as a function the barotropic flow in coupling between "{}}//\&}
\DoxyCodeLine{4302                  \textcolor{stringliteral}{"{}the barotropic and baroclinic flow.  This is only used "{}}//\&}
\DoxyCodeLine{4303                  \textcolor{stringliteral}{"{}if SPLIT is true."{}}, default=.true.)}
\DoxyCodeLine{4304   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INTEGRAL\_BT\_CONTINUITY"{}}, cs\%integral\_bt\_cont, \&}
\DoxyCodeLine{4305                  \textcolor{stringliteral}{"{}If true, use the time-\/integrated velocity over the barotropic steps "{}}//\&}
\DoxyCodeLine{4306                  \textcolor{stringliteral}{"{}to determine the integrated transports used to update the continuity "{}}//\&}
\DoxyCodeLine{4307                  \textcolor{stringliteral}{"{}equation.  Otherwise the transports are the sum of the transports based on "{}}//\&}
\DoxyCodeLine{4308                  \textcolor{stringliteral}{"{}a series of instantaneous velocities and the BT\_CONT\_TYPE for transports.  "{}}//\&}
\DoxyCodeLine{4309                  \textcolor{stringliteral}{"{}This is only valid if USE\_BT\_CONT\_TYPE = True."{}}, \&}
\DoxyCodeLine{4310                  default=.false., do\_not\_log=.not.use\_bt\_cont\_type)}
\DoxyCodeLine{4311   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BOUND\_BT\_CORRECTION"{}}, cs\%bound\_BT\_corr, \&}
\DoxyCodeLine{4312                  \textcolor{stringliteral}{"{}If true, the corrective pseudo mass-\/fluxes into the "{}}//\&}
\DoxyCodeLine{4313                  \textcolor{stringliteral}{"{}barotropic solver are limited to values that require "{}}//\&}
\DoxyCodeLine{4314                  \textcolor{stringliteral}{"{}less than maxCFL\_BT\_cont to be accommodated."{}},default=.false.)}
\DoxyCodeLine{4315   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_CONT\_CORR\_BOUNDS"{}}, cs\%BT\_cont\_bounds, \&}
\DoxyCodeLine{4316                  \textcolor{stringliteral}{"{}If true, and BOUND\_BT\_CORRECTION is true, use the "{}}//\&}
\DoxyCodeLine{4317                  \textcolor{stringliteral}{"{}BT\_cont\_type variables to set limits determined by "{}}//\&}
\DoxyCodeLine{4318                  \textcolor{stringliteral}{"{}MAXCFL\_BT\_CONT on the CFL number of the velocities "{}}//\&}
\DoxyCodeLine{4319                  \textcolor{stringliteral}{"{}that are likely to be driven by the corrective mass fluxes."{}}, \&}
\DoxyCodeLine{4320                  default=.true., do\_not\_log=.not.cs\%bound\_BT\_corr)}
\DoxyCodeLine{4321   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}ADJUST\_BT\_CONT"{}}, cs\%adjust\_BT\_cont, \&}
\DoxyCodeLine{4322                  \textcolor{stringliteral}{"{}If true, adjust the curve fit to the BT\_cont type "{}}//\&}
\DoxyCodeLine{4323                  \textcolor{stringliteral}{"{}that is used by the barotropic solver to match the "{}}//\&}
\DoxyCodeLine{4324                  \textcolor{stringliteral}{"{}transport about which the flow is being linearized."{}}, \&}
\DoxyCodeLine{4325                  default=.false., do\_not\_log=.not.use\_bt\_cont\_type)}
\DoxyCodeLine{4326   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}GRADUAL\_BT\_ICS"{}}, cs\%gradual\_BT\_ICs, \&}
\DoxyCodeLine{4327                  \textcolor{stringliteral}{"{}If true, adjust the initial conditions for the "{}}//\&}
\DoxyCodeLine{4328                  \textcolor{stringliteral}{"{}barotropic solver to the values from the layered "{}}//\&}
\DoxyCodeLine{4329                  \textcolor{stringliteral}{"{}solution over a whole timestep instead of instantly. "{}}//\&}
\DoxyCodeLine{4330                  \textcolor{stringliteral}{"{}This is a decent approximation to the inclusion of "{}}//\&}
\DoxyCodeLine{4331                  \textcolor{stringliteral}{"{}sum(u dh\_dt) while also correcting for truncation errors."{}}, \&}
\DoxyCodeLine{4332                  default=.false.)}
\DoxyCodeLine{4333   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_USE\_VISC\_REM\_U\_UH0"{}}, cs\%visc\_rem\_u\_uh0, \&}
\DoxyCodeLine{4334                  \textcolor{stringliteral}{"{}If true, use the viscous remnants when estimating the "{}}//\&}
\DoxyCodeLine{4335                  \textcolor{stringliteral}{"{}barotropic velocities that were used to calculate uh0 "{}}//\&}
\DoxyCodeLine{4336                  \textcolor{stringliteral}{"{}and vh0.  False is probably the better choice."{}}, default=.false.)}
\DoxyCodeLine{4337   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_USE\_WIDE\_HALOS"{}}, cs\%use\_wide\_halos, \&}
\DoxyCodeLine{4338                  \textcolor{stringliteral}{"{}If true, use wide halos and march in during the "{}}//\&}
\DoxyCodeLine{4339                  \textcolor{stringliteral}{"{}barotropic time stepping for efficiency."{}}, default=.true., \&}
\DoxyCodeLine{4340                  layoutparam=.true.)}
\DoxyCodeLine{4341   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BTHALO"{}}, bt\_halo\_sz, \&}
\DoxyCodeLine{4342                  \textcolor{stringliteral}{"{}The minimum halo size for the barotropic solver."{}}, default=0, \&}
\DoxyCodeLine{4343                  layoutparam=.true.)}
\DoxyCodeLine{4344 \textcolor{preprocessor}{\#ifdef STATIC\_MEMORY\_}}
\DoxyCodeLine{4345 \textcolor{preprocessor}{}  \textcolor{keywordflow}{if} ((bt\_halo\_sz > 0) .and. (bt\_halo\_sz /= bthalo\_)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{4346       \textcolor{stringliteral}{"{}barotropic\_init: Run-\/time values of BTHALO must agree with the "{}}//\&}
\DoxyCodeLine{4347       \textcolor{stringliteral}{"{}macro BTHALO\_ with STATIC\_MEMORY\_."{}})}
\DoxyCodeLine{4348   wd\_halos(1) = whaloi\_+nihalo\_ ; wd\_halos(2) = whaloj\_+njhalo\_}
\DoxyCodeLine{4349 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{4350 \textcolor{preprocessor}{}  wd\_halos(1) = bt\_halo\_sz; wd\_halos(2) =  bt\_halo\_sz}
\DoxyCodeLine{4351 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{4352 \textcolor{preprocessor}{}  \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}!BT x-\/halo"{}}, wd\_halos(1), \&}
\DoxyCodeLine{4353                  \textcolor{stringliteral}{"{}The barotropic x-\/halo size that is actually used."{}}, \&}
\DoxyCodeLine{4354                  layoutparam=.true.)}
\DoxyCodeLine{4355   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}!BT y-\/halo"{}}, wd\_halos(2), \&}
\DoxyCodeLine{4356                  \textcolor{stringliteral}{"{}The barotropic y-\/halo size that is actually used."{}}, \&}
\DoxyCodeLine{4357                  layoutparam=.true.)}
\DoxyCodeLine{4358 }
\DoxyCodeLine{4359   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NONLINEAR\_BT\_CONTINUITY"{}}, cs\%Nonlinear\_continuity, \&}
\DoxyCodeLine{4360                  \textcolor{stringliteral}{"{}If true, use nonlinear transports in the barotropic "{}}//\&}
\DoxyCodeLine{4361                  \textcolor{stringliteral}{"{}continuity equation.  This does not apply if "{}}//\&}
\DoxyCodeLine{4362                  \textcolor{stringliteral}{"{}USE\_BT\_CONT\_TYPE is true."{}}, default=.false., do\_not\_log=use\_bt\_cont\_type)}
\DoxyCodeLine{4363   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}NONLIN\_BT\_CONT\_UPDATE\_PERIOD"{}}, cs\%Nonlin\_cont\_update\_period, \&}
\DoxyCodeLine{4364                  \textcolor{stringliteral}{"{}If NONLINEAR\_BT\_CONTINUITY is true, this is the number "{}}//\&}
\DoxyCodeLine{4365                  \textcolor{stringliteral}{"{}of barotropic time steps between updates to the face "{}}//\&}
\DoxyCodeLine{4366                  \textcolor{stringliteral}{"{}areas, or 0 to update only before the barotropic stepping."{}}, \&}
\DoxyCodeLine{4367                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=1, do\_not\_log=.not.cs\%Nonlinear\_continuity)}
\DoxyCodeLine{4368 }
\DoxyCodeLine{4369   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_PROJECT\_VELOCITY"{}}, cs\%BT\_project\_velocity,\&}
\DoxyCodeLine{4370                  \textcolor{stringliteral}{"{}If true, step the barotropic velocity first and project "{}}//\&}
\DoxyCodeLine{4371                  \textcolor{stringliteral}{"{}out the velocity tendency by 1+BEBT when calculating the "{}}//\&}
\DoxyCodeLine{4372                  \textcolor{stringliteral}{"{}transport.  The default (false) is to use a predictor "{}}//\&}
\DoxyCodeLine{4373                  \textcolor{stringliteral}{"{}continuity step to find the pressure field, and then "{}}//\&}
\DoxyCodeLine{4374                  \textcolor{stringliteral}{"{}to do a corrector continuity step using a weighted "{}}//\&}
\DoxyCodeLine{4375                  \textcolor{stringliteral}{"{}average of the old and new velocities, with weights "{}}//\&}
\DoxyCodeLine{4376                  \textcolor{stringliteral}{"{}of (1-\/BEBT) and BEBT."{}}, default=.false.)}
\DoxyCodeLine{4377   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_NONLIN\_STRESS"{}}, cs\%nonlin\_stress, \&}
\DoxyCodeLine{4378                  \textcolor{stringliteral}{"{}If true, use the full depth of the ocean at the start of the barotropic "{}}//\&}
\DoxyCodeLine{4379                  \textcolor{stringliteral}{"{}step when calculating the surface stress contribution to the barotropic "{}}//\&}
\DoxyCodeLine{4380                  \textcolor{stringliteral}{"{}acclerations.  Otherwise use the depth based on bathyT."{}}, default=.false.)}
\DoxyCodeLine{4381 }
\DoxyCodeLine{4382   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DYNAMIC\_SURFACE\_PRESSURE"{}}, cs\%dynamic\_psurf, \&}
\DoxyCodeLine{4383                  \textcolor{stringliteral}{"{}If true, add a dynamic pressure due to a viscous ice "{}}//\&}
\DoxyCodeLine{4384                  \textcolor{stringliteral}{"{}shelf, for instance."{}}, default=.false.)}
\DoxyCodeLine{4385   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}ICE\_LENGTH\_DYN\_PSURF"{}}, cs\%ice\_strength\_length, \&}
\DoxyCodeLine{4386                  \textcolor{stringliteral}{"{}The length scale at which the Rayleigh damping rate due "{}}//\&}
\DoxyCodeLine{4387                  \textcolor{stringliteral}{"{}to the ice strength should be the same as if a Laplacian "{}}//\&}
\DoxyCodeLine{4388                  \textcolor{stringliteral}{"{}were applied, if DYNAMIC\_SURFACE\_PRESSURE is true."{}}, \&}
\DoxyCodeLine{4389                  units=\textcolor{stringliteral}{"{}m"{}}, default=1.0e4, scale=us\%m\_to\_L, do\_not\_log=.not.cs\%dynamic\_psurf)}
\DoxyCodeLine{4390   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEPTH\_MIN\_DYN\_PSURF"{}}, cs\%Dmin\_dyn\_psurf, \&}
\DoxyCodeLine{4391                  \textcolor{stringliteral}{"{}The minimum depth to use in limiting the size of the "{}}//\&}
\DoxyCodeLine{4392                  \textcolor{stringliteral}{"{}dynamic surface pressure for stability, if "{}}//\&}
\DoxyCodeLine{4393                  \textcolor{stringliteral}{"{}DYNAMIC\_SURFACE\_PRESSURE is true.."{}}, \&}
\DoxyCodeLine{4394                  units=\textcolor{stringliteral}{"{}m"{}}, default=1.0e-\/6, scale=us\%m\_to\_Z, do\_not\_log=.not.cs\%dynamic\_psurf)}
\DoxyCodeLine{4395   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CONST\_DYN\_PSURF"{}}, cs\%const\_dyn\_psurf, \&}
\DoxyCodeLine{4396                  \textcolor{stringliteral}{"{}The constant that scales the dynamic surface pressure, "{}}//\&}
\DoxyCodeLine{4397                  \textcolor{stringliteral}{"{}if DYNAMIC\_SURFACE\_PRESSURE is true.  Stable values "{}}//\&}
\DoxyCodeLine{4398                  \textcolor{stringliteral}{"{}are < \string~1.0."{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.9, do\_not\_log=.not.cs\%dynamic\_psurf)}
\DoxyCodeLine{4399 }
\DoxyCodeLine{4400   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_CORIOLIS\_SCALE"{}}, cs\%BT\_Coriolis\_scale, \&}
\DoxyCodeLine{4401                  \textcolor{stringliteral}{"{}A factor by which the barotropic Coriolis anomaly terms are scaled."{}}, \&}
\DoxyCodeLine{4402                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=1.0)}
\DoxyCodeLine{4403   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEFAULT\_2018\_ANSWERS"{}}, default\_2018\_answers, \&}
\DoxyCodeLine{4404                  \textcolor{stringliteral}{"{}This sets the default value for the various \_2018\_ANSWERS parameters."{}}, \&}
\DoxyCodeLine{4405                  default=.false.)}
\DoxyCodeLine{4406   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BAROTROPIC\_2018\_ANSWERS"{}}, cs\%answers\_2018, \&}
\DoxyCodeLine{4407                  \textcolor{stringliteral}{"{}If true, use expressions for the barotropic solver that recover the answers "{}}//\&}
\DoxyCodeLine{4408                  \textcolor{stringliteral}{"{}from the end of 2018.  Otherwise, use more efficient or general expressions."{}}, \&}
\DoxyCodeLine{4409                  default=default\_2018\_answers)}
\DoxyCodeLine{4410 }
\DoxyCodeLine{4411   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}TIDES"{}}, cs\%tides, \&}
\DoxyCodeLine{4412                  \textcolor{stringliteral}{"{}If true, apply tidal momentum forcing."{}}, default=.false.)}
\DoxyCodeLine{4413   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}SADOURNY"{}}, cs\%Sadourny, \&}
\DoxyCodeLine{4414                  \textcolor{stringliteral}{"{}If true, the Coriolis terms are discretized with the "{}}//\&}
\DoxyCodeLine{4415                  \textcolor{stringliteral}{"{}Sadourny (1975) energy conserving scheme, otherwise "{}}//\&}
\DoxyCodeLine{4416                  \textcolor{stringliteral}{"{}the Arakawa \& Hsu scheme is used.  If the internal "{}}//\&}
\DoxyCodeLine{4417                  \textcolor{stringliteral}{"{}deformation radius is not resolved, the Sadourny scheme "{}}//\&}
\DoxyCodeLine{4418                  \textcolor{stringliteral}{"{}should probably be used."{}}, default=.true.)}
\DoxyCodeLine{4419 }
\DoxyCodeLine{4420   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_THICK\_SCHEME"{}}, hvel\_str, \&}
\DoxyCodeLine{4421                  \textcolor{stringliteral}{"{}A string describing the scheme that is used to set the "{}}//\&}
\DoxyCodeLine{4422                  \textcolor{stringliteral}{"{}open face areas used for barotropic transport and the "{}}//\&}
\DoxyCodeLine{4423                  \textcolor{stringliteral}{"{}relative weights of the accelerations. Valid values are:\(\backslash\)n"{}}//\&}
\DoxyCodeLine{4424                  \textcolor{stringliteral}{"{}\(\backslash\)t ARITHMETIC -\/ arithmetic mean layer thicknesses \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4425                  \textcolor{stringliteral}{"{}\(\backslash\)t HARMONIC -\/ harmonic mean layer thicknesses \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4426                  \textcolor{stringliteral}{"{}\(\backslash\)t HYBRID (the default) -\/ use arithmetic means for \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4427                  \textcolor{stringliteral}{"{}\(\backslash\)t    layers above the shallowest bottom, the harmonic \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4428                  \textcolor{stringliteral}{"{}\(\backslash\)t    mean for layers below, and a weighted average for \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4429                  \textcolor{stringliteral}{"{}\(\backslash\)t    layers that straddle that depth \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4430                  \textcolor{stringliteral}{"{}\(\backslash\)t FROM\_BT\_CONT -\/ use the average thicknesses kept \(\backslash\)n"{}}//\&}
\DoxyCodeLine{4431                  \textcolor{stringliteral}{"{}\(\backslash\)t    in the h\_u and h\_v fields of the BT\_cont\_type"{}}, \&}
\DoxyCodeLine{4432                  default=bt\_cont\_string)}
\DoxyCodeLine{4433   \textcolor{keywordflow}{select case} (hvel\_str)}
\DoxyCodeLine{4434     \textcolor{keywordflow}{case} (hybrid\_string) ; cs\%hvel\_scheme = hybrid}
\DoxyCodeLine{4435     \textcolor{keywordflow}{case} (harmonic\_string) ; cs\%hvel\_scheme = harmonic}
\DoxyCodeLine{4436     \textcolor{keywordflow}{case} (arithmetic\_string) ; cs\%hvel\_scheme = arithmetic}
\DoxyCodeLine{4437     \textcolor{keywordflow}{case} (bt\_cont\_string) ; cs\%hvel\_scheme = from\_bt\_cont}
\DoxyCodeLine{4438 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{4439       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{'barotropic\_init: BT\_THICK\_SCHEME ="{}'}//trim(hvel\_str)//\textcolor{stringliteral}{'"{}'}, 0)}
\DoxyCodeLine{4440       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}barotropic\_init: Unrecognized setting "{}}// \&}
\DoxyCodeLine{4441             \textcolor{stringliteral}{"{}\#define BT\_THICK\_SCHEME "{}}//trim(hvel\_str)//\textcolor{stringliteral}{"{} found in input file."{}})}
\DoxyCodeLine{4442 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{4443   \textcolor{keywordflow}{if} ((cs\%hvel\_scheme == from\_bt\_cont) .and. .not.use\_bt\_cont\_type) \&}
\DoxyCodeLine{4444     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}barotropic\_init: BT\_THICK\_SCHEME FROM\_BT\_CONT "{}}//\&}
\DoxyCodeLine{4445                            \textcolor{stringliteral}{"{}can only be used if USE\_BT\_CONT\_TYPE is defined."{}})}
\DoxyCodeLine{4446 }
\DoxyCodeLine{4447   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_STRONG\_DRAG"{}}, cs\%strong\_drag, \&}
\DoxyCodeLine{4448                  \textcolor{stringliteral}{"{}If true, use a stronger estimate of the retarding "{}}//\&}
\DoxyCodeLine{4449                  \textcolor{stringliteral}{"{}effects of strong bottom drag, by making it implicit "{}}//\&}
\DoxyCodeLine{4450                  \textcolor{stringliteral}{"{}with the barotropic time-\/step instead of implicit with "{}}//\&}
\DoxyCodeLine{4451                  \textcolor{stringliteral}{"{}the baroclinic time-\/step and dividing by the number of "{}}//\&}
\DoxyCodeLine{4452                  \textcolor{stringliteral}{"{}barotropic steps."{}}, default=.false.)}
\DoxyCodeLine{4453   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_LINEAR\_WAVE\_DRAG"{}}, cs\%linear\_wave\_drag, \&}
\DoxyCodeLine{4454                  \textcolor{stringliteral}{"{}If true, apply a linear drag to the barotropic velocities, "{}}//\&}
\DoxyCodeLine{4455                  \textcolor{stringliteral}{"{}using rates set by lin\_drag\_u \& \_v divided by the depth of "{}}//\&}
\DoxyCodeLine{4456                  \textcolor{stringliteral}{"{}the ocean.  This was introduced to facilitate tide modeling."{}}, \&}
\DoxyCodeLine{4457                  default=.false.)}
\DoxyCodeLine{4458   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_WAVE\_DRAG\_FILE"{}}, wave\_drag\_file, \&}
\DoxyCodeLine{4459                  \textcolor{stringliteral}{"{}The name of the file with the barotropic linear wave drag "{}}//\&}
\DoxyCodeLine{4460                  \textcolor{stringliteral}{"{}piston velocities."{}}, default=\textcolor{stringliteral}{"{}"{}}, do\_not\_log=.not.cs\%linear\_wave\_drag)}
\DoxyCodeLine{4461   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_WAVE\_DRAG\_VAR"{}}, wave\_drag\_var, \&}
\DoxyCodeLine{4462                  \textcolor{stringliteral}{"{}The name of the variable in BT\_WAVE\_DRAG\_FILE with the "{}}//\&}
\DoxyCodeLine{4463                  \textcolor{stringliteral}{"{}barotropic linear wave drag piston velocities at h points."{}}, \&}
\DoxyCodeLine{4464                  default=\textcolor{stringliteral}{"{}rH"{}}, do\_not\_log=.not.cs\%linear\_wave\_drag)}
\DoxyCodeLine{4465   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_WAVE\_DRAG\_SCALE"{}}, wave\_drag\_scale, \&}
\DoxyCodeLine{4466                  \textcolor{stringliteral}{"{}A scaling factor for the barotropic linear wave drag "{}}//\&}
\DoxyCodeLine{4467                  \textcolor{stringliteral}{"{}piston velocities."{}}, default=1.0, units=\textcolor{stringliteral}{"{}nondim"{}}, \&}
\DoxyCodeLine{4468                  do\_not\_log=.not.cs\%linear\_wave\_drag)}
\DoxyCodeLine{4469 }
\DoxyCodeLine{4470   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CLIP\_BT\_VELOCITY"{}}, cs\%clip\_velocity, \&}
\DoxyCodeLine{4471                  \textcolor{stringliteral}{"{}If true, limit any velocity components that exceed "{}}//\&}
\DoxyCodeLine{4472                  \textcolor{stringliteral}{"{}CFL\_TRUNCATE.  This should only be used as a desperate "{}}//\&}
\DoxyCodeLine{4473                  \textcolor{stringliteral}{"{}debugging measure."{}}, default=.false.)}
\DoxyCodeLine{4474   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CFL\_TRUNCATE"{}}, cs\%CFL\_trunc, \&}
\DoxyCodeLine{4475                  \textcolor{stringliteral}{"{}The value of the CFL number that will cause velocity "{}}//\&}
\DoxyCodeLine{4476                  \textcolor{stringliteral}{"{}components to be truncated; instability can occur past 0.5."{}}, \&}
\DoxyCodeLine{4477                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.5, do\_not\_log=.not.cs\%clip\_velocity)}
\DoxyCodeLine{4478   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}MAXVEL"{}}, cs\%maxvel, \&}
\DoxyCodeLine{4479                  \textcolor{stringliteral}{"{}The maximum velocity allowed before the velocity "{}}//\&}
\DoxyCodeLine{4480                  \textcolor{stringliteral}{"{}components are truncated."{}}, units=\textcolor{stringliteral}{"{}m s-\/1"{}}, default=3.0e8, scale=us\%m\_s\_to\_L\_T, \&}
\DoxyCodeLine{4481                  do\_not\_log=.not.cs\%clip\_velocity)}
\DoxyCodeLine{4482   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}MAXCFL\_BT\_CONT"{}}, cs\%maxCFL\_BT\_cont, \&}
\DoxyCodeLine{4483                  \textcolor{stringliteral}{"{}The maximum permitted CFL number associated with the "{}}//\&}
\DoxyCodeLine{4484                  \textcolor{stringliteral}{"{}barotropic accelerations from the summed velocities "{}}//\&}
\DoxyCodeLine{4485                  \textcolor{stringliteral}{"{}times the time-\/derivatives of thicknesses."{}}, units=\textcolor{stringliteral}{"{}nondim"{}}, \&}
\DoxyCodeLine{4486                  default=0.25)}
\DoxyCodeLine{4487   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}VEL\_UNDERFLOW"{}}, cs\%vel\_underflow, \&}
\DoxyCodeLine{4488                  \textcolor{stringliteral}{"{}A negligibly small velocity magnitude below which velocity "{}}//\&}
\DoxyCodeLine{4489                  \textcolor{stringliteral}{"{}components are set to 0.  A reasonable value might be "{}}//\&}
\DoxyCodeLine{4490                  \textcolor{stringliteral}{"{}1e-\/30 m/s, which is less than an Angstrom divided by "{}}//\&}
\DoxyCodeLine{4491                  \textcolor{stringliteral}{"{}the age of the universe."{}}, units=\textcolor{stringliteral}{"{}m s-\/1"{}}, default=0.0, scale=us\%m\_s\_to\_L\_T)}
\DoxyCodeLine{4492 }
\DoxyCodeLine{4493   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DT\_BT\_FILTER"{}}, cs\%dt\_bt\_filter, \&}
\DoxyCodeLine{4494                  \textcolor{stringliteral}{"{}A time-\/scale over which the barotropic mode solutions "{}}//\&}
\DoxyCodeLine{4495                  \textcolor{stringliteral}{"{}are filtered, in seconds if positive, or as a fraction "{}}//\&}
\DoxyCodeLine{4496                  \textcolor{stringliteral}{"{}of DT if negative. When used this can never be taken to "{}}//\&}
\DoxyCodeLine{4497                  \textcolor{stringliteral}{"{}be longer than 2*dt.  Set this to 0 to apply no filtering."{}}, \&}
\DoxyCodeLine{4498                  units=\textcolor{stringliteral}{"{}sec or nondim"{}}, default=-\/0.25)}
\DoxyCodeLine{4499   \textcolor{keywordflow}{if} (cs\%dt\_bt\_filter > 0.0) cs\%dt\_bt\_filter = us\%s\_to\_T*cs\%dt\_bt\_filter}
\DoxyCodeLine{4500   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}G\_BT\_EXTRA"{}}, cs\%G\_extra, \&}
\DoxyCodeLine{4501                  \textcolor{stringliteral}{"{}A nondimensional factor by which gtot is enhanced."{}}, \&}
\DoxyCodeLine{4502                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.0)}
\DoxyCodeLine{4503   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}SSH\_EXTRA"{}}, ssh\_extra, \&}
\DoxyCodeLine{4504                  \textcolor{stringliteral}{"{}An estimate of how much higher SSH might get, for use "{}}//\&}
\DoxyCodeLine{4505                  \textcolor{stringliteral}{"{}in calculating the safe external wave speed. The "{}}//\&}
\DoxyCodeLine{4506                  \textcolor{stringliteral}{"{}default is the minimum of 10 m or 5\% of MAXIMUM\_DEPTH."{}}, \&}
\DoxyCodeLine{4507                  units=\textcolor{stringliteral}{"{}m"{}}, default=min(10.0,0.05*g\%max\_depth*us\%Z\_to\_m), scale=us\%m\_to\_Z)}
\DoxyCodeLine{4508 }
\DoxyCodeLine{4509   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEBUG"{}}, cs\%debug, \&}
\DoxyCodeLine{4510                  \textcolor{stringliteral}{"{}If true, write out verbose debugging data."{}}, \&}
\DoxyCodeLine{4511                  default=.false., debuggingparam=.true.)}
\DoxyCodeLine{4512   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DEBUG\_BT"{}}, cs\%debug\_bt, \&}
\DoxyCodeLine{4513                  \textcolor{stringliteral}{"{}If true, write out verbose debugging data within the "{}}//\&}
\DoxyCodeLine{4514                  \textcolor{stringliteral}{"{}barotropic time-\/stepping loop. The data volume can be "{}}//\&}
\DoxyCodeLine{4515                  \textcolor{stringliteral}{"{}quite large if this is true."{}}, default=cs\%debug, \&}
\DoxyCodeLine{4516                  debuggingparam=.true.)}
\DoxyCodeLine{4517 }
\DoxyCodeLine{4518   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}LINEARIZED\_BT\_CORIOLIS"{}}, cs\%linearized\_BT\_PV, \&}
\DoxyCodeLine{4519                  \textcolor{stringliteral}{"{}If true use the bottom depth instead of the total water column thickness "{}}//\&}
\DoxyCodeLine{4520                  \textcolor{stringliteral}{"{}in the barotropic Coriolis term calculations."{}}, default=.true.)}
\DoxyCodeLine{4521   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BEBT"{}}, cs\%bebt, \&}
\DoxyCodeLine{4522                  \textcolor{stringliteral}{"{}BEBT determines whether the barotropic time stepping "{}}//\&}
\DoxyCodeLine{4523                  \textcolor{stringliteral}{"{}uses the forward-\/backward time-\/stepping scheme or a "{}}//\&}
\DoxyCodeLine{4524                  \textcolor{stringliteral}{"{}backward Euler scheme. BEBT is valid in the range from "{}}//\&}
\DoxyCodeLine{4525                  \textcolor{stringliteral}{"{}0 (for a forward-\/backward treatment of nonrotating "{}}//\&}
\DoxyCodeLine{4526                  \textcolor{stringliteral}{"{}gravity waves) to 1 (for a backward Euler treatment). "{}}//\&}
\DoxyCodeLine{4527                  \textcolor{stringliteral}{"{}In practice, BEBT must be greater than about 0.05."{}}, \&}
\DoxyCodeLine{4528                  units=\textcolor{stringliteral}{"{}nondim"{}}, default=0.1)}
\DoxyCodeLine{4529   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DTBT"{}}, dtbt\_input, \&}
\DoxyCodeLine{4530                  \textcolor{stringliteral}{"{}The barotropic time step, in s. DTBT is only used with "{}}//\&}
\DoxyCodeLine{4531                  \textcolor{stringliteral}{"{}the split explicit time stepping. To set the time step "{}}//\&}
\DoxyCodeLine{4532                  \textcolor{stringliteral}{"{}automatically based the maximum stable value use 0, or "{}}//\&}
\DoxyCodeLine{4533                  \textcolor{stringliteral}{"{}a negative value gives the fraction of the stable value. "{}}//\&}
\DoxyCodeLine{4534                  \textcolor{stringliteral}{"{}Setting DTBT to 0 is the same as setting it to -\/0.98. "{}}//\&}
\DoxyCodeLine{4535                  \textcolor{stringliteral}{"{}The value of DTBT that will actually be used is an "{}}//\&}
\DoxyCodeLine{4536                  \textcolor{stringliteral}{"{}integer fraction of DT, rounding down."{}}, units=\textcolor{stringliteral}{"{}s or nondim"{}},\&}
\DoxyCodeLine{4537                  default = -\/0.98)}
\DoxyCodeLine{4538   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}BT\_USE\_OLD\_CORIOLIS\_BRACKET\_BUG"{}}, \&}
\DoxyCodeLine{4539                  cs\%use\_old\_coriolis\_bracket\_bug , \&}
\DoxyCodeLine{4540                  \textcolor{stringliteral}{"{}If True, use an order of operations that is not bitwise "{}}//\&}
\DoxyCodeLine{4541                  \textcolor{stringliteral}{"{}rotationally symmetric in the meridional Coriolis term of "{}}//\&}
\DoxyCodeLine{4542                  \textcolor{stringliteral}{"{}the barotropic solver."{}}, default=.false.)}
\DoxyCodeLine{4543 }
\DoxyCodeLine{4544   \textcolor{comment}{! Initialize a version of the MOM domain that is specific to the barotropic solver.}}
\DoxyCodeLine{4545   \textcolor{keyword}{call }clone\_mom\_domain(g\%Domain, cs\%BT\_Domain, min\_halo=wd\_halos, symmetric=.true.)}
\DoxyCodeLine{4546 \textcolor{preprocessor}{\#ifdef STATIC\_MEMORY\_}}
\DoxyCodeLine{4547 \textcolor{preprocessor}{}  \textcolor{keywordflow}{if} (wd\_halos(1) /= whaloi\_+nihalo\_) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}barotropic\_init: "{}}//\&}
\DoxyCodeLine{4548           \textcolor{stringliteral}{"{}Barotropic x-\/halo sizes are incorrectly resized with STATIC\_MEMORY\_."{}})}
\DoxyCodeLine{4549   \textcolor{keywordflow}{if} (wd\_halos(2) /= whaloj\_+njhalo\_) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}barotropic\_init: "{}}//\&}
\DoxyCodeLine{4550           \textcolor{stringliteral}{"{}Barotropic y-\/halo sizes are incorrectly resized with STATIC\_MEMORY\_."{}})}
\DoxyCodeLine{4551 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{4552 \textcolor{preprocessor}{}  \textcolor{keywordflow}{if} (bt\_halo\_sz > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4553     \textcolor{keywordflow}{if} (wd\_halos(1) > bt\_halo\_sz) \&}
\DoxyCodeLine{4554       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"{}barotropic\_init: barotropic x-\/halo size increased."{}}, 3)}
\DoxyCodeLine{4555     \textcolor{keywordflow}{if} (wd\_halos(2) > bt\_halo\_sz) \&}
\DoxyCodeLine{4556       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"{}barotropic\_init: barotropic y-\/halo size increased."{}}, 3)}
\DoxyCodeLine{4557 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4558 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{4559 \textcolor{preprocessor}{}}
\DoxyCodeLine{4560   cs\%isdw = g\%isc-\/wd\_halos(1) ; cs\%iedw = g\%iec+wd\_halos(1)}
\DoxyCodeLine{4561   cs\%jsdw = g\%jsc-\/wd\_halos(2) ; cs\%jedw = g\%jec+wd\_halos(2)}
\DoxyCodeLine{4562   isdw = cs\%isdw ; iedw = cs\%iedw ; jsdw = cs\%jsdw ; jedw = cs\%jedw}
\DoxyCodeLine{4563 }
\DoxyCodeLine{4564   alloc\_(cs\%frhatu(isdb:iedb,jsd:jed,nz)) ; alloc\_(cs\%frhatv(isd:ied,jsdb:jedb,nz))}
\DoxyCodeLine{4565   alloc\_(cs\%eta\_cor(isd:ied,jsd:jed))}
\DoxyCodeLine{4566   \textcolor{keywordflow}{if} (cs\%bound\_BT\_corr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4567     alloc\_(cs\%eta\_cor\_bound(isd:ied,jsd:jed)) ; cs\%eta\_cor\_bound(:,:) = 0.0}
\DoxyCodeLine{4568 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4569   alloc\_(cs\%IDatu(isdb:iedb,jsd:jed)) ; alloc\_(cs\%IDatv(isd:ied,jsdb:jedb))}
\DoxyCodeLine{4570 }
\DoxyCodeLine{4571   alloc\_(cs\%ua\_polarity(isdw:iedw,jsdw:jedw))}
\DoxyCodeLine{4572   alloc\_(cs\%va\_polarity(isdw:iedw,jsdw:jedw))}
\DoxyCodeLine{4573 }
\DoxyCodeLine{4574   cs\%frhatu(:,:,:) = 0.0 ; cs\%frhatv(:,:,:) = 0.0}
\DoxyCodeLine{4575   cs\%eta\_cor(:,:) = 0.0}
\DoxyCodeLine{4576   cs\%IDatu(:,:) = 0.0 ; cs\%IDatv(:,:) = 0.0}
\DoxyCodeLine{4577 }
\DoxyCodeLine{4578   cs\%ua\_polarity(:,:) = 1.0 ; cs\%va\_polarity(:,:) = 1.0}
\DoxyCodeLine{4579   \textcolor{keyword}{call }create\_group\_pass(pass\_a\_polarity, cs\%ua\_polarity, cs\%va\_polarity, cs\%BT\_domain, to\_all, agrid)}
\DoxyCodeLine{4580   \textcolor{keyword}{call }do\_group\_pass(pass\_a\_polarity, cs\%BT\_domain)}
\DoxyCodeLine{4581 }
\DoxyCodeLine{4582   \textcolor{keywordflow}{if} (use\_bt\_cont\_type) \&}
\DoxyCodeLine{4583     \textcolor{keyword}{call }alloc\_bt\_cont\_type(bt\_cont, g, (cs\%hvel\_scheme == from\_bt\_cont))}
\DoxyCodeLine{4584 }
\DoxyCodeLine{4585   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then} \textcolor{comment}{! Make a local copy of loop ranges for chksum calls}}
\DoxyCodeLine{4586     \textcolor{keyword}{allocate}(cs\%debug\_BT\_HI)}
\DoxyCodeLine{4587     cs\%debug\_BT\_HI\%isc=g\%isc}
\DoxyCodeLine{4588     cs\%debug\_BT\_HI\%iec=g\%iec}
\DoxyCodeLine{4589     cs\%debug\_BT\_HI\%jsc=g\%jsc}
\DoxyCodeLine{4590     cs\%debug\_BT\_HI\%jec=g\%jec}
\DoxyCodeLine{4591     cs\%debug\_BT\_HI\%IscB=g\%isc-\/1}
\DoxyCodeLine{4592     cs\%debug\_BT\_HI\%IecB=g\%iec}
\DoxyCodeLine{4593     cs\%debug\_BT\_HI\%JscB=g\%jsc-\/1}
\DoxyCodeLine{4594     cs\%debug\_BT\_HI\%JecB=g\%jec}
\DoxyCodeLine{4595     cs\%debug\_BT\_HI\%isd=cs\%isdw}
\DoxyCodeLine{4596     cs\%debug\_BT\_HI\%ied=cs\%iedw}
\DoxyCodeLine{4597     cs\%debug\_BT\_HI\%jsd=cs\%jsdw}
\DoxyCodeLine{4598     cs\%debug\_BT\_HI\%jed=cs\%jedw}
\DoxyCodeLine{4599     cs\%debug\_BT\_HI\%IsdB=cs\%isdw-\/1}
\DoxyCodeLine{4600     cs\%debug\_BT\_HI\%IedB=cs\%iedw}
\DoxyCodeLine{4601     cs\%debug\_BT\_HI\%JsdB=cs\%jsdw-\/1}
\DoxyCodeLine{4602     cs\%debug\_BT\_HI\%JedB=cs\%jedw}
\DoxyCodeLine{4603     cs\%debug\_BT\_HI\%turns = g\%HI\%turns}
\DoxyCodeLine{4604 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4605 }
\DoxyCodeLine{4606   \textcolor{comment}{! IareaT, IdxCu, and IdyCv need to be allocated with wide halos.}}
\DoxyCodeLine{4607   alloc\_(cs\%IareaT(cs\%isdw:cs\%iedw,cs\%jsdw:cs\%jedw)) ; cs\%IareaT(:,:) = 0.0}
\DoxyCodeLine{4608   alloc\_(cs\%bathyT(cs\%isdw:cs\%iedw,cs\%jsdw:cs\%jedw)) ; cs\%bathyT(:,:) = gv\%Angstrom\_m \textcolor{comment}{!\#\#\# Change to 0.0?}}
\DoxyCodeLine{4609   alloc\_(cs\%IdxCu(cs\%isdw-\/1:cs\%iedw,cs\%jsdw:cs\%jedw)) ; cs\%IdxCu(:,:) = 0.0}
\DoxyCodeLine{4610   alloc\_(cs\%IdyCv(cs\%isdw:cs\%iedw,cs\%jsdw-\/1:cs\%jedw)) ; cs\%IdyCv(:,:) = 0.0}
\DoxyCodeLine{4611   alloc\_(cs\%dy\_Cu(cs\%isdw-\/1:cs\%iedw,cs\%jsdw:cs\%jedw)) ; cs\%dy\_Cu(:,:) = 0.0}
\DoxyCodeLine{4612   alloc\_(cs\%dx\_Cv(cs\%isdw:cs\%iedw,cs\%jsdw-\/1:cs\%jedw)) ; cs\%dx\_Cv(:,:) = 0.0}
\DoxyCodeLine{4613   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{4614     cs\%IareaT(i,j) = g\%IareaT(i,j)}
\DoxyCodeLine{4615     cs\%bathyT(i,j) = g\%bathyT(i,j)}
\DoxyCodeLine{4616 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4617 }
\DoxyCodeLine{4618   \textcolor{comment}{! Note: G\%IdxCu \& G\%IdyCv may be valid for a smaller extent than CS\%IdxCu \& CS\%IdyCv, even without}}
\DoxyCodeLine{4619   \textcolor{comment}{!   wide halos.}}
\DoxyCodeLine{4620   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB}
\DoxyCodeLine{4621     cs\%IdxCu(i,j) = g\%IdxCu(i,j) ; cs\%dy\_Cu(i,j) = g\%dy\_Cu(i,j)}
\DoxyCodeLine{4622 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4623   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{4624     cs\%IdyCv(i,j) = g\%IdyCv(i,j) ; cs\%dx\_Cv(i,j) = g\%dx\_Cv(i,j)}
\DoxyCodeLine{4625 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4626   \textcolor{keyword}{call }create\_group\_pass(pass\_static\_data, cs\%IareaT, cs\%BT\_domain, to\_all)}
\DoxyCodeLine{4627   \textcolor{keyword}{call }create\_group\_pass(pass\_static\_data, cs\%bathyT, cs\%BT\_domain, to\_all)}
\DoxyCodeLine{4628   \textcolor{keyword}{call }create\_group\_pass(pass\_static\_data, cs\%IdxCu, cs\%IdyCv, cs\%BT\_domain, to\_all+scalar\_pair)}
\DoxyCodeLine{4629   \textcolor{keyword}{call }create\_group\_pass(pass\_static\_data, cs\%dy\_Cu, cs\%dx\_Cv, cs\%BT\_domain, to\_all+scalar\_pair)}
\DoxyCodeLine{4630   \textcolor{keyword}{call }do\_group\_pass(pass\_static\_data, cs\%BT\_domain)}
\DoxyCodeLine{4631 }
\DoxyCodeLine{4632   \textcolor{keywordflow}{if} (cs\%linearized\_BT\_PV) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4633     alloc\_(cs\%q\_D(cs\%isdw-\/1:cs\%iedw,cs\%jsdw-\/1:cs\%jedw))}
\DoxyCodeLine{4634     alloc\_(cs\%D\_u\_Cor(cs\%isdw-\/1:cs\%iedw,cs\%jsdw:cs\%jedw))}
\DoxyCodeLine{4635     alloc\_(cs\%D\_v\_Cor(cs\%isdw:cs\%iedw,cs\%jsdw-\/1:cs\%jedw))}
\DoxyCodeLine{4636     cs\%q\_D(:,:) = 0.0 ; cs\%D\_u\_Cor(:,:) = 0.0 ; cs\%D\_v\_Cor(:,:) = 0.0}
\DoxyCodeLine{4637 }
\DoxyCodeLine{4638     mean\_sl = g\%Z\_ref}
\DoxyCodeLine{4639     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{4640       cs\%D\_u\_Cor(i,j) = 0.5 * (max(mean\_sl+g\%bathyT(i+1,j),0.0) + max(mean\_sl+g\%bathyT(i,j),0.0))}
\DoxyCodeLine{4641 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4642     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4643       cs\%D\_v\_Cor(i,j) = 0.5 * (max(mean\_sl+g\%bathyT(i,j+1),0.0) + max(mean\_sl+g\%bathyT(i,j),0.0))}
\DoxyCodeLine{4644 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4645     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{4646       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)+g\%mask2dT(i,j+1)+g\%mask2dT(i+1,j)+g\%mask2dT(i+1,j+1)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4647         cs\%q\_D(i,j) = 0.25 * (cs\%BT\_Coriolis\_scale * g\%CoriolisBu(i,j)) * \&}
\DoxyCodeLine{4648            ((g\%areaT(i,j) + g\%areaT(i+1,j+1)) + (g\%areaT(i+1,j) + g\%areaT(i,j+1))) / \&}
\DoxyCodeLine{4649            (max(((g\%areaT(i,j) * max(mean\_sl+g\%bathyT(i,j),0.0) + \&}
\DoxyCodeLine{4650                   g\%areaT(i+1,j+1) * max(mean\_sl+g\%bathyT(i+1,j+1),0.0)) + \&}
\DoxyCodeLine{4651                  (g\%areaT(i+1,j) * max(mean\_sl+g\%bathyT(i+1,j),0.0) + \&}
\DoxyCodeLine{4652                   g\%areaT(i,j+1) * max(mean\_sl+g\%bathyT(i,j+1),0.0))), gv\%H\_to\_Z*gv\%H\_subroundoff) )}
\DoxyCodeLine{4653       \textcolor{keywordflow}{else} \textcolor{comment}{! All four h points are masked out so q\_D(I,J) will is meaningless}}
\DoxyCodeLine{4654         cs\%q\_D(i,j) = 0.}
\DoxyCodeLine{4655 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{4656 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4657     \textcolor{comment}{! With very wide halos, q and D need to be calculated on the available data}}
\DoxyCodeLine{4658     \textcolor{comment}{! domain and then updated onto the full computational domain.}}
\DoxyCodeLine{4659     \textcolor{keyword}{call }create\_group\_pass(pass\_q\_d\_cor, cs\%q\_D, cs\%BT\_Domain, to\_all, position=corner)}
\DoxyCodeLine{4660     \textcolor{keyword}{call }create\_group\_pass(pass\_q\_d\_cor, cs\%D\_u\_Cor, cs\%D\_v\_Cor, cs\%BT\_Domain, \&}
\DoxyCodeLine{4661                            to\_all+scalar\_pair)}
\DoxyCodeLine{4662     \textcolor{keyword}{call }do\_group\_pass(pass\_q\_d\_cor, cs\%BT\_Domain)}
\DoxyCodeLine{4663 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4664 }
\DoxyCodeLine{4665   \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4666     alloc\_(cs\%lin\_drag\_u(isdb:iedb,jsd:jed)) ; cs\%lin\_drag\_u(:,:) = 0.0}
\DoxyCodeLine{4667     alloc\_(cs\%lin\_drag\_v(isd:ied,jsdb:jedb)) ; cs\%lin\_drag\_v(:,:) = 0.0}
\DoxyCodeLine{4668 }
\DoxyCodeLine{4669     \textcolor{keywordflow}{if} (len\_trim(wave\_drag\_file) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4670       inputdir = \textcolor{stringliteral}{"{}."{}} ;  \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INPUTDIR"{}}, inputdir)}
\DoxyCodeLine{4671       wave\_drag\_file = trim(slasher(inputdir))//trim(wave\_drag\_file)}
\DoxyCodeLine{4672       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}INPUTDIR/BT\_WAVE\_DRAG\_FILE"{}}, wave\_drag\_file)}
\DoxyCodeLine{4673 }
\DoxyCodeLine{4674       \textcolor{keyword}{allocate}(lin\_drag\_h(isd:ied,jsd:jed)) ; lin\_drag\_h(:,:) = 0.0}
\DoxyCodeLine{4675 }
\DoxyCodeLine{4676       \textcolor{keyword}{call }mom\_read\_data(wave\_drag\_file, wave\_drag\_var, lin\_drag\_h, g\%Domain, scale=us\%m\_to\_Z*us\%T\_to\_s)}
\DoxyCodeLine{4677       \textcolor{keyword}{call }pass\_var(lin\_drag\_h, g\%Domain)}
\DoxyCodeLine{4678       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{4679         cs\%lin\_drag\_u(i,j) = (gv\%Z\_to\_H * wave\_drag\_scale) * \&}
\DoxyCodeLine{4680            0.5 * (lin\_drag\_h(i,j) + lin\_drag\_h(i+1,j))}
\DoxyCodeLine{4681 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4682       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4683         cs\%lin\_drag\_v(i,j) = (gv\%Z\_to\_H * wave\_drag\_scale) * \&}
\DoxyCodeLine{4684             0.5 * (lin\_drag\_h(i,j) + lin\_drag\_h(i,j+1))}
\DoxyCodeLine{4685 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4686       \textcolor{keyword}{deallocate}(lin\_drag\_h)}
\DoxyCodeLine{4687 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{4688 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4689 }
\DoxyCodeLine{4690   cs\%dtbt\_fraction = 0.98 ; \textcolor{keywordflow}{if} (dtbt\_input < 0.0) cs\%dtbt\_fraction = -\/dtbt\_input}
\DoxyCodeLine{4691 }
\DoxyCodeLine{4692   dtbt\_tmp = -\/1.0}
\DoxyCodeLine{4693   \textcolor{keywordflow}{if} (query\_initialized(cs\%dtbt, \textcolor{stringliteral}{"{}DTBT"{}}, restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4694     dtbt\_tmp = cs\%dtbt}
\DoxyCodeLine{4695     \textcolor{keywordflow}{if} ((us\%s\_to\_T\_restart /= 0.0) .and. (us\%s\_to\_T\_restart /= us\%s\_to\_T)) \&}
\DoxyCodeLine{4696       dtbt\_tmp = (us\%s\_to\_T / us\%s\_to\_T\_restart) * cs\%dtbt}
\DoxyCodeLine{4697 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4698 }
\DoxyCodeLine{4699   \textcolor{comment}{! Estimate the maximum stable barotropic time step.}}
\DoxyCodeLine{4700   gtot\_estimate = 0.0}
\DoxyCodeLine{4701   \textcolor{keywordflow}{do} k=1,g\%ke ; gtot\_estimate = gtot\_estimate + gv\%g\_prime(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4702   \textcolor{keyword}{call }set\_dtbt(g, gv, us, cs, gtot\_est=gtot\_estimate, ssh\_add=ssh\_extra)}
\DoxyCodeLine{4703 }
\DoxyCodeLine{4704   \textcolor{keywordflow}{if} (dtbt\_input > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4705     cs\%dtbt = us\%s\_to\_T * dtbt\_input}
\DoxyCodeLine{4706   \textcolor{keywordflow}{elseif} (dtbt\_tmp > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4707     cs\%dtbt = dtbt\_tmp}
\DoxyCodeLine{4708 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4709   \textcolor{keywordflow}{if} ((dtbt\_tmp > 0.0) .and. (dtbt\_input > 0.0)) calc\_dtbt = .false.}
\DoxyCodeLine{4710 }
\DoxyCodeLine{4711   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}DTBT as used"{}}, cs\%dtbt*us\%T\_to\_s)}
\DoxyCodeLine{4712   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}estimated maximum DTBT"{}}, cs\%dtbt\_max*us\%T\_to\_s)}
\DoxyCodeLine{4713 }
\DoxyCodeLine{4714   \textcolor{comment}{! ubtav and vbtav, and perhaps ubt\_IC and vbt\_IC, are allocated and}}
\DoxyCodeLine{4715   \textcolor{comment}{! initialized in register\_barotropic\_restarts.}}
\DoxyCodeLine{4716 }
\DoxyCodeLine{4717   \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4718     thickness\_units = \textcolor{stringliteral}{"{}m"{}} ; flux\_units = \textcolor{stringliteral}{"{}m3 s-\/1"{}}}
\DoxyCodeLine{4719   \textcolor{keywordflow}{else}}
\DoxyCodeLine{4720     thickness\_units = \textcolor{stringliteral}{"{}kg m-\/2"{}} ; flux\_units = \textcolor{stringliteral}{"{}kg s-\/1"{}}}
\DoxyCodeLine{4721 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4722 }
\DoxyCodeLine{4723   cs\%id\_PFu\_bt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'PFuBT'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4724       \textcolor{stringliteral}{'Zonal Anomalous Barotropic Pressure Force Force Acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4725   cs\%id\_PFv\_bt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'PFvBT'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4726       \textcolor{stringliteral}{'Meridional Anomalous Barotropic Pressure Force Acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4727   cs\%id\_Coru\_bt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'CoruBT'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4728       \textcolor{stringliteral}{'Zonal Barotropic Coriolis Acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4729   cs\%id\_Corv\_bt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'CorvBT'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4730       \textcolor{stringliteral}{'Meridional Barotropic Coriolis Acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4731   cs\%id\_uaccel = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'u\_accel\_bt'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4732       \textcolor{stringliteral}{'Barotropic zonal acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4733   cs\%id\_vaccel = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'v\_accel\_bt'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4734       \textcolor{stringliteral}{'Barotropic meridional acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4735   cs\%id\_ubtforce = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ubtforce'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4736       \textcolor{stringliteral}{'Barotropic zonal acceleration from baroclinic terms'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4737   cs\%id\_vbtforce = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vbtforce'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4738       \textcolor{stringliteral}{'Barotropic meridional acceleration from baroclinic terms'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4739   cs\%id\_ubtdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ubt\_dt'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4740       \textcolor{stringliteral}{'Barotropic zonal acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4741   cs\%id\_vbtdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vbt\_dt'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4742       \textcolor{stringliteral}{'Barotropic meridional acceleration'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{4743 }
\DoxyCodeLine{4744   cs\%id\_eta\_bt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'eta\_bt'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4745       \textcolor{stringliteral}{'Barotropic end SSH'}, thickness\_units, conversion=gv\%H\_to\_m)}
\DoxyCodeLine{4746   cs\%id\_ubt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ubt'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4747       \textcolor{stringliteral}{'Barotropic end zonal velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4748   cs\%id\_vbt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vbt'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4749       \textcolor{stringliteral}{'Barotropic end meridional velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4750   cs\%id\_eta\_st = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'eta\_st'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4751       \textcolor{stringliteral}{'Barotropic start SSH'}, thickness\_units, conversion=gv\%H\_to\_m)}
\DoxyCodeLine{4752   cs\%id\_ubt\_st = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ubt\_st'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4753       \textcolor{stringliteral}{'Barotropic start zonal velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4754   cs\%id\_vbt\_st = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vbt\_st'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4755       \textcolor{stringliteral}{'Barotropic start meridional velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4756   cs\%id\_ubtav = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ubtav'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4757       \textcolor{stringliteral}{'Barotropic time-\/average zonal velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4758   cs\%id\_vbtav = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vbtav'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4759       \textcolor{stringliteral}{'Barotropic time-\/average meridional velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4760   cs\%id\_eta\_cor = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'eta\_cor'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4761       \textcolor{stringliteral}{'Corrective mass flux'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=gv\%H\_to\_m)}
\DoxyCodeLine{4762   cs\%id\_visc\_rem\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'visc\_rem\_u'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{4763       \textcolor{stringliteral}{'Viscous remnant at u'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{4764   cs\%id\_visc\_rem\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'visc\_rem\_v'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{4765       \textcolor{stringliteral}{'Viscous remnant at v'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{4766   cs\%id\_gtotn = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'gtot\_n'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4767       \textcolor{stringliteral}{'gtot to North'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=gv\%m\_to\_H*(us\%L\_T\_to\_m\_s**2))}
\DoxyCodeLine{4768   cs\%id\_gtots = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'gtot\_s'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4769       \textcolor{stringliteral}{'gtot to South'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=gv\%m\_to\_H*(us\%L\_T\_to\_m\_s**2))}
\DoxyCodeLine{4770   cs\%id\_gtote = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'gtot\_e'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4771       \textcolor{stringliteral}{'gtot to East'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=gv\%m\_to\_H*(us\%L\_T\_to\_m\_s**2))}
\DoxyCodeLine{4772   cs\%id\_gtotw = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'gtot\_w'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4773       \textcolor{stringliteral}{'gtot to West'}, \textcolor{stringliteral}{'m s-\/2'}, conversion=gv\%m\_to\_H*(us\%L\_T\_to\_m\_s**2))}
\DoxyCodeLine{4774   cs\%id\_eta\_hifreq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'eta\_hifreq'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4775       \textcolor{stringliteral}{'High Frequency Barotropic SSH'}, thickness\_units, conversion=gv\%H\_to\_m)}
\DoxyCodeLine{4776   cs\%id\_ubt\_hifreq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ubt\_hifreq'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4777       \textcolor{stringliteral}{'High Frequency Barotropic zonal velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4778   cs\%id\_vbt\_hifreq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vbt\_hifreq'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4779       \textcolor{stringliteral}{'High Frequency Barotropic meridional velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4780   cs\%id\_eta\_pred\_hifreq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'eta\_pred\_hifreq'}, diag\%axesT1, time, \&}
\DoxyCodeLine{4781       \textcolor{stringliteral}{'High Frequency Predictor Barotropic SSH'}, thickness\_units, \&}
\DoxyCodeLine{4782       conversion=gv\%H\_to\_m)}
\DoxyCodeLine{4783   cs\%id\_uhbt\_hifreq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhbt\_hifreq'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4784       \textcolor{stringliteral}{'High Frequency Barotropic zonal transport'}, \textcolor{stringliteral}{'m3 s-\/1'}, \&}
\DoxyCodeLine{4785       conversion=gv\%H\_to\_m*us\%L\_to\_m*us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4786   cs\%id\_vhbt\_hifreq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhbt\_hifreq'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4787       \textcolor{stringliteral}{'High Frequency Barotropic meridional transport'}, \textcolor{stringliteral}{'m3 s-\/1'}, \&}
\DoxyCodeLine{4788       conversion=gv\%H\_to\_m*us\%L\_to\_m*us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4789   cs\%id\_frhatu = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'frhatu'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{4790       \textcolor{stringliteral}{'Fractional thickness of layers in u-\/columns'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{4791   cs\%id\_frhatv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'frhatv'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{4792       \textcolor{stringliteral}{'Fractional thickness of layers in v-\/columns'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{4793   cs\%id\_frhatu1 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'frhatu1'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{4794       \textcolor{stringliteral}{'Predictor Fractional thickness of layers in u-\/columns'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{4795   cs\%id\_frhatv1 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'frhatv1'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{4796       \textcolor{stringliteral}{'Predictor Fractional thickness of layers in v-\/columns'}, \textcolor{stringliteral}{'nondim'})}
\DoxyCodeLine{4797   cs\%id\_uhbt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhbt'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4798       \textcolor{stringliteral}{'Barotropic zonal transport averaged over a baroclinic step'}, \textcolor{stringliteral}{'m3 s-\/1'}, \&}
\DoxyCodeLine{4799       conversion=gv\%H\_to\_m*us\%L\_to\_m*us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4800   cs\%id\_vhbt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhbt'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4801       \textcolor{stringliteral}{'Barotropic meridional transport averaged over a baroclinic step'}, \textcolor{stringliteral}{'m3 s-\/1'}, \&}
\DoxyCodeLine{4802       conversion=gv\%H\_to\_m*us\%L\_to\_m*us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4803 }
\DoxyCodeLine{4804   \textcolor{keywordflow}{if} (use\_bt\_cont\_type) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4805     cs\%id\_BTC\_FA\_u\_EE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_u\_EE'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4806         \textcolor{stringliteral}{'BTCont type far east face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4807     cs\%id\_BTC\_FA\_u\_E0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_u\_E0'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4808         \textcolor{stringliteral}{'BTCont type near east face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4809     cs\%id\_BTC\_FA\_u\_WW = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_u\_WW'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4810         \textcolor{stringliteral}{'BTCont type far west face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4811     cs\%id\_BTC\_FA\_u\_W0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_u\_W0'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4812         \textcolor{stringliteral}{'BTCont type near west face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4813     cs\%id\_BTC\_ubt\_EE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_ubt\_EE'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4814         \textcolor{stringliteral}{'BTCont type far east velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4815     cs\%id\_BTC\_ubt\_WW = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_ubt\_WW'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4816         \textcolor{stringliteral}{'BTCont type far west velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4817     \textcolor{comment}{! This is a specialized diagnostic that is not being made widely available (yet).}}
\DoxyCodeLine{4818     \textcolor{comment}{! CS\%id\_BTC\_FA\_u\_rat0 = register\_diag\_field('ocean\_model', 'BTC\_FA\_u\_rat0', diag\%axesCu1, Time, \&}}
\DoxyCodeLine{4819     \textcolor{comment}{!     'BTCont type ratio of near east and west face areas', 'nondim')}}
\DoxyCodeLine{4820     cs\%id\_BTC\_FA\_v\_NN = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_v\_NN'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4821         \textcolor{stringliteral}{'BTCont type far north face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4822     cs\%id\_BTC\_FA\_v\_N0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_v\_N0'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4823         \textcolor{stringliteral}{'BTCont type near north face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4824     cs\%id\_BTC\_FA\_v\_SS = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_v\_SS'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4825         \textcolor{stringliteral}{'BTCont type far south face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4826     cs\%id\_BTC\_FA\_v\_S0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_FA\_v\_S0'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4827         \textcolor{stringliteral}{'BTCont type near south face area'}, \textcolor{stringliteral}{'m2'}, conversion=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{4828     cs\%id\_BTC\_vbt\_NN = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_vbt\_NN'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4829         \textcolor{stringliteral}{'BTCont type far north velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4830     cs\%id\_BTC\_vbt\_SS = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'BTC\_vbt\_SS'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4831         \textcolor{stringliteral}{'BTCont type far south velocity'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{4832     \textcolor{comment}{! This is a specialized diagnostic that is not being made widely available (yet).}}
\DoxyCodeLine{4833     \textcolor{comment}{! CS\%id\_BTC\_FA\_v\_rat0 = register\_diag\_field('ocean\_model', 'BTC\_FA\_v\_rat0', diag\%axesCv1, Time, \&}}
\DoxyCodeLine{4834     \textcolor{comment}{!     'BTCont type ratio of near north and south face areas', 'nondim')}}
\DoxyCodeLine{4835     \textcolor{comment}{! CS\%id\_BTC\_FA\_h\_rat0 = register\_diag\_field('ocean\_model', 'BTC\_FA\_h\_rat0', diag\%axesT1, Time, \&}}
\DoxyCodeLine{4836     \textcolor{comment}{!     'BTCont type maximum ratios of near face areas around cells', 'nondim')}}
\DoxyCodeLine{4837 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4838   cs\%id\_uhbt0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhbt0'}, diag\%axesCu1, time, \&}
\DoxyCodeLine{4839       \textcolor{stringliteral}{'Barotropic zonal transport difference'}, \textcolor{stringliteral}{'m3 s-\/1'}, conversion=gv\%H\_to\_m*us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{4840   cs\%id\_vhbt0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhbt0'}, diag\%axesCv1, time, \&}
\DoxyCodeLine{4841       \textcolor{stringliteral}{'Barotropic meridional transport difference'}, \textcolor{stringliteral}{'m3 s-\/1'}, conversion=gv\%H\_to\_m*us\%L\_to\_m**2*us\%s\_to\_T)}
\DoxyCodeLine{4842 }
\DoxyCodeLine{4843   \textcolor{keywordflow}{if} (cs\%id\_frhatu1 > 0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%frhatu1, isdb,iedb,jsd,jed,nz)}
\DoxyCodeLine{4844   \textcolor{keywordflow}{if} (cs\%id\_frhatv1 > 0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%frhatv1, isd,ied,jsdb,jedb,nz)}
\DoxyCodeLine{4845 }
\DoxyCodeLine{4846   \textcolor{keywordflow}{if} (.NOT.query\_initialized(cs\%ubtav,\textcolor{stringliteral}{"{}ubtav"{}},restart\_cs) .or. \&}
\DoxyCodeLine{4847       .NOT.query\_initialized(cs\%vbtav,\textcolor{stringliteral}{"{}vbtav"{}},restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4848     \textcolor{keyword}{call }btcalc(h, g, gv, cs, may\_use\_default=.true.)}
\DoxyCodeLine{4849     cs\%ubtav(:,:) = 0.0 ; cs\%vbtav(:,:) = 0.0}
\DoxyCodeLine{4850     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{4851       cs\%ubtav(i,j) = cs\%ubtav(i,j) + cs\%frhatu(i,j,k) * u(i,j,k)}
\DoxyCodeLine{4852 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4853     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4854       cs\%vbtav(i,j) = cs\%vbtav(i,j) + cs\%frhatv(i,j,k) * v(i,j,k)}
\DoxyCodeLine{4855 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4856   \textcolor{keywordflow}{elseif} ((us\%s\_to\_T\_restart*us\%m\_to\_L\_restart /= 0.0) .and. \&}
\DoxyCodeLine{4857           (us\%m\_to\_L*us\%s\_to\_T\_restart) /= (us\%m\_to\_L\_restart*us\%s\_to\_T)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4858     vel\_rescale = (us\%m\_to\_L*us\%s\_to\_T\_restart) / (us\%m\_to\_L\_restart*us\%s\_to\_T)}
\DoxyCodeLine{4859     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; cs\%ubtav(i,j) = vel\_rescale * cs\%ubtav(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4860     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; cs\%vbtav(i,j) = vel\_rescale * cs\%vbtav(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4861 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4862 }
\DoxyCodeLine{4863   \textcolor{keywordflow}{if} (cs\%gradual\_BT\_ICs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4864     \textcolor{keywordflow}{if} (.NOT.query\_initialized(cs\%ubt\_IC,\textcolor{stringliteral}{"{}ubt\_IC"{}},restart\_cs) .or. \&}
\DoxyCodeLine{4865         .NOT.query\_initialized(cs\%vbt\_IC,\textcolor{stringliteral}{"{}vbt\_IC"{}},restart\_cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4866       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; cs\%ubt\_IC(i,j) = cs\%ubtav(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4867       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; cs\%vbt\_IC(i,j) = cs\%vbtav(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4868     \textcolor{keywordflow}{elseif} ((us\%s\_to\_T\_restart*us\%m\_to\_L\_restart /= 0.0) .and. \&}
\DoxyCodeLine{4869             (us\%m\_to\_L*us\%s\_to\_T\_restart) /= (us\%m\_to\_L\_restart*us\%s\_to\_T)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4870       vel\_rescale = (us\%m\_to\_L*us\%s\_to\_T\_restart) / (us\%m\_to\_L\_restart*us\%s\_to\_T)}
\DoxyCodeLine{4871       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; cs\%ubt\_IC(i,j) = vel\_rescale * cs\%ubt\_IC(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4872       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; cs\%vbt\_IC(i,j) = vel\_rescale * cs\%vbt\_IC(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4873 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{4874 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4875 \textcolor{comment}{!   Calculate other constants which are used for btstep.}}
\DoxyCodeLine{4876 }
\DoxyCodeLine{4877   \textcolor{keywordflow}{if} (.not.cs\%nonlin\_stress) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4878     mean\_sl = g\%Z\_ref}
\DoxyCodeLine{4879     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{4880       \textcolor{keywordflow}{if} (g\%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4881         cs\%IDatu(i,j) = g\%mask2dCu(i,j) * 2.0 / ((g\%bathyT(i+1,j) + g\%bathyT(i,j)) + 2.0*mean\_sl)}
\DoxyCodeLine{4882       \textcolor{keywordflow}{else} \textcolor{comment}{! Both neighboring H points are masked out so IDatu(I,j) is meaningless}}
\DoxyCodeLine{4883         cs\%IDatu(i,j) = 0.}
\DoxyCodeLine{4884 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{4885 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4886     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4887       \textcolor{keywordflow}{if} (g\%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4888         cs\%IDatv(i,j) = g\%mask2dCv(i,j) * 2.0 / ((g\%bathyT(i,j+1) + g\%bathyT(i,j)) + 2.0*mean\_sl)}
\DoxyCodeLine{4889       \textcolor{keywordflow}{else} \textcolor{comment}{! Both neighboring H points are masked out so IDatv(i,J) is meaningless}}
\DoxyCodeLine{4890         cs\%IDatv(i,j) = 0.}
\DoxyCodeLine{4891 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{4892 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4893 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4894 }
\DoxyCodeLine{4895   \textcolor{keyword}{call }find\_face\_areas(datu, datv, g, gv, us, cs, ms, halo=1)}
\DoxyCodeLine{4896   \textcolor{keywordflow}{if} ((cs\%bound\_BT\_corr) .and. .not.(use\_bt\_cont\_type .and. cs\%BT\_cont\_bounds)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4897     \textcolor{comment}{! This is not used in most test cases.  Were it ever to become more widely used, consider}}
\DoxyCodeLine{4898     \textcolor{comment}{! replacing maxvel with min(G\%dxT(i,j),G\%dyT(i,j)) * (CS\%maxCFL\_BT\_cont*Idt) .}}
\DoxyCodeLine{4899     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4900       cs\%eta\_cor\_bound(i,j) = g\%IareaT(i,j) * 0.1 * cs\%maxvel * \&}
\DoxyCodeLine{4901          ((datu(i-\/1,j) + datu(i,j)) + (datv(i,j) + datv(i,j-\/1)))}
\DoxyCodeLine{4902 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4903 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4904 }
\DoxyCodeLine{4905   \textcolor{keywordflow}{if} (cs\%gradual\_BT\_ICs) \&}
\DoxyCodeLine{4906     \textcolor{keyword}{call }create\_group\_pass(pass\_bt\_hbt\_btav, cs\%ubt\_IC, cs\%vbt\_IC, g\%Domain)}
\DoxyCodeLine{4907   \textcolor{keyword}{call }create\_group\_pass(pass\_bt\_hbt\_btav, cs\%ubtav, cs\%vbtav, g\%Domain)}
\DoxyCodeLine{4908   \textcolor{keyword}{call }do\_group\_pass(pass\_bt\_hbt\_btav, g\%Domain)}
\DoxyCodeLine{4909 }
\DoxyCodeLine{4910 \textcolor{comment}{!  id\_clock\_pass = cpu\_clock\_id('(Ocean BT halo updates)', grain=CLOCK\_ROUTINE)}}
\DoxyCodeLine{4911   id\_clock\_calc\_pre  = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT pre-\/calcs only)'}, grain=clock\_routine)}
\DoxyCodeLine{4912   id\_clock\_pass\_pre = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT pre-\/step halo updates)'}, grain=clock\_routine)}
\DoxyCodeLine{4913   id\_clock\_calc = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT stepping calcs only)'}, grain=clock\_routine)}
\DoxyCodeLine{4914   id\_clock\_pass\_step = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT stepping halo updates)'}, grain=clock\_routine)}
\DoxyCodeLine{4915   id\_clock\_calc\_post = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT post-\/calcs only)'}, grain=clock\_routine)}
\DoxyCodeLine{4916   id\_clock\_pass\_post = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT post-\/step halo updates)'}, grain=clock\_routine)}
\DoxyCodeLine{4917   \textcolor{keywordflow}{if} (dtbt\_input <= 0.0) \&}
\DoxyCodeLine{4918     id\_clock\_sync = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean BT global synch)'}, grain=clock\_routine)}
\DoxyCodeLine{4919 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_ac7100cec548b4bf6d69d4a52e074a04f}\label{namespacemom__barotropic_ac7100cec548b4bf6d69d4a52e074a04f}} 
\index{mom\_barotropic@{mom\_barotropic}!bt\_cont\_to\_face\_areas@{bt\_cont\_to\_face\_areas}}
\index{bt\_cont\_to\_face\_areas@{bt\_cont\_to\_face\_areas}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{bt\_cont\_to\_face\_areas()}{bt\_cont\_to\_face\_areas()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::bt\+\_\+cont\+\_\+to\+\_\+face\+\_\+areas (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__variables_1_1bt__cont__type}{bt\+\_\+cont\+\_\+type}}), intent(inout)}]{B\+T\+\_\+cont,  }\item[{real, dimension(ms\%isdw-\/1\+:ms\%iedw,ms\%jsdw\+:ms\%jedw), intent(out)}]{Datu,  }\item[{real, dimension(ms\%isdw\+:ms\%iedw,ms\%jsdw-\/1\+:ms\%jedw), intent(out)}]{Datv,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}), intent(in)}]{MS,  }\item[{integer, intent(in), optional}]{halo,  }\item[{logical, intent(in), optional}]{maximize }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine uses the B\+T\+CL types to find typical or maximum face areas, which can then be used for finding wave speeds, etc. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+cont} & The B\+T\+\_\+cont\+\_\+type input to the barotropic solver. \\
\hline
\mbox{\texttt{ in}}  & {\em ms} & A type that describes the memory sizes of the argument arrays. \\
\hline
\mbox{\texttt{ out}}  & {\em datu} & The effective zonal face area \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em datv} & The effective meridional face area \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & The extra halo size to use here. \\
\hline
\mbox{\texttt{ in}}  & {\em maximize} & If present and true, find the maximum face area for any velocity. \\
\hline
\end{DoxyParams}


Definition at line 3996 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3997   \textcolor{keywordtype}{type}(BT\_cont\_type),     \textcolor{keywordtype}{intent(inout)} :: BT\_cont\textcolor{comment}{    !< The BT\_cont\_type input to the}}
\DoxyCodeLine{3998 \textcolor{comment}{                                                      !! barotropic solver.}}
\DoxyCodeLine{3999   \textcolor{keywordtype}{type}(memory\_size\_type), \textcolor{keywordtype}{intent(in)}    :: MS\textcolor{comment}{         !< A type that describes the memory}}
\DoxyCodeLine{4000 \textcolor{comment}{                                                      !! sizes of the argument arrays.}}
\DoxyCodeLine{4001 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(MS\%isdw-\/1:MS\%iedw,MS\%jsdw:MS\%jedw)}, \&}
\DoxyCodeLine{4002                           \textcolor{keywordtype}{intent(out)}   :: Datu\textcolor{comment}{       !< The effective zonal face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{4003 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(MS\%isdw:MS\%iedw,MS\%jsdw-\/1:MS\%jedw)}, \&}
\DoxyCodeLine{4004                           \textcolor{keywordtype}{intent(out)}   :: Datv\textcolor{comment}{       !< The effective meridional face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{4005   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{4006   \textcolor{keywordtype}{type}(unit\_scale\_type),  \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{4007   \textcolor{keywordtype}{integer},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{       !< The extra halo size to use here.}}
\DoxyCodeLine{4008   \textcolor{keywordtype}{logical},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: maximize\textcolor{comment}{   !< If present and true, find the}}
\DoxyCodeLine{4009 \textcolor{comment}{                                                      !! maximum face area for any velocity.}}
\DoxyCodeLine{4010 }
\DoxyCodeLine{4011   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{4012   \textcolor{keywordtype}{logical} :: find\_max}
\DoxyCodeLine{4013   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, hs}
\DoxyCodeLine{4014   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{4015   hs = 1 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) hs = max(halo,0)}
\DoxyCodeLine{4016   find\_max = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(maximize)) find\_max = maximize}
\DoxyCodeLine{4017 }
\DoxyCodeLine{4018   \textcolor{keywordflow}{if} (find\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4019     \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/1-\/hs,ie+hs}
\DoxyCodeLine{4020       datu(i,j) = max(bt\_cont\%FA\_u\_EE(i,j), bt\_cont\%FA\_u\_E0(i,j), \&}
\DoxyCodeLine{4021                       bt\_cont\%FA\_u\_W0(i,j), bt\_cont\%FA\_u\_WW(i,j))}
\DoxyCodeLine{4022 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4023     \textcolor{keywordflow}{do} j=js-\/1-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{4024       datv(i,j) = max(bt\_cont\%FA\_v\_NN(i,j), bt\_cont\%FA\_v\_N0(i,j), \&}
\DoxyCodeLine{4025                       bt\_cont\%FA\_v\_S0(i,j), bt\_cont\%FA\_v\_SS(i,j))}
\DoxyCodeLine{4026 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4027   \textcolor{keywordflow}{else}}
\DoxyCodeLine{4028     \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/1-\/hs,ie+hs}
\DoxyCodeLine{4029       datu(i,j) = 0.5 * (bt\_cont\%FA\_u\_E0(i,j) + bt\_cont\%FA\_u\_W0(i,j))}
\DoxyCodeLine{4030 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4031     \textcolor{keywordflow}{do} j=js-\/1-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{4032       datv(i,j) = 0.5 * (bt\_cont\%FA\_v\_N0(i,j) + bt\_cont\%FA\_v\_S0(i,j))}
\DoxyCodeLine{4033 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4034 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4035 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a856387dc8ee2b7b50ea2bd9fca16db78}\label{namespacemom__barotropic_a856387dc8ee2b7b50ea2bd9fca16db78}} 
\index{mom\_barotropic@{mom\_barotropic}!bt\_mass\_source@{bt\_mass\_source}}
\index{bt\_mass\_source@{bt\_mass\_source}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{bt\_mass\_source()}{bt\_mass\_source()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::bt\+\_\+mass\+\_\+source (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{eta,  }\item[{logical, intent(in)}]{set\+\_\+cor,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



bt\+\_\+mass\+\_\+source determines the appropriately limited mass source for the barotropic solver, along with a corrective fictitious mass source that will drive the barotropic estimate of the free surface height toward the baroclinic estimate. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & The free surface height that is to be corrected \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em set\+\_\+cor} & A flag to indicate whether to set the corrective fluxes (and update the slowly varying part of eta\+\_\+cor) (.true.) or whether to incrementally update the corrective fluxes. \\
\hline
 & {\em cs} & The control structure returned by a previous call to barotropic\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 4146 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4147   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{        !< The ocean's grid structure.}}
\DoxyCodeLine{4148   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{       !< The ocean's vertical grid structure.}}
\DoxyCodeLine{4149 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{  !< Layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4150 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},   \textcolor{keywordtype}{intent(in)} :: eta\textcolor{comment}{      !< The free surface height that is to be}}
\DoxyCodeLine{4151 \textcolor{comment}{                                                             !! corrected [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4152   \textcolor{keywordtype}{logical},                            \textcolor{keywordtype}{intent(in)} :: set\_cor\textcolor{comment}{  !< A flag to indicate whether to set the corrective}}
\DoxyCodeLine{4153 \textcolor{comment}{                                                             !! fluxes (and update the slowly varying part of eta\_cor)}}
\DoxyCodeLine{4154 \textcolor{comment}{                                                             !! (.true.) or whether to incrementally update the}}
\DoxyCodeLine{4155 \textcolor{comment}{                                                             !! corrective fluxes.}}
\DoxyCodeLine{4156   \textcolor{keywordtype}{type}(barotropic\_CS),                \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{       !< The control structure returned by a previous call}}
\DoxyCodeLine{4157 \textcolor{comment}{                                                             !! to barotropic\_init.}}
\DoxyCodeLine{4158 }
\DoxyCodeLine{4159   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{4160 \textcolor{keywordtype}{  real} :: h\_tot(SZI\_(G))      \textcolor{comment}{! The sum of the layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4161 \textcolor{keywordtype}{  real} :: eta\_h(SZI\_(G))      \textcolor{comment}{! The free surface height determined from}}
\DoxyCodeLine{4162                               \textcolor{comment}{! the sum of the layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4163 \textcolor{keywordtype}{  real} :: d\_eta               \textcolor{comment}{! The difference between estimates of the total}}
\DoxyCodeLine{4164                               \textcolor{comment}{! thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4165   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz, i, j, k}
\DoxyCodeLine{4166 }
\DoxyCodeLine{4167   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}bt\_mass\_source: "{}}// \&}
\DoxyCodeLine{4168         \textcolor{stringliteral}{"{}Module MOM\_barotropic must be initialized before it is used."{}})}
\DoxyCodeLine{4169   \textcolor{keywordflow}{if} (.not.cs\%split) \textcolor{keywordflow}{return}}
\DoxyCodeLine{4170 }
\DoxyCodeLine{4171   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{4172 }
\DoxyCodeLine{4173   \textcolor{comment}{!\$OMP parallel do default(shared) private(eta\_h,h\_tot,d\_eta)}}
\DoxyCodeLine{4174   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{4175     \textcolor{keywordflow}{do} i=is,ie ; h\_tot(i) = h(i,j,1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4176     \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4177       \textcolor{keywordflow}{do} i=is,ie ; eta\_h(i) = h(i,j,1) -\/ g\%bathyT(i,j)*gv\%Z\_to\_H ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4178     \textcolor{keywordflow}{else}}
\DoxyCodeLine{4179       \textcolor{keywordflow}{do} i=is,ie ; eta\_h(i) = h(i,j,1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4180 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{4181     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4182       eta\_h(i) = eta\_h(i) + h(i,j,k)}
\DoxyCodeLine{4183       h\_tot(i) = h\_tot(i) + h(i,j,k)}
\DoxyCodeLine{4184 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4185 }
\DoxyCodeLine{4186     \textcolor{keywordflow}{if} (set\_cor) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4187       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4188         d\_eta = eta\_h(i) -\/ eta(i,j)}
\DoxyCodeLine{4189         cs\%eta\_cor(i,j) = d\_eta}
\DoxyCodeLine{4190 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{4191     \textcolor{keywordflow}{else}}
\DoxyCodeLine{4192       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{4193         d\_eta = eta\_h(i) -\/ eta(i,j)}
\DoxyCodeLine{4194         cs\%eta\_cor(i,j) = cs\%eta\_cor(i,j) + d\_eta}
\DoxyCodeLine{4195 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{4196 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{4197 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{4198 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_aa60ee766449413de40cdbc19964a6556}\label{namespacemom__barotropic_aa60ee766449413de40cdbc19964a6556}} 
\index{mom\_barotropic@{mom\_barotropic}!btcalc@{btcalc}}
\index{btcalc@{btcalc}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{btcalc()}{btcalc()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::btcalc (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{h\+\_\+u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{h\+\_\+v,  }\item[{logical, intent(in), optional}]{may\+\_\+use\+\_\+default,  }\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), optional, pointer}]{O\+BC }\end{DoxyParamCaption})}



btcalc calculates the barotropic velocities from the full velocity and thickness fields, determines the fraction of the total water column in each layer at velocity points, and determines a corrective fictitious mass source that will drive the barotropic estimate of the free surface height toward the baroclinic estimate. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
 & {\em cs} & The control structure returned by a previous call to barotropic\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+u} & The specified thicknesses at u-\/points \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+v} & The specified thicknesses at v-\/points \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em may\+\_\+use\+\_\+default} & An optional logical argument to indicate that the default velocity point thicknesses may be used for this particular calculation, even though the setting of CShvel\+\_\+scheme would usually require that h\+\_\+u and h\+\_\+v be passed in. \\
\hline
 & {\em obc} & Open boundary control structure. \\
\hline
\end{DoxyParams}


Definition at line 3183 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3184   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{3185   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure.}}
\DoxyCodeLine{3186 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{3187                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3188   \textcolor{keywordtype}{type}(barotropic\_CS),     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< The control structure returned by a previous}}
\DoxyCodeLine{3189 \textcolor{comment}{                                                 !! call to barotropic\_init.}}
\DoxyCodeLine{3190 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{3191                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_u\textcolor{comment}{  !< The specified thicknesses at u-\/points [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3192 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{3193                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_v\textcolor{comment}{  !< The specified thicknesses at v-\/points [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3194   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: may\_use\_default\textcolor{comment}{ !< An optional logical argument}}
\DoxyCodeLine{3195 \textcolor{comment}{                                                 !! to indicate that the default velocity point}}
\DoxyCodeLine{3196 \textcolor{comment}{                                                 !! thicknesses may be used for this particular}}
\DoxyCodeLine{3197 \textcolor{comment}{                                                 !! calculation, even though the setting of}}
\DoxyCodeLine{3198 \textcolor{comment}{                                                 !! CS\%hvel\_scheme would usually require that h\_u}}
\DoxyCodeLine{3199 \textcolor{comment}{                                                 !! and h\_v be passed in.}}
\DoxyCodeLine{3200   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundary control structure.}}
\DoxyCodeLine{3201 }
\DoxyCodeLine{3202   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3203 \textcolor{keywordtype}{  real} :: hatutot(SZIB\_(G))    \textcolor{comment}{! The sum of the layer thicknesses interpolated to u points [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3204 \textcolor{keywordtype}{  real} :: hatvtot(SZI\_(G))     \textcolor{comment}{! The sum of the layer thicknesses interpolated to v points [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3205 \textcolor{keywordtype}{  real} :: Ihatutot(SZIB\_(G))   \textcolor{comment}{! Ihatutot is the inverse of hatutot [H-\/1 \string~> m-\/1 or m2 kg-\/1].}}
\DoxyCodeLine{3206 \textcolor{keywordtype}{  real} :: Ihatvtot(SZI\_(G))    \textcolor{comment}{! Ihatvtot is the inverse of hatvtot [H-\/1 \string~> m-\/1 or m2 kg-\/1].}}
\DoxyCodeLine{3207 \textcolor{keywordtype}{  real} :: h\_arith              \textcolor{comment}{! The arithmetic mean thickness [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3208 \textcolor{keywordtype}{  real} :: h\_harm               \textcolor{comment}{! The harmonic mean thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3209 \textcolor{keywordtype}{  real} :: h\_neglect            \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{3210                                \textcolor{comment}{! in roundoff and can be neglected [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3211 \textcolor{keywordtype}{  real} :: wt\_arith             \textcolor{comment}{! The nondimensional weight for the arithmetic mean thickness.}}
\DoxyCodeLine{3212                                \textcolor{comment}{! The harmonic mean uses a weight of (1 -\/ wt\_arith).}}
\DoxyCodeLine{3213 \textcolor{keywordtype}{  real} :: Rh                   \textcolor{comment}{! A ratio of summed thicknesses, nondim.}}
\DoxyCodeLine{3214 \textcolor{keywordtype}{  real} :: e\_u(SZIB\_(G),SZK\_(G)+1) \textcolor{comment}{!   The interface heights at u-\/velocity and}}
\DoxyCodeLine{3215 \textcolor{keywordtype}{  real} :: e\_v(SZI\_(G),SZK\_(G)+1)  \textcolor{comment}{! v-\/velocity points [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3216 \textcolor{keywordtype}{  real} :: D\_shallow\_u(SZI\_(G)) \textcolor{comment}{! The shallower of the adjacent depths [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3217 \textcolor{keywordtype}{  real} :: D\_shallow\_v(SZIB\_(G))\textcolor{comment}{! The shallower of the adjacent depths [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3218 \textcolor{keywordtype}{  real} :: htot                 \textcolor{comment}{! The sum of the layer thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{3219 \textcolor{keywordtype}{  real} :: Ihtot                \textcolor{comment}{! The inverse of htot [H-\/1 \string~> m-\/1 or m2 kg-\/1].}}
\DoxyCodeLine{3220 }
\DoxyCodeLine{3221   \textcolor{keywordtype}{logical} :: use\_default, test\_dflt, apply\_OBCs}
\DoxyCodeLine{3222   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, i, j, k}
\DoxyCodeLine{3223   \textcolor{keywordtype}{integer} :: iss, ies, n}
\DoxyCodeLine{3224 }
\DoxyCodeLine{3225 \textcolor{comment}{!    This section interpolates thicknesses onto u \& v grid points with the}}
\DoxyCodeLine{3226 \textcolor{comment}{! second order accurate estimate h = 2*(h+ * h-\/)/(h+ + h-\/).}}
\DoxyCodeLine{3227   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{3228       \textcolor{stringliteral}{"{}btcalc: Module MOM\_barotropic must be initialized before it is used."{}})}
\DoxyCodeLine{3229   \textcolor{keywordflow}{if} (.not.cs\%split) \textcolor{keywordflow}{return}}
\DoxyCodeLine{3230 }
\DoxyCodeLine{3231   use\_default = .false.}
\DoxyCodeLine{3232   test\_dflt = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(may\_use\_default)) test\_dflt = may\_use\_default}
\DoxyCodeLine{3233 }
\DoxyCodeLine{3234   \textcolor{keywordflow}{if} (test\_dflt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3235     \textcolor{keywordflow}{if} (.not.((\textcolor{keyword}{present}(h\_u) .and. \textcolor{keyword}{present}(h\_v)) .or. \&}
\DoxyCodeLine{3236               (cs\%hvel\_scheme == harmonic) .or. (cs\%hvel\_scheme == hybrid) .or.\&}
\DoxyCodeLine{3237               (cs\%hvel\_scheme == arithmetic))) use\_default = .true.}
\DoxyCodeLine{3238   \textcolor{keywordflow}{else}}
\DoxyCodeLine{3239     \textcolor{keywordflow}{if} (.not.((\textcolor{keyword}{present}(h\_u) .and. \textcolor{keyword}{present}(h\_v)) .or. \&}
\DoxyCodeLine{3240               (cs\%hvel\_scheme == harmonic) .or. (cs\%hvel\_scheme == hybrid) .or.\&}
\DoxyCodeLine{3241               (cs\%hvel\_scheme == arithmetic))) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{3242         \textcolor{stringliteral}{"{}btcalc: Inconsistent settings of optional arguments and hvel\_scheme."{}})}
\DoxyCodeLine{3243 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3244 }
\DoxyCodeLine{3245   apply\_obcs = .false.}
\DoxyCodeLine{3246   \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{3247     \textcolor{comment}{! Some open boundary condition points might be in this processor's symmetric}}
\DoxyCodeLine{3248     \textcolor{comment}{! computational domain.}}
\DoxyCodeLine{3249     apply\_obcs = (obc\%number\_of\_segments > 0)}
\DoxyCodeLine{3250 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3251 }
\DoxyCodeLine{3252   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{3253   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{3254   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{3255 }
\DoxyCodeLine{3256   \textcolor{comment}{!   This estimates the fractional thickness of each layer at the velocity}}
\DoxyCodeLine{3257   \textcolor{comment}{! points, using a harmonic mean estimate.}}
\DoxyCodeLine{3258 \textcolor{comment}{!\$OMP parallel do default(none) shared(is,ie,js,je,nz,h\_u,CS,h\_neglect,h,use\_default,G,GV) \&}}
\DoxyCodeLine{3259 \textcolor{comment}{!\$OMP                          private(hatutot,Ihatutot,e\_u,D\_shallow\_u,h\_arith,h\_harm,wt\_arith)}}
\DoxyCodeLine{3260 }
\DoxyCodeLine{3261   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{3262     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_u)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3263       \textcolor{keywordflow}{do} i=is-\/1,ie ; hatutot(i) = h\_u(i,j,1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3264       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3265         hatutot(i) = hatutot(i) + h\_u(i,j,k)}
\DoxyCodeLine{3266 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3267       \textcolor{keywordflow}{do} i=is-\/1,ie ; ihatutot(i) = g\%mask2dCu(i,j) / (hatutot(i) + h\_neglect) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3268       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3269         cs\%frhatu(i,j,k) = h\_u(i,j,k) * ihatutot(i)}
\DoxyCodeLine{3270 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3271     \textcolor{keywordflow}{else}}
\DoxyCodeLine{3272       \textcolor{keywordflow}{if} (cs\%hvel\_scheme == arithmetic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3273         \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3274           cs\%frhatu(i,j,1) = 0.5 * (h(i+1,j,1) + h(i,j,1))}
\DoxyCodeLine{3275           hatutot(i) = cs\%frhatu(i,j,1)}
\DoxyCodeLine{3276 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3277         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3278           cs\%frhatu(i,j,k) = 0.5 * (h(i+1,j,k) + h(i,j,k))}
\DoxyCodeLine{3279           hatutot(i) = hatutot(i) + cs\%frhatu(i,j,k)}
\DoxyCodeLine{3280 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3281       \textcolor{keywordflow}{elseif} (cs\%hvel\_scheme == hybrid .or. use\_default) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3282         \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3283           e\_u(i,nz+1) = -\/0.5 * gv\%Z\_to\_H * (g\%bathyT(i+1,j) + g\%bathyT(i,j))}
\DoxyCodeLine{3284           d\_shallow\_u(i) = -\/gv\%Z\_to\_H * min(g\%bathyT(i+1,j), g\%bathyT(i,j))}
\DoxyCodeLine{3285           hatutot(i) = 0.0}
\DoxyCodeLine{3286 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3287         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3288           e\_u(i,k) = e\_u(i,k+1) + 0.5 * (h(i+1,j,k) + h(i,j,k))}
\DoxyCodeLine{3289           h\_arith = 0.5 * (h(i+1,j,k) + h(i,j,k))}
\DoxyCodeLine{3290           \textcolor{keywordflow}{if} (e\_u(i,k+1) >= d\_shallow\_u(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3291             cs\%frhatu(i,j,k) = h\_arith}
\DoxyCodeLine{3292           \textcolor{keywordflow}{else}}
\DoxyCodeLine{3293             h\_harm = (h(i+1,j,k) * h(i,j,k)) / (h\_arith + h\_neglect)}
\DoxyCodeLine{3294             \textcolor{keywordflow}{if} (e\_u(i,k) <= d\_shallow\_u(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3295               cs\%frhatu(i,j,k) = h\_harm}
\DoxyCodeLine{3296             \textcolor{keywordflow}{else}}
\DoxyCodeLine{3297               wt\_arith = (e\_u(i,k) -\/ d\_shallow\_u(i)) / (h\_arith + h\_neglect)}
\DoxyCodeLine{3298               cs\%frhatu(i,j,k) = wt\_arith*h\_arith + (1.0-\/wt\_arith)*h\_harm}
\DoxyCodeLine{3299 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{3300 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3301           hatutot(i) = hatutot(i) + cs\%frhatu(i,j,k)}
\DoxyCodeLine{3302 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3303       \textcolor{keywordflow}{elseif} (cs\%hvel\_scheme == harmonic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3304         \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3305           cs\%frhatu(i,j,1) = 2.0*(h(i+1,j,1) * h(i,j,1)) / \&}
\DoxyCodeLine{3306                              ((h(i+1,j,1) + h(i,j,1)) + h\_neglect)}
\DoxyCodeLine{3307           hatutot(i) = cs\%frhatu(i,j,1)}
\DoxyCodeLine{3308 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3309         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3310           cs\%frhatu(i,j,k) = 2.0*(h(i+1,j,k) * h(i,j,k)) / \&}
\DoxyCodeLine{3311                              ((h(i+1,j,k) + h(i,j,k)) + h\_neglect)}
\DoxyCodeLine{3312           hatutot(i) = hatutot(i) + cs\%frhatu(i,j,k)}
\DoxyCodeLine{3313 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3314 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3315       \textcolor{keywordflow}{do} i=is-\/1,ie ; ihatutot(i) = g\%mask2dCu(i,j) / (hatutot(i) + h\_neglect) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3316       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3317         cs\%frhatu(i,j,k) = cs\%frhatu(i,j,k) * ihatutot(i)}
\DoxyCodeLine{3318 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3319 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3320 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{3321 }
\DoxyCodeLine{3322 \textcolor{comment}{!\$OMP parallel do default(none) shared(is,ie,js,je,nz,CS,G,GV,h\_v,h\_neglect,h,use\_default) \&}}
\DoxyCodeLine{3323 \textcolor{comment}{!\$OMP                          private(hatvtot,Ihatvtot,e\_v,D\_shallow\_v,h\_arith,h\_harm,wt\_arith)}}
\DoxyCodeLine{3324   \textcolor{keywordflow}{do} j=js-\/1,je}
\DoxyCodeLine{3325     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_v)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3326       \textcolor{keywordflow}{do} i=is,ie ; hatvtot(i) = h\_v(i,j,1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3327       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3328         hatvtot(i) = hatvtot(i) + h\_v(i,j,k)}
\DoxyCodeLine{3329 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3330       \textcolor{keywordflow}{do} i=is,ie ; ihatvtot(i) = g\%mask2dCv(i,j) / (hatvtot(i) + h\_neglect) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3331       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3332         cs\%frhatv(i,j,k) = h\_v(i,j,k) * ihatvtot(i)}
\DoxyCodeLine{3333 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3334     \textcolor{keywordflow}{else}}
\DoxyCodeLine{3335       \textcolor{keywordflow}{if} (cs\%hvel\_scheme == arithmetic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3336         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3337           cs\%frhatv(i,j,1) = 0.5 * (h(i,j+1,1) + h(i,j,1))}
\DoxyCodeLine{3338           hatvtot(i) = cs\%frhatv(i,j,1)}
\DoxyCodeLine{3339 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3340         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3341           cs\%frhatv(i,j,k) = 0.5 * (h(i,j+1,k) + h(i,j,k))}
\DoxyCodeLine{3342           hatvtot(i) = hatvtot(i) + cs\%frhatv(i,j,k)}
\DoxyCodeLine{3343 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3344       \textcolor{keywordflow}{elseif} (cs\%hvel\_scheme == hybrid .or. use\_default) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3345         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3346           e\_v(i,nz+1) = -\/0.5 * gv\%Z\_to\_H * (g\%bathyT(i,j+1) + g\%bathyT(i,j))}
\DoxyCodeLine{3347           d\_shallow\_v(i) = -\/gv\%Z\_to\_H * min(g\%bathyT(i,j+1), g\%bathyT(i,j))}
\DoxyCodeLine{3348           hatvtot(i) = 0.0}
\DoxyCodeLine{3349 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3350         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3351           e\_v(i,k) = e\_v(i,k+1) + 0.5 * (h(i,j+1,k) + h(i,j,k))}
\DoxyCodeLine{3352           h\_arith = 0.5 * (h(i,j+1,k) + h(i,j,k))}
\DoxyCodeLine{3353           \textcolor{keywordflow}{if} (e\_v(i,k+1) >= d\_shallow\_v(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3354             cs\%frhatv(i,j,k) = h\_arith}
\DoxyCodeLine{3355           \textcolor{keywordflow}{else}}
\DoxyCodeLine{3356             h\_harm = (h(i,j+1,k) * h(i,j,k)) / (h\_arith + h\_neglect)}
\DoxyCodeLine{3357             \textcolor{keywordflow}{if} (e\_v(i,k) <= d\_shallow\_v(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3358               cs\%frhatv(i,j,k) = h\_harm}
\DoxyCodeLine{3359             \textcolor{keywordflow}{else}}
\DoxyCodeLine{3360               wt\_arith = (e\_v(i,k) -\/ d\_shallow\_v(i)) / (h\_arith + h\_neglect)}
\DoxyCodeLine{3361               cs\%frhatv(i,j,k) = wt\_arith*h\_arith + (1.0-\/wt\_arith)*h\_harm}
\DoxyCodeLine{3362 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{3363 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3364           hatvtot(i) = hatvtot(i) + cs\%frhatv(i,j,k)}
\DoxyCodeLine{3365 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3366       \textcolor{keywordflow}{elseif} (cs\%hvel\_scheme == harmonic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3367         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3368           cs\%frhatv(i,j,1) = 2.0*(h(i,j+1,1) * h(i,j,1)) / \&}
\DoxyCodeLine{3369                              ((h(i,j+1,1) + h(i,j,1)) + h\_neglect)}
\DoxyCodeLine{3370           hatvtot(i) = cs\%frhatv(i,j,1)}
\DoxyCodeLine{3371 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3372         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3373           cs\%frhatv(i,j,k) = 2.0*(h(i,j+1,k) * h(i,j,k)) / \&}
\DoxyCodeLine{3374                              ((h(i,j+1,k) + h(i,j,k)) + h\_neglect)}
\DoxyCodeLine{3375           hatvtot(i) = hatvtot(i) + cs\%frhatv(i,j,k)}
\DoxyCodeLine{3376 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3377 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3378       \textcolor{keywordflow}{do} i=is,ie ; ihatvtot(i) = g\%mask2dCv(i,j) / (hatvtot(i) + h\_neglect) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3379       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3380         cs\%frhatv(i,j,k) = cs\%frhatv(i,j,k) * ihatvtot(i)}
\DoxyCodeLine{3381 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3382 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3383 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{3384 }
\DoxyCodeLine{3385   \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments \textcolor{comment}{! Test for segment type?}}
\DoxyCodeLine{3386     \textcolor{keywordflow}{if} (.not. obc\%segment(n)\%on\_pe) cycle}
\DoxyCodeLine{3387     \textcolor{keywordflow}{if} (obc\%segment(n)\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3388       j = obc\%segment(n)\%HI\%JsdB}
\DoxyCodeLine{3389       \textcolor{keywordflow}{if} ((j >= js-\/1) .and. (j <= je)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3390         iss = max(is,obc\%segment(n)\%HI\%isd) ; ies = min(ie,obc\%segment(n)\%HI\%ied)}
\DoxyCodeLine{3391         \textcolor{keywordflow}{do} i=iss,ies ; hatvtot(i) = h(i,j,1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3392         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=iss,ies}
\DoxyCodeLine{3393           hatvtot(i) = hatvtot(i) + h(i,j,k)}
\DoxyCodeLine{3394 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3395         \textcolor{keywordflow}{do} i=iss,ies}
\DoxyCodeLine{3396           ihatvtot(i) = g\%mask2dCv(i,j) / (hatvtot(i) + h\_neglect)}
\DoxyCodeLine{3397 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3398         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=iss,ies}
\DoxyCodeLine{3399           cs\%frhatv(i,j,k) = h(i,j,k) * ihatvtot(i)}
\DoxyCodeLine{3400 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3401 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3402     \textcolor{keywordflow}{elseif} (obc\%segment(n)\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3403       j = obc\%segment(n)\%HI\%JsdB}
\DoxyCodeLine{3404       \textcolor{keywordflow}{if} ((j >= js-\/1) .and. (j <= je)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3405         iss = max(is,obc\%segment(n)\%HI\%isd) ; ies = min(ie,obc\%segment(n)\%HI\%ied)}
\DoxyCodeLine{3406         \textcolor{keywordflow}{do} i=iss,ies ; hatvtot(i) = h(i,j+1,1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3407         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=iss,ies}
\DoxyCodeLine{3408           hatvtot(i) = hatvtot(i) + h(i,j+1,k)}
\DoxyCodeLine{3409 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3410         \textcolor{keywordflow}{do} i=iss,ies}
\DoxyCodeLine{3411           ihatvtot(i) = g\%mask2dCv(i,j) / (hatvtot(i) + h\_neglect)}
\DoxyCodeLine{3412 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3413         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=iss,ies}
\DoxyCodeLine{3414           cs\%frhatv(i,j,k) = h(i,j+1,k) * ihatvtot(i)}
\DoxyCodeLine{3415 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3416 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3417     \textcolor{keywordflow}{elseif} (obc\%segment(n)\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3418       i = obc\%segment(n)\%HI\%IsdB}
\DoxyCodeLine{3419       \textcolor{keywordflow}{if} ((i >= is-\/1) .and. (i <= ie)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3420         \textcolor{keywordflow}{do} j = max(js,obc\%segment(n)\%HI\%jsd), min(je,obc\%segment(n)\%HI\%jed)}
\DoxyCodeLine{3421           htot = h(i,j,1)}
\DoxyCodeLine{3422           \textcolor{keywordflow}{do} k=2,nz ; htot = htot + h(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3423           ihtot = g\%mask2dCu(i,j) / (htot + h\_neglect)}
\DoxyCodeLine{3424           \textcolor{keywordflow}{do} k=1,nz ; cs\%frhatu(i,j,k) = h(i,j,k) * ihtot ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3425 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3426 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3427     \textcolor{keywordflow}{elseif} (obc\%segment(n)\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3428       i = obc\%segment(n)\%HI\%IsdB}
\DoxyCodeLine{3429       \textcolor{keywordflow}{if} ((i >= is-\/1) .and. (i <= ie)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3430         \textcolor{keywordflow}{do} j = max(js,obc\%segment(n)\%HI\%jsd), min(je,obc\%segment(n)\%HI\%jed)}
\DoxyCodeLine{3431           htot = h(i+1,j,1)}
\DoxyCodeLine{3432           \textcolor{keywordflow}{do} k=2,nz ; htot = htot + h(i+1,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3433           ihtot = g\%mask2dCu(i,j) / (htot + h\_neglect)}
\DoxyCodeLine{3434           \textcolor{keywordflow}{do} k=1,nz ; cs\%frhatu(i,j,k) = h(i+1,j,k) * ihtot ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3435 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3436 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3437     \textcolor{keywordflow}{else}}
\DoxyCodeLine{3438       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}btcalc encountered and OBC segment of indeterminate direction."{}})}
\DoxyCodeLine{3439 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3440 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3441 }
\DoxyCodeLine{3442   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3443     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}btcalc frhat[uv]"{}}, cs\%frhatu, cs\%frhatv, g\%HI, \&}
\DoxyCodeLine{3444                   haloshift=0, symmetric=.true., omit\_corners=.true., \&}
\DoxyCodeLine{3445                   scalar\_pair=.true.)}
\DoxyCodeLine{3446     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_u) .and. \textcolor{keyword}{present}(h\_v)) \&}
\DoxyCodeLine{3447       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}btcalc h\_[uv]"{}}, h\_u, h\_v, g\%HI, haloshift=0, \&}
\DoxyCodeLine{3448                     symmetric=.true., omit\_corners=.true., scale=gv\%H\_to\_m, \&}
\DoxyCodeLine{3449                     scalar\_pair=.true.)}
\DoxyCodeLine{3450     \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"{}btcalc h"{}},g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{3451 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3452 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_ac60353f002de5980317d117a3db1a075}\label{namespacemom__barotropic_ac60353f002de5980317d117a3db1a075}} 
\index{mom\_barotropic@{mom\_barotropic}!btstep@{btstep}}
\index{btstep@{btstep}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{btstep()}{btstep()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::btstep (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{U\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{V\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{eta\+\_\+in,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{bc\+\_\+accel\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{bc\+\_\+accel\+\_\+v,  }\item[{type(\mbox{\hyperlink{structmom__forcing__type_1_1mech__forcing}{mech\+\_\+forcing}}), intent(in)}]{forces,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{pbce,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{eta\+\_\+\+P\+F\+\_\+in,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{U\+\_\+\+Cor,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{V\+\_\+\+Cor,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{accel\+\_\+layer\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{accel\+\_\+layer\+\_\+v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{eta\+\_\+out,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(out)}]{uhbtav,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(out)}]{vhbtav,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{visc\+\_\+rem\+\_\+u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{visc\+\_\+rem\+\_\+v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out), optional}]{etaav,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1accel__diag__ptrs}{accel\+\_\+diag\+\_\+ptrs}}), optional, pointer}]{A\+Dp,  }\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), optional, pointer}]{O\+BC,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1bt__cont__type}{bt\+\_\+cont\+\_\+type}}), optional, pointer}]{B\+T\+\_\+cont,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{eta\+\_\+\+P\+F\+\_\+start,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{taux\+\_\+bot,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{tauy\+\_\+bot,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{uh0,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{vh0,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{u\+\_\+uh0,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{v\+\_\+vh0 }\end{DoxyParamCaption})}



This subroutine time steps the barotropic equations explicitly. For gravity waves, anything between a forwards-\/backwards scheme and a simulated backwards Euler scheme is used, with bebt between 0.\+0 and 1.\+0 determining the scheme. In practice, bebt must be of order 0.\+2 or greater. A forwards-\/backwards treatment of the Coriolis terms is always used. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em u\+\_\+in} & The initial (3-\/D) zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em v\+\_\+in} & The initial (3-\/D) meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eta\+\_\+in} & The initial barotropic free surface height anomaly or column mass anomaly \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & The time increment to integrate over \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em bc\+\_\+accel\+\_\+u} & The zonal baroclinic accelerations, \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em bc\+\_\+accel\+\_\+v} & The meridional baroclinic accelerations, \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em forces} & A structure with the driving mechanical forces \\
\hline
\mbox{\texttt{ in}}  & {\em pbce} & The baroclinic pressure anomaly in each layer due to free surface height anomalies \mbox{[}L2 H-\/1 T-\/2 $\sim$$>$ m s-\/2 or m4 kg-\/1 s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em eta\+\_\+pf\+\_\+in} & The 2-\/D eta field (either S\+SH anomaly or column mass anomaly) that was used to calculate the input pressure gradient accelerations (or its final value if eta\+\_\+\+P\+F\+\_\+start is provided \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. Note\+: eta\+\_\+in, pbce, and eta\+\_\+\+P\+F\+\_\+in must have up-\/to-\/date values in the first point of their halos. \\
\hline
\mbox{\texttt{ in}}  & {\em u\+\_\+cor} & The (3-\/D) zonal velocities used to calculate the Coriolis terms in bc\+\_\+accel\+\_\+u \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em v\+\_\+cor} & The (3-\/D) meridional velocities used to calculate the Coriolis terms in bc\+\_\+accel\+\_\+u \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em accel\+\_\+layer\+\_\+u} & The zonal acceleration of each layer due to the barotropic calculation \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em accel\+\_\+layer\+\_\+v} & The meridional acceleration of each layer due to the barotropic calculation \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em eta\+\_\+out} & The final barotropic free surface height anomaly or column mass anomaly \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em uhbtav} & the barotropic zonal volume or mass fluxes averaged through the barotropic steps \mbox{[}H L2 T-\/1 $\sim$$>$ m3 or kg s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em vhbtav} & the barotropic meridional volume or mass fluxes averaged through the barotropic steps \mbox{[}H L2 T-\/1 $\sim$$>$ m3 or kg s-\/1\mbox{]}. \\
\hline
 & {\em cs} & The control structure returned by a previous call to barotropic\+\_\+init. \\
\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, in the zonal direction. Nondimensional between 0 (at the bottom) and 1 (far above the bottom). \\
\hline
\mbox{\texttt{ in}}  & {\em visc\+\_\+rem\+\_\+v} & Ditto for meridional direction \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em etaav} & The free surface height or column mass averaged over the barotropic integration \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
 & {\em adp} & Acceleration diagnostic pointers \\
\hline
 & {\em obc} & The open boundary condition structure. \\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
 & {\em eta\+\_\+pf\+\_\+start} & The eta field consistent with the pressure gradient at the start of the barotropic stepping \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
 & {\em taux\+\_\+bot} & The zonal bottom frictional stress from ocean to the seafloor \mbox{[}R L Z T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
 & {\em tauy\+\_\+bot} & The meridional bottom frictional stress from ocean to the seafloor \mbox{[}R L Z T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
 & {\em uh0} & The zonal layer transports at reference velocities \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
 & {\em u\+\_\+uh0} & The velocities used to calculate uh0 \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
 & {\em vh0} & The zonal layer transports at reference velocities \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}. \\
\hline
 & {\em v\+\_\+vh0} & The velocities used to calculate vh0 \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 406 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{411   \textcolor{keywordtype}{type}(ocean\_grid\_type),                   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{       !< The ocean's grid structure.}}
\DoxyCodeLine{412   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{      !< The ocean's vertical grid structure.}}
\DoxyCodeLine{413   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{      !< A dimensional unit scaling type}}
\DoxyCodeLine{414 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: U\_in\textcolor{comment}{    !< The initial (3-\/D) zonal}}
\DoxyCodeLine{415 \textcolor{comment}{                                                                    !! velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{416 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: V\_in\textcolor{comment}{    !< The initial (3-\/D) meridional}}
\DoxyCodeLine{417 \textcolor{comment}{                                                                    !! velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{418 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          \textcolor{keywordtype}{intent(in)}  :: eta\_in\textcolor{comment}{  !< The initial barotropic free surface height}}
\DoxyCodeLine{419 \textcolor{comment}{                                                         !! anomaly or column mass anomaly [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{420 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}  :: dt\textcolor{comment}{      !< The time increment to integrate over [T \string~> s].}}
\DoxyCodeLine{421 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: bc\_accel\_u\textcolor{comment}{ !< The zonal baroclinic accelerations,}}
\DoxyCodeLine{422 \textcolor{comment}{                                                                       !! [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{423 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: bc\_accel\_v\textcolor{comment}{ !< The meridional baroclinic accelerations,}}
\DoxyCodeLine{424 \textcolor{comment}{                                                                       !! [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{425   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}  :: forces\textcolor{comment}{     !< A structure with the driving mechanical forces}}
\DoxyCodeLine{426 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}  :: pbce\textcolor{comment}{       !< The baroclinic pressure anomaly in each layer}}
\DoxyCodeLine{427 \textcolor{comment}{                                                         !! due to free surface height anomalies}}
\DoxyCodeLine{428 \textcolor{comment}{                                                         !! [L2 H-\/1 T-\/2 \string~> m s-\/2 or m4 kg-\/1 s-\/2].}}
\DoxyCodeLine{429 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          \textcolor{keywordtype}{intent(in)}  :: eta\_PF\_in\textcolor{comment}{  !< The 2-\/D eta field (either SSH anomaly or}}
\DoxyCodeLine{430 \textcolor{comment}{                                                         !! column mass anomaly) that was used to calculate the input}}
\DoxyCodeLine{431 \textcolor{comment}{                                                         !! pressure gradient accelerations (or its final value if}}
\DoxyCodeLine{432 \textcolor{comment}{                                                         !! eta\_PF\_start is provided [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{433 \textcolor{comment}{                                                         !! Note: eta\_in, pbce, and eta\_PF\_in must have up-\/to-\/date}}
\DoxyCodeLine{434 \textcolor{comment}{                                                         !! values in the first point of their halos.}}
\DoxyCodeLine{435 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: U\_Cor\textcolor{comment}{      !< The (3-\/D) zonal velocities used to}}
\DoxyCodeLine{436 \textcolor{comment}{                                                         !! calculate the Coriolis terms in bc\_accel\_u [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{437 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: V\_Cor\textcolor{comment}{      !< The (3-\/D) meridional velocities used to}}
\DoxyCodeLine{438 \textcolor{comment}{                                                         !! calculate the Coriolis terms in bc\_accel\_u [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{439 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: accel\_layer\_u\textcolor{comment}{ !< The zonal acceleration of each layer due}}
\DoxyCodeLine{440 \textcolor{comment}{                                                         !! to the barotropic calculation [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{441 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: accel\_layer\_v\textcolor{comment}{ !< The meridional acceleration of each layer}}
\DoxyCodeLine{442 \textcolor{comment}{                                                         !! due to the barotropic calculation [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{443 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          \textcolor{keywordtype}{intent(out)} :: eta\_out\textcolor{comment}{       !< The final barotropic free surface}}
\DoxyCodeLine{444 \textcolor{comment}{                                                         !! height anomaly or column mass anomaly [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{445 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},         \textcolor{keywordtype}{intent(out)} :: uhbtav\textcolor{comment}{        !< the barotropic zonal volume or mass}}
\DoxyCodeLine{446 \textcolor{comment}{                                                         !! fluxes averaged through the barotropic steps}}
\DoxyCodeLine{447 \textcolor{comment}{                                                         !! [H L2 T-\/1 \string~> m3 or kg s-\/1].}}
\DoxyCodeLine{448 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(out)} :: vhbtav\textcolor{comment}{        !< the barotropic meridional volume or mass}}
\DoxyCodeLine{449 \textcolor{comment}{                                                         !! fluxes averaged through the barotropic steps}}
\DoxyCodeLine{450 \textcolor{comment}{                                                         !! [H L2 T-\/1 \string~> m3 or kg s-\/1].}}
\DoxyCodeLine{451   \textcolor{keywordtype}{type}(barotropic\_CS),                       \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{            !< The control structure returned by a}}
\DoxyCodeLine{452 \textcolor{comment}{                                                         !! previous call to barotropic\_init.}}
\DoxyCodeLine{453 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: visc\_rem\_u\textcolor{comment}{    !< Both the fraction of the momentum}}
\DoxyCodeLine{454 \textcolor{comment}{                                                         !! originally in a layer that remains after a time-\/step of}}
\DoxyCodeLine{455 \textcolor{comment}{                                                         !! viscosity, and the fraction of a time-\/step's worth of a}}
\DoxyCodeLine{456 \textcolor{comment}{                                                         !! barotropic acceleration that a layer experiences after}}
\DoxyCodeLine{457 \textcolor{comment}{                                                         !! viscosity is applied, in the zonal direction. Nondimensional}}
\DoxyCodeLine{458 \textcolor{comment}{                                                         !! between 0 (at the bottom) and 1 (far above the bottom).}}
\DoxyCodeLine{459 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: visc\_rem\_v\textcolor{comment}{    !< Ditto for meridional direction [nondim].}}
\DoxyCodeLine{460 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: etaav\textcolor{comment}{        !< The free surface height or column mass}}
\DoxyCodeLine{461 \textcolor{comment}{                                                         !! averaged over the barotropic integration [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{462   \textcolor{keywordtype}{type}(accel\_diag\_ptrs),               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: ADp\textcolor{comment}{          !< Acceleration diagnostic pointers}}
\DoxyCodeLine{463   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{          !< The open boundary condition structure.}}
\DoxyCodeLine{464   \textcolor{keywordtype}{type}(BT\_cont\_type),                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: BT\_cont\textcolor{comment}{      !< A structure with elements that describe}}
\DoxyCodeLine{465 \textcolor{comment}{                                                         !! the effective open face areas as a function of barotropic}}
\DoxyCodeLine{466 \textcolor{comment}{                                                         !! flow.}}
\DoxyCodeLine{467 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: eta\_PF\_start\textcolor{comment}{ !< The eta field consistent with the pressure}}
\DoxyCodeLine{468 \textcolor{comment}{                                                         !! gradient at the start of the barotropic stepping}}
\DoxyCodeLine{469 \textcolor{comment}{                                                         !! [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{470 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: taux\_bot\textcolor{comment}{     !< The zonal bottom frictional stress from}}
\DoxyCodeLine{471 \textcolor{comment}{                                                         !! ocean to the seafloor [R L Z T-\/2 \string~> Pa].}}
\DoxyCodeLine{472 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: tauy\_bot\textcolor{comment}{     !< The meridional bottom frictional stress}}
\DoxyCodeLine{473 \textcolor{comment}{                                                         !! from ocean to the seafloor [R L Z T-\/2 \string~> Pa].}}
\DoxyCodeLine{474 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: uh0\textcolor{comment}{     !< The zonal layer transports at reference}}
\DoxyCodeLine{475 \textcolor{comment}{                                                                    !! velocities [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{476 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: u\_uh0\textcolor{comment}{   !< The velocities used to calculate}}
\DoxyCodeLine{477 \textcolor{comment}{                                                                    !! uh0 [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{478 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: vh0\textcolor{comment}{     !< The zonal layer transports at reference}}
\DoxyCodeLine{479 \textcolor{comment}{                                                                    !! velocities [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{480 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: v\_vh0\textcolor{comment}{   !< The velocities used to calculate}}
\DoxyCodeLine{481 \textcolor{comment}{                                                                    !! vh0 [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{482 }
\DoxyCodeLine{483   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{484 \textcolor{keywordtype}{  real} :: ubt\_Cor(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! The barotropic velocities that had been}}
\DoxyCodeLine{485 \textcolor{keywordtype}{  real} :: vbt\_Cor(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! used to calculate the input Coriolis}}
\DoxyCodeLine{486                                     \textcolor{comment}{! terms [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{487 \textcolor{keywordtype}{  real} :: wt\_u(SZIB\_(G),SZJ\_(G),SZK\_(G)) \textcolor{comment}{! wt\_u and wt\_v are the}}
\DoxyCodeLine{488 \textcolor{keywordtype}{  real} :: wt\_v(SZI\_(G),SZJB\_(G),SZK\_(G)) \textcolor{comment}{! normalized weights to}}
\DoxyCodeLine{489                 \textcolor{comment}{! be used in calculating barotropic velocities, possibly with}}
\DoxyCodeLine{490                 \textcolor{comment}{! sums less than one due to viscous losses.  Nondimensional.}}
\DoxyCodeLine{491 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{492     av\_rem\_u, \&   \textcolor{comment}{! The weighted average of visc\_rem\_u, nondimensional.}}
\DoxyCodeLine{493     tmp\_u, \&      \textcolor{comment}{! A temporary array at u points.}}
\DoxyCodeLine{494     ubt\_st, \&     \textcolor{comment}{! The zonal barotropic velocity at the start of timestep [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{495     ubt\_dt        \textcolor{comment}{! The zonal barotropic velocity tendency [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{496 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{497     av\_rem\_v, \&   \textcolor{comment}{! The weighted average of visc\_rem\_v, nondimensional.}}
\DoxyCodeLine{498     tmp\_v, \&      \textcolor{comment}{! A temporary array at v points.}}
\DoxyCodeLine{499     vbt\_st, \&     \textcolor{comment}{! The meridional barotropic velocity at the start of timestep [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{500     vbt\_dt        \textcolor{comment}{! The meridional barotropic velocity tendency [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{501 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{502     tmp\_h, \&      \textcolor{comment}{! A temporary array at h points.}}
\DoxyCodeLine{503     e\_anom        \textcolor{comment}{! The anomaly in the sea surface height or column mass}}
\DoxyCodeLine{504                   \textcolor{comment}{! averaged between the beginning and end of the time step,}}
\DoxyCodeLine{505                   \textcolor{comment}{! relative to eta\_PF, with SAL effects included [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{506 }
\DoxyCodeLine{507   \textcolor{comment}{! These are always allocated with symmetric memory and wide halos.}}
\DoxyCodeLine{508 \textcolor{keywordtype}{  real} :: q(SZIBW\_(CS),SZJBW\_(CS))  \textcolor{comment}{! A pseudo potential vorticity [T-\/1 Z-\/1 \string~> s-\/1 m-\/1]}}
\DoxyCodeLine{509                   \textcolor{comment}{! or [T-\/1 H-\/1 \string~> s-\/1 m-\/1 or m2 s-\/1 kg-\/1]}}
\DoxyCodeLine{510 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(CS),SZJW\_(CS))} :: \&}
\DoxyCodeLine{511     ubt, \&        \textcolor{comment}{! The zonal barotropic velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{512     bt\_rem\_u, \&   \textcolor{comment}{! The fraction of the barotropic zonal velocity that remains}}
\DoxyCodeLine{513                   \textcolor{comment}{! after a time step, the remainder being lost to bottom drag.}}
\DoxyCodeLine{514                   \textcolor{comment}{! bt\_rem\_u is a nondimensional number between 0 and 1.}}
\DoxyCodeLine{515     bt\_force\_u, \& \textcolor{comment}{! The vertical average of all of the u-\/accelerations that are}}
\DoxyCodeLine{516                   \textcolor{comment}{! not explicitly included in the barotropic equation [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{517     u\_accel\_bt, \& \textcolor{comment}{! The difference between the zonal acceleration from the}}
\DoxyCodeLine{518                   \textcolor{comment}{! barotropic calculation and BT\_force\_u [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{519     uhbt, \&       \textcolor{comment}{! The zonal barotropic thickness fluxes [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{520     uhbt0, \&      \textcolor{comment}{! The difference between the sum of the layer zonal thickness}}
\DoxyCodeLine{521                   \textcolor{comment}{! fluxes and the barotropic thickness flux using the same}}
\DoxyCodeLine{522                   \textcolor{comment}{! velocity [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{523     ubt\_old, \&    \textcolor{comment}{! The starting value of ubt in a barotropic step [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{524     ubt\_first, \&  \textcolor{comment}{! The starting value of ubt in a series of barotropic steps [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{525     ubt\_sum, \&    \textcolor{comment}{! The sum of ubt over the time steps [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{526     ubt\_int, \&    \textcolor{comment}{! The running time integral of ubt over the time steps [L \string~> m].}}
\DoxyCodeLine{527     uhbt\_sum, \&   \textcolor{comment}{! The sum of uhbt over the time steps [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{528     uhbt\_int, \&   \textcolor{comment}{! The running time integral of uhbt over the time steps [H L2  \string~> m3].}}
\DoxyCodeLine{529     ubt\_wtd, \&    \textcolor{comment}{! A weighted sum used to find the filtered final ubt [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{530     ubt\_trans, \&  \textcolor{comment}{! The latest value of ubt used for a transport [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{531     azon, bzon, \& \textcolor{comment}{! \_zon \& \_mer are the values of the Coriolis force which}}
\DoxyCodeLine{532     czon, dzon, \& \textcolor{comment}{! are applied to the neighboring values of vbtav \& ubtav,}}
\DoxyCodeLine{533     amer, bmer, \& \textcolor{comment}{! respectively to get the barotropic inertial rotation}}
\DoxyCodeLine{534     cmer, dmer, \& \textcolor{comment}{! [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{535     cor\_u, \&      \textcolor{comment}{! The zonal Coriolis acceleration [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{536     cor\_ref\_u, \&  \textcolor{comment}{! The zonal barotropic Coriolis acceleration due}}
\DoxyCodeLine{537                   \textcolor{comment}{! to the reference velocities [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{538     pfu, \&        \textcolor{comment}{! The zonal pressure force acceleration [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{539     rayleigh\_u, \& \textcolor{comment}{! A Rayleigh drag timescale operating at u-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{540     pfu\_bt\_sum, \& \textcolor{comment}{! The summed zonal barotropic pressure gradient force [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{541     coru\_bt\_sum, \& \textcolor{comment}{! The summed zonal barotropic Coriolis acceleration [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{542     dcor\_u, \&     \textcolor{comment}{! An averaged depth or total thickness at u points [Z \string~> m] or [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{543     datu          \textcolor{comment}{! Basin depth at u-\/velocity grid points times the y-\/grid}}
\DoxyCodeLine{544                   \textcolor{comment}{! spacing [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{545 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(CS),SZJBW\_(CS))} :: \&}
\DoxyCodeLine{546     vbt, \&        \textcolor{comment}{! The meridional barotropic velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{547     bt\_rem\_v, \&   \textcolor{comment}{! The fraction of the barotropic meridional velocity that}}
\DoxyCodeLine{548                   \textcolor{comment}{! remains after a time step, the rest being lost to bottom}}
\DoxyCodeLine{549                   \textcolor{comment}{! drag.  bt\_rem\_v is a nondimensional number between 0 and 1.}}
\DoxyCodeLine{550     bt\_force\_v, \& \textcolor{comment}{! The vertical average of all of the v-\/accelerations that are}}
\DoxyCodeLine{551                   \textcolor{comment}{! not explicitly included in the barotropic equation [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{552     v\_accel\_bt, \& \textcolor{comment}{! The difference between the meridional acceleration from the}}
\DoxyCodeLine{553                   \textcolor{comment}{! barotropic calculation and BT\_force\_v [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{554     vhbt, \&       \textcolor{comment}{! The meridional barotropic thickness fluxes [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{555     vhbt0, \&      \textcolor{comment}{! The difference between the sum of the layer meridional}}
\DoxyCodeLine{556                   \textcolor{comment}{! thickness fluxes and the barotropic thickness flux using}}
\DoxyCodeLine{557                   \textcolor{comment}{! the same velocities [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{558     vbt\_old, \&    \textcolor{comment}{! The starting value of vbt in a barotropic step [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{559     vbt\_first, \&  \textcolor{comment}{! The starting value of ubt in a series of barotropic steps [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{560     vbt\_sum, \&    \textcolor{comment}{! The sum of vbt over the time steps [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{561     vbt\_int, \&    \textcolor{comment}{! The running time integral of vbt over the time steps [L \string~> m].}}
\DoxyCodeLine{562     vhbt\_sum, \&   \textcolor{comment}{! The sum of vhbt over the time steps [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1].}}
\DoxyCodeLine{563     vhbt\_int, \&   \textcolor{comment}{! The running time integral of vhbt over the time steps [H L2  \string~> m3].}}
\DoxyCodeLine{564     vbt\_wtd, \&    \textcolor{comment}{! A weighted sum used to find the filtered final vbt [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{565     vbt\_trans, \&  \textcolor{comment}{! The latest value of vbt used for a transport [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{566     cor\_v, \&      \textcolor{comment}{! The meridional Coriolis acceleration [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{567     cor\_ref\_v, \&  \textcolor{comment}{! The meridional barotropic Coriolis acceleration due}}
\DoxyCodeLine{568                   \textcolor{comment}{! to the reference velocities [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{569     pfv, \&        \textcolor{comment}{! The meridional pressure force acceleration [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{570     rayleigh\_v, \& \textcolor{comment}{! A Rayleigh drag timescale operating at v-\/points [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{571     pfv\_bt\_sum, \& \textcolor{comment}{! The summed meridional barotropic pressure gradient force,}}
\DoxyCodeLine{572                   \textcolor{comment}{! [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{573     corv\_bt\_sum, \& \textcolor{comment}{! The summed meridional barotropic Coriolis acceleration,}}
\DoxyCodeLine{574                   \textcolor{comment}{! [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{575     dcor\_v, \&     \textcolor{comment}{! An averaged depth or total thickness at v points [Z \string~> m] or [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{576     datv          \textcolor{comment}{! Basin depth at v-\/velocity grid points times the x-\/grid}}
\DoxyCodeLine{577                   \textcolor{comment}{! spacing [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{578 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{target}, \textcolor{keywordtype}{dimension(SZIW\_(CS),SZJW\_(CS))} :: \&}
\DoxyCodeLine{579     eta, \&        \textcolor{comment}{! The barotropic free surface height anomaly or column mass}}
\DoxyCodeLine{580                   \textcolor{comment}{! anomaly [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{581     eta\_pred      \textcolor{comment}{! A predictor value of eta [H \string~> m or kg m-\/2] like eta.}}
\DoxyCodeLine{582 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: \&}
\DoxyCodeLine{583     eta\_PF\_BT     \textcolor{comment}{! A pointer to the eta array (either eta or eta\_pred) that}}
\DoxyCodeLine{584                   \textcolor{comment}{! determines the barotropic pressure force [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{585 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(CS),SZJW\_(CS))} :: \&}
\DoxyCodeLine{586     eta\_sum, \&    \textcolor{comment}{! eta summed across the timesteps [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{587     eta\_wtd, \&    \textcolor{comment}{! A weighted estimate used to calculate eta\_out [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{588     eta\_IC, \&     \textcolor{comment}{! A local copy of the initial 2-\/D eta field (eta\_in) [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{589     eta\_PF, \&     \textcolor{comment}{! A local copy of the 2-\/D eta field (either SSH anomaly or}}
\DoxyCodeLine{590                   \textcolor{comment}{! column mass anomaly) that was used to calculate the input}}
\DoxyCodeLine{591                   \textcolor{comment}{! pressure gradient accelerations [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{592     eta\_pf\_1, \&   \textcolor{comment}{! The initial value of eta\_PF, when interp\_eta\_PF is}}
\DoxyCodeLine{593                   \textcolor{comment}{! true [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{594     d\_eta\_pf, \&   \textcolor{comment}{! The change in eta\_PF over the barotropic time stepping when}}
\DoxyCodeLine{595                   \textcolor{comment}{! interp\_eta\_PF is true [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{596     gtot\_e, \&     \textcolor{comment}{! gtot\_X is the effective total reduced gravity used to relate}}
\DoxyCodeLine{597     gtot\_w, \&     \textcolor{comment}{! free surface height deviations to pressure forces (including}}
\DoxyCodeLine{598     gtot\_n, \&     \textcolor{comment}{! GFS and baroclinic  contributions) in the barotropic momentum}}
\DoxyCodeLine{599     gtot\_s, \&     \textcolor{comment}{! equations half a grid-\/point in the X-\/direction (X is N, S, E, or W)}}
\DoxyCodeLine{600                   \textcolor{comment}{! from the thickness point [L2 H-\/1 T-\/2 \string~> m s-\/2 or m4 kg-\/1 s-\/2].}}
\DoxyCodeLine{601                   \textcolor{comment}{! (See Hallberg, J Comp Phys 1997 for a discussion.)}}
\DoxyCodeLine{602     eta\_src, \&    \textcolor{comment}{! The source of eta per barotropic timestep [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{603     dyn\_coef\_eta, \& \textcolor{comment}{! The coefficient relating the changes in eta to the}}
\DoxyCodeLine{604                   \textcolor{comment}{! dynamic surface pressure under rigid ice}}
\DoxyCodeLine{605                   \textcolor{comment}{! [L2 T-\/2 H-\/1 \string~> m s-\/2 or m4 s-\/2 kg-\/1].}}
\DoxyCodeLine{606     p\_surf\_dyn    \textcolor{comment}{! A dynamic surface pressure under rigid ice [L2 T-\/2 \string~> m2 s-\/2].}}
\DoxyCodeLine{607   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{dimension(SZIBW\_(CS),SZJW\_(CS))} :: \&}
\DoxyCodeLine{608     BTCL\_u        \textcolor{comment}{! A repackaged version of the u-\/point information in BT\_cont.}}
\DoxyCodeLine{609   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{dimension(SZIW\_(CS),SZJBW\_(CS))} :: \&}
\DoxyCodeLine{610     BTCL\_v        \textcolor{comment}{! A repackaged version of the v-\/point information in BT\_cont.}}
\DoxyCodeLine{611   \textcolor{comment}{! End of wide-\/sized variables.}}
\DoxyCodeLine{612 }
\DoxyCodeLine{613 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(CS),SZJW\_(CS))} :: \&}
\DoxyCodeLine{614     ubt\_prev, ubt\_sum\_prev, ubt\_wtd\_prev, \& \textcolor{comment}{! Previous velocities stored for OBCs [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{615     uhbt\_prev, uhbt\_sum\_prev, \& \textcolor{comment}{! Previous transports stored for OBCs [L2 H T-\/1 \string~> m3 s-\/1]}}
\DoxyCodeLine{616     ubt\_int\_prev, \& \textcolor{comment}{! Previous value of time-\/integrated velocity stored for OBCs [L \string~> m]}}
\DoxyCodeLine{617     uhbt\_int\_prev   \textcolor{comment}{! Previous value of time-\/integrated transport stored for OBCs [L2 H \string~> m3]}}
\DoxyCodeLine{618 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(CS),SZJBW\_(CS))} :: \&}
\DoxyCodeLine{619     vbt\_prev, vbt\_sum\_prev, vbt\_wtd\_prev, \& \textcolor{comment}{! Previous velocities stored for OBCs [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{620     vhbt\_prev, vhbt\_sum\_prev, \& \textcolor{comment}{! Previous transports stored for OBCs [L2 H T-\/1 \string~> m3 s-\/1]}}
\DoxyCodeLine{621     vbt\_int\_prev, \& \textcolor{comment}{! Previous value of time-\/integrated velocity stored for OBCs [L \string~> m]}}
\DoxyCodeLine{622     vhbt\_int\_prev   \textcolor{comment}{! Previous value of time-\/integrated transport stored for OBCs [L2 H \string~> m3]}}
\DoxyCodeLine{623 \textcolor{keywordtype}{  real} :: mass\_to\_Z   \textcolor{comment}{! The depth unit conversion divided by the mean density (Rho0) [Z m-\/1 R-\/1 \string~> m3 kg-\/1].}}
\DoxyCodeLine{624 \textcolor{keywordtype}{  real} :: mass\_accel\_to\_Z \textcolor{comment}{! The inverse of the mean density (Rho0) [R-\/1 \string~> m3 kg-\/1].}}
\DoxyCodeLine{625 \textcolor{keywordtype}{  real} :: visc\_rem    \textcolor{comment}{! A work variable that may equal visc\_rem\_[uv].  Nondim.}}
\DoxyCodeLine{626 \textcolor{keywordtype}{  real} :: vel\_prev    \textcolor{comment}{! The previous velocity [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{627 \textcolor{keywordtype}{  real} :: dtbt        \textcolor{comment}{! The barotropic time step [T \string~> s].}}
\DoxyCodeLine{628 \textcolor{keywordtype}{  real} :: bebt        \textcolor{comment}{! A copy of CS\%bebt [nondim].}}
\DoxyCodeLine{629 \textcolor{keywordtype}{  real} :: be\_proj     \textcolor{comment}{! The fractional amount by which velocities are projected}}
\DoxyCodeLine{630                       \textcolor{comment}{! when project\_velocity is true. For now be\_proj is set}}
\DoxyCodeLine{631                       \textcolor{comment}{! to equal bebt, as they have similar roles and meanings.}}
\DoxyCodeLine{632 \textcolor{keywordtype}{  real} :: Idt         \textcolor{comment}{! The inverse of dt [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{633 \textcolor{keywordtype}{  real} :: det\_de      \textcolor{comment}{! The partial derivative due to self-\/attraction and loading}}
\DoxyCodeLine{634                       \textcolor{comment}{! of the reference geopotential with the sea surface height.}}
\DoxyCodeLine{635                       \textcolor{comment}{! This is typically \string~0.09 or less.}}
\DoxyCodeLine{636 \textcolor{keywordtype}{  real} :: dgeo\_de     \textcolor{comment}{! The constant of proportionality between geopotential and}}
\DoxyCodeLine{637                       \textcolor{comment}{! sea surface height.  It is a nondimensional number of}}
\DoxyCodeLine{638                       \textcolor{comment}{! order 1.  For stability, this may be made larger}}
\DoxyCodeLine{639                       \textcolor{comment}{! than the physical problem would suggest.}}
\DoxyCodeLine{640 \textcolor{keywordtype}{  real} :: Instep      \textcolor{comment}{! The inverse of the number of barotropic time steps to take.}}
\DoxyCodeLine{641 \textcolor{keywordtype}{  real} :: wt\_end      \textcolor{comment}{! The weighting of the final value of eta\_PF [nondim]}}
\DoxyCodeLine{642   \textcolor{keywordtype}{integer} :: nstep    \textcolor{comment}{! The number of barotropic time steps to take.}}
\DoxyCodeLine{643   \textcolor{keywordtype}{type}(time\_type) :: \&}
\DoxyCodeLine{644     time\_bt\_start, \&  \textcolor{comment}{! The starting time of the barotropic steps.}}
\DoxyCodeLine{645     time\_step\_end, \&  \textcolor{comment}{! The end time of a barotropic step.}}
\DoxyCodeLine{646     time\_end\_in       \textcolor{comment}{! The end time for diagnostics when this routine started.}}
\DoxyCodeLine{647 \textcolor{keywordtype}{  real} :: time\_int\_in \textcolor{comment}{! The diagnostics' time interval when this routine started.}}
\DoxyCodeLine{648 \textcolor{keywordtype}{  real} :: Htot\_avg    \textcolor{comment}{! The average total thickness of the tracer columns adjacent to a}}
\DoxyCodeLine{649                       \textcolor{comment}{! velocity point [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{650   \textcolor{keywordtype}{logical} :: do\_hifreq\_output  \textcolor{comment}{! If true, output occurs every barotropic step.}}
\DoxyCodeLine{651   \textcolor{keywordtype}{logical} :: use\_BT\_cont, do\_ave, find\_etaav, find\_PF, find\_Cor}
\DoxyCodeLine{652   \textcolor{keywordtype}{logical} :: integral\_BT\_cont \textcolor{comment}{! If true, update the barotropic continuity equation directly}}
\DoxyCodeLine{653                       \textcolor{comment}{! from the initial condition using the time-\/integrated barotropic velocity.}}
\DoxyCodeLine{654   \textcolor{keywordtype}{logical} :: ice\_is\_rigid, nonblock\_setup, interp\_eta\_PF}
\DoxyCodeLine{655   \textcolor{keywordtype}{logical} :: project\_velocity, add\_uh0}
\DoxyCodeLine{656 }
\DoxyCodeLine{657 \textcolor{keywordtype}{  real} :: dyn\_coef\_max \textcolor{comment}{! The maximum stable value of dyn\_coef\_eta}}
\DoxyCodeLine{658                       \textcolor{comment}{! [L2 T-\/2 H-\/1 \string~> m s-\/2 or m4 s-\/2 kg-\/1].}}
\DoxyCodeLine{659 \textcolor{keywordtype}{  real} :: ice\_strength = 0.0  \textcolor{comment}{! The effective strength of the ice [L2 Z-\/1 T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{660 \textcolor{keywordtype}{  real} :: Idt\_max2    \textcolor{comment}{! The squared inverse of the local maximum stable}}
\DoxyCodeLine{661                       \textcolor{comment}{! barotropic time step [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{662 \textcolor{keywordtype}{  real} :: H\_min\_dyn   \textcolor{comment}{! The minimum depth to use in limiting the size of the}}
\DoxyCodeLine{663                       \textcolor{comment}{! dynamic surface pressure for stability [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{664 \textcolor{keywordtype}{  real} :: H\_eff\_dx2   \textcolor{comment}{! The effective total thickness divided by the grid spacing}}
\DoxyCodeLine{665                       \textcolor{comment}{! squared [H L-\/2 \string~> m-\/1 or kg m-\/4].}}
\DoxyCodeLine{666 \textcolor{keywordtype}{  real} :: u\_max\_cor, v\_max\_cor \textcolor{comment}{! The maximum corrective velocities [L T-\/1 \string~> m s-\/1].}}
\DoxyCodeLine{667 \textcolor{keywordtype}{  real} :: uint\_cor, vint\_cor \textcolor{comment}{! The maximum time-\/integrated corrective velocities [L \string~> m].}}
\DoxyCodeLine{668 \textcolor{keywordtype}{  real} :: Htot        \textcolor{comment}{! The total thickness [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{669 \textcolor{keywordtype}{  real} :: eta\_cor\_max \textcolor{comment}{! The maximum fluid that can be added as a correction to eta [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{670 \textcolor{keywordtype}{  real} :: accel\_underflow \textcolor{comment}{! An acceleration that is so small it should be zeroed out [L T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{671 \textcolor{keywordtype}{  real} :: h\_neglect            \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{672                                \textcolor{comment}{! in roundoff and can be neglected [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{673 \textcolor{keywordtype}{  real} :: Idtbt       \textcolor{comment}{! The inverse of the barotropic time step [T-\/1 \string~> s-\/1]}}
\DoxyCodeLine{674 }
\DoxyCodeLine{675 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: wt\_vel, wt\_eta, wt\_accel, wt\_trans, wt\_accel2}
\DoxyCodeLine{676 \textcolor{keywordtype}{  real} :: sum\_wt\_vel, sum\_wt\_eta, sum\_wt\_accel, sum\_wt\_trans}
\DoxyCodeLine{677 \textcolor{keywordtype}{  real} :: I\_sum\_wt\_vel, I\_sum\_wt\_eta, I\_sum\_wt\_accel, I\_sum\_wt\_trans}
\DoxyCodeLine{678 \textcolor{keywordtype}{  real} :: dt\_filt     \textcolor{comment}{! The half-\/width of the barotropic filter [T \string~> s].}}
\DoxyCodeLine{679 \textcolor{keywordtype}{  real} :: trans\_wt1, trans\_wt2 \textcolor{comment}{! The weights used to compute ubt\_trans and vbt\_trans}}
\DoxyCodeLine{680   \textcolor{keywordtype}{integer} :: nfilter}
\DoxyCodeLine{681 }
\DoxyCodeLine{682   \textcolor{keywordtype}{logical} :: apply\_OBCs, apply\_OBC\_flather, apply\_OBC\_open}
\DoxyCodeLine{683   \textcolor{keywordtype}{type}(memory\_size\_type) :: MS}
\DoxyCodeLine{684   \textcolor{keywordtype}{character(len=200)} :: mesg}
\DoxyCodeLine{685   \textcolor{keywordtype}{integer} :: isv, iev, jsv, jev \textcolor{comment}{! The valid array size at the end of a step.}}
\DoxyCodeLine{686   \textcolor{keywordtype}{integer} :: stencil  \textcolor{comment}{! The stencil size of the algorithm, often 1 or 2.}}
\DoxyCodeLine{687   \textcolor{keywordtype}{integer} :: isvf, ievf, jsvf, jevf, num\_cycles}
\DoxyCodeLine{688   \textcolor{keywordtype}{integer} :: i, j, k, n}
\DoxyCodeLine{689   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz, Isq, Ieq, Jsq, Jeq}
\DoxyCodeLine{690   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{691   \textcolor{keywordtype}{integer} :: ioff, joff}
\DoxyCodeLine{692   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{693 }
\DoxyCodeLine{694   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{695       \textcolor{stringliteral}{"{}btstep: Module MOM\_barotropic must be initialized before it is used."{}})}
\DoxyCodeLine{696   \textcolor{keywordflow}{if} (.not.cs\%split) \textcolor{keywordflow}{return}}
\DoxyCodeLine{697   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{698   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{699   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{700   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{701   ms\%isdw = cs\%isdw ; ms\%iedw = cs\%iedw ; ms\%jsdw = cs\%jsdw ; ms\%jedw = cs\%jedw}
\DoxyCodeLine{702   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{703 }
\DoxyCodeLine{704   idt = 1.0 / dt}
\DoxyCodeLine{705   accel\_underflow = cs\%vel\_underflow * idt}
\DoxyCodeLine{706 }
\DoxyCodeLine{707   use\_bt\_cont = .false.}
\DoxyCodeLine{708   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bt\_cont)) use\_bt\_cont = (\textcolor{keyword}{associated}(bt\_cont))}
\DoxyCodeLine{709   integral\_bt\_cont = use\_bt\_cont .and. cs\%integral\_BT\_cont}
\DoxyCodeLine{710 }
\DoxyCodeLine{711   interp\_eta\_pf = .false.}
\DoxyCodeLine{712   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(eta\_pf\_start)) interp\_eta\_pf = (\textcolor{keyword}{associated}(eta\_pf\_start))}
\DoxyCodeLine{713 }
\DoxyCodeLine{714   project\_velocity = cs\%BT\_project\_velocity}
\DoxyCodeLine{715 }
\DoxyCodeLine{716   \textcolor{comment}{! Figure out the fullest arrays that could be updated.}}
\DoxyCodeLine{717   stencil = 1}
\DoxyCodeLine{718   \textcolor{keywordflow}{if} ((.not.use\_bt\_cont) .and. cs\%Nonlinear\_continuity .and. \&}
\DoxyCodeLine{719       (cs\%Nonlin\_cont\_update\_period > 0)) stencil = 2}
\DoxyCodeLine{720 }
\DoxyCodeLine{721   do\_ave = query\_averaging\_enabled(cs\%diag)}
\DoxyCodeLine{722   find\_etaav = \textcolor{keyword}{present}(etaav)}
\DoxyCodeLine{723   find\_pf = (do\_ave .and. ((cs\%id\_PFu\_bt > 0) .or. (cs\%id\_PFv\_bt > 0)))}
\DoxyCodeLine{724   find\_cor = (do\_ave .and. ((cs\%id\_Coru\_bt > 0) .or. (cs\%id\_Corv\_bt > 0)))}
\DoxyCodeLine{725 }
\DoxyCodeLine{726   add\_uh0 = .false.}
\DoxyCodeLine{727   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uh0)) add\_uh0 = \textcolor{keyword}{associated}(uh0)}
\DoxyCodeLine{728   \textcolor{keywordflow}{if} (add\_uh0 .and. .not.(\textcolor{keyword}{present}(vh0) .and. \textcolor{keyword}{present}(u\_uh0) .and. \&}
\DoxyCodeLine{729                           \textcolor{keyword}{present}(v\_vh0))) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{730       \textcolor{stringliteral}{"{}btstep: vh0, u\_uh0, and v\_vh0 must be present if uh0 is used."{}})}
\DoxyCodeLine{731   \textcolor{keywordflow}{if} (add\_uh0 .and. .not.(\textcolor{keyword}{associated}(vh0) .and. \textcolor{keyword}{associated}(u\_uh0) .and. \&}
\DoxyCodeLine{732                           \textcolor{keyword}{associated}(v\_vh0))) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{733       \textcolor{stringliteral}{"{}btstep: vh0, u\_uh0, and v\_vh0 must be associated if uh0 is used."{}})}
\DoxyCodeLine{734 }
\DoxyCodeLine{735   \textcolor{comment}{! This can be changed to try to optimize the performance.}}
\DoxyCodeLine{736   nonblock\_setup = g\%nonblocking\_updates}
\DoxyCodeLine{737 }
\DoxyCodeLine{738   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{739 }
\DoxyCodeLine{740   apply\_obcs = .false. ; cs\%BT\_OBC\%apply\_u\_OBCs = .false. ; cs\%BT\_OBC\%apply\_v\_OBCs = .false.}
\DoxyCodeLine{741   apply\_obc\_open = .false.}
\DoxyCodeLine{742   apply\_obc\_flather = .false.}
\DoxyCodeLine{743   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{744     cs\%BT\_OBC\%apply\_u\_OBCs = obc\%open\_u\_BCs\_exist\_globally .or. obc\%specified\_u\_BCs\_exist\_globally}
\DoxyCodeLine{745     cs\%BT\_OBC\%apply\_v\_OBCs = obc\%open\_v\_BCs\_exist\_globally .or. obc\%specified\_v\_BCs\_exist\_globally}
\DoxyCodeLine{746     apply\_obc\_flather = open\_boundary\_query(obc, apply\_flather\_obc=.true.)}
\DoxyCodeLine{747     apply\_obc\_open = open\_boundary\_query(obc, apply\_open\_obc=.true.)}
\DoxyCodeLine{748     apply\_obcs = open\_boundary\_query(obc, apply\_specified\_obc=.true.) .or. \&}
\DoxyCodeLine{749            apply\_obc\_flather .or. apply\_obc\_open}
\DoxyCodeLine{750 }
\DoxyCodeLine{751     \textcolor{keywordflow}{if} (apply\_obc\_flather .and. .not.gv\%Boussinesq) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{752       \textcolor{stringliteral}{"{}btstep: Flather open boundary conditions have not yet been "{}}// \&}
\DoxyCodeLine{753       \textcolor{stringliteral}{"{}implemented for a non-\/Boussinesq model."{}})}
\DoxyCodeLine{754 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{755 }
\DoxyCodeLine{756   num\_cycles = 1}
\DoxyCodeLine{757   \textcolor{keywordflow}{if} (cs\%use\_wide\_halos) \&}
\DoxyCodeLine{758     num\_cycles = min((is-\/cs\%isdw) / stencil, (js-\/cs\%jsdw) / stencil)}
\DoxyCodeLine{759   isvf = is -\/ (num\_cycles-\/1)*stencil ; ievf = ie + (num\_cycles-\/1)*stencil}
\DoxyCodeLine{760   jsvf = js -\/ (num\_cycles-\/1)*stencil ; jevf = je + (num\_cycles-\/1)*stencil}
\DoxyCodeLine{761 }
\DoxyCodeLine{762   nstep = ceiling(dt/cs\%dtbt -\/ 0.0001)}
\DoxyCodeLine{763   \textcolor{keywordflow}{if} (is\_root\_pe() .and. (nstep /= cs\%nstep\_last)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{764     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("{}btstep is using a dynamic barotropic timestep of "{}, ES12.6, \&}}
\DoxyCodeLine{765 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "{} seconds, max "{}, ES12.6, "{}."{})'}) (us\%T\_to\_s*dt/nstep), us\%T\_to\_s*cs\%dtbt\_max}
\DoxyCodeLine{766     \textcolor{keyword}{call }mom\_mesg(mesg, 3)}
\DoxyCodeLine{767 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{768   cs\%nstep\_last = nstep}
\DoxyCodeLine{769 }
\DoxyCodeLine{770   \textcolor{comment}{! Set the actual barotropic time step.}}
\DoxyCodeLine{771   instep = 1.0 / real(nstep)}
\DoxyCodeLine{772   dtbt = dt * instep}
\DoxyCodeLine{773   idtbt = 1.0 / dtbt}
\DoxyCodeLine{774   bebt = cs\%bebt}
\DoxyCodeLine{775   be\_proj = cs\%bebt}
\DoxyCodeLine{776   mass\_accel\_to\_z = 1.0 / gv\%Rho0}
\DoxyCodeLine{777   mass\_to\_z = us\%m\_to\_Z / gv\%Rho0}
\DoxyCodeLine{778 }
\DoxyCodeLine{779   \textcolor{comment}{!-\/-\/-\/ setup the weight when computing vbt\_trans and ubt\_trans}}
\DoxyCodeLine{780   \textcolor{keywordflow}{if} (project\_velocity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{781     trans\_wt1 = (1.0 + be\_proj); trans\_wt2 = -\/be\_proj}
\DoxyCodeLine{782   \textcolor{keywordflow}{else}}
\DoxyCodeLine{783     trans\_wt1 = bebt ;           trans\_wt2 = (1.0-\/bebt)}
\DoxyCodeLine{784 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{785 }
\DoxyCodeLine{786   do\_hifreq\_output = .false.}
\DoxyCodeLine{787   \textcolor{keywordflow}{if} ((cs\%id\_ubt\_hifreq > 0) .or. (cs\%id\_vbt\_hifreq > 0) .or. \&}
\DoxyCodeLine{788       (cs\%id\_eta\_hifreq > 0) .or. (cs\%id\_eta\_pred\_hifreq > 0) .or. \&}
\DoxyCodeLine{789       (cs\%id\_uhbt\_hifreq > 0) .or. (cs\%id\_vhbt\_hifreq > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{790     do\_hifreq\_output = query\_averaging\_enabled(cs\%diag, time\_int\_in, time\_end\_in)}
\DoxyCodeLine{791     \textcolor{keywordflow}{if} (do\_hifreq\_output) \&}
\DoxyCodeLine{792       time\_bt\_start = time\_end\_in -\/ real\_to\_time(us\%T\_to\_s*dt)}
\DoxyCodeLine{793 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{794 }
\DoxyCodeLine{795 \textcolor{comment}{!-\/-\/-\/ begin setup for group halo update}}
\DoxyCodeLine{796   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{797   \textcolor{keywordflow}{if} (.not. cs\%linearized\_BT\_PV) \textcolor{keywordflow}{then}}
\DoxyCodeLine{798     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_q\_DCor, q, cs\%BT\_Domain, to\_all, position=corner)}
\DoxyCodeLine{799     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_q\_DCor, dcor\_u, dcor\_v, cs\%BT\_Domain, \&}
\DoxyCodeLine{800          to\_all+scalar\_pair)}
\DoxyCodeLine{801 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{802   \textcolor{keywordflow}{if} ((isq > is-\/1) .or. (jsq > js-\/1)) \&}
\DoxyCodeLine{803     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_tmp\_uv, tmp\_u, tmp\_v, g\%Domain)}
\DoxyCodeLine{804   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_gtot, gtot\_e, gtot\_n, cs\%BT\_Domain, \&}
\DoxyCodeLine{805        to\_all+scalar\_pair, agrid)}
\DoxyCodeLine{806   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_gtot, gtot\_w, gtot\_s, cs\%BT\_Domain, \&}
\DoxyCodeLine{807        to\_all+scalar\_pair, agrid)}
\DoxyCodeLine{808 }
\DoxyCodeLine{809   \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \&}
\DoxyCodeLine{810     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, dyn\_coef\_eta, cs\%BT\_Domain)}
\DoxyCodeLine{811   \textcolor{keywordflow}{if} (interp\_eta\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{812     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, eta\_pf\_1, cs\%BT\_Domain)}
\DoxyCodeLine{813     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, d\_eta\_pf, cs\%BT\_Domain)}
\DoxyCodeLine{814   \textcolor{keywordflow}{else}}
\DoxyCodeLine{815     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, eta\_pf, cs\%BT\_Domain)}
\DoxyCodeLine{816 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{817   \textcolor{keywordflow}{if} (integral\_bt\_cont) \&}
\DoxyCodeLine{818     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, eta\_ic, cs\%BT\_Domain)}
\DoxyCodeLine{819   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, eta\_src, cs\%BT\_Domain)}
\DoxyCodeLine{820   \textcolor{comment}{! The following halo updates are not needed without wide halos.  RWH}}
\DoxyCodeLine{821   \textcolor{comment}{! We do need them after all.}}
\DoxyCodeLine{822 \textcolor{comment}{! if (ievf > ie) then}}
\DoxyCodeLine{823     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, bt\_rem\_u, bt\_rem\_v, \&}
\DoxyCodeLine{824                       cs\%BT\_Domain, to\_all+scalar\_pair)}
\DoxyCodeLine{825     \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \&}
\DoxyCodeLine{826       \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_bt\_rem, rayleigh\_u, rayleigh\_v, \&}
\DoxyCodeLine{827                       cs\%BT\_Domain, to\_all+scalar\_pair)}
\DoxyCodeLine{828 \textcolor{comment}{! endif}}
\DoxyCodeLine{829   \textcolor{comment}{! The following halo update is not needed without wide halos.  RWH}}
\DoxyCodeLine{830   \textcolor{keywordflow}{if} (((g\%isd > cs\%isdw) .or. (g\%jsd > cs\%jsdw)) .or. (isq <= is-\/1) .or. (jsq <= js-\/1)) \&}
\DoxyCodeLine{831     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_force\_hbt0\_Cor\_ref, bt\_force\_u, bt\_force\_v, cs\%BT\_Domain)}
\DoxyCodeLine{832   \textcolor{keywordflow}{if} (add\_uh0) \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_force\_hbt0\_Cor\_ref, uhbt0, vhbt0, cs\%BT\_Domain)}
\DoxyCodeLine{833   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_force\_hbt0\_Cor\_ref, cor\_ref\_u, cor\_ref\_v, cs\%BT\_Domain)}
\DoxyCodeLine{834   \textcolor{keywordflow}{if} (.not. use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{835     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_Dat\_uv, datu, datv, cs\%BT\_Domain, to\_all+scalar\_pair)}
\DoxyCodeLine{836 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{837   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_ubt, eta, cs\%BT\_Domain)}
\DoxyCodeLine{838   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_ubt, ubt, vbt, cs\%BT\_Domain)}
\DoxyCodeLine{839   \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{840     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_ubt, ubt\_int, vbt\_int, cs\%BT\_Domain)}
\DoxyCodeLine{841     \textcolor{comment}{! This is only needed with integral\_BT\_cont, OBCs and multiple barotropic steps between halo updates.}}
\DoxyCodeLine{842     \textcolor{keywordflow}{if} (apply\_obc\_open) \&}
\DoxyCodeLine{843       \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_eta\_ubt, uhbt\_int, vhbt\_int, cs\%BT\_Domain)}
\DoxyCodeLine{844 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{845 }
\DoxyCodeLine{846   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_ubt\_Cor, ubt\_cor, vbt\_cor, g\%Domain)}
\DoxyCodeLine{847   \textcolor{comment}{! These passes occur at the end of the routine, as data is being readied to}}
\DoxyCodeLine{848   \textcolor{comment}{! share with the main part of the MOM6 code.}}
\DoxyCodeLine{849   \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keywordflow}{then}}
\DoxyCodeLine{850     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_etaav, etaav, g\%Domain)}
\DoxyCodeLine{851 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{852   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_e\_anom, e\_anom, g\%Domain)}
\DoxyCodeLine{853   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_ubta\_uhbta, cs\%ubtav, cs\%vbtav, g\%Domain)}
\DoxyCodeLine{854   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_ubta\_uhbta, uhbtav, vhbtav, g\%Domain)}
\DoxyCodeLine{855 }
\DoxyCodeLine{856   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{857 \textcolor{comment}{!-\/-\/-\/ end setup for group halo update}}
\DoxyCodeLine{858 }
\DoxyCodeLine{859 \textcolor{comment}{!   Calculate the constant coefficients for the Coriolis force terms in the}}
\DoxyCodeLine{860 \textcolor{comment}{! barotropic momentum equations.  This has to be done quite early to start}}
\DoxyCodeLine{861 \textcolor{comment}{! the halo update that needs to be completed before the next calculations.}}
\DoxyCodeLine{862   \textcolor{keywordflow}{if} (cs\%linearized\_BT\_PV) \textcolor{keywordflow}{then}}
\DoxyCodeLine{863     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{864     \textcolor{keywordflow}{do} j=jsvf-\/2,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/2,ievf+1}
\DoxyCodeLine{865       q(i,j) = cs\%q\_D(i,j)}
\DoxyCodeLine{866 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{867     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{868     \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/2,ievf+1}
\DoxyCodeLine{869       dcor\_u(i,j) = cs\%D\_u\_Cor(i,j)}
\DoxyCodeLine{870 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{871     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{872     \textcolor{keywordflow}{do} j=jsvf-\/2,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{873       dcor\_v(i,j) = cs\%D\_v\_Cor(i,j)}
\DoxyCodeLine{874 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{875   \textcolor{keywordflow}{else}}
\DoxyCodeLine{876     q(:,:) = 0.0 ; dcor\_u(:,:) = 0.0 ; dcor\_v(:,:) = 0.0}
\DoxyCodeLine{877     \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{878       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{879       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{880         dcor\_u(i,j) = 0.5 * (max(gv\%Z\_to\_H*g\%bathyT(i+1,j) + eta\_in(i+1,j), 0.0) + \&}
\DoxyCodeLine{881                              max(gv\%Z\_to\_H*g\%bathyT(i,j) + eta\_in(i,j), 0.0) )}
\DoxyCodeLine{882 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{883       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{884       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{885         dcor\_v(i,j) = 0.5 * (max(gv\%Z\_to\_H*g\%bathyT(i,j+1) + eta\_in(i+1,j), 0.0) + \&}
\DoxyCodeLine{886                              max(gv\%Z\_to\_H*g\%bathyT(i,j) + eta\_in(i,j), 0.0) )}
\DoxyCodeLine{887 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{888       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{889       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{890         q(i,j) = 0.25 * (cs\%BT\_Coriolis\_scale * g\%CoriolisBu(i,j)) * \&}
\DoxyCodeLine{891              ((g\%areaT(i,j) + g\%areaT(i+1,j+1)) + (g\%areaT(i+1,j) + g\%areaT(i,j+1))) / \&}
\DoxyCodeLine{892              (max((g\%areaT(i,j) * max(gv\%Z\_to\_H*g\%bathyT(i,j) + eta\_in(i,j), 0.0) + \&}
\DoxyCodeLine{893                g\%areaT(i+1,j+1) * max(gv\%Z\_to\_H*g\%bathyT(i+1,j+1) + eta\_in(i+1,j+1), 0.0)) + \&}
\DoxyCodeLine{894               (g\%areaT(i+1,j) * max(gv\%Z\_to\_H*g\%bathyT(i+1,j) + eta\_in(i+1,j), 0.0) + \&}
\DoxyCodeLine{895                g\%areaT(i,j+1) * max(gv\%Z\_to\_H*g\%bathyT(i,j+1) + eta\_in(i,j+1), 0.0)), h\_neglect) )}
\DoxyCodeLine{896 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{897     \textcolor{keywordflow}{else}}
\DoxyCodeLine{898       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{899       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{900         dcor\_u(i,j) = 0.5 * (eta\_in(i+1,j) + eta\_in(i,j))}
\DoxyCodeLine{901 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{902       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{903       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{904         dcor\_v(i,j) = 0.5 * (eta\_in(i,j+1) + eta\_in(i,j))}
\DoxyCodeLine{905 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{906       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{907       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{908         q(i,j) = 0.25 * (cs\%BT\_Coriolis\_scale * g\%CoriolisBu(i,j)) * \&}
\DoxyCodeLine{909              ((g\%areaT(i,j) + g\%areaT(i+1,j+1)) + (g\%areaT(i+1,j) + g\%areaT(i,j+1))) / \&}
\DoxyCodeLine{910              (max((g\%areaT(i,j) * eta\_in(i,j) + g\%areaT(i+1,j+1) * eta\_in(i+1,j+1)) + \&}
\DoxyCodeLine{911                   (g\%areaT(i+1,j) * eta\_in(i+1,j) + g\%areaT(i,j+1) * eta\_in(i,j+1)), h\_neglect) )}
\DoxyCodeLine{912 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{913 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{914 }
\DoxyCodeLine{915     \textcolor{comment}{! With very wide halos, q and D need to be calculated on the available data}}
\DoxyCodeLine{916     \textcolor{comment}{! domain and then updated onto the full computational domain.}}
\DoxyCodeLine{917     \textcolor{comment}{! These calculations can be done almost immediately, but the halo updates}}
\DoxyCodeLine{918     \textcolor{comment}{! must be done before the [abcd]mer and [abcd]zon are calculated.}}
\DoxyCodeLine{919     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{920     \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{921       \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_q\_DCor, cs\%BT\_Domain, clock=id\_clock\_pass\_pre)}
\DoxyCodeLine{922     \textcolor{keywordflow}{else}}
\DoxyCodeLine{923       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_q\_DCor, cs\%BT\_Domain, clock=id\_clock\_pass\_pre)}
\DoxyCodeLine{924 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{925     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{926 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{927 }
\DoxyCodeLine{928   \textcolor{comment}{! Zero out various wide-\/halo arrays.}}
\DoxyCodeLine{929   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{930   \textcolor{keywordflow}{do} j=cs\%jsdw,cs\%jedw ; \textcolor{keywordflow}{do} i=cs\%isdw,cs\%iedw}
\DoxyCodeLine{931     gtot\_e(i,j) = 0.0 ; gtot\_w(i,j) = 0.0}
\DoxyCodeLine{932     gtot\_n(i,j) = 0.0 ; gtot\_s(i,j) = 0.0}
\DoxyCodeLine{933     eta(i,j) = 0.0}
\DoxyCodeLine{934     eta\_pf(i,j) = 0.0}
\DoxyCodeLine{935     \textcolor{keywordflow}{if} (interp\_eta\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{936       eta\_pf\_1(i,j) = 0.0 ; d\_eta\_pf(i,j) = 0.0}
\DoxyCodeLine{937 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{938     \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{939       eta\_ic(i,j) = 0.0}
\DoxyCodeLine{940 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{941     p\_surf\_dyn(i,j) = 0.0}
\DoxyCodeLine{942     \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) dyn\_coef\_eta(i,j) = 0.0}
\DoxyCodeLine{943 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{944   \textcolor{comment}{!   The halo regions of various arrays need to be initialized to}}
\DoxyCodeLine{945   \textcolor{comment}{! non-\/NaNs in case the neighboring domains are not part of the ocean.}}
\DoxyCodeLine{946   \textcolor{comment}{! Otherwise a halo update later on fills in the correct values.}}
\DoxyCodeLine{947   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{948   \textcolor{keywordflow}{do} j=cs\%jsdw,cs\%jedw ; \textcolor{keywordflow}{do} i=cs\%isdw-\/1,cs\%iedw}
\DoxyCodeLine{949     cor\_ref\_u(i,j) = 0.0 ; bt\_force\_u(i,j) = 0.0 ; ubt(i,j) = 0.0}
\DoxyCodeLine{950     datu(i,j) = 0.0 ; bt\_rem\_u(i,j) = 0.0 ; uhbt0(i,j) = 0.0}
\DoxyCodeLine{951 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{952   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{953   \textcolor{keywordflow}{do} j=cs\%jsdw-\/1,cs\%jedw ; \textcolor{keywordflow}{do} i=cs\%isdw,cs\%iedw}
\DoxyCodeLine{954     cor\_ref\_v(i,j) = 0.0 ; bt\_force\_v(i,j) = 0.0 ; vbt(i,j) = 0.0}
\DoxyCodeLine{955     datv(i,j) = 0.0 ; bt\_rem\_v(i,j) = 0.0 ; vhbt0(i,j) = 0.0}
\DoxyCodeLine{956 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{957 }
\DoxyCodeLine{958   \textcolor{comment}{! Copy input arrays into their wide-\/halo counterparts.}}
\DoxyCodeLine{959   \textcolor{keywordflow}{if} (interp\_eta\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{960     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{961     \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied \textcolor{comment}{! Was "{}do j=Jsq,Jeq+1 ; do i=Isq,Ieq+1"{} but doing so breaks OBC. Not sure why?}}
\DoxyCodeLine{962       eta(i,j) = eta\_in(i,j)}
\DoxyCodeLine{963       eta\_pf\_1(i,j) = eta\_pf\_start(i,j)}
\DoxyCodeLine{964       d\_eta\_pf(i,j) = eta\_pf\_in(i,j) -\/ eta\_pf\_start(i,j)}
\DoxyCodeLine{965 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{966   \textcolor{keywordflow}{else}}
\DoxyCodeLine{967     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{968     \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied \textcolor{comment}{!: Was "{}do j=Jsq,Jeq+1 ; do i=Isq,Ieq+1"{} but doing so breaks OBC. Not sure why?}}
\DoxyCodeLine{969       eta(i,j) = eta\_in(i,j)}
\DoxyCodeLine{970       eta\_pf(i,j) = eta\_pf\_in(i,j)}
\DoxyCodeLine{971 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{972 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{973   \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{974     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{975     \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{976       eta\_ic(i,j) = eta\_in(i,j)}
\DoxyCodeLine{977 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{978 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{979 }
\DoxyCodeLine{980   \textcolor{comment}{!\$OMP parallel do default(shared) private(visc\_rem)}}
\DoxyCodeLine{981   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{982     \textcolor{comment}{! rem needs greater than visc\_rem\_u and 1-\/Instep/visc\_rem\_u.}}
\DoxyCodeLine{983     \textcolor{comment}{! The 0.5 below is just for safety.}}
\DoxyCodeLine{984     \textcolor{keywordflow}{if} (visc\_rem\_u(i,j,k) <= 0.0) \textcolor{keywordflow}{then} ; visc\_rem = 0.0}
\DoxyCodeLine{985     \textcolor{keywordflow}{elseif} (visc\_rem\_u(i,j,k) >= 1.0) \textcolor{keywordflow}{then} ; visc\_rem = 1.0}
\DoxyCodeLine{986     \textcolor{keywordflow}{elseif} (visc\_rem\_u(i,j,k)**2 > visc\_rem\_u(i,j,k) -\/ 0.5*instep) \textcolor{keywordflow}{then}}
\DoxyCodeLine{987       visc\_rem = visc\_rem\_u(i,j,k)}
\DoxyCodeLine{988     \textcolor{keywordflow}{else} ; visc\_rem = 1.0 -\/ 0.5*instep/visc\_rem\_u(i,j,k) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{989     wt\_u(i,j,k) = cs\%frhatu(i,j,k) * visc\_rem}
\DoxyCodeLine{990 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{991   \textcolor{comment}{!\$OMP parallel do default(shared) private(visc\_rem)}}
\DoxyCodeLine{992   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{993     \textcolor{comment}{! rem needs greater than visc\_rem\_v and 1-\/Instep/visc\_rem\_v.}}
\DoxyCodeLine{994     \textcolor{keywordflow}{if} (visc\_rem\_v(i,j,k) <= 0.0) \textcolor{keywordflow}{then} ; visc\_rem = 0.0}
\DoxyCodeLine{995     \textcolor{keywordflow}{elseif} (visc\_rem\_v(i,j,k) >= 1.0) \textcolor{keywordflow}{then} ; visc\_rem = 1.0}
\DoxyCodeLine{996     \textcolor{keywordflow}{elseif} (visc\_rem\_v(i,j,k)**2 > visc\_rem\_v(i,j,k) -\/ 0.5*instep) \textcolor{keywordflow}{then}}
\DoxyCodeLine{997       visc\_rem = visc\_rem\_v(i,j,k)}
\DoxyCodeLine{998     \textcolor{keywordflow}{else} ; visc\_rem = 1.0 -\/ 0.5*instep/visc\_rem\_v(i,j,k) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{999     wt\_v(i,j,k) = cs\%frhatv(i,j,k) * visc\_rem}
\DoxyCodeLine{1000 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1001 }
\DoxyCodeLine{1002   \textcolor{comment}{!   Use u\_Cor and v\_Cor as the reference values for the Coriolis terms,}}
\DoxyCodeLine{1003   \textcolor{comment}{! including the viscous remnant.}}
\DoxyCodeLine{1004   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1005   \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie ; ubt\_cor(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1006   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1007   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie+1 ; vbt\_cor(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1008   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1009   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1010     ubt\_cor(i,j) = ubt\_cor(i,j) + wt\_u(i,j,k) * u\_cor(i,j,k)}
\DoxyCodeLine{1011 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1012   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1013   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1014     vbt\_cor(i,j) = vbt\_cor(i,j) + wt\_v(i,j,k) * v\_cor(i,j,k)}
\DoxyCodeLine{1015 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1016 }
\DoxyCodeLine{1017   \textcolor{comment}{! The gtot arrays are the effective layer-\/weighted reduced gravities for}}
\DoxyCodeLine{1018   \textcolor{comment}{! accelerations across the various faces, with names for the relative}}
\DoxyCodeLine{1019   \textcolor{comment}{! locations of the faces to the pressure point.  They will have their halos}}
\DoxyCodeLine{1020   \textcolor{comment}{! updated later on.}}
\DoxyCodeLine{1021   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1022   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{1023     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1024       gtot\_e(i,j)   = gtot\_e(i,j)   + pbce(i,j,k)   * wt\_u(i,j,k)}
\DoxyCodeLine{1025       gtot\_w(i+1,j) = gtot\_w(i+1,j) + pbce(i+1,j,k) * wt\_u(i,j,k)}
\DoxyCodeLine{1026 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1027 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1028   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1029   \textcolor{keywordflow}{do} j=js-\/1,je}
\DoxyCodeLine{1030      \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1031       gtot\_n(i,j)   = gtot\_n(i,j)   + pbce(i,j,k)   * wt\_v(i,j,k)}
\DoxyCodeLine{1032       gtot\_s(i,j+1) = gtot\_s(i,j+1) + pbce(i,j+1,k) * wt\_v(i,j,k)}
\DoxyCodeLine{1033 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1034 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1035 }
\DoxyCodeLine{1036   \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1037     \textcolor{keyword}{call }tidal\_forcing\_sensitivity(g, cs\%tides\_CSp, det\_de)}
\DoxyCodeLine{1038     dgeo\_de = 1.0 + det\_de + cs\%G\_extra}
\DoxyCodeLine{1039   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1040     dgeo\_de = 1.0 + cs\%G\_extra}
\DoxyCodeLine{1041 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1042 }
\DoxyCodeLine{1043   \textcolor{keywordflow}{if} (nonblock\_setup .and. .not.cs\%linearized\_BT\_PV) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1044     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1045     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_q\_DCor, cs\%BT\_Domain, clock=id\_clock\_pass\_pre)}
\DoxyCodeLine{1046     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1047 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1048 }
\DoxyCodeLine{1049   \textcolor{comment}{! Calculate the open areas at the velocity points.}}
\DoxyCodeLine{1050   \textcolor{comment}{! The halo updates are needed before Datu is first used, either in set\_up\_BT\_OBC or ubt\_Cor.}}
\DoxyCodeLine{1051   \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1052     \textcolor{keyword}{call }set\_local\_bt\_cont\_types(bt\_cont, btcl\_u, btcl\_v, g, us, ms, cs\%BT\_Domain, 1+ievf-\/ie, dt\_baroclinic=dt)}
\DoxyCodeLine{1053   \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1054     \textcolor{keyword}{call }set\_local\_bt\_cont\_types(bt\_cont, btcl\_u, btcl\_v, g, us, ms, cs\%BT\_Domain, 1+ievf-\/ie)}
\DoxyCodeLine{1055   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1056     \textcolor{keywordflow}{if} (cs\%Nonlinear\_continuity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1057       \textcolor{keyword}{call }find\_face\_areas(datu, datv, g, gv, us, cs, ms, eta, 1)}
\DoxyCodeLine{1058     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1059       \textcolor{keyword}{call }find\_face\_areas(datu, datv, g, gv, us, cs, ms, halo=1)}
\DoxyCodeLine{1060 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1061 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1062 }
\DoxyCodeLine{1063   \textcolor{comment}{! Set up fields related to the open boundary conditions.}}
\DoxyCodeLine{1064   \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1065     \textcolor{keyword}{call }set\_up\_bt\_obc(obc, eta, cs\%BT\_OBC, cs\%BT\_Domain, g, gv, us, ms, ievf-\/ie, use\_bt\_cont, \&}
\DoxyCodeLine{1066                        integral\_bt\_cont, dt, datu, datv, btcl\_u, btcl\_v)}
\DoxyCodeLine{1067 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1068 }
\DoxyCodeLine{1069   \textcolor{comment}{! Determine the difference between the sum of the layer fluxes and the}}
\DoxyCodeLine{1070   \textcolor{comment}{! barotropic fluxes found from the same input velocities.}}
\DoxyCodeLine{1071   \textcolor{keywordflow}{if} (add\_uh0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1072     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1073     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; uhbt(i,j) = 0.0 ; ubt(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1074     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1075     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; vhbt(i,j) = 0.0 ; vbt(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1076     \textcolor{keywordflow}{if} (cs\%visc\_rem\_u\_uh0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1077       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1078       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1079         uhbt(i,j) = uhbt(i,j) + uh0(i,j,k)}
\DoxyCodeLine{1080         ubt(i,j) = ubt(i,j) + wt\_u(i,j,k) * u\_uh0(i,j,k)}
\DoxyCodeLine{1081 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1082       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1083       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1084         vhbt(i,j) = vhbt(i,j) + vh0(i,j,k)}
\DoxyCodeLine{1085         vbt(i,j) = vbt(i,j) + wt\_v(i,j,k) * v\_vh0(i,j,k)}
\DoxyCodeLine{1086 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1087     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1088       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1089       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1090         uhbt(i,j) = uhbt(i,j) + uh0(i,j,k)}
\DoxyCodeLine{1091         ubt(i,j) = ubt(i,j) + cs\%frhatu(i,j,k) * u\_uh0(i,j,k)}
\DoxyCodeLine{1092 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1093       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1094       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1095         vhbt(i,j) = vhbt(i,j) + vh0(i,j,k)}
\DoxyCodeLine{1096         vbt(i,j) = vbt(i,j) + cs\%frhatv(i,j,k) * v\_vh0(i,j,k)}
\DoxyCodeLine{1097 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1098 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1099     \textcolor{keywordflow}{if} ((use\_bt\_cont .or. integral\_bt\_cont) .and. cs\%adjust\_BT\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1100       \textcolor{comment}{! Use the additional input transports to broaden the fits}}
\DoxyCodeLine{1101       \textcolor{comment}{! over which the bt\_cont\_type applies.}}
\DoxyCodeLine{1102 }
\DoxyCodeLine{1103       \textcolor{comment}{! Fill in the halo data for ubt, vbt, uhbt, and vhbt.}}
\DoxyCodeLine{1104       \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1105       \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{1106       \textcolor{keyword}{call }pass\_vector(ubt, vbt, cs\%BT\_Domain, complete=.false., halo=1+ievf-\/ie)}
\DoxyCodeLine{1107       \textcolor{keyword}{call }pass\_vector(uhbt, vhbt, cs\%BT\_Domain, complete=.true., halo=1+ievf-\/ie)}
\DoxyCodeLine{1108       \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{1109       \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1110 }
\DoxyCodeLine{1111       \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1112         \textcolor{keyword}{call }adjust\_local\_bt\_cont\_types(ubt, uhbt, vbt, vhbt, btcl\_u, btcl\_v, \&}
\DoxyCodeLine{1113                                         g, us, ms, halo=1+ievf-\/ie, dt\_baroclinic=dt)}
\DoxyCodeLine{1114       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1115         \textcolor{keyword}{call }adjust\_local\_bt\_cont\_types(ubt, uhbt, vbt, vhbt, btcl\_u, btcl\_v, \&}
\DoxyCodeLine{1116                                         g, us, ms, halo=1+ievf-\/ie)}
\DoxyCodeLine{1117 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1118 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1119     \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1120       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1121       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1122         uhbt0(i,j) = uhbt(i,j) -\/ find\_uhbt(dt*ubt(i,j), btcl\_u(i,j)) * idt}
\DoxyCodeLine{1123 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1124       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1125       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1126         vhbt0(i,j) = vhbt(i,j) -\/ find\_vhbt(dt*vbt(i,j), btcl\_v(i,j)) * idt}
\DoxyCodeLine{1127 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1128     \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1129       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1130       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1131         uhbt0(i,j) = uhbt(i,j) -\/ find\_uhbt(ubt(i,j), btcl\_u(i,j))}
\DoxyCodeLine{1132 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1133       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1134       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1135         vhbt0(i,j) = vhbt(i,j) -\/ find\_vhbt(vbt(i,j), btcl\_v(i,j))}
\DoxyCodeLine{1136 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1137     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1138       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1139       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1140         uhbt0(i,j) = uhbt(i,j) -\/ datu(i,j)*ubt(i,j)}
\DoxyCodeLine{1141 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1142       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1143       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1144         vhbt0(i,j) = vhbt(i,j) -\/ datv(i,j)*vbt(i,j)}
\DoxyCodeLine{1145 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1146 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1147     \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! zero out pressure force across boundary}}
\DoxyCodeLine{1148       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1149       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1150         uhbt0(i,j) = 0.0}
\DoxyCodeLine{1151 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1152 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1153     \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! zero out PF across boundary}}
\DoxyCodeLine{1154       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1155       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1156         vhbt0(i,j) = 0.0}
\DoxyCodeLine{1157 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1158 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1159 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1160 }
\DoxyCodeLine{1161 \textcolor{comment}{! Calculate the initial barotropic velocities from the layer's velocities.}}
\DoxyCodeLine{1162   \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1163     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1164     \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/2,ievf+1}
\DoxyCodeLine{1165       ubt(i,j) = 0.0 ; uhbt(i,j) = 0.0 ; u\_accel\_bt(i,j) = 0.0}
\DoxyCodeLine{1166       ubt\_int(i,j) = 0.0 ; uhbt\_int(i,j) = 0.0}
\DoxyCodeLine{1167 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1168     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1169     \textcolor{keywordflow}{do} j=jsvf-\/2,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1170       vbt(i,j) = 0.0 ; vhbt(i,j) = 0.0 ; v\_accel\_bt(i,j) = 0.0}
\DoxyCodeLine{1171       vbt\_int(i,j) = 0.0 ; vhbt\_int(i,j) = 0.0}
\DoxyCodeLine{1172 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1173   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1174     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1175     \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/2,ievf+1}
\DoxyCodeLine{1176       ubt(i,j) = 0.0 ; uhbt(i,j) = 0.0 ; u\_accel\_bt(i,j) = 0.0}
\DoxyCodeLine{1177 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1178     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1179     \textcolor{keywordflow}{do} j=jsvf-\/2,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1180       vbt(i,j) = 0.0 ; vhbt(i,j) = 0.0 ; v\_accel\_bt(i,j) = 0.0}
\DoxyCodeLine{1181 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1182 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1183   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1184   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1185     ubt(i,j) = ubt(i,j) + wt\_u(i,j,k) * u\_in(i,j,k)}
\DoxyCodeLine{1186 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1187   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1188   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1189     vbt(i,j) = vbt(i,j) + wt\_v(i,j,k) * v\_in(i,j,k)}
\DoxyCodeLine{1190 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1191   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1192   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1193     \textcolor{keywordflow}{if} (abs(ubt(i,j)) < cs\%vel\_underflow) ubt(i,j) = 0.0}
\DoxyCodeLine{1194 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1195   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1196   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1197     \textcolor{keywordflow}{if} (abs(vbt(i,j)) < cs\%vel\_underflow) vbt(i,j) = 0.0}
\DoxyCodeLine{1198 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1199 }
\DoxyCodeLine{1200   \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1201     ubt\_first(:,:) = ubt(:,:) ; vbt\_first(:,:) = vbt(:,:)}
\DoxyCodeLine{1202 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1203 }
\DoxyCodeLine{1204 \textcolor{comment}{!   Here the vertical average accelerations due to the Coriolis, advective,}}
\DoxyCodeLine{1205 \textcolor{comment}{! pressure gradient and horizontal viscous terms in the layer momentum}}
\DoxyCodeLine{1206 \textcolor{comment}{! equations are calculated.  These will be used to determine the difference}}
\DoxyCodeLine{1207 \textcolor{comment}{! between the accelerations due to the average of the layer equations and the}}
\DoxyCodeLine{1208 \textcolor{comment}{! barotropic calculation.}}
\DoxyCodeLine{1209 }
\DoxyCodeLine{1210   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1211   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; \textcolor{keywordflow}{if} (g\%mask2dCu(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1212     \textcolor{keywordflow}{if} (cs\%nonlin\_stress) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1213       \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1214         htot\_avg = 0.5*(max(cs\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j), 0.0) + \&}
\DoxyCodeLine{1215                         max(cs\%bathyT(i+1,j)*gv\%Z\_to\_H + eta(i+1,j), 0.0))}
\DoxyCodeLine{1216       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1217         htot\_avg = 0.5*(eta(i,j) + eta(i+1,j))}
\DoxyCodeLine{1218 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1219       \textcolor{keywordflow}{if} (htot\_avg*cs\%dy\_Cu(i,j) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1220         cs\%IDatu(i,j) = 0.0}
\DoxyCodeLine{1221       \textcolor{keywordflow}{elseif} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1222         cs\%IDatu(i,j) = cs\%dy\_Cu(i,j) / (max(find\_duhbt\_du(ubt(i,j)*dt, btcl\_u(i,j)), \&}
\DoxyCodeLine{1223                                              cs\%dy\_Cu(i,j)*htot\_avg) )}
\DoxyCodeLine{1224       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then} \textcolor{comment}{! Reconsider the max and whether there should be some scaling.}}
\DoxyCodeLine{1225         cs\%IDatu(i,j) = cs\%dy\_Cu(i,j) / (max(find\_duhbt\_du(ubt(i,j), btcl\_u(i,j)), \&}
\DoxyCodeLine{1226                                              cs\%dy\_Cu(i,j)*htot\_avg) )}
\DoxyCodeLine{1227       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1228         cs\%IDatu(i,j) = 1.0 / htot\_avg}
\DoxyCodeLine{1229 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1230 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1231 }
\DoxyCodeLine{1232     bt\_force\_u(i,j) = forces\%taux(i,j) * mass\_accel\_to\_z * cs\%IDatu(i,j)*visc\_rem\_u(i,j,1)}
\DoxyCodeLine{1233   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1234     bt\_force\_u(i,j) = 0.0}
\DoxyCodeLine{1235 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1236   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1237   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dCv(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1238     \textcolor{keywordflow}{if} (cs\%nonlin\_stress) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1239       \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1240         htot\_avg = 0.5*(max(cs\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j), 0.0) + \&}
\DoxyCodeLine{1241                         max(cs\%bathyT(i,j+1)*gv\%Z\_to\_H + eta(i,j+1), 0.0))}
\DoxyCodeLine{1242       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1243         htot\_avg = 0.5*(eta(i,j) + eta(i,j+1))}
\DoxyCodeLine{1244 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1245       \textcolor{keywordflow}{if} (htot\_avg*cs\%dx\_Cv(i,j) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1246         cs\%IDatv(i,j) = 0.0}
\DoxyCodeLine{1247       \textcolor{keywordflow}{elseif} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1248         cs\%IDatv(i,j) = cs\%dx\_Cv(i,j) / (max(find\_dvhbt\_dv(vbt(i,j)*dt, btcl\_v(i,j)), \&}
\DoxyCodeLine{1249                                              cs\%dx\_Cv(i,j)*htot\_avg) )}
\DoxyCodeLine{1250       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then} \textcolor{comment}{! Reconsider the max and whether there should be some scaling.}}
\DoxyCodeLine{1251         cs\%IDatv(i,j) = cs\%dx\_Cv(i,j) / (max(find\_dvhbt\_dv(vbt(i,j), btcl\_v(i,j)), \&}
\DoxyCodeLine{1252                                              cs\%dx\_Cv(i,j)*htot\_avg) )}
\DoxyCodeLine{1253       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1254         cs\%IDatv(i,j) = 1.0 / htot\_avg}
\DoxyCodeLine{1255 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1256 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1257 }
\DoxyCodeLine{1258     bt\_force\_v(i,j) = forces\%tauy(i,j) * mass\_accel\_to\_z * cs\%IDatv(i,j)*visc\_rem\_v(i,j,1)}
\DoxyCodeLine{1259   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1260     bt\_force\_v(i,j) = 0.0}
\DoxyCodeLine{1261 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1262   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(taux\_bot) .and. \textcolor{keyword}{present}(tauy\_bot)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1263     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(taux\_bot) .and. \textcolor{keyword}{associated}(tauy\_bot)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1264       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1265       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; \textcolor{keywordflow}{if} (g\%mask2dCu(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1266         bt\_force\_u(i,j) = bt\_force\_u(i,j) -\/ taux\_bot(i,j) * mass\_to\_z  * cs\%IDatu(i,j)}
\DoxyCodeLine{1267 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1268       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1269       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dCv(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1270         bt\_force\_v(i,j) = bt\_force\_v(i,j) -\/ tauy\_bot(i,j) * mass\_to\_z  * cs\%IDatv(i,j)}
\DoxyCodeLine{1271 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1272 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1273 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1274 }
\DoxyCodeLine{1275   \textcolor{comment}{! bc\_accel\_u \& bc\_accel\_v are only available on the potentially}}
\DoxyCodeLine{1276   \textcolor{comment}{! non-\/symmetric computational domain.}}
\DoxyCodeLine{1277   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1278   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{1279     bt\_force\_u(i,j) = bt\_force\_u(i,j) + wt\_u(i,j,k) * bc\_accel\_u(i,j,k)}
\DoxyCodeLine{1280 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1281   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1282   \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1283     bt\_force\_v(i,j) = bt\_force\_v(i,j) + wt\_v(i,j,k) * bc\_accel\_v(i,j,k)}
\DoxyCodeLine{1284 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1285 }
\DoxyCodeLine{1286   \textcolor{keywordflow}{if} (cs\%gradual\_BT\_ICs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1287     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1288     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1289       bt\_force\_u(i,j) = bt\_force\_u(i,j) + (ubt(i,j) -\/ cs\%ubt\_IC(i,j)) * idt}
\DoxyCodeLine{1290       ubt(i,j) = cs\%ubt\_IC(i,j)}
\DoxyCodeLine{1291       \textcolor{keywordflow}{if} (abs(ubt(i,j)) < cs\%vel\_underflow) ubt(i,j) = 0.0}
\DoxyCodeLine{1292 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1293     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1294     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1295       bt\_force\_v(i,j) = bt\_force\_v(i,j) + (vbt(i,j) -\/ cs\%vbt\_IC(i,j)) * idt}
\DoxyCodeLine{1296       vbt(i,j) = cs\%vbt\_IC(i,j)}
\DoxyCodeLine{1297       \textcolor{keywordflow}{if} (abs(vbt(i,j)) < cs\%vel\_underflow) vbt(i,j) = 0.0}
\DoxyCodeLine{1298 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1299 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1300 }
\DoxyCodeLine{1301   \textcolor{keywordflow}{if} ((isq > is-\/1) .or. (jsq > js-\/1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1302     \textcolor{comment}{! Non-\/symmetric memory is being used, so the edge values need to be}}
\DoxyCodeLine{1303     \textcolor{comment}{! filled in with a halo update of a non-\/symmetric array.}}
\DoxyCodeLine{1304     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1305     \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{1306     tmp\_u(:,:) = 0.0 ; tmp\_v(:,:) = 0.0}
\DoxyCodeLine{1307     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq ; tmp\_u(i,j) = bt\_force\_u(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1308     \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie ; tmp\_v(i,j) = bt\_force\_v(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1309     \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1310       \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_tmp\_uv, g\%Domain)}
\DoxyCodeLine{1311     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1312       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_tmp\_uv, g\%Domain)}
\DoxyCodeLine{1313       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb ; bt\_force\_u(i,j) = tmp\_u(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1314       \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied ; bt\_force\_v(i,j) = tmp\_v(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1315 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1316     \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{1317     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1318 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1319 }
\DoxyCodeLine{1320   \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1321     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1322     \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{1323     \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_gtot, cs\%BT\_Domain)}
\DoxyCodeLine{1324     \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_ubt\_Cor, g\%Domain)}
\DoxyCodeLine{1325     \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{1326     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1327 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1328 }
\DoxyCodeLine{1329   \textcolor{comment}{! Determine the weighted Coriolis parameters for the neighboring velocities.}}
\DoxyCodeLine{1330   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1331   \textcolor{keywordflow}{do} j=jsvf-\/1,jevf ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1332     \textcolor{keywordflow}{if} (cs\%Sadourny) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1333       amer(i-\/1,j) = dcor\_u(i-\/1,j) * q(i-\/1,j)}
\DoxyCodeLine{1334       bmer(i,j) = dcor\_u(i,j) * q(i,j)}
\DoxyCodeLine{1335       cmer(i,j+1) = dcor\_u(i,j+1) * q(i,j)}
\DoxyCodeLine{1336       dmer(i-\/1,j+1) = dcor\_u(i-\/1,j+1) * q(i-\/1,j)}
\DoxyCodeLine{1337     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1338       amer(i-\/1,j) = dcor\_u(i-\/1,j) * \&}
\DoxyCodeLine{1339                     ((q(i,j) + q(i-\/1,j-\/1)) + q(i-\/1,j)) / 3.0}
\DoxyCodeLine{1340       bmer(i,j) = dcor\_u(i,j) * \&}
\DoxyCodeLine{1341                   (q(i,j) + (q(i-\/1,j) + q(i,j-\/1))) / 3.0}
\DoxyCodeLine{1342       cmer(i,j+1) = dcor\_u(i,j+1) * \&}
\DoxyCodeLine{1343                     (q(i,j) + (q(i-\/1,j) + q(i,j+1))) / 3.0}
\DoxyCodeLine{1344       dmer(i-\/1,j+1) = dcor\_u(i-\/1,j+1) * \&}
\DoxyCodeLine{1345                       ((q(i,j) + q(i-\/1,j+1)) + q(i-\/1,j)) / 3.0}
\DoxyCodeLine{1346 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1347 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1348 }
\DoxyCodeLine{1349   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1350   \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf}
\DoxyCodeLine{1351     \textcolor{keywordflow}{if} (cs\%Sadourny) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1352       azon(i,j) = dcor\_v(i+1,j) * q(i,j)}
\DoxyCodeLine{1353       bzon(i,j) = dcor\_v(i,j) * q(i,j)}
\DoxyCodeLine{1354       czon(i,j) = dcor\_v(i,j-\/1) * q(i,j-\/1)}
\DoxyCodeLine{1355       dzon(i,j) = dcor\_v(i+1,j-\/1) * q(i,j-\/1)}
\DoxyCodeLine{1356     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1357       azon(i,j) = dcor\_v(i+1,j) * \&}
\DoxyCodeLine{1358                   (q(i,j) + (q(i+1,j) + q(i,j-\/1))) / 3.0}
\DoxyCodeLine{1359       bzon(i,j) = dcor\_v(i,j) * \&}
\DoxyCodeLine{1360                   (q(i,j) + (q(i-\/1,j) + q(i,j-\/1))) / 3.0}
\DoxyCodeLine{1361       czon(i,j) = dcor\_v(i,j-\/1) * \&}
\DoxyCodeLine{1362                   ((q(i,j) + q(i-\/1,j-\/1)) + q(i,j-\/1)) / 3.0}
\DoxyCodeLine{1363       dzon(i,j) = dcor\_v(i+1,j-\/1) * \&}
\DoxyCodeLine{1364                   ((q(i,j) + q(i+1,j-\/1)) + q(i,j-\/1)) / 3.0}
\DoxyCodeLine{1365 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1366 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1367 }
\DoxyCodeLine{1368 \textcolor{comment}{! Complete the previously initiated message passing.}}
\DoxyCodeLine{1369   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1370   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{1371   \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1372     \textcolor{keywordflow}{if} ((isq > is-\/1) .or. (jsq > js-\/1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1373       \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_tmp\_uv, g\%Domain)}
\DoxyCodeLine{1374       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb ; bt\_force\_u(i,j) = tmp\_u(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1375       \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied ; bt\_force\_v(i,j) = tmp\_v(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1376 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1377     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_gtot, cs\%BT\_Domain)}
\DoxyCodeLine{1378     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_ubt\_Cor, g\%Domain)}
\DoxyCodeLine{1379   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1380     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_gtot, cs\%BT\_Domain)}
\DoxyCodeLine{1381     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_ubt\_Cor, g\%Domain)}
\DoxyCodeLine{1382 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1383   \textcolor{comment}{! The various elements of gtot are positive definite but directional, so use}}
\DoxyCodeLine{1384   \textcolor{comment}{! the polarity arrays to sort out when the directions have shifted.}}
\DoxyCodeLine{1385   \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1386     \textcolor{keywordflow}{if} (cs\%ua\_polarity(i,j) < 0.0) \textcolor{keyword}{call }swap(gtot\_e(i,j), gtot\_w(i,j))}
\DoxyCodeLine{1387     \textcolor{keywordflow}{if} (cs\%va\_polarity(i,j) < 0.0) \textcolor{keyword}{call }swap(gtot\_n(i,j), gtot\_s(i,j))}
\DoxyCodeLine{1388 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1389 }
\DoxyCodeLine{1390   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1391   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1392     cor\_ref\_u(i,j) =  \&}
\DoxyCodeLine{1393         ((azon(i,j) * vbt\_cor(i+1,j) + czon(i,j) * vbt\_cor(i  ,j-\/1)) + \&}
\DoxyCodeLine{1394          (bzon(i,j) * vbt\_cor(i  ,j) + dzon(i,j) * vbt\_cor(i+1,j-\/1)))}
\DoxyCodeLine{1395 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1396   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1397   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1398     cor\_ref\_v(i,j) = -\/1.0 * \&}
\DoxyCodeLine{1399         ((amer(i-\/1,j) * ubt\_cor(i-\/1,j) + cmer(i  ,j+1) * ubt\_cor(i  ,j+1)) + \&}
\DoxyCodeLine{1400          (bmer(i  ,j) * ubt\_cor(i  ,j) + dmer(i-\/1,j+1) * ubt\_cor(i-\/1,j+1)))}
\DoxyCodeLine{1401 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1402 }
\DoxyCodeLine{1403   \textcolor{comment}{! Now start new halo updates.}}
\DoxyCodeLine{1404   \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1405     \textcolor{keywordflow}{if} (.not.use\_bt\_cont) \&}
\DoxyCodeLine{1406       \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_Dat\_uv, cs\%BT\_Domain)}
\DoxyCodeLine{1407 }
\DoxyCodeLine{1408     \textcolor{comment}{! The following halo update is not needed without wide halos.  RWH}}
\DoxyCodeLine{1409     \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_force\_hbt0\_Cor\_ref, cs\%BT\_Domain)}
\DoxyCodeLine{1410 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1411   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{1412   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1413   \textcolor{comment}{!\$OMP parallel default(shared) private(u\_max\_cor,uint\_cor,v\_max\_cor,vint\_cor,eta\_cor\_max,Htot)}}
\DoxyCodeLine{1414   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1415   \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie ; av\_rem\_u(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1416   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1417   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie+1 ; av\_rem\_v(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1418   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1419   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1420     av\_rem\_u(i,j) = av\_rem\_u(i,j) + cs\%frhatu(i,j,k) * visc\_rem\_u(i,j,k)}
\DoxyCodeLine{1421 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1422   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1423   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1424     av\_rem\_v(i,j) = av\_rem\_v(i,j) + cs\%frhatv(i,j,k) * visc\_rem\_v(i,j,k)}
\DoxyCodeLine{1425 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1426   \textcolor{keywordflow}{if} (cs\%strong\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1427     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1428     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1429       bt\_rem\_u(i,j) = g\%mask2dCu(i,j) * \&}
\DoxyCodeLine{1430          ((nstep * av\_rem\_u(i,j)) / (1.0 + (nstep-\/1)*av\_rem\_u(i,j)))}
\DoxyCodeLine{1431 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1432     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1433     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1434       bt\_rem\_v(i,j) = g\%mask2dCv(i,j) * \&}
\DoxyCodeLine{1435          ((nstep * av\_rem\_v(i,j)) / (1.0 + (nstep-\/1)*av\_rem\_v(i,j)))}
\DoxyCodeLine{1436 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1437   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1438     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1439     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1440       bt\_rem\_u(i,j) = 0.0}
\DoxyCodeLine{1441       \textcolor{keywordflow}{if} (g\%mask2dCu(i,j) * av\_rem\_u(i,j) > 0.0) \&}
\DoxyCodeLine{1442         bt\_rem\_u(i,j) = g\%mask2dCu(i,j) * (av\_rem\_u(i,j)**instep)}
\DoxyCodeLine{1443 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1444     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1445     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1446       bt\_rem\_v(i,j) = 0.0}
\DoxyCodeLine{1447       \textcolor{keywordflow}{if} (g\%mask2dCv(i,j) * av\_rem\_v(i,j) > 0.0) \&}
\DoxyCodeLine{1448         bt\_rem\_v(i,j) = g\%mask2dCv(i,j) * (av\_rem\_v(i,j)**instep)}
\DoxyCodeLine{1449 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1450 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1451   \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1452     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1453     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; \textcolor{keywordflow}{if} (cs\%lin\_drag\_u(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1454       htot = 0.5 * (eta(i,j) + eta(i+1,j))}
\DoxyCodeLine{1455       \textcolor{keywordflow}{if} (gv\%Boussinesq) \&}
\DoxyCodeLine{1456         htot = htot + 0.5*gv\%Z\_to\_H * (cs\%bathyT(i,j) + cs\%bathyT(i+1,j))}
\DoxyCodeLine{1457       bt\_rem\_u(i,j) = bt\_rem\_u(i,j) * (htot / (htot + cs\%lin\_drag\_u(i,j) * dtbt))}
\DoxyCodeLine{1458 }
\DoxyCodeLine{1459       rayleigh\_u(i,j) = cs\%lin\_drag\_u(i,j) / htot}
\DoxyCodeLine{1460 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1461     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1462     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (cs\%lin\_drag\_v(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1463       htot = 0.5 * (eta(i,j) + eta(i,j+1))}
\DoxyCodeLine{1464       \textcolor{keywordflow}{if} (gv\%Boussinesq) \&}
\DoxyCodeLine{1465         htot = htot + 0.5*gv\%Z\_to\_H * (cs\%bathyT(i,j) + cs\%bathyT(i+1,j+1))}
\DoxyCodeLine{1466       bt\_rem\_v(i,j) = bt\_rem\_v(i,j) * (htot / (htot + cs\%lin\_drag\_v(i,j) * dtbt))}
\DoxyCodeLine{1467 }
\DoxyCodeLine{1468       rayleigh\_v(i,j) = cs\%lin\_drag\_v(i,j) / htot}
\DoxyCodeLine{1469 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1470 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1471 }
\DoxyCodeLine{1472   \textcolor{comment}{! Zero out the arrays for various time-\/averaged quantities.}}
\DoxyCodeLine{1473   \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1474     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1475     \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1476       eta\_sum(i,j) = 0.0 ; eta\_wtd(i,j) = 0.0}
\DoxyCodeLine{1477 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1478   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1479     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1480     \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1481       eta\_wtd(i,j) = 0.0}
\DoxyCodeLine{1482 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1483 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1484   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1485   \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1 ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf}
\DoxyCodeLine{1486     ubt\_sum(i,j) = 0.0 ; uhbt\_sum(i,j) = 0.0}
\DoxyCodeLine{1487     pfu\_bt\_sum(i,j) = 0.0 ; coru\_bt\_sum(i,j) = 0.0}
\DoxyCodeLine{1488     ubt\_wtd(i,j) = 0.0 ; ubt\_trans(i,j) = 0.0}
\DoxyCodeLine{1489 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1490   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1491   \textcolor{keywordflow}{do} j=jsvf-\/1,jevf ; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1}
\DoxyCodeLine{1492     vbt\_sum(i,j) = 0.0 ; vhbt\_sum(i,j) = 0.0}
\DoxyCodeLine{1493     pfv\_bt\_sum(i,j) = 0.0 ; corv\_bt\_sum(i,j) = 0.0}
\DoxyCodeLine{1494     vbt\_wtd(i,j) = 0.0 ; vbt\_trans(i,j) = 0.0}
\DoxyCodeLine{1495 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1496 }
\DoxyCodeLine{1497   \textcolor{comment}{! Set the mass source, after first initializing the halos to 0.}}
\DoxyCodeLine{1498   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1499   \textcolor{keywordflow}{do} j=jsvf-\/1,jevf+1; \textcolor{keywordflow}{do} i=isvf-\/1,ievf+1 ; eta\_src(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1500   \textcolor{keywordflow}{if} (cs\%bound\_BT\_corr) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} ((use\_bt\_cont.or.integral\_bt\_cont) .and. cs\%BT\_cont\_bounds) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1501     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1502       \textcolor{keywordflow}{if} (cs\%eta\_cor(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1503         \textcolor{comment}{!   Limit the source (outward) correction to be a fraction the mass that}}
\DoxyCodeLine{1504         \textcolor{comment}{! can be transported out of the cell by velocities with a CFL number of CFL\_cor.}}
\DoxyCodeLine{1505         \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1506           uint\_cor = g\%dxT(i,j) * cs\%maxCFL\_BT\_cont}
\DoxyCodeLine{1507           vint\_cor = g\%dyT(i,j) * cs\%maxCFL\_BT\_cont}
\DoxyCodeLine{1508           eta\_cor\_max = (cs\%IareaT(i,j) * \&}
\DoxyCodeLine{1509                    (((find\_uhbt(uint\_cor, btcl\_u(i,j)) + dt*uhbt0(i,j)) -\/ \&}
\DoxyCodeLine{1510                      (find\_uhbt(-\/uint\_cor, btcl\_u(i-\/1,j)) + dt*uhbt0(i-\/1,j))) + \&}
\DoxyCodeLine{1511                     ((find\_vhbt(vint\_cor, btcl\_v(i,j)) + dt*vhbt0(i,j)) -\/ \&}
\DoxyCodeLine{1512                      (find\_vhbt(-\/vint\_cor, btcl\_v(i,j-\/1)) + dt*vhbt0(i,j-\/1))) ))}
\DoxyCodeLine{1513         \textcolor{keywordflow}{else} \textcolor{comment}{! (use\_BT\_Cont) then}}
\DoxyCodeLine{1514           u\_max\_cor = g\%dxT(i,j) * (cs\%maxCFL\_BT\_cont*idt)}
\DoxyCodeLine{1515           v\_max\_cor = g\%dyT(i,j) * (cs\%maxCFL\_BT\_cont*idt)}
\DoxyCodeLine{1516           eta\_cor\_max = dt * (cs\%IareaT(i,j) * \&}
\DoxyCodeLine{1517                    (((find\_uhbt(u\_max\_cor, btcl\_u(i,j)) + uhbt0(i,j)) -\/ \&}
\DoxyCodeLine{1518                      (find\_uhbt(-\/u\_max\_cor, btcl\_u(i-\/1,j)) + uhbt0(i-\/1,j))) + \&}
\DoxyCodeLine{1519                     ((find\_vhbt(v\_max\_cor, btcl\_v(i,j)) + vhbt0(i,j)) -\/ \&}
\DoxyCodeLine{1520                      (find\_vhbt(-\/v\_max\_cor, btcl\_v(i,j-\/1)) + vhbt0(i,j-\/1))) ))}
\DoxyCodeLine{1521 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1522         cs\%eta\_cor(i,j) = min(cs\%eta\_cor(i,j), max(0.0, eta\_cor\_max))}
\DoxyCodeLine{1523       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1524         \textcolor{comment}{! Limit the sink (inward) correction to the amount of mass that is already inside the cell.}}
\DoxyCodeLine{1525         htot = eta(i,j)}
\DoxyCodeLine{1526         \textcolor{keywordflow}{if} (gv\%Boussinesq) htot = cs\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j)}
\DoxyCodeLine{1527 }
\DoxyCodeLine{1528         cs\%eta\_cor(i,j) = max(cs\%eta\_cor(i,j), -\/max(0.0,htot))}
\DoxyCodeLine{1529 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1530 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1531   \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1532     \textcolor{keywordflow}{if} (abs(cs\%eta\_cor(i,j)) > dt*cs\%eta\_cor\_bound(i,j)) \&}
\DoxyCodeLine{1533       cs\%eta\_cor(i,j) = sign(dt*cs\%eta\_cor\_bound(i,j), cs\%eta\_cor(i,j))}
\DoxyCodeLine{1534 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1535   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1536   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1537     eta\_src(i,j) = g\%mask2dT(i,j) * (instep * cs\%eta\_cor(i,j))}
\DoxyCodeLine{1538 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1539 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{1540 }
\DoxyCodeLine{1541   \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1542     ice\_is\_rigid = (\textcolor{keyword}{associated}(forces\%rigidity\_ice\_u) .and. \&}
\DoxyCodeLine{1543                     \textcolor{keyword}{associated}(forces\%rigidity\_ice\_v))}
\DoxyCodeLine{1544     h\_min\_dyn = gv\%Z\_to\_H * cs\%Dmin\_dyn\_psurf}
\DoxyCodeLine{1545     \textcolor{keywordflow}{if} (ice\_is\_rigid .and. use\_bt\_cont) \&}
\DoxyCodeLine{1546       \textcolor{keyword}{call }bt\_cont\_to\_face\_areas(bt\_cont, datu, datv, g, us, ms, 0, .true.)}
\DoxyCodeLine{1547     \textcolor{keywordflow}{if} (ice\_is\_rigid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1548       \textcolor{comment}{!\$OMP parallel do default(shared) private(Idt\_max2,H\_eff\_dx2,dyn\_coef\_max,ice\_strength)}}
\DoxyCodeLine{1549       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1550       \textcolor{comment}{! First determine the maximum stable value for dyn\_coef\_eta.}}
\DoxyCodeLine{1551 }
\DoxyCodeLine{1552       \textcolor{comment}{!   This estimate of the maximum stable time step is pretty accurate for}}
\DoxyCodeLine{1553       \textcolor{comment}{! gravity waves, but it is a conservative estimate since it ignores the}}
\DoxyCodeLine{1554       \textcolor{comment}{! stabilizing effect of the bottom drag.}}
\DoxyCodeLine{1555       idt\_max2 = 0.5 * (dgeo\_de * (1.0 + 2.0*bebt)) * (g\%IareaT(i,j) * \&}
\DoxyCodeLine{1556             ((gtot\_e(i,j) * (datu(i,j)*g\%IdxCu(i,j)) + \&}
\DoxyCodeLine{1557               gtot\_w(i,j) * (datu(i-\/1,j)*g\%IdxCu(i-\/1,j))) + \&}
\DoxyCodeLine{1558              (gtot\_n(i,j) * (datv(i,j)*g\%IdyCv(i,j)) + \&}
\DoxyCodeLine{1559               gtot\_s(i,j) * (datv(i,j-\/1)*g\%IdyCv(i,j-\/1)))) + \&}
\DoxyCodeLine{1560             ((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-\/1,j-\/1)**2) + \&}
\DoxyCodeLine{1561              (g\%CoriolisBu(i-\/1,j)**2 + g\%CoriolisBu(i,j-\/1)**2)) * cs\%BT\_Coriolis\_scale**2 )}
\DoxyCodeLine{1562       h\_eff\_dx2 = max(h\_min\_dyn * ((g\%IdxT(i,j))**2 + (g\%IdyT(i,j))**2), \&}
\DoxyCodeLine{1563                       g\%IareaT(i,j) * \&}
\DoxyCodeLine{1564                         ((datu(i,j)*g\%IdxCu(i,j) + datu(i-\/1,j)*g\%IdxCu(i-\/1,j)) + \&}
\DoxyCodeLine{1565                          (datv(i,j)*g\%IdyCv(i,j) + datv(i,j-\/1)*g\%IdyCv(i,j-\/1)) ) )}
\DoxyCodeLine{1566       dyn\_coef\_max = cs\%const\_dyn\_psurf * max(0.0, 1.0 -\/ dtbt**2 * idt\_max2) / \&}
\DoxyCodeLine{1567                      (dtbt**2 * h\_eff\_dx2)}
\DoxyCodeLine{1568 }
\DoxyCodeLine{1569       \textcolor{comment}{! ice\_strength has units of [L2 Z-\/1 T-\/2 \string~> m s-\/2]. rigidity\_ice\_[uv] has units of [L4 Z-\/1 T-\/1 \string~> m3 s-\/1].}}
\DoxyCodeLine{1570       ice\_strength = ((forces\%rigidity\_ice\_u(i,j) + forces\%rigidity\_ice\_u(i-\/1,j)) + \&}
\DoxyCodeLine{1571                       (forces\%rigidity\_ice\_v(i,j) + forces\%rigidity\_ice\_v(i,j-\/1))) / \&}
\DoxyCodeLine{1572                       (cs\%ice\_strength\_length**2 * dtbt)}
\DoxyCodeLine{1573 }
\DoxyCodeLine{1574       \textcolor{comment}{! Units of dyn\_coef: [L2 T-\/2 H-\/1 \string~> m s-\/2 or m4 s-\/2 kg-\/1]}}
\DoxyCodeLine{1575       dyn\_coef\_eta(i,j) = min(dyn\_coef\_max, ice\_strength * gv\%H\_to\_Z)}
\DoxyCodeLine{1576 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1577 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1578 }
\DoxyCodeLine{1579   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1580   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{1581   \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1582     \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_eta\_bt\_rem, cs\%BT\_Domain)}
\DoxyCodeLine{1583     \textcolor{comment}{! The following halo update is not needed without wide halos.  RWH}}
\DoxyCodeLine{1584   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1585     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_eta\_bt\_rem, cs\%BT\_Domain)}
\DoxyCodeLine{1586     \textcolor{keywordflow}{if} (.not.use\_bt\_cont) \&}
\DoxyCodeLine{1587       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_Dat\_uv, cs\%BT\_Domain)}
\DoxyCodeLine{1588     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_force\_hbt0\_Cor\_ref, cs\%BT\_Domain)}
\DoxyCodeLine{1589 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1590   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{1591   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1592 }
\DoxyCodeLine{1593   \textcolor{comment}{! Complete all of the outstanding halo updates.}}
\DoxyCodeLine{1594   \textcolor{keywordflow}{if} (nonblock\_setup) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1595     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1596     \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{1597 }
\DoxyCodeLine{1598     \textcolor{keywordflow}{if} (.not.use\_bt\_cont) \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_Dat\_uv, cs\%BT\_Domain)}
\DoxyCodeLine{1599     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_force\_hbt0\_Cor\_ref, cs\%BT\_Domain)}
\DoxyCodeLine{1600     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_eta\_bt\_rem, cs\%BT\_Domain)}
\DoxyCodeLine{1601 }
\DoxyCodeLine{1602     \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{1603     \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{1604 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1605 }
\DoxyCodeLine{1606   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1607     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT [uv]hbt"{}}, uhbt, vhbt, cs\%debug\_BT\_HI, haloshift=0, \&}
\DoxyCodeLine{1608                   scale=us\%s\_to\_T*us\%L\_to\_m**2*gv\%H\_to\_m)}
\DoxyCodeLine{1609     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT Initial [uv]bt"{}}, ubt, vbt, cs\%debug\_BT\_HI, haloshift=0, scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{1610     \textcolor{keyword}{call }hchksum(eta, \textcolor{stringliteral}{"{}BT Initial eta"{}}, cs\%debug\_BT\_HI, haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1611     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT BT\_force\_[uv]"{}}, bt\_force\_u, bt\_force\_v, \&}
\DoxyCodeLine{1612                   cs\%debug\_BT\_HI, haloshift=0, scale=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{1613     \textcolor{keywordflow}{if} (interp\_eta\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1614       \textcolor{keyword}{call }hchksum(eta\_pf\_1, \textcolor{stringliteral}{"{}BT eta\_PF\_1"{}},cs\%debug\_BT\_HI,haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1615       \textcolor{keyword}{call }hchksum(d\_eta\_pf, \textcolor{stringliteral}{"{}BT d\_eta\_PF"{}},cs\%debug\_BT\_HI,haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1616     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1617       \textcolor{keyword}{call }hchksum(eta\_pf, \textcolor{stringliteral}{"{}BT eta\_PF"{}},cs\%debug\_BT\_HI,haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1618       \textcolor{keyword}{call }hchksum(eta\_pf\_in, \textcolor{stringliteral}{"{}BT eta\_PF\_in"{}},g\%HI,haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1619 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1620     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT Cor\_ref\_[uv]"{}}, cor\_ref\_u, cor\_ref\_v, cs\%debug\_BT\_HI, haloshift=0, scale=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{1621     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT [uv]hbt0"{}}, uhbt0, vhbt0, cs\%debug\_BT\_HI, haloshift=0, \&}
\DoxyCodeLine{1622                   scale=us\%L\_to\_m**2*us\%s\_to\_T*gv\%H\_to\_m)}
\DoxyCodeLine{1623     \textcolor{keywordflow}{if} (.not. use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1624       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT Dat[uv]"{}}, datu, datv, cs\%debug\_BT\_HI, haloshift=1, scale=us\%L\_to\_m*gv\%H\_to\_m)}
\DoxyCodeLine{1625 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1626     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT wt\_[uv]"{}}, wt\_u, wt\_v, g\%HI, haloshift=0, \&}
\DoxyCodeLine{1627                   symmetric=.true., omit\_corners=.true., scalar\_pair=.true.)}
\DoxyCodeLine{1628     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT frhat[uv]"{}}, cs\%frhatu, cs\%frhatv, g\%HI, haloshift=0, \&}
\DoxyCodeLine{1629                   symmetric=.true., omit\_corners=.true., scalar\_pair=.true.)}
\DoxyCodeLine{1630     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT bc\_accel\_[uv]"{}}, bc\_accel\_u, bc\_accel\_v, g\%HI, haloshift=0, scale=us\%L\_T2\_to\_m\_s2)}
\DoxyCodeLine{1631     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT IDat[uv]"{}}, cs\%IDatu, cs\%IDatv, g\%HI, haloshift=0, \&}
\DoxyCodeLine{1632                   scale=us\%m\_to\_Z, scalar\_pair=.true.)}
\DoxyCodeLine{1633     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT visc\_rem\_[uv]"{}}, visc\_rem\_u, visc\_rem\_v, g\%HI, \&}
\DoxyCodeLine{1634                   haloshift=1, scalar\_pair=.true.)}
\DoxyCodeLine{1635 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1636 }
\DoxyCodeLine{1637   \textcolor{keywordflow}{if} (cs\%id\_ubtdt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1638     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{1639       ubt\_st(i,j) = ubt(i,j)}
\DoxyCodeLine{1640 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1641 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1642   \textcolor{keywordflow}{if} (cs\%id\_vbtdt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1643     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{1644       vbt\_st(i,j) = vbt(i,j)}
\DoxyCodeLine{1645 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1646 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1647 }
\DoxyCodeLine{1648   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1649     \textcolor{keywordflow}{if} (cs\%id\_eta\_st > 0) \textcolor{keyword}{call }post\_data(cs\%id\_eta\_st, eta(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{1650     \textcolor{keywordflow}{if} (cs\%id\_ubt\_st > 0) \textcolor{keyword}{call }post\_data(cs\%id\_ubt\_st, ubt(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{1651     \textcolor{keywordflow}{if} (cs\%id\_vbt\_st > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vbt\_st, vbt(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{1652 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1653 }
\DoxyCodeLine{1654   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{1655   \textcolor{keywordflow}{if} (id\_clock\_calc > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc)}
\DoxyCodeLine{1656 }
\DoxyCodeLine{1657   \textcolor{keywordflow}{if} (project\_velocity) \textcolor{keywordflow}{then} ; eta\_pf\_bt => eta ; \textcolor{keywordflow}{else} ; eta\_pf\_bt => eta\_pred ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1658 }
\DoxyCodeLine{1659   \textcolor{keywordflow}{if} (cs\%dt\_bt\_filter >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1660     dt\_filt = 0.5 * max(0.0, min(cs\%dt\_bt\_filter, 2.0*dt))}
\DoxyCodeLine{1661   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1662     dt\_filt = 0.5 * max(0.0, dt * min(-\/cs\%dt\_bt\_filter, 2.0))}
\DoxyCodeLine{1663 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1664   nfilter = ceiling(dt\_filt / dtbt)}
\DoxyCodeLine{1665 }
\DoxyCodeLine{1666   \textcolor{keywordflow}{if} (nstep+nfilter==0 ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1667       \textcolor{stringliteral}{"{}btstep: number of barotropic step (nstep+nfilter) is 0"{}})}
\DoxyCodeLine{1668 }
\DoxyCodeLine{1669   \textcolor{comment}{! Set up the normalized weights for the filtered velocity.}}
\DoxyCodeLine{1670   sum\_wt\_vel = 0.0 ; sum\_wt\_eta = 0.0 ; sum\_wt\_accel = 0.0 ; sum\_wt\_trans = 0.0}
\DoxyCodeLine{1671   \textcolor{keyword}{allocate}(wt\_vel(nstep+nfilter)) ; \textcolor{keyword}{allocate}(wt\_eta(nstep+nfilter))}
\DoxyCodeLine{1672   \textcolor{keyword}{allocate}(wt\_trans(nstep+nfilter+1)) ; \textcolor{keyword}{allocate}(wt\_accel(nstep+nfilter+1))}
\DoxyCodeLine{1673   \textcolor{keyword}{allocate}(wt\_accel2(nstep+nfilter+1))}
\DoxyCodeLine{1674   \textcolor{keywordflow}{do} n=1,nstep+nfilter}
\DoxyCodeLine{1675     \textcolor{comment}{! Modify this to use a different filter...}}
\DoxyCodeLine{1676 }
\DoxyCodeLine{1677     \textcolor{comment}{! This is a filter that ramps down linearly over a time dt\_filt.}}
\DoxyCodeLine{1678     \textcolor{keywordflow}{if} ( (n==nstep) .or. (dt\_filt -\/ abs(n-\/nstep)*dtbt >= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1679       wt\_vel(n) = 1.0  ; wt\_eta(n) = 1.0}
\DoxyCodeLine{1680     \textcolor{keywordflow}{elseif} (dtbt + dt\_filt -\/ abs(n-\/nstep)*dtbt > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1681       wt\_vel(n) = 1.0 + (dt\_filt / dtbt) -\/ abs(n-\/nstep) ; wt\_eta(n) = wt\_vel(n)}
\DoxyCodeLine{1682     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1683       wt\_vel(n) = 0.0  ; wt\_eta(n) = 0.0}
\DoxyCodeLine{1684 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1685     \textcolor{comment}{! This is a simple stepfunction filter.}}
\DoxyCodeLine{1686     \textcolor{comment}{! if (n < nstep-\/nfilter) then ; wt\_vel(n) = 0.0 ; else ; wt\_vel(n) = 1.0 ; endif}}
\DoxyCodeLine{1687     \textcolor{comment}{! wt\_eta(n) = wt\_vel(n)}}
\DoxyCodeLine{1688 }
\DoxyCodeLine{1689     \textcolor{comment}{! The rest should not be changed.}}
\DoxyCodeLine{1690     sum\_wt\_vel = sum\_wt\_vel + wt\_vel(n) ; sum\_wt\_eta = sum\_wt\_eta + wt\_eta(n)}
\DoxyCodeLine{1691 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1692   wt\_trans(nstep+nfilter+1) = 0.0 ; wt\_accel(nstep+nfilter+1) = 0.0}
\DoxyCodeLine{1693   \textcolor{keywordflow}{do} n=nstep+nfilter,1,-\/1}
\DoxyCodeLine{1694     wt\_trans(n) = wt\_trans(n+1) + wt\_eta(n)}
\DoxyCodeLine{1695     wt\_accel(n) = wt\_accel(n+1) + wt\_vel(n)}
\DoxyCodeLine{1696     sum\_wt\_accel = sum\_wt\_accel + wt\_accel(n) ; sum\_wt\_trans = sum\_wt\_trans + wt\_trans(n)}
\DoxyCodeLine{1697 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1698   \textcolor{comment}{! Normalize the weights.}}
\DoxyCodeLine{1699   i\_sum\_wt\_vel = 1.0 / sum\_wt\_vel ; i\_sum\_wt\_accel = 1.0 / sum\_wt\_accel}
\DoxyCodeLine{1700   i\_sum\_wt\_eta = 1.0 / sum\_wt\_eta ; i\_sum\_wt\_trans = 1.0 / sum\_wt\_trans}
\DoxyCodeLine{1701   \textcolor{keywordflow}{do} n=1,nstep+nfilter}
\DoxyCodeLine{1702     wt\_vel(n) = wt\_vel(n) * i\_sum\_wt\_vel}
\DoxyCodeLine{1703     \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1704       wt\_accel2(n) = wt\_accel(n)}
\DoxyCodeLine{1705      \textcolor{comment}{! wt\_trans(n) = wt\_trans(n) * I\_sum\_wt\_trans}}
\DoxyCodeLine{1706     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1707       wt\_accel2(n) = wt\_accel(n) * i\_sum\_wt\_accel}
\DoxyCodeLine{1708       wt\_trans(n) = wt\_trans(n) * i\_sum\_wt\_trans}
\DoxyCodeLine{1709 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1710     wt\_accel(n) = wt\_accel(n) * i\_sum\_wt\_accel}
\DoxyCodeLine{1711     wt\_eta(n) = wt\_eta(n) * i\_sum\_wt\_eta}
\DoxyCodeLine{1712 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1713 }
\DoxyCodeLine{1714   sum\_wt\_vel = 0.0 ; sum\_wt\_eta = 0.0 ; sum\_wt\_accel = 0.0 ; sum\_wt\_trans = 0.0}
\DoxyCodeLine{1715 }
\DoxyCodeLine{1716   \textcolor{comment}{! The following loop contains all of the time steps.}}
\DoxyCodeLine{1717   isv=is ; iev=ie ; jsv=js ; jev=je}
\DoxyCodeLine{1718   \textcolor{keywordflow}{do} n=1,nstep+nfilter}
\DoxyCodeLine{1719 }
\DoxyCodeLine{1720     sum\_wt\_vel = sum\_wt\_vel + wt\_vel(n)}
\DoxyCodeLine{1721     sum\_wt\_eta = sum\_wt\_eta + wt\_eta(n)}
\DoxyCodeLine{1722     sum\_wt\_accel = sum\_wt\_accel + wt\_accel2(n)}
\DoxyCodeLine{1723     sum\_wt\_trans = sum\_wt\_trans + wt\_trans(n)}
\DoxyCodeLine{1724 }
\DoxyCodeLine{1725     \textcolor{keywordflow}{if} (cs\%clip\_velocity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1726       \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{1727         \textcolor{keywordflow}{if} ((ubt(i,j) * (dt * g\%dy\_Cu(i,j))) * g\%IareaT(i+1,j) < -\/cs\%CFL\_trunc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1728           \textcolor{comment}{! Add some error reporting later.}}
\DoxyCodeLine{1729           ubt(i,j) = (-\/0.95*cs\%CFL\_trunc) * (g\%areaT(i+1,j) / (dt * g\%dy\_Cu(i,j)))}
\DoxyCodeLine{1730         \textcolor{keywordflow}{elseif} ((ubt(i,j) * (dt * g\%dy\_Cu(i,j))) * g\%IareaT(i,j) > cs\%CFL\_trunc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1731           \textcolor{comment}{! Add some error reporting later.}}
\DoxyCodeLine{1732           ubt(i,j) = (0.95*cs\%CFL\_trunc) * (g\%areaT(i,j) / (dt * g\%dy\_Cu(i,j)))}
\DoxyCodeLine{1733 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1734 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1735       \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{1736         \textcolor{keywordflow}{if} ((vbt(i,j) * (dt * g\%dx\_Cv(i,j))) * g\%IareaT(i,j+1) < -\/cs\%CFL\_trunc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1737           \textcolor{comment}{! Add some error reporting later.}}
\DoxyCodeLine{1738           vbt(i,j) = (-\/0.9*cs\%CFL\_trunc) * (g\%areaT(i,j+1) / (dt * g\%dx\_Cv(i,j)))}
\DoxyCodeLine{1739         \textcolor{keywordflow}{elseif} ((vbt(i,j) * (dt * g\%dx\_Cv(i,j))) * g\%IareaT(i,j) > cs\%CFL\_trunc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1740           \textcolor{comment}{! Add some error reporting later.}}
\DoxyCodeLine{1741           vbt(i,j) = (0.9*cs\%CFL\_trunc) * (g\%areaT(i,j) / (dt * g\%dx\_Cv(i,j)))}
\DoxyCodeLine{1742 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1743 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1744 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1745 }
\DoxyCodeLine{1746     \textcolor{keywordflow}{if} ((iev -\/ stencil < ie) .or. (jev -\/ stencil < je)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1747       \textcolor{keywordflow}{if} (id\_clock\_calc > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc)}
\DoxyCodeLine{1748       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_eta\_ubt, cs\%BT\_Domain, clock=id\_clock\_pass\_step)}
\DoxyCodeLine{1749       isv = isvf ; iev = ievf ; jsv = jsvf ; jev = jevf}
\DoxyCodeLine{1750       \textcolor{keywordflow}{if} (id\_clock\_calc > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc)}
\DoxyCodeLine{1751     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1752       isv = isv+stencil ; iev = iev-\/stencil}
\DoxyCodeLine{1753       jsv = jsv+stencil ; jev = jev-\/stencil}
\DoxyCodeLine{1754 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1755 }
\DoxyCodeLine{1756     \textcolor{keywordflow}{if} ((.not.use\_bt\_cont) .and. cs\%Nonlinear\_continuity .and. \&}
\DoxyCodeLine{1757         (cs\%Nonlin\_cont\_update\_period > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1758       \textcolor{keywordflow}{if} ((n>1) .and. (mod(n-\/1,cs\%Nonlin\_cont\_update\_period) == 0)) \&}
\DoxyCodeLine{1759         \textcolor{keyword}{call }find\_face\_areas(datu, datv, g, gv, us, cs, ms, eta, 1+iev-\/ie)}
\DoxyCodeLine{1760 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1761 }
\DoxyCodeLine{1762     \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1763       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1764       \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/2,iev+1}
\DoxyCodeLine{1765         ubt\_int\_prev(i,j) = ubt\_int(i,j) ; uhbt\_int\_prev(i,j) = uhbt\_int(i,j)}
\DoxyCodeLine{1766 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1767       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{1768       \textcolor{keywordflow}{do} j=jsv-\/2,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1769         vbt\_int\_prev(i,j) = vbt\_int(i,j) ; vhbt\_int\_prev(i,j) = vhbt\_int(i,j)}
\DoxyCodeLine{1770 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1771 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1772 }
\DoxyCodeLine{1773     \textcolor{comment}{!\$OMP parallel default(shared) private(vel\_prev, ioff, joff)}}
\DoxyCodeLine{1774     \textcolor{keywordflow}{if} (cs\%dynamic\_psurf .or. .not.project\_velocity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1775       \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1776         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1777         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/2,iev+1}
\DoxyCodeLine{1778           uhbt\_int(i,j) = find\_uhbt(ubt\_int(i,j) + dtbt*ubt(i,j), btcl\_u(i,j)) + n*dtbt*uhbt0(i,j)}
\DoxyCodeLine{1779 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1780         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1781         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1782         \textcolor{keywordflow}{do} j=jsv-\/2,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1783           vhbt\_int(i,j) = find\_vhbt(vbt\_int(i,j) + dtbt*vbt(i,j), btcl\_v(i,j)) + n*dtbt*vhbt0(i,j)}
\DoxyCodeLine{1784 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1785         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1786         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1787           eta\_pred(i,j) = (eta\_ic(i,j) + n*eta\_src(i,j)) + cs\%IareaT(i,j) * \&}
\DoxyCodeLine{1788                      ((uhbt\_int(i-\/1,j) -\/ uhbt\_int(i,j)) + (vhbt\_int(i,j-\/1) -\/ vhbt\_int(i,j)))}
\DoxyCodeLine{1789 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1790       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1791         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1792         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/2,iev+1}
\DoxyCodeLine{1793           uhbt(i,j) = find\_uhbt(ubt(i,j), btcl\_u(i,j)) + uhbt0(i,j)}
\DoxyCodeLine{1794 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1795         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1796         \textcolor{keywordflow}{do} j=jsv-\/2,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1797           vhbt(i,j) = find\_vhbt(vbt(i,j), btcl\_v(i,j)) + vhbt0(i,j)}
\DoxyCodeLine{1798 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1799         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1800         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1801           eta\_pred(i,j) = (eta(i,j) + eta\_src(i,j)) + (dtbt * cs\%IareaT(i,j)) * \&}
\DoxyCodeLine{1802                      ((uhbt(i-\/1,j) -\/ uhbt(i,j)) + (vhbt(i,j-\/1) -\/ vhbt(i,j)))}
\DoxyCodeLine{1803 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1804       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1805         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1806         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1807           eta\_pred(i,j) = (eta(i,j) + eta\_src(i,j)) + (dtbt * cs\%IareaT(i,j)) * \&}
\DoxyCodeLine{1808               (((datu(i-\/1,j)*ubt(i-\/1,j) + uhbt0(i-\/1,j)) -\/ \&}
\DoxyCodeLine{1809                 (datu(i,j)*ubt(i,j) + uhbt0(i,j))) + \&}
\DoxyCodeLine{1810                ((datv(i,j-\/1)*vbt(i,j-\/1) + vhbt0(i,j-\/1)) -\/ \&}
\DoxyCodeLine{1811                 (datv(i,j)*vbt(i,j) + vhbt0(i,j))))}
\DoxyCodeLine{1812 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1813 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1814 }
\DoxyCodeLine{1815       \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1816         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1817         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1818           p\_surf\_dyn(i,j) = dyn\_coef\_eta(i,j) * (eta\_pred(i,j) -\/ eta(i,j))}
\DoxyCodeLine{1819 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1820 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1821 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1822 }
\DoxyCodeLine{1823     \textcolor{comment}{! Recall that just outside the do n loop, there is code like...}}
\DoxyCodeLine{1824     \textcolor{comment}{!  eta\_PF\_BT => eta\_pred ; if (project\_velocity) eta\_PF\_BT => eta}}
\DoxyCodeLine{1825 }
\DoxyCodeLine{1826     \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1827       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1828       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1829         eta\_sum(i,j) = eta\_sum(i,j) + wt\_accel2(n) * eta\_pf\_bt(i,j)}
\DoxyCodeLine{1830 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1831       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1832 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1833 }
\DoxyCodeLine{1834     \textcolor{keywordflow}{if} (interp\_eta\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1835       wt\_end = n*instep  \textcolor{comment}{! This could be (n-\/0.5)*Instep.}}
\DoxyCodeLine{1836       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1837       \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1838         eta\_pf(i,j) = eta\_pf\_1(i,j) + wt\_end*d\_eta\_pf(i,j)}
\DoxyCodeLine{1839 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1840 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1841 }
\DoxyCodeLine{1842     \textcolor{keywordflow}{if} (apply\_obc\_flather .or. apply\_obc\_open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1843       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1844       \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/2,iev+1}
\DoxyCodeLine{1845         ubt\_old(i,j) = ubt(i,j)}
\DoxyCodeLine{1846 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1847       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1848       \textcolor{keywordflow}{do} j=jsv-\/2,jev+1 ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{1849         vbt\_old(i,j) = vbt(i,j)}
\DoxyCodeLine{1850 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1851 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1852 }
\DoxyCodeLine{1853     \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1854       \textcolor{keywordflow}{if} (mod(n+g\%first\_direction,2)==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1855         ioff = 1; joff = 0}
\DoxyCodeLine{1856       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1857         ioff = 0; joff = 1}
\DoxyCodeLine{1858 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1859 }
\DoxyCodeLine{1860       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! save the old value of ubt and uhbt}}
\DoxyCodeLine{1861         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1862         \textcolor{keywordflow}{do} j=jsv-\/joff,jev+joff ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{1863           ubt\_prev(i,j) = ubt(i,j) ; uhbt\_prev(i,j) = uhbt(i,j)}
\DoxyCodeLine{1864           ubt\_sum\_prev(i,j) = ubt\_sum(i,j) ; uhbt\_sum\_prev(i,j) = uhbt\_sum(i,j) ; ubt\_wtd\_prev(i,j) = ubt\_wtd(i,j)}
\DoxyCodeLine{1865 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1866 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1867 }
\DoxyCodeLine{1868       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! save the old value of vbt and vhbt}}
\DoxyCodeLine{1869         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{1870         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/ioff,iev+ioff}
\DoxyCodeLine{1871           vbt\_prev(i,j) = vbt(i,j) ; vhbt\_prev(i,j) = vhbt(i,j)}
\DoxyCodeLine{1872           vbt\_sum\_prev(i,j) = vbt\_sum(i,j) ; vhbt\_sum\_prev(i,j) = vhbt\_sum(i,j) ; vbt\_wtd\_prev(i,j) = vbt\_wtd(i,j)}
\DoxyCodeLine{1873 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1874 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1875 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1876 }
\DoxyCodeLine{1877     \textcolor{keywordflow}{if} (mod(n+g\%first\_direction,2)==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1878       \textcolor{comment}{! On odd-\/steps, update v first.}}
\DoxyCodeLine{1879       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1880       \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1881         cor\_v(i,j) = -\/1.0*((amer(i-\/1,j) * ubt(i-\/1,j) + cmer(i,j+1) * ubt(i,j+1)) + \&}
\DoxyCodeLine{1882                (bmer(i,j) * ubt(i,j) + dmer(i-\/1,j+1) * ubt(i-\/1,j+1))) -\/ cor\_ref\_v(i,j)}
\DoxyCodeLine{1883         pfv(i,j) = ((eta\_pf\_bt(i,j)-\/eta\_pf(i,j))*gtot\_n(i,j) -\/ \&}
\DoxyCodeLine{1884                      (eta\_pf\_bt(i,j+1)-\/eta\_pf(i,j+1))*gtot\_s(i,j+1)) * \&}
\DoxyCodeLine{1885                    dgeo\_de * cs\%IdyCv(i,j)}
\DoxyCodeLine{1886 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1887       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1888       \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1889         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1890         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1891           pfv(i,j) = pfv(i,j) + (p\_surf\_dyn(i,j) -\/ p\_surf\_dyn(i,j+1)) * cs\%IdyCv(i,j)}
\DoxyCodeLine{1892 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1893         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1894 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1895 }
\DoxyCodeLine{1896       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! zero out PF across boundary}}
\DoxyCodeLine{1897         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1898         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1 ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1899           pfv(i,j) = 0.0}
\DoxyCodeLine{1900 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1901         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1902 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1903       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1904       \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1905         vel\_prev = vbt(i,j)}
\DoxyCodeLine{1906         vbt(i,j) = bt\_rem\_v(i,j) * (vbt(i,j) + \&}
\DoxyCodeLine{1907                     dtbt * ((bt\_force\_v(i,j) + cor\_v(i,j)) + pfv(i,j)))}
\DoxyCodeLine{1908         vbt\_trans(i,j) = trans\_wt1*vbt(i,j) + trans\_wt2*vel\_prev}
\DoxyCodeLine{1909 }
\DoxyCodeLine{1910         \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1911           v\_accel\_bt(i,j) = v\_accel\_bt(i,j) + wt\_accel(n) * \&}
\DoxyCodeLine{1912               ((cor\_v(i,j) + pfv(i,j)) -\/ vbt(i,j)*rayleigh\_v(i,j))}
\DoxyCodeLine{1913         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1914           v\_accel\_bt(i,j) = v\_accel\_bt(i,j) + wt\_accel(n) * (cor\_v(i,j) + pfv(i,j))}
\DoxyCodeLine{1915 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1916 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1917 }
\DoxyCodeLine{1918       \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1919         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1920         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1921           vbt\_int(i,j) = vbt\_int(i,j) + dtbt * vbt\_trans(i,j)}
\DoxyCodeLine{1922           vhbt\_int(i,j) = find\_vhbt(vbt\_int(i,j), btcl\_v(i,j)) + n*dtbt*vhbt0(i,j)}
\DoxyCodeLine{1923           \textcolor{comment}{! Estimate the mass flux within a single timestep to take the filtered average.}}
\DoxyCodeLine{1924           vhbt(i,j) = (vhbt\_int(i,j) -\/ vhbt\_int\_prev(i,j)) * idtbt}
\DoxyCodeLine{1925 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1926       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1927         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1928         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1929           vhbt(i,j) = find\_vhbt(vbt\_trans(i,j), btcl\_v(i,j)) + vhbt0(i,j)}
\DoxyCodeLine{1930 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1931         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1932       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1933         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1934         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1}
\DoxyCodeLine{1935           vhbt(i,j) = datv(i,j)*vbt\_trans(i,j) + vhbt0(i,j)}
\DoxyCodeLine{1936 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1937         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1938 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1939       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! copy back the value for v-\/points on the boundary.}}
\DoxyCodeLine{1940         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1941         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1 ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1942           vbt(i,j) = vbt\_prev(i,j) ; vhbt(i,j) = vhbt\_prev(i,j)}
\DoxyCodeLine{1943 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1944 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1945       \textcolor{comment}{! Now update the zonal velocity.}}
\DoxyCodeLine{1946       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1947       \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{1948         cor\_u(i,j) = ((azon(i,j) * vbt(i+1,j) + czon(i,j) * vbt(i,j-\/1)) + \&}
\DoxyCodeLine{1949                       (bzon(i,j) * vbt(i,j) + dzon(i,j) * vbt(i+1,j-\/1))) -\/ \&}
\DoxyCodeLine{1950                      cor\_ref\_u(i,j)}
\DoxyCodeLine{1951         pfu(i,j) = ((eta\_pf\_bt(i,j)-\/eta\_pf(i,j))*gtot\_e(i,j) -\/ \&}
\DoxyCodeLine{1952                      (eta\_pf\_bt(i+1,j)-\/eta\_pf(i+1,j))*gtot\_w(i+1,j)) * \&}
\DoxyCodeLine{1953                     dgeo\_de * cs\%IdxCu(i,j)}
\DoxyCodeLine{1954 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1955       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1956 }
\DoxyCodeLine{1957       \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1958         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1959         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{1960           pfu(i,j) = pfu(i,j) + (p\_surf\_dyn(i,j) -\/ p\_surf\_dyn(i+1,j)) * cs\%IdxCu(i,j)}
\DoxyCodeLine{1961 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1962         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1963 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1964 }
\DoxyCodeLine{1965       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! zero out pressure force across boundary}}
\DoxyCodeLine{1966         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1967         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1968           pfu(i,j) = 0.0}
\DoxyCodeLine{1969 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1970         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1971 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1972       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1973       \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{1974         vel\_prev = ubt(i,j)}
\DoxyCodeLine{1975         ubt(i,j) = bt\_rem\_u(i,j) * (ubt(i,j) + \&}
\DoxyCodeLine{1976              dtbt * ((bt\_force\_u(i,j) + cor\_u(i,j)) + pfu(i,j)))}
\DoxyCodeLine{1977         \textcolor{keywordflow}{if} (abs(ubt(i,j)) < cs\%vel\_underflow) ubt(i,j) = 0.0}
\DoxyCodeLine{1978         ubt\_trans(i,j) = trans\_wt1*ubt(i,j) + trans\_wt2*vel\_prev}
\DoxyCodeLine{1979 }
\DoxyCodeLine{1980         \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1981           u\_accel\_bt(i,j) = u\_accel\_bt(i,j) + wt\_accel(n) * \&}
\DoxyCodeLine{1982               ((cor\_u(i,j) + pfu(i,j)) -\/ ubt(i,j)*rayleigh\_u(i,j))}
\DoxyCodeLine{1983         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1984           u\_accel\_bt(i,j) = u\_accel\_bt(i,j) + wt\_accel(n) * (cor\_u(i,j) + pfu(i,j))}
\DoxyCodeLine{1985 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1986 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1987       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{1988 }
\DoxyCodeLine{1989       \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1990         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1991         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{1992           ubt\_int(i,j) = ubt\_int(i,j) + dtbt * ubt\_trans(i,j)}
\DoxyCodeLine{1993           uhbt\_int(i,j) = find\_uhbt(ubt\_int(i,j), btcl\_u(i,j)) + n*dtbt*uhbt0(i,j)}
\DoxyCodeLine{1994           \textcolor{comment}{! Estimate the mass flux within a single timestep to take the filtered average.}}
\DoxyCodeLine{1995           uhbt(i,j) = (uhbt\_int(i,j) -\/ uhbt\_int\_prev(i,j)) * idtbt}
\DoxyCodeLine{1996 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1997       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1998         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{1999         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2000           uhbt(i,j) = find\_uhbt(ubt\_trans(i,j), btcl\_u(i,j)) + uhbt0(i,j)}
\DoxyCodeLine{2001 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2002       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2003         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2004         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2005           uhbt(i,j) = datu(i,j)*ubt\_trans(i,j) + uhbt0(i,j)}
\DoxyCodeLine{2006 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2007 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2008       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! copy back the value for u-\/points on the boundary.}}
\DoxyCodeLine{2009         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2010         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2011           ubt(i,j) = ubt\_prev(i,j) ; uhbt(i,j) = uhbt\_prev(i,j)}
\DoxyCodeLine{2012 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2013 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2014     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2015       \textcolor{comment}{! On even steps, update u first.}}
\DoxyCodeLine{2016       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2017       \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2018         cor\_u(i,j) = ((azon(i,j) * vbt(i+1,j) + czon(i,j) * vbt(i,j-\/1)) + \&}
\DoxyCodeLine{2019                       (bzon(i,j) * vbt(i,j) +  dzon(i,j) * vbt(i+1,j-\/1))) -\/ \&}
\DoxyCodeLine{2020                      cor\_ref\_u(i,j)}
\DoxyCodeLine{2021         pfu(i,j) = ((eta\_pf\_bt(i,j)-\/eta\_pf(i,j))*gtot\_e(i,j) -\/ \&}
\DoxyCodeLine{2022                      (eta\_pf\_bt(i+1,j)-\/eta\_pf(i+1,j))*gtot\_w(i+1,j)) * \&}
\DoxyCodeLine{2023                      dgeo\_de * cs\%IdxCu(i,j)}
\DoxyCodeLine{2024 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2025       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2026 }
\DoxyCodeLine{2027       \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2028         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2029         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2030           pfu(i,j) = pfu(i,j) + (p\_surf\_dyn(i,j) -\/ p\_surf\_dyn(i+1,j)) * cs\%IdxCu(i,j)}
\DoxyCodeLine{2031 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2032         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2033 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2034 }
\DoxyCodeLine{2035       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! zero out pressure force across boundary}}
\DoxyCodeLine{2036         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2037         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2038           pfu(i,j) = 0.0}
\DoxyCodeLine{2039 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2040 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2041 }
\DoxyCodeLine{2042       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2043       \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2044         vel\_prev = ubt(i,j)}
\DoxyCodeLine{2045         ubt(i,j) = bt\_rem\_u(i,j) * (ubt(i,j) + \&}
\DoxyCodeLine{2046              dtbt * ((bt\_force\_u(i,j) + cor\_u(i,j)) + pfu(i,j)))}
\DoxyCodeLine{2047         \textcolor{keywordflow}{if} (abs(ubt(i,j)) < cs\%vel\_underflow) ubt(i,j) = 0.0}
\DoxyCodeLine{2048         ubt\_trans(i,j) = trans\_wt1*ubt(i,j) + trans\_wt2*vel\_prev}
\DoxyCodeLine{2049 }
\DoxyCodeLine{2050         \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2051           u\_accel\_bt(i,j) = u\_accel\_bt(i,j) + wt\_accel(n) * \&}
\DoxyCodeLine{2052               ((cor\_u(i,j) + pfu(i,j)) -\/ ubt(i,j)*rayleigh\_u(i,j))}
\DoxyCodeLine{2053         \textcolor{keywordflow}{else}}
\DoxyCodeLine{2054           u\_accel\_bt(i,j) = u\_accel\_bt(i,j) + wt\_accel(n) * (cor\_u(i,j) + pfu(i,j))}
\DoxyCodeLine{2055 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2056 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2057 }
\DoxyCodeLine{2058       \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2059         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2060         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2061           ubt\_int(i,j) = ubt\_int(i,j) + dtbt * ubt\_trans(i,j)}
\DoxyCodeLine{2062           uhbt\_int(i,j) = find\_uhbt(ubt\_int(i,j), btcl\_u(i,j)) + n*dtbt*uhbt0(i,j)}
\DoxyCodeLine{2063           \textcolor{comment}{! Estimate the mass flux within a single timestep to take the filtered average.}}
\DoxyCodeLine{2064           uhbt(i,j) = (uhbt\_int(i,j) -\/ uhbt\_int\_prev(i,j)) * idtbt}
\DoxyCodeLine{2065 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2066       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2067         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2068         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2069           uhbt(i,j) = find\_uhbt(ubt\_trans(i,j), btcl\_u(i,j)) + uhbt0(i,j)}
\DoxyCodeLine{2070 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2071         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2072       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2073         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2074         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev}
\DoxyCodeLine{2075           uhbt(i,j) = datu(i,j)*ubt\_trans(i,j) + uhbt0(i,j)}
\DoxyCodeLine{2076 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2077         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2078 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2079       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! copy back the value for u-\/points on the boundary.}}
\DoxyCodeLine{2080         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2081         \textcolor{keywordflow}{do} j=jsv-\/1,jev+1 ; \textcolor{keywordflow}{do} i=isv-\/1,iev ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2082           ubt(i,j) = ubt\_prev(i,j) ; uhbt(i,j) = uhbt\_prev(i,j)}
\DoxyCodeLine{2083 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2084 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2085 }
\DoxyCodeLine{2086       \textcolor{comment}{! Now update the meridional velocity.}}
\DoxyCodeLine{2087       \textcolor{keywordflow}{if} (cs\%use\_old\_coriolis\_bracket\_bug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2088         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2089         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2090           cor\_v(i,j) = -\/1.0*((amer(i-\/1,j) * ubt(i-\/1,j) + bmer(i,j) * ubt(i,j)) + \&}
\DoxyCodeLine{2091                   (cmer(i,j+1) * ubt(i,j+1) + dmer(i-\/1,j+1) * ubt(i-\/1,j+1))) -\/ cor\_ref\_v(i,j)}
\DoxyCodeLine{2092           pfv(i,j) = ((eta\_pf\_bt(i,j)-\/eta\_pf(i,j))*gtot\_n(i,j) -\/ \&}
\DoxyCodeLine{2093                        (eta\_pf\_bt(i,j+1)-\/eta\_pf(i,j+1))*gtot\_s(i,j+1)) * \&}
\DoxyCodeLine{2094                       dgeo\_de * cs\%IdyCv(i,j)}
\DoxyCodeLine{2095 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2096         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2097       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2098         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2099         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2100           cor\_v(i,j) = -\/1.0*((amer(i-\/1,j) * ubt(i-\/1,j) + cmer(i,j+1) * ubt(i,j+1)) + \&}
\DoxyCodeLine{2101                   (bmer(i,j) * ubt(i,j) + dmer(i-\/1,j+1) * ubt(i-\/1,j+1))) -\/ cor\_ref\_v(i,j)}
\DoxyCodeLine{2102           pfv(i,j) = ((eta\_pf\_bt(i,j)-\/eta\_pf(i,j))*gtot\_n(i,j) -\/ \&}
\DoxyCodeLine{2103                        (eta\_pf\_bt(i,j+1)-\/eta\_pf(i,j+1))*gtot\_s(i,j+1)) * \&}
\DoxyCodeLine{2104                       dgeo\_de * cs\%IdyCv(i,j)}
\DoxyCodeLine{2105 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2106         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2107 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2108 }
\DoxyCodeLine{2109       \textcolor{keywordflow}{if} (cs\%dynamic\_psurf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2110         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2111         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2112           pfv(i,j) = pfv(i,j) + (p\_surf\_dyn(i,j) -\/ p\_surf\_dyn(i,j+1)) * cs\%IdyCv(i,j)}
\DoxyCodeLine{2113 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2114         \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2115 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2116 }
\DoxyCodeLine{2117       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! zero out PF across boundary}}
\DoxyCodeLine{2118         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2119         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv-\/1,iev+1 ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2120           pfv(i,j) = 0.0}
\DoxyCodeLine{2121 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2122 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2123 }
\DoxyCodeLine{2124       \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2125       \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2126         vel\_prev = vbt(i,j)}
\DoxyCodeLine{2127         vbt(i,j) = bt\_rem\_v(i,j) * (vbt(i,j) + \&}
\DoxyCodeLine{2128              dtbt * ((bt\_force\_v(i,j) + cor\_v(i,j)) + pfv(i,j)))}
\DoxyCodeLine{2129         \textcolor{keywordflow}{if} (abs(vbt(i,j)) < cs\%vel\_underflow) vbt(i,j) = 0.0}
\DoxyCodeLine{2130         vbt\_trans(i,j) = trans\_wt1*vbt(i,j) + trans\_wt2*vel\_prev}
\DoxyCodeLine{2131 }
\DoxyCodeLine{2132         \textcolor{keywordflow}{if} (cs\%linear\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2133           v\_accel\_bt(i,j) = v\_accel\_bt(i,j) + wt\_accel(n) * \&}
\DoxyCodeLine{2134               ((cor\_v(i,j) + pfv(i,j)) -\/ vbt(i,j)*rayleigh\_v(i,j))}
\DoxyCodeLine{2135         \textcolor{keywordflow}{else}}
\DoxyCodeLine{2136           v\_accel\_bt(i,j) = v\_accel\_bt(i,j) + wt\_accel(n) * (cor\_v(i,j) + pfv(i,j))}
\DoxyCodeLine{2137 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2138 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2139       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2140       \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2141         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2142         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2143           vbt\_int(i,j) = vbt\_int(i,j) + dtbt * vbt\_trans(i,j)}
\DoxyCodeLine{2144           vhbt\_int(i,j) = find\_vhbt(vbt\_int(i,j), btcl\_v(i,j)) + n*dtbt*vhbt0(i,j)}
\DoxyCodeLine{2145           \textcolor{comment}{! Estimate the mass flux within a single timestep to take the filtered average.}}
\DoxyCodeLine{2146           vhbt(i,j) = (vhbt\_int(i,j) -\/ vhbt\_int\_prev(i,j)) * idtbt}
\DoxyCodeLine{2147 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2148       \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2149         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2150         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2151           vhbt(i,j) = find\_vhbt(vbt\_trans(i,j), btcl\_v(i,j)) + vhbt0(i,j)}
\DoxyCodeLine{2152 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2153       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2154         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2155         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2156           vhbt(i,j) = datv(i,j)*vbt\_trans(i,j) + vhbt0(i,j)}
\DoxyCodeLine{2157 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2158 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2159       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! copy back the value for v-\/points on the boundary.}}
\DoxyCodeLine{2160         \textcolor{comment}{!\$OMP do schedule(static)}}
\DoxyCodeLine{2161         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{do} i=isv,iev ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2162           vbt(i,j) = vbt\_prev(i,j); vhbt(i,j) = vhbt\_prev(i,j)}
\DoxyCodeLine{2163 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2164 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2165 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2166 }
\DoxyCodeLine{2167     \textcolor{comment}{! This might need to be moved outside of the OMP do loop directives.}}
\DoxyCodeLine{2168     \textcolor{keywordflow}{if} (cs\%debug\_bt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2169       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("{}BT vel update "{},I4)'}) n}
\DoxyCodeLine{2170       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} PF[uv]"{}}, pfu, pfv, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2171                     scale=us\%L\_T\_to\_m\_s*us\%s\_to\_T)}
\DoxyCodeLine{2172       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} Cor\_[uv]"{}}, cor\_u, cor\_v, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2173                     scale=us\%L\_T\_to\_m\_s*us\%s\_to\_T)}
\DoxyCodeLine{2174       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} BT\_force\_[uv]"{}}, bt\_force\_u, bt\_force\_v, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2175                     scale=us\%L\_T\_to\_m\_s*us\%s\_to\_T)}
\DoxyCodeLine{2176       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} BT\_rem\_[uv]"{}}, bt\_rem\_u, bt\_rem\_v, cs\%debug\_BT\_HI, haloshift=iev-\/ie)}
\DoxyCodeLine{2177       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} [uv]bt"{}}, ubt, vbt, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2178                     scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2179       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} [uv]bt\_trans"{}}, ubt\_trans, vbt\_trans, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2180                     scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2181       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} [uv]hbt"{}}, uhbt, vhbt, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2182                     scale=us\%s\_to\_T*us\%L\_to\_m**2*gv\%H\_to\_m)}
\DoxyCodeLine{2183       \textcolor{keywordflow}{if} (integral\_bt\_cont) \&}
\DoxyCodeLine{2184         \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} [uv]hbt\_int"{}}, uhbt\_int, vhbt\_int, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2185                       scale=us\%L\_to\_m**2*gv\%H\_to\_m)}
\DoxyCodeLine{2186 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2187 }
\DoxyCodeLine{2188     \textcolor{keywordflow}{if} (find\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2189       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2190       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2191         pfu\_bt\_sum(i,j)  = pfu\_bt\_sum(i,j) + wt\_accel2(n) * pfu(i,j)}
\DoxyCodeLine{2192 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2193       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2194       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2195       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2196         pfv\_bt\_sum(i,j)  = pfv\_bt\_sum(i,j) + wt\_accel2(n) * pfv(i,j)}
\DoxyCodeLine{2197 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2198       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2199 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2200     \textcolor{keywordflow}{if} (find\_cor) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2201       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2202       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2203         coru\_bt\_sum(i,j) = coru\_bt\_sum(i,j) + wt\_accel2(n) * cor\_u(i,j)}
\DoxyCodeLine{2204 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2205       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2206       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2207       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2208         corv\_bt\_sum(i,j) = corv\_bt\_sum(i,j) + wt\_accel2(n) * cor\_v(i,j)}
\DoxyCodeLine{2209 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2210       \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2211 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2212 }
\DoxyCodeLine{2213     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2214     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2215       ubt\_sum(i,j) = ubt\_sum(i,j) + wt\_trans(n) * ubt\_trans(i,j)}
\DoxyCodeLine{2216       uhbt\_sum(i,j) = uhbt\_sum(i,j) + wt\_trans(n) * uhbt(i,j)}
\DoxyCodeLine{2217       ubt\_wtd(i,j) = ubt\_wtd(i,j) + wt\_vel(n) * ubt(i,j)}
\DoxyCodeLine{2218 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2219     \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2220     \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2221     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2222       vbt\_sum(i,j) = vbt\_sum(i,j) + wt\_trans(n) * vbt\_trans(i,j)}
\DoxyCodeLine{2223       vhbt\_sum(i,j) = vhbt\_sum(i,j) + wt\_trans(n) * vhbt(i,j)}
\DoxyCodeLine{2224       vbt\_wtd(i,j) = vbt\_wtd(i,j) + wt\_vel(n) * vbt(i,j)}
\DoxyCodeLine{2225 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2226     \textcolor{comment}{!\$OMP end do nowait}}
\DoxyCodeLine{2227 }
\DoxyCodeLine{2228     \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2229 }
\DoxyCodeLine{2230       \textcolor{comment}{!\$OMP single}}
\DoxyCodeLine{2231       \textcolor{keyword}{call }apply\_velocity\_obcs(obc, ubt, vbt, uhbt, vhbt, \&}
\DoxyCodeLine{2232              ubt\_trans, vbt\_trans, eta, ubt\_old, vbt\_old, cs\%BT\_OBC, \&}
\DoxyCodeLine{2233              g, ms, us, iev-\/ie, dtbt, bebt, use\_bt\_cont, integral\_bt\_cont, \&}
\DoxyCodeLine{2234              n*dtbt, datu, datv, btcl\_u, btcl\_v, uhbt0, vhbt0, \&}
\DoxyCodeLine{2235              ubt\_int\_prev, vbt\_int\_prev, uhbt\_int\_prev, vhbt\_int\_prev)}
\DoxyCodeLine{2236       \textcolor{comment}{!\$OMP end single}}
\DoxyCodeLine{2237 }
\DoxyCodeLine{2238       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2239         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2240         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2241           \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2242             \textcolor{comment}{! Update the summed and integrated quantities from the saved previous values.}}
\DoxyCodeLine{2243             ubt\_sum(i,j) = ubt\_sum\_prev(i,j) + wt\_trans(n) * ubt\_trans(i,j)}
\DoxyCodeLine{2244             uhbt\_sum(i,j) = uhbt\_sum\_prev(i,j) + wt\_trans(n) * uhbt(i,j)}
\DoxyCodeLine{2245             ubt\_wtd(i,j) = ubt\_wtd\_prev(i,j) + wt\_vel(n) * ubt(i,j)}
\DoxyCodeLine{2246             \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2247               uhbt\_int(i,j) = uhbt\_int\_prev(i,j) + dtbt * uhbt(i,j)}
\DoxyCodeLine{2248               ubt\_int(i,j) = ubt\_int\_prev(i,j) + dtbt * ubt\_trans(i,j)}
\DoxyCodeLine{2249 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{2250 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2251 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2252 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2253       \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2254         \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2255         \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2256           \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2257             \textcolor{comment}{! Update the summed and integrated quantities from the saved previous values.}}
\DoxyCodeLine{2258             vbt\_sum(i,j) = vbt\_sum\_prev(i,j) + wt\_trans(n) * vbt\_trans(i,j)}
\DoxyCodeLine{2259             vhbt\_sum(i,j) = vhbt\_sum\_prev(i,j) + wt\_trans(n) * vhbt(i,j)}
\DoxyCodeLine{2260             vbt\_wtd(i,j) = vbt\_wtd\_prev(i,j) + wt\_vel(n) * vbt(i,j)}
\DoxyCodeLine{2261             \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2262               vbt\_int(i,j) = vbt\_int\_prev(i,j) + dtbt * vbt\_trans(i,j)}
\DoxyCodeLine{2263               vhbt\_int(i,j) = vhbt\_int\_prev(i,j) + dtbt * vhbt(i,j)}
\DoxyCodeLine{2264 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{2265 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2266 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2267 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2268 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2269 }
\DoxyCodeLine{2270     \textcolor{keywordflow}{if} (cs\%debug\_bt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2271       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT [uv]hbt just after OBC"{}}, uhbt, vhbt, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2272                     scale=us\%s\_to\_T*us\%L\_to\_m**2*gv\%H\_to\_m)}
\DoxyCodeLine{2273       \textcolor{keywordflow}{if} (integral\_bt\_cont) \&}
\DoxyCodeLine{2274         \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"{}BT [uv]hbt\_int just after OBC"{}}, uhbt\_int, vhbt\_int, cs\%debug\_BT\_HI, \&}
\DoxyCodeLine{2275                       haloshift=iev-\/ie, scale=us\%L\_to\_m**2*gv\%H\_to\_m)}
\DoxyCodeLine{2276 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2277 }
\DoxyCodeLine{2278     \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2279       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2280       \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2281         eta(i,j) = (eta\_ic(i,j) + n*eta\_src(i,j)) + cs\%IareaT(i,j) * \&}
\DoxyCodeLine{2282                    ((uhbt\_int(i-\/1,j) -\/ uhbt\_int(i,j)) + (vhbt\_int(i,j-\/1) -\/ vhbt\_int(i,j)))}
\DoxyCodeLine{2283         eta\_wtd(i,j) = eta\_wtd(i,j) + eta(i,j) * wt\_eta(n)}
\DoxyCodeLine{2284 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2285     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2286       \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{2287       \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{do} i=isv,iev}
\DoxyCodeLine{2288         eta(i,j) = (eta(i,j) + eta\_src(i,j)) + (dtbt * cs\%IareaT(i,j)) * \&}
\DoxyCodeLine{2289                    ((uhbt(i-\/1,j) -\/ uhbt(i,j)) + (vhbt(i,j-\/1) -\/ vhbt(i,j)))}
\DoxyCodeLine{2290         eta\_wtd(i,j) = eta\_wtd(i,j) + eta(i,j) * wt\_eta(n)}
\DoxyCodeLine{2291 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2292 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2293     \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{2294 }
\DoxyCodeLine{2295     \textcolor{keywordflow}{if} (do\_hifreq\_output) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2296       time\_step\_end = time\_bt\_start + real\_to\_time(n*us\%T\_to\_s*dtbt)}
\DoxyCodeLine{2297       \textcolor{keyword}{call }enable\_averaging(us\%T\_to\_s*dtbt, time\_step\_end, cs\%diag)}
\DoxyCodeLine{2298       \textcolor{keywordflow}{if} (cs\%id\_ubt\_hifreq > 0) \textcolor{keyword}{call }post\_data(cs\%id\_ubt\_hifreq, ubt(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2299       \textcolor{keywordflow}{if} (cs\%id\_vbt\_hifreq > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vbt\_hifreq, vbt(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2300       \textcolor{keywordflow}{if} (cs\%id\_eta\_hifreq > 0) \textcolor{keyword}{call }post\_data(cs\%id\_eta\_hifreq, eta(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{2301       \textcolor{keywordflow}{if} (cs\%id\_uhbt\_hifreq > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uhbt\_hifreq, uhbt(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2302       \textcolor{keywordflow}{if} (cs\%id\_vhbt\_hifreq > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vhbt\_hifreq, vhbt(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2303       \textcolor{keywordflow}{if} (cs\%id\_eta\_pred\_hifreq > 0) \textcolor{keyword}{call }post\_data(cs\%id\_eta\_pred\_hifreq, eta\_pf\_bt(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{2304 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2305 }
\DoxyCodeLine{2306     \textcolor{keywordflow}{if} (cs\%debug\_bt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2307       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("{}BT step "{},I4)'}) n}
\DoxyCodeLine{2308       \textcolor{keyword}{call }uvchksum(trim(mesg)//\textcolor{stringliteral}{"{} [uv]bt"{}}, ubt, vbt, cs\%debug\_BT\_HI, haloshift=iev-\/ie, \&}
\DoxyCodeLine{2309                     scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2310       \textcolor{keyword}{call }hchksum(eta, trim(mesg)//\textcolor{stringliteral}{"{} eta"{}}, cs\%debug\_BT\_HI, haloshift=iev-\/ie, scale=gv\%H\_to\_m)}
\DoxyCodeLine{2311 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2312 }
\DoxyCodeLine{2313     \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2314       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2315         \textcolor{keywordflow}{if} (eta(i,j) < -\/gv\%Z\_to\_H*g\%bathyT(i,j)) \&}
\DoxyCodeLine{2316           \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}btstep: eta has dropped below bathyT."{}})}
\DoxyCodeLine{2317 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2318     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2319       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2320         \textcolor{keywordflow}{if} (eta(i,j) < 0.0) \&}
\DoxyCodeLine{2321           \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}btstep: negative eta in a non-\/Boussinesq barotropic solver."{}})}
\DoxyCodeLine{2322 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2323 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2324 }
\DoxyCodeLine{2325 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end of do n=1,ntimestep}}
\DoxyCodeLine{2326   \textcolor{keywordflow}{if} (id\_clock\_calc > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc)}
\DoxyCodeLine{2327   \textcolor{keywordflow}{if} (id\_clock\_calc\_post > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_post)}
\DoxyCodeLine{2328 }
\DoxyCodeLine{2329   \textcolor{comment}{! Reset the time information in the diag type.}}
\DoxyCodeLine{2330   \textcolor{keywordflow}{if} (do\_hifreq\_output) \textcolor{keyword}{call }enable\_averaging(time\_int\_in, time\_end\_in, cs\%diag)}
\DoxyCodeLine{2331 }
\DoxyCodeLine{2332   \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2333     i\_sum\_wt\_vel = 1.0 / sum\_wt\_vel ; i\_sum\_wt\_eta = 1.0 / sum\_wt\_eta}
\DoxyCodeLine{2334     i\_sum\_wt\_accel = 1.0 / sum\_wt\_accel ; i\_sum\_wt\_trans = 1.0 / sum\_wt\_trans}
\DoxyCodeLine{2335   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2336     i\_sum\_wt\_vel = 1.0 ; i\_sum\_wt\_eta = 1.0 ; i\_sum\_wt\_accel = 1.0 ; i\_sum\_wt\_trans = 1.0}
\DoxyCodeLine{2337 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2338 }
\DoxyCodeLine{2339   \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2340     etaav(i,j) = eta\_sum(i,j) * i\_sum\_wt\_accel}
\DoxyCodeLine{2341 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2342   \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1 ; e\_anom(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2343   \textcolor{keywordflow}{if} (interp\_eta\_pf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2344     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2345       e\_anom(i,j) = dgeo\_de * (0.5 * (eta(i,j) + eta\_in(i,j)) -\/ \&}
\DoxyCodeLine{2346                                (eta\_pf\_1(i,j) + 0.5*d\_eta\_pf(i,j)))}
\DoxyCodeLine{2347 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2348   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2349     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2350       e\_anom(i,j) = dgeo\_de * (0.5 * (eta(i,j) + eta\_in(i,j)) -\/ eta\_pf(i,j))}
\DoxyCodeLine{2351 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2352 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2353   \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2354     \textcolor{comment}{!!! Not safe for wide halos...}}
\DoxyCodeLine{2355     \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! copy back the value for u-\/points on the boundary.}}
\DoxyCodeLine{2356       \textcolor{comment}{!GOMP parallel do default(shared)}}
\DoxyCodeLine{2357       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2358         l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{2359         \textcolor{keywordflow}{if} (l\_seg == obc\_none) cycle}
\DoxyCodeLine{2360 }
\DoxyCodeLine{2361         \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2362           e\_anom(i+1,j) = e\_anom(i,j)}
\DoxyCodeLine{2363         \textcolor{keywordflow}{elseif} (obc\%segment(l\_seg)\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2364           e\_anom(i,j) = e\_anom(i+1,j)}
\DoxyCodeLine{2365 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2366 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2367 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2368 }
\DoxyCodeLine{2369     \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then}  \textcolor{comment}{! copy back the value for v-\/points on the boundary.}}
\DoxyCodeLine{2370       \textcolor{comment}{!GOMP parallel do default(shared)}}
\DoxyCodeLine{2371       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2372         l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{2373         \textcolor{keywordflow}{if} (l\_seg == obc\_none) cycle}
\DoxyCodeLine{2374 }
\DoxyCodeLine{2375         \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2376           e\_anom(i,j+1) = e\_anom(i,j)}
\DoxyCodeLine{2377         \textcolor{keywordflow}{elseif} (obc\%segment(l\_seg)\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2378           e\_anom(i,j) = e\_anom(i,j+1)}
\DoxyCodeLine{2379 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2380 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2381 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2382 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2383 }
\DoxyCodeLine{2384   \textcolor{comment}{! It is possible that eta\_out and eta\_in are the same.}}
\DoxyCodeLine{2385   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2386     eta\_out(i,j) = eta\_wtd(i,j) * i\_sum\_wt\_eta}
\DoxyCodeLine{2387 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2388 }
\DoxyCodeLine{2389   \textcolor{keywordflow}{if} (id\_clock\_calc\_post > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_post)}
\DoxyCodeLine{2390   \textcolor{keywordflow}{if} (id\_clock\_pass\_post > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_post)}
\DoxyCodeLine{2391   \textcolor{keywordflow}{if} (g\%nonblocking\_updates) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2392     \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_e\_anom, g\%Domain)}
\DoxyCodeLine{2393   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2394     \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_etaav, g\%Domain)}
\DoxyCodeLine{2395     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_e\_anom, g\%Domain)}
\DoxyCodeLine{2396 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2397   \textcolor{keywordflow}{if} (id\_clock\_pass\_post > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_post)}
\DoxyCodeLine{2398   \textcolor{keywordflow}{if} (id\_clock\_calc\_post > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_post)}
\DoxyCodeLine{2399 }
\DoxyCodeLine{2400   \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2401     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2402       cs\%ubtav(i,j) = ubt\_sum(i,j) * i\_sum\_wt\_trans}
\DoxyCodeLine{2403       uhbtav(i,j) = uhbt\_sum(i,j) * i\_sum\_wt\_trans}
\DoxyCodeLine{2404       ubt\_wtd(i,j) = ubt\_wtd(i,j) * i\_sum\_wt\_vel}
\DoxyCodeLine{2405 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2406 }
\DoxyCodeLine{2407     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2408       cs\%vbtav(i,j) = vbt\_sum(i,j) * i\_sum\_wt\_trans}
\DoxyCodeLine{2409       vhbtav(i,j) = vhbt\_sum(i,j) * i\_sum\_wt\_trans}
\DoxyCodeLine{2410       vbt\_wtd(i,j) = vbt\_wtd(i,j) * i\_sum\_wt\_vel}
\DoxyCodeLine{2411 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2412   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2413     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2414       cs\%ubtav(i,j) = ubt\_sum(i,j)}
\DoxyCodeLine{2415       uhbtav(i,j) = uhbt\_sum(i,j)}
\DoxyCodeLine{2416 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2417 }
\DoxyCodeLine{2418     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2419       cs\%vbtav(i,j) = vbt\_sum(i,j)}
\DoxyCodeLine{2420       vhbtav(i,j) = vhbt\_sum(i,j)}
\DoxyCodeLine{2421 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2422 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2423 }
\DoxyCodeLine{2424 }
\DoxyCodeLine{2425   \textcolor{keywordflow}{if} (id\_clock\_calc\_post > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_post)}
\DoxyCodeLine{2426   \textcolor{keywordflow}{if} (id\_clock\_pass\_post > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_post)}
\DoxyCodeLine{2427   \textcolor{keywordflow}{if} (g\%nonblocking\_updates) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2428     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_e\_anom, g\%Domain)}
\DoxyCodeLine{2429     \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_etaav, g\%Domain)}
\DoxyCodeLine{2430     \textcolor{keyword}{call }start\_group\_pass(cs\%pass\_ubta\_uhbta, g\%DoMain)}
\DoxyCodeLine{2431   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2432     \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_ubta\_uhbta, g\%Domain)}
\DoxyCodeLine{2433 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2434   \textcolor{keywordflow}{if} (id\_clock\_pass\_post > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_post)}
\DoxyCodeLine{2435   \textcolor{keywordflow}{if} (id\_clock\_calc\_post > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_post)}
\DoxyCodeLine{2436 }
\DoxyCodeLine{2437   \textcolor{comment}{! Now calculate each layer's accelerations.}}
\DoxyCodeLine{2438   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{2439   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{2440     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2441       accel\_layer\_u(i,j,k) = (u\_accel\_bt(i,j) -\/ \&}
\DoxyCodeLine{2442            ((pbce(i+1,j,k) -\/ gtot\_w(i+1,j)) * e\_anom(i+1,j) -\/ \&}
\DoxyCodeLine{2443             (pbce(i,j,k) -\/ gtot\_e(i,j)) * e\_anom(i,j)) * cs\%IdxCu(i,j) )}
\DoxyCodeLine{2444       \textcolor{keywordflow}{if} (abs(accel\_layer\_u(i,j,k)) < accel\_underflow) accel\_layer\_u(i,j,k) = 0.0}
\DoxyCodeLine{2445 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2446     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2447       accel\_layer\_v(i,j,k) = (v\_accel\_bt(i,j) -\/ \&}
\DoxyCodeLine{2448            ((pbce(i,j+1,k) -\/ gtot\_s(i,j+1)) * e\_anom(i,j+1) -\/ \&}
\DoxyCodeLine{2449             (pbce(i,j,k) -\/ gtot\_n(i,j)) * e\_anom(i,j)) * cs\%IdyCv(i,j) )}
\DoxyCodeLine{2450       \textcolor{keywordflow}{if} (abs(accel\_layer\_v(i,j,k)) < accel\_underflow) accel\_layer\_v(i,j,k) = 0.0}
\DoxyCodeLine{2451 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2452 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2453 }
\DoxyCodeLine{2454   \textcolor{keywordflow}{if} (apply\_obcs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2455     \textcolor{comment}{! Correct the accelerations at OBC velocity points, but only in the}}
\DoxyCodeLine{2456     \textcolor{comment}{! symmetric-\/memory computational domain, not in the wide halo regions.}}
\DoxyCodeLine{2457     \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_u\_OBCs) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2458       \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2459         u\_accel\_bt(i,j) = (ubt\_wtd(i,j) -\/ ubt\_first(i,j)) / dt}
\DoxyCodeLine{2460         \textcolor{keywordflow}{do} k=1,nz ; accel\_layer\_u(i,j,k) = u\_accel\_bt(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2461 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2462 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2463     \textcolor{keywordflow}{if} (cs\%BT\_OBC\%apply\_v\_OBCs) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2464       \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2465         v\_accel\_bt(i,j) = (vbt\_wtd(i,j) -\/ vbt\_first(i,j)) / dt}
\DoxyCodeLine{2466         \textcolor{keywordflow}{do} k=1,nz ; accel\_layer\_v(i,j,k) = v\_accel\_bt(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2467 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2468 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2469 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2470 }
\DoxyCodeLine{2471   \textcolor{keywordflow}{if} (id\_clock\_calc\_post > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_post)}
\DoxyCodeLine{2472 }
\DoxyCodeLine{2473   \textcolor{comment}{! Calculate diagnostic quantities.}}
\DoxyCodeLine{2474   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2475 }
\DoxyCodeLine{2476     \textcolor{keywordflow}{if} (cs\%gradual\_BT\_ICs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2477       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; cs\%ubt\_IC(i,j) = ubt\_wtd(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2478       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; cs\%vbt\_IC(i,j) = vbt\_wtd(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2479 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2480 }
\DoxyCodeLine{2481 \textcolor{comment}{!  Offer various barotropic terms for averaging.}}
\DoxyCodeLine{2482     \textcolor{keywordflow}{if} (cs\%id\_PFu\_bt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2483       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2484         pfu\_bt\_sum(i,j) = pfu\_bt\_sum(i,j) * i\_sum\_wt\_accel}
\DoxyCodeLine{2485 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2486       \textcolor{keyword}{call }post\_data(cs\%id\_PFu\_bt, pfu\_bt\_sum(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2487 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2488     \textcolor{keywordflow}{if} (cs\%id\_PFv\_bt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2489       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2490         pfv\_bt\_sum(i,j) = pfv\_bt\_sum(i,j) * i\_sum\_wt\_accel}
\DoxyCodeLine{2491 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2492       \textcolor{keyword}{call }post\_data(cs\%id\_PFv\_bt, pfv\_bt\_sum(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2493 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2494     \textcolor{keywordflow}{if} (cs\%id\_Coru\_bt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2495       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2496         coru\_bt\_sum(i,j) = coru\_bt\_sum(i,j) * i\_sum\_wt\_accel}
\DoxyCodeLine{2497 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2498       \textcolor{keyword}{call }post\_data(cs\%id\_Coru\_bt, coru\_bt\_sum(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2499 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2500     \textcolor{keywordflow}{if} (cs\%id\_Corv\_bt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2501       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2502         corv\_bt\_sum(i,j) = corv\_bt\_sum(i,j) * i\_sum\_wt\_accel}
\DoxyCodeLine{2503 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2504       \textcolor{keyword}{call }post\_data(cs\%id\_Corv\_bt, corv\_bt\_sum(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2505 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2506     \textcolor{keywordflow}{if} (cs\%id\_ubtdt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2507       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2508         ubt\_dt(i,j) = (ubt\_wtd(i,j) -\/ ubt\_st(i,j))*idt}
\DoxyCodeLine{2509 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2510       \textcolor{keyword}{call }post\_data(cs\%id\_ubtdt, ubt\_dt(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2511 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2512     \textcolor{keywordflow}{if} (cs\%id\_vbtdt > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2513       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2514         vbt\_dt(i,j) = (vbt\_wtd(i,j) -\/ vbt\_st(i,j))*idt}
\DoxyCodeLine{2515 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2516       \textcolor{keyword}{call }post\_data(cs\%id\_vbtdt, vbt\_dt(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2517 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2518 }
\DoxyCodeLine{2519     \textcolor{keywordflow}{if} (cs\%id\_ubtforce > 0) \textcolor{keyword}{call }post\_data(cs\%id\_ubtforce, bt\_force\_u(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2520     \textcolor{keywordflow}{if} (cs\%id\_vbtforce > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vbtforce, bt\_force\_v(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2521     \textcolor{keywordflow}{if} (cs\%id\_uaccel > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uaccel, u\_accel\_bt(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2522     \textcolor{keywordflow}{if} (cs\%id\_vaccel > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vaccel, v\_accel\_bt(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2523 }
\DoxyCodeLine{2524     \textcolor{keywordflow}{if} (cs\%id\_eta\_cor > 0) \textcolor{keyword}{call }post\_data(cs\%id\_eta\_cor, cs\%eta\_cor, cs\%diag)}
\DoxyCodeLine{2525     \textcolor{keywordflow}{if} (cs\%id\_eta\_bt > 0) \textcolor{keyword}{call }post\_data(cs\%id\_eta\_bt, eta\_out, cs\%diag)}
\DoxyCodeLine{2526     \textcolor{keywordflow}{if} (cs\%id\_gtotn > 0) \textcolor{keyword}{call }post\_data(cs\%id\_gtotn, gtot\_n(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{2527     \textcolor{keywordflow}{if} (cs\%id\_gtots > 0) \textcolor{keyword}{call }post\_data(cs\%id\_gtots, gtot\_s(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{2528     \textcolor{keywordflow}{if} (cs\%id\_gtote > 0) \textcolor{keyword}{call }post\_data(cs\%id\_gtote, gtot\_e(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{2529     \textcolor{keywordflow}{if} (cs\%id\_gtotw > 0) \textcolor{keyword}{call }post\_data(cs\%id\_gtotw, gtot\_w(isd:ied,jsd:jed), cs\%diag)}
\DoxyCodeLine{2530     \textcolor{keywordflow}{if} (cs\%id\_ubt > 0) \textcolor{keyword}{call }post\_data(cs\%id\_ubt, ubt\_wtd(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2531     \textcolor{keywordflow}{if} (cs\%id\_vbt > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vbt, vbt\_wtd(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2532     \textcolor{keywordflow}{if} (cs\%id\_ubtav > 0) \textcolor{keyword}{call }post\_data(cs\%id\_ubtav, cs\%ubtav, cs\%diag)}
\DoxyCodeLine{2533     \textcolor{keywordflow}{if} (cs\%id\_vbtav > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vbtav, cs\%vbtav, cs\%diag)}
\DoxyCodeLine{2534     \textcolor{keywordflow}{if} (cs\%id\_visc\_rem\_u > 0) \textcolor{keyword}{call }post\_data(cs\%id\_visc\_rem\_u, visc\_rem\_u, cs\%diag)}
\DoxyCodeLine{2535     \textcolor{keywordflow}{if} (cs\%id\_visc\_rem\_v > 0) \textcolor{keyword}{call }post\_data(cs\%id\_visc\_rem\_v, visc\_rem\_v, cs\%diag)}
\DoxyCodeLine{2536 }
\DoxyCodeLine{2537     \textcolor{keywordflow}{if} (cs\%id\_frhatu > 0) \textcolor{keyword}{call }post\_data(cs\%id\_frhatu, cs\%frhatu, cs\%diag)}
\DoxyCodeLine{2538     \textcolor{keywordflow}{if} (cs\%id\_uhbt > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uhbt, uhbtav, cs\%diag)}
\DoxyCodeLine{2539     \textcolor{keywordflow}{if} (cs\%id\_frhatv > 0) \textcolor{keyword}{call }post\_data(cs\%id\_frhatv, cs\%frhatv, cs\%diag)}
\DoxyCodeLine{2540     \textcolor{keywordflow}{if} (cs\%id\_vhbt > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vhbt, vhbtav, cs\%diag)}
\DoxyCodeLine{2541     \textcolor{keywordflow}{if} (cs\%id\_uhbt0 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_uhbt0, uhbt0(isdb:iedb,jsd:jed), cs\%diag)}
\DoxyCodeLine{2542     \textcolor{keywordflow}{if} (cs\%id\_vhbt0 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_vhbt0, vhbt0(isd:ied,jsdb:jedb), cs\%diag)}
\DoxyCodeLine{2543 }
\DoxyCodeLine{2544     \textcolor{keywordflow}{if} (cs\%id\_frhatu1 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_frhatu1, cs\%frhatu1, cs\%diag)}
\DoxyCodeLine{2545     \textcolor{keywordflow}{if} (cs\%id\_frhatv1 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_frhatv1, cs\%frhatv1, cs\%diag)}
\DoxyCodeLine{2546 }
\DoxyCodeLine{2547     \textcolor{keywordflow}{if} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2548       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_u\_EE > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_u\_EE, bt\_cont\%FA\_u\_EE, cs\%diag)}
\DoxyCodeLine{2549       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_u\_E0 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_u\_E0, bt\_cont\%FA\_u\_E0, cs\%diag)}
\DoxyCodeLine{2550       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_u\_W0 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_u\_W0, bt\_cont\%FA\_u\_W0, cs\%diag)}
\DoxyCodeLine{2551       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_u\_WW > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_u\_WW, bt\_cont\%FA\_u\_WW, cs\%diag)}
\DoxyCodeLine{2552       \textcolor{keywordflow}{if} (cs\%id\_BTC\_uBT\_EE > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_uBT\_EE, bt\_cont\%uBT\_EE, cs\%diag)}
\DoxyCodeLine{2553       \textcolor{keywordflow}{if} (cs\%id\_BTC\_uBT\_WW > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_uBT\_WW, bt\_cont\%uBT\_WW, cs\%diag)}
\DoxyCodeLine{2554       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_u\_rat0 > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2555         tmp\_u(:,:) = 0.0}
\DoxyCodeLine{2556         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2557           \textcolor{keywordflow}{if} ((g\%mask2dCu(i,j) > 0.0) .and. (bt\_cont\%FA\_u\_W0(i,j) > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2558             tmp\_u(i,j) = (bt\_cont\%FA\_u\_E0(i,j)/ bt\_cont\%FA\_u\_W0(i,j))}
\DoxyCodeLine{2559           \textcolor{keywordflow}{else}}
\DoxyCodeLine{2560             tmp\_u(i,j) = 1.0}
\DoxyCodeLine{2561 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2562 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2563         \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_u\_rat0, tmp\_u, cs\%diag)}
\DoxyCodeLine{2564 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2565       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_v\_NN > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_v\_NN, bt\_cont\%FA\_v\_NN, cs\%diag)}
\DoxyCodeLine{2566       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_v\_N0 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_v\_N0, bt\_cont\%FA\_v\_N0, cs\%diag)}
\DoxyCodeLine{2567       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_v\_S0 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_v\_S0, bt\_cont\%FA\_v\_S0, cs\%diag)}
\DoxyCodeLine{2568       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_v\_SS > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_v\_SS, bt\_cont\%FA\_v\_SS, cs\%diag)}
\DoxyCodeLine{2569       \textcolor{keywordflow}{if} (cs\%id\_BTC\_vBT\_NN > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_vBT\_NN, bt\_cont\%vBT\_NN, cs\%diag)}
\DoxyCodeLine{2570       \textcolor{keywordflow}{if} (cs\%id\_BTC\_vBT\_SS > 0) \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_vBT\_SS, bt\_cont\%vBT\_SS, cs\%diag)}
\DoxyCodeLine{2571       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_v\_rat0 > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2572         tmp\_v(:,:) = 0.0}
\DoxyCodeLine{2573         \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2574           \textcolor{keywordflow}{if} ((g\%mask2dCv(i,j) > 0.0) .and. (bt\_cont\%FA\_v\_S0(i,j) > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2575             tmp\_v(i,j) = (bt\_cont\%FA\_v\_N0(i,j)/ bt\_cont\%FA\_v\_S0(i,j))}
\DoxyCodeLine{2576           \textcolor{keywordflow}{else}}
\DoxyCodeLine{2577             tmp\_v(i,j) = 1.0}
\DoxyCodeLine{2578 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2579 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2580         \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_v\_rat0, tmp\_v, cs\%diag)}
\DoxyCodeLine{2581 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2582       \textcolor{keywordflow}{if} (cs\%id\_BTC\_FA\_h\_rat0 > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2583         tmp\_h(:,:) = 0.0}
\DoxyCodeLine{2584         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2585           tmp\_h(i,j) = 1.0}
\DoxyCodeLine{2586           \textcolor{keywordflow}{if} ((g\%mask2dCu(i,j) > 0.0) .and. (bt\_cont\%FA\_u\_W0(i,j) > 0.0) .and. (bt\_cont\%FA\_u\_E0(i,j) > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2587             \textcolor{keywordflow}{if} (bt\_cont\%FA\_u\_W0(i,j) > bt\_cont\%FA\_u\_E0(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2588               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_u\_W0(i,j)/ bt\_cont\%FA\_u\_E0(i,j)))}
\DoxyCodeLine{2589             \textcolor{keywordflow}{else}}
\DoxyCodeLine{2590               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_u\_E0(i,j)/ bt\_cont\%FA\_u\_W0(i,j)))}
\DoxyCodeLine{2591 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{2592 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2593           \textcolor{keywordflow}{if} ((g\%mask2dCu(i-\/1,j) > 0.0) .and. (bt\_cont\%FA\_u\_W0(i-\/1,j) > 0.0) .and. (bt\_cont\%FA\_u\_E0(i-\/1,j) > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2594             \textcolor{keywordflow}{if} (bt\_cont\%FA\_u\_W0(i-\/1,j) > bt\_cont\%FA\_u\_E0(i-\/1,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2595               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_u\_W0(i-\/1,j)/ bt\_cont\%FA\_u\_E0(i-\/1,j)))}
\DoxyCodeLine{2596             \textcolor{keywordflow}{else}}
\DoxyCodeLine{2597               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_u\_E0(i-\/1,j)/ bt\_cont\%FA\_u\_W0(i-\/1,j)))}
\DoxyCodeLine{2598 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{2599 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2600           \textcolor{keywordflow}{if} ((g\%mask2dCv(i,j) > 0.0) .and. (bt\_cont\%FA\_v\_S0(i,j) > 0.0) .and. (bt\_cont\%FA\_v\_N0(i,j) > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2601             \textcolor{keywordflow}{if} (bt\_cont\%FA\_v\_S0(i,j) > bt\_cont\%FA\_v\_N0(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2602               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_v\_S0(i,j)/ bt\_cont\%FA\_v\_N0(i,j)))}
\DoxyCodeLine{2603             \textcolor{keywordflow}{else}}
\DoxyCodeLine{2604               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_v\_N0(i,j)/ bt\_cont\%FA\_v\_S0(i,j)))}
\DoxyCodeLine{2605 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{2606 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2607           \textcolor{keywordflow}{if} ((g\%mask2dCv(i,j-\/1) > 0.0) .and. (bt\_cont\%FA\_v\_S0(i,j-\/1) > 0.0) .and. (bt\_cont\%FA\_v\_N0(i,j-\/1) > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2608             \textcolor{keywordflow}{if} (bt\_cont\%FA\_v\_S0(i,j-\/1) > bt\_cont\%FA\_v\_N0(i,j-\/1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2609               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_v\_S0(i,j-\/1)/ bt\_cont\%FA\_v\_N0(i,j-\/1)))}
\DoxyCodeLine{2610             \textcolor{keywordflow}{else}}
\DoxyCodeLine{2611               tmp\_h(i,j) = max(tmp\_h(i,j), (bt\_cont\%FA\_v\_N0(i,j-\/1)/ bt\_cont\%FA\_v\_S0(i,j-\/1)))}
\DoxyCodeLine{2612 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{2613 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{2614 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2615         \textcolor{keyword}{call }post\_data(cs\%id\_BTC\_FA\_h\_rat0, tmp\_h, cs\%diag)}
\DoxyCodeLine{2616 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2617 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2618   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2619     \textcolor{keywordflow}{if} (cs\%id\_frhatu1 > 0) cs\%frhatu1(:,:,:) = cs\%frhatu(:,:,:)}
\DoxyCodeLine{2620     \textcolor{keywordflow}{if} (cs\%id\_frhatv1 > 0) cs\%frhatv1(:,:,:) = cs\%frhatv(:,:,:)}
\DoxyCodeLine{2621 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2622 }
\DoxyCodeLine{2623   \textcolor{keywordflow}{if} ((\textcolor{keyword}{present}(adp)) .and. (\textcolor{keyword}{associated}(adp\%diag\_hfrac\_u))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2624     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{2625       adp\%diag\_hfrac\_u(i,j,k) = cs\%frhatu(i,j,k)}
\DoxyCodeLine{2626 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2627 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2628   \textcolor{keywordflow}{if} ((\textcolor{keyword}{present}(adp)) .and. (\textcolor{keyword}{associated}(adp\%diag\_hfrac\_v))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2629     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2630       adp\%diag\_hfrac\_v(i,j,k) = cs\%frhatv(i,j,k)}
\DoxyCodeLine{2631 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2632 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2633 }
\DoxyCodeLine{2634   \textcolor{keywordflow}{if} (g\%nonblocking\_updates) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2635     \textcolor{keywordflow}{if} (find\_etaav) \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_etaav, g\%Domain)}
\DoxyCodeLine{2636     \textcolor{keyword}{call }complete\_group\_pass(cs\%pass\_ubta\_uhbta, g\%Domain)}
\DoxyCodeLine{2637 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2638 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_ac8250401fa646cce0f3108587caf19be}\label{namespacemom__barotropic_ac8250401fa646cce0f3108587caf19be}} 
\index{mom\_barotropic@{mom\_barotropic}!destroy\_bt\_obc@{destroy\_bt\_obc}}
\index{destroy\_bt\_obc@{destroy\_bt\_obc}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{destroy\_bt\_obc()}{destroy\_bt\_obc()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::destroy\+\_\+bt\+\_\+obc (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1bt__obc__type}{bt\+\_\+obc\+\_\+type}}), intent(inout)}]{B\+T\+\_\+\+O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Clean up the B\+T\+\_\+\+O\+BC memory. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+obc} & A structure with the private barotropic arrays related to the open boundary conditions, set by set\+\_\+up\+\_\+\+B\+T\+\_\+\+O\+BC. \\
\hline
\end{DoxyParams}


Definition at line 3157 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3158   \textcolor{keywordtype}{type}(BT\_OBC\_type), \textcolor{keywordtype}{intent(inout)} :: BT\_OBC\textcolor{comment}{ !< A structure with the private barotropic arrays}}
\DoxyCodeLine{3159 \textcolor{comment}{                                             !! related to the open boundary conditions,}}
\DoxyCodeLine{3160 \textcolor{comment}{                                             !! set by set\_up\_BT\_OBC.}}
\DoxyCodeLine{3161 }
\DoxyCodeLine{3162   \textcolor{keywordflow}{if} (bt\_obc\%is\_alloced) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3163     \textcolor{keyword}{deallocate}(bt\_obc\%Cg\_u)}
\DoxyCodeLine{3164     \textcolor{keyword}{deallocate}(bt\_obc\%H\_u)}
\DoxyCodeLine{3165     \textcolor{keyword}{deallocate}(bt\_obc\%uhbt)}
\DoxyCodeLine{3166     \textcolor{keyword}{deallocate}(bt\_obc\%ubt\_outer)}
\DoxyCodeLine{3167     \textcolor{keyword}{deallocate}(bt\_obc\%eta\_outer\_u)}
\DoxyCodeLine{3168 }
\DoxyCodeLine{3169     \textcolor{keyword}{deallocate}(bt\_obc\%Cg\_v)}
\DoxyCodeLine{3170     \textcolor{keyword}{deallocate}(bt\_obc\%H\_v)}
\DoxyCodeLine{3171     \textcolor{keyword}{deallocate}(bt\_obc\%vhbt)}
\DoxyCodeLine{3172     \textcolor{keyword}{deallocate}(bt\_obc\%vbt\_outer)}
\DoxyCodeLine{3173     \textcolor{keyword}{deallocate}(bt\_obc\%eta\_outer\_v)}
\DoxyCodeLine{3174     bt\_obc\%is\_alloced = .false.}
\DoxyCodeLine{3175 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_abcc5b7bef6e5c17630b05962d61995e3}\label{namespacemom__barotropic_abcc5b7bef6e5c17630b05962d61995e3}} 
\index{mom\_barotropic@{mom\_barotropic}!find\_duhbt\_du@{find\_duhbt\_du}}
\index{find\_duhbt\_du@{find\_duhbt\_du}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{find\_duhbt\_du()}{find\_duhbt\_du()}}
{\footnotesize\ttfamily real function mom\+\_\+barotropic\+::find\+\_\+duhbt\+\_\+du (\begin{DoxyParamCaption}\item[{real, intent(in)}]{u,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), intent(in)}]{B\+TC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The function find\+\_\+duhbt\+\_\+du determines the marginal zonal face area for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True for a given time-\/integrated velocity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em u} & The local zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or time integrated velocity \mbox{[}L $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em btc} & A structure containing various fields that allow the barotropic transports to be calculated consistently with the layers\textquotesingle{} continuity equations. The dimensions of some of the elements in this type vary depending on I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The zonal barotropic face area \mbox{[}L H $\sim$$>$ m2\mbox{]} 
\end{DoxyReturn}


Definition at line 3483 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3484 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: u\textcolor{comment}{    !< The local zonal velocity [L T-\/1 \string~> m s-\/1] or time integrated velocity [L \string~> m]}}
\DoxyCodeLine{3485   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{intent(in)} :: BTC\textcolor{comment}{ !< A structure containing various fields that}}
\DoxyCodeLine{3486 \textcolor{comment}{                           !! allow the barotropic transports to be calculated consistently}}
\DoxyCodeLine{3487 \textcolor{comment}{                           !! with the layers' continuity equations.  The dimensions of some}}
\DoxyCodeLine{3488 \textcolor{comment}{                           !! of the elements in this type vary depending on INTEGRAL\_BT\_CONT.}}
\DoxyCodeLine{3489 \textcolor{keywordtype}{  real} :: duhbt\_du\textcolor{comment}{ !< The zonal barotropic face area [L H \string~> m2]}}
\DoxyCodeLine{3490 }
\DoxyCodeLine{3491   \textcolor{keywordflow}{if} (u == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3492     duhbt\_du = 0.5*(btc\%FA\_u\_E0 + btc\%FA\_u\_W0)  \textcolor{comment}{! Note the potential discontinuity here.}}
\DoxyCodeLine{3493   \textcolor{keywordflow}{elseif} (u < btc\%uBT\_EE) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3494     duhbt\_du = btc\%FA\_u\_EE}
\DoxyCodeLine{3495   \textcolor{keywordflow}{elseif} (u < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3496     duhbt\_du = (btc\%FA\_u\_E0 + 3.0*btc\%uh\_crvE * u**2)}
\DoxyCodeLine{3497   \textcolor{keywordflow}{elseif} (u <= btc\%uBT\_WW) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3498     duhbt\_du = (btc\%FA\_u\_W0 + 3.0*btc\%uh\_crvW * u**2)}
\DoxyCodeLine{3499   \textcolor{keywordflow}{else} \textcolor{comment}{! (u > BTC\%uBT\_WW)}}
\DoxyCodeLine{3500     duhbt\_du = btc\%FA\_u\_WW}
\DoxyCodeLine{3501 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3502 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a951d827a745c277e8950a091c060ee86}\label{namespacemom__barotropic_a951d827a745c277e8950a091c060ee86}} 
\index{mom\_barotropic@{mom\_barotropic}!find\_dvhbt\_dv@{find\_dvhbt\_dv}}
\index{find\_dvhbt\_dv@{find\_dvhbt\_dv}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{find\_dvhbt\_dv()}{find\_dvhbt\_dv()}}
{\footnotesize\ttfamily real function mom\+\_\+barotropic\+::find\+\_\+dvhbt\+\_\+dv (\begin{DoxyParamCaption}\item[{real, intent(in)}]{v,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), intent(in)}]{B\+TC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The function find\+\_\+dvhbt\+\_\+dv determines the marginal meridional face area for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True for a given time-\/integrated velocity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em v} & The local meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or time integrated velocity \mbox{[}L $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em btc} & A structure containing various fields that allow the barotropic transports to be calculated consistently with the layers\textquotesingle{} continuity equations. The dimensions of some of the elements in this type vary depending on I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The meridional barotropic face area \mbox{[}L H $\sim$$>$ m2\mbox{]} 
\end{DoxyReturn}


Definition at line 3632 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3633 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: v\textcolor{comment}{    !< The local meridional velocity [L T-\/1 \string~> m s-\/1] or time integrated velocity [L \string~> m]}}
\DoxyCodeLine{3634   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{intent(in)} :: BTC\textcolor{comment}{ !< A structure containing various fields that}}
\DoxyCodeLine{3635 \textcolor{comment}{                           !! allow the barotropic transports to be calculated consistently}}
\DoxyCodeLine{3636 \textcolor{comment}{                           !! with the layers' continuity equations.  The dimensions of some}}
\DoxyCodeLine{3637 \textcolor{comment}{                           !! of the elements in this type vary depending on INTEGRAL\_BT\_CONT.}}
\DoxyCodeLine{3638 \textcolor{keywordtype}{  real} :: dvhbt\_dv\textcolor{comment}{ !< The meridional barotropic face area [L H \string~> m2]}}
\DoxyCodeLine{3639 }
\DoxyCodeLine{3640   \textcolor{keywordflow}{if} (v == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3641     dvhbt\_dv = 0.5*(btc\%FA\_v\_N0 + btc\%FA\_v\_S0)  \textcolor{comment}{! Note the potential discontinuity here.}}
\DoxyCodeLine{3642   \textcolor{keywordflow}{elseif} (v < btc\%vBT\_NN) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3643     dvhbt\_dv = btc\%FA\_v\_NN}
\DoxyCodeLine{3644   \textcolor{keywordflow}{elseif} (v < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3645     dvhbt\_dv = btc\%FA\_v\_N0 + 3.0*btc\%vh\_crvN * v**2}
\DoxyCodeLine{3646   \textcolor{keywordflow}{elseif} (v <= btc\%vBT\_SS) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3647     dvhbt\_dv = btc\%FA\_v\_S0 + 3.0*btc\%vh\_crvS * v**2}
\DoxyCodeLine{3648   \textcolor{keywordflow}{else} \textcolor{comment}{! (v > BTC\%vBT\_SS)}}
\DoxyCodeLine{3649     dvhbt\_dv = btc\%FA\_v\_SS}
\DoxyCodeLine{3650 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3651 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_aba29d11dc2530622be997c069fb932ae}\label{namespacemom__barotropic_aba29d11dc2530622be997c069fb932ae}} 
\index{mom\_barotropic@{mom\_barotropic}!find\_face\_areas@{find\_face\_areas}}
\index{find\_face\_areas@{find\_face\_areas}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{find\_face\_areas()}{find\_face\_areas()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::find\+\_\+face\+\_\+areas (\begin{DoxyParamCaption}\item[{real, dimension(ms\%isdw-\/1\+:ms\%iedw,ms\%jsdw\+:ms\%jedw), intent(out)}]{Datu,  }\item[{real, dimension(ms\%isdw\+:ms\%iedw,ms\%jsdw-\/1\+:ms\%jedw), intent(out)}]{Datv,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}), intent(in)}]{MS,  }\item[{real, dimension(ms\%isdw\+:ms\%iedw,ms\%jsdw\+:ms\%jedw), intent(in), optional}]{eta,  }\item[{integer, intent(in), optional}]{halo,  }\item[{real, intent(in), optional}]{add\+\_\+max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine determines the open face areas of cells for calculating the barotropic transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ms} & A type that describes the memory sizes of the argument arrays. \\
\hline
\mbox{\texttt{ out}}  & {\em datu} & The open zonal face area \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em datv} & The open meridional face area \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to barotropic\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & The barotropic free surface height anomaly \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & The halo size to use, default = 1. \\
\hline
\mbox{\texttt{ in}}  & {\em add\+\_\+max} & A value to add to the maximum depth (used to overestimate the external wave speed) \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 4048 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4049   \textcolor{keywordtype}{type}(memory\_size\_type),  \textcolor{keywordtype}{intent(in)} :: MS\textcolor{comment}{    !< A type that describes the memory sizes of the argument arrays.}}
\DoxyCodeLine{4050 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(MS\%isdw-\/1:MS\%iedw,MS\%jsdw:MS\%jedw)}, \&}
\DoxyCodeLine{4051                            \textcolor{keywordtype}{intent(out)} :: Datu\textcolor{comment}{ !< The open zonal face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{4052 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(MS\%isdw:MS\%iedw,MS\%jsdw-\/1:MS\%jedw)}, \&}
\DoxyCodeLine{4053                            \textcolor{keywordtype}{intent(out)} :: Datv\textcolor{comment}{ !< The open meridional face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{4054   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{4055   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure.}}
\DoxyCodeLine{4056   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{4057   \textcolor{keywordtype}{type}(barotropic\_CS),     \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{   !< The control structure returned by a previous}}
\DoxyCodeLine{4058 \textcolor{comment}{                                               !! call to barotropic\_init.}}
\DoxyCodeLine{4059 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(MS\%isdw:MS\%iedw,MS\%jsdw:MS\%jedw)}, \&}
\DoxyCodeLine{4060                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: eta\textcolor{comment}{  !< The barotropic free surface height anomaly}}
\DoxyCodeLine{4061 \textcolor{comment}{                                               !! or column mass anomaly [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4062   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\textcolor{comment}{ !< The halo size to use, default = 1.}}
\DoxyCodeLine{4063 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: add\_max\textcolor{comment}{ !< A value to add to the maximum depth (used}}
\DoxyCodeLine{4064 \textcolor{comment}{                                               !! to overestimate the external wave speed) [Z \string~> m].}}
\DoxyCodeLine{4065 }
\DoxyCodeLine{4066   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{4067 \textcolor{keywordtype}{  real} :: H1, H2      \textcolor{comment}{! Temporary total thicknesses [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{4068   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, hs}
\DoxyCodeLine{4069   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{4070   hs = 1 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) hs = max(halo,0)}
\DoxyCodeLine{4071 }
\DoxyCodeLine{4072 \textcolor{comment}{!\$OMP parallel default(none) shared(is,ie,js,je,hs,eta,GV,CS,Datu,Datv,add\_max) \&}}
\DoxyCodeLine{4073 \textcolor{comment}{!\$OMP                       private(H1,H2)}}
\DoxyCodeLine{4074   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(eta)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4075     \textcolor{comment}{! The use of harmonic mean thicknesses ensure positive definiteness.}}
\DoxyCodeLine{4076     \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4077 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4078       \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/1-\/hs,ie+hs}
\DoxyCodeLine{4079         h1 = cs\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j) ; h2 = cs\%bathyT(i+1,j)*gv\%Z\_to\_H + eta(i+1,j)}
\DoxyCodeLine{4080         datu(i,j) = 0.0 ; \textcolor{keywordflow}{if} ((h1 > 0.0) .and. (h2 > 0.0)) \&}
\DoxyCodeLine{4081         datu(i,j) = cs\%dy\_Cu(i,j) * (2.0 * h1 * h2) / (h1 + h2)}
\DoxyCodeLine{4082 \textcolor{comment}{!       Datu(I,j) = CS\%dy\_Cu(I,j) * 0.5 * (H1 + H2)}}
\DoxyCodeLine{4083 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4084 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4085       \textcolor{keywordflow}{do} j=js-\/1-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{4086         h1 = cs\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j) ; h2 = cs\%bathyT(i,j+1)*gv\%Z\_to\_H + eta(i,j+1)}
\DoxyCodeLine{4087         datv(i,j) = 0.0 ; \textcolor{keywordflow}{if} ((h1 > 0.0) .and. (h2 > 0.0)) \&}
\DoxyCodeLine{4088         datv(i,j) = cs\%dx\_Cv(i,j) * (2.0 * h1 * h2) / (h1 + h2)}
\DoxyCodeLine{4089 \textcolor{comment}{!       Datv(i,J) = CS\%dy\_v(i,J) * 0.5 * (H1 + H2)}}
\DoxyCodeLine{4090 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4091     \textcolor{keywordflow}{else}}
\DoxyCodeLine{4092 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4093       \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/1-\/hs,ie+hs}
\DoxyCodeLine{4094         datu(i,j) = 0.0 ; \textcolor{keywordflow}{if} ((eta(i,j) > 0.0) .and. (eta(i+1,j) > 0.0)) \&}
\DoxyCodeLine{4095         datu(i,j) = cs\%dy\_Cu(i,j) * (2.0 * eta(i,j) * eta(i+1,j)) / \&}
\DoxyCodeLine{4096                                   (eta(i,j) + eta(i+1,j))}
\DoxyCodeLine{4097         \textcolor{comment}{! Datu(I,j) = CS\%dy\_Cu(I,j) * 0.5 * (eta(i,j) + eta(i+1,j))}}
\DoxyCodeLine{4098 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4099 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4100       \textcolor{keywordflow}{do} j=js-\/1-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{4101         datv(i,j) = 0.0 ; \textcolor{keywordflow}{if} ((eta(i,j) > 0.0) .and. (eta(i,j+1) > 0.0)) \&}
\DoxyCodeLine{4102         datv(i,j) = cs\%dx\_Cv(i,j) * (2.0 * eta(i,j) * eta(i,j+1)) / \&}
\DoxyCodeLine{4103                                   (eta(i,j) + eta(i,j+1))}
\DoxyCodeLine{4104         \textcolor{comment}{! Datv(i,J) = CS\%dy\_v(i,J) * 0.5 * (eta(i,j) + eta(i,j+1))}}
\DoxyCodeLine{4105 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4106 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{4107   \textcolor{keywordflow}{elseif} (\textcolor{keyword}{present}(add\_max)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4108 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4109     \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/1-\/hs,ie+hs}
\DoxyCodeLine{4110       datu(i,j) = cs\%dy\_Cu(i,j) * gv\%Z\_to\_H * \&}
\DoxyCodeLine{4111                  (max(cs\%bathyT(i+1,j), cs\%bathyT(i,j)) + add\_max)}
\DoxyCodeLine{4112 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4113 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4114     \textcolor{keywordflow}{do} j=js-\/1-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{4115       datv(i,j) = cs\%dx\_Cv(i,j) * gv\%Z\_to\_H * \&}
\DoxyCodeLine{4116                  (max(cs\%bathyT(i,j+1), cs\%bathyT(i,j)) + add\_max)}
\DoxyCodeLine{4117 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4118   \textcolor{keywordflow}{else}}
\DoxyCodeLine{4119 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4120     \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/1-\/hs,ie+hs}
\DoxyCodeLine{4121       datu(i, j) = 0.0}
\DoxyCodeLine{4122       \textcolor{comment}{!Would be "{}if (G\%mask2dCu(I,j)>0.) \&"{} is G was valid on BT domain}}
\DoxyCodeLine{4123       \textcolor{keywordflow}{if} (cs\%bathyT(i+1,j)+cs\%bathyT(i,j)>0.) \&}
\DoxyCodeLine{4124         datu(i,j) = 2.0*cs\%dy\_Cu(i,j) * gv\%Z\_to\_H * \&}
\DoxyCodeLine{4125                   (cs\%bathyT(i+1,j) * cs\%bathyT(i,j)) / \&}
\DoxyCodeLine{4126                   (cs\%bathyT(i+1,j) + cs\%bathyT(i,j))}
\DoxyCodeLine{4127 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4128 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{4129     \textcolor{keywordflow}{do} j=js-\/1-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{4130       datv(i, j) = 0.0}
\DoxyCodeLine{4131       \textcolor{comment}{!Would be "{}if (G\%mask2dCv(i,J)>0.) \&"{} is G was valid on BT domain}}
\DoxyCodeLine{4132       \textcolor{keywordflow}{if} (cs\%bathyT(i,j+1)+cs\%bathyT(i,j)>0.) \&}
\DoxyCodeLine{4133         datv(i,j) = 2.0*cs\%dx\_Cv(i,j) * gv\%Z\_to\_H * \&}
\DoxyCodeLine{4134                   (cs\%bathyT(i,j+1) * cs\%bathyT(i,j)) / \&}
\DoxyCodeLine{4135                   (cs\%bathyT(i,j+1) + cs\%bathyT(i,j))}
\DoxyCodeLine{4136 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4137 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4138 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{4139 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a8ad2b12e885746401a97fd65ad189722}\label{namespacemom__barotropic_a8ad2b12e885746401a97fd65ad189722}} 
\index{mom\_barotropic@{mom\_barotropic}!find\_uhbt@{find\_uhbt}}
\index{find\_uhbt@{find\_uhbt}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{find\_uhbt()}{find\_uhbt()}}
{\footnotesize\ttfamily real function mom\+\_\+barotropic\+::find\+\_\+uhbt (\begin{DoxyParamCaption}\item[{real, intent(in)}]{u,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), intent(in)}]{B\+TC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The function find\+\_\+uhbt determines the zonal transport for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True it determines the time-\/integrated zonal transport for a given time-\/integrated velocity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em u} & The local zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or time integrated velocity \mbox{[}L $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em btc} & A structure containing various fields that allow the barotropic transports to be calculated consistently with the layers\textquotesingle{} continuity equations. The dimensions of some of the elements in this type vary depending on I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The zonal barotropic transport \mbox{[}L2 H T-\/1 $\sim$$>$ m3 s-\/1\mbox{]} or time integrated transport \mbox{[}L2 H $\sim$$>$ m3\mbox{]} 
\end{DoxyReturn}


Definition at line 3458 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3459 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: u\textcolor{comment}{    !< The local zonal velocity [L T-\/1 \string~> m s-\/1] or time integrated velocity [L \string~> m]}}
\DoxyCodeLine{3460   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{intent(in)} :: BTC\textcolor{comment}{ !< A structure containing various fields that}}
\DoxyCodeLine{3461 \textcolor{comment}{                           !! allow the barotropic transports to be calculated consistently}}
\DoxyCodeLine{3462 \textcolor{comment}{                           !! with the layers' continuity equations.  The dimensions of some}}
\DoxyCodeLine{3463 \textcolor{comment}{                           !! of the elements in this type vary depending on INTEGRAL\_BT\_CONT.}}
\DoxyCodeLine{3464 }
\DoxyCodeLine{3465 \textcolor{keywordtype}{  real} :: uhbt\textcolor{comment}{ !< The zonal barotropic transport [L2 H T-\/1 \string~> m3 s-\/1] or time integrated transport [L2 H \string~> m3]}}
\DoxyCodeLine{3466 }
\DoxyCodeLine{3467   \textcolor{keywordflow}{if} (u == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3468     uhbt = 0.0}
\DoxyCodeLine{3469   \textcolor{keywordflow}{elseif} (u < btc\%uBT\_EE) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3470     uhbt = (u -\/ btc\%uBT\_EE) * btc\%FA\_u\_EE + btc\%uh\_EE}
\DoxyCodeLine{3471   \textcolor{keywordflow}{elseif} (u < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3472     uhbt = u * (btc\%FA\_u\_E0 + btc\%uh\_crvE * u**2)}
\DoxyCodeLine{3473   \textcolor{keywordflow}{elseif} (u <= btc\%uBT\_WW) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3474     uhbt = u * (btc\%FA\_u\_W0 + btc\%uh\_crvW * u**2)}
\DoxyCodeLine{3475   \textcolor{keywordflow}{else} \textcolor{comment}{! (u > BTC\%uBT\_WW)}}
\DoxyCodeLine{3476     uhbt = (u -\/ btc\%uBT\_WW) * btc\%FA\_u\_WW + btc\%uh\_WW}
\DoxyCodeLine{3477 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3478 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_ae96b701027f6f77feed0f68515b31e55}\label{namespacemom__barotropic_ae96b701027f6f77feed0f68515b31e55}} 
\index{mom\_barotropic@{mom\_barotropic}!find\_vhbt@{find\_vhbt}}
\index{find\_vhbt@{find\_vhbt}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{find\_vhbt()}{find\_vhbt()}}
{\footnotesize\ttfamily real function mom\+\_\+barotropic\+::find\+\_\+vhbt (\begin{DoxyParamCaption}\item[{real, intent(in)}]{v,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), intent(in)}]{B\+TC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The function find\+\_\+vhbt determines the meridional transport for a given velocity, or with I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True it determines the time-\/integrated meridional transport for a given time-\/integrated velocity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em v} & The local meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or time integrated velocity \mbox{[}L $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em btc} & A structure containing various fields that allow the barotropic transports to be calculated consistently with the layers\textquotesingle{} continuity equations. The dimensions of some of the elements in this type vary depending on I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The meridional barotropic transport \mbox{[}L2 H T-\/1 $\sim$$>$ m3 s-\/1\mbox{]} or time integrated transport \mbox{[}L2 H $\sim$$>$ m3\mbox{]} 
\end{DoxyReturn}


Definition at line 3608 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3609 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: v\textcolor{comment}{    !< The local meridional velocity [L T-\/1 \string~> m s-\/1] or time integrated velocity [L \string~> m]}}
\DoxyCodeLine{3610   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{intent(in)} :: BTC\textcolor{comment}{ !< A structure containing various fields that}}
\DoxyCodeLine{3611 \textcolor{comment}{                           !! allow the barotropic transports to be calculated consistently}}
\DoxyCodeLine{3612 \textcolor{comment}{                           !! with the layers' continuity equations.  The dimensions of some}}
\DoxyCodeLine{3613 \textcolor{comment}{                           !! of the elements in this type vary depending on INTEGRAL\_BT\_CONT.}}
\DoxyCodeLine{3614 \textcolor{keywordtype}{  real} :: vhbt\textcolor{comment}{ !< The meridional barotropic transport [L2 H T-\/1 \string~> m3 s-\/1] or time integrated transport [L2 H \string~> m3]}}
\DoxyCodeLine{3615 }
\DoxyCodeLine{3616   \textcolor{keywordflow}{if} (v == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3617     vhbt = 0.0}
\DoxyCodeLine{3618   \textcolor{keywordflow}{elseif} (v < btc\%vBT\_NN) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3619     vhbt = (v -\/ btc\%vBT\_NN) * btc\%FA\_v\_NN + btc\%vh\_NN}
\DoxyCodeLine{3620   \textcolor{keywordflow}{elseif} (v < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3621     vhbt = v * (btc\%FA\_v\_N0 + btc\%vh\_crvN * v**2)}
\DoxyCodeLine{3622   \textcolor{keywordflow}{elseif} (v <= btc\%vBT\_SS) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3623     vhbt = v * (btc\%FA\_v\_S0 + btc\%vh\_crvS * v**2)}
\DoxyCodeLine{3624   \textcolor{keywordflow}{else} \textcolor{comment}{! (v > BTC\%vBT\_SS)}}
\DoxyCodeLine{3625     vhbt = (v -\/ btc\%vBT\_SS) * btc\%FA\_v\_SS + btc\%vh\_SS}
\DoxyCodeLine{3626 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3627 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a28fa2e7600a471735c3b827ac08ed94b}\label{namespacemom__barotropic_a28fa2e7600a471735c3b827ac08ed94b}} 
\index{mom\_barotropic@{mom\_barotropic}!register\_barotropic\_restarts@{register\_barotropic\_restarts}}
\index{register\_barotropic\_restarts@{register\_barotropic\_restarts}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{register\_barotropic\_restarts()}{register\_barotropic\_restarts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::register\+\_\+barotropic\+\_\+restarts (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__hor__index_1_1hor__index__type}{hor\+\_\+index\+\_\+type}}), intent(in)}]{HI,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__restart_1_1mom__restart__cs}{mom\+\_\+restart\+\_\+cs}}), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



This subroutine is used to register any fields from \mbox{\hyperlink{MOM__barotropic_8F90_source}{M\+O\+M\+\_\+barotropic.\+F90}} that should be written to or read from the restart file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & A horizontal index type structure. \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters. \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure. \\
\hline
\end{DoxyParams}


Definition at line 4964 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4965   \textcolor{keywordtype}{type}(hor\_index\_type),    \textcolor{keywordtype}{intent(in)} :: HI\textcolor{comment}{         !< A horizontal index type structure.}}
\DoxyCodeLine{4966   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-\/time parameters.}}
\DoxyCodeLine{4967   \textcolor{keywordtype}{type}(barotropic\_CS),     \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{         !< A pointer that is set to point to the control}}
\DoxyCodeLine{4968 \textcolor{comment}{                                                    !! structure for this module.}}
\DoxyCodeLine{4969   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{         !< The ocean's vertical grid structure.}}
\DoxyCodeLine{4970   \textcolor{keywordtype}{type}(MOM\_restart\_CS),    \textcolor{keywordtype}{pointer}    :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure.}}
\DoxyCodeLine{4971 }
\DoxyCodeLine{4972   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{4973   \textcolor{keywordtype}{type}(vardesc) :: vd(3)}
\DoxyCodeLine{4974   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}MOM\_barotropic"{}}  \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{4975   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{4976 }
\DoxyCodeLine{4977   isd = hi\%isd ; ied = hi\%ied ; jsd = hi\%jsd ; jed = hi\%jed}
\DoxyCodeLine{4978   isdb = hi\%IsdB ; iedb = hi\%IedB ; jsdb = hi\%JsdB ; jedb = hi\%JedB}
\DoxyCodeLine{4979 }
\DoxyCodeLine{4980   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4981     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}register\_barotropic\_restarts called with an associated "{}}// \&}
\DoxyCodeLine{4982                             \textcolor{stringliteral}{"{}control structure."{}})}
\DoxyCodeLine{4983     \textcolor{keywordflow}{return}}
\DoxyCodeLine{4984 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4985   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{4986 }
\DoxyCodeLine{4987   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}GRADUAL\_BT\_ICS"{}}, cs\%gradual\_BT\_ICs, \&}
\DoxyCodeLine{4988                  \textcolor{stringliteral}{"{}If true, adjust the initial conditions for the "{}}//\&}
\DoxyCodeLine{4989                  \textcolor{stringliteral}{"{}barotropic solver to the values from the layered "{}}//\&}
\DoxyCodeLine{4990                  \textcolor{stringliteral}{"{}solution over a whole timestep instead of instantly. "{}}//\&}
\DoxyCodeLine{4991                  \textcolor{stringliteral}{"{}This is a decent approximation to the inclusion of "{}}//\&}
\DoxyCodeLine{4992                  \textcolor{stringliteral}{"{}sum(u dh\_dt) while also correcting for truncation errors."{}}, \&}
\DoxyCodeLine{4993                  default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{4994 }
\DoxyCodeLine{4995   alloc\_(cs\%ubtav(isdb:iedb,jsd:jed))      ; cs\%ubtav(:,:) = 0.0}
\DoxyCodeLine{4996   alloc\_(cs\%vbtav(isd:ied,jsdb:jedb))      ; cs\%vbtav(:,:) = 0.0}
\DoxyCodeLine{4997   \textcolor{keywordflow}{if} (cs\%gradual\_BT\_ICs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4998     alloc\_(cs\%ubt\_IC(isdb:iedb,jsd:jed))     ; cs\%ubt\_IC(:,:) = 0.0}
\DoxyCodeLine{4999     alloc\_(cs\%vbt\_IC(isd:ied,jsdb:jedb))     ; cs\%vbt\_IC(:,:) = 0.0}
\DoxyCodeLine{5000 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{5001 }
\DoxyCodeLine{5002   vd(2) = var\_desc(\textcolor{stringliteral}{"{}ubtav"{}},\textcolor{stringliteral}{"{}m s-\/1"{}},\textcolor{stringliteral}{"{}Time mean barotropic zonal velocity"{}}, \&}
\DoxyCodeLine{5003                 hor\_grid=\textcolor{stringliteral}{'u'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{5004   vd(3) = var\_desc(\textcolor{stringliteral}{"{}vbtav"{}},\textcolor{stringliteral}{"{}m s-\/1"{}},\textcolor{stringliteral}{"{}Time mean barotropic meridional velocity"{}},\&}
\DoxyCodeLine{5005                 hor\_grid=\textcolor{stringliteral}{'v'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{5006   \textcolor{keyword}{call }register\_restart\_pair(cs\%ubtav, cs\%vbtav, vd(2), vd(3), .false., restart\_cs)}
\DoxyCodeLine{5007 }
\DoxyCodeLine{5008   \textcolor{keywordflow}{if} (cs\%gradual\_BT\_ICs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{5009     vd(2) = var\_desc(\textcolor{stringliteral}{"{}ubt\_IC"{}}, \textcolor{stringliteral}{"{}m s-\/1"{}}, \&}
\DoxyCodeLine{5010                 longname=\textcolor{stringliteral}{"{}Next initial condition for the barotropic zonal velocity"{}}, \&}
\DoxyCodeLine{5011                 hor\_grid=\textcolor{stringliteral}{'u'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{5012     vd(3) = var\_desc(\textcolor{stringliteral}{"{}vbt\_IC"{}}, \textcolor{stringliteral}{"{}m s-\/1"{}}, \&}
\DoxyCodeLine{5013                 longname=\textcolor{stringliteral}{"{}Next initial condition for the barotropic meridional velocity"{}},\&}
\DoxyCodeLine{5014                 hor\_grid=\textcolor{stringliteral}{'v'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{5015     \textcolor{keyword}{call }register\_restart\_pair(cs\%ubt\_IC, cs\%vbt\_IC, vd(2), vd(3), .false., restart\_cs)}
\DoxyCodeLine{5016 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{5017 }
\DoxyCodeLine{5018 }
\DoxyCodeLine{5019   \textcolor{keyword}{call }register\_restart\_field(cs\%dtbt, \textcolor{stringliteral}{"{}DTBT"{}}, .false., restart\_cs, \&}
\DoxyCodeLine{5020                               longname=\textcolor{stringliteral}{"{}Barotropic timestep"{}}, units=\textcolor{stringliteral}{"{}seconds"{}})}
\DoxyCodeLine{5021 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a486257b675aa4e81c2d1634b5288a67f}\label{namespacemom__barotropic_a486257b675aa4e81c2d1634b5288a67f}} 
\index{mom\_barotropic@{mom\_barotropic}!set\_dtbt@{set\_dtbt}}
\index{set\_dtbt@{set\_dtbt}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{set\_dtbt()}{set\_dtbt()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+barotropic\+::set\+\_\+dtbt (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1barotropic__cs}{barotropic\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{eta,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{pbce,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1bt__cont__type}{bt\+\_\+cont\+\_\+type}}), optional, pointer}]{B\+T\+\_\+cont,  }\item[{real, intent(in), optional}]{gtot\+\_\+est,  }\item[{real, intent(in), optional}]{S\+S\+H\+\_\+add }\end{DoxyParamCaption})}



This subroutine automatically determines an optimal value for dtbt based on some state of the ocean. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & Barotropic control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & The barotropic free surface height anomaly or column mass anomaly \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em pbce} & The baroclinic pressure anomaly in each layer due to free surface height anomalies \mbox{[}L2 H-\/1 T-\/2 $\sim$$>$ m s-\/2 or m4 kg-\/1 s-\/2\mbox{]}. \\
\hline
 & {\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 gtot\+\_\+est} & An estimate of the total gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ssh\+\_\+add} & An additional contribution to S\+SH to provide a margin of error when calculating the external wave speed \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 2643 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2644   \textcolor{keywordtype}{type}(ocean\_grid\_type),        \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{2645   \textcolor{keywordtype}{type}(verticalGrid\_type),      \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure.}}
\DoxyCodeLine{2646   \textcolor{keywordtype}{type}(unit\_scale\_type),        \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{2647   \textcolor{keywordtype}{type}(barotropic\_CS),          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< Barotropic control structure.}}
\DoxyCodeLine{2648 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: eta\textcolor{comment}{  !< The barotropic free surface}}
\DoxyCodeLine{2649 \textcolor{comment}{                                                      !! height anomaly or column mass anomaly [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2650 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: pbce\textcolor{comment}{  !< The baroclinic pressure}}
\DoxyCodeLine{2651 \textcolor{comment}{                                                      !! anomaly in each layer due to free surface}}
\DoxyCodeLine{2652 \textcolor{comment}{                                                      !! height anomalies [L2 H-\/1 T-\/2 \string~> m s-\/2 or m4 kg-\/1 s-\/2].}}
\DoxyCodeLine{2653   \textcolor{keywordtype}{type}(BT\_cont\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: BT\_cont\textcolor{comment}{  !< A structure with elements that describe}}
\DoxyCodeLine{2654 \textcolor{comment}{                                                      !! the effective open face areas as a}}
\DoxyCodeLine{2655 \textcolor{comment}{                                                      !! function of barotropic flow.}}
\DoxyCodeLine{2656 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: gtot\_est\textcolor{comment}{ !< An estimate of the total gravitational}}
\DoxyCodeLine{2657 \textcolor{comment}{                                                      !! acceleration [L2 Z-\/1 T-\/2 \string~> m s-\/2].}}
\DoxyCodeLine{2658 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: SSH\_add\textcolor{comment}{  !< An additional contribution to SSH to}}
\DoxyCodeLine{2659 \textcolor{comment}{                                                      !! provide a margin of error when}}
\DoxyCodeLine{2660 \textcolor{comment}{                                                      !! calculating the external wave speed [Z \string~> m].}}
\DoxyCodeLine{2661 }
\DoxyCodeLine{2662   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2663 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{2664     gtot\_E, \&     \textcolor{comment}{! gtot\_X is the effective total reduced gravity used to relate}}
\DoxyCodeLine{2665     gtot\_W, \&     \textcolor{comment}{! free surface height deviations to pressure forces (including}}
\DoxyCodeLine{2666     gtot\_N, \&     \textcolor{comment}{! GFS and baroclinic  contributions) in the barotropic momentum}}
\DoxyCodeLine{2667     gtot\_S        \textcolor{comment}{! equations half a grid-\/point in the X-\/direction (X is N, S, E, or W)}}
\DoxyCodeLine{2668                   \textcolor{comment}{! from the thickness point [L2 H-\/1 T-\/2 \string~> m s-\/2 or m4 kg-\/1 s-\/2].}}
\DoxyCodeLine{2669                   \textcolor{comment}{! (See Hallberg, J Comp Phys 1997 for a discussion.)}}
\DoxyCodeLine{2670 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBS\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{2671     Datu          \textcolor{comment}{! Basin depth at u-\/velocity grid points times the y-\/grid}}
\DoxyCodeLine{2672                   \textcolor{comment}{! spacing [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{2673 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJBS\_(G))} :: \&}
\DoxyCodeLine{2674     Datv          \textcolor{comment}{! Basin depth at v-\/velocity grid points times the x-\/grid}}
\DoxyCodeLine{2675                   \textcolor{comment}{! spacing [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{2676 \textcolor{keywordtype}{  real} :: det\_de  \textcolor{comment}{! The partial derivative due to self-\/attraction and loading}}
\DoxyCodeLine{2677                   \textcolor{comment}{! of the reference geopotential with the sea surface height [nondim].}}
\DoxyCodeLine{2678                   \textcolor{comment}{! This is typically \string~0.09 or less.}}
\DoxyCodeLine{2679 \textcolor{keywordtype}{  real} :: dgeo\_de \textcolor{comment}{! The constant of proportionality between geopotential and}}
\DoxyCodeLine{2680                   \textcolor{comment}{! sea surface height [nondim].  It is a nondimensional number of}}
\DoxyCodeLine{2681                   \textcolor{comment}{! order 1.  For stability, this may be made larger}}
\DoxyCodeLine{2682                   \textcolor{comment}{! than physical problem would suggest.}}
\DoxyCodeLine{2683 \textcolor{keywordtype}{  real} :: add\_SSH \textcolor{comment}{! An additional contribution to SSH to provide a margin of error}}
\DoxyCodeLine{2684                   \textcolor{comment}{! when calculating the external wave speed [Z \string~> m].}}
\DoxyCodeLine{2685 \textcolor{keywordtype}{  real} :: min\_max\_dt2 \textcolor{comment}{! The square of the minimum value of the largest stable barotropic}}
\DoxyCodeLine{2686                       \textcolor{comment}{! timesteps [T2 \string~> s2]}}
\DoxyCodeLine{2687 \textcolor{keywordtype}{  real} :: dtbt\_max    \textcolor{comment}{! The maximum barotropic timestep [T \string~> s]}}
\DoxyCodeLine{2688 \textcolor{keywordtype}{  real} :: Idt\_max2    \textcolor{comment}{! The squared inverse of the local maximum stable}}
\DoxyCodeLine{2689                       \textcolor{comment}{! barotropic time step [T-\/2 \string~> s-\/2].}}
\DoxyCodeLine{2690   \textcolor{keywordtype}{logical} :: use\_BT\_cont}
\DoxyCodeLine{2691   \textcolor{keywordtype}{type}(memory\_size\_type) :: MS}
\DoxyCodeLine{2692 }
\DoxyCodeLine{2693   \textcolor{keywordtype}{character(len=200)} :: mesg}
\DoxyCodeLine{2694   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{2695 }
\DoxyCodeLine{2696   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2697       \textcolor{stringliteral}{"{}set\_dtbt: Module MOM\_barotropic must be initialized before it is used."{}})}
\DoxyCodeLine{2698   \textcolor{keywordflow}{if} (.not.cs\%split) \textcolor{keywordflow}{return}}
\DoxyCodeLine{2699   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{2700   ms\%isdw = g\%isd ; ms\%iedw = g\%ied ; ms\%jsdw = g\%jsd ; ms\%jedw = g\%jed}
\DoxyCodeLine{2701 }
\DoxyCodeLine{2702   \textcolor{keywordflow}{if} (.not.(\textcolor{keyword}{present}(pbce) .or. \textcolor{keyword}{present}(gtot\_est))) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2703       \textcolor{stringliteral}{"{}set\_dtbt: Either pbce or gtot\_est must be present."{}})}
\DoxyCodeLine{2704 }
\DoxyCodeLine{2705   add\_ssh = 0.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ssh\_add)) add\_ssh = ssh\_add}
\DoxyCodeLine{2706 }
\DoxyCodeLine{2707   use\_bt\_cont = .false.}
\DoxyCodeLine{2708   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bt\_cont)) use\_bt\_cont = (\textcolor{keyword}{associated}(bt\_cont))}
\DoxyCodeLine{2709 }
\DoxyCodeLine{2710   \textcolor{keywordflow}{if} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2711     \textcolor{keyword}{call }bt\_cont\_to\_face\_areas(bt\_cont, datu, datv, g, us, ms, 0, .true.)}
\DoxyCodeLine{2712   \textcolor{keywordflow}{elseif} (cs\%Nonlinear\_continuity .and. \textcolor{keyword}{present}(eta)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2713     \textcolor{keyword}{call }find\_face\_areas(datu, datv, g, gv, us, cs, ms, eta=eta, halo=0)}
\DoxyCodeLine{2714   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2715     \textcolor{keyword}{call }find\_face\_areas(datu, datv, g, gv, us, cs, ms, halo=0, add\_max=add\_ssh)}
\DoxyCodeLine{2716 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2717 }
\DoxyCodeLine{2718   det\_de = 0.0}
\DoxyCodeLine{2719   \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keyword}{call }tidal\_forcing\_sensitivity(g, cs\%tides\_CSp, det\_de)}
\DoxyCodeLine{2720   dgeo\_de = 1.0 + max(0.0, det\_de + cs\%G\_extra)}
\DoxyCodeLine{2721   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(pbce)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2722     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2723       gtot\_e(i,j) = 0.0 ; gtot\_w(i,j) = 0.0}
\DoxyCodeLine{2724       gtot\_n(i,j) = 0.0 ; gtot\_s(i,j) = 0.0}
\DoxyCodeLine{2725 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2726     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2727       gtot\_e(i,j) = gtot\_e(i,j) + pbce(i,j,k) * cs\%frhatu(i,j,k)}
\DoxyCodeLine{2728       gtot\_w(i,j) = gtot\_w(i,j) + pbce(i,j,k) * cs\%frhatu(i-\/1,j,k)}
\DoxyCodeLine{2729       gtot\_n(i,j) = gtot\_n(i,j) + pbce(i,j,k) * cs\%frhatv(i,j,k)}
\DoxyCodeLine{2730       gtot\_s(i,j) = gtot\_s(i,j) + pbce(i,j,k) * cs\%frhatv(i,j-\/1,k)}
\DoxyCodeLine{2731 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2732   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2733     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2734       gtot\_e(i,j) = gtot\_est * gv\%H\_to\_Z ; gtot\_w(i,j) = gtot\_est * gv\%H\_to\_Z}
\DoxyCodeLine{2735       gtot\_n(i,j) = gtot\_est * gv\%H\_to\_Z ; gtot\_s(i,j) = gtot\_est * gv\%H\_to\_Z}
\DoxyCodeLine{2736 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2737 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2738 }
\DoxyCodeLine{2739   min\_max\_dt2 = 1.0e38*us\%s\_to\_T**2  \textcolor{comment}{! A huge value for the permissible timestep squared.}}
\DoxyCodeLine{2740   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2741     \textcolor{comment}{!   This is pretty accurate for gravity waves, but it is a conservative}}
\DoxyCodeLine{2742     \textcolor{comment}{! estimate since it ignores the stabilizing effect of the bottom drag.}}
\DoxyCodeLine{2743     idt\_max2 = 0.5 * (1.0 + 2.0*cs\%bebt) * (g\%IareaT(i,j) * \&}
\DoxyCodeLine{2744       ((gtot\_e(i,j)*datu(i,j)*g\%IdxCu(i,j) + gtot\_w(i,j)*datu(i-\/1,j)*g\%IdxCu(i-\/1,j)) + \&}
\DoxyCodeLine{2745        (gtot\_n(i,j)*datv(i,j)*g\%IdyCv(i,j) + gtot\_s(i,j)*datv(i,j-\/1)*g\%IdyCv(i,j-\/1))) + \&}
\DoxyCodeLine{2746       ((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-\/1,j-\/1)**2) + \&}
\DoxyCodeLine{2747        (g\%CoriolisBu(i-\/1,j)**2 + g\%CoriolisBu(i,j-\/1)**2)) * cs\%BT\_Coriolis\_scale**2 )}
\DoxyCodeLine{2748     \textcolor{keywordflow}{if} (idt\_max2 * min\_max\_dt2 > 1.0) min\_max\_dt2 = 1.0 / idt\_max2}
\DoxyCodeLine{2749 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2750   dtbt\_max = sqrt(min\_max\_dt2 / dgeo\_de)}
\DoxyCodeLine{2751   \textcolor{keywordflow}{if} (id\_clock\_sync > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_sync)}
\DoxyCodeLine{2752   \textcolor{keyword}{call }min\_across\_pes(dtbt\_max)}
\DoxyCodeLine{2753   \textcolor{keywordflow}{if} (id\_clock\_sync > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_sync)}
\DoxyCodeLine{2754 }
\DoxyCodeLine{2755   cs\%dtbt = cs\%dtbt\_fraction * dtbt\_max}
\DoxyCodeLine{2756   cs\%dtbt\_max = dtbt\_max}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a2be327af11ae54368acd32a3ba360ac4}\label{namespacemom__barotropic_a2be327af11ae54368acd32a3ba360ac4}} 
\index{mom\_barotropic@{mom\_barotropic}!set\_local\_bt\_cont\_types@{set\_local\_bt\_cont\_types}}
\index{set\_local\_bt\_cont\_types@{set\_local\_bt\_cont\_types}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{set\_local\_bt\_cont\_types()}{set\_local\_bt\_cont\_types()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::set\+\_\+local\+\_\+bt\+\_\+cont\+\_\+types (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__variables_1_1bt__cont__type}{bt\+\_\+cont\+\_\+type}}), intent(inout)}]{B\+T\+\_\+cont,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), dimension( ms \%isdw-\/1\+: ms \%iedw, ms \%jsdw\+: ms \%jedw), intent(out)}]{B\+T\+C\+L\+\_\+u,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), dimension( ms \%isdw\+: ms \%iedw, ms \%jsdw-\/1\+: ms \%jedw), intent(out)}]{B\+T\+C\+L\+\_\+v,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}), intent(in)}]{MS,  }\item[{type(\mbox{\hyperlink{structmom__domains_1_1mom__domain__type}{mom\+\_\+domain\+\_\+type}}), intent(inout)}]{B\+T\+\_\+\+Domain,  }\item[{integer, intent(in), optional}]{halo,  }\item[{real, intent(in), optional}]{dt\+\_\+baroclinic }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets up reordered versions of the B\+T\+\_\+cont type in the local\+\_\+\+B\+T\+\_\+cont types, which have wide halos properly filled in. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+cont} & The B\+T\+\_\+cont\+\_\+type input to the barotropic solver. \\
\hline
\mbox{\texttt{ in}}  & {\em ms} & A type that describes the memory sizes of the argument arrays. \\
\hline
\mbox{\texttt{ out}}  & {\em btcl\+\_\+u} & A structure with the u information from B\+T\+\_\+cont. \\
\hline
\mbox{\texttt{ out}}  & {\em btcl\+\_\+v} & A structure with the v information from B\+T\+\_\+cont. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+domain} & The domain to use for updating the halos of wide arrays. \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & The extra halo size to use here. \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+baroclinic} & The baroclinic time step \mbox{[}T $\sim$$>$ s\mbox{]}, which is provided if I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+N\+T\+I\+N\+U\+I\+TY is true. \\
\hline
\end{DoxyParams}


Definition at line 3756 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3757   \textcolor{keywordtype}{type}(BT\_cont\_type),                                    \textcolor{keywordtype}{intent(inout)} :: BT\_cont\textcolor{comment}{    !< The BT\_cont\_type input to the}}
\DoxyCodeLine{3758 \textcolor{comment}{                                                                                     !! barotropic solver.}}
\DoxyCodeLine{3759   \textcolor{keywordtype}{type}(memory\_size\_type),                                \textcolor{keywordtype}{intent(in)}    :: MS\textcolor{comment}{         !< A type that describes the}}
\DoxyCodeLine{3760 \textcolor{comment}{                                                                                     !! memory sizes of the argument}}
\DoxyCodeLine{3761 \textcolor{comment}{                                                                                     !! arrays.}}
\DoxyCodeLine{3762   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(out)} :: BTCL\_u\textcolor{comment}{ !< A structure with the u}}
\DoxyCodeLine{3763 \textcolor{comment}{                                                                                     !! information from BT\_cont.}}
\DoxyCodeLine{3764   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(out)} :: BTCL\_v\textcolor{comment}{ !< A structure with the v}}
\DoxyCodeLine{3765 \textcolor{comment}{                                                                                     !! information from BT\_cont.}}
\DoxyCodeLine{3766   \textcolor{keywordtype}{type}(ocean\_grid\_type),                                 \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{3767   \textcolor{keywordtype}{type}(unit\_scale\_type),                                 \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{3768   \textcolor{keywordtype}{type}(MOM\_domain\_type),                                 \textcolor{keywordtype}{intent(inout)} :: BT\_Domain\textcolor{comment}{  !< The domain to use for updating}}
\DoxyCodeLine{3769 \textcolor{comment}{                                                                                     !! the halos of wide arrays.}}
\DoxyCodeLine{3770   \textcolor{keywordtype}{integer},                                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{       !< The extra halo size to use here.}}
\DoxyCodeLine{3771 \textcolor{keywordtype}{  real},                                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: dt\_baroclinic\textcolor{comment}{ !< The baroclinic time step}}
\DoxyCodeLine{3772 \textcolor{comment}{                                                                                     !! [T \string~> s], which is provided if}}
\DoxyCodeLine{3773 \textcolor{comment}{                                                                                     !! INTEGRAL\_BT\_CONTINUITY is true.}}
\DoxyCodeLine{3774 }
\DoxyCodeLine{3775   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3776 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))} :: \&}
\DoxyCodeLine{3777     u\_polarity, \&      \textcolor{comment}{! An array used to test for halo update polarity [nondim]}}
\DoxyCodeLine{3778     uBT\_EE, uBT\_WW, \&  \textcolor{comment}{! Zonal velocities at which the form of the fit changes [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{3779     FA\_u\_EE, FA\_u\_E0, FA\_u\_W0, FA\_u\_WW \textcolor{comment}{! Zonal face areas [H L \string~> m2 or kg m-\/1]}}
\DoxyCodeLine{3780 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))} :: \&}
\DoxyCodeLine{3781     v\_polarity, \&      \textcolor{comment}{! An array used to test for halo update polarity [nondim]}}
\DoxyCodeLine{3782     vBT\_NN, vBT\_SS, \&  \textcolor{comment}{! Meridional velocities at which the form of the fit changes [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{3783     FA\_v\_NN, FA\_v\_N0, FA\_v\_S0, FA\_v\_SS \textcolor{comment}{! Meridional face areas [H L \string~> m2 or kg m-\/1]}}
\DoxyCodeLine{3784 \textcolor{keywordtype}{  real} :: dt \textcolor{comment}{! The baroclinic timestep [T \string~> s] or 1.0 [nondim]}}
\DoxyCodeLine{3785 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_3 = 1.0/3.0}
\DoxyCodeLine{3786   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, hs}
\DoxyCodeLine{3787 }
\DoxyCodeLine{3788   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{3789   hs = 1 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) hs = max(halo,0)}
\DoxyCodeLine{3790   dt = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dt\_baroclinic)) dt = dt\_baroclinic}
\DoxyCodeLine{3791 }
\DoxyCodeLine{3792   \textcolor{comment}{! Copy the BT\_cont arrays into symmetric, potentially wide haloed arrays.}}
\DoxyCodeLine{3793 \textcolor{comment}{!\$OMP parallel default(none) shared(is,ie,js,je,hs,u\_polarity,uBT\_EE,uBT\_WW,FA\_u\_EE, \&}}
\DoxyCodeLine{3794 \textcolor{comment}{!\$OMP                               FA\_u\_E0,FA\_u\_W0,FA\_u\_WW,v\_polarity,vBT\_NN,vBT\_SS,\&}}
\DoxyCodeLine{3795 \textcolor{comment}{!\$OMP                               FA\_v\_NN,FA\_v\_N0,FA\_v\_S0,FA\_v\_SS,BT\_cont )}}
\DoxyCodeLine{3796 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{3797   \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs-\/1,ie+hs}
\DoxyCodeLine{3798     u\_polarity(i,j) = 1.0}
\DoxyCodeLine{3799     ubt\_ee(i,j) = 0.0 ; ubt\_ww(i,j) = 0.0}
\DoxyCodeLine{3800     fa\_u\_ee(i,j) = 0.0 ; fa\_u\_e0(i,j) = 0.0 ; fa\_u\_w0(i,j) = 0.0 ; fa\_u\_ww(i,j) = 0.0}
\DoxyCodeLine{3801 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3802 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{3803   \textcolor{keywordflow}{do} j=js-\/hs-\/1,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{3804     v\_polarity(i,j) = 1.0}
\DoxyCodeLine{3805     vbt\_nn(i,j) = 0.0 ; vbt\_ss(i,j) = 0.0}
\DoxyCodeLine{3806     fa\_v\_nn(i,j) = 0.0 ; fa\_v\_n0(i,j) = 0.0 ; fa\_v\_s0(i,j) = 0.0 ; fa\_v\_ss(i,j) = 0.0}
\DoxyCodeLine{3807 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3808 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{3809   \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3810     ubt\_ee(i,j) = bt\_cont\%uBT\_EE(i,j) ; ubt\_ww(i,j) = bt\_cont\%uBT\_WW(i,j)}
\DoxyCodeLine{3811     fa\_u\_ee(i,j) = bt\_cont\%FA\_u\_EE(i,j) ; fa\_u\_e0(i,j) = bt\_cont\%FA\_u\_E0(i,j)}
\DoxyCodeLine{3812     fa\_u\_w0(i,j) = bt\_cont\%FA\_u\_W0(i,j) ; fa\_u\_ww(i,j) = bt\_cont\%FA\_u\_WW(i,j)}
\DoxyCodeLine{3813 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3814 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{3815   \textcolor{keywordflow}{do} j=js-\/1,je; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3816     vbt\_nn(i,j) = bt\_cont\%vBT\_NN(i,j) ; vbt\_ss(i,j) = bt\_cont\%vBT\_SS(i,j)}
\DoxyCodeLine{3817     fa\_v\_nn(i,j) = bt\_cont\%FA\_v\_NN(i,j) ; fa\_v\_n0(i,j) = bt\_cont\%FA\_v\_N0(i,j)}
\DoxyCodeLine{3818     fa\_v\_s0(i,j) = bt\_cont\%FA\_v\_S0(i,j) ; fa\_v\_ss(i,j) = bt\_cont\%FA\_v\_SS(i,j)}
\DoxyCodeLine{3819 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3820 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{3821 }
\DoxyCodeLine{3822   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_calc\_pre)}
\DoxyCodeLine{3823   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_pre)}
\DoxyCodeLine{3824 \textcolor{comment}{!-\/-\/-\/ begin setup for group halo update}}
\DoxyCodeLine{3825   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_polarity\_BT, u\_polarity, v\_polarity, bt\_domain)}
\DoxyCodeLine{3826   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_polarity\_BT, ubt\_ee, vbt\_nn, bt\_domain)}
\DoxyCodeLine{3827   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_polarity\_BT, ubt\_ww, vbt\_ss, bt\_domain)}
\DoxyCodeLine{3828 }
\DoxyCodeLine{3829   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_FA\_uv, fa\_u\_ee, fa\_v\_nn, bt\_domain, to\_all+scalar\_pair)}
\DoxyCodeLine{3830   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_FA\_uv, fa\_u\_e0, fa\_v\_n0, bt\_domain, to\_all+scalar\_pair)}
\DoxyCodeLine{3831   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_FA\_uv, fa\_u\_w0, fa\_v\_s0, bt\_domain, to\_all+scalar\_pair)}
\DoxyCodeLine{3832   \textcolor{keyword}{call }create\_group\_pass(bt\_cont\%pass\_FA\_uv, fa\_u\_ww, fa\_v\_ss, bt\_domain, to\_all+scalar\_pair)}
\DoxyCodeLine{3833 \textcolor{comment}{!-\/-\/-\/ end setup for group halo update}}
\DoxyCodeLine{3834   \textcolor{comment}{! Do halo updates on BT\_cont.}}
\DoxyCodeLine{3835   \textcolor{keyword}{call }do\_group\_pass(bt\_cont\%pass\_polarity\_BT, bt\_domain)}
\DoxyCodeLine{3836   \textcolor{keyword}{call }do\_group\_pass(bt\_cont\%pass\_FA\_uv, bt\_domain)}
\DoxyCodeLine{3837   \textcolor{keywordflow}{if} (id\_clock\_pass\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_pre)}
\DoxyCodeLine{3838   \textcolor{keywordflow}{if} (id\_clock\_calc\_pre > 0) \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_calc\_pre)}
\DoxyCodeLine{3839 }
\DoxyCodeLine{3840   \textcolor{comment}{!\$OMP parallel default(shared)}}
\DoxyCodeLine{3841   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{3842   \textcolor{keywordflow}{do} j=js-\/hs,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs-\/1,ie+hs}
\DoxyCodeLine{3843     btcl\_u(i,j)\%FA\_u\_EE = fa\_u\_ee(i,j) ; btcl\_u(i,j)\%FA\_u\_E0 = fa\_u\_e0(i,j)}
\DoxyCodeLine{3844     btcl\_u(i,j)\%FA\_u\_W0 = fa\_u\_w0(i,j) ; btcl\_u(i,j)\%FA\_u\_WW = fa\_u\_ww(i,j)}
\DoxyCodeLine{3845     btcl\_u(i,j)\%uBT\_EE = dt*ubt\_ee(i,j)   ; btcl\_u(i,j)\%uBT\_WW = dt*ubt\_ww(i,j)}
\DoxyCodeLine{3846     \textcolor{comment}{! Check for reversed polarity in the tripolar halo regions.}}
\DoxyCodeLine{3847     \textcolor{keywordflow}{if} (u\_polarity(i,j) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3848       \textcolor{keyword}{call }swap(btcl\_u(i,j)\%FA\_u\_EE, btcl\_u(i,j)\%FA\_u\_WW)}
\DoxyCodeLine{3849       \textcolor{keyword}{call }swap(btcl\_u(i,j)\%FA\_u\_E0, btcl\_u(i,j)\%FA\_u\_W0)}
\DoxyCodeLine{3850       \textcolor{keyword}{call }swap(btcl\_u(i,j)\%uBT\_EE,  btcl\_u(i,j)\%uBT\_WW)}
\DoxyCodeLine{3851 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3852 }
\DoxyCodeLine{3853     btcl\_u(i,j)\%uh\_EE = btcl\_u(i,j)\%uBT\_EE * \&}
\DoxyCodeLine{3854         (c1\_3 * (2.0*btcl\_u(i,j)\%FA\_u\_E0 + btcl\_u(i,j)\%FA\_u\_EE))}
\DoxyCodeLine{3855     btcl\_u(i,j)\%uh\_WW = btcl\_u(i,j)\%uBT\_WW * \&}
\DoxyCodeLine{3856         (c1\_3 * (2.0*btcl\_u(i,j)\%FA\_u\_W0 + btcl\_u(i,j)\%FA\_u\_WW))}
\DoxyCodeLine{3857 }
\DoxyCodeLine{3858     btcl\_u(i,j)\%uh\_crvE = 0.0 ; btcl\_u(i,j)\%uh\_crvW = 0.0}
\DoxyCodeLine{3859     \textcolor{keywordflow}{if} (abs(btcl\_u(i,j)\%uBT\_WW) > 0.0) btcl\_u(i,j)\%uh\_crvW = \&}
\DoxyCodeLine{3860       (c1\_3 * (btcl\_u(i,j)\%FA\_u\_WW -\/ btcl\_u(i,j)\%FA\_u\_W0)) / btcl\_u(i,j)\%uBT\_WW**2}
\DoxyCodeLine{3861     \textcolor{keywordflow}{if} (abs(btcl\_u(i,j)\%uBT\_EE) > 0.0) btcl\_u(i,j)\%uh\_crvE = \&}
\DoxyCodeLine{3862       (c1\_3 * (btcl\_u(i,j)\%FA\_u\_EE -\/ btcl\_u(i,j)\%FA\_u\_E0)) / btcl\_u(i,j)\%uBT\_EE**2}
\DoxyCodeLine{3863 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3864   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{3865   \textcolor{keywordflow}{do} j=js-\/hs-\/1,je+hs ; \textcolor{keywordflow}{do} i=is-\/hs,ie+hs}
\DoxyCodeLine{3866     btcl\_v(i,j)\%FA\_v\_NN = fa\_v\_nn(i,j) ; btcl\_v(i,j)\%FA\_v\_N0 = fa\_v\_n0(i,j)}
\DoxyCodeLine{3867     btcl\_v(i,j)\%FA\_v\_S0 = fa\_v\_s0(i,j) ; btcl\_v(i,j)\%FA\_v\_SS = fa\_v\_ss(i,j)}
\DoxyCodeLine{3868     btcl\_v(i,j)\%vBT\_NN = dt*vbt\_nn(i,j)   ; btcl\_v(i,j)\%vBT\_SS = dt*vbt\_ss(i,j)}
\DoxyCodeLine{3869     \textcolor{comment}{! Check for reversed polarity in the tripolar halo regions.}}
\DoxyCodeLine{3870     \textcolor{keywordflow}{if} (v\_polarity(i,j) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3871       \textcolor{keyword}{call }swap(btcl\_v(i,j)\%FA\_v\_NN, btcl\_v(i,j)\%FA\_v\_SS)}
\DoxyCodeLine{3872       \textcolor{keyword}{call }swap(btcl\_v(i,j)\%FA\_v\_N0, btcl\_v(i,j)\%FA\_v\_S0)}
\DoxyCodeLine{3873       \textcolor{keyword}{call }swap(btcl\_v(i,j)\%vBT\_NN,  btcl\_v(i,j)\%vBT\_SS)}
\DoxyCodeLine{3874 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3875 }
\DoxyCodeLine{3876     btcl\_v(i,j)\%vh\_NN = btcl\_v(i,j)\%vBT\_NN * \&}
\DoxyCodeLine{3877         (c1\_3 * (2.0*btcl\_v(i,j)\%FA\_v\_N0 + btcl\_v(i,j)\%FA\_v\_NN))}
\DoxyCodeLine{3878     btcl\_v(i,j)\%vh\_SS = btcl\_v(i,j)\%vBT\_SS * \&}
\DoxyCodeLine{3879         (c1\_3 * (2.0*btcl\_v(i,j)\%FA\_v\_S0 + btcl\_v(i,j)\%FA\_v\_SS))}
\DoxyCodeLine{3880 }
\DoxyCodeLine{3881     btcl\_v(i,j)\%vh\_crvN = 0.0 ; btcl\_v(i,j)\%vh\_crvS = 0.0}
\DoxyCodeLine{3882     \textcolor{keywordflow}{if} (abs(btcl\_v(i,j)\%vBT\_SS) > 0.0) btcl\_v(i,j)\%vh\_crvS = \&}
\DoxyCodeLine{3883       (c1\_3 * (btcl\_v(i,j)\%FA\_v\_SS -\/ btcl\_v(i,j)\%FA\_v\_S0)) / btcl\_v(i,j)\%vBT\_SS**2}
\DoxyCodeLine{3884     \textcolor{keywordflow}{if} (abs(btcl\_v(i,j)\%vBT\_NN) > 0.0) btcl\_v(i,j)\%vh\_crvN = \&}
\DoxyCodeLine{3885       (c1\_3 * (btcl\_v(i,j)\%FA\_v\_NN -\/ btcl\_v(i,j)\%FA\_v\_N0)) / btcl\_v(i,j)\%vBT\_NN**2}
\DoxyCodeLine{3886 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3887   \textcolor{comment}{!\$OMP end parallel}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_af8296e1b2f7a24a091c7ad563393edb0}\label{namespacemom__barotropic_af8296e1b2f7a24a091c7ad563393edb0}} 
\index{mom\_barotropic@{mom\_barotropic}!set\_up\_bt\_obc@{set\_up\_bt\_obc}}
\index{set\_up\_bt\_obc@{set\_up\_bt\_obc}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{set\_up\_bt\_obc()}{set\_up\_bt\_obc()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::set\+\_\+up\+\_\+bt\+\_\+obc (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}}), pointer}]{O\+BC,  }\item[{real, dimension(sziw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{eta,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1bt__obc__type}{bt\+\_\+obc\+\_\+type}}), intent(inout)}]{B\+T\+\_\+\+O\+BC,  }\item[{type(\mbox{\hyperlink{structmom__domains_1_1mom__domain__type}{mom\+\_\+domain\+\_\+type}}), intent(inout)}]{B\+T\+\_\+\+Domain,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1memory__size__type}{memory\+\_\+size\+\_\+type}}), intent(in)}]{MS,  }\item[{integer, intent(in)}]{halo,  }\item[{logical, intent(in)}]{use\+\_\+\+B\+T\+\_\+cont,  }\item[{logical, intent(in)}]{integral\+\_\+\+B\+T\+\_\+cont,  }\item[{real, intent(in)}]{dt\+\_\+baroclinic,  }\item[{real, dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{Datu,  }\item[{real, dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{Datv,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), dimension(szibw\+\_\+(ms),szjw\+\_\+(ms)), intent(in)}]{B\+T\+C\+L\+\_\+u,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), dimension(sziw\+\_\+(ms),szjbw\+\_\+(ms)), intent(in)}]{B\+T\+C\+L\+\_\+v }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets up the private structure used to apply the open boundary conditions, as developed by Mehmet Ilicak. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & An associated pointer to an O\+BC type. \\
\hline
\mbox{\texttt{ in}}  & {\em ms} & A type that describes the memory sizes of the argument arrays. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & The barotropic free surface height anomaly or column mass anomaly \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+obc} & A structure with the private barotropic arrays related to the open boundary conditions, set by set\+\_\+up\+\_\+\+B\+T\+\_\+\+O\+BC. \\
\hline
\mbox{\texttt{ in,out}}  & {\em bt\+\_\+domain} & M\+O\+M\+\_\+domain\+\_\+type associated with wide arrays \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & The extra halo size to use here. \\
\hline
\mbox{\texttt{ in}}  & {\em use\+\_\+bt\+\_\+cont} & If true, use the B\+T\+\_\+cont\+\_\+types to calculate transports. \\
\hline
\mbox{\texttt{ in}}  & {\em integral\+\_\+bt\+\_\+cont} & If true, update the barotropic continuity equation directly from the initial condition using the time-\/integrated barotropic velocity. \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+baroclinic} & The baroclinic timestep for this cycle of updates to the barotropic solver \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em datu} & A fixed estimate of the face areas at u points \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em datv} & A fixed estimate of the face areas at v points \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em btcl\+\_\+u} & Structure of information used for a dynamic estimate of the face areas at u-\/points. \\
\hline
\mbox{\texttt{ in}}  & {\em btcl\+\_\+v} & Structure of information used for a dynamic estimate of the face areas at v-\/points. \\
\hline
\end{DoxyParams}


Definition at line 2967 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2969   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                  \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{    !< An associated pointer to an OBC type.}}
\DoxyCodeLine{2970   \textcolor{keywordtype}{type}(memory\_size\_type),                \textcolor{keywordtype}{intent(in)}    :: MS\textcolor{comment}{     !< A type that describes the memory sizes of the}}
\DoxyCodeLine{2971 \textcolor{comment}{                                                                 !! argument arrays.}}
\DoxyCodeLine{2972 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJW\_(MS))},  \textcolor{keywordtype}{intent(in)}    :: eta\textcolor{comment}{    !< The barotropic free surface height anomaly or}}
\DoxyCodeLine{2973 \textcolor{comment}{                                                                 !! column mass anomaly [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2974   \textcolor{keywordtype}{type}(BT\_OBC\_type),                     \textcolor{keywordtype}{intent(inout)} :: BT\_OBC\textcolor{comment}{ !< A structure with the private barotropic arrays}}
\DoxyCodeLine{2975 \textcolor{comment}{                                                                 !! related to the open boundary conditions,}}
\DoxyCodeLine{2976 \textcolor{comment}{                                                                 !! set by set\_up\_BT\_OBC.}}
\DoxyCodeLine{2977   \textcolor{keywordtype}{type}(MOM\_domain\_type),                 \textcolor{keywordtype}{intent(inout)} :: BT\_Domain\textcolor{comment}{ !< MOM\_domain\_type associated with wide arrays}}
\DoxyCodeLine{2978   \textcolor{keywordtype}{type}(ocean\_grid\_type),                 \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< The ocean's grid structure.}}
\DoxyCodeLine{2979   \textcolor{keywordtype}{type}(verticalGrid\_type),               \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< The ocean's vertical grid structure.}}
\DoxyCodeLine{2980   \textcolor{keywordtype}{type}(unit\_scale\_type),                 \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{2981   \textcolor{keywordtype}{integer},                               \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{   !< The extra halo size to use here.}}
\DoxyCodeLine{2982   \textcolor{keywordtype}{logical},                               \textcolor{keywordtype}{intent(in)}    :: use\_BT\_cont\textcolor{comment}{ !< If true, use the BT\_cont\_types to calculate}}
\DoxyCodeLine{2983 \textcolor{comment}{                                                                 !! transports.}}
\DoxyCodeLine{2984   \textcolor{keywordtype}{logical},                               \textcolor{keywordtype}{intent(in)}    :: integral\_BT\_cont\textcolor{comment}{ !< If true, update the barotropic continuity}}
\DoxyCodeLine{2985 \textcolor{comment}{                                                                 !! equation directly from the initial condition}}
\DoxyCodeLine{2986 \textcolor{comment}{                                                                 !! using the time-\/integrated barotropic velocity.}}
\DoxyCodeLine{2987 \textcolor{keywordtype}{  real},                                  \textcolor{keywordtype}{intent(in)}    :: dt\_baroclinic\textcolor{comment}{ !< The baroclinic timestep for this cycle of}}
\DoxyCodeLine{2988 \textcolor{comment}{                                                                 !! updates to the barotropic solver [T \string~> s]}}
\DoxyCodeLine{2989 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: Datu\textcolor{comment}{   !< A fixed estimate of the face areas at u points}}
\DoxyCodeLine{2990 \textcolor{comment}{                                                                 !! [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{2991 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)}    :: Datv\textcolor{comment}{   !< A fixed estimate of the face areas at v points}}
\DoxyCodeLine{2992 \textcolor{comment}{                                                                 !! [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{2993   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{dimension(SZIBW\_(MS),SZJW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: BTCL\_u\textcolor{comment}{ !< Structure of information used}}
\DoxyCodeLine{2994 \textcolor{comment}{                                                                 !! for a dynamic estimate of the face areas at}}
\DoxyCodeLine{2995 \textcolor{comment}{                                                                 !! u-\/points.}}
\DoxyCodeLine{2996   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{dimension(SZIW\_(MS),SZJBW\_(MS))}, \textcolor{keywordtype}{intent(in)} :: BTCL\_v\textcolor{comment}{ !< Structure of information used}}
\DoxyCodeLine{2997 \textcolor{comment}{                                                                 !! for a dynamic estimate of the face areas at}}
\DoxyCodeLine{2998 \textcolor{comment}{                                                                 !! v-\/points.}}
\DoxyCodeLine{2999 }
\DoxyCodeLine{3000   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3001 \textcolor{keywordtype}{  real} :: I\_dt      \textcolor{comment}{! The inverse of the time interval of this call [T-\/1 \string~> s-\/1].}}
\DoxyCodeLine{3002   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, n, nz, Isq, Ieq, Jsq, Jeq}
\DoxyCodeLine{3003   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{3004   \textcolor{keywordtype}{integer} :: isdw, iedw, jsdw, jedw}
\DoxyCodeLine{3005   \textcolor{keywordtype}{logical} :: OBC\_used}
\DoxyCodeLine{3006   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer}  :: segment\textcolor{comment}{ !< Open boundary segment}}
\DoxyCodeLine{3007 }
\DoxyCodeLine{3008   is = g\%isc-\/halo ; ie = g\%iec+halo ; js = g\%jsc-\/halo ; je = g\%jec+halo}
\DoxyCodeLine{3009   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed ; nz = g\%ke}
\DoxyCodeLine{3010   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{3011   isdw = ms\%isdw ; iedw = ms\%iedw ; jsdw = ms\%jsdw ; jedw = ms\%jedw}
\DoxyCodeLine{3012 }
\DoxyCodeLine{3013   i\_dt = 1.0 / dt\_baroclinic}
\DoxyCodeLine{3014 }
\DoxyCodeLine{3015   \textcolor{keywordflow}{if} ((isdw < isd) .or. (jsdw < jsd)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3016     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}set\_up\_BT\_OBC: Open boundary conditions are not "{}}//\&}
\DoxyCodeLine{3017                            \textcolor{stringliteral}{"{}yet fully implemented with wide barotropic halos."{}})}
\DoxyCodeLine{3018 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3019 }
\DoxyCodeLine{3020   \textcolor{keywordflow}{if} (.not. bt\_obc\%is\_alloced) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3021     \textcolor{keyword}{allocate}(bt\_obc\%Cg\_u(isdw-\/1:iedw,jsdw:jedw))        ; bt\_obc\%Cg\_u(:,:) = 0.0}
\DoxyCodeLine{3022     \textcolor{keyword}{allocate}(bt\_obc\%H\_u(isdw-\/1:iedw,jsdw:jedw))         ; bt\_obc\%H\_u(:,:) = 0.0}
\DoxyCodeLine{3023     \textcolor{keyword}{allocate}(bt\_obc\%uhbt(isdw-\/1:iedw,jsdw:jedw))        ; bt\_obc\%uhbt(:,:) = 0.0}
\DoxyCodeLine{3024     \textcolor{keyword}{allocate}(bt\_obc\%ubt\_outer(isdw-\/1:iedw,jsdw:jedw))   ; bt\_obc\%ubt\_outer(:,:) = 0.0}
\DoxyCodeLine{3025     \textcolor{keyword}{allocate}(bt\_obc\%eta\_outer\_u(isdw-\/1:iedw,jsdw:jedw)) ; bt\_obc\%eta\_outer\_u(:,:) = 0.0}
\DoxyCodeLine{3026 }
\DoxyCodeLine{3027     \textcolor{keyword}{allocate}(bt\_obc\%Cg\_v(isdw:iedw,jsdw-\/1:jedw))        ; bt\_obc\%Cg\_v(:,:) = 0.0}
\DoxyCodeLine{3028     \textcolor{keyword}{allocate}(bt\_obc\%H\_v(isdw:iedw,jsdw-\/1:jedw))         ; bt\_obc\%H\_v(:,:) = 0.0}
\DoxyCodeLine{3029     \textcolor{keyword}{allocate}(bt\_obc\%vhbt(isdw:iedw,jsdw-\/1:jedw))        ; bt\_obc\%vhbt(:,:) = 0.0}
\DoxyCodeLine{3030     \textcolor{keyword}{allocate}(bt\_obc\%vbt\_outer(isdw:iedw,jsdw-\/1:jedw))   ; bt\_obc\%vbt\_outer(:,:) = 0.0}
\DoxyCodeLine{3031     \textcolor{keyword}{allocate}(bt\_obc\%eta\_outer\_v(isdw:iedw,jsdw-\/1:jedw)) ; bt\_obc\%eta\_outer\_v(:,:)=0.0}
\DoxyCodeLine{3032     bt\_obc\%is\_alloced = .true.}
\DoxyCodeLine{3033     \textcolor{keyword}{call }create\_group\_pass(bt\_obc\%pass\_uv, bt\_obc\%ubt\_outer, bt\_obc\%vbt\_outer, bt\_domain)}
\DoxyCodeLine{3034     \textcolor{keyword}{call }create\_group\_pass(bt\_obc\%pass\_uhvh, bt\_obc\%uhbt, bt\_obc\%vhbt, bt\_domain)}
\DoxyCodeLine{3035     \textcolor{keyword}{call }create\_group\_pass(bt\_obc\%pass\_eta\_outer, bt\_obc\%eta\_outer\_u, bt\_obc\%eta\_outer\_v, bt\_domain,to\_all+scalar\_pair)}
\DoxyCodeLine{3036     \textcolor{keyword}{call }create\_group\_pass(bt\_obc\%pass\_h, bt\_obc\%H\_u, bt\_obc\%H\_v, bt\_domain,to\_all+scalar\_pair)}
\DoxyCodeLine{3037     \textcolor{keyword}{call }create\_group\_pass(bt\_obc\%pass\_cg, bt\_obc\%Cg\_u, bt\_obc\%Cg\_v, bt\_domain,to\_all+scalar\_pair)}
\DoxyCodeLine{3038 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3039 }
\DoxyCodeLine{3040   \textcolor{keywordflow}{if} (bt\_obc\%apply\_u\_OBCs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3041     \textcolor{keywordflow}{if} (obc\%specified\_u\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3042       \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{3043         segment => obc\%segment(n)}
\DoxyCodeLine{3044         \textcolor{keywordflow}{if} (segment\%is\_E\_or\_W .and. segment\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3045           \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed ; \textcolor{keywordflow}{do} i=segment\%HI\%IsdB,segment\%HI\%IedB}
\DoxyCodeLine{3046             bt\_obc\%uhbt(i,j) = 0.}
\DoxyCodeLine{3047 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3048           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed ; \textcolor{keywordflow}{do} i=segment\%HI\%IsdB,segment\%HI\%IedB}
\DoxyCodeLine{3049             bt\_obc\%uhbt(i,j) = bt\_obc\%uhbt(i,j) + segment\%normal\_trans(i,j,k)}
\DoxyCodeLine{3050 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3051 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3052 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3053 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3054     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; \textcolor{keywordflow}{if} (obc\%segnum\_u(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3055       \textcolor{comment}{! Can this go in segment loop above? Is loop above wrong for wide halos??}}
\DoxyCodeLine{3056       \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_u(i,j))\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3057         \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3058           bt\_obc\%ubt\_outer(i,j) = uhbt\_to\_ubt(bt\_obc\%uhbt(i,j)*dt\_baroclinic, btcl\_u(i,j)) * i\_dt}
\DoxyCodeLine{3059         \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3060           bt\_obc\%ubt\_outer(i,j) = uhbt\_to\_ubt(bt\_obc\%uhbt(i,j), btcl\_u(i,j))}
\DoxyCodeLine{3061         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3062           \textcolor{keywordflow}{if} (datu(i,j) > 0.0) bt\_obc\%ubt\_outer(i,j) = bt\_obc\%uhbt(i,j) / datu(i,j)}
\DoxyCodeLine{3063 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3064       \textcolor{keywordflow}{else}  \textcolor{comment}{! This is assuming Flather as only other option}}
\DoxyCodeLine{3065         \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3066           \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_u(i,j))\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3067             bt\_obc\%H\_u(i,j) = g\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j)}
\DoxyCodeLine{3068           \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_u(i,j))\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3069             bt\_obc\%H\_u(i,j) = g\%bathyT(i+1,j)*gv\%Z\_to\_H + eta(i+1,j)}
\DoxyCodeLine{3070 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3071         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3072           \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_u(i,j))\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3073             bt\_obc\%H\_u(i,j) = eta(i,j)}
\DoxyCodeLine{3074           \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_u(i,j))\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3075             bt\_obc\%H\_u(i,j) = eta(i+1,j)}
\DoxyCodeLine{3076 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3077 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3078         bt\_obc\%Cg\_u(i,j) = sqrt(gv\%g\_prime(1) * gv\%H\_to\_Z*bt\_obc\%H\_u(i,j))}
\DoxyCodeLine{3079 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3080 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3081     \textcolor{keywordflow}{if} (obc\%Flather\_u\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3082      \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{3083         segment => obc\%segment(n)}
\DoxyCodeLine{3084         \textcolor{keywordflow}{if} (segment\%is\_E\_or\_W .and. segment\%Flather) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3085           \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed ; \textcolor{keywordflow}{do} i=segment\%HI\%IsdB,segment\%HI\%IedB}
\DoxyCodeLine{3086             bt\_obc\%ubt\_outer(i,j) = segment\%normal\_vel\_bt(i,j)}
\DoxyCodeLine{3087             bt\_obc\%eta\_outer\_u(i,j) = segment\%eta(i,j)}
\DoxyCodeLine{3088 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3089 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3090 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3091 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3092 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3093 }
\DoxyCodeLine{3094   \textcolor{keywordflow}{if} (bt\_obc\%apply\_v\_OBCs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3095     \textcolor{keywordflow}{if} (obc\%specified\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3096       \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{3097         segment => obc\%segment(n)}
\DoxyCodeLine{3098         \textcolor{keywordflow}{if} (segment\%is\_N\_or\_S .and. segment\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3099           \textcolor{keywordflow}{do} j=segment\%HI\%JsdB,segment\%HI\%JedB ; \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{3100             bt\_obc\%vhbt(i,j) = 0.}
\DoxyCodeLine{3101 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3102           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment\%HI\%JsdB,segment\%HI\%JedB ; \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{3103             bt\_obc\%vhbt(i,j) = bt\_obc\%vhbt(i,j) + segment\%normal\_trans(i,j,k)}
\DoxyCodeLine{3104 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3105 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3106 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3107 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3108     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (obc\%segnum\_v(i,j) /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3109       \textcolor{comment}{! Can this go in segment loop above? Is loop above wrong for wide halos??}}
\DoxyCodeLine{3110       \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%specified) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3111         \textcolor{keywordflow}{if} (integral\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3112           bt\_obc\%vbt\_outer(i,j) = vhbt\_to\_vbt(bt\_obc\%vhbt(i,j)*dt\_baroclinic, btcl\_v(i,j)) * i\_dt}
\DoxyCodeLine{3113         \textcolor{keywordflow}{elseif} (use\_bt\_cont) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3114           bt\_obc\%vbt\_outer(i,j) = vhbt\_to\_vbt(bt\_obc\%vhbt(i,j), btcl\_v(i,j))}
\DoxyCodeLine{3115         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3116           \textcolor{keywordflow}{if} (datv(i,j) > 0.0) bt\_obc\%vbt\_outer(i,j) = bt\_obc\%vhbt(i,j) / datv(i,j)}
\DoxyCodeLine{3117 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3118       \textcolor{keywordflow}{else}  \textcolor{comment}{! This is assuming Flather as only other option}}
\DoxyCodeLine{3119         \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3120           \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3121             bt\_obc\%H\_v(i,j) = g\%bathyT(i,j)*gv\%Z\_to\_H + eta(i,j)}
\DoxyCodeLine{3122           \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_v(i,j))\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3123             bt\_obc\%H\_v(i,j) = g\%bathyT(i,j+1)*gv\%Z\_to\_H + eta(i,j+1)}
\DoxyCodeLine{3124 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3125         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3126           \textcolor{keywordflow}{if} (obc\%segment(obc\%segnum\_v(i,j))\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3127             bt\_obc\%H\_v(i,j) = eta(i,j)}
\DoxyCodeLine{3128           \textcolor{keywordflow}{elseif} (obc\%segment(obc\%segnum\_v(i,j))\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3129             bt\_obc\%H\_v(i,j) = eta(i,j+1)}
\DoxyCodeLine{3130 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3131 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3132         bt\_obc\%Cg\_v(i,j) = sqrt(gv\%g\_prime(1) * gv\%H\_to\_Z*bt\_obc\%H\_v(i,j))}
\DoxyCodeLine{3133 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3134 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3135     \textcolor{keywordflow}{if} (obc\%Flather\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3136      \textcolor{keywordflow}{do} n = 1, obc\%number\_of\_segments}
\DoxyCodeLine{3137         segment => obc\%segment(n)}
\DoxyCodeLine{3138         \textcolor{keywordflow}{if} (segment\%is\_N\_or\_S .and. segment\%Flather) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3139           \textcolor{keywordflow}{do} j=segment\%HI\%JsdB,segment\%HI\%JedB ; \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{3140             bt\_obc\%vbt\_outer(i,j) = segment\%normal\_vel\_bt(i,j)}
\DoxyCodeLine{3141             bt\_obc\%eta\_outer\_v(i,j) = segment\%eta(i,j)}
\DoxyCodeLine{3142 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3143 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3144 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3145 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3146 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3147 }
\DoxyCodeLine{3148   \textcolor{keyword}{call }do\_group\_pass(bt\_obc\%pass\_uv, bt\_domain)}
\DoxyCodeLine{3149   \textcolor{keyword}{call }do\_group\_pass(bt\_obc\%pass\_uhvh, bt\_domain)}
\DoxyCodeLine{3150   \textcolor{keyword}{call }do\_group\_pass(bt\_obc\%pass\_eta\_outer, bt\_domain)}
\DoxyCodeLine{3151   \textcolor{keyword}{call }do\_group\_pass(bt\_obc\%pass\_h, bt\_domain)}
\DoxyCodeLine{3152   \textcolor{keyword}{call }do\_group\_pass(bt\_obc\%pass\_cg, bt\_domain)}
\DoxyCodeLine{3153 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_af1813744cf2034c2413ef904bf628263}\label{namespacemom__barotropic_af1813744cf2034c2413ef904bf628263}} 
\index{mom\_barotropic@{mom\_barotropic}!swap@{swap}}
\index{swap@{swap}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{swap()}{swap()}}
{\footnotesize\ttfamily subroutine mom\+\_\+barotropic\+::swap (\begin{DoxyParamCaption}\item[{real, intent(inout)}]{a,  }\item[{real, intent(inout)}]{b }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Swap the values of two real variables. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em a} & The first variable to be swapped. \\
\hline
\mbox{\texttt{ in,out}}  & {\em b} & The second variable to be swapped. \\
\hline
\end{DoxyParams}


Definition at line 4039 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{4040 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(inout)} :: a\textcolor{comment}{ !< The first variable to be swapped.}}
\DoxyCodeLine{4041 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(inout)} :: b\textcolor{comment}{ !< The second variable to be swapped.}}
\DoxyCodeLine{4042 \textcolor{keywordtype}{  real} :: tmp}
\DoxyCodeLine{4043   tmp = a ; a = b ; b = tmp}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_a0311f0f3d4e27f4017582d6a8c01298c}\label{namespacemom__barotropic_a0311f0f3d4e27f4017582d6a8c01298c}} 
\index{mom\_barotropic@{mom\_barotropic}!uhbt\_to\_ubt@{uhbt\_to\_ubt}}
\index{uhbt\_to\_ubt@{uhbt\_to\_ubt}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{uhbt\_to\_ubt()}{uhbt\_to\_ubt()}}
{\footnotesize\ttfamily real function mom\+\_\+barotropic\+::uhbt\+\_\+to\+\_\+ubt (\begin{DoxyParamCaption}\item[{real, intent(in)}]{uhbt,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__u__type}{local\+\_\+bt\+\_\+cont\+\_\+u\+\_\+type}}), intent(in)}]{B\+TC,  }\item[{real, intent(in), optional}]{guess }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function inverts the transport function to determine the barotopic velocity that is consistent with a given transport, or if I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True this finds the time-\/integrated velocity that is consistent with a time-\/integrated transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em uhbt} & The barotropic zonal transport that should be inverted for, \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]} or the time-\/integrated transport \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em btc} & A structure containing various fields that allow the barotropic transports to be calculated consistently with the layers\textquotesingle{} continuity equations. The dimensions of some of the elements in this type vary depending on I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT. \\
\hline
\mbox{\texttt{ in}}  & {\em guess} & A guess at what ubt will be \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or \mbox{[}L $\sim$$>$ m\mbox{]}. The result is not allowed to be dramatically larger than guess. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The result -\/ The velocity that gives uhbt transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or the time-\/integrated velocity \mbox{[}L $\sim$$>$ m\mbox{]}. 
\end{DoxyReturn}


Definition at line 3508 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3509 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: uhbt\textcolor{comment}{                      !< The barotropic zonal transport that should be inverted for,}}
\DoxyCodeLine{3510 \textcolor{comment}{                                                !! [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1] or the time-\/integrated}}
\DoxyCodeLine{3511 \textcolor{comment}{                                                !! transport [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{3512   \textcolor{keywordtype}{type}(local\_BT\_cont\_u\_type), \textcolor{keywordtype}{intent(in)} :: BTC\textcolor{comment}{ !< A structure containing various fields that allow the}}
\DoxyCodeLine{3513 \textcolor{comment}{                                                !! barotropic transports to be calculated consistently with the}}
\DoxyCodeLine{3514 \textcolor{comment}{                                                !! layers' continuity equations.  The dimensions of some}}
\DoxyCodeLine{3515 \textcolor{comment}{                                                !! of the elements in this type vary depending on INTEGRAL\_BT\_CONT.}}
\DoxyCodeLine{3516 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: guess\textcolor{comment}{           !< A guess at what ubt will be [L T-\/1 \string~> m s-\/1] or [L \string~> m].}}
\DoxyCodeLine{3517 \textcolor{comment}{                                                !! The result is not allowed to be dramatically larger than guess.}}
\DoxyCodeLine{3518 \textcolor{keywordtype}{  real} :: ubt\textcolor{comment}{                                   !< The result -\/ The velocity that gives uhbt transport [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{3519 \textcolor{comment}{                                                !! or the time-\/integrated velocity [L \string~> m].}}
\DoxyCodeLine{3520 }
\DoxyCodeLine{3521   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3522 \textcolor{keywordtype}{  real} :: ubt\_min, ubt\_max       \textcolor{comment}{! Bounding values of vbt [L T-\/1 \string~> m s-\/1] or [L \string~> m]}}
\DoxyCodeLine{3523 \textcolor{keywordtype}{  real} :: uhbt\_err               \textcolor{comment}{! The transport error [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1] or [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{3524 \textcolor{keywordtype}{  real} :: derr\_du                \textcolor{comment}{! The change in transport error with vbt, i.e. the face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{3525 \textcolor{keywordtype}{  real} :: uherr\_min, uherr\_max   \textcolor{comment}{! The bounding values of the transport error [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1]}}
\DoxyCodeLine{3526                                  \textcolor{comment}{! or [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{3527 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: tol = 1.0e-\/10 \textcolor{comment}{! A fractional match tolerance [nondim]}}
\DoxyCodeLine{3528 \textcolor{keywordtype}{  real} :: dvel  \textcolor{comment}{! Temporary variable used in the limiting the velocity [L T-\/1 \string~> m s-\/1] or [L \string~> m].}}
\DoxyCodeLine{3529 \textcolor{keywordtype}{  real} :: vsr   \textcolor{comment}{! Temporary variable used in the limiting the velocity [nondim].}}
\DoxyCodeLine{3530 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: vs1 = 1.25  \textcolor{comment}{! Nondimensional parameters used in limiting}}
\DoxyCodeLine{3531 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: vs2 = 2.0   \textcolor{comment}{! the velocity, starting at vs1, with the}}
\DoxyCodeLine{3532                                  \textcolor{comment}{! maximum increase of vs2, both nondim.}}
\DoxyCodeLine{3533   \textcolor{keywordtype}{integer} :: itt, max\_itt = 20}
\DoxyCodeLine{3534 }
\DoxyCodeLine{3535   \textcolor{comment}{! Find the value of ubt that gives uhbt.}}
\DoxyCodeLine{3536   \textcolor{keywordflow}{if} (uhbt == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3537     ubt = 0.0}
\DoxyCodeLine{3538   \textcolor{keywordflow}{elseif} (uhbt < btc\%uh\_EE) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3539     ubt = btc\%uBT\_EE + (uhbt -\/ btc\%uh\_EE) / btc\%FA\_u\_EE}
\DoxyCodeLine{3540   \textcolor{keywordflow}{elseif} (uhbt < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3541     \textcolor{comment}{! Iterate to convergence with Newton's method (when bounded) and the}}
\DoxyCodeLine{3542     \textcolor{comment}{! false position method otherwise.  ubt will be negative.}}
\DoxyCodeLine{3543     ubt\_min = btc\%uBT\_EE ; uherr\_min = btc\%uh\_EE -\/ uhbt}
\DoxyCodeLine{3544     ubt\_max = 0.0 ; uherr\_max = -\/uhbt}
\DoxyCodeLine{3545     \textcolor{comment}{! Use a false-\/position method first guess.}}
\DoxyCodeLine{3546     ubt = btc\%uBT\_EE * (uhbt / btc\%uh\_EE)}
\DoxyCodeLine{3547     \textcolor{keywordflow}{do} itt = 1, max\_itt}
\DoxyCodeLine{3548       uhbt\_err = ubt * (btc\%FA\_u\_E0 + btc\%uh\_crvE * ubt**2) -\/ uhbt}
\DoxyCodeLine{3549 }
\DoxyCodeLine{3550       \textcolor{keywordflow}{if} (abs(uhbt\_err) < tol*abs(uhbt)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3551       \textcolor{keywordflow}{if} (uhbt\_err > 0.0) \textcolor{keywordflow}{then} ; ubt\_max = ubt ; uherr\_max = uhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3552       \textcolor{keywordflow}{if} (uhbt\_err < 0.0) \textcolor{keywordflow}{then} ; ubt\_min = ubt ; uherr\_min = uhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3553 }
\DoxyCodeLine{3554       derr\_du = btc\%FA\_u\_E0 + 3.0 * btc\%uh\_crvE * ubt**2}
\DoxyCodeLine{3555       \textcolor{keywordflow}{if} ((uhbt\_err >= derr\_du*(ubt -\/ ubt\_min)) .or. \&}
\DoxyCodeLine{3556           (-\/uhbt\_err >= derr\_du*(ubt\_max -\/ ubt)) .or. (derr\_du <= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3557         \textcolor{comment}{! Use a false-\/position method guess.}}
\DoxyCodeLine{3558         ubt = ubt\_max + (ubt\_min-\/ubt\_max) * (uherr\_max / (uherr\_max-\/uherr\_min))}
\DoxyCodeLine{3559       \textcolor{keywordflow}{else} \textcolor{comment}{! Use Newton's method.}}
\DoxyCodeLine{3560         ubt = ubt -\/ uhbt\_err / derr\_du}
\DoxyCodeLine{3561         \textcolor{keywordflow}{if} (abs(uhbt\_err) < (0.01*tol)*abs(ubt\_min*derr\_du)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3562 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3563 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{3564   \textcolor{keywordflow}{elseif} (uhbt <= btc\%uh\_WW) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3565     \textcolor{comment}{! Iterate to convergence with Newton's method.  ubt will be positive.}}
\DoxyCodeLine{3566     ubt\_min = 0.0 ; uherr\_min = -\/uhbt}
\DoxyCodeLine{3567     ubt\_max = btc\%uBT\_WW ; uherr\_max = btc\%uh\_WW -\/ uhbt}
\DoxyCodeLine{3568     \textcolor{comment}{! Use a false-\/position method first guess.}}
\DoxyCodeLine{3569     ubt = btc\%uBT\_WW * (uhbt / btc\%uh\_WW)}
\DoxyCodeLine{3570     \textcolor{keywordflow}{do} itt = 1, max\_itt}
\DoxyCodeLine{3571       uhbt\_err = ubt * (btc\%FA\_u\_W0 + btc\%uh\_crvW * ubt**2) -\/ uhbt}
\DoxyCodeLine{3572 }
\DoxyCodeLine{3573       \textcolor{keywordflow}{if} (abs(uhbt\_err) < tol*abs(uhbt)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3574       \textcolor{keywordflow}{if} (uhbt\_err > 0.0) \textcolor{keywordflow}{then} ; ubt\_max = ubt ; uherr\_max = uhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3575       \textcolor{keywordflow}{if} (uhbt\_err < 0.0) \textcolor{keywordflow}{then} ; ubt\_min = ubt ; uherr\_min = uhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3576 }
\DoxyCodeLine{3577       derr\_du = btc\%FA\_u\_W0 + 3.0 * btc\%uh\_crvW * ubt**2}
\DoxyCodeLine{3578       \textcolor{keywordflow}{if} ((uhbt\_err >= derr\_du*(ubt -\/ ubt\_min)) .or. \&}
\DoxyCodeLine{3579           (-\/uhbt\_err >= derr\_du*(ubt\_max -\/ ubt)) .or. (derr\_du <= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3580         \textcolor{comment}{! Use a false-\/position method guess.}}
\DoxyCodeLine{3581         ubt = ubt\_min + (ubt\_max-\/ubt\_min) * (-\/uherr\_min / (uherr\_max-\/uherr\_min))}
\DoxyCodeLine{3582       \textcolor{keywordflow}{else} \textcolor{comment}{! Use Newton's method.}}
\DoxyCodeLine{3583         ubt = ubt -\/ uhbt\_err / derr\_du}
\DoxyCodeLine{3584         \textcolor{keywordflow}{if} (abs(uhbt\_err) < (0.01*tol)*(ubt\_max*derr\_du)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3585 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3586 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{3587   \textcolor{keywordflow}{else} \textcolor{comment}{! (uhbt > BTC\%uh\_WW)}}
\DoxyCodeLine{3588     ubt = btc\%uBT\_WW + (uhbt -\/ btc\%uh\_WW) / btc\%FA\_u\_WW}
\DoxyCodeLine{3589 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3590 }
\DoxyCodeLine{3591   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(guess)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3592     dvel = abs(ubt) -\/ vs1*abs(guess)}
\DoxyCodeLine{3593     \textcolor{keywordflow}{if} (dvel > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Limit the velocity}}
\DoxyCodeLine{3594       \textcolor{keywordflow}{if} (dvel < 40.0 * (abs(guess)*(vs2-\/vs1)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3595         vsr = vs2 -\/ (vs2-\/vs1) * exp(-\/dvel / (abs(guess)*(vs2-\/vs1)))}
\DoxyCodeLine{3596       \textcolor{keywordflow}{else}  \textcolor{comment}{! The exp is less than 4e-\/18 anyway in this case, so neglect it.}}
\DoxyCodeLine{3597         vsr = vs2}
\DoxyCodeLine{3598 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3599       ubt = sign(vsr * guess, ubt)}
\DoxyCodeLine{3600 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3601 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3602 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__barotropic_aeed3e618781611b448105a122e1a358c}\label{namespacemom__barotropic_aeed3e618781611b448105a122e1a358c}} 
\index{mom\_barotropic@{mom\_barotropic}!vhbt\_to\_vbt@{vhbt\_to\_vbt}}
\index{vhbt\_to\_vbt@{vhbt\_to\_vbt}!mom\_barotropic@{mom\_barotropic}}
\doxysubsubsection{\texorpdfstring{vhbt\_to\_vbt()}{vhbt\_to\_vbt()}}
{\footnotesize\ttfamily real function mom\+\_\+barotropic\+::vhbt\+\_\+to\+\_\+vbt (\begin{DoxyParamCaption}\item[{real, intent(in)}]{vhbt,  }\item[{type(\mbox{\hyperlink{structmom__barotropic_1_1local__bt__cont__v__type}{local\+\_\+bt\+\_\+cont\+\_\+v\+\_\+type}}), intent(in)}]{B\+TC,  }\item[{real, intent(in), optional}]{guess }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function inverts the transport function to determine the barotopic velocity that is consistent with a given transport, or if I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT=True this finds the time-\/integrated velocity that is consistent with a time-\/integrated transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em vhbt} & The barotropic meridional transport that should be inverted for \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]} or the time-\/integrated transport \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em btc} & A structure containing various fields that allow the barotropic transports to be calculated consistently with the layers\textquotesingle{} continuity equations. The dimensions of some of the elements in this type vary depending on I\+N\+T\+E\+G\+R\+A\+L\+\_\+\+B\+T\+\_\+\+C\+O\+NT. \\
\hline
\mbox{\texttt{ in}}  & {\em guess} & A guess at what vbt will be \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or \mbox{[}L $\sim$$>$ m\mbox{]}. The result is not allowed to be dramatically larger than guess. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The result -\/ The velocity that gives vhbt transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} or the time-\/integrated velocity \mbox{[}L $\sim$$>$ m\mbox{]}. 
\end{DoxyReturn}


Definition at line 3657 of file M\+O\+M\+\_\+barotropic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3658 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: vhbt\textcolor{comment}{                      !< The barotropic meridional transport that should be}}
\DoxyCodeLine{3659 \textcolor{comment}{                                                !! inverted for [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1] or the}}
\DoxyCodeLine{3660 \textcolor{comment}{                                                !! time-\/integrated transport [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{3661   \textcolor{keywordtype}{type}(local\_BT\_cont\_v\_type), \textcolor{keywordtype}{intent(in)} :: BTC\textcolor{comment}{ !< A structure containing various fields that allow the}}
\DoxyCodeLine{3662 \textcolor{comment}{                                                !! barotropic transports to be calculated consistently}}
\DoxyCodeLine{3663 \textcolor{comment}{                                                !! with the layers' continuity equations.  The dimensions of some}}
\DoxyCodeLine{3664 \textcolor{comment}{                                                !! of the elements in this type vary depending on INTEGRAL\_BT\_CONT.}}
\DoxyCodeLine{3665 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: guess\textcolor{comment}{           !< A guess at what vbt will be [L T-\/1 \string~> m s-\/1] or [L \string~> m].}}
\DoxyCodeLine{3666 \textcolor{comment}{                                                !! The result is not allowed to be dramatically larger than guess.}}
\DoxyCodeLine{3667 \textcolor{keywordtype}{  real} :: vbt\textcolor{comment}{                                   !< The result -\/ The velocity that gives vhbt transport [L T-\/1 \string~> m s-\/1]}}
\DoxyCodeLine{3668 \textcolor{comment}{                                                !! or the time-\/integrated velocity [L \string~> m].}}
\DoxyCodeLine{3669 }
\DoxyCodeLine{3670   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3671 \textcolor{keywordtype}{  real} :: vbt\_min, vbt\_max       \textcolor{comment}{! Bounding values of vbt [L T-\/1 \string~> m s-\/1] or [L \string~> m]}}
\DoxyCodeLine{3672 \textcolor{keywordtype}{  real} :: vhbt\_err               \textcolor{comment}{! The transport error [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1] or [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{3673 \textcolor{keywordtype}{  real} :: derr\_dv                \textcolor{comment}{! The change in transport error with vbt, i.e. the face area [H L \string~> m2 or kg m-\/1].}}
\DoxyCodeLine{3674 \textcolor{keywordtype}{  real} :: vherr\_min, vherr\_max   \textcolor{comment}{! The bounding values of the transport error [H L2 T-\/1 \string~> m3 s-\/1 or kg s-\/1]}}
\DoxyCodeLine{3675                                  \textcolor{comment}{! or [H L2 \string~> m3 or kg].}}
\DoxyCodeLine{3676 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: tol = 1.0e-\/10 \textcolor{comment}{! A fractional match tolerance [nondim]}}
\DoxyCodeLine{3677 \textcolor{keywordtype}{  real} :: dvel  \textcolor{comment}{! Temporary variable used in the limiting the velocity [L T-\/1 \string~> m s-\/1] or [L \string~> m].}}
\DoxyCodeLine{3678 \textcolor{keywordtype}{  real} :: vsr   \textcolor{comment}{! Temporary variable used in the limiting the velocity [nondim].}}
\DoxyCodeLine{3679 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: vs1 = 1.25  \textcolor{comment}{! Nondimensional parameters used in limiting}}
\DoxyCodeLine{3680 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: vs2 = 2.0   \textcolor{comment}{! the velocity, starting at vs1, with the}}
\DoxyCodeLine{3681                                  \textcolor{comment}{! maximum increase of vs2, both nondim.}}
\DoxyCodeLine{3682   \textcolor{keywordtype}{integer} :: itt, max\_itt = 20}
\DoxyCodeLine{3683 }
\DoxyCodeLine{3684   \textcolor{comment}{! Find the value of vbt that gives vhbt.}}
\DoxyCodeLine{3685   \textcolor{keywordflow}{if} (vhbt == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3686     vbt = 0.0}
\DoxyCodeLine{3687   \textcolor{keywordflow}{elseif} (vhbt < btc\%vh\_NN) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3688     vbt = btc\%vBT\_NN + (vhbt -\/ btc\%vh\_NN) / btc\%FA\_v\_NN}
\DoxyCodeLine{3689   \textcolor{keywordflow}{elseif} (vhbt < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3690     \textcolor{comment}{! Iterate to convergence with Newton's method (when bounded) and the}}
\DoxyCodeLine{3691     \textcolor{comment}{! false position method otherwise.  vbt will be negative.}}
\DoxyCodeLine{3692     vbt\_min = btc\%vBT\_NN ; vherr\_min = btc\%vh\_NN -\/ vhbt}
\DoxyCodeLine{3693     vbt\_max = 0.0 ; vherr\_max = -\/vhbt}
\DoxyCodeLine{3694     \textcolor{comment}{! Use a false-\/position method first guess.}}
\DoxyCodeLine{3695     vbt = btc\%vBT\_NN * (vhbt / btc\%vh\_NN)}
\DoxyCodeLine{3696     \textcolor{keywordflow}{do} itt = 1, max\_itt}
\DoxyCodeLine{3697       vhbt\_err = vbt * (btc\%FA\_v\_N0 + btc\%vh\_crvN * vbt**2) -\/ vhbt}
\DoxyCodeLine{3698 }
\DoxyCodeLine{3699       \textcolor{keywordflow}{if} (abs(vhbt\_err) < tol*abs(vhbt)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3700       \textcolor{keywordflow}{if} (vhbt\_err > 0.0) \textcolor{keywordflow}{then} ; vbt\_max = vbt ; vherr\_max = vhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3701       \textcolor{keywordflow}{if} (vhbt\_err < 0.0) \textcolor{keywordflow}{then} ; vbt\_min = vbt ; vherr\_min = vhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3702 }
\DoxyCodeLine{3703       derr\_dv = btc\%FA\_v\_N0 + 3.0 * btc\%vh\_crvN * vbt**2}
\DoxyCodeLine{3704       \textcolor{keywordflow}{if} ((vhbt\_err >= derr\_dv*(vbt -\/ vbt\_min)) .or. \&}
\DoxyCodeLine{3705           (-\/vhbt\_err >= derr\_dv*(vbt\_max -\/ vbt)) .or. (derr\_dv <= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3706         \textcolor{comment}{! Use a false-\/position method guess.}}
\DoxyCodeLine{3707         vbt = vbt\_max + (vbt\_min-\/vbt\_max) * (vherr\_max / (vherr\_max-\/vherr\_min))}
\DoxyCodeLine{3708       \textcolor{keywordflow}{else} \textcolor{comment}{! Use Newton's method.}}
\DoxyCodeLine{3709         vbt = vbt -\/ vhbt\_err / derr\_dv}
\DoxyCodeLine{3710         \textcolor{keywordflow}{if} (abs(vhbt\_err) < (0.01*tol)*abs(derr\_dv*vbt\_min)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3711 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3712 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{3713   \textcolor{keywordflow}{elseif} (vhbt <= btc\%vh\_SS) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3714     \textcolor{comment}{! Iterate to convergence with Newton's method.  vbt will be positive.}}
\DoxyCodeLine{3715     vbt\_min = 0.0 ; vherr\_min = -\/vhbt}
\DoxyCodeLine{3716     vbt\_max = btc\%vBT\_SS ; vherr\_max = btc\%vh\_SS -\/ vhbt}
\DoxyCodeLine{3717     \textcolor{comment}{! Use a false-\/position method first guess.}}
\DoxyCodeLine{3718     vbt = btc\%vBT\_SS * (vhbt / btc\%vh\_SS)}
\DoxyCodeLine{3719     \textcolor{keywordflow}{do} itt = 1, max\_itt}
\DoxyCodeLine{3720       vhbt\_err = vbt * (btc\%FA\_v\_S0 + btc\%vh\_crvS * vbt**2) -\/ vhbt}
\DoxyCodeLine{3721 }
\DoxyCodeLine{3722       \textcolor{keywordflow}{if} (abs(vhbt\_err) < tol*abs(vhbt)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3723       \textcolor{keywordflow}{if} (vhbt\_err > 0.0) \textcolor{keywordflow}{then} ; vbt\_max = vbt ; vherr\_max = vhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3724       \textcolor{keywordflow}{if} (vhbt\_err < 0.0) \textcolor{keywordflow}{then} ; vbt\_min = vbt ; vherr\_min = vhbt\_err ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3725 }
\DoxyCodeLine{3726       derr\_dv = btc\%FA\_v\_S0 + 3.0 * btc\%vh\_crvS * vbt**2}
\DoxyCodeLine{3727       \textcolor{keywordflow}{if} ((vhbt\_err >= derr\_dv*(vbt -\/ vbt\_min)) .or. \&}
\DoxyCodeLine{3728           (-\/vhbt\_err >= derr\_dv*(vbt\_max -\/ vbt)) .or. (derr\_dv <= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3729         \textcolor{comment}{! Use a false-\/position method guess.}}
\DoxyCodeLine{3730         vbt = vbt\_min + (vbt\_max-\/vbt\_min) * (-\/vherr\_min / (vherr\_max-\/vherr\_min))}
\DoxyCodeLine{3731       \textcolor{keywordflow}{else} \textcolor{comment}{! Use Newton's method.}}
\DoxyCodeLine{3732         vbt = vbt -\/ vhbt\_err / derr\_dv}
\DoxyCodeLine{3733         \textcolor{keywordflow}{if} (abs(vhbt\_err) < (0.01*tol)*(vbt\_max*derr\_dv)) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{3734 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3735 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{3736   \textcolor{keywordflow}{else} \textcolor{comment}{! (vhbt > BTC\%vh\_SS)}}
\DoxyCodeLine{3737     vbt = btc\%vBT\_SS + (vhbt -\/ btc\%vh\_SS) / btc\%FA\_v\_SS}
\DoxyCodeLine{3738 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3739 }
\DoxyCodeLine{3740   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(guess)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3741     dvel = abs(vbt) -\/ vs1*abs(guess)}
\DoxyCodeLine{3742     \textcolor{keywordflow}{if} (dvel > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Limit the velocity}}
\DoxyCodeLine{3743       \textcolor{keywordflow}{if} (dvel < 40.0 * (abs(guess)*(vs2-\/vs1)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3744         vsr = vs2 -\/ (vs2-\/vs1) * exp(-\/dvel / (abs(guess)*(vs2-\/vs1)))}
\DoxyCodeLine{3745       \textcolor{keywordflow}{else}  \textcolor{comment}{! The exp is less than 4e-\/18 anyway in this case, so neglect it.}}
\DoxyCodeLine{3746         vsr = vs2}
\DoxyCodeLine{3747 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{3748       vbt = sign(guess * vsr, vbt)}
\DoxyCodeLine{3749 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3750 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3751 }

\end{DoxyCode}
