\hypertarget{namespacemom__diagnostics}{}\section{mom\+\_\+diagnostics Module Reference}
\label{namespacemom__diagnostics}\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}


\subsection{Detailed Description}
Calculates any requested diagnostic quantities that are not calculated in the various subroutines. Diagnostic quantities are requested by allocating them memory. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}
\begin{DoxyCompactList}\small\item\em The control structure for the M\+O\+M\+\_\+diagnostics module. \end{DoxyCompactList}\item 
type \hyperlink{structmom__diagnostics_1_1surface__diag__ids}{surface\+\_\+diag\+\_\+ids}
\begin{DoxyCompactList}\small\item\em A structure with diagnostic I\+Ds of the surface and integrated variables. \end{DoxyCompactList}\item 
type \hyperlink{structmom__diagnostics_1_1transport__diag__ids}{transport\+\_\+diag\+\_\+ids}
\begin{DoxyCompactList}\small\item\em A structure with diagnostic I\+Ds of mass transport related diagnostics. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__diagnostics_a6bd689b4d9f660020d8e3960879b4799}{calculate\+\_\+diagnostic\+\_\+fields} (u, v, h, uh, vh, tv, A\+Dp, C\+Dp, p\+\_\+surf, dt, diag\+\_\+pre\+\_\+sync, G, GV, US, CS, eta\+\_\+bt)
\begin{DoxyCompactList}\small\item\em Diagnostics not more naturally calculated elsewhere are computed here. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__diagnostics_ab43b50cd32dfe693c6ce575c279988fb}{find\+\_\+weights} (Rlist, R\+\_\+in, k, nz, wt, wt\+\_\+p)
\begin{DoxyCompactList}\small\item\em This subroutine finds the location of R\+\_\+in in an increasing ordered list, Rlist, returning as k the element such that Rlist(k) $<$= R\+\_\+in $<$ Rlist(k+1), and where wt and wt\+\_\+p are the linear weights that should be assigned to elements k and k+1. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__diagnostics_a3dc7691c006b2abc1c355adc8e4d1a34}{calculate\+\_\+vertical\+\_\+integrals} (h, tv, p\+\_\+surf, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em This subroutine calculates vertical integrals of several tracers, along with the mass-\/weight of these tracers, the total column mass, and the carefully calculated column height. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__diagnostics_ad8679de99516ebb0ec2a973c441f2fec}{calculate\+\_\+energy\+\_\+diagnostics} (u, v, h, uh, vh, A\+Dp, C\+Dp, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em This subroutine calculates terms in the mechanical energy budget. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_addfe6cd212e836194ccaf737bcc5cce8}{register\+\_\+time\+\_\+deriv} (lb, f\+\_\+ptr, deriv\+\_\+ptr, CS)
\begin{DoxyCompactList}\small\item\em This subroutine registers fields to calculate a diagnostic time derivative. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__diagnostics_ad69737c75e3f4a36546c8437fb39b099}{calculate\+\_\+derivs} (dt, G, CS)
\begin{DoxyCompactList}\small\item\em This subroutine calculates all registered time derivatives. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_ac756556059608d88e6a4ef34a07e60ee}{post\+\_\+surface\+\_\+dyn\+\_\+diags} (I\+Ds, G, diag, sfc\+\_\+state, ssh)
\begin{DoxyCompactList}\small\item\em This routine posts diagnostics of various dynamic ocean surface quantities, including velocities, speed and sea surface height, at the time the ocean state is reported back to the caller. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_a6fc7dbf8144ba279cc9b7856780ba5d6}{post\+\_\+surface\+\_\+thermo\+\_\+diags} (I\+Ds, G, GV, US, diag, dt\+\_\+int, sfc\+\_\+state, tv, ssh, ssh\+\_\+ibc)
\begin{DoxyCompactList}\small\item\em This routine posts diagnostics of various ocean surface and integrated quantities at the time the ocean state is reported back to the caller. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_acab7430159d4702301069d0d4f82f45c}{post\+\_\+transport\+\_\+diagnostics} (G, GV, US, uhtr, vhtr, h, I\+Ds, diag\+\_\+pre\+\_\+dyn, diag, dt\+\_\+trans, Reg)
\begin{DoxyCompactList}\small\item\em This routine posts diagnostics of the transports, including the subgridscale contributions. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_ae8281123dfff124b0a362ea9fd1e0078}{mom\+\_\+diagnostics\+\_\+init} (M\+IS, A\+Dp, C\+Dp, Time, G, GV, US, param\+\_\+file, diag, CS, tv)
\begin{DoxyCompactList}\small\item\em This subroutine registers various diagnostics and allocates space for fields that other diagnostis depend upon. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_ae9e2f6374b60bc78898a3c462174f90d}{register\+\_\+surface\+\_\+diags} (Time, G, US, I\+Ds, diag, tv)
\begin{DoxyCompactList}\small\item\em Register diagnostics of the surface state and integrated quantities. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_ac16b7c49e4a4b5ea2beb426bc5270ee9}{register\+\_\+transport\+\_\+diags} (Time, G, GV, US, I\+Ds, diag)
\begin{DoxyCompactList}\small\item\em Register certain diagnostics related to transports. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_af505e1356cf2f8172d27b60136b928e4}{write\+\_\+static\+\_\+fields} (G, GV, US, tv, diag)
\begin{DoxyCompactList}\small\item\em Offers the static fields in the ocean grid type for output via the diag\+\_\+manager. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__diagnostics_a90a92410576d955e89d2aa4e3f6d7402}{set\+\_\+dependent\+\_\+diagnostics} (M\+IS, A\+Dp, C\+Dp, G, CS)
\begin{DoxyCompactList}\small\item\em This subroutine sets up diagnostics upon which other diagnostics depend. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diagnostics_ae7ada8fb77b23b1b4cfb10d8c8b0ba50}{mom\+\_\+diagnostics\+\_\+end} (CS, A\+Dp)
\begin{DoxyCompactList}\small\item\em Deallocate memory associated with the diagnostics module. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__diagnostics_ad69737c75e3f4a36546c8437fb39b099}\label{namespacemom__diagnostics_ad69737c75e3f4a36546c8437fb39b099}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!calculate\+\_\+derivs@{calculate\+\_\+derivs}}
\index{calculate\+\_\+derivs@{calculate\+\_\+derivs}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{calculate\+\_\+derivs()}{calculate\_derivs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diagnostics\+::calculate\+\_\+derivs (\begin{DoxyParamCaption}\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), intent(inout)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates all registered time derivatives. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em dt} & The time interval over which differences occur \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in,out}  & {\em cs} & Control structure returned by previous call to diagnostics\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 1194 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1194   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< The time interval over which differences occur [T ~> s].}
1195   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
1196   \textcolor{keywordtype}{type}(diagnostics\_cs),  \textcolor{keywordtype}{intent(inout)} :: cs\textcolor{comment}{   !< Control structure returned by previous call to}
1197 \textcolor{comment}{                                               !! diagnostics\_init.}
1198 
1199 \textcolor{comment}{! This subroutine calculates all registered time derivatives.}
1200   \textcolor{keywordtype}{real} :: idt  \textcolor{comment}{! The inverse timestep [T-1 ~> s-1]}
1201   \textcolor{keywordtype}{integer} :: i, j, k, m
1202 
1203   \textcolor{keywordflow}{if} (dt > 0.0) \textcolor{keywordflow}{then} ; idt = 1.0/dt
1204   \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{return} ;\textcolor{keywordflow}{ endif}
1205 
1206   \textcolor{comment}{! Because the field is unknown, its grid index bounds are also unknown.}
1207   \textcolor{comment}{! Additionally, two of the fields (dudt, dvdt) require calculation of spatial}
1208   \textcolor{comment}{! derivatives when computing d(KE)/dt.  This raises issues in non-symmetric}
1209   \textcolor{comment}{! mode, where the symmetric boundaries (west, south) may not be updated.}
1210 
1211   \textcolor{comment}{! For this reason, we explicitly loop from isc-1:iec and jsc-1:jec, in order}
1212   \textcolor{comment}{! to force boundary value updates, even though it may not be strictly valid}
1213   \textcolor{comment}{! for all fields.  Note this assumes a halo, and that it has been updated.}
1214 
1215   \textcolor{keywordflow}{do} m=1,cs%num\_time\_deriv
1216     \textcolor{keywordflow}{do} k=1,cs%nlay(m) ; \textcolor{keywordflow}{do} j=g%jsc-1,g%jec ; \textcolor{keywordflow}{do} i=g%isc-1,g%iec
1217       cs%deriv(m)%p(i,j,k) = (cs%var\_ptr(m)%p(i,j,k) - cs%prev\_val(m)%p(i,j,k)) * idt
1218       cs%prev\_val(m)%p(i,j,k) = cs%var\_ptr(m)%p(i,j,k)
1219 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1220 \textcolor{keywordflow}{  enddo}
1221 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_a6bd689b4d9f660020d8e3960879b4799}\label{namespacemom__diagnostics_a6bd689b4d9f660020d8e3960879b4799}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!calculate\+\_\+diagnostic\+\_\+fields@{calculate\+\_\+diagnostic\+\_\+fields}}
\index{calculate\+\_\+diagnostic\+\_\+fields@{calculate\+\_\+diagnostic\+\_\+fields}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{calculate\+\_\+diagnostic\+\_\+fields()}{calculate\_diagnostic\_fields()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::calculate\+\_\+diagnostic\+\_\+fields (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{uh,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{vh,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(accel\+\_\+diag\+\_\+ptrs), intent(in)}]{A\+Dp,  }\item[{type(cont\+\_\+diag\+\_\+ptrs), intent(in)}]{C\+Dp,  }\item[{real, dimension(\+:,\+:), pointer}]{p\+\_\+surf,  }\item[{real, intent(in)}]{dt,  }\item[{type(diag\+\_\+grid\+\_\+storage), intent(in)}]{diag\+\_\+pre\+\_\+sync,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), intent(inout)}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{eta\+\_\+bt }\end{DoxyParamCaption})}



Diagnostics not more naturally calculated elsewhere are computed here. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em uh} & Transport through zonal faces = u$\ast$h$\ast$dy,\\
\hline
\mbox{\tt in}  & {\em vh} & Transport through meridional faces = v$\ast$h$\ast$dx,\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables.\\
\hline
\mbox{\tt in}  & {\em adp} & structure with pointers to accelerations in momentum equation.\\
\hline
\mbox{\tt in}  & {\em cdp} & structure with pointers to terms in continuity equation.\\
\hline
 & {\em p\+\_\+surf} & A pointer to the surface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. If p\+\_\+surf is not associated, it is the same as setting the surface pressure to 0.\\
\hline
\mbox{\tt in}  & {\em dt} & The time difference since the last call to this subroutine \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em diag\+\_\+pre\+\_\+sync} & Target grids from previous timestep\\
\hline
\mbox{\tt in,out}  & {\em cs} & Control structure returned by a previous call to diagnostics\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em eta\+\_\+bt} & An optional barotropic \\
\hline
\end{DoxyParams}


Definition at line 197 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
197   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
198   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
199   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
200   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
201                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< The zonal velocity [L T-1 ~> m s-1].}
202   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
203                            \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< The meridional velocity [L T-1 ~> m s-1].}
204   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
205                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2].}
206   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
207                            \textcolor{keywordtype}{intent(in)}    :: uh\textcolor{comment}{   !< Transport through zonal faces = u*h*dy,}
208 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
209   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
210                            \textcolor{keywordtype}{intent(in)}    :: vh\textcolor{comment}{   !< Transport through meridional faces = v*h*dx,}
211 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
212   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various}
213 \textcolor{comment}{                                                 !! thermodynamic variables.}
214   \textcolor{keywordtype}{type}(accel\_diag\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: adp\textcolor{comment}{  !< structure with pointers to}
215 \textcolor{comment}{                                                 !! accelerations in momentum equation.}
216   \textcolor{keywordtype}{type}(cont\_diag\_ptrs),    \textcolor{keywordtype}{intent(in)}    :: cdp\textcolor{comment}{  !< structure with pointers to}
217 \textcolor{comment}{                                                 !! terms in continuity equation.}
218   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},    \textcolor{keywordtype}{pointer}       :: p\_surf\textcolor{comment}{ !< A pointer to the surface pressure [R L2 T-2 ~> Pa].}
219 \textcolor{comment}{                                                 !! If p\_surf is not associated, it is the same}
220 \textcolor{comment}{                                                 !! as setting the surface pressure to 0.}
221   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< The time difference since the last}
222 \textcolor{comment}{                                                 !! call to this subroutine [T ~> s].}
223   \textcolor{keywordtype}{type}(diag\_grid\_storage), \textcolor{keywordtype}{intent(in)}    :: diag\_pre\_sync\textcolor{comment}{ !< Target grids from previous timestep}
224   \textcolor{keywordtype}{type}(diagnostics\_cs),    \textcolor{keywordtype}{intent(inout)} :: cs\textcolor{comment}{   !< Control structure returned by a}
225 \textcolor{comment}{                                                 !! previous call to diagnostics\_init.}
226   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
227                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}   :: eta\_bt\textcolor{comment}{ !< An optional barotropic}
228 \textcolor{comment}{    !! variable that gives the "correct" free surface height (Boussinesq) or total water column}
229 \textcolor{comment}{    !! mass per unit area (non-Boussinesq).  This is used to dilate the layer thicknesses when}
230 \textcolor{comment}{    !! calculating interface heights [H ~> m or kg m-2].}
231 
232   \textcolor{comment}{! Local variables}
233   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: eosdom \textcolor{comment}{! The i-computational domain for the equation of state}
234   \textcolor{keywordtype}{integer} i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz, nkmb
235 
236   \textcolor{keywordtype}{real} :: rcv(szi\_(g),szj\_(g),szk\_(g))  \textcolor{comment}{! Coordinate variable potential density [R ~> kg m-3].}
237   \textcolor{keywordtype}{real} :: work\_3d(szi\_(g),szj\_(g),szk\_(g)) \textcolor{comment}{! A 3-d temporary work array.}
238   \textcolor{keywordtype}{real} :: work\_2d(szi\_(g),szj\_(g))         \textcolor{comment}{! A 2-d temporary work array.}
239   \textcolor{keywordtype}{real} :: rho\_in\_situ(szi\_(g))             \textcolor{comment}{! In situ density [R ~> kg m-3]}
240 
241   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: &
242     hf\_du\_dt\_2d, hf\_dv\_dt\_2d \textcolor{comment}{! z integeral of hf\_du\_dt, hf\_dv\_dt [L T-2 ~> m s-2].}
243 
244   \textcolor{comment}{! tmp array for surface properties}
245   \textcolor{keywordtype}{real} :: surface\_field(szi\_(g),szj\_(g))
246   \textcolor{keywordtype}{real} :: pressure\_1d(szi\_(g)) \textcolor{comment}{! Temporary array for pressure when calling EOS [R L2 T-2 ~> Pa]}
247   \textcolor{keywordtype}{real} :: wt, wt\_p
248 
249   \textcolor{keywordtype}{real} :: f2\_h     \textcolor{comment}{! Squared Coriolis parameter at to h-points [T-2 ~> s-2]}
250   \textcolor{keywordtype}{real} :: mag\_beta \textcolor{comment}{! Magnitude of the gradient of f [T-1 L-1 ~> s-1 m-1]}
251   \textcolor{keywordtype}{real} :: absurdly\_small\_freq2 \textcolor{comment}{! Frequency squared used to avoid division by 0 [T-2 ~> s-2]}
252 
253   \textcolor{keywordtype}{integer} :: k\_list
254 
255   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))} :: temp\_layer\_ave, salt\_layer\_ave
256   \textcolor{keywordtype}{real} :: thetaoga, soga, masso, tosga, sosga
257 
258   is  = g%isc  ; ie   = g%iec  ; js  = g%jsc  ; je  = g%jec
259   isq = g%IscB ; ieq  = g%IecB ; jsq = g%JscB ; jeq = g%JecB
260   nz  = g%ke   ; nkmb = gv%nk\_rho\_varies
261 
262   \textcolor{comment}{! This value is roughly (pi / (the age of the universe) )^2.}
263   absurdly\_small\_freq2 = 1e-34*us%T\_to\_s**2
264 
265   \textcolor{keywordflow}{if} (loc(cs)==0) \textcolor{keyword}{call }mom\_error(fatal, &
266          \textcolor{stringliteral}{"calculate\_diagnostic\_fields: Module must be initialized before used."})
267 
268   \textcolor{keyword}{call }calculate\_derivs(dt, g, cs)
269 
270   \textcolor{keywordflow}{if} (dt > 0.0) \textcolor{keywordflow}{then}
271     \textcolor{keyword}{call }diag\_save\_grids(cs%diag)
272     \textcolor{keyword}{call }diag\_copy\_storage\_to\_diag(cs%diag, diag\_pre\_sync)
273 
274     \textcolor{keywordflow}{if} (cs%id\_h\_pre\_sync > 0) &
275         \textcolor{keyword}{call }post\_data(cs%id\_h\_pre\_sync, diag\_pre\_sync%h\_state, cs%diag, alt\_h = diag\_pre\_sync%h\_state)
276 
277     \textcolor{keywordflow}{if} (cs%id\_du\_dt>0) \textcolor{keyword}{call }post\_data(cs%id\_du\_dt, cs%du\_dt, cs%diag, alt\_h = diag\_pre\_sync%h\_state)
278 
279     \textcolor{keywordflow}{if} (cs%id\_dv\_dt>0) \textcolor{keyword}{call }post\_data(cs%id\_dv\_dt, cs%dv\_dt, cs%diag, alt\_h = diag\_pre\_sync%h\_state)
280 
281     \textcolor{keywordflow}{if} (cs%id\_dh\_dt>0) \textcolor{keyword}{call }post\_data(cs%id\_dh\_dt, cs%dh\_dt, cs%diag, alt\_h = diag\_pre\_sync%h\_state)
282 
283     \textcolor{comment}{!! Diagnostics for terms multiplied by fractional thicknesses}
284 
285     \textcolor{comment}{! 3D diagnostics hf\_du(dv)\_dt are commented because there is no clarity on proper remapping grid
       option.}
286     \textcolor{comment}{! The code is retained for degugging purposes in the future.}
287     \textcolor{comment}{!if (CS%id\_hf\_du\_dt > 0) then}
288     \textcolor{comment}{!  do k=1,nz ; do j=js,je ; do I=Isq,Ieq}
289     \textcolor{comment}{!    CS%hf\_du\_dt(I,j,k) = CS%du\_dt(I,j,k) * ADp%diag\_hfrac\_u(I,j,k)}
290     \textcolor{comment}{!  enddo ; enddo ; enddo}
291     \textcolor{comment}{!  call post\_data(CS%id\_hf\_du\_dt, CS%hf\_du\_dt, CS%diag, alt\_h = diag\_pre\_sync%h\_state)}
292     \textcolor{comment}{!endif}
293 
294     \textcolor{comment}{!if (CS%id\_hf\_dv\_dt > 0) then}
295     \textcolor{comment}{!  do k=1,nz ; do J=Jsq,Jeq ; do i=is,ie}
296     \textcolor{comment}{!    CS%hf\_dv\_dt(i,J,k) = CS%dv\_dt(i,J,k) * ADp%diag\_hfrac\_v(i,J,k)}
297     \textcolor{comment}{!  enddo ; enddo ; enddo}
298     \textcolor{comment}{!  call post\_data(CS%id\_hf\_dv\_dt, CS%hf\_dv\_dt, CS%diag, alt\_h = diag\_pre\_sync%h\_state)}
299     \textcolor{comment}{!endif}
300 
301     \textcolor{keywordflow}{if} (cs%id\_hf\_du\_dt\_2d > 0) \textcolor{keywordflow}{then}
302       \textcolor{keyword}{allocate}(hf\_du\_dt\_2d(g%IsdB:g%IedB,g%jsd:g%jed))
303       hf\_du\_dt\_2d(:,:) = 0.0
304       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
305         hf\_du\_dt\_2d(i,j) = hf\_du\_dt\_2d(i,j) + cs%du\_dt(i,j,k) * adp%diag\_hfrac\_u(i,j,k)
306 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
307       \textcolor{keyword}{call }post\_data(cs%id\_hf\_du\_dt\_2d, hf\_du\_dt\_2d, cs%diag)
308       \textcolor{keyword}{deallocate}(hf\_du\_dt\_2d)
309 \textcolor{keywordflow}{    endif}
310 
311     \textcolor{keywordflow}{if} (cs%id\_hf\_dv\_dt\_2d > 0) \textcolor{keywordflow}{then}
312       \textcolor{keyword}{allocate}(hf\_dv\_dt\_2d(g%isd:g%ied,g%JsdB:g%JedB))
313       hf\_dv\_dt\_2d(:,:) = 0.0
314       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
315         hf\_dv\_dt\_2d(i,j) = hf\_dv\_dt\_2d(i,j) + cs%dv\_dt(i,j,k) * adp%diag\_hfrac\_v(i,j,k)
316 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
317       \textcolor{keyword}{call }post\_data(cs%id\_hf\_dv\_dt\_2d, hf\_dv\_dt\_2d, cs%diag)
318       \textcolor{keyword}{deallocate}(hf\_dv\_dt\_2d)
319 \textcolor{keywordflow}{    endif}
320 
321     \textcolor{keyword}{call }diag\_restore\_grids(cs%diag)
322 
323     \textcolor{keyword}{call }calculate\_energy\_diagnostics(u, v, h, uh, vh, adp, cdp, g, gv, us, cs)
324 \textcolor{keywordflow}{  endif}
325 
326   \textcolor{comment}{! smg: is the following robust to ALE? It seems a bit opaque.}
327   \textcolor{comment}{! If the model is NOT in isopycnal mode then nkmb=0. But we need all the}
328   \textcolor{comment}{! following diagnostics to treat all layers as variable density, so we set}
329   \textcolor{comment}{! nkmb = nz, on the expectation that loops nkmb+1,nz will not iterate.}
330   \textcolor{comment}{! This behavior is ANSI F77 but some compiler options can force at least}
331   \textcolor{comment}{! one iteration that would break the following one-line workaround!}
332   \textcolor{keywordflow}{if} (nkmb==0 .and. nz > 1) nkmb = nz
333 
334   \textcolor{keywordflow}{if} (cs%id\_u > 0) \textcolor{keyword}{call }post\_data(cs%id\_u, u, cs%diag)
335 
336   \textcolor{keywordflow}{if} (cs%id\_v > 0) \textcolor{keyword}{call }post\_data(cs%id\_v, v, cs%diag)
337 
338   \textcolor{keywordflow}{if} (cs%id\_h > 0) \textcolor{keyword}{call }post\_data(cs%id\_h, h, cs%diag)
339 
340   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%e)) \textcolor{keywordflow}{then}
341     \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, cs%e, eta\_bt)
342     \textcolor{keywordflow}{if} (cs%id\_e > 0) \textcolor{keyword}{call }post\_data(cs%id\_e, cs%e, cs%diag)
343 \textcolor{keywordflow}{  endif}
344 
345   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%e\_D)) \textcolor{keywordflow}{then}
346     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%e)) \textcolor{keywordflow}{then}
347       \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
348         cs%e\_D(i,j,k) = cs%e(i,j,k) + g%bathyT(i,j)
349 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
350     \textcolor{keywordflow}{else}
351       \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, cs%e\_D, eta\_bt)
352       \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
353         cs%e\_D(i,j,k) = cs%e\_D(i,j,k) + g%bathyT(i,j)
354 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
355 \textcolor{keywordflow}{    endif}
356 
357     \textcolor{keywordflow}{if} (cs%id\_e\_D > 0) \textcolor{keyword}{call }post\_data(cs%id\_e\_D, cs%e\_D, cs%diag)
358 \textcolor{keywordflow}{  endif}
359 
360   \textcolor{comment}{! mass per area of grid cell (for Bouss, use Rho0)}
361   \textcolor{keywordflow}{if} (cs%id\_masscello > 0) \textcolor{keywordflow}{then}
362     \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
363       work\_3d(i,j,k) = gv%H\_to\_kg\_m2*h(i,j,k)
364 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
365     \textcolor{keyword}{call }post\_data(cs%id\_masscello, work\_3d, cs%diag)
366 \textcolor{keywordflow}{  endif}
367 
368   \textcolor{comment}{! mass of liquid ocean (for Bouss, use Rho0). The reproducing sum requires the use of MKS units.}
369   \textcolor{keywordflow}{if} (cs%id\_masso > 0) \textcolor{keywordflow}{then}
370     work\_2d(:,:) = 0.0
371     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
372       work\_2d(i,j) = work\_2d(i,j) + (gv%H\_to\_kg\_m2*h(i,j,k)) * us%L\_to\_m**2*g%areaT(i,j)
373 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
374     masso = reproducing\_sum(work\_2d)
375     \textcolor{keyword}{call }post\_data(cs%id\_masso, masso, cs%diag)
376 \textcolor{keywordflow}{  endif}
377 
378   \textcolor{comment}{! diagnose thickness/volumes of grid cells [m]}
379   \textcolor{keywordflow}{if} (cs%id\_thkcello>0 .or. cs%id\_volcello>0) \textcolor{keywordflow}{then}
380     \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then} \textcolor{comment}{! thkcello = h for Boussinesq}
381       \textcolor{keywordflow}{if} (cs%id\_thkcello > 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (gv%H\_to\_Z == 1.0) \textcolor{keywordflow}{then}
382         \textcolor{keyword}{call }post\_data(cs%id\_thkcello, h, cs%diag)
383       \textcolor{keywordflow}{else}
384         \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
385           work\_3d(i,j,k) = gv%H\_to\_Z*h(i,j,k)
386 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
387         \textcolor{keyword}{call }post\_data(cs%id\_thkcello, work\_3d, cs%diag)
388 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ endif}
389       \textcolor{keywordflow}{if} (cs%id\_volcello > 0) \textcolor{keywordflow}{then} \textcolor{comment}{! volcello = h*area for Boussinesq}
390         \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
391           work\_3d(i,j,k) = ( gv%H\_to\_Z*h(i,j,k) ) * us%Z\_to\_m*us%L\_to\_m**2*g%areaT(i,j)
392 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
393         \textcolor{keyword}{call }post\_data(cs%id\_volcello, work\_3d, cs%diag)
394 \textcolor{keywordflow}{      endif}
395     \textcolor{keywordflow}{else} \textcolor{comment}{! thkcello = dp/(rho*g) for non-Boussinesq}
396       eosdom(:) = eos\_domain(g%HI)
397       \textcolor{keywordflow}{do} j=js,je
398         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_surf)) \textcolor{keywordflow}{then} \textcolor{comment}{! Pressure loading at top of surface layer [R L2 T-2 ~> Pa]}
399           \textcolor{keywordflow}{do} i=is,ie
400             pressure\_1d(i) = p\_surf(i,j)
401 \textcolor{keywordflow}{          enddo}
402         \textcolor{keywordflow}{else}
403           \textcolor{keywordflow}{do} i=is,ie
404             pressure\_1d(i) = 0.0
405 \textcolor{keywordflow}{          enddo}
406 \textcolor{keywordflow}{        endif}
407         \textcolor{keywordflow}{do} k=1,nz \textcolor{comment}{! Integrate vertically downward for pressure}
408           \textcolor{keywordflow}{do} i=is,ie \textcolor{comment}{! Pressure for EOS at the layer center [R L2 T-2 ~> Pa]}
409             pressure\_1d(i) = pressure\_1d(i) + 0.5*(gv%H\_to\_RZ*gv%g\_Earth)*h(i,j,k)
410 \textcolor{keywordflow}{          enddo}
411           \textcolor{comment}{! Store in-situ density [R ~> kg m-3] in work\_3d}
412           \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), pressure\_1d, rho\_in\_situ, &
413                                  tv%eqn\_of\_state, eosdom)
414           \textcolor{keywordflow}{do} i=is,ie \textcolor{comment}{! Cell thickness = dz = dp/(g*rho) (meter); store in work\_3d}
415             work\_3d(i,j,k) = (gv%H\_to\_RZ*h(i,j,k)) / rho\_in\_situ(i)
416 \textcolor{keywordflow}{          enddo}
417           \textcolor{keywordflow}{do} i=is,ie \textcolor{comment}{! Pressure for EOS at the bottom interface [R L2 T-2 ~> Pa]}
418             pressure\_1d(i) = pressure\_1d(i) + 0.5*(gv%H\_to\_RZ*gv%g\_Earth)*h(i,j,k)
419 \textcolor{keywordflow}{          enddo}
420 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! k}
421 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! j}
422       \textcolor{keywordflow}{if} (cs%id\_thkcello > 0) \textcolor{keyword}{call }post\_data(cs%id\_thkcello, work\_3d, cs%diag)
423       \textcolor{keywordflow}{if} (cs%id\_volcello > 0) \textcolor{keywordflow}{then}
424         \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie \textcolor{comment}{! volcello = dp/(rho*g)*area for non-Boussinesq}
425           work\_3d(i,j,k) = us%Z\_to\_m*us%L\_to\_m**2*g%areaT(i,j) * work\_3d(i,j,k)
426 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
427         \textcolor{keyword}{call }post\_data(cs%id\_volcello, work\_3d, cs%diag)
428 \textcolor{keywordflow}{      endif}
429 \textcolor{keywordflow}{    endif}
430 \textcolor{keywordflow}{  endif}
431 
432   \textcolor{comment}{! Calculate additional, potentially derived temperature diagnostics}
433   \textcolor{keywordflow}{if} (tv%T\_is\_conT) \textcolor{keywordflow}{then}
434     \textcolor{comment}{! Internal T&S variables are conservative temperature & absolute salinity,}
435     \textcolor{comment}{! so they need to converted to potential temperature and practical salinity}
436     \textcolor{comment}{! for some diagnostics using TEOS-10 function calls.}
437     \textcolor{keywordflow}{if} ((cs%id\_Tpot > 0) .or. (cs%id\_tob > 0)) \textcolor{keywordflow}{then}
438       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
439         work\_3d(i,j,k) = gsw\_pt\_from\_ct(tv%S(i,j,k),tv%T(i,j,k))
440 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
441       \textcolor{keywordflow}{if} (cs%id\_Tpot > 0) \textcolor{keyword}{call }post\_data(cs%id\_Tpot, work\_3d, cs%diag)
442       \textcolor{keywordflow}{if} (cs%id\_tob > 0) \textcolor{keyword}{call }post\_data(cs%id\_tob, work\_3d(:,:,nz), cs%diag, mask=g%mask2dT)
443 \textcolor{keywordflow}{    endif}
444   \textcolor{keywordflow}{else}
445     \textcolor{comment}{! Internal T&S variables are potential temperature & practical salinity}
446     \textcolor{keywordflow}{if} (cs%id\_tob > 0) \textcolor{keyword}{call }post\_data(cs%id\_tob, tv%T(:,:,nz), cs%diag, mask=g%mask2dT)
447 \textcolor{keywordflow}{  endif}
448 
449   \textcolor{comment}{! Calculate additional, potentially derived salinity diagnostics}
450   \textcolor{keywordflow}{if} (tv%S\_is\_absS) \textcolor{keywordflow}{then}
451     \textcolor{comment}{! Internal T&S variables are conservative temperature & absolute salinity,}
452     \textcolor{comment}{! so they need to converted to potential temperature and practical salinity}
453     \textcolor{comment}{! for some diagnostics using TEOS-10 function calls.}
454     \textcolor{keywordflow}{if} ((cs%id\_Sprac > 0) .or. (cs%id\_sob > 0)) \textcolor{keywordflow}{then}
455       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
456         work\_3d(i,j,k) = gsw\_sp\_from\_sr(tv%S(i,j,k))
457 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
458       \textcolor{keywordflow}{if} (cs%id\_Sprac > 0) \textcolor{keyword}{call }post\_data(cs%id\_Sprac, work\_3d, cs%diag)
459       \textcolor{keywordflow}{if} (cs%id\_sob > 0) \textcolor{keyword}{call }post\_data(cs%id\_sob, work\_3d(:,:,nz), cs%diag, mask=g%mask2dT)
460 \textcolor{keywordflow}{    endif}
461   \textcolor{keywordflow}{else}
462     \textcolor{comment}{! Internal T&S variables are potential temperature & practical salinity}
463     \textcolor{keywordflow}{if} (cs%id\_sob > 0) \textcolor{keyword}{call }post\_data(cs%id\_sob, tv%S(:,:,nz), cs%diag, mask=g%mask2dT)
464 \textcolor{keywordflow}{  endif}
465 
466   \textcolor{comment}{! volume mean potential temperature}
467   \textcolor{keywordflow}{if} (cs%id\_thetaoga>0) \textcolor{keywordflow}{then}
468     thetaoga = global\_volume\_mean(tv%T, h, g, gv)
469     \textcolor{keyword}{call }post\_data(cs%id\_thetaoga, thetaoga, cs%diag)
470 \textcolor{keywordflow}{  endif}
471 
472   \textcolor{comment}{! area mean SST}
473   \textcolor{keywordflow}{if} (cs%id\_tosga > 0) \textcolor{keywordflow}{then}
474     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
475        surface\_field(i,j) = tv%T(i,j,1)
476 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
477     tosga = global\_area\_mean(surface\_field, g)
478     \textcolor{keyword}{call }post\_data(cs%id\_tosga, tosga, cs%diag)
479 \textcolor{keywordflow}{  endif}
480 
481   \textcolor{comment}{! volume mean salinity}
482   \textcolor{keywordflow}{if} (cs%id\_soga>0) \textcolor{keywordflow}{then}
483     soga = global\_volume\_mean(tv%S, h, g, gv)
484     \textcolor{keyword}{call }post\_data(cs%id\_soga, soga, cs%diag)
485 \textcolor{keywordflow}{  endif}
486 
487   \textcolor{comment}{! area mean SSS}
488   \textcolor{keywordflow}{if} (cs%id\_sosga > 0) \textcolor{keywordflow}{then}
489     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
490        surface\_field(i,j) = tv%S(i,j,1)
491 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
492     sosga = global\_area\_mean(surface\_field, g)
493     \textcolor{keyword}{call }post\_data(cs%id\_sosga, sosga, cs%diag)
494 \textcolor{keywordflow}{  endif}
495 
496   \textcolor{comment}{! layer mean potential temperature}
497   \textcolor{keywordflow}{if} (cs%id\_temp\_layer\_ave>0) \textcolor{keywordflow}{then}
498     temp\_layer\_ave = global\_layer\_mean(tv%T, h, g, gv)
499     \textcolor{keyword}{call }post\_data(cs%id\_temp\_layer\_ave, temp\_layer\_ave, cs%diag)
500 \textcolor{keywordflow}{  endif}
501 
502   \textcolor{comment}{! layer mean salinity}
503   \textcolor{keywordflow}{if} (cs%id\_salt\_layer\_ave>0) \textcolor{keywordflow}{then}
504     salt\_layer\_ave = global\_layer\_mean(tv%S, h, g, gv)
505     \textcolor{keyword}{call }post\_data(cs%id\_salt\_layer\_ave, salt\_layer\_ave, cs%diag)
506 \textcolor{keywordflow}{  endif}
507 
508   \textcolor{keyword}{call }calculate\_vertical\_integrals(h, tv, p\_surf, g, gv, us, cs)
509 
510   \textcolor{keywordflow}{if} ((cs%id\_Rml > 0) .or. (cs%id\_Rcv > 0) .or. \textcolor{keyword}{associated}(cs%h\_Rlay) .or. &
511       \textcolor{keyword}{associated}(cs%uh\_Rlay) .or. \textcolor{keyword}{associated}(cs%vh\_Rlay) .or. &
512       \textcolor{keyword}{associated}(cs%uhGM\_Rlay) .or. \textcolor{keyword}{associated}(cs%vhGM\_Rlay)) \textcolor{keywordflow}{then}
513 
514     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%eqn\_of\_state)) \textcolor{keywordflow}{then}
515       eosdom(:) = eos\_domain(g%HI, halo=1)
516       pressure\_1d(:) = tv%P\_Ref
517       \textcolor{comment}{!$OMP parallel do default(shared)}
518       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je+1
519         \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), pressure\_1d, rcv(:,j,k), tv%eqn\_of\_state, &
520                                eosdom)
521 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
522     \textcolor{keywordflow}{else} \textcolor{comment}{! Rcv should not be used much in this case, so fill in sensible values.}
523       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
524         rcv(i,j,k) = gv%Rlay(k)
525 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
526 \textcolor{keywordflow}{    endif}
527     \textcolor{keywordflow}{if} (cs%id\_Rml > 0) \textcolor{keyword}{call }post\_data(cs%id\_Rml, rcv, cs%diag)
528     \textcolor{keywordflow}{if} (cs%id\_Rcv > 0) \textcolor{keyword}{call }post\_data(cs%id\_Rcv, rcv, cs%diag)
529 
530     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%h\_Rlay)) \textcolor{keywordflow}{then}
531       k\_list = nz/2
532 \textcolor{comment}{!$OMP parallel do default(none) shared(is,ie,js,je,nz,nkmb,CS,Rcv,h,GV) &}
533 \textcolor{comment}{!$OMP                          private(wt,wt\_p) firstprivate(k\_list)}
534       \textcolor{keywordflow}{do} j=js,je
535         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=is,ie
536           cs%h\_Rlay(i,j,k) = 0.0
537 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
538         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=is,ie
539           cs%h\_Rlay(i,j,k) = h(i,j,k)
540 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
541         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=is,ie
542           \textcolor{keyword}{call }find\_weights(gv%Rlay, rcv(i,j,k), k\_list, nz, wt, wt\_p)
543           cs%h\_Rlay(i,j,k\_list)   = cs%h\_Rlay(i,j,k\_list)   + h(i,j,k)*wt
544           cs%h\_Rlay(i,j,k\_list+1) = cs%h\_Rlay(i,j,k\_list+1) + h(i,j,k)*wt\_p
545 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
546 \textcolor{keywordflow}{      enddo}
547 
548       \textcolor{keywordflow}{if} (cs%id\_h\_Rlay > 0) \textcolor{keyword}{call }post\_data(cs%id\_h\_Rlay, cs%h\_Rlay, cs%diag)
549 \textcolor{keywordflow}{    endif}
550 
551     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%uh\_Rlay)) \textcolor{keywordflow}{then}
552       k\_list = nz/2
553 \textcolor{comment}{!$OMP parallel do default(none) shared(Isq,Ieq,js,je,nz,nkmb,Rcv,CS,GV,uh) &}
554 \textcolor{comment}{!$OMP                          private(wt,wt\_p) firstprivate(k\_list)}
555       \textcolor{keywordflow}{do} j=js,je
556         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=isq,ieq
557           cs%uh\_Rlay(i,j,k) = 0.0
558 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
559         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=isq,ieq
560           cs%uh\_Rlay(i,j,k) = uh(i,j,k)
561 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
562         k\_list = nz/2
563         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=isq,ieq
564           \textcolor{keyword}{call }find\_weights(gv%Rlay, 0.5*(rcv(i,j,k)+rcv(i+1,j,k)), k\_list, nz, wt, wt\_p)
565           cs%uh\_Rlay(i,j,k\_list)   = cs%uh\_Rlay(i,j,k\_list)   + uh(i,j,k)*wt
566           cs%uh\_Rlay(i,j,k\_list+1) = cs%uh\_Rlay(i,j,k\_list+1) + uh(i,j,k)*wt\_p
567 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
568 \textcolor{keywordflow}{      enddo}
569 
570       \textcolor{keywordflow}{if} (cs%id\_uh\_Rlay > 0) \textcolor{keyword}{call }post\_data(cs%id\_uh\_Rlay, cs%uh\_Rlay, cs%diag)
571 \textcolor{keywordflow}{    endif}
572 
573     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%vh\_Rlay)) \textcolor{keywordflow}{then}
574       k\_list = nz/2
575 \textcolor{comment}{!$OMP parallel do default(none)  shared(Jsq,Jeq,is,ie,nz,nkmb,Rcv,CS,GV,vh) &}
576 \textcolor{comment}{!$OMP                          private(wt,wt\_p) firstprivate(k\_list)}
577       \textcolor{keywordflow}{do} j=jsq,jeq
578         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=is,ie
579           cs%vh\_Rlay(i,j,k) = 0.0
580 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
581         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=is,ie
582           cs%vh\_Rlay(i,j,k) = vh(i,j,k)
583 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
584         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=is,ie
585           \textcolor{keyword}{call }find\_weights(gv%Rlay, 0.5*(rcv(i,j,k)+rcv(i,j+1,k)), k\_list, nz, wt, wt\_p)
586           cs%vh\_Rlay(i,j,k\_list)   = cs%vh\_Rlay(i,j,k\_list)   + vh(i,j,k)*wt
587           cs%vh\_Rlay(i,j,k\_list+1) = cs%vh\_Rlay(i,j,k\_list+1) + vh(i,j,k)*wt\_p
588 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
589 \textcolor{keywordflow}{      enddo}
590 
591       \textcolor{keywordflow}{if} (cs%id\_vh\_Rlay > 0) \textcolor{keyword}{call }post\_data(cs%id\_vh\_Rlay, cs%vh\_Rlay, cs%diag)
592 \textcolor{keywordflow}{    endif}
593 
594     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%uhGM\_Rlay) .and. \textcolor{keyword}{associated}(cdp%uhGM)) \textcolor{keywordflow}{then}
595       k\_list = nz/2
596 \textcolor{comment}{!$OMP parallel do default(none) shared(Isq,Ieq,js,je,nz,nkmb,Rcv,CDP,CS,GV) &}
597 \textcolor{comment}{!$OMP                          private(wt,wt\_p) firstprivate(k\_list)}
598       \textcolor{keywordflow}{do} j=js,je
599         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=isq,ieq
600           cs%uhGM\_Rlay(i,j,k) = 0.0
601 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
602         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=isq,ieq
603           cs%uhGM\_Rlay(i,j,k) = cdp%uhGM(i,j,k)
604 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
605         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=isq,ieq
606           \textcolor{keyword}{call }find\_weights(gv%Rlay, 0.5*(rcv(i,j,k)+rcv(i+1,j,k)), k\_list, nz, wt, wt\_p)
607           cs%uhGM\_Rlay(i,j,k\_list)   = cs%uhGM\_Rlay(i,j,k\_list)   + cdp%uhGM(i,j,k)*wt
608           cs%uhGM\_Rlay(i,j,k\_list+1) = cs%uhGM\_Rlay(i,j,k\_list+1) + cdp%uhGM(i,j,k)*wt\_p
609 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
610 \textcolor{keywordflow}{      enddo}
611 
612       \textcolor{keywordflow}{if} (cs%id\_uhGM\_Rlay > 0) \textcolor{keyword}{call }post\_data(cs%id\_uhGM\_Rlay, cs%uhGM\_Rlay, cs%diag)
613 \textcolor{keywordflow}{    endif}
614 
615     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%vhGM\_Rlay) .and. \textcolor{keyword}{associated}(cdp%vhGM)) \textcolor{keywordflow}{then}
616       k\_list = nz/2
617 \textcolor{comment}{!$OMP parallel do default(none) shared(is,ie,Jsq,Jeq,nz,nkmb,CS,CDp,Rcv,GV) &}
618 \textcolor{comment}{!$OMP                          private(wt,wt\_p) firstprivate(k\_list)}
619       \textcolor{keywordflow}{do} j=jsq,jeq
620         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=is,ie
621           cs%vhGM\_Rlay(i,j,k) = 0.0
622 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
623         \textcolor{keywordflow}{do} k=nkmb+1,nz ; \textcolor{keywordflow}{do} i=is,ie
624           cs%vhGM\_Rlay(i,j,k) = cdp%vhGM(i,j,k)
625 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
626         \textcolor{keywordflow}{do} k=1,nkmb ; \textcolor{keywordflow}{do} i=is,ie
627           \textcolor{keyword}{call }find\_weights(gv%Rlay, 0.5*(rcv(i,j,k)+rcv(i,j+1,k)), k\_list, nz, wt, wt\_p)
628           cs%vhGM\_Rlay(i,j,k\_list)   = cs%vhGM\_Rlay(i,j,k\_list)   + cdp%vhGM(i,j,k)*wt
629           cs%vhGM\_Rlay(i,j,k\_list+1) = cs%vhGM\_Rlay(i,j,k\_list+1) + cdp%vhGM(i,j,k)*wt\_p
630 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
631 \textcolor{keywordflow}{      enddo}
632 
633       \textcolor{keywordflow}{if} (cs%id\_vhGM\_Rlay > 0) \textcolor{keyword}{call }post\_data(cs%id\_vhGM\_Rlay, cs%vhGM\_Rlay, cs%diag)
634 \textcolor{keywordflow}{    endif}
635 \textcolor{keywordflow}{  endif}
636 
637   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%eqn\_of\_state)) \textcolor{keywordflow}{then}
638     eosdom(:) = eos\_domain(g%HI)
639     \textcolor{keywordflow}{if} (cs%id\_rhopot0 > 0) \textcolor{keywordflow}{then}
640       pressure\_1d(:) = 0.
641       \textcolor{comment}{!$OMP parallel do default(shared)}
642       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je
643         \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), pressure\_1d, rcv(:,j,k), &
644                                 tv%eqn\_of\_state, eosdom)
645 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
646       \textcolor{keywordflow}{if} (cs%id\_rhopot0 > 0) \textcolor{keyword}{call }post\_data(cs%id\_rhopot0, rcv, cs%diag)
647 \textcolor{keywordflow}{    endif}
648     \textcolor{keywordflow}{if} (cs%id\_rhopot2 > 0) \textcolor{keywordflow}{then}
649       pressure\_1d(:) = 2.0e7*us%kg\_m3\_to\_R*us%m\_s\_to\_L\_T**2 \textcolor{comment}{! 2000 dbars}
650       \textcolor{comment}{!$OMP parallel do default(shared)}
651       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je
652         \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), pressure\_1d, rcv(:,j,k), &
653                                 tv%eqn\_of\_state, eosdom)
654 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
655       \textcolor{keywordflow}{if} (cs%id\_rhopot2 > 0) \textcolor{keyword}{call }post\_data(cs%id\_rhopot2, rcv, cs%diag)
656 \textcolor{keywordflow}{    endif}
657     \textcolor{keywordflow}{if} (cs%id\_rhoinsitu > 0) \textcolor{keywordflow}{then}
658       \textcolor{comment}{!$OMP parallel do default(shared) private(pressure\_1d)}
659       \textcolor{keywordflow}{do} j=js,je
660         pressure\_1d(:) = 0. \textcolor{comment}{! Start at p=0 Pa at surface}
661         \textcolor{keywordflow}{do} k=1,nz
662           pressure\_1d(:) =  pressure\_1d(:) + 0.5 * h(:,j,k) * (gv%H\_to\_RZ*gv%g\_Earth) \textcolor{comment}{! Pressure in middle
       of layer k}
663           \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), pressure\_1d, rcv(:,j,k), &
664                                 tv%eqn\_of\_state, eosdom)
665           pressure\_1d(:) =  pressure\_1d(:) + 0.5 * h(:,j,k) * (gv%H\_to\_RZ*gv%g\_Earth) \textcolor{comment}{! Pressure at bottom
       of layer k}
666 \textcolor{keywordflow}{        enddo}
667 \textcolor{keywordflow}{      enddo}
668       \textcolor{keywordflow}{if} (cs%id\_rhoinsitu > 0) \textcolor{keyword}{call }post\_data(cs%id\_rhoinsitu, rcv, cs%diag)
669 \textcolor{keywordflow}{    endif}
670 
671     \textcolor{keywordflow}{if} (cs%id\_drho\_dT > 0 .or. cs%id\_drho\_dS > 0) \textcolor{keywordflow}{then}
672       \textcolor{comment}{!$OMP parallel do default(shared) private(pressure\_1d)}
673       \textcolor{keywordflow}{do} j=js,je
674         pressure\_1d(:) = 0. \textcolor{comment}{! Start at p=0 Pa at surface}
675         \textcolor{keywordflow}{do} k=1,nz
676           pressure\_1d(:) =  pressure\_1d(:) + 0.5 * h(:,j,k) * gv%H\_to\_Pa \textcolor{comment}{! Pressure in middle of layer k}
677           \textcolor{comment}{! To avoid storing more arrays, put drho\_dT into Rcv, and drho\_dS into work3d}
678           \textcolor{keyword}{call }calculate\_density\_derivs(tv%T(:,j,k),tv%S(:,j,k),pressure\_1d, &
679                                  rcv(:,j,k),work\_3d(:,j,k),is,ie-is+1, tv%eqn\_of\_state)
680           pressure\_1d(:) =  pressure\_1d(:) + 0.5 * h(:,j,k) * gv%H\_to\_Pa \textcolor{comment}{! Pressure at bottom of layer k}
681 \textcolor{keywordflow}{        enddo}
682 \textcolor{keywordflow}{      enddo}
683       \textcolor{keywordflow}{if} (cs%id\_drho\_dT > 0) \textcolor{keyword}{call }post\_data(cs%id\_drho\_dT, rcv, cs%diag)
684       \textcolor{keywordflow}{if} (cs%id\_drho\_dS > 0) \textcolor{keyword}{call }post\_data(cs%id\_drho\_dS, work\_3d, cs%diag)
685 \textcolor{keywordflow}{    endif}
686 \textcolor{keywordflow}{  endif}
687 
688   \textcolor{keywordflow}{if} ((cs%id\_cg1>0) .or. (cs%id\_Rd1>0) .or. (cs%id\_cfl\_cg1>0) .or. &
689       (cs%id\_cfl\_cg1\_x>0) .or. (cs%id\_cfl\_cg1\_y>0)) \textcolor{keywordflow}{then}
690     \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp)
691     \textcolor{keywordflow}{if} (cs%id\_cg1>0) \textcolor{keyword}{call }post\_data(cs%id\_cg1, cs%cg1, cs%diag)
692     \textcolor{keywordflow}{if} (cs%id\_Rd1>0) \textcolor{keywordflow}{then}
693       \textcolor{comment}{!$OMP parallel do default(shared) private(f2\_h,mag\_beta)}
694       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
695         \textcolor{comment}{! Blend the equatorial deformation radius with the standard one.}
696         f2\_h = absurdly\_small\_freq2 + 0.25 * &
697             ((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
698              (g%CoriolisBu(i-1,j)**2 + g%CoriolisBu(i,j-1)**2))
699         mag\_beta = sqrt(0.5 * ( &
700             (((g%CoriolisBu(i,j)-g%CoriolisBu(i-1,j)) * g%IdxCv(i,j))**2 + &
701              ((g%CoriolisBu(i,j-1)-g%CoriolisBu(i-1,j-1)) * g%IdxCv(i,j-1))**2) + &
702             (((g%CoriolisBu(i,j)-g%CoriolisBu(i,j-1)) * g%IdyCu(i,j))**2 + &
703              ((g%CoriolisBu(i-1,j)-g%CoriolisBu(i-1,j-1)) * g%IdyCu(i-1,j))**2) ))
704         cs%Rd1(i,j) = cs%cg1(i,j) / sqrt(f2\_h + cs%cg1(i,j) * mag\_beta)
705 
706 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
707       \textcolor{keyword}{call }post\_data(cs%id\_Rd1, cs%Rd1, cs%diag)
708 \textcolor{keywordflow}{    endif}
709     \textcolor{keywordflow}{if} (cs%id\_cfl\_cg1>0) \textcolor{keywordflow}{then}
710       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
711         cs%cfl\_cg1(i,j) = (dt*cs%cg1(i,j)) * (g%IdxT(i,j) + g%IdyT(i,j))
712 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
713       \textcolor{keyword}{call }post\_data(cs%id\_cfl\_cg1, cs%cfl\_cg1, cs%diag)
714 \textcolor{keywordflow}{    endif}
715     \textcolor{keywordflow}{if} (cs%id\_cfl\_cg1\_x>0) \textcolor{keywordflow}{then}
716       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
717         cs%cfl\_cg1\_x(i,j) = (dt*cs%cg1(i,j)) * g%IdxT(i,j)
718 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
719       \textcolor{keyword}{call }post\_data(cs%id\_cfl\_cg1\_x, cs%cfl\_cg1\_x, cs%diag)
720 \textcolor{keywordflow}{    endif}
721     \textcolor{keywordflow}{if} (cs%id\_cfl\_cg1\_y>0) \textcolor{keywordflow}{then}
722       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
723         cs%cfl\_cg1\_y(i,j) = (dt*cs%cg1(i,j)) * g%IdyT(i,j)
724 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
725       \textcolor{keyword}{call }post\_data(cs%id\_cfl\_cg1\_y, cs%cfl\_cg1\_y, cs%diag)
726 \textcolor{keywordflow}{    endif}
727 \textcolor{keywordflow}{  endif}
728   \textcolor{keywordflow}{if} ((cs%id\_cg\_ebt>0) .or. (cs%id\_Rd\_ebt>0) .or. (cs%id\_p\_ebt>0)) \textcolor{keywordflow}{then}
729     \textcolor{keywordflow}{if} (cs%id\_p\_ebt>0) \textcolor{keywordflow}{then}
730       \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp, use\_ebt\_mode=.true., &
731                       mono\_n2\_column\_fraction=cs%mono\_N2\_column\_fraction, &
732                       mono\_n2\_depth=cs%mono\_N2\_depth, modal\_structure=cs%p\_ebt)
733       \textcolor{keyword}{call }post\_data(cs%id\_p\_ebt, cs%p\_ebt, cs%diag)
734     \textcolor{keywordflow}{else}
735       \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp, use\_ebt\_mode=.true., &
736                       mono\_n2\_column\_fraction=cs%mono\_N2\_column\_fraction, &
737                       mono\_n2\_depth=cs%mono\_N2\_depth)
738 \textcolor{keywordflow}{    endif}
739     \textcolor{keywordflow}{if} (cs%id\_cg\_ebt>0) \textcolor{keyword}{call }post\_data(cs%id\_cg\_ebt, cs%cg1, cs%diag)
740     \textcolor{keywordflow}{if} (cs%id\_Rd\_ebt>0) \textcolor{keywordflow}{then}
741       \textcolor{comment}{!$OMP parallel do default(shared) private(f2\_h,mag\_beta)}
742       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
743         \textcolor{comment}{! Blend the equatorial deformation radius with the standard one.}
744         f2\_h = absurdly\_small\_freq2 + 0.25 * &
745             ((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
746              (g%CoriolisBu(i-1,j)**2 + g%CoriolisBu(i,j-1)**2))
747         mag\_beta = sqrt(0.5 * ( &
748             (((g%CoriolisBu(i,j)-g%CoriolisBu(i-1,j)) * g%IdxCv(i,j))**2 + &
749              ((g%CoriolisBu(i,j-1)-g%CoriolisBu(i-1,j-1)) * g%IdxCv(i,j-1))**2) + &
750             (((g%CoriolisBu(i,j)-g%CoriolisBu(i,j-1)) * g%IdyCu(i,j))**2 + &
751              ((g%CoriolisBu(i-1,j)-g%CoriolisBu(i-1,j-1)) * g%IdyCu(i-1,j))**2) ))
752         cs%Rd1(i,j) = cs%cg1(i,j) / sqrt(f2\_h + cs%cg1(i,j) * mag\_beta)
753 
754 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
755       \textcolor{keyword}{call }post\_data(cs%id\_Rd\_ebt, cs%Rd1, cs%diag)
756 \textcolor{keywordflow}{    endif}
757 \textcolor{keywordflow}{  endif}
758 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ad8679de99516ebb0ec2a973c441f2fec}\label{namespacemom__diagnostics_ad8679de99516ebb0ec2a973c441f2fec}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!calculate\+\_\+energy\+\_\+diagnostics@{calculate\+\_\+energy\+\_\+diagnostics}}
\index{calculate\+\_\+energy\+\_\+diagnostics@{calculate\+\_\+energy\+\_\+diagnostics}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{calculate\+\_\+energy\+\_\+diagnostics()}{calculate\_energy\_diagnostics()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diagnostics\+::calculate\+\_\+energy\+\_\+diagnostics (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{uh,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{vh,  }\item[{type(accel\+\_\+diag\+\_\+ptrs), intent(in)}]{A\+Dp,  }\item[{type(cont\+\_\+diag\+\_\+ptrs), intent(in)}]{C\+Dp,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), intent(inout)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates terms in the mechanical energy budget. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em uh} & Transport through zonal faces=u$\ast$h$\ast$dy,\\
\hline
\mbox{\tt in}  & {\em vh} & Transport through merid faces=v$\ast$h$\ast$dx,\\
\hline
\mbox{\tt in}  & {\em adp} & Structure pointing to accelerations in momentum equation.\\
\hline
\mbox{\tt in}  & {\em cdp} & Structure pointing to terms in continuity equations.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em cs} & Control structure returned by a previous call to diagnostics\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 950 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
950   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
951   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
952   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
953                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< The zonal velocity [L T-1 ~> m s-1].}
954   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
955                            \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< The meridional velocity [L T-1 ~> m s-1].}
956   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
957                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2].}
958   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
959                            \textcolor{keywordtype}{intent(in)}    :: uh\textcolor{comment}{   !< Transport through zonal faces=u*h*dy,}
960 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
961   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
962                            \textcolor{keywordtype}{intent(in)}    :: vh\textcolor{comment}{   !< Transport through merid faces=v*h*dx,}
963 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
964   \textcolor{keywordtype}{type}(accel\_diag\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: adp\textcolor{comment}{  !< Structure pointing to accelerations in momentum
       equation.}
965   \textcolor{keywordtype}{type}(cont\_diag\_ptrs),    \textcolor{keywordtype}{intent(in)}    :: cdp\textcolor{comment}{  !< Structure pointing to terms in continuity equations.}
966   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
967   \textcolor{keywordtype}{type}(diagnostics\_cs),    \textcolor{keywordtype}{intent(inout)} :: cs\textcolor{comment}{   !< Control structure returned by a previous call to}
968 \textcolor{comment}{                                                 !! diagnostics\_init.}
969 
970 \textcolor{comment}{! This subroutine calculates terms in the mechanical energy budget.}
971 
972   \textcolor{comment}{! Local variables}
973   \textcolor{keywordtype}{real} :: ke\_u(szib\_(g),szj\_(g))
974   \textcolor{keywordtype}{real} :: ke\_v(szi\_(g),szjb\_(g))
975   \textcolor{keywordtype}{real} :: ke\_h(szi\_(g),szj\_(g))
976 
977   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
978   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
979   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
980 
981   \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is-1,ie
982     ke\_u(i,j) = 0.0 ; ke\_v(i,j) = 0.0
983 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
984 
985   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE)) \textcolor{keywordflow}{then}
986     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
987       cs%KE(i,j,k) = ((u(i,j,k) * u(i,j,k) + u(i-1,j,k) * u(i-1,j,k)) &
988           + (v(i,j,k) * v(i,j,k) + v(i,j-1,k) * v(i,j-1,k))) * 0.25
989       \textcolor{comment}{! DELETE THE FOLLOWING...  Make this 0 to test the momentum balance,}
990       \textcolor{comment}{! or a huge number to test the continuity balance.}
991       \textcolor{comment}{! CS%KE(i,j,k) *= 1e20}
992 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
993     \textcolor{keywordflow}{if} (cs%id\_KE > 0) \textcolor{keyword}{call }post\_data(cs%id\_KE, cs%KE, cs%diag)
994 \textcolor{keywordflow}{  endif}
995 
996   \textcolor{keywordflow}{if} (.not.g%symmetric) \textcolor{keywordflow}{then}
997     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dKE\_dt) .OR. \textcolor{keyword}{associated}(cs%PE\_to\_KE) .OR. \textcolor{keyword}{associated}(cs%KE\_CorAdv) .OR. &
998        \textcolor{keyword}{associated}(cs%KE\_adv) .OR. \textcolor{keyword}{associated}(cs%KE\_visc)  .OR. \textcolor{keyword}{associated}(cs%KE\_horvisc).OR. &
999        \textcolor{keyword}{associated}(cs%KE\_dia) ) \textcolor{keywordflow}{then}
1000         \textcolor{keyword}{call }create\_group\_pass(cs%pass\_KE\_uv, ke\_u, ke\_v, g%Domain, to\_north+to\_east)
1001 \textcolor{keywordflow}{    endif}
1002 \textcolor{keywordflow}{  endif}
1003 
1004   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dKE\_dt)) \textcolor{keywordflow}{then}
1005     \textcolor{keywordflow}{do} k=1,nz
1006       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1007         ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * cs%du\_dt(i,j,k)
1008 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1009       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1010         ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * cs%dv\_dt(i,j,k)
1011 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1012       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1013         ke\_h(i,j) = cs%KE(i,j,k) * cs%dh\_dt(i,j,k)
1014 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1015       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1016          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1017       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1018         cs%dKE\_dt(i,j,k) = ke\_h(i,j) + 0.5 * g%IareaT(i,j) &
1019             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1020 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1021 \textcolor{keywordflow}{    enddo}
1022     \textcolor{keywordflow}{if} (cs%id\_dKEdt > 0) \textcolor{keyword}{call }post\_data(cs%id\_dKEdt, cs%dKE\_dt, cs%diag)
1023 \textcolor{keywordflow}{  endif}
1024 
1025   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%PE\_to\_KE)) \textcolor{keywordflow}{then}
1026     \textcolor{keywordflow}{do} k=1,nz
1027       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1028         ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * adp%PFu(i,j,k)
1029 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1030       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1031         ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * adp%PFv(i,j,k)
1032 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1033       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1034          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1035       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1036         cs%PE\_to\_KE(i,j,k) = 0.5 * g%IareaT(i,j) &
1037             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1038 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1039 \textcolor{keywordflow}{    enddo}
1040     \textcolor{keywordflow}{if} (cs%id\_PE\_to\_KE > 0) \textcolor{keyword}{call }post\_data(cs%id\_PE\_to\_KE, cs%PE\_to\_KE, cs%diag)
1041 \textcolor{keywordflow}{  endif}
1042 
1043   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_CorAdv)) \textcolor{keywordflow}{then}
1044     \textcolor{keywordflow}{do} k=1,nz
1045       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1046         ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * adp%CAu(i,j,k)
1047 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1048       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1049         ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * adp%CAv(i,j,k)
1050 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1051       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1052         ke\_h(i,j) = -cs%KE(i,j,k) * g%IareaT(i,j) &
1053             * (uh(i,j,k) - uh(i-1,j,k) + vh(i,j,k) - vh(i,j-1,k))
1054 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1055       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1056          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1057       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1058         cs%KE\_CorAdv(i,j,k) = ke\_h(i,j) + 0.5 * g%IareaT(i,j) &
1059             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1060 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1061 \textcolor{keywordflow}{    enddo}
1062     \textcolor{keywordflow}{if} (cs%id\_KE\_Coradv > 0) \textcolor{keyword}{call }post\_data(cs%id\_KE\_Coradv, cs%KE\_Coradv, cs%diag)
1063 \textcolor{keywordflow}{  endif}
1064 
1065   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_adv)) \textcolor{keywordflow}{then}
1066     \textcolor{comment}{! NOTE: All terms in KE\_adv are multipled by -1, which can easily produce}
1067     \textcolor{comment}{! negative zeros and may signal a reproducibility issue over land.}
1068     \textcolor{comment}{! We resolve this by re-initializing and only evaluating over water points.}
1069     ke\_u(:,:) = 0. ; ke\_v(:,:) = 0.
1070     \textcolor{keywordflow}{do} k=1,nz
1071       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1072         \textcolor{keywordflow}{if} (g%mask2dCu(i,j) /= 0.) &
1073           ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * adp%gradKEu(i,j,k)
1074 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1075       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1076         \textcolor{keywordflow}{if} (g%mask2dCv(i,j) /= 0.) &
1077           ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * adp%gradKEv(i,j,k)
1078 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1079       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1080         ke\_h(i,j) = -cs%KE(i,j,k) * g%IareaT(i,j) &
1081             * (uh(i,j,k) - uh(i-1,j,k) + vh(i,j,k) - vh(i,j-1,k))
1082 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1083       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1084          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1085       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1086         cs%KE\_adv(i,j,k) = ke\_h(i,j) + 0.5 * g%IareaT(i,j) &
1087             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1088 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1089 \textcolor{keywordflow}{    enddo}
1090     \textcolor{keywordflow}{if} (cs%id\_KE\_adv > 0) \textcolor{keyword}{call }post\_data(cs%id\_KE\_adv, cs%KE\_adv, cs%diag)
1091 \textcolor{keywordflow}{  endif}
1092 
1093   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_visc)) \textcolor{keywordflow}{then}
1094     \textcolor{keywordflow}{do} k=1,nz
1095       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1096         ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * adp%du\_dt\_visc(i,j,k)
1097 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1098       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1099         ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * adp%dv\_dt\_visc(i,j,k)
1100 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1101       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1102          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1103       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1104         cs%KE\_visc(i,j,k) = 0.5 * g%IareaT(i,j) &
1105             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1106 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1107 \textcolor{keywordflow}{    enddo}
1108     \textcolor{keywordflow}{if} (cs%id\_KE\_visc > 0) \textcolor{keyword}{call }post\_data(cs%id\_KE\_visc, cs%KE\_visc, cs%diag)
1109 \textcolor{keywordflow}{  endif}
1110 
1111   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_horvisc)) \textcolor{keywordflow}{then}
1112     \textcolor{keywordflow}{do} k=1,nz
1113       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1114         ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * adp%diffu(i,j,k)
1115 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1116       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1117         ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * adp%diffv(i,j,k)
1118 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1119       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1120          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1121       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1122         cs%KE\_horvisc(i,j,k) = 0.5 * g%IareaT(i,j) &
1123             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1124 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1125 \textcolor{keywordflow}{    enddo}
1126     \textcolor{keywordflow}{if} (cs%id\_KE\_horvisc > 0) \textcolor{keyword}{call }post\_data(cs%id\_KE\_horvisc, cs%KE\_horvisc, cs%diag)
1127 \textcolor{keywordflow}{  endif}
1128 
1129   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_dia)) \textcolor{keywordflow}{then}
1130     \textcolor{keywordflow}{do} k=1,nz
1131       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1132         ke\_u(i,j) = uh(i,j,k) * g%dxCu(i,j) * adp%du\_dt\_dia(i,j,k)
1133 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1134       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1135         ke\_v(i,j) = vh(i,j,k) * g%dyCv(i,j) * adp%dv\_dt\_dia(i,j,k)
1136 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1137       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1138         ke\_h(i,j) = cs%KE(i,j,k) &
1139             * (us%T\_to\_s * (cdp%diapyc\_vel(i,j,k) - cdp%diapyc\_vel(i,j,k+1)))
1140 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1141       \textcolor{keywordflow}{if} (.not.g%symmetric) &
1142          \textcolor{keyword}{call }do\_group\_pass(cs%pass\_KE\_uv, g%domain)
1143       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1144         cs%KE\_dia(i,j,k) = ke\_h(i,j) + 0.5 * g%IareaT(i,j) &
1145             * (ke\_u(i,j) + ke\_u(i-1,j) + ke\_v(i,j) + ke\_v(i,j-1))
1146 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1147 \textcolor{keywordflow}{    enddo}
1148     \textcolor{keywordflow}{if} (cs%id\_KE\_dia > 0) \textcolor{keyword}{call }post\_data(cs%id\_KE\_dia, cs%KE\_dia, cs%diag)
1149 \textcolor{keywordflow}{  endif}
1150 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_a3dc7691c006b2abc1c355adc8e4d1a34}\label{namespacemom__diagnostics_a3dc7691c006b2abc1c355adc8e4d1a34}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!calculate\+\_\+vertical\+\_\+integrals@{calculate\+\_\+vertical\+\_\+integrals}}
\index{calculate\+\_\+vertical\+\_\+integrals@{calculate\+\_\+vertical\+\_\+integrals}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{calculate\+\_\+vertical\+\_\+integrals()}{calculate\_vertical\_integrals()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diagnostics\+::calculate\+\_\+vertical\+\_\+integrals (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(\+:,\+:), pointer}]{p\+\_\+surf,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), intent(inout)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates vertical integrals of several tracers, along with the mass-\/weight of these tracers, the total column mass, and the carefully calculated column height. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables.\\
\hline
 & {\em p\+\_\+surf} & A pointer to the surface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. If p\+\_\+surf is not associated, it is the same as setting the surface pressure to 0.\\
\hline
\mbox{\tt in,out}  & {\em cs} & Control structure returned by a previous call to diagnostics\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 833 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
833   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
834   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
835   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
836   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
837                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2].}
838   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various}
839 \textcolor{comment}{                                                 !! thermodynamic variables.}
840   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},    \textcolor{keywordtype}{pointer}       :: p\_surf\textcolor{comment}{ !< A pointer to the surface pressure [R L2 T-2 ~> Pa].}
841 \textcolor{comment}{                                                 !! If p\_surf is not associated, it is the same}
842 \textcolor{comment}{                                                 !! as setting the surface pressure to 0.}
843   \textcolor{keywordtype}{type}(diagnostics\_cs),    \textcolor{keywordtype}{intent(inout)} :: cs\textcolor{comment}{   !< Control structure returned by a}
844 \textcolor{comment}{                                                 !! previous call to diagnostics\_init.}
845 
846   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: &
847     z\_top, &  \textcolor{comment}{! Height of the top of a layer or the ocean [Z ~> m].}
848     z\_bot, &  \textcolor{comment}{! Height of the bottom of a layer (for id\_mass) or the}
849               \textcolor{comment}{! (positive) depth of the ocean (for id\_col\_ht) [Z ~> m].}
850     mass, &   \textcolor{comment}{! integrated mass of the water column [R Z ~> kg m-2].  For}
851               \textcolor{comment}{! non-Boussinesq models this is rho*dz. For Boussinesq}
852               \textcolor{comment}{! models, this is either the integral of in-situ density}
853               \textcolor{comment}{! (rho*dz for col\_mass) or reference density (Rho\_0*dz for mass\_wt).}
854     btm\_pres,&\textcolor{comment}{! The pressure at the ocean bottom, or CMIP variable 'pbo'.}
855               \textcolor{comment}{! This is the column mass multiplied by gravity plus the pressure}
856               \textcolor{comment}{! at the ocean surface [R L2 T-2 ~> Pa].}
857     dpress, & \textcolor{comment}{! Change in hydrostatic pressure across a layer [R L2 T-2 ~> Pa].}
858     tr\_int    \textcolor{comment}{! vertical integral of a tracer times density,}
859               \textcolor{comment}{! (Rho\_0 in a Boussinesq model) [TR kg m-2].}
860   \textcolor{keywordtype}{real}    :: ig\_earth  \textcolor{comment}{! Inverse of gravitational acceleration [T2 Z L-2 ~> s2 m-1].}
861 
862   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
863   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
864 
865   \textcolor{keywordflow}{if} (cs%id\_mass\_wt > 0) \textcolor{keywordflow}{then}
866     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
867     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
868       mass(i,j) = mass(i,j) + gv%H\_to\_RZ*h(i,j,k)
869 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
870     \textcolor{keyword}{call }post\_data(cs%id\_mass\_wt, mass, cs%diag)
871 \textcolor{keywordflow}{  endif}
872 
873   \textcolor{keywordflow}{if} (cs%id\_temp\_int > 0) \textcolor{keywordflow}{then}
874     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; tr\_int(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
875     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
876       tr\_int(i,j) = tr\_int(i,j) + (gv%H\_to\_RZ*h(i,j,k))*tv%T(i,j,k)
877 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
878     \textcolor{keyword}{call }post\_data(cs%id\_temp\_int, tr\_int, cs%diag)
879 \textcolor{keywordflow}{  endif}
880 
881   \textcolor{keywordflow}{if} (cs%id\_salt\_int > 0) \textcolor{keywordflow}{then}
882     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; tr\_int(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
883     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
884       tr\_int(i,j) = tr\_int(i,j) + (gv%H\_to\_RZ*h(i,j,k))*tv%S(i,j,k)
885 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
886     \textcolor{keyword}{call }post\_data(cs%id\_salt\_int, tr\_int, cs%diag)
887 \textcolor{keywordflow}{  endif}
888 
889   \textcolor{keywordflow}{if} (cs%id\_col\_ht > 0) \textcolor{keywordflow}{then}
890     \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, z\_top)
891     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
892       z\_bot(i,j) = z\_top(i,j) + g%bathyT(i,j)
893 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
894     \textcolor{keyword}{call }post\_data(cs%id\_col\_ht, z\_bot, cs%diag)
895 \textcolor{keywordflow}{  endif}
896 
897   \textcolor{comment}{! NOTE: int\_density\_z expects z\_top and z\_btm values from [ij]sq to [ij]eq+1}
898   \textcolor{keywordflow}{if} (cs%id\_col\_mass > 0 .or. cs%id\_pbo > 0) \textcolor{keywordflow}{then}
899     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
900     \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then}
901       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%eqn\_of\_state)) \textcolor{keywordflow}{then}
902         ig\_earth = 1.0 / gv%g\_Earth
903 \textcolor{comment}{!       do j=js,je ; do i=is,ie ; z\_bot(i,j) = -P\_SURF(i,j)/GV%H\_to\_Pa ; enddo ; enddo}
904         \textcolor{keywordflow}{do} j=g%jscB,g%jecB+1 ; \textcolor{keywordflow}{do} i=g%iscB,g%iecB+1
905           z\_bot(i,j) = 0.0
906 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
907         \textcolor{keywordflow}{do} k=1,nz
908           \textcolor{keywordflow}{do} j=g%jscB,g%jecB+1 ; \textcolor{keywordflow}{do} i=g%iscB,g%iecB+1
909             z\_top(i,j) = z\_bot(i,j)
910             z\_bot(i,j) = z\_top(i,j) - gv%H\_to\_Z*h(i,j,k)
911 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
912           \textcolor{keyword}{call }int\_density\_dz(tv%T(:,:,k), tv%S(:,:,k), z\_top, z\_bot, 0.0, gv%Rho0, gv%g\_Earth, &
913                               g%HI, tv%eqn\_of\_state, us, dpress)
914           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
915             mass(i,j) = mass(i,j) + dpress(i,j) * ig\_earth
916 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
917 \textcolor{keywordflow}{        enddo}
918       \textcolor{keywordflow}{else}
919         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
920           mass(i,j) = mass(i,j) + (gv%H\_to\_Z*gv%Rlay(k))*h(i,j,k)
921 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
922 \textcolor{keywordflow}{      endif}
923     \textcolor{keywordflow}{else}
924       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
925         mass(i,j) = mass(i,j) + gv%H\_to\_RZ*h(i,j,k)
926 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
927 \textcolor{keywordflow}{    endif}
928     \textcolor{keywordflow}{if} (cs%id\_col\_mass > 0) \textcolor{keywordflow}{then}
929       \textcolor{keyword}{call }post\_data(cs%id\_col\_mass, mass, cs%diag)
930 \textcolor{keywordflow}{    endif}
931     \textcolor{keywordflow}{if} (cs%id\_pbo > 0) \textcolor{keywordflow}{then}
932       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; btm\_pres(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
933       \textcolor{comment}{! 'pbo' is defined as the sea water pressure at the sea floor}
934       \textcolor{comment}{!     pbo = (mass * g) + p\_surf}
935       \textcolor{comment}{! where p\_surf is the sea water pressure at sea water surface.}
936       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
937         btm\_pres(i,j) = gv%g\_Earth * mass(i,j)
938         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_surf)) \textcolor{keywordflow}{then}
939           btm\_pres(i,j) = btm\_pres(i,j) + p\_surf(i,j)
940 \textcolor{keywordflow}{        endif}
941 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
942       \textcolor{keyword}{call }post\_data(cs%id\_pbo, btm\_pres, cs%diag)
943 \textcolor{keywordflow}{    endif}
944 \textcolor{keywordflow}{  endif}
945 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ab43b50cd32dfe693c6ce575c279988fb}\label{namespacemom__diagnostics_ab43b50cd32dfe693c6ce575c279988fb}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!find\+\_\+weights@{find\+\_\+weights}}
\index{find\+\_\+weights@{find\+\_\+weights}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{find\+\_\+weights()}{find\_weights()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diagnostics\+::find\+\_\+weights (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{Rlist,  }\item[{real, intent(in)}]{R\+\_\+in,  }\item[{integer, intent(inout)}]{k,  }\item[{integer, intent(in)}]{nz,  }\item[{real, intent(out)}]{wt,  }\item[{real, intent(out)}]{wt\+\_\+p }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine finds the location of R\+\_\+in in an increasing ordered list, Rlist, returning as k the element such that Rlist(k) $<$= R\+\_\+in $<$ Rlist(k+1), and where wt and wt\+\_\+p are the linear weights that should be assigned to elements k and k+1. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em rlist} & The list of target densities \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
\mbox{\tt in}  & {\em r\+\_\+in} & The density being inserted into Rlist \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em k} & The value of k such that Rlist(k) $<$= R\+\_\+in $<$ Rlist(k+1) The input value is a first guess\\
\hline
\mbox{\tt in}  & {\em nz} & The number of layers in Rlist\\
\hline
\mbox{\tt out}  & {\em wt} & The weight of layer k for interpolation, nondim\\
\hline
\mbox{\tt out}  & {\em wt\+\_\+p} & The weight of layer k+1 for interpolation, nondim \\
\hline
\end{DoxyParams}


Definition at line 766 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
766   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, &
767             \textcolor{keywordtype}{intent(in)}    :: rlist\textcolor{comment}{ !< The list of target densities [R ~> kg m-3]}
768   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{intent(in)}    :: r\_in\textcolor{comment}{ !< The density being inserted into Rlist [R ~> kg m-3]}
769   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(inout)} :: k\textcolor{comment}{    !< The value of k such that Rlist(k) <= R\_in < Rlist(k+1)}
770 \textcolor{comment}{                                  !! The input value is a first guess}
771   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{   !< The number of layers in Rlist}
772   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{intent(out)}   :: wt\textcolor{comment}{   !< The weight of layer k for interpolation, nondim}
773   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{intent(out)}   :: wt\_p\textcolor{comment}{ !< The weight of layer k+1 for interpolation, nondim}
774 
775   \textcolor{comment}{! This subroutine finds location of R\_in in an increasing ordered}
776   \textcolor{comment}{! list, Rlist, returning as k the element such that}
777   \textcolor{comment}{!  Rlist(k) <= R\_in < Rlist(k+1), and where wt and wt\_p are the linear}
778   \textcolor{comment}{! weights that should be assigned to elements k and k+1.}
779 
780   \textcolor{keywordtype}{integer} :: k\_upper, k\_lower, k\_new, inc
781 
782   \textcolor{comment}{! First, bracket the desired point.}
783   \textcolor{keywordflow}{if} ((k < 1) .or. (k > nz)) k = nz/2
784 
785   k\_upper = k ; k\_lower = k ; inc = 1
786   \textcolor{keywordflow}{if} (r\_in < rlist(k)) \textcolor{keywordflow}{then}
787     \textcolor{keywordflow}{do}
788       k\_lower = max(k\_lower-inc, 1)
789       \textcolor{keywordflow}{if} ((k\_lower == 1) .or. (r\_in >= rlist(k\_lower))) \textcolor{keywordflow}{exit}
790       k\_upper = k\_lower
791       inc = inc*2
792 \textcolor{keywordflow}{    enddo}
793   \textcolor{keywordflow}{else}
794     \textcolor{keywordflow}{do}
795       k\_upper = min(k\_upper+inc, nz)
796       \textcolor{keywordflow}{if} ((k\_upper == nz) .or. (r\_in < rlist(k\_upper))) \textcolor{keywordflow}{exit}
797       k\_lower = k\_upper
798       inc = inc*2
799 \textcolor{keywordflow}{    enddo}
800 \textcolor{keywordflow}{  endif}
801 
802   \textcolor{keywordflow}{if} ((k\_lower == 1) .and. (r\_in <= rlist(k\_lower))) \textcolor{keywordflow}{then}
803     k = 1 ; wt = 1.0 ; wt\_p = 0.0
804   \textcolor{keywordflow}{elseif} ((k\_upper == nz) .and. (r\_in >= rlist(k\_upper))) \textcolor{keywordflow}{then}
805     k = nz-1 ; wt = 0.0 ; wt\_p = 1.0
806   \textcolor{keywordflow}{else}
807     \textcolor{keywordflow}{do}
808       \textcolor{keywordflow}{if} (k\_upper <= k\_lower+1) \textcolor{keywordflow}{exit}
809       k\_new = (k\_upper + k\_lower) / 2
810       \textcolor{keywordflow}{if} (r\_in < rlist(k\_new)) \textcolor{keywordflow}{then}
811         k\_upper = k\_new
812       \textcolor{keywordflow}{else}
813         k\_lower = k\_new
814 \textcolor{keywordflow}{      endif}
815 \textcolor{keywordflow}{    enddo}
816 
817 \textcolor{comment}{!   Uncomment this as a code check}
818 \textcolor{comment}{!    if ((R\_in < Rlist(k\_lower)) .or. (R\_in >= Rlist(k\_upper)) .or. (k\_upper-k\_lower /= 1)) &}
819 \textcolor{comment}{!      write (*,*) "Error: ",R\_in," is not between R(",k\_lower,") = ", &}
820 \textcolor{comment}{!        Rlist(k\_lower)," and R(",k\_upper,") = ",Rlist(k\_upper),"."}
821     k = k\_lower
822     wt = (rlist(k\_upper) - r\_in) / (rlist(k\_upper) - rlist(k\_lower))
823     wt\_p = 1.0 - wt
824 
825 \textcolor{keywordflow}{  endif}
826 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ae7ada8fb77b23b1b4cfb10d8c8b0ba50}\label{namespacemom__diagnostics_ae7ada8fb77b23b1b4cfb10d8c8b0ba50}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!mom\+\_\+diagnostics\+\_\+end@{mom\+\_\+diagnostics\+\_\+end}}
\index{mom\+\_\+diagnostics\+\_\+end@{mom\+\_\+diagnostics\+\_\+end}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{mom\+\_\+diagnostics\+\_\+end()}{mom\_diagnostics\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::mom\+\_\+diagnostics\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), pointer}]{CS,  }\item[{type(accel\+\_\+diag\+\_\+ptrs), intent(inout)}]{A\+Dp }\end{DoxyParamCaption})}



Deallocate memory associated with the diagnostics module. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure returned by a previous call to diagnostics\+\_\+init.\\
\hline
\mbox{\tt in,out}  & {\em adp} & structure with pointers to accelerations in momentum equation. \\
\hline
\end{DoxyParams}


Definition at line 2237 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
2237   \textcolor{keywordtype}{type}(diagnostics\_cs),   \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{  !< Control structure returned by a}
2238 \textcolor{comment}{                                               !! previous call to diagnostics\_init.}
2239   \textcolor{keywordtype}{type}(accel\_diag\_ptrs),  \textcolor{keywordtype}{intent(inout)} :: adp\textcolor{comment}{ !< structure with pointers to}
2240 \textcolor{comment}{                                               !! accelerations in momentum equation.}
2241   \textcolor{keywordtype}{integer} :: m
2242 
2243   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%e))          \textcolor{keyword}{deallocate}(cs%e)
2244   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%e\_D))        \textcolor{keyword}{deallocate}(cs%e\_D)
2245   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE))         \textcolor{keyword}{deallocate}(cs%KE)
2246   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dKE\_dt))     \textcolor{keyword}{deallocate}(cs%dKE\_dt)
2247   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%PE\_to\_KE))   \textcolor{keyword}{deallocate}(cs%PE\_to\_KE)
2248   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_Coradv))  \textcolor{keyword}{deallocate}(cs%KE\_Coradv)
2249   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_adv))     \textcolor{keyword}{deallocate}(cs%KE\_adv)
2250   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_visc))    \textcolor{keyword}{deallocate}(cs%KE\_visc)
2251   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_horvisc)) \textcolor{keyword}{deallocate}(cs%KE\_horvisc)
2252   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_dia))     \textcolor{keyword}{deallocate}(cs%KE\_dia)
2253   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dv\_dt))      \textcolor{keyword}{deallocate}(cs%dv\_dt)
2254   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dh\_dt))      \textcolor{keyword}{deallocate}(cs%dh\_dt)
2255   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%du\_dt))      \textcolor{keyword}{deallocate}(cs%du\_dt)
2256   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%h\_Rlay))     \textcolor{keyword}{deallocate}(cs%h\_Rlay)
2257   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%uh\_Rlay))    \textcolor{keyword}{deallocate}(cs%uh\_Rlay)
2258   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%vh\_Rlay))    \textcolor{keyword}{deallocate}(cs%vh\_Rlay)
2259   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%uhGM\_Rlay))  \textcolor{keyword}{deallocate}(cs%uhGM\_Rlay)
2260   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%vhGM\_Rlay))  \textcolor{keyword}{deallocate}(cs%vhGM\_Rlay)
2261 
2262   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%gradKEu))    \textcolor{keyword}{deallocate}(adp%gradKEu)
2263   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%gradKEu))    \textcolor{keyword}{deallocate}(adp%gradKEu)
2264   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%du\_dt\_visc)) \textcolor{keyword}{deallocate}(adp%du\_dt\_visc)
2265   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%dv\_dt\_visc)) \textcolor{keyword}{deallocate}(adp%dv\_dt\_visc)
2266   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%du\_dt\_dia))  \textcolor{keyword}{deallocate}(adp%du\_dt\_dia)
2267   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%dv\_dt\_dia))  \textcolor{keyword}{deallocate}(adp%dv\_dt\_dia)
2268   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%du\_other))   \textcolor{keyword}{deallocate}(adp%du\_other)
2269   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%dv\_other))   \textcolor{keyword}{deallocate}(adp%dv\_other)
2270 
2271   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%diag\_hfrac\_u)) \textcolor{keyword}{deallocate}(adp%diag\_hfrac\_u)
2272   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(adp%diag\_hfrac\_v)) \textcolor{keyword}{deallocate}(adp%diag\_hfrac\_v)
2273 
2274   \textcolor{keywordflow}{do} m=1,cs%num\_time\_deriv ; \textcolor{keyword}{deallocate}(cs%prev\_val(m)%p) ;\textcolor{keywordflow}{ enddo}
2275 
2276   \textcolor{keyword}{deallocate}(cs)
2277 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ae8281123dfff124b0a362ea9fd1e0078}\label{namespacemom__diagnostics_ae8281123dfff124b0a362ea9fd1e0078}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!mom\+\_\+diagnostics\+\_\+init@{mom\+\_\+diagnostics\+\_\+init}}
\index{mom\+\_\+diagnostics\+\_\+init@{mom\+\_\+diagnostics\+\_\+init}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{mom\+\_\+diagnostics\+\_\+init()}{mom\_diagnostics\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::mom\+\_\+diagnostics\+\_\+init (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+internal\+\_\+state), intent(in)}]{M\+IS,  }\item[{type(accel\+\_\+diag\+\_\+ptrs), intent(inout)}]{A\+Dp,  }\item[{type(cont\+\_\+diag\+\_\+ptrs), intent(inout)}]{C\+Dp,  }\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), pointer}]{CS,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv }\end{DoxyParamCaption})}



This subroutine registers various diagnostics and allocates space for fields that other diagnostis depend upon. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em mis} & For \char`\"{}\+M\+O\+M Internal State\char`\"{} a set of pointers to the fields and accelerations that make up the ocean\textquotesingle{}s internal physical state.\\
\hline
\mbox{\tt in,out}  & {\em adp} & Structure with pointers to momentum equation terms.\\
\hline
\mbox{\tt in,out}  & {\em cdp} & Structure with pointers to continuity equation terms.\\
\hline
\mbox{\tt in}  & {\em time} & Current model time.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters.\\
\hline
\mbox{\tt in,out}  & {\em diag} & Structure to regulate diagnostic output.\\
\hline
 & {\em cs} & Pointer set to point to control structure for this module.\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables. \\
\hline
\end{DoxyParams}


Definition at line 1493 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1493   \textcolor{keywordtype}{type}(ocean\_internal\_state), \textcolor{keywordtype}{intent(in)}    :: mis\textcolor{comment}{  !< For "MOM Internal State" a set of pointers to}
1494 \textcolor{comment}{                                                    !! the fields and accelerations that make up the}
1495 \textcolor{comment}{                                                    !! ocean's internal physical state.}
1496   \textcolor{keywordtype}{type}(accel\_diag\_ptrs),      \textcolor{keywordtype}{intent(inout)} :: adp\textcolor{comment}{  !< Structure with pointers to momentum equation}
1497 \textcolor{comment}{                                                    !! terms.}
1498   \textcolor{keywordtype}{type}(cont\_diag\_ptrs),       \textcolor{keywordtype}{intent(inout)} :: cdp\textcolor{comment}{  !< Structure with pointers to continuity}
1499 \textcolor{comment}{                                                    !! equation terms.}
1500   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< Current model time.}
1501   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< The ocean's grid structure.}
1502   \textcolor{keywordtype}{type}(verticalgrid\_type),    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
1503   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
1504   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time}
1505 \textcolor{comment}{                                                    !! parameters.}
1506   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},    \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< Structure to regulate diagnostic output.}
1507   \textcolor{keywordtype}{type}(diagnostics\_cs),       \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< Pointer set to point to control structure}
1508 \textcolor{comment}{                                                    !! for this module.}
1509   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),      \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various}
1510 \textcolor{comment}{                                                    !! thermodynamic variables.}
1511 
1512   \textcolor{comment}{! Local variables}
1513   \textcolor{keywordtype}{real} :: omega, f2\_min, convert\_h
1514   \textcolor{comment}{! This include declares and sets the variable "version".}
1515 \textcolor{preprocessor}{# include "version\_variable.h"}
1516 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_diagnostics"} \textcolor{comment}{! This module's name.}
1517   \textcolor{keywordtype}{character(len=48)} :: thickness\_units, flux\_units
1518   \textcolor{keywordtype}{real} :: wave\_speed\_min      \textcolor{comment}{! A floor in the first mode speed below which 0 is returned [L T-1 ~> m s-1]}
1519   \textcolor{keywordtype}{real} :: wave\_speed\_tol      \textcolor{comment}{! The fractional tolerance for finding the wave speeds [nondim]}
1520   \textcolor{keywordtype}{logical} :: better\_speed\_est \textcolor{comment}{! If true, use a more robust estimate of the first}
1521                               \textcolor{comment}{! mode wave speed as the starting point for iterations.}
1522   \textcolor{keywordtype}{logical} :: use\_temperature, adiabatic
1523   \textcolor{keywordtype}{logical} :: default\_2018\_answers, remap\_answers\_2018
1524   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, isdb, iedb, jsdb, jedb, nz, nkml, nkbl
1525   \textcolor{keywordtype}{integer} :: is, ie, js, je, isq, ieq, jsq, jeq, i, j
1526 
1527   is   = g%isc  ; ie   = g%iec  ; js   = g%jsc  ; je   = g%jec
1528   isq  = g%IscB ; ieq  = g%IecB ; jsq  = g%JscB ; jeq  = g%JecB
1529   isd  = g%isd  ; ied  = g%ied  ; jsd  = g%jsd  ; jed  = g%jed ; nz = g%ke
1530   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
1531 
1532   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
1533     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_diagnostics\_init called with an associated "}// &
1534                             \textcolor{stringliteral}{"control structure."})
1535     \textcolor{keywordflow}{return}
1536 \textcolor{keywordflow}{  endif}
1537   \textcolor{keyword}{allocate}(cs)
1538 
1539   cs%diag => diag
1540   use\_temperature = \textcolor{keyword}{associated}(tv%T)
1541   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADIABATIC"}, adiabatic, default=.false., &
1542                  do\_not\_log=.true.)
1543 
1544   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
1545   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
1546   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DIAG\_EBT\_MONO\_N2\_COLUMN\_FRACTION"}, cs%mono\_N2\_column\_fraction, &
1547                  \textcolor{stringliteral}{"The lower fraction of water column over which N2 is limited as monotonic "}// &
1548                  \textcolor{stringliteral}{"for the purposes of calculating the equivalent barotropic wave speed."}, &
1549                  units=\textcolor{stringliteral}{'nondim'}, default=0.)
1550   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DIAG\_EBT\_MONO\_N2\_DEPTH"}, cs%mono\_N2\_depth, &
1551                  \textcolor{stringliteral}{"The depth below which N2 is limited as monotonic for the "}// &
1552                  \textcolor{stringliteral}{"purposes of calculating the equivalent barotropic wave speed."}, &
1553                  units=\textcolor{stringliteral}{'m'}, scale=us%m\_to\_Z, default=-1.)
1554   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_WAVE\_SPEED\_TOL"}, wave\_speed\_tol, &
1555                  \textcolor{stringliteral}{"The fractional tolerance for finding the wave speeds."}, &
1556                  units=\textcolor{stringliteral}{"nondim"}, default=0.001)
1557   \textcolor{comment}{!### Set defaults so that wave\_speed\_min*wave\_speed\_tol >= 1e-9 m s-1}
1558   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_WAVE\_SPEED\_MIN"}, wave\_speed\_min, &
1559                  \textcolor{stringliteral}{"A floor in the first mode speed below which 0 used instead."}, &
1560                  units=\textcolor{stringliteral}{"m s-1"}, default=0.0, scale=us%m\_s\_to\_L\_T)
1561   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_WAVE\_SPEED\_BETTER\_EST"}, better\_speed\_est, &
1562                  \textcolor{stringliteral}{"If true, use a more robust estimate of the first mode wave speed as the "}//&
1563                  \textcolor{stringliteral}{"starting point for iterations."}, default=.false.) \textcolor{comment}{!### Change the default.}
1564   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
1565                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
1566                  default=.false.)
1567   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, remap\_answers\_2018, &
1568                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
1569                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
1570                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
1571 
1572   \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then}
1573     thickness\_units = \textcolor{stringliteral}{"m"} ; flux\_units = \textcolor{stringliteral}{"m3 s-1"} ; convert\_h = gv%H\_to\_m
1574   \textcolor{keywordflow}{else}
1575     thickness\_units = \textcolor{stringliteral}{"kg m-2"} ; flux\_units = \textcolor{stringliteral}{"kg s-1"} ; convert\_h = gv%H\_to\_kg\_m2
1576 \textcolor{keywordflow}{  endif}
1577 
1578   cs%id\_masscello = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'masscello'}, diag%axesTL,&
1579       time, \textcolor{stringliteral}{'Mass per unit area of liquid ocean grid cell'}, \textcolor{stringliteral}{'kg m-2'},           &
1580       standard\_name=\textcolor{stringliteral}{'sea\_water\_mass\_per\_unit\_area'}, v\_extensive=.true.)
1581 
1582   cs%id\_masso = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'masso'}, time,  &
1583       diag, \textcolor{stringliteral}{'Mass of liquid ocean'}, \textcolor{stringliteral}{'kg'}, standard\_name=\textcolor{stringliteral}{'sea\_water\_mass'})
1584 
1585   cs%id\_thkcello = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'thkcello'}, diag%axesTL, time, &
1586       long\_name = \textcolor{stringliteral}{'Cell Thickness'}, standard\_name=\textcolor{stringliteral}{'cell\_thickness'}, &
1587       units=\textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m, v\_extensive=.true.)
1588   cs%id\_h\_pre\_sync = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h\_pre\_sync'}, diag%axesTL, time, &
1589       long\_name = \textcolor{stringliteral}{'Cell thickness from the previous timestep'}, &
1590       units=\textcolor{stringliteral}{'m'}, conversion=gv%H\_to\_m, v\_extensive=.true.)
1591 
1592   \textcolor{comment}{! Note that CS%id\_volcello would normally be registered here but because it is a "cell measure" and}
1593   \textcolor{comment}{! must be registered first. We earlier stored the handle of volcello but need it here for posting}
1594   \textcolor{comment}{! by this module.}
1595   cs%id\_volcello = diag\_get\_volume\_cell\_measure\_dm\_id(diag)
1596 
1597   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
1598     \textcolor{keywordflow}{if} (tv%T\_is\_conT) \textcolor{keywordflow}{then}
1599       cs%id\_Tpot = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'temp'}, diag%axesTL, &
1600           time, \textcolor{stringliteral}{'Potential Temperature'}, \textcolor{stringliteral}{'degC'})
1601 \textcolor{keywordflow}{    endif}
1602     \textcolor{keywordflow}{if} (tv%S\_is\_absS) \textcolor{keywordflow}{then}
1603       cs%id\_Sprac = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'salt'}, diag%axesTL, &
1604           time, \textcolor{stringliteral}{'Salinity'}, \textcolor{stringliteral}{'psu'})
1605 \textcolor{keywordflow}{    endif}
1606 
1607     cs%id\_tob = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'tob'}, diag%axesT1, time, &
1608         long\_name=\textcolor{stringliteral}{'Sea Water Potential Temperature at Sea Floor'}, &
1609         standard\_name=\textcolor{stringliteral}{'sea\_water\_potential\_temperature\_at\_sea\_floor'}, units=\textcolor{stringliteral}{'degC'})
1610     cs%id\_sob = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'sob'},diag%axesT1, time, &
1611         long\_name=\textcolor{stringliteral}{'Sea Water Salinity at Sea Floor'}, &
1612         standard\_name=\textcolor{stringliteral}{'sea\_water\_salinity\_at\_sea\_floor'}, units=\textcolor{stringliteral}{'psu'})
1613 
1614     cs%id\_temp\_layer\_ave = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'temp\_layer\_ave'}, &
1615         diag%axesZL, time, \textcolor{stringliteral}{'Layer Average Ocean Temperature'}, \textcolor{stringliteral}{'degC'})
1616     cs%id\_salt\_layer\_ave = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'salt\_layer\_ave'}, &
1617         diag%axesZL, time, \textcolor{stringliteral}{'Layer Average Ocean Salinity'}, \textcolor{stringliteral}{'psu'})
1618 
1619     cs%id\_thetaoga = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'thetaoga'}, &
1620         time, diag, \textcolor{stringliteral}{'Global Mean Ocean Potential Temperature'}, \textcolor{stringliteral}{'degC'},&
1621         standard\_name=\textcolor{stringliteral}{'sea\_water\_potential\_temperature'})
1622     cs%id\_soga = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'soga'}, &
1623         time, diag, \textcolor{stringliteral}{'Global Mean Ocean Salinity'}, \textcolor{stringliteral}{'psu'}, &
1624         standard\_name=\textcolor{stringliteral}{'sea\_water\_salinity'})
1625 
1626     cs%id\_tosga = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'sst\_global'}, time, diag,&
1627         long\_name=\textcolor{stringliteral}{'Global Area Average Sea Surface Temperature'},                &
1628         units=\textcolor{stringliteral}{'degC'}, standard\_name=\textcolor{stringliteral}{'sea\_surface\_temperature'},                  &
1629         cmor\_field\_name=\textcolor{stringliteral}{'tosga'}, cmor\_standard\_name=\textcolor{stringliteral}{'sea\_surface\_temperature'},  &
1630         cmor\_long\_name=\textcolor{stringliteral}{'Sea Surface Temperature'})
1631     cs%id\_sosga = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'sss\_global'}, time, diag,&
1632         long\_name=\textcolor{stringliteral}{'Global Area Average Sea Surface Salinity'},                   &
1633         units=\textcolor{stringliteral}{'psu'}, standard\_name=\textcolor{stringliteral}{'sea\_surface\_salinity'},                      &
1634         cmor\_field\_name=\textcolor{stringliteral}{'sosga'}, cmor\_standard\_name=\textcolor{stringliteral}{'sea\_surface\_salinity'},     &
1635         cmor\_long\_name=\textcolor{stringliteral}{'Sea Surface Salinity'})
1636 \textcolor{keywordflow}{  endif}
1637 
1638   cs%id\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'u'}, diag%axesCuL, time,              &
1639       \textcolor{stringliteral}{'Zonal velocity'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s, cmor\_field\_name=\textcolor{stringliteral}{'uo'}, &
1640       cmor\_standard\_name=\textcolor{stringliteral}{'sea\_water\_x\_velocity'}, cmor\_long\_name=\textcolor{stringliteral}{'Sea Water X Velocity'})
1641   cs%id\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'v'}, diag%axesCvL, time,                  &
1642       \textcolor{stringliteral}{'Meridional velocity'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s, cmor\_field\_name=\textcolor{stringliteral}{'vo'}, &
1643       cmor\_standard\_name=\textcolor{stringliteral}{'sea\_water\_y\_velocity'}, cmor\_long\_name=\textcolor{stringliteral}{'Sea Water Y Velocity'})
1644   cs%id\_h = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h'}, diag%axesTL, time, &
1645       \textcolor{stringliteral}{'Layer Thickness'}, thickness\_units, v\_extensive=.true., conversion=convert\_h)
1646 
1647   cs%id\_e = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'e'}, diag%axesTi, time, &
1648       \textcolor{stringliteral}{'Interface Height Relative to Mean Sea Level'}, \textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m)
1649   \textcolor{keywordflow}{if} (cs%id\_e>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%e,isd,ied,jsd,jed,nz+1)
1650 
1651   cs%id\_e\_D = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'e\_D'}, diag%axesTi, time, &
1652       \textcolor{stringliteral}{'Interface Height above the Seafloor'}, \textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m)
1653   \textcolor{keywordflow}{if} (cs%id\_e\_D>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%e\_D,isd,ied,jsd,jed,nz+1)
1654 
1655   cs%id\_Rml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Rml'}, diag%axesTL, time, &
1656       \textcolor{stringliteral}{'Mixed Layer Coordinate Potential Density'}, \textcolor{stringliteral}{'kg m-3'}, conversion=us%R\_to\_kg\_m3)
1657 
1658   cs%id\_Rcv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Rho\_cv'}, diag%axesTL, time, &
1659       \textcolor{stringliteral}{'Coordinate Potential Density'}, \textcolor{stringliteral}{'kg m-3'}, conversion=us%R\_to\_kg\_m3)
1660 
1661   cs%id\_rhopot0 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'rhopot0'}, diag%axesTL, time, &
1662       \textcolor{stringliteral}{'Potential density referenced to surface'}, \textcolor{stringliteral}{'kg m-3'}, conversion=us%R\_to\_kg\_m3)
1663   cs%id\_rhopot2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'rhopot2'}, diag%axesTL, time, &
1664       \textcolor{stringliteral}{'Potential density referenced to 2000 dbar'}, \textcolor{stringliteral}{'kg m-3'}, conversion=us%R\_to\_kg\_m3)
1665   cs%id\_rhoinsitu = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'rhoinsitu'}, diag%axesTL, time, &
1666       \textcolor{stringliteral}{'In situ density'}, \textcolor{stringliteral}{'kg m-3'}, conversion=us%R\_to\_kg\_m3)
1667   cs%id\_drho\_dT = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'drho\_dT'}, diag%axesTL, time, &
1668       \textcolor{stringliteral}{'Partial derivative of rhoinsitu with respect to temperature (alpha)'}, \textcolor{stringliteral}{'kg m-3 degC-1'})
1669   cs%id\_drho\_dS = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'drho\_dS'}, diag%axesTL, time, &
1670       \textcolor{stringliteral}{'Partial derivative of rhoinsitu with respect to salinity (beta)'}, \textcolor{stringliteral}{'kg^2 g-1 m-3'})
1671 
1672   cs%id\_du\_dt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dudt'}, diag%axesCuL, time, &
1673       \textcolor{stringliteral}{'Zonal Acceleration'}, \textcolor{stringliteral}{'m s-2'}, conversion=us%L\_T2\_to\_m\_s2)
1674   \textcolor{keywordflow}{if} ((cs%id\_du\_dt>0) .and. .not.\textcolor{keyword}{associated}(cs%du\_dt)) \textcolor{keywordflow}{then}
1675     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%du\_dt,isdb,iedb,jsd,jed,nz)
1676     \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%u), mis%u, cs%du\_dt, cs)
1677 \textcolor{keywordflow}{  endif}
1678 
1679   cs%id\_dv\_dt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dvdt'}, diag%axesCvL, time, &
1680       \textcolor{stringliteral}{'Meridional Acceleration'}, \textcolor{stringliteral}{'m s-2'}, conversion=us%L\_T2\_to\_m\_s2)
1681   \textcolor{keywordflow}{if} ((cs%id\_dv\_dt>0) .and. .not.\textcolor{keyword}{associated}(cs%dv\_dt)) \textcolor{keywordflow}{then}
1682     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%dv\_dt,isd,ied,jsdb,jedb,nz)
1683     \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%v), mis%v, cs%dv\_dt, cs)
1684 \textcolor{keywordflow}{  endif}
1685 
1686   cs%id\_dh\_dt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dhdt'}, diag%axesTL, time, &
1687       \textcolor{stringliteral}{'Thickness tendency'}, trim(thickness\_units)//\textcolor{stringliteral}{" s-1"}, conversion=convert\_h*us%s\_to\_T, v\_extensive=.
      true.)
1688   \textcolor{keywordflow}{if} ((cs%id\_dh\_dt>0) .and. .not.\textcolor{keyword}{associated}(cs%dh\_dt)) \textcolor{keywordflow}{then}
1689     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%dh\_dt,isd,ied,jsd,jed,nz)
1690     \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%h), mis%h, cs%dh\_dt, cs)
1691 \textcolor{keywordflow}{  endif}
1692 
1693   \textcolor{comment}{!CS%id\_hf\_du\_dt = register\_diag\_field('ocean\_model', 'hf\_dudt', diag%axesCuL, Time, &}
1694   \textcolor{comment}{!    'Fractional Thickness-weighted Zonal Acceleration', 'm s-2', v\_extensive=.true., &}
1695   \textcolor{comment}{!    conversion=US%L\_T2\_to\_m\_s2)}
1696   \textcolor{comment}{!if (CS%id\_hf\_du\_dt > 0) then}
1697   \textcolor{comment}{!  call safe\_alloc\_ptr(CS%hf\_du\_dt,IsdB,IedB,jsd,jed,nz)}
1698   \textcolor{comment}{!  if (.not.associated(CS%du\_dt)) then}
1699   \textcolor{comment}{!    call safe\_alloc\_ptr(CS%du\_dt,IsdB,IedB,jsd,jed,nz)}
1700   \textcolor{comment}{!    call register\_time\_deriv(lbound(MIS%u), MIS%u, CS%du\_dt, CS)}
1701   \textcolor{comment}{!  endif}
1702   \textcolor{comment}{!  call safe\_alloc\_ptr(ADp%diag\_hfrac\_u,IsdB,IedB,jsd,jed,nz)}
1703   \textcolor{comment}{!endif}
1704 
1705   \textcolor{comment}{!CS%id\_hf\_dv\_dt = register\_diag\_field('ocean\_model', 'hf\_dvdt', diag%axesCvL, Time, &}
1706   \textcolor{comment}{!    'Fractional Thickness-weighted Meridional Acceleration', 'm s-2', v\_extensive=.true., &}
1707   \textcolor{comment}{!    conversion=US%L\_T2\_to\_m\_s2)}
1708   \textcolor{comment}{!if (CS%id\_hf\_dv\_dt > 0) then}
1709   \textcolor{comment}{!  call safe\_alloc\_ptr(CS%hf\_dv\_dt,isd,ied,JsdB,JedB,nz)}
1710   \textcolor{comment}{!  if (.not.associated(CS%dv\_dt)) then}
1711   \textcolor{comment}{!    call safe\_alloc\_ptr(CS%dv\_dt,isd,ied,JsdB,JedB,nz)}
1712   \textcolor{comment}{!    call register\_time\_deriv(lbound(MIS%v), MIS%v, CS%dv\_dt, CS)}
1713   \textcolor{comment}{!  endif}
1714   \textcolor{comment}{!  call safe\_alloc\_ptr(ADp%diag\_hfrac\_v,isd,ied,Jsd,JedB,nz)}
1715   \textcolor{comment}{!endif}
1716 
1717   cs%id\_hf\_du\_dt\_2d = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'hf\_dudt\_2d'}, diag%axesCu1, time, &
1718       \textcolor{stringliteral}{'Depth-sum Fractional Thickness-weighted Zonal Acceleration'}, \textcolor{stringliteral}{'m s-2'}, conversion=us%L\_T2\_to\_m\_s2)
1719   \textcolor{keywordflow}{if} (cs%id\_hf\_du\_dt\_2d > 0) \textcolor{keywordflow}{then}
1720     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%du\_dt)) \textcolor{keywordflow}{then}
1721       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%du\_dt,isdb,iedb,jsd,jed,nz)
1722       \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%u), mis%u, cs%du\_dt, cs)
1723 \textcolor{keywordflow}{    endif}
1724     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%diag\_hfrac\_u,isdb,iedb,jsd,jed,nz)
1725 \textcolor{keywordflow}{  endif}
1726 
1727   cs%id\_hf\_dv\_dt\_2d = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'hf\_dvdt\_2d'}, diag%axesCv1, time, &
1728       \textcolor{stringliteral}{'Depth-sum Fractional Thickness-weighted Meridional Acceleration'}, \textcolor{stringliteral}{'m s-2'}, conversion=us
      %L\_T2\_to\_m\_s2)
1729   \textcolor{keywordflow}{if} (cs%id\_hf\_dv\_dt\_2d > 0) \textcolor{keywordflow}{then}
1730     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%dv\_dt)) \textcolor{keywordflow}{then}
1731       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%dv\_dt,isd,ied,jsdb,jedb,nz)
1732       \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%v), mis%v, cs%dv\_dt, cs)
1733 \textcolor{keywordflow}{    endif}
1734     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%diag\_hfrac\_v,isd,ied,jsd,jedb,nz)
1735 \textcolor{keywordflow}{  endif}
1736 
1737   \textcolor{comment}{! layer thickness variables}
1738   \textcolor{comment}{!if (GV%nk\_rho\_varies > 0) then}
1739     cs%id\_h\_Rlay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h\_rho'}, diag%axesTL, time, &
1740         \textcolor{stringliteral}{'Layer thicknesses in pure potential density coordinates'}, &
1741         thickness\_units, conversion=convert\_h)
1742     \textcolor{keywordflow}{if} (cs%id\_h\_Rlay>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%h\_Rlay,isd,ied,jsd,jed,nz)
1743 
1744     cs%id\_uh\_Rlay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uh\_rho'}, diag%axesCuL, time, &
1745         \textcolor{stringliteral}{'Zonal volume transport in pure potential density coordinates'}, &
1746         flux\_units, conversion=us%L\_to\_m**2*us%s\_to\_T*convert\_h)
1747     \textcolor{keywordflow}{if} (cs%id\_uh\_Rlay>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%uh\_Rlay,isdb,iedb,jsd,jed,nz)
1748 
1749     cs%id\_vh\_Rlay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vh\_rho'}, diag%axesCvL, time, &
1750         \textcolor{stringliteral}{'Meridional volume transport in pure potential density coordinates'}, &
1751         flux\_units, conversion=us%L\_to\_m**2*us%s\_to\_T*convert\_h)
1752     \textcolor{keywordflow}{if} (cs%id\_vh\_Rlay>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%vh\_Rlay,isd,ied,jsdb,jedb,nz)
1753 
1754     cs%id\_uhGM\_Rlay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhGM\_rho'}, diag%axesCuL, time, &
1755         \textcolor{stringliteral}{'Zonal volume transport due to interface height diffusion in pure potential '}//&
1756         \textcolor{stringliteral}{'density coordinates'}, flux\_units, conversion=us%L\_to\_m**2*us%s\_to\_T*convert\_h)
1757     \textcolor{keywordflow}{if} (cs%id\_uhGM\_Rlay>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%uhGM\_Rlay,isdb,iedb,jsd,jed,nz)
1758 
1759     cs%id\_vhGM\_Rlay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhGM\_rho'}, diag%axesCvL, time, &
1760         \textcolor{stringliteral}{'Meridional volume transport due to interface height diffusion in pure potential '}//&
1761         \textcolor{stringliteral}{'density coordinates'}, flux\_units, conversion=us%L\_to\_m**2*us%s\_to\_T*convert\_h)
1762     \textcolor{keywordflow}{if} (cs%id\_vhGM\_Rlay>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%vhGM\_Rlay,isd,ied,jsdb,jedb,nz)
1763   \textcolor{comment}{!endif}
1764 
1765 
1766   \textcolor{comment}{! terms in the kinetic energy budget}
1767   cs%id\_KE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KE'}, diag%axesTL, time, &
1768       \textcolor{stringliteral}{'Layer kinetic energy per unit mass'}, &
1769       \textcolor{stringliteral}{'m2 s-2'}, conversion=us%L\_T\_to\_m\_s**2)
1770   \textcolor{keywordflow}{if} (cs%id\_KE>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE,isd,ied,jsd,jed,nz)
1771 
1772   cs%id\_dKEdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dKE\_dt'}, diag%axesTL, time, &
1773       \textcolor{stringliteral}{'Kinetic Energy Tendency of Layer'}, &
1774       \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1775   \textcolor{keywordflow}{if} (cs%id\_dKEdt>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%dKE\_dt,isd,ied,jsd,jed,nz)
1776 
1777   cs%id\_PE\_to\_KE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'PE\_to\_KE'}, diag%axesTL, time, &
1778       \textcolor{stringliteral}{'Potential to Kinetic Energy Conversion of Layer'}, &
1779       \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1780   \textcolor{keywordflow}{if} (cs%id\_PE\_to\_KE>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%PE\_to\_KE,isd,ied,jsd,jed,nz)
1781 
1782   cs%id\_KE\_Coradv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KE\_Coradv'}, diag%axesTL, time, &
1783       \textcolor{stringliteral}{'Kinetic Energy Source from Coriolis and Advection'}, &
1784       \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1785   \textcolor{keywordflow}{if} (cs%id\_KE\_Coradv>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE\_Coradv,isd,ied,jsd,jed,nz)
1786 
1787   cs%id\_KE\_adv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KE\_adv'}, diag%axesTL, time, &
1788       \textcolor{stringliteral}{'Kinetic Energy Source from Advection'}, &
1789       \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1790   \textcolor{keywordflow}{if} (cs%id\_KE\_adv>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE\_adv,isd,ied,jsd,jed,nz)
1791 
1792   cs%id\_KE\_visc = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KE\_visc'}, diag%axesTL, time, &
1793       \textcolor{stringliteral}{'Kinetic Energy Source from Vertical Viscosity and Stresses'}, &
1794       \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1795   \textcolor{keywordflow}{if} (cs%id\_KE\_visc>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE\_visc,isd,ied,jsd,jed,nz)
1796 
1797   cs%id\_KE\_horvisc = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KE\_horvisc'}, diag%axesTL, time, &
1798       \textcolor{stringliteral}{'Kinetic Energy Source from Horizontal Viscosity'}, &
1799       \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1800   \textcolor{keywordflow}{if} (cs%id\_KE\_horvisc>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE\_horvisc,isd,ied,jsd,jed,nz)
1801 
1802   \textcolor{keywordflow}{if} (.not. adiabatic) \textcolor{keywordflow}{then}
1803     cs%id\_KE\_dia = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KE\_dia'}, diag%axesTL, time, &
1804         \textcolor{stringliteral}{'Kinetic Energy Source from Diapycnal Diffusion'}, &
1805         \textcolor{stringliteral}{'m3 s-3'}, conversion=gv%H\_to\_m*(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
1806     \textcolor{keywordflow}{if} (cs%id\_KE\_dia>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE\_dia,isd,ied,jsd,jed,nz)
1807 \textcolor{keywordflow}{  endif}
1808 
1809   \textcolor{comment}{! gravity wave CFLs}
1810   cs%id\_cg1 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'cg1'}, diag%axesT1, time, &
1811       \textcolor{stringliteral}{'First baroclinic gravity wave speed'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
1812   cs%id\_Rd1 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Rd1'}, diag%axesT1, time, &
1813       \textcolor{stringliteral}{'First baroclinic deformation radius'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
1814   cs%id\_cfl\_cg1 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'CFL\_cg1'}, diag%axesT1, time, &
1815       \textcolor{stringliteral}{'CFL of first baroclinic gravity wave = dt*cg1*(1/dx+1/dy)'}, \textcolor{stringliteral}{'nondim'})
1816   cs%id\_cfl\_cg1\_x = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'CFL\_cg1\_x'}, diag%axesT1, time, &
1817       \textcolor{stringliteral}{'i-component of CFL of first baroclinic gravity wave = dt*cg1*/dx'}, \textcolor{stringliteral}{'nondim'})
1818   cs%id\_cfl\_cg1\_y = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'CFL\_cg1\_y'}, diag%axesT1, time, &
1819       \textcolor{stringliteral}{'j-component of CFL of first baroclinic gravity wave = dt*cg1*/dy'}, \textcolor{stringliteral}{'nondim'})
1820   cs%id\_cg\_ebt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'cg\_ebt'}, diag%axesT1, time, &
1821       \textcolor{stringliteral}{'Equivalent barotropic gravity wave speed'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
1822   cs%id\_Rd\_ebt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Rd\_ebt'}, diag%axesT1, time, &
1823       \textcolor{stringliteral}{'Equivalent barotropic deformation radius'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
1824   cs%id\_p\_ebt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'p\_ebt'}, diag%axesTL, time, &
1825       \textcolor{stringliteral}{'Equivalent barotropic modal strcuture'}, \textcolor{stringliteral}{'nondim'})
1826 
1827   \textcolor{keywordflow}{if} ((cs%id\_cg1>0) .or. (cs%id\_Rd1>0) .or. (cs%id\_cfl\_cg1>0) .or. &
1828       (cs%id\_cfl\_cg1\_x>0) .or. (cs%id\_cfl\_cg1\_y>0) .or. &
1829       (cs%id\_cg\_ebt>0) .or. (cs%id\_Rd\_ebt>0) .or. (cs%id\_p\_ebt>0)) \textcolor{keywordflow}{then}
1830     \textcolor{keyword}{call }wave\_speed\_init(cs%wave\_speed\_CSp, remap\_answers\_2018=remap\_answers\_2018, &
1831                          better\_speed\_est=better\_speed\_est, min\_speed=wave\_speed\_min, &
1832                          wave\_speed\_tol=wave\_speed\_tol)
1833     \textcolor{keyword}{call }wave\_speed\_init(cs%wave\_speed\_CSp, remap\_answers\_2018=remap\_answers\_2018)
1834     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%cg1,isd,ied,jsd,jed)
1835     \textcolor{keywordflow}{if} (cs%id\_Rd1>0)       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%Rd1,isd,ied,jsd,jed)
1836     \textcolor{keywordflow}{if} (cs%id\_Rd\_ebt>0)    \textcolor{keyword}{call }safe\_alloc\_ptr(cs%Rd1,isd,ied,jsd,jed)
1837     \textcolor{keywordflow}{if} (cs%id\_cfl\_cg1>0)   \textcolor{keyword}{call }safe\_alloc\_ptr(cs%cfl\_cg1,isd,ied,jsd,jed)
1838     \textcolor{keywordflow}{if} (cs%id\_cfl\_cg1\_x>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%cfl\_cg1\_x,isd,ied,jsd,jed)
1839     \textcolor{keywordflow}{if} (cs%id\_cfl\_cg1\_y>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%cfl\_cg1\_y,isd,ied,jsd,jed)
1840     \textcolor{keywordflow}{if} (cs%id\_p\_ebt>0) \textcolor{keyword}{call }safe\_alloc\_ptr(cs%p\_ebt,isd,ied,jsd,jed,nz)
1841 \textcolor{keywordflow}{  endif}
1842 
1843   cs%id\_mass\_wt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'mass\_wt'}, diag%axesT1, time,  &
1844       \textcolor{stringliteral}{'The column mass for calculating mass-weighted average properties'}, \textcolor{stringliteral}{'kg m-2'}, conversion=us
      %RZ\_to\_kg\_m2)
1845 
1846   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
1847     cs%id\_temp\_int = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'temp\_int'}, diag%axesT1, time,                &
1848         \textcolor{stringliteral}{'Density weighted column integrated potential temperature'}, \textcolor{stringliteral}{'degC kg m-2'}, conversion=us
      %RZ\_to\_kg\_m2, &
1849         cmor\_field\_name=\textcolor{stringliteral}{'opottempmint'},                                                               &
1850         cmor\_long\_name=\textcolor{stringliteral}{'integral\_wrt\_depth\_of\_product\_of\_sea\_water\_density\_and\_potential\_temperature'},&
1851         cmor\_standard\_name=\textcolor{stringliteral}{'Depth integrated density times potential temperature'})
1852 
1853     cs%id\_salt\_int = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'salt\_int'}, diag%axesT1, time,   &
1854         \textcolor{stringliteral}{'Density weighted column integrated salinity'}, \textcolor{stringliteral}{'psu kg m-2'}, conversion=us%RZ\_to\_kg\_m2, &
1855         cmor\_field\_name=\textcolor{stringliteral}{'somint'},                                                        &
1856         cmor\_long\_name=\textcolor{stringliteral}{'integral\_wrt\_depth\_of\_product\_of\_sea\_water\_density\_and\_salinity'},&
1857         cmor\_standard\_name=\textcolor{stringliteral}{'Depth integrated density times salinity'})
1858 \textcolor{keywordflow}{  endif}
1859 
1860   cs%id\_col\_mass = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'col\_mass'}, diag%axesT1, time, &
1861       \textcolor{stringliteral}{'The column integrated in situ density'}, \textcolor{stringliteral}{'kg m-2'}, conversion=us%RZ\_to\_kg\_m2)
1862 
1863   cs%id\_col\_ht = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'col\_height'}, diag%axesT1, time, &
1864       \textcolor{stringliteral}{'The height of the water column'}, \textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m)
1865   cs%id\_pbo = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'pbo'}, diag%axesT1, time, &
1866       long\_name=\textcolor{stringliteral}{'Sea Water Pressure at Sea Floor'}, standard\_name=\textcolor{stringliteral}{'sea\_water\_pressure\_at\_sea\_floor'}, &
1867       units=\textcolor{stringliteral}{'Pa'}, conversion=us%RL2\_T2\_to\_Pa)
1868 
1869   \textcolor{keyword}{call }set\_dependent\_diagnostics(mis, adp, cdp, g, cs)
1870 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ac756556059608d88e6a4ef34a07e60ee}\label{namespacemom__diagnostics_ac756556059608d88e6a4ef34a07e60ee}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!post\+\_\+surface\+\_\+dyn\+\_\+diags@{post\+\_\+surface\+\_\+dyn\+\_\+diags}}
\index{post\+\_\+surface\+\_\+dyn\+\_\+diags@{post\+\_\+surface\+\_\+dyn\+\_\+diags}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{post\+\_\+surface\+\_\+dyn\+\_\+diags()}{post\_surface\_dyn\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::post\+\_\+surface\+\_\+dyn\+\_\+diags (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diagnostics_1_1surface__diag__ids}{surface\+\_\+diag\+\_\+ids}), intent(in)}]{I\+Ds,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(diag\+\_\+ctrl), intent(in)}]{diag,  }\item[{type(surface), intent(in)}]{sfc\+\_\+state,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{ssh }\end{DoxyParamCaption})}



This routine posts diagnostics of various dynamic ocean surface quantities, including velocities, speed and sea surface height, at the time the ocean state is reported back to the caller. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em ids} & A structure with the diagnostic I\+Ds.\\
\hline
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em diag} & regulates diagnostic output\\
\hline
\mbox{\tt in}  & {\em sfc\+\_\+state} & structure describing the ocean surface state\\
\hline
\mbox{\tt in}  & {\em ssh} & Time mean surface height without corrections for ice displacement \mbox{[}m\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1228 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1228   \textcolor{keywordtype}{type}(surface\_diag\_ids),   \textcolor{keywordtype}{intent(in)} :: ids\textcolor{comment}{ !< A structure with the diagnostic IDs.}
1229   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< ocean grid structure}
1230   \textcolor{keywordtype}{type}(diag\_ctrl),          \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{ !< regulates diagnostic output}
1231   \textcolor{keywordtype}{type}(surface),            \textcolor{keywordtype}{intent(in)} :: sfc\_state\textcolor{comment}{ !< structure describing the ocean surface state}
1232   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
1233                             \textcolor{keywordtype}{intent(in)} :: ssh\textcolor{comment}{ !< Time mean surface height without corrections for ice
       displacement [m]}
1234 
1235   \textcolor{comment}{! Local variables}
1236   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: speed  \textcolor{comment}{! The surface speed [L T-1 ~> m s-1]}
1237   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
1238 
1239   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
1240 
1241   \textcolor{keywordflow}{if} (ids%id\_ssh > 0) &
1242     \textcolor{keyword}{call }post\_data(ids%id\_ssh, ssh, diag, mask=g%mask2dT)
1243 
1244   \textcolor{keywordflow}{if} (ids%id\_ssu > 0) &
1245     \textcolor{keyword}{call }post\_data(ids%id\_ssu, sfc\_state%u, diag, mask=g%mask2dCu)
1246 
1247   \textcolor{keywordflow}{if} (ids%id\_ssv > 0) &
1248     \textcolor{keyword}{call }post\_data(ids%id\_ssv, sfc\_state%v, diag, mask=g%mask2dCv)
1249 
1250   \textcolor{keywordflow}{if} (ids%id\_speed > 0) \textcolor{keywordflow}{then}
1251     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1252       speed(i,j) = sqrt(0.5*(sfc\_state%u(i-1,j)**2 + sfc\_state%u(i,j)**2) + &
1253                         0.5*(sfc\_state%v(i,j-1)**2 + sfc\_state%v(i,j)**2))
1254 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1255     \textcolor{keyword}{call }post\_data(ids%id\_speed, speed, diag, mask=g%mask2dT)
1256 \textcolor{keywordflow}{  endif}
1257 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_a6fc7dbf8144ba279cc9b7856780ba5d6}\label{namespacemom__diagnostics_a6fc7dbf8144ba279cc9b7856780ba5d6}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!post\+\_\+surface\+\_\+thermo\+\_\+diags@{post\+\_\+surface\+\_\+thermo\+\_\+diags}}
\index{post\+\_\+surface\+\_\+thermo\+\_\+diags@{post\+\_\+surface\+\_\+thermo\+\_\+diags}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{post\+\_\+surface\+\_\+thermo\+\_\+diags()}{post\_surface\_thermo\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::post\+\_\+surface\+\_\+thermo\+\_\+diags (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diagnostics_1_1surface__diag__ids}{surface\+\_\+diag\+\_\+ids}), intent(in)}]{I\+Ds,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(diag\+\_\+ctrl), intent(in)}]{diag,  }\item[{real, intent(in)}]{dt\+\_\+int,  }\item[{type(surface), intent(in)}]{sfc\+\_\+state,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{ssh,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{ssh\+\_\+ibc }\end{DoxyParamCaption})}



This routine posts diagnostics of various ocean surface and integrated quantities at the time the ocean state is reported back to the caller. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em ids} & A structure with the diagnostic I\+Ds.\\
\hline
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em diag} & regulates diagnostic output\\
\hline
\mbox{\tt in}  & {\em dt\+\_\+int} & total time step associated with these diagnostics \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sfc\+\_\+state} & structure describing the ocean surface state\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables\\
\hline
\mbox{\tt in}  & {\em ssh} & Time mean surface height without corrections for ice displacement \mbox{[}m\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ssh\+\_\+ibc} & Time mean surface height with corrections for ice displacement and the inverse barometer \mbox{[}m\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1265 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1265   \textcolor{keywordtype}{type}(surface\_diag\_ids),   \textcolor{keywordtype}{intent(in)} :: ids\textcolor{comment}{ !< A structure with the diagnostic IDs.}
1266   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< ocean grid structure}
1267   \textcolor{keywordtype}{type}(verticalgrid\_type),  \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{  !< ocean vertical grid structure}
1268   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1269   \textcolor{keywordtype}{type}(diag\_ctrl),          \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{  !< regulates diagnostic output}
1270   \textcolor{keywordtype}{real},                     \textcolor{keywordtype}{intent(in)} :: dt\_int\textcolor{comment}{ !< total time step associated with these diagnostics [T ~>
       s].}
1271   \textcolor{keywordtype}{type}(surface),            \textcolor{keywordtype}{intent(in)} :: sfc\_state\textcolor{comment}{ !< structure describing the ocean surface state}
1272   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),    \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{  !< A structure pointing to various thermodynamic variables}
1273   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
1274                             \textcolor{keywordtype}{intent(in)} :: ssh\textcolor{comment}{ !< Time mean surface height without corrections for ice
       displacement [m]}
1275   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)} :: ssh\_ibc\textcolor{comment}{ !< Time mean surface height with corrections}
1276 \textcolor{comment}{                                                  !! for ice displacement and the inverse barometer [m]}
1277 
1278   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: work\_2d  \textcolor{comment}{! A 2-d work array}
1279   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
1280     zos  \textcolor{comment}{! dynamic sea lev (zero area mean) from inverse-barometer adjusted ssh [m]}
1281   \textcolor{keywordtype}{real} :: i\_time\_int    \textcolor{comment}{! The inverse of the time interval [T-1 ~> s-1].}
1282   \textcolor{keywordtype}{real} :: zos\_area\_mean, volo, ssh\_ga
1283   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
1284 
1285   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
1286 
1287   \textcolor{comment}{! area mean SSH}
1288   \textcolor{keywordflow}{if} (ids%id\_ssh\_ga > 0) \textcolor{keywordflow}{then}
1289     ssh\_ga = global\_area\_mean(ssh, g)
1290     \textcolor{keyword}{call }post\_data(ids%id\_ssh\_ga, ssh\_ga, diag)
1291 \textcolor{keywordflow}{  endif}
1292 
1293   \textcolor{comment}{! post the dynamic sea level, zos, and zossq.}
1294   \textcolor{comment}{! zos is ave\_ssh with sea ice inverse barometer removed,}
1295   \textcolor{comment}{! and with zero global area mean.}
1296   \textcolor{keywordflow}{if} (ids%id\_zos > 0 .or. ids%id\_zossq > 0) \textcolor{keywordflow}{then}
1297     zos(:,:) = 0.0
1298     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1299       zos(i,j) = ssh\_ibc(i,j)
1300 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1301     zos\_area\_mean = global\_area\_mean(zos, g)
1302     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1303       zos(i,j) = zos(i,j) - g%mask2dT(i,j)*zos\_area\_mean
1304 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1305     \textcolor{keywordflow}{if} (ids%id\_zos > 0) \textcolor{keyword}{call }post\_data(ids%id\_zos, zos, diag, mask=g%mask2dT)
1306     \textcolor{keywordflow}{if} (ids%id\_zossq > 0) \textcolor{keywordflow}{then}
1307       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1308         work\_2d(i,j) = zos(i,j)*zos(i,j)
1309 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1310       \textcolor{keyword}{call }post\_data(ids%id\_zossq, work\_2d, diag, mask=g%mask2dT)
1311 \textcolor{keywordflow}{    endif}
1312 \textcolor{keywordflow}{  endif}
1313 
1314   \textcolor{comment}{! post total volume of the liquid ocean}
1315   \textcolor{keywordflow}{if} (ids%id\_volo > 0) \textcolor{keywordflow}{then}
1316     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1317       work\_2d(i,j) = g%mask2dT(i,j)*(ssh(i,j) + us%Z\_to\_m*g%bathyT(i,j))
1318 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1319     volo = global\_area\_integral(work\_2d, g)
1320     \textcolor{keyword}{call }post\_data(ids%id\_volo, volo, diag)
1321 \textcolor{keywordflow}{  endif}
1322 
1323   \textcolor{comment}{! Use Adcroft's rule of reciprocals; it does the right thing here.}
1324   i\_time\_int = 0.0 ; \textcolor{keywordflow}{if} (dt\_int > 0.0) i\_time\_int = 1.0 / dt\_int
1325 
1326   \textcolor{comment}{! post time-averaged rate of frazil formation}
1327   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%frazil) .and. (ids%id\_fraz > 0)) \textcolor{keywordflow}{then}
1328     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1329       work\_2d(i,j) = tv%frazil(i,j) * i\_time\_int
1330 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1331     \textcolor{keyword}{call }post\_data(ids%id\_fraz, work\_2d, diag, mask=g%mask2dT)
1332 \textcolor{keywordflow}{  endif}
1333 
1334   \textcolor{comment}{! post time-averaged salt deficit}
1335   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%salt\_deficit) .and. (ids%id\_salt\_deficit > 0)) \textcolor{keywordflow}{then}
1336     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1337       work\_2d(i,j) = tv%salt\_deficit(i,j) * i\_time\_int
1338 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1339     \textcolor{keyword}{call }post\_data(ids%id\_salt\_deficit, work\_2d, diag, mask=g%mask2dT)
1340 \textcolor{keywordflow}{  endif}
1341 
1342   \textcolor{comment}{! post temperature of P-E+R}
1343   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%TempxPmE) .and. (ids%id\_Heat\_PmE > 0)) \textcolor{keywordflow}{then}
1344     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1345       work\_2d(i,j) = tv%TempxPmE(i,j) * (tv%C\_p * i\_time\_int)
1346 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1347     \textcolor{keyword}{call }post\_data(ids%id\_Heat\_PmE, work\_2d, diag, mask=g%mask2dT)
1348 \textcolor{keywordflow}{  endif}
1349 
1350   \textcolor{comment}{! post geothermal heating or internal heat source/sinks}
1351   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%internal\_heat) .and. (ids%id\_intern\_heat > 0)) \textcolor{keywordflow}{then}
1352     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1353       work\_2d(i,j) = tv%internal\_heat(i,j) * (tv%C\_p * i\_time\_int)
1354 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1355     \textcolor{keyword}{call }post\_data(ids%id\_intern\_heat, work\_2d, diag, mask=g%mask2dT)
1356 \textcolor{keywordflow}{  endif}
1357 
1358   \textcolor{keywordflow}{if} (tv%T\_is\_conT) \textcolor{keywordflow}{then}
1359     \textcolor{comment}{! Internal T&S variables are conservative temperature & absolute salinity}
1360     \textcolor{keywordflow}{if} (ids%id\_sstcon > 0) \textcolor{keyword}{call }post\_data(ids%id\_sstcon, sfc\_state%SST, diag, mask=g%mask2dT)
1361     \textcolor{comment}{! Use TEOS-10 function calls convert T&S diagnostics from conservative temp}
1362     \textcolor{comment}{! to potential temperature.}
1363     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1364       work\_2d(i,j) = gsw\_pt\_from\_ct(sfc\_state%SSS(i,j), sfc\_state%SST(i,j))
1365 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1366     \textcolor{keywordflow}{if} (ids%id\_sst > 0) \textcolor{keyword}{call }post\_data(ids%id\_sst, work\_2d, diag, mask=g%mask2dT)
1367   \textcolor{keywordflow}{else}
1368     \textcolor{comment}{! Internal T&S variables are potential temperature & practical salinity}
1369     \textcolor{keywordflow}{if} (ids%id\_sst > 0) \textcolor{keyword}{call }post\_data(ids%id\_sst, sfc\_state%SST, diag, mask=g%mask2dT)
1370 \textcolor{keywordflow}{  endif}
1371 
1372   \textcolor{keywordflow}{if} (tv%S\_is\_absS) \textcolor{keywordflow}{then}
1373     \textcolor{comment}{! Internal T&S variables are conservative temperature & absolute salinity}
1374     \textcolor{keywordflow}{if} (ids%id\_sssabs > 0) \textcolor{keyword}{call }post\_data(ids%id\_sssabs, sfc\_state%SSS, diag, mask=g%mask2dT)
1375     \textcolor{comment}{! Use TEOS-10 function calls convert T&S diagnostics from absolute salinity}
1376     \textcolor{comment}{! to practical salinity.}
1377     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1378       work\_2d(i,j) = gsw\_sp\_from\_sr(sfc\_state%SSS(i,j))
1379 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1380     \textcolor{keywordflow}{if} (ids%id\_sss > 0) \textcolor{keyword}{call }post\_data(ids%id\_sss, work\_2d, diag, mask=g%mask2dT)
1381   \textcolor{keywordflow}{else}
1382     \textcolor{comment}{! Internal T&S variables are potential temperature & practical salinity}
1383     \textcolor{keywordflow}{if} (ids%id\_sss > 0) \textcolor{keyword}{call }post\_data(ids%id\_sss, sfc\_state%SSS, diag, mask=g%mask2dT)
1384 \textcolor{keywordflow}{  endif}
1385 
1386   \textcolor{keywordflow}{if} (ids%id\_sst\_sq > 0) \textcolor{keywordflow}{then}
1387     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1388       work\_2d(i,j) = sfc\_state%SST(i,j)*sfc\_state%SST(i,j)
1389 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1390     \textcolor{keyword}{call }post\_data(ids%id\_sst\_sq, work\_2d, diag, mask=g%mask2dT)
1391 \textcolor{keywordflow}{  endif}
1392   \textcolor{keywordflow}{if} (ids%id\_sss\_sq > 0) \textcolor{keywordflow}{then}
1393     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1394       work\_2d(i,j) = sfc\_state%SSS(i,j)*sfc\_state%SSS(i,j)
1395 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1396     \textcolor{keyword}{call }post\_data(ids%id\_sss\_sq, work\_2d, diag, mask=g%mask2dT)
1397 \textcolor{keywordflow}{  endif}
1398 
1399   \textcolor{keyword}{call }coupler\_type\_send\_data(sfc\_state%tr\_fields, get\_diag\_time\_end(diag))
1400 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_acab7430159d4702301069d0d4f82f45c}\label{namespacemom__diagnostics_acab7430159d4702301069d0d4f82f45c}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!post\+\_\+transport\+\_\+diagnostics@{post\+\_\+transport\+\_\+diagnostics}}
\index{post\+\_\+transport\+\_\+diagnostics@{post\+\_\+transport\+\_\+diagnostics}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{post\+\_\+transport\+\_\+diagnostics()}{post\_transport\_diagnostics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::post\+\_\+transport\+\_\+diagnostics (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{uhtr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{vhtr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(\hyperlink{structmom__diagnostics_1_1transport__diag__ids}{transport\+\_\+diag\+\_\+ids}), intent(in)}]{I\+Ds,  }\item[{type(diag\+\_\+grid\+\_\+storage), intent(inout)}]{diag\+\_\+pre\+\_\+dyn,  }\item[{type(diag\+\_\+ctrl), intent(inout)}]{diag,  }\item[{real, intent(in)}]{dt\+\_\+trans,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{Reg }\end{DoxyParamCaption})}



This routine posts diagnostics of the transports, including the subgridscale contributions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em uhtr} & Accumulated zonal thickness fluxes used to advect tracers \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em vhtr} & Accumulated meridional thickness fluxes used to advect tracers \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h} & The updated layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ids} & A structure with the diagnostic I\+Ds.\\
\hline
\mbox{\tt in,out}  & {\em diag\+\_\+pre\+\_\+dyn} & Stored grids from before dynamics\\
\hline
\mbox{\tt in,out}  & {\em diag} & regulates diagnostic output\\
\hline
\mbox{\tt in}  & {\em dt\+\_\+trans} & total time step associated with the transports \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
 & {\em reg} & Pointer to the tracer registry \\
\hline
\end{DoxyParams}


Definition at line 1408 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1408   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< ocean grid structure}
1409   \textcolor{keywordtype}{type}(verticalgrid\_type),  \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{  !< ocean vertical grid structure}
1410   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1411   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: uhtr\textcolor{comment}{ !< Accumulated zonal thickness fluxes}
1412 \textcolor{comment}{                                                 !! used to advect tracers [H L2 ~> m3 or kg]}
1413   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: vhtr\textcolor{comment}{ !< Accumulated meridional thickness fluxes}
1414 \textcolor{comment}{                                                 !! used to advect tracers [H L2 ~> m3 or kg]}
1415   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
1416                             \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{   !< The updated layer thicknesses [H ~> m or kg m-2]}
1417   \textcolor{keywordtype}{type}(transport\_diag\_ids), \textcolor{keywordtype}{intent(in)}    :: ids\textcolor{comment}{ !< A structure with the diagnostic IDs.}
1418   \textcolor{keywordtype}{type}(diag\_grid\_storage),  \textcolor{keywordtype}{intent(inout)} :: diag\_pre\_dyn\textcolor{comment}{ !< Stored grids from before dynamics}
1419   \textcolor{keywordtype}{type}(diag\_ctrl),          \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< regulates diagnostic output}
1420   \textcolor{keywordtype}{real},                     \textcolor{keywordtype}{intent(in)}    :: dt\_trans\textcolor{comment}{ !< total time step associated with the transports [T
       ~> s].}
1421   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}     :: reg\textcolor{comment}{ !< Pointer to the tracer registry}
1422 
1423   \textcolor{comment}{! Local variables}
1424   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G), SZJ\_(G))} :: umo2d \textcolor{comment}{! Diagnostics of integrated mass transport [R Z L2 T-1 ~> kg
       s-1]}
1425   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJB\_(G))} :: vmo2d \textcolor{comment}{! Diagnostics of integrated mass transport [R Z L2 T-1 ~> kg
       s-1]}
1426   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G), SZJ\_(G), SZK\_(G))} :: umo \textcolor{comment}{! Diagnostics of layer mass transport [R Z L2 T-1 ~>
       kg s-1]}
1427   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJB\_(G), SZK\_(G))} :: vmo \textcolor{comment}{! Diagnostics of layer mass transport [R Z L2 T-1 ~>
       kg s-1]}
1428   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}    :: h\_tend \textcolor{comment}{! Change in layer thickness due to dynamics}
1429                           \textcolor{comment}{! [H s-1 ~> m s-1 or kg m-2 s-1].}
1430   \textcolor{keywordtype}{real} :: idt             \textcolor{comment}{! The inverse of the time interval [T-1 ~> s-1]}
1431   \textcolor{keywordtype}{real} :: h\_to\_rz\_dt   \textcolor{comment}{! A conversion factor from accumulated transports to fluxes}
1432                           \textcolor{comment}{! [R Z H-1 T-1 ~> kg m-3 s-1 or s-1].}
1433   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
1434   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1435 
1436   idt = 1. / dt\_trans
1437   h\_to\_rz\_dt = gv%H\_to\_RZ * idt
1438 
1439   \textcolor{keyword}{call }diag\_save\_grids(diag)
1440   \textcolor{keyword}{call }diag\_copy\_storage\_to\_diag(diag, diag\_pre\_dyn)
1441 
1442   \textcolor{keywordflow}{if} (ids%id\_umo\_2d > 0) \textcolor{keywordflow}{then}
1443     umo2d(:,:) = 0.0
1444     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
1445       umo2d(i,j) = umo2d(i,j) + uhtr(i,j,k) * h\_to\_rz\_dt
1446 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1447     \textcolor{keyword}{call }post\_data(ids%id\_umo\_2d, umo2d, diag)
1448 \textcolor{keywordflow}{  endif}
1449   \textcolor{keywordflow}{if} (ids%id\_umo > 0) \textcolor{keywordflow}{then}
1450     \textcolor{comment}{! Convert to kg/s.}
1451     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
1452       umo(i,j,k) = uhtr(i,j,k) * h\_to\_rz\_dt
1453 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1454     \textcolor{keyword}{call }post\_data(ids%id\_umo, umo, diag, alt\_h = diag\_pre\_dyn%h\_state)
1455 \textcolor{keywordflow}{  endif}
1456   \textcolor{keywordflow}{if} (ids%id\_vmo\_2d > 0) \textcolor{keywordflow}{then}
1457     vmo2d(:,:) = 0.0
1458     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
1459       vmo2d(i,j) = vmo2d(i,j) + vhtr(i,j,k) * h\_to\_rz\_dt
1460 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1461     \textcolor{keyword}{call }post\_data(ids%id\_vmo\_2d, vmo2d, diag)
1462 \textcolor{keywordflow}{  endif}
1463   \textcolor{keywordflow}{if} (ids%id\_vmo > 0) \textcolor{keywordflow}{then}
1464     \textcolor{comment}{! Convert to kg/s.}
1465     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
1466       vmo(i,j,k) = vhtr(i,j,k) * h\_to\_rz\_dt
1467 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1468     \textcolor{keyword}{call }post\_data(ids%id\_vmo, vmo, diag, alt\_h = diag\_pre\_dyn%h\_state)
1469 \textcolor{keywordflow}{  endif}
1470 
1471   \textcolor{keywordflow}{if} (ids%id\_uhtr > 0) \textcolor{keyword}{call }post\_data(ids%id\_uhtr, uhtr, diag, alt\_h = diag\_pre\_dyn%h\_state)
1472   \textcolor{keywordflow}{if} (ids%id\_vhtr > 0) \textcolor{keyword}{call }post\_data(ids%id\_vhtr, vhtr, diag, alt\_h = diag\_pre\_dyn%h\_state)
1473   \textcolor{keywordflow}{if} (ids%id\_dynamics\_h > 0) \textcolor{keyword}{call }post\_data(ids%id\_dynamics\_h, diag\_pre\_dyn%h\_state, diag, &
1474                                             alt\_h = diag\_pre\_dyn%h\_state)
1475   \textcolor{comment}{! Post the change in thicknesses}
1476   \textcolor{keywordflow}{if} (ids%id\_dynamics\_h\_tendency > 0) \textcolor{keywordflow}{then}
1477     h\_tend(:,:,:) = 0.
1478     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1479       h\_tend(i,j,k) = (h(i,j,k) - diag\_pre\_dyn%h\_state(i,j,k))*idt
1480 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1481     \textcolor{keyword}{call }post\_data(ids%id\_dynamics\_h\_tendency, h\_tend, diag, alt\_h = diag\_pre\_dyn%h\_state)
1482 \textcolor{keywordflow}{  endif}
1483 
1484   \textcolor{keyword}{call }post\_tracer\_transport\_diagnostics(g, gv, reg, diag\_pre\_dyn%h\_state, diag)
1485 
1486   \textcolor{keyword}{call }diag\_restore\_grids(diag)
1487 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ae9e2f6374b60bc78898a3c462174f90d}\label{namespacemom__diagnostics_ae9e2f6374b60bc78898a3c462174f90d}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!register\+\_\+surface\+\_\+diags@{register\+\_\+surface\+\_\+diags}}
\index{register\+\_\+surface\+\_\+diags@{register\+\_\+surface\+\_\+diags}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{register\+\_\+surface\+\_\+diags()}{register\_surface\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::register\+\_\+surface\+\_\+diags (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__diagnostics_1_1surface__diag__ids}{surface\+\_\+diag\+\_\+ids}), intent(inout)}]{I\+Ds,  }\item[{type(diag\+\_\+ctrl), intent(inout)}]{diag,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv }\end{DoxyParamCaption})}



Register diagnostics of the surface state and integrated quantities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & current model time\\
\hline
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em ids} & A structure with the diagnostic I\+Ds.\\
\hline
\mbox{\tt in,out}  & {\em diag} & regulates diagnostic output\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\end{DoxyParams}


Definition at line 1876 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1876   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{  !< current model time}
1877   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{     !< ocean grid structure}
1878   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
1879   \textcolor{keywordtype}{type}(surface\_diag\_ids),  \textcolor{keywordtype}{intent(inout)} :: ids\textcolor{comment}{   !< A structure with the diagnostic IDs.}
1880   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{  !< regulates diagnostic output}
1881   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{    !< A structure pointing to various thermodynamic
       variables}
1882 
1883   \textcolor{comment}{! Vertically integrated, budget, and surface state diagnostics}
1884   ids%id\_volo = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'volo'}, time, diag,&
1885       long\_name=\textcolor{stringliteral}{'Total volume of liquid ocean'}, units=\textcolor{stringliteral}{'m3'},            &
1886       standard\_name=\textcolor{stringliteral}{'sea\_water\_volume'})
1887   ids%id\_zos = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'zos'}, diag%axesT1, time,&
1888       standard\_name = \textcolor{stringliteral}{'sea\_surface\_height\_above\_geoid'},                   &
1889       long\_name= \textcolor{stringliteral}{'Sea surface height above geoid'}, units=\textcolor{stringliteral}{'m'})
1890   ids%id\_zossq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'zossq'}, diag%axesT1, time,&
1891       standard\_name=\textcolor{stringliteral}{'square\_of\_sea\_surface\_height\_above\_geoid'},             &
1892       long\_name=\textcolor{stringliteral}{'Square of sea surface height above geoid'}, units=\textcolor{stringliteral}{'m2'})
1893   ids%id\_ssh = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSH'}, diag%axesT1, time, &
1894       \textcolor{stringliteral}{'Sea Surface Height'}, \textcolor{stringliteral}{'m'})
1895   ids%id\_ssh\_ga = register\_scalar\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ssh\_ga'}, time, diag,&
1896       long\_name=\textcolor{stringliteral}{'Area averaged sea surface height'}, units=\textcolor{stringliteral}{'m'},            &
1897       standard\_name=\textcolor{stringliteral}{'area\_averaged\_sea\_surface\_height'})
1898   ids%id\_ssu = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSU'}, diag%axesCu1, time, &
1899       \textcolor{stringliteral}{'Sea Surface Zonal Velocity'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
1900   ids%id\_ssv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSV'}, diag%axesCv1, time, &
1901       \textcolor{stringliteral}{'Sea Surface Meridional Velocity'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
1902   ids%id\_speed = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'speed'}, diag%axesT1, time, &
1903       \textcolor{stringliteral}{'Sea Surface Speed'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
1904 
1905   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) \textcolor{keywordflow}{then}
1906     ids%id\_sst = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SST'}, diag%axesT1, time,     &
1907         \textcolor{stringliteral}{'Sea Surface Temperature'}, \textcolor{stringliteral}{'degC'}, cmor\_field\_name=\textcolor{stringliteral}{'tos'}, &
1908         cmor\_long\_name=\textcolor{stringliteral}{'Sea Surface Temperature'},                                &
1909         cmor\_standard\_name=\textcolor{stringliteral}{'sea\_surface\_temperature'})
1910     ids%id\_sst\_sq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SST\_sq'}, diag%axesT1, time, &
1911         \textcolor{stringliteral}{'Sea Surface Temperature Squared'}, \textcolor{stringliteral}{'degC2'}, cmor\_field\_name=\textcolor{stringliteral}{'tossq'}, &
1912         cmor\_long\_name=\textcolor{stringliteral}{'Square of Sea Surface Temperature '},                      &
1913         cmor\_standard\_name=\textcolor{stringliteral}{'square\_of\_sea\_surface\_temperature'})
1914     ids%id\_sss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSS'}, diag%axesT1, time, &
1915         \textcolor{stringliteral}{'Sea Surface Salinity'}, \textcolor{stringliteral}{'psu'}, cmor\_field\_name=\textcolor{stringliteral}{'sos'}, &
1916         cmor\_long\_name=\textcolor{stringliteral}{'Sea Surface Salinity'},                            &
1917         cmor\_standard\_name=\textcolor{stringliteral}{'sea\_surface\_salinity'})
1918     ids%id\_sss\_sq = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSS\_sq'}, diag%axesT1, time, &
1919         \textcolor{stringliteral}{'Sea Surface Salinity Squared'}, \textcolor{stringliteral}{'psu'}, cmor\_field\_name=\textcolor{stringliteral}{'sossq'}, &
1920         cmor\_long\_name=\textcolor{stringliteral}{'Square of Sea Surface Salinity '},                     &
1921         cmor\_standard\_name=\textcolor{stringliteral}{'square\_of\_sea\_surface\_salinity'})
1922     \textcolor{keywordflow}{if} (tv%T\_is\_conT) \textcolor{keywordflow}{then}
1923       ids%id\_sstcon = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'conSST'}, diag%axesT1, time,     &
1924           \textcolor{stringliteral}{'Sea Surface Conservative Temperature'}, \textcolor{stringliteral}{'Celsius'})
1925 \textcolor{keywordflow}{    endif}
1926     \textcolor{keywordflow}{if} (tv%S\_is\_absS) \textcolor{keywordflow}{then}
1927       ids%id\_sssabs = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'absSSS'}, diag%axesT1, time,     &
1928           \textcolor{stringliteral}{'Sea Surface Absolute Salinity'}, \textcolor{stringliteral}{'g kg-1'})
1929 \textcolor{keywordflow}{    endif}
1930     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%frazil)) \textcolor{keywordflow}{then}
1931       ids%id\_fraz = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'frazil'}, diag%axesT1, time, &
1932             \textcolor{stringliteral}{'Heat from frazil formation'}, \textcolor{stringliteral}{'W m-2'}, conversion=us%QRZ\_T\_to\_W\_m2, &
1933             cmor\_field\_name=\textcolor{stringliteral}{'hfsifrazil'}, &
1934             cmor\_standard\_name=\textcolor{stringliteral}{'heat\_flux\_into\_sea\_water\_due\_to\_frazil\_ice\_formation'}, &
1935             cmor\_long\_name=\textcolor{stringliteral}{'Heat Flux into Sea Water due to Frazil Ice Formation'})
1936 \textcolor{keywordflow}{    endif}
1937 \textcolor{keywordflow}{  endif}
1938 
1939   ids%id\_salt\_deficit = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'salt\_deficit'}, diag%axesT1, time, &
1940          \textcolor{stringliteral}{'Salt sink in ocean due to ice flux'}, &
1941          \textcolor{stringliteral}{'psu m-2 s-1'}, conversion=us%RZ\_T\_to\_kg\_m2s)
1942   ids%id\_Heat\_PmE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Heat\_PmE'}, diag%axesT1, time, &
1943          \textcolor{stringliteral}{'Heat flux into ocean from mass flux into ocean'}, &
1944          \textcolor{stringliteral}{'W m-2'}, conversion=us%QRZ\_T\_to\_W\_m2)
1945   ids%id\_intern\_heat = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'internal\_heat'}, diag%axesT1, time,&
1946          \textcolor{stringliteral}{'Heat flux into ocean from geothermal or other internal sources'}, &
1947          \textcolor{stringliteral}{'W m-2'}, conversion=us%QRZ\_T\_to\_W\_m2)
1948 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_addfe6cd212e836194ccaf737bcc5cce8}\label{namespacemom__diagnostics_addfe6cd212e836194ccaf737bcc5cce8}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!register\+\_\+time\+\_\+deriv@{register\+\_\+time\+\_\+deriv}}
\index{register\+\_\+time\+\_\+deriv@{register\+\_\+time\+\_\+deriv}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{register\+\_\+time\+\_\+deriv()}{register\_time\_deriv()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::register\+\_\+time\+\_\+deriv (\begin{DoxyParamCaption}\item[{integer, dimension(3), intent(in)}]{lb,  }\item[{real, dimension(lb(1)\+:,lb(2)\+:,\+:), target}]{f\+\_\+ptr,  }\item[{real, dimension(lb(1)\+:,lb(2)\+:,\+:), target}]{deriv\+\_\+ptr,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine registers fields to calculate a diagnostic time derivative. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em lb} & Lower index bound of f\+\_\+ptr\\
\hline
 & {\em f\+\_\+ptr} & Time derivative operand\\
\hline
 & {\em deriv\+\_\+ptr} & Time derivative of f\+\_\+ptr\\
\hline
 & {\em cs} & Control structure returned by previous call to diagnostics\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 1155 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1155   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)}, \textcolor{keywordtype}{dimension(3)} :: lb\textcolor{comment}{     !< Lower index bound of f\_ptr}
1156   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(lb(1):,lb(2):,:)}, \textcolor{keywordtype}{target} :: f\_ptr
1157                                               \textcolor{comment}{!< Time derivative operand}
1158   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(lb(1):,lb(2):,:)}, \textcolor{keywordtype}{target} :: deriv\_ptr
1159                                               \textcolor{comment}{!< Time derivative of f\_ptr}
1160   \textcolor{keywordtype}{type}(diagnostics\_cs),  \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{        !< Control structure returned by previous call to}
1161 \textcolor{comment}{                                              !! diagnostics\_init.}
1162 
1163   \textcolor{comment}{! This subroutine registers fields to calculate a diagnostic time derivative.}
1164   \textcolor{comment}{! NOTE: Lower bound is required for grid indexing in calculate\_derivs().}
1165   \textcolor{comment}{!       We assume that the vertical axis is 1-indexed.}
1166 
1167   \textcolor{keywordtype}{integer} :: m\textcolor{comment}{      !< New index of deriv\_ptr in CS%deriv}
1168   \textcolor{keywordtype}{integer} :: ub(3)\textcolor{comment}{  !< Upper index bound of f\_ptr, based on shape.}
1169 
1170   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, &
1171          \textcolor{stringliteral}{"register\_time\_deriv: Module must be initialized before it is used."})
1172 
1173   \textcolor{keywordflow}{if} (cs%num\_time\_deriv >= max\_fields\_) \textcolor{keywordflow}{then}
1174     \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"MOM\_diagnostics:  Attempted to register more than "} // &
1175                    \textcolor{stringliteral}{"MAX\_FIELDS\_ diagnostic time derivatives via register\_time\_deriv."})
1176     \textcolor{keywordflow}{return}
1177 \textcolor{keywordflow}{  endif}
1178 
1179   m = cs%num\_time\_deriv+1 ; cs%num\_time\_deriv = m
1180 
1181   ub(:) = lb(:) + shape(f\_ptr) - 1
1182 
1183   cs%nlay(m) = \textcolor{keyword}{size}(f\_ptr, 3)
1184   cs%deriv(m)%p => deriv\_ptr
1185   \textcolor{keyword}{allocate}(cs%prev\_val(m)%p(lb(1):ub(1), lb(2):ub(2), cs%nlay(m)))
1186 
1187   cs%var\_ptr(m)%p => f\_ptr
1188   cs%prev\_val(m)%p(:,:,:) = f\_ptr(:,:,:)
1189 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_ac16b7c49e4a4b5ea2beb426bc5270ee9}\label{namespacemom__diagnostics_ac16b7c49e4a4b5ea2beb426bc5270ee9}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!register\+\_\+transport\+\_\+diags@{register\+\_\+transport\+\_\+diags}}
\index{register\+\_\+transport\+\_\+diags@{register\+\_\+transport\+\_\+diags}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{register\+\_\+transport\+\_\+diags()}{register\_transport\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::register\+\_\+transport\+\_\+diags (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__diagnostics_1_1transport__diag__ids}{transport\+\_\+diag\+\_\+ids}), intent(inout)}]{I\+Ds,  }\item[{type(diag\+\_\+ctrl), intent(inout)}]{diag }\end{DoxyParamCaption})}



Register certain diagnostics related to transports. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & current model time\\
\hline
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em ids} & A structure with the diagnostic I\+Ds.\\
\hline
\mbox{\tt in,out}  & {\em diag} & regulates diagnostic output \\
\hline
\end{DoxyParams}


Definition at line 1953 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
1953   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{  !< current model time}
1954   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{     !< ocean grid structure}
1955   \textcolor{keywordtype}{type}(verticalgrid\_type),  \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{    !< ocean vertical grid structure}
1956   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
1957   \textcolor{keywordtype}{type}(transport\_diag\_ids), \textcolor{keywordtype}{intent(inout)} :: ids\textcolor{comment}{   !< A structure with the diagnostic IDs.}
1958   \textcolor{keywordtype}{type}(diag\_ctrl),          \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{  !< regulates diagnostic output}
1959 
1960   \textcolor{keywordtype}{real} :: h\_convert
1961   \textcolor{keywordtype}{character(len=48)} :: thickness\_units
1962 
1963   thickness\_units = get\_thickness\_units(gv)
1964   \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then}
1965     h\_convert = gv%H\_to\_m
1966   \textcolor{keywordflow}{else}
1967     h\_convert = gv%H\_to\_kg\_m2
1968 \textcolor{keywordflow}{  endif}
1969 
1970   \textcolor{comment}{! Diagnostics related to tracer and mass transport}
1971   ids%id\_uhtr = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhtr'}, diag%axesCuL, time, &
1972       \textcolor{stringliteral}{'Accumulated zonal thickness fluxes to advect tracers'}, \textcolor{stringliteral}{'kg'}, &
1973       y\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true., conversion=h\_convert*us%L\_to\_m**2)
1974   ids%id\_vhtr = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhtr'}, diag%axesCvL, time, &
1975       \textcolor{stringliteral}{'Accumulated meridional thickness fluxes to advect tracers'}, \textcolor{stringliteral}{'kg'}, &
1976       x\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true., conversion=h\_convert*us%L\_to\_m**2)
1977   ids%id\_umo = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'umo'}, &
1978       diag%axesCuL, time, \textcolor{stringliteral}{'Ocean Mass X Transport'}, &
1979       \textcolor{stringliteral}{'kg s-1'}, conversion=us%RZ\_T\_to\_kg\_m2s*us%L\_to\_m**2, &
1980       standard\_name=\textcolor{stringliteral}{'ocean\_mass\_x\_transport'}, y\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true.)
1981   ids%id\_vmo = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vmo'}, &
1982       diag%axesCvL, time, \textcolor{stringliteral}{'Ocean Mass Y Transport'}, &
1983       \textcolor{stringliteral}{'kg s-1'}, conversion=us%RZ\_T\_to\_kg\_m2s*us%L\_to\_m**2, &
1984       standard\_name=\textcolor{stringliteral}{'ocean\_mass\_y\_transport'}, x\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true.)
1985   ids%id\_umo\_2d = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'umo\_2d'}, &
1986       diag%axesCu1, time, \textcolor{stringliteral}{'Ocean Mass X Transport Vertical Sum'}, &
1987       \textcolor{stringliteral}{'kg s-1'}, conversion=us%RZ\_T\_to\_kg\_m2s*us%L\_to\_m**2, &
1988       standard\_name=\textcolor{stringliteral}{'ocean\_mass\_x\_transport\_vertical\_sum'}, y\_cell\_method=\textcolor{stringliteral}{'sum'})
1989   ids%id\_vmo\_2d = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vmo\_2d'}, &
1990       diag%axesCv1, time, \textcolor{stringliteral}{'Ocean Mass Y Transport Vertical Sum'}, &
1991       \textcolor{stringliteral}{'kg s-1'}, conversion=us%RZ\_T\_to\_kg\_m2s*us%L\_to\_m**2, &
1992       standard\_name=\textcolor{stringliteral}{'ocean\_mass\_y\_transport\_vertical\_sum'}, x\_cell\_method=\textcolor{stringliteral}{'sum'})
1993   ids%id\_dynamics\_h = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'dynamics\_h'},  &
1994       diag%axesTl, time, \textcolor{stringliteral}{'Change in layer thicknesses due to horizontal dynamics'}, &
1995       \textcolor{stringliteral}{'m s-1'}, v\_extensive=.true., conversion=gv%H\_to\_m)
1996   ids%id\_dynamics\_h\_tendency = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'dynamics\_h\_tendency'},  &
1997       diag%axesTl, time, \textcolor{stringliteral}{'Change in layer thicknesses due to horizontal dynamics'}, &
1998       \textcolor{stringliteral}{'m s-1'}, v\_extensive=.true., conversion=gv%H\_to\_m*us%s\_to\_T)
1999 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_a90a92410576d955e89d2aa4e3f6d7402}\label{namespacemom__diagnostics_a90a92410576d955e89d2aa4e3f6d7402}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!set\+\_\+dependent\+\_\+diagnostics@{set\+\_\+dependent\+\_\+diagnostics}}
\index{set\+\_\+dependent\+\_\+diagnostics@{set\+\_\+dependent\+\_\+diagnostics}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{set\+\_\+dependent\+\_\+diagnostics()}{set\_dependent\_diagnostics()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diagnostics\+::set\+\_\+dependent\+\_\+diagnostics (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+internal\+\_\+state), intent(in)}]{M\+IS,  }\item[{type(accel\+\_\+diag\+\_\+ptrs), intent(inout)}]{A\+Dp,  }\item[{type(cont\+\_\+diag\+\_\+ptrs), intent(inout)}]{C\+Dp,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__diagnostics_1_1diagnostics__cs}{diagnostics\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets up diagnostics upon which other diagnostics depend. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em mis} & For \char`\"{}\+M\+O\+M Internal State\char`\"{} a set of pointers to the fields and accelerations making up ocean internal physical state.\\
\hline
\mbox{\tt in,out}  & {\em adp} & Structure pointing to accelerations in momentum equation.\\
\hline
\mbox{\tt in,out}  & {\em cdp} & Structure pointing to terms in continuity equation.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
 & {\em cs} & Pointer to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 2178 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
2178   \textcolor{keywordtype}{type}(ocean\_internal\_state), \textcolor{keywordtype}{intent(in)}    :: mis\textcolor{comment}{ !< For "MOM Internal State" a set of pointers to}
2179 \textcolor{comment}{                                                   !! the fields and accelerations making up ocean}
2180 \textcolor{comment}{                                                   !! internal physical state.}
2181   \textcolor{keywordtype}{type}(accel\_diag\_ptrs),      \textcolor{keywordtype}{intent(inout)} :: adp\textcolor{comment}{ !< Structure pointing to accelerations in}
2182 \textcolor{comment}{                                                   !! momentum equation.}
2183   \textcolor{keywordtype}{type}(cont\_diag\_ptrs),       \textcolor{keywordtype}{intent(inout)} :: cdp\textcolor{comment}{ !< Structure pointing to terms in continuity}
2184 \textcolor{comment}{                                                   !! equation.}
2185   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{   !< The ocean's grid structure.}
2186   \textcolor{keywordtype}{type}(diagnostics\_cs),       \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{  !< Pointer to the control structure for this}
2187 \textcolor{comment}{                                                   !! module.}
2188 
2189 \textcolor{comment}{! This subroutine sets up diagnostics upon which other diagnostics depend.}
2190   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, isdb, iedb, jsdb, jedb, nz
2191   isd  = g%isd  ; ied  = g%ied  ; jsd  = g%jsd  ; jed  = g%jed ; nz = g%ke
2192   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
2193 
2194   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dKE\_dt) .or. \textcolor{keyword}{associated}(cs%PE\_to\_KE) .or. &
2195       \textcolor{keyword}{associated}(cs%KE\_CorAdv) .or. \textcolor{keyword}{associated}(cs%KE\_adv) .or. &
2196       \textcolor{keyword}{associated}(cs%KE\_visc) .or. \textcolor{keyword}{associated}(cs%KE\_horvisc) .or. &
2197       \textcolor{keyword}{associated}(cs%KE\_dia)) &
2198     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%KE,isd,ied,jsd,jed,nz)
2199 
2200   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%dKE\_dt)) \textcolor{keywordflow}{then}
2201     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%du\_dt)) \textcolor{keywordflow}{then}
2202       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%du\_dt,isdb,iedb,jsd,jed,nz)
2203       \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%u), mis%u, cs%du\_dt, cs)
2204 \textcolor{keywordflow}{    endif}
2205     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%dv\_dt)) \textcolor{keywordflow}{then}
2206       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%dv\_dt,isd,ied,jsdb,jedb,nz)
2207       \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%v), mis%v, cs%dv\_dt, cs)
2208 \textcolor{keywordflow}{    endif}
2209     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%dh\_dt)) \textcolor{keywordflow}{then}
2210       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%dh\_dt,isd,ied,jsd,jed,nz)
2211       \textcolor{keyword}{call }register\_time\_deriv(lbound(mis%h), mis%h, cs%dh\_dt, cs)
2212 \textcolor{keywordflow}{    endif}
2213 \textcolor{keywordflow}{  endif}
2214 
2215   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_adv)) \textcolor{keywordflow}{then}
2216     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%gradKEu,isdb,iedb,jsd,jed,nz)
2217     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%gradKEv,isd,ied,jsdb,jedb,nz)
2218 \textcolor{keywordflow}{  endif}
2219 
2220   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_visc)) \textcolor{keywordflow}{then}
2221     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%du\_dt\_visc,isdb,iedb,jsd,jed,nz)
2222     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%dv\_dt\_visc,isd,ied,jsdb,jedb,nz)
2223 \textcolor{keywordflow}{  endif}
2224 
2225   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%KE\_dia)) \textcolor{keywordflow}{then}
2226     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%du\_dt\_dia,isdb,iedb,jsd,jed,nz)
2227     \textcolor{keyword}{call }safe\_alloc\_ptr(adp%dv\_dt\_dia,isd,ied,jsdb,jedb,nz)
2228 \textcolor{keywordflow}{  endif}
2229 
2230   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%uhGM\_Rlay)) \textcolor{keyword}{call }safe\_alloc\_ptr(cdp%uhGM,isdb,iedb,jsd,jed,nz)
2231   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%vhGM\_Rlay)) \textcolor{keyword}{call }safe\_alloc\_ptr(cdp%vhGM,isd,ied,jsdb,jedb,nz)
2232 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diagnostics_af505e1356cf2f8172d27b60136b928e4}\label{namespacemom__diagnostics_af505e1356cf2f8172d27b60136b928e4}} 
\index{mom\+\_\+diagnostics@{mom\+\_\+diagnostics}!write\+\_\+static\+\_\+fields@{write\+\_\+static\+\_\+fields}}
\index{write\+\_\+static\+\_\+fields@{write\+\_\+static\+\_\+fields}!mom\+\_\+diagnostics@{mom\+\_\+diagnostics}}
\subsubsection{\texorpdfstring{write\+\_\+static\+\_\+fields()}{write\_static\_fields()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diagnostics\+::write\+\_\+static\+\_\+fields (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag }\end{DoxyParamCaption})}



Offers the static fields in the ocean grid type for output via the diag\+\_\+manager. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables\\
\hline
\mbox{\tt in,out}  & {\em diag} & regulates diagnostic output \\
\hline
\end{DoxyParams}


Definition at line 2004 of file M\+O\+M\+\_\+diagnostics.\+F90.


\begin{DoxyCode}
2004   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< ocean grid structure}
2005   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< ocean vertical grid structure}
2006   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
2007   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic variables}
2008   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< regulates diagnostic output}
2009 
2010   \textcolor{comment}{! Local variables}
2011   \textcolor{keywordtype}{integer} :: id
2012   \textcolor{keywordtype}{logical} :: use\_temperature
2013 
2014   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolat'}, diag%axesT1, &
2015         \textcolor{stringliteral}{'Latitude of tracer (T) points'}, \textcolor{stringliteral}{'degrees\_north'})
2016   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLatT, diag, .true.)
2017 
2018   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolon'}, diag%axesT1, &
2019         \textcolor{stringliteral}{'Longitude of tracer (T) points'}, \textcolor{stringliteral}{'degrees\_east'})
2020   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLonT, diag, .true.)
2021 
2022   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolat\_c'}, diag%axesB1, &
2023         \textcolor{stringliteral}{'Latitude of corner (Bu) points'}, \textcolor{stringliteral}{'degrees\_north'}, interp\_method=\textcolor{stringliteral}{'none'})
2024   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLatBu, diag, .true.)
2025 
2026   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolon\_c'}, diag%axesB1, &
2027         \textcolor{stringliteral}{'Longitude of corner (Bu) points'}, \textcolor{stringliteral}{'degrees\_east'}, interp\_method=\textcolor{stringliteral}{'none'})
2028   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLonBu, diag, .true.)
2029 
2030   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolat\_v'}, diag%axesCv1, &
2031         \textcolor{stringliteral}{'Latitude of meridional velocity (Cv) points'}, \textcolor{stringliteral}{'degrees\_north'}, interp\_method=\textcolor{stringliteral}{'none'})
2032   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLatCv, diag, .true.)
2033 
2034   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolon\_v'}, diag%axesCv1, &
2035         \textcolor{stringliteral}{'Longitude of meridional velocity (Cv) points'}, \textcolor{stringliteral}{'degrees\_east'}, interp\_method=\textcolor{stringliteral}{'none'})
2036   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLonCv, diag, .true.)
2037 
2038   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolat\_u'}, diag%axesCu1, &
2039         \textcolor{stringliteral}{'Latitude of zonal velocity (Cu) points'}, \textcolor{stringliteral}{'degrees\_north'}, interp\_method=\textcolor{stringliteral}{'none'})
2040   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLatCu, diag, .true.)
2041 
2042   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geolon\_u'}, diag%axesCu1, &
2043         \textcolor{stringliteral}{'Longitude of zonal velocity (Cu) points'}, \textcolor{stringliteral}{'degrees\_east'}, interp\_method=\textcolor{stringliteral}{'none'})
2044   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%geoLonCu, diag, .true.)
2045 
2046   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'area\_t'}, diag%axesT1, &
2047         \textcolor{stringliteral}{'Surface area of tracer (T) cells'}, \textcolor{stringliteral}{'m2'}, conversion=us%L\_to\_m**2, &
2048         cmor\_field\_name=\textcolor{stringliteral}{'areacello'}, cmor\_standard\_name=\textcolor{stringliteral}{'cell\_area'}, &
2049         cmor\_long\_name=\textcolor{stringliteral}{'Ocean Grid-Cell Area'}, &
2050         x\_cell\_method=\textcolor{stringliteral}{'sum'}, y\_cell\_method=\textcolor{stringliteral}{'sum'}, area\_cell\_method=\textcolor{stringliteral}{'sum'})
2051   \textcolor{keywordflow}{if} (id > 0) \textcolor{keywordflow}{then}
2052     \textcolor{keyword}{call }post\_data(id, g%areaT, diag, .true.)
2053     \textcolor{keyword}{call }diag\_register\_area\_ids(diag, id\_area\_t=id)
2054 \textcolor{keywordflow}{  endif}
2055 
2056   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'area\_u'}, diag%axesCu1, &
2057         \textcolor{stringliteral}{'Surface area of x-direction flow (U) cells'}, \textcolor{stringliteral}{'m2'}, conversion=us%L\_to\_m**2, &
2058         cmor\_field\_name=\textcolor{stringliteral}{'areacello\_cu'}, cmor\_standard\_name=\textcolor{stringliteral}{'cell\_area'}, &
2059         cmor\_long\_name=\textcolor{stringliteral}{'Ocean Grid-Cell Area'}, &
2060         x\_cell\_method=\textcolor{stringliteral}{'sum'}, y\_cell\_method=\textcolor{stringliteral}{'sum'}, area\_cell\_method=\textcolor{stringliteral}{'sum'})
2061   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%areaCu, diag, .true.)
2062 
2063   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'area\_v'}, diag%axesCv1, &
2064         \textcolor{stringliteral}{'Surface area of y-direction flow (V) cells'}, \textcolor{stringliteral}{'m2'}, conversion=us%L\_to\_m**2, &
2065         cmor\_field\_name=\textcolor{stringliteral}{'areacello\_cv'}, cmor\_standard\_name=\textcolor{stringliteral}{'cell\_area'}, &
2066         cmor\_long\_name=\textcolor{stringliteral}{'Ocean Grid-Cell Area'}, &
2067         x\_cell\_method=\textcolor{stringliteral}{'sum'}, y\_cell\_method=\textcolor{stringliteral}{'sum'}, area\_cell\_method=\textcolor{stringliteral}{'sum'})
2068   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%areaCv, diag, .true.)
2069 
2070   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'area\_q'}, diag%axesB1, &
2071         \textcolor{stringliteral}{'Surface area of B-grid flow (Q) cells'}, \textcolor{stringliteral}{'m2'}, conversion=us%L\_to\_m**2, &
2072         cmor\_field\_name=\textcolor{stringliteral}{'areacello\_bu'}, cmor\_standard\_name=\textcolor{stringliteral}{'cell\_area'}, &
2073         cmor\_long\_name=\textcolor{stringliteral}{'Ocean Grid-Cell Area'}, &
2074         x\_cell\_method=\textcolor{stringliteral}{'sum'}, y\_cell\_method=\textcolor{stringliteral}{'sum'}, area\_cell\_method=\textcolor{stringliteral}{'sum'})
2075   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%areaBu, diag, .true.)
2076 
2077   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'depth\_ocean'}, diag%axesT1,  &
2078         \textcolor{stringliteral}{'Depth of the ocean at tracer points'}, \textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m, &
2079         standard\_name=\textcolor{stringliteral}{'sea\_floor\_depth\_below\_geoid'},                     &
2080         cmor\_field\_name=\textcolor{stringliteral}{'deptho'}, cmor\_long\_name=\textcolor{stringliteral}{'Sea Floor Depth'},      &
2081         cmor\_standard\_name=\textcolor{stringliteral}{'sea\_floor\_depth\_below\_geoid'}, area=diag%axesT1%id\_area, &
2082         x\_cell\_method=\textcolor{stringliteral}{'mean'}, y\_cell\_method=\textcolor{stringliteral}{'mean'}, area\_cell\_method=\textcolor{stringliteral}{'mean'})
2083   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%bathyT, diag, .true., mask=g%mask2dT)
2084 
2085   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'wet'}, diag%axesT1, &
2086         \textcolor{stringliteral}{'0 if land, 1 if ocean at tracer points'}, \textcolor{stringliteral}{'none'}, area=diag%axesT1%id\_area)
2087   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%mask2dT, diag, .true.)
2088 
2089   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'wet\_c'}, diag%axesB1, &
2090         \textcolor{stringliteral}{'0 if land, 1 if ocean at corner (Bu) points'}, \textcolor{stringliteral}{'none'}, interp\_method=\textcolor{stringliteral}{'none'})
2091   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%mask2dBu, diag, .true.)
2092 
2093   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'wet\_u'}, diag%axesCu1, &
2094         \textcolor{stringliteral}{'0 if land, 1 if ocean at zonal velocity (Cu) points'}, \textcolor{stringliteral}{'none'}, interp\_method=\textcolor{stringliteral}{'none'})
2095   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%mask2dCu, diag, .true.)
2096 
2097   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'wet\_v'}, diag%axesCv1, &
2098         \textcolor{stringliteral}{'0 if land, 1 if ocean at meridional velocity (Cv) points'}, \textcolor{stringliteral}{'none'}, interp\_method=\textcolor{stringliteral}{'none'})
2099   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%mask2dCv, diag, .true.)
2100 
2101   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Coriolis'}, diag%axesB1, &
2102         \textcolor{stringliteral}{'Coriolis parameter at corner (Bu) points'}, \textcolor{stringliteral}{'s-1'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%s\_to\_T)
2103   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%CoriolisBu, diag, .true.)
2104 
2105   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dxt'}, diag%axesT1, &
2106         \textcolor{stringliteral}{'Delta(x) at thickness/tracer points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2107   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dxT, diag, .true.)
2108 
2109   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dyt'}, diag%axesT1, &
2110         \textcolor{stringliteral}{'Delta(y) at thickness/tracer points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2111   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dyT, diag, .true.)
2112 
2113   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dxCu'}, diag%axesCu1, &
2114         \textcolor{stringliteral}{'Delta(x) at u points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2115   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dxCu, diag, .true.)
2116 
2117   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dyCu'}, diag%axesCu1, &
2118         \textcolor{stringliteral}{'Delta(y) at u points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2119   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dyCu, diag, .true.)
2120 
2121   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dxCv'}, diag%axesCv1, &
2122         \textcolor{stringliteral}{'Delta(x) at v points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2123   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dxCv, diag, .true.)
2124 
2125   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dyCv'}, diag%axesCv1, &
2126         \textcolor{stringliteral}{'Delta(y) at v points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2127   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dyCv, diag, .true.)
2128 
2129   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dyCuo'}, diag%axesCu1, &
2130         \textcolor{stringliteral}{'Open meridional grid spacing at u points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m
      )
2131   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dy\_Cu, diag, .true.)
2132 
2133   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dxCvo'}, diag%axesCv1, &
2134         \textcolor{stringliteral}{'Open zonal grid spacing at v points (meter)'}, \textcolor{stringliteral}{'m'}, interp\_method=\textcolor{stringliteral}{'none'}, conversion=us%L\_to\_m)
2135   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%dx\_Cv, diag, .true.)
2136 
2137   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'sin\_rot'}, diag%axesT1, &
2138         \textcolor{stringliteral}{'sine of the clockwise angle of the ocean grid north to true north'}, \textcolor{stringliteral}{'none'})
2139   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%sin\_rot, diag, .true.)
2140 
2141   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'cos\_rot'}, diag%axesT1, &
2142         \textcolor{stringliteral}{'cosine of the clockwise angle of the ocean grid north to true north'}, \textcolor{stringliteral}{'none'})
2143   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%cos\_rot, diag, .true.)
2144 
2145 
2146   \textcolor{comment}{! This static diagnostic is from CF 1.8, and is the fraction of a cell}
2147   \textcolor{comment}{! covered by ocean, given as a percentage (poorly named).}
2148   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'area\_t\_percent'}, diag%axesT1, &
2149         \textcolor{stringliteral}{'Percentage of cell area covered by ocean'}, \textcolor{stringliteral}{'%'}, conversion=100.0, &
2150         cmor\_field\_name=\textcolor{stringliteral}{'sftof'}, cmor\_standard\_name=\textcolor{stringliteral}{'SeaAreaFraction'}, &
2151         cmor\_long\_name=\textcolor{stringliteral}{'Sea Area Fraction'}, &
2152         x\_cell\_method=\textcolor{stringliteral}{'mean'}, y\_cell\_method=\textcolor{stringliteral}{'mean'}, area\_cell\_method=\textcolor{stringliteral}{'mean'})
2153   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, g%mask2dT, diag, .true.)
2154 
2155 
2156   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Rho\_0'}, diag%axesNull, &
2157        \textcolor{stringliteral}{'mean ocean density used with the Boussinesq approximation'}, &
2158        \textcolor{stringliteral}{'kg m-3'}, conversion=us%R\_to\_kg\_m3, cmor\_field\_name=\textcolor{stringliteral}{'rhozero'}, &
2159        cmor\_standard\_name=\textcolor{stringliteral}{'reference\_sea\_water\_density\_for\_boussinesq\_approximation'}, &
2160        cmor\_long\_name=\textcolor{stringliteral}{'reference sea water density for boussinesq approximation'})
2161   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, gv%Rho0, diag, .true.)
2162 
2163   use\_temperature = \textcolor{keyword}{associated}(tv%T)
2164   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
2165     id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'C\_p'}, diag%axesNull, &
2166          \textcolor{stringliteral}{'heat capacity of sea water'}, \textcolor{stringliteral}{'J kg-1 K-1'}, conversion=us%Q\_to\_J\_kg, &
2167          cmor\_field\_name=\textcolor{stringliteral}{'cpocean'}, &
2168          cmor\_standard\_name=\textcolor{stringliteral}{'specific\_heat\_capacity\_of\_sea\_water'}, &
2169          cmor\_long\_name=\textcolor{stringliteral}{'specific\_heat\_capacity\_of\_sea\_water'})
2170     \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, tv%C\_p, diag, .true.)
2171 \textcolor{keywordflow}{  endif}
2172 
\end{DoxyCode}
