\hypertarget{namespacemom__offline__main}{}\section{mom\+\_\+offline\+\_\+main Module Reference}
\label{namespacemom__offline__main}\index{mom\_offline\_main@{mom\_offline\_main}}


\subsection{Detailed Description}
The routines here implement the offline tracer algorithm used in M\+O\+M6. These are called from step\+\_\+offline Some routines called here can be found in the M\+O\+M\+\_\+offline\+\_\+aux module. 

\hypertarget{namespacemom__offline__main_offline_overview}{}\subsection{Offline Tracer Transport in M\+O\+M6}\label{namespacemom__offline__main_offline_overview}
\textquotesingle{}Offline tracer modeling\textquotesingle{} uses physical fields (e.\+g. mass transports and layer thicknesses) saved from a previous integration of the physical model to transport passive tracers. These fields are accumulated or averaged over a period of time (in this test case, 1 day) and used to integrate portions of the M\+O\+M6 code base that handle the 3d advection and diffusion of passive tracers.

The distribution of tracers in the ocean modeled offline should not be expected to match an online simulation. Accumulating transports over more than one online model timestep implicitly assumes homogeneity over that time period and essentially aliases over processes that occur with higher frequency. For example, consider the case of a surface boundary layer with a strong diurnal cycle. An offline simulation with a 1 day timestep, captures the net transport into or out of that layer, but not the exact cycling. This effective aliasing may also complicate online model configurations which strongly-\/eddying regions. In this case, the offline model timestep must be limited to some fraction of the eddy correlation timescale. Lastly, the nonlinear advection scheme which applies limited mass-\/transports over a sequence of iterations means that tracers are not transported along exactly the same path as they are in the online model.

This capability has currently targeted the Baltic\+\_\+\+A\+L\+E\+\_\+z test case, though some work has also been done with the O\+M4 1/2 degree configuration. Work is ongoing to develop recommendations and best practices for investigators seeking to use M\+O\+M6 for offline tracer modeling.\hypertarget{namespacemom__offline__main_offline_technical}{}\subsection{Implementation of offline routine in M\+O\+M6}\label{namespacemom__offline__main_offline_technical}
The subroutine step\+\_\+tracers that coordinates this can be found in \mbox{\hyperlink{MOM_8F90_source}{M\+O\+M.\+F90}} and is only called using the solo ocean driver. This is to avoid issues with coupling to other climate components that may be relying on fluxes from the ocean to be coupled more often than the offline time step. Other routines related to offline tracer modeling can be found in tracers/\+M\+O\+M\+\_\+offline\+\_\+control.\+F90

As can also be seen in the comments for the step\+\_\+tracers subroutine, an offline time step comprises the following steps\+:
\begin{DoxyEnumerate}
\item Using the layer thicknesses and tracer concentrations from the previous timestep, half of the accumulated vertical mixing (eatr and ebtr) is applied in the call to tracer\+\_\+column\+\_\+fns. For tracers whose source/sink terms need dt, this value is set to 1/2 dt\+\_\+offline
\item Half of the accumulated surface freshwater fluxes are applied S\+T\+A\+RT I\+T\+E\+R\+A\+T\+I\+ON
\item Accumulated mass fluxes are used to do horizontal transport. The number of iterations used in advect\+\_\+tracer is limited to 2 (e.\+g x-\/$>$y-\/$>$x-\/$>$y). The remaining mass fluxes are stored for later use and resulting layer thicknesses fed into the next step
\item Tracers and the h-\/grid are regridded and remapped in a call to A\+LE. This allows for layers which might \textquotesingle{}vanish\textquotesingle{} because of horizontal mass transport to be \textquotesingle{}reinflated\textquotesingle{} and essentially allows for the vertical transport of tracers
\item Check that transport is done if the remaining mass fluxes equals 0 or if the max number of iterations has been reached E\+ND I\+T\+E\+R\+A\+T\+I\+ON
\item Repeat steps 1 and 2
\item Redistribute any residual mass fluxes that remain after the advection iterations in a barotropic manner, progressively upward through the water column.
\item Force a remapping to the stored layer thicknesses that correspond to the snapshot of the online model at the end of an accumulation interval
\item Reset T/S and h to their stored snapshotted values to prevent model drift
\end{DoxyEnumerate}\hypertarget{namespacemom__offline__main_offline_evaluation}{}\subsection{Evaluating the utility of an offline tracer model}\label{namespacemom__offline__main_offline_evaluation}
How well an offline tracer model can be used as an alternative to integrating tracers online with the prognostic model must be evaluated for each application. This efficacy may be related to the native coordinate of the online model, to the length of the offline timestep, and to the behavior of the tracer itself.

A framework for formally regression testing the offline capability still needs to be developed. However, as a simple way of testing whether the offline model is nominally behaving as expected, the total inventory of the advection test tracers (tr1, tr2, etc.) should be conserved between time steps except for the last 4 decimal places. As a general guideline, an offline timestep of 5 days or less.\hypertarget{namespacemom__offline__main_offline_parameters}{}\subsection{Runtime parameters for offline tracers}\label{namespacemom__offline__main_offline_parameters}

\begin{DoxyItemize}
\item O\+F\+F\+L\+I\+N\+E\+D\+IR\+: Input directory where the offline fields can be found
\item O\+F\+F\+\_\+\+S\+U\+M\+\_\+\+F\+I\+LE\+: Filename where the accumulated fields can be found (e.\+g. horizontal mass transports)
\item O\+F\+F\+\_\+\+S\+N\+A\+P\+\_\+\+F\+I\+LE\+: Filename where snapshot fields can be found (e.\+g. end of timestep layer thickness)
\item S\+T\+A\+R\+T\+\_\+\+I\+N\+D\+EX\+: Which timelevel of the input files to read first
\item N\+U\+M\+T\+I\+ME\+: How many timelevels to read before \textquotesingle{}looping\textquotesingle{} back to 1
\item F\+I\+E\+L\+D\+S\+\_\+\+A\+R\+E\+\_\+\+O\+F\+F\+S\+ET\+: True if the time-\/averaged fields and snapshot fields are offset by one time level, probably not needed -\/N\+U\+M\+\_\+\+O\+F\+F\+\_\+\+I\+T\+ER\+: Maximum number of iterations to do for the nonlinear advection scheme -\/R\+E\+D\+I\+S\+T\+R\+I\+B\+U\+T\+E\+\_\+\+M\+E\+T\+H\+OD\+: Redistributes any remaining horizontal fluxes throughout the rest of water column. Options are \textquotesingle{}barotropic\textquotesingle{} which "evenly distributes flux throughout the entire water column,\textquotesingle{}upwards\textquotesingle{} which adds the maximum of the remaining flux in each layer above, and \textquotesingle{}none\textquotesingle{} which does no redistribution" 
\end{DoxyItemize}\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the offline transport module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_ae85546d26ceb447742abe3c528cad2d7}{offline\+\_\+advection\+\_\+ale}} (fluxes, Time\+\_\+start, time\+\_\+interval, CS, id\+\_\+clock\+\_\+ale, h\+\_\+pre, uhtr, vhtr, converged)
\begin{DoxyCompactList}\small\item\em 3D advection is done by doing flux-\/limited nonlinear horizontal advection interspersed with an A\+LE regridding/remapping step. The loop in this routine is exited if remaining residual transports are below a runtime-\/specified value or a maximum number of iterations is reached. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a312c47e83e64a6bdf064526f77a8a8ec}{offline\+\_\+redistribute\+\_\+residual}} (CS, h\+\_\+pre, uhtr, vhtr, converged)
\begin{DoxyCompactList}\small\item\em In the case where the main advection routine did not converge, something needs to be done with the remaining transport. Two different ways are offered, \textquotesingle{}barotropic\textquotesingle{} means that the residual is distributed equally throughout the water column. \textquotesingle{}upwards\textquotesingle{} attempts to redistribute the transport in the layers above and will eventually work down the entire water column. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__offline__main_a713ee3448313842b0f07a5a750a01c60}{remaining\+\_\+transport\+\_\+sum}} (CS, uhtr, vhtr)
\begin{DoxyCompactList}\small\item\em Sums any non-\/negligible remaining transport to check for advection convergence. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_aaef35c02f93931567c41ae8bc0544bdd}{offline\+\_\+diabatic\+\_\+ale}} (fluxes, Time\+\_\+start, Time\+\_\+end, CS, h\+\_\+pre, eatr, ebtr)
\begin{DoxyCompactList}\small\item\em The vertical/diabatic driver for offline tracers. First the eatr/ebtr associated with the interpolated vertical diffusivities are calculated and then any tracer column functions are done which can include vertical diffuvities and source/sink terms. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a04d329761570d6d9fbc38589bea929cc}{offline\+\_\+fw\+\_\+fluxes\+\_\+into\+\_\+ocean}} (G, GV, CS, fluxes, h, in\+\_\+flux\+\_\+optional)
\begin{DoxyCompactList}\small\item\em Apply positive freshwater fluxes (into the ocean) and update net\+Mass\+Out with only the negative (out of the ocean) fluxes. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_ad96c09ff7c8f34d9602fd111ec492cfe}{offline\+\_\+fw\+\_\+fluxes\+\_\+out\+\_\+ocean}} (G, GV, CS, fluxes, h, out\+\_\+flux\+\_\+optional)
\begin{DoxyCompactList}\small\item\em Apply negative freshwater fluxes (out of the ocean) \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a887d59c64eb269aad257eacc8cf30444}{offline\+\_\+advection\+\_\+layer}} (fluxes, Time\+\_\+start, time\+\_\+interval, CS, h\+\_\+pre, eatr, ebtr, uhtr, vhtr)
\begin{DoxyCompactList}\small\item\em When in layer mode, 3D horizontal advection using stored mass fluxes must be used. Horizontal advection is done via tracer\+\_\+advect, whereas the vertical component is actually handled by vertdiff in tracer\+\_\+column\+\_\+fns. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a2e59b996b88713928c04f72d57c5a531}{update\+\_\+offline\+\_\+fields}} (CS, h, fluxes, do\+\_\+ale)
\begin{DoxyCompactList}\small\item\em Update fields used in this round of offline transport. First fields are updated from files or from arrays read during initialization. Then if in an A\+L\+E-\/dependent coordinate, regrid/remap fields. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a0adf88ec8f84684573c1bafd91b22cf6}{register\+\_\+diags\+\_\+offline\+\_\+transport}} (Time, diag, CS)
\begin{DoxyCompactList}\small\item\em Initialize additional diagnostics required for offline tracer transport. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_ad773f8f414f53f000cab30ad097aeaab}{post\+\_\+offline\+\_\+convergence\+\_\+diags}} (CS, h\+\_\+off, h\+\_\+end, uhtr, vhtr)
\begin{DoxyCompactList}\small\item\em Posts diagnostics related to offline convergence diagnostics. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a9c797acd29d9ecf43fb1194392b8f2bb}{extract\+\_\+offline\+\_\+main}} (CS, uhtr, vhtr, eatr, ebtr, h\+\_\+end, accumulated\+\_\+time, vertical\+\_\+time, dt\+\_\+offline, dt\+\_\+offline\+\_\+vertical, skip\+\_\+diffusion)
\begin{DoxyCompactList}\small\item\em Extracts members of the offline main control structure. All arguments are optional except the control structure itself. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_aadf3150c45b59adac6e70933971e6f8a}{insert\+\_\+offline\+\_\+main}} (CS, A\+L\+E\+\_\+\+C\+Sp, diabatic\+\_\+\+C\+Sp, diag, O\+BC, tracer\+\_\+adv\+\_\+\+C\+Sp, tracer\+\_\+flow\+\_\+\+C\+Sp, tracer\+\_\+\+Reg, tv, G, GV, x\+\_\+before\+\_\+y, debug)
\begin{DoxyCompactList}\small\item\em Inserts (assigns values to) members of the offline main control structure. All arguments are optional except for the CS itself. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_ae68ac2570f0623013b09714d467ef857}{offline\+\_\+transport\+\_\+init}} (param\+\_\+file, CS, diabatic\+\_\+\+C\+Sp, G, GV, US)
\begin{DoxyCompactList}\small\item\em Initializes the control structure for offline transport and reads in some of the. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__offline__main_abc6fd7e877d8e70014cbad2d4e3f11c5}{read\+\_\+all\+\_\+input}} (CS)
\begin{DoxyCompactList}\small\item\em Coordinates the allocation and reading in all time levels of uh, vh, hend, temp, and salt from files. Used when read\+\_\+all\+\_\+ts\+\_\+uvh. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__main_a853e9fbade83984621d26f51c1a2d651}{offline\+\_\+transport\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Deallocates (if necessary) arrays within the offline control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__offline__main_a9c797acd29d9ecf43fb1194392b8f2bb}\label{namespacemom__offline__main_a9c797acd29d9ecf43fb1194392b8f2bb}} 
\index{mom\_offline\_main@{mom\_offline\_main}!extract\_offline\_main@{extract\_offline\_main}}
\index{extract\_offline\_main@{extract\_offline\_main}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{extract\_offline\_main()}{extract\_offline\_main()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::extract\+\_\+offline\+\_\+main (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), intent(in), target}]{CS,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{uhtr,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{vhtr,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{eatr,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{ebtr,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{h\+\_\+end,  }\item[{type(time\+\_\+type), optional, pointer}]{accumulated\+\_\+time,  }\item[{type(time\+\_\+type), optional, pointer}]{vertical\+\_\+time,  }\item[{real, intent(out), optional}]{dt\+\_\+offline,  }\item[{real, intent(out), optional}]{dt\+\_\+offline\+\_\+vertical,  }\item[{logical, intent(out), optional}]{skip\+\_\+diffusion }\end{DoxyParamCaption})}



Extracts members of the offline main control structure. All arguments are optional except the control structure itself. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Offline control structure \\
\hline
 & {\em uhtr} & Remaining zonal mass transport \mbox{[}H m2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
 & {\em vhtr} & Remaining meridional mass transport \mbox{[}H m2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
 & {\em eatr} & Amount of fluid entrained from the layer above within one time step \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
 & {\em ebtr} & Amount of fluid entrained from the layer below within one time step \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
 & {\em h\+\_\+end} & Thicknesses at the end of offline timestep \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
 & {\em accumulated\+\_\+time} & Length of time accumulated in the current offline interval \\
\hline
 & {\em vertical\+\_\+time} & The next value of accumulate\+\_\+time at which to vertical processes \\
\hline
\mbox{\texttt{ out}}  & {\em dt\+\_\+offline} & Timestep used for offline tracers \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em dt\+\_\+offline\+\_\+vertical} & Timestep used for calls to tracer vertical physics \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em skip\+\_\+diffusion} & Skips horizontal diffusion of tracers \\
\hline
\end{DoxyParams}


Definition at line 1205 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1205   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in   )} :: CS\textcolor{comment}{ !< Offline control structure}}
\DoxyCodeLine{1206   \textcolor{comment}{! Returned optional arguments}}
\DoxyCodeLine{1207 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: uhtr\textcolor{comment}{ !< Remaining zonal mass transport [H m2 ~> m3 or kg]}}
\DoxyCodeLine{1208 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: vhtr\textcolor{comment}{ !< Remaining meridional mass transport [H m2 ~> m3 or kg]}}
\DoxyCodeLine{1209 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: eatr\textcolor{comment}{ !< Amount of fluid entrained from the layer above within}}
\DoxyCodeLine{1210 \textcolor{comment}{                                                          !! one time step [H ~> m or kg m-2]}}
\DoxyCodeLine{1211 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: ebtr\textcolor{comment}{ !< Amount of fluid entrained from the layer below within}}
\DoxyCodeLine{1212 \textcolor{comment}{                                                          !! one time step [H ~> m or kg m-2]}}
\DoxyCodeLine{1213 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: h\_end\textcolor{comment}{ !< Thicknesses at the end of offline timestep}}
\DoxyCodeLine{1214 \textcolor{comment}{                                                          !! [H ~> m or kg m-2]}}
\DoxyCodeLine{1215   \textcolor{keywordtype}{type}(time\_type),        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: accumulated\_time\textcolor{comment}{ !< Length of time accumulated in the}}
\DoxyCodeLine{1216 \textcolor{comment}{                                                          !! current offline interval}}
\DoxyCodeLine{1217   \textcolor{keywordtype}{type}(time\_type),        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: vertical\_time\textcolor{comment}{ !< The next value of accumulate\_time at which to}}
\DoxyCodeLine{1218 \textcolor{comment}{                                                          !! vertical processes}}
\DoxyCodeLine{1219 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: dt\_offline\textcolor{comment}{ !< Timestep used for offline tracers [T ~> s]}}
\DoxyCodeLine{1220 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: dt\_offline\_vertical\textcolor{comment}{ !< Timestep used for calls to tracer}}
\DoxyCodeLine{1221 \textcolor{comment}{                                                          !! vertical physics [T ~> s]}}
\DoxyCodeLine{1222   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(  out)} :: skip\_diffusion\textcolor{comment}{ !< Skips horizontal diffusion of tracers}}
\DoxyCodeLine{1223 }
\DoxyCodeLine{1224   \textcolor{comment}{! Pointers to 3d members}}
\DoxyCodeLine{1225   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhtr)) uhtr => cs\%uhtr}
\DoxyCodeLine{1226   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhtr)) vhtr => cs\%vhtr}
\DoxyCodeLine{1227   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(eatr)) eatr => cs\%eatr}
\DoxyCodeLine{1228   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ebtr)) ebtr => cs\%ebtr}
\DoxyCodeLine{1229   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_end)) h\_end => cs\%h\_end}
\DoxyCodeLine{1230 }
\DoxyCodeLine{1231   \textcolor{comment}{! Pointers to integer members which need to be modified}}
\DoxyCodeLine{1232   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(accumulated\_time)) accumulated\_time => cs\%accumulated\_time}
\DoxyCodeLine{1233   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vertical\_time)) vertical\_time => cs\%vertical\_time}
\DoxyCodeLine{1234 }
\DoxyCodeLine{1235   \textcolor{comment}{! Return value of non-modified integers}}
\DoxyCodeLine{1236   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dt\_offline))  dt\_offline = cs\%dt\_offline}
\DoxyCodeLine{1237   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dt\_offline\_vertical)) dt\_offline\_vertical = cs\%dt\_offline\_vertical}
\DoxyCodeLine{1238   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(skip\_diffusion)) skip\_diffusion = cs\%skip\_diffusion}
\DoxyCodeLine{1239 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_aadf3150c45b59adac6e70933971e6f8a}\label{namespacemom__offline__main_aadf3150c45b59adac6e70933971e6f8a}} 
\index{mom\_offline\_main@{mom\_offline\_main}!insert\_offline\_main@{insert\_offline\_main}}
\index{insert\_offline\_main@{insert\_offline\_main}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{insert\_offline\_main()}{insert\_offline\_main()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::insert\+\_\+offline\+\_\+main (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), intent(inout)}]{CS,  }\item[{type(ale\+\_\+cs), intent(in), optional, target}]{A\+L\+E\+\_\+\+C\+Sp,  }\item[{type(diabatic\+\_\+cs), intent(in), optional, target}]{diabatic\+\_\+\+C\+Sp,  }\item[{type(diag\+\_\+ctrl), intent(in), optional, target}]{diag,  }\item[{type(ocean\+\_\+obc\+\_\+type), intent(in), optional, target}]{O\+BC,  }\item[{type(tracer\+\_\+advect\+\_\+cs), intent(in), optional, target}]{tracer\+\_\+adv\+\_\+\+C\+Sp,  }\item[{type(tracer\+\_\+flow\+\_\+control\+\_\+cs), intent(in), optional, target}]{tracer\+\_\+flow\+\_\+\+C\+Sp,  }\item[{type(tracer\+\_\+registry\+\_\+type), intent(in), optional, target}]{tracer\+\_\+\+Reg,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in), optional, target}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in), optional, target}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in), optional, target}]{GV,  }\item[{logical, intent(in), optional}]{x\+\_\+before\+\_\+y,  }\item[{logical, intent(in), optional}]{debug }\end{DoxyParamCaption})}



Inserts (assigns values to) members of the offline main control structure. All arguments are optional except for the CS itself. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Offline control structure \\
\hline
\mbox{\texttt{ in}}  & {\em ale\+\_\+csp} & A pointer to the A\+LE control structure \\
\hline
\mbox{\texttt{ in}}  & {\em diabatic\+\_\+csp} & A pointer to the diabatic control structure \\
\hline
\mbox{\texttt{ in}}  & {\em diag} & A pointer to the structure that regulates diagnostic output \\
\hline
\mbox{\texttt{ in}}  & {\em obc} & A pointer to the open boundary condition control structure \\
\hline
\mbox{\texttt{ in}}  & {\em tracer\+\_\+adv\+\_\+csp} & A pointer to the tracer advection control structure \\
\hline
\mbox{\texttt{ in}}  & {\em tracer\+\_\+flow\+\_\+csp} & A pointer to the tracer flow control control structure \\
\hline
\mbox{\texttt{ in}}  & {\em tracer\+\_\+reg} & A pointer to the tracer registry \\
\hline
\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 x\+\_\+before\+\_\+y} & Indicates which horizontal direction is advected first \\
\hline
\mbox{\texttt{ in}}  & {\em debug} & If true, write verbose debugging messages \\
\hline
\end{DoxyParams}


Definition at line 1246 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1246   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{  !< Offline control structure}}
\DoxyCodeLine{1247   \textcolor{comment}{! Inserted optional arguments}}
\DoxyCodeLine{1248   \textcolor{keywordtype}{type}(ALE\_CS), \&}
\DoxyCodeLine{1249             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: ALE\_CSp\textcolor{comment}{  !< A pointer to the ALE control structure}}
\DoxyCodeLine{1250   \textcolor{keywordtype}{type}(diabatic\_CS), \&}
\DoxyCodeLine{1251             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: diabatic\_CSp\textcolor{comment}{ !< A pointer to the diabatic control structure}}
\DoxyCodeLine{1252   \textcolor{keywordtype}{type}(diag\_ctrl), \&}
\DoxyCodeLine{1253             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: diag\textcolor{comment}{     !< A pointer to the structure that regulates diagnostic output}}
\DoxyCodeLine{1254   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \&}
\DoxyCodeLine{1255             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: OBC\textcolor{comment}{      !< A pointer to the open boundary condition control structure}}
\DoxyCodeLine{1256   \textcolor{keywordtype}{type}(tracer\_advect\_CS), \&}
\DoxyCodeLine{1257             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: tracer\_adv\_CSp\textcolor{comment}{ !< A pointer to the tracer advection control structure}}
\DoxyCodeLine{1258   \textcolor{keywordtype}{type}(tracer\_flow\_control\_CS), \&}
\DoxyCodeLine{1259             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: tracer\_flow\_CSp\textcolor{comment}{ !< A pointer to the tracer flow control control structure}}
\DoxyCodeLine{1260   \textcolor{keywordtype}{type}(tracer\_registry\_type), \&}
\DoxyCodeLine{1261             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: tracer\_Reg\textcolor{comment}{ !< A pointer to the tracer registry}}
\DoxyCodeLine{1262   \textcolor{keywordtype}{type}(thermo\_var\_ptrs), \&}
\DoxyCodeLine{1263             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: tv\textcolor{comment}{       !< A structure pointing to various thermodynamic variables}}
\DoxyCodeLine{1264   \textcolor{keywordtype}{type}(ocean\_grid\_type), \&}
\DoxyCodeLine{1265             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: G\textcolor{comment}{        !< ocean grid structure}}
\DoxyCodeLine{1266   \textcolor{keywordtype}{type}(verticalGrid\_type), \&}
\DoxyCodeLine{1267             \textcolor{keywordtype}{target}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: GV\textcolor{comment}{       !< ocean vertical grid structure}}
\DoxyCodeLine{1268   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: x\_before\_y\textcolor{comment}{ !< Indicates which horizontal direction is advected first}}
\DoxyCodeLine{1269   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: debug\textcolor{comment}{    !< If true, write verbose debugging messages}}
\DoxyCodeLine{1270 }
\DoxyCodeLine{1271 }
\DoxyCodeLine{1272   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ale\_csp))         cs\%ALE\_CSp => ale\_csp}
\DoxyCodeLine{1273   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(diabatic\_csp))    cs\%diabatic\_CSp => diabatic\_csp}
\DoxyCodeLine{1274   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(diag))            cs\%diag => diag}
\DoxyCodeLine{1275   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc))             cs\%OBC => obc}
\DoxyCodeLine{1276   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tracer\_adv\_csp))  cs\%tracer\_adv\_CSp => tracer\_adv\_csp}
\DoxyCodeLine{1277   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tracer\_flow\_csp)) cs\%tracer\_flow\_CSp => tracer\_flow\_csp}
\DoxyCodeLine{1278   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tracer\_reg))      cs\%tracer\_Reg => tracer\_reg}
\DoxyCodeLine{1279   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tv))              cs\%tv => tv}
\DoxyCodeLine{1280   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(g))               cs\%G => g}
\DoxyCodeLine{1281   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(gv))              cs\%GV => gv}
\DoxyCodeLine{1282   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(x\_before\_y))      cs\%x\_before\_y = x\_before\_y}
\DoxyCodeLine{1283   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(debug))           cs\%debug = debug}
\DoxyCodeLine{1284 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_ae85546d26ceb447742abe3c528cad2d7}\label{namespacemom__offline__main_ae85546d26ceb447742abe3c528cad2d7}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_advection\_ale@{offline\_advection\_ale}}
\index{offline\_advection\_ale@{offline\_advection\_ale}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_advection\_ale()}{offline\_advection\_ale()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+advection\+\_\+ale (\begin{DoxyParamCaption}\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+start,  }\item[{real, intent(in)}]{time\+\_\+interval,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{integer, intent(in)}]{id\+\_\+clock\+\_\+ale,  }\item[{real, dimension( cs\%g \%isd\+: cs\%g \%ied, cs\%g \%jsd\+: cs\%g \%jed, cs\%g \%ke), intent(inout)}]{h\+\_\+pre,  }\item[{real, dimension( cs\%g \%isdb\+: cs\%g \%iedb, cs\%g \%jsd\+: cs\%g \%jed, cs\%g \%ke), intent(inout)}]{uhtr,  }\item[{real, dimension( cs\%g \%isd\+: cs\%g \%ied, cs\%g \%jsdb\+: cs\%g \%jedb, cs\%g \%ke), intent(inout)}]{vhtr,  }\item[{logical, intent(out)}]{converged }\end{DoxyParamCaption})}



3D advection is done by doing flux-\/limited nonlinear horizontal advection interspersed with an A\+LE regridding/remapping step. The loop in this routine is exited if remaining residual transports are below a runtime-\/specified value or a maximum number of iterations is reached. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em fluxes} & pointers to forcing fields \\
\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 for offline module \\
\hline
\mbox{\texttt{ in}}  & {\em id\+\_\+clock\+\_\+ale} & Clock for A\+LE routines \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+pre} & layer thicknesses before advection \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Zonal mass transport \mbox{[}H m2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Meridional mass transport \mbox{[}H m2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em converged} & True if the iterations have converged \\
\hline
\end{DoxyParams}


Definition at line 210 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{210   \textcolor{keywordtype}{type}(forcing),    \textcolor{keywordtype}{intent(inout)}      :: fluxes\textcolor{comment}{        !< pointers to forcing fields}}
\DoxyCodeLine{211   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{intent(in)}         :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time type}}
\DoxyCodeLine{212 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)}         :: time\_interval\textcolor{comment}{ !< time interval}}
\DoxyCodeLine{213   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}  :: CS\textcolor{comment}{            !< control structure for offline module}}
\DoxyCodeLine{214   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(in)}         :: id\_clock\_ALE\textcolor{comment}{  !< Clock for ALE routines}}
\DoxyCodeLine{215 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{216                     \textcolor{keywordtype}{intent(inout)}      :: h\_pre\textcolor{comment}{         !< layer thicknesses before advection}}
\DoxyCodeLine{217 \textcolor{comment}{                                                        !! [H ~> m or kg m-2]}}
\DoxyCodeLine{218 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{219                     \textcolor{keywordtype}{intent(inout)}      :: uhtr\textcolor{comment}{          !< Zonal mass transport [H m2 ~> m3 or kg]}}
\DoxyCodeLine{220 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{221                     \textcolor{keywordtype}{intent(inout)}      :: vhtr\textcolor{comment}{          !< Meridional mass transport [H m2 ~> m3 or kg]}}
\DoxyCodeLine{222   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(  out)}      :: converged\textcolor{comment}{     !< True if the iterations have converged}}
\DoxyCodeLine{223 }
\DoxyCodeLine{224   \textcolor{comment}{! Local pointers}}
\DoxyCodeLine{225   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{226                                                       \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{227   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}}
\DoxyCodeLine{228                                                       \textcolor{comment}{! about the vertical grid}}
\DoxyCodeLine{229   \textcolor{comment}{! Work arrays for mass transports}}
\DoxyCodeLine{230 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}   :: uhtr\_sub}
\DoxyCodeLine{231   \textcolor{comment}{! Meridional mass transports}}
\DoxyCodeLine{232 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}   :: vhtr\_sub}
\DoxyCodeLine{233 }
\DoxyCodeLine{234 \textcolor{keywordtype}{  real} :: prev\_tot\_residual, tot\_residual  \textcolor{comment}{! Used to keep track of how close to convergence we are}}
\DoxyCodeLine{235 }
\DoxyCodeLine{236   \textcolor{comment}{! Variables used to keep track of layer thicknesses at various points in the code}}
\DoxyCodeLine{237 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: \&}
\DoxyCodeLine{238       h\_new, \&}
\DoxyCodeLine{239       h\_vol}
\DoxyCodeLine{240   \textcolor{comment}{! Fields for eta\_diff diagnostic}}
\DoxyCodeLine{241 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G))}         :: eta\_pre, eta\_end}
\DoxyCodeLine{242   \textcolor{keywordtype}{integer}                                        :: niter, iter}
\DoxyCodeLine{243 \textcolor{keywordtype}{  real}                                           :: Inum\_iter}
\DoxyCodeLine{244   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{245   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz}
\DoxyCodeLine{246   \textcolor{keywordtype}{integer} :: isv, iev, jsv, jev \textcolor{comment}{! The valid range of the indices.}}
\DoxyCodeLine{247   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{248   \textcolor{keywordtype}{logical} :: z\_first, x\_before\_y}
\DoxyCodeLine{249 \textcolor{keywordtype}{  real} :: evap\_CFL\_limit  \textcolor{comment}{! Limit on the fraction of the water that can be fluxed out of the}}
\DoxyCodeLine{250                           \textcolor{comment}{! top layer in a timestep [nondim]}}
\DoxyCodeLine{251 \textcolor{keywordtype}{  real} :: minimum\_forcing\_depth \textcolor{comment}{! The smallest depth over which fluxes can be applied [H ~> m or kg m-2]}}
\DoxyCodeLine{252 \textcolor{keywordtype}{  real} :: dt\_iter    \textcolor{comment}{! The timestep to use for each iteration [T ~> s]}}
\DoxyCodeLine{253 }
\DoxyCodeLine{254   \textcolor{keywordtype}{integer} :: nstocks}
\DoxyCodeLine{255 \textcolor{keywordtype}{  real} :: stock\_values(MAX\_FIELDS\_)}
\DoxyCodeLine{256   \textcolor{keywordtype}{character(len=20)} :: debug\_msg}
\DoxyCodeLine{257   \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_offline\_adv)}
\DoxyCodeLine{258 }
\DoxyCodeLine{259   \textcolor{comment}{! Grid-related pointer assignments}}
\DoxyCodeLine{260   g => cs\%G}
\DoxyCodeLine{261   gv => cs\%GV}
\DoxyCodeLine{262 }
\DoxyCodeLine{263   x\_before\_y = cs\%x\_before\_y}
\DoxyCodeLine{264 }
\DoxyCodeLine{265   \textcolor{comment}{! Initialize some shorthand variables from other structures}}
\DoxyCodeLine{266   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{267   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{268   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{269 }
\DoxyCodeLine{270   evap\_cfl\_limit = cs\%evap\_CFL\_limit}
\DoxyCodeLine{271   minimum\_forcing\_depth = cs\%minimum\_forcing\_depth}
\DoxyCodeLine{272 }
\DoxyCodeLine{273   niter = cs\%num\_off\_iter}
\DoxyCodeLine{274   inum\_iter = 1./real(niter)}
\DoxyCodeLine{275   dt\_iter = cs\%dt\_offline*inum\_iter}
\DoxyCodeLine{276 }
\DoxyCodeLine{277   \textcolor{comment}{! Initialize working arrays}}
\DoxyCodeLine{278   h\_new(:,:,:) = 0.0}
\DoxyCodeLine{279   h\_vol(:,:,:) = 0.0}
\DoxyCodeLine{280   uhtr\_sub(:,:,:) = 0.0}
\DoxyCodeLine{281   vhtr\_sub(:,:,:) = 0.0}
\DoxyCodeLine{282 }
\DoxyCodeLine{283   \textcolor{comment}{! converged should only be true if there are no remaining mass fluxes}}
\DoxyCodeLine{284   converged = .false.}
\DoxyCodeLine{285 }
\DoxyCodeLine{286   \textcolor{comment}{! Tracers are transported using the stored mass fluxes. Where possible, operators are Strang-split around}}
\DoxyCodeLine{287   \textcolor{comment}{! the call to}}
\DoxyCodeLine{288   \textcolor{comment}{! 1)  Using the layer thicknesses and tracer concentrations from the previous timestep,}}
\DoxyCodeLine{289   \textcolor{comment}{!     half of the accumulated vertical mixing (eatr and ebtr) is applied in the call to tracer\_column\_fns.}}
\DoxyCodeLine{290   \textcolor{comment}{!     For tracers whose source/sink terms need dt, this value is set to 1/2 dt\_offline}}
\DoxyCodeLine{291   \textcolor{comment}{! 2)  Half of the accumulated surface freshwater fluxes are applied}}
\DoxyCodeLine{292   \textcolor{comment}{!! START ITERATION}}
\DoxyCodeLine{293   \textcolor{comment}{! 3)  Accumulated mass fluxes are used to do horizontal transport. The number of iterations used in}}
\DoxyCodeLine{294   \textcolor{comment}{!     advect\_tracer is limited to 2 (e.g x->y->x->y). The remaining mass fluxes are stored for later use}}
\DoxyCodeLine{295   \textcolor{comment}{!     and resulting layer thicknesses fed into the next step}}
\DoxyCodeLine{296   \textcolor{comment}{! 4)  Tracers and the h-grid are regridded and remapped in a call to ALE. This allows for layers which might}}
\DoxyCodeLine{297   \textcolor{comment}{!     'vanish' because of horizontal mass transport to be 'reinflated'}}
\DoxyCodeLine{298   \textcolor{comment}{! 5)  Check that transport is done if the remaining mass fluxes equals 0 or if the max number of iterations}}
\DoxyCodeLine{299   \textcolor{comment}{!     has been reached}}
\DoxyCodeLine{300   \textcolor{comment}{!! END ITERATION}}
\DoxyCodeLine{301   \textcolor{comment}{! 6)  Repeat steps 1 and 2}}
\DoxyCodeLine{302   \textcolor{comment}{! 7)  Force a remapping to the stored layer thicknesses that correspond to the snapshot of the online model}}
\DoxyCodeLine{303   \textcolor{comment}{! 8)  Reset T/S and h to their stored snapshotted values to prevent model drift}}
\DoxyCodeLine{304 }
\DoxyCodeLine{305   \textcolor{comment}{! Copy over the horizontal mass fluxes from the total mass fluxes}}
\DoxyCodeLine{306   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{307     uhtr\_sub(i,j,k) = uhtr(i,j,k)}
\DoxyCodeLine{308 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{309   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{310     vhtr\_sub(i,j,k) = vhtr(i,j,k)}
\DoxyCodeLine{311 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{312   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{313     h\_new(i,j,k) = h\_pre(i,j,k)}
\DoxyCodeLine{314 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{315 }
\DoxyCodeLine{316   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{317     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre before transport"},g\%HI)}
\DoxyCodeLine{318     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]htr\_sub before transport"}, uhtr\_sub, vhtr\_sub, g\%HI)}
\DoxyCodeLine{319 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{320   tot\_residual = remaining\_transport\_sum(cs, uhtr, vhtr)}
\DoxyCodeLine{321   \textcolor{keywordflow}{if} (cs\%print\_adv\_offline) \textcolor{keywordflow}{then}}
\DoxyCodeLine{322     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'(A,ES24.16)'}) \textcolor{stringliteral}{"Main advection starting transport: "}, tot\_residual}
\DoxyCodeLine{323     \textcolor{keyword}{call }mom\_mesg(mesg)}
\DoxyCodeLine{324 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{325 }
\DoxyCodeLine{326   \textcolor{comment}{! This loop does essentially a flux-limited, nonlinear advection scheme until all mass fluxes}}
\DoxyCodeLine{327   \textcolor{comment}{! are used. ALE is done after the horizontal advection.}}
\DoxyCodeLine{328   \textcolor{keywordflow}{do} iter=1,cs\%num\_off\_iter}
\DoxyCodeLine{329 }
\DoxyCodeLine{330     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{331       h\_vol(i,j,k) = h\_new(i,j,k) * g\%US\%L\_to\_m**2*g\%areaT(i,j)}
\DoxyCodeLine{332       h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{333 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{334 }
\DoxyCodeLine{335     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{336       \textcolor{keyword}{call }hchksum(h\_vol,\textcolor{stringliteral}{"h\_vol before advect"},g\%HI)}
\DoxyCodeLine{337       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]htr\_sub before advect"}, uhtr\_sub, vhtr\_sub, g\%HI)}
\DoxyCodeLine{338       \textcolor{keyword}{write}(debug\_msg, \textcolor{stringliteral}{'(A,I4.4)'}) \textcolor{stringliteral}{'Before advect '}, iter}
\DoxyCodeLine{339       \textcolor{keyword}{call }mom\_tracer\_chkinv(debug\_msg, g, h\_pre, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{340 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{341 }
\DoxyCodeLine{342     \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr\_sub, vhtr\_sub, cs\%OBC, cs\%dt\_offline, g, gv, cs\%US, \&}
\DoxyCodeLine{343         cs\%tracer\_adv\_CSp, cs\%tracer\_Reg, h\_vol, max\_iter\_in=1, \&}
\DoxyCodeLine{344         uhr\_out=uhtr, vhr\_out=vhtr, h\_out=h\_new, x\_first\_in=x\_before\_y)}
\DoxyCodeLine{345 }
\DoxyCodeLine{346     \textcolor{comment}{! Switch the direction every iteration}}
\DoxyCodeLine{347     x\_before\_y = .not. x\_before\_y}
\DoxyCodeLine{348 }
\DoxyCodeLine{349     \textcolor{comment}{! Update the new layer thicknesses after one round of advection has happened}}
\DoxyCodeLine{350     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{351       h\_new(i,j,k) = h\_new(i,j,k) / (g\%US\%L\_to\_m**2*g\%areaT(i,j))}
\DoxyCodeLine{352 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{353 }
\DoxyCodeLine{354     \textcolor{keywordflow}{if} (modulo(iter,cs\%off\_ale\_mod)==0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{355       \textcolor{comment}{! Do ALE remapping/regridding to allow for more advection to occur in the next iteration}}
\DoxyCodeLine{356       \textcolor{keyword}{call }pass\_var(h\_new,g\%Domain)}
\DoxyCodeLine{357       \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{358         \textcolor{keyword}{call }hchksum(h\_new,\textcolor{stringliteral}{"h\_new before ALE"},g\%HI)}
\DoxyCodeLine{359         \textcolor{keyword}{write}(debug\_msg, \textcolor{stringliteral}{'(A,I4.4)'}) \textcolor{stringliteral}{'Before ALE '}, iter}
\DoxyCodeLine{360         \textcolor{keyword}{call }mom\_tracer\_chkinv(debug\_msg, g, h\_new, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{361 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{362       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ale)}
\DoxyCodeLine{363       \textcolor{keyword}{call }ale\_main\_offline(g, gv, h\_new, cs\%tv, cs\%tracer\_Reg, cs\%ALE\_CSp, cs\%OBC, cs\%dt\_offline)}
\DoxyCodeLine{364       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ale)}
\DoxyCodeLine{365 }
\DoxyCodeLine{366       \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{367         \textcolor{keyword}{call }hchksum(h\_new,\textcolor{stringliteral}{"h\_new after ALE"},g\%HI)}
\DoxyCodeLine{368         \textcolor{keyword}{write}(debug\_msg, \textcolor{stringliteral}{'(A,I4.4)'}) \textcolor{stringliteral}{'After ALE '}, iter}
\DoxyCodeLine{369         \textcolor{keyword}{call }mom\_tracer\_chkinv(debug\_msg, g, h\_new, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{370 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{371 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{372 }
\DoxyCodeLine{373     \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{374       uhtr\_sub(i,j,k) = uhtr(i,j,k)}
\DoxyCodeLine{375       vhtr\_sub(i,j,k) = vhtr(i,j,k)}
\DoxyCodeLine{376 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{377     \textcolor{keyword}{call }pass\_var(h\_new, g\%Domain)}
\DoxyCodeLine{378     \textcolor{keyword}{call }pass\_vector(uhtr\_sub,vhtr\_sub,g\%Domain)}
\DoxyCodeLine{379 }
\DoxyCodeLine{380     \textcolor{comment}{! Check for whether we've used up all the advection, or if we need to move on because}}
\DoxyCodeLine{381     \textcolor{comment}{! advection has stalled}}
\DoxyCodeLine{382     tot\_residual = remaining\_transport\_sum(cs, uhtr, vhtr)}
\DoxyCodeLine{383     \textcolor{keywordflow}{if} (cs\%print\_adv\_offline) \textcolor{keywordflow}{then}}
\DoxyCodeLine{384       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'(A,ES24.16)'}) \textcolor{stringliteral}{"Main advection remaining transport: "}, tot\_residual}
\DoxyCodeLine{385       \textcolor{keyword}{call }mom\_mesg(mesg)}
\DoxyCodeLine{386 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{387     \textcolor{comment}{! If all the mass transports have been used u, then quit}}
\DoxyCodeLine{388     \textcolor{keywordflow}{if} (tot\_residual == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{389       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"Converged after iteration "}, iter}
\DoxyCodeLine{390       \textcolor{keyword}{call }mom\_mesg(mesg)}
\DoxyCodeLine{391       converged = .true.}
\DoxyCodeLine{392       \textcolor{keywordflow}{exit}}
\DoxyCodeLine{393 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{394     \textcolor{comment}{! If advection has stalled or the remaining residual is less than a specified amount, quit}}
\DoxyCodeLine{395     \textcolor{keywordflow}{if} ( (tot\_residual == prev\_tot\_residual) .or. (tot\_residual<cs\%min\_residual) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{396       converged = .false.}
\DoxyCodeLine{397       \textcolor{keywordflow}{exit}}
\DoxyCodeLine{398 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{399 }
\DoxyCodeLine{400     prev\_tot\_residual = tot\_residual}
\DoxyCodeLine{401 }
\DoxyCodeLine{402 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{403 }
\DoxyCodeLine{404   \textcolor{comment}{! Make sure that uhtr and vhtr halos are updated}}
\DoxyCodeLine{405   h\_pre(:,:,:) = h\_new(:,:,:)}
\DoxyCodeLine{406   \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g\%Domain)}
\DoxyCodeLine{407 }
\DoxyCodeLine{408   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{409     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h after offline\_advection\_ale"},g\%HI)}
\DoxyCodeLine{410     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]htr after offline\_advection\_ale"}, uhtr, vhtr, g\%HI)}
\DoxyCodeLine{411     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"After offline\_advection\_ale"}, g, h\_pre, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{412 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{413 }
\DoxyCodeLine{414   \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_offline\_adv)}
\DoxyCodeLine{415 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a887d59c64eb269aad257eacc8cf30444}\label{namespacemom__offline__main_a887d59c64eb269aad257eacc8cf30444}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_advection\_layer@{offline\_advection\_layer}}
\index{offline\_advection\_layer@{offline\_advection\_layer}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_advection\_layer()}{offline\_advection\_layer()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+advection\+\_\+layer (\begin{DoxyParamCaption}\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+start,  }\item[{real, intent(in)}]{time\+\_\+interval,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{h\+\_\+pre,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{eatr,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{ebtr,  }\item[{real, dimension(szib\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(cs\%g),szjb\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{vhtr }\end{DoxyParamCaption})}



When in layer mode, 3D horizontal advection using stored mass fluxes must be used. Horizontal advection is done via tracer\+\_\+advect, whereas the vertical component is actually handled by vertdiff in tracer\+\_\+column\+\_\+fns. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em fluxes} & pointers to forcing fields \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+start} & starting time of a segment, as a time type \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+interval} & Offline transport time interval \\
\hline
 & {\em cs} & Control structure for offline module \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+pre} & layer thicknesses before advection \\
\hline
\mbox{\texttt{ in,out}}  & {\em eatr} & Entrainment from layer above \\
\hline
\mbox{\texttt{ in,out}}  & {\em ebtr} & Entrainment from layer below \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Zonal mass transport \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Meridional mass transport \\
\hline
\end{DoxyParams}


Definition at line 846 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{846   \textcolor{keywordtype}{type}(forcing),              \textcolor{keywordtype}{intent(inout)}    :: fluxes\textcolor{comment}{        !< pointers to forcing fields}}
\DoxyCodeLine{847   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{intent(in)}       :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time type}}
\DoxyCodeLine{848 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in)}       :: time\_interval\textcolor{comment}{ !< Offline transport time interval}}
\DoxyCodeLine{849   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}          :: CS\textcolor{comment}{            !< Control structure for offline module}}
\DoxyCodeLine{850 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))},  \textcolor{keywordtype}{intent(inout)} :: h\_pre\textcolor{comment}{ !< layer thicknesses before advection}}
\DoxyCodeLine{851 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))},  \textcolor{keywordtype}{intent(inout)} :: eatr\textcolor{comment}{ !< Entrainment from layer above}}
\DoxyCodeLine{852 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))},  \textcolor{keywordtype}{intent(inout)} :: ebtr\textcolor{comment}{ !< Entrainment from layer below}}
\DoxyCodeLine{853 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{  !< Zonal mass transport}}
\DoxyCodeLine{854 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{  !< Meridional mass transport}}
\DoxyCodeLine{855   \textcolor{comment}{! Local pointers}}
\DoxyCodeLine{856   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{857                                                       \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{858   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}}
\DoxyCodeLine{859                                                       \textcolor{comment}{! about the vertical grid}}
\DoxyCodeLine{860   \textcolor{comment}{! Remaining zonal mass transports}}
\DoxyCodeLine{861 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}   :: uhtr\_sub}
\DoxyCodeLine{862   \textcolor{comment}{! Remaining meridional mass transports}}
\DoxyCodeLine{863 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}   :: vhtr\_sub}
\DoxyCodeLine{864 }
\DoxyCodeLine{865 \textcolor{keywordtype}{  real} :: sum\_abs\_fluxes, sum\_u, sum\_v  \textcolor{comment}{! Used to keep track of how close to convergence we are}}
\DoxyCodeLine{866 \textcolor{keywordtype}{  real} :: dt\_offline}
\DoxyCodeLine{867 }
\DoxyCodeLine{868   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{869   \textcolor{comment}{! Vertical diffusion related variables}}
\DoxyCodeLine{870 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: \&}
\DoxyCodeLine{871       eatr\_sub, \&}
\DoxyCodeLine{872       ebtr\_sub}
\DoxyCodeLine{873   \textcolor{comment}{! Variables used to keep track of layer thicknesses at various points in the code}}
\DoxyCodeLine{874 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: \&}
\DoxyCodeLine{875       h\_new, \&}
\DoxyCodeLine{876       h\_vol}
\DoxyCodeLine{877   \textcolor{comment}{! Work arrays for temperature and salinity}}
\DoxyCodeLine{878 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: \&}
\DoxyCodeLine{879       temp\_old, salt\_old, \&}
\DoxyCodeLine{880       temp\_mean, salt\_mean, \&}
\DoxyCodeLine{881       zero\_3dh     \textcolor{comment}{!}}
\DoxyCodeLine{882   \textcolor{keywordtype}{integer} :: niter, iter}
\DoxyCodeLine{883 \textcolor{keywordtype}{  real}    :: Inum\_iter}
\DoxyCodeLine{884 \textcolor{keywordtype}{  real}    :: dt\_iter  \textcolor{comment}{! The timestep of each iteration [T ~> s]}}
\DoxyCodeLine{885   \textcolor{keywordtype}{logical} :: converged}
\DoxyCodeLine{886   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{887   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz}
\DoxyCodeLine{888   \textcolor{keywordtype}{integer} :: isv, iev, jsv, jev \textcolor{comment}{! The valid range of the indices.}}
\DoxyCodeLine{889   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{890   \textcolor{keywordtype}{logical} :: z\_first, x\_before\_y}
\DoxyCodeLine{891 }
\DoxyCodeLine{892   g => cs\%G ; gv => cs\%GV}
\DoxyCodeLine{893   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{894   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{895   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{896 }
\DoxyCodeLine{897   dt\_iter = cs\%US\%s\_to\_T * time\_interval / real(max(1, cs\%num\_off\_iter))}
\DoxyCodeLine{898 }
\DoxyCodeLine{899   \textcolor{keywordflow}{do} iter=1,cs\%num\_off\_iter}
\DoxyCodeLine{900 }
\DoxyCodeLine{901     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1}
\DoxyCodeLine{902       eatr\_sub(i,j,k) = eatr(i,j,k)}
\DoxyCodeLine{903       ebtr\_sub(i,j,k) = ebtr(i,j,k)}
\DoxyCodeLine{904 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{905 }
\DoxyCodeLine{906     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ie+1}
\DoxyCodeLine{907       uhtr\_sub(i,j,k) = uhtr(i,j,k)}
\DoxyCodeLine{908 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{909 }
\DoxyCodeLine{910     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-2,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1}
\DoxyCodeLine{911       vhtr\_sub(i,j,k) = vhtr(i,j,k)}
\DoxyCodeLine{912 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{913 }
\DoxyCodeLine{914 }
\DoxyCodeLine{915     \textcolor{comment}{! Calculate 3d mass transports to be used in this iteration}}
\DoxyCodeLine{916     \textcolor{keyword}{call }limit\_mass\_flux\_3d(g, gv, uhtr\_sub, vhtr\_sub, eatr\_sub, ebtr\_sub, h\_pre)}
\DoxyCodeLine{917 }
\DoxyCodeLine{918     \textcolor{keywordflow}{if} (z\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{919       \textcolor{comment}{! First do vertical advection}}
\DoxyCodeLine{920       \textcolor{keyword}{call }update\_h\_vertical\_flux(g, gv, eatr\_sub, ebtr\_sub, h\_pre, h\_new)}
\DoxyCodeLine{921       \textcolor{keyword}{call }call\_tracer\_column\_fns(h\_pre, h\_new, eatr\_sub, ebtr\_sub, \&}
\DoxyCodeLine{922           fluxes, cs\%mld, dt\_iter, g, gv, cs\%US, cs\%tv, cs\%optics, cs\%tracer\_flow\_CSp, cs\%debug)}
\DoxyCodeLine{923       \textcolor{comment}{! We are now done with the vertical mass transports, so now h\_new is h\_sub}}
\DoxyCodeLine{924       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1}
\DoxyCodeLine{925         h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{926 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{927       \textcolor{keyword}{call }pass\_var(h\_pre,g\%Domain)}
\DoxyCodeLine{928 }
\DoxyCodeLine{929       \textcolor{comment}{! Second zonal and meridional advection}}
\DoxyCodeLine{930       \textcolor{keyword}{call }update\_h\_horizontal\_flux(g, gv, uhtr\_sub, vhtr\_sub, h\_pre, h\_new)}
\DoxyCodeLine{931       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i = is-1, ie+1 ; \textcolor{keywordflow}{do} j=js-1, je+1}
\DoxyCodeLine{932         h\_vol(i,j,k) = h\_pre(i,j,k)*g\%US\%L\_to\_m**2*g\%areaT(i,j)}
\DoxyCodeLine{933 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{934       \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr\_sub, vhtr\_sub, cs\%OBC, dt\_iter, g, gv, cs\%US, \&}
\DoxyCodeLine{935           cs\%tracer\_adv\_CSp, cs\%tracer\_Reg, h\_vol, max\_iter\_in=30, x\_first\_in=x\_before\_y)}
\DoxyCodeLine{936 }
\DoxyCodeLine{937       \textcolor{comment}{! Done with horizontal so now h\_pre should be h\_new}}
\DoxyCodeLine{938       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1}
\DoxyCodeLine{939           h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{940 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{941 }
\DoxyCodeLine{942 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{943 }
\DoxyCodeLine{944     \textcolor{keywordflow}{if} (.not. z\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{945 }
\DoxyCodeLine{946       \textcolor{comment}{! First zonal and meridional advection}}
\DoxyCodeLine{947       \textcolor{keyword}{call }update\_h\_horizontal\_flux(g, gv, uhtr\_sub, vhtr\_sub, h\_pre, h\_new)}
\DoxyCodeLine{948       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i = is-1, ie+1 ; \textcolor{keywordflow}{do} j=js-1, je+1}
\DoxyCodeLine{949         h\_vol(i,j,k) = h\_pre(i,j,k)*g\%US\%L\_to\_m**2*g\%areaT(i,j)}
\DoxyCodeLine{950 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{951       \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr\_sub, vhtr\_sub, cs\%OBC, dt\_iter, g, gv, cs\%US, \&}
\DoxyCodeLine{952           cs\%tracer\_adv\_CSp, cs\%tracer\_Reg, h\_vol, max\_iter\_in=30, x\_first\_in=x\_before\_y)}
\DoxyCodeLine{953 }
\DoxyCodeLine{954       \textcolor{comment}{! Done with horizontal so now h\_pre should be h\_new}}
\DoxyCodeLine{955       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1}
\DoxyCodeLine{956           h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{957 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{958 }
\DoxyCodeLine{959       \textcolor{comment}{! Second vertical advection}}
\DoxyCodeLine{960       \textcolor{keyword}{call }update\_h\_vertical\_flux(g, gv, eatr\_sub, ebtr\_sub, h\_pre, h\_new)}
\DoxyCodeLine{961       \textcolor{keyword}{call }call\_tracer\_column\_fns(h\_pre, h\_new, eatr\_sub, ebtr\_sub, \&}
\DoxyCodeLine{962           fluxes, cs\%mld, dt\_iter, g, gv, cs\%US, cs\%tv, cs\%optics, cs\%tracer\_flow\_CSp, cs\%debug)}
\DoxyCodeLine{963       \textcolor{comment}{! We are now done with the vertical mass transports, so now h\_new is h\_sub}}
\DoxyCodeLine{964       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1}
\DoxyCodeLine{965         h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{966 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{967 }
\DoxyCodeLine{968 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{969 }
\DoxyCodeLine{970     \textcolor{comment}{! Update remaining transports}}
\DoxyCodeLine{971     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1}
\DoxyCodeLine{972       eatr(i,j,k) = eatr(i,j,k) - eatr\_sub(i,j,k)}
\DoxyCodeLine{973       ebtr(i,j,k) = ebtr(i,j,k) - ebtr\_sub(i,j,k)}
\DoxyCodeLine{974 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{975 }
\DoxyCodeLine{976     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ie+1}
\DoxyCodeLine{977       uhtr(i,j,k) = uhtr(i,j,k) - uhtr\_sub(i,j,k)}
\DoxyCodeLine{978 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{979 }
\DoxyCodeLine{980     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-2,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1}
\DoxyCodeLine{981       vhtr(i,j,k) = vhtr(i,j,k) - vhtr\_sub(i,j,k)}
\DoxyCodeLine{982 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{983 }
\DoxyCodeLine{984     \textcolor{keyword}{call }pass\_var(eatr,g\%Domain)}
\DoxyCodeLine{985     \textcolor{keyword}{call }pass\_var(ebtr,g\%Domain)}
\DoxyCodeLine{986     \textcolor{keyword}{call }pass\_var(h\_pre,g\%Domain)}
\DoxyCodeLine{987     \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g\%Domain)}
\DoxyCodeLine{988   \textcolor{comment}{!}}
\DoxyCodeLine{989     \textcolor{comment}{! Calculate how close we are to converging by summing the remaining fluxes at each point}}
\DoxyCodeLine{990     sum\_abs\_fluxes = 0.0}
\DoxyCodeLine{991     sum\_u = 0.0}
\DoxyCodeLine{992     sum\_v = 0.0}
\DoxyCodeLine{993     \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{994       sum\_u = sum\_u + abs(uhtr(i-1,j,k))+abs(uhtr(i,j,k))}
\DoxyCodeLine{995       sum\_v = sum\_v + abs(vhtr(i,j-1,k))+abs(vhtr(i,j,k))}
\DoxyCodeLine{996       sum\_abs\_fluxes = sum\_abs\_fluxes + abs(eatr(i,j,k)) + abs(ebtr(i,j,k)) + abs(uhtr(i-1,j,k)) + \&}
\DoxyCodeLine{997           abs(uhtr(i,j,k)) + abs(vhtr(i,j-1,k)) + abs(vhtr(i,j,k))}
\DoxyCodeLine{998 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{999     \textcolor{keyword}{call }sum\_across\_pes(sum\_abs\_fluxes)}
\DoxyCodeLine{1000 }
\DoxyCodeLine{1001     \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"offline\_advection\_layer: Remaining u-flux, v-flux:"}, sum\_u, sum\_v}
\DoxyCodeLine{1002     \textcolor{keyword}{call }mom\_mesg(mesg)}
\DoxyCodeLine{1003     \textcolor{keywordflow}{if} (sum\_abs\_fluxes==0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1004       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'offline\_advection\_layer: Converged after iteration'}, iter}
\DoxyCodeLine{1005       \textcolor{keyword}{call }mom\_mesg(mesg)}
\DoxyCodeLine{1006       \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1007 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1008 }
\DoxyCodeLine{1009     \textcolor{comment}{! Switch order of Strang split every iteration}}
\DoxyCodeLine{1010     z\_first = .not. z\_first}
\DoxyCodeLine{1011     x\_before\_y = .not. x\_before\_y}
\DoxyCodeLine{1012 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1013 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_aaef35c02f93931567c41ae8bc0544bdd}\label{namespacemom__offline__main_aaef35c02f93931567c41ae8bc0544bdd}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_diabatic\_ale@{offline\_diabatic\_ale}}
\index{offline\_diabatic\_ale@{offline\_diabatic\_ale}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_diabatic\_ale()}{offline\_diabatic\_ale()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+diabatic\+\_\+ale (\begin{DoxyParamCaption}\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+start,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+end,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{h\+\_\+pre,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{eatr,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{ebtr }\end{DoxyParamCaption})}



The vertical/diabatic driver for offline tracers. First the eatr/ebtr associated with the interpolated vertical diffusivities are calculated and then any tracer column functions are done which can include vertical diffuvities and source/sink terms. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em fluxes} & pointers to forcing fields \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+start} & starting time of a segment, as a time type \\
\hline
\mbox{\texttt{ in}}  & {\em time\+\_\+end} & time interval \\
\hline
 & {\em cs} & control structure from initialize\+\_\+\+M\+OM \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+pre} & layer thicknesses before advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em eatr} & Entrainment from layer above \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em ebtr} & Entrainment from layer below \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 654 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{654 }
\DoxyCodeLine{655   \textcolor{keywordtype}{type}(forcing),    \textcolor{keywordtype}{intent(inout)}      :: fluxes\textcolor{comment}{     !< pointers to forcing fields}}
\DoxyCodeLine{656   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{intent(in)}         :: Time\_start\textcolor{comment}{ !< starting time of a segment, as a time type}}
\DoxyCodeLine{657   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{intent(in)}         :: Time\_end\textcolor{comment}{   !< time interval}}
\DoxyCodeLine{658   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}  :: CS\textcolor{comment}{         !< control structure from initialize\_MOM}}
\DoxyCodeLine{659 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{660                     \textcolor{keywordtype}{intent(inout)}      :: h\_pre\textcolor{comment}{      !< layer thicknesses before advection [H ~> m or kg m-2]}}
\DoxyCodeLine{661 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{662                     \textcolor{keywordtype}{intent(inout)}      :: eatr\textcolor{comment}{       !< Entrainment from layer above [H ~> m or kg m-2]}}
\DoxyCodeLine{663 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{664                     \textcolor{keywordtype}{intent(inout)}      :: ebtr\textcolor{comment}{       !< Entrainment from layer below [H ~> m or kg m-2]}}
\DoxyCodeLine{665 }
\DoxyCodeLine{666 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G))} :: \&}
\DoxyCodeLine{667     sw, sw\_vis, sw\_nir\textcolor{comment}{ !< Save old values of shortwave radiation [Q R Z T-1 ~> W m-2]}}
\DoxyCodeLine{668 \textcolor{keywordtype}{  real} :: hval}
\DoxyCodeLine{669   \textcolor{keywordtype}{integer} :: i,j,k}
\DoxyCodeLine{670   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz}
\DoxyCodeLine{671   \textcolor{keywordtype}{integer} :: k\_nonzero}
\DoxyCodeLine{672 \textcolor{keywordtype}{  real} :: stock\_values(MAX\_FIELDS\_)}
\DoxyCodeLine{673 \textcolor{keywordtype}{  real} :: Kd\_bot}
\DoxyCodeLine{674   \textcolor{keywordtype}{integer} :: nstocks}
\DoxyCodeLine{675   nz = cs\%GV\%ke}
\DoxyCodeLine{676   is = cs\%G\%isc ; ie = cs\%G\%iec ; js = cs\%G\%jsc ; je = cs\%G\%jec}
\DoxyCodeLine{677 }
\DoxyCodeLine{678   \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_offline\_diabatic)}
\DoxyCodeLine{679 }
\DoxyCodeLine{680   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Applying tracer source, sinks, and vertical mixing"})}
\DoxyCodeLine{681 }
\DoxyCodeLine{682   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{683     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre before offline\_diabatic\_ale"},cs\%G\%HI)}
\DoxyCodeLine{684     \textcolor{keyword}{call }hchksum(eatr,\textcolor{stringliteral}{"eatr before offline\_diabatic\_ale"},cs\%G\%HI)}
\DoxyCodeLine{685     \textcolor{keyword}{call }hchksum(ebtr,\textcolor{stringliteral}{"ebtr before offline\_diabatic\_ale"},cs\%G\%HI)}
\DoxyCodeLine{686     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before offline\_diabatic\_ale"}, cs\%G, h\_pre, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{687 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{688 }
\DoxyCodeLine{689   eatr(:,:,:) = 0.}
\DoxyCodeLine{690   ebtr(:,:,:) = 0.}
\DoxyCodeLine{691   \textcolor{comment}{! Calculate eatr and ebtr if vertical diffusivity is read}}
\DoxyCodeLine{692   \textcolor{comment}{! Because the saved remapped diagnostics from the online run assume a zero minimum thickness}}
\DoxyCodeLine{693   \textcolor{comment}{! but ALE may have a minimum thickness. Flood the diffusivities for all layers with the value}}
\DoxyCodeLine{694   \textcolor{comment}{! of Kd closest to the bottom which is non-zero}}
\DoxyCodeLine{695   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{696     k\_nonzero = nz+1}
\DoxyCodeLine{697     \textcolor{comment}{! Find the nonzero bottom Kd}}
\DoxyCodeLine{698     \textcolor{keywordflow}{do} k=nz+1,1,-1}
\DoxyCodeLine{699       \textcolor{keywordflow}{if} (cs\%Kd(i,j,k)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{700         kd\_bot = cs\%Kd(i,j,k)}
\DoxyCodeLine{701         k\_nonzero = k}
\DoxyCodeLine{702         \textcolor{keywordflow}{exit}}
\DoxyCodeLine{703 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{704 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{705     \textcolor{comment}{! Flood the bottom interfaces}}
\DoxyCodeLine{706     \textcolor{keywordflow}{do} k=k\_nonzero,nz+1}
\DoxyCodeLine{707       cs\%Kd(i,j,k) = kd\_bot}
\DoxyCodeLine{708 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{709 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{710 }
\DoxyCodeLine{711   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{712     eatr(i,j,1) = 0.}
\DoxyCodeLine{713 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{714   \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{715     hval=1.0/(cs\%GV\%H\_subroundoff + 0.5*(h\_pre(i,j,k-1) + h\_pre(i,j,k)))}
\DoxyCodeLine{716     eatr(i,j,k) = (cs\%GV\%m\_to\_H**2*cs\%US\%T\_to\_s) * cs\%dt\_offline\_vertical * hval * cs\%Kd(i,j,k)}
\DoxyCodeLine{717     ebtr(i,j,k-1) = eatr(i,j,k)}
\DoxyCodeLine{718 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{719   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{720     ebtr(i,j,nz) = 0.}
\DoxyCodeLine{721 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{722 }
\DoxyCodeLine{723   \textcolor{comment}{! Add diurnal cycle for shortwave radiation (only used if run in ocean-only mode)}}
\DoxyCodeLine{724   \textcolor{keywordflow}{if} (cs\%diurnal\_SW .and. cs\%read\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{725     sw(:,:) = fluxes\%sw(:,:)}
\DoxyCodeLine{726     sw\_vis(:,:) = fluxes\%sw\_vis\_dir(:,:)}
\DoxyCodeLine{727     sw\_nir(:,:) = fluxes\%sw\_nir\_dir(:,:)}
\DoxyCodeLine{728     \textcolor{keyword}{call }offline\_add\_diurnal\_sw(fluxes, cs\%G, time\_start, time\_end)}
\DoxyCodeLine{729 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{730 }
\DoxyCodeLine{731   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%optics)) \&}
\DoxyCodeLine{732     \textcolor{keyword}{call }set\_pen\_shortwave(cs\%optics, fluxes, cs\%G, cs\%GV, cs\%US, cs\%diabatic\_aux\_CSp, \&}
\DoxyCodeLine{733                            cs\%opacity\_CSp, cs\%tracer\_flow\_CSp)}
\DoxyCodeLine{734 }
\DoxyCodeLine{735   \textcolor{comment}{! Note that tracerBoundaryFluxesInOut within this subroutine should NOT be called}}
\DoxyCodeLine{736   \textcolor{comment}{! as the freshwater fluxes have already been accounted for}}
\DoxyCodeLine{737   \textcolor{keyword}{call }call\_tracer\_column\_fns(h\_pre, h\_pre, eatr, ebtr, fluxes, cs\%MLD, cs\%dt\_offline\_vertical, \&}
\DoxyCodeLine{738                               cs\%G, cs\%GV, cs\%US, cs\%tv, cs\%optics, cs\%tracer\_flow\_CSp, cs\%debug)}
\DoxyCodeLine{739 }
\DoxyCodeLine{740   \textcolor{keywordflow}{if} (cs\%diurnal\_SW .and. cs\%read\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{741     fluxes\%sw(:,:) = sw(:,:)}
\DoxyCodeLine{742     fluxes\%sw\_vis\_dir(:,:) = sw\_vis(:,:)}
\DoxyCodeLine{743     fluxes\%sw\_nir\_dir(:,:) = sw\_nir(:,:)}
\DoxyCodeLine{744 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{745 }
\DoxyCodeLine{746   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{747     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre after offline\_diabatic\_ale"},cs\%G\%HI)}
\DoxyCodeLine{748     \textcolor{keyword}{call }hchksum(eatr,\textcolor{stringliteral}{"eatr after offline\_diabatic\_ale"},cs\%G\%HI)}
\DoxyCodeLine{749     \textcolor{keyword}{call }hchksum(ebtr,\textcolor{stringliteral}{"ebtr after offline\_diabatic\_ale"},cs\%G\%HI)}
\DoxyCodeLine{750     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"After offline\_diabatic\_ale"}, cs\%G, h\_pre, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{751 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{752 }
\DoxyCodeLine{753   \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_offline\_diabatic)}
\DoxyCodeLine{754 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a04d329761570d6d9fbc38589bea929cc}\label{namespacemom__offline__main_a04d329761570d6d9fbc38589bea929cc}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_fw\_fluxes\_into\_ocean@{offline\_fw\_fluxes\_into\_ocean}}
\index{offline\_fw\_fluxes\_into\_ocean@{offline\_fw\_fluxes\_into\_ocean}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_fw\_fluxes\_into\_ocean()}{offline\_fw\_fluxes\_into\_ocean()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+fw\+\_\+fluxes\+\_\+into\+\_\+ocean (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), intent(inout)}]{CS,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in), optional}]{in\+\_\+flux\+\_\+optional }\end{DoxyParamCaption})}



Apply positive freshwater fluxes (into the ocean) and update net\+Mass\+Out with only the negative (out of the ocean) fluxes. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Offline control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & Surface fluxes container \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+flux\+\_\+optional} & The total time-\/integrated amount \\
\hline
\end{DoxyParams}


Definition at line 760 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{760   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Offline control structure}}
\DoxyCodeLine{761   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{762   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{763   \textcolor{keywordtype}{type}(forcing),              \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Surface fluxes container}}
\DoxyCodeLine{764 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{765                               \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{766 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{767                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: in\_flux\_optional\textcolor{comment}{ !< The total time-integrated amount}}
\DoxyCodeLine{768 \textcolor{comment}{                                                  !! of tracer that leaves with freshwater}}
\DoxyCodeLine{769 }
\DoxyCodeLine{770   \textcolor{keywordtype}{integer} :: i, j, m}
\DoxyCodeLine{771 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: negative\_fw\textcolor{comment}{ !< store all negative fluxes}}
\DoxyCodeLine{772   \textcolor{keywordtype}{logical} :: update\_h\textcolor{comment}{ !< Flag for whether h should be updated}}
\DoxyCodeLine{773 }
\DoxyCodeLine{774   \textcolor{keywordflow}{if} ( \textcolor{keyword}{present}(in\_flux\_optional) ) \&}
\DoxyCodeLine{775     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Positive freshwater fluxes with non-zero tracer concentration not supported yet"})}
\DoxyCodeLine{776 }
\DoxyCodeLine{777   \textcolor{comment}{! Set all fluxes to 0}}
\DoxyCodeLine{778   negative\_fw(:,:) = 0.}
\DoxyCodeLine{779 }
\DoxyCodeLine{780   \textcolor{comment}{! Sort fluxes into positive and negative}}
\DoxyCodeLine{781   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{782     \textcolor{keywordflow}{if} (fluxes\%netMassOut(i,j)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{783       negative\_fw(i,j) = fluxes\%netMassOut(i,j)}
\DoxyCodeLine{784       fluxes\%netMassOut(i,j) = 0.}
\DoxyCodeLine{785 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{786 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{787 }
\DoxyCodeLine{788   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{789     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h before fluxes into ocean"},g\%HI)}
\DoxyCodeLine{790     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before fluxes into ocean"}, g, h, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{791 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{792   \textcolor{keywordflow}{do} m = 1,cs\%tracer\_reg\%ntr}
\DoxyCodeLine{793     \textcolor{comment}{! Layer thicknesses should only be updated after the last tracer is finished}}
\DoxyCodeLine{794     update\_h = ( m == cs\%tracer\_reg\%ntr )}
\DoxyCodeLine{795     \textcolor{keyword}{call }applytracerboundaryfluxesinout(g, gv, cs\%tracer\_reg\%tr(m)\%t, cs\%dt\_offline, fluxes, h, \&}
\DoxyCodeLine{796                                         cs\%evap\_CFL\_limit, cs\%minimum\_forcing\_depth, update\_h\_opt = update\_h)}
\DoxyCodeLine{797 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{798   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{799     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h after fluxes into ocean"},g\%HI)}
\DoxyCodeLine{800     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"After fluxes into ocean"}, g, h, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{801 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{802 }
\DoxyCodeLine{803   \textcolor{comment}{! Now that fluxes into the ocean are done, save the negative fluxes for later}}
\DoxyCodeLine{804   fluxes\%netMassOut(:,:) = negative\_fw(:,:)}
\DoxyCodeLine{805 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_ad96c09ff7c8f34d9602fd111ec492cfe}\label{namespacemom__offline__main_ad96c09ff7c8f34d9602fd111ec492cfe}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_fw\_fluxes\_out\_ocean@{offline\_fw\_fluxes\_out\_ocean}}
\index{offline\_fw\_fluxes\_out\_ocean@{offline\_fw\_fluxes\_out\_ocean}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_fw\_fluxes\_out\_ocean()}{offline\_fw\_fluxes\_out\_ocean()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+fw\+\_\+fluxes\+\_\+out\+\_\+ocean (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), intent(inout)}]{CS,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in), optional}]{out\+\_\+flux\+\_\+optional }\end{DoxyParamCaption})}



Apply negative freshwater fluxes (out of the ocean) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Offline control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & Surface fluxes container \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em out\+\_\+flux\+\_\+optional} & The total time-\/integrated amount \\
\hline
\end{DoxyParams}


Definition at line 810 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{810   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Offline control structure}}
\DoxyCodeLine{811   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{812   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{813   \textcolor{keywordtype}{type}(forcing),              \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Surface fluxes container}}
\DoxyCodeLine{814 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{815                               \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{816 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{817                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: out\_flux\_optional\textcolor{comment}{ !< The total time-integrated amount}}
\DoxyCodeLine{818 \textcolor{comment}{                                                  !! of tracer that leaves with freshwater}}
\DoxyCodeLine{819 }
\DoxyCodeLine{820   \textcolor{keywordtype}{integer} :: m}
\DoxyCodeLine{821   \textcolor{keywordtype}{logical} :: update\_h\textcolor{comment}{ !< Flag for whether h should be updated}}
\DoxyCodeLine{822 }
\DoxyCodeLine{823   \textcolor{keywordflow}{if} ( \textcolor{keyword}{present}(out\_flux\_optional) ) \&}
\DoxyCodeLine{824     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Negative freshwater fluxes with non-zero tracer concentration not supported yet"})}
\DoxyCodeLine{825 }
\DoxyCodeLine{826   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{827     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h before fluxes out of ocean"},g\%HI)}
\DoxyCodeLine{828     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before fluxes out of ocean"}, g, h, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{829 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{830   \textcolor{keywordflow}{do} m = 1, cs\%tracer\_reg\%ntr}
\DoxyCodeLine{831     \textcolor{comment}{! Layer thicknesses should only be updated after the last tracer is finished}}
\DoxyCodeLine{832     update\_h = ( m == cs\%tracer\_reg\%ntr )}
\DoxyCodeLine{833     \textcolor{keyword}{call }applytracerboundaryfluxesinout(g, gv, cs\%tracer\_reg\%tr(m)\%t, cs\%dt\_offline, fluxes, h, \&}
\DoxyCodeLine{834                                         cs\%evap\_CFL\_limit, cs\%minimum\_forcing\_depth, update\_h\_opt = update\_h)}
\DoxyCodeLine{835 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{836   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{837     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h after fluxes out of ocean"},g\%HI)}
\DoxyCodeLine{838     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before fluxes out of ocean"}, g, h, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{839 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{840 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a312c47e83e64a6bdf064526f77a8a8ec}\label{namespacemom__offline__main_a312c47e83e64a6bdf064526f77a8a8ec}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_redistribute\_residual@{offline\_redistribute\_residual}}
\index{offline\_redistribute\_residual@{offline\_redistribute\_residual}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_redistribute\_residual()}{offline\_redistribute\_residual()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+redistribute\+\_\+residual (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{h\+\_\+pre,  }\item[{real, dimension(szib\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(cs\%g),szjb\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{vhtr,  }\item[{logical, intent(in)}]{converged }\end{DoxyParamCaption})}



In the case where the main advection routine did not converge, something needs to be done with the remaining transport. Two different ways are offered, \textquotesingle{}barotropic\textquotesingle{} means that the residual is distributed equally throughout the water column. \textquotesingle{}upwards\textquotesingle{} attempts to redistribute the transport in the layers above and will eventually work down the entire water column. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & control structure from initialize\+\_\+\+M\+OM \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+pre} & layer thicknesses before advection \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Zonal mass transport \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Meridional mass transport \\
\hline
\mbox{\texttt{ in}}  & {\em converged} & True if the iterations have converged \\
\hline
\end{DoxyParams}


Definition at line 423 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{423   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< control structure from initialize\_MOM}}
\DoxyCodeLine{424 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{425                               \textcolor{keywordtype}{intent(inout)} :: h\_pre\textcolor{comment}{ !< layer thicknesses before advection}}
\DoxyCodeLine{426 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{427                               \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{  !< Zonal mass transport}}
\DoxyCodeLine{428 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}, \&}
\DoxyCodeLine{429                               \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{  !< Meridional mass transport}}
\DoxyCodeLine{430   \textcolor{keywordtype}{logical},                    \textcolor{keywordtype}{intent(in   )} :: converged\textcolor{comment}{ !< True if the iterations have converged}}
\DoxyCodeLine{431 }
\DoxyCodeLine{432   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}}
\DoxyCodeLine{433                                                       \textcolor{comment}{! metrics and related information}}
\DoxyCodeLine{434   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}}
\DoxyCodeLine{435                                                       \textcolor{comment}{! about the vertical grid}}
\DoxyCodeLine{436   \textcolor{keywordtype}{logical} :: x\_before\_y}
\DoxyCodeLine{437   \textcolor{comment}{! Variables used to keep track of layer thicknesses at various points in the code}}
\DoxyCodeLine{438 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: \&}
\DoxyCodeLine{439       h\_new, \&}
\DoxyCodeLine{440       h\_vol}
\DoxyCodeLine{441 }
\DoxyCodeLine{442   \textcolor{comment}{! Used to calculate the eta diagnostics}}
\DoxyCodeLine{443 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G))} :: eta\_work}
\DoxyCodeLine{444 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: uhr\textcolor{comment}{  !< Zonal mass transport}}
\DoxyCodeLine{445 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))} :: vhr\textcolor{comment}{  !< Meridional mass transport}}
\DoxyCodeLine{446 }
\DoxyCodeLine{447   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{448   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz, iter}
\DoxyCodeLine{449 \textcolor{keywordtype}{  real} :: prev\_tot\_residual, tot\_residual, stock\_values(MAX\_FIELDS\_)}
\DoxyCodeLine{450   \textcolor{keywordtype}{integer} :: nstocks}
\DoxyCodeLine{451 }
\DoxyCodeLine{452   \textcolor{comment}{! Assign grid pointers}}
\DoxyCodeLine{453   g  => cs\%G}
\DoxyCodeLine{454   gv => cs\%GV}
\DoxyCodeLine{455 }
\DoxyCodeLine{456   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{457   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{458 }
\DoxyCodeLine{459   x\_before\_y = cs\%x\_before\_y}
\DoxyCodeLine{460 }
\DoxyCodeLine{461   \textcolor{keywordflow}{if} (cs\%id\_eta\_pre\_distribute>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{462     eta\_work(:,:) = 0.0}
\DoxyCodeLine{463     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{464       \textcolor{keywordflow}{if} (h\_pre(i,j,k)>gv\%Angstrom\_H) \textcolor{keywordflow}{then}}
\DoxyCodeLine{465         eta\_work(i,j) = eta\_work(i,j) + h\_pre(i,j,k)}
\DoxyCodeLine{466 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{467 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{468     \textcolor{keyword}{call }post\_data(cs\%id\_eta\_pre\_distribute,eta\_work,cs\%diag)}
\DoxyCodeLine{469 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{470 }
\DoxyCodeLine{471   \textcolor{comment}{! These are used to find out how much will be redistributed in this routine}}
\DoxyCodeLine{472   \textcolor{keywordflow}{if} (cs\%id\_h\_redist>0) \textcolor{keyword}{call }post\_data(cs\%id\_h\_redist, h\_pre, cs\%diag)}
\DoxyCodeLine{473   \textcolor{keywordflow}{if} (cs\%id\_uhr\_redist>0) \textcolor{keyword}{call }post\_data(cs\%id\_uhr\_redist, uhtr, cs\%diag)}
\DoxyCodeLine{474   \textcolor{keywordflow}{if} (cs\%id\_vhr\_redist>0) \textcolor{keyword}{call }post\_data(cs\%id\_vhr\_redist, vhtr, cs\%diag)}
\DoxyCodeLine{475 }
\DoxyCodeLine{476   \textcolor{keywordflow}{if} (converged) \textcolor{keywordflow}{return}}
\DoxyCodeLine{477 }
\DoxyCodeLine{478   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{479     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before redistribute "}, g, h\_pre, cs\%tracer\_reg\%Tr, cs\%tracer\_reg\%ntr)}
\DoxyCodeLine{480 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{481 }
\DoxyCodeLine{482   \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_redistribute)}
\DoxyCodeLine{483 }
\DoxyCodeLine{484   \textcolor{keywordflow}{if} (cs\%redistribute\_upwards .or. cs\%redistribute\_barotropic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{485     \textcolor{keywordflow}{do} iter = 1, cs\%num\_off\_iter}
\DoxyCodeLine{486 }
\DoxyCodeLine{487       \textcolor{comment}{! Perform upwards redistribution}}
\DoxyCodeLine{488       \textcolor{keywordflow}{if} (cs\%redistribute\_upwards) \textcolor{keywordflow}{then}}
\DoxyCodeLine{489 }
\DoxyCodeLine{490         \textcolor{comment}{! Calculate the layer volumes at beginning of redistribute}}
\DoxyCodeLine{491         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{492           h\_vol(i,j,k) = h\_pre(i,j,k)*g\%US\%L\_to\_m**2*g\%areaT(i,j)}
\DoxyCodeLine{493 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{494         \textcolor{keyword}{call }pass\_var(h\_vol,g\%Domain)}
\DoxyCodeLine{495         \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g\%Domain)}
\DoxyCodeLine{496 }
\DoxyCodeLine{497         \textcolor{comment}{! Store volumes for advect\_tracer}}
\DoxyCodeLine{498         h\_pre(:,:,:) = h\_vol(:,:,:)}
\DoxyCodeLine{499 }
\DoxyCodeLine{500         \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{501           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"Before upwards redistribute "}, cs\%tracer\_Reg\%Tr, cs\%tracer\_Reg\%ntr, g)}
\DoxyCodeLine{502           \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]tr before upwards redistribute"}, uhtr, vhtr, g\%HI)}
\DoxyCodeLine{503 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{504 }
\DoxyCodeLine{505         \textcolor{keywordflow}{if} (x\_before\_y) \textcolor{keywordflow}{then}}
\DoxyCodeLine{506           \textcolor{keyword}{call }distribute\_residual\_uh\_upwards(g, gv, h\_vol, uhtr)}
\DoxyCodeLine{507           \textcolor{keyword}{call }distribute\_residual\_vh\_upwards(g, gv, h\_vol, vhtr)}
\DoxyCodeLine{508         \textcolor{keywordflow}{else}}
\DoxyCodeLine{509           \textcolor{keyword}{call }distribute\_residual\_vh\_upwards(g, gv, h\_vol, vhtr)}
\DoxyCodeLine{510           \textcolor{keyword}{call }distribute\_residual\_uh\_upwards(g, gv, h\_vol, uhtr)}
\DoxyCodeLine{511 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{512 }
\DoxyCodeLine{513         \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr, vhtr, cs\%OBC, cs\%dt\_offline, g, gv, cs\%US, \&}
\DoxyCodeLine{514             cs\%tracer\_adv\_CSp, cs\%tracer\_Reg, h\_prev\_opt = h\_pre, max\_iter\_in=1, \&}
\DoxyCodeLine{515             h\_out=h\_new, uhr\_out=uhr, vhr\_out=vhr, x\_first\_in=x\_before\_y)}
\DoxyCodeLine{516 }
\DoxyCodeLine{517         \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{518           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"After upwards redistribute "}, cs\%tracer\_Reg\%Tr, cs\%tracer\_Reg\%ntr, g)}
\DoxyCodeLine{519 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{520 }
\DoxyCodeLine{521         \textcolor{comment}{! Convert h\_new back to layer thickness for ALE remapping}}
\DoxyCodeLine{522         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{523           uhtr(i,j,k) = uhr(i,j,k)}
\DoxyCodeLine{524           vhtr(i,j,k) = vhr(i,j,k)}
\DoxyCodeLine{525           h\_vol(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{526           h\_new(i,j,k) = h\_new(i,j,k) / (g\%US\%L\_to\_m**2*g\%areaT(i,j))}
\DoxyCodeLine{527           h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{528 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{529 }
\DoxyCodeLine{530 \textcolor{keywordflow}{      endif} \textcolor{comment}{! redistribute upwards}}
\DoxyCodeLine{531 }
\DoxyCodeLine{532       \textcolor{comment}{! Perform barotropic redistribution}}
\DoxyCodeLine{533       \textcolor{keywordflow}{if} (cs\%redistribute\_barotropic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{534 }
\DoxyCodeLine{535         \textcolor{comment}{! Calculate the layer volumes at beginning of redistribute}}
\DoxyCodeLine{536         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{537           h\_vol(i,j,k) = h\_pre(i,j,k)*g\%US\%L\_to\_m**2*g\%areaT(i,j)}
\DoxyCodeLine{538 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{539         \textcolor{keyword}{call }pass\_var(h\_vol,g\%Domain)}
\DoxyCodeLine{540         \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g\%Domain)}
\DoxyCodeLine{541 }
\DoxyCodeLine{542         \textcolor{comment}{! Copy h\_vol to h\_pre for advect\_tracer routine}}
\DoxyCodeLine{543         h\_pre(:,:,:) = h\_vol(:,:,:)}
\DoxyCodeLine{544 }
\DoxyCodeLine{545         \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{546           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"Before barotropic redistribute "}, cs\%tracer\_Reg\%Tr, cs\%tracer\_Reg\%ntr, g)}
\DoxyCodeLine{547           \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]tr before upwards redistribute"}, uhtr, vhtr, g\%HI)}
\DoxyCodeLine{548 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{549 }
\DoxyCodeLine{550         \textcolor{keywordflow}{if} (x\_before\_y) \textcolor{keywordflow}{then}}
\DoxyCodeLine{551           \textcolor{keyword}{call }distribute\_residual\_uh\_barotropic(g, gv, h\_vol, uhtr)}
\DoxyCodeLine{552           \textcolor{keyword}{call }distribute\_residual\_vh\_barotropic(g, gv, h\_vol, vhtr)}
\DoxyCodeLine{553         \textcolor{keywordflow}{else}}
\DoxyCodeLine{554           \textcolor{keyword}{call }distribute\_residual\_vh\_barotropic(g, gv, h\_vol, vhtr)}
\DoxyCodeLine{555           \textcolor{keyword}{call }distribute\_residual\_uh\_barotropic(g, gv, h\_vol, uhtr)}
\DoxyCodeLine{556 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{557 }
\DoxyCodeLine{558         \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr, vhtr, cs\%OBC, cs\%dt\_offline, g, gv, cs\%US, \&}
\DoxyCodeLine{559             cs\%tracer\_adv\_CSp, cs\%tracer\_Reg, h\_prev\_opt = h\_pre, max\_iter\_in=1, \&}
\DoxyCodeLine{560             h\_out=h\_new, uhr\_out=uhr, vhr\_out=vhr, x\_first\_in=x\_before\_y)}
\DoxyCodeLine{561 }
\DoxyCodeLine{562         \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{563           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"After barotropic redistribute "}, cs\%tracer\_Reg\%Tr, cs\%tracer\_Reg\%ntr, g)}
\DoxyCodeLine{564 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{565 }
\DoxyCodeLine{566         \textcolor{comment}{! Convert h\_new back to layer thickness for ALE remapping}}
\DoxyCodeLine{567         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{568           uhtr(i,j,k) = uhr(i,j,k)}
\DoxyCodeLine{569           vhtr(i,j,k) = vhr(i,j,k)}
\DoxyCodeLine{570           h\_vol(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{571           h\_new(i,j,k) = h\_new(i,j,k) / (g\%US\%L\_to\_m**2*g\%areaT(i,j))}
\DoxyCodeLine{572           h\_pre(i,j,k) = h\_new(i,j,k)}
\DoxyCodeLine{573 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{574 }
\DoxyCodeLine{575 \textcolor{keywordflow}{      endif} \textcolor{comment}{! redistribute barotropic}}
\DoxyCodeLine{576 }
\DoxyCodeLine{577       \textcolor{comment}{! Check to see if all transport has been exhausted}}
\DoxyCodeLine{578       tot\_residual = remaining\_transport\_sum(cs, uhtr, vhtr)}
\DoxyCodeLine{579       \textcolor{keywordflow}{if} (cs\%print\_adv\_offline) \textcolor{keywordflow}{then}}
\DoxyCodeLine{580         \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'(A,ES24.16)'}) \textcolor{stringliteral}{"Residual advection remaining transport: "}, tot\_residual}
\DoxyCodeLine{581         \textcolor{keyword}{call }mom\_mesg(mesg)}
\DoxyCodeLine{582 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{583       \textcolor{comment}{! If the remaining residual is 0, then this return is done}}
\DoxyCodeLine{584       \textcolor{keywordflow}{if} (tot\_residual==0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{585         \textcolor{keywordflow}{exit}}
\DoxyCodeLine{586 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{587 }
\DoxyCodeLine{588       \textcolor{keywordflow}{if} ( (tot\_residual == prev\_tot\_residual) .or. (tot\_residual<cs\%min\_residual) ) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{589       prev\_tot\_residual = tot\_residual}
\DoxyCodeLine{590 }
\DoxyCodeLine{591 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! Redistribution iteration}}
\DoxyCodeLine{592 \textcolor{keywordflow}{  endif} \textcolor{comment}{! If one of the redistribution routines is requested}}
\DoxyCodeLine{593 }
\DoxyCodeLine{594   \textcolor{keywordflow}{if} (cs\%id\_eta\_post\_distribute>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{595     eta\_work(:,:) = 0.0}
\DoxyCodeLine{596     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{597       \textcolor{keywordflow}{if} (h\_pre(i,j,k)>gv\%Angstrom\_H) \textcolor{keywordflow}{then}}
\DoxyCodeLine{598         eta\_work(i,j) = eta\_work(i,j) + h\_pre(i,j,k)}
\DoxyCodeLine{599 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{600 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{601     \textcolor{keyword}{call }post\_data(cs\%id\_eta\_post\_distribute,eta\_work,cs\%diag)}
\DoxyCodeLine{602 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{603 }
\DoxyCodeLine{604   \textcolor{keywordflow}{if} (cs\%id\_uhr>0) \textcolor{keyword}{call }post\_data(cs\%id\_uhr,uhtr,cs\%diag)}
\DoxyCodeLine{605   \textcolor{keywordflow}{if} (cs\%id\_vhr>0) \textcolor{keyword}{call }post\_data(cs\%id\_vhr,vhtr,cs\%diag)}
\DoxyCodeLine{606 }
\DoxyCodeLine{607   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{608     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre after redistribute"},g\%HI)}
\DoxyCodeLine{609     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"uhtr after redistribute"}, uhtr, vhtr, g\%HI)}
\DoxyCodeLine{610     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"after redistribute "}, g, h\_new, cs\%tracer\_Reg\%Tr, cs\%tracer\_Reg\%ntr)}
\DoxyCodeLine{611 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{612 }
\DoxyCodeLine{613   \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_redistribute)}
\DoxyCodeLine{614 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a853e9fbade83984621d26f51c1a2d651}\label{namespacemom__offline__main_a853e9fbade83984621d26f51c1a2d651}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_transport\_end@{offline\_transport\_end}}
\index{offline\_transport\_end@{offline\_transport\_end}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_transport\_end()}{offline\_transport\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+transport\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocates (if necessary) arrays within the offline control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & Control structure for offline module \\
\hline
\end{DoxyParams}


Definition at line 1506 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1506   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Control structure for offline module}}
\DoxyCodeLine{1507 }
\DoxyCodeLine{1508   \textcolor{comment}{! Explicitly allocate all allocatable arrays}}
\DoxyCodeLine{1509   \textcolor{keyword}{deallocate}(cs\%uhtr)}
\DoxyCodeLine{1510   \textcolor{keyword}{deallocate}(cs\%vhtr)}
\DoxyCodeLine{1511   \textcolor{keyword}{deallocate}(cs\%eatr)}
\DoxyCodeLine{1512   \textcolor{keyword}{deallocate}(cs\%ebtr)}
\DoxyCodeLine{1513   \textcolor{keyword}{deallocate}(cs\%h\_end)}
\DoxyCodeLine{1514   \textcolor{keyword}{deallocate}(cs\%netMassOut)}
\DoxyCodeLine{1515   \textcolor{keyword}{deallocate}(cs\%netMassIn)}
\DoxyCodeLine{1516   \textcolor{keyword}{deallocate}(cs\%Kd)}
\DoxyCodeLine{1517   \textcolor{keywordflow}{if} (cs\%read\_mld) \textcolor{keyword}{deallocate}(cs\%mld)}
\DoxyCodeLine{1518   \textcolor{keywordflow}{if} (cs\%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1519     \textcolor{keyword}{deallocate}(cs\%uhtr\_all)}
\DoxyCodeLine{1520     \textcolor{keyword}{deallocate}(cs\%vhtr\_all)}
\DoxyCodeLine{1521     \textcolor{keyword}{deallocate}(cs\%hend\_all)}
\DoxyCodeLine{1522     \textcolor{keyword}{deallocate}(cs\%temp\_all)}
\DoxyCodeLine{1523     \textcolor{keyword}{deallocate}(cs\%salt\_all)}
\DoxyCodeLine{1524 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1525 }
\DoxyCodeLine{1526   \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1527 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_ae68ac2570f0623013b09714d467ef857}\label{namespacemom__offline__main_ae68ac2570f0623013b09714d467ef857}} 
\index{mom\_offline\_main@{mom\_offline\_main}!offline\_transport\_init@{offline\_transport\_init}}
\index{offline\_transport\_init@{offline\_transport\_init}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{offline\_transport\_init()}{offline\_transport\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::offline\+\_\+transport\+\_\+init (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{type(diabatic\+\_\+cs), intent(in)}]{diabatic\+\_\+\+C\+Sp,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in), target}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in), target}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), target}]{US }\end{DoxyParamCaption})}



Initializes the control structure for offline transport and reads in some of the. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters \\
\hline
 & {\em cs} & Offline control structure \\
\hline
\mbox{\texttt{ in}}  & {\em diabatic\+\_\+csp} & The diabatic control structure \\
\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
\end{DoxyParams}


Definition at line 1290 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1290 }
\DoxyCodeLine{1291   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}}
\DoxyCodeLine{1292   \textcolor{keywordtype}{type}(offline\_transport\_CS),      \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Offline control structure}}
\DoxyCodeLine{1293   \textcolor{keywordtype}{type}(diabatic\_CS),               \textcolor{keywordtype}{intent(in)} :: diabatic\_CSp\textcolor{comment}{ !< The diabatic control structure}}
\DoxyCodeLine{1294   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< ocean grid structure}}
\DoxyCodeLine{1295   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{1296   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1297 }
\DoxyCodeLine{1298   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"offline\_transport"}}
\DoxyCodeLine{1299   \textcolor{keywordtype}{character(len=20)}  :: redistribute\_method}
\DoxyCodeLine{1300 }
\DoxyCodeLine{1301   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz}
\DoxyCodeLine{1302   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{1303 }
\DoxyCodeLine{1304   is   = g\%isc   ; ie   = g\%iec  ; js   = g\%jsc  ; je   = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{1305   isd  = g\%isd   ; ied  = g\%ied  ; jsd  = g\%jsd  ; jed  = g\%jed}
\DoxyCodeLine{1306   isdb = g\%IsdB  ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{1307 }
\DoxyCodeLine{1308   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"offline\_transport\_init, MOM\_offline\_control.F90"})}
\DoxyCodeLine{1309 }
\DoxyCodeLine{1310   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1311     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"offline\_transport\_init called with an associated "}// \&}
\DoxyCodeLine{1312       \textcolor{stringliteral}{"control structure."})}
\DoxyCodeLine{1313     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1314 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1315   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{1316   \textcolor{keyword}{call }log\_version(param\_file, mdl,version, \textcolor{stringliteral}{"This module allows for tracers to be run offline"})}
\DoxyCodeLine{1317 }
\DoxyCodeLine{1318   \textcolor{comment}{! Determining the internal unit scaling factors for this run.}}
\DoxyCodeLine{1319   cs\%US => us}
\DoxyCodeLine{1320 }
\DoxyCodeLine{1321   \textcolor{comment}{! Parse MOM\_input for offline control}}
\DoxyCodeLine{1322   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFFLINEDIR"}, cs\%offlinedir, \&}
\DoxyCodeLine{1323     \textcolor{stringliteral}{"Input directory where the offline fields can be found"},  fail\_if\_missing = .true.)}
\DoxyCodeLine{1324   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_SUM\_FILE"}, cs\%sum\_file, \&}
\DoxyCodeLine{1325     \textcolor{stringliteral}{"Filename where the accumulated fields can be found"},     fail\_if\_missing = .true.)}
\DoxyCodeLine{1326   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_SNAP\_FILE"}, cs\%snap\_file, \&}
\DoxyCodeLine{1327     \textcolor{stringliteral}{"Filename where snapshot fields can be found"},            fail\_if\_missing = .true.)}
\DoxyCodeLine{1328   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_MEAN\_FILE"}, cs\%mean\_file, \&}
\DoxyCodeLine{1329     \textcolor{stringliteral}{"Filename where averaged fields can be found"},            fail\_if\_missing = .true.)}
\DoxyCodeLine{1330   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_SURF\_FILE"}, cs\%surf\_file, \&}
\DoxyCodeLine{1331     \textcolor{stringliteral}{"Filename where averaged fields can be found"},            fail\_if\_missing = .true.)}
\DoxyCodeLine{1332   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NUMTIME"}, cs\%numtime, \&}
\DoxyCodeLine{1333     \textcolor{stringliteral}{"Number of timelevels in offline input files"},            fail\_if\_missing = .true.)}
\DoxyCodeLine{1334   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NK\_INPUT"}, cs\%nk\_input, \&}
\DoxyCodeLine{1335     \textcolor{stringliteral}{"Number of vertical levels in offline input files"}, default = nz)}
\DoxyCodeLine{1336   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT\_OFFLINE"}, cs\%dt\_offline, \&}
\DoxyCodeLine{1337     \textcolor{stringliteral}{"Length of time between reading in of input fields"}, units=\textcolor{stringliteral}{'s'}, scale=us\%s\_to\_T, fail\_if\_missing = .true.)}
\DoxyCodeLine{1338   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT\_OFFLINE\_VERTICAL"}, cs\%dt\_offline\_vertical, \&}
\DoxyCodeLine{1339     \textcolor{stringliteral}{"Length of the offline timestep for tracer column sources/sinks "} //\&}
\DoxyCodeLine{1340     \textcolor{stringliteral}{"This should be set to the length of the coupling timestep for "} //\&}
\DoxyCodeLine{1341     \textcolor{stringliteral}{"tracers which need shortwave fluxes"}, units=\textcolor{stringliteral}{"s"}, scale=us\%s\_to\_T, fail\_if\_missing = .true.)}
\DoxyCodeLine{1342   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"START\_INDEX"}, cs\%start\_index, \&}
\DoxyCodeLine{1343     \textcolor{stringliteral}{"Which time index to start from"}, default=1)}
\DoxyCodeLine{1344   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FIELDS\_ARE\_OFFSET"}, cs\%fields\_are\_offset, \&}
\DoxyCodeLine{1345     \textcolor{stringliteral}{"True if the time-averaged fields and snapshot fields "}//\&}
\DoxyCodeLine{1346     \textcolor{stringliteral}{"are offset by one time level"}, default=.false.)}
\DoxyCodeLine{1347   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REDISTRIBUTE\_METHOD"}, redistribute\_method, \&}
\DoxyCodeLine{1348     \textcolor{stringliteral}{"Redistributes any remaining horizontal fluxes throughout "}    //\&}
\DoxyCodeLine{1349     \textcolor{stringliteral}{"the rest of water column. Options are 'barotropic' which "}    //\&}
\DoxyCodeLine{1350     \textcolor{stringliteral}{"evenly distributes flux throughout the entire water column, "} //\&}
\DoxyCodeLine{1351     \textcolor{stringliteral}{"'upwards' which adds the maximum of the remaining flux in "}   //\&}
\DoxyCodeLine{1352     \textcolor{stringliteral}{"each layer above, both which first applies upwards and then "} //\&}
\DoxyCodeLine{1353     \textcolor{stringliteral}{"barotropic, and 'none' which does no redistribution"}, \&}
\DoxyCodeLine{1354     default=\textcolor{stringliteral}{'barotropic'})}
\DoxyCodeLine{1355   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NUM\_OFF\_ITER"}, cs\%num\_off\_iter, \&}
\DoxyCodeLine{1356     \textcolor{stringliteral}{"Number of iterations to subdivide the offline tracer advection and diffusion"}, \&}
\DoxyCodeLine{1357     default = 60)}
\DoxyCodeLine{1358   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_ALE\_MOD"}, cs\%off\_ale\_mod, \&}
\DoxyCodeLine{1359     \textcolor{stringliteral}{"Sets how many horizontal advection steps are taken before an ALE "} //\&}
\DoxyCodeLine{1360     \textcolor{stringliteral}{"remapping step is done. 1 would be x->y->ALE, 2 would be"}           //\&}
\DoxyCodeLine{1361     \textcolor{stringliteral}{"x->y->x->y->ALE"}, default = 1)}
\DoxyCodeLine{1362   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRINT\_ADV\_OFFLINE"}, cs\%print\_adv\_offline, \&}
\DoxyCodeLine{1363     \textcolor{stringliteral}{"Print diagnostic output every advection subiteration"},default=.false.)}
\DoxyCodeLine{1364   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SKIP\_DIFFUSION\_OFFLINE"}, cs\%skip\_diffusion, \&}
\DoxyCodeLine{1365     \textcolor{stringliteral}{"Do not do horizontal diffusion"},default=.false.)}
\DoxyCodeLine{1366   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_SW"}, cs\%read\_sw, \&}
\DoxyCodeLine{1367     \textcolor{stringliteral}{"Read in shortwave radiation field instead of using values from the coupler"}//\&}
\DoxyCodeLine{1368     \textcolor{stringliteral}{"when in offline tracer mode"},default=.false.)}
\DoxyCodeLine{1369   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_MLD"}, cs\%read\_mld, \&}
\DoxyCodeLine{1370     \textcolor{stringliteral}{"Read in mixed layer depths for tracers which exchange with the atmosphere"}//\&}
\DoxyCodeLine{1371     \textcolor{stringliteral}{"when in offline tracer mode"},default=.false.)}
\DoxyCodeLine{1372   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLD\_VAR\_NAME"}, cs\%mld\_var\_name, \&}
\DoxyCodeLine{1373     \textcolor{stringliteral}{"Name of the variable containing the depth of active mixing"},\&}
\DoxyCodeLine{1374     default=\textcolor{stringliteral}{'ePBL\_h\_ML'})}
\DoxyCodeLine{1375   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFFLINE\_ADD\_DIURNAL\_SW"}, cs\%diurnal\_sw, \&}
\DoxyCodeLine{1376     \textcolor{stringliteral}{"Adds a synthetic diurnal cycle in the same way that the ice "} // \&}
\DoxyCodeLine{1377     \textcolor{stringliteral}{"model would have when time-averaged fields of shortwave "}    // \&}
\DoxyCodeLine{1378     \textcolor{stringliteral}{"radiation are read in"}, default=.false.)}
\DoxyCodeLine{1379   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_MAX"}, cs\%Kd\_max, \&}
\DoxyCodeLine{1380     \textcolor{stringliteral}{"The maximum permitted increment for the diapycnal "}//\&}
\DoxyCodeLine{1381     \textcolor{stringliteral}{"diffusivity from TKE-based parameterizations, or a "}//\&}
\DoxyCodeLine{1382     \textcolor{stringliteral}{"negative value for no limit."}, units=\textcolor{stringliteral}{"m2 s-1"}, default=-1.0)}
\DoxyCodeLine{1383   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIN\_RESIDUAL\_TRANSPORT"}, cs\%min\_residual, \&}
\DoxyCodeLine{1384     \textcolor{stringliteral}{"How much remaining transport before the main offline advection "}// \&}
\DoxyCodeLine{1385     \textcolor{stringliteral}{"is exited. The default value corresponds to about 1 meter of "}  // \&}
\DoxyCodeLine{1386     \textcolor{stringliteral}{"difference in a grid cell"}, default = 1.e9)}
\DoxyCodeLine{1387   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_ALL\_TS\_UVH"}, cs\%read\_all\_ts\_uvh,  \&}
\DoxyCodeLine{1388     \textcolor{stringliteral}{"Reads all time levels of a subset of the fields necessary to run "}    //      \&}
\DoxyCodeLine{1389     \textcolor{stringliteral}{"the model offline. This can require a large amount of memory "}//      \&}
\DoxyCodeLine{1390     \textcolor{stringliteral}{"and will make initialization very slow. However, for offline "}//      \&}
\DoxyCodeLine{1391     \textcolor{stringliteral}{"runs spanning more than a year this can reduce total I/O overhead"},    \&}
\DoxyCodeLine{1392     default = .false.)}
\DoxyCodeLine{1393 }
\DoxyCodeLine{1394   \textcolor{comment}{! Concatenate offline directory and file names}}
\DoxyCodeLine{1395   cs\%snap\_file = trim(cs\%offlinedir)//trim(cs\%snap\_file)}
\DoxyCodeLine{1396   cs\%mean\_file = trim(cs\%offlinedir)//trim(cs\%mean\_file)}
\DoxyCodeLine{1397   cs\%sum\_file = trim(cs\%offlinedir)//trim(cs\%sum\_file)}
\DoxyCodeLine{1398   cs\%surf\_file = trim(cs\%offlinedir)//trim(cs\%surf\_file)}
\DoxyCodeLine{1399 }
\DoxyCodeLine{1400   cs\%num\_vert\_iter = cs\%dt\_offline/cs\%dt\_offline\_vertical}
\DoxyCodeLine{1401 }
\DoxyCodeLine{1402   \textcolor{comment}{! Map redistribute\_method onto logicals in CS}}
\DoxyCodeLine{1403   \textcolor{keywordflow}{select case} (redistribute\_method)}
\DoxyCodeLine{1404     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'barotropic'})}
\DoxyCodeLine{1405       cs\%redistribute\_barotropic = .true.}
\DoxyCodeLine{1406       cs\%redistribute\_upwards    = .false.}
\DoxyCodeLine{1407     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'upwards'})}
\DoxyCodeLine{1408       cs\%redistribute\_barotropic = .false.}
\DoxyCodeLine{1409       cs\%redistribute\_upwards    = .true.}
\DoxyCodeLine{1410     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'both'})}
\DoxyCodeLine{1411       cs\%redistribute\_barotropic = .true.}
\DoxyCodeLine{1412       cs\%redistribute\_upwards    = .true.}
\DoxyCodeLine{1413     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'none'})}
\DoxyCodeLine{1414       cs\%redistribute\_barotropic = .false.}
\DoxyCodeLine{1415       cs\%redistribute\_upwards    = .false.}
\DoxyCodeLine{1416 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{1417 }
\DoxyCodeLine{1418   \textcolor{comment}{! Set the accumulated time to zero}}
\DoxyCodeLine{1419   cs\%accumulated\_time = real\_to\_time(0.0)}
\DoxyCodeLine{1420   cs\%vertical\_time = cs\%accumulated\_time}
\DoxyCodeLine{1421   \textcolor{comment}{! Set the starting read index for time-averaged and snapshotted fields}}
\DoxyCodeLine{1422   cs\%ridx\_sum = cs\%start\_index}
\DoxyCodeLine{1423   \textcolor{keywordflow}{if} (cs\%fields\_are\_offset) cs\%ridx\_snap = next\_modulo\_time(cs\%start\_index,cs\%numtime)}
\DoxyCodeLine{1424   \textcolor{keywordflow}{if} (.not. cs\%fields\_are\_offset) cs\%ridx\_snap = cs\%start\_index}
\DoxyCodeLine{1425 }
\DoxyCodeLine{1426   \textcolor{comment}{! Copy members from other modules}}
\DoxyCodeLine{1427   \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, opacity\_csp=cs\%opacity\_CSp, optics\_csp=cs\%optics, \&}
\DoxyCodeLine{1428                                diabatic\_aux\_csp=cs\%diabatic\_aux\_CSp, \&}
\DoxyCodeLine{1429                                evap\_cfl\_limit=cs\%evap\_CFL\_limit, \&}
\DoxyCodeLine{1430                                minimum\_forcing\_depth=cs\%minimum\_forcing\_depth)}
\DoxyCodeLine{1431 }
\DoxyCodeLine{1432   \textcolor{comment}{! Grid pointer assignments}}
\DoxyCodeLine{1433   cs\%G  => g}
\DoxyCodeLine{1434   cs\%GV => gv}
\DoxyCodeLine{1435 }
\DoxyCodeLine{1436   \textcolor{comment}{! Allocate arrays}}
\DoxyCodeLine{1437   \textcolor{keyword}{allocate}(cs\%uhtr(isdb:iedb,jsd:jed,nz))   ; cs\%uhtr(:,:,:) = 0.0}
\DoxyCodeLine{1438   \textcolor{keyword}{allocate}(cs\%vhtr(isd:ied,jsdb:jedb,nz))   ; cs\%vhtr(:,:,:) = 0.0}
\DoxyCodeLine{1439   \textcolor{keyword}{allocate}(cs\%eatr(isd:ied,jsd:jed,nz))          ; cs\%eatr(:,:,:) = 0.0}
\DoxyCodeLine{1440   \textcolor{keyword}{allocate}(cs\%ebtr(isd:ied,jsd:jed,nz))          ; cs\%ebtr(:,:,:) = 0.0}
\DoxyCodeLine{1441   \textcolor{keyword}{allocate}(cs\%h\_end(isd:ied,jsd:jed,nz))         ; cs\%h\_end(:,:,:) = 0.0}
\DoxyCodeLine{1442   \textcolor{keyword}{allocate}(cs\%netMassOut(g\%isd:g\%ied,g\%jsd:g\%jed)) ; cs\%netMassOut(:,:) = 0.0}
\DoxyCodeLine{1443   \textcolor{keyword}{allocate}(cs\%netMassIn(g\%isd:g\%ied,g\%jsd:g\%jed))  ; cs\%netMassIn(:,:) = 0.0}
\DoxyCodeLine{1444   \textcolor{keyword}{allocate}(cs\%Kd(isd:ied,jsd:jed,nz+1)) ; cs\%Kd = 0.}
\DoxyCodeLine{1445   \textcolor{keywordflow}{if} (cs\%read\_mld) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1446     \textcolor{keyword}{allocate}(cs\%mld(g\%isd:g\%ied,g\%jsd:g\%jed)) ; cs\%mld(:,:) = 0.0}
\DoxyCodeLine{1447 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1448 }
\DoxyCodeLine{1449   \textcolor{keywordflow}{if} (cs\%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1450     \textcolor{keyword}{call }read\_all\_input(cs)}
\DoxyCodeLine{1451 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1452 }
\DoxyCodeLine{1453   \textcolor{comment}{! Initialize ids for clocks used in offline routines}}
\DoxyCodeLine{1454   cs\%id\_clock\_read\_fields =      cpu\_clock\_id(\textcolor{stringliteral}{'(Offline read fields)'},grain=clock\_module)}
\DoxyCodeLine{1455   cs\%id\_clock\_offline\_diabatic = cpu\_clock\_id(\textcolor{stringliteral}{'(Offline diabatic)'},grain=clock\_module)}
\DoxyCodeLine{1456   cs\%id\_clock\_offline\_adv =      cpu\_clock\_id(\textcolor{stringliteral}{'(Offline transport)'},grain=clock\_module)}
\DoxyCodeLine{1457   cs\%id\_clock\_redistribute =     cpu\_clock\_id(\textcolor{stringliteral}{'(Offline redistribute)'},grain=clock\_module)}
\DoxyCodeLine{1458 }
\DoxyCodeLine{1459   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"offline\_transport\_init"})}
\DoxyCodeLine{1460 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_ad773f8f414f53f000cab30ad097aeaab}\label{namespacemom__offline__main_ad773f8f414f53f000cab30ad097aeaab}} 
\index{mom\_offline\_main@{mom\_offline\_main}!post\_offline\_convergence\_diags@{post\_offline\_convergence\_diags}}
\index{post\_offline\_convergence\_diags@{post\_offline\_convergence\_diags}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{post\_offline\_convergence\_diags()}{post\_offline\_convergence\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::post\+\_\+offline\+\_\+convergence\+\_\+diags (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), intent(in)}]{CS,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{h\+\_\+off,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{h\+\_\+end,  }\item[{real, dimension(szib\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(cs\%g),szjb\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(inout)}]{vhtr }\end{DoxyParamCaption})}



Posts diagnostics related to offline convergence diagnostics. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Offline control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+off} & Thicknesses at end of offline step \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+end} & Stored thicknesses \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhtr} & Remaining zonal mass transport \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhtr} & Remaining meridional mass transport \\
\hline
\end{DoxyParams}


Definition at line 1172 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1172   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(in   )} :: CS\textcolor{comment}{     !< Offline control structure}}
\DoxyCodeLine{1173 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))},  \textcolor{keywordtype}{intent(inout)} :: h\_off\textcolor{comment}{  !< Thicknesses at end of offline step}}
\DoxyCodeLine{1174 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))},  \textcolor{keywordtype}{intent(inout)} :: h\_end\textcolor{comment}{  !< Stored thicknesses}}
\DoxyCodeLine{1175 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Remaining zonal mass transport}}
\DoxyCodeLine{1176 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Remaining meridional mass transport}}
\DoxyCodeLine{1177 }
\DoxyCodeLine{1178 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G))} :: eta\_diff}
\DoxyCodeLine{1179   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{1180 }
\DoxyCodeLine{1181   \textcolor{keywordflow}{if} (cs\%id\_eta\_diff\_end>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1182     \textcolor{comment}{! Calculate difference in column thickness}}
\DoxyCodeLine{1183     eta\_diff = 0.}
\DoxyCodeLine{1184     \textcolor{keywordflow}{do} k=1,cs\%GV\%ke ; \textcolor{keywordflow}{do} j=cs\%G\%jsc,cs\%G\%jec ; \textcolor{keywordflow}{do} i=cs\%G\%isc,cs\%G\%iec}
\DoxyCodeLine{1185       eta\_diff(i,j) = eta\_diff(i,j) + h\_off(i,j,k)}
\DoxyCodeLine{1186 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1187     \textcolor{keywordflow}{do} k=1,cs\%GV\%ke ; \textcolor{keywordflow}{do} j=cs\%G\%jsc,cs\%G\%jec ; \textcolor{keywordflow}{do} i=cs\%G\%isc,cs\%G\%iec}
\DoxyCodeLine{1188       eta\_diff(i,j) = eta\_diff(i,j) - h\_end(i,j,k)}
\DoxyCodeLine{1189 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1190 }
\DoxyCodeLine{1191     \textcolor{keyword}{call }post\_data(cs\%id\_eta\_diff\_end, eta\_diff, cs\%diag)}
\DoxyCodeLine{1192 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1193 }
\DoxyCodeLine{1194   \textcolor{keywordflow}{if} (cs\%id\_hdiff>0) \textcolor{keyword}{call }post\_data(cs\%id\_hdiff, h\_off-h\_end, cs\%diag)}
\DoxyCodeLine{1195   \textcolor{keywordflow}{if} (cs\%id\_hr>0) \textcolor{keyword}{call }post\_data(cs\%id\_hr, h\_off, cs\%diag)}
\DoxyCodeLine{1196   \textcolor{keywordflow}{if} (cs\%id\_uhr\_end>0) \textcolor{keyword}{call }post\_data(cs\%id\_uhr\_end, uhtr, cs\%diag)}
\DoxyCodeLine{1197   \textcolor{keywordflow}{if} (cs\%id\_vhr\_end>0) \textcolor{keyword}{call }post\_data(cs\%id\_vhr\_end, vhtr, cs\%diag)}
\DoxyCodeLine{1198 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_abc6fd7e877d8e70014cbad2d4e3f11c5}\label{namespacemom__offline__main_abc6fd7e877d8e70014cbad2d4e3f11c5}} 
\index{mom\_offline\_main@{mom\_offline\_main}!read\_all\_input@{read\_all\_input}}
\index{read\_all\_input@{read\_all\_input}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{read\_all\_input()}{read\_all\_input()}}
{\footnotesize\ttfamily subroutine mom\+\_\+offline\+\_\+main\+::read\+\_\+all\+\_\+input (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Coordinates the allocation and reading in all time levels of uh, vh, hend, temp, and salt from files. Used when read\+\_\+all\+\_\+ts\+\_\+uvh. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Control structure for offline module \\
\hline
\end{DoxyParams}


Definition at line 1466 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1466   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)}  :: CS\textcolor{comment}{ !< Control structure for offline module}}
\DoxyCodeLine{1467 }
\DoxyCodeLine{1468   \textcolor{keywordtype}{integer} :: is, ie, js, je, isd, ied, jsd, jed, nz, t, ntime}
\DoxyCodeLine{1469   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{1470 }
\DoxyCodeLine{1471   nz = cs\%GV\%ke ; ntime = cs\%numtime}
\DoxyCodeLine{1472   isd  = cs\%G\%isd   ; ied  = cs\%G\%ied  ; jsd  = cs\%G\%jsd  ; jed  = cs\%G\%jed}
\DoxyCodeLine{1473   isdb = cs\%G\%IsdB  ; iedb = cs\%G\%IedB ; jsdb = cs\%G\%JsdB ; jedb = cs\%G\%JedB}
\DoxyCodeLine{1474 }
\DoxyCodeLine{1475   \textcolor{comment}{! Extra safety check that we're not going to overallocate any arrays}}
\DoxyCodeLine{1476   \textcolor{keywordflow}{if} (cs\%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1477     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%uhtr\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"uhtr\_all is already allocated"})}
\DoxyCodeLine{1478     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%vhtr\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"vhtr\_all is already allocated"})}
\DoxyCodeLine{1479     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%hend\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"hend\_all is already allocated"})}
\DoxyCodeLine{1480     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%temp\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"temp\_all is already allocated"})}
\DoxyCodeLine{1481     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%salt\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"salt\_all is already allocated"})}
\DoxyCodeLine{1482 }
\DoxyCodeLine{1483     \textcolor{keyword}{allocate}(cs\%uhtr\_all(isdb:iedb,jsd:jed,nz,ntime))     ; cs\%uhtr\_all(:,:,:,:) = 0.0}
\DoxyCodeLine{1484     \textcolor{keyword}{allocate}(cs\%vhtr\_all(isd:ied,jsdb:jedb,nz,ntime))     ; cs\%vhtr\_all(:,:,:,:) = 0.0}
\DoxyCodeLine{1485     \textcolor{keyword}{allocate}(cs\%hend\_all(isd:ied,jsd:jed,nz,ntime))       ; cs\%hend\_all(:,:,:,:) = 0.0}
\DoxyCodeLine{1486     \textcolor{keyword}{allocate}(cs\%temp\_all(isd:ied,jsd:jed,nz,1:ntime))     ; cs\%temp\_all(:,:,:,:) = 0.0}
\DoxyCodeLine{1487     \textcolor{keyword}{allocate}(cs\%salt\_all(isd:ied,jsd:jed,nz,1:ntime))     ; cs\%salt\_all(:,:,:,:) = 0.0}
\DoxyCodeLine{1488 }
\DoxyCodeLine{1489     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Reading in uhtr, vhtr, h\_start, h\_end, temp, salt"})}
\DoxyCodeLine{1490     \textcolor{keywordflow}{do} t = 1,ntime}
\DoxyCodeLine{1491       \textcolor{keyword}{call }mom\_read\_vector(cs\%snap\_file, \textcolor{stringliteral}{'uhtr\_sum'}, \textcolor{stringliteral}{'vhtr\_sum'}, cs\%uhtr\_all(:,:,1:cs\%nk\_input,t), \&}
\DoxyCodeLine{1492                        cs\%vhtr\_all(:,:,1:cs\%nk\_input,t), cs\%G\%Domain, timelevel=t)}
\DoxyCodeLine{1493       \textcolor{keyword}{call }mom\_read\_data(cs\%snap\_file,\textcolor{stringliteral}{'h\_end'}, cs\%hend\_all(:,:,1:cs\%nk\_input,t), cs\%G\%Domain, \&}
\DoxyCodeLine{1494         timelevel=t, position=center)}
\DoxyCodeLine{1495       \textcolor{keyword}{call }mom\_read\_data(cs\%mean\_file,\textcolor{stringliteral}{'temp'}, cs\%temp\_all(:,:,1:cs\%nk\_input,t), cs\%G\%Domain, \&}
\DoxyCodeLine{1496         timelevel=t, position=center)}
\DoxyCodeLine{1497       \textcolor{keyword}{call }mom\_read\_data(cs\%mean\_file,\textcolor{stringliteral}{'salt'}, cs\%salt\_all(:,:,1:cs\%nk\_input,t), cs\%G\%Domain, \&}
\DoxyCodeLine{1498         timelevel=t, position=center)}
\DoxyCodeLine{1499 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1500 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1501 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a0adf88ec8f84684573c1bafd91b22cf6}\label{namespacemom__offline__main_a0adf88ec8f84684573c1bafd91b22cf6}} 
\index{mom\_offline\_main@{mom\_offline\_main}!register\_diags\_offline\_transport@{register\_diags\_offline\_transport}}
\index{register\_diags\_offline\_transport@{register\_diags\_offline\_transport}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{register\_diags\_offline\_transport()}{register\_diags\_offline\_transport()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::register\+\_\+diags\+\_\+offline\+\_\+transport (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(diag\+\_\+ctrl), intent(in)}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initialize additional diagnostics required for offline tracer transport. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure for offline module \\
\hline
\mbox{\texttt{ in}}  & {\em time} & current model time \\
\hline
\mbox{\texttt{ in}}  & {\em diag} & Structure that regulates diagnostic output \\
\hline
\end{DoxyParams}


Definition at line 1115 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1115 }
\DoxyCodeLine{1116   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< Control structure for offline module}}
\DoxyCodeLine{1117   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)} :: Time\textcolor{comment}{ !< current model time}}
\DoxyCodeLine{1118   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{ !< Structure that regulates diagnostic output}}
\DoxyCodeLine{1119 }
\DoxyCodeLine{1120   \textcolor{comment}{! U-cell fields}}
\DoxyCodeLine{1121   cs\%id\_uhr = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhr'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{1122     \textcolor{stringliteral}{'Zonal thickness fluxes remaining at end of advection'}, \textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1123   cs\%id\_uhr\_redist = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhr\_redist'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{1124     \textcolor{stringliteral}{'Zonal thickness fluxes to be redistributed vertically'}, \textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1125   cs\%id\_uhr\_end = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhr\_end'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{1126     \textcolor{stringliteral}{'Zonal thickness fluxes at end of offline step'}, \textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1127 }
\DoxyCodeLine{1128   \textcolor{comment}{! V-cell fields}}
\DoxyCodeLine{1129   cs\%id\_vhr = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhr'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{1130     \textcolor{stringliteral}{'Meridional thickness fluxes remaining at end of advection'}, \textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1131   cs\%id\_vhr\_redist = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhr\_redist'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{1132     \textcolor{stringliteral}{'Meridional thickness to be redistributed vertically'}, \textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1133   cs\%id\_vhr\_end = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhr\_end'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{1134     \textcolor{stringliteral}{'Meridional thickness at end of offline step'}, \textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1135 }
\DoxyCodeLine{1136   \textcolor{comment}{! T-cell fields}}
\DoxyCodeLine{1137   cs\%id\_hdiff  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'hdiff'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1138     \textcolor{stringliteral}{'Difference between the stored and calculated layer thickness'}, \textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1139   cs\%id\_hr  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'hr'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1140     \textcolor{stringliteral}{'Layer thickness at end of offline step'}, \textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1141   cs\%id\_ear  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ear'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1142     \textcolor{stringliteral}{'Remaining thickness entrained from above'}, \textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1143   cs\%id\_ebr  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ebr'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1144     \textcolor{stringliteral}{'Remaining thickness entrained from below'}, \textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1145   cs\%id\_eta\_pre\_distribute = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'eta\_pre\_distribute'}, \&}
\DoxyCodeLine{1146     diag\%axesT1, time, \textcolor{stringliteral}{'Total water column height before residual transport redistribution'},\textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1147   cs\%id\_eta\_post\_distribute = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'eta\_post\_distribute'}, \&}
\DoxyCodeLine{1148     diag\%axesT1, time, \textcolor{stringliteral}{'Total water column height after residual transport redistribution'},\textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1149   cs\%id\_eta\_diff\_end = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'eta\_diff\_end'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1150     \textcolor{stringliteral}{'Difference in total water column height from online and offline '} // \&}
\DoxyCodeLine{1151     \textcolor{stringliteral}{'at the end of the offline timestep'},\textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1152   cs\%id\_h\_redist = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'h\_redist'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1153     \textcolor{stringliteral}{'Layer thicknesses before redistribution of mass fluxes'},\textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1154 }
\DoxyCodeLine{1155   \textcolor{comment}{! Regridded/remapped input fields}}
\DoxyCodeLine{1156   cs\%id\_uhtr\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhtr\_regrid'}, diag\%axesCuL, time, \&}
\DoxyCodeLine{1157                                           \textcolor{stringliteral}{'Zonal mass transport regridded/remapped onto offline grid'},\textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1158   cs\%id\_vhtr\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhtr\_regrid'}, diag\%axesCvL, time, \&}
\DoxyCodeLine{1159                                           \textcolor{stringliteral}{'Meridional mass transport regridded/remapped onto offline grid'},\textcolor{stringliteral}{'kg'})}
\DoxyCodeLine{1160   cs\%id\_temp\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'temp\_regrid'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1161                                           \textcolor{stringliteral}{'Temperature regridded/remapped onto offline grid'},\textcolor{stringliteral}{'C'})}
\DoxyCodeLine{1162   cs\%id\_salt\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'salt\_regrid'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1163                                           \textcolor{stringliteral}{'Salinity regridded/remapped onto offline grid'},\textcolor{stringliteral}{'g kg-1'})}
\DoxyCodeLine{1164   cs\%id\_h\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h\_regrid'}, diag\%axesTL, time, \&}
\DoxyCodeLine{1165                                           \textcolor{stringliteral}{'Layer thicknesses regridded/remapped onto offline grid'},\textcolor{stringliteral}{'m'})}
\DoxyCodeLine{1166 }
\DoxyCodeLine{1167 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a713ee3448313842b0f07a5a750a01c60}\label{namespacemom__offline__main_a713ee3448313842b0f07a5a750a01c60}} 
\index{mom\_offline\_main@{mom\_offline\_main}!remaining\_transport\_sum@{remaining\_transport\_sum}}
\index{remaining\_transport\_sum@{remaining\_transport\_sum}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{remaining\_transport\_sum()}{remaining\_transport\_sum()}}
{\footnotesize\ttfamily real function mom\+\_\+offline\+\_\+main\+::remaining\+\_\+transport\+\_\+sum (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szib\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(in)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(cs\%g),szjb\+\_\+(cs\%g),szk\+\_\+(cs\%g)), intent(in)}]{vhtr }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sums any non-\/negligible remaining transport to check for advection convergence. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & control structure for offline module \\
\hline
\mbox{\texttt{ in}}  & {\em uhtr} & Zonal mass transport \\
\hline
\mbox{\texttt{ in}}  & {\em vhtr} & Meridional mass transport \\
\hline
\end{DoxyParams}


Definition at line 619 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{619   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}  :: CS\textcolor{comment}{ !< control structure for offline module}}
\DoxyCodeLine{620 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))}, \textcolor{keywordtype}{intent(in   )}  :: uhtr\textcolor{comment}{  !< Zonal mass transport}}
\DoxyCodeLine{621 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJB\_(CS\%G),SZK\_(CS\%G))}, \textcolor{keywordtype}{intent(in   )}  :: vhtr\textcolor{comment}{  !< Meridional mass transport}}
\DoxyCodeLine{622 }
\DoxyCodeLine{623   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{624   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{625   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz}
\DoxyCodeLine{626 \textcolor{keywordtype}{  real} :: h\_min\textcolor{comment}{ !< A layer thickness below roundoff from GV type}}
\DoxyCodeLine{627 \textcolor{keywordtype}{  real} :: uh\_neglect\textcolor{comment}{ !< A small value of zonal transport that effectively is below roundoff error}}
\DoxyCodeLine{628 \textcolor{keywordtype}{  real} :: vh\_neglect\textcolor{comment}{ !< A small value of meridional transport that effectively is below roundoff error}}
\DoxyCodeLine{629 }
\DoxyCodeLine{630   nz = cs\%GV\%ke}
\DoxyCodeLine{631   is = cs\%G\%isc ; ie = cs\%G\%iec ; js = cs\%G\%jsc ; je = cs\%G\%jec}
\DoxyCodeLine{632 }
\DoxyCodeLine{633   h\_min = cs\%GV\%H\_subroundoff}
\DoxyCodeLine{634 }
\DoxyCodeLine{635   remaining\_transport\_sum = 0.}
\DoxyCodeLine{636   \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{637     uh\_neglect = h\_min*cs\%G\%US\%L\_to\_m**2*min(cs\%G\%areaT(i,j),cs\%G\%areaT(i+1,j))}
\DoxyCodeLine{638     vh\_neglect = h\_min*cs\%G\%US\%L\_to\_m**2*min(cs\%G\%areaT(i,j),cs\%G\%areaT(i,j+1))}
\DoxyCodeLine{639     \textcolor{keywordflow}{if} (abs(uhtr(i,j,k))>uh\_neglect) \textcolor{keywordflow}{then}}
\DoxyCodeLine{640       remaining\_transport\_sum = remaining\_transport\_sum + abs(uhtr(i,j,k))}
\DoxyCodeLine{641 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{642     \textcolor{keywordflow}{if} (abs(vhtr(i,j,k))>vh\_neglect) \textcolor{keywordflow}{then}}
\DoxyCodeLine{643       remaining\_transport\_sum = remaining\_transport\_sum + abs(vhtr(i,j,k))}
\DoxyCodeLine{644 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{645 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{646   \textcolor{keyword}{call }sum\_across\_pes(remaining\_transport\_sum)}
\DoxyCodeLine{647 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__main_a2e59b996b88713928c04f72d57c5a531}\label{namespacemom__offline__main_a2e59b996b88713928c04f72d57c5a531}} 
\index{mom\_offline\_main@{mom\_offline\_main}!update\_offline\_fields@{update\_offline\_fields}}
\index{update\_offline\_fields@{update\_offline\_fields}!mom\_offline\_main@{mom\_offline\_main}}
\subsubsection{\texorpdfstring{update\_offline\_fields()}{update\_offline\_fields()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+main\+::update\+\_\+offline\+\_\+fields (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__offline__main_1_1offline__transport__cs}{offline\+\_\+transport\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(cs\%g),szj\+\_\+(cs\%g),szk\+\_\+(cs\%g))}]{h,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{logical, intent(in)}]{do\+\_\+ale }\end{DoxyParamCaption})}



Update fields used in this round of offline transport. First fields are updated from files or from arrays read during initialization. Then if in an A\+L\+E-\/dependent coordinate, regrid/remap fields. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure for offline module \\
\hline
 & {\em h} & The regridded layer thicknesses \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & Pointers to forcing fields \\
\hline
\mbox{\texttt{ in}}  & {\em do\+\_\+ale} & True if using A\+LE \\
\hline
\end{DoxyParams}


Definition at line 1019 of file M\+O\+M\+\_\+offline\+\_\+main.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1019   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}               :: CS\textcolor{comment}{ !< Control structure for offline module}}
\DoxyCodeLine{1020 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: h\textcolor{comment}{ !< The regridded layer thicknesses}}
\DoxyCodeLine{1021   \textcolor{keywordtype}{type}(forcing),        \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Pointers to forcing fields}}
\DoxyCodeLine{1022   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in   )} :: do\_ale\textcolor{comment}{ !< True if using ALE}}
\DoxyCodeLine{1023   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1024   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{1025 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(CS\%G),SZJ\_(CS\%G),SZK\_(CS\%G))} :: h\_start}
\DoxyCodeLine{1026   is = cs\%G\%isc ; ie = cs\%G\%iec ; js = cs\%G\%jsc ; je = cs\%G\%jec ; nz = cs\%GV\%ke}
\DoxyCodeLine{1027 }
\DoxyCodeLine{1028   \textcolor{keyword}{call }cpu\_clock\_begin(cs\%id\_clock\_read\_fields)}
\DoxyCodeLine{1029   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"update\_offline\_fields, MOM\_offline\_main.F90"})}
\DoxyCodeLine{1030 }
\DoxyCodeLine{1031   \textcolor{comment}{! Store a copy of the layer thicknesses before ALE regrid/remap}}
\DoxyCodeLine{1032   h\_start(:,:,:) = h(:,:,:)}
\DoxyCodeLine{1033 }
\DoxyCodeLine{1034   \textcolor{comment}{! Most fields will be read in from files}}
\DoxyCodeLine{1035   \textcolor{keyword}{call }update\_offline\_from\_files( cs\%G, cs\%GV, cs\%nk\_input, cs\%mean\_file, cs\%sum\_file, cs\%snap\_file, cs\%surf\_file,    \&}
\DoxyCodeLine{1036                                   cs\%h\_end, cs\%uhtr, cs\%vhtr, cs\%tv\%T, cs\%tv\%S, cs\%mld, cs\%Kd, fluxes,                \&}
\DoxyCodeLine{1037                                   cs\%ridx\_sum, cs\%ridx\_snap, cs\%read\_mld, cs\%read\_sw, .not. cs\%read\_all\_ts\_uvh, do\_ale)}
\DoxyCodeLine{1038   \textcolor{comment}{! If uh, vh, h\_end, temp, salt were read in at the beginning, fields are copied from those arrays}}
\DoxyCodeLine{1039   \textcolor{keywordflow}{if} (cs\%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1040       \textcolor{keyword}{call }update\_offline\_from\_arrays(cs\%G, cs\%GV, cs\%nk\_input, cs\%ridx\_sum, cs\%mean\_file, cs\%sum\_file, cs\%snap\_file, \&}
\DoxyCodeLine{1041         cs\%uhtr, cs\%vhtr, cs\%h\_end, cs\%uhtr\_all, cs\%vhtr\_all, cs\%hend\_all, cs\%tv\%T, cs\%tv\%S, cs\%temp\_all, cs\%salt\_all)}
\DoxyCodeLine{1042 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1043   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1044     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]h after update offline from files and arrays"}, cs\%uhtr, cs\%vhtr, cs\%G\%HI)}
\DoxyCodeLine{1045 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1046 }
\DoxyCodeLine{1047   \textcolor{comment}{! If using an ALE-dependent vertical coordinate, fields will need to be remapped}}
\DoxyCodeLine{1048   \textcolor{keywordflow}{if} (do\_ale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1049     \textcolor{comment}{! These halo passes are necessary because u, v fields will need information 1 step into the halo}}
\DoxyCodeLine{1050     \textcolor{keyword}{call }pass\_var(h, cs\%G\%Domain)}
\DoxyCodeLine{1051     \textcolor{keyword}{call }pass\_var(cs\%tv\%T, cs\%G\%Domain)}
\DoxyCodeLine{1052     \textcolor{keyword}{call }pass\_var(cs\%tv\%S, cs\%G\%Domain)}
\DoxyCodeLine{1053     \textcolor{keyword}{call }ale\_offline\_inputs(cs\%ALE\_CSp, cs\%G, cs\%GV, h, cs\%tv, cs\%tracer\_Reg, cs\%uhtr, cs\%vhtr, cs\%Kd, \&}
\DoxyCodeLine{1054                             cs\%debug, cs\%OBC)}
\DoxyCodeLine{1055     \textcolor{keywordflow}{if} (cs\%id\_temp\_regrid>0) \textcolor{keyword}{call }post\_data(cs\%id\_temp\_regrid, cs\%tv\%T, cs\%diag)}
\DoxyCodeLine{1056     \textcolor{keywordflow}{if} (cs\%id\_salt\_regrid>0) \textcolor{keyword}{call }post\_data(cs\%id\_salt\_regrid, cs\%tv\%S, cs\%diag)}
\DoxyCodeLine{1057     \textcolor{keywordflow}{if} (cs\%id\_uhtr\_regrid>0) \textcolor{keyword}{call }post\_data(cs\%id\_uhtr\_regrid, cs\%uhtr, cs\%diag)}
\DoxyCodeLine{1058     \textcolor{keywordflow}{if} (cs\%id\_vhtr\_regrid>0) \textcolor{keyword}{call }post\_data(cs\%id\_vhtr\_regrid, cs\%vhtr, cs\%diag)}
\DoxyCodeLine{1059     \textcolor{keywordflow}{if} (cs\%id\_h\_regrid>0) \textcolor{keyword}{call }post\_data(cs\%id\_h\_regrid, h, cs\%diag)}
\DoxyCodeLine{1060     \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1061       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]h after ALE regridding/remapping of inputs"}, cs\%uhtr, cs\%vhtr, cs\%G\%HI)}
\DoxyCodeLine{1062       \textcolor{keyword}{call }hchksum(h\_start,\textcolor{stringliteral}{"h\_start after update offline from files and arrays"}, cs\%G\%HI)}
\DoxyCodeLine{1063 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1064 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1065 }
\DoxyCodeLine{1066   \textcolor{comment}{! Update halos for some}}
\DoxyCodeLine{1067   \textcolor{keyword}{call }pass\_var(cs\%h\_end, cs\%G\%Domain)}
\DoxyCodeLine{1068   \textcolor{keyword}{call }pass\_var(cs\%tv\%T, cs\%G\%Domain)}
\DoxyCodeLine{1069   \textcolor{keyword}{call }pass\_var(cs\%tv\%S, cs\%G\%Domain)}
\DoxyCodeLine{1070 }
\DoxyCodeLine{1071   \textcolor{comment}{! Update the read indices}}
\DoxyCodeLine{1072   cs\%ridx\_snap = next\_modulo\_time(cs\%ridx\_snap,cs\%numtime)}
\DoxyCodeLine{1073   cs\%ridx\_sum = next\_modulo\_time(cs\%ridx\_sum,cs\%numtime)}
\DoxyCodeLine{1074 }
\DoxyCodeLine{1075   \textcolor{comment}{! Apply masks/factors at T, U, and V points}}
\DoxyCodeLine{1076   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1077     \textcolor{keywordflow}{if} (cs\%G\%mask2dT(i,j)<1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1078       cs\%h\_end(i,j,k) = cs\%GV\%Angstrom\_H}
\DoxyCodeLine{1079 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1080 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1081 }
\DoxyCodeLine{1082   \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1083     cs\%Kd(i,j,k) = max(0.0, cs\%Kd(i,j,k))}
\DoxyCodeLine{1084     \textcolor{keywordflow}{if} (cs\%Kd\_max>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1085       cs\%Kd(i,j,k) = min(cs\%Kd\_max, cs\%Kd(i,j,k))}
\DoxyCodeLine{1086 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1087 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1088 }
\DoxyCodeLine{1089   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1090     \textcolor{keywordflow}{if} (cs\%G\%mask2dCv(i,j)<1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1091       cs\%vhtr(i,j,k) = 0.0}
\DoxyCodeLine{1092 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1093 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1094 }
\DoxyCodeLine{1095   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie}
\DoxyCodeLine{1096     \textcolor{keywordflow}{if} (cs\%G\%mask2dCu(i,j)<1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1097       cs\%uhtr(i,j,k) = 0.0}
\DoxyCodeLine{1098 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1099 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1100 }
\DoxyCodeLine{1101   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1102     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]htr\_sub after update\_offline\_fields"}, cs\%uhtr, cs\%vhtr, cs\%G\%HI)}
\DoxyCodeLine{1103     \textcolor{keyword}{call }hchksum(cs\%h\_end, \textcolor{stringliteral}{"h\_end after update\_offline\_fields"}, cs\%G\%HI)}
\DoxyCodeLine{1104     \textcolor{keyword}{call }hchksum(cs\%tv\%T, \textcolor{stringliteral}{"Temp after update\_offline\_fields"}, cs\%G\%HI)}
\DoxyCodeLine{1105     \textcolor{keyword}{call }hchksum(cs\%tv\%S, \textcolor{stringliteral}{"Salt after update\_offline\_fields"}, cs\%G\%HI)}
\DoxyCodeLine{1106 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1107 }
\DoxyCodeLine{1108   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"update\_offline\_fields"})}
\DoxyCodeLine{1109   \textcolor{keyword}{call }cpu\_clock\_end(cs\%id\_clock\_read\_fields)}
\DoxyCodeLine{1110 }

\end{DoxyCode}
