\hypertarget{namespacemom__tracer__initialization__from__z}{}\section{mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z Module Reference}
\label{namespacemom__tracer__initialization__from__z}\index{mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z@{mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z}}


\subsection{Detailed Description}
Initializes hydrography from z-\/coordinate climatology files. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__initialization__from__z_ad1570db6534aa3b22bdc5dffef561458}{mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z}} (h, tr, G, GV, US, PF, src\+\_\+file, src\+\_\+var\+\_\+nam, src\+\_\+var\+\_\+unit\+\_\+conversion, src\+\_\+var\+\_\+record, homogenize, use\+A\+L\+Eremapping, remapping\+Scheme, src\+\_\+var\+\_\+gridspec)
\begin{DoxyCompactList}\small\item\em Initializes a tracer from a z-\/space data file. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__tracer__initialization__from__z_a01747092117d7076ec9a97368b0fdccf}\label{namespacemom__tracer__initialization__from__z_a01747092117d7076ec9a97368b0fdccf}} 
character(len=40) \mbox{\hyperlink{namespacemom__tracer__initialization__from__z_a01747092117d7076ec9a97368b0fdccf}{mdl}} = \char`\"{}M\+O\+M\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+Z\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tracer__initialization__from__z_ad1570db6534aa3b22bdc5dffef561458}\label{namespacemom__tracer__initialization__from__z_ad1570db6534aa3b22bdc5dffef561458}} 
\index{mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z@{mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z}!mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z@{mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z}}
\index{mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z@{mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z}!mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z@{mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z}}
\subsubsection{\texorpdfstring{mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z()}{mom\_initialize\_tracer\_from\_z()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+z\+::mom\+\_\+initialize\+\_\+tracer\+\_\+from\+\_\+z (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{tr,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{character(len=$\ast$), intent(in)}]{src\+\_\+file,  }\item[{character(len=$\ast$), intent(in)}]{src\+\_\+var\+\_\+nam,  }\item[{real, intent(in), optional}]{src\+\_\+var\+\_\+unit\+\_\+conversion,  }\item[{integer, intent(in), optional}]{src\+\_\+var\+\_\+record,  }\item[{logical, intent(in), optional}]{homogenize,  }\item[{logical, intent(in), optional}]{use\+A\+L\+Eremapping,  }\item[{character(len=$\ast$), intent(in), optional}]{remapping\+Scheme,  }\item[{character(len=$\ast$), intent(in), optional}]{src\+\_\+var\+\_\+gridspec }\end{DoxyParamCaption})}



Initializes a tracer from a z-\/space data file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
 & {\em tr} & Pointer to array to be initialized\\
\hline
\mbox{\tt in}  & {\em pf} & parameter file\\
\hline
\mbox{\tt in}  & {\em src\+\_\+file} & source filename\\
\hline
\mbox{\tt in}  & {\em src\+\_\+var\+\_\+nam} & variable name in file\\
\hline
\mbox{\tt in}  & {\em src\+\_\+var\+\_\+unit\+\_\+conversion} & optional multiplicative unit conversion\\
\hline
\mbox{\tt in}  & {\em src\+\_\+var\+\_\+record} & record to read for multiple time-\/level files\\
\hline
\mbox{\tt in}  & {\em homogenize} & optionally homogenize to mean value\\
\hline
\mbox{\tt in}  & {\em usealeremapping} & to remap or not (optional)\\
\hline
\mbox{\tt in}  & {\em remappingscheme} & remapping scheme to use.\\
\hline
\mbox{\tt in}  & {\em src\+\_\+var\+\_\+gridspec} & Source variable name in a gridspec file. This is not implemented yet. \\
\hline
\end{DoxyParams}


Definition at line 49 of file M\+O\+M\+\_\+tracer\+\_\+initialization\+\_\+from\+\_\+\+Z.\+F90.


\begin{DoxyCode}
49   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{   !< Ocean grid structure.}
50   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< Ocean vertical grid structure.}
51   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
52   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
53                               \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{   !< Layer thickness [H ~> m or kg m-2].}
54   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},     \textcolor{keywordtype}{pointer}       :: tr\textcolor{comment}{  !< Pointer to array to be initialized}
55   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: PF\textcolor{comment}{  !< parameter file}
56   \textcolor{keywordtype}{character(len=*)},           \textcolor{keywordtype}{intent(in)}    :: src\_file\textcolor{comment}{ !< source filename}
57   \textcolor{keywordtype}{character(len=*)},           \textcolor{keywordtype}{intent(in)}    :: src\_var\_nam\textcolor{comment}{ !< variable name in file}
58   \textcolor{keywordtype}{real},             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: src\_var\_unit\_conversion\textcolor{comment}{ !< optional multiplicative unit
       conversion}
59   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: src\_var\_record\textcolor{comment}{  !< record to read for multiple time-level
       files}
60   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: homogenize\textcolor{comment}{ !< optionally homogenize to mean value}
61   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: useALEremapping\textcolor{comment}{ !< to remap or not (optional)}
62   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: remappingScheme\textcolor{comment}{ !< remapping scheme to use.}
63   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: src\_var\_gridspec\textcolor{comment}{ !< Source variable name in a gridspec file.}
64 \textcolor{comment}{                                                                !! This is not implemented yet.}
65   \textcolor{comment}{! Local variables}
66   \textcolor{keywordtype}{real} :: land\_fill = 0.0
67   \textcolor{keywordtype}{character(len=200)} :: inputdir \textcolor{comment}{! The directory where NetCDF input files are.}
68   \textcolor{keywordtype}{character(len=200)} :: mesg
69   \textcolor{keywordtype}{real}               :: convert
70   \textcolor{keywordtype}{integer}            :: recnum
71   \textcolor{keywordtype}{character(len=10)}  :: remapScheme
72   \textcolor{keywordtype}{logical}            :: homog,useALE
73 
74   \textcolor{comment}{! This include declares and sets the variable "version".}
75 \textcolor{preprocessor}{# include "version\_variable.h"}
76 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_initialize\_tracers\_from\_Z"} \textcolor{comment}{! This module's name.}
77 
78   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz \textcolor{comment}{! compute domain indices}
79   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed \textcolor{comment}{! data domain indices}
80   \textcolor{keywordtype}{integer} :: i, j, k, kd
81   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{target} :: tr\_z, mask\_z
82   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{target} :: z\_edges\_in, z\_in
83 
84   \textcolor{comment}{! Local variables for ALE remapping}
85   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: hSrc \textcolor{comment}{! Source thicknesses [H ~> m or kg m-2].}
86   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: h1 \textcolor{comment}{! A 1-d column of source thicknesses [Z ~> m].}
87   \textcolor{keywordtype}{real} :: zTopOfCell, zBottomOfCell, z\_bathy  \textcolor{comment}{! Heights [Z ~> m].}
88   \textcolor{keywordtype}{type}(remapping\_CS) :: remapCS \textcolor{comment}{! Remapping parameters and work arrays}
89 
90   \textcolor{keywordtype}{real} :: missing\_value
91   \textcolor{keywordtype}{integer} :: nPoints
92   \textcolor{keywordtype}{integer} :: id\_clock\_routine, id\_clock\_ALE
93   \textcolor{keywordtype}{logical} :: answers\_2018, default\_2018\_answers, hor\_regrid\_answers\_2018
94   \textcolor{keywordtype}{logical} :: reentrant\_x, tripolar\_n
95 
96   id\_clock\_routine = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize tracer from Z)'}, grain=clock\_routine)
97   id\_clock\_ale = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize tracer from Z) ALE'}, grain=clock\_loop)
98 
99   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_routine)
100 
101   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
102   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
103 
104   \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
105 
106   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_HOMOGENIZE"}, homog, &
107                  \textcolor{stringliteral}{"If True, then horizontally homogenize the interpolated "}//&
108                  \textcolor{stringliteral}{"initial conditions."}, default=.false.)
109   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_ALE\_REMAPPING"}, useale, &
110                  \textcolor{stringliteral}{"If True, then remap straight to model coordinate from file."},&
111                  default=.true.)
112   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_REMAPPING\_SCHEME"}, remapscheme, &
113                  \textcolor{stringliteral}{"The remapping scheme to use if using Z\_INIT\_ALE\_REMAPPING is True."}, &
114                  default=\textcolor{stringliteral}{"PLM"})
115   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
116                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
117                  default=.false.)
118   \textcolor{keywordflow}{if} (useale) \textcolor{keywordflow}{then}
119     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, answers\_2018, &
120                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
121                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
122                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
123 \textcolor{keywordflow}{  endif}
124   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"HOR\_REGRID\_2018\_ANSWERS"}, hor\_regrid\_answers\_2018, &
125                  \textcolor{stringliteral}{"If true, use the order of arithmetic for horizonal regridding that recovers "}//&
126                  \textcolor{stringliteral}{"the answers from the end of 2018.  Otherwise, use rotationally symmetric "}//&
127                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
128 
129   \textcolor{comment}{! These are model grid properties, but being applied to the data grid for now.}
130   \textcolor{comment}{! need to revisit this (mjh)}
131   reentrant\_x = .false. ;  \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REENTRANT\_X"}, reentrant\_x,default=.true.)
132   tripolar\_n = .false. ;  \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TRIPOLAR\_N"}, tripolar\_n, default=.false.)
133 
134   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(homogenize)) homog=homogenize
135   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(usealeremapping)) useale=usealeremapping
136   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(remappingscheme)) remapscheme=remappingscheme
137   recnum=1
138   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(src\_var\_record)) recnum = src\_var\_record
139   convert=1.0
140   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(src\_var\_unit\_conversion)) convert = src\_var\_unit\_conversion
141 
142   \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(src\_file, src\_var\_nam, convert, recnum, &
143        g, tr\_z, mask\_z, z\_in, z\_edges\_in, missing\_value, reentrant\_x, tripolar\_n, &
144        homog, m\_to\_z=us%m\_to\_Z, answers\_2018=hor\_regrid\_answers\_2018)
145 
146   kd = \textcolor{keyword}{size}(z\_edges\_in,1)-1
147   \textcolor{keyword}{call }pass\_var(tr\_z,g%Domain)
148   \textcolor{keyword}{call }pass\_var(mask\_z,g%Domain)
149 
150 \textcolor{comment}{! Done with horizontal interpolation.}
151 \textcolor{comment}{! Now remap to model coordinates}
152   \textcolor{keywordflow}{if} (useale) \textcolor{keywordflow}{then}
153     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ale)
154     \textcolor{comment}{! First we reserve a work space for reconstructions of the source data}
155     \textcolor{keyword}{allocate}( h1(kd) )
156     \textcolor{keyword}{allocate}( hsrc(isd:ied,jsd:jed,kd) )
157     \textcolor{comment}{! Set parameters for reconstructions}
158     \textcolor{keyword}{call }initialize\_remapping( remapcs, remapscheme, boundary\_extrapolation=.false., answers\_2018=
      answers\_2018 )
159     \textcolor{comment}{! Next we initialize the regridding package so that it knows about the target grid}
160 
161     \textcolor{keywordflow}{do} j = js, je ; \textcolor{keywordflow}{do} i = is, ie
162       \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
163         \textcolor{comment}{! Build the source grid}
164         ztopofcell = 0. ; zbottomofcell = 0. ; npoints = 0
165         z\_bathy = g%bathyT(i,j)
166         \textcolor{keywordflow}{do} k = 1, kd
167           \textcolor{keywordflow}{if} (mask\_z(i,j,k) > 0.) \textcolor{keywordflow}{then}
168             zbottomofcell = -min( z\_edges\_in(k+1), z\_bathy )
169           \textcolor{keywordflow}{elseif} (k>1) \textcolor{keywordflow}{then}
170             zbottomofcell = -z\_bathy
171 \textcolor{keywordflow}{          endif}
172           h1(k) = ztopofcell - zbottomofcell
173           \textcolor{keywordflow}{if} (h1(k)>0.) npoints = npoints + 1
174           ztopofcell = zbottomofcell \textcolor{comment}{! Bottom becomes top for next value of k}
175 \textcolor{keywordflow}{        enddo}
176         h1(kd) = h1(kd) + ( ztopofcell + z\_bathy ) \textcolor{comment}{! In case data is deeper than model}
177       \textcolor{keywordflow}{else}
178         tr(i,j,:) = 0.
179 \textcolor{keywordflow}{      endif} \textcolor{comment}{! mask2dT}
180       hsrc(i,j,:) = gv%Z\_to\_H * h1(:)
181 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
182 
183     \textcolor{keyword}{call }ale\_remap\_scalar(remapcs, g, gv, kd, hsrc, tr\_z, h, tr, all\_cells=.false., answers\_2018=
      answers\_2018 )
184 
185     \textcolor{keyword}{deallocate}( hsrc )
186     \textcolor{keyword}{deallocate}( h1 )
187 
188     \textcolor{keywordflow}{do} k=1,nz
189       \textcolor{keyword}{call }mystats(tr(:,:,k), missing\_value, is, ie, js, je, k, \textcolor{stringliteral}{'Tracer from ALE()'})
190 \textcolor{keywordflow}{    enddo}
191     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ale)
192 \textcolor{keywordflow}{  endif} \textcolor{comment}{! useALEremapping}
193 
194 \textcolor{comment}{! Fill land values}
195   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
196     \textcolor{keywordflow}{if} (tr(i,j,k) == missing\_value) \textcolor{keywordflow}{then}
197       tr(i,j,k)=land\_fill
198 \textcolor{keywordflow}{    endif}
199 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
200 
201   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
202   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_routine)
203 
\end{DoxyCode}
