\hypertarget{interfacemom__eos_1_1calculate__density}{}\doxysection{mom\+\_\+eos\+::calculate\+\_\+density Interface Reference}
\label{interfacemom__eos_1_1calculate__density}\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}


\doxysubsection{Detailed Description}
Calculates density of sea water from T, S and P. 

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

\doxysubsection*{Private functions}
\begin{DoxyCompactItemize}
\item 
subroutine \mbox{\hyperlink{interfacemom__eos_1_1calculate__density_a784e74a411a4ab45fde914754f27894e}{calculate\+\_\+density\+\_\+scalar}} (T, S, pressure, rho, E\+OS, rho\+\_\+ref, scale)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate density of sea water for scalar inputs. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. The pressure and density can be rescaled with the US. If both the US and scale arguments are present the density scaling uses the product of the two scaling factors. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{interfacemom__eos_1_1calculate__density_a9c2bb282a0662cf90074096d64f15377}{calculate\+\_\+density\+\_\+array}} (T, S, pressure, rho, start, npts, E\+OS, rho\+\_\+ref, scale)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{interfacemom__eos_1_1calculate__density_aa113783c30ac2dbeef25e428929abe54}{calculate\+\_\+density\+\_\+1d}} (T, S, pressure, rho, E\+OS, dom, rho\+\_\+ref, scale)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs, potentially limiting the domain of indices that are worked on. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{interfacemom__eos_1_1calculate__density_abf1cef7a943f4ae996c954c45bab9ea1}{calculate\+\_\+stanley\+\_\+density\+\_\+scalar}} (T, S, pressure, Tvar, T\+Scov, Svar, rho, E\+OS, rho\+\_\+ref, scale)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate density of sea water for scalar inputs including the variance of T, S and covariance of T-\/S. The calculation uses only the second order correction in a series as discussed in Stanley et al., 2020. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. The density can be rescaled using rho\+\_\+ref. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{interfacemom__eos_1_1calculate__density_ab702d0b5d50a77451bfcea5a8f3c58f3}{calculate\+\_\+stanley\+\_\+density\+\_\+array}} (T, S, pressure, Tvar, T\+Scov, Svar, rho, start, npts, E\+OS, rho\+\_\+ref, scale)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs including the variance of T, S and covariance of T-\/S. The calculation uses only the second order correction in a series as discussed in Stanley et al., 2020. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{interfacemom__eos_1_1calculate__density_a49e5008e5bc77c498a869f1c9eda1f43}{calculate\+\_\+stanley\+\_\+density\+\_\+1d}} (T, S, pressure, Tvar, T\+Scov, Svar, rho, E\+OS, dom, rho\+\_\+ref, scale)
\begin{DoxyCompactList}\small\item\em Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs including the variance of T, S and covariance of T-\/S, potentially limiting the domain of indices that are worked on. The calculation uses only the second order correction in a series as discussed in Stanley et al., 2020. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Calculates density of sea water from T, S and P. 

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



\doxysubsection{Functions and subroutines}
\mbox{\Hypertarget{interfacemom__eos_1_1calculate__density_aa113783c30ac2dbeef25e428929abe54}\label{interfacemom__eos_1_1calculate__density_aa113783c30ac2dbeef25e428929abe54}} 
\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}!calculate\_density\_1d@{calculate\_density\_1d}}
\index{calculate\_density\_1d@{calculate\_density\_1d}!mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}
\doxysubsubsection{\texorpdfstring{calculate\_density\_1d()}{calculate\_density\_1d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+::calculate\+\_\+density\+::calculate\+\_\+density\+\_\+1d (\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[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{E\+OS,  }\item[{integer, dimension(2), intent(in), optional}]{dom,  }\item[{real, intent(in), optional}]{rho\+\_\+ref,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs, potentially limiting the domain of indices that are worked on. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pressure} & Pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em rho} & Density (in-\/situ if pressure is local) \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em dom} & The domain of indices to work on, taking into account that arrays start at 1. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A multiplicative factor by which to scale density in combination with scaling given by US \mbox{[}various\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{360 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{        !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{361 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{        !< Salinity [ppt]}}
\DoxyCodeLine{362 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: pressure\textcolor{comment}{ !< Pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{363 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(inout)} :: rho\textcolor{comment}{      !< Density (in-\/situ if pressure is local) [R \string~> kg m-\/3]}}
\DoxyCodeLine{364   \textcolor{keywordtype}{type}(EOS\_type),        \textcolor{keywordtype}{pointer}       :: EOS\textcolor{comment}{      !< Equation of state structure}}
\DoxyCodeLine{365   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: dom\textcolor{comment}{   !< The domain of indices to work on, taking}}
\DoxyCodeLine{366 \textcolor{comment}{                                                       !! into account that arrays start at 1.}}
\DoxyCodeLine{367 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: rho\_ref\textcolor{comment}{ !< A reference density [kg m-\/3]}}
\DoxyCodeLine{368 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: scale\textcolor{comment}{ !< A multiplicative factor by which to scale density}}
\DoxyCodeLine{369 \textcolor{comment}{                                                   !! in combination with scaling given by US [various]}}
\DoxyCodeLine{370   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{371 \textcolor{keywordtype}{  real} :: p\_scale   \textcolor{comment}{! A factor to convert pressure to units of Pa [Pa T2 R-\/1 L-\/2 \string~> 1]}}
\DoxyCodeLine{372 \textcolor{keywordtype}{  real} :: rho\_scale \textcolor{comment}{! A factor to convert density from kg m-\/3 to the desired units [R m3 kg-\/1 \string~> 1]}}
\DoxyCodeLine{373 \textcolor{keywordtype}{  real} :: rho\_unscale \textcolor{comment}{! A factor to convert density from R to kg m-\/3 [kg m-\/3 R-\/1 \string~> 1]}}
\DoxyCodeLine{374 \textcolor{keywordtype}{  real} :: rho\_reference \textcolor{comment}{! rho\_ref converted to [kg m-\/3]}}
\DoxyCodeLine{375 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(size(rho))} :: pres  \textcolor{comment}{! Pressure converted to [Pa]}}
\DoxyCodeLine{376   \textcolor{keywordtype}{integer} :: i, is, ie, npts}
\DoxyCodeLine{377 }
\DoxyCodeLine{378   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(eos)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{379     \textcolor{stringliteral}{"calculate\_density\_1d called with an unassociated EOS\_type EOS."})}
\DoxyCodeLine{380 }
\DoxyCodeLine{381   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dom)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{382     is = dom(1) ; ie = dom(2) ; npts = 1 + ie -\/ is}
\DoxyCodeLine{383   \textcolor{keywordflow}{else}}
\DoxyCodeLine{384     is = 1 ; ie = \textcolor{keyword}{size}(rho) ; npts = 1 + ie -\/ is}
\DoxyCodeLine{385 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{386 }
\DoxyCodeLine{387   p\_scale = eos\%RL2\_T2\_to\_Pa}
\DoxyCodeLine{388   rho\_unscale = eos\%R\_to\_kg\_m3}
\DoxyCodeLine{389 }
\DoxyCodeLine{390   \textcolor{keywordflow}{if} ((p\_scale == 1.0) .and. (rho\_unscale == 1.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{391     \textcolor{keyword}{call }calculate\_density\_array(t, s, pressure, rho, is, npts, eos, rho\_ref=rho\_ref)}
\DoxyCodeLine{392   \textcolor{keywordflow}{elseif} (\textcolor{keyword}{present}(rho\_ref)) \textcolor{keywordflow}{then} \textcolor{comment}{! This is the same as above, but with some extra work to rescale variables.}}
\DoxyCodeLine{393     \textcolor{keywordflow}{do} i=is,ie ; pres(i) = p\_scale * pressure(i) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{394     rho\_reference = rho\_unscale*rho\_ref}
\DoxyCodeLine{395     \textcolor{keyword}{call }calculate\_density\_array(t, s, pres, rho, is, npts, eos, rho\_ref=rho\_reference)}
\DoxyCodeLine{396   \textcolor{keywordflow}{else}  \textcolor{comment}{! There is rescaling of variables, but rho\_ref is not present. Passing a 0 value of rho\_ref}}
\DoxyCodeLine{397         \textcolor{comment}{! changes answers at roundoff for some equations of state, like Wright and UNESCO.}}
\DoxyCodeLine{398     \textcolor{keywordflow}{do} i=is,ie ; pres(i) = p\_scale * pressure(i) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{399     \textcolor{keyword}{call }calculate\_density\_array(t, s, pres, rho, is, npts, eos)}
\DoxyCodeLine{400 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{401 }
\DoxyCodeLine{402   rho\_scale = eos\%kg\_m3\_to\_R}
\DoxyCodeLine{403   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) rho\_scale = rho\_scale * scale}
\DoxyCodeLine{404   \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{405     rho(i) = rho\_scale * rho(i)}
\DoxyCodeLine{406 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{407 }

\end{DoxyCode}
\mbox{\Hypertarget{interfacemom__eos_1_1calculate__density_a9c2bb282a0662cf90074096d64f15377}\label{interfacemom__eos_1_1calculate__density_a9c2bb282a0662cf90074096d64f15377}} 
\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}!calculate\_density\_array@{calculate\_density\_array}}
\index{calculate\_density\_array@{calculate\_density\_array}!mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}
\doxysubsubsection{\texorpdfstring{calculate\_density\_array()}{calculate\_density\_array()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+::calculate\+\_\+density\+::calculate\+\_\+density\+\_\+array (\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[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{E\+OS,  }\item[{real, intent(in), optional}]{rho\+\_\+ref,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pressure} & Pressure \mbox{[}Pa\mbox{]} or \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em rho} & Density (in-\/situ if pressure is local) \mbox{[}kg m-\/3\mbox{]} or \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em start} & Start index for computation \\
\hline
\mbox{\texttt{ in}}  & {\em npts} & Number of point to compute \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A multiplicative factor by which to scale density in combination with scaling given by US \mbox{[}various\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{263 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{        !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{264 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{        !< Salinity [ppt]}}
\DoxyCodeLine{265 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: pressure\textcolor{comment}{ !< Pressure [Pa] or [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{266 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: rho\textcolor{comment}{      !< Density (in-\/situ if pressure is local) [kg m-\/3] or [R \string~> kg m-\/3]}}
\DoxyCodeLine{267   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: start\textcolor{comment}{    !< Start index for computation}}
\DoxyCodeLine{268   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: npts\textcolor{comment}{     !< Number of point to compute}}
\DoxyCodeLine{269   \textcolor{keywordtype}{type}(EOS\_type),     \textcolor{keywordtype}{pointer}       :: EOS\textcolor{comment}{      !< Equation of state structure}}
\DoxyCodeLine{270 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: rho\_ref\textcolor{comment}{  !< A reference density [kg m-\/3]}}
\DoxyCodeLine{271 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: scale\textcolor{comment}{    !< A multiplicative factor by which to scale density}}
\DoxyCodeLine{272 \textcolor{comment}{                                                !! in combination with scaling given by US [various]}}
\DoxyCodeLine{273   \textcolor{keywordtype}{integer} :: j}
\DoxyCodeLine{274 }
\DoxyCodeLine{275   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(eos)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{276     \textcolor{stringliteral}{"calculate\_density\_array called with an unassociated EOS\_type EOS."})}
\DoxyCodeLine{277 }
\DoxyCodeLine{278   \textcolor{keywordflow}{select case} (eos\%form\_of\_EOS)}
\DoxyCodeLine{279     \textcolor{keywordflow}{case} (eos\_linear)}
\DoxyCodeLine{280       \textcolor{keyword}{call }calculate\_density\_linear(t, s, pressure, rho, start, npts, \&}
\DoxyCodeLine{281                                     eos\%Rho\_T0\_S0, eos\%dRho\_dT, eos\%dRho\_dS, rho\_ref)}
\DoxyCodeLine{282     \textcolor{keywordflow}{case} (eos\_unesco)}
\DoxyCodeLine{283       \textcolor{keyword}{call }calculate\_density\_unesco(t, s, pressure, rho, start, npts, rho\_ref)}
\DoxyCodeLine{284     \textcolor{keywordflow}{case} (eos\_wright)}
\DoxyCodeLine{285       \textcolor{keyword}{call }calculate\_density\_wright(t, s, pressure, rho, start, npts, rho\_ref)}
\DoxyCodeLine{286     \textcolor{keywordflow}{case} (eos\_teos10)}
\DoxyCodeLine{287       \textcolor{keyword}{call }calculate\_density\_teos10(t, s, pressure, rho, start, npts, rho\_ref)}
\DoxyCodeLine{288     \textcolor{keywordflow}{case} (eos\_nemo)}
\DoxyCodeLine{289     \textcolor{keyword}{call }calculate\_density\_nemo(t, s, pressure, rho, start, npts, rho\_ref)}
\DoxyCodeLine{290 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{291       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calculate\_density\_array: EOS\%form\_of\_EOS is not valid."})}
\DoxyCodeLine{292 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{293 }
\DoxyCodeLine{294   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (scale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=start,start+npts-\/1}
\DoxyCodeLine{295     rho(j) = scale * rho(j)}
\DoxyCodeLine{296 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{297 }

\end{DoxyCode}
\mbox{\Hypertarget{interfacemom__eos_1_1calculate__density_a784e74a411a4ab45fde914754f27894e}\label{interfacemom__eos_1_1calculate__density_a784e74a411a4ab45fde914754f27894e}} 
\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}!calculate\_density\_scalar@{calculate\_density\_scalar}}
\index{calculate\_density\_scalar@{calculate\_density\_scalar}!mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}
\doxysubsubsection{\texorpdfstring{calculate\_density\_scalar()}{calculate\_density\_scalar()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+::calculate\+\_\+density\+::calculate\+\_\+density\+\_\+scalar (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T,  }\item[{real, intent(in)}]{S,  }\item[{real, intent(in)}]{pressure,  }\item[{real, intent(out)}]{rho,  }\item[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{E\+OS,  }\item[{real, intent(in), optional}]{rho\+\_\+ref,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the appropriate subroutine to calculate density of sea water for scalar inputs. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. The pressure and density can be rescaled with the US. If both the US and scale arguments are present the density scaling uses the product of the two scaling factors. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pressure} & Pressure \mbox{[}Pa\mbox{]} or \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em rho} & Density (in-\/situ if pressure is local) \mbox{[}kg m-\/3\mbox{]} or \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A multiplicative factor by which to scale density in combination with scaling given by US \mbox{[}various\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: T\textcolor{comment}{        !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{167 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: S\textcolor{comment}{        !< Salinity [ppt]}}
\DoxyCodeLine{168 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: pressure\textcolor{comment}{ !< Pressure [Pa] or [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{169 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(out)} :: rho\textcolor{comment}{      !< Density (in-\/situ if pressure is local) [kg m-\/3] or [R \string~> kg m-\/3]}}
\DoxyCodeLine{170   \textcolor{keywordtype}{type}(EOS\_type), \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{      !< Equation of state structure}}
\DoxyCodeLine{171 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{  !< A reference density [kg m-\/3]}}
\DoxyCodeLine{172 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{    !< A multiplicative factor by which to scale density in}}
\DoxyCodeLine{173 \textcolor{comment}{                                          !! combination with scaling given by US [various]}}
\DoxyCodeLine{174 }
\DoxyCodeLine{175 \textcolor{keywordtype}{  real} :: rho\_scale \textcolor{comment}{! A factor to convert density from kg m-\/3 to the desired units [R m3 kg-\/1 \string~> 1]}}
\DoxyCodeLine{176 \textcolor{keywordtype}{  real} :: p\_scale   \textcolor{comment}{! A factor to convert pressure to units of Pa [Pa T2 R-\/1 L-\/2 \string~> 1]}}
\DoxyCodeLine{177 }
\DoxyCodeLine{178   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(eos)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{179     \textcolor{stringliteral}{"calculate\_density\_scalar called with an unassociated EOS\_type EOS."})}
\DoxyCodeLine{180 }
\DoxyCodeLine{181   p\_scale = eos\%RL2\_T2\_to\_Pa}
\DoxyCodeLine{182 }
\DoxyCodeLine{183   \textcolor{keywordflow}{select case} (eos\%form\_of\_EOS)}
\DoxyCodeLine{184     \textcolor{keywordflow}{case} (eos\_linear)}
\DoxyCodeLine{185       \textcolor{keyword}{call }calculate\_density\_linear(t, s, p\_scale*pressure, rho, \&}
\DoxyCodeLine{186                                     eos\%Rho\_T0\_S0, eos\%dRho\_dT, eos\%dRho\_dS, rho\_ref)}
\DoxyCodeLine{187     \textcolor{keywordflow}{case} (eos\_unesco)}
\DoxyCodeLine{188       \textcolor{keyword}{call }calculate\_density\_unesco(t, s, p\_scale*pressure, rho, rho\_ref)}
\DoxyCodeLine{189     \textcolor{keywordflow}{case} (eos\_wright)}
\DoxyCodeLine{190       \textcolor{keyword}{call }calculate\_density\_wright(t, s, p\_scale*pressure, rho, rho\_ref)}
\DoxyCodeLine{191     \textcolor{keywordflow}{case} (eos\_teos10)}
\DoxyCodeLine{192       \textcolor{keyword}{call }calculate\_density\_teos10(t, s, p\_scale*pressure, rho, rho\_ref)}
\DoxyCodeLine{193     \textcolor{keywordflow}{case} (eos\_nemo)}
\DoxyCodeLine{194       \textcolor{keyword}{call }calculate\_density\_nemo(t, s, p\_scale*pressure, rho, rho\_ref)}
\DoxyCodeLine{195 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{196       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calculate\_density\_scalar: EOS is not valid."})}
\DoxyCodeLine{197 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{198 }
\DoxyCodeLine{199   rho\_scale = eos\%kg\_m3\_to\_R}
\DoxyCodeLine{200   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) rho\_scale = rho\_scale * scale}
\DoxyCodeLine{201   rho = rho\_scale * rho}
\DoxyCodeLine{202 }

\end{DoxyCode}
\mbox{\Hypertarget{interfacemom__eos_1_1calculate__density_a49e5008e5bc77c498a869f1c9eda1f43}\label{interfacemom__eos_1_1calculate__density_a49e5008e5bc77c498a869f1c9eda1f43}} 
\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}!calculate\_stanley\_density\_1d@{calculate\_stanley\_density\_1d}}
\index{calculate\_stanley\_density\_1d@{calculate\_stanley\_density\_1d}!mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}
\doxysubsubsection{\texorpdfstring{calculate\_stanley\_density\_1d()}{calculate\_stanley\_density\_1d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+::calculate\+\_\+density\+::calculate\+\_\+stanley\+\_\+density\+\_\+1d (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(in)}]{Tvar,  }\item[{real, dimension(\+:), intent(in)}]{T\+Scov,  }\item[{real, dimension(\+:), intent(in)}]{Svar,  }\item[{real, dimension(\+:), intent(inout)}]{rho,  }\item[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{E\+OS,  }\item[{integer, dimension(2), intent(in), optional}]{dom,  }\item[{real, intent(in), optional}]{rho\+\_\+ref,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs including the variance of T, S and covariance of T-\/S, potentially limiting the domain of indices that are worked on. The calculation uses only the second order correction in a series as discussed in Stanley et al., 2020. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pressure} & Pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tvar} & Variance of potential temperature \mbox{[}deg\+C2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tscov} & Covariance of potential temperature and salinity \mbox{[}degC ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em svar} & Variance of salinity \mbox{[}ppt2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em rho} & Density (in-\/situ if pressure is local) \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em dom} & The domain of indices to work on, taking into account that arrays start at 1. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A multiplicative factor by which to scale density in combination with scaling given by US \mbox{[}various\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{417 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{        !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{418 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{        !< Salinity [ppt]}}
\DoxyCodeLine{419 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: pressure\textcolor{comment}{ !< Pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{420 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: Tvar\textcolor{comment}{     !< Variance of potential temperature [degC2]}}
\DoxyCodeLine{421 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: TScov\textcolor{comment}{    !< Covariance of potential temperature and salinity [degC ppt]}}
\DoxyCodeLine{422 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(in)}    :: Svar\textcolor{comment}{     !< Variance of salinity [ppt2]}}
\DoxyCodeLine{423 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},    \textcolor{keywordtype}{intent(inout)} :: rho\textcolor{comment}{      !< Density (in-\/situ if pressure is local) [R \string~> kg m-\/3]}}
\DoxyCodeLine{424   \textcolor{keywordtype}{type}(EOS\_type),        \textcolor{keywordtype}{pointer}       :: EOS\textcolor{comment}{      !< Equation of state structure}}
\DoxyCodeLine{425   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: dom\textcolor{comment}{   !< The domain of indices to work on, taking}}
\DoxyCodeLine{426 \textcolor{comment}{                                                       !! into account that arrays start at 1.}}
\DoxyCodeLine{427 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: rho\_ref\textcolor{comment}{ !< A reference density [kg m-\/3]}}
\DoxyCodeLine{428 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: scale\textcolor{comment}{ !< A multiplicative factor by which to scale density}}
\DoxyCodeLine{429 \textcolor{comment}{                                                   !! in combination with scaling given by US [various]}}
\DoxyCodeLine{430   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{431 \textcolor{keywordtype}{  real} :: p\_scale   \textcolor{comment}{! A factor to convert pressure to units of Pa [Pa T2 R-\/1 L-\/2 \string~> 1]}}
\DoxyCodeLine{432 \textcolor{keywordtype}{  real} :: rho\_scale \textcolor{comment}{! A factor to convert density from kg m-\/3 to the desired units [R m3 kg-\/1 \string~> 1]}}
\DoxyCodeLine{433 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(size(rho))} :: pres  \textcolor{comment}{! Pressure converted to [Pa]}}
\DoxyCodeLine{434 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(size(T))} :: d2RdTT, d2RdST, d2RdSS, d2RdSp, d2RdTp \textcolor{comment}{! Second derivatives of density wrt T,S,p}}
\DoxyCodeLine{435   \textcolor{keywordtype}{integer} :: i, is, ie, npts}
\DoxyCodeLine{436 }
\DoxyCodeLine{437   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(eos)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{438     \textcolor{stringliteral}{"calculate\_density\_1d called with an unassociated EOS\_type EOS."})}
\DoxyCodeLine{439 }
\DoxyCodeLine{440   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dom)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{441     is = dom(1) ; ie = dom(2) ; npts = 1 + ie -\/ is}
\DoxyCodeLine{442   \textcolor{keywordflow}{else}}
\DoxyCodeLine{443     is = 1 ; ie = \textcolor{keyword}{size}(rho) ; npts = 1 + ie -\/ is}
\DoxyCodeLine{444 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{445 }
\DoxyCodeLine{446   p\_scale = eos\%RL2\_T2\_to\_Pa}
\DoxyCodeLine{447   \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{448     pres(i) = p\_scale * pressure(i)}
\DoxyCodeLine{449 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{450 }
\DoxyCodeLine{451   \textcolor{keywordflow}{select case} (eos\%form\_of\_EOS)}
\DoxyCodeLine{452     \textcolor{keywordflow}{case} (eos\_linear)}
\DoxyCodeLine{453       \textcolor{keyword}{call }calculate\_density\_linear(t, s, pres, rho, 1, npts, \&}
\DoxyCodeLine{454                                     eos\%Rho\_T0\_S0, eos\%dRho\_dT, eos\%dRho\_dS, rho\_ref)}
\DoxyCodeLine{455       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_linear(t, s, pres, d2rdss, d2rdst, \&}
\DoxyCodeLine{456                                                   d2rdtt, d2rdsp, d2rdtp, 1, npts)}
\DoxyCodeLine{457     \textcolor{keywordflow}{case} (eos\_wright)}
\DoxyCodeLine{458       \textcolor{keyword}{call }calculate\_density\_wright(t, s, pres, rho, 1, npts, rho\_ref)}
\DoxyCodeLine{459       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_wright(t, s, pres, d2rdss, d2rdst, \&}
\DoxyCodeLine{460                                                   d2rdtt, d2rdsp, d2rdtp, 1, npts)}
\DoxyCodeLine{461     \textcolor{keywordflow}{case} (eos\_teos10)}
\DoxyCodeLine{462       \textcolor{keyword}{call }calculate\_density\_teos10(t, s, pres, rho, 1, npts, rho\_ref)}
\DoxyCodeLine{463       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_teos10(t, s, pres, d2rdss, d2rdst, \&}
\DoxyCodeLine{464                                                   d2rdtt, d2rdsp, d2rdtp, 1, npts)}
\DoxyCodeLine{465 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{466       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calculate\_stanley\_density\_scalar: EOS is not valid."})}
\DoxyCodeLine{467 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{468 }
\DoxyCodeLine{469   \textcolor{comment}{! Equation 25 of Stanley et al., 2020.}}
\DoxyCodeLine{470   \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{471     rho(i) = rho(i) \&}
\DoxyCodeLine{472              + ( 0.5 * d2rdtt(i) * tvar(i) + ( d2rdst(i) * tscov(i) + 0.5 * d2rdss(i) * svar(i) ) )}
\DoxyCodeLine{473 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{474 }
\DoxyCodeLine{475   rho\_scale = eos\%kg\_m3\_to\_R}
\DoxyCodeLine{476   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) rho\_scale = rho\_scale * scale}
\DoxyCodeLine{477   \textcolor{keywordflow}{if} (rho\_scale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{478     rho(i) = rho\_scale * rho(i)}
\DoxyCodeLine{479 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{480 }

\end{DoxyCode}
\mbox{\Hypertarget{interfacemom__eos_1_1calculate__density_ab702d0b5d50a77451bfcea5a8f3c58f3}\label{interfacemom__eos_1_1calculate__density_ab702d0b5d50a77451bfcea5a8f3c58f3}} 
\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}!calculate\_stanley\_density\_array@{calculate\_stanley\_density\_array}}
\index{calculate\_stanley\_density\_array@{calculate\_stanley\_density\_array}!mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}
\doxysubsubsection{\texorpdfstring{calculate\_stanley\_density\_array()}{calculate\_stanley\_density\_array()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+::calculate\+\_\+density\+::calculate\+\_\+stanley\+\_\+density\+\_\+array (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{T,  }\item[{real, dimension(\+:), intent(in)}]{S,  }\item[{real, dimension(\+:), intent(in)}]{pressure,  }\item[{real, dimension(\+:), intent(in)}]{Tvar,  }\item[{real, dimension(\+:), intent(in)}]{T\+Scov,  }\item[{real, dimension(\+:), intent(in)}]{Svar,  }\item[{real, dimension(\+:), intent(inout)}]{rho,  }\item[{integer, intent(in)}]{start,  }\item[{integer, intent(in)}]{npts,  }\item[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{E\+OS,  }\item[{real, intent(in), optional}]{rho\+\_\+ref,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the appropriate subroutine to calculate the density of sea water for 1-\/D array inputs including the variance of T, S and covariance of T-\/S. The calculation uses only the second order correction in a series as discussed in Stanley et al., 2020. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pressure} & Pressure \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tvar} & Variance of potential temperature referenced to the surface \mbox{[}deg\+C2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tscov} & Covariance of potential temperature and salinity \mbox{[}degC ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em svar} & Variance of salinity \mbox{[}ppt2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em rho} & Density (in-\/situ if pressure is local) \mbox{[}kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em start} & Start index for computation \\
\hline
\mbox{\texttt{ in}}  & {\em npts} & Number of point to compute \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A multiplicative factor by which to scale density from kg m-\/3 to the desired units \mbox{[}R m3 kg-\/1\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{306 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{        !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{307 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{        !< Salinity [ppt]}}
\DoxyCodeLine{308 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: pressure\textcolor{comment}{ !< Pressure [Pa]}}
\DoxyCodeLine{309 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: Tvar\textcolor{comment}{     !< Variance of potential temperature referenced to the surface [degC2]}}
\DoxyCodeLine{310 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: TScov\textcolor{comment}{    !< Covariance of potential temperature and salinity [degC ppt]}}
\DoxyCodeLine{311 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}    :: Svar\textcolor{comment}{     !< Variance of salinity [ppt2]}}
\DoxyCodeLine{312 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: rho\textcolor{comment}{      !< Density (in-\/situ if pressure is local) [kg m-\/3]}}
\DoxyCodeLine{313   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: start\textcolor{comment}{    !< Start index for computation}}
\DoxyCodeLine{314   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: npts\textcolor{comment}{     !< Number of point to compute}}
\DoxyCodeLine{315   \textcolor{keywordtype}{type}(EOS\_type),     \textcolor{keywordtype}{pointer}       :: EOS\textcolor{comment}{      !< Equation of state structure}}
\DoxyCodeLine{316 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: rho\_ref\textcolor{comment}{  !< A reference density [kg m-\/3].}}
\DoxyCodeLine{317 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{    !< A multiplicative factor by which to scale density}}
\DoxyCodeLine{318 \textcolor{comment}{                                                !! from kg m-\/3 to the desired units [R m3 kg-\/1]}}
\DoxyCodeLine{319   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{320 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(size(T))} :: d2RdTT, d2RdST, d2RdSS, d2RdSp, d2RdTp \textcolor{comment}{! Second derivatives of density wrt T,S,p}}
\DoxyCodeLine{321   \textcolor{keywordtype}{integer} :: j}
\DoxyCodeLine{322 }
\DoxyCodeLine{323   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(eos)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{324     \textcolor{stringliteral}{"calculate\_density\_array called with an unassociated EOS\_type EOS."})}
\DoxyCodeLine{325 }
\DoxyCodeLine{326   \textcolor{keywordflow}{select case} (eos\%form\_of\_EOS)}
\DoxyCodeLine{327     \textcolor{keywordflow}{case} (eos\_linear)}
\DoxyCodeLine{328       \textcolor{keyword}{call }calculate\_density\_linear(t, s, pressure, rho, start, npts, \&}
\DoxyCodeLine{329                                     eos\%Rho\_T0\_S0, eos\%dRho\_dT, eos\%dRho\_dS, rho\_ref)}
\DoxyCodeLine{330       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_linear(t, s, pressure, d2rdss, d2rdst, \&}
\DoxyCodeLine{331                                                   d2rdtt, d2rdsp, d2rdtp, start, npts)}
\DoxyCodeLine{332     \textcolor{keywordflow}{case} (eos\_wright)}
\DoxyCodeLine{333       \textcolor{keyword}{call }calculate\_density\_wright(t, s, pressure, rho, start, npts, rho\_ref)}
\DoxyCodeLine{334       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_wright(t, s, pressure, d2rdss, d2rdst, \&}
\DoxyCodeLine{335                                                   d2rdtt, d2rdsp, d2rdtp, start, npts)}
\DoxyCodeLine{336     \textcolor{keywordflow}{case} (eos\_teos10)}
\DoxyCodeLine{337       \textcolor{keyword}{call }calculate\_density\_teos10(t, s, pressure, rho, start, npts, rho\_ref)}
\DoxyCodeLine{338       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_teos10(t, s, pressure, d2rdss, d2rdst, \&}
\DoxyCodeLine{339                                                   d2rdtt, d2rdsp, d2rdtp, start, npts)}
\DoxyCodeLine{340 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{341       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calculate\_stanley\_density\_array: EOS\%form\_of\_EOS is not valid."})}
\DoxyCodeLine{342 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{343 }
\DoxyCodeLine{344   \textcolor{comment}{! Equation 25 of Stanley et al., 2020.}}
\DoxyCodeLine{345   \textcolor{keywordflow}{do} j=start,start+npts-\/1}
\DoxyCodeLine{346     rho(j) = rho(j) \&}
\DoxyCodeLine{347              + ( 0.5 * d2rdtt(j) * tvar(j) + ( d2rdst(j) * tscov(j) + 0.5 * d2rdss(j) * svar(j) ) )}
\DoxyCodeLine{348 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{349 }
\DoxyCodeLine{350   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (scale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=start,start+npts-\/1}
\DoxyCodeLine{351     rho(j) = scale * rho(j)}
\DoxyCodeLine{352 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{353 }

\end{DoxyCode}
\mbox{\Hypertarget{interfacemom__eos_1_1calculate__density_abf1cef7a943f4ae996c954c45bab9ea1}\label{interfacemom__eos_1_1calculate__density_abf1cef7a943f4ae996c954c45bab9ea1}} 
\index{mom\_eos::calculate\_density@{mom\_eos::calculate\_density}!calculate\_stanley\_density\_scalar@{calculate\_stanley\_density\_scalar}}
\index{calculate\_stanley\_density\_scalar@{calculate\_stanley\_density\_scalar}!mom\_eos::calculate\_density@{mom\_eos::calculate\_density}}
\doxysubsubsection{\texorpdfstring{calculate\_stanley\_density\_scalar()}{calculate\_stanley\_density\_scalar()}}
{\footnotesize\ttfamily subroutine mom\+\_\+eos\+::calculate\+\_\+density\+::calculate\+\_\+stanley\+\_\+density\+\_\+scalar (\begin{DoxyParamCaption}\item[{real, intent(in)}]{T,  }\item[{real, intent(in)}]{S,  }\item[{real, intent(in)}]{pressure,  }\item[{real, intent(in)}]{Tvar,  }\item[{real, intent(in)}]{T\+Scov,  }\item[{real, intent(in)}]{Svar,  }\item[{real, intent(out)}]{rho,  }\item[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{E\+OS,  }\item[{real, intent(in), optional}]{rho\+\_\+ref,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the appropriate subroutine to calculate density of sea water for scalar inputs including the variance of T, S and covariance of T-\/S. The calculation uses only the second order correction in a series as discussed in Stanley et al., 2020. If rho\+\_\+ref is present, the anomaly with respect to rho\+\_\+ref is returned. The density can be rescaled using rho\+\_\+ref. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em t} & Potential temperature referenced to the surface \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tvar} & Variance of potential temperature referenced to the surface \mbox{[}deg\+C2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tscov} & Covariance of potential temperature and salinity \mbox{[}degC ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em svar} & Variance of salinity \mbox{[}ppt2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em pressure} & Pressure \mbox{[}Pa\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em rho} & Density (in-\/situ if pressure is local) \mbox{[}kg m-\/3\mbox{]} or \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
 & {\em eos} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ref} & A reference density \mbox{[}kg m-\/3\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A multiplicative factor by which to scale density from kg m-\/3 to the desired units \mbox{[}R m3 kg-\/1\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{212 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: T\textcolor{comment}{        !< Potential temperature referenced to the surface [degC]}}
\DoxyCodeLine{213 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: S\textcolor{comment}{        !< Salinity [ppt]}}
\DoxyCodeLine{214 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: Tvar\textcolor{comment}{     !< Variance of potential temperature referenced to the surface [degC2]}}
\DoxyCodeLine{215 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: TScov\textcolor{comment}{    !< Covariance of potential temperature and salinity [degC ppt]}}
\DoxyCodeLine{216 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: Svar\textcolor{comment}{     !< Variance of salinity [ppt2]}}
\DoxyCodeLine{217 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(in)}  :: pressure\textcolor{comment}{ !< Pressure [Pa]}}
\DoxyCodeLine{218 \textcolor{keywordtype}{  real},           \textcolor{keywordtype}{intent(out)} :: rho\textcolor{comment}{      !< Density (in-\/situ if pressure is local) [kg m-\/3] or [R \string~> kg m-\/3]}}
\DoxyCodeLine{219   \textcolor{keywordtype}{type}(EOS\_type), \textcolor{keywordtype}{pointer}     :: EOS\textcolor{comment}{      !< Equation of state structure}}
\DoxyCodeLine{220 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: rho\_ref\textcolor{comment}{  !< A reference density [kg m-\/3].}}
\DoxyCodeLine{221 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{    !< A multiplicative factor by which to scale density}}
\DoxyCodeLine{222 \textcolor{comment}{                                          !! from kg m-\/3 to the desired units [R m3 kg-\/1]}}
\DoxyCodeLine{223   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{224 \textcolor{keywordtype}{  real} :: d2RdTT, d2RdST, d2RdSS, d2RdSp, d2RdTp \textcolor{comment}{! Second derivatives of density wrt T,S,p}}
\DoxyCodeLine{225 \textcolor{keywordtype}{  real} :: rho\_scale \textcolor{comment}{! A factor to convert density from kg m-\/3 to the desired units [R m3 kg-\/1 \string~> 1]}}
\DoxyCodeLine{226 \textcolor{keywordtype}{  real} :: p\_scale   \textcolor{comment}{! A factor to convert pressure to units of Pa [Pa T2 R-\/1 L-\/2 \string~> 1]}}
\DoxyCodeLine{227 }
\DoxyCodeLine{228   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(eos)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{229     \textcolor{stringliteral}{"calculate\_stanley\_density\_scalar called with an unassociated EOS\_type EOS."})}
\DoxyCodeLine{230 }
\DoxyCodeLine{231   p\_scale = eos\%RL2\_T2\_to\_Pa}
\DoxyCodeLine{232 }
\DoxyCodeLine{233   \textcolor{keywordflow}{select case} (eos\%form\_of\_EOS)}
\DoxyCodeLine{234     \textcolor{keywordflow}{case} (eos\_linear)}
\DoxyCodeLine{235       \textcolor{keyword}{call }calculate\_density\_linear(t, s, p\_scale*pressure, rho, \&}
\DoxyCodeLine{236                                     eos\%Rho\_T0\_S0, eos\%dRho\_dT, eos\%dRho\_dS, rho\_ref)}
\DoxyCodeLine{237       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_linear(t, s, pressure, d2rdss, d2rdst, \&}
\DoxyCodeLine{238                                                   d2rdtt, d2rdsp, d2rdtp)}
\DoxyCodeLine{239     \textcolor{keywordflow}{case} (eos\_wright)}
\DoxyCodeLine{240       \textcolor{keyword}{call }calculate\_density\_wright(t, s, p\_scale*pressure, rho, rho\_ref)}
\DoxyCodeLine{241       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_wright(t, s, pressure, d2rdss, d2rdst, \&}
\DoxyCodeLine{242                                                   d2rdtt, d2rdsp, d2rdtp)}
\DoxyCodeLine{243     \textcolor{keywordflow}{case} (eos\_teos10)}
\DoxyCodeLine{244       \textcolor{keyword}{call }calculate\_density\_teos10(t, s, p\_scale*pressure, rho, rho\_ref)}
\DoxyCodeLine{245       \textcolor{keyword}{call }calculate\_density\_second\_derivs\_teos10(t, s, pressure, d2rdss, d2rdst, \&}
\DoxyCodeLine{246                                                   d2rdtt, d2rdsp, d2rdtp)}
\DoxyCodeLine{247 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{248       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calculate\_stanley\_density\_scalar: EOS is not valid."})}
\DoxyCodeLine{249 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{250 }
\DoxyCodeLine{251   \textcolor{comment}{! Equation 25 of Stanley et al., 2020.}}
\DoxyCodeLine{252   rho = rho + ( 0.5 * d2rdtt * tvar + ( d2rdst * tscov + 0.5 * d2rdss * svar ) )}
\DoxyCodeLine{253 }
\DoxyCodeLine{254   rho\_scale = eos\%kg\_m3\_to\_R}
\DoxyCodeLine{255   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) rho\_scale = rho\_scale * scale}
\DoxyCodeLine{256   rho = rho\_scale * rho}
\DoxyCodeLine{257 }

\end{DoxyCode}


The documentation for this interface was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/home/cermak/src/\+M\+O\+M6.\+devrob/src/equation\+\_\+of\+\_\+state/M\+O\+M\+\_\+\+E\+O\+S.\+F90\end{DoxyCompactItemize}
