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


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


\begin{DoxyCode}
846   \textcolor{keywordtype}{type}(forcing),              \textcolor{keywordtype}{intent(inout)}    :: fluxes\textcolor{comment}{        !< pointers to forcing fields}
847   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{intent(in)}       :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time
       type}
848   \textcolor{keywordtype}{real},                       \textcolor{keywordtype}{intent(in)}       :: time\_interval\textcolor{comment}{ !< Offline transport time interval}
849   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}          :: CS\textcolor{comment}{            !< Control structure for offline module}
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}
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}
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}
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}
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}
855   \textcolor{comment}{! Local pointers}
856   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}
857                                                       \textcolor{comment}{! metrics and related information}
858   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}
859                                                       \textcolor{comment}{! about the vertical grid}
860   \textcolor{comment}{! Remaining zonal mass transports}
861   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))}   :: uhtr\_sub
862   \textcolor{comment}{! Remaining meridional mass transports}
863   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJB\_(CS%G),SZK\_(CS%G))}   :: vhtr\_sub
864 
865   \textcolor{keywordtype}{real} :: sum\_abs\_fluxes, sum\_u, sum\_v  \textcolor{comment}{! Used to keep track of how close to convergence we are}
866   \textcolor{keywordtype}{real} :: dt\_offline
867 
868   \textcolor{comment}{! Local variables}
869   \textcolor{comment}{! Vertical diffusion related variables}
870   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: &
871       eatr\_sub, &
872       ebtr\_sub
873   \textcolor{comment}{! Variables used to keep track of layer thicknesses at various points in the code}
874   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: &
875       h\_new, &
876       h\_vol
877   \textcolor{comment}{! Work arrays for temperature and salinity}
878   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: &
879       temp\_old, salt\_old, &
880       temp\_mean, salt\_mean, &
881       zero\_3dh     \textcolor{comment}{!}
882   \textcolor{keywordtype}{integer} :: niter, iter
883   \textcolor{keywordtype}{real}    :: Inum\_iter
884   \textcolor{keywordtype}{real}    :: dt\_iter  \textcolor{comment}{! The timestep of each iteration [T ~> s]}
885   \textcolor{keywordtype}{logical} :: converged
886   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}
887   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz
888   \textcolor{keywordtype}{integer} :: isv, iev, jsv, jev \textcolor{comment}{! The valid range of the indices.}
889   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
890   \textcolor{keywordtype}{logical} :: z\_first, x\_before\_y
891 
892   g => cs%G ; gv => cs%GV
893   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
894   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
895   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
896 
897   dt\_iter = cs%US%s\_to\_T * time\_interval / \textcolor{keywordtype}{real}(max(1, CS%num\_off\_iter))
898 
899   \textcolor{keywordflow}{do} iter=1,cs%num\_off\_iter
900 
901     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
902       eatr\_sub(i,j,k) = eatr(i,j,k)
903       ebtr\_sub(i,j,k) = ebtr(i,j,k)
904 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
905 
906     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ie+1
907       uhtr\_sub(i,j,k) = uhtr(i,j,k)
908 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
909 
910     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-2,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
911       vhtr\_sub(i,j,k) = vhtr(i,j,k)
912 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
913 
914 
915     \textcolor{comment}{! Calculate 3d mass transports to be used in this iteration}
916     \textcolor{keyword}{call }limit\_mass\_flux\_3d(g, gv, uhtr\_sub, vhtr\_sub, eatr\_sub, ebtr\_sub, h\_pre)
917 
918     \textcolor{keywordflow}{if} (z\_first) \textcolor{keywordflow}{then}
919       \textcolor{comment}{! First do vertical advection}
920       \textcolor{keyword}{call }update\_h\_vertical\_flux(g, gv, eatr\_sub, ebtr\_sub, h\_pre, h\_new)
921       \textcolor{keyword}{call }call\_tracer\_column\_fns(h\_pre, h\_new, eatr\_sub, ebtr\_sub, &
922           fluxes, cs%mld, dt\_iter, g, gv, cs%US, cs%tv, cs%optics, cs%tracer\_flow\_CSp, cs%debug)
923       \textcolor{comment}{! We are now done with the vertical mass transports, so now h\_new is h\_sub}
924       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
925         h\_pre(i,j,k) = h\_new(i,j,k)
926 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
927       \textcolor{keyword}{call }pass\_var(h\_pre,g%Domain)
928 
929       \textcolor{comment}{! Second zonal and meridional advection}
930       \textcolor{keyword}{call }update\_h\_horizontal\_flux(g, gv, uhtr\_sub, vhtr\_sub, h\_pre, h\_new)
931       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i = is-1, ie+1 ; \textcolor{keywordflow}{do} j=js-1, je+1
932         h\_vol(i,j,k) = h\_pre(i,j,k)*g%US%L\_to\_m**2*g%areaT(i,j)
933 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
934       \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr\_sub, vhtr\_sub, cs%OBC, dt\_iter, g, gv, cs%US, &
935           cs%tracer\_adv\_CSp, cs%tracer\_Reg, h\_vol, max\_iter\_in=30, x\_first\_in=x\_before\_y)
936 
937       \textcolor{comment}{! Done with horizontal so now h\_pre should be h\_new}
938       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1
939           h\_pre(i,j,k) = h\_new(i,j,k)
940 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
941 
942 \textcolor{keywordflow}{    endif}
943 
944     \textcolor{keywordflow}{if} (.not. z\_first) \textcolor{keywordflow}{then}
945 
946       \textcolor{comment}{! First zonal and meridional advection}
947       \textcolor{keyword}{call }update\_h\_horizontal\_flux(g, gv, uhtr\_sub, vhtr\_sub, h\_pre, h\_new)
948       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i = is-1, ie+1 ; \textcolor{keywordflow}{do} j=js-1, je+1
949         h\_vol(i,j,k) = h\_pre(i,j,k)*g%US%L\_to\_m**2*g%areaT(i,j)
950 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
951       \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr\_sub, vhtr\_sub, cs%OBC, dt\_iter, g, gv, cs%US, &
952           cs%tracer\_adv\_CSp, cs%tracer\_Reg, h\_vol, max\_iter\_in=30, x\_first\_in=x\_before\_y)
953 
954       \textcolor{comment}{! Done with horizontal so now h\_pre should be h\_new}
955       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1
956           h\_pre(i,j,k) = h\_new(i,j,k)
957 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
958 
959       \textcolor{comment}{! Second vertical advection}
960       \textcolor{keyword}{call }update\_h\_vertical\_flux(g, gv, eatr\_sub, ebtr\_sub, h\_pre, h\_new)
961       \textcolor{keyword}{call }call\_tracer\_column\_fns(h\_pre, h\_new, eatr\_sub, ebtr\_sub, &
962           fluxes, cs%mld, dt\_iter, g, gv, cs%US, cs%tv, cs%optics, cs%tracer\_flow\_CSp, cs%debug)
963       \textcolor{comment}{! We are now done with the vertical mass transports, so now h\_new is h\_sub}
964       \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1
965         h\_pre(i,j,k) = h\_new(i,j,k)
966 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
967 
968 \textcolor{keywordflow}{    endif}
969 
970     \textcolor{comment}{! Update remaining transports}
971     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
972       eatr(i,j,k) = eatr(i,j,k) - eatr\_sub(i,j,k)
973       ebtr(i,j,k) = ebtr(i,j,k) - ebtr\_sub(i,j,k)
974 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
975 
976     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ie+1
977       uhtr(i,j,k) = uhtr(i,j,k) - uhtr\_sub(i,j,k)
978 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
979 
980     \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-2,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
981       vhtr(i,j,k) = vhtr(i,j,k) - vhtr\_sub(i,j,k)
982 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
983 
984     \textcolor{keyword}{call }pass\_var(eatr,g%Domain)
985     \textcolor{keyword}{call }pass\_var(ebtr,g%Domain)
986     \textcolor{keyword}{call }pass\_var(h\_pre,g%Domain)
987     \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g%Domain)
988   \textcolor{comment}{!}
989     \textcolor{comment}{! Calculate how close we are to converging by summing the remaining fluxes at each point}
990     sum\_abs\_fluxes = 0.0
991     sum\_u = 0.0
992     sum\_v = 0.0
993     \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is,ie
994       sum\_u = sum\_u + abs(uhtr(i-1,j,k))+abs(uhtr(i,j,k))
995       sum\_v = sum\_v + abs(vhtr(i,j-1,k))+abs(vhtr(i,j,k))
996       sum\_abs\_fluxes = sum\_abs\_fluxes + abs(eatr(i,j,k)) + abs(ebtr(i,j,k)) + abs(uhtr(i-1,j,k)) + &
997           abs(uhtr(i,j,k)) + abs(vhtr(i,j-1,k)) + abs(vhtr(i,j,k))
998 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
999     \textcolor{keyword}{call }sum\_across\_pes(sum\_abs\_fluxes)
1000 
1001     \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"offline\_advection\_layer: Remaining u-flux, v-flux:"}, sum\_u, sum\_v
1002     \textcolor{keyword}{call }mom\_mesg(mesg)
1003     \textcolor{keywordflow}{if} (sum\_abs\_fluxes==0) \textcolor{keywordflow}{then}
1004       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'offline\_advection\_layer: Converged after iteration'}, iter
1005       \textcolor{keyword}{call }mom\_mesg(mesg)
1006       \textcolor{keywordflow}{exit}
1007 \textcolor{keywordflow}{    endif}
1008 
1009     \textcolor{comment}{! Switch order of Strang split every iteration}
1010     z\_first = .not. z\_first
1011     x\_before\_y = .not. x\_before\_y
1012 \textcolor{keywordflow}{  enddo}
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{\tt in,out}  & {\em fluxes} & pointers to forcing fields\\
\hline
\mbox{\tt in}  & {\em time\+\_\+start} & starting time of a segment, as a time type\\
\hline
\mbox{\tt in}  & {\em time\+\_\+end} & time interval\\
\hline
 & {\em cs} & control structure from initialize\+\_\+\+M\+OM\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+pre} & layer thicknesses before advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em eatr} & Entrainment from layer above \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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}
654 
655   \textcolor{keywordtype}{type}(forcing),    \textcolor{keywordtype}{intent(inout)}      :: fluxes\textcolor{comment}{     !< pointers to forcing fields}
656   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{intent(in)}         :: Time\_start\textcolor{comment}{ !< starting time of a segment, as a time type}
657   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{intent(in)}         :: Time\_end\textcolor{comment}{   !< time interval}
658   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}  :: CS\textcolor{comment}{         !< control structure from initialize\_MOM}
659   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))}, &
660                     \textcolor{keywordtype}{intent(inout)}      :: h\_pre\textcolor{comment}{      !< layer thicknesses before advection [H ~> m or kg
       m-2]}
661   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))}, &
662                     \textcolor{keywordtype}{intent(inout)}      :: eatr\textcolor{comment}{       !< Entrainment from layer above [H ~> m or kg m-2]}
663   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))}, &
664                     \textcolor{keywordtype}{intent(inout)}      :: ebtr\textcolor{comment}{       !< Entrainment from layer below [H ~> m or kg m-2]}
665 
666   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G))} :: &
667     sw, sw\_vis, sw\_nir\textcolor{comment}{ !< Save old values of shortwave radiation [Q R Z T-1 ~> W m-2]}
668   \textcolor{keywordtype}{real} :: hval
669   \textcolor{keywordtype}{integer} :: i,j,k
670   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz
671   \textcolor{keywordtype}{integer} :: k\_nonzero
672   \textcolor{keywordtype}{real} :: stock\_values(MAX\_FIELDS\_)
673   \textcolor{keywordtype}{real} :: Kd\_bot
674   \textcolor{keywordtype}{integer} :: nstocks
675   nz = cs%GV%ke
676   is = cs%G%isc ; ie = cs%G%iec ; js = cs%G%jsc ; je = cs%G%jec
677 
678   \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_offline\_diabatic)
679 
680   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Applying tracer source, sinks, and vertical mixing"})
681 
682   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
683     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre before offline\_diabatic\_ale"},cs%G%HI)
684     \textcolor{keyword}{call }hchksum(eatr,\textcolor{stringliteral}{"eatr before offline\_diabatic\_ale"},cs%G%HI)
685     \textcolor{keyword}{call }hchksum(ebtr,\textcolor{stringliteral}{"ebtr before offline\_diabatic\_ale"},cs%G%HI)
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)
687 \textcolor{keywordflow}{  endif}
688 
689   eatr(:,:,:) = 0.
690   ebtr(:,:,:) = 0.
691   \textcolor{comment}{! Calculate eatr and ebtr if vertical diffusivity is read}
692   \textcolor{comment}{! Because the saved remapped diagnostics from the online run assume a zero minimum thickness}
693   \textcolor{comment}{! but ALE may have a minimum thickness. Flood the diffusivities for all layers with the value}
694   \textcolor{comment}{! of Kd closest to the bottom which is non-zero}
695   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
696     k\_nonzero = nz+1
697     \textcolor{comment}{! Find the nonzero bottom Kd}
698     \textcolor{keywordflow}{do} k=nz+1,1,-1
699       \textcolor{keywordflow}{if} (cs%Kd(i,j,k)>0.) \textcolor{keywordflow}{then}
700         kd\_bot = cs%Kd(i,j,k)
701         k\_nonzero = k
702         \textcolor{keywordflow}{exit}
703 \textcolor{keywordflow}{      endif}
704 \textcolor{keywordflow}{    enddo}
705     \textcolor{comment}{! Flood the bottom interfaces}
706     \textcolor{keywordflow}{do} k=k\_nonzero,nz+1
707       cs%Kd(i,j,k) = kd\_bot
708 \textcolor{keywordflow}{    enddo}
709 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
710 
711   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
712     eatr(i,j,1) = 0.
713 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
714   \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
715     hval=1.0/(cs%GV%H\_subroundoff + 0.5*(h\_pre(i,j,k-1) + h\_pre(i,j,k)))
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)
717     ebtr(i,j,k-1) = eatr(i,j,k)
718 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
719   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
720     ebtr(i,j,nz) = 0.
721 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
722 
723   \textcolor{comment}{! Add diurnal cycle for shortwave radiation (only used if run in ocean-only mode)}
724   \textcolor{keywordflow}{if} (cs%diurnal\_SW .and. cs%read\_sw) \textcolor{keywordflow}{then}
725     sw(:,:) = fluxes%sw(:,:)
726     sw\_vis(:,:) = fluxes%sw\_vis\_dir(:,:)
727     sw\_nir(:,:) = fluxes%sw\_nir\_dir(:,:)
728     \textcolor{keyword}{call }offline\_add\_diurnal\_sw(fluxes, cs%G, time\_start, time\_end)
729 \textcolor{keywordflow}{  endif}
730 
731   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%optics)) &
732     \textcolor{keyword}{call }set\_pen\_shortwave(cs%optics, fluxes, cs%G, cs%GV, cs%US, cs%diabatic\_aux\_CSp, &
733                            cs%opacity\_CSp, cs%tracer\_flow\_CSp)
734 
735   \textcolor{comment}{! Note that tracerBoundaryFluxesInOut within this subroutine should NOT be called}
736   \textcolor{comment}{! as the freshwater fluxes have already been accounted for}
737   \textcolor{keyword}{call }call\_tracer\_column\_fns(h\_pre, h\_pre, eatr, ebtr, fluxes, cs%MLD, cs%dt\_offline\_vertical, &
738                               cs%G, cs%GV, cs%US, cs%tv, cs%optics, cs%tracer\_flow\_CSp, cs%debug)
739 
740   \textcolor{keywordflow}{if} (cs%diurnal\_SW .and. cs%read\_sw) \textcolor{keywordflow}{then}
741     fluxes%sw(:,:) = sw(:,:)
742     fluxes%sw\_vis\_dir(:,:) = sw\_vis(:,:)
743     fluxes%sw\_nir\_dir(:,:) = sw\_nir(:,:)
744 \textcolor{keywordflow}{  endif}
745 
746   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
747     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre after offline\_diabatic\_ale"},cs%G%HI)
748     \textcolor{keyword}{call }hchksum(eatr,\textcolor{stringliteral}{"eatr after offline\_diabatic\_ale"},cs%G%HI)
749     \textcolor{keyword}{call }hchksum(ebtr,\textcolor{stringliteral}{"ebtr after offline\_diabatic\_ale"},cs%G%HI)
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)
751 \textcolor{keywordflow}{  endif}
752 
753   \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_offline\_diabatic)
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{\tt in,out}  & {\em cs} & Offline control structure\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in,out}  & {\em fluxes} & Surface fluxes container\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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}
760   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Offline control structure}
761   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}
762   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}
763   \textcolor{keywordtype}{type}(forcing),              \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Surface fluxes container}
764   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
765                               \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
766   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
767                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: in\_flux\_optional\textcolor{comment}{ !< The total time-integrated amount}
768 \textcolor{comment}{                                                  !! of tracer that leaves with freshwater}
769 
770   \textcolor{keywordtype}{integer} :: i, j, m
771   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: negative\_fw\textcolor{comment}{ !< store all negative fluxes}
772   \textcolor{keywordtype}{logical} :: update\_h\textcolor{comment}{ !< Flag for whether h should be updated}
773 
774   \textcolor{keywordflow}{if} ( \textcolor{keyword}{present}(in\_flux\_optional) ) &
775     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Positive freshwater fluxes with non-zero tracer concentration not supported
       yet"})
776 
777   \textcolor{comment}{! Set all fluxes to 0}
778   negative\_fw(:,:) = 0.
779 
780   \textcolor{comment}{! Sort fluxes into positive and negative}
781   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
782     \textcolor{keywordflow}{if} (fluxes%netMassOut(i,j)<0.0) \textcolor{keywordflow}{then}
783       negative\_fw(i,j) = fluxes%netMassOut(i,j)
784       fluxes%netMassOut(i,j) = 0.
785 \textcolor{keywordflow}{    endif}
786 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
787 
788   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
789     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h before fluxes into ocean"},g%HI)
790     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before fluxes into ocean"}, g, h, cs%tracer\_reg%Tr, cs%tracer\_reg%ntr)
791 \textcolor{keywordflow}{  endif}
792   \textcolor{keywordflow}{do} m = 1,cs%tracer\_reg%ntr
793     \textcolor{comment}{! Layer thicknesses should only be updated after the last tracer is finished}
794     update\_h = ( m == cs%tracer\_reg%ntr )
795     \textcolor{keyword}{call }applytracerboundaryfluxesinout(g, gv, cs%tracer\_reg%tr(m)%t, cs%dt\_offline, fluxes, h, &
796                                         cs%evap\_CFL\_limit, cs%minimum\_forcing\_depth, update\_h\_opt = 
      update\_h)
797 \textcolor{keywordflow}{  enddo}
798   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
799     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h after fluxes into ocean"},g%HI)
800     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"After fluxes into ocean"}, g, h, cs%tracer\_reg%Tr, cs%tracer\_reg%ntr)
801 \textcolor{keywordflow}{  endif}
802 
803   \textcolor{comment}{! Now that fluxes into the ocean are done, save the negative fluxes for later}
804   fluxes%netMassOut(:,:) = negative\_fw(:,:)
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{\tt in,out}  & {\em cs} & Offline control structure\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in,out}  & {\em fluxes} & Surface fluxes container\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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}
810   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Offline control structure}
811   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}
812   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}
813   \textcolor{keywordtype}{type}(forcing),              \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Surface fluxes container}
814   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
815                               \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
816   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
817                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: out\_flux\_optional\textcolor{comment}{ !< The total time-integrated amount}
818 \textcolor{comment}{                                                  !! of tracer that leaves with freshwater}
819 
820   \textcolor{keywordtype}{integer} :: m
821   \textcolor{keywordtype}{logical} :: update\_h\textcolor{comment}{ !< Flag for whether h should be updated}
822 
823   \textcolor{keywordflow}{if} ( \textcolor{keyword}{present}(out\_flux\_optional) ) &
824     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Negative freshwater fluxes with non-zero tracer concentration not supported
       yet"})
825 
826   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
827     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h before fluxes out of ocean"},g%HI)
828     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before fluxes out of ocean"}, g, h, cs%tracer\_reg%Tr, cs%tracer\_reg%ntr)
829 \textcolor{keywordflow}{  endif}
830   \textcolor{keywordflow}{do} m = 1, cs%tracer\_reg%ntr
831     \textcolor{comment}{! Layer thicknesses should only be updated after the last tracer is finished}
832     update\_h = ( m == cs%tracer\_reg%ntr )
833     \textcolor{keyword}{call }applytracerboundaryfluxesinout(g, gv, cs%tracer\_reg%tr(m)%t, cs%dt\_offline, fluxes, h, &
834                                         cs%evap\_CFL\_limit, cs%minimum\_forcing\_depth, update\_h\_opt = 
      update\_h)
835 \textcolor{keywordflow}{  enddo}
836   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
837     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"h after fluxes out of ocean"},g%HI)
838     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before fluxes out of ocean"}, g, h, cs%tracer\_reg%Tr, cs%tracer\_reg%ntr)
839 \textcolor{keywordflow}{  endif}
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{\tt in,out}  & {\em h\+\_\+pre} & layer thicknesses before advection\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Zonal mass transport\\
\hline
\mbox{\tt in,out}  & {\em vhtr} & Meridional mass transport\\
\hline
\mbox{\tt 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}
423   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< control structure from initialize\_MOM}
424   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))}, &
425                               \textcolor{keywordtype}{intent(inout)} :: h\_pre\textcolor{comment}{ !< layer thicknesses before advection}
426   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))}, &
427                               \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{  !< Zonal mass transport}
428   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJB\_(CS%G),SZK\_(CS%G))}, &
429                               \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{  !< Meridional mass transport}
430   \textcolor{keywordtype}{logical},                    \textcolor{keywordtype}{intent(in   )} :: converged\textcolor{comment}{ !< True if the iterations have converged}
431 
432   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}
433                                                       \textcolor{comment}{! metrics and related information}
434   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}
435                                                       \textcolor{comment}{! about the vertical grid}
436   \textcolor{keywordtype}{logical} :: x\_before\_y
437   \textcolor{comment}{! Variables used to keep track of layer thicknesses at various points in the code}
438   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: &
439       h\_new, &
440       h\_vol
441 
442   \textcolor{comment}{! Used to calculate the eta diagnostics}
443   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G))} :: eta\_work
444   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: uhr\textcolor{comment}{  !< Zonal mass transport}
445   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJB\_(CS%G),SZK\_(CS%G))} :: vhr\textcolor{comment}{  !< Meridional mass transport}
446 
447   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}
448   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz, iter
449   \textcolor{keywordtype}{real} :: prev\_tot\_residual, tot\_residual, stock\_values(MAX\_FIELDS\_)
450   \textcolor{keywordtype}{integer} :: nstocks
451 
452   \textcolor{comment}{! Assign grid pointers}
453   g  => cs%G
454   gv => cs%GV
455 
456   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
457   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
458 
459   x\_before\_y = cs%x\_before\_y
460 
461   \textcolor{keywordflow}{if} (cs%id\_eta\_pre\_distribute>0) \textcolor{keywordflow}{then}
462     eta\_work(:,:) = 0.0
463     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
464       \textcolor{keywordflow}{if} (h\_pre(i,j,k)>gv%Angstrom\_H) \textcolor{keywordflow}{then}
465         eta\_work(i,j) = eta\_work(i,j) + h\_pre(i,j,k)
466 \textcolor{keywordflow}{      endif}
467 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
468     \textcolor{keyword}{call }post\_data(cs%id\_eta\_pre\_distribute,eta\_work,cs%diag)
469 \textcolor{keywordflow}{  endif}
470 
471   \textcolor{comment}{! These are used to find out how much will be redistributed in this routine}
472   \textcolor{keywordflow}{if} (cs%id\_h\_redist>0) \textcolor{keyword}{call }post\_data(cs%id\_h\_redist, h\_pre, cs%diag)
473   \textcolor{keywordflow}{if} (cs%id\_uhr\_redist>0) \textcolor{keyword}{call }post\_data(cs%id\_uhr\_redist, uhtr, cs%diag)
474   \textcolor{keywordflow}{if} (cs%id\_vhr\_redist>0) \textcolor{keyword}{call }post\_data(cs%id\_vhr\_redist, vhtr, cs%diag)
475 
476   \textcolor{keywordflow}{if} (converged) \textcolor{keywordflow}{return}
477 
478   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
479     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"Before redistribute "}, g, h\_pre, cs%tracer\_reg%Tr, cs%tracer\_reg%ntr)
480 \textcolor{keywordflow}{  endif}
481 
482   \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_redistribute)
483 
484   \textcolor{keywordflow}{if} (cs%redistribute\_upwards .or. cs%redistribute\_barotropic) \textcolor{keywordflow}{then}
485     \textcolor{keywordflow}{do} iter = 1, cs%num\_off\_iter
486 
487       \textcolor{comment}{! Perform upwards redistribution}
488       \textcolor{keywordflow}{if} (cs%redistribute\_upwards) \textcolor{keywordflow}{then}
489 
490         \textcolor{comment}{! Calculate the layer volumes at beginning of redistribute}
491         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
492           h\_vol(i,j,k) = h\_pre(i,j,k)*g%US%L\_to\_m**2*g%areaT(i,j)
493 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
494         \textcolor{keyword}{call }pass\_var(h\_vol,g%Domain)
495         \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g%Domain)
496 
497         \textcolor{comment}{! Store volumes for advect\_tracer}
498         h\_pre(:,:,:) = h\_vol(:,:,:)
499 
500         \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
501           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"Before upwards redistribute "}, cs%tracer\_Reg%Tr, cs%tracer\_Reg%ntr, g)
502           \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]tr before upwards redistribute"}, uhtr, vhtr, g%HI)
503 \textcolor{keywordflow}{        endif}
504 
505         \textcolor{keywordflow}{if} (x\_before\_y) \textcolor{keywordflow}{then}
506           \textcolor{keyword}{call }distribute\_residual\_uh\_upwards(g, gv, h\_vol, uhtr)
507           \textcolor{keyword}{call }distribute\_residual\_vh\_upwards(g, gv, h\_vol, vhtr)
508         \textcolor{keywordflow}{else}
509           \textcolor{keyword}{call }distribute\_residual\_vh\_upwards(g, gv, h\_vol, vhtr)
510           \textcolor{keyword}{call }distribute\_residual\_uh\_upwards(g, gv, h\_vol, uhtr)
511 \textcolor{keywordflow}{        endif}
512 
513         \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr, vhtr, cs%OBC, cs%dt\_offline, g, gv, cs%US, &
514             cs%tracer\_adv\_CSp, cs%tracer\_Reg, h\_prev\_opt = h\_pre, max\_iter\_in=1, &
515             h\_out=h\_new, uhr\_out=uhr, vhr\_out=vhr, x\_first\_in=x\_before\_y)
516 
517         \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
518           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"After upwards redistribute "}, cs%tracer\_Reg%Tr, cs%tracer\_Reg%ntr, g)
519 \textcolor{keywordflow}{        endif}
520 
521         \textcolor{comment}{! Convert h\_new back to layer thickness for ALE remapping}
522         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
523           uhtr(i,j,k) = uhr(i,j,k)
524           vhtr(i,j,k) = vhr(i,j,k)
525           h\_vol(i,j,k) = h\_new(i,j,k)
526           h\_new(i,j,k) = h\_new(i,j,k) / (g%US%L\_to\_m**2*g%areaT(i,j))
527           h\_pre(i,j,k) = h\_new(i,j,k)
528 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
529 
530 \textcolor{keywordflow}{      endif} \textcolor{comment}{! redistribute upwards}
531 
532       \textcolor{comment}{! Perform barotropic redistribution}
533       \textcolor{keywordflow}{if} (cs%redistribute\_barotropic) \textcolor{keywordflow}{then}
534 
535         \textcolor{comment}{! Calculate the layer volumes at beginning of redistribute}
536         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
537           h\_vol(i,j,k) = h\_pre(i,j,k)*g%US%L\_to\_m**2*g%areaT(i,j)
538 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
539         \textcolor{keyword}{call }pass\_var(h\_vol,g%Domain)
540         \textcolor{keyword}{call }pass\_vector(uhtr,vhtr,g%Domain)
541 
542         \textcolor{comment}{! Copy h\_vol to h\_pre for advect\_tracer routine}
543         h\_pre(:,:,:) = h\_vol(:,:,:)
544 
545         \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
546           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"Before barotropic redistribute "}, cs%tracer\_Reg%Tr, cs%tracer\_Reg%ntr, g)
547           \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]tr before upwards redistribute"}, uhtr, vhtr, g%HI)
548 \textcolor{keywordflow}{        endif}
549 
550         \textcolor{keywordflow}{if} (x\_before\_y) \textcolor{keywordflow}{then}
551           \textcolor{keyword}{call }distribute\_residual\_uh\_barotropic(g, gv, h\_vol, uhtr)
552           \textcolor{keyword}{call }distribute\_residual\_vh\_barotropic(g, gv, h\_vol, vhtr)
553         \textcolor{keywordflow}{else}
554           \textcolor{keyword}{call }distribute\_residual\_vh\_barotropic(g, gv, h\_vol, vhtr)
555           \textcolor{keyword}{call }distribute\_residual\_uh\_barotropic(g, gv, h\_vol, uhtr)
556 \textcolor{keywordflow}{        endif}
557 
558         \textcolor{keyword}{call }advect\_tracer(h\_pre, uhtr, vhtr, cs%OBC, cs%dt\_offline, g, gv, cs%US, &
559             cs%tracer\_adv\_CSp, cs%tracer\_Reg, h\_prev\_opt = h\_pre, max\_iter\_in=1, &
560             h\_out=h\_new, uhr\_out=uhr, vhr\_out=vhr, x\_first\_in=x\_before\_y)
561 
562         \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
563           \textcolor{keyword}{call }mom\_tracer\_chksum(\textcolor{stringliteral}{"After barotropic redistribute "}, cs%tracer\_Reg%Tr, cs%tracer\_Reg%ntr, g)
564 \textcolor{keywordflow}{        endif}
565 
566         \textcolor{comment}{! Convert h\_new back to layer thickness for ALE remapping}
567         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
568           uhtr(i,j,k) = uhr(i,j,k)
569           vhtr(i,j,k) = vhr(i,j,k)
570           h\_vol(i,j,k) = h\_new(i,j,k)
571           h\_new(i,j,k) = h\_new(i,j,k) / (g%US%L\_to\_m**2*g%areaT(i,j))
572           h\_pre(i,j,k) = h\_new(i,j,k)
573 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
574 
575 \textcolor{keywordflow}{      endif} \textcolor{comment}{! redistribute barotropic}
576 
577       \textcolor{comment}{! Check to see if all transport has been exhausted}
578       tot\_residual = remaining\_transport\_sum(cs, uhtr, vhtr)
579       \textcolor{keywordflow}{if} (cs%print\_adv\_offline) \textcolor{keywordflow}{then}
580         \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'(A,ES24.16)'}) \textcolor{stringliteral}{"Residual advection remaining transport: "}, tot\_residual
581         \textcolor{keyword}{call }mom\_mesg(mesg)
582 \textcolor{keywordflow}{      endif}
583       \textcolor{comment}{! If the remaining residual is 0, then this return is done}
584       \textcolor{keywordflow}{if} (tot\_residual==0.0 ) \textcolor{keywordflow}{then}
585         \textcolor{keywordflow}{exit}
586 \textcolor{keywordflow}{      endif}
587 
588       \textcolor{keywordflow}{if} ( (tot\_residual == prev\_tot\_residual) .or. (tot\_residual<cs%min\_residual) ) \textcolor{keywordflow}{exit}
589       prev\_tot\_residual = tot\_residual
590 
591 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! Redistribution iteration}
592 \textcolor{keywordflow}{  endif} \textcolor{comment}{! If one of the redistribution routines is requested}
593 
594   \textcolor{keywordflow}{if} (cs%id\_eta\_post\_distribute>0) \textcolor{keywordflow}{then}
595     eta\_work(:,:) = 0.0
596     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
597       \textcolor{keywordflow}{if} (h\_pre(i,j,k)>gv%Angstrom\_H) \textcolor{keywordflow}{then}
598         eta\_work(i,j) = eta\_work(i,j) + h\_pre(i,j,k)
599 \textcolor{keywordflow}{      endif}
600 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
601     \textcolor{keyword}{call }post\_data(cs%id\_eta\_post\_distribute,eta\_work,cs%diag)
602 \textcolor{keywordflow}{  endif}
603 
604   \textcolor{keywordflow}{if} (cs%id\_uhr>0) \textcolor{keyword}{call }post\_data(cs%id\_uhr,uhtr,cs%diag)
605   \textcolor{keywordflow}{if} (cs%id\_vhr>0) \textcolor{keyword}{call }post\_data(cs%id\_vhr,vhtr,cs%diag)
606 
607   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
608     \textcolor{keyword}{call }hchksum(h\_pre,\textcolor{stringliteral}{"h\_pre after redistribute"},g%HI)
609     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"uhtr after redistribute"}, uhtr, vhtr, g%HI)
610     \textcolor{keyword}{call }mom\_tracer\_chkinv(\textcolor{stringliteral}{"after redistribute "}, g, h\_new, cs%tracer\_Reg%Tr, cs%tracer\_Reg%ntr)
611 \textcolor{keywordflow}{  endif}
612 
613   \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_redistribute)
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}
1506   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Control structure for offline module}
1507 
1508   \textcolor{comment}{! Explicitly allocate all allocatable arrays}
1509   \textcolor{keyword}{deallocate}(cs%uhtr)
1510   \textcolor{keyword}{deallocate}(cs%vhtr)
1511   \textcolor{keyword}{deallocate}(cs%eatr)
1512   \textcolor{keyword}{deallocate}(cs%ebtr)
1513   \textcolor{keyword}{deallocate}(cs%h\_end)
1514   \textcolor{keyword}{deallocate}(cs%netMassOut)
1515   \textcolor{keyword}{deallocate}(cs%netMassIn)
1516   \textcolor{keyword}{deallocate}(cs%Kd)
1517   \textcolor{keywordflow}{if} (cs%read\_mld) \textcolor{keyword}{deallocate}(cs%mld)
1518   \textcolor{keywordflow}{if} (cs%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}
1519     \textcolor{keyword}{deallocate}(cs%uhtr\_all)
1520     \textcolor{keyword}{deallocate}(cs%vhtr\_all)
1521     \textcolor{keyword}{deallocate}(cs%hend\_all)
1522     \textcolor{keyword}{deallocate}(cs%temp\_all)
1523     \textcolor{keyword}{deallocate}(cs%salt\_all)
1524 \textcolor{keywordflow}{  endif}
1525 
1526   \textcolor{keyword}{deallocate}(cs)
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{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters\\
\hline
 & {\em cs} & Offline control structure\\
\hline
\mbox{\tt in}  & {\em diabatic\+\_\+csp} & The diabatic control structure\\
\hline
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
1290 
1291   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}
1292   \textcolor{keywordtype}{type}(offline\_transport\_CS),      \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Offline control structure}
1293   \textcolor{keywordtype}{type}(diabatic\_CS),               \textcolor{keywordtype}{intent(in)} :: diabatic\_CSp\textcolor{comment}{ !< The diabatic control structure}
1294   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< ocean grid structure}
1295   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{ !< ocean vertical grid structure}
1296   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}
1297 
1298   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"offline\_transport"}
1299   \textcolor{keywordtype}{character(len=20)}  :: redistribute\_method
1300 
1301   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz
1302   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
1303 
1304   is   = g%isc   ; ie   = g%iec  ; js   = g%jsc  ; je   = g%jec ; nz = gv%ke
1305   isd  = g%isd   ; ied  = g%ied  ; jsd  = g%jsd  ; jed  = g%jed
1306   isdb = g%IsdB  ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
1307 
1308   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"offline\_transport\_init, MOM\_offline\_control.F90"})
1309 
1310   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
1311     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"offline\_transport\_init called with an associated "}// &
1312       \textcolor{stringliteral}{"control structure."})
1313     \textcolor{keywordflow}{return}
1314 \textcolor{keywordflow}{  endif}
1315   \textcolor{keyword}{allocate}(cs)
1316   \textcolor{keyword}{call }log\_version(param\_file, mdl,version, \textcolor{stringliteral}{"This module allows for tracers to be run offline"})
1317 
1318   \textcolor{comment}{! Determining the internal unit scaling factors for this run.}
1319   cs%US => us
1320 
1321   \textcolor{comment}{! Parse MOM\_input for offline control}
1322   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFFLINEDIR"}, cs%offlinedir, &
1323     \textcolor{stringliteral}{"Input directory where the offline fields can be found"},  fail\_if\_missing = .true.)
1324   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_SUM\_FILE"}, cs%sum\_file, &
1325     \textcolor{stringliteral}{"Filename where the accumulated fields can be found"},     fail\_if\_missing = .true.)
1326   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_SNAP\_FILE"}, cs%snap\_file, &
1327     \textcolor{stringliteral}{"Filename where snapshot fields can be found"},            fail\_if\_missing = .true.)
1328   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_MEAN\_FILE"}, cs%mean\_file, &
1329     \textcolor{stringliteral}{"Filename where averaged fields can be found"},            fail\_if\_missing = .true.)
1330   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_SURF\_FILE"}, cs%surf\_file, &
1331     \textcolor{stringliteral}{"Filename where averaged fields can be found"},            fail\_if\_missing = .true.)
1332   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NUMTIME"}, cs%numtime, &
1333     \textcolor{stringliteral}{"Number of timelevels in offline input files"},            fail\_if\_missing = .true.)
1334   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NK\_INPUT"}, cs%nk\_input, &
1335     \textcolor{stringliteral}{"Number of vertical levels in offline input files"}, default = nz)
1336   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT\_OFFLINE"}, cs%dt\_offline, &
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.)
1338   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT\_OFFLINE\_VERTICAL"}, cs%dt\_offline\_vertical, &
1339     \textcolor{stringliteral}{"Length of the offline timestep for tracer column sources/sinks "} //&
1340     \textcolor{stringliteral}{"This should be set to the length of the coupling timestep for "} //&
1341     \textcolor{stringliteral}{"tracers which need shortwave fluxes"}, units=\textcolor{stringliteral}{"s"}, scale=us%s\_to\_T, fail\_if\_missing = .true.)
1342   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"START\_INDEX"}, cs%start\_index, &
1343     \textcolor{stringliteral}{"Which time index to start from"}, default=1)
1344   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FIELDS\_ARE\_OFFSET"}, cs%fields\_are\_offset, &
1345     \textcolor{stringliteral}{"True if the time-averaged fields and snapshot fields "}//&
1346     \textcolor{stringliteral}{"are offset by one time level"}, default=.false.)
1347   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REDISTRIBUTE\_METHOD"}, redistribute\_method, &
1348     \textcolor{stringliteral}{"Redistributes any remaining horizontal fluxes throughout "}    //&
1349     \textcolor{stringliteral}{"the rest of water column. Options are 'barotropic' which "}    //&
1350     \textcolor{stringliteral}{"evenly distributes flux throughout the entire water column, "} //&
1351     \textcolor{stringliteral}{"'upwards' which adds the maximum of the remaining flux in "}   //&
1352     \textcolor{stringliteral}{"each layer above, both which first applies upwards and then "} //&
1353     \textcolor{stringliteral}{"barotropic, and 'none' which does no redistribution"}, &
1354     default=\textcolor{stringliteral}{'barotropic'})
1355   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NUM\_OFF\_ITER"}, cs%num\_off\_iter, &
1356     \textcolor{stringliteral}{"Number of iterations to subdivide the offline tracer advection and diffusion"}, &
1357     default = 60)
1358   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFF\_ALE\_MOD"}, cs%off\_ale\_mod, &
1359     \textcolor{stringliteral}{"Sets how many horizontal advection steps are taken before an ALE "} //&
1360     \textcolor{stringliteral}{"remapping step is done. 1 would be x->y->ALE, 2 would be"}           //&
1361     \textcolor{stringliteral}{"x->y->x->y->ALE"}, default = 1)
1362   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRINT\_ADV\_OFFLINE"}, cs%print\_adv\_offline, &
1363     \textcolor{stringliteral}{"Print diagnostic output every advection subiteration"},default=.false.)
1364   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SKIP\_DIFFUSION\_OFFLINE"}, cs%skip\_diffusion, &
1365     \textcolor{stringliteral}{"Do not do horizontal diffusion"},default=.false.)
1366   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_SW"}, cs%read\_sw, &
1367     \textcolor{stringliteral}{"Read in shortwave radiation field instead of using values from the coupler"}//&
1368     \textcolor{stringliteral}{"when in offline tracer mode"},default=.false.)
1369   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_MLD"}, cs%read\_mld, &
1370     \textcolor{stringliteral}{"Read in mixed layer depths for tracers which exchange with the atmosphere"}//&
1371     \textcolor{stringliteral}{"when in offline tracer mode"},default=.false.)
1372   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLD\_VAR\_NAME"}, cs%mld\_var\_name, &
1373     \textcolor{stringliteral}{"Name of the variable containing the depth of active mixing"},&
1374     default=\textcolor{stringliteral}{'ePBL\_h\_ML'})
1375   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OFFLINE\_ADD\_DIURNAL\_SW"}, cs%diurnal\_sw, &
1376     \textcolor{stringliteral}{"Adds a synthetic diurnal cycle in the same way that the ice "} // &
1377     \textcolor{stringliteral}{"model would have when time-averaged fields of shortwave "}    // &
1378     \textcolor{stringliteral}{"radiation are read in"}, default=.false.)
1379   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_MAX"}, cs%Kd\_max, &
1380     \textcolor{stringliteral}{"The maximum permitted increment for the diapycnal "}//&
1381     \textcolor{stringliteral}{"diffusivity from TKE-based parameterizations, or a "}//&
1382     \textcolor{stringliteral}{"negative value for no limit."}, units=\textcolor{stringliteral}{"m2 s-1"}, default=-1.0)
1383   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIN\_RESIDUAL\_TRANSPORT"}, cs%min\_residual, &
1384     \textcolor{stringliteral}{"How much remaining transport before the main offline advection "}// &
1385     \textcolor{stringliteral}{"is exited. The default value corresponds to about 1 meter of "}  // &
1386     \textcolor{stringliteral}{"difference in a grid cell"}, default = 1.e9)
1387   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_ALL\_TS\_UVH"}, cs%read\_all\_ts\_uvh,  &
1388     \textcolor{stringliteral}{"Reads all time levels of a subset of the fields necessary to run "}    //      &
1389     \textcolor{stringliteral}{"the model offline. This can require a large amount of memory "}//      &
1390     \textcolor{stringliteral}{"and will make initialization very slow. However, for offline "}//      &
1391     \textcolor{stringliteral}{"runs spanning more than a year this can reduce total I/O overhead"},    &
1392     default = .false.)
1393 
1394   \textcolor{comment}{! Concatenate offline directory and file names}
1395   cs%snap\_file = trim(cs%offlinedir)//trim(cs%snap\_file)
1396   cs%mean\_file = trim(cs%offlinedir)//trim(cs%mean\_file)
1397   cs%sum\_file = trim(cs%offlinedir)//trim(cs%sum\_file)
1398   cs%surf\_file = trim(cs%offlinedir)//trim(cs%surf\_file)
1399 
1400   cs%num\_vert\_iter = cs%dt\_offline/cs%dt\_offline\_vertical
1401 
1402   \textcolor{comment}{! Map redistribute\_method onto logicals in CS}
1403   \textcolor{keywordflow}{select case} (redistribute\_method)
1404     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'barotropic'})
1405       cs%redistribute\_barotropic = .true.
1406       cs%redistribute\_upwards    = .false.
1407     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'upwards'})
1408       cs%redistribute\_barotropic = .false.
1409       cs%redistribute\_upwards    = .true.
1410     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'both'})
1411       cs%redistribute\_barotropic = .true.
1412       cs%redistribute\_upwards    = .true.
1413     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'none'})
1414       cs%redistribute\_barotropic = .false.
1415       cs%redistribute\_upwards    = .false.
1416 \textcolor{keywordflow}{  end select}
1417 
1418   \textcolor{comment}{! Set the accumulated time to zero}
1419   cs%accumulated\_time = real\_to\_time(0.0)
1420   cs%vertical\_time = cs%accumulated\_time
1421   \textcolor{comment}{! Set the starting read index for time-averaged and snapshotted fields}
1422   cs%ridx\_sum = cs%start\_index
1423   \textcolor{keywordflow}{if} (cs%fields\_are\_offset) cs%ridx\_snap = next\_modulo\_time(cs%start\_index,cs%numtime)
1424   \textcolor{keywordflow}{if} (.not. cs%fields\_are\_offset) cs%ridx\_snap = cs%start\_index
1425 
1426   \textcolor{comment}{! Copy members from other modules}
1427   \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, opacity\_csp=cs%opacity\_CSp, optics\_csp=cs%optics, &
1428                                diabatic\_aux\_csp=cs%diabatic\_aux\_CSp, &
1429                                evap\_cfl\_limit=cs%evap\_CFL\_limit, &
1430                                minimum\_forcing\_depth=cs%minimum\_forcing\_depth)
1431 
1432   \textcolor{comment}{! Grid pointer assignments}
1433   cs%G  => g
1434   cs%GV => gv
1435 
1436   \textcolor{comment}{! Allocate arrays}
1437   \textcolor{keyword}{allocate}(cs%uhtr(isdb:iedb,jsd:jed,nz))   ; cs%uhtr(:,:,:) = 0.0
1438   \textcolor{keyword}{allocate}(cs%vhtr(isd:ied,jsdb:jedb,nz))   ; cs%vhtr(:,:,:) = 0.0
1439   \textcolor{keyword}{allocate}(cs%eatr(isd:ied,jsd:jed,nz))          ; cs%eatr(:,:,:) = 0.0
1440   \textcolor{keyword}{allocate}(cs%ebtr(isd:ied,jsd:jed,nz))          ; cs%ebtr(:,:,:) = 0.0
1441   \textcolor{keyword}{allocate}(cs%h\_end(isd:ied,jsd:jed,nz))         ; cs%h\_end(:,:,:) = 0.0
1442   \textcolor{keyword}{allocate}(cs%netMassOut(g%isd:g%ied,g%jsd:g%jed)) ; cs%netMassOut(:,:) = 0.0
1443   \textcolor{keyword}{allocate}(cs%netMassIn(g%isd:g%ied,g%jsd:g%jed))  ; cs%netMassIn(:,:) = 0.0
1444   \textcolor{keyword}{allocate}(cs%Kd(isd:ied,jsd:jed,nz+1)) ; cs%Kd = 0.
1445   \textcolor{keywordflow}{if} (cs%read\_mld) \textcolor{keywordflow}{then}
1446     \textcolor{keyword}{allocate}(cs%mld(g%isd:g%ied,g%jsd:g%jed)) ; cs%mld(:,:) = 0.0
1447 \textcolor{keywordflow}{  endif}
1448 
1449   \textcolor{keywordflow}{if} (cs%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}
1450     \textcolor{keyword}{call }read\_all\_input(cs)
1451 \textcolor{keywordflow}{  endif}
1452 
1453   \textcolor{comment}{! Initialize ids for clocks used in offline routines}
1454   cs%id\_clock\_read\_fields =      cpu\_clock\_id(\textcolor{stringliteral}{'(Offline read fields)'},grain=clock\_module)
1455   cs%id\_clock\_offline\_diabatic = cpu\_clock\_id(\textcolor{stringliteral}{'(Offline diabatic)'},grain=clock\_module)
1456   cs%id\_clock\_offline\_adv =      cpu\_clock\_id(\textcolor{stringliteral}{'(Offline transport)'},grain=clock\_module)
1457   cs%id\_clock\_redistribute =     cpu\_clock\_id(\textcolor{stringliteral}{'(Offline redistribute)'},grain=clock\_module)
1458 
1459   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"offline\_transport\_init"})
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{\tt in}  & {\em cs} & Offline control structure\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+off} & Thicknesses at end of offline step\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+end} & Stored thicknesses\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Remaining zonal mass transport\\
\hline
\mbox{\tt 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}
1172   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(in   )} :: CS\textcolor{comment}{     !< Offline control structure}
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}
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}
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}
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}
1177 
1178   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G))} :: eta\_diff
1179   \textcolor{keywordtype}{integer} :: i, j, k
1180 
1181   \textcolor{keywordflow}{if} (cs%id\_eta\_diff\_end>0) \textcolor{keywordflow}{then}
1182     \textcolor{comment}{! Calculate difference in column thickness}
1183     eta\_diff = 0.
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
1185       eta\_diff(i,j) = eta\_diff(i,j) + h\_off(i,j,k)
1186 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
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
1188       eta\_diff(i,j) = eta\_diff(i,j) - h\_end(i,j,k)
1189 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1190 
1191     \textcolor{keyword}{call }post\_data(cs%id\_eta\_diff\_end, eta\_diff, cs%diag)
1192 \textcolor{keywordflow}{  endif}
1193 
1194   \textcolor{keywordflow}{if} (cs%id\_hdiff>0) \textcolor{keyword}{call }post\_data(cs%id\_hdiff, h\_off-h\_end, cs%diag)
1195   \textcolor{keywordflow}{if} (cs%id\_hr>0) \textcolor{keyword}{call }post\_data(cs%id\_hr, h\_off, cs%diag)
1196   \textcolor{keywordflow}{if} (cs%id\_uhr\_end>0) \textcolor{keyword}{call }post\_data(cs%id\_uhr\_end, uhtr, cs%diag)
1197   \textcolor{keywordflow}{if} (cs%id\_vhr\_end>0) \textcolor{keyword}{call }post\_data(cs%id\_vhr\_end, vhtr, cs%diag)
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{\tt 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}
1466   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{intent(inout)}  :: CS\textcolor{comment}{ !< Control structure for offline module}
1467 
1468   \textcolor{keywordtype}{integer} :: is, ie, js, je, isd, ied, jsd, jed, nz, t, ntime
1469   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
1470 
1471   nz = cs%GV%ke ; ntime = cs%numtime
1472   isd  = cs%G%isd   ; ied  = cs%G%ied  ; jsd  = cs%G%jsd  ; jed  = cs%G%jed
1473   isdb = cs%G%IsdB  ; iedb = cs%G%IedB ; jsdb = cs%G%JsdB ; jedb = cs%G%JedB
1474 
1475   \textcolor{comment}{! Extra safety check that we're not going to overallocate any arrays}
1476   \textcolor{keywordflow}{if} (cs%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}
1477     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%uhtr\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"uhtr\_all is already allocated"})
1478     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%vhtr\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"vhtr\_all is already allocated"})
1479     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%hend\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"hend\_all is already allocated"})
1480     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%temp\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"temp\_all is already allocated"})
1481     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%salt\_all)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"salt\_all is already allocated"})
1482 
1483     \textcolor{keyword}{allocate}(cs%uhtr\_all(isdb:iedb,jsd:jed,nz,ntime))     ; cs%uhtr\_all(:,:,:,:) = 0.0
1484     \textcolor{keyword}{allocate}(cs%vhtr\_all(isd:ied,jsdb:jedb,nz,ntime))     ; cs%vhtr\_all(:,:,:,:) = 0.0
1485     \textcolor{keyword}{allocate}(cs%hend\_all(isd:ied,jsd:jed,nz,ntime))       ; cs%hend\_all(:,:,:,:) = 0.0
1486     \textcolor{keyword}{allocate}(cs%temp\_all(isd:ied,jsd:jed,nz,1:ntime))     ; cs%temp\_all(:,:,:,:) = 0.0
1487     \textcolor{keyword}{allocate}(cs%salt\_all(isd:ied,jsd:jed,nz,1:ntime))     ; cs%salt\_all(:,:,:,:) = 0.0
1488 
1489     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Reading in uhtr, vhtr, h\_start, h\_end, temp, salt"})
1490     \textcolor{keywordflow}{do} t = 1,ntime
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), &
1492                        cs%vhtr\_all(:,:,1:cs%nk\_input,t), cs%G%Domain, timelevel=t)
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, &
1494         timelevel=t, position=center)
1495       \textcolor{keyword}{call }mom\_read\_data(cs%mean\_file,\textcolor{stringliteral}{'temp'}, cs%temp\_all(:,:,1:cs%nk\_input,t), cs%G%Domain, &
1496         timelevel=t, position=center)
1497       \textcolor{keyword}{call }mom\_read\_data(cs%mean\_file,\textcolor{stringliteral}{'salt'}, cs%salt\_all(:,:,1:cs%nk\_input,t), cs%G%Domain, &
1498         timelevel=t, position=center)
1499 \textcolor{keywordflow}{    enddo}
1500 \textcolor{keywordflow}{  endif}
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{\tt in}  & {\em time} & current model time\\
\hline
\mbox{\tt 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}
1115 
1116   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< Control structure for offline module}
1117   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)} :: Time\textcolor{comment}{ !< current model time}
1118   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{ !< Structure that regulates diagnostic output}
1119 
1120   \textcolor{comment}{! U-cell fields}
1121   cs%id\_uhr = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhr'}, diag%axesCuL, time, &
1122     \textcolor{stringliteral}{'Zonal thickness fluxes remaining at end of advection'}, \textcolor{stringliteral}{'kg'})
1123   cs%id\_uhr\_redist = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhr\_redist'}, diag%axesCuL, time, &
1124     \textcolor{stringliteral}{'Zonal thickness fluxes to be redistributed vertically'}, \textcolor{stringliteral}{'kg'})
1125   cs%id\_uhr\_end = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhr\_end'}, diag%axesCuL, time, &
1126     \textcolor{stringliteral}{'Zonal thickness fluxes at end of offline step'}, \textcolor{stringliteral}{'kg'})
1127 
1128   \textcolor{comment}{! V-cell fields}
1129   cs%id\_vhr = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhr'}, diag%axesCvL, time, &
1130     \textcolor{stringliteral}{'Meridional thickness fluxes remaining at end of advection'}, \textcolor{stringliteral}{'kg'})
1131   cs%id\_vhr\_redist = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhr\_redist'}, diag%axesCvL, time, &
1132     \textcolor{stringliteral}{'Meridional thickness to be redistributed vertically'}, \textcolor{stringliteral}{'kg'})
1133   cs%id\_vhr\_end = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhr\_end'}, diag%axesCvL, time, &
1134     \textcolor{stringliteral}{'Meridional thickness at end of offline step'}, \textcolor{stringliteral}{'kg'})
1135 
1136   \textcolor{comment}{! T-cell fields}
1137   cs%id\_hdiff  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'hdiff'}, diag%axesTL, time, &
1138     \textcolor{stringliteral}{'Difference between the stored and calculated layer thickness'}, \textcolor{stringliteral}{'m'})
1139   cs%id\_hr  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'hr'}, diag%axesTL, time, &
1140     \textcolor{stringliteral}{'Layer thickness at end of offline step'}, \textcolor{stringliteral}{'m'})
1141   cs%id\_ear  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ear'}, diag%axesTL, time, &
1142     \textcolor{stringliteral}{'Remaining thickness entrained from above'}, \textcolor{stringliteral}{'m'})
1143   cs%id\_ebr  = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ebr'}, diag%axesTL, time, &
1144     \textcolor{stringliteral}{'Remaining thickness entrained from below'}, \textcolor{stringliteral}{'m'})
1145   cs%id\_eta\_pre\_distribute = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'eta\_pre\_distribute'}, &
1146     diag%axesT1, time, \textcolor{stringliteral}{'Total water column height before residual transport redistribution'},\textcolor{stringliteral}{'m'})
1147   cs%id\_eta\_post\_distribute = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'eta\_post\_distribute'}, &
1148     diag%axesT1, time, \textcolor{stringliteral}{'Total water column height after residual transport redistribution'},\textcolor{stringliteral}{'m'})
1149   cs%id\_eta\_diff\_end = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'eta\_diff\_end'}, diag%axesT1, time, &
1150     \textcolor{stringliteral}{'Difference in total water column height from online and offline '} // &
1151     \textcolor{stringliteral}{'at the end of the offline timestep'},\textcolor{stringliteral}{'m'})
1152   cs%id\_h\_redist = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'h\_redist'}, diag%axesTL, time, &
1153     \textcolor{stringliteral}{'Layer thicknesses before redistribution of mass fluxes'},\textcolor{stringliteral}{'m'})
1154 
1155   \textcolor{comment}{! Regridded/remapped input fields}
1156   cs%id\_uhtr\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhtr\_regrid'}, diag%axesCuL, time, &
1157                                           \textcolor{stringliteral}{'Zonal mass transport regridded/remapped onto offline grid'},\textcolor{stringliteral}{'kg'})
1158   cs%id\_vhtr\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhtr\_regrid'}, diag%axesCvL, time, &
1159                                           \textcolor{stringliteral}{'Meridional mass transport regridded/remapped onto offline grid'},\textcolor{stringliteral}{
      'kg'})
1160   cs%id\_temp\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'temp\_regrid'}, diag%axesTL, time, &
1161                                           \textcolor{stringliteral}{'Temperature regridded/remapped onto offline grid'},\textcolor{stringliteral}{'C'})
1162   cs%id\_salt\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'salt\_regrid'}, diag%axesTL, time, &
1163                                           \textcolor{stringliteral}{'Salinity regridded/remapped onto offline grid'},\textcolor{stringliteral}{'g kg-1'})
1164   cs%id\_h\_regrid = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h\_regrid'}, diag%axesTL, time, &
1165                                           \textcolor{stringliteral}{'Layer thicknesses regridded/remapped onto offline grid'},\textcolor{stringliteral}{'m'})
1166 
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{\tt in}  & {\em uhtr} & Zonal mass transport\\
\hline
\mbox{\tt in}  & {\em vhtr} & Meridional mass transport \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
619   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}  :: CS\textcolor{comment}{ !< control structure for offline module}
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}
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}
622 
623   \textcolor{comment}{! Local variables}
624   \textcolor{keywordtype}{integer} :: i, j, k
625   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz
626   \textcolor{keywordtype}{real} :: h\_min\textcolor{comment}{ !< A layer thickness below roundoff from GV type}
627   \textcolor{keywordtype}{real} :: uh\_neglect\textcolor{comment}{ !< A small value of zonal transport that effectively is below roundoff error}
628   \textcolor{keywordtype}{real} :: vh\_neglect\textcolor{comment}{ !< A small value of meridional transport that effectively is below roundoff error}
629 
630   nz = cs%GV%ke
631   is = cs%G%isc ; ie = cs%G%iec ; js = cs%G%jsc ; je = cs%G%jec
632 
633   h\_min = cs%GV%H\_subroundoff
634 
635   remaining\_transport\_sum = 0.
636   \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
637     uh\_neglect = h\_min*cs%G%US%L\_to\_m**2*min(cs%G%areaT(i,j),cs%G%areaT(i+1,j))
638     vh\_neglect = h\_min*cs%G%US%L\_to\_m**2*min(cs%G%areaT(i,j),cs%G%areaT(i,j+1))
639     \textcolor{keywordflow}{if} (abs(uhtr(i,j,k))>uh\_neglect) \textcolor{keywordflow}{then}
640       remaining\_transport\_sum = remaining\_transport\_sum + abs(uhtr(i,j,k))
641 \textcolor{keywordflow}{    endif}
642     \textcolor{keywordflow}{if} (abs(vhtr(i,j,k))>vh\_neglect) \textcolor{keywordflow}{then}
643       remaining\_transport\_sum = remaining\_transport\_sum + abs(vhtr(i,j,k))
644 \textcolor{keywordflow}{    endif}
645 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
646   \textcolor{keyword}{call }sum\_across\_pes(remaining\_transport\_sum)
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{\tt in,out}  & {\em fluxes} & Pointers to forcing fields\\
\hline
\mbox{\tt 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}
1019   \textcolor{keywordtype}{type}(offline\_transport\_CS), \textcolor{keywordtype}{pointer}               :: CS\textcolor{comment}{ !< Control structure for offline module}
1020   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: h\textcolor{comment}{ !< The regridded layer thicknesses}
1021   \textcolor{keywordtype}{type}(forcing),        \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Pointers to forcing fields}
1022   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in   )} :: do\_ale\textcolor{comment}{ !< True if using ALE}
1023   \textcolor{comment}{! Local variables}
1024   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
1025   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G),SZK\_(CS%G))} :: h\_start
1026   is = cs%G%isc ; ie = cs%G%iec ; js = cs%G%jsc ; je = cs%G%jec ; nz = cs%GV%ke
1027 
1028   \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_read\_fields)
1029   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"update\_offline\_fields, MOM\_offline\_main.F90"})
1030 
1031   \textcolor{comment}{! Store a copy of the layer thicknesses before ALE regrid/remap}
1032   h\_start(:,:,:) = h(:,:,:)
1033 
1034   \textcolor{comment}{! Most fields will be read in from files}
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,    &
1036                                   cs%h\_end, cs%uhtr, cs%vhtr, cs%tv%T, cs%tv%S, cs%mld, cs%Kd, fluxes,     
                 &
1037                                   cs%ridx\_sum, cs%ridx\_snap, cs%read\_mld, cs%read\_sw, .not. cs
      %read\_all\_ts\_uvh, do\_ale)
1038   \textcolor{comment}{! If uh, vh, h\_end, temp, salt were read in at the beginning, fields are copied from those arrays}
1039   \textcolor{keywordflow}{if} (cs%read\_all\_ts\_uvh) \textcolor{keywordflow}{then}
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, &
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)
1042 \textcolor{keywordflow}{    endif}
1043   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
1044     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]h after update offline from files and arrays"}, cs%uhtr, cs%vhtr, cs%G%HI)
1045 \textcolor{keywordflow}{  endif}
1046 
1047   \textcolor{comment}{! If using an ALE-dependent vertical coordinate, fields will need to be remapped}
1048   \textcolor{keywordflow}{if} (do\_ale) \textcolor{keywordflow}{then}
1049     \textcolor{comment}{! These halo passes are necessary because u, v fields will need information 1 step into the halo}
1050     \textcolor{keyword}{call }pass\_var(h, cs%G%Domain)
1051     \textcolor{keyword}{call }pass\_var(cs%tv%T, cs%G%Domain)
1052     \textcolor{keyword}{call }pass\_var(cs%tv%S, cs%G%Domain)
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, &
1054                             cs%debug, cs%OBC)
1055     \textcolor{keywordflow}{if} (cs%id\_temp\_regrid>0) \textcolor{keyword}{call }post\_data(cs%id\_temp\_regrid, cs%tv%T, cs%diag)
1056     \textcolor{keywordflow}{if} (cs%id\_salt\_regrid>0) \textcolor{keyword}{call }post\_data(cs%id\_salt\_regrid, cs%tv%S, cs%diag)
1057     \textcolor{keywordflow}{if} (cs%id\_uhtr\_regrid>0) \textcolor{keyword}{call }post\_data(cs%id\_uhtr\_regrid, cs%uhtr, cs%diag)
1058     \textcolor{keywordflow}{if} (cs%id\_vhtr\_regrid>0) \textcolor{keyword}{call }post\_data(cs%id\_vhtr\_regrid, cs%vhtr, cs%diag)
1059     \textcolor{keywordflow}{if} (cs%id\_h\_regrid>0) \textcolor{keyword}{call }post\_data(cs%id\_h\_regrid, h, cs%diag)
1060     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
1061       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]h after ALE regridding/remapping of inputs"}, cs%uhtr, cs%vhtr, cs%G%HI)
1062       \textcolor{keyword}{call }hchksum(h\_start,\textcolor{stringliteral}{"h\_start after update offline from files and arrays"}, cs%G%HI)
1063 \textcolor{keywordflow}{    endif}
1064 \textcolor{keywordflow}{  endif}
1065 
1066   \textcolor{comment}{! Update halos for some}
1067   \textcolor{keyword}{call }pass\_var(cs%h\_end, cs%G%Domain)
1068   \textcolor{keyword}{call }pass\_var(cs%tv%T, cs%G%Domain)
1069   \textcolor{keyword}{call }pass\_var(cs%tv%S, cs%G%Domain)
1070 
1071   \textcolor{comment}{! Update the read indices}
1072   cs%ridx\_snap = next\_modulo\_time(cs%ridx\_snap,cs%numtime)
1073   cs%ridx\_sum = next\_modulo\_time(cs%ridx\_sum,cs%numtime)
1074 
1075   \textcolor{comment}{! Apply masks/factors at T, U, and V points}
1076   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1077     \textcolor{keywordflow}{if} (cs%G%mask2dT(i,j)<1.0) \textcolor{keywordflow}{then}
1078       cs%h\_end(i,j,k) = cs%GV%Angstrom\_H
1079 \textcolor{keywordflow}{    endif}
1080 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1081 
1082   \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1083     cs%Kd(i,j,k) = max(0.0, cs%Kd(i,j,k))
1084     \textcolor{keywordflow}{if} (cs%Kd\_max>0.) \textcolor{keywordflow}{then}
1085       cs%Kd(i,j,k) = min(cs%Kd\_max, cs%Kd(i,j,k))
1086 \textcolor{keywordflow}{    endif}
1087 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1088 
1089   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
1090     \textcolor{keywordflow}{if} (cs%G%mask2dCv(i,j)<1.0) \textcolor{keywordflow}{then}
1091       cs%vhtr(i,j,k) = 0.0
1092 \textcolor{keywordflow}{    endif}
1093 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1094 
1095   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
1096     \textcolor{keywordflow}{if} (cs%G%mask2dCu(i,j)<1.0) \textcolor{keywordflow}{then}
1097       cs%uhtr(i,j,k) = 0.0
1098 \textcolor{keywordflow}{    endif}
1099 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1100 
1101   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
1102     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"[uv]htr\_sub after update\_offline\_fields"}, cs%uhtr, cs%vhtr, cs%G%HI)
1103     \textcolor{keyword}{call }hchksum(cs%h\_end, \textcolor{stringliteral}{"h\_end after update\_offline\_fields"}, cs%G%HI)
1104     \textcolor{keyword}{call }hchksum(cs%tv%T, \textcolor{stringliteral}{"Temp after update\_offline\_fields"}, cs%G%HI)
1105     \textcolor{keyword}{call }hchksum(cs%tv%S, \textcolor{stringliteral}{"Salt after update\_offline\_fields"}, cs%G%HI)
1106 \textcolor{keywordflow}{  endif}
1107 
1108   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"update\_offline\_fields"})
1109   \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_read\_fields)
1110 
\end{DoxyCode}
