\hypertarget{namespacemom__tracer__z__init}{}\doxysection{mom\+\_\+tracer\+\_\+z\+\_\+init Module Reference}
\label{namespacemom__tracer__z__init}\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}


\doxysubsection{Detailed Description}
Used to initialize tracers from a depth-\/ (or z$\ast$-\/) space file. \doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__tracer__z__init_aef33387149983391f1ea92bad7344360}{tracer\+\_\+z\+\_\+init}} (tr, h, filename, tr\+\_\+name, G, US, missing\+\_\+val, land\+\_\+val)
\begin{DoxyCompactList}\small\item\em This function initializes a tracer by reading a Z-\/space file, returning .true. if this appears to have been successful, and false otherwise. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__z__init_a2c439cbda792bb711a62094bbe779aec}{tracer\+\_\+z\+\_\+init\+\_\+array}} (tr\+\_\+in, z\+\_\+edges, nk\+\_\+data, e, land\+\_\+fill, G, nlay, nlevs, eps\+\_\+z, tr)
\begin{DoxyCompactList}\small\item\em Layer model routine for remapping tracers from pseudo-\/z coordinates into layers defined by target interface positions. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tracer__z__init_a9f9a4d16dbd230d126b3f4d255071ad8}{read\+\_\+z\+\_\+edges}} (filename, tr\+\_\+name, z\+\_\+edges, nz\+\_\+out, has\+\_\+edges, use\+\_\+missing, missing, scale)
\begin{DoxyCompactList}\small\item\em This subroutine reads the vertical coordinate data for a field from a Net\+C\+DF file. It also might read the missing value attribute for that same field. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tracer__z__init_a4cfb4818fc391a8d95ce737c06662d25}{find\+\_\+overlap}} (e, Z\+\_\+top, Z\+\_\+bot, k\+\_\+max, k\+\_\+start, k\+\_\+top, k\+\_\+bot, wt, z1, z2)
\begin{DoxyCompactList}\small\item\em Determines the layers bounded by interfaces e that overlap with the depth range between Z\+\_\+top and Z\+\_\+bot, and the fractional weights of each layer. It also calculates the normalized relative depths of the range of each layer that overlaps that depth range. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__tracer__z__init_a95177109110908c348d612ceb6923f9f}{find\+\_\+limited\+\_\+slope}} (val, e, k)
\begin{DoxyCompactList}\small\item\em This subroutine determines a limited slope for val to be advected with a piecewise limited scheme. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__z__init_ada3b3c684981ee5dabaaef4998589ca8}{determine\+\_\+temperature}} (temp, salt, R\+\_\+tgt, p\+\_\+ref, niter, land\+\_\+fill, h, k\+\_\+start, G, US, eos, h\+\_\+massless)
\begin{DoxyCompactList}\small\item\em This subroutine determines the potential temperature and salinity that is consistent with the target density using provided initial guess. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tracer__z__init_ada3b3c684981ee5dabaaef4998589ca8}\label{namespacemom__tracer__z__init_ada3b3c684981ee5dabaaef4998589ca8}} 
\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}!determine\_temperature@{determine\_temperature}}
\index{determine\_temperature@{determine\_temperature}!mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}
\doxysubsubsection{\texorpdfstring{determine\_temperature()}{determine\_temperature()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+z\+\_\+init\+::determine\+\_\+temperature (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{temp,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{salt,  }\item[{real, dimension( g \%ke), intent(in)}]{R\+\_\+tgt,  }\item[{real, intent(in)}]{p\+\_\+ref,  }\item[{integer, intent(in)}]{niter,  }\item[{real, intent(in)}]{land\+\_\+fill,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{integer, intent(in)}]{k\+\_\+start,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__eos_1_1eos__type}{eos\+\_\+type}}), pointer}]{eos,  }\item[{real, intent(in), optional}]{h\+\_\+massless }\end{DoxyParamCaption})}



This subroutine determines the potential temperature and salinity that is consistent with the target density using provided initial guess. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em temp} & potential temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em salt} & salinity \mbox{[}P\+SU\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em r\+\_\+tgt} & desired potential density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+ref} & reference pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em niter} & maximum number of iterations \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+start} & starting index (i.\+e. below the buffer layer) \\
\hline
\mbox{\texttt{ in}}  & {\em land\+\_\+fill} & land fill value \\
\hline
\mbox{\texttt{ in}}  & {\em h} & layer thickness, used only to avoid working on \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em eos} & seawater equation of state control structure \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+massless} & A threshold below which a layer is determined to be massless \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 613 of file M\+O\+M\+\_\+tracer\+\_\+\+Z\+\_\+init.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{614   \textcolor{keywordtype}{type}(ocean\_grid\_type),         \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{615 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{616                                  \textcolor{keywordtype}{intent(inout)} :: temp\textcolor{comment}{ !< potential temperature [degC]}}
\DoxyCodeLine{617 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{618                                  \textcolor{keywordtype}{intent(inout)} :: salt\textcolor{comment}{ !< salinity [PSU]}}
\DoxyCodeLine{619 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G))},      \textcolor{keywordtype}{intent(in)}    :: R\_tgt\textcolor{comment}{ !< desired potential density [R \string~> kg m-\/3].}}
\DoxyCodeLine{620 \textcolor{keywordtype}{  real},                          \textcolor{keywordtype}{intent(in)}    :: p\_ref\textcolor{comment}{ !< reference pressure [R L2 T-\/2 \string~> Pa].}}
\DoxyCodeLine{621   \textcolor{keywordtype}{integer},                       \textcolor{keywordtype}{intent(in)}    :: niter\textcolor{comment}{ !< maximum number of iterations}}
\DoxyCodeLine{622   \textcolor{keywordtype}{integer},                       \textcolor{keywordtype}{intent(in)}    :: k\_start\textcolor{comment}{ !< starting index (i.e. below the buffer layer)}}
\DoxyCodeLine{623 \textcolor{keywordtype}{  real},                          \textcolor{keywordtype}{intent(in)}    :: land\_fill\textcolor{comment}{ !< land fill value}}
\DoxyCodeLine{624 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{625                                  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{   !< layer thickness, used only to avoid working on}}
\DoxyCodeLine{626 \textcolor{comment}{                                                      !! massless layers [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{627   \textcolor{keywordtype}{type}(unit\_scale\_type),         \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{628   \textcolor{keywordtype}{type}(eos\_type),                \textcolor{keywordtype}{pointer}       :: eos\textcolor{comment}{ !< seawater equation of state control structure}}
\DoxyCodeLine{629 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_massless\textcolor{comment}{ !< A threshold below which a layer is}}
\DoxyCodeLine{630 \textcolor{comment}{                                                      !! determined to be massless [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{631 }
\DoxyCodeLine{632 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: T\_max = 31.0, t\_min = -\/2.0}
\DoxyCodeLine{633   \textcolor{comment}{! Local variables (All of which need documentation!)}}
\DoxyCodeLine{634 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{635     T, S, dT, dS, \&}
\DoxyCodeLine{636     rho, \& \textcolor{comment}{! Layer densities [R \string~> kg m-\/3]}}
\DoxyCodeLine{637     hin, \& \textcolor{comment}{! Input layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{638     drho\_dT, \& \textcolor{comment}{! Partial derivative of density with temperature [R degC-\/1 \string~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{639     drho\_dS    \textcolor{comment}{! Partial derivative of density with salinity [R ppt-\/1 \string~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{640 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: press \textcolor{comment}{! Reference pressures [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{641 \textcolor{keywordtype}{  real}    :: dT\_dS\_gauge  \textcolor{comment}{! The relative penalizing of temperature to salinity changes when}}
\DoxyCodeLine{642                           \textcolor{comment}{! minimizing property changes while correcting density [degC ppt-\/1].}}
\DoxyCodeLine{643 \textcolor{keywordtype}{  real}    :: I\_denom      \textcolor{comment}{! The inverse of the magnitude squared of the density gradient in}}
\DoxyCodeLine{644                           \textcolor{comment}{! T-\/S space streched with dT\_dS\_gauge [ppt2 R-\/2 \string~> ppt2 m6 kg-\/2]}}
\DoxyCodeLine{645   \textcolor{keywordtype}{logical} :: adjust\_salt, old\_fit}
\DoxyCodeLine{646 \textcolor{keywordtype}{  real} :: S\_min, S\_max}
\DoxyCodeLine{647 \textcolor{keywordtype}{  real} :: tol\_T    \textcolor{comment}{! The tolerance for temperature matches [degC]}}
\DoxyCodeLine{648 \textcolor{keywordtype}{  real} :: tol\_S    \textcolor{comment}{! The tolerance for salinity matches [ppt]}}
\DoxyCodeLine{649 \textcolor{keywordtype}{  real} :: tol\_rho  \textcolor{comment}{! The tolerance for density matches [R \string~> kg m-\/3]}}
\DoxyCodeLine{650 \textcolor{keywordtype}{  real} :: max\_t\_adj, max\_s\_adj}
\DoxyCodeLine{651   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{652   \textcolor{keywordtype}{integer} :: i, j, k, kz, is, ie, js, je, nz, itt}
\DoxyCodeLine{653 }
\DoxyCodeLine{654   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{655 }
\DoxyCodeLine{656   \textcolor{comment}{! These hard coded parameters need to be set properly.}}
\DoxyCodeLine{657   s\_min = 0.5 ; s\_max = 65.0}
\DoxyCodeLine{658   max\_t\_adj = 1.0 ; max\_s\_adj = 0.5}
\DoxyCodeLine{659   tol\_t=1.e-\/4 ; tol\_s=1.e-\/4 ; tol\_rho = 1.e-\/4*us\%kg\_m3\_to\_R}
\DoxyCodeLine{660   old\_fit = .true.   \textcolor{comment}{! reproduces siena behavior}}
\DoxyCodeLine{661 }
\DoxyCodeLine{662   \textcolor{comment}{! \#\#\# The whole determine\_temperature subroutine needs to be reexamined, both the algorithms}}
\DoxyCodeLine{663   \textcolor{comment}{!     and the extensive use of hard-\/coded dimensional parameters.}}
\DoxyCodeLine{664 }
\DoxyCodeLine{665   \textcolor{comment}{! We will switch to the newer method which simultaneously adjusts}}
\DoxyCodeLine{666   \textcolor{comment}{! temp and salt based on the ratio of the thermal and haline coefficients, once it is tested.}}
\DoxyCodeLine{667 }
\DoxyCodeLine{668   press(:) = p\_ref}
\DoxyCodeLine{669   eosdom(:) = eos\_domain(g\%HI)}
\DoxyCodeLine{670 }
\DoxyCodeLine{671   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{672     ds(:,:) = 0. \textcolor{comment}{! Needs to be zero everywhere since there is a maxval(abs(dS)) later...}}
\DoxyCodeLine{673     t(:,:) = temp(:,j,:)}
\DoxyCodeLine{674     s(:,:) = salt(:,j,:)}
\DoxyCodeLine{675     hin(:,:) = h(:,j,:)}
\DoxyCodeLine{676     dt(:,:) = 0.0}
\DoxyCodeLine{677     adjust\_salt = .true.}
\DoxyCodeLine{678     iter\_loop: \textcolor{keywordflow}{do} itt = 1,niter}
\DoxyCodeLine{679       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{680         \textcolor{keyword}{call }calculate\_density(t(:,k), s(:,k), press, rho(:,k), eos, eosdom )}
\DoxyCodeLine{681         \textcolor{keyword}{call }calculate\_density\_derivs(t(:,k), s(:,k), press, drho\_dt(:,k), drho\_ds(:,k), \&}
\DoxyCodeLine{682                                       eos, eosdom )}
\DoxyCodeLine{683 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{684       \textcolor{keywordflow}{do} k=k\_start,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{685 \textcolor{comment}{!       if (abs(rho(i,k)-\/R\_tgt(k))>tol\_rho .and. hin(i,k)>h\_massless .and. abs(T(i,k)-\/land\_fill) < epsln) then}}
\DoxyCodeLine{686         \textcolor{keywordflow}{if} (abs(rho(i,k)-\/r\_tgt(k))>tol\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{687           \textcolor{keywordflow}{if} (old\_fit) \textcolor{keywordflow}{then}}
\DoxyCodeLine{688             dt(i,k) = max(min((r\_tgt(k)-\/rho(i,k)) / drho\_dt(i,k), max\_t\_adj), -\/max\_t\_adj)}
\DoxyCodeLine{689             t(i,k) = max(min(t(i,k)+dt(i,k), t\_max), t\_min)}
\DoxyCodeLine{690           \textcolor{keywordflow}{else}}
\DoxyCodeLine{691             dt\_ds\_gauge = 10.0  \textcolor{comment}{! 10 degC is weighted equivalently to 1 ppt.}}
\DoxyCodeLine{692             i\_denom = 1.0 / (drho\_ds(i,k)**2 + dt\_ds\_gauge**2*drho\_dt(i,k)**2)}
\DoxyCodeLine{693             ds(i,k) = (r\_tgt(k)-\/rho(i,k)) * drho\_ds(i,k) * i\_denom}
\DoxyCodeLine{694             dt(i,k) = (r\_tgt(k)-\/rho(i,k)) * dt\_ds\_gauge**2*drho\_dt(i,k) * i\_denom}
\DoxyCodeLine{695 }
\DoxyCodeLine{696             t(i,k) = max(min(t(i,k)+dt(i,k), t\_max), t\_min)}
\DoxyCodeLine{697             s(i,k) = max(min(s(i,k)+ds(i,k), s\_max), s\_min)}
\DoxyCodeLine{698 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{699 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{700 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{701       \textcolor{keywordflow}{if} (maxval(abs(dt)) < tol\_t) \textcolor{keywordflow}{then}}
\DoxyCodeLine{702         adjust\_salt = .false.}
\DoxyCodeLine{703         \textcolor{keywordflow}{exit} iter\_loop}
\DoxyCodeLine{704 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{705 \textcolor{keywordflow}{    enddo} iter\_loop}
\DoxyCodeLine{706 }
\DoxyCodeLine{707     \textcolor{keywordflow}{if} (adjust\_salt .and. old\_fit) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} itt = 1,niter}
\DoxyCodeLine{708       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{709         \textcolor{keyword}{call }calculate\_density(t(:,k), s(:,k), press, rho(:,k), eos, eosdom )}
\DoxyCodeLine{710         \textcolor{keyword}{call }calculate\_density\_derivs(t(:,k), s(:,k), press, drho\_dt(:,k), drho\_ds(:,k), \&}
\DoxyCodeLine{711                                       eos, eosdom )}
\DoxyCodeLine{712 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{713       \textcolor{keywordflow}{do} k=k\_start,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{714 \textcolor{comment}{!       if (abs(rho(i,k)-\/R\_tgt(k))>tol\_rho .and. hin(i,k)>h\_massless .and. abs(T(i,k)-\/land\_fill) < epsln ) then}}
\DoxyCodeLine{715         \textcolor{keywordflow}{if} (abs(rho(i,k)-\/r\_tgt(k)) > tol\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{716           ds(i,k) = max(min((r\_tgt(k)-\/rho(i,k)) / drho\_ds(i,k), max\_s\_adj), -\/max\_s\_adj)}
\DoxyCodeLine{717           s(i,k) = max(min(s(i,k)+ds(i,k), s\_max), s\_min)}
\DoxyCodeLine{718 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{719 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{720       \textcolor{keywordflow}{if} (maxval(abs(ds)) < tol\_s) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{721 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{722 }
\DoxyCodeLine{723     temp(:,j,:) = t(:,:)}
\DoxyCodeLine{724     salt(:,j,:) = s(:,:)}
\DoxyCodeLine{725 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{726 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__z__init_a95177109110908c348d612ceb6923f9f}\label{namespacemom__tracer__z__init_a95177109110908c348d612ceb6923f9f}} 
\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}!find\_limited\_slope@{find\_limited\_slope}}
\index{find\_limited\_slope@{find\_limited\_slope}!mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}
\doxysubsubsection{\texorpdfstring{find\_limited\_slope()}{find\_limited\_slope()}}
{\footnotesize\ttfamily real function mom\+\_\+tracer\+\_\+z\+\_\+init\+::find\+\_\+limited\+\_\+slope (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{val,  }\item[{real, dimension(\+:), intent(in)}]{e,  }\item[{integer, intent(in)}]{k }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine determines a limited slope for val to be advected with a piecewise limited scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em val} & An column the values that are being interpolated. \\
\hline
\mbox{\texttt{ in}}  & {\em e} & A column\textquotesingle{}s interface heights \mbox{[}Z $\sim$$>$ m\mbox{]} or other units. \\
\hline
\mbox{\texttt{ in}}  & {\em k} & The layer whose slope is being determined. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The normalized slope in the intracell distribution of val. 
\end{DoxyReturn}


Definition at line 579 of file M\+O\+M\+\_\+tracer\+\_\+\+Z\+\_\+init.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{580 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: val\textcolor{comment}{ !< An column the values that are being interpolated.}}
\DoxyCodeLine{581 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: e\textcolor{comment}{   !< A column's interface heights [Z \string~> m] or other units.}}
\DoxyCodeLine{582   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)} :: k\textcolor{comment}{   !< The layer whose slope is being determined.}}
\DoxyCodeLine{583 \textcolor{keywordtype}{  real} :: slope\textcolor{comment}{ !< The normalized slope in the intracell distribution of val.}}
\DoxyCodeLine{584   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{585 \textcolor{keywordtype}{  real} :: amn, cmn}
\DoxyCodeLine{586 \textcolor{keywordtype}{  real} :: d1, d2}
\DoxyCodeLine{587 }
\DoxyCodeLine{588   \textcolor{keywordflow}{if} ((val(k)-\/val(k-\/1)) * (val(k)-\/val(k+1)) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{589     slope = 0.0 \textcolor{comment}{! ; curvature = 0.0}}
\DoxyCodeLine{590   \textcolor{keywordflow}{else}}
\DoxyCodeLine{591     d1 = 0.5*(e(k-\/1)-\/e(k+1)) ; d2 = 0.5*(e(k)-\/e(k+2))}
\DoxyCodeLine{592     \textcolor{keywordflow}{if} (d1*d2 > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{593       slope = ((d1**2)*(val(k+1) -\/ val(k)) + (d2**2)*(val(k) -\/ val(k-\/1))) * \&}
\DoxyCodeLine{594               (e(k) -\/ e(k+1)) / (d1*d2*(d1+d2))}
\DoxyCodeLine{595       \textcolor{comment}{! slope = 0.5*(val(k+1) -\/ val(k-\/1))}}
\DoxyCodeLine{596       \textcolor{comment}{! This is S.J. Lin's form of the PLM limiter.}}
\DoxyCodeLine{597       amn = min(abs(slope), 2.0*(max(val(k-\/1), val(k), val(k+1)) -\/ val(k)))}
\DoxyCodeLine{598       cmn = 2.0*(val(k) -\/ min(val(k-\/1), val(k), val(k+1)))}
\DoxyCodeLine{599       slope = sign(1.0, slope) * min(amn, cmn)}
\DoxyCodeLine{600 }
\DoxyCodeLine{601       \textcolor{comment}{! min(abs(slope), 2.0*(max(val(k-\/1),val(k),val(k+1)) -\/ val(k)), \&}}
\DoxyCodeLine{602       \textcolor{comment}{!                 2.0*(val(k) -\/ min(val(k-\/1),val(k),val(k+1))))}}
\DoxyCodeLine{603       \textcolor{comment}{! curvature = 0.0}}
\DoxyCodeLine{604     \textcolor{keywordflow}{else}}
\DoxyCodeLine{605       slope = 0.0 \textcolor{comment}{! ; curvature = 0.0}}
\DoxyCodeLine{606 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{607 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{608 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__z__init_a4cfb4818fc391a8d95ce737c06662d25}\label{namespacemom__tracer__z__init_a4cfb4818fc391a8d95ce737c06662d25}} 
\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}!find\_overlap@{find\_overlap}}
\index{find\_overlap@{find\_overlap}!mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}
\doxysubsubsection{\texorpdfstring{find\_overlap()}{find\_overlap()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tracer\+\_\+z\+\_\+init\+::find\+\_\+overlap (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{e,  }\item[{real, intent(in)}]{Z\+\_\+top,  }\item[{real, intent(in)}]{Z\+\_\+bot,  }\item[{integer, intent(in)}]{k\+\_\+max,  }\item[{integer, intent(in)}]{k\+\_\+start,  }\item[{integer, intent(out)}]{k\+\_\+top,  }\item[{integer, intent(out)}]{k\+\_\+bot,  }\item[{real, dimension(\+:), intent(out)}]{wt,  }\item[{real, dimension(\+:), intent(out)}]{z1,  }\item[{real, dimension(\+:), intent(out)}]{z2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Determines the layers bounded by interfaces e that overlap with the depth range between Z\+\_\+top and Z\+\_\+bot, and the fractional weights of each layer. It also calculates the normalized relative depths of the range of each layer that overlaps that depth range. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em e} & Column interface heights, \mbox{[}Z $\sim$$>$ m\mbox{]} or other units. \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+top} & Top of range being mapped to, in the units of e \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+bot} & Bottom of range being mapped to, in the units of e \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+max} & Number of valid layers. \\
\hline
\mbox{\texttt{ in}}  & {\em k\+\_\+start} & Layer at which to start searching. \\
\hline
\mbox{\texttt{ out}}  & {\em k\+\_\+top} & Indices of top layers that overlap with the depth range. \\
\hline
\mbox{\texttt{ out}}  & {\em k\+\_\+bot} & Indices of bottom layers that overlap with the depth range. \\
\hline
\mbox{\texttt{ out}}  & {\em wt} & Relative weights of each layer from k\+\_\+top to k\+\_\+bot \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em z1} & Depth of the top limits of the part of a layer that contributes to a depth level, relative to the cell center and normalized by the cell thickness \mbox{[}nondim\mbox{]}. Note that -\/1/2 $<$= z1 $<$ z2 $<$= 1/2. \\
\hline
\mbox{\texttt{ out}}  & {\em z2} & Depths of the bottom limit of the part of a layer that contributes to a depth level, relative to the cell center and normalized by the cell thickness \mbox{[}nondim\mbox{]}. Note that -\/1/2 $<$= z1 $<$ z2 $<$= 1/2. \\
\hline
\end{DoxyParams}


Definition at line 517 of file M\+O\+M\+\_\+tracer\+\_\+\+Z\+\_\+init.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{518 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}  :: e\textcolor{comment}{      !< Column interface heights, [Z \string~> m] or other units.}}
\DoxyCodeLine{519 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}  :: Z\_top\textcolor{comment}{  !< Top of range being mapped to, in the units of e [Z \string~> m].}}
\DoxyCodeLine{520 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}  :: Z\_bot\textcolor{comment}{  !< Bottom of range being mapped to, in the units of e [Z \string~> m].}}
\DoxyCodeLine{521   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}  :: k\_max\textcolor{comment}{  !< Number of valid layers.}}
\DoxyCodeLine{522   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}  :: k\_start\textcolor{comment}{ !< Layer at which to start searching.}}
\DoxyCodeLine{523   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(out)} :: k\_top\textcolor{comment}{  !< Indices of top layers that overlap with the depth range.}}
\DoxyCodeLine{524   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(out)} :: k\_bot\textcolor{comment}{  !< Indices of bottom layers that overlap with the depth range.}}
\DoxyCodeLine{525 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(out)} :: wt\textcolor{comment}{     !< Relative weights of each layer from k\_top to k\_bot [nondim].}}
\DoxyCodeLine{526 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(out)} :: z1\textcolor{comment}{     !< Depth of the top limits of the part of}}
\DoxyCodeLine{527 \textcolor{comment}{       !! a layer that contributes to a depth level, relative to the cell center and normalized}}
\DoxyCodeLine{528 \textcolor{comment}{       !! by the cell thickness [nondim].  Note that -\/1/2 <= z1 < z2 <= 1/2.}}
\DoxyCodeLine{529 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(out)}   :: z2\textcolor{comment}{     !< Depths of the bottom limit of the part of}}
\DoxyCodeLine{530 \textcolor{comment}{       !! a layer that contributes to a depth level, relative to the cell center and normalized}}
\DoxyCodeLine{531 \textcolor{comment}{       !! by the cell thickness [nondim].  Note that -\/1/2 <= z1 < z2 <= 1/2.}}
\DoxyCodeLine{532   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{533 \textcolor{keywordtype}{  real}    :: Ih, e\_c, tot\_wt, I\_totwt}
\DoxyCodeLine{534   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{535 }
\DoxyCodeLine{536   wt(:) = 0.0 ; z1(:) = 0.0 ; z2(:) = 0.0 ; k\_bot = k\_max}
\DoxyCodeLine{537 }
\DoxyCodeLine{538   \textcolor{keywordflow}{do} k=k\_start,k\_max ; \textcolor{keywordflow}{if} (e(k+1) < z\_top) \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{539   k\_top = k}
\DoxyCodeLine{540   \textcolor{keywordflow}{if} (k\_top > k\_max) \textcolor{keywordflow}{return}}
\DoxyCodeLine{541 }
\DoxyCodeLine{542   \textcolor{comment}{! Determine the fractional weights of each layer.}}
\DoxyCodeLine{543   \textcolor{comment}{! Note that by convention, e and Z\_int decrease with increasing k.}}
\DoxyCodeLine{544   \textcolor{keywordflow}{if} (e(k+1) <= z\_bot) \textcolor{keywordflow}{then}}
\DoxyCodeLine{545     wt(k) = 1.0 ; k\_bot = k}
\DoxyCodeLine{546     ih = 0.0 ; \textcolor{keywordflow}{if} (e(k) /= e(k+1)) ih = 1.0 / (e(k)-\/e(k+1))}
\DoxyCodeLine{547     e\_c = 0.5*(e(k)+e(k+1))}
\DoxyCodeLine{548     z1(k) = (e\_c -\/ min(e(k), z\_top)) * ih}
\DoxyCodeLine{549     z2(k) = (e\_c -\/ z\_bot) * ih}
\DoxyCodeLine{550   \textcolor{keywordflow}{else}}
\DoxyCodeLine{551     wt(k) = min(e(k),z\_top) -\/ e(k+1) ; tot\_wt = wt(k) \textcolor{comment}{! These are always > 0.}}
\DoxyCodeLine{552     \textcolor{keywordflow}{if} (e(k) /= e(k+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{553       z1(k) = (0.5*(e(k)+e(k+1)) -\/ min(e(k), z\_top)) / (e(k)-\/e(k+1))}
\DoxyCodeLine{554     \textcolor{keywordflow}{else} ; z1(k) = -\/0.5 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{555     z2(k) = 0.5}
\DoxyCodeLine{556     k\_bot = k\_max}
\DoxyCodeLine{557     \textcolor{keywordflow}{do} k=k\_top+1,k\_max}
\DoxyCodeLine{558       \textcolor{keywordflow}{if} (e(k+1) <= z\_bot) \textcolor{keywordflow}{then}}
\DoxyCodeLine{559         k\_bot = k}
\DoxyCodeLine{560         wt(k) = e(k) -\/ z\_bot ; z1(k) = -\/0.5}
\DoxyCodeLine{561         \textcolor{keywordflow}{if} (e(k) /= e(k+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{562           z2(k) = (0.5*(e(k)+e(k+1)) -\/ z\_bot) / (e(k)-\/e(k+1))}
\DoxyCodeLine{563         \textcolor{keywordflow}{else} ; z2(k) = 0.5 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{564       \textcolor{keywordflow}{else}}
\DoxyCodeLine{565         wt(k) = e(k) -\/ e(k+1) ; z1(k) = -\/0.5 ; z2(k) = 0.5}
\DoxyCodeLine{566 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{567       tot\_wt = tot\_wt + wt(k) \textcolor{comment}{! wt(k) is always > 0.}}
\DoxyCodeLine{568       \textcolor{keywordflow}{if} (k>=k\_bot) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{569 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{570 }
\DoxyCodeLine{571     i\_totwt = 0.0 ; \textcolor{keywordflow}{if} (tot\_wt > 0.0) i\_totwt = 1.0 / tot\_wt}
\DoxyCodeLine{572     \textcolor{keywordflow}{do} k=k\_top,k\_bot ; wt(k) = i\_totwt*wt(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{573 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{574 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__z__init_a9f9a4d16dbd230d126b3f4d255071ad8}\label{namespacemom__tracer__z__init_a9f9a4d16dbd230d126b3f4d255071ad8}} 
\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}!read\_z\_edges@{read\_z\_edges}}
\index{read\_z\_edges@{read\_z\_edges}!mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}
\doxysubsubsection{\texorpdfstring{read\_z\_edges()}{read\_z\_edges()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tracer\+\_\+z\+\_\+init\+::read\+\_\+z\+\_\+edges (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{filename,  }\item[{character(len=$\ast$), intent(in)}]{tr\+\_\+name,  }\item[{real, dimension(\+:), intent(out), allocatable}]{z\+\_\+edges,  }\item[{integer, intent(out)}]{nz\+\_\+out,  }\item[{logical, intent(out)}]{has\+\_\+edges,  }\item[{logical, intent(inout)}]{use\+\_\+missing,  }\item[{real, intent(inout)}]{missing,  }\item[{real, intent(in)}]{scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine reads the vertical coordinate data for a field from a Net\+C\+DF file. It also might read the missing value attribute for that same field. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em filename} & The name of the file to read from. \\
\hline
\mbox{\texttt{ in}}  & {\em tr\+\_\+name} & The name of the tracer in the file. \\
\hline
\mbox{\texttt{ out}}  & {\em z\+\_\+edges} & The depths of the vertical edges of the tracer array \\
\hline
\mbox{\texttt{ out}}  & {\em nz\+\_\+out} & The number of vertical layers in the tracer array \\
\hline
\mbox{\texttt{ out}}  & {\em has\+\_\+edges} & If true the values in z\+\_\+edges are the edges of the tracer cells, otherwise they are the cell centers \\
\hline
\mbox{\texttt{ in,out}}  & {\em use\+\_\+missing} & If false on input, see whether the tracer has a missing value, and if so return true \\
\hline
\mbox{\texttt{ in,out}}  & {\em missing} & The missing value, if one has been found \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A scaling factor for z\+\_\+edges into new units. \\
\hline
\end{DoxyParams}


Definition at line 383 of file M\+O\+M\+\_\+tracer\+\_\+\+Z\+\_\+init.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{385   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: filename\textcolor{comment}{ !< The name of the file to read from.}}
\DoxyCodeLine{386   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: tr\_name\textcolor{comment}{ !< The name of the tracer in the file.}}
\DoxyCodeLine{387 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}, \&}
\DoxyCodeLine{388                     \textcolor{keywordtype}{intent(out)}   :: z\_edges\textcolor{comment}{ !< The depths of the vertical edges of the tracer array}}
\DoxyCodeLine{389   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(out)}   :: nz\_out\textcolor{comment}{  !< The number of vertical layers in the tracer array}}
\DoxyCodeLine{390   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(out)}   :: has\_edges\textcolor{comment}{ !< If true the values in z\_edges are the edges of the}}
\DoxyCodeLine{391 \textcolor{comment}{                                             !! tracer cells, otherwise they are the cell centers}}
\DoxyCodeLine{392   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(inout)} :: use\_missing\textcolor{comment}{ !< If false on input, see whether the tracer has a}}
\DoxyCodeLine{393 \textcolor{comment}{                                             !! missing value, and if so return true}}
\DoxyCodeLine{394 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(inout)} :: missing\textcolor{comment}{ !< The missing value, if one has been found}}
\DoxyCodeLine{395 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{   !< A scaling factor for z\_edges into new units.}}
\DoxyCodeLine{396 }
\DoxyCodeLine{397   \textcolor{comment}{!   This subroutine reads the vertical coordinate data for a field from a}}
\DoxyCodeLine{398   \textcolor{comment}{! NetCDF file.  It also might read the missing value attribute for that same field.}}
\DoxyCodeLine{399   \textcolor{keywordtype}{character(len=32)} :: mdl}
\DoxyCodeLine{400   \textcolor{keywordtype}{character(len=120)} :: dim\_name, edge\_name, tr\_msg, dim\_msg}
\DoxyCodeLine{401   \textcolor{keywordtype}{logical} :: monotonic}
\DoxyCodeLine{402   \textcolor{keywordtype}{integer} :: ncid, status, intid, tr\_id, layid, k}
\DoxyCodeLine{403   \textcolor{keywordtype}{integer} :: nz\_edge, ndim, tr\_dim\_ids(NF90\_MAX\_VAR\_DIMS)}
\DoxyCodeLine{404 }
\DoxyCodeLine{405   mdl = \textcolor{stringliteral}{"{}MOM\_tracer\_Z\_init read\_Z\_edges: "{}}}
\DoxyCodeLine{406   tr\_msg = trim(tr\_name)//\textcolor{stringliteral}{"{} in "{}}//trim(filename)}
\DoxyCodeLine{407 }
\DoxyCodeLine{408   status = nf90\_open(filename, nf90\_nowrite, ncid)}
\DoxyCodeLine{409   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{410     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} Difficulties opening "{}}//trim(filename)//\&}
\DoxyCodeLine{411         \textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{412     nz\_out = -\/1 ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{413 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{414 }
\DoxyCodeLine{415   status = nf90\_inq\_varid(ncid, tr\_name, tr\_id)}
\DoxyCodeLine{416   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{417     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} Difficulties finding variable "{}}//\&}
\DoxyCodeLine{418         trim(tr\_msg)//\textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{419     nz\_out = -\/1 ; status = nf90\_close(ncid) ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{420 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{421   status = nf90\_inquire\_variable(ncid, tr\_id, ndims=ndim, dimids=tr\_dim\_ids)}
\DoxyCodeLine{422   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{423     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} cannot inquire about "{}}//trim(tr\_msg))}
\DoxyCodeLine{424   \textcolor{keywordflow}{elseif} ((ndim < 3) .or. (ndim > 4)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{425     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} "{}}//trim(tr\_msg)//\&}
\DoxyCodeLine{426          \textcolor{stringliteral}{"{} has too many or too few dimensions."{}})}
\DoxyCodeLine{427     nz\_out = -\/1 ; status = nf90\_close(ncid) ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{428 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{429 }
\DoxyCodeLine{430   \textcolor{keywordflow}{if} (.not.use\_missing) \textcolor{keywordflow}{then}}
\DoxyCodeLine{431     \textcolor{comment}{! Try to find the missing value from the dataset.}}
\DoxyCodeLine{432     status = nf90\_get\_att(ncid, tr\_id, \textcolor{stringliteral}{"{}missing\_value"{}}, missing)}
\DoxyCodeLine{433     \textcolor{keywordflow}{if} (status /= nf90\_noerr) use\_missing = .true.}
\DoxyCodeLine{434 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{435 }
\DoxyCodeLine{436   \textcolor{comment}{! Get the axis name and length.}}
\DoxyCodeLine{437   status = nf90\_inquire\_dimension(ncid, tr\_dim\_ids(3), dim\_name, len=nz\_out)}
\DoxyCodeLine{438   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{439     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} cannot inquire about dimension(3) of "{}}//\&}
\DoxyCodeLine{440                     trim(tr\_msg))}
\DoxyCodeLine{441 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{442 }
\DoxyCodeLine{443   dim\_msg = trim(dim\_name)//\textcolor{stringliteral}{"{} in "{}}//trim(filename)}
\DoxyCodeLine{444   status = nf90\_inq\_varid(ncid, dim\_name, layid)}
\DoxyCodeLine{445   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{446     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} Difficulties finding variable "{}}//\&}
\DoxyCodeLine{447         trim(dim\_msg)//\textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{448     nz\_out = -\/1 ; status = nf90\_close(ncid) ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{449 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{450   \textcolor{comment}{! Find out if the Z-\/axis has an edges attribute}}
\DoxyCodeLine{451   status = nf90\_get\_att(ncid, layid, \textcolor{stringliteral}{"{}edges"{}}, edge\_name)}
\DoxyCodeLine{452   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{453     \textcolor{keyword}{call }mom\_mesg(mdl//\textcolor{stringliteral}{"{} "{}}//trim(dim\_msg)//\&}
\DoxyCodeLine{454          \textcolor{stringliteral}{"{} has no readable edges attribute -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{455     has\_edges = .false.}
\DoxyCodeLine{456   \textcolor{keywordflow}{else}}
\DoxyCodeLine{457     has\_edges = .true.}
\DoxyCodeLine{458     status = nf90\_inq\_varid(ncid, edge\_name, intid)}
\DoxyCodeLine{459     \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{460       \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} Difficulties finding edge variable "{}}//\&}
\DoxyCodeLine{461           trim(edge\_name)//\textcolor{stringliteral}{"{} in "{}}//trim(filename)//\textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{462       has\_edges = .false.}
\DoxyCodeLine{463 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{464 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{465 }
\DoxyCodeLine{466   nz\_edge = nz\_out ; \textcolor{keywordflow}{if} (has\_edges) nz\_edge = nz\_out+1}
\DoxyCodeLine{467   \textcolor{keyword}{allocate}(z\_edges(nz\_edge)) ; z\_edges(:) = 0.0}
\DoxyCodeLine{468 }
\DoxyCodeLine{469   \textcolor{keywordflow}{if} (nz\_out < 1) \textcolor{keywordflow}{return}}
\DoxyCodeLine{470 }
\DoxyCodeLine{471   \textcolor{comment}{! Read the right variable.}}
\DoxyCodeLine{472   \textcolor{keywordflow}{if} (has\_edges) \textcolor{keywordflow}{then}}
\DoxyCodeLine{473     dim\_msg = trim(edge\_name)//\textcolor{stringliteral}{"{} in "{}}//trim(filename)}
\DoxyCodeLine{474     status = nf90\_get\_var(ncid, intid, z\_edges)}
\DoxyCodeLine{475     \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{476       \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} Difficulties reading variable "{}}//\&}
\DoxyCodeLine{477           trim(dim\_msg)//\textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{478       nz\_out = -\/1 ; status = nf90\_close(ncid) ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{479 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{480   \textcolor{keywordflow}{else}}
\DoxyCodeLine{481     status = nf90\_get\_var(ncid, layid, z\_edges)}
\DoxyCodeLine{482     \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483       \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} Difficulties reading variable "{}}//\&}
\DoxyCodeLine{484           trim(dim\_msg)//\textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{485       nz\_out = -\/1 ; status = nf90\_close(ncid) ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{486 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{487 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{488 }
\DoxyCodeLine{489   status = nf90\_close(ncid)}
\DoxyCodeLine{490   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keyword}{call }mom\_error(warning, mdl// \&}
\DoxyCodeLine{491     \textcolor{stringliteral}{"{} Difficulties closing "{}}//trim(filename)//\textcolor{stringliteral}{"{} -\/ "{}}//trim(nf90\_strerror(status)))}
\DoxyCodeLine{492 }
\DoxyCodeLine{493   \textcolor{comment}{! z\_edges should be montonically decreasing with our sign convention.}}
\DoxyCodeLine{494   \textcolor{comment}{! Change the sign sign convention if it looks like z\_edges is increasing.}}
\DoxyCodeLine{495   \textcolor{keywordflow}{if} (z\_edges(1) < z\_edges(2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{496     \textcolor{keywordflow}{do} k=1,nz\_edge ; z\_edges(k) = -\/z\_edges(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{497 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{498   \textcolor{comment}{! Check that z\_edges is now monotonically decreasing.}}
\DoxyCodeLine{499   monotonic = .true.}
\DoxyCodeLine{500   \textcolor{keywordflow}{do} k=2,nz\_edge ; \textcolor{keywordflow}{if} (z\_edges(k) >= z\_edges(k-\/1)) monotonic = .false. ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{501   \textcolor{keywordflow}{if} (.not.monotonic) \&}
\DoxyCodeLine{502     \textcolor{keyword}{call }mom\_error(warning,mdl//\textcolor{stringliteral}{"{} "{}}//trim(dim\_msg)//\textcolor{stringliteral}{"{} is not monotonic."{}})}
\DoxyCodeLine{503 }
\DoxyCodeLine{504   \textcolor{keywordflow}{if} (scale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz\_edge ; z\_edges(k) = scale*z\_edges(k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{505 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__z__init_aef33387149983391f1ea92bad7344360}\label{namespacemom__tracer__z__init_aef33387149983391f1ea92bad7344360}} 
\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}!tracer\_z\_init@{tracer\_z\_init}}
\index{tracer\_z\_init@{tracer\_z\_init}!mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}
\doxysubsubsection{\texorpdfstring{tracer\_z\_init()}{tracer\_z\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+tracer\+\_\+z\+\_\+init\+::tracer\+\_\+z\+\_\+init (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{tr,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{character(len=$\ast$), intent(in)}]{filename,  }\item[{character(len=$\ast$), intent(in)}]{tr\+\_\+name,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{real, intent(in), optional}]{missing\+\_\+val,  }\item[{real, intent(in), optional}]{land\+\_\+val }\end{DoxyParamCaption})}



This function initializes a tracer by reading a Z-\/space file, returning .true. if this appears to have been successful, and false otherwise. 

\begin{DoxyReturn}{Returns}
A return code indicating if the initialization has been successful 
\end{DoxyReturn}

\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ out}}  & {\em tr} & The tracer to initialize \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em filename} & The name of the file to read from \\
\hline
\mbox{\texttt{ in}}  & {\em tr\+\_\+name} & The name of the tracer in the file \\
\hline
\mbox{\texttt{ in}}  & {\em missing\+\_\+val} & The missing value for the tracer \\
\hline
\mbox{\texttt{ in}}  & {\em land\+\_\+val} & A value to use to fill in land points \\
\hline
\end{DoxyParams}


Definition at line 30 of file M\+O\+M\+\_\+tracer\+\_\+\+Z\+\_\+init.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{31   \textcolor{keywordtype}{logical} :: tracer\_Z\_init\textcolor{comment}{ !< A return code indicating if the initialization has been successful}}
\DoxyCodeLine{32   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{33   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{34 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{35                          \textcolor{keywordtype}{intent(out)}   :: tr\textcolor{comment}{   !< The tracer to initialize}}
\DoxyCodeLine{36 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{37                          \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{38   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: filename\textcolor{comment}{ !< The name of the file to read from}}
\DoxyCodeLine{39   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: tr\_name\textcolor{comment}{ !< The name of the tracer in the file}}
\DoxyCodeLine{40 \textcolor{comment}{! type(param\_file\_type), intent(in)    :: param\_file !< A structure to parse for run-\/time parameters}}
\DoxyCodeLine{41 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: missing\_val\textcolor{comment}{ !< The missing value for the tracer}}
\DoxyCodeLine{42 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: land\_val\textcolor{comment}{ !< A value to use to fill in land points}}
\DoxyCodeLine{43 }
\DoxyCodeLine{44   \textcolor{comment}{!   This function initializes a tracer by reading a Z-\/space file, returning true if this}}
\DoxyCodeLine{45   \textcolor{comment}{! appears to have been successful, and false otherwise.}}
\DoxyCodeLine{46 \textcolor{comment}{!}}
\DoxyCodeLine{47   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{save} :: init\_calls = 0}
\DoxyCodeLine{48 \textcolor{comment}{! This include declares and sets the variable "{}version"{}.}}
\DoxyCodeLine{49 \textcolor{preprocessor}{\#include "{}version\_variable.h"{}}}
\DoxyCodeLine{50 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}MOM\_tracer\_Z\_init"{}} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{51   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}}
\DoxyCodeLine{52 }
\DoxyCodeLine{53 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: \&}
\DoxyCodeLine{54     tr\_in   \textcolor{comment}{! The z-\/space array of tracer concentrations that is read in.}}
\DoxyCodeLine{55 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: \&}
\DoxyCodeLine{56     z\_edges, \&  \textcolor{comment}{! The depths of the cell edges or cell centers (depending on}}
\DoxyCodeLine{57                 \textcolor{comment}{! the value of has\_edges) in the input z* data [Z \string~> m].}}
\DoxyCodeLine{58     tr\_1d, \&    \textcolor{comment}{! A copy of the input tracer concentrations in a column.}}
\DoxyCodeLine{59     wt, \&   \textcolor{comment}{! The fractional weight for each layer in the range between}}
\DoxyCodeLine{60             \textcolor{comment}{! k\_top and k\_bot, nondim.}}
\DoxyCodeLine{61     z1, \&   \textcolor{comment}{! z1 and z2 are the depths of the top and bottom limits of the part}}
\DoxyCodeLine{62     z2      \textcolor{comment}{! of a z-\/cell that contributes to a layer, relative to the cell}}
\DoxyCodeLine{63             \textcolor{comment}{! center and normalized by the cell thickness, nondim.}}
\DoxyCodeLine{64             \textcolor{comment}{! Note that -\/1/2 <= z1 <= z2 <= 1/2.}}
\DoxyCodeLine{65 \textcolor{keywordtype}{  real}    :: e(SZK\_(G)+1)  \textcolor{comment}{! The z-\/star interface heights [Z \string~> m].}}
\DoxyCodeLine{66 \textcolor{keywordtype}{  real}    :: landval    \textcolor{comment}{! The tracer value to use in land points.}}
\DoxyCodeLine{67 \textcolor{keywordtype}{  real}    :: sl\_tr      \textcolor{comment}{! The normalized slope of the tracer}}
\DoxyCodeLine{68                         \textcolor{comment}{! within the cell, in tracer units.}}
\DoxyCodeLine{69 \textcolor{keywordtype}{  real}    :: htot(SZI\_(G)) \textcolor{comment}{! The vertical sum of h [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{70 \textcolor{keywordtype}{  real}    :: dilate     \textcolor{comment}{! The amount by which the thicknesses are dilated to}}
\DoxyCodeLine{71                         \textcolor{comment}{! create a z-\/star coordinate, nondim or in m3 kg-\/1.}}
\DoxyCodeLine{72 \textcolor{keywordtype}{  real}    :: missing    \textcolor{comment}{! The missing value for the tracer.}}
\DoxyCodeLine{73 }
\DoxyCodeLine{74   \textcolor{keywordtype}{logical} :: has\_edges, use\_missing, zero\_surface}
\DoxyCodeLine{75   \textcolor{keywordtype}{character(len=80)} :: loc\_msg}
\DoxyCodeLine{76   \textcolor{keywordtype}{integer} :: k\_top, k\_bot, k\_bot\_prev, k\_start}
\DoxyCodeLine{77   \textcolor{keywordtype}{integer} :: i, j, k, kz, is, ie, js, je, nz, nz\_in}
\DoxyCodeLine{78   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{79 }
\DoxyCodeLine{80   landval = 0.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(land\_val)) landval = land\_val}
\DoxyCodeLine{81 }
\DoxyCodeLine{82   zero\_surface = .false. \textcolor{comment}{! Make this false for errors to be fatal.}}
\DoxyCodeLine{83 }
\DoxyCodeLine{84   use\_missing = .false.}
\DoxyCodeLine{85   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(missing\_val)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{86     use\_missing = .true. ; missing = missing\_val}
\DoxyCodeLine{87 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{88 }
\DoxyCodeLine{89   \textcolor{comment}{! Find out the number of input levels and read the depth of the edges,}}
\DoxyCodeLine{90   \textcolor{comment}{! also modifying their sign convention to be monotonically decreasing.}}
\DoxyCodeLine{91   \textcolor{keyword}{call }read\_z\_edges(filename, tr\_name, z\_edges, nz\_in, has\_edges, use\_missing, \&}
\DoxyCodeLine{92                     missing, scale=us\%m\_to\_Z)}
\DoxyCodeLine{93   \textcolor{keywordflow}{if} (nz\_in < 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{94     tracer\_z\_init = .false.}
\DoxyCodeLine{95     \textcolor{keywordflow}{return}}
\DoxyCodeLine{96 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{97 }
\DoxyCodeLine{98   \textcolor{keyword}{allocate}(tr\_in(g\%isd:g\%ied,g\%jsd:g\%jed,nz\_in)) ; tr\_in(:,:,:) = 0.0}
\DoxyCodeLine{99   \textcolor{keyword}{allocate}(tr\_1d(nz\_in)) ; tr\_1d(:) = 0.0}
\DoxyCodeLine{100   \textcolor{keyword}{call }mom\_read\_data(filename, tr\_name, tr\_in(:,:,:), g\%Domain)}
\DoxyCodeLine{101 }
\DoxyCodeLine{102   \textcolor{comment}{! Fill missing values from above?  Use a "{}close"{} test to avoid problems}}
\DoxyCodeLine{103   \textcolor{comment}{! from type-\/conversion rounoff.}}
\DoxyCodeLine{104   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(missing\_val)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{105     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{106       \textcolor{keywordflow}{if} (g\%mask2dT(i,j) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{107         tr\_in(i,j,1) = landval}
\DoxyCodeLine{108       \textcolor{keywordflow}{elseif} (abs(tr\_in(i,j,1) -\/ missing\_val) <= 1e-\/6*abs(missing\_val)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{109         \textcolor{keyword}{write}(loc\_msg,\textcolor{stringliteral}{'(f7.2,"{} N "{},f7.2,"{} E"{})'}) g\%geoLatT(i,j), g\%geoLonT(i,j)}
\DoxyCodeLine{110         \textcolor{keywordflow}{if} (zero\_surface) \textcolor{keywordflow}{then}}
\DoxyCodeLine{111           \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}tracer\_Z\_init: Missing value of "{}}// \&}
\DoxyCodeLine{112                 trim(tr\_name)//\textcolor{stringliteral}{"{} found in an ocean point at "{}}//trim(loc\_msg)// \&}
\DoxyCodeLine{113                 \textcolor{stringliteral}{"{} in "{}}//trim(filename) )}
\DoxyCodeLine{114           tr\_in(i,j,1) = 0.0}
\DoxyCodeLine{115         \textcolor{keywordflow}{else}}
\DoxyCodeLine{116           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}tracer\_Z\_init: Missing value of "{}}// \&}
\DoxyCodeLine{117                 trim(tr\_name)//\textcolor{stringliteral}{"{} found in an ocean point at "{}}//trim(loc\_msg)// \&}
\DoxyCodeLine{118                 \textcolor{stringliteral}{"{} in "{}}//trim(filename) )}
\DoxyCodeLine{119 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{120 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{121 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{122     \textcolor{keywordflow}{do} k=2,nz\_in ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{123       \textcolor{keywordflow}{if} (abs(tr\_in(i,j,k) -\/ missing\_val) <= 1e-\/6*abs(missing\_val)) \&}
\DoxyCodeLine{124         tr\_in(i,j,k) = tr\_in(i,j,k-\/1)}
\DoxyCodeLine{125 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{126 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{127 }
\DoxyCodeLine{128   \textcolor{keyword}{allocate}(wt(nz\_in+1)) ; \textcolor{keyword}{allocate}(z1(nz\_in+1)) ; \textcolor{keyword}{allocate}(z2(nz\_in+1))}
\DoxyCodeLine{129 }
\DoxyCodeLine{130   \textcolor{comment}{! This is a placeholder, and will be replaced with our full vertical}}
\DoxyCodeLine{131   \textcolor{comment}{! interpolation machinery when it is in place.}}
\DoxyCodeLine{132   \textcolor{keywordflow}{if} (has\_edges) \textcolor{keywordflow}{then}}
\DoxyCodeLine{133     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{134       \textcolor{keywordflow}{do} i=is,ie ; htot(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{135       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie ; htot(i) = htot(i) + h(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{136 }
\DoxyCodeLine{137       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j)*htot(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{138         \textcolor{comment}{! Determine the z* heights of the model interfaces.}}
\DoxyCodeLine{139         dilate = (g\%bathyT(i,j) -\/ 0.0) / htot(i)}
\DoxyCodeLine{140         e(nz+1) = -\/g\%bathyT(i,j)}
\DoxyCodeLine{141         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; e(k) = e(k+1) + dilate * h(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{142 }
\DoxyCodeLine{143         \textcolor{comment}{! Create a single-\/column copy of tr\_in.  Efficiency is not an issue here.}}
\DoxyCodeLine{144         \textcolor{keywordflow}{do} k=1,nz\_in ; tr\_1d(k) = tr\_in(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{145         k\_bot = 1 ; k\_bot\_prev = -\/1}
\DoxyCodeLine{146         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{147           \textcolor{keywordflow}{if} (e(k+1) > z\_edges(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{148             tr(i,j,k) = tr\_1d(1)}
\DoxyCodeLine{149           \textcolor{keywordflow}{elseif} (e(k) < z\_edges(nz\_in+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{150             tr(i,j,k) = tr\_1d(nz\_in)}
\DoxyCodeLine{151           \textcolor{keywordflow}{else}}
\DoxyCodeLine{152             k\_start = k\_bot \textcolor{comment}{! The starting point for this search}}
\DoxyCodeLine{153             \textcolor{keyword}{call }find\_overlap(z\_edges, e(k), e(k+1), nz\_in, \&}
\DoxyCodeLine{154                               k\_start, k\_top, k\_bot, wt, z1, z2)}
\DoxyCodeLine{155             kz = k\_top}
\DoxyCodeLine{156             \textcolor{keywordflow}{if} (kz /= k\_bot\_prev) \textcolor{keywordflow}{then}}
\DoxyCodeLine{157               \textcolor{comment}{! Calculate the intra-\/cell profile.}}
\DoxyCodeLine{158               sl\_tr = 0.0 \textcolor{comment}{! ; cur\_tr = 0.0}}
\DoxyCodeLine{159               \textcolor{keywordflow}{if} ((kz < nz\_in) .and. (kz > 1)) \&}
\DoxyCodeLine{160                 sl\_tr = find\_limited\_slope(tr\_1d, z\_edges, kz)}
\DoxyCodeLine{161 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{162             \textcolor{comment}{! This is the piecewise linear form.}}
\DoxyCodeLine{163             tr(i,j,k) = wt(kz) * (tr\_1d(kz) + 0.5*sl\_tr*(z2(kz) + z1(kz)))}
\DoxyCodeLine{164             \textcolor{comment}{! For the piecewise parabolic form add the following...}}
\DoxyCodeLine{165             \textcolor{comment}{!     + C1\_3*cur\_tr*(z2(kz)**2 + z2(kz)*z1(kz) + z1(kz)**2))}}
\DoxyCodeLine{166             \textcolor{keywordflow}{do} kz=k\_top+1,k\_bot-\/1}
\DoxyCodeLine{167               tr(i,j,k) = tr(i,j,k) + wt(kz)*tr\_1d(kz)}
\DoxyCodeLine{168 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{169             \textcolor{keywordflow}{if} (k\_bot > k\_top) \textcolor{keywordflow}{then}}
\DoxyCodeLine{170               kz = k\_bot}
\DoxyCodeLine{171               \textcolor{comment}{! Calculate the intra-\/cell profile.}}
\DoxyCodeLine{172               sl\_tr = 0.0 \textcolor{comment}{! ; cur\_tr = 0.0}}
\DoxyCodeLine{173               \textcolor{keywordflow}{if} ((kz < nz\_in) .and. (kz > 1)) \&}
\DoxyCodeLine{174                 sl\_tr = find\_limited\_slope(tr\_1d, z\_edges, kz)}
\DoxyCodeLine{175               \textcolor{comment}{! This is the piecewise linear form.}}
\DoxyCodeLine{176               tr(i,j,k) = tr(i,j,k) + wt(kz) * \&}
\DoxyCodeLine{177                   (tr\_1d(kz) + 0.5*sl\_tr*(z2(kz) + z1(kz)))}
\DoxyCodeLine{178               \textcolor{comment}{! For the piecewise parabolic form add the following...}}
\DoxyCodeLine{179               \textcolor{comment}{!     + C1\_3*cur\_tr*(z2(kz)**2 + z2(kz)*z1(kz) + z1(kz)**2))}}
\DoxyCodeLine{180 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{181             k\_bot\_prev = k\_bot}
\DoxyCodeLine{182 }
\DoxyCodeLine{183             \textcolor{comment}{!   Now handle the unlikely case where the layer partially extends}}
\DoxyCodeLine{184             \textcolor{comment}{! past the valid range of the input data by extrapolating using}}
\DoxyCodeLine{185             \textcolor{comment}{! the top or bottom value.}}
\DoxyCodeLine{186             \textcolor{keywordflow}{if} ((e(k) > z\_edges(1)) .and. (z\_edges(nz\_in+1) > e(k+1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{187               tr(i,j,k) = (((e(k) -\/ z\_edges(1)) * tr\_1d(1) + \&}
\DoxyCodeLine{188                            (z\_edges(1) -\/ z\_edges(nz\_in)) * tr(i,j,k)) + \&}
\DoxyCodeLine{189                            (z\_edges(nz\_in+1) -\/ e(k+1)) * tr\_1d(nz\_in)) / \&}
\DoxyCodeLine{190                           (e(k) -\/ e(k+1))}
\DoxyCodeLine{191             \textcolor{keywordflow}{elseif} (e(k) > z\_edges(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{192               tr(i,j,k) = ((e(k) -\/ z\_edges(1)) * tr\_1d(1) + \&}
\DoxyCodeLine{193                            (z\_edges(1) -\/ e(k+1)) * tr(i,j,k)) / \&}
\DoxyCodeLine{194                           (e(k) -\/ e(k+1))}
\DoxyCodeLine{195             \textcolor{keywordflow}{elseif} (z\_edges(nz\_in) > e(k+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{196               tr(i,j,k) = ((e(k) -\/ z\_edges(nz\_in+1)) * tr(i,j,k) + \&}
\DoxyCodeLine{197                            (z\_edges(nz\_in+1) -\/ e(k+1)) * tr\_1d(nz\_in)) / \&}
\DoxyCodeLine{198                           (e(k) -\/ e(k+1))}
\DoxyCodeLine{199 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{200 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{201 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! k-\/loop}}
\DoxyCodeLine{202       \textcolor{keywordflow}{else}}
\DoxyCodeLine{203         \textcolor{keywordflow}{do} k=1,nz ; tr(i,j,k) = landval ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{204 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{205 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! j-\/loop}}
\DoxyCodeLine{206   \textcolor{keywordflow}{else}}
\DoxyCodeLine{207     \textcolor{comment}{! Without edge values, integrate a linear interpolation between cell centers.}}
\DoxyCodeLine{208     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{209       \textcolor{keywordflow}{do} i=is,ie ; htot(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{210       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie ; htot(i) = htot(i) + h(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{211 }
\DoxyCodeLine{212       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j)*htot(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{213         \textcolor{comment}{! Determine the z* heights of the model interfaces.}}
\DoxyCodeLine{214         dilate = (g\%bathyT(i,j) -\/ 0.0) / htot(i)}
\DoxyCodeLine{215         e(nz+1) = -\/g\%bathyT(i,j)}
\DoxyCodeLine{216         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; e(k) = e(k+1) + dilate * h(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{217 }
\DoxyCodeLine{218         \textcolor{comment}{! Create a single-\/column copy of tr\_in.  Efficiency is not an issue here.}}
\DoxyCodeLine{219         \textcolor{keywordflow}{do} k=1,nz\_in ; tr\_1d(k) = tr\_in(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{220         k\_bot = 1}
\DoxyCodeLine{221         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{222           \textcolor{keywordflow}{if} (e(k+1) > z\_edges(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{223             tr(i,j,k) = tr\_1d(1)}
\DoxyCodeLine{224           \textcolor{keywordflow}{elseif} (z\_edges(nz\_in) > e(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{225             tr(i,j,k) = tr\_1d(nz\_in)}
\DoxyCodeLine{226           \textcolor{keywordflow}{else}}
\DoxyCodeLine{227             k\_start = k\_bot \textcolor{comment}{! The starting point for this search}}
\DoxyCodeLine{228             \textcolor{keyword}{call }find\_overlap(z\_edges, e(k), e(k+1), nz\_in-\/1, \&}
\DoxyCodeLine{229                               k\_start, k\_top, k\_bot, wt, z1, z2)}
\DoxyCodeLine{230 }
\DoxyCodeLine{231             kz = k\_top}
\DoxyCodeLine{232             \textcolor{keywordflow}{if} (k\_top < nz\_in) \textcolor{keywordflow}{then}}
\DoxyCodeLine{233               tr(i,j,k) = wt(kz)*0.5*((tr\_1d(kz) + tr\_1d(kz+1)) + \&}
\DoxyCodeLine{234                                       (tr\_1d(kz+1) -\/ tr\_1d(kz))*(z2(kz)+z1(kz)))}
\DoxyCodeLine{235             \textcolor{keywordflow}{else}}
\DoxyCodeLine{236               tr(i,j,k) = wt(kz)*tr\_1d(nz\_in)}
\DoxyCodeLine{237 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{238             \textcolor{keywordflow}{do} kz=k\_top+1,k\_bot-\/1}
\DoxyCodeLine{239               tr(i,j,k) = tr(i,j,k) + wt(kz)*0.5*(tr\_1d(kz) + tr\_1d(kz+1))}
\DoxyCodeLine{240 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{241             \textcolor{keywordflow}{if} (k\_bot > k\_top) \textcolor{keywordflow}{then}}
\DoxyCodeLine{242               kz = k\_bot}
\DoxyCodeLine{243               tr(i,j,k) = tr(i,j,k) + wt(kz)*0.5*((tr\_1d(kz) + tr\_1d(kz+1)) + \&}
\DoxyCodeLine{244                                         (tr\_1d(kz+1) -\/ tr\_1d(kz))*(z2(kz)+z1(kz)))}
\DoxyCodeLine{245 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{246 }
\DoxyCodeLine{247             \textcolor{comment}{! Now handle the case where the layer partially extends past}}
\DoxyCodeLine{248             \textcolor{comment}{! the valid range of the input data.}}
\DoxyCodeLine{249             \textcolor{keywordflow}{if} ((e(k) > z\_edges(1)) .and. (z\_edges(nz\_in) > e(k+1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{250               tr(i,j,k) = (((e(k) -\/ z\_edges(1)) * tr\_1d(1) + \&}
\DoxyCodeLine{251                            (z\_edges(1) -\/ z\_edges(nz\_in)) * tr(i,j,k)) + \&}
\DoxyCodeLine{252                            (z\_edges(nz\_in) -\/ e(k+1)) * tr\_1d(nz\_in)) / \&}
\DoxyCodeLine{253                           (e(k) -\/ e(k+1))}
\DoxyCodeLine{254             \textcolor{keywordflow}{elseif} (e(k) > z\_edges(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{255               tr(i,j,k) = ((e(k) -\/ z\_edges(1)) * tr\_1d(1) + \&}
\DoxyCodeLine{256                            (z\_edges(1) -\/ e(k+1)) * tr(i,j,k)) / \&}
\DoxyCodeLine{257                           (e(k) -\/ e(k+1))}
\DoxyCodeLine{258             \textcolor{keywordflow}{elseif} (z\_edges(nz\_in) > e(k+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{259               tr(i,j,k) = ((e(k) -\/ z\_edges(nz\_in)) * tr(i,j,k) + \&}
\DoxyCodeLine{260                            (z\_edges(nz\_in) -\/ e(k+1)) * tr\_1d(nz\_in)) / \&}
\DoxyCodeLine{261                           (e(k) -\/ e(k+1))}
\DoxyCodeLine{262 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{263 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{264 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{265       \textcolor{keywordflow}{else}}
\DoxyCodeLine{266         \textcolor{keywordflow}{do} k=1,nz ; tr(i,j,k) = landval ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{267 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{268 \textcolor{keywordflow}{    enddo}  \textcolor{comment}{! j-\/loop}}
\DoxyCodeLine{269 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{270 }
\DoxyCodeLine{271   \textcolor{keyword}{deallocate}(tr\_in) ; \textcolor{keyword}{deallocate}(tr\_1d) ; \textcolor{keyword}{deallocate}(z\_edges)}
\DoxyCodeLine{272   \textcolor{keyword}{deallocate}(wt) ; \textcolor{keyword}{deallocate}(z1) ; \textcolor{keyword}{deallocate}(z2)}
\DoxyCodeLine{273 }
\DoxyCodeLine{274   tracer\_z\_init = .true.}
\DoxyCodeLine{275 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__z__init_a2c439cbda792bb711a62094bbe779aec}\label{namespacemom__tracer__z__init_a2c439cbda792bb711a62094bbe779aec}} 
\index{mom\_tracer\_z\_init@{mom\_tracer\_z\_init}!tracer\_z\_init\_array@{tracer\_z\_init\_array}}
\index{tracer\_z\_init\_array@{tracer\_z\_init\_array}!mom\_tracer\_z\_init@{mom\_tracer\_z\_init}}
\doxysubsubsection{\texorpdfstring{tracer\_z\_init\_array()}{tracer\_z\_init\_array()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+z\+\_\+init\+::tracer\+\_\+z\+\_\+init\+\_\+array (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),nk\+\_\+data), intent(in)}]{tr\+\_\+in,  }\item[{real, dimension(nk\+\_\+data+1), intent(in)}]{z\+\_\+edges,  }\item[{integer, intent(in)}]{nk\+\_\+data,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),nlay+1), intent(in)}]{e,  }\item[{real, intent(in)}]{land\+\_\+fill,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{integer, intent(in)}]{nlay,  }\item[{integer, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{nlevs,  }\item[{real, intent(in)}]{eps\+\_\+z,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),nlay), intent(out)}]{tr }\end{DoxyParamCaption})}



Layer model routine for remapping tracers from pseudo-\/z coordinates into layers defined by target interface positions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em nk\+\_\+data} & The number of levels in the input data \\
\hline
\mbox{\texttt{ in}}  & {\em tr\+\_\+in} & The z-\/space array of tracer concentrations that is read in. \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+edges} & The depths of the cell edges in the input z$\ast$ data \mbox{[}Z $\sim$$>$ m or m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nlay} & The number of vertical layers in the target grid \\
\hline
\mbox{\texttt{ in}}  & {\em e} & The depths of the target layer interfaces \mbox{[}Z $\sim$$>$ m or m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em land\+\_\+fill} & fill in data over land (1) \\
\hline
\mbox{\texttt{ in}}  & {\em nlevs} & The number of input levels with valid data \\
\hline
\mbox{\texttt{ in}}  & {\em eps\+\_\+z} & A negligibly thin layer thickness \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em tr} & tracers in layer space \\
\hline
\end{DoxyParams}


Definition at line 280 of file M\+O\+M\+\_\+tracer\+\_\+\+Z\+\_\+init.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{282   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{     !< The ocean's grid structure}}
\DoxyCodeLine{283   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}  :: nk\_data\textcolor{comment}{ !< The number of levels in the input data}}
\DoxyCodeLine{284 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),nk\_data)}, \&}
\DoxyCodeLine{285                               \textcolor{keywordtype}{intent(in)}  :: tr\_in\textcolor{comment}{ !< The z-\/space array of tracer concentrations that is read in.}}
\DoxyCodeLine{286 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk\_data+1)}, \textcolor{keywordtype}{intent(in)}  :: z\_edges\textcolor{comment}{ !< The depths of the cell edges in the input z* data}}
\DoxyCodeLine{287 \textcolor{comment}{                                                          !! [Z \string~> m or m]}}
\DoxyCodeLine{288   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}  :: nlay\textcolor{comment}{ !< The number of vertical layers in the target grid}}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),nlay+1)}, \&}
\DoxyCodeLine{290                               \textcolor{keywordtype}{intent(in)}  :: e\textcolor{comment}{ !< The depths of the target layer interfaces [Z \string~> m or m]}}
\DoxyCodeLine{291 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in)}  :: land\_fill\textcolor{comment}{ !< fill in data over land (1)}}
\DoxyCodeLine{292   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{293                               \textcolor{keywordtype}{intent(in)}  :: nlevs\textcolor{comment}{ !< The number of input levels with valid data}}
\DoxyCodeLine{294 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in)}  :: eps\_z\textcolor{comment}{ !< A negligibly thin layer thickness [Z \string~> m].}}
\DoxyCodeLine{295 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),nlay)}, \&}
\DoxyCodeLine{296                               \textcolor{keywordtype}{intent(out)} :: tr\textcolor{comment}{ !< tracers in layer space}}
\DoxyCodeLine{297 }
\DoxyCodeLine{298   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{299 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk\_data)} :: tr\_1d\textcolor{comment}{ !< a copy of the input tracer concentrations in a column.}}
\DoxyCodeLine{300 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nlay+1)}  :: e\_1d  \textcolor{comment}{! A 1-\/d column of intreface heights, in the same units as e.}}
\DoxyCodeLine{301 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nlay)}    :: tr\_   \textcolor{comment}{! A 1-\/d column of output tracer concentrations}}
\DoxyCodeLine{302   \textcolor{keywordtype}{integer} :: k\_top, k\_bot, k\_bot\_prev, kstart}
\DoxyCodeLine{303 \textcolor{keywordtype}{  real}    :: sl\_tr    \textcolor{comment}{! The tracer concentration slope times the layer thickness, in tracer units.}}
\DoxyCodeLine{304 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk\_data)} :: wt\textcolor{comment}{ !< The fractional weight for each layer in the range between z1 and z2}}
\DoxyCodeLine{305 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk\_data)} :: z1, z2 \textcolor{comment}{! z1 and z2 are the fractional depths of the top and bottom}}
\DoxyCodeLine{306                                   \textcolor{comment}{! limits of the part of a z-\/cell that contributes to a layer, relative}}
\DoxyCodeLine{307                                   \textcolor{comment}{! to the cell center and normalized by the cell thickness [nondim].}}
\DoxyCodeLine{308                                   \textcolor{comment}{! Note that -\/1/2 <= z1 <= z2 <= 1/2.}}
\DoxyCodeLine{309   \textcolor{keywordtype}{integer} :: i, j, k, kz, is, ie, js, je}
\DoxyCodeLine{310 }
\DoxyCodeLine{311   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{312 }
\DoxyCodeLine{313   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{314     i\_loop: \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{315       \textcolor{keywordflow}{if} (nlevs(i,j) == 0 .or. g\%mask2dT(i,j) == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{316         tr(i,j,:) = land\_fill}
\DoxyCodeLine{317         cycle i\_loop}
\DoxyCodeLine{318 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{319 }
\DoxyCodeLine{320       \textcolor{keywordflow}{do} k=1,nk\_data}
\DoxyCodeLine{321         tr\_1d(k) = tr\_in(i,j,k)}
\DoxyCodeLine{322 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{323 }
\DoxyCodeLine{324       \textcolor{keywordflow}{do} k=1,nlay+1}
\DoxyCodeLine{325         e\_1d(k) = e(i,j,k)}
\DoxyCodeLine{326 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{327       k\_bot = 1 ; k\_bot\_prev = -\/1}
\DoxyCodeLine{328       \textcolor{keywordflow}{do} k=1,nlay}
\DoxyCodeLine{329         \textcolor{keywordflow}{if} (e\_1d(k+1) > z\_edges(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{330           tr(i,j,k) = tr\_1d(1)}
\DoxyCodeLine{331         \textcolor{keywordflow}{elseif} (e\_1d(k) < z\_edges(nlevs(i,j)+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{332           tr(i,j,k) = tr\_1d(nlevs(i,j))}
\DoxyCodeLine{333 }
\DoxyCodeLine{334         \textcolor{keywordflow}{else}}
\DoxyCodeLine{335           kstart = k\_bot}
\DoxyCodeLine{336           \textcolor{keyword}{call }find\_overlap(z\_edges, e\_1d(k), e\_1d(k+1), nlevs(i,j), \&}
\DoxyCodeLine{337                             kstart, k\_top, k\_bot, wt, z1, z2)}
\DoxyCodeLine{338           kz = k\_top}
\DoxyCodeLine{339           sl\_tr = 0.0 \textcolor{comment}{! ; cur\_tr=0.0}}
\DoxyCodeLine{340           \textcolor{keywordflow}{if} (kz /= k\_bot\_prev) \textcolor{keywordflow}{then}}
\DoxyCodeLine{341             \textcolor{comment}{! Calculate the intra-\/cell profile.}}
\DoxyCodeLine{342             \textcolor{keywordflow}{if} ((kz < nlevs(i,j)) .and. (kz > 1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{343               sl\_tr = find\_limited\_slope(tr\_1d, z\_edges, kz)}
\DoxyCodeLine{344 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{345 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{346           \textcolor{keywordflow}{if} (kz > nlevs(i,j)) kz = nlevs(i,j)}
\DoxyCodeLine{347           \textcolor{comment}{! This is the piecewise linear form.}}
\DoxyCodeLine{348           tr(i,j,k) = wt(kz) * (tr\_1d(kz) + 0.5*sl\_tr*(z2(kz) + z1(kz)))}
\DoxyCodeLine{349           \textcolor{comment}{! For the piecewise parabolic form add the following...}}
\DoxyCodeLine{350           \textcolor{comment}{!     + C1\_3*wt(kz) * cur\_tr*(z2(kz)**2 + z2(kz)*z1(kz) + z1(kz)**2))}}
\DoxyCodeLine{351           \textcolor{keywordflow}{do} kz=k\_top+1,k\_bot-\/1}
\DoxyCodeLine{352             tr(i,j,k) = tr(i,j,k) + wt(kz)*tr\_1d(kz)}
\DoxyCodeLine{353 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{354 }
\DoxyCodeLine{355           \textcolor{keywordflow}{if} (k\_bot > k\_top) \textcolor{keywordflow}{then}}
\DoxyCodeLine{356             kz = k\_bot}
\DoxyCodeLine{357             \textcolor{comment}{! Calculate the intra-\/cell profile.}}
\DoxyCodeLine{358             sl\_tr = 0.0 \textcolor{comment}{! ; cur\_tr = 0.0}}
\DoxyCodeLine{359             \textcolor{keywordflow}{if} ((kz < nlevs(i,j)) .and. (kz > 1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{360               sl\_tr = find\_limited\_slope(tr\_1d, z\_edges, kz)}
\DoxyCodeLine{361 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{362             \textcolor{comment}{! This is the piecewise linear form.}}
\DoxyCodeLine{363             tr(i,j,k) = tr(i,j,k) + wt(kz) * (tr\_1d(kz) + 0.5*sl\_tr*(z2(kz) + z1(kz)))}
\DoxyCodeLine{364             \textcolor{comment}{! For the piecewise parabolic form add the following...}}
\DoxyCodeLine{365             \textcolor{comment}{!     + C1\_3*cur\_tr*(z2(kz)**2 + z2(kz)*z1(kz) + z1(kz)**2))}}
\DoxyCodeLine{366 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{367           k\_bot\_prev = k\_bot}
\DoxyCodeLine{368 }
\DoxyCodeLine{369 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{370 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-\/loop}}
\DoxyCodeLine{371 }
\DoxyCodeLine{372       \textcolor{keywordflow}{do} k=2,nlay  \textcolor{comment}{! simply fill vanished layers with adjacent value}}
\DoxyCodeLine{373         \textcolor{keywordflow}{if} (e\_1d(k)-\/e\_1d(k+1) <= eps\_z) tr(i,j,k) = tr(i,j,k-\/1)}
\DoxyCodeLine{374 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{375 }
\DoxyCodeLine{376 \textcolor{keywordflow}{    enddo} i\_loop}
\DoxyCodeLine{377 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{378 }

\end{DoxyCode}
