\hypertarget{namespaceideal__age__example}{}\section{ideal\+\_\+age\+\_\+example Module Reference}
\label{namespaceideal__age__example}\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}


\subsection{Detailed Description}
A tracer package of ideal age tracers. 

Originally 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 two) of dynamically passive tracers for diagnostic purposes. The tracers here are an ideal age tracer that ages at a rate of 1/year once it is isolated from the surface, and a vintage tracer, whose surface concentration grows exponen-\/ with time with a 30-\/year timescale (similar to C\+F\+Cs). \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the ideal\+\_\+age\+\_\+tracer package. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespaceideal__age__example_a58d550a02148b87b1d1ce979fcaf6c00}{register\+\_\+ideal\+\_\+age\+\_\+tracer}} (HI, GV, param\+\_\+file, CS, tr\+\_\+\+Reg, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Register the ideal age tracer fields to be used with M\+OM. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceideal__age__example_ae8c12d0128c24a491f7af62d4dd6ec5d}{initialize\+\_\+ideal\+\_\+age\+\_\+tracer}} (restart, day, G, GV, US, h, diag, O\+BC, CS, sponge\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Sets the ideal age traces to their initial values and sets up the tracer output. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceideal__age__example_a6c2fb023e159a153d56220585b57ceb5}{ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics}} (h\+\_\+old, h\+\_\+new, ea, eb, fluxes, dt, G, GV, US, CS, evap\+\_\+\+C\+F\+L\+\_\+limit, minimum\+\_\+forcing\+\_\+depth)
\begin{DoxyCompactList}\small\item\em Applies diapycnal diffusion, aging and regeneration at the surface to the ideal age tracers. \end{DoxyCompactList}\item 
integer function, public \mbox{\hyperlink{namespaceideal__age__example_a2300d82e30802a3127f4a63277d37776}{ideal\+\_\+age\+\_\+stock}} (h, stocks, G, GV, CS, names, units, stock\+\_\+index)
\begin{DoxyCompactList}\small\item\em Calculates the mass-\/weighted integral of all tracer stocks, returning the number of stocks it has calculated. If stock\+\_\+index is present, only the stock corresponding to that coded index is found. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceideal__age__example_aea477e25ddf0fdc4f05fd45a102eb7c0}{ideal\+\_\+age\+\_\+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. This particular tracer package does not report anything back to the coupler. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceideal__age__example_aa60b31c0f0a31db75ba3522f52c8d648}{ideal\+\_\+age\+\_\+example\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Deallocate any memory associated with this tracer package. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespaceideal__age__example_a50d4c454d945cfb178a50dcad0f4ae15}\label{namespaceideal__age__example_a50d4c454d945cfb178a50dcad0f4ae15}} 
integer, parameter \mbox{\hyperlink{namespaceideal__age__example_a50d4c454d945cfb178a50dcad0f4ae15}{ntr\+\_\+max}} = 3
\begin{DoxyCompactList}\small\item\em the maximum number of tracers in this module. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespaceideal__age__example_aa60b31c0f0a31db75ba3522f52c8d648}\label{namespaceideal__age__example_aa60b31c0f0a31db75ba3522f52c8d648}} 
\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}!ideal\+\_\+age\+\_\+example\+\_\+end@{ideal\+\_\+age\+\_\+example\+\_\+end}}
\index{ideal\+\_\+age\+\_\+example\+\_\+end@{ideal\+\_\+age\+\_\+example\+\_\+end}!ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}
\subsubsection{\texorpdfstring{ideal\+\_\+age\+\_\+example\+\_\+end()}{ideal\_age\_example\_end()}}
{\footnotesize\ttfamily subroutine, public ideal\+\_\+age\+\_\+example\+::ideal\+\_\+age\+\_\+example\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocate any memory associated with this tracer package. 


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


Definition at line 455 of file ideal\+\_\+age\+\_\+example.\+F90.


\begin{DoxyCode}
455   \textcolor{keywordtype}{type}(ideal\_age\_tracer\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous}
456 \textcolor{comment}{                                           !! call to register\_ideal\_age\_tracer.}
457 
458   \textcolor{keywordtype}{integer} :: m
459 
460   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
461     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tr)) \textcolor{keyword}{deallocate}(cs%tr)
462     \textcolor{keyword}{deallocate}(cs)
463 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespaceideal__age__example_a2300d82e30802a3127f4a63277d37776}\label{namespaceideal__age__example_a2300d82e30802a3127f4a63277d37776}} 
\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}!ideal\+\_\+age\+\_\+stock@{ideal\+\_\+age\+\_\+stock}}
\index{ideal\+\_\+age\+\_\+stock@{ideal\+\_\+age\+\_\+stock}!ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}
\subsubsection{\texorpdfstring{ideal\+\_\+age\+\_\+stock()}{ideal\_age\_stock()}}
{\footnotesize\ttfamily integer function, public ideal\+\_\+age\+\_\+example\+::ideal\+\_\+age\+\_\+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{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+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})}



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


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s 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
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
 & {\em cs} & The control structure returned by a previous call to register\+\_\+ideal\+\_\+age\+\_\+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}
The number of stocks calculated here. 
\end{DoxyReturn}


Definition at line 375 of file ideal\+\_\+age\+\_\+example.\+F90.


\begin{DoxyCode}
375   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}
376   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
377                                       \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
378   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},                 \textcolor{keywordtype}{intent(out)}   :: stocks\textcolor{comment}{ !< the mass-weighted integrated amount of
       each}
379 \textcolor{comment}{                                                            !! tracer, in kg times concentration units [kg
       conc].}
380   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
381   \textcolor{keywordtype}{type}(ideal\_age\_tracer\_CS),          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< The control structure returned by a previous}
382 \textcolor{comment}{                                                            !! call to register\_ideal\_age\_tracer.}
383   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},     \textcolor{keywordtype}{intent(out)}   :: names\textcolor{comment}{  !< the names of the stocks calculated.}
384   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},     \textcolor{keywordtype}{intent(out)}   :: units\textcolor{comment}{  !< the units of the stocks calculated.}
385   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},                  \textcolor{keywordtype}{intent(in)}    :: stock\_index\textcolor{comment}{ !< the coded index of a specific stock}
386 \textcolor{comment}{                                                                   !! being sought.}
387   \textcolor{keywordtype}{integer}                                           :: ideal\_age\_stock\textcolor{comment}{ !< The number of stocks calculated
       here.}
388 \textcolor{comment}{! This function calculates the mass-weighted integral of all tracer stocks,}
389 \textcolor{comment}{! returning the number of stocks it has calculated.  If the stock\_index}
390 \textcolor{comment}{! is present, only the stock corresponding to that coded index is returned.}
391 
392   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, m
393   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
394 
395   ideal\_age\_stock = 0
396   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
397   \textcolor{keywordflow}{if} (cs%ntr < 1) \textcolor{keywordflow}{return}
398 
399   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stock\_index)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (stock\_index > 0) \textcolor{keywordflow}{then}
400     \textcolor{comment}{! Check whether this stock is available from this routine.}
401 
402     \textcolor{comment}{! No stocks from this routine are being checked yet.  Return 0.}
403     \textcolor{keywordflow}{return}
404 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
405 
406   \textcolor{keywordflow}{do} m=1,cs%ntr
407     \textcolor{keyword}{call }query\_vardesc(cs%tr\_desc(m), name=names(m), units=units(m), caller=\textcolor{stringliteral}{"ideal\_age\_stock"})
408     units(m) = trim(units(m))//\textcolor{stringliteral}{" kg"}
409     stocks(m) = 0.0
410     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
411       stocks(m) = stocks(m) + cs%tr(i,j,k,m) * &
412                              (g%mask2dT(i,j) * g%US%L\_to\_m**2*g%areaT(i,j) * h(i,j,k))
413 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
414     stocks(m) = gv%H\_to\_kg\_m2 * stocks(m)
415 \textcolor{keywordflow}{  enddo}
416   ideal\_age\_stock = cs%ntr
417 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceideal__age__example_a6c2fb023e159a153d56220585b57ceb5}\label{namespaceideal__age__example_a6c2fb023e159a153d56220585b57ceb5}} 
\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}!ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics@{ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics}}
\index{ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics@{ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics}!ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}
\subsubsection{\texorpdfstring{ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics()}{ideal\_age\_tracer\_column\_physics()}}
{\footnotesize\ttfamily subroutine, public ideal\+\_\+age\+\_\+example\+::ideal\+\_\+age\+\_\+tracer\+\_\+column\+\_\+physics (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+old,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+new,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{ea,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), 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{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+cs}}), pointer}]{CS,  }\item[{real, intent(in), optional}]{evap\+\_\+\+C\+F\+L\+\_\+limit,  }\item[{real, intent(in), optional}]{minimum\+\_\+forcing\+\_\+depth }\end{DoxyParamCaption})}



Applies diapycnal diffusion, aging and regeneration at the surface to the ideal age tracers. 


\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 register\+\_\+ideal\+\_\+age\+\_\+tracer.\\
\hline
\mbox{\tt in}  & {\em evap\+\_\+cfl\+\_\+limit} & Limit on the fraction of the water that can be fluxed out of the top layer in a timestep \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em minimum\+\_\+forcing\+\_\+depth} & The smallest depth over which fluxes can be applied \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 286 of file ideal\+\_\+age\+\_\+example.\+F90.


\begin{DoxyCode}
286   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}
287   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
288   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
289                            \textcolor{keywordtype}{intent(in)} :: h\_old\textcolor{comment}{ !< Layer thickness before entrainment [H ~> m or kg m-2].}
290   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
291                            \textcolor{keywordtype}{intent(in)} :: h\_new\textcolor{comment}{ !< Layer thickness after entrainment [H ~> m or kg m-2].}
292   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
293                            \textcolor{keywordtype}{intent(in)} :: ea\textcolor{comment}{   !< an array to which the amount of fluid entrained}
294 \textcolor{comment}{                                              !! from the layer above during this call will be}
295 \textcolor{comment}{                                              !! added [H ~> m or kg m-2].}
296   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
297                            \textcolor{keywordtype}{intent(in)} :: eb\textcolor{comment}{   !< an array to which the amount of fluid entrained}
298 \textcolor{comment}{                                              !! from the layer below during this call will be}
299 \textcolor{comment}{                                              !! added [H ~> m or kg m-2].}
300   \textcolor{keywordtype}{type}(forcing),           \textcolor{keywordtype}{intent(in)} :: fluxes\textcolor{comment}{ !< A structure containing pointers to thermodynamic}
301 \textcolor{comment}{                                              !! and tracer forcing fields.  Unused fields have NULL ptrs.}
302   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)} :: dt\textcolor{comment}{   !< The amount of time covered by this call [T ~> s]}
303   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
304   \textcolor{keywordtype}{type}(ideal\_age\_tracer\_CS), \textcolor{keywordtype}{pointer}  :: CS\textcolor{comment}{   !< The control structure returned by a previous}
305 \textcolor{comment}{                                              !! call to register\_ideal\_age\_tracer.}
306   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: evap\_CFL\_limit\textcolor{comment}{ !< Limit on the fraction of the water that can}
307 \textcolor{comment}{                                              !! be fluxed out of the top layer in a timestep [nondim]}
308   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: minimum\_forcing\_depth\textcolor{comment}{ !< The smallest depth over which}
309 \textcolor{comment}{                                              !! fluxes can be applied [H ~> m or kg m-2]}
310 \textcolor{comment}{!   This subroutine applies diapycnal diffusion and any other column}
311 \textcolor{comment}{! tracer physics or chemistry to the tracers from this file.}
312 \textcolor{comment}{! This is a simple example of a set of advected passive tracers.}
313 
314 \textcolor{comment}{! The arguments to this subroutine are redundant in that}
315 \textcolor{comment}{!     h\_new(k) = h\_old(k) + ea(k) - eb(k-1) + eb(k) - ea(k+1)}
316   \textcolor{comment}{! Local variables}
317   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: h\_work \textcolor{comment}{! Used so that h can be modified}
318   \textcolor{keywordtype}{real} :: sfc\_val  \textcolor{comment}{! The surface value for the tracers.}
319   \textcolor{keywordtype}{real} :: Isecs\_per\_year  \textcolor{comment}{! The inverse of the amount of time in a year [T-1 ~> s-1]}
320   \textcolor{keywordtype}{real} :: year            \textcolor{comment}{! The time in years.}
321   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, m
322   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
323 
324   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
325   \textcolor{keywordflow}{if} (cs%ntr < 1) \textcolor{keywordflow}{return}
326 
327   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(evap\_cfl\_limit) .and. \textcolor{keyword}{present}(minimum\_forcing\_depth)) \textcolor{keywordflow}{then}
328     \textcolor{keywordflow}{do} m=1,cs%ntr
329       \textcolor{keywordflow}{do} k=1,nz ;\textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
330         h\_work(i,j,k) = h\_old(i,j,k)
331 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
332       \textcolor{keyword}{call }applytracerboundaryfluxesinout(g, gv, cs%tr(:,:,:,m), dt, fluxes, h\_work, &
333                                           evap\_cfl\_limit, minimum\_forcing\_depth)
334       \textcolor{keyword}{call }tracer\_vertdiff(h\_work, ea, eb, dt, cs%tr(:,:,:,m), g, gv)
335 \textcolor{keywordflow}{    enddo}
336   \textcolor{keywordflow}{else}
337     \textcolor{keywordflow}{do} m=1,cs%ntr
338       \textcolor{keyword}{call }tracer\_vertdiff(h\_old, ea, eb, dt, cs%tr(:,:,:,m), g, gv)
339 \textcolor{keywordflow}{    enddo}
340 \textcolor{keywordflow}{  endif}
341 
342   isecs\_per\_year = 1.0 / (365.0*86400.0*us%s\_to\_T)
343   \textcolor{comment}{!   Set the surface value of tracer 1 to increase exponentially}
344   \textcolor{comment}{! with a 30 year time scale.}
345   year = us%s\_to\_T*time\_type\_to\_real(cs%Time) * isecs\_per\_year
346 
347   \textcolor{keywordflow}{do} m=1,cs%ntr
348     \textcolor{keywordflow}{if} (cs%sfc\_growth\_rate(m) == 0.0) \textcolor{keywordflow}{then}
349       sfc\_val = cs%young\_val(m)
350     \textcolor{keywordflow}{else}
351       sfc\_val = cs%young\_val(m) * &
352           exp((year-cs%tracer\_start\_year(m)) * cs%sfc\_growth\_rate(m))
353 \textcolor{keywordflow}{    endif}
354     \textcolor{keywordflow}{do} k=1,cs%nkml ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
355       \textcolor{keywordflow}{if} (g%mask2dT(i,j) > 0.5) \textcolor{keywordflow}{then}
356         cs%tr(i,j,k,m) = sfc\_val
357       \textcolor{keywordflow}{else}
358         cs%tr(i,j,k,m) = cs%land\_val(m)
359 \textcolor{keywordflow}{      endif}
360 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
361 \textcolor{keywordflow}{  enddo}
362   \textcolor{keywordflow}{do} m=1,cs%ntr ; \textcolor{keywordflow}{if} (cs%tracer\_ages(m) .and. &
363                       (year>=cs%tracer\_start\_year(m))) \textcolor{keywordflow}{then}
364 \textcolor{comment}{!$OMP parallel do default(none) shared(is,ie,js,je,CS,nz,G,dt,Isecs\_per\_year,m)}
365     \textcolor{keywordflow}{do} k=cs%nkml+1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
366       cs%tr(i,j,k,m) = cs%tr(i,j,k,m) + g%mask2dT(i,j)*dt*isecs\_per\_year
367 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
368 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}
369 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceideal__age__example_aea477e25ddf0fdc4f05fd45a102eb7c0}\label{namespaceideal__age__example_aea477e25ddf0fdc4f05fd45a102eb7c0}} 
\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}!ideal\+\_\+age\+\_\+tracer\+\_\+surface\+\_\+state@{ideal\+\_\+age\+\_\+tracer\+\_\+surface\+\_\+state}}
\index{ideal\+\_\+age\+\_\+tracer\+\_\+surface\+\_\+state@{ideal\+\_\+age\+\_\+tracer\+\_\+surface\+\_\+state}!ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}
\subsubsection{\texorpdfstring{ideal\+\_\+age\+\_\+tracer\+\_\+surface\+\_\+state()}{ideal\_age\_tracer\_surface\_state()}}
{\footnotesize\ttfamily subroutine, public ideal\+\_\+age\+\_\+example\+::ideal\+\_\+age\+\_\+tracer\+\_\+surface\+\_\+state (\begin{DoxyParamCaption}\item[{type(surface), intent(inout)}]{sfc\+\_\+state,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+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. This particular tracer package does not report anything back to the coupler. 


\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 thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
 & {\em cs} & The control structure returned by a previous call to register\+\_\+ideal\+\_\+age\+\_\+tracer. \\
\hline
\end{DoxyParams}


Definition at line 424 of file ideal\+\_\+age\+\_\+example.\+F90.


\begin{DoxyCode}
424   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}
425   \textcolor{keywordtype}{type}(surface),          \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{ !< A structure containing fields that}
426 \textcolor{comment}{                                              !! describe the surface state of the ocean.}
427   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
428                           \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2].}
429   \textcolor{keywordtype}{type}(ideal\_age\_tracer\_CS), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure returned by a previous}
430 \textcolor{comment}{                                              !! call to register\_ideal\_age\_tracer.}
431 
432   \textcolor{comment}{! This particular tracer package does not report anything back to the coupler.}
433   \textcolor{comment}{! The code that is here is just a rough guide for packages that would.}
434 
435   \textcolor{keywordtype}{integer} :: m, is, ie, js, je, isd, ied, jsd, jed
436   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
437   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
438 
439   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
440 
441   \textcolor{keywordflow}{if} (cs%coupled\_tracers) \textcolor{keywordflow}{then}
442     \textcolor{keywordflow}{do} m=1,cs%ntr
443       \textcolor{comment}{!   This call loads the surface values into the appropriate array in the}
444       \textcolor{comment}{! coupler-type structure.}
445       \textcolor{keyword}{call }coupler\_type\_set\_data(cs%tr(:,:,1,m), cs%ind\_tr(m), ind\_csurf, &
446                    sfc\_state%tr\_fields, idim=(/isd, is, ie, ied/), &
447                    jdim=(/jsd, js, je, jed/) )
448 \textcolor{keywordflow}{    enddo}
449 \textcolor{keywordflow}{  endif}
450 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceideal__age__example_ae8c12d0128c24a491f7af62d4dd6ec5d}\label{namespaceideal__age__example_ae8c12d0128c24a491f7af62d4dd6ec5d}} 
\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}!initialize\+\_\+ideal\+\_\+age\+\_\+tracer@{initialize\+\_\+ideal\+\_\+age\+\_\+tracer}}
\index{initialize\+\_\+ideal\+\_\+age\+\_\+tracer@{initialize\+\_\+ideal\+\_\+age\+\_\+tracer}!ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}
\subsubsection{\texorpdfstring{initialize\+\_\+ideal\+\_\+age\+\_\+tracer()}{initialize\_ideal\_age\_tracer()}}
{\footnotesize\ttfamily subroutine, public ideal\+\_\+age\+\_\+example\+::initialize\+\_\+ideal\+\_\+age\+\_\+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[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(diag\+\_\+ctrl), intent(in), target}]{diag,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{type(\mbox{\hyperlink{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+cs}}), pointer}]{CS,  }\item[{type(sponge\+\_\+cs), pointer}]{sponge\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



Sets the ideal age traces to their initial values and 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 us} & A dimensional unit scaling type\\
\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 register\+\_\+ideal\+\_\+age\+\_\+tracer.\\
\hline
 & {\em sponge\+\_\+csp} & Pointer to the control structure for the sponges. \\
\hline
\end{DoxyParams}


Definition at line 198 of file ideal\+\_\+age\+\_\+example.\+F90.


\begin{DoxyCode}
198   \textcolor{keywordtype}{logical},                            \textcolor{keywordtype}{intent(in)} :: restart\textcolor{comment}{ !< .true. if the fields have already}
199 \textcolor{comment}{                                                         !! been read from a restart file.}
200   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: day\textcolor{comment}{  !< Time of the start of the run.}
201   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}
202   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
203   \textcolor{keywordtype}{type}(unit\_scale\_type),              \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
204   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
205                                       \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
206   \textcolor{keywordtype}{type}(diag\_ctrl),            \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{ !< A structure that is used to regulate}
207 \textcolor{comment}{                                                         !! diagnostic output.}
208   \textcolor{keywordtype}{type}(ocean\_OBC\_type),               \textcolor{keywordtype}{pointer}    :: OBC\textcolor{comment}{  !< This open boundary condition type specifies}
209 \textcolor{comment}{                                                         !! whether, where, and what open boundary}
210 \textcolor{comment}{                                                         !! conditions are used.}
211   \textcolor{keywordtype}{type}(ideal\_age\_tracer\_CS),          \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure returned by a previous}
212 \textcolor{comment}{                                                       !! call to register\_ideal\_age\_tracer.}
213   \textcolor{keywordtype}{type}(sponge\_CS),                    \textcolor{keywordtype}{pointer}    :: sponge\_CSp\textcolor{comment}{ !< Pointer to the control structure for the
       sponges.}
214 
215 \textcolor{comment}{!   This subroutine initializes the CS%ntr tracer fields in tr(:,:,:,:)}
216 \textcolor{comment}{! and it sets up the tracer output.}
217 
218   \textcolor{comment}{! Local variables}
219   \textcolor{keywordtype}{character(len=24)} :: name     \textcolor{comment}{! A variable's name in a NetCDF file.}
220   \textcolor{keywordtype}{character(len=72)} :: longname \textcolor{comment}{! The long name of that variable.}
221   \textcolor{keywordtype}{character(len=48)} :: units    \textcolor{comment}{! The dimensions of the variable.}
222   \textcolor{keywordtype}{character(len=48)} :: flux\_units \textcolor{comment}{! The units for age tracer fluxes, either}
223                                 \textcolor{comment}{! years m3 s-1 or years kg s-1.}
224   \textcolor{keywordtype}{character(len=72)} :: cmorname \textcolor{comment}{! The CMOR name of that variable.}
225   \textcolor{keywordtype}{logical} :: OK
226   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz, m
227   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
228 
229   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
230   \textcolor{keywordflow}{if} (cs%ntr < 1) \textcolor{keywordflow}{return}
231   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
232   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
233   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
234 
235   cs%Time => day
236   cs%diag => diag
237   cs%nkml = max(gv%nkml,1)
238 
239   \textcolor{keywordflow}{do} m=1,cs%ntr
240     \textcolor{keyword}{call }query\_vardesc(cs%tr\_desc(m), name=name, &
241                        caller=\textcolor{stringliteral}{"initialize\_ideal\_age\_tracer"})
242     \textcolor{keywordflow}{if} ((.not.restart) .or. (cs%tracers\_may\_reinit .and. .not. &
243         query\_initialized(cs%tr(:,:,:,m), name, cs%restart\_CSp))) \textcolor{keywordflow}{then}
244 
245       \textcolor{keywordflow}{if} (len\_trim(cs%IC\_file) > 0) \textcolor{keywordflow}{then}
246   \textcolor{comment}{!  Read the tracer concentrations from a netcdf file.}
247         \textcolor{keywordflow}{if} (.not.file\_exists(cs%IC\_file, g%Domain)) &
248           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"initialize\_ideal\_age\_tracer: "}// &
249                                  \textcolor{stringliteral}{"Unable to open "}//cs%IC\_file)
250 
251         \textcolor{keywordflow}{if} (cs%Z\_IC\_file) \textcolor{keywordflow}{then}
252           ok = tracer\_z\_init(cs%tr(:,:,:,m), h, cs%IC\_file, name,&
253                              g, us, -1e34, 0.0) \textcolor{comment}{! CS%land\_val(m))}
254           \textcolor{keywordflow}{if} (.not.ok) \textcolor{keywordflow}{then}
255             ok = tracer\_z\_init(cs%tr(:,:,:,m), h, cs%IC\_file, &
256                      trim(name), g, us, -1e34, 0.0) \textcolor{comment}{! CS%land\_val(m))}
257             \textcolor{keywordflow}{if} (.not.ok) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"initialize\_ideal\_age\_tracer: "}//&
258                     \textcolor{stringliteral}{"Unable to read "}//trim(name)//\textcolor{stringliteral}{" from "}//&
259                     trim(cs%IC\_file)//\textcolor{stringliteral}{"."})
260 \textcolor{keywordflow}{          endif}
261         \textcolor{keywordflow}{else}
262           \textcolor{keyword}{call }mom\_read\_data(cs%IC\_file, trim(name), cs%tr(:,:,:,m), g%Domain)
263 \textcolor{keywordflow}{        endif}
264       \textcolor{keywordflow}{else}
265         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
266           \textcolor{keywordflow}{if} (g%mask2dT(i,j) < 0.5) \textcolor{keywordflow}{then}
267             cs%tr(i,j,k,m) = cs%land\_val(m)
268           \textcolor{keywordflow}{else}
269             cs%tr(i,j,k,m) = cs%IC\_val(m)
270 \textcolor{keywordflow}{          endif}
271 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
272 \textcolor{keywordflow}{      endif}
273 
274 \textcolor{keywordflow}{    endif} \textcolor{comment}{! restart}
275 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! Tracer loop}
276 
277   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
278   \textcolor{comment}{! Steal from updated DOME in the fullness of time.}
279 \textcolor{keywordflow}{  endif}
280 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceideal__age__example_a58d550a02148b87b1d1ce979fcaf6c00}\label{namespaceideal__age__example_a58d550a02148b87b1d1ce979fcaf6c00}} 
\index{ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}!register\+\_\+ideal\+\_\+age\+\_\+tracer@{register\+\_\+ideal\+\_\+age\+\_\+tracer}}
\index{register\+\_\+ideal\+\_\+age\+\_\+tracer@{register\+\_\+ideal\+\_\+age\+\_\+tracer}!ideal\+\_\+age\+\_\+example@{ideal\+\_\+age\+\_\+example}}
\subsubsection{\texorpdfstring{register\+\_\+ideal\+\_\+age\+\_\+tracer()}{register\_ideal\_age\_tracer()}}
{\footnotesize\ttfamily logical function, public ideal\+\_\+age\+\_\+example\+::register\+\_\+ideal\+\_\+age\+\_\+tracer (\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{structideal__age__example_1_1ideal__age__tracer__cs}{ideal\+\_\+age\+\_\+tracer\+\_\+cs}}), pointer}]{CS,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{tr\+\_\+\+Reg,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Register the ideal age tracer fields 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} & The control structure returned by a previous call to register\+\_\+ideal\+\_\+age\+\_\+tracer.\\
\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 73 of file ideal\+\_\+age\+\_\+example.\+F90.


\begin{DoxyCode}
73   \textcolor{keywordtype}{type}(hor\_index\_type),       \textcolor{keywordtype}{intent(in)} :: HI\textcolor{comment}{   !< A horizontal index type structure}
74   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
75   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}
76   \textcolor{keywordtype}{type}(ideal\_age\_tracer\_CS),  \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure returned by a previous}
77 \textcolor{comment}{                                               !! call to register\_ideal\_age\_tracer.}
78   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}    :: tr\_Reg\textcolor{comment}{ !< A pointer that is set to point to the control}
79 \textcolor{comment}{                                                  !! structure for the tracer advection and}
80 \textcolor{comment}{                                                  !! diffusion module}
81   \textcolor{keywordtype}{type}(MOM\_restart\_CS),       \textcolor{keywordtype}{pointer}    :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}
82 
83 \textcolor{comment}{! This include declares and sets the variable "version".}
84 \textcolor{preprocessor}{#include "version\_variable.h"}
85 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"ideal\_age\_example"} \textcolor{comment}{! This module's name.}
86   \textcolor{keywordtype}{character(len=200)} :: inputdir \textcolor{comment}{! The directory where the input files are.}
87   \textcolor{keywordtype}{character(len=48)}  :: var\_name \textcolor{comment}{! The variable's name.}
88   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{pointer} :: tr\_ptr(:,:,:) => null()
89   \textcolor{keywordtype}{logical} :: register\_ideal\_age\_tracer
90   \textcolor{keywordtype}{logical} :: do\_ideal\_age, do\_vintage, do\_ideal\_age\_dated
91   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, nz, m
92   isd = hi%isd ; ied = hi%ied ; jsd = hi%jsd ; jed = hi%jed ; nz = gv%ke
93 
94   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
95     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"register\_ideal\_age\_tracer called with an "}// &
96                              \textcolor{stringliteral}{"associated control structure."})
97     \textcolor{keywordflow}{return}
98 \textcolor{keywordflow}{  endif}
99   \textcolor{keyword}{allocate}(cs)
100 
101   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
102   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
103   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DO\_IDEAL\_AGE"}, do\_ideal\_age, &
104                  \textcolor{stringliteral}{"If true, use an ideal age tracer that is set to 0 age "}//&
105                  \textcolor{stringliteral}{"in the mixed layer and ages at unit rate in the interior."}, &
106                  default=.true.)
107   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DO\_IDEAL\_VINTAGE"}, do\_vintage, &
108                  \textcolor{stringliteral}{"If true, use an ideal vintage tracer that is set to an "}//&
109                  \textcolor{stringliteral}{"exponentially increasing value in the mixed layer and "}//&
110                  \textcolor{stringliteral}{"is conserved thereafter."}, default=.false.)
111   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DO\_IDEAL\_AGE\_DATED"}, do\_ideal\_age\_dated, &
112                  \textcolor{stringliteral}{"If true, use an ideal age tracer that is everywhere 0 "}//&
113                  \textcolor{stringliteral}{"before IDEAL\_AGE\_DATED\_START\_YEAR, but the behaves like "}//&
114                  \textcolor{stringliteral}{"the standard ideal age tracer - i.e. is set to 0 age in "}//&
115                  \textcolor{stringliteral}{"the mixed layer and ages at unit rate in the interior."}, &
116                  default=.false.)
117 
118 
119   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"AGE\_IC\_FILE"}, cs%IC\_file, &
120                  \textcolor{stringliteral}{"The file in which the age-tracer initial values can be "}//&
121                  \textcolor{stringliteral}{"found, or an empty string for internal initialization."}, &
122                  default=\textcolor{stringliteral}{" "})
123   \textcolor{keywordflow}{if} ((len\_trim(cs%IC\_file) > 0) .and. (scan(cs%IC\_file,\textcolor{stringliteral}{'/'}) == 0)) \textcolor{keywordflow}{then}
124     \textcolor{comment}{! Add the directory if CS%IC\_file is not already a complete path.}
125     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
126     cs%IC\_file = trim(slasher(inputdir))//trim(cs%IC\_file)
127     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/AGE\_IC\_FILE"}, cs%IC\_file)
128 \textcolor{keywordflow}{  endif}
129   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"AGE\_IC\_FILE\_IS\_Z"}, cs%Z\_IC\_file, &
130                  \textcolor{stringliteral}{"If true, AGE\_IC\_FILE is in depth space, not layer space"}, &
131                  default=.false.)
132   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TRACERS\_MAY\_REINIT"}, cs%tracers\_may\_reinit, &
133                  \textcolor{stringliteral}{"If true, tracers may go through the initialization code "}//&
134                  \textcolor{stringliteral}{"if they are not found in the restart files.  Otherwise "}//&
135                  \textcolor{stringliteral}{"it is a fatal error if the tracers are not found in the "}//&
136                  \textcolor{stringliteral}{"restart files of a restarted run."}, default=.false.)
137 
138   cs%ntr = 0
139   \textcolor{keywordflow}{if} (do\_ideal\_age) \textcolor{keywordflow}{then}
140     cs%ntr = cs%ntr + 1 ; m = cs%ntr
141     cs%tr\_desc(m) = var\_desc(\textcolor{stringliteral}{"age"}, \textcolor{stringliteral}{"yr"}, \textcolor{stringliteral}{"Ideal Age Tracer"}, cmor\_field\_name=\textcolor{stringliteral}{"agessc"}, caller=mdl)
142     cs%tracer\_ages(m) = .true. ; cs%sfc\_growth\_rate(m) = 0.0
143     cs%IC\_val(m) = 0.0 ; cs%young\_val(m) = 0.0 ; cs%tracer\_start\_year(m) = 0.0
144 \textcolor{keywordflow}{  endif}
145 
146   \textcolor{keywordflow}{if} (do\_vintage) \textcolor{keywordflow}{then}
147     cs%ntr = cs%ntr + 1 ; m = cs%ntr
148     cs%tr\_desc(m) = var\_desc(\textcolor{stringliteral}{"vintage"}, \textcolor{stringliteral}{"yr"}, \textcolor{stringliteral}{"Exponential Vintage Tracer"}, &
149                             caller=mdl)
150     cs%tracer\_ages(m) = .false. ; cs%sfc\_growth\_rate(m) = 1.0/30.0
151     cs%IC\_val(m) = 0.0 ; cs%young\_val(m) = 1e-20 ; cs%tracer\_start\_year(m) = 0.0
152     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"IDEAL\_VINTAGE\_START\_YEAR"}, cs%tracer\_start\_year(m), &
153                  \textcolor{stringliteral}{"The date at which the ideal vintage tracer starts."}, &
154                  units=\textcolor{stringliteral}{"years"}, default=0.0)
155 \textcolor{keywordflow}{  endif}
156 
157   \textcolor{keywordflow}{if} (do\_ideal\_age\_dated) \textcolor{keywordflow}{then}
158     cs%ntr = cs%ntr + 1 ; m = cs%ntr
159     cs%tr\_desc(m) = var\_desc(\textcolor{stringliteral}{"age\_dated"},\textcolor{stringliteral}{"yr"},\textcolor{stringliteral}{"Ideal Age Tracer with a Start Date"},&
160                             caller=mdl)
161     cs%tracer\_ages(m) = .true. ; cs%sfc\_growth\_rate(m) = 0.0
162     cs%IC\_val(m) = 0.0 ; cs%young\_val(m) = 0.0 ; cs%tracer\_start\_year(m) = 0.0
163     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"IDEAL\_AGE\_DATED\_START\_YEAR"}, cs%tracer\_start\_year(m), &
164                  \textcolor{stringliteral}{"The date at which the dated ideal age tracer starts."}, &
165                  units=\textcolor{stringliteral}{"years"}, default=0.0)
166 \textcolor{keywordflow}{  endif}
167 
168   \textcolor{keyword}{allocate}(cs%tr(isd:ied,jsd:jed,nz,cs%ntr)) ; cs%tr(:,:,:,:) = 0.0
169 
170   \textcolor{keywordflow}{do} m=1,cs%ntr
171     \textcolor{comment}{! This is needed to force the compiler not to do a copy in the registration}
172     \textcolor{comment}{! calls.  Curses on the designers and implementers of Fortran90.}
173     tr\_ptr => cs%tr(:,:,:,m)
174     \textcolor{keyword}{call }query\_vardesc(cs%tr\_desc(m), name=var\_name, &
175                        caller=\textcolor{stringliteral}{"register\_ideal\_age\_tracer"})
176     \textcolor{comment}{! Register the tracer for horizontal advection, diffusion, and restarts.}
177     \textcolor{keyword}{call }register\_tracer(tr\_ptr, tr\_reg, param\_file, hi, gv, tr\_desc=cs%tr\_desc(m), &
178                          registry\_diags=.true., restart\_cs=restart\_cs, &
179                          mandatory=.not.cs%tracers\_may\_reinit, &
180                          flux\_scale=gv%H\_to\_m)
181 
182     \textcolor{comment}{!   Set coupled\_tracers to be true (hard-coded above) to provide the surface}
183     \textcolor{comment}{! values to the coupler (if any).  This is meta-code and its arguments will}
184     \textcolor{comment}{! currently (deliberately) give fatal errors if it is used.}
185     \textcolor{keywordflow}{if} (cs%coupled\_tracers) &
186       cs%ind\_tr(m) = aof\_set\_coupler\_flux(trim(var\_name)//\textcolor{stringliteral}{'\_flux'}, &
187           flux\_type=\textcolor{stringliteral}{' '}, implementation=\textcolor{stringliteral}{' '}, caller=\textcolor{stringliteral}{"register\_ideal\_age\_tracer"})
188 \textcolor{keywordflow}{  enddo}
189 
190   cs%tr\_Reg => tr\_reg
191   cs%restart\_CSp => restart\_cs
192   register\_ideal\_age\_tracer = .true.
\end{DoxyCode}
