\hypertarget{namespacemom}{}\doxysection{mom Module Reference}
\label{namespacemom}\index{mom@{mom}}


\doxysubsection{Detailed Description}
The central module of the M\+O\+M6 ocean model. 

Modular Ocean Model (M\+OM) Version 6.\+0 (M\+O\+M6)

\begin{DoxyAuthor}{Authors}
Alistair Adcroft, Robert Hallberg, and Stephen Griffies
\end{DoxyAuthor}
Additional contributions from\+:
\begin{DoxyItemize}
\item Whit Anderson
\item Brian Arbic
\item Will Cooke
\item Anand Gnanadesikan
\item Matthew Harrison
\item Mehmet Ilicak
\item Laura Jackson
\item Jasmine John
\item John Krasting
\item Zhi Liang
\item Bonnie Samuels
\item Harper Simmons
\item Laurent White
\item Niki Zadeh
\end{DoxyItemize}

M\+OM ice-\/shelf code was developed by
\begin{DoxyItemize}
\item Daniel Goldberg
\item Robert Hallberg
\item Chris Little
\item Olga Sergienko
\end{DoxyItemize}\hypertarget{namespacemom_section_overview}{}\doxysubsection{Overview of M\+OM}\label{namespacemom_section_overview}
This program (M\+OM) simulates the ocean by numerically solving the hydrostatic primitive equations in generalized Lagrangian vertical coordinates, typically tracking stretched pressure (p$\ast$) surfaces or following isopycnals in the ocean\textquotesingle{}s interior, and general orthogonal horizontal coordinates. Unlike earlier versions of M\+OM, in M\+O\+M6 these equations are horizontally discretized on an Arakawa C-\/grid. (It remains to be seen whether a B-\/grid dynamic core will be revived in M\+O\+M6 at a later date; for now applications requiring a B-\/grid discretization should use M\+O\+M5.\+1.) M\+O\+M6 offers a range of options for the physical parameterizations, from those most appropriate to highly idealized models for geophysical fluid dynamics studies to a rich suite of processes appropriate for realistic ocean simulations. The thermodynamic options typically use conservative temperature and preformed salinity as conservative state variables and a full nonlinear equation of state, but there are also idealized adiabatic configurations of the model that use fixed density layers. Version 6.\+0 of M\+OM continues in the long tradition of a commitment to climate-\/quality ocean simulations embodied in previous versions of M\+OM, even as it draws extensively on the lessons learned in the development of the Generalized Ocean Layered Dynamics (G\+O\+LD) ocean model, which was also primarily developed at N\+O\+A\+A/\+G\+F\+DL. M\+OM has also benefited tremendously from the F\+MS infrastructure, which it utilizes and shares with other component models developed at N\+O\+A\+A/\+G\+F\+DL.

When run is isopycnal-\/coordinate mode, the uppermost few layers are often used to describe a bulk mixed layer, including the effects of penetrating shortwave radiation. Either a split-\/ explicit time stepping scheme or a non-\/split scheme may be used for the dynamics, while the time stepping may be split (and use different numbers of steps to cover the same interval) for the forcing, the thermodynamics, and for the dynamics. Most of the numerics are second order accurate in space. M\+OM can run with an absurdly thin minimum layer thickness. A variety of non-\/isopycnal vertical coordinate options are under development, but all exploit the advantages of a Lagrangian vertical coordinate, as discussed in detail by Adcroft and Hallberg (Ocean Modelling, 2006).

Details of the numerics and physical parameterizations are provided in the appropriate source files. All of the available options are selected at run-\/time by parsing the input files, usually M\+O\+M\+\_\+input and M\+O\+M\+\_\+override, and the options choices are then documented for each run in M\+O\+M\+\_\+param\+\_\+docs.

M\+O\+M6 integrates the equations forward in time in three distinct phases. In one phase, the dynamic equations for the velocities and layer thicknesses are advanced, capturing the propagation of external and internal inertia-\/gravity waves, Rossby waves, and other strictly adiabatic processes, including lateral stresses, vertical viscosity and momentum forcing, and interface height diffusion (commonly called Gent-\/\+Mc\+Williams diffusion in depth-\/ coordinate models). In the second phase, all tracers are advected and diffused along the layers. The third phase applies diabatic processes, vertical mixing of water properties, and perhaps vertical remapping to cause the layers to track the desired vertical coordinate.

The present file (\mbox{\hyperlink{MOM_8F90_source}{M\+O\+M.\+F90}}) orchestrates the main time stepping loops. One time integration option for the dynamics uses a split explicit time stepping scheme to rapidly step the barotropic pressure and velocity fields. The barotropic velocities are averaged over the baroclinic time step before they are used to advect thickness and determine the baroclinic accelerations. As described in Hallberg and Adcroft (2009), a barotropic correction is applied to the time-\/mean layer velocities to ensure that the sum of the layer transports agrees with the time-\/mean barotropic transport, thereby ensuring that the estimates of the free surface from the sum of the layer thicknesses agrees with the final free surface height as calculated by the barotropic solver. The barotropic and baroclinic velocities are kept consistent by recalculating the barotropic velocities from the baroclinic transports each time step. This scheme is described in Hallberg, 1997, J. Comp. Phys. 135, 54-\/65 and in Hallberg and Adcroft, 2009, Ocean Modelling, 29, 15-\/26.

The other time integration options use non-\/split time stepping schemes based on the 3-\/step third order Runge-\/\+Kutta scheme described in Matsuno, 1966, J. Met. Soc. Japan, 44, 85-\/88, or on a two-\/step quasi-\/2nd order Runge-\/\+Kutta scheme. These are much slower than the split time-\/stepping scheme, but they are useful for providing a more robust solution for debugging cases where the more complicated split time-\/stepping scheme may be giving suspect solutions.

There are a range of closure options available. Horizontal velocities are subject to a combination of horizontal biharmonic and Laplacian friction (based on a stress tensor formalism) and a vertical Fickian viscosity (perhaps using the kinematic viscosity of water). The horizontal viscosities may be constant, spatially varying or may be dynamically calculated using Smagorinsky\textquotesingle{}s approach. A diapycnal diffusion of density and thermodynamic quantities is also allowed, but not required, as is horizontal diffusion of interface heights (akin to the Gent-\/\+Mc\+Williams closure of geopotential coordinate models). The diapycnal mixing may use a fixed diffusivity or it may use the shear Richardson number dependent closure, like that described in Jackson et al. (J\+PO, 2008). When there is diapycnal diffusion, it applies to momentum as well. As this is in addition to the vertical viscosity, the vertical Prandtl always exceeds 1. A refined bulk-\/mixed layer is often used to describe the planetary boundary layer in realistic ocean simulations.

M\+OM has a number of noteworthy debugging capabilities. Excessively large velocities are truncated and M\+OM will stop itself after a number of such instances to keep the model from crashing altogether. This is useful in diagnosing failures, or (by accepting some truncations) it may be useful for getting the model past the adjustment from an ill-\/balanced initial condition. In addition, all of the accelerations in the columns with excessively large velocities may be directed to a text file. Parallelization errors may be diagnosed using the D\+E\+B\+UG option, which causes extensive checksums to be written out along with comments indicating where in the algorithm the sums originate and what variable is being summed. The point where these checksums differ between runs is usually a good indication of where in the code the problem lies. All of the test cases provided with M\+OM are routinely tested to ensure that they give bitwise identical results regardless of the domain decomposition, or whether they use static or dynamic memory allocation.\hypertarget{namespacemom_section_structure}{}\doxysubsection{Structure of M\+OM}\label{namespacemom_section_structure}
About 115 other files of source code and 4 header files comprise the M\+OM code, although there are several hundred more files that make up the F\+MS infrastructure upon which M\+OM is built. Each of the M\+OM files contains comments documenting what it does, and most of the file names are fairly self-\/evident. In addition, all subroutines and data types are referenced via a module use, only statement, and the module names are consistent with the file names, so it is not too hard to find the source file for a subroutine.

The typical M\+OM directory tree is as follows\+:

\begin{DoxyVerb}        ../MOM
        |-- config_src
        |   |-- coupled_driver
        |   |-- dynamic
        |   `-- solo_driver
        |-- examples
        |   |-- CM2G
        |   |-- ...
        |   `-- torus_advection_test
        `-- src
            |-- core
            |-- diagnostics
            |-- equation_of_state
            |-- framework
            |-- ice_shelf
            |-- initialization
            |-- parameterizations
            |   |-- lateral
            |   `-- vertical
            |-- tracer
            `-- user\end{DoxyVerb}


Rather than describing each file here, each directory contents will be described to give a broad overview of the M\+OM code structure.

The directories under config\+\_\+src contain files that are used for configuring the code, for instance for coupled or ocean-\/only runs. Only one or two of these directories are used in compiling any, particular run.


\begin{DoxyItemize}
\item config\+\_\+src/coupled\+\_\+driver\+: The files here are used to couple M\+OM as a component in a larger run driven by the F\+MS coupler. This includes code that converts various forcing fields into the code structures and flux and unit conventions used by M\+OM, and converts the M\+OM surface fields back to the forms used by other F\+MS components.
\item config\+\_\+src/dynamic\+: The only file here is the version of \mbox{\hyperlink{MOM__memory_8h}{M\+O\+M\+\_\+memory.\+h}} that is used for dynamic memory configurations of M\+OM.
\item config\+\_\+src/solo\+\_\+driver\+: The files here are include the \+\_\+main driver that is used when M\+OM is configured as an ocean-\/only model, as well as the files that specify the surface forcing in this configuration.

The directories under examples provide a large number of working configurations of M\+OM, along with reference solutions for several different compilers on G\+F\+DL\textquotesingle{}s latest large computer. The versions of \mbox{\hyperlink{MOM__memory_8h}{M\+O\+M\+\_\+memory.\+h}} in these directories need not be used if dynamic memory allocation is desired, and the answers should be unchanged.

The directories under src contain most of the M\+OM files. These files are used in every configuration using M\+OM.
\item src/core\+: The files here constitute the M\+OM dynamic core. This directory also includes files with the types that describe the model\textquotesingle{}s lateral grid and have defined types that are shared across various M\+OM modules to allow for more succinct and flexible subroutine argument lists.
\item src/diagnostics\+: The files here calculate various diagnostics that are anciliary to the model itself. While most of these diagnostics do not directly affect the model\textquotesingle{}s solution, there are some, like the calculation of the deformation radius, that are used in some of the process parameterizations.
\item src/equation\+\_\+of\+\_\+state\+: These files describe the physical properties of sea-\/water, including both the equation of state and when it freezes.
\item src/framework\+: These files provide infrastructure utilities for M\+OM. Many are simply wrappers for capabilities provided by F\+MS, although others provide capabilities (like the file\+\_\+parser) that are unique to M\+OM. When M\+OM is adapted to use a modeling infrastructure distinct from F\+MS, most of the required changes are in this directory.
\item src/initialization\+: These are the files that are used to initialize the M\+OM grid or provide the initial physical state for M\+OM. These files are not intended to be modified, but provide a means for calling user-\/specific initialization code like the examples in src/user.
\item src/parameterizations/lateral\+: These files implement a number of quasi-\/lateral (along-\/layer) process parameterizations, including lateral viscosities, parameterizations of eddy effects, and the calculation of tidal forcing.
\item src/parameterizations/vertical\+: These files implement a number of vertical mixing or diabatic processes, including the effects of vertical viscosity and code to parameterize the planetary boundary layer. There is a separate driver that orchestrates this portion of the algorithm, and there is a diversity of parameterizations to be found here.
\item src/tracer\+: These files handle the lateral transport and diffusion of tracers, or are the code to implement various passive tracer packages. Additional tracer packages are readily accommodated.
\item src/user\+: These are either stub routines that a user could use to change the model\textquotesingle{}s initial conditions or forcing, or are examples that implement specific test cases. These files can easily be hand edited to create new analytically specified configurations.
\end{DoxyItemize}

Most simulations can be set up by modifying only the files M\+O\+M\+\_\+input, and possibly one or two of the files in src/user. In addition, the diag\+\_\+table (M\+O\+M\+\_\+diag\+\_\+table) will commonly be modified to tailor the output to the needs of the question at hand. The F\+MS utility mkmf works with a file called path\+\_\+names to build an appropriate makefile, and path\+\_\+names should be edited to reflect the actual location of the desired source code.

There are 3 publicly visible subroutines in this file (\mbox{\hyperlink{MOM_8F90_source}{M\+O\+M.\+F90}}).
\begin{DoxyItemize}
\item step\+\_\+\+M\+OM steps M\+OM over a specified interval of time.
\item M\+O\+M\+\_\+initialize calls initialize and does other initialization that does not warrant user modification.
\item extract\+\_\+surface\+\_\+state determines the surface (bulk mixed layer if traditional isoycnal vertical coordinate) properties of the current model state and packages pointers to these fields into an exported structure.

The remaining subroutines in this file (\mbox{\hyperlink{MOM_8F90_source}{src/core/\+M\+O\+M.\+F90}}) are\+:
\item find\+\_\+total\+\_\+transport determines the barotropic mass transport.
\item register\+\_\+diags registers many diagnostic fields for the dynamic solver, or of the main model variables.
\item M\+O\+M\+\_\+timing\+\_\+init initializes various C\+PU time clocks.
\item write\+\_\+static\+\_\+fields writes out various time-\/invariant fields.
\item set\+\_\+restart\+\_\+fields is used to specify those fields that are written to and read from the restart file.
\end{DoxyItemize}\hypertarget{namespacemom_section_heat_budget}{}\doxysubsection{Diagnosing M\+O\+M heat budget}\label{namespacemom_section_heat_budget}
Here are some example heat budgets for the A\+LE version of M\+O\+M6.\hypertarget{namespacemom_subsection_2d_heat_budget}{}\doxysubsubsection{Depth integrated heat budget}\label{namespacemom_subsection_2d_heat_budget}
Depth integrated heat budget diagnostic for M\+OM.


\begin{DoxyItemize}
\item O\+P\+O\+T\+T\+E\+M\+P\+T\+E\+N\+D\+\_\+2d = T\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+X\+Y\+\_\+2d + O\+P\+O\+T\+T\+E\+M\+P\+P\+M\+D\+I\+F\+F\+\_\+2d + H\+F\+DS + H\+F\+G\+E\+OU
\item T\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+X\+Y\+\_\+2d = horizontal advection
\item O\+P\+O\+T\+T\+E\+M\+P\+P\+M\+D\+I\+F\+F\+\_\+2d = neutral diffusion
\item H\+F\+DS = net surface boundary heat flux
\item H\+F\+G\+E\+OU = geothermal heat flux
\item H\+F\+DS = net surface boundary heat flux entering the ocean = rsntds + rlntds + hfls + hfss + heat\+\_\+pme + hfsifrazil
\item More heat flux cross-\/checks
\begin{DoxyItemize}
\item hfds = net\+\_\+heat\+\_\+coupler + hfsifrazil + heat\+\_\+pme
\item heat\+\_\+pme = heat\+\_\+content\+\_\+surfwater = heat\+\_\+content\+\_\+massin + heat\+\_\+content\+\_\+massout = heat\+\_\+content\+\_\+fprec + heat\+\_\+content\+\_\+cond + heat\+\_\+content\+\_\+vprec
\begin{DoxyItemize}
\item hfrunoffds + hfevapds + hfrainds
\end{DoxyItemize}
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{namespacemom_subsection_3d_heat_budget}{}\doxysubsubsection{Depth integrated heat budget}\label{namespacemom_subsection_3d_heat_budget}
Here is an example 3d heat budget diagnostic for M\+OM.


\begin{DoxyItemize}
\item O\+P\+O\+T\+T\+E\+M\+P\+T\+E\+ND = T\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+XY + T\+H\+\_\+\+T\+E\+N\+D\+E\+N\+C\+Y\+\_\+\+V\+E\+R\+T\+\_\+\+R\+E\+M\+AP + O\+P\+O\+T\+T\+E\+M\+P\+D\+I\+FF + O\+P\+O\+T\+T\+E\+M\+P\+P\+M\+D\+I\+FF
\begin{DoxyItemize}
\item B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY + F\+R\+A\+Z\+I\+L\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY
\end{DoxyItemize}
\item O\+P\+O\+T\+T\+E\+M\+P\+T\+E\+ND = net tendency of heat as diagnosed in \mbox{\hyperlink{MOM_8F90_source}{M\+O\+M.\+F90}}
\item T\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+XY = heating of a cell from lateral advection
\item T\+H\+\_\+\+T\+E\+N\+D\+E\+N\+C\+Y\+\_\+\+V\+E\+R\+T\+\_\+\+R\+E\+M\+AP = heating of a cell from vertical remapping
\item O\+P\+O\+T\+T\+E\+M\+P\+D\+I\+FF = heating of a cell from diabatic diffusion
\item O\+P\+O\+T\+T\+E\+M\+P\+P\+M\+D\+I\+FF = heating of a cell from neutral diffusion
\item B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY = heating of cell from boundary fluxes
\item F\+R\+A\+Z\+I\+L\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY = heating of cell from frazil
\item T\+H\+\_\+\+T\+E\+N\+D\+E\+N\+C\+Y\+\_\+\+V\+E\+R\+T\+\_\+\+R\+E\+M\+AP has zero vertical sum, as it redistributes heat in vertical.
\item O\+P\+O\+T\+T\+E\+M\+P\+D\+I\+FF has zero vertical sum, as it redistributes heat in the vertical.
\item B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY generally has 3d structure, with k $>$ 1 contributions from penetrative shortwave, and from other fluxes for the case when layers are tiny, in which case M\+O\+M6 partitions tendencies into k $>$ 1 layers.
\item F\+R\+A\+Z\+I\+L\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY generally has 3d structure, since M\+O\+M6 frazil calculation checks the full ocean column.
\item F\+R\+A\+Z\+I\+L\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY\mbox{[}k=@sum\mbox{]} = H\+F\+S\+I\+F\+R\+A\+Z\+IL = column integrated frazil heating.
\item H\+F\+DS = F\+R\+A\+Z\+I\+L\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY\mbox{[}k=@sum\mbox{]} + B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+H\+E\+A\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY\mbox{[}k=@sum\mbox{]}

Here is an example 2d heat budget (depth summed) diagnostic for M\+OM.
\item O\+P\+O\+T\+T\+E\+M\+P\+T\+E\+N\+D\+\_\+2d = T\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+X\+Y\+\_\+2d + O\+P\+O\+T\+T\+E\+M\+P\+P\+M\+D\+I\+F\+F\+\_\+2d + H\+F\+DS

Here is an example 3d salt budget diagnostic for M\+OM.
\item O\+S\+A\+L\+T\+T\+E\+ND = S\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+XY + S\+H\+\_\+\+T\+E\+N\+D\+E\+N\+C\+Y\+\_\+\+V\+E\+R\+T\+\_\+\+R\+E\+M\+AP + O\+S\+A\+L\+T\+D\+I\+FF + O\+S\+A\+L\+T\+P\+M\+D\+I\+FF
\begin{DoxyItemize}
\item B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+S\+A\+L\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY
\end{DoxyItemize}
\item O\+S\+A\+L\+T\+T\+E\+ND = net tendency of salt as diagnosed in \mbox{\hyperlink{MOM_8F90_source}{M\+O\+M.\+F90}}
\item S\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+XY = salt convergence to cell from lateral advection
\item S\+H\+\_\+\+T\+E\+N\+D\+E\+N\+C\+Y\+\_\+\+V\+E\+R\+T\+\_\+\+R\+E\+M\+AP = salt convergence to cell from vertical remapping
\item O\+S\+A\+L\+T\+D\+I\+FF = salt convergence to cell from diabatic diffusion
\item O\+S\+A\+L\+T\+P\+M\+D\+I\+FF = salt convergence to cell from neutral diffusion
\item B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+S\+A\+L\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY = salt convergence to cell from boundary fluxes
\item S\+H\+\_\+\+T\+E\+N\+D\+E\+N\+C\+Y\+\_\+\+V\+E\+R\+T\+\_\+\+R\+E\+M\+AP has zero vertical sum, as it redistributes salt in vertical.
\item O\+S\+A\+L\+T\+D\+I\+FF has zero vertical sum, as it redistributes salt in the vertical.
\item B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+S\+A\+L\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY generally has 3d structure, with k $>$ 1 contributions from the case when layers are tiny, in which case M\+O\+M6 partitions tendencies into k $>$ 1 layers.
\item S\+F\+D\+SI = B\+O\+U\+N\+D\+A\+R\+Y\+\_\+\+F\+O\+R\+C\+I\+N\+G\+\_\+\+S\+A\+L\+T\+\_\+\+T\+E\+N\+D\+E\+N\+CY\mbox{[}k=@sum\mbox{]}

Here is an example 2d salt budget (depth summed) diagnostic for M\+OM.
\item O\+S\+A\+L\+T\+T\+E\+N\+D\+\_\+2d = S\+\_\+\+A\+D\+V\+E\+C\+T\+I\+O\+N\+\_\+\+X\+Y\+\_\+2d + O\+S\+A\+L\+T\+P\+M\+D\+I\+F\+F\+\_\+2d + S\+F\+D\+SI (+ S\+A\+L\+T\+\_\+\+F\+L\+U\+X\+\_\+\+R\+E\+S\+T\+O\+RE) 
\end{DoxyItemize}\doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}
\begin{DoxyCompactList}\small\item\em Control structure for the M\+OM module, including the variables that describe the state of the ocean. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom_1_1mom__diag__ids}{mom\+\_\+diag\+\_\+ids}}
\begin{DoxyCompactList}\small\item\em A structure with diagnostic I\+Ds of the state variables. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom_adf54a4e3a72611aa2088f46076e56e53}{step\+\_\+mom}} (forces\+\_\+in, fluxes\+\_\+in, sfc\+\_\+state, Time\+\_\+start, time\+\_\+int\+\_\+in, CS, Waves, do\+\_\+dynamics, do\+\_\+thermodynamics, start\+\_\+cycle, end\+\_\+cycle, cycle\+\_\+length, reset\+\_\+therm)
\begin{DoxyCompactList}\small\item\em This subroutine orchestrates the time stepping of M\+OM. The adiabatic dynamics are stepped by calls to one of the step\+\_\+\+M\+O\+M\+\_\+dyn\+\_\+...routines. The action of lateral processes on tracers occur in calls to advect\+\_\+tracer and tracer\+\_\+hordiff. Vertical mixing and possibly remapping occur inside of diabatic. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}{step\+\_\+mom\+\_\+dynamics}} (forces, p\+\_\+surf\+\_\+begin, p\+\_\+surf\+\_\+end, dt, dt\+\_\+thermo, bbl\+\_\+time\+\_\+int, CS, Time\+\_\+local, Waves)
\begin{DoxyCompactList}\small\item\em Time step the ocean dynamics, including the momentum and continuity equations. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_a0a07938ed3127b70bab5d466967aec80}{step\+\_\+mom\+\_\+tracer\+\_\+dyn}} (CS, G, GV, US, h, Time\+\_\+local)
\begin{DoxyCompactList}\small\item\em step\+\_\+\+M\+O\+M\+\_\+tracer\+\_\+dyn does tracer advection and lateral diffusion, bringing the tracers up to date with the changes in state due to the dynamics. Surface sources and sinks and remapping are handled via step\+\_\+\+M\+O\+M\+\_\+thermo. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}{step\+\_\+mom\+\_\+thermo}} (CS, G, GV, US, u, v, h, tv, fluxes, dtdia, Time\+\_\+end\+\_\+thermo, update\+\_\+\+B\+BL, Waves)
\begin{DoxyCompactList}\small\item\em M\+O\+M\+\_\+step\+\_\+thermo orchestrates the thermodynamic time stepping and vertical remapping, via calls to diabatic (or adiabatic) and A\+L\+E\+\_\+main. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}{step\+\_\+offline}} (forces, fluxes, sfc\+\_\+state, Time\+\_\+start, time\+\_\+interval, CS)
\begin{DoxyCompactList}\small\item\em step\+\_\+offline is the main driver for running tracers offline in M\+O\+M6. This has been primarily developed with A\+LE configurations in mind. Some work has been done in isopycnal configuration, but the work is very preliminary. Some more detail about this capability along with some of the subroutines called here can be found in tracers/\+M\+O\+M\+\_\+offline\+\_\+control.\+F90 \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_a96708b16215666edbfa5b46228f3a200}{initialize\+\_\+mom}} (Time, Time\+\_\+init, param\+\_\+file, dirs, CS, restart\+\_\+\+C\+Sp, Time\+\_\+in, offline\+\_\+tracer\+\_\+mode, input\+\_\+restart\+\_\+file, diag\+\_\+ptr, count\+\_\+calls, tracer\+\_\+flow\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Initialize M\+OM, including memory allocation, setting up parameters and diagnostics, initializing the ocean state variables, and initializing subsidiary modules. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_a2269d5cd79625cbf16cb916346379207}{finish\+\_\+mom\+\_\+initialization}} (Time, dirs, CS, restart\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Finishes initializing M\+OM and writes out the initial conditions. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}{register\+\_\+diags}} (Time, G, GV, US, I\+Ds, diag)
\begin{DoxyCompactList}\small\item\em Register certain diagnostics. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_ab57e47834591c651339770f7e51efe57}{mom\+\_\+timing\+\_\+init}} (CS)
\begin{DoxyCompactList}\small\item\em Set up C\+PU clock I\+Ds for timing various subroutines. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}{set\+\_\+restart\+\_\+fields}} (GV, US, param\+\_\+file, CS, restart\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Set the fields that are needed for bitwise identical restarting the time stepping scheme. In addition to those specified here directly, there may be fields related to the forcing or to the barotropic solver that are needed; these are specified in sub-\/ routines that are called from this one. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{adjust\+\_\+ssh\+\_\+for\+\_\+p\+\_\+atm}} (tv, G, GV, US, ssh, p\+\_\+atm, use\+\_\+\+E\+OS)
\begin{DoxyCompactList}\small\item\em Apply a correction to the sea surface height to compensate for the atmospheric pressure (the inverse barometer). \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{extract\+\_\+surface\+\_\+state}} (CS, sfc\+\_\+state\+\_\+in)
\begin{DoxyCompactList}\small\item\em Set the surface (return) properties of the ocean model by setting the appropriate fields in sfc\+\_\+state. Unused fields are set to N\+U\+LL or are unallocated. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a8f5160e583b599050515b8fe5575aa15}\label{namespacemom_a8f5160e583b599050515b8fe5575aa15}} 
subroutine \mbox{\hyperlink{namespacemom_a8f5160e583b599050515b8fe5575aa15}{rotate\+\_\+initial\+\_\+state}} (u\+\_\+in, v\+\_\+in, h\+\_\+in, T\+\_\+in, S\+\_\+in, use\+\_\+temperature, turns, u, v, h, T, S)
\begin{DoxyCompactList}\small\item\em Rotate initialization fields from input to rotated arrays. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{mom\+\_\+state\+\_\+is\+\_\+synchronized}} (CS, adv\+\_\+dyn)
\begin{DoxyCompactList}\small\item\em Return true if all phases of step\+\_\+\+M\+OM are at the same point in time. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_aece0dd1e2c9498844befd8ba71986b96}{get\+\_\+mom\+\_\+state\+\_\+elements}} (CS, G, GV, US, C\+\_\+p, C\+\_\+p\+\_\+scaled, use\+\_\+temp)
\begin{DoxyCompactList}\small\item\em This subroutine offers access to values or pointers to other types from within the M\+O\+M\+\_\+control\+\_\+struct, allowing the M\+O\+M\+\_\+control\+\_\+struct to be opaque. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_a462293ed92e99927ef9939747d633080}{get\+\_\+ocean\+\_\+stocks}} (CS, mass, heat, salt, on\+\_\+\+P\+E\+\_\+only)
\begin{DoxyCompactList}\small\item\em Find the global integrals of various quantities. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}{mom\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em End of ocean model, including memory deallocation. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}\label{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}} 
integer \mbox{\hyperlink{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}{id\+\_\+clock\+\_\+ocean}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}\label{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}} 
integer \mbox{\hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\+\_\+clock\+\_\+dynamics}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a052256dfa3e56390f62ef3a826d62617}\label{namespacemom_a052256dfa3e56390f62ef3a826d62617}} 
integer \mbox{\hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\+\_\+clock\+\_\+thermo}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a0fa4debacd02de6fcd066066c232adf3}\label{namespacemom_a0fa4debacd02de6fcd066066c232adf3}} 
integer \mbox{\hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\+\_\+clock\+\_\+tracer}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a50edf00aa5998073d2db0360949253ba}\label{namespacemom_a50edf00aa5998073d2db0360949253ba}} 
integer \mbox{\hyperlink{namespacemom_a50edf00aa5998073d2db0360949253ba}{id\+\_\+clock\+\_\+diabatic}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_af865d838388a05163e8de8d266316d5f}\label{namespacemom_af865d838388a05163e8de8d266316d5f}} 
integer \mbox{\hyperlink{namespacemom_af865d838388a05163e8de8d266316d5f}{id\+\_\+clock\+\_\+adiabatic}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_aa512b2d8dd73b02634e772701be07a87}\label{namespacemom_aa512b2d8dd73b02634e772701be07a87}} 
integer \mbox{\hyperlink{namespacemom_aa512b2d8dd73b02634e772701be07a87}{id\+\_\+clock\+\_\+continuity}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}\label{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}} 
integer \mbox{\hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\+\_\+clock\+\_\+thick\+\_\+diff}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_aa69e79e4c51e1c24c474b84311322251}\label{namespacemom_aa69e79e4c51e1c24c474b84311322251}} 
integer \mbox{\hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\+\_\+clock\+\_\+bbl\+\_\+visc}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}\label{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}} 
integer \mbox{\hyperlink{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}{id\+\_\+clock\+\_\+ml\+\_\+restrat}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_aa773fddb51f99098d75304eb271270d4}\label{namespacemom_aa773fddb51f99098d75304eb271270d4}} 
integer \mbox{\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\+\_\+clock\+\_\+diagnostics}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a09f2ac3470372b9ee233f4cc5a7a0da1}\label{namespacemom_a09f2ac3470372b9ee233f4cc5a7a0da1}} 
integer \mbox{\hyperlink{namespacemom_a09f2ac3470372b9ee233f4cc5a7a0da1}{id\+\_\+clock\+\_\+z\+\_\+diag}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a7cf03c18244d0630616e925bab1841a2}\label{namespacemom_a7cf03c18244d0630616e925bab1841a2}} 
integer \mbox{\hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\+\_\+clock\+\_\+init}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}\label{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}} 
integer \mbox{\hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\+\_\+clock\+\_\+mom\+\_\+init}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}\label{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}} 
integer \mbox{\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\+\_\+clock\+\_\+pass}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_ac4d20612cad32d412dae492fedc2e971}\label{namespacemom_ac4d20612cad32d412dae492fedc2e971}} 
integer \mbox{\hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\+\_\+clock\+\_\+pass\+\_\+init}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a722ed13d0e6d76852e680054a0e3c964}\label{namespacemom_a722ed13d0e6d76852e680054a0e3c964}} 
integer \mbox{\hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\+\_\+clock\+\_\+ale}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}\label{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}} 
integer \mbox{\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\+\_\+clock\+\_\+other}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}\label{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}} 
integer \mbox{\hyperlink{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}{id\+\_\+clock\+\_\+offline\+\_\+tracer}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom_a785851181d2a3db5a938322d2ff9498a}\label{namespacemom_a785851181d2a3db5a938322d2ff9498a}} 
integer \mbox{\hyperlink{namespacemom_a785851181d2a3db5a938322d2ff9498a}{id\+\_\+clock\+\_\+unit\+\_\+tests}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\end{DoxyCompactItemize}



\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}\label{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}} 
\index{mom@{mom}!adjust\_ssh\_for\_p\_atm@{adjust\_ssh\_for\_p\_atm}}
\index{adjust\_ssh\_for\_p\_atm@{adjust\_ssh\_for\_p\_atm}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{adjust\_ssh\_for\_p\_atm()}{adjust\_ssh\_for\_p\_atm()}}
{\footnotesize\ttfamily subroutine mom\+::adjust\+\_\+ssh\+\_\+for\+\_\+p\+\_\+atm (\begin{DoxyParamCaption}\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{ssh,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{p\+\_\+atm,  }\item[{logical, intent(in), optional}]{use\+\_\+\+E\+OS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Apply a correction to the sea surface height to compensate for the atmospheric pressure (the inverse barometer). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em g} & ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em ssh} & time mean surface height \mbox{[}m\mbox{]} \\
\hline
 & {\em p\+\_\+atm} & Ocean surface pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em use\+\_\+eos} & If true, calculate the density for the S\+SH correction using the equation of state. \\
\hline
\end{DoxyParams}


Definition at line 2964 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2964   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),             \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< A structure pointing to various thermodynamic variables}}
\DoxyCodeLine{2965   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{   !< ocean grid structure}}
\DoxyCodeLine{2966   \textcolor{keywordtype}{type}(verticalGrid\_type),           \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< ocean vertical grid structure}}
\DoxyCodeLine{2967   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{2968 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: ssh\textcolor{comment}{ !< time mean surface height [m]}}
\DoxyCodeLine{2969 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: p\_atm\textcolor{comment}{ !< Ocean surface pressure [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{2970   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: use\_EOS\textcolor{comment}{ !< If true, calculate the density for}}
\DoxyCodeLine{2971 \textcolor{comment}{                                                       !! the SSH correction using the equation of state.}}
\DoxyCodeLine{2972 }
\DoxyCodeLine{2973 \textcolor{keywordtype}{  real} :: Rho\_conv(SZI\_(G))  \textcolor{comment}{! The density used to convert surface pressure to}}
\DoxyCodeLine{2974                       \textcolor{comment}{! a corrected effective SSH [R ~> kg m-\/3].}}
\DoxyCodeLine{2975 \textcolor{keywordtype}{  real} :: IgR0        \textcolor{comment}{! The SSH conversion factor from R L2 T-\/2 to m [m T2 R-\/1 L-\/2 ~> m Pa-\/1].}}
\DoxyCodeLine{2976   \textcolor{keywordtype}{logical} :: calc\_rho}
\DoxyCodeLine{2977   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{2978   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{2979 }
\DoxyCodeLine{2980   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{2981   eosdom(:) = eos\_domain(g\%HI)}
\DoxyCodeLine{2982   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(p\_atm)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_atm)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2983     calc\_rho = \textcolor{keyword}{associated}(tv\%eqn\_of\_state)}
\DoxyCodeLine{2984     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(use\_eos) .and. calc\_rho) calc\_rho = use\_eos}
\DoxyCodeLine{2985     \textcolor{comment}{! Correct the output sea surface height for the contribution from the ice pressure.}}
\DoxyCodeLine{2986     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{2987       \textcolor{keywordflow}{if} (calc\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2988         \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,1), tv\%S(:,j,1), 0.5*p\_atm(:,j), rho\_conv, \&}
\DoxyCodeLine{2989                                tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{2990         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2991           igr0 = us\%Z\_to\_m / (rho\_conv(i) * gv\%g\_Earth)}
\DoxyCodeLine{2992           ssh(i,j) = ssh(i,j) + p\_atm(i,j) * igr0}
\DoxyCodeLine{2993 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{2994       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2995         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2996           ssh(i,j) = ssh(i,j) + p\_atm(i,j) * (us\%Z\_to\_m / (gv\%Rho0 * gv\%g\_Earth))}
\DoxyCodeLine{2997 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{2998 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2999 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{3000 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3001 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}\label{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}} 
\index{mom@{mom}!extract\_surface\_state@{extract\_surface\_state}}
\index{extract\_surface\_state@{extract\_surface\_state}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{extract\_surface\_state()}{extract\_surface\_state()}}
{\footnotesize\ttfamily subroutine, public mom\+::extract\+\_\+surface\+\_\+state (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{type(surface), intent(inout), target}]{sfc\+\_\+state\+\_\+in }\end{DoxyParamCaption})}



Set the surface (return) properties of the ocean model by setting the appropriate fields in sfc\+\_\+state. Unused fields are set to N\+U\+LL or are unallocated. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Master M\+OM control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em sfc\+\_\+state\+\_\+in} & transparent ocean surface state structure shared with the calling routine data in this structure is intent out. \\
\hline
\end{DoxyParams}


Definition at line 3008 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3008   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Master MOM control structure}}
\DoxyCodeLine{3009   \textcolor{keywordtype}{type}(surface), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: sfc\_state\_in\textcolor{comment}{ !< transparent ocean surface state}}
\DoxyCodeLine{3010 \textcolor{comment}{                                             !! structure shared with the calling routine}}
\DoxyCodeLine{3011 \textcolor{comment}{                                             !! data in this structure is intent out.}}
\DoxyCodeLine{3012 }
\DoxyCodeLine{3013   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{3014 \textcolor{keywordtype}{  real} :: hu, hv  \textcolor{comment}{! Thicknesses interpolated to velocity points [H ~> m or kg m-\/2]}}
\DoxyCodeLine{3015   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null() \textcolor{comment}{!< pointer to a structure containing}}
\DoxyCodeLine{3016 \textcolor{comment}{                                                  !! metrics and related information}}
\DoxyCodeLine{3017   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G\_in => null() \textcolor{comment}{!< Input grid metric}}
\DoxyCodeLine{3018   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{!< structure containing vertical grid info}}
\DoxyCodeLine{3019   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{!< structure containing various unit conversion factors}}
\DoxyCodeLine{3020   \textcolor{keywordtype}{type}(surface),           \textcolor{keywordtype}{pointer} :: sfc\_state => null()  \textcolor{comment}{! surface state on the model grid}}
\DoxyCodeLine{3021 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{pointer} :: \&}
\DoxyCodeLine{3022     h => null()    \textcolor{comment}{!< h : layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{3023 \textcolor{keywordtype}{  real} :: depth(SZI\_(CS\%G))\textcolor{comment}{  !< Distance from the surface in depth units [Z ~> m] or [H ~> m or kg m-\/2]}}
\DoxyCodeLine{3024 \textcolor{keywordtype}{  real} :: depth\_ml\textcolor{comment}{           !< Depth over which to average to determine mixed}}
\DoxyCodeLine{3025 \textcolor{comment}{                             !! layer properties [Z ~> m] or [H ~> m or kg m-\/2]}}
\DoxyCodeLine{3026 \textcolor{keywordtype}{  real} :: dh\textcolor{comment}{                 !< Thickness of a layer within the mixed layer [Z ~> m] or [H ~> m or kg m-\/2]}}
\DoxyCodeLine{3027 \textcolor{keywordtype}{  real} :: mass\textcolor{comment}{               !< Mass per unit area of a layer [R Z ~> kg m-\/2]}}
\DoxyCodeLine{3028 \textcolor{keywordtype}{  real} :: T\_freeze\textcolor{comment}{           !< freezing temperature [degC]}}
\DoxyCodeLine{3029 \textcolor{keywordtype}{  real} :: I\_depth\textcolor{comment}{            !< The inverse of depth [Z-\/1 ~> m-\/1] or [H-\/1 ~> m-\/1 or m2 kg-\/1]}}
\DoxyCodeLine{3030 \textcolor{keywordtype}{  real} :: missing\_depth\textcolor{comment}{      !< The portion of depth\_ml that can not be found in a column [H ~> m or kg m-\/2]}}
\DoxyCodeLine{3031 \textcolor{keywordtype}{  real} :: H\_rescale\textcolor{comment}{          !< A conversion factor from thickness units to the units used in the}}
\DoxyCodeLine{3032 \textcolor{comment}{                             !! calculation of properties of the uppermost ocean [nondim] or [Z H-\/1 ~> 1 or m3 kg-\/1]}}
\DoxyCodeLine{3033                              \textcolor{comment}{!  After the ANSWERS\_2018 flag has been obsoleted, H\_rescale will be 1.}}
\DoxyCodeLine{3034 \textcolor{keywordtype}{  real} :: delT(SZI\_(CS\%G))\textcolor{comment}{   !< Depth integral of T-\/T\_freeze [Z degC ~> m degC]}}
\DoxyCodeLine{3035   \textcolor{keywordtype}{logical} :: use\_temperature\textcolor{comment}{ !< If true, temp and saln used as state variables.}}
\DoxyCodeLine{3036   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, numberOfErrors, ig, jg}
\DoxyCodeLine{3037   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed}
\DoxyCodeLine{3038   \textcolor{keywordtype}{integer} :: iscB, iecB, jscB, jecB, isdB, iedB, jsdB, jedB}
\DoxyCodeLine{3039   \textcolor{keywordtype}{logical} :: localError}
\DoxyCodeLine{3040   \textcolor{keywordtype}{character(240)} :: msg}
\DoxyCodeLine{3041   \textcolor{keywordtype}{integer} :: turns    \textcolor{comment}{! Number of quarter turns}}
\DoxyCodeLine{3042 }
\DoxyCodeLine{3043   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"extract\_surface\_state(), MOM.F90"})}
\DoxyCodeLine{3044   g => cs\%G ; g\_in => cs\%G\_in ; gv => cs\%GV ; us => cs\%US}
\DoxyCodeLine{3045   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{3046   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{3047   iscb = g\%iscB ; iecb = g\%iecB; jscb = g\%jscB ; jecb = g\%jecB}
\DoxyCodeLine{3048   isdb = g\%isdB ; iedb = g\%iedB; jsdb = g\%jsdB ; jedb = g\%jedB}
\DoxyCodeLine{3049   h => cs\%h}
\DoxyCodeLine{3050 }
\DoxyCodeLine{3051   use\_temperature = \textcolor{keyword}{associated}(cs\%tv\%T)}
\DoxyCodeLine{3052 }
\DoxyCodeLine{3053   turns = 0}
\DoxyCodeLine{3054   \textcolor{keywordflow}{if} (cs\%rotate\_index) \&}
\DoxyCodeLine{3055     turns = g\%HI\%turns}
\DoxyCodeLine{3056 }
\DoxyCodeLine{3057   \textcolor{keywordflow}{if} (.not.sfc\_state\_in\%arrays\_allocated) \&}
\DoxyCodeLine{3058     \textcolor{comment}{!  Consider using a run-\/time flag to determine whether to do the vertical}}
\DoxyCodeLine{3059     \textcolor{comment}{! integrals, since the 3-\/d sums are not negligible in cost.}}
\DoxyCodeLine{3060     \textcolor{keyword}{call }allocate\_surface\_state(sfc\_state\_in, g\_in, use\_temperature, \&}
\DoxyCodeLine{3061         do\_integrals=.true., omit\_frazil=.not.\textcolor{keyword}{associated}(cs\%tv\%frazil))}
\DoxyCodeLine{3062 }
\DoxyCodeLine{3063   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3064     \textcolor{keyword}{allocate}(sfc\_state)}
\DoxyCodeLine{3065     \textcolor{keyword}{call }allocate\_surface\_state(sfc\_state, g, use\_temperature, \&}
\DoxyCodeLine{3066         do\_integrals=.true., omit\_frazil=.not.\textcolor{keyword}{associated}(cs\%tv\%frazil))}
\DoxyCodeLine{3067   \textcolor{keywordflow}{else}}
\DoxyCodeLine{3068     sfc\_state => sfc\_state\_in}
\DoxyCodeLine{3069 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3070 }
\DoxyCodeLine{3071   sfc\_state\%T\_is\_conT = cs\%tv\%T\_is\_conT}
\DoxyCodeLine{3072   sfc\_state\%S\_is\_absS = cs\%tv\%S\_is\_absS}
\DoxyCodeLine{3073 }
\DoxyCodeLine{3074   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3075     sfc\_state\%sea\_lev(i,j) = us\%m\_to\_Z*cs\%ave\_ssh\_ibc(i,j)}
\DoxyCodeLine{3076 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3077 }
\DoxyCodeLine{3078   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%frazil) .and. \textcolor{keyword}{associated}(cs\%tv\%frazil)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3079     sfc\_state\%frazil(i,j) = cs\%tv\%frazil(i,j)}
\DoxyCodeLine{3080 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3081 }
\DoxyCodeLine{3082   \textcolor{comment}{! copy Hml into sfc\_state, so that caps can access it}}
\DoxyCodeLine{3083   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%Hml)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3084     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3085       sfc\_state\%Hml(i,j) = cs\%Hml(i,j)}
\DoxyCodeLine{3086 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3087 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3088 }
\DoxyCodeLine{3089   \textcolor{keywordflow}{if} (cs\%Hmix < 0.0) \textcolor{keywordflow}{then}  \textcolor{comment}{! A bulk mixed layer is in use, so layer 1 has the properties}}
\DoxyCodeLine{3090     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3091       sfc\_state\%SST(i,j) = cs\%tv\%T(i,j,1)}
\DoxyCodeLine{3092       sfc\_state\%SSS(i,j) = cs\%tv\%S(i,j,1)}
\DoxyCodeLine{3093 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{3094     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3095       sfc\_state\%u(i,j) = cs\%u(i,j,1)}
\DoxyCodeLine{3096 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3097     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3098       sfc\_state\%v(i,j) = cs\%v(i,j,1)}
\DoxyCodeLine{3099 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3100 }
\DoxyCodeLine{3101   \textcolor{keywordflow}{else}  \textcolor{comment}{! (CS\%Hmix >= 0.0)}}
\DoxyCodeLine{3102     h\_rescale = 1.0 ; \textcolor{keywordflow}{if} (cs\%answers\_2018) h\_rescale = gv\%H\_to\_Z}
\DoxyCodeLine{3103     depth\_ml = cs\%Hmix}
\DoxyCodeLine{3104     \textcolor{keywordflow}{if} (.not.cs\%answers\_2018) depth\_ml = cs\%Hmix*gv\%Z\_to\_H}
\DoxyCodeLine{3105     \textcolor{comment}{! Determine the mean tracer properties of the uppermost depth\_ml fluid.}}
\DoxyCodeLine{3106 }
\DoxyCodeLine{3107     \textcolor{comment}{!\$OMP parallel do default(shared) private(depth,dh)}}
\DoxyCodeLine{3108     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{3109       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3110         depth(i) = 0.0}
\DoxyCodeLine{3111         \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3112           sfc\_state\%SST(i,j) = 0.0 ; sfc\_state\%SSS(i,j) = 0.0}
\DoxyCodeLine{3113         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3114           sfc\_state\%sfc\_density(i,j) = 0.0}
\DoxyCodeLine{3115 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3116 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3117 }
\DoxyCodeLine{3118       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3119         \textcolor{keywordflow}{if} (depth(i) + h(i,j,k)*h\_rescale < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3120           dh = h(i,j,k)*h\_rescale}
\DoxyCodeLine{3121         \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3122           dh = depth\_ml -\/ depth(i)}
\DoxyCodeLine{3123         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3124           dh = 0.0}
\DoxyCodeLine{3125 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3126         \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3127           sfc\_state\%SST(i,j) = sfc\_state\%SST(i,j) + dh * cs\%tv\%T(i,j,k)}
\DoxyCodeLine{3128           sfc\_state\%SSS(i,j) = sfc\_state\%SSS(i,j) + dh * cs\%tv\%S(i,j,k)}
\DoxyCodeLine{3129         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3130           sfc\_state\%sfc\_density(i,j) = sfc\_state\%sfc\_density(i,j) + dh * gv\%Rlay(k)}
\DoxyCodeLine{3131 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3132         depth(i) = depth(i) + dh}
\DoxyCodeLine{3133 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3134   \textcolor{comment}{! Calculate the average properties of the mixed layer depth.}}
\DoxyCodeLine{3135       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3136         \textcolor{keywordflow}{if} (cs\%answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3137           \textcolor{keywordflow}{if} (depth(i) < gv\%H\_subroundoff*h\_rescale) \&}
\DoxyCodeLine{3138               depth(i) = gv\%H\_subroundoff*h\_rescale}
\DoxyCodeLine{3139           \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3140             sfc\_state\%SST(i,j) = sfc\_state\%SST(i,j) / depth(i)}
\DoxyCodeLine{3141             sfc\_state\%SSS(i,j) = sfc\_state\%SSS(i,j) / depth(i)}
\DoxyCodeLine{3142           \textcolor{keywordflow}{else}}
\DoxyCodeLine{3143             sfc\_state\%sfc\_density(i,j) = sfc\_state\%sfc\_density(i,j) / depth(i)}
\DoxyCodeLine{3144 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3145         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3146           \textcolor{keywordflow}{if} (depth(i) < gv\%H\_subroundoff*h\_rescale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3147             i\_depth = 1.0 / (gv\%H\_subroundoff*h\_rescale)}
\DoxyCodeLine{3148             missing\_depth = gv\%H\_subroundoff*h\_rescale -\/ depth(i)}
\DoxyCodeLine{3149             \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3150               sfc\_state\%SST(i,j) = (sfc\_state\%SST(i,j) + missing\_depth*cs\%tv\%T(i,j,1)) * i\_depth}
\DoxyCodeLine{3151               sfc\_state\%SSS(i,j) = (sfc\_state\%SSS(i,j) + missing\_depth*cs\%tv\%S(i,j,1)) * i\_depth}
\DoxyCodeLine{3152             \textcolor{keywordflow}{else}}
\DoxyCodeLine{3153               sfc\_state\%sfc\_density(i,j) = (sfc\_state\%sfc\_density(i,j) + \&}
\DoxyCodeLine{3154                                             missing\_depth*gv\%Rlay(1)) * i\_depth}
\DoxyCodeLine{3155 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{3156           \textcolor{keywordflow}{else}}
\DoxyCodeLine{3157             i\_depth = 1.0 / depth(i)}
\DoxyCodeLine{3158             \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3159               sfc\_state\%SST(i,j) = sfc\_state\%SST(i,j) * i\_depth}
\DoxyCodeLine{3160               sfc\_state\%SSS(i,j) = sfc\_state\%SSS(i,j) * i\_depth}
\DoxyCodeLine{3161             \textcolor{keywordflow}{else}}
\DoxyCodeLine{3162               sfc\_state\%sfc\_density(i,j) = sfc\_state\%sfc\_density(i,j) * i\_depth}
\DoxyCodeLine{3163 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{3164 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3165 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3166 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3167 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end of j loop}}
\DoxyCodeLine{3168 }
\DoxyCodeLine{3169 \textcolor{comment}{!   Determine the mean velocities in the uppermost depth\_ml fluid.}}
\DoxyCodeLine{3170     \textcolor{comment}{! NOTE: Velocity loops start on `[ij]s-\/1` in order to update halo values}}
\DoxyCodeLine{3171     \textcolor{comment}{!       required by the speed diagnostic on the non-\/symmetric grid.}}
\DoxyCodeLine{3172     \textcolor{comment}{!       This assumes that u and v halos have already been updated.}}
\DoxyCodeLine{3173     \textcolor{keywordflow}{if} (cs\%Hmix\_UV>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3174       depth\_ml = cs\%Hmix\_UV}
\DoxyCodeLine{3175       \textcolor{keywordflow}{if} (.not.cs\%answers\_2018) depth\_ml = cs\%Hmix\_UV*gv\%Z\_to\_H}
\DoxyCodeLine{3176       \textcolor{comment}{!\$OMP parallel do default(shared) private(depth,dh,hv)}}
\DoxyCodeLine{3177       \textcolor{keywordflow}{do} j=js-\/1,ie}
\DoxyCodeLine{3178         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3179           depth(i) = 0.0}
\DoxyCodeLine{3180           sfc\_state\%v(i,j) = 0.0}
\DoxyCodeLine{3181 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3182         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3183           hv = 0.5 * (h(i,j,k) + h(i,j+1,k)) * h\_rescale}
\DoxyCodeLine{3184           \textcolor{keywordflow}{if} (depth(i) + hv < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3185             dh = hv}
\DoxyCodeLine{3186           \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3187             dh = depth\_ml -\/ depth(i)}
\DoxyCodeLine{3188           \textcolor{keywordflow}{else}}
\DoxyCodeLine{3189             dh = 0.0}
\DoxyCodeLine{3190 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3191           sfc\_state\%v(i,j) = sfc\_state\%v(i,j) + dh * cs\%v(i,j,k)}
\DoxyCodeLine{3192           depth(i) = depth(i) + dh}
\DoxyCodeLine{3193 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3194         \textcolor{comment}{! Calculate the average properties of the mixed layer depth.}}
\DoxyCodeLine{3195         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3196           sfc\_state\%v(i,j) = sfc\_state\%v(i,j) / max(depth(i), gv\%H\_subroundoff*h\_rescale)}
\DoxyCodeLine{3197 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3198 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! end of j loop}}
\DoxyCodeLine{3199 }
\DoxyCodeLine{3200       \textcolor{comment}{!\$OMP parallel do default(shared) private(depth,dh,hu)}}
\DoxyCodeLine{3201       \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{3202         \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3203           depth(i) = 0.0}
\DoxyCodeLine{3204           sfc\_state\%u(i,j) = 0.0}
\DoxyCodeLine{3205 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3206         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3207           hu = 0.5 * (h(i,j,k) + h(i+1,j,k)) * h\_rescale}
\DoxyCodeLine{3208           \textcolor{keywordflow}{if} (depth(i) + hu < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3209             dh = hu}
\DoxyCodeLine{3210           \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3211             dh = depth\_ml -\/ depth(i)}
\DoxyCodeLine{3212           \textcolor{keywordflow}{else}}
\DoxyCodeLine{3213             dh = 0.0}
\DoxyCodeLine{3214 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{3215           sfc\_state\%u(i,j) = sfc\_state\%u(i,j) + dh * cs\%u(i,j,k)}
\DoxyCodeLine{3216           depth(i) = depth(i) + dh}
\DoxyCodeLine{3217 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3218         \textcolor{comment}{! Calculate the average properties of the mixed layer depth.}}
\DoxyCodeLine{3219         \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3220           sfc\_state\%u(i,j) = sfc\_state\%u(i,j) / max(depth(i), gv\%H\_subroundoff*h\_rescale)}
\DoxyCodeLine{3221 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{3222 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! end of j loop}}
\DoxyCodeLine{3223     \textcolor{keywordflow}{else} \textcolor{comment}{! Hmix\_UV<=0.}}
\DoxyCodeLine{3224       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3225         sfc\_state\%u(i,j) = cs\%u(i,j,1)}
\DoxyCodeLine{3226 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3227       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3228         sfc\_state\%v(i,j) = cs\%v(i,j,1)}
\DoxyCodeLine{3229 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3230 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3231 \textcolor{keywordflow}{  endif}  \textcolor{comment}{! (CS\%Hmix >= 0.0)}}
\DoxyCodeLine{3232 }
\DoxyCodeLine{3233 }
\DoxyCodeLine{3234   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%melt\_potential)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3235     \textcolor{comment}{!\$OMP parallel do default(shared) private(depth\_ml, dh, T\_freeze, depth, delT)}}
\DoxyCodeLine{3236     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{3237       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3238         depth(i) = 0.0}
\DoxyCodeLine{3239         delt(i) = 0.0}
\DoxyCodeLine{3240 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3241 }
\DoxyCodeLine{3242       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3243         depth\_ml = min(cs\%HFrz, cs\%visc\%MLD(i,j))}
\DoxyCodeLine{3244         \textcolor{keywordflow}{if} (depth(i) + h(i,j,k)*gv\%H\_to\_Z < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3245           dh = h(i,j,k)*gv\%H\_to\_Z}
\DoxyCodeLine{3246         \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3247           dh = depth\_ml -\/ depth(i)}
\DoxyCodeLine{3248         \textcolor{keywordflow}{else}}
\DoxyCodeLine{3249           dh = 0.0}
\DoxyCodeLine{3250 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{3251 }
\DoxyCodeLine{3252         \textcolor{comment}{! p=0 OK, HFrz ~ 10 to 20m}}
\DoxyCodeLine{3253         \textcolor{keyword}{call }calculate\_tfreeze(cs\%tv\%S(i,j,k), 0.0, t\_freeze, cs\%tv\%eqn\_of\_state)}
\DoxyCodeLine{3254         depth(i) = depth(i) + dh}
\DoxyCodeLine{3255         delt(i) =  delt(i) + dh * (cs\%tv\%T(i,j,k) -\/ t\_freeze)}
\DoxyCodeLine{3256 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3257 }
\DoxyCodeLine{3258       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3259        \textcolor{comment}{! set melt\_potential to zero to avoid passing previous values}}
\DoxyCodeLine{3260        sfc\_state\%melt\_potential(i,j) = 0.0}
\DoxyCodeLine{3261 }
\DoxyCodeLine{3262        \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3263          \textcolor{comment}{! instantaneous melt\_potential [Q R Z ~> J m-\/2]}}
\DoxyCodeLine{3264          sfc\_state\%melt\_potential(i,j) = cs\%tv\%C\_p * gv\%Rho0 * delt(i)}
\DoxyCodeLine{3265 \textcolor{keywordflow}{       endif}}
\DoxyCodeLine{3266 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{3267 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end of j loop}}
\DoxyCodeLine{3268 \textcolor{keywordflow}{  endif}   \textcolor{comment}{! melt\_potential}}
\DoxyCodeLine{3269 }
\DoxyCodeLine{3270   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%salt\_deficit) .and. \textcolor{keyword}{associated}(cs\%tv\%salt\_deficit)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3271     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3272     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3273       \textcolor{comment}{! Convert from gSalt to kgSalt}}
\DoxyCodeLine{3274       sfc\_state\%salt\_deficit(i,j) = 0.001 * cs\%tv\%salt\_deficit(i,j)}
\DoxyCodeLine{3275 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3276 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3277   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%TempxPmE) .and. \textcolor{keyword}{associated}(cs\%tv\%TempxPmE)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3278     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3279     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3280       sfc\_state\%TempxPmE(i,j) = cs\%tv\%TempxPmE(i,j)}
\DoxyCodeLine{3281 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3282 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3283   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%internal\_heat) .and. \textcolor{keyword}{associated}(cs\%tv\%internal\_heat)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3284     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3285     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3286       sfc\_state\%internal\_heat(i,j) = cs\%tv\%internal\_heat(i,j)}
\DoxyCodeLine{3287 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3288 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3289   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%taux\_shelf) .and. \textcolor{keyword}{associated}(cs\%visc\%taux\_shelf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3290     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3291     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{3292       sfc\_state\%taux\_shelf(i,j) = cs\%visc\%taux\_shelf(i,j)}
\DoxyCodeLine{3293 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3294 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3295   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%tauy\_shelf) .and. \textcolor{keyword}{associated}(cs\%visc\%tauy\_shelf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3296     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3297     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3298       sfc\_state\%tauy\_shelf(i,j) = cs\%visc\%tauy\_shelf(i,j)}
\DoxyCodeLine{3299 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3300 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3301 }
\DoxyCodeLine{3302   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%ocean\_mass) .and. \textcolor{keyword}{allocated}(sfc\_state\%ocean\_heat) .and. \&}
\DoxyCodeLine{3303       \textcolor{keyword}{allocated}(sfc\_state\%ocean\_salt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3304     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3305     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3306       sfc\_state\%ocean\_mass(i,j) = 0.0}
\DoxyCodeLine{3307       sfc\_state\%ocean\_heat(i,j) = 0.0 ; sfc\_state\%ocean\_salt(i,j) = 0.0}
\DoxyCodeLine{3308 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3309     \textcolor{comment}{!\$OMP parallel do default(shared) private(mass)}}
\DoxyCodeLine{3310     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3311       mass = gv\%H\_to\_RZ*h(i,j,k)}
\DoxyCodeLine{3312       sfc\_state\%ocean\_mass(i,j) = sfc\_state\%ocean\_mass(i,j) + mass}
\DoxyCodeLine{3313       sfc\_state\%ocean\_heat(i,j) = sfc\_state\%ocean\_heat(i,j) + mass * cs\%tv\%T(i,j,k)}
\DoxyCodeLine{3314       sfc\_state\%ocean\_salt(i,j) = sfc\_state\%ocean\_salt(i,j) + mass * (1.0e-\/3*cs\%tv\%S(i,j,k))}
\DoxyCodeLine{3315 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3316   \textcolor{keywordflow}{else}}
\DoxyCodeLine{3317     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%ocean\_mass)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3318       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3319       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; sfc\_state\%ocean\_mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3320       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3321       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3322         sfc\_state\%ocean\_mass(i,j) = sfc\_state\%ocean\_mass(i,j) + gv\%H\_to\_RZ*h(i,j,k)}
\DoxyCodeLine{3323 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3324 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3325     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%ocean\_heat)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3326       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3327       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; sfc\_state\%ocean\_heat(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3328       \textcolor{comment}{!\$OMP parallel do default(shared) private(mass)}}
\DoxyCodeLine{3329       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3330         mass = gv\%H\_to\_RZ*h(i,j,k)}
\DoxyCodeLine{3331         sfc\_state\%ocean\_heat(i,j) = sfc\_state\%ocean\_heat(i,j) + mass*cs\%tv\%T(i,j,k)}
\DoxyCodeLine{3332 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3333 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3334     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state\%ocean\_salt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3335       \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{3336       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; sfc\_state\%ocean\_salt(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3337       \textcolor{comment}{!\$OMP parallel do default(shared) private(mass)}}
\DoxyCodeLine{3338       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3339         mass = gv\%H\_to\_RZ*h(i,j,k)}
\DoxyCodeLine{3340         sfc\_state\%ocean\_salt(i,j) = sfc\_state\%ocean\_salt(i,j) + mass * (1.0e-\/3*cs\%tv\%S(i,j,k))}
\DoxyCodeLine{3341 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3342 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3343 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3344 }
\DoxyCodeLine{3345   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tracer\_flow\_CSp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3346     \textcolor{keyword}{call }call\_tracer\_surface\_state(sfc\_state, h, g, cs\%tracer\_flow\_CSp)}
\DoxyCodeLine{3347 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3348 }
\DoxyCodeLine{3349   \textcolor{keywordflow}{if} (cs\%check\_bad\_sfc\_vals) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3350     numberoferrors=0 \textcolor{comment}{! count number of errors}}
\DoxyCodeLine{3351     \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{3352       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3353         localerror = sfc\_state\%sea\_lev(i,j) <= -\/g\%bathyT(i,j) \&}
\DoxyCodeLine{3354                 .or. sfc\_state\%sea\_lev(i,j) >=  cs\%bad\_val\_ssh\_max  \&}
\DoxyCodeLine{3355                 .or. sfc\_state\%sea\_lev(i,j) <= -\/cs\%bad\_val\_ssh\_max  \&}
\DoxyCodeLine{3356                 .or. sfc\_state\%sea\_lev(i,j) + g\%bathyT(i,j) < cs\%bad\_val\_col\_thick}
\DoxyCodeLine{3357         \textcolor{keywordflow}{if} (use\_temperature) localerror = localerror \&}
\DoxyCodeLine{3358                 .or. sfc\_state\%SSS(i,j)<0.                        \&}
\DoxyCodeLine{3359                 .or. sfc\_state\%SSS(i,j)>=cs\%bad\_val\_sss\_max       \&}
\DoxyCodeLine{3360                 .or. sfc\_state\%SST(i,j)< cs\%bad\_val\_sst\_min       \&}
\DoxyCodeLine{3361                 .or. sfc\_state\%SST(i,j)>=cs\%bad\_val\_sst\_max}
\DoxyCodeLine{3362         \textcolor{keywordflow}{if} (localerror) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3363           numberoferrors=numberoferrors+1}
\DoxyCodeLine{3364           \textcolor{keywordflow}{if} (numberoferrors<9) \textcolor{keywordflow}{then} \textcolor{comment}{! Only report details for the first few errors}}
\DoxyCodeLine{3365             ig = i + g\%HI\%idg\_offset \textcolor{comment}{! Global i-\/index}}
\DoxyCodeLine{3366             jg = j + g\%HI\%jdg\_offset \textcolor{comment}{! Global j-\/index}}
\DoxyCodeLine{3367             \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3368               \textcolor{keyword}{write}(msg(1:240),\textcolor{stringliteral}{'(2(a,i4,x),4(a,f8.3,x),8(a,es11.4,x))'}) \&}
\DoxyCodeLine{3369                 \textcolor{stringliteral}{'Extreme surface sfc\_state detected: i='},ig,\textcolor{stringliteral}{'j='},jg, \&}
\DoxyCodeLine{3370                 \textcolor{stringliteral}{'lon='},g\%geoLonT(i,j), \textcolor{stringliteral}{'lat='},g\%geoLatT(i,j), \&}
\DoxyCodeLine{3371                 \textcolor{stringliteral}{'x='},g\%gridLonT(ig), \textcolor{stringliteral}{'y='},g\%gridLatT(jg), \&}
\DoxyCodeLine{3372                 \textcolor{stringliteral}{'D='},cs\%US\%Z\_to\_m*g\%bathyT(i,j),  \textcolor{stringliteral}{'SSH='},cs\%US\%Z\_to\_m*sfc\_state\%sea\_lev(i,j), \&}
\DoxyCodeLine{3373                 \textcolor{stringliteral}{'SST='},sfc\_state\%SST(i,j), \textcolor{stringliteral}{'SSS='},sfc\_state\%SSS(i,j), \&}
\DoxyCodeLine{3374                 \textcolor{stringliteral}{'U-\/='},us\%L\_T\_to\_m\_s*sfc\_state\%u(i-\/1,j), \textcolor{stringliteral}{'U+='},us\%L\_T\_to\_m\_s*sfc\_state\%u(i,j), \&}
\DoxyCodeLine{3375                 \textcolor{stringliteral}{'V-\/='},us\%L\_T\_to\_m\_s*sfc\_state\%v(i,j-\/1), \textcolor{stringliteral}{'V+='},us\%L\_T\_to\_m\_s*sfc\_state\%v(i,j)}
\DoxyCodeLine{3376             \textcolor{keywordflow}{else}}
\DoxyCodeLine{3377               \textcolor{keyword}{write}(msg(1:240),\textcolor{stringliteral}{'(2(a,i4,x),4(a,f8.3,x),6(a,es11.4))'}) \&}
\DoxyCodeLine{3378                 \textcolor{stringliteral}{'Extreme surface sfc\_state detected: i='},ig,\textcolor{stringliteral}{'j='},jg, \&}
\DoxyCodeLine{3379                 \textcolor{stringliteral}{'lon='},g\%geoLonT(i,j), \textcolor{stringliteral}{'lat='},g\%geoLatT(i,j), \&}
\DoxyCodeLine{3380                 \textcolor{stringliteral}{'x='},g\%gridLonT(i), \textcolor{stringliteral}{'y='},g\%gridLatT(j), \&}
\DoxyCodeLine{3381                 \textcolor{stringliteral}{'D='},cs\%US\%Z\_to\_m*g\%bathyT(i,j),  \textcolor{stringliteral}{'SSH='},cs\%US\%Z\_to\_m*sfc\_state\%sea\_lev(i,j), \&}
\DoxyCodeLine{3382                 \textcolor{stringliteral}{'U-\/='},us\%L\_T\_to\_m\_s*sfc\_state\%u(i-\/1,j), \textcolor{stringliteral}{'U+='},us\%L\_T\_to\_m\_s*sfc\_state\%u(i,j), \&}
\DoxyCodeLine{3383                 \textcolor{stringliteral}{'V-\/='},us\%L\_T\_to\_m\_s*sfc\_state\%v(i,j-\/1), \textcolor{stringliteral}{'V+='},us\%L\_T\_to\_m\_s*sfc\_state\%v(i,j)}
\DoxyCodeLine{3384 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{3385             \textcolor{keyword}{call }mom\_error(warning, trim(msg), all\_print=.true.)}
\DoxyCodeLine{3386           \textcolor{keywordflow}{elseif} (numberoferrors==9) \textcolor{keywordflow}{then} \textcolor{comment}{! Indicate once that there are more errors}}
\DoxyCodeLine{3387             \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'There were more unreported extreme events!'}, all\_print=.true.)}
\DoxyCodeLine{3388 \textcolor{keywordflow}{          endif} \textcolor{comment}{! numberOfErrors}}
\DoxyCodeLine{3389 \textcolor{keywordflow}{        endif} \textcolor{comment}{! localError}}
\DoxyCodeLine{3390 \textcolor{keywordflow}{      endif} \textcolor{comment}{! mask2dT}}
\DoxyCodeLine{3391 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{3392     \textcolor{keyword}{call }sum\_across\_pes(numberoferrors)}
\DoxyCodeLine{3393     \textcolor{keywordflow}{if} (numberoferrors>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3394       \textcolor{keyword}{write}(msg(1:240),\textcolor{stringliteral}{'(3(a,i9,x))'}) \textcolor{stringliteral}{'There were a total of '},numberoferrors, \&}
\DoxyCodeLine{3395           \textcolor{stringliteral}{'locations detected with extreme surface values!'}}
\DoxyCodeLine{3396       \textcolor{keyword}{call }mom\_error(fatal, trim(msg))}
\DoxyCodeLine{3397 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{3398 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3399 }
\DoxyCodeLine{3400   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keyword}{call }mom\_surface\_chksum(\textcolor{stringliteral}{"Post extract\_sfc"}, sfc\_state, g, us, haloshift=0)}
\DoxyCodeLine{3401 }
\DoxyCodeLine{3402   \textcolor{comment}{! Rotate sfc\_state back onto the input grid, sfc\_state\_in}}
\DoxyCodeLine{3403   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3404     \textcolor{keyword}{call }rotate\_surface\_state(sfc\_state, g, sfc\_state\_in, g\_in, -\/turns)}
\DoxyCodeLine{3405     \textcolor{keyword}{call }deallocate\_surface\_state(sfc\_state)}
\DoxyCodeLine{3406 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3407 }
\DoxyCodeLine{3408   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"extract\_surface\_sfc\_state()"})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a2269d5cd79625cbf16cb916346379207}\label{namespacemom_a2269d5cd79625cbf16cb916346379207}} 
\index{mom@{mom}!finish\_mom\_initialization@{finish\_mom\_initialization}}
\index{finish\_mom\_initialization@{finish\_mom\_initialization}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{finish\_mom\_initialization()}{finish\_mom\_initialization()}}
{\footnotesize\ttfamily subroutine, public mom\+::finish\+\_\+mom\+\_\+initialization (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(directories), intent(in)}]{dirs,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



Finishes initializing M\+OM and writes out the initial conditions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & model time, used in this routine \\
\hline
\mbox{\texttt{ in}}  & {\em dirs} & structure with directory paths \\
\hline
 & {\em cs} & pointer to M\+OM control structure \\
\hline
 & {\em restart\+\_\+csp} & pointer to the restart control structure that will be used for M\+OM. \\
\hline
\end{DoxyParams}


Definition at line 2774 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2774   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{        !< model time, used in this routine}}
\DoxyCodeLine{2775   \textcolor{keywordtype}{type}(directories),        \textcolor{keywordtype}{intent(in)}    :: dirs\textcolor{comment}{        !< structure with directory paths}}
\DoxyCodeLine{2776   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{          !< pointer to MOM control structure}}
\DoxyCodeLine{2777   \textcolor{keywordtype}{type}(MOM\_restart\_CS),     \textcolor{keywordtype}{pointer}       :: restart\_CSp\textcolor{comment}{ !< pointer to the restart control}}
\DoxyCodeLine{2778 \textcolor{comment}{                                                         !! structure that will be used for MOM.}}
\DoxyCodeLine{2779   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2780   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null()  \textcolor{comment}{! pointer to a structure containing}}
\DoxyCodeLine{2781                                                    \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{2782   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to the vertical grid structure}}
\DoxyCodeLine{2783   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{2784                                                    \textcolor{comment}{! various unit conversion factors}}
\DoxyCodeLine{2785   \textcolor{keywordtype}{type}(MOM\_restart\_CS),    \textcolor{keywordtype}{pointer} :: restart\_CSp\_tmp => null()}
\DoxyCodeLine{2786 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable} :: z\_interface(:,:,:) \textcolor{comment}{! Interface heights [m]}}
\DoxyCodeLine{2787   \textcolor{keywordtype}{type}(vardesc) :: vd}
\DoxyCodeLine{2788 }
\DoxyCodeLine{2789   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_init)}
\DoxyCodeLine{2790   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"finish\_MOM\_initialization()"})}
\DoxyCodeLine{2791 }
\DoxyCodeLine{2792   \textcolor{comment}{! Pointers for convenience}}
\DoxyCodeLine{2793   g => cs\%G ; gv => cs\%GV ; us => cs\%US}
\DoxyCodeLine{2794 }
\DoxyCodeLine{2795   \textcolor{comment}{!\#\#\# Move to initialize\_MOM?}}
\DoxyCodeLine{2796   \textcolor{keyword}{call }fix\_restart\_scaling(gv)}
\DoxyCodeLine{2797   \textcolor{keyword}{call }fix\_restart\_unit\_scaling(us)}
\DoxyCodeLine{2798 }
\DoxyCodeLine{2799   \textcolor{comment}{! Write initial conditions}}
\DoxyCodeLine{2800   \textcolor{keywordflow}{if} (cs\%write\_IC) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2801     \textcolor{keyword}{allocate}(restart\_csp\_tmp)}
\DoxyCodeLine{2802     restart\_csp\_tmp = restart\_csp}
\DoxyCodeLine{2803     \textcolor{keyword}{allocate}(z\_interface(szi\_(g),szj\_(g),szk\_(g)+1))}
\DoxyCodeLine{2804     \textcolor{keyword}{call }find\_eta(cs\%h, cs\%tv, g, gv, us, z\_interface, eta\_to\_m=1.0)}
\DoxyCodeLine{2805     \textcolor{keyword}{call }register\_restart\_field(z\_interface, \textcolor{stringliteral}{"eta"}, .true., restart\_csp\_tmp, \&}
\DoxyCodeLine{2806                                 \textcolor{stringliteral}{"Interface heights"}, \textcolor{stringliteral}{"meter"}, z\_grid=\textcolor{stringliteral}{'i'})}
\DoxyCodeLine{2807 }
\DoxyCodeLine{2808     \textcolor{keyword}{call }save\_restart(dirs\%output\_directory, time, cs\%G\_in, \&}
\DoxyCodeLine{2809                       restart\_csp\_tmp, filename=cs\%IC\_file, gv=gv)}
\DoxyCodeLine{2810     \textcolor{keyword}{deallocate}(z\_interface)}
\DoxyCodeLine{2811     \textcolor{keyword}{deallocate}(restart\_csp\_tmp)}
\DoxyCodeLine{2812 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2813 }
\DoxyCodeLine{2814   \textcolor{keyword}{call }write\_energy(cs\%u, cs\%v, cs\%h, cs\%tv, time, 0, g, gv, us, \&}
\DoxyCodeLine{2815                     cs\%sum\_output\_CSp, cs\%tracer\_flow\_CSp)}
\DoxyCodeLine{2816 }
\DoxyCodeLine{2817   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"finish\_MOM\_initialization()"})}
\DoxyCodeLine{2818   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_init)}
\DoxyCodeLine{2819 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_aece0dd1e2c9498844befd8ba71986b96}\label{namespacemom_aece0dd1e2c9498844befd8ba71986b96}} 
\index{mom@{mom}!get\_mom\_state\_elements@{get\_mom\_state\_elements}}
\index{get\_mom\_state\_elements@{get\_mom\_state\_elements}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{get\_mom\_state\_elements()}{get\_mom\_state\_elements()}}
{\footnotesize\ttfamily subroutine, public mom\+::get\+\_\+mom\+\_\+state\+\_\+elements (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), optional, pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), optional, pointer}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), optional, pointer}]{US,  }\item[{real, intent(out), optional}]{C\+\_\+p,  }\item[{real, intent(out), optional}]{C\+\_\+p\+\_\+scaled,  }\item[{logical, intent(out), optional}]{use\+\_\+temp }\end{DoxyParamCaption})}



This subroutine offers access to values or pointers to other types from within the M\+O\+M\+\_\+control\+\_\+struct, allowing the M\+O\+M\+\_\+control\+\_\+struct to be opaque. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+OM control structure \\
\hline
 & {\em g} & structure containing metrics and grid info \\
\hline
 & {\em gv} & structure containing vertical grid info \\
\hline
 & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ out}}  & {\em c\+\_\+p} & The heat capacity \mbox{[}J kg deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em c\+\_\+p\+\_\+scaled} & The heat capacity in scaled units \mbox{[}Q deg\+C-\/1 $\sim$$>$ J kg deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em use\+\_\+temp} & True if temperature is a state variable \\
\hline
\end{DoxyParams}


Definition at line 3450 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3450   \textcolor{keywordtype}{type}(MOM\_control\_struct),          \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{ !< MOM control structure}}
\DoxyCodeLine{3451   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: G\textcolor{comment}{    !< structure containing metrics and grid info}}
\DoxyCodeLine{3452   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: GV\textcolor{comment}{   !< structure containing vertical grid info}}
\DoxyCodeLine{3453   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{3454 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: C\_p\textcolor{comment}{  !< The heat capacity [J kg degC-\/1]}}
\DoxyCodeLine{3455 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: C\_p\_scaled\textcolor{comment}{ !< The heat capacity in scaled}}
\DoxyCodeLine{3456 \textcolor{comment}{                                                         !! units [Q degC-\/1 ~> J kg degC-\/1]}}
\DoxyCodeLine{3457   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: use\_temp\textcolor{comment}{ !< True if temperature is a state variable}}
\DoxyCodeLine{3458 }
\DoxyCodeLine{3459   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(g)) g => cs\%G\_in}
\DoxyCodeLine{3460   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(gv)) gv => cs\%GV}
\DoxyCodeLine{3461   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) us => cs\%US}
\DoxyCodeLine{3462   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(c\_p)) c\_p = cs\%US\%Q\_to\_J\_kg * cs\%tv\%C\_p}
\DoxyCodeLine{3463   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(c\_p\_scaled)) c\_p\_scaled = cs\%tv\%C\_p}
\DoxyCodeLine{3464   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(use\_temp)) use\_temp = \textcolor{keyword}{associated}(cs\%tv\%T)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a462293ed92e99927ef9939747d633080}\label{namespacemom_a462293ed92e99927ef9939747d633080}} 
\index{mom@{mom}!get\_ocean\_stocks@{get\_ocean\_stocks}}
\index{get\_ocean\_stocks@{get\_ocean\_stocks}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{get\_ocean\_stocks()}{get\_ocean\_stocks()}}
{\footnotesize\ttfamily subroutine, public mom\+::get\+\_\+ocean\+\_\+stocks (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{real, intent(out), optional}]{mass,  }\item[{real, intent(out), optional}]{heat,  }\item[{real, intent(out), optional}]{salt,  }\item[{logical, intent(in), optional}]{on\+\_\+\+P\+E\+\_\+only }\end{DoxyParamCaption})}



Find the global integrals of various quantities. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+OM control structure \\
\hline
\mbox{\texttt{ out}}  & {\em heat} & The globally integrated integrated ocean heat \mbox{[}J\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em salt} & The globally integrated integrated ocean salt \mbox{[}kg\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em mass} & The globally integrated integrated ocean mass \mbox{[}kg\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em on\+\_\+pe\+\_\+only} & If present and true, only sum on the local PE. \\
\hline
\end{DoxyParams}


Definition at line 3469 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3469   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< MOM control structure}}
\DoxyCodeLine{3470 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: heat\textcolor{comment}{  !< The globally integrated integrated ocean heat [J].}}
\DoxyCodeLine{3471 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: salt\textcolor{comment}{  !< The globally integrated integrated ocean salt [kg].}}
\DoxyCodeLine{3472 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: mass\textcolor{comment}{  !< The globally integrated integrated ocean mass [kg].}}
\DoxyCodeLine{3473   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: on\_PE\_only\textcolor{comment}{ !< If present and true, only sum on the local PE.}}
\DoxyCodeLine{3474 }
\DoxyCodeLine{3475   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(mass)) \&}
\DoxyCodeLine{3476     mass = global\_mass\_integral(cs\%h, cs\%G, cs\%GV, on\_pe\_only=on\_pe\_only)}
\DoxyCodeLine{3477   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(heat)) \&}
\DoxyCodeLine{3478     heat = cs\%US\%Q\_to\_J\_kg*cs\%tv\%C\_p * global\_mass\_integral(cs\%h, cs\%G, cs\%GV, cs\%tv\%T, on\_pe\_only=on\_pe\_only)}
\DoxyCodeLine{3479   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(salt)) \&}
\DoxyCodeLine{3480     salt = 1.0e-\/3 * global\_mass\_integral(cs\%h, cs\%G, cs\%GV, cs\%tv\%S, on\_pe\_only=on\_pe\_only)}
\DoxyCodeLine{3481 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a96708b16215666edbfa5b46228f3a200}\label{namespacemom_a96708b16215666edbfa5b46228f3a200}} 
\index{mom@{mom}!initialize\_mom@{initialize\_mom}}
\index{initialize\_mom@{initialize\_mom}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{initialize\_mom()}{initialize\_mom()}}
{\footnotesize\ttfamily subroutine, public mom\+::initialize\+\_\+mom (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(inout), target}]{Time,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+init,  }\item[{type(param\+\_\+file\+\_\+type), intent(out)}]{param\+\_\+file,  }\item[{type(directories), intent(out)}]{dirs,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+C\+Sp,  }\item[{type(time\+\_\+type), intent(in), optional}]{Time\+\_\+in,  }\item[{logical, intent(out), optional}]{offline\+\_\+tracer\+\_\+mode,  }\item[{character(len=$\ast$), intent(in), optional}]{input\+\_\+restart\+\_\+file,  }\item[{type(diag\+\_\+ctrl), optional, pointer}]{diag\+\_\+ptr,  }\item[{logical, intent(in), optional}]{count\+\_\+calls,  }\item[{type(tracer\+\_\+flow\+\_\+control\+\_\+cs), optional, pointer}]{tracer\+\_\+flow\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



Initialize M\+OM, including memory allocation, setting up parameters and diagnostics, initializing the ocean state variables, and initializing subsidiary modules. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em time} & model time, set in this routine \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+init} & The start time for the coupled model\textquotesingle{}s calendar \\
\hline
\mbox{\texttt{ out}}  & {\em param\+\_\+file} & structure indicating parameter file to parse \\
\hline
\mbox{\texttt{ out}}  & {\em dirs} & structure with directory paths \\
\hline
 & {\em cs} & pointer set in this routine to M\+OM control structure \\
\hline
 & {\em restart\+\_\+csp} & pointer set in this routine to the restart control structure that will be used for M\+OM. \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+in} & time passed to M\+O\+M\+\_\+initialize\+\_\+state when model is not being started from a restart file \\
\hline
\mbox{\texttt{ out}}  & {\em offline\+\_\+tracer\+\_\+mode} & True is returned if tracers are being run offline \\
\hline
\mbox{\texttt{ in}}  & {\em input\+\_\+restart\+\_\+file} & If present, name of restart file to read \\
\hline
 & {\em diag\+\_\+ptr} & A pointer set in this routine to the diagnostic regulatory structure \\
\hline
 & {\em tracer\+\_\+flow\+\_\+csp} & A pointer set in this routine to \\
\hline
\mbox{\texttt{ in}}  & {\em count\+\_\+calls} & If true, nstep\+\_\+tot counts the number of calls to step\+\_\+\+M\+OM instead of the number of dynamics timesteps. \\
\hline
\end{DoxyParams}


Definition at line 1604 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1604   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(inout)} :: Time\textcolor{comment}{        !< model time, set in this routine}}
\DoxyCodeLine{1605   \textcolor{keywordtype}{type}(time\_type),           \textcolor{keywordtype}{intent(in)}    :: Time\_init\textcolor{comment}{   !< The start time for the coupled model's calendar}}
\DoxyCodeLine{1606   \textcolor{keywordtype}{type}(param\_file\_type),     \textcolor{keywordtype}{intent(out)}   :: param\_file\textcolor{comment}{  !< structure indicating parameter file to parse}}
\DoxyCodeLine{1607   \textcolor{keywordtype}{type}(directories),         \textcolor{keywordtype}{intent(out)}   :: dirs\textcolor{comment}{        !< structure with directory paths}}
\DoxyCodeLine{1608   \textcolor{keywordtype}{type}(MOM\_control\_struct),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{          !< pointer set in this routine to MOM control structure}}
\DoxyCodeLine{1609   \textcolor{keywordtype}{type}(MOM\_restart\_CS),      \textcolor{keywordtype}{pointer}       :: restart\_CSp\textcolor{comment}{ !< pointer set in this routine to the}}
\DoxyCodeLine{1610 \textcolor{comment}{                                                          !! restart control structure that will}}
\DoxyCodeLine{1611 \textcolor{comment}{                                                          !! be used for MOM.}}
\DoxyCodeLine{1612   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: Time\_in\textcolor{comment}{     !< time passed to MOM\_initialize\_state when}}
\DoxyCodeLine{1613 \textcolor{comment}{                                                          !! model is not being started from a restart file}}
\DoxyCodeLine{1614   \textcolor{keywordtype}{logical},         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: offline\_tracer\_mode\textcolor{comment}{ !< True is returned if tracers are being run offline}}
\DoxyCodeLine{1615   \textcolor{keywordtype}{character(len=*)},\textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: input\_restart\_file\textcolor{comment}{ !< If present, name of restart file to read}}
\DoxyCodeLine{1616   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: diag\_ptr\textcolor{comment}{    !< A pointer set in this routine to the diagnostic}}
\DoxyCodeLine{1617 \textcolor{comment}{                                                          !! regulatory structure}}
\DoxyCodeLine{1618   \textcolor{keywordtype}{type}(tracer\_flow\_control\_CS), \&}
\DoxyCodeLine{1619                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: tracer\_flow\_CSp\textcolor{comment}{ !< A pointer set in this routine to}}
\DoxyCodeLine{1620 \textcolor{comment}{                                                          !! the tracer flow control structure.}}
\DoxyCodeLine{1621   \textcolor{keywordtype}{logical},         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: count\_calls\textcolor{comment}{ !< If true, nstep\_tot counts the number of}}
\DoxyCodeLine{1622 \textcolor{comment}{                                                          !! calls to step\_MOM instead of the number of}}
\DoxyCodeLine{1623 \textcolor{comment}{                                                          !! dynamics timesteps.}}
\DoxyCodeLine{1624   \textcolor{comment}{! local variables}}
\DoxyCodeLine{1625   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{pointer} :: G => null()    \textcolor{comment}{! A pointer to the metric grid use for the run}}
\DoxyCodeLine{1626   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{pointer} :: G\_in => null() \textcolor{comment}{! Pointer to the input grid}}
\DoxyCodeLine{1627   \textcolor{keywordtype}{type}(hor\_index\_type),   \textcolor{keywordtype}{pointer} :: HI => null()   \textcolor{comment}{! A hor\_index\_type for array extents}}
\DoxyCodeLine{1628   \textcolor{keywordtype}{type}(hor\_index\_type),   \textcolor{keywordtype}{target}  :: HI\_in          \textcolor{comment}{! HI on the input grid}}
\DoxyCodeLine{1629   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer} :: GV => null()}
\DoxyCodeLine{1630   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{pointer} :: dG => null()}
\DoxyCodeLine{1631   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{pointer} :: dG\_in => null()}
\DoxyCodeLine{1632   \textcolor{keywordtype}{type}(diag\_ctrl),        \textcolor{keywordtype}{pointer} :: diag => null()}
\DoxyCodeLine{1633   \textcolor{keywordtype}{type}(unit\_scale\_type),  \textcolor{keywordtype}{pointer} :: US => null()}
\DoxyCodeLine{1634   \textcolor{keywordtype}{character(len=4)}, \textcolor{keywordtype}{parameter} :: vers\_num = \textcolor{stringliteral}{'v2.0'}}
\DoxyCodeLine{1635   \textcolor{keywordtype}{integer} :: turns   \textcolor{comment}{! Number of grid quarter-\/turns}}
\DoxyCodeLine{1636 }
\DoxyCodeLine{1637   \textcolor{comment}{! Initial state on the input index map}}
\DoxyCodeLine{1638 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: u\_in, v\_in, h\_in}
\DoxyCodeLine{1639 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{target} :: T\_in, S\_in}
\DoxyCodeLine{1640   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{pointer} :: OBC\_in => null()}
\DoxyCodeLine{1641   \textcolor{keywordtype}{type}(sponge\_CS), \textcolor{keywordtype}{pointer} :: sponge\_in\_CSp => null()}
\DoxyCodeLine{1642   \textcolor{keywordtype}{type}(ALE\_sponge\_CS), \textcolor{keywordtype}{pointer} :: ALE\_sponge\_in\_CSp => null()}
\DoxyCodeLine{1643 }
\DoxyCodeLine{1644   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{1645 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{1646 \textcolor{preprocessor}{}}
\DoxyCodeLine{1647   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz}
\DoxyCodeLine{1648   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{1649 \textcolor{keywordtype}{  real}    :: dtbt        \textcolor{comment}{! The barotropic timestep [s]}}
\DoxyCodeLine{1650 }
\DoxyCodeLine{1651 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)}   :: eta \textcolor{comment}{! free surface height or column mass [H ~> m or kg m-\/2]}}
\DoxyCodeLine{1652 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)}   :: area\_shelf\_h \textcolor{comment}{! area occupied by ice shelf [L2 ~> m2]}}
\DoxyCodeLine{1653 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{target}  :: frac\_shelf\_h \textcolor{comment}{! fraction of total area occupied by ice shelf [nondim]}}
\DoxyCodeLine{1654 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: shelf\_area => null()}
\DoxyCodeLine{1655   \textcolor{keywordtype}{type}(MOM\_restart\_CS),  \textcolor{keywordtype}{pointer}      :: restart\_CSp\_tmp => null()}
\DoxyCodeLine{1656   \textcolor{keywordtype}{type}(group\_pass\_type) :: tmp\_pass\_uv\_T\_S\_h, pass\_uv\_T\_S\_h}
\DoxyCodeLine{1657 }
\DoxyCodeLine{1658 \textcolor{keywordtype}{  real}    :: default\_val       \textcolor{comment}{! default value for a parameter}}
\DoxyCodeLine{1659   \textcolor{keywordtype}{logical} :: write\_geom\_files  \textcolor{comment}{! If true, write out the grid geometry files.}}
\DoxyCodeLine{1660   \textcolor{keywordtype}{logical} :: ensemble\_ocean    \textcolor{comment}{! If true, perform an ensemble gather at the end of step\_MOM}}
\DoxyCodeLine{1661   \textcolor{keywordtype}{logical} :: new\_sim}
\DoxyCodeLine{1662   \textcolor{keywordtype}{logical} :: use\_geothermal    \textcolor{comment}{! If true, apply geothermal heating.}}
\DoxyCodeLine{1663   \textcolor{keywordtype}{logical} :: use\_EOS           \textcolor{comment}{! If true, density calculated from T \& S using an equation of state.}}
\DoxyCodeLine{1664   \textcolor{keywordtype}{logical} :: symmetric         \textcolor{comment}{! If true, use symmetric memory allocation.}}
\DoxyCodeLine{1665   \textcolor{keywordtype}{logical} :: save\_IC           \textcolor{comment}{! If true, save the initial conditions.}}
\DoxyCodeLine{1666   \textcolor{keywordtype}{logical} :: do\_unit\_tests     \textcolor{comment}{! If true, call unit tests.}}
\DoxyCodeLine{1667   \textcolor{keywordtype}{logical} :: test\_grid\_copy = .false.}
\DoxyCodeLine{1668 }
\DoxyCodeLine{1669   \textcolor{keywordtype}{logical} :: bulkmixedlayer    \textcolor{comment}{! If true, a refined bulk mixed layer scheme is used}}
\DoxyCodeLine{1670                                \textcolor{comment}{! with nkml sublayers and nkbl buffer layer.}}
\DoxyCodeLine{1671   \textcolor{keywordtype}{logical} :: use\_temperature   \textcolor{comment}{! If true, temp and saln used as state variables.}}
\DoxyCodeLine{1672   \textcolor{keywordtype}{logical} :: use\_frazil        \textcolor{comment}{! If true, liquid seawater freezes if temp below freezing,}}
\DoxyCodeLine{1673                                \textcolor{comment}{! with accumulated heat deficit returned to surface ocean.}}
\DoxyCodeLine{1674   \textcolor{keywordtype}{logical} :: bound\_salinity    \textcolor{comment}{! If true, salt is added to keep salinity above}}
\DoxyCodeLine{1675                                \textcolor{comment}{! a minimum value, and the deficit is reported.}}
\DoxyCodeLine{1676   \textcolor{keywordtype}{logical} :: default\_2018\_answers \textcolor{comment}{! The default setting for the various 2018\_ANSWERS flags.}}
\DoxyCodeLine{1677   \textcolor{keywordtype}{logical} :: use\_conT\_absS     \textcolor{comment}{! If true, the prognostics T \& S are conservative temperature}}
\DoxyCodeLine{1678                                \textcolor{comment}{! and absolute salinity. Care should be taken to convert them}}
\DoxyCodeLine{1679                                \textcolor{comment}{! to potential temperature and practical salinity before}}
\DoxyCodeLine{1680                                \textcolor{comment}{! exchanging them with the coupler and/or reporting T\&S diagnostics.}}
\DoxyCodeLine{1681   \textcolor{keywordtype}{logical} :: advect\_TS         \textcolor{comment}{! If false, then no horizontal advection of temperature}}
\DoxyCodeLine{1682                                \textcolor{comment}{! and salnity is performed}}
\DoxyCodeLine{1683   \textcolor{keywordtype}{logical} :: use\_ice\_shelf     \textcolor{comment}{! Needed for ALE}}
\DoxyCodeLine{1684   \textcolor{keywordtype}{logical} :: global\_indexing   \textcolor{comment}{! If true use global horizontal index values instead}}
\DoxyCodeLine{1685                                \textcolor{comment}{! of having the data domain on each processor start at 1.}}
\DoxyCodeLine{1686   \textcolor{keywordtype}{logical} :: bathy\_at\_vel      \textcolor{comment}{! If true, also define bathymetric fields at the}}
\DoxyCodeLine{1687                                \textcolor{comment}{! the velocity points.}}
\DoxyCodeLine{1688   \textcolor{keywordtype}{logical} :: calc\_dtbt         \textcolor{comment}{! Indicates whether the dynamically adjusted barotropic}}
\DoxyCodeLine{1689                                \textcolor{comment}{! time step needs to be updated before it is used.}}
\DoxyCodeLine{1690   \textcolor{keywordtype}{logical} :: debug\_truncations \textcolor{comment}{! If true, turn on diagnostics useful for debugging truncations.}}
\DoxyCodeLine{1691   \textcolor{keywordtype}{integer} :: first\_direction   \textcolor{comment}{! An integer that indicates which direction is to be}}
\DoxyCodeLine{1692                                \textcolor{comment}{! updated first in directionally split parts of the}}
\DoxyCodeLine{1693                                \textcolor{comment}{! calculation.  This can be altered during the course}}
\DoxyCodeLine{1694                                \textcolor{comment}{! of the run via calls to set\_first\_direction.}}
\DoxyCodeLine{1695   \textcolor{keywordtype}{integer} :: nkml, nkbl, verbosity, write\_geom}
\DoxyCodeLine{1696   \textcolor{keywordtype}{integer} :: dynamics\_stencil  \textcolor{comment}{! The computational stencil for the calculations}}
\DoxyCodeLine{1697                                \textcolor{comment}{! in the dynamic core.}}
\DoxyCodeLine{1698 \textcolor{keywordtype}{  real} :: conv2watt, conv2salt}
\DoxyCodeLine{1699 \textcolor{keywordtype}{  real} :: RL2\_T2\_rescale, Z\_rescale, QRZ\_rescale \textcolor{comment}{! Unit conversion factors}}
\DoxyCodeLine{1700   \textcolor{keywordtype}{character(len=48)} :: flux\_units, S\_flux\_units}
\DoxyCodeLine{1701 }
\DoxyCodeLine{1702   \textcolor{keywordtype}{type}(vardesc) :: vd\_T, vd\_S  \textcolor{comment}{! Structures describing temperature and salinity variables.}}
\DoxyCodeLine{1703   \textcolor{keywordtype}{type}(time\_type)                 :: Start\_time}
\DoxyCodeLine{1704   \textcolor{keywordtype}{type}(ocean\_internal\_state)      :: MOM\_internal\_state}
\DoxyCodeLine{1705   \textcolor{keywordtype}{character(len=200)} :: area\_varname, ice\_shelf\_file, inputdir, filename}
\DoxyCodeLine{1706 }
\DoxyCodeLine{1707   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1708     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"initialize\_MOM called with an associated "}// \&}
\DoxyCodeLine{1709                             \textcolor{stringliteral}{"control structure."})}
\DoxyCodeLine{1710     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1711 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1712   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{1713 }
\DoxyCodeLine{1714   cs\%Time => time}
\DoxyCodeLine{1715 }
\DoxyCodeLine{1716   id\_clock\_init = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean Initialization'}, grain=clock\_subcomponent)}
\DoxyCodeLine{1717   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_init)}
\DoxyCodeLine{1718 }
\DoxyCodeLine{1719   start\_time = time ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(time\_in)) start\_time = time\_in}
\DoxyCodeLine{1720 }
\DoxyCodeLine{1721   \textcolor{comment}{! Read paths and filenames from namelist and store in "dirs".}}
\DoxyCodeLine{1722   \textcolor{comment}{! Also open the parsed input parameter file(s) and setup param\_file.}}
\DoxyCodeLine{1723   \textcolor{keyword}{call }get\_mom\_input(param\_file, dirs, default\_input\_filename=input\_restart\_file)}
\DoxyCodeLine{1724 }
\DoxyCodeLine{1725   verbosity = 2 ; \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"VERBOSITY"}, verbosity)}
\DoxyCodeLine{1726   \textcolor{keyword}{call }mom\_set\_verbosity(verbosity)}
\DoxyCodeLine{1727   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"initialize\_MOM(), MOM.F90"})}
\DoxyCodeLine{1728 }
\DoxyCodeLine{1729   \textcolor{keyword}{call }find\_obsolete\_params(param\_file)}
\DoxyCodeLine{1730 }
\DoxyCodeLine{1731   \textcolor{comment}{! Determining the internal unit scaling factors for this run.}}
\DoxyCodeLine{1732   \textcolor{keyword}{call }unit\_scaling\_init(param\_file, cs\%US)}
\DoxyCodeLine{1733   us => cs\%US}
\DoxyCodeLine{1734 }
\DoxyCodeLine{1735   \textcolor{comment}{! Read relevant parameters and write them to the model log.}}
\DoxyCodeLine{1736   \textcolor{keyword}{call }log\_version(param\_file, \textcolor{stringliteral}{"MOM"}, version, \textcolor{stringliteral}{""}, log\_to\_all=.true., layout=.true., debugging=.true.)}
\DoxyCodeLine{1737   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"VERBOSITY"}, verbosity,  \&}
\DoxyCodeLine{1738                  \textcolor{stringliteral}{"Integer controlling level of messaging\(\backslash\)n"} // \&}
\DoxyCodeLine{1739                  \textcolor{stringliteral}{"\(\backslash\)t0 = Only FATAL messages\(\backslash\)n"} // \&}
\DoxyCodeLine{1740                  \textcolor{stringliteral}{"\(\backslash\)t2 = Only FATAL, WARNING, NOTE [default]\(\backslash\)n"} // \&}
\DoxyCodeLine{1741                  \textcolor{stringliteral}{"\(\backslash\)t9 = All)"}, default=2, debuggingparam=.true.)}
\DoxyCodeLine{1742   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DO\_UNIT\_TESTS"}, do\_unit\_tests, \&}
\DoxyCodeLine{1743                  \textcolor{stringliteral}{"If True, exercises unit tests at model start up."}, \&}
\DoxyCodeLine{1744                  default=.false., debuggingparam=.true.)}
\DoxyCodeLine{1745   \textcolor{keywordflow}{if} (do\_unit\_tests) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1746     id\_clock\_unit\_tests = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean unit tests)'}, grain=clock\_module)}
\DoxyCodeLine{1747     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_unit\_tests)}
\DoxyCodeLine{1748     \textcolor{keyword}{call }unit\_tests(verbosity)}
\DoxyCodeLine{1749     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_unit\_tests)}
\DoxyCodeLine{1750 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1751 }
\DoxyCodeLine{1752   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"SPLIT"}, cs\%split, \&}
\DoxyCodeLine{1753                  \textcolor{stringliteral}{"Use the split time stepping if true."}, default=.true.)}
\DoxyCodeLine{1754   \textcolor{keywordflow}{if} (cs\%split) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1755     cs\%use\_RK2 = .false.}
\DoxyCodeLine{1756   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1757     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_RK2"}, cs\%use\_RK2, \&}
\DoxyCodeLine{1758                  \textcolor{stringliteral}{"If true, use RK2 instead of RK3 in the unsplit time stepping."}, \&}
\DoxyCodeLine{1759                  default=.false.)}
\DoxyCodeLine{1760 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1761 }
\DoxyCodeLine{1762   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"CALC\_RHO\_FOR\_SEA\_LEVEL"}, cs\%calc\_rho\_for\_sea\_lev, \&}
\DoxyCodeLine{1763                  \textcolor{stringliteral}{"If true, the in-\/situ density is used to calculate the "}//\&}
\DoxyCodeLine{1764                  \textcolor{stringliteral}{"effective sea level that is returned to the coupler. If false, "}//\&}
\DoxyCodeLine{1765                  \textcolor{stringliteral}{"the Boussinesq parameter RHO\_0 is used."}, default=.false.)}
\DoxyCodeLine{1766   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, use\_temperature, \&}
\DoxyCodeLine{1767                  \textcolor{stringliteral}{"If true, Temperature and salinity are used as state "}//\&}
\DoxyCodeLine{1768                  \textcolor{stringliteral}{"variables."}, default=.true.)}
\DoxyCodeLine{1769   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_EOS"}, use\_eos, \&}
\DoxyCodeLine{1770                  \textcolor{stringliteral}{"If true,  density is calculated from temperature and "}//\&}
\DoxyCodeLine{1771                  \textcolor{stringliteral}{"salinity with an equation of state.  If USE\_EOS is "}//\&}
\DoxyCodeLine{1772                  \textcolor{stringliteral}{"true, ENABLE\_THERMODYNAMICS must be true as well."}, \&}
\DoxyCodeLine{1773                  default=use\_temperature)}
\DoxyCodeLine{1774   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DIABATIC\_FIRST"}, cs\%diabatic\_first, \&}
\DoxyCodeLine{1775                  \textcolor{stringliteral}{"If true, apply diabatic and thermodynamic processes, "}//\&}
\DoxyCodeLine{1776                  \textcolor{stringliteral}{"including buoyancy forcing and mass gain or loss, "}//\&}
\DoxyCodeLine{1777                  \textcolor{stringliteral}{"before stepping the dynamics forward."}, default=.false.)}
\DoxyCodeLine{1778   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_CONTEMP\_ABSSAL"}, use\_cont\_abss, \&}
\DoxyCodeLine{1779                  \textcolor{stringliteral}{"If true, the prognostics T\&S are the conservative temperature "}//\&}
\DoxyCodeLine{1780                  \textcolor{stringliteral}{"and absolute salinity. Care should be taken to convert them "}//\&}
\DoxyCodeLine{1781                  \textcolor{stringliteral}{"to potential temperature and practical salinity before "}//\&}
\DoxyCodeLine{1782                  \textcolor{stringliteral}{"exchanging them with the coupler and/or reporting T\&S diagnostics."}, \&}
\DoxyCodeLine{1783                  default=.false.)}
\DoxyCodeLine{1784   cs\%tv\%T\_is\_conT = use\_cont\_abss ; cs\%tv\%S\_is\_absS = use\_cont\_abss}
\DoxyCodeLine{1785   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ADIABATIC"}, cs\%adiabatic, \&}
\DoxyCodeLine{1786                  \textcolor{stringliteral}{"There are no diapycnal mass fluxes if ADIABATIC is "}//\&}
\DoxyCodeLine{1787                  \textcolor{stringliteral}{"true. This assumes that KD = KDML = 0.0 and that "}//\&}
\DoxyCodeLine{1788                  \textcolor{stringliteral}{"there is no buoyancy forcing, but makes the model "}//\&}
\DoxyCodeLine{1789                  \textcolor{stringliteral}{"faster by eliminating subroutine calls."}, default=.false.)}
\DoxyCodeLine{1790   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DO\_DYNAMICS"}, cs\%do\_dynamics, \&}
\DoxyCodeLine{1791                  \textcolor{stringliteral}{"If False, skips the dynamics calls that update u \& v, as well as "}//\&}
\DoxyCodeLine{1792                  \textcolor{stringliteral}{"the gravity wave adjustment to h. This may be a fragile feature, "}//\&}
\DoxyCodeLine{1793                  \textcolor{stringliteral}{"but can be useful during development"}, default=.true.)}
\DoxyCodeLine{1794   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ADVECT\_TS"}, advect\_ts, \&}
\DoxyCodeLine{1795                  \textcolor{stringliteral}{"If True, advect temperature and salinity horizontally "}//\&}
\DoxyCodeLine{1796                  \textcolor{stringliteral}{"If False, T/S are registered for advection. "}//\&}
\DoxyCodeLine{1797                  \textcolor{stringliteral}{"This is intended only to be used in offline tracer mode "}//\&}
\DoxyCodeLine{1798                  \textcolor{stringliteral}{"and is by default false in that case."}, \&}
\DoxyCodeLine{1799                  do\_not\_log = .true., default=.true. )}
\DoxyCodeLine{1800   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(offline\_tracer\_mode)) \textcolor{keywordflow}{then} \textcolor{comment}{! Only read this parameter in enabled modes}}
\DoxyCodeLine{1801     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"OFFLINE\_TRACER\_MODE"}, cs\%offline\_tracer\_mode, \&}
\DoxyCodeLine{1802                  \textcolor{stringliteral}{"If true, barotropic and baroclinic dynamics, thermodynamics "}//\&}
\DoxyCodeLine{1803                  \textcolor{stringliteral}{"are all bypassed with all the fields necessary to integrate "}//\&}
\DoxyCodeLine{1804                  \textcolor{stringliteral}{"the tracer advection and diffusion equation are read in from "}//\&}
\DoxyCodeLine{1805                  \textcolor{stringliteral}{"files stored from a previous integration of the prognostic model. "}//\&}
\DoxyCodeLine{1806                  \textcolor{stringliteral}{"NOTE: This option only used in the ocean\_solo\_driver."}, default=.false.)}
\DoxyCodeLine{1807     \textcolor{keywordflow}{if} (cs\%offline\_tracer\_mode) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1808       \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ADVECT\_TS"}, advect\_ts, \&}
\DoxyCodeLine{1809                    \textcolor{stringliteral}{"If True, advect temperature and salinity horizontally "}//\&}
\DoxyCodeLine{1810                    \textcolor{stringliteral}{"If False, T/S are registered for advection. "}//\&}
\DoxyCodeLine{1811                    \textcolor{stringliteral}{"This is intended only to be used in offline tracer mode."}//\&}
\DoxyCodeLine{1812                    \textcolor{stringliteral}{"and is by default false in that case"}, \&}
\DoxyCodeLine{1813                    default=.false. )}
\DoxyCodeLine{1814 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1815 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1816   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_REGRIDDING"}, cs\%use\_ALE\_algorithm, \&}
\DoxyCodeLine{1817                  \textcolor{stringliteral}{"If True, use the ALE algorithm (regridding/remapping). "}//\&}
\DoxyCodeLine{1818                  \textcolor{stringliteral}{"If False, use the layered isopycnal algorithm."}, default=.false. )}
\DoxyCodeLine{1819   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BULKMIXEDLAYER"}, bulkmixedlayer, \&}
\DoxyCodeLine{1820                  \textcolor{stringliteral}{"If true, use a Kraus-\/Turner-\/like bulk mixed layer "}//\&}
\DoxyCodeLine{1821                  \textcolor{stringliteral}{"with transitional buffer layers.  Layers 1 through "}//\&}
\DoxyCodeLine{1822                  \textcolor{stringliteral}{"NKML+NKBL have variable densities. There must be at "}//\&}
\DoxyCodeLine{1823                  \textcolor{stringliteral}{"least NKML+NKBL+1 layers if BULKMIXEDLAYER is true. "}//\&}
\DoxyCodeLine{1824                  \textcolor{stringliteral}{"BULKMIXEDLAYER can not be used with USE\_REGRIDDING. "}//\&}
\DoxyCodeLine{1825                  \textcolor{stringliteral}{"The default is influenced by ENABLE\_THERMODYNAMICS."}, \&}
\DoxyCodeLine{1826                  default=use\_temperature .and. .not.cs\%use\_ALE\_algorithm)}
\DoxyCodeLine{1827   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"THICKNESSDIFFUSE"}, cs\%thickness\_diffuse, \&}
\DoxyCodeLine{1828                  \textcolor{stringliteral}{"If true, interface heights are diffused with a "}//\&}
\DoxyCodeLine{1829                  \textcolor{stringliteral}{"coefficient of KHTH."}, default=.false.)}
\DoxyCodeLine{1830   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"},  \textcolor{stringliteral}{"THICKNESSDIFFUSE\_FIRST"}, \&}
\DoxyCodeLine{1831                                       cs\%thickness\_diffuse\_first, \&}
\DoxyCodeLine{1832                  \textcolor{stringliteral}{"If true, do thickness diffusion before dynamics. "}//\&}
\DoxyCodeLine{1833                  \textcolor{stringliteral}{"This is only used if THICKNESSDIFFUSE is true."}, \&}
\DoxyCodeLine{1834                  default=.false.)}
\DoxyCodeLine{1835   \textcolor{keywordflow}{if} (.not.cs\%thickness\_diffuse) cs\%thickness\_diffuse\_first = .false.}
\DoxyCodeLine{1836   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BATHYMETRY\_AT\_VEL"}, bathy\_at\_vel, \&}
\DoxyCodeLine{1837                  \textcolor{stringliteral}{"If true, there are separate values for the basin depths "}//\&}
\DoxyCodeLine{1838                  \textcolor{stringliteral}{"at velocity points.  Otherwise the effects of topography "}//\&}
\DoxyCodeLine{1839                  \textcolor{stringliteral}{"are entirely determined from thickness points."}, \&}
\DoxyCodeLine{1840                  default=.false.)}
\DoxyCodeLine{1841   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_WAVES"}, cs\%UseWaves, default=.false., \&}
\DoxyCodeLine{1842                  do\_not\_log=.true.)}
\DoxyCodeLine{1843 }
\DoxyCodeLine{1844   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DEBUG"}, cs\%debug, \&}
\DoxyCodeLine{1845                  \textcolor{stringliteral}{"If true, write out verbose debugging data."}, \&}
\DoxyCodeLine{1846                  default=.false., debuggingparam=.true.)}
\DoxyCodeLine{1847   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DEBUG\_TRUNCATIONS"}, debug\_truncations, \&}
\DoxyCodeLine{1848                  \textcolor{stringliteral}{"If true, calculate all diagnostics that are useful for "}//\&}
\DoxyCodeLine{1849                  \textcolor{stringliteral}{"debugging truncations."}, default=.false., debuggingparam=.true.)}
\DoxyCodeLine{1850 }
\DoxyCodeLine{1851   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DT"}, cs\%dt, \&}
\DoxyCodeLine{1852                  \textcolor{stringliteral}{"The (baroclinic) dynamics time step.  The time-\/step that "}//\&}
\DoxyCodeLine{1853                  \textcolor{stringliteral}{"is actually used will be an integer fraction of the "}//\&}
\DoxyCodeLine{1854                  \textcolor{stringliteral}{"forcing time-\/step (DT\_FORCING in ocean-\/only mode or the "}//\&}
\DoxyCodeLine{1855                  \textcolor{stringliteral}{"coupling timestep in coupled mode.)"}, units=\textcolor{stringliteral}{"s"}, scale=us\%s\_to\_T, \&}
\DoxyCodeLine{1856                  fail\_if\_missing=.true.)}
\DoxyCodeLine{1857   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DT\_THERM"}, cs\%dt\_therm, \&}
\DoxyCodeLine{1858                  \textcolor{stringliteral}{"The thermodynamic and tracer advection time step. "}//\&}
\DoxyCodeLine{1859                  \textcolor{stringliteral}{"Ideally DT\_THERM should be an integer multiple of DT "}//\&}
\DoxyCodeLine{1860                  \textcolor{stringliteral}{"and less than the forcing or coupling time-\/step, unless "}//\&}
\DoxyCodeLine{1861                  \textcolor{stringliteral}{"THERMO\_SPANS\_COUPLING is true, in which case DT\_THERM "}//\&}
\DoxyCodeLine{1862                  \textcolor{stringliteral}{"can be an integer multiple of the coupling timestep.  By "}//\&}
\DoxyCodeLine{1863                  \textcolor{stringliteral}{"default DT\_THERM is set to DT."}, \&}
\DoxyCodeLine{1864                  units=\textcolor{stringliteral}{"s"}, scale=us\%s\_to\_T, default=us\%T\_to\_s*cs\%dt)}
\DoxyCodeLine{1865   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"THERMO\_SPANS\_COUPLING"}, cs\%thermo\_spans\_coupling, \&}
\DoxyCodeLine{1866                  \textcolor{stringliteral}{"If true, the MOM will take thermodynamic and tracer "}//\&}
\DoxyCodeLine{1867                  \textcolor{stringliteral}{"timesteps that can be longer than the coupling timestep. "}//\&}
\DoxyCodeLine{1868                  \textcolor{stringliteral}{"The actual thermodynamic timestep that is used in this "}//\&}
\DoxyCodeLine{1869                  \textcolor{stringliteral}{"case is the largest integer multiple of the coupling "}//\&}
\DoxyCodeLine{1870                  \textcolor{stringliteral}{"timestep that is less than or equal to DT\_THERM."}, default=.false.)}
\DoxyCodeLine{1871 }
\DoxyCodeLine{1872   \textcolor{keywordflow}{if} (bulkmixedlayer) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1873     cs\%Hmix = -\/1.0 ; cs\%Hmix\_UV = -\/1.0}
\DoxyCodeLine{1874   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1875     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"HMIX\_SFC\_PROP"}, cs\%Hmix, \&}
\DoxyCodeLine{1876                  \textcolor{stringliteral}{"If BULKMIXEDLAYER is false, HMIX\_SFC\_PROP is the depth "}//\&}
\DoxyCodeLine{1877                  \textcolor{stringliteral}{"over which to average to find surface properties like "}//\&}
\DoxyCodeLine{1878                  \textcolor{stringliteral}{"SST and SSS or density (but not surface velocities)."}, \&}
\DoxyCodeLine{1879                  units=\textcolor{stringliteral}{"m"}, default=1.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{1880     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"HMIX\_UV\_SFC\_PROP"}, cs\%Hmix\_UV, \&}
\DoxyCodeLine{1881                  \textcolor{stringliteral}{"If BULKMIXEDLAYER is false, HMIX\_UV\_SFC\_PROP is the depth "}//\&}
\DoxyCodeLine{1882                  \textcolor{stringliteral}{"over which to average to find surface flow properties, "}//\&}
\DoxyCodeLine{1883                  \textcolor{stringliteral}{"SSU, SSV. A non-\/positive value indicates no averaging."}, \&}
\DoxyCodeLine{1884                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{1885 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1886   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"HFREEZE"}, cs\%HFrz, \&}
\DoxyCodeLine{1887                  \textcolor{stringliteral}{"If HFREEZE > 0, melt potential will be computed. The actual depth "}//\&}
\DoxyCodeLine{1888                  \textcolor{stringliteral}{"over which melt potential is computed will be min(HFREEZE, OBLD), "}//\&}
\DoxyCodeLine{1889                  \textcolor{stringliteral}{"where OBLD is the boundary layer depth. If HFREEZE <= 0 (default), "}//\&}
\DoxyCodeLine{1890                  \textcolor{stringliteral}{"melt potential will not be computed."}, units=\textcolor{stringliteral}{"m"}, default=-\/1.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{1891   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"INTERPOLATE\_P\_SURF"}, cs\%interp\_p\_surf, \&}
\DoxyCodeLine{1892                  \textcolor{stringliteral}{"If true, linearly interpolate the surface pressure "}//\&}
\DoxyCodeLine{1893                  \textcolor{stringliteral}{"over the coupling time step, using the specified value "}//\&}
\DoxyCodeLine{1894                  \textcolor{stringliteral}{"at the end of the step."}, default=.false.)}
\DoxyCodeLine{1895 }
\DoxyCodeLine{1896   \textcolor{keywordflow}{if} (cs\%split) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1897     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DTBT"}, dtbt, default=-\/0.98)}
\DoxyCodeLine{1898     default\_val = us\%T\_to\_s*cs\%dt\_therm ; \textcolor{keywordflow}{if} (dtbt > 0.0) default\_val = -\/1.0}
\DoxyCodeLine{1899     cs\%dtbt\_reset\_period = -\/1.0}
\DoxyCodeLine{1900     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DTBT\_RESET\_PERIOD"}, cs\%dtbt\_reset\_period, \&}
\DoxyCodeLine{1901                  \textcolor{stringliteral}{"The period between recalculations of DTBT (if DTBT <= 0). "}//\&}
\DoxyCodeLine{1902                  \textcolor{stringliteral}{"If DTBT\_RESET\_PERIOD is negative, DTBT is set based "}//\&}
\DoxyCodeLine{1903                  \textcolor{stringliteral}{"only on information available at initialization.  If 0, "}//\&}
\DoxyCodeLine{1904                  \textcolor{stringliteral}{"DTBT will be set every dynamics time step. The default "}//\&}
\DoxyCodeLine{1905                  \textcolor{stringliteral}{"is set by DT\_THERM.  This is only used if SPLIT is true."}, \&}
\DoxyCodeLine{1906                  units=\textcolor{stringliteral}{"s"}, default=default\_val, do\_not\_read=(dtbt > 0.0))}
\DoxyCodeLine{1907 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1908 }
\DoxyCodeLine{1909   \textcolor{comment}{! This is here in case these values are used inappropriately.}}
\DoxyCodeLine{1910   use\_frazil = .false. ; bound\_salinity = .false.}
\DoxyCodeLine{1911   cs\%tv\%P\_Ref = 2.0e7*us\%kg\_m3\_to\_R*us\%m\_s\_to\_L\_T**2}
\DoxyCodeLine{1912   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1913     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"FRAZIL"}, use\_frazil, \&}
\DoxyCodeLine{1914                  \textcolor{stringliteral}{"If true, water freezes if it gets too cold, and the "}//\&}
\DoxyCodeLine{1915                  \textcolor{stringliteral}{"accumulated heat deficit is returned in the "}//\&}
\DoxyCodeLine{1916                  \textcolor{stringliteral}{"surface state.  FRAZIL is only used if "}//\&}
\DoxyCodeLine{1917                  \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS is true."}, default=.false.)}
\DoxyCodeLine{1918     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DO\_GEOTHERMAL"}, use\_geothermal, \&}
\DoxyCodeLine{1919                  \textcolor{stringliteral}{"If true, apply geothermal heating."}, default=.false.)}
\DoxyCodeLine{1920     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BOUND\_SALINITY"}, bound\_salinity, \&}
\DoxyCodeLine{1921                  \textcolor{stringliteral}{"If true, limit salinity to being positive. (The sea-\/ice "}//\&}
\DoxyCodeLine{1922                  \textcolor{stringliteral}{"model may ask for more salt than is available and "}//\&}
\DoxyCodeLine{1923                  \textcolor{stringliteral}{"drive the salinity negative otherwise.)"}, default=.false.)}
\DoxyCodeLine{1924     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"MIN\_SALINITY"}, cs\%tv\%min\_salinity, \&}
\DoxyCodeLine{1925                  \textcolor{stringliteral}{"The minimum value of salinity when BOUND\_SALINITY=True."}, \&}
\DoxyCodeLine{1926                  units=\textcolor{stringliteral}{"PPT"}, default=0.0, do\_not\_log=.not.bound\_salinity)}
\DoxyCodeLine{1927     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"C\_P"}, cs\%tv\%C\_p, \&}
\DoxyCodeLine{1928                  \textcolor{stringliteral}{"The heat capacity of sea water, approximated as a "}//\&}
\DoxyCodeLine{1929                  \textcolor{stringliteral}{"constant. This is only used if ENABLE\_THERMODYNAMICS is "}//\&}
\DoxyCodeLine{1930                  \textcolor{stringliteral}{"true. The default value is from the TEOS-\/10 definition "}//\&}
\DoxyCodeLine{1931                  \textcolor{stringliteral}{"of conservative temperature."}, units=\textcolor{stringliteral}{"J kg-\/1 K-\/1"}, \&}
\DoxyCodeLine{1932                  default=3991.86795711963, scale=us\%J\_kg\_to\_Q)}
\DoxyCodeLine{1933     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_PSURF\_IN\_EOS"}, cs\%use\_p\_surf\_in\_EOS, \&}
\DoxyCodeLine{1934                  \textcolor{stringliteral}{"If true, always include the surface pressure contributions "}//\&}
\DoxyCodeLine{1935                  \textcolor{stringliteral}{"in equation of state calculations."}, default=.true.)}
\DoxyCodeLine{1936 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1937   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"P\_REF"}, cs\%tv\%P\_Ref, \&}
\DoxyCodeLine{1938                  \textcolor{stringliteral}{"The pressure that is used for calculating the coordinate "}//\&}
\DoxyCodeLine{1939                  \textcolor{stringliteral}{"density.  (1 Pa = 1e4 dbar, so 2e7 is commonly used.) "}//\&}
\DoxyCodeLine{1940                  \textcolor{stringliteral}{"This is only used if USE\_EOS and ENABLE\_THERMODYNAMICS are true."}, \&}
\DoxyCodeLine{1941                  units=\textcolor{stringliteral}{"Pa"}, default=2.0e7, scale=us\%kg\_m3\_to\_R*us\%m\_s\_to\_L\_T**2)}
\DoxyCodeLine{1942 }
\DoxyCodeLine{1943   \textcolor{keywordflow}{if} (bulkmixedlayer) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1944     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"NKML"}, nkml, \&}
\DoxyCodeLine{1945                  \textcolor{stringliteral}{"The number of sublayers within the mixed layer if "}//\&}
\DoxyCodeLine{1946                  \textcolor{stringliteral}{"BULKMIXEDLAYER is true."}, units=\textcolor{stringliteral}{"nondim"}, default=2)}
\DoxyCodeLine{1947     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"NKBL"}, nkbl, \&}
\DoxyCodeLine{1948                  \textcolor{stringliteral}{"The number of layers that are used as variable density "}//\&}
\DoxyCodeLine{1949                  \textcolor{stringliteral}{"buffer layers if BULKMIXEDLAYER is true."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{1950                  default=2)}
\DoxyCodeLine{1951 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1952 }
\DoxyCodeLine{1953   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"GLOBAL\_INDEXING"}, global\_indexing, \&}
\DoxyCodeLine{1954                  \textcolor{stringliteral}{"If true, use a global lateral indexing convention, so "}//\&}
\DoxyCodeLine{1955                  \textcolor{stringliteral}{"that corresponding points on different processors have "}//\&}
\DoxyCodeLine{1956                  \textcolor{stringliteral}{"the same index. This does not work with static memory."}, \&}
\DoxyCodeLine{1957                  default=.false., layoutparam=.true.)}
\DoxyCodeLine{1958 \textcolor{preprocessor}{\#ifdef STATIC\_MEMORY\_}}
\DoxyCodeLine{1959 \textcolor{preprocessor}{}  \textcolor{keywordflow}{if} (global\_indexing) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"initialize\_MOM: "}//\&}
\DoxyCodeLine{1960        \textcolor{stringliteral}{"GLOBAL\_INDEXING can not be true with STATIC\_MEMORY."})}
\DoxyCodeLine{1961 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1962 \textcolor{preprocessor}{}  \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"FIRST\_DIRECTION"}, first\_direction, \&}
\DoxyCodeLine{1963                  \textcolor{stringliteral}{"An integer that indicates which direction goes first "}//\&}
\DoxyCodeLine{1964                  \textcolor{stringliteral}{"in parts of the code that use directionally split "}//\&}
\DoxyCodeLine{1965                  \textcolor{stringliteral}{"updates, with even numbers (or 0) used for x-\/ first "}//\&}
\DoxyCodeLine{1966                  \textcolor{stringliteral}{"and odd numbers used for y-\/first."}, default=0)}
\DoxyCodeLine{1967 }
\DoxyCodeLine{1968   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"CHECK\_BAD\_SURFACE\_VALS"}, cs\%check\_bad\_sfc\_vals, \&}
\DoxyCodeLine{1969                  \textcolor{stringliteral}{"If true, check the surface state for ridiculous values."}, \&}
\DoxyCodeLine{1970                  default=.false.)}
\DoxyCodeLine{1971   \textcolor{keywordflow}{if} (cs\%check\_bad\_sfc\_vals) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1972     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SSH\_MAX"}, cs\%bad\_val\_ssh\_max, \&}
\DoxyCodeLine{1973                  \textcolor{stringliteral}{"The value of SSH above which a bad value message is "}//\&}
\DoxyCodeLine{1974                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, \&}
\DoxyCodeLine{1975                  units=\textcolor{stringliteral}{"m"}, default=20.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{1976     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SSS\_MAX"}, cs\%bad\_val\_sss\_max, \&}
\DoxyCodeLine{1977                  \textcolor{stringliteral}{"The value of SSS above which a bad value message is "}//\&}
\DoxyCodeLine{1978                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, units=\textcolor{stringliteral}{"PPT"}, \&}
\DoxyCodeLine{1979                  default=45.0)}
\DoxyCodeLine{1980     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SST\_MAX"}, cs\%bad\_val\_sst\_max, \&}
\DoxyCodeLine{1981                  \textcolor{stringliteral}{"The value of SST above which a bad value message is "}//\&}
\DoxyCodeLine{1982                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, \&}
\DoxyCodeLine{1983                  units=\textcolor{stringliteral}{"deg C"}, default=45.0)}
\DoxyCodeLine{1984     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SST\_MIN"}, cs\%bad\_val\_sst\_min, \&}
\DoxyCodeLine{1985                  \textcolor{stringliteral}{"The value of SST below which a bad value message is "}//\&}
\DoxyCodeLine{1986                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, \&}
\DoxyCodeLine{1987                  units=\textcolor{stringliteral}{"deg C"}, default=-\/2.1)}
\DoxyCodeLine{1988     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_COLUMN\_THICKNESS"}, cs\%bad\_val\_col\_thick, \&}
\DoxyCodeLine{1989                  \textcolor{stringliteral}{"The value of column thickness below which a bad value message is "}//\&}
\DoxyCodeLine{1990                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, \&}
\DoxyCodeLine{1991                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{1992 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1993   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, \&}
\DoxyCodeLine{1994                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, \&}
\DoxyCodeLine{1995                  default=.false.)}
\DoxyCodeLine{1996   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"SURFACE\_2018\_ANSWERS"}, cs\%answers\_2018, \&}
\DoxyCodeLine{1997                  \textcolor{stringliteral}{"If true, use expressions for the surface properties that recover the answers "}//\&}
\DoxyCodeLine{1998                  \textcolor{stringliteral}{"from the end of 2018. Otherwise, use more appropriate expressions that differ "}//\&}
\DoxyCodeLine{1999                  \textcolor{stringliteral}{"at roundoff for non-\/Boussinesq cases."}, default=default\_2018\_answers)}
\DoxyCodeLine{2000 }
\DoxyCodeLine{2001   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"SAVE\_INITIAL\_CONDS"}, save\_ic, \&}
\DoxyCodeLine{2002                  \textcolor{stringliteral}{"If true, write the initial conditions to a file given "}//\&}
\DoxyCodeLine{2003                  \textcolor{stringliteral}{"by IC\_OUTPUT\_FILE."}, default=.false.)}
\DoxyCodeLine{2004   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"IC\_OUTPUT\_FILE"}, cs\%IC\_file, \&}
\DoxyCodeLine{2005                  \textcolor{stringliteral}{"The file into which to write the initial conditions."}, \&}
\DoxyCodeLine{2006                  default=\textcolor{stringliteral}{"MOM\_IC"})}
\DoxyCodeLine{2007   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"WRITE\_GEOM"}, write\_geom, \&}
\DoxyCodeLine{2008                  \textcolor{stringliteral}{"If =0, never write the geometry and vertical grid files. "}//\&}
\DoxyCodeLine{2009                  \textcolor{stringliteral}{"If =1, write the geometry and vertical grid files only for "}//\&}
\DoxyCodeLine{2010                  \textcolor{stringliteral}{"a new simulation. If =2, always write the geometry and "}//\&}
\DoxyCodeLine{2011                  \textcolor{stringliteral}{"vertical grid files. Other values are invalid."}, default=1)}
\DoxyCodeLine{2012   \textcolor{keywordflow}{if} (write\_geom<0 .or. write\_geom>2) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM: "}//\&}
\DoxyCodeLine{2013          \textcolor{stringliteral}{"WRITE\_GEOM must be equal to 0, 1 or 2."})}
\DoxyCodeLine{2014   write\_geom\_files = ((write\_geom==2) .or. ((write\_geom==1) .and. \&}
\DoxyCodeLine{2015      ((dirs\%input\_filename(1:1)==\textcolor{stringliteral}{'n'}) .and. (len\_trim(dirs\%input\_filename)==1))))}
\DoxyCodeLine{2016 \textcolor{comment}{! If the restart file type had been initialized, this could become:}}
\DoxyCodeLine{2017 \textcolor{comment}{!  write\_geom\_files = ((write\_geom==2) .or. \&}}
\DoxyCodeLine{2018 \textcolor{comment}{!                      ((write\_geom==1) .and. is\_new\_run(restart\_CSp)))}}
\DoxyCodeLine{2019 }
\DoxyCodeLine{2020   \textcolor{comment}{! Check for inconsistent parameter settings.}}
\DoxyCodeLine{2021   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm .and. bulkmixedlayer) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2022     \textcolor{stringliteral}{"MOM: BULKMIXEDLAYER can not currently be used with the ALE algorithm."})}
\DoxyCodeLine{2023   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm .and. .not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2024      \textcolor{stringliteral}{"MOM: At this time, USE\_EOS should be True when using the ALE algorithm."})}
\DoxyCodeLine{2025   \textcolor{keywordflow}{if} (cs\%adiabatic .and. use\_temperature) \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{2026     \textcolor{stringliteral}{"MOM: ADIABATIC and ENABLE\_THERMODYNAMICS both defined is usually unwise."})}
\DoxyCodeLine{2027   \textcolor{keywordflow}{if} (use\_eos .and. .not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2028     \textcolor{stringliteral}{"MOM: ENABLE\_THERMODYNAMICS must be defined to use USE\_EOS."})}
\DoxyCodeLine{2029   \textcolor{keywordflow}{if} (cs\%adiabatic .and. bulkmixedlayer) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2030     \textcolor{stringliteral}{"MOM: ADIABATIC and BULKMIXEDLAYER can not both be defined."})}
\DoxyCodeLine{2031   \textcolor{keywordflow}{if} (bulkmixedlayer .and. .not.use\_eos) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2032       \textcolor{stringliteral}{"initialize\_MOM: A bulk mixed layer can only be used with T \& S as "}//\&}
\DoxyCodeLine{2033       \textcolor{stringliteral}{"state variables. Add USE\_EOS = True to MOM\_input."})}
\DoxyCodeLine{2034 }
\DoxyCodeLine{2035   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"ICE\_SHELF"}, use\_ice\_shelf, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{2036   \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2037      inputdir = \textcolor{stringliteral}{"."} ;  \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"INPUTDIR"}, inputdir)}
\DoxyCodeLine{2038      inputdir = slasher(inputdir)}
\DoxyCodeLine{2039      \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"ICE\_THICKNESS\_FILE"}, ice\_shelf\_file, \&}
\DoxyCodeLine{2040                     \textcolor{stringliteral}{"The file from which the ice bathymetry and area are read."}, \&}
\DoxyCodeLine{2041                     fail\_if\_missing=.true.)}
\DoxyCodeLine{2042      \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"ICE\_AREA\_VARNAME"}, area\_varname, \&}
\DoxyCodeLine{2043                     \textcolor{stringliteral}{"The name of the area variable in ICE\_THICKNESS\_FILE."}, \&}
\DoxyCodeLine{2044                     fail\_if\_missing=.true.)}
\DoxyCodeLine{2045 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2046 }
\DoxyCodeLine{2047 }
\DoxyCodeLine{2048   cs\%ensemble\_ocean=.false.}
\DoxyCodeLine{2049   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ENSEMBLE\_OCEAN"}, cs\%ensemble\_ocean, \&}
\DoxyCodeLine{2050                  \textcolor{stringliteral}{"If False, The model is being run in serial mode as a single realization. "}//\&}
\DoxyCodeLine{2051                  \textcolor{stringliteral}{"If True, The current model realization is part of a larger ensemble "}//\&}
\DoxyCodeLine{2052                  \textcolor{stringliteral}{"and at the end of step MOM, we will perform a gather of the ensemble "}//\&}
\DoxyCodeLine{2053                  \textcolor{stringliteral}{"members for statistical evaluation and/or data assimilation."}, default=.false.)}
\DoxyCodeLine{2054 }
\DoxyCodeLine{2055   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"MOM parameters read (initialize\_MOM)"})}
\DoxyCodeLine{2056 }
\DoxyCodeLine{2057   \textcolor{comment}{! Grid rotation test}}
\DoxyCodeLine{2058   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ROTATE\_INDEX"}, cs\%rotate\_index, \&}
\DoxyCodeLine{2059       \textcolor{stringliteral}{"Enable rotation of the horizontal indices."}, default=.false., \&}
\DoxyCodeLine{2060       debuggingparam=.true.)}
\DoxyCodeLine{2061   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2062     \textcolor{comment}{! TODO: Index rotation currently only works when index rotation does not}}
\DoxyCodeLine{2063     \textcolor{comment}{!   change the MPI rank of each domain.  Resolving this will require a}}
\DoxyCodeLine{2064     \textcolor{comment}{!   modification to FMS PE assignment.}}
\DoxyCodeLine{2065     \textcolor{comment}{!   For now, we only permit single-\/core runs.}}
\DoxyCodeLine{2066 }
\DoxyCodeLine{2067     \textcolor{keywordflow}{if} (num\_pes() /= 1) \&}
\DoxyCodeLine{2068       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Index rotation is only supported on one PE."})}
\DoxyCodeLine{2069 }
\DoxyCodeLine{2070     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"INDEX\_TURNS"}, turns, \&}
\DoxyCodeLine{2071         \textcolor{stringliteral}{"Number of counterclockwise quarter-\/turn index rotations."}, \&}
\DoxyCodeLine{2072         default=1, debuggingparam=.true.)}
\DoxyCodeLine{2073 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2074 }
\DoxyCodeLine{2075   \textcolor{comment}{! Set up the model domain and grids.}}
\DoxyCodeLine{2076 \textcolor{preprocessor}{\#ifdef SYMMETRIC\_MEMORY\_}}
\DoxyCodeLine{2077 \textcolor{preprocessor}{}  symmetric = .true.}
\DoxyCodeLine{2078 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{2079 \textcolor{preprocessor}{}  symmetric = .false.}
\DoxyCodeLine{2080 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{2081 \textcolor{preprocessor}{}  g\_in => cs\%G\_in}
\DoxyCodeLine{2082 \textcolor{preprocessor}{\#ifdef STATIC\_MEMORY\_}}
\DoxyCodeLine{2083 \textcolor{preprocessor}{}  \textcolor{keyword}{call }mom\_domains\_init(g\_in\%domain, param\_file, symmetric=symmetric, \&}
\DoxyCodeLine{2084             static\_memory=.true., nihalo=nihalo\_, njhalo=njhalo\_, \&}
\DoxyCodeLine{2085             niglobal=niglobal\_, njglobal=njglobal\_, niproc=niproc\_, \&}
\DoxyCodeLine{2086             njproc=njproc\_)}
\DoxyCodeLine{2087 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{2088 \textcolor{preprocessor}{}  \textcolor{keyword}{call }mom\_domains\_init(g\_in\%domain, param\_file, symmetric=symmetric, \&}
\DoxyCodeLine{2089                         domain\_name=\textcolor{stringliteral}{"MOM\_in"})}
\DoxyCodeLine{2090 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{2091 \textcolor{preprocessor}{}}
\DoxyCodeLine{2092   \textcolor{comment}{! Copy input grid (G\_in) domain to active grid G}}
\DoxyCodeLine{2093   \textcolor{comment}{! Swap axes for quarter and 3-\/quarter turns}}
\DoxyCodeLine{2094   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2095     \textcolor{keyword}{allocate}(cs\%G)}
\DoxyCodeLine{2096     \textcolor{keyword}{call }clone\_mom\_domain(g\_in\%Domain, cs\%G\%Domain, turns=turns)}
\DoxyCodeLine{2097     first\_direction = modulo(first\_direction + turns, 2)}
\DoxyCodeLine{2098   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2099     cs\%G => g\_in}
\DoxyCodeLine{2100 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2101 }
\DoxyCodeLine{2102   \textcolor{comment}{! TODO: It is unlikey that test\_grid\_copy and rotate\_index would work at the}}
\DoxyCodeLine{2103   \textcolor{comment}{!   same time.  It may be possible to enable both but for now we prevent it.}}
\DoxyCodeLine{2104   \textcolor{keywordflow}{if} (test\_grid\_copy .and. cs\%rotate\_index) \&}
\DoxyCodeLine{2105     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Grid cannot be copied during index rotation."})}
\DoxyCodeLine{2106 }
\DoxyCodeLine{2107   \textcolor{keywordflow}{if} (test\_grid\_copy) \textcolor{keywordflow}{then} ; \textcolor{keyword}{allocate}(g)}
\DoxyCodeLine{2108   \textcolor{keywordflow}{else} ; g => cs\%G ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2109 }
\DoxyCodeLine{2110   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"domains initialized (initialize\_MOM)"})}
\DoxyCodeLine{2111 }
\DoxyCodeLine{2112   \textcolor{keyword}{call }mom\_debugging\_init(param\_file)}
\DoxyCodeLine{2113   \textcolor{keyword}{call }diag\_mediator\_infrastructure\_init()}
\DoxyCodeLine{2114   \textcolor{keyword}{call }mom\_io\_init(param\_file)}
\DoxyCodeLine{2115 }
\DoxyCodeLine{2116   \textcolor{comment}{! Create HI and dG on the input index map.}}
\DoxyCodeLine{2117   \textcolor{keyword}{call }hor\_index\_init(g\_in\%Domain, hi\_in, param\_file, \&}
\DoxyCodeLine{2118                       local\_indexing=.not.global\_indexing)}
\DoxyCodeLine{2119   \textcolor{keyword}{call }create\_dyn\_horgrid(dg\_in, hi\_in, bathymetry\_at\_vel=bathy\_at\_vel)}
\DoxyCodeLine{2120   \textcolor{keyword}{call }clone\_mom\_domain(g\_in\%Domain, dg\_in\%Domain)}
\DoxyCodeLine{2121 }
\DoxyCodeLine{2122   \textcolor{comment}{! Allocate initialize time-\/invariant MOM variables.}}
\DoxyCodeLine{2123   \textcolor{keyword}{call }mom\_initialize\_fixed(dg\_in, us, obc\_in, param\_file, write\_geom\_files, \&}
\DoxyCodeLine{2124                             dirs\%output\_directory)}
\DoxyCodeLine{2125 }
\DoxyCodeLine{2126   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from MOM\_initialize\_fixed() (initialize\_MOM)"})}
\DoxyCodeLine{2127 }
\DoxyCodeLine{2128   \textcolor{comment}{! Determine HI and dG for the model index map.}}
\DoxyCodeLine{2129   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2130     \textcolor{keyword}{allocate}(hi)}
\DoxyCodeLine{2131     \textcolor{keyword}{call }rotate\_hor\_index(hi\_in, turns, hi)}
\DoxyCodeLine{2132     \textcolor{keyword}{call }create\_dyn\_horgrid(dg, hi, bathymetry\_at\_vel=bathy\_at\_vel)}
\DoxyCodeLine{2133     \textcolor{keyword}{call }clone\_mom\_domain(g\%Domain, dg\%Domain)}
\DoxyCodeLine{2134     \textcolor{keyword}{call }rotate\_dyngrid(dg\_in, dg, us, turns)}
\DoxyCodeLine{2135     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc\_in)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2136       \textcolor{comment}{! TODO: General OBC index rotations is not yet supported.}}
\DoxyCodeLine{2137       \textcolor{keywordflow}{if} (modulo(turns, 4) /= 1) \&}
\DoxyCodeLine{2138         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"OBC index rotation of 180 and 270 degrees is "} \&}
\DoxyCodeLine{2139           // \textcolor{stringliteral}{"not yet unsupported."})}
\DoxyCodeLine{2140       \textcolor{keyword}{allocate}(cs\%OBC)}
\DoxyCodeLine{2141       \textcolor{keyword}{call }rotate\_obc\_config(obc\_in, dg\_in, cs\%OBC, dg, turns)}
\DoxyCodeLine{2142 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2143   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2144     hi => hi\_in}
\DoxyCodeLine{2145     dg => dg\_in}
\DoxyCodeLine{2146     cs\%OBC => obc\_in}
\DoxyCodeLine{2147 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2148 }
\DoxyCodeLine{2149   \textcolor{keyword}{call }verticalgridinit( param\_file, cs\%GV, us )}
\DoxyCodeLine{2150   gv => cs\%GV}
\DoxyCodeLine{2151 }
\DoxyCodeLine{2152   \textcolor{comment}{! Allocate the auxiliary non-\/symmetric domain for debugging or I/O purposes.}}
\DoxyCodeLine{2153   \textcolor{keywordflow}{if} (cs\%debug .or. dg\%symmetric) \&}
\DoxyCodeLine{2154     \textcolor{keyword}{call }clone\_mom\_domain(dg\%Domain, dg\%Domain\_aux, symmetric=.false.)}
\DoxyCodeLine{2155 }
\DoxyCodeLine{2156   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"grids initialized (initialize\_MOM)"})}
\DoxyCodeLine{2157 }
\DoxyCodeLine{2158   \textcolor{keyword}{call }mom\_timing\_init(cs)}
\DoxyCodeLine{2159 }
\DoxyCodeLine{2160   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%OBC)) \textcolor{keyword}{call }call\_obc\_register(param\_file, cs\%update\_OBC\_CSp, cs\%OBC)}
\DoxyCodeLine{2161 }
\DoxyCodeLine{2162   \textcolor{keyword}{call }tracer\_registry\_init(param\_file, cs\%tracer\_Reg)}
\DoxyCodeLine{2163 }
\DoxyCodeLine{2164   \textcolor{comment}{! Allocate and initialize space for the primary time-\/varying MOM variables.}}
\DoxyCodeLine{2165   is   = dg\%isc   ; ie   = dg\%iec  ; js   = dg\%jsc  ; je   = dg\%jec ; nz = gv\%ke}
\DoxyCodeLine{2166   isd  = dg\%isd   ; ied  = dg\%ied  ; jsd  = dg\%jsd  ; jed  = dg\%jed}
\DoxyCodeLine{2167   isdb = dg\%IsdB  ; iedb = dg\%IedB ; jsdb = dg\%JsdB ; jedb = dg\%JedB}
\DoxyCodeLine{2168   alloc\_(cs\%u(isdb:iedb,jsd:jed,nz))   ; cs\%u(:,:,:) = 0.0}
\DoxyCodeLine{2169   alloc\_(cs\%v(isd:ied,jsdb:jedb,nz))   ; cs\%v(:,:,:) = 0.0}
\DoxyCodeLine{2170   alloc\_(cs\%h(isd:ied,jsd:jed,nz))     ; cs\%h(:,:,:) = gv\%Angstrom\_H}
\DoxyCodeLine{2171   alloc\_(cs\%uh(isdb:iedb,jsd:jed,nz))  ; cs\%uh(:,:,:) = 0.0}
\DoxyCodeLine{2172   alloc\_(cs\%vh(isd:ied,jsdb:jedb,nz))  ; cs\%vh(:,:,:) = 0.0}
\DoxyCodeLine{2173   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2174     alloc\_(cs\%T(isd:ied,jsd:jed,nz))   ; cs\%T(:,:,:) = 0.0}
\DoxyCodeLine{2175     alloc\_(cs\%S(isd:ied,jsd:jed,nz))   ; cs\%S(:,:,:) = 0.0}
\DoxyCodeLine{2176     cs\%tv\%T => cs\%T ; cs\%tv\%S => cs\%S}
\DoxyCodeLine{2177     \textcolor{keywordflow}{if} (cs\%tv\%T\_is\_conT) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2178       vd\_t = var\_desc(name=\textcolor{stringliteral}{"contemp"}, units=\textcolor{stringliteral}{"Celsius"}, longname=\textcolor{stringliteral}{"Conservative Temperature"}, \&}
\DoxyCodeLine{2179                       cmor\_field\_name=\textcolor{stringliteral}{"thetao"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Potential Temperature"}, \&}
\DoxyCodeLine{2180                       conversion=us\%Q\_to\_J\_kg*cs\%tv\%C\_p)}
\DoxyCodeLine{2181     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2182       vd\_t = var\_desc(name=\textcolor{stringliteral}{"temp"}, units=\textcolor{stringliteral}{"degC"}, longname=\textcolor{stringliteral}{"Potential Temperature"}, \&}
\DoxyCodeLine{2183                       cmor\_field\_name=\textcolor{stringliteral}{"thetao"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Potential Temperature"}, \&}
\DoxyCodeLine{2184                       conversion=us\%Q\_to\_J\_kg*cs\%tv\%C\_p)}
\DoxyCodeLine{2185 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2186     \textcolor{keywordflow}{if} (cs\%tv\%S\_is\_absS) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2187       vd\_s = var\_desc(name=\textcolor{stringliteral}{"abssalt"},units=\textcolor{stringliteral}{"g kg-\/1"},longname=\textcolor{stringliteral}{"Absolute Salinity"}, \&}
\DoxyCodeLine{2188                       cmor\_field\_name=\textcolor{stringliteral}{"so"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Salinity"}, \&}
\DoxyCodeLine{2189                       conversion=0.001)}
\DoxyCodeLine{2190     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2191       vd\_s = var\_desc(name=\textcolor{stringliteral}{"salt"},units=\textcolor{stringliteral}{"psu"},longname=\textcolor{stringliteral}{"Salinity"}, \&}
\DoxyCodeLine{2192                       cmor\_field\_name=\textcolor{stringliteral}{"so"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Salinity"}, \&}
\DoxyCodeLine{2193                       conversion=0.001)}
\DoxyCodeLine{2194 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2195 }
\DoxyCodeLine{2196     \textcolor{keywordflow}{if} (advect\_ts) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2197       s\_flux\_units = get\_tr\_flux\_units(gv, \textcolor{stringliteral}{"psu"}) \textcolor{comment}{! Could change to "kg m-\/2 s-\/1"?}}
\DoxyCodeLine{2198       conv2watt    = gv\%H\_to\_kg\_m2 * us\%Q\_to\_J\_kg*cs\%tv\%C\_p}
\DoxyCodeLine{2199       \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2200         conv2salt = gv\%H\_to\_m \textcolor{comment}{! Could change to GV\%H\_to\_kg\_m2 * 0.001?}}
\DoxyCodeLine{2201       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2202         conv2salt = gv\%H\_to\_kg\_m2}
\DoxyCodeLine{2203 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2204       \textcolor{keyword}{call }register\_tracer(cs\%tv\%T, cs\%tracer\_Reg, param\_file, dg\%HI, gv, \&}
\DoxyCodeLine{2205                            tr\_desc=vd\_t, registry\_diags=.true., flux\_nameroot=\textcolor{stringliteral}{'T'}, \&}
\DoxyCodeLine{2206                            flux\_units=\textcolor{stringliteral}{'W'}, flux\_longname=\textcolor{stringliteral}{'Heat'}, \&}
\DoxyCodeLine{2207                            flux\_scale=conv2watt, convergence\_units=\textcolor{stringliteral}{'W m-\/2'}, \&}
\DoxyCodeLine{2208                            convergence\_scale=conv2watt, cmor\_tendprefix=\textcolor{stringliteral}{"opottemp"}, diag\_form=2)}
\DoxyCodeLine{2209       \textcolor{keyword}{call }register\_tracer(cs\%tv\%S, cs\%tracer\_Reg, param\_file, dg\%HI, gv, \&}
\DoxyCodeLine{2210                            tr\_desc=vd\_s, registry\_diags=.true., flux\_nameroot=\textcolor{stringliteral}{'S'}, \&}
\DoxyCodeLine{2211                            flux\_units=s\_flux\_units, flux\_longname=\textcolor{stringliteral}{'Salt'}, \&}
\DoxyCodeLine{2212                            flux\_scale=conv2salt, convergence\_units=\textcolor{stringliteral}{'kg m-\/2 s-\/1'}, \&}
\DoxyCodeLine{2213                            convergence\_scale=0.001*gv\%H\_to\_kg\_m2, cmor\_tendprefix=\textcolor{stringliteral}{"osalt"}, diag\_form=2)}
\DoxyCodeLine{2214 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2215     \textcolor{comment}{! NOTE: register\_temp\_salt\_segments includes allocation of tracer fields}}
\DoxyCodeLine{2216     \textcolor{comment}{!   along segments.  Bit reproducibility requires that MOM\_initialize\_state}}
\DoxyCodeLine{2217     \textcolor{comment}{!   be called on the input index map, so we must setup both OBC and OBC\_in.}}
\DoxyCodeLine{2218     \textcolor{comment}{!}}
\DoxyCodeLine{2219     \textcolor{comment}{! XXX: This call on OBC\_in allocates the tracer fields on the unrotated}}
\DoxyCodeLine{2220     \textcolor{comment}{!   grid, but also incorrectly stores a pointer to a tracer\_type for the}}
\DoxyCodeLine{2221     \textcolor{comment}{!   rotated registry (e.g. segment\%tr\_reg\%Tr(n)\%Tr) from CS\%tracer\_reg.}}
\DoxyCodeLine{2222     \textcolor{comment}{!}}
\DoxyCodeLine{2223     \textcolor{comment}{!   While incorrect and potentially dangerous, it does not seem that this}}
\DoxyCodeLine{2224     \textcolor{comment}{!   pointer is used during initialization, so we leave it for now.}}
\DoxyCodeLine{2225     \textcolor{keywordflow}{if} (cs\%rotate\_index .and. \textcolor{keyword}{associated}(obc\_in)) \&}
\DoxyCodeLine{2226       \textcolor{keyword}{call }register\_temp\_salt\_segments(gv, obc\_in, cs\%tracer\_Reg, param\_file)}
\DoxyCodeLine{2227     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%OBC)) \&}
\DoxyCodeLine{2228       \textcolor{keyword}{call }register\_temp\_salt\_segments(gv, cs\%OBC, cs\%tracer\_Reg, param\_file)}
\DoxyCodeLine{2229 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2230   \textcolor{keywordflow}{if} (use\_frazil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2231     \textcolor{keyword}{allocate}(cs\%tv\%frazil(isd:ied,jsd:jed)) ; cs\%tv\%frazil(:,:) = 0.0}
\DoxyCodeLine{2232 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2233   \textcolor{keywordflow}{if} (bound\_salinity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2234     \textcolor{keyword}{allocate}(cs\%tv\%salt\_deficit(isd:ied,jsd:jed)) ; cs\%tv\%salt\_deficit(:,:) = 0.0}
\DoxyCodeLine{2235 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2236 }
\DoxyCodeLine{2237   \textcolor{keywordflow}{if} (bulkmixedlayer .or. use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2238     \textcolor{keyword}{allocate}(cs\%Hml(isd:ied,jsd:jed)) ; cs\%Hml(:,:) = 0.0}
\DoxyCodeLine{2239 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2240 }
\DoxyCodeLine{2241   \textcolor{keywordflow}{if} (bulkmixedlayer) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2242     gv\%nkml = nkml ; gv\%nk\_rho\_varies = nkml + nkbl}
\DoxyCodeLine{2243   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2244     gv\%nkml = 0 ; gv\%nk\_rho\_varies = 0}
\DoxyCodeLine{2245 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2246   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2247     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"NK\_RHO\_VARIES"}, gv\%nk\_rho\_varies, default=0) \textcolor{comment}{! Will default to nz later... -\/AJA}}
\DoxyCodeLine{2248 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2249 }
\DoxyCodeLine{2250   alloc\_(cs\%uhtr(isdb:iedb,jsd:jed,nz)) ; cs\%uhtr(:,:,:) = 0.0}
\DoxyCodeLine{2251   alloc\_(cs\%vhtr(isd:ied,jsdb:jedb,nz)) ; cs\%vhtr(:,:,:) = 0.0}
\DoxyCodeLine{2252   cs\%t\_dyn\_rel\_adv = 0.0 ; cs\%t\_dyn\_rel\_thermo = 0.0 ; cs\%t\_dyn\_rel\_diag = 0.0}
\DoxyCodeLine{2253 }
\DoxyCodeLine{2254   \textcolor{keywordflow}{if} (debug\_truncations) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2255     \textcolor{keyword}{allocate}(cs\%u\_prev(isdb:iedb,jsd:jed,nz)) ; cs\%u\_prev(:,:,:) = 0.0}
\DoxyCodeLine{2256     \textcolor{keyword}{allocate}(cs\%v\_prev(isd:ied,jsdb:jedb,nz)) ; cs\%v\_prev(:,:,:) = 0.0}
\DoxyCodeLine{2257     mom\_internal\_state\%u\_prev => cs\%u\_prev}
\DoxyCodeLine{2258     mom\_internal\_state\%v\_prev => cs\%v\_prev}
\DoxyCodeLine{2259     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%ADp\%du\_dt\_visc,isdb,iedb,jsd,jed,nz)}
\DoxyCodeLine{2260     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%ADp\%dv\_dt\_visc,isd,ied,jsdb,jedb,nz)}
\DoxyCodeLine{2261     \textcolor{keywordflow}{if} (.not.cs\%adiabatic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2262       \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%ADp\%du\_dt\_dia,isdb,iedb,jsd,jed,nz)}
\DoxyCodeLine{2263       \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%ADp\%dv\_dt\_dia,isd,ied,jsdb,jedb,nz)}
\DoxyCodeLine{2264 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2265 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2266 }
\DoxyCodeLine{2267   mom\_internal\_state\%u => cs\%u ; mom\_internal\_state\%v => cs\%v}
\DoxyCodeLine{2268   mom\_internal\_state\%h => cs\%h}
\DoxyCodeLine{2269   mom\_internal\_state\%uh => cs\%uh ; mom\_internal\_state\%vh => cs\%vh}
\DoxyCodeLine{2270   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2271     mom\_internal\_state\%T => cs\%T ; mom\_internal\_state\%S => cs\%S}
\DoxyCodeLine{2272 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2273 }
\DoxyCodeLine{2274   cs\%CDp\%uh => cs\%uh ; cs\%CDp\%vh => cs\%vh}
\DoxyCodeLine{2275 }
\DoxyCodeLine{2276   \textcolor{keywordflow}{if} (cs\%interp\_p\_surf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2277     \textcolor{keyword}{allocate}(cs\%p\_surf\_prev(isd:ied,jsd:jed)) ; cs\%p\_surf\_prev(:,:) = 0.0}
\DoxyCodeLine{2278 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2279 }
\DoxyCodeLine{2280   alloc\_(cs\%ssh\_rint(isd:ied,jsd:jed)) ; cs\%ssh\_rint(:,:) = 0.0}
\DoxyCodeLine{2281   alloc\_(cs\%ave\_ssh\_ibc(isd:ied,jsd:jed)) ; cs\%ave\_ssh\_ibc(:,:) = 0.0}
\DoxyCodeLine{2282   alloc\_(cs\%eta\_av\_bc(isd:ied,jsd:jed)) ; cs\%eta\_av\_bc(:,:) = 0.0}
\DoxyCodeLine{2283   cs\%time\_in\_cycle = 0.0 ; cs\%time\_in\_thermo\_cycle = 0.0}
\DoxyCodeLine{2284 }
\DoxyCodeLine{2285   \textcolor{comment}{! Use the Wright equation of state by default, unless otherwise specified}}
\DoxyCodeLine{2286   \textcolor{comment}{! Note: this line and the following block ought to be in a separate}}
\DoxyCodeLine{2287   \textcolor{comment}{! initialization routine for tv.}}
\DoxyCodeLine{2288   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keyword}{call }eos\_init(param\_file, cs\%tv\%eqn\_of\_state, us)}
\DoxyCodeLine{2289   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2290     \textcolor{keyword}{allocate}(cs\%tv\%TempxPmE(isd:ied,jsd:jed)) ; cs\%tv\%TempxPmE(:,:) = 0.0}
\DoxyCodeLine{2291     \textcolor{keywordflow}{if} (use\_geothermal) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2292       \textcolor{keyword}{allocate}(cs\%tv\%internal\_heat(isd:ied,jsd:jed)) ; cs\%tv\%internal\_heat(:,:) = 0.0}
\DoxyCodeLine{2293 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2294 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2295   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"state variables allocated (initialize\_MOM)"})}
\DoxyCodeLine{2296 }
\DoxyCodeLine{2297   \textcolor{comment}{! Set the fields that are needed for bitwise identical restarting}}
\DoxyCodeLine{2298   \textcolor{comment}{! the time stepping scheme.}}
\DoxyCodeLine{2299   \textcolor{keyword}{call }restart\_init(param\_file, restart\_csp)}
\DoxyCodeLine{2300   \textcolor{keyword}{call }set\_restart\_fields(gv, us, param\_file, cs, restart\_csp)}
\DoxyCodeLine{2301   \textcolor{keywordflow}{if} (cs\%split) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2302     \textcolor{keyword}{call }register\_restarts\_dyn\_split\_rk2(dg\%HI, gv, param\_file, \&}
\DoxyCodeLine{2303              cs\%dyn\_split\_RK2\_CSp, restart\_csp, cs\%uh, cs\%vh)}
\DoxyCodeLine{2304   \textcolor{keywordflow}{elseif} (cs\%use\_RK2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2305     \textcolor{keyword}{call }register\_restarts\_dyn\_unsplit\_rk2(dg\%HI, gv, param\_file, \&}
\DoxyCodeLine{2306            cs\%dyn\_unsplit\_RK2\_CSp, restart\_csp)}
\DoxyCodeLine{2307   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2308     \textcolor{keyword}{call }register\_restarts\_dyn\_unsplit(dg\%HI, gv, param\_file, \&}
\DoxyCodeLine{2309            cs\%dyn\_unsplit\_CSp, restart\_csp)}
\DoxyCodeLine{2310 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2311 }
\DoxyCodeLine{2312   \textcolor{comment}{! This subroutine calls user-\/specified tracer registration routines.}}
\DoxyCodeLine{2313   \textcolor{comment}{! Additional calls can be added to MOM\_tracer\_flow\_control.F90.}}
\DoxyCodeLine{2314   \textcolor{keyword}{call }call\_tracer\_register(dg\%HI, gv, us, param\_file, cs\%tracer\_flow\_CSp, \&}
\DoxyCodeLine{2315                             cs\%tracer\_Reg, restart\_csp)}
\DoxyCodeLine{2316 }
\DoxyCodeLine{2317   \textcolor{keyword}{call }meke\_alloc\_register\_restart(dg\%HI, param\_file, cs\%MEKE, restart\_csp)}
\DoxyCodeLine{2318   \textcolor{keyword}{call }set\_visc\_register\_restarts(dg\%HI, gv, param\_file, cs\%visc, restart\_csp)}
\DoxyCodeLine{2319   \textcolor{keyword}{call }mixedlayer\_restrat\_register\_restarts(dg\%HI, param\_file, \&}
\DoxyCodeLine{2320            cs\%mixedlayer\_restrat\_CSp, restart\_csp)}
\DoxyCodeLine{2321 }
\DoxyCodeLine{2322   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%OBC)) \&}
\DoxyCodeLine{2323     \textcolor{keyword}{call }open\_boundary\_register\_restarts(dg\%HI, gv, cs\%OBC, cs\%tracer\_Reg, \&}
\DoxyCodeLine{2324                           param\_file, restart\_csp, use\_temperature)}
\DoxyCodeLine{2325 }
\DoxyCodeLine{2326   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"restart registration complete (initialize\_MOM)"})}
\DoxyCodeLine{2327 }
\DoxyCodeLine{2328   \textcolor{comment}{! Initialize dynamically evolving fields, perhaps from restart files.}}
\DoxyCodeLine{2329   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_mom\_init)}
\DoxyCodeLine{2330   \textcolor{keyword}{call }mom\_initialize\_coord(gv, us, param\_file, write\_geom\_files, \&}
\DoxyCodeLine{2331                             dirs\%output\_directory, cs\%tv, dg\%max\_depth)}
\DoxyCodeLine{2332   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from MOM\_initialize\_coord() (initialize\_MOM)"})}
\DoxyCodeLine{2333 }
\DoxyCodeLine{2334   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2335     \textcolor{keyword}{call }ale\_init(param\_file, gv, us, dg\%max\_depth, cs\%ALE\_CSp)}
\DoxyCodeLine{2336     \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from ALE\_init() (initialize\_MOM)"})}
\DoxyCodeLine{2337 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2338 }
\DoxyCodeLine{2339   \textcolor{comment}{!   Shift from using the temporary dynamic grid type to using the final}}
\DoxyCodeLine{2340   \textcolor{comment}{! (potentially static) ocean-\/specific grid type.}}
\DoxyCodeLine{2341   \textcolor{comment}{!   The next line would be needed if G\%Domain had not already been init'd above:}}
\DoxyCodeLine{2342   \textcolor{comment}{!     call clone\_MOM\_domain(dG\%Domain, G\%Domain)}}
\DoxyCodeLine{2343 }
\DoxyCodeLine{2344   \textcolor{comment}{! NOTE: If indices are rotated, then G and G\_in must both be initialized.}}
\DoxyCodeLine{2345   \textcolor{comment}{!   If not rotated, then G\_in and G are the same grid.}}
\DoxyCodeLine{2346   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2347     \textcolor{keyword}{call }mom\_grid\_init(g, param\_file, us, hi, bathymetry\_at\_vel=bathy\_at\_vel)}
\DoxyCodeLine{2348     \textcolor{keyword}{call }copy\_dyngrid\_to\_mom\_grid(dg, g, us)}
\DoxyCodeLine{2349     \textcolor{keyword}{call }destroy\_dyn\_horgrid(dg)}
\DoxyCodeLine{2350 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2351   \textcolor{keyword}{call }mom\_grid\_init(g\_in, param\_file, us, hi\_in, bathymetry\_at\_vel=bathy\_at\_vel)}
\DoxyCodeLine{2352   \textcolor{keyword}{call }copy\_dyngrid\_to\_mom\_grid(dg\_in, g\_in, us)}
\DoxyCodeLine{2353   \textcolor{keyword}{call }destroy\_dyn\_horgrid(dg\_in)}
\DoxyCodeLine{2354 }
\DoxyCodeLine{2355   \textcolor{comment}{! Set a few remaining fields that are specific to the ocean grid type.}}
\DoxyCodeLine{2356   \textcolor{keyword}{call }set\_first\_direction(g, first\_direction)}
\DoxyCodeLine{2357   \textcolor{comment}{! Allocate the auxiliary non-\/symmetric domain for debugging or I/O purposes.}}
\DoxyCodeLine{2358   \textcolor{keywordflow}{if} (cs\%debug .or. g\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2359     \textcolor{keyword}{call }clone\_mom\_domain(g\%Domain, g\%Domain\_aux, symmetric=.false.)}
\DoxyCodeLine{2360   \textcolor{keywordflow}{else} ; g\%Domain\_aux => g\%Domain ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2361   \textcolor{comment}{! Copy common variables from the vertical grid to the horizontal grid.}}
\DoxyCodeLine{2362   \textcolor{comment}{! Consider removing this later?}}
\DoxyCodeLine{2363   g\%ke = gv\%ke}
\DoxyCodeLine{2364 }
\DoxyCodeLine{2365   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2366     g\_in\%ke = gv\%ke}
\DoxyCodeLine{2367 }
\DoxyCodeLine{2368     \textcolor{keyword}{allocate}(u\_in(g\_in\%IsdB:g\_in\%IedB, g\_in\%jsd:g\_in\%jed, nz))}
\DoxyCodeLine{2369     \textcolor{keyword}{allocate}(v\_in(g\_in\%isd:g\_in\%ied, g\_in\%JsdB:g\_in\%JedB, nz))}
\DoxyCodeLine{2370     \textcolor{keyword}{allocate}(h\_in(g\_in\%isd:g\_in\%ied, g\_in\%jsd:g\_in\%jed, nz))}
\DoxyCodeLine{2371     u\_in(:,:,:) = 0.0}
\DoxyCodeLine{2372     v\_in(:,:,:) = 0.0}
\DoxyCodeLine{2373     h\_in(:,:,:) = gv\%Angstrom\_H}
\DoxyCodeLine{2374 }
\DoxyCodeLine{2375     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2376       \textcolor{keyword}{allocate}(t\_in(g\_in\%isd:g\_in\%ied, g\_in\%jsd:g\_in\%jed, nz))}
\DoxyCodeLine{2377       \textcolor{keyword}{allocate}(s\_in(g\_in\%isd:g\_in\%ied, g\_in\%jsd:g\_in\%jed, nz))}
\DoxyCodeLine{2378       t\_in(:,:,:) = 0.0}
\DoxyCodeLine{2379       s\_in(:,:,:) = 0.0}
\DoxyCodeLine{2380 }
\DoxyCodeLine{2381       cs\%tv\%T => t\_in}
\DoxyCodeLine{2382       cs\%tv\%S => s\_in}
\DoxyCodeLine{2383 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2384 }
\DoxyCodeLine{2385     \textcolor{keyword}{call }mom\_initialize\_state(u\_in, v\_in, h\_in, cs\%tv, time, g\_in, gv, us, \&}
\DoxyCodeLine{2386         param\_file, dirs, restart\_csp, cs\%ALE\_CSp, cs\%tracer\_Reg, \&}
\DoxyCodeLine{2387         sponge\_in\_csp, ale\_sponge\_in\_csp, obc\_in, time\_in)}
\DoxyCodeLine{2388 }
\DoxyCodeLine{2389     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2390       cs\%tv\%T => cs\%T}
\DoxyCodeLine{2391       cs\%tv\%S => cs\%S}
\DoxyCodeLine{2392 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2393 }
\DoxyCodeLine{2394     \textcolor{keyword}{call }rotate\_initial\_state(u\_in, v\_in, h\_in, t\_in, s\_in, use\_temperature, \&}
\DoxyCodeLine{2395         turns, cs\%u, cs\%v, cs\%h, cs\%T, cs\%S)}
\DoxyCodeLine{2396 }
\DoxyCodeLine{2397     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(sponge\_in\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2398       \textcolor{comment}{! TODO: Implementation and testing of non-\/ALE spong rotation}}
\DoxyCodeLine{2399       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Index rotation of non-\/ALE sponge is not yet implemented."})}
\DoxyCodeLine{2400 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2401 }
\DoxyCodeLine{2402     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(ale\_sponge\_in\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2403       \textcolor{keyword}{call }rotate\_ale\_sponge(ale\_sponge\_in\_csp, g\_in, cs\%ALE\_sponge\_CSp, g, turns, param\_file)}
\DoxyCodeLine{2404       \textcolor{keyword}{call }update\_ale\_sponge\_field(cs\%ALE\_sponge\_CSp, t\_in, g, gv, cs\%T)}
\DoxyCodeLine{2405       \textcolor{keyword}{call }update\_ale\_sponge\_field(cs\%ALE\_sponge\_CSp, s\_in, g, gv, cs\%S)}
\DoxyCodeLine{2406 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2407 }
\DoxyCodeLine{2408     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc\_in)) \&}
\DoxyCodeLine{2409       \textcolor{keyword}{call }rotate\_obc\_init(obc\_in, g, gv, us, param\_file, cs\%tv, restart\_csp, cs\%OBC)}
\DoxyCodeLine{2410 }
\DoxyCodeLine{2411     \textcolor{keyword}{deallocate}(u\_in)}
\DoxyCodeLine{2412     \textcolor{keyword}{deallocate}(v\_in)}
\DoxyCodeLine{2413     \textcolor{keyword}{deallocate}(h\_in)}
\DoxyCodeLine{2414     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2415       \textcolor{keyword}{deallocate}(t\_in)}
\DoxyCodeLine{2416       \textcolor{keyword}{deallocate}(s\_in)}
\DoxyCodeLine{2417 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2418   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2419     \textcolor{keyword}{call }mom\_initialize\_state(cs\%u, cs\%v, cs\%h, cs\%tv, time, g, gv, us, \&}
\DoxyCodeLine{2420         param\_file, dirs, restart\_csp, cs\%ALE\_CSp, cs\%tracer\_Reg, \&}
\DoxyCodeLine{2421         cs\%sponge\_CSp, cs\%ALE\_sponge\_CSp, cs\%OBC, time\_in)}
\DoxyCodeLine{2422 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2423 }
\DoxyCodeLine{2424   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_mom\_init)}
\DoxyCodeLine{2425   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from MOM\_initialize\_state() (initialize\_MOM)"})}
\DoxyCodeLine{2426 }
\DoxyCodeLine{2427 \textcolor{comment}{! ! Need this after MOM\_initialize\_state for DOME OBC stuff.}}
\DoxyCodeLine{2428 \textcolor{comment}{! if (associated(CS\%OBC)) \&}}
\DoxyCodeLine{2429 \textcolor{comment}{!   call open\_boundary\_register\_restarts(G\%HI, GV, CS\%OBC, CS\%tracer\_Reg, \&}}
\DoxyCodeLine{2430 \textcolor{comment}{!                         param\_file, restart\_CSp, use\_temperature)}}
\DoxyCodeLine{2431 }
\DoxyCodeLine{2432 \textcolor{comment}{! call callTree\_waypoint("restart registration complete (initialize\_MOM)")}}
\DoxyCodeLine{2433 }
\DoxyCodeLine{2434   \textcolor{comment}{! From this point, there may be pointers being set, so the final grid type}}
\DoxyCodeLine{2435   \textcolor{comment}{! that will persist throughout the run has to be used.}}
\DoxyCodeLine{2436 }
\DoxyCodeLine{2437   \textcolor{keywordflow}{if} (test\_grid\_copy) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2438     \textcolor{comment}{!  Copy the data from the temporary grid to the dyn\_hor\_grid to CS\%G.}}
\DoxyCodeLine{2439     \textcolor{keyword}{call }create\_dyn\_horgrid(dg, g\%HI)}
\DoxyCodeLine{2440     \textcolor{keyword}{call }clone\_mom\_domain(g\%Domain, dg\%Domain)}
\DoxyCodeLine{2441 }
\DoxyCodeLine{2442     \textcolor{keyword}{call }clone\_mom\_domain(g\%Domain, cs\%G\%Domain)}
\DoxyCodeLine{2443     \textcolor{keyword}{call }mom\_grid\_init(cs\%G, param\_file, us)}
\DoxyCodeLine{2444 }
\DoxyCodeLine{2445     \textcolor{keyword}{call }copy\_mom\_grid\_to\_dyngrid(g, dg, us)}
\DoxyCodeLine{2446     \textcolor{keyword}{call }copy\_dyngrid\_to\_mom\_grid(dg, cs\%G, us)}
\DoxyCodeLine{2447 }
\DoxyCodeLine{2448     \textcolor{keyword}{call }destroy\_dyn\_horgrid(dg)}
\DoxyCodeLine{2449     \textcolor{keyword}{call }mom\_grid\_end(g) ; \textcolor{keyword}{deallocate}(g)}
\DoxyCodeLine{2450 }
\DoxyCodeLine{2451     g => cs\%G}
\DoxyCodeLine{2452     \textcolor{keywordflow}{if} (cs\%debug .or. cs\%G\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2453       \textcolor{keyword}{call }clone\_mom\_domain(cs\%G\%Domain, cs\%G\%Domain\_aux, symmetric=.false.)}
\DoxyCodeLine{2454     \textcolor{keywordflow}{else} ; cs\%G\%Domain\_aux => cs\%G\%Domain ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2455     g\%ke = gv\%ke}
\DoxyCodeLine{2456 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2457 }
\DoxyCodeLine{2458   \textcolor{comment}{! At this point, all user-\/modified initialization code has been called.  The}}
\DoxyCodeLine{2459   \textcolor{comment}{! remainder of this subroutine is controlled by the parameters that have}}
\DoxyCodeLine{2460   \textcolor{comment}{! have already been set.}}
\DoxyCodeLine{2461 }
\DoxyCodeLine{2462   \textcolor{keywordflow}{if} (ale\_remap\_init\_conds(cs\%ALE\_CSp) .and. .not. query\_initialized(cs\%h,\textcolor{stringliteral}{"h"},restart\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2463     \textcolor{comment}{! This block is controlled by the ALE parameter REMAP\_AFTER\_INITIALIZATION.}}
\DoxyCodeLine{2464     \textcolor{comment}{! \(\backslash\)todo This block exists for legacy reasons and we should phase it out of}}
\DoxyCodeLine{2465     \textcolor{comment}{! all examples. !\#\#\#}}
\DoxyCodeLine{2466     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2467       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre ALE adjust init cond [uv]"}, \&}
\DoxyCodeLine{2468                     cs\%u, cs\%v, g\%HI, haloshift=1)}
\DoxyCodeLine{2469       \textcolor{keyword}{call }hchksum(cs\%h,\textcolor{stringliteral}{"Pre ALE adjust init cond h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{2470 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2471     \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"Calling adjustGridForIntegrity() to remap initial conditions (initialize\_MOM)"})}
\DoxyCodeLine{2472     \textcolor{keyword}{call }adjustgridforintegrity(cs\%ALE\_CSp, g, gv, cs\%h )}
\DoxyCodeLine{2473     \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"Calling ALE\_main() to remap initial conditions (initialize\_MOM)"})}
\DoxyCodeLine{2474     \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2475       filename = trim(inputdir)//trim(ice\_shelf\_file)}
\DoxyCodeLine{2476       \textcolor{keywordflow}{if} (.not.file\_exists(filename, g\%Domain)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2477         \textcolor{stringliteral}{"MOM: Unable to open "}//trim(filename))}
\DoxyCodeLine{2478 }
\DoxyCodeLine{2479       \textcolor{keyword}{allocate}(area\_shelf\_h(isd:ied,jsd:jed))}
\DoxyCodeLine{2480       \textcolor{keyword}{allocate}(frac\_shelf\_h(isd:ied,jsd:jed))}
\DoxyCodeLine{2481       \textcolor{keyword}{call }mom\_read\_data(filename, trim(area\_varname), area\_shelf\_h, g\%Domain, scale=us\%m\_to\_L**2)}
\DoxyCodeLine{2482       \textcolor{comment}{! initialize frac\_shelf\_h with zeros (open water everywhere)}}
\DoxyCodeLine{2483       frac\_shelf\_h(:,:) = 0.0}
\DoxyCodeLine{2484       \textcolor{comment}{! compute fractional ice shelf coverage of h}}
\DoxyCodeLine{2485       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{2486         \textcolor{keywordflow}{if} (g\%areaT(i,j) > 0.0) \&}
\DoxyCodeLine{2487           frac\_shelf\_h(i,j) = area\_shelf\_h(i,j) / g\%areaT(i,j)}
\DoxyCodeLine{2488 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2489       \textcolor{comment}{! pass to the pointer}}
\DoxyCodeLine{2490       shelf\_area => frac\_shelf\_h}
\DoxyCodeLine{2491       \textcolor{keyword}{call }ale\_main(g, gv, us, cs\%h, cs\%u, cs\%v, cs\%tv, cs\%tracer\_Reg, cs\%ALE\_CSp, \&}
\DoxyCodeLine{2492                     cs\%OBC, frac\_shelf\_h=shelf\_area)}
\DoxyCodeLine{2493     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2494       \textcolor{keyword}{call }ale\_main( g, gv, us, cs\%h, cs\%u, cs\%v, cs\%tv, cs\%tracer\_Reg, cs\%ALE\_CSp, cs\%OBC)}
\DoxyCodeLine{2495 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2496 }
\DoxyCodeLine{2497     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_init)}
\DoxyCodeLine{2498     \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs\%u, cs\%v, g\%Domain)}
\DoxyCodeLine{2499     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2500       \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs\%tv\%T, g\%Domain, halo=1)}
\DoxyCodeLine{2501       \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs\%tv\%S, g\%Domain, halo=1)}
\DoxyCodeLine{2502 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2503     \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs\%h, g\%Domain, halo=1)}
\DoxyCodeLine{2504     \textcolor{keyword}{call }do\_group\_pass(tmp\_pass\_uv\_t\_s\_h, g\%Domain)}
\DoxyCodeLine{2505     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_init)}
\DoxyCodeLine{2506 }
\DoxyCodeLine{2507     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2508       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post ALE adjust init cond [uv]"}, cs\%u, cs\%v, g\%HI, haloshift=1)}
\DoxyCodeLine{2509       \textcolor{keyword}{call }hchksum(cs\%h, \textcolor{stringliteral}{"Post ALE adjust init cond h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{2510 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2511 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2512   \textcolor{keywordflow}{if} ( cs\%use\_ALE\_algorithm ) \textcolor{keyword}{call }ale\_updateverticalgridtype( cs\%ALE\_CSp, gv )}
\DoxyCodeLine{2513 }
\DoxyCodeLine{2514   diag => cs\%diag}
\DoxyCodeLine{2515   \textcolor{comment}{! Initialize the diag mediator.}}
\DoxyCodeLine{2516   \textcolor{keyword}{call }diag\_mediator\_init(g, gv, us, gv\%ke, param\_file, diag, doc\_file\_dir=dirs\%output\_directory)}
\DoxyCodeLine{2517   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(diag\_ptr)) diag\_ptr => cs\%diag}
\DoxyCodeLine{2518 }
\DoxyCodeLine{2519   \textcolor{comment}{! Initialize the diagnostics masks for native arrays.}}
\DoxyCodeLine{2520   \textcolor{comment}{! This step has to be done after call to MOM\_initialize\_state}}
\DoxyCodeLine{2521   \textcolor{comment}{! and before MOM\_diagnostics\_init}}
\DoxyCodeLine{2522   \textcolor{keyword}{call }diag\_masks\_set(g, gv\%ke, diag)}
\DoxyCodeLine{2523 }
\DoxyCodeLine{2524   \textcolor{comment}{! Set up pointers within diag mediator control structure,}}
\DoxyCodeLine{2525   \textcolor{comment}{! this needs to occur \_after\_ CS\%h etc. have been allocated.}}
\DoxyCodeLine{2526   \textcolor{keyword}{call }diag\_set\_state\_ptrs(cs\%h, cs\%T, cs\%S, cs\%tv\%eqn\_of\_state, diag)}
\DoxyCodeLine{2527 }
\DoxyCodeLine{2528   \textcolor{comment}{! This call sets up the diagnostic axes. These are needed,}}
\DoxyCodeLine{2529   \textcolor{comment}{! e.g. to generate the target grids below.}}
\DoxyCodeLine{2530   \textcolor{keyword}{call }set\_axes\_info(g, gv, us, param\_file, diag)}
\DoxyCodeLine{2531 }
\DoxyCodeLine{2532   \textcolor{comment}{! Whenever thickness/T/S changes let the diag manager know, target grids}}
\DoxyCodeLine{2533   \textcolor{comment}{! for vertical remapping may need to be regenerated.}}
\DoxyCodeLine{2534   \textcolor{comment}{! FIXME: are h, T, S updated at the same time? Review these for T, S updates.}}
\DoxyCodeLine{2535   \textcolor{keyword}{call }diag\_update\_remap\_grids(diag)}
\DoxyCodeLine{2536 }
\DoxyCodeLine{2537   \textcolor{comment}{! Setup the diagnostic grid storage types}}
\DoxyCodeLine{2538   \textcolor{keyword}{call }diag\_grid\_storage\_init(cs\%diag\_pre\_sync, g, diag)}
\DoxyCodeLine{2539   \textcolor{keyword}{call }diag\_grid\_storage\_init(cs\%diag\_pre\_dyn, g, diag)}
\DoxyCodeLine{2540 }
\DoxyCodeLine{2541   \textcolor{comment}{! Calculate masks for diagnostics arrays in non-\/native coordinates}}
\DoxyCodeLine{2542   \textcolor{comment}{! This step has to be done after set\_axes\_info() because the axes needed}}
\DoxyCodeLine{2543   \textcolor{comment}{! to be configured, and after diag\_update\_remap\_grids() because the grids}}
\DoxyCodeLine{2544   \textcolor{comment}{! must be defined.}}
\DoxyCodeLine{2545   \textcolor{keyword}{call }set\_masks\_for\_axes(g, diag)}
\DoxyCodeLine{2546 }
\DoxyCodeLine{2547   \textcolor{comment}{! Diagnose static fields AND associate areas/volumes with axes}}
\DoxyCodeLine{2548   \textcolor{keyword}{call }write\_static\_fields(g, gv, us, cs\%tv, cs\%diag)}
\DoxyCodeLine{2549   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"static fields written (initialize\_MOM)"})}
\DoxyCodeLine{2550 }
\DoxyCodeLine{2551   \textcolor{comment}{! Register the volume cell measure (must be one of first diagnostics)}}
\DoxyCodeLine{2552   \textcolor{keyword}{call }register\_cell\_measure(g, cs\%diag, time)}
\DoxyCodeLine{2553 }
\DoxyCodeLine{2554   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_mom\_init)}
\DoxyCodeLine{2555   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2556     \textcolor{keyword}{call }ale\_writecoordinatefile( cs\%ALE\_CSp, gv, dirs\%output\_directory )}
\DoxyCodeLine{2557 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2558   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_mom\_init)}
\DoxyCodeLine{2559   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"ALE initialized (initialize\_MOM)"})}
\DoxyCodeLine{2560 }
\DoxyCodeLine{2561   cs\%useMEKE = meke\_init(time, g, us, param\_file, diag, cs\%MEKE\_CSp, cs\%MEKE, restart\_csp)}
\DoxyCodeLine{2562 }
\DoxyCodeLine{2563   \textcolor{keyword}{call }varmix\_init(time, g, gv, us, param\_file, diag, cs\%VarMix)}
\DoxyCodeLine{2564   \textcolor{keyword}{call }set\_visc\_init(time, g, gv, us, param\_file, diag, cs\%visc, cs\%set\_visc\_CSp, restart\_csp, cs\%OBC)}
\DoxyCodeLine{2565   \textcolor{keyword}{call }thickness\_diffuse\_init(time, g, gv, us, param\_file, diag, cs\%CDp, cs\%thickness\_diffuse\_CSp)}
\DoxyCodeLine{2566 }
\DoxyCodeLine{2567   \textcolor{keywordflow}{if} (cs\%split) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2568     \textcolor{keyword}{allocate}(eta(szi\_(g),szj\_(g))) ; eta(:,:) = 0.0}
\DoxyCodeLine{2569     \textcolor{keyword}{call }initialize\_dyn\_split\_rk2(cs\%u, cs\%v, cs\%h, cs\%uh, cs\%vh, eta, time, \&}
\DoxyCodeLine{2570               g, gv, us, param\_file, diag, cs\%dyn\_split\_RK2\_CSp, restart\_csp, \&}
\DoxyCodeLine{2571               cs\%dt, cs\%ADp, cs\%CDp, mom\_internal\_state, cs\%VarMix, cs\%MEKE, \&}
\DoxyCodeLine{2572               cs\%thickness\_diffuse\_CSp,                                      \&}
\DoxyCodeLine{2573               cs\%OBC, cs\%update\_OBC\_CSp, cs\%ALE\_CSp, cs\%set\_visc\_CSp,        \&}
\DoxyCodeLine{2574               cs\%visc, dirs, cs\%ntrunc, calc\_dtbt=calc\_dtbt, cont\_stencil=cs\%cont\_stencil)}
\DoxyCodeLine{2575     \textcolor{keywordflow}{if} (cs\%dtbt\_reset\_period > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2576       cs\%dtbt\_reset\_interval = real\_to\_time(cs\%dtbt\_reset\_period)}
\DoxyCodeLine{2577       \textcolor{comment}{! Set dtbt\_reset\_time to be the next even multiple of dtbt\_reset\_interval.}}
\DoxyCodeLine{2578       cs\%dtbt\_reset\_time = time\_init + cs\%dtbt\_reset\_interval * \&}
\DoxyCodeLine{2579                                  ((time -\/ time\_init) / cs\%dtbt\_reset\_interval)}
\DoxyCodeLine{2580       \textcolor{keywordflow}{if} ((cs\%dtbt\_reset\_time > time) .and. calc\_dtbt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2581         \textcolor{comment}{! Back up dtbt\_reset\_time one interval to force dtbt to be calculated,}}
\DoxyCodeLine{2582         \textcolor{comment}{! because the restart was not aligned with the interval to recalculate}}
\DoxyCodeLine{2583         \textcolor{comment}{! dtbt, and dtbt was not read from a restart file.}}
\DoxyCodeLine{2584         cs\%dtbt\_reset\_time = cs\%dtbt\_reset\_time -\/ cs\%dtbt\_reset\_interval}
\DoxyCodeLine{2585 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2586 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2587   \textcolor{keywordflow}{elseif} (cs\%use\_RK2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2588     \textcolor{keyword}{call }initialize\_dyn\_unsplit\_rk2(cs\%u, cs\%v, cs\%h, time, g, gv, us,     \&}
\DoxyCodeLine{2589             param\_file, diag, cs\%dyn\_unsplit\_RK2\_CSp, restart\_csp,         \&}
\DoxyCodeLine{2590             cs\%ADp, cs\%CDp, mom\_internal\_state, cs\%MEKE, cs\%OBC,           \&}
\DoxyCodeLine{2591             cs\%update\_OBC\_CSp, cs\%ALE\_CSp, cs\%set\_visc\_CSp, cs\%visc, dirs, \&}
\DoxyCodeLine{2592             cs\%ntrunc, cont\_stencil=cs\%cont\_stencil)}
\DoxyCodeLine{2593   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2594     \textcolor{keyword}{call }initialize\_dyn\_unsplit(cs\%u, cs\%v, cs\%h, time, g, gv, us,         \&}
\DoxyCodeLine{2595             param\_file, diag, cs\%dyn\_unsplit\_CSp, restart\_csp,             \&}
\DoxyCodeLine{2596             cs\%ADp, cs\%CDp, mom\_internal\_state, cs\%MEKE, cs\%OBC,           \&}
\DoxyCodeLine{2597             cs\%update\_OBC\_CSp, cs\%ALE\_CSp, cs\%set\_visc\_CSp, cs\%visc, dirs, \&}
\DoxyCodeLine{2598             cs\%ntrunc, cont\_stencil=cs\%cont\_stencil)}
\DoxyCodeLine{2599 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2600 }
\DoxyCodeLine{2601   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"dynamics initialized (initialize\_MOM)"})}
\DoxyCodeLine{2602 }
\DoxyCodeLine{2603   cs\%mixedlayer\_restrat = mixedlayer\_restrat\_init(time, g, gv, us, param\_file, diag, \&}
\DoxyCodeLine{2604                                                   cs\%mixedlayer\_restrat\_CSp, restart\_csp)}
\DoxyCodeLine{2605   \textcolor{keywordflow}{if} (cs\%mixedlayer\_restrat) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2606     \textcolor{keywordflow}{if} (.not.(bulkmixedlayer .or. cs\%use\_ALE\_algorithm)) \&}
\DoxyCodeLine{2607       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM: MIXEDLAYER\_RESTRAT true requires a boundary layer scheme."})}
\DoxyCodeLine{2608     \textcolor{comment}{! When DIABATIC\_FIRST=False and using CS\%visc\%ML in mixedlayer\_restrat we need to update after a restart}}
\DoxyCodeLine{2609     \textcolor{keywordflow}{if} (.not. cs\%diabatic\_first .and. \textcolor{keyword}{associated}(cs\%visc\%MLD)) \&}
\DoxyCodeLine{2610       \textcolor{keyword}{call }pass\_var(cs\%visc\%MLD, g\%domain, halo=1)}
\DoxyCodeLine{2611 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2612 }
\DoxyCodeLine{2613   \textcolor{keyword}{call }mom\_diagnostics\_init(mom\_internal\_state, cs\%ADp, cs\%CDp, time, g, gv, us, \&}
\DoxyCodeLine{2614                             param\_file, diag, cs\%diagnostics\_CSp, cs\%tv)}
\DoxyCodeLine{2615   \textcolor{keyword}{call }diag\_copy\_diag\_to\_storage(cs\%diag\_pre\_sync, cs\%h, cs\%diag)}
\DoxyCodeLine{2616 }
\DoxyCodeLine{2617   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%sponge\_CSp)) \&}
\DoxyCodeLine{2618     \textcolor{keyword}{call }init\_sponge\_diags(time, g, gv, us, diag, cs\%sponge\_CSp)}
\DoxyCodeLine{2619 }
\DoxyCodeLine{2620   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%ALE\_sponge\_CSp)) \&}
\DoxyCodeLine{2621     \textcolor{keyword}{call }init\_ale\_sponge\_diags(time, g, diag, cs\%ALE\_sponge\_CSp)}
\DoxyCodeLine{2622 }
\DoxyCodeLine{2623   \textcolor{keywordflow}{if} (cs\%adiabatic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2624     \textcolor{keyword}{call }adiabatic\_driver\_init(time, g, param\_file, diag, cs\%diabatic\_CSp, \&}
\DoxyCodeLine{2625                                cs\%tracer\_flow\_CSp)}
\DoxyCodeLine{2626   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2627     \textcolor{keyword}{call }diabatic\_driver\_init(time, g, gv, us, param\_file, cs\%use\_ALE\_algorithm, diag, \&}
\DoxyCodeLine{2628                               cs\%ADp, cs\%CDp, cs\%diabatic\_CSp, cs\%tracer\_flow\_CSp, \&}
\DoxyCodeLine{2629                               cs\%sponge\_CSp, cs\%ALE\_sponge\_CSp)}
\DoxyCodeLine{2630 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2631 }
\DoxyCodeLine{2632   \textcolor{keyword}{call }tracer\_advect\_init(time, g, us, param\_file, diag, cs\%tracer\_adv\_CSp)}
\DoxyCodeLine{2633   \textcolor{keyword}{call }tracer\_hor\_diff\_init(time, g, us, param\_file, diag, cs\%tv\%eqn\_of\_state, cs\%diabatic\_CSp, \&}
\DoxyCodeLine{2634                             cs\%tracer\_diff\_CSp)}
\DoxyCodeLine{2635 }
\DoxyCodeLine{2636   \textcolor{keyword}{call }lock\_tracer\_registry(cs\%tracer\_Reg)}
\DoxyCodeLine{2637   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"tracer registry now locked (initialize\_MOM)"})}
\DoxyCodeLine{2638 }
\DoxyCodeLine{2639   \textcolor{comment}{! now register some diagnostics since the tracer registry is now locked}}
\DoxyCodeLine{2640   \textcolor{keyword}{call }register\_surface\_diags(time, g, us, cs\%sfc\_IDs, cs\%diag, cs\%tv)}
\DoxyCodeLine{2641   \textcolor{keyword}{call }register\_diags(time, g, gv, us, cs\%IDs, cs\%diag)}
\DoxyCodeLine{2642   \textcolor{keyword}{call }register\_transport\_diags(time, g, gv, us, cs\%transport\_IDs, cs\%diag)}
\DoxyCodeLine{2643   \textcolor{keyword}{call }register\_tracer\_diagnostics(cs\%tracer\_Reg, cs\%h, time, diag, g, gv, us, \&}
\DoxyCodeLine{2644                                    cs\%use\_ALE\_algorithm)}
\DoxyCodeLine{2645   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2646     \textcolor{keyword}{call }ale\_register\_diags(time, g, gv, us, diag, cs\%ALE\_CSp)}
\DoxyCodeLine{2647 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2648 }
\DoxyCodeLine{2649   \textcolor{comment}{! This subroutine initializes any tracer packages.}}
\DoxyCodeLine{2650   new\_sim = is\_new\_run(restart\_csp)}
\DoxyCodeLine{2651   \textcolor{keyword}{call }tracer\_flow\_control\_init(.not.new\_sim, time, g, gv, us, cs\%h, param\_file, \&}
\DoxyCodeLine{2652              cs\%diag, cs\%OBC, cs\%tracer\_flow\_CSp, cs\%sponge\_CSp, \&}
\DoxyCodeLine{2653              cs\%ALE\_sponge\_CSp, cs\%tv)}
\DoxyCodeLine{2654   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tracer\_flow\_csp)) tracer\_flow\_csp => cs\%tracer\_flow\_CSp}
\DoxyCodeLine{2655 }
\DoxyCodeLine{2656   \textcolor{comment}{! If running in offline tracer mode, initialize the necessary control structure and}}
\DoxyCodeLine{2657   \textcolor{comment}{! parameters}}
\DoxyCodeLine{2658   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(offline\_tracer\_mode)) offline\_tracer\_mode=cs\%offline\_tracer\_mode}
\DoxyCodeLine{2659 }
\DoxyCodeLine{2660   \textcolor{keywordflow}{if} (cs\%offline\_tracer\_mode) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2661     \textcolor{comment}{! Setup some initial parameterizations and also assign some of the subtypes}}
\DoxyCodeLine{2662     \textcolor{keyword}{call }offline\_transport\_init(param\_file, cs\%offline\_CSp, cs\%diabatic\_CSp, g, gv, us)}
\DoxyCodeLine{2663     \textcolor{keyword}{call }insert\_offline\_main( cs=cs\%offline\_CSp, ale\_csp=cs\%ALE\_CSp, diabatic\_csp=cs\%diabatic\_CSp, \&}
\DoxyCodeLine{2664                               diag=cs\%diag, obc=cs\%OBC, tracer\_adv\_csp=cs\%tracer\_adv\_CSp,              \&}
\DoxyCodeLine{2665                               tracer\_flow\_csp=cs\%tracer\_flow\_CSp, tracer\_reg=cs\%tracer\_Reg,            \&}
\DoxyCodeLine{2666                               tv=cs\%tv, x\_before\_y = (mod(first\_direction,2)==0), debug=cs\%debug )}
\DoxyCodeLine{2667     \textcolor{keyword}{call }register\_diags\_offline\_transport(time, cs\%diag, cs\%offline\_CSp)}
\DoxyCodeLine{2668 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2669 }
\DoxyCodeLine{2670   \textcolor{comment}{!-\/-\/-\/ set up group pass for u,v,T,S and h. pass\_uv\_T\_S\_h also is used in step\_MOM}}
\DoxyCodeLine{2671   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass\_init)}
\DoxyCodeLine{2672   dynamics\_stencil = min(3, g\%Domain\%nihalo, g\%Domain\%njhalo)}
\DoxyCodeLine{2673   \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs\%u, cs\%v, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{2674   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2675     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs\%tv\%T, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{2676     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs\%tv\%S, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{2677 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2678   \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs\%h, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{2679 }
\DoxyCodeLine{2680   \textcolor{keyword}{call }do\_group\_pass(pass\_uv\_t\_s\_h, g\%Domain)}
\DoxyCodeLine{2681 }
\DoxyCodeLine{2682   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%visc\%Kv\_shear)) \&}
\DoxyCodeLine{2683     \textcolor{keyword}{call }pass\_var(cs\%visc\%Kv\_shear, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{2684 }
\DoxyCodeLine{2685   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%visc\%Kv\_slow)) \&}
\DoxyCodeLine{2686     \textcolor{keyword}{call }pass\_var(cs\%visc\%Kv\_slow, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{2687 }
\DoxyCodeLine{2688   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass\_init)}
\DoxyCodeLine{2689 }
\DoxyCodeLine{2690   \textcolor{keyword}{call }register\_obsolete\_diagnostics(param\_file, cs\%diag)}
\DoxyCodeLine{2691 }
\DoxyCodeLine{2692   \textcolor{keywordflow}{if} (use\_frazil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2693     \textcolor{keywordflow}{if} (query\_initialized(cs\%tv\%frazil, \textcolor{stringliteral}{"frazil"}, restart\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2694       \textcolor{comment}{! Test whether the dimensional rescaling has changed for heat content.}}
\DoxyCodeLine{2695       \textcolor{keywordflow}{if} ((us\%kg\_m3\_to\_R\_restart*us\%m\_to\_Z\_restart*us\%J\_kg\_to\_Q\_restart /= 0.0) .and. \&}
\DoxyCodeLine{2696           ((us\%J\_kg\_to\_Q*us\%kg\_m3\_to\_R*us\%m\_to\_Z) /= \&}
\DoxyCodeLine{2697            (us\%J\_kg\_to\_Q\_restart*us\%kg\_m3\_to\_R\_restart*us\%m\_to\_Z\_restart)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2698         qrz\_rescale = (us\%J\_kg\_to\_Q*us\%kg\_m3\_to\_R*us\%m\_to\_Z) / \&}
\DoxyCodeLine{2699                       (us\%J\_kg\_to\_Q\_restart*us\%kg\_m3\_to\_R\_restart*us\%m\_to\_Z\_restart)}
\DoxyCodeLine{2700         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2701           cs\%tv\%frazil(i,j) = qrz\_rescale * cs\%tv\%frazil(i,j)}
\DoxyCodeLine{2702 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2703 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2704     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2705       cs\%tv\%frazil(:,:) = 0.0}
\DoxyCodeLine{2706 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2707 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2708 }
\DoxyCodeLine{2709   \textcolor{keywordflow}{if} (cs\%interp\_p\_surf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2710     cs\%p\_surf\_prev\_set = query\_initialized(cs\%p\_surf\_prev,\textcolor{stringliteral}{"p\_surf\_prev"},restart\_csp)}
\DoxyCodeLine{2711 }
\DoxyCodeLine{2712     \textcolor{keywordflow}{if} (cs\%p\_surf\_prev\_set) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2713       \textcolor{comment}{! Test whether the dimensional rescaling has changed for pressure.}}
\DoxyCodeLine{2714       \textcolor{keywordflow}{if} ((us\%kg\_m3\_to\_R\_restart*us\%s\_to\_T\_restart*us\%m\_to\_L\_restart /= 0.0) .and. \&}
\DoxyCodeLine{2715           ((us\%kg\_m3\_to\_R*(us\%m\_to\_L*us\%s\_to\_T\_restart)**2) /= \&}
\DoxyCodeLine{2716            (us\%kg\_m3\_to\_R\_restart*(us\%m\_to\_L\_restart*us\%s\_to\_T)**2)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2717         rl2\_t2\_rescale = (us\%kg\_m3\_to\_R*(us\%m\_to\_L*us\%s\_to\_T\_restart)**2) / \&}
\DoxyCodeLine{2718                          (us\%kg\_m3\_to\_R\_restart*(us\%m\_to\_L\_restart*us\%s\_to\_T)**2)}
\DoxyCodeLine{2719         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2720           cs\%p\_surf\_prev(i,j) = rl2\_t2\_rescale * cs\%p\_surf\_prev(i,j)}
\DoxyCodeLine{2721 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2722 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2723 }
\DoxyCodeLine{2724       \textcolor{keyword}{call }pass\_var(cs\%p\_surf\_prev, g\%domain)}
\DoxyCodeLine{2725 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2726 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2727 }
\DoxyCodeLine{2728   \textcolor{keywordflow}{if} (use\_ice\_shelf .and. \textcolor{keyword}{associated}(cs\%Hml)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2729     \textcolor{keywordflow}{if} (query\_initialized(cs\%Hml, \textcolor{stringliteral}{"hML"}, restart\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2730       \textcolor{comment}{! Test whether the dimensional rescaling has changed for depths.}}
\DoxyCodeLine{2731       \textcolor{keywordflow}{if} ((us\%m\_to\_Z\_restart /= 0.0) .and. (us\%m\_to\_Z /= us\%m\_to\_Z\_restart) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2732         z\_rescale = us\%m\_to\_Z / us\%m\_to\_Z\_restart}
\DoxyCodeLine{2733         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{2734           cs\%Hml(i,j) = z\_rescale * cs\%Hml(i,j)}
\DoxyCodeLine{2735 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2736 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2737 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2738 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2739 }
\DoxyCodeLine{2740   \textcolor{keywordflow}{if} (.not.query\_initialized(cs\%ave\_ssh\_ibc,\textcolor{stringliteral}{"ave\_ssh"},restart\_csp)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2741     \textcolor{keywordflow}{if} (cs\%split) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2742       \textcolor{keyword}{call }find\_eta(cs\%h, cs\%tv, g, gv, us, cs\%ave\_ssh\_ibc, eta, eta\_to\_m=1.0)}
\DoxyCodeLine{2743     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2744       \textcolor{keyword}{call }find\_eta(cs\%h, cs\%tv, g, gv, us, cs\%ave\_ssh\_ibc, eta\_to\_m=1.0)}
\DoxyCodeLine{2745 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2746 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2747   \textcolor{keywordflow}{if} (cs\%split) \textcolor{keyword}{deallocate}(eta)}
\DoxyCodeLine{2748 }
\DoxyCodeLine{2749   cs\%nstep\_tot = 0}
\DoxyCodeLine{2750   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(count\_calls)) cs\%count\_calls = count\_calls}
\DoxyCodeLine{2751   \textcolor{keyword}{call }mom\_sum\_output\_init(g\_in, us, param\_file, dirs\%output\_directory, \&}
\DoxyCodeLine{2752                            cs\%ntrunc, time\_init, cs\%sum\_output\_CSp)}
\DoxyCodeLine{2753 }
\DoxyCodeLine{2754   \textcolor{comment}{! Flag whether to save initial conditions in finish\_MOM\_initialization() or not.}}
\DoxyCodeLine{2755   cs\%write\_IC = save\_ic .and. \&}
\DoxyCodeLine{2756                 .not.((dirs\%input\_filename(1:1) == \textcolor{stringliteral}{'r'}) .and. \&}
\DoxyCodeLine{2757                       (len\_trim(dirs\%input\_filename) == 1))}
\DoxyCodeLine{2758 }
\DoxyCodeLine{2759   \textcolor{keywordflow}{if} (cs\%ensemble\_ocean) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2760     \textcolor{keyword}{call }init\_oda(time, g, gv, cs\%odaCS)}
\DoxyCodeLine{2761 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2762 }
\DoxyCodeLine{2763   \textcolor{comment}{!\#\#\# This could perhaps go here instead of in finish\_MOM\_initialization?}}
\DoxyCodeLine{2764   \textcolor{comment}{! call fix\_restart\_scaling(GV)}}
\DoxyCodeLine{2765   \textcolor{comment}{! call fix\_restart\_unit\_scaling(US)}}
\DoxyCodeLine{2766 }
\DoxyCodeLine{2767   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"initialize\_MOM()"})}
\DoxyCodeLine{2768   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_init)}
\DoxyCodeLine{2769 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}\label{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}} 
\index{mom@{mom}!mom\_end@{mom\_end}}
\index{mom\_end@{mom\_end}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{mom\_end()}{mom\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+::mom\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS }\end{DoxyParamCaption})}



End of ocean model, including memory deallocation. 


\begin{DoxyParams}{Parameters}
{\em cs} & M\+OM control structure \\
\hline
\end{DoxyParams}


Definition at line 3486 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3486   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< MOM control structure}}
\DoxyCodeLine{3487 }
\DoxyCodeLine{3488   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm) \textcolor{keyword}{call }ale\_end(cs\%ALE\_CSp)}
\DoxyCodeLine{3489 }
\DoxyCodeLine{3490   dealloc\_(cs\%u) ; dealloc\_(cs\%v) ; dealloc\_(cs\%h)}
\DoxyCodeLine{3491   dealloc\_(cs\%uh) ; dealloc\_(cs\%vh)}
\DoxyCodeLine{3492 }
\DoxyCodeLine{3493   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%T)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3494     dealloc\_(cs\%T) ; cs\%tv\%T => null() ; dealloc\_(cs\%S) ; cs\%tv\%S => null()}
\DoxyCodeLine{3495 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3496   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%frazil)) \textcolor{keyword}{deallocate}(cs\%tv\%frazil)}
\DoxyCodeLine{3497   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%salt\_deficit)) \textcolor{keyword}{deallocate}(cs\%tv\%salt\_deficit)}
\DoxyCodeLine{3498   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%Hml)) \textcolor{keyword}{deallocate}(cs\%Hml)}
\DoxyCodeLine{3499 }
\DoxyCodeLine{3500   \textcolor{keyword}{call }tracer\_advect\_end(cs\%tracer\_adv\_CSp)}
\DoxyCodeLine{3501   \textcolor{keyword}{call }tracer\_hor\_diff\_end(cs\%tracer\_diff\_CSp)}
\DoxyCodeLine{3502   \textcolor{keyword}{call }tracer\_registry\_end(cs\%tracer\_Reg)}
\DoxyCodeLine{3503   \textcolor{keyword}{call }tracer\_flow\_control\_end(cs\%tracer\_flow\_CSp)}
\DoxyCodeLine{3504 }
\DoxyCodeLine{3505   \textcolor{keyword}{call }diabatic\_driver\_end(cs\%diabatic\_CSp)}
\DoxyCodeLine{3506 }
\DoxyCodeLine{3507   \textcolor{keywordflow}{if} (cs\%offline\_tracer\_mode) \textcolor{keyword}{call }offline\_transport\_end(cs\%offline\_CSp)}
\DoxyCodeLine{3508 }
\DoxyCodeLine{3509   dealloc\_(cs\%uhtr) ; dealloc\_(cs\%vhtr)}
\DoxyCodeLine{3510   \textcolor{keywordflow}{if} (cs\%split) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3511     \textcolor{keyword}{call }end\_dyn\_split\_rk2(cs\%dyn\_split\_RK2\_CSp)}
\DoxyCodeLine{3512   \textcolor{keywordflow}{elseif} (cs\%use\_RK2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3513     \textcolor{keyword}{call }end\_dyn\_unsplit\_rk2(cs\%dyn\_unsplit\_RK2\_CSp)}
\DoxyCodeLine{3514   \textcolor{keywordflow}{else}}
\DoxyCodeLine{3515     \textcolor{keyword}{call }end\_dyn\_unsplit(cs\%dyn\_unsplit\_CSp)}
\DoxyCodeLine{3516 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3517   dealloc\_(cs\%ave\_ssh\_ibc) ; dealloc\_(cs\%ssh\_rint)}
\DoxyCodeLine{3518   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%update\_OBC\_CSp)) \textcolor{keyword}{call }obc\_register\_end(cs\%update\_OBC\_CSp)}
\DoxyCodeLine{3519 }
\DoxyCodeLine{3520   \textcolor{keyword}{call }verticalgridend(cs\%GV)}
\DoxyCodeLine{3521   \textcolor{keyword}{call }unit\_scaling\_end(cs\%US)}
\DoxyCodeLine{3522   \textcolor{keyword}{call }mom\_grid\_end(cs\%G)}
\DoxyCodeLine{3523 }
\DoxyCodeLine{3524   \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{3525 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_ada38a8329b76f9fa1685a230869a7647}\label{namespacemom_ada38a8329b76f9fa1685a230869a7647}} 
\index{mom@{mom}!mom\_state\_is\_synchronized@{mom\_state\_is\_synchronized}}
\index{mom\_state\_is\_synchronized@{mom\_state\_is\_synchronized}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{mom\_state\_is\_synchronized()}{mom\_state\_is\_synchronized()}}
{\footnotesize\ttfamily logical function, public mom\+::mom\+\_\+state\+\_\+is\+\_\+synchronized (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{logical, intent(in), optional}]{adv\+\_\+dyn }\end{DoxyParamCaption})}



Return true if all phases of step\+\_\+\+M\+OM are at the same point in time. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+OM control structure \\
\hline
\mbox{\texttt{ in}}  & {\em adv\+\_\+dyn} & If present and true, only check whether the advection is up-\/to-\/date with the dynamics. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if all phases of the update are synchronized. 
\end{DoxyReturn}


Definition at line 3429 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{3429   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< MOM control structure}}
\DoxyCodeLine{3430   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adv\_dyn\textcolor{comment}{  !< If present and true, only check}}
\DoxyCodeLine{3431 \textcolor{comment}{                                          !! whether the advection is up-\/to-\/date with}}
\DoxyCodeLine{3432 \textcolor{comment}{                                          !! the dynamics.}}
\DoxyCodeLine{3433   \textcolor{keywordtype}{logical} :: in\_synch\textcolor{comment}{ !< True if all phases of the update are synchronized.}}
\DoxyCodeLine{3434 }
\DoxyCodeLine{3435   \textcolor{keywordtype}{logical} :: adv\_only}
\DoxyCodeLine{3436 }
\DoxyCodeLine{3437   adv\_only = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adv\_dyn)) adv\_only = adv\_dyn}
\DoxyCodeLine{3438 }
\DoxyCodeLine{3439   \textcolor{keywordflow}{if} (adv\_only) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3440     in\_synch = (cs\%t\_dyn\_rel\_adv == 0.0)}
\DoxyCodeLine{3441   \textcolor{keywordflow}{else}}
\DoxyCodeLine{3442     in\_synch = ((cs\%t\_dyn\_rel\_adv == 0.0) .and. (cs\%t\_dyn\_rel\_thermo == 0.0))}
\DoxyCodeLine{3443 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3444 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_ab57e47834591c651339770f7e51efe57}\label{namespacemom_ab57e47834591c651339770f7e51efe57}} 
\index{mom@{mom}!mom\_timing\_init@{mom\_timing\_init}}
\index{mom\_timing\_init@{mom\_timing\_init}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{mom\_timing\_init()}{mom\_timing\_init()}}
{\footnotesize\ttfamily subroutine mom\+::mom\+\_\+timing\+\_\+init (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), intent(in)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Set up C\+PU clock I\+Ds for timing various subroutines. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & control structure set up by initialize\+\_\+\+M\+OM. \\
\hline
\end{DoxyParams}


Definition at line 2855 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2855   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{  !< control structure set up by initialize\_MOM.}}
\DoxyCodeLine{2856 }
\DoxyCodeLine{2857  id\_clock\_ocean    = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean'}, grain=clock\_component)}
\DoxyCodeLine{2858  id\_clock\_dynamics = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean dynamics'}, grain=clock\_subcomponent)}
\DoxyCodeLine{2859  id\_clock\_thermo   = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean thermodynamics and tracers'}, grain=clock\_subcomponent)}
\DoxyCodeLine{2860  id\_clock\_other    = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean Other'}, grain=clock\_subcomponent)}
\DoxyCodeLine{2861  id\_clock\_tracer   = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tracer advection)'}, grain=clock\_module\_driver)}
\DoxyCodeLine{2862  \textcolor{keywordflow}{if} (.not.cs\%adiabatic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2863    id\_clock\_diabatic = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean diabatic driver)'}, grain=clock\_module\_driver)}
\DoxyCodeLine{2864  \textcolor{keywordflow}{else}}
\DoxyCodeLine{2865    id\_clock\_adiabatic = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean adiabatic driver)'}, grain=clock\_module\_driver)}
\DoxyCodeLine{2866 \textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2867 }
\DoxyCodeLine{2868  id\_clock\_continuity = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity equation *)'}, grain=clock\_module)}
\DoxyCodeLine{2869  id\_clock\_bbl\_visc   = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean set BBL viscosity)'}, grain=clock\_module)}
\DoxyCodeLine{2870  id\_clock\_pass       = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean message passing *)'}, grain=clock\_module)}
\DoxyCodeLine{2871  id\_clock\_mom\_init   = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean MOM\_initialize\_state)'}, grain=clock\_module)}
\DoxyCodeLine{2872  id\_clock\_pass\_init  = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean init message passing *)'}, grain=clock\_routine)}
\DoxyCodeLine{2873  \textcolor{keywordflow}{if} (cs\%thickness\_diffuse) \&}
\DoxyCodeLine{2874    id\_clock\_thick\_diff = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean thickness diffusion *)'}, grain=clock\_module)}
\DoxyCodeLine{2875 \textcolor{comment}{!if (CS\%mixedlayer\_restrat) \&}}
\DoxyCodeLine{2876    id\_clock\_ml\_restrat = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean mixed layer restrat)'}, grain=clock\_module)}
\DoxyCodeLine{2877  id\_clock\_diagnostics  = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean collective diagnostics)'}, grain=clock\_module)}
\DoxyCodeLine{2878  id\_clock\_z\_diag       = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean Z-\/space diagnostics)'}, grain=clock\_module)}
\DoxyCodeLine{2879  id\_clock\_ale          = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean ALE)'}, grain=clock\_module)}
\DoxyCodeLine{2880  \textcolor{keywordflow}{if} (cs\%offline\_tracer\_mode) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2881   id\_clock\_offline\_tracer = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean offline tracers'}, grain=clock\_subcomponent)}
\DoxyCodeLine{2882 \textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2883 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}\label{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}} 
\index{mom@{mom}!register\_diags@{register\_diags}}
\index{register\_diags@{register\_diags}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{register\_diags()}{register\_diags()}}
{\footnotesize\ttfamily subroutine mom\+::register\+\_\+diags (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(inout)}]{US,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__diag__ids}{mom\+\_\+diag\+\_\+ids}}), intent(inout)}]{I\+Ds,  }\item[{type(diag\+\_\+ctrl), intent(inout)}]{diag }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Register certain diagnostics. 


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


Definition at line 2824 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2824   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{  !< current model time}}
\DoxyCodeLine{2825   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< ocean grid structure}}
\DoxyCodeLine{2826   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< ocean vertical grid structure}}
\DoxyCodeLine{2827   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(inout)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{2828   \textcolor{keywordtype}{type}(MOM\_diag\_IDs),      \textcolor{keywordtype}{intent(inout)} :: IDs\textcolor{comment}{   !< A structure with the diagnostic IDs.}}
\DoxyCodeLine{2829   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{  !< regulates diagnostic output}}
\DoxyCodeLine{2830 }
\DoxyCodeLine{2831 \textcolor{keywordtype}{  real} :: H\_convert}
\DoxyCodeLine{2832   \textcolor{keywordtype}{character(len=48)} :: thickness\_units}
\DoxyCodeLine{2833 }
\DoxyCodeLine{2834   thickness\_units = get\_thickness\_units(gv)}
\DoxyCodeLine{2835   \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2836     h\_convert = gv\%H\_to\_m}
\DoxyCodeLine{2837   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2838     h\_convert = gv\%H\_to\_kg\_m2}
\DoxyCodeLine{2839 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2840 }
\DoxyCodeLine{2841   \textcolor{comment}{! Diagnostics of the rapidly varying dynamic state}}
\DoxyCodeLine{2842   ids\%id\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'u\_dyn'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{2843       \textcolor{stringliteral}{'Zonal velocity after the dynamics update'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2844   ids\%id\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'v\_dyn'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{2845       \textcolor{stringliteral}{'Meridional velocity after the dynamics update'}, \textcolor{stringliteral}{'m s-\/1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2846   ids\%id\_h = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h\_dyn'}, diag\%axesTL, time, \&}
\DoxyCodeLine{2847       \textcolor{stringliteral}{'Layer Thickness after the dynamics update'}, thickness\_units, \&}
\DoxyCodeLine{2848       v\_extensive=.true., conversion=h\_convert)}
\DoxyCodeLine{2849   ids\%id\_ssh\_inst = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSH\_inst'}, diag\%axesT1, \&}
\DoxyCodeLine{2850       time, \textcolor{stringliteral}{'Instantaneous Sea Surface Height'}, \textcolor{stringliteral}{'m'})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}\label{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}} 
\index{mom@{mom}!set\_restart\_fields@{set\_restart\_fields}}
\index{set\_restart\_fields@{set\_restart\_fields}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{set\_restart\_fields()}{set\_restart\_fields()}}
{\footnotesize\ttfamily subroutine mom\+::set\+\_\+restart\+\_\+fields (\begin{DoxyParamCaption}\item[{type(verticalgrid\+\_\+type), intent(inout)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(inout)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), intent(in)}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+C\+Sp }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Set the fields that are needed for bitwise identical restarting the time stepping scheme. In addition to those specified here directly, there may be fields related to the forcing or to the barotropic solver that are needed; these are specified in sub-\/ routines that are called from this one. 

This routine should be altered if there are any changes to the time stepping scheme. The C\+H\+E\+C\+K\+\_\+\+R\+E\+S\+T\+A\+RT facility may be used to confirm that all needed restart fields have been included. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & opened file for parsing to get parameters \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & control structure set up by initialize\+\_\+\+M\+OM \\
\hline
 & {\em restart\+\_\+csp} & pointer to the restart control structure that will be used for M\+OM. \\
\hline
\end{DoxyParams}


Definition at line 2896 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2896   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(inout)} :: GV\textcolor{comment}{         !< ocean vertical grid structure}}
\DoxyCodeLine{2897   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(inout)} :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{2898   \textcolor{keywordtype}{type}(param\_file\_type),    \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{    !< opened file for parsing to get parameters}}
\DoxyCodeLine{2899   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{            !< control structure set up by initialize\_MOM}}
\DoxyCodeLine{2900   \textcolor{keywordtype}{type}(MOM\_restart\_CS),     \textcolor{keywordtype}{pointer}    :: restart\_CSp\textcolor{comment}{   !< pointer to the restart control}}
\DoxyCodeLine{2901 \textcolor{comment}{                                                        !! structure that will be used for MOM.}}
\DoxyCodeLine{2902   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2903   \textcolor{keywordtype}{logical} :: use\_ice\_shelf \textcolor{comment}{! Needed to determine whether to add CS\%Hml to restarts}}
\DoxyCodeLine{2904   \textcolor{keywordtype}{character(len=48)} :: thickness\_units, flux\_units}
\DoxyCodeLine{2905   \textcolor{keywordtype}{type}(vardesc) :: u\_desc, v\_desc}
\DoxyCodeLine{2906 }
\DoxyCodeLine{2907   thickness\_units = get\_thickness\_units(gv)}
\DoxyCodeLine{2908   flux\_units = get\_flux\_units(gv)}
\DoxyCodeLine{2909 }
\DoxyCodeLine{2910   u\_desc = var\_desc(\textcolor{stringliteral}{"u"}, \textcolor{stringliteral}{"m s-\/1"}, \textcolor{stringliteral}{"Zonal velocity"}, hor\_grid=\textcolor{stringliteral}{'Cu'})}
\DoxyCodeLine{2911   v\_desc = var\_desc(\textcolor{stringliteral}{"v"}, \textcolor{stringliteral}{"m s-\/1"}, \textcolor{stringliteral}{"Meridional velocity"}, hor\_grid=\textcolor{stringliteral}{'Cv'})}
\DoxyCodeLine{2912 }
\DoxyCodeLine{2913   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%T)) \&}
\DoxyCodeLine{2914     \textcolor{keyword}{call }register\_restart\_field(cs\%tv\%T, \textcolor{stringliteral}{"Temp"}, .true., restart\_csp, \&}
\DoxyCodeLine{2915                                 \textcolor{stringliteral}{"Potential Temperature"}, \textcolor{stringliteral}{"degC"})}
\DoxyCodeLine{2916   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%S)) \&}
\DoxyCodeLine{2917     \textcolor{keyword}{call }register\_restart\_field(cs\%tv\%S, \textcolor{stringliteral}{"Salt"}, .true., restart\_csp, \&}
\DoxyCodeLine{2918                                 \textcolor{stringliteral}{"Salinity"}, \textcolor{stringliteral}{"PPT"})}
\DoxyCodeLine{2919 }
\DoxyCodeLine{2920   \textcolor{keyword}{call }register\_restart\_field(cs\%h, \textcolor{stringliteral}{"h"}, .true., restart\_csp, \&}
\DoxyCodeLine{2921                               \textcolor{stringliteral}{"Layer Thickness"}, thickness\_units)}
\DoxyCodeLine{2922 }
\DoxyCodeLine{2923   \textcolor{keyword}{call }register\_restart\_pair(cs\%u, cs\%v, u\_desc, v\_desc, .true., restart\_csp)}
\DoxyCodeLine{2924 }
\DoxyCodeLine{2925   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%frazil)) \&}
\DoxyCodeLine{2926     \textcolor{keyword}{call }register\_restart\_field(cs\%tv\%frazil, \textcolor{stringliteral}{"frazil"}, .false., restart\_csp, \&}
\DoxyCodeLine{2927                                 \textcolor{stringliteral}{"Frazil heat flux into ocean"}, \textcolor{stringliteral}{"J m-\/2"})}
\DoxyCodeLine{2928 }
\DoxyCodeLine{2929   \textcolor{keywordflow}{if} (cs\%interp\_p\_surf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2930     \textcolor{keyword}{call }register\_restart\_field(cs\%p\_surf\_prev, \textcolor{stringliteral}{"p\_surf\_prev"}, .false., restart\_csp, \&}
\DoxyCodeLine{2931                                 \textcolor{stringliteral}{"Previous ocean surface pressure"}, \textcolor{stringliteral}{"Pa"})}
\DoxyCodeLine{2932 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2933 }
\DoxyCodeLine{2934   \textcolor{keyword}{call }register\_restart\_field(cs\%ave\_ssh\_ibc, \textcolor{stringliteral}{"ave\_ssh"}, .false., restart\_csp, \&}
\DoxyCodeLine{2935                               \textcolor{stringliteral}{"Time average sea surface height"}, \textcolor{stringliteral}{"meter"})}
\DoxyCodeLine{2936 }
\DoxyCodeLine{2937   \textcolor{comment}{! hML is needed when using the ice shelf module}}
\DoxyCodeLine{2938   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{''}, \textcolor{stringliteral}{"ICE\_SHELF"}, use\_ice\_shelf, default=.false., \&}
\DoxyCodeLine{2939                  do\_not\_log=.true.)}
\DoxyCodeLine{2940   \textcolor{keywordflow}{if} (use\_ice\_shelf .and. \textcolor{keyword}{associated}(cs\%Hml)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2941     \textcolor{keyword}{call }register\_restart\_field(cs\%Hml, \textcolor{stringliteral}{"hML"}, .false., restart\_csp, \&}
\DoxyCodeLine{2942                                 \textcolor{stringliteral}{"Mixed layer thickness"}, \textcolor{stringliteral}{"meter"})}
\DoxyCodeLine{2943 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2944 }
\DoxyCodeLine{2945   \textcolor{comment}{! Register scalar unit conversion factors.}}
\DoxyCodeLine{2946   \textcolor{keyword}{call }register\_restart\_field(us\%m\_to\_Z\_restart, \textcolor{stringliteral}{"m\_to\_Z"}, .false., restart\_csp, \&}
\DoxyCodeLine{2947                               \textcolor{stringliteral}{"Height unit conversion factor"}, \textcolor{stringliteral}{"Z meter-\/1"})}
\DoxyCodeLine{2948   \textcolor{keyword}{call }register\_restart\_field(gv\%m\_to\_H\_restart, \textcolor{stringliteral}{"m\_to\_H"}, .false., restart\_csp, \&}
\DoxyCodeLine{2949                               \textcolor{stringliteral}{"Thickness unit conversion factor"}, \textcolor{stringliteral}{"H meter-\/1"})}
\DoxyCodeLine{2950   \textcolor{keyword}{call }register\_restart\_field(us\%m\_to\_L\_restart, \textcolor{stringliteral}{"m\_to\_L"}, .false., restart\_csp, \&}
\DoxyCodeLine{2951                               \textcolor{stringliteral}{"Length unit conversion factor"}, \textcolor{stringliteral}{"L meter-\/1"})}
\DoxyCodeLine{2952   \textcolor{keyword}{call }register\_restart\_field(us\%s\_to\_T\_restart, \textcolor{stringliteral}{"s\_to\_T"}, .false., restart\_csp, \&}
\DoxyCodeLine{2953                               \textcolor{stringliteral}{"Time unit conversion factor"}, \textcolor{stringliteral}{"T second-\/1"})}
\DoxyCodeLine{2954   \textcolor{keyword}{call }register\_restart\_field(us\%kg\_m3\_to\_R\_restart, \textcolor{stringliteral}{"kg\_m3\_to\_R"}, .false., restart\_csp, \&}
\DoxyCodeLine{2955                               \textcolor{stringliteral}{"Density unit conversion factor"}, \textcolor{stringliteral}{"R m3 kg-\/1"})}
\DoxyCodeLine{2956   \textcolor{keyword}{call }register\_restart\_field(us\%J\_kg\_to\_Q\_restart, \textcolor{stringliteral}{"J\_kg\_to\_Q"}, .false., restart\_csp, \&}
\DoxyCodeLine{2957                               \textcolor{stringliteral}{"Heat content unit conversion factor."}, units=\textcolor{stringliteral}{"Q kg J-\/1"})}
\DoxyCodeLine{2958 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_adf54a4e3a72611aa2088f46076e56e53}\label{namespacemom_adf54a4e3a72611aa2088f46076e56e53}} 
\index{mom@{mom}!step\_mom@{step\_mom}}
\index{step\_mom@{step\_mom}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{step\_mom()}{step\_mom()}}
{\footnotesize\ttfamily subroutine, public mom\+::step\+\_\+mom (\begin{DoxyParamCaption}\item[{type(mech\+\_\+forcing), intent(inout), target}]{forces\+\_\+in,  }\item[{type(forcing), intent(inout), target}]{fluxes\+\_\+in,  }\item[{type(surface), intent(inout), target}]{sfc\+\_\+state,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+start,  }\item[{real, intent(in)}]{time\+\_\+int\+\_\+in,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves,  }\item[{logical, intent(in), optional}]{do\+\_\+dynamics,  }\item[{logical, intent(in), optional}]{do\+\_\+thermodynamics,  }\item[{logical, intent(in), optional}]{start\+\_\+cycle,  }\item[{logical, intent(in), optional}]{end\+\_\+cycle,  }\item[{real, intent(in), optional}]{cycle\+\_\+length,  }\item[{logical, intent(in), optional}]{reset\+\_\+therm }\end{DoxyParamCaption})}



This subroutine orchestrates the time stepping of M\+OM. The adiabatic dynamics are stepped by calls to one of the step\+\_\+\+M\+O\+M\+\_\+dyn\+\_\+...routines. The action of lateral processes on tracers occur in calls to advect\+\_\+tracer and tracer\+\_\+hordiff. Vertical mixing and possibly remapping occur inside of diabatic. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em forces\+\_\+in} & A structure with the driving mechanical forces \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes\+\_\+in} & A structure with pointers to themodynamic, tracer and mass exchange forcing fields \\
\hline
\mbox{\texttt{ in,out}}  & {\em sfc\+\_\+state} & surface ocean state \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+start} & starting time of a segment, as a time type \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+int\+\_\+in} & time interval covered by this run segment \mbox{[}s\mbox{]}. \\
\hline
 & {\em cs} & control structure from initialize\+\_\+\+M\+OM \\
\hline
 & {\em waves} & An optional pointer to a wave property CS \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+dynamics} & Present and false, do not do updates due to the dynamics. \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+thermodynamics} & Present and false, do not do updates due to the thermodynamics or remapping. \\
\hline
\mbox{\texttt{ in}}  & {\em start\+\_\+cycle} & This indicates whether this call is to be treated as the first call to step\+\_\+\+M\+OM in a time-\/stepping cycle; missing is like true. \\
\hline
\mbox{\texttt{ in}}  & {\em end\+\_\+cycle} & This indicates whether this call is to be treated as the last call to step\+\_\+\+M\+OM in a time-\/stepping cycle; missing is like true. \\
\hline
\mbox{\texttt{ in}}  & {\em cycle\+\_\+length} & The amount of time in a coupled time stepping cycle \mbox{[}s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em reset\+\_\+therm} & This indicates whether the running sums of thermodynamic quantities should be reset. If missing, this is like start\+\_\+cycle. \\
\hline
\end{DoxyParams}


Definition at line 422 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{422   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: forces\_in\textcolor{comment}{ !< A structure with the driving mechanical forces}}
\DoxyCodeLine{423   \textcolor{keywordtype}{type}(forcing), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: fluxes\_in\textcolor{comment}{  !< A structure with pointers to themodynamic,}}
\DoxyCodeLine{424 \textcolor{comment}{                                                     !! tracer and mass exchange forcing fields}}
\DoxyCodeLine{425   \textcolor{keywordtype}{type}(surface), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{  !< surface ocean state}}
\DoxyCodeLine{426   \textcolor{keywordtype}{type}(time\_type),    \textcolor{keywordtype}{intent(in)}    :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time type}}
\DoxyCodeLine{427 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}    :: time\_int\_in\textcolor{comment}{   !< time interval covered by this run segment [s].}}
\DoxyCodeLine{428   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{            !< control structure from initialize\_MOM}}
\DoxyCodeLine{429   \textcolor{keywordtype}{type}(Wave\_parameters\_CS), \&}
\DoxyCodeLine{430             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{         !< An optional pointer to a wave property CS}}
\DoxyCodeLine{431   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: do\_dynamics\textcolor{comment}{   !< Present and false, do not do updates due}}
\DoxyCodeLine{432 \textcolor{comment}{                                                     !! to the dynamics.}}
\DoxyCodeLine{433   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: do\_thermodynamics\textcolor{comment}{  !< Present and false, do not do updates due}}
\DoxyCodeLine{434 \textcolor{comment}{                                                     !! to the thermodynamics or remapping.}}
\DoxyCodeLine{435   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: start\_cycle\textcolor{comment}{   !< This indicates whether this call is to be}}
\DoxyCodeLine{436 \textcolor{comment}{                                                     !! treated as the first call to step\_MOM in a}}
\DoxyCodeLine{437 \textcolor{comment}{                                                     !! time-\/stepping cycle; missing is like true.}}
\DoxyCodeLine{438   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: end\_cycle\textcolor{comment}{     !< This indicates whether this call is to be}}
\DoxyCodeLine{439 \textcolor{comment}{                                                     !! treated as the last call to step\_MOM in a}}
\DoxyCodeLine{440 \textcolor{comment}{                                                     !! time-\/stepping cycle; missing is like true.}}
\DoxyCodeLine{441 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: cycle\_length\textcolor{comment}{  !< The amount of time in a coupled time}}
\DoxyCodeLine{442 \textcolor{comment}{                                                     !! stepping cycle [s].}}
\DoxyCodeLine{443   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: reset\_therm\textcolor{comment}{   !< This indicates whether the running sums of}}
\DoxyCodeLine{444 \textcolor{comment}{                                                     !! thermodynamic quantities should be reset.}}
\DoxyCodeLine{445 \textcolor{comment}{                                                     !! If missing, this is like start\_cycle.}}
\DoxyCodeLine{446 }
\DoxyCodeLine{447   \textcolor{comment}{! local variables}}
\DoxyCodeLine{448   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null()  \textcolor{comment}{! pointer to a structure containing}}
\DoxyCodeLine{449                                                    \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{450   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G\_in => null()  \textcolor{comment}{! Input grid metric}}
\DoxyCodeLine{451   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to the vertical grid structure}}
\DoxyCodeLine{452   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{453                                                    \textcolor{comment}{! various unit conversion factors}}
\DoxyCodeLine{454   \textcolor{keywordtype}{integer}       :: ntstep \textcolor{comment}{! time steps between tracer updates or diabatic forcing}}
\DoxyCodeLine{455   \textcolor{keywordtype}{integer}       :: n\_max  \textcolor{comment}{! number of steps to take in this call}}
\DoxyCodeLine{456 }
\DoxyCodeLine{457   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, n}
\DoxyCodeLine{458   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{459 }
\DoxyCodeLine{460 \textcolor{keywordtype}{  real} :: time\_interval   \textcolor{comment}{! time interval covered by this run segment [T ~> s].}}
\DoxyCodeLine{461 \textcolor{keywordtype}{  real} :: dt              \textcolor{comment}{! baroclinic time step [T ~> s]}}
\DoxyCodeLine{462 \textcolor{keywordtype}{  real} :: dtdia           \textcolor{comment}{! time step for diabatic processes [T ~> s]}}
\DoxyCodeLine{463 \textcolor{keywordtype}{  real} :: dt\_therm        \textcolor{comment}{! a limited and quantized version of CS\%dt\_therm [T ~> s]}}
\DoxyCodeLine{464 \textcolor{keywordtype}{  real} :: dt\_therm\_here   \textcolor{comment}{! a further limited value of dt\_therm [T ~> s]}}
\DoxyCodeLine{465 }
\DoxyCodeLine{466 \textcolor{keywordtype}{  real} :: wt\_end, wt\_beg}
\DoxyCodeLine{467 \textcolor{keywordtype}{  real} :: bbl\_time\_int    \textcolor{comment}{! The amount of time over which the calculated BBL}}
\DoxyCodeLine{468                           \textcolor{comment}{! properties will apply, for use in diagnostics, or 0}}
\DoxyCodeLine{469                           \textcolor{comment}{! if it is not to be calculated anew [T ~> s].}}
\DoxyCodeLine{470 \textcolor{keywordtype}{  real} :: rel\_time = 0.0  \textcolor{comment}{! relative time since start of this call [T ~> s].}}
\DoxyCodeLine{471 }
\DoxyCodeLine{472   \textcolor{keywordtype}{logical} :: calc\_dtbt                 \textcolor{comment}{! Indicates whether the dynamically adjusted}}
\DoxyCodeLine{473                                        \textcolor{comment}{! barotropic time step needs to be updated.}}
\DoxyCodeLine{474   \textcolor{keywordtype}{logical} :: do\_advection              \textcolor{comment}{! If true, it is time to advect tracers.}}
\DoxyCodeLine{475   \textcolor{keywordtype}{logical} :: do\_calc\_bbl               \textcolor{comment}{! If true, calculate the boundary layer properties.}}
\DoxyCodeLine{476   \textcolor{keywordtype}{logical} :: thermo\_does\_span\_coupling \textcolor{comment}{! If true, thermodynamic forcing spans}}
\DoxyCodeLine{477                                        \textcolor{comment}{! multiple dynamic timesteps.}}
\DoxyCodeLine{478   \textcolor{keywordtype}{logical} :: do\_dyn     \textcolor{comment}{! If true, dynamics are updated with this call.}}
\DoxyCodeLine{479   \textcolor{keywordtype}{logical} :: do\_thermo  \textcolor{comment}{! If true, thermodynamics and remapping may be applied with this call.}}
\DoxyCodeLine{480   \textcolor{keywordtype}{logical} :: cycle\_start \textcolor{comment}{! If true, do calculations that are only done at the start of}}
\DoxyCodeLine{481                         \textcolor{comment}{! a stepping cycle (whatever that may mean).}}
\DoxyCodeLine{482   \textcolor{keywordtype}{logical} :: cycle\_end  \textcolor{comment}{! If true, do calculations and diagnostics that are only done at}}
\DoxyCodeLine{483                         \textcolor{comment}{! the end of a stepping cycle (whatever that may mean).}}
\DoxyCodeLine{484   \textcolor{keywordtype}{logical} :: therm\_reset \textcolor{comment}{! If true, reset running sums of thermodynamic quantities.}}
\DoxyCodeLine{485 \textcolor{keywordtype}{  real} :: cycle\_time    \textcolor{comment}{! The length of the coupled time-\/stepping cycle [T ~> s].}}
\DoxyCodeLine{486 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G))} :: \&}
\DoxyCodeLine{487     ssh         \textcolor{comment}{! sea surface height, which may be based on eta\_av [m]}}
\DoxyCodeLine{488 }
\DoxyCodeLine{489 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: \&}
\DoxyCodeLine{490     u => null(), \& \textcolor{comment}{! u : zonal velocity component [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{491     v => null(), \& \textcolor{comment}{! v : meridional velocity component [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{492     h => null()    \textcolor{comment}{! h : layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{493 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: \&}
\DoxyCodeLine{494     p\_surf => null() \textcolor{comment}{! A pointer to the ocean surface pressure [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{495 \textcolor{keywordtype}{  real} :: I\_wt\_ssh  \textcolor{comment}{! The inverse of the time weights [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{496 }
\DoxyCodeLine{497   \textcolor{keywordtype}{type}(time\_type) :: Time\_local, end\_time\_thermo, Time\_temp}
\DoxyCodeLine{498   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_tau\_ustar\_psurf}
\DoxyCodeLine{499   \textcolor{keywordtype}{logical} :: showCallTree}
\DoxyCodeLine{500 }
\DoxyCodeLine{501   \textcolor{comment}{! External forcing fields on the model index map}}
\DoxyCodeLine{502   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{pointer} :: forces     \textcolor{comment}{! Mechanical forcing}}
\DoxyCodeLine{503   \textcolor{keywordtype}{type}(forcing), \textcolor{keywordtype}{pointer} :: fluxes          \textcolor{comment}{! Boundary fluxes}}
\DoxyCodeLine{504   \textcolor{keywordtype}{type}(surface), \textcolor{keywordtype}{pointer} :: sfc\_state\_diag  \textcolor{comment}{! Surface boundary fields}}
\DoxyCodeLine{505   \textcolor{keywordtype}{integer} :: turns  \textcolor{comment}{! Number of quarter turns from input to model indexing}}
\DoxyCodeLine{506 }
\DoxyCodeLine{507   g => cs\%G ; g\_in => cs\%G\_in ; gv => cs\%GV ; us => cs\%US}
\DoxyCodeLine{508   is   = g\%isc  ; ie   = g\%iec  ; js   = g\%jsc  ; je   = g\%jec ; nz = g\%ke}
\DoxyCodeLine{509   isq  = g\%IscB ; ieq  = g\%IecB ; jsq  = g\%JscB ; jeq  = g\%JecB}
\DoxyCodeLine{510   isd  = g\%isd  ; ied  = g\%ied  ; jsd  = g\%jsd  ; jed  = g\%jed}
\DoxyCodeLine{511   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{512   u => cs\%u ; v => cs\%v ; h => cs\%h}
\DoxyCodeLine{513 }
\DoxyCodeLine{514   time\_interval = us\%s\_to\_T*time\_int\_in}
\DoxyCodeLine{515   do\_dyn = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(do\_dynamics)) do\_dyn = do\_dynamics}
\DoxyCodeLine{516   do\_thermo = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(do\_thermodynamics)) do\_thermo = do\_thermodynamics}
\DoxyCodeLine{517   \textcolor{keywordflow}{if} (.not.(do\_dyn .or. do\_thermo)) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Step\_MOM: "}//\&}
\DoxyCodeLine{518     \textcolor{stringliteral}{"Both do\_dynamics and do\_thermodynamics are false, which makes no sense."})}
\DoxyCodeLine{519   cycle\_start = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(start\_cycle)) cycle\_start = start\_cycle}
\DoxyCodeLine{520   cycle\_end = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(end\_cycle)) cycle\_end = end\_cycle}
\DoxyCodeLine{521   cycle\_time = time\_interval ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(cycle\_length)) cycle\_time = us\%s\_to\_T*cycle\_length}
\DoxyCodeLine{522   therm\_reset = cycle\_start ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(reset\_therm)) therm\_reset = reset\_therm}
\DoxyCodeLine{523 }
\DoxyCodeLine{524   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ocean)}
\DoxyCodeLine{525   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_other)}
\DoxyCodeLine{526 }
\DoxyCodeLine{527   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{528     \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Beginning of step\_MOM "}, u, v, h, cs\%uh, cs\%vh, g, gv, us)}
\DoxyCodeLine{529 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{530 }
\DoxyCodeLine{531   showcalltree = calltree\_showquery()}
\DoxyCodeLine{532   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"step\_MOM(), MOM.F90"})}
\DoxyCodeLine{533 }
\DoxyCodeLine{534   \textcolor{comment}{! Rotate the forces from G\_in to G}}
\DoxyCodeLine{535   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{536     turns = g\%HI\%turns}
\DoxyCodeLine{537     \textcolor{keyword}{allocate}(forces)}
\DoxyCodeLine{538     \textcolor{keyword}{call }allocate\_mech\_forcing(forces\_in, g, forces)}
\DoxyCodeLine{539     \textcolor{keyword}{call }rotate\_mech\_forcing(forces\_in, turns, forces)}
\DoxyCodeLine{540 }
\DoxyCodeLine{541     \textcolor{keyword}{allocate}(fluxes)}
\DoxyCodeLine{542     \textcolor{keyword}{call }allocate\_forcing\_type(fluxes\_in, g, fluxes)}
\DoxyCodeLine{543     \textcolor{keyword}{call }rotate\_forcing(fluxes\_in, fluxes, turns)}
\DoxyCodeLine{544   \textcolor{keywordflow}{else}}
\DoxyCodeLine{545     forces => forces\_in}
\DoxyCodeLine{546     fluxes => fluxes\_in}
\DoxyCodeLine{547 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{548 }
\DoxyCodeLine{549   \textcolor{comment}{! First determine the time step that is consistent with this call and an}}
\DoxyCodeLine{550   \textcolor{comment}{! integer fraction of time\_interval.}}
\DoxyCodeLine{551   \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{552     n\_max = 1}
\DoxyCodeLine{553     \textcolor{keywordflow}{if} (time\_interval > cs\%dt) n\_max = ceiling(time\_interval/cs\%dt -\/ 0.001)}
\DoxyCodeLine{554     dt = time\_interval / real(n\_max)}
\DoxyCodeLine{555     thermo\_does\_span\_coupling = (cs\%thermo\_spans\_coupling .and. \&}
\DoxyCodeLine{556                                 (cs\%dt\_therm > 1.5*cycle\_time))}
\DoxyCodeLine{557     \textcolor{keywordflow}{if} (thermo\_does\_span\_coupling) \textcolor{keywordflow}{then}}
\DoxyCodeLine{558       \textcolor{comment}{! Set dt\_therm to be an integer multiple of the coupling time step.}}
\DoxyCodeLine{559       dt\_therm = cycle\_time * floor(cs\%dt\_therm / cycle\_time + 0.001)}
\DoxyCodeLine{560       ntstep = floor(dt\_therm/dt + 0.001)}
\DoxyCodeLine{561     \textcolor{keywordflow}{elseif} (.not.do\_thermo) \textcolor{keywordflow}{then}}
\DoxyCodeLine{562       dt\_therm = cs\%dt\_therm}
\DoxyCodeLine{563       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(cycle\_length)) dt\_therm = min(cs\%dt\_therm, us\%s\_to\_T*cycle\_length)}
\DoxyCodeLine{564       \textcolor{comment}{! ntstep is not used.}}
\DoxyCodeLine{565     \textcolor{keywordflow}{else}}
\DoxyCodeLine{566       ntstep = max(1, min(n\_max, floor(cs\%dt\_therm/dt + 0.001)))}
\DoxyCodeLine{567       dt\_therm = dt*ntstep}
\DoxyCodeLine{568 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{569 }
\DoxyCodeLine{570     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(forces\%p\_surf)) p\_surf => forces\%p\_surf}
\DoxyCodeLine{571     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(forces\%p\_surf)) cs\%interp\_p\_surf = .false.}
\DoxyCodeLine{572     cs\%tv\%p\_surf => null()}
\DoxyCodeLine{573     \textcolor{keywordflow}{if} (cs\%use\_p\_surf\_in\_EOS .and. \textcolor{keyword}{associated}(forces\%p\_surf)) cs\%tv\%p\_surf => forces\%p\_surf}
\DoxyCodeLine{574 }
\DoxyCodeLine{575     \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/ Initiate group halo pass of the forcing fields}}
\DoxyCodeLine{576     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass)}
\DoxyCodeLine{577     \textcolor{keyword}{call }create\_group\_pass(pass\_tau\_ustar\_psurf, forces\%taux, forces\%tauy, g\%Domain)}
\DoxyCodeLine{578     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(forces\%ustar)) \&}
\DoxyCodeLine{579       \textcolor{keyword}{call }create\_group\_pass(pass\_tau\_ustar\_psurf, forces\%ustar, g\%Domain)}
\DoxyCodeLine{580     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(forces\%p\_surf)) \&}
\DoxyCodeLine{581       \textcolor{keyword}{call }create\_group\_pass(pass\_tau\_ustar\_psurf, forces\%p\_surf, g\%Domain)}
\DoxyCodeLine{582     \textcolor{keywordflow}{if} (g\%nonblocking\_updates) \textcolor{keywordflow}{then}}
\DoxyCodeLine{583       \textcolor{keyword}{call }start\_group\_pass(pass\_tau\_ustar\_psurf, g\%Domain)}
\DoxyCodeLine{584     \textcolor{keywordflow}{else}}
\DoxyCodeLine{585       \textcolor{keyword}{call }do\_group\_pass(pass\_tau\_ustar\_psurf, g\%Domain)}
\DoxyCodeLine{586 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{587     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass)}
\DoxyCodeLine{588   \textcolor{keywordflow}{else}}
\DoxyCodeLine{589     \textcolor{comment}{! This step only updates the thermodynamics so setting timesteps is simpler.}}
\DoxyCodeLine{590     n\_max = 1}
\DoxyCodeLine{591     \textcolor{keywordflow}{if} ((time\_interval > cs\%dt\_therm) .and. (cs\%dt\_therm > 0.0)) \&}
\DoxyCodeLine{592       n\_max = ceiling(time\_interval/cs\%dt\_therm -\/ 0.001)}
\DoxyCodeLine{593 }
\DoxyCodeLine{594     dt = time\_interval / real(n\_max)}
\DoxyCodeLine{595     dt\_therm = dt ; ntstep = 1}
\DoxyCodeLine{596     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%p\_surf)) p\_surf => fluxes\%p\_surf}
\DoxyCodeLine{597     cs\%tv\%p\_surf => null()}
\DoxyCodeLine{598     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%p\_surf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{599       \textcolor{keywordflow}{if} (cs\%use\_p\_surf\_in\_EOS) cs\%tv\%p\_surf => fluxes\%p\_surf}
\DoxyCodeLine{600 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{601     \textcolor{keywordflow}{if} (cs\%UseWaves) \textcolor{keyword}{call }pass\_var(fluxes\%ustar, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{602 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{603 }
\DoxyCodeLine{604   \textcolor{keywordflow}{if} (therm\_reset) \textcolor{keywordflow}{then}}
\DoxyCodeLine{605     cs\%time\_in\_thermo\_cycle = 0.0}
\DoxyCodeLine{606     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%frazil))        cs\%tv\%frazil(:,:)        = 0.0}
\DoxyCodeLine{607     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%salt\_deficit))  cs\%tv\%salt\_deficit(:,:)  = 0.0}
\DoxyCodeLine{608     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%TempxPmE))      cs\%tv\%TempxPmE(:,:)      = 0.0}
\DoxyCodeLine{609     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%internal\_heat)) cs\%tv\%internal\_heat(:,:) = 0.0}
\DoxyCodeLine{610 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{611 }
\DoxyCodeLine{612   \textcolor{keywordflow}{if} (cycle\_start) \textcolor{keywordflow}{then}}
\DoxyCodeLine{613     cs\%time\_in\_cycle = 0.0}
\DoxyCodeLine{614     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; cs\%ssh\_rint(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{615 }
\DoxyCodeLine{616     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%VarMix)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{617       \textcolor{keyword}{call }enable\_averages(cycle\_time, time\_start + real\_to\_time(us\%T\_to\_s*cycle\_time), cs\%diag)}
\DoxyCodeLine{618       \textcolor{keyword}{call }calc\_resoln\_function(h, cs\%tv, g, gv, us, cs\%VarMix)}
\DoxyCodeLine{619       \textcolor{keyword}{call }calc\_depth\_function(g, cs\%VarMix)}
\DoxyCodeLine{620       \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{621 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{622 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{623 }
\DoxyCodeLine{624   \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{625     \textcolor{keywordflow}{if} (g\%nonblocking\_updates) \&}
\DoxyCodeLine{626       \textcolor{keyword}{call }complete\_group\_pass(pass\_tau\_ustar\_psurf, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{627 }
\DoxyCodeLine{628     \textcolor{keywordflow}{if} (cs\%interp\_p\_surf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{629       \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs\%p\_surf\_end))   \textcolor{keyword}{allocate}(cs\%p\_surf\_end(isd:ied,jsd:jed))}
\DoxyCodeLine{630       \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs\%p\_surf\_begin)) \textcolor{keyword}{allocate}(cs\%p\_surf\_begin(isd:ied,jsd:jed))}
\DoxyCodeLine{631       \textcolor{keywordflow}{if} (.not.cs\%p\_surf\_prev\_set) \textcolor{keywordflow}{then}}
\DoxyCodeLine{632         \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{633           cs\%p\_surf\_prev(i,j) = forces\%p\_surf(i,j)}
\DoxyCodeLine{634 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{635         cs\%p\_surf\_prev\_set = .true.}
\DoxyCodeLine{636 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{637     \textcolor{keywordflow}{else}}
\DoxyCodeLine{638       cs\%p\_surf\_end  => forces\%p\_surf}
\DoxyCodeLine{639 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{640 }
\DoxyCodeLine{641     \textcolor{keywordflow}{if} (cs\%UseWaves) \textcolor{keywordflow}{then}}
\DoxyCodeLine{642       \textcolor{comment}{! Update wave information, which is presently kept static over each call to step\_mom}}
\DoxyCodeLine{643       \textcolor{keyword}{call }enable\_averages(time\_interval, time\_start + real\_to\_time(us\%T\_to\_s*time\_interval), cs\%diag)}
\DoxyCodeLine{644       \textcolor{keyword}{call }update\_stokes\_drift(g, gv, us, waves, h, forces\%ustar)}
\DoxyCodeLine{645       \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{646 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{647   \textcolor{keywordflow}{else} \textcolor{comment}{! not do\_dyn.}}
\DoxyCodeLine{648     \textcolor{keywordflow}{if} (cs\%UseWaves) \& \textcolor{comment}{! Diagnostics are not enabled in this call.}}
\DoxyCodeLine{649       \textcolor{keyword}{call }update\_stokes\_drift(g, gv, us, waves, h, fluxes\%ustar)}
\DoxyCodeLine{650 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{651 }
\DoxyCodeLine{652   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{653     \textcolor{keywordflow}{if} (cycle\_start) \&}
\DoxyCodeLine{654       \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Before steps "}, u, v, h, cs\%uh, cs\%vh, g, gv, us)}
\DoxyCodeLine{655     \textcolor{keywordflow}{if} (cycle\_start) \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Before steps "}, u, v, g)}
\DoxyCodeLine{656     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keyword}{call }mom\_mech\_forcing\_chksum(\textcolor{stringliteral}{"Before steps"}, forces, g, us, haloshift=0)}
\DoxyCodeLine{657     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Before steps "}, forces\%taux, forces\%tauy, g)}
\DoxyCodeLine{658 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{659   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_other)}
\DoxyCodeLine{660 }
\DoxyCodeLine{661   rel\_time = 0.0}
\DoxyCodeLine{662   \textcolor{keywordflow}{do} n=1,n\_max}
\DoxyCodeLine{663     rel\_time = rel\_time + dt \textcolor{comment}{! The relative time at the end of the step.}}
\DoxyCodeLine{664     \textcolor{comment}{! Set the universally visible time to the middle of the time step.}}
\DoxyCodeLine{665     cs\%Time = time\_start + real\_to\_time(us\%T\_to\_s*(rel\_time -\/ 0.5*dt))}
\DoxyCodeLine{666     \textcolor{comment}{! Set the local time to the end of the time step.}}
\DoxyCodeLine{667     time\_local = time\_start + real\_to\_time(us\%T\_to\_s*rel\_time)}
\DoxyCodeLine{668 }
\DoxyCodeLine{669     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"DT cycles (step\_MOM) n="},n)}
\DoxyCodeLine{670 }
\DoxyCodeLine{671     \textcolor{comment}{! Update the vertically extensive diagnostic grids so that they are}}
\DoxyCodeLine{672     \textcolor{comment}{! referenced to the beginning timestep}}
\DoxyCodeLine{673     \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag, update\_intensive = .false., update\_extensive = .true. )}
\DoxyCodeLine{674 }
\DoxyCodeLine{675     \textcolor{comment}{!===========================================================================}}
\DoxyCodeLine{676     \textcolor{comment}{! This is the first place where the diabatic processes and remapping could occur.}}
\DoxyCodeLine{677     \textcolor{keywordflow}{if} (cs\%diabatic\_first .and. (cs\%t\_dyn\_rel\_adv==0.0) .and. do\_thermo) \textcolor{keywordflow}{then} \textcolor{comment}{! do thermodynamics.}}
\DoxyCodeLine{678 }
\DoxyCodeLine{679       \textcolor{keywordflow}{if} (.not.do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{680         dtdia = dt}
\DoxyCodeLine{681       \textcolor{keywordflow}{elseif} (thermo\_does\_span\_coupling) \textcolor{keywordflow}{then}}
\DoxyCodeLine{682         dtdia = dt\_therm}
\DoxyCodeLine{683         \textcolor{keywordflow}{if} ((fluxes\%dt\_buoy\_accum > 0.0) .and. (dtdia > time\_interval) .and. \&}
\DoxyCodeLine{684             (abs(fluxes\%dt\_buoy\_accum -\/ dtdia) > 1e-\/6*dtdia)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{685           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"step\_MOM: Mismatch between long thermodynamic "}//\&}
\DoxyCodeLine{686             \textcolor{stringliteral}{"timestep and time over which buoyancy fluxes have been accumulated."})}
\DoxyCodeLine{687 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{688         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM is not yet set up to have restarts that work "}//\&}
\DoxyCodeLine{689           \textcolor{stringliteral}{"with THERMO\_SPANS\_COUPLING and DIABATIC\_FIRST."})}
\DoxyCodeLine{690       \textcolor{keywordflow}{else}}
\DoxyCodeLine{691         dtdia = dt*min(ntstep,n\_max-\/(n-\/1))}
\DoxyCodeLine{692 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{693 }
\DoxyCodeLine{694       end\_time\_thermo = time\_local}
\DoxyCodeLine{695       \textcolor{keywordflow}{if} (dtdia > dt) \textcolor{keywordflow}{then}}
\DoxyCodeLine{696         \textcolor{comment}{! If necessary, temporarily reset CS\%Time to the center of the period covered}}
\DoxyCodeLine{697         \textcolor{comment}{! by the call to step\_MOM\_thermo, noting that they begin at the same time.}}
\DoxyCodeLine{698         cs\%Time = cs\%Time + real\_to\_time(0.5*us\%T\_to\_s*(dtdia-\/dt))}
\DoxyCodeLine{699         \textcolor{comment}{! The end-\/time of the diagnostic interval needs to be set ahead if there}}
\DoxyCodeLine{700         \textcolor{comment}{! are multiple dynamic time steps worth of thermodynamics applied here.}}
\DoxyCodeLine{701         end\_time\_thermo = time\_local + real\_to\_time(us\%T\_to\_s*(dtdia-\/dt))}
\DoxyCodeLine{702 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{703 }
\DoxyCodeLine{704       \textcolor{comment}{! Apply diabatic forcing, do mixing, and regrid.}}
\DoxyCodeLine{705       \textcolor{keyword}{call }step\_mom\_thermo(cs, g, gv, us, u, v, h, cs\%tv, fluxes, dtdia, \&}
\DoxyCodeLine{706                            end\_time\_thermo, .true., waves=waves)}
\DoxyCodeLine{707       cs\%time\_in\_thermo\_cycle = cs\%time\_in\_thermo\_cycle + dtdia}
\DoxyCodeLine{708 }
\DoxyCodeLine{709       \textcolor{comment}{! The diabatic processes are now ahead of the dynamics by dtdia.}}
\DoxyCodeLine{710       cs\%t\_dyn\_rel\_thermo = -\/dtdia}
\DoxyCodeLine{711       \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished diabatic\_first (step\_MOM)"})}
\DoxyCodeLine{712 }
\DoxyCodeLine{713       \textcolor{keywordflow}{if} (dtdia > dt) \& \textcolor{comment}{! Reset CS\%Time to its previous value.}}
\DoxyCodeLine{714         cs\%Time = time\_start + real\_to\_time(us\%T\_to\_s*(rel\_time -\/ 0.5*dt))}
\DoxyCodeLine{715 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end of block "(CS\%diabatic\_first .and. (CS\%t\_dyn\_rel\_adv==0.0))"}}
\DoxyCodeLine{716 }
\DoxyCodeLine{717     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{718       \textcolor{comment}{! Store pre-\/dynamics thicknesses for proper diagnostic remapping for transports or}}
\DoxyCodeLine{719       \textcolor{comment}{! advective tendencies.  If there are more than one dynamics steps per advective}}
\DoxyCodeLine{720       \textcolor{comment}{! step (i.e DT\_THERM > DT), this needs to be stored at the first dynamics call.}}
\DoxyCodeLine{721       \textcolor{keywordflow}{if} (.not.cs\%preadv\_h\_stored .and. (cs\%t\_dyn\_rel\_adv == 0.)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{722         \textcolor{keyword}{call }diag\_copy\_diag\_to\_storage(cs\%diag\_pre\_dyn, h, cs\%diag)}
\DoxyCodeLine{723         cs\%preadv\_h\_stored = .true.}
\DoxyCodeLine{724 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{725 }
\DoxyCodeLine{726       \textcolor{comment}{! The pre-\/dynamics velocities might be stored for debugging truncations.}}
\DoxyCodeLine{727       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%u\_prev) .and. \textcolor{keyword}{associated}(cs\%v\_prev)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{728         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{729           cs\%u\_prev(i,j,k) = u(i,j,k)}
\DoxyCodeLine{730 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{731         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{732           cs\%v\_prev(i,j,k) = v(i,j,k)}
\DoxyCodeLine{733 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{734 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{735 }
\DoxyCodeLine{736       dt\_therm\_here = dt\_therm}
\DoxyCodeLine{737       \textcolor{keywordflow}{if} (do\_thermo .and. do\_dyn .and. .not.thermo\_does\_span\_coupling) \&}
\DoxyCodeLine{738         dt\_therm\_here = dt*min(ntstep, n\_max-\/n+1)}
\DoxyCodeLine{739 }
\DoxyCodeLine{740       \textcolor{comment}{! Indicate whether the bottom boundary layer properties need to be}}
\DoxyCodeLine{741       \textcolor{comment}{! recalculated, and if so for how long an interval they are valid.}}
\DoxyCodeLine{742       bbl\_time\_int = 0.0}
\DoxyCodeLine{743       \textcolor{keywordflow}{if} (do\_thermo) \textcolor{keywordflow}{then}}
\DoxyCodeLine{744         \textcolor{keywordflow}{if} ((cs\%t\_dyn\_rel\_adv == 0.0) .or. (n==1)) \&}
\DoxyCodeLine{745           bbl\_time\_int = max(dt, min(dt\_therm -\/ cs\%t\_dyn\_rel\_adv, dt*(1+n\_max-\/n)) )}
\DoxyCodeLine{746       \textcolor{keywordflow}{else}}
\DoxyCodeLine{747         \textcolor{keywordflow}{if} ((cs\%t\_dyn\_rel\_adv == 0.0) .or. ((n==1) .and. cycle\_start)) \&}
\DoxyCodeLine{748           bbl\_time\_int = min(dt\_therm, cycle\_time)}
\DoxyCodeLine{749 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{750 }
\DoxyCodeLine{751       \textcolor{keywordflow}{if} (cs\%interp\_p\_surf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{752         wt\_end = real(n) / real(n\_max)}
\DoxyCodeLine{753         wt\_beg = real(n-\/1) / real(n\_max)}
\DoxyCodeLine{754         \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{755           cs\%p\_surf\_end(i,j) = wt\_end * forces\%p\_surf(i,j) + \&}
\DoxyCodeLine{756                           (1.0-\/wt\_end) * cs\%p\_surf\_prev(i,j)}
\DoxyCodeLine{757           cs\%p\_surf\_begin(i,j) = wt\_beg * forces\%p\_surf(i,j) + \&}
\DoxyCodeLine{758                           (1.0-\/wt\_beg) * cs\%p\_surf\_prev(i,j)}
\DoxyCodeLine{759 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{760 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{761 }
\DoxyCodeLine{762       \textcolor{keyword}{call }step\_mom\_dynamics(forces, cs\%p\_surf\_begin, cs\%p\_surf\_end, dt, \&}
\DoxyCodeLine{763                              dt\_therm\_here, bbl\_time\_int, cs, \&}
\DoxyCodeLine{764                              time\_local, waves=waves)}
\DoxyCodeLine{765 }
\DoxyCodeLine{766       \textcolor{comment}{!===========================================================================}}
\DoxyCodeLine{767       \textcolor{comment}{! This is the start of the tracer advection part of the algorithm.}}
\DoxyCodeLine{768 }
\DoxyCodeLine{769       \textcolor{keywordflow}{if} (thermo\_does\_span\_coupling .or. .not.do\_thermo) \textcolor{keywordflow}{then}}
\DoxyCodeLine{770         do\_advection = (cs\%t\_dyn\_rel\_adv + 0.5*dt > dt\_therm)}
\DoxyCodeLine{771       \textcolor{keywordflow}{else}}
\DoxyCodeLine{772         do\_advection = ((mod(n,ntstep) == 0) .or. (n==n\_max))}
\DoxyCodeLine{773 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{774 }
\DoxyCodeLine{775       \textcolor{keywordflow}{if} (do\_advection) \textcolor{keywordflow}{then} \textcolor{comment}{! Do advective transport and lateral tracer mixing.}}
\DoxyCodeLine{776         \textcolor{keyword}{call }step\_mom\_tracer\_dyn(cs, g, gv, us, h, time\_local)}
\DoxyCodeLine{777         \textcolor{keywordflow}{if} (cs\%diabatic\_first .and. abs(cs\%t\_dyn\_rel\_thermo) > 1e-\/6*dt) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{778                 \textcolor{stringliteral}{"step\_MOM: Mismatch between the dynamics and diabatic times "}//\&}
\DoxyCodeLine{779                 \textcolor{stringliteral}{"with DIABATIC\_FIRST."})}
\DoxyCodeLine{780 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{781 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end of (do\_dyn)}}
\DoxyCodeLine{782 }
\DoxyCodeLine{783     \textcolor{comment}{!===========================================================================}}
\DoxyCodeLine{784     \textcolor{comment}{! This is the second place where the diabatic processes and remapping could occur.}}
\DoxyCodeLine{785     \textcolor{keywordflow}{if} ((cs\%t\_dyn\_rel\_adv==0.0) .and. do\_thermo .and. (.not.cs\%diabatic\_first)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{786 }
\DoxyCodeLine{787       dtdia = cs\%t\_dyn\_rel\_thermo}
\DoxyCodeLine{788       \textcolor{comment}{! If the MOM6 dynamic and thermodynamic time stepping is being orchestrated}}
\DoxyCodeLine{789       \textcolor{comment}{! by the coupler, the value of diabatic\_first does not matter.}}
\DoxyCodeLine{790       \textcolor{keywordflow}{if} ((cs\%t\_dyn\_rel\_thermo==0.0) .and. .not.do\_dyn) dtdia = dt}
\DoxyCodeLine{791 }
\DoxyCodeLine{792       \textcolor{keywordflow}{if} (cs\%thermo\_spans\_coupling .and. (cs\%dt\_therm > 1.5*cycle\_time) .and. \&}
\DoxyCodeLine{793           (abs(dt\_therm -\/ dtdia) > 1e-\/6*dt\_therm)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{794         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"step\_MOM: Mismatch between dt\_therm and dtdia "}//\&}
\DoxyCodeLine{795                        \textcolor{stringliteral}{"before call to diabatic."})}
\DoxyCodeLine{796 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{797 }
\DoxyCodeLine{798       \textcolor{comment}{! If necessary, temporarily reset CS\%Time to the center of the period covered}}
\DoxyCodeLine{799       \textcolor{comment}{! by the call to step\_MOM\_thermo, noting that they end at the same time.}}
\DoxyCodeLine{800       \textcolor{keywordflow}{if} (dtdia > dt) cs\%Time = cs\%Time -\/ real\_to\_time(0.5*us\%T\_to\_s*(dtdia-\/dt))}
\DoxyCodeLine{801 }
\DoxyCodeLine{802       \textcolor{comment}{! Apply diabatic forcing, do mixing, and regrid.}}
\DoxyCodeLine{803       \textcolor{keyword}{call }step\_mom\_thermo(cs, g, gv, us, u, v, h, cs\%tv, fluxes, dtdia, \&}
\DoxyCodeLine{804                            time\_local, .false., waves=waves)}
\DoxyCodeLine{805       cs\%time\_in\_thermo\_cycle = cs\%time\_in\_thermo\_cycle + dtdia}
\DoxyCodeLine{806 }
\DoxyCodeLine{807       \textcolor{keywordflow}{if} ((cs\%t\_dyn\_rel\_thermo==0.0) .and. .not.do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{808         \textcolor{comment}{! The diabatic processes are now ahead of the dynamics by dtdia.}}
\DoxyCodeLine{809         cs\%t\_dyn\_rel\_thermo = -\/dtdia}
\DoxyCodeLine{810       \textcolor{keywordflow}{else} \textcolor{comment}{! The diabatic processes and the dynamics are synchronized.}}
\DoxyCodeLine{811         cs\%t\_dyn\_rel\_thermo = 0.0}
\DoxyCodeLine{812 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{813 }
\DoxyCodeLine{814       \textcolor{keywordflow}{if} (dtdia > dt) \& \textcolor{comment}{! Reset CS\%Time to its previous value.}}
\DoxyCodeLine{815         cs\%Time = time\_start + real\_to\_time(us\%T\_to\_s*(rel\_time -\/ 0.5*dt))}
\DoxyCodeLine{816 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{817 }
\DoxyCodeLine{818     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{819       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_dynamics)}
\DoxyCodeLine{820       \textcolor{comment}{! Determining the time-\/average sea surface height is part of the algorithm.}}
\DoxyCodeLine{821       \textcolor{comment}{! This may be eta\_av if Boussinesq, or need to be diagnosed if not.}}
\DoxyCodeLine{822       cs\%time\_in\_cycle = cs\%time\_in\_cycle + dt}
\DoxyCodeLine{823       \textcolor{keyword}{call }find\_eta(h, cs\%tv, g, gv, us, ssh, cs\%eta\_av\_bc, eta\_to\_m=1.0)}
\DoxyCodeLine{824       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{825         cs\%ssh\_rint(i,j) = cs\%ssh\_rint(i,j) + dt*ssh(i,j)}
\DoxyCodeLine{826 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{827       \textcolor{keywordflow}{if} (cs\%IDs\%id\_ssh\_inst > 0) \textcolor{keyword}{call }post\_data(cs\%IDs\%id\_ssh\_inst, ssh, cs\%diag)}
\DoxyCodeLine{828       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_dynamics)}
\DoxyCodeLine{829 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{830 }
\DoxyCodeLine{831     \textcolor{comment}{!===========================================================================}}
\DoxyCodeLine{832     \textcolor{comment}{! Calculate diagnostics at the end of the time step if the state is self-\/consistent.}}
\DoxyCodeLine{833     \textcolor{keywordflow}{if} (mom\_state\_is\_synchronized(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{834     \textcolor{comment}{!\#\#\# Perhaps this should be if (CS\%t\_dyn\_rel\_thermo == 0.0)}}
\DoxyCodeLine{835       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_other) ; \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_diagnostics)}
\DoxyCodeLine{836       \textcolor{comment}{! Diagnostics that require the complete state to be up-\/to-\/date can be calculated.}}
\DoxyCodeLine{837 }
\DoxyCodeLine{838       \textcolor{keyword}{call }enable\_averages(cs\%t\_dyn\_rel\_diag, time\_local, cs\%diag)}
\DoxyCodeLine{839       \textcolor{keyword}{call }calculate\_diagnostic\_fields(u, v, h, cs\%uh, cs\%vh, cs\%tv, cs\%ADp,  \&}
\DoxyCodeLine{840                           cs\%CDp, p\_surf, cs\%t\_dyn\_rel\_diag, cs\%diag\_pre\_sync,\&}
\DoxyCodeLine{841                           g, gv, us, cs\%diagnostics\_CSp)}
\DoxyCodeLine{842       \textcolor{keyword}{call }post\_tracer\_diagnostics\_at\_sync(cs\%Tracer\_reg, h, cs\%diag\_pre\_sync, cs\%diag, g, gv, cs\%t\_dyn\_rel\_diag)}
\DoxyCodeLine{843       \textcolor{keyword}{call }diag\_copy\_diag\_to\_storage(cs\%diag\_pre\_sync, h, cs\%diag)}
\DoxyCodeLine{844       \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished calculate\_diagnostic\_fields (step\_MOM)"})}
\DoxyCodeLine{845       \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{846       cs\%t\_dyn\_rel\_diag = 0.0}
\DoxyCodeLine{847 }
\DoxyCodeLine{848       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_diagnostics) ; \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_other)}
\DoxyCodeLine{849 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{850 }
\DoxyCodeLine{851     \textcolor{keywordflow}{if} (do\_dyn .and. .not.cs\%count\_calls) cs\%nstep\_tot = cs\%nstep\_tot + 1}
\DoxyCodeLine{852     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"DT cycles (step\_MOM)"})}
\DoxyCodeLine{853 }
\DoxyCodeLine{854 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! complete the n loop}}
\DoxyCodeLine{855 }
\DoxyCodeLine{856   \textcolor{keywordflow}{if} (cs\%count\_calls .and. cycle\_start) cs\%nstep\_tot = cs\%nstep\_tot + 1}
\DoxyCodeLine{857 }
\DoxyCodeLine{858   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_other)}
\DoxyCodeLine{859 }
\DoxyCodeLine{860   \textcolor{keywordflow}{if} (cs\%time\_in\_cycle > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{861     i\_wt\_ssh = 1.0/cs\%time\_in\_cycle}
\DoxyCodeLine{862     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{863       ssh(i,j) = cs\%ssh\_rint(i,j)*i\_wt\_ssh}
\DoxyCodeLine{864       cs\%ave\_ssh\_ibc(i,j) = ssh(i,j)}
\DoxyCodeLine{865 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{866     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{867       \textcolor{keyword}{call }adjust\_ssh\_for\_p\_atm(cs\%tv, g, gv, us, cs\%ave\_ssh\_ibc, forces\%p\_surf\_SSH, \&}
\DoxyCodeLine{868                                 cs\%calc\_rho\_for\_sea\_lev)}
\DoxyCodeLine{869     \textcolor{keywordflow}{elseif} (do\_thermo) \textcolor{keywordflow}{then}}
\DoxyCodeLine{870       \textcolor{keyword}{call }adjust\_ssh\_for\_p\_atm(cs\%tv, g, gv, us, cs\%ave\_ssh\_ibc, fluxes\%p\_surf\_SSH, \&}
\DoxyCodeLine{871                                 cs\%calc\_rho\_for\_sea\_lev)}
\DoxyCodeLine{872 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{873 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{874 }
\DoxyCodeLine{875   \textcolor{keywordflow}{if} (do\_dyn .and. cs\%interp\_p\_surf) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{876     cs\%p\_surf\_prev(i,j) = forces\%p\_surf(i,j)}
\DoxyCodeLine{877 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{878 }
\DoxyCodeLine{879   \textcolor{keywordflow}{if} (cs\%ensemble\_ocean) \textcolor{keywordflow}{then}}
\DoxyCodeLine{880     \textcolor{comment}{! update the time for the next analysis step if needed}}
\DoxyCodeLine{881     \textcolor{keyword}{call }set\_analysis\_time(cs\%Time,cs\%odaCS)}
\DoxyCodeLine{882     \textcolor{comment}{! store ensemble vector in odaCS}}
\DoxyCodeLine{883     \textcolor{keyword}{call }set\_prior\_tracer(cs\%Time, g, gv, cs\%h, cs\%tv, cs\%odaCS)}
\DoxyCodeLine{884     \textcolor{comment}{! call DA interface}}
\DoxyCodeLine{885     \textcolor{keyword}{call }oda(cs\%Time,cs\%odaCS)}
\DoxyCodeLine{886 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{887 }
\DoxyCodeLine{888   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"calling extract\_surface\_state (step\_MOM)"})}
\DoxyCodeLine{889   \textcolor{comment}{! NOTE: sfc\_state uses input indexing, since it is also used by drivers.}}
\DoxyCodeLine{890   \textcolor{keyword}{call }extract\_surface\_state(cs, sfc\_state)}
\DoxyCodeLine{891 }
\DoxyCodeLine{892   \textcolor{comment}{! Do diagnostics that only occur at the end of a complete forcing step.}}
\DoxyCodeLine{893   \textcolor{keywordflow}{if} (cycle\_end) \textcolor{keywordflow}{then}}
\DoxyCodeLine{894     \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{895       \textcolor{keyword}{allocate}(sfc\_state\_diag)}
\DoxyCodeLine{896       \textcolor{keyword}{call }rotate\_surface\_state(sfc\_state, g\_in, sfc\_state\_diag, g, turns)}
\DoxyCodeLine{897     \textcolor{keywordflow}{else}}
\DoxyCodeLine{898       sfc\_state\_diag => sfc\_state}
\DoxyCodeLine{899 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{900 }
\DoxyCodeLine{901     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_diagnostics)}
\DoxyCodeLine{902     \textcolor{keywordflow}{if} (cs\%time\_in\_cycle > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{903       \textcolor{keyword}{call }enable\_averages(cs\%time\_in\_cycle, time\_local, cs\%diag)}
\DoxyCodeLine{904       \textcolor{keyword}{call }post\_surface\_dyn\_diags(cs\%sfc\_IDs, g, cs\%diag, sfc\_state\_diag, ssh)}
\DoxyCodeLine{905 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{906     \textcolor{keywordflow}{if} (cs\%time\_in\_thermo\_cycle > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{907       \textcolor{keyword}{call }enable\_averages(cs\%time\_in\_thermo\_cycle, time\_local, cs\%diag)}
\DoxyCodeLine{908       \textcolor{keyword}{call }post\_surface\_thermo\_diags(cs\%sfc\_IDs, g, gv, us, cs\%diag, cs\%time\_in\_thermo\_cycle, \&}
\DoxyCodeLine{909                                      sfc\_state\_diag, cs\%tv, ssh, cs\%ave\_ssh\_ibc)}
\DoxyCodeLine{910 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{911     \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{912     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_diagnostics)}
\DoxyCodeLine{913 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{914 }
\DoxyCodeLine{915   \textcolor{comment}{! Accumulate the surface fluxes for assessing conservation}}
\DoxyCodeLine{916   \textcolor{keywordflow}{if} (do\_thermo .and. fluxes\%fluxes\_used) \&}
\DoxyCodeLine{917     \textcolor{keyword}{call }accumulate\_net\_input(fluxes, sfc\_state, cs\%tv, fluxes\%dt\_buoy\_accum, \&}
\DoxyCodeLine{918                               g, us, cs\%sum\_output\_CSp)}
\DoxyCodeLine{919 }
\DoxyCodeLine{920   \textcolor{keywordflow}{if} (mom\_state\_is\_synchronized(cs)) \&}
\DoxyCodeLine{921     \textcolor{keyword}{call }write\_energy(cs\%u, cs\%v, cs\%h, cs\%tv, time\_local, cs\%nstep\_tot, \&}
\DoxyCodeLine{922                       g, gv, us, cs\%sum\_output\_CSp, cs\%tracer\_flow\_CSp, \&}
\DoxyCodeLine{923                       dt\_forcing=real\_to\_time(us\%T\_to\_s*time\_interval) )}
\DoxyCodeLine{924 }
\DoxyCodeLine{925   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_other)}
\DoxyCodeLine{926 }
\DoxyCodeLine{927   \textcolor{comment}{! De-\/rotate fluxes and copy back to the input, since they can be changed.}}
\DoxyCodeLine{928   \textcolor{keywordflow}{if} (cs\%rotate\_index) \textcolor{keywordflow}{then}}
\DoxyCodeLine{929     \textcolor{keyword}{call }rotate\_forcing(fluxes, fluxes\_in, -\/turns)}
\DoxyCodeLine{930 }
\DoxyCodeLine{931     \textcolor{keyword}{call }deallocate\_mech\_forcing(forces)}
\DoxyCodeLine{932     \textcolor{keyword}{deallocate}(forces)}
\DoxyCodeLine{933 }
\DoxyCodeLine{934     \textcolor{keyword}{call }deallocate\_forcing\_type(fluxes)}
\DoxyCodeLine{935     \textcolor{keyword}{deallocate}(fluxes)}
\DoxyCodeLine{936 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{937 }
\DoxyCodeLine{938   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"step\_MOM()"})}
\DoxyCodeLine{939   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ocean)}
\DoxyCodeLine{940 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}\label{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}} 
\index{mom@{mom}!step\_mom\_dynamics@{step\_mom\_dynamics}}
\index{step\_mom\_dynamics@{step\_mom\_dynamics}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{step\_mom\_dynamics()}{step\_mom\_dynamics()}}
{\footnotesize\ttfamily subroutine mom\+::step\+\_\+mom\+\_\+dynamics (\begin{DoxyParamCaption}\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, dimension(\+:,\+:), pointer}]{p\+\_\+surf\+\_\+begin,  }\item[{real, dimension(\+:,\+:), pointer}]{p\+\_\+surf\+\_\+end,  }\item[{real, intent(in)}]{dt,  }\item[{real, intent(in)}]{dt\+\_\+thermo,  }\item[{real, intent(in)}]{bbl\+\_\+time\+\_\+int,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+local,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Time step the ocean dynamics, including the momentum and continuity equations. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em forces} & A structure with the driving mechanical forces \\
\hline
 & {\em p\+\_\+surf\+\_\+begin} & A pointer (perhaps N\+U\+LL) to the surface pressure at the beginning of this dynamic step, intent in \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
 & {\em p\+\_\+surf\+\_\+end} & A pointer (perhaps N\+U\+LL) to the surface pressure at the end of this dynamic step, intent in \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & time interval covered by this call \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+thermo} & time interval covered by any updates that may span multiple dynamics steps \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em bbl\+\_\+time\+\_\+int} & time interval over which updates to the bottom boundary layer properties will apply \mbox{[}T $\sim$$>$ s\mbox{]}, or zero not to update the properties. \\
\hline
 & {\em cs} & control structure from initialize\+\_\+\+M\+OM \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+local} & End time of a segment, as a time type \\
\hline
 & {\em waves} & Container for wave related parameters; the \\
\hline
\end{DoxyParams}


Definition at line 946 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{946   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{     !< A structure with the driving mechanical forces}}
\DoxyCodeLine{947 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer}     :: p\_surf\_begin\textcolor{comment}{ !< A pointer (perhaps NULL) to the surface}}
\DoxyCodeLine{948 \textcolor{comment}{                                                  !! pressure at the beginning of this dynamic}}
\DoxyCodeLine{949 \textcolor{comment}{                                                  !! step, intent in [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{950 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer}     :: p\_surf\_end\textcolor{comment}{ !< A pointer (perhaps NULL) to the surface}}
\DoxyCodeLine{951 \textcolor{comment}{                                                  !! pressure at the end of this dynamic step,}}
\DoxyCodeLine{952 \textcolor{comment}{                                                  !! intent in [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{953 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{         !< time interval covered by this call [T ~> s].}}
\DoxyCodeLine{954 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}    :: dt\_thermo\textcolor{comment}{  !< time interval covered by any updates that may}}
\DoxyCodeLine{955 \textcolor{comment}{                                                  !! span multiple dynamics steps [T ~> s].}}
\DoxyCodeLine{956 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}    :: bbl\_time\_int\textcolor{comment}{ !< time interval over which updates to the}}
\DoxyCodeLine{957 \textcolor{comment}{                                                  !! bottom boundary layer properties will apply [T ~> s],}}
\DoxyCodeLine{958 \textcolor{comment}{                                                  !! or zero not to update the properties.}}
\DoxyCodeLine{959   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{         !< control structure from initialize\_MOM}}
\DoxyCodeLine{960   \textcolor{keywordtype}{type}(time\_type),    \textcolor{keywordtype}{intent(in)}    :: Time\_local\textcolor{comment}{ !< End time of a segment, as a time type}}
\DoxyCodeLine{961   \textcolor{keywordtype}{type}(wave\_parameters\_CS), \&}
\DoxyCodeLine{962             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{      !< Container for wave related parameters; the}}
\DoxyCodeLine{963 \textcolor{comment}{                                                  !! fields in Waves are intent in here.}}
\DoxyCodeLine{964 }
\DoxyCodeLine{965   \textcolor{comment}{! local variables}}
\DoxyCodeLine{966   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null()  \textcolor{comment}{! pointer to a structure containing}}
\DoxyCodeLine{967                                                    \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{968   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to the vertical grid structure}}
\DoxyCodeLine{969   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{970                                                    \textcolor{comment}{! various unit conversion factors}}
\DoxyCodeLine{971   \textcolor{keywordtype}{type}(MOM\_diag\_IDs), \textcolor{keywordtype}{pointer} :: IDs => null() \textcolor{comment}{! A structure with the diagnostic IDs.}}
\DoxyCodeLine{972 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: \&}
\DoxyCodeLine{973     u => null(), \& \textcolor{comment}{! u : zonal velocity component [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{974     v => null(), \& \textcolor{comment}{! v : meridional velocity component [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{975     h => null()    \textcolor{comment}{! h : layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{976 }
\DoxyCodeLine{977   \textcolor{keywordtype}{logical} :: calc\_dtbt  \textcolor{comment}{! Indicates whether the dynamically adjusted}}
\DoxyCodeLine{978                         \textcolor{comment}{! barotropic time step needs to be updated.}}
\DoxyCodeLine{979   \textcolor{keywordtype}{logical} :: showCallTree}
\DoxyCodeLine{980 }
\DoxyCodeLine{981   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz}
\DoxyCodeLine{982   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{983 }
\DoxyCodeLine{984   g => cs\%G ; gv => cs\%GV ; us => cs\%US ; ids => cs\%IDs}
\DoxyCodeLine{985   is   = g\%isc  ; ie   = g\%iec  ; js   = g\%jsc  ; je   = g\%jec ; nz = g\%ke}
\DoxyCodeLine{986   isq  = g\%IscB ; ieq  = g\%IecB ; jsq  = g\%JscB ; jeq  = g\%JecB}
\DoxyCodeLine{987   isd  = g\%isd  ; ied  = g\%ied  ; jsd  = g\%jsd  ; jed  = g\%jed}
\DoxyCodeLine{988   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{989   u => cs\%u ; v => cs\%v ; h => cs\%h}
\DoxyCodeLine{990   showcalltree = calltree\_showquery()}
\DoxyCodeLine{991 }
\DoxyCodeLine{992   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_dynamics)}
\DoxyCodeLine{993 }
\DoxyCodeLine{994   \textcolor{keywordflow}{if} ((cs\%t\_dyn\_rel\_adv == 0.0) .and. cs\%thickness\_diffuse .and. cs\%thickness\_diffuse\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{995 }
\DoxyCodeLine{996     \textcolor{keyword}{call }enable\_averages(dt\_thermo, time\_local+real\_to\_time(us\%T\_to\_s*(dt\_thermo-\/dt)), cs\%diag)}
\DoxyCodeLine{997     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_thick\_diff)}
\DoxyCodeLine{998     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%VarMix)) \&}
\DoxyCodeLine{999       \textcolor{keyword}{call }calc\_slope\_functions(h, cs\%tv, dt, g, gv, us, cs\%VarMix, obc=cs\%OBC)}
\DoxyCodeLine{1000     \textcolor{keyword}{call }thickness\_diffuse(h, cs\%uhtr, cs\%vhtr, cs\%tv, dt\_thermo, g, gv, us, \&}
\DoxyCodeLine{1001                            cs\%MEKE, cs\%VarMix, cs\%CDp, cs\%thickness\_diffuse\_CSp)}
\DoxyCodeLine{1002     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_thick\_diff)}
\DoxyCodeLine{1003     \textcolor{keyword}{call }pass\_var(h, g\%Domain, clock=id\_clock\_pass, halo=max(2,cs\%cont\_stencil))}
\DoxyCodeLine{1004     \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1005     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished thickness\_diffuse\_first (step\_MOM)"})}
\DoxyCodeLine{1006 }
\DoxyCodeLine{1007     \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}}
\DoxyCodeLine{1008     \textcolor{comment}{! for vertical remapping may need to be regenerated.}}
\DoxyCodeLine{1009     \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{1010 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1011 }
\DoxyCodeLine{1012   \textcolor{comment}{! The bottom boundary layer properties need to be recalculated.}}
\DoxyCodeLine{1013   \textcolor{keywordflow}{if} (bbl\_time\_int > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1014     \textcolor{keyword}{call }enable\_averages(bbl\_time\_int, \&}
\DoxyCodeLine{1015               time\_local + real\_to\_time(us\%T\_to\_s*(bbl\_time\_int-\/dt)), cs\%diag)}
\DoxyCodeLine{1016     \textcolor{comment}{! Calculate the BBL properties and store them inside visc (u,h).}}
\DoxyCodeLine{1017     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_bbl\_visc)}
\DoxyCodeLine{1018     \textcolor{keyword}{call }set\_viscous\_bbl(cs\%u, cs\%v, cs\%h, cs\%tv, cs\%visc, g, gv, us, \&}
\DoxyCodeLine{1019                          cs\%set\_visc\_CSp, symmetrize=.true.)}
\DoxyCodeLine{1020     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_bbl\_visc)}
\DoxyCodeLine{1021     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"done with set\_viscous\_BBL (step\_MOM)"})}
\DoxyCodeLine{1022     \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1023 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1024 }
\DoxyCodeLine{1025 }
\DoxyCodeLine{1026   \textcolor{keywordflow}{if} (cs\%do\_dynamics .and. cs\%split) \textcolor{keywordflow}{then} \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/ start SPLIT}}
\DoxyCodeLine{1027     \textcolor{comment}{! This section uses a split time stepping scheme for the dynamic equations,}}
\DoxyCodeLine{1028     \textcolor{comment}{! basically the stacked shallow water equations with viscosity.}}
\DoxyCodeLine{1029 }
\DoxyCodeLine{1030     calc\_dtbt = .false.}
\DoxyCodeLine{1031     \textcolor{keywordflow}{if} (cs\%dtbt\_reset\_period == 0.0) calc\_dtbt = .true.}
\DoxyCodeLine{1032     \textcolor{keywordflow}{if} (cs\%dtbt\_reset\_period > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1033       \textcolor{keywordflow}{if} (time\_local >= cs\%dtbt\_reset\_time) \textcolor{keywordflow}{then}  \textcolor{comment}{!\#\#\# Change >= to > here.}}
\DoxyCodeLine{1034         calc\_dtbt = .true.}
\DoxyCodeLine{1035         cs\%dtbt\_reset\_time = cs\%dtbt\_reset\_time + cs\%dtbt\_reset\_interval}
\DoxyCodeLine{1036 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1037 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1038 }
\DoxyCodeLine{1039     \textcolor{keyword}{call }step\_mom\_dyn\_split\_rk2(u, v, h, cs\%tv, cs\%visc, time\_local, dt, forces, \&}
\DoxyCodeLine{1040                 p\_surf\_begin, p\_surf\_end, cs\%uh, cs\%vh, cs\%uhtr, cs\%vhtr, \&}
\DoxyCodeLine{1041                 cs\%eta\_av\_bc, g, gv, us, cs\%dyn\_split\_RK2\_CSp, calc\_dtbt, cs\%VarMix, \&}
\DoxyCodeLine{1042                 cs\%MEKE, cs\%thickness\_diffuse\_CSp, waves=waves)}
\DoxyCodeLine{1043     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished step\_MOM\_dyn\_split (step\_MOM)"})}
\DoxyCodeLine{1044 }
\DoxyCodeLine{1045   \textcolor{keywordflow}{elseif} (cs\%do\_dynamics) \textcolor{keywordflow}{then} \textcolor{comment}{! -\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/ not SPLIT}}
\DoxyCodeLine{1046     \textcolor{comment}{!   This section uses an unsplit stepping scheme for the dynamic}}
\DoxyCodeLine{1047     \textcolor{comment}{! equations; basically the stacked shallow water equations with viscosity.}}
\DoxyCodeLine{1048     \textcolor{comment}{! Because the time step is limited by CFL restrictions on the external}}
\DoxyCodeLine{1049     \textcolor{comment}{! gravity waves, the unsplit is usually much less efficient that the split}}
\DoxyCodeLine{1050     \textcolor{comment}{! approaches. But because of its simplicity, the unsplit method is very}}
\DoxyCodeLine{1051     \textcolor{comment}{! useful for debugging purposes.}}
\DoxyCodeLine{1052 }
\DoxyCodeLine{1053     \textcolor{keywordflow}{if} (cs\%use\_RK2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1054       \textcolor{keyword}{call }step\_mom\_dyn\_unsplit\_rk2(u, v, h, cs\%tv, cs\%visc, time\_local, dt, forces, \&}
\DoxyCodeLine{1055                p\_surf\_begin, p\_surf\_end, cs\%uh, cs\%vh, cs\%uhtr, cs\%vhtr, \&}
\DoxyCodeLine{1056                cs\%eta\_av\_bc, g, gv, us, cs\%dyn\_unsplit\_RK2\_CSp, cs\%VarMix, cs\%MEKE)}
\DoxyCodeLine{1057     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1058       \textcolor{keyword}{call }step\_mom\_dyn\_unsplit(u, v, h, cs\%tv, cs\%visc, time\_local, dt, forces, \&}
\DoxyCodeLine{1059                p\_surf\_begin, p\_surf\_end, cs\%uh, cs\%vh, cs\%uhtr, cs\%vhtr, \&}
\DoxyCodeLine{1060                cs\%eta\_av\_bc, g, gv, us, cs\%dyn\_unsplit\_CSp, cs\%VarMix, cs\%MEKE, waves=waves)}
\DoxyCodeLine{1061 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1062     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished step\_MOM\_dyn\_unsplit (step\_MOM)"})}
\DoxyCodeLine{1063 }
\DoxyCodeLine{1064 \textcolor{keywordflow}{  endif} \textcolor{comment}{! -\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/ end SPLIT}}
\DoxyCodeLine{1065 }
\DoxyCodeLine{1066   \textcolor{keywordflow}{if} (cs\%thickness\_diffuse .and. .not.cs\%thickness\_diffuse\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1067     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_thick\_diff)}
\DoxyCodeLine{1068 }
\DoxyCodeLine{1069     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-\/thickness\_diffuse h"}, g\%HI, haloshift=0, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1070 }
\DoxyCodeLine{1071     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%VarMix)) \&}
\DoxyCodeLine{1072       \textcolor{keyword}{call }calc\_slope\_functions(h, cs\%tv, dt, g, gv, us, cs\%VarMix, obc=cs\%OBC)}
\DoxyCodeLine{1073     \textcolor{keyword}{call }thickness\_diffuse(h, cs\%uhtr, cs\%vhtr, cs\%tv, dt, g, gv, us, \&}
\DoxyCodeLine{1074                            cs\%MEKE, cs\%VarMix, cs\%CDp, cs\%thickness\_diffuse\_CSp)}
\DoxyCodeLine{1075 }
\DoxyCodeLine{1076     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Post-\/thickness\_diffuse h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1077     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_thick\_diff)}
\DoxyCodeLine{1078     \textcolor{keyword}{call }pass\_var(h, g\%Domain, clock=id\_clock\_pass, halo=max(2,cs\%cont\_stencil))}
\DoxyCodeLine{1079     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished thickness\_diffuse (step\_MOM)"})}
\DoxyCodeLine{1080 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1081 }
\DoxyCodeLine{1082   \textcolor{comment}{! apply the submesoscale mixed layer restratification parameterization}}
\DoxyCodeLine{1083   \textcolor{keywordflow}{if} (cs\%mixedlayer\_restrat) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1084     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1085       \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-\/mixedlayer\_restrat h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1086       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-\/mixedlayer\_restrat uhtr"}, \&}
\DoxyCodeLine{1087                     cs\%uhtr, cs\%vhtr, g\%HI, haloshift=0, scale=gv\%H\_to\_m*us\%L\_to\_m**2)}
\DoxyCodeLine{1088 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1089     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ml\_restrat)}
\DoxyCodeLine{1090     \textcolor{keyword}{call }mixedlayer\_restrat(h, cs\%uhtr, cs\%vhtr, cs\%tv, forces, dt, cs\%visc\%MLD, \&}
\DoxyCodeLine{1091                             cs\%VarMix, g, gv, us, cs\%mixedlayer\_restrat\_CSp)}
\DoxyCodeLine{1092     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ml\_restrat)}
\DoxyCodeLine{1093     \textcolor{keyword}{call }pass\_var(h, g\%Domain, clock=id\_clock\_pass, halo=max(2,cs\%cont\_stencil))}
\DoxyCodeLine{1094     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1095       \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Post-\/mixedlayer\_restrat h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1096       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post-\/mixedlayer\_restrat [uv]htr"}, \&}
\DoxyCodeLine{1097                     cs\%uhtr, cs\%vhtr, g\%HI, haloshift=0, scale=gv\%H\_to\_m*us\%L\_to\_m**2)}
\DoxyCodeLine{1098 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1099 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1100 }
\DoxyCodeLine{1101   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}}
\DoxyCodeLine{1102   \textcolor{comment}{! for vertical remapping may need to be regenerated.}}
\DoxyCodeLine{1103   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{1104 }
\DoxyCodeLine{1105   \textcolor{keywordflow}{if} (cs\%useMEKE) \textcolor{keyword}{call }step\_forward\_meke(cs\%MEKE, h, cs\%VarMix\%SN\_u, cs\%VarMix\%SN\_v, \&}
\DoxyCodeLine{1106                                          cs\%visc, dt, g, gv, us, cs\%MEKE\_CSp, cs\%uhtr, cs\%vhtr)}
\DoxyCodeLine{1107   \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1108 }
\DoxyCodeLine{1109   \textcolor{comment}{! Advance the dynamics time by dt.}}
\DoxyCodeLine{1110   cs\%t\_dyn\_rel\_adv = cs\%t\_dyn\_rel\_adv + dt}
\DoxyCodeLine{1111   cs\%t\_dyn\_rel\_thermo = cs\%t\_dyn\_rel\_thermo + dt}
\DoxyCodeLine{1112   \textcolor{keywordflow}{if} (abs(cs\%t\_dyn\_rel\_thermo) < 1e-\/6*dt) cs\%t\_dyn\_rel\_thermo = 0.0}
\DoxyCodeLine{1113   cs\%t\_dyn\_rel\_diag = cs\%t\_dyn\_rel\_diag + dt}
\DoxyCodeLine{1114 }
\DoxyCodeLine{1115   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_dynamics)}
\DoxyCodeLine{1116 }
\DoxyCodeLine{1117   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_other) ; \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_diagnostics)}
\DoxyCodeLine{1118   \textcolor{keyword}{call }enable\_averages(dt, time\_local, cs\%diag)}
\DoxyCodeLine{1119   \textcolor{comment}{! These diagnostics are available after every time dynamics step.}}
\DoxyCodeLine{1120   \textcolor{keywordflow}{if} (ids\%id\_u > 0) \textcolor{keyword}{call }post\_data(ids\%id\_u, u, cs\%diag)}
\DoxyCodeLine{1121   \textcolor{keywordflow}{if} (ids\%id\_v > 0) \textcolor{keyword}{call }post\_data(ids\%id\_v, v, cs\%diag)}
\DoxyCodeLine{1122   \textcolor{keywordflow}{if} (ids\%id\_h > 0) \textcolor{keyword}{call }post\_data(ids\%id\_h, h, cs\%diag)}
\DoxyCodeLine{1123   \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1124   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_diagnostics) ; \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_other)}
\DoxyCodeLine{1125 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}\label{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}} 
\index{mom@{mom}!step\_mom\_thermo@{step\_mom\_thermo}}
\index{step\_mom\_thermo@{step\_mom\_thermo}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{step\_mom\_thermo()}{step\_mom\_thermo()}}
{\footnotesize\ttfamily subroutine mom\+::step\+\_\+mom\+\_\+thermo (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), intent(inout)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(inout)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{real, intent(in)}]{dtdia,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+end\+\_\+thermo,  }\item[{logical, intent(in)}]{update\+\_\+\+B\+BL,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



M\+O\+M\+\_\+step\+\_\+thermo orchestrates the thermodynamic time stepping and vertical remapping, via calls to diabatic (or adiabatic) and A\+L\+E\+\_\+main. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Master M\+OM control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & ocean grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em u} & zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em v} & meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & pointers to forcing fields \\
\hline
\mbox{\texttt{ in}}  & {\em dtdia} & The time interval over which to advance \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+end\+\_\+thermo} & End of averaging interval for thermo diags \\
\hline
\mbox{\texttt{ in}}  & {\em update\+\_\+bbl} & If true, calculate the bottom boundary layer properties. \\
\hline
 & {\em waves} & Container for wave related parameters \\
\hline
\end{DoxyParams}


Definition at line 1213 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1213   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{     !< Master MOM control structure}}
\DoxyCodeLine{1214   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< ocean grid structure}}
\DoxyCodeLine{1215   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(inout)} :: GV\textcolor{comment}{     !< ocean vertical grid structure}}
\DoxyCodeLine{1216   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{1217 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1218                             \textcolor{keywordtype}{intent(inout)} :: u\textcolor{comment}{      !< zonal velocity [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{1219 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{1220                             \textcolor{keywordtype}{intent(inout)} :: v\textcolor{comment}{      !< meridional velocity [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{1221 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{1222                             \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{1223   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),    \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{     !< A structure pointing to various thermodynamic variables}}
\DoxyCodeLine{1224   \textcolor{keywordtype}{type}(forcing),            \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< pointers to forcing fields}}
\DoxyCodeLine{1225 \textcolor{keywordtype}{  real},                     \textcolor{keywordtype}{intent(in)}    :: dtdia\textcolor{comment}{  !< The time interval over which to advance [T ~> s]}}
\DoxyCodeLine{1226   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\_end\_thermo\textcolor{comment}{ !< End of averaging interval for thermo diags}}
\DoxyCodeLine{1227   \textcolor{keywordtype}{logical},                  \textcolor{keywordtype}{intent(in)}    :: update\_BBL\textcolor{comment}{ !< If true, calculate the bottom boundary layer properties.}}
\DoxyCodeLine{1228   \textcolor{keywordtype}{type}(wave\_parameters\_CS), \&}
\DoxyCodeLine{1229                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{  !< Container for wave related parameters}}
\DoxyCodeLine{1230 \textcolor{comment}{                                                    !! the fields in Waves are intent in here.}}
\DoxyCodeLine{1231 }
\DoxyCodeLine{1232   \textcolor{keywordtype}{logical} :: use\_ice\_shelf \textcolor{comment}{! Needed for selecting the right ALE interface.}}
\DoxyCodeLine{1233   \textcolor{keywordtype}{logical} :: showCallTree}
\DoxyCodeLine{1234   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_T\_S, pass\_T\_S\_h, pass\_uv\_T\_S\_h}
\DoxyCodeLine{1235   \textcolor{keywordtype}{integer} :: dynamics\_stencil  \textcolor{comment}{! The computational stencil for the calculations}}
\DoxyCodeLine{1236                                \textcolor{comment}{! in the dynamic core.}}
\DoxyCodeLine{1237   \textcolor{keywordtype}{integer} :: halo\_sz \textcolor{comment}{! The size of a halo where data must be valid.}}
\DoxyCodeLine{1238   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{1239 }
\DoxyCodeLine{1240   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{1241   showcalltree = calltree\_showquery()}
\DoxyCodeLine{1242   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"step\_MOM\_thermo(), MOM.F90"})}
\DoxyCodeLine{1243 }
\DoxyCodeLine{1244   use\_ice\_shelf = .false.}
\DoxyCodeLine{1245   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%frac\_shelf\_h)) use\_ice\_shelf = .true.}
\DoxyCodeLine{1246 }
\DoxyCodeLine{1247   \textcolor{keyword}{call }enable\_averages(dtdia, time\_end\_thermo, cs\%diag)}
\DoxyCodeLine{1248 }
\DoxyCodeLine{1249   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%odaCS)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1250     \textcolor{keyword}{call }apply\_oda\_tracer\_increments(us\%T\_to\_s*dtdia,g,tv,h,cs\%odaCS)}
\DoxyCodeLine{1251 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1252 }
\DoxyCodeLine{1253   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%p\_surf) .or. \textcolor{keyword}{associated}(fluxes\%p\_surf\_full)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1254     \textcolor{keyword}{call }extract\_diabatic\_member(cs\%diabatic\_CSp, diabatic\_halo=halo\_sz)}
\DoxyCodeLine{1255     \textcolor{keywordflow}{if} (halo\_sz > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1256       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%p\_surf\_full)) \&}
\DoxyCodeLine{1257         \textcolor{keyword}{call }pass\_var(fluxes\%p\_surf\_full, g\%Domain, \&}
\DoxyCodeLine{1258                       clock=id\_clock\_pass, halo=halo\_sz, complete=.not.\textcolor{keyword}{associated}(fluxes\%p\_surf))}
\DoxyCodeLine{1259       \textcolor{keyword}{call }pass\_var(fluxes\%p\_surf, g\%Domain, clock=id\_clock\_pass, halo=halo\_sz, complete=.true.)}
\DoxyCodeLine{1260 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1261 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1262 }
\DoxyCodeLine{1263   \textcolor{keywordflow}{if} (update\_bbl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1264     \textcolor{comment}{!   Calculate the BBL properties and store them inside visc (u,h).}}
\DoxyCodeLine{1265     \textcolor{comment}{! This is here so that CS\%visc is updated before diabatic() when}}
\DoxyCodeLine{1266     \textcolor{comment}{! DIABATIC\_FIRST=True. Otherwise diabatic() is called after the dynamics}}
\DoxyCodeLine{1267     \textcolor{comment}{! and set\_viscous\_BBL is called as a part of the dynamic stepping.}}
\DoxyCodeLine{1268     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_bbl\_visc)}
\DoxyCodeLine{1269     \textcolor{keyword}{call }set\_viscous\_bbl(u, v, h, tv, cs\%visc, g, gv, us, cs\%set\_visc\_CSp, symmetrize=.true.)}
\DoxyCodeLine{1270     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_bbl\_visc)}
\DoxyCodeLine{1271     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"done with set\_viscous\_BBL (step\_MOM\_thermo)"})}
\DoxyCodeLine{1272 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1273 }
\DoxyCodeLine{1274   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_thermo)}
\DoxyCodeLine{1275   \textcolor{keywordflow}{if} (.not.cs\%adiabatic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1276     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1277       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-\/diabatic [uv]"}, u, v, g\%HI, haloshift=2, scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{1278       \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-\/diabatic h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1279       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-\/diabatic [uv]h"}, cs\%uhtr, cs\%vhtr, g\%HI, \&}
\DoxyCodeLine{1280                     haloshift=0, scale=gv\%H\_to\_m*us\%L\_to\_m**2)}
\DoxyCodeLine{1281     \textcolor{comment}{! call MOM\_state\_chksum("Pre-\/diabatic ", u, v, h, CS\%uhtr, CS\%vhtr, G, GV, vel\_scale=1.0)}}
\DoxyCodeLine{1282       \textcolor{keyword}{call }mom\_thermo\_chksum(\textcolor{stringliteral}{"Pre-\/diabatic "}, tv, g, us, haloshift=0)}
\DoxyCodeLine{1283       \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Pre-\/diabatic "}, u, v, g)}
\DoxyCodeLine{1284       \textcolor{keyword}{call }mom\_forcing\_chksum(\textcolor{stringliteral}{"Pre-\/diabatic"}, fluxes, g, us, haloshift=0)}
\DoxyCodeLine{1285 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1286 }
\DoxyCodeLine{1287     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_diabatic)}
\DoxyCodeLine{1288 }
\DoxyCodeLine{1289     \textcolor{keyword}{call }diabatic(u, v, h, tv, cs\%Hml, fluxes, cs\%visc, cs\%ADp, cs\%CDp, dtdia, \&}
\DoxyCodeLine{1290                   time\_end\_thermo, g, gv, us, cs\%diabatic\_CSp, obc=cs\%OBC, waves=waves)}
\DoxyCodeLine{1291     fluxes\%fluxes\_used = .true.}
\DoxyCodeLine{1292 }
\DoxyCodeLine{1293     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished diabatic (step\_MOM\_thermo)"})}
\DoxyCodeLine{1294 }
\DoxyCodeLine{1295     \textcolor{comment}{! Regridding/remapping is done here, at end of thermodynamics time step}}
\DoxyCodeLine{1296     \textcolor{comment}{! (that may comprise several dynamical time steps)}}
\DoxyCodeLine{1297     \textcolor{comment}{! The routine 'ALE\_main' can be found in 'MOM\_ALE.F90'.}}
\DoxyCodeLine{1298     \textcolor{keywordflow}{if} ( cs\%use\_ALE\_algorithm ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1299       \textcolor{keyword}{call }enable\_averages(dtdia, time\_end\_thermo, cs\%diag)}
\DoxyCodeLine{1300 \textcolor{comment}{!         call pass\_vector(u, v, G\%Domain)}}
\DoxyCodeLine{1301       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass)}
\DoxyCodeLine{1302       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%T)) \&}
\DoxyCodeLine{1303         \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s\_h, tv\%T, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1304       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%S)) \&}
\DoxyCodeLine{1305         \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s\_h, tv\%S, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1306       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s\_h, h, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1307       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s\_h, g\%Domain)}
\DoxyCodeLine{1308       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass)}
\DoxyCodeLine{1309 }
\DoxyCodeLine{1310       \textcolor{keyword}{call }preale\_tracer\_diagnostics(cs\%tracer\_Reg, g, gv)}
\DoxyCodeLine{1311 }
\DoxyCodeLine{1312       \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1313         \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Pre-\/ALE "}, u, v, h, cs\%uh, cs\%vh, g, gv, us)}
\DoxyCodeLine{1314         \textcolor{keyword}{call }hchksum(tv\%T,\textcolor{stringliteral}{"Pre-\/ALE T"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1315         \textcolor{keyword}{call }hchksum(tv\%S,\textcolor{stringliteral}{"Pre-\/ALE S"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1316         \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Pre-\/ALE "}, u, v, g)}
\DoxyCodeLine{1317 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1318       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ale)}
\DoxyCodeLine{1319       \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1320         \textcolor{keyword}{call }ale\_main(g, gv, us, h, u, v, tv, cs\%tracer\_Reg, cs\%ALE\_CSp, cs\%OBC, \&}
\DoxyCodeLine{1321                       dtdia, fluxes\%frac\_shelf\_h)}
\DoxyCodeLine{1322       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1323         \textcolor{keyword}{call }ale\_main(g, gv, us, h, u, v, tv, cs\%tracer\_Reg, cs\%ALE\_CSp, cs\%OBC, dtdia)}
\DoxyCodeLine{1324 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1325 }
\DoxyCodeLine{1326       \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished ALE\_main (step\_MOM\_thermo)"})}
\DoxyCodeLine{1327       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ale)}
\DoxyCodeLine{1328 \textcolor{keywordflow}{    endif}   \textcolor{comment}{! endif for the block "if ( CS\%use\_ALE\_algorithm )"}}
\DoxyCodeLine{1329 }
\DoxyCodeLine{1330     dynamics\_stencil = min(3, g\%Domain\%nihalo, g\%Domain\%njhalo)}
\DoxyCodeLine{1331     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, u, v, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{1332     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%T)) \&}
\DoxyCodeLine{1333       \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, tv\%T, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{1334     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%S)) \&}
\DoxyCodeLine{1335       \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, tv\%S, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{1336     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, h, g\%Domain, halo=dynamics\_stencil)}
\DoxyCodeLine{1337     \textcolor{keyword}{call }do\_group\_pass(pass\_uv\_t\_s\_h, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{1338 }
\DoxyCodeLine{1339     \textcolor{keywordflow}{if} (cs\%debug .and. cs\%use\_ALE\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1340       \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Post-\/ALE "}, u, v, h, cs\%uh, cs\%vh, g, gv, us)}
\DoxyCodeLine{1341       \textcolor{keyword}{call }hchksum(tv\%T, \textcolor{stringliteral}{"Post-\/ALE T"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1342       \textcolor{keyword}{call }hchksum(tv\%S, \textcolor{stringliteral}{"Post-\/ALE S"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1343       \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Post-\/ALE "}, u, v, g)}
\DoxyCodeLine{1344 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1345 }
\DoxyCodeLine{1346     \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}}
\DoxyCodeLine{1347     \textcolor{comment}{! for vertical remapping may need to be regenerated. This needs to}}
\DoxyCodeLine{1348     \textcolor{comment}{! happen after the H update and before the next post\_data.}}
\DoxyCodeLine{1349     \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{1350 }
\DoxyCodeLine{1351     \textcolor{comment}{!\#\#\# Consider moving this up into the if ALE block.}}
\DoxyCodeLine{1352     \textcolor{keyword}{call }postale\_tracer\_diagnostics(cs\%tracer\_Reg, g, gv, cs\%diag, dtdia)}
\DoxyCodeLine{1353 }
\DoxyCodeLine{1354     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1355       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post-\/diabatic u"}, u, v, g\%HI, haloshift=2, scale=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{1356       \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"Post-\/diabatic h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1357       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post-\/diabatic [uv]h"}, cs\%uhtr, cs\%vhtr, g\%HI, \&}
\DoxyCodeLine{1358                     haloshift=0, scale=gv\%H\_to\_m*us\%L\_to\_m**2)}
\DoxyCodeLine{1359     \textcolor{comment}{! call MOM\_state\_chksum("Post-\/diabatic ", u, v, \&}}
\DoxyCodeLine{1360     \textcolor{comment}{!                       h, CS\%uhtr, CS\%vhtr, G, GV, haloshift=1)}}
\DoxyCodeLine{1361       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%T)) \textcolor{keyword}{call }hchksum(tv\%T, \textcolor{stringliteral}{"Post-\/diabatic T"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1362       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%S)) \textcolor{keyword}{call }hchksum(tv\%S, \textcolor{stringliteral}{"Post-\/diabatic S"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1363       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%frazil)) \textcolor{keyword}{call }hchksum(tv\%frazil, \textcolor{stringliteral}{"Post-\/diabatic frazil"}, g\%HI, haloshift=0, \&}
\DoxyCodeLine{1364                                               scale=g\%US\%Q\_to\_J\_kg*g\%US\%RZ\_to\_kg\_m2)}
\DoxyCodeLine{1365       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%salt\_deficit)) \textcolor{keyword}{call }hchksum(tv\%salt\_deficit, \&}
\DoxyCodeLine{1366                                \textcolor{stringliteral}{"Post-\/diabatic salt deficit"}, g\%HI, haloshift=0, scale=us\%RZ\_to\_kg\_m2)}
\DoxyCodeLine{1367     \textcolor{comment}{! call MOM\_thermo\_chksum("Post-\/diabatic ", tv, G, US)}}
\DoxyCodeLine{1368       \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Post-\/diabatic "}, u, v, g)}
\DoxyCodeLine{1369 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1370     \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1371 }
\DoxyCodeLine{1372     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_diabatic)}
\DoxyCodeLine{1373   \textcolor{keywordflow}{else}   \textcolor{comment}{! complement of "if (.not.CS\%adiabatic)"}}
\DoxyCodeLine{1374 }
\DoxyCodeLine{1375     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_adiabatic)}
\DoxyCodeLine{1376     \textcolor{keyword}{call }adiabatic(h, tv, fluxes, dtdia, g, gv, us, cs\%diabatic\_CSp)}
\DoxyCodeLine{1377     fluxes\%fluxes\_used = .true.}
\DoxyCodeLine{1378     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_adiabatic)}
\DoxyCodeLine{1379 }
\DoxyCodeLine{1380     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%T)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1381       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, tv\%T, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1382       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, tv\%S, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1383       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{1384       \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1385         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%T)) \textcolor{keyword}{call }hchksum(tv\%T, \textcolor{stringliteral}{"Post-\/diabatic T"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1386         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%S)) \textcolor{keyword}{call }hchksum(tv\%S, \textcolor{stringliteral}{"Post-\/diabatic S"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1387 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1388 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1389 }
\DoxyCodeLine{1390 \textcolor{keywordflow}{  endif}   \textcolor{comment}{! endif for the block "if (.not.CS\%adiabatic)"}}
\DoxyCodeLine{1391   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_thermo)}
\DoxyCodeLine{1392 }
\DoxyCodeLine{1393   \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1394 }
\DoxyCodeLine{1395   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"step\_MOM\_thermo(), MOM.F90"})}
\DoxyCodeLine{1396 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_a0a07938ed3127b70bab5d466967aec80}\label{namespacemom_a0a07938ed3127b70bab5d466967aec80}} 
\index{mom@{mom}!step\_mom\_tracer\_dyn@{step\_mom\_tracer\_dyn}}
\index{step\_mom\_tracer\_dyn@{step\_mom\_tracer\_dyn}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{step\_mom\_tracer\_dyn()}{step\_mom\_tracer\_dyn()}}
{\footnotesize\ttfamily subroutine mom\+::step\+\_\+mom\+\_\+tracer\+\_\+dyn (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), intent(inout)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+local }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



step\+\_\+\+M\+O\+M\+\_\+tracer\+\_\+dyn does tracer advection and lateral diffusion, bringing the tracers up to date with the changes in state due to the dynamics. Surface sources and sinks and remapping are handled via step\+\_\+\+M\+O\+M\+\_\+thermo. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & layer thicknesses after the transports \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+local} & The model time at the end of the time step. \\
\hline
\end{DoxyParams}


Definition at line 1132 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1132   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{     !< control structure}}
\DoxyCodeLine{1133   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< ocean grid structure}}
\DoxyCodeLine{1134   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< ocean vertical grid structure}}
\DoxyCodeLine{1135   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{1136 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{1137                             \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< layer thicknesses after the transports [H ~> m or kg m-\/2]}}
\DoxyCodeLine{1138   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\_local\textcolor{comment}{ !< The model time at the end}}
\DoxyCodeLine{1139 \textcolor{comment}{                                                    !! of the time step.}}
\DoxyCodeLine{1140   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_T\_S}
\DoxyCodeLine{1141   \textcolor{keywordtype}{integer} :: halo\_sz \textcolor{comment}{! The size of a halo where data must be valid.}}
\DoxyCodeLine{1142   \textcolor{keywordtype}{logical} :: showCallTree}
\DoxyCodeLine{1143   showcalltree = calltree\_showquery()}
\DoxyCodeLine{1144 }
\DoxyCodeLine{1145   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1146     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_other)}
\DoxyCodeLine{1147     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-\/advection h"}, g\%HI, haloshift=1, scale=gv\%H\_to\_m)}
\DoxyCodeLine{1148     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-\/advection uhtr"}, cs\%uhtr, cs\%vhtr, g\%HI, \&}
\DoxyCodeLine{1149                   haloshift=0, scale=gv\%H\_to\_m*us\%L\_to\_m**2)}
\DoxyCodeLine{1150     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%T)) \textcolor{keyword}{call }hchksum(cs\%tv\%T, \textcolor{stringliteral}{"Pre-\/advection T"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1151     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%S)) \textcolor{keyword}{call }hchksum(cs\%tv\%S, \textcolor{stringliteral}{"Pre-\/advection S"}, g\%HI, haloshift=1)}
\DoxyCodeLine{1152     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%frazil)) \textcolor{keyword}{call }hchksum(cs\%tv\%frazil, \textcolor{stringliteral}{"Pre-\/advection frazil"}, g\%HI, haloshift=0, \&}
\DoxyCodeLine{1153                                                scale=g\%US\%Q\_to\_J\_kg*g\%US\%RZ\_to\_kg\_m2)}
\DoxyCodeLine{1154     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%salt\_deficit)) \textcolor{keyword}{call }hchksum(cs\%tv\%salt\_deficit, \&}
\DoxyCodeLine{1155                    \textcolor{stringliteral}{"Pre-\/advection salt deficit"}, g\%HI, haloshift=0, scale=us\%RZ\_to\_kg\_m2)}
\DoxyCodeLine{1156   \textcolor{comment}{! call MOM\_thermo\_chksum("Pre-\/advection ", CS\%tv, G, US)}}
\DoxyCodeLine{1157     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_other)}
\DoxyCodeLine{1158 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1159 }
\DoxyCodeLine{1160   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_thermo) ; \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_tracer)}
\DoxyCodeLine{1161   \textcolor{keyword}{call }enable\_averages(cs\%t\_dyn\_rel\_adv, time\_local, cs\%diag)}
\DoxyCodeLine{1162 }
\DoxyCodeLine{1163   \textcolor{keyword}{call }advect\_tracer(h, cs\%uhtr, cs\%vhtr, cs\%OBC, cs\%t\_dyn\_rel\_adv, g, gv, us, \&}
\DoxyCodeLine{1164                      cs\%tracer\_adv\_CSp, cs\%tracer\_Reg)}
\DoxyCodeLine{1165   \textcolor{keyword}{call }tracer\_hordiff(h, cs\%t\_dyn\_rel\_adv, cs\%MEKE, cs\%VarMix, g, gv, us, \&}
\DoxyCodeLine{1166                       cs\%tracer\_diff\_CSp, cs\%tracer\_Reg, cs\%tv)}
\DoxyCodeLine{1167   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished tracer advection/diffusion (step\_MOM)"})}
\DoxyCodeLine{1168   \textcolor{keyword}{call }update\_segment\_tracer\_reservoirs(g, gv, cs\%uhtr, cs\%vhtr, h, cs\%OBC, \&}
\DoxyCodeLine{1169                      cs\%t\_dyn\_rel\_adv, cs\%tracer\_Reg)}
\DoxyCodeLine{1170   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_tracer) ; \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_thermo)}
\DoxyCodeLine{1171 }
\DoxyCodeLine{1172   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_other) ; \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_diagnostics)}
\DoxyCodeLine{1173   \textcolor{keyword}{call }post\_transport\_diagnostics(g, gv, us, cs\%uhtr, cs\%vhtr, h, cs\%transport\_IDs, \&}
\DoxyCodeLine{1174            cs\%diag\_pre\_dyn, cs\%diag, cs\%t\_dyn\_rel\_adv, cs\%tracer\_reg)}
\DoxyCodeLine{1175   \textcolor{comment}{! Rebuild the remap grids now that we've posted the fields which rely on thicknesses}}
\DoxyCodeLine{1176   \textcolor{comment}{! from before the dynamics calls}}
\DoxyCodeLine{1177   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs\%diag)}
\DoxyCodeLine{1178 }
\DoxyCodeLine{1179   \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1180   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_diagnostics) ; \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_other)}
\DoxyCodeLine{1181 }
\DoxyCodeLine{1182   \textcolor{comment}{! Reset the accumulated transports to 0 and record that the dynamics}}
\DoxyCodeLine{1183   \textcolor{comment}{! and advective times now agree.}}
\DoxyCodeLine{1184   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_thermo) ; \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_tracer)}
\DoxyCodeLine{1185   cs\%uhtr(:,:,:) = 0.0}
\DoxyCodeLine{1186   cs\%vhtr(:,:,:) = 0.0}
\DoxyCodeLine{1187   cs\%t\_dyn\_rel\_adv = 0.0}
\DoxyCodeLine{1188   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_tracer) ; \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_thermo)}
\DoxyCodeLine{1189 }
\DoxyCodeLine{1190   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tv\%T)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1191     \textcolor{keyword}{call }extract\_diabatic\_member(cs\%diabatic\_CSp, diabatic\_halo=halo\_sz)}
\DoxyCodeLine{1192     \textcolor{keywordflow}{if} (halo\_sz > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1193       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs\%tv\%T, g\%Domain, to\_all, halo=halo\_sz)}
\DoxyCodeLine{1194       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs\%tv\%S, g\%Domain, to\_all, halo=halo\_sz)}
\DoxyCodeLine{1195       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{1196     \textcolor{keywordflow}{elseif} (cs\%diabatic\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1197       \textcolor{comment}{! Temperature and salinity need halo updates because they will be used}}
\DoxyCodeLine{1198       \textcolor{comment}{! in the dynamics before they are changed again.}}
\DoxyCodeLine{1199       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs\%tv\%T, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1200       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs\%tv\%S, g\%Domain, to\_all+omit\_corners, halo=1)}
\DoxyCodeLine{1201       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{1202 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1203 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1204 }
\DoxyCodeLine{1205   cs\%preadv\_h\_stored = .false.}
\DoxyCodeLine{1206 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}\label{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}} 
\index{mom@{mom}!step\_offline@{step\_offline}}
\index{step\_offline@{step\_offline}!mom@{mom}}
\doxysubsubsection{\texorpdfstring{step\_offline()}{step\_offline()}}
{\footnotesize\ttfamily subroutine, public mom\+::step\+\_\+offline (\begin{DoxyParamCaption}\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(surface), intent(inout)}]{sfc\+\_\+state,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+start,  }\item[{real, intent(in)}]{time\+\_\+interval,  }\item[{type(\mbox{\hyperlink{structmom_1_1mom__control__struct}{mom\+\_\+control\+\_\+struct}}), pointer}]{CS }\end{DoxyParamCaption})}



step\+\_\+offline is the main driver for running tracers offline in M\+O\+M6. This has been primarily developed with A\+LE configurations in mind. Some work has been done in isopycnal configuration, but the work is very preliminary. Some more detail about this capability along with some of the subroutines called here can be found in tracers/\+M\+O\+M\+\_\+offline\+\_\+control.\+F90 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em forces} & A structure with the driving mechanical forces \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & pointers to forcing fields \\
\hline
\mbox{\texttt{ in,out}}  & {\em sfc\+\_\+state} & surface ocean state \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+start} & starting time of a segment, as a time type \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+interval} & time interval \\
\hline
 & {\em cs} & control structure from initialize\+\_\+\+M\+OM \\
\hline
\end{DoxyParams}


Definition at line 1405 of file M\+O\+M.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1405   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{        !< A structure with the driving mechanical forces}}
\DoxyCodeLine{1406   \textcolor{keywordtype}{type}(forcing),      \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{        !< pointers to forcing fields}}
\DoxyCodeLine{1407   \textcolor{keywordtype}{type}(surface),      \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{     !< surface ocean state}}
\DoxyCodeLine{1408   \textcolor{keywordtype}{type}(time\_type),    \textcolor{keywordtype}{intent(in)}    :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time type}}
\DoxyCodeLine{1409 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}    :: time\_interval\textcolor{comment}{ !< time interval}}
\DoxyCodeLine{1410   \textcolor{keywordtype}{type}(MOM\_control\_struct), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{            !< control structure from initialize\_MOM}}
\DoxyCodeLine{1411 }
\DoxyCodeLine{1412   \textcolor{comment}{! Local pointers}}
\DoxyCodeLine{1413   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{1414                                                       \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{1415   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}}
\DoxyCodeLine{1416                                                       \textcolor{comment}{! about the vertical grid}}
\DoxyCodeLine{1417   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{1418                                                       \textcolor{comment}{! various unit conversion factors}}
\DoxyCodeLine{1419 }
\DoxyCodeLine{1420   \textcolor{keywordtype}{logical} :: first\_iter\textcolor{comment}{    !< True if this is the first time step\_offline has been called in a given interval}}
\DoxyCodeLine{1421   \textcolor{keywordtype}{logical} :: last\_iter\textcolor{comment}{     !< True if this is the last time step\_tracer is to be called in an offline interval}}
\DoxyCodeLine{1422   \textcolor{keywordtype}{logical} :: do\_vertical\textcolor{comment}{   !< If enough time has elapsed, do the diabatic tracer sources/sinks}}
\DoxyCodeLine{1423   \textcolor{keywordtype}{logical} :: adv\_converged\textcolor{comment}{ !< True if all the horizontal fluxes have been used}}
\DoxyCodeLine{1424 }
\DoxyCodeLine{1425 \textcolor{keywordtype}{  real} :: dt\_offline          \textcolor{comment}{! The offline timestep for advection [T ~> s]}}
\DoxyCodeLine{1426 \textcolor{keywordtype}{  real} :: dt\_offline\_vertical \textcolor{comment}{! The offline timestep for vertical fluxes and remapping [T ~> s]}}
\DoxyCodeLine{1427   \textcolor{keywordtype}{logical} :: skip\_diffusion}
\DoxyCodeLine{1428   \textcolor{keywordtype}{integer} :: id\_eta\_diff\_end}
\DoxyCodeLine{1429 }
\DoxyCodeLine{1430   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{pointer} :: accumulated\_time => null()}
\DoxyCodeLine{1431   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{pointer} :: vertical\_time => null()}
\DoxyCodeLine{1432   \textcolor{keywordtype}{integer} :: i,j,k}
\DoxyCodeLine{1433   \textcolor{keywordtype}{integer} :: is, ie, js, je, isd, ied, jsd, jed}
\DoxyCodeLine{1434 }
\DoxyCodeLine{1435   \textcolor{comment}{! 3D pointers}}
\DoxyCodeLine{1436 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: \&}
\DoxyCodeLine{1437     uhtr => null(), vhtr => null(), \&}
\DoxyCodeLine{1438     eatr => null(), ebtr => null(), \&}
\DoxyCodeLine{1439     h\_end => null()}
\DoxyCodeLine{1440 }
\DoxyCodeLine{1441   \textcolor{comment}{! 2D Array for diagnostics}}
\DoxyCodeLine{1442 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G))} :: eta\_pre, eta\_end}
\DoxyCodeLine{1443   \textcolor{keywordtype}{type}(time\_type) :: Time\_end    \textcolor{comment}{! End time of a segment, as a time type}}
\DoxyCodeLine{1444 }
\DoxyCodeLine{1445   \textcolor{comment}{! Grid-\/related pointer assignments}}
\DoxyCodeLine{1446   g => cs\%G ; gv => cs\%GV ; us => cs\%US}
\DoxyCodeLine{1447 }
\DoxyCodeLine{1448   is  = g\%isc  ; ie  = g\%iec  ; js  = g\%jsc  ; je  = g\%jec}
\DoxyCodeLine{1449   isd = g\%isd  ; ied = g\%ied  ; jsd = g\%jsd  ; jed = g\%jed}
\DoxyCodeLine{1450 }
\DoxyCodeLine{1451   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_offline\_tracer)}
\DoxyCodeLine{1452   \textcolor{keyword}{call }extract\_offline\_main(cs\%offline\_CSp, uhtr, vhtr, eatr, ebtr, h\_end, accumulated\_time, \&}
\DoxyCodeLine{1453                             vertical\_time, dt\_offline, dt\_offline\_vertical, skip\_diffusion)}
\DoxyCodeLine{1454   time\_end = increment\_date(time\_start, seconds=floor(time\_interval+0.001))}
\DoxyCodeLine{1455 }
\DoxyCodeLine{1456   \textcolor{keyword}{call }enable\_averaging(time\_interval, time\_end, cs\%diag)}
\DoxyCodeLine{1457 }
\DoxyCodeLine{1458   \textcolor{comment}{! Check to see if this is the first iteration of the offline interval}}
\DoxyCodeLine{1459   \textcolor{keywordflow}{if} (accumulated\_time == real\_to\_time(0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1460     first\_iter = .true.}
\DoxyCodeLine{1461   \textcolor{keywordflow}{else} \textcolor{comment}{! This is probably unnecessary but is used to guard against unwanted behavior}}
\DoxyCodeLine{1462     first\_iter = .false.}
\DoxyCodeLine{1463 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1464 }
\DoxyCodeLine{1465   \textcolor{comment}{! Check to see if vertical tracer functions should be done}}
\DoxyCodeLine{1466   \textcolor{keywordflow}{if} (first\_iter .or. (accumulated\_time >= vertical\_time)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1467     do\_vertical = .true.}
\DoxyCodeLine{1468     vertical\_time = accumulated\_time + real\_to\_time(us\%T\_to\_s*dt\_offline\_vertical)}
\DoxyCodeLine{1469   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1470     do\_vertical = .false.}
\DoxyCodeLine{1471 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1472 }
\DoxyCodeLine{1473   \textcolor{comment}{! Increment the amount of time elapsed since last read and check if it's time to roll around}}
\DoxyCodeLine{1474   accumulated\_time = accumulated\_time + real\_to\_time(time\_interval)}
\DoxyCodeLine{1475 }
\DoxyCodeLine{1476   last\_iter = (accumulated\_time >= real\_to\_time(us\%T\_to\_s*dt\_offline))}
\DoxyCodeLine{1477 }
\DoxyCodeLine{1478   \textcolor{keywordflow}{if} (cs\%use\_ALE\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1479     \textcolor{comment}{! If this is the first iteration in the offline timestep, then we need to read in fields and}}
\DoxyCodeLine{1480     \textcolor{comment}{! perform the main advection.}}
\DoxyCodeLine{1481     \textcolor{keywordflow}{if} (first\_iter) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1482       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Reading in new offline fields"})}
\DoxyCodeLine{1483       \textcolor{comment}{! Read in new transport and other fields}}
\DoxyCodeLine{1484       \textcolor{comment}{! call update\_transport\_from\_files(G, GV, CS\%offline\_CSp, h\_end, eatr, ebtr, uhtr, vhtr, \&}}
\DoxyCodeLine{1485       \textcolor{comment}{!     CS\%tv\%T, CS\%tv\%S, fluxes, CS\%use\_ALE\_algorithm)}}
\DoxyCodeLine{1486       \textcolor{comment}{! call update\_transport\_from\_arrays(CS\%offline\_CSp)}}
\DoxyCodeLine{1487       \textcolor{keyword}{call }update\_offline\_fields(cs\%offline\_CSp, cs\%h, fluxes, cs\%use\_ALE\_algorithm)}
\DoxyCodeLine{1488 }
\DoxyCodeLine{1489       \textcolor{comment}{! Apply any fluxes into the ocean}}
\DoxyCodeLine{1490       \textcolor{keyword}{call }offline\_fw\_fluxes\_into\_ocean(g, gv, cs\%offline\_CSp, fluxes, cs\%h)}
\DoxyCodeLine{1491 }
\DoxyCodeLine{1492       \textcolor{keywordflow}{if} (.not.cs\%diabatic\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1493         \textcolor{keyword}{call }offline\_advection\_ale(fluxes, time\_start, time\_interval, cs\%offline\_CSp, id\_clock\_ale, \&}
\DoxyCodeLine{1494             cs\%h, uhtr, vhtr, converged=adv\_converged)}
\DoxyCodeLine{1495 }
\DoxyCodeLine{1496         \textcolor{comment}{! Redistribute any remaining transport}}
\DoxyCodeLine{1497         \textcolor{keyword}{call }offline\_redistribute\_residual(cs\%offline\_CSp, cs\%h, uhtr, vhtr, adv\_converged)}
\DoxyCodeLine{1498 }
\DoxyCodeLine{1499         \textcolor{comment}{! Perform offline diffusion if requested}}
\DoxyCodeLine{1500         \textcolor{keywordflow}{if} (.not. skip\_diffusion) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1501           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%VarMix)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1502             \textcolor{keyword}{call }pass\_var(cs\%h, g\%Domain)}
\DoxyCodeLine{1503             \textcolor{keyword}{call }calc\_resoln\_function(cs\%h, cs\%tv, g, gv, us, cs\%VarMix)}
\DoxyCodeLine{1504             \textcolor{keyword}{call }calc\_depth\_function(g, cs\%VarMix)}
\DoxyCodeLine{1505             \textcolor{keyword}{call }calc\_slope\_functions(cs\%h, cs\%tv, dt\_offline, g, gv, us, cs\%VarMix, obc=cs\%OBC)}
\DoxyCodeLine{1506 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1507           \textcolor{keyword}{call }tracer\_hordiff(cs\%h, dt\_offline, cs\%MEKE, cs\%VarMix, g, gv, us, \&}
\DoxyCodeLine{1508               cs\%tracer\_diff\_CSp, cs\%tracer\_Reg, cs\%tv)}
\DoxyCodeLine{1509 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1510 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1511 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1512     \textcolor{comment}{! The functions related to column physics of tracers is performed separately in ALE mode}}
\DoxyCodeLine{1513     \textcolor{keywordflow}{if} (do\_vertical) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1514       \textcolor{keyword}{call }offline\_diabatic\_ale(fluxes, time\_start, time\_end, cs\%offline\_CSp, cs\%h, eatr, ebtr)}
\DoxyCodeLine{1515 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1516 }
\DoxyCodeLine{1517     \textcolor{comment}{! Last thing that needs to be done is the final ALE remapping}}
\DoxyCodeLine{1518     \textcolor{keywordflow}{if} (last\_iter) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1519       \textcolor{keywordflow}{if} (cs\%diabatic\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1520         \textcolor{keyword}{call }offline\_advection\_ale(fluxes, time\_start, time\_interval, cs\%offline\_CSp, id\_clock\_ale, \&}
\DoxyCodeLine{1521             cs\%h, uhtr, vhtr, converged=adv\_converged)}
\DoxyCodeLine{1522 }
\DoxyCodeLine{1523         \textcolor{comment}{! Redistribute any remaining transport and perform the remaining advection}}
\DoxyCodeLine{1524         \textcolor{keyword}{call }offline\_redistribute\_residual(cs\%offline\_CSp, cs\%h, uhtr, vhtr, adv\_converged)}
\DoxyCodeLine{1525                 \textcolor{comment}{! Perform offline diffusion if requested}}
\DoxyCodeLine{1526         \textcolor{keywordflow}{if} (.not. skip\_diffusion) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1527           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%VarMix)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1528             \textcolor{keyword}{call }pass\_var(cs\%h, g\%Domain)}
\DoxyCodeLine{1529             \textcolor{keyword}{call }calc\_resoln\_function(cs\%h, cs\%tv, g, gv, us, cs\%VarMix)}
\DoxyCodeLine{1530             \textcolor{keyword}{call }calc\_depth\_function(g, cs\%VarMix)}
\DoxyCodeLine{1531             \textcolor{keyword}{call }calc\_slope\_functions(cs\%h, cs\%tv, dt\_offline, g, gv, us, cs\%VarMix, obc=cs\%OBC)}
\DoxyCodeLine{1532 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1533           \textcolor{keyword}{call }tracer\_hordiff(cs\%h, dt\_offline, cs\%MEKE, cs\%VarMix, g, gv, us, \&}
\DoxyCodeLine{1534               cs\%tracer\_diff\_CSp, cs\%tracer\_Reg, cs\%tv)}
\DoxyCodeLine{1535 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1536 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1537 }
\DoxyCodeLine{1538       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Last iteration of offline interval"})}
\DoxyCodeLine{1539 }
\DoxyCodeLine{1540       \textcolor{comment}{! Apply freshwater fluxes out of the ocean}}
\DoxyCodeLine{1541       \textcolor{keyword}{call }offline\_fw\_fluxes\_out\_ocean(g, gv, cs\%offline\_CSp, fluxes, cs\%h)}
\DoxyCodeLine{1542       \textcolor{comment}{! These diagnostic can be used to identify which grid points did not converge within}}
\DoxyCodeLine{1543       \textcolor{comment}{! the specified number of advection sub iterations}}
\DoxyCodeLine{1544       \textcolor{keyword}{call }post\_offline\_convergence\_diags(cs\%offline\_CSp, cs\%h, h\_end, uhtr, vhtr)}
\DoxyCodeLine{1545 }
\DoxyCodeLine{1546       \textcolor{comment}{! Call ALE one last time to make sure that tracers are remapped onto the layer thicknesses}}
\DoxyCodeLine{1547       \textcolor{comment}{! stored from the forward run}}
\DoxyCodeLine{1548       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ale)}
\DoxyCodeLine{1549       \textcolor{keyword}{call }ale\_offline\_tracer\_final( g, gv, cs\%h, cs\%tv, h\_end, cs\%tracer\_Reg, cs\%ALE\_CSp, cs\%OBC)}
\DoxyCodeLine{1550       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ale)}
\DoxyCodeLine{1551       \textcolor{keyword}{call }pass\_var(cs\%h, g\%Domain)}
\DoxyCodeLine{1552 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1553   \textcolor{keywordflow}{else} \textcolor{comment}{! NON-\/ALE MODE...NOT WELL TESTED}}
\DoxyCodeLine{1554     \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{1555         \textcolor{stringliteral}{"Offline tracer mode in non-\/ALE configuration has not been thoroughly tested"})}
\DoxyCodeLine{1556     \textcolor{comment}{! Note that for the layer mode case, the calls to tracer sources and sinks is embedded in}}
\DoxyCodeLine{1557     \textcolor{comment}{! main\_offline\_advection\_layer. Warning: this may not be appropriate for tracers that}}
\DoxyCodeLine{1558     \textcolor{comment}{! exchange with the atmosphere}}
\DoxyCodeLine{1559     \textcolor{keywordflow}{if} (abs(time\_interval -\/ us\%T\_to\_s*dt\_offline) > 1.0e-\/6) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1560       \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1561           \textcolor{stringliteral}{"For offline tracer mode in a non-\/ALE configuration, dt\_offline must equal time\_interval"})}
\DoxyCodeLine{1562 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1563     \textcolor{keyword}{call }update\_offline\_fields(cs\%offline\_CSp, cs\%h, fluxes, cs\%use\_ALE\_algorithm)}
\DoxyCodeLine{1564     \textcolor{keyword}{call }offline\_advection\_layer(fluxes, time\_start, time\_interval, cs\%offline\_CSp, \&}
\DoxyCodeLine{1565         cs\%h, eatr, ebtr, uhtr, vhtr)}
\DoxyCodeLine{1566     \textcolor{comment}{! Perform offline diffusion if requested}}
\DoxyCodeLine{1567     \textcolor{keywordflow}{if} (.not. skip\_diffusion) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1568       \textcolor{keyword}{call }tracer\_hordiff(h\_end, dt\_offline, cs\%MEKE, cs\%VarMix, g, gv, us, \&}
\DoxyCodeLine{1569                           cs\%tracer\_diff\_CSp, cs\%tracer\_Reg, cs\%tv)}
\DoxyCodeLine{1570 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1571 }
\DoxyCodeLine{1572     cs\%h = h\_end}
\DoxyCodeLine{1573 }
\DoxyCodeLine{1574     \textcolor{keyword}{call }pass\_var(cs\%tv\%T, g\%Domain)}
\DoxyCodeLine{1575     \textcolor{keyword}{call }pass\_var(cs\%tv\%S, g\%Domain)}
\DoxyCodeLine{1576     \textcolor{keyword}{call }pass\_var(cs\%h, g\%Domain)}
\DoxyCodeLine{1577 }
\DoxyCodeLine{1578 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1579 }
\DoxyCodeLine{1580   \textcolor{keyword}{call }adjust\_ssh\_for\_p\_atm(cs\%tv, g, gv, us, cs\%ave\_ssh\_ibc, forces\%p\_surf\_SSH, \&}
\DoxyCodeLine{1581                             cs\%calc\_rho\_for\_sea\_lev)}
\DoxyCodeLine{1582   \textcolor{keyword}{call }extract\_surface\_state(cs, sfc\_state)}
\DoxyCodeLine{1583 }
\DoxyCodeLine{1584   \textcolor{keyword}{call }disable\_averaging(cs\%diag)}
\DoxyCodeLine{1585   \textcolor{keyword}{call }pass\_var(cs\%tv\%T, g\%Domain)}
\DoxyCodeLine{1586   \textcolor{keyword}{call }pass\_var(cs\%tv\%S, g\%Domain)}
\DoxyCodeLine{1587   \textcolor{keyword}{call }pass\_var(cs\%h, g\%Domain)}
\DoxyCodeLine{1588 }
\DoxyCodeLine{1589   fluxes\%fluxes\_used = .true.}
\DoxyCodeLine{1590 }
\DoxyCodeLine{1591   \textcolor{keywordflow}{if} (last\_iter) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1592     accumulated\_time = real\_to\_time(0.0)}
\DoxyCodeLine{1593 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1594 }
\DoxyCodeLine{1595   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_offline\_tracer)}
\DoxyCodeLine{1596 }

\end{DoxyCode}
