\hypertarget{namespacemom__remapping}{}\section{mom\+\_\+remapping Module Reference}
\label{namespacemom__remapping}\index{mom\_remapping@{mom\_remapping}}


\subsection{Detailed Description}
Provides column-\/wise vertical remapping functions. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Container for remapping parameters. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a50e96a4a1083bb1fae3ca0130b6a2c11}{remapping\+\_\+set\+\_\+param}} (CS, remapping\+\_\+scheme, boundary\+\_\+extrapolation, check\+\_\+reconstruction, check\+\_\+remapping, force\+\_\+bounds\+\_\+in\+\_\+subcell, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Set parameters within remapping object. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a5777b80186106733e7a182694d708fba}{extract\+\_\+member\+\_\+remapping\+\_\+cs}} (CS, remapping\+\_\+scheme, degree, boundary\+\_\+extrapolation, check\+\_\+reconstruction, check\+\_\+remapping, force\+\_\+bounds\+\_\+in\+\_\+subcell)
\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a80ed96a40bd7320cfe4213e1550365f0}{buildgridfromh}} (nz, h, x)
\begin{DoxyCompactList}\small\item\em Calculate edge coordinate x from cell width h. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__remapping_accd6922c5eb61fa77c11869d8b219f7c}{ispossumerrsignificant}} (n1, sum1, n2, sum2)
\begin{DoxyCompactList}\small\item\em Compare two summation estimates of positive data and judge if due to more than round-\/off. When two sums are calculated from different vectors that should add up to the same value, the results can differ by round off. The round off error can be bounded to be proportional to the number of operations. This function returns true if the difference between sum1 and sum2 is larger than than the estimated round off bound. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_abe4a1d5b1b9f26063a5e4aba5be0b0a5}{remapping\+\_\+core\+\_\+h}} (CS, n0, h0, u0, n1, h1, u1, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to grid h1 assuming the top edge is aligned. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a38bd02a8643f4a984bc3985f34106d9a}{remapping\+\_\+core\+\_\+w}} (CS, n0, h0, u0, n1, dx, u1, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a5bb0006054c9fa4522783aa3f1f500d5}{build\+\_\+reconstructions\+\_\+1d}} (CS, n0, h0, u0, ppoly\+\_\+r\+\_\+coefs, ppoly\+\_\+r\+\_\+E, ppoly\+\_\+r\+\_\+S, i\+Method, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Creates polynomial reconstructions of u0 on the source grid h0. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a1756ab9c7329e586ded97e7270b14d4d}{check\+\_\+reconstructions\+\_\+1d}} (n0, h0, u0, deg, boundary\+\_\+extrapolation, ppoly\+\_\+r\+\_\+coefs, ppoly\+\_\+r\+\_\+E, ppoly\+\_\+r\+\_\+S)
\begin{DoxyCompactList}\small\item\em Checks that edge values and reconstructions satisfy bounds. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_ab933069898cb9de16ec60f175185762e}{remap\+\_\+via\+\_\+sub\+\_\+cells}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, n1, h1, method, force\+\_\+bounds\+\_\+in\+\_\+subcell, u1, uh\+\_\+err, ah\+\_\+sub, aisub\+\_\+src, aiss, aise)
\begin{DoxyCompactList}\small\item\em Remaps column of n0 values u0 on grid h0 to grid h1 with n1 cells by calculating the n0+n1+1 sub-\/integrals of the intersection of h0 and h1, and the summing the appropriate integrals into the h1$\ast$u1 values. h0 and h1 must have the same units. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__remapping_a89dde73fbc6eec035c8dabc225a9c210}{average\+\_\+value\+\_\+ppoly}} (n0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, method, i0, xa, xb)
\begin{DoxyCompactList}\small\item\em Returns the average value of a reconstruction within a single source cell, i0, between the non-\/dimensional positions xa and xb (xa$<$=xb) with dimensional separation dh. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a0b392b7cbac49fc8ab52b2830e3a9306}{measure\+\_\+input\+\_\+bounds}} (n0, h0, u0, edge\+\_\+values, h0tot, h0err, u0tot, u0err, u0min, u0max)
\begin{DoxyCompactList}\small\item\em Measure totals and bounds on source grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a5453aeefe69feaff159b67f3a4bd2366}{measure\+\_\+output\+\_\+bounds}} (n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max)
\begin{DoxyCompactList}\small\item\em Measure totals and bounds on destination grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_add104225e8ea85f4e6a324da6be3dba2}{remapbyprojection}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, n1, h1, method, u1, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to grid h1 by integrating over the projection of each h1 cell onto the h0 grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_ad41da2080e01eaed0b189079801b3c9b}{remapbydeltaz}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, n1, dx1, method, u1, h1, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. The new grid is defined relative to the original grid by change dx1(\+:) = x\+New(\+:) -\/ x\+Old(\+:) and the remapping calculated so that h\+New(k) q\+New(k) = h\+Old(k) q\+Old(k) + F(k+1) -\/ F(k) where F(k) = dx1(k) q\+Average and where q\+Average is the average q\+Old in the region z\+Old(k) to z\+New(k). \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a98e87df5ab2fcf8483894f95c4fde672}{integraterecononinterval}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, method, xL, xR, hC, u\+Ave, j\+Start, x\+Start, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Integrate the reconstructed column profile over a single cell. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a494289c324db2496816f2687f4ceea76}{dzfromh1h2}} (n1, h1, n2, h2, dx)
\begin{DoxyCompactList}\small\item\em Calculates the change in interface positions based on h1 and h2. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a81211827af45207130d25cae520b55e5}{initialize\+\_\+remapping}} (CS, remapping\+\_\+scheme, boundary\+\_\+extrapolation, check\+\_\+reconstruction, check\+\_\+remapping, force\+\_\+bounds\+\_\+in\+\_\+subcell, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Constructor for remapping control structure. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a41a89ac62578250500b7a450d5fdfae7}{setreconstructiontype}} (string, CS)
\begin{DoxyCompactList}\small\item\em Changes the method of reconstruction Use this routine to parse a string parameter specifying the reconstruction and re-\/allocates work arrays appropriately. It is called from initialize\+\_\+remapping but can be called from an external module too. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a10ca09dcc83f53137647ba51ba5deb72}{end\+\_\+remapping}} (CS)
\begin{DoxyCompactList}\small\item\em Destrcutor for remapping control structure. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__remapping_a5849f564453d5ed76fb4feffd41eca26}{remapping\+\_\+unit\+\_\+tests}} (verbose)
\begin{DoxyCompactList}\small\item\em Runs unit tests on remapping functions. Should only be called from a single/root thread Returns True if a test fails, otherwise False. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__remapping_a3235506c107c81b116cec92952dd8cbb}{test\+\_\+answer}} (verbose, n, u, u\+\_\+true, label, tol)
\begin{DoxyCompactList}\small\item\em Returns true if any cell of u and u\+\_\+true are not identical. Returns false otherwise. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_ad1246e94fd3b411c2ea8ba675a52874b}{dumpgrid}} (n, h, x, u)
\begin{DoxyCompactList}\small\item\em Convenience function for printing grid to screen. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__remapping_a3dad5d18f7b13f14230f9c50f976c14d}\label{namespacemom__remapping_a3dad5d18f7b13f14230f9c50f976c14d}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a3dad5d18f7b13f14230f9c50f976c14d}{remapping\+\_\+pcm}} = 0
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$1) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_ac174af1d37725840215d9e65525b4a58}\label{namespacemom__remapping_ac174af1d37725840215d9e65525b4a58}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_ac174af1d37725840215d9e65525b4a58}{remapping\+\_\+plm}} = 1
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$2) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a40ab417b859bc139c78739f29291641f}\label{namespacemom__remapping_a40ab417b859bc139c78739f29291641f}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a40ab417b859bc139c78739f29291641f}{remapping\+\_\+ppm\+\_\+h4}} = 2
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$3) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a186e67e08bd3485a2850d20ecbf3be85}\label{namespacemom__remapping_a186e67e08bd3485a2850d20ecbf3be85}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a186e67e08bd3485a2850d20ecbf3be85}{remapping\+\_\+ppm\+\_\+ih4}} = 3
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$3) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a782d61555a87cd8a68a37ed8a9bb4a95}\label{namespacemom__remapping_a782d61555a87cd8a68a37ed8a9bb4a95}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a782d61555a87cd8a68a37ed8a9bb4a95}{remapping\+\_\+pqm\+\_\+ih4ih3}} = 4
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$4) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a0890124a6b6d71f31c6d382f52172337}\label{namespacemom__remapping_a0890124a6b6d71f31c6d382f52172337}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a0890124a6b6d71f31c6d382f52172337}{remapping\+\_\+pqm\+\_\+ih6ih5}} = 5
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$5) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_ac1cc04f1f416e9132c98a416e3cf286d}\label{namespacemom__remapping_ac1cc04f1f416e9132c98a416e3cf286d}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_ac1cc04f1f416e9132c98a416e3cf286d}{integration\+\_\+pcm}} = 0
\begin{DoxyCompactList}\small\item\em Piecewise Constant Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a37c86f210a0a7732da5906716f080141}\label{namespacemom__remapping_a37c86f210a0a7732da5906716f080141}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a37c86f210a0a7732da5906716f080141}{integration\+\_\+plm}} = 1
\begin{DoxyCompactList}\small\item\em Piecewise Linear Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a1ad21cf7ed0b74aeb469799d9d748c85}\label{namespacemom__remapping_a1ad21cf7ed0b74aeb469799d9d748c85}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a1ad21cf7ed0b74aeb469799d9d748c85}{integration\+\_\+ppm}} = 3
\begin{DoxyCompactList}\small\item\em Piecewise Parabolic Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a356299a6f7a626edd65e449246a4b60d}\label{namespacemom__remapping_a356299a6f7a626edd65e449246a4b60d}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a356299a6f7a626edd65e449246a4b60d}{integration\+\_\+pqm}} = 5
\begin{DoxyCompactList}\small\item\em Piecewise Quartic Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a348a14b44b2dff0964e53ec4091b796b}\label{namespacemom__remapping_a348a14b44b2dff0964e53ec4091b796b}} 
character(len=40) \mbox{\hyperlink{namespacemom__remapping_a348a14b44b2dff0964e53ec4091b796b}{mdl}} = \char`\"{}M\+O\+M\+\_\+remapping\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a8c5a45fb3f4f16cc89405a51fd7361cc}\label{namespacemom__remapping_a8c5a45fb3f4f16cc89405a51fd7361cc}} 
character(len=256), public \mbox{\hyperlink{namespacemom__remapping_a8c5a45fb3f4f16cc89405a51fd7361cc}{remappingschemesdoc}} = \char`\"{}P\+CM (1st-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+L\+M (2nd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+P\+M\+\_\+\+H4 (3rd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+P\+M\+\_\+\+I\+H4 (3rd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+Q\+M\+\_\+\+I\+H4\+I\+H3 (4th-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+Q\+M\+\_\+\+I\+H6\+I\+H5 (5th-\/order accurate)\textbackslash{}n\char`\"{}
\begin{DoxyCompactList}\small\item\em Documentation for external callers. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a5978c723e71e49b2f54768fea10000cb}\label{namespacemom__remapping_a5978c723e71e49b2f54768fea10000cb}} 
character(len=3), public \mbox{\hyperlink{namespacemom__remapping_a5978c723e71e49b2f54768fea10000cb}{remappingdefaultscheme}} = \char`\"{}P\+LM\char`\"{}
\begin{DoxyCompactList}\small\item\em Default remapping method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a3f6a36677ae2737e9cd9d5875110ffc1}\label{namespacemom__remapping_a3f6a36677ae2737e9cd9d5875110ffc1}} 
real, parameter \mbox{\hyperlink{namespacemom__remapping_a3f6a36677ae2737e9cd9d5875110ffc1}{hneglect\+\_\+dflt}} = 1.E-\/30
\begin{DoxyCompactList}\small\item\em A thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} that can be added to thicknesses in a denominator without changing the numerical result, except where a division by zero would otherwise occur. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a8b7945e5d6bd0a3387df90476eca0014}\label{namespacemom__remapping_a8b7945e5d6bd0a3387df90476eca0014}} 
logical, parameter \mbox{\hyperlink{namespacemom__remapping_a8b7945e5d6bd0a3387df90476eca0014}{old\+\_\+algorithm}} = .false.
\begin{DoxyCompactList}\small\item\em Use the old \char`\"{}broken\char`\"{} algorithm. This is a temporary measure to assist debugging until we delete the old algorithm. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__remapping_a89dde73fbc6eec035c8dabc225a9c210}\label{namespacemom__remapping_a89dde73fbc6eec035c8dabc225a9c210}} 
\index{mom\_remapping@{mom\_remapping}!average\_value\_ppoly@{average\_value\_ppoly}}
\index{average\_value\_ppoly@{average\_value\_ppoly}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{average\_value\_ppoly()}{average\_value\_ppoly()}}
{\footnotesize\ttfamily real function, public mom\+\_\+remapping\+::average\+\_\+value\+\_\+ppoly (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{method,  }\item[{integer, intent(in)}]{i0,  }\item[{real, intent(in)}]{xa,  }\item[{real, intent(in)}]{xb }\end{DoxyParamCaption})}



Returns the average value of a reconstruction within a single source cell, i0, between the non-\/dimensional positions xa and xb (xa$<$=xb) with dimensional separation dh. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Cell means \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Remapping scheme to use \\
\hline
\mbox{\texttt{ in}}  & {\em i0} & Source cell index \\
\hline
\mbox{\texttt{ in}}  & {\em xa} & Non-\/dimensional start position within source cell \\
\hline
\mbox{\texttt{ in}}  & {\em xb} & Non-\/dimensional end position within source cell \\
\hline
\end{DoxyParams}


Definition at line 930 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{930   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}}
\DoxyCodeLine{931 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: u0(:)\textcolor{comment}{  !< Cell means}}
\DoxyCodeLine{932 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E(:,:)\textcolor{comment}{     !< Edge value of polynomial}}
\DoxyCodeLine{933 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs(:,:)\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{934   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{935   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: i0\textcolor{comment}{     !< Source cell index}}
\DoxyCodeLine{936 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: xa\textcolor{comment}{     !< Non-dimensional start position within source cell}}
\DoxyCodeLine{937 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: xb\textcolor{comment}{     !< Non-dimensional end position within source cell}}
\DoxyCodeLine{938   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{939 \textcolor{keywordtype}{  real} :: u\_ave, xa\_2, xb\_2, xa2pxb2, xapxb}
\DoxyCodeLine{940 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: r\_3 = 1.0/3.0 \textcolor{comment}{! Used in evaluation of integrated polynomials}}
\DoxyCodeLine{941 }
\DoxyCodeLine{942 \textcolor{keywordtype}{  real} :: mx, a\_L, a\_R, u\_c, Ya, Yb, my, xa2b2ab, Ya2b2ab, a\_c}
\DoxyCodeLine{943 }
\DoxyCodeLine{944   \textcolor{keywordflow}{if} (xb > xa) \textcolor{keywordflow}{then}}
\DoxyCodeLine{945     \textcolor{keywordflow}{select case} ( method )}
\DoxyCodeLine{946       \textcolor{keywordflow}{case} ( integration\_pcm )}
\DoxyCodeLine{947         u\_ave = u0(i0)}
\DoxyCodeLine{948       \textcolor{keywordflow}{case} ( integration\_plm )}
\DoxyCodeLine{949         u\_ave = (                                           \&}
\DoxyCodeLine{950             ppoly0\_coefs(i0,1)                       \&}
\DoxyCodeLine{951           + ppoly0\_coefs(i0,2) * 0.5 * ( xb + xa ) )}
\DoxyCodeLine{952       \textcolor{keywordflow}{case} ( integration\_ppm )}
\DoxyCodeLine{953         mx = 0.5 * ( xa + xb )}
\DoxyCodeLine{954         a\_l = ppoly0\_e(i0, 1)}
\DoxyCodeLine{955         a\_r = ppoly0\_e(i0, 2)}
\DoxyCodeLine{956         u\_c = u0(i0)}
\DoxyCodeLine{957         a\_c = 0.5 * ( ( u\_c - a\_l ) + ( u\_c - a\_r ) ) \textcolor{comment}{! a\_6 / 6}}
\DoxyCodeLine{958         \textcolor{keywordflow}{if} (mx<0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{959           \textcolor{comment}{! This integration of the PPM reconstruction is expressed in distances from the left edge}}
\DoxyCodeLine{960           xa2b2ab = (xa*xa+xb*xb)+xa*xb}
\DoxyCodeLine{961           u\_ave = a\_l + ( ( a\_r - a\_l ) * mx \&}
\DoxyCodeLine{962                           + a\_c * ( 3. * ( xb + xa ) - 2.*xa2b2ab ) )}
\DoxyCodeLine{963         \textcolor{keywordflow}{else}}
\DoxyCodeLine{964           \textcolor{comment}{! This integration of the PPM reconstruction is expressed in distances from the right edge}}
\DoxyCodeLine{965           ya = 1. - xa}
\DoxyCodeLine{966           yb = 1. - xb}
\DoxyCodeLine{967           my = 0.5 * ( ya + yb )}
\DoxyCodeLine{968           ya2b2ab = (ya*ya+yb*yb)+ya*yb}
\DoxyCodeLine{969           u\_ave = a\_r  + ( ( a\_l - a\_r ) * my \&}
\DoxyCodeLine{970                            + a\_c * ( 3. * ( yb + ya ) - 2.*ya2b2ab ) )}
\DoxyCodeLine{971 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{972       \textcolor{keywordflow}{case} ( integration\_pqm )}
\DoxyCodeLine{973         xa\_2 = xa*xa}
\DoxyCodeLine{974         xb\_2 = xb*xb}
\DoxyCodeLine{975         xa2pxb2 = xa\_2 + xb\_2}
\DoxyCodeLine{976         xapxb = xa + xb}
\DoxyCodeLine{977         u\_ave = (                                                                               \&}
\DoxyCodeLine{978               ppoly0\_coefs(i0,1)                                                         \&}
\DoxyCodeLine{979           + ( ppoly0\_coefs(i0,2) * 0.5 * ( xapxb )                                       \&}
\DoxyCodeLine{980           + ( ppoly0\_coefs(i0,3) * r\_3 * ( xa2pxb2 + xa*xb )                             \&}
\DoxyCodeLine{981           + ( ppoly0\_coefs(i0,4) * 0.25* ( xa2pxb2 * xapxb )                             \&}
\DoxyCodeLine{982           +   ppoly0\_coefs(i0,5) * 0.2 * ( ( xb*xb\_2 + xa*xa\_2 ) * xapxb + xa\_2*xb\_2 ) ) ) ) )}
\DoxyCodeLine{983 \textcolor{keywordflow}{      case default}}
\DoxyCodeLine{984         \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )}
\DoxyCodeLine{985 \textcolor{keywordflow}{    end select}}
\DoxyCodeLine{986   \textcolor{keywordflow}{else} \textcolor{comment}{! dh == 0.}}
\DoxyCodeLine{987     \textcolor{keywordflow}{select case} ( method )}
\DoxyCodeLine{988       \textcolor{keywordflow}{case} ( integration\_pcm )}
\DoxyCodeLine{989         u\_ave =        ppoly0\_coefs(i0,1)}
\DoxyCodeLine{990       \textcolor{keywordflow}{case} ( integration\_plm )}
\DoxyCodeLine{991        \textcolor{comment}{!u\_ave =        ppoly0\_coefs(i0,1)   \&}}
\DoxyCodeLine{992        \textcolor{comment}{!      + xa *   ppoly0\_coefs(i0,2)}}
\DoxyCodeLine{993         a\_l = ppoly0\_e(i0, 1)}
\DoxyCodeLine{994         a\_r = ppoly0\_e(i0, 2)}
\DoxyCodeLine{995         ya = 1. - xa}
\DoxyCodeLine{996         \textcolor{keywordflow}{if} (xa < 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{997           u\_ave = a\_l + xa * ( a\_r - a\_l )}
\DoxyCodeLine{998         \textcolor{keywordflow}{else}}
\DoxyCodeLine{999           u\_ave = a\_r + ya * ( a\_l - a\_r )}
\DoxyCodeLine{1000 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1001       \textcolor{keywordflow}{case} ( integration\_ppm )}
\DoxyCodeLine{1002        \textcolor{comment}{!u\_ave =        ppoly0\_coefs(i0,1)   \&}}
\DoxyCodeLine{1003        \textcolor{comment}{!      + xa * ( ppoly0\_coefs(i0,2)   \&}}
\DoxyCodeLine{1004        \textcolor{comment}{!      + xa *   ppoly0\_coefs(i0,3) )}}
\DoxyCodeLine{1005         a\_l = ppoly0\_e(i0, 1)}
\DoxyCodeLine{1006         a\_r = ppoly0\_e(i0, 2)}
\DoxyCodeLine{1007         u\_c = u0(i0)}
\DoxyCodeLine{1008         a\_c = 3. * ( ( u\_c - a\_l ) + ( u\_c - a\_r ) ) \textcolor{comment}{! a\_6}}
\DoxyCodeLine{1009         ya = 1. - xa}
\DoxyCodeLine{1010         \textcolor{keywordflow}{if} (xa < 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1011           u\_ave = a\_l + xa * ( ( a\_r - a\_l ) + a\_c * ya )}
\DoxyCodeLine{1012         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1013           u\_ave = a\_r + ya * ( ( a\_l - a\_r ) + a\_c * xa )}
\DoxyCodeLine{1014 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1015       \textcolor{keywordflow}{case} ( integration\_pqm )}
\DoxyCodeLine{1016         u\_ave =        ppoly0\_coefs(i0,1)   \&}
\DoxyCodeLine{1017               + xa * ( ppoly0\_coefs(i0,2)   \&}
\DoxyCodeLine{1018               + xa * ( ppoly0\_coefs(i0,3)   \&}
\DoxyCodeLine{1019               + xa * ( ppoly0\_coefs(i0,4)   \&}
\DoxyCodeLine{1020               + xa *   ppoly0\_coefs(i0,5) ) ) )}
\DoxyCodeLine{1021 \textcolor{keywordflow}{      case default}}
\DoxyCodeLine{1022         \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )}
\DoxyCodeLine{1023 \textcolor{keywordflow}{    end select}}
\DoxyCodeLine{1024 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1025   average\_value\_ppoly = u\_ave}
\DoxyCodeLine{1026 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5bb0006054c9fa4522783aa3f1f500d5}\label{namespacemom__remapping_a5bb0006054c9fa4522783aa3f1f500d5}} 
\index{mom\_remapping@{mom\_remapping}!build\_reconstructions\_1d@{build\_reconstructions\_1d}}
\index{build\_reconstructions\_1d@{build\_reconstructions\_1d}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{build\_reconstructions\_1d()}{build\_reconstructions\_1d()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::build\+\_\+reconstructions\+\_\+1d (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{real, dimension(n0,cs\%degree+1), intent(out)}]{ppoly\+\_\+r\+\_\+coefs,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+E,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+S,  }\item[{integer, intent(out)}]{i\+Method,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Creates polynomial reconstructions of u0 on the source grid h0. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em n0} & Number of cells on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Cell widths on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Cell averages on source grid \\
\hline
\mbox{\texttt{ out}}  & {\em ppoly\+\_\+r\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ out}}  & {\em ppoly\+\_\+r\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ out}}  & {\em ppoly\+\_\+r\+\_\+s} & Edge slope of polynomial \\
\hline
\mbox{\texttt{ out}}  & {\em imethod} & Integration method \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h0. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 358 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{358   \textcolor{keywordtype}{type}(remapping\_CS),    \textcolor{keywordtype}{intent(in)}  :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{359   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}}
\DoxyCodeLine{360 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}}
\DoxyCodeLine{361 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}}
\DoxyCodeLine{362 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,CS\%degree+1)}, \&}
\DoxyCodeLine{363                          \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_coefs\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{364 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_E\textcolor{comment}{ !< Edge value of polynomial}}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_S\textcolor{comment}{ !< Edge slope of polynomial}}
\DoxyCodeLine{366   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(out)} :: iMethod\textcolor{comment}{ !< Integration method}}
\DoxyCodeLine{367 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},        \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{368 \textcolor{comment}{                                         !! purpose of cell reconstructions}}
\DoxyCodeLine{369 \textcolor{comment}{                                         !! in the same units as h0.}}
\DoxyCodeLine{370 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},        \textcolor{keywordtype}{intent(in)}  :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}}
\DoxyCodeLine{371 \textcolor{comment}{                                         !! for the purpose of edge value}}
\DoxyCodeLine{372 \textcolor{comment}{                                         !! calculations in the same units as h0.}}
\DoxyCodeLine{373   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{374   \textcolor{keywordtype}{integer} :: local\_remapping\_scheme}
\DoxyCodeLine{375   \textcolor{keywordtype}{integer} :: remapping\_scheme\textcolor{comment}{ !< Remapping scheme}}
\DoxyCodeLine{376   \textcolor{keywordtype}{logical} :: boundary\_extrapolation\textcolor{comment}{ !< Extrapolate at boundaries if true}}
\DoxyCodeLine{377 }
\DoxyCodeLine{378   \textcolor{comment}{! Reset polynomial}}
\DoxyCodeLine{379   ppoly\_r\_e(:,:) = 0.0}
\DoxyCodeLine{380   ppoly\_r\_s(:,:) = 0.0}
\DoxyCodeLine{381   ppoly\_r\_coefs(:,:) = 0.0}
\DoxyCodeLine{382   imethod = -999}
\DoxyCodeLine{383 }
\DoxyCodeLine{384   local\_remapping\_scheme = cs\%remapping\_scheme}
\DoxyCodeLine{385   \textcolor{keywordflow}{if} (n0<=1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{386     local\_remapping\_scheme = remapping\_pcm}
\DoxyCodeLine{387   \textcolor{keywordflow}{elseif} (n0<=3) \textcolor{keywordflow}{then}}
\DoxyCodeLine{388     local\_remapping\_scheme = min( local\_remapping\_scheme, remapping\_plm )}
\DoxyCodeLine{389   \textcolor{keywordflow}{elseif} (n0<=4) \textcolor{keywordflow}{then}}
\DoxyCodeLine{390     local\_remapping\_scheme = min( local\_remapping\_scheme, remapping\_ppm\_h4 )}
\DoxyCodeLine{391 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{392   \textcolor{keywordflow}{select case} ( local\_remapping\_scheme )}
\DoxyCodeLine{393     \textcolor{keywordflow}{case} ( remapping\_pcm )}
\DoxyCodeLine{394       \textcolor{keyword}{call }pcm\_reconstruction( n0, u0, ppoly\_r\_e, ppoly\_r\_coefs)}
\DoxyCodeLine{395       imethod = integration\_pcm}
\DoxyCodeLine{396     \textcolor{keywordflow}{case} ( remapping\_plm )}
\DoxyCodeLine{397       \textcolor{keyword}{call }plm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect )}
\DoxyCodeLine{398       \textcolor{keywordflow}{if} ( cs\%boundary\_extrapolation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{399         \textcolor{keyword}{call }plm\_boundary\_extrapolation( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect)}
\DoxyCodeLine{400 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{401       imethod = integration\_plm}
\DoxyCodeLine{402     \textcolor{keywordflow}{case} ( remapping\_ppm\_h4 )}
\DoxyCodeLine{403       \textcolor{keyword}{call }edge\_values\_explicit\_h4( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{404       \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{405       \textcolor{keywordflow}{if} ( cs\%boundary\_extrapolation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{406         \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect )}
\DoxyCodeLine{407 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{408       imethod = integration\_ppm}
\DoxyCodeLine{409     \textcolor{keywordflow}{case} ( remapping\_ppm\_ih4 )}
\DoxyCodeLine{410       \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{411       \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{412       \textcolor{keywordflow}{if} ( cs\%boundary\_extrapolation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{413         \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect )}
\DoxyCodeLine{414 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{415       imethod = integration\_ppm}
\DoxyCodeLine{416     \textcolor{keywordflow}{case} ( remapping\_pqm\_ih4ih3 )}
\DoxyCodeLine{417       \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{418       \textcolor{keyword}{call }edge\_slopes\_implicit\_h3( n0, h0, u0, ppoly\_r\_s, h\_neglect, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{419       \textcolor{keyword}{call }pqm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, ppoly\_r\_coefs, h\_neglect, \&}
\DoxyCodeLine{420                                answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{421       \textcolor{keywordflow}{if} ( cs\%boundary\_extrapolation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{422         \textcolor{keyword}{call }pqm\_boundary\_extrapolation\_v1( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, \&}
\DoxyCodeLine{423                                             ppoly\_r\_coefs, h\_neglect )}
\DoxyCodeLine{424 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{425       imethod = integration\_pqm}
\DoxyCodeLine{426     \textcolor{keywordflow}{case} ( remapping\_pqm\_ih6ih5 )}
\DoxyCodeLine{427       \textcolor{keyword}{call }edge\_values\_implicit\_h6( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{428       \textcolor{keyword}{call }edge\_slopes\_implicit\_h5( n0, h0, u0, ppoly\_r\_s, h\_neglect, answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{429       \textcolor{keyword}{call }pqm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, ppoly\_r\_coefs, h\_neglect, \&}
\DoxyCodeLine{430                                answers\_2018=cs\%answers\_2018 )}
\DoxyCodeLine{431       \textcolor{keywordflow}{if} ( cs\%boundary\_extrapolation ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{432         \textcolor{keyword}{call }pqm\_boundary\_extrapolation\_v1( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, \&}
\DoxyCodeLine{433                                             ppoly\_r\_coefs, h\_neglect )}
\DoxyCodeLine{434 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{435       imethod = integration\_pqm}
\DoxyCodeLine{436 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{437       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, build\_reconstructions\_1d: '}//\&}
\DoxyCodeLine{438            \textcolor{stringliteral}{'The selected remapping method is invalid'} )}
\DoxyCodeLine{439 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{440 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a80ed96a40bd7320cfe4213e1550365f0}\label{namespacemom__remapping_a80ed96a40bd7320cfe4213e1550365f0}} 
\index{mom\_remapping@{mom\_remapping}!buildgridfromh@{buildgridfromh}}
\index{buildgridfromh@{buildgridfromh}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{buildgridfromh()}{buildgridfromh()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::buildgridfromh (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nz,  }\item[{real, dimension(nz), intent(in)}]{h,  }\item[{real, dimension(nz+1), intent(inout)}]{x }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate edge coordinate x from cell width h. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nz} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Cell widths \\
\hline
\mbox{\texttt{ in,out}}  & {\em x} & Edge coordiantes starting at x(1)=0 \\
\hline
\end{DoxyParams}


Definition at line 142 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{142   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{143 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Cell widths}}
\DoxyCodeLine{144 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(inout)} :: x\textcolor{comment}{  !< Edge coordiantes starting at x(1)=0}}
\DoxyCodeLine{145   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{146   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{147 }
\DoxyCodeLine{148   x(1) = 0.0}
\DoxyCodeLine{149   \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{150     x(k+1) = x(k) + h(k)}
\DoxyCodeLine{151 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{152 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a1756ab9c7329e586ded97e7270b14d4d}\label{namespacemom__remapping_a1756ab9c7329e586ded97e7270b14d4d}} 
\index{mom\_remapping@{mom\_remapping}!check\_reconstructions\_1d@{check\_reconstructions\_1d}}
\index{check\_reconstructions\_1d@{check\_reconstructions\_1d}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{check\_reconstructions\_1d()}{check\_reconstructions\_1d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::check\+\_\+reconstructions\+\_\+1d (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{integer, intent(in)}]{deg,  }\item[{logical, intent(in)}]{boundary\+\_\+extrapolation,  }\item[{real, dimension(n0,deg+1), intent(out)}]{ppoly\+\_\+r\+\_\+coefs,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+E,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+S }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Checks that edge values and reconstructions satisfy bounds. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Cell widths on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Cell averages on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em deg} & Degree of polynomial reconstruction \\
\hline
\mbox{\texttt{ in}}  & {\em boundary\+\_\+extrapolation} & Extrapolate at boundaries if true \\
\hline
\mbox{\texttt{ out}}  & {\em ppoly\+\_\+r\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ out}}  & {\em ppoly\+\_\+r\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ out}}  & {\em ppoly\+\_\+r\+\_\+s} & Edge slope of polynomial \\
\hline
\end{DoxyParams}


Definition at line 446 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{446   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}}
\DoxyCodeLine{447 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)},      \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}}
\DoxyCodeLine{448 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)},      \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}}
\DoxyCodeLine{449   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}  :: deg\textcolor{comment}{ !< Degree of polynomial reconstruction}}
\DoxyCodeLine{450   \textcolor{keywordtype}{logical},                  \textcolor{keywordtype}{intent(in)}  :: boundary\_extrapolation\textcolor{comment}{ !< Extrapolate at boundaries if true}}
\DoxyCodeLine{451 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,deg+1)},\textcolor{keywordtype}{intent(out)} :: ppoly\_r\_coefs\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{452 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)},    \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_E\textcolor{comment}{ !< Edge value of polynomial}}
\DoxyCodeLine{453 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)},    \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_S\textcolor{comment}{ !< Edge slope of polynomial}}
\DoxyCodeLine{454   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{455   \textcolor{keywordtype}{integer} :: i0, n}
\DoxyCodeLine{456 \textcolor{keywordtype}{  real} :: u\_l, u\_c, u\_r \textcolor{comment}{! Cell averages}}
\DoxyCodeLine{457 \textcolor{keywordtype}{  real} :: u\_min, u\_max}
\DoxyCodeLine{458   \textcolor{keywordtype}{logical} :: problem\_detected}
\DoxyCodeLine{459 }
\DoxyCodeLine{460   problem\_detected = .false.}
\DoxyCodeLine{461   \textcolor{keywordflow}{do} i0 = 1, n0}
\DoxyCodeLine{462     u\_l = u0(max(1,i0-1))}
\DoxyCodeLine{463     u\_c = u0(i0)}
\DoxyCodeLine{464     u\_r = u0(min(n0,i0+1))}
\DoxyCodeLine{465     \textcolor{keywordflow}{if} (i0 > 1 .or. .not. boundary\_extrapolation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{466       u\_min = min(u\_l, u\_c)}
\DoxyCodeLine{467       u\_max = max(u\_l, u\_c)}
\DoxyCodeLine{468       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,1) < u\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{469         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Left edge undershoot at'},i0,\textcolor{stringliteral}{'u(i0-1)='},u\_l,\textcolor{stringliteral}{'u(i0)='},u\_c, \&}
\DoxyCodeLine{470                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,1),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,1)-u\_min}
\DoxyCodeLine{471         problem\_detected = .true.}
\DoxyCodeLine{472 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{473       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,1) > u\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{474         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Left edge overshoot at'},i0,\textcolor{stringliteral}{'u(i0-1)='},u\_l,\textcolor{stringliteral}{'u(i0)='},u\_c, \&}
\DoxyCodeLine{475                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,1),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,1)-u\_max}
\DoxyCodeLine{476         problem\_detected = .true.}
\DoxyCodeLine{477 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{478 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{479     \textcolor{keywordflow}{if} (i0 < n0 .or. .not. boundary\_extrapolation) \textcolor{keywordflow}{then}}
\DoxyCodeLine{480       u\_min = min(u\_c, u\_r)}
\DoxyCodeLine{481       u\_max = max(u\_c, u\_r)}
\DoxyCodeLine{482       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,2) < u\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Right edge undershoot at'},i0,\textcolor{stringliteral}{'u(i0)='},u\_c,\textcolor{stringliteral}{'u(i0+1)='},u\_r, \&}
\DoxyCodeLine{484                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,2),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,2)-u\_min}
\DoxyCodeLine{485         problem\_detected = .true.}
\DoxyCodeLine{486 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{487       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,2) > u\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{488         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Right edge overshoot at'},i0,\textcolor{stringliteral}{'u(i0)='},u\_c,\textcolor{stringliteral}{'u(i0+1)='},u\_r, \&}
\DoxyCodeLine{489                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,2),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,2)-u\_max}
\DoxyCodeLine{490         problem\_detected = .true.}
\DoxyCodeLine{491 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{492 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{493     \textcolor{keywordflow}{if} (i0 > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{494       \textcolor{keywordflow}{if} ( (u\_c-u\_l)*(ppoly\_r\_e(i0,1)-ppoly\_r\_e(i0-1,2)) < 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{495         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Non-monotonic edges at'},i0,\textcolor{stringliteral}{'u(i0-1)='},u\_l,\textcolor{stringliteral}{'u(i0)='},u\_c, \&}
\DoxyCodeLine{496                                           \textcolor{stringliteral}{'right edge='},ppoly\_r\_e(i0-1,2),\textcolor{stringliteral}{'left edge='},ppoly\_r\_e(i0,1)}
\DoxyCodeLine{497         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(5(a,1pe24.16,x))'}) \textcolor{stringliteral}{'u(i0)-u(i0-1)'},u\_c-u\_l,\textcolor{stringliteral}{'edge diff='},ppoly\_r\_e(i0,1)-ppoly\_r\_e(i0-1,2)}
\DoxyCodeLine{498         problem\_detected = .true.}
\DoxyCodeLine{499 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{500 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{501     \textcolor{keywordflow}{if} (problem\_detected) \textcolor{keywordflow}{then}}
\DoxyCodeLine{502       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,1p9e24.16)'}) \textcolor{stringliteral}{'Polynomial coeffs:'},ppoly\_r\_coefs(i0,:)}
\DoxyCodeLine{503       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(3(a,1pe24.16,x))'}) \textcolor{stringliteral}{'u\_l='},u\_l,\textcolor{stringliteral}{'u\_c='},u\_c,\textcolor{stringliteral}{'u\_r='},u\_r}
\DoxyCodeLine{504       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a4,10a24)'}) \textcolor{stringliteral}{'i0'},\textcolor{stringliteral}{'h0(i0)'},\textcolor{stringliteral}{'u0(i0)'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'Polynomial coefficients'}}
\DoxyCodeLine{505       \textcolor{keywordflow}{do} n = 1, n0}
\DoxyCodeLine{506         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i4,1p10e24.16)'}) n,h0(n),u0(n),ppoly\_r\_e(n,1),ppoly\_r\_e(n,2),ppoly\_r\_coefs(n,:)}
\DoxyCodeLine{507 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{508       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'MOM\_remapping, check\_reconstructions\_1d: '}// \&}
\DoxyCodeLine{509                    \textcolor{stringliteral}{'Edge values or polynomial coefficients were inconsistent!'})}
\DoxyCodeLine{510 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{511 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{512 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_ad1246e94fd3b411c2ea8ba675a52874b}\label{namespacemom__remapping_ad1246e94fd3b411c2ea8ba675a52874b}} 
\index{mom\_remapping@{mom\_remapping}!dumpgrid@{dumpgrid}}
\index{dumpgrid@{dumpgrid}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{dumpgrid()}{dumpgrid()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::dumpgrid (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n,  }\item[{real, dimension(\+:), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(in)}]{x,  }\item[{real, dimension(\+:), intent(in)}]{u }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Convenience function for printing grid to screen. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Cell thickness \\
\hline
\mbox{\texttt{ in}}  & {\em x} & Interface delta \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Cell average values \\
\hline
\end{DoxyParams}


Definition at line 1919 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1919   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{1920 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{ !< Cell thickness}}
\DoxyCodeLine{1921 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{ !< Interface delta}}
\DoxyCodeLine{1922 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: u\textcolor{comment}{ !< Cell average values}}
\DoxyCodeLine{1923   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{1924   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("i=",20i10)'}) (i,i=1,n+1)}
\DoxyCodeLine{1925   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("x=",20es10.2)'}) (x(i),i=1,n+1)}
\DoxyCodeLine{1926   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("i=",5x,20i10)'}) (i,i=1,n)}
\DoxyCodeLine{1927   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("h=",5x,20es10.2)'}) (h(i),i=1,n)}
\DoxyCodeLine{1928   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("u=",5x,20es10.2)'}) (u(i),i=1,n)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a494289c324db2496816f2687f4ceea76}\label{namespacemom__remapping_a494289c324db2496816f2687f4ceea76}} 
\index{mom\_remapping@{mom\_remapping}!dzfromh1h2@{dzfromh1h2}}
\index{dzfromh1h2@{dzfromh1h2}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{dzfromh1h2()}{dzfromh1h2()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::dzfromh1h2 (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(\+:), intent(in)}]{h1,  }\item[{integer, intent(in)}]{n2,  }\item[{real, dimension(\+:), intent(in)}]{h2,  }\item[{real, dimension(\+:), intent(out)}]{dx }\end{DoxyParamCaption})}



Calculates the change in interface positions based on h1 and h2. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n1} & Number of cells on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h1} & Cell widths of source grid (size n1) \\
\hline
\mbox{\texttt{ in}}  & {\em n2} & Number of cells on target grid \\
\hline
\mbox{\texttt{ in}}  & {\em h2} & Cell widths of target grid (size n2) \\
\hline
\mbox{\texttt{ out}}  & {\em dx} & Change in interface position (size n2+1) \\
\hline
\end{DoxyParams}


Definition at line 1526 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1526   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on source grid}}
\DoxyCodeLine{1527 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}  :: h1\textcolor{comment}{ !< Cell widths of source grid (size n1)}}
\DoxyCodeLine{1528   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}  :: n2\textcolor{comment}{ !< Number of cells on target grid}}
\DoxyCodeLine{1529 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}  :: h2\textcolor{comment}{ !< Cell widths of target grid (size n2)}}
\DoxyCodeLine{1530 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(out)} :: dx\textcolor{comment}{ !< Change in interface position (size n2+1)}}
\DoxyCodeLine{1531   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1532   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1533 \textcolor{keywordtype}{  real} :: x1, x2}
\DoxyCodeLine{1534 }
\DoxyCodeLine{1535   x1 = 0.}
\DoxyCodeLine{1536   x2 = 0.}
\DoxyCodeLine{1537   dx(1) = 0.}
\DoxyCodeLine{1538   \textcolor{keywordflow}{do} k = 1, max(n1,n2)}
\DoxyCodeLine{1539     \textcolor{keywordflow}{if} (k <= n1) x1 = x1 + h1(k) \textcolor{comment}{! Interface k+1, right of source cell k}}
\DoxyCodeLine{1540     \textcolor{keywordflow}{if} (k <= n2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1541       x2 = x2 + h2(k) \textcolor{comment}{! Interface k+1, right of target cell k}}
\DoxyCodeLine{1542       dx(k+1) = x2 - x1 \textcolor{comment}{! Change of interface k+1, target - source}}
\DoxyCodeLine{1543 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1544 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1545 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a10ca09dcc83f53137647ba51ba5deb72}\label{namespacemom__remapping_a10ca09dcc83f53137647ba51ba5deb72}} 
\index{mom\_remapping@{mom\_remapping}!end\_remapping@{end\_remapping}}
\index{end\_remapping@{end\_remapping}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{end\_remapping()}{end\_remapping()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::end\+\_\+remapping (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})}



Destrcutor for remapping control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 1607 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1607   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{1608 }
\DoxyCodeLine{1609   cs\%degree = 0}
\DoxyCodeLine{1610 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5777b80186106733e7a182694d708fba}\label{namespacemom__remapping_a5777b80186106733e7a182694d708fba}} 
\index{mom\_remapping@{mom\_remapping}!extract\_member\_remapping\_cs@{extract\_member\_remapping\_cs}}
\index{extract\_member\_remapping\_cs@{extract\_member\_remapping\_cs}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{extract\_member\_remapping\_cs()}{extract\_member\_remapping\_cs()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::extract\+\_\+member\+\_\+remapping\+\_\+cs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(out), optional}]{remapping\+\_\+scheme,  }\item[{integer, intent(out), optional}]{degree,  }\item[{logical, intent(out), optional}]{boundary\+\_\+extrapolation,  }\item[{logical, intent(out), optional}]{check\+\_\+reconstruction,  }\item[{logical, intent(out), optional}]{check\+\_\+remapping,  }\item[{logical, intent(out), optional}]{force\+\_\+bounds\+\_\+in\+\_\+subcell }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Control structure for remapping module\\
\hline
\mbox{\texttt{ out}}  & {\em remapping\+\_\+scheme} & Determines which reconstruction scheme to use\\
\hline
\mbox{\texttt{ out}}  & {\em degree} & Degree of polynomial reconstruction\\
\hline
\mbox{\texttt{ out}}  & {\em boundary\+\_\+extrapolation} & If true, extrapolate boundaries\\
\hline
\mbox{\texttt{ out}}  & {\em check\+\_\+reconstruction} & If true, reconstructions are checked for consistency.\\
\hline
\mbox{\texttt{ out}}  & {\em check\+\_\+remapping} & If true, the result of remapping are checked for conservation and bounds.\\
\hline
\mbox{\texttt{ out}}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & If true, the intermediate values used in remapping are forced to be bounded. \\
\hline
\end{DoxyParams}


Definition at line 122 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{122   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Control structure for remapping module}}
\DoxyCodeLine{123   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: remapping\_scheme\textcolor{comment}{        !< Determines which reconstruction scheme to use}}
\DoxyCodeLine{124   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: degree\textcolor{comment}{                  !< Degree of polynomial reconstruction}}
\DoxyCodeLine{125   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: boundary\_extrapolation\textcolor{comment}{  !< If true, extrapolate boundaries}}
\DoxyCodeLine{126   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: check\_reconstruction\textcolor{comment}{    !< If true, reconstructions are checked for consistency.}}
\DoxyCodeLine{127   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: check\_remapping\textcolor{comment}{         !< If true, the result of remapping are checked}}
\DoxyCodeLine{128 \textcolor{comment}{                                                            !!  for conservation and bounds.}}
\DoxyCodeLine{129   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: force\_bounds\_in\_subcell\textcolor{comment}{ !< If true, the intermediate values used in}}
\DoxyCodeLine{130 \textcolor{comment}{                                                            !! remapping are forced to be bounded.}}
\DoxyCodeLine{131 }
\DoxyCodeLine{132   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(remapping\_scheme)) remapping\_scheme = cs\%remapping\_scheme}
\DoxyCodeLine{133   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(degree)) degree = cs\%degree}
\DoxyCodeLine{134   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(boundary\_extrapolation)) boundary\_extrapolation = cs\%boundary\_extrapolation}
\DoxyCodeLine{135   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_reconstruction)) check\_reconstruction = cs\%check\_reconstruction}
\DoxyCodeLine{136   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_remapping)) check\_remapping = cs\%check\_remapping}
\DoxyCodeLine{137   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(force\_bounds\_in\_subcell)) force\_bounds\_in\_subcell = cs\%force\_bounds\_in\_subcell}
\DoxyCodeLine{138 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a81211827af45207130d25cae520b55e5}\label{namespacemom__remapping_a81211827af45207130d25cae520b55e5}} 
\index{mom\_remapping@{mom\_remapping}!initialize\_remapping@{initialize\_remapping}}
\index{initialize\_remapping@{initialize\_remapping}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{initialize\_remapping()}{initialize\_remapping()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::initialize\+\_\+remapping (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{remapping\+\_\+scheme,  }\item[{logical, intent(in), optional}]{boundary\+\_\+extrapolation,  }\item[{logical, intent(in), optional}]{check\+\_\+reconstruction,  }\item[{logical, intent(in), optional}]{check\+\_\+remapping,  }\item[{logical, intent(in), optional}]{force\+\_\+bounds\+\_\+in\+\_\+subcell,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Constructor for remapping control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em remapping\+\_\+scheme} & Remapping scheme to use \\
\hline
\mbox{\texttt{ in}}  & {\em boundary\+\_\+extrapolation} & Indicate to extrapolate in boundary cells \\
\hline
\mbox{\texttt{ in}}  & {\em check\+\_\+reconstruction} & Indicate to check reconstructions \\
\hline
\mbox{\texttt{ in}}  & {\em check\+\_\+remapping} & Indicate to check results of remapping \\
\hline
\mbox{\texttt{ in}}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & Force subcells values to be bounded \\
\hline
\mbox{\texttt{ in}}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 1551 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1551   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1552   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{1553   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: remapping\_scheme\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{1554   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: boundary\_extrapolation\textcolor{comment}{ !< Indicate to extrapolate in boundary cells}}
\DoxyCodeLine{1555   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: check\_reconstruction\textcolor{comment}{ !< Indicate to check reconstructions}}
\DoxyCodeLine{1556   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: check\_remapping\textcolor{comment}{ !< Indicate to check results of remapping}}
\DoxyCodeLine{1557   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: force\_bounds\_in\_subcell\textcolor{comment}{ !< Force subcells values to be bounded}}
\DoxyCodeLine{1558   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}}
\DoxyCodeLine{1559 }
\DoxyCodeLine{1560   \textcolor{comment}{! Note that remapping\_scheme is mandatory for initialize\_remapping()}}
\DoxyCodeLine{1561   \textcolor{keyword}{call }remapping\_set\_param(cs, remapping\_scheme=remapping\_scheme, boundary\_extrapolation=boundary\_extrapolation,  \&}
\DoxyCodeLine{1562                check\_reconstruction=check\_reconstruction, check\_remapping=check\_remapping, \&}
\DoxyCodeLine{1563                force\_bounds\_in\_subcell=force\_bounds\_in\_subcell, answers\_2018=answers\_2018)}
\DoxyCodeLine{1564 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a98e87df5ab2fcf8483894f95c4fde672}\label{namespacemom__remapping_a98e87df5ab2fcf8483894f95c4fde672}} 
\index{mom\_remapping@{mom\_remapping}!integraterecononinterval@{integraterecononinterval}}
\index{integraterecononinterval@{integraterecononinterval}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{integraterecononinterval()}{integraterecononinterval()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::integraterecononinterval (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{h0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{method,  }\item[{real, intent(in)}]{xL,  }\item[{real, intent(in)}]{xR,  }\item[{real, intent(in)}]{hC,  }\item[{real, intent(out)}]{u\+Ave,  }\item[{integer, intent(inout)}]{j\+Start,  }\item[{real, intent(inout)}]{x\+Start,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Integrate the reconstructed column profile over a single cell. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Source grid sizes (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Source cell averages \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Remapping scheme to use \\
\hline
\mbox{\texttt{ in}}  & {\em xl} & Left edges of target cell \\
\hline
\mbox{\texttt{ in}}  & {\em xr} & Right edges of target cell \\
\hline
\mbox{\texttt{ in}}  & {\em hc} & Cell width hC = xR -\/ xL \\
\hline
\mbox{\texttt{ out}}  & {\em uave} & Average value on target cell \\
\hline
\mbox{\texttt{ in,out}}  & {\em jstart} & The index of the cell to start searching from On exit, contains index of last cell used \\
\hline
\mbox{\texttt{ in,out}}  & {\em xstart} & The left edge position of cell j\+Start On first entry should be 0. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h. \\
\hline
\end{DoxyParams}


Definition at line 1227 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1227   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}}
\DoxyCodeLine{1228 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h0\textcolor{comment}{     !< Source grid sizes (size n0)}}
\DoxyCodeLine{1229 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u0\textcolor{comment}{     !< Source cell averages}}
\DoxyCodeLine{1230 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E\textcolor{comment}{ !< Edge value of polynomial}}
\DoxyCodeLine{1231 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{1232   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{1233 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}    :: xL\textcolor{comment}{     !< Left edges of target cell}}
\DoxyCodeLine{1234 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}    :: xR\textcolor{comment}{     !< Right edges of target cell}}
\DoxyCodeLine{1235 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)}    :: hC\textcolor{comment}{     !< Cell width hC = xR - xL}}
\DoxyCodeLine{1236 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(out)}   :: uAve\textcolor{comment}{   !< Average value on target cell}}
\DoxyCodeLine{1237   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(inout)} :: jStart\textcolor{comment}{ !< The index of the cell to start searching from}}
\DoxyCodeLine{1238 \textcolor{comment}{                                   !< On exit, contains index of last cell used}}
\DoxyCodeLine{1239 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(inout)} :: xStart\textcolor{comment}{ !< The left edge position of cell jStart}}
\DoxyCodeLine{1240 \textcolor{comment}{                                   !< On first entry should be 0.}}
\DoxyCodeLine{1241 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{1242 \textcolor{comment}{                                          !! purpose of cell reconstructions}}
\DoxyCodeLine{1243 \textcolor{comment}{                                          !! in the same units as h.}}
\DoxyCodeLine{1244   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1245   \textcolor{keywordtype}{integer} :: j, k}
\DoxyCodeLine{1246   \textcolor{keywordtype}{integer} :: jL, jR       \textcolor{comment}{! indexes of source cells containing target}}
\DoxyCodeLine{1247                           \textcolor{comment}{! cell edges}}
\DoxyCodeLine{1248 \textcolor{keywordtype}{  real}    :: q            \textcolor{comment}{! complete integration}}
\DoxyCodeLine{1249 \textcolor{keywordtype}{  real}    :: xi0, xi1     \textcolor{comment}{! interval of integration (local -- normalized}}
\DoxyCodeLine{1250                           \textcolor{comment}{! -- coordinates)}}
\DoxyCodeLine{1251 \textcolor{keywordtype}{  real}    :: x0jLl, x0jLr \textcolor{comment}{! Left/right position of cell jL}}
\DoxyCodeLine{1252 \textcolor{keywordtype}{  real}    :: x0jRl, x0jRr \textcolor{comment}{! Left/right position of cell jR}}
\DoxyCodeLine{1253 \textcolor{keywordtype}{  real}    :: hAct         \textcolor{comment}{! The distance actually used in the integration}}
\DoxyCodeLine{1254                           \textcolor{comment}{! (notionally xR - xL) which differs due to roundoff.}}
\DoxyCodeLine{1255 \textcolor{keywordtype}{  real}    :: x0\_2, x1\_2, x02px12, x0px1 \textcolor{comment}{! Used in evaluation of integrated polynomials}}
\DoxyCodeLine{1256 \textcolor{keywordtype}{  real}     :: hNeglect    \textcolor{comment}{! A negligible thicness in the same units as h.}}
\DoxyCodeLine{1257 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: r\_3 = 1.0/3.0 \textcolor{comment}{! Used in evaluation of integrated polynomials}}
\DoxyCodeLine{1258 }
\DoxyCodeLine{1259   hneglect = hneglect\_dflt ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect}
\DoxyCodeLine{1260 }
\DoxyCodeLine{1261   q = -1.e30}
\DoxyCodeLine{1262   x0jll = -1.e30}
\DoxyCodeLine{1263   x0jrl = -1.e30}
\DoxyCodeLine{1264 }
\DoxyCodeLine{1265   \textcolor{comment}{! Find the left most cell in source grid spanned by the target cell}}
\DoxyCodeLine{1266   jl = -1}
\DoxyCodeLine{1267   x0jlr = xstart}
\DoxyCodeLine{1268   \textcolor{keywordflow}{do} j = jstart, n0}
\DoxyCodeLine{1269     x0jll = x0jlr}
\DoxyCodeLine{1270     x0jlr = x0jll + h0(j)}
\DoxyCodeLine{1271     \textcolor{comment}{! Left edge is found in cell j}}
\DoxyCodeLine{1272     \textcolor{keywordflow}{if} ( ( xl >= x0jll ) .AND. ( xl <= x0jlr ) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1273       jl = j}
\DoxyCodeLine{1274       \textcolor{keywordflow}{exit} \textcolor{comment}{! once target grid cell is found, exit loop}}
\DoxyCodeLine{1275 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1276 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1277   jstart = jl}
\DoxyCodeLine{1278   xstart = x0jll}
\DoxyCodeLine{1279 }
\DoxyCodeLine{1280 \textcolor{comment}{! ! HACK to handle round-off problems. Need only at  j=n0.}}
\DoxyCodeLine{1281 \textcolor{comment}{! ! This moves the effective cell boundary outwards a smidgen.}}
\DoxyCodeLine{1282 \textcolor{comment}{! if (xL>x0jLr) x0jLr = xL}}
\DoxyCodeLine{1283 }
\DoxyCodeLine{1284   \textcolor{comment}{! If, at this point, jL is equal to -1, it means the vanished}}
\DoxyCodeLine{1285   \textcolor{comment}{! cell lies outside the source grid. In other words, it means that}}
\DoxyCodeLine{1286   \textcolor{comment}{! the source and target grids do not cover the same physical domain}}
\DoxyCodeLine{1287   \textcolor{comment}{! and there is something very wrong !}}
\DoxyCodeLine{1288   \textcolor{keywordflow}{if} ( jl == -1 ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{1289           \textcolor{stringliteral}{'MOM\_remapping, integrateReconOnInterval: '}//\&}
\DoxyCodeLine{1290           \textcolor{stringliteral}{'The location of the left-most cell could not be found'})}
\DoxyCodeLine{1291 }
\DoxyCodeLine{1292 }
\DoxyCodeLine{1293   \textcolor{comment}{! ============================================================}}
\DoxyCodeLine{1294   \textcolor{comment}{! Check whether target cell is vanished. If it is, the cell}}
\DoxyCodeLine{1295   \textcolor{comment}{! average is simply the interpolated value at the location}}
\DoxyCodeLine{1296   \textcolor{comment}{! of the vanished cell. If it isn't, we need to integrate the}}
\DoxyCodeLine{1297   \textcolor{comment}{! quantity within the cell and divide by the cell width to}}
\DoxyCodeLine{1298   \textcolor{comment}{! determine the cell average.}}
\DoxyCodeLine{1299   \textcolor{comment}{! ============================================================}}
\DoxyCodeLine{1300   \textcolor{comment}{! 1. Cell is vanished}}
\DoxyCodeLine{1301  \textcolor{comment}{!if ( abs(xR - xL) <= epsilon(xR)*max(abs(xR),abs(xL)) ) then}}
\DoxyCodeLine{1302   \textcolor{keywordflow}{if} ( abs(xr - xl) == 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1303 }
\DoxyCodeLine{1304     \textcolor{comment}{! We check whether the source cell (i.e. the cell in which the}}
\DoxyCodeLine{1305     \textcolor{comment}{! vanished target cell lies) is vanished. If it is, the interpolated}}
\DoxyCodeLine{1306     \textcolor{comment}{! value is set to be mean of the edge values (which should be the same).}}
\DoxyCodeLine{1307     \textcolor{comment}{! If it isn't, we simply interpolate.}}
\DoxyCodeLine{1308     \textcolor{keywordflow}{if} ( h0(jl) == 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1309       uave = 0.5 * ( ppoly0\_e(jl,1) + ppoly0\_e(jl,2) )}
\DoxyCodeLine{1310     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1311       \textcolor{comment}{! WHY IS THIS NOT WRITTEN AS xi0 = ( xL - x0jLl ) / h0(jL) ---AJA}}
\DoxyCodeLine{1312       xi0 = xl / ( h0(jl) + hneglect ) - x0jll / ( h0(jl) + hneglect )}
\DoxyCodeLine{1313 }
\DoxyCodeLine{1314       \textcolor{keywordflow}{select case} ( method )}
\DoxyCodeLine{1315         \textcolor{keywordflow}{case} ( integration\_pcm )}
\DoxyCodeLine{1316           uave =         ppoly0\_coefs(jl,1)}
\DoxyCodeLine{1317         \textcolor{keywordflow}{case} ( integration\_plm )}
\DoxyCodeLine{1318           uave =         ppoly0\_coefs(jl,1)   \&}
\DoxyCodeLine{1319                + xi0 *   ppoly0\_coefs(jl,2)}
\DoxyCodeLine{1320         \textcolor{keywordflow}{case} ( integration\_ppm )}
\DoxyCodeLine{1321           uave =         ppoly0\_coefs(jl,1)   \&}
\DoxyCodeLine{1322                + xi0 * ( ppoly0\_coefs(jl,2)   \&}
\DoxyCodeLine{1323                + xi0 *   ppoly0\_coefs(jl,3) )}
\DoxyCodeLine{1324         \textcolor{keywordflow}{case} ( integration\_pqm )}
\DoxyCodeLine{1325           uave =         ppoly0\_coefs(jl,1)   \&}
\DoxyCodeLine{1326                + xi0 * ( ppoly0\_coefs(jl,2)   \&}
\DoxyCodeLine{1327                + xi0 * ( ppoly0\_coefs(jl,3)   \&}
\DoxyCodeLine{1328                + xi0 * ( ppoly0\_coefs(jl,4)   \&}
\DoxyCodeLine{1329                + xi0 *   ppoly0\_coefs(jl,5) ) ) )}
\DoxyCodeLine{1330 \textcolor{keywordflow}{        case default}}
\DoxyCodeLine{1331           \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )}
\DoxyCodeLine{1332 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{1333 }
\DoxyCodeLine{1334 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end checking whether source cell is vanished}}
\DoxyCodeLine{1335 }
\DoxyCodeLine{1336   \textcolor{comment}{! 2. Cell is not vanished}}
\DoxyCodeLine{1337   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1338 }
\DoxyCodeLine{1339     \textcolor{comment}{! Find the right most cell in source grid spanned by the target cell}}
\DoxyCodeLine{1340     jr = -1}
\DoxyCodeLine{1341     x0jrr = xstart}
\DoxyCodeLine{1342     \textcolor{keywordflow}{do} j = jstart,n0}
\DoxyCodeLine{1343       x0jrl = x0jrr}
\DoxyCodeLine{1344       x0jrr = x0jrl + h0(j)}
\DoxyCodeLine{1345       \textcolor{comment}{! Right edge is found in cell j}}
\DoxyCodeLine{1346       \textcolor{keywordflow}{if} ( ( xr >= x0jrl ) .AND. ( xr <= x0jrr ) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1347         jr = j}
\DoxyCodeLine{1348         \textcolor{keywordflow}{exit}  \textcolor{comment}{! once target grid cell is found, exit loop}}
\DoxyCodeLine{1349 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1350 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end loop on source grid cells}}
\DoxyCodeLine{1351 }
\DoxyCodeLine{1352     \textcolor{comment}{! If xR>x0jRr then the previous loop reached j=n0 and the target}}
\DoxyCodeLine{1353     \textcolor{comment}{! position, xR, was beyond the right edge of the source grid (h0).}}
\DoxyCodeLine{1354     \textcolor{comment}{! This can happen due to roundoff, in which case we set jR=n0.}}
\DoxyCodeLine{1355     \textcolor{keywordflow}{if} (xr>x0jrr) jr = n0}
\DoxyCodeLine{1356 }
\DoxyCodeLine{1357     \textcolor{comment}{! To integrate, two cases must be considered: (1) the target cell is}}
\DoxyCodeLine{1358     \textcolor{comment}{! entirely contained within a cell of the source grid and (2) the target}}
\DoxyCodeLine{1359     \textcolor{comment}{! cell spans at least two cells of the source grid.}}
\DoxyCodeLine{1360 }
\DoxyCodeLine{1361     \textcolor{keywordflow}{if} ( jl == jr ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1362       \textcolor{comment}{! The target cell is entirely contained within a cell of the source}}
\DoxyCodeLine{1363       \textcolor{comment}{! grid. This situation is represented by the following schematic, where}}
\DoxyCodeLine{1364       \textcolor{comment}{! the cell in which xL and xR are located has index jL=jR :}}
\DoxyCodeLine{1365       \textcolor{comment}{!}}
\DoxyCodeLine{1366       \textcolor{comment}{! ----|-----o--------o----------|-------------}}
\DoxyCodeLine{1367       \textcolor{comment}{!           xL       xR}}
\DoxyCodeLine{1368       \textcolor{comment}{!}}
\DoxyCodeLine{1369       \textcolor{comment}{! Determine normalized coordinates}}
\DoxyCodeLine{1370 \textcolor{preprocessor}{\#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}}
\DoxyCodeLine{1371 \textcolor{preprocessor}{}      xi0 = max( 0., min( 1., ( xl - x0jll ) / ( h0(jl) + hneglect ) ) )}
\DoxyCodeLine{1372       xi1 = max( 0., min( 1., ( xr - x0jll ) / ( h0(jl) + hneglect ) ) )}
\DoxyCodeLine{1373 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{1374 \textcolor{preprocessor}{}      xi0 = xl / h0(jl) - x0jll / ( h0(jl) + hneglect )}
\DoxyCodeLine{1375       xi1 = xr / h0(jl) - x0jll / ( h0(jl) + hneglect )}
\DoxyCodeLine{1376 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1377 \textcolor{preprocessor}{}}
\DoxyCodeLine{1378       hact = h0(jl) * ( xi1 - xi0 )}
\DoxyCodeLine{1379 }
\DoxyCodeLine{1380       \textcolor{comment}{! Depending on which polynomial is used, integrate quantity}}
\DoxyCodeLine{1381       \textcolor{comment}{! between xi0 and xi1. Integration is carried out in normalized}}
\DoxyCodeLine{1382       \textcolor{comment}{! coordinates, hence: \(\backslash\)int\_xL\string^xR p(x) dx = h \(\backslash\)int\_xi0\string^xi1 p(xi) dxi}}
\DoxyCodeLine{1383       \textcolor{keywordflow}{select case} ( method )}
\DoxyCodeLine{1384         \textcolor{keywordflow}{case} ( integration\_pcm )}
\DoxyCodeLine{1385           q = ( xr - xl ) * ppoly0\_coefs(jl,1)}
\DoxyCodeLine{1386         \textcolor{keywordflow}{case} ( integration\_plm )}
\DoxyCodeLine{1387           q = ( xr - xl ) * (                            \&}
\DoxyCodeLine{1388               ppoly0\_coefs(jl,1)                         \&}
\DoxyCodeLine{1389             + ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) )}
\DoxyCodeLine{1390         \textcolor{keywordflow}{case} ( integration\_ppm )}
\DoxyCodeLine{1391           q = ( xr - xl ) * (                            \&}
\DoxyCodeLine{1392                 ppoly0\_coefs(jl,1)                       \&}
\DoxyCodeLine{1393             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) \&}
\DoxyCodeLine{1394             +   ppoly0\_coefs(jl,3) * r\_3 * ( ( xi1*xi1 + xi0*xi0 ) + xi0*xi1 ) ) )}
\DoxyCodeLine{1395         \textcolor{keywordflow}{case} ( integration\_pqm )}
\DoxyCodeLine{1396           x0\_2 = xi0*xi0}
\DoxyCodeLine{1397           x1\_2 = xi1*xi1}
\DoxyCodeLine{1398           x02px12 = x0\_2 + x1\_2}
\DoxyCodeLine{1399           x0px1 = xi1 + xi0}
\DoxyCodeLine{1400           q = ( xr - xl ) * (                                    \&}
\DoxyCodeLine{1401                 ppoly0\_coefs(jl,1)                               \&}
\DoxyCodeLine{1402             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 )         \&}
\DoxyCodeLine{1403             + ( ppoly0\_coefs(jl,3) * r\_3 * ( x02px12 + xi0*xi1 ) \&}
\DoxyCodeLine{1404             +   ppoly0\_coefs(jl,4) * 0.25* ( x02px12 * x0px1 )   \&}
\DoxyCodeLine{1405             +   ppoly0\_coefs(jl,5) * 0.2 * ( ( xi1*x1\_2 + xi0*x0\_2 ) * x0px1 + x0\_2*x1\_2 ) ) ) )}
\DoxyCodeLine{1406 \textcolor{keywordflow}{        case default}}
\DoxyCodeLine{1407           \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )}
\DoxyCodeLine{1408 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{1409 }
\DoxyCodeLine{1410     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1411     \textcolor{comment}{! The target cell spans at least two cells of the source grid.}}
\DoxyCodeLine{1412     \textcolor{comment}{! This situation is represented by the following schematic, where}}
\DoxyCodeLine{1413     \textcolor{comment}{! the cells in which xL and xR are located have indexes jL and jR,}}
\DoxyCodeLine{1414     \textcolor{comment}{! respectively :}}
\DoxyCodeLine{1415     \textcolor{comment}{!}}
\DoxyCodeLine{1416     \textcolor{comment}{! ----|-----o---|--- ... --|---o----------|-------------}}
\DoxyCodeLine{1417     \textcolor{comment}{!           xL                 xR}}
\DoxyCodeLine{1418     \textcolor{comment}{!}}
\DoxyCodeLine{1419     \textcolor{comment}{! We first integrate from xL up to the right boundary of cell jL, then}}
\DoxyCodeLine{1420     \textcolor{comment}{! add the integrated amounts of cells located between jL and jR and then}}
\DoxyCodeLine{1421     \textcolor{comment}{! integrate from the left boundary of cell jR up to xR}}
\DoxyCodeLine{1422 }
\DoxyCodeLine{1423       q = 0.0}
\DoxyCodeLine{1424 }
\DoxyCodeLine{1425       \textcolor{comment}{! Integrate from xL up to right boundary of cell jL}}
\DoxyCodeLine{1426 \textcolor{preprocessor}{\#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}}
\DoxyCodeLine{1427 \textcolor{preprocessor}{}      xi0 = max( 0., min( 1., ( xl - x0jll ) / ( h0(jl) + hneglect ) ) )}
\DoxyCodeLine{1428 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{1429 \textcolor{preprocessor}{}      xi0 = (xl - x0jll) / ( h0(jl) + hneglect )}
\DoxyCodeLine{1430 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1431 \textcolor{preprocessor}{}      xi1 = 1.0}
\DoxyCodeLine{1432 }
\DoxyCodeLine{1433       hact = h0(jl) * ( xi1 - xi0 )}
\DoxyCodeLine{1434 }
\DoxyCodeLine{1435       \textcolor{keywordflow}{select case} ( method )}
\DoxyCodeLine{1436         \textcolor{keywordflow}{case} ( integration\_pcm )}
\DoxyCodeLine{1437           q = q + ( x0jlr - xl ) * ppoly0\_coefs(jl,1)}
\DoxyCodeLine{1438         \textcolor{keywordflow}{case} ( integration\_plm )}
\DoxyCodeLine{1439           q = q + ( x0jlr - xl ) * (                     \&}
\DoxyCodeLine{1440               ppoly0\_coefs(jl,1)                         \&}
\DoxyCodeLine{1441             + ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) )}
\DoxyCodeLine{1442         \textcolor{keywordflow}{case} ( integration\_ppm )}
\DoxyCodeLine{1443           q = q + ( x0jlr - xl ) * (                     \&}
\DoxyCodeLine{1444                 ppoly0\_coefs(jl,1)                       \&}
\DoxyCodeLine{1445             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) \&}
\DoxyCodeLine{1446             +   ppoly0\_coefs(jl,3) * r\_3 * ( ( xi1*xi1 + xi0*xi0 ) + xi0*xi1 ) ) )}
\DoxyCodeLine{1447         \textcolor{keywordflow}{case} ( integration\_pqm )}
\DoxyCodeLine{1448           x0\_2 = xi0*xi0}
\DoxyCodeLine{1449           x1\_2 = xi1*xi1}
\DoxyCodeLine{1450           x02px12 = x0\_2 + x1\_2}
\DoxyCodeLine{1451           x0px1 = xi1 + xi0}
\DoxyCodeLine{1452           q = q + ( x0jlr - xl ) * (                             \&}
\DoxyCodeLine{1453                 ppoly0\_coefs(jl,1)                               \&}
\DoxyCodeLine{1454             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 )         \&}
\DoxyCodeLine{1455             + ( ppoly0\_coefs(jl,3) * r\_3 * ( x02px12 + xi0*xi1 ) \&}
\DoxyCodeLine{1456             +   ppoly0\_coefs(jl,4) * 0.25* ( x02px12 * x0px1 )   \&}
\DoxyCodeLine{1457             +   ppoly0\_coefs(jl,5) * 0.2 * ( ( xi1*x1\_2 + xi0*x0\_2 ) * x0px1 + x0\_2*x1\_2 ) ) ) )}
\DoxyCodeLine{1458 \textcolor{keywordflow}{        case default}}
\DoxyCodeLine{1459           \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'The selected integration method is invalid'} )}
\DoxyCodeLine{1460 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{1461 }
\DoxyCodeLine{1462       \textcolor{comment}{! Integrate contents within cells strictly comprised between jL and jR}}
\DoxyCodeLine{1463       \textcolor{keywordflow}{if} ( jr > (jl+1) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1464         \textcolor{keywordflow}{do} k = jl+1,jr-1}
\DoxyCodeLine{1465           q = q + h0(k) * u0(k)}
\DoxyCodeLine{1466           hact = hact + h0(k)}
\DoxyCodeLine{1467 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1468 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1469 }
\DoxyCodeLine{1470       \textcolor{comment}{! Integrate from left boundary of cell jR up to xR}}
\DoxyCodeLine{1471       xi0 = 0.0}
\DoxyCodeLine{1472 \textcolor{preprocessor}{\#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}}
\DoxyCodeLine{1473 \textcolor{preprocessor}{}      xi1 = max( 0., min( 1., ( xr - x0jrl ) / ( h0(jr) + hneglect ) ) )}
\DoxyCodeLine{1474 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{1475 \textcolor{preprocessor}{}      xi1 = (xr - x0jrl) / ( h0(jr) + hneglect )}
\DoxyCodeLine{1476 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1477 \textcolor{preprocessor}{}}
\DoxyCodeLine{1478       hact = hact + h0(jr) * ( xi1 - xi0 )}
\DoxyCodeLine{1479 }
\DoxyCodeLine{1480       \textcolor{keywordflow}{select case} ( method )}
\DoxyCodeLine{1481         \textcolor{keywordflow}{case} ( integration\_pcm )}
\DoxyCodeLine{1482           q = q + ( xr - x0jrl ) * ppoly0\_coefs(jr,1)}
\DoxyCodeLine{1483         \textcolor{keywordflow}{case} ( integration\_plm )}
\DoxyCodeLine{1484           q = q + ( xr - x0jrl ) * (                     \&}
\DoxyCodeLine{1485               ppoly0\_coefs(jr,1)                         \&}
\DoxyCodeLine{1486             + ppoly0\_coefs(jr,2) * 0.5 * ( xi1 + xi0 ) )}
\DoxyCodeLine{1487         \textcolor{keywordflow}{case} ( integration\_ppm )}
\DoxyCodeLine{1488           q = q + ( xr - x0jrl ) * (                     \&}
\DoxyCodeLine{1489                 ppoly0\_coefs(jr,1)                       \&}
\DoxyCodeLine{1490             + ( ppoly0\_coefs(jr,2) * 0.5 * ( xi1 + xi0 ) \&}
\DoxyCodeLine{1491             +   ppoly0\_coefs(jr,3) * r\_3 * ( ( xi1*xi1 + xi0*xi0 ) + xi0*xi1 ) ) )}
\DoxyCodeLine{1492         \textcolor{keywordflow}{case} ( integration\_pqm )}
\DoxyCodeLine{1493           x0\_2 = xi0*xi0}
\DoxyCodeLine{1494           x1\_2 = xi1*xi1}
\DoxyCodeLine{1495           x02px12 = x0\_2 + x1\_2}
\DoxyCodeLine{1496           x0px1 = xi1 + xi0}
\DoxyCodeLine{1497           q = q + ( xr - x0jrl ) * (                             \&}
\DoxyCodeLine{1498                 ppoly0\_coefs(jr,1)                               \&}
\DoxyCodeLine{1499             + ( ppoly0\_coefs(jr,2) * 0.5 * ( xi1 + xi0 )         \&}
\DoxyCodeLine{1500             + ( ppoly0\_coefs(jr,3) * r\_3 * ( x02px12 + xi0*xi1 ) \&}
\DoxyCodeLine{1501             +   ppoly0\_coefs(jr,4) * 0.25* ( x02px12 * x0px1 )   \&}
\DoxyCodeLine{1502             +   ppoly0\_coefs(jr,5) * 0.2 * ( ( xi1*x1\_2 + xi0*x0\_2 ) * x0px1 + x0\_2*x1\_2 ) ) ) )}
\DoxyCodeLine{1503 \textcolor{keywordflow}{        case default}}
\DoxyCodeLine{1504           \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )}
\DoxyCodeLine{1505 \textcolor{keywordflow}{      end select}}
\DoxyCodeLine{1506 }
\DoxyCodeLine{1507 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end integration for non-vanished cells}}
\DoxyCodeLine{1508 }
\DoxyCodeLine{1509     \textcolor{comment}{! The cell average is the integrated value divided by the cell width}}
\DoxyCodeLine{1510 \textcolor{preprocessor}{\#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}}
\DoxyCodeLine{1511 \textcolor{preprocessor}{}\textcolor{keywordflow}{if} (hact==0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1512     uave = ppoly0\_coefs(jl,1)}
\DoxyCodeLine{1513 \textcolor{keywordflow}{else}}
\DoxyCodeLine{1514     uave = q / hact}
\DoxyCodeLine{1515 \textcolor{keywordflow}{endif}}
\DoxyCodeLine{1516 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{1517 \textcolor{preprocessor}{}    uave = q / hc}
\DoxyCodeLine{1518 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1519 \textcolor{preprocessor}{}}
\DoxyCodeLine{1520 \textcolor{keywordflow}{  endif} \textcolor{comment}{! endif clause to check if cell is vanished}}
\DoxyCodeLine{1521 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_accd6922c5eb61fa77c11869d8b219f7c}\label{namespacemom__remapping_accd6922c5eb61fa77c11869d8b219f7c}} 
\index{mom\_remapping@{mom\_remapping}!ispossumerrsignificant@{ispossumerrsignificant}}
\index{ispossumerrsignificant@{ispossumerrsignificant}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{ispossumerrsignificant()}{ispossumerrsignificant()}}
{\footnotesize\ttfamily logical function mom\+\_\+remapping\+::ispossumerrsignificant (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n1,  }\item[{real, intent(in)}]{sum1,  }\item[{integer, intent(in)}]{n2,  }\item[{real, intent(in)}]{sum2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Compare two summation estimates of positive data and judge if due to more than round-\/off. When two sums are calculated from different vectors that should add up to the same value, the results can differ by round off. The round off error can be bounded to be proportional to the number of operations. This function returns true if the difference between sum1 and sum2 is larger than than the estimated round off bound. 

\begin{DoxyNote}{Note}
This estimate/function is only valid for summation of positive data. 
\end{DoxyNote}

\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n1} & Number of values in sum1 \\
\hline
\mbox{\texttt{ in}}  & {\em n2} & Number of values in sum2 \\
\hline
\mbox{\texttt{ in}}  & {\em sum1} & Sum of n1 values \\
\hline
\mbox{\texttt{ in}}  & {\em sum2} & Sum of n2 values \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if difference in sums is large 
\end{DoxyReturn}


Definition at line 164 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{164   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n1\textcolor{comment}{   !< Number of values in sum1}}
\DoxyCodeLine{165   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n2\textcolor{comment}{   !< Number of values in sum2}}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: sum1\textcolor{comment}{ !< Sum of n1 values}}
\DoxyCodeLine{167 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: sum2\textcolor{comment}{ !< Sum of n2 values}}
\DoxyCodeLine{168   \textcolor{keywordtype}{logical}             :: isPosSumErrSignificant\textcolor{comment}{ !< True if difference in sums is large}}
\DoxyCodeLine{169   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{170 \textcolor{keywordtype}{  real} :: sumErr, allowedErr, eps}
\DoxyCodeLine{171 }
\DoxyCodeLine{172   \textcolor{keywordflow}{if} (sum1<0.) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'isPosSumErrSignificant: sum1<0 is not allowed!'})}
\DoxyCodeLine{173   \textcolor{keywordflow}{if} (sum2<0.) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'isPosSumErrSignificant: sum2<0 is not allowed!'})}
\DoxyCodeLine{174   sumerr = abs(sum1-sum2)}
\DoxyCodeLine{175   eps = epsilon(sum1)}
\DoxyCodeLine{176   allowederr = eps*0.5*(real(n1-1)*sum1+real(n2-1)*sum2)}
\DoxyCodeLine{177   \textcolor{keywordflow}{if} (sumerr>allowederr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{178     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: sum1,sum2='},sum1,sum2}
\DoxyCodeLine{179     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: eps='},eps}
\DoxyCodeLine{180     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: err,n*eps='},sumerr,allowederr}
\DoxyCodeLine{181     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: err/eps,n1,n2,n1+n2='},sumerr/eps,n1,n2,n1+n2}
\DoxyCodeLine{182     ispossumerrsignificant = .true.}
\DoxyCodeLine{183   \textcolor{keywordflow}{else}}
\DoxyCodeLine{184     ispossumerrsignificant = .false.}
\DoxyCodeLine{185 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a0b392b7cbac49fc8ab52b2830e3a9306}\label{namespacemom__remapping_a0b392b7cbac49fc8ab52b2830e3a9306}} 
\index{mom\_remapping@{mom\_remapping}!measure\_input\_bounds@{measure\_input\_bounds}}
\index{measure\_input\_bounds@{measure\_input\_bounds}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{measure\_input\_bounds()}{measure\_input\_bounds()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::measure\+\_\+input\+\_\+bounds (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{real, dimension(n0,2), intent(in)}]{edge\+\_\+values,  }\item[{real, intent(out)}]{h0tot,  }\item[{real, intent(out)}]{h0err,  }\item[{real, intent(out)}]{u0tot,  }\item[{real, intent(out)}]{u0err,  }\item[{real, intent(out)}]{u0min,  }\item[{real, intent(out)}]{u0max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Measure totals and bounds on source grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Cell widths on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Cell averages on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em edge\+\_\+values} & Cell edge values on source grid \\
\hline
\mbox{\texttt{ out}}  & {\em h0tot} & Sum of cell widths \\
\hline
\mbox{\texttt{ out}}  & {\em h0err} & Magnitude of round-\/off error in h0tot \\
\hline
\mbox{\texttt{ out}}  & {\em u0tot} & Sum of cell widths times values \\
\hline
\mbox{\texttt{ out}}  & {\em u0err} & Magnitude of round-\/off error in u0tot \\
\hline
\mbox{\texttt{ out}}  & {\em u0min} & Minimum value in reconstructions of u0 \\
\hline
\mbox{\texttt{ out}}  & {\em u0max} & Maximum value in reconstructions of u0 \\
\hline
\end{DoxyParams}


Definition at line 1031 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1031   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}}
\DoxyCodeLine{1032 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}}
\DoxyCodeLine{1033 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}}
\DoxyCodeLine{1034 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(in)}  :: edge\_values\textcolor{comment}{ !< Cell edge values on source grid}}
\DoxyCodeLine{1035 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: h0tot\textcolor{comment}{ !< Sum of cell widths}}
\DoxyCodeLine{1036 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: h0err\textcolor{comment}{ !< Magnitude of round-off error in h0tot}}
\DoxyCodeLine{1037 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u0tot\textcolor{comment}{ !< Sum of cell widths times values}}
\DoxyCodeLine{1038 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u0err\textcolor{comment}{ !< Magnitude of round-off error in u0tot}}
\DoxyCodeLine{1039 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u0min\textcolor{comment}{ !< Minimum value in reconstructions of u0}}
\DoxyCodeLine{1040 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u0max\textcolor{comment}{ !< Maximum value in reconstructions of u0}}
\DoxyCodeLine{1041   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1042   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1043 \textcolor{keywordtype}{  real} :: eps}
\DoxyCodeLine{1044 }
\DoxyCodeLine{1045   eps = epsilon(h0(1))}
\DoxyCodeLine{1046   h0tot = h0(1)}
\DoxyCodeLine{1047   h0err = 0.}
\DoxyCodeLine{1048   u0tot = h0(1) * u0(1)}
\DoxyCodeLine{1049   u0err = 0.}
\DoxyCodeLine{1050   u0min = min( edge\_values(1,1), edge\_values(1,2) )}
\DoxyCodeLine{1051   u0max = max( edge\_values(1,1), edge\_values(1,2) )}
\DoxyCodeLine{1052   \textcolor{keywordflow}{do} k = 2, n0}
\DoxyCodeLine{1053     h0tot = h0tot + h0(k)}
\DoxyCodeLine{1054     h0err = h0err + eps * max(h0tot, h0(k))}
\DoxyCodeLine{1055     u0tot = u0tot + h0(k) * u0(k)}
\DoxyCodeLine{1056     u0err = u0err + eps * max(abs(u0tot), abs(h0(k) * u0(k)))}
\DoxyCodeLine{1057     u0min = min( u0min, edge\_values(k,1), edge\_values(k,2) )}
\DoxyCodeLine{1058     u0max = max( u0max, edge\_values(k,1), edge\_values(k,2) )}
\DoxyCodeLine{1059 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1060 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5453aeefe69feaff159b67f3a4bd2366}\label{namespacemom__remapping_a5453aeefe69feaff159b67f3a4bd2366}} 
\index{mom\_remapping@{mom\_remapping}!measure\_output\_bounds@{measure\_output\_bounds}}
\index{measure\_output\_bounds@{measure\_output\_bounds}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{measure\_output\_bounds()}{measure\_output\_bounds()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::measure\+\_\+output\+\_\+bounds (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(in)}]{h1,  }\item[{real, dimension(n1), intent(in)}]{u1,  }\item[{real, intent(out)}]{h1tot,  }\item[{real, intent(out)}]{h1err,  }\item[{real, intent(out)}]{u1tot,  }\item[{real, intent(out)}]{u1err,  }\item[{real, intent(out)}]{u1min,  }\item[{real, intent(out)}]{u1max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Measure totals and bounds on destination grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n1} & Number of cells on destination grid \\
\hline
\mbox{\texttt{ in}}  & {\em h1} & Cell widths on destination grid \\
\hline
\mbox{\texttt{ in}}  & {\em u1} & Cell averages on destination grid \\
\hline
\mbox{\texttt{ out}}  & {\em h1tot} & Sum of cell widths \\
\hline
\mbox{\texttt{ out}}  & {\em h1err} & Magnitude of round-\/off error in h1tot \\
\hline
\mbox{\texttt{ out}}  & {\em u1tot} & Sum of cell widths times values \\
\hline
\mbox{\texttt{ out}}  & {\em u1err} & Magnitude of round-\/off error in u1tot \\
\hline
\mbox{\texttt{ out}}  & {\em u1min} & Minimum value in reconstructions of u1 \\
\hline
\mbox{\texttt{ out}}  & {\em u1max} & Maximum value in reconstructions of u1 \\
\hline
\end{DoxyParams}


Definition at line 1065 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1065   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on destination grid}}
\DoxyCodeLine{1066 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1)},   \textcolor{keywordtype}{intent(in)}  :: h1\textcolor{comment}{ !< Cell widths on destination grid}}
\DoxyCodeLine{1067 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1)},   \textcolor{keywordtype}{intent(in)}  :: u1\textcolor{comment}{ !< Cell averages on destination grid}}
\DoxyCodeLine{1068 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: h1tot\textcolor{comment}{ !< Sum of cell widths}}
\DoxyCodeLine{1069 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: h1err\textcolor{comment}{ !< Magnitude of round-off error in h1tot}}
\DoxyCodeLine{1070 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u1tot\textcolor{comment}{ !< Sum of cell widths times values}}
\DoxyCodeLine{1071 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u1err\textcolor{comment}{ !< Magnitude of round-off error in u1tot}}
\DoxyCodeLine{1072 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u1min\textcolor{comment}{ !< Minimum value in reconstructions of u1}}
\DoxyCodeLine{1073 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: u1max\textcolor{comment}{ !< Maximum value in reconstructions of u1}}
\DoxyCodeLine{1074   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1075   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1076 \textcolor{keywordtype}{  real} :: eps}
\DoxyCodeLine{1077 }
\DoxyCodeLine{1078   eps = epsilon(h1(1))}
\DoxyCodeLine{1079   h1tot = h1(1)}
\DoxyCodeLine{1080   h1err = 0.}
\DoxyCodeLine{1081   u1tot = h1(1) * u1(1)}
\DoxyCodeLine{1082   u1err = 0.}
\DoxyCodeLine{1083   u1min = u1(1)}
\DoxyCodeLine{1084   u1max = u1(1)}
\DoxyCodeLine{1085   \textcolor{keywordflow}{do} k = 2, n1}
\DoxyCodeLine{1086     h1tot = h1tot + h1(k)}
\DoxyCodeLine{1087     h1err = h1err + eps * max(h1tot, h1(k))}
\DoxyCodeLine{1088     u1tot = u1tot + h1(k) * u1(k)}
\DoxyCodeLine{1089     u1err = u1err + eps * max(abs(u1tot), abs(h1(k) * u1(k)))}
\DoxyCodeLine{1090     u1min = min(u1min, u1(k))}
\DoxyCodeLine{1091     u1max = max(u1max, u1(k))}
\DoxyCodeLine{1092 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1093 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_ab933069898cb9de16ec60f175185762e}\label{namespacemom__remapping_ab933069898cb9de16ec60f175185762e}} 
\index{mom\_remapping@{mom\_remapping}!remap\_via\_sub\_cells@{remap\_via\_sub\_cells}}
\index{remap\_via\_sub\_cells@{remap\_via\_sub\_cells}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remap\_via\_sub\_cells()}{remap\_via\_sub\_cells()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::remap\+\_\+via\+\_\+sub\+\_\+cells (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{real, dimension(n0,2), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(in)}]{h1,  }\item[{integer, intent(in)}]{method,  }\item[{logical, intent(in)}]{force\+\_\+bounds\+\_\+in\+\_\+subcell,  }\item[{real, dimension(n1), intent(out)}]{u1,  }\item[{real, intent(out)}]{uh\+\_\+err,  }\item[{real, dimension(n0+n1+1), intent(out), optional}]{ah\+\_\+sub,  }\item[{integer, dimension(n0+n1+1), intent(out), optional}]{aisub\+\_\+src,  }\item[{integer, dimension(n0), intent(out), optional}]{aiss,  }\item[{integer, dimension(n0), intent(out), optional}]{aise }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Remaps column of n0 values u0 on grid h0 to grid h1 with n1 cells by calculating the n0+n1+1 sub-\/integrals of the intersection of h0 and h1, and the summing the appropriate integrals into the h1$\ast$u1 values. h0 and h1 must have the same units. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Source grid widths (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Source cell averages (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em n1} & Number of cells in target grid \\
\hline
\mbox{\texttt{ in}}  & {\em h1} & Target grid widths (size n1) \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Remapping scheme to use \\
\hline
\mbox{\texttt{ in}}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & Force sub-\/cell values to be bounded \\
\hline
\mbox{\texttt{ out}}  & {\em u1} & Target cell averages (size n1) \\
\hline
\mbox{\texttt{ out}}  & {\em uh\+\_\+err} & Estimate of bound on error in sum of u$\ast$h \\
\hline
\mbox{\texttt{ out}}  & {\em ah\+\_\+sub} & h\+\_\+sub \\
\hline
\mbox{\texttt{ out}}  & {\em aisub\+\_\+src} & i\+\_\+sub\+\_\+src \\
\hline
\mbox{\texttt{ out}}  & {\em aiss} & isrc\+\_\+start \\
\hline
\mbox{\texttt{ out}}  & {\em aise} & isrc\+\_\+ens \\
\hline
\end{DoxyParams}


Definition at line 520 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{520   \textcolor{keywordtype}{integer},           \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}}
\DoxyCodeLine{521 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(in)}    :: h0(n0)\textcolor{comment}{  !< Source grid widths (size n0)}}
\DoxyCodeLine{522 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(in)}    :: u0(n0)\textcolor{comment}{  !< Source cell averages (size n0)}}
\DoxyCodeLine{523 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E(n0,2)\textcolor{comment}{            !< Edge value of polynomial}}
\DoxyCodeLine{524 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs(:,:)\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{525   \textcolor{keywordtype}{integer},           \textcolor{keywordtype}{intent(in)}    :: n1\textcolor{comment}{     !< Number of cells in target grid}}
\DoxyCodeLine{526 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(in)}    :: h1(n1)\textcolor{comment}{  !< Target grid widths (size n1)}}
\DoxyCodeLine{527   \textcolor{keywordtype}{integer},           \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{528   \textcolor{keywordtype}{logical},           \textcolor{keywordtype}{intent(in)}    :: force\_bounds\_in\_subcell\textcolor{comment}{ !< Force sub-cell values to be bounded}}
\DoxyCodeLine{529 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(out)}   :: u1(n1)\textcolor{comment}{  !< Target cell averages (size n1)}}
\DoxyCodeLine{530 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(out)}   :: uh\_err\textcolor{comment}{ !< Estimate of bound on error in sum of u*h}}
\DoxyCodeLine{531 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(out)}   :: ah\_sub(n0+n1+1)\textcolor{comment}{ !< h\_sub}}
\DoxyCodeLine{532   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: aisub\_src(n0+n1+1)\textcolor{comment}{ !< i\_sub\_src}}
\DoxyCodeLine{533   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: aiss(n0)\textcolor{comment}{ !< isrc\_start}}
\DoxyCodeLine{534   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: aise(n0)\textcolor{comment}{ !< isrc\_ens}}
\DoxyCodeLine{535   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{536   \textcolor{keywordtype}{integer} :: i\_sub \textcolor{comment}{! Index of sub-cell}}
\DoxyCodeLine{537   \textcolor{keywordtype}{integer} :: i0 \textcolor{comment}{! Index into h0(1:n0), source column}}
\DoxyCodeLine{538   \textcolor{keywordtype}{integer} :: i1 \textcolor{comment}{! Index into h1(1:n1), target column}}
\DoxyCodeLine{539   \textcolor{keywordtype}{integer} :: i\_start0 \textcolor{comment}{! Used to record which sub-cells map to source cells}}
\DoxyCodeLine{540   \textcolor{keywordtype}{integer} :: i\_start1 \textcolor{comment}{! Used to record which sub-cells map to target cells}}
\DoxyCodeLine{541   \textcolor{keywordtype}{integer} :: i\_max \textcolor{comment}{! Used to record which sub-cell is the largest contribution of a source cell}}
\DoxyCodeLine{542 \textcolor{keywordtype}{  real} :: dh\_max \textcolor{comment}{! Used to record which sub-cell is the largest contribution of a source cell}}
\DoxyCodeLine{543 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: h\_sub \textcolor{comment}{! Width of each each sub-cell}}
\DoxyCodeLine{544 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: uh\_sub \textcolor{comment}{! Integral of u*h over each sub-cell}}
\DoxyCodeLine{545 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: u\_sub \textcolor{comment}{! Average of u over each sub-cell}}
\DoxyCodeLine{546   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: isub\_src \textcolor{comment}{! Index of source cell for each sub-cell}}
\DoxyCodeLine{547   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0)} :: isrc\_start \textcolor{comment}{! Index of first sub-cell within each source cell}}
\DoxyCodeLine{548   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0)} :: isrc\_end \textcolor{comment}{! Index of last sub-cell within each source cell}}
\DoxyCodeLine{549   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0)} :: isrc\_max \textcolor{comment}{! Index of thickest sub-cell within each source cell}}
\DoxyCodeLine{550 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)} :: h0\_eff \textcolor{comment}{! Effective thickness of source cells}}
\DoxyCodeLine{551 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)} :: u0\_min \textcolor{comment}{! Minimum value of reconstructions in source cell}}
\DoxyCodeLine{552 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)} :: u0\_max \textcolor{comment}{! Minimum value of reconstructions in source cell}}
\DoxyCodeLine{553   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n1)} :: itgt\_start \textcolor{comment}{! Index of first sub-cell within each target cell}}
\DoxyCodeLine{554   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n1)} :: itgt\_end \textcolor{comment}{! Index of last sub-cell within each target cell}}
\DoxyCodeLine{555 \textcolor{keywordtype}{  real} :: xa, xb \textcolor{comment}{! Non-dimensional position within a source cell (0..1)}}
\DoxyCodeLine{556 \textcolor{keywordtype}{  real} :: h0\_supply, h1\_supply \textcolor{comment}{! The amount of width available for constructing sub-cells}}
\DoxyCodeLine{557 \textcolor{keywordtype}{  real} :: dh \textcolor{comment}{! The width of the sub-cell}}
\DoxyCodeLine{558 \textcolor{keywordtype}{  real} :: duh \textcolor{comment}{! The total amount of accumulated stuff (u*h)}}
\DoxyCodeLine{559 \textcolor{keywordtype}{  real} :: dh0\_eff \textcolor{comment}{! Running sum of source cell thickness}}
\DoxyCodeLine{560   \textcolor{comment}{! For error checking/debugging}}
\DoxyCodeLine{561   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{parameter} :: force\_bounds\_in\_target = .true. \textcolor{comment}{! To fix round-off issues}}
\DoxyCodeLine{562   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{parameter} :: adjust\_thickest\_subcell = .true. \textcolor{comment}{! To fix round-off conservation issues}}
\DoxyCodeLine{563   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{parameter} :: debug\_bounds = .false. \textcolor{comment}{! For debugging overshoots etc.}}
\DoxyCodeLine{564   \textcolor{keywordtype}{integer} :: k, i0\_last\_thick\_cell}
\DoxyCodeLine{565 \textcolor{keywordtype}{  real} :: h0tot, h0err, h1tot, h1err, h2tot, h2err, u02\_err}
\DoxyCodeLine{566 \textcolor{keywordtype}{  real} :: u0tot, u0err, u0min, u0max, u1tot, u1err, u1min, u1max, u2tot, u2err, u2min, u2max, u\_orig}
\DoxyCodeLine{567   \textcolor{keywordtype}{logical} :: src\_has\_volume\textcolor{comment}{ !< True if h0 has not been consumed}}
\DoxyCodeLine{568   \textcolor{keywordtype}{logical} :: tgt\_has\_volume\textcolor{comment}{ !< True if h1 has not been consumed}}
\DoxyCodeLine{569 }
\DoxyCodeLine{570   \textcolor{keywordflow}{if} (old\_algorithm) isrc\_max(:)=1}
\DoxyCodeLine{571 }
\DoxyCodeLine{572   i0\_last\_thick\_cell = 0}
\DoxyCodeLine{573   \textcolor{keywordflow}{do} i0 = 1, n0}
\DoxyCodeLine{574     u0\_min(i0) = min(ppoly0\_e(i0,1), ppoly0\_e(i0,2))}
\DoxyCodeLine{575     u0\_max(i0) = max(ppoly0\_e(i0,1), ppoly0\_e(i0,2))}
\DoxyCodeLine{576     \textcolor{keywordflow}{if} (h0(i0)>0.) i0\_last\_thick\_cell = i0}
\DoxyCodeLine{577 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{578 }
\DoxyCodeLine{579   \textcolor{comment}{! Initialize algorithm}}
\DoxyCodeLine{580   h0\_supply = h0(1)}
\DoxyCodeLine{581   h1\_supply = h1(1)}
\DoxyCodeLine{582   src\_has\_volume = .true.}
\DoxyCodeLine{583   tgt\_has\_volume = .true.}
\DoxyCodeLine{584   i0 = 1 ; i1 = 1}
\DoxyCodeLine{585   i\_start0 = 1 ; i\_start1 = 1}
\DoxyCodeLine{586   i\_max = 1}
\DoxyCodeLine{587   dh\_max = 0.}
\DoxyCodeLine{588   dh0\_eff = 0.}
\DoxyCodeLine{589 }
\DoxyCodeLine{590   \textcolor{comment}{! First sub-cell is always vanished}}
\DoxyCodeLine{591   h\_sub(1) = 0.}
\DoxyCodeLine{592   isrc\_start(1) = 1}
\DoxyCodeLine{593   isrc\_end(1) = 1}
\DoxyCodeLine{594   isrc\_max(1) = 1}
\DoxyCodeLine{595   isub\_src(1) = 1}
\DoxyCodeLine{596 }
\DoxyCodeLine{597   \textcolor{comment}{! Loop over each sub-cell to calculate intersections with source and target grids}}
\DoxyCodeLine{598   \textcolor{keywordflow}{do} i\_sub = 2, n0+n1+1}
\DoxyCodeLine{599 }
\DoxyCodeLine{600     \textcolor{comment}{! This is the width of the sub-cell, determined by which ever column has the least}}
\DoxyCodeLine{601     \textcolor{comment}{! supply available to consume.}}
\DoxyCodeLine{602     dh = min(h0\_supply, h1\_supply)}
\DoxyCodeLine{603 }
\DoxyCodeLine{604     \textcolor{comment}{! This is the running sum of the source cell thickness. After summing over each}}
\DoxyCodeLine{605     \textcolor{comment}{! sub-cell, the sum of sub-cell thickness might differ from the original source}}
\DoxyCodeLine{606     \textcolor{comment}{! cell thickness due to round off.}}
\DoxyCodeLine{607     dh0\_eff = dh0\_eff + min(dh, h0\_supply)}
\DoxyCodeLine{608 }
\DoxyCodeLine{609     \textcolor{comment}{! Record the source index (i0) that this sub-cell integral belongs to. This}}
\DoxyCodeLine{610     \textcolor{comment}{! is needed to index the reconstruction coefficients for the source cell}}
\DoxyCodeLine{611     \textcolor{comment}{! used in the integrals of the sub-cell width.}}
\DoxyCodeLine{612     isub\_src(i\_sub) = i0}
\DoxyCodeLine{613     h\_sub(i\_sub) = dh}
\DoxyCodeLine{614 }
\DoxyCodeLine{615     \textcolor{comment}{! For recording the largest sub-cell within a source cell.}}
\DoxyCodeLine{616     \textcolor{keywordflow}{if} (dh >= dh\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{617       i\_max = i\_sub}
\DoxyCodeLine{618       dh\_max = dh}
\DoxyCodeLine{619 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{620 }
\DoxyCodeLine{621     \textcolor{comment}{! Which ever column (source or target) has the least width left to consume determined}}
\DoxyCodeLine{622     \textcolor{comment}{! the width, dh, of sub-cell i\_sub in the expression for dh above.}}
\DoxyCodeLine{623     \textcolor{keywordflow}{if} (h0\_supply <= h1\_supply .and. src\_has\_volume) \textcolor{keywordflow}{then}}
\DoxyCodeLine{624       \textcolor{comment}{! h0\_supply is smaller than h1\_supply) so we consume h0\_supply and increment the}}
\DoxyCodeLine{625       \textcolor{comment}{! source cell index.}}
\DoxyCodeLine{626       h1\_supply = h1\_supply - dh \textcolor{comment}{! Although this is a difference the result will}}
\DoxyCodeLine{627                                  \textcolor{comment}{! be non-negative because of the conditional.}}
\DoxyCodeLine{628       \textcolor{comment}{! Record the sub-cell start/end index that span the source cell i0.}}
\DoxyCodeLine{629       isrc\_start(i0) = i\_start0}
\DoxyCodeLine{630       isrc\_end(i0) = i\_sub}
\DoxyCodeLine{631       i\_start0 = i\_sub + 1}
\DoxyCodeLine{632       \textcolor{comment}{! Record the sub-cell that is the largest fraction of the source cell.}}
\DoxyCodeLine{633       isrc\_max(i0) = i\_max}
\DoxyCodeLine{634       i\_max = i\_sub + 1}
\DoxyCodeLine{635       dh\_max = 0.}
\DoxyCodeLine{636       \textcolor{comment}{! Record the source cell thickness found by summing the sub-cell thicknesses.}}
\DoxyCodeLine{637       h0\_eff(i0) = dh0\_eff}
\DoxyCodeLine{638       \textcolor{comment}{! Move the source index.}}
\DoxyCodeLine{639       \textcolor{keywordflow}{if} (old\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{640         \textcolor{keywordflow}{if} (i0 < i0\_last\_thick\_cell) \textcolor{keywordflow}{then}}
\DoxyCodeLine{641           i0 = i0 + 1}
\DoxyCodeLine{642           h0\_supply = h0(i0)}
\DoxyCodeLine{643           dh0\_eff = 0.}
\DoxyCodeLine{644           \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (h0\_supply==0. .and. i0<i0\_last\_thick\_cell)}
\DoxyCodeLine{645             \textcolor{comment}{! This loop skips over vanished source cells}}
\DoxyCodeLine{646             i0 = i0 + 1}
\DoxyCodeLine{647             h0\_supply = h0(i0)}
\DoxyCodeLine{648 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{649         \textcolor{keywordflow}{else}}
\DoxyCodeLine{650           h0\_supply = 1.e30}
\DoxyCodeLine{651 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{652       \textcolor{keywordflow}{else}}
\DoxyCodeLine{653         \textcolor{keywordflow}{if} (i0 < n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{654           i0 = i0 + 1}
\DoxyCodeLine{655           h0\_supply = h0(i0)}
\DoxyCodeLine{656           dh0\_eff = 0.}
\DoxyCodeLine{657         \textcolor{keywordflow}{else}}
\DoxyCodeLine{658           h0\_supply = 0.}
\DoxyCodeLine{659           src\_has\_volume = .false.}
\DoxyCodeLine{660 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{661 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{662     \textcolor{keywordflow}{elseif} (h0\_supply >= h1\_supply .and. tgt\_has\_volume) \textcolor{keywordflow}{then}}
\DoxyCodeLine{663       \textcolor{comment}{! h1\_supply is smaller than h0\_supply) so we consume h1\_supply and increment the}}
\DoxyCodeLine{664       \textcolor{comment}{! target cell index.}}
\DoxyCodeLine{665       h0\_supply = h0\_supply - dh \textcolor{comment}{! Although this is a difference the result will}}
\DoxyCodeLine{666                                  \textcolor{comment}{! be non-negative because of the conditional.}}
\DoxyCodeLine{667       \textcolor{comment}{! Record the sub-cell start/end index that span the target cell i1.}}
\DoxyCodeLine{668       itgt\_start(i1) = i\_start1}
\DoxyCodeLine{669       itgt\_end(i1) = i\_sub}
\DoxyCodeLine{670       i\_start1 = i\_sub + 1}
\DoxyCodeLine{671       \textcolor{comment}{! Move the target index.}}
\DoxyCodeLine{672       \textcolor{keywordflow}{if} (i1 < n1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{673         i1 = i1 + 1}
\DoxyCodeLine{674         h1\_supply = h1(i1)}
\DoxyCodeLine{675       \textcolor{keywordflow}{else}}
\DoxyCodeLine{676         \textcolor{keywordflow}{if} (old\_algorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{677           h1\_supply = 1.e30}
\DoxyCodeLine{678         \textcolor{keywordflow}{else}}
\DoxyCodeLine{679           h1\_supply = 0.}
\DoxyCodeLine{680           tgt\_has\_volume = .false.}
\DoxyCodeLine{681 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{682 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{683     \textcolor{keywordflow}{elseif} (src\_has\_volume) \textcolor{keywordflow}{then}}
\DoxyCodeLine{684       \textcolor{comment}{! We ran out of target volume but still have source cells to consume}}
\DoxyCodeLine{685       h\_sub(i\_sub) = h0\_supply}
\DoxyCodeLine{686       \textcolor{comment}{! Record the sub-cell start/end index that span the source cell i0.}}
\DoxyCodeLine{687       isrc\_start(i0) = i\_start0}
\DoxyCodeLine{688       isrc\_end(i0) = i\_sub}
\DoxyCodeLine{689       i\_start0 = i\_sub + 1}
\DoxyCodeLine{690       \textcolor{comment}{! Record the sub-cell that is the largest fraction of the source cell.}}
\DoxyCodeLine{691       isrc\_max(i0) = i\_max}
\DoxyCodeLine{692       i\_max = i\_sub + 1}
\DoxyCodeLine{693       dh\_max = 0.}
\DoxyCodeLine{694       \textcolor{comment}{! Record the source cell thickness found by summing the sub-cell thicknesses.}}
\DoxyCodeLine{695       h0\_eff(i0) = dh0\_eff}
\DoxyCodeLine{696       \textcolor{keywordflow}{if} (i0 < n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{697         i0 = i0 + 1}
\DoxyCodeLine{698         h0\_supply = h0(i0)}
\DoxyCodeLine{699         dh0\_eff = 0.}
\DoxyCodeLine{700       \textcolor{keywordflow}{else}}
\DoxyCodeLine{701         h0\_supply = 0.}
\DoxyCodeLine{702         src\_has\_volume = .false.}
\DoxyCodeLine{703 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{704     \textcolor{keywordflow}{elseif} (tgt\_has\_volume) \textcolor{keywordflow}{then}}
\DoxyCodeLine{705       \textcolor{comment}{! We ran out of source volume but still have target cells to consume}}
\DoxyCodeLine{706       h\_sub(i\_sub) = h1\_supply}
\DoxyCodeLine{707       \textcolor{comment}{! Record the sub-cell start/end index that span the target cell i1.}}
\DoxyCodeLine{708       itgt\_start(i1) = i\_start1}
\DoxyCodeLine{709       itgt\_end(i1) = i\_sub}
\DoxyCodeLine{710       i\_start1 = i\_sub + 1}
\DoxyCodeLine{711       \textcolor{comment}{! Move the target index.}}
\DoxyCodeLine{712       \textcolor{keywordflow}{if} (i1 < n1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{713         i1 = i1 + 1}
\DoxyCodeLine{714         h1\_supply = h1(i1)}
\DoxyCodeLine{715       \textcolor{keywordflow}{else}}
\DoxyCodeLine{716         h1\_supply = 0.}
\DoxyCodeLine{717         tgt\_has\_volume = .false.}
\DoxyCodeLine{718 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{719     \textcolor{keywordflow}{else}}
\DoxyCodeLine{720       stop \textcolor{stringliteral}{'remap\_via\_sub\_cells: THIS SHOULD NEVER HAPPEN!'}}
\DoxyCodeLine{721 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{722 }
\DoxyCodeLine{723 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{724 }
\DoxyCodeLine{725   \textcolor{comment}{! Loop over each sub-cell to calculate average/integral values within each sub-cell.}}
\DoxyCodeLine{726   xa = 0.}
\DoxyCodeLine{727   dh0\_eff = 0.}
\DoxyCodeLine{728   uh\_sub(1) = 0.}
\DoxyCodeLine{729   u\_sub(1) = ppoly0\_e(1,1)}
\DoxyCodeLine{730   u02\_err = 0.}
\DoxyCodeLine{731   \textcolor{keywordflow}{do} i\_sub = 2, n0+n1}
\DoxyCodeLine{732 }
\DoxyCodeLine{733     \textcolor{comment}{! Sub-cell thickness from loop above}}
\DoxyCodeLine{734     dh = h\_sub(i\_sub)}
\DoxyCodeLine{735 }
\DoxyCodeLine{736     \textcolor{comment}{! Source cell}}
\DoxyCodeLine{737     i0 = isub\_src(i\_sub)}
\DoxyCodeLine{738 }
\DoxyCodeLine{739     \textcolor{comment}{! Evaluate average and integral for sub-cell i\_sub.}}
\DoxyCodeLine{740     \textcolor{comment}{! Integral is over distance dh but expressed in terms of non-dimensional}}
\DoxyCodeLine{741     \textcolor{comment}{! positions with source cell from xa to xb  (0 <= xa <= xb <= 1).}}
\DoxyCodeLine{742     dh0\_eff = dh0\_eff + dh \textcolor{comment}{! Cumulative thickness within the source cell}}
\DoxyCodeLine{743     \textcolor{keywordflow}{if} (h0\_eff(i0)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{744       xb = dh0\_eff / h0\_eff(i0) \textcolor{comment}{! This expression yields xa <= xb <= 1.0}}
\DoxyCodeLine{745       xb = min(1., xb) \textcolor{comment}{! This is only needed when the total target column is wider than the source column}}
\DoxyCodeLine{746       u\_sub(i\_sub) = average\_value\_ppoly( n0, u0, ppoly0\_e, ppoly0\_coefs, method, i0, xa, xb)}
\DoxyCodeLine{747     \textcolor{keywordflow}{else} \textcolor{comment}{! Vanished cell}}
\DoxyCodeLine{748       xb = 1.}
\DoxyCodeLine{749       u\_sub(i\_sub) = u0(i0)}
\DoxyCodeLine{750 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{751     \textcolor{keywordflow}{if} (debug\_bounds) \textcolor{keywordflow}{then}}
\DoxyCodeLine{752       \textcolor{keywordflow}{if} (method<5 .and.(u\_sub(i\_sub)<u0\_min(i0) .or. u\_sub(i\_sub)>u0\_max(i0))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{753         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Sub cell average is out of bounds'},i\_sub,\textcolor{stringliteral}{'method='},method}
\DoxyCodeLine{754         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'xa,xb: '},xa,xb}
\DoxyCodeLine{755         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Edge values: '},ppoly0\_e(i0,:),\textcolor{stringliteral}{'mean'},u0(i0)}
\DoxyCodeLine{756         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'a\_c: '},(u0(i0)-ppoly0\_e(i0,1))+(u0(i0)-ppoly0\_e(i0,2))}
\DoxyCodeLine{757         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Polynomial coeffs: '},ppoly0\_coefs(i0,:)}
\DoxyCodeLine{758         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Bounds min='},u0\_min(i0),\textcolor{stringliteral}{'max='},u0\_max(i0)}
\DoxyCodeLine{759         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Average: '},u\_sub(i\_sub),\textcolor{stringliteral}{'rel to min='},u\_sub(i\_sub)-u0\_min(i0),\textcolor{stringliteral}{'rel to max='},u\_sub(i\_sub)-u0\_max(i0)}
\DoxyCodeLine{760         \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remap\_via\_sub\_cells: '}//\&}
\DoxyCodeLine{761              \textcolor{stringliteral}{'Sub-cell average is out of bounds!'} )}
\DoxyCodeLine{762 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{763 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{764     \textcolor{keywordflow}{if} (force\_bounds\_in\_subcell) \textcolor{keywordflow}{then}}
\DoxyCodeLine{765       \textcolor{comment}{! These next two lines should not be needed but when using PQM we found roundoff}}
\DoxyCodeLine{766       \textcolor{comment}{! can lead to overshoots. These lines sweep issues under the rug which need to be}}
\DoxyCodeLine{767       \textcolor{comment}{! properly .. later. -AJA}}
\DoxyCodeLine{768       u\_orig = u\_sub(i\_sub)}
\DoxyCodeLine{769       u\_sub(i\_sub) = max( u\_sub(i\_sub), u0\_min(i0) )}
\DoxyCodeLine{770       u\_sub(i\_sub) = min( u\_sub(i\_sub), u0\_max(i0) )}
\DoxyCodeLine{771       u02\_err = u02\_err + dh*abs( u\_sub(i\_sub) - u\_orig )}
\DoxyCodeLine{772 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{773     uh\_sub(i\_sub) = dh * u\_sub(i\_sub)}
\DoxyCodeLine{774 }
\DoxyCodeLine{775     \textcolor{keywordflow}{if} (isub\_src(i\_sub+1) /= i0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{776       \textcolor{comment}{! If the next sub-cell is in a different source cell, reset the position counters}}
\DoxyCodeLine{777       dh0\_eff = 0.}
\DoxyCodeLine{778       xa = 0.}
\DoxyCodeLine{779     \textcolor{keywordflow}{else}}
\DoxyCodeLine{780       xa = xb \textcolor{comment}{! Next integral will start at end of last}}
\DoxyCodeLine{781 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{782 }
\DoxyCodeLine{783 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{784   u\_sub(n0+n1+1) = ppoly0\_e(n0,2)                   \textcolor{comment}{! This value is only needed when total target column}}
\DoxyCodeLine{785   uh\_sub(n0+n1+1) = ppoly0\_e(n0,2) * h\_sub(n0+n1+1) \textcolor{comment}{! is wider than the source column}}
\DoxyCodeLine{786 }
\DoxyCodeLine{787   \textcolor{keywordflow}{if} (adjust\_thickest\_subcell) \textcolor{keywordflow}{then}}
\DoxyCodeLine{788     \textcolor{comment}{! Loop over each source cell substituting the integral/average for the thickest sub-cell (within}}
\DoxyCodeLine{789     \textcolor{comment}{! the source cell) with the residual of the source cell integral minus the other sub-cell integrals}}
\DoxyCodeLine{790     \textcolor{comment}{! aka a genius algorithm for accurate conservation when remapping from Robert Hallberg (@Hallberg-NOAA).}}
\DoxyCodeLine{791     \textcolor{keywordflow}{do} i0 = 1, i0\_last\_thick\_cell}
\DoxyCodeLine{792       i\_max = isrc\_max(i0)}
\DoxyCodeLine{793       dh\_max = h\_sub(i\_max)}
\DoxyCodeLine{794       \textcolor{keywordflow}{if} (dh\_max > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{795         \textcolor{comment}{! duh will be the sum of sub-cell integrals within the source cell except for the thickest sub-cell.}}
\DoxyCodeLine{796         duh = 0.}
\DoxyCodeLine{797         \textcolor{keywordflow}{do} i\_sub = isrc\_start(i0), isrc\_end(i0)}
\DoxyCodeLine{798           \textcolor{keywordflow}{if} (i\_sub /= i\_max) duh = duh + uh\_sub(i\_sub)}
\DoxyCodeLine{799 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{800         uh\_sub(i\_max) = u0(i0)*h0(i0) - duh}
\DoxyCodeLine{801         u02\_err = u02\_err + max( abs(uh\_sub(i\_max)), abs(u0(i0)*h0(i0)), abs(duh) )}
\DoxyCodeLine{802 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{803 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{804 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{805 }
\DoxyCodeLine{806   \textcolor{comment}{! Loop over each target cell summing the integrals from sub-cells within the target cell.}}
\DoxyCodeLine{807   uh\_err = 0.}
\DoxyCodeLine{808   \textcolor{keywordflow}{do} i1 = 1, n1}
\DoxyCodeLine{809     \textcolor{keywordflow}{if} (h1(i1) > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{810       duh = 0. ; dh = 0.}
\DoxyCodeLine{811       i\_sub = itgt\_start(i1)}
\DoxyCodeLine{812       \textcolor{keywordflow}{if} (force\_bounds\_in\_target) \textcolor{keywordflow}{then}}
\DoxyCodeLine{813         u1min = u\_sub(i\_sub)}
\DoxyCodeLine{814         u1max = u\_sub(i\_sub)}
\DoxyCodeLine{815 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{816       \textcolor{keywordflow}{do} i\_sub = itgt\_start(i1), itgt\_end(i1)}
\DoxyCodeLine{817         \textcolor{keywordflow}{if} (force\_bounds\_in\_target) \textcolor{keywordflow}{then}}
\DoxyCodeLine{818           u1min = min(u1min, u\_sub(i\_sub))}
\DoxyCodeLine{819           u1max = max(u1max, u\_sub(i\_sub))}
\DoxyCodeLine{820 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{821         dh = dh + h\_sub(i\_sub)}
\DoxyCodeLine{822         duh = duh + uh\_sub(i\_sub)}
\DoxyCodeLine{823         \textcolor{comment}{! This accumulates the contribution to the error bound for the sum of u*h}}
\DoxyCodeLine{824         uh\_err = uh\_err + max(abs(duh),abs(uh\_sub(i\_sub)))*epsilon(duh)}
\DoxyCodeLine{825 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{826       u1(i1) = duh / dh}
\DoxyCodeLine{827       \textcolor{comment}{! This is the contribution from the division to the error bound for the sum of u*h}}
\DoxyCodeLine{828       uh\_err = uh\_err + abs(duh)*epsilon(duh)}
\DoxyCodeLine{829       \textcolor{keywordflow}{if} (force\_bounds\_in\_target) \textcolor{keywordflow}{then}}
\DoxyCodeLine{830         u\_orig = u1(i1)}
\DoxyCodeLine{831         u1(i1) = max(u1min, min(u1max, u1(i1)))}
\DoxyCodeLine{832         \textcolor{comment}{! Adjusting to be bounded contributes to the error for the sum of u*h}}
\DoxyCodeLine{833         uh\_err = uh\_err + dh*abs( u1(i1)-u\_orig )}
\DoxyCodeLine{834 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{835     \textcolor{keywordflow}{else}}
\DoxyCodeLine{836       u1(i1) = u\_sub(itgt\_start(i1))}
\DoxyCodeLine{837 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{838 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{839 }
\DoxyCodeLine{840   \textcolor{comment}{! Check errors and bounds}}
\DoxyCodeLine{841   \textcolor{keywordflow}{if} (debug\_bounds) \textcolor{keywordflow}{then}}
\DoxyCodeLine{842     \textcolor{keyword}{call }measure\_input\_bounds( n0, h0, u0, ppoly0\_e, h0tot, h0err, u0tot, u0err, u0min, u0max )}
\DoxyCodeLine{843     \textcolor{keyword}{call }measure\_output\_bounds( n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max )}
\DoxyCodeLine{844     \textcolor{keyword}{call }measure\_output\_bounds( n0+n1+1, h\_sub, u\_sub, h2tot, h2err, u2tot, u2err, u2min, u2max )}
\DoxyCodeLine{845     \textcolor{keywordflow}{if} (method<5) \textcolor{keywordflow}{then} \textcolor{comment}{! We except PQM until we've debugged it}}
\DoxyCodeLine{846     \textcolor{keywordflow}{if} (     (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err+u02\_err .and. abs(h1tot-h0tot)<h0err+h1err) \&}
\DoxyCodeLine{847         .or. (abs(u2tot-u0tot)>u0err+u2err+u02\_err .and. abs(h2tot-h0tot)<h0err+h2err) \&}
\DoxyCodeLine{848         .or. (u1min<u0min .or. u1max>u0max) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{849       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'method = '},method}
\DoxyCodeLine{850       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Source to sub-cells:'}}
\DoxyCodeLine{851       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h2tot='},h2tot,\textcolor{stringliteral}{'dh='},h2tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h2err='},h2err}
\DoxyCodeLine{852       \textcolor{keywordflow}{if} (abs(h2tot-h0tot)>h0err+h2err) \&}
\DoxyCodeLine{853         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h2tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h2err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{854       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u2tot='},u2tot,\textcolor{stringliteral}{'duh='},u2tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u2err='},u2err,\&}
\DoxyCodeLine{855                  \textcolor{stringliteral}{'adjustment err='},u02\_err}
\DoxyCodeLine{856       \textcolor{keywordflow}{if} (abs(u2tot-u0tot)>u0err+u2err) \&}
\DoxyCodeLine{857         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u2tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u2err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{858       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Sub-cells to target:'}}
\DoxyCodeLine{859       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h2tot='},h2tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h2tot,\textcolor{stringliteral}{'h2err='},h2err,\textcolor{stringliteral}{'h1err='},h1err}
\DoxyCodeLine{860       \textcolor{keywordflow}{if} (abs(h1tot-h2tot)>h2err+h1err) \&}
\DoxyCodeLine{861         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h2tot,\textcolor{stringliteral}{'allowed err='},h2err+h1err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{862       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u2tot='},u2tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u2tot,\textcolor{stringliteral}{'u2err='},u2err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{'uh\_err='},uh\_err}
\DoxyCodeLine{863       \textcolor{keywordflow}{if} (abs(u1tot-u2tot)>u2err+u1err) \&}
\DoxyCodeLine{864         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u2tot,\textcolor{stringliteral}{'allowed err='},u2err+u1err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{865       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Source to target:'}}
\DoxyCodeLine{866       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h1err='},h1err}
\DoxyCodeLine{867       \textcolor{keywordflow}{if} (abs(h1tot-h0tot)>h0err+h1err) \&}
\DoxyCodeLine{868         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h1err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{869       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{'uh\_err='},uh\_err}
\DoxyCodeLine{870       \textcolor{keywordflow}{if} (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err) \&}
\DoxyCodeLine{871         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u1err+uh\_err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{872       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0min='},u0min,\textcolor{stringliteral}{'u1min='},u1min,\textcolor{stringliteral}{'u2min='},u2min}
\DoxyCodeLine{873       \textcolor{keywordflow}{if} (u1min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U minimum overshoot='},u1min-u0min,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{874       \textcolor{keywordflow}{if} (u2min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U2 minimum overshoot='},u2min-u0min,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{875       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0max='},u0max,\textcolor{stringliteral}{'u1max='},u1max,\textcolor{stringliteral}{'u2max='},u2max}
\DoxyCodeLine{876       \textcolor{keywordflow}{if} (u1max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U maximum overshoot='},u1max-u0max,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{877       \textcolor{keywordflow}{if} (u2max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U2 maximum overshoot='},u2max-u0max,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{878       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,6a24,2a3)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'h0'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'h1'},\textcolor{stringliteral}{'u1'},\textcolor{stringliteral}{'is'},\textcolor{stringliteral}{'ie'}}
\DoxyCodeLine{879       \textcolor{keywordflow}{do} k = 1, max(n0,n1)}
\DoxyCodeLine{880         \textcolor{keywordflow}{if} (k<=min(n0,n1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{881           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16,2i3)'}) k,h0(k),ppoly0\_e(k,1),u0(k),ppoly0\_e(k,2),h1(k),u1(k),itgt\_start(k),itgt\_end(k)}
\DoxyCodeLine{882         \textcolor{keywordflow}{elseif} (k>n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{883           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,96x,1p2e24.16,2i3)'}) k,h1(k),u1(k),itgt\_start(k),itgt\_end(k)}
\DoxyCodeLine{884         \textcolor{keywordflow}{else}}
\DoxyCodeLine{885           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p4e24.16)'}) k,h0(k),ppoly0\_e(k,1),u0(k),ppoly0\_e(k,2)}
\DoxyCodeLine{886 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{887 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{888       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'Polynomial coefficients'}}
\DoxyCodeLine{889       \textcolor{keywordflow}{do} k = 1, n0}
\DoxyCodeLine{890         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,u0(k),ppoly0\_coefs(k,:)}
\DoxyCodeLine{891 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{892       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,3a24,a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'Sub-cell h'},\textcolor{stringliteral}{'Sub-cell u'},\textcolor{stringliteral}{'Sub-cell hu'},\textcolor{stringliteral}{'i0'},\textcolor{stringliteral}{'xa'},\textcolor{stringliteral}{'xb'}}
\DoxyCodeLine{893       xa = 0.}
\DoxyCodeLine{894       dh0\_eff = 0.}
\DoxyCodeLine{895       \textcolor{keywordflow}{do} k = 1, n0+n1+1}
\DoxyCodeLine{896         dh = h\_sub(k)}
\DoxyCodeLine{897         i0 = isub\_src(k)}
\DoxyCodeLine{898         dh0\_eff = dh0\_eff + dh \textcolor{comment}{! Cumulative thickness within the source cell}}
\DoxyCodeLine{899         xb = dh0\_eff / h0\_eff(i0) \textcolor{comment}{! This expression yields xa <= xb <= 1.0}}
\DoxyCodeLine{900         xb = min(1., xb) \textcolor{comment}{! This is only needed when the total target column is wider than the source column}}
\DoxyCodeLine{901         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p3e24.16,i3,1p2e24.16)'}) k,h\_sub(k),u\_sub(k),uh\_sub(k),i0,xa,xb}
\DoxyCodeLine{902         \textcolor{keywordflow}{if} (k<=n0+n1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{903           \textcolor{keywordflow}{if} (isub\_src(k+1) /= i0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{904             dh0\_eff = 0.; xa = 0.}
\DoxyCodeLine{905           \textcolor{keywordflow}{else}}
\DoxyCodeLine{906             xa = xb}
\DoxyCodeLine{907 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{908 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{909 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{910       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remap\_via\_sub\_cells: '}//\&}
\DoxyCodeLine{911              \textcolor{stringliteral}{'Remapping result is inconsistent!'} )}
\DoxyCodeLine{912 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{913 \textcolor{keywordflow}{    endif} \textcolor{comment}{! method<5}}
\DoxyCodeLine{914 \textcolor{keywordflow}{  endif} \textcolor{comment}{! debug\_bounds}}
\DoxyCodeLine{915 }
\DoxyCodeLine{916   \textcolor{comment}{! Include the error remapping from source to sub-cells in the estimate of total remapping error}}
\DoxyCodeLine{917   uh\_err = uh\_err + u02\_err}
\DoxyCodeLine{918 }
\DoxyCodeLine{919   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ah\_sub)) ah\_sub(1:n0+n1+1) = h\_sub(1:n0+n1+1)}
\DoxyCodeLine{920   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(aisub\_src)) aisub\_src(1:n0+n1+1) = isub\_src(1:n0+n1+1)}
\DoxyCodeLine{921   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(aiss)) aiss(1:n0) = isrc\_start(1:n0)}
\DoxyCodeLine{922   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(aise)) aise(1:n0) = isrc\_end(1:n0)}
\DoxyCodeLine{923 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_ad41da2080e01eaed0b189079801b3c9b}\label{namespacemom__remapping_ad41da2080e01eaed0b189079801b3c9b}} 
\index{mom\_remapping@{mom\_remapping}!remapbydeltaz@{remapbydeltaz}}
\index{remapbydeltaz@{remapbydeltaz}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remapbydeltaz()}{remapbydeltaz()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::remapbydeltaz (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{h0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(\+:), intent(in)}]{dx1,  }\item[{integer, intent(in)}]{method,  }\item[{real, dimension(\+:), intent(out)}]{u1,  }\item[{real, dimension(\+:), intent(out), optional}]{h1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. The new grid is defined relative to the original grid by change dx1(\+:) = x\+New(\+:) -\/ x\+Old(\+:) and the remapping calculated so that h\+New(k) q\+New(k) = h\+Old(k) q\+Old(k) + F(k+1) -\/ F(k) where F(k) = dx1(k) q\+Average and where q\+Average is the average q\+Old in the region z\+Old(k) to z\+New(k). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Source grid sizes (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Source cell averages (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em n1} & Number of cells in target grid \\
\hline
\mbox{\texttt{ in}}  & {\em dx1} & Target grid edge positions (size n1+1) \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Remapping scheme to use \\
\hline
\mbox{\texttt{ out}}  & {\em u1} & Target cell averages (size n1) \\
\hline
\mbox{\texttt{ out}}  & {\em h1} & Target grid widths (size n1) \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h. \\
\hline
\end{DoxyParams}


Definition at line 1148 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1148   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{     !< Number of cells in source grid}}
\DoxyCodeLine{1149 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{     !< Source grid sizes (size n0)}}
\DoxyCodeLine{1150 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{     !< Source cell averages (size n0)}}
\DoxyCodeLine{1151 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}  :: ppoly0\_E\textcolor{comment}{ !< Edge value of polynomial}}
\DoxyCodeLine{1152 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}  :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{1153   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{     !< Number of cells in target grid}}
\DoxyCodeLine{1154 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: dx1\textcolor{comment}{    !< Target grid edge positions (size n1+1)}}
\DoxyCodeLine{1155   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: method\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{1156 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(out)} :: u1\textcolor{comment}{     !< Target cell averages (size n1)}}
\DoxyCodeLine{1157 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \&}
\DoxyCodeLine{1158               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: h1\textcolor{comment}{     !< Target grid widths (size n1)}}
\DoxyCodeLine{1159 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{1160 \textcolor{comment}{                                           !! purpose of cell reconstructions}}
\DoxyCodeLine{1161 \textcolor{comment}{                                           !! in the same units as h.}}
\DoxyCodeLine{1162   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1163   \textcolor{keywordtype}{integer} :: iTarget}
\DoxyCodeLine{1164 \textcolor{keywordtype}{  real}    :: xL, xR    \textcolor{comment}{! coordinates of target cell edges}}
\DoxyCodeLine{1165 \textcolor{keywordtype}{  real}    :: xOld, hOld, uOld}
\DoxyCodeLine{1166 \textcolor{keywordtype}{  real}    :: xNew, hNew, h\_err}
\DoxyCodeLine{1167 \textcolor{keywordtype}{  real}    :: uhNew, hFlux, uAve, fluxL, fluxR}
\DoxyCodeLine{1168   \textcolor{keywordtype}{integer} :: jStart \textcolor{comment}{! Used by integrateReconOnInterval()}}
\DoxyCodeLine{1169 \textcolor{keywordtype}{  real}    :: xStart \textcolor{comment}{! Used by integrateReconOnInterval()}}
\DoxyCodeLine{1170 }
\DoxyCodeLine{1171   \textcolor{comment}{! Loop on cells in target grid. For each cell, iTarget, the left flux is}}
\DoxyCodeLine{1172   \textcolor{comment}{! the right flux of the cell to the left, iTarget-1.}}
\DoxyCodeLine{1173   \textcolor{comment}{! The left flux is initialized by started at iTarget=0 to calculate the}}
\DoxyCodeLine{1174   \textcolor{comment}{! right flux which can take into account the target left boundary being}}
\DoxyCodeLine{1175   \textcolor{comment}{! in the interior of the source domain.}}
\DoxyCodeLine{1176   fluxr = 0.}
\DoxyCodeLine{1177   h\_err = 0. \textcolor{comment}{! For measuring round-off error}}
\DoxyCodeLine{1178   jstart = 1}
\DoxyCodeLine{1179   xstart = 0.}
\DoxyCodeLine{1180   \textcolor{keywordflow}{do} itarget = 0,n1}
\DoxyCodeLine{1181     fluxl = fluxr \textcolor{comment}{! This does nothing for iTarget=0}}
\DoxyCodeLine{1182 }
\DoxyCodeLine{1183     \textcolor{keywordflow}{if} (itarget == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1184       xold = 0.     \textcolor{comment}{! Left boundary is at x=0}}
\DoxyCodeLine{1185       hold = -1.e30 \textcolor{comment}{! Should not be used for iTarget = 0}}
\DoxyCodeLine{1186       uold = -1.e30 \textcolor{comment}{! Should not be used for iTarget = 0}}
\DoxyCodeLine{1187     \textcolor{keywordflow}{elseif} (itarget <= n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1188       xold = xold + h0(itarget) \textcolor{comment}{! Position of right edge of cell}}
\DoxyCodeLine{1189       hold = h0(itarget)}
\DoxyCodeLine{1190       uold = u0(itarget)}
\DoxyCodeLine{1191       h\_err = h\_err + epsilon(hold) * max(hold, xold)}
\DoxyCodeLine{1192     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1193       hold = 0.       \textcolor{comment}{! as if for layers>n0, they were vanished}}
\DoxyCodeLine{1194       uold = 1.e30    \textcolor{comment}{! and the initial value should not matter}}
\DoxyCodeLine{1195 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1196     xnew = xold + dx1(itarget+1)}
\DoxyCodeLine{1197     xl = min( xold, xnew )}
\DoxyCodeLine{1198     xr = max( xold, xnew )}
\DoxyCodeLine{1199 }
\DoxyCodeLine{1200     \textcolor{comment}{! hFlux is the positive width of the remapped volume}}
\DoxyCodeLine{1201     hflux = abs(dx1(itarget+1))}
\DoxyCodeLine{1202     \textcolor{keyword}{call }integraterecononinterval( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, method, \&}
\DoxyCodeLine{1203                                    xl, xr, hflux, uave, jstart, xstart )}
\DoxyCodeLine{1204     \textcolor{comment}{! uAve is the average value of u, independent of sign of dx1}}
\DoxyCodeLine{1205     fluxr = dx1(itarget+1)*uave \textcolor{comment}{! Includes sign of dx1}}
\DoxyCodeLine{1206 }
\DoxyCodeLine{1207     \textcolor{keywordflow}{if} (itarget>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1208       hnew = hold + ( dx1(itarget+1) - dx1(itarget) )}
\DoxyCodeLine{1209       hnew = max( 0., hnew )}
\DoxyCodeLine{1210       uhnew = ( uold * hold ) + ( fluxr - fluxl )}
\DoxyCodeLine{1211       \textcolor{keywordflow}{if} (hnew>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1212         u1(itarget) = uhnew / hnew}
\DoxyCodeLine{1213       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1214         u1(itarget) = uave}
\DoxyCodeLine{1215 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1216       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h1)) h1(itarget) = hnew}
\DoxyCodeLine{1217 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1218 }
\DoxyCodeLine{1219 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end iTarget loop on target grid cells}}
\DoxyCodeLine{1220 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_add104225e8ea85f4e6a324da6be3dba2}\label{namespacemom__remapping_add104225e8ea85f4e6a324da6be3dba2}} 
\index{mom\_remapping@{mom\_remapping}!remapbyprojection@{remapbyprojection}}
\index{remapbyprojection@{remapbyprojection}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remapbyprojection()}{remapbyprojection()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::remapbyprojection (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{h0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(\+:), intent(in)}]{h1,  }\item[{integer, intent(in)}]{method,  }\item[{real, dimension(\+:), intent(out)}]{u1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Remaps column of values u0 on grid h0 to grid h1 by integrating over the projection of each h1 cell onto the h0 grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n0} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Source grid widths (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Source cell averages (size n0) \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e} & Edge value of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial \\
\hline
\mbox{\texttt{ in}}  & {\em n1} & Number of cells in target grid \\
\hline
\mbox{\texttt{ in}}  & {\em h1} & Target grid widths (size n1) \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Remapping scheme to use \\
\hline
\mbox{\texttt{ out}}  & {\em u1} & Target cell averages (size n1) \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h. \\
\hline
\end{DoxyParams}


Definition at line 1100 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1100   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}}
\DoxyCodeLine{1101 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: h0(:)\textcolor{comment}{  !< Source grid widths (size n0)}}
\DoxyCodeLine{1102 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: u0(:)\textcolor{comment}{  !< Source cell averages (size n0)}}
\DoxyCodeLine{1103 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E(:,:)\textcolor{comment}{     !< Edge value of polynomial}}
\DoxyCodeLine{1104 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs(:,:)\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{1105   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: n1\textcolor{comment}{     !< Number of cells in target grid}}
\DoxyCodeLine{1106 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(in)}    :: h1(:)\textcolor{comment}{  !< Target grid widths (size n1)}}
\DoxyCodeLine{1107   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{1108 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{intent(out)}   :: u1(:)\textcolor{comment}{  !< Target cell averages (size n1)}}
\DoxyCodeLine{1109 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}   :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{1110 \textcolor{comment}{                                           !! purpose of cell reconstructions}}
\DoxyCodeLine{1111 \textcolor{comment}{                                           !! in the same units as h.}}
\DoxyCodeLine{1112   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1113   \textcolor{keywordtype}{integer}       :: iTarget}
\DoxyCodeLine{1114 \textcolor{keywordtype}{  real}          :: xL, xR       \textcolor{comment}{! coordinates of target cell edges}}
\DoxyCodeLine{1115   \textcolor{keywordtype}{integer}       :: jStart \textcolor{comment}{! Used by integrateReconOnInterval()}}
\DoxyCodeLine{1116 \textcolor{keywordtype}{  real}          :: xStart \textcolor{comment}{! Used by integrateReconOnInterval()}}
\DoxyCodeLine{1117 }
\DoxyCodeLine{1118   \textcolor{comment}{! Loop on cells in target grid (grid1). For each target cell, we need to find}}
\DoxyCodeLine{1119   \textcolor{comment}{! in which source cells the target cell edges lie. The associated indexes are}}
\DoxyCodeLine{1120   \textcolor{comment}{! noted j0 and j1.}}
\DoxyCodeLine{1121   xr = 0. \textcolor{comment}{! Left boundary is at x=0}}
\DoxyCodeLine{1122   jstart = 1}
\DoxyCodeLine{1123   xstart = 0.}
\DoxyCodeLine{1124   \textcolor{keywordflow}{do} itarget = 1,n1}
\DoxyCodeLine{1125     \textcolor{comment}{! Determine the coordinates of the target cell edges}}
\DoxyCodeLine{1126     xl = xr}
\DoxyCodeLine{1127     xr = xl + h1(itarget)}
\DoxyCodeLine{1128 }
\DoxyCodeLine{1129     \textcolor{keyword}{call }integraterecononinterval( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, method, \&}
\DoxyCodeLine{1130                                    xl, xr, h1(itarget), u1(itarget), jstart, xstart, h\_neglect )}
\DoxyCodeLine{1131 }
\DoxyCodeLine{1132 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end iTarget loop on target grid cells}}
\DoxyCodeLine{1133 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_abe4a1d5b1b9f26063a5e4aba5be0b0a5}\label{namespacemom__remapping_abe4a1d5b1b9f26063a5e4aba5be0b0a5}} 
\index{mom\_remapping@{mom\_remapping}!remapping\_core\_h@{remapping\_core\_h}}
\index{remapping\_core\_h@{remapping\_core\_h}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remapping\_core\_h()}{remapping\_core\_h()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::remapping\+\_\+core\+\_\+h (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(in)}]{h1,  }\item[{real, dimension(n1), intent(out)}]{u1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Remaps column of values u0 on grid h0 to grid h1 assuming the top edge is aligned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em n0} & Number of cells on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Cell widths on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Cell averages on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em n1} & Number of cells on target grid \\
\hline
\mbox{\texttt{ in}}  & {\em h1} & Cell widths on target grid \\
\hline
\mbox{\texttt{ out}}  & {\em u1} & Cell averages on target grid \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h0. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 190 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{190   \textcolor{keywordtype}{type}(remapping\_CS),  \textcolor{keywordtype}{intent(in)}  :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{191   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}}
\DoxyCodeLine{192 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}}
\DoxyCodeLine{193 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}}
\DoxyCodeLine{194   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on target grid}}
\DoxyCodeLine{195 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1)}, \textcolor{keywordtype}{intent(in)}  :: h1\textcolor{comment}{ !< Cell widths on target grid}}
\DoxyCodeLine{196 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1)}, \textcolor{keywordtype}{intent(out)} :: u1\textcolor{comment}{ !< Cell averages on target grid}}
\DoxyCodeLine{197 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{198 \textcolor{comment}{                                         !! purpose of cell reconstructions}}
\DoxyCodeLine{199 \textcolor{comment}{                                         !! in the same units as h0.}}
\DoxyCodeLine{200 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}}
\DoxyCodeLine{201 \textcolor{comment}{                                         !! for the purpose of edge value}}
\DoxyCodeLine{202 \textcolor{comment}{                                         !! calculations in the same units as h0.}}
\DoxyCodeLine{203   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{204   \textcolor{keywordtype}{integer} :: iMethod}
\DoxyCodeLine{205 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_E            \textcolor{comment}{!Edge value of polynomial}}
\DoxyCodeLine{206 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_S            \textcolor{comment}{!Edge slope of polynomial}}
\DoxyCodeLine{207 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,CS\%degree+1)} :: ppoly\_r\_coefs \textcolor{comment}{!Coefficients of polynomial}}
\DoxyCodeLine{208   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{209 \textcolor{keywordtype}{  real} :: eps, h0tot, h0err, h1tot, h1err, u0tot, u0err, u0min, u0max, u1tot, u1err, u1min, u1max, uh\_err}
\DoxyCodeLine{210 \textcolor{keywordtype}{  real} :: hNeglect, hNeglect\_edge}
\DoxyCodeLine{211 }
\DoxyCodeLine{212   hneglect = 1.0e-30 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect}
\DoxyCodeLine{213   hneglect\_edge = 1.0e-10 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect\_edge)) hneglect\_edge = h\_neglect\_edge}
\DoxyCodeLine{214 }
\DoxyCodeLine{215   \textcolor{keyword}{call }build\_reconstructions\_1d( cs, n0, h0, u0, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s, imethod, \&}
\DoxyCodeLine{216                                  hneglect, hneglect\_edge )}
\DoxyCodeLine{217 }
\DoxyCodeLine{218   \textcolor{keywordflow}{if} (cs\%check\_reconstruction) \textcolor{keyword}{call }check\_reconstructions\_1d(n0, h0, u0, cs\%degree, \&}
\DoxyCodeLine{219                                    cs\%boundary\_extrapolation, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s)}
\DoxyCodeLine{220 }
\DoxyCodeLine{221 }
\DoxyCodeLine{222   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, n1, h1, imethod, \&}
\DoxyCodeLine{223                             cs\%force\_bounds\_in\_subcell, u1, uh\_err )}
\DoxyCodeLine{224 }
\DoxyCodeLine{225   \textcolor{keywordflow}{if} (cs\%check\_remapping) \textcolor{keywordflow}{then}}
\DoxyCodeLine{226     \textcolor{comment}{! Check errors and bounds}}
\DoxyCodeLine{227     \textcolor{keyword}{call }measure\_input\_bounds( n0, h0, u0, ppoly\_r\_e, h0tot, h0err, u0tot, u0err, u0min, u0max )}
\DoxyCodeLine{228     \textcolor{keyword}{call }measure\_output\_bounds( n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max )}
\DoxyCodeLine{229     \textcolor{keywordflow}{if} (imethod<5) \textcolor{keywordflow}{then} \textcolor{comment}{! We except PQM until we've debugged it}}
\DoxyCodeLine{230     \textcolor{keywordflow}{if} ( (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err .and. abs(h1tot-h0tot)<h0err+h1err) \&}
\DoxyCodeLine{231         .or. (u1min<u0min .or. u1max>u0max) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{232       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'iMethod = '},imethod}
\DoxyCodeLine{233       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h1err='},h1err}
\DoxyCodeLine{234       \textcolor{keywordflow}{if} (abs(h1tot-h0tot)>h0err+h1err) \&}
\DoxyCodeLine{235         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h1err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{236       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{'uh\_err='},uh\_err}
\DoxyCodeLine{237       \textcolor{keywordflow}{if} (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err) \&}
\DoxyCodeLine{238         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u1err+uh\_err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{239       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0min='},u0min,\textcolor{stringliteral}{'u1min='},u1min}
\DoxyCodeLine{240       \textcolor{keywordflow}{if} (u1min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U minimum overshoot='},u1min-u0min,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{241       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0max='},u0max,\textcolor{stringliteral}{'u1max='},u1max}
\DoxyCodeLine{242       \textcolor{keywordflow}{if} (u1max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U maximum overshoot='},u1max-u0max,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{243       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,6a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'h0'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'h1'},\textcolor{stringliteral}{'u1'}}
\DoxyCodeLine{244       \textcolor{keywordflow}{do} k = 1, max(n0,n1)}
\DoxyCodeLine{245         \textcolor{keywordflow}{if} (k<=min(n0,n1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{246           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2),h1(k),u1(k)}
\DoxyCodeLine{247         \textcolor{keywordflow}{elseif} (k>n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{248           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,96x,1p2e24.16)'}) k,h1(k),u1(k)}
\DoxyCodeLine{249         \textcolor{keywordflow}{else}}
\DoxyCodeLine{250           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p4e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2)}
\DoxyCodeLine{251 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{252 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{253       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'Polynomial coefficients'}}
\DoxyCodeLine{254       \textcolor{keywordflow}{do} k = 1, n0}
\DoxyCodeLine{255         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,u0(k),ppoly\_r\_coefs(k,:)}
\DoxyCodeLine{256 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{257       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remapping\_core\_h: '}//\&}
\DoxyCodeLine{258              \textcolor{stringliteral}{'Remapping result is inconsistent!'} )}
\DoxyCodeLine{259 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{260 \textcolor{keywordflow}{    endif} \textcolor{comment}{! method<5}}
\DoxyCodeLine{261 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{262 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a38bd02a8643f4a984bc3985f34106d9a}\label{namespacemom__remapping_a38bd02a8643f4a984bc3985f34106d9a}} 
\index{mom\_remapping@{mom\_remapping}!remapping\_core\_w@{remapping\_core\_w}}
\index{remapping\_core\_w@{remapping\_core\_w}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remapping\_core\_w()}{remapping\_core\_w()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::remapping\+\_\+core\+\_\+w (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1+1), intent(in)}]{dx,  }\item[{real, dimension(n1), intent(out)}]{u1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em n0} & Number of cells on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em h0} & Cell widths on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em u0} & Cell averages on source grid \\
\hline
\mbox{\texttt{ in}}  & {\em n1} & Number of cells on target grid \\
\hline
\mbox{\texttt{ in}}  & {\em dx} & Cell widths on target grid \\
\hline
\mbox{\texttt{ out}}  & {\em u1} & Cell averages on target grid \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h0. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 268 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{268   \textcolor{keywordtype}{type}(remapping\_CS),  \textcolor{keywordtype}{intent(in)}  :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{269   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}}
\DoxyCodeLine{270 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}}
\DoxyCodeLine{271 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}}
\DoxyCodeLine{272   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on target grid}}
\DoxyCodeLine{273 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1+1)}, \textcolor{keywordtype}{intent(in)} :: dx\textcolor{comment}{ !< Cell widths on target grid}}
\DoxyCodeLine{274 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1)}, \textcolor{keywordtype}{intent(out)} :: u1\textcolor{comment}{ !< Cell averages on target grid}}
\DoxyCodeLine{275 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{276 \textcolor{comment}{                                         !! purpose of cell reconstructions}}
\DoxyCodeLine{277 \textcolor{comment}{                                         !! in the same units as h0.}}
\DoxyCodeLine{278 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}}
\DoxyCodeLine{279 \textcolor{comment}{                                         !! for the purpose of edge value}}
\DoxyCodeLine{280 \textcolor{comment}{                                         !! calculations in the same units as h0.}}
\DoxyCodeLine{281   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{282   \textcolor{keywordtype}{integer} :: iMethod}
\DoxyCodeLine{283 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_E            \textcolor{comment}{!Edge value of polynomial}}
\DoxyCodeLine{284 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_S            \textcolor{comment}{!Edge slope of polynomial}}
\DoxyCodeLine{285 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n0,CS\%degree+1)} :: ppoly\_r\_coefs \textcolor{comment}{!Coefficients of polynomial}}
\DoxyCodeLine{286   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{287 \textcolor{keywordtype}{  real} :: eps, h0tot, h0err, h1tot, h1err}
\DoxyCodeLine{288 \textcolor{keywordtype}{  real} :: u0tot, u0err, u0min, u0max, u1tot, u1err, u1min, u1max, uh\_err}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n1)} :: h1\textcolor{comment}{ !< Cell widths on target grid}}
\DoxyCodeLine{290 \textcolor{keywordtype}{  real} :: hNeglect, hNeglect\_edge}
\DoxyCodeLine{291 }
\DoxyCodeLine{292   hneglect = 1.0e-30 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect}
\DoxyCodeLine{293   hneglect\_edge = 1.0e-10 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect\_edge)) hneglect\_edge = h\_neglect\_edge}
\DoxyCodeLine{294 }
\DoxyCodeLine{295   \textcolor{keyword}{call }build\_reconstructions\_1d( cs, n0, h0, u0, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s, imethod,\&}
\DoxyCodeLine{296                                   hneglect, hneglect\_edge )}
\DoxyCodeLine{297 }
\DoxyCodeLine{298   \textcolor{keywordflow}{if} (cs\%check\_reconstruction) \textcolor{keyword}{call }check\_reconstructions\_1d(n0, h0, u0, cs\%degree, \&}
\DoxyCodeLine{299                                    cs\%boundary\_extrapolation, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s)}
\DoxyCodeLine{300 }
\DoxyCodeLine{301   \textcolor{comment}{! This is a temporary step prior to switching to remapping\_core\_h()}}
\DoxyCodeLine{302   \textcolor{keywordflow}{do} k = 1, n1}
\DoxyCodeLine{303     \textcolor{keywordflow}{if} (k<=n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{304       h1(k) = max( 0., h0(k) + ( dx(k+1) - dx(k) ) )}
\DoxyCodeLine{305     \textcolor{keywordflow}{else}}
\DoxyCodeLine{306       h1(k) = max( 0., dx(k+1) - dx(k) )}
\DoxyCodeLine{307 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{308 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{309   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, n1, h1, imethod, \&}
\DoxyCodeLine{310                             cs\%force\_bounds\_in\_subcell,u1, uh\_err )}
\DoxyCodeLine{311 \textcolor{comment}{! call remapByDeltaZ( n0, h0, u0, ppoly\_r\_E, ppoly\_r\_coefs, n1, dx, iMethod, u1, hNeglect )}}
\DoxyCodeLine{312 \textcolor{comment}{! call remapByProjection( n0, h0, u0, CS\%ppoly\_r, n1, h1, iMethod, u1, hNeglect )}}
\DoxyCodeLine{313 }
\DoxyCodeLine{314   \textcolor{keywordflow}{if} (cs\%check\_remapping) \textcolor{keywordflow}{then}}
\DoxyCodeLine{315     \textcolor{comment}{! Check errors and bounds}}
\DoxyCodeLine{316     \textcolor{keyword}{call }measure\_input\_bounds( n0, h0, u0, ppoly\_r\_e, h0tot, h0err, u0tot, u0err, u0min, u0max )}
\DoxyCodeLine{317     \textcolor{keyword}{call }measure\_output\_bounds( n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max )}
\DoxyCodeLine{318     \textcolor{keywordflow}{if} (imethod<5) \textcolor{keywordflow}{then} \textcolor{comment}{! We except PQM until we've debugged it}}
\DoxyCodeLine{319     \textcolor{keywordflow}{if} ( (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err .and. abs(h1tot-h0tot)<h0err+h1err) \&}
\DoxyCodeLine{320         .or. (u1min<u0min .or. u1max>u0max) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{321       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'iMethod = '},imethod}
\DoxyCodeLine{322       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h1err='},h1err}
\DoxyCodeLine{323       \textcolor{keywordflow}{if} (abs(h1tot-h0tot)>h0err+h1err) \&}
\DoxyCodeLine{324         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h1err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{325       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{'uh\_err='},uh\_err}
\DoxyCodeLine{326       \textcolor{keywordflow}{if} (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err) \&}
\DoxyCodeLine{327         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u1err+uh\_err,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{328       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0min='},u0min,\textcolor{stringliteral}{'u1min='},u1min}
\DoxyCodeLine{329       \textcolor{keywordflow}{if} (u1min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U minimum overshoot='},u1min-u0min,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{330       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0max='},u0max,\textcolor{stringliteral}{'u1max='},u1max}
\DoxyCodeLine{331       \textcolor{keywordflow}{if} (u1max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U maximum overshoot='},u1max-u0max,\textcolor{stringliteral}{' <-----!'}}
\DoxyCodeLine{332       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,6a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'h0'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'h1'},\textcolor{stringliteral}{'u1'}}
\DoxyCodeLine{333       \textcolor{keywordflow}{do} k = 1, max(n0,n1)}
\DoxyCodeLine{334         \textcolor{keywordflow}{if} (k<=min(n0,n1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{335           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2),h1(k),u1(k)}
\DoxyCodeLine{336         \textcolor{keywordflow}{elseif} (k>n0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{337           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,96x,1p2e24.16)'}) k,h1(k),u1(k)}
\DoxyCodeLine{338         \textcolor{keywordflow}{else}}
\DoxyCodeLine{339           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p4e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2)}
\DoxyCodeLine{340 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{341 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{342       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'Polynomial coefficients'}}
\DoxyCodeLine{343       \textcolor{keywordflow}{do} k = 1, n0}
\DoxyCodeLine{344         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,u0(k),ppoly\_r\_coefs(k,:)}
\DoxyCodeLine{345 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{346       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remapping\_core\_w: '}//\&}
\DoxyCodeLine{347              \textcolor{stringliteral}{'Remapping result is inconsistent!'} )}
\DoxyCodeLine{348 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{349 \textcolor{keywordflow}{    endif} \textcolor{comment}{! method<5}}
\DoxyCodeLine{350 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{351 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a50e96a4a1083bb1fae3ca0130b6a2c11}\label{namespacemom__remapping_a50e96a4a1083bb1fae3ca0130b6a2c11}} 
\index{mom\_remapping@{mom\_remapping}!remapping\_set\_param@{remapping\_set\_param}}
\index{remapping\_set\_param@{remapping\_set\_param}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remapping\_set\_param()}{remapping\_set\_param()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::remapping\+\_\+set\+\_\+param (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS,  }\item[{character(len=$\ast$), intent(in), optional}]{remapping\+\_\+scheme,  }\item[{logical, intent(in), optional}]{boundary\+\_\+extrapolation,  }\item[{logical, intent(in), optional}]{check\+\_\+reconstruction,  }\item[{logical, intent(in), optional}]{check\+\_\+remapping,  }\item[{logical, intent(in), optional}]{force\+\_\+bounds\+\_\+in\+\_\+subcell,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Set parameters within remapping object. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em remapping\+\_\+scheme} & Remapping scheme to use \\
\hline
\mbox{\texttt{ in}}  & {\em boundary\+\_\+extrapolation} & Indicate to extrapolate in boundary cells \\
\hline
\mbox{\texttt{ in}}  & {\em check\+\_\+reconstruction} & Indicate to check reconstructions \\
\hline
\mbox{\texttt{ in}}  & {\em check\+\_\+remapping} & Indicate to check results of remapping \\
\hline
\mbox{\texttt{ in}}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & Force subcells values to be bounded \\
\hline
\mbox{\texttt{ in}}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 92 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{92   \textcolor{keywordtype}{type}(remapping\_CS),         \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{93   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: remapping\_scheme\textcolor{comment}{ !< Remapping scheme to use}}
\DoxyCodeLine{94   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: boundary\_extrapolation\textcolor{comment}{ !< Indicate to extrapolate in boundary cells}}
\DoxyCodeLine{95   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: check\_reconstruction\textcolor{comment}{ !< Indicate to check reconstructions}}
\DoxyCodeLine{96   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: check\_remapping\textcolor{comment}{ !< Indicate to check results of remapping}}
\DoxyCodeLine{97   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: force\_bounds\_in\_subcell\textcolor{comment}{ !< Force subcells values to be bounded}}
\DoxyCodeLine{98   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}}
\DoxyCodeLine{99 }
\DoxyCodeLine{100   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(remapping\_scheme)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{101     \textcolor{keyword}{call }setreconstructiontype( remapping\_scheme, cs )}
\DoxyCodeLine{102 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{103   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(boundary\_extrapolation)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{104     cs\%boundary\_extrapolation = boundary\_extrapolation}
\DoxyCodeLine{105 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{106   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_reconstruction)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{107     cs\%check\_reconstruction = check\_reconstruction}
\DoxyCodeLine{108 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{109   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_remapping)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{110     cs\%check\_remapping = check\_remapping}
\DoxyCodeLine{111 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{112   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(force\_bounds\_in\_subcell)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{113     cs\%force\_bounds\_in\_subcell = force\_bounds\_in\_subcell}
\DoxyCodeLine{114 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{115   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(answers\_2018)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{116     cs\%answers\_2018 = answers\_2018}
\DoxyCodeLine{117 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5849f564453d5ed76fb4feffd41eca26}\label{namespacemom__remapping_a5849f564453d5ed76fb4feffd41eca26}} 
\index{mom\_remapping@{mom\_remapping}!remapping\_unit\_tests@{remapping\_unit\_tests}}
\index{remapping\_unit\_tests@{remapping\_unit\_tests}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{remapping\_unit\_tests()}{remapping\_unit\_tests()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+remapping\+::remapping\+\_\+unit\+\_\+tests (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose }\end{DoxyParamCaption})}



Runs unit tests on remapping functions. Should only be called from a single/root thread Returns True if a test fails, otherwise False. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\end{DoxyParams}


Definition at line 1617 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1617   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{1618   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1619   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: n0 = 4, n1 = 3, n2 = 6}
\DoxyCodeLine{1620 \textcolor{keywordtype}{  real} :: h0(n0), x0(n0+1), u0(n0)}
\DoxyCodeLine{1621 \textcolor{keywordtype}{  real} :: h1(n1), x1(n1+1), u1(n1), hn1(n1), dx1(n1+1)}
\DoxyCodeLine{1622 \textcolor{keywordtype}{  real} :: h2(n2), x2(n2+1), u2(n2), hn2(n2), dx2(n2+1)}
\DoxyCodeLine{1623   \textcolor{keyword}{data} u0 /9., 3., -3., -9./   \textcolor{comment}{! Linear profile, 4 at surface to -4 at bottom}}
\DoxyCodeLine{1624   \textcolor{keyword}{data} h0 /4*0.75/ \textcolor{comment}{! 4 uniform layers with total depth of 3}}
\DoxyCodeLine{1625   \textcolor{keyword}{data} h1 /3*1./   \textcolor{comment}{! 3 uniform layers with total depth of 3}}
\DoxyCodeLine{1626   \textcolor{keyword}{data} h2 /6*0.5/  \textcolor{comment}{! 6 uniform layers with total depth of 3}}
\DoxyCodeLine{1627   \textcolor{keywordtype}{type}(remapping\_CS) :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{1628 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: ppoly0\_E, ppoly0\_S, ppoly0\_coefs}
\DoxyCodeLine{1629   \textcolor{keywordtype}{logical} :: answers\_2018 \textcolor{comment}{!  If true use older, less acccurate expressions.}}
\DoxyCodeLine{1630   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{1631 \textcolor{keywordtype}{  real} :: err, h\_neglect, h\_neglect\_edge}
\DoxyCodeLine{1632   \textcolor{keywordtype}{logical} :: thisTest, v}
\DoxyCodeLine{1633 }
\DoxyCodeLine{1634   v = verbose}
\DoxyCodeLine{1635   answers\_2018 = .false. \textcolor{comment}{! .true.}}
\DoxyCodeLine{1636   h\_neglect = hneglect\_dflt}
\DoxyCodeLine{1637   h\_neglect\_edge = hneglect\_dflt ; \textcolor{keywordflow}{if} (answers\_2018) h\_neglect\_edge = 1.0e-10}
\DoxyCodeLine{1638 }
\DoxyCodeLine{1639   \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'==== MOM\_remapping: remapping\_unit\_tests ================='}}
\DoxyCodeLine{1640   remapping\_unit\_tests = .false. \textcolor{comment}{! Normally return false}}
\DoxyCodeLine{1641 }
\DoxyCodeLine{1642   thistest = .false.}
\DoxyCodeLine{1643   \textcolor{keyword}{call }buildgridfromh(n0, h0, x0)}
\DoxyCodeLine{1644   \textcolor{keywordflow}{do} i=1,n0+1}
\DoxyCodeLine{1645     err=x0(i)-0.75*real(i-1)}
\DoxyCodeLine{1646     \textcolor{keywordflow}{if} (abs(err)>real(i-1)*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1647 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1648   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed buildGridFromH() 1'}}
\DoxyCodeLine{1649   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1650   \textcolor{keyword}{call }buildgridfromh(n1, h1, x1)}
\DoxyCodeLine{1651   \textcolor{keywordflow}{do} i=1,n1+1}
\DoxyCodeLine{1652     err=x1(i)-real(i-1)}
\DoxyCodeLine{1653     \textcolor{keywordflow}{if} (abs(err)>real(i-1)*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1654 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1655   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed buildGridFromH() 2'}}
\DoxyCodeLine{1656   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1657 }
\DoxyCodeLine{1658   thistest = .false.}
\DoxyCodeLine{1659   \textcolor{keyword}{call }initialize\_remapping(cs, \textcolor{stringliteral}{'PPM\_H4'}, answers\_2018=answers\_2018)}
\DoxyCodeLine{1660   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h0 (test data)'}}
\DoxyCodeLine{1661   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n0,h0,x0,u0)}
\DoxyCodeLine{1662 }
\DoxyCodeLine{1663   \textcolor{keyword}{call }dzfromh1h2( n0, h0, n1, h1, dx1 )}
\DoxyCodeLine{1664   \textcolor{keyword}{call }remapping\_core\_w( cs, n0, h0, u0, n1, dx1, u1, h\_neglect, h\_neglect\_edge)}
\DoxyCodeLine{1665   \textcolor{keywordflow}{do} i=1,n1}
\DoxyCodeLine{1666     err=u1(i)-8.*(0.5*real(1+n1)-real(i))}
\DoxyCodeLine{1667     \textcolor{keywordflow}{if} (abs(err)>real(n1-1)*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1668 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1669   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h1 (by projection)'}}
\DoxyCodeLine{1670   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n1,h1,x1,u1)}
\DoxyCodeLine{1671   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapping\_core\_w()'}}
\DoxyCodeLine{1672   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1673 }
\DoxyCodeLine{1674   thistest = .false.}
\DoxyCodeLine{1675   \textcolor{keyword}{allocate}(ppoly0\_e(n0,2))}
\DoxyCodeLine{1676   \textcolor{keyword}{allocate}(ppoly0\_s(n0,2))}
\DoxyCodeLine{1677   \textcolor{keyword}{allocate}(ppoly0\_coefs(n0,cs\%degree+1))}
\DoxyCodeLine{1678 }
\DoxyCodeLine{1679   ppoly0\_e(:,:) = 0.0}
\DoxyCodeLine{1680   ppoly0\_s(:,:) = 0.0}
\DoxyCodeLine{1681   ppoly0\_coefs(:,:) = 0.0}
\DoxyCodeLine{1682 }
\DoxyCodeLine{1683   \textcolor{keyword}{call }edge\_values\_explicit\_h4( n0, h0, u0, ppoly0\_e, h\_neglect=1e-10, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1684   \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1685   \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, h\_neglect )}
\DoxyCodeLine{1686   u1(:) = 0.}
\DoxyCodeLine{1687   \textcolor{keyword}{call }remapbyprojection( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, \&}
\DoxyCodeLine{1688                           n1, h1, integration\_ppm, u1, h\_neglect )}
\DoxyCodeLine{1689   \textcolor{keywordflow}{do} i=1,n1}
\DoxyCodeLine{1690     err=u1(i)-8.*(0.5*real(1+n1)-real(i))}
\DoxyCodeLine{1691     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1692 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1693   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapByProjection()'}}
\DoxyCodeLine{1694   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1695 }
\DoxyCodeLine{1696   thistest = .false.}
\DoxyCodeLine{1697   u1(:) = 0.}
\DoxyCodeLine{1698   \textcolor{keyword}{call }remapbydeltaz( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, \&}
\DoxyCodeLine{1699                       n1, x1-x0(1:n1+1), \&}
\DoxyCodeLine{1700                       integration\_ppm, u1, hn1, h\_neglect )}
\DoxyCodeLine{1701   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h1 (by delta)'}}
\DoxyCodeLine{1702   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n1,h1,x1,u1)}
\DoxyCodeLine{1703   hn1=hn1-h1}
\DoxyCodeLine{1704   \textcolor{keywordflow}{do} i=1,n1}
\DoxyCodeLine{1705     err=u1(i)-8.*(0.5*real(1+n1)-real(i))}
\DoxyCodeLine{1706     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1707 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1708   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapByDeltaZ() 1'}}
\DoxyCodeLine{1709   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1710 }
\DoxyCodeLine{1711   thistest = .false.}
\DoxyCodeLine{1712   \textcolor{keyword}{call }buildgridfromh(n2, h2, x2)}
\DoxyCodeLine{1713   dx2(1:n0+1) = x2(1:n0+1) - x0}
\DoxyCodeLine{1714   dx2(n0+2:n2+1) = x2(n0+2:n2+1) - x0(n0+1)}
\DoxyCodeLine{1715   \textcolor{keyword}{call }remapbydeltaz( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, \&}
\DoxyCodeLine{1716                       n2, dx2, \&}
\DoxyCodeLine{1717                       integration\_ppm, u2, hn2, h\_neglect )}
\DoxyCodeLine{1718   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h2'}}
\DoxyCodeLine{1719   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n2,h2,x2,u2)}
\DoxyCodeLine{1720   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'hn2'}}
\DoxyCodeLine{1721   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n2,hn2,x2,u2)}
\DoxyCodeLine{1722 }
\DoxyCodeLine{1723   \textcolor{keywordflow}{do} i=1,n2}
\DoxyCodeLine{1724     err=u2(i)-8./2.*(0.5*real(1+n2)-real(i))}
\DoxyCodeLine{1725     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1726 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1727   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapByDeltaZ() 2'}}
\DoxyCodeLine{1728   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1729 }
\DoxyCodeLine{1730   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'Via sub-cells'}}
\DoxyCodeLine{1731   thistest = .false.}
\DoxyCodeLine{1732   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, \&}
\DoxyCodeLine{1733                             n2, h2, integration\_ppm, .false., u2, err )}
\DoxyCodeLine{1734   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n2,h2,x2,u2)}
\DoxyCodeLine{1735 }
\DoxyCodeLine{1736   \textcolor{keywordflow}{do} i=1,n2}
\DoxyCodeLine{1737     err=u2(i)-8./2.*(0.5*real(1+n2)-real(i))}
\DoxyCodeLine{1738     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.}
\DoxyCodeLine{1739 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1740   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remap\_via\_sub\_cells() 2'}}
\DoxyCodeLine{1741   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1742 }
\DoxyCodeLine{1743   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, \&}
\DoxyCodeLine{1744                             6, (/.125,.125,.125,.125,.125,.125/), integration\_ppm, .false., u2, err )}
\DoxyCodeLine{1745   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(6,h2,x2,u2)}
\DoxyCodeLine{1746 }
\DoxyCodeLine{1747   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, \&}
\DoxyCodeLine{1748                             3, (/2.25,1.5,1./), integration\_ppm, .false., u2, err )}
\DoxyCodeLine{1749   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(3,h2,x2,u2)}
\DoxyCodeLine{1750 }
\DoxyCodeLine{1751   \textcolor{keywordflow}{if} (.not. remapping\_unit\_tests) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'Pass'}}
\DoxyCodeLine{1752 }
\DoxyCodeLine{1753   \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'===== MOM\_remapping: new remapping\_unit\_tests =================='}}
\DoxyCodeLine{1754 }
\DoxyCodeLine{1755   \textcolor{keyword}{deallocate}(ppoly0\_e, ppoly0\_s, ppoly0\_coefs)}
\DoxyCodeLine{1756   \textcolor{keyword}{allocate}(ppoly0\_coefs(5,6))}
\DoxyCodeLine{1757   \textcolor{keyword}{allocate}(ppoly0\_e(5,2))}
\DoxyCodeLine{1758   \textcolor{keyword}{allocate}(ppoly0\_s(5,2))}
\DoxyCodeLine{1759 }
\DoxyCodeLine{1760   \textcolor{keyword}{call }pcm\_reconstruction(3, (/1.,2.,4./), ppoly0\_e(1:3,:), \&}
\DoxyCodeLine{1761                           ppoly0\_coefs(1:3,:) )}
\DoxyCodeLine{1762   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1763     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,2.,4./), \textcolor{stringliteral}{'PCM: left edges'})}
\DoxyCodeLine{1764   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1765     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,2.,4./), \textcolor{stringliteral}{'PCM: right edges'})}
\DoxyCodeLine{1766   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1767     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,2.,4./), \textcolor{stringliteral}{'PCM: P0'})}
\DoxyCodeLine{1768 }
\DoxyCodeLine{1769   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,1.,1./), (/1.,3.,5./), ppoly0\_e(1:3,:), \&}
\DoxyCodeLine{1770                           ppoly0\_coefs(1:3,:), h\_neglect )}
\DoxyCodeLine{1771   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1772     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,2.,5./), \textcolor{stringliteral}{'Unlim PLM: left edges'})}
\DoxyCodeLine{1773   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1774     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,4.,5./), \textcolor{stringliteral}{'Unlim PLM: right edges'})}
\DoxyCodeLine{1775   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1776     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,2.,5./), \textcolor{stringliteral}{'Unlim PLM: P0'})}
\DoxyCodeLine{1777   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1778     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,2.,0./), \textcolor{stringliteral}{'Unlim PLM: P1'})}
\DoxyCodeLine{1779 }
\DoxyCodeLine{1780   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,1.,1./), (/1.,2.,7./), ppoly0\_e(1:3,:), \&}
\DoxyCodeLine{1781                           ppoly0\_coefs(1:3,:), h\_neglect )}
\DoxyCodeLine{1782   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1783     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,1.,7./), \textcolor{stringliteral}{'Left lim PLM: left edges'})}
\DoxyCodeLine{1784   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1785     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,3.,7./), \textcolor{stringliteral}{'Left lim PLM: right edges'})}
\DoxyCodeLine{1786   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1787     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,1.,7./), \textcolor{stringliteral}{'Left lim PLM: P0'})}
\DoxyCodeLine{1788   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1789     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,2.,0./), \textcolor{stringliteral}{'Left lim PLM: P1'})}
\DoxyCodeLine{1790 }
\DoxyCodeLine{1791   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,1.,1./), (/1.,6.,7./), ppoly0\_e(1:3,:), \&}
\DoxyCodeLine{1792                           ppoly0\_coefs(1:3,:), h\_neglect )}
\DoxyCodeLine{1793   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1794     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,5.,7./), \textcolor{stringliteral}{'Right lim PLM: left edges'})}
\DoxyCodeLine{1795   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1796     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,7.,7./), \textcolor{stringliteral}{'Right lim PLM: right edges'})}
\DoxyCodeLine{1797   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1798     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,5.,7./), \textcolor{stringliteral}{'Right lim PLM: P0'})}
\DoxyCodeLine{1799   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1800     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,2.,0./), \textcolor{stringliteral}{'Right lim PLM: P1'})}
\DoxyCodeLine{1801 }
\DoxyCodeLine{1802   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,2.,3./), (/1.,4.,9./), ppoly0\_e(1:3,:), \&}
\DoxyCodeLine{1803                           ppoly0\_coefs(1:3,:), h\_neglect )}
\DoxyCodeLine{1804   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1805     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,2.,9./), \textcolor{stringliteral}{'Non-uniform line PLM: left edges'})}
\DoxyCodeLine{1806   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1807     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,6.,9./), \textcolor{stringliteral}{'Non-uniform line PLM: right edges'})}
\DoxyCodeLine{1808   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1809     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,2.,9./), \textcolor{stringliteral}{'Non-uniform line PLM: P0'})}
\DoxyCodeLine{1810   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1811     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,4.,0./), \textcolor{stringliteral}{'Non-uniform line PLM: P1'})}
\DoxyCodeLine{1812 }
\DoxyCodeLine{1813   \textcolor{keyword}{call }edge\_values\_explicit\_h4( 5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0\_e, \&}
\DoxyCodeLine{1814                                 h\_neglect=1e-10, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1815   \textcolor{comment}{! The next two tests currently fail due to roundoff, but pass when given a reasonable tolerance.}}
\DoxyCodeLine{1816   thistest = test\_answer(v, 5, ppoly0\_e(:,1), (/0.,2.,4.,6.,8./), \textcolor{stringliteral}{'Line H4: left edges'}, tol=8.0e-15)}
\DoxyCodeLine{1817   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1818   thistest = test\_answer(v, 5, ppoly0\_e(:,2), (/2.,4.,6.,8.,10./), \textcolor{stringliteral}{'Line H4: right edges'}, tol=1.0e-14)}
\DoxyCodeLine{1819   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1820   ppoly0\_e(:,1) = (/0.,2.,4.,6.,8./)}
\DoxyCodeLine{1821   ppoly0\_e(:,2) = (/2.,4.,6.,8.,10./)}
\DoxyCodeLine{1822   \textcolor{keyword}{call }ppm\_reconstruction(5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0\_e(1:5,:), \&}
\DoxyCodeLine{1823                               ppoly0\_coefs(1:5,:), h\_neglect, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1824   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1825     test\_answer(v, 5, ppoly0\_coefs(:,1), (/1.,2.,4.,6.,9./), \textcolor{stringliteral}{'Line PPM: P0'})}
\DoxyCodeLine{1826   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1827     test\_answer(v, 5, ppoly0\_coefs(:,2), (/0.,2.,2.,2.,0./), \textcolor{stringliteral}{'Line PPM: P1'})}
\DoxyCodeLine{1828   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1829     test\_answer(v, 5, ppoly0\_coefs(:,3), (/0.,0.,0.,0.,0./), \textcolor{stringliteral}{'Line PPM: P2'})}
\DoxyCodeLine{1830 }
\DoxyCodeLine{1831   \textcolor{keyword}{call }edge\_values\_explicit\_h4( 5, (/1.,1.,1.,1.,1./), (/1.,1.,7.,19.,37./), ppoly0\_e, \&}
\DoxyCodeLine{1832                                 h\_neglect=1e-10, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1833   \textcolor{comment}{! The next two tests are now passing when answers\_2018 = .false., but otherwise only work to roundoff.}}
\DoxyCodeLine{1834   thistest = test\_answer(v, 5, ppoly0\_e(:,1), (/3.,0.,3.,12.,27./), \textcolor{stringliteral}{'Parabola H4: left edges'}, tol=2.7e-14)}
\DoxyCodeLine{1835   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1836   thistest = test\_answer(v, 5, ppoly0\_e(:,2), (/0.,3.,12.,27.,48./), \textcolor{stringliteral}{'Parabola H4: right edges'}, tol=4.8e-14)}
\DoxyCodeLine{1837   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest}
\DoxyCodeLine{1838   ppoly0\_e(:,1) = (/0.,0.,3.,12.,27./)}
\DoxyCodeLine{1839   ppoly0\_e(:,2) = (/0.,3.,12.,27.,48./)}
\DoxyCodeLine{1840   \textcolor{keyword}{call }ppm\_reconstruction(5, (/1.,1.,1.,1.,1./), (/0.,1.,7.,19.,37./), ppoly0\_e(1:5,:), \&}
\DoxyCodeLine{1841                           ppoly0\_coefs(1:5,:), h\_neglect, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1842   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1843     test\_answer(v, 5, ppoly0\_e(:,1), (/0.,0.,3.,12.,37./), \textcolor{stringliteral}{'Parabola PPM: left edges'})}
\DoxyCodeLine{1844   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1845     test\_answer(v, 5, ppoly0\_e(:,2), (/0.,3.,12.,27.,37./), \textcolor{stringliteral}{'Parabola PPM: right edges'})}
\DoxyCodeLine{1846   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1847     test\_answer(v, 5, ppoly0\_coefs(:,1), (/0.,0.,3.,12.,37./), \textcolor{stringliteral}{'Parabola PPM: P0'})}
\DoxyCodeLine{1848   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1849     test\_answer(v, 5, ppoly0\_coefs(:,2), (/0.,0.,6.,12.,0./), \textcolor{stringliteral}{'Parabola PPM: P1'})}
\DoxyCodeLine{1850   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1851     test\_answer(v, 5, ppoly0\_coefs(:,3), (/0.,3.,3.,3.,0./), \textcolor{stringliteral}{'Parabola PPM: P2'})}
\DoxyCodeLine{1852 }
\DoxyCodeLine{1853   ppoly0\_e(:,1) = (/0.,0.,6.,10.,15./)}
\DoxyCodeLine{1854   ppoly0\_e(:,2) = (/0.,6.,12.,17.,15./)}
\DoxyCodeLine{1855   \textcolor{keyword}{call }ppm\_reconstruction(5, (/1.,1.,1.,1.,1./), (/0.,5.,7.,16.,15./), ppoly0\_e(1:5,:), \&}
\DoxyCodeLine{1856                           ppoly0\_coefs(1:5,:), h\_neglect, answers\_2018=answers\_2018 )}
\DoxyCodeLine{1857   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1858     test\_answer(v, 5, ppoly0\_e(:,1), (/0.,3.,6.,16.,15./), \textcolor{stringliteral}{'Limits PPM: left edges'})}
\DoxyCodeLine{1859   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1860     test\_answer(v, 5, ppoly0\_e(:,2), (/0.,6.,9.,16.,15./), \textcolor{stringliteral}{'Limits PPM: right edges'})}
\DoxyCodeLine{1861   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1862     test\_answer(v, 5, ppoly0\_coefs(:,1), (/0.,3.,6.,16.,15./), \textcolor{stringliteral}{'Limits PPM: P0'})}
\DoxyCodeLine{1863   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1864     test\_answer(v, 5, ppoly0\_coefs(:,2), (/0.,6.,0.,0.,0./), \textcolor{stringliteral}{'Limits PPM: P1'})}
\DoxyCodeLine{1865   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1866     test\_answer(v, 5, ppoly0\_coefs(:,3), (/0.,-3.,3.,0.,0./), \textcolor{stringliteral}{'Limits PPM: P2'})}
\DoxyCodeLine{1867 }
\DoxyCodeLine{1868   \textcolor{keyword}{call }plm\_reconstruction(4, (/0.,1.,1.,0./), (/5.,4.,2.,1./), ppoly0\_e(1:4,:), \&}
\DoxyCodeLine{1869                           ppoly0\_coefs(1:4,:), h\_neglect )}
\DoxyCodeLine{1870   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1871     test\_answer(v, 4, ppoly0\_e(1:4,1), (/5.,5.,3.,1./), \textcolor{stringliteral}{'PPM: left edges h=0110'})}
\DoxyCodeLine{1872   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1873     test\_answer(v, 4, ppoly0\_e(1:4,2), (/5.,3.,1.,1./), \textcolor{stringliteral}{'PPM: right edges h=0110'})}
\DoxyCodeLine{1874   \textcolor{keyword}{call }remap\_via\_sub\_cells( 4, (/0.,1.,1.,0./), (/5.,4.,2.,1./), ppoly0\_e(1:4,:), \&}
\DoxyCodeLine{1875                             ppoly0\_coefs(1:4,:), \&}
\DoxyCodeLine{1876                             2, (/1.,1./), integration\_plm, .false., u2, err )}
\DoxyCodeLine{1877   remapping\_unit\_tests = remapping\_unit\_tests .or. \&}
\DoxyCodeLine{1878     test\_answer(v, 2, u2, (/4.,2./), \textcolor{stringliteral}{'PLM: remapped  h=0110->h=11'})}
\DoxyCodeLine{1879 }
\DoxyCodeLine{1880   \textcolor{keyword}{deallocate}(ppoly0\_e, ppoly0\_s, ppoly0\_coefs)}
\DoxyCodeLine{1881 }
\DoxyCodeLine{1882   \textcolor{keywordflow}{if} (.not. remapping\_unit\_tests) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'Pass'}}
\DoxyCodeLine{1883 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a41a89ac62578250500b7a450d5fdfae7}\label{namespacemom__remapping_a41a89ac62578250500b7a450d5fdfae7}} 
\index{mom\_remapping@{mom\_remapping}!setreconstructiontype@{setreconstructiontype}}
\index{setreconstructiontype@{setreconstructiontype}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{setreconstructiontype()}{setreconstructiontype()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::setreconstructiontype (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{string,  }\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Changes the method of reconstruction Use this routine to parse a string parameter specifying the reconstruction and re-\/allocates work arrays appropriately. It is called from initialize\+\_\+remapping but can be called from an external module too. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em string} & String to parse for method \\
\hline
\mbox{\texttt{ in,out}}  & {\em cs} & Remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 1572 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1572   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: string\textcolor{comment}{ !< String to parse for method}}
\DoxyCodeLine{1573   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}}
\DoxyCodeLine{1574   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1575   \textcolor{keywordtype}{integer} :: degree}
\DoxyCodeLine{1576   degree = -99}
\DoxyCodeLine{1577   \textcolor{keywordflow}{select case} ( uppercase(trim(string)) )}
\DoxyCodeLine{1578     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PCM"})}
\DoxyCodeLine{1579       cs\%remapping\_scheme = remapping\_pcm}
\DoxyCodeLine{1580       degree = 0}
\DoxyCodeLine{1581     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PLM"})}
\DoxyCodeLine{1582       cs\%remapping\_scheme = remapping\_plm}
\DoxyCodeLine{1583       degree = 1}
\DoxyCodeLine{1584     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM\_H4"})}
\DoxyCodeLine{1585       cs\%remapping\_scheme = remapping\_ppm\_h4}
\DoxyCodeLine{1586       degree = 2}
\DoxyCodeLine{1587     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM\_IH4"})}
\DoxyCodeLine{1588       cs\%remapping\_scheme = remapping\_ppm\_ih4}
\DoxyCodeLine{1589       degree = 2}
\DoxyCodeLine{1590     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PQM\_IH4IH3"})}
\DoxyCodeLine{1591       cs\%remapping\_scheme = remapping\_pqm\_ih4ih3}
\DoxyCodeLine{1592       degree = 4}
\DoxyCodeLine{1593     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PQM\_IH6IH5"})}
\DoxyCodeLine{1594       cs\%remapping\_scheme = remapping\_pqm\_ih6ih5}
\DoxyCodeLine{1595       degree = 4}
\DoxyCodeLine{1596 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{1597       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"setReconstructionType: "}//\&}
\DoxyCodeLine{1598        \textcolor{stringliteral}{"Unrecognized choice for REMAPPING\_SCHEME ("}//trim(string)//\textcolor{stringliteral}{")."})}
\DoxyCodeLine{1599 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{1600 }
\DoxyCodeLine{1601   cs\%degree = degree}
\DoxyCodeLine{1602 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a3235506c107c81b116cec92952dd8cbb}\label{namespacemom__remapping_a3235506c107c81b116cec92952dd8cbb}} 
\index{mom\_remapping@{mom\_remapping}!test\_answer@{test\_answer}}
\index{test\_answer@{test\_answer}!mom\_remapping@{mom\_remapping}}
\subsubsection{\texorpdfstring{test\_answer()}{test\_answer()}}
{\footnotesize\ttfamily logical function mom\+\_\+remapping\+::test\+\_\+answer (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{integer, intent(in)}]{n,  }\item[{real, dimension(n), intent(in)}]{u,  }\item[{real, dimension(n), intent(in)}]{u\+\_\+true,  }\item[{character(len=$\ast$), intent(in)}]{label,  }\item[{real, intent(in), optional}]{tol }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if any cell of u and u\+\_\+true are not identical. Returns false otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em n} & Number of cells in u \\
\hline
\mbox{\texttt{ in}}  & {\em u} & Values to test \\
\hline
\mbox{\texttt{ in}}  & {\em u\+\_\+true} & Values to test against (correct answer) \\
\hline
\mbox{\texttt{ in}}  & {\em label} & Message \\
\hline
\mbox{\texttt{ in}}  & {\em tol} & The tolerance for differences between u and u\+\_\+true \\
\hline
\end{DoxyParams}


Definition at line 1888 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1888   \textcolor{keywordtype}{logical},            \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}}
\DoxyCodeLine{1889   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{      !< Number of cells in u}}
\DoxyCodeLine{1890 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n)}, \textcolor{keywordtype}{intent(in)} :: u\textcolor{comment}{      !< Values to test}}
\DoxyCodeLine{1891 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(n)}, \textcolor{keywordtype}{intent(in)} :: u\_true\textcolor{comment}{ !< Values to test against (correct answer)}}
\DoxyCodeLine{1892   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)} :: label\textcolor{comment}{  !< Message}}
\DoxyCodeLine{1893 \textcolor{keywordtype}{  real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: tol\textcolor{comment}{    !< The tolerance for differences between u and u\_true}}
\DoxyCodeLine{1894   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1895 \textcolor{keywordtype}{  real} :: tolerance \textcolor{comment}{! The tolerance for differences between u and u\_true}}
\DoxyCodeLine{1896   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1897 }
\DoxyCodeLine{1898   tolerance = 0.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tol)) tolerance = tol}
\DoxyCodeLine{1899   test\_answer = .false.}
\DoxyCodeLine{1900   \textcolor{keywordflow}{do} k = 1, n}
\DoxyCodeLine{1901     \textcolor{keywordflow}{if} (abs(u(k) - u\_true(k)) > tolerance) test\_answer = .true.}
\DoxyCodeLine{1902 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1903   \textcolor{keywordflow}{if} (test\_answer .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1904     \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(a4,2a24,x,a)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'Calculated value'},\textcolor{stringliteral}{'Correct value'},label}
\DoxyCodeLine{1905     \textcolor{keywordflow}{do} k = 1, n}
\DoxyCodeLine{1906       \textcolor{keywordflow}{if} (abs(u(k) - u\_true(k)) > tolerance) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1907         \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(i4,1p2e24.16,a,1pe24.16,a)'}) k,u(k),u\_true(k),\textcolor{stringliteral}{' err='},u(k)-u\_true(k),\textcolor{stringliteral}{' < wrong'}}
\DoxyCodeLine{1908         \textcolor{keyword}{write}(stderr,\textcolor{stringliteral}{'(i4,1p2e24.16,a,1pe24.16,a)'}) k,u(k),u\_true(k),\textcolor{stringliteral}{' err='},u(k)-u\_true(k),\textcolor{stringliteral}{' < wrong'}}
\DoxyCodeLine{1909       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1910         \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(i4,1p2e24.16)'}) k,u(k),u\_true(k)}
\DoxyCodeLine{1911 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1912 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1913 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1914 }

\end{DoxyCode}
