\hypertarget{namespaceuser__tracer__example}{}\doxysection{user\+\_\+tracer\+\_\+example Module Reference}
\label{namespaceuser__tracer__example}\index{user\_tracer\_example@{user\_tracer\_example}}


\doxysubsection{Detailed Description}
A sample tracer package that has striped initial conditions. 

Original by Robert Hallberg, 2002

This file contains an example of the code that is needed to set up and use a set (in this case one) of dynamically passive tracers.

A single subroutine is called from within each file to register each of the tracers for reinitialization and advection and to register the subroutine that initializes the tracers and set up their output and the subroutine that does any tracer physics or chemistry along with diapycnal mixing (included here because some tracers may float or swim vertically or dye diapycnal processes). \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the U\+S\+E\+R\+\_\+tracer\+\_\+example module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespaceuser__tracer__example_a71efc349b3fbeb6f4cb2155de1f8bbe5}{user\+\_\+register\+\_\+tracer\+\_\+example}} (HI, GV, param\+\_\+file, CS, tr\+\_\+\+Reg, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em This subroutine is used to register tracer fields and subroutines to be used with M\+OM. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceuser__tracer__example_a00806c17a421a7f59d45022ad2472bf3}{user\+\_\+initialize\+\_\+tracer}} (restart, day, G, GV, h, diag, O\+BC, CS, sponge\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em This subroutine initializes the N\+TR tracer fields in tr(\+:,\+:,\+:,\+:) and it sets up the tracer output. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceuser__tracer__example_a5d96d128687dfa6fdb8ae17f7ef2813a}{tracer\+\_\+column\+\_\+physics}} (h\+\_\+old, h\+\_\+new, ea, eb, fluxes, dt, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em This subroutine applies diapycnal diffusion and any other column tracer physics or chemistry to the tracers from this file. This is a simple example of a set of advected passive tracers. The arguments to this subroutine are redundant in that h\+\_\+new(k) = h\+\_\+old(k) + ea(k) -\/ eb(k-\/1) + eb(k) -\/ ea(k+1) \end{DoxyCompactList}\item 
integer function, public \mbox{\hyperlink{namespaceuser__tracer__example_a040e2b8e8c5a41ccb6398e66d820c4be}{user\+\_\+tracer\+\_\+stock}} (h, stocks, G, GV, CS, names, units, stock\+\_\+index)
\begin{DoxyCompactList}\small\item\em This function calculates the mass-\/weighted integral of all tracer stocks, returning the number of stocks it has calculated. If the stock\+\_\+index is present, only the stock corresponding to that coded index is returned. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceuser__tracer__example_ab45158867aad4ae53c99e7139abfaf2a}{user\+\_\+tracer\+\_\+surface\+\_\+state}} (sfc\+\_\+state, h, G, CS)
\begin{DoxyCompactList}\small\item\em This subroutine extracts the surface fields from this tracer package that are to be shared with the atmosphere in coupled configurations. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceuser__tracer__example_a800285abb2c731b52159ebcc476b9174}{user\+\_\+tracer\+\_\+example\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clean up allocated memory at the end. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespaceuser__tracer__example_a8878e6c0ffc368959f12d7c06e1d60ba}\label{namespaceuser__tracer__example_a8878e6c0ffc368959f12d7c06e1d60ba}} 
integer, parameter \mbox{\hyperlink{namespaceuser__tracer__example_a8878e6c0ffc368959f12d7c06e1d60ba}{ntr}} = 1
\begin{DoxyCompactList}\small\item\em The number of tracers in this module. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespaceuser__tracer__example_a5d96d128687dfa6fdb8ae17f7ef2813a}\label{namespaceuser__tracer__example_a5d96d128687dfa6fdb8ae17f7ef2813a}} 
\index{user\_tracer\_example@{user\_tracer\_example}!tracer\_column\_physics@{tracer\_column\_physics}}
\index{tracer\_column\_physics@{tracer\_column\_physics}!user\_tracer\_example@{user\_tracer\_example}}
\doxysubsubsection{\texorpdfstring{tracer\_column\_physics()}{tracer\_column\_physics()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+tracer\+\_\+example\+::tracer\+\_\+column\+\_\+physics (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+old,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+new,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{ea,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{eb,  }\item[{type(forcing), intent(in)}]{fluxes,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine applies diapycnal diffusion and any other column tracer physics or chemistry to the tracers from this file. This is a simple example of a set of advected passive tracers. The arguments to this subroutine are redundant in that h\+\_\+new(k) = h\+\_\+old(k) + ea(k) -\/ eb(k-\/1) + eb(k) -\/ ea(k+1) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\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}}  & {\em h\+\_\+old} & Layer thickness before entrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+new} & Layer thickness after entrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ea} & an array to which the amount of fluid entrained \\
\hline
\mbox{\texttt{ in}}  & {\em eb} & an array to which the amount of fluid entrained \\
\hline
\mbox{\texttt{ in}}  & {\em fluxes} & A structure containing pointers to thermodynamic and tracer forcing fields. Unused fields have N\+U\+LL ptrs. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & The amount of time covered by this call \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to U\+S\+E\+R\+\_\+register\+\_\+tracer\+\_\+example. \\
\hline
\end{DoxyParams}


Definition at line 263 of file tracer\+\_\+example.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{264   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{265   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{266 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{267                            \textcolor{keywordtype}{intent(in)} :: h\_old\textcolor{comment}{ !< Layer thickness before entrainment [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{268 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{269                            \textcolor{keywordtype}{intent(in)} :: h\_new\textcolor{comment}{ !< Layer thickness after entrainment [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{270 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{271                            \textcolor{keywordtype}{intent(in)} :: ea\textcolor{comment}{   !< an array to which the amount of fluid entrained}}
\DoxyCodeLine{272 \textcolor{comment}{                                              !! from the layer above during this call will be}}
\DoxyCodeLine{273 \textcolor{comment}{                                              !! added [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{274 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{275                            \textcolor{keywordtype}{intent(in)} :: eb\textcolor{comment}{   !< an array to which the amount of fluid entrained}}
\DoxyCodeLine{276 \textcolor{comment}{                                              !! from the layer below during this call will be}}
\DoxyCodeLine{277 \textcolor{comment}{                                              !! added [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{278   \textcolor{keywordtype}{type}(forcing),           \textcolor{keywordtype}{intent(in)} :: fluxes\textcolor{comment}{ !< A structure containing pointers to thermodynamic}}
\DoxyCodeLine{279 \textcolor{comment}{                                              !! and tracer forcing fields.  Unused fields have NULL ptrs.}}
\DoxyCodeLine{280 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)} :: dt\textcolor{comment}{   !< The amount of time covered by this call [T \string~> s]}}
\DoxyCodeLine{281   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{282   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous}}
\DoxyCodeLine{283 \textcolor{comment}{                                              !! call to USER\_register\_tracer\_example.}}
\DoxyCodeLine{284 }
\DoxyCodeLine{285 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{286 \textcolor{keywordtype}{  real} :: hold0(SZI\_(G))       \textcolor{comment}{! The original topmost layer thickness,}}
\DoxyCodeLine{287                                \textcolor{comment}{! with surface mass fluxes added back, m.}}
\DoxyCodeLine{288 \textcolor{keywordtype}{  real} :: b1(SZI\_(G))          \textcolor{comment}{! b1 and c1 are variables used by the}}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real} :: c1(SZI\_(G),SZK\_(G))  \textcolor{comment}{! tridiagonal solver.}}
\DoxyCodeLine{290 \textcolor{keywordtype}{  real} :: d1(SZI\_(G))          \textcolor{comment}{! d1=1-\/c1 is used by the tridiagonal solver.}}
\DoxyCodeLine{291 \textcolor{keywordtype}{  real} :: h\_neglect            \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{292                                \textcolor{comment}{! in roundoff and can be neglected [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{293 \textcolor{keywordtype}{  real} :: b\_denom\_1 \textcolor{comment}{! The first term in the denominator of b1 [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{294   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, m}
\DoxyCodeLine{295 }
\DoxyCodeLine{296 \textcolor{comment}{! The following array (trdc) determines the behavior of the tracer}}
\DoxyCodeLine{297 \textcolor{comment}{! diapycnal advection.  The first element is 1 if tracers are}}
\DoxyCodeLine{298 \textcolor{comment}{! passively advected.  The second and third are the concentrations}}
\DoxyCodeLine{299 \textcolor{comment}{! to which downwelling and upwelling water are set, respectively.}}
\DoxyCodeLine{300 \textcolor{comment}{! For most (normal) tracers, the appropriate vales are \{1,0,0\}.}}
\DoxyCodeLine{301 }
\DoxyCodeLine{302 \textcolor{keywordtype}{  real} :: trdc(3)}
\DoxyCodeLine{303 \textcolor{comment}{!   Uncomment the following line to dye both upwelling and downwelling.}}
\DoxyCodeLine{304 \textcolor{comment}{! data trdc / 0.0,1.0,1.0 /}}
\DoxyCodeLine{305 \textcolor{comment}{!   Uncomment the following line to dye downwelling.}}
\DoxyCodeLine{306 \textcolor{comment}{! data trdc / 0.0,1.0,0.0 /}}
\DoxyCodeLine{307 \textcolor{comment}{!   Uncomment the following line to dye upwelling.}}
\DoxyCodeLine{308 \textcolor{comment}{! data trdc / 0.0,0.0,1.0 /}}
\DoxyCodeLine{309 \textcolor{comment}{!   Uncomment the following line for tracer concentrations to be set}}
\DoxyCodeLine{310 \textcolor{comment}{! to zero in any diapycnal motions.}}
\DoxyCodeLine{311 \textcolor{comment}{! data trdc / 0.0,0.0,0.0 /}}
\DoxyCodeLine{312 \textcolor{comment}{!   Uncomment the following line for most "physical" tracers, which}}
\DoxyCodeLine{313 \textcolor{comment}{! are advected diapycnally in the usual manner.}}
\DoxyCodeLine{314   \textcolor{keyword}{data} trdc / 1.0,0.0,0.0 /}
\DoxyCodeLine{315   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{316 }
\DoxyCodeLine{317   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{318   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{319 }
\DoxyCodeLine{320   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{321     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{322 \textcolor{comment}{!   The following line is appropriate for quantities like salinity}}
\DoxyCodeLine{323 \textcolor{comment}{! that are left behind by evaporation, and any surface fluxes would}}
\DoxyCodeLine{324 \textcolor{comment}{! be explicitly included in the flux structure.}}
\DoxyCodeLine{325       hold0(i) = h\_old(i,j,1)}
\DoxyCodeLine{326 \textcolor{comment}{!   The following line is appropriate for quantities like temperature}}
\DoxyCodeLine{327 \textcolor{comment}{! that can be assumed to have the same concentration in evaporation}}
\DoxyCodeLine{328 \textcolor{comment}{! as they had in the water.  The explicit surface fluxes here would}}
\DoxyCodeLine{329 \textcolor{comment}{! reflect differences in concentration from the ambient water, not}}
\DoxyCodeLine{330 \textcolor{comment}{! the absolute fluxes.}}
\DoxyCodeLine{331   \textcolor{comment}{!   hold0(i) = h\_old(i,j,1) + ea(i,j,1)}}
\DoxyCodeLine{332       b\_denom\_1 = h\_old(i,j,1) + ea(i,j,1) + h\_neglect}
\DoxyCodeLine{333       b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,1))}
\DoxyCodeLine{334 \textcolor{comment}{!       d1(i) = b\_denom\_1 * b1(i)}}
\DoxyCodeLine{335       d1(i) = trdc(1) * (b\_denom\_1 * b1(i)) + (1.0 -\/ trdc(1))}
\DoxyCodeLine{336       \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{337         cs\%tr(i,j,1,m) = b1(i)*(hold0(i)*cs\%tr(i,j,1,m) + trdc(3)*eb(i,j,1))}
\DoxyCodeLine{338  \textcolor{comment}{!      Add any surface tracer fluxes to the preceding line.}}
\DoxyCodeLine{339 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{340 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{341     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{342       c1(i,k) = trdc(1) * eb(i,j,k-\/1) * b1(i)}
\DoxyCodeLine{343       b\_denom\_1 = h\_old(i,j,k) + d1(i)*ea(i,j,k) + h\_neglect}
\DoxyCodeLine{344       b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,k))}
\DoxyCodeLine{345       d1(i) = trdc(1) * (b\_denom\_1 * b1(i)) + (1.0 -\/ trdc(1))}
\DoxyCodeLine{346       \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{347         cs\%tr(i,j,k,m) = b1(i) * (h\_old(i,j,k)*cs\%tr(i,j,k,m) + \&}
\DoxyCodeLine{348                  ea(i,j,k)*(trdc(1)*cs\%tr(i,j,k-\/1,m)+trdc(2)) + \&}
\DoxyCodeLine{349                  eb(i,j,k)*trdc(3))}
\DoxyCodeLine{350 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{351 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{352     \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} k=nz-\/1,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{353       cs\%tr(i,j,k,m) = cs\%tr(i,j,k,m) + c1(i,k+1)*cs\%tr(i,j,k+1,m)}
\DoxyCodeLine{354 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{355 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{356 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__tracer__example_a00806c17a421a7f59d45022ad2472bf3}\label{namespaceuser__tracer__example_a00806c17a421a7f59d45022ad2472bf3}} 
\index{user\_tracer\_example@{user\_tracer\_example}!user\_initialize\_tracer@{user\_initialize\_tracer}}
\index{user\_initialize\_tracer@{user\_initialize\_tracer}!user\_tracer\_example@{user\_tracer\_example}}
\doxysubsubsection{\texorpdfstring{user\_initialize\_tracer()}{user\_initialize\_tracer()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+tracer\+\_\+example\+::user\+\_\+initialize\+\_\+tracer (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{restart,  }\item[{type(time\+\_\+type), intent(in), target}]{day,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(diag\+\_\+ctrl), intent(in), target}]{diag,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{type(\mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}), pointer}]{CS,  }\item[{type(sponge\+\_\+cs), pointer}]{sponge\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



This subroutine initializes the N\+TR tracer fields in tr(\+:,\+:,\+:,\+:) and it sets up the tracer output. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em restart} & .true. if the fields have already been read from a restart file. \\
\hline
\mbox{\texttt{ in}}  & {\em day} & Time of the start of the run. \\
\hline
\mbox{\texttt{ in}}  & {\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}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em diag} & A structure that is used to regulate diagnostic output. \\
\hline
 & {\em obc} & This open boundary condition type specifies whether, where, and what open boundary conditions are used. \\
\hline
 & {\em cs} & The control structure returned by a previous call to U\+S\+E\+R\+\_\+register\+\_\+tracer\+\_\+example. \\
\hline
 & {\em sponge\+\_\+csp} & A pointer to the control structure for the sponges, if they are in use. \\
\hline
\end{DoxyParams}


Definition at line 139 of file tracer\+\_\+example.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{141   \textcolor{keywordtype}{logical},                            \textcolor{keywordtype}{intent(in)} :: restart\textcolor{comment}{ !< .true. if the fields have already}}
\DoxyCodeLine{142 \textcolor{comment}{                                                         !! been read from a restart file.}}
\DoxyCodeLine{143   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: day\textcolor{comment}{  !< Time of the start of the run.}}
\DoxyCodeLine{144   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{145   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{146 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{147                                       \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{148   \textcolor{keywordtype}{type}(diag\_ctrl),            \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{ !< A structure that is used to regulate}}
\DoxyCodeLine{149 \textcolor{comment}{                                                         !! diagnostic output.}}
\DoxyCodeLine{150   \textcolor{keywordtype}{type}(ocean\_OBC\_type),               \textcolor{keywordtype}{pointer}    :: OBC\textcolor{comment}{  !< This open boundary condition type specifies}}
\DoxyCodeLine{151 \textcolor{comment}{                                                         !! whether, where, and what open boundary}}
\DoxyCodeLine{152 \textcolor{comment}{                                                         !! conditions are used.}}
\DoxyCodeLine{153   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS),       \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< The control structure returned by a previous}}
\DoxyCodeLine{154 \textcolor{comment}{                                                         !! call to USER\_register\_tracer\_example.}}
\DoxyCodeLine{155   \textcolor{keywordtype}{type}(sponge\_CS),                    \textcolor{keywordtype}{pointer}    :: sponge\_CSp\textcolor{comment}{    !< A pointer to the control structure}}
\DoxyCodeLine{156 \textcolor{comment}{                                                                  !! for the sponges, if they are in use.}}
\DoxyCodeLine{157 }
\DoxyCodeLine{158 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{159 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable} :: temp(:,:,:)}
\DoxyCodeLine{160   \textcolor{keywordtype}{character(len=32)} :: name     \textcolor{comment}{! A variable's name in a NetCDF file.}}
\DoxyCodeLine{161   \textcolor{keywordtype}{character(len=72)} :: longname \textcolor{comment}{! The long name of that variable.}}
\DoxyCodeLine{162   \textcolor{keywordtype}{character(len=48)} :: units    \textcolor{comment}{! The dimensions of the variable.}}
\DoxyCodeLine{163   \textcolor{keywordtype}{character(len=48)} :: flux\_units \textcolor{comment}{! The units for tracer fluxes, usually}}
\DoxyCodeLine{164                             \textcolor{comment}{! kg(tracer) kg(water)-\/1 m3 s-\/1 or kg(tracer) s-\/1.}}
\DoxyCodeLine{165 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{pointer} :: tr\_ptr(:,:,:) => null()}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real} :: PI     \textcolor{comment}{! 3.1415926... calculated as 4*atan(1)}}
\DoxyCodeLine{167 \textcolor{keywordtype}{  real} :: tr\_y   \textcolor{comment}{! Initial zonally uniform tracer concentrations.}}
\DoxyCodeLine{168 \textcolor{keywordtype}{  real} :: dist2  \textcolor{comment}{! The distance squared from a line [m2].}}
\DoxyCodeLine{169   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz, m}
\DoxyCodeLine{170   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB, lntr}
\DoxyCodeLine{171 }
\DoxyCodeLine{172   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{173   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{174   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{175   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{176 }
\DoxyCodeLine{177   lntr = ntr \textcolor{comment}{! Avoids compile-\/time warning when NTR<2}}
\DoxyCodeLine{178   cs\%Time => day}
\DoxyCodeLine{179   cs\%diag => diag}
\DoxyCodeLine{180 }
\DoxyCodeLine{181   \textcolor{keywordflow}{if} (.not.restart) \textcolor{keywordflow}{then}}
\DoxyCodeLine{182     \textcolor{keywordflow}{if} (len\_trim(cs\%tracer\_IC\_file) >= 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{183 \textcolor{comment}{!  Read the tracer concentrations from a netcdf file.}}
\DoxyCodeLine{184       \textcolor{keywordflow}{if} (.not.file\_exists(cs\%tracer\_IC\_file, g\%Domain)) \&}
\DoxyCodeLine{185         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"USER\_initialize\_tracer: Unable to open "}// \&}
\DoxyCodeLine{186                         cs\%tracer\_IC\_file)}
\DoxyCodeLine{187       \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{188         \textcolor{keyword}{call }query\_vardesc(cs\%tr\_desc(m), name, caller=\textcolor{stringliteral}{"USER\_initialize\_tracer"})}
\DoxyCodeLine{189         \textcolor{keyword}{call }mom\_read\_data(cs\%tracer\_IC\_file, trim(name), cs\%tr(:,:,:,m), g\%Domain)}
\DoxyCodeLine{190 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{191     \textcolor{keywordflow}{else}}
\DoxyCodeLine{192       \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{193         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{194           cs\%tr(i,j,k,m) = 1.0e-\/20 \textcolor{comment}{! This could just as well be 0.}}
\DoxyCodeLine{195 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{196 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{197 }
\DoxyCodeLine{198 \textcolor{comment}{!    This sets a stripe of tracer across the basin.}}
\DoxyCodeLine{199       pi = 4.0*atan(1.0)}
\DoxyCodeLine{200       \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{201         dist2 = (g\%Rad\_Earth * pi / 180.0)**2 * \&}
\DoxyCodeLine{202                (g\%geoLatT(i,j) -\/ 40.0) * (g\%geoLatT(i,j) -\/ 40.0)}
\DoxyCodeLine{203         tr\_y = 0.5*exp(-\/dist2/(1.0e5*1.0e5))}
\DoxyCodeLine{204 }
\DoxyCodeLine{205         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{206 \textcolor{comment}{!      This adds the stripes of tracer to every layer.}}
\DoxyCodeLine{207           cs\%tr(i,j,k,1) = cs\%tr(i,j,k,1) + tr\_y}
\DoxyCodeLine{208 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{209 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{210 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{211 \textcolor{keywordflow}{  endif} \textcolor{comment}{! restart}}
\DoxyCodeLine{212 }
\DoxyCodeLine{213   \textcolor{keywordflow}{if} ( cs\%use\_sponge ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{214 \textcolor{comment}{!   If sponges are used, this example damps tracers in sponges in the}}
\DoxyCodeLine{215 \textcolor{comment}{! northern half of the domain to 1 and tracers in the southern half}}
\DoxyCodeLine{216 \textcolor{comment}{! to 0.  For any tracers that are not damped in the sponge, the call}}
\DoxyCodeLine{217 \textcolor{comment}{! to set\_up\_sponge\_field can simply be omitted.}}
\DoxyCodeLine{218     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(sponge\_csp)) \&}
\DoxyCodeLine{219       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"USER\_initialize\_tracer: "}// \&}
\DoxyCodeLine{220         \textcolor{stringliteral}{"The pointer to sponge\_CSp must be associated if SPONGE is defined."})}
\DoxyCodeLine{221 }
\DoxyCodeLine{222     \textcolor{keyword}{allocate}(temp(g\%isd:g\%ied,g\%jsd:g\%jed,nz))}
\DoxyCodeLine{223     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{224       \textcolor{keywordflow}{if} (g\%geoLatT(i,j) > 700.0 .and. (k > nz/2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{225         temp(i,j,k) = 1.0}
\DoxyCodeLine{226       \textcolor{keywordflow}{else}}
\DoxyCodeLine{227         temp(i,j,k) = 0.0}
\DoxyCodeLine{228 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{229 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{230 }
\DoxyCodeLine{231 \textcolor{comment}{!   do m=1,NTR}}
\DoxyCodeLine{232     \textcolor{keywordflow}{do} m=1,1}
\DoxyCodeLine{233       \textcolor{comment}{! This is needed to force the compiler not to do a copy in the sponge}}
\DoxyCodeLine{234       \textcolor{comment}{! calls.  Curses on the designers and implementers of Fortran90.}}
\DoxyCodeLine{235       tr\_ptr => cs\%tr(:,:,:,m)}
\DoxyCodeLine{236       \textcolor{keyword}{call }set\_up\_sponge\_field(temp, tr\_ptr, g, nz, sponge\_csp)}
\DoxyCodeLine{237 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{238     \textcolor{keyword}{deallocate}(temp)}
\DoxyCodeLine{239 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{240 }
\DoxyCodeLine{241   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{242     \textcolor{keyword}{call }query\_vardesc(cs\%tr\_desc(1), name, caller=\textcolor{stringliteral}{"USER\_initialize\_tracer"})}
\DoxyCodeLine{243     \textcolor{keywordflow}{if} (obc\%specified\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}}
\DoxyCodeLine{244       \textcolor{comment}{! Steal from updated DOME in the fullness of time.}}
\DoxyCodeLine{245     \textcolor{keywordflow}{else}}
\DoxyCodeLine{246       \textcolor{comment}{! Steal from updated DOME in the fullness of time.}}
\DoxyCodeLine{247 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{248     \textcolor{comment}{! All tracers but the first have 0 concentration in their inflows. As this}}
\DoxyCodeLine{249     \textcolor{comment}{! is the default value, the following calls are unnecessary.}}
\DoxyCodeLine{250     \textcolor{keywordflow}{do} m=2,lntr}
\DoxyCodeLine{251       \textcolor{keyword}{call }query\_vardesc(cs\%tr\_desc(m), name, caller=\textcolor{stringliteral}{"USER\_initialize\_tracer"})}
\DoxyCodeLine{252       \textcolor{comment}{! Steal from updated DOME in the fullness of time.}}
\DoxyCodeLine{253 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{254 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{255 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__tracer__example_a71efc349b3fbeb6f4cb2155de1f8bbe5}\label{namespaceuser__tracer__example_a71efc349b3fbeb6f4cb2155de1f8bbe5}} 
\index{user\_tracer\_example@{user\_tracer\_example}!user\_register\_tracer\_example@{user\_register\_tracer\_example}}
\index{user\_register\_tracer\_example@{user\_register\_tracer\_example}!user\_tracer\_example@{user\_tracer\_example}}
\doxysubsubsection{\texorpdfstring{user\_register\_tracer\_example()}{user\_register\_tracer\_example()}}
{\footnotesize\ttfamily logical function, public user\+\_\+tracer\+\_\+example\+::user\+\_\+register\+\_\+tracer\+\_\+example (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}), pointer}]{CS,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{tr\+\_\+\+Reg,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



This subroutine is used to register tracer fields and subroutines to be used with M\+OM. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em hi} & A horizontal index type structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module \\
\hline
 & {\em tr\+\_\+reg} & A pointer that is set to point to the control structure for the tracer advection and diffusion module \\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure \\
\hline
\end{DoxyParams}


Definition at line 56 of file tracer\+\_\+example.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{57   \textcolor{keywordtype}{type}(hor\_index\_type),    \textcolor{keywordtype}{intent(in)}   :: HI\textcolor{comment}{   !< A horizontal index type structure}}
\DoxyCodeLine{58   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}   :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{59   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}   :: param\_file\textcolor{comment}{ !< A structure to parse for run-\/time parameters}}
\DoxyCodeLine{60   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< A pointer that is set to point to the control}}
\DoxyCodeLine{61 \textcolor{comment}{                                                !! structure for this module}}
\DoxyCodeLine{62   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}   :: tr\_Reg\textcolor{comment}{ !< A pointer that is set to point to the control}}
\DoxyCodeLine{63 \textcolor{comment}{                                                  !! structure for the tracer advection and}}
\DoxyCodeLine{64 \textcolor{comment}{                                                  !! diffusion module}}
\DoxyCodeLine{65   \textcolor{keywordtype}{type}(MOM\_restart\_CS),       \textcolor{keywordtype}{pointer}   :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}}
\DoxyCodeLine{66 }
\DoxyCodeLine{67 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{68   \textcolor{keywordtype}{character(len=80)}  :: name, longname}
\DoxyCodeLine{69 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{70 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{71 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"tracer\_example"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{72   \textcolor{keywordtype}{character(len=200)} :: inputdir}
\DoxyCodeLine{73   \textcolor{keywordtype}{character(len=48)} :: flux\_units \textcolor{comment}{! The units for tracer fluxes, usually}}
\DoxyCodeLine{74                             \textcolor{comment}{! kg(tracer) kg(water)-\/1 m3 s-\/1 or kg(tracer) s-\/1.}}
\DoxyCodeLine{75 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{pointer} :: tr\_ptr(:,:,:) => null()}
\DoxyCodeLine{76   \textcolor{keywordtype}{logical} :: USER\_register\_tracer\_example}
\DoxyCodeLine{77   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, nz, m}
\DoxyCodeLine{78   isd = hi\%isd ; ied = hi\%ied ; jsd = hi\%jsd ; jed = hi\%jed ; nz = gv\%ke}
\DoxyCodeLine{79 }
\DoxyCodeLine{80   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{81     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"USER\_register\_tracer\_example called with an "}// \&}
\DoxyCodeLine{82                             \textcolor{stringliteral}{"associated control structure."})}
\DoxyCodeLine{83     \textcolor{keywordflow}{return}}
\DoxyCodeLine{84 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{85   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{86 }
\DoxyCodeLine{87   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{88   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{89   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TRACER\_EXAMPLE\_IC\_FILE"}, cs\%tracer\_IC\_file, \&}
\DoxyCodeLine{90                  \textcolor{stringliteral}{"The name of a file from which to read the initial "}//\&}
\DoxyCodeLine{91                  \textcolor{stringliteral}{"conditions for the DOME tracers, or blank to initialize "}//\&}
\DoxyCodeLine{92                  \textcolor{stringliteral}{"them internally."}, default=\textcolor{stringliteral}{" "})}
\DoxyCodeLine{93   \textcolor{keywordflow}{if} (len\_trim(cs\%tracer\_IC\_file) >= 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{94     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})}
\DoxyCodeLine{95     cs\%tracer\_IC\_file = trim(slasher(inputdir))//trim(cs\%tracer\_IC\_file)}
\DoxyCodeLine{96     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/TRACER\_EXAMPLE\_IC\_FILE"}, \&}
\DoxyCodeLine{97                    cs\%tracer\_IC\_file)}
\DoxyCodeLine{98 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{99   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE"}, cs\%use\_sponge, \&}
\DoxyCodeLine{100                  \textcolor{stringliteral}{"If true, sponges may be applied anywhere in the domain. "}//\&}
\DoxyCodeLine{101                  \textcolor{stringliteral}{"The exact location and properties of those sponges are "}//\&}
\DoxyCodeLine{102                  \textcolor{stringliteral}{"specified from MOM\_initialization.F90."}, default=.false.)}
\DoxyCodeLine{103 }
\DoxyCodeLine{104   \textcolor{keyword}{allocate}(cs\%tr(isd:ied,jsd:jed,nz,ntr)) ; cs\%tr(:,:,:,:) = 0.0}
\DoxyCodeLine{105 }
\DoxyCodeLine{106   \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{107     \textcolor{keywordflow}{if} (m < 10) \textcolor{keywordflow}{then} ; \textcolor{keyword}{write}(name,\textcolor{stringliteral}{'("tr",I1.1)'}) m}
\DoxyCodeLine{108     \textcolor{keywordflow}{else} ; \textcolor{keyword}{write}(name,\textcolor{stringliteral}{'("tr",I2.2)'}) m ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{109     \textcolor{keyword}{write}(longname,\textcolor{stringliteral}{'("Concentration of Tracer ",I2.2)'}) m}
\DoxyCodeLine{110     cs\%tr\_desc(m) = var\_desc(name, units=\textcolor{stringliteral}{"kg kg-\/1"}, longname=longname, caller=mdl)}
\DoxyCodeLine{111 }
\DoxyCodeLine{112     \textcolor{comment}{! This needs to be changed if the units of tracer are changed above.}}
\DoxyCodeLine{113     \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then} ; flux\_units = \textcolor{stringliteral}{"kg kg-\/1 m3 s-\/1"}}
\DoxyCodeLine{114     \textcolor{keywordflow}{else} ; flux\_units = \textcolor{stringliteral}{"kg s-\/1"} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{115 }
\DoxyCodeLine{116     \textcolor{comment}{! This is needed to force the compiler not to do a copy in the registration}}
\DoxyCodeLine{117     \textcolor{comment}{! calls.  Curses on the designers and implementers of Fortran90.}}
\DoxyCodeLine{118     tr\_ptr => cs\%tr(:,:,:,m)}
\DoxyCodeLine{119     \textcolor{comment}{! Register the tracer for horizontal advection, diffusion, and restarts.}}
\DoxyCodeLine{120     \textcolor{keyword}{call }register\_tracer(tr\_ptr, tr\_reg, param\_file, hi, gv, \&}
\DoxyCodeLine{121                          name=name, longname=longname, units=\textcolor{stringliteral}{"kg kg-\/1"}, \&}
\DoxyCodeLine{122                          registry\_diags=.true., flux\_units=flux\_units, \&}
\DoxyCodeLine{123                          restart\_cs=restart\_cs)}
\DoxyCodeLine{124 }
\DoxyCodeLine{125     \textcolor{comment}{!   Set coupled\_tracers to be true (hard-\/coded above) to provide the surface}}
\DoxyCodeLine{126     \textcolor{comment}{! values to the coupler (if any).  This is meta-\/code and its arguments will}}
\DoxyCodeLine{127     \textcolor{comment}{! currently (deliberately) give fatal errors if it is used.}}
\DoxyCodeLine{128     \textcolor{keywordflow}{if} (cs\%coupled\_tracers) \&}
\DoxyCodeLine{129       cs\%ind\_tr(m) = aof\_set\_coupler\_flux(trim(name)//\textcolor{stringliteral}{'\_flux'}, \&}
\DoxyCodeLine{130           flux\_type=\textcolor{stringliteral}{' '}, implementation=\textcolor{stringliteral}{' '}, caller=\textcolor{stringliteral}{"USER\_register\_tracer\_example"})}
\DoxyCodeLine{131 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{132 }
\DoxyCodeLine{133   cs\%tr\_Reg => tr\_reg}
\DoxyCodeLine{134   user\_register\_tracer\_example = .true.}

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__tracer__example_a800285abb2c731b52159ebcc476b9174}\label{namespaceuser__tracer__example_a800285abb2c731b52159ebcc476b9174}} 
\index{user\_tracer\_example@{user\_tracer\_example}!user\_tracer\_example\_end@{user\_tracer\_example\_end}}
\index{user\_tracer\_example\_end@{user\_tracer\_example\_end}!user\_tracer\_example@{user\_tracer\_example}}
\doxysubsubsection{\texorpdfstring{user\_tracer\_example\_end()}{user\_tracer\_example\_end()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+tracer\+\_\+example\+::user\+\_\+tracer\+\_\+example\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clean up allocated memory at the end. 


\begin{DoxyParams}{Parameters}
{\em cs} & The control structure returned by a previous call to register\+\_\+\+U\+S\+E\+R\+\_\+tracer. \\
\hline
\end{DoxyParams}


Definition at line 439 of file tracer\+\_\+example.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{440   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous}}
\DoxyCodeLine{441 \textcolor{comment}{                                              !! call to register\_USER\_tracer.}}
\DoxyCodeLine{442   \textcolor{keywordtype}{integer} :: m}
\DoxyCodeLine{443 }
\DoxyCodeLine{444   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{445     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%tr)) \textcolor{keyword}{deallocate}(cs\%tr)}
\DoxyCodeLine{446     \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{447 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__tracer__example_a040e2b8e8c5a41ccb6398e66d820c4be}\label{namespaceuser__tracer__example_a040e2b8e8c5a41ccb6398e66d820c4be}} 
\index{user\_tracer\_example@{user\_tracer\_example}!user\_tracer\_stock@{user\_tracer\_stock}}
\index{user\_tracer\_stock@{user\_tracer\_stock}!user\_tracer\_example@{user\_tracer\_example}}
\doxysubsubsection{\texorpdfstring{user\_tracer\_stock()}{user\_tracer\_stock()}}
{\footnotesize\ttfamily integer function, public user\+\_\+tracer\+\_\+example\+::user\+\_\+tracer\+\_\+stock (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(out)}]{stocks,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}), pointer}]{CS,  }\item[{character(len=$\ast$), dimension(\+:), intent(out)}]{names,  }\item[{character(len=$\ast$), dimension(\+:), intent(out)}]{units,  }\item[{integer, intent(in), optional}]{stock\+\_\+index }\end{DoxyParamCaption})}



This function calculates the mass-\/weighted integral of all tracer stocks, returning the number of stocks it has calculated. If the stock\+\_\+index is present, only the stock corresponding to that coded index is returned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\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}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em stocks} & the mass-\/weighted integrated amount of each tracer, in kg times concentration units \mbox{[}kg conc\mbox{]}. \\
\hline
 & {\em cs} & The control structure returned by a previous call to register\+\_\+\+U\+S\+E\+R\+\_\+tracer. \\
\hline
\mbox{\texttt{ out}}  & {\em names} & The names of the stocks calculated. \\
\hline
\mbox{\texttt{ out}}  & {\em units} & The units of the stocks calculated. \\
\hline
\mbox{\texttt{ in}}  & {\em stock\+\_\+index} & The coded index of a specific stock being sought. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value\+: the number of stocks calculated here. 
\end{DoxyReturn}


Definition at line 362 of file tracer\+\_\+example.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{363   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{364   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{366                                       \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{367 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},                 \textcolor{keywordtype}{intent(out)}   :: stocks\textcolor{comment}{ !< the mass-\/weighted integrated amount of each}}
\DoxyCodeLine{368 \textcolor{comment}{                                                              !! tracer, in kg times concentration units [kg conc].}}
\DoxyCodeLine{369   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS),       \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< The control structure returned by a}}
\DoxyCodeLine{370 \textcolor{comment}{                                                              !! previous call to register\_USER\_tracer.}}
\DoxyCodeLine{371   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},     \textcolor{keywordtype}{intent(out)}   :: names\textcolor{comment}{  !< The names of the stocks calculated.}}
\DoxyCodeLine{372   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},     \textcolor{keywordtype}{intent(out)}   :: units\textcolor{comment}{  !< The units of the stocks calculated.}}
\DoxyCodeLine{373   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},                  \textcolor{keywordtype}{intent(in)}    :: stock\_index\textcolor{comment}{ !< The coded index of a specific stock}}
\DoxyCodeLine{374 \textcolor{comment}{                                                              !! being sought.}}
\DoxyCodeLine{375   \textcolor{keywordtype}{integer}                                           :: USER\_tracer\_stock\textcolor{comment}{ !< Return value: the number of}}
\DoxyCodeLine{376 \textcolor{comment}{                                                              !! stocks calculated here.}}
\DoxyCodeLine{377 }
\DoxyCodeLine{378 \textcolor{comment}{! Local variables}}
\DoxyCodeLine{379   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, m}
\DoxyCodeLine{380   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{381 }
\DoxyCodeLine{382   user\_tracer\_stock = 0}
\DoxyCodeLine{383   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{384 }
\DoxyCodeLine{385   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stock\_index)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (stock\_index > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{386     \textcolor{comment}{! Check whether this stock is available from this routine.}}
\DoxyCodeLine{387 }
\DoxyCodeLine{388     \textcolor{comment}{! No stocks from this routine are being checked yet.  Return 0.}}
\DoxyCodeLine{389     \textcolor{keywordflow}{return}}
\DoxyCodeLine{390 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{391 }
\DoxyCodeLine{392   \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{393     \textcolor{keyword}{call }query\_vardesc(cs\%tr\_desc(m), name=names(m), units=units(m), caller=\textcolor{stringliteral}{"USER\_tracer\_stock"})}
\DoxyCodeLine{394     units(m) = trim(units(m))//\textcolor{stringliteral}{" kg"}}
\DoxyCodeLine{395     stocks(m) = 0.0}
\DoxyCodeLine{396     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{397       stocks(m) = stocks(m) + cs\%tr(i,j,k,m) * \&}
\DoxyCodeLine{398                              (g\%mask2dT(i,j) * g\%US\%L\_to\_m**2*g\%areaT(i,j) * h(i,j,k))}
\DoxyCodeLine{399 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{400     stocks(m) = gv\%H\_to\_kg\_m2 * stocks(m)}
\DoxyCodeLine{401 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{402   user\_tracer\_stock = ntr}
\DoxyCodeLine{403 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__tracer__example_ab45158867aad4ae53c99e7139abfaf2a}\label{namespaceuser__tracer__example_ab45158867aad4ae53c99e7139abfaf2a}} 
\index{user\_tracer\_example@{user\_tracer\_example}!user\_tracer\_surface\_state@{user\_tracer\_surface\_state}}
\index{user\_tracer\_surface\_state@{user\_tracer\_surface\_state}!user\_tracer\_example@{user\_tracer\_example}}
\doxysubsubsection{\texorpdfstring{user\_tracer\_surface\_state()}{user\_tracer\_surface\_state()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+tracer\+\_\+example\+::user\+\_\+tracer\+\_\+surface\+\_\+state (\begin{DoxyParamCaption}\item[{type(surface), intent(inout)}]{sfc\+\_\+state,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structuser__tracer__example_1_1user__tracer__example__cs}{user\+\_\+tracer\+\_\+example\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine extracts the surface fields from this tracer package that are to be shared with the atmosphere in coupled configurations. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em sfc\+\_\+state} & A structure containing fields that describe the surface state of the ocean. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
 & {\em cs} & The control structure returned by a previous call to register\+\_\+\+U\+S\+E\+R\+\_\+tracer. \\
\hline
\end{DoxyParams}


Definition at line 408 of file tracer\+\_\+example.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{409   \textcolor{keywordtype}{type}(ocean\_grid\_type),        \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< The ocean's grid structure}}
\DoxyCodeLine{410   \textcolor{keywordtype}{type}(surface),                \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{ !< A structure containing fields that}}
\DoxyCodeLine{411 \textcolor{comment}{                                                       !! describe the surface state of the ocean.}}
\DoxyCodeLine{412 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{413                                 \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{414   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a previous}}
\DoxyCodeLine{415 \textcolor{comment}{                                                    !! call to register\_USER\_tracer.}}
\DoxyCodeLine{416 }
\DoxyCodeLine{417   \textcolor{comment}{! This particular tracer package does not report anything back to the coupler.}}
\DoxyCodeLine{418   \textcolor{comment}{! The code that is here is just a rough guide for packages that would.}}
\DoxyCodeLine{419 }
\DoxyCodeLine{420   \textcolor{keywordtype}{integer} :: m, is, ie, js, je, isd, ied, jsd, jed}
\DoxyCodeLine{421   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{422   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{423 }
\DoxyCodeLine{424   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{425 }
\DoxyCodeLine{426   \textcolor{keywordflow}{if} (cs\%coupled\_tracers) \textcolor{keywordflow}{then}}
\DoxyCodeLine{427     \textcolor{keywordflow}{do} m=1,ntr}
\DoxyCodeLine{428       \textcolor{comment}{!   This call loads the surface values into the appropriate array in the}}
\DoxyCodeLine{429       \textcolor{comment}{! coupler-\/type structure.}}
\DoxyCodeLine{430       \textcolor{keyword}{call }coupler\_type\_set\_data(cs\%tr(:,:,1,m), cs\%ind\_tr(m), ind\_csurf, \&}
\DoxyCodeLine{431                    sfc\_state\%tr\_fields, idim=(/isd, is, ie, ied/), \&}
\DoxyCodeLine{432                    jdim=(/jsd, js, je, jed/) )}
\DoxyCodeLine{433 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{434 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{435 }

\end{DoxyCode}
