\hypertarget{namespacemom__offline__aux}{}\section{mom\+\_\+offline\+\_\+aux Module Reference}
\label{namespacemom__offline__aux}\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}


\subsection{Detailed Description}
Contains routines related to offline transport of tracers. These routines are likely to be called from the M\+O\+M\+\_\+offline\+\_\+main module. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_a2a72a34fb47df31ad8a10ee51b4beca3}{update\+\_\+h\+\_\+horizontal\+\_\+flux}} (G, GV, uhtr, vhtr, h\+\_\+pre, h\+\_\+new)
\begin{DoxyCompactList}\small\item\em This updates thickness based on the convergence of horizontal mass fluxes N\+O\+TE\+: Only used in non-\/\+A\+LE mode. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_a1dd22761e228785bf84f2d6db11ba8cc}{update\+\_\+h\+\_\+vertical\+\_\+flux}} (G, GV, ea, eb, h\+\_\+pre, h\+\_\+new)
\begin{DoxyCompactList}\small\item\em Updates layer thicknesses due to vertical mass transports N\+O\+TE\+: Only used in non-\/\+A\+LE configuration. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_a970148366cfc57cb311ab0c3fdbf0f6b}{limit\+\_\+mass\+\_\+flux\+\_\+3d}} (G, GV, uh, vh, ea, eb, h\+\_\+pre)
\begin{DoxyCompactList}\small\item\em This routine limits the mass fluxes so that the a layer cannot be completely depleted. N\+O\+TE\+: Only used in non-\/\+A\+LE mode. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_ab0ae4b0baa6a99a7c424f88cb308bff2}{distribute\+\_\+residual\+\_\+uh\+\_\+barotropic}} (G, GV, hvol, uh)
\begin{DoxyCompactList}\small\item\em In the case where offline advection has failed to converge, redistribute the u-\/flux into remainder of the water column as a barotropic equivalent. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_ad23ced9ed480b299332ca600e97d82bc}{distribute\+\_\+residual\+\_\+vh\+\_\+barotropic}} (G, GV, hvol, vh)
\begin{DoxyCompactList}\small\item\em Redistribute the v-\/flux as a barotropic equivalent. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_a926820f5e1a788c56f1f5f485f667a1f}{distribute\+\_\+residual\+\_\+uh\+\_\+upwards}} (G, GV, hvol, uh)
\begin{DoxyCompactList}\small\item\em In the case where offline advection has failed to converge, redistribute the u-\/flux into layers above. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_ae89d0bdb8c648bc137a188c4f7fa956d}{distribute\+\_\+residual\+\_\+vh\+\_\+upwards}} (G, GV, hvol, vh)
\begin{DoxyCompactList}\small\item\em In the case where offline advection has failed to converge, redistribute the u-\/flux into layers above. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_ac03963f0ae27e12160f78c6a420bc7a8}{offline\+\_\+add\+\_\+diurnal\+\_\+sw}} (fluxes, G, Time\+\_\+start, Time\+\_\+end)
\begin{DoxyCompactList}\small\item\em add\+\_\+diurnal\+\_\+\+SW adjusts the shortwave fluxes in an forcying\+\_\+type variable to add a synthetic diurnal cycle. Adapted from S\+I\+S2 \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_a088f31cd992ae91a4610aafe43b04c08}{update\+\_\+offline\+\_\+from\+\_\+files}} (G, GV, nk\+\_\+input, mean\+\_\+file, sum\+\_\+file, snap\+\_\+file, surf\+\_\+file, h\+\_\+end, uhtr, vhtr, temp\+\_\+mean, salt\+\_\+mean, mld, Kd, fluxes, ridx\+\_\+sum, ridx\+\_\+snap, read\+\_\+mld, read\+\_\+sw, read\+\_\+ts\+\_\+uvh, do\+\_\+ale\+\_\+in)
\begin{DoxyCompactList}\small\item\em Controls the reading in 3d mass fluxes, diffusive fluxes, and other fields stored in a previous integration of the online model. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__offline__aux_a6fc82d358eae9030a030182290a30858}{update\+\_\+offline\+\_\+from\+\_\+arrays}} (G, GV, nk\+\_\+input, ridx\+\_\+sum, mean\+\_\+file, sum\+\_\+file, snap\+\_\+file, uhtr, vhtr, hend, uhtr\+\_\+all, vhtr\+\_\+all, hend\+\_\+all, temp, salt, temp\+\_\+all, salt\+\_\+all)
\begin{DoxyCompactList}\small\item\em Fields for offline transport are copied from the stored arrays read during initialization. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__offline__aux_a4704d9514fdbf239f228f261938a9a09}\label{namespacemom__offline__aux_a4704d9514fdbf239f228f261938a9a09}} 
integer function, public \mbox{\hyperlink{namespacemom__offline__aux_a4704d9514fdbf239f228f261938a9a09}{next\+\_\+modulo\+\_\+time}} (inidx, numtime)
\begin{DoxyCompactList}\small\item\em Calculates the next timelevel to read from the input fields. This allows the \textquotesingle{}looping\textquotesingle{} of the fields. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__offline__aux_ab0ae4b0baa6a99a7c424f88cb308bff2}\label{namespacemom__offline__aux_ab0ae4b0baa6a99a7c424f88cb308bff2}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!distribute\+\_\+residual\+\_\+uh\+\_\+barotropic@{distribute\+\_\+residual\+\_\+uh\+\_\+barotropic}}
\index{distribute\+\_\+residual\+\_\+uh\+\_\+barotropic@{distribute\+\_\+residual\+\_\+uh\+\_\+barotropic}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{distribute\+\_\+residual\+\_\+uh\+\_\+barotropic()}{distribute\_residual\_uh\_barotropic()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::distribute\+\_\+residual\+\_\+uh\+\_\+barotropic (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{hvol,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uh }\end{DoxyParamCaption})}



In the case where offline advection has failed to converge, redistribute the u-\/flux into remainder of the water column as a barotropic equivalent. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em hvol} & Mass of water in the cells at the end\\
\hline
\mbox{\tt in,out}  & {\em uh} & Zonal mass transport within a timestep \mbox{[}kg\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 240 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
240   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{    !< ocean grid structure}
241   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{   !< ocean vertical grid structure}
242   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
243                            \textcolor{keywordtype}{intent(in   )} :: hvol\textcolor{comment}{ !< Mass of water in the cells at the end}
244 \textcolor{comment}{                                                 !! of the previous timestep [kg]}
245   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
246                            \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{   !< Zonal mass transport within a timestep [kg]}
247 
248   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))}   :: uh2d
249   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))}           :: uh2d\_sum
250   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}    :: h2d
251   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}            :: h2d\_sum
252 
253   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz
254   \textcolor{keywordtype}{real} :: uh\_neglect
255 
256   \textcolor{comment}{! Set index-related variables for fields on T-grid}
257   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
258 
259   \textcolor{keywordflow}{do} j=js,je
260     uh2d\_sum(:) = 0.0
261     \textcolor{comment}{! Copy over uh to a working array and sum up the remaining fluxes in a column}
262     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie
263       uh2d(i,k) = uh(i,j,k)
264       uh2d\_sum(i) = uh2d\_sum(i) + uh2d(i,k)
265 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
266 
267     \textcolor{comment}{! Copy over h to a working array and calculate total column volume}
268     h2d\_sum(:) = 0.0
269     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie+1
270       h2d(i,k) = hvol(i,j,k)
271       \textcolor{keywordflow}{if} (hvol(i,j,k)>0.) \textcolor{keywordflow}{then}
272         h2d\_sum(i) = h2d\_sum(i) + h2d(i,k)
273       \textcolor{keywordflow}{else}
274         h2d(i,k) = gv%H\_subroundoff
275 \textcolor{keywordflow}{      endif}
276 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
277 
278     \textcolor{comment}{! Distribute flux. Note min/max is intended to make sure that the mass transport}
279     \textcolor{comment}{! does not deplete a cell}
280     \textcolor{keywordflow}{do} i=is-1,ie
281       \textcolor{keywordflow}{if} ( uh2d\_sum(i)>0.0 ) \textcolor{keywordflow}{then}
282         \textcolor{keywordflow}{do} k=1,nz
283           uh2d(i,k) = uh2d\_sum(i)*(h2d(i,k)/h2d\_sum(i))
284 \textcolor{keywordflow}{        enddo}
285       \textcolor{keywordflow}{elseif} (uh2d\_sum(i)<0.0) \textcolor{keywordflow}{then}
286         \textcolor{keywordflow}{do} k=1,nz
287           uh2d(i,k) = uh2d\_sum(i)*(h2d(i+1,k)/h2d\_sum(i+1))
288 \textcolor{keywordflow}{        enddo}
289       \textcolor{keywordflow}{else}
290         \textcolor{keywordflow}{do} k=1,nz
291           uh2d(i,k) = 0.0
292 \textcolor{keywordflow}{        enddo}
293 \textcolor{keywordflow}{      endif}
294       \textcolor{comment}{! Calculate and check that column integrated transports match the original to}
295       \textcolor{comment}{! within the tolerance limit}
296       uh\_neglect = gv%Angstrom\_H*g%US%L\_to\_m**2 * min(g%areaT(i,j), g%areaT(i+1,j))
297       \textcolor{keywordflow}{if} ( abs(sum(uh2d(i,:))-uh2d\_sum(i)) > uh\_neglect) &
298         \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"Column integral of uh does not match after "}//&
299         \textcolor{stringliteral}{"barotropic redistribution"})
300 \textcolor{keywordflow}{    enddo}
301 
302     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie
303       uh(i,j,k) = uh2d(i,k)
304 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
305 \textcolor{keywordflow}{  enddo}
306 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_a926820f5e1a788c56f1f5f485f667a1f}\label{namespacemom__offline__aux_a926820f5e1a788c56f1f5f485f667a1f}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!distribute\+\_\+residual\+\_\+uh\+\_\+upwards@{distribute\+\_\+residual\+\_\+uh\+\_\+upwards}}
\index{distribute\+\_\+residual\+\_\+uh\+\_\+upwards@{distribute\+\_\+residual\+\_\+uh\+\_\+upwards}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{distribute\+\_\+residual\+\_\+uh\+\_\+upwards()}{distribute\_residual\_uh\_upwards()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::distribute\+\_\+residual\+\_\+uh\+\_\+upwards (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{hvol,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uh }\end{DoxyParamCaption})}



In the case where offline advection has failed to converge, redistribute the u-\/flux into layers above. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em hvol} & Mass of water in the cells at the end\\
\hline
\mbox{\tt in,out}  & {\em uh} & Zonal mass transport within a timestep \mbox{[}kg\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 384 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
384   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{     !< ocean grid structure}
385   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{    !< ocean vertical grid structure}
386   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
387                            \textcolor{keywordtype}{intent(in   )} :: hvol\textcolor{comment}{  !< Mass of water in the cells at the end}
388 \textcolor{comment}{                                                  !! of the previous timestep [kg]}
389   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
390                            \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{    !< Zonal mass transport within a timestep [kg]}
391 
392   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))}   :: uh2d
393   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}    :: h2d
394 
395   \textcolor{keywordtype}{real}  :: uh\_neglect, uh\_remain, uh\_add, uh\_sum, uh\_col, uh\_max
396   \textcolor{keywordtype}{real}  :: hup, hdown, hlos, min\_h
397   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz, k\_rev
398 
399   \textcolor{comment}{! Set index-related variables for fields on T-grid}
400   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
401 
402   min\_h = gv%Angstrom\_H*0.1
403 
404   \textcolor{keywordflow}{do} j=js,je
405     \textcolor{comment}{! Copy over uh and cell volume to working arrays}
406     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-2,ie+1
407       uh2d(i,k) = uh(i,j,k)
408 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
409     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie+1
410       \textcolor{comment}{! Subtract just a little bit of thickness to avoid roundoff errors}
411       h2d(i,k) = hvol(i,j,k)-min\_h*g%US%L\_to\_m**2*g%areaT(i,j)
412 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
413 
414     \textcolor{keywordflow}{do} i=is-1,ie
415       uh\_col = sum(uh2d(i,:)) \textcolor{comment}{! Store original column-integrated transport}
416       \textcolor{keywordflow}{do} k=1,nz
417         uh\_remain = uh2d(i,k)
418         uh2d(i,k) = 0.0
419         \textcolor{keywordflow}{if} (abs(uh\_remain)>0.0) \textcolor{keywordflow}{then}
420           \textcolor{keywordflow}{do} k\_rev = k,1,-1
421             uh\_sum = uh\_remain + uh2d(i,k\_rev)
422             \textcolor{keywordflow}{if} (uh\_sum<0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Transport to the left}
423               hup = h2d(i+1,k\_rev)
424               hlos = max(0.0,uh2d(i+1,k\_rev))
425               \textcolor{keywordflow}{if} ((((hup - hlos) + uh\_sum) < 0.0) .and. &
426                   ((0.5*hup + uh\_sum) < 0.0)) \textcolor{keywordflow}{then}
427                 uh2d(i,k\_rev) = min(-0.5*hup,-hup+hlos,0.0)
428                 uh\_remain = uh\_sum - uh2d(i,k\_rev)
429               \textcolor{keywordflow}{else}
430                 uh2d(i,k\_rev) = uh\_sum
431                 uh\_remain = 0.0
432                 \textcolor{keywordflow}{exit}
433 \textcolor{keywordflow}{              endif}
434             \textcolor{keywordflow}{else} \textcolor{comment}{! Transport to the right}
435               hup = h2d(i,k\_rev)
436               hlos = max(0.0,-uh2d(i-1,k\_rev))
437               \textcolor{keywordflow}{if} ((((hup - hlos) - uh\_sum) < 0.0) .and. &
438                   ((0.5*hup - uh\_sum) < 0.0)) \textcolor{keywordflow}{then}
439                 uh2d(i,k\_rev) = max(0.5*hup,hup-hlos,0.0)
440                 uh\_remain = uh\_sum - uh2d(i,k\_rev)
441               \textcolor{keywordflow}{else}
442                 uh2d(i,k\_rev) = uh\_sum
443                 uh\_remain = 0.0
444                 \textcolor{keywordflow}{exit}
445 \textcolor{keywordflow}{              endif}
446 \textcolor{keywordflow}{            endif}
447 \textcolor{keywordflow}{          enddo} \textcolor{comment}{! k\_rev}
448 \textcolor{keywordflow}{        endif}
449 
450         \textcolor{keywordflow}{if} (abs(uh\_remain)>0.0) \textcolor{keywordflow}{then}
451           \textcolor{keywordflow}{if} (k<nz) \textcolor{keywordflow}{then}
452             uh2d(i,k+1) = uh2d(i,k+1) + uh\_remain
453           \textcolor{keywordflow}{else}
454             uh2d(i,k) = uh2d(i,k) + uh\_remain
455             \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"Water column cannot accommodate UH redistribution. Tracer may not be
       conserved"})
456 \textcolor{keywordflow}{          endif}
457 \textcolor{keywordflow}{        endif}
458 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-loop}
459 
460       \textcolor{comment}{! Calculate and check that column integrated transports match the original to}
461       \textcolor{comment}{! within the tolerance limit}
462       uh\_neglect = gv%Angstrom\_H*g%US%L\_to\_m**2 * min(g%areaT(i,j), g%areaT(i+1,j))
463       \textcolor{keywordflow}{if} (abs(uh\_col - sum(uh2d(i,:)))>uh\_neglect) \textcolor{keywordflow}{then}
464         \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"Column integral of uh does not match after "}//&
465         \textcolor{stringliteral}{"upwards redistribution"})
466 \textcolor{keywordflow}{      endif}
467 
468 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i-loop}
469 
470     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie
471       uh(i,j,k) = uh2d(i,k)
472 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
473 \textcolor{keywordflow}{  enddo}
474 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_ad23ced9ed480b299332ca600e97d82bc}\label{namespacemom__offline__aux_ad23ced9ed480b299332ca600e97d82bc}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!distribute\+\_\+residual\+\_\+vh\+\_\+barotropic@{distribute\+\_\+residual\+\_\+vh\+\_\+barotropic}}
\index{distribute\+\_\+residual\+\_\+vh\+\_\+barotropic@{distribute\+\_\+residual\+\_\+vh\+\_\+barotropic}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{distribute\+\_\+residual\+\_\+vh\+\_\+barotropic()}{distribute\_residual\_vh\_barotropic()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::distribute\+\_\+residual\+\_\+vh\+\_\+barotropic (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{hvol,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vh }\end{DoxyParamCaption})}



Redistribute the v-\/flux as a barotropic equivalent. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em hvol} & Mass of water in the cells at the end\\
\hline
\mbox{\tt in,out}  & {\em vh} & Meridional mass transport within a timestep \mbox{[}kg\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 311 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
311   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{    !< ocean grid structure}
312   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{   !< ocean vertical grid structure}
313   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
314                            \textcolor{keywordtype}{intent(in   )} :: hvol\textcolor{comment}{ !< Mass of water in the cells at the end}
315 \textcolor{comment}{                                                 !! of the previous timestep [kg]}
316   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
317                            \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{   !< Meridional mass transport within a timestep [kg]}
318 
319   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJB\_(G),SZK\_(G))}   :: vh2d
320   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJB\_(G))}           :: vh2d\_sum
321   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))}    :: h2d
322   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G))}            :: h2d\_sum
323 
324   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz
325   \textcolor{keywordtype}{real} :: vh\_neglect
326 
327   \textcolor{comment}{! Set index-related variables for fields on T-grid}
328   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
329 
330   \textcolor{keywordflow}{do} i=is,ie
331     vh2d\_sum(:) = 0.0
332     \textcolor{comment}{! Copy over uh to a working array and sum up the remaining fluxes in a column}
333     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je
334       vh2d(j,k) = vh(i,j,k)
335       vh2d\_sum(j) = vh2d\_sum(j) + vh2d(j,k)
336 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
337 
338     \textcolor{comment}{! Copy over h to a working array and calculate column volume}
339     h2d\_sum(:) = 0.0
340     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je+1
341       h2d(j,k) = hvol(i,j,k)
342       \textcolor{keywordflow}{if} (hvol(i,j,k)>0.) \textcolor{keywordflow}{then}
343         h2d\_sum(j) = h2d\_sum(j) + h2d(j,k)
344       \textcolor{keywordflow}{else}
345         h2d(j,k) = gv%H\_subroundoff
346 \textcolor{keywordflow}{      endif}
347 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
348 
349     \textcolor{comment}{! Distribute flux evenly throughout a column}
350     \textcolor{keywordflow}{do} j=js-1,je
351       \textcolor{keywordflow}{if} ( vh2d\_sum(j)>0.0 ) \textcolor{keywordflow}{then}
352         \textcolor{keywordflow}{do} k=1,nz
353           vh2d(j,k) = vh2d\_sum(j)*(h2d(j,k)/h2d\_sum(j))
354 \textcolor{keywordflow}{        enddo}
355       \textcolor{keywordflow}{elseif} (vh2d\_sum(j)<0.0) \textcolor{keywordflow}{then}
356         \textcolor{keywordflow}{do} k=1,nz
357           vh2d(j,k) = vh2d\_sum(j)*(h2d(j+1,k)/h2d\_sum(j+1))
358 \textcolor{keywordflow}{        enddo}
359       \textcolor{keywordflow}{else}
360         \textcolor{keywordflow}{do} k=1,nz
361           vh2d(j,k) = 0.0
362 \textcolor{keywordflow}{        enddo}
363 \textcolor{keywordflow}{      endif}
364       \textcolor{comment}{! Calculate and check that column integrated transports match the original to}
365       \textcolor{comment}{! within the tolerance limit}
366       vh\_neglect = gv%Angstrom\_H*g%US%L\_to\_m**2 * min(g%areaT(i,j), g%areaT(i,j+1))
367       \textcolor{keywordflow}{if} ( abs(sum(vh2d(j,:))-vh2d\_sum(j)) > vh\_neglect) \textcolor{keywordflow}{then}
368           \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"Column integral of vh does not match after "}//&
369           \textcolor{stringliteral}{"barotropic redistribution"})
370 \textcolor{keywordflow}{      endif}
371 
372 \textcolor{keywordflow}{    enddo}
373 
374     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je
375       vh(i,j,k) = vh2d(j,k)
376 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
377 \textcolor{keywordflow}{  enddo}
378 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_ae89d0bdb8c648bc137a188c4f7fa956d}\label{namespacemom__offline__aux_ae89d0bdb8c648bc137a188c4f7fa956d}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!distribute\+\_\+residual\+\_\+vh\+\_\+upwards@{distribute\+\_\+residual\+\_\+vh\+\_\+upwards}}
\index{distribute\+\_\+residual\+\_\+vh\+\_\+upwards@{distribute\+\_\+residual\+\_\+vh\+\_\+upwards}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{distribute\+\_\+residual\+\_\+vh\+\_\+upwards()}{distribute\_residual\_vh\_upwards()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::distribute\+\_\+residual\+\_\+vh\+\_\+upwards (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{hvol,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vh }\end{DoxyParamCaption})}



In the case where offline advection has failed to converge, redistribute the u-\/flux into layers above. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em hvol} & Mass of water in the cells at the end\\
\hline
\mbox{\tt in,out}  & {\em vh} & Meridional mass transport within a timestep \mbox{[}kg\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 480 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
480   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{     !< ocean grid structure}
481   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{    !< ocean vertical grid structure}
482   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
483                            \textcolor{keywordtype}{intent(in   )} :: hvol\textcolor{comment}{  !< Mass of water in the cells at the end}
484 \textcolor{comment}{                                                  !! of the previous timestep [kg]}
485   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
486                            \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{    !< Meridional mass transport within a timestep [kg]}
487 
488   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJB\_(G),SZK\_(G))}   :: vh2d
489   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJB\_(G))}           :: vh2d\_sum
490   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))}    :: h2d
491   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G))}            :: h2d\_sum
492 
493   \textcolor{keywordtype}{real}  :: vh\_neglect, vh\_remain, vh\_col, vh\_sum
494   \textcolor{keywordtype}{real}  :: hup, hlos, min\_h
495   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz, k\_rev
496 
497   \textcolor{comment}{! Set index-related variables for fields on T-grid}
498   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
499 
500   min\_h = 0.1*gv%Angstrom\_H
501 
502   \textcolor{keywordflow}{do} i=is,ie
503     \textcolor{comment}{! Copy over uh and cell volume to working arrays}
504     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-2,je+1
505       vh2d(j,k) = vh(i,j,k)
506 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
507     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je+1
508       h2d(j,k) = hvol(i,j,k)-min\_h*g%US%L\_to\_m**2*g%areaT(i,j)
509 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
510 
511     \textcolor{keywordflow}{do} j=js-1,je
512       vh\_col = sum(vh2d(j,:))
513       \textcolor{keywordflow}{do} k=1,nz
514         vh\_remain = vh2d(j,k)
515         vh2d(j,k) = 0.0
516         \textcolor{keywordflow}{if} (abs(vh\_remain)>0.0) \textcolor{keywordflow}{then}
517           \textcolor{keywordflow}{do} k\_rev = k,1,-1
518             vh\_sum = vh\_remain + vh2d(j,k\_rev)
519             \textcolor{keywordflow}{if} (vh\_sum<0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Transport to the left}
520               hup = h2d(j+1,k\_rev)
521               hlos = max(0.0,vh2d(j+1,k\_rev))
522               \textcolor{keywordflow}{if} ((((hup - hlos) + vh\_sum) < 0.0) .and. &
523                   ((0.5*hup + vh\_sum) < 0.0)) \textcolor{keywordflow}{then}
524                 vh2d(j,k\_rev) = min(-0.5*hup,-hup+hlos,0.0)
525                 vh\_remain = vh\_sum - vh2d(j,k\_rev)
526               \textcolor{keywordflow}{else}
527                 vh2d(j,k\_rev) = vh\_sum
528                 vh\_remain = 0.0
529                 \textcolor{keywordflow}{exit}
530 \textcolor{keywordflow}{              endif}
531             \textcolor{keywordflow}{else} \textcolor{comment}{! Transport to the right}
532               hup = h2d(j,k\_rev)
533               hlos = max(0.0,-vh2d(j-1,k\_rev))
534               \textcolor{keywordflow}{if} ((((hup - hlos) - vh\_sum) < 0.0) .and. &
535                   ((0.5*hup - vh\_sum) < 0.0)) \textcolor{keywordflow}{then}
536                 vh2d(j,k\_rev) = max(0.5*hup,hup-hlos,0.0)
537                 vh\_remain = vh\_sum - vh2d(j,k\_rev)
538               \textcolor{keywordflow}{else}
539                 vh2d(j,k\_rev) = vh\_sum
540                 vh\_remain = 0.0
541                 \textcolor{keywordflow}{exit}
542 \textcolor{keywordflow}{              endif}
543 \textcolor{keywordflow}{            endif}
544 
545 \textcolor{keywordflow}{          enddo} \textcolor{comment}{! k\_rev}
546 \textcolor{keywordflow}{        endif}
547 
548         \textcolor{keywordflow}{if} (abs(vh\_remain)>0.0) \textcolor{keywordflow}{then}
549          \textcolor{keywordflow}{if} (k<nz) \textcolor{keywordflow}{then}
550             vh2d(j,k+1) = vh2d(j,k+1) + vh\_remain
551           \textcolor{keywordflow}{else}
552             vh2d(j,k) = vh2d(j,k) + vh\_remain
553             \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"Water column cannot accommodate VH redistribution. Tracer will not be
       conserved"})
554 \textcolor{keywordflow}{          endif}
555 \textcolor{keywordflow}{        endif} \textcolor{comment}{! k-loop}
556 \textcolor{keywordflow}{      enddo}
557 
558       \textcolor{comment}{! Calculate and check that column integrated transports match the original to}
559       \textcolor{comment}{! within the tolerance limit}
560       vh\_neglect = gv%Angstrom\_H*g%US%L\_to\_m**2 * min(g%areaT(i,j), g%areaT(i,j+1))
561       \textcolor{keywordflow}{if} ( abs(vh\_col-sum(vh2d(j,:))) > vh\_neglect) \textcolor{keywordflow}{then}
562         \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"Column integral of vh does not match after "}//&
563                                \textcolor{stringliteral}{"upwards redistribution"})
564 \textcolor{keywordflow}{      endif}
565 \textcolor{keywordflow}{    enddo}
566 
567     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js-1,je
568       vh(i,j,k) = vh2d(j,k)
569 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
570 \textcolor{keywordflow}{  enddo}
571 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_a970148366cfc57cb311ab0c3fdbf0f6b}\label{namespacemom__offline__aux_a970148366cfc57cb311ab0c3fdbf0f6b}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!limit\+\_\+mass\+\_\+flux\+\_\+3d@{limit\+\_\+mass\+\_\+flux\+\_\+3d}}
\index{limit\+\_\+mass\+\_\+flux\+\_\+3d@{limit\+\_\+mass\+\_\+flux\+\_\+3d}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{limit\+\_\+mass\+\_\+flux\+\_\+3d()}{limit\_mass\_flux\_3d()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::limit\+\_\+mass\+\_\+flux\+\_\+3d (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{uh,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(inout)}]{vh,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{ea,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{eb,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+pre }\end{DoxyParamCaption})}



This routine limits the mass fluxes so that the a layer cannot be completely depleted. N\+O\+TE\+: Only used in non-\/\+A\+LE mode. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in,out}  & {\em uh} & Mass flux through zonal face \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vh} & Mass flux through meridional face \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em ea} & Mass of fluid entrained from the layer\\
\hline
\mbox{\tt in,out}  & {\em eb} & Mass of fluid entrained from the layer\\
\hline
\mbox{\tt in}  & {\em h\+\_\+pre} & Layer thicknesses at the end of the previous \\
\hline
\end{DoxyParams}


Definition at line 137 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
137   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{     !< ocean grid structure}
138   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{    !< ocean vertical grid structure}
139   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
140                            \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{    !< Mass flux through zonal face [kg]}
141   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
142                            \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{    !< Mass flux through meridional face [kg]}
143   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
144                            \textcolor{keywordtype}{intent(inout)} :: ea\textcolor{comment}{    !< Mass of fluid entrained from the layer}
145 \textcolor{comment}{                                                  !! above within this timestep [kg m-2]}
146   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
147                            \textcolor{keywordtype}{intent(inout)} :: eb\textcolor{comment}{    !< Mass of fluid entrained from the layer}
148 \textcolor{comment}{                                                  !! below within this timestep [kg m-2]}
149   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
150                            \textcolor{keywordtype}{intent(in)}    :: h\_pre\textcolor{comment}{ !< Layer thicknesses at the end of the previous}
151 \textcolor{comment}{                                                  !! step [kg m-2].}
152 
153   \textcolor{comment}{! Local variables}
154   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz
155   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: top\_flux, bottom\_flux
156   \textcolor{keywordtype}{real} :: pos\_flux, hvol, h\_neglect, scale\_factor, max\_off\_cfl
157 
158   max\_off\_cfl =0.5
159 
160   \textcolor{comment}{! In this subroutine, fluxes out of the box are scaled away if they deplete}
161   \textcolor{comment}{! the layer, note that we define the positive direction as flux out of the box.}
162   \textcolor{comment}{! Hence, uh(I-1) is multipled by negative one, but uh(I) is not}
163 
164   \textcolor{comment}{! Set index-related variables for fields on T-grid}
165   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
166 
167   \textcolor{comment}{! Calculate top and bottom fluxes from ea and eb. Note the explicit negative signs}
168   \textcolor{comment}{! to enforce the positive out convention}
169   k = 1
170   \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
171     top\_flux(i,j,k) = -ea(i,j,k)
172     bottom\_flux(i,j,k) = -(eb(i,j,k)-ea(i,j,k+1))
173 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
174 
175   \textcolor{keywordflow}{do} k=2, nz-1 ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
176     top\_flux(i,j,k) = -(ea(i,j,k)-eb(i,j,k-1))
177     bottom\_flux(i,j,k) = -(eb(i,j,k)-ea(i,j,k+1))
178 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
179 
180   k=nz
181   \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
182     top\_flux(i,j,k) = -(ea(i,j,k)-eb(i,j,k-1))
183     bottom\_flux(i,j,k) = -eb(i,j,k)
184 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
185 
186 
187   \textcolor{comment}{! Calculate sum of positive fluxes (negatives applied to enforce convention)}
188   \textcolor{comment}{! in a given cell and scale it back if it would deplete a layer}
189   \textcolor{keywordflow}{do} k = 1, nz ; \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
190 
191     hvol = h\_pre(i,j,k)*g%US%L\_to\_m**2*g%areaT(i,j)
192     pos\_flux  = max(0.0,-uh(i-1,j,k)) + max(0.0, -vh(i,j-1,k)) + &
193       max(0.0, uh(i,j,k)) + max(0.0, vh(i,j,k)) + &
194       max(0.0, top\_flux(i,j,k)*g%US%L\_to\_m**2*g%areaT(i,j)) + max(0.0, bottom\_flux(i,j,k)*g%US%L\_to\_m**2*g
      %areaT(i,j))
195 
196     \textcolor{keywordflow}{if} (pos\_flux>hvol .and. pos\_flux>0.0) \textcolor{keywordflow}{then}
197       scale\_factor = ( hvol )/pos\_flux*max\_off\_cfl
198     \textcolor{keywordflow}{else} \textcolor{comment}{! Don't scale}
199       scale\_factor = 1.0
200 \textcolor{keywordflow}{    endif}
201 
202     \textcolor{comment}{! Scale horizontal fluxes}
203     \textcolor{keywordflow}{if} (-uh(i-1,j,k)>0) uh(i-1,j,k) = uh(i-1,j,k)*scale\_factor
204     \textcolor{keywordflow}{if} (uh(i,j,k)>0)    uh(i,j,k)   = uh(i,j,k)*scale\_factor
205     \textcolor{keywordflow}{if} (-vh(i,j-1,k)>0) vh(i,j-1,k) = vh(i,j-1,k)*scale\_factor
206     \textcolor{keywordflow}{if} (vh(i,j,k)>0)    vh(i,j,k)   = vh(i,j,k)*scale\_factor
207 
208     \textcolor{keywordflow}{if} (k>1 .and. k<nz) \textcolor{keywordflow}{then}
209     \textcolor{comment}{! Scale interior layers}
210       \textcolor{keywordflow}{if} (top\_flux(i,j,k)>0.0) \textcolor{keywordflow}{then}
211         ea(i,j,k) = ea(i,j,k)*scale\_factor
212         eb(i,j,k-1) = eb(i,j,k-1)*scale\_factor
213 \textcolor{keywordflow}{      endif}
214       \textcolor{keywordflow}{if} (bottom\_flux(i,j,k)>0.0) \textcolor{keywordflow}{then}
215         eb(i,j,k) = eb(i,j,k)*scale\_factor
216         ea(i,j,k+1) = ea(i,j,k+1)*scale\_factor
217 \textcolor{keywordflow}{      endif}
218     \textcolor{comment}{! Scale top layer}
219     \textcolor{keywordflow}{elseif} (k==1) \textcolor{keywordflow}{then}
220       \textcolor{keywordflow}{if} (top\_flux(i,j,k)>0.0)    ea(i,j,k) = ea(i,j,k)*scale\_factor
221       \textcolor{keywordflow}{if} (bottom\_flux(i,j,k)>0.0) \textcolor{keywordflow}{then}
222         eb(i,j,k)   = eb(i,j,k)*scale\_factor
223         ea(i,j,k+1) = ea(i,j,k+1)*scale\_factor
224 \textcolor{keywordflow}{      endif}
225     \textcolor{comment}{! Scale bottom layer}
226     \textcolor{keywordflow}{elseif} (k==nz) \textcolor{keywordflow}{then}
227       \textcolor{keywordflow}{if} (top\_flux(i,j,k)>0.0) \textcolor{keywordflow}{then}
228         ea(i,j,k)   = ea(i,j,k)*scale\_factor
229         eb(i,j,k-1) = eb(i,j,k-1)*scale\_factor
230 \textcolor{keywordflow}{      endif}
231       \textcolor{keywordflow}{if} (bottom\_flux(i,j,k)>0.0) eb(i,j,k)=eb(i,j,k)*scale\_factor
232 \textcolor{keywordflow}{    endif}
233 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
234 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_ac03963f0ae27e12160f78c6a420bc7a8}\label{namespacemom__offline__aux_ac03963f0ae27e12160f78c6a420bc7a8}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!offline\+\_\+add\+\_\+diurnal\+\_\+sw@{offline\+\_\+add\+\_\+diurnal\+\_\+sw}}
\index{offline\+\_\+add\+\_\+diurnal\+\_\+sw@{offline\+\_\+add\+\_\+diurnal\+\_\+sw}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{offline\+\_\+add\+\_\+diurnal\+\_\+sw()}{offline\_add\_diurnal\_sw()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::offline\+\_\+add\+\_\+diurnal\+\_\+sw (\begin{DoxyParamCaption}\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+start,  }\item[{type(time\+\_\+type), intent(in)}]{Time\+\_\+end }\end{DoxyParamCaption})}



add\+\_\+diurnal\+\_\+\+SW adjusts the shortwave fluxes in an forcying\+\_\+type variable to add a synthetic diurnal cycle. Adapted from S\+I\+S2 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em fluxes} & The type with atmospheric fluxes to be adjusted.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean lateral grid type.\\
\hline
\mbox{\tt in}  & {\em time\+\_\+start} & The start time for this step.\\
\hline
\mbox{\tt in}  & {\em time\+\_\+end} & The ending time for this step. \\
\hline
\end{DoxyParams}


Definition at line 577 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
577   \textcolor{keywordtype}{type}(forcing),         \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< The type with atmospheric fluxes to be adjusted.}
578   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< The ocean lateral grid type.}
579   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{intent(in)}    :: Time\_start\textcolor{comment}{ !< The start time for this step.}
580   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{intent(in)}    :: Time\_end\textcolor{comment}{   !< The ending time for this step.}
581 
582   \textcolor{keywordtype}{real} :: diurnal\_factor, time\_since\_ae, rad
583   \textcolor{keywordtype}{real} :: fracday\_dt, fracday\_day
584   \textcolor{keywordtype}{real} :: cosz\_day, cosz\_dt, rrsun\_day, rrsun\_dt
585   \textcolor{keywordtype}{type}(time\_type) :: dt\_here
586 
587   \textcolor{keywordtype}{integer} :: i, j, k, i2, j2, isc, iec, jsc, jec, i\_off, j\_off
588 
589   isc = g%isc ; iec = g%iec ; jsc = g%jsc ; jec = g%jec
590   i\_off = lbound(fluxes%sens,1) - g%isc ; j\_off = lbound(fluxes%sens,2) - g%jsc
591 
592   \textcolor{comment}{!   Orbital\_time extracts the time of year relative to the northern}
593   \textcolor{comment}{! hemisphere autumnal equinox from a time\_type variable.}
594   time\_since\_ae = orbital\_time(time\_start)
595   dt\_here = time\_end - time\_start
596   rad = acos(-1.)/180.
597 
598 \textcolor{comment}{!$OMP parallel do default(none) shared(isc,iec,jsc,jec,G,rad,Time\_start,dt\_here,time\_since\_ae, &}
599 \textcolor{comment}{!$OMP                                  fluxes,i\_off,j\_off) &}
600 \textcolor{comment}{!$OMP                          private(i,j,i2,j2,k,cosz\_dt,fracday\_dt,rrsun\_dt, &}
601 \textcolor{comment}{!$OMP                                  fracday\_day,cosz\_day,rrsun\_day,diurnal\_factor)}
602   \textcolor{keywordflow}{do} j=jsc,jec ; \textcolor{keywordflow}{do} i=isc,iec
603 \textcolor{comment}{!    Per Rick Hemler:}
604 \textcolor{comment}{!      Call diurnal\_solar with dtime=dt\_here to get cosz averaged over dt\_here.}
605 \textcolor{comment}{!      Call daily\_mean\_solar to get cosz averaged over a day.  Then}
606 \textcolor{comment}{!      diurnal\_factor = cosz\_dt\_ice*fracday\_dt\_ice*rrsun\_dt\_ice /}
607 \textcolor{comment}{!                       cosz\_day*fracday\_day*rrsun\_day}
608 
609     \textcolor{keyword}{call }diurnal\_solar(g%geoLatT(i,j)*rad, g%geoLonT(i,j)*rad, time\_start, cosz=cosz\_dt, &
610                        fracday=fracday\_dt, rrsun=rrsun\_dt, dt\_time=dt\_here)
611     \textcolor{keyword}{call }daily\_mean\_solar(g%geoLatT(i,j)*rad, time\_since\_ae, cosz\_day, fracday\_day, rrsun\_day)
612     diurnal\_factor = cosz\_dt*fracday\_dt*rrsun\_dt / &
613                      max(1e-30, cosz\_day*fracday\_day*rrsun\_day)
614 
615     i2 = i+i\_off ; j2 = j+j\_off
616     fluxes%sw(i2,j2) = fluxes%sw(i2,j2) * diurnal\_factor
617     fluxes%sw\_vis\_dir(i2,j2) = fluxes%sw\_vis\_dir(i2,j2) * diurnal\_factor
618     fluxes%sw\_vis\_dif(i2,j2) = fluxes%sw\_vis\_dif(i2,j2) * diurnal\_factor
619     fluxes%sw\_nir\_dir(i2,j2) = fluxes%sw\_nir\_dir(i2,j2) * diurnal\_factor
620     fluxes%sw\_nir\_dif(i2,j2) = fluxes%sw\_nir\_dif(i2,j2) * diurnal\_factor
621 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
622 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_a2a72a34fb47df31ad8a10ee51b4beca3}\label{namespacemom__offline__aux_a2a72a34fb47df31ad8a10ee51b4beca3}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!update\+\_\+h\+\_\+horizontal\+\_\+flux@{update\+\_\+h\+\_\+horizontal\+\_\+flux}}
\index{update\+\_\+h\+\_\+horizontal\+\_\+flux@{update\+\_\+h\+\_\+horizontal\+\_\+flux}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{update\+\_\+h\+\_\+horizontal\+\_\+flux()}{update\_h\_horizontal\_flux()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::update\+\_\+h\+\_\+horizontal\+\_\+flux (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{uhtr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{vhtr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+pre,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h\+\_\+new }\end{DoxyParamCaption})}



This updates thickness based on the convergence of horizontal mass fluxes N\+O\+TE\+: Only used in non-\/\+A\+LE mode. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em uhtr} & Accumulated mass flux through zonal face \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em vhtr} & Accumulated mass flux through meridional face \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h\+\_\+pre} & Previous layer thicknesses \mbox{[}kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+new} & Updated layer thicknesses \mbox{[}kg m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 46 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
46   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{     !< ocean grid structure}
47   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{    !< ocean vertical grid structure}
48   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
49                            \textcolor{keywordtype}{intent(in)}    :: uhtr\textcolor{comment}{  !< Accumulated mass flux through zonal face [kg]}
50   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
51                            \textcolor{keywordtype}{intent(in)}    :: vhtr\textcolor{comment}{  !< Accumulated mass flux through meridional face [kg]}
52   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
53                            \textcolor{keywordtype}{intent(in)}    :: h\_pre\textcolor{comment}{ !< Previous layer thicknesses [kg m-2].}
54   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
55                            \textcolor{keywordtype}{intent(inout)} :: h\_new\textcolor{comment}{ !< Updated layer thicknesses [kg m-2].}
56 
57   \textcolor{comment}{! Local variables}
58   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz
59   \textcolor{comment}{! Set index-related variables for fields on T-grid}
60   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
61 
62   \textcolor{keywordflow}{do} k = 1, nz
63     \textcolor{keywordflow}{do} i=is-1,ie+1 ; \textcolor{keywordflow}{do} j=js-1,je+1
64 
65       h\_new(i,j,k) = max(0.0, g%US%L\_to\_m**2*g%areaT(i,j)*h\_pre(i,j,k) + &
66         ((uhtr(i-1,j,k) - uhtr(i,j,k)) + (vhtr(i,j-1,k) - vhtr(i,j,k))))
67 
68       \textcolor{comment}{! In the case that the layer is now dramatically thinner than it was previously,}
69       \textcolor{comment}{! add a bit of mass to avoid truncation errors.  This will lead to}
70       \textcolor{comment}{! non-conservation of tracers}
71       h\_new(i,j,k) = h\_new(i,j,k) + &
72         max(gv%Angstrom\_H, 1.0e-13*h\_new(i,j,k) - g%US%L\_to\_m**2*g%areaT(i,j)*h\_pre(i,j,k))
73 
74       \textcolor{comment}{! Convert back to thickness}
75       h\_new(i,j,k) = h\_new(i,j,k) / (g%US%L\_to\_m**2*g%areaT(i,j))
76 
77 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
78 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_a1dd22761e228785bf84f2d6db11ba8cc}\label{namespacemom__offline__aux_a1dd22761e228785bf84f2d6db11ba8cc}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!update\+\_\+h\+\_\+vertical\+\_\+flux@{update\+\_\+h\+\_\+vertical\+\_\+flux}}
\index{update\+\_\+h\+\_\+vertical\+\_\+flux@{update\+\_\+h\+\_\+vertical\+\_\+flux}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{update\+\_\+h\+\_\+vertical\+\_\+flux()}{update\_h\_vertical\_flux()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::update\+\_\+h\+\_\+vertical\+\_\+flux (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{ea,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{eb,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+pre,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h\+\_\+new }\end{DoxyParamCaption})}



Updates layer thicknesses due to vertical mass transports N\+O\+TE\+: Only used in non-\/\+A\+LE configuration. 


\begin{DoxyParams}[1]{Parameters}
 & {\em g} & ocean grid structure\\
\hline
 & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em ea} & Mass of fluid entrained from the layer\\
\hline
\mbox{\tt in}  & {\em eb} & Mass of fluid entrained from the layer\\
\hline
\mbox{\tt in}  & {\em h\+\_\+pre} & Layer thicknesses at the end of the previous\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+new} & Updated layer thicknesses \mbox{[}kg m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 84 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
84   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}       :: G\textcolor{comment}{     !< ocean grid structure}
85   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{pointer}       :: GV\textcolor{comment}{    !< ocean vertical grid structure}
86   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
87                            \textcolor{keywordtype}{intent(in)}    :: ea\textcolor{comment}{    !< Mass of fluid entrained from the layer}
88 \textcolor{comment}{                                                  !! above within this timestep [kg m-2]}
89   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
90                            \textcolor{keywordtype}{intent(in)}    :: eb\textcolor{comment}{    !< Mass of fluid entrained from the layer}
91 \textcolor{comment}{                                                  !! below within this timestep [kg m-2]}
92   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
93                            \textcolor{keywordtype}{intent(in)}    :: h\_pre\textcolor{comment}{ !< Layer thicknesses at the end of the previous}
94 \textcolor{comment}{                                                  !! step [kg m-2].}
95   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
96                            \textcolor{keywordtype}{intent(inout)} :: h\_new\textcolor{comment}{ !< Updated layer thicknesses [kg m-2].}
97 
98   \textcolor{comment}{! Local variables}
99   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, nz
100   \textcolor{comment}{! Set index-related variables for fields on T-grid}
101   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
102 
103   \textcolor{comment}{! Update h\_new with convergence of vertical mass transports}
104   \textcolor{keywordflow}{do} j=js-1,je+1
105     \textcolor{keywordflow}{do} i=is-1,ie+1
106 
107       \textcolor{comment}{! Top layer}
108       h\_new(i,j,1) = max(0.0, h\_pre(i,j,1) + (eb(i,j,1) - ea(i,j,2) + ea(i,j,1) ))
109       h\_new(i,j,1) = h\_new(i,j,1) + &
110           max(0.0, 1.0e-13*h\_new(i,j,1) - h\_pre(i,j,1))
111 
112       \textcolor{comment}{! Bottom layer}
113 \textcolor{comment}{!        h\_new(i,j,nz) = h\_pre(i,j,nz) + (ea(i,j,nz) - eb(i,j,nz-1)+eb(i,j,nz))}
114       h\_new(i,j,nz) = max(0.0, h\_pre(i,j,nz) + (ea(i,j,nz) - eb(i,j,nz-1)+eb(i,j,nz)))
115       h\_new(i,j,nz) = h\_new(i,j,nz) + &
116           max(0.0, 1.0e-13*h\_new(i,j,nz) - h\_pre(i,j,nz))
117 
118 \textcolor{keywordflow}{    enddo}
119 
120     \textcolor{comment}{! Interior layers}
121     \textcolor{keywordflow}{do} k=2,nz-1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
122 
123       h\_new(i,j,k) = max(0.0, h\_pre(i,j,k) + ((ea(i,j,k) - eb(i,j,k-1)) + &
124           (eb(i,j,k) - ea(i,j,k+1))))
125       h\_new(i,j,k) = h\_new(i,j,k) + &
126         max(0.0, 1.0e-13*h\_new(i,j,k) - h\_pre(i,j,k))
127 
128 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
129 
130 \textcolor{keywordflow}{  enddo}
131 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_a6fc82d358eae9030a030182290a30858}\label{namespacemom__offline__aux_a6fc82d358eae9030a030182290a30858}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!update\+\_\+offline\+\_\+from\+\_\+arrays@{update\+\_\+offline\+\_\+from\+\_\+arrays}}
\index{update\+\_\+offline\+\_\+from\+\_\+arrays@{update\+\_\+offline\+\_\+from\+\_\+arrays}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{update\+\_\+offline\+\_\+from\+\_\+arrays()}{update\_offline\_from\_arrays()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::update\+\_\+offline\+\_\+from\+\_\+arrays (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{integer, intent(in)}]{nk\+\_\+input,  }\item[{integer, intent(in)}]{ridx\+\_\+sum,  }\item[{character(len=200), intent(in)}]{mean\+\_\+file,  }\item[{character(len=200), intent(in)}]{sum\+\_\+file,  }\item[{character(len=200), intent(in)}]{snap\+\_\+file,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{hend,  }\item[{real, dimension(\+:,\+:,\+:,\+:), intent(inout), allocatable}]{uhtr\+\_\+all,  }\item[{real, dimension(\+:,\+:,\+:,\+:), intent(inout), allocatable}]{vhtr\+\_\+all,  }\item[{real, dimension(\+:,\+:,\+:,\+:), intent(inout), allocatable}]{hend\+\_\+all,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{temp,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{salt,  }\item[{real, dimension(\+:,\+:,\+:,\+:), intent(inout), allocatable}]{temp\+\_\+all,  }\item[{real, dimension(\+:,\+:,\+:,\+:), intent(inout), allocatable}]{salt\+\_\+all }\end{DoxyParamCaption})}



Fields for offline transport are copied from the stored arrays read during initialization. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Horizontal grid type\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid type\\
\hline
\mbox{\tt in}  & {\em nk\+\_\+input} & Number of levels in input file\\
\hline
\mbox{\tt in}  & {\em ridx\+\_\+sum} & Index to read from\\
\hline
\mbox{\tt in}  & {\em mean\+\_\+file} & Name of file with averages fields\\
\hline
\mbox{\tt in}  & {\em sum\+\_\+file} & Name of file with summed fields\\
\hline
\mbox{\tt in}  & {\em snap\+\_\+file} & Name of file with snapshot fields\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Zonal mass fluxes \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhtr} & Meridional mass fluxes \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em hend} & End of timestep layer thickness \mbox{[}kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em uhtr\+\_\+all} & Zonal mass fluxes \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhtr\+\_\+all} & Meridional mass fluxes \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em hend\+\_\+all} & End of timestep layer thickness \mbox{[}kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em temp} & Temperature array\\
\hline
\mbox{\tt in,out}  & {\em salt} & Salinity array\\
\hline
\mbox{\tt in,out}  & {\em temp\+\_\+all} & Temperature array\\
\hline
\mbox{\tt in,out}  & {\em salt\+\_\+all} & Salinity array \\
\hline
\end{DoxyParams}


Definition at line 765 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
765   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{         !< Horizontal grid type}
766   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in   )} :: GV\textcolor{comment}{        !< Vertical grid type}
767   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in   )} :: nk\_input\textcolor{comment}{  !< Number of levels in input file}
768   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in   )} :: ridx\_sum\textcolor{comment}{  !< Index to read from}
769   \textcolor{keywordtype}{character(len=200)},                        \textcolor{keywordtype}{intent(in   )} :: mean\_file\textcolor{comment}{ !< Name of file with averages
       fields}
770   \textcolor{keywordtype}{character(len=200)},                        \textcolor{keywordtype}{intent(in   )} :: sum\_file\textcolor{comment}{  !< Name of file with summed fields}
771   \textcolor{keywordtype}{character(len=200)},                        \textcolor{keywordtype}{intent(in   )} :: snap\_file\textcolor{comment}{ !< Name of file with snapshot
       fields}
772   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{      !< Zonal mass fluxes [kg]}
773   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{      !< Meridional mass fluxes [kg]}
774   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: hend\textcolor{comment}{      !< End of timestep layer thickness
       [kg m-2]}
775   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:,:)}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{intent(inout)} :: uhtr\_all\textcolor{comment}{  !< Zonal mass fluxes [kg]}
776   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:,:)}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{intent(inout)} :: vhtr\_all\textcolor{comment}{  !< Meridional mass fluxes [kg]}
777   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:,:)}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{intent(inout)} :: hend\_all\textcolor{comment}{  !< End of timestep layer thickness
       [kg m-2]}
778   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: temp\textcolor{comment}{      !< Temperature array}
779   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: salt\textcolor{comment}{      !< Salinity array}
780   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:,:)}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{intent(inout)} :: temp\_all\textcolor{comment}{  !< Temperature array}
781   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:,:)}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{intent(inout)} :: salt\_all\textcolor{comment}{  !< Salinity array}
782 
783   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
784   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: fill\_value = 0.
785   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
786 
787   \textcolor{comment}{! Check that all fields are allocated (this is a redundant check)}
788   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(uhtr\_all)) &
789       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"uhtr\_all not allocated before call to update\_transport\_from\_arrays"})
790   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(vhtr\_all)) &
791       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"vhtr\_all not allocated before call to update\_transport\_from\_arrays"})
792   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(hend\_all)) &
793       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"hend\_all not allocated before call to update\_transport\_from\_arrays"})
794   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(temp\_all)) &
795       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"temp\_all not allocated before call to update\_transport\_from\_arrays"})
796   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(salt\_all)) &
797       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"salt\_all not allocated before call to update\_transport\_from\_arrays"})
798 
799   \textcolor{comment}{! Copy uh, vh, h\_end, temp, and salt}
800   \textcolor{keywordflow}{do} k=1,nk\_input ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
801     uhtr(i,j,k) = uhtr\_all(i,j,k,ridx\_sum)
802     vhtr(i,j,k) = vhtr\_all(i,j,k,ridx\_sum)
803     hend(i,j,k) = hend\_all(i,j,k,ridx\_sum)
804     temp(i,j,k) = temp\_all(i,j,k,ridx\_sum)
805     salt(i,j,k) = salt\_all(i,j,k,ridx\_sum)
806 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
807 
808   \textcolor{comment}{! Fill the rest of the arrays with 0s (fill\_value could probably be changed to a runtime parameter)}
809   \textcolor{keywordflow}{do} k=nk\_input+1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
810     uhtr(i,j,k) = fill\_value
811     vhtr(i,j,k) = fill\_value
812     hend(i,j,k) = fill\_value
813     temp(i,j,k) = fill\_value
814     salt(i,j,k) = fill\_value
815 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
816 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__offline__aux_a088f31cd992ae91a4610aafe43b04c08}\label{namespacemom__offline__aux_a088f31cd992ae91a4610aafe43b04c08}} 
\index{mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}!update\+\_\+offline\+\_\+from\+\_\+files@{update\+\_\+offline\+\_\+from\+\_\+files}}
\index{update\+\_\+offline\+\_\+from\+\_\+files@{update\+\_\+offline\+\_\+from\+\_\+files}!mom\+\_\+offline\+\_\+aux@{mom\+\_\+offline\+\_\+aux}}
\subsubsection{\texorpdfstring{update\+\_\+offline\+\_\+from\+\_\+files()}{update\_offline\_from\_files()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+offline\+\_\+aux\+::update\+\_\+offline\+\_\+from\+\_\+files (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{integer, intent(in)}]{nk\+\_\+input,  }\item[{character(len=$\ast$), intent(in)}]{mean\+\_\+file,  }\item[{character(len=$\ast$), intent(in)}]{sum\+\_\+file,  }\item[{character(len=$\ast$), intent(in)}]{snap\+\_\+file,  }\item[{character(len=$\ast$), intent(in)}]{surf\+\_\+file,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h\+\_\+end,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{temp\+\_\+mean,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{salt\+\_\+mean,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{mld,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Kd,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{integer, intent(in)}]{ridx\+\_\+sum,  }\item[{integer, intent(in)}]{ridx\+\_\+snap,  }\item[{logical, intent(in)}]{read\+\_\+mld,  }\item[{logical, intent(in)}]{read\+\_\+sw,  }\item[{logical, intent(in)}]{read\+\_\+ts\+\_\+uvh,  }\item[{logical, intent(in), optional}]{do\+\_\+ale\+\_\+in }\end{DoxyParamCaption})}



Controls the reading in 3d mass fluxes, diffusive fluxes, and other fields stored in a previous integration of the online model. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Horizontal grid type\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid type\\
\hline
\mbox{\tt in}  & {\em nk\+\_\+input} & Number of levels in input file\\
\hline
\mbox{\tt in}  & {\em mean\+\_\+file} & Name of file with averages fields\\
\hline
\mbox{\tt in}  & {\em sum\+\_\+file} & Name of file with summed fields\\
\hline
\mbox{\tt in}  & {\em snap\+\_\+file} & Name of file with snapshot fields\\
\hline
\mbox{\tt in}  & {\em surf\+\_\+file} & Name of file with surface fields\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Zonal mass fluxes \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhtr} & Meridional mass fluxes \mbox{[}kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+end} & End of timestep layer thickness\\
\hline
\mbox{\tt in,out}  & {\em temp\+\_\+mean} & Averaged temperature\\
\hline
\mbox{\tt in,out}  & {\em salt\+\_\+mean} & Averaged salinity\\
\hline
\mbox{\tt in,out}  & {\em mld} & Averaged mixed layer depth\\
\hline
\mbox{\tt in,out}  & {\em kd} & Diapycnal diffusivities at interfaces\\
\hline
\mbox{\tt in,out}  & {\em fluxes} & Fields with surface fluxes\\
\hline
\mbox{\tt in}  & {\em ridx\+\_\+sum} & Read index for sum, mean, and surf files\\
\hline
\mbox{\tt in}  & {\em ridx\+\_\+snap} & Read index for snapshot file\\
\hline
\mbox{\tt in}  & {\em read\+\_\+mld} & True if reading in M\+LD\\
\hline
\mbox{\tt in}  & {\em read\+\_\+sw} & True if reading in radiative fluxes\\
\hline
\mbox{\tt in}  & {\em read\+\_\+ts\+\_\+uvh} & True if reading in uh, vh, and h\\
\hline
\mbox{\tt in}  & {\em do\+\_\+ale\+\_\+in} & True if using A\+LE algorithms \\
\hline
\end{DoxyParams}


Definition at line 630 of file M\+O\+M\+\_\+offline\+\_\+aux.\+F90.


\begin{DoxyCode}
630 
631   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{         !< Horizontal grid type}
632   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in   )} :: GV\textcolor{comment}{        !< Vertical grid type}
633   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in   )} :: nk\_input\textcolor{comment}{  !< Number of levels in input file}
634   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in   )} :: mean\_file\textcolor{comment}{ !< Name of file with averages fields}
635   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in   )} :: sum\_file\textcolor{comment}{  !< Name of file with summed fields}
636   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in   )} :: snap\_file\textcolor{comment}{ !< Name of file with snapshot fields}
637   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in   )} :: surf\_file\textcolor{comment}{ !< Name of file with surface fields}
638   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
639                            \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{      !< Zonal mass fluxes [kg]}
640   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
641                            \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{      !< Meridional mass fluxes [kg]}
642   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
643                            \textcolor{keywordtype}{intent(inout)} :: h\_end\textcolor{comment}{     !< End of timestep layer thickness}
644   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
645                            \textcolor{keywordtype}{intent(inout)} :: temp\_mean\textcolor{comment}{ !< Averaged temperature}
646   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
647                            \textcolor{keywordtype}{intent(inout)} :: salt\_mean\textcolor{comment}{ !< Averaged salinity}
648   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          &
649                            \textcolor{keywordtype}{intent(inout)} :: mld\textcolor{comment}{       !< Averaged mixed layer depth}
650   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, &
651                            \textcolor{keywordtype}{intent(inout)} :: Kd\textcolor{comment}{        !< Diapycnal diffusivities at interfaces}
652   \textcolor{keywordtype}{type}(forcing),           \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{    !< Fields with surface fluxes}
653   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in   )} :: ridx\_sum\textcolor{comment}{  !< Read index for sum, mean, and surf files}
654   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in   )} :: ridx\_snap\textcolor{comment}{ !< Read index for snapshot file}
655   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in   )} :: read\_mld\textcolor{comment}{  !< True if reading in MLD}
656   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in   )} :: read\_sw\textcolor{comment}{   !< True if reading in radiative fluxes}
657   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in   )} :: read\_ts\_uvh\textcolor{comment}{ !< True if reading in uh, vh, and h}
658   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: do\_ale\_in\textcolor{comment}{ !< True if using ALE algorithms}
659 
660   \textcolor{keywordtype}{logical} :: do\_ale
661   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
662   \textcolor{keywordtype}{real}    :: Initer\_vert
663 
664   do\_ale = .false.
665   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(do\_ale\_in) ) do\_ale = do\_ale\_in
666 
667   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
668 
669   \textcolor{comment}{! Check if reading in UH, VH, and h\_end}
670   \textcolor{keywordflow}{if} (read\_ts\_uvh) \textcolor{keywordflow}{then}
671     h\_end(:,:,:) = 0.0
672     temp\_mean(:,:,:) = 0.0
673     salt\_mean(:,:,:) = 0.0
674     uhtr(:,:,:) = 0.0
675     vhtr(:,:,:) = 0.0
676     \textcolor{comment}{! Time-summed fields}
677     \textcolor{keyword}{call }mom\_read\_vector(sum\_file, \textcolor{stringliteral}{'uhtr\_sum'}, \textcolor{stringliteral}{'vhtr\_sum'}, uhtr(:,:,1:nk\_input), &
678                          vhtr(:,:,1:nk\_input), g%Domain, timelevel=ridx\_sum)
679     \textcolor{keyword}{call }mom\_read\_data(snap\_file, \textcolor{stringliteral}{'h\_end'}, h\_end(:,:,1:nk\_input), g%Domain, &
680                        timelevel=ridx\_snap,position=center)
681     \textcolor{keyword}{call }mom\_read\_data(mean\_file, \textcolor{stringliteral}{'temp'}, temp\_mean(:,:,1:nk\_input), g%Domain, &
682                        timelevel=ridx\_sum,position=center)
683     \textcolor{keyword}{call }mom\_read\_data(mean\_file, \textcolor{stringliteral}{'salt'}, salt\_mean(:,:,1:nk\_input), g%Domain, &
684                        timelevel=ridx\_sum,position=center)
685 \textcolor{keywordflow}{  endif}
686 
687   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
688     \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
689       temp\_mean(:,:,nk\_input:nz) = temp\_mean(i,j,nk\_input)
690       salt\_mean(:,:,nk\_input:nz) = salt\_mean(i,j,nk\_input)
691 \textcolor{keywordflow}{    endif}
692 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
693 
694   \textcolor{comment}{! Check if reading vertical diffusivities or entrainment fluxes}
695   \textcolor{keyword}{call }mom\_read\_data( mean\_file, \textcolor{stringliteral}{'Kd\_interface'}, kd(:,:,1:nk\_input+1), g%Domain, &
696                   timelevel=ridx\_sum,position=center)
697 
698   \textcolor{comment}{! This block makes sure that the fluxes control structure, which may not be used in the solo\_driver,}
699   \textcolor{comment}{! contains netMassIn and netMassOut which is necessary for the applyTracerBoundaryFluxesInOut routine}
700   \textcolor{keywordflow}{if} (do\_ale) \textcolor{keywordflow}{then}
701     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(fluxes%netMassOut)) \textcolor{keywordflow}{then}
702       \textcolor{keyword}{allocate}(fluxes%netMassOut(g%isd:g%ied,g%jsd:g%jed))
703       fluxes%netMassOut(:,:) = 0.0
704 \textcolor{keywordflow}{    endif}
705     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(fluxes%netMassIn)) \textcolor{keywordflow}{then}
706       \textcolor{keyword}{allocate}(fluxes%netMassIn(g%isd:g%ied,g%jsd:g%jed))
707       fluxes%netMassIn(:,:) = 0.0
708 \textcolor{keywordflow}{    endif}
709 
710     fluxes%netMassOut(:,:) = 0.0
711     fluxes%netMassIn(:,:) = 0.0
712     \textcolor{keyword}{call }mom\_read\_data(surf\_file,\textcolor{stringliteral}{'massout\_flux\_sum'},fluxes%netMassOut, g%Domain, &
713         timelevel=ridx\_sum)
714     \textcolor{keyword}{call }mom\_read\_data(surf\_file,\textcolor{stringliteral}{'massin\_flux\_sum'}, fluxes%netMassIn,  g%Domain, &
715         timelevel=ridx\_sum)
716 
717     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
718       \textcolor{keywordflow}{if} (g%mask2dT(i,j)<1.0) \textcolor{keywordflow}{then}
719         fluxes%netMassOut(i,j) = 0.0
720         fluxes%netMassIn(i,j) = 0.0
721 \textcolor{keywordflow}{      endif}
722 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
723 
724 \textcolor{keywordflow}{  endif}
725 
726   \textcolor{keywordflow}{if} (read\_mld) \textcolor{keywordflow}{then}
727     \textcolor{keyword}{call }mom\_read\_data(surf\_file, \textcolor{stringliteral}{'ePBL\_h\_ML'}, mld, g%Domain, timelevel=ridx\_sum)
728 \textcolor{keywordflow}{  endif}
729 
730   \textcolor{keywordflow}{if} (read\_sw) \textcolor{keywordflow}{then}
731     \textcolor{comment}{! Shortwave radiation is only needed for offline mode with biogeochemistry but without the coupler.}
732     \textcolor{comment}{! Need to double check, but set\_opacity seems to only need the sum of the diffuse and}
733     \textcolor{comment}{! direct fluxes in the visible and near-infrared bands. For convenience, we store the}
734     \textcolor{comment}{! sum of the direct and diffuse fluxes in the 'dir' field and set the 'dif' fields to zero}
735     \textcolor{keyword}{call }mom\_read\_data(mean\_file,\textcolor{stringliteral}{'sw\_vis'}, fluxes%sw\_vis\_dir, g%Domain, &
736                        timelevel=ridx\_sum, scale=g%US%W\_m2\_to\_QRZ\_T)
737     \textcolor{keyword}{call }mom\_read\_data(mean\_file,\textcolor{stringliteral}{'sw\_nir'}, fluxes%sw\_nir\_dir, g%Domain, &
738                        timelevel=ridx\_sum, scale=g%US%W\_m2\_to\_QRZ\_T)
739     fluxes%sw\_vis\_dir(:,:) = fluxes%sw\_vis\_dir(:,:)*0.5
740     fluxes%sw\_vis\_dif(:,:) = fluxes%sw\_vis\_dir(:,:)
741     fluxes%sw\_nir\_dir(:,:) = fluxes%sw\_nir\_dir(:,:)*0.5
742     fluxes%sw\_nir\_dif(:,:) = fluxes%sw\_nir\_dir(:,:)
743     fluxes%sw = (fluxes%sw\_vis\_dir + fluxes%sw\_vis\_dif) + (fluxes%sw\_nir\_dir + fluxes%sw\_nir\_dif)
744     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
745       \textcolor{keywordflow}{if} (g%mask2dT(i,j)<1.0) \textcolor{keywordflow}{then}
746         fluxes%sw(i,j) = 0.0
747         fluxes%sw\_vis\_dir(i,j) = 0.0
748         fluxes%sw\_nir\_dir(i,j) = 0.0
749         fluxes%sw\_vis\_dif(i,j) = 0.0
750         fluxes%sw\_nir\_dif(i,j) = 0.0
751 \textcolor{keywordflow}{      endif}
752 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
753     \textcolor{keyword}{call }pass\_var(fluxes%sw,g%Domain)
754     \textcolor{keyword}{call }pass\_var(fluxes%sw\_vis\_dir,g%Domain)
755     \textcolor{keyword}{call }pass\_var(fluxes%sw\_vis\_dif,g%Domain)
756     \textcolor{keyword}{call }pass\_var(fluxes%sw\_nir\_dir,g%Domain)
757     \textcolor{keyword}{call }pass\_var(fluxes%sw\_nir\_dif,g%Domain)
758 \textcolor{keywordflow}{  endif}
759 
\end{DoxyCode}
