\hypertarget{namespacemom__sum__output}{}\section{mom\+\_\+sum\+\_\+output Module Reference}
\label{namespacemom__sum__output}\index{mom\_sum\_output@{mom\_sum\_output}}


\subsection{Detailed Description}
Reports integrated quantities for monitoring the model state. 

By Robert Hallberg, April 1994 -\/ June 2002.

This file contains the subroutine (write\+\_\+energy) that writes horizontally integrated quantities, such as energies and layer volumes, and other summary information to an output file. Some of these quantities (A\+PE or resting interface height) are defined relative to the global histogram of topography. The subroutine that compiles that histogram (depth\+\_\+list\+\_\+setup) is also included in this file.

In addition, if the number of velocity truncations since the previous call to write\+\_\+energy exceeds maxtrunc or the total energy exceeds a very large threshold, a fatal termination is triggered. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__sum__output_1_1depth__list}{depth\+\_\+list}}
\begin{DoxyCompactList}\small\item\em A list of depths and corresponding globally integrated ocean area at each depth and the ocean volume below each depth. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the M\+O\+M\+\_\+sum\+\_\+output module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__sum__output_a05003e74cbb39fbdf760d23617390445}{mom\+\_\+sum\+\_\+output\+\_\+init}} (G, US, param\+\_\+file, directory, ntrnc, Input\+\_\+start\+\_\+time, CS)
\begin{DoxyCompactList}\small\item\em M\+O\+M\+\_\+sum\+\_\+output\+\_\+init initializes the parameters and settings for the M\+O\+M\+\_\+sum\+\_\+output module. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__sum__output_ae54994f461b38198510274dadbce8fb5}{mom\+\_\+sum\+\_\+output\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em M\+O\+M\+\_\+sum\+\_\+output\+\_\+end deallocates memory used by the M\+O\+M\+\_\+sum\+\_\+output module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__sum__output_ad3cc692dd515100ec8cf92d740c91e72}{write\+\_\+energy}} (u, v, h, tv, day, n, G, GV, US, CS, tracer\+\_\+\+C\+Sp, O\+BC, dt\+\_\+forcing)
\begin{DoxyCompactList}\small\item\em This subroutine calculates and writes the total model energy, the energy and mass of each layer, and other globally integrated physical quantities. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__sum__output_a773833f7ac86b8b65b0e6e8f91f05ec4}{accumulate\+\_\+net\+\_\+input}} (fluxes, sfc\+\_\+state, tv, dt, G, US, CS)
\begin{DoxyCompactList}\small\item\em This subroutine accumates the net input of volume, salt and heat, through the ocean surface for use in diagnosing conservation. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__sum__output_a53d3dcd50cba41760dd8713228785a8d}{depth\+\_\+list\+\_\+setup}} (G, US, CS)
\begin{DoxyCompactList}\small\item\em This subroutine sets up an ordered list of depths, along with the cross sectional areas at each depth and the volume of fluid deeper than each depth. This might be read from a previously created file or it might be created anew. (For now only new creation occurs. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__sum__output_a1db5001777c2171a7f3f16122b4bacd1}{create\+\_\+depth\+\_\+list}} (G, CS)
\begin{DoxyCompactList}\small\item\em create\+\_\+depth\+\_\+list makes an ordered list of depths, along with the cross sectional areas at each depth and the volume of fluid deeper than each depth. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__sum__output_a955e777980a668bfc611c78de5de1895}{write\+\_\+depth\+\_\+list}} (G, US, CS, filename, list\+\_\+size)
\begin{DoxyCompactList}\small\item\em This subroutine writes out the depth list to the specified file. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__sum__output_a4f45b1c7dbff4fe064e102ccb2967daf}{read\+\_\+depth\+\_\+list}} (G, US, CS, filename)
\begin{DoxyCompactList}\small\item\em This subroutine reads in the depth list to the specified file and allocates and sets up CSDL and CSlist\+\_\+size . \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__sum__output_a928dd1160bb6c0033a417c618b9d01ef}{get\+\_\+depth\+\_\+list\+\_\+checksums}} (G, depth\+\_\+chksum, area\+\_\+chksum)
\begin{DoxyCompactList}\small\item\em Return the checksums required to verify D\+E\+P\+T\+H\+\_\+\+L\+I\+S\+T\+\_\+\+F\+I\+LE contents. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__sum__output_a5191c3198dcd24f50da9279ce7ebbc60}\label{namespacemom__sum__output_a5191c3198dcd24f50da9279ce7ebbc60}} 
integer, parameter \mbox{\hyperlink{namespacemom__sum__output_a5191c3198dcd24f50da9279ce7ebbc60}{num\+\_\+fields}} = 17
\begin{DoxyCompactList}\small\item\em Number of diagnostic fields. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__sum__output_a4502602fe6c41088fc5a7f658070b386}\label{namespacemom__sum__output_a4502602fe6c41088fc5a7f658070b386}} 
character($\ast$), parameter \mbox{\hyperlink{namespacemom__sum__output_a4502602fe6c41088fc5a7f658070b386}{depth\+\_\+chksum\+\_\+attr}} = \char`\"{}bathy\+T\+\_\+checksum\char`\"{}
\begin{DoxyCompactList}\small\item\em Checksum attribute name of GbathyT over the compute domain. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__sum__output_af8db0fa8cff32727c5f23cc328b67a7c}\label{namespacemom__sum__output_af8db0fa8cff32727c5f23cc328b67a7c}} 
character($\ast$), parameter \mbox{\hyperlink{namespacemom__sum__output_af8db0fa8cff32727c5f23cc328b67a7c}{area\+\_\+chksum\+\_\+attr}} = \char`\"{}mask2d\+T\+\_\+area\+T\+\_\+checksum\char`\"{}
\begin{DoxyCompactList}\small\item\em Checksum attribute of name of Gmask2dT $\ast$ GareaT over the compute domain. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__sum__output_a773833f7ac86b8b65b0e6e8f91f05ec4}\label{namespacemom__sum__output_a773833f7ac86b8b65b0e6e8f91f05ec4}} 
\index{mom\_sum\_output@{mom\_sum\_output}!accumulate\_net\_input@{accumulate\_net\_input}}
\index{accumulate\_net\_input@{accumulate\_net\_input}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{accumulate\_net\_input()}{accumulate\_net\_input()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sum\+\_\+output\+::accumulate\+\_\+net\+\_\+input (\begin{DoxyParamCaption}\item[{type(forcing), intent(in)}]{fluxes,  }\item[{type(surface), intent(in)}]{sfc\+\_\+state,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine accumates the net input of volume, salt and heat, through the ocean surface for use in diagnosing conservation. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em fluxes} & A structure containing pointers to any possible forcing fields. Unused fields are unallocated. \\
\hline
\mbox{\texttt{ in}}  & {\em sfc\+\_\+state} & A structure containing fields that describe the surface state of the ocean. \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & The amount of time over which to average \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to M\+O\+M\+\_\+sum\+\_\+output\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 953 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{953   \textcolor{keywordtype}{type}(forcing),         \textcolor{keywordtype}{intent(in)} :: fluxes\textcolor{comment}{ !< A structure containing pointers to any possible}}
\DoxyCodeLine{954 \textcolor{comment}{                                              !! forcing fields.  Unused fields are unallocated.}}
\DoxyCodeLine{955   \textcolor{keywordtype}{type}(surface),         \textcolor{keywordtype}{intent(in)} :: sfc\_state\textcolor{comment}{ !< A structure containing fields that}}
\DoxyCodeLine{956 \textcolor{comment}{                                              !! describe the surface state of the ocean.}}
\DoxyCodeLine{957   \textcolor{keywordtype}{type}(thermo\_var\_ptrs), \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{     !< A structure pointing to various}}
\DoxyCodeLine{958 \textcolor{comment}{                                              !! thermodynamic variables.}}
\DoxyCodeLine{959 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)} :: dt\textcolor{comment}{     !< The amount of time over which to average [T ~> s].}}
\DoxyCodeLine{960   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{      !< The ocean's grid structure.}}
\DoxyCodeLine{961   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{962   \textcolor{keywordtype}{type}(Sum\_output\_CS),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{     !< The control structure returned by a previous call}}
\DoxyCodeLine{963 \textcolor{comment}{                                              !! to MOM\_sum\_output\_init.}}
\DoxyCodeLine{964   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{965 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{966     FW\_in, \&   \textcolor{comment}{! The net fresh water input, integrated over a timestep [kg].}}
\DoxyCodeLine{967     salt\_in, \& \textcolor{comment}{! The total salt added by surface fluxes, integrated}}
\DoxyCodeLine{968                \textcolor{comment}{! over a time step [ppt kg].}}
\DoxyCodeLine{969     heat\_in    \textcolor{comment}{! The total heat added by surface fluxes, integrated}}
\DoxyCodeLine{970                \textcolor{comment}{! over a time step [J].}}
\DoxyCodeLine{971 \textcolor{keywordtype}{  real} :: FW\_input   \textcolor{comment}{! The net fresh water input, integrated over a timestep}}
\DoxyCodeLine{972                      \textcolor{comment}{! and summed over space [kg].}}
\DoxyCodeLine{973 \textcolor{keywordtype}{  real} :: salt\_input \textcolor{comment}{! The total salt added by surface fluxes, integrated}}
\DoxyCodeLine{974                      \textcolor{comment}{! over a time step and summed over space [ppt kg].}}
\DoxyCodeLine{975 \textcolor{keywordtype}{  real} :: heat\_input \textcolor{comment}{! The total heat added by boundary fluxes, integrated}}
\DoxyCodeLine{976                      \textcolor{comment}{! over a time step and summed over space [J].}}
\DoxyCodeLine{977 \textcolor{keywordtype}{  real} :: RZL2\_to\_kg \textcolor{comment}{! A combination of scaling factors for mass [kg R-1 Z-1 L-2 ~> 1]}}
\DoxyCodeLine{978 \textcolor{keywordtype}{  real} :: QRZL2\_to\_J \textcolor{comment}{! A combination of scaling factors for heat [J Q-1 R-1 Z-1 L-2 ~> 1]}}
\DoxyCodeLine{979 }
\DoxyCodeLine{980   \textcolor{keywordtype}{type}(EFP\_type) :: \&}
\DoxyCodeLine{981     FW\_in\_EFP,   \&   \textcolor{comment}{! The net fresh water input, integrated over a timestep}}
\DoxyCodeLine{982                      \textcolor{comment}{! and summed over space [kg].}}
\DoxyCodeLine{983     salt\_in\_efp, \&   \textcolor{comment}{! The total salt added by surface fluxes, integrated}}
\DoxyCodeLine{984                      \textcolor{comment}{! over a time step and summed over space [ppt kg].}}
\DoxyCodeLine{985     heat\_in\_efp      \textcolor{comment}{! The total heat added by boundary fluxes, integrated}}
\DoxyCodeLine{986                      \textcolor{comment}{! over a time step and summed over space [J].}}
\DoxyCodeLine{987 }
\DoxyCodeLine{988 \textcolor{keywordtype}{  real} :: inputs(3)   \textcolor{comment}{! A mixed array for combining the sums}}
\DoxyCodeLine{989   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, isr, ier, jsr, jer}
\DoxyCodeLine{990 }
\DoxyCodeLine{991   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{992 }
\DoxyCodeLine{993   rzl2\_to\_kg = us\%L\_to\_m**2*us\%RZ\_to\_kg\_m2}
\DoxyCodeLine{994   qrzl2\_to\_j = rzl2\_to\_kg*us\%Q\_to\_J\_kg}
\DoxyCodeLine{995 }
\DoxyCodeLine{996   fw\_in(:,:) = 0.0}
\DoxyCodeLine{997   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%evap)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{998     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%lprec) .and. \textcolor{keyword}{associated}(fluxes\%fprec)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{999       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1000         fw\_in(i,j) = rzl2\_to\_kg * dt*g\%areaT(i,j)*(fluxes\%evap(i,j) + \&}
\DoxyCodeLine{1001             (((fluxes\%lprec(i,j) + fluxes\%vprec(i,j)) + fluxes\%lrunoff(i,j)) + \&}
\DoxyCodeLine{1002               (fluxes\%fprec(i,j) + fluxes\%frunoff(i,j))))}
\DoxyCodeLine{1003 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1004     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1005       \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1006         \textcolor{stringliteral}{"accumulate\_net\_input called with associated evap field, but no precip field."})}
\DoxyCodeLine{1007 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1008 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1009 }
\DoxyCodeLine{1010   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%seaice\_melt)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1011     fw\_in(i,j) = fw\_in(i,j) + rzl2\_to\_kg*dt * \&}
\DoxyCodeLine{1012                  g\%areaT(i,j) * fluxes\%seaice\_melt(i,j)}
\DoxyCodeLine{1013 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1014 }
\DoxyCodeLine{1015   salt\_in(:,:) = 0.0 ; heat\_in(:,:) = 0.0}
\DoxyCodeLine{1016   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1017 }
\DoxyCodeLine{1018     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%sw)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1019       heat\_in(i,j) = heat\_in(i,j) + dt * qrzl2\_to\_j * g\%areaT(i,j) * (fluxes\%sw(i,j) + \&}
\DoxyCodeLine{1020              (fluxes\%lw(i,j) + (fluxes\%latent(i,j) + fluxes\%sens(i,j))))}
\DoxyCodeLine{1021 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1022 }
\DoxyCodeLine{1023     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%seaice\_melt\_heat)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1024        heat\_in(i,j) = heat\_in(i,j) + dt * qrzl2\_to\_j * g\%areaT(i,j) * \&}
\DoxyCodeLine{1025                                      fluxes\%seaice\_melt\_heat(i,j)}
\DoxyCodeLine{1026 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1027 }
\DoxyCodeLine{1028     \textcolor{comment}{! smg: new code}}
\DoxyCodeLine{1029     \textcolor{comment}{! include heat content from water transport across ocean surface}}
\DoxyCodeLine{1030 \textcolor{comment}{!    if (associated(fluxes\%heat\_content\_lprec)) then ; do j=js,je ; do i=is,ie}}
\DoxyCodeLine{1031 \textcolor{comment}{!      heat\_in(i,j) = heat\_in(i,j) + dt * QRZL2\_to\_J * G\%areaT(i,j) * \&}}
\DoxyCodeLine{1032 \textcolor{comment}{!         (fluxes\%heat\_content\_lprec(i,j)   + (fluxes\%heat\_content\_fprec(i,j)   \&}}
\DoxyCodeLine{1033 \textcolor{comment}{!       + (fluxes\%heat\_content\_lrunoff(i,j) + (fluxes\%heat\_content\_frunoff(i,j) \&}}
\DoxyCodeLine{1034 \textcolor{comment}{!       + (fluxes\%heat\_content\_cond(i,j)    + (fluxes\%heat\_content\_vprec(i,j)   \&}}
\DoxyCodeLine{1035 \textcolor{comment}{!       +  fluxes\%heat\_content\_massout(i,j)))))))}}
\DoxyCodeLine{1036 \textcolor{comment}{!    enddo ; enddo ; endif}}
\DoxyCodeLine{1037 }
\DoxyCodeLine{1038     \textcolor{comment}{! smg: old code}}
\DoxyCodeLine{1039     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%TempxPmE)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1040       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1041         heat\_in(i,j) = heat\_in(i,j) + (fluxes\%C\_p * qrzl2\_to\_j*g\%areaT(i,j)) * tv\%TempxPmE(i,j)}
\DoxyCodeLine{1042 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1043     \textcolor{keywordflow}{elseif} (\textcolor{keyword}{associated}(fluxes\%evap)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1044       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1045         heat\_in(i,j) = heat\_in(i,j) + (us\%Q\_to\_J\_kg*fluxes\%C\_p * sfc\_state\%SST(i,j)) * fw\_in(i,j)}
\DoxyCodeLine{1046 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1047 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1048 }
\DoxyCodeLine{1049     \textcolor{comment}{! The following heat sources may or may not be used.}}
\DoxyCodeLine{1050     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%internal\_heat)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1051       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1052         heat\_in(i,j) = heat\_in(i,j) + (fluxes\%C\_p * qrzl2\_to\_j*g\%areaT(i,j)) * tv\%internal\_heat(i,j)}
\DoxyCodeLine{1053 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1054 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1055     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%frazil)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1056       heat\_in(i,j) = heat\_in(i,j) + qrzl2\_to\_j * g\%areaT(i,j) * tv\%frazil(i,j)}
\DoxyCodeLine{1057 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1058     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%heat\_added)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1059       heat\_in(i,j) = heat\_in(i,j) + qrzl2\_to\_j * dt*g\%areaT(i,j) * fluxes\%heat\_added(i,j)}
\DoxyCodeLine{1060 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1061 \textcolor{comment}{!    if (associated(sfc\_state\%sw\_lost)) then ; do j=js,je ; do i=is,ie}}
\DoxyCodeLine{1062 \textcolor{comment}{!      heat\_in(i,j) = heat\_in(i,j) - US\%L\_to\_m**2*G\%areaT(i,j) * sfc\_state\%sw\_lost(i,j)}}
\DoxyCodeLine{1063 \textcolor{comment}{!    enddo ; enddo ; endif}}
\DoxyCodeLine{1064 }
\DoxyCodeLine{1065     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%salt\_flux)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1066       \textcolor{comment}{! convert salt\_flux from kg (salt)/(m\string^2 s) to ppt * [m s-1].}}
\DoxyCodeLine{1067       salt\_in(i,j) = rzl2\_to\_kg * dt * \&}
\DoxyCodeLine{1068                      g\%areaT(i,j)*(1000.0*fluxes\%salt\_flux(i,j))}
\DoxyCodeLine{1069 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1070 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1071 }
\DoxyCodeLine{1072   \textcolor{keywordflow}{if} ((cs\%use\_temperature) .or. \textcolor{keyword}{associated}(fluxes\%lprec) .or. \&}
\DoxyCodeLine{1073       \textcolor{keyword}{associated}(fluxes\%evap)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1074     \textcolor{comment}{! The on-PE sums are stored here, but the sums across PEs are deferred to}}
\DoxyCodeLine{1075     \textcolor{comment}{! the next call to write\_energy to avoid extra barriers.}}
\DoxyCodeLine{1076     isr = is - (g\%isd-1) ; ier = ie - (g\%isd-1) ; jsr = js - (g\%jsd-1) ; jer = je - (g\%jsd-1)}
\DoxyCodeLine{1077     fw\_in\_efp   = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}(fw\_in,   isr, ier, jsr, jer, only\_on\_pe=.true.)}
\DoxyCodeLine{1078     heat\_in\_efp = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}(heat\_in, isr, ier, jsr, jer, only\_on\_pe=.true.)}
\DoxyCodeLine{1079     salt\_in\_efp = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}(salt\_in, isr, ier, jsr, jer, only\_on\_pe=.true.)}
\DoxyCodeLine{1080 }
\DoxyCodeLine{1081     cs\%fresh\_water\_in\_EFP = cs\%fresh\_water\_in\_EFP + fw\_in\_efp}
\DoxyCodeLine{1082     cs\%net\_salt\_in\_EFP    = cs\%net\_salt\_in\_EFP    + salt\_in\_efp}
\DoxyCodeLine{1083     cs\%net\_heat\_in\_EFP    = cs\%net\_heat\_in\_EFP    + heat\_in\_efp}
\DoxyCodeLine{1084 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1085 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_a1db5001777c2171a7f3f16122b4bacd1}\label{namespacemom__sum__output_a1db5001777c2171a7f3f16122b4bacd1}} 
\index{mom\_sum\_output@{mom\_sum\_output}!create\_depth\_list@{create\_depth\_list}}
\index{create\_depth\_list@{create\_depth\_list}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{create\_depth\_list()}{create\_depth\_list()}}
{\footnotesize\ttfamily subroutine mom\+\_\+sum\+\_\+output\+::create\+\_\+depth\+\_\+list (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



create\+\_\+depth\+\_\+list makes an ordered list of depths, along with the cross sectional areas at each depth and the volume of fluid deeper than each depth. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
 & {\em cs} & The control structure set up in M\+O\+M\+\_\+sum\+\_\+output\+\_\+init, in which the ordered depth list is stored. \\
\hline
\end{DoxyParams}


Definition at line 1123 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1123   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{1124   \textcolor{keywordtype}{type}(Sum\_output\_CS),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure set up in MOM\_sum\_output\_init,}}
\DoxyCodeLine{1125 \textcolor{comment}{                                          !! in which the ordered depth list is stored.}}
\DoxyCodeLine{1126   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1127 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%Domain\%niglobal*G\%Domain\%njglobal + 1)} :: \&}
\DoxyCodeLine{1128     Dlist, \&  !< The global list of bottom depths [Z ~> m].}
\DoxyCodeLine{1129     AreaList\textcolor{comment}{  !< The global list of cell areas [L2 ~> m2].}}
\DoxyCodeLine{1130   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(G\%Domain\%niglobal*G\%Domain\%njglobal+1)} :: \&}
\DoxyCodeLine{1131     indx2\textcolor{comment}{     !< The position of an element in the original unsorted list.}}
\DoxyCodeLine{1132 \textcolor{keywordtype}{  real}    :: Dnow\textcolor{comment}{  !< The depth now being considered for sorting [Z ~> m].}}
\DoxyCodeLine{1133 \textcolor{keywordtype}{  real}    :: Dprev\textcolor{comment}{ !< The most recent depth that was considered [Z ~> m].}}
\DoxyCodeLine{1134 \textcolor{keywordtype}{  real}    :: vol\textcolor{comment}{   !< The running sum of open volume below a deptn [Z L2 ~> m3].}}
\DoxyCodeLine{1135 \textcolor{keywordtype}{  real}    :: area\textcolor{comment}{  !< The open area at the current depth [L2 ~> m2].}}
\DoxyCodeLine{1136 \textcolor{keywordtype}{  real}    :: D\_list\_prev\textcolor{comment}{ !< The most recent depth added to the list [Z ~> m].}}
\DoxyCodeLine{1137   \textcolor{keywordtype}{logical} :: add\_to\_list\textcolor{comment}{ !< This depth should be included as an entry on the list.}}
\DoxyCodeLine{1138 }
\DoxyCodeLine{1139   \textcolor{keywordtype}{integer} :: ir, indxt}
\DoxyCodeLine{1140   \textcolor{keywordtype}{integer} :: mls, list\_size}
\DoxyCodeLine{1141   \textcolor{keywordtype}{integer} :: list\_pos, i\_global, j\_global}
\DoxyCodeLine{1142   \textcolor{keywordtype}{integer} :: i, j, k, kl}
\DoxyCodeLine{1143 }
\DoxyCodeLine{1144   mls = g\%Domain\%niglobal*g\%Domain\%njglobal}
\DoxyCodeLine{1145 }
\DoxyCodeLine{1146 \textcolor{comment}{! Need to collect the global data from compute domains to a 1D array for sorting.}}
\DoxyCodeLine{1147   dlist(:) = 0.0}
\DoxyCodeLine{1148   arealist(:) = 0.0}
\DoxyCodeLine{1149   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{1150     \textcolor{comment}{! Set global indices that start the global domain at 1 (Fortran convention).}}
\DoxyCodeLine{1151     j\_global = j + g\%jdg\_offset - (g\%jsg-1)}
\DoxyCodeLine{1152     i\_global = i + g\%idg\_offset - (g\%isg-1)}
\DoxyCodeLine{1153 }
\DoxyCodeLine{1154     list\_pos = (j\_global-1)*g\%Domain\%niglobal + i\_global}
\DoxyCodeLine{1155     dlist(list\_pos) = g\%bathyT(i,j)}
\DoxyCodeLine{1156     arealist(list\_pos) = g\%mask2dT(i,j) * g\%areaT(i,j)}
\DoxyCodeLine{1157 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1158 }
\DoxyCodeLine{1159   \textcolor{comment}{! These sums reproduce across PEs because the arrays are only nonzero on one PE.}}
\DoxyCodeLine{1160   \textcolor{keyword}{call }sum\_across\_pes(dlist, mls+1)}
\DoxyCodeLine{1161   \textcolor{keyword}{call }sum\_across\_pes(arealist, mls+1)}
\DoxyCodeLine{1162 }
\DoxyCodeLine{1163   \textcolor{keywordflow}{do} j=1,mls+1 ; indx2(j) = j ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1164   k = mls / 2  + 1 ; ir = mls}
\DoxyCodeLine{1165   \textcolor{keywordflow}{do}}
\DoxyCodeLine{1166     \textcolor{keywordflow}{if} (k > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1167       k = k - 1}
\DoxyCodeLine{1168       indxt = indx2(k)}
\DoxyCodeLine{1169       dnow = dlist(indxt)}
\DoxyCodeLine{1170     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1171       indxt = indx2(ir)}
\DoxyCodeLine{1172       dnow = dlist(indxt)}
\DoxyCodeLine{1173       indx2(ir) = indx2(1)}
\DoxyCodeLine{1174       ir = ir - 1}
\DoxyCodeLine{1175       \textcolor{keywordflow}{if} (ir == 1) \textcolor{keywordflow}{then} ; indx2(1) = indxt ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1176 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1177     i=k ; j=k*2}
\DoxyCodeLine{1178     \textcolor{keywordflow}{do} ; \textcolor{keywordflow}{if} (j > ir) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1179       \textcolor{keywordflow}{if} (j < ir .AND. dlist(indx2(j)) < dlist(indx2(j+1))) j = j + 1}
\DoxyCodeLine{1180       \textcolor{keywordflow}{if} (dnow < dlist(indx2(j))) \textcolor{keywordflow}{then} ; indx2(i) = indx2(j) ; i = j ; j = j + i}
\DoxyCodeLine{1181       \textcolor{keywordflow}{else} ; j = ir+1 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1182 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1183     indx2(i) = indxt}
\DoxyCodeLine{1184 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1185 }
\DoxyCodeLine{1186 \textcolor{comment}{!  At this point, the lists should perhaps be culled to save memory.}}
\DoxyCodeLine{1187 \textcolor{comment}{! Culling: (1) identical depths (e.g. land) - take the last one.}}
\DoxyCodeLine{1188 \textcolor{comment}{!          (2) the topmost and bottommost depths are always saved.}}
\DoxyCodeLine{1189 \textcolor{comment}{!          (3) very close depths}}
\DoxyCodeLine{1190 \textcolor{comment}{!          (4) equal volume changes.}}
\DoxyCodeLine{1191 }
\DoxyCodeLine{1192   \textcolor{comment}{! Count the unique elements in the list.}}
\DoxyCodeLine{1193   d\_list\_prev = dlist(indx2(mls))}
\DoxyCodeLine{1194   list\_size = 2}
\DoxyCodeLine{1195   \textcolor{keywordflow}{do} k=mls-1,1,-1}
\DoxyCodeLine{1196     \textcolor{keywordflow}{if} (dlist(indx2(k)) < d\_list\_prev-cs\%D\_list\_min\_inc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1197       list\_size = list\_size + 1}
\DoxyCodeLine{1198       d\_list\_prev = dlist(indx2(k))}
\DoxyCodeLine{1199 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1200 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1201 }
\DoxyCodeLine{1202   cs\%list\_size = list\_size}
\DoxyCodeLine{1203   \textcolor{keyword}{allocate}(cs\%DL(cs\%list\_size+1))}
\DoxyCodeLine{1204 }
\DoxyCodeLine{1205   vol = 0.0 ; area = 0.0}
\DoxyCodeLine{1206   dprev = dlist(indx2(mls))}
\DoxyCodeLine{1207   d\_list\_prev = dprev}
\DoxyCodeLine{1208 }
\DoxyCodeLine{1209   kl = 0}
\DoxyCodeLine{1210   \textcolor{keywordflow}{do} k=mls,1,-1}
\DoxyCodeLine{1211     i = indx2(k)}
\DoxyCodeLine{1212     vol = vol + area * (dprev - dlist(i))}
\DoxyCodeLine{1213     area = area + arealist(i)}
\DoxyCodeLine{1214 }
\DoxyCodeLine{1215     add\_to\_list = .false.}
\DoxyCodeLine{1216     \textcolor{keywordflow}{if} ((kl == 0) .or. (k==1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1217       add\_to\_list = .true.}
\DoxyCodeLine{1218     \textcolor{keywordflow}{elseif} (dlist(indx2(k-1)) < d\_list\_prev-cs\%D\_list\_min\_inc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1219       add\_to\_list = .true.}
\DoxyCodeLine{1220       d\_list\_prev = dlist(indx2(k-1))}
\DoxyCodeLine{1221 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1222 }
\DoxyCodeLine{1223     \textcolor{keywordflow}{if} (add\_to\_list) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1224       kl = kl+1}
\DoxyCodeLine{1225       cs\%DL(kl)\%depth = dlist(i)}
\DoxyCodeLine{1226       cs\%DL(kl)\%area = area}
\DoxyCodeLine{1227       cs\%DL(kl)\%vol\_below = vol}
\DoxyCodeLine{1228 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1229     dprev = dlist(i)}
\DoxyCodeLine{1230 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1231 }
\DoxyCodeLine{1232   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (kl < list\_size)}
\DoxyCodeLine{1233     \textcolor{comment}{! I don't understand why this is needed... RWH}}
\DoxyCodeLine{1234     kl = kl+1}
\DoxyCodeLine{1235     cs\%DL(kl)\%vol\_below = cs\%DL(kl-1)\%vol\_below * 1.000001}
\DoxyCodeLine{1236     cs\%DL(kl)\%area = cs\%DL(kl-1)\%area}
\DoxyCodeLine{1237     cs\%DL(kl)\%depth = cs\%DL(kl-1)\%depth}
\DoxyCodeLine{1238 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1239 }
\DoxyCodeLine{1240   cs\%DL(cs\%list\_size+1)\%vol\_below = cs\%DL(cs\%list\_size)\%vol\_below * 1000.0}
\DoxyCodeLine{1241   cs\%DL(cs\%list\_size+1)\%area = cs\%DL(cs\%list\_size)\%area}
\DoxyCodeLine{1242   cs\%DL(cs\%list\_size+1)\%depth = cs\%DL(cs\%list\_size)\%depth}
\DoxyCodeLine{1243 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_a53d3dcd50cba41760dd8713228785a8d}\label{namespacemom__sum__output_a53d3dcd50cba41760dd8713228785a8d}} 
\index{mom\_sum\_output@{mom\_sum\_output}!depth\_list\_setup@{depth\_list\_setup}}
\index{depth\_list\_setup@{depth\_list\_setup}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{depth\_list\_setup()}{depth\_list\_setup()}}
{\footnotesize\ttfamily subroutine mom\+\_\+sum\+\_\+output\+::depth\+\_\+list\+\_\+setup (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets up an ordered list of depths, along with the cross sectional areas at each depth and the volume of fluid deeper than each depth. This might be read from a previously created file or it might be created anew. (For now only new creation occurs. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to M\+O\+M\+\_\+sum\+\_\+output\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 1093 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1093   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{   !< The ocean's grid structure}}
\DoxyCodeLine{1094   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{1095   \textcolor{keywordtype}{type}(Sum\_output\_CS),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{  !< The control structure returned by a}}
\DoxyCodeLine{1096 \textcolor{comment}{                                           !! previous call to MOM\_sum\_output\_init.}}
\DoxyCodeLine{1097   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1098   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1099 }
\DoxyCodeLine{1100   \textcolor{keywordflow}{if} (cs\%read\_depth\_list) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1101     \textcolor{keywordflow}{if} (file\_exists(cs\%depth\_list\_file)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1102       \textcolor{keyword}{call }read\_depth\_list(g, us, cs, cs\%depth\_list\_file)}
\DoxyCodeLine{1103     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1104       \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"depth\_list\_setup: "}// \&}
\DoxyCodeLine{1105         trim(cs\%depth\_list\_file)//\textcolor{stringliteral}{" does not exist.  Creating a new file."})}
\DoxyCodeLine{1106       \textcolor{keyword}{call }create\_depth\_list(g, cs)}
\DoxyCodeLine{1107 }
\DoxyCodeLine{1108       \textcolor{keyword}{call }write\_depth\_list(g, us, cs, cs\%depth\_list\_file, cs\%list\_size+1)}
\DoxyCodeLine{1109 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1110   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1111     \textcolor{keyword}{call }create\_depth\_list(g, cs)}
\DoxyCodeLine{1112 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1113 }
\DoxyCodeLine{1114   \textcolor{keywordflow}{do} k=1,g\%ke}
\DoxyCodeLine{1115     cs\%lH(k) = cs\%list\_size}
\DoxyCodeLine{1116 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1117 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_a928dd1160bb6c0033a417c618b9d01ef}\label{namespacemom__sum__output_a928dd1160bb6c0033a417c618b9d01ef}} 
\index{mom\_sum\_output@{mom\_sum\_output}!get\_depth\_list\_checksums@{get\_depth\_list\_checksums}}
\index{get\_depth\_list\_checksums@{get\_depth\_list\_checksums}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{get\_depth\_list\_checksums()}{get\_depth\_list\_checksums()}}
{\footnotesize\ttfamily subroutine mom\+\_\+sum\+\_\+output\+::get\+\_\+depth\+\_\+list\+\_\+checksums (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{character(len=16), intent(out)}]{depth\+\_\+chksum,  }\item[{character(len=16), intent(out)}]{area\+\_\+chksum }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Return the checksums required to verify D\+E\+P\+T\+H\+\_\+\+L\+I\+S\+T\+\_\+\+F\+I\+LE contents. 

This function computes checksums for the bathymetry (GbathyT) and masked area (mask2dT $\ast$ areaT) fields of the model grid G, which are used to compute the depth list. A difference in checksum indicates that a different method was used to compute the grid data, and that any results using the depth list, such as A\+PE, will not be reproducible.

Checksums are saved as hexadecimal strings, in order to avoid potential datatype issues with net\+C\+DF attributes. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ out}}  & {\em depth\+\_\+chksum} & Depth checksum hexstring \\
\hline
\mbox{\texttt{ out}}  & {\em area\+\_\+chksum} & Area checksum hexstring \\
\hline
\end{DoxyParams}


Definition at line 1499 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1499   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{          !< Ocean grid structure}}
\DoxyCodeLine{1500   \textcolor{keywordtype}{character(len=16)}, \textcolor{keywordtype}{intent(out)} :: depth\_chksum\textcolor{comment}{  !< Depth checksum hexstring}}
\DoxyCodeLine{1501   \textcolor{keywordtype}{character(len=16)}, \textcolor{keywordtype}{intent(out)} :: area\_chksum\textcolor{comment}{   !< Area checksum hexstring}}
\DoxyCodeLine{1502 }
\DoxyCodeLine{1503   \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{1504 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable} :: field(:,:)}
\DoxyCodeLine{1505 }
\DoxyCodeLine{1506   \textcolor{keyword}{allocate}(field(g\%isc:g\%iec, g\%jsc:g\%jec))}
\DoxyCodeLine{1507 }
\DoxyCodeLine{1508   \textcolor{comment}{! Depth checksum}}
\DoxyCodeLine{1509   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{1510     field(i,j) = g\%bathyT(i,j)}
\DoxyCodeLine{1511 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1512   \textcolor{keyword}{write}(depth\_chksum, \textcolor{stringliteral}{'(Z16)'}) mpp\_chksum(field(:,:))}
\DoxyCodeLine{1513 }
\DoxyCodeLine{1514   \textcolor{comment}{! Area checksum}}
\DoxyCodeLine{1515   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{1516     field(i,j) = g\%mask2dT(i,j) * g\%US\%L\_to\_m**2*g\%areaT(i,j)}
\DoxyCodeLine{1517 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1518   \textcolor{keyword}{write}(area\_chksum, \textcolor{stringliteral}{'(Z16)'}) mpp\_chksum(field(:,:))}
\DoxyCodeLine{1519 }
\DoxyCodeLine{1520   \textcolor{keyword}{deallocate}(field)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_ae54994f461b38198510274dadbce8fb5}\label{namespacemom__sum__output_ae54994f461b38198510274dadbce8fb5}} 
\index{mom\_sum\_output@{mom\_sum\_output}!mom\_sum\_output\_end@{mom\_sum\_output\_end}}
\index{mom\_sum\_output\_end@{mom\_sum\_output\_end}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{mom\_sum\_output\_end()}{mom\_sum\_output\_end()}}
{\footnotesize\ttfamily subroutine mom\+\_\+sum\+\_\+output\+::mom\+\_\+sum\+\_\+output\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



M\+O\+M\+\_\+sum\+\_\+output\+\_\+end deallocates memory used by the M\+O\+M\+\_\+sum\+\_\+output module. 


\begin{DoxyParams}{Parameters}
{\em cs} & The control structure returned by a previous call to M\+O\+M\+\_\+sum\+\_\+output\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 284 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{284   \textcolor{keywordtype}{type}(Sum\_output\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< The control structure returned by a}}
\DoxyCodeLine{285 \textcolor{comment}{                                      !! previous call to MOM\_sum\_output\_init.}}
\DoxyCodeLine{286   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{287     \textcolor{keywordflow}{if} (cs\%do\_APE\_calc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{288       \textcolor{keyword}{deallocate}(cs\%lH, cs\%DL)}
\DoxyCodeLine{289 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{290 }
\DoxyCodeLine{291     \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{292 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_a05003e74cbb39fbdf760d23617390445}\label{namespacemom__sum__output_a05003e74cbb39fbdf760d23617390445}} 
\index{mom\_sum\_output@{mom\_sum\_output}!mom\_sum\_output\_init@{mom\_sum\_output\_init}}
\index{mom\_sum\_output\_init@{mom\_sum\_output\_init}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{mom\_sum\_output\_init()}{mom\_sum\_output\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sum\+\_\+output\+::mom\+\_\+sum\+\_\+output\+\_\+init (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{character(len=$\ast$), intent(in)}]{directory,  }\item[{integer, intent(inout), target}]{ntrnc,  }\item[{type(time\+\_\+type), intent(in)}]{Input\+\_\+start\+\_\+time,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



M\+O\+M\+\_\+sum\+\_\+output\+\_\+init initializes the parameters and settings for the M\+O\+M\+\_\+sum\+\_\+output module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters. \\
\hline
\mbox{\texttt{ in}}  & {\em directory} & The directory where the energy file goes. \\
\hline
\mbox{\texttt{ in,out}}  & {\em ntrnc} & The integer that stores the number of times the velocity has been truncated since the last call to write\+\_\+energy. \\
\hline
\mbox{\texttt{ in}}  & {\em input\+\_\+start\+\_\+time} & The start time of the simulation. \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 136 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{136   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{137   \textcolor{keywordtype}{type}(unit\_scale\_type),  \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{138   \textcolor{keywordtype}{type}(param\_file\_type),  \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time}}
\DoxyCodeLine{139 \textcolor{comment}{                                                      !! parameters.}}
\DoxyCodeLine{140   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)}    :: directory\textcolor{comment}{  !< The directory where the energy file goes.}}
\DoxyCodeLine{141   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{target},        \textcolor{keywordtype}{intent(inout)} :: ntrnc\textcolor{comment}{      !< The integer that stores the number of times}}
\DoxyCodeLine{142 \textcolor{comment}{                                                      !! the velocity has been truncated since the}}
\DoxyCodeLine{143 \textcolor{comment}{                                                      !! last call to write\_energy.}}
\DoxyCodeLine{144   \textcolor{keywordtype}{type}(time\_type),        \textcolor{keywordtype}{intent(in)}    :: Input\_start\_time\textcolor{comment}{ !< The start time of the simulation.}}
\DoxyCodeLine{145   \textcolor{keywordtype}{type}(Sum\_output\_CS),    \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< A pointer that is set to point to the}}
\DoxyCodeLine{146 \textcolor{comment}{                                                      !! control structure for this module.}}
\DoxyCodeLine{147   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{148 \textcolor{keywordtype}{  real} :: Time\_unit \textcolor{comment}{! The time unit in seconds for ENERGYSAVEDAYS.}}
\DoxyCodeLine{149 \textcolor{keywordtype}{  real} :: Rho\_0     \textcolor{comment}{! A reference density [kg m-3]}}
\DoxyCodeLine{150 \textcolor{keywordtype}{  real} :: maxvel    \textcolor{comment}{! The maximum permitted velocity [m s-1]}}
\DoxyCodeLine{151 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{152 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{153 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_sum\_output"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{154   \textcolor{keywordtype}{character(len=200)} :: energyfile  \textcolor{comment}{! The name of the energy file.}}
\DoxyCodeLine{155   \textcolor{keywordtype}{character(len=32)} :: filename\_appendix = \textcolor{stringliteral}{''} \textcolor{comment}{!fms appendix to filename for ensemble runs}}
\DoxyCodeLine{156 }
\DoxyCodeLine{157   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{158     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_sum\_output\_init called with associated control structure."})}
\DoxyCodeLine{159     \textcolor{keywordflow}{return}}
\DoxyCodeLine{160 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{161   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{162 }
\DoxyCodeLine{163   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{164   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{165   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CALCULATE\_APE"}, cs\%do\_APE\_calc, \&}
\DoxyCodeLine{166                  \textcolor{stringliteral}{"If true, calculate the available potential energy of "}//\&}
\DoxyCodeLine{167                  \textcolor{stringliteral}{"the interfaces.  Setting this to false reduces the "}//\&}
\DoxyCodeLine{168                  \textcolor{stringliteral}{"memory footprint of high-PE-count models dramatically."}, \&}
\DoxyCodeLine{169                  default=.true.)}
\DoxyCodeLine{170   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WRITE\_STOCKS"}, cs\%write\_stocks, \&}
\DoxyCodeLine{171                  \textcolor{stringliteral}{"If true, write the integrated tracer amounts to stdout "}//\&}
\DoxyCodeLine{172                  \textcolor{stringliteral}{"when the energy files are written."}, default=.true.)}
\DoxyCodeLine{173   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, cs\%use\_temperature, \&}
\DoxyCodeLine{174                  \textcolor{stringliteral}{"If true, Temperature and salinity are used as state "}//\&}
\DoxyCodeLine{175                  \textcolor{stringliteral}{"variables."}, default=.true.)}
\DoxyCodeLine{176   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT"}, cs\%dt\_in\_T, \&}
\DoxyCodeLine{177                  \textcolor{stringliteral}{"The (baroclinic) dynamics time step."}, \&}
\DoxyCodeLine{178                  units=\textcolor{stringliteral}{"s"}, scale=us\%s\_to\_T, fail\_if\_missing=.true.)}
\DoxyCodeLine{179   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAXTRUNC"}, cs\%maxtrunc, \&}
\DoxyCodeLine{180                  \textcolor{stringliteral}{"The run will be stopped, and the day set to a very "}//\&}
\DoxyCodeLine{181                  \textcolor{stringliteral}{"large value if the velocity is truncated more than "}//\&}
\DoxyCodeLine{182                  \textcolor{stringliteral}{"MAXTRUNC times between energy saves.  Set MAXTRUNC to 0 "}//\&}
\DoxyCodeLine{183                  \textcolor{stringliteral}{"to stop if there is any truncation of velocities."}, \&}
\DoxyCodeLine{184                  units=\textcolor{stringliteral}{"truncations save\_interval-1"}, default=0)}
\DoxyCodeLine{185 }
\DoxyCodeLine{186   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAX\_ENERGY"}, cs\%max\_Energy, \&}
\DoxyCodeLine{187                  \textcolor{stringliteral}{"The maximum permitted average energy per unit mass; the "}//\&}
\DoxyCodeLine{188                  \textcolor{stringliteral}{"model will be stopped if there is more energy than "}//\&}
\DoxyCodeLine{189                  \textcolor{stringliteral}{"this.  If zero or negative, this is set to 10*MAXVEL\string^2."}, \&}
\DoxyCodeLine{190                  units=\textcolor{stringliteral}{"m2 s-2"}, default=0.0)}
\DoxyCodeLine{191   \textcolor{keywordflow}{if} (cs\%max\_Energy <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{192     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAXVEL"}, maxvel, \&}
\DoxyCodeLine{193                  \textcolor{stringliteral}{"The maximum velocity allowed before the velocity "}//\&}
\DoxyCodeLine{194                  \textcolor{stringliteral}{"components are truncated."}, units=\textcolor{stringliteral}{"m s-1"}, default=3.0e8)}
\DoxyCodeLine{195     cs\%max\_Energy = 10.0 * maxvel**2}
\DoxyCodeLine{196     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"MAX\_ENERGY as used"}, cs\%max\_Energy)}
\DoxyCodeLine{197 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{198 }
\DoxyCodeLine{199   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ENERGYFILE"}, energyfile, \&}
\DoxyCodeLine{200                  \textcolor{stringliteral}{"The file to use to write the energies and globally "}//\&}
\DoxyCodeLine{201                  \textcolor{stringliteral}{"summed diagnostics."}, default=\textcolor{stringliteral}{"ocean.stats"})}
\DoxyCodeLine{202 }
\DoxyCodeLine{203   \textcolor{comment}{!query fms\_io if there is a filename\_appendix (for ensemble runs)}}
\DoxyCodeLine{204   \textcolor{keyword}{call }get\_filename\_appendix(filename\_appendix)}
\DoxyCodeLine{205   \textcolor{keywordflow}{if} (len\_trim(filename\_appendix) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{206      energyfile = trim(energyfile) //\textcolor{stringliteral}{'.'}//trim(filename\_appendix)}
\DoxyCodeLine{207 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{208 }
\DoxyCodeLine{209   cs\%energyfile = trim(slasher(directory))//trim(energyfile)}
\DoxyCodeLine{210   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"output\_path/ENERGYFILE"}, cs\%energyfile)}
\DoxyCodeLine{211 \textcolor{preprocessor}{\#ifdef STATSLABEL}}
\DoxyCodeLine{212 \textcolor{preprocessor}{}  cs\%energyfile = trim(cs\%energyfile)//\textcolor{stringliteral}{"."}//trim(adjustl(statslabel))}
\DoxyCodeLine{213 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{214 \textcolor{preprocessor}{}}
\DoxyCodeLine{215   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DATE\_STAMPED\_STDOUT"}, cs\%date\_stamped\_output, \&}
\DoxyCodeLine{216                  \textcolor{stringliteral}{"If true, use dates (not times) in messages to stdout"}, \&}
\DoxyCodeLine{217                  default=.true.)}
\DoxyCodeLine{218   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIMEUNIT"}, cs\%Timeunit, \&}
\DoxyCodeLine{219                  \textcolor{stringliteral}{"The time unit in seconds a number of input fields"}, \&}
\DoxyCodeLine{220                  units=\textcolor{stringliteral}{"s"}, default=86400.0)}
\DoxyCodeLine{221   \textcolor{keywordflow}{if} (cs\%Timeunit < 0.0) cs\%Timeunit = 86400.0}
\DoxyCodeLine{222 }
\DoxyCodeLine{223 }
\DoxyCodeLine{224 }
\DoxyCodeLine{225   \textcolor{keywordflow}{if} (cs\%do\_APE\_calc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{226     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_DEPTH\_LIST"}, cs\%read\_depth\_list, \&}
\DoxyCodeLine{227                    \textcolor{stringliteral}{"Read the depth list from a file if it exists or "}//\&}
\DoxyCodeLine{228                    \textcolor{stringliteral}{"create that file otherwise."}, default=.false.)}
\DoxyCodeLine{229     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEPTH\_LIST\_MIN\_INC"}, cs\%D\_list\_min\_inc, \&}
\DoxyCodeLine{230                    \textcolor{stringliteral}{"The minimum increment between the depths of the "}//\&}
\DoxyCodeLine{231                    \textcolor{stringliteral}{"entries in the depth-list file."}, \&}
\DoxyCodeLine{232                    units=\textcolor{stringliteral}{"m"}, default=1.0e-10, scale=us\%m\_to\_Z)}
\DoxyCodeLine{233     \textcolor{keywordflow}{if} (cs\%read\_depth\_list) \textcolor{keywordflow}{then}}
\DoxyCodeLine{234       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEPTH\_LIST\_FILE"}, cs\%depth\_list\_file, \&}
\DoxyCodeLine{235                    \textcolor{stringliteral}{"The name of the depth list file."}, default=\textcolor{stringliteral}{"Depth\_list.nc"})}
\DoxyCodeLine{236       \textcolor{keywordflow}{if} (scan(cs\%depth\_list\_file,\textcolor{stringliteral}{'/'}) == 0) \&}
\DoxyCodeLine{237         cs\%depth\_list\_file = trim(slasher(directory))//trim(cs\%depth\_list\_file)}
\DoxyCodeLine{238 }
\DoxyCodeLine{239       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REQUIRE\_DEPTH\_LIST\_CHECKSUMS"}, \&}
\DoxyCodeLine{240                      cs\%require\_depth\_list\_chksum, \&}
\DoxyCodeLine{241                  \textcolor{stringliteral}{"Require that matching checksums be in Depth\_list.nc "}//\&}
\DoxyCodeLine{242                  \textcolor{stringliteral}{"when reading the file."}, default=.true.)}
\DoxyCodeLine{243       \textcolor{keywordflow}{if} (.not. cs\%require\_depth\_list\_chksum) \&}
\DoxyCodeLine{244         \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"UPDATE\_DEPTH\_LIST\_CHECKSUMS"}, \&}
\DoxyCodeLine{245                      cs\%update\_depth\_list\_chksum, \&}
\DoxyCodeLine{246                  \textcolor{stringliteral}{"Automatically update the Depth\_list.nc file if the "}//\&}
\DoxyCodeLine{247                  \textcolor{stringliteral}{"checksums are missing or do not match current values."}, \&}
\DoxyCodeLine{248                  default=.false.)}
\DoxyCodeLine{249 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{250 }
\DoxyCodeLine{251     \textcolor{keyword}{allocate}(cs\%lH(g\%ke))}
\DoxyCodeLine{252     \textcolor{keyword}{call }depth\_list\_setup(g, us, cs)}
\DoxyCodeLine{253   \textcolor{keywordflow}{else}}
\DoxyCodeLine{254     cs\%list\_size = 0}
\DoxyCodeLine{255 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{256 }
\DoxyCodeLine{257   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIMEUNIT"}, time\_unit, \&}
\DoxyCodeLine{258                  \textcolor{stringliteral}{"The time unit for ENERGYSAVEDAYS."}, \&}
\DoxyCodeLine{259                  units=\textcolor{stringliteral}{"s"}, default=86400.0)}
\DoxyCodeLine{260   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ENERGYSAVEDAYS"},cs\%energysavedays, \&}
\DoxyCodeLine{261                  \textcolor{stringliteral}{"The interval in units of TIMEUNIT between saves of the "}//\&}
\DoxyCodeLine{262                  \textcolor{stringliteral}{"energies of the run and other globally summed diagnostics."},\&}
\DoxyCodeLine{263                  default=set\_time(0,days=1), timeunit=time\_unit)}
\DoxyCodeLine{264   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ENERGYSAVEDAYS\_GEOMETRIC"},cs\%energysavedays\_geometric, \&}
\DoxyCodeLine{265                  \textcolor{stringliteral}{"The starting interval in units of TIMEUNIT for the first call "}//\&}
\DoxyCodeLine{266                  \textcolor{stringliteral}{"to save the energies of the run and other globally summed diagnostics. "}//\&}
\DoxyCodeLine{267                  \textcolor{stringliteral}{"The interval increases by a factor of 2. after each call to write\_energy."},\&}
\DoxyCodeLine{268                  default=set\_time(seconds=0), timeunit=time\_unit)}
\DoxyCodeLine{269 }
\DoxyCodeLine{270   \textcolor{keywordflow}{if} ((time\_type\_to\_real(cs\%energysavedays\_geometric) > 0.) .and. \&}
\DoxyCodeLine{271      (cs\%energysavedays\_geometric < cs\%energysavedays)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{272          cs\%energysave\_geometric = .true.}
\DoxyCodeLine{273   \textcolor{keywordflow}{else}}
\DoxyCodeLine{274          cs\%energysave\_geometric = .false.}
\DoxyCodeLine{275 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{276 }
\DoxyCodeLine{277   cs\%Start\_time = input\_start\_time}
\DoxyCodeLine{278   cs\%ntrunc => ntrnc}
\DoxyCodeLine{279 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_a4f45b1c7dbff4fe064e102ccb2967daf}\label{namespacemom__sum__output_a4f45b1c7dbff4fe064e102ccb2967daf}} 
\index{mom\_sum\_output@{mom\_sum\_output}!read\_depth\_list@{read\_depth\_list}}
\index{read\_depth\_list@{read\_depth\_list}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{read\_depth\_list()}{read\_depth\_list()}}
{\footnotesize\ttfamily subroutine mom\+\_\+sum\+\_\+output\+::read\+\_\+depth\+\_\+list (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{filename }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine reads in the depth list to the specified file and allocates and sets up CSDL and CSlist\+\_\+size . 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to M\+O\+M\+\_\+sum\+\_\+output\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em filename} & The path to the depth list file to read. \\
\hline
\end{DoxyParams}


Definition at line 1343 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1343   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{   !< The ocean's grid structure}}
\DoxyCodeLine{1344   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{1345   \textcolor{keywordtype}{type}(Sum\_output\_CS),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{  !< The control structure returned by a}}
\DoxyCodeLine{1346 \textcolor{comment}{                                           !! previous call to MOM\_sum\_output\_init.}}
\DoxyCodeLine{1347   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)} :: filename\textcolor{comment}{ !< The path to the depth list file to read.}}
\DoxyCodeLine{1348   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1349   \textcolor{keywordtype}{character(len=32)} :: mdl}
\DoxyCodeLine{1350   \textcolor{keywordtype}{character(len=240)} :: var\_name, var\_msg}
\DoxyCodeLine{1351 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable} :: tmp(:)}
\DoxyCodeLine{1352   \textcolor{keywordtype}{integer} :: ncid, status, varid, list\_size, k}
\DoxyCodeLine{1353   \textcolor{keywordtype}{integer} :: ndim, len, var\_dim\_ids(NF90\_MAX\_VAR\_DIMS)}
\DoxyCodeLine{1354   \textcolor{keywordtype}{character(len=16)} :: depth\_file\_chksum, depth\_grid\_chksum}
\DoxyCodeLine{1355   \textcolor{keywordtype}{character(len=16)} :: area\_file\_chksum, area\_grid\_chksum}
\DoxyCodeLine{1356   \textcolor{keywordtype}{integer} :: depth\_attr\_status, area\_attr\_status}
\DoxyCodeLine{1357 }
\DoxyCodeLine{1358   mdl = \textcolor{stringliteral}{"MOM\_sum\_output read\_depth\_list:"}}
\DoxyCodeLine{1359 }
\DoxyCodeLine{1360   status = nf90\_open(filename, nf90\_nowrite, ncid)}
\DoxyCodeLine{1361   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1362     \textcolor{keyword}{call }mom\_error(fatal,mdl//\textcolor{stringliteral}{" Difficulties opening "}//trim(filename)// \&}
\DoxyCodeLine{1363         \textcolor{stringliteral}{" - "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1364 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1365 }
\DoxyCodeLine{1366   \textcolor{comment}{! Check bathymetric consistency}}
\DoxyCodeLine{1367   depth\_attr\_status = nf90\_get\_att(ncid, nf90\_global, depth\_chksum\_attr, \&}
\DoxyCodeLine{1368                                    depth\_file\_chksum)}
\DoxyCodeLine{1369   area\_attr\_status = nf90\_get\_att(ncid, nf90\_global, area\_chksum\_attr, \&}
\DoxyCodeLine{1370                                   area\_file\_chksum)}
\DoxyCodeLine{1371 }
\DoxyCodeLine{1372   \textcolor{keywordflow}{if} (any([depth\_attr\_status, area\_attr\_status] == nf90\_enotatt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1373     var\_msg = trim(cs\%depth\_list\_file) // \textcolor{stringliteral}{" checksums are missing;"}}
\DoxyCodeLine{1374     \textcolor{keywordflow}{if} (cs\%require\_depth\_list\_chksum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1375       \textcolor{keyword}{call }mom\_error(fatal, trim(var\_msg) // \textcolor{stringliteral}{" aborting."})}
\DoxyCodeLine{1376     \textcolor{keywordflow}{elseif} (cs\%update\_depth\_list\_chksum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1377       \textcolor{keyword}{call }mom\_error(warning, trim(var\_msg) // \textcolor{stringliteral}{" updating file."})}
\DoxyCodeLine{1378       \textcolor{keyword}{call }create\_depth\_list(g, cs)}
\DoxyCodeLine{1379       \textcolor{keyword}{call }write\_depth\_list(g, us, cs, cs\%depth\_list\_file, cs\%list\_size+1)}
\DoxyCodeLine{1380       \textcolor{keywordflow}{return}}
\DoxyCodeLine{1381     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1382       \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1383         trim(var\_msg) // \textcolor{stringliteral}{" some diagnostics may not be reproducible."})}
\DoxyCodeLine{1384 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1385   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1386     \textcolor{comment}{! Validate netCDF call}}
\DoxyCodeLine{1387     \textcolor{keywordflow}{if} (depth\_attr\_status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1388       var\_msg = mdl // \textcolor{stringliteral}{"Failed to read "} // trim(filename) // \textcolor{stringliteral}{":"} \&}
\DoxyCodeLine{1389                 // depth\_chksum\_attr}
\DoxyCodeLine{1390       \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1391         trim(var\_msg) // \textcolor{stringliteral}{" - "} // nf90\_strerror(depth\_attr\_status))}
\DoxyCodeLine{1392 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1393 }
\DoxyCodeLine{1394     \textcolor{keywordflow}{if} (area\_attr\_status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1395       var\_msg = mdl // \textcolor{stringliteral}{"Failed to read "} // trim(filename) // \textcolor{stringliteral}{":"} \&}
\DoxyCodeLine{1396                 // area\_chksum\_attr}
\DoxyCodeLine{1397       \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1398         trim(var\_msg) // \textcolor{stringliteral}{" - "} // nf90\_strerror(area\_attr\_status))}
\DoxyCodeLine{1399 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1400 }
\DoxyCodeLine{1401     \textcolor{keyword}{call }get\_depth\_list\_checksums(g, depth\_grid\_chksum, area\_grid\_chksum)}
\DoxyCodeLine{1402 }
\DoxyCodeLine{1403     \textcolor{keywordflow}{if} (depth\_grid\_chksum /= depth\_file\_chksum \&}
\DoxyCodeLine{1404             .or. area\_grid\_chksum /= area\_file\_chksum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1405       var\_msg = trim(cs\%depth\_list\_file) // \textcolor{stringliteral}{" checksums do not match;"}}
\DoxyCodeLine{1406       \textcolor{keywordflow}{if} (cs\%require\_depth\_list\_chksum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1407         \textcolor{keyword}{call }mom\_error(fatal, trim(var\_msg) // \textcolor{stringliteral}{" aborting."})}
\DoxyCodeLine{1408       \textcolor{keywordflow}{elseif} (cs\%update\_depth\_list\_chksum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1409         \textcolor{keyword}{call }mom\_error(warning, trim(var\_msg) // \textcolor{stringliteral}{" updating file."})}
\DoxyCodeLine{1410         \textcolor{keyword}{call }create\_depth\_list(g, cs)}
\DoxyCodeLine{1411         \textcolor{keyword}{call }write\_depth\_list(g, us, cs, cs\%depth\_list\_file, cs\%list\_size+1)}
\DoxyCodeLine{1412         \textcolor{keywordflow}{return}}
\DoxyCodeLine{1413       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1414         \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1415           trim(var\_msg) // \textcolor{stringliteral}{" some diagnostics may not be reproducible."})}
\DoxyCodeLine{1416 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1417 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1418 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1419 }
\DoxyCodeLine{1420   var\_name = \textcolor{stringliteral}{"depth"}}
\DoxyCodeLine{1421   var\_msg = trim(var\_name)//\textcolor{stringliteral}{" in "}//trim(filename)//\textcolor{stringliteral}{" - "}}
\DoxyCodeLine{1422   status = nf90\_inq\_varid(ncid, var\_name, varid)}
\DoxyCodeLine{1423   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1424         \textcolor{stringliteral}{" Difficulties finding variable "}//trim(var\_msg)//\&}
\DoxyCodeLine{1425         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1426 }
\DoxyCodeLine{1427   status = nf90\_inquire\_variable(ncid, varid, ndims=ndim, dimids=var\_dim\_ids)}
\DoxyCodeLine{1428   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1429     \textcolor{keyword}{call }mom\_error(fatal,mdl//\textcolor{stringliteral}{" cannot inquire about "}//trim(var\_msg)//\&}
\DoxyCodeLine{1430         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1431   \textcolor{keywordflow}{elseif} (ndim > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1432     \textcolor{keyword}{call }mom\_error(fatal,mdl//\textcolor{stringliteral}{" "}//trim(var\_msg)//\&}
\DoxyCodeLine{1433          \textcolor{stringliteral}{" has too many or too few dimensions."})}
\DoxyCodeLine{1434 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1435 }
\DoxyCodeLine{1436   \textcolor{comment}{! Get the length of the list.}}
\DoxyCodeLine{1437   status = nf90\_inquire\_dimension(ncid, var\_dim\_ids(1), len=list\_size)}
\DoxyCodeLine{1438   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1439         \textcolor{stringliteral}{" cannot inquire about dimension(1) of "}//trim(var\_msg)//\&}
\DoxyCodeLine{1440         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1441 }
\DoxyCodeLine{1442   cs\%list\_size = list\_size-1}
\DoxyCodeLine{1443   \textcolor{keyword}{allocate}(cs\%DL(list\_size))}
\DoxyCodeLine{1444   \textcolor{keyword}{allocate}(tmp(list\_size))}
\DoxyCodeLine{1445 }
\DoxyCodeLine{1446   status = nf90\_get\_var(ncid, varid, tmp)}
\DoxyCodeLine{1447   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1448         \textcolor{stringliteral}{" Difficulties reading variable "}//trim(var\_msg)//\&}
\DoxyCodeLine{1449         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1450 }
\DoxyCodeLine{1451   \textcolor{keywordflow}{do} k=1,list\_size ; cs\%DL(k)\%depth = us\%m\_to\_Z*tmp(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1452 }
\DoxyCodeLine{1453   var\_name = \textcolor{stringliteral}{"area"}}
\DoxyCodeLine{1454   var\_msg = trim(var\_name)//\textcolor{stringliteral}{" in "}//trim(filename)//\textcolor{stringliteral}{" - "}}
\DoxyCodeLine{1455   status = nf90\_inq\_varid(ncid, var\_name, varid)}
\DoxyCodeLine{1456   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1457         \textcolor{stringliteral}{" Difficulties finding variable "}//trim(var\_msg)//\&}
\DoxyCodeLine{1458         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1459   status = nf90\_get\_var(ncid, varid, tmp)}
\DoxyCodeLine{1460   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1461         \textcolor{stringliteral}{" Difficulties reading variable "}//trim(var\_msg)//\&}
\DoxyCodeLine{1462         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1463 }
\DoxyCodeLine{1464   \textcolor{keywordflow}{do} k=1,list\_size ; cs\%DL(k)\%area = us\%m\_to\_L**2*tmp(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1465 }
\DoxyCodeLine{1466   var\_name = \textcolor{stringliteral}{"vol\_below"}}
\DoxyCodeLine{1467   var\_msg = trim(var\_name)//\textcolor{stringliteral}{" in "}//trim(filename)}
\DoxyCodeLine{1468   status = nf90\_inq\_varid(ncid, var\_name, varid)}
\DoxyCodeLine{1469   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1470         \textcolor{stringliteral}{" Difficulties finding variable "}//trim(var\_msg)//\&}
\DoxyCodeLine{1471         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1472   status = nf90\_get\_var(ncid, varid, tmp)}
\DoxyCodeLine{1473   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(fatal,mdl// \&}
\DoxyCodeLine{1474         \textcolor{stringliteral}{" Difficulties reading variable "}//trim(var\_msg)//\&}
\DoxyCodeLine{1475         trim(nf90\_strerror(status)))}
\DoxyCodeLine{1476 }
\DoxyCodeLine{1477   \textcolor{keywordflow}{do} k=1,list\_size ; cs\%DL(k)\%vol\_below = us\%m\_to\_Z*us\%m\_to\_L**2*tmp(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1478 }
\DoxyCodeLine{1479   status = nf90\_close(ncid)}
\DoxyCodeLine{1480   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, mdl// \&}
\DoxyCodeLine{1481     \textcolor{stringliteral}{" Difficulties closing "}//trim(filename)//\textcolor{stringliteral}{" - "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1482 }
\DoxyCodeLine{1483   \textcolor{keyword}{deallocate}(tmp)}
\DoxyCodeLine{1484 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_a955e777980a668bfc611c78de5de1895}\label{namespacemom__sum__output_a955e777980a668bfc611c78de5de1895}} 
\index{mom\_sum\_output@{mom\_sum\_output}!write\_depth\_list@{write\_depth\_list}}
\index{write\_depth\_list@{write\_depth\_list}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{write\_depth\_list()}{write\_depth\_list()}}
{\footnotesize\ttfamily subroutine mom\+\_\+sum\+\_\+output\+::write\+\_\+depth\+\_\+list (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{filename,  }\item[{integer, intent(in)}]{list\+\_\+size }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine writes out the depth list to the specified file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to M\+O\+M\+\_\+sum\+\_\+output\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em filename} & The path to the depth list file to write. \\
\hline
\mbox{\texttt{ in}}  & {\em list\+\_\+size} & The size of the depth list. \\
\hline
\end{DoxyParams}


Definition at line 1248 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1248   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{   !< The ocean's grid structure.}}
\DoxyCodeLine{1249   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{1250   \textcolor{keywordtype}{type}(Sum\_output\_CS),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{  !< The control structure returned by a}}
\DoxyCodeLine{1251 \textcolor{comment}{                                           !! previous call to MOM\_sum\_output\_init.}}
\DoxyCodeLine{1252   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)} :: filename\textcolor{comment}{ !< The path to the depth list file to write.}}
\DoxyCodeLine{1253   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: list\_size\textcolor{comment}{ !< The size of the depth list.}}
\DoxyCodeLine{1254   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1255 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable} :: tmp(:)}
\DoxyCodeLine{1256   \textcolor{keywordtype}{integer} :: ncid, dimid(1), Did, Aid, Vid, status, k}
\DoxyCodeLine{1257   \textcolor{keywordtype}{character(len=16)} :: depth\_chksum, area\_chksum}
\DoxyCodeLine{1258 }
\DoxyCodeLine{1259   \textcolor{comment}{! All ranks are required to compute the global checksum}}
\DoxyCodeLine{1260   \textcolor{keyword}{call }get\_depth\_list\_checksums(g, depth\_chksum, area\_chksum)}
\DoxyCodeLine{1261 }
\DoxyCodeLine{1262   \textcolor{keywordflow}{if} (.not.is\_root\_pe()) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1263 }
\DoxyCodeLine{1264   \textcolor{keyword}{allocate}(tmp(list\_size)) ; tmp(:) = 0.0}
\DoxyCodeLine{1265 }
\DoxyCodeLine{1266   status = nf90\_create(filename, 0, ncid)}
\DoxyCodeLine{1267   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1268     \textcolor{keyword}{call }mom\_error(warning, filename//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1269     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1270 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1271 }
\DoxyCodeLine{1272   status = nf90\_def\_dim(ncid, \textcolor{stringliteral}{"list"}, list\_size, dimid(1))}
\DoxyCodeLine{1273   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1274       filename//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1275 }
\DoxyCodeLine{1276   status = nf90\_def\_var(ncid, \textcolor{stringliteral}{"depth"}, nf90\_double, dimid, did)}
\DoxyCodeLine{1277   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1278       filename//\textcolor{stringliteral}{" depth "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1279   status = nf90\_put\_att(ncid, did, \textcolor{stringliteral}{"long\_name"}, \textcolor{stringliteral}{"Sorted depth"})}
\DoxyCodeLine{1280   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1281       filename//\textcolor{stringliteral}{" depth "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1282   status = nf90\_put\_att(ncid, did, \textcolor{stringliteral}{"units"}, \textcolor{stringliteral}{"m"})}
\DoxyCodeLine{1283   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1284       filename//\textcolor{stringliteral}{" depth "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1285 }
\DoxyCodeLine{1286   status = nf90\_def\_var(ncid, \textcolor{stringliteral}{"area"}, nf90\_double, dimid, aid)}
\DoxyCodeLine{1287   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1288       filename//\textcolor{stringliteral}{" area "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1289   status = nf90\_put\_att(ncid, aid, \textcolor{stringliteral}{"long\_name"}, \textcolor{stringliteral}{"Open area at depth"})}
\DoxyCodeLine{1290   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1291       filename//\textcolor{stringliteral}{" area "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1292   status = nf90\_put\_att(ncid, aid, \textcolor{stringliteral}{"units"}, \textcolor{stringliteral}{"m2"})}
\DoxyCodeLine{1293   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1294       filename//\textcolor{stringliteral}{" area "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1295 }
\DoxyCodeLine{1296   status = nf90\_def\_var(ncid, \textcolor{stringliteral}{"vol\_below"}, nf90\_double, dimid, vid)}
\DoxyCodeLine{1297   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1298       filename//\textcolor{stringliteral}{" vol\_below "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1299   status = nf90\_put\_att(ncid, vid, \textcolor{stringliteral}{"long\_name"}, \textcolor{stringliteral}{"Open volume below depth"})}
\DoxyCodeLine{1300    \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1301       filename//\textcolor{stringliteral}{" vol\_below "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1302   status = nf90\_put\_att(ncid, vid, \textcolor{stringliteral}{"units"}, \textcolor{stringliteral}{"m3"})}
\DoxyCodeLine{1303   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1304       filename//\textcolor{stringliteral}{" vol\_below "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1305 }
\DoxyCodeLine{1306   \textcolor{comment}{! Dependency checksums}}
\DoxyCodeLine{1307   status = nf90\_put\_att(ncid, nf90\_global, depth\_chksum\_attr, depth\_chksum)}
\DoxyCodeLine{1308   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1309       filename//\textcolor{stringliteral}{" "}//depth\_chksum\_attr//\textcolor{stringliteral}{" "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1310 }
\DoxyCodeLine{1311   status = nf90\_put\_att(ncid, nf90\_global, area\_chksum\_attr, area\_chksum)}
\DoxyCodeLine{1312   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1313       filename//\textcolor{stringliteral}{" "}//area\_chksum\_attr//\textcolor{stringliteral}{" "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1314 }
\DoxyCodeLine{1315   status = nf90\_enddef(ncid)}
\DoxyCodeLine{1316   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1317       filename//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1318 }
\DoxyCodeLine{1319   \textcolor{keywordflow}{do} k=1,list\_size ; tmp(k) = us\%Z\_to\_m*cs\%DL(k)\%depth ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1320   status = nf90\_put\_var(ncid, did, tmp)}
\DoxyCodeLine{1321   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1322       filename//\textcolor{stringliteral}{" depth "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1323 }
\DoxyCodeLine{1324   \textcolor{keywordflow}{do} k=1,list\_size ; tmp(k) = us\%L\_to\_m**2*cs\%DL(k)\%area ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1325   status = nf90\_put\_var(ncid, aid, tmp)}
\DoxyCodeLine{1326   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1327       filename//\textcolor{stringliteral}{" area "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1328 }
\DoxyCodeLine{1329   \textcolor{keywordflow}{do} k=1,list\_size ; tmp(k) = us\%Z\_to\_m*us\%L\_to\_m**2*cs\%DL(k)\%vol\_below ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1330   status = nf90\_put\_var(ncid, vid, tmp)}
\DoxyCodeLine{1331   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1332       filename//\textcolor{stringliteral}{" vol\_below "}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1333 }
\DoxyCodeLine{1334   status = nf90\_close(ncid)}
\DoxyCodeLine{1335   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1336       filename//trim(nf90\_strerror(status)))}
\DoxyCodeLine{1337 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sum__output_ad3cc692dd515100ec8cf92d740c91e72}\label{namespacemom__sum__output_ad3cc692dd515100ec8cf92d740c91e72}} 
\index{mom\_sum\_output@{mom\_sum\_output}!write\_energy@{write\_energy}}
\index{write\_energy@{write\_energy}!mom\_sum\_output@{mom\_sum\_output}}
\subsubsection{\texorpdfstring{write\_energy()}{write\_energy()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sum\+\_\+output\+::write\+\_\+energy (\begin{DoxyParamCaption}\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(time\+\_\+type), intent(in)}]{day,  }\item[{integer, intent(in)}]{n,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__sum__output_1_1sum__output__cs}{sum\+\_\+output\+\_\+cs}}), pointer}]{CS,  }\item[{type(tracer\+\_\+flow\+\_\+control\+\_\+cs), optional, pointer}]{tracer\+\_\+\+C\+Sp,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{type(time\+\_\+type), intent(in), optional}]{dt\+\_\+forcing }\end{DoxyParamCaption})}



This subroutine calculates and writes the total model energy, the energy and mass of each layer, and other globally integrated physical quantities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables. \\
\hline
\mbox{\texttt{ in}}  & {\em day} & The current model time. \\
\hline
\mbox{\texttt{ in}}  & {\em n} & The time step number of the current execution. \\
\hline
 & {\em cs} & The control structure returned by a previous call to M\+O\+M\+\_\+sum\+\_\+output\+\_\+init. \\
\hline
 & {\em tracer\+\_\+csp} & tracer control structure. \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+forcing} & The forcing time step \\
\hline
\end{DoxyParams}


Definition at line 298 of file M\+O\+M\+\_\+sum\+\_\+output.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{298   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{   !< The ocean's grid structure.}}
\DoxyCodeLine{299   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< The ocean's vertical grid structure.}}
\DoxyCodeLine{300   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{301 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{302                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{   !< The zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{303 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{304                            \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{   !< The meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{305 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{306                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{   !< Layer thicknesses [H ~> m or kg m-2].}}
\DoxyCodeLine{307   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< A structure pointing to various}}
\DoxyCodeLine{308 \textcolor{comment}{                                                !! thermodynamic variables.}}
\DoxyCodeLine{309   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: day\textcolor{comment}{ !< The current model time.}}
\DoxyCodeLine{310   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: n\textcolor{comment}{   !< The time step number of the}}
\DoxyCodeLine{311 \textcolor{comment}{                                                !! current execution.}}
\DoxyCodeLine{312   \textcolor{keywordtype}{type}(Sum\_output\_CS),     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< The control structure returned by a}}
\DoxyCodeLine{313 \textcolor{comment}{                                                !! previous call to MOM\_sum\_output\_init.}}
\DoxyCodeLine{314   \textcolor{keywordtype}{type}(tracer\_flow\_control\_CS), \&}
\DoxyCodeLine{315                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}    :: tracer\_CSp\textcolor{comment}{ !< tracer control structure.}}
\DoxyCodeLine{316   \textcolor{keywordtype}{type}(ocean\_OBC\_type),         \&}
\DoxyCodeLine{317                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}    :: OBC\textcolor{comment}{ !< Open boundaries control structure.}}
\DoxyCodeLine{318   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: dt\_forcing\textcolor{comment}{ !< The forcing time step}}
\DoxyCodeLine{319   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{320 \textcolor{keywordtype}{  real} :: eta(SZI\_(G),SZJ\_(G),SZK\_(G)+1) \textcolor{comment}{! The height of interfaces [Z ~> m].}}
\DoxyCodeLine{321 \textcolor{keywordtype}{  real} :: areaTm(SZI\_(G),SZJ\_(G)) \textcolor{comment}{! A masked version of areaT [L2 ~> m2].}}
\DoxyCodeLine{322 \textcolor{keywordtype}{  real} :: KE(SZK\_(G))  \textcolor{comment}{! The total kinetic energy of a layer [J].}}
\DoxyCodeLine{323 \textcolor{keywordtype}{  real} :: PE(SZK\_(G)+1)\textcolor{comment}{! The available potential energy of an interface [J].}}
\DoxyCodeLine{324 \textcolor{keywordtype}{  real} :: KE\_tot       \textcolor{comment}{! The total kinetic energy [J].}}
\DoxyCodeLine{325 \textcolor{keywordtype}{  real} :: PE\_tot       \textcolor{comment}{! The total available potential energy [J].}}
\DoxyCodeLine{326 \textcolor{keywordtype}{  real} :: Z\_0APE(SZK\_(G)+1) \textcolor{comment}{! The uniform depth which overlies the same}}
\DoxyCodeLine{327                        \textcolor{comment}{! volume as is below an interface [Z ~> m].}}
\DoxyCodeLine{328 \textcolor{keywordtype}{  real} :: H\_0APE(SZK\_(G)+1) \textcolor{comment}{! A version of Z\_0APE, converted to m, usually positive.}}
\DoxyCodeLine{329 \textcolor{keywordtype}{  real} :: toten        \textcolor{comment}{! The total kinetic \& potential energies of}}
\DoxyCodeLine{330                        \textcolor{comment}{! all layers [J] (i.e. kg m2 s-2).}}
\DoxyCodeLine{331 \textcolor{keywordtype}{  real} :: En\_mass      \textcolor{comment}{! The total kinetic and potential energies divided by}}
\DoxyCodeLine{332                        \textcolor{comment}{! the total mass of the ocean [m2 s-2].}}
\DoxyCodeLine{333 \textcolor{keywordtype}{  real} :: vol\_lay(SZK\_(G))  \textcolor{comment}{! The volume of fluid in a layer [Z L2 ~> m3].}}
\DoxyCodeLine{334 \textcolor{keywordtype}{  real} :: volbelow     \textcolor{comment}{! The volume of all layers beneath an interface [Z L2 ~> m3].}}
\DoxyCodeLine{335 \textcolor{keywordtype}{  real} :: mass\_lay(SZK\_(G)) \textcolor{comment}{! The mass of fluid in a layer [kg].}}
\DoxyCodeLine{336 \textcolor{keywordtype}{  real} :: mass\_tot     \textcolor{comment}{! The total mass of the ocean [kg].}}
\DoxyCodeLine{337 \textcolor{keywordtype}{  real} :: vol\_tot      \textcolor{comment}{! The total ocean volume [m3].}}
\DoxyCodeLine{338 \textcolor{keywordtype}{  real} :: mass\_chg     \textcolor{comment}{! The change in total ocean mass of fresh water since}}
\DoxyCodeLine{339                        \textcolor{comment}{! the last call to this subroutine [kg].}}
\DoxyCodeLine{340 \textcolor{keywordtype}{  real} :: mass\_anom    \textcolor{comment}{! The change in fresh water that cannot be accounted for}}
\DoxyCodeLine{341                        \textcolor{comment}{! by the surface fluxes [kg].}}
\DoxyCodeLine{342 \textcolor{keywordtype}{  real} :: Salt         \textcolor{comment}{! The total amount of salt in the ocean [ppt kg].}}
\DoxyCodeLine{343 \textcolor{keywordtype}{  real} :: Salt\_chg     \textcolor{comment}{! The change in total ocean salt since the last call}}
\DoxyCodeLine{344                        \textcolor{comment}{! to this subroutine [ppt kg].}}
\DoxyCodeLine{345 \textcolor{keywordtype}{  real} :: Salt\_anom    \textcolor{comment}{! The change in salt that cannot be accounted for by}}
\DoxyCodeLine{346                        \textcolor{comment}{! the surface fluxes [ppt kg].}}
\DoxyCodeLine{347 \textcolor{keywordtype}{  real} :: salin        \textcolor{comment}{! The mean salinity of the ocean [ppt].}}
\DoxyCodeLine{348 \textcolor{keywordtype}{  real} :: salin\_chg    \textcolor{comment}{! The change in total salt since the last call}}
\DoxyCodeLine{349                        \textcolor{comment}{! to this subroutine divided by total mass [ppt].}}
\DoxyCodeLine{350 \textcolor{keywordtype}{  real} :: salin\_anom   \textcolor{comment}{! The change in total salt that cannot be accounted for by}}
\DoxyCodeLine{351                        \textcolor{comment}{! the surface fluxes divided by total mass [ppt].}}
\DoxyCodeLine{352 \textcolor{keywordtype}{  real} :: Heat         \textcolor{comment}{! The total amount of Heat in the ocean [J].}}
\DoxyCodeLine{353 \textcolor{keywordtype}{  real} :: Heat\_chg     \textcolor{comment}{! The change in total ocean heat since the last call to this subroutine [J].}}
\DoxyCodeLine{354 \textcolor{keywordtype}{  real} :: Heat\_anom    \textcolor{comment}{! The change in heat that cannot be accounted for by the surface fluxes [J].}}
\DoxyCodeLine{355 \textcolor{keywordtype}{  real} :: temp         \textcolor{comment}{! The mean potential temperature of the ocean [degC].}}
\DoxyCodeLine{356 \textcolor{keywordtype}{  real} :: temp\_chg     \textcolor{comment}{! The change in total heat divided by total heat capacity}}
\DoxyCodeLine{357                        \textcolor{comment}{! of the ocean since the last call to this subroutine, degC.}}
\DoxyCodeLine{358 \textcolor{keywordtype}{  real} :: temp\_anom    \textcolor{comment}{! The change in total heat that cannot be accounted for}}
\DoxyCodeLine{359                        \textcolor{comment}{! by the surface fluxes, divided by the total heat}}
\DoxyCodeLine{360                        \textcolor{comment}{! capacity of the ocean [degC].}}
\DoxyCodeLine{361 \textcolor{keywordtype}{  real} :: hint         \textcolor{comment}{! The deviation of an interface from H [Z ~> m].}}
\DoxyCodeLine{362 \textcolor{keywordtype}{  real} :: hbot         \textcolor{comment}{! 0 if the basin is deeper than H, or the}}
\DoxyCodeLine{363                        \textcolor{comment}{! height of the basin depth over H otherwise [Z ~> m].}}
\DoxyCodeLine{364                        \textcolor{comment}{! This makes PE only include real fluid.}}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real} :: hbelow       \textcolor{comment}{! The depth of fluid in all layers beneath an interface [Z ~> m].}}
\DoxyCodeLine{366   \textcolor{keywordtype}{type}(EFP\_type) :: \&}
\DoxyCodeLine{367     mass\_EFP, \&        \textcolor{comment}{! The total mass of the ocean in extended fixed point form [kg].}}
\DoxyCodeLine{368     salt\_EFP, \&        \textcolor{comment}{! The total amount of salt in the ocean in extended fixed point form [ppt kg].}}
\DoxyCodeLine{369     heat\_EFP, \&        \textcolor{comment}{! The total amount of heat in the ocean in extended fixed point form [J].}}
\DoxyCodeLine{370     salt\_chg\_EFP, \&    \textcolor{comment}{! The change in total ocean salt since the last call to this subroutine [ppt kg].}}
\DoxyCodeLine{371     heat\_chg\_EFP, \&    \textcolor{comment}{! The change in total ocean heat since the last call to this subroutine [J].}}
\DoxyCodeLine{372     mass\_chg\_EFP, \&    \textcolor{comment}{! The change in total ocean mass of fresh water since}}
\DoxyCodeLine{373                        \textcolor{comment}{! the last call to this subroutine [kg].}}
\DoxyCodeLine{374     salt\_anom\_efp, \&   \textcolor{comment}{! The change in salt that cannot be accounted for by the surface}}
\DoxyCodeLine{375                        \textcolor{comment}{! fluxes [ppt kg].}}
\DoxyCodeLine{376     heat\_anom\_efp, \&   \textcolor{comment}{! The change in heat that cannot be accounted for by the surface fluxes [J].}}
\DoxyCodeLine{377     mass\_anom\_efp      \textcolor{comment}{! The change in fresh water that cannot be accounted for by the surface}}
\DoxyCodeLine{378                        \textcolor{comment}{! fluxes [kg].}}
\DoxyCodeLine{379   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{dimension(5)} :: EFP\_list \textcolor{comment}{! An array of EFP types for joint global sums.}}
\DoxyCodeLine{380 \textcolor{keywordtype}{  real} :: CFL\_Iarea    \textcolor{comment}{! Direction-based inverse area used in CFL test [L-2].}}
\DoxyCodeLine{381 \textcolor{keywordtype}{  real} :: CFL\_trans    \textcolor{comment}{! A transport-based definition of the CFL number [nondim].}}
\DoxyCodeLine{382 \textcolor{keywordtype}{  real} :: CFL\_lin      \textcolor{comment}{! A simpler definition of the CFL number [nondim].}}
\DoxyCodeLine{383 \textcolor{keywordtype}{  real} :: max\_CFL(2)   \textcolor{comment}{! The maxima of the CFL numbers [nondim].}}
\DoxyCodeLine{384 \textcolor{keywordtype}{  real} :: Irho0        \textcolor{comment}{! The inverse of the reference density [m3 kg-1].}}
\DoxyCodeLine{385 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{386     tmp1               \textcolor{comment}{! A temporary array}}
\DoxyCodeLine{387 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)} :: \&}
\DoxyCodeLine{388     PE\_pt              \textcolor{comment}{! The potential energy at each point [J].}}
\DoxyCodeLine{389 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{390     Temp\_int, Salt\_int \textcolor{comment}{! Layer and cell integrated heat and salt [J] and [g Salt].}}
\DoxyCodeLine{391 \textcolor{keywordtype}{  real} :: HL2\_to\_kg    \textcolor{comment}{! A conversion factor from a thickness-volume to mass [kg H-1 L-2 ~> kg m-3 or 1]}}
\DoxyCodeLine{392 \textcolor{keywordtype}{  real} :: KE\_scale\_factor   \textcolor{comment}{! The combination of unit rescaling factors in the kinetic energy}}
\DoxyCodeLine{393                             \textcolor{comment}{! calculation [kg T2 H-1 L-2 s-2 ~> kg m-3 or nondim]}}
\DoxyCodeLine{394 \textcolor{keywordtype}{  real} :: PE\_scale\_factor   \textcolor{comment}{! The combination of unit rescaling factors in the potential energy}}
\DoxyCodeLine{395                             \textcolor{comment}{! calculation [kg T2 R-1 Z-1 L-2 s-2 ~> nondim]}}
\DoxyCodeLine{396   \textcolor{keywordtype}{integer} :: num\_nc\_fields  \textcolor{comment}{! The number of fields that will actually go into}}
\DoxyCodeLine{397                             \textcolor{comment}{! the NetCDF file.}}
\DoxyCodeLine{398   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, ns, nz, m, Isq, Ieq, Jsq, Jeq, isr, ier, jsr, jer}
\DoxyCodeLine{399   \textcolor{keywordtype}{integer} :: l, lbelow, labove   \textcolor{comment}{! indices of deep\_area\_vol, used to find Z\_0APE.}}
\DoxyCodeLine{400                                  \textcolor{comment}{! lbelow \& labove are lower \& upper limits for l}}
\DoxyCodeLine{401                                  \textcolor{comment}{! in the search for the entry in lH to use.}}
\DoxyCodeLine{402   \textcolor{keywordtype}{integer} :: start\_of\_day, num\_days}
\DoxyCodeLine{403 \textcolor{keywordtype}{  real}    :: reday, var}
\DoxyCodeLine{404   \textcolor{keywordtype}{character(len=240)} :: energypath\_nc}
\DoxyCodeLine{405   \textcolor{keywordtype}{character(len=200)} :: mesg}
\DoxyCodeLine{406   \textcolor{keywordtype}{character(len=32)}  :: mesg\_intro, time\_units, day\_str, n\_str, date\_str}
\DoxyCodeLine{407   \textcolor{keywordtype}{logical} :: date\_stamped}
\DoxyCodeLine{408   \textcolor{keywordtype}{type}(time\_type) :: dt\_force \textcolor{comment}{! A time\_type version of the forcing timestep.}}
\DoxyCodeLine{409 \textcolor{keywordtype}{  real} :: Tr\_stocks(MAX\_FIELDS\_)}
\DoxyCodeLine{410 \textcolor{keywordtype}{  real} :: Tr\_min(MAX\_FIELDS\_), Tr\_max(MAX\_FIELDS\_)}
\DoxyCodeLine{411 \textcolor{keywordtype}{  real} :: Tr\_min\_x(MAX\_FIELDS\_), Tr\_min\_y(MAX\_FIELDS\_), Tr\_min\_z(MAX\_FIELDS\_)}
\DoxyCodeLine{412 \textcolor{keywordtype}{  real} :: Tr\_max\_x(MAX\_FIELDS\_), Tr\_max\_y(MAX\_FIELDS\_), Tr\_max\_z(MAX\_FIELDS\_)}
\DoxyCodeLine{413   \textcolor{keywordtype}{logical} :: Tr\_minmax\_got(MAX\_FIELDS\_) = .false.}
\DoxyCodeLine{414   \textcolor{keywordtype}{character(len=40)}, \textcolor{keywordtype}{dimension(MAX\_FIELDS\_)} :: \&}
\DoxyCodeLine{415     Tr\_names, Tr\_units}
\DoxyCodeLine{416   \textcolor{keywordtype}{integer} :: nTr\_stocks}
\DoxyCodeLine{417   \textcolor{keywordtype}{integer} :: iyear, imonth, iday, ihour, iminute, isecond, itick \textcolor{comment}{! For call to get\_date()}}
\DoxyCodeLine{418   \textcolor{keywordtype}{logical} :: local\_open\_BC}
\DoxyCodeLine{419   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()}
\DoxyCodeLine{420 }
\DoxyCodeLine{421  \textcolor{comment}{! A description for output of each of the fields.}}
\DoxyCodeLine{422   \textcolor{keywordtype}{type}(vardesc) :: vars(NUM\_FIELDS+MAX\_FIELDS\_)}
\DoxyCodeLine{423 }
\DoxyCodeLine{424   \textcolor{comment}{! write\_energy\_time is the next integral multiple of energysavedays.}}
\DoxyCodeLine{425   dt\_force = set\_time(seconds=2) ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dt\_forcing)) dt\_force = dt\_forcing}
\DoxyCodeLine{426   \textcolor{keywordflow}{if} (cs\%previous\_calls == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{427     \textcolor{keywordflow}{if} (cs\%energysave\_geometric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{428       \textcolor{keywordflow}{if} (cs\%energysavedays\_geometric < cs\%energysavedays) \textcolor{keywordflow}{then}}
\DoxyCodeLine{429         cs\%write\_energy\_time = day + cs\%energysavedays\_geometric}
\DoxyCodeLine{430         cs\%geometric\_end\_time = cs\%Start\_time + cs\%energysavedays * \&}
\DoxyCodeLine{431           (1 + (day - cs\%Start\_time) / cs\%energysavedays)}
\DoxyCodeLine{432       \textcolor{keywordflow}{else}}
\DoxyCodeLine{433         cs\%write\_energy\_time = cs\%Start\_time + cs\%energysavedays * \&}
\DoxyCodeLine{434           (1 + (day - cs\%Start\_time) / cs\%energysavedays)}
\DoxyCodeLine{435 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{436     \textcolor{keywordflow}{else}}
\DoxyCodeLine{437       cs\%write\_energy\_time = cs\%Start\_time + cs\%energysavedays * \&}
\DoxyCodeLine{438         (1 + (day - cs\%Start\_time) / cs\%energysavedays)}
\DoxyCodeLine{439 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{440   \textcolor{keywordflow}{elseif} (day + (dt\_force/2) <= cs\%write\_energy\_time) \textcolor{keywordflow}{then}}
\DoxyCodeLine{441     \textcolor{keywordflow}{return}  \textcolor{comment}{! Do not write this step}}
\DoxyCodeLine{442   \textcolor{keywordflow}{else} \textcolor{comment}{! Determine the next write time before proceeding}}
\DoxyCodeLine{443     \textcolor{keywordflow}{if} (cs\%energysave\_geometric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{444       \textcolor{keywordflow}{if} (cs\%write\_energy\_time + cs\%energysavedays\_geometric >= \&}
\DoxyCodeLine{445           cs\%geometric\_end\_time) \textcolor{keywordflow}{then}}
\DoxyCodeLine{446         cs\%write\_energy\_time = cs\%geometric\_end\_time}
\DoxyCodeLine{447         cs\%energysave\_geometric = .false.  \textcolor{comment}{! stop geometric progression}}
\DoxyCodeLine{448       \textcolor{keywordflow}{else}}
\DoxyCodeLine{449         cs\%write\_energy\_time = cs\%write\_energy\_time + cs\%energysavedays\_geometric}
\DoxyCodeLine{450 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{451       cs\%energysavedays\_geometric = cs\%energysavedays\_geometric*2}
\DoxyCodeLine{452     \textcolor{keywordflow}{else}}
\DoxyCodeLine{453       cs\%write\_energy\_time = cs\%write\_energy\_time + cs\%energysavedays}
\DoxyCodeLine{454 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{455 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{456 }
\DoxyCodeLine{457   num\_nc\_fields = 17}
\DoxyCodeLine{458   \textcolor{keywordflow}{if} (.not.cs\%use\_temperature) num\_nc\_fields = 11}
\DoxyCodeLine{459   vars(1) = var\_desc(\textcolor{stringliteral}{"Ntrunc"},\textcolor{stringliteral}{"Nondim"},\textcolor{stringliteral}{"Number of Velocity Truncations"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{460   vars(2) = var\_desc(\textcolor{stringliteral}{"En"},\textcolor{stringliteral}{"Joules"},\textcolor{stringliteral}{"Total Energy"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{461   vars(3) = var\_desc(\textcolor{stringliteral}{"APE"},\textcolor{stringliteral}{"Joules"},\textcolor{stringliteral}{"Total Interface APE"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'i'})}
\DoxyCodeLine{462   vars(4) = var\_desc(\textcolor{stringliteral}{"KE"},\textcolor{stringliteral}{"Joules"},\textcolor{stringliteral}{"Total Layer KE"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'L'})}
\DoxyCodeLine{463   vars(5) = var\_desc(\textcolor{stringliteral}{"H0"},\textcolor{stringliteral}{"meter"},\textcolor{stringliteral}{"Zero APE Depth of Interface"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'i'})}
\DoxyCodeLine{464   vars(6) = var\_desc(\textcolor{stringliteral}{"Mass\_lay"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Total Layer Mass"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'L'})}
\DoxyCodeLine{465   vars(7) = var\_desc(\textcolor{stringliteral}{"Mass"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Total Mass"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{466   vars(8) = var\_desc(\textcolor{stringliteral}{"Mass\_chg"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Total Mass Change between Entries"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{467   vars(9) = var\_desc(\textcolor{stringliteral}{"Mass\_anom"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Anomalous Total Mass Change"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{468   vars(10) = var\_desc(\textcolor{stringliteral}{"max\_CFL\_trans"},\textcolor{stringliteral}{"Nondim"},\textcolor{stringliteral}{"Maximum finite-volume CFL"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{469   vars(11) = var\_desc(\textcolor{stringliteral}{"max\_CFL\_lin"},\textcolor{stringliteral}{"Nondim"},\textcolor{stringliteral}{"Maximum finite-difference CFL"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{470   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{471     vars(12) = var\_desc(\textcolor{stringliteral}{"Salt"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Total Salt"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{472     vars(13) = var\_desc(\textcolor{stringliteral}{"Salt\_chg"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Total Salt Change between Entries"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{473     vars(14) = var\_desc(\textcolor{stringliteral}{"Salt\_anom"},\textcolor{stringliteral}{"kg"},\textcolor{stringliteral}{"Anomalous Total Salt Change"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{474     vars(15) = var\_desc(\textcolor{stringliteral}{"Heat"},\textcolor{stringliteral}{"Joules"},\textcolor{stringliteral}{"Total Heat"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{475     vars(16) = var\_desc(\textcolor{stringliteral}{"Heat\_chg"},\textcolor{stringliteral}{"Joules"},\textcolor{stringliteral}{"Total Heat Change between Entries"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{476     vars(17) = var\_desc(\textcolor{stringliteral}{"Heat\_anom"},\textcolor{stringliteral}{"Joules"},\textcolor{stringliteral}{"Anomalous Total Heat Change"},\textcolor{stringliteral}{'1'},\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{477 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{478 }
\DoxyCodeLine{479   local\_open\_bc = .false.}
\DoxyCodeLine{480   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{481     local\_open\_bc = (obc\%open\_u\_BCs\_exist\_globally .or. obc\%open\_v\_BCs\_exist\_globally)}
\DoxyCodeLine{482 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{483 }
\DoxyCodeLine{484   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{485   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{486   isr = is - (g\%isd-1) ; ier = ie - (g\%isd-1) ; jsr = js - (g\%jsd-1) ; jer = je - (g\%jsd-1)}
\DoxyCodeLine{487 }
\DoxyCodeLine{488 }
\DoxyCodeLine{489   hl2\_to\_kg = gv\%H\_to\_kg\_m2*us\%L\_to\_m**2}
\DoxyCodeLine{490 }
\DoxyCodeLine{491   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{492          \textcolor{stringliteral}{"write\_energy: Module must be initialized before it is used."})}
\DoxyCodeLine{493 }
\DoxyCodeLine{494   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{495     areatm(i,j) = g\%mask2dT(i,j)*g\%areaT(i,j)}
\DoxyCodeLine{496 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{497 }
\DoxyCodeLine{498   \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{499     tmp1(:,:,:) = 0.0}
\DoxyCodeLine{500     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{501       tmp1(i,j,k) = h(i,j,k) * (hl2\_to\_kg*areatm(i,j))}
\DoxyCodeLine{502 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{503 }
\DoxyCodeLine{504     \textcolor{comment}{! This block avoids using the points beyond an open boundary condition}}
\DoxyCodeLine{505     \textcolor{comment}{! in the accumulation of mass, but perhaps it would be unnecessary if there}}
\DoxyCodeLine{506     \textcolor{comment}{! were a more judicious use of masks in the loops 4 or 7 lines above.}}
\DoxyCodeLine{507     \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{508       \textcolor{keywordflow}{do} ns=1, obc\%number\_of\_segments}
\DoxyCodeLine{509         segment => obc\%segment(ns)}
\DoxyCodeLine{510         \textcolor{keywordflow}{if} (.not. segment\%on\_pe .or. segment\%specified) cycle}
\DoxyCodeLine{511         i=segment\%HI\%IsdB ; j=segment\%HI\%JsdB}
\DoxyCodeLine{512         \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{513           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed}
\DoxyCodeLine{514             tmp1(i+1,j,k) = 0.0}
\DoxyCodeLine{515 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{516         \textcolor{keywordflow}{elseif} (segment\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{517           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment\%HI\%jsd,segment\%HI\%jed}
\DoxyCodeLine{518             tmp1(i,j,k) = 0.0}
\DoxyCodeLine{519 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{520         \textcolor{keywordflow}{elseif} (segment\%direction == obc\_direction\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{521           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{522             tmp1(i,j+1,k) = 0.0}
\DoxyCodeLine{523 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{524         \textcolor{keywordflow}{elseif} (segment\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{525           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{526             tmp1(i,j,k) = 0.0}
\DoxyCodeLine{527 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{528 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{529 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{530 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{531 }
\DoxyCodeLine{532     mass\_tot = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmp1, isr, ier, jsr, jer, sums=mass\_lay, efp\_sum=mass\_efp)}
\DoxyCodeLine{533     \textcolor{keywordflow}{do} k=1,nz ; vol\_lay(k) = (us\%m\_to\_L**2*gv\%H\_to\_Z/gv\%H\_to\_kg\_m2)*mass\_lay(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{534   \textcolor{keywordflow}{else}}
\DoxyCodeLine{535     tmp1(:,:,:) = 0.0}
\DoxyCodeLine{536     \textcolor{keywordflow}{if} (cs\%do\_APE\_calc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{537       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{538         tmp1(i,j,k) = hl2\_to\_kg * h(i,j,k) * areatm(i,j)}
\DoxyCodeLine{539 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{540       mass\_tot = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmp1, isr, ier, jsr, jer, sums=mass\_lay, efp\_sum=mass\_efp)}
\DoxyCodeLine{541 }
\DoxyCodeLine{542       \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, eta)}
\DoxyCodeLine{543       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{544         tmp1(i,j,k) = us\%Z\_to\_m*us\%L\_to\_m**2*(eta(i,j,k)-eta(i,j,k+1)) * areatm(i,j)}
\DoxyCodeLine{545 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{546       vol\_tot = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmp1, isr, ier, jsr, jer, sums=vol\_lay)}
\DoxyCodeLine{547       \textcolor{keywordflow}{do} k=1,nz ; vol\_lay(k) = us\%m\_to\_Z*us\%m\_to\_L**2 * vol\_lay(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{548     \textcolor{keywordflow}{else}}
\DoxyCodeLine{549       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{550         tmp1(i,j,k) = hl2\_to\_kg * h(i,j,k) * areatm(i,j)}
\DoxyCodeLine{551 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{552       mass\_tot = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmp1, isr, ier, jsr, jer, sums=mass\_lay, efp\_sum=mass\_efp)}
\DoxyCodeLine{553       \textcolor{keywordflow}{do} k=1,nz ; vol\_lay(k) = us\%m\_to\_Z*us\%m\_to\_L**2*us\%kg\_m3\_to\_R * (mass\_lay(k) / gv\%Rho0) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{554 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{555 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Boussinesq}}
\DoxyCodeLine{556 }
\DoxyCodeLine{557   ntr\_stocks = 0}
\DoxyCodeLine{558   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tracer\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{559     \textcolor{keyword}{call }call\_tracer\_stocks(h, tr\_stocks, g, gv, tracer\_csp, stock\_names=tr\_names, \&}
\DoxyCodeLine{560                             stock\_units=tr\_units, num\_stocks=ntr\_stocks,\&}
\DoxyCodeLine{561                             got\_min\_max=tr\_minmax\_got, global\_min=tr\_min, global\_max=tr\_max, \&}
\DoxyCodeLine{562                             xgmin=tr\_min\_x, ygmin=tr\_min\_y, zgmin=tr\_min\_z,\&}
\DoxyCodeLine{563                             xgmax=tr\_max\_x, ygmax=tr\_max\_y, zgmax=tr\_max\_z)}
\DoxyCodeLine{564     \textcolor{keywordflow}{if} (ntr\_stocks > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{565       \textcolor{keywordflow}{do} m=1,ntr\_stocks}
\DoxyCodeLine{566         vars(num\_nc\_fields+m) = var\_desc(tr\_names(m), units=tr\_units(m), \&}
\DoxyCodeLine{567                       longname=tr\_names(m), hor\_grid=\textcolor{stringliteral}{'1'}, z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{568 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{569       num\_nc\_fields = num\_nc\_fields + ntr\_stocks}
\DoxyCodeLine{570 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{571 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{572 }
\DoxyCodeLine{573   \textcolor{keywordflow}{if} (cs\%previous\_calls == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{574 }
\DoxyCodeLine{575     cs\%mass\_prev\_EFP = mass\_efp}
\DoxyCodeLine{576     cs\%fresh\_water\_in\_EFP = real\_to\_efp(0.0)}
\DoxyCodeLine{577     \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{578       cs\%net\_salt\_in\_EFP = real\_to\_efp(0.0)  ; cs\%net\_heat\_in\_EFP = real\_to\_efp(0.0)}
\DoxyCodeLine{579 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{580 }
\DoxyCodeLine{581     \textcolor{comment}{!  Reopen or create a text output file, with an explanatory header line.}}
\DoxyCodeLine{582     \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}}
\DoxyCodeLine{583       \textcolor{keywordflow}{if} (day > cs\%Start\_time) \textcolor{keywordflow}{then}}
\DoxyCodeLine{584         \textcolor{keyword}{call }open\_file(cs\%fileenergy\_ascii, trim(cs\%energyfile), \&}
\DoxyCodeLine{585                        action=append\_file, form=ascii\_file, nohdrs=.true.)}
\DoxyCodeLine{586       \textcolor{keywordflow}{else}}
\DoxyCodeLine{587         \textcolor{keyword}{call }open\_file(cs\%fileenergy\_ascii, trim(cs\%energyfile), \&}
\DoxyCodeLine{588                        action=writeonly\_file, form=ascii\_file, nohdrs=.true.)}
\DoxyCodeLine{589         \textcolor{keywordflow}{if} (abs(cs\%timeunit - 86400.0) < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{590           \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{591             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'("  Step,",7x,"Day,  Truncs,      \&}}
\DoxyCodeLine{592 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&Energy/Mass,      Maximum CFL,  Mean Sea Level,  Total Mass,  Mean Salin, \&}}
\DoxyCodeLine{593 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&Mean Temp, Frac Mass Err,   Salin Err,    Temp Err")'})}
\DoxyCodeLine{594             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'(12x,"[days]",17x,"[m2 s-2]",11x,"[Nondim]",7x,"[m]",13x,\&}}
\DoxyCodeLine{595 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&"[kg]",9x,"[PSU]",6x,"[degC]",7x,"[Nondim]",8x,"[PSU]",8x,"[degC]")'})}
\DoxyCodeLine{596           \textcolor{keywordflow}{else}}
\DoxyCodeLine{597             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'("  Step,",7x,"Day,  Truncs,      \&}}
\DoxyCodeLine{598 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&Energy/Mass,      Maximum CFL,  Mean sea level,   Total Mass,    Frac Mass Err")'})}
\DoxyCodeLine{599             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'(12x,"[days]",17x,"[m2 s-2]",11x,"[Nondim]",8x,"[m]",13x,\&}}
\DoxyCodeLine{600 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&"[kg]",11x,"[Nondim]")'})}
\DoxyCodeLine{601 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{602         \textcolor{keywordflow}{else}}
\DoxyCodeLine{603           \textcolor{keywordflow}{if} ((cs\%timeunit >= 0.99) .and. (cs\%timeunit < 1.01)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{604             time\_units = \textcolor{stringliteral}{"           [seconds]     "}}
\DoxyCodeLine{605           \textcolor{keywordflow}{elseif} ((cs\%timeunit >= 3599.0) .and. (cs\%timeunit < 3601.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{606             time\_units = \textcolor{stringliteral}{"            [hours]      "}}
\DoxyCodeLine{607           \textcolor{keywordflow}{elseif} ((cs\%timeunit >= 86399.0) .and. (cs\%timeunit < 86401.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{608             time\_units = \textcolor{stringliteral}{"             [days]      "}}
\DoxyCodeLine{609           \textcolor{keywordflow}{elseif} ((cs\%timeunit >= 3.0e7) .and. (cs\%timeunit < 3.2e7)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{610             time\_units = \textcolor{stringliteral}{"            [years]      "}}
\DoxyCodeLine{611           \textcolor{keywordflow}{else}}
\DoxyCodeLine{612             \textcolor{keyword}{write}(time\_units,\textcolor{stringliteral}{'(9x,"[",es8.2," s]    ")'}) cs\%timeunit}
\DoxyCodeLine{613 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{614 }
\DoxyCodeLine{615           \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{616             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'("  Step,",7x,"Time, Truncs,      \&}}
\DoxyCodeLine{617 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&Energy/Mass,      Maximum CFL,  Mean Sea Level,  Total Mass,  Mean Salin, \&}}
\DoxyCodeLine{618 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&Mean Temp, Frac Mass Err,   Salin Err,    Temp Err")'})}
\DoxyCodeLine{619             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'(A25,10x,"[m2 s-2]",11x,"[Nondim]",7x,"[m]",13x,\&}}
\DoxyCodeLine{620 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&"[kg]",9x,"[PSU]",6x,"[degC]",7x,"[Nondim]",8x,"[PSU]",6x,\&}}
\DoxyCodeLine{621 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&"[degC]")'}) time\_units}
\DoxyCodeLine{622           \textcolor{keywordflow}{else}}
\DoxyCodeLine{623             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'("  Step,",7x,"Time, Truncs,      \&}}
\DoxyCodeLine{624 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&Energy/Mass,      Maximum CFL,  Mean sea level,   Total Mass,    Frac Mass Err")'})}
\DoxyCodeLine{625             \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'(A25,10x,"[m2 s-2]",11x,"[Nondim]",8x,"[m]",13x,\&}}
\DoxyCodeLine{626 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&"[kg]",11x,"[Nondim]")'}) time\_units}
\DoxyCodeLine{627 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{628 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{629 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{630 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{631 }
\DoxyCodeLine{632     energypath\_nc = trim(cs\%energyfile) // \textcolor{stringliteral}{".nc"}}
\DoxyCodeLine{633     \textcolor{keywordflow}{if} (day > cs\%Start\_time) \textcolor{keywordflow}{then}}
\DoxyCodeLine{634       \textcolor{keyword}{call }reopen\_file(cs\%fileenergy\_nc, trim(energypath\_nc), vars, \&}
\DoxyCodeLine{635                        num\_nc\_fields, cs\%fields, single\_file, cs\%timeunit, \&}
\DoxyCodeLine{636                        g=g, gv=gv)}
\DoxyCodeLine{637     \textcolor{keywordflow}{else}}
\DoxyCodeLine{638       \textcolor{keyword}{call }create\_file(cs\%fileenergy\_nc, trim(energypath\_nc), vars, \&}
\DoxyCodeLine{639                        num\_nc\_fields, cs\%fields, single\_file, cs\%timeunit, \&}
\DoxyCodeLine{640                        g=g, gv=gv)}
\DoxyCodeLine{641 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{642 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{643 }
\DoxyCodeLine{644   \textcolor{keywordflow}{if} (cs\%do\_APE\_calc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{645     lbelow = 1 ; volbelow = 0.0}
\DoxyCodeLine{646     \textcolor{keywordflow}{do} k=nz,1,-1}
\DoxyCodeLine{647       volbelow = volbelow + vol\_lay(k)}
\DoxyCodeLine{648       \textcolor{keywordflow}{if} ((volbelow >= cs\%DL(cs\%lH(k))\%vol\_below) .and. \&}
\DoxyCodeLine{649           (volbelow < cs\%DL(cs\%lH(k)+1)\%vol\_below)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{650         l = cs\%lH(k)}
\DoxyCodeLine{651       \textcolor{keywordflow}{else}}
\DoxyCodeLine{652         labove=cs\%list\_size+1}
\DoxyCodeLine{653         l = (labove + lbelow) / 2}
\DoxyCodeLine{654         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (l > lbelow)}
\DoxyCodeLine{655           \textcolor{keywordflow}{if} (volbelow < cs\%DL(l)\%vol\_below) \textcolor{keywordflow}{then} ; labove = l}
\DoxyCodeLine{656           \textcolor{keywordflow}{else} ; lbelow = l ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{657           l = (labove + lbelow) / 2}
\DoxyCodeLine{658 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{659         cs\%lH(k) = l}
\DoxyCodeLine{660 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{661       lbelow = l}
\DoxyCodeLine{662       z\_0ape(k) = cs\%DL(l)\%depth - (volbelow - cs\%DL(l)\%vol\_below) / cs\%DL(l)\%area}
\DoxyCodeLine{663 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{664     z\_0ape(nz+1) = cs\%DL(2)\%depth}
\DoxyCodeLine{665 }
\DoxyCodeLine{666     \textcolor{comment}{!   Calculate the Available Potential Energy integrated over each interface.  With a nonlinear}}
\DoxyCodeLine{667     \textcolor{comment}{! equation of state or with a bulk mixed layer this calculation is only approximate.}}
\DoxyCodeLine{668     \textcolor{comment}{! With an ALE model this does not make sense and should be revisited.}}
\DoxyCodeLine{669     pe\_scale\_factor = us\%RZ\_to\_kg\_m2*us\%L\_to\_m**2*us\%L\_T\_to\_m\_s**2}
\DoxyCodeLine{670     pe\_pt(:,:,:) = 0.0}
\DoxyCodeLine{671     \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{672       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{673         hbelow = 0.0}
\DoxyCodeLine{674         \textcolor{keywordflow}{do} k=nz,1,-1}
\DoxyCodeLine{675           hbelow = hbelow + h(i,j,k) * gv\%H\_to\_Z}
\DoxyCodeLine{676           hint = z\_0ape(k) + (hbelow - g\%bathyT(i,j))}
\DoxyCodeLine{677           hbot = z\_0ape(k) - g\%bathyT(i,j)}
\DoxyCodeLine{678           hbot = (hbot + abs(hbot)) * 0.5}
\DoxyCodeLine{679           pe\_pt(i,j,k) = (0.5 * pe\_scale\_factor * areatm(i,j)) * (gv\%Rho0*gv\%g\_prime(k)) * \&}
\DoxyCodeLine{680                   (hint * hint - hbot * hbot)}
\DoxyCodeLine{681 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{682 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{683     \textcolor{keywordflow}{else}}
\DoxyCodeLine{684       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{685         \textcolor{keywordflow}{do} k=nz,1,-1}
\DoxyCodeLine{686           hint = z\_0ape(k) + eta(i,j,k)  \textcolor{comment}{! eta and H\_0 have opposite signs.}}
\DoxyCodeLine{687           hbot = max(z\_0ape(k) - g\%bathyT(i,j), 0.0)}
\DoxyCodeLine{688           pe\_pt(i,j,k) = (0.5 * pe\_scale\_factor * areatm(i,j) * (gv\%Rho0*gv\%g\_prime(k))) * \&}
\DoxyCodeLine{689                   (hint * hint - hbot * hbot)}
\DoxyCodeLine{690 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{691 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{692 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{693 }
\DoxyCodeLine{694     pe\_tot = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(pe\_pt, isr, ier, jsr, jer, sums=pe)}
\DoxyCodeLine{695     \textcolor{keywordflow}{do} k=1,nz+1 ; h\_0ape(k) = us\%Z\_to\_m*z\_0ape(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{696   \textcolor{keywordflow}{else}}
\DoxyCodeLine{697     pe\_tot = 0.0}
\DoxyCodeLine{698     \textcolor{keywordflow}{do} k=1,nz+1 ; pe(k) = 0.0 ; h\_0ape(k) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{699 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{700 }
\DoxyCodeLine{701 \textcolor{comment}{! Calculate the Kinetic Energy integrated over each layer.}}
\DoxyCodeLine{702   ke\_scale\_factor = hl2\_to\_kg*us\%L\_T\_to\_m\_s**2}
\DoxyCodeLine{703   tmp1(:,:,:) = 0.0}
\DoxyCodeLine{704   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{705     tmp1(i,j,k) = (0.25 * ke\_scale\_factor * (areatm(i,j) * h(i,j,k))) * \&}
\DoxyCodeLine{706             ((u(i-1,j,k)**2 + u(i,j,k)**2) + (v(i,j-1,k)**2 + v(i,j,k)**2))}
\DoxyCodeLine{707 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{708 }
\DoxyCodeLine{709   ke\_tot = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmp1, isr, ier, jsr, jer, sums=ke)}
\DoxyCodeLine{710 }
\DoxyCodeLine{711   toten = ke\_tot + pe\_tot}
\DoxyCodeLine{712 }
\DoxyCodeLine{713   salt = 0.0 ; heat = 0.0}
\DoxyCodeLine{714   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{715     temp\_int(:,:) = 0.0 ; salt\_int(:,:) = 0.0}
\DoxyCodeLine{716     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{717       salt\_int(i,j) = salt\_int(i,j) + tv\%S(i,j,k) * \&}
\DoxyCodeLine{718                       (h(i,j,k)*(hl2\_to\_kg * areatm(i,j)))}
\DoxyCodeLine{719       temp\_int(i,j) = temp\_int(i,j) + (us\%Q\_to\_J\_kg*tv\%C\_p * tv\%T(i,j,k)) * \&}
\DoxyCodeLine{720                       (h(i,j,k)*(hl2\_to\_kg * areatm(i,j)))}
\DoxyCodeLine{721 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{722     salt\_efp = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}(salt\_int, isr, ier, jsr, jer, only\_on\_pe=.true.)}
\DoxyCodeLine{723     heat\_efp = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}(temp\_int, isr, ier, jsr, jer, only\_on\_pe=.true.)}
\DoxyCodeLine{724 }
\DoxyCodeLine{725     \textcolor{comment}{! Combining the sums avoids multiple blocking all-PE updates.}}
\DoxyCodeLine{726     efp\_list(1) = salt\_efp ;  efp\_list(2) = heat\_efp ; efp\_list(3) = cs\%fresh\_water\_in\_EFP}
\DoxyCodeLine{727     efp\_list(4) = cs\%net\_salt\_in\_EFP ; efp\_list(5) = cs\%net\_heat\_in\_EFP}
\DoxyCodeLine{728     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(efp\_list, 5)}
\DoxyCodeLine{729     \textcolor{comment}{! Return the globally summed values to the original variables.}}
\DoxyCodeLine{730     salt\_efp = efp\_list(1) ; heat\_efp = efp\_list(2) ; cs\%fresh\_water\_in\_EFP = efp\_list(3)}
\DoxyCodeLine{731     cs\%net\_salt\_in\_EFP = efp\_list(4) ; cs\%net\_heat\_in\_EFP = efp\_list(5)}
\DoxyCodeLine{732 }
\DoxyCodeLine{733     salt = efp\_to\_real(salt\_efp)}
\DoxyCodeLine{734     heat = efp\_to\_real(heat\_efp)}
\DoxyCodeLine{735   \textcolor{keywordflow}{else}}
\DoxyCodeLine{736     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(cs\%fresh\_water\_in\_EFP)}
\DoxyCodeLine{737 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{738 }
\DoxyCodeLine{739 \textcolor{comment}{! Calculate the maximum CFL numbers.}}
\DoxyCodeLine{740   max\_cfl(1:2) = 0.0}
\DoxyCodeLine{741   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq}
\DoxyCodeLine{742     cfl\_iarea = g\%IareaT(i,j)}
\DoxyCodeLine{743     \textcolor{keywordflow}{if} (u(i,j,k) < 0.0) \&}
\DoxyCodeLine{744       cfl\_iarea = g\%IareaT(i+1,j)}
\DoxyCodeLine{745 }
\DoxyCodeLine{746     cfl\_trans = abs(u(i,j,k) * cs\%dt\_in\_T) * (g\%dy\_Cu(i,j) * cfl\_iarea)}
\DoxyCodeLine{747     cfl\_lin = abs(u(i,j,k) * cs\%dt\_in\_T) * g\%IdxCu(i,j)}
\DoxyCodeLine{748     max\_cfl(1) = max(max\_cfl(1), cfl\_trans)}
\DoxyCodeLine{749     max\_cfl(2) = max(max\_cfl(2), cfl\_lin)}
\DoxyCodeLine{750 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{751   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{752     cfl\_iarea = g\%IareaT(i,j)}
\DoxyCodeLine{753     \textcolor{keywordflow}{if} (v(i,j,k) < 0.0) \&}
\DoxyCodeLine{754       cfl\_iarea = g\%IareaT(i,j+1)}
\DoxyCodeLine{755 }
\DoxyCodeLine{756     cfl\_trans = abs(v(i,j,k) * cs\%dt\_in\_T) * (g\%dx\_Cv(i,j) * cfl\_iarea)}
\DoxyCodeLine{757     cfl\_lin = abs(v(i,j,k) * cs\%dt\_in\_T) * g\%IdyCv(i,j)}
\DoxyCodeLine{758     max\_cfl(1) = max(max\_cfl(1), cfl\_trans)}
\DoxyCodeLine{759     max\_cfl(2) = max(max\_cfl(2), cfl\_lin)}
\DoxyCodeLine{760 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{761 }
\DoxyCodeLine{762   \textcolor{keyword}{call }sum\_across\_pes(cs\%ntrunc)}
\DoxyCodeLine{763   \textcolor{comment}{!   Sum the various quantities across all the processors.  This sum is NOT}}
\DoxyCodeLine{764   \textcolor{comment}{! guaranteed to be bitwise reproducible, even on the same decomposition.}}
\DoxyCodeLine{765   \textcolor{comment}{!   The sum of Tr\_stocks should be reimplemented using the reproducing sums.}}
\DoxyCodeLine{766   \textcolor{keywordflow}{if} (ntr\_stocks > 0) \textcolor{keyword}{call }sum\_across\_pes(tr\_stocks,ntr\_stocks)}
\DoxyCodeLine{767 }
\DoxyCodeLine{768   \textcolor{keyword}{call }max\_across\_pes(max\_cfl, 2)}
\DoxyCodeLine{769   irho0 = 1.0 / (us\%R\_to\_kg\_m3*gv\%Rho0)}
\DoxyCodeLine{770 }
\DoxyCodeLine{771   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{772     \textcolor{keywordflow}{if} (cs\%previous\_calls == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{773       cs\%salt\_prev\_EFP = salt\_efp ; cs\%heat\_prev\_EFP = heat\_efp}
\DoxyCodeLine{774 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{775     salt\_chg\_efp = salt\_efp - cs\%salt\_prev\_EFP}
\DoxyCodeLine{776     salt\_chg = efp\_to\_real(salt\_chg\_efp)}
\DoxyCodeLine{777     salt\_anom\_efp = salt\_chg\_efp - cs\%net\_salt\_in\_EFP}
\DoxyCodeLine{778     salt\_anom = efp\_to\_real(salt\_anom\_efp)}
\DoxyCodeLine{779     heat\_chg\_efp = heat\_efp - cs\%heat\_prev\_EFP}
\DoxyCodeLine{780     heat\_chg = efp\_to\_real(heat\_chg\_efp)}
\DoxyCodeLine{781     heat\_anom\_efp = heat\_chg\_efp - cs\%net\_heat\_in\_EFP}
\DoxyCodeLine{782     heat\_anom = efp\_to\_real(heat\_anom\_efp)}
\DoxyCodeLine{783 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{784 }
\DoxyCodeLine{785   mass\_chg\_efp = mass\_efp - cs\%mass\_prev\_EFP}
\DoxyCodeLine{786   mass\_anom\_efp = mass\_chg\_efp - cs\%fresh\_water\_in\_EFP}
\DoxyCodeLine{787   mass\_anom = efp\_to\_real(mass\_anom\_efp)}
\DoxyCodeLine{788   \textcolor{keywordflow}{if} (cs\%use\_temperature .and. .not.gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{789     \textcolor{comment}{! net\_salt\_input needs to be converted from ppt m s-1 to kg m-2 s-1.}}
\DoxyCodeLine{790     mass\_anom = mass\_anom - 0.001*efp\_to\_real(cs\%net\_salt\_in\_EFP)}
\DoxyCodeLine{791 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{792   mass\_chg = efp\_to\_real(mass\_chg\_efp)}
\DoxyCodeLine{793 }
\DoxyCodeLine{794   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{795     salin = salt / mass\_tot ; salin\_anom = salt\_anom / mass\_tot}
\DoxyCodeLine{796    \textcolor{comment}{! salin\_chg = Salt\_chg / mass\_tot}}
\DoxyCodeLine{797     temp = heat / (mass\_tot*us\%Q\_to\_J\_kg*tv\%C\_p) ; temp\_anom = heat\_anom / (mass\_tot*us\%Q\_to\_J\_kg*tv\%C\_p)}
\DoxyCodeLine{798 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{799   en\_mass = toten / mass\_tot}
\DoxyCodeLine{800 }
\DoxyCodeLine{801   \textcolor{keyword}{call }get\_time(day, start\_of\_day, num\_days)}
\DoxyCodeLine{802   date\_stamped = (cs\%date\_stamped\_output .and. (get\_calendar\_type() /= no\_calendar))}
\DoxyCodeLine{803   \textcolor{keywordflow}{if} (date\_stamped) \&}
\DoxyCodeLine{804     \textcolor{keyword}{call }get\_date(day, iyear, imonth, iday, ihour, iminute, isecond, itick)}
\DoxyCodeLine{805   \textcolor{keywordflow}{if} (abs(cs\%timeunit - 86400.0) < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{806     reday = real(num\_days)+ (real(start\_of\_day)/86400.0)}
\DoxyCodeLine{807     mesg\_intro = \textcolor{stringliteral}{"MOM Day "}}
\DoxyCodeLine{808   \textcolor{keywordflow}{else}}
\DoxyCodeLine{809     reday = real(num\_days)*(86400.0/cs\%timeunit) + \&}
\DoxyCodeLine{810 \textcolor{keywordtype}{            REAL}(start\_of\_day)/abs(CS\%timeunit)}
\DoxyCodeLine{811     mesg\_intro = \textcolor{stringliteral}{"MOM Time "}}
\DoxyCodeLine{812 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{813   \textcolor{keywordflow}{if} (reday < 1.0e8) \textcolor{keywordflow}{then} ;      \textcolor{keyword}{write}(day\_str, \textcolor{stringliteral}{'(F12.3)'}) reday}
\DoxyCodeLine{814   \textcolor{keywordflow}{elseif} (reday < 1.0e11) \textcolor{keywordflow}{then} ; \textcolor{keyword}{write}(day\_str, \textcolor{stringliteral}{'(F15.3)'}) reday}
\DoxyCodeLine{815   \textcolor{keywordflow}{else} ;                         \textcolor{keyword}{write}(day\_str, \textcolor{stringliteral}{'(ES15.9)'}) reday ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{816 }
\DoxyCodeLine{817   \textcolor{keywordflow}{if}     (n < 1000000)   \textcolor{keywordflow}{then} ; \textcolor{keyword}{write}(n\_str, \textcolor{stringliteral}{'(I6)'})  n}
\DoxyCodeLine{818   \textcolor{keywordflow}{elseif} (n < 10000000)  \textcolor{keywordflow}{then} ; \textcolor{keyword}{write}(n\_str, \textcolor{stringliteral}{'(I7)'})  n}
\DoxyCodeLine{819   \textcolor{keywordflow}{elseif} (n < 100000000) \textcolor{keywordflow}{then} ; \textcolor{keyword}{write}(n\_str, \textcolor{stringliteral}{'(I8)'})  n}
\DoxyCodeLine{820   \textcolor{keywordflow}{else}                        ; \textcolor{keyword}{write}(n\_str, \textcolor{stringliteral}{'(I10)'}) n ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{821 }
\DoxyCodeLine{822   \textcolor{keywordflow}{if} (date\_stamped) \textcolor{keywordflow}{then}}
\DoxyCodeLine{823     \textcolor{keyword}{write}(date\_str,\textcolor{stringliteral}{'("MOM Date",i7,2("/",i2.2)," ",i2.2,2(":",i2.2))'}) \&}
\DoxyCodeLine{824        iyear, imonth, iday, ihour, iminute, isecond}
\DoxyCodeLine{825   \textcolor{keywordflow}{else}}
\DoxyCodeLine{826     date\_str = trim(mesg\_intro)//trim(day\_str)}
\DoxyCodeLine{827 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{828 }
\DoxyCodeLine{829   \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}}
\DoxyCodeLine{830     \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{831         \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'(A," ",A,": En ",ES12.6, ", MaxCFL ", F8.5, ", Mass ", \&}}
\DoxyCodeLine{832 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \& ES18.12, ", Salt ", F15.11,", Temp ", F15.11)'}) \&}
\DoxyCodeLine{833           trim(date\_str), trim(n\_str), en\_mass, max\_cfl(1), mass\_tot, salin, temp}
\DoxyCodeLine{834     \textcolor{keywordflow}{else}}
\DoxyCodeLine{835         \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'(A," ",A,": En ",ES12.6, ", MaxCFL ", F8.5, ", Mass ", \&}}
\DoxyCodeLine{836 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \& ES18.12)'}) \&}
\DoxyCodeLine{837           trim(date\_str), trim(n\_str), en\_mass, max\_cfl(1), mass\_tot}
\DoxyCodeLine{838 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{839 }
\DoxyCodeLine{840     \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{841       \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'(A,",",A,",", I6,", En ",ES22.16, \&}}
\DoxyCodeLine{842 \textcolor{stringliteral}{}\textcolor{stringliteral}{                               \&", CFL ", F8.5, ", SL ",\&}}
\DoxyCodeLine{843 \textcolor{stringliteral}{}\textcolor{stringliteral}{                               \&es11.4,", M ",ES11.5,", S",f8.4,", T",f8.4,\&}}
\DoxyCodeLine{844 \textcolor{stringliteral}{}\textcolor{stringliteral}{                               \&", Me ",ES9.2,", Se ",ES9.2,", Te ",ES9.2)'}) \&}
\DoxyCodeLine{845             trim(n\_str), trim(day\_str), cs\%ntrunc, en\_mass, max\_cfl(1), \&}
\DoxyCodeLine{846             -h\_0ape(1), mass\_tot, salin, temp, mass\_anom/mass\_tot, salin\_anom, \&}
\DoxyCodeLine{847             temp\_anom}
\DoxyCodeLine{848     \textcolor{keywordflow}{else}}
\DoxyCodeLine{849       \textcolor{keyword}{write}(cs\%fileenergy\_ascii,\textcolor{stringliteral}{'(A,",",A,",", I6,", En ",ES22.16, \&}}
\DoxyCodeLine{850 \textcolor{stringliteral}{}\textcolor{stringliteral}{                                \&", CFL ", F8.5, ", SL ",\&}}
\DoxyCodeLine{851 \textcolor{stringliteral}{}\textcolor{stringliteral}{                                  \&ES11.4,", Mass ",ES11.5,", Me ",ES9.2)'}) \&}
\DoxyCodeLine{852             trim(n\_str), trim(day\_str), cs\%ntrunc, en\_mass, max\_cfl(1), \&}
\DoxyCodeLine{853             -h\_0ape(1), mass\_tot, mass\_anom/mass\_tot}
\DoxyCodeLine{854 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{855 }
\DoxyCodeLine{856     \textcolor{keywordflow}{if} (cs\%ntrunc > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{857       \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'(A," Energy/Mass:",ES12.5," Truncations ",I0)'}) \&}
\DoxyCodeLine{858         trim(date\_str), en\_mass, cs\%ntrunc}
\DoxyCodeLine{859 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{860 }
\DoxyCodeLine{861     \textcolor{keywordflow}{if} (cs\%write\_stocks) \textcolor{keywordflow}{then}}
\DoxyCodeLine{862       \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("    Total Energy: ",Z16.16,ES24.16)'}) toten, toten}
\DoxyCodeLine{863       \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("    Total Mass: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5," (",ES8.1,")")'}) \&}
\DoxyCodeLine{864             mass\_tot, mass\_chg, mass\_anom, mass\_anom/mass\_tot}
\DoxyCodeLine{865       \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{866         \textcolor{keywordflow}{if} (salt == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{867           \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("    Total Salt: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5)'}) \&}
\DoxyCodeLine{868               salt*0.001, salt\_chg*0.001, salt\_anom*0.001}
\DoxyCodeLine{869         \textcolor{keywordflow}{else}}
\DoxyCodeLine{870           \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("    Total Salt: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5," (",ES8.1,")")'}) \&}
\DoxyCodeLine{871               salt*0.001, salt\_chg*0.001, salt\_anom*0.001, salt\_anom/salt}
\DoxyCodeLine{872 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{873         \textcolor{keywordflow}{if} (heat == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{874           \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("    Total Heat: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5)'}) \&}
\DoxyCodeLine{875               heat, heat\_chg, heat\_anom}
\DoxyCodeLine{876         \textcolor{keywordflow}{else}}
\DoxyCodeLine{877           \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("    Total Heat: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5," (",ES8.1,")")'}) \&}
\DoxyCodeLine{878               heat, heat\_chg, heat\_anom, heat\_anom/heat}
\DoxyCodeLine{879 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{880 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{881       \textcolor{keywordflow}{do} m=1,ntr\_stocks}
\DoxyCodeLine{882 }
\DoxyCodeLine{883          \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'("      Total ",a,": ",ES24.16,X,a)'}) \&}
\DoxyCodeLine{884               trim(tr\_names(m)), tr\_stocks(m), trim(tr\_units(m))}
\DoxyCodeLine{885 }
\DoxyCodeLine{886          \textcolor{keywordflow}{if} (tr\_minmax\_got(m)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{887            \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'(64X,"Global Min:",ES24.16,X,"at: (", f7.2,","f7.2,","f8.2,")"  )'}) \&}
\DoxyCodeLine{888                 tr\_min(m),tr\_min\_x(m),tr\_min\_y(m),tr\_min\_z(m)}
\DoxyCodeLine{889            \textcolor{keyword}{write}(*,\textcolor{stringliteral}{'(64X,"Global Max:",ES24.16,X,"at: (", f7.2,","f7.2,","f8.2,")"  )'}) \&}
\DoxyCodeLine{890                 tr\_max(m),tr\_max\_x(m),tr\_max\_y(m),tr\_max\_z(m)}
\DoxyCodeLine{891 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{892 }
\DoxyCodeLine{893 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{894 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{895 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{896 }
\DoxyCodeLine{897   var = real(cs\%ntrunc)}
\DoxyCodeLine{898   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(1), var, reday)}
\DoxyCodeLine{899   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(2), toten, reday)}
\DoxyCodeLine{900   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(3), pe, reday)}
\DoxyCodeLine{901   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(4), ke, reday)}
\DoxyCodeLine{902   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(5), h\_0ape, reday)}
\DoxyCodeLine{903   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(6), mass\_lay, reday)}
\DoxyCodeLine{904 }
\DoxyCodeLine{905   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(7), mass\_tot, reday)}
\DoxyCodeLine{906   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(8), mass\_chg, reday)}
\DoxyCodeLine{907   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(9), mass\_anom, reday)}
\DoxyCodeLine{908   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(10), max\_cfl(1), reday)}
\DoxyCodeLine{909   \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(11), max\_cfl(2), reday)}
\DoxyCodeLine{910   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{911     \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(12), 0.001*salt, reday)}
\DoxyCodeLine{912     \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(13), 0.001*salt\_chg, reday)}
\DoxyCodeLine{913     \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(14), 0.001*salt\_anom, reday)}
\DoxyCodeLine{914     \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(15), heat, reday)}
\DoxyCodeLine{915     \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(16), heat\_chg, reday)}
\DoxyCodeLine{916     \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(17), heat\_anom, reday)}
\DoxyCodeLine{917     \textcolor{keywordflow}{do} m=1,ntr\_stocks}
\DoxyCodeLine{918       \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(17+m), tr\_stocks(m), reday)}
\DoxyCodeLine{919 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{920   \textcolor{keywordflow}{else}}
\DoxyCodeLine{921     \textcolor{keywordflow}{do} m=1,ntr\_stocks}
\DoxyCodeLine{922       \textcolor{keyword}{call }write\_field(cs\%fileenergy\_nc, cs\%fields(11+m), tr\_stocks(m), reday)}
\DoxyCodeLine{923 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{924 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{925 }
\DoxyCodeLine{926   \textcolor{keyword}{call }flush\_file(cs\%fileenergy\_nc)}
\DoxyCodeLine{927 }
\DoxyCodeLine{928   \textcolor{comment}{! The second (impossible-looking) test looks for a NaN in En\_mass.}}
\DoxyCodeLine{929   \textcolor{keywordflow}{if} ((en\_mass>cs\%max\_Energy) .or. \&}
\DoxyCodeLine{930      ((en\_mass>cs\%max\_Energy) .and. (en\_mass<cs\%max\_Energy))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{931     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Energy per unit mass of ",ES11.4," exceeds ",ES11.4)'}) \&}
\DoxyCodeLine{932                   en\_mass, cs\%max\_Energy}
\DoxyCodeLine{933     \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{934       \textcolor{stringliteral}{"write\_energy : Excessive energy per unit mass or NaNs forced model termination."})}
\DoxyCodeLine{935 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{936   \textcolor{keywordflow}{if} (cs\%ntrunc>cs\%maxtrunc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{937     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"write\_energy : Ocean velocity has been truncated too many times."})}
\DoxyCodeLine{938 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{939   cs\%ntrunc = 0}
\DoxyCodeLine{940   cs\%previous\_calls = cs\%previous\_calls + 1}
\DoxyCodeLine{941 }
\DoxyCodeLine{942   cs\%mass\_prev\_EFP = mass\_efp ; cs\%fresh\_water\_in\_EFP = real\_to\_efp(0.0)}
\DoxyCodeLine{943   \textcolor{keywordflow}{if} (cs\%use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{944     cs\%salt\_prev\_EFP = salt\_efp ; cs\%net\_salt\_in\_EFP = real\_to\_efp(0.0)}
\DoxyCodeLine{945     cs\%heat\_prev\_EFP = heat\_efp ; cs\%net\_heat\_in\_EFP = real\_to\_efp(0.0)}
\DoxyCodeLine{946 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{947 }

\end{DoxyCode}
