\hypertarget{namespaceoil__tracer}{}\section{oil\+\_\+tracer Module Reference}
\label{namespaceoil__tracer}\index{oil\+\_\+tracer@{oil\+\_\+tracer}}


\subsection{Detailed Description}
A tracer package to mimic dissolved oil. 

By Alistair Adcroft and Robert Hallberg, 2010 $\ast$.

In the midst of the Deepwater Horizon oil spill, it became evident that models were needed to predict the long-\/term fate of dissolved oil in the open ocean. This tracer packages mimics the transport, dilution and decay of dissolved oil plumes in the ocean.

This tracer package was central to the simulations used by Adcroft et al., G\+RL 2010, to prove that the Deepwater Horizon spill was an important regional event, with implications for dissolved oxygen levels in the Gulf of Mexico, but not one that would directly impact the East Coast of the U.\+S. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+tracer\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the oil tracer package. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespaceoil__tracer_a3aceaf614d8651772124719e32879e23}{register\+\_\+oil\+\_\+tracer}} (HI, GV, US, param\+\_\+file, CS, tr\+\_\+\+Reg, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Register oil tracer fields and subroutines to be used with M\+OM. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceoil__tracer_a3cb362789ef0ea593f8b7de22016a92e}{initialize\+\_\+oil\+\_\+tracer}} (restart, day, G, GV, US, h, diag, O\+BC, CS, sponge\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Initialize the oil tracers and set up tracer output. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceoil__tracer_a2e5cd83c5d5a92a7774d7e6bda53c646}{oil\+\_\+tracer\+\_\+column\+\_\+physics}} (h\+\_\+old, h\+\_\+new, ea, eb, fluxes, dt, G, GV, US, CS, tv, evap\+\_\+\+C\+F\+L\+\_\+limit, minimum\+\_\+forcing\+\_\+depth)
\begin{DoxyCompactList}\small\item\em Apply sources, sinks, diapycnal mixing and rising motions to the oil tracers. \end{DoxyCompactList}\item 
integer function, public \mbox{\hyperlink{namespaceoil__tracer_ac8964b16549dba8fc850e4af15af8029}{oil\+\_\+stock}} (h, stocks, G, GV, CS, names, units, stock\+\_\+index)
\begin{DoxyCompactList}\small\item\em Calculate the mass-\/weighted integral of the oil 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{namespaceoil__tracer_a08f2426138c293029ea1d58b2119c3ce}{oil\+\_\+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{namespaceoil__tracer_a428f70692e0f8a537b73e24ada1e5357}{oil\+\_\+tracer\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Deallocate memory associated with this tracer package. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespaceoil__tracer_a7d9cefa818e16dd56e1051c3bcff940f}\label{namespaceoil__tracer_a7d9cefa818e16dd56e1051c3bcff940f}} 
integer, parameter \mbox{\hyperlink{namespaceoil__tracer_a7d9cefa818e16dd56e1051c3bcff940f}{ntr\+\_\+max}} = 20
\begin{DoxyCompactList}\small\item\em the maximum number of tracers in this module. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespaceoil__tracer_a3cb362789ef0ea593f8b7de22016a92e}\label{namespaceoil__tracer_a3cb362789ef0ea593f8b7de22016a92e}} 
\index{oil\+\_\+tracer@{oil\+\_\+tracer}!initialize\+\_\+oil\+\_\+tracer@{initialize\+\_\+oil\+\_\+tracer}}
\index{initialize\+\_\+oil\+\_\+tracer@{initialize\+\_\+oil\+\_\+tracer}!oil\+\_\+tracer@{oil\+\_\+tracer}}
\subsubsection{\texorpdfstring{initialize\+\_\+oil\+\_\+tracer()}{initialize\_oil\_tracer()}}
{\footnotesize\ttfamily subroutine, public oil\+\_\+tracer\+::initialize\+\_\+oil\+\_\+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{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+tracer\+\_\+cs}}), pointer}]{CS,  }\item[{type(sponge\+\_\+cs), pointer}]{sponge\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



Initialize the oil tracers and set up 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\+\_\+oil\+\_\+tracer.\\
\hline
 & {\em sponge\+\_\+csp} & Pointer to the control structure for the sponges. \\
\hline
\end{DoxyParams}


Definition at line 206 of file oil\+\_\+tracer.\+F90.


\begin{DoxyCode}
206   \textcolor{keywordtype}{logical},                            \textcolor{keywordtype}{intent(in)} :: restart\textcolor{comment}{ !< .true. if the fields have already}
207 \textcolor{comment}{                                                         !! been read from a restart file.}
208   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: day\textcolor{comment}{  !< Time of the start of the run.}
209   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}
210   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
211   \textcolor{keywordtype}{type}(unit\_scale\_type),              \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
212   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
213                                       \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
214   \textcolor{keywordtype}{type}(diag\_ctrl),            \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{ !< A structure that is used to regulate}
215 \textcolor{comment}{                                                         !! diagnostic output.}
216   \textcolor{keywordtype}{type}(ocean\_OBC\_type),               \textcolor{keywordtype}{pointer}    :: OBC\textcolor{comment}{  !< This open boundary condition type specifies}
217 \textcolor{comment}{                                                         !! whether, where, and what open boundary}
218 \textcolor{comment}{                                                         !! conditions are used.}
219   \textcolor{keywordtype}{type}(oil\_tracer\_CS),                \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure returned by a previous}
220 \textcolor{comment}{                                                       !! call to register\_oil\_tracer.}
221   \textcolor{keywordtype}{type}(sponge\_CS),                    \textcolor{keywordtype}{pointer}    :: sponge\_CSp\textcolor{comment}{ !< Pointer to the control structure for the
       sponges.}
222 
223   \textcolor{comment}{! Local variables}
224   \textcolor{keywordtype}{character(len=16)} :: name     \textcolor{comment}{! A variable's name in a NetCDF file.}
225   \textcolor{keywordtype}{character(len=72)} :: longname \textcolor{comment}{! The long name of that variable.}
226   \textcolor{keywordtype}{character(len=48)} :: units    \textcolor{comment}{! The dimensions of the variable.}
227   \textcolor{keywordtype}{character(len=48)} :: flux\_units \textcolor{comment}{! The units for age tracer fluxes, either}
228                                 \textcolor{comment}{! years m3 s-1 or years kg s-1.}
229   \textcolor{keywordtype}{logical} :: OK
230   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz, m
231   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
232 
233   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
234   \textcolor{keywordflow}{if} (cs%ntr < 1) \textcolor{keywordflow}{return}
235   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
236   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
237   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
238 
239   \textcolor{comment}{! Establish location of source}
240   \textcolor{keywordflow}{do} j=g%jsdB+1,g%jed ; \textcolor{keywordflow}{do} i=g%isdB+1,g%ied
241     \textcolor{comment}{! This test for i,j index is specific to a lat/lon (non-rotated grid).}
242     \textcolor{comment}{! and needs to be generalized to work properly on the tri-polar grid.}
243     \textcolor{keywordflow}{if} (cs%oil\_source\_longitude<g%geoLonBu(i,j) .and. &
244         cs%oil\_source\_longitude>=g%geoLonBu(i-1,j) .and. &
245         cs%oil\_source\_latitude<g%geoLatBu(i,j) .and. &
246         cs%oil\_source\_latitude>=g%geoLatBu(i,j-1) ) \textcolor{keywordflow}{then}
247       cs%oil\_source\_i=i
248       cs%oil\_source\_j=j
249 \textcolor{keywordflow}{    endif}
250 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
251 
252   cs%Time => day
253   cs%diag => diag
254 
255   \textcolor{keywordflow}{do} m=1,cs%ntr
256     \textcolor{keyword}{call }query\_vardesc(cs%tr\_desc(m), name=name, caller=\textcolor{stringliteral}{"initialize\_oil\_tracer"})
257     \textcolor{keywordflow}{if} ((.not.restart) .or. (cs%oil\_may\_reinit .and. .not. &
258         query\_initialized(cs%tr(:,:,:,m), name, cs%restart\_CSp))) \textcolor{keywordflow}{then}
259 
260       \textcolor{keywordflow}{if} (len\_trim(cs%IC\_file) > 0) \textcolor{keywordflow}{then}
261   \textcolor{comment}{!  Read the tracer concentrations from a netcdf file.}
262         \textcolor{keywordflow}{if} (.not.file\_exists(cs%IC\_file, g%Domain)) &
263           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"initialize\_oil\_tracer: "}// &
264                                  \textcolor{stringliteral}{"Unable to open "}//cs%IC\_file)
265 
266         \textcolor{keywordflow}{if} (cs%Z\_IC\_file) \textcolor{keywordflow}{then}
267           ok = tracer\_z\_init(cs%tr(:,:,:,m), h, cs%IC\_file, name, &
268                              g, us, -1e34, 0.0) \textcolor{comment}{! CS%land\_val(m))}
269           \textcolor{keywordflow}{if} (.not.ok) \textcolor{keywordflow}{then}
270             ok = tracer\_z\_init(cs%tr(:,:,:,m), h, cs%IC\_file, &
271                      trim(name), g, us, -1e34, 0.0) \textcolor{comment}{! CS%land\_val(m))}
272             \textcolor{keywordflow}{if} (.not.ok) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"initialize\_oil\_tracer: "}//&
273                     \textcolor{stringliteral}{"Unable to read "}//trim(name)//\textcolor{stringliteral}{" from "}//&
274                     trim(cs%IC\_file)//\textcolor{stringliteral}{"."})
275 \textcolor{keywordflow}{          endif}
276         \textcolor{keywordflow}{else}
277           \textcolor{keyword}{call }mom\_read\_data(cs%IC\_file, trim(name), cs%tr(:,:,:,m), g%Domain)
278 \textcolor{keywordflow}{        endif}
279       \textcolor{keywordflow}{else}
280         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
281           \textcolor{keywordflow}{if} (g%mask2dT(i,j) < 0.5) \textcolor{keywordflow}{then}
282             cs%tr(i,j,k,m) = cs%land\_val(m)
283           \textcolor{keywordflow}{else}
284             cs%tr(i,j,k,m) = cs%IC\_val(m)
285 \textcolor{keywordflow}{          endif}
286 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
287 \textcolor{keywordflow}{      endif}
288 
289 \textcolor{keywordflow}{    endif} \textcolor{comment}{! restart}
290 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! Tracer loop}
291 
292   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
293   \textcolor{comment}{! Put something here...}
294 \textcolor{keywordflow}{  endif}
295 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceoil__tracer_ac8964b16549dba8fc850e4af15af8029}\label{namespaceoil__tracer_ac8964b16549dba8fc850e4af15af8029}} 
\index{oil\+\_\+tracer@{oil\+\_\+tracer}!oil\+\_\+stock@{oil\+\_\+stock}}
\index{oil\+\_\+stock@{oil\+\_\+stock}!oil\+\_\+tracer@{oil\+\_\+tracer}}
\subsubsection{\texorpdfstring{oil\+\_\+stock()}{oil\_stock()}}
{\footnotesize\ttfamily integer function, public oil\+\_\+tracer\+::oil\+\_\+stock (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), 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{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+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})}



Calculate the mass-\/weighted integral of the oil 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\+\_\+oil\+\_\+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 408 of file oil\+\_\+tracer.\+F90.


\begin{DoxyCode}
408   \textcolor{keywordtype}{type}(ocean\_grid\_type),              \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}
409   \textcolor{keywordtype}{type}(verticalGrid\_type),            \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
410   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
411   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},                 \textcolor{keywordtype}{intent(out)}   :: stocks\textcolor{comment}{ !< the mass-weighted integrated amount of
       each}
412 \textcolor{comment}{                                                              !! tracer, in kg times concentration units
       [kg conc].}
413   \textcolor{keywordtype}{type}(oil\_tracer\_CS),                \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< The control structure returned by a previous}
414 \textcolor{comment}{                                                            !! call to register\_oil\_tracer.}
415   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},     \textcolor{keywordtype}{intent(out)}   :: names\textcolor{comment}{  !< the names of the stocks calculated.}
416   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},     \textcolor{keywordtype}{intent(out)}   :: units\textcolor{comment}{  !< the units of the stocks calculated.}
417   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional},                  \textcolor{keywordtype}{intent(in)}    :: stock\_index\textcolor{comment}{ !< the coded index of a specific stock}
418 \textcolor{comment}{                                                                   !! being sought.}
419   \textcolor{keywordtype}{integer}                                           :: oil\_stock\textcolor{comment}{ !< The number of stocks calculated here.}
420 
421 \textcolor{comment}{! This function calculates the mass-weighted integral of all tracer stocks,}
422 \textcolor{comment}{! returning the number of stocks it has calculated.  If the stock\_index}
423 \textcolor{comment}{! is present, only the stock corresponding to that coded index is returned.}
424 
425   \textcolor{comment}{! Local variables}
426   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, m
427   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
428 
429   oil\_stock = 0
430   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
431   \textcolor{keywordflow}{if} (cs%ntr < 1) \textcolor{keywordflow}{return}
432 
433   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stock\_index)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (stock\_index > 0) \textcolor{keywordflow}{then}
434     \textcolor{comment}{! Check whether this stock is available from this routine.}
435 
436     \textcolor{comment}{! No stocks from this routine are being checked yet.  Return 0.}
437     \textcolor{keywordflow}{return}
438 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
439 
440   \textcolor{keywordflow}{do} m=1,cs%ntr
441     \textcolor{keyword}{call }query\_vardesc(cs%tr\_desc(m), name=names(m), units=units(m), caller=\textcolor{stringliteral}{"oil\_stock"})
442     units(m) = trim(units(m))//\textcolor{stringliteral}{" kg"}
443     stocks(m) = 0.0
444     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
445       stocks(m) = stocks(m) + cs%tr(i,j,k,m) * &
446                              (g%mask2dT(i,j) * g%US%L\_to\_m**2*g%areaT(i,j) * h(i,j,k))
447 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
448     stocks(m) = gv%H\_to\_kg\_m2 * stocks(m)
449 \textcolor{keywordflow}{  enddo}
450   oil\_stock = cs%ntr
451 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceoil__tracer_a2e5cd83c5d5a92a7774d7e6bda53c646}\label{namespaceoil__tracer_a2e5cd83c5d5a92a7774d7e6bda53c646}} 
\index{oil\+\_\+tracer@{oil\+\_\+tracer}!oil\+\_\+tracer\+\_\+column\+\_\+physics@{oil\+\_\+tracer\+\_\+column\+\_\+physics}}
\index{oil\+\_\+tracer\+\_\+column\+\_\+physics@{oil\+\_\+tracer\+\_\+column\+\_\+physics}!oil\+\_\+tracer@{oil\+\_\+tracer}}
\subsubsection{\texorpdfstring{oil\+\_\+tracer\+\_\+column\+\_\+physics()}{oil\_tracer\_column\_physics()}}
{\footnotesize\ttfamily subroutine, public oil\+\_\+tracer\+::oil\+\_\+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{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+tracer\+\_\+cs}}), pointer}]{CS,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, intent(in), optional}]{evap\+\_\+\+C\+F\+L\+\_\+limit,  }\item[{real, intent(in), optional}]{minimum\+\_\+forcing\+\_\+depth }\end{DoxyParamCaption})}



Apply sources, sinks, diapycnal mixing and rising motions to the oil 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\+\_\+oil\+\_\+tracer.\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables\\
\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 301 of file oil\+\_\+tracer.\+F90.


\begin{DoxyCode}
301   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}
302   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
303   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
304                            \textcolor{keywordtype}{intent(in)} :: h\_old\textcolor{comment}{ !< Layer thickness before entrainment [H ~> m or kg m-2].}
305   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
306                            \textcolor{keywordtype}{intent(in)} :: h\_new\textcolor{comment}{ !< Layer thickness after entrainment [H ~> m or kg m-2].}
307   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
308                            \textcolor{keywordtype}{intent(in)} :: ea\textcolor{comment}{   !< an array to which the amount of fluid entrained}
309 \textcolor{comment}{                                              !! from the layer above during this call will be}
310 \textcolor{comment}{                                              !! added [H ~> m or kg m-2].}
311   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
312                            \textcolor{keywordtype}{intent(in)} :: eb\textcolor{comment}{   !< an array to which the amount of fluid entrained}
313 \textcolor{comment}{                                              !! from the layer below during this call will be}
314 \textcolor{comment}{                                              !! added [H ~> m or kg m-2].}
315   \textcolor{keywordtype}{type}(forcing),           \textcolor{keywordtype}{intent(in)} :: fluxes\textcolor{comment}{ !< A structure containing pointers to thermodynamic}
316 \textcolor{comment}{                                              !! and tracer forcing fields.  Unused fields have NULL ptrs.}
317   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)} :: dt\textcolor{comment}{   !< The amount of time covered by this call [T ~> s]}
318   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
319   \textcolor{keywordtype}{type}(oil\_tracer\_CS),     \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< The control structure returned by a previous}
320 \textcolor{comment}{                                              !! call to register\_oil\_tracer.}
321   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic variables}
322   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: evap\_CFL\_limit\textcolor{comment}{ !< Limit on the fraction of the water that can}
323 \textcolor{comment}{                                              !! be fluxed out of the top layer in a timestep [nondim]}
324   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: minimum\_forcing\_depth\textcolor{comment}{ !< The smallest depth over which}
325 \textcolor{comment}{                                              !! fluxes can be applied [H ~> m or kg m-2]}
326 \textcolor{comment}{!   This subroutine applies diapycnal diffusion and any other column}
327 \textcolor{comment}{! tracer physics or chemistry to the tracers from this file.}
328 \textcolor{comment}{! This is a simple example of a set of advected passive tracers.}
329 
330 \textcolor{comment}{! The arguments to this subroutine are redundant in that}
331 \textcolor{comment}{!     h\_new(k) = h\_old(k) + ea(k) - eb(k-1) + eb(k) - ea(k+1)}
332 
333   \textcolor{comment}{! Local variables}
334   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: h\_work \textcolor{comment}{! Used so that h can be modified}
335   \textcolor{keywordtype}{real} :: Isecs\_per\_year = 1.0 / (365.0*86400.0)
336   \textcolor{keywordtype}{real} :: year, h\_total, ldecay
337   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, m, k\_max
338   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
339 
340   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
341   \textcolor{keywordflow}{if} (cs%ntr < 1) \textcolor{keywordflow}{return}
342 
343   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(evap\_cfl\_limit) .and. \textcolor{keyword}{present}(minimum\_forcing\_depth)) \textcolor{keywordflow}{then}
344     \textcolor{keywordflow}{do} m=1,cs%ntr
345       \textcolor{keywordflow}{do} k=1,nz ;\textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
346         h\_work(i,j,k) = h\_old(i,j,k)
347 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
348       \textcolor{keyword}{call }applytracerboundaryfluxesinout(g, gv, cs%tr(:,:,:,m), dt, fluxes, h\_work, &
349                                           evap\_cfl\_limit, minimum\_forcing\_depth)
350       \textcolor{keyword}{call }tracer\_vertdiff(h\_work, ea, eb, dt, cs%tr(:,:,:,m), g, gv)
351 \textcolor{keywordflow}{    enddo}
352   \textcolor{keywordflow}{else}
353     \textcolor{keywordflow}{do} m=1,cs%ntr
354       \textcolor{keyword}{call }tracer\_vertdiff(h\_old, ea, eb, dt, cs%tr(:,:,:,m), g, gv)
355 \textcolor{keywordflow}{    enddo}
356 \textcolor{keywordflow}{  endif}
357 
358   year = time\_type\_to\_real(cs%Time) * isecs\_per\_year
359 
360   \textcolor{comment}{! Decay tracer (limit decay rate to 1/dt - just in case)}
361   \textcolor{keywordflow}{do} m=2,cs%ntr
362     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
363       \textcolor{comment}{!CS%tr(i,j,k,m) = CS%tr(i,j,k,m) - dt*CS%oil\_decay\_rate(m)*CS%tr(i,j,k,m) ! Simple}
364       \textcolor{comment}{!CS%tr(i,j,k,m) = CS%tr(i,j,k,m) - min(dt*CS%oil\_decay\_rate(m),1.)*CS%tr(i,j,k,m) ! Safer}
365       \textcolor{keywordflow}{if} (cs%oil\_decay\_rate(m)>0.) \textcolor{keywordflow}{then}
366         cs%tr(i,j,k,m) = g%mask2dT(i,j)*max(1. - dt*cs%oil\_decay\_rate(m),0.)*cs%tr(i,j,k,m) \textcolor{comment}{! Safest}
367       \textcolor{keywordflow}{elseif} (cs%oil\_decay\_rate(m)<0.) \textcolor{keywordflow}{then}
368         ldecay = 12.*(3.0**(-(tv%T(i,j,k)-20.)/10.)) \textcolor{comment}{! Timescale [days]}
369         ldecay = 1. / (86400.*us%s\_to\_T * ldecay) \textcolor{comment}{! Rate [T-1 ~> s-1]}
370         cs%tr(i,j,k,m) = g%mask2dT(i,j)*max(1. - dt*ldecay,0.)*cs%tr(i,j,k,m)
371 \textcolor{keywordflow}{      endif}
372 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
373 \textcolor{keywordflow}{  enddo}
374 
375   \textcolor{comment}{! Add oil at the source location}
376   \textcolor{keywordflow}{if} (year>=cs%oil\_start\_year .and. year<=cs%oil\_end\_year .and. &
377       cs%oil\_source\_i>-999 .and. cs%oil\_source\_j>-999) \textcolor{keywordflow}{then}
378     i=cs%oil\_source\_i ; j=cs%oil\_source\_j
379     k\_max=nz ; h\_total=0.
380     \textcolor{keywordflow}{do} k=nz, 2, -1
381       h\_total = h\_total + h\_new(i,j,k)
382       \textcolor{keywordflow}{if} (h\_total<10.) k\_max=k-1 \textcolor{comment}{! Find bottom most interface that is 10 m above bottom}
383 \textcolor{keywordflow}{    enddo}
384     \textcolor{keywordflow}{do} m=1,cs%ntr
385       k=cs%oil\_source\_k(m)
386       \textcolor{keywordflow}{if} (k>0) \textcolor{keywordflow}{then}
387         k=min(k,k\_max) \textcolor{comment}{! Only insert k or first layer with interface 10 m above bottom}
388         cs%tr(i,j,k,m) = cs%tr(i,j,k,m) + cs%oil\_source\_rate*dt / &
389                 ((h\_new(i,j,k)+gv%H\_subroundoff) * g%US%L\_to\_m**2*g%areaT(i,j) )
390       \textcolor{keywordflow}{elseif} (k<0) \textcolor{keywordflow}{then}
391         h\_total=gv%H\_subroundoff
392         \textcolor{keywordflow}{do} k=1, nz
393           h\_total = h\_total + h\_new(i,j,k)
394 \textcolor{keywordflow}{        enddo}
395         \textcolor{keywordflow}{do} k=1, nz
396           cs%tr(i,j,k,m) = cs%tr(i,j,k,m) + cs%oil\_source\_rate*dt/(h\_total &
397                                            * g%US%L\_to\_m**2*g%areaT(i,j) )
398 \textcolor{keywordflow}{        enddo}
399 \textcolor{keywordflow}{      endif}
400 \textcolor{keywordflow}{    enddo}
401 \textcolor{keywordflow}{  endif}
402 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceoil__tracer_a428f70692e0f8a537b73e24ada1e5357}\label{namespaceoil__tracer_a428f70692e0f8a537b73e24ada1e5357}} 
\index{oil\+\_\+tracer@{oil\+\_\+tracer}!oil\+\_\+tracer\+\_\+end@{oil\+\_\+tracer\+\_\+end}}
\index{oil\+\_\+tracer\+\_\+end@{oil\+\_\+tracer\+\_\+end}!oil\+\_\+tracer@{oil\+\_\+tracer}}
\subsubsection{\texorpdfstring{oil\+\_\+tracer\+\_\+end()}{oil\_tracer\_end()}}
{\footnotesize\ttfamily subroutine, public oil\+\_\+tracer\+::oil\+\_\+tracer\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+tracer\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocate memory associated with this tracer package. 


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


Definition at line 489 of file oil\+\_\+tracer.\+F90.


\begin{DoxyCode}
489   \textcolor{keywordtype}{type}(oil\_tracer\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous}
490 \textcolor{comment}{                                     !! call to register\_oil\_tracer.}
491   \textcolor{keywordtype}{integer} :: m
492 
493   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
494     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tr)) \textcolor{keyword}{deallocate}(cs%tr)
495     \textcolor{keyword}{deallocate}(cs)
496 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespaceoil__tracer_a08f2426138c293029ea1d58b2119c3ce}\label{namespaceoil__tracer_a08f2426138c293029ea1d58b2119c3ce}} 
\index{oil\+\_\+tracer@{oil\+\_\+tracer}!oil\+\_\+tracer\+\_\+surface\+\_\+state@{oil\+\_\+tracer\+\_\+surface\+\_\+state}}
\index{oil\+\_\+tracer\+\_\+surface\+\_\+state@{oil\+\_\+tracer\+\_\+surface\+\_\+state}!oil\+\_\+tracer@{oil\+\_\+tracer}}
\subsubsection{\texorpdfstring{oil\+\_\+tracer\+\_\+surface\+\_\+state()}{oil\_tracer\_surface\_state()}}
{\footnotesize\ttfamily subroutine, public oil\+\_\+tracer\+::oil\+\_\+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{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+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\+\_\+oil\+\_\+tracer. \\
\hline
\end{DoxyParams}


Definition at line 458 of file oil\+\_\+tracer.\+F90.


\begin{DoxyCode}
458   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}
459   \textcolor{keywordtype}{type}(surface),          \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{ !< A structure containing fields that}
460 \textcolor{comment}{                                              !! describe the surface state of the ocean.}
461   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
462                           \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2].}
463   \textcolor{keywordtype}{type}(oil\_tracer\_CS),    \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a previous}
464 \textcolor{comment}{                                              !! call to register\_oil\_tracer.}
465 
466   \textcolor{comment}{! This particular tracer package does not report anything back to the coupler.}
467   \textcolor{comment}{! The code that is here is just a rough guide for packages that would.}
468 
469   \textcolor{keywordtype}{integer} :: m, is, ie, js, je, isd, ied, jsd, jed
470   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
471   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
472 
473   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
474 
475   \textcolor{keywordflow}{if} (cs%coupled\_tracers) \textcolor{keywordflow}{then}
476     \textcolor{keywordflow}{do} m=1,cs%ntr
477       \textcolor{comment}{!   This call loads the surface values into the appropriate array in the}
478       \textcolor{comment}{! coupler-type structure.}
479       \textcolor{keyword}{call }coupler\_type\_set\_data(cs%tr(:,:,1,m), cs%ind\_tr(m), ind\_csurf, &
480                    sfc\_state%tr\_fields, idim=(/isd, is, ie, ied/), &
481                    jdim=(/jsd, js, je, jed/) )
482 \textcolor{keywordflow}{    enddo}
483 \textcolor{keywordflow}{  endif}
484 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceoil__tracer_a3aceaf614d8651772124719e32879e23}\label{namespaceoil__tracer_a3aceaf614d8651772124719e32879e23}} 
\index{oil\+\_\+tracer@{oil\+\_\+tracer}!register\+\_\+oil\+\_\+tracer@{register\+\_\+oil\+\_\+tracer}}
\index{register\+\_\+oil\+\_\+tracer@{register\+\_\+oil\+\_\+tracer}!oil\+\_\+tracer@{oil\+\_\+tracer}}
\subsubsection{\texorpdfstring{register\+\_\+oil\+\_\+tracer()}{register\_oil\_tracer()}}
{\footnotesize\ttfamily logical function, public oil\+\_\+tracer\+::register\+\_\+oil\+\_\+tracer (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structoil__tracer_1_1oil__tracer__cs}{oil\+\_\+tracer\+\_\+cs}}), pointer}]{CS,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{tr\+\_\+\+Reg,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Register oil 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 us} & A dimensional unit scaling type\\
\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 78 of file oil\+\_\+tracer.\+F90.


\begin{DoxyCode}
78   \textcolor{keywordtype}{type}(hor\_index\_type),       \textcolor{keywordtype}{intent(in)} :: HI\textcolor{comment}{   !< A horizontal index type structure}
79   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
80   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
81   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}
82   \textcolor{keywordtype}{type}(oil\_tracer\_CS),        \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< A pointer that is set to point to the control}
83 \textcolor{comment}{                                                 !! structure for this module}
84   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}    :: tr\_Reg\textcolor{comment}{ !< A pointer that is set to point to the control}
85 \textcolor{comment}{                                                 !! structure for the tracer advection and}
86 \textcolor{comment}{                                                 !! diffusion module}
87   \textcolor{keywordtype}{type}(MOM\_restart\_CS),       \textcolor{keywordtype}{pointer}    :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}
88 
89   \textcolor{comment}{! Local variables}
90   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"oil\_tracer"} \textcolor{comment}{! This module's name.}
91 \textcolor{comment}{! This include declares and sets the variable "version".}
92 \textcolor{preprocessor}{#include "version\_variable.h"}
93 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=200)} :: inputdir \textcolor{comment}{! The directory where the input files are.}
94   \textcolor{keywordtype}{character(len=48)}  :: var\_name \textcolor{comment}{! The variable's name.}
95   \textcolor{keywordtype}{character(len=3)}   :: name\_tag \textcolor{comment}{! String for creating identifying oils}
96   \textcolor{keywordtype}{character(len=48)} :: flux\_units \textcolor{comment}{! The units for tracer fluxes, here}
97                             \textcolor{comment}{! kg(oil) s-1 or kg(oil) m-3 kg(water) s-1.}
98   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{pointer} :: tr\_ptr(:,:,:) => null()
99   \textcolor{keywordtype}{logical} :: register\_oil\_tracer
100   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, nz, m, i, j
101   isd = hi%isd ; ied = hi%ied ; jsd = hi%jsd ; jed = hi%jed ; nz = gv%ke
102 
103   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
104     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"register\_oil\_tracer called with an "}// &
105                              \textcolor{stringliteral}{"associated control structure."})
106     \textcolor{keywordflow}{return}
107 \textcolor{keywordflow}{  endif}
108   \textcolor{keyword}{allocate}(cs)
109 
110   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
111   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
112   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_IC\_FILE"}, cs%IC\_file, &
113                  \textcolor{stringliteral}{"The file in which the oil tracer initial values can be "}//&
114                  \textcolor{stringliteral}{"found, or an empty string for internal initialization."}, &
115                  default=\textcolor{stringliteral}{" "})
116   \textcolor{keywordflow}{if} ((len\_trim(cs%IC\_file) > 0) .and. (scan(cs%IC\_file,\textcolor{stringliteral}{'/'}) == 0)) \textcolor{keywordflow}{then}
117     \textcolor{comment}{! Add the directory if CS%IC\_file is not already a complete path.}
118     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
119     cs%IC\_file = trim(slasher(inputdir))//trim(cs%IC\_file)
120     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/CFC\_IC\_FILE"}, cs%IC\_file)
121 \textcolor{keywordflow}{  endif}
122   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_IC\_FILE\_IS\_Z"}, cs%Z\_IC\_file, &
123                  \textcolor{stringliteral}{"If true, OIL\_IC\_FILE is in depth space, not layer space"}, &
124                  default=.false.)
125 
126   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_MAY\_REINIT"}, cs%oil\_may\_reinit, &
127                  \textcolor{stringliteral}{"If true, oil tracers may go through the initialization "}//&
128                  \textcolor{stringliteral}{"code if they are not found in the restart files. "}//&
129                  \textcolor{stringliteral}{"Otherwise it is a fatal error if the oil tracers are not "}//&
130                  \textcolor{stringliteral}{"found in the restart files of a restarted run."}, &
131                  default=.false.)
132   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_SOURCE\_LONGITUDE"}, cs%oil\_source\_longitude, &
133                  \textcolor{stringliteral}{"The geographic longitude of the oil source."}, units=\textcolor{stringliteral}{"degrees E"}, &
134                  fail\_if\_missing=.true.)
135   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_SOURCE\_LATITUDE"}, cs%oil\_source\_latitude, &
136                  \textcolor{stringliteral}{"The geographic latitude of the oil source."}, units=\textcolor{stringliteral}{"degrees N"}, &
137                  fail\_if\_missing=.true.)
138   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_SOURCE\_LAYER"}, cs%oil\_source\_k, &
139                  \textcolor{stringliteral}{"The layer into which the oil is introduced, or a "}//&
140                  \textcolor{stringliteral}{"negative number for a vertically uniform source, "}//&
141                  \textcolor{stringliteral}{"or 0 not to use this tracer."}, units=\textcolor{stringliteral}{"Layer"}, default=0)
142   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_SOURCE\_RATE"}, cs%oil\_source\_rate, &
143                  \textcolor{stringliteral}{"The rate of oil injection."}, units=\textcolor{stringliteral}{"kg s-1"}, scale=us%T\_to\_s, default=1.0)
144   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_DECAY\_DAYS"}, cs%oil\_decay\_days, &
145                  \textcolor{stringliteral}{"The decay timescale in days (if positive), or no decay "}//&
146                  \textcolor{stringliteral}{"if 0, or use the temperature dependent decay rate of "}//&
147                  \textcolor{stringliteral}{"Adcroft et al. (GRL, 2010) if negative."}, units=\textcolor{stringliteral}{"days"}, &
148                  default=0.0)
149   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_DATED\_START\_YEAR"}, cs%oil\_start\_year, &
150                  \textcolor{stringliteral}{"The time at which the oil source starts"}, units=\textcolor{stringliteral}{"years"}, &
151                  default=0.0)
152   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_DATED\_END\_YEAR"}, cs%oil\_end\_year, &
153                  \textcolor{stringliteral}{"The time at which the oil source ends"}, units=\textcolor{stringliteral}{"years"}, &
154                  default=1.0e99)
155 
156   cs%ntr = 0
157   cs%oil\_decay\_rate(:) = 0.
158   \textcolor{keywordflow}{do} m=1,ntr\_max
159     \textcolor{keywordflow}{if} (cs%oil\_source\_k(m)/=0) \textcolor{keywordflow}{then}
160       \textcolor{keyword}{write}(name\_tag(1:3),\textcolor{stringliteral}{'("\_",I2.2)'}) m
161       cs%ntr = cs%ntr + 1
162       cs%tr\_desc(m) = var\_desc(\textcolor{stringliteral}{"oil"}//trim(name\_tag), \textcolor{stringliteral}{"kg m-3"}, \textcolor{stringliteral}{"Oil Tracer"}, caller=mdl)
163       cs%IC\_val(m) = 0.0
164       \textcolor{keywordflow}{if} (cs%oil\_decay\_days(m)>0.) \textcolor{keywordflow}{then}
165         cs%oil\_decay\_rate(m) = 1. / (86400.0*us%s\_to\_T * cs%oil\_decay\_days(m))
166       \textcolor{keywordflow}{elseif} (cs%oil\_decay\_days(m)<0.) \textcolor{keywordflow}{then}
167         cs%oil\_decay\_rate(m) = -1.
168 \textcolor{keywordflow}{      endif}
169 \textcolor{keywordflow}{    endif}
170 \textcolor{keywordflow}{  enddo}
171   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"OIL\_DECAY\_RATE"}, us%s\_to\_T*cs%oil\_decay\_rate(1:cs%ntr))
172 
173   \textcolor{comment}{! This needs to be changed if the units of tracer are changed above.}
174   \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then} ; flux\_units = \textcolor{stringliteral}{"kg s-1"}
175   \textcolor{keywordflow}{else} ; flux\_units = \textcolor{stringliteral}{"kg m-3 kg s-1"} ;\textcolor{keywordflow}{ endif}
176 
177   \textcolor{keyword}{allocate}(cs%tr(isd:ied,jsd:jed,nz,cs%ntr)) ; cs%tr(:,:,:,:) = 0.0
178 
179   \textcolor{keywordflow}{do} m=1,cs%ntr
180     \textcolor{comment}{! This is needed to force the compiler not to do a copy in the registration}
181     \textcolor{comment}{! calls.  Curses on the designers and implementers of Fortran90.}
182     tr\_ptr => cs%tr(:,:,:,m)
183     \textcolor{keyword}{call }query\_vardesc(cs%tr\_desc(m), name=var\_name, caller=\textcolor{stringliteral}{"register\_oil\_tracer"})
184     \textcolor{comment}{! Register the tracer for horizontal advection, diffusion, and restarts.}
185     \textcolor{keyword}{call }register\_tracer(tr\_ptr, tr\_reg, param\_file, hi, gv, tr\_desc=cs%tr\_desc(m), &
186                          registry\_diags=.true., flux\_units=flux\_units, restart\_cs=restart\_cs, &
187                          mandatory=.not.cs%oil\_may\_reinit)
188 
189     \textcolor{comment}{!   Set coupled\_tracers to be true (hard-coded above) to provide the surface}
190     \textcolor{comment}{! values to the coupler (if any).  This is meta-code and its arguments will}
191     \textcolor{comment}{! currently (deliberately) give fatal errors if it is used.}
192     \textcolor{keywordflow}{if} (cs%coupled\_tracers) &
193       cs%ind\_tr(m) = aof\_set\_coupler\_flux(trim(var\_name)//\textcolor{stringliteral}{'\_flux'}, &
194           flux\_type=\textcolor{stringliteral}{' '}, implementation=\textcolor{stringliteral}{' '}, caller=\textcolor{stringliteral}{"register\_oil\_tracer"})
195 \textcolor{keywordflow}{  enddo}
196 
197   cs%tr\_Reg => tr\_reg
198   cs%restart\_CSp => restart\_cs
199   register\_oil\_tracer = .true.
200 
\end{DoxyCode}
