\hypertarget{namespaceuser__tracer__example}{}\section{user\+\_\+tracer\+\_\+example Module Reference}
\label{namespaceuser__tracer__example}\index{user\+\_\+tracer\+\_\+example@{user\+\_\+tracer\+\_\+example}}


\subsection{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). \subsection*{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}
\subsection*{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}
\subsection*{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}


\subsection{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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h\+\_\+old} & Layer thickness before entrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+new} & Layer thickness after entrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em ea} & an array to which the amount of fluid entrained\\
\hline
\mbox{\tt in}  & {\em eb} & an array to which the amount of fluid entrained\\
\hline
\mbox{\tt in}  & {\em fluxes} & A structure containing pointers to thermodynamic and tracer forcing fields. Unused fields have N\+U\+LL ptrs.\\
\hline
\mbox{\tt in}  & {\em dt} & The amount of time covered by this call \mbox{[}T $\sim$$>$ s\mbox{]}\\
\hline
\mbox{\tt 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 264 of file tracer\+\_\+example.\+F90.


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


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


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


\begin{DoxyCode}
440   \textcolor{keywordtype}{type}(USER\_tracer\_example\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous}
441 \textcolor{comment}{                                              !! call to register\_USER\_tracer.}
442   \textcolor{keywordtype}{integer} :: m
443 
444   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
445     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tr)) \textcolor{keyword}{deallocate}(cs%tr)
446     \textcolor{keyword}{deallocate}(cs)
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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{\tt out}  & {\em names} & The names of the stocks calculated.\\
\hline
\mbox{\tt out}  & {\em units} & The units of the stocks calculated.\\
\hline
\mbox{\tt 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 363 of file tracer\+\_\+example.\+F90.


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


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