\hypertarget{namespacemom__horizontal__regridding}{}\doxysection{mom\+\_\+horizontal\+\_\+regridding Module Reference}
\label{namespacemom__horizontal__regridding}\index{mom\_horizontal\_regridding@{mom\_horizontal\_regridding}}


\doxysubsection{Detailed Description}
Horizontal interpolation. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
interface \mbox{\hyperlink{interfacemom__horizontal__regridding_1_1fill__boundaries}{fill\+\_\+boundaries}}
\begin{DoxyCompactList}\small\item\em Fill grid edges. \end{DoxyCompactList}\item 
interface \mbox{\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}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\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 \mbox{\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 \mbox{\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 \mbox{\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 \mbox{\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) \mbox{\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) \mbox{\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 \mbox{\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}


\doxysubsection{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em m} & input array (ND) \\
\hline
\mbox{\texttt{ in}}  & {\em cyclic\+\_\+x} & True if domain is zonally re-\/entrant \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{951   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}             :: m\textcolor{comment}{ !< input array (ND)}}
\DoxyCodeLine{952   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}             :: cyclic\_x\textcolor{comment}{ !< True if domain is zonally re-\/entrant}}
\DoxyCodeLine{953   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}             :: tripolar\_n\textcolor{comment}{ !< True if domain has an Arctic fold}}
\DoxyCodeLine{954   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(0:size(m,1)+1,0:size(m,2)+1)} :: mp}
\DoxyCodeLine{955 }
\DoxyCodeLine{956 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{dimension(size(m,1),size(m,2))}         :: m\_real}
\DoxyCodeLine{957 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{dimension(0:size(m,1)+1,0:size(m,2)+1)} :: mp\_real}
\DoxyCodeLine{958 }
\DoxyCodeLine{959   m\_real = real(m)}
\DoxyCodeLine{960 }
\DoxyCodeLine{961   mp\_real = fill\_boundaries\_real(m\_real,cyclic\_x,tripolar\_n)}
\DoxyCodeLine{962 }
\DoxyCodeLine{963   mp = int(mp\_real)}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em m} & input array (ND) \\
\hline
\mbox{\texttt{ in}}  & {\em cyclic\+\_\+x} & True if domain is zonally re-\/entrant \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{969 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}             :: m\textcolor{comment}{ !< input array (ND)}}
\DoxyCodeLine{970   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in)}             :: cyclic\_x\textcolor{comment}{ !< True if domain is zonally re-\/entrant}}
\DoxyCodeLine{971   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in)}             :: tripolar\_n\textcolor{comment}{ !< True if domain has an Arctic fold}}
\DoxyCodeLine{972 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(0:size(m,1)+1,0:size(m,2)+1)} :: mp}
\DoxyCodeLine{973 }
\DoxyCodeLine{974   \textcolor{keywordtype}{integer} :: ni,nj,i,j}
\DoxyCodeLine{975 }
\DoxyCodeLine{976   ni=\textcolor{keyword}{size}(m,1); nj=\textcolor{keyword}{size}(m,2)}
\DoxyCodeLine{977 }
\DoxyCodeLine{978   mp(1:ni,1:nj)=m(:,:)}
\DoxyCodeLine{979 }
\DoxyCodeLine{980   \textcolor{keywordflow}{if} (cyclic\_x) \textcolor{keywordflow}{then}}
\DoxyCodeLine{981     mp(0,1:nj)=m(ni,1:nj)}
\DoxyCodeLine{982     mp(ni+1,1:nj)=m(1,1:nj)}
\DoxyCodeLine{983   \textcolor{keywordflow}{else}}
\DoxyCodeLine{984     mp(0,1:nj)=m(1,1:nj)}
\DoxyCodeLine{985     mp(ni+1,1:nj)=m(ni,1:nj)}
\DoxyCodeLine{986 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{987 }
\DoxyCodeLine{988   mp(1:ni,0)=m(1:ni,1)}
\DoxyCodeLine{989   \textcolor{keywordflow}{if} (tripolar\_n) \textcolor{keywordflow}{then}}
\DoxyCodeLine{990     \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{991       mp(i,nj+1)=m(ni-\/i+1,nj)}
\DoxyCodeLine{992 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{993   \textcolor{keywordflow}{else}}
\DoxyCodeLine{994     mp(1:ni,nj+1)=m(1:ni,nj)}
\DoxyCodeLine{995 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in,out}}  & {\em aout} & The array with missing values to fill \\
\hline
\mbox{\texttt{ in}}  & {\em good} & Valid data mask for incoming array \\
\hline
\mbox{\texttt{ in}}  & {\em fill} & Same shape array of points which need \\
\hline
\mbox{\texttt{ in}}  & {\em prev} & First guess where isolated holes exist. \\
\hline
\mbox{\texttt{ in}}  & {\em smooth} & If present and true, apply a number of Laplacian iterations to the interpolated data \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+pass} & The maximum number of iterations \\
\hline
\mbox{\texttt{ in}}  & {\em relc} & A relaxation coefficient for Laplacian (ND) \\
\hline
\mbox{\texttt{ in}}  & {\em crit} & A minimal value for deltas between iterations. \\
\hline
\mbox{\texttt{ in}}  & {\em debug} & If true, write verbose debugging messages. \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{105   \textcolor{keywordtype}{use }\mbox{\hyperlink{namespacemom__coms}{mom\_coms}}, \textcolor{keywordtype}{only} : sum\_across\_pes}
\DoxyCodeLine{106 }
\DoxyCodeLine{107   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{108 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{109                          \textcolor{keywordtype}{intent(inout)} :: aout\textcolor{comment}{ !< The array with missing values to fill}}
\DoxyCodeLine{110 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{111                          \textcolor{keywordtype}{intent(in)}    :: good\textcolor{comment}{ !< Valid data mask for incoming array}}
\DoxyCodeLine{112 \textcolor{comment}{                                               !! (1==good data; 0==missing data).}}
\DoxyCodeLine{113 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{114                          \textcolor{keywordtype}{intent(in)}    :: fill\textcolor{comment}{ !< Same shape array of points which need}}
\DoxyCodeLine{115 \textcolor{comment}{                                               !! filling (1==fill;0==dont fill)}}
\DoxyCodeLine{116 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{117                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: prev\textcolor{comment}{ !< First guess where isolated holes exist.}}
\DoxyCodeLine{118   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: smooth\textcolor{comment}{ !< If present and true, apply a number of}}
\DoxyCodeLine{119 \textcolor{comment}{                                                 !! Laplacian iterations to the interpolated data}}
\DoxyCodeLine{120   \textcolor{keywordtype}{integer},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: num\_pass\textcolor{comment}{ !< The maximum number of iterations}}
\DoxyCodeLine{121 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: relc\textcolor{comment}{ !< A relaxation coefficient for Laplacian (ND)}}
\DoxyCodeLine{122 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: crit\textcolor{comment}{ !< A minimal value for deltas between iterations.}}
\DoxyCodeLine{123   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: debug\textcolor{comment}{ !< If true, write verbose debugging messages.}}
\DoxyCodeLine{124   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use expressions that give the same}}
\DoxyCodeLine{125 \textcolor{comment}{                                                !! answers as the code did in late 2018.  Otherwise}}
\DoxyCodeLine{126 \textcolor{comment}{                                                !! add parentheses for rotational symmetry.}}
\DoxyCodeLine{127 }
\DoxyCodeLine{128 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: b,r}
\DoxyCodeLine{129 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: fill\_pts, good\_, good\_new}
\DoxyCodeLine{130 }
\DoxyCodeLine{131   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{132   \textcolor{keywordtype}{integer} :: i,j,k}
\DoxyCodeLine{133 \textcolor{keywordtype}{  real}    :: east,west,north,south,sor}
\DoxyCodeLine{134 \textcolor{keywordtype}{  real}    :: ge,gw,gn,gs,ngood}
\DoxyCodeLine{135   \textcolor{keywordtype}{logical} :: do\_smooth,siena\_bug}
\DoxyCodeLine{136 \textcolor{keywordtype}{  real}    :: nfill, nfill\_prev}
\DoxyCodeLine{137   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: num\_pass\_default = 10000}
\DoxyCodeLine{138 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: relc\_default = 0.25, crit\_default = 1.e-\/3}
\DoxyCodeLine{139 }
\DoxyCodeLine{140   \textcolor{keywordtype}{integer} :: npass}
\DoxyCodeLine{141   \textcolor{keywordtype}{integer} :: is, ie, js, je}
\DoxyCodeLine{142 \textcolor{keywordtype}{  real}    :: relax\_coeff, acrit, ares}
\DoxyCodeLine{143   \textcolor{keywordtype}{logical} :: debug\_it, ans\_2018}
\DoxyCodeLine{144 }
\DoxyCodeLine{145   debug\_it=.false.}
\DoxyCodeLine{146   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(debug)) debug\_it=debug}
\DoxyCodeLine{147 }
\DoxyCodeLine{148   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{149 }
\DoxyCodeLine{150   npass = num\_pass\_default}
\DoxyCodeLine{151   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(num\_pass)) npass = num\_pass}
\DoxyCodeLine{152 }
\DoxyCodeLine{153   relax\_coeff = relc\_default}
\DoxyCodeLine{154   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(relc)) relax\_coeff = relc}
\DoxyCodeLine{155 }
\DoxyCodeLine{156   acrit = crit\_default}
\DoxyCodeLine{157   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(crit)) acrit = crit}
\DoxyCodeLine{158 }
\DoxyCodeLine{159   do\_smooth=.false.}
\DoxyCodeLine{160   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(smooth)) do\_smooth=smooth}
\DoxyCodeLine{161 }
\DoxyCodeLine{162   ans\_2018 = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(answers\_2018)) ans\_2018 = answers\_2018}
\DoxyCodeLine{163 }
\DoxyCodeLine{164   fill\_pts(:,:) = fill(:,:)}
\DoxyCodeLine{165 }
\DoxyCodeLine{166   nfill = sum(fill(is:ie,js:je))}
\DoxyCodeLine{167   \textcolor{keyword}{call }sum\_across\_pes(nfill)}
\DoxyCodeLine{168 }
\DoxyCodeLine{169   nfill\_prev = nfill}
\DoxyCodeLine{170   good\_(:,:) = good(:,:)}
\DoxyCodeLine{171   r(:,:) = 0.0}
\DoxyCodeLine{172 }
\DoxyCodeLine{173   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (nfill > 0.0)}
\DoxyCodeLine{174 }
\DoxyCodeLine{175     \textcolor{keyword}{call }pass\_var(good\_,g\%Domain)}
\DoxyCodeLine{176     \textcolor{keyword}{call }pass\_var(aout,g\%Domain)}
\DoxyCodeLine{177 }
\DoxyCodeLine{178     b(:,:)=aout(:,:)}
\DoxyCodeLine{179     good\_new(:,:)=good\_(:,:)}
\DoxyCodeLine{180 }
\DoxyCodeLine{181     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{182 }
\DoxyCodeLine{183       \textcolor{keywordflow}{if} (good\_(i,j) == 1.0 .or. fill(i,j) == 0.) cycle}
\DoxyCodeLine{184 }
\DoxyCodeLine{185       ge=good\_(i+1,j) ; gw=good\_(i-\/1,j)}
\DoxyCodeLine{186       gn=good\_(i,j+1) ; gs=good\_(i,j-\/1)}
\DoxyCodeLine{187       east=0.0 ; west=0.0 ; north=0.0 ; south=0.0}
\DoxyCodeLine{188       \textcolor{keywordflow}{if} (ge == 1.0) east = aout(i+1,j)*ge}
\DoxyCodeLine{189       \textcolor{keywordflow}{if} (gw == 1.0) west = aout(i-\/1,j)*gw}
\DoxyCodeLine{190       \textcolor{keywordflow}{if} (gn == 1.0) north = aout(i,j+1)*gn}
\DoxyCodeLine{191       \textcolor{keywordflow}{if} (gs == 1.0) south = aout(i,j-\/1)*gs}
\DoxyCodeLine{192 }
\DoxyCodeLine{193       \textcolor{keywordflow}{if} (ans\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{194         ngood = ge+gw+gn+gs}
\DoxyCodeLine{195       \textcolor{keywordflow}{else}}
\DoxyCodeLine{196         ngood = (ge+gw) + (gn+gs)}
\DoxyCodeLine{197 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{198       \textcolor{keywordflow}{if} (ngood > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{199         \textcolor{keywordflow}{if} (ans\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{200           b(i,j)=(east+west+north+south)/ngood}
\DoxyCodeLine{201         \textcolor{keywordflow}{else}}
\DoxyCodeLine{202           b(i,j) = ((east+west) + (north+south))/ngood}
\DoxyCodeLine{203 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{204         fill\_pts(i,j) = 0.0}
\DoxyCodeLine{205         good\_new(i,j) = 1.0}
\DoxyCodeLine{206 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{207 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{208 }
\DoxyCodeLine{209     aout(is:ie,js:je) = b(is:ie,js:je)}
\DoxyCodeLine{210     good\_(is:ie,js:je) = good\_new(is:ie,js:je)}
\DoxyCodeLine{211     nfill\_prev = nfill}
\DoxyCodeLine{212     nfill = sum(fill\_pts(is:ie,js:je))}
\DoxyCodeLine{213     \textcolor{keyword}{call }sum\_across\_pes(nfill)}
\DoxyCodeLine{214 }
\DoxyCodeLine{215     \textcolor{keywordflow}{if} (nfill == nfill\_prev .and. \textcolor{keyword}{PRESENT}(prev)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{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}}
\DoxyCodeLine{217         aout(i,j) = prev(i,j)}
\DoxyCodeLine{218         fill\_pts(i,j) = 0.0}
\DoxyCodeLine{219 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{220     \textcolor{keywordflow}{elseif} (nfill == nfill\_prev) \textcolor{keywordflow}{then}}
\DoxyCodeLine{221       \textcolor{keyword}{call }mom\_error(warning, \&}
\DoxyCodeLine{222            \textcolor{stringliteral}{'Unable to fill missing points using either data at the same vertical level from a connected basin'}//\&}
\DoxyCodeLine{223            \textcolor{stringliteral}{'or using a point from a previous vertical level.  Make sure that the original data has some valid'}//\&}
\DoxyCodeLine{224            \textcolor{stringliteral}{'data in all basins.'}, .true.)}
\DoxyCodeLine{225       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'nfill='},nfill}
\DoxyCodeLine{226       \textcolor{keyword}{call }mom\_error(warning, mesg, .true.)}
\DoxyCodeLine{227 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{228 }
\DoxyCodeLine{229     nfill = sum(fill\_pts(is:ie,js:je))}
\DoxyCodeLine{230     \textcolor{keyword}{call }sum\_across\_pes(nfill)}
\DoxyCodeLine{231 }
\DoxyCodeLine{232 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{233 }
\DoxyCodeLine{234   \textcolor{keywordflow}{if} (do\_smooth) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,npass}
\DoxyCodeLine{235     \textcolor{keyword}{call }pass\_var(aout,g\%Domain)}
\DoxyCodeLine{236     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{237       \textcolor{keywordflow}{if} (fill(i,j) == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{238         east = max(good(i+1,j),fill(i+1,j)) ; west = max(good(i-\/1,j),fill(i-\/1,j))}
\DoxyCodeLine{239         north = max(good(i,j+1),fill(i,j+1)) ; south = max(good(i,j-\/1),fill(i,j-\/1))}
\DoxyCodeLine{240         \textcolor{keywordflow}{if} (ans\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{241           r(i,j) = relax\_coeff*(south*aout(i,j-\/1)+north*aout(i,j+1) + \&}
\DoxyCodeLine{242                                 west*aout(i-\/1,j)+east*aout(i+1,j) -\/ \&}
\DoxyCodeLine{243                                (south+north+west+east)*aout(i,j))}
\DoxyCodeLine{244         \textcolor{keywordflow}{else}}
\DoxyCodeLine{245           r(i,j) = relax\_coeff*( ((south*aout(i,j-\/1) + north*aout(i,j+1)) + \&}
\DoxyCodeLine{246                                   (west*aout(i-\/1,j)+east*aout(i+1,j))) -\/ \&}
\DoxyCodeLine{247                                  ((south+north)+(west+east))*aout(i,j) )}
\DoxyCodeLine{248 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{249       \textcolor{keywordflow}{else}}
\DoxyCodeLine{250         r(i,j) = 0.}
\DoxyCodeLine{251 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{252 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{253     ares = 0.0}
\DoxyCodeLine{254     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{255       aout(i,j) = r(i,j) + aout(i,j)}
\DoxyCodeLine{256       ares = max(ares, abs(r(i,j)))}
\DoxyCodeLine{257 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{258     \textcolor{keyword}{call }max\_across\_pes(ares)}
\DoxyCodeLine{259     \textcolor{keywordflow}{if} (ares <= acrit) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{260 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{261 }
\DoxyCodeLine{262   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{263     \textcolor{keywordflow}{if} (good\_(i,j) == 0.0 .and. fill\_pts(i,j) == 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{264       \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'In fill\_miss, fill, good,i,j= '},fill\_pts(i,j),good\_(i,j),i,j}
\DoxyCodeLine{265       \textcolor{keyword}{call }mom\_error(warning, mesg, .true.)}
\DoxyCodeLine{266       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM\_initialize: "}// \&}
\DoxyCodeLine{267            \textcolor{stringliteral}{"fill is true and good is false after fill\_miss, how did this happen? "})}
\DoxyCodeLine{268 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{269 \textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em fms\+\_\+id} & A unique id used by the F\+MS time interpolator \\
\hline
\mbox{\texttt{ in}}  & {\em time} & A F\+MS time type \\
\hline
\mbox{\texttt{ in}}  & {\em conversion} & Conversion factor for tracer. \\
\hline
\mbox{\texttt{ 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{\texttt{ out}}  & {\em missing\+\_\+value} & The missing value in the returned array. \\
\hline
\mbox{\texttt{ in}}  & {\em reentrant\+\_\+x} & If true, this grid is reentrant in the x-\/direction \\
\hline
\mbox{\texttt{ in}}  & {\em tripolar\+\_\+n} & If true, this is a northern tripolar grid \\
\hline
\mbox{\texttt{ in}}  & {\em homogenize} & If present and true, horizontally homogenize data to produce perfectly \char`\"{}flat\char`\"{} initial conditions \\
\hline
\mbox{\texttt{ in}}  & {\em spongeongrid} & If present and true, the sponge data are on the model grid \\
\hline
\mbox{\texttt{ in}}  & {\em m\+\_\+to\+\_\+z} & A conversion factor from meters to the units of depth. If missing, GbathyT must be in m. \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{636 }
\DoxyCodeLine{637   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: fms\_id\textcolor{comment}{     !< A unique id used by the FMS time interpolator}}
\DoxyCodeLine{638   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< A FMS time type}}
\DoxyCodeLine{639 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: conversion\textcolor{comment}{ !< Conversion factor for tracer.}}
\DoxyCodeLine{640   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< Grid object}}
\DoxyCodeLine{641 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: tr\_z\textcolor{comment}{       !< pointer to allocatable tracer array on local}}
\DoxyCodeLine{642 \textcolor{comment}{                                                     !! model grid and native vertical levels.}}
\DoxyCodeLine{643 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: mask\_z\textcolor{comment}{     !< pointer to allocatable tracer mask array on}}
\DoxyCodeLine{644 \textcolor{comment}{                                                     !! local model grid and native vertical levels.}}
\DoxyCodeLine{645 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_in\textcolor{comment}{       !< Cell grid values for input data.}}
\DoxyCodeLine{646 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_edges\_in\textcolor{comment}{ !< Cell grid edge values for input data. (Intent out)}}
\DoxyCodeLine{647 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)}   :: missing\_value\textcolor{comment}{ !< The missing value in the returned array.}}
\DoxyCodeLine{648   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: reentrant\_x\textcolor{comment}{ !< If true, this grid is reentrant in the x-\/direction}}
\DoxyCodeLine{649   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: tripolar\_n\textcolor{comment}{ !< If true, this is a northern tripolar grid}}
\DoxyCodeLine{650   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: homogenize\textcolor{comment}{ !< If present and true, horizontally homogenize data}}
\DoxyCodeLine{651 \textcolor{comment}{                                                     !! to produce perfectly "flat" initial conditions}}
\DoxyCodeLine{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}}
\DoxyCodeLine{653 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: m\_to\_Z\textcolor{comment}{     !< A conversion factor from meters to the units}}
\DoxyCodeLine{654 \textcolor{comment}{                                                     !! of depth.  If missing, G\%bathyT must be in m.}}
\DoxyCodeLine{655   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use expressions that give the same}}
\DoxyCodeLine{656 \textcolor{comment}{                                                     !! answers as the code did in late 2018.  Otherwise}}
\DoxyCodeLine{657 \textcolor{comment}{                                                     !! add parentheses for rotational symmetry.}}
\DoxyCodeLine{658 }
\DoxyCodeLine{659   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{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}}
\DoxyCodeLine{661 \textcolor{comment}{                                                     !! native horizontal grid and extended grid}}
\DoxyCodeLine{662 \textcolor{comment}{                                                     !! with poles.}}
\DoxyCodeLine{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}}
\DoxyCodeLine{664 \textcolor{comment}{                                                     !! on the original grid}}
\DoxyCodeLine{665 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},  \textcolor{keywordtype}{allocatable}   :: mask\_in\textcolor{comment}{    !< A 2-\/d mask for extended input grid.}}
\DoxyCodeLine{666 }
\DoxyCodeLine{667 \textcolor{keywordtype}{  real} :: PI\_180}
\DoxyCodeLine{668   \textcolor{keywordtype}{integer} :: rcode, ncid, varid, ndims, id, jd, kd, jdp}
\DoxyCodeLine{669   \textcolor{keywordtype}{integer} :: i,j,k}
\DoxyCodeLine{670   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: start, count, dims, dim\_id}
\DoxyCodeLine{671 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: x\_in, y\_in}
\DoxyCodeLine{672 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lon\_in, lat\_in}
\DoxyCodeLine{673 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lat\_inp, last\_row}
\DoxyCodeLine{674 \textcolor{keywordtype}{  real} :: max\_lat, min\_lat, pole, max\_depth, npole}
\DoxyCodeLine{675 \textcolor{keywordtype}{  real} :: roundoff  \textcolor{comment}{! The magnitude of roundoff, usually ~2e-\/16.}}
\DoxyCodeLine{676   \textcolor{keywordtype}{logical} :: add\_np}
\DoxyCodeLine{677   \textcolor{keywordtype}{character(len=8)}  :: laynum}
\DoxyCodeLine{678   \textcolor{keywordtype}{type}(horiz\_interp\_type) :: Interp}
\DoxyCodeLine{679   \textcolor{keywordtype}{type}(axistype), \textcolor{keywordtype}{dimension(4)} :: axes\_data}
\DoxyCodeLine{680   \textcolor{keywordtype}{integer} :: is, ie, js, je     \textcolor{comment}{! compute domain indices}}
\DoxyCodeLine{681   \textcolor{keywordtype}{integer} :: isc,iec,jsc,jec    \textcolor{comment}{! global compute domain indices}}
\DoxyCodeLine{682   \textcolor{keywordtype}{integer} :: isg, ieg, jsg, jeg \textcolor{comment}{! global extent}}
\DoxyCodeLine{683   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed \textcolor{comment}{! data domain indices}}
\DoxyCodeLine{684   \textcolor{keywordtype}{integer} :: id\_clock\_read}
\DoxyCodeLine{685   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: fld\_sz}
\DoxyCodeLine{686   \textcolor{keywordtype}{character(len=12)}  :: dim\_name(4)}
\DoxyCodeLine{687   \textcolor{keywordtype}{logical} :: debug=.false.}
\DoxyCodeLine{688   \textcolor{keywordtype}{logical} :: spongeDataOngrid}
\DoxyCodeLine{689 \textcolor{keywordtype}{  real} :: npoints,varAvg}
\DoxyCodeLine{690 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: lon\_out, lat\_out, tr\_out, mask\_out}
\DoxyCodeLine{691 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: good, fill}
\DoxyCodeLine{692 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: tr\_outf,tr\_prev}
\DoxyCodeLine{693 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: good2,fill2}
\DoxyCodeLine{694 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: nlevs}
\DoxyCodeLine{695   \textcolor{keywordtype}{integer} :: turns}
\DoxyCodeLine{696 }
\DoxyCodeLine{697   turns = g\%HI\%turns}
\DoxyCodeLine{698 }
\DoxyCodeLine{699   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{700   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{701   isg = g\%isg ; ieg = g\%ieg ; jsg = g\%jsg ; jeg = g\%jeg}
\DoxyCodeLine{702 }
\DoxyCodeLine{703   id\_clock\_read = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize tracer from Z) read'}, grain=clock\_loop)}
\DoxyCodeLine{704 }
\DoxyCodeLine{705   pi\_180=atan(1.0)/45.}
\DoxyCodeLine{706 }
\DoxyCodeLine{707   \textcolor{comment}{! Open NetCDF file and if present, extract data and spatial coordinate information}}
\DoxyCodeLine{708   \textcolor{comment}{! The convention adopted here requires that the data be written in (i,j,k) ordering.}}
\DoxyCodeLine{709 }
\DoxyCodeLine{710   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_read)}
\DoxyCodeLine{711 }
\DoxyCodeLine{712   fld\_sz = get\_external\_field\_size(fms\_id)}
\DoxyCodeLine{713   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lon\_in)) \textcolor{keyword}{deallocate}(lon\_in)}
\DoxyCodeLine{714   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lat\_in)) \textcolor{keyword}{deallocate}(lat\_in)}
\DoxyCodeLine{715   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_in)) \textcolor{keyword}{deallocate}(z\_in)}
\DoxyCodeLine{716   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_edges\_in)) \textcolor{keyword}{deallocate}(z\_edges\_in)}
\DoxyCodeLine{717   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(tr\_z)) \textcolor{keyword}{deallocate}(tr\_z)}
\DoxyCodeLine{718   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(mask\_z)) \textcolor{keyword}{deallocate}(mask\_z)}
\DoxyCodeLine{719 }
\DoxyCodeLine{720   axes\_data =  get\_external\_field\_axes(fms\_id)}
\DoxyCodeLine{721 }
\DoxyCodeLine{722   id = fld\_sz(1) ; jd  = fld\_sz(2) ; kd = fld\_sz(3)}
\DoxyCodeLine{723 }
\DoxyCodeLine{724   spongedataongrid=.false.}
\DoxyCodeLine{725   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(spongeongrid)) spongedataongrid=spongeongrid}
\DoxyCodeLine{726   \textcolor{keywordflow}{if} (.not. spongedataongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{727     \textcolor{keyword}{allocate}(lon\_in(id),lat\_in(jd))}
\DoxyCodeLine{728     \textcolor{keyword}{call }mpp\_get\_axis\_data(axes\_data(1), lon\_in)}
\DoxyCodeLine{729     \textcolor{keyword}{call }mpp\_get\_axis\_data(axes\_data(2), lat\_in)}
\DoxyCodeLine{730 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{731 }
\DoxyCodeLine{732   \textcolor{keyword}{allocate}(z\_in(kd),z\_edges\_in(kd+1))}
\DoxyCodeLine{733 }
\DoxyCodeLine{734   \textcolor{keyword}{allocate}(tr\_z(isd:ied,jsd:jed,kd), mask\_z(isd:ied,jsd:jed,kd))}
\DoxyCodeLine{735 }
\DoxyCodeLine{736   \textcolor{keyword}{call }mpp\_get\_axis\_data(axes\_data(3), z\_in)}
\DoxyCodeLine{737 }
\DoxyCodeLine{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}}
\DoxyCodeLine{739 }
\DoxyCodeLine{740   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_read)}
\DoxyCodeLine{741 }
\DoxyCodeLine{742   missing\_value = get\_external\_field\_missing(fms\_id)}
\DoxyCodeLine{743 }
\DoxyCodeLine{744   \textcolor{keywordflow}{if} (.not. spongedataongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{745     \textcolor{comment}{! extrapolate the input data to the north pole using the northerm-\/most latitude}}
\DoxyCodeLine{746     max\_lat = maxval(lat\_in)}
\DoxyCodeLine{747     add\_np=.false.}
\DoxyCodeLine{748     \textcolor{keywordflow}{if} (max\_lat < 90.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{749       add\_np = .true.}
\DoxyCodeLine{750       jdp = jd+1}
\DoxyCodeLine{751       \textcolor{keyword}{allocate}(lat\_inp(jdp))}
\DoxyCodeLine{752       lat\_inp(1:jd) = lat\_in(:)}
\DoxyCodeLine{753       lat\_inp(jd+1) = 90.0}
\DoxyCodeLine{754       \textcolor{keyword}{deallocate}(lat\_in)}
\DoxyCodeLine{755       \textcolor{keyword}{allocate}(lat\_in(1:jdp))}
\DoxyCodeLine{756       lat\_in(:) = lat\_inp(:)}
\DoxyCodeLine{757     \textcolor{keywordflow}{else}}
\DoxyCodeLine{758       jdp=jd}
\DoxyCodeLine{759 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{760     \textcolor{keyword}{call }horiz\_interp\_init()}
\DoxyCodeLine{761     lon\_in = lon\_in*pi\_180}
\DoxyCodeLine{762     lat\_in = lat\_in*pi\_180}
\DoxyCodeLine{763     \textcolor{keyword}{allocate}(x\_in(id,jdp), y\_in(id,jdp))}
\DoxyCodeLine{764     \textcolor{keyword}{call }meshgrid(lon\_in, lat\_in, x\_in, y\_in)}
\DoxyCodeLine{765     lon\_out(:,:) = g\%geoLonT(:,:)*pi\_180}
\DoxyCodeLine{766     lat\_out(:,:) = g\%geoLatT(:,:)*pi\_180}
\DoxyCodeLine{767     \textcolor{keyword}{allocate}(data\_in(id,jd,kd)) ; data\_in(:,:,:)=0.0}
\DoxyCodeLine{768     \textcolor{keyword}{allocate}(tr\_in(id,jd)) ; tr\_in(:,:)=0.0}
\DoxyCodeLine{769     \textcolor{keyword}{allocate}(tr\_inp(id,jdp)) ; tr\_inp(:,:)=0.0}
\DoxyCodeLine{770     \textcolor{keyword}{allocate}(mask\_in(id,jdp)) ; mask\_in(:,:)=0.0}
\DoxyCodeLine{771     \textcolor{keyword}{allocate}(last\_row(id))    ; last\_row(:)=0.0}
\DoxyCodeLine{772   \textcolor{keywordflow}{else}}
\DoxyCodeLine{773     \textcolor{keyword}{allocate}(data\_in(isd:ied,jsd:jed,kd))}
\DoxyCodeLine{774 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{775   \textcolor{comment}{! construct level cell boundaries as the mid-\/point between adjacent centers}}
\DoxyCodeLine{776   z\_edges\_in(1) = 0.0}
\DoxyCodeLine{777   \textcolor{keywordflow}{do} k=2,kd}
\DoxyCodeLine{778     z\_edges\_in(k) = 0.5*(z\_in(k-\/1)+z\_in(k))}
\DoxyCodeLine{779 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{780   z\_edges\_in(kd+1) = 2.0*z\_in(kd) -\/ z\_in(kd-\/1)}
\DoxyCodeLine{781 }
\DoxyCodeLine{782 }
\DoxyCodeLine{783   max\_depth = maxval(g\%bathyT)}
\DoxyCodeLine{784   \textcolor{keyword}{call }mpp\_max(max\_depth)}
\DoxyCodeLine{785 }
\DoxyCodeLine{786   \textcolor{keywordflow}{if} (z\_edges\_in(kd+1)<max\_depth) z\_edges\_in(kd+1)=max\_depth}
\DoxyCodeLine{787 }
\DoxyCodeLine{788   \textcolor{comment}{!  roundoff = 3.0*EPSILON(missing\_value)}}
\DoxyCodeLine{789   roundoff = 1.e-\/4}
\DoxyCodeLine{790 }
\DoxyCodeLine{791   \textcolor{keywordflow}{if} (.not.spongedataongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{792     \textcolor{keywordflow}{if} (is\_root\_pe()) \&}
\DoxyCodeLine{793       \textcolor{keyword}{call }time\_interp\_external(fms\_id, time, data\_in, verbose=.true., turns=turns)}
\DoxyCodeLine{794     \textcolor{comment}{! loop through each data level and interpolate to model grid.}}
\DoxyCodeLine{795     \textcolor{comment}{! after interpolating, fill in points which will be needed}}
\DoxyCodeLine{796     \textcolor{comment}{! to define the layers}}
\DoxyCodeLine{797     \textcolor{keywordflow}{do} k=1,kd}
\DoxyCodeLine{798       \textcolor{keyword}{write}(laynum,\textcolor{stringliteral}{'(I8)'}) k ; laynum = adjustl(laynum)}
\DoxyCodeLine{799       \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}}
\DoxyCodeLine{800         tr\_in(1:id,1:jd) = data\_in(1:id,1:jd,k)}
\DoxyCodeLine{801         \textcolor{keywordflow}{if} (add\_np) \textcolor{keywordflow}{then}}
\DoxyCodeLine{802          last\_row(:)=tr\_in(:,jd); pole=0.0;npole=0.0}
\DoxyCodeLine{803          \textcolor{keywordflow}{do} i=1,id}
\DoxyCodeLine{804            \textcolor{keywordflow}{if} (abs(tr\_in(i,jd)-\/missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{805              pole = pole+last\_row(i)}
\DoxyCodeLine{806              npole = npole+1.0}
\DoxyCodeLine{807 \textcolor{keywordflow}{           endif}}
\DoxyCodeLine{808 \textcolor{keywordflow}{         enddo}}
\DoxyCodeLine{809          \textcolor{keywordflow}{if} (npole > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{810            pole=pole/npole}
\DoxyCodeLine{811          \textcolor{keywordflow}{else}}
\DoxyCodeLine{812            pole=missing\_value}
\DoxyCodeLine{813 \textcolor{keywordflow}{         endif}}
\DoxyCodeLine{814          tr\_inp(:,1:jd) = tr\_in(:,:)}
\DoxyCodeLine{815          tr\_inp(:,jdp) = pole}
\DoxyCodeLine{816         \textcolor{keywordflow}{else}}
\DoxyCodeLine{817          tr\_inp(:,:) = tr\_in(:,:)}
\DoxyCodeLine{818 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{819 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{820 }
\DoxyCodeLine{821       \textcolor{keyword}{call }mpp\_sync()}
\DoxyCodeLine{822       \textcolor{keyword}{call }mpp\_broadcast(tr\_inp, id*jdp, root\_pe())}
\DoxyCodeLine{823       \textcolor{keyword}{call }mpp\_sync\_self()}
\DoxyCodeLine{824 }
\DoxyCodeLine{825       mask\_in=0.0}
\DoxyCodeLine{826 }
\DoxyCodeLine{827       \textcolor{keywordflow}{do} j=1,jdp ; \textcolor{keywordflow}{do} i=1,id}
\DoxyCodeLine{828         \textcolor{keywordflow}{if} (abs(tr\_inp(i,j)-\/missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{829           mask\_in(i,j)=1.0}
\DoxyCodeLine{830           tr\_inp(i,j) = tr\_inp(i,j) * conversion}
\DoxyCodeLine{831         \textcolor{keywordflow}{else}}
\DoxyCodeLine{832           tr\_inp(i,j) = missing\_value}
\DoxyCodeLine{833 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{834 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{835 }
\DoxyCodeLine{836       \textcolor{comment}{! call fms routine horiz\_interp to interpolate input level data to model horizontal grid}}
\DoxyCodeLine{837       \textcolor{keywordflow}{if} (k == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{838         \textcolor{keyword}{call }horiz\_interp\_new(interp, x\_in, y\_in, lon\_out(is:ie,js:je), lat\_out(is:ie,js:je), \&}
\DoxyCodeLine{839                               interp\_method=\textcolor{stringliteral}{'bilinear'}, src\_modulo=.true.)}
\DoxyCodeLine{840 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{841 }
\DoxyCodeLine{842       \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{843         \textcolor{keyword}{call }mystats(tr\_in, missing\_value, 1, id, 1, jd, k, \textcolor{stringliteral}{'Tracer from file'})}
\DoxyCodeLine{844 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{845 }
\DoxyCodeLine{846       tr\_out(:,:) = 0.0}
\DoxyCodeLine{847 }
\DoxyCodeLine{848       \textcolor{keyword}{call }horiz\_interp(interp, tr\_inp, tr\_out(is:ie,js:je), missing\_value=missing\_value, \&}
\DoxyCodeLine{849                         new\_missing\_handle=.true.)}
\DoxyCodeLine{850 }
\DoxyCodeLine{851       mask\_out(:,:) = 1.0}
\DoxyCodeLine{852       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{853         \textcolor{keywordflow}{if} (abs(tr\_out(i,j)-\/missing\_value) < abs(roundoff*missing\_value)) mask\_out(i,j) = 0.}
\DoxyCodeLine{854 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{855 }
\DoxyCodeLine{856       fill(:,:) = 0.0 ; good(:,:) = 0.0}
\DoxyCodeLine{857 }
\DoxyCodeLine{858       npoints = 0 ; varavg = 0.}
\DoxyCodeLine{859       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{860         \textcolor{keywordflow}{if} (mask\_out(i,j) < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{861           tr\_out(i,j) = missing\_value}
\DoxyCodeLine{862         \textcolor{keywordflow}{else}}
\DoxyCodeLine{863           good(i,j) = 1.0}
\DoxyCodeLine{864           npoints = npoints + 1}
\DoxyCodeLine{865           varavg = varavg + tr\_out(i,j)}
\DoxyCodeLine{866 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{867         \textcolor{keywordflow}{if} ((g\%mask2dT(i,j) == 1.0) .and. (z\_edges\_in(k) <= g\%bathyT(i,j)) .and. \&}
\DoxyCodeLine{868             (mask\_out(i,j) < 1.0)) \&}
\DoxyCodeLine{869           fill(i,j)=1.0}
\DoxyCodeLine{870 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{871       \textcolor{keyword}{call }pass\_var(fill, g\%Domain)}
\DoxyCodeLine{872       \textcolor{keyword}{call }pass\_var(good, g\%Domain)}
\DoxyCodeLine{873 }
\DoxyCodeLine{874       \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{875         \textcolor{keyword}{call }mystats(tr\_out, missing\_value, is, ie, js, je, k, \textcolor{stringliteral}{'variable from horiz\_interp()'})}
\DoxyCodeLine{876 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{877 }
\DoxyCodeLine{878       \textcolor{comment}{! Horizontally homogenize data to produce perfectly "flat" initial conditions}}
\DoxyCodeLine{879       \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(homogenize)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (homogenize) \textcolor{keywordflow}{then}}
\DoxyCodeLine{880         \textcolor{keyword}{call }sum\_across\_pes(npoints)}
\DoxyCodeLine{881         \textcolor{keyword}{call }sum\_across\_pes(varavg)}
\DoxyCodeLine{882         \textcolor{keywordflow}{if} (npoints>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{883           varavg = varavg/real(npoints)}
\DoxyCodeLine{884 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{885         tr\_out(:,:) = varavg}
\DoxyCodeLine{886 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{887 }
\DoxyCodeLine{888       \textcolor{comment}{! tr\_out contains input z-\/space data on the model grid with missing values}}
\DoxyCodeLine{889       \textcolor{comment}{! now fill in missing values using "ICE-\/nine" algorithm.}}
\DoxyCodeLine{890       tr\_outf(:,:) = tr\_out(:,:)}
\DoxyCodeLine{891       \textcolor{keywordflow}{if} (k==1) tr\_prev(:,:) = tr\_outf(:,:)}
\DoxyCodeLine{892       good2(:,:) = good(:,:)}
\DoxyCodeLine{893       fill2(:,:) = fill(:,:)}
\DoxyCodeLine{894 }
\DoxyCodeLine{895       \textcolor{keyword}{call }fill\_miss\_2d(tr\_outf, good2, fill2, tr\_prev, g, smooth=.true., answers\_2018=answers\_2018)}
\DoxyCodeLine{896 }
\DoxyCodeLine{897 \textcolor{comment}{!     if (debug) then}}
\DoxyCodeLine{898 \textcolor{comment}{!       call hchksum(tr\_outf, 'field from fill\_miss\_2d ', G\%HI)}}
\DoxyCodeLine{899 \textcolor{comment}{!     endif}}
\DoxyCodeLine{900 }
\DoxyCodeLine{901 \textcolor{comment}{!     call myStats(tr\_outf, missing\_value, is, ie, js, je, k, 'field from fill\_miss\_2d()')}}
\DoxyCodeLine{902 }
\DoxyCodeLine{903       tr\_z(:,:,k) = tr\_outf(:,:)*g\%mask2dT(:,:)}
\DoxyCodeLine{904       mask\_z(:,:,k) = good2(:,:) + fill2(:,:)}
\DoxyCodeLine{905       tr\_prev(:,:) = tr\_z(:,:,k)}
\DoxyCodeLine{906 }
\DoxyCodeLine{907       \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{908         \textcolor{keyword}{call }hchksum(tr\_prev,\textcolor{stringliteral}{'field after fill '},g\%HI)}
\DoxyCodeLine{909 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{910 }
\DoxyCodeLine{911 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! kd}}
\DoxyCodeLine{912   \textcolor{keywordflow}{else}}
\DoxyCodeLine{913       \textcolor{keyword}{call }time\_interp\_external(fms\_id, time, data\_in, verbose=.true., turns=turns)}
\DoxyCodeLine{914       \textcolor{keywordflow}{do} k=1,kd}
\DoxyCodeLine{915         \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{916           \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{917             tr\_z(i,j,k)=data\_in(i,j,k)}
\DoxyCodeLine{918             \textcolor{keywordflow}{if} (abs(tr\_z(i,j,k)-\/missing\_value) < abs(roundoff*missing\_value)) mask\_z(i,j,k) = 0.}
\DoxyCodeLine{919 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{920 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{921 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{922 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em filename} & Path to file containing tracer to be interpolated. \\
\hline
\mbox{\texttt{ in}}  & {\em varnam} & Name of tracer in filee. \\
\hline
\mbox{\texttt{ in}}  & {\em conversion} & Conversion factor for tracer. \\
\hline
\mbox{\texttt{ in}}  & {\em recnum} & Record number of tracer to be read. \\
\hline
\mbox{\texttt{ 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{\texttt{ out}}  & {\em missing\+\_\+value} & The missing value in the returned array. \\
\hline
\mbox{\texttt{ in}}  & {\em reentrant\+\_\+x} & If true, this grid is reentrant in the x-\/direction \\
\hline
\mbox{\texttt{ in}}  & {\em tripolar\+\_\+n} & If true, this is a northern tripolar grid \\
\hline
\mbox{\texttt{ in}}  & {\em homogenize} & If present and true, horizontally homogenize data to produce perfectly \char`\"{}flat\char`\"{} initial conditions \\
\hline
\mbox{\texttt{ in}}  & {\em m\+\_\+to\+\_\+z} & A conversion factor from meters to the units of depth. If missing, GbathyT must be in m. \\
\hline
\mbox{\texttt{ 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{\texttt{ 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}{0}
\DoxyCodeLine{277 }
\DoxyCodeLine{278   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: filename\textcolor{comment}{   !< Path to file containing tracer to be}}
\DoxyCodeLine{279 \textcolor{comment}{                                                     !! interpolated.}}
\DoxyCodeLine{280   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: varnam\textcolor{comment}{     !< Name of tracer in filee.}}
\DoxyCodeLine{281 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: conversion\textcolor{comment}{ !< Conversion factor for tracer.}}
\DoxyCodeLine{282   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: recnum\textcolor{comment}{     !< Record number of tracer to be read.}}
\DoxyCodeLine{283   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< Grid object}}
\DoxyCodeLine{284 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: tr\_z\textcolor{comment}{       !< pointer to allocatable tracer array on local}}
\DoxyCodeLine{285 \textcolor{comment}{                                                     !! model grid and input-\/file vertical levels.}}
\DoxyCodeLine{286 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}  :: mask\_z\textcolor{comment}{     !< pointer to allocatable tracer mask array on}}
\DoxyCodeLine{287 \textcolor{comment}{                                                     !! local model grid and input-\/file vertical levels.}}
\DoxyCodeLine{288 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_in\textcolor{comment}{       !< Cell grid values for input data.}}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable},     \textcolor{keywordtype}{dimension(:)}  :: z\_edges\_in\textcolor{comment}{ !< Cell grid edge values for input data.}}
\DoxyCodeLine{290 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)}   :: missing\_value\textcolor{comment}{ !< The missing value in the returned array.}}
\DoxyCodeLine{291   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: reentrant\_x\textcolor{comment}{ !< If true, this grid is reentrant in the x-\/direction}}
\DoxyCodeLine{292   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: tripolar\_n\textcolor{comment}{ !< If true, this is a northern tripolar grid}}
\DoxyCodeLine{293   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: homogenize\textcolor{comment}{ !< If present and true, horizontally homogenize data}}
\DoxyCodeLine{294 \textcolor{comment}{                                                     !! to produce perfectly "flat" initial conditions}}
\DoxyCodeLine{295 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: m\_to\_Z\textcolor{comment}{     !< A conversion factor from meters to the units}}
\DoxyCodeLine{296 \textcolor{comment}{                                                     !! of depth.  If missing, G\%bathyT must be in m.}}
\DoxyCodeLine{297   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use expressions that give the same}}
\DoxyCodeLine{298 \textcolor{comment}{                                                     !! answers as the code did in late 2018.  Otherwise}}
\DoxyCodeLine{299 \textcolor{comment}{                                                     !! add parentheses for rotational symmetry.}}
\DoxyCodeLine{300   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: ongrid\textcolor{comment}{     !< If true, then data are assumed to have been interpolated}}
\DoxyCodeLine{301 \textcolor{comment}{                                                     !! to the model horizontal grid. In this case, only}}
\DoxyCodeLine{302 \textcolor{comment}{                                                     !! extrapolation is performed by this routine}}
\DoxyCodeLine{303 }
\DoxyCodeLine{304   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{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}}
\DoxyCodeLine{306                                                      \textcolor{comment}{! native horizontal grid and extended grid}}
\DoxyCodeLine{307                                                      \textcolor{comment}{! with poles.}}
\DoxyCodeLine{308 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},  \textcolor{keywordtype}{allocatable}   :: mask\_in    \textcolor{comment}{! A 2-\/d mask for extended input grid.}}
\DoxyCodeLine{309 }
\DoxyCodeLine{310 \textcolor{keywordtype}{  real} :: PI\_180}
\DoxyCodeLine{311   \textcolor{keywordtype}{integer} :: rcode, ncid, varid, ndims, id, jd, kd, jdp}
\DoxyCodeLine{312   \textcolor{keywordtype}{integer} :: i,j,k}
\DoxyCodeLine{313   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: start, count, dims, dim\_id}
\DoxyCodeLine{314 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: x\_in, y\_in}
\DoxyCodeLine{315 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lon\_in, lat\_in}
\DoxyCodeLine{316 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}  :: lat\_inp, last\_row}
\DoxyCodeLine{317 \textcolor{keywordtype}{  real} :: max\_lat, min\_lat, pole, max\_depth, npole}
\DoxyCodeLine{318 \textcolor{keywordtype}{  real} :: roundoff  \textcolor{comment}{! The magnitude of roundoff, usually ~2e-\/16.}}
\DoxyCodeLine{319 \textcolor{keywordtype}{  real} :: add\_offset, scale\_factor}
\DoxyCodeLine{320   \textcolor{keywordtype}{logical} :: add\_np}
\DoxyCodeLine{321   \textcolor{keywordtype}{logical} :: is\_ongrid}
\DoxyCodeLine{322   \textcolor{keywordtype}{character(len=8)}  :: laynum}
\DoxyCodeLine{323   \textcolor{keywordtype}{type}(horiz\_interp\_type) :: Interp}
\DoxyCodeLine{324   \textcolor{keywordtype}{integer} :: is, ie, js, je     \textcolor{comment}{! compute domain indices}}
\DoxyCodeLine{325   \textcolor{keywordtype}{integer} :: isc,iec,jsc,jec    \textcolor{comment}{! global compute domain indices}}
\DoxyCodeLine{326   \textcolor{keywordtype}{integer} :: isg, ieg, jsg, jeg \textcolor{comment}{! global extent}}
\DoxyCodeLine{327   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed \textcolor{comment}{! data domain indices}}
\DoxyCodeLine{328   \textcolor{keywordtype}{integer} :: id\_clock\_read}
\DoxyCodeLine{329   \textcolor{keywordtype}{character(len=12)}  :: dim\_name(4)}
\DoxyCodeLine{330   \textcolor{keywordtype}{logical} :: debug=.false.}
\DoxyCodeLine{331 \textcolor{keywordtype}{  real} :: npoints,varAvg}
\DoxyCodeLine{332 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: lon\_out, lat\_out, tr\_out, mask\_out}
\DoxyCodeLine{333 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: good, fill}
\DoxyCodeLine{334 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: tr\_outf,tr\_prev}
\DoxyCodeLine{335 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: good2,fill2}
\DoxyCodeLine{336 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: nlevs}
\DoxyCodeLine{337 }
\DoxyCodeLine{338   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{339   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{340   isg = g\%isg ; ieg = g\%ieg ; jsg = g\%jsg ; jeg = g\%jeg}
\DoxyCodeLine{341 }
\DoxyCodeLine{342   id\_clock\_read = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize tracer from Z) read'}, grain=clock\_loop)}
\DoxyCodeLine{343 }
\DoxyCodeLine{344   is\_ongrid=.false.}
\DoxyCodeLine{345   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ongrid)) is\_ongrid=ongrid}
\DoxyCodeLine{346 }
\DoxyCodeLine{347   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(tr\_z)) \textcolor{keyword}{deallocate}(tr\_z)}
\DoxyCodeLine{348   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(mask\_z)) \textcolor{keyword}{deallocate}(mask\_z)}
\DoxyCodeLine{349   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_edges\_in)) \textcolor{keyword}{deallocate}(z\_edges\_in)}
\DoxyCodeLine{350 }
\DoxyCodeLine{351   pi\_180=atan(1.0)/45.}
\DoxyCodeLine{352 }
\DoxyCodeLine{353   \textcolor{comment}{! Open NetCDF file and if present, extract data and spatial coordinate information}}
\DoxyCodeLine{354   \textcolor{comment}{! The convention adopted here requires that the data be written in (i,j,k) ordering.}}
\DoxyCodeLine{355 }
\DoxyCodeLine{356   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_read)}
\DoxyCodeLine{357 }
\DoxyCodeLine{358   rcode = nf90\_open(filename, nf90\_nowrite, ncid)}
\DoxyCodeLine{359   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error opening file "}//trim(filename)//\&}
\DoxyCodeLine{360                            \textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{361   rcode = nf90\_inq\_varid(ncid, varnam, varid)}
\DoxyCodeLine{362   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(varnam)//\&}
\DoxyCodeLine{363                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{364 }
\DoxyCodeLine{365   rcode = nf90\_inquire\_variable(ncid, varid, ndims=ndims, dimids=dims)}
\DoxyCodeLine{366   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'error inquiring dimensions hinterp\_extrap'})}
\DoxyCodeLine{367   \textcolor{keywordflow}{if} (ndims < 3) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Variable "}//trim(varnam)//\textcolor{stringliteral}{" in file "}// \&}
\DoxyCodeLine{368               trim(filename)//\textcolor{stringliteral}{" has too few dimensions."})}
\DoxyCodeLine{369 }
\DoxyCodeLine{370   rcode = nf90\_inquire\_dimension(ncid, dims(1), dim\_name(1), len=id)}
\DoxyCodeLine{371   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 1 data for "}// \&}
\DoxyCodeLine{372                 trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{373   rcode = nf90\_inq\_varid(ncid, dim\_name(1), dim\_id(1))}
\DoxyCodeLine{374   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(dim\_name(1))//\&}
\DoxyCodeLine{375                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{376   rcode = nf90\_inquire\_dimension(ncid, dims(2), dim\_name(2), len=jd)}
\DoxyCodeLine{377   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 2 data for "}// \&}
\DoxyCodeLine{378                 trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{379   rcode = nf90\_inq\_varid(ncid, dim\_name(2), dim\_id(2))}
\DoxyCodeLine{380   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(dim\_name(2))//\&}
\DoxyCodeLine{381                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{382   rcode = nf90\_inquire\_dimension(ncid, dims(3), dim\_name(3), len=kd)}
\DoxyCodeLine{383   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 3 data for "}// \&}
\DoxyCodeLine{384                 trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{385   rcode = nf90\_inq\_varid(ncid, dim\_name(3), dim\_id(3))}
\DoxyCodeLine{386   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding variable "}//trim(dim\_name(3))//\&}
\DoxyCodeLine{387                                  \textcolor{stringliteral}{" in file "}//trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{388 }
\DoxyCodeLine{389   missing\_value=0.0}
\DoxyCodeLine{390   rcode = nf90\_get\_att(ncid, varid, \textcolor{stringliteral}{"\_FillValue"}, missing\_value)}
\DoxyCodeLine{391   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error finding missing value for "}//\&}
\DoxyCodeLine{392        trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{393 }
\DoxyCodeLine{394   rcode = nf90\_get\_att(ncid, varid, \textcolor{stringliteral}{"add\_offset"}, add\_offset)}
\DoxyCodeLine{395   \textcolor{keywordflow}{if} (rcode /= 0) add\_offset = 0.0}
\DoxyCodeLine{396 }
\DoxyCodeLine{397   rcode = nf90\_get\_att(ncid, varid, \textcolor{stringliteral}{"scale\_factor"}, scale\_factor)}
\DoxyCodeLine{398   \textcolor{keywordflow}{if} (rcode /= 0) scale\_factor = 1.0}
\DoxyCodeLine{399 }
\DoxyCodeLine{400   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lon\_in)) \textcolor{keyword}{deallocate}(lon\_in)}
\DoxyCodeLine{401   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(lat\_in)) \textcolor{keyword}{deallocate}(lat\_in)}
\DoxyCodeLine{402   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_in)) \textcolor{keyword}{deallocate}(z\_in)}
\DoxyCodeLine{403   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(z\_edges\_in)) \textcolor{keyword}{deallocate}(z\_edges\_in)}
\DoxyCodeLine{404   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(tr\_z)) \textcolor{keyword}{deallocate}(tr\_z)}
\DoxyCodeLine{405   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(mask\_z)) \textcolor{keyword}{deallocate}(mask\_z)}
\DoxyCodeLine{406 }
\DoxyCodeLine{407   \textcolor{keyword}{allocate}(lon\_in(id),lat\_in(jd),z\_in(kd),z\_edges\_in(kd+1))}
\DoxyCodeLine{408   \textcolor{keyword}{allocate}(tr\_z(isd:ied,jsd:jed,kd), mask\_z(isd:ied,jsd:jed,kd))}
\DoxyCodeLine{409 }
\DoxyCodeLine{410   start = 1; count = 1; count(1) = id}
\DoxyCodeLine{411   rcode = nf90\_get\_var(ncid, dim\_id(1), lon\_in, start, count)}
\DoxyCodeLine{412   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 1 values for var\_name "}// \&}
\DoxyCodeLine{413                 trim(varnam)//\textcolor{stringliteral}{",dim\_name "}//trim(dim\_name(1))//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in hinterp\_extrap"})}
\DoxyCodeLine{414   start = 1; count = 1; count(1) = jd}
\DoxyCodeLine{415   rcode = nf90\_get\_var(ncid, dim\_id(2), lat\_in, start, count)}
\DoxyCodeLine{416   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 2 values for var\_name "}// \&}
\DoxyCodeLine{417                 trim(varnam)//\textcolor{stringliteral}{",dim\_name "}//trim(dim\_name(2))//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in  hinterp\_extrap"})}
\DoxyCodeLine{418   start = 1; count = 1; count(1) = kd}
\DoxyCodeLine{419   rcode = nf90\_get\_var(ncid, dim\_id(3), z\_in, start, count)}
\DoxyCodeLine{420   \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"error reading dimension 3 values for var\_name "}// \&}
\DoxyCodeLine{421                 trim(varnam//\textcolor{stringliteral}{",dim\_name "}//trim(dim\_name(3)))//\textcolor{stringliteral}{" in file "}// trim(filename)//\textcolor{stringliteral}{" in  hinterp\_extrap"})}
\DoxyCodeLine{422 }
\DoxyCodeLine{423   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_read)}
\DoxyCodeLine{424 }
\DoxyCodeLine{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}}
\DoxyCodeLine{426 }
\DoxyCodeLine{427   \textcolor{comment}{! extrapolate the input data to the north pole using the northerm-\/most latitude}}
\DoxyCodeLine{428   add\_np=.false.}
\DoxyCodeLine{429   jdp=jd}
\DoxyCodeLine{430   \textcolor{keywordflow}{if} (.not. is\_ongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{431      max\_lat = maxval(lat\_in)}
\DoxyCodeLine{432      \textcolor{keywordflow}{if} (max\_lat < 90.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{433         add\_np=.true.}
\DoxyCodeLine{434         jdp=jd+1}
\DoxyCodeLine{435         \textcolor{keyword}{allocate}(lat\_inp(jdp))}
\DoxyCodeLine{436         lat\_inp(1:jd)=lat\_in(:)}
\DoxyCodeLine{437         lat\_inp(jd+1)=90.0}
\DoxyCodeLine{438         \textcolor{keyword}{deallocate}(lat\_in)}
\DoxyCodeLine{439         \textcolor{keyword}{allocate}(lat\_in(1:jdp))}
\DoxyCodeLine{440         lat\_in(:)=lat\_inp(:)}
\DoxyCodeLine{441 \textcolor{keywordflow}{     endif}}
\DoxyCodeLine{442 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{443   \textcolor{comment}{! construct level cell boundaries as the mid-\/point between adjacent centers}}
\DoxyCodeLine{444 }
\DoxyCodeLine{445   z\_edges\_in(1) = 0.0}
\DoxyCodeLine{446   \textcolor{keywordflow}{do} k=2,kd}
\DoxyCodeLine{447     z\_edges\_in(k)=0.5*(z\_in(k-\/1)+z\_in(k))}
\DoxyCodeLine{448 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{449   z\_edges\_in(kd+1)=2.0*z\_in(kd) -\/ z\_in(kd-\/1)}
\DoxyCodeLine{450 }
\DoxyCodeLine{451   \textcolor{keywordflow}{if} (is\_ongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{452      \textcolor{keyword}{allocate}(tr\_in(is:ie,js:je)) ; tr\_in(:,:)=0.0}
\DoxyCodeLine{453      \textcolor{keyword}{allocate}(mask\_in(is:ie,js:je)) ; mask\_in(:,:)=0.0}
\DoxyCodeLine{454   \textcolor{keywordflow}{else}}
\DoxyCodeLine{455      \textcolor{keyword}{call }horiz\_interp\_init()}
\DoxyCodeLine{456      lon\_in = lon\_in*pi\_180}
\DoxyCodeLine{457      lat\_in = lat\_in*pi\_180}
\DoxyCodeLine{458      \textcolor{keyword}{allocate}(x\_in(id,jdp),y\_in(id,jdp))}
\DoxyCodeLine{459      \textcolor{keyword}{call }meshgrid(lon\_in,lat\_in, x\_in, y\_in)}
\DoxyCodeLine{460      lon\_out(:,:) = g\%geoLonT(:,:)*pi\_180}
\DoxyCodeLine{461      lat\_out(:,:) = g\%geoLatT(:,:)*pi\_180}
\DoxyCodeLine{462      \textcolor{keyword}{allocate}(tr\_in(id,jd)) ; tr\_in(:,:)=0.0}
\DoxyCodeLine{463      \textcolor{keyword}{allocate}(tr\_inp(id,jdp)) ; tr\_inp(:,:)=0.0}
\DoxyCodeLine{464      \textcolor{keyword}{allocate}(mask\_in(id,jdp)) ; mask\_in(:,:)=0.0}
\DoxyCodeLine{465      \textcolor{keyword}{allocate}(last\_row(id))    ; last\_row(:)=0.0}
\DoxyCodeLine{466 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{467 }
\DoxyCodeLine{468 }
\DoxyCodeLine{469 }
\DoxyCodeLine{470   max\_depth = maxval(g\%bathyT)}
\DoxyCodeLine{471   \textcolor{keyword}{call }mpp\_max(max\_depth)}
\DoxyCodeLine{472 }
\DoxyCodeLine{473   \textcolor{keywordflow}{if} (z\_edges\_in(kd+1)<max\_depth) z\_edges\_in(kd+1)=max\_depth}
\DoxyCodeLine{474   roundoff = 3.0*epsilon(missing\_value)}
\DoxyCodeLine{475 }
\DoxyCodeLine{476   \textcolor{comment}{! loop through each data level and interpolate to model grid.}}
\DoxyCodeLine{477   \textcolor{comment}{! after interpolating, fill in points which will be needed}}
\DoxyCodeLine{478   \textcolor{comment}{! to define the layers}}
\DoxyCodeLine{479   \textcolor{keywordflow}{do} k=1,kd}
\DoxyCodeLine{480     \textcolor{keyword}{write}(laynum,\textcolor{stringliteral}{'(I8)'}) k ; laynum = adjustl(laynum)}
\DoxyCodeLine{481     mask\_in=0.0}
\DoxyCodeLine{482     \textcolor{keywordflow}{if} (is\_ongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483        start(1) = is+g\%HI\%idg\_offset ; start(2) = js+g\%HI\%jdg\_offset ; start(3) = k}
\DoxyCodeLine{484        count(1) = ie-\/is+1 ; count(2) = je-\/js+1; count(3) = 1}
\DoxyCodeLine{485        rcode = nf90\_get\_var(ncid,varid, tr\_in, start, count)}
\DoxyCodeLine{486        \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"hinterp\_and\_extract\_from\_Fie: "}//\&}
\DoxyCodeLine{487             \textcolor{stringliteral}{"error reading level "}//trim(laynum)//\textcolor{stringliteral}{" of variable "}//\&}
\DoxyCodeLine{488             trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename))}
\DoxyCodeLine{489 }
\DoxyCodeLine{490        \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{491          \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{492            \textcolor{keywordflow}{if} (abs(tr\_in(i,j)-\/missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{493               mask\_in(i,j) = 1.0}
\DoxyCodeLine{494               tr\_in(i,j) = (tr\_in(i,j)*scale\_factor+add\_offset) * conversion}
\DoxyCodeLine{495            \textcolor{keywordflow}{else}}
\DoxyCodeLine{496               tr\_in(i,j) = missing\_value}
\DoxyCodeLine{497 \textcolor{keywordflow}{           endif}}
\DoxyCodeLine{498 \textcolor{keywordflow}{         enddo}}
\DoxyCodeLine{499 \textcolor{keywordflow}{       enddo}}
\DoxyCodeLine{500 }
\DoxyCodeLine{501     \textcolor{keywordflow}{else}}
\DoxyCodeLine{502        \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}}
\DoxyCodeLine{503           start = 1 ; start(3) = k ; count(:) = 1 ; count(1) = id ; count(2) = jd}
\DoxyCodeLine{504           rcode = nf90\_get\_var(ncid,varid, tr\_in, start, count)}
\DoxyCodeLine{505           \textcolor{keywordflow}{if} (rcode /= 0) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"hinterp\_and\_extract\_from\_Fie: "}//\&}
\DoxyCodeLine{506                \textcolor{stringliteral}{"error reading level "}//trim(laynum)//\textcolor{stringliteral}{" of variable "}//\&}
\DoxyCodeLine{507                trim(varnam)//\textcolor{stringliteral}{" in file "}// trim(filename))}
\DoxyCodeLine{508 }
\DoxyCodeLine{509           \textcolor{keywordflow}{if} (add\_np) \textcolor{keywordflow}{then}}
\DoxyCodeLine{510              last\_row(:)=tr\_in(:,jd); pole=0.0;npole=0.0}
\DoxyCodeLine{511              \textcolor{keywordflow}{do} i=1,id}
\DoxyCodeLine{512                \textcolor{keywordflow}{if} (abs(tr\_in(i,jd)-\/missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{513                   pole = pole+last\_row(i)}
\DoxyCodeLine{514                   npole = npole+1.0}
\DoxyCodeLine{515 \textcolor{keywordflow}{               endif}}
\DoxyCodeLine{516 \textcolor{keywordflow}{             enddo}}
\DoxyCodeLine{517              \textcolor{keywordflow}{if} (npole > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{518                 pole=pole/npole}
\DoxyCodeLine{519              \textcolor{keywordflow}{else}}
\DoxyCodeLine{520                 pole=missing\_value}
\DoxyCodeLine{521 \textcolor{keywordflow}{             endif}}
\DoxyCodeLine{522              tr\_inp(:,1:jd) = tr\_in(:,:)}
\DoxyCodeLine{523              tr\_inp(:,jdp) = pole}
\DoxyCodeLine{524           \textcolor{keywordflow}{else}}
\DoxyCodeLine{525              tr\_inp(:,:) = tr\_in(:,:)}
\DoxyCodeLine{526 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{527 \textcolor{keywordflow}{       endif}}
\DoxyCodeLine{528 }
\DoxyCodeLine{529        \textcolor{keyword}{call }mpp\_sync()}
\DoxyCodeLine{530        \textcolor{keyword}{call }mpp\_broadcast(tr\_inp, id*jdp, root\_pe())}
\DoxyCodeLine{531        \textcolor{keyword}{call }mpp\_sync\_self()}
\DoxyCodeLine{532 }
\DoxyCodeLine{533        \textcolor{keywordflow}{do} j=1,jdp}
\DoxyCodeLine{534          \textcolor{keywordflow}{do} i=1,id}
\DoxyCodeLine{535            \textcolor{keywordflow}{if} (abs(tr\_inp(i,j)-\/missing\_value) > abs(roundoff*missing\_value)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{536               mask\_in(i,j) = 1.0}
\DoxyCodeLine{537               tr\_inp(i,j) = (tr\_inp(i,j)*scale\_factor+add\_offset) * conversion}
\DoxyCodeLine{538            \textcolor{keywordflow}{else}}
\DoxyCodeLine{539               tr\_inp(i,j) = missing\_value}
\DoxyCodeLine{540 \textcolor{keywordflow}{           endif}}
\DoxyCodeLine{541 \textcolor{keywordflow}{         enddo}}
\DoxyCodeLine{542 \textcolor{keywordflow}{       enddo}}
\DoxyCodeLine{543 }
\DoxyCodeLine{544 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{545 }
\DoxyCodeLine{546 }
\DoxyCodeLine{547 }
\DoxyCodeLine{548 \textcolor{comment}{!   call fms routine horiz\_interp to interpolate input level data to model horizontal grid}}
\DoxyCodeLine{549     \textcolor{keywordflow}{if} (.not. is\_ongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{550        \textcolor{keywordflow}{if} (k == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{551           \textcolor{keyword}{call }horiz\_interp\_new(interp,x\_in,y\_in,lon\_out(is:ie,js:je),lat\_out(is:ie,js:je), \&}
\DoxyCodeLine{552                interp\_method=\textcolor{stringliteral}{'bilinear'},src\_modulo=.true.)}
\DoxyCodeLine{553 \textcolor{keywordflow}{       endif}}
\DoxyCodeLine{554 }
\DoxyCodeLine{555        \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{556           \textcolor{keyword}{call }mystats(tr\_inp,missing\_value, is,ie,js,je,k,\textcolor{stringliteral}{'Tracer from file'})}
\DoxyCodeLine{557 \textcolor{keywordflow}{       endif}}
\DoxyCodeLine{558 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{559 }
\DoxyCodeLine{560     tr\_out(:,:) = 0.0}
\DoxyCodeLine{561     \textcolor{keywordflow}{if} (is\_ongrid) \textcolor{keywordflow}{then}}
\DoxyCodeLine{562        tr\_out(is:ie,js:je)=tr\_in(is:ie,js:je)}
\DoxyCodeLine{563     \textcolor{keywordflow}{else}}
\DoxyCodeLine{564        \textcolor{keyword}{call }horiz\_interp(interp,tr\_inp,tr\_out(is:ie,js:je), missing\_value=missing\_value, new\_missing\_handle=.true.)}
\DoxyCodeLine{565 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{566 }
\DoxyCodeLine{567     mask\_out=1.0}
\DoxyCodeLine{568     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{569       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{570         \textcolor{keywordflow}{if} (abs(tr\_out(i,j)-\/missing\_value) < abs(roundoff*missing\_value)) mask\_out(i,j)=0.}
\DoxyCodeLine{571 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{572 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{573 }
\DoxyCodeLine{574     fill = 0.0; good = 0.0}
\DoxyCodeLine{575 }
\DoxyCodeLine{576     npoints = 0 ; varavg = 0.}
\DoxyCodeLine{577     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{578       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{579         \textcolor{keywordflow}{if} (mask\_out(i,j) < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{580           tr\_out(i,j)=missing\_value}
\DoxyCodeLine{581         \textcolor{keywordflow}{else}}
\DoxyCodeLine{582           good(i,j)=1.0}
\DoxyCodeLine{583           npoints = npoints + 1}
\DoxyCodeLine{584           varavg = varavg + tr\_out(i,j)}
\DoxyCodeLine{585 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{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) \&}
\DoxyCodeLine{587           fill(i,j)=1.0}
\DoxyCodeLine{588 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{589 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{590     \textcolor{keyword}{call }pass\_var(fill,g\%Domain)}
\DoxyCodeLine{591     \textcolor{keyword}{call }pass\_var(good,g\%Domain)}
\DoxyCodeLine{592 }
\DoxyCodeLine{593     \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{594       \textcolor{keyword}{call }mystats(tr\_out,missing\_value, is,ie,js,je,k,\textcolor{stringliteral}{'variable from horiz\_interp()'})}
\DoxyCodeLine{595 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{596 }
\DoxyCodeLine{597     \textcolor{comment}{! Horizontally homogenize data to produce perfectly "flat" initial conditions}}
\DoxyCodeLine{598     \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(homogenize)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{599        \textcolor{keywordflow}{if} (homogenize) \textcolor{keywordflow}{then}}
\DoxyCodeLine{600           \textcolor{keyword}{call }sum\_across\_pes(npoints)}
\DoxyCodeLine{601           \textcolor{keyword}{call }sum\_across\_pes(varavg)}
\DoxyCodeLine{602           \textcolor{keywordflow}{if} (npoints>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{603              varavg = varavg/real(npoints)}
\DoxyCodeLine{604 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{605           tr\_out(:,:) = varavg}
\DoxyCodeLine{606 \textcolor{keywordflow}{       endif}}
\DoxyCodeLine{607 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{608 }
\DoxyCodeLine{609     \textcolor{comment}{! tr\_out contains input z-\/space data on the model grid with missing values}}
\DoxyCodeLine{610     \textcolor{comment}{! now fill in missing values using "ICE-\/nine" algorithm.}}
\DoxyCodeLine{611     tr\_outf(:,:) = tr\_out(:,:)}
\DoxyCodeLine{612     \textcolor{keywordflow}{if} (k==1) tr\_prev(:,:) = tr\_outf(:,:)}
\DoxyCodeLine{613     good2(:,:) = good(:,:)}
\DoxyCodeLine{614     fill2(:,:) = fill(:,:)}
\DoxyCodeLine{615 }
\DoxyCodeLine{616     \textcolor{keyword}{call }fill\_miss\_2d(tr\_outf, good2, fill2, tr\_prev, g, smooth=.true., answers\_2018=answers\_2018)}
\DoxyCodeLine{617     \textcolor{keyword}{call }mystats(tr\_outf, missing\_value, is, ie, js, je, k, \textcolor{stringliteral}{'field from fill\_miss\_2d()'})}
\DoxyCodeLine{618 }
\DoxyCodeLine{619     tr\_z(:,:,k) = tr\_outf(:,:) * g\%mask2dT(:,:)}
\DoxyCodeLine{620     mask\_z(:,:,k) = good2(:,:) + fill2(:,:)}
\DoxyCodeLine{621 }
\DoxyCodeLine{622     tr\_prev(:,:) = tr\_z(:,:,k)}
\DoxyCodeLine{623 }
\DoxyCodeLine{624     \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{625       \textcolor{keyword}{call }hchksum(tr\_prev,\textcolor{stringliteral}{'field after fill '},g\%HI)}
\DoxyCodeLine{626 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{627 }
\DoxyCodeLine{628 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! kd}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em x} & input 1-\/dimensional vector \\
\hline
\mbox{\texttt{ in}}  & {\em y} & input 1-\/dimensional vector \\
\hline
\mbox{\texttt{ in,out}}  & {\em x\+\_\+t} & output 2-\/dimensional array \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{928 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},                   \textcolor{keywordtype}{intent(in)}    :: x\textcolor{comment}{  !< input 1-\/dimensional vector}}
\DoxyCodeLine{929 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},                   \textcolor{keywordtype}{intent(in)}    :: y\textcolor{comment}{  !< input 1-\/dimensional vector}}
\DoxyCodeLine{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}}
\DoxyCodeLine{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}}
\DoxyCodeLine{932 }
\DoxyCodeLine{933   \textcolor{keywordtype}{integer} :: ni,nj,i,j}
\DoxyCodeLine{934 }
\DoxyCodeLine{935   ni=\textcolor{keyword}{size}(x,1) ; nj=\textcolor{keyword}{size}(y,1)}
\DoxyCodeLine{936 }
\DoxyCodeLine{937   \textcolor{keywordflow}{do} j=1,nj ; \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{938     x\_t(i,j) = x(i)}
\DoxyCodeLine{939 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{940 }
\DoxyCodeLine{941   \textcolor{keywordflow}{do} j=1,nj ; \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{942     y\_t(i,j) = y(j)}
\DoxyCodeLine{943 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em array} & input array (ND) \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{62 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)} :: array\textcolor{comment}{ !< input array (ND)}}
\DoxyCodeLine{63 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: missing\textcolor{comment}{ !< missing value (ND)}}
\DoxyCodeLine{64   \textcolor{keywordtype}{integer} :: is\textcolor{comment}{   !< Start index in i}}
\DoxyCodeLine{65   \textcolor{keywordtype}{integer} :: ie\textcolor{comment}{   !< End index in i}}
\DoxyCodeLine{66   \textcolor{keywordtype}{integer} :: js\textcolor{comment}{   !< Start index in j}}
\DoxyCodeLine{67   \textcolor{keywordtype}{integer} :: je\textcolor{comment}{   !< End index in j}}
\DoxyCodeLine{68   \textcolor{keywordtype}{integer} :: k\textcolor{comment}{ !< Level to calculate statistics for}}
\DoxyCodeLine{69   \textcolor{keywordtype}{character(len=*)} :: mesg\textcolor{comment}{ !< Label to use in message}}
\DoxyCodeLine{70   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{71 \textcolor{keywordtype}{  real} :: minA, maxA}
\DoxyCodeLine{72   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{73   \textcolor{keywordtype}{logical} :: found}
\DoxyCodeLine{74   \textcolor{keywordtype}{character(len=120)} :: lMesg}
\DoxyCodeLine{75   mina = 9.e24 ; maxa = -\/9.e24 ; found = .false.}
\DoxyCodeLine{76 }
\DoxyCodeLine{77   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{78     \textcolor{keywordflow}{if} (array(i,j) /= array(i,j)) stop \textcolor{stringliteral}{'Nan!'}}
\DoxyCodeLine{79     \textcolor{keywordflow}{if} (abs(array(i,j)-\/missing) > 1.e-\/6*abs(missing)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{80       \textcolor{keywordflow}{if} (found) \textcolor{keywordflow}{then}}
\DoxyCodeLine{81         mina = min(mina, array(i,j))}
\DoxyCodeLine{82         maxa = max(maxa, array(i,j))}
\DoxyCodeLine{83       \textcolor{keywordflow}{else}}
\DoxyCodeLine{84         found = .true.}
\DoxyCodeLine{85         mina = array(i,j)}
\DoxyCodeLine{86         maxa = array(i,j)}
\DoxyCodeLine{87 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{88 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{89 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{90   \textcolor{keyword}{call }min\_across\_pes(mina)}
\DoxyCodeLine{91   \textcolor{keyword}{call }max\_across\_pes(maxa)}
\DoxyCodeLine{92   \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keywordflow}{then}}
\DoxyCodeLine{93     \textcolor{keyword}{write}(lmesg(1:120),\textcolor{stringliteral}{'(2(a,es12.4),a,i3,x,a)'}) \&}
\DoxyCodeLine{94          \textcolor{stringliteral}{'init\_from\_Z: min='},mina,\textcolor{stringliteral}{' max='},maxa,\textcolor{stringliteral}{' Level='},k,trim(mesg)}
\DoxyCodeLine{95     \textcolor{keyword}{call }mom\_mesg(lmesg,2)}
\DoxyCodeLine{96 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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{\texttt{ in,out}}  & {\em zi} & input and output array (ND) \\
\hline
\mbox{\texttt{ in}}  & {\em fill} & same shape as zi, 1=fill \\
\hline
\mbox{\texttt{ in}}  & {\em bad} & same shape as zi, 1=bad data \\
\hline
\mbox{\texttt{ in}}  & {\em sor} & relaxation coefficient (ND) \\
\hline
\mbox{\texttt{ in}}  & {\em niter} & maximum number of iterations \\
\hline
\mbox{\texttt{ in}}  & {\em cyclic\+\_\+x} & true if domain is zonally reentrant \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{1006 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{dimension(:,:)},                   \textcolor{keywordtype}{intent(inout)} :: zi\textcolor{comment}{ !< input and output array (ND)}}
\DoxyCodeLine{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}}
\DoxyCodeLine{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}}
\DoxyCodeLine{1009 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}  :: sor\textcolor{comment}{ !< relaxation coefficient (ND)}}
\DoxyCodeLine{1010   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)} :: niter\textcolor{comment}{ !< maximum number of iterations}}
\DoxyCodeLine{1011   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)} :: cyclic\_x\textcolor{comment}{ !< true if domain is zonally reentrant}}
\DoxyCodeLine{1012   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)} :: tripolar\_n\textcolor{comment}{ !< true if domain has an Arctic fold}}
\DoxyCodeLine{1013 }
\DoxyCodeLine{1014   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1015 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(size(zi,1),size(zi,2))} :: res, m}
\DoxyCodeLine{1016   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(size(zi,1),size(zi,2),4)} :: B}
\DoxyCodeLine{1017 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(0:size(zi,1)+1,0:size(zi,2)+1)} :: mp}
\DoxyCodeLine{1018   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(0:size(zi,1)+1,0:size(zi,2)+1)} :: nm}
\DoxyCodeLine{1019   \textcolor{keywordtype}{integer} :: i,j,k,n}
\DoxyCodeLine{1020   \textcolor{keywordtype}{integer} :: ni,nj}
\DoxyCodeLine{1021 \textcolor{keywordtype}{  real} :: Isum, bsum}
\DoxyCodeLine{1022 }
\DoxyCodeLine{1023   ni=\textcolor{keyword}{size}(zi,1) ; nj=\textcolor{keyword}{size}(zi,2)}
\DoxyCodeLine{1024 }
\DoxyCodeLine{1025 }
\DoxyCodeLine{1026   mp(:,:) = fill\_boundaries(zi,cyclic\_x,tripolar\_n)}
\DoxyCodeLine{1027 }
\DoxyCodeLine{1028   b(:,:,:) = 0.0}
\DoxyCodeLine{1029   nm(:,:) = fill\_boundaries(bad,cyclic\_x,tripolar\_n)}
\DoxyCodeLine{1030 }
\DoxyCodeLine{1031   \textcolor{keywordflow}{do} j=1,nj}
\DoxyCodeLine{1032     \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{1033       \textcolor{keywordflow}{if} (fill(i,j) == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1034         b(i,j,1)=1-\/nm(i+1,j);b(i,j,2)=1-\/nm(i-\/1,j)}
\DoxyCodeLine{1035         b(i,j,3)=1-\/nm(i,j+1);b(i,j,4)=1-\/nm(i,j-\/1)}
\DoxyCodeLine{1036 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1037 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1038 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1039 }
\DoxyCodeLine{1040   \textcolor{keywordflow}{do} n=1,niter}
\DoxyCodeLine{1041     \textcolor{keywordflow}{do} j=1,nj}
\DoxyCodeLine{1042       \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{1043         \textcolor{keywordflow}{if} (fill(i,j) == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1044           bsum = real(b(i,j,1)+b(i,j,2)+b(i,j,3)+b(i,j,4))}
\DoxyCodeLine{1045           isum = 1.0/bsum}
\DoxyCodeLine{1046           res(i,j)=isum*(b(i,j,1)*mp(i+1,j)+b(i,j,2)*mp(i-\/1,j)+\&}
\DoxyCodeLine{1047                    b(i,j,3)*mp(i,j+1)+b(i,j,4)*mp(i,j-\/1)) -\/ mp(i,j)}
\DoxyCodeLine{1048 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1049 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1050 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1051     res(:,:)=res(:,:)*sor}
\DoxyCodeLine{1052 }
\DoxyCodeLine{1053     \textcolor{keywordflow}{do} j=1,nj}
\DoxyCodeLine{1054       \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{1055         mp(i,j)=mp(i,j)+res(i,j)}
\DoxyCodeLine{1056 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1057 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1058 }
\DoxyCodeLine{1059     zi(:,:)=mp(1:ni,1:nj)}
\DoxyCodeLine{1060     mp = fill\_boundaries(zi,cyclic\_x,tripolar\_n)}
\DoxyCodeLine{1061 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1062 }

\end{DoxyCode}
