\hypertarget{namespacemom__density__integrals}{}\doxysection{mom\+\_\+density\+\_\+integrals Module Reference}
\label{namespacemom__density__integrals}\index{mom\_density\_integrals@{mom\_density\_integrals}}


\doxysubsection{Detailed Description}
Provides integrals of density. \doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_ac36ae5f4af2d02df0a1adf41b762e017}{int\+\_\+density\+\_\+dz}} (T, S, z\+\_\+t, z\+\_\+b, rho\+\_\+ref, rho\+\_\+0, G\+\_\+e, HI, E\+OS, US, dpa, intz\+\_\+dpa, intx\+\_\+dpa, inty\+\_\+dpa, bathyT, dz\+\_\+neglect, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate analytical and nearly-\/analytical integrals in z across layers of pressure anomalies, which are required for calculating the finite-\/volume form pressure accelerations in a Boussinesq model. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_ad0ff54518bfacf7beebbe4dba687a914}{int\+\_\+density\+\_\+dz\+\_\+generic\+\_\+pcm}} (T, S, z\+\_\+t, z\+\_\+b, rho\+\_\+ref, rho\+\_\+0, G\+\_\+e, HI, E\+OS, US, dpa, intz\+\_\+dpa, intx\+\_\+dpa, inty\+\_\+dpa, bathyT, dz\+\_\+neglect, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em Calculates (by numerical quadrature) integrals of pressure anomalies across layers, which are required for calculating the finite-\/volume form pressure accelerations in a Boussinesq model. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_a454d4d62eb599716cc3389fb8aa90b4b}{int\+\_\+density\+\_\+dz\+\_\+generic\+\_\+plm}} (k, tv, T\+\_\+t, T\+\_\+b, S\+\_\+t, S\+\_\+b, e, rho\+\_\+ref, rho\+\_\+0, G\+\_\+e, dz\+\_\+subroundoff, bathyT, HI, GV, E\+OS, US, dpa, intz\+\_\+dpa, intx\+\_\+dpa, inty\+\_\+dpa, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em Compute pressure gradient force integrals by quadrature for the case where T and S are linear profiles. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_a3bf090e5cbb58811b3dd0ee4de80f999}{int\+\_\+density\+\_\+dz\+\_\+generic\+\_\+ppm}} (k, tv, T\+\_\+t, T\+\_\+b, S\+\_\+t, S\+\_\+b, e, rho\+\_\+ref, rho\+\_\+0, G\+\_\+e, dz\+\_\+subroundoff, bathyT, HI, GV, E\+OS, US, dpa, intz\+\_\+dpa, intx\+\_\+dpa, inty\+\_\+dpa, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em Compute pressure gradient force integrals for layer \char`\"{}k\char`\"{} and the case where T and S are parabolic profiles. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_a759c2ae7aec17c59d532050f68a1e518}{int\+\_\+specific\+\_\+vol\+\_\+dp}} (T, S, p\+\_\+t, p\+\_\+b, alpha\+\_\+ref, HI, E\+OS, US, dza, intp\+\_\+dza, intx\+\_\+dza, inty\+\_\+dza, halo\+\_\+size, bathyP, d\+P\+\_\+tiny, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate analytical and nearly-\/analytical integrals in pressure across layers of geopotential anomalies, which are required for calculating the finite-\/volume form pressure accelerations in a non-\/\+Boussinesq model. There are essentially no free assumptions, apart from the use of Boole\textquotesingle{}s rule to do the horizontal integrals, and from a truncation in the series for log(1-\/eps/1+eps) that assumes that $\vert$eps$\vert$ $<$ 0.\+34. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_a86ebdfebaaea2ac0339dcabed482dd11}{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+generic\+\_\+pcm}} (T, S, p\+\_\+t, p\+\_\+b, alpha\+\_\+ref, HI, E\+OS, US, dza, intp\+\_\+dza, intx\+\_\+dza, inty\+\_\+dza, halo\+\_\+size, bathyP, d\+P\+\_\+neglect, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em This subroutine calculates integrals of specific volume anomalies in pressure across layers, which are required for calculating the finite-\/volume form pressure accelerations in a non-\/\+Boussinesq model. There are essentially no free assumptions, apart from the use of Boole\textquotesingle{}s rule quadrature to do the integrals. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_a71a518f80b5f2ecf83fd9c638cad140d}{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+generic\+\_\+plm}} (T\+\_\+t, T\+\_\+b, S\+\_\+t, S\+\_\+b, p\+\_\+t, p\+\_\+b, alpha\+\_\+ref, d\+P\+\_\+neglect, bathyP, HI, E\+OS, US, dza, intp\+\_\+dza, intx\+\_\+dza, inty\+\_\+dza, use\+Mass\+Wght\+Interp)
\begin{DoxyCompactList}\small\item\em This subroutine calculates integrals of specific volume anomalies in pressure across layers, which are required for calculating the finite-\/volume form pressure accelerations in a non-\/\+Boussinesq model. There are essentially no free assumptions, apart from the use of Boole\textquotesingle{}s rule quadrature to do the integrals. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__density__integrals_af9946b0e15d53d8f1fd1ab1c1f81f3a2}{find\+\_\+depth\+\_\+of\+\_\+pressure\+\_\+in\+\_\+cell}} (T\+\_\+t, T\+\_\+b, S\+\_\+t, S\+\_\+b, z\+\_\+t, z\+\_\+b, P\+\_\+t, P\+\_\+tgt, rho\+\_\+ref, G\+\_\+e, E\+OS, US, P\+\_\+b, z\+\_\+out, z\+\_\+tol)
\begin{DoxyCompactList}\small\item\em Find the depth at which the reconstructed pressure matches P\+\_\+tgt. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__density__integrals_abb8d1f2c24def176a27ef2d30fa373df}{frac\+\_\+dp\+\_\+at\+\_\+pos}} (T\+\_\+t, T\+\_\+b, S\+\_\+t, S\+\_\+b, z\+\_\+t, z\+\_\+b, rho\+\_\+ref, G\+\_\+e, pos, E\+OS)
\begin{DoxyCompactList}\small\item\em Returns change in anomalous pressure change from top to non-\/dimensional position pos between z\+\_\+t and z\+\_\+b. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__density__integrals_af9946b0e15d53d8f1fd1ab1c1f81f3a2}\label{namespacemom__density__integrals_af9946b0e15d53d8f1fd1ab1c1f81f3a2}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!find\_depth\_of\_pressure\_in\_cell@{find\_depth\_of\_pressure\_in\_cell}}
\index{find\_depth\_of\_pressure\_in\_cell@{find\_depth\_of\_pressure\_in\_cell}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{find\_depth\_of\_pressure\_in\_cell()}{find\_depth\_of\_pressure\_in\_cell()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::find\+\_\+depth\+\_\+of\+\_\+pressure\+\_\+in\+\_\+cell (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T\+\_\+t,  }\item[{real, intent(in)}]{T\+\_\+b,  }\item[{real, intent(in)}]{S\+\_\+t,  }\item[{real, intent(in)}]{S\+\_\+b,  }\item[{real, intent(in)}]{z\+\_\+t,  }\item[{real, intent(in)}]{z\+\_\+b,  }\item[{real, intent(in)}]{P\+\_\+t,  }\item[{real, intent(in)}]{P\+\_\+tgt,  }\item[{real, intent(in)}]{rho\+\_\+ref,  }\item[{real, intent(in)}]{G\+\_\+e,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(out)}]{P\+\_\+b,  }\item[{real, intent(out)}]{z\+\_\+out,  }\item[{real, intent(in), optional}]{z\+\_\+tol }\end{DoxyParamCaption})}



Find the depth at which the reconstructed pressure matches P\+\_\+tgt. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t\+\_\+t} & Potential temperature at the cell top \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+b} & Potential temperature at the cell bottom \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+t} & Salinity at the cell top \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+b} & Salinity at the cell bottom \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+t} & Absolute height of top of cell \mbox{[}Z $\sim$$>$ m\mbox{]} (Boussinesq ????) \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+b} & Absolute height of bottom of cell \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+t} & Anomalous pressure of top of cell, relative to g$\ast$rho\+\_\+ref$\ast$z\+\_\+t \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+tgt} & Target pressure at height z\+\_\+out, relative to g$\ast$rho\+\_\+ref$\ast$z\+\_\+out \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & Reference density with which calculation are anomalous to \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em g\+\_\+e} & Gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ out}}  & {\em p\+\_\+b} & Pressure at the bottom of the cell \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em z\+\_\+out} & Absolute depth at which anomalous pressure = p\+\_\+tgt \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+tol} & The tolerance in finding z\+\_\+out \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1527 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1527 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: T\_t\textcolor{comment}{ !< Potential temperature at the cell top [degC]}}
\DoxyCodeLine{1528 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: T\_b\textcolor{comment}{ !< Potential temperature at the cell bottom [degC]}}
\DoxyCodeLine{1529 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: S\_t\textcolor{comment}{ !< Salinity at the cell top [ppt]}}
\DoxyCodeLine{1530 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: S\_b\textcolor{comment}{ !< Salinity at the cell bottom [ppt]}}
\DoxyCodeLine{1531 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: z\_t\textcolor{comment}{ !< Absolute height of top of cell [Z ~> m]   (Boussinesq ????)}}
\DoxyCodeLine{1532 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: z\_b\textcolor{comment}{ !< Absolute height of bottom of cell [Z ~> m]}}
\DoxyCodeLine{1533 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: P\_t\textcolor{comment}{ !< Anomalous pressure of top of cell, relative}}
\DoxyCodeLine{1534 \textcolor{comment}{                                            !! to g*rho\_ref*z\_t [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1535 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: P\_tgt\textcolor{comment}{ !< Target pressure at height z\_out, relative}}
\DoxyCodeLine{1536 \textcolor{comment}{                                            !! to g*rho\_ref*z\_out [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1537 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{ !< Reference density with which calculation}}
\DoxyCodeLine{1538 \textcolor{comment}{                                            !! are anomalous to [R ~> kg m-\/3]}}
\DoxyCodeLine{1539 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}  :: G\_e\textcolor{comment}{ !< Gravitational acceleration [L2 Z-\/1 T-\/2 ~> m s-\/2]}}
\DoxyCodeLine{1540   \textcolor{keywordtype}{type}(EOS\_type),        \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{1541   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1542 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: P\_b\textcolor{comment}{ !< Pressure at the bottom of the cell [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1543 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: z\_out\textcolor{comment}{ !< Absolute depth at which anomalous pressure = p\_tgt [Z ~> m]}}
\DoxyCodeLine{1544 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},        \textcolor{keywordtype}{intent(in)}  :: z\_tol\textcolor{comment}{ !< The tolerance in finding z\_out [Z ~> m]}}
\DoxyCodeLine{1545 }
\DoxyCodeLine{1546   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1547 \textcolor{keywordtype}{  real} :: dp    \textcolor{comment}{! Pressure thickness of the layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1548 \textcolor{keywordtype}{  real} :: F\_guess, F\_l, F\_r  \textcolor{comment}{! Fractional positions [nondim]}}
\DoxyCodeLine{1549 \textcolor{keywordtype}{  real} :: GxRho \textcolor{comment}{! The product of the gravitational acceleration and reference density [R L2 Z-\/1 T-\/2 ~> Pa m-\/1]}}
\DoxyCodeLine{1550 \textcolor{keywordtype}{  real} :: Pa, Pa\_left, Pa\_right, Pa\_tol \textcolor{comment}{! Pressure anomalies, P = integral of g*(rho-\/rho\_ref) dz [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1551   \textcolor{keywordtype}{character(len=240)} :: msg}
\DoxyCodeLine{1552 }
\DoxyCodeLine{1553   gxrho = g\_e * rho\_ref}
\DoxyCodeLine{1554 }
\DoxyCodeLine{1555   \textcolor{comment}{! Anomalous pressure difference across whole cell}}
\DoxyCodeLine{1556   dp = frac\_dp\_at\_pos(t\_t, t\_b, s\_t, s\_b, z\_t, z\_b, rho\_ref, g\_e, 1.0, eos)}
\DoxyCodeLine{1557 }
\DoxyCodeLine{1558   p\_b = p\_t + dp \textcolor{comment}{! Anomalous pressure at bottom of cell}}
\DoxyCodeLine{1559 }
\DoxyCodeLine{1560   \textcolor{keywordflow}{if} (p\_tgt <= p\_t ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1561     z\_out = z\_t}
\DoxyCodeLine{1562     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1563 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1564 }
\DoxyCodeLine{1565   \textcolor{keywordflow}{if} (p\_tgt >= p\_b) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1566     z\_out = z\_b}
\DoxyCodeLine{1567     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1568 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1569 }
\DoxyCodeLine{1570   f\_l = 0.}
\DoxyCodeLine{1571   pa\_left = p\_t -\/ p\_tgt \textcolor{comment}{! Pa\_left < 0}}
\DoxyCodeLine{1572   f\_r = 1.}
\DoxyCodeLine{1573   pa\_right = p\_b -\/ p\_tgt \textcolor{comment}{! Pa\_right > 0}}
\DoxyCodeLine{1574   pa\_tol = gxrho * 1.0e-\/5*us\%m\_to\_Z}
\DoxyCodeLine{1575   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(z\_tol)) pa\_tol = gxrho * z\_tol}
\DoxyCodeLine{1576 }
\DoxyCodeLine{1577   f\_guess = f\_l -\/ pa\_left / (pa\_right -\/ pa\_left) * (f\_r -\/ f\_l)}
\DoxyCodeLine{1578   pa = pa\_right -\/ pa\_left \textcolor{comment}{! To get into iterative loop}}
\DoxyCodeLine{1579   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} ( abs(pa) > pa\_tol )}
\DoxyCodeLine{1580 }
\DoxyCodeLine{1581     z\_out = z\_t + ( z\_b -\/ z\_t ) * f\_guess}
\DoxyCodeLine{1582     pa = frac\_dp\_at\_pos(t\_t, t\_b, s\_t, s\_b, z\_t, z\_b, rho\_ref, g\_e, f\_guess, eos) -\/ ( p\_tgt -\/ p\_t )}
\DoxyCodeLine{1583 }
\DoxyCodeLine{1584     \textcolor{keywordflow}{if} (pa<pa\_left) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1585       \textcolor{keyword}{write}(msg,*) pa\_left,pa,pa\_right,p\_t-\/p\_tgt,p\_b-\/p\_tgt}
\DoxyCodeLine{1586       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'find\_depth\_of\_pressure\_in\_cell out of bounds negative: /n'}//msg)}
\DoxyCodeLine{1587     \textcolor{keywordflow}{elseif} (pa<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1588       pa\_left = pa}
\DoxyCodeLine{1589       f\_l = f\_guess}
\DoxyCodeLine{1590     \textcolor{keywordflow}{elseif} (pa>pa\_right) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1591       \textcolor{keyword}{write}(msg,*) pa\_left,pa,pa\_right,p\_t-\/p\_tgt,p\_b-\/p\_tgt}
\DoxyCodeLine{1592       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'find\_depth\_of\_pressure\_in\_cell out of bounds positive: /n'}//msg)}
\DoxyCodeLine{1593     \textcolor{keywordflow}{elseif} (pa>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1594       pa\_right = pa}
\DoxyCodeLine{1595       f\_r = f\_guess}
\DoxyCodeLine{1596     \textcolor{keywordflow}{else} \textcolor{comment}{! Pa == 0}}
\DoxyCodeLine{1597       \textcolor{keywordflow}{return}}
\DoxyCodeLine{1598 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1599     f\_guess = f\_l -\/ pa\_left / (pa\_right -\/ pa\_left) * (f\_r -\/ f\_l)}
\DoxyCodeLine{1600 }
\DoxyCodeLine{1601 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1602 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_abb8d1f2c24def176a27ef2d30fa373df}\label{namespacemom__density__integrals_abb8d1f2c24def176a27ef2d30fa373df}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!frac\_dp\_at\_pos@{frac\_dp\_at\_pos}}
\index{frac\_dp\_at\_pos@{frac\_dp\_at\_pos}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{frac\_dp\_at\_pos()}{frac\_dp\_at\_pos()}}
{\footnotesize\ttfamily real function mom\+\_\+density\+\_\+integrals\+::frac\+\_\+dp\+\_\+at\+\_\+pos (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T\+\_\+t,  }\item[{real, intent(in)}]{T\+\_\+b,  }\item[{real, intent(in)}]{S\+\_\+t,  }\item[{real, intent(in)}]{S\+\_\+b,  }\item[{real, intent(in)}]{z\+\_\+t,  }\item[{real, intent(in)}]{z\+\_\+b,  }\item[{real, intent(in)}]{rho\+\_\+ref,  }\item[{real, intent(in)}]{G\+\_\+e,  }\item[{real, intent(in)}]{pos,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns change in anomalous pressure change from top to non-\/dimensional position pos between z\+\_\+t and z\+\_\+b. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t\+\_\+t} & Potential temperature at the cell top \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+b} & Potential temperature at the cell bottom \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+t} & Salinity at the cell top \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+b} & Salinity at the cell bottom \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+t} & The geometric height at the top of the layer \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+b} & The geometric height at the bottom of the layer \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A mean density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}, that is subtracted out to reduce the magnitude of each of the integrals. \\
\hline
\mbox{\texttt{ in}}  & {\em g\+\_\+e} & The Earth\textquotesingle{}s gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pos} & The fractional vertical position, 0 to 1 \mbox{[}nondim\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\end{DoxyParams}


Definition at line 1609 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1609 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: T\_t\textcolor{comment}{ !< Potential temperature at the cell top [degC]}}
\DoxyCodeLine{1610 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: T\_b\textcolor{comment}{ !< Potential temperature at the cell bottom [degC]}}
\DoxyCodeLine{1611 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: S\_t\textcolor{comment}{ !< Salinity at the cell top [ppt]}}
\DoxyCodeLine{1612 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: S\_b\textcolor{comment}{ !< Salinity at the cell bottom [ppt]}}
\DoxyCodeLine{1613 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: z\_t\textcolor{comment}{ !< The geometric height at the top of the layer [Z ~> m]}}
\DoxyCodeLine{1614 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: z\_b\textcolor{comment}{ !< The geometric height at the bottom of the layer [Z ~> m]}}
\DoxyCodeLine{1615 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{ !< A mean density [R ~> kg m-\/3], that is subtracted out to}}
\DoxyCodeLine{1616 \textcolor{comment}{                                     !! reduce the magnitude of each of the integrals.}}
\DoxyCodeLine{1617 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: G\_e\textcolor{comment}{ !< The Earth's gravitational acceleration [L2 Z-\/1 T-\/2 ~> m s-\/2]}}
\DoxyCodeLine{1618 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: pos\textcolor{comment}{ !< The fractional vertical position, 0 to 1 [nondim]}}
\DoxyCodeLine{1619   \textcolor{keywordtype}{type}(EOS\_type), \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{1620 \textcolor{keywordtype}{  real}                        :: fract\_dp\_at\_pos\textcolor{comment}{ !< The change in pressure from the layer top to}}
\DoxyCodeLine{1621 \textcolor{comment}{                                     !! fractional position pos [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1622   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1623 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_90 = 1.0/90.0  \textcolor{comment}{! A rational constant [nondim]}}
\DoxyCodeLine{1624 \textcolor{keywordtype}{  real} :: dz                 \textcolor{comment}{! Distance from the layer top [Z ~> m]}}
\DoxyCodeLine{1625 \textcolor{keywordtype}{  real} :: top\_weight, bottom\_weight \textcolor{comment}{! Fractional weights at quadrature points [nondim]}}
\DoxyCodeLine{1626 \textcolor{keywordtype}{  real} :: rho\_ave            \textcolor{comment}{! Average density [R ~> kg m-\/3]}}
\DoxyCodeLine{1627 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(5)} :: T5   \textcolor{comment}{! Temperatures at quadrature points [degC]}}
\DoxyCodeLine{1628 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(5)} :: S5   \textcolor{comment}{! Salinities at quadrature points [ppt]}}
\DoxyCodeLine{1629 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(5)} :: p5   \textcolor{comment}{! Pressures at quadrature points [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1630 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(5)} :: rho5 \textcolor{comment}{! Densities at quadrature points [R ~> kg m-\/3]}}
\DoxyCodeLine{1631   \textcolor{keywordtype}{integer} :: n}
\DoxyCodeLine{1632 }
\DoxyCodeLine{1633   \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{1634     \textcolor{comment}{! Evaluate density at five quadrature points}}
\DoxyCodeLine{1635     bottom\_weight = 0.25*real(n-\/1) * pos}
\DoxyCodeLine{1636     top\_weight = 1.0 -\/ bottom\_weight}
\DoxyCodeLine{1637     \textcolor{comment}{! Salinity and temperature points are linearly interpolated}}
\DoxyCodeLine{1638     s5(n) = top\_weight * s\_t + bottom\_weight * s\_b}
\DoxyCodeLine{1639     t5(n) = top\_weight * t\_t + bottom\_weight * t\_b}
\DoxyCodeLine{1640     p5(n) = ( top\_weight * z\_t + bottom\_weight * z\_b ) * ( g\_e * rho\_ref )}
\DoxyCodeLine{1641 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1642   \textcolor{keyword}{call }calculate\_density(t5, s5, p5, rho5, eos)}
\DoxyCodeLine{1643   rho5(:) = rho5(:) \textcolor{comment}{!-\/ rho\_ref ! Work with anomalies relative to rho\_ref}}
\DoxyCodeLine{1644 }
\DoxyCodeLine{1645   \textcolor{comment}{! Use Boole's rule to estimate the average density}}
\DoxyCodeLine{1646   rho\_ave = c1\_90*(7.0*(rho5(1)+rho5(5)) + 32.0*(rho5(2)+rho5(4)) + 12.0*rho5(3))}
\DoxyCodeLine{1647 }
\DoxyCodeLine{1648   dz = ( z\_t -\/ z\_b ) * pos}
\DoxyCodeLine{1649   frac\_dp\_at\_pos = g\_e * dz * rho\_ave}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_ac36ae5f4af2d02df0a1adf41b762e017}\label{namespacemom__density__integrals_ac36ae5f4af2d02df0a1adf41b762e017}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_density\_dz@{int\_density\_dz}}
\index{int\_density\_dz@{int\_density\_dz}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_density\_dz()}{int\_density\_dz()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+density\+\_\+dz (\begin{DoxyParamCaption}\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{T,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{S,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{z\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{z\+\_\+b,  }\item[{real, intent(in)}]{rho\+\_\+ref,  }\item[{real, intent(in)}]{rho\+\_\+0,  }\item[{real, intent(in)}]{G\+\_\+e,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(inout)}]{dpa,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(inout), optional}]{intz\+\_\+dpa,  }\item[{real, dimension(szib\+\_\+(hi),szj\+\_\+(hi)), intent(inout), optional}]{intx\+\_\+dpa,  }\item[{real, dimension(szi\+\_\+(hi),szjb\+\_\+(hi)), intent(inout), optional}]{inty\+\_\+dpa,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in), optional}]{bathyT,  }\item[{real, intent(in), optional}]{dz\+\_\+neglect,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



Calls the appropriate subroutine to calculate analytical and nearly-\/analytical integrals in z across layers of pressure anomalies, which are required for calculating the finite-\/volume form pressure accelerations in a Boussinesq model. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & Ocean horizontal index structures for the arrays \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+t} & Height at the top of the layer in depth units \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+b} & Height at the bottom of the layer \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A mean density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is subtracted out to reduce the magnitude of each of the integrals. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+0} & A density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is used to calculate the pressure (as p$\sim$=-\/z$\ast$rho\+\_\+0$\ast$\+G\+\_\+e) used in the equation of state. \\
\hline
\mbox{\texttt{ in}}  & {\em g\+\_\+e} & The Earth\textquotesingle{}s gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]} or \mbox{[}m2 Z-\/1 s-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dpa} & The change in the pressure anomaly \\
\hline
\mbox{\texttt{ in,out}}  & {\em intz\+\_\+dpa} & The integral through the thickness of the \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dpa} & The integral in x of the difference between \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dpa} & The integral in y of the difference between \\
\hline
\mbox{\texttt{ in}}  & {\em bathyt} & The depth of the bathymetry \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+neglect} & A minuscule thickness change \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 42 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{42   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{  !< Ocean horizontal index structures for the arrays}}
\DoxyCodeLine{43 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{44                         \textcolor{keywordtype}{intent(in)}  :: T\textcolor{comment}{   !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{45 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{46                         \textcolor{keywordtype}{intent(in)}  :: S\textcolor{comment}{   !< Salinity [ppt]}}
\DoxyCodeLine{47 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{48                         \textcolor{keywordtype}{intent(in)}  :: z\_t\textcolor{comment}{ !< Height at the top of the layer in depth units [Z ~> m]}}
\DoxyCodeLine{49 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{50                         \textcolor{keywordtype}{intent(in)}  :: z\_b\textcolor{comment}{ !< Height at the bottom of the layer [Z ~> m]}}
\DoxyCodeLine{51 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{ !< A mean density [R ~> kg m-\/3] or [kg m-\/3], that is}}
\DoxyCodeLine{52 \textcolor{comment}{                                           !! subtracted out to reduce the magnitude of each of the}}
\DoxyCodeLine{53 \textcolor{comment}{                                           !! integrals.}}
\DoxyCodeLine{54 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_0\textcolor{comment}{ !< A density [R ~> kg m-\/3] or [kg m-\/3], that is used}}
\DoxyCodeLine{55 \textcolor{comment}{                                           !! to calculate the pressure (as p~=-\/z*rho\_0*G\_e)}}
\DoxyCodeLine{56 \textcolor{comment}{                                           !! used in the equation of state.}}
\DoxyCodeLine{57 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: G\_e\textcolor{comment}{ !< The Earth's gravitational acceleration}}
\DoxyCodeLine{58 \textcolor{comment}{                                           !! [L2 Z-\/1 T-\/2 ~> m s-\/2] or [m2 Z-\/1 s-\/2 ~> m s-\/2]}}
\DoxyCodeLine{59   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{60   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{61 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{62                       \textcolor{keywordtype}{intent(inout)} :: dpa\textcolor{comment}{ !< The change in the pressure anomaly}}
\DoxyCodeLine{63 \textcolor{comment}{                                           !! across the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{64 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{65             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intz\_dpa\textcolor{comment}{ !< The integral through the thickness of the}}
\DoxyCodeLine{66 \textcolor{comment}{                                           !! layer of the pressure anomaly relative to the}}
\DoxyCodeLine{67 \textcolor{comment}{                                           !! anomaly at the top of the layer [R L2 Z T-\/2 ~> Pa m]}}
\DoxyCodeLine{68 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{69             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dpa\textcolor{comment}{ !< The integral in x of the difference between}}
\DoxyCodeLine{70 \textcolor{comment}{                                          !! the pressure anomaly at the top and bottom of the}}
\DoxyCodeLine{71 \textcolor{comment}{                                          !! layer divided by the x grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{72 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{73             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dpa\textcolor{comment}{ !< The integral in y of the difference between}}
\DoxyCodeLine{74 \textcolor{comment}{                                          !! the pressure anomaly at the top and bottom of the}}
\DoxyCodeLine{75 \textcolor{comment}{                                          !! layer divided by the y grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{76 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{77               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: bathyT\textcolor{comment}{ !< The depth of the bathymetry [Z ~> m]}}
\DoxyCodeLine{78 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dz\_neglect\textcolor{comment}{ !< A minuscule thickness change [Z ~> m]}}
\DoxyCodeLine{79   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting to}}
\DoxyCodeLine{80 \textcolor{comment}{                                           !! interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{81 }
\DoxyCodeLine{82   \textcolor{keywordflow}{if} (eos\_quadrature(eos)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{83     \textcolor{keyword}{call }int\_density\_dz\_generic\_pcm(t, s, z\_t, z\_b, rho\_ref, rho\_0, g\_e, hi, eos, us, dpa, \&}
\DoxyCodeLine{84                                     intz\_dpa, intx\_dpa, inty\_dpa, bathyt, dz\_neglect, usemasswghtinterp)}
\DoxyCodeLine{85   \textcolor{keywordflow}{else}}
\DoxyCodeLine{86     \textcolor{keyword}{call }analytic\_int\_density\_dz(t, s, z\_t, z\_b, rho\_ref, rho\_0, g\_e, hi, eos, dpa, \&}
\DoxyCodeLine{87                                  intz\_dpa, intx\_dpa, inty\_dpa, bathyt, dz\_neglect, usemasswghtinterp)}
\DoxyCodeLine{88 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{89 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_ad0ff54518bfacf7beebbe4dba687a914}\label{namespacemom__density__integrals_ad0ff54518bfacf7beebbe4dba687a914}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_density\_dz\_generic\_pcm@{int\_density\_dz\_generic\_pcm}}
\index{int\_density\_dz\_generic\_pcm@{int\_density\_dz\_generic\_pcm}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_density\_dz\_generic\_pcm()}{int\_density\_dz\_generic\_pcm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+density\+\_\+dz\+\_\+generic\+\_\+pcm (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{T,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{S,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{z\+\_\+t,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{z\+\_\+b,  }\item[{real, intent(in)}]{rho\+\_\+ref,  }\item[{real, intent(in)}]{rho\+\_\+0,  }\item[{real, intent(in)}]{G\+\_\+e,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout)}]{dpa,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intz\+\_\+dpa,  }\item[{real, dimension( hi \%isdb\+: hi \%iedb, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intx\+\_\+dpa,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsdb\+: hi \%jedb), intent(inout), optional}]{inty\+\_\+dpa,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in), optional}]{bathyT,  }\item[{real, intent(in), optional}]{dz\+\_\+neglect,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



Calculates (by numerical quadrature) integrals of pressure anomalies across layers, which are required for calculating the finite-\/volume form pressure accelerations in a Boussinesq model. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & Horizontal index type for input variables. \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Potential temperature of the layer \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity of the layer \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+t} & Height at the top of the layer in depth units \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+b} & Height at the bottom of the layer \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A mean density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is subtracted out to reduce the magnitude of each of the integrals. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+0} & A density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is used to calculate the pressure (as p$\sim$=-\/z$\ast$rho\+\_\+0$\ast$\+G\+\_\+e) used in the equation of state. \\
\hline
\mbox{\texttt{ in}}  & {\em g\+\_\+e} & The Earth\textquotesingle{}s gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]} or \mbox{[}m2 Z-\/1 s-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dpa} & The change in the pressure anomaly \\
\hline
\mbox{\texttt{ in,out}}  & {\em intz\+\_\+dpa} & The integral through the thickness of the \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dpa} & The integral in x of the difference between \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dpa} & The integral in y of the difference between \\
\hline
\mbox{\texttt{ in}}  & {\em bathyt} & The depth of the bathymetry \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+neglect} & A minuscule thickness change \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 98 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{98   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{  !< Horizontal index type for input variables.}}
\DoxyCodeLine{99 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{100                         \textcolor{keywordtype}{intent(in)}  :: T\textcolor{comment}{  !< Potential temperature of the layer [degC]}}
\DoxyCodeLine{101 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{102                         \textcolor{keywordtype}{intent(in)}  :: S\textcolor{comment}{  !< Salinity of the layer [ppt]}}
\DoxyCodeLine{103 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{104                         \textcolor{keywordtype}{intent(in)}  :: z\_t\textcolor{comment}{ !< Height at the top of the layer in depth units [Z ~> m]}}
\DoxyCodeLine{105 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{106                         \textcolor{keywordtype}{intent(in)}  :: z\_b\textcolor{comment}{ !< Height at the bottom of the layer [Z ~> m]}}
\DoxyCodeLine{107 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{ !< A mean density [R ~> kg m-\/3] or [kg m-\/3], that is}}
\DoxyCodeLine{108 \textcolor{comment}{                                          !! subtracted out to reduce the magnitude}}
\DoxyCodeLine{109 \textcolor{comment}{                                          !! of each of the integrals.}}
\DoxyCodeLine{110 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_0\textcolor{comment}{ !< A density [R ~> kg m-\/3] or [kg m-\/3], that is used}}
\DoxyCodeLine{111 \textcolor{comment}{                                          !! to calculate the pressure (as p~=-\/z*rho\_0*G\_e)}}
\DoxyCodeLine{112 \textcolor{comment}{                                          !! used in the equation of state.}}
\DoxyCodeLine{113 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: G\_e\textcolor{comment}{ !< The Earth's gravitational acceleration}}
\DoxyCodeLine{114 \textcolor{comment}{                                          !! [L2 Z-\/1 T-\/2 ~> m s-\/2] or [m2 Z-\/1 s-\/2 ~> m s-\/2]}}
\DoxyCodeLine{115   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{116   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{117 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{118                       \textcolor{keywordtype}{intent(inout)} :: dpa\textcolor{comment}{ !< The change in the pressure anomaly}}
\DoxyCodeLine{119 \textcolor{comment}{                                          !! across the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{120 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{121             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intz\_dpa\textcolor{comment}{ !< The integral through the thickness of the}}
\DoxyCodeLine{122 \textcolor{comment}{                                          !! layer of the pressure anomaly relative to the}}
\DoxyCodeLine{123 \textcolor{comment}{                                          !! anomaly at the top of the layer [R L2 Z T-\/2 ~> Pa m]}}
\DoxyCodeLine{124 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{125             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dpa\textcolor{comment}{ !< The integral in x of the difference between}}
\DoxyCodeLine{126 \textcolor{comment}{                                          !! the pressure anomaly at the top and bottom of the}}
\DoxyCodeLine{127 \textcolor{comment}{                                          !! layer divided by the x grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{128 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{129             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dpa\textcolor{comment}{ !< The integral in y of the difference between}}
\DoxyCodeLine{130 \textcolor{comment}{                                          !! the pressure anomaly at the top and bottom of the}}
\DoxyCodeLine{131 \textcolor{comment}{                                          !! layer divided by the y grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{132 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{133               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: bathyT\textcolor{comment}{ !< The depth of the bathymetry [Z ~> m]}}
\DoxyCodeLine{134 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dz\_neglect\textcolor{comment}{ !< A minuscule thickness change [Z ~> m]}}
\DoxyCodeLine{135   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting to}}
\DoxyCodeLine{136 \textcolor{comment}{                                          !! interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{137   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{138 \textcolor{keywordtype}{  real} :: T5(5), S5(5) \textcolor{comment}{! Temperatures and salinities at five quadrature points [degC] and [ppt]}}
\DoxyCodeLine{139 \textcolor{keywordtype}{  real} :: p5(5)      \textcolor{comment}{! Pressures at five quadrature points, never rescaled from Pa [Pa]}}
\DoxyCodeLine{140 \textcolor{keywordtype}{  real} :: r5(5)      \textcolor{comment}{! Densities at five quadrature points [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{141 \textcolor{keywordtype}{  real} :: rho\_anom   \textcolor{comment}{! The depth averaged density anomaly [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{142 \textcolor{keywordtype}{  real} :: w\_left, w\_right \textcolor{comment}{! Left and right weights [nondim]}}
\DoxyCodeLine{143 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_90 = 1.0/90.0  \textcolor{comment}{! Rational constants.}}
\DoxyCodeLine{144 \textcolor{keywordtype}{  real} :: GxRho      \textcolor{comment}{! The gravitational acceleration times density and unit conversion factors [Pa Z-\/1 ~> kg m-\/2 s-\/2]}}
\DoxyCodeLine{145 \textcolor{keywordtype}{  real} :: I\_Rho      \textcolor{comment}{! The inverse of the Boussinesq density [R-\/1 ~> m3 kg-\/1] or [m3 kg-\/1]}}
\DoxyCodeLine{146 \textcolor{keywordtype}{  real} :: rho\_scale  \textcolor{comment}{! A scaling factor for densities from kg m-\/3 to R [R m3 kg-\/1 ~> 1]}}
\DoxyCodeLine{147 \textcolor{keywordtype}{  real} :: rho\_ref\_mks \textcolor{comment}{! The reference density in MKS units, never rescaled from kg m-\/3 [kg m-\/3]}}
\DoxyCodeLine{148 \textcolor{keywordtype}{  real} :: dz         \textcolor{comment}{! The layer thickness [Z ~> m]}}
\DoxyCodeLine{149 \textcolor{keywordtype}{  real} :: hWght      \textcolor{comment}{! A pressure-\/thickness below topography [Z ~> m]}}
\DoxyCodeLine{150 \textcolor{keywordtype}{  real} :: hL, hR     \textcolor{comment}{! Pressure-\/thicknesses of the columns to the left and right [Z ~> m]}}
\DoxyCodeLine{151 \textcolor{keywordtype}{  real} :: iDenom     \textcolor{comment}{! The inverse of the denominator in the weights [Z-\/2 ~> m-\/2]}}
\DoxyCodeLine{152 \textcolor{keywordtype}{  real} :: hWt\_LL, hWt\_LR \textcolor{comment}{! hWt\_LA is the weighted influence of A on the left column [nondim]}}
\DoxyCodeLine{153 \textcolor{keywordtype}{  real} :: hWt\_RL, hWt\_RR \textcolor{comment}{! hWt\_RA is the weighted influence of A on the right column [nondim]}}
\DoxyCodeLine{154 \textcolor{keywordtype}{  real} :: wt\_L, wt\_R \textcolor{comment}{! The linear weights of the left and right columns [nondim]}}
\DoxyCodeLine{155 \textcolor{keywordtype}{  real} :: wtT\_L, wtT\_R \textcolor{comment}{! The weights for tracers from the left and right columns [nondim]}}
\DoxyCodeLine{156 \textcolor{keywordtype}{  real} :: intz(5)    \textcolor{comment}{! The gravitational acceleration times the integrals of density}}
\DoxyCodeLine{157                      \textcolor{comment}{! with height at the 5 sub-\/column locations [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{158   \textcolor{keywordtype}{logical} :: do\_massWeight \textcolor{comment}{! Indicates whether to do mass weighting.}}
\DoxyCodeLine{159   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, i, j, m, n}
\DoxyCodeLine{160 }
\DoxyCodeLine{161   \textcolor{comment}{! These array bounds work for the indexing convention of the input arrays, but}}
\DoxyCodeLine{162   \textcolor{comment}{! on the computational domain defined for the output arrays.}}
\DoxyCodeLine{163   isq = hi\%IscB ; ieq = hi\%IecB}
\DoxyCodeLine{164   jsq = hi\%JscB ; jeq = hi\%JecB}
\DoxyCodeLine{165   is = hi\%isc ; ie = hi\%iec}
\DoxyCodeLine{166   js = hi\%jsc ; je = hi\%jec}
\DoxyCodeLine{167 }
\DoxyCodeLine{168   rho\_scale = us\%kg\_m3\_to\_R}
\DoxyCodeLine{169   gxrho = us\%RL2\_T2\_to\_Pa * g\_e * rho\_0}
\DoxyCodeLine{170   rho\_ref\_mks = rho\_ref * us\%R\_to\_kg\_m3}
\DoxyCodeLine{171   i\_rho = 1.0 / rho\_0}
\DoxyCodeLine{172 }
\DoxyCodeLine{173   do\_massweight = .false.}
\DoxyCodeLine{174   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (usemasswghtinterp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{175     do\_massweight = .true.}
\DoxyCodeLine{176     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{present}(bathyt)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"int\_density\_dz\_generic: "}//\&}
\DoxyCodeLine{177         \textcolor{stringliteral}{"bathyT must be present if useMassWghtInterp is present and true."})}
\DoxyCodeLine{178     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{present}(dz\_neglect)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"int\_density\_dz\_generic: "}//\&}
\DoxyCodeLine{179         \textcolor{stringliteral}{"dz\_neglect must be present if useMassWghtInterp is present and true."})}
\DoxyCodeLine{180 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{181 }
\DoxyCodeLine{182   \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{183     dz = z\_t(i,j) -\/ z\_b(i,j)}
\DoxyCodeLine{184     \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{185       t5(n) = t(i,j) ; s5(n) = s(i,j)}
\DoxyCodeLine{186       p5(n) = -\/gxrho*(z\_t(i,j) -\/ 0.25*real(n-\/1)*dz)}
\DoxyCodeLine{187 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{188     \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{189       \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{190     \textcolor{keywordflow}{else}}
\DoxyCodeLine{191       \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{192 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{193 }
\DoxyCodeLine{194     \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{195     rho\_anom = c1\_90*(7.0*(r5(1)+r5(5)) + 32.0*(r5(2)+r5(4)) + 12.0*r5(3))}
\DoxyCodeLine{196     dpa(i,j) = g\_e*dz*rho\_anom}
\DoxyCodeLine{197     \textcolor{comment}{! Use a Boole's-\/rule-\/like fifth-\/order accurate estimate of the double integral of}}
\DoxyCodeLine{198     \textcolor{comment}{! the pressure anomaly.}}
\DoxyCodeLine{199     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intz\_dpa)) intz\_dpa(i,j) = 0.5*g\_e*dz**2 * \&}
\DoxyCodeLine{200           (rho\_anom -\/ c1\_90*(16.0*(r5(4)-\/r5(2)) + 7.0*(r5(5)-\/r5(1))) )}
\DoxyCodeLine{201 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{202 }
\DoxyCodeLine{203   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{204     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{205     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}}
\DoxyCodeLine{206     \textcolor{comment}{! T \& S along the top and bottom integrals, akin to thickness weighting.}}
\DoxyCodeLine{207     hwght = 0.0}
\DoxyCodeLine{208     \textcolor{keywordflow}{if} (do\_massweight) \&}
\DoxyCodeLine{209       hwght = max(0., -\/bathyt(i,j)-\/z\_t(i+1,j), -\/bathyt(i+1,j)-\/z\_t(i,j))}
\DoxyCodeLine{210     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{211       hl = (z\_t(i,j) -\/ z\_b(i,j)) + dz\_neglect}
\DoxyCodeLine{212       hr = (z\_t(i+1,j) -\/ z\_b(i+1,j)) + dz\_neglect}
\DoxyCodeLine{213       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{214       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{215       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom}
\DoxyCodeLine{216       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom}
\DoxyCodeLine{217     \textcolor{keywordflow}{else}}
\DoxyCodeLine{218       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0}
\DoxyCodeLine{219 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{220 }
\DoxyCodeLine{221     intz(1) = dpa(i,j) ; intz(5) = dpa(i+1,j)}
\DoxyCodeLine{222     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{223       \textcolor{comment}{! T, S, and z are interpolated in the horizontal.  The z interpolation}}
\DoxyCodeLine{224       \textcolor{comment}{! is linear, but for T and S it may be thickness weighted.}}
\DoxyCodeLine{225       wt\_l = 0.25*real(5-\/m) ; wt\_r = 1.0-\/wt\_l}
\DoxyCodeLine{226       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr}
\DoxyCodeLine{227       dz = wt\_l*(z\_t(i,j) -\/ z\_b(i,j)) + wt\_r*(z\_t(i+1,j) -\/ z\_b(i+1,j))}
\DoxyCodeLine{228       t5(1) = wtt\_l*t(i,j) + wtt\_r*t(i+1,j)}
\DoxyCodeLine{229       s5(1) = wtt\_l*s(i,j) + wtt\_r*s(i+1,j)}
\DoxyCodeLine{230       p5(1) = -\/gxrho*(wt\_l*z\_t(i,j) + wt\_r*z\_t(i+1,j))}
\DoxyCodeLine{231       \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{232         t5(n) = t5(1) ; s5(n) = s5(1) ; p5(n) = p5(n-\/1) + gxrho*0.25*dz}
\DoxyCodeLine{233 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{234       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{235         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{236       \textcolor{keywordflow}{else}}
\DoxyCodeLine{237         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{238 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{239 }
\DoxyCodeLine{240     \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{241       intz(m) = g\_e*dz*( c1\_90*(7.0*(r5(1)+r5(5)) + 32.0*(r5(2)+r5(4)) + 12.0*r5(3)))}
\DoxyCodeLine{242 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{243     \textcolor{comment}{! Use Boole's rule to integrate the bottom pressure anomaly values in x.}}
\DoxyCodeLine{244     intx\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + \&}
\DoxyCodeLine{245                            12.0*intz(3))}
\DoxyCodeLine{246 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{247 }
\DoxyCodeLine{248   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{249     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{250     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}}
\DoxyCodeLine{251     \textcolor{comment}{! T \& S along the top and bottom integrals, akin to thickness weighting.}}
\DoxyCodeLine{252     hwght = 0.0}
\DoxyCodeLine{253     \textcolor{keywordflow}{if} (do\_massweight) \&}
\DoxyCodeLine{254       hwght = max(0., -\/bathyt(i,j)-\/z\_t(i,j+1), -\/bathyt(i,j+1)-\/z\_t(i,j))}
\DoxyCodeLine{255     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{256       hl = (z\_t(i,j) -\/ z\_b(i,j)) + dz\_neglect}
\DoxyCodeLine{257       hr = (z\_t(i,j+1) -\/ z\_b(i,j+1)) + dz\_neglect}
\DoxyCodeLine{258       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{259       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{260       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom}
\DoxyCodeLine{261       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom}
\DoxyCodeLine{262     \textcolor{keywordflow}{else}}
\DoxyCodeLine{263       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0}
\DoxyCodeLine{264 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{265 }
\DoxyCodeLine{266     intz(1) = dpa(i,j) ; intz(5) = dpa(i,j+1)}
\DoxyCodeLine{267     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{268       \textcolor{comment}{! T, S, and z are interpolated in the horizontal.  The z interpolation}}
\DoxyCodeLine{269       \textcolor{comment}{! is linear, but for T and S it may be thickness weighted.}}
\DoxyCodeLine{270       wt\_l = 0.25*real(5-\/m) ; wt\_r = 1.0-\/wt\_l}
\DoxyCodeLine{271       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr}
\DoxyCodeLine{272       dz = wt\_l*(z\_t(i,j) -\/ z\_b(i,j)) + wt\_r*(z\_t(i,j+1) -\/ z\_b(i,j+1))}
\DoxyCodeLine{273       t5(1) = wtt\_l*t(i,j) + wtt\_r*t(i,j+1)}
\DoxyCodeLine{274       s5(1) = wtt\_l*s(i,j) + wtt\_r*s(i,j+1)}
\DoxyCodeLine{275       p5(1) = -\/gxrho*(wt\_l*z\_t(i,j) + wt\_r*z\_t(i,j+1))}
\DoxyCodeLine{276       \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{277         t5(n) = t5(1) ; s5(n) = s5(1)}
\DoxyCodeLine{278         p5(n) = p5(n-\/1) + gxrho*0.25*dz}
\DoxyCodeLine{279 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{280       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{281         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{282       \textcolor{keywordflow}{else}}
\DoxyCodeLine{283         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{284 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{285 }
\DoxyCodeLine{286     \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{287       intz(m) = g\_e*dz*( c1\_90*(7.0*(r5(1)+r5(5)) + 32.0*(r5(2)+r5(4)) + 12.0*r5(3)))}
\DoxyCodeLine{288 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{289     \textcolor{comment}{! Use Boole's rule to integrate the values.}}
\DoxyCodeLine{290     inty\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + \&}
\DoxyCodeLine{291                                      12.0*intz(3))}
\DoxyCodeLine{292 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_a454d4d62eb599716cc3389fb8aa90b4b}\label{namespacemom__density__integrals_a454d4d62eb599716cc3389fb8aa90b4b}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_density\_dz\_generic\_plm@{int\_density\_dz\_generic\_plm}}
\index{int\_density\_dz\_generic\_plm@{int\_density\_dz\_generic\_plm}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_density\_dz\_generic\_plm()}{int\_density\_dz\_generic\_plm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+density\+\_\+dz\+\_\+generic\+\_\+plm (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{k,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed, gv \%ke), intent(in)}]{T\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed, gv \%ke), intent(in)}]{T\+\_\+b,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed, gv \%ke), intent(in)}]{S\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed, gv \%ke), intent(in)}]{S\+\_\+b,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed, gv \%ke+1), intent(in)}]{e,  }\item[{real, intent(in)}]{rho\+\_\+ref,  }\item[{real, intent(in)}]{rho\+\_\+0,  }\item[{real, intent(in)}]{G\+\_\+e,  }\item[{real, intent(in)}]{dz\+\_\+subroundoff,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{bathyT,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(inout)}]{dpa,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(inout), optional}]{intz\+\_\+dpa,  }\item[{real, dimension(szib\+\_\+(hi),szj\+\_\+(hi)), intent(inout), optional}]{intx\+\_\+dpa,  }\item[{real, dimension(szi\+\_\+(hi),szjb\+\_\+(hi)), intent(inout), optional}]{inty\+\_\+dpa,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



Compute pressure gradient force integrals by quadrature for the case where T and S are linear profiles. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em k} & Layer index to calculate integrals for \\
\hline
\mbox{\texttt{ in}}  & {\em hi} & Ocean horizontal index structures for the input arrays \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+t} & Potential temperature at the cell top \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+b} & Potential temperature at the cell bottom \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+t} & Salinity at the cell top \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+b} & Salinity at the cell bottom \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em e} & Height of interfaces \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A mean density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is subtracted out to reduce the magnitude of each of the integrals. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+0} & A density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is used to calculate the pressure (as p$\sim$=-\/z$\ast$rho\+\_\+0$\ast$\+G\+\_\+e) used in the equation of state. \\
\hline
\mbox{\texttt{ in}}  & {\em g\+\_\+e} & The Earth\textquotesingle{}s gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+subroundoff} & A minuscule thickness change \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em bathyt} & The depth of the bathymetry \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dpa} & The change in the pressure anomaly across the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em intz\+\_\+dpa} & The integral through the thickness of the layer of \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dpa} & The integral in x of the difference between the \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dpa} & The integral in y of the difference between the \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 301 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{301   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: k\textcolor{comment}{   !< Layer index to calculate integrals for}}
\DoxyCodeLine{302   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{  !< Ocean horizontal index structures for the input arrays}}
\DoxyCodeLine{303   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{304   \textcolor{keywordtype}{type}(thermo\_var\_ptrs), \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{  !< Thermodynamic variables}}
\DoxyCodeLine{305 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{306                         \textcolor{keywordtype}{intent(in)}  :: T\_t\textcolor{comment}{ !< Potential temperature at the cell top [degC]}}
\DoxyCodeLine{307 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{308                         \textcolor{keywordtype}{intent(in)}  :: T\_b\textcolor{comment}{ !< Potential temperature at the cell bottom [degC]}}
\DoxyCodeLine{309 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{310                         \textcolor{keywordtype}{intent(in)}  :: S\_t\textcolor{comment}{ !< Salinity at the cell top [ppt]}}
\DoxyCodeLine{311 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{312                         \textcolor{keywordtype}{intent(in)}  :: S\_b\textcolor{comment}{ !< Salinity at the cell bottom [ppt]}}
\DoxyCodeLine{313 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV)+1)}, \&}
\DoxyCodeLine{314                         \textcolor{keywordtype}{intent(in)}  :: e\textcolor{comment}{   !< Height of interfaces [Z ~> m]}}
\DoxyCodeLine{315 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{ !< A mean density [R ~> kg m-\/3] or [kg m-\/3], that is subtracted}}
\DoxyCodeLine{316 \textcolor{comment}{                                           !! out to reduce the magnitude of each of the integrals.}}
\DoxyCodeLine{317 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_0\textcolor{comment}{ !< A density [R ~> kg m-\/3] or [kg m-\/3], that is used to calculate}}
\DoxyCodeLine{318 \textcolor{comment}{                                           !! the pressure (as p~=-\/z*rho\_0*G\_e) used in the equation of state.}}
\DoxyCodeLine{319 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: G\_e\textcolor{comment}{ !< The Earth's gravitational acceleration [L2 Z-\/1 T-\/2 ~> m s-\/2]}}
\DoxyCodeLine{320 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: dz\_subroundoff\textcolor{comment}{ !< A minuscule thickness change [Z ~> m]}}
\DoxyCodeLine{321 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{322                         \textcolor{keywordtype}{intent(in)}  :: bathyT\textcolor{comment}{ !< The depth of the bathymetry [Z ~> m]}}
\DoxyCodeLine{323   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{324   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{325 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{326                         \textcolor{keywordtype}{intent(inout)} :: dpa\textcolor{comment}{ !< The change in the pressure anomaly across the layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{327 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{328               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intz\_dpa\textcolor{comment}{ !< The integral through the thickness of the layer of}}
\DoxyCodeLine{329 \textcolor{comment}{                                           !! the pressure anomaly relative to the anomaly at the}}
\DoxyCodeLine{330 \textcolor{comment}{                                           !! top of the layer [R L2 Z T-\/2 ~> Pa Z]}}
\DoxyCodeLine{331 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{332               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dpa\textcolor{comment}{ !< The integral in x of the difference between the}}
\DoxyCodeLine{333 \textcolor{comment}{                                           !! pressure anomaly at the top and bottom of the layer}}
\DoxyCodeLine{334 \textcolor{comment}{                                           !! divided by the x grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{335 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{336               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dpa\textcolor{comment}{ !< The integral in y of the difference between the}}
\DoxyCodeLine{337 \textcolor{comment}{                                           !! pressure anomaly at the top and bottom of the layer}}
\DoxyCodeLine{338 \textcolor{comment}{                                           !! divided by the y grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{339   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting to}}
\DoxyCodeLine{340 \textcolor{comment}{                                           !! interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{341 }
\DoxyCodeLine{342 \textcolor{comment}{! This subroutine calculates (by numerical quadrature) integrals of}}
\DoxyCodeLine{343 \textcolor{comment}{! pressure anomalies across layers, which are required for calculating the}}
\DoxyCodeLine{344 \textcolor{comment}{! finite-\/volume form pressure accelerations in a Boussinesq model.  The one}}
\DoxyCodeLine{345 \textcolor{comment}{! potentially dodgy assumption here is that rho\_0 is used both in the denominator}}
\DoxyCodeLine{346 \textcolor{comment}{! of the accelerations, and in the pressure used to calculated density (the}}
\DoxyCodeLine{347 \textcolor{comment}{! latter being -\/z*rho\_0*G\_e).  These two uses could be separated if need be.}}
\DoxyCodeLine{348 \textcolor{comment}{!}}
\DoxyCodeLine{349 \textcolor{comment}{! It is assumed that the salinity and temperature profiles are linear in the}}
\DoxyCodeLine{350 \textcolor{comment}{! vertical. The top and bottom values within each layer are provided and}}
\DoxyCodeLine{351 \textcolor{comment}{! a linear interpolation is used to compute intermediate values.}}
\DoxyCodeLine{352 }
\DoxyCodeLine{353   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{354 \textcolor{keywordtype}{  real} :: T5((5*HI\%iscB+1):(5*(HI\%iecB+2)))  \textcolor{comment}{! Temperatures along a line of subgrid locations [degC]}}
\DoxyCodeLine{355 \textcolor{keywordtype}{  real} :: S5((5*HI\%iscB+1):(5*(HI\%iecB+2)))  \textcolor{comment}{! Salinities along a line of subgrid locations [ppt]}}
\DoxyCodeLine{356 \textcolor{keywordtype}{  real} :: T25((5*HI\%iscB+1):(5*(HI\%iecB+2))) \textcolor{comment}{! SGS temperature variance along a line of subgrid locations [degC2]}}
\DoxyCodeLine{357 \textcolor{keywordtype}{  real} :: TS5((5*HI\%iscB+1):(5*(HI\%iecB+2))) \textcolor{comment}{! SGS temp-\/salt covariance along a line of subgrid locations [degC ppt]}}
\DoxyCodeLine{358 \textcolor{keywordtype}{  real} :: S25((5*HI\%iscB+1):(5*(HI\%iecB+2))) \textcolor{comment}{! SGS salinity variance along a line of subgrid locations [ppt2]}}
\DoxyCodeLine{359 \textcolor{keywordtype}{  real} :: p5((5*HI\%iscB+1):(5*(HI\%iecB+2)))  \textcolor{comment}{! Pressures along a line of subgrid locations, never}}
\DoxyCodeLine{360                                                \textcolor{comment}{! rescaled from Pa [Pa]}}
\DoxyCodeLine{361 \textcolor{keywordtype}{  real} :: r5((5*HI\%iscB+1):(5*(HI\%iecB+2)))  \textcolor{comment}{! Densities anomalies along a line of subgrid}}
\DoxyCodeLine{362                                                \textcolor{comment}{! locations [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{363 \textcolor{keywordtype}{  real} :: T15((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! Temperatures at an array of subgrid locations [degC]}}
\DoxyCodeLine{364 \textcolor{keywordtype}{  real} :: S15((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! Salinities at an array of subgrid locations [ppt]}}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real} :: T215((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! SGS temperature variance along a line of subgrid locations [degC2]}}
\DoxyCodeLine{366 \textcolor{keywordtype}{  real} :: TS15((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! SGS temp-\/salt covariance along a line of subgrid locations [degC ppt]}}
\DoxyCodeLine{367 \textcolor{keywordtype}{  real} :: S215((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! SGS salinity variance along a line of subgrid locations [ppt2]}}
\DoxyCodeLine{368 \textcolor{keywordtype}{  real} :: p15((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! Pressures at an array of subgrid locations [Pa]}}
\DoxyCodeLine{369 \textcolor{keywordtype}{  real} :: r15((15*HI\%iscB+1):(15*(HI\%iecB+1))) \textcolor{comment}{! Densities at an array of subgrid locations}}
\DoxyCodeLine{370                                                  \textcolor{comment}{! [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{371 \textcolor{keywordtype}{  real} :: wt\_t(5), wt\_b(5)          \textcolor{comment}{! Top and bottom weights [nondim]}}
\DoxyCodeLine{372 \textcolor{keywordtype}{  real} :: rho\_anom                  \textcolor{comment}{! A density anomaly [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{373 \textcolor{keywordtype}{  real} :: w\_left, w\_right           \textcolor{comment}{! Left and right weights [nondim]}}
\DoxyCodeLine{374 \textcolor{keywordtype}{  real} :: intz(5)    \textcolor{comment}{! The gravitational acceleration times the integrals of density}}
\DoxyCodeLine{375                      \textcolor{comment}{! with height at the 5 sub-\/column locations [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{376 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_90 = 1.0/90.0  \textcolor{comment}{! A rational constant [nondim]}}
\DoxyCodeLine{377 \textcolor{keywordtype}{  real} :: GxRho      \textcolor{comment}{! The gravitational acceleration times density and unit conversion factors [Pa Z-\/1 ~> kg m-\/2 s-\/2]}}
\DoxyCodeLine{378 \textcolor{keywordtype}{  real} :: I\_Rho      \textcolor{comment}{! The inverse of the Boussinesq density [R-\/1 ~> m3 kg-\/1] or [m3 kg-\/1]}}
\DoxyCodeLine{379 \textcolor{keywordtype}{  real} :: rho\_scale  \textcolor{comment}{! A scaling factor for densities from kg m-\/3 to R [R m3 kg-\/1 ~> 1]}}
\DoxyCodeLine{380 \textcolor{keywordtype}{  real} :: rho\_ref\_mks \textcolor{comment}{! The reference density in MKS units, never rescaled from kg m-\/3 [kg m-\/3]}}
\DoxyCodeLine{381 \textcolor{keywordtype}{  real} :: dz(HI\%iscB:HI\%iecB+1)   \textcolor{comment}{! Layer thicknesses at tracer points [Z ~> m]}}
\DoxyCodeLine{382 \textcolor{keywordtype}{  real} :: dz\_x(5,HI\%iscB:HI\%iecB) \textcolor{comment}{! Layer thicknesses along an x-\/line of subrid locations [Z ~> m]}}
\DoxyCodeLine{383 \textcolor{keywordtype}{  real} :: dz\_y(5,HI\%isc:HI\%iec)   \textcolor{comment}{! Layer thicknesses along a y-\/line of subrid locations [Z ~> m]}}
\DoxyCodeLine{384 \textcolor{keywordtype}{  real} :: massWeightToggle          \textcolor{comment}{! A non-\/dimensional toggle factor (0 or 1) [nondim]}}
\DoxyCodeLine{385 \textcolor{keywordtype}{  real} :: Ttl, Tbl, Ttr, Tbr        \textcolor{comment}{! Temperatures at the velocity cell corners [degC]}}
\DoxyCodeLine{386 \textcolor{keywordtype}{  real} :: Stl, Sbl, Str, Sbr        \textcolor{comment}{! Salinities at the velocity cell corners [ppt]}}
\DoxyCodeLine{387 \textcolor{keywordtype}{  real} :: hWght                     \textcolor{comment}{! A topographically limited thicknes weight [Z ~> m]}}
\DoxyCodeLine{388 \textcolor{keywordtype}{  real} :: hL, hR                    \textcolor{comment}{! Thicknesses to the left and right [Z ~> m]}}
\DoxyCodeLine{389 \textcolor{keywordtype}{  real} :: iDenom                    \textcolor{comment}{! The denominator of the thickness weight expressions [Z-\/2 ~> m-\/2]}}
\DoxyCodeLine{390   \textcolor{keywordtype}{logical} :: use\_stanley\_eos \textcolor{comment}{! True is SGS variance fields exist in tv.}}
\DoxyCodeLine{391   \textcolor{keywordtype}{logical} :: use\_varT, use\_varS, use\_covarTS}
\DoxyCodeLine{392   \textcolor{keywordtype}{integer} :: Isq, Ieq, Jsq, Jeq, i, j, m, n}
\DoxyCodeLine{393   \textcolor{keywordtype}{integer} :: pos}
\DoxyCodeLine{394 }
\DoxyCodeLine{395   isq = hi\%IscB ; ieq = hi\%IecB ; jsq = hi\%JscB ; jeq = hi\%JecB}
\DoxyCodeLine{396 }
\DoxyCodeLine{397   rho\_scale = us\%kg\_m3\_to\_R}
\DoxyCodeLine{398   gxrho = us\%RL2\_T2\_to\_Pa * g\_e * rho\_0}
\DoxyCodeLine{399   rho\_ref\_mks = rho\_ref * us\%R\_to\_kg\_m3}
\DoxyCodeLine{400   i\_rho = 1.0 / rho\_0}
\DoxyCodeLine{401   massweighttoggle = 0.}
\DoxyCodeLine{402   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{403     \textcolor{keywordflow}{if} (usemasswghtinterp) massweighttoggle = 1.}
\DoxyCodeLine{404 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{405 }
\DoxyCodeLine{406   use\_vart = \textcolor{keyword}{associated}(tv\%varT)}
\DoxyCodeLine{407   use\_covarts = \textcolor{keyword}{associated}(tv\%covarTS)}
\DoxyCodeLine{408   use\_vars = \textcolor{keyword}{associated}(tv\%varS)}
\DoxyCodeLine{409   use\_stanley\_eos = use\_vart .or. use\_covarts .or. use\_vars}
\DoxyCodeLine{410   t25(:) = 0.}
\DoxyCodeLine{411   ts5(:) = 0.}
\DoxyCodeLine{412   s25(:) = 0.}
\DoxyCodeLine{413   t215(:) = 0.}
\DoxyCodeLine{414   ts15(:) = 0.}
\DoxyCodeLine{415   s215(:) = 0.}
\DoxyCodeLine{416 }
\DoxyCodeLine{417   \textcolor{keywordflow}{do} n = 1, 5}
\DoxyCodeLine{418     wt\_t(n) = 0.25 * real(5-\/n)}
\DoxyCodeLine{419     wt\_b(n) = 1.0 -\/ wt\_t(n)}
\DoxyCodeLine{420 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{421 }
\DoxyCodeLine{422   \textcolor{comment}{! 1. Compute vertical integrals}}
\DoxyCodeLine{423   \textcolor{keywordflow}{do} j=jsq,jeq+1}
\DoxyCodeLine{424     \textcolor{keywordflow}{do} i = isq,ieq+1}
\DoxyCodeLine{425       dz(i) = e(i,j,k) -\/ e(i,j,k+1)}
\DoxyCodeLine{426       \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{427         p5(i*5+n) = -\/gxrho*(e(i,j,k) -\/ 0.25*real(n-\/1)*dz(i))}
\DoxyCodeLine{428         \textcolor{comment}{! Salinity and temperature points are linearly interpolated}}
\DoxyCodeLine{429         s5(i*5+n) = wt\_t(n) * s\_t(i,j,k) + wt\_b(n) * s\_b(i,j,k)}
\DoxyCodeLine{430         t5(i*5+n) = wt\_t(n) * t\_t(i,j,k) + wt\_b(n) * t\_b(i,j,k)}
\DoxyCodeLine{431 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{432       \textcolor{keywordflow}{if} (use\_vart) t25(i*5+1:i*5+5) = tv\%varT(i,j,k)}
\DoxyCodeLine{433       \textcolor{keywordflow}{if} (use\_covarts) ts5(i*5+1:i*5+5) = tv\%covarTS(i,j,k)}
\DoxyCodeLine{434       \textcolor{keywordflow}{if} (use\_vars) s25(i*5+1:i*5+5) = tv\%varS(i,j,k)}
\DoxyCodeLine{435 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{436     \textcolor{keywordflow}{if} (use\_stanley\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{437       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{438         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, t25, ts5, s25, r5, 1, (ieq-\/isq+2)*5, eos, \&}
\DoxyCodeLine{439                                rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{440       \textcolor{keywordflow}{else}}
\DoxyCodeLine{441         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, t25, ts5, s25, r5, 1, (ieq-\/isq+2)*5, eos, \&}
\DoxyCodeLine{442                                rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{443 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{444     \textcolor{keywordflow}{else}}
\DoxyCodeLine{445       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{446         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, (ieq-\/isq+2)*5, eos, rho\_ref=rho\_ref\_mks, \&}
\DoxyCodeLine{447                                scale=rho\_scale)}
\DoxyCodeLine{448       \textcolor{keywordflow}{else}}
\DoxyCodeLine{449         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, (ieq-\/isq+2)*5, eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{450 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{451 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{452 }
\DoxyCodeLine{453     \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{454     \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{455       rho\_anom = c1\_90*(7.0*(r5(i*5+1)+r5(i*5+5)) + 32.0*(r5(i*5+2)+r5(i*5+4)) + 12.0*r5(i*5+3))}
\DoxyCodeLine{456       dpa(i,j) = g\_e*dz(i)*rho\_anom}
\DoxyCodeLine{457       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intz\_dpa)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{458       \textcolor{comment}{! Use a Boole's-\/rule-\/like fifth-\/order accurate estimate of}}
\DoxyCodeLine{459       \textcolor{comment}{! the double integral of the pressure anomaly.}}
\DoxyCodeLine{460         intz\_dpa(i,j) = 0.5*g\_e*dz(i)**2 * \&}
\DoxyCodeLine{461                 (rho\_anom -\/ c1\_90*(16.0*(r5(i*5+4)-\/r5(i*5+2)) + 7.0*(r5(i*5+5)-\/r5(i*5+1))) )}
\DoxyCodeLine{462 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{463 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{464 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end loops on j}}
\DoxyCodeLine{465 }
\DoxyCodeLine{466   \textcolor{comment}{! 2. Compute horizontal integrals in the x direction}}
\DoxyCodeLine{467   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=hi\%jsc,hi\%jec}
\DoxyCodeLine{468     \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{469       \textcolor{comment}{! Corner values of T and S}}
\DoxyCodeLine{470       \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{471       \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation}}
\DoxyCodeLine{472       \textcolor{comment}{! of T,S along the top and bottom integrals, almost like thickness}}
\DoxyCodeLine{473       \textcolor{comment}{! weighting.}}
\DoxyCodeLine{474       \textcolor{comment}{! Note: To work in terrain following coordinates we could offset}}
\DoxyCodeLine{475       \textcolor{comment}{! this distance by the layer thickness to replicate other models.}}
\DoxyCodeLine{476       hwght = massweighttoggle * \&}
\DoxyCodeLine{477               max(0., -\/bathyt(i,j)-\/e(i+1,j,k), -\/bathyt(i+1,j)-\/e(i,j,k))}
\DoxyCodeLine{478       \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{479         hl = (e(i,j,k) -\/ e(i,j,k+1)) + dz\_subroundoff}
\DoxyCodeLine{480         hr = (e(i+1,j,k) -\/ e(i+1,j,k+1)) + dz\_subroundoff}
\DoxyCodeLine{481         hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{482         idenom = 1./( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{483         ttl = ( (hwght*hr)*t\_t(i+1,j,k) + (hwght*hl + hr*hl)*t\_t(i,j,k) ) * idenom}
\DoxyCodeLine{484         ttr = ( (hwght*hl)*t\_t(i,j,k) + (hwght*hr + hr*hl)*t\_t(i+1,j,k) ) * idenom}
\DoxyCodeLine{485         tbl = ( (hwght*hr)*t\_b(i+1,j,k) + (hwght*hl + hr*hl)*t\_b(i,j,k) ) * idenom}
\DoxyCodeLine{486         tbr = ( (hwght*hl)*t\_b(i,j,k) + (hwght*hr + hr*hl)*t\_b(i+1,j,k) ) * idenom}
\DoxyCodeLine{487         stl = ( (hwght*hr)*s\_t(i+1,j,k) + (hwght*hl + hr*hl)*s\_t(i,j,k) ) * idenom}
\DoxyCodeLine{488         str = ( (hwght*hl)*s\_t(i,j,k) + (hwght*hr + hr*hl)*s\_t(i+1,j,k) ) * idenom}
\DoxyCodeLine{489         sbl = ( (hwght*hr)*s\_b(i+1,j,k) + (hwght*hl + hr*hl)*s\_b(i,j,k) ) * idenom}
\DoxyCodeLine{490         sbr = ( (hwght*hl)*s\_b(i,j,k) + (hwght*hr + hr*hl)*s\_b(i+1,j,k) ) * idenom}
\DoxyCodeLine{491       \textcolor{keywordflow}{else}}
\DoxyCodeLine{492         ttl = t\_t(i,j,k); tbl = t\_b(i,j,k); ttr = t\_t(i+1,j,k); tbr = t\_b(i+1,j,k)}
\DoxyCodeLine{493         stl = s\_t(i,j,k); sbl = s\_b(i,j,k); str = s\_t(i+1,j,k); sbr = s\_b(i+1,j,k)}
\DoxyCodeLine{494 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{495 }
\DoxyCodeLine{496       \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{497         w\_left = wt\_t(m) ; w\_right = wt\_b(m)}
\DoxyCodeLine{498         dz\_x(m,i) = w\_left*(e(i,j,k) -\/ e(i,j,k+1)) + w\_right*(e(i+1,j,k) -\/ e(i+1,j,k+1))}
\DoxyCodeLine{499 }
\DoxyCodeLine{500         \textcolor{comment}{! Salinity and temperature points are linearly interpolated in}}
\DoxyCodeLine{501         \textcolor{comment}{! the horizontal. The subscript (1) refers to the top value in}}
\DoxyCodeLine{502         \textcolor{comment}{! the vertical profile while subscript (5) refers to the bottom}}
\DoxyCodeLine{503         \textcolor{comment}{! value in the vertical profile.}}
\DoxyCodeLine{504         pos = i*15+(m-\/2)*5}
\DoxyCodeLine{505         t15(pos+1) = w\_left*ttl + w\_right*ttr}
\DoxyCodeLine{506         t15(pos+5) = w\_left*tbl + w\_right*tbr}
\DoxyCodeLine{507 }
\DoxyCodeLine{508         s15(pos+1) = w\_left*stl + w\_right*str}
\DoxyCodeLine{509         s15(pos+5) = w\_left*sbl + w\_right*sbr}
\DoxyCodeLine{510 }
\DoxyCodeLine{511         p15(pos+1) = -\/gxrho*(w\_left*e(i,j,k) + w\_right*e(i+1,j,k))}
\DoxyCodeLine{512 }
\DoxyCodeLine{513         \textcolor{comment}{! Pressure}}
\DoxyCodeLine{514         \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{515           p15(pos+n) = p15(pos+n-\/1) + gxrho*0.25*dz\_x(m,i)}
\DoxyCodeLine{516 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{517 }
\DoxyCodeLine{518         \textcolor{comment}{! Salinity and temperature (linear interpolation in the vertical)}}
\DoxyCodeLine{519         \textcolor{keywordflow}{do} n=2,4}
\DoxyCodeLine{520           s15(pos+n) = wt\_t(n) * s15(pos+1) + wt\_b(n) * s15(pos+5)}
\DoxyCodeLine{521           t15(pos+n) = wt\_t(n) * t15(pos+1) + wt\_b(n) * t15(pos+5)}
\DoxyCodeLine{522 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{523         \textcolor{keywordflow}{if} (use\_vart) t215(pos+1:pos+5) = w\_left*tv\%varT(i,j,k) + w\_right*tv\%varT(i+1,j,k)}
\DoxyCodeLine{524         \textcolor{keywordflow}{if} (use\_covarts) ts15(pos+1:pos+5) = w\_left*tv\%covarTS(i,j,k) + w\_right*tv\%covarTS(i+1,j,k)}
\DoxyCodeLine{525         \textcolor{keywordflow}{if} (use\_vars) s215(pos+1:pos+5) = w\_left*tv\%varS(i,j,k) + w\_right*tv\%varS(i+1,j,k)}
\DoxyCodeLine{526 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{527 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{528 }
\DoxyCodeLine{529     \textcolor{keywordflow}{if} (use\_stanley\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{530       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{531         \textcolor{keyword}{call }calculate\_density(t15, s15, p15, t215, ts15, s215, r15, 1, 15*(ieq-\/isq+1), eos, \&}
\DoxyCodeLine{532                                rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{533       \textcolor{keywordflow}{else}}
\DoxyCodeLine{534         \textcolor{keyword}{call }calculate\_density(t15, s15, p15, t215, ts15, s215, r15, 1, 15*(ieq-\/isq+1), eos, \&}
\DoxyCodeLine{535                                rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{536 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{537     \textcolor{keywordflow}{else}}
\DoxyCodeLine{538       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{539         \textcolor{keyword}{call }calculate\_density(t15, s15, p15, r15, 1, 15*(ieq-\/isq+1), eos, rho\_ref=rho\_ref\_mks, \&}
\DoxyCodeLine{540                                scale=rho\_scale)}
\DoxyCodeLine{541       \textcolor{keywordflow}{else}}
\DoxyCodeLine{542         \textcolor{keyword}{call }calculate\_density(t15, s15, p15, r15, 1, 15*(ieq-\/isq+1), eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{543 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{544 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{545 }
\DoxyCodeLine{546     \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{547       intz(1) = dpa(i,j) ; intz(5) = dpa(i+1,j)}
\DoxyCodeLine{548 }
\DoxyCodeLine{549       \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{550       \textcolor{keywordflow}{do} m = 2,4}
\DoxyCodeLine{551         pos = i*15+(m-\/2)*5}
\DoxyCodeLine{552         intz(m) = g\_e*dz\_x(m,i)*( c1\_90*(7.0*(r15(pos+1)+r15(pos+5)) + 32.0*(r15(pos+2)+r15(pos+4)) + \&}
\DoxyCodeLine{553                           12.0*r15(pos+3)))}
\DoxyCodeLine{554 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{555       \textcolor{comment}{! Use Boole's rule to integrate the bottom pressure anomaly values in x.}}
\DoxyCodeLine{556       intx\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + \&}
\DoxyCodeLine{557                              12.0*intz(3))}
\DoxyCodeLine{558 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{559 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{560 }
\DoxyCodeLine{561   \textcolor{comment}{! 3. Compute horizontal integrals in the y direction}}
\DoxyCodeLine{562   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsq,jeq}
\DoxyCodeLine{563     \textcolor{keywordflow}{do} i=hi\%isc,hi\%iec}
\DoxyCodeLine{564     \textcolor{comment}{! Corner values of T and S}}
\DoxyCodeLine{565     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{566     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation}}
\DoxyCodeLine{567     \textcolor{comment}{! of T,S along the top and bottom integrals, almost like thickness}}
\DoxyCodeLine{568     \textcolor{comment}{! weighting.}}
\DoxyCodeLine{569     \textcolor{comment}{! Note: To work in terrain following coordinates we could offset}}
\DoxyCodeLine{570     \textcolor{comment}{! this distance by the layer thickness to replicate other models.}}
\DoxyCodeLine{571       hwght = massweighttoggle * \&}
\DoxyCodeLine{572               max(0., -\/bathyt(i,j)-\/e(i,j+1,k), -\/bathyt(i,j+1)-\/e(i,j,k))}
\DoxyCodeLine{573       \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{574         hl = (e(i,j,k) -\/ e(i,j,k+1)) + dz\_subroundoff}
\DoxyCodeLine{575         hr = (e(i,j+1,k) -\/ e(i,j+1,k+1)) + dz\_subroundoff}
\DoxyCodeLine{576         hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{577         idenom = 1./( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{578         ttl = ( (hwght*hr)*t\_t(i,j+1,k) + (hwght*hl + hr*hl)*t\_t(i,j,k) ) * idenom}
\DoxyCodeLine{579         ttr = ( (hwght*hl)*t\_t(i,j,k) + (hwght*hr + hr*hl)*t\_t(i,j+1,k) ) * idenom}
\DoxyCodeLine{580         tbl = ( (hwght*hr)*t\_b(i,j+1,k) + (hwght*hl + hr*hl)*t\_b(i,j,k) ) * idenom}
\DoxyCodeLine{581         tbr = ( (hwght*hl)*t\_b(i,j,k) + (hwght*hr + hr*hl)*t\_b(i,j+1,k) ) * idenom}
\DoxyCodeLine{582         stl = ( (hwght*hr)*s\_t(i,j+1,k) + (hwght*hl + hr*hl)*s\_t(i,j,k) ) * idenom}
\DoxyCodeLine{583         str = ( (hwght*hl)*s\_t(i,j,k) + (hwght*hr + hr*hl)*s\_t(i,j+1,k) ) * idenom}
\DoxyCodeLine{584         sbl = ( (hwght*hr)*s\_b(i,j+1,k) + (hwght*hl + hr*hl)*s\_b(i,j,k) ) * idenom}
\DoxyCodeLine{585         sbr = ( (hwght*hl)*s\_b(i,j,k) + (hwght*hr + hr*hl)*s\_b(i,j+1,k) ) * idenom}
\DoxyCodeLine{586       \textcolor{keywordflow}{else}}
\DoxyCodeLine{587         ttl = t\_t(i,j,k); tbl = t\_b(i,j,k); ttr = t\_t(i,j+1,k); tbr = t\_b(i,j+1,k)}
\DoxyCodeLine{588         stl = s\_t(i,j,k); sbl = s\_b(i,j,k); str = s\_t(i,j+1,k); sbr = s\_b(i,j+1,k)}
\DoxyCodeLine{589 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{590 }
\DoxyCodeLine{591       \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{592         w\_left = wt\_t(m) ; w\_right = wt\_b(m)}
\DoxyCodeLine{593         dz\_y(m,i) = w\_left*(e(i,j,k) -\/ e(i,j,k+1)) + w\_right*(e(i,j+1,k) -\/ e(i,j+1,k+1))}
\DoxyCodeLine{594 }
\DoxyCodeLine{595         \textcolor{comment}{! Salinity and temperature points are linearly interpolated in}}
\DoxyCodeLine{596         \textcolor{comment}{! the horizontal. The subscript (1) refers to the top value in}}
\DoxyCodeLine{597         \textcolor{comment}{! the vertical profile while subscript (5) refers to the bottom}}
\DoxyCodeLine{598         \textcolor{comment}{! value in the vertical profile.}}
\DoxyCodeLine{599         pos = i*15+(m-\/2)*5}
\DoxyCodeLine{600         t15(pos+1) = w\_left*ttl + w\_right*ttr}
\DoxyCodeLine{601         t15(pos+5) = w\_left*tbl + w\_right*tbr}
\DoxyCodeLine{602 }
\DoxyCodeLine{603         s15(pos+1) = w\_left*stl + w\_right*str}
\DoxyCodeLine{604         s15(pos+5) = w\_left*sbl + w\_right*sbr}
\DoxyCodeLine{605 }
\DoxyCodeLine{606         p15(pos+1) = -\/gxrho*(w\_left*e(i,j,k) + w\_right*e(i,j+1,k))}
\DoxyCodeLine{607 }
\DoxyCodeLine{608         \textcolor{comment}{! Pressure}}
\DoxyCodeLine{609         \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{610           p15(pos+n) = p15(pos+n-\/1) + gxrho*0.25*dz\_y(m,i)}
\DoxyCodeLine{611 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{612 }
\DoxyCodeLine{613         \textcolor{comment}{! Salinity and temperature (linear interpolation in the vertical)}}
\DoxyCodeLine{614         \textcolor{keywordflow}{do} n=2,4}
\DoxyCodeLine{615           s15(pos+n) = wt\_t(n) * s15(pos+1) + wt\_b(n) * s15(pos+5)}
\DoxyCodeLine{616           t15(pos+n) = wt\_t(n) * t15(pos+1) + wt\_b(n) * t15(pos+5)}
\DoxyCodeLine{617 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{618         \textcolor{keywordflow}{if} (use\_vart) t215(pos+1:pos+5) = w\_left*tv\%varT(i,j,k) + w\_right*tv\%varT(i,j+1,k)}
\DoxyCodeLine{619         \textcolor{keywordflow}{if} (use\_covarts) ts15(pos+1:pos+5) = w\_left*tv\%covarTS(i,j,k) + w\_right*tv\%covarTS(i,j+1,k)}
\DoxyCodeLine{620         \textcolor{keywordflow}{if} (use\_vars) s215(pos+1:pos+5) = w\_left*tv\%varS(i,j,k) + w\_right*tv\%varS(i,j+1,k)}
\DoxyCodeLine{621 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{622 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{623 }
\DoxyCodeLine{624     \textcolor{keywordflow}{if} (use\_stanley\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{625       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{626         \textcolor{keyword}{call }calculate\_density(t15(15*hi\%isc+1:), s15(15*hi\%isc+1:), p15(15*hi\%isc+1:), \&}
\DoxyCodeLine{627                                t215(15*hi\%isc+1:), ts15(15*hi\%isc+1:), s215(15*hi\%isc+1:), \&}
\DoxyCodeLine{628                                r15(15*hi\%isc+1:), 1, 15*(hi\%iec-\/hi\%isc+1), eos, \&}
\DoxyCodeLine{629                                rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{630       \textcolor{keywordflow}{else}}
\DoxyCodeLine{631         \textcolor{keyword}{call }calculate\_density(t15(15*hi\%isc+1:), s15(15*hi\%isc+1:), p15(15*hi\%isc+1:), \&}
\DoxyCodeLine{632                                t215(15*hi\%isc+1:), ts15(15*hi\%isc+1:), s215(15*hi\%isc+1:), \&}
\DoxyCodeLine{633                                r15(15*hi\%isc+1:), 1, 15*(hi\%iec-\/hi\%isc+1), eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{634 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{635     \textcolor{keywordflow}{else}}
\DoxyCodeLine{636       \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{637         \textcolor{keyword}{call }calculate\_density(t15(15*hi\%isc+1:), s15(15*hi\%isc+1:), p15(15*hi\%isc+1:), \&}
\DoxyCodeLine{638                                r15(15*hi\%isc+1:), 1, 15*(hi\%iec-\/hi\%isc+1), eos, \&}
\DoxyCodeLine{639                                rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{640       \textcolor{keywordflow}{else}}
\DoxyCodeLine{641         \textcolor{keyword}{call }calculate\_density(t15(15*hi\%isc+1:), s15(15*hi\%isc+1:), p15(15*hi\%isc+1:), \&}
\DoxyCodeLine{642                                r15(15*hi\%isc+1:), 1, 15*(hi\%iec-\/hi\%isc+1), eos, rho\_ref=rho\_ref\_mks)}
\DoxyCodeLine{643 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{644 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{645 }
\DoxyCodeLine{646     \textcolor{keywordflow}{do} i=hi\%isc,hi\%iec}
\DoxyCodeLine{647       intz(1) = dpa(i,j) ; intz(5) = dpa(i,j+1)}
\DoxyCodeLine{648 }
\DoxyCodeLine{649       \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{650       \textcolor{keywordflow}{do} m = 2,4}
\DoxyCodeLine{651         pos = i*15+(m-\/2)*5}
\DoxyCodeLine{652         intz(m) = g\_e*dz\_y(m,i)*( c1\_90*(7.0*(r15(pos+1)+r15(pos+5)) + \&}
\DoxyCodeLine{653                                          32.0*(r15(pos+2)+r15(pos+4)) + \&}
\DoxyCodeLine{654                                          12.0*r15(pos+3)))}
\DoxyCodeLine{655 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{656       \textcolor{comment}{! Use Boole's rule to integrate the values.}}
\DoxyCodeLine{657       inty\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + \&}
\DoxyCodeLine{658                              12.0*intz(3))}
\DoxyCodeLine{659 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{660 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{661 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_a3bf090e5cbb58811b3dd0ee4de80f999}\label{namespacemom__density__integrals_a3bf090e5cbb58811b3dd0ee4de80f999}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_density\_dz\_generic\_ppm@{int\_density\_dz\_generic\_ppm}}
\index{int\_density\_dz\_generic\_ppm@{int\_density\_dz\_generic\_ppm}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_density\_dz\_generic\_ppm()}{int\_density\_dz\_generic\_ppm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+density\+\_\+dz\+\_\+generic\+\_\+ppm (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{k,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi),szk\+\_\+(gv)), intent(in)}]{T\+\_\+t,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi),szk\+\_\+(gv)), intent(in)}]{T\+\_\+b,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi),szk\+\_\+(gv)), intent(in)}]{S\+\_\+t,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi),szk\+\_\+(gv)), intent(in)}]{S\+\_\+b,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi),szk\+\_\+(gv)+1), intent(in)}]{e,  }\item[{real, intent(in)}]{rho\+\_\+ref,  }\item[{real, intent(in)}]{rho\+\_\+0,  }\item[{real, intent(in)}]{G\+\_\+e,  }\item[{real, intent(in)}]{dz\+\_\+subroundoff,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{bathyT,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout)}]{dpa,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intz\+\_\+dpa,  }\item[{real, dimension( hi \%isdb\+: hi \%iedb, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intx\+\_\+dpa,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsdb\+: hi \%jedb), intent(inout), optional}]{inty\+\_\+dpa,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



Compute pressure gradient force integrals for layer \char`\"{}k\char`\"{} and the case where T and S are parabolic profiles. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em k} & Layer index to calculate integrals for \\
\hline
\mbox{\texttt{ in}}  & {\em hi} & Ocean horizontal index structures for the input arrays \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+t} & Potential temperature at the cell top \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+b} & Potential temperature at the cell bottom \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+t} & Salinity at the cell top \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+b} & Salinity at the cell bottom \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em e} & Height of interfaces \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A mean density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is subtracted out to reduce the magnitude of each of the integrals. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+0} & A density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} or \mbox{[}kg m-\/3\mbox{]}, that is used to calculate the pressure (as p$\sim$=-\/z$\ast$rho\+\_\+0$\ast$\+G\+\_\+e) used in the equation of state. \\
\hline
\mbox{\texttt{ in}}  & {\em g\+\_\+e} & The Earth\textquotesingle{}s gravitational acceleration \mbox{[}m s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+subroundoff} & A minuscule thickness change \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em bathyt} & The depth of the bathymetry \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dpa} & The change in the pressure anomaly across the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em intz\+\_\+dpa} & The integral through the thickness of the layer of \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dpa} & The integral in x of the difference between the \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dpa} & The integral in y of the difference between the \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 670 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{670   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: k\textcolor{comment}{   !< Layer index to calculate integrals for}}
\DoxyCodeLine{671   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{  !< Ocean horizontal index structures for the input arrays}}
\DoxyCodeLine{672   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{ !< Vertical grid structure}}
\DoxyCodeLine{673   \textcolor{keywordtype}{type}(thermo\_var\_ptrs), \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{  !< Thermodynamic variables}}
\DoxyCodeLine{674 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{675                         \textcolor{keywordtype}{intent(in)}  :: T\_t\textcolor{comment}{ !< Potential temperature at the cell top [degC]}}
\DoxyCodeLine{676 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{677                         \textcolor{keywordtype}{intent(in)}  :: T\_b\textcolor{comment}{ !< Potential temperature at the cell bottom [degC]}}
\DoxyCodeLine{678 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{679                         \textcolor{keywordtype}{intent(in)}  :: S\_t\textcolor{comment}{ !< Salinity at the cell top [ppt]}}
\DoxyCodeLine{680 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV))}, \&}
\DoxyCodeLine{681                         \textcolor{keywordtype}{intent(in)}  :: S\_b\textcolor{comment}{ !< Salinity at the cell bottom [ppt]}}
\DoxyCodeLine{682 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI),SZK\_(GV)+1)}, \&}
\DoxyCodeLine{683                         \textcolor{keywordtype}{intent(in)}  :: e\textcolor{comment}{   !< Height of interfaces [Z ~> m]}}
\DoxyCodeLine{684 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{ !< A mean density [R ~> kg m-\/3] or [kg m-\/3], that is}}
\DoxyCodeLine{685 \textcolor{comment}{                                           !! subtracted out to reduce the magnitude of each of the integrals.}}
\DoxyCodeLine{686 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_0\textcolor{comment}{ !< A density [R ~> kg m-\/3] or [kg m-\/3], that is used to calculate}}
\DoxyCodeLine{687 \textcolor{comment}{                                           !! the pressure (as p~=-\/z*rho\_0*G\_e) used in the equation of state.}}
\DoxyCodeLine{688 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: G\_e\textcolor{comment}{ !< The Earth's gravitational acceleration [m s-\/2]}}
\DoxyCodeLine{689 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: dz\_subroundoff\textcolor{comment}{ !< A minuscule thickness change [Z ~> m]}}
\DoxyCodeLine{690 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{691                         \textcolor{keywordtype}{intent(in)}  :: bathyT\textcolor{comment}{ !< The depth of the bathymetry [Z ~> m]}}
\DoxyCodeLine{692   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{693   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{694 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{695                         \textcolor{keywordtype}{intent(inout)} :: dpa\textcolor{comment}{ !< The change in the pressure anomaly across the layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{696 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{697               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intz\_dpa\textcolor{comment}{ !< The integral through the thickness of the layer of}}
\DoxyCodeLine{698 \textcolor{comment}{                                           !! the pressure anomaly relative to the anomaly at the}}
\DoxyCodeLine{699 \textcolor{comment}{                                           !! top of the layer [R L2 Z T-\/2 ~> Pa m]}}
\DoxyCodeLine{700 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{701               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dpa\textcolor{comment}{ !< The integral in x of the difference between the}}
\DoxyCodeLine{702 \textcolor{comment}{                                           !! pressure anomaly at the top and bottom of the layer}}
\DoxyCodeLine{703 \textcolor{comment}{                                           !! divided by the x grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{704 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{705               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dpa\textcolor{comment}{ !< The integral in y of the difference between the}}
\DoxyCodeLine{706 \textcolor{comment}{                                           !! pressure anomaly at the top and bottom of the layer}}
\DoxyCodeLine{707 \textcolor{comment}{                                           !! divided by the y grid spacing [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{708   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting to}}
\DoxyCodeLine{709 \textcolor{comment}{                                           !! interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{710 }
\DoxyCodeLine{711 \textcolor{comment}{! This subroutine calculates (by numerical quadrature) integrals of}}
\DoxyCodeLine{712 \textcolor{comment}{! pressure anomalies across layers, which are required for calculating the}}
\DoxyCodeLine{713 \textcolor{comment}{! finite-\/volume form pressure accelerations in a Boussinesq model.  The one}}
\DoxyCodeLine{714 \textcolor{comment}{! potentially dodgy assumption here is that rho\_0 is used both in the denominator}}
\DoxyCodeLine{715 \textcolor{comment}{! of the accelerations, and in the pressure used to calculated density (the}}
\DoxyCodeLine{716 \textcolor{comment}{! latter being -\/z*rho\_0*G\_e).  These two uses could be separated if need be.}}
\DoxyCodeLine{717 \textcolor{comment}{!}}
\DoxyCodeLine{718 \textcolor{comment}{! It is assumed that the salinity and temperature profiles are parabolic in the}}
\DoxyCodeLine{719 \textcolor{comment}{! vertical. The top and bottom values within each layer are provided and}}
\DoxyCodeLine{720 \textcolor{comment}{! a parabolic interpolation is used to compute intermediate values.}}
\DoxyCodeLine{721 }
\DoxyCodeLine{722   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{723 \textcolor{keywordtype}{  real} :: T5(5) \textcolor{comment}{! Temperatures along a line of subgrid locations [degC]}}
\DoxyCodeLine{724 \textcolor{keywordtype}{  real} :: S5(5) \textcolor{comment}{! Salinities along a line of subgrid locations [ppt]}}
\DoxyCodeLine{725 \textcolor{keywordtype}{  real} :: T25(5) \textcolor{comment}{! SGS temperature variance along a line of subgrid locations [degC2]}}
\DoxyCodeLine{726 \textcolor{keywordtype}{  real} :: TS5(5) \textcolor{comment}{! SGS temperature-\/salinity covariance along a line of subgrid locations [degC ppt]}}
\DoxyCodeLine{727 \textcolor{keywordtype}{  real} :: S25(5) \textcolor{comment}{! SGS salinity variance along a line of subgrid locations [ppt2]}}
\DoxyCodeLine{728 \textcolor{keywordtype}{  real} :: p5(5) \textcolor{comment}{! Pressures at five quadrature points, never rescaled from Pa [Pa]}}
\DoxyCodeLine{729 \textcolor{keywordtype}{  real} :: r5(5) \textcolor{comment}{! Density anomalies from rho\_ref at quadrature points [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{730 \textcolor{keywordtype}{  real} :: wt\_t(5), wt\_b(5) \textcolor{comment}{! Top and bottom weights [nondim]}}
\DoxyCodeLine{731 \textcolor{keywordtype}{  real} :: rho\_anom \textcolor{comment}{! The integrated density anomaly [R ~> kg m-\/3] or [kg m-\/3]}}
\DoxyCodeLine{732 \textcolor{keywordtype}{  real} :: w\_left, w\_right  \textcolor{comment}{! Left and right weights [nondim]}}
\DoxyCodeLine{733 \textcolor{keywordtype}{  real} :: intz(5) \textcolor{comment}{! The gravitational acceleration times the integrals of density}}
\DoxyCodeLine{734                   \textcolor{comment}{! with height at the 5 sub-\/column locations [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{735 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_90 = 1.0/90.0  \textcolor{comment}{! Rational constants.}}
\DoxyCodeLine{736 \textcolor{keywordtype}{  real} :: GxRho \textcolor{comment}{! The gravitational acceleration times density and unit conversion factors [Pa Z-\/1 ~> kg m-\/2 s-\/2]}}
\DoxyCodeLine{737 \textcolor{keywordtype}{  real} :: I\_Rho \textcolor{comment}{! The inverse of the Boussinesq density [R-\/1 ~> m3 kg-\/1] or [m3 kg-\/1]}}
\DoxyCodeLine{738 \textcolor{keywordtype}{  real} :: rho\_scale \textcolor{comment}{! A scaling factor for densities from kg m-\/3 to R [R m3 kg-\/1 ~> 1]}}
\DoxyCodeLine{739 \textcolor{keywordtype}{  real} :: rho\_ref\_mks \textcolor{comment}{! The reference density in MKS units, never rescaled from kg m-\/3 [kg m-\/3]}}
\DoxyCodeLine{740 \textcolor{keywordtype}{  real} :: dz \textcolor{comment}{! Layer thicknesses at tracer points [Z ~> m]}}
\DoxyCodeLine{741 \textcolor{keywordtype}{  real} :: massWeightToggle \textcolor{comment}{! A non-\/dimensional toggle factor (0 or 1) [nondim]}}
\DoxyCodeLine{742 \textcolor{keywordtype}{  real} :: Ttl, Tbl, Tml, Ttr, Tbr, Tmr \textcolor{comment}{! Temperatures at the velocity cell corners [degC]}}
\DoxyCodeLine{743 \textcolor{keywordtype}{  real} :: Stl, Sbl, Sml, Str, Sbr, Smr \textcolor{comment}{! Salinities at the velocity cell corners [ppt]}}
\DoxyCodeLine{744 \textcolor{keywordtype}{  real} :: s6 \textcolor{comment}{! PPM curvature coefficient for S [ppt]}}
\DoxyCodeLine{745 \textcolor{keywordtype}{  real} :: t6 \textcolor{comment}{! PPM curvature coefficient for T [degC]}}
\DoxyCodeLine{746 \textcolor{keywordtype}{  real} :: T\_top, T\_mn, T\_bot \textcolor{comment}{! Left edge, cell mean and right edge values used in PPM reconstructions of T}}
\DoxyCodeLine{747 \textcolor{keywordtype}{  real} :: S\_top, S\_mn, S\_bot \textcolor{comment}{! Left edge, cell mean and right edge values used in PPM reconstructions of S}}
\DoxyCodeLine{748 \textcolor{keywordtype}{  real} :: hWght  \textcolor{comment}{! A topographically limited thicknes weight [Z ~> m]}}
\DoxyCodeLine{749 \textcolor{keywordtype}{  real} :: hL, hR \textcolor{comment}{! Thicknesses to the left and right [Z ~> m]}}
\DoxyCodeLine{750 \textcolor{keywordtype}{  real} :: iDenom \textcolor{comment}{! The denominator of the thickness weight expressions [Z-\/2 ~> m-\/2]}}
\DoxyCodeLine{751   \textcolor{keywordtype}{integer} :: Isq, Ieq, Jsq, Jeq, i, j, m, n}
\DoxyCodeLine{752   \textcolor{keywordtype}{logical} :: use\_PPM \textcolor{comment}{! If false, assume zero curvature in reconstruction, i.e. PLM}}
\DoxyCodeLine{753   \textcolor{keywordtype}{logical} :: use\_stanley\_eos \textcolor{comment}{! True is SGS variance fields exist in tv.}}
\DoxyCodeLine{754   \textcolor{keywordtype}{logical} :: use\_varT, use\_varS, use\_covarTS}
\DoxyCodeLine{755 }
\DoxyCodeLine{756   isq = hi\%IscB ; ieq = hi\%IecB ; jsq = hi\%JscB ; jeq = hi\%JecB}
\DoxyCodeLine{757 }
\DoxyCodeLine{758   rho\_scale = us\%kg\_m3\_to\_R}
\DoxyCodeLine{759   gxrho = us\%RL2\_T2\_to\_Pa * g\_e * rho\_0}
\DoxyCodeLine{760   rho\_ref\_mks = rho\_ref * us\%R\_to\_kg\_m3}
\DoxyCodeLine{761   i\_rho = 1.0 / rho\_0}
\DoxyCodeLine{762   massweighttoggle = 0.}
\DoxyCodeLine{763   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{764     \textcolor{keywordflow}{if} (usemasswghtinterp) massweighttoggle = 1.}
\DoxyCodeLine{765 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{766 }
\DoxyCodeLine{767   \textcolor{comment}{! In event PPM calculation is bypassed with use\_PPM=False}}
\DoxyCodeLine{768   s6 = 0.}
\DoxyCodeLine{769   t6 = 0.}
\DoxyCodeLine{770   use\_ppm = .true. \textcolor{comment}{! This is a place-\/holder to allow later re-\/use of this function}}
\DoxyCodeLine{771 }
\DoxyCodeLine{772   use\_vart = \textcolor{keyword}{associated}(tv\%varT)}
\DoxyCodeLine{773   use\_covarts = \textcolor{keyword}{associated}(tv\%covarTS)}
\DoxyCodeLine{774   use\_vars = \textcolor{keyword}{associated}(tv\%varS)}
\DoxyCodeLine{775   use\_stanley\_eos = use\_vart .or. use\_covarts .or. use\_vars}
\DoxyCodeLine{776   t25(:) = 0.}
\DoxyCodeLine{777   ts5(:) = 0.}
\DoxyCodeLine{778   s25(:) = 0.}
\DoxyCodeLine{779 }
\DoxyCodeLine{780   \textcolor{keywordflow}{do} n = 1, 5}
\DoxyCodeLine{781     wt\_t(n) = 0.25 * real(5-\/n)}
\DoxyCodeLine{782     wt\_b(n) = 1.0 -\/ wt\_t(n)}
\DoxyCodeLine{783 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{784 }
\DoxyCodeLine{785   \textcolor{comment}{! 1. Compute vertical integrals}}
\DoxyCodeLine{786   \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{787     \textcolor{keywordflow}{if} (use\_ppm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{788       \textcolor{comment}{! Curvature coefficient of the parabolas}}
\DoxyCodeLine{789       s6 = 3.0 * ( 2.0*tv\%S(i,j,k) -\/ ( s\_t(i,j,k) + s\_b(i,j,k) ) )}
\DoxyCodeLine{790       t6 = 3.0 * ( 2.0*tv\%T(i,j,k) -\/ ( t\_t(i,j,k) + t\_b(i,j,k) ) )}
\DoxyCodeLine{791 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{792     dz = e(i,j,k) -\/ e(i,j,k+1)}
\DoxyCodeLine{793     \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{794       p5(n) = -\/gxrho*(e(i,j,k) -\/ 0.25*real(n-\/1)*dz)}
\DoxyCodeLine{795       \textcolor{comment}{! Salinity and temperature points are reconstructed with PPM}}
\DoxyCodeLine{796       s5(n) = wt\_t(n) * s\_t(i,j,k) + wt\_b(n) * ( s\_b(i,j,k) + s6 * wt\_t(n) )}
\DoxyCodeLine{797       t5(n) = wt\_t(n) * t\_t(i,j,k) + wt\_b(n) * ( t\_b(i,j,k) + t6 * wt\_t(n) )}
\DoxyCodeLine{798 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{799     \textcolor{keywordflow}{if} (use\_stanley\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{800       \textcolor{keywordflow}{if} (use\_vart) t25(:) = tv\%varT(i,j,k)}
\DoxyCodeLine{801       \textcolor{keywordflow}{if} (use\_covarts) ts5(:) = tv\%covarTS(i,j,k)}
\DoxyCodeLine{802       \textcolor{keywordflow}{if} (use\_vars) s25(:) = tv\%varS(i,j,k)}
\DoxyCodeLine{803       \textcolor{keyword}{call }calculate\_density(t5, s5, p5, t25, ts5, s25, r5, \&}
\DoxyCodeLine{804                              1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{805     \textcolor{keywordflow}{else}}
\DoxyCodeLine{806       \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{807 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{808 }
\DoxyCodeLine{809     \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{810     rho\_anom = c1\_90*(7.0*(r5(1)+r5(5)) + 32.0*(r5(2)+r5(4)) + 12.0*r5(3))}
\DoxyCodeLine{811     dpa(i,j) = g\_e*dz*rho\_anom}
\DoxyCodeLine{812     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intz\_dpa)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{813       \textcolor{comment}{! Use a Boole's-\/rule-\/like fifth-\/order accurate estimate of}}
\DoxyCodeLine{814       \textcolor{comment}{! the double integral of the pressure anomaly.}}
\DoxyCodeLine{815       intz\_dpa(i,j) = 0.5*g\_e*dz**2 * \&}
\DoxyCodeLine{816                       (rho\_anom -\/ c1\_90*(16.0*(r5(4)-\/r5(2)) + 7.0*(r5(5)-\/r5(1))) )}
\DoxyCodeLine{817 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{818 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! end loops on j and i}}
\DoxyCodeLine{819 }
\DoxyCodeLine{820   \textcolor{comment}{! 2. Compute horizontal integrals in the x direction}}
\DoxyCodeLine{821   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=hi\%jsc,hi\%jec ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{822     \textcolor{comment}{! Corner values of T and S}}
\DoxyCodeLine{823     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{824     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation}}
\DoxyCodeLine{825     \textcolor{comment}{! of T,S along the top and bottom integrals, almost like thickness}}
\DoxyCodeLine{826     \textcolor{comment}{! weighting.}}
\DoxyCodeLine{827     \textcolor{comment}{! Note: To work in terrain following coordinates we could offset}}
\DoxyCodeLine{828     \textcolor{comment}{! this distance by the layer thickness to replicate other models.}}
\DoxyCodeLine{829     hwght = massweighttoggle * \&}
\DoxyCodeLine{830             max(0., -\/bathyt(i,j)-\/e(i+1,j,k), -\/bathyt(i+1,j)-\/e(i,j,k))}
\DoxyCodeLine{831     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{832       hl = (e(i,j,k) -\/ e(i,j,k+1)) + dz\_subroundoff}
\DoxyCodeLine{833       hr = (e(i+1,j,k) -\/ e(i+1,j,k+1)) + dz\_subroundoff}
\DoxyCodeLine{834       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{835       idenom = 1./( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{836       ttl = ( (hwght*hr)*t\_t(i+1,j,k) + (hwght*hl + hr*hl)*t\_t(i,j,k) ) * idenom}
\DoxyCodeLine{837       tbl = ( (hwght*hr)*t\_b(i+1,j,k) + (hwght*hl + hr*hl)*t\_b(i,j,k) ) * idenom}
\DoxyCodeLine{838       tml = ( (hwght*hr)*tv\%T(i+1,j,k)+ (hwght*hl + hr*hl)*tv\%T(i,j,k) ) * idenom}
\DoxyCodeLine{839       ttr = ( (hwght*hl)*t\_t(i,j,k) + (hwght*hr + hr*hl)*t\_t(i+1,j,k) ) * idenom}
\DoxyCodeLine{840       tbr = ( (hwght*hl)*t\_b(i,j,k) + (hwght*hr + hr*hl)*t\_b(i+1,j,k) ) * idenom}
\DoxyCodeLine{841       tmr = ( (hwght*hl)*tv\%T(i,j,k) + (hwght*hr + hr*hl)*tv\%T(i+1,j,k) ) * idenom}
\DoxyCodeLine{842       stl = ( (hwght*hr)*s\_t(i+1,j,k) + (hwght*hl + hr*hl)*s\_t(i,j,k) ) * idenom}
\DoxyCodeLine{843       sbl = ( (hwght*hr)*s\_b(i+1,j,k) + (hwght*hl + hr*hl)*s\_b(i,j,k) ) * idenom}
\DoxyCodeLine{844       sml = ( (hwght*hr)*tv\%S(i+1,j,k) + (hwght*hl + hr*hl)*tv\%S(i,j,k) ) * idenom}
\DoxyCodeLine{845       str = ( (hwght*hl)*s\_t(i,j,k) + (hwght*hr + hr*hl)*s\_t(i+1,j,k) ) * idenom}
\DoxyCodeLine{846       sbr = ( (hwght*hl)*s\_b(i,j,k) + (hwght*hr + hr*hl)*s\_b(i+1,j,k) ) * idenom}
\DoxyCodeLine{847       smr = ( (hwght*hl)*tv\%S(i,j,k) + (hwght*hr + hr*hl)*tv\%S(i+1,j,k) ) * idenom}
\DoxyCodeLine{848     \textcolor{keywordflow}{else}}
\DoxyCodeLine{849       ttl = t\_t(i,j,k); tbl = t\_b(i,j,k); ttr = t\_t(i+1,j,k); tbr = t\_b(i+1,j,k)}
\DoxyCodeLine{850       tml = tv\%T(i,j,k); tmr = tv\%T(i+1,j,k)}
\DoxyCodeLine{851       stl = s\_t(i,j,k); sbl = s\_b(i,j,k); str = s\_t(i+1,j,k); sbr = s\_b(i+1,j,k)}
\DoxyCodeLine{852       sml = tv\%S(i,j,k); smr = tv\%S(i+1,j,k)}
\DoxyCodeLine{853 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{854 }
\DoxyCodeLine{855     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{856       w\_left = wt\_t(m) ; w\_right = wt\_b(m)}
\DoxyCodeLine{857 }
\DoxyCodeLine{858       \textcolor{comment}{! Salinity and temperature points are linearly interpolated in}}
\DoxyCodeLine{859       \textcolor{comment}{! the horizontal. The subscript (1) refers to the top value in}}
\DoxyCodeLine{860       \textcolor{comment}{! the vertical profile while subscript (5) refers to the bottom}}
\DoxyCodeLine{861       \textcolor{comment}{! value in the vertical profile.}}
\DoxyCodeLine{862       t\_top = w\_left*ttl + w\_right*ttr}
\DoxyCodeLine{863       t\_mn = w\_left*tml + w\_right*tmr}
\DoxyCodeLine{864       t\_bot = w\_left*tbl + w\_right*tbr}
\DoxyCodeLine{865 }
\DoxyCodeLine{866       s\_top = w\_left*stl + w\_right*str}
\DoxyCodeLine{867       s\_mn = w\_left*sml + w\_right*smr}
\DoxyCodeLine{868       s\_bot = w\_left*sbl + w\_right*sbr}
\DoxyCodeLine{869 }
\DoxyCodeLine{870       \textcolor{comment}{! Pressure}}
\DoxyCodeLine{871       dz = w\_left*(e(i,j,k) -\/ e(i,j,k+1)) + w\_right*(e(i+1,j,k) -\/ e(i+1,j,k+1))}
\DoxyCodeLine{872       p5(1) = -\/gxrho*(w\_left*e(i,j,k) + w\_right*e(i+1,j,k))}
\DoxyCodeLine{873       \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{874         p5(n) = p5(n-\/1) + gxrho*0.25*dz}
\DoxyCodeLine{875 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{876 }
\DoxyCodeLine{877       \textcolor{comment}{! Parabolic reconstructions in the vertical for T and S}}
\DoxyCodeLine{878       \textcolor{keywordflow}{if} (use\_ppm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{879         \textcolor{comment}{! Coefficients of the parabolas}}
\DoxyCodeLine{880         s6 = 3.0 * ( 2.0*s\_mn -\/ ( s\_top + s\_bot ) )}
\DoxyCodeLine{881         t6 = 3.0 * ( 2.0*t\_mn -\/ ( t\_top + t\_bot ) )}
\DoxyCodeLine{882 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{883       \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{884         s5(n) = wt\_t(n) * s\_top + wt\_b(n) * ( s\_bot + s6 * wt\_t(n) )}
\DoxyCodeLine{885         t5(n) = wt\_t(n) * t\_top + wt\_b(n) * ( t\_bot + t6 * wt\_t(n) )}
\DoxyCodeLine{886 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{887 }
\DoxyCodeLine{888       \textcolor{keywordflow}{if} (use\_stanley\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{889         \textcolor{keywordflow}{if} (use\_vart) t25(:) = w\_left*tv\%varT(i,j,k) + w\_right*tv\%varT(i+1,j,k)}
\DoxyCodeLine{890         \textcolor{keywordflow}{if} (use\_covarts) ts5(:) = w\_left*tv\%covarTS(i,j,k) + w\_right*tv\%covarTS(i+1,j,k)}
\DoxyCodeLine{891         \textcolor{keywordflow}{if} (use\_vars) s25(:) = w\_left*tv\%varS(i,j,k) + w\_right*tv\%varS(i+1,j,k)}
\DoxyCodeLine{892         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, t25, ts5, s25, r5, \&}
\DoxyCodeLine{893                                1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{894       \textcolor{keywordflow}{else}}
\DoxyCodeLine{895         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{896 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{897 }
\DoxyCodeLine{898       \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{899       intz(m) = g\_e*dz*( c1\_90*(7.0*(r5(1)+r5(5)) + 32.0*(r5(2)+r5(4)) + 12.0*r5(3)) )}
\DoxyCodeLine{900 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! m}}
\DoxyCodeLine{901     intz(1) = dpa(i,j) ; intz(5) = dpa(i+1,j)}
\DoxyCodeLine{902 }
\DoxyCodeLine{903     \textcolor{comment}{! Use Boole's rule to integrate the bottom pressure anomaly values in x.}}
\DoxyCodeLine{904     intx\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + 12.0*intz(3))}
\DoxyCodeLine{905 }
\DoxyCodeLine{906 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{907 }
\DoxyCodeLine{908   \textcolor{comment}{! 3. Compute horizontal integrals in the y direction}}
\DoxyCodeLine{909   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=hi\%isc,hi\%iec}
\DoxyCodeLine{910     \textcolor{comment}{! Corner values of T and S}}
\DoxyCodeLine{911     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{912     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation}}
\DoxyCodeLine{913     \textcolor{comment}{! of T,S along the top and bottom integrals, almost like thickness}}
\DoxyCodeLine{914     \textcolor{comment}{! weighting.}}
\DoxyCodeLine{915     \textcolor{comment}{! Note: To work in terrain following coordinates we could offset}}
\DoxyCodeLine{916     \textcolor{comment}{! this distance by the layer thickness to replicate other models.}}
\DoxyCodeLine{917     hwght = massweighttoggle * \&}
\DoxyCodeLine{918             max(0., -\/bathyt(i,j)-\/e(i,j+1,k), -\/bathyt(i,j+1)-\/e(i,j,k))}
\DoxyCodeLine{919     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{920       hl = (e(i,j,k) -\/ e(i,j,k+1)) + dz\_subroundoff}
\DoxyCodeLine{921       hr = (e(i,j+1,k) -\/ e(i,j+1,k+1)) + dz\_subroundoff}
\DoxyCodeLine{922       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{923       idenom = 1./( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{924       ttl = ( (hwght*hr)*t\_t(i,j+1,k) + (hwght*hl + hr*hl)*t\_t(i,j,k) ) * idenom}
\DoxyCodeLine{925       tbl = ( (hwght*hr)*t\_b(i,j+1,k) + (hwght*hl + hr*hl)*t\_b(i,j,k) ) * idenom}
\DoxyCodeLine{926       tml = ( (hwght*hr)*tv\%T(i,j+1,k)+ (hwght*hl + hr*hl)*tv\%T(i,j,k) ) * idenom}
\DoxyCodeLine{927       ttr = ( (hwght*hl)*t\_t(i,j,k) + (hwght*hr + hr*hl)*t\_t(i,j+1,k) ) * idenom}
\DoxyCodeLine{928       tbr = ( (hwght*hl)*t\_b(i,j,k) + (hwght*hr + hr*hl)*t\_b(i,j+1,k) ) * idenom}
\DoxyCodeLine{929       tmr = ( (hwght*hl)*tv\%T(i,j,k) + (hwght*hr + hr*hl)*tv\%T(i,j+1,k) ) * idenom}
\DoxyCodeLine{930       stl = ( (hwght*hr)*s\_t(i,j+1,k) + (hwght*hl + hr*hl)*s\_t(i,j,k) ) * idenom}
\DoxyCodeLine{931       sbl = ( (hwght*hr)*s\_b(i,j+1,k) + (hwght*hl + hr*hl)*s\_b(i,j,k) ) * idenom}
\DoxyCodeLine{932       sml = ( (hwght*hr)*tv\%S(i,j+1,k)+ (hwght*hl + hr*hl)*tv\%S(i,j,k) ) * idenom}
\DoxyCodeLine{933       str = ( (hwght*hl)*s\_t(i,j,k) + (hwght*hr + hr*hl)*s\_t(i,j+1,k) ) * idenom}
\DoxyCodeLine{934       sbr = ( (hwght*hl)*s\_b(i,j,k) + (hwght*hr + hr*hl)*s\_b(i,j+1,k) ) * idenom}
\DoxyCodeLine{935       smr = ( (hwght*hl)*tv\%S(i,j,k) + (hwght*hr + hr*hl)*tv\%S(i,j+1,k) ) * idenom}
\DoxyCodeLine{936     \textcolor{keywordflow}{else}}
\DoxyCodeLine{937       ttl = t\_t(i,j,k); tbl = t\_b(i,j,k); ttr = t\_t(i,j+1,k); tbr = t\_b(i,j+1,k)}
\DoxyCodeLine{938       tml = tv\%T(i,j,k); tmr = tv\%T(i,j+1,k)}
\DoxyCodeLine{939       stl = s\_t(i,j,k); sbl = s\_b(i,j,k); str = s\_t(i,j+1,k); sbr = s\_b(i,j+1,k)}
\DoxyCodeLine{940       sml = tv\%S(i,j,k); smr = tv\%S(i,j+1,k)}
\DoxyCodeLine{941 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{942 }
\DoxyCodeLine{943     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{944       w\_left = wt\_t(m) ; w\_right = wt\_b(m)}
\DoxyCodeLine{945 }
\DoxyCodeLine{946       \textcolor{comment}{! Salinity and temperature points are linearly interpolated in}}
\DoxyCodeLine{947       \textcolor{comment}{! the horizontal. The subscript (1) refers to the top value in}}
\DoxyCodeLine{948       \textcolor{comment}{! the vertical profile while subscript (5) refers to the bottom}}
\DoxyCodeLine{949       \textcolor{comment}{! value in the vertical profile.}}
\DoxyCodeLine{950       t\_top = w\_left*ttl + w\_right*ttr}
\DoxyCodeLine{951       t\_mn = w\_left*tml + w\_right*tmr}
\DoxyCodeLine{952       t\_bot = w\_left*tbl + w\_right*tbr}
\DoxyCodeLine{953 }
\DoxyCodeLine{954       s\_top = w\_left*stl + w\_right*str}
\DoxyCodeLine{955       s\_mn = w\_left*sml + w\_right*smr}
\DoxyCodeLine{956       s\_bot = w\_left*sbl + w\_right*sbr}
\DoxyCodeLine{957 }
\DoxyCodeLine{958       \textcolor{comment}{! Pressure}}
\DoxyCodeLine{959       dz = w\_left*(e(i,j,k) -\/ e(i,j,k+1)) + w\_right*(e(i,j+1,k) -\/ e(i,j+1,k+1))}
\DoxyCodeLine{960       p5(1) = -\/gxrho*(w\_left*e(i,j,k) + w\_right*e(i,j+1,k))}
\DoxyCodeLine{961       \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{962         p5(n) = p5(n-\/1) + gxrho*0.25*dz}
\DoxyCodeLine{963 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{964 }
\DoxyCodeLine{965       \textcolor{comment}{! Parabolic reconstructions in the vertical for T and S}}
\DoxyCodeLine{966       \textcolor{keywordflow}{if} (use\_ppm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{967         \textcolor{comment}{! Coefficients of the parabolas}}
\DoxyCodeLine{968         s6 = 3.0 * ( 2.0*s\_mn -\/ ( s\_top + s\_bot ) )}
\DoxyCodeLine{969         t6 = 3.0 * ( 2.0*t\_mn -\/ ( t\_top + t\_bot ) )}
\DoxyCodeLine{970 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{971       \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{972         s5(n) = wt\_t(n) * s\_top + wt\_b(n) * ( s\_bot + s6 * wt\_t(n) )}
\DoxyCodeLine{973         t5(n) = wt\_t(n) * t\_top + wt\_b(n) * ( t\_bot + t6 * wt\_t(n) )}
\DoxyCodeLine{974 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{975 }
\DoxyCodeLine{976       \textcolor{keywordflow}{if} (use\_stanley\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{977         \textcolor{keywordflow}{if} (use\_vart) t25(:) = w\_left*tv\%varT(i,j,k) + w\_right*tv\%varT(i,j+1,k)}
\DoxyCodeLine{978         \textcolor{keywordflow}{if} (use\_covarts) ts5(:) = w\_left*tv\%covarTS(i,j,k) + w\_right*tv\%covarTS(i,j+1,k)}
\DoxyCodeLine{979         \textcolor{keywordflow}{if} (use\_vars) s25(:) = w\_left*tv\%varS(i,j,k) + w\_right*tv\%varS(i,j+1,k)}
\DoxyCodeLine{980         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, t25, ts5, s25, r5, \&}
\DoxyCodeLine{981                                1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{982       \textcolor{keywordflow}{else}}
\DoxyCodeLine{983         \textcolor{keyword}{call }calculate\_density(t5, s5, p5, r5, 1, 5, eos, rho\_ref=rho\_ref\_mks, scale=rho\_scale)}
\DoxyCodeLine{984 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{985 }
\DoxyCodeLine{986       \textcolor{comment}{! Use Boole's rule to estimate the pressure anomaly change.}}
\DoxyCodeLine{987       intz(m) = g\_e*dz*( c1\_90*(7.0*(r5(1)+r5(5)) + 32.0*(r5(2)+r5(4)) + 12.0*r5(3)) )}
\DoxyCodeLine{988 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! m}}
\DoxyCodeLine{989     intz(1) = dpa(i,j) ; intz(5) = dpa(i,j+1)}
\DoxyCodeLine{990 }
\DoxyCodeLine{991     \textcolor{comment}{! Use Boole's rule to integrate the bottom pressure anomaly values in y.}}
\DoxyCodeLine{992     inty\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + 12.0*intz(3))}
\DoxyCodeLine{993 }
\DoxyCodeLine{994 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{995 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_a86ebdfebaaea2ac0339dcabed482dd11}\label{namespacemom__density__integrals_a86ebdfebaaea2ac0339dcabed482dd11}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_spec\_vol\_dp\_generic\_pcm@{int\_spec\_vol\_dp\_generic\_pcm}}
\index{int\_spec\_vol\_dp\_generic\_pcm@{int\_spec\_vol\_dp\_generic\_pcm}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_spec\_vol\_dp\_generic\_pcm()}{int\_spec\_vol\_dp\_generic\_pcm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+generic\+\_\+pcm (\begin{DoxyParamCaption}\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{T,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{S,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{p\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{p\+\_\+b,  }\item[{real, intent(in)}]{alpha\+\_\+ref,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout)}]{dza,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intp\+\_\+dza,  }\item[{real, dimension( hi \%isdb\+: hi \%iedb, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intx\+\_\+dza,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsdb\+: hi \%jedb), intent(inout), optional}]{inty\+\_\+dza,  }\item[{integer, intent(in), optional}]{halo\+\_\+size,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in), optional}]{bathyP,  }\item[{real, intent(in), optional}]{d\+P\+\_\+neglect,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



This subroutine calculates integrals of specific volume anomalies in pressure across layers, which are required for calculating the finite-\/volume form pressure accelerations in a non-\/\+Boussinesq model. There are essentially no free assumptions, apart from the use of Boole\textquotesingle{}s rule quadrature to do the integrals. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & A horizontal index type structure. \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Potential temperature of the layer \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity of the layer \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+t} & Pressure atop the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+b} & Pressure below the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em alpha\+\_\+ref} & A mean specific volume that is subtracted out to reduce the magnitude of each of the integrals \mbox{[}R-\/1 $\sim$$>$ m3 kg-\/1\mbox{]} The calculation is mathematically identical with different values of alpha\+\_\+ref, but alpha\+\_\+ref alters the effects of roundoff, and answers do change. \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dza} & The change in the geopotential anomaly \\
\hline
\mbox{\texttt{ in,out}}  & {\em intp\+\_\+dza} & The integral in pressure through the layer of \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dza} & The integral in x of the difference between \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dza} & The integral in y of the difference between \\
\hline
\mbox{\texttt{ in}}  & {\em halo\+\_\+size} & The width of halo points on which to calculate dza. \\
\hline
\mbox{\texttt{ in}}  & {\em bathyp} & The pressure at the bathymetry \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dp\+\_\+neglect} & A minuscule pressure change with the same units as p\+\_\+t \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 1065 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1065   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{ !< A horizontal index type structure.}}
\DoxyCodeLine{1066 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1067                         \textcolor{keywordtype}{intent(in)}  :: T\textcolor{comment}{  !< Potential temperature of the layer [degC]}}
\DoxyCodeLine{1068 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1069                         \textcolor{keywordtype}{intent(in)}  :: S\textcolor{comment}{  !< Salinity of the layer [ppt]}}
\DoxyCodeLine{1070 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1071                         \textcolor{keywordtype}{intent(in)}  :: p\_t\textcolor{comment}{ !< Pressure atop the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1072 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1073                         \textcolor{keywordtype}{intent(in)}  :: p\_b\textcolor{comment}{ !< Pressure below the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1074 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: alpha\_ref\textcolor{comment}{ !< A mean specific volume that is subtracted out}}
\DoxyCodeLine{1075 \textcolor{comment}{                            !! to reduce the magnitude of each of the integrals [R-\/1 ~> m3 kg-\/1]}}
\DoxyCodeLine{1076 \textcolor{comment}{                            !! The calculation is mathematically identical with different values of}}
\DoxyCodeLine{1077 \textcolor{comment}{                            !! alpha\_ref, but alpha\_ref alters the effects of roundoff, and}}
\DoxyCodeLine{1078 \textcolor{comment}{                            !! answers do change.}}
\DoxyCodeLine{1079   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{1080   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1081 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1082                         \textcolor{keywordtype}{intent(inout)} :: dza\textcolor{comment}{ !< The change in the geopotential anomaly}}
\DoxyCodeLine{1083 \textcolor{comment}{                            !! across the layer [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1084 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1085               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intp\_dza\textcolor{comment}{ !< The integral in pressure through the layer of}}
\DoxyCodeLine{1086 \textcolor{comment}{                            !! the geopotential anomaly relative to the anomaly at the bottom of the}}
\DoxyCodeLine{1087 \textcolor{comment}{                            !! layer [R L4 T-\/4 ~> Pa m2 s-\/2] or [Pa m2 s-\/2]}}
\DoxyCodeLine{1088 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1089               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dza\textcolor{comment}{  !< The integral in x of the difference between}}
\DoxyCodeLine{1090 \textcolor{comment}{                            !! the geopotential anomaly at the top and bottom of the layer divided}}
\DoxyCodeLine{1091 \textcolor{comment}{                            !! by the x grid spacing [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1092 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{1093               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dza\textcolor{comment}{  !< The integral in y of the difference between}}
\DoxyCodeLine{1094 \textcolor{comment}{                            !! the geopotential anomaly at the top and bottom of the layer divided}}
\DoxyCodeLine{1095 \textcolor{comment}{                            !! by the y grid spacing [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1096   \textcolor{keywordtype}{integer},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\_size\textcolor{comment}{ !< The width of halo points on which to calculate dza.}}
\DoxyCodeLine{1097 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1098               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: bathyP\textcolor{comment}{ !< The pressure at the bathymetry [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1099 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dP\_neglect\textcolor{comment}{ !< A minuscule pressure change with}}
\DoxyCodeLine{1100 \textcolor{comment}{                                             !! the same units as p\_t [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1101   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting}}
\DoxyCodeLine{1102 \textcolor{comment}{                            !! to interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{1103 }
\DoxyCodeLine{1104 \textcolor{comment}{!   This subroutine calculates analytical and nearly-\/analytical integrals in}}
\DoxyCodeLine{1105 \textcolor{comment}{! pressure across layers of geopotential anomalies, which are required for}}
\DoxyCodeLine{1106 \textcolor{comment}{! calculating the finite-\/volume form pressure accelerations in a non-\/Boussinesq}}
\DoxyCodeLine{1107 \textcolor{comment}{! model.  There are essentially no free assumptions, apart from the use of}}
\DoxyCodeLine{1108 \textcolor{comment}{! Boole's rule to do the horizontal integrals, and from a truncation in the}}
\DoxyCodeLine{1109 \textcolor{comment}{! series for log(1-\/eps/1+eps) that assumes that |eps| < 0.34.}}
\DoxyCodeLine{1110 }
\DoxyCodeLine{1111   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1112 \textcolor{keywordtype}{  real} :: T5(5)      \textcolor{comment}{! Temperatures at five quadrature points [degC]}}
\DoxyCodeLine{1113 \textcolor{keywordtype}{  real} :: S5(5)      \textcolor{comment}{! Salinities at five quadrature points [ppt]}}
\DoxyCodeLine{1114 \textcolor{keywordtype}{  real} :: p5(5)      \textcolor{comment}{! Pressures at five quadrature points, scaled back to Pa if necessary [Pa]}}
\DoxyCodeLine{1115 \textcolor{keywordtype}{  real} :: a5(5)      \textcolor{comment}{! Specific volumes at five quadrature points [R-\/1 ~> m3 kg-\/1] or [m3 kg-\/1]}}
\DoxyCodeLine{1116 \textcolor{keywordtype}{  real} :: alpha\_anom \textcolor{comment}{! The depth averaged specific density anomaly [R-\/1 ~> m3 kg-\/1]}}
\DoxyCodeLine{1117 \textcolor{keywordtype}{  real} :: dp         \textcolor{comment}{! The pressure change through a layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1118 \textcolor{keywordtype}{  real} :: hWght      \textcolor{comment}{! A pressure-\/thickness below topography [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1119 \textcolor{keywordtype}{  real} :: hL, hR     \textcolor{comment}{! Pressure-\/thicknesses of the columns to the left and right [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1120 \textcolor{keywordtype}{  real} :: alpha\_ref\_mks \textcolor{comment}{! The reference specific volume in MKS units, never rescaled from m3 kg-\/1 [m3 kg-\/1]}}
\DoxyCodeLine{1121 \textcolor{keywordtype}{  real} :: iDenom     \textcolor{comment}{! The inverse of the denominator in the weights [T4 R-\/2 L-\/4 ~> Pa-\/2]}}
\DoxyCodeLine{1122 \textcolor{keywordtype}{  real} :: hWt\_LL, hWt\_LR \textcolor{comment}{! hWt\_LA is the weighted influence of A on the left column [nondim]}}
\DoxyCodeLine{1123 \textcolor{keywordtype}{  real} :: hWt\_RL, hWt\_RR \textcolor{comment}{! hWt\_RA is the weighted influence of A on the right column [nondim]}}
\DoxyCodeLine{1124 \textcolor{keywordtype}{  real} :: wt\_L, wt\_R \textcolor{comment}{! The linear weights of the left and right columns [nondim]}}
\DoxyCodeLine{1125 \textcolor{keywordtype}{  real} :: wtT\_L, wtT\_R \textcolor{comment}{! The weights for tracers from the left and right columns [nondim]}}
\DoxyCodeLine{1126 \textcolor{keywordtype}{  real} :: intp(5)    \textcolor{comment}{! The integrals of specific volume with pressure at the}}
\DoxyCodeLine{1127                      \textcolor{comment}{! 5 sub-\/column locations [L2 T-\/2 ~> m2 s-\/2]}}
\DoxyCodeLine{1128 \textcolor{keywordtype}{  real} :: RL2\_T2\_to\_Pa  \textcolor{comment}{! A unit conversion factor from the rescaled units of pressure to Pa [Pa T2 R-\/1 L-\/2 ~> 1]}}
\DoxyCodeLine{1129 \textcolor{keywordtype}{  real} :: SV\_scale   \textcolor{comment}{! A multiplicative factor by which to scale specific}}
\DoxyCodeLine{1130                      \textcolor{comment}{! volume from m3 kg-\/1 to the desired units [kg m-\/3 R-\/1 ~> 1]}}
\DoxyCodeLine{1131   \textcolor{keywordtype}{logical} :: do\_massWeight \textcolor{comment}{! Indicates whether to do mass weighting.}}
\DoxyCodeLine{1132 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_90 = 1.0/90.0  \textcolor{comment}{! A rational constant.}}
\DoxyCodeLine{1133   \textcolor{keywordtype}{integer} :: Isq, Ieq, Jsq, Jeq, ish, ieh, jsh, jeh, i, j, m, n, halo}
\DoxyCodeLine{1134 }
\DoxyCodeLine{1135   isq = hi\%IscB ; ieq = hi\%IecB ; jsq = hi\%JscB ; jeq = hi\%JecB}
\DoxyCodeLine{1136   halo = 0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo\_size)) halo = max(halo\_size,0)}
\DoxyCodeLine{1137   ish = hi\%isc-\/halo ; ieh = hi\%iec+halo ; jsh = hi\%jsc-\/halo ; jeh = hi\%jec+halo}
\DoxyCodeLine{1138   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dza)) \textcolor{keywordflow}{then} ; ish = min(isq,ish) ; ieh = max(ieq+1,ieh);\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1139   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dza)) \textcolor{keywordflow}{then} ; jsh = min(jsq,jsh) ; jeh = max(jeq+1,jeh);\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1140 }
\DoxyCodeLine{1141   sv\_scale = us\%R\_to\_kg\_m3}
\DoxyCodeLine{1142   rl2\_t2\_to\_pa = us\%RL2\_T2\_to\_Pa}
\DoxyCodeLine{1143   alpha\_ref\_mks = alpha\_ref * us\%kg\_m3\_to\_R}
\DoxyCodeLine{1144 }
\DoxyCodeLine{1145   do\_massweight = .false.}
\DoxyCodeLine{1146   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (usemasswghtinterp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1147     do\_massweight = .true.}
\DoxyCodeLine{1148     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{present}(bathyp)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"int\_spec\_vol\_dp\_generic: "}//\&}
\DoxyCodeLine{1149         \textcolor{stringliteral}{"bathyP must be present if useMassWghtInterp is present and true."})}
\DoxyCodeLine{1150     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{present}(dp\_neglect)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"int\_spec\_vol\_dp\_generic: "}//\&}
\DoxyCodeLine{1151         \textcolor{stringliteral}{"dP\_neglect must be present if useMassWghtInterp is present and true."})}
\DoxyCodeLine{1152 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1153 }
\DoxyCodeLine{1154   \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1155     dp = p\_b(i,j) -\/ p\_t(i,j)}
\DoxyCodeLine{1156     \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{1157       t5(n) = t(i,j) ; s5(n) = s(i,j)}
\DoxyCodeLine{1158       p5(n) = rl2\_t2\_to\_pa * (p\_b(i,j) -\/ 0.25*real(n-\/1)*dp)}
\DoxyCodeLine{1159 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1160 }
\DoxyCodeLine{1161     \textcolor{keywordflow}{if} (sv\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1162       \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks, scale=sv\_scale)}
\DoxyCodeLine{1163     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1164       \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks)}
\DoxyCodeLine{1165 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1166 }
\DoxyCodeLine{1167     \textcolor{comment}{! Use Boole's rule to estimate the interface height anomaly change.}}
\DoxyCodeLine{1168     alpha\_anom = c1\_90*(7.0*(a5(1)+a5(5)) + 32.0*(a5(2)+a5(4)) + 12.0*a5(3))}
\DoxyCodeLine{1169     dza(i,j) = dp*alpha\_anom}
\DoxyCodeLine{1170     \textcolor{comment}{! Use a Boole's-\/rule-\/like fifth-\/order accurate estimate of the double integral of}}
\DoxyCodeLine{1171     \textcolor{comment}{! the interface height anomaly.}}
\DoxyCodeLine{1172     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intp\_dza)) intp\_dza(i,j) = 0.5*dp**2 * \&}
\DoxyCodeLine{1173           (alpha\_anom -\/ c1\_90*(16.0*(a5(4)-\/a5(2)) + 7.0*(a5(5)-\/a5(1))) )}
\DoxyCodeLine{1174 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1175 }
\DoxyCodeLine{1176   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dza)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=hi\%jsc,hi\%jec ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{1177     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{1178     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}}
\DoxyCodeLine{1179     \textcolor{comment}{! T \& S along the top and bottom integrals, akin to thickness weighting.}}
\DoxyCodeLine{1180     hwght = 0.0}
\DoxyCodeLine{1181     \textcolor{keywordflow}{if} (do\_massweight) \&}
\DoxyCodeLine{1182       hwght = max(0., bathyp(i,j)-\/p\_t(i+1,j), bathyp(i+1,j)-\/p\_t(i,j))}
\DoxyCodeLine{1183     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1184       hl = (p\_b(i,j) -\/ p\_t(i,j)) + dp\_neglect}
\DoxyCodeLine{1185       hr = (p\_b(i+1,j) -\/ p\_t(i+1,j)) + dp\_neglect}
\DoxyCodeLine{1186       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{1187       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{1188       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom}
\DoxyCodeLine{1189       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom}
\DoxyCodeLine{1190     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1191       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0}
\DoxyCodeLine{1192 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1193 }
\DoxyCodeLine{1194     intp(1) = dza(i,j) ; intp(5) = dza(i+1,j)}
\DoxyCodeLine{1195     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{1196       wt\_l = 0.25*real(5-\/m) ; wt\_r = 1.0-\/wt\_l}
\DoxyCodeLine{1197       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr}
\DoxyCodeLine{1198 }
\DoxyCodeLine{1199       \textcolor{comment}{! T, S, and p are interpolated in the horizontal.  The p interpolation}}
\DoxyCodeLine{1200       \textcolor{comment}{! is linear, but for T and S it may be thickness weighted.}}
\DoxyCodeLine{1201       p5(1) = rl2\_t2\_to\_pa * (wt\_l*p\_b(i,j) + wt\_r*p\_b(i+1,j))}
\DoxyCodeLine{1202       dp = wt\_l*(p\_b(i,j) -\/ p\_t(i,j)) + wt\_r*(p\_b(i+1,j) -\/ p\_t(i+1,j))}
\DoxyCodeLine{1203       t5(1) = wtt\_l*t(i,j) + wtt\_r*t(i+1,j)}
\DoxyCodeLine{1204       s5(1) = wtt\_l*s(i,j) + wtt\_r*s(i+1,j)}
\DoxyCodeLine{1205 }
\DoxyCodeLine{1206       \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{1207         t5(n) = t5(1) ; s5(n) = s5(1) ; p5(n) = p5(n-\/1) -\/ rl2\_t2\_to\_pa * 0.25*dp}
\DoxyCodeLine{1208 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1209       \textcolor{keywordflow}{if} (sv\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1210         \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks, scale=sv\_scale)}
\DoxyCodeLine{1211       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1212         \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks)}
\DoxyCodeLine{1213 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1214 }
\DoxyCodeLine{1215     \textcolor{comment}{! Use Boole's rule to estimate the interface height anomaly change.}}
\DoxyCodeLine{1216       intp(m) = dp*( c1\_90*(7.0*(a5(1)+a5(5)) + 32.0*(a5(2)+a5(4)) + \&}
\DoxyCodeLine{1217                                 12.0*a5(3)))}
\DoxyCodeLine{1218 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1219     \textcolor{comment}{! Use Boole's rule to integrate the interface height anomaly values in x.}}
\DoxyCodeLine{1220     intx\_dza(i,j) = c1\_90*(7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4)) + \&}
\DoxyCodeLine{1221                            12.0*intp(3))}
\DoxyCodeLine{1222 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1223 }
\DoxyCodeLine{1224   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dza)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=hi\%isc,hi\%iec}
\DoxyCodeLine{1225     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{1226     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}}
\DoxyCodeLine{1227     \textcolor{comment}{! T \& S along the top and bottom integrals, akin to thickness weighting.}}
\DoxyCodeLine{1228     hwght = 0.0}
\DoxyCodeLine{1229     \textcolor{keywordflow}{if} (do\_massweight) \&}
\DoxyCodeLine{1230       hwght = max(0., bathyp(i,j)-\/p\_t(i,j+1), bathyp(i,j+1)-\/p\_t(i,j))}
\DoxyCodeLine{1231     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1232       hl = (p\_b(i,j) -\/ p\_t(i,j)) + dp\_neglect}
\DoxyCodeLine{1233       hr = (p\_b(i,j+1) -\/ p\_t(i,j+1)) + dp\_neglect}
\DoxyCodeLine{1234       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{1235       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{1236       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom}
\DoxyCodeLine{1237       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom}
\DoxyCodeLine{1238     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1239       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0}
\DoxyCodeLine{1240 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1241 }
\DoxyCodeLine{1242     intp(1) = dza(i,j) ; intp(5) = dza(i,j+1)}
\DoxyCodeLine{1243     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{1244       wt\_l = 0.25*real(5-\/m) ; wt\_r = 1.0-\/wt\_l}
\DoxyCodeLine{1245       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr}
\DoxyCodeLine{1246 }
\DoxyCodeLine{1247       \textcolor{comment}{! T, S, and p are interpolated in the horizontal.  The p interpolation}}
\DoxyCodeLine{1248       \textcolor{comment}{! is linear, but for T and S it may be thickness weighted.}}
\DoxyCodeLine{1249       p5(1) = rl2\_t2\_to\_pa * (wt\_l*p\_b(i,j) + wt\_r*p\_b(i,j+1))}
\DoxyCodeLine{1250       dp = wt\_l*(p\_b(i,j) -\/ p\_t(i,j)) + wt\_r*(p\_b(i,j+1) -\/ p\_t(i,j+1))}
\DoxyCodeLine{1251       t5(1) = wtt\_l*t(i,j) + wtt\_r*t(i,j+1)}
\DoxyCodeLine{1252       s5(1) = wtt\_l*s(i,j) + wtt\_r*s(i,j+1)}
\DoxyCodeLine{1253       \textcolor{keywordflow}{do} n=2,5}
\DoxyCodeLine{1254         t5(n) = t5(1) ; s5(n) = s5(1) ; p5(n) = rl2\_t2\_to\_pa * (p5(n-\/1) -\/ 0.25*dp)}
\DoxyCodeLine{1255 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1256       \textcolor{keywordflow}{if} (sv\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1257         \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks, scale=sv\_scale)}
\DoxyCodeLine{1258       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1259         \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks)}
\DoxyCodeLine{1260 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1261 }
\DoxyCodeLine{1262     \textcolor{comment}{! Use Boole's rule to estimate the interface height anomaly change.}}
\DoxyCodeLine{1263       intp(m) = dp*( c1\_90*(7.0*(a5(1)+a5(5)) + 32.0*(a5(2)+a5(4)) + \&}
\DoxyCodeLine{1264                                 12.0*a5(3)))}
\DoxyCodeLine{1265 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1266     \textcolor{comment}{! Use Boole's rule to integrate the interface height anomaly values in y.}}
\DoxyCodeLine{1267     inty\_dza(i,j) = c1\_90*(7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4)) + \&}
\DoxyCodeLine{1268                            12.0*intp(3))}
\DoxyCodeLine{1269 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1270 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_a71a518f80b5f2ecf83fd9c638cad140d}\label{namespacemom__density__integrals_a71a518f80b5f2ecf83fd9c638cad140d}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_spec\_vol\_dp\_generic\_plm@{int\_spec\_vol\_dp\_generic\_plm}}
\index{int\_spec\_vol\_dp\_generic\_plm@{int\_spec\_vol\_dp\_generic\_plm}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_spec\_vol\_dp\_generic\_plm()}{int\_spec\_vol\_dp\_generic\_plm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+generic\+\_\+plm (\begin{DoxyParamCaption}\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{T\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{T\+\_\+b,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{S\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{S\+\_\+b,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{p\+\_\+t,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{p\+\_\+b,  }\item[{real, intent(in)}]{alpha\+\_\+ref,  }\item[{real, intent(in)}]{d\+P\+\_\+neglect,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(in)}]{bathyP,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout)}]{dza,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intp\+\_\+dza,  }\item[{real, dimension( hi \%isdb\+: hi \%iedb, hi \%jsd\+: hi \%jed), intent(inout), optional}]{intx\+\_\+dza,  }\item[{real, dimension( hi \%isd\+: hi \%ied, hi \%jsdb\+: hi \%jedb), intent(inout), optional}]{inty\+\_\+dza,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



This subroutine calculates integrals of specific volume anomalies in pressure across layers, which are required for calculating the finite-\/volume form pressure accelerations in a non-\/\+Boussinesq model. There are essentially no free assumptions, apart from the use of Boole\textquotesingle{}s rule quadrature to do the integrals. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & A horizontal index type structure. \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+t} & Potential temperature at the top of the layer \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+b} & Potential temperature at the bottom of the layer \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+t} & Salinity at the top the layer \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+b} & Salinity at the bottom the layer \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+t} & Pressure atop the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+b} & Pressure below the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em alpha\+\_\+ref} & A mean specific volume that is subtracted out to reduce the magnitude of each of the integrals \mbox{[}R-\/1 $\sim$$>$ m3 kg-\/1\mbox{]} The calculation is mathematically identical with different values of alpha\+\_\+ref, but alpha\+\_\+ref alters the effects of roundoff, and answers do change. \\
\hline
\mbox{\texttt{ in}}  & {\em dp\+\_\+neglect} & !$<$ A miniscule pressure change with the same units as p\+\_\+t \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em bathyp} & The pressure at the bathymetry \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dza} & The change in the geopotential anomaly \\
\hline
\mbox{\texttt{ in,out}}  & {\em intp\+\_\+dza} & The integral in pressure through the layer of \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dza} & The integral in x of the difference between \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dza} & The integral in y of the difference between \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 1280 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1280   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{ !< A horizontal index type structure.}}
\DoxyCodeLine{1281 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1282                         \textcolor{keywordtype}{intent(in)}  :: T\_t\textcolor{comment}{  !< Potential temperature at the top of the layer [degC]}}
\DoxyCodeLine{1283 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1284                         \textcolor{keywordtype}{intent(in)}  :: T\_b\textcolor{comment}{  !< Potential temperature at the bottom of the layer [degC]}}
\DoxyCodeLine{1285 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1286                         \textcolor{keywordtype}{intent(in)}  :: S\_t\textcolor{comment}{  !< Salinity at the top the layer [ppt]}}
\DoxyCodeLine{1287 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1288                         \textcolor{keywordtype}{intent(in)}  :: S\_b\textcolor{comment}{  !< Salinity at the bottom the layer [ppt]}}
\DoxyCodeLine{1289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1290                         \textcolor{keywordtype}{intent(in)}  :: p\_t\textcolor{comment}{ !< Pressure atop the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1291 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1292                         \textcolor{keywordtype}{intent(in)}  :: p\_b\textcolor{comment}{ !< Pressure below the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1293 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: alpha\_ref\textcolor{comment}{ !< A mean specific volume that is subtracted out}}
\DoxyCodeLine{1294 \textcolor{comment}{                            !! to reduce the magnitude of each of the integrals [R-\/1 ~> m3 kg-\/1]}}
\DoxyCodeLine{1295 \textcolor{comment}{                            !! The calculation is mathematically identical with different values of}}
\DoxyCodeLine{1296 \textcolor{comment}{                            !! alpha\_ref, but alpha\_ref alters the effects of roundoff, and}}
\DoxyCodeLine{1297 \textcolor{comment}{                            !! answers do change.}}
\DoxyCodeLine{1298 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: dP\_neglect\textcolor{comment}{ !<!< A miniscule pressure change with}}
\DoxyCodeLine{1299 \textcolor{comment}{                                             !! the same units as p\_t [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1300 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1301                         \textcolor{keywordtype}{intent(in)}  :: bathyP\textcolor{comment}{ !< The pressure at the bathymetry [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1302   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{1303   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1304 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1305                         \textcolor{keywordtype}{intent(inout)} :: dza\textcolor{comment}{ !< The change in the geopotential anomaly}}
\DoxyCodeLine{1306 \textcolor{comment}{                            !! across the layer [L2 T-\/2 ~> m2 s-\/2]}}
\DoxyCodeLine{1307 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1308               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intp\_dza\textcolor{comment}{ !< The integral in pressure through the layer of}}
\DoxyCodeLine{1309 \textcolor{comment}{                            !! the geopotential anomaly relative to the anomaly at the bottom of the}}
\DoxyCodeLine{1310 \textcolor{comment}{                            !! layer [R L4 T-\/4 ~> Pa m2 s-\/2] or [Pa m2 s-\/2]}}
\DoxyCodeLine{1311 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1312               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dza\textcolor{comment}{  !< The integral in x of the difference between}}
\DoxyCodeLine{1313 \textcolor{comment}{                            !! the geopotential anomaly at the top and bottom of the layer divided}}
\DoxyCodeLine{1314 \textcolor{comment}{                            !! by the x grid spacing [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1315 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{1316               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dza\textcolor{comment}{  !< The integral in y of the difference between}}
\DoxyCodeLine{1317 \textcolor{comment}{                            !! the geopotential anomaly at the top and bottom of the layer divided}}
\DoxyCodeLine{1318 \textcolor{comment}{                            !! by the y grid spacing [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1319   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting}}
\DoxyCodeLine{1320 \textcolor{comment}{                            !! to interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{1321 }
\DoxyCodeLine{1322 \textcolor{comment}{!   This subroutine calculates analytical and nearly-\/analytical integrals in}}
\DoxyCodeLine{1323 \textcolor{comment}{! pressure across layers of geopotential anomalies, which are required for}}
\DoxyCodeLine{1324 \textcolor{comment}{! calculating the finite-\/volume form pressure accelerations in a non-\/Boussinesq}}
\DoxyCodeLine{1325 \textcolor{comment}{! model.  There are essentially no free assumptions, apart from the use of}}
\DoxyCodeLine{1326 \textcolor{comment}{! Boole's rule to do the horizontal integrals, and from a truncation in the}}
\DoxyCodeLine{1327 \textcolor{comment}{! series for log(1-\/eps/1+eps) that assumes that |eps| < 0.34.}}
\DoxyCodeLine{1328 }
\DoxyCodeLine{1329 \textcolor{keywordtype}{  real} :: T5(5)      \textcolor{comment}{! Temperatures at five quadrature points [degC]}}
\DoxyCodeLine{1330 \textcolor{keywordtype}{  real} :: S5(5)      \textcolor{comment}{! Salinities at five quadrature points [ppt]}}
\DoxyCodeLine{1331 \textcolor{keywordtype}{  real} :: p5(5)      \textcolor{comment}{! Pressures at five quadrature points, scaled back to Pa as necessary [Pa]}}
\DoxyCodeLine{1332 \textcolor{keywordtype}{  real} :: a5(5)      \textcolor{comment}{! Specific volumes at five quadrature points [R-\/1 ~> m3 kg-\/1] or [m3 kg-\/1]}}
\DoxyCodeLine{1333 \textcolor{keywordtype}{  real} :: T15(15)    \textcolor{comment}{! Temperatures at fifteen interior quadrature points [degC]}}
\DoxyCodeLine{1334 \textcolor{keywordtype}{  real} :: S15(15)    \textcolor{comment}{! Salinities at fifteen interior quadrature points [ppt]}}
\DoxyCodeLine{1335 \textcolor{keywordtype}{  real} :: p15(15)    \textcolor{comment}{! Pressures at fifteen quadrature points, scaled back to Pa as necessary [Pa]}}
\DoxyCodeLine{1336 \textcolor{keywordtype}{  real} :: a15(15)    \textcolor{comment}{! Specific volumes at fifteen quadrature points [R-\/1 ~> m3 kg-\/1] or [m3 kg-\/1]}}
\DoxyCodeLine{1337 \textcolor{keywordtype}{  real} :: wt\_t(5), wt\_b(5) \textcolor{comment}{! Weights of top and bottom values at quadrature points [nondim]}}
\DoxyCodeLine{1338 \textcolor{keywordtype}{  real} :: T\_top, T\_bot, S\_top, S\_bot, P\_top, P\_bot}
\DoxyCodeLine{1339 }
\DoxyCodeLine{1340 \textcolor{keywordtype}{  real} :: alpha\_anom \textcolor{comment}{! The depth averaged specific density anomaly [m3 kg-\/1]}}
\DoxyCodeLine{1341 \textcolor{keywordtype}{  real} :: dp         \textcolor{comment}{! The pressure change through a layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1342 \textcolor{keywordtype}{  real} :: dp\_90(2:4) \textcolor{comment}{! The pressure change through a layer divided by 90 [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1343 \textcolor{keywordtype}{  real} :: hWght      \textcolor{comment}{! A pressure-\/thickness below topography [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1344 \textcolor{keywordtype}{  real} :: hL, hR     \textcolor{comment}{! Pressure-\/thicknesses of the columns to the left and right [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{1345 \textcolor{keywordtype}{  real} :: alpha\_ref\_mks \textcolor{comment}{! The reference specific volume in MKS units, never rescaled from m3 kg-\/1 [m3 kg-\/1]}}
\DoxyCodeLine{1346 \textcolor{keywordtype}{  real} :: iDenom     \textcolor{comment}{! The inverse of the denominator in the weights [T4 R-\/2 L-\/4 ~> Pa-\/2]}}
\DoxyCodeLine{1347 \textcolor{keywordtype}{  real} :: hWt\_LL, hWt\_LR \textcolor{comment}{! hWt\_LA is the weighted influence of A on the left column [nondim]}}
\DoxyCodeLine{1348 \textcolor{keywordtype}{  real} :: hWt\_RL, hWt\_RR \textcolor{comment}{! hWt\_RA is the weighted influence of A on the right column [nondim]}}
\DoxyCodeLine{1349 \textcolor{keywordtype}{  real} :: wt\_L, wt\_R \textcolor{comment}{! The linear weights of the left and right columns [nondim]}}
\DoxyCodeLine{1350 \textcolor{keywordtype}{  real} :: wtT\_L, wtT\_R \textcolor{comment}{! The weights for tracers from the left and right columns [nondim]}}
\DoxyCodeLine{1351 \textcolor{keywordtype}{  real} :: intp(5)    \textcolor{comment}{! The integrals of specific volume with pressure at the}}
\DoxyCodeLine{1352                      \textcolor{comment}{! 5 sub-\/column locations [L2 T-\/2 ~> m2 s-\/2]}}
\DoxyCodeLine{1353 \textcolor{keywordtype}{  real} :: RL2\_T2\_to\_Pa  \textcolor{comment}{! A unit conversion factor from the rescaled units of pressure to Pa [Pa T2 R-\/1 L-\/2 ~> 1]}}
\DoxyCodeLine{1354 \textcolor{keywordtype}{  real} :: SV\_scale   \textcolor{comment}{! A multiplicative factor by which to scale specific}}
\DoxyCodeLine{1355                      \textcolor{comment}{! volume from m3 kg-\/1 to the desired units [kg m-\/3 R-\/1 ~> 1]}}
\DoxyCodeLine{1356 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: C1\_90 = 1.0/90.0  \textcolor{comment}{! A rational constant.}}
\DoxyCodeLine{1357   \textcolor{keywordtype}{logical} :: do\_massWeight \textcolor{comment}{! Indicates whether to do mass weighting.}}
\DoxyCodeLine{1358   \textcolor{keywordtype}{integer} :: Isq, Ieq, Jsq, Jeq, i, j, m, n, pos}
\DoxyCodeLine{1359 }
\DoxyCodeLine{1360   isq = hi\%IscB ; ieq = hi\%IecB ; jsq = hi\%JscB ; jeq = hi\%JecB}
\DoxyCodeLine{1361 }
\DoxyCodeLine{1362   do\_massweight = .false.}
\DoxyCodeLine{1363   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) do\_massweight = usemasswghtinterp}
\DoxyCodeLine{1364 }
\DoxyCodeLine{1365   sv\_scale = us\%R\_to\_kg\_m3}
\DoxyCodeLine{1366   rl2\_t2\_to\_pa = us\%RL2\_T2\_to\_Pa}
\DoxyCodeLine{1367   alpha\_ref\_mks = alpha\_ref * us\%kg\_m3\_to\_R}
\DoxyCodeLine{1368 }
\DoxyCodeLine{1369   \textcolor{keywordflow}{do} n = 1, 5 \textcolor{comment}{! Note that these are reversed from int\_density\_dz.}}
\DoxyCodeLine{1370     wt\_t(n) = 0.25 * real(n-\/1)}
\DoxyCodeLine{1371     wt\_b(n) = 1.0 -\/ wt\_t(n)}
\DoxyCodeLine{1372 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1373 }
\DoxyCodeLine{1374   \textcolor{comment}{! 1. Compute vertical integrals}}
\DoxyCodeLine{1375   \textcolor{keywordflow}{do} j=jsq,jeq+1; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{1376     dp = p\_b(i,j) -\/ p\_t(i,j)}
\DoxyCodeLine{1377     \textcolor{keywordflow}{do} n=1,5 \textcolor{comment}{! T, S and p are linearly interpolated in the vertical.}}
\DoxyCodeLine{1378       p5(n) = rl2\_t2\_to\_pa * (wt\_t(n) * p\_t(i,j) + wt\_b(n) * p\_b(i,j))}
\DoxyCodeLine{1379       s5(n) = wt\_t(n) * s\_t(i,j) + wt\_b(n) * s\_b(i,j)}
\DoxyCodeLine{1380       t5(n) = wt\_t(n) * t\_t(i,j) + wt\_b(n) * t\_b(i,j)}
\DoxyCodeLine{1381 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1382     \textcolor{keywordflow}{if} (sv\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1383       \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks, scale=sv\_scale)}
\DoxyCodeLine{1384     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1385       \textcolor{keyword}{call }calculate\_spec\_vol(t5, s5, p5, a5, 1, 5, eos, alpha\_ref\_mks)}
\DoxyCodeLine{1386 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1387 }
\DoxyCodeLine{1388     \textcolor{comment}{! Use Boole's rule to estimate the interface height anomaly change.}}
\DoxyCodeLine{1389     alpha\_anom = c1\_90*((7.0*(a5(1)+a5(5)) + 32.0*(a5(2)+a5(4))) + 12.0*a5(3))}
\DoxyCodeLine{1390     dza(i,j) = dp*alpha\_anom}
\DoxyCodeLine{1391     \textcolor{comment}{! Use a Boole's-\/rule-\/like fifth-\/order accurate estimate of the double integral of}}
\DoxyCodeLine{1392     \textcolor{comment}{! the interface height anomaly.}}
\DoxyCodeLine{1393     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intp\_dza)) intp\_dza(i,j) = 0.5*dp**2 * \&}
\DoxyCodeLine{1394           (alpha\_anom -\/ c1\_90*(16.0*(a5(4)-\/a5(2)) + 7.0*(a5(5)-\/a5(1))) )}
\DoxyCodeLine{1395 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1396 }
\DoxyCodeLine{1397   \textcolor{comment}{! 2. Compute horizontal integrals in the x direction}}
\DoxyCodeLine{1398   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dza)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=hi\%jsc,hi\%jec ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{1399     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{1400     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation}}
\DoxyCodeLine{1401     \textcolor{comment}{! of T,S along the top and bottom integrals, almost like thickness}}
\DoxyCodeLine{1402     \textcolor{comment}{! weighting. Note: To work in terrain following coordinates we could}}
\DoxyCodeLine{1403     \textcolor{comment}{! offset this distance by the layer thickness to replicate other models.}}
\DoxyCodeLine{1404     hwght = 0.0}
\DoxyCodeLine{1405     \textcolor{keywordflow}{if} (do\_massweight) \&}
\DoxyCodeLine{1406       hwght =  max(0., bathyp(i,j)-\/p\_t(i+1,j), bathyp(i+1,j)-\/p\_t(i,j))}
\DoxyCodeLine{1407     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1408       hl = (p\_b(i,j) -\/ p\_t(i,j)) + dp\_neglect}
\DoxyCodeLine{1409       hr = (p\_b(i+1,j) -\/ p\_t(i+1,j)) + dp\_neglect}
\DoxyCodeLine{1410       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{1411       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{1412       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom}
\DoxyCodeLine{1413       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom}
\DoxyCodeLine{1414     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1415       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0}
\DoxyCodeLine{1416 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1417 }
\DoxyCodeLine{1418     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{1419       wt\_l = 0.25*real(5-\/m) ; wt\_r = 1.0-\/wt\_l}
\DoxyCodeLine{1420       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr}
\DoxyCodeLine{1421 }
\DoxyCodeLine{1422       \textcolor{comment}{! T, S, and p are interpolated in the horizontal.  The p interpolation}}
\DoxyCodeLine{1423       \textcolor{comment}{! is linear, but for T and S it may be thickness weighted.}}
\DoxyCodeLine{1424       p\_top = wt\_l*p\_t(i,j) + wt\_r*p\_t(i+1,j)}
\DoxyCodeLine{1425       p\_bot = wt\_l*p\_b(i,j) + wt\_r*p\_b(i+1,j)}
\DoxyCodeLine{1426       t\_top = wtt\_l*t\_t(i,j) + wtt\_r*t\_t(i+1,j)}
\DoxyCodeLine{1427       t\_bot = wtt\_l*t\_b(i,j) + wtt\_r*t\_b(i+1,j)}
\DoxyCodeLine{1428       s\_top = wtt\_l*s\_t(i,j) + wtt\_r*s\_t(i+1,j)}
\DoxyCodeLine{1429       s\_bot = wtt\_l*s\_b(i,j) + wtt\_r*s\_b(i+1,j)}
\DoxyCodeLine{1430       dp\_90(m) = c1\_90*(p\_bot -\/ p\_top)}
\DoxyCodeLine{1431 }
\DoxyCodeLine{1432       \textcolor{comment}{! Salinity, temperature and pressure with linear interpolation in the vertical.}}
\DoxyCodeLine{1433       pos = (m-\/2)*5}
\DoxyCodeLine{1434       \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{1435         p15(pos+n) = rl2\_t2\_to\_pa * (wt\_t(n) * p\_top + wt\_b(n) * p\_bot)}
\DoxyCodeLine{1436         s15(pos+n) = wt\_t(n) * s\_top + wt\_b(n) * s\_bot}
\DoxyCodeLine{1437         t15(pos+n) = wt\_t(n) * t\_top + wt\_b(n) * t\_bot}
\DoxyCodeLine{1438 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1439 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1440 }
\DoxyCodeLine{1441     \textcolor{keywordflow}{if} (sv\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1442       \textcolor{keyword}{call }calculate\_spec\_vol(t15, s15, p15, a15, 1, 15, eos, alpha\_ref\_mks, scale=sv\_scale)}
\DoxyCodeLine{1443     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1444       \textcolor{keyword}{call }calculate\_spec\_vol(t15, s15, p15, a15, 1, 15, eos, alpha\_ref\_mks)}
\DoxyCodeLine{1445 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1446 }
\DoxyCodeLine{1447     intp(1) = dza(i,j) ; intp(5) = dza(i+1,j)}
\DoxyCodeLine{1448     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{1449       \textcolor{comment}{! Use Boole's rule to estimate the interface height anomaly change.}}
\DoxyCodeLine{1450       \textcolor{comment}{! The integrals at the ends of the segment are already known.}}
\DoxyCodeLine{1451       pos = (m-\/2)*5}
\DoxyCodeLine{1452       intp(m) = dp\_90(m)*((7.0*(a15(pos+1)+a15(pos+5)) + \&}
\DoxyCodeLine{1453                           32.0*(a15(pos+2)+a15(pos+4))) + 12.0*a15(pos+3))}
\DoxyCodeLine{1454 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1455     \textcolor{comment}{! Use Boole's rule to integrate the interface height anomaly values in x.}}
\DoxyCodeLine{1456     intx\_dza(i,j) = c1\_90*((7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4))) + \&}
\DoxyCodeLine{1457                            12.0*intp(3))}
\DoxyCodeLine{1458 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1459 }
\DoxyCodeLine{1460   \textcolor{comment}{! 3. Compute horizontal integrals in the y direction}}
\DoxyCodeLine{1461   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dza)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=hi\%isc,hi\%iec}
\DoxyCodeLine{1462     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}}
\DoxyCodeLine{1463     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation}}
\DoxyCodeLine{1464     \textcolor{comment}{! of T,S along the top and bottom integrals, like thickness weighting.}}
\DoxyCodeLine{1465     hwght = 0.0}
\DoxyCodeLine{1466     \textcolor{keywordflow}{if} (do\_massweight) \&}
\DoxyCodeLine{1467       hwght = max(0., bathyp(i,j)-\/p\_t(i,j+1), bathyp(i,j+1)-\/p\_t(i,j))}
\DoxyCodeLine{1468     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1469       hl = (p\_b(i,j) -\/ p\_t(i,j)) + dp\_neglect}
\DoxyCodeLine{1470       hr = (p\_b(i,j+1) -\/ p\_t(i,j+1)) + dp\_neglect}
\DoxyCodeLine{1471       hwght = hwght * ( (hl-\/hr)/(hl+hr) )**2}
\DoxyCodeLine{1472       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )}
\DoxyCodeLine{1473       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom}
\DoxyCodeLine{1474       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom}
\DoxyCodeLine{1475     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1476       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0}
\DoxyCodeLine{1477 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1478 }
\DoxyCodeLine{1479     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{1480       wt\_l = 0.25*real(5-\/m) ; wt\_r = 1.0-\/wt\_l}
\DoxyCodeLine{1481       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr}
\DoxyCodeLine{1482 }
\DoxyCodeLine{1483       \textcolor{comment}{! T, S, and p are interpolated in the horizontal.  The p interpolation}}
\DoxyCodeLine{1484       \textcolor{comment}{! is linear, but for T and S it may be thickness weighted.}}
\DoxyCodeLine{1485       p\_top = wt\_l*p\_t(i,j) + wt\_r*p\_t(i,j+1)}
\DoxyCodeLine{1486       p\_bot = wt\_l*p\_b(i,j) + wt\_r*p\_b(i,j+1)}
\DoxyCodeLine{1487       t\_top = wtt\_l*t\_t(i,j) + wtt\_r*t\_t(i,j+1)}
\DoxyCodeLine{1488       t\_bot = wtt\_l*t\_b(i,j) + wtt\_r*t\_b(i,j+1)}
\DoxyCodeLine{1489       s\_top = wtt\_l*s\_t(i,j) + wtt\_r*s\_t(i,j+1)}
\DoxyCodeLine{1490       s\_bot = wtt\_l*s\_b(i,j) + wtt\_r*s\_b(i,j+1)}
\DoxyCodeLine{1491       dp\_90(m) = c1\_90*(p\_bot -\/ p\_top)}
\DoxyCodeLine{1492 }
\DoxyCodeLine{1493       \textcolor{comment}{! Salinity, temperature and pressure with linear interpolation in the vertical.}}
\DoxyCodeLine{1494       pos = (m-\/2)*5}
\DoxyCodeLine{1495       \textcolor{keywordflow}{do} n=1,5}
\DoxyCodeLine{1496         p15(pos+n) = rl2\_t2\_to\_pa * (wt\_t(n) * p\_top + wt\_b(n) * p\_bot)}
\DoxyCodeLine{1497         s15(pos+n) = wt\_t(n) * s\_top + wt\_b(n) * s\_bot}
\DoxyCodeLine{1498         t15(pos+n) = wt\_t(n) * t\_top + wt\_b(n) * t\_bot}
\DoxyCodeLine{1499 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1500 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1501 }
\DoxyCodeLine{1502     \textcolor{keywordflow}{if} (sv\_scale /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1503       \textcolor{keyword}{call }calculate\_spec\_vol(t15, s15, p15, a15, 1, 15, eos, alpha\_ref\_mks, scale=sv\_scale)}
\DoxyCodeLine{1504     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1505       \textcolor{keyword}{call }calculate\_spec\_vol(t15, s15, p15, a15, 1, 15, eos, alpha\_ref\_mks)}
\DoxyCodeLine{1506 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1507 }
\DoxyCodeLine{1508     intp(1) = dza(i,j) ; intp(5) = dza(i,j+1)}
\DoxyCodeLine{1509     \textcolor{keywordflow}{do} m=2,4}
\DoxyCodeLine{1510       \textcolor{comment}{! Use Boole's rule to estimate the interface height anomaly change.}}
\DoxyCodeLine{1511       \textcolor{comment}{! The integrals at the ends of the segment are already known.}}
\DoxyCodeLine{1512       pos = (m-\/2)*5}
\DoxyCodeLine{1513       intp(m) = dp\_90(m) * ((7.0*(a15(pos+1)+a15(pos+5)) + \&}
\DoxyCodeLine{1514                             32.0*(a15(pos+2)+a15(pos+4))) + 12.0*a15(pos+3))}
\DoxyCodeLine{1515 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1516     \textcolor{comment}{! Use Boole's rule to integrate the interface height anomaly values in x.}}
\DoxyCodeLine{1517     inty\_dza(i,j) = c1\_90*((7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4))) + \&}
\DoxyCodeLine{1518                            12.0*intp(3))}
\DoxyCodeLine{1519 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1520 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__density__integrals_a759c2ae7aec17c59d532050f68a1e518}\label{namespacemom__density__integrals_a759c2ae7aec17c59d532050f68a1e518}} 
\index{mom\_density\_integrals@{mom\_density\_integrals}!int\_specific\_vol\_dp@{int\_specific\_vol\_dp}}
\index{int\_specific\_vol\_dp@{int\_specific\_vol\_dp}!mom\_density\_integrals@{mom\_density\_integrals}}
\doxysubsubsection{\texorpdfstring{int\_specific\_vol\_dp()}{int\_specific\_vol\_dp()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+density\+\_\+integrals\+::int\+\_\+specific\+\_\+vol\+\_\+dp (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{T,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{S,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{p\+\_\+t,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in)}]{p\+\_\+b,  }\item[{real, intent(in)}]{alpha\+\_\+ref,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(eos\+\_\+type), pointer}]{E\+OS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(inout)}]{dza,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(inout), optional}]{intp\+\_\+dza,  }\item[{real, dimension(szib\+\_\+(hi),szj\+\_\+(hi)), intent(inout), optional}]{intx\+\_\+dza,  }\item[{real, dimension(szi\+\_\+(hi),szjb\+\_\+(hi)), intent(inout), optional}]{inty\+\_\+dza,  }\item[{integer, intent(in), optional}]{halo\+\_\+size,  }\item[{real, dimension(szi\+\_\+(hi),szj\+\_\+(hi)), intent(in), optional}]{bathyP,  }\item[{real, intent(in), optional}]{d\+P\+\_\+tiny,  }\item[{logical, intent(in), optional}]{use\+Mass\+Wght\+Interp }\end{DoxyParamCaption})}



Calls the appropriate subroutine to calculate analytical and nearly-\/analytical integrals in pressure across layers of geopotential anomalies, which are required for calculating the finite-\/volume form pressure accelerations in a non-\/\+Boussinesq model. There are essentially no free assumptions, apart from the use of Boole\textquotesingle{}s rule to do the horizontal integrals, and from a truncation in the series for log(1-\/eps/1+eps) that assumes that $\vert$eps$\vert$ $<$ 0.\+34. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & The horizontal index structure \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+t} & Pressure at the top of the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+b} & Pressure at the bottom of the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em alpha\+\_\+ref} & A mean specific volume that is subtracted out to reduce the magnitude of each of the integrals \mbox{[}R-\/1 $\sim$$>$ m3 kg-\/1\mbox{]} The calculation is mathematically identical with different values of alpha\+\_\+ref, but this reduces the effects of roundoff. \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em dza} & The change in the geopotential anomaly across \\
\hline
\mbox{\texttt{ in,out}}  & {\em intp\+\_\+dza} & The integral in pressure through the layer of the \\
\hline
\mbox{\texttt{ in,out}}  & {\em intx\+\_\+dza} & The integral in x of the difference between the \\
\hline
\mbox{\texttt{ in,out}}  & {\em inty\+\_\+dza} & The integral in y of the difference between the \\
\hline
\mbox{\texttt{ in}}  & {\em halo\+\_\+size} & The width of halo points on which to calculate dza. \\
\hline
\mbox{\texttt{ in}}  & {\em bathyp} & The pressure at the bathymetry \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dp\+\_\+tiny} & A minuscule pressure change with the same units as p\+\_\+t \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals. \\
\hline
\end{DoxyParams}


Definition at line 1007 of file M\+O\+M\+\_\+density\+\_\+integrals.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1007   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: HI\textcolor{comment}{  !< The horizontal index structure}}
\DoxyCodeLine{1008 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1009                         \textcolor{keywordtype}{intent(in)}  :: T\textcolor{comment}{   !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{1010 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1011                         \textcolor{keywordtype}{intent(in)}  :: S\textcolor{comment}{   !< Salinity [ppt]}}
\DoxyCodeLine{1012 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1013                         \textcolor{keywordtype}{intent(in)}  :: p\_t\textcolor{comment}{ !< Pressure at the top of the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1014 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1015                         \textcolor{keywordtype}{intent(in)}  :: p\_b\textcolor{comment}{ !< Pressure at the bottom of the layer [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1016 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}  :: alpha\_ref\textcolor{comment}{ !< A mean specific volume that is subtracted out}}
\DoxyCodeLine{1017 \textcolor{comment}{                            !! to reduce the magnitude of each of the integrals [R-\/1 ~> m3 kg-\/1]}}
\DoxyCodeLine{1018 \textcolor{comment}{                            !! The calculation is mathematically identical with different values of}}
\DoxyCodeLine{1019 \textcolor{comment}{                            !! alpha\_ref, but this reduces the effects of roundoff.}}
\DoxyCodeLine{1020   \textcolor{keywordtype}{type}(EOS\_type),       \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{1021   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{1022 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1023                         \textcolor{keywordtype}{intent(inout)} :: dza\textcolor{comment}{ !< The change in the geopotential anomaly across}}
\DoxyCodeLine{1024 \textcolor{comment}{                            !! the layer [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1025 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1026               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intp\_dza\textcolor{comment}{ !< The integral in pressure through the layer of the}}
\DoxyCodeLine{1027 \textcolor{comment}{                            !! geopotential anomaly relative to the anomaly at the bottom of the}}
\DoxyCodeLine{1028 \textcolor{comment}{                            !! layer [R L4 T-\/4 ~> Pa m2 s-\/2] or [Pa m2 s-\/2]}}
\DoxyCodeLine{1029 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1030               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dza\textcolor{comment}{ !< The integral in x of the difference between the}}
\DoxyCodeLine{1031 \textcolor{comment}{                            !! geopotential anomaly at the top and bottom of the layer divided by}}
\DoxyCodeLine{1032 \textcolor{comment}{                            !! the x grid spacing [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1033 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJB\_(HI))}, \&}
\DoxyCodeLine{1034               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dza\textcolor{comment}{ !< The integral in y of the difference between the}}
\DoxyCodeLine{1035 \textcolor{comment}{                            !! geopotential anomaly at the top and bottom of the layer divided by}}
\DoxyCodeLine{1036 \textcolor{comment}{                            !! the y grid spacing [L2 T-\/2 ~> m2 s-\/2] or [m2 s-\/2]}}
\DoxyCodeLine{1037   \textcolor{keywordtype}{integer},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\_size\textcolor{comment}{ !< The width of halo points on which to calculate dza.}}
\DoxyCodeLine{1038 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(HI),SZJ\_(HI))}, \&}
\DoxyCodeLine{1039               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: bathyP\textcolor{comment}{  !< The pressure at the bathymetry [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1040 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dP\_tiny\textcolor{comment}{ !< A minuscule pressure change with}}
\DoxyCodeLine{1041 \textcolor{comment}{                            !! the same units as p\_t [R L2 T-\/2 ~> Pa] or [Pa]}}
\DoxyCodeLine{1042   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: useMassWghtInterp\textcolor{comment}{ !< If true, uses mass weighting}}
\DoxyCodeLine{1043 \textcolor{comment}{                            !! to interpolate T/S for top and bottom integrals.}}
\DoxyCodeLine{1044 }
\DoxyCodeLine{1045   \textcolor{keywordflow}{if} (eos\_quadrature(eos)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1046     \textcolor{keyword}{call }int\_spec\_vol\_dp\_generic\_pcm(t, s, p\_t, p\_b, alpha\_ref, hi, eos, us, \&}
\DoxyCodeLine{1047                                      dza, intp\_dza, intx\_dza, inty\_dza, halo\_size, \&}
\DoxyCodeLine{1048                                      bathyp, dp\_tiny, usemasswghtinterp)}
\DoxyCodeLine{1049   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1050     \textcolor{keyword}{call }analytic\_int\_specific\_vol\_dp(t, s, p\_t, p\_b, alpha\_ref, hi, eos, \&}
\DoxyCodeLine{1051                                       dza, intp\_dza, intx\_dza, inty\_dza, halo\_size, \&}
\DoxyCodeLine{1052                                       bathyp, dp\_tiny, usemasswghtinterp)}
\DoxyCodeLine{1053 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1054 }

\end{DoxyCode}
