\hypertarget{namespacemom__horizontal__regridding}{}\section{mom\+\_\+horizontal\+\_\+regridding Module Reference}
\label{namespacemom__horizontal__regridding}\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}


\subsection{Detailed Description}
Horizontal interpolation. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
interface \hyperlink{interfacemom__horizontal__regridding_1_1fill__boundaries}{fill\+\_\+boundaries}
\begin{DoxyCompactList}\small\item\em Fill grid edges. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__horizontal__regridding_1_1horiz__interp__and__extrap__tracer}{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer}
\begin{DoxyCompactList}\small\item\em Extrapolate and interpolate data. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__horizontal__regridding_a2eefabc60ef9735714237dd2094963cd}{mystats} (array, missing, is, ie, js, je, k, mesg)
\begin{DoxyCompactList}\small\item\em Write to the terminal some basic statistics about the k-\/th level of an array. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__horizontal__regridding_aed390b9c00196debf5c2ab811c3a4203}{fill\+\_\+miss\+\_\+2d} (aout, good, fill, prev, G, smooth, num\+\_\+pass, relc, crit, debug, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Use I\+C\+E-\/9 algorithm to populate points (fill=1) with valid data (good=1). If no information is available, Then use a previous guess (prev). Optionally (smooth) blend the filled points to achieve a more desirable result. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__horizontal__regridding_a1668fd9b402d78a7ececce78fa21696a}{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record} (filename, varnam, conversion, recnum, G, tr\+\_\+z, mask\+\_\+z, z\+\_\+in, z\+\_\+edges\+\_\+in, missing\+\_\+value, reentrant\+\_\+x, tripolar\+\_\+n, homogenize, m\+\_\+to\+\_\+Z, answers\+\_\+2018, ongrid)
\begin{DoxyCompactList}\small\item\em Extrapolate and interpolate from a file record. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__horizontal__regridding_aabf2c2ac43a9bfd897cca10dcb97a3c4}{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id} (fms\+\_\+id, Time, conversion, G, tr\+\_\+z, mask\+\_\+z, z\+\_\+in, z\+\_\+edges\+\_\+in, missing\+\_\+value, reentrant\+\_\+x, tripolar\+\_\+n, homogenize, sponge\+Ongrid, m\+\_\+to\+\_\+Z, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Extrapolate and interpolate using a F\+MS time interpolation handle. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__horizontal__regridding_a4612a182a8630f102a29e0cce1bd7a77}{meshgrid} (x, y, x\+\_\+T, y\+\_\+T)
\begin{DoxyCompactList}\small\item\em Create a 2d-\/mesh of grid coordinates from 1-\/d arrays. \end{DoxyCompactList}\item 
integer function, dimension(0\+:size(m, 1)+1, 0\+:size(m, 2)+1) \hyperlink{namespacemom__horizontal__regridding_a97e2579ce7c653f73557eb51fd632757}{fill\+\_\+boundaries\+\_\+int} (m, cyclic\+\_\+x, tripolar\+\_\+n)
\begin{DoxyCompactList}\small\item\em Fill grid edges for integer data. \end{DoxyCompactList}\item 
real function, dimension(0\+:size(m, 1)+1, 0\+:size(m, 2)+1) \hyperlink{namespacemom__horizontal__regridding_ae5756b21f0db3264f0981e27ecb75b17}{fill\+\_\+boundaries\+\_\+real} (m, cyclic\+\_\+x, tripolar\+\_\+n)
\begin{DoxyCompactList}\small\item\em Fill grid edges for real data. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__horizontal__regridding_a333ea43962d49ea6730eeb7bff8923f6}{smooth\+\_\+heights} (zi, fill, bad, sor, niter, cyclic\+\_\+x, tripolar\+\_\+n)
\begin{DoxyCompactList}\small\item\em Solve del2 (zi) = 0 using successive iterations with a 5 point stencil. Only points fill==1 are modified. Except where bad==1, information propagates isotropically in index space. The resulting solution in each region is an approximation to del2(zi)=0 subject to boundary conditions along the valid points curve bounding this region. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_a97e2579ce7c653f73557eb51fd632757}\label{namespacemom__horizontal__regridding_a97e2579ce7c653f73557eb51fd632757}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!fill\+\_\+boundaries\+\_\+int@{fill\+\_\+boundaries\+\_\+int}}
\index{fill\+\_\+boundaries\+\_\+int@{fill\+\_\+boundaries\+\_\+int}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{fill\+\_\+boundaries\+\_\+int()}{fill\_boundaries\_int()}}
{\footnotesize\ttfamily integer function, dimension(0\+:size(m,1)+1,0\+:size(m,2)+1) mom\+\_\+horizontal\+\_\+regridding\+::fill\+\_\+boundaries\+\_\+int (\begin{DoxyParamCaption}\item[{integer, dimension(\+:,\+:), intent(in)}]{m,  }\item[{logical, intent(in)}]{cyclic\+\_\+x,  }\item[{logical, intent(in)}]{tripolar\+\_\+n }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Fill grid edges for integer data. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em m} & input array (ND)\\
\hline
\mbox{\tt in}  & {\em cyclic\+\_\+x} & True if domain is zonally re-\/entrant\\
\hline
\mbox{\tt in}  & {\em tripolar\+\_\+n} & True if domain has an Arctic fold \\
\hline
\end{DoxyParams}


Definition at line 951 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
951   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}             :: m\textcolor{comment}{ !< input array (ND)}
952   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}             :: cyclic\_x\textcolor{comment}{ !< True if domain is zonally re-entrant}
953   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}             :: tripolar\_n\textcolor{comment}{ !< True if domain has an Arctic fold}
954   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(0:size(m,1)+1,0:size(m,2)+1)} :: mp
955 
956   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{dimension(size(m,1),size(m,2))}         :: m\_real
957   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{dimension(0:size(m,1)+1,0:size(m,2)+1)} :: mp\_real
958 
959   m\_real = \textcolor{keywordtype}{real}(m)
960 
961   mp\_real = fill\_boundaries\_real(m\_real,cyclic\_x,tripolar\_n)
962 
963   mp = int(mp\_real)
964 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_ae5756b21f0db3264f0981e27ecb75b17}\label{namespacemom__horizontal__regridding_ae5756b21f0db3264f0981e27ecb75b17}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!fill\+\_\+boundaries\+\_\+real@{fill\+\_\+boundaries\+\_\+real}}
\index{fill\+\_\+boundaries\+\_\+real@{fill\+\_\+boundaries\+\_\+real}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{fill\+\_\+boundaries\+\_\+real()}{fill\_boundaries\_real()}}
{\footnotesize\ttfamily real function, dimension(0\+:size(m,1)+1,0\+:size(m,2)+1) mom\+\_\+horizontal\+\_\+regridding\+::fill\+\_\+boundaries\+\_\+real (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), intent(in)}]{m,  }\item[{logical, intent(in)}]{cyclic\+\_\+x,  }\item[{logical, intent(in)}]{tripolar\+\_\+n }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Fill grid edges for real data. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em m} & input array (ND)\\
\hline
\mbox{\tt in}  & {\em cyclic\+\_\+x} & True if domain is zonally re-\/entrant\\
\hline
\mbox{\tt in}  & {\em tripolar\+\_\+n} & True if domain has an Arctic fold \\
\hline
\end{DoxyParams}


Definition at line 969 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
969   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}             :: m\textcolor{comment}{ !< input array (ND)}
970   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in)}             :: cyclic\_x\textcolor{comment}{ !< True if domain is zonally re-entrant}
971   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in)}             :: tripolar\_n\textcolor{comment}{ !< True if domain has an Arctic fold}
972   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(0:size(m,1)+1,0:size(m,2)+1)} :: mp
973 
974   \textcolor{keywordtype}{integer} :: ni,nj,i,j
975 
976   ni=\textcolor{keyword}{size}(m,1); nj=\textcolor{keyword}{size}(m,2)
977 
978   mp(1:ni,1:nj)=m(:,:)
979 
980   \textcolor{keywordflow}{if} (cyclic\_x) \textcolor{keywordflow}{then}
981     mp(0,1:nj)=m(ni,1:nj)
982     mp(ni+1,1:nj)=m(1,1:nj)
983   \textcolor{keywordflow}{else}
984     mp(0,1:nj)=m(1,1:nj)
985     mp(ni+1,1:nj)=m(ni,1:nj)
986 \textcolor{keywordflow}{  endif}
987 
988   mp(1:ni,0)=m(1:ni,1)
989   \textcolor{keywordflow}{if} (tripolar\_n) \textcolor{keywordflow}{then}
990     \textcolor{keywordflow}{do} i=1,ni
991       mp(i,nj+1)=m(ni-i+1,nj)
992 \textcolor{keywordflow}{    enddo}
993   \textcolor{keywordflow}{else}
994     mp(1:ni,nj+1)=m(1:ni,nj)
995 \textcolor{keywordflow}{  endif}
996 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_aed390b9c00196debf5c2ab811c3a4203}\label{namespacemom__horizontal__regridding_aed390b9c00196debf5c2ab811c3a4203}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!fill\+\_\+miss\+\_\+2d@{fill\+\_\+miss\+\_\+2d}}
\index{fill\+\_\+miss\+\_\+2d@{fill\+\_\+miss\+\_\+2d}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{fill\+\_\+miss\+\_\+2d()}{fill\_miss\_2d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+horizontal\+\_\+regridding\+::fill\+\_\+miss\+\_\+2d (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{aout,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{good,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{fill,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{prev,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{logical, intent(in), optional}]{smooth,  }\item[{integer, intent(in), optional}]{num\+\_\+pass,  }\item[{real, intent(in), optional}]{relc,  }\item[{real, intent(in), optional}]{crit,  }\item[{logical, intent(in), optional}]{debug,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Use I\+C\+E-\/9 algorithm to populate points (fill=1) with valid data (good=1). If no information is available, Then use a previous guess (prev). Optionally (smooth) blend the filled points to achieve a more desirable result. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in,out}  & {\em aout} & The array with missing values to fill\\
\hline
\mbox{\tt in}  & {\em good} & Valid data mask for incoming array\\
\hline
\mbox{\tt in}  & {\em fill} & Same shape array of points which need\\
\hline
\mbox{\tt in}  & {\em prev} & First guess where isolated holes exist.\\
\hline
\mbox{\tt in}  & {\em smooth} & If present and true, apply a number of Laplacian iterations to the interpolated data\\
\hline
\mbox{\tt in}  & {\em num\+\_\+pass} & The maximum number of iterations\\
\hline
\mbox{\tt in}  & {\em relc} & A relaxation coefficient for Laplacian (ND)\\
\hline
\mbox{\tt in}  & {\em crit} & A minimal value for deltas between iterations.\\
\hline
\mbox{\tt in}  & {\em debug} & If true, write verbose debugging messages.\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true, use expressions that give the same answers as the code did in late 2018. Otherwise add parentheses for rotational symmetry. \\
\hline
\end{DoxyParams}


Definition at line 105 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
105   \textcolor{keywordtype}{use }\hyperlink{namespacemom__coms}{mom\_coms}\textcolor{keywordtype}{, only} : sum\_across\_pes
106 
107   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
108   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
109                          \textcolor{keywordtype}{intent(inout)} :: aout\textcolor{comment}{ !< The array with missing values to fill}
110   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
111                          \textcolor{keywordtype}{intent(in)}    :: good\textcolor{comment}{ !< Valid data mask for incoming array}
112 \textcolor{comment}{                                               !! (1==good data; 0==missing data).}
113   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
114                          \textcolor{keywordtype}{intent(in)}    :: fill\textcolor{comment}{ !< Same shape array of points which need}
115 \textcolor{comment}{                                               !! filling (1==fill;0==dont fill)}
116   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
117                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: prev\textcolor{comment}{ !< First guess where isolated holes exist.}
118   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: smooth\textcolor{comment}{ !< If present and true, apply a number of}
119 \textcolor{comment}{                                                 !! Laplacian iterations to the interpolated data}
120   \textcolor{keywordtype}{integer},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: num\_pass\textcolor{comment}{ !< The maximum number of iterations}
121   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: relc\textcolor{comment}{ !< A relaxation coefficient for Laplacian (ND)}
122   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: crit\textcolor{comment}{ !< A minimal value for deltas between iterations.}
123   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: debug\textcolor{comment}{ !< If true, write verbose debugging messages.}
124   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use expressions that give the same}
125 \textcolor{comment}{                                                !! answers as the code did in late 2018.  Otherwise}
126 \textcolor{comment}{                                                !! add parentheses for rotational symmetry.}
127 
128   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: b,r
129   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: fill\_pts, good\_, good\_new
130 
131   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}
132   \textcolor{keywordtype}{integer} :: i,j,k
133   \textcolor{keywordtype}{real}    :: east,west,north,south,sor
134   \textcolor{keywordtype}{real}    :: ge,gw,gn,gs,ngood
135   \textcolor{keywordtype}{logical} :: do\_smooth,siena\_bug
136   \textcolor{keywordtype}{real}    :: nfill, nfill\_prev
137   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: num\_pass\_default = 10000
138   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: relc\_default = 0.25, crit\_default = 1.e-3
139 
140   \textcolor{keywordtype}{integer} :: npass
141   \textcolor{keywordtype}{integer} :: is, ie, js, je
142   \textcolor{keywordtype}{real}    :: relax\_coeff, acrit, ares
143   \textcolor{keywordtype}{logical} :: debug\_it, ans\_2018
144 
145   debug\_it=.false.
146   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(debug)) debug\_it=debug
147 
148   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
149 
150   npass = num\_pass\_default
151   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(num\_pass)) npass = num\_pass
152 
153   relax\_coeff = relc\_default
154   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(relc)) relax\_coeff = relc
155 
156   acrit = crit\_default
157   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(crit)) acrit = crit
158 
159   do\_smooth=.false.
160   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(smooth)) do\_smooth=smooth
161 
162   ans\_2018 = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(answers\_2018)) ans\_2018 = answers\_2018
163 
164   fill\_pts(:,:) = fill(:,:)
165 
166   nfill = sum(fill(is:ie,js:je))
167   \textcolor{keyword}{call }sum\_across\_pes(nfill)
168 
169   nfill\_prev = nfill
170   good\_(:,:) = good(:,:)
171   r(:,:) = 0.0
172 
173   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (nfill > 0.0)
174 
175     \textcolor{keyword}{call }pass\_var(good\_,g%Domain)
176     \textcolor{keyword}{call }pass\_var(aout,g%Domain)
177 
178     b(:,:)=aout(:,:)
179     good\_new(:,:)=good\_(:,:)
180 
181     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
182 
183       \textcolor{keywordflow}{if} (good\_(i,j) == 1.0 .or. fill(i,j) == 0.) cycle
184 
185       ge=good\_(i+1,j) ; gw=good\_(i-1,j)
186       gn=good\_(i,j+1) ; gs=good\_(i,j-1)
187       east=0.0 ; west=0.0 ; north=0.0 ; south=0.0
188       \textcolor{keywordflow}{if} (ge == 1.0) east = aout(i+1,j)*ge
189       \textcolor{keywordflow}{if} (gw == 1.0) west = aout(i-1,j)*gw
190       \textcolor{keywordflow}{if} (gn == 1.0) north = aout(i,j+1)*gn
191       \textcolor{keywordflow}{if} (gs == 1.0) south = aout(i,j-1)*gs
192 
193       \textcolor{keywordflow}{if} (ans\_2018) \textcolor{keywordflow}{then}
194         ngood = ge+gw+gn+gs
195       \textcolor{keywordflow}{else}
196         ngood = (ge+gw) + (gn+gs)
197 \textcolor{keywordflow}{      endif}
198       \textcolor{keywordflow}{if} (ngood > 0.) \textcolor{keywordflow}{then}
199         \textcolor{keywordflow}{if} (ans\_2018) \textcolor{keywordflow}{then}
200           b(i,j)=(east+west+north+south)/ngood
201         \textcolor{keywordflow}{else}
202           b(i,j) = ((east+west) + (north+south))/ngood
203 \textcolor{keywordflow}{        endif}
204         fill\_pts(i,j) = 0.0
205         good\_new(i,j) = 1.0
206 \textcolor{keywordflow}{      endif}
207 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
208 
209     aout(is:ie,js:je) = b(is:ie,js:je)
210     good\_(is:ie,js:je) = good\_new(is:ie,js:je)
211     nfill\_prev = nfill
212     nfill = sum(fill\_pts(is:ie,js:je))
213     \textcolor{keyword}{call }sum\_across\_pes(nfill)
214 
215     \textcolor{keywordflow}{if} (nfill == nfill\_prev .and. \textcolor{keyword}{PRESENT}(prev)) \textcolor{keywordflow}{then}
216       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (fill\_pts(i,j) == 1.0) \textcolor{keywordflow}{then}
217         aout(i,j) = prev(i,j)
218         fill\_pts(i,j) = 0.0
219 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
220     \textcolor{keywordflow}{elseif} (nfill == nfill\_prev) \textcolor{keywordflow}{then}
221       \textcolor{keyword}{call }mom\_error(warning, &
222            \textcolor{stringliteral}{'Unable to fill missing points using either data at the same vertical level from a connected
       basin'}//&
223            \textcolor{stringliteral}{'or using a point from a previous vertical level.  Make sure that the original data has some
       valid'}//&
224            \textcolor{stringliteral}{'data in all basins.'}, .true.)
225       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'nfill='},nfill
226       \textcolor{keyword}{call }mom\_error(warning, mesg, .true.)
227 \textcolor{keywordflow}{    endif}
228 
229     nfill = sum(fill\_pts(is:ie,js:je))
230     \textcolor{keyword}{call }sum\_across\_pes(nfill)
231 
232 \textcolor{keywordflow}{  enddo}
233 
234   \textcolor{keywordflow}{if} (do\_smooth) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,npass
235     \textcolor{keyword}{call }pass\_var(aout,g%Domain)
236     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
237       \textcolor{keywordflow}{if} (fill(i,j) == 1) \textcolor{keywordflow}{then}
238         east = max(good(i+1,j),fill(i+1,j)) ; west = max(good(i-1,j),fill(i-1,j))
239         north = max(good(i,j+1),fill(i,j+1)) ; south = max(good(i,j-1),fill(i,j-1))
240         \textcolor{keywordflow}{if} (ans\_2018) \textcolor{keywordflow}{then}
241           r(i,j) = relax\_coeff*(south*aout(i,j-1)+north*aout(i,j+1) + &
242                                 west*aout(i-1,j)+east*aout(i+1,j) - &
243                                (south+north+west+east)*aout(i,j))
244         \textcolor{keywordflow}{else}
245           r(i,j) = relax\_coeff*( ((south*aout(i,j-1) + north*aout(i,j+1)) + &
246                                   (west*aout(i-1,j)+east*aout(i+1,j))) - &
247                                  ((south+north)+(west+east))*aout(i,j) )
248 \textcolor{keywordflow}{        endif}
249       \textcolor{keywordflow}{else}
250         r(i,j) = 0.
251 \textcolor{keywordflow}{      endif}
252 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
253     ares = 0.0
254     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
255       aout(i,j) = r(i,j) + aout(i,j)
256       ares = max(ares, abs(r(i,j)))
257 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
258     \textcolor{keyword}{call }max\_across\_pes(ares)
259     \textcolor{keywordflow}{if} (ares <= acrit) \textcolor{keywordflow}{exit}
260 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}
261 
262   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
263     \textcolor{keywordflow}{if} (good\_(i,j) == 0.0 .and. fill\_pts(i,j) == 1.0) \textcolor{keywordflow}{then}
264       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'In fill\_miss, fill, good,i,j= '},fill\_pts(i,j),good\_(i,j),i,j
265       \textcolor{keyword}{call }mom\_error(warning, mesg, .true.)
266       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM\_initialize: "}// &
267            \textcolor{stringliteral}{"fill is true and good is false after fill\_miss, how did this happen? "})
268 \textcolor{keywordflow}{    endif}
269 \textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
270 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_aabf2c2ac43a9bfd897cca10dcb97a3c4}\label{namespacemom__horizontal__regridding_aabf2c2ac43a9bfd897cca10dcb97a3c4}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id@{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id}}
\index{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id@{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id()}{horiz\_interp\_and\_extrap\_tracer\_fms\_id()}}
{\footnotesize\ttfamily subroutine mom\+\_\+horizontal\+\_\+regridding\+::horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+fms\+\_\+id (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{fms\+\_\+id,  }\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{real, intent(in)}]{conversion,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(\+:,\+:,\+:), allocatable}]{tr\+\_\+z,  }\item[{real, dimension(\+:,\+:,\+:), allocatable}]{mask\+\_\+z,  }\item[{real, dimension(\+:), allocatable}]{z\+\_\+in,  }\item[{real, dimension(\+:), allocatable}]{z\+\_\+edges\+\_\+in,  }\item[{real, intent(out)}]{missing\+\_\+value,  }\item[{logical, intent(in)}]{reentrant\+\_\+x,  }\item[{logical, intent(in)}]{tripolar\+\_\+n,  }\item[{logical, intent(in), optional}]{homogenize,  }\item[{logical, intent(in), optional}]{sponge\+Ongrid,  }\item[{real, intent(in), optional}]{m\+\_\+to\+\_\+Z,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Extrapolate and interpolate using a F\+MS time interpolation handle. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em fms\+\_\+id} & A unique id used by the F\+MS time interpolator\\
\hline
\mbox{\tt in}  & {\em time} & A F\+MS time type\\
\hline
\mbox{\tt in}  & {\em conversion} & Conversion factor for tracer.\\
\hline
\mbox{\tt in,out}  & {\em g} & Grid object\\
\hline
 & {\em tr\+\_\+z} & pointer to allocatable tracer array on local model grid and native vertical levels.\\
\hline
 & {\em mask\+\_\+z} & pointer to allocatable tracer mask array on local model grid and native vertical levels.\\
\hline
 & {\em z\+\_\+in} & Cell grid values for input data.\\
\hline
 & {\em z\+\_\+edges\+\_\+in} & Cell grid edge values for input data. (Intent out)\\
\hline
\mbox{\tt out}  & {\em missing\+\_\+value} & The missing value in the returned array.\\
\hline
\mbox{\tt in}  & {\em reentrant\+\_\+x} & If true, this grid is reentrant in the x-\/direction\\
\hline
\mbox{\tt in}  & {\em tripolar\+\_\+n} & If true, this is a northern tripolar grid\\
\hline
\mbox{\tt in}  & {\em homogenize} & If present and true, horizontally homogenize data to produce perfectly \char`\"{}flat\char`\"{} initial conditions\\
\hline
\mbox{\tt in}  & {\em spongeongrid} & If present and true, the sponge data are on the model grid\\
\hline
\mbox{\tt in}  & {\em m\+\_\+to\+\_\+z} & A conversion factor from meters to the units of depth. If missing, GbathyT must be in m.\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true, use expressions that give the same answers as the code did in late 2018. Otherwise add parentheses for rotational symmetry. \\
\hline
\end{DoxyParams}


Definition at line 636 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
636 
637   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: fms\_id\textcolor{comment}{     !< A unique id used by the FMS time interpolator}
638   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{       !< A FMS time type}
639   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: conversion\textcolor{comment}{ !< Conversion factor for tracer.}
640   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{          !< Grid object}
641   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: tr\_z\textcolor{comment}{       !< pointer to allocatable tracer array on local}
642 \textcolor{comment}{                                                     !! model grid and native vertical levels.}
643   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: mask\_z\textcolor{comment}{     !< pointer to allocatable tracer mask array on}
644 \textcolor{comment}{                                                     !! local model grid and native vertical levels.}
645   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_in\textcolor{comment}{       !< Cell grid values for input data.}
646   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_edges\_in\textcolor{comment}{ !< Cell grid edge values for input data. (Intent out)}
647   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)}   :: missing\_value\textcolor{comment}{ !< The missing value in the returned array.}
648   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: reentrant\_x\textcolor{comment}{ !< If true, this grid is reentrant in the x-direction}
649   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: tripolar\_n\textcolor{comment}{ !< If true, this is a northern tripolar grid}
650   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: homogenize\textcolor{comment}{ !< If present and true, horizontally homogenize data}
651 \textcolor{comment}{                                                     !! to produce perfectly "flat" initial conditions}
652   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: spongeongrid\textcolor{comment}{ !< If present and true, the sponge data are on the
       model grid}
653   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: m\_to\_z\textcolor{comment}{     !< A conversion factor from meters to the units}
654 \textcolor{comment}{                                                     !! of depth.  If missing, G%bathyT must be in m.}
655   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use expressions that give the same}
656 \textcolor{comment}{                                                     !! answers as the code did in late 2018.  Otherwise}
657 \textcolor{comment}{                                                     !! add parentheses for rotational symmetry.}
658 
659   \textcolor{comment}{! Local variables}
660   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},  \textcolor{keywordtype}{allocatable}   :: tr\_in,tr\_inp\textcolor{comment}{ !< A 2-d array for holding input data on}
661 \textcolor{comment}{                                                     !! native horizontal grid and extended grid}
662 \textcolor{comment}{                                                     !! with poles.}
663   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable}  :: data\_in\textcolor{comment}{    !< A buffer for storing the full 3-d time-interpolated
       array}
664 \textcolor{comment}{                                                     !! on the original grid}
665   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},  \textcolor{keywordtype}{allocatable}   :: mask\_in\textcolor{comment}{    !< A 2-d mask for extended input grid.}
666 
667   \textcolor{keywordtype}{real} :: pi\_180
668   \textcolor{keywordtype}{integer} :: rcode, ncid, varid, ndims, id, jd, kd, jdp
669   \textcolor{keywordtype}{integer} :: i,j,k
670   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: start, count, dims, dim\_id
671   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: x\_in, y\_in
672   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lon\_in, lat\_in
673   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lat\_inp, last\_row
674   \textcolor{keywordtype}{real} :: max\_lat, min\_lat, pole, max\_depth, npole
675   \textcolor{keywordtype}{real} :: roundoff  \textcolor{comment}{! The magnitude of roundoff, usually ~2e-16.}
676   \textcolor{keywordtype}{logical} :: add\_np
677   \textcolor{keywordtype}{character(len=8)}  :: laynum
678   \textcolor{keywordtype}{type}(horiz\_interp\_type) :: interp
679   \textcolor{keywordtype}{type}(axistype), \textcolor{keywordtype}{dimension(4)} :: axes\_data
680   \textcolor{keywordtype}{integer} :: is, ie, js, je     \textcolor{comment}{! compute domain indices}
681   \textcolor{keywordtype}{integer} :: isc,iec,jsc,jec    \textcolor{comment}{! global compute domain indices}
682   \textcolor{keywordtype}{integer} :: isg, ieg, jsg, jeg \textcolor{comment}{! global extent}
683   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed \textcolor{comment}{! data domain indices}
684   \textcolor{keywordtype}{integer} :: id\_clock\_read
685   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: fld\_sz
686   \textcolor{keywordtype}{character(len=12)}  :: dim\_name(4)
687   \textcolor{keywordtype}{logical} :: debug=.false.
688   \textcolor{keywordtype}{logical} :: spongedataongrid
689   \textcolor{keywordtype}{real} :: npoints,varavg
690   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: lon\_out, lat\_out, tr\_out, mask\_out
691   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: good, fill
692   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: tr\_outf,tr\_prev
693   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: good2,fill2
694   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: nlevs
695   \textcolor{keywordtype}{integer} :: turns
696 
697   turns = g%HI%turns
698 
699   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
700   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
701   isg = g%isg ; ieg = g%ieg ; jsg = g%jsg ; jeg = g%jeg
702 
703   id\_clock\_read = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize tracer from Z) read'}, grain=clock\_loop)
704 
705   pi\_180=atan(1.0)/45.
706 
707   \textcolor{comment}{! Open NetCDF file and if present, extract data and spatial coordinate information}
708   \textcolor{comment}{! The convention adopted here requires that the data be written in (i,j,k) ordering.}
709 
710   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_read)
711 
712   fld\_sz = get\_external\_field\_size(fms\_id)
713   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lon\_in)) \textcolor{keyword}{deallocate}(lon\_in)
714   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lat\_in)) \textcolor{keyword}{deallocate}(lat\_in)
715   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_in)) \textcolor{keyword}{deallocate}(z\_in)
716   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_edges\_in)) \textcolor{keyword}{deallocate}(z\_edges\_in)
717   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(tr\_z)) \textcolor{keyword}{deallocate}(tr\_z)
718   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(mask\_z)) \textcolor{keyword}{deallocate}(mask\_z)
719 
720   axes\_data =  get\_external\_field\_axes(fms\_id)
721 
722   id = fld\_sz(1) ; jd  = fld\_sz(2) ; kd = fld\_sz(3)
723 
724   spongedataongrid=.false.
725   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(spongeongrid)) spongedataongrid=spongeongrid
726   \textcolor{keywordflow}{if} (.not. spongedataongrid) \textcolor{keywordflow}{then}
727     \textcolor{keyword}{allocate}(lon\_in(id),lat\_in(jd))
728     \textcolor{keyword}{call }mpp\_get\_axis\_data(axes\_data(1), lon\_in)
729     \textcolor{keyword}{call }mpp\_get\_axis\_data(axes\_data(2), lat\_in)
730 \textcolor{keywordflow}{  endif}
731 
732   \textcolor{keyword}{allocate}(z\_in(kd),z\_edges\_in(kd+1))
733 
734   \textcolor{keyword}{allocate}(tr\_z(isd:ied,jsd:jed,kd), mask\_z(isd:ied,jsd:jed,kd))
735 
736   \textcolor{keyword}{call }mpp\_get\_axis\_data(axes\_data(3), z\_in)
737 
738   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(m\_to\_z)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,kd ; z\_in(k) = m\_to\_z * z\_in(k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
739 
740   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_read)
741 
742   missing\_value = get\_external\_field\_missing(fms\_id)
743 
744   \textcolor{keywordflow}{if} (.not. spongedataongrid) \textcolor{keywordflow}{then}
745     \textcolor{comment}{! extrapolate the input data to the north pole using the northerm-most latitude}
746     max\_lat = maxval(lat\_in)
747     add\_np=.false.
748     \textcolor{keywordflow}{if} (max\_lat < 90.0) \textcolor{keywordflow}{then}
749       add\_np = .true.
750       jdp = jd+1
751       \textcolor{keyword}{allocate}(lat\_inp(jdp))
752       lat\_inp(1:jd) = lat\_in(:)
753       lat\_inp(jd+1) = 90.0
754       \textcolor{keyword}{deallocate}(lat\_in)
755       \textcolor{keyword}{allocate}(lat\_in(1:jdp))
756       lat\_in(:) = lat\_inp(:)
757     \textcolor{keywordflow}{else}
758       jdp=jd
759 \textcolor{keywordflow}{    endif}
760     \textcolor{keyword}{call }horiz\_interp\_init()
761     lon\_in = lon\_in*pi\_180
762     lat\_in = lat\_in*pi\_180
763     \textcolor{keyword}{allocate}(x\_in(id,jdp), y\_in(id,jdp))
764     \textcolor{keyword}{call }meshgrid(lon\_in, lat\_in, x\_in, y\_in)
765     lon\_out(:,:) = g%geoLonT(:,:)*pi\_180
766     lat\_out(:,:) = g%geoLatT(:,:)*pi\_180
767     \textcolor{keyword}{allocate}(data\_in(id,jd,kd)) ; data\_in(:,:,:)=0.0
768     \textcolor{keyword}{allocate}(tr\_in(id,jd)) ; tr\_in(:,:)=0.0
769     \textcolor{keyword}{allocate}(tr\_inp(id,jdp)) ; tr\_inp(:,:)=0.0
770     \textcolor{keyword}{allocate}(mask\_in(id,jdp)) ; mask\_in(:,:)=0.0
771     \textcolor{keyword}{allocate}(last\_row(id))    ; last\_row(:)=0.0
772   \textcolor{keywordflow}{else}
773     \textcolor{keyword}{allocate}(data\_in(isd:ied,jsd:jed,kd))
774 \textcolor{keywordflow}{  endif}
775   \textcolor{comment}{! construct level cell boundaries as the mid-point between adjacent centers}
776   z\_edges\_in(1) = 0.0
777   \textcolor{keywordflow}{do} k=2,kd
778     z\_edges\_in(k) = 0.5*(z\_in(k-1)+z\_in(k))
779 \textcolor{keywordflow}{  enddo}
780   z\_edges\_in(kd+1) = 2.0*z\_in(kd) - z\_in(kd-1)
781 
782 
783   max\_depth = maxval(g%bathyT)
784   \textcolor{keyword}{call }mpp\_max(max\_depth)
785 
786   \textcolor{keywordflow}{if} (z\_edges\_in(kd+1)<max\_depth) z\_edges\_in(kd+1)=max\_depth
787 
788   \textcolor{comment}{!  roundoff = 3.0*EPSILON(missing\_value)}
789   roundoff = 1.e-4
790 
791   \textcolor{keywordflow}{if} (.not.spongedataongrid) \textcolor{keywordflow}{then}
792     \textcolor{keywordflow}{if} (is\_root\_pe()) &
793       \textcolor{keyword}{call }time\_interp\_external(fms\_id, time, data\_in, verbose=.true., turns=turns)
794     \textcolor{comment}{! loop through each data level and interpolate to model grid.}
795     \textcolor{comment}{! after interpolating, fill in points which will be needed}
796     \textcolor{comment}{! to define the layers}
797     \textcolor{keywordflow}{do} k=1,kd
798       \textcolor{keyword}{write}(laynum,\textcolor{stringliteral}{'(I8)'}) k ; laynum = adjustl(laynum)
799       \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}
800         tr\_in(1:id,1:jd) = data\_in(1:id,1:jd,k)
801         \textcolor{keywordflow}{if} (add\_np) \textcolor{keywordflow}{then}
802          last\_row(:)=tr\_in(:,jd); pole=0.0;npole=0.0
803          \textcolor{keywordflow}{do} i=1,id
804            \textcolor{keywordflow}{if} (abs(tr\_in(i,jd)-missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}
805              pole = pole+last\_row(i)
806              npole = npole+1.0
807 \textcolor{keywordflow}{           endif}
808 \textcolor{keywordflow}{         enddo}
809          \textcolor{keywordflow}{if} (npole > 0) \textcolor{keywordflow}{then}
810            pole=pole/npole
811          \textcolor{keywordflow}{else}
812            pole=missing\_value
813 \textcolor{keywordflow}{         endif}
814          tr\_inp(:,1:jd) = tr\_in(:,:)
815          tr\_inp(:,jdp) = pole
816         \textcolor{keywordflow}{else}
817          tr\_inp(:,:) = tr\_in(:,:)
818 \textcolor{keywordflow}{        endif}
819 \textcolor{keywordflow}{      endif}
820 
821       \textcolor{keyword}{call }mpp\_sync()
822       \textcolor{keyword}{call }mpp\_broadcast(tr\_inp, id*jdp, root\_pe())
823       \textcolor{keyword}{call }mpp\_sync\_self()
824 
825       mask\_in=0.0
826 
827       \textcolor{keywordflow}{do} j=1,jdp ; \textcolor{keywordflow}{do} i=1,id
828         \textcolor{keywordflow}{if} (abs(tr\_inp(i,j)-missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}
829           mask\_in(i,j)=1.0
830           tr\_inp(i,j) = tr\_inp(i,j) * conversion
831         \textcolor{keywordflow}{else}
832           tr\_inp(i,j) = missing\_value
833 \textcolor{keywordflow}{        endif}
834 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
835 
836       \textcolor{comment}{! call fms routine horiz\_interp to interpolate input level data to model horizontal grid}
837       \textcolor{keywordflow}{if} (k == 1) \textcolor{keywordflow}{then}
838         \textcolor{keyword}{call }horiz\_interp\_new(interp, x\_in, y\_in, lon\_out(is:ie,js:je), lat\_out(is:ie,js:je), &
839                               interp\_method=\textcolor{stringliteral}{'bilinear'}, src\_modulo=.true.)
840 \textcolor{keywordflow}{      endif}
841 
842       \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
843         \textcolor{keyword}{call }mystats(tr\_in, missing\_value, 1, id, 1, jd, k, \textcolor{stringliteral}{'Tracer from file'})
844 \textcolor{keywordflow}{      endif}
845 
846       tr\_out(:,:) = 0.0
847 
848       \textcolor{keyword}{call }horiz\_interp(interp, tr\_inp, tr\_out(is:ie,js:je), missing\_value=missing\_value, &
849                         new\_missing\_handle=.true.)
850 
851       mask\_out(:,:) = 1.0
852       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
853         \textcolor{keywordflow}{if} (abs(tr\_out(i,j)-missing\_value) < abs(roundoff*missing\_value)) mask\_out(i,j) = 0.
854 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
855 
856       fill(:,:) = 0.0 ; good(:,:) = 0.0
857 
858       npoints = 0 ; varavg = 0.
859       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
860         \textcolor{keywordflow}{if} (mask\_out(i,j) < 1.0) \textcolor{keywordflow}{then}
861           tr\_out(i,j) = missing\_value
862         \textcolor{keywordflow}{else}
863           good(i,j) = 1.0
864           npoints = npoints + 1
865           varavg = varavg + tr\_out(i,j)
866 \textcolor{keywordflow}{        endif}
867         \textcolor{keywordflow}{if} ((g%mask2dT(i,j) == 1.0) .and. (z\_edges\_in(k) <= g%bathyT(i,j)) .and. &
868             (mask\_out(i,j) < 1.0)) &
869           fill(i,j)=1.0
870 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{  enddo}
871       \textcolor{keyword}{call }pass\_var(fill, g%Domain)
872       \textcolor{keyword}{call }pass\_var(good, g%Domain)
873 
874       \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
875         \textcolor{keyword}{call }mystats(tr\_out, missing\_value, is, ie, js, je, k, \textcolor{stringliteral}{'variable from horiz\_interp()'})
876 \textcolor{keywordflow}{      endif}
877 
878       \textcolor{comment}{! Horizontally homogenize data to produce perfectly "flat" initial conditions}
879       \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(homogenize)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (homogenize) \textcolor{keywordflow}{then}
880         \textcolor{keyword}{call }sum\_across\_pes(npoints)
881         \textcolor{keyword}{call }sum\_across\_pes(varavg)
882         \textcolor{keywordflow}{if} (npoints>0) \textcolor{keywordflow}{then}
883           varavg = varavg/\textcolor{keywordtype}{real}(npoints)
884 \textcolor{keywordflow}{        endif}
885         tr\_out(:,:) = varavg
886 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ endif}
887 
888       \textcolor{comment}{! tr\_out contains input z-space data on the model grid with missing values}
889       \textcolor{comment}{! now fill in missing values using "ICE-nine" algorithm.}
890       tr\_outf(:,:) = tr\_out(:,:)
891       \textcolor{keywordflow}{if} (k==1) tr\_prev(:,:) = tr\_outf(:,:)
892       good2(:,:) = good(:,:)
893       fill2(:,:) = fill(:,:)
894 
895       \textcolor{keyword}{call }fill\_miss\_2d(tr\_outf, good2, fill2, tr\_prev, g, smooth=.true., answers\_2018=answers\_2018)
896 
897 \textcolor{comment}{!     if (debug) then}
898 \textcolor{comment}{!       call hchksum(tr\_outf, 'field from fill\_miss\_2d ', G%HI)}
899 \textcolor{comment}{!     endif}
900 
901 \textcolor{comment}{!     call myStats(tr\_outf, missing\_value, is, ie, js, je, k, 'field from fill\_miss\_2d()')}
902 
903       tr\_z(:,:,k) = tr\_outf(:,:)*g%mask2dT(:,:)
904       mask\_z(:,:,k) = good2(:,:) + fill2(:,:)
905       tr\_prev(:,:) = tr\_z(:,:,k)
906 
907       \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
908         \textcolor{keyword}{call }hchksum(tr\_prev,\textcolor{stringliteral}{'field after fill '},g%HI)
909 \textcolor{keywordflow}{      endif}
910 
911 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! kd}
912   \textcolor{keywordflow}{else}
913       \textcolor{keyword}{call }time\_interp\_external(fms\_id, time, data\_in, verbose=.true., turns=turns)
914       \textcolor{keywordflow}{do} k=1,kd
915         \textcolor{keywordflow}{do} j=js,je
916           \textcolor{keywordflow}{do} i=is,ie
917             tr\_z(i,j,k)=data\_in(i,j,k)
918             \textcolor{keywordflow}{if} (abs(tr\_z(i,j,k)-missing\_value) < abs(roundoff*missing\_value)) mask\_z(i,j,k) = 0.
919 \textcolor{keywordflow}{          enddo}
920 \textcolor{keywordflow}{        enddo}
921 \textcolor{keywordflow}{      enddo}
922 \textcolor{keywordflow}{  endif}
923 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_a1668fd9b402d78a7ececce78fa21696a}\label{namespacemom__horizontal__regridding_a1668fd9b402d78a7ececce78fa21696a}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record@{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record}}
\index{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record@{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record()}{horiz\_interp\_and\_extrap\_tracer\_record()}}
{\footnotesize\ttfamily subroutine mom\+\_\+horizontal\+\_\+regridding\+::horiz\+\_\+interp\+\_\+and\+\_\+extrap\+\_\+tracer\+\_\+record (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{filename,  }\item[{character(len=$\ast$), intent(in)}]{varnam,  }\item[{real, intent(in)}]{conversion,  }\item[{integer, intent(in)}]{recnum,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(\+:,\+:,\+:), allocatable}]{tr\+\_\+z,  }\item[{real, dimension(\+:,\+:,\+:), allocatable}]{mask\+\_\+z,  }\item[{real, dimension(\+:), allocatable}]{z\+\_\+in,  }\item[{real, dimension(\+:), allocatable}]{z\+\_\+edges\+\_\+in,  }\item[{real, intent(out)}]{missing\+\_\+value,  }\item[{logical, intent(in)}]{reentrant\+\_\+x,  }\item[{logical, intent(in)}]{tripolar\+\_\+n,  }\item[{logical, intent(in), optional}]{homogenize,  }\item[{real, intent(in), optional}]{m\+\_\+to\+\_\+Z,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018,  }\item[{logical, intent(in), optional}]{ongrid }\end{DoxyParamCaption})}



Extrapolate and interpolate from a file record. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em filename} & Path to file containing tracer to be interpolated.\\
\hline
\mbox{\tt in}  & {\em varnam} & Name of tracer in filee.\\
\hline
\mbox{\tt in}  & {\em conversion} & Conversion factor for tracer.\\
\hline
\mbox{\tt in}  & {\em recnum} & Record number of tracer to be read.\\
\hline
\mbox{\tt in,out}  & {\em g} & Grid object\\
\hline
 & {\em tr\+\_\+z} & pointer to allocatable tracer array on local model grid and input-\/file vertical levels.\\
\hline
 & {\em mask\+\_\+z} & pointer to allocatable tracer mask array on local model grid and input-\/file vertical levels.\\
\hline
 & {\em z\+\_\+in} & Cell grid values for input data.\\
\hline
 & {\em z\+\_\+edges\+\_\+in} & Cell grid edge values for input data.\\
\hline
\mbox{\tt out}  & {\em missing\+\_\+value} & The missing value in the returned array.\\
\hline
\mbox{\tt in}  & {\em reentrant\+\_\+x} & If true, this grid is reentrant in the x-\/direction\\
\hline
\mbox{\tt in}  & {\em tripolar\+\_\+n} & If true, this is a northern tripolar grid\\
\hline
\mbox{\tt in}  & {\em homogenize} & If present and true, horizontally homogenize data to produce perfectly \char`\"{}flat\char`\"{} initial conditions\\
\hline
\mbox{\tt in}  & {\em m\+\_\+to\+\_\+z} & A conversion factor from meters to the units of depth. If missing, GbathyT must be in m.\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true, use expressions that give the same answers as the code did in late 2018. Otherwise add parentheses for rotational symmetry.\\
\hline
\mbox{\tt in}  & {\em ongrid} & If true, then data are assumed to have been interpolated to the model horizontal grid. In this case, only extrapolation is performed by this routine \\
\hline
\end{DoxyParams}


Definition at line 277 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
277 
278   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: filename\textcolor{comment}{   !< Path to file containing tracer to be}
279 \textcolor{comment}{                                                     !! interpolated.}
280   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: varnam\textcolor{comment}{     !< Name of tracer in filee.}
281   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: conversion\textcolor{comment}{ !< Conversion factor for tracer.}
282   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: recnum\textcolor{comment}{     !< Record number of tracer to be read.}
283   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{          !< Grid object}
284   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: tr\_z\textcolor{comment}{       !< pointer to allocatable tracer array on local}
285 \textcolor{comment}{                                                     !! model grid and input-file vertical levels.}
286   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: mask\_z\textcolor{comment}{     !< pointer to allocatable tracer mask array on}
287 \textcolor{comment}{                                                     !! local model grid and input-file vertical levels.}
288   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_in\textcolor{comment}{       !< Cell grid values for input data.}
289   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_edges\_in\textcolor{comment}{ !< Cell grid edge values for input data.}
290   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)}   :: missing\_value\textcolor{comment}{ !< The missing value in the returned array.}
291   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: reentrant\_x\textcolor{comment}{ !< If true, this grid is reentrant in the x-direction}
292   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: tripolar\_n\textcolor{comment}{ !< If true, this is a northern tripolar grid}
293   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: homogenize\textcolor{comment}{ !< If present and true, horizontally homogenize data}
294 \textcolor{comment}{                                                     !! to produce perfectly "flat" initial conditions}
295   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: m\_to\_z\textcolor{comment}{     !< A conversion factor from meters to the units}
296 \textcolor{comment}{                                                     !! of depth.  If missing, G%bathyT must be in m.}
297   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use expressions that give the same}
298 \textcolor{comment}{                                                     !! answers as the code did in late 2018.  Otherwise}
299 \textcolor{comment}{                                                     !! add parentheses for rotational symmetry.}
300   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: ongrid\textcolor{comment}{     !< If true, then data are assumed to have been
       interpolated}
301 \textcolor{comment}{                                                     !! to the model horizontal grid. In this case, only}
302 \textcolor{comment}{                                                     !! extrapolation is performed by this routine}
303 
304   \textcolor{comment}{! Local variables}
305   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},  \textcolor{keywordtype}{allocatable}   :: tr\_in, tr\_inp \textcolor{comment}{! A 2-d array for holding input data on}
306                                                      \textcolor{comment}{! native horizontal grid and extended grid}
307                                                      \textcolor{comment}{! with poles.}
308   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},  \textcolor{keywordtype}{allocatable}   :: mask\_in    \textcolor{comment}{! A 2-d mask for extended input grid.}
309 
310   \textcolor{keywordtype}{real} :: pi\_180
311   \textcolor{keywordtype}{integer} :: rcode, ncid, varid, ndims, id, jd, kd, jdp
312   \textcolor{keywordtype}{integer} :: i,j,k
313   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: start, count, dims, dim\_id
314   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: x\_in, y\_in
315   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lon\_in, lat\_in
316   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lat\_inp, last\_row
317   \textcolor{keywordtype}{real} :: max\_lat, min\_lat, pole, max\_depth, npole
318   \textcolor{keywordtype}{real} :: roundoff  \textcolor{comment}{! The magnitude of roundoff, usually ~2e-16.}
319   \textcolor{keywordtype}{real} :: add\_offset, scale\_factor
320   \textcolor{keywordtype}{logical} :: add\_np
321   \textcolor{keywordtype}{logical} :: is\_ongrid
322   \textcolor{keywordtype}{character(len=8)}  :: laynum
323   \textcolor{keywordtype}{type}(horiz\_interp\_type) :: interp
324   \textcolor{keywordtype}{integer} :: is, ie, js, je     \textcolor{comment}{! compute domain indices}
325   \textcolor{keywordtype}{integer} :: isc,iec,jsc,jec    \textcolor{comment}{! global compute domain indices}
326   \textcolor{keywordtype}{integer} :: isg, ieg, jsg, jeg \textcolor{comment}{! global extent}
327   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed \textcolor{comment}{! data domain indices}
328   \textcolor{keywordtype}{integer} :: id\_clock\_read
329   \textcolor{keywordtype}{character(len=12)}  :: dim\_name(4)
330   \textcolor{keywordtype}{logical} :: debug=.false.
331   \textcolor{keywordtype}{real} :: npoints,varavg
332   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: lon\_out, lat\_out, tr\_out, mask\_out
333   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: good, fill
334   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: tr\_outf,tr\_prev
335   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: good2,fill2
336   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: nlevs
337 
338   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
339   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
340   isg = g%isg ; ieg = g%ieg ; jsg = g%jsg ; jeg = g%jeg
341 
342   id\_clock\_read = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize tracer from Z) read'}, grain=clock\_loop)
343 
344   is\_ongrid=.false.
345   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ongrid)) is\_ongrid=ongrid
346 
347   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(tr\_z)) \textcolor{keyword}{deallocate}(tr\_z)
348   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(mask\_z)) \textcolor{keyword}{deallocate}(mask\_z)
349   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_edges\_in)) \textcolor{keyword}{deallocate}(z\_edges\_in)
350 
351   pi\_180=atan(1.0)/45.
352 
353   \textcolor{comment}{! Open NetCDF file and if present, extract data and spatial coordinate information}
354   \textcolor{comment}{! The convention adopted here requires that the data be written in (i,j,k) ordering.}
355 
356   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_read)
357 
358   rcode = nf90\_open(filename, nf90\_nowrite, ncid)
359   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error opening file "}//trim(filename)//&
360                            \textcolor{stringliteral}{" in hinterp\_extrap"})
361   rcode = nf90\_inq\_varid(ncid, varnam, varid)
362   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(varnam)//&
363                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
364 
365   rcode = nf90\_inquire\_variable(ncid, varid, ndims=ndims, dimids=dims)
366   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'error inquiring dimensions hinterp\_extrap'})
367   \textcolor{keywordflow}{if} (ndims < 3) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Variable "}//trim(varnam)//\textcolor{stringliteral}{" in file "}// &
368               trim(filename)//\textcolor{stringliteral}{" has too few dimensions."})
369 
370   rcode = nf90\_inquire\_dimension(ncid, dims(1), dim\_name(1), len=id)
371   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 1 data for "}// &
372                 trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
373   rcode = nf90\_inq\_varid(ncid, dim\_name(1), dim\_id(1))
374   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(dim\_name(1))//&
375                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
376   rcode = nf90\_inquire\_dimension(ncid, dims(2), dim\_name(2), len=jd)
377   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 2 data for "}// &
378                 trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
379   rcode = nf90\_inq\_varid(ncid, dim\_name(2), dim\_id(2))
380   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(dim\_name(2))//&
381                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
382   rcode = nf90\_inquire\_dimension(ncid, dims(3), dim\_name(3), len=kd)
383   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 3 data for "}// &
384                 trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
385   rcode = nf90\_inq\_varid(ncid, dim\_name(3), dim\_id(3))
386   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(dim\_name(3))//&
387                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
388 
389   missing\_value=0.0
390   rcode = nf90\_get\_att(ncid, varid, \textcolor{stringliteral}{"\_FillValue"}, missing\_value)
391   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding missing value for "}//&
392        trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})
393 
394   rcode = nf90\_get\_att(ncid, varid, \textcolor{stringliteral}{"add\_offset"}, add\_offset)
395   \textcolor{keywordflow}{if} (rcode /= 0) add\_offset = 0.0
396 
397   rcode = nf90\_get\_att(ncid, varid, \textcolor{stringliteral}{"scale\_factor"}, scale\_factor)
398   \textcolor{keywordflow}{if} (rcode /= 0) scale\_factor = 1.0
399 
400   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lon\_in)) \textcolor{keyword}{deallocate}(lon\_in)
401   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lat\_in)) \textcolor{keyword}{deallocate}(lat\_in)
402   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_in)) \textcolor{keyword}{deallocate}(z\_in)
403   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_edges\_in)) \textcolor{keyword}{deallocate}(z\_edges\_in)
404   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(tr\_z)) \textcolor{keyword}{deallocate}(tr\_z)
405   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(mask\_z)) \textcolor{keyword}{deallocate}(mask\_z)
406 
407   \textcolor{keyword}{allocate}(lon\_in(id),lat\_in(jd),z\_in(kd),z\_edges\_in(kd+1))
408   \textcolor{keyword}{allocate}(tr\_z(isd:ied,jsd:jed,kd), mask\_z(isd:ied,jsd:jed,kd))
409 
410   start = 1; count = 1; count(1) = id
411   rcode = nf90\_get\_var(ncid, dim\_id(1), lon\_in, start, count)
412   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 1 values for var\_name "}// &
413                 trim(varnam)//\textcolor{stringliteral}{",dim\_name "}//trim(dim\_name(1))//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in
       hinterp\_extrap"})
414   start = 1; count = 1; count(1) = jd
415   rcode = nf90\_get\_var(ncid, dim\_id(2), lat\_in, start, count)
416   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 2 values for var\_name "}// &
417                 trim(varnam)//\textcolor{stringliteral}{",dim\_name "}//trim(dim\_name(2))//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in 
       hinterp\_extrap"})
418   start = 1; count = 1; count(1) = kd
419   rcode = nf90\_get\_var(ncid, dim\_id(3), z\_in, start, count)
420   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 3 values for var\_name "}// &
421                 trim(varnam//\textcolor{stringliteral}{",dim\_name "}//trim(dim\_name(3)))//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in 
       hinterp\_extrap"})
422 
423   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_read)
424 
425   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(m\_to\_z)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,kd ; z\_in(k) = m\_to\_z * z\_in(k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
426 
427   \textcolor{comment}{! extrapolate the input data to the north pole using the northerm-most latitude}
428   add\_np=.false.
429   jdp=jd
430   \textcolor{keywordflow}{if} (.not. is\_ongrid) \textcolor{keywordflow}{then}
431      max\_lat = maxval(lat\_in)
432      \textcolor{keywordflow}{if} (max\_lat < 90.0) \textcolor{keywordflow}{then}
433         add\_np=.true.
434         jdp=jd+1
435         \textcolor{keyword}{allocate}(lat\_inp(jdp))
436         lat\_inp(1:jd)=lat\_in(:)
437         lat\_inp(jd+1)=90.0
438         \textcolor{keyword}{deallocate}(lat\_in)
439         \textcolor{keyword}{allocate}(lat\_in(1:jdp))
440         lat\_in(:)=lat\_inp(:)
441 \textcolor{keywordflow}{     endif}
442 \textcolor{keywordflow}{  endif}
443   \textcolor{comment}{! construct level cell boundaries as the mid-point between adjacent centers}
444 
445   z\_edges\_in(1) = 0.0
446   \textcolor{keywordflow}{do} k=2,kd
447     z\_edges\_in(k)=0.5*(z\_in(k-1)+z\_in(k))
448 \textcolor{keywordflow}{  enddo}
449   z\_edges\_in(kd+1)=2.0*z\_in(kd) - z\_in(kd-1)
450 
451   \textcolor{keywordflow}{if} (is\_ongrid) \textcolor{keywordflow}{then}
452      \textcolor{keyword}{allocate}(tr\_in(is:ie,js:je)) ; tr\_in(:,:)=0.0
453      \textcolor{keyword}{allocate}(mask\_in(is:ie,js:je)) ; mask\_in(:,:)=0.0
454   \textcolor{keywordflow}{else}
455      \textcolor{keyword}{call }horiz\_interp\_init()
456      lon\_in = lon\_in*pi\_180
457      lat\_in = lat\_in*pi\_180
458      \textcolor{keyword}{allocate}(x\_in(id,jdp),y\_in(id,jdp))
459      \textcolor{keyword}{call }meshgrid(lon\_in,lat\_in, x\_in, y\_in)
460      lon\_out(:,:) = g%geoLonT(:,:)*pi\_180
461      lat\_out(:,:) = g%geoLatT(:,:)*pi\_180
462      \textcolor{keyword}{allocate}(tr\_in(id,jd)) ; tr\_in(:,:)=0.0
463      \textcolor{keyword}{allocate}(tr\_inp(id,jdp)) ; tr\_inp(:,:)=0.0
464      \textcolor{keyword}{allocate}(mask\_in(id,jdp)) ; mask\_in(:,:)=0.0
465      \textcolor{keyword}{allocate}(last\_row(id))    ; last\_row(:)=0.0
466 \textcolor{keywordflow}{  endif}
467 
468 
469 
470   max\_depth = maxval(g%bathyT)
471   \textcolor{keyword}{call }mpp\_max(max\_depth)
472 
473   \textcolor{keywordflow}{if} (z\_edges\_in(kd+1)<max\_depth) z\_edges\_in(kd+1)=max\_depth
474   roundoff = 3.0*epsilon(missing\_value)
475 
476   \textcolor{comment}{! loop through each data level and interpolate to model grid.}
477   \textcolor{comment}{! after interpolating, fill in points which will be needed}
478   \textcolor{comment}{! to define the layers}
479   \textcolor{keywordflow}{do} k=1,kd
480     \textcolor{keyword}{write}(laynum,\textcolor{stringliteral}{'(I8)'}) k ; laynum = adjustl(laynum)
481     mask\_in=0.0
482     \textcolor{keywordflow}{if} (is\_ongrid) \textcolor{keywordflow}{then}
483        start(1) = is+g%HI%idg\_offset ; start(2) = js+g%HI%jdg\_offset ; start(3) = k
484        count(1) = ie-is+1 ; count(2) = je-js+1; count(3) = 1
485        rcode = nf90\_get\_var(ncid,varid, tr\_in, start, count)
486        \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"hinterp\_and\_extract\_from\_Fie: "}//&
487             \textcolor{stringliteral}{"error reading level "}//trim(laynum)//\textcolor{stringliteral}{" of variable "}//&
488             trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename))
489 
490        \textcolor{keywordflow}{do} j=js,je
491          \textcolor{keywordflow}{do} i=is,ie
492            \textcolor{keywordflow}{if} (abs(tr\_in(i,j)-missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}
493               mask\_in(i,j) = 1.0
494               tr\_in(i,j) = (tr\_in(i,j)*scale\_factor+add\_offset) * conversion
495            \textcolor{keywordflow}{else}
496               tr\_in(i,j) = missing\_value
497 \textcolor{keywordflow}{           endif}
498 \textcolor{keywordflow}{         enddo}
499 \textcolor{keywordflow}{       enddo}
500 
501     \textcolor{keywordflow}{else}
502        \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}
503           start = 1 ; start(3) = k ; count(:) = 1 ; count(1) = id ; count(2) = jd
504           rcode = nf90\_get\_var(ncid,varid, tr\_in, start, count)
505           \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"hinterp\_and\_extract\_from\_Fie: "}//&
506                \textcolor{stringliteral}{"error reading level "}//trim(laynum)//\textcolor{stringliteral}{" of variable "}//&
507                trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename))
508 
509           \textcolor{keywordflow}{if} (add\_np) \textcolor{keywordflow}{then}
510              last\_row(:)=tr\_in(:,jd); pole=0.0;npole=0.0
511              \textcolor{keywordflow}{do} i=1,id
512                \textcolor{keywordflow}{if} (abs(tr\_in(i,jd)-missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}
513                   pole = pole+last\_row(i)
514                   npole = npole+1.0
515 \textcolor{keywordflow}{               endif}
516 \textcolor{keywordflow}{             enddo}
517              \textcolor{keywordflow}{if} (npole > 0) \textcolor{keywordflow}{then}
518                 pole=pole/npole
519              \textcolor{keywordflow}{else}
520                 pole=missing\_value
521 \textcolor{keywordflow}{             endif}
522              tr\_inp(:,1:jd) = tr\_in(:,:)
523              tr\_inp(:,jdp) = pole
524           \textcolor{keywordflow}{else}
525              tr\_inp(:,:) = tr\_in(:,:)
526 \textcolor{keywordflow}{          endif}
527 \textcolor{keywordflow}{       endif}
528 
529        \textcolor{keyword}{call }mpp\_sync()
530        \textcolor{keyword}{call }mpp\_broadcast(tr\_inp, id*jdp, root\_pe())
531        \textcolor{keyword}{call }mpp\_sync\_self()
532 
533        \textcolor{keywordflow}{do} j=1,jdp
534          \textcolor{keywordflow}{do} i=1,id
535            \textcolor{keywordflow}{if} (abs(tr\_inp(i,j)-missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}
536               mask\_in(i,j) = 1.0
537               tr\_inp(i,j) = (tr\_inp(i,j)*scale\_factor+add\_offset) * conversion
538            \textcolor{keywordflow}{else}
539               tr\_inp(i,j) = missing\_value
540 \textcolor{keywordflow}{           endif}
541 \textcolor{keywordflow}{         enddo}
542 \textcolor{keywordflow}{       enddo}
543 
544 \textcolor{keywordflow}{    endif}
545 
546 
547 
548 \textcolor{comment}{!   call fms routine horiz\_interp to interpolate input level data to model horizontal grid}
549     \textcolor{keywordflow}{if} (.not. is\_ongrid) \textcolor{keywordflow}{then}
550        \textcolor{keywordflow}{if} (k == 1) \textcolor{keywordflow}{then}
551           \textcolor{keyword}{call }horiz\_interp\_new(interp,x\_in,y\_in,lon\_out(is:ie,js:je),lat\_out(is:ie,js:je), &
552                interp\_method=\textcolor{stringliteral}{'bilinear'},src\_modulo=.true.)
553 \textcolor{keywordflow}{       endif}
554 
555        \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
556           \textcolor{keyword}{call }mystats(tr\_inp,missing\_value, is,ie,js,je,k,\textcolor{stringliteral}{'Tracer from file'})
557 \textcolor{keywordflow}{       endif}
558 \textcolor{keywordflow}{    endif}
559 
560     tr\_out(:,:) = 0.0
561     \textcolor{keywordflow}{if} (is\_ongrid) \textcolor{keywordflow}{then}
562        tr\_out(is:ie,js:je)=tr\_in(is:ie,js:je)
563     \textcolor{keywordflow}{else}
564        \textcolor{keyword}{call }horiz\_interp(interp,tr\_inp,tr\_out(is:ie,js:je), missing\_value=missing\_value, new\_missing\_handle
      =.true.)
565 \textcolor{keywordflow}{    endif}
566 
567     mask\_out=1.0
568     \textcolor{keywordflow}{do} j=js,je
569       \textcolor{keywordflow}{do} i=is,ie
570         \textcolor{keywordflow}{if} (abs(tr\_out(i,j)-missing\_value) < abs(roundoff*missing\_value)) mask\_out(i,j)=0.
571 \textcolor{keywordflow}{      enddo}
572 \textcolor{keywordflow}{    enddo}
573 
574     fill = 0.0; good = 0.0
575 
576     npoints = 0 ; varavg = 0.
577     \textcolor{keywordflow}{do} j=js,je
578       \textcolor{keywordflow}{do} i=is,ie
579         \textcolor{keywordflow}{if} (mask\_out(i,j) < 1.0) \textcolor{keywordflow}{then}
580           tr\_out(i,j)=missing\_value
581         \textcolor{keywordflow}{else}
582           good(i,j)=1.0
583           npoints = npoints + 1
584           varavg = varavg + tr\_out(i,j)
585 \textcolor{keywordflow}{        endif}
586         \textcolor{keywordflow}{if} (g%mask2dT(i,j) == 1.0 .and. z\_edges\_in(k) <= g%bathyT(i,j) .and. mask\_out(i,j) < 1.0) &
587           fill(i,j)=1.0
588 \textcolor{keywordflow}{      enddo}
589 \textcolor{keywordflow}{    enddo}
590     \textcolor{keyword}{call }pass\_var(fill,g%Domain)
591     \textcolor{keyword}{call }pass\_var(good,g%Domain)
592 
593     \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
594       \textcolor{keyword}{call }mystats(tr\_out,missing\_value, is,ie,js,je,k,\textcolor{stringliteral}{'variable from horiz\_interp()'})
595 \textcolor{keywordflow}{    endif}
596 
597     \textcolor{comment}{! Horizontally homogenize data to produce perfectly "flat" initial conditions}
598     \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(homogenize)) \textcolor{keywordflow}{then}
599        \textcolor{keywordflow}{if} (homogenize) \textcolor{keywordflow}{then}
600           \textcolor{keyword}{call }sum\_across\_pes(npoints)
601           \textcolor{keyword}{call }sum\_across\_pes(varavg)
602           \textcolor{keywordflow}{if} (npoints>0) \textcolor{keywordflow}{then}
603              varavg = varavg/\textcolor{keywordtype}{real}(npoints)
604 \textcolor{keywordflow}{          endif}
605           tr\_out(:,:) = varavg
606 \textcolor{keywordflow}{       endif}
607 \textcolor{keywordflow}{    endif}
608 
609     \textcolor{comment}{! tr\_out contains input z-space data on the model grid with missing values}
610     \textcolor{comment}{! now fill in missing values using "ICE-nine" algorithm.}
611     tr\_outf(:,:) = tr\_out(:,:)
612     \textcolor{keywordflow}{if} (k==1) tr\_prev(:,:) = tr\_outf(:,:)
613     good2(:,:) = good(:,:)
614     fill2(:,:) = fill(:,:)
615 
616     \textcolor{keyword}{call }fill\_miss\_2d(tr\_outf, good2, fill2, tr\_prev, g, smooth=.true., answers\_2018=answers\_2018)
617     \textcolor{keyword}{call }mystats(tr\_outf, missing\_value, is, ie, js, je, k, \textcolor{stringliteral}{'field from fill\_miss\_2d()'})
618 
619     tr\_z(:,:,k) = tr\_outf(:,:) * g%mask2dT(:,:)
620     mask\_z(:,:,k) = good2(:,:) + fill2(:,:)
621 
622     tr\_prev(:,:) = tr\_z(:,:,k)
623 
624     \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
625       \textcolor{keyword}{call }hchksum(tr\_prev,\textcolor{stringliteral}{'field after fill '},g%HI)
626 \textcolor{keywordflow}{    endif}
627 
628 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! kd}
629 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_a4612a182a8630f102a29e0cce1bd7a77}\label{namespacemom__horizontal__regridding_a4612a182a8630f102a29e0cce1bd7a77}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!meshgrid@{meshgrid}}
\index{meshgrid@{meshgrid}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{meshgrid()}{meshgrid()}}
{\footnotesize\ttfamily subroutine mom\+\_\+horizontal\+\_\+regridding\+::meshgrid (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{x,  }\item[{real, dimension(\+:), intent(in)}]{y,  }\item[{real, dimension(size(x,1),size(y,1)), intent(inout)}]{x\+\_\+T,  }\item[{real, dimension(size(x,1),size(y,1)), intent(inout)}]{y\+\_\+T }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Create a 2d-\/mesh of grid coordinates from 1-\/d arrays. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em x} & input 1-\/dimensional vector\\
\hline
\mbox{\tt in}  & {\em y} & input 1-\/dimensional vector\\
\hline
\mbox{\tt in,out}  & {\em x\+\_\+t} & output 2-\/dimensional array\\
\hline
\mbox{\tt in,out}  & {\em y\+\_\+t} & output 2-\/dimensional array \\
\hline
\end{DoxyParams}


Definition at line 928 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
928   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},                   \textcolor{keywordtype}{intent(in)}    :: x\textcolor{comment}{  !< input 1-dimensional vector}
929   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},                   \textcolor{keywordtype}{intent(in)}    :: y\textcolor{comment}{  !< input 1-dimensional vector}
930   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(x,1),size(y,1))}, \textcolor{keywordtype}{intent(inout)} :: x\_t\textcolor{comment}{ !< output 2-dimensional array}
931   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(x,1),size(y,1))}, \textcolor{keywordtype}{intent(inout)} :: y\_t\textcolor{comment}{ !< output 2-dimensional array}
932 
933   \textcolor{keywordtype}{integer} :: ni,nj,i,j
934 
935   ni=\textcolor{keyword}{size}(x,1) ; nj=\textcolor{keyword}{size}(y,1)
936 
937   \textcolor{keywordflow}{do} j=1,nj ; \textcolor{keywordflow}{do} i=1,ni
938     x\_t(i,j) = x(i)
939 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
940 
941   \textcolor{keywordflow}{do} j=1,nj ; \textcolor{keywordflow}{do} i=1,ni
942     y\_t(i,j) = y(j)
943 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
944 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_a2eefabc60ef9735714237dd2094963cd}\label{namespacemom__horizontal__regridding_a2eefabc60ef9735714237dd2094963cd}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!mystats@{mystats}}
\index{mystats@{mystats}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{mystats()}{mystats()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+horizontal\+\_\+regridding\+::mystats (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), intent(in)}]{array,  }\item[{real, intent(in)}]{missing,  }\item[{integer}]{is,  }\item[{integer}]{ie,  }\item[{integer}]{js,  }\item[{integer}]{je,  }\item[{integer}]{k,  }\item[{character(len=$\ast$)}]{mesg }\end{DoxyParamCaption})}



Write to the terminal some basic statistics about the k-\/th level of an array. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em array} & input array (ND)\\
\hline
\mbox{\tt in}  & {\em missing} & missing value (ND)\\
\hline
 & {\em is} & Start index in i\\
\hline
 & {\em ie} & End index in i\\
\hline
 & {\em js} & Start index in j\\
\hline
 & {\em je} & End index in j\\
\hline
 & {\em k} & Level to calculate statistics for\\
\hline
 & {\em mesg} & Label to use in message \\
\hline
\end{DoxyParams}


Definition at line 62 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
62   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)} :: array\textcolor{comment}{ !< input array (ND)}
63   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: missing\textcolor{comment}{ !< missing value (ND)}
64   \textcolor{keywordtype}{integer} :: is\textcolor{comment}{   !< Start index in i}
65   \textcolor{keywordtype}{integer} :: ie\textcolor{comment}{   !< End index in i}
66   \textcolor{keywordtype}{integer} :: js\textcolor{comment}{   !< Start index in j}
67   \textcolor{keywordtype}{integer} :: je\textcolor{comment}{   !< End index in j}
68   \textcolor{keywordtype}{integer} :: k\textcolor{comment}{ !< Level to calculate statistics for}
69   \textcolor{keywordtype}{character(len=*)} :: mesg\textcolor{comment}{ !< Label to use in message}
70   \textcolor{comment}{! Local variables}
71   \textcolor{keywordtype}{real} :: mina, maxa
72   \textcolor{keywordtype}{integer} :: i,j
73   \textcolor{keywordtype}{logical} :: found
74   \textcolor{keywordtype}{character(len=120)} :: lmesg
75   mina = 9.e24 ; maxa = -9.e24 ; found = .false.
76 
77   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
78     \textcolor{keywordflow}{if} (array(i,j) /= array(i,j)) stop \textcolor{stringliteral}{'Nan!'}
79     \textcolor{keywordflow}{if} (abs(array(i,j)-missing) > 1.e-6*abs(missing)) \textcolor{keywordflow}{then}
80       \textcolor{keywordflow}{if} (found) \textcolor{keywordflow}{then}
81         mina = min(mina, array(i,j))
82         maxa = max(maxa, array(i,j))
83       \textcolor{keywordflow}{else}
84         found = .true.
85         mina = array(i,j)
86         maxa = array(i,j)
87 \textcolor{keywordflow}{      endif}
88 \textcolor{keywordflow}{    endif}
89 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
90   \textcolor{keyword}{call }min\_across\_pes(mina)
91   \textcolor{keyword}{call }max\_across\_pes(maxa)
92   \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}
93     \textcolor{keyword}{write}(lmesg(1:120),\textcolor{stringliteral}{'(2(a,es12.4),a,i3,x,a)'}) &
94          \textcolor{stringliteral}{'init\_from\_Z: min='},mina,\textcolor{stringliteral}{' max='},maxa,\textcolor{stringliteral}{' Level='},k,trim(mesg)
95     \textcolor{keyword}{call }mom\_mesg(lmesg,2)
96 \textcolor{keywordflow}{  endif}
97 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__horizontal__regridding_a333ea43962d49ea6730eeb7bff8923f6}\label{namespacemom__horizontal__regridding_a333ea43962d49ea6730eeb7bff8923f6}} 
\index{mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}!smooth\+\_\+heights@{smooth\+\_\+heights}}
\index{smooth\+\_\+heights@{smooth\+\_\+heights}!mom\+\_\+horizontal\+\_\+regridding@{mom\+\_\+horizontal\+\_\+regridding}}
\subsubsection{\texorpdfstring{smooth\+\_\+heights()}{smooth\_heights()}}
{\footnotesize\ttfamily subroutine mom\+\_\+horizontal\+\_\+regridding\+::smooth\+\_\+heights (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), intent(inout)}]{zi,  }\item[{integer, dimension(size(zi,1),size(zi,2)), intent(in)}]{fill,  }\item[{integer, dimension(size(zi,1),size(zi,2)), intent(in)}]{bad,  }\item[{real, intent(in)}]{sor,  }\item[{integer, intent(in)}]{niter,  }\item[{logical, intent(in)}]{cyclic\+\_\+x,  }\item[{logical, intent(in)}]{tripolar\+\_\+n }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Solve del2 (zi) = 0 using successive iterations with a 5 point stencil. Only points fill==1 are modified. Except where bad==1, information propagates isotropically in index space. The resulting solution in each region is an approximation to del2(zi)=0 subject to boundary conditions along the valid points curve bounding this region. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em zi} & input and output array (ND)\\
\hline
\mbox{\tt in}  & {\em fill} & same shape as zi, 1=fill\\
\hline
\mbox{\tt in}  & {\em bad} & same shape as zi, 1=bad data\\
\hline
\mbox{\tt in}  & {\em sor} & relaxation coefficient (ND)\\
\hline
\mbox{\tt in}  & {\em niter} & maximum number of iterations\\
\hline
\mbox{\tt in}  & {\em cyclic\+\_\+x} & true if domain is zonally reentrant\\
\hline
\mbox{\tt in}  & {\em tripolar\+\_\+n} & true if domain has an Arctic fold \\
\hline
\end{DoxyParams}


Definition at line 1006 of file M\+O\+M\+\_\+horizontal\+\_\+regridding.\+F90.


\begin{DoxyCode}
1006   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{dimension(:,:)},                   \textcolor{keywordtype}{intent(inout)} :: zi\textcolor{comment}{ !< input and output array (ND)}
1007   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(size(zi,1),size(zi,2))}, \textcolor{keywordtype}{intent(in)} :: fill\textcolor{comment}{ !< same shape as zi, 1=fill}
1008   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(size(zi,1),size(zi,2))}, \textcolor{keywordtype}{intent(in)} :: bad\textcolor{comment}{  !< same shape as zi, 1=bad data}
1009   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}  :: sor\textcolor{comment}{ !< relaxation coefficient (ND)}
1010   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)} :: niter\textcolor{comment}{ !< maximum number of iterations}
1011   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)} :: cyclic\_x\textcolor{comment}{ !< true if domain is zonally reentrant}
1012   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)} :: tripolar\_n\textcolor{comment}{ !< true if domain has an Arctic fold}
1013 
1014   \textcolor{comment}{! Local variables}
1015   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(zi,1),size(zi,2))} :: res, m
1016   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(size(zi,1),size(zi,2),4)} :: b
1017   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(0:size(zi,1)+1,0:size(zi,2)+1)} :: mp
1018   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(0:size(zi,1)+1,0:size(zi,2)+1)} :: nm
1019   \textcolor{keywordtype}{integer} :: i,j,k,n
1020   \textcolor{keywordtype}{integer} :: ni,nj
1021   \textcolor{keywordtype}{real} :: isum, bsum
1022 
1023   ni=\textcolor{keyword}{size}(zi,1) ; nj=\textcolor{keyword}{size}(zi,2)
1024 
1025 
1026   mp(:,:) = fill\_boundaries(zi,cyclic\_x,tripolar\_n)
1027 
1028   b(:,:,:) = 0.0
1029   nm(:,:) = fill\_boundaries(bad,cyclic\_x,tripolar\_n)
1030 
1031   \textcolor{keywordflow}{do} j=1,nj
1032     \textcolor{keywordflow}{do} i=1,ni
1033       \textcolor{keywordflow}{if} (fill(i,j) == 1) \textcolor{keywordflow}{then}
1034         b(i,j,1)=1-nm(i+1,j);b(i,j,2)=1-nm(i-1,j)
1035         b(i,j,3)=1-nm(i,j+1);b(i,j,4)=1-nm(i,j-1)
1036 \textcolor{keywordflow}{      endif}
1037 \textcolor{keywordflow}{    enddo}
1038 \textcolor{keywordflow}{  enddo}
1039 
1040   \textcolor{keywordflow}{do} n=1,niter
1041     \textcolor{keywordflow}{do} j=1,nj
1042       \textcolor{keywordflow}{do} i=1,ni
1043         \textcolor{keywordflow}{if} (fill(i,j) == 1) \textcolor{keywordflow}{then}
1044           bsum = \textcolor{keywordtype}{real}(b(i,j,1)+b(i,j,2)+b(i,j,3)+b(i,j,4))
1045           isum = 1.0/bsum
1046           res(i,j)=isum*(b(i,j,1)*mp(i+1,j)+b(i,j,2)*mp(i-1,j)+&
1047                    b(i,j,3)*mp(i,j+1)+b(i,j,4)*mp(i,j-1)) - mp(i,j)
1048 \textcolor{keywordflow}{        endif}
1049 \textcolor{keywordflow}{      enddo}
1050 \textcolor{keywordflow}{    enddo}
1051     res(:,:)=res(:,:)*sor
1052 
1053     \textcolor{keywordflow}{do} j=1,nj
1054       \textcolor{keywordflow}{do} i=1,ni
1055         mp(i,j)=mp(i,j)+res(i,j)
1056 \textcolor{keywordflow}{      enddo}
1057 \textcolor{keywordflow}{    enddo}
1058 
1059     zi(:,:)=mp(1:ni,1:nj)
1060     mp = fill\_boundaries(zi,cyclic\_x,tripolar\_n)
1061 \textcolor{keywordflow}{  enddo}
1062 
\end{DoxyCode}
