\hypertarget{namespacemom__eos__wright}{}\section{mom\+\_\+eos\+\_\+wright Module Reference}
\label{namespacemom__eos__wright}\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}


\subsection{Detailed Description}
The equation of state using the Wright 1997 expressions. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
interface \hyperlink{interfacemom__eos__wright_1_1calculate__density__derivs__wright}{calculate\+\_\+density\+\_\+derivs\+\_\+wright}
\begin{DoxyCompactList}\small\item\em For a given thermodynamic state, return the derivatives of density with temperature and salinity. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__eos__wright_1_1calculate__density__second__derivs__wright}{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+wright}
\begin{DoxyCompactList}\small\item\em For a given thermodynamic state, return the second derivatives of density with various combinations of temperature, salinity, and pressure. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__eos__wright_1_1calculate__density__wright}{calculate\+\_\+density\+\_\+wright}
\begin{DoxyCompactList}\small\item\em Compute the in situ density of sea water (in \mbox{[}kg m-\/3\mbox{]}), or its anomaly with respect to a reference density, from salinity (in psu), potential temperature (in deg C), and pressure \mbox{[}Pa\mbox{]}, using the expressions from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__eos__wright_1_1calculate__spec__vol__wright}{calculate\+\_\+spec\+\_\+vol\+\_\+wright}
\begin{DoxyCompactList}\small\item\em Compute the in situ specific volume of sea water (in \mbox{[}m3 kg-\/1\mbox{]}), or an anomaly with respect to a reference specific volume, from salinity (in psu), potential temperature (in deg C), and pressure \mbox{[}Pa\mbox{]}, using the expressions from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine \hyperlink{namespacemom__eos__wright_a047725cee226bb5621080176aaff36d6}{calculate\+\_\+density\+\_\+scalar\+\_\+wright} (T, S, pressure, rho, rho\+\_\+ref)
\begin{DoxyCompactList}\small\item\em This subroutine computes the in situ density of sea water (rho in \mbox{[}kg m-\/3\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}), and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_a9d96824061e9c3d438c3d909a00fb7ab}{calculate\+\_\+density\+\_\+array\+\_\+wright} (T, S, pressure, rho, start, npts, rho\+\_\+ref)
\begin{DoxyCompactList}\small\item\em This subroutine computes the in situ density of sea water (rho in \mbox{[}kg m-\/3\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}), and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_aa1577bed7878372af9be62afea06cbf0}{calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright} (T, S, pressure, specvol, spv\+\_\+ref)
\begin{DoxyCompactList}\small\item\em This subroutine computes the in situ specific volume of sea water (specvol in \mbox{[}m3 kg-\/1\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}) and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. If spv\+\_\+ref is present, specvol is an anomaly from spv\+\_\+ref. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_a0e1da760ed0fca53533430d0bd03ee6d}{calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright} (T, S, pressure, specvol, start, npts, spv\+\_\+ref)
\begin{DoxyCompactList}\small\item\em This subroutine computes the in situ specific volume of sea water (specvol in \mbox{[}m3 kg-\/1\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}) and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. If spv\+\_\+ref is present, specvol is an anomaly from spv\+\_\+ref. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_a576d1ff13c93f4a3ffbd483d43a78ab7}{calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright} (T, S, pressure, drho\+\_\+dT, drho\+\_\+dS, start, npts)
\begin{DoxyCompactList}\small\item\em For a given thermodynamic state, return the thermal/haline expansion coefficients. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_a8264a21fbe5809d5290ea388e0b2e64f}{calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright} (T, S, pressure, drho\+\_\+dT, drho\+\_\+dS)
\begin{DoxyCompactList}\small\item\em The scalar version of calculate\+\_\+density\+\_\+derivs which promotes scalar inputs to a 1-\/element array and then demotes the output back to a scalar. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_a218432c80512597414f0c1fe4ae2d97d}{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright} (T, S, P, drho\+\_\+ds\+\_\+ds, drho\+\_\+ds\+\_\+dt, drho\+\_\+dt\+\_\+dt, drho\+\_\+ds\+\_\+dp, drho\+\_\+dt\+\_\+dp, start, npts)
\begin{DoxyCompactList}\small\item\em Second derivatives of density with respect to temperature, salinity, and pressure. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__eos__wright_a74e1c5129ef4414337347a115bcdff10}{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright} (T, S, P, drho\+\_\+ds\+\_\+ds, drho\+\_\+ds\+\_\+dt, drho\+\_\+dt\+\_\+dt, drho\+\_\+ds\+\_\+dp, drho\+\_\+dt\+\_\+dp)
\begin{DoxyCompactList}\small\item\em Second derivatives of density with respect to temperature, salinity, and pressure for scalar inputs. Inputs promoted to 1-\/element array and output demoted to scalar. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__eos__wright_a890d098ddbdc76f6cfbf1b7cf19b6388}{calculate\+\_\+specvol\+\_\+derivs\+\_\+wright} (T, S, pressure, d\+S\+V\+\_\+dT, d\+S\+V\+\_\+dS, start, npts)
\begin{DoxyCompactList}\small\item\em For a given thermodynamic state, return the partial derivatives of specific volume with temperature and salinity. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__eos__wright_ab5610ab6dd25f488ff5821dcbde78e0d}{calculate\+\_\+compress\+\_\+wright} (T, S, pressure, rho, drho\+\_\+dp, start, npts)
\begin{DoxyCompactList}\small\item\em This subroutine computes the in situ density of sea water (rho in \mbox{[}kg m-\/3\mbox{]}) and the compressibility (drho/dp = C\+\_\+sound$^\wedge$-\/2) (drho\+\_\+dp \mbox{[}s2 m-\/2\mbox{]}) from salinity (sal in psu), potential temperature (T \mbox{[}degC\mbox{]}), and pressure \mbox{[}Pa\mbox{]}. It uses the expressions from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. Coded by R. Hallberg, 1/01. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__eos__wright_ac94eaa2504eb4ccb12b41add45e1301e}{int\+\_\+density\+\_\+dz\+\_\+wright} (T, S, z\+\_\+t, z\+\_\+b, rho\+\_\+ref, rho\+\_\+0, G\+\_\+e, HI, dpa, intz\+\_\+dpa, intx\+\_\+dpa, inty\+\_\+dpa, bathyT, dz\+\_\+neglect, use\+Mass\+Wght\+Interp, rho\+\_\+scale, pres\+\_\+scale)
\begin{DoxyCompactList}\small\item\em This subroutine calculates analytical and nearly-\/analytical 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 \hyperlink{namespacemom__eos__wright_a35402f454f02a3fa680a6d7870931aa6}{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright} (T, S, p\+\_\+t, p\+\_\+b, spv\+\_\+ref, HI, dza, intp\+\_\+dza, intx\+\_\+dza, inty\+\_\+dza, halo\+\_\+size, bathyP, d\+P\+\_\+neglect, use\+Mass\+Wght\+Interp, S\+V\+\_\+scale, pres\+\_\+scale)
\begin{DoxyCompactList}\small\item\em This subroutine calculates 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}\end{DoxyCompactItemize}
\subsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a987d5c090f8875b3f847ffcedfcbbec3}\label{namespacemom__eos__wright_a987d5c090f8875b3f847ffcedfcbbec3}} 
real, parameter \hyperlink{namespacemom__eos__wright_a987d5c090f8875b3f847ffcedfcbbec3}{a0} = 7.\+057924e-\/4
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a7e7cc154421595caa7f3624fe1ca3673}\label{namespacemom__eos__wright_a7e7cc154421595caa7f3624fe1ca3673}} 
real, parameter \hyperlink{namespacemom__eos__wright_a7e7cc154421595caa7f3624fe1ca3673}{a1} = 3.\+480336e-\/7
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a4a32a06ae840315cf54baa44822e348d}\label{namespacemom__eos__wright_a4a32a06ae840315cf54baa44822e348d}} 
real, parameter \hyperlink{namespacemom__eos__wright_a4a32a06ae840315cf54baa44822e348d}{a2} = -\/1.\+112733e-\/7
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_af4229fb5d51c0a7ff4728400c07f8b27}\label{namespacemom__eos__wright_af4229fb5d51c0a7ff4728400c07f8b27}} 
real, parameter \hyperlink{namespacemom__eos__wright_af4229fb5d51c0a7ff4728400c07f8b27}{b0} = 5.\+790749e8
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a50e15ae674d09fcbb22d050ba02d8a45}\label{namespacemom__eos__wright_a50e15ae674d09fcbb22d050ba02d8a45}} 
real, parameter \hyperlink{namespacemom__eos__wright_a50e15ae674d09fcbb22d050ba02d8a45}{b1} = 3.\+516535e6
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a7789c35566542d0531bec1e59bfb0142}\label{namespacemom__eos__wright_a7789c35566542d0531bec1e59bfb0142}} 
real, parameter \hyperlink{namespacemom__eos__wright_a7789c35566542d0531bec1e59bfb0142}{b2} = -\/4.\+002714e4
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a6d60b717365295a1cc748ca0952799dc}\label{namespacemom__eos__wright_a6d60b717365295a1cc748ca0952799dc}} 
real, parameter \hyperlink{namespacemom__eos__wright_a6d60b717365295a1cc748ca0952799dc}{b3} = 2.\+084372e2
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a56b4d3d9cbd8ef16485d99c207214806}\label{namespacemom__eos__wright_a56b4d3d9cbd8ef16485d99c207214806}} 
real, parameter \hyperlink{namespacemom__eos__wright_a56b4d3d9cbd8ef16485d99c207214806}{b4} = 5.\+944068e5
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a9db48983c2f40b67bc472fe5f9621a7e}\label{namespacemom__eos__wright_a9db48983c2f40b67bc472fe5f9621a7e}} 
real, parameter \hyperlink{namespacemom__eos__wright_a9db48983c2f40b67bc472fe5f9621a7e}{b5} = -\/9.\+643486e3
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a218345b2966cffd9e1ef2b17170e8525}\label{namespacemom__eos__wright_a218345b2966cffd9e1ef2b17170e8525}} 
real, parameter \hyperlink{namespacemom__eos__wright_a218345b2966cffd9e1ef2b17170e8525}{c0} = 1.\+704853e5
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a31d4375b948d86099cb395cab4b9a771}\label{namespacemom__eos__wright_a31d4375b948d86099cb395cab4b9a771}} 
real, parameter \hyperlink{namespacemom__eos__wright_a31d4375b948d86099cb395cab4b9a771}{c1} = 7.\+904722e2
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a8cac4a7420b6ac57f3c9e1abc251a110}\label{namespacemom__eos__wright_a8cac4a7420b6ac57f3c9e1abc251a110}} 
real, parameter \hyperlink{namespacemom__eos__wright_a8cac4a7420b6ac57f3c9e1abc251a110}{c2} = -\/7.\+984422
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a4cb9d874402c19becc87294045861267}\label{namespacemom__eos__wright_a4cb9d874402c19becc87294045861267}} 
real, parameter \hyperlink{namespacemom__eos__wright_a4cb9d874402c19becc87294045861267}{c3} = 5.\+140652e-\/2
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a946198aad59501f936a956f6f9da0861}\label{namespacemom__eos__wright_a946198aad59501f936a956f6f9da0861}} 
real, parameter \hyperlink{namespacemom__eos__wright_a946198aad59501f936a956f6f9da0861}{c4} = -\/2.\+302158e2
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__eos__wright_a240d653273908c24302d935f94f32c4c}\label{namespacemom__eos__wright_a240d653273908c24302d935f94f32c4c}} 
real, parameter \hyperlink{namespacemom__eos__wright_a240d653273908c24302d935f94f32c4c}{c5} = -\/3.\+079464
\begin{DoxyCompactList}\small\item\em Parameters in the Wright equation of state. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__eos__wright_ab5610ab6dd25f488ff5821dcbde78e0d}\label{namespacemom__eos__wright_ab5610ab6dd25f488ff5821dcbde78e0d}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+compress\+\_\+wright@{calculate\+\_\+compress\+\_\+wright}}
\index{calculate\+\_\+compress\+\_\+wright@{calculate\+\_\+compress\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+compress\+\_\+wright()}{calculate\_compress\_wright()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+compress\+\_\+wright (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(inout)}]{rho,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+dp,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts }\end{DoxyParamCaption})}



This subroutine computes the in situ density of sea water (rho in \mbox{[}kg m-\/3\mbox{]}) and the compressibility (drho/dp = C\+\_\+sound$^\wedge$-\/2) (drho\+\_\+dp \mbox{[}s2 m-\/2\mbox{]}) from salinity (sal in psu), potential temperature (T \mbox{[}degC\mbox{]}), and pressure \mbox{[}Pa\mbox{]}. It uses the expressions from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. Coded by R. Hallberg, 1/01. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em rho} & In situ density \mbox{[}kg m-\/3\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+dp} & The partial derivative of density with pressure (also the inverse of the square of sound speed) \mbox{[}s2 m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em start} & The starting point in the arrays.\\
\hline
\mbox{\tt in}  & {\em npts} & The number of values to calculate. \\
\hline
\end{DoxyParams}


Definition at line 380 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
380   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: t\textcolor{comment}{        !< Potential temperature relative to the surface [degC].}
381   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: s\textcolor{comment}{        !< Salinity [PSU].}
382   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: pressure\textcolor{comment}{ !< pressure [Pa].}
383   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{dimension(:)} :: rho\textcolor{comment}{      !< In situ density [kg m-3].}
384   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{dimension(:)} :: drho\_dp\textcolor{comment}{  !< The partial derivative of density with pressure}
385 \textcolor{comment}{                                                   !! (also the inverse of the square of sound speed)}
386 \textcolor{comment}{                                                   !! [s2 m-2].}
387   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}                  :: start\textcolor{comment}{    !< The starting point in the arrays.}
388   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}                  :: npts\textcolor{comment}{     !< The number of values to calculate.}
389 
390   \textcolor{comment}{! Coded by R. Hallberg, 1/01}
391   \textcolor{comment}{! Local variables}
392   \textcolor{keywordtype}{real} :: al0, p0, lambda, i\_denom
393   \textcolor{keywordtype}{integer} :: j
394 
395   \textcolor{keywordflow}{do} j=start,start+npts-1
396     al0 = (a0 + a1*t(j)) +a2*s(j)
397     p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
398     lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
399 
400     i\_denom = 1.0 / (lambda + al0*(pressure(j) + p0))
401     rho(j) = (pressure(j) + p0) * i\_denom
402     drho\_dp(j) = lambda * i\_denom * i\_denom
403 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a9d96824061e9c3d438c3d909a00fb7ab}\label{namespacemom__eos__wright_a9d96824061e9c3d438c3d909a00fb7ab}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+density\+\_\+array\+\_\+wright@{calculate\+\_\+density\+\_\+array\+\_\+wright}}
\index{calculate\+\_\+density\+\_\+array\+\_\+wright@{calculate\+\_\+density\+\_\+array\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+density\+\_\+array\+\_\+wright()}{calculate\_density\_array\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+density\+\_\+array\+\_\+wright (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(inout)}]{rho,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts,  }\item[{real, intent(in), optional}]{rho\+\_\+ref }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine computes the in situ density of sea water (rho in \mbox{[}kg m-\/3\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}), and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em rho} & in situ density \mbox{[}kg m-\/3\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em start} & the starting point in the arrays.\\
\hline
\mbox{\tt in}  & {\em npts} & the number of values to calculate.\\
\hline
\mbox{\tt in}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 111 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
111   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: t\textcolor{comment}{        !< potential temperature relative to the surface [degC].}
112   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: s\textcolor{comment}{        !< salinity [PSU].}
113   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: pressure\textcolor{comment}{ !< pressure [Pa].}
114   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: rho\textcolor{comment}{      !< in situ density [kg m-3].}
115   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: start\textcolor{comment}{    !< the starting point in the arrays.}
116   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: npts\textcolor{comment}{     !< the number of values to calculate.}
117   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: rho\_ref\textcolor{comment}{  !< A reference density [kg m-3].}
118 
119   \textcolor{comment}{! Original coded by R. Hallberg, 7/00, anomaly coded in 3/18.}
120   \textcolor{comment}{! Local variables}
121   \textcolor{keywordtype}{real} :: al0, p0, lambda
122   \textcolor{keywordtype}{real} :: al\_ts, p\_tsp, lam\_ts, pa\_000
123   \textcolor{keywordtype}{integer} :: j
124 
125   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(rho\_ref)) pa\_000 = (b0*(1.0 - a0*rho\_ref) - rho\_ref*c0)
126   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(rho\_ref)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=start,start+npts-1
127     al\_ts = a1*t(j) +a2*s(j)
128     al0 = a0 + al\_ts
129     p\_tsp = pressure(j) + (b4*s(j) + t(j) * (b1 + (t(j)*(b2 + b3*t(j)) + b5*s(j))))
130     lam\_ts = c4*s(j) + t(j) * (c1 + (t(j)*(c2 + c3*t(j)) + c5*s(j)))
131 
132     \textcolor{comment}{! The following two expressions are mathematically equivalent.}
133     \textcolor{comment}{! rho(j) = (b0 + p0\_TSp) / ((c0 + lam\_TS) + al0*(b0 + p0\_TSp)) - rho\_ref}
134     rho(j) = (pa\_000 + (p\_tsp - rho\_ref*(p\_tsp*al0 + (b0*al\_ts + lam\_ts)))) / &
135              ( (c0 + lam\_ts) + al0*(b0 + p\_tsp) )
136 \textcolor{keywordflow}{  enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} j=start,start+npts-1
137     al0 = (a0 + a1*t(j)) +a2*s(j)
138     p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*(b2 + b3*t(j)) + b5*s(j))
139     lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*(c2 + c3*t(j)) + c5*s(j))
140     rho(j) = (pressure(j) + p0) / (lambda + al0*(pressure(j) + p0))
141 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}
142 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a576d1ff13c93f4a3ffbd483d43a78ab7}\label{namespacemom__eos__wright_a576d1ff13c93f4a3ffbd483d43a78ab7}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright@{calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright}}
\index{calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright@{calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright()}{calculate\_density\_derivs\_array\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+density\+\_\+derivs\+\_\+array\+\_\+wright (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+dT,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+dS,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



For a given thermodynamic state, return the thermal/haline expansion coefficients. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+dt} & The partial derivative of density with potential temperature \mbox{[}kg m-\/3 deg\+C-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+ds} & The partial derivative of density with salinity, in \mbox{[}kg m-\/3 P\+S\+U-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em start} & The starting point in the arrays.\\
\hline
\mbox{\tt in}  & {\em npts} & The number of values to calculate. \\
\hline
\end{DoxyParams}


Definition at line 200 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
200   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: t\textcolor{comment}{        !< Potential temperature relative to the}
201 \textcolor{comment}{                                                   !! surface [degC].}
202   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: s\textcolor{comment}{        !< Salinity [PSU].}
203   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: pressure\textcolor{comment}{ !< pressure [Pa].}
204   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{dimension(:)} :: drho\_dt\textcolor{comment}{  !< The partial derivative of density with potential}
205 \textcolor{comment}{                                                   !! temperature [kg m-3 degC-1].}
206   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{dimension(:)} :: drho\_ds\textcolor{comment}{  !< The partial derivative of density with salinity,}
207 \textcolor{comment}{                                                   !! in [kg m-3 PSU-1].}
208   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}                  :: start\textcolor{comment}{    !< The starting point in the arrays.}
209   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}                  :: npts\textcolor{comment}{     !< The number of values to calculate.}
210 
211   \textcolor{comment}{! Local variables}
212   \textcolor{keywordtype}{real} :: al0, p0, lambda, i\_denom2
213   \textcolor{keywordtype}{integer} :: j
214 
215   \textcolor{keywordflow}{do} j=start,start+npts-1
216     al0 = (a0 + a1*t(j)) + a2*s(j)
217     p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
218     lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
219 
220     i\_denom2 = 1.0 / (lambda + al0*(pressure(j) + p0))
221     i\_denom2 = i\_denom2 *i\_denom2
222     drho\_dt(j) = i\_denom2 * &
223       (lambda* (b1 + t(j)*(2.0*b2 + 3.0*b3*t(j)) + b5*s(j)) - &
224        (pressure(j)+p0) * ( (pressure(j)+p0)*a1 + &
225         (c1 + t(j)*(c2*2.0 + c3*3.0*t(j)) + c5*s(j)) ))
226     drho\_ds(j) = i\_denom2 * (lambda* (b4 + b5*t(j)) - &
227       (pressure(j)+p0) * ( (pressure(j)+p0)*a2 + (c4 + c5*t(j)) ))
228 \textcolor{keywordflow}{  enddo}
229 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a8264a21fbe5809d5290ea388e0b2e64f}\label{namespacemom__eos__wright_a8264a21fbe5809d5290ea388e0b2e64f}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright@{calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright}}
\index{calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright@{calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright()}{calculate\_density\_derivs\_scalar\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+density\+\_\+derivs\+\_\+scalar\+\_\+wright (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T,  }\item[{real, intent(in)}]{S,  }\item[{real, intent(in)}]{pressure,  }\item[{real, intent(out)}]{drho\+\_\+dT,  }\item[{real, intent(out)}]{drho\+\_\+dS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The scalar version of calculate\+\_\+density\+\_\+derivs which promotes scalar inputs to a 1-\/element array and then demotes the output back to a scalar. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+dt} & The partial derivative of density with potential temperature \mbox{[}kg m-\/3 deg\+C-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+ds} & The partial derivative of density with salinity, in \mbox{[}kg m-\/3 P\+S\+U-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 235 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
235   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)}  :: t\textcolor{comment}{        !< Potential temperature relative to the surface [degC].}
236   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)}  :: s\textcolor{comment}{        !< Salinity [PSU].}
237   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)}  :: pressure\textcolor{comment}{ !< pressure [Pa].}
238   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(out)} :: drho\_dt\textcolor{comment}{  !< The partial derivative of density with potential}
239 \textcolor{comment}{                                   !! temperature [kg m-3 degC-1].}
240   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(out)} :: drho\_ds\textcolor{comment}{  !< The partial derivative of density with salinity,}
241 \textcolor{comment}{                                   !! in [kg m-3 PSU-1].}
242 
243   \textcolor{comment}{! Local variables needed to promote the input/output scalars to 1-element arrays}
244   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1)} :: t0, s0, p0
245   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1)} :: drdt0, drds0
246 
247   t0(1) = t
248   s0(1) = s
249   p0(1) = pressure
250   \textcolor{keyword}{call }calculate\_density\_derivs\_array\_wright(t0, s0, p0, drdt0, drds0, 1, 1)
251   drho\_dt = drdt0(1)
252   drho\_ds = drds0(1)
253 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a047725cee226bb5621080176aaff36d6}\label{namespacemom__eos__wright_a047725cee226bb5621080176aaff36d6}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+density\+\_\+scalar\+\_\+wright@{calculate\+\_\+density\+\_\+scalar\+\_\+wright}}
\index{calculate\+\_\+density\+\_\+scalar\+\_\+wright@{calculate\+\_\+density\+\_\+scalar\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+density\+\_\+scalar\+\_\+wright()}{calculate\_density\_scalar\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+density\+\_\+scalar\+\_\+wright (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T,  }\item[{real, intent(in)}]{S,  }\item[{real, intent(in)}]{pressure,  }\item[{real, intent(out)}]{rho,  }\item[{real, intent(in), optional}]{rho\+\_\+ref }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine computes the in situ density of sea water (rho in \mbox{[}kg m-\/3\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}), and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em rho} & In situ density \mbox{[}kg m-\/3\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 81 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
81   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(in)}  :: t\textcolor{comment}{        !< Potential temperature relative to the surface [degC].}
82   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(in)}  :: s\textcolor{comment}{        !< Salinity [PSU].}
83   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(in)}  :: pressure\textcolor{comment}{ !< pressure [Pa].}
84   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(out)} :: rho\textcolor{comment}{      !< In situ density [kg m-3].}
85   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{  !< A reference density [kg m-3].}
86 
87 \textcolor{comment}{! *====================================================================*}
88 \textcolor{comment}{! *  This subroutine computes the in situ density of sea water (rho in *}
89 \textcolor{comment}{! *  [kg m-3]) from salinity (S [PSU]), potential temperature  *}
90 \textcolor{comment}{! *  (T [degC]), and pressure [Pa].  It uses the expression from    *}
91 \textcolor{comment}{! *  Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.                *}
92 \textcolor{comment}{! *  Coded by R. Hallberg, 7/00                                        *}
93 \textcolor{comment}{! *====================================================================*}
94 
95   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1)} :: t0, s0, pressure0, rho0
96 
97   t0(1) = t
98   s0(1) = s
99   pressure0(1) = pressure
100 
101   \textcolor{keyword}{call }calculate\_density\_array\_wright(t0, s0, pressure0, rho0, 1, 1, rho\_ref)
102   rho = rho0(1)
103 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a218432c80512597414f0c1fe4ae2d97d}\label{namespacemom__eos__wright_a218432c80512597414f0c1fe4ae2d97d}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright@{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright}}
\index{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright@{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright()}{calculate\_density\_second\_derivs\_array\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+array\+\_\+wright (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{P,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+ds\+\_\+ds,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+ds\+\_\+dt,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+dt\+\_\+dt,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+ds\+\_\+dp,  }\item[{real, dimension(\+:), intent(inout)}]{drho\+\_\+dt\+\_\+dp,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Second derivatives of density with respect to temperature, salinity, and pressure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature referenced to 0 dbar \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}\\
\hline
\mbox{\tt in}  & {\em p} & Pressure \mbox{[}Pa\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+ds\+\_\+ds} & Partial derivative of beta with respect to S \mbox{[}kg m-\/3 P\+S\+U-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+ds\+\_\+dt} & Partial derivative of beta with respcct to T \mbox{[}kg m-\/3 P\+S\+U-\/1 deg\+C-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+dt\+\_\+dt} & Partial derivative of alpha with respect to T \mbox{[}kg m-\/3 deg\+C-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+ds\+\_\+dp} & Partial derivative of beta with respect to pressure \mbox{[}kg m-\/3 P\+S\+U-\/1 Pa-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em drho\+\_\+dt\+\_\+dp} & Partial derivative of alpha with respect to pressure \mbox{[}kg m-\/3 deg\+C-\/1 Pa-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em start} & Starting index in T,S,P\\
\hline
\mbox{\tt in}  & {\em npts} & Number of points to loop over \\
\hline
\end{DoxyParams}


Definition at line 259 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
259   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in   )} :: t\textcolor{comment}{ !< Potential temperature referenced to 0 dbar [degC]}
260   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in   )} :: s\textcolor{comment}{ !< Salinity [PSU]}
261   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in   )} :: p\textcolor{comment}{ !< Pressure [Pa]}
262   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: drho\_ds\_ds\textcolor{comment}{ !< Partial derivative of beta with respect}
263 \textcolor{comment}{                                                  !! to S [kg m-3 PSU-2]}
264   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: drho\_ds\_dt\textcolor{comment}{ !< Partial derivative of beta with respcct}
265 \textcolor{comment}{                                                  !! to T [kg m-3 PSU-1 degC-1]}
266   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: drho\_dt\_dt\textcolor{comment}{ !< Partial derivative of alpha with respect}
267 \textcolor{comment}{                                                  !! to T [kg m-3 degC-2]}
268   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: drho\_ds\_dp\textcolor{comment}{ !< Partial derivative of beta with respect}
269 \textcolor{comment}{                                                  !! to pressure [kg m-3 PSU-1 Pa-1]}
270   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: drho\_dt\_dp\textcolor{comment}{ !< Partial derivative of alpha with respect}
271 \textcolor{comment}{                                                  !! to pressure [kg m-3 degC-1 Pa-1]}
272   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in   )} :: start\textcolor{comment}{ !< Starting index in T,S,P}
273   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in   )} :: npts\textcolor{comment}{  !< Number of points to loop over}
274 
275   \textcolor{comment}{! Local variables}
276   \textcolor{keywordtype}{real} :: z0, z1, z2, z3, z4, z5, z6 ,z7, z8, z9, z10, z11, z2\_2, z2\_3
277   \textcolor{keywordtype}{integer} :: j
278   \textcolor{comment}{! Based on the above expression with common terms factored, there probably exists a more numerically
       stable}
279   \textcolor{comment}{! and/or efficient expression}
280 
281   \textcolor{keywordflow}{do} j = start,start+npts-1
282     z0 = t(j)*(b1 + b5*s(j) + t(j)*(b2 + b3*t(j)))
283     z1 = (b0 + p(j) + b4*s(j) + z0)
284     z3 = (b1 + b5*s(j) + t(j)*(2.*b2 + 2.*b3*t(j)))
285     z4 = (c0 + c4*s(j) + t(j)*(c1 + c5*s(j) + t(j)*(c2 + c3*t(j))))
286     z5 = (b1 + b5*s(j) + t(j)*(b2 + b3*t(j)) + t(j)*(b2 + 2.*b3*t(j)))
287     z6 = c1 + c5*s(j) + t(j)*(c2 + c3*t(j)) + t(j)*(c2 + 2.*c3*t(j))
288     z7 = (c4 + c5*t(j) + a2*z1)
289     z8 = (c1 + c5*s(j) + t(j)*(2.*c2 + 3.*c3*t(j)) + a1*z1)
290     z9 = (a0 + a2*s(j) + a1*t(j))
291     z10 = (b4 + b5*t(j))
292     z11 = (z10*z4 - z1*z7)
293     z2 = (c0 + c4*s(j) + t(j)*(c1 + c5*s(j) + t(j)*(c2 + c3*t(j))) + z9*z1)
294     z2\_2 = z2*z2
295     z2\_3 = z2\_2*z2
296 
297     drho\_ds\_ds(j) = (z10*(c4 + c5*t(j)) - a2*z10*z1 - z10*z7)/z2\_2 - (2.*(c4 + c5*t(j) + z9*z10 + a2*z1)*
      z11)/z2\_3
298     drho\_ds\_dt(j) = (z10*z6 - z1*(c5 + a2*z5) + b5*z4 - z5*z7)/z2\_2 - (2.*(z6 + z9*z5 + a1*z1)*z11)/z2\_3
299     drho\_dt\_dt(j) = (z3*z6 - z1*(2.*c2 + 6.*c3*t(j) + a1*z5) + (2.*b2 + 4.*b3*t(j))*z4 - z5*z8)/z2\_2 - &
300                     (2.*(z6 + z9*z5 + a1*z1)*(z3*z4 - z1*z8))/z2\_3
301     drho\_ds\_dp(j) = (-c4 - c5*t(j) - 2.*a2*z1)/z2\_2 - (2.*z9*z11)/z2\_3
302     drho\_dt\_dp(j) = (-c1 - c5*s(j) - t(j)*(2.*c2 + 3.*c3*t(j)) - 2.*a1*z1)/z2\_2 - (2.*z9*(z3*z4 - z1*z8))/
      z2\_3
303 \textcolor{keywordflow}{  enddo}
304 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a74e1c5129ef4414337347a115bcdff10}\label{namespacemom__eos__wright_a74e1c5129ef4414337347a115bcdff10}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright@{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright}}
\index{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright@{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright()}{calculate\_density\_second\_derivs\_scalar\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+density\+\_\+second\+\_\+derivs\+\_\+scalar\+\_\+wright (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T,  }\item[{real, intent(in)}]{S,  }\item[{real, intent(in)}]{P,  }\item[{real, intent(out)}]{drho\+\_\+ds\+\_\+ds,  }\item[{real, intent(out)}]{drho\+\_\+ds\+\_\+dt,  }\item[{real, intent(out)}]{drho\+\_\+dt\+\_\+dt,  }\item[{real, intent(out)}]{drho\+\_\+ds\+\_\+dp,  }\item[{real, intent(out)}]{drho\+\_\+dt\+\_\+dp }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Second derivatives of density with respect to temperature, salinity, and pressure for scalar inputs. Inputs promoted to 1-\/element array and output demoted to scalar. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature referenced to 0 dbar\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}\\
\hline
\mbox{\tt in}  & {\em p} & pressure \mbox{[}Pa\mbox{]}\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+ds\+\_\+ds} & Partial derivative of beta with respect to S \mbox{[}kg m-\/3 P\+S\+U-\/2\mbox{]}\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+ds\+\_\+dt} & Partial derivative of beta with respcct to T \mbox{[}kg m-\/3 P\+S\+U-\/1 deg\+C-\/1\mbox{]}\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+dt\+\_\+dt} & Partial derivative of alpha with respect to T \mbox{[}kg m-\/3 deg\+C-\/2\mbox{]}\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+ds\+\_\+dp} & Partial derivative of beta with respect to pressure \mbox{[}kg m-\/3 P\+S\+U-\/1 Pa-\/1\mbox{]}\\
\hline
\mbox{\tt out}  & {\em drho\+\_\+dt\+\_\+dp} & Partial derivative of alpha with respect to pressure \mbox{[}kg m-\/3 deg\+C-\/1 Pa-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 311 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
311   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in   )} :: t\textcolor{comment}{          !< Potential temperature referenced to 0 dbar}
312   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in   )} :: s\textcolor{comment}{          !< Salinity [PSU]}
313   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in   )} :: p\textcolor{comment}{          !< pressure [Pa]}
314   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(  out)} :: drho\_ds\_ds\textcolor{comment}{ !< Partial derivative of beta with respect}
315 \textcolor{comment}{                                    !! to S [kg m-3 PSU-2]}
316   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(  out)} :: drho\_ds\_dt\textcolor{comment}{ !< Partial derivative of beta with respcct}
317 \textcolor{comment}{                                    !! to T [kg m-3 PSU-1 degC-1]}
318   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(  out)} :: drho\_dt\_dt\textcolor{comment}{ !< Partial derivative of alpha with respect}
319 \textcolor{comment}{                                    !! to T [kg m-3 degC-2]}
320   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(  out)} :: drho\_ds\_dp\textcolor{comment}{ !< Partial derivative of beta with respect}
321 \textcolor{comment}{                                    !! to pressure [kg m-3 PSU-1 Pa-1]}
322   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(  out)} :: drho\_dt\_dp\textcolor{comment}{ !< Partial derivative of alpha with respect}
323 \textcolor{comment}{                                    !! to pressure [kg m-3 degC-1 Pa-1]}
324   \textcolor{comment}{! Local variables}
325   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1)} :: t0, s0, p0
326   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1)} :: drdsds, drdsdt, drdtdt, drdsdp, drdtdp
327 
328   t0(1) = t
329   s0(1) = s
330   p0(1) = p
331   \textcolor{keyword}{call }calculate\_density\_second\_derivs\_array\_wright(t0, s0, p0, drdsds, drdsdt, drdtdt, drdsdp, drdtdp, 1, 
      1)
332   drho\_ds\_ds = drdsds(1)
333   drho\_ds\_dt = drdsdt(1)
334   drho\_dt\_dt = drdtdt(1)
335   drho\_ds\_dp = drdsdp(1)
336   drho\_dt\_dp = drdtdp(1)
337 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a0e1da760ed0fca53533430d0bd03ee6d}\label{namespacemom__eos__wright_a0e1da760ed0fca53533430d0bd03ee6d}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright@{calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright}}
\index{calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright@{calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright()}{calculate\_spec\_vol\_array\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+spec\+\_\+vol\+\_\+array\+\_\+wright (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(inout)}]{specvol,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts,  }\item[{real, intent(in), optional}]{spv\+\_\+ref }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine computes the in situ specific volume of sea water (specvol in \mbox{[}m3 kg-\/1\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}) and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. If spv\+\_\+ref is present, specvol is an anomaly from spv\+\_\+ref. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em specvol} & in situ specific volume \mbox{[}m3 kg-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em start} & the starting point in the arrays.\\
\hline
\mbox{\tt in}  & {\em npts} & the number of values to calculate.\\
\hline
\mbox{\tt in}  & {\em spv\+\_\+ref} & A reference specific volume \mbox{[}m3 kg-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 172 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
172   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: t\textcolor{comment}{        !< potential temperature relative to the}
173 \textcolor{comment}{                                              !! surface [degC].}
174   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: s\textcolor{comment}{        !< salinity [PSU].}
175   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: pressure\textcolor{comment}{ !< pressure [Pa].}
176   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: specvol\textcolor{comment}{  !< in situ specific volume [m3 kg-1].}
177   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: start\textcolor{comment}{    !< the starting point in the arrays.}
178   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: npts\textcolor{comment}{     !< the number of values to calculate.}
179   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: spv\_ref\textcolor{comment}{  !< A reference specific volume [m3 kg-1].}
180 
181   \textcolor{comment}{! Local variables}
182   \textcolor{keywordtype}{real} :: al0, p0, lambda
183   \textcolor{keywordtype}{integer} :: j
184 
185   \textcolor{keywordflow}{do} j=start,start+npts-1
186     al0 = (a0 + a1*t(j)) +a2*s(j)
187     p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
188     lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
189 
190     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(spv\_ref)) \textcolor{keywordflow}{then}
191       specvol(j) = (lambda + (al0 - spv\_ref)*(pressure(j) + p0)) / (pressure(j) + p0)
192     \textcolor{keywordflow}{else}
193       specvol(j) = (lambda + al0*(pressure(j) + p0)) / (pressure(j) + p0)
194 \textcolor{keywordflow}{    endif}
195 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_aa1577bed7878372af9be62afea06cbf0}\label{namespacemom__eos__wright_aa1577bed7878372af9be62afea06cbf0}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright@{calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright}}
\index{calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright@{calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright()}{calculate\_spec\_vol\_scalar\_wright()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+spec\+\_\+vol\+\_\+scalar\+\_\+wright (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T,  }\item[{real, intent(in)}]{S,  }\item[{real, intent(in)}]{pressure,  }\item[{real, intent(out)}]{specvol,  }\item[{real, intent(in), optional}]{spv\+\_\+ref }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine computes the in situ specific volume of sea water (specvol in \mbox{[}m3 kg-\/1\mbox{]}) from salinity (S \mbox{[}P\+SU\mbox{]}), potential temperature (T \mbox{[}degC\mbox{]}) and pressure \mbox{[}Pa\mbox{]}. It uses the expression from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-\/740. If spv\+\_\+ref is present, specvol is an anomaly from spv\+\_\+ref. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em specvol} & in situ specific volume \mbox{[}m3 kg-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em spv\+\_\+ref} & A reference specific volume \mbox{[}m3 kg-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 151 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
151   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(in)}  :: t\textcolor{comment}{        !< potential temperature relative to the surface [degC].}
152   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(in)}  :: s\textcolor{comment}{        !< salinity [PSU].}
153   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(in)}  :: pressure\textcolor{comment}{ !< pressure [Pa].}
154   \textcolor{keywordtype}{real},           \textcolor{keywordtype}{intent(out)} :: specvol\textcolor{comment}{  !< in situ specific volume [m3 kg-1].}
155   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: spv\_ref\textcolor{comment}{  !< A reference specific volume [m3 kg-1].}
156 
157   \textcolor{comment}{! Local variables}
158   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1)} :: t0, s0, pressure0, spv0
159 
160   t0(1) = t ; s0(1) = s ; pressure0(1) = pressure
161 
162   \textcolor{keyword}{call }calculate\_spec\_vol\_array\_wright(t0, s0, pressure0, spv0, 1, 1, spv\_ref)
163   specvol = spv0(1)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a890d098ddbdc76f6cfbf1b7cf19b6388}\label{namespacemom__eos__wright_a890d098ddbdc76f6cfbf1b7cf19b6388}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!calculate\+\_\+specvol\+\_\+derivs\+\_\+wright@{calculate\+\_\+specvol\+\_\+derivs\+\_\+wright}}
\index{calculate\+\_\+specvol\+\_\+derivs\+\_\+wright@{calculate\+\_\+specvol\+\_\+derivs\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{calculate\+\_\+specvol\+\_\+derivs\+\_\+wright()}{calculate\_specvol\_derivs\_wright()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+eos\+\_\+wright\+::calculate\+\_\+specvol\+\_\+derivs\+\_\+wright (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(inout)}]{d\+S\+V\+\_\+dT,  }\item[{real, dimension(\+:), intent(inout)}]{d\+S\+V\+\_\+dS,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts }\end{DoxyParamCaption})}



For a given thermodynamic state, return the partial derivatives of specific volume with temperature and salinity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em pressure} & pressure \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em dsv\+\_\+dt} & The partial derivative of specific volume with potential temperature \mbox{[}m3 kg-\/1 deg\+C-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em dsv\+\_\+ds} & The partial derivative of specific volume with salinity \mbox{[}m3 kg-\/1 / Pa\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em start} & The starting point in the arrays.\\
\hline
\mbox{\tt in}  & {\em npts} & The number of values to calculate. \\
\hline
\end{DoxyParams}


Definition at line 343 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
343   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: t\textcolor{comment}{        !< Potential temperature relative to the surface [degC].}
344   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: s\textcolor{comment}{        !< Salinity [PSU].}
345   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)},    \textcolor{keywordtype}{dimension(:)} :: pressure\textcolor{comment}{ !< pressure [Pa].}
346   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{dimension(:)} :: dsv\_dt\textcolor{comment}{   !< The partial derivative of specific volume with}
347 \textcolor{comment}{                                                   !! potential temperature [m3 kg-1 degC-1].}
348   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{dimension(:)} :: dsv\_ds\textcolor{comment}{   !< The partial derivative of specific volume with}
349 \textcolor{comment}{                                                   !! salinity [m3 kg-1 / Pa].}
350   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}                  :: start\textcolor{comment}{    !< The starting point in the arrays.}
351   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}                  :: npts\textcolor{comment}{     !< The number of values to calculate.}
352 
353   \textcolor{comment}{! Local variables}
354   \textcolor{keywordtype}{real} :: al0, p0, lambda, i\_denom
355   \textcolor{keywordtype}{integer} :: j
356 
357   \textcolor{keywordflow}{do} j=start,start+npts-1
358 \textcolor{comment}{!    al0 = (a0 + a1*T(j)) + a2*S(j)}
359     p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
360     lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
361 
362     \textcolor{comment}{! SV = al0 + lambda / (pressure(j) + p0)}
363 
364     i\_denom = 1.0 / (pressure(j) + p0)
365     dsv\_dt(j) = (a1 + i\_denom * (c1 + t(j)*((2.0*c2 + 3.0*c3*t(j))) + c5*s(j))) - &
366                 (i\_denom**2 * lambda) *  (b1 + t(j)*((2.0*b2 + 3.0*b3*t(j))) + b5*s(j))
367     dsv\_ds(j) = (a2 + i\_denom * (c4 + c5*t(j))) - &
368                 (i\_denom**2 * lambda) *  (b4 + b5*t(j))
369 \textcolor{keywordflow}{  enddo}
370 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_ac94eaa2504eb4ccb12b41add45e1301e}\label{namespacemom__eos__wright_ac94eaa2504eb4ccb12b41add45e1301e}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!int\+\_\+density\+\_\+dz\+\_\+wright@{int\+\_\+density\+\_\+dz\+\_\+wright}}
\index{int\+\_\+density\+\_\+dz\+\_\+wright@{int\+\_\+density\+\_\+dz\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{int\+\_\+density\+\_\+dz\+\_\+wright()}{int\_density\_dz\_wright()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+eos\+\_\+wright\+::int\+\_\+density\+\_\+dz\+\_\+wright (\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[{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,  }\item[{real, intent(in), optional}]{rho\+\_\+scale,  }\item[{real, intent(in), optional}]{pres\+\_\+scale }\end{DoxyParamCaption})}



This subroutine calculates analytical and nearly-\/analytical 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{\tt in}  & {\em hi} & The horizontal index type for the arrays.\\
\hline
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em z\+\_\+t} & Height at the top of the layer in depth units \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em z\+\_\+b} & Height at the top of the layer \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt 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. (The pressure is calucated as p$\sim$=-\/z$\ast$rho\+\_\+0$\ast$\+G\+\_\+e.)\\
\hline
\mbox{\tt in}  & {\em rho\+\_\+0} & 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{\tt 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
\mbox{\tt in,out}  & {\em dpa} & The change in the pressure anomaly across the\\
\hline
\mbox{\tt in,out}  & {\em intz\+\_\+dpa} & The integral through the thickness of the layer\\
\hline
\mbox{\tt in,out}  & {\em intx\+\_\+dpa} & The integral in x of the difference between the\\
\hline
\mbox{\tt in,out}  & {\em inty\+\_\+dpa} & The integral in y of the difference between the\\
\hline
\mbox{\tt in}  & {\em bathyt} & The depth of the bathymetry \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dz\+\_\+neglect} & A miniscule thickness change \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals.\\
\hline
\mbox{\tt in}  & {\em rho\+\_\+scale} & A multiplicative factor by which to scale density from kg m-\/3 to the desired units \mbox{[}R m3 kg-\/1 $\sim$$>$ 1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em pres\+\_\+scale} & A multiplicative factor to convert pressure into Pa \mbox{[}Pa T2 R-\/1 L-\/2 $\sim$$>$ 1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 412 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
412   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: hi\textcolor{comment}{       !< The horizontal index type for the arrays.}
413   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
414                         \textcolor{keywordtype}{intent(in)}  :: t\textcolor{comment}{        !< Potential temperature relative to the surface}
415 \textcolor{comment}{                                                !! [degC].}
416   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
417                         \textcolor{keywordtype}{intent(in)}  :: s\textcolor{comment}{        !< Salinity [PSU].}
418   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
419                         \textcolor{keywordtype}{intent(in)}  :: z\_t\textcolor{comment}{      !< Height at the top of the layer in depth units [Z ~> m].}
420   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
421                         \textcolor{keywordtype}{intent(in)}  :: z\_b\textcolor{comment}{      !< Height at the top of the layer [Z ~> m].}
422   \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}
423 \textcolor{comment}{                                                !! out to reduce the magnitude of each of the integrals.}
424 \textcolor{comment}{                                                !! (The pressure is calucated as p~=-z*rho\_0*G\_e.)}
425   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)}  :: rho\_0\textcolor{comment}{    !< Density [R ~> kg m-3] or [kg m-3], that is used}
426 \textcolor{comment}{                                                !! to calculate the pressure (as p~=-z*rho\_0*G\_e)}
427 \textcolor{comment}{                                                !! used in the equation of state.}
428   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)}  :: g\_e\textcolor{comment}{      !< The Earth's gravitational acceleration}
429 \textcolor{comment}{                                                !! [L2 Z-1 T-2 ~> m s-2] or [m2 Z-1 s-2 ~> m s-2].}
430   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
431                         \textcolor{keywordtype}{intent(inout)} :: dpa\textcolor{comment}{    !< The change in the pressure anomaly across the}
432 \textcolor{comment}{                                                !! layer [R L2 T-2 ~> Pa] or [Pa].}
433   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
434               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intz\_dpa\textcolor{comment}{ !< The integral through the thickness of the layer}
435 \textcolor{comment}{                                                !! of the pressure anomaly relative to the anomaly}
436 \textcolor{comment}{                                                !! at the top of the layer [R Z L2 T-2 ~> Pa m].}
437   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%IsdB:HI%IedB,HI%jsd:HI%jed)}, &
438               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dpa\textcolor{comment}{ !< The integral in x of the difference between the}
439 \textcolor{comment}{                                                !! pressure anomaly at the top and bottom of the}
440 \textcolor{comment}{                                                !! layer divided by the x grid spacing [R L2 T-2 ~> Pa].}
441   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%JsdB:HI%JedB)}, &
442               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dpa\textcolor{comment}{ !< The integral in y of the difference between the}
443 \textcolor{comment}{                                                !! pressure anomaly at the top and bottom of the}
444 \textcolor{comment}{                                                !! layer divided by the y grid spacing [R L2 T-2 ~> Pa].}
445   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
446               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: bathyt\textcolor{comment}{   !< The depth of the bathymetry [Z ~> m].}
447   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dz\_neglect\textcolor{comment}{ !< A miniscule thickness change [Z ~> m].}
448   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: usemasswghtinterp\textcolor{comment}{ !< If true, uses mass weighting to}
449 \textcolor{comment}{                                                !! interpolate T/S for top and bottom integrals.}
450   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: rho\_scale\textcolor{comment}{ !< A multiplicative factor by which to scale density}
451 \textcolor{comment}{                                                 !! from kg m-3 to the desired units [R m3 kg-1 ~> 1]}
452   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: pres\_scale\textcolor{comment}{ !< A multiplicative factor to convert pressure}
453 \textcolor{comment}{                                                 !! into Pa [Pa T2 R-1 L-2 ~> 1].}
454 
455   \textcolor{comment}{! Local variables}
456   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)} :: al0\_2d, p0\_2d, lambda\_2d
457   \textcolor{keywordtype}{real} :: al0, p0, lambda
458   \textcolor{keywordtype}{real} :: rho\_anom   \textcolor{comment}{! The density anomaly from rho\_ref [kg m-3].}
459   \textcolor{keywordtype}{real} :: eps, eps2, rem
460   \textcolor{keywordtype}{real} :: gxrho      \textcolor{comment}{! The gravitational acceleration times density and unit conversion factors [Pa Z-1 ~>
       kg m-2 s-2]}
461   \textcolor{keywordtype}{real} :: g\_earth    \textcolor{comment}{! The gravitational acceleration [m2 Z-1 s-2 ~> m s-2]}
462   \textcolor{keywordtype}{real} :: i\_rho      \textcolor{comment}{! The inverse of the Boussinesq density [m3 kg-1]}
463   \textcolor{keywordtype}{real} :: rho\_ref\_mks \textcolor{comment}{! The reference density in MKS units, never rescaled from kg m-3 [kg m-3]}
464   \textcolor{keywordtype}{real} :: p\_ave, i\_al0, i\_lzz
465   \textcolor{keywordtype}{real} :: dz         \textcolor{comment}{! The layer thickness [Z ~> m].}
466   \textcolor{keywordtype}{real} :: hwght      \textcolor{comment}{! A pressure-thickness below topography [Z ~> m].}
467   \textcolor{keywordtype}{real} :: hl, hr     \textcolor{comment}{! Pressure-thicknesses of the columns to the left and right [Z ~> m].}
468   \textcolor{keywordtype}{real} :: idenom     \textcolor{comment}{! The inverse of the denominator in the weights [Z-2 ~> m-2].}
469   \textcolor{keywordtype}{real} :: hwt\_ll, hwt\_lr \textcolor{comment}{! hWt\_LA is the weighted influence of A on the left column [nondim].}
470   \textcolor{keywordtype}{real} :: hwt\_rl, hwt\_rr \textcolor{comment}{! hWt\_RA is the weighted influence of A on the right column [nondim].}
471   \textcolor{keywordtype}{real} :: wt\_l, wt\_r \textcolor{comment}{! The linear weights of the left and right columns [nondim].}
472   \textcolor{keywordtype}{real} :: wtt\_l, wtt\_r \textcolor{comment}{! The weights for tracers from the left and right columns [nondim].}
473   \textcolor{keywordtype}{real} :: intz(5)    \textcolor{comment}{! The integrals of density with height at the}
474                      \textcolor{comment}{! 5 sub-column locations [R L2 T-2 ~> Pa].}
475   \textcolor{keywordtype}{real} :: pa\_to\_rl2\_t2 \textcolor{comment}{! A conversion factor of pressures from Pa to the output units indicated by}
476                        \textcolor{comment}{! pres\_scale [R L2 T-2 Pa-1 ~> 1] or [1].}
477   \textcolor{keywordtype}{logical} :: do\_massweight \textcolor{comment}{! Indicates whether to do mass weighting.}
478   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: c1\_3 = 1.0/3.0, c1\_7 = 1.0/7.0    \textcolor{comment}{! Rational constants.}
479   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: c1\_9 = 1.0/9.0, c1\_90 = 1.0/90.0  \textcolor{comment}{! Rational constants.}
480   \textcolor{keywordtype}{integer} :: is, ie, js, je, isq, ieq, jsq, jeq, i, j, m
481 
482   \textcolor{comment}{! These array bounds work for the indexing convention of the input arrays, but}
483   \textcolor{comment}{! on the computational domain defined for the output arrays.}
484   isq = hi%IscB ; ieq = hi%IecB
485   jsq = hi%JscB ; jeq = hi%JecB
486   is = hi%isc ; ie = hi%iec
487   js = hi%jsc ; je = hi%jec
488 
489   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(pres\_scale)) \textcolor{keywordflow}{then}
490     gxrho = pres\_scale * g\_e * rho\_0 ; g\_earth = pres\_scale * g\_e
491     pa\_to\_rl2\_t2 = 1.0 / pres\_scale
492   \textcolor{keywordflow}{else}
493     gxrho = g\_e * rho\_0 ; g\_earth = g\_e
494     pa\_to\_rl2\_t2 = 1.0
495 \textcolor{keywordflow}{  endif}
496   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(rho\_scale)) \textcolor{keywordflow}{then}
497     g\_earth = g\_earth * rho\_scale
498     rho\_ref\_mks = rho\_ref / rho\_scale ; i\_rho = rho\_scale / rho\_0
499   \textcolor{keywordflow}{else}
500     rho\_ref\_mks = rho\_ref ; i\_rho = 1.0 / rho\_0
501 \textcolor{keywordflow}{  endif}
502 
503   do\_massweight = .false.
504   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (usemasswghtinterp) \textcolor{keywordflow}{then}
505     do\_massweight = .true.
506   \textcolor{comment}{! if (.not.present(bathyT)) call MOM\_error(FATAL, "int\_density\_dz\_generic: "//&}
507   \textcolor{comment}{!     "bathyT must be present if useMassWghtInterp is present and true.")}
508   \textcolor{comment}{! if (.not.present(dz\_neglect)) call MOM\_error(FATAL, "int\_density\_dz\_generic: "//&}
509   \textcolor{comment}{!     "dz\_neglect must be present if useMassWghtInterp is present and true.")}
510 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
511 
512   \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1
513     al0\_2d(i,j) = (a0 + a1*t(i,j)) + a2*s(i,j)
514     p0\_2d(i,j) = (b0 + b4*s(i,j)) + t(i,j) * (b1 + t(i,j)*((b2 + b3*t(i,j))) + b5*s(i,j))
515     lambda\_2d(i,j) = (c0 +c4*s(i,j)) + t(i,j) * (c1 + t(i,j)*((c2 + c3*t(i,j))) + c5*s(i,j))
516 
517     al0 = al0\_2d(i,j) ; p0 = p0\_2d(i,j) ; lambda = lambda\_2d(i,j)
518 
519     dz = z\_t(i,j) - z\_b(i,j)
520     p\_ave = -0.5*gxrho*(z\_t(i,j)+z\_b(i,j))
521 
522     i\_al0 = 1.0 / al0
523     i\_lzz = 1.0 / (p0 + (lambda * i\_al0) + p\_ave)
524     eps = 0.5*gxrho*dz*i\_lzz ; eps2 = eps*eps
525 
526 \textcolor{comment}{!     rho(j) = (pressure(j) + p0) / (lambda + al0*(pressure(j) + p0))}
527 
528     rho\_anom = (p0 + p\_ave)*(i\_lzz*i\_al0) - rho\_ref\_mks
529     rem = i\_rho * (lambda * i\_al0**2) * eps2 * &
530           (c1\_3 + eps2*(0.2 + eps2*(c1\_7 + c1\_9*eps2)))
531     dpa(i,j) = pa\_to\_rl2\_t2 * (g\_earth*rho\_anom*dz - 2.0*eps*rem)
532     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intz\_dpa)) &
533       intz\_dpa(i,j) = pa\_to\_rl2\_t2 * (0.5*g\_earth*rho\_anom*dz**2 - dz*(1.0+eps)*rem)
534 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
535 
536   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
537     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}
538     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}
539     \textcolor{comment}{! T & S along the top and bottom integrals, akin to thickness weighting.}
540     hwght = 0.0
541     \textcolor{keywordflow}{if} (do\_massweight) &
542       hwght = max(0., -bathyt(i,j)-z\_t(i+1,j), -bathyt(i+1,j)-z\_t(i,j))
543     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}
544       hl = (z\_t(i,j) - z\_b(i,j)) + dz\_neglect
545       hr = (z\_t(i+1,j) - z\_b(i+1,j)) + dz\_neglect
546       hwght = hwght * ( (hl-hr)/(hl+hr) )**2
547       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
548       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom
549       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom
550     \textcolor{keywordflow}{else}
551       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0
552 \textcolor{keywordflow}{    endif}
553 
554     intz(1) = dpa(i,j) ; intz(5) = dpa(i+1,j)
555     \textcolor{keywordflow}{do} m=2,4
556       wt\_l = 0.25*\textcolor{keywordtype}{real(5-m)} ; wt\_r = 1.0-wt\_l
557       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr
558 
559       al0 = wtt\_l*al0\_2d(i,j) + wtt\_r*al0\_2d(i+1,j)
560       p0 = wtt\_l*p0\_2d(i,j) + wtt\_r*p0\_2d(i+1,j)
561       lambda = wtt\_l*lambda\_2d(i,j) + wtt\_r*lambda\_2d(i+1,j)
562 
563       dz = wt\_l*(z\_t(i,j) - z\_b(i,j)) + wt\_r*(z\_t(i+1,j) - z\_b(i+1,j))
564       p\_ave = -0.5*gxrho*(wt\_l*(z\_t(i,j)+z\_b(i,j)) + &
565                           wt\_r*(z\_t(i+1,j)+z\_b(i+1,j)))
566 
567       i\_al0 = 1.0 / al0
568       i\_lzz = 1.0 / (p0 + (lambda * i\_al0) + p\_ave)
569       eps = 0.5*gxrho*dz*i\_lzz ; eps2 = eps*eps
570 
571       intz(m) = pa\_to\_rl2\_t2 * ( g\_earth*dz*((p0 + p\_ave)*(i\_lzz*i\_al0) - rho\_ref\_mks) - 2.0*eps * &
572                 i\_rho * (lambda * i\_al0**2) * eps2 * (c1\_3 + eps2*(0.2 + eps2*(c1\_7 + c1\_9*eps2))) )
573 \textcolor{keywordflow}{    enddo}
574     \textcolor{comment}{! Use Boole's rule to integrate the values.}
575     intx\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + 12.0*intz(3))
576 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
577 
578   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dpa)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
579     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}
580     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}
581     \textcolor{comment}{! T & S along the top and bottom integrals, akin to thickness weighting.}
582     hwght = 0.0
583     \textcolor{keywordflow}{if} (do\_massweight) &
584       hwght = max(0., -bathyt(i,j)-z\_t(i,j+1), -bathyt(i,j+1)-z\_t(i,j))
585     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}
586       hl = (z\_t(i,j) - z\_b(i,j)) + dz\_neglect
587       hr = (z\_t(i,j+1) - z\_b(i,j+1)) + dz\_neglect
588       hwght = hwght * ( (hl-hr)/(hl+hr) )**2
589       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
590       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom
591       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom
592     \textcolor{keywordflow}{else}
593       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0
594 \textcolor{keywordflow}{    endif}
595 
596     intz(1) = dpa(i,j) ; intz(5) = dpa(i,j+1)
597     \textcolor{keywordflow}{do} m=2,4
598       wt\_l = 0.25*\textcolor{keywordtype}{real(5-m)} ; wt\_r = 1.0-wt\_l
599       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr
600 
601       al0 = wtt\_l*al0\_2d(i,j) + wtt\_r*al0\_2d(i,j+1)
602       p0 = wtt\_l*p0\_2d(i,j) + wtt\_r*p0\_2d(i,j+1)
603       lambda = wtt\_l*lambda\_2d(i,j) + wtt\_r*lambda\_2d(i,j+1)
604 
605       dz = wt\_l*(z\_t(i,j) - z\_b(i,j)) + wt\_r*(z\_t(i,j+1) - z\_b(i,j+1))
606       p\_ave = -0.5*gxrho*(wt\_l*(z\_t(i,j)+z\_b(i,j)) + &
607                           wt\_r*(z\_t(i,j+1)+z\_b(i,j+1)))
608 
609       i\_al0 = 1.0 / al0
610       i\_lzz = 1.0 / (p0 + (lambda * i\_al0) + p\_ave)
611       eps = 0.5*gxrho*dz*i\_lzz ; eps2 = eps*eps
612 
613       intz(m) = pa\_to\_rl2\_t2 * ( g\_earth*dz*((p0 + p\_ave)*(i\_lzz*i\_al0) - rho\_ref\_mks) - 2.0*eps * &
614                 i\_rho * (lambda * i\_al0**2) * eps2 * (c1\_3 + eps2*(0.2 + eps2*(c1\_7 + c1\_9*eps2))) )
615 \textcolor{keywordflow}{    enddo}
616     \textcolor{comment}{! Use Boole's rule to integrate the values.}
617     inty\_dpa(i,j) = c1\_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + 12.0*intz(3))
618 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
619 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__eos__wright_a35402f454f02a3fa680a6d7870931aa6}\label{namespacemom__eos__wright_a35402f454f02a3fa680a6d7870931aa6}} 
\index{mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}!int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright@{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright}}
\index{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright@{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright}!mom\+\_\+eos\+\_\+wright@{mom\+\_\+eos\+\_\+wright}}
\subsubsection{\texorpdfstring{int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright()}{int\_spec\_vol\_dp\_wright()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+eos\+\_\+wright\+::int\+\_\+spec\+\_\+vol\+\_\+dp\+\_\+wright (\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)}]{spv\+\_\+ref,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\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,  }\item[{real, intent(in), optional}]{S\+V\+\_\+scale,  }\item[{real, intent(in), optional}]{pres\+\_\+scale }\end{DoxyParamCaption})}



This subroutine calculates 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{\tt in}  & {\em hi} & The ocean\textquotesingle{}s horizontal index type.\\
\hline
\mbox{\tt in}  & {\em t} & Potential temperature relative to the surface\\
\hline
\mbox{\tt in}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]}.\\
\hline
\mbox{\tt 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{\tt in}  & {\em p\+\_\+b} & Pressure at the top of the layer \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em spv\+\_\+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 spv\+\_\+ref, but this reduces the effects of roundoff.\\
\hline
\mbox{\tt in,out}  & {\em dza} & The change in the geopotential anomaly across\\
\hline
\mbox{\tt in,out}  & {\em intp\+\_\+dza} & The integral in pressure through the layer of\\
\hline
\mbox{\tt in,out}  & {\em intx\+\_\+dza} & The integral in x of the difference between the\\
\hline
\mbox{\tt in,out}  & {\em inty\+\_\+dza} & The integral in y of the difference between the\\
\hline
\mbox{\tt in}  & {\em halo\+\_\+size} & The width of halo points on which to calculate dza.\\
\hline
\mbox{\tt in}  & {\em bathyp} & The pressure at the bathymetry \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} or \mbox{[}Pa\mbox{]}\\
\hline
\mbox{\tt 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{\tt in}  & {\em usemasswghtinterp} & If true, uses mass weighting to interpolate T/S for top and bottom integrals.\\
\hline
\mbox{\tt in}  & {\em sv\+\_\+scale} & A multiplicative factor by which to scale specific volume from m3 kg-\/1 to the desired units \mbox{[}kg m-\/3 R-\/1 $\sim$$>$ 1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em pres\+\_\+scale} & A multiplicative factor to convert pressure into Pa \mbox{[}Pa T2 R-\/1 L-\/2 $\sim$$>$ 1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 631 of file M\+O\+M\+\_\+\+E\+O\+S\+\_\+\+Wright.\+F90.


\begin{DoxyCode}
631   \textcolor{keywordtype}{type}(hor\_index\_type), \textcolor{keywordtype}{intent(in)}  :: hi\textcolor{comment}{        !< The ocean's horizontal index type.}
632   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
633                         \textcolor{keywordtype}{intent(in)}  :: t\textcolor{comment}{         !< Potential temperature relative to the surface}
634 \textcolor{comment}{                                                 !! [degC].}
635   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
636                         \textcolor{keywordtype}{intent(in)}  :: s\textcolor{comment}{         !< Salinity [PSU].}
637   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
638                         \textcolor{keywordtype}{intent(in)}  :: p\_t\textcolor{comment}{       !< Pressure at the top of the layer [R L2 T-2 ~> Pa] or
       [Pa].}
639   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
640                         \textcolor{keywordtype}{intent(in)}  :: p\_b\textcolor{comment}{       !< Pressure at the top of the layer [R L2 T-2 ~> Pa] or
       [Pa].}
641   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)}  :: spv\_ref\textcolor{comment}{   !< A mean specific volume that is subtracted out}
642 \textcolor{comment}{                            !! to reduce the magnitude of each of the integrals [R-1 ~> m3 kg-1].}
643 \textcolor{comment}{                            !! The calculation is mathematically identical with different values of}
644 \textcolor{comment}{                            !! spv\_ref, but this reduces the effects of roundoff.}
645   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
646                         \textcolor{keywordtype}{intent(inout)} :: dza\textcolor{comment}{     !< The change in the geopotential anomaly across}
647 \textcolor{comment}{                                                 !! the layer [T-2 ~> m2 s-2] or [m2 s-2].}
648   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
649               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intp\_dza\textcolor{comment}{ !< The integral in pressure through the layer of}
650 \textcolor{comment}{                                                 !! the geopotential anomaly relative to the anomaly}
651 \textcolor{comment}{                                                 !! at the bottom of the layer [R L4 T-4 ~> Pa m2 s-2]}
652 \textcolor{comment}{                                                 !! or [Pa m2 s-2].}
653   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%IsdB:HI%IedB,HI%jsd:HI%jed)}, &
654               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: intx\_dza\textcolor{comment}{ !< The integral in x of the difference between the}
655 \textcolor{comment}{                                                 !! geopotential anomaly at the top and bottom of}
656 \textcolor{comment}{                                                 !! the layer divided by the x grid spacing}
657 \textcolor{comment}{                                                 !! [L2 T-2 ~> m2 s-2] or [m2 s-2].}
658   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%JsdB:HI%JedB)}, &
659               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: inty\_dza\textcolor{comment}{ !< The integral in y of the difference between the}
660 \textcolor{comment}{                                                 !! geopotential anomaly at the top and bottom of}
661 \textcolor{comment}{                                                 !! the layer divided by the y grid spacing}
662 \textcolor{comment}{                                                 !! [L2 T-2 ~> m2 s-2] or [m2 s-2].}
663   \textcolor{keywordtype}{integer},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\_size\textcolor{comment}{ !< The width of halo points on which to calculate}
664 \textcolor{comment}{                                                 !! dza.}
665   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)}, &
666               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: bathyp\textcolor{comment}{    !< The pressure at the bathymetry [R L2 T-2 ~> Pa] or [Pa]}
667   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: dp\_neglect\textcolor{comment}{ !< A miniscule pressure change with}
668 \textcolor{comment}{                                                 !! the same units as p\_t [R L2 T-2 ~> Pa] or [Pa]}
669   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: usemasswghtinterp\textcolor{comment}{ !< If true, uses mass weighting}
670 \textcolor{comment}{                            !! to interpolate T/S for top and bottom integrals.}
671   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: sv\_scale\textcolor{comment}{  !< A multiplicative factor by which to scale specific}
672 \textcolor{comment}{                            !! volume from m3 kg-1 to the desired units [kg m-3 R-1 ~> 1]}
673   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: pres\_scale\textcolor{comment}{ !< A multiplicative factor to convert pressure}
674 \textcolor{comment}{                            !! into Pa [Pa T2 R-1 L-2 ~> 1].}
675 
676   \textcolor{comment}{! Local variables}
677   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(HI%isd:HI%ied,HI%jsd:HI%jed)} :: al0\_2d, p0\_2d, lambda\_2d
678   \textcolor{keywordtype}{real} :: al0        \textcolor{comment}{! A term in the Wright EOS [R-1 ~> m3 kg-1]}
679   \textcolor{keywordtype}{real} :: p0         \textcolor{comment}{! A term in the Wright EOS [R L2 T-2 ~> Pa]}
680   \textcolor{keywordtype}{real} :: lambda     \textcolor{comment}{! A term in the Wright EOS [L2 T-2 ~> m2 s-2]}
681   \textcolor{keywordtype}{real} :: al0\_scale  \textcolor{comment}{! Scaling factor to convert al0 from MKS units [R-1 kg m-3 ~> 1]}
682   \textcolor{keywordtype}{real} :: p0\_scale   \textcolor{comment}{! Scaling factor to convert p0 from MKS units [R L2 T-2 Pa-1 ~> 1]}
683   \textcolor{keywordtype}{real} :: lam\_scale  \textcolor{comment}{! Scaling factor to convert lambda from MKS units [L2 s2 T-2 m-2 ~> 1]}
684   \textcolor{keywordtype}{real} :: p\_ave      \textcolor{comment}{! The layer average pressure [R L2 T-2 ~> Pa]}
685   \textcolor{keywordtype}{real} :: rem        \textcolor{comment}{! [L2 T-2 ~> m2 s-2]}
686   \textcolor{keywordtype}{real} :: eps, eps2  \textcolor{comment}{! A nondimensional ratio and its square [nondim]}
687   \textcolor{keywordtype}{real} :: alpha\_anom \textcolor{comment}{! The depth averaged specific volume anomaly [R-1 ~> m3 kg-1].}
688   \textcolor{keywordtype}{real} :: dp         \textcolor{comment}{! The pressure change through a layer [R L2 T-2 ~> Pa].}
689   \textcolor{keywordtype}{real} :: hwght      \textcolor{comment}{! A pressure-thickness below topography [R L2 T-2 ~> Pa].}
690   \textcolor{keywordtype}{real} :: hl, hr     \textcolor{comment}{! Pressure-thicknesses of the columns to the left and right [R L2 T-2 ~> Pa].}
691   \textcolor{keywordtype}{real} :: idenom     \textcolor{comment}{! The inverse of the denominator in the weights [T4 R-2 L-4 ~> Pa-2].}
692   \textcolor{keywordtype}{real} :: hwt\_ll, hwt\_lr \textcolor{comment}{! hWt\_LA is the weighted influence of A on the left column [nondim].}
693   \textcolor{keywordtype}{real} :: hwt\_rl, hwt\_rr \textcolor{comment}{! hWt\_RA is the weighted influence of A on the right column [nondim].}
694   \textcolor{keywordtype}{real} :: wt\_l, wt\_r \textcolor{comment}{! The linear weights of the left and right columns [nondim].}
695   \textcolor{keywordtype}{real} :: wtt\_l, wtt\_r \textcolor{comment}{! The weights for tracers from the left and right columns [nondim].}
696   \textcolor{keywordtype}{real} :: intp(5)    \textcolor{comment}{! The integrals of specific volume with pressure at the}
697                      \textcolor{comment}{! 5 sub-column locations [L2 T-2 ~> m2 s-2].}
698   \textcolor{keywordtype}{logical} :: do\_massweight \textcolor{comment}{! Indicates whether to do mass weighting.}
699   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: c1\_3 = 1.0/3.0, c1\_7 = 1.0/7.0    \textcolor{comment}{! Rational constants.}
700   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: c1\_9 = 1.0/9.0, c1\_90 = 1.0/90.0  \textcolor{comment}{! Rational constants.}
701   \textcolor{keywordtype}{integer} :: isq, ieq, jsq, jeq, ish, ieh, jsh, jeh, i, j, m, halo
702 
703   isq = hi%IscB ; ieq = hi%IecB ; jsq = hi%JscB ; jeq = hi%JecB
704   halo = 0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo\_size)) halo = max(halo\_size,0)
705   ish = hi%isc-halo ; ieh = hi%iec+halo ; jsh = hi%jsc-halo ; jeh = hi%jec+halo
706   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intx\_dza)) \textcolor{keywordflow}{then} ; ish = min(isq,ish) ; ieh = max(ieq+1,ieh);\textcolor{keywordflow}{ endif}
707   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(inty\_dza)) \textcolor{keywordflow}{then} ; jsh = min(jsq,jsh) ; jeh = max(jeq+1,jeh);\textcolor{keywordflow}{ endif}
708 
709 
710   al0\_scale = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sv\_scale)) al0\_scale = sv\_scale
711   p0\_scale = 1.0
712   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(pres\_scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (pres\_scale /= 1.0) \textcolor{keywordflow}{then}
713     p0\_scale = 1.0 / pres\_scale
714 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
715   lam\_scale = al0\_scale * p0\_scale
716 
717   do\_massweight = .false.
718   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usemasswghtinterp)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (usemasswghtinterp) \textcolor{keywordflow}{then}
719     do\_massweight = .true.
720 \textcolor{comment}{!    if (.not.present(bathyP)) call MOM\_error(FATAL, "int\_spec\_vol\_dp\_generic: "//&}
721 \textcolor{comment}{!        "bathyP must be present if useMassWghtInterp is present and true.")}
722 \textcolor{comment}{!    if (.not.present(dP\_neglect)) call MOM\_error(FATAL, "int\_spec\_vol\_dp\_generic: "//&}
723 \textcolor{comment}{!        "dP\_neglect must be present if useMassWghtInterp is present and true.")}
724 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
725 
726   \textcolor{comment}{!  alpha(j) = (lambda + al0*(pressure(j) + p0)) / (pressure(j) + p0)}
727   \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
728     al0\_2d(i,j) = al0\_scale * ( (a0 + a1*t(i,j)) + a2*s(i,j) )
729     p0\_2d(i,j) = p0\_scale * ( (b0 + b4*s(i,j)) + t(i,j) * (b1 + t(i,j)*((b2 + b3*t(i,j))) + b5*s(i,j)) )
730     lambda\_2d(i,j) = lam\_scale * ( (c0 + c4*s(i,j)) + t(i,j) * (c1 + t(i,j)*((c2 + c3*t(i,j))) + c5*s(i,j))
       )
731 
732     al0 = al0\_2d(i,j) ; p0 = p0\_2d(i,j) ; lambda = lambda\_2d(i,j)
733     dp = p\_b(i,j) - p\_t(i,j)
734     p\_ave = 0.5*(p\_t(i,j)+p\_b(i,j))
735 
736     eps = 0.5 * dp / (p0 + p\_ave) ; eps2 = eps*eps
737     alpha\_anom = al0 + lambda / (p0 + p\_ave) - spv\_ref
738     rem = lambda * eps2 * (c1\_3 + eps2*(0.2 + eps2*(c1\_7 + c1\_9*eps2)))
739     dza(i,j) = alpha\_anom*dp + 2.0*eps*rem
740     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(intp\_dza)) &
741       intp\_dza(i,j) = 0.5*alpha\_anom*dp**2 - dp*(1.0-eps)*rem
742 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
743 
744   \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
745     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}
746     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}
747     \textcolor{comment}{! T & S along the top and bottom integrals, akin to thickness weighting.}
748     hwght = 0.0
749     \textcolor{keywordflow}{if} (do\_massweight) &
750       hwght = max(0., bathyp(i,j)-p\_t(i+1,j), bathyp(i+1,j)-p\_t(i,j))
751     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}
752       hl = (p\_b(i,j) - p\_t(i,j)) + dp\_neglect
753       hr = (p\_b(i+1,j) - p\_t(i+1,j)) + dp\_neglect
754       hwght = hwght * ( (hl-hr)/(hl+hr) )**2
755       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
756       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom
757       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom
758     \textcolor{keywordflow}{else}
759       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0
760 \textcolor{keywordflow}{    endif}
761 
762     intp(1) = dza(i,j) ; intp(5) = dza(i+1,j)
763     \textcolor{keywordflow}{do} m=2,4
764       wt\_l = 0.25*\textcolor{keywordtype}{real(5-m)} ; wt\_r = 1.0-wt\_l
765       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr
766 
767       \textcolor{comment}{! T, S, and p are interpolated in the horizontal.  The p interpolation}
768       \textcolor{comment}{! is linear, but for T and S it may be thickness wekghted.}
769       al0 = wtt\_l*al0\_2d(i,j) + wtt\_r*al0\_2d(i+1,j)
770       p0 = wtt\_l*p0\_2d(i,j) + wtt\_r*p0\_2d(i+1,j)
771       lambda = wtt\_l*lambda\_2d(i,j) + wtt\_r*lambda\_2d(i+1,j)
772 
773       dp = wt\_l*(p\_b(i,j) - p\_t(i,j)) + wt\_r*(p\_b(i+1,j) - p\_t(i+1,j))
774       p\_ave = 0.5*(wt\_l*(p\_t(i,j)+p\_b(i,j)) + wt\_r*(p\_t(i+1,j)+p\_b(i+1,j)))
775 
776       eps = 0.5 * dp / (p0 + p\_ave) ; eps2 = eps*eps
777       intp(m) = (al0 + lambda / (p0 + p\_ave) - spv\_ref)*dp + 2.0*eps* &
778                lambda * eps2 * (c1\_3 + eps2*(0.2 + eps2*(c1\_7 + c1\_9*eps2)))
779 \textcolor{keywordflow}{    enddo}
780     \textcolor{comment}{! Use Boole's rule to integrate the values.}
781     intx\_dza(i,j) = c1\_90*(7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4)) + &
782                            12.0*intp(3))
783 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
784 
785   \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
786     \textcolor{comment}{! hWght is the distance measure by which the cell is violation of}
787     \textcolor{comment}{! hydrostatic consistency. For large hWght we bias the interpolation of}
788     \textcolor{comment}{! T & S along the top and bottom integrals, akin to thickness weighting.}
789     hwght = 0.0
790     \textcolor{keywordflow}{if} (do\_massweight) &
791       hwght = max(0., bathyp(i,j)-p\_t(i,j+1), bathyp(i,j+1)-p\_t(i,j))
792     \textcolor{keywordflow}{if} (hwght > 0.) \textcolor{keywordflow}{then}
793       hl = (p\_b(i,j) - p\_t(i,j)) + dp\_neglect
794       hr = (p\_b(i,j+1) - p\_t(i,j+1)) + dp\_neglect
795       hwght = hwght * ( (hl-hr)/(hl+hr) )**2
796       idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
797       hwt\_ll = (hwght*hl + hr*hl) * idenom ; hwt\_lr = (hwght*hr) * idenom
798       hwt\_rr = (hwght*hr + hr*hl) * idenom ; hwt\_rl = (hwght*hl) * idenom
799     \textcolor{keywordflow}{else}
800       hwt\_ll = 1.0 ; hwt\_lr = 0.0 ; hwt\_rr = 1.0 ; hwt\_rl = 0.0
801 \textcolor{keywordflow}{    endif}
802 
803     intp(1) = dza(i,j) ; intp(5) = dza(i,j+1)
804     \textcolor{keywordflow}{do} m=2,4
805       wt\_l = 0.25*\textcolor{keywordtype}{real(5-m)} ; wt\_r = 1.0-wt\_l
806       wtt\_l = wt\_l*hwt\_ll + wt\_r*hwt\_rl ; wtt\_r = wt\_l*hwt\_lr + wt\_r*hwt\_rr
807 
808       \textcolor{comment}{! T, S, and p are interpolated in the horizontal.  The p interpolation}
809       \textcolor{comment}{! is linear, but for T and S it may be thickness wekghted.}
810       al0 = wt\_l*al0\_2d(i,j) + wt\_r*al0\_2d(i,j+1)
811       p0 = wt\_l*p0\_2d(i,j) + wt\_r*p0\_2d(i,j+1)
812       lambda = wt\_l*lambda\_2d(i,j) + wt\_r*lambda\_2d(i,j+1)
813 
814       dp = wt\_l*(p\_b(i,j) - p\_t(i,j)) + wt\_r*(p\_b(i,j+1) - p\_t(i,j+1))
815       p\_ave = 0.5*(wt\_l*(p\_t(i,j)+p\_b(i,j)) + wt\_r*(p\_t(i,j+1)+p\_b(i,j+1)))
816 
817       eps = 0.5 * dp / (p0 + p\_ave) ; eps2 = eps*eps
818       intp(m) = (al0 + lambda / (p0 + p\_ave) - spv\_ref)*dp + 2.0*eps* &
819                lambda * eps2 * (c1\_3 + eps2*(0.2 + eps2*(c1\_7 + c1\_9*eps2)))
820 \textcolor{keywordflow}{    enddo}
821     \textcolor{comment}{! Use Boole's rule to integrate the values.}
822     inty\_dza(i,j) = c1\_90*(7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4)) + &
823                            12.0*intp(3))
824 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
\end{DoxyCode}
