\hypertarget{namespacemom__tracer__advect}{}\doxysection{mom\+\_\+tracer\+\_\+advect Module Reference}
\label{namespacemom__tracer__advect}\index{mom\_tracer\_advect@{mom\_tracer\_advect}}


\doxysubsection{Detailed Description}
This module contains the subroutines that advect tracers along coordinate surfaces. 

This program contains the subroutines that advect tracers horizontally (i.\+e. along layers).\hypertarget{namespacemom__tracer__advect_section_mom_advect_intro}{}\doxysubsection{section\+\_\+mom\+\_\+advect\+\_\+intro}\label{namespacemom__tracer__advect_section_mom_advect_intro}

\begin{DoxyItemize}
\item advect\+\_\+tracer advects tracer concentrations using a combination of the modified flux advection scheme from Easter (Mon. Wea. Rev., 1993) with tracer distributions given by the monotonic modified van Leer scheme proposed by Lin et al. (Mon. Wea. Rev., 1994). This scheme conserves the total amount of tracer while avoiding spurious maxima and minima of the tracer concentration. If a higher order accuracy scheme is needed, suggest monotonic piecewise parabolic method, as described in Carpenter et al. (M\+WR, 1990).
\item advect\+\_\+tracer has 4 arguments, described below. This subroutine determines the volume of a layer in a grid cell at the previous instance when the tracer concentration was changed, so it is essential that the volume fluxes should be correct. It is also important that the tracer advection occurs before each calculation of the diabatic forcing. 
\end{DoxyItemize}\doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for this module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__advect_a28a6e28170a8d4f34337a1a202e0d902}{advect\+\_\+tracer}} (h\+\_\+end, uhtr, vhtr, O\+BC, dt, G, GV, US, CS, Reg, h\+\_\+prev\+\_\+opt, max\+\_\+iter\+\_\+in, x\+\_\+first\+\_\+in, uhr\+\_\+out, vhr\+\_\+out, h\+\_\+out)
\begin{DoxyCompactList}\small\item\em This routine time steps the tracer concentration using a monotonic, conservative, weakly diffusive scheme. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tracer__advect_a07f6e664b3346db7f9ddbcd4b4d6c8f4}{advect\+\_\+x}} (Tr, hprev, uhr, uh\+\_\+neglect, O\+BC, domore\+\_\+u, ntr, Idt, is, ie, js, je, k, G, GV, US, use\+P\+PM, use\+Huynh)
\begin{DoxyCompactList}\small\item\em This subroutine does 1-\/d flux-\/form advection in the zonal direction using a monotonic piecewise linear scheme. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tracer__advect_a20a82831fad6aa07cb946aeadbbfdda9}{advect\+\_\+y}} (Tr, hprev, vhr, vh\+\_\+neglect, O\+BC, domore\+\_\+v, ntr, Idt, is, ie, js, je, k, G, GV, US, use\+P\+PM, use\+Huynh)
\begin{DoxyCompactList}\small\item\em This subroutine does 1-\/d flux-\/form advection using a monotonic piecewise linear scheme. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__advect_aacf9cdc544c9c3a188d6e3e9a0d7b9df}{tracer\+\_\+advect\+\_\+init}} (Time, G, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initialize lateral tracer advection module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__advect_a2e466a8a34546bb9265a74ff0209df47}{tracer\+\_\+advect\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Close the tracer advection module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__tracer__advect_a951134d3dcb3508f71abb05dc39837cc}\label{namespacemom__tracer__advect_a951134d3dcb3508f71abb05dc39837cc}} 
integer \mbox{\hyperlink{namespacemom__tracer__advect_a951134d3dcb3508f71abb05dc39837cc}{id\+\_\+clock\+\_\+advect}}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tracer__advect_a6590ebd9b76b6d5fea6d13e2deb0c271}\label{namespacemom__tracer__advect_a6590ebd9b76b6d5fea6d13e2deb0c271}} 
integer \mbox{\hyperlink{namespacemom__tracer__advect_a6590ebd9b76b6d5fea6d13e2deb0c271}{id\+\_\+clock\+\_\+pass}}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tracer__advect_a4f1598f314da682e38e10f560bb94428}\label{namespacemom__tracer__advect_a4f1598f314da682e38e10f560bb94428}} 
integer \mbox{\hyperlink{namespacemom__tracer__advect_a4f1598f314da682e38e10f560bb94428}{id\+\_\+clock\+\_\+sync}}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\end{DoxyCompactItemize}



\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tracer__advect_a28a6e28170a8d4f34337a1a202e0d902}\label{namespacemom__tracer__advect_a28a6e28170a8d4f34337a1a202e0d902}} 
\index{mom\_tracer\_advect@{mom\_tracer\_advect}!advect\_tracer@{advect\_tracer}}
\index{advect\_tracer@{advect\_tracer}!mom\_tracer\_advect@{mom\_tracer\_advect}}
\doxysubsubsection{\texorpdfstring{advect\_tracer()}{advect\_tracer()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+advect\+::advect\+\_\+tracer (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+end,  }\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[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}), pointer}]{CS,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{Reg,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{h\+\_\+prev\+\_\+opt,  }\item[{integer, intent(in), optional}]{max\+\_\+iter\+\_\+in,  }\item[{logical, intent(in), optional}]{x\+\_\+first\+\_\+in,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{uhr\+\_\+out,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out), optional}]{vhr\+\_\+out,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{h\+\_\+out }\end{DoxyParamCaption})}



This routine time steps the tracer concentration using a monotonic, conservative, weakly diffusive scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+end} & layer thickness after advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em uhtr} & accumulated volume/mass flux through zonal face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em vhtr} & accumulated volume/mass flux through merid face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
 & {\em obc} & specifies whether, where, and what O\+B\+Cs are used \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & time increment \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & control structure for module \\
\hline
 & {\em reg} & pointer to tracer registry \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+prev\+\_\+opt} & layer thickness before advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+iter\+\_\+in} & The maximum number of iterations \\
\hline
\mbox{\texttt{ in}}  & {\em x\+\_\+first\+\_\+in} & If present, indicate whether to update first in the x-\/ or y-\/direction. \\
\hline
\mbox{\texttt{ out}}  & {\em uhr\+\_\+out} & accumulated volume/mass flux through zonal face \\
\hline
\mbox{\texttt{ out}}  & {\em vhr\+\_\+out} & accumulated volume/mass flux through merid face \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+out} & layer thickness before advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 52 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{52   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{     !< ocean grid structure}}
\DoxyCodeLine{53   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< ocean vertical grid structure}}
\DoxyCodeLine{54 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{55                            \textcolor{keywordtype}{intent(in)}    :: h\_end\textcolor{comment}{ !< layer thickness after advection [H ~> m or kg m-\/2]}}
\DoxyCodeLine{56 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{57                            \textcolor{keywordtype}{intent(in)}    :: uhtr\textcolor{comment}{  !< accumulated volume/mass flux through zonal face [H L2 ~> m3 or kg]}}
\DoxyCodeLine{58 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{59                            \textcolor{keywordtype}{intent(in)}    :: vhtr\textcolor{comment}{  !< accumulated volume/mass flux through merid face [H L2 ~> m3 or kg]}}
\DoxyCodeLine{60   \textcolor{keywordtype}{type}(ocean\_OBC\_type),    \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{   !< specifies whether, where, and what OBCs are used}}
\DoxyCodeLine{61 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{    !< time increment [T ~> s]}}
\DoxyCodeLine{62   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{63   \textcolor{keywordtype}{type}(tracer\_advect\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< control structure for module}}
\DoxyCodeLine{64   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}    :: Reg\textcolor{comment}{   !< pointer to tracer registry}}
\DoxyCodeLine{65 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{66                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_prev\_opt\textcolor{comment}{ !< layer thickness before advection [H ~> m or kg m-\/2]}}
\DoxyCodeLine{67   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: max\_iter\_in\textcolor{comment}{ !< The maximum number of iterations}}
\DoxyCodeLine{68   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: x\_first\_in\textcolor{comment}{ !< If present, indicate whether to update}}
\DoxyCodeLine{69 \textcolor{comment}{                                                  !! first in the x-\/ or y-\/direction.}}
\DoxyCodeLine{70 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{71                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}    :: uhr\_out\textcolor{comment}{  !< accumulated volume/mass flux through zonal face}}
\DoxyCodeLine{72 \textcolor{comment}{                                                  !! [H L2 ~> m3 or kg]}}
\DoxyCodeLine{73 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{74                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}    :: vhr\_out\textcolor{comment}{  !< accumulated volume/mass flux through merid face}}
\DoxyCodeLine{75 \textcolor{comment}{                                                  !! [H L2 ~> m3 or kg]}}
\DoxyCodeLine{76 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \&}
\DoxyCodeLine{77                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}    :: h\_out\textcolor{comment}{ !< layer thickness before advection [H ~> m or kg m-\/2]}}
\DoxyCodeLine{78 }
\DoxyCodeLine{79   \textcolor{keywordtype}{type}(tracer\_type) :: Tr(MAX\_FIELDS\_) \textcolor{comment}{! The array of registered tracers}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{81     hprev           \textcolor{comment}{! cell volume at the end of previous tracer change [H L2 ~> m3 or kg]}}
\DoxyCodeLine{82 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{83     uhr             \textcolor{comment}{! The remaining zonal thickness flux [H L2 ~> m3 or kg]}}
\DoxyCodeLine{84 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{85     vhr             \textcolor{comment}{! The remaining meridional thickness fluxes [H L2 ~> m3 or kg]}}
\DoxyCodeLine{86 \textcolor{keywordtype}{  real} :: uh\_neglect(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! uh\_neglect and vh\_neglect are the}}
\DoxyCodeLine{87 \textcolor{keywordtype}{  real} :: vh\_neglect(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! magnitude of remaining transports that}}
\DoxyCodeLine{88                                        \textcolor{comment}{! can be simply discarded [H L2 ~> m3 or kg].}}
\DoxyCodeLine{89 }
\DoxyCodeLine{90 \textcolor{keywordtype}{  real} :: landvolfill                   \textcolor{comment}{! An arbitrary? nonzero cell volume [H L2 ~> m3 or kg].}}
\DoxyCodeLine{91 \textcolor{keywordtype}{  real} :: Idt                           \textcolor{comment}{! 1/dt [T-\/1 ~> s-\/1].}}
\DoxyCodeLine{92   \textcolor{keywordtype}{logical} :: domore\_u(SZJ\_(G),SZK\_(G))  \textcolor{comment}{! domore\_\_ indicate whether there is more}}
\DoxyCodeLine{93   \textcolor{keywordtype}{logical} :: domore\_v(SZJB\_(G),SZK\_(G)) \textcolor{comment}{! advection to be done in the corresponding}}
\DoxyCodeLine{94                                         \textcolor{comment}{! row or column.}}
\DoxyCodeLine{95   \textcolor{keywordtype}{logical} :: x\_first            \textcolor{comment}{! If true, advect in the x-\/direction first.}}
\DoxyCodeLine{96   \textcolor{keywordtype}{integer} :: max\_iter           \textcolor{comment}{! maximum number of iterations in each layer}}
\DoxyCodeLine{97   \textcolor{keywordtype}{integer} :: domore\_k(SZK\_(G))}
\DoxyCodeLine{98   \textcolor{keywordtype}{integer} :: stencil            \textcolor{comment}{! stencil of the advection scheme}}
\DoxyCodeLine{99   \textcolor{keywordtype}{integer} :: nsten\_halo         \textcolor{comment}{! number of stencils that fit in the halos}}
\DoxyCodeLine{100   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz, itt, ntr, do\_any}
\DoxyCodeLine{101   \textcolor{keywordtype}{integer} :: isv, iev, jsv, jev \textcolor{comment}{! The valid range of the indices.}}
\DoxyCodeLine{102   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{103 }
\DoxyCodeLine{104   domore\_u(:,:) = .false.}
\DoxyCodeLine{105   domore\_v(:,:) = .false.}
\DoxyCodeLine{106   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{107   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{108   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{109   landvolfill = 1.0e-\/20         \textcolor{comment}{! This is arbitrary, but must be positive.}}
\DoxyCodeLine{110   stencil = 2                   \textcolor{comment}{! The scheme's stencil; 2 for PLM and PPM:H3}}
\DoxyCodeLine{111 }
\DoxyCodeLine{112   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tracer\_advect: "}// \&}
\DoxyCodeLine{113        \textcolor{stringliteral}{"tracer\_advect\_init must be called before advect\_tracer."})}
\DoxyCodeLine{114   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(reg)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tracer\_advect: "}// \&}
\DoxyCodeLine{115        \textcolor{stringliteral}{"register\_tracer must be called before advect\_tracer."})}
\DoxyCodeLine{116   \textcolor{keywordflow}{if} (reg\%ntr==0) \textcolor{keywordflow}{return}}
\DoxyCodeLine{117   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_advect)}
\DoxyCodeLine{118   x\_first = (mod(g\%first\_direction,2) == 0)}
\DoxyCodeLine{119 }
\DoxyCodeLine{120   \textcolor{comment}{! increase stencil size for Colella \& Woodward PPM}}
\DoxyCodeLine{121   \textcolor{keywordflow}{if} (cs\%usePPM .and. .not. cs\%useHuynh) stencil = 3}
\DoxyCodeLine{122 }
\DoxyCodeLine{123   ntr = reg\%ntr}
\DoxyCodeLine{124   \textcolor{keywordflow}{do} m=1,ntr ; tr(m) = reg\%Tr(m) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{125   idt = 1.0 / dt}
\DoxyCodeLine{126 }
\DoxyCodeLine{127   max\_iter = 2*int(ceiling(dt/cs\%dt)) + 1}
\DoxyCodeLine{128 }
\DoxyCodeLine{129   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(max\_iter\_in)) max\_iter = max\_iter\_in}
\DoxyCodeLine{130   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(x\_first\_in))  x\_first = x\_first\_in}
\DoxyCodeLine{131   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass)}
\DoxyCodeLine{132   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_uhr\_vhr\_t\_hprev, uhr, vhr, g\%Domain)}
\DoxyCodeLine{133   \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_uhr\_vhr\_t\_hprev, hprev, g\%Domain)}
\DoxyCodeLine{134   \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{135     \textcolor{keyword}{call }create\_group\_pass(cs\%pass\_uhr\_vhr\_t\_hprev, tr(m)\%t, g\%Domain)}
\DoxyCodeLine{136 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{137   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass)}
\DoxyCodeLine{138 }
\DoxyCodeLine{139 \textcolor{comment}{!\$OMP parallel default(none) shared(nz,jsd,jed,IsdB,IedB,uhr,jsdB,jedB,Isd,Ied,vhr, \&}}
\DoxyCodeLine{140 \textcolor{comment}{!\$OMP                               hprev,domore\_k,js,je,is,ie,uhtr,vhtr,G,GV,h\_end,\&}}
\DoxyCodeLine{141 \textcolor{comment}{!\$OMP                               uh\_neglect,vh\_neglect,ntr,Tr,h\_prev\_opt)}}
\DoxyCodeLine{142 }
\DoxyCodeLine{143   \textcolor{comment}{! This initializes the halos of uhr and vhr because pass\_vector might do}}
\DoxyCodeLine{144   \textcolor{comment}{! calculations on them, even though they are never used.}}
\DoxyCodeLine{145   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{146   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{147     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb ; uhr(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{148     \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied ; vhr(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{149     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; hprev(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{150     domore\_k(k)=1}
\DoxyCodeLine{151     \textcolor{comment}{!  Put the remaining (total) thickness fluxes into uhr and vhr.}}
\DoxyCodeLine{152     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie ; uhr(i,j,k) = uhtr(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{153     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie ; vhr(i,j,k) = vhtr(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{154     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{present}(h\_prev\_opt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{155     \textcolor{comment}{!   This loop reconstructs the thickness field the last time that the}}
\DoxyCodeLine{156     \textcolor{comment}{! tracers were updated, probably just after the diabatic forcing.  A useful}}
\DoxyCodeLine{157     \textcolor{comment}{! diagnostic could be to compare this reconstruction with that older value.}}
\DoxyCodeLine{158       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{159         hprev(i,j,k) = max(0.0, g\%areaT(i,j)*h\_end(i,j,k) + \&}
\DoxyCodeLine{160              ((uhr(i,j,k) -\/ uhr(i-\/1,j,k)) + (vhr(i,j,k) -\/ vhr(i,j-\/1,k))))}
\DoxyCodeLine{161     \textcolor{comment}{! In the case that the layer is now dramatically thinner than it was previously,}}
\DoxyCodeLine{162     \textcolor{comment}{! add a bit of mass to avoid truncation errors.  This will lead to}}
\DoxyCodeLine{163     \textcolor{comment}{! non-\/conservation of tracers}}
\DoxyCodeLine{164         hprev(i,j,k) = hprev(i,j,k) + \&}
\DoxyCodeLine{165                        max(0.0, 1.0e-\/13*hprev(i,j,k) -\/ g\%areaT(i,j)*h\_end(i,j,k))}
\DoxyCodeLine{166 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{167     \textcolor{keywordflow}{else}}
\DoxyCodeLine{168       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{169         hprev(i,j,k) = h\_prev\_opt(i,j,k)}
\DoxyCodeLine{170 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{171 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{172 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{173 }
\DoxyCodeLine{174 }
\DoxyCodeLine{175   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{176   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied-\/1}
\DoxyCodeLine{177     uh\_neglect(i,j) = gv\%H\_subroundoff * min(g\%areaT(i,j), g\%areaT(i+1,j))}
\DoxyCodeLine{178 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{179   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{180   \textcolor{keywordflow}{do} j=jsd,jed-\/1 ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{181     vh\_neglect(i,j) = gv\%H\_subroundoff * min(g\%areaT(i,j), g\%areaT(i,j+1))}
\DoxyCodeLine{182 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{183 }
\DoxyCodeLine{184   \textcolor{comment}{! initialize diagnostic fluxes and tendencies}}
\DoxyCodeLine{185   \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{186   \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{187     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad\_x)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{188       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{189         tr(m)\%ad\_x(i,j,k) = 0.0}
\DoxyCodeLine{190 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{191 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{192     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad\_y)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{193       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{194         tr(m)\%ad\_y(i,j,k) = 0.0}
\DoxyCodeLine{195 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{196 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{197     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%advection\_xy)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{198       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{199         tr(m)\%advection\_xy(i,j,k) = 0.0}
\DoxyCodeLine{200 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{201 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{202     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad2d\_x)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{203       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; tr(m)\%ad2d\_x(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{204 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{205     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad2d\_y)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{206       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; tr(m)\%ad2d\_y(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{207 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{208 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{209   \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{210 }
\DoxyCodeLine{211   isv = is ; iev = ie ; jsv = js ; jev = je}
\DoxyCodeLine{212 }
\DoxyCodeLine{213   \textcolor{keywordflow}{do} itt=1,max\_iter}
\DoxyCodeLine{214 }
\DoxyCodeLine{215     \textcolor{keywordflow}{if} (isv > is-\/stencil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{216       \textcolor{keyword}{call }do\_group\_pass(cs\%pass\_uhr\_vhr\_t\_hprev, g\%Domain, clock=id\_clock\_pass)}
\DoxyCodeLine{217 }
\DoxyCodeLine{218       nsten\_halo = min(is-\/isd,ied-\/ie,js-\/jsd,jed-\/je)/stencil}
\DoxyCodeLine{219       isv = is-\/nsten\_halo*stencil ; jsv = js-\/nsten\_halo*stencil}
\DoxyCodeLine{220       iev = ie+nsten\_halo*stencil ; jev = je+nsten\_halo*stencil}
\DoxyCodeLine{221       \textcolor{comment}{! Reevaluate domore\_u \& domore\_v unless the valid range is the same size as}}
\DoxyCodeLine{222       \textcolor{comment}{! before.  Also, do this if there is Strang splitting.}}
\DoxyCodeLine{223       \textcolor{keywordflow}{if} ((nsten\_halo > 1) .or. (itt==1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{224         \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{225         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{226           \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{if} (.not.domore\_u(j,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{227             \textcolor{keywordflow}{do} i=isv+stencil-\/1,iev-\/stencil; \textcolor{keywordflow}{if} (uhr(i,j,k) /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{228               domore\_u(j,k) = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{229 \textcolor{keywordflow}{            endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{230 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{231           \textcolor{keywordflow}{do} j=jsv+stencil-\/1,jev-\/stencil ; \textcolor{keywordflow}{if} (.not.domore\_v(j,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{232             \textcolor{keywordflow}{do} i=isv+stencil,iev-\/stencil; \textcolor{keywordflow}{if} (vhr(i,j,k) /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{233               domore\_v(j,k) = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{234 \textcolor{keywordflow}{            endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{235 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{236 }
\DoxyCodeLine{237           \textcolor{comment}{!   At this point, domore\_k is global.  Change it so that it indicates}}
\DoxyCodeLine{238           \textcolor{comment}{! whether any work is needed on a layer on this processor.}}
\DoxyCodeLine{239           domore\_k(k) = 0}
\DoxyCodeLine{240           \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{if} (domore\_u(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{241           \textcolor{keywordflow}{do} j=jsv+stencil-\/1,jev-\/stencil ; \textcolor{keywordflow}{if} (domore\_v(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{242 }
\DoxyCodeLine{243 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! k-\/loop}}
\DoxyCodeLine{244 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{245 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{246 }
\DoxyCodeLine{247     \textcolor{comment}{! Set the range of valid points after this iteration.}}
\DoxyCodeLine{248     isv = isv + stencil ; iev = iev -\/ stencil}
\DoxyCodeLine{249     jsv = jsv + stencil ; jev = jev -\/ stencil}
\DoxyCodeLine{250 }
\DoxyCodeLine{251     \textcolor{comment}{!  To ensure positive definiteness of the thickness at each iteration, the}}
\DoxyCodeLine{252     \textcolor{comment}{!  mass fluxes out of each layer are checked each step, and limited to keep}}
\DoxyCodeLine{253     \textcolor{comment}{!  the thicknesses positive.  This means that several iterations may be required}}
\DoxyCodeLine{254     \textcolor{comment}{!  for all the transport to happen.  The sum over domore\_k keeps the processors}}
\DoxyCodeLine{255     \textcolor{comment}{!  synchronized.  This may not be very efficient, but it should be reliable.}}
\DoxyCodeLine{256 }
\DoxyCodeLine{257     \textcolor{comment}{!\$OMP parallel default(shared)}}
\DoxyCodeLine{258 }
\DoxyCodeLine{259     \textcolor{keywordflow}{if} (x\_first) \textcolor{keywordflow}{then}}
\DoxyCodeLine{260 }
\DoxyCodeLine{261       \textcolor{comment}{!\$OMP do ordered}}
\DoxyCodeLine{262       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{263         \textcolor{comment}{! First, advect zonally.}}
\DoxyCodeLine{264         \textcolor{keyword}{call }advect\_x(tr, hprev, uhr, uh\_neglect, obc, domore\_u, ntr, idt, \&}
\DoxyCodeLine{265                       isv, iev, jsv-\/stencil, jev+stencil, k, g, gv, us, cs\%usePPM, cs\%useHuynh)}
\DoxyCodeLine{266 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{267 }
\DoxyCodeLine{268       \textcolor{comment}{!\$OMP do ordered}}
\DoxyCodeLine{269       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{270         \textcolor{comment}{!  Next, advect meridionally.}}
\DoxyCodeLine{271         \textcolor{keyword}{call }advect\_y(tr, hprev, vhr, vh\_neglect, obc, domore\_v, ntr, idt, \&}
\DoxyCodeLine{272                       isv, iev, jsv, jev, k, g, gv, us, cs\%usePPM, cs\%useHuynh)}
\DoxyCodeLine{273 }
\DoxyCodeLine{274         \textcolor{comment}{! Update domore\_k(k) for the next iteration}}
\DoxyCodeLine{275         domore\_k(k) = 0}
\DoxyCodeLine{276         \textcolor{keywordflow}{do} j=jsv-\/stencil,jev+stencil ; \textcolor{keywordflow}{if} (domore\_u(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{277         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{if} (domore\_v(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{278 }
\DoxyCodeLine{279 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{280 }
\DoxyCodeLine{281     \textcolor{keywordflow}{else}}
\DoxyCodeLine{282 }
\DoxyCodeLine{283       \textcolor{comment}{!\$OMP do ordered}}
\DoxyCodeLine{284       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{285         \textcolor{comment}{! First, advect meridionally.}}
\DoxyCodeLine{286         \textcolor{keyword}{call }advect\_y(tr, hprev, vhr, vh\_neglect, obc, domore\_v, ntr, idt, \&}
\DoxyCodeLine{287                       isv-\/stencil, iev+stencil, jsv, jev, k, g, gv, us, cs\%usePPM, cs\%useHuynh)}
\DoxyCodeLine{288 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{289 }
\DoxyCodeLine{290       \textcolor{comment}{!\$OMP do ordered}}
\DoxyCodeLine{291       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{292         \textcolor{comment}{! Next, advect zonally.}}
\DoxyCodeLine{293         \textcolor{keyword}{call }advect\_x(tr, hprev, uhr, uh\_neglect, obc, domore\_u, ntr, idt, \&}
\DoxyCodeLine{294                       isv, iev, jsv, jev, k, g, gv, us, cs\%usePPM, cs\%useHuynh)}
\DoxyCodeLine{295 }
\DoxyCodeLine{296         \textcolor{comment}{! Update domore\_k(k) for the next iteration}}
\DoxyCodeLine{297         domore\_k(k) = 0}
\DoxyCodeLine{298         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{if} (domore\_u(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{299         \textcolor{keywordflow}{do} j=jsv-\/1,jev ; \textcolor{keywordflow}{if} (domore\_v(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{300 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{301 }
\DoxyCodeLine{302 \textcolor{keywordflow}{    endif} \textcolor{comment}{! x\_first}}
\DoxyCodeLine{303 }
\DoxyCodeLine{304     \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{305 }
\DoxyCodeLine{306     \textcolor{comment}{! If the advection just isn't finishing after max\_iter, move on.}}
\DoxyCodeLine{307     \textcolor{keywordflow}{if} (itt >= max\_iter) \textcolor{keywordflow}{then}}
\DoxyCodeLine{308       \textcolor{keywordflow}{exit}}
\DoxyCodeLine{309 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{310 }
\DoxyCodeLine{311     \textcolor{comment}{! Exit if there are no layers that need more iterations.}}
\DoxyCodeLine{312     \textcolor{keywordflow}{if} (isv > is-\/stencil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{313       do\_any = 0}
\DoxyCodeLine{314       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_sync)}
\DoxyCodeLine{315       \textcolor{keyword}{call }sum\_across\_pes(domore\_k(:), nz)}
\DoxyCodeLine{316       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_sync)}
\DoxyCodeLine{317       \textcolor{keywordflow}{do} k=1,nz ; do\_any = do\_any + domore\_k(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{318       \textcolor{keywordflow}{if} (do\_any == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{319         \textcolor{keywordflow}{exit}}
\DoxyCodeLine{320 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{321 }
\DoxyCodeLine{322 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{323 }
\DoxyCodeLine{324 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! Iterations loop}}
\DoxyCodeLine{325 }
\DoxyCodeLine{326   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhr\_out)) uhr\_out(:,:,:) = uhr(:,:,:)}
\DoxyCodeLine{327   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhr\_out)) vhr\_out(:,:,:) = vhr(:,:,:)}
\DoxyCodeLine{328   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_out)) h\_out(:,:,:) = hprev(:,:,:)}
\DoxyCodeLine{329 }
\DoxyCodeLine{330   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_advect)}
\DoxyCodeLine{331 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_a07f6e664b3346db7f9ddbcd4b4d6c8f4}\label{namespacemom__tracer__advect_a07f6e664b3346db7f9ddbcd4b4d6c8f4}} 
\index{mom\_tracer\_advect@{mom\_tracer\_advect}!advect\_x@{advect\_x}}
\index{advect\_x@{advect\_x}!mom\_tracer\_advect@{mom\_tracer\_advect}}
\doxysubsubsection{\texorpdfstring{advect\_x()}{advect\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tracer\+\_\+advect\+::advect\+\_\+x (\begin{DoxyParamCaption}\item[{type(tracer\+\_\+type), dimension(ntr), intent(inout)}]{Tr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{hprev,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{uhr,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{uh\+\_\+neglect,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{logical, dimension( g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{domore\+\_\+u,  }\item[{integer, intent(in)}]{ntr,  }\item[{real, intent(in)}]{Idt,  }\item[{integer, intent(in)}]{is,  }\item[{integer, intent(in)}]{ie,  }\item[{integer, intent(in)}]{js,  }\item[{integer, intent(in)}]{je,  }\item[{integer, intent(in)}]{k,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{logical, intent(in)}]{use\+P\+PM,  }\item[{logical, intent(in)}]{use\+Huynh }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does 1-\/d flux-\/form advection in the zonal direction using a monotonic piecewise linear scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em tr} & The array of registered tracers to work on \\
\hline
\mbox{\texttt{ in,out}}  & {\em hprev} & cell volume at the end of previous tracer change \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em uhr} & accumulated volume/mass flux through the zonal face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em uh\+\_\+neglect} & A tiny zonal mass flux that can be neglected \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
 & {\em obc} & specifies whether, where, and what O\+B\+Cs are used \\
\hline
\mbox{\texttt{ in,out}}  & {\em domore\+\_\+u} & If true, there is more advection to be done in this u-\/row \\
\hline
\mbox{\texttt{ in}}  & {\em idt} & The inverse of dt \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ntr} & The number of tracers \\
\hline
\mbox{\texttt{ in}}  & {\em is} & The starting tracer i-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em ie} & The ending tracer i-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em js} & The starting tracer j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em je} & The ending tracer j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em k} & The k-\/level to work on \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em useppm} & If true, use P\+PM instead of P\+LM \\
\hline
\mbox{\texttt{ in}}  & {\em usehuynh} & If true, use the Huynh scheme for P\+PM interface values \\
\hline
\end{DoxyParams}


Definition at line 339 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{339   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{340   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{341   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{dimension(ntr)},         \textcolor{keywordtype}{intent(inout)} :: Tr\textcolor{comment}{   !< The array of registered tracers to work on}}
\DoxyCodeLine{342 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: hprev\textcolor{comment}{ !< cell volume at the end of previous}}
\DoxyCodeLine{343 \textcolor{comment}{                                                                  !! tracer change [H L2 ~> m3 or kg]}}
\DoxyCodeLine{344 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhr\textcolor{comment}{ !< accumulated volume/mass flux through}}
\DoxyCodeLine{345 \textcolor{comment}{                                                                  !! the zonal face [H L2 ~> m3 or kg]}}
\DoxyCodeLine{346 \textcolor{keywordtype}{   real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},        \textcolor{keywordtype}{intent(in)}    :: uh\_neglect\textcolor{comment}{ !< A tiny zonal mass flux that can}}
\DoxyCodeLine{347 \textcolor{comment}{                                                                  !! be neglected [H L2 ~> m3 or kg]}}
\DoxyCodeLine{348   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                      \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< specifies whether, where, and what OBCs are used}}
\DoxyCodeLine{349   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))},       \textcolor{keywordtype}{intent(inout)} :: domore\_u\textcolor{comment}{ !< If true, there is more advection to be}}
\DoxyCodeLine{350 \textcolor{comment}{                                                                  !! done in this u-\/row}}
\DoxyCodeLine{351 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: Idt\textcolor{comment}{ !< The inverse of dt [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{352   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ntr\textcolor{comment}{ !< The number of tracers}}
\DoxyCodeLine{353   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: is\textcolor{comment}{  !< The starting tracer i-\/index to work on}}
\DoxyCodeLine{354   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ie\textcolor{comment}{  !< The ending tracer i-\/index to work on}}
\DoxyCodeLine{355   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: js\textcolor{comment}{  !< The starting tracer j-\/index to work on}}
\DoxyCodeLine{356   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: je\textcolor{comment}{  !< The ending tracer j-\/index to work on}}
\DoxyCodeLine{357   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: k\textcolor{comment}{   !< The k-\/level to work on}}
\DoxyCodeLine{358   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{359   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: usePPM\textcolor{comment}{ !< If true, use PPM instead of PLM}}
\DoxyCodeLine{360   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: useHuynh\textcolor{comment}{ !< If true, use the Huynh scheme}}
\DoxyCodeLine{361 \textcolor{comment}{                                                                     !! for PPM interface values}}
\DoxyCodeLine{362 }
\DoxyCodeLine{363 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr)} :: \&}
\DoxyCodeLine{364     slope\_x             \textcolor{comment}{! The concentration slope per grid point [conc].}}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),ntr)} :: \&}
\DoxyCodeLine{366     flux\_x              \textcolor{comment}{! The tracer flux across a boundary [H L2 conc ~> m3 conc or kg conc].}}
\DoxyCodeLine{367 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr)} :: \&}
\DoxyCodeLine{368     T\_tmp               \textcolor{comment}{! The copy of the tracer concentration at constant i,k [H m2 conc ~> m3 conc or kg conc].}}
\DoxyCodeLine{369 }
\DoxyCodeLine{370 \textcolor{keywordtype}{  real} :: maxslope      \textcolor{comment}{! The maximum concentration slope per grid point}}
\DoxyCodeLine{371                         \textcolor{comment}{! consistent with monotonicity [conc].}}
\DoxyCodeLine{372 \textcolor{keywordtype}{  real} :: hup, hlos     \textcolor{comment}{! hup is the upwind volume, hlos is the}}
\DoxyCodeLine{373                         \textcolor{comment}{! part of that volume that might be lost}}
\DoxyCodeLine{374                         \textcolor{comment}{! due to advection out the other side of}}
\DoxyCodeLine{375                         \textcolor{comment}{! the grid box, both in [H L2 ~> m3 or kg].}}
\DoxyCodeLine{376 \textcolor{keywordtype}{  real} :: uhh(SZIB\_(G)) \textcolor{comment}{! The zonal flux that occurs during the}}
\DoxyCodeLine{377                         \textcolor{comment}{! current iteration [H L2 ~> m3 or kg].}}
\DoxyCodeLine{378 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{379     hlst, \&             \textcolor{comment}{! Work variable [H L2 ~> m3 or kg].}}
\DoxyCodeLine{380     Ihnew, \&            \textcolor{comment}{! Work variable [H-\/1 L-\/2 ~> m-\/3 or kg-\/1].}}
\DoxyCodeLine{381     CFL                 \textcolor{comment}{! The absolute value of the advective upwind-\/cell CFL number [nondim].}}
\DoxyCodeLine{382 \textcolor{keywordtype}{  real} :: min\_h         \textcolor{comment}{! The minimum thickness that can be realized during}}
\DoxyCodeLine{383                         \textcolor{comment}{! any of the passes [H ~> m or kg m-\/2].}}
\DoxyCodeLine{384 \textcolor{keywordtype}{  real} :: tiny\_h        \textcolor{comment}{! The smallest numerically invertable thickness [H ~> m or kg m-\/2].}}
\DoxyCodeLine{385 \textcolor{keywordtype}{  real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{386                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-\/2].}}
\DoxyCodeLine{387   \textcolor{keywordtype}{logical} :: do\_i(SZIB\_(G),SZJ\_(G))     \textcolor{comment}{! If true, work on given points.}}
\DoxyCodeLine{388   \textcolor{keywordtype}{logical} :: do\_any\_i}
\DoxyCodeLine{389   \textcolor{keywordtype}{integer} :: i, j, m, n, i\_up, stencil}
\DoxyCodeLine{390 \textcolor{keywordtype}{  real} :: aR, aL, dMx, dMn, Tp, Tc, Tm, dA, mA, a6}
\DoxyCodeLine{391 \textcolor{keywordtype}{  real} :: fac1,u\_L\_in,u\_L\_out  \textcolor{comment}{! terms used for time-\/stepping OBC reservoirs}}
\DoxyCodeLine{392   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment=>null()}
\DoxyCodeLine{393   \textcolor{keywordtype}{logical} :: usePLMslope}
\DoxyCodeLine{394   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))} :: domore\_u\_initial}
\DoxyCodeLine{395 }
\DoxyCodeLine{396   \textcolor{comment}{! keep a local copy of the initial values of domore\_u, which is to be used when computing ad2d\_x}}
\DoxyCodeLine{397   \textcolor{comment}{! diagnostic at the end of this subroutine.}}
\DoxyCodeLine{398   domore\_u\_initial = domore\_u}
\DoxyCodeLine{399 }
\DoxyCodeLine{400   useplmslope = .not. (useppm .and. usehuynh)}
\DoxyCodeLine{401   \textcolor{comment}{! stencil for calculating slope values}}
\DoxyCodeLine{402   stencil = 1}
\DoxyCodeLine{403   \textcolor{keywordflow}{if} (useppm .and. .not. usehuynh) stencil = 2}
\DoxyCodeLine{404 }
\DoxyCodeLine{405   min\_h = 0.1*gv\%Angstrom\_H}
\DoxyCodeLine{406   tiny\_h = tiny(min\_h)}
\DoxyCodeLine{407   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{408 }
\DoxyCodeLine{409   \textcolor{keywordflow}{do} i=is-\/1,ie ; cfl(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{410 }
\DoxyCodeLine{411   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (domore\_u(j,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{412     domore\_u(j,k) = .false.}
\DoxyCodeLine{413 }
\DoxyCodeLine{414     \textcolor{comment}{! Calculate the i-\/direction profiles (slopes) of each tracer that is being advected.}}
\DoxyCodeLine{415     \textcolor{keywordflow}{if} (useplmslope) \textcolor{keywordflow}{then}}
\DoxyCodeLine{416       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is-\/stencil,ie+stencil}
\DoxyCodeLine{417        \textcolor{comment}{!if (ABS(Tr(m)\%t(i+1,j,k)-\/Tr(m)\%t(i,j,k)) < \&}}
\DoxyCodeLine{418        \textcolor{comment}{!    ABS(Tr(m)\%t(i,j,k)-\/Tr(m)\%t(i-\/1,j,k))) then}}
\DoxyCodeLine{419        \textcolor{comment}{!  maxslope = 4.0*(Tr(m)\%t(i+1,j,k)-\/Tr(m)\%t(i,j,k))}}
\DoxyCodeLine{420        \textcolor{comment}{!else}}
\DoxyCodeLine{421        \textcolor{comment}{!  maxslope = 4.0*(Tr(m)\%t(i,j,k)-\/Tr(m)\%t(i-\/1,j,k))}}
\DoxyCodeLine{422        \textcolor{comment}{!endif}}
\DoxyCodeLine{423        \textcolor{comment}{!if ((Tr(m)\%t(i+1,j,k)-\/Tr(m)\%t(i,j,k)) * (Tr(m)\%t(i,j,k)-\/Tr(m)\%t(i-\/1,j,k)) < 0.0) then}}
\DoxyCodeLine{424        \textcolor{comment}{!  slope\_x(i,m) = 0.0}}
\DoxyCodeLine{425        \textcolor{comment}{!elseif (ABS(Tr(m)\%t(i+1,j,k)-\/Tr(m)\%t(i-\/1,j,k))<ABS(maxslope)) then}}
\DoxyCodeLine{426        \textcolor{comment}{!  slope\_x(i,m) = G\%mask2dCu(I,j)*G\%mask2dCu(I-\/1,j) * \&}}
\DoxyCodeLine{427        \textcolor{comment}{!                 0.5*(Tr(m)\%t(i+1,j,k)-\/Tr(m)\%t(i-\/1,j,k))}}
\DoxyCodeLine{428        \textcolor{comment}{!else}}
\DoxyCodeLine{429        \textcolor{comment}{!  slope\_x(i,m) = G\%mask2dCu(I,j)*G\%mask2dCu(I-\/1,j) * 0.5*maxslope}}
\DoxyCodeLine{430        \textcolor{comment}{!endif}}
\DoxyCodeLine{431         tp = tr(m)\%t(i+1,j,k) ; tc = tr(m)\%t(i,j,k) ; tm = tr(m)\%t(i-\/1,j,k)}
\DoxyCodeLine{432         dmx = max( tp, tc, tm ) -\/ tc}
\DoxyCodeLine{433         dmn= tc -\/ min( tp, tc, tm )}
\DoxyCodeLine{434         slope\_x(i,m) = g\%mask2dCu(i,j)*g\%mask2dCu(i-\/1,j) * \&}
\DoxyCodeLine{435             sign( min(0.5*abs(tp-\/tm), 2.0*dmx, 2.0*dmn), tp-\/tm )}
\DoxyCodeLine{436 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{437 \textcolor{keywordflow}{    endif} \textcolor{comment}{! usePLMslope}}
\DoxyCodeLine{438 }
\DoxyCodeLine{439     \textcolor{comment}{! make a copy of the tracers in case values need to be overridden for OBCs}}
\DoxyCodeLine{440     \textcolor{keywordflow}{do} m = 1,ntr}
\DoxyCodeLine{441       \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{442         t\_tmp(i,m) = tr(m)\%t(i,j,k)}
\DoxyCodeLine{443 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{444 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{445     \textcolor{comment}{! loop through open boundaries and recalculate flux terms}}
\DoxyCodeLine{446     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc\%OBC\_pe) \textcolor{keywordflow}{then}}
\DoxyCodeLine{447        \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments}
\DoxyCodeLine{448          segment=>obc\%segment(n)}
\DoxyCodeLine{449          \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment\%tr\_Reg)) cycle}
\DoxyCodeLine{450          \textcolor{keywordflow}{if} (segment\%is\_E\_or\_W) \textcolor{keywordflow}{then}}
\DoxyCodeLine{451            \textcolor{keywordflow}{if} (j>=segment\%HI\%jsd .and. j<=segment\%HI\%jed) \textcolor{keywordflow}{then}}
\DoxyCodeLine{452               i = segment\%HI\%IsdB}
\DoxyCodeLine{453               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! replace tracers with OBC values}}
\DoxyCodeLine{454                 \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment\%tr\_Reg\%Tr(m)\%tres)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{455                    \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{456                       t\_tmp(i,m) = segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{457                    \textcolor{keywordflow}{else}}
\DoxyCodeLine{458                       t\_tmp(i+1,m) = segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{459 \textcolor{keywordflow}{                   endif}}
\DoxyCodeLine{460                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{461                    \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_w) \textcolor{keywordflow}{then}}
\DoxyCodeLine{462                       t\_tmp(i,m) = segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc}
\DoxyCodeLine{463                    \textcolor{keywordflow}{else}}
\DoxyCodeLine{464                       t\_tmp(i+1,m) = segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc}
\DoxyCodeLine{465 \textcolor{keywordflow}{                   endif}}
\DoxyCodeLine{466 \textcolor{keywordflow}{                endif}}
\DoxyCodeLine{467 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{468               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! Apply update tracer values for slope calculation}}
\DoxyCodeLine{469                 \textcolor{keywordflow}{do} i=segment\%HI\%IsdB-\/1,segment\%HI\%IsdB+1}
\DoxyCodeLine{470                   tp = t\_tmp(i+1,m) ; tc = t\_tmp(i,m) ; tm = t\_tmp(i-\/1,m)}
\DoxyCodeLine{471                   dmx = max( tp, tc, tm ) -\/ tc}
\DoxyCodeLine{472                   dmn= tc -\/ min( tp, tc, tm )}
\DoxyCodeLine{473                   slope\_x(i,m) = g\%mask2dCu(i,j)*g\%mask2dCu(i-\/1,j) * \&}
\DoxyCodeLine{474                        sign( min(0.5*abs(tp-\/tm), 2.0*dmx, 2.0*dmn), tp-\/tm )}
\DoxyCodeLine{475 \textcolor{keywordflow}{                enddo}}
\DoxyCodeLine{476 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{477 }
\DoxyCodeLine{478 \textcolor{keywordflow}{           endif}}
\DoxyCodeLine{479 \textcolor{keywordflow}{         endif}}
\DoxyCodeLine{480 \textcolor{keywordflow}{       enddo}}
\DoxyCodeLine{481     endif;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{482 }
\DoxyCodeLine{483 }
\DoxyCodeLine{484     \textcolor{comment}{! Calculate the i-\/direction fluxes of each tracer, using as much}}
\DoxyCodeLine{485     \textcolor{comment}{! the minimum of the remaining mass flux (uhr) and the half the mass}}
\DoxyCodeLine{486     \textcolor{comment}{! in the cell plus whatever part of its half of the mass flux that}}
\DoxyCodeLine{487     \textcolor{comment}{! the flux through the other side does not require.}}
\DoxyCodeLine{488     \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{489       \textcolor{keywordflow}{if} ((uhr(i,j,k) == 0.0) .or. \&}
\DoxyCodeLine{490           ((uhr(i,j,k) < 0.0) .and. (hprev(i+1,j,k) <= tiny\_h)) .or. \&}
\DoxyCodeLine{491           ((uhr(i,j,k) > 0.0) .and. (hprev(i,j,k) <= tiny\_h)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{492         uhh(i) = 0.0}
\DoxyCodeLine{493         cfl(i) = 0.0}
\DoxyCodeLine{494       \textcolor{keywordflow}{elseif} (uhr(i,j,k) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{495         hup = hprev(i+1,j,k) -\/ g\%areaT(i+1,j)*min\_h}
\DoxyCodeLine{496         hlos = max(0.0, uhr(i+1,j,k))}
\DoxyCodeLine{497         \textcolor{keywordflow}{if} ((((hup -\/ hlos) + uhr(i,j,k)) < 0.0) .and. \&}
\DoxyCodeLine{498             ((0.5*hup + uhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{499           uhh(i) = min(-\/0.5*hup, -\/hup+hlos, 0.0)}
\DoxyCodeLine{500           domore\_u(j,k) = .true.}
\DoxyCodeLine{501         \textcolor{keywordflow}{else}}
\DoxyCodeLine{502           uhh(i) = uhr(i,j,k)}
\DoxyCodeLine{503 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{504         cfl(i) = -\/ uhh(i) / (hprev(i+1,j,k))  \textcolor{comment}{! CFL is positive}}
\DoxyCodeLine{505       \textcolor{keywordflow}{else}}
\DoxyCodeLine{506         hup = hprev(i,j,k) -\/ g\%areaT(i,j)*min\_h}
\DoxyCodeLine{507         hlos = max(0.0, -\/uhr(i-\/1,j,k))}
\DoxyCodeLine{508         \textcolor{keywordflow}{if} ((((hup -\/ hlos) -\/ uhr(i,j,k)) < 0.0) .and. \&}
\DoxyCodeLine{509             ((0.5*hup -\/ uhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{510           uhh(i) = max(0.5*hup, hup-\/hlos, 0.0)}
\DoxyCodeLine{511           domore\_u(j,k) = .true.}
\DoxyCodeLine{512         \textcolor{keywordflow}{else}}
\DoxyCodeLine{513           uhh(i) = uhr(i,j,k)}
\DoxyCodeLine{514 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{515         cfl(i) = uhh(i) / (hprev(i,j,k))  \textcolor{comment}{! CFL is positive}}
\DoxyCodeLine{516 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{517 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{518 }
\DoxyCodeLine{519 }
\DoxyCodeLine{520     \textcolor{keywordflow}{if} (useppm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{521       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{522         \textcolor{comment}{! centre cell depending on upstream direction}}
\DoxyCodeLine{523         \textcolor{keywordflow}{if} (uhh(i) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{524           i\_up = i}
\DoxyCodeLine{525         \textcolor{keywordflow}{else}}
\DoxyCodeLine{526           i\_up = i+1}
\DoxyCodeLine{527 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{528 }
\DoxyCodeLine{529         \textcolor{comment}{! Implementation of PPM-\/H3}}
\DoxyCodeLine{530         tp = t\_tmp(i\_up+1,m) ; tc = t\_tmp(i\_up,m) ; tm = t\_tmp(i\_up-\/1,m)}
\DoxyCodeLine{531 }
\DoxyCodeLine{532         \textcolor{keywordflow}{if} (usehuynh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{533           al = ( 5.*tc + ( 2.*tm -\/ tp ) )/6. \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{534           al = max( min(tc,tm), al) ; al = min( max(tc,tm), al) \textcolor{comment}{! Bound}}
\DoxyCodeLine{535           ar = ( 5.*tc + ( 2.*tp -\/ tm ) )/6. \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{536           ar = max( min(tc,tp), ar) ; ar = min( max(tc,tp), ar) \textcolor{comment}{! Bound}}
\DoxyCodeLine{537         \textcolor{keywordflow}{else}}
\DoxyCodeLine{538           al = 0.5 * ((tm + tc) + (slope\_x(i\_up-\/1,m) -\/ slope\_x(i\_up,m)) / 3.)}
\DoxyCodeLine{539           ar = 0.5 * ((tc + tp) + (slope\_x(i\_up,m) -\/ slope\_x(i\_up+1,m)) / 3.)}
\DoxyCodeLine{540 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{541 }
\DoxyCodeLine{542         da = ar -\/ al ; ma = 0.5*( ar + al )}
\DoxyCodeLine{543         \textcolor{keywordflow}{if} (g\%mask2dCu(i\_up,j)*g\%mask2dCu(i\_up-\/1,j)*(tp-\/tc)*(tc-\/tm) <= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{544           al = tc ; ar = tc \textcolor{comment}{! PCM for local extremum and bounadry cells}}
\DoxyCodeLine{545         \textcolor{keywordflow}{elseif} ( da*(tc-\/ma) > (da*da)/6. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{546           al = 3.*tc -\/ 2.*ar}
\DoxyCodeLine{547         \textcolor{keywordflow}{elseif} ( da*(tc-\/ma) < -\/ (da*da)/6. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{548           ar = 3.*tc -\/ 2.*al}
\DoxyCodeLine{549 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{550 }
\DoxyCodeLine{551         a6 = 6.*tc -\/ 3. * (ar + al) \textcolor{comment}{! Curvature}}
\DoxyCodeLine{552 }
\DoxyCodeLine{553         \textcolor{keywordflow}{if} (uhh(i) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{554           flux\_x(i,j,m) = uhh(i)*( ar -\/ 0.5 * cfl(i) * ( \&}
\DoxyCodeLine{555                ( ar -\/ al ) -\/ a6 * ( 1. -\/ 2./3. * cfl(i) ) ) )}
\DoxyCodeLine{556         \textcolor{keywordflow}{else}}
\DoxyCodeLine{557           flux\_x(i,j,m) = uhh(i)*( al + 0.5 * cfl(i) * ( \&}
\DoxyCodeLine{558                ( ar -\/ al ) + a6 * ( 1. -\/ 2./3. * cfl(i) ) ) )}
\DoxyCodeLine{559 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{560 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{561     \textcolor{keywordflow}{else} \textcolor{comment}{! PLM}}
\DoxyCodeLine{562       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{563         \textcolor{keywordflow}{if} (uhh(i) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{564           \textcolor{comment}{! Indirect implementation of PLM}}
\DoxyCodeLine{565          \textcolor{comment}{!aL = Tr(m)\%t(i,j,k) -\/ 0.5 * slope\_x(i,m)}}
\DoxyCodeLine{566          \textcolor{comment}{!aR = Tr(m)\%t(i,j,k) + 0.5 * slope\_x(i,m)}}
\DoxyCodeLine{567          \textcolor{comment}{!flux\_x(I,j,m) = uhh(I)*( aR -\/ 0.5 * (aR-\/aL) * CFL(I) )}}
\DoxyCodeLine{568           \textcolor{comment}{! Alternative implementation of PLM}}
\DoxyCodeLine{569           tc = t\_tmp(i,m)}
\DoxyCodeLine{570           flux\_x(i,j,m) = uhh(i)*( tc + 0.5 * slope\_x(i,m) * ( 1. -\/ cfl(i) ) )}
\DoxyCodeLine{571         \textcolor{keywordflow}{else}}
\DoxyCodeLine{572           \textcolor{comment}{! Indirect implementation of PLM}}
\DoxyCodeLine{573          \textcolor{comment}{!aL = Tr(m)\%t(i+1,j,k) -\/ 0.5 * slope\_x(i+1,m)}}
\DoxyCodeLine{574          \textcolor{comment}{!aR = Tr(m)\%t(i+1,j,k) + 0.5 * slope\_x(i+1,m)}}
\DoxyCodeLine{575          \textcolor{comment}{!flux\_x(I,j,m) = uhh(I)*( aL + 0.5 * (aR-\/aL) * CFL(I) )}}
\DoxyCodeLine{576           \textcolor{comment}{! Alternative implementation of PLM}}
\DoxyCodeLine{577           tc = t\_tmp(i+1,m)}
\DoxyCodeLine{578           flux\_x(i,j,m) = uhh(i)*( tc -\/ 0.5 * slope\_x(i+1,m) * ( 1. -\/ cfl(i) ) )}
\DoxyCodeLine{579 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{580 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{581 \textcolor{keywordflow}{    endif} \textcolor{comment}{! usePPM}}
\DoxyCodeLine{582 }
\DoxyCodeLine{583     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc\%OBC\_pe) \textcolor{keywordflow}{then}}
\DoxyCodeLine{584       \textcolor{keywordflow}{if} (obc\%specified\_u\_BCs\_exist\_globally .or. obc\%open\_u\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{585         \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments}
\DoxyCodeLine{586           segment=>obc\%segment(n)}
\DoxyCodeLine{587           \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment\%tr\_Reg)) cycle}
\DoxyCodeLine{588           \textcolor{keywordflow}{if} (segment\%is\_E\_or\_W) \textcolor{keywordflow}{then}}
\DoxyCodeLine{589             \textcolor{keywordflow}{if} (j>=segment\%HI\%jsd .and. j<=segment\%HI\%jed) \textcolor{keywordflow}{then}}
\DoxyCodeLine{590               i = segment\%HI\%IsdB}
\DoxyCodeLine{591               \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}}
\DoxyCodeLine{592               \textcolor{comment}{! Now changing to simply fixed inflows.}}
\DoxyCodeLine{593               \textcolor{keywordflow}{if} ((uhr(i,j,k) > 0.0) .and. (segment\%direction == obc\_direction\_w) .or. \&}
\DoxyCodeLine{594                  (uhr(i,j,k) < 0.0) .and. (segment\%direction == obc\_direction\_e)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{595                 uhh(i) = uhr(i,j,k)}
\DoxyCodeLine{596               \textcolor{comment}{! should the reservoir evolve for this case Kate ?? -\/ Nope}}
\DoxyCodeLine{597                 \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{598                   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment\%tr\_Reg\%Tr(m)\%tres)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{599                     flux\_x(i,j,m) = uhh(i)*segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{600                   \textcolor{keywordflow}{else} ; flux\_x(i,j,m) = uhh(i)*segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{601 \textcolor{keywordflow}{                enddo}}
\DoxyCodeLine{602 \textcolor{keywordflow}{              endif}}
\DoxyCodeLine{603 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{604 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{605 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{606 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{607 }
\DoxyCodeLine{608       \textcolor{keywordflow}{if} (obc\%open\_u\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{609         \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments}
\DoxyCodeLine{610           segment=>obc\%segment(n)}
\DoxyCodeLine{611           i = segment\%HI\%IsdB}
\DoxyCodeLine{612           \textcolor{keywordflow}{if} (segment\%is\_E\_or\_W .and. (j >= segment\%HI\%jsd .and. j<= segment\%HI\%jed)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{613             \textcolor{keywordflow}{if} (segment\%specified) cycle}
\DoxyCodeLine{614             \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment\%tr\_Reg)) cycle}
\DoxyCodeLine{615 }
\DoxyCodeLine{616             \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}}
\DoxyCodeLine{617             \textcolor{keywordflow}{if} ((uhr(i,j,k) > 0.0) .and. (g\%mask2dT(i,j) < 0.5) .or. \&}
\DoxyCodeLine{618                (uhr(i,j,k) < 0.0) .and. (g\%mask2dT(i+1,j) < 0.5)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{619               uhh(i) = uhr(i,j,k)}
\DoxyCodeLine{620               \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{621                 \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment\%tr\_Reg\%Tr(m)\%tres)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{622                   flux\_x(i,j,m) = uhh(i)*segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{623                 else; flux\_x(i,j,m) = uhh(i)*segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{624 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{625 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{626 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{627 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{628 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{629 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{630 }
\DoxyCodeLine{631     \textcolor{comment}{! Calculate new tracer concentration in each cell after accounting}}
\DoxyCodeLine{632     \textcolor{comment}{! for the i-\/direction fluxes.}}
\DoxyCodeLine{633     \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{634       uhr(i,j,k) = uhr(i,j,k) -\/ uhh(i)}
\DoxyCodeLine{635       \textcolor{keywordflow}{if} (abs(uhr(i,j,k)) < uh\_neglect(i,j)) uhr(i,j,k) = 0.0}
\DoxyCodeLine{636 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{637     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{638       \textcolor{keywordflow}{if} ((uhh(i) /= 0.0) .or. (uhh(i-\/1) /= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{639         do\_i(i,j) = .true.}
\DoxyCodeLine{640         hlst(i) = hprev(i,j,k)}
\DoxyCodeLine{641         hprev(i,j,k) = hprev(i,j,k) -\/ (uhh(i) -\/ uhh(i-\/1))}
\DoxyCodeLine{642         \textcolor{keywordflow}{if} (hprev(i,j,k) <= 0.0) \textcolor{keywordflow}{then} ; do\_i(i,j) = .false.}
\DoxyCodeLine{643         \textcolor{keywordflow}{elseif} (hprev(i,j,k) < h\_neglect*g\%areaT(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{644           hlst(i) = hlst(i) + (h\_neglect*g\%areaT(i,j) -\/ hprev(i,j,k))}
\DoxyCodeLine{645           ihnew(i) = 1.0 / (h\_neglect*g\%areaT(i,j))}
\DoxyCodeLine{646         \textcolor{keywordflow}{else} ;  ihnew(i) = 1.0 / hprev(i,j,k) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{647       \textcolor{keywordflow}{else}}
\DoxyCodeLine{648         do\_i(i,j) = .false.}
\DoxyCodeLine{649 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{650 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{651 }
\DoxyCodeLine{652     \textcolor{comment}{! update tracer concentration from i-\/flux and save some diagnostics}}
\DoxyCodeLine{653     \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{654 }
\DoxyCodeLine{655       \textcolor{comment}{! update tracer}}
\DoxyCodeLine{656       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{657         \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{658           \textcolor{keywordflow}{if} (ihnew(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{659             tr(m)\%t(i,j,k) = (tr(m)\%t(i,j,k) * hlst(i) -\/ \&}
\DoxyCodeLine{660                               (flux\_x(i,j,m) -\/ flux\_x(i-\/1,j,m))) * ihnew(i)}
\DoxyCodeLine{661 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{662 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{663 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{664 }
\DoxyCodeLine{665       \textcolor{comment}{! diagnostics}}
\DoxyCodeLine{666       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad\_x)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{667         tr(m)\%ad\_x(i,j,k) = tr(m)\%ad\_x(i,j,k) + flux\_x(i,j,m)*idt}
\DoxyCodeLine{668 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{669 }
\DoxyCodeLine{670       \textcolor{comment}{! diagnose convergence of flux\_x (do not use the Ihnew(i) part of the logic).}}
\DoxyCodeLine{671       \textcolor{comment}{! division by areaT to get into W/m2 for heat and kg/(s*m2) for salt.}}
\DoxyCodeLine{672       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%advection\_xy)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{673         \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{674           tr(m)\%advection\_xy(i,j,k) = tr(m)\%advection\_xy(i,j,k) -\/ (flux\_x(i,j,m) -\/ flux\_x(i-\/1,j,m)) * \&}
\DoxyCodeLine{675                                           idt * g\%IareaT(i,j)}
\DoxyCodeLine{676 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{677 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{678 }
\DoxyCodeLine{679 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{680 }
\DoxyCodeLine{681 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{682 }
\DoxyCodeLine{683 }
\DoxyCodeLine{684 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! End of j-\/loop.}}
\DoxyCodeLine{685 }
\DoxyCodeLine{686   \textcolor{comment}{! compute ad2d\_x diagnostic outside above j-\/loop so as to make the summation ordered when OMP is active.}}
\DoxyCodeLine{687 }
\DoxyCodeLine{688   \textcolor{comment}{!\$OMP ordered}}
\DoxyCodeLine{689   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (domore\_u\_initial(j,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{690     \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{691       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad2d\_x)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{692         tr(m)\%ad2d\_x(i,j) = tr(m)\%ad2d\_x(i,j) + flux\_x(i,j,m)*idt}
\DoxyCodeLine{693 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{694 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{695 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-\/loop.}}
\DoxyCodeLine{696   \textcolor{comment}{!\$OMP end ordered}}
\DoxyCodeLine{697 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_a20a82831fad6aa07cb946aeadbbfdda9}\label{namespacemom__tracer__advect_a20a82831fad6aa07cb946aeadbbfdda9}} 
\index{mom\_tracer\_advect@{mom\_tracer\_advect}!advect\_y@{advect\_y}}
\index{advect\_y@{advect\_y}!mom\_tracer\_advect@{mom\_tracer\_advect}}
\doxysubsubsection{\texorpdfstring{advect\_y()}{advect\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tracer\+\_\+advect\+::advect\+\_\+y (\begin{DoxyParamCaption}\item[{type(tracer\+\_\+type), dimension(ntr), intent(inout)}]{Tr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{hprev,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(inout)}]{vhr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(inout)}]{vh\+\_\+neglect,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{logical, dimension( g \%jsdb\+: g \%jedb, g \%ke), intent(inout)}]{domore\+\_\+v,  }\item[{integer, intent(in)}]{ntr,  }\item[{real, intent(in)}]{Idt,  }\item[{integer, intent(in)}]{is,  }\item[{integer, intent(in)}]{ie,  }\item[{integer, intent(in)}]{js,  }\item[{integer, intent(in)}]{je,  }\item[{integer, intent(in)}]{k,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{logical, intent(in)}]{use\+P\+PM,  }\item[{logical, intent(in)}]{use\+Huynh }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does 1-\/d flux-\/form advection using a monotonic piecewise linear scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em tr} & The array of registered tracers to work on \\
\hline
\mbox{\texttt{ in,out}}  & {\em hprev} & cell volume at the end of previous tracer change \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vhr} & accumulated volume/mass flux through the meridional face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em vh\+\_\+neglect} & A tiny meridional mass flux that can be neglected \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
 & {\em obc} & specifies whether, where, and what O\+B\+Cs are used \\
\hline
\mbox{\texttt{ in,out}}  & {\em domore\+\_\+v} & If true, there is more advection to be done in this v-\/row \\
\hline
\mbox{\texttt{ in}}  & {\em idt} & The inverse of dt \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ntr} & The number of tracers \\
\hline
\mbox{\texttt{ in}}  & {\em is} & The starting tracer i-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em ie} & The ending tracer i-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em js} & The starting tracer j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em je} & The ending tracer j-\/index to work on \\
\hline
\mbox{\texttt{ in}}  & {\em k} & The k-\/level to work on \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em useppm} & If true, use P\+PM instead of P\+LM \\
\hline
\mbox{\texttt{ in}}  & {\em usehuynh} & If true, use the Huynh scheme for P\+PM interface values \\
\hline
\end{DoxyParams}


Definition at line 704 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{704   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{705   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{706   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{dimension(ntr)},         \textcolor{keywordtype}{intent(inout)} :: Tr\textcolor{comment}{   !< The array of registered tracers to work on}}
\DoxyCodeLine{707 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: hprev\textcolor{comment}{ !< cell volume at the end of previous}}
\DoxyCodeLine{708 \textcolor{comment}{                                                                  !! tracer change [H L2 ~> m3 or kg]}}
\DoxyCodeLine{709 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhr\textcolor{comment}{ !< accumulated volume/mass flux through}}
\DoxyCodeLine{710 \textcolor{comment}{                                                                  !! the meridional face [H L2 ~> m3 or kg]}}
\DoxyCodeLine{711 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vh\_neglect\textcolor{comment}{ !< A tiny meridional mass flux that can}}
\DoxyCodeLine{712 \textcolor{comment}{                                                                  !! be neglected [H L2 ~> m3 or kg]}}
\DoxyCodeLine{713   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                      \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< specifies whether, where, and what OBCs are used}}
\DoxyCodeLine{714   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZJB\_(G),SZK\_(G))},      \textcolor{keywordtype}{intent(inout)} :: domore\_v\textcolor{comment}{ !< If true, there is more advection to be}}
\DoxyCodeLine{715 \textcolor{comment}{                                                                  !! done in this v-\/row}}
\DoxyCodeLine{716 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: Idt\textcolor{comment}{ !< The inverse of dt [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{717   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ntr\textcolor{comment}{ !< The number of tracers}}
\DoxyCodeLine{718   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: is\textcolor{comment}{  !< The starting tracer i-\/index to work on}}
\DoxyCodeLine{719   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ie\textcolor{comment}{  !< The ending tracer i-\/index to work on}}
\DoxyCodeLine{720   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: js\textcolor{comment}{  !< The starting tracer j-\/index to work on}}
\DoxyCodeLine{721   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: je\textcolor{comment}{  !< The ending tracer j-\/index to work on}}
\DoxyCodeLine{722   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: k\textcolor{comment}{   !< The k-\/level to work on}}
\DoxyCodeLine{723   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{724   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: usePPM\textcolor{comment}{ !< If true, use PPM instead of PLM}}
\DoxyCodeLine{725   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: useHuynh\textcolor{comment}{ !< If true, use the Huynh scheme}}
\DoxyCodeLine{726 \textcolor{comment}{                                                                     !! for PPM interface values}}
\DoxyCodeLine{727 }
\DoxyCodeLine{728 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr,SZJ\_(G))} :: \&}
\DoxyCodeLine{729     slope\_y                     \textcolor{comment}{! The concentration slope per grid point [conc].}}
\DoxyCodeLine{730 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr,SZJB\_(G))} :: \&}
\DoxyCodeLine{731        flux\_y                      \textcolor{comment}{! The tracer flux across a boundary [H m2 conc ~> m3 conc or kg conc].}}
\DoxyCodeLine{732 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr,SZJB\_(G))} :: \&}
\DoxyCodeLine{733     T\_tmp               \textcolor{comment}{! The copy of the tracer concentration at constant i,k [H m2 conc ~> m3 conc or kg conc].}}
\DoxyCodeLine{734 \textcolor{keywordtype}{  real} :: maxslope              \textcolor{comment}{! The maximum concentration slope per grid point}}
\DoxyCodeLine{735                                 \textcolor{comment}{! consistent with monotonicity [conc].}}
\DoxyCodeLine{736 \textcolor{keywordtype}{  real} :: vhh(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! The meridional flux that occurs during the}}
\DoxyCodeLine{737                                 \textcolor{comment}{! current iteration [H L2 ~> m3 or kg].}}
\DoxyCodeLine{738 \textcolor{keywordtype}{  real} :: hup, hlos             \textcolor{comment}{! hup is the upwind volume, hlos is the}}
\DoxyCodeLine{739                                 \textcolor{comment}{! part of that volume that might be lost}}
\DoxyCodeLine{740                                 \textcolor{comment}{! due to advection out the other side of}}
\DoxyCodeLine{741                                 \textcolor{comment}{! the grid box, both in  [H L2 ~> m3 or kg].}}
\DoxyCodeLine{742 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{743     hlst, \&             \textcolor{comment}{! Work variable [H L2 ~> m3 or kg].}}
\DoxyCodeLine{744     Ihnew, \&            \textcolor{comment}{! Work variable [H-\/1 L-\/2 ~> m-\/3 or kg-\/1].}}
\DoxyCodeLine{745     CFL                 \textcolor{comment}{! The absolute value of the advective upwind-\/cell CFL number [nondim].}}
\DoxyCodeLine{746 \textcolor{keywordtype}{  real} :: min\_h         \textcolor{comment}{! The minimum thickness that can be realized during}}
\DoxyCodeLine{747                         \textcolor{comment}{! any of the passes [H ~> m or kg m-\/2].}}
\DoxyCodeLine{748 \textcolor{keywordtype}{  real} :: tiny\_h        \textcolor{comment}{! The smallest numerically invertable thickness [H ~> m or kg m-\/2].}}
\DoxyCodeLine{749 \textcolor{keywordtype}{  real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{750                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-\/2].}}
\DoxyCodeLine{751   \textcolor{keywordtype}{logical} :: do\_j\_tr(SZJ\_(G))   \textcolor{comment}{! If true, calculate the tracer profiles.}}
\DoxyCodeLine{752   \textcolor{keywordtype}{logical} :: do\_i(SZIB\_(G), SZJ\_(G))     \textcolor{comment}{! If true, work on given points.}}
\DoxyCodeLine{753   \textcolor{keywordtype}{logical} :: do\_any\_i}
\DoxyCodeLine{754   \textcolor{keywordtype}{integer} :: i, j, j2, m, n, j\_up, stencil}
\DoxyCodeLine{755 \textcolor{keywordtype}{  real} :: aR, aL, dMx, dMn, Tp, Tc, Tm, dA, mA, a6}
\DoxyCodeLine{756 \textcolor{keywordtype}{  real} :: fac1,v\_L\_in,v\_L\_out  \textcolor{comment}{! terms used for time-\/stepping OBC reservoirs}}
\DoxyCodeLine{757   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment=>null()}
\DoxyCodeLine{758   \textcolor{keywordtype}{logical} :: usePLMslope}
\DoxyCodeLine{759 }
\DoxyCodeLine{760   useplmslope = .not. (useppm .and. usehuynh)}
\DoxyCodeLine{761   \textcolor{comment}{! stencil for calculating slope values}}
\DoxyCodeLine{762   stencil = 1}
\DoxyCodeLine{763   \textcolor{keywordflow}{if} (useppm .and. .not. usehuynh) stencil = 2}
\DoxyCodeLine{764 }
\DoxyCodeLine{765   min\_h = 0.1*gv\%Angstrom\_H}
\DoxyCodeLine{766   tiny\_h = tiny(min\_h)}
\DoxyCodeLine{767   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{768 }
\DoxyCodeLine{769   \textcolor{comment}{! We conditionally perform work on tracer points: calculating the PLM slope,}}
\DoxyCodeLine{770   \textcolor{comment}{! and updating tracer concentration within a cell}}
\DoxyCodeLine{771   \textcolor{comment}{! this depends on whether there is a flux which would affect this tracer point,}}
\DoxyCodeLine{772   \textcolor{comment}{! as indicated by domore\_v. In the case of PPM reconstruction, a flux requires}}
\DoxyCodeLine{773   \textcolor{comment}{! slope calculations at the two tracer points on either side (as indicated by}}
\DoxyCodeLine{774   \textcolor{comment}{! the stencil variable), so we account for this with the do\_j\_tr flag array}}
\DoxyCodeLine{775   \textcolor{comment}{!}}
\DoxyCodeLine{776   \textcolor{comment}{! Note: this does lead to unnecessary work in updating tracer concentrations,}}
\DoxyCodeLine{777   \textcolor{comment}{! since that doesn't need a wider stencil with the PPM advection scheme, but}}
\DoxyCodeLine{778   \textcolor{comment}{! this would require an additional loop, etc.}}
\DoxyCodeLine{779   do\_j\_tr(:) = .false.}
\DoxyCodeLine{780   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{if} (domore\_v(j,k)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j2=1-\/stencil,stencil ; do\_j\_tr(j+j2) = .true. ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{781 }
\DoxyCodeLine{782   \textcolor{comment}{! Calculate the j-\/direction profiles (slopes) of each tracer that}}
\DoxyCodeLine{783   \textcolor{comment}{! is being advected.}}
\DoxyCodeLine{784   \textcolor{keywordflow}{if} (useplmslope) \textcolor{keywordflow}{then}}
\DoxyCodeLine{785     \textcolor{keywordflow}{do} j=js-\/stencil,je+stencil ; \textcolor{keywordflow}{if} (do\_j\_tr(j)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{786       \textcolor{comment}{!if (ABS(Tr(m)\%t(i,j+1,k)-\/Tr(m)\%t(i,j,k)) < \&}}
\DoxyCodeLine{787       \textcolor{comment}{!    ABS(Tr(m)\%t(i,j,k)-\/Tr(m)\%t(i,j-\/1,k))) then}}
\DoxyCodeLine{788       \textcolor{comment}{!  maxslope = 4.0*(Tr(m)\%t(i,j+1,k)-\/Tr(m)\%t(i,j,k))}}
\DoxyCodeLine{789       \textcolor{comment}{!else}}
\DoxyCodeLine{790       \textcolor{comment}{!  maxslope = 4.0*(Tr(m)\%t(i,j,k)-\/Tr(m)\%t(i,j-\/1,k))}}
\DoxyCodeLine{791       \textcolor{comment}{!endif}}
\DoxyCodeLine{792       \textcolor{comment}{!if ((Tr(m)\%t(i,j+1,k)-\/Tr(m)\%t(i,j,k))*(Tr(m)\%t(i,j,k)-\/Tr(m)\%t(i,j-\/1,k)) < 0.0) then}}
\DoxyCodeLine{793       \textcolor{comment}{!  slope\_y(i,m,j) = 0.0}}
\DoxyCodeLine{794       \textcolor{comment}{!elseif (ABS(Tr(m)\%t(i,j+1,k)-\/Tr(m)\%t(i,j-\/1,k))<ABS(maxslope)) then}}
\DoxyCodeLine{795       \textcolor{comment}{!  slope\_y(i,m,j) = G\%mask2dCv(i,J) * G\%mask2dCv(i,J-\/1) * \&}}
\DoxyCodeLine{796       \textcolor{comment}{!                 0.5*(Tr(m)\%t(i,j+1,k)-\/Tr(m)\%t(i,j-\/1,k))}}
\DoxyCodeLine{797       \textcolor{comment}{!else}}
\DoxyCodeLine{798       \textcolor{comment}{!  slope\_y(i,m,j) = G\%mask2dCv(i,J) * G\%mask2dCv(i,J-\/1) * 0.5*maxslope}}
\DoxyCodeLine{799       \textcolor{comment}{!endif}}
\DoxyCodeLine{800        tp = tr(m)\%t(i,j+1,k) ; tc = tr(m)\%t(i,j,k) ; tm = tr(m)\%t(i,j-\/1,k)}
\DoxyCodeLine{801        dmx = max( tp, tc, tm ) -\/ tc}
\DoxyCodeLine{802        dmn= tc -\/ min( tp, tc, tm )}
\DoxyCodeLine{803        slope\_y(i,m,j) = g\%mask2dCv(i,j)*g\%mask2dCv(i,j-\/1) * \&}
\DoxyCodeLine{804            sign( min(0.5*abs(tp-\/tm), 2.0*dmx, 2.0*dmn), tp-\/tm )}
\DoxyCodeLine{805 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of i-\/, m-\/, \& j-\/ loops.}}
\DoxyCodeLine{806 \textcolor{keywordflow}{  endif} \textcolor{comment}{! usePLMslope}}
\DoxyCodeLine{807 }
\DoxyCodeLine{808 }
\DoxyCodeLine{809   \textcolor{comment}{! make a copy of the tracers in case values need to be overridden for OBCs}}
\DoxyCodeLine{810 }
\DoxyCodeLine{811   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{812     t\_tmp(i,m,j) = tr(m)\%t(i,j,k)}
\DoxyCodeLine{813 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{814 }
\DoxyCodeLine{815   \textcolor{comment}{! loop through open boundaries and recalculate flux terms}}
\DoxyCodeLine{816   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc\%OBC\_pe) \textcolor{keywordflow}{then}}
\DoxyCodeLine{817      \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments}
\DoxyCodeLine{818        segment=>obc\%segment(n)}
\DoxyCodeLine{819        \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment\%tr\_Reg)) cycle}
\DoxyCodeLine{820        \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{821          \textcolor{keywordflow}{if} (segment\%is\_N\_or\_S) \textcolor{keywordflow}{then}}
\DoxyCodeLine{822            \textcolor{keywordflow}{if} (i>=segment\%HI\%isd .and. i<=segment\%HI\%ied) \textcolor{keywordflow}{then}}
\DoxyCodeLine{823               j = segment\%HI\%JsdB}
\DoxyCodeLine{824               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! replace tracers with OBC values}}
\DoxyCodeLine{825                 \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment\%tr\_Reg\%Tr(m)\%tres)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{826                    \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{827                       t\_tmp(i,m,j) = segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{828                    \textcolor{keywordflow}{else}}
\DoxyCodeLine{829                       t\_tmp(i,m,j+1) = segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{830 \textcolor{keywordflow}{                   endif}}
\DoxyCodeLine{831                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{832                    \textcolor{keywordflow}{if} (segment\%direction == obc\_direction\_s) \textcolor{keywordflow}{then}}
\DoxyCodeLine{833                       t\_tmp(i,m,j) = segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc}
\DoxyCodeLine{834                    \textcolor{keywordflow}{else}}
\DoxyCodeLine{835                       t\_tmp(i,m,j+1) = segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc}
\DoxyCodeLine{836 \textcolor{keywordflow}{                   endif}}
\DoxyCodeLine{837 \textcolor{keywordflow}{                endif}}
\DoxyCodeLine{838 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{839               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! Apply update tracer values for slope calculation}}
\DoxyCodeLine{840                 \textcolor{keywordflow}{do} j=segment\%HI\%JsdB-\/1,segment\%HI\%JsdB+1}
\DoxyCodeLine{841                   tp = t\_tmp(i,m,j+1) ; tc = t\_tmp(i,m,j) ; tm = t\_tmp(i,m,j-\/1)}
\DoxyCodeLine{842                   dmx = max( tp, tc, tm ) -\/ tc}
\DoxyCodeLine{843                   dmn= tc -\/ min( tp, tc, tm )}
\DoxyCodeLine{844                   slope\_y(i,m,j) = g\%mask2dCv(i,j)*g\%mask2dCv(i,j-\/1) * \&}
\DoxyCodeLine{845                        sign( min(0.5*abs(tp-\/tm), 2.0*dmx, 2.0*dmn), tp-\/tm )}
\DoxyCodeLine{846 \textcolor{keywordflow}{                enddo}}
\DoxyCodeLine{847 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{848 \textcolor{keywordflow}{           endif}}
\DoxyCodeLine{849 \textcolor{keywordflow}{         endif} \textcolor{comment}{! is\_N\_S}}
\DoxyCodeLine{850 \textcolor{keywordflow}{       enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{851 \textcolor{keywordflow}{     enddo} \textcolor{comment}{! segment loop}}
\DoxyCodeLine{852   endif;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{853 }
\DoxyCodeLine{854   \textcolor{comment}{! Calculate the j-\/direction fluxes of each tracer, using as much}}
\DoxyCodeLine{855   \textcolor{comment}{! the minimum of the remaining mass flux (vhr) and the half the mass}}
\DoxyCodeLine{856   \textcolor{comment}{! in the cell plus whatever part of its half of the mass flux that}}
\DoxyCodeLine{857   \textcolor{comment}{! the flux through the other side does not require.}}
\DoxyCodeLine{858   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{if} (domore\_v(j,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{859     domore\_v(j,k) = .false.}
\DoxyCodeLine{860 }
\DoxyCodeLine{861     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{862       \textcolor{keywordflow}{if} ((vhr(i,j,k) == 0.0) .or. \&}
\DoxyCodeLine{863           ((vhr(i,j,k) < 0.0) .and. (hprev(i,j+1,k) <= tiny\_h)) .or. \&}
\DoxyCodeLine{864           ((vhr(i,j,k) > 0.0) .and. (hprev(i,j,k) <= tiny\_h)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{865         vhh(i,j) = 0.0}
\DoxyCodeLine{866         cfl(i) = 0.0}
\DoxyCodeLine{867       \textcolor{keywordflow}{elseif} (vhr(i,j,k) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{868         hup = hprev(i,j+1,k) -\/ g\%areaT(i,j+1)*min\_h}
\DoxyCodeLine{869         hlos = max(0.0, vhr(i,j+1,k))}
\DoxyCodeLine{870         \textcolor{keywordflow}{if} ((((hup -\/ hlos) + vhr(i,j,k)) < 0.0) .and. \&}
\DoxyCodeLine{871             ((0.5*hup + vhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{872           vhh(i,j) = min(-\/0.5*hup, -\/hup+hlos, 0.0)}
\DoxyCodeLine{873           domore\_v(j,k) = .true.}
\DoxyCodeLine{874         \textcolor{keywordflow}{else}}
\DoxyCodeLine{875           vhh(i,j) = vhr(i,j,k)}
\DoxyCodeLine{876 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{877         cfl(i) = -\/ vhh(i,j) / hprev(i,j+1,k)  \textcolor{comment}{! CFL is positive}}
\DoxyCodeLine{878       \textcolor{keywordflow}{else}}
\DoxyCodeLine{879         hup = hprev(i,j,k) -\/ g\%areaT(i,j)*min\_h}
\DoxyCodeLine{880         hlos = max(0.0, -\/vhr(i,j-\/1,k))}
\DoxyCodeLine{881         \textcolor{keywordflow}{if} ((((hup -\/ hlos) -\/ vhr(i,j,k)) < 0.0) .and. \&}
\DoxyCodeLine{882             ((0.5*hup -\/ vhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{883           vhh(i,j) = max(0.5*hup, hup-\/hlos, 0.0)}
\DoxyCodeLine{884           domore\_v(j,k) = .true.}
\DoxyCodeLine{885         \textcolor{keywordflow}{else}}
\DoxyCodeLine{886           vhh(i,j) = vhr(i,j,k)}
\DoxyCodeLine{887 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{888         cfl(i) = vhh(i,j) / hprev(i,j,k)  \textcolor{comment}{! CFL is positive}}
\DoxyCodeLine{889 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{890 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{891 }
\DoxyCodeLine{892     \textcolor{keywordflow}{if} (useppm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{893       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{894         \textcolor{comment}{! centre cell depending on upstream direction}}
\DoxyCodeLine{895         \textcolor{keywordflow}{if} (vhh(i,j) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{896           j\_up = j}
\DoxyCodeLine{897         \textcolor{keywordflow}{else}}
\DoxyCodeLine{898           j\_up = j + 1}
\DoxyCodeLine{899 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{900 }
\DoxyCodeLine{901         \textcolor{comment}{! Implementation of PPM-\/H3}}
\DoxyCodeLine{902         tp = t\_tmp(i,m,j\_up+1) ; tc = t\_tmp(i,m,j\_up) ; tm = t\_tmp(i,m,j\_up-\/1)}
\DoxyCodeLine{903 }
\DoxyCodeLine{904         \textcolor{keywordflow}{if} (usehuynh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{905           al = ( 5.*tc + ( 2.*tm -\/ tp ) )/6. \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{906           al = max( min(tc,tm), al) ; al = min( max(tc,tm), al) \textcolor{comment}{! Bound}}
\DoxyCodeLine{907           ar = ( 5.*tc + ( 2.*tp -\/ tm ) )/6. \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{908           ar = max( min(tc,tp), ar) ; ar = min( max(tc,tp), ar) \textcolor{comment}{! Bound}}
\DoxyCodeLine{909         \textcolor{keywordflow}{else}}
\DoxyCodeLine{910           al = 0.5 * ((tm + tc) + (slope\_y(i,m,j\_up-\/1) -\/ slope\_y(i,m,j\_up)) / 3.)}
\DoxyCodeLine{911           ar = 0.5 * ((tc + tp) + (slope\_y(i,m,j\_up) -\/ slope\_y(i,m,j\_up+1)) / 3.)}
\DoxyCodeLine{912 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{913 }
\DoxyCodeLine{914         da = ar -\/ al ; ma = 0.5*( ar + al )}
\DoxyCodeLine{915         \textcolor{keywordflow}{if} (g\%mask2dCv(i,j\_up)*g\%mask2dCv(i,j\_up-\/1)*(tp-\/tc)*(tc-\/tm) <= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{916           al = tc ; ar = tc \textcolor{comment}{! PCM for local extremum and bounadry cells}}
\DoxyCodeLine{917         \textcolor{keywordflow}{elseif} ( da*(tc-\/ma) > (da*da)/6. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{918           al = 3.*tc -\/ 2.*ar}
\DoxyCodeLine{919         \textcolor{keywordflow}{elseif} ( da*(tc-\/ma) < -\/ (da*da)/6. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{920           ar = 3.*tc -\/ 2.*al}
\DoxyCodeLine{921 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{922 }
\DoxyCodeLine{923         a6 = 6.*tc -\/ 3. * (ar + al) \textcolor{comment}{! Curvature}}
\DoxyCodeLine{924 }
\DoxyCodeLine{925         \textcolor{keywordflow}{if} (vhh(i,j) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{926           flux\_y(i,m,j) = vhh(i,j)*( ar -\/ 0.5 * cfl(i) * ( \&}
\DoxyCodeLine{927                ( ar -\/ al ) -\/ a6 * ( 1. -\/ 2./3. * cfl(i) ) ) )}
\DoxyCodeLine{928         \textcolor{keywordflow}{else}}
\DoxyCodeLine{929           flux\_y(i,m,j) = vhh(i,j)*( al + 0.5 * cfl(i) * ( \&}
\DoxyCodeLine{930                ( ar -\/ al ) + a6 * ( 1. -\/ 2./3. * cfl(i) ) ) )}
\DoxyCodeLine{931 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{932 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{933     \textcolor{keywordflow}{else} \textcolor{comment}{! PLM}}
\DoxyCodeLine{934       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{935         \textcolor{keywordflow}{if} (vhh(i,j) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{936           \textcolor{comment}{! Indirect implementation of PLM}}
\DoxyCodeLine{937          \textcolor{comment}{!aL = Tr(m)\%t(i,j,k) -\/ 0.5 * slope\_y(i,m,j)}}
\DoxyCodeLine{938          \textcolor{comment}{!aR = Tr(m)\%t(i,j,k) + 0.5 * slope\_y(i,m,j)}}
\DoxyCodeLine{939          \textcolor{comment}{!flux\_y(i,m,J) = vhh(i,J)*( aR -\/ 0.5 * (aR-\/aL) * CFL(i) )}}
\DoxyCodeLine{940           \textcolor{comment}{! Alternative implementation of PLM}}
\DoxyCodeLine{941           tc = t\_tmp(i,m,j)}
\DoxyCodeLine{942           flux\_y(i,m,j) = vhh(i,j)*( tc + 0.5 * slope\_y(i,m,j) * ( 1. -\/ cfl(i) ) )}
\DoxyCodeLine{943         \textcolor{keywordflow}{else}}
\DoxyCodeLine{944           \textcolor{comment}{! Indirect implementation of PLM}}
\DoxyCodeLine{945          \textcolor{comment}{!aL = Tr(m)\%t(i,j+1,k) -\/ 0.5 * slope\_y(i,m,j+1)}}
\DoxyCodeLine{946          \textcolor{comment}{!aR = Tr(m)\%t(i,j+1,k) + 0.5 * slope\_y(i,m,j+1)}}
\DoxyCodeLine{947          \textcolor{comment}{!flux\_y(i,m,J) = vhh(i,J)*( aL + 0.5 * (aR-\/aL) * CFL(i) )}}
\DoxyCodeLine{948           \textcolor{comment}{! Alternative implementation of PLM}}
\DoxyCodeLine{949           tc = t\_tmp(i,m,j+1)}
\DoxyCodeLine{950           flux\_y(i,m,j) = vhh(i,j)*( tc -\/ 0.5 * slope\_y(i,m,j+1) * ( 1. -\/ cfl(i) ) )}
\DoxyCodeLine{951 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{952 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{953 \textcolor{keywordflow}{    endif} \textcolor{comment}{! usePPM}}
\DoxyCodeLine{954 }
\DoxyCodeLine{955     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc\%OBC\_pe) \textcolor{keywordflow}{then}}
\DoxyCodeLine{956       \textcolor{keywordflow}{if} (obc\%specified\_v\_BCs\_exist\_globally .or. obc\%open\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{957         \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments}
\DoxyCodeLine{958           segment=>obc\%segment(n)}
\DoxyCodeLine{959           \textcolor{keywordflow}{if} (.not. segment\%specified) cycle}
\DoxyCodeLine{960           \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment\%tr\_Reg)) cycle}
\DoxyCodeLine{961           \textcolor{keywordflow}{if} (obc\%segment(n)\%is\_N\_or\_S) \textcolor{keywordflow}{then}}
\DoxyCodeLine{962             \textcolor{keywordflow}{if} (j >= segment\%HI\%JsdB .and. j<= segment\%HI\%JedB) \textcolor{keywordflow}{then}}
\DoxyCodeLine{963               \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{964                 \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}}
\DoxyCodeLine{965                 \textcolor{comment}{! Now changing to simply fixed inflows.}}
\DoxyCodeLine{966                 \textcolor{keywordflow}{if} ((vhr(i,j,k) > 0.0) .and. (segment\%direction == obc\_direction\_s) .or. \&}
\DoxyCodeLine{967                    (vhr(i,j,k) < 0.0) .and. (segment\%direction == obc\_direction\_n)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{968                   vhh(i,j) = vhr(i,j,k)}
\DoxyCodeLine{969                   \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{970                     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment\%tr\_Reg\%Tr(m)\%t)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{971                       flux\_y(i,m,j) = vhh(i,j)*obc\%segment(n)\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{972                     \textcolor{keywordflow}{else} ; flux\_y(i,m,j) = vhh(i,j)*obc\%segment(n)\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{973 \textcolor{keywordflow}{                  enddo}}
\DoxyCodeLine{974 \textcolor{keywordflow}{                endif}}
\DoxyCodeLine{975 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{976 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{977 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{978 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{979 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{980 }
\DoxyCodeLine{981       \textcolor{keywordflow}{if} (obc\%open\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{982         \textcolor{keywordflow}{do} n=1,obc\%number\_of\_segments}
\DoxyCodeLine{983           segment=>obc\%segment(n)}
\DoxyCodeLine{984           \textcolor{keywordflow}{if} (segment\%specified) cycle}
\DoxyCodeLine{985           \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment\%tr\_Reg)) cycle}
\DoxyCodeLine{986           \textcolor{keywordflow}{if} (segment\%is\_N\_or\_S .and. (j >= segment\%HI\%JsdB .and. j<= segment\%HI\%JedB)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{987             \textcolor{keywordflow}{do} i=segment\%HI\%isd,segment\%HI\%ied}
\DoxyCodeLine{988               \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}}
\DoxyCodeLine{989               \textcolor{keywordflow}{if} ((vhr(i,j,k) > 0.0) .and. (g\%mask2dT(i,j) < 0.5) .or. \&}
\DoxyCodeLine{990                   (vhr(i,j,k) < 0.0) .and. (g\%mask2dT(i,j+1) < 0.5)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{991                 vhh(i,j) = vhr(i,j,k)}
\DoxyCodeLine{992                 \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{993                   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment\%tr\_Reg\%Tr(m)\%t)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{994                     flux\_y(i,m,j) = vhh(i,j)*segment\%tr\_Reg\%Tr(m)\%tres(i,j,k)}
\DoxyCodeLine{995                   \textcolor{keywordflow}{else} ; flux\_y(i,m,j) = vhh(i,j)*segment\%tr\_Reg\%Tr(m)\%OBC\_inflow\_conc ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{996 \textcolor{keywordflow}{                enddo}}
\DoxyCodeLine{997 \textcolor{keywordflow}{              endif}}
\DoxyCodeLine{998 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{999 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1000 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1001 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1002     endif;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1003 }
\DoxyCodeLine{1004   \textcolor{keywordflow}{else} \textcolor{comment}{! not domore\_v.}}
\DoxyCodeLine{1005     \textcolor{keywordflow}{do} i=is,ie ; vhh(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1006     \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie ; flux\_y(i,m,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1007 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-\/loop}}
\DoxyCodeLine{1008 }
\DoxyCodeLine{1009   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1010     vhr(i,j,k) = vhr(i,j,k) -\/ vhh(i,j)}
\DoxyCodeLine{1011     \textcolor{keywordflow}{if} (abs(vhr(i,j,k)) < vh\_neglect(i,j)) vhr(i,j,k) = 0.0}
\DoxyCodeLine{1012 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1013 }
\DoxyCodeLine{1014   \textcolor{comment}{! Calculate new tracer concentration in each cell after accounting}}
\DoxyCodeLine{1015   \textcolor{comment}{! for the j-\/direction fluxes.}}
\DoxyCodeLine{1016   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (do\_j\_tr(j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1017     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1018       \textcolor{keywordflow}{if} ((vhh(i,j) /= 0.0) .or. (vhh(i,j-\/1) /= 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1019         do\_i(i,j) = .true.}
\DoxyCodeLine{1020         hlst(i) = hprev(i,j,k)}
\DoxyCodeLine{1021         hprev(i,j,k) = max(hprev(i,j,k) -\/ (vhh(i,j) -\/ vhh(i,j-\/1)), 0.0)}
\DoxyCodeLine{1022         \textcolor{keywordflow}{if} (hprev(i,j,k) <= 0.0) \textcolor{keywordflow}{then} ; do\_i(i,j) = .false.}
\DoxyCodeLine{1023         \textcolor{keywordflow}{elseif} (hprev(i,j,k) < h\_neglect*g\%areaT(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1024           hlst(i) = hlst(i) + (h\_neglect*g\%areaT(i,j) -\/ hprev(i,j,k))}
\DoxyCodeLine{1025           ihnew(i) = 1.0 / (h\_neglect*g\%areaT(i,j))}
\DoxyCodeLine{1026         \textcolor{keywordflow}{else} ;  ihnew(i) = 1.0 / hprev(i,j,k) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1027       \textcolor{keywordflow}{else} ; do\_i(i,j) = .false. ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1028 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1029 }
\DoxyCodeLine{1030     \textcolor{comment}{! update tracer and save some diagnostics}}
\DoxyCodeLine{1031     \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{1032       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1033         tr(m)\%t(i,j,k) = (tr(m)\%t(i,j,k) * hlst(i) -\/ \&}
\DoxyCodeLine{1034                           (flux\_y(i,m,j) -\/ flux\_y(i,m,j-\/1))) * ihnew(i)}
\DoxyCodeLine{1035 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1036 }
\DoxyCodeLine{1037       \textcolor{comment}{! diagnostics}}
\DoxyCodeLine{1038       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad\_y)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1039         tr(m)\%ad\_y(i,j,k) = tr(m)\%ad\_y(i,j,k) + flux\_y(i,m,j)*idt}
\DoxyCodeLine{1040 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1041 }
\DoxyCodeLine{1042       \textcolor{comment}{! diagnose convergence of flux\_y and add to convergence of flux\_x.}}
\DoxyCodeLine{1043       \textcolor{comment}{! division by areaT to get into W/m2 for heat and kg/(s*m2) for salt.}}
\DoxyCodeLine{1044       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%advection\_xy)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1045         \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1046           tr(m)\%advection\_xy(i,j,k) = tr(m)\%advection\_xy(i,j,k) -\/ (flux\_y(i,m,j) -\/ flux\_y(i,m,j-\/1))* idt * \&}
\DoxyCodeLine{1047                                           g\%IareaT(i,j)}
\DoxyCodeLine{1048 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1049 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1050 }
\DoxyCodeLine{1051 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1052 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-\/loop.}}
\DoxyCodeLine{1053 }
\DoxyCodeLine{1054   \textcolor{comment}{! compute ad2d\_y diagnostic outside above j-\/loop so as to make the summation ordered when OMP is active.}}
\DoxyCodeLine{1055 }
\DoxyCodeLine{1056   \textcolor{comment}{!\$OMP ordered}}
\DoxyCodeLine{1057   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (do\_j\_tr(j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1058     \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{1059       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)\%ad2d\_y)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1060         tr(m)\%ad2d\_y(i,j) = tr(m)\%ad2d\_y(i,j) + flux\_y(i,m,j)*idt}
\DoxyCodeLine{1061 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1062 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1063 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-\/loop.}}
\DoxyCodeLine{1064   \textcolor{comment}{!\$OMP end ordered}}
\DoxyCodeLine{1065 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_a2e466a8a34546bb9265a74ff0209df47}\label{namespacemom__tracer__advect_a2e466a8a34546bb9265a74ff0209df47}} 
\index{mom\_tracer\_advect@{mom\_tracer\_advect}!tracer\_advect\_end@{tracer\_advect\_end}}
\index{tracer\_advect\_end@{tracer\_advect\_end}!mom\_tracer\_advect@{mom\_tracer\_advect}}
\doxysubsubsection{\texorpdfstring{tracer\_advect\_end()}{tracer\_advect\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+advect\+::tracer\+\_\+advect\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Close the tracer advection module. 


\begin{DoxyParams}{Parameters}
{\em cs} & module control structure \\
\hline
\end{DoxyParams}


Definition at line 1125 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1125   \textcolor{keywordtype}{type}(tracer\_advect\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< module control structure}}
\DoxyCodeLine{1126 }
\DoxyCodeLine{1127   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1128 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_aacf9cdc544c9c3a188d6e3e9a0d7b9df}\label{namespacemom__tracer__advect_aacf9cdc544c9c3a188d6e3e9a0d7b9df}} 
\index{mom\_tracer\_advect@{mom\_tracer\_advect}!tracer\_advect\_init@{tracer\_advect\_init}}
\index{tracer\_advect\_init@{tracer\_advect\_init}!mom\_tracer\_advect@{mom\_tracer\_advect}}
\doxysubsubsection{\texorpdfstring{tracer\_advect\_init()}{tracer\_advect\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+advect\+::tracer\+\_\+advect\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initialize lateral tracer advection module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & current model time \\
\hline
\mbox{\texttt{ in}}  & {\em g} & ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & open file to parse for model parameters \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & regulates diagnostic output \\
\hline
 & {\em cs} & module control structure \\
\hline
\end{DoxyParams}


Definition at line 1070 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1070   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{        !< current model time}}
\DoxyCodeLine{1071   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{           !< ocean grid structure}}
\DoxyCodeLine{1072   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{          !< A dimensional unit scaling type}}
\DoxyCodeLine{1073   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{  !< open file to parse for model parameters}}
\DoxyCodeLine{1074   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{        !< regulates diagnostic output}}
\DoxyCodeLine{1075   \textcolor{keywordtype}{type}(tracer\_advect\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{          !< module control structure}}
\DoxyCodeLine{1076 }
\DoxyCodeLine{1077   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{save} :: init\_calls = 0}
\DoxyCodeLine{1078 }
\DoxyCodeLine{1079   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{1080 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{1081 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_tracer\_advect"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{1082   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}}
\DoxyCodeLine{1083 }
\DoxyCodeLine{1084   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1085     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"tracer\_advect\_init called with associated control structure."})}
\DoxyCodeLine{1086     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1087 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1088   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{1089 }
\DoxyCodeLine{1090   cs\%diag => diag}
\DoxyCodeLine{1091 }
\DoxyCodeLine{1092   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{1093   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{1094   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT"}, cs\%dt, fail\_if\_missing=.true., \&}
\DoxyCodeLine{1095           desc=\textcolor{stringliteral}{"The (baroclinic) dynamics time step."}, units=\textcolor{stringliteral}{"s"}, scale=us\%s\_to\_T)}
\DoxyCodeLine{1096   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs\%debug, default=.false.)}
\DoxyCodeLine{1097   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TRACER\_ADVECTION\_SCHEME"}, mesg, \&}
\DoxyCodeLine{1098           desc=\textcolor{stringliteral}{"The horizontal transport scheme for tracers:\(\backslash\)n"}//\&}
\DoxyCodeLine{1099           \textcolor{stringliteral}{"  PLM    -\/ Piecewise Linear Method\(\backslash\)n"}//\&}
\DoxyCodeLine{1100           \textcolor{stringliteral}{"  PPM:H3 -\/ Piecewise Parabolic Method (Huyhn 3rd order)\(\backslash\)n"}// \&}
\DoxyCodeLine{1101           \textcolor{stringliteral}{"  PPM    -\/ Piecewise Parabolic Method (Colella-\/Woodward)"} \&}
\DoxyCodeLine{1102           , default=\textcolor{stringliteral}{'PLM'})}
\DoxyCodeLine{1103   \textcolor{keywordflow}{select case} (trim(mesg))}
\DoxyCodeLine{1104     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PLM"})}
\DoxyCodeLine{1105       cs\%usePPM = .false.}
\DoxyCodeLine{1106     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM:H3"})}
\DoxyCodeLine{1107       cs\%usePPM = .true.}
\DoxyCodeLine{1108       cs\%useHuynh = .true.}
\DoxyCodeLine{1109     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM"})}
\DoxyCodeLine{1110       cs\%usePPM = .true.}
\DoxyCodeLine{1111       cs\%useHuynh = .false.}
\DoxyCodeLine{1112 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{1113       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tracer\_advect, tracer\_advect\_init: "}//\&}
\DoxyCodeLine{1114            \textcolor{stringliteral}{"Unknown TRACER\_ADVECTION\_SCHEME = "}//trim(mesg))}
\DoxyCodeLine{1115 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{1116 }
\DoxyCodeLine{1117   id\_clock\_advect = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean advect tracer)'}, grain=clock\_module)}
\DoxyCodeLine{1118   id\_clock\_pass = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tracer halo updates)'}, grain=clock\_routine)}
\DoxyCodeLine{1119   id\_clock\_sync = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tracer global synch)'}, grain=clock\_routine)}
\DoxyCodeLine{1120 }

\end{DoxyCode}
