\hypertarget{namespacemom__pressureforce__fv}{}\section{mom\+\_\+pressureforce\+\_\+fv Module Reference}
\label{namespacemom__pressureforce__fv}\index{mom\_pressureforce\_fv@{mom\_pressureforce\_fv}}


\subsection{Detailed Description}
Finite volume pressure gradient (integrated by quadrature or analytically) 

Provides the Boussinesq and non-\/\+Boussinesq forms of horizontal accelerations due to pressure gradients using a vertically integrated finite volume form, as described by Adcroft et al., 2008. Integration in the vertical is made either by quadrature or analytically.

This form eliminates the thermobaric instabilities that had been a problem with previous forms of the pressure gradient force calculation, as described by Hallberg, 2005.

Adcroft, A., R. Hallberg, and M. Harrison, 2008\+: A finite volume discretization of the pressure gradient force using analytic integration. Ocean Modelling, 22, 106-\/113. \href{http://doi.org/10.1016/j.ocemod.2008.02.001}{\texttt{ http\+://doi.\+org/10.\+1016/j.\+ocemod.\+2008.\+02.\+001}}

Hallberg, 2005\+: A thermobaric instability of Lagrangian vertical coordinate ocean models. Ocean Modelling, 8, 279-\/300. \href{http://dx.doi.org/10.1016/j.ocemod.2004.01.001}{\texttt{ http\+://dx.\+doi.\+org/10.\+1016/j.\+ocemod.\+2004.\+01.\+001}} \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__pressureforce__fv_1_1pressureforce__fv__cs}{pressureforce\+\_\+fv\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Finite volume pressure gradient control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__pressureforce__fv_a50c4a61827e473e643f3f330adf62872}{pressureforce\+\_\+fv\+\_\+nonbouss}} (h, tv, P\+Fu, P\+Fv, G, GV, US, CS, A\+L\+E\+\_\+\+C\+Sp, p\+\_\+atm, pbce, eta)
\begin{DoxyCompactList}\small\item\em Non-\/\+Boussinesq analytically-\/integrated finite volume form of pressure gradient. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__pressureforce__fv_a08e9a212bae769c475093a6e0fd6b12b}{pressureforce\+\_\+fv\+\_\+bouss}} (h, tv, P\+Fu, P\+Fv, G, GV, US, CS, A\+L\+E\+\_\+\+C\+Sp, p\+\_\+atm, pbce, eta)
\begin{DoxyCompactList}\small\item\em Boussinesq analytically-\/integrated finite volume form of pressure gradient. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__pressureforce__fv_a59da32e314b0a8a8feb6e8cd63ef88e0}{pressureforce\+\_\+fv\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS, tides\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Initializes the finite volume pressure gradient control structure. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__pressureforce__fv_ae4ced0f46de081e5cbd55134d878e802}{pressureforce\+\_\+fv\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Deallocates the finite volume pressure gradient control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__pressureforce__fv_a08e9a212bae769c475093a6e0fd6b12b}\label{namespacemom__pressureforce__fv_a08e9a212bae769c475093a6e0fd6b12b}} 
\index{mom\_pressureforce\_fv@{mom\_pressureforce\_fv}!pressureforce\_fv\_bouss@{pressureforce\_fv\_bouss}}
\index{pressureforce\_fv\_bouss@{pressureforce\_fv\_bouss}!mom\_pressureforce\_fv@{mom\_pressureforce\_fv}}
\subsubsection{\texorpdfstring{pressureforce\_fv\_bouss()}{pressureforce\_fv\_bouss()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+pressureforce\+\_\+fv\+::pressureforce\+\_\+fv\+\_\+bouss (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{P\+Fu,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out)}]{P\+Fv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__pressureforce__fv_1_1pressureforce__fv__cs}{pressureforce\+\_\+fv\+\_\+cs}}), pointer}]{CS,  }\item[{type(ale\+\_\+cs), pointer}]{A\+L\+E\+\_\+\+C\+Sp,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{p\+\_\+atm,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{pbce,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out), optional}]{eta }\end{DoxyParamCaption})}



Boussinesq analytically-\/integrated finite volume form of pressure gradient. 

Determines the acceleration due to hydrostatic pressure forces, using the finite volume form of the terms and analytic integrals in depth.

To work, the following fields must be set outside of the usual (is\+:ie,js\+:je) range before this subroutine is called\+: h(isB\+:ie+1,jsB\+:je+1), T(isB\+:ie+1,jsB\+:je+1), and S(isB\+:ie+1,jsB\+:je+1). 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables \\
\hline
\mbox{\texttt{ out}}  & {\em pfu} & Zonal acceleration \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em pfv} & Meridional acceleration \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
 & {\em cs} & Finite volume P\+GF control structure \\
\hline
 & {\em ale\+\_\+csp} & A\+LE control structure \\
\hline
 & {\em p\+\_\+atm} & The pressure at the ice-\/ocean or atmosphere-\/ocean interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em pbce} & The baroclinic pressure anomaly in each layer due to eta anomalies \mbox{[}L2 T-\/2 H-\/1 $\sim$$>$ m s-\/2 or m4 s-\/2 kg-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em eta} & The bottom mass used to calculate P\+Fu and P\+Fv \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}, with any tidal contributions or compressibility compensation. \\
\hline
\end{DoxyParams}


Definition at line 417 of file M\+O\+M\+\_\+\+Pressure\+Force\+\_\+\+F\+V.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{417   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{   !< Ocean grid structure}}
\DoxyCodeLine{418   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{  !< Vertical grid structure}}
\DoxyCodeLine{419   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{420 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{   !< Layer thickness [H ~> m]}}
\DoxyCodeLine{421   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}  :: tv\textcolor{comment}{  !< Thermodynamic variables}}
\DoxyCodeLine{422 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: PFu\textcolor{comment}{ !< Zonal acceleration [L T-2 ~> m s-2]}}
\DoxyCodeLine{423 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: PFv\textcolor{comment}{ !< Meridional acceleration [L T-2 ~> m s-2]}}
\DoxyCodeLine{424   \textcolor{keywordtype}{type}(PressureForce\_FV\_CS),                 \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{  !< Finite volume PGF control structure}}
\DoxyCodeLine{425   \textcolor{keywordtype}{type}(ALE\_CS),                              \textcolor{keywordtype}{pointer}     :: ALE\_CSp\textcolor{comment}{ !< ALE control structure}}
\DoxyCodeLine{426 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: p\_atm\textcolor{comment}{ !< The pressure at the ice-ocean}}
\DoxyCodeLine{427 \textcolor{comment}{                                                         !! or atmosphere-ocean interface [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{428 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: pbce\textcolor{comment}{ !< The baroclinic pressure}}
\DoxyCodeLine{429 \textcolor{comment}{                                                         !! anomaly in each layer due to eta anomalies}}
\DoxyCodeLine{430 \textcolor{comment}{                                                         !! [L2 T-2 H-1 ~> m s-2 or m4 s-2 kg-1].}}
\DoxyCodeLine{431 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: eta\textcolor{comment}{ !< The bottom mass used to}}
\DoxyCodeLine{432 \textcolor{comment}{                                                         !! calculate PFu and PFv [H ~> m or kg m-2], with any}}
\DoxyCodeLine{433 \textcolor{comment}{                                                         !! tidal contributions or compressibility compensation.}}
\DoxyCodeLine{434   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{435 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)} :: e \textcolor{comment}{! Interface height in depth units [Z ~> m].}}
\DoxyCodeLine{436 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: \&}
\DoxyCodeLine{437     e\_tidal, \&  \textcolor{comment}{! The bottom geopotential anomaly due to tidal forces from}}
\DoxyCodeLine{438                 \textcolor{comment}{! astronomical sources and self-attraction and loading [Z ~> m].}}
\DoxyCodeLine{439     dm          \textcolor{comment}{! The barotropic adjustment to the Montgomery potential to}}
\DoxyCodeLine{440                 \textcolor{comment}{! account for a reduced gravity model [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{441 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{442     Rho\_cv\_BL   \textcolor{comment}{!   The coordinate potential density in the deepest variable}}
\DoxyCodeLine{443                 \textcolor{comment}{! density near-surface layer [R ~> kg m-3].}}
\DoxyCodeLine{444 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{445     dz\_geo, \&   \textcolor{comment}{! The change in geopotential thickness through a layer [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{446     pa, \&       \textcolor{comment}{! The pressure anomaly (i.e. pressure + g*RHO\_0*e) at the}}
\DoxyCodeLine{447                 \textcolor{comment}{! the interface atop a layer [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{448     dpa, \&      \textcolor{comment}{! The change in pressure anomaly between the top and bottom}}
\DoxyCodeLine{449                 \textcolor{comment}{! of a layer [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{450     intz\_dpa    \textcolor{comment}{! The vertical integral in depth of the pressure anomaly less the}}
\DoxyCodeLine{451                 \textcolor{comment}{! pressure anomaly at the top of the layer [H R L2 T-2 ~> m Pa or kg m-2 Pa].}}
\DoxyCodeLine{452 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{453     intx\_pa, \&  \textcolor{comment}{! The zonal integral of the pressure anomaly along the interface}}
\DoxyCodeLine{454                 \textcolor{comment}{! atop a layer, divided by the grid spacing [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{455     intx\_dpa    \textcolor{comment}{! The change in intx\_pa through a layer [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{456 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{457     inty\_pa, \&  \textcolor{comment}{! The meridional integral of the pressure anomaly along the}}
\DoxyCodeLine{458                 \textcolor{comment}{! interface atop a layer, divided by the grid spacing [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{459     inty\_dpa    \textcolor{comment}{! The change in inty\_pa through a layer [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{460 }
\DoxyCodeLine{461 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{target} :: \&}
\DoxyCodeLine{462     T\_tmp, \&    \textcolor{comment}{! Temporary array of temperatures where layers that are lighter}}
\DoxyCodeLine{463                 \textcolor{comment}{! than the mixed layer have the mixed layer's properties [degC].}}
\DoxyCodeLine{464     s\_tmp       \textcolor{comment}{! Temporary array of salinities where layers that are lighter}}
\DoxyCodeLine{465                 \textcolor{comment}{! than the mixed layer have the mixed layer's properties [ppt].}}
\DoxyCodeLine{466 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{467     S\_t, S\_b, T\_t, T\_b \textcolor{comment}{! Top and bottom edge values for linear reconstructions}}
\DoxyCodeLine{468                        \textcolor{comment}{! of salinity and temperature within each layer.}}
\DoxyCodeLine{469 \textcolor{keywordtype}{  real} :: rho\_in\_situ(SZI\_(G)) \textcolor{comment}{! The in situ density [R ~> kg m-3].}}
\DoxyCodeLine{470 \textcolor{keywordtype}{  real} :: p\_ref(SZI\_(G))     \textcolor{comment}{!   The pressure used to calculate the coordinate}}
\DoxyCodeLine{471                              \textcolor{comment}{! density, [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).}}
\DoxyCodeLine{472 \textcolor{keywordtype}{  real} :: p0(SZI\_(G))        \textcolor{comment}{! An array of zeros to use for pressure [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{473 \textcolor{keywordtype}{  real} :: h\_neglect          \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{474                              \textcolor{comment}{! in roundoff and can be neglected [H ~> m].}}
\DoxyCodeLine{475 \textcolor{keywordtype}{  real} :: I\_Rho0             \textcolor{comment}{! The inverse of the Boussinesq reference density [R-1 ~> m3 kg-1].}}
\DoxyCodeLine{476 \textcolor{keywordtype}{  real} :: G\_Rho0             \textcolor{comment}{! G\_Earth / Rho0 in [L2 Z-1 T-2 R-1 ~> m4 s-2 kg-1].}}
\DoxyCodeLine{477 \textcolor{keywordtype}{  real} :: rho\_ref            \textcolor{comment}{! The reference density [R ~> kg m-3].}}
\DoxyCodeLine{478 \textcolor{keywordtype}{  real} :: dz\_neglect         \textcolor{comment}{! A minimal thickness [Z ~> m], like e.}}
\DoxyCodeLine{479   \textcolor{keywordtype}{logical} :: use\_p\_atm       \textcolor{comment}{! If true, use the atmospheric pressure.}}
\DoxyCodeLine{480   \textcolor{keywordtype}{logical} :: use\_ALE         \textcolor{comment}{! If true, use an ALE pressure reconstruction.}}
\DoxyCodeLine{481   \textcolor{keywordtype}{logical} :: use\_EOS         \textcolor{comment}{! If true, density is calculated from T \& S using an equation of state.}}
\DoxyCodeLine{482   \textcolor{keywordtype}{type}(thermo\_var\_ptrs) :: tv\_tmp\textcolor{comment}{! A structure of temporary T \& S.}}
\DoxyCodeLine{483 \textcolor{keywordtype}{  real} :: Tl(5)              \textcolor{comment}{! copy and T in local stencil [degC]}}
\DoxyCodeLine{484 \textcolor{keywordtype}{  real} :: mn\_T               \textcolor{comment}{! mean of T in local stencil [degC]}}
\DoxyCodeLine{485 \textcolor{keywordtype}{  real} :: mn\_T2              \textcolor{comment}{! mean of T**2 in local stencil [degC]}}
\DoxyCodeLine{486 \textcolor{keywordtype}{  real} :: hl(5)              \textcolor{comment}{! Copy of local stencil of H [H ~> m]}}
\DoxyCodeLine{487 \textcolor{keywordtype}{  real} :: r\_sm\_H             \textcolor{comment}{! Reciprocal of sum of H in local stencil [H-1 ~> m-1]}}
\DoxyCodeLine{488 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_6 = 1.0/6.0}
\DoxyCodeLine{489   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-computational domain for the equation of state}}
\DoxyCodeLine{490   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, nkmb}
\DoxyCodeLine{491   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{492 }
\DoxyCodeLine{493   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{494   nkmb=gv\%nk\_rho\_varies}
\DoxyCodeLine{495   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{496   eosdom(1) = isq - (g\%isd-1) ;  eosdom(2) = g\%iec+1 - (g\%isd-1)}
\DoxyCodeLine{497 }
\DoxyCodeLine{498   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{499        \textcolor{stringliteral}{"MOM\_PressureForce\_FV\_Bouss: Module must be initialized before it is used."})}
\DoxyCodeLine{500 }
\DoxyCodeLine{501   use\_p\_atm = .false.}
\DoxyCodeLine{502   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(p\_atm)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_atm)) use\_p\_atm = .true. ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{503   use\_eos = \textcolor{keyword}{associated}(tv\%eqn\_of\_state)}
\DoxyCodeLine{504   \textcolor{keywordflow}{do} i=isq,ieq+1 ; p0(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{505   use\_ale = .false.}
\DoxyCodeLine{506   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(ale\_csp)) use\_ale = cs\%reconstruct .and. use\_eos}
\DoxyCodeLine{507 }
\DoxyCodeLine{508   \textcolor{keywordflow}{if} (cs\%Stanley\_T2\_det\_coeff>=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{509     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(tv\%varT)) \textcolor{keyword}{call }safe\_alloc\_ptr(tv\%varT, g\%isd, g\%ied, g\%jsd, g\%jed, gv\%ke)}
\DoxyCodeLine{510     \textcolor{keywordflow}{do} k=1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1}
\DoxyCodeLine{511       \textcolor{comment}{! Strictly speaking we should estimate the *horizontal* grid-scale variance}}
\DoxyCodeLine{512       \textcolor{comment}{! but neither of the following blocks make a rotation to the horizontal}}
\DoxyCodeLine{513       \textcolor{comment}{! and instead work along coordinate.}}
\DoxyCodeLine{514 }
\DoxyCodeLine{515       \textcolor{comment}{! This block calculates a simple |delta T| along coordinates and does}}
\DoxyCodeLine{516       \textcolor{comment}{! not allow vanishing layer thicknesses or layers tracking topography}}
\DoxyCodeLine{517       \textcolor{comment}{!! SGS variance in i-direction [degC2]}}
\DoxyCodeLine{518       \textcolor{comment}{!dTdi2 = ( ( G\%mask2dCu(I  ,j) * G\%IdxCu(I  ,j) * ( tv\%T(i+1,j,k) - tv\%T(i,j,k) ) \&}}
\DoxyCodeLine{519       \textcolor{comment}{!          + G\%mask2dCu(I-1,j) * G\%IdxCu(I-1,j) * ( tv\%T(i,j,k) - tv\%T(i-1,j,k) ) \&}}
\DoxyCodeLine{520       \textcolor{comment}{!          ) * G\%dxT(i,j) * 0.5 )**2}}
\DoxyCodeLine{521       \textcolor{comment}{!! SGS variance in j-direction [degC2]}}
\DoxyCodeLine{522       \textcolor{comment}{!dTdj2 = ( ( G\%mask2dCv(i,J  ) * G\%IdyCv(i,J  ) * ( tv\%T(i,j+1,k) - tv\%T(i,j,k) ) \&}}
\DoxyCodeLine{523       \textcolor{comment}{!          + G\%mask2dCv(i,J-1) * G\%IdyCv(i,J-1) * ( tv\%T(i,j,k) - tv\%T(i,j-1,k) ) \&}}
\DoxyCodeLine{524       \textcolor{comment}{!          ) * G\%dyT(i,j) * 0.5 )**2}}
\DoxyCodeLine{525       \textcolor{comment}{!tv\%varT(i,j,k) = CS\%Stanley\_T2\_det\_coeff * 0.5 * ( dTdi2 + dTdj2 )}}
\DoxyCodeLine{526 }
\DoxyCodeLine{527       \textcolor{comment}{! This block does a thickness weighted variance calculation and helps control for}}
\DoxyCodeLine{528       \textcolor{comment}{! extreme gradients along layers which are vanished against topography. It is}}
\DoxyCodeLine{529       \textcolor{comment}{! still a poor approximation in the interior when coordinates are strongly tilted.}}
\DoxyCodeLine{530       hl(1) = h(i,j,k) * g\%mask2dT(i,j)}
\DoxyCodeLine{531       hl(2) = h(i-1,j,k) * g\%mask2dCu(i-1,j)}
\DoxyCodeLine{532       hl(3) = h(i+1,j,k) * g\%mask2dCu(i,j)}
\DoxyCodeLine{533       hl(4) = h(i,j-1,k) * g\%mask2dCv(i,j-1)}
\DoxyCodeLine{534       hl(5) = h(i,j+1,k) * g\%mask2dCv(i,j)}
\DoxyCodeLine{535       r\_sm\_h = 1. / ( ( hl(1) + ( ( hl(2) + hl(3) ) + ( hl(4) + hl(5) ) ) ) + gv\%H\_subroundoff )}
\DoxyCodeLine{536       \textcolor{comment}{! Mean of T}}
\DoxyCodeLine{537       tl(1) = tv\%T(i,j,k) ; tl(2) = tv\%T(i-1,j,k) ; tl(3) = tv\%T(i+1,j,k)}
\DoxyCodeLine{538       tl(4) = tv\%T(i,j-1,k) ; tl(5) = tv\%T(i,j+1,k)}
\DoxyCodeLine{539       mn\_t = ( hl(1)*tl(1) + ( ( hl(2)*tl(2) + hl(3)*tl(3) ) + ( hl(4)*tl(4) + hl(5)*tl(5) ) ) ) * r\_sm\_h}
\DoxyCodeLine{540       \textcolor{comment}{! Adjust T vectors to have zero mean}}
\DoxyCodeLine{541       tl(:) = tl(:) - mn\_t ; mn\_t = 0.}
\DoxyCodeLine{542       \textcolor{comment}{! Variance of T}}
\DoxyCodeLine{543       mn\_t2 = ( hl(1)*tl(1)*tl(1) + ( ( hl(2)*tl(2)*tl(2) + hl(3)*tl(3)*tl(3) ) \&}
\DoxyCodeLine{544                                     + ( hl(4)*tl(4)*tl(4) + hl(5)*tl(5)*tl(5) ) ) ) * r\_sm\_h}
\DoxyCodeLine{545       \textcolor{comment}{! Variance should be positive but round-off can violate this. Calculating}}
\DoxyCodeLine{546       \textcolor{comment}{! variance directly would fix this but requires more operations.}}
\DoxyCodeLine{547       tv\%varT(i,j,k) = cs\%Stanley\_T2\_det\_coeff * max(0., mn\_t2)}
\DoxyCodeLine{548 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{549 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{550 }
\DoxyCodeLine{551   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{552   dz\_neglect = gv\%H\_subroundoff * gv\%H\_to\_Z}
\DoxyCodeLine{553   i\_rho0 = 1.0 / gv\%Rho0}
\DoxyCodeLine{554   g\_rho0 = gv\%g\_Earth / gv\%Rho0}
\DoxyCodeLine{555   rho\_ref = cs\%Rho0}
\DoxyCodeLine{556 }
\DoxyCodeLine{557   \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{558     \textcolor{comment}{!   Determine the surface height anomaly for calculating self attraction}}
\DoxyCodeLine{559     \textcolor{comment}{! and loading.  This should really be based on bottom pressure anomalies,}}
\DoxyCodeLine{560     \textcolor{comment}{! but that is not yet implemented, and the current form is correct for}}
\DoxyCodeLine{561     \textcolor{comment}{! barotropic tides.}}
\DoxyCodeLine{562     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{563     \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{564       \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{565         e(i,j,1) = -g\%bathyT(i,j)}
\DoxyCodeLine{566 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{567       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{568         e(i,j,1) = e(i,j,1) + h(i,j,k)*gv\%H\_to\_Z}
\DoxyCodeLine{569 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{570 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{571     \textcolor{keyword}{call }calc\_tidal\_forcing(cs\%Time, e(:,:,1), e\_tidal, g, cs\%tides\_CSp, m\_to\_z=us\%m\_to\_Z)}
\DoxyCodeLine{572 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{573 }
\DoxyCodeLine{574 \textcolor{comment}{!    Here layer interface heights, e, are calculated.}}
\DoxyCodeLine{575   \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{576     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{577     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{578       e(i,j,nz+1) = -(g\%bathyT(i,j) + e\_tidal(i,j))}
\DoxyCodeLine{579 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{580   \textcolor{keywordflow}{else}}
\DoxyCodeLine{581     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{582     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{583       e(i,j,nz+1) = -g\%bathyT(i,j)}
\DoxyCodeLine{584 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{585 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{586   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{587   \textcolor{keywordflow}{do} j=jsq,jeq+1; \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{588     e(i,j,k) = e(i,j,k+1) + h(i,j,k)*gv\%H\_to\_Z}
\DoxyCodeLine{589 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{590 }
\DoxyCodeLine{591   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{592 \textcolor{comment}{! With a bulk mixed layer, replace the T \& S of any layers that are}}
\DoxyCodeLine{593 \textcolor{comment}{! lighter than the the buffer layer with the properties of the buffer}}
\DoxyCodeLine{594 \textcolor{comment}{! layer.  These layers will be massless anyway, and it avoids any}}
\DoxyCodeLine{595 \textcolor{comment}{! formal calculations with hydrostatically unstable profiles.}}
\DoxyCodeLine{596 }
\DoxyCodeLine{597     \textcolor{keywordflow}{if} (nkmb>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{598       tv\_tmp\%T => t\_tmp ; tv\_tmp\%S => s\_tmp}
\DoxyCodeLine{599       tv\_tmp\%eqn\_of\_state => tv\%eqn\_of\_state}
\DoxyCodeLine{600 }
\DoxyCodeLine{601       \textcolor{keywordflow}{do} i=isq,ieq+1 ; p\_ref(i) = tv\%P\_Ref ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{602      \textcolor{comment}{!\$OMP parallel do default(shared) private(Rho\_cv\_BL)}}
\DoxyCodeLine{603       \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{604         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{605           tv\_tmp\%T(i,j,k) = tv\%T(i,j,k) ; tv\_tmp\%S(i,j,k) = tv\%S(i,j,k)}
\DoxyCodeLine{606 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{607         \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,nkmb), tv\%S(:,j,nkmb), p\_ref, rho\_cv\_bl(:), \&}
\DoxyCodeLine{608                                tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{609 }
\DoxyCodeLine{610         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{611           \textcolor{keywordflow}{if} (gv\%Rlay(k) < rho\_cv\_bl(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{612             tv\_tmp\%T(i,j,k) = tv\%T(i,j,nkmb) ; tv\_tmp\%S(i,j,k) = tv\%S(i,j,nkmb)}
\DoxyCodeLine{613           \textcolor{keywordflow}{else}}
\DoxyCodeLine{614             tv\_tmp\%T(i,j,k) = tv\%T(i,j,k) ; tv\_tmp\%S(i,j,k) = tv\%S(i,j,k)}
\DoxyCodeLine{615 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{616 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{617 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{618     \textcolor{keywordflow}{else}}
\DoxyCodeLine{619       tv\_tmp\%T => tv\%T ; tv\_tmp\%S => tv\%S}
\DoxyCodeLine{620       tv\_tmp\%eqn\_of\_state => tv\%eqn\_of\_state}
\DoxyCodeLine{621 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{622 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{623 }
\DoxyCodeLine{624   \textcolor{keywordflow}{if} (cs\%GFS\_scale < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{625     \textcolor{comment}{! Adjust the Montgomery potential to make this a reduced gravity model.}}
\DoxyCodeLine{626     \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{627       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{628       \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{629         \textcolor{keywordflow}{if} (use\_p\_atm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{630           \textcolor{keyword}{call }calculate\_density(tv\_tmp\%T(:,j,1), tv\_tmp\%S(:,j,1), p\_atm(:,j), rho\_in\_situ, \&}
\DoxyCodeLine{631                                  tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{632         \textcolor{keywordflow}{else}}
\DoxyCodeLine{633           \textcolor{keyword}{call }calculate\_density(tv\_tmp\%T(:,j,1), tv\_tmp\%S(:,j,1), p0, rho\_in\_situ, \&}
\DoxyCodeLine{634                                  tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{635 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{636         \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{637           dm(i,j) = (cs\%GFS\_scale - 1.0) * (g\_rho0 * rho\_in\_situ(i)) * e(i,j,1)}
\DoxyCodeLine{638 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{639 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{640     \textcolor{keywordflow}{else}}
\DoxyCodeLine{641       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{642       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{643         dm(i,j) = (cs\%GFS\_scale - 1.0) * (g\_rho0 * gv\%Rlay(1)) * e(i,j,1)}
\DoxyCodeLine{644 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{645 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{646 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{647   \textcolor{comment}{! I have checked that rho\_0 drops out and that the 1-layer case is right. RWH.}}
\DoxyCodeLine{648 }
\DoxyCodeLine{649   \textcolor{comment}{! If regridding is activated, do a linear reconstruction of salinity}}
\DoxyCodeLine{650   \textcolor{comment}{! and temperature across each layer. The subscripts 't' and 'b' refer}}
\DoxyCodeLine{651   \textcolor{comment}{! to top and bottom values within each layer (these are the only degrees}}
\DoxyCodeLine{652   \textcolor{comment}{! of freedeom needed to know the linear profile).}}
\DoxyCodeLine{653   \textcolor{keywordflow}{if} ( use\_ale ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{654     \textcolor{keywordflow}{if} ( cs\%Recon\_Scheme == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{655       \textcolor{keyword}{call }ts\_plm\_edge\_values(ale\_csp, s\_t, s\_b, t\_t, t\_b, g, gv, tv, h, cs\%boundary\_extrap)}
\DoxyCodeLine{656     \textcolor{keywordflow}{elseif} ( cs\%Recon\_Scheme == 2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{657       \textcolor{keyword}{call }ts\_ppm\_edge\_values(ale\_csp, s\_t, s\_b, t\_t, t\_b, g, gv, tv, h, cs\%boundary\_extrap)}
\DoxyCodeLine{658 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{659 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{660 }
\DoxyCodeLine{661   \textcolor{comment}{! Set the surface boundary conditions on pressure anomaly and its horizontal}}
\DoxyCodeLine{662   \textcolor{comment}{! integrals, assuming that the surface pressure anomaly varies linearly}}
\DoxyCodeLine{663   \textcolor{comment}{! in x and y.}}
\DoxyCodeLine{664   \textcolor{keywordflow}{if} (use\_p\_atm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{665     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{666     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{667       pa(i,j) = (rho\_ref*gv\%g\_Earth)*e(i,j,1) + p\_atm(i,j)}
\DoxyCodeLine{668 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{669   \textcolor{keywordflow}{else}}
\DoxyCodeLine{670     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{671     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{672       pa(i,j) = (rho\_ref*gv\%g\_Earth)*e(i,j,1)}
\DoxyCodeLine{673 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{674 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{675   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{676   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{677     intx\_pa(i,j) = 0.5*(pa(i,j) + pa(i+1,j))}
\DoxyCodeLine{678 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{679   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{680   \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{681     inty\_pa(i,j) = 0.5*(pa(i,j) + pa(i,j+1))}
\DoxyCodeLine{682 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{683 }
\DoxyCodeLine{684   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{685     \textcolor{comment}{! Calculate 4 integrals through the layer that are required in the}}
\DoxyCodeLine{686     \textcolor{comment}{! subsequent calculation.}}
\DoxyCodeLine{687 }
\DoxyCodeLine{688     \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{689       \textcolor{comment}{! The following routine computes the integrals that are needed to}}
\DoxyCodeLine{690       \textcolor{comment}{! calculate the pressure gradient force. Linear profiles for T and S are}}
\DoxyCodeLine{691       \textcolor{comment}{! assumed when regridding is activated. Otherwise, the previous version}}
\DoxyCodeLine{692       \textcolor{comment}{! is used, whereby densities within each layer are constant no matter}}
\DoxyCodeLine{693       \textcolor{comment}{! where the layers are located.}}
\DoxyCodeLine{694       \textcolor{keywordflow}{if} ( use\_ale ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{695         \textcolor{keywordflow}{if} ( cs\%Recon\_Scheme == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{696           \textcolor{keyword}{call }int\_density\_dz\_generic\_plm(k, tv,  t\_t, t\_b, s\_t, s\_b, e, \&}
\DoxyCodeLine{697                     rho\_ref, cs\%Rho0, gv\%g\_Earth, dz\_neglect, g\%bathyT, \&}
\DoxyCodeLine{698                     g\%HI, gv, tv\%eqn\_of\_state, us, dpa, intz\_dpa, intx\_dpa, inty\_dpa, \&}
\DoxyCodeLine{699                     usemasswghtinterp=cs\%useMassWghtInterp)}
\DoxyCodeLine{700         \textcolor{keywordflow}{elseif} ( cs\%Recon\_Scheme == 2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{701           \textcolor{keyword}{call }int\_density\_dz\_generic\_ppm(k, tv, t\_t, t\_b, s\_t, s\_b, e, \&}
\DoxyCodeLine{702                     rho\_ref, cs\%Rho0, gv\%g\_Earth, dz\_neglect, g\%bathyT, \&}
\DoxyCodeLine{703                     g\%HI, gv, tv\%eqn\_of\_state, us, dpa, intz\_dpa, intx\_dpa, inty\_dpa, \&}
\DoxyCodeLine{704                     usemasswghtinterp=cs\%useMassWghtInterp)}
\DoxyCodeLine{705 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{706       \textcolor{keywordflow}{else}}
\DoxyCodeLine{707         \textcolor{keyword}{call }int\_density\_dz(tv\_tmp\%T(:,:,k), tv\_tmp\%S(:,:,k), e(:,:,k), e(:,:,k+1), \&}
\DoxyCodeLine{708                   rho\_ref, cs\%Rho0, gv\%g\_Earth, g\%HI, tv\%eqn\_of\_state, us, dpa, \&}
\DoxyCodeLine{709                   intz\_dpa, intx\_dpa, inty\_dpa, g\%bathyT, dz\_neglect, cs\%useMassWghtInterp)}
\DoxyCodeLine{710 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{711       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{712       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{713         intz\_dpa(i,j) = intz\_dpa(i,j)*gv\%Z\_to\_H}
\DoxyCodeLine{714 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{715     \textcolor{keywordflow}{else}}
\DoxyCodeLine{716       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{717       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{718         dz\_geo(i,j) = gv\%g\_Earth * gv\%H\_to\_Z*h(i,j,k)}
\DoxyCodeLine{719         dpa(i,j) = (gv\%Rlay(k) - rho\_ref) * dz\_geo(i,j)}
\DoxyCodeLine{720         intz\_dpa(i,j) = 0.5*(gv\%Rlay(k) - rho\_ref) * dz\_geo(i,j)*h(i,j,k)}
\DoxyCodeLine{721 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{722       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{723       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{724         intx\_dpa(i,j) = 0.5*(gv\%Rlay(k) - rho\_ref) * (dz\_geo(i,j) + dz\_geo(i+1,j))}
\DoxyCodeLine{725 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{726       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{727       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{728         inty\_dpa(i,j) = 0.5*(gv\%Rlay(k) - rho\_ref) * (dz\_geo(i,j) + dz\_geo(i,j+1))}
\DoxyCodeLine{729 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{730 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{731 }
\DoxyCodeLine{732     \textcolor{comment}{! Compute pressure gradient in x direction}}
\DoxyCodeLine{733     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{734     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{735       pfu(i,j,k) = (((pa(i,j)*h(i,j,k) + intz\_dpa(i,j)) - \&}
\DoxyCodeLine{736                    (pa(i+1,j)*h(i+1,j,k) + intz\_dpa(i+1,j))) + \&}
\DoxyCodeLine{737                    ((h(i+1,j,k) - h(i,j,k)) * intx\_pa(i,j) - \&}
\DoxyCodeLine{738                    (e(i+1,j,k+1) - e(i,j,k+1)) * intx\_dpa(i,j) * gv\%Z\_to\_H)) * \&}
\DoxyCodeLine{739                    ((2.0*i\_rho0*g\%IdxCu(i,j)) / \&}
\DoxyCodeLine{740                    ((h(i,j,k) + h(i+1,j,k)) + h\_neglect))}
\DoxyCodeLine{741       intx\_pa(i,j) = intx\_pa(i,j) + intx\_dpa(i,j)}
\DoxyCodeLine{742 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{743     \textcolor{comment}{! Compute pressure gradient in y direction}}
\DoxyCodeLine{744     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{745     \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{746       pfv(i,j,k) = (((pa(i,j)*h(i,j,k) + intz\_dpa(i,j)) - \&}
\DoxyCodeLine{747                    (pa(i,j+1)*h(i,j+1,k) + intz\_dpa(i,j+1))) + \&}
\DoxyCodeLine{748                    ((h(i,j+1,k) - h(i,j,k)) * inty\_pa(i,j) - \&}
\DoxyCodeLine{749                    (e(i,j+1,k+1) - e(i,j,k+1)) * inty\_dpa(i,j) * gv\%Z\_to\_H)) * \&}
\DoxyCodeLine{750                    ((2.0*i\_rho0*g\%IdyCv(i,j)) / \&}
\DoxyCodeLine{751                    ((h(i,j,k) + h(i,j+1,k)) + h\_neglect))}
\DoxyCodeLine{752       inty\_pa(i,j) = inty\_pa(i,j) + inty\_dpa(i,j)}
\DoxyCodeLine{753 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{754     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{755     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{756       pa(i,j) = pa(i,j) + dpa(i,j)}
\DoxyCodeLine{757 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{758 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{759 }
\DoxyCodeLine{760   \textcolor{keywordflow}{if} (cs\%GFS\_scale < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{761     \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{762       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{763       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{764         pfu(i,j,k) = pfu(i,j,k) - (dm(i+1,j) - dm(i,j)) * g\%IdxCu(i,j)}
\DoxyCodeLine{765 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{766       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{767       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{768         pfv(i,j,k) = pfv(i,j,k) - (dm(i,j+1) - dm(i,j)) * g\%IdyCv(i,j)}
\DoxyCodeLine{769 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{770 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{771 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{772 }
\DoxyCodeLine{773   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(pbce)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{774     \textcolor{keyword}{call }set\_pbce\_bouss(e, tv\_tmp, g, gv, us, cs\%Rho0, cs\%GFS\_scale, pbce)}
\DoxyCodeLine{775 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{776 }
\DoxyCodeLine{777   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(eta)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{778     \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{779     \textcolor{comment}{! eta is the sea surface height relative to a time-invariant geoid, for comparison with}}
\DoxyCodeLine{780     \textcolor{comment}{! what is used for eta in btstep.  See how e was calculated about 200 lines above.}}
\DoxyCodeLine{781       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{782       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{783         eta(i,j) = e(i,j,1)*gv\%Z\_to\_H + e\_tidal(i,j)*gv\%Z\_to\_H}
\DoxyCodeLine{784 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{785     \textcolor{keywordflow}{else}}
\DoxyCodeLine{786       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{787       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{788         eta(i,j) = e(i,j,1)*gv\%Z\_to\_H}
\DoxyCodeLine{789 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{790 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{791 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{792 }
\DoxyCodeLine{793   \textcolor{keywordflow}{if} (cs\%id\_e\_tidal>0) \textcolor{keyword}{call }post\_data(cs\%id\_e\_tidal, e\_tidal, cs\%diag)}
\DoxyCodeLine{794   \textcolor{keywordflow}{if} (cs\%id\_tvar\_sgs>0) \textcolor{keyword}{call }post\_data(cs\%id\_tvar\_sgs, tv\%varT, cs\%diag)}
\DoxyCodeLine{795 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__pressureforce__fv_ae4ced0f46de081e5cbd55134d878e802}\label{namespacemom__pressureforce__fv_ae4ced0f46de081e5cbd55134d878e802}} 
\index{mom\_pressureforce\_fv@{mom\_pressureforce\_fv}!pressureforce\_fv\_end@{pressureforce\_fv\_end}}
\index{pressureforce\_fv\_end@{pressureforce\_fv\_end}!mom\_pressureforce\_fv@{mom\_pressureforce\_fv}}
\subsubsection{\texorpdfstring{pressureforce\_fv\_end()}{pressureforce\_fv\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+pressureforce\+\_\+fv\+::pressureforce\+\_\+fv\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__pressureforce__fv_1_1pressureforce__fv__cs}{pressureforce\+\_\+fv\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocates the finite volume pressure gradient control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & Finite volume pressure control structure that will be deallocated in this subroutine. \\
\hline
\end{DoxyParams}


Definition at line 881 of file M\+O\+M\+\_\+\+Pressure\+Force\+\_\+\+F\+V.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{881   \textcolor{keywordtype}{type}(PressureForce\_FV\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Finite volume pressure control structure that}}
\DoxyCodeLine{882 \textcolor{comment}{                                            !! will be deallocated in this subroutine.}}
\DoxyCodeLine{883   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__pressureforce__fv_a59da32e314b0a8a8feb6e8cd63ef88e0}\label{namespacemom__pressureforce__fv_a59da32e314b0a8a8feb6e8cd63ef88e0}} 
\index{mom\_pressureforce\_fv@{mom\_pressureforce\_fv}!pressureforce\_fv\_init@{pressureforce\_fv\_init}}
\index{pressureforce\_fv\_init@{pressureforce\_fv\_init}!mom\_pressureforce\_fv@{mom\_pressureforce\_fv}}
\subsubsection{\texorpdfstring{pressureforce\_fv\_init()}{pressureforce\_fv\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+pressureforce\+\_\+fv\+::pressureforce\+\_\+fv\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__pressureforce__fv_1_1pressureforce__fv__cs}{pressureforce\+\_\+fv\+\_\+cs}}), pointer}]{CS,  }\item[{type(tidal\+\_\+forcing\+\_\+cs), optional, pointer}]{tides\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



Initializes the finite volume pressure gradient control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & Current model time \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file handles \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics control structure \\
\hline
 & {\em cs} & Finite volume P\+GF control structure \\
\hline
 & {\em tides\+\_\+csp} & Tides control structure \\
\hline
\end{DoxyParams}


Definition at line 800 of file M\+O\+M\+\_\+\+Pressure\+Force\+\_\+\+F\+V.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{800   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},    \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< Current model time}}
\DoxyCodeLine{801   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{802   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{803   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{804   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file handles}}
\DoxyCodeLine{805   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},    \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< Diagnostics control structure}}
\DoxyCodeLine{806   \textcolor{keywordtype}{type}(PressureForce\_FV\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Finite volume PGF control structure}}
\DoxyCodeLine{807   \textcolor{keywordtype}{type}(tidal\_forcing\_CS), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: tides\_CSp\textcolor{comment}{ !< Tides control structure}}
\DoxyCodeLine{808   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{809 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{810 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl  \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{811   \textcolor{keywordtype}{logical} :: use\_ALE}
\DoxyCodeLine{812 }
\DoxyCodeLine{813   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{814     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"PressureForce\_init called with an associated "}// \&}
\DoxyCodeLine{815                             \textcolor{stringliteral}{"control structure."})}
\DoxyCodeLine{816     \textcolor{keywordflow}{return}}
\DoxyCodeLine{817   \textcolor{keywordflow}{else} ; \textcolor{keyword}{allocate}(cs) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{818 }
\DoxyCodeLine{819   cs\%diag => diag ; cs\%Time => time}
\DoxyCodeLine{820   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tides\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{821     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tides\_csp)) cs\%tides\_CSp => tides\_csp}
\DoxyCodeLine{822 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{823 }
\DoxyCodeLine{824   mdl = \textcolor{stringliteral}{"MOM\_PressureForce\_FV"}}
\DoxyCodeLine{825   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{826   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RHO\_0"}, cs\%Rho0, \&}
\DoxyCodeLine{827                  \textcolor{stringliteral}{"The mean ocean density used with BOUSSINESQ true to "}//\&}
\DoxyCodeLine{828                  \textcolor{stringliteral}{"calculate accelerations and the mass for conservation "}//\&}
\DoxyCodeLine{829                  \textcolor{stringliteral}{"properties, or with BOUSSINSEQ false to convert some "}//\&}
\DoxyCodeLine{830                  \textcolor{stringliteral}{"parameters from vertical units of m to kg m-2."}, \&}
\DoxyCodeLine{831                  units=\textcolor{stringliteral}{"kg m-3"}, default=1035.0, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{832   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDES"}, cs\%tides, \&}
\DoxyCodeLine{833                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing."}, default=.false.)}
\DoxyCodeLine{834   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_REGRIDDING"}, use\_ale, \&}
\DoxyCodeLine{835                  \textcolor{stringliteral}{"If True, use the ALE algorithm (regridding/remapping). "}//\&}
\DoxyCodeLine{836                  \textcolor{stringliteral}{"If False, use the layered isopycnal algorithm."}, default=.false. )}
\DoxyCodeLine{837   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MASS\_WEIGHT\_IN\_PRESSURE\_GRADIENT"}, cs\%useMassWghtInterp, \&}
\DoxyCodeLine{838                  \textcolor{stringliteral}{"If true, use mass weighting when interpolating T/S for "}//\&}
\DoxyCodeLine{839                  \textcolor{stringliteral}{"integrals near the bathymetry in FV pressure gradient "}//\&}
\DoxyCodeLine{840                  \textcolor{stringliteral}{"calculations."}, default=.false.)}
\DoxyCodeLine{841   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RECONSTRUCT\_FOR\_PRESSURE"}, cs\%reconstruct, \&}
\DoxyCodeLine{842                  \textcolor{stringliteral}{"If True, use vertical reconstruction of T \& S within "}//\&}
\DoxyCodeLine{843                  \textcolor{stringliteral}{"the integrals of the FV pressure gradient calculation. "}//\&}
\DoxyCodeLine{844                  \textcolor{stringliteral}{"If False, use the constant-by-layer algorithm. "}//\&}
\DoxyCodeLine{845                  \textcolor{stringliteral}{"The default is set by USE\_REGRIDDING."}, \&}
\DoxyCodeLine{846                  default=use\_ale )}
\DoxyCodeLine{847   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRESSURE\_RECONSTRUCTION\_SCHEME"}, cs\%Recon\_Scheme, \&}
\DoxyCodeLine{848                  \textcolor{stringliteral}{"Order of vertical reconstruction of T/S to use in the "}//\&}
\DoxyCodeLine{849                  \textcolor{stringliteral}{"integrals within the FV pressure gradient calculation.\(\backslash\)n"}//\&}
\DoxyCodeLine{850                  \textcolor{stringliteral}{" 0: PCM or no reconstruction.\(\backslash\)n"}//\&}
\DoxyCodeLine{851                  \textcolor{stringliteral}{" 1: PLM reconstruction.\(\backslash\)n"}//\&}
\DoxyCodeLine{852                  \textcolor{stringliteral}{" 2: PPM reconstruction."}, default=1)}
\DoxyCodeLine{853   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BOUNDARY\_EXTRAPOLATION\_PRESSURE"}, cs\%boundary\_extrap, \&}
\DoxyCodeLine{854                  \textcolor{stringliteral}{"If true, the reconstruction of T \& S for pressure in "}//\&}
\DoxyCodeLine{855                  \textcolor{stringliteral}{"boundary cells is extrapolated, rather than using PCM "}//\&}
\DoxyCodeLine{856                  \textcolor{stringliteral}{"in these cells. If true, the same order polynomial is "}//\&}
\DoxyCodeLine{857                  \textcolor{stringliteral}{"used as is used for the interior cells."}, default=.true.)}
\DoxyCodeLine{858   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PGF\_STANLEY\_T2\_DET\_COEFF"}, cs\%Stanley\_T2\_det\_coeff, \&}
\DoxyCodeLine{859                  \textcolor{stringliteral}{"The coefficient correlating SGS temperature variance with "}// \&}
\DoxyCodeLine{860                  \textcolor{stringliteral}{"the mean temperature gradient in the deterministic part of "}// \&}
\DoxyCodeLine{861                  \textcolor{stringliteral}{"the Stanley form of the Brankart correction. "}// \&}
\DoxyCodeLine{862                  \textcolor{stringliteral}{"Negative values disable the scheme."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)}
\DoxyCodeLine{863   \textcolor{keywordflow}{if} (cs\%Stanley\_T2\_det\_coeff>=0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{864     cs\%id\_tvar\_sgs = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'tvar\_sgs\_pgf'}, diag\%axesTL, \&}
\DoxyCodeLine{865         time, \textcolor{stringliteral}{'SGS temperature variance used in PGF'}, \textcolor{stringliteral}{'degC2'})}
\DoxyCodeLine{866 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{867   \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{868     cs\%id\_e\_tidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'e\_tidal'}, diag\%axesT1, \&}
\DoxyCodeLine{869         time, \textcolor{stringliteral}{'Tidal Forcing Astronomical and SAL Height Anomaly'}, \textcolor{stringliteral}{'meter'}, conversion=us\%Z\_to\_m)}
\DoxyCodeLine{870 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{871 }
\DoxyCodeLine{872   cs\%GFS\_scale = 1.0}
\DoxyCodeLine{873   \textcolor{keywordflow}{if} (gv\%g\_prime(1) /= gv\%g\_Earth) cs\%GFS\_scale = gv\%g\_prime(1) / gv\%g\_Earth}
\DoxyCodeLine{874 }
\DoxyCodeLine{875   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"GFS / G\_EARTH"}, cs\%GFS\_scale)}
\DoxyCodeLine{876 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__pressureforce__fv_a50c4a61827e473e643f3f330adf62872}\label{namespacemom__pressureforce__fv_a50c4a61827e473e643f3f330adf62872}} 
\index{mom\_pressureforce\_fv@{mom\_pressureforce\_fv}!pressureforce\_fv\_nonbouss@{pressureforce\_fv\_nonbouss}}
\index{pressureforce\_fv\_nonbouss@{pressureforce\_fv\_nonbouss}!mom\_pressureforce\_fv@{mom\_pressureforce\_fv}}
\subsubsection{\texorpdfstring{pressureforce\_fv\_nonbouss()}{pressureforce\_fv\_nonbouss()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+pressureforce\+\_\+fv\+::pressureforce\+\_\+fv\+\_\+nonbouss (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{P\+Fu,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out)}]{P\+Fv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__pressureforce__fv_1_1pressureforce__fv__cs}{pressureforce\+\_\+fv\+\_\+cs}}), pointer}]{CS,  }\item[{type(ale\+\_\+cs), pointer}]{A\+L\+E\+\_\+\+C\+Sp,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{p\+\_\+atm,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{pbce,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out), optional}]{eta }\end{DoxyParamCaption})}



Non-\/\+Boussinesq analytically-\/integrated finite volume form of pressure gradient. 

Determines the acceleration due to hydrostatic pressure forces, using the analytic finite volume form of the Pressure gradient, and does not make the Boussinesq approximation.

To work, the following fields must be set outside of the usual (is\+:ie,js\+:je) range before this subroutine is called\+: h(isB\+:ie+1,jsB\+:je+1), T(isB\+:ie+1,jsB\+:je+1), and S(isB\+:ie+1,jsB\+:je+1). 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ kg/m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables \\
\hline
\mbox{\texttt{ out}}  & {\em pfu} & Zonal acceleration \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em pfv} & Meridional acceleration \mbox{[}L T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
 & {\em cs} & Finite volume P\+GF control structure \\
\hline
 & {\em ale\+\_\+csp} & A\+LE control structure \\
\hline
 & {\em p\+\_\+atm} & The pressure at the ice-\/ocean or atmosphere-\/ocean interface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em pbce} & The baroclinic pressure anomaly in each layer due to eta anomalies \mbox{[}L2 T-\/2 H-\/1 $\sim$$>$ m s-\/2 or m4 s-\/2 kg-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em eta} & The bottom mass used to calculate P\+Fu and P\+Fv \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}, with any tidal contributions or compressibility compensation. \\
\hline
\end{DoxyParams}


Definition at line 77 of file M\+O\+M\+\_\+\+Pressure\+Force\+\_\+\+F\+V.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{77   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{   !< Ocean grid structure}}
\DoxyCodeLine{78   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{  !< Vertical grid structure}}
\DoxyCodeLine{79   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{   !< Layer thickness [H ~> kg/m2]}}
\DoxyCodeLine{81   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}  :: tv\textcolor{comment}{  !< Thermodynamic variables}}
\DoxyCodeLine{82 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: PFu\textcolor{comment}{ !< Zonal acceleration [L T-2 ~> m s-2]}}
\DoxyCodeLine{83 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: PFv\textcolor{comment}{ !< Meridional acceleration [L T-2 ~> m s-2]}}
\DoxyCodeLine{84   \textcolor{keywordtype}{type}(PressureForce\_FV\_CS),                 \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{  !< Finite volume PGF control structure}}
\DoxyCodeLine{85   \textcolor{keywordtype}{type}(ALE\_CS),                              \textcolor{keywordtype}{pointer}     :: ALE\_CSp\textcolor{comment}{ !< ALE control structure}}
\DoxyCodeLine{86 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: p\_atm\textcolor{comment}{ !< The pressure at the ice-ocean}}
\DoxyCodeLine{87 \textcolor{comment}{                                                           !! or atmosphere-ocean interface [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{88 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: pbce\textcolor{comment}{ !< The baroclinic pressure}}
\DoxyCodeLine{89 \textcolor{comment}{                                                           !! anomaly in each layer due to eta anomalies}}
\DoxyCodeLine{90 \textcolor{comment}{                                                           !! [L2 T-2 H-1 ~> m s-2 or m4 s-2 kg-1].}}
\DoxyCodeLine{91 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: eta\textcolor{comment}{ !< The bottom mass used to}}
\DoxyCodeLine{92 \textcolor{comment}{                                                           !! calculate PFu and PFv [H ~> m or kg m-2], with any tidal}}
\DoxyCodeLine{93 \textcolor{comment}{                                                           !! contributions or compressibility compensation.}}
\DoxyCodeLine{94   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{95 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)} :: p \textcolor{comment}{! Interface pressure [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{96 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{target} :: \&}
\DoxyCodeLine{97     T\_tmp, \&    \textcolor{comment}{! Temporary array of temperatures where layers that are lighter}}
\DoxyCodeLine{98                 \textcolor{comment}{! than the mixed layer have the mixed layer's properties [degC].}}
\DoxyCodeLine{99     s\_tmp       \textcolor{comment}{! Temporary array of salinities where layers that are lighter}}
\DoxyCodeLine{100                 \textcolor{comment}{! than the mixed layer have the mixed layer's properties [ppt].}}
\DoxyCodeLine{101 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{102     S\_t, \&      \textcolor{comment}{! Top and bottom edge values for linear reconstructions}}
\DoxyCodeLine{103     S\_b, \&      \textcolor{comment}{! of salinity within each layer [ppt].}}
\DoxyCodeLine{104     T\_t, \&      \textcolor{comment}{! Top and bottom edge values for linear reconstructions}}
\DoxyCodeLine{105     T\_b         \textcolor{comment}{! of temperature within each layer [degC].}}
\DoxyCodeLine{106 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}  :: \&}
\DoxyCodeLine{107     dza, \&      \textcolor{comment}{! The change in geopotential anomaly between the top and bottom}}
\DoxyCodeLine{108                 \textcolor{comment}{! of a layer [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{109     intp\_dza    \textcolor{comment}{! The vertical integral in depth of the pressure anomaly less}}
\DoxyCodeLine{110                 \textcolor{comment}{! the pressure anomaly at the top of the layer [R L4 Z-4 ~> Pa m2 s-2].}}
\DoxyCodeLine{111 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: \&}
\DoxyCodeLine{112     dp, \&       \textcolor{comment}{! The (positive) change in pressure across a layer [R L2 Z-2 ~> Pa].}}
\DoxyCodeLine{113     SSH, \&      \textcolor{comment}{! The sea surface height anomaly, in depth units [Z ~> m].}}
\DoxyCodeLine{114     e\_tidal, \&  \textcolor{comment}{! The bottom geopotential anomaly due to tidal forces from}}
\DoxyCodeLine{115                 \textcolor{comment}{! astronomical sources and self-attraction and loading [Z ~> m].}}
\DoxyCodeLine{116     dm, \&       \textcolor{comment}{! The barotropic adjustment to the Montgomery potential to}}
\DoxyCodeLine{117                 \textcolor{comment}{! account for a reduced gravity model [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{118     za          \textcolor{comment}{! The geopotential anomaly (i.e. g*e + alpha\_0*pressure) at the}}
\DoxyCodeLine{119                 \textcolor{comment}{! interface atop a layer [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{120 }
\DoxyCodeLine{121 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: Rho\_cv\_BL \textcolor{comment}{!  The coordinate potential density in the deepest variable}}
\DoxyCodeLine{122                 \textcolor{comment}{! density near-surface layer [R ~> kg m-3].}}
\DoxyCodeLine{123 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{124     intx\_za     \textcolor{comment}{! The zonal integral of the geopotential anomaly along the}}
\DoxyCodeLine{125                 \textcolor{comment}{! interface below a layer, divided by the grid spacing [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{126 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{127     intx\_dza    \textcolor{comment}{! The change in intx\_za through a layer [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{128 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{129     inty\_za     \textcolor{comment}{! The meridional integral of the geopotential anomaly along the}}
\DoxyCodeLine{130                 \textcolor{comment}{! interface below a layer, divided by the grid spacing [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{131 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{132     inty\_dza    \textcolor{comment}{! The change in inty\_za through a layer [L2 T-2 ~> m2 s-2].}}
\DoxyCodeLine{133 \textcolor{keywordtype}{  real} :: p\_ref(SZI\_(G))     \textcolor{comment}{!   The pressure used to calculate the coordinate}}
\DoxyCodeLine{134                              \textcolor{comment}{! density, [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).}}
\DoxyCodeLine{135 }
\DoxyCodeLine{136 \textcolor{keywordtype}{  real} :: dp\_neglect         \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{137                              \textcolor{comment}{! in roundoff and can be neglected [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{138 \textcolor{keywordtype}{  real} :: I\_gEarth           \textcolor{comment}{! The inverse of GV\%g\_Earth [L2 Z L-2 ~> s2 m-1]}}
\DoxyCodeLine{139 \textcolor{keywordtype}{  real} :: alpha\_anom         \textcolor{comment}{! The in-situ specific volume, averaged over a}}
\DoxyCodeLine{140                              \textcolor{comment}{! layer, less alpha\_ref [R-1 ~> m3 kg-1].}}
\DoxyCodeLine{141   \textcolor{keywordtype}{logical} :: use\_p\_atm       \textcolor{comment}{! If true, use the atmospheric pressure.}}
\DoxyCodeLine{142   \textcolor{keywordtype}{logical} :: use\_ALE         \textcolor{comment}{! If true, use an ALE pressure reconstruction.}}
\DoxyCodeLine{143   \textcolor{keywordtype}{logical} :: use\_EOS         \textcolor{comment}{! If true, density is calculated from T \& S using an equation of state.}}
\DoxyCodeLine{144   \textcolor{keywordtype}{type}(thermo\_var\_ptrs) :: tv\_tmp\textcolor{comment}{! A structure of temporary T \& S.}}
\DoxyCodeLine{145 }
\DoxyCodeLine{146 \textcolor{keywordtype}{  real} :: alpha\_ref     \textcolor{comment}{! A reference specific volume [R-1 ~> m3 kg-1] that is used}}
\DoxyCodeLine{147                         \textcolor{comment}{! to reduce the impact of truncation errors.}}
\DoxyCodeLine{148 \textcolor{keywordtype}{  real} :: rho\_in\_situ(SZI\_(G)) \textcolor{comment}{! The in situ density [R ~> kg m-3].}}
\DoxyCodeLine{149 \textcolor{keywordtype}{  real} :: Pa\_to\_H       \textcolor{comment}{! A factor to convert from Pa to the thicknesss units (H) [H T2 R-1 L-2 ~> H Pa-1].}}
\DoxyCodeLine{150 \textcolor{keywordtype}{  real} :: H\_to\_RL2\_T2   \textcolor{comment}{! A factor to convert from thicknesss units (H) to pressure units [R L2 T-2 H-1 ~> Pa H-1].}}
\DoxyCodeLine{151 \textcolor{comment}{!  real :: oneatm = 101325.0  ! 1 atm in [Pa] = [kg m-1 s-2]}}
\DoxyCodeLine{152 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_6 = 1.0/6.0}
\DoxyCodeLine{153   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, nkmb}
\DoxyCodeLine{154   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-computational domain for the equation of state}}
\DoxyCodeLine{155   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{156 }
\DoxyCodeLine{157   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{158   nkmb=gv\%nk\_rho\_varies}
\DoxyCodeLine{159   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{160   eosdom(1) = isq - (g\%isd-1) ;  eosdom(2) = g\%iec+1 - (g\%isd-1)}
\DoxyCodeLine{161 }
\DoxyCodeLine{162   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{163        \textcolor{stringliteral}{"MOM\_PressureForce\_FV\_nonBouss: Module must be initialized before it is used."})}
\DoxyCodeLine{164   \textcolor{keywordflow}{if} (cs\%Stanley\_T2\_det\_coeff>=0.) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{165        \textcolor{stringliteral}{"MOM\_PressureForce\_FV\_nonBouss: The Stanley parameterization is not yet"}//\&}
\DoxyCodeLine{166        \textcolor{stringliteral}{"implemented in non-Boussinesq mode."})}
\DoxyCodeLine{167 }
\DoxyCodeLine{168   use\_p\_atm = .false.}
\DoxyCodeLine{169   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(p\_atm)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_atm)) use\_p\_atm = .true. ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{170   use\_eos = \textcolor{keyword}{associated}(tv\%eqn\_of\_state)}
\DoxyCodeLine{171   use\_ale = .false.}
\DoxyCodeLine{172   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(ale\_csp)) use\_ale = cs\%reconstruct .and. use\_eos}
\DoxyCodeLine{173 }
\DoxyCodeLine{174   h\_to\_rl2\_t2 = gv\%g\_Earth*gv\%H\_to\_RZ}
\DoxyCodeLine{175   dp\_neglect = gv\%g\_Earth*gv\%H\_to\_RZ * gv\%H\_subroundoff}
\DoxyCodeLine{176   alpha\_ref = 1.0 / cs\%Rho0}
\DoxyCodeLine{177   i\_gearth = 1.0 / gv\%g\_Earth}
\DoxyCodeLine{178 }
\DoxyCodeLine{179   \textcolor{keywordflow}{if} (use\_p\_atm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{180     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{181     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{182       p(i,j,1) = p\_atm(i,j)}
\DoxyCodeLine{183 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{184   \textcolor{keywordflow}{else}}
\DoxyCodeLine{185     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{186     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{187       p(i,j,1) = 0.0 \textcolor{comment}{! or oneatm}}
\DoxyCodeLine{188 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{189 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{190   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{191   \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} k=2,nz+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{192     p(i,j,k) = p(i,j,k-1) + h\_to\_rl2\_t2 * h(i,j,k-1)}
\DoxyCodeLine{193 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{194 }
\DoxyCodeLine{195   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{196   \textcolor{comment}{!   With a bulk mixed layer, replace the T \& S of any layers that are}}
\DoxyCodeLine{197   \textcolor{comment}{! lighter than the the buffer layer with the properties of the buffer}}
\DoxyCodeLine{198   \textcolor{comment}{! layer.  These layers will be massless anyway, and it avoids any}}
\DoxyCodeLine{199   \textcolor{comment}{! formal calculations with hydrostatically unstable profiles.}}
\DoxyCodeLine{200     \textcolor{keywordflow}{if} (nkmb>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{201       tv\_tmp\%T => t\_tmp ; tv\_tmp\%S => s\_tmp}
\DoxyCodeLine{202       tv\_tmp\%eqn\_of\_state => tv\%eqn\_of\_state}
\DoxyCodeLine{203       \textcolor{keywordflow}{do} i=isq,ieq+1 ; p\_ref(i) = tv\%P\_Ref ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{204       \textcolor{comment}{!\$OMP parallel do default(shared) private(Rho\_cv\_BL)}}
\DoxyCodeLine{205       \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{206         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{207           tv\_tmp\%T(i,j,k) = tv\%T(i,j,k) ; tv\_tmp\%S(i,j,k) = tv\%S(i,j,k)}
\DoxyCodeLine{208 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{209         \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,nkmb), tv\%S(:,j,nkmb), p\_ref, rho\_cv\_bl(:), \&}
\DoxyCodeLine{210                                tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{211         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{212           \textcolor{keywordflow}{if} (gv\%Rlay(k) < rho\_cv\_bl(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{213             tv\_tmp\%T(i,j,k) = tv\%T(i,j,nkmb) ; tv\_tmp\%S(i,j,k) = tv\%S(i,j,nkmb)}
\DoxyCodeLine{214           \textcolor{keywordflow}{else}}
\DoxyCodeLine{215             tv\_tmp\%T(i,j,k) = tv\%T(i,j,k) ; tv\_tmp\%S(i,j,k) = tv\%S(i,j,k)}
\DoxyCodeLine{216 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{217 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{218 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{219     \textcolor{keywordflow}{else}}
\DoxyCodeLine{220       tv\_tmp\%T => tv\%T ; tv\_tmp\%S => tv\%S}
\DoxyCodeLine{221       tv\_tmp\%eqn\_of\_state => tv\%eqn\_of\_state}
\DoxyCodeLine{222 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{223 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{224 }
\DoxyCodeLine{225   \textcolor{comment}{! If regridding is activated, do a linear reconstruction of salinity}}
\DoxyCodeLine{226   \textcolor{comment}{! and temperature across each layer. The subscripts 't' and 'b' refer}}
\DoxyCodeLine{227   \textcolor{comment}{! to top and bottom values within each layer (these are the only degrees}}
\DoxyCodeLine{228   \textcolor{comment}{! of freedeom needed to know the linear profile).}}
\DoxyCodeLine{229   \textcolor{keywordflow}{if} ( use\_ale ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{230     \textcolor{keywordflow}{if} ( cs\%Recon\_Scheme == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{231       \textcolor{keyword}{call }ts\_plm\_edge\_values(ale\_csp, s\_t, s\_b, t\_t, t\_b, g, gv, tv, h, cs\%boundary\_extrap)}
\DoxyCodeLine{232     \textcolor{keywordflow}{elseif} ( cs\%Recon\_Scheme == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{233       \textcolor{keyword}{call }ts\_ppm\_edge\_values(ale\_csp, s\_t, s\_b, t\_t, t\_b, g, gv, tv, h, cs\%boundary\_extrap)}
\DoxyCodeLine{234 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{235 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{236 }
\DoxyCodeLine{237   \textcolor{comment}{!\$OMP parallel do default(shared) private(alpha\_anom,dp)}}
\DoxyCodeLine{238   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{239     \textcolor{comment}{! Calculate 4 integrals through the layer that are required in the}}
\DoxyCodeLine{240     \textcolor{comment}{! subsequent calculation.}}
\DoxyCodeLine{241     \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{242       \textcolor{keywordflow}{if} ( use\_ale ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{243         \textcolor{keywordflow}{if} ( cs\%Recon\_Scheme == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{244           \textcolor{keyword}{call }int\_spec\_vol\_dp\_generic\_plm( t\_t(:,:,k), t\_b(:,:,k), s\_t(:,:,k), s\_b(:,:,k), \&}
\DoxyCodeLine{245                     p(:,:,k), p(:,:,k+1), alpha\_ref, dp\_neglect, p(:,:,nz+1), g\%HI, \&}
\DoxyCodeLine{246                     tv\%eqn\_of\_state, us, dza(:,:,k), intp\_dza(:,:,k), intx\_dza(:,:,k), inty\_dza(:,:,k), \&}
\DoxyCodeLine{247                     usemasswghtinterp=cs\%useMassWghtInterp)}
\DoxyCodeLine{248         \textcolor{keywordflow}{elseif} ( cs\%Recon\_Scheme == 2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{249           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"PressureForce\_FV\_nonBouss: "}//\&}
\DoxyCodeLine{250                          \textcolor{stringliteral}{"int\_spec\_vol\_dp\_generic\_ppm does not exist yet."})}
\DoxyCodeLine{251         \textcolor{comment}{!  call int\_spec\_vol\_dp\_generic\_ppm ( tv\%T(:,:,k), T\_t(:,:,k), T\_b(:,:,k), \&}}
\DoxyCodeLine{252         \textcolor{comment}{!            tv\%S(:,:,k), S\_t(:,:,k), S\_b(:,:,k), p(:,:,K), p(:,:,K+1), \&}}
\DoxyCodeLine{253         \textcolor{comment}{!            alpha\_ref, G\%HI, tv\%eqn\_of\_state, dza(:,:,k), intp\_dza(:,:,k), \&}}
\DoxyCodeLine{254         \textcolor{comment}{!            intx\_dza(:,:,k), inty\_dza(:,:,k))}}
\DoxyCodeLine{255 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{256       \textcolor{keywordflow}{else}}
\DoxyCodeLine{257         \textcolor{keyword}{call }int\_specific\_vol\_dp(tv\_tmp\%T(:,:,k), tv\_tmp\%S(:,:,k), p(:,:,k), \&}
\DoxyCodeLine{258                                p(:,:,k+1), alpha\_ref, g\%HI, tv\%eqn\_of\_state, \&}
\DoxyCodeLine{259                                us, dza(:,:,k), intp\_dza(:,:,k), intx\_dza(:,:,k), \&}
\DoxyCodeLine{260                                inty\_dza(:,:,k), bathyp=p(:,:,nz+1), dp\_tiny=dp\_neglect, \&}
\DoxyCodeLine{261                                usemasswghtinterp=cs\%useMassWghtInterp)}
\DoxyCodeLine{262 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{263     \textcolor{keywordflow}{else}}
\DoxyCodeLine{264       alpha\_anom = 1.0 / gv\%Rlay(k) - alpha\_ref}
\DoxyCodeLine{265       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{266         dp(i,j) = h\_to\_rl2\_t2 * h(i,j,k)}
\DoxyCodeLine{267         dza(i,j,k) = alpha\_anom * dp(i,j)}
\DoxyCodeLine{268         intp\_dza(i,j,k) = 0.5 * alpha\_anom * dp(i,j)**2}
\DoxyCodeLine{269 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{270       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{271         intx\_dza(i,j,k) = 0.5 * alpha\_anom * (dp(i,j)+dp(i+1,j))}
\DoxyCodeLine{272 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{273       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{274         inty\_dza(i,j,k) = 0.5 * alpha\_anom * (dp(i,j)+dp(i,j+1))}
\DoxyCodeLine{275 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{276 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{277 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{278 }
\DoxyCodeLine{279   \textcolor{comment}{!   The bottom geopotential anomaly is calculated first so that the increments}}
\DoxyCodeLine{280   \textcolor{comment}{! to the geopotential anomalies can be reused.  Alternately, the surface}}
\DoxyCodeLine{281   \textcolor{comment}{! geopotential could be calculated directly with separate calls to}}
\DoxyCodeLine{282   \textcolor{comment}{! int\_specific\_vol\_dp with alpha\_ref=0, and the anomalies used going}}
\DoxyCodeLine{283   \textcolor{comment}{! downward, which would relieve the need for dza, intp\_dza, intx\_dza, and}}
\DoxyCodeLine{284   \textcolor{comment}{! inty\_dza to be 3-D arrays.}}
\DoxyCodeLine{285 }
\DoxyCodeLine{286   \textcolor{comment}{! Sum vertically to determine the surface geopotential anomaly.}}
\DoxyCodeLine{287   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{288   \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{289     \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{290       za(i,j) = alpha\_ref*p(i,j,nz+1) - gv\%g\_Earth*g\%bathyT(i,j)}
\DoxyCodeLine{291 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{292     \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{293       za(i,j) = za(i,j) + dza(i,j,k)}
\DoxyCodeLine{294 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{295 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{296 }
\DoxyCodeLine{297   \textcolor{keywordflow}{if} (cs\%tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{298     \textcolor{comment}{! Find and add the tidal geopotential anomaly.}}
\DoxyCodeLine{299     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{300     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{301       ssh(i,j) = (za(i,j) - alpha\_ref*p(i,j,1)) * i\_gearth}
\DoxyCodeLine{302 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{303     \textcolor{keyword}{call }calc\_tidal\_forcing(cs\%Time, ssh, e\_tidal, g, cs\%tides\_CSp, m\_to\_z=us\%m\_to\_Z)}
\DoxyCodeLine{304     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{305     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{306       za(i,j) = za(i,j) - gv\%g\_Earth * e\_tidal(i,j)}
\DoxyCodeLine{307 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{308 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{309 }
\DoxyCodeLine{310   \textcolor{keywordflow}{if} (cs\%GFS\_scale < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{311     \textcolor{comment}{! Adjust the Montgomery potential to make this a reduced gravity model.}}
\DoxyCodeLine{312     \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{313       \textcolor{comment}{!\$OMP parallel do default(shared) private(rho\_in\_situ)}}
\DoxyCodeLine{314       \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{315         \textcolor{keyword}{call }calculate\_density(tv\_tmp\%T(:,j,1), tv\_tmp\%S(:,j,1), p(:,j,1), rho\_in\_situ, \&}
\DoxyCodeLine{316                                tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{317 }
\DoxyCodeLine{318         \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{319           dm(i,j) = (cs\%GFS\_scale - 1.0) * (p(i,j,1)*(1.0/rho\_in\_situ(i) - alpha\_ref) + za(i,j))}
\DoxyCodeLine{320 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{321 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{322     \textcolor{keywordflow}{else}}
\DoxyCodeLine{323       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{324       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{325         dm(i,j) = (cs\%GFS\_scale - 1.0) * (p(i,j,1)*(1.0/gv\%Rlay(1) - alpha\_ref) + za(i,j))}
\DoxyCodeLine{326 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{327 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{328 \textcolor{comment}{!  else}}
\DoxyCodeLine{329 \textcolor{comment}{!    do j=Jsq,Jeq+1 ; do i=Isq,Ieq+1 ; dM(i,j) = 0.0 ; enddo ; enddo}}
\DoxyCodeLine{330 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{331 }
\DoxyCodeLine{332   \textcolor{comment}{!   This order of integrating upward and then downward again is necessary with}}
\DoxyCodeLine{333   \textcolor{comment}{! a nonlinear equation of state, so that the surface geopotentials will go}}
\DoxyCodeLine{334   \textcolor{comment}{! linearly between the values at thickness points, but the bottom}}
\DoxyCodeLine{335   \textcolor{comment}{! geopotentials will not now be linear at the sub-grid-scale.  Doing this}}
\DoxyCodeLine{336   \textcolor{comment}{! ensures no motion with flat isopycnals, even with a nonlinear equation of state.}}
\DoxyCodeLine{337   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{338   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{339     intx\_za(i,j) = 0.5*(za(i,j) + za(i+1,j))}
\DoxyCodeLine{340 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{341   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{342   \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{343     inty\_za(i,j) = 0.5*(za(i,j) + za(i,j+1))}
\DoxyCodeLine{344 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{345   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{346     \textcolor{comment}{! These expressions for the acceleration have been carefully checked in}}
\DoxyCodeLine{347     \textcolor{comment}{! a set of idealized cases, and should be bug-free.}}
\DoxyCodeLine{348     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{349     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{350       dp(i,j) = h\_to\_rl2\_t2 * h(i,j,k)}
\DoxyCodeLine{351       za(i,j) = za(i,j) - dza(i,j,k)}
\DoxyCodeLine{352 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{353     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{354     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{355       intx\_za(i,j) = intx\_za(i,j) - intx\_dza(i,j,k)}
\DoxyCodeLine{356       pfu(i,j,k) = ( ((za(i,j)*dp(i,j) + intp\_dza(i,j,k)) - \&}
\DoxyCodeLine{357                       (za(i+1,j)*dp(i+1,j) + intp\_dza(i+1,j,k))) + \&}
\DoxyCodeLine{358                      ((dp(i+1,j) - dp(i,j)) * intx\_za(i,j) - \&}
\DoxyCodeLine{359                       (p(i+1,j,k) - p(i,j,k)) * intx\_dza(i,j,k)) ) * \&}
\DoxyCodeLine{360                    (2.0*g\%IdxCu(i,j) / ((dp(i,j) + dp(i+1,j)) + dp\_neglect))}
\DoxyCodeLine{361 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{362     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{363     \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{364       inty\_za(i,j) = inty\_za(i,j) - inty\_dza(i,j,k)}
\DoxyCodeLine{365       pfv(i,j,k) = (((za(i,j)*dp(i,j) + intp\_dza(i,j,k)) - \&}
\DoxyCodeLine{366                      (za(i,j+1)*dp(i,j+1) + intp\_dza(i,j+1,k))) + \&}
\DoxyCodeLine{367                     ((dp(i,j+1) - dp(i,j)) * inty\_za(i,j) - \&}
\DoxyCodeLine{368                      (p(i,j+1,k) - p(i,j,k)) * inty\_dza(i,j,k))) * \&}
\DoxyCodeLine{369                     (2.0*g\%IdyCv(i,j) / ((dp(i,j) + dp(i,j+1)) + dp\_neglect))}
\DoxyCodeLine{370 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{371 }
\DoxyCodeLine{372     \textcolor{keywordflow}{if} (cs\%GFS\_scale < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{373       \textcolor{comment}{! Adjust the Montgomery potential to make this a reduced gravity model.}}
\DoxyCodeLine{374       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{375       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{376         pfu(i,j,k) = pfu(i,j,k) - (dm(i+1,j) - dm(i,j)) * g\%IdxCu(i,j)}
\DoxyCodeLine{377 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{378       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{379       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{380         pfv(i,j,k) = pfv(i,j,k) - (dm(i,j+1) - dm(i,j)) * g\%IdyCv(i,j)}
\DoxyCodeLine{381 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{382 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{383 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{384 }
\DoxyCodeLine{385   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(pbce)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{386     \textcolor{keyword}{call }set\_pbce\_nonbouss(p, tv\_tmp, g, gv, us, cs\%GFS\_scale, pbce)}
\DoxyCodeLine{387 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{388 }
\DoxyCodeLine{389   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(eta)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{390     pa\_to\_h = 1.0 / (gv\%g\_Earth * gv\%H\_to\_RZ)}
\DoxyCodeLine{391     \textcolor{keywordflow}{if} (use\_p\_atm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{392       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{393       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{394         eta(i,j) = (p(i,j,nz+1) - p\_atm(i,j))*pa\_to\_h \textcolor{comment}{! eta has the same units as h.}}
\DoxyCodeLine{395 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{396     \textcolor{keywordflow}{else}}
\DoxyCodeLine{397       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{398       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{399         eta(i,j) = p(i,j,nz+1)*pa\_to\_h \textcolor{comment}{! eta has the same units as h.}}
\DoxyCodeLine{400 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{401 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{402 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{403 }
\DoxyCodeLine{404   \textcolor{keywordflow}{if} (cs\%id\_e\_tidal>0) \textcolor{keyword}{call }post\_data(cs\%id\_e\_tidal, e\_tidal, cs\%diag)}
\DoxyCodeLine{405 }

\end{DoxyCode}
