\hypertarget{namespacemom__regridding}{}\doxysection{mom\+\_\+regridding Module Reference}
\label{namespacemom__regridding}\index{mom\_regridding@{mom\_regridding}}


\doxysubsection{Detailed Description}
Generates vertical grids as part of the A\+LE algorithm. 

A vertical grid is defined solely by the cell thicknesses, $h$. Most calculations in this module start with the coordinate at the bottom of the column set to -\/depth, and use a increasing value of coordinate with decreasing k. This is consistent with the rest of M\+O\+M6 that uses position, $z$ which is a negative quantity for most of the ocean.

A change in grid is define through a change in position of the interfaces\+: \[ z^n_{k+1/2} = z^{n-1}_{k+1/2} + \Delta z_{k+1/2} \] with the positive upward coordinate convention \[ z_{k-1/2} = z_{k+1/2} + h_k \] so that \[ h^n_k = h^{n-1}_k + ( \Delta z_{k-1/2} - \Delta z_{k+1/2} ) \]

Original date of creation\+: 2008.\+06.\+09 by L. White \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Regridding control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_a8c91ba68f0906e1fc76b7008caf6288e}{initialize\+\_\+regridding}} (CS, GV, US, max\+\_\+depth, param\+\_\+file, mdl, coord\+\_\+mode, param\+\_\+prefix, param\+\_\+suffix)
\begin{DoxyCompactList}\small\item\em Initialization and configures a regridding control structure based on customizable run-\/time parameters. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_ad4abdb8447ed3f4f769b822a468728b1}{check\+\_\+grid\+\_\+def}} (filename, varname, expected\+\_\+units, msg, ierr)
\begin{DoxyCompactList}\small\item\em Do some basic checks on the vertical grid definition file, variable. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_a9f55ab3a80ab1202b7664e9c65ebf08b}{end\+\_\+regridding}} (CS)
\begin{DoxyCompactList}\small\item\em Deallocation of regridding memory. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_ab354fe3423a39fef6f2b66f409b1682c}{regridding\+\_\+main}} (remap\+CS, CS, G, GV, h, tv, h\+\_\+new, dz\+Interface, frac\+\_\+shelf\+\_\+h, conv\+\_\+adjust)
\begin{DoxyCompactList}\small\item\em Dispatching regridding routine for orchestrating regridding \& remapping. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a8dd75489564f85609033f53c0cb16cbb}{calc\+\_\+h\+\_\+new\+\_\+by\+\_\+dz}} (CS, G, GV, h, dz\+Interface, h\+\_\+new)
\begin{DoxyCompactList}\small\item\em Calculates h\+\_\+new from h + delta\+\_\+k dz\+Interface. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_a810d6a0658d645ac7a9e2b6680ce819c}{check\+\_\+remapping\+\_\+grid}} (G, GV, h, dz\+Interface, msg)
\begin{DoxyCompactList}\small\item\em Check that the total thickness of two grids match. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_ab2a6be87039f49176d91a494126d8430}{check\+\_\+grid\+\_\+column}} (nk, depth, h, dz\+Interface, msg)
\begin{DoxyCompactList}\small\item\em Check that the total thickness of new and old grids are consistent. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a9dddf53999f90d1a4edc79179c5b5da4}{filtered\+\_\+grid\+\_\+motion}} (CS, nk, z\+\_\+old, z\+\_\+new, dz\+\_\+g)
\begin{DoxyCompactList}\small\item\em Returns the change in interface position motion after filtering and assuming the top and bottom interfaces do not move. The filtering is a function of depth, and is applied as the integrated average filtering over the trajectory of the interface. By design, this code can not give tangled interfaces provided that z\+\_\+old and z\+\_\+new are not already tangled. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a55e6873a74355daea004d39c452e0069}{build\+\_\+zstar\+\_\+grid}} (CS, G, GV, h, dz\+Interface, frac\+\_\+shelf\+\_\+h)
\begin{DoxyCompactList}\small\item\em Builds a z$\ast$-\/ccordinate grid with partial steps (Adcroft and Campin, 2004). z$\ast$ is defined as z$\ast$ = (z-\/eta)/(H+eta)$\ast$H s.\+t. z$\ast$=0 when z=eta and z$\ast$=-\/H when z=-\/H . \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a455d807ccfbbfd109be231321bec1038}{build\+\_\+sigma\+\_\+grid}} (CS, G, GV, h, dz\+Interface)
\begin{DoxyCompactList}\small\item\em This routine builds a grid based on terrain-\/following coordinates. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_aa3db078bb52a4993c82d35c1b250a898}{build\+\_\+rho\+\_\+grid}} (G, GV, US, h, tv, dz\+Interface, remap\+CS, CS)
\begin{DoxyCompactList}\small\item\em This routine builds a new grid based on a given set of target interface densities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a74433d7b55b2ba3a333553563d55089f}{build\+\_\+grid\+\_\+hycom1}} (G, GV, US, h, tv, h\+\_\+new, dz\+Interface, CS)
\begin{DoxyCompactList}\small\item\em Builds a simple Hy\+C\+O\+M-\/like grid with the deepest location of potential density interpolated from the column profile and a clipping of depth for each interface to a fixed z$\ast$ or p$\ast$ grid. This should probably be (optionally?) changed to find the nearest location of the target density. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_aa57d2b70fe2247b5fd8283d7e3fb2cfd}{build\+\_\+grid\+\_\+adaptive}} (G, GV, US, h, tv, dz\+Interface, remap\+CS, CS)
\begin{DoxyCompactList}\small\item\em This subroutine builds an adaptive grid that follows density surfaces where possible, subject to constraints on the smoothness of interface heights. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a63b857ebd60054fd49dca31d7f10d2d0}{build\+\_\+grid\+\_\+slight}} (G, GV, US, h, tv, dz\+Interface, CS)
\begin{DoxyCompactList}\small\item\em Builds a grid that tracks density interfaces for water that is denser than the surface density plus an increment of some number of layers, and uses all lighter layers uniformly above this location. Note that this amounts to interpolating to find the depth of an arbitrary (non-\/integer) interface index which should make the results vary smoothly in space to the extent that the surface density and interior stratification vary smoothly in space. Over shallow topography, this will tend to give a uniform sigma-\/like coordinate. For sufficiently shallow water, a minimum grid spacing is used to avoid certain instabilities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a7752ab22440e0d5f9a0b11d583acb812}{adjust\+\_\+interface\+\_\+motion}} (CS, nk, h\+\_\+old, dz\+\_\+int)
\begin{DoxyCompactList}\small\item\em Adjust dz\+\_\+\+Interface to ensure non-\/negative future thicknesses. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a53fe5957610e488f1fb9052ff69007ec}{build\+\_\+grid\+\_\+arbitrary}} (G, GV, h, dz\+Interface, h\+\_\+new, CS)
\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_aeb36a31003c4887ea1af82c11c627f2f}{inflate\+\_\+vanished\+\_\+layers\+\_\+old}} (CS, G, GV, h)
\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_aac58190f39678cb94e0f918455804f43}{convective\+\_\+adjustment}} (G, GV, h, tv)
\begin{DoxyCompactList}\small\item\em Achieve convective adjustment by swapping layers. \end{DoxyCompactList}\item 
real function, dimension(nk), public \mbox{\hyperlink{namespacemom__regridding_a8b3b0c1555006f196d9bb1baededd9e6}{uniformresolution}} (nk, coord\+Mode, max\+Depth, rho\+Light, rho\+Heavy)
\begin{DoxyCompactList}\small\item\em Return a uniform resolution vector in the units of the coordinate. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_ad9614000d524a78e043d52f9734314e0}{initcoord}} (CS, GV, US, coord\+\_\+mode)
\begin{DoxyCompactList}\small\item\em Initialize the coordinate resolutions by calling the appropriate initialization routine for the specified coordinate mode. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_a162e9f816bc892550624d781fdddd6ca}{setcoordinateresolution}} (dz, CS, scale)
\begin{DoxyCompactList}\small\item\em Set the fixed resolution data. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_ab6ada39c6f95e652907bab93f9c5a3f1}{set\+\_\+target\+\_\+densities\+\_\+from\+\_\+gv}} (GV, US, CS)
\begin{DoxyCompactList}\small\item\em Set target densities based on the old Rlay variable. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_ae7eade38ab8e2adb0797a7191ddebb18}{set\+\_\+target\+\_\+densities}} (CS, rho\+\_\+int)
\begin{DoxyCompactList}\small\item\em Set target densities based on vector of interface values. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_aac547ec199090852d539c7aefc44dfa7}{set\+\_\+regrid\+\_\+max\+\_\+depths}} (CS, max\+\_\+depths, units\+\_\+to\+\_\+H)
\begin{DoxyCompactList}\small\item\em Set maximum interface depths based on a vector of input values. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_ae91ca3f1376b3c72940268b5d9f87bb4}{set\+\_\+regrid\+\_\+max\+\_\+thickness}} (CS, max\+\_\+h, units\+\_\+to\+\_\+H)
\begin{DoxyCompactList}\small\item\em Set maximum layer thicknesses based on a vector of input values. \end{DoxyCompactList}\item 
real function, dimension(cs\%nk), public \mbox{\hyperlink{namespacemom__regridding_af36c8643e6b6b97e6ab94f9a0d00ca32}{getcoordinateresolution}} (CS, undo\+\_\+scaling)
\begin{DoxyCompactList}\small\item\em Query the fixed resolution data. \end{DoxyCompactList}\item 
real function, dimension(cs\%nk+1), public \mbox{\hyperlink{namespacemom__regridding_af20d0def7ceffa33a6595c6c9e8613fd}{getcoordinateinterfaces}} (CS, undo\+\_\+scaling)
\begin{DoxyCompactList}\small\item\em Query the target coordinate interface positions. \end{DoxyCompactList}\item 
character(len=20) function, public \mbox{\hyperlink{namespacemom__regridding_ad693fbb3424bb0ba9d0ad8878828e604}{getcoordinateunits}} (CS)
\begin{DoxyCompactList}\small\item\em Query the target coordinate units. \end{DoxyCompactList}\item 
character(len=20) function, public \mbox{\hyperlink{namespacemom__regridding_ac1e1f08a6d33ab71e6a3c5008c519ee6}{getcoordinateshortname}} (CS)
\begin{DoxyCompactList}\small\item\em Query the short name of the coordinate. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__regridding_a88398318fb996137b3f0d79b7fc8c4e9}{set\+\_\+regrid\+\_\+params}} (CS, boundary\+\_\+extrapolation, min\+\_\+thickness, old\+\_\+grid\+\_\+weight, interp\+\_\+scheme, depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+shallow, depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+deep, compress\+\_\+fraction, ref\+\_\+pressure, dz\+\_\+min\+\_\+surface, nz\+\_\+fixed\+\_\+surface, Rho\+\_\+\+M\+L\+\_\+avg\+\_\+depth, nlay\+\_\+\+M\+L\+\_\+to\+\_\+interior, fix\+\_\+haloclines, halocline\+\_\+filt\+\_\+len, halocline\+\_\+strat\+\_\+tol, integrate\+\_\+downward\+\_\+for\+\_\+e, remap\+\_\+answers\+\_\+2018, adapt\+Time\+Ratio, adapt\+Zoom, adapt\+Zoom\+Coeff, adapt\+Buoy\+Coeff, adapt\+Alpha, adapt\+Do\+Min, adapt\+Drho0)
\begin{DoxyCompactList}\small\item\em Can be used to set any of the parameters for M\+O\+M\+\_\+regridding. \end{DoxyCompactList}\item 
integer function, public \mbox{\hyperlink{namespacemom__regridding_ab4d037c069414d7a709219350e7b71ed}{get\+\_\+regrid\+\_\+size}} (CS)
\begin{DoxyCompactList}\small\item\em Returns the number of levels/layers in the regridding control structure. \end{DoxyCompactList}\item 
type(zlike\+\_\+cs) function, public \mbox{\hyperlink{namespacemom__regridding_a8ff04f8857825fcc814cdad9684717e7}{get\+\_\+zlike\+\_\+cs}} (CS)
\begin{DoxyCompactList}\small\item\em This returns a copy of the zlike\+\_\+\+CS stored in the regridding control structure. \end{DoxyCompactList}\item 
type(sigma\+\_\+cs) function, public \mbox{\hyperlink{namespacemom__regridding_aef5b07937353a9fe2ce51dd6c2beed54}{get\+\_\+sigma\+\_\+cs}} (CS)
\begin{DoxyCompactList}\small\item\em This returns a copy of the sigma\+\_\+\+CS stored in the regridding control structure. \end{DoxyCompactList}\item 
type(rho\+\_\+cs) function, public \mbox{\hyperlink{namespacemom__regridding_a358f07a447816230753c8d3d5a0fb8af}{get\+\_\+rho\+\_\+cs}} (CS)
\begin{DoxyCompactList}\small\item\em This returns a copy of the rho\+\_\+\+CS stored in the regridding control structure. \end{DoxyCompactList}\item 
real function, dimension(cs\%nk), public \mbox{\hyperlink{namespacemom__regridding_a1587a58d8fe87432c3f7817952014584}{getstaticthickness}} (CS, S\+SH, depth)
\begin{DoxyCompactList}\small\item\em Return coordinate-\/derived thicknesses for fixed coordinate systems. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__regridding_a2becd8126867cdce125b31e07d13065e}{dz\+\_\+function1}} (string, dz)
\begin{DoxyCompactList}\small\item\em Parses a string and generates a dz(\+:) profile that goes like k$\ast$$\ast$power. \end{DoxyCompactList}\item 
integer function \mbox{\hyperlink{namespacemom__regridding_a64758b08fbd1d2a98d4d7de593fb49be}{rho\+\_\+function1}} (string, rho\+\_\+target)
\begin{DoxyCompactList}\small\item\em Parses a string and generates a rho\+\_\+target(\+:) profile with refined resolution downward and returns the number of levels. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__regridding_a0b3b3b00c51baa3b8652ee98884252e5}\label{namespacemom__regridding_a0b3b3b00c51baa3b8652ee98884252e5}} 
character(len= $\ast$), parameter, public \mbox{\hyperlink{namespacemom__regridding_a0b3b3b00c51baa3b8652ee98884252e5}{regriddingcoordinatemodedoc}} = \char`\"{} L\+A\+Y\+ER -\/ Isopycnal or stacked shallow water layers\textbackslash{}n\char`\"{}// \char`\"{} Z\+S\+T\+AR, Z$\ast$ -\/ stretched geopotential z$\ast$\textbackslash{}n\char`\"{}// \char`\"{} S\+I\+G\+M\+A\+\_\+\+S\+H\+E\+L\+F\+\_\+\+Z\+S\+T\+AR -\/ stretched geopotential z$\ast$ ignoring shelf\textbackslash{}n\char`\"{}// \char`\"{} S\+I\+G\+MA -\/ terrain following coordinates\textbackslash{}n\char`\"{}// \char`\"{} R\+HO -\/ continuous isopycnal\textbackslash{}n\char`\"{}// \char`\"{} H\+Y\+C\+O\+M1 -\/ Hy\+C\+OM-\/like hybrid coordinate\textbackslash{}n\char`\"{}// \char`\"{} S\+L\+I\+G\+HT -\/ stretched coordinates above continuous isopycnal\textbackslash{}n\char`\"{}// \char`\"{} A\+D\+A\+P\+T\+I\+VE -\/ optimize for smooth neutral density surfaces\char`\"{}
\begin{DoxyCompactList}\small\item\em Documentation for coordinate options. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__regridding_a78401834f39a900c91dca44c7b6e2509}\label{namespacemom__regridding_a78401834f39a900c91dca44c7b6e2509}} 
character(len= $\ast$), parameter, public \mbox{\hyperlink{namespacemom__regridding_a78401834f39a900c91dca44c7b6e2509}{regriddinginterpschemedoc}} = \char`\"{} P1\+M\+\_\+\+H2 (2nd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} P1\+M\+\_\+\+H4 (2nd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} P1\+M\+\_\+\+I\+H4 (2nd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} P\+LM (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`\"{} P3\+M\+\_\+\+I\+H4\+I\+H3 (4th-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} P3\+M\+\_\+\+I\+H6\+I\+H5 (4th-\/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)\char`\"{}
\begin{DoxyCompactList}\small\item\em Documentation for regridding interpolation schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__regridding_ab4f3052ef1f1b1ed4395678d6cbdf7ff}\label{namespacemom__regridding_ab4f3052ef1f1b1ed4395678d6cbdf7ff}} 
character(len= $\ast$), parameter, public \mbox{\hyperlink{namespacemom__regridding_ab4f3052ef1f1b1ed4395678d6cbdf7ff}{regriddingdefaultinterpscheme}} = \char`\"{}P1\+M\+\_\+\+H2\char`\"{}
\begin{DoxyCompactList}\small\item\em Default interpolation scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__regridding_ace083ec9749efc2bcb7d3a33b97c0678}\label{namespacemom__regridding_ace083ec9749efc2bcb7d3a33b97c0678}} 
logical, parameter, public \mbox{\hyperlink{namespacemom__regridding_ace083ec9749efc2bcb7d3a33b97c0678}{regriddingdefaultboundaryextrapolation}} = .false.
\begin{DoxyCompactList}\small\item\em Default mode for boundary extrapolation. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__regridding_a219230a6fd36ab9b6ec19109f60fdcee}\label{namespacemom__regridding_a219230a6fd36ab9b6ec19109f60fdcee}} 
real, parameter, public \mbox{\hyperlink{namespacemom__regridding_a219230a6fd36ab9b6ec19109f60fdcee}{regriddingdefaultminthickness}} = 1.e-\/3
\begin{DoxyCompactList}\small\item\em Default minimum thickness for some coordinate generation modes. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__regridding_a7752ab22440e0d5f9a0b11d583acb812}\label{namespacemom__regridding_a7752ab22440e0d5f9a0b11d583acb812}} 
\index{mom\_regridding@{mom\_regridding}!adjust\_interface\_motion@{adjust\_interface\_motion}}
\index{adjust\_interface\_motion@{adjust\_interface\_motion}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{adjust\_interface\_motion()}{adjust\_interface\_motion()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::adjust\+\_\+interface\+\_\+motion (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{h\+\_\+old,  }\item[{real, dimension(cs\%nk+1), intent(inout)}]{dz\+\_\+int }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adjust dz\+\_\+\+Interface to ensure non-\/negative future thicknesses. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers in h\+\_\+old \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+old} & Minium allowed thickness of h \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em dz\+\_\+int} & Minium allowed thickness of h \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1666   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1667   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{ !< Number of layers in h\_old}}
\DoxyCodeLine{1668 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},      \textcolor{keywordtype}{intent(in)}    :: h\_old\textcolor{comment}{ !< Minium allowed thickness of h [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1669 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \textcolor{keywordtype}{intent(inout)} :: dz\_int\textcolor{comment}{ !< Minium allowed thickness of h [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1670   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1671   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1672 \textcolor{keywordtype}{  real} :: h\_new, eps, h\_total, h\_err}
\DoxyCodeLine{1673 }
\DoxyCodeLine{1674   eps = 1. ; eps = epsilon(eps)}
\DoxyCodeLine{1675 }
\DoxyCodeLine{1676   h\_total = 0. ; h\_err = 0.}
\DoxyCodeLine{1677   \textcolor{keywordflow}{do} k = 1, min(cs\%nk,nk)}
\DoxyCodeLine{1678     h\_total = h\_total + h\_old(k)}
\DoxyCodeLine{1679     h\_err = h\_err + max( h\_old(k), abs(dz\_int(k)), abs(dz\_int(k+1)) )*eps}
\DoxyCodeLine{1680     h\_new = h\_old(k) + ( dz\_int(k) -\/ dz\_int(k+1) )}
\DoxyCodeLine{1681     \textcolor{keywordflow}{if} (h\_new < -\/3.0*h\_err) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1682       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'h<0 at k='},k,\textcolor{stringliteral}{'h\_old='},h\_old(k), \&}
\DoxyCodeLine{1683         \textcolor{stringliteral}{'wup='},dz\_int(k),\textcolor{stringliteral}{'wdn='},dz\_int(k+1),\textcolor{stringliteral}{'dw\_dz='},dz\_int(k) -\/ dz\_int(k+1), \&}
\DoxyCodeLine{1684         \textcolor{stringliteral}{'h\_new='},h\_new,\textcolor{stringliteral}{'h\_err='},h\_err}
\DoxyCodeLine{1685       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding: adjust\_interface\_motion() -\/ '}//\&}
\DoxyCodeLine{1686                      \textcolor{stringliteral}{'implied h<0 is larger than roundoff!'})}
\DoxyCodeLine{1687 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1688 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1689   \textcolor{keywordflow}{if} (cs\%nk>nk) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1690     \textcolor{keywordflow}{do} k = nk+1, cs\%nk}
\DoxyCodeLine{1691       h\_err = h\_err + max( abs(dz\_int(k)), abs(dz\_int(k+1)) )*eps}
\DoxyCodeLine{1692       h\_new = ( dz\_int(k) -\/ dz\_int(k+1) )}
\DoxyCodeLine{1693       \textcolor{keywordflow}{if} (h\_new < -\/3.0*h\_err) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1694         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'h<0 at k='},k,\textcolor{stringliteral}{'h\_old was empty'},\&}
\DoxyCodeLine{1695           \textcolor{stringliteral}{'wup='},dz\_int(k),\textcolor{stringliteral}{'wdn='},dz\_int(k+1),\textcolor{stringliteral}{'dw\_dz='},dz\_int(k) -\/ dz\_int(k+1), \&}
\DoxyCodeLine{1696           \textcolor{stringliteral}{'h\_new='},h\_new,\textcolor{stringliteral}{'h\_err='},h\_err}
\DoxyCodeLine{1697         \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding: adjust\_interface\_motion() -\/ '}//\&}
\DoxyCodeLine{1698                        \textcolor{stringliteral}{'implied h<0 is larger than roundoff!'})}
\DoxyCodeLine{1699 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1700 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1701 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1702   \textcolor{keywordflow}{do} k = min(cs\%nk,nk),2,-\/1}
\DoxyCodeLine{1703     h\_new = h\_old(k) + ( dz\_int(k) -\/ dz\_int(k+1) )}
\DoxyCodeLine{1704     \textcolor{keywordflow}{if} (h\_new<cs\%min\_thickness) \&}
\DoxyCodeLine{1705       dz\_int(k) = ( dz\_int(k+1) -\/ h\_old(k) ) + cs\%min\_thickness \textcolor{comment}{! Implies next h\_new = min\_thickness}}
\DoxyCodeLine{1706     h\_new = h\_old(k) + ( dz\_int(k) -\/ dz\_int(k+1) )}
\DoxyCodeLine{1707     \textcolor{keywordflow}{if} (h\_new<0.) \&}
\DoxyCodeLine{1708       dz\_int(k) = ( 1. -\/ eps ) * ( dz\_int(k+1) -\/ h\_old(k) ) \textcolor{comment}{! Backup in case min\_thickness==0}}
\DoxyCodeLine{1709     h\_new = h\_old(k) + ( dz\_int(k) -\/ dz\_int(k+1) )}
\DoxyCodeLine{1710     \textcolor{keywordflow}{if} (h\_new<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1711       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'h<0 at k='},k,\textcolor{stringliteral}{'h\_old='},h\_old(k), \&}
\DoxyCodeLine{1712         \textcolor{stringliteral}{'wup='},dz\_int(k),\textcolor{stringliteral}{'wdn='},dz\_int(k+1),\textcolor{stringliteral}{'dw\_dz='},dz\_int(k) -\/ dz\_int(k+1), \&}
\DoxyCodeLine{1713         \textcolor{stringliteral}{'h\_new='},h\_new}
\DoxyCodeLine{1714       stop \textcolor{stringliteral}{'Still did not work!'}}
\DoxyCodeLine{1715       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding: adjust\_interface\_motion() -\/ '}//\&}
\DoxyCodeLine{1716                      \textcolor{stringliteral}{'Repeated adjustment for roundoff h<0 failed!'})}
\DoxyCodeLine{1717 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1718 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1719  \textcolor{comment}{!if (dz\_int(1)/=0.) stop 'MOM\_regridding: adjust\_interface\_motion() surface moved'}}
\DoxyCodeLine{1720 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_aa57d2b70fe2247b5fd8283d7e3fb2cfd}\label{namespacemom__regridding_aa57d2b70fe2247b5fd8283d7e3fb2cfd}} 
\index{mom\_regridding@{mom\_regridding}!build\_grid\_adaptive@{build\_grid\_adaptive}}
\index{build\_grid\_adaptive@{build\_grid\_adaptive}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_grid\_adaptive()}{build\_grid\_adaptive()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+grid\+\_\+adaptive (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke+1), intent(inout)}]{dz\+Interface,  }\item[{type(remapping\+\_\+cs), intent(in)}]{remap\+CS,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine builds an adaptive grid that follows density surfaces where possible, subject to constraints on the smoothness of interface heights. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & The change in interface depth \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em remapcs} & The remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1533   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1534   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{1535   \textcolor{keywordtype}{type}(unit\_scale\_type),                       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1536 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1537   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                       \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various}}
\DoxyCodeLine{1538 \textcolor{comment}{                                                                     !! thermodynamic variables}}
\DoxyCodeLine{1539 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV)+1)}, \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< The change in interface depth}}
\DoxyCodeLine{1540 \textcolor{comment}{                                                                     !! [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1541   \textcolor{keywordtype}{type}(remapping\_CS),                          \textcolor{keywordtype}{intent(in)}    :: remapCS\textcolor{comment}{ !< The remapping control structure}}
\DoxyCodeLine{1542   \textcolor{keywordtype}{type}(regridding\_CS),                         \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{   !< Regridding control structure}}
\DoxyCodeLine{1543 }
\DoxyCodeLine{1544   \textcolor{comment}{! local variables}}
\DoxyCodeLine{1545   \textcolor{keywordtype}{integer} :: i, j, k, nz \textcolor{comment}{! indices and dimension lengths}}
\DoxyCodeLine{1546   \textcolor{comment}{! temperature, salinity and pressure on interfaces}}
\DoxyCodeLine{1547 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV)+1)} :: tInt, sInt}
\DoxyCodeLine{1548   \textcolor{comment}{! current interface positions and after tendency term is applied}}
\DoxyCodeLine{1549   \textcolor{comment}{! positive downward}}
\DoxyCodeLine{1550 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV)+1)} :: zInt \textcolor{comment}{! Interface depths [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1551 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: zNext  \textcolor{comment}{! New interface depths [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1552 }
\DoxyCodeLine{1553   nz = gv\%ke}
\DoxyCodeLine{1554 }
\DoxyCodeLine{1555   \textcolor{comment}{! position surface at z = 0.}}
\DoxyCodeLine{1556   zint(:,:,1) = 0.}
\DoxyCodeLine{1557 }
\DoxyCodeLine{1558   \textcolor{comment}{! work on interior interfaces}}
\DoxyCodeLine{1559   \textcolor{keywordflow}{do} k = 2, nz ; \textcolor{keywordflow}{do} j = g\%jsc-\/2,g\%jec+2 ; \textcolor{keywordflow}{do} i = g\%isc-\/2,g\%iec+2}
\DoxyCodeLine{1560     tint(i,j,k) = 0.5 * (tv\%T(i,j,k-\/1) + tv\%T(i,j,k))}
\DoxyCodeLine{1561     sint(i,j,k) = 0.5 * (tv\%S(i,j,k-\/1) + tv\%S(i,j,k))}
\DoxyCodeLine{1562     zint(i,j,k) = zint(i,j,k-\/1) + h(i,j,k-\/1) \textcolor{comment}{! zInt in [H]}}
\DoxyCodeLine{1563 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1564 }
\DoxyCodeLine{1565   \textcolor{comment}{! top and bottom temp/salt interfaces are just the layer}}
\DoxyCodeLine{1566   \textcolor{comment}{! average values}}
\DoxyCodeLine{1567   tint(:,:,1) = tv\%T(:,:,1) ; tint(:,:,nz+1) = tv\%T(:,:,nz)}
\DoxyCodeLine{1568   sint(:,:,1) = tv\%S(:,:,1) ; sint(:,:,nz+1) = tv\%S(:,:,nz)}
\DoxyCodeLine{1569 }
\DoxyCodeLine{1570   \textcolor{comment}{! set the bottom interface depth}}
\DoxyCodeLine{1571   zint(:,:,nz+1)  = zint(:,:,nz) + h(:,:,nz)}
\DoxyCodeLine{1572 }
\DoxyCodeLine{1573   \textcolor{comment}{! calculate horizontal density derivatives (alpha/beta)}}
\DoxyCodeLine{1574   \textcolor{comment}{! between cells in a 5-\/point stencil, columnwise}}
\DoxyCodeLine{1575   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1576     \textcolor{keywordflow}{if} (g\%mask2dT(i,j) < 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1577       dzinterface(i,j,:) = 0. \textcolor{comment}{! land point, don't move interfaces, and skip}}
\DoxyCodeLine{1578       cycle}
\DoxyCodeLine{1579 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1580 }
\DoxyCodeLine{1581     \textcolor{keyword}{call }build\_adapt\_column(cs\%adapt\_CS, g, gv, us, tv, i, j, zint, tint, sint, h, znext)}
\DoxyCodeLine{1582 }
\DoxyCodeLine{1583     \textcolor{keyword}{call }filtered\_grid\_motion(cs, nz, zint(i,j,:), znext, dzinterface(i,j,:))}
\DoxyCodeLine{1584     \textcolor{comment}{! convert from depth to z}}
\DoxyCodeLine{1585     \textcolor{keywordflow}{do} k = 1, nz+1 ; dzinterface(i,j,k) = -\/dzinterface(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1586     \textcolor{keyword}{call }adjust\_interface\_motion(cs, nz, h(i,j,:), dzinterface(i,j,:))}
\DoxyCodeLine{1587 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a53fe5957610e488f1fb9052ff69007ec}\label{namespacemom__regridding_a53fe5957610e488f1fb9052ff69007ec}} 
\index{mom\_regridding@{mom\_regridding}!build\_grid\_arbitrary@{build\_grid\_arbitrary}}
\index{build\_grid\_arbitrary@{build\_grid\_arbitrary}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_grid\_arbitrary()}{build\_grid\_arbitrary()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+grid\+\_\+arbitrary (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g), szk\+\_\+(gv)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g), szk\+\_\+(gv)+1), intent(inout)}]{dz\+Interface,  }\item[{real, intent(inout)}]{h\+\_\+new,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure\\
\hline
\mbox{\texttt{ in}}  & {\em h} & Original layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & The change in interface depth \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+new} & New layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1727 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1728 \textcolor{comment}{! This routine builds a grid based on arbitrary rules}}
\DoxyCodeLine{1729 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1730 }
\DoxyCodeLine{1731   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1732   \textcolor{keywordtype}{type}(ocean\_grid\_type),                        \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{1733   \textcolor{keywordtype}{type}(verticalGrid\_type),                      \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{1734 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(GV))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Original layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1735 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(GV)+1)}, \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< The change in interface}}
\DoxyCodeLine{1736 \textcolor{comment}{                                                                    !! depth [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1737 \textcolor{keywordtype}{  real},                                         \textcolor{keywordtype}{intent(inout)} :: h\_new\textcolor{comment}{ !< New layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1738   \textcolor{keywordtype}{type}(regridding\_CS),                          \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1739 }
\DoxyCodeLine{1740   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1741   \textcolor{keywordtype}{integer}   :: i, j, k}
\DoxyCodeLine{1742   \textcolor{keywordtype}{integer}   :: nz}
\DoxyCodeLine{1743 \textcolor{keywordtype}{  real}      :: z\_inter(SZK\_(GV)+1)}
\DoxyCodeLine{1744 \textcolor{keywordtype}{  real}      :: total\_height}
\DoxyCodeLine{1745 \textcolor{keywordtype}{  real}      :: delta\_h}
\DoxyCodeLine{1746 \textcolor{keywordtype}{  real}      :: max\_depth}
\DoxyCodeLine{1747 \textcolor{keywordtype}{  real}      :: eta              \textcolor{comment}{! local elevation}}
\DoxyCodeLine{1748 \textcolor{keywordtype}{  real}      :: local\_depth}
\DoxyCodeLine{1749 \textcolor{keywordtype}{  real}      :: x1, y1, x2, y2}
\DoxyCodeLine{1750 \textcolor{keywordtype}{  real}      :: x, t}
\DoxyCodeLine{1751 }
\DoxyCodeLine{1752   nz = gv\%ke}
\DoxyCodeLine{1753   max\_depth = g\%max\_depth*gv\%Z\_to\_H}
\DoxyCodeLine{1754 }
\DoxyCodeLine{1755   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1}
\DoxyCodeLine{1756     \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1757 }
\DoxyCodeLine{1758       \textcolor{comment}{! Local depth}}
\DoxyCodeLine{1759       local\_depth = g\%bathyT(i,j)*gv\%Z\_to\_H}
\DoxyCodeLine{1760 }
\DoxyCodeLine{1761       \textcolor{comment}{! Determine water column height}}
\DoxyCodeLine{1762       total\_height = 0.0}
\DoxyCodeLine{1763       \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{1764         total\_height = total\_height + h(i,j,k)}
\DoxyCodeLine{1765 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1766 }
\DoxyCodeLine{1767       eta = total\_height -\/ local\_depth}
\DoxyCodeLine{1768 }
\DoxyCodeLine{1769       \textcolor{comment}{! Compute new thicknesses based on stretched water column}}
\DoxyCodeLine{1770       delta\_h = (max\_depth + eta) / nz}
\DoxyCodeLine{1771 }
\DoxyCodeLine{1772       \textcolor{comment}{! Define interfaces}}
\DoxyCodeLine{1773       z\_inter(1) = eta}
\DoxyCodeLine{1774       \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{1775         z\_inter(k+1) = z\_inter(k) -\/ delta\_h}
\DoxyCodeLine{1776 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1777 }
\DoxyCodeLine{1778       \textcolor{comment}{! Refine grid in the middle}}
\DoxyCodeLine{1779       \textcolor{keywordflow}{do} k = 1,nz+1}
\DoxyCodeLine{1780         x1 = 0.35; y1 = 0.45; x2 = 0.65; y2 = 0.55}
\DoxyCodeLine{1781 }
\DoxyCodeLine{1782         x = -\/ ( z\_inter(k) -\/ eta ) / max\_depth}
\DoxyCodeLine{1783 }
\DoxyCodeLine{1784         \textcolor{keywordflow}{if} ( x <= x1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1785           t = y1*x/x1}
\DoxyCodeLine{1786         \textcolor{keywordflow}{elseif} ( (x > x1 ) .and. ( x < x2 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1787           t = y1 + (y2-\/y1) * (x-\/x1) / (x2-\/x1)}
\DoxyCodeLine{1788         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1789           t = y2 + (1.0-\/y2) * (x-\/x2) / (1.0-\/x2)}
\DoxyCodeLine{1790 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1791 }
\DoxyCodeLine{1792         z\_inter(k) = -\/t * max\_depth + eta}
\DoxyCodeLine{1793 }
\DoxyCodeLine{1794 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1795 }
\DoxyCodeLine{1796       \textcolor{comment}{! Modify interface heights to account for topography}}
\DoxyCodeLine{1797       z\_inter(nz+1) = -\/ local\_depth}
\DoxyCodeLine{1798 }
\DoxyCodeLine{1799       \textcolor{comment}{! Modify interface heights to avoid layers of zero thicknesses}}
\DoxyCodeLine{1800       \textcolor{keywordflow}{do} k = nz,1,-\/1}
\DoxyCodeLine{1801         \textcolor{keywordflow}{if} ( z\_inter(k) < (z\_inter(k+1) + cs\%min\_thickness) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1802           z\_inter(k) = z\_inter(k+1) + cs\%min\_thickness}
\DoxyCodeLine{1803 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1804 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1805 }
\DoxyCodeLine{1806       \textcolor{comment}{! Chnage in interface position}}
\DoxyCodeLine{1807       x = 0. \textcolor{comment}{! Left boundary at x=0}}
\DoxyCodeLine{1808       dzinterface(i,j,1) = 0.}
\DoxyCodeLine{1809       \textcolor{keywordflow}{do} k = 2,nz}
\DoxyCodeLine{1810         x = x + h(i,j,k)}
\DoxyCodeLine{1811         dzinterface(i,j,k) = z\_inter(k) -\/ x}
\DoxyCodeLine{1812 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1813       dzinterface(i,j,nz+1) = 0.}
\DoxyCodeLine{1814 }
\DoxyCodeLine{1815 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1816 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1817 }
\DoxyCodeLine{1818 stop \textcolor{stringliteral}{'OOOOOOPS'} \textcolor{comment}{! For some reason the gnu compiler will not let me delete this}}
\DoxyCodeLine{1819                 \textcolor{comment}{! routine????}}
\DoxyCodeLine{1820 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a74433d7b55b2ba3a333553563d55089f}\label{namespacemom__regridding_a74433d7b55b2ba3a333553563d55089f}} 
\index{mom\_regridding@{mom\_regridding}!build\_grid\_hycom1@{build\_grid\_hycom1}}
\index{build\_grid\_hycom1@{build\_grid\_hycom1}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_grid\_hycom1()}{build\_grid\_hycom1()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+grid\+\_\+hycom1 (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,cs\%nk), intent(inout)}]{h\+\_\+new,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,cs\%nk+1), intent(inout)}]{dz\+Interface,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Builds a simple Hy\+C\+O\+M-\/like grid with the deepest location of potential density interpolated from the column profile and a clipping of depth for each interface to a fixed z$\ast$ or p$\ast$ grid. This should probably be (optionally?) changed to find the nearest location of the target density. 

\begin{DoxyRemark}{Remarks}
\{ Based on Bleck, 2002\+: An oceanice general circulation model framed in hybrid isopycnic-\/\+Cartesian coordinates, Ocean Modelling 37, 55-\/88. \href{http://dx.doi.org/10.1016/S1463-5003(01)00012-9}{\texttt{ http\+://dx.\+doi.\+org/10.\+1016/\+S1463-\/5003(01)00012-\/9}} \} 
\end{DoxyRemark}

\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Existing model thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamics structure \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+new} & New layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & Changes in interface position \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1461   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{1462   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{1463   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1464 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Existing model thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1465   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamics structure}}
\DoxyCodeLine{1466   \textcolor{keywordtype}{type}(regridding\_CS),                       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1467 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS\%nk)},    \textcolor{keywordtype}{intent(inout)} :: h\_new\textcolor{comment}{ !< New layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1468 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS\%nk+1)},  \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< Changes in interface position}}
\DoxyCodeLine{1469 }
\DoxyCodeLine{1470   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1471 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: z\_col \textcolor{comment}{! Source interface positions relative to the surface [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1472 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)} :: z\_col\_new \textcolor{comment}{! New interface positions relative to the surface [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1473 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: dz\_col  \textcolor{comment}{! The realized change in z\_col [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1474 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))}   :: p\_col   \textcolor{comment}{! Layer center pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1475 \textcolor{keywordtype}{  real} :: ref\_pres  \textcolor{comment}{! The reference pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1476   \textcolor{keywordtype}{integer}   :: i, j, k, nki}
\DoxyCodeLine{1477 \textcolor{keywordtype}{  real} :: depth}
\DoxyCodeLine{1478 \textcolor{keywordtype}{  real} :: h\_neglect, h\_neglect\_edge}
\DoxyCodeLine{1479 }
\DoxyCodeLine{1480   \textcolor{keywordflow}{if} (.not.cs\%remap\_answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1481     h\_neglect = gv\%H\_subroundoff ; h\_neglect\_edge = gv\%H\_subroundoff}
\DoxyCodeLine{1482   \textcolor{keywordflow}{elseif} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1483     h\_neglect = gv\%m\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%m\_to\_H*1.0e-\/10}
\DoxyCodeLine{1484   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1485     h\_neglect = gv\%kg\_m2\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%kg\_m2\_to\_H*1.0e-\/10}
\DoxyCodeLine{1486 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1487 }
\DoxyCodeLine{1488   \textcolor{keywordflow}{if} (.not.cs\%target\_density\_set) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"build\_grid\_HyCOM1 : "}//\&}
\DoxyCodeLine{1489         \textcolor{stringliteral}{"Target densities must be set before build\_grid\_HyCOM1 is called."})}
\DoxyCodeLine{1490 }
\DoxyCodeLine{1491   nki = min(gv\%ke, cs\%nk)}
\DoxyCodeLine{1492 }
\DoxyCodeLine{1493   \textcolor{comment}{! Build grid based on target interface densities}}
\DoxyCodeLine{1494   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1495     \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1496 }
\DoxyCodeLine{1497       depth = g\%bathyT(i,j) * gv\%Z\_to\_H}
\DoxyCodeLine{1498 }
\DoxyCodeLine{1499       z\_col(1) = 0. \textcolor{comment}{! Work downward rather than bottom up}}
\DoxyCodeLine{1500       \textcolor{keywordflow}{do} k = 1, gv\%ke}
\DoxyCodeLine{1501         z\_col(k+1) = z\_col(k) + h(i,j,k)}
\DoxyCodeLine{1502         p\_col(k) = tv\%P\_Ref + cs\%compressibility\_fraction * \&}
\DoxyCodeLine{1503              ( 0.5 * ( z\_col(k) + z\_col(k+1) ) * (gv\%H\_to\_RZ*gv\%g\_Earth) -\/ tv\%P\_Ref )}
\DoxyCodeLine{1504 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1505 }
\DoxyCodeLine{1506       \textcolor{keyword}{call }build\_hycom1\_column(cs\%hycom\_CS, tv\%eqn\_of\_state, gv\%ke, depth, \&}
\DoxyCodeLine{1507                                h(i,j,:), tv\%T(i,j,:), tv\%S(i,j,:), p\_col, \&}
\DoxyCodeLine{1508                                z\_col, z\_col\_new, zscale=gv\%Z\_to\_H, \&}
\DoxyCodeLine{1509                                h\_neglect=h\_neglect, h\_neglect\_edge=h\_neglect\_edge)}
\DoxyCodeLine{1510 }
\DoxyCodeLine{1511       \textcolor{comment}{! Calculate the final change in grid position after blending new and old grids}}
\DoxyCodeLine{1512       \textcolor{keyword}{call }filtered\_grid\_motion( cs, gv\%ke, z\_col, z\_col\_new, dz\_col )}
\DoxyCodeLine{1513 }
\DoxyCodeLine{1514       \textcolor{comment}{! This adjusts things robust to round-\/off errors}}
\DoxyCodeLine{1515       dz\_col(:) = -\/dz\_col(:)}
\DoxyCodeLine{1516       \textcolor{keyword}{call }adjust\_interface\_motion( cs, gv\%ke, h(i,j,:), dz\_col(:) )}
\DoxyCodeLine{1517 }
\DoxyCodeLine{1518       dzinterface(i,j,1:nki+1) = dz\_col(1:nki+1)}
\DoxyCodeLine{1519       \textcolor{keywordflow}{if} (nki<cs\%nk) dzinterface(i,j,nki+2:cs\%nk+1) = 0.}
\DoxyCodeLine{1520 }
\DoxyCodeLine{1521     \textcolor{keywordflow}{else} \textcolor{comment}{! on land}}
\DoxyCodeLine{1522       dzinterface(i,j,:) = 0.}
\DoxyCodeLine{1523 \textcolor{keywordflow}{    endif} \textcolor{comment}{! mask2dT}}
\DoxyCodeLine{1524 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i,j}}
\DoxyCodeLine{1525 }
\DoxyCodeLine{1526   \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{1527 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a63b857ebd60054fd49dca31d7f10d2d0}\label{namespacemom__regridding_a63b857ebd60054fd49dca31d7f10d2d0}} 
\index{mom\_regridding@{mom\_regridding}!build\_grid\_slight@{build\_grid\_slight}}
\index{build\_grid\_slight@{build\_grid\_slight}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_grid\_slight()}{build\_grid\_slight()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+grid\+\_\+slight (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(gv)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(gv)+1), intent(inout)}]{dz\+Interface,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Builds a grid that tracks density interfaces for water that is denser than the surface density plus an increment of some number of layers, and uses all lighter layers uniformly above this location. Note that this amounts to interpolating to find the depth of an arbitrary (non-\/integer) interface index which should make the results vary smoothly in space to the extent that the surface density and interior stratification vary smoothly in space. Over shallow topography, this will tend to give a uniform sigma-\/like coordinate. For sufficiently shallow water, a minimum grid spacing is used to avoid certain instabilities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Existing model thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamics structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & Changes in interface position \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1600   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{1601   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{1602   \textcolor{keywordtype}{type}(unit\_scale\_type),                       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1603 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Existing model thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1604   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                       \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamics structure}}
\DoxyCodeLine{1605 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV)+1)}, \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< Changes in interface position}}
\DoxyCodeLine{1606   \textcolor{keywordtype}{type}(regridding\_CS),                         \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1607 }
\DoxyCodeLine{1608 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: z\_col   \textcolor{comment}{! Interface positions relative to the surface [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1609 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: z\_col\_new \textcolor{comment}{! Interface positions relative to the surface [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1610 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: dz\_col  \textcolor{comment}{! The realized change in z\_col [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1611 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))}   :: p\_col   \textcolor{comment}{! Layer center pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{1612 \textcolor{keywordtype}{  real} :: depth}
\DoxyCodeLine{1613   \textcolor{keywordtype}{integer} :: i, j, k, nz}
\DoxyCodeLine{1614 \textcolor{keywordtype}{  real} :: h\_neglect, h\_neglect\_edge}
\DoxyCodeLine{1615 }
\DoxyCodeLine{1616   \textcolor{keywordflow}{if} (.not.cs\%remap\_answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1617     h\_neglect = gv\%H\_subroundoff ; h\_neglect\_edge = gv\%H\_subroundoff}
\DoxyCodeLine{1618   \textcolor{keywordflow}{elseif} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1619     h\_neglect = gv\%m\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%m\_to\_H*1.0e-\/10}
\DoxyCodeLine{1620   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1621     h\_neglect = gv\%kg\_m2\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%kg\_m2\_to\_H*1.0e-\/10}
\DoxyCodeLine{1622 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1623 }
\DoxyCodeLine{1624   nz = gv\%ke}
\DoxyCodeLine{1625 }
\DoxyCodeLine{1626   \textcolor{keywordflow}{if} (.not.cs\%target\_density\_set) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"build\_grid\_SLight : "}//\&}
\DoxyCodeLine{1627         \textcolor{stringliteral}{"Target densities must be set before build\_grid\_SLight is called."})}
\DoxyCodeLine{1628 }
\DoxyCodeLine{1629   \textcolor{comment}{! Build grid based on target interface densities}}
\DoxyCodeLine{1630   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1631     \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1632 }
\DoxyCodeLine{1633       depth = g\%bathyT(i,j) * gv\%Z\_to\_H}
\DoxyCodeLine{1634       z\_col(1) = 0. \textcolor{comment}{! Work downward rather than bottom up}}
\DoxyCodeLine{1635       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1636         z\_col(k+1) = z\_col(k) + h(i,j,k)}
\DoxyCodeLine{1637         p\_col(k) = tv\%P\_Ref + cs\%compressibility\_fraction * \&}
\DoxyCodeLine{1638                     ( 0.5 * ( z\_col(k) + z\_col(k+1) ) * (gv\%H\_to\_RZ*gv\%g\_Earth) -\/ tv\%P\_Ref )}
\DoxyCodeLine{1639 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1640 }
\DoxyCodeLine{1641       \textcolor{keyword}{call }build\_slight\_column(cs\%slight\_CS, tv\%eqn\_of\_state, gv\%H\_to\_RZ*gv\%g\_Earth, \&}
\DoxyCodeLine{1642                           gv\%H\_subroundoff, nz, depth, h(i, j, :), \&}
\DoxyCodeLine{1643                           tv\%T(i, j, :), tv\%S(i, j, :), p\_col, z\_col, z\_col\_new, \&}
\DoxyCodeLine{1644                           h\_neglect=h\_neglect, h\_neglect\_edge=h\_neglect\_edge)}
\DoxyCodeLine{1645 }
\DoxyCodeLine{1646       \textcolor{comment}{! Calculate the final change in grid position after blending new and old grids}}
\DoxyCodeLine{1647       \textcolor{keyword}{call }filtered\_grid\_motion( cs, nz, z\_col, z\_col\_new, dz\_col )}
\DoxyCodeLine{1648       \textcolor{keywordflow}{do} k=1,nz+1 ; dzinterface(i,j,k) = -\/dz\_col(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1649 \textcolor{preprocessor}{\#ifdef \_\_DO\_SAFETY\_CHECKS\_\_}}
\DoxyCodeLine{1650 \textcolor{preprocessor}{}      \textcolor{keywordflow}{if} (dzinterface(i,j,1) /= 0.) stop \textcolor{stringliteral}{'build\_grid\_SLight: Surface moved?!'}}
\DoxyCodeLine{1651       \textcolor{keywordflow}{if} (dzinterface(i,j,nz+1) /= 0.) stop \textcolor{stringliteral}{'build\_grid\_SLight: Bottom moved?!'}}
\DoxyCodeLine{1652 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1653 \textcolor{preprocessor}{}}
\DoxyCodeLine{1654       \textcolor{comment}{! This adjusts things robust to round-\/off errors}}
\DoxyCodeLine{1655       \textcolor{keyword}{call }adjust\_interface\_motion( cs, nz, h(i,j,:), dzinterface(i,j,:) )}
\DoxyCodeLine{1656 }
\DoxyCodeLine{1657     \textcolor{keywordflow}{else} \textcolor{comment}{! on land}}
\DoxyCodeLine{1658       dzinterface(i,j,:) = 0.}
\DoxyCodeLine{1659 \textcolor{keywordflow}{    endif} \textcolor{comment}{! mask2dT}}
\DoxyCodeLine{1660 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i,j}}
\DoxyCodeLine{1661 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_aa3db078bb52a4993c82d35c1b250a898}\label{namespacemom__regridding_aa3db078bb52a4993c82d35c1b250a898}} 
\index{mom\_regridding@{mom\_regridding}!build\_rho\_grid@{build\_rho\_grid}}
\index{build\_rho\_grid@{build\_rho\_grid}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_rho\_grid()}{build\_rho\_grid()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+rho\+\_\+grid (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,  gv \%ke+1), intent(inout)}]{dz\+Interface,  }\item[{type(remapping\+\_\+cs), intent(in)}]{remap\+CS,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This routine builds a new grid based on a given set of target interface densities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamics structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & The change in interface depth \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em remapcs} & The remapping control structure \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1328 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1329 \textcolor{comment}{! This routine builds a new grid based on a given set of target interface}}
\DoxyCodeLine{1330 \textcolor{comment}{! densities (these target densities are computed by taking the mean value}}
\DoxyCodeLine{1331 \textcolor{comment}{! of given layer densities). The algorithn operates as follows within each}}
\DoxyCodeLine{1332 \textcolor{comment}{! column:}}
\DoxyCodeLine{1333 \textcolor{comment}{! 1. Given T \& S within each layer, the layer densities are computed.}}
\DoxyCodeLine{1334 \textcolor{comment}{! 2. Based on these layer densities, a global density profile is reconstructed}}
\DoxyCodeLine{1335 \textcolor{comment}{!    (this profile is monotonically increasing and may be discontinuous)}}
\DoxyCodeLine{1336 \textcolor{comment}{! 3. The new grid interfaces are determined based on the target interface}}
\DoxyCodeLine{1337 \textcolor{comment}{!    densities.}}
\DoxyCodeLine{1338 \textcolor{comment}{! 4. T \& S are remapped onto the new grid.}}
\DoxyCodeLine{1339 \textcolor{comment}{! 5. Return to step 1 until convergence or until the maximum number of}}
\DoxyCodeLine{1340 \textcolor{comment}{!    iterations is reached, whichever comes first.}}
\DoxyCodeLine{1341 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1342 }
\DoxyCodeLine{1343   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1344   \textcolor{keywordtype}{type}(ocean\_grid\_type),                        \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{1345   \textcolor{keywordtype}{type}(verticalGrid\_type),                      \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{1346   \textcolor{keywordtype}{type}(unit\_scale\_type),                        \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1347 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))},    \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1348   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                        \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamics structure}}
\DoxyCodeLine{1349 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(GV)+1)}, \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< The change in interface depth}}
\DoxyCodeLine{1350 \textcolor{comment}{                                                                    !! [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1351   \textcolor{keywordtype}{type}(remapping\_CS),                           \textcolor{keywordtype}{intent(in)}    :: remapCS\textcolor{comment}{ !< The remapping control structure}}
\DoxyCodeLine{1352   \textcolor{keywordtype}{type}(regridding\_CS),                          \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1353 }
\DoxyCodeLine{1354   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1355   \textcolor{keywordtype}{integer} :: nz}
\DoxyCodeLine{1356   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{1357 \textcolor{keywordtype}{  real}    :: nominalDepth   \textcolor{comment}{! Depth of the bottom of the ocean, positive downward [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1358 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: zOld, zNew \textcolor{comment}{! Old and new interface heights [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1359 \textcolor{keywordtype}{  real} :: h\_neglect, h\_neglect\_edge \textcolor{comment}{! Negligible thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1360 \textcolor{preprocessor}{\#ifdef \_\_DO\_SAFETY\_CHECKS\_\_}}
\DoxyCodeLine{1361 \textcolor{preprocessor}{}\textcolor{keywordtype}{  real}    :: totalThickness}
\DoxyCodeLine{1362 \textcolor{keywordtype}{  real}    :: dh}
\DoxyCodeLine{1363 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1364 \textcolor{preprocessor}{}}
\DoxyCodeLine{1365   \textcolor{keywordflow}{if} (.not.cs\%remap\_answers\_2018) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1366     h\_neglect = gv\%H\_subroundoff ; h\_neglect\_edge = gv\%H\_subroundoff}
\DoxyCodeLine{1367   \textcolor{keywordflow}{elseif} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1368     h\_neglect = gv\%m\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%m\_to\_H*1.0e-\/10}
\DoxyCodeLine{1369   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1370     h\_neglect = gv\%kg\_m2\_to\_H*1.0e-\/30 ; h\_neglect\_edge = gv\%kg\_m2\_to\_H*1.0e-\/10}
\DoxyCodeLine{1371 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1372 }
\DoxyCodeLine{1373   nz = gv\%ke}
\DoxyCodeLine{1374 }
\DoxyCodeLine{1375   \textcolor{keywordflow}{if} (.not.cs\%target\_density\_set) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"build\_rho\_grid: "}//\&}
\DoxyCodeLine{1376         \textcolor{stringliteral}{"Target densities must be set before build\_rho\_grid is called."})}
\DoxyCodeLine{1377 }
\DoxyCodeLine{1378   \textcolor{comment}{! Build grid based on target interface densities}}
\DoxyCodeLine{1379   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1}
\DoxyCodeLine{1380     \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1381 }
\DoxyCodeLine{1382       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)==0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1383         dzinterface(i,j,:) = 0.}
\DoxyCodeLine{1384         cycle}
\DoxyCodeLine{1385 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1386 }
\DoxyCodeLine{1387 }
\DoxyCodeLine{1388       \textcolor{comment}{! Local depth (G\%bathyT is positive)}}
\DoxyCodeLine{1389       nominaldepth = g\%bathyT(i,j)*gv\%Z\_to\_H}
\DoxyCodeLine{1390 }
\DoxyCodeLine{1391       \textcolor{keyword}{call }build\_rho\_column(cs\%rho\_CS, nz, nominaldepth, h(i, j, :), \&}
\DoxyCodeLine{1392                             tv\%T(i, j, :), tv\%S(i, j, :), tv\%eqn\_of\_state, znew, \&}
\DoxyCodeLine{1393                             h\_neglect=h\_neglect, h\_neglect\_edge=h\_neglect\_edge)}
\DoxyCodeLine{1394 }
\DoxyCodeLine{1395       \textcolor{keywordflow}{if} (cs\%integrate\_downward\_for\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1396         zold(1) = 0.}
\DoxyCodeLine{1397         \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{1398           zold(k+1) = zold(k) -\/ h(i,j,k)}
\DoxyCodeLine{1399 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1400       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1401         \textcolor{comment}{! The rest of the model defines grids integrating up from the bottom}}
\DoxyCodeLine{1402         zold(nz+1) = -\/ nominaldepth}
\DoxyCodeLine{1403         \textcolor{keywordflow}{do} k = nz,1,-\/1}
\DoxyCodeLine{1404           zold(k) = zold(k+1) + h(i,j,k)}
\DoxyCodeLine{1405 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1406 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1407 }
\DoxyCodeLine{1408       \textcolor{comment}{! Calculate the final change in grid position after blending new and old grids}}
\DoxyCodeLine{1409       \textcolor{keyword}{call }filtered\_grid\_motion( cs, nz, zold, znew, dzinterface(i,j,:) )}
\DoxyCodeLine{1410 }
\DoxyCodeLine{1411 \textcolor{preprocessor}{\#ifdef \_\_DO\_SAFETY\_CHECKS\_\_}}
\DoxyCodeLine{1412 \textcolor{preprocessor}{}      \textcolor{keywordflow}{do} k = 2,nz}
\DoxyCodeLine{1413         \textcolor{keywordflow}{if} (znew(k) > zold(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1414           \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'zOld='},zold}
\DoxyCodeLine{1415           \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'zNew='},znew}
\DoxyCodeLine{1416           \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding, build\_rho\_grid: '}//\&}
\DoxyCodeLine{1417                \textcolor{stringliteral}{'interior interface above surface!'} )}
\DoxyCodeLine{1418 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1419         \textcolor{keywordflow}{if} (znew(k) > znew(k-\/1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1420           \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'zOld='},zold}
\DoxyCodeLine{1421           \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'zNew='},znew}
\DoxyCodeLine{1422           \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding, build\_rho\_grid: '}//\&}
\DoxyCodeLine{1423                \textcolor{stringliteral}{'interior interfaces cross!'} )}
\DoxyCodeLine{1424 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1425 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1426 }
\DoxyCodeLine{1427       totalthickness = 0.0}
\DoxyCodeLine{1428       \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{1429         totalthickness = totalthickness + h(i,j,k)}
\DoxyCodeLine{1430 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1431 }
\DoxyCodeLine{1432       dh=max(nominaldepth,totalthickness)}
\DoxyCodeLine{1433       \textcolor{keywordflow}{if} (abs(znew(1)-\/zold(1))>(nz-\/1)*0.5*epsilon(dh)*dh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1434         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'min\_thickness='},cs\%min\_thickness}
\DoxyCodeLine{1435         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'nominalDepth='},nominaldepth,\textcolor{stringliteral}{'totalThickness='},totalthickness}
\DoxyCodeLine{1436         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'zNew(1)-\/zOld(1) = '},znew(1)-\/zold(1),epsilon(dh),nz}
\DoxyCodeLine{1437         \textcolor{keywordflow}{do} k=1,nz+1}
\DoxyCodeLine{1438           \textcolor{keyword}{write}(0,*) k,zold(k),znew(k)}
\DoxyCodeLine{1439 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1440         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1441           \textcolor{keyword}{write}(0,*) k,h(i,j,k),znew(k)-\/znew(k+1)}
\DoxyCodeLine{1442 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1443         \textcolor{keyword}{call }mom\_error( fatal, \&}
\DoxyCodeLine{1444                \textcolor{stringliteral}{'MOM\_regridding, build\_rho\_grid: top surface has moved!!!'} )}
\DoxyCodeLine{1445 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1446 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1447 \textcolor{preprocessor}{}}
\DoxyCodeLine{1448 \textcolor{keywordflow}{    enddo}  \textcolor{comment}{! end loop on i}}
\DoxyCodeLine{1449 \textcolor{keywordflow}{  enddo}  \textcolor{comment}{! end loop on j}}
\DoxyCodeLine{1450 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a455d807ccfbbfd109be231321bec1038}\label{namespacemom__regridding_a455d807ccfbbfd109be231321bec1038}} 
\index{mom\_regridding@{mom\_regridding}!build\_sigma\_grid@{build\_sigma\_grid}}
\index{build\_sigma\_grid@{build\_sigma\_grid}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_sigma\_grid()}{build\_sigma\_grid()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+sigma\+\_\+grid (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, cs\%nk+1), intent(inout)}]{dz\+Interface }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This routine builds a grid based on terrain-\/following coordinates. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & The change in interface depth \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1249 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1250 \textcolor{comment}{! This routine builds a grid based on terrain-\/following coordinates.}}
\DoxyCodeLine{1251 \textcolor{comment}{! The module parameter coordinateResolution(:) determines the resolution in}}
\DoxyCodeLine{1252 \textcolor{comment}{! sigma coordinate, dSigma(:). sigma-\/coordinates are defined by}}
\DoxyCodeLine{1253 \textcolor{comment}{!   sigma = (eta-\/z)/(H+eta)  s.t. sigma=0 at z=eta and sigma=1 at z=-\/H .}}
\DoxyCodeLine{1254 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1255 }
\DoxyCodeLine{1256   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1257   \textcolor{keywordtype}{type}(regridding\_CS),                       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1258   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{1259   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{1260 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1261 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), CS\%nk+1)}, \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< The change in interface depth}}
\DoxyCodeLine{1262 \textcolor{comment}{                                                                 !! [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1263 }
\DoxyCodeLine{1264   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1265   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{1266   \textcolor{keywordtype}{integer} :: nz}
\DoxyCodeLine{1267 \textcolor{keywordtype}{  real}    :: nominalDepth, totalThickness, dh}
\DoxyCodeLine{1268 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: zOld, zNew}
\DoxyCodeLine{1269 }
\DoxyCodeLine{1270   nz = gv\%ke}
\DoxyCodeLine{1271 }
\DoxyCodeLine{1272   \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1273     \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1}
\DoxyCodeLine{1274 }
\DoxyCodeLine{1275       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)==0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1276         dzinterface(i,j,:) = 0.}
\DoxyCodeLine{1277         cycle}
\DoxyCodeLine{1278 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1279 }
\DoxyCodeLine{1280       \textcolor{comment}{! The rest of the model defines grids integrating up from the bottom}}
\DoxyCodeLine{1281       nominaldepth = g\%bathyT(i,j)*gv\%Z\_to\_H}
\DoxyCodeLine{1282 }
\DoxyCodeLine{1283       \textcolor{comment}{! Determine water column height}}
\DoxyCodeLine{1284       totalthickness = 0.0}
\DoxyCodeLine{1285       \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{1286         totalthickness = totalthickness + h(i,j,k)}
\DoxyCodeLine{1287 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1288 }
\DoxyCodeLine{1289       \textcolor{keyword}{call }build\_sigma\_column(cs\%sigma\_CS, nominaldepth, totalthickness, znew)}
\DoxyCodeLine{1290 }
\DoxyCodeLine{1291       \textcolor{comment}{! Calculate the final change in grid position after blending new and old grids}}
\DoxyCodeLine{1292       zold(nz+1) =  -\/nominaldepth}
\DoxyCodeLine{1293       \textcolor{keywordflow}{do} k = nz,1,-\/1}
\DoxyCodeLine{1294         zold(k) = zold(k+1) + h(i, j, k)}
\DoxyCodeLine{1295 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1296 }
\DoxyCodeLine{1297       \textcolor{keyword}{call }filtered\_grid\_motion( cs, nz, zold, znew, dzinterface(i,j,:) )}
\DoxyCodeLine{1298 }
\DoxyCodeLine{1299 \textcolor{preprocessor}{\#ifdef \_\_DO\_SAFETY\_CHECKS\_\_}}
\DoxyCodeLine{1300 \textcolor{preprocessor}{}      dh=max(nominaldepth,totalthickness)}
\DoxyCodeLine{1301       \textcolor{keywordflow}{if} (abs(znew(1)-\/zold(1))>(cs\%nk-\/1)*0.5*epsilon(dh)*dh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1302         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'min\_thickness='},cs\%min\_thickness}
\DoxyCodeLine{1303         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'nominalDepth='},nominaldepth,\textcolor{stringliteral}{'totalThickness='},totalthickness}
\DoxyCodeLine{1304         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'dzInterface(1) = '},dzinterface(i,j,1),epsilon(dh),nz,cs\%nk}
\DoxyCodeLine{1305         \textcolor{keywordflow}{do} k=1,nz+1}
\DoxyCodeLine{1306           \textcolor{keyword}{write}(0,*) k,zold(k),znew(k)}
\DoxyCodeLine{1307 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1308         \textcolor{keywordflow}{do} k=1,cs\%nk}
\DoxyCodeLine{1309           \textcolor{keyword}{write}(0,*) k,h(i,j,k),znew(k)-\/znew(k+1),totalthickness*cs\%coordinateResolution(k),cs\%coordinateResolution(k)}
\DoxyCodeLine{1310 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1311         \textcolor{keyword}{call }mom\_error( fatal, \&}
\DoxyCodeLine{1312                \textcolor{stringliteral}{'MOM\_regridding, build\_sigma\_grid: top surface has moved!!!'} )}
\DoxyCodeLine{1313 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1314       dzinterface(i,j,1) = 0.}
\DoxyCodeLine{1315       dzinterface(i,j,cs\%nk+1) = 0.}
\DoxyCodeLine{1316 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1317 \textcolor{preprocessor}{}}
\DoxyCodeLine{1318 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1319 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1320 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a55e6873a74355daea004d39c452e0069}\label{namespacemom__regridding_a55e6873a74355daea004d39c452e0069}} 
\index{mom\_regridding@{mom\_regridding}!build\_zstar\_grid@{build\_zstar\_grid}}
\index{build\_zstar\_grid@{build\_zstar\_grid}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{build\_zstar\_grid()}{build\_zstar\_grid()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::build\+\_\+zstar\+\_\+grid (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, cs\%nk+1), intent(inout)}]{dz\+Interface,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{frac\+\_\+shelf\+\_\+h }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Builds a z$\ast$-\/ccordinate grid with partial steps (Adcroft and Campin, 2004). z$\ast$ is defined as z$\ast$ = (z-\/eta)/(H+eta)$\ast$H s.\+t. z$\ast$=0 when z=eta and z$\ast$=-\/H when z=-\/H . 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & The change in interface depth \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
 & {\em frac\+\_\+shelf\+\_\+h} & Fractional ice shelf coverage \mbox{[}nondim\mbox{]}. \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1159 }
\DoxyCodeLine{1160   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1161   \textcolor{keywordtype}{type}(regridding\_CS),                       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1162   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Ocean grid structure}}
\DoxyCodeLine{1163   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{1164 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1165 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), CS\%nk+1)}, \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< The change in interface depth}}
\DoxyCodeLine{1166 \textcolor{comment}{                                                                 !! [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{1167 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: frac\_shelf\_h\textcolor{comment}{ !< Fractional ice shelf coverage [nondim].}}
\DoxyCodeLine{1168   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1169 \textcolor{keywordtype}{  real}    :: nominalDepth, totalThickness, dh  \textcolor{comment}{! Depths and thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1170 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: zOld, zNew    \textcolor{comment}{! Coordinate interface heights [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1171   \textcolor{keywordtype}{integer} :: i, j, k, nz}
\DoxyCodeLine{1172   \textcolor{keywordtype}{logical} :: ice\_shelf}
\DoxyCodeLine{1173 }
\DoxyCodeLine{1174   nz = gv\%ke}
\DoxyCodeLine{1175   ice\_shelf = .false.}
\DoxyCodeLine{1176   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(frac\_shelf\_h)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1177     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(frac\_shelf\_h)) ice\_shelf = .true.}
\DoxyCodeLine{1178 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1179 }
\DoxyCodeLine{1180 \textcolor{comment}{!\$OMP parallel do default(none) shared(G,GV,dzInterface,CS,nz,h,frac\_shelf\_h,ice\_shelf) \&}}
\DoxyCodeLine{1181 \textcolor{comment}{!\$OMP                          private(nominalDepth,totalThickness,zNew,dh,zOld)}}
\DoxyCodeLine{1182   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1}
\DoxyCodeLine{1183     \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1184 }
\DoxyCodeLine{1185       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)==0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1186         dzinterface(i,j,:) = 0.}
\DoxyCodeLine{1187         cycle}
\DoxyCodeLine{1188 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1189 }
\DoxyCodeLine{1190       \textcolor{comment}{! Local depth (G\%bathyT is positive)}}
\DoxyCodeLine{1191       nominaldepth = g\%bathyT(i,j)*gv\%Z\_to\_H}
\DoxyCodeLine{1192 }
\DoxyCodeLine{1193       \textcolor{comment}{! Determine water column thickness}}
\DoxyCodeLine{1194       totalthickness = 0.0}
\DoxyCodeLine{1195       \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{1196         totalthickness = totalthickness + h(i,j,k)}
\DoxyCodeLine{1197 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1198 }
\DoxyCodeLine{1199       zold(nz+1) = -\/ nominaldepth}
\DoxyCodeLine{1200       \textcolor{keywordflow}{do} k = nz,1,-\/1}
\DoxyCodeLine{1201         zold(k) = zold(k+1) + h(i,j,k)}
\DoxyCodeLine{1202 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1203 }
\DoxyCodeLine{1204       \textcolor{keywordflow}{if} (ice\_shelf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1205         \textcolor{keywordflow}{if} (frac\_shelf\_h(i,j) > 0.) \textcolor{keywordflow}{then} \textcolor{comment}{! under ice shelf}}
\DoxyCodeLine{1206           \textcolor{keyword}{call }build\_zstar\_column(cs\%zlike\_CS, nominaldepth, totalthickness, znew, \&}
\DoxyCodeLine{1207                                 z\_rigid\_top = totalthickness-\/nominaldepth, \&}
\DoxyCodeLine{1208                                 eta\_orig=zold(1), zscale=gv\%Z\_to\_H)}
\DoxyCodeLine{1209         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1210           \textcolor{keyword}{call }build\_zstar\_column(cs\%zlike\_CS, nominaldepth, totalthickness, \&}
\DoxyCodeLine{1211                                 znew, zscale=gv\%Z\_to\_H)}
\DoxyCodeLine{1212 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1213       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1214         \textcolor{keyword}{call }build\_zstar\_column(cs\%zlike\_CS, nominaldepth, totalthickness, \&}
\DoxyCodeLine{1215                                 znew, zscale=gv\%Z\_to\_H)}
\DoxyCodeLine{1216 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1217 }
\DoxyCodeLine{1218       \textcolor{comment}{! Calculate the final change in grid position after blending new and old grids}}
\DoxyCodeLine{1219       \textcolor{keyword}{call }filtered\_grid\_motion( cs, nz, zold, znew, dzinterface(i,j,:) )}
\DoxyCodeLine{1220 }
\DoxyCodeLine{1221 \textcolor{preprocessor}{\#ifdef \_\_DO\_SAFETY\_CHECKS\_\_}}
\DoxyCodeLine{1222 \textcolor{preprocessor}{}      dh=max(nominaldepth,totalthickness)}
\DoxyCodeLine{1223       \textcolor{keywordflow}{if} (abs(znew(1)-\/zold(1))>(nz-\/1)*0.5*epsilon(dh)*dh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1224         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'min\_thickness='},cs\%min\_thickness}
\DoxyCodeLine{1225         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'nominalDepth='},nominaldepth,\textcolor{stringliteral}{'totalThickness='},totalthickness}
\DoxyCodeLine{1226         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'dzInterface(1) = '},dzinterface(i,j,1),epsilon(dh),nz}
\DoxyCodeLine{1227         \textcolor{keywordflow}{do} k=1,nz+1}
\DoxyCodeLine{1228           \textcolor{keyword}{write}(0,*) k,zold(k),znew(k)}
\DoxyCodeLine{1229 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1230         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1231           \textcolor{keyword}{write}(0,*) k,h(i,j,k),znew(k)-\/znew(k+1),cs\%coordinateResolution(k)}
\DoxyCodeLine{1232 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1233         \textcolor{keyword}{call }mom\_error( fatal, \&}
\DoxyCodeLine{1234                \textcolor{stringliteral}{'MOM\_regridding, build\_zstar\_grid(): top surface has moved!!!'} )}
\DoxyCodeLine{1235 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1236 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{1237 \textcolor{preprocessor}{}}
\DoxyCodeLine{1238       \textcolor{keyword}{call }adjust\_interface\_motion( cs, nz, h(i,j,:), dzinterface(i,j,:) )}
\DoxyCodeLine{1239 }
\DoxyCodeLine{1240 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1241 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1242 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a8dd75489564f85609033f53c0cb16cbb}\label{namespacemom__regridding_a8dd75489564f85609033f53c0cb16cbb}} 
\index{mom\_regridding@{mom\_regridding}!calc\_h\_new\_by\_dz@{calc\_h\_new\_by\_dz}}
\index{calc\_h\_new\_by\_dz@{calc\_h\_new\_by\_dz}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{calc\_h\_new\_by\_dz()}{calc\_h\_new\_by\_dz()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::calc\+\_\+h\+\_\+new\+\_\+by\+\_\+dz (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,cs\%nk+1), intent(in)}]{dz\+Interface,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,cs\%nk), intent(inout)}]{h\+\_\+new }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates h\+\_\+new from h + delta\+\_\+k dz\+Interface. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Old layer thicknesses (arbitrary units) \\
\hline
\mbox{\texttt{ in}}  & {\em dzinterface} & Change in interface positions (same as h) \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+new} & New layer thicknesses (same as h) \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{907   \textcolor{keywordtype}{type}(regridding\_CS),                       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{908   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{909   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{910 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Old layer thicknesses (arbitrary units)}}
\DoxyCodeLine{911 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS\%nk+1)},  \textcolor{keywordtype}{intent(in)}    :: dzInterface\textcolor{comment}{ !< Change in interface positions (same as h)}}
\DoxyCodeLine{912 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS\%nk)},    \textcolor{keywordtype}{intent(inout)} :: h\_new\textcolor{comment}{ !< New layer thicknesses (same as h)}}
\DoxyCodeLine{913   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{914   \textcolor{keywordtype}{integer} :: i, j, k, nki}
\DoxyCodeLine{915 }
\DoxyCodeLine{916   nki = min(cs\%nk, gv\%ke)}
\DoxyCodeLine{917 }
\DoxyCodeLine{918   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{919   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1}
\DoxyCodeLine{920     \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{921       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{922         \textcolor{keywordflow}{do} k=1,nki}
\DoxyCodeLine{923           h\_new(i,j,k) = max( 0., h(i,j,k) + ( dzinterface(i,j,k) -\/ dzinterface(i,j,k+1) ) )}
\DoxyCodeLine{924 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{925         \textcolor{keywordflow}{if} (cs\%nk > gv\%ke) \textcolor{keywordflow}{then}}
\DoxyCodeLine{926           \textcolor{keywordflow}{do} k=nki+1, cs\%nk}
\DoxyCodeLine{927             h\_new(i,j,k) = max( 0., dzinterface(i,j,k) -\/ dzinterface(i,j,k+1) )}
\DoxyCodeLine{928 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{929 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{930       \textcolor{keywordflow}{else}}
\DoxyCodeLine{931         h\_new(i,j,1:nki) = h(i,j,1:nki)}
\DoxyCodeLine{932         \textcolor{keywordflow}{if} (cs\%nk > gv\%ke) h\_new(i,j,nki+1:cs\%nk) = 0.}
\DoxyCodeLine{933         \textcolor{comment}{! On land points, why are we keeping the original h rather than setting to zero? -\/AJA}}
\DoxyCodeLine{934 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{935 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{936 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{937 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ab2a6be87039f49176d91a494126d8430}\label{namespacemom__regridding_ab2a6be87039f49176d91a494126d8430}} 
\index{mom\_regridding@{mom\_regridding}!check\_grid\_column@{check\_grid\_column}}
\index{check\_grid\_column@{check\_grid\_column}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{check\_grid\_column()}{check\_grid\_column()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::check\+\_\+grid\+\_\+column (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{real, intent(in)}]{depth,  }\item[{real, dimension(nk), intent(in)}]{h,  }\item[{real, dimension(nk+1), intent(in)}]{dz\+Interface,  }\item[{character(len=$\ast$), intent(in)}]{msg }\end{DoxyParamCaption})}



Check that the total thickness of new and old grids are consistent. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em depth} & Depth of bottom \mbox{[}Z $\sim$$>$ m\mbox{]} or arbitrary units \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Cell thicknesses \mbox{[}Z $\sim$$>$ m\mbox{]} or arbitrary units \\
\hline
\mbox{\texttt{ in}}  & {\em dzinterface} & Change in interface positions (same units as h) \\
\hline
\mbox{\texttt{ in}}  & {\em msg} & Message to append to errors \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{960   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{961 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)} :: depth\textcolor{comment}{ !< Depth of bottom [Z \string~> m] or arbitrary units}}
\DoxyCodeLine{962 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{  !< Cell thicknesses [Z \string~> m] or arbitrary units}}
\DoxyCodeLine{963 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)}, \textcolor{keywordtype}{intent(in)} :: dzInterface\textcolor{comment}{ !< Change in interface positions (same units as h)}}
\DoxyCodeLine{964   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)} :: msg\textcolor{comment}{ !< Message to append to errors}}
\DoxyCodeLine{965   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{966   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{967 \textcolor{keywordtype}{  real}    :: eps, total\_h\_old, total\_h\_new, h\_new, z\_old, z\_new}
\DoxyCodeLine{968 }
\DoxyCodeLine{969   eps =1. ; eps = epsilon(eps)}
\DoxyCodeLine{970 }
\DoxyCodeLine{971   \textcolor{comment}{! Total thickness of grid h}}
\DoxyCodeLine{972   total\_h\_old = 0.}
\DoxyCodeLine{973   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{974     total\_h\_old = total\_h\_old + h(k)}
\DoxyCodeLine{975 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{976 }
\DoxyCodeLine{977   \textcolor{comment}{! Integrate upwards for the interfaces consistent with the rest of MOM6}}
\DoxyCodeLine{978   z\_old = -\/ depth}
\DoxyCodeLine{979   \textcolor{keywordflow}{if} (depth == 0.) z\_old = -\/ total\_h\_old}
\DoxyCodeLine{980   total\_h\_new = 0.}
\DoxyCodeLine{981   \textcolor{keywordflow}{do} k = nk,1,-\/1}
\DoxyCodeLine{982     z\_old = z\_old + h(k) \textcolor{comment}{! Old interface position above layer k}}
\DoxyCodeLine{983     z\_new = z\_old + dzinterface(k) \textcolor{comment}{! New interface position based on dzInterface}}
\DoxyCodeLine{984     h\_new = h(k) + ( dzinterface(k) -\/ dzinterface(k+1) ) \textcolor{comment}{! New thickness}}
\DoxyCodeLine{985     \textcolor{keywordflow}{if} (h\_new<0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{986       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'k,h,hnew='},k,h(k),h\_new}
\DoxyCodeLine{987       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'dzI(k+1),dzI(k)='},dzinterface(k+1),dzinterface(k)}
\DoxyCodeLine{988       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding, check\_grid\_column: '}//\&}
\DoxyCodeLine{989         \textcolor{stringliteral}{'Negative layer thickness implied by re-\/gridding, '}//trim(msg))}
\DoxyCodeLine{990 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{991     total\_h\_new = total\_h\_new + h\_new}
\DoxyCodeLine{992 }
\DoxyCodeLine{993 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{994 }
\DoxyCodeLine{995   \textcolor{comment}{! Conservation by implied h\_new}}
\DoxyCodeLine{996   \textcolor{keywordflow}{if} (abs(total\_h\_new-\/total\_h\_old)>real(nk-\/1)*0.5*(total\_h\_old+total\_h\_new)*eps) \textcolor{keywordflow}{then}}
\DoxyCodeLine{997     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'nk='},nk}
\DoxyCodeLine{998     \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{999       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'k,h,hnew='},k,h(k),h(k)+(dzinterface(k)-\/dzinterface(k+1))}
\DoxyCodeLine{1000 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1001     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Hold,Hnew,Hnew-\/Hold='},total\_h\_old,total\_h\_new,total\_h\_new-\/total\_h\_old}
\DoxyCodeLine{1002     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'eps,(n)/2*eps*H='},eps,real(nk-\/1)*0.5*(total\_h\_old+total\_h\_new)*eps}
\DoxyCodeLine{1003     \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding, check\_grid\_column: '}//\&}
\DoxyCodeLine{1004       \textcolor{stringliteral}{'Re-\/gridding did NOT conserve total thickness to within roundoff '}//trim(msg))}
\DoxyCodeLine{1005 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1006 }
\DoxyCodeLine{1007   \textcolor{comment}{! Check that the top and bottom are intentionally moving}}
\DoxyCodeLine{1008   \textcolor{keywordflow}{if} (dzinterface(1) /= 0.) \textcolor{keyword}{call }mom\_error( fatal, \&}
\DoxyCodeLine{1009     \textcolor{stringliteral}{'MOM\_regridding, check\_grid\_column: Non-\/zero dzInterface at surface! '}//trim(msg))}
\DoxyCodeLine{1010   \textcolor{keywordflow}{if} (dzinterface(nk+1) /= 0.) \textcolor{keyword}{call }mom\_error( fatal, \&}
\DoxyCodeLine{1011     \textcolor{stringliteral}{'MOM\_regridding, check\_grid\_column: Non-\/zero dzInterface at bottom! '}//trim(msg))}
\DoxyCodeLine{1012 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ad4abdb8447ed3f4f769b822a468728b1}\label{namespacemom__regridding_ad4abdb8447ed3f4f769b822a468728b1}} 
\index{mom\_regridding@{mom\_regridding}!check\_grid\_def@{check\_grid\_def}}
\index{check\_grid\_def@{check\_grid\_def}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{check\_grid\_def()}{check\_grid\_def()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::check\+\_\+grid\+\_\+def (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{filename,  }\item[{character(len=$\ast$), intent(in)}]{varname,  }\item[{character(len=$\ast$), intent(in)}]{expected\+\_\+units,  }\item[{character(len=$\ast$), intent(inout)}]{msg,  }\item[{logical, intent(out)}]{ierr }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Do some basic checks on the vertical grid definition file, variable. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em filename} & File name \\
\hline
\mbox{\texttt{ in}}  & {\em varname} & Variable name \\
\hline
\mbox{\texttt{ in}}  & {\em expected\+\_\+units} & Expected units of variable \\
\hline
\mbox{\texttt{ in,out}}  & {\em msg} & Message to use for errors \\
\hline
\mbox{\texttt{ out}}  & {\em ierr} & True if an error occurs \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{738   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: filename\textcolor{comment}{ !< File name}}
\DoxyCodeLine{739   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: varname\textcolor{comment}{ !< Variable name}}
\DoxyCodeLine{740   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: expected\_units\textcolor{comment}{ !< Expected units of variable}}
\DoxyCodeLine{741   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(inout)} :: msg\textcolor{comment}{ !< Message to use for errors}}
\DoxyCodeLine{742   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(out)}   :: ierr\textcolor{comment}{ !< True if an error occurs}}
\DoxyCodeLine{743   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{744   \textcolor{keywordtype}{character (len=200)} :: units, long\_name}
\DoxyCodeLine{745   \textcolor{keywordtype}{integer} :: ncid, status, intid, vid}
\DoxyCodeLine{746   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{747 }
\DoxyCodeLine{748   ierr = .false.}
\DoxyCodeLine{749   status = nf90\_open(trim(filename), nf90\_nowrite, ncid)}
\DoxyCodeLine{750   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{751     ierr = .true.}
\DoxyCodeLine{752     msg = \textcolor{stringliteral}{'File not found: '}//trim(filename)}
\DoxyCodeLine{753     \textcolor{keywordflow}{return}}
\DoxyCodeLine{754 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{755 }
\DoxyCodeLine{756   status = nf90\_inq\_varid(ncid, trim(varname), vid)}
\DoxyCodeLine{757   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{758     ierr = .true.}
\DoxyCodeLine{759     msg = \textcolor{stringliteral}{'Var not found: '}//trim(varname)}
\DoxyCodeLine{760     \textcolor{keywordflow}{return}}
\DoxyCodeLine{761 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{762 }
\DoxyCodeLine{763   status = nf90\_get\_att(ncid, vid, \textcolor{stringliteral}{"units"}, units)}
\DoxyCodeLine{764   \textcolor{keywordflow}{if} (status /= nf90\_noerr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{765     ierr = .true.}
\DoxyCodeLine{766     msg = \textcolor{stringliteral}{'Attribute not found: units'}}
\DoxyCodeLine{767     \textcolor{keywordflow}{return}}
\DoxyCodeLine{768 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{769   \textcolor{comment}{! NF90\_GET\_ATT can return attributes with null characters, which TRIM will not truncate.}}
\DoxyCodeLine{770   \textcolor{comment}{! This loop replaces any null characters with a space so that the following check between}}
\DoxyCodeLine{771   \textcolor{comment}{! the read units and the expected units will pass}}
\DoxyCodeLine{772   \textcolor{keywordflow}{do} i=1,len\_trim(units)}
\DoxyCodeLine{773     \textcolor{keywordflow}{if} (units(i:i) == char(0)) units(i:i) = \textcolor{stringliteral}{" "}}
\DoxyCodeLine{774 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{775 }
\DoxyCodeLine{776   \textcolor{keywordflow}{if} (trim(units) /= trim(expected\_units)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{777     \textcolor{keywordflow}{if} (trim(expected\_units) == \textcolor{stringliteral}{"meters"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{778       \textcolor{keywordflow}{if} (trim(units) /= \textcolor{stringliteral}{"m"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{779         ierr = .true.}
\DoxyCodeLine{780 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{781     \textcolor{keywordflow}{else}}
\DoxyCodeLine{782       ierr = .true.}
\DoxyCodeLine{783 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{784 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{785 }
\DoxyCodeLine{786   \textcolor{keywordflow}{if} (ierr) \textcolor{keywordflow}{then}}
\DoxyCodeLine{787     msg = \textcolor{stringliteral}{'Units incorrect: '}//trim(units)//\textcolor{stringliteral}{' /= '}//trim(expected\_units)}
\DoxyCodeLine{788 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{789 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a810d6a0658d645ac7a9e2b6680ce819c}\label{namespacemom__regridding_a810d6a0658d645ac7a9e2b6680ce819c}} 
\index{mom\_regridding@{mom\_regridding}!check\_remapping\_grid@{check\_remapping\_grid}}
\index{check\_remapping\_grid@{check\_remapping\_grid}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{check\_remapping\_grid()}{check\_remapping\_grid()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::check\+\_\+remapping\+\_\+grid (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke+1), intent(in)}]{dz\+Interface,  }\item[{character(len=$\ast$), intent(in)}]{msg }\end{DoxyParamCaption})}



Check that the total thickness of two grids match. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dzinterface} & Change in interface positions \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em msg} & Message to append to errors \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{942   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{   !< Grid structure}}
\DoxyCodeLine{943   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{  !< Ocean vertical grid structure}}
\DoxyCodeLine{944 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))},   \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{   !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{945 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV)+1)}, \textcolor{keywordtype}{intent(in)} :: dzInterface\textcolor{comment}{ !< Change in interface positions}}
\DoxyCodeLine{946 \textcolor{comment}{                                                                 !! [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{947   \textcolor{keywordtype}{character(len=*)},                            \textcolor{keywordtype}{intent(in)} :: msg\textcolor{comment}{ !< Message to append to errors}}
\DoxyCodeLine{948   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{949   \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{950 }
\DoxyCodeLine{951   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{952   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{953     \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keyword}{call }check\_grid\_column( gv\%ke, gv\%Z\_to\_H*g\%bathyT(i,j), h(i,j,:), dzinterface(i,j,:), msg )}
\DoxyCodeLine{954 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{955 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_aac58190f39678cb94e0f918455804f43}\label{namespacemom__regridding_aac58190f39678cb94e0f918455804f43}} 
\index{mom\_regridding@{mom\_regridding}!convective\_adjustment@{convective\_adjustment}}
\index{convective\_adjustment@{convective\_adjustment}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{convective\_adjustment()}{convective\_adjustment()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::convective\+\_\+adjustment (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(gv)), intent(inout)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Achieve convective adjustment by swapping layers. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1870   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1871   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{1872 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \&}
\DoxyCodeLine{1873                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1874   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic variables}}
\DoxyCodeLine{1875 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1876 \textcolor{comment}{! Check each water column to see whether it is stratified. If not, sort the}}
\DoxyCodeLine{1877 \textcolor{comment}{! layers by successive swappings of water masses (bubble sort algorithm)}}
\DoxyCodeLine{1878 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1879 }
\DoxyCodeLine{1880   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1881   \textcolor{keywordtype}{integer}   :: i, j, k}
\DoxyCodeLine{1882 \textcolor{keywordtype}{  real}      :: T0, T1       \textcolor{comment}{! temperatures}}
\DoxyCodeLine{1883 \textcolor{keywordtype}{  real}      :: S0, S1       \textcolor{comment}{! salinities}}
\DoxyCodeLine{1884 \textcolor{keywordtype}{  real}      :: r0, r1       \textcolor{comment}{! densities}}
\DoxyCodeLine{1885 \textcolor{keywordtype}{  real}      :: h0, h1}
\DoxyCodeLine{1886   \textcolor{keywordtype}{logical}   :: stratified}
\DoxyCodeLine{1887 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(GV\%ke)} :: p\_col, densities}
\DoxyCodeLine{1888 }
\DoxyCodeLine{1889   p\_col(:) = 0.}
\DoxyCodeLine{1890 }
\DoxyCodeLine{1891   \textcolor{comment}{! Loop on columns}}
\DoxyCodeLine{1892   \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1 ; \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1893 }
\DoxyCodeLine{1894     \textcolor{comment}{! Compute densities within current water column}}
\DoxyCodeLine{1895     \textcolor{keyword}{call }calculate\_density( tv\%T(i,j,:), tv\%S(i,j,:), p\_col, densities, tv\%eqn\_of\_state)}
\DoxyCodeLine{1896 }
\DoxyCodeLine{1897     \textcolor{comment}{! Repeat restratification until complete}}
\DoxyCodeLine{1898     \textcolor{keywordflow}{do}}
\DoxyCodeLine{1899       stratified = .true.}
\DoxyCodeLine{1900       \textcolor{keywordflow}{do} k = 1,gv\%ke-\/1}
\DoxyCodeLine{1901         \textcolor{comment}{! Gather information of current and next cells}}
\DoxyCodeLine{1902         t0 = tv\%T(i,j,k)  ; t1 = tv\%T(i,j,k+1)}
\DoxyCodeLine{1903         s0 = tv\%S(i,j,k)  ; s1 = tv\%S(i,j,k+1)}
\DoxyCodeLine{1904         r0 = densities(k) ; r1 = densities(k+1)}
\DoxyCodeLine{1905         h0 = h(i,j,k) ; h1 = h(i,j,k+1)}
\DoxyCodeLine{1906         \textcolor{comment}{! If the density of the current cell is larger than the density}}
\DoxyCodeLine{1907         \textcolor{comment}{! below it, we swap the cells and recalculate the densitiies}}
\DoxyCodeLine{1908         \textcolor{comment}{! within the swapped cells}}
\DoxyCodeLine{1909         \textcolor{keywordflow}{if} ( r0 > r1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1910           tv\%T(i,j,k) = t1 ; tv\%T(i,j,k+1) = t0}
\DoxyCodeLine{1911           tv\%S(i,j,k) = s1 ; tv\%S(i,j,k+1) = s0}
\DoxyCodeLine{1912           h(i,j,k)    = h1 ; h(i,j,k+1)    = h0}
\DoxyCodeLine{1913           \textcolor{comment}{! Recompute densities at levels k and k+1}}
\DoxyCodeLine{1914           \textcolor{keyword}{call }calculate\_density( tv\%T(i,j,k), tv\%S(i,j,k), p\_col(k), densities(k), tv\%eqn\_of\_state)}
\DoxyCodeLine{1915           \textcolor{keyword}{call }calculate\_density( tv\%T(i,j,k+1), tv\%S(i,j,k+1), p\_col(k+1), \&}
\DoxyCodeLine{1916                                   densities(k+1), tv\%eqn\_of\_state )}
\DoxyCodeLine{1917           stratified = .false.}
\DoxyCodeLine{1918 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1919 \textcolor{keywordflow}{      enddo}  \textcolor{comment}{! k}}
\DoxyCodeLine{1920 }
\DoxyCodeLine{1921       \textcolor{keywordflow}{if} ( stratified ) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1922 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1923 }
\DoxyCodeLine{1924 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}  \textcolor{comment}{! i \& j}}
\DoxyCodeLine{1925 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a2becd8126867cdce125b31e07d13065e}\label{namespacemom__regridding_a2becd8126867cdce125b31e07d13065e}} 
\index{mom\_regridding@{mom\_regridding}!dz\_function1@{dz\_function1}}
\index{dz\_function1@{dz\_function1}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{dz\_function1()}{dz\_function1()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::dz\+\_\+function1 (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{string,  }\item[{real, dimension(\+:), intent(inout)}]{dz }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parses a string and generates a dz(\+:) profile that goes like k$\ast$$\ast$power. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em string} & String with list of parameters in form dz\+\_\+min, H\+\_\+total, power, precision \\
\hline
\mbox{\texttt{ in,out}}  & {\em dz} & Profile of nominal thicknesses \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2418   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: string\textcolor{comment}{ !< String with list of parameters in form}}
\DoxyCodeLine{2419 \textcolor{comment}{                                              !! dz\_min, H\_total, power, precision}}
\DoxyCodeLine{2420 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: dz\textcolor{comment}{     !< Profile of nominal thicknesses}}
\DoxyCodeLine{2421   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2422   \textcolor{keywordtype}{integer} :: nk, k}
\DoxyCodeLine{2423 \textcolor{keywordtype}{  real}    :: dz\_min, power, prec, H\_total}
\DoxyCodeLine{2424 }
\DoxyCodeLine{2425   nk = \textcolor{keyword}{size}(dz) \textcolor{comment}{! Number of cells}}
\DoxyCodeLine{2426   prec = -\/1024.}
\DoxyCodeLine{2427   \textcolor{keyword}{read}( string, *) dz\_min, h\_total, power, prec}
\DoxyCodeLine{2428   \textcolor{keywordflow}{if} (prec == -\/1024.) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"dz\_function1: "}// \&}
\DoxyCodeLine{2429           \textcolor{stringliteral}{"Problem reading FNC1: string  ="}//trim(string))}
\DoxyCodeLine{2430   \textcolor{comment}{! Create profile of ( dz -\/ dz\_min )}}
\DoxyCodeLine{2431   \textcolor{keywordflow}{do} k = 1, nk}
\DoxyCodeLine{2432     dz(k) = (real(k-\/1)/real(nk-\/1))**power}
\DoxyCodeLine{2433 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2434   dz(:) = ( h\_total -\/ real(nk) * dz\_min ) * ( dz(:) / sum(dz) ) \textcolor{comment}{! Rescale to so total is H\_total}}
\DoxyCodeLine{2435   dz(:) = anint( dz(:) / prec ) * prec \textcolor{comment}{! Rounds to precision prec}}
\DoxyCodeLine{2436   dz(:) = ( h\_total -\/ real(nk) * dz\_min ) * ( dz(:) / sum(dz) ) \textcolor{comment}{! Rescale to so total is H\_total}}
\DoxyCodeLine{2437   dz(:) = anint( dz(:) / prec ) * prec \textcolor{comment}{! Rounds to precision prec}}
\DoxyCodeLine{2438   dz(nk) = dz(nk) + ( h\_total -\/ sum( dz(:) + dz\_min ) ) \textcolor{comment}{! Adjust bottommost layer}}
\DoxyCodeLine{2439   dz(:) = anint( dz(:) / prec ) * prec \textcolor{comment}{! Rounds to precision prec}}
\DoxyCodeLine{2440   dz(:) = dz(:) + dz\_min \textcolor{comment}{! Finally add in the constant dz\_min}}
\DoxyCodeLine{2441 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a9f55ab3a80ab1202b7664e9c65ebf08b}\label{namespacemom__regridding_a9f55ab3a80ab1202b7664e9c65ebf08b}} 
\index{mom\_regridding@{mom\_regridding}!end\_regridding@{end\_regridding}}
\index{end\_regridding@{end\_regridding}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{end\_regridding()}{end\_regridding()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::end\+\_\+regridding (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})}



Deallocation of regridding memory. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{794   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{795 }
\DoxyCodeLine{796   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%zlike\_CS))  \textcolor{keyword}{call }end\_coord\_zlike(cs\%zlike\_CS)}
\DoxyCodeLine{797   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%sigma\_CS))  \textcolor{keyword}{call }end\_coord\_sigma(cs\%sigma\_CS)}
\DoxyCodeLine{798   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%rho\_CS))    \textcolor{keyword}{call }end\_coord\_rho(cs\%rho\_CS)}
\DoxyCodeLine{799   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%hycom\_CS))  \textcolor{keyword}{call }end\_coord\_hycom(cs\%hycom\_CS)}
\DoxyCodeLine{800   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%slight\_CS)) \textcolor{keyword}{call }end\_coord\_slight(cs\%slight\_CS)}
\DoxyCodeLine{801   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%adapt\_CS))  \textcolor{keyword}{call }end\_coord\_adapt(cs\%adapt\_CS)}
\DoxyCodeLine{802 }
\DoxyCodeLine{803   \textcolor{keyword}{deallocate}( cs\%coordinateResolution )}
\DoxyCodeLine{804   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%target\_density)) \textcolor{keyword}{deallocate}( cs\%target\_density )}
\DoxyCodeLine{805   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%max\_interface\_depths) ) \textcolor{keyword}{deallocate}( cs\%max\_interface\_depths )}
\DoxyCodeLine{806   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%max\_layer\_thickness) ) \textcolor{keyword}{deallocate}( cs\%max\_layer\_thickness )}
\DoxyCodeLine{807 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a9dddf53999f90d1a4edc79179c5b5da4}\label{namespacemom__regridding_a9dddf53999f90d1a4edc79179c5b5da4}} 
\index{mom\_regridding@{mom\_regridding}!filtered\_grid\_motion@{filtered\_grid\_motion}}
\index{filtered\_grid\_motion@{filtered\_grid\_motion}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{filtered\_grid\_motion()}{filtered\_grid\_motion()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::filtered\+\_\+grid\+\_\+motion (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk+1), intent(in)}]{z\+\_\+old,  }\item[{real, dimension(cs\%nk+1), intent(in)}]{z\+\_\+new,  }\item[{real, dimension(cs\%nk+1), intent(inout)}]{dz\+\_\+g }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the change in interface position motion after filtering and assuming the top and bottom interfaces do not move. The filtering is a function of depth, and is applied as the integrated average filtering over the trajectory of the interface. By design, this code can not give tangled interfaces provided that z\+\_\+old and z\+\_\+new are not already tangled. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+old} & Old grid position \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+new} & New grid position \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em dz\+\_\+g} & Change in interface positions \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1021   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1022   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{ !< Number of cells in source grid}}
\DoxyCodeLine{1023 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)},    \textcolor{keywordtype}{intent(in)}    :: z\_old\textcolor{comment}{ !< Old grid position [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1024 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \textcolor{keywordtype}{intent(in)}    :: z\_new\textcolor{comment}{ !< New grid position [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1025 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \textcolor{keywordtype}{intent(inout)} :: dz\_g\textcolor{comment}{ !< Change in interface positions [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1026   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1027 \textcolor{keywordtype}{  real} :: sgn  \textcolor{comment}{! The sign convention for downward.}}
\DoxyCodeLine{1028 \textcolor{keywordtype}{  real} :: dz\_tgt, zr1, z\_old\_k}
\DoxyCodeLine{1029 \textcolor{keywordtype}{  real} :: Aq, Bq, dz0, z0, F0}
\DoxyCodeLine{1030 \textcolor{keywordtype}{  real} :: zs, zd, dzwt, Idzwt}
\DoxyCodeLine{1031 \textcolor{keywordtype}{  real} :: wtd, Iwtd}
\DoxyCodeLine{1032 \textcolor{keywordtype}{  real} :: Int\_zs, Int\_zd, dInt\_zs\_zd}
\DoxyCodeLine{1033 \textcolor{comment}{! For debugging:}}
\DoxyCodeLine{1034 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk+1)} :: z\_act}
\DoxyCodeLine{1035 \textcolor{comment}{!  real, dimension(nk+1) :: ddz\_g\_s, ddz\_g\_d}}
\DoxyCodeLine{1036   \textcolor{keywordtype}{logical} :: debug = .false.}
\DoxyCodeLine{1037   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1038 }
\DoxyCodeLine{1039   \textcolor{keywordflow}{if} ((z\_old(nk+1) -\/ z\_old(1)) * (z\_new(cs\%nk+1) -\/ z\_new(1)) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1040     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"filtered\_grid\_motion: z\_old and z\_new use different sign conventions."})}
\DoxyCodeLine{1041   \textcolor{keywordflow}{elseif} ((z\_old(nk+1) -\/ z\_old(1)) * (z\_new(cs\%nk+1) -\/ z\_new(1)) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1042     \textcolor{comment}{! This is a massless column, so do nothing and return.}}
\DoxyCodeLine{1043     \textcolor{keywordflow}{do} k=1,cs\%nk+1 ; dz\_g(k) = 0.0 ;\textcolor{keywordflow}{ enddo} ; \textcolor{keywordflow}{return}}
\DoxyCodeLine{1044   \textcolor{keywordflow}{elseif} ((z\_old(nk+1) -\/ z\_old(1)) + (z\_new(cs\%nk+1) -\/ z\_new(1)) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1045     sgn = 1.0}
\DoxyCodeLine{1046   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1047     sgn = -\/1.0}
\DoxyCodeLine{1048 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1049 }
\DoxyCodeLine{1050   \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1051     \textcolor{keywordflow}{do} k=2,cs\%nk+1}
\DoxyCodeLine{1052       \textcolor{keywordflow}{if} (sgn*(z\_new(k)-\/z\_new(k-\/1)) < -\/5e-\/16*(abs(z\_new(k))+abs(z\_new(k-\/1))) ) \&}
\DoxyCodeLine{1053         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"filtered\_grid\_motion: z\_new is tangled."})}
\DoxyCodeLine{1054 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1055     \textcolor{keywordflow}{do} k=2,nk+1}
\DoxyCodeLine{1056       \textcolor{keywordflow}{if} (sgn*(z\_old(k)-\/z\_old(k-\/1)) < -\/5e-\/16*(abs(z\_old(k))+abs(z\_old(k-\/1))) ) \&}
\DoxyCodeLine{1057         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"filtered\_grid\_motion: z\_old is tangled."})}
\DoxyCodeLine{1058 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1059     \textcolor{comment}{! ddz\_g\_s(:) = 0.0 ; ddz\_g\_d(:) = 0.0}}
\DoxyCodeLine{1060 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1061 }
\DoxyCodeLine{1062   zs = cs\%depth\_of\_time\_filter\_shallow}
\DoxyCodeLine{1063   zd = cs\%depth\_of\_time\_filter\_deep}
\DoxyCodeLine{1064   wtd = 1.0 -\/ cs\%old\_grid\_weight}
\DoxyCodeLine{1065   iwtd = 1.0 / wtd}
\DoxyCodeLine{1066 }
\DoxyCodeLine{1067   dzwt = (zd -\/ zs)}
\DoxyCodeLine{1068   idzwt = 0.0 ; \textcolor{keywordflow}{if} (abs(zd -\/ zs) > 0.0) idzwt = 1.0 / (zd -\/ zs)}
\DoxyCodeLine{1069   dint\_zs\_zd = 0.5*(1.0 + iwtd) * (zd -\/ zs)}
\DoxyCodeLine{1070   aq = 0.5*(iwtd -\/ 1.0)}
\DoxyCodeLine{1071 }
\DoxyCodeLine{1072   dz\_g(1) = 0.0}
\DoxyCodeLine{1073   z\_old\_k = z\_old(1)}
\DoxyCodeLine{1074   \textcolor{keywordflow}{do} k = 2,cs\%nk+1}
\DoxyCodeLine{1075     \textcolor{keywordflow}{if} (k<=nk+1) z\_old\_k = z\_old(k) \textcolor{comment}{! This allows for virtual z\_old interface at bottom of the model}}
\DoxyCodeLine{1076     \textcolor{comment}{! zr1 is positive and increases with depth, and dz\_tgt is positive downward.}}
\DoxyCodeLine{1077     dz\_tgt = sgn*(z\_new(k) -\/ z\_old\_k)}
\DoxyCodeLine{1078     zr1 = sgn*(z\_old\_k -\/ z\_old(1))}
\DoxyCodeLine{1079 }
\DoxyCodeLine{1080     \textcolor{comment}{!   First, handle the two simple and common cases that do not pass through}}
\DoxyCodeLine{1081     \textcolor{comment}{! the adjustment rate transition zone.}}
\DoxyCodeLine{1082     \textcolor{keywordflow}{if} ((zr1 > zd) .and. (zr1 + wtd * dz\_tgt > zd)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1083       dz\_g(k) = sgn * wtd * dz\_tgt}
\DoxyCodeLine{1084     \textcolor{keywordflow}{elseif} ((zr1 < zs) .and. (zr1 + dz\_tgt < zs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1085       dz\_g(k) = sgn * dz\_tgt}
\DoxyCodeLine{1086     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1087       \textcolor{comment}{! Find the new value by inverting the equation}}
\DoxyCodeLine{1088       \textcolor{comment}{!   integral(0 to dz\_new) Iwt(z) dz = dz\_tgt}}
\DoxyCodeLine{1089       \textcolor{comment}{! This is trivial where Iwt is a constant, and agrees with the two limits above.}}
\DoxyCodeLine{1090 }
\DoxyCodeLine{1091       \textcolor{comment}{! Take test values at the transition points to figure out which segment}}
\DoxyCodeLine{1092       \textcolor{comment}{! the new value will be found in.}}
\DoxyCodeLine{1093       \textcolor{keywordflow}{if} (zr1 >= zd) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1094         int\_zd = iwtd*(zd -\/ zr1)}
\DoxyCodeLine{1095         int\_zs = int\_zd -\/ dint\_zs\_zd}
\DoxyCodeLine{1096       \textcolor{keywordflow}{elseif} (zr1 <= zs) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1097         int\_zs = (zs -\/ zr1)}
\DoxyCodeLine{1098         int\_zd = dint\_zs\_zd + (zs -\/ zr1)}
\DoxyCodeLine{1099       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1100 \textcolor{comment}{!        Int\_zd = (zd -\/ zr1) * (Iwtd + 0.5*(1.0 -\/ Iwtd) * (zd -\/ zr1) / (zd -\/ zs))}}
\DoxyCodeLine{1101         int\_zd = (zd -\/ zr1) * (iwtd*(0.5*(zd+zr1) -\/ zs) + 0.5*(zd -\/ zr1)) * idzwt}
\DoxyCodeLine{1102         int\_zs = (zs -\/ zr1) * (0.5*iwtd * ((zr1 -\/ zs)) + (zd -\/ 0.5*(zr1+zs))) * idzwt}
\DoxyCodeLine{1103         \textcolor{comment}{! It has been verified that  Int\_zs = Int\_zd -\/ dInt\_zs\_zd to within roundoff.}}
\DoxyCodeLine{1104 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1105 }
\DoxyCodeLine{1106       \textcolor{keywordflow}{if} (dz\_tgt >= int\_zd) \textcolor{keywordflow}{then} \textcolor{comment}{! The new location is in the deep, slow region.}}
\DoxyCodeLine{1107         dz\_g(k) = sgn * ((zd-\/zr1) + wtd*(dz\_tgt -\/ int\_zd))}
\DoxyCodeLine{1108       \textcolor{keywordflow}{elseif} (dz\_tgt <= int\_zs) \textcolor{keywordflow}{then} \textcolor{comment}{! The new location is in the shallow region.}}
\DoxyCodeLine{1109         dz\_g(k) = sgn * ((zs-\/zr1) + (dz\_tgt -\/ int\_zs))}
\DoxyCodeLine{1110       \textcolor{keywordflow}{else}  \textcolor{comment}{! We need to solve a quadratic equation for z\_new.}}
\DoxyCodeLine{1111         \textcolor{comment}{! For accuracy, do the integral from the starting depth or the nearest}}
\DoxyCodeLine{1112         \textcolor{comment}{! edge of the transition region.  The results with each choice are}}
\DoxyCodeLine{1113         \textcolor{comment}{! mathematically equivalent, but differ in roundoff, and this choice}}
\DoxyCodeLine{1114         \textcolor{comment}{! should minimize the likelihood of inadvertently overlapping interfaces.}}
\DoxyCodeLine{1115         \textcolor{keywordflow}{if} (zr1 <= zs) \textcolor{keywordflow}{then} ; dz0 = zs-\/zr1 ; z0 = zs ; f0 = dz\_tgt -\/ int\_zs}
\DoxyCodeLine{1116         \textcolor{keywordflow}{elseif} (zr1 >= zd) \textcolor{keywordflow}{then} ; dz0 = zd-\/zr1 ; z0 = zd ; f0 = dz\_tgt -\/ int\_zd}
\DoxyCodeLine{1117         \textcolor{keywordflow}{else} ; dz0 = 0.0 ; z0 = zr1 ; f0 = dz\_tgt ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1118 }
\DoxyCodeLine{1119         bq = (dzwt + 2.0*aq*(z0-\/zs))}
\DoxyCodeLine{1120         \textcolor{comment}{! Solve the quadratic: Aq*(zn-\/z0)**2 + Bq*(zn-\/z0) -\/ F0*dzwt = 0}}
\DoxyCodeLine{1121         \textcolor{comment}{! Note that b>=0, and the two terms in the standard form cancel for the right root.}}
\DoxyCodeLine{1122         dz\_g(k) = sgn * (dz0 + 2.0*f0*dzwt / (bq + sqrt(bq**2 + 4.0*aq*f0*dzwt) ))}
\DoxyCodeLine{1123 }
\DoxyCodeLine{1124 \textcolor{comment}{!       if (debug) then}}
\DoxyCodeLine{1125 \textcolor{comment}{!         dz0 = zs-\/zr1 ; z0 = zs ; F0 = dz\_tgt -\/ Int\_zs ; Bq = (dzwt + 2.0*Aq*(z0-\/zs))}}
\DoxyCodeLine{1126 \textcolor{comment}{!         ddz\_g\_s(k) = sgn * (dz0 + 2.0*F0*dzwt / (Bq + sqrt(Bq**2 + 4.0*Aq*F0*dzwt) )) -\/ dz\_g(k)}}
\DoxyCodeLine{1127 \textcolor{comment}{!         dz0 = zd-\/zr1 ; z0 = zd ; F0 = dz\_tgt -\/ Int\_zd ; Bq = (dzwt + 2.0*Aq*(z0-\/zs))}}
\DoxyCodeLine{1128 \textcolor{comment}{!         ddz\_g\_d(k) = sgn * (dz0 + 2.0*F0*dzwt / (Bq + sqrt(Bq**2 + 4.0*Aq*F0*dzwt) )) -\/ dz\_g(k)}}
\DoxyCodeLine{1129 \textcolor{comment}{!}}
\DoxyCodeLine{1130 \textcolor{comment}{!         if (abs(ddz\_g\_s(k)) > 1e-\/12*(abs(dz\_g(k)) + abs(dz\_g(k)+ddz\_g\_s(k)))) \&}}
\DoxyCodeLine{1131 \textcolor{comment}{!           call MOM\_error(WARNING, "filtered\_grid\_motion: Expect z\_output to be tangled (sc).")}}
\DoxyCodeLine{1132 \textcolor{comment}{!         if (abs(ddz\_g\_d(k) -\/ ddz\_g\_s(k)) > 1e-\/12*(abs(dz\_g(k)+ddz\_g\_d(k)) + abs(dz\_g(k)+ddz\_g\_s(k)))) \&}}
\DoxyCodeLine{1133 \textcolor{comment}{!           call MOM\_error(WARNING, "filtered\_grid\_motion: Expect z\_output to be tangled.")}}
\DoxyCodeLine{1134 \textcolor{comment}{!       endif}}
\DoxyCodeLine{1135 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1136 }
\DoxyCodeLine{1137 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1138 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1139  \textcolor{comment}{!dz\_g(CS\%nk+1) = 0.0}}
\DoxyCodeLine{1140 }
\DoxyCodeLine{1141   \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1142     z\_old\_k = z\_old(1)}
\DoxyCodeLine{1143     \textcolor{keywordflow}{do} k=1,cs\%nk+1}
\DoxyCodeLine{1144       \textcolor{keywordflow}{if} (k<=nk+1) z\_old\_k = z\_old(k) \textcolor{comment}{! This allows for virtual z\_old interface at bottom of the model}}
\DoxyCodeLine{1145       z\_act(k) = z\_old\_k + dz\_g(k)}
\DoxyCodeLine{1146 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1147     \textcolor{keywordflow}{do} k=2,cs\%nk+1}
\DoxyCodeLine{1148       \textcolor{keywordflow}{if} (sgn*((z\_act(k))-\/z\_act(k-\/1)) < -\/1e-\/15*(abs(z\_act(k))+abs(z\_act(k-\/1))) ) \&}
\DoxyCodeLine{1149         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"filtered\_grid\_motion: z\_output is tangled."})}
\DoxyCodeLine{1150 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1151 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1152 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ab4d037c069414d7a709219350e7b71ed}\label{namespacemom__regridding_ab4d037c069414d7a709219350e7b71ed}} 
\index{mom\_regridding@{mom\_regridding}!get\_regrid\_size@{get\_regrid\_size}}
\index{get\_regrid\_size@{get\_regrid\_size}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{get\_regrid\_size()}{get\_regrid\_size()}}
{\footnotesize\ttfamily integer function, public mom\+\_\+regridding\+::get\+\_\+regrid\+\_\+size (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})}



Returns the number of levels/layers in the regridding control structure. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2348   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2349 }
\DoxyCodeLine{2350   get\_regrid\_size = cs\%nk}
\DoxyCodeLine{2351 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a358f07a447816230753c8d3d5a0fb8af}\label{namespacemom__regridding_a358f07a447816230753c8d3d5a0fb8af}} 
\index{mom\_regridding@{mom\_regridding}!get\_rho\_cs@{get\_rho\_cs}}
\index{get\_rho\_cs@{get\_rho\_cs}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{get\_rho\_cs()}{get\_rho\_cs()}}
{\footnotesize\ttfamily type(rho\+\_\+cs) function, public mom\+\_\+regridding\+::get\+\_\+rho\+\_\+cs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})}



This returns a copy of the rho\+\_\+\+CS stored in the regridding control structure. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2372   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2373   \textcolor{keywordtype}{type}(rho\_CS) :: get\_rho\_CS}
\DoxyCodeLine{2374 }
\DoxyCodeLine{2375   get\_rho\_cs = cs\%rho\_CS}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_aef5b07937353a9fe2ce51dd6c2beed54}\label{namespacemom__regridding_aef5b07937353a9fe2ce51dd6c2beed54}} 
\index{mom\_regridding@{mom\_regridding}!get\_sigma\_cs@{get\_sigma\_cs}}
\index{get\_sigma\_cs@{get\_sigma\_cs}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{get\_sigma\_cs()}{get\_sigma\_cs()}}
{\footnotesize\ttfamily type(sigma\+\_\+cs) function, public mom\+\_\+regridding\+::get\+\_\+sigma\+\_\+cs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})}



This returns a copy of the sigma\+\_\+\+CS stored in the regridding control structure. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2364   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2365   \textcolor{keywordtype}{type}(sigma\_CS) :: get\_sigma\_CS}
\DoxyCodeLine{2366 }
\DoxyCodeLine{2367   get\_sigma\_cs = cs\%sigma\_CS}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a8ff04f8857825fcc814cdad9684717e7}\label{namespacemom__regridding_a8ff04f8857825fcc814cdad9684717e7}} 
\index{mom\_regridding@{mom\_regridding}!get\_zlike\_cs@{get\_zlike\_cs}}
\index{get\_zlike\_cs@{get\_zlike\_cs}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{get\_zlike\_cs()}{get\_zlike\_cs()}}
{\footnotesize\ttfamily type(zlike\+\_\+cs) function, public mom\+\_\+regridding\+::get\+\_\+zlike\+\_\+cs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})}



This returns a copy of the zlike\+\_\+\+CS stored in the regridding control structure. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2356   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2357   \textcolor{keywordtype}{type}(zlike\_CS) :: get\_zlike\_CS}
\DoxyCodeLine{2358 }
\DoxyCodeLine{2359   get\_zlike\_cs = cs\%zlike\_CS}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_af20d0def7ceffa33a6595c6c9e8613fd}\label{namespacemom__regridding_af20d0def7ceffa33a6595c6c9e8613fd}} 
\index{mom\_regridding@{mom\_regridding}!getcoordinateinterfaces@{getcoordinateinterfaces}}
\index{getcoordinateinterfaces@{getcoordinateinterfaces}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{getcoordinateinterfaces()}{getcoordinateinterfaces()}}
{\footnotesize\ttfamily real function, dimension(cs\%nk+1), public mom\+\_\+regridding\+::getcoordinateinterfaces (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{logical, intent(in), optional}]{undo\+\_\+scaling }\end{DoxyParamCaption})}



Query the target coordinate interface positions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em undo\+\_\+scaling} & If present and true, undo any internal rescaling of the resolution data. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Interface positions in target coordinate 
\end{DoxyReturn}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2141   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{                      !< Regridding control structure}}
\DoxyCodeLine{2142   \textcolor{keywordtype}{logical},   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: undo\_scaling\textcolor{comment}{            !< If present and true, undo any internal}}
\DoxyCodeLine{2143 \textcolor{comment}{                                                             !! rescaling of the resolution data.}}
\DoxyCodeLine{2144 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}        :: getCoordinateInterfaces\textcolor{comment}{ !< Interface positions in target coordinate}}
\DoxyCodeLine{2145 }
\DoxyCodeLine{2146   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{2147   \textcolor{keywordtype}{logical} :: unscale}
\DoxyCodeLine{2148   unscale = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(undo\_scaling)) unscale = undo\_scaling}
\DoxyCodeLine{2149 }
\DoxyCodeLine{2150   \textcolor{comment}{! When using a coordinate with target densities, we need to get the actual}}
\DoxyCodeLine{2151   \textcolor{comment}{! densities, rather than computing the interfaces based on resolution}}
\DoxyCodeLine{2152   \textcolor{keywordflow}{if} (cs\%regridding\_scheme == regridding\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2153     \textcolor{keywordflow}{if} (.not. cs\%target\_density\_set) \&}
\DoxyCodeLine{2154       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'MOM\_regridding, getCoordinateInterfaces: '}//\&}
\DoxyCodeLine{2155                             \textcolor{stringliteral}{'target densities not set!'})}
\DoxyCodeLine{2156 }
\DoxyCodeLine{2157     \textcolor{keywordflow}{if} (unscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2158       getcoordinateinterfaces(:) = cs\%coord\_scale * cs\%target\_density(:)}
\DoxyCodeLine{2159     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2160       getcoordinateinterfaces(:) = cs\%target\_density(:)}
\DoxyCodeLine{2161 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2162   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2163     \textcolor{keywordflow}{if} (unscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2164       getcoordinateinterfaces(1) = 0.}
\DoxyCodeLine{2165       \textcolor{keywordflow}{do} k = 1, cs\%nk}
\DoxyCodeLine{2166         getcoordinateinterfaces(k+1) = getcoordinateinterfaces(k) -\/ \&}
\DoxyCodeLine{2167                                        cs\%coord\_scale * cs\%coordinateResolution(k)}
\DoxyCodeLine{2168 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{2169     \textcolor{keywordflow}{else}}
\DoxyCodeLine{2170       getcoordinateinterfaces(1) = 0.}
\DoxyCodeLine{2171       \textcolor{keywordflow}{do} k = 1, cs\%nk}
\DoxyCodeLine{2172         getcoordinateinterfaces(k+1) = getcoordinateinterfaces(k) -\/ \&}
\DoxyCodeLine{2173                                        cs\%coordinateResolution(k)}
\DoxyCodeLine{2174 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{2175 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2176     \textcolor{comment}{! The following line has an "abs()" to allow ferret users to reference}}
\DoxyCodeLine{2177     \textcolor{comment}{! data by index. It is a temporary work around...  :(  -\/AJA}}
\DoxyCodeLine{2178     getcoordinateinterfaces(:) = abs( getcoordinateinterfaces(:) )}
\DoxyCodeLine{2179 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2180 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_af36c8643e6b6b97e6ab94f9a0d00ca32}\label{namespacemom__regridding_af36c8643e6b6b97e6ab94f9a0d00ca32}} 
\index{mom\_regridding@{mom\_regridding}!getcoordinateresolution@{getcoordinateresolution}}
\index{getcoordinateresolution@{getcoordinateresolution}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{getcoordinateresolution()}{getcoordinateresolution()}}
{\footnotesize\ttfamily real function, dimension(cs\%nk), public mom\+\_\+regridding\+::getcoordinateresolution (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{logical, intent(in), optional}]{undo\+\_\+scaling }\end{DoxyParamCaption})}



Query the fixed resolution data. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em undo\+\_\+scaling} & If present and true, undo any internal rescaling of the resolution data. \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2123   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2124   \textcolor{keywordtype}{logical},   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: undo\_scaling\textcolor{comment}{ !< If present and true, undo any internal}}
\DoxyCodeLine{2125 \textcolor{comment}{                                        !! rescaling of the resolution data.}}
\DoxyCodeLine{2126 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk)}          :: getCoordinateResolution}
\DoxyCodeLine{2127 }
\DoxyCodeLine{2128   \textcolor{keywordtype}{logical} :: unscale}
\DoxyCodeLine{2129   unscale = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(undo\_scaling)) unscale = undo\_scaling}
\DoxyCodeLine{2130 }
\DoxyCodeLine{2131   \textcolor{keywordflow}{if} (unscale) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2132     getcoordinateresolution(:) = cs\%coord\_scale * cs\%coordinateResolution(:)}
\DoxyCodeLine{2133   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2134     getcoordinateresolution(:) = cs\%coordinateResolution(:)}
\DoxyCodeLine{2135 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2136 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ac1e1f08a6d33ab71e6a3c5008c519ee6}\label{namespacemom__regridding_ac1e1f08a6d33ab71e6a3c5008c519ee6}} 
\index{mom\_regridding@{mom\_regridding}!getcoordinateshortname@{getcoordinateshortname}}
\index{getcoordinateshortname@{getcoordinateshortname}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{getcoordinateshortname()}{getcoordinateshortname()}}
{\footnotesize\ttfamily character(len=20) function, public mom\+\_\+regridding\+::getcoordinateshortname (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})}



Query the short name of the coordinate. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2210   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2211   \textcolor{keywordtype}{character(len=20)}               :: getCoordinateShortName}
\DoxyCodeLine{2212 }
\DoxyCodeLine{2213   \textcolor{keywordflow}{select case} ( cs\%regridding\_scheme )}
\DoxyCodeLine{2214     \textcolor{keywordflow}{case} ( regridding\_zstar )}
\DoxyCodeLine{2215       \textcolor{comment}{!getCoordinateShortName = 'z*'}}
\DoxyCodeLine{2216       \textcolor{comment}{! The following line is a temporary work around...  :(  -\/AJA}}
\DoxyCodeLine{2217       getcoordinateshortname = \textcolor{stringliteral}{'pseudo-\/depth, -\/z*'}}
\DoxyCodeLine{2218     \textcolor{keywordflow}{case} ( regridding\_sigma\_shelf\_zstar )}
\DoxyCodeLine{2219       getcoordinateshortname = \textcolor{stringliteral}{'pseudo-\/depth, -\/z*/sigma'}}
\DoxyCodeLine{2220     \textcolor{keywordflow}{case} ( regridding\_sigma )}
\DoxyCodeLine{2221       getcoordinateshortname = \textcolor{stringliteral}{'sigma'}}
\DoxyCodeLine{2222     \textcolor{keywordflow}{case} ( regridding\_rho )}
\DoxyCodeLine{2223       getcoordinateshortname = \textcolor{stringliteral}{'rho'}}
\DoxyCodeLine{2224     \textcolor{keywordflow}{case} ( regridding\_arbitrary )}
\DoxyCodeLine{2225       getcoordinateshortname = \textcolor{stringliteral}{'coordinate'}}
\DoxyCodeLine{2226     \textcolor{keywordflow}{case} ( regridding\_hycom1 )}
\DoxyCodeLine{2227       getcoordinateshortname = \textcolor{stringliteral}{'z-\/rho'}}
\DoxyCodeLine{2228     \textcolor{keywordflow}{case} ( regridding\_slight )}
\DoxyCodeLine{2229       getcoordinateshortname = \textcolor{stringliteral}{'s-\/rho'}}
\DoxyCodeLine{2230     \textcolor{keywordflow}{case} ( regridding\_adaptive )}
\DoxyCodeLine{2231       getcoordinateshortname = \textcolor{stringliteral}{'adaptive'}}
\DoxyCodeLine{2232 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{2233       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, getCoordinateShortName: '}//\&}
\DoxyCodeLine{2234                      \textcolor{stringliteral}{'Unknown regridding scheme selected!'})}
\DoxyCodeLine{2235 \textcolor{keywordflow}{  end select} \textcolor{comment}{! type of grid}}
\DoxyCodeLine{2236 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ad693fbb3424bb0ba9d0ad8878828e604}\label{namespacemom__regridding_ad693fbb3424bb0ba9d0ad8878828e604}} 
\index{mom\_regridding@{mom\_regridding}!getcoordinateunits@{getcoordinateunits}}
\index{getcoordinateunits@{getcoordinateunits}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{getcoordinateunits()}{getcoordinateunits()}}
{\footnotesize\ttfamily character(len=20) function, public mom\+\_\+regridding\+::getcoordinateunits (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})}



Query the target coordinate units. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2186   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2187   \textcolor{keywordtype}{character(len=20)}               :: getCoordinateUnits}
\DoxyCodeLine{2188 }
\DoxyCodeLine{2189   \textcolor{keywordflow}{select case} ( cs\%regridding\_scheme )}
\DoxyCodeLine{2190     \textcolor{keywordflow}{case} ( regridding\_zstar, regridding\_hycom1, regridding\_slight, regridding\_adaptive )}
\DoxyCodeLine{2191       getcoordinateunits = \textcolor{stringliteral}{'meter'}}
\DoxyCodeLine{2192     \textcolor{keywordflow}{case} ( regridding\_sigma\_shelf\_zstar )}
\DoxyCodeLine{2193       getcoordinateunits = \textcolor{stringliteral}{'meter/fraction'}}
\DoxyCodeLine{2194     \textcolor{keywordflow}{case} ( regridding\_sigma )}
\DoxyCodeLine{2195       getcoordinateunits = \textcolor{stringliteral}{'fraction'}}
\DoxyCodeLine{2196     \textcolor{keywordflow}{case} ( regridding\_rho )}
\DoxyCodeLine{2197       getcoordinateunits = \textcolor{stringliteral}{'kg/m3'}}
\DoxyCodeLine{2198     \textcolor{keywordflow}{case} ( regridding\_arbitrary )}
\DoxyCodeLine{2199       getcoordinateunits = \textcolor{stringliteral}{'unknown'}}
\DoxyCodeLine{2200 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{2201       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, getCoordinateUnits: '}//\&}
\DoxyCodeLine{2202                      \textcolor{stringliteral}{'Unknown regridding scheme selected!'})}
\DoxyCodeLine{2203 \textcolor{keywordflow}{  end select} \textcolor{comment}{! type of grid}}
\DoxyCodeLine{2204 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a1587a58d8fe87432c3f7817952014584}\label{namespacemom__regridding_a1587a58d8fe87432c3f7817952014584}} 
\index{mom\_regridding@{mom\_regridding}!getstaticthickness@{getstaticthickness}}
\index{getstaticthickness@{getstaticthickness}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{getstaticthickness()}{getstaticthickness()}}
{\footnotesize\ttfamily real function, dimension(cs\%nk), public mom\+\_\+regridding\+::getstaticthickness (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{real, intent(in)}]{S\+SH,  }\item[{real, intent(in)}]{depth }\end{DoxyParamCaption})}



Return coordinate-\/derived thicknesses for fixed coordinate systems. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em ssh} & The sea surface height, in the same units as depth \\
\hline
\mbox{\texttt{ in}}  & {\em depth} & The maximum depth of the grid, often \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The returned thicknesses in the units of depth 
\end{DoxyReturn}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2381   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2382 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{intent(in)} :: SSH\textcolor{comment}{   !< The sea surface height, in the same units as depth}}
\DoxyCodeLine{2383 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{intent(in)} :: depth\textcolor{comment}{ !< The maximum depth of the grid, often [Z \string~> m]}}
\DoxyCodeLine{2384 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk)}          :: getStaticThickness\textcolor{comment}{ !< The returned thicknesses in the units of depth}}
\DoxyCodeLine{2385   \textcolor{comment}{! Local}}
\DoxyCodeLine{2386   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{2387 \textcolor{keywordtype}{  real} :: z, dz}
\DoxyCodeLine{2388 }
\DoxyCodeLine{2389   \textcolor{keywordflow}{select case} ( cs\%regridding\_scheme )}
\DoxyCodeLine{2390     \textcolor{keywordflow}{case} ( regridding\_zstar, regridding\_sigma\_shelf\_zstar, regridding\_hycom1, regridding\_slight, regridding\_adaptive )}
\DoxyCodeLine{2391       \textcolor{keywordflow}{if} (depth>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2392         z = ssh}
\DoxyCodeLine{2393         \textcolor{keywordflow}{do} k = 1, cs\%nk}
\DoxyCodeLine{2394           dz = cs\%coordinateResolution(k) * ( 1. + ssh/depth ) \textcolor{comment}{! Nominal dz*}}
\DoxyCodeLine{2395           dz = max(dz, 0.)              \textcolor{comment}{! Avoid negative incase ssh=-\/depth}}
\DoxyCodeLine{2396           dz = min(dz, depth -\/ z)       \textcolor{comment}{! Clip if below topography}}
\DoxyCodeLine{2397           z = z + dz                    \textcolor{comment}{! Bottom of layer}}
\DoxyCodeLine{2398           getstaticthickness(k) = dz}
\DoxyCodeLine{2399 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{2400       \textcolor{keywordflow}{else}}
\DoxyCodeLine{2401         getstaticthickness(:) = 0. \textcolor{comment}{! On land ...}}
\DoxyCodeLine{2402 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2403     \textcolor{keywordflow}{case} ( regridding\_sigma )}
\DoxyCodeLine{2404       getstaticthickness(:) = cs\%coordinateResolution(:) * ( depth + ssh )}
\DoxyCodeLine{2405     \textcolor{keywordflow}{case} ( regridding\_rho )}
\DoxyCodeLine{2406       getstaticthickness(:) = 0. \textcolor{comment}{! Not applicable}}
\DoxyCodeLine{2407     \textcolor{keywordflow}{case} ( regridding\_arbitrary )}
\DoxyCodeLine{2408       getstaticthickness(:) = 0.  \textcolor{comment}{! Not applicable}}
\DoxyCodeLine{2409 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{2410       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, getStaticThickness: '}//\&}
\DoxyCodeLine{2411                      \textcolor{stringliteral}{'Unknown regridding scheme selected!'})}
\DoxyCodeLine{2412 \textcolor{keywordflow}{  end select} \textcolor{comment}{! type of grid}}
\DoxyCodeLine{2413 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_aeb36a31003c4887ea1af82c11c627f2f}\label{namespacemom__regridding_aeb36a31003c4887ea1af82c11c627f2f}} 
\index{mom\_regridding@{mom\_regridding}!inflate\_vanished\_layers\_old@{inflate\_vanished\_layers\_old}}
\index{inflate\_vanished\_layers\_old@{inflate\_vanished\_layers\_old}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{inflate\_vanished\_layers\_old()}{inflate\_vanished\_layers\_old()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::inflate\+\_\+vanished\+\_\+layers\+\_\+old (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g), szk\+\_\+(gv)), intent(inout)}]{h }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1829 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1830 \textcolor{comment}{! This routine is called when initializing the regridding options. The}}
\DoxyCodeLine{1831 \textcolor{comment}{! objective is to make sure all layers are at least as thick as the minimum}}
\DoxyCodeLine{1832 \textcolor{comment}{! thickness allowed for regridding purposes (this parameter is set in the}}
\DoxyCodeLine{1833 \textcolor{comment}{! MOM\_input file or defaulted to 1.0e-\/3). When layers are too thin, they}}
\DoxyCodeLine{1834 \textcolor{comment}{! are inflated up to the minmum thickness.}}
\DoxyCodeLine{1835 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1836 }
\DoxyCodeLine{1837   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1838   \textcolor{keywordtype}{type}(regridding\_CS),                    \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{   !< Regridding control structure}}
\DoxyCodeLine{1839   \textcolor{keywordtype}{type}(ocean\_grid\_type),                  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1840   \textcolor{keywordtype}{type}(verticalGrid\_type),                \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{1841 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(GV))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{    !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{1842 }
\DoxyCodeLine{1843   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1844   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{1845 \textcolor{keywordtype}{  real}    :: hTmp(GV\%ke)}
\DoxyCodeLine{1846 }
\DoxyCodeLine{1847   \textcolor{keywordflow}{do} i = g\%isc-\/1,g\%iec+1}
\DoxyCodeLine{1848     \textcolor{keywordflow}{do} j = g\%jsc-\/1,g\%jec+1}
\DoxyCodeLine{1849 }
\DoxyCodeLine{1850       \textcolor{comment}{! Build grid for current column}}
\DoxyCodeLine{1851       \textcolor{keywordflow}{do} k = 1,gv\%ke}
\DoxyCodeLine{1852         htmp(k) = h(i,j,k)}
\DoxyCodeLine{1853 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1854 }
\DoxyCodeLine{1855       \textcolor{keyword}{call }old\_inflate\_layers\_1d( cs\%min\_thickness, gv\%ke, htmp )}
\DoxyCodeLine{1856 }
\DoxyCodeLine{1857       \textcolor{comment}{! Save modified grid}}
\DoxyCodeLine{1858       \textcolor{keywordflow}{do} k = 1,gv\%ke}
\DoxyCodeLine{1859         h(i,j,k) = htmp(k)}
\DoxyCodeLine{1860 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1861 }
\DoxyCodeLine{1862 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1863 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1864 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ad9614000d524a78e043d52f9734314e0}\label{namespacemom__regridding_ad9614000d524a78e043d52f9734314e0}} 
\index{mom\_regridding@{mom\_regridding}!initcoord@{initcoord}}
\index{initcoord@{initcoord}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{initcoord()}{initcoord()}}
{\footnotesize\ttfamily subroutine mom\+\_\+regridding\+::initcoord (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{character(len=$\ast$), intent(in)}]{coord\+\_\+mode }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initialize the coordinate resolutions by calling the appropriate initialization routine for the specified coordinate mode. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em coord\+\_\+mode} & A string indicating the coordinate mode. See the documentation for \mbox{\hyperlink{namespaceregrid__consts}{regrid\+\_\+consts}} for the recognized values. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1973   \textcolor{keywordtype}{type}(regridding\_CS),     \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{1974   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in)}    :: coord\_mode\textcolor{comment}{ !< A string indicating the coordinate mode.}}
\DoxyCodeLine{1975 \textcolor{comment}{                                               !! See the documentation for regrid\_consts}}
\DoxyCodeLine{1976 \textcolor{comment}{                                               !! for the recognized values.}}
\DoxyCodeLine{1977   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{1978   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{1979 }
\DoxyCodeLine{1980   \textcolor{keywordflow}{select case} (coordinatemode(coord\_mode))}
\DoxyCodeLine{1981   \textcolor{keywordflow}{case} (regridding\_zstar)}
\DoxyCodeLine{1982     \textcolor{keyword}{call }init\_coord\_zlike(cs\%zlike\_CS, cs\%nk, cs\%coordinateResolution)}
\DoxyCodeLine{1983   \textcolor{keywordflow}{case} (regridding\_sigma\_shelf\_zstar)}
\DoxyCodeLine{1984     \textcolor{keyword}{call }init\_coord\_zlike(cs\%zlike\_CS, cs\%nk, cs\%coordinateResolution)}
\DoxyCodeLine{1985   \textcolor{keywordflow}{case} (regridding\_sigma)}
\DoxyCodeLine{1986     \textcolor{keyword}{call }init\_coord\_sigma(cs\%sigma\_CS, cs\%nk, cs\%coordinateResolution)}
\DoxyCodeLine{1987   \textcolor{keywordflow}{case} (regridding\_rho)}
\DoxyCodeLine{1988     \textcolor{keyword}{call }init\_coord\_rho(cs\%rho\_CS, cs\%nk, cs\%ref\_pressure, cs\%target\_density, cs\%interp\_CS)}
\DoxyCodeLine{1989   \textcolor{keywordflow}{case} (regridding\_hycom1)}
\DoxyCodeLine{1990     \textcolor{keyword}{call }init\_coord\_hycom(cs\%hycom\_CS, cs\%nk, cs\%coordinateResolution, cs\%target\_density, \&}
\DoxyCodeLine{1991                           cs\%interp\_CS)}
\DoxyCodeLine{1992   \textcolor{keywordflow}{case} (regridding\_slight)}
\DoxyCodeLine{1993     \textcolor{keyword}{call }init\_coord\_slight(cs\%slight\_CS, cs\%nk, cs\%ref\_pressure, cs\%target\_density, \&}
\DoxyCodeLine{1994                            cs\%interp\_CS, gv\%m\_to\_H)}
\DoxyCodeLine{1995   \textcolor{keywordflow}{case} (regridding\_adaptive)}
\DoxyCodeLine{1996     \textcolor{keyword}{call }init\_coord\_adapt(cs\%adapt\_CS, cs\%nk, cs\%coordinateResolution, gv\%m\_to\_H, us\%kg\_m3\_to\_R)}
\DoxyCodeLine{1997 \textcolor{keywordflow}{  end select}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a8c91ba68f0906e1fc76b7008caf6288e}\label{namespacemom__regridding_a8c91ba68f0906e1fc76b7008caf6288e}} 
\index{mom\_regridding@{mom\_regridding}!initialize\_regridding@{initialize\_regridding}}
\index{initialize\_regridding@{initialize\_regridding}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{initialize\_regridding()}{initialize\_regridding()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::initialize\+\_\+regridding (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in)}]{max\+\_\+depth,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{character(len=$\ast$), intent(in)}]{mdl,  }\item[{character(len=$\ast$), intent(in)}]{coord\+\_\+mode,  }\item[{character(len=$\ast$), intent(in)}]{param\+\_\+prefix,  }\item[{character(len=$\ast$), intent(in)}]{param\+\_\+suffix }\end{DoxyParamCaption})}



Initialization and configures a regridding control structure based on customizable run-\/time parameters. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+depth} & The maximum depth of the ocean \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file \\
\hline
\mbox{\texttt{ in}}  & {\em mdl} & Name of calling module. \\
\hline
\mbox{\texttt{ in}}  & {\em coord\+\_\+mode} & Coordinate mode \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+prefix} & String to prefix to parameter names. If empty, causes main model parameters to be used. \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+suffix} & String to append to parameter names. \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{181   \textcolor{keywordtype}{type}(regridding\_CS),        \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{  !< Regridding control structure}}
\DoxyCodeLine{182   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< Ocean vertical grid structure}}
\DoxyCodeLine{183   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{184 \textcolor{keywordtype}{  real},                       \textcolor{keywordtype}{intent(in)}    :: max\_depth\textcolor{comment}{  !< The maximum depth of the ocean [Z \string~> m].}}
\DoxyCodeLine{185   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file}}
\DoxyCodeLine{186   \textcolor{keywordtype}{character(len=*)},           \textcolor{keywordtype}{intent(in)}    :: mdl\textcolor{comment}{        !< Name of calling module.}}
\DoxyCodeLine{187   \textcolor{keywordtype}{character(len=*)},           \textcolor{keywordtype}{intent(in)}    :: coord\_mode\textcolor{comment}{ !< Coordinate mode}}
\DoxyCodeLine{188   \textcolor{keywordtype}{character(len=*)},           \textcolor{keywordtype}{intent(in)}    :: param\_prefix\textcolor{comment}{ !< String to prefix to parameter names.}}
\DoxyCodeLine{189 \textcolor{comment}{                                                            !! If empty, causes main model parameters to be used.}}
\DoxyCodeLine{190   \textcolor{keywordtype}{character(len=*)},           \textcolor{keywordtype}{intent(in)}    :: param\_suffix\textcolor{comment}{ !< String to append to parameter names.}}
\DoxyCodeLine{191 }
\DoxyCodeLine{192   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{193   \textcolor{keywordtype}{integer} :: ke \textcolor{comment}{! Number of levels}}
\DoxyCodeLine{194   \textcolor{keywordtype}{character(len=80)}  :: string, string2, varName \textcolor{comment}{! Temporary strings}}
\DoxyCodeLine{195   \textcolor{keywordtype}{character(len=40)}  :: coord\_units, param\_name, coord\_res\_param \textcolor{comment}{! Temporary strings}}
\DoxyCodeLine{196   \textcolor{keywordtype}{character(len=200)} :: inputdir, fileName}
\DoxyCodeLine{197   \textcolor{keywordtype}{character(len=320)} :: message \textcolor{comment}{! Temporary strings}}
\DoxyCodeLine{198   \textcolor{keywordtype}{character(len=12)} :: expected\_units \textcolor{comment}{! Temporary strings}}
\DoxyCodeLine{199   \textcolor{keywordtype}{logical} :: tmpLogical, fix\_haloclines, set\_max, do\_sum, main\_parameters}
\DoxyCodeLine{200   \textcolor{keywordtype}{logical} :: coord\_is\_state\_dependent, ierr}
\DoxyCodeLine{201   \textcolor{keywordtype}{logical} :: default\_2018\_answers, remap\_answers\_2018}
\DoxyCodeLine{202 \textcolor{keywordtype}{  real} :: filt\_len, strat\_tol, index\_scale, tmpReal, P\_Ref}
\DoxyCodeLine{203 \textcolor{keywordtype}{  real} :: maximum\_depth \textcolor{comment}{! The maximum depth of the ocean [m] (not in Z).}}
\DoxyCodeLine{204 \textcolor{keywordtype}{  real} :: dz\_fixed\_sfc, Rho\_avg\_depth, nlay\_sfc\_int}
\DoxyCodeLine{205 \textcolor{keywordtype}{  real} :: adaptTimeRatio, adaptZoom, adaptZoomCoeff, adaptBuoyCoeff, adaptAlpha}
\DoxyCodeLine{206 \textcolor{keywordtype}{  real} :: adaptDrho0 \textcolor{comment}{! Reference density difference for stratification-\/dependent diffusion. [R \string~> kg m-\/3]}}
\DoxyCodeLine{207   \textcolor{keywordtype}{integer} :: nz\_fixed\_sfc, k, nzf(4)}
\DoxyCodeLine{208 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: dz     \textcolor{comment}{! Resolution (thickness) in units of coordinate, which may be [m]}}
\DoxyCodeLine{209                                             \textcolor{comment}{! or [Z \string~> m] or [H \string~> m or kg m-\/2] or [R \string~> kg m-\/3] or other units.}}
\DoxyCodeLine{210 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: h\_max  \textcolor{comment}{! Maximum layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{211 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: z\_max  \textcolor{comment}{! Maximum interface depths [H \string~> m or kg m-\/2] or other}}
\DoxyCodeLine{212                                             \textcolor{comment}{! units depending on the coordinate}}
\DoxyCodeLine{213 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: dz\_max \textcolor{comment}{! Thicknesses used to find maximum interface depths}}
\DoxyCodeLine{214                                             \textcolor{comment}{! [H \string~> m or kg m-\/2] or other units}}
\DoxyCodeLine{215 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: rho\_target \textcolor{comment}{! Target density used in HYBRID mode [kg m-\/3]}}
\DoxyCodeLine{216   \textcolor{comment}{! Thicknesses [m] that give level centers corresponding to table 2 of WOA09}}
\DoxyCodeLine{217 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(40)} :: woa09\_dz = (/ 5.,  10.,  10.,  15.,  22.5, 25., 25.,  25.,  \&}
\DoxyCodeLine{218                                       37.5, 50.,  50.,  75., 100., 100., 100., 100., \&}
\DoxyCodeLine{219                                      100., 100., 100., 100., 100., 100., 100., 175., \&}
\DoxyCodeLine{220                                      250., 375., 500., 500., 500., 500., 500., 500., \&}
\DoxyCodeLine{221                                      500., 500., 500., 500., 500., 500., 500., 500. /)}
\DoxyCodeLine{222 }
\DoxyCodeLine{223   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})}
\DoxyCodeLine{224   inputdir = slasher(inputdir)}
\DoxyCodeLine{225 }
\DoxyCodeLine{226   main\_parameters=.false.}
\DoxyCodeLine{227   \textcolor{keywordflow}{if} (len\_trim(param\_prefix)==0) main\_parameters=.true.}
\DoxyCodeLine{228   \textcolor{keywordflow}{if} (main\_parameters .and. len\_trim(param\_suffix)>0) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{', initialize\_regridding: '}// \&}
\DoxyCodeLine{229               \textcolor{stringliteral}{'Suffix provided without prefix for parameter names!'})}
\DoxyCodeLine{230 }
\DoxyCodeLine{231   cs\%nk = 0}
\DoxyCodeLine{232   cs\%regridding\_scheme = coordinatemode(coord\_mode)}
\DoxyCodeLine{233   coord\_is\_state\_dependent = state\_dependent(coord\_mode)}
\DoxyCodeLine{234   maximum\_depth = us\%Z\_to\_m*max\_depth}
\DoxyCodeLine{235 }
\DoxyCodeLine{236   \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keywordflow}{then}}
\DoxyCodeLine{237     \textcolor{comment}{! Read coordinate units parameter (main model = REGRIDDING\_COORDINATE\_UNITS)}}
\DoxyCodeLine{238     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REGRIDDING\_COORDINATE\_UNITS"}, coord\_units, \&}
\DoxyCodeLine{239                  \textcolor{stringliteral}{"Units of the regridding coordinate."}, default=coordinateunits(coord\_mode))}
\DoxyCodeLine{240   \textcolor{keywordflow}{else}}
\DoxyCodeLine{241     coord\_units=coordinateunits(coord\_mode)}
\DoxyCodeLine{242 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{243 }
\DoxyCodeLine{244   \textcolor{keywordflow}{if} (coord\_is\_state\_dependent) \textcolor{keywordflow}{then}}
\DoxyCodeLine{245     \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keywordflow}{then}}
\DoxyCodeLine{246       param\_name = \textcolor{stringliteral}{"INTERPOLATION\_SCHEME"}}
\DoxyCodeLine{247       string2 = regriddingdefaultinterpscheme}
\DoxyCodeLine{248     \textcolor{keywordflow}{else}}
\DoxyCodeLine{249       param\_name = trim(param\_prefix)//\textcolor{stringliteral}{"\_INTERP\_SCHEME\_"}//trim(param\_suffix)}
\DoxyCodeLine{250       string2 = \textcolor{stringliteral}{'PPM\_H4'} \textcolor{comment}{! Default for diagnostics}}
\DoxyCodeLine{251 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{252     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERPOLATION\_SCHEME"}, string, \&}
\DoxyCodeLine{253                  \textcolor{stringliteral}{"This sets the interpolation scheme to use to "}//\&}
\DoxyCodeLine{254                  \textcolor{stringliteral}{"determine the new grid. These parameters are "}//\&}
\DoxyCodeLine{255                  \textcolor{stringliteral}{"only relevant when REGRIDDING\_COORDINATE\_MODE is "}//\&}
\DoxyCodeLine{256                  \textcolor{stringliteral}{"set to a function of state. Otherwise, it is not "}//\&}
\DoxyCodeLine{257                  \textcolor{stringliteral}{"used. It can be one of the following schemes: "}//\&}
\DoxyCodeLine{258                  trim(regriddinginterpschemedoc), default=trim(string2))}
\DoxyCodeLine{259     \textcolor{keyword}{call }set\_regrid\_params(cs, interp\_scheme=string)}
\DoxyCodeLine{260 }
\DoxyCodeLine{261     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, \&}
\DoxyCodeLine{262                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, \&}
\DoxyCodeLine{263                  default=.false.)}
\DoxyCodeLine{264     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, remap\_answers\_2018, \&}
\DoxyCodeLine{265                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//\&}
\DoxyCodeLine{266                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//\&}
\DoxyCodeLine{267                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)}
\DoxyCodeLine{268     \textcolor{keyword}{call }set\_regrid\_params(cs, remap\_answers\_2018=remap\_answers\_2018)}
\DoxyCodeLine{269 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{270 }
\DoxyCodeLine{271   \textcolor{keywordflow}{if} (main\_parameters .and. coord\_is\_state\_dependent) \textcolor{keywordflow}{then}}
\DoxyCodeLine{272     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BOUNDARY\_EXTRAPOLATION"}, tmplogical, \&}
\DoxyCodeLine{273                  \textcolor{stringliteral}{"When defined, a proper high-\/order reconstruction "}//\&}
\DoxyCodeLine{274                  \textcolor{stringliteral}{"scheme is used within boundary cells rather "}//\&}
\DoxyCodeLine{275                  \textcolor{stringliteral}{"than PCM. E.g., if PPM is used for remapping, a "}//\&}
\DoxyCodeLine{276                  \textcolor{stringliteral}{"PPM reconstruction will also be used within "}//\&}
\DoxyCodeLine{277                  \textcolor{stringliteral}{"boundary cells."}, default=regriddingdefaultboundaryextrapolation)}
\DoxyCodeLine{278     \textcolor{keyword}{call }set\_regrid\_params(cs, boundary\_extrapolation=tmplogical)}
\DoxyCodeLine{279   \textcolor{keywordflow}{else}}
\DoxyCodeLine{280     \textcolor{keyword}{call }set\_regrid\_params(cs, boundary\_extrapolation=.false.)}
\DoxyCodeLine{281 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{282 }
\DoxyCodeLine{283   \textcolor{comment}{! Read coordinate configuration parameter (main model = ALE\_COORDINATE\_CONFIG)}}
\DoxyCodeLine{284   \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keywordflow}{then}}
\DoxyCodeLine{285     param\_name = \textcolor{stringliteral}{"ALE\_COORDINATE\_CONFIG"}}
\DoxyCodeLine{286     coord\_res\_param = \textcolor{stringliteral}{"ALE\_RESOLUTION"}}
\DoxyCodeLine{287     string2 = \textcolor{stringliteral}{'UNIFORM'}}
\DoxyCodeLine{288   \textcolor{keywordflow}{else}}
\DoxyCodeLine{289     param\_name = trim(param\_prefix)//\textcolor{stringliteral}{"\_DEF\_"}//trim(param\_suffix)}
\DoxyCodeLine{290     coord\_res\_param = trim(param\_prefix)//\textcolor{stringliteral}{"\_RES\_"}//trim(param\_suffix)}
\DoxyCodeLine{291     string2 = \textcolor{stringliteral}{'UNIFORM'}}
\DoxyCodeLine{292     \textcolor{keywordflow}{if} (maximum\_depth>3000.) string2=\textcolor{stringliteral}{'WOA09'} \textcolor{comment}{! For convenience}}
\DoxyCodeLine{293 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{294   \textcolor{keyword}{call }get\_param(param\_file, mdl, param\_name, string, \&}
\DoxyCodeLine{295                  \textcolor{stringliteral}{"Determines how to specify the coordinate "}//\&}
\DoxyCodeLine{296                  \textcolor{stringliteral}{"resolution. Valid options are:\(\backslash\)n"}//\&}
\DoxyCodeLine{297                  \textcolor{stringliteral}{" PARAM       -\/ use the vector-\/parameter "}//trim(coord\_res\_param)//\textcolor{stringliteral}{"\(\backslash\)n"}//\&}
\DoxyCodeLine{298                  \textcolor{stringliteral}{" UNIFORM[:N] -\/ uniformly distributed\(\backslash\)n"}//\&}
\DoxyCodeLine{299                  \textcolor{stringliteral}{" FILE:string -\/ read from a file. The string specifies\(\backslash\)n"}//\&}
\DoxyCodeLine{300                  \textcolor{stringliteral}{"               the filename and variable name, separated\(\backslash\)n"}//\&}
\DoxyCodeLine{301                  \textcolor{stringliteral}{"               by a comma or space, e.g. FILE:lev.nc,dz\(\backslash\)n"}//\&}
\DoxyCodeLine{302                  \textcolor{stringliteral}{"               or FILE:lev.nc,interfaces=zw\(\backslash\)n"}//\&}
\DoxyCodeLine{303                  \textcolor{stringliteral}{" WOA09[:N]   -\/ the WOA09 vertical grid (approximately)\(\backslash\)n"}//\&}
\DoxyCodeLine{304                  \textcolor{stringliteral}{" FNC1:string -\/ FNC1:dz\_min,H\_total,power,precision\(\backslash\)n"}//\&}
\DoxyCodeLine{305                  \textcolor{stringliteral}{" HYBRID:string -\/ read from a file. The string specifies\(\backslash\)n"}//\&}
\DoxyCodeLine{306                  \textcolor{stringliteral}{"               the filename and two variable names, separated\(\backslash\)n"}//\&}
\DoxyCodeLine{307                  \textcolor{stringliteral}{"               by a comma or space, for sigma-\/2 and dz. e.g.\(\backslash\)n"}//\&}
\DoxyCodeLine{308                  \textcolor{stringliteral}{"               HYBRID:vgrid.nc,sigma2,dz"},\&}
\DoxyCodeLine{309                  default=trim(string2))}
\DoxyCodeLine{310   message = \textcolor{stringliteral}{"The distribution of vertical resolution for the target\(\backslash\)n"}//\&}
\DoxyCodeLine{311             \textcolor{stringliteral}{"grid used for Eulerian-\/like coordinates. For example,\(\backslash\)n"}//\&}
\DoxyCodeLine{312             \textcolor{stringliteral}{"in z-\/coordinate mode, the parameter is a list of level\(\backslash\)n"}//\&}
\DoxyCodeLine{313             \textcolor{stringliteral}{"thicknesses (in m). In sigma-\/coordinate mode, the list\(\backslash\)n"}//\&}
\DoxyCodeLine{314             \textcolor{stringliteral}{"is of non-\/dimensional fractions of the water column."}}
\DoxyCodeLine{315   \textcolor{keywordflow}{if} (index(trim(string),\textcolor{stringliteral}{'UNIFORM'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{316     \textcolor{keywordflow}{if} (len\_trim(string)==7) \textcolor{keywordflow}{then}}
\DoxyCodeLine{317       ke = gv\%ke \textcolor{comment}{! Use model nk by default}}
\DoxyCodeLine{318       tmpreal = maximum\_depth}
\DoxyCodeLine{319     \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'UNIFORM:'})==1 .and. len\_trim(string)>8) \textcolor{keywordflow}{then}}
\DoxyCodeLine{320       \textcolor{comment}{! Format is "UNIFORM:N" or "UNIFORM:N,dz"}}
\DoxyCodeLine{321       ke = extract\_integer(string(9:len\_trim(string)),\textcolor{stringliteral}{''},1)}
\DoxyCodeLine{322       tmpreal = extract\_real(string(9:len\_trim(string)),\textcolor{stringliteral}{','},2,missing\_value=maximum\_depth)}
\DoxyCodeLine{323     \textcolor{keywordflow}{else}}
\DoxyCodeLine{324       \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{', initialize\_regridding: '}// \&}
\DoxyCodeLine{325           \textcolor{stringliteral}{'Unable to interpret "'}//trim(string)//\textcolor{stringliteral}{'".'})}
\DoxyCodeLine{326 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{327     \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{328     dz(:) = uniformresolution(ke, coord\_mode, tmpreal, \&}
\DoxyCodeLine{329                               us\%R\_to\_kg\_m3*(gv\%Rlay(1) + 0.5*(gv\%Rlay(1)-\/gv\%Rlay(min(2,ke)))), \&}
\DoxyCodeLine{330                               us\%R\_to\_kg\_m3*(gv\%Rlay(ke) + 0.5*(gv\%Rlay(ke)-\/gv\%Rlay(max(ke-\/1,1)))) )}
\DoxyCodeLine{331     \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!"}//coord\_res\_param, dz, \&}
\DoxyCodeLine{332                    trim(message), units=trim(coord\_units))}
\DoxyCodeLine{333   \textcolor{keywordflow}{elseif} (trim(string)==\textcolor{stringliteral}{'PARAM'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{334     \textcolor{comment}{! Read coordinate resolution (main model = ALE\_RESOLUTION)}}
\DoxyCodeLine{335     ke = gv\%ke \textcolor{comment}{! Use model nk by default}}
\DoxyCodeLine{336     \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{337     \textcolor{keyword}{call }get\_param(param\_file, mdl, coord\_res\_param, dz, \&}
\DoxyCodeLine{338                    trim(message), units=trim(coord\_units), fail\_if\_missing=.true.)}
\DoxyCodeLine{339   \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'FILE:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{340     \textcolor{comment}{! FILE:filename,var\_name is assumed to be reading level thickness variables}}
\DoxyCodeLine{341     \textcolor{comment}{! FILE:filename,interfaces=var\_name reads positions}}
\DoxyCodeLine{342     \textcolor{keywordflow}{if} (string(6:6)==\textcolor{stringliteral}{'.'} .or. string(6:6)==\textcolor{stringliteral}{'/'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{343       \textcolor{comment}{! If we specified "FILE:./xyz" or "FILE:/xyz" then we have a relative or absolute path}}
\DoxyCodeLine{344       filename = trim( extractword(trim(string(6:80)), 1) )}
\DoxyCodeLine{345     \textcolor{keywordflow}{else}}
\DoxyCodeLine{346       \textcolor{comment}{! Otherwise assume we should look for the file in INPUTDIR}}
\DoxyCodeLine{347       filename = trim(inputdir) // trim( extractword(trim(string(6:80)), 1) )}
\DoxyCodeLine{348 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{349     \textcolor{keywordflow}{if} (.not. file\_exists(filename)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{350             \textcolor{stringliteral}{"Specified file not found: Looking for '"}//trim(filename)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{351 }
\DoxyCodeLine{352     varname = trim( extractword(trim(string(6:)), 2) )}
\DoxyCodeLine{353     \textcolor{keywordflow}{if} (len\_trim(varname)==0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{354       \textcolor{keywordflow}{if} (field\_exists(filename,\textcolor{stringliteral}{'dz'})) then; varname = \textcolor{stringliteral}{'dz'}}
\DoxyCodeLine{355       \textcolor{keywordflow}{elseif} (field\_exists(filename,\textcolor{stringliteral}{'dsigma'})) then; varname = \textcolor{stringliteral}{'dsigma'}}
\DoxyCodeLine{356       \textcolor{keywordflow}{elseif} (field\_exists(filename,\textcolor{stringliteral}{'ztest'})) then; varname = \textcolor{stringliteral}{'ztest'}}
\DoxyCodeLine{357       \textcolor{keywordflow}{else} ;  \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{358                     \textcolor{stringliteral}{"Coordinate variable not specified and none could be guessed."})}
\DoxyCodeLine{359 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{360 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{361     \textcolor{comment}{! This check fails when the variable is a dimension variable! -\/AJA}}
\DoxyCodeLine{362    \textcolor{comment}{!if (.not. field\_exists(fileName,trim(varName))) call MOM\_error(FATAL,trim(mdl)//", initialize\_regridding: "// \&}}
\DoxyCodeLine{363    \textcolor{comment}{!             "Specified field not found: Looking for '"//trim(varName)//"' ("//trim(string)//")")}}
\DoxyCodeLine{364     \textcolor{keywordflow}{if} (cs\%regridding\_scheme == regridding\_sigma) \textcolor{keywordflow}{then}}
\DoxyCodeLine{365       expected\_units = \textcolor{stringliteral}{'nondim'}}
\DoxyCodeLine{366     \textcolor{keywordflow}{elseif} (cs\%regridding\_scheme == regridding\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{367       expected\_units = \textcolor{stringliteral}{'kg m-\/3'}}
\DoxyCodeLine{368     \textcolor{keywordflow}{else}}
\DoxyCodeLine{369       expected\_units = \textcolor{stringliteral}{'meters'}}
\DoxyCodeLine{370 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{371     \textcolor{keywordflow}{if} (index(trim(varname),\textcolor{stringliteral}{'interfaces='})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{372       varname=trim(varname(12:))}
\DoxyCodeLine{373       \textcolor{keyword}{call }check\_grid\_def(filename, varname, expected\_units, message, ierr)}
\DoxyCodeLine{374       \textcolor{keywordflow}{if} (ierr) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}//\&}
\DoxyCodeLine{375                   \textcolor{stringliteral}{"Unsupported format in grid definition '"}//trim(filename)//\textcolor{stringliteral}{"'. Error message "}//trim(message))}
\DoxyCodeLine{376       \textcolor{keyword}{call }field\_size(trim(filename), trim(varname), nzf)}
\DoxyCodeLine{377       ke = nzf(1)-\/1}
\DoxyCodeLine{378       \textcolor{keywordflow}{if} (ke < 1) \textcolor{keyword}{call }mom\_error(fatal, trim(mdl)//\textcolor{stringliteral}{" initialize\_regridding via Var "}//trim(varname)//\&}
\DoxyCodeLine{379                                  \textcolor{stringliteral}{"in FILE "}//trim(filename)//\textcolor{stringliteral}{" requires at least 2 target interface values."})}
\DoxyCodeLine{380       \textcolor{keywordflow}{if} (cs\%regridding\_scheme == regridding\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{381         \textcolor{keyword}{allocate}(rho\_target(ke+1))}
\DoxyCodeLine{382         \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), rho\_target)}
\DoxyCodeLine{383       \textcolor{keywordflow}{else}}
\DoxyCodeLine{384         \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{385         \textcolor{keyword}{allocate}(z\_max(ke+1))}
\DoxyCodeLine{386         \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), z\_max)}
\DoxyCodeLine{387         dz(:) = abs(z\_max(1:ke) -\/ z\_max(2:ke+1))}
\DoxyCodeLine{388         \textcolor{keyword}{deallocate}(z\_max)}
\DoxyCodeLine{389 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{390     \textcolor{keywordflow}{else}}
\DoxyCodeLine{391       \textcolor{comment}{! Assume reading resolution}}
\DoxyCodeLine{392       \textcolor{keyword}{call }field\_size(trim(filename), trim(varname), nzf)}
\DoxyCodeLine{393       ke = nzf(1)}
\DoxyCodeLine{394       \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{395       \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), dz)}
\DoxyCodeLine{396 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{397     \textcolor{keywordflow}{if} (main\_parameters .and. (ke/=gv\%ke)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{398       \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{', initialize\_regridding: '}// \&}
\DoxyCodeLine{399                  \textcolor{stringliteral}{'Mismatch in number of model levels and "'}//trim(string)//\textcolor{stringliteral}{'".'})}
\DoxyCodeLine{400 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{401     \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!"}//coord\_res\_param, dz, \&}
\DoxyCodeLine{402                trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{403   \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'FNC1:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{404     ke = gv\%ke; \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{405     \textcolor{keyword}{call }dz\_function1( trim(string(6:)), dz )}
\DoxyCodeLine{406     \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!"}//coord\_res\_param, dz, \&}
\DoxyCodeLine{407                trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{408   \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'RFNC1:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{409     \textcolor{comment}{! Function used for set target interface densities}}
\DoxyCodeLine{410     ke = rho\_function1( trim(string(7:)), rho\_target )}
\DoxyCodeLine{411   \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'HYBRID:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{412     ke = gv\%ke; \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{413     \textcolor{comment}{! The following assumes the FILE: syntax of above but without "FILE:" in the string}}
\DoxyCodeLine{414     \textcolor{keyword}{allocate}(rho\_target(ke+1))}
\DoxyCodeLine{415     filename = trim( extractword(trim(string(8:)), 1) )}
\DoxyCodeLine{416     \textcolor{keywordflow}{if} (filename(1:1)/=\textcolor{stringliteral}{'.'} .and. filename(1:1)/=\textcolor{stringliteral}{'/'}) filename = trim(inputdir) // trim( filename )}
\DoxyCodeLine{417     \textcolor{keywordflow}{if} (.not. file\_exists(filename)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: HYBRID "}// \&}
\DoxyCodeLine{418       \textcolor{stringliteral}{"Specified file not found: Looking for '"}//trim(filename)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{419     varname = trim( extractword(trim(string(8:)), 2) )}
\DoxyCodeLine{420     \textcolor{keywordflow}{if} (.not. field\_exists(filename,varname)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: HYBRID "}// \&}
\DoxyCodeLine{421       \textcolor{stringliteral}{"Specified field not found: Looking for '"}//trim(varname)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{422     \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), rho\_target)}
\DoxyCodeLine{423     varname = trim( extractword(trim(string(8:)), 3) )}
\DoxyCodeLine{424     \textcolor{keywordflow}{if} (varname(1:5) == \textcolor{stringliteral}{'FNC1:'}) \textcolor{keywordflow}{then} \textcolor{comment}{! Use FNC1 to calculate dz}}
\DoxyCodeLine{425       \textcolor{keyword}{call }dz\_function1( trim(string((index(trim(string),\textcolor{stringliteral}{'FNC1:'})+5):)), dz )}
\DoxyCodeLine{426     \textcolor{keywordflow}{else} \textcolor{comment}{! Read dz from file}}
\DoxyCodeLine{427       \textcolor{keywordflow}{if} (.not. field\_exists(filename,varname)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: HYBRID "}// \&}
\DoxyCodeLine{428         \textcolor{stringliteral}{"Specified field not found: Looking for '"}//trim(varname)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{429       \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), dz)}
\DoxyCodeLine{430 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{431     \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keywordflow}{then}}
\DoxyCodeLine{432       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!"}//coord\_res\_param, dz, \&}
\DoxyCodeLine{433                trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{434       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!TARGET\_DENSITIES"}, rho\_target, \&}
\DoxyCodeLine{435                \textcolor{stringliteral}{'HYBRID target densities for interfaces'}, units=coordinateunits(coord\_mode))}
\DoxyCodeLine{436 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{437   \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'WOA09'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{438     \textcolor{keywordflow}{if} (len\_trim(string)==5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{439       tmpreal = 0. ; ke = 0}
\DoxyCodeLine{440       \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (tmpreal<maximum\_depth)}
\DoxyCodeLine{441         ke = ke + 1}
\DoxyCodeLine{442         tmpreal = tmpreal + woa09\_dz(ke)}
\DoxyCodeLine{443 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{444     \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'WOA09:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{445       \textcolor{keywordflow}{if} (len\_trim(string)==6) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{', initialize\_regridding: '}// \&}
\DoxyCodeLine{446                  \textcolor{stringliteral}{'Expected string of form "WOA09:N" but got "'}//trim(string)//\textcolor{stringliteral}{'".'})}
\DoxyCodeLine{447       ke = extract\_integer(string(7:len\_trim(string)),\textcolor{stringliteral}{''},1)}
\DoxyCodeLine{448 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{449     \textcolor{keywordflow}{if} (ke>40 .or. ke<1) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{', initialize\_regridding: '}// \&}
\DoxyCodeLine{450                  \textcolor{stringliteral}{'For "WOA05:N" N must 0<N<41 but got "'}//trim(string)//\textcolor{stringliteral}{'".'})}
\DoxyCodeLine{451     \textcolor{keyword}{allocate}(dz(ke))}
\DoxyCodeLine{452     dz(1:ke) = woa09\_dz(1:ke)}
\DoxyCodeLine{453   \textcolor{keywordflow}{else}}
\DoxyCodeLine{454     \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{455       \textcolor{stringliteral}{"Unrecognized coordinate configuration"}//trim(string))}
\DoxyCodeLine{456 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{457 }
\DoxyCodeLine{458   \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keywordflow}{then}}
\DoxyCodeLine{459     \textcolor{comment}{! This is a work around to apparently needed to work with the from\_Z initialization...  ???}}
\DoxyCodeLine{460     \textcolor{keywordflow}{if} (coordinatemode(coord\_mode) == regridding\_zstar .or. \&}
\DoxyCodeLine{461         coordinatemode(coord\_mode) == regridding\_hycom1 .or. \&}
\DoxyCodeLine{462         coordinatemode(coord\_mode) == regridding\_slight .or. \&}
\DoxyCodeLine{463         coordinatemode(coord\_mode) == regridding\_adaptive) \textcolor{keywordflow}{then}}
\DoxyCodeLine{464       \textcolor{comment}{! Adjust target grid to be consistent with maximum\_depth}}
\DoxyCodeLine{465       tmpreal = sum( dz(:) )}
\DoxyCodeLine{466       \textcolor{keywordflow}{if} (tmpreal < maximum\_depth) \textcolor{keywordflow}{then}}
\DoxyCodeLine{467         dz(ke) = dz(ke) + ( maximum\_depth -\/ tmpreal )}
\DoxyCodeLine{468       \textcolor{keywordflow}{elseif} (tmpreal > maximum\_depth) \textcolor{keywordflow}{then}}
\DoxyCodeLine{469         \textcolor{keywordflow}{if} ( dz(ke) + ( maximum\_depth -\/ tmpreal ) > 0. ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{470           dz(ke) = dz(ke) + ( maximum\_depth -\/ tmpreal )}
\DoxyCodeLine{471         \textcolor{keywordflow}{else}}
\DoxyCodeLine{472           \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{473             \textcolor{stringliteral}{"MAXIMUM\_DEPTH was too shallow to adjust bottom layer of DZ!"}//trim(string))}
\DoxyCodeLine{474 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{475 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{476 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{477 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{478 }
\DoxyCodeLine{479   cs\%nk=ke}
\DoxyCodeLine{480 }
\DoxyCodeLine{481   \textcolor{comment}{! Target resolution (for fixed coordinates)}}
\DoxyCodeLine{482   \textcolor{keyword}{allocate}( cs\%coordinateResolution(cs\%nk) ); cs\%coordinateResolution(:) = -\/1.e30}
\DoxyCodeLine{483   \textcolor{keywordflow}{if} (state\_dependent(cs\%regridding\_scheme)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{484     \textcolor{comment}{! Target values}}
\DoxyCodeLine{485     \textcolor{keyword}{allocate}( cs\%target\_density(cs\%nk+1) ); cs\%target\_density(:) = -\/1.e30*us\%kg\_m3\_to\_R}
\DoxyCodeLine{486 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{487 }
\DoxyCodeLine{488   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(dz)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{489     \textcolor{keywordflow}{if} (coordinatemode(coord\_mode) == regridding\_sigma) \textcolor{keywordflow}{then}}
\DoxyCodeLine{490       \textcolor{keyword}{call }setcoordinateresolution(dz, cs, scale=1.0)}
\DoxyCodeLine{491     \textcolor{keywordflow}{elseif} (coordinatemode(coord\_mode) == regridding\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{492       \textcolor{keyword}{call }setcoordinateresolution(dz, cs, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{493       cs\%coord\_scale = us\%R\_to\_kg\_m3}
\DoxyCodeLine{494     \textcolor{keywordflow}{elseif} (coordinatemode(coord\_mode) == regridding\_adaptive) \textcolor{keywordflow}{then}}
\DoxyCodeLine{495       \textcolor{keyword}{call }setcoordinateresolution(dz, cs, scale=gv\%m\_to\_H)}
\DoxyCodeLine{496       cs\%coord\_scale = gv\%H\_to\_m}
\DoxyCodeLine{497     \textcolor{keywordflow}{else}}
\DoxyCodeLine{498       \textcolor{keyword}{call }setcoordinateresolution(dz, cs, scale=us\%m\_to\_Z)}
\DoxyCodeLine{499       cs\%coord\_scale = us\%Z\_to\_m}
\DoxyCodeLine{500 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{501 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{502 }
\DoxyCodeLine{503   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(rho\_target)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{504     \textcolor{keyword}{call }set\_target\_densities(cs, us\%kg\_m3\_to\_R*rho\_target)}
\DoxyCodeLine{505     \textcolor{keyword}{deallocate}(rho\_target)}
\DoxyCodeLine{506 }
\DoxyCodeLine{507   \textcolor{comment}{! \(\backslash\)todo This line looks like it would overwrite the target densities set just above?}}
\DoxyCodeLine{508   \textcolor{keywordflow}{elseif} (coordinatemode(coord\_mode) == regridding\_rho) \textcolor{keywordflow}{then}}
\DoxyCodeLine{509     \textcolor{keyword}{call }set\_target\_densities\_from\_gv(gv, us, cs)}
\DoxyCodeLine{510     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!TARGET\_DENSITIES"}, us\%R\_to\_kg\_m3*cs\%target\_density(:), \&}
\DoxyCodeLine{511              \textcolor{stringliteral}{'RHO target densities for interfaces'}, units=coordinateunits(coord\_mode))}
\DoxyCodeLine{512 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{513 }
\DoxyCodeLine{514   \textcolor{comment}{! initialise coordinate-\/specific control structure}}
\DoxyCodeLine{515   \textcolor{keyword}{call }initcoord(cs, gv, us, coord\_mode)}
\DoxyCodeLine{516 }
\DoxyCodeLine{517   \textcolor{keywordflow}{if} (main\_parameters .and. coord\_is\_state\_dependent) \textcolor{keywordflow}{then}}
\DoxyCodeLine{518     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"P\_REF"}, p\_ref, \&}
\DoxyCodeLine{519                  \textcolor{stringliteral}{"The pressure that is used for calculating the coordinate "}//\&}
\DoxyCodeLine{520                  \textcolor{stringliteral}{"density.  (1 Pa = 1e4 dbar, so 2e7 is commonly used.) "}//\&}
\DoxyCodeLine{521                  \textcolor{stringliteral}{"This is only used if USE\_EOS and ENABLE\_THERMODYNAMICS are true."}, \&}
\DoxyCodeLine{522                  units=\textcolor{stringliteral}{"Pa"}, default=2.0e7, scale=us\%kg\_m3\_to\_R*us\%m\_s\_to\_L\_T**2)}
\DoxyCodeLine{523     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REGRID\_COMPRESSIBILITY\_FRACTION"}, tmpreal, \&}
\DoxyCodeLine{524                  \textcolor{stringliteral}{"When interpolating potential density profiles we can add "}//\&}
\DoxyCodeLine{525                  \textcolor{stringliteral}{"some artificial compressibility solely to make homogeneous "}//\&}
\DoxyCodeLine{526                  \textcolor{stringliteral}{"regions appear stratified."}, units=\textcolor{stringliteral}{"nondim"}, default=0.)}
\DoxyCodeLine{527     \textcolor{keyword}{call }set\_regrid\_params(cs, compress\_fraction=tmpreal, ref\_pressure=p\_ref)}
\DoxyCodeLine{528 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{529 }
\DoxyCodeLine{530   \textcolor{keywordflow}{if} (main\_parameters) \textcolor{keywordflow}{then}}
\DoxyCodeLine{531     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIN\_THICKNESS"}, tmpreal, \&}
\DoxyCodeLine{532                  \textcolor{stringliteral}{"When regridding, this is the minimum layer "}//\&}
\DoxyCodeLine{533                  \textcolor{stringliteral}{"thickness allowed."}, units=\textcolor{stringliteral}{"m"}, scale=gv\%m\_to\_H, \&}
\DoxyCodeLine{534                  default=regriddingdefaultminthickness )}
\DoxyCodeLine{535     \textcolor{keyword}{call }set\_regrid\_params(cs, min\_thickness=tmpreal)}
\DoxyCodeLine{536   \textcolor{keywordflow}{else}}
\DoxyCodeLine{537     \textcolor{keyword}{call }set\_regrid\_params(cs, min\_thickness=0.)}
\DoxyCodeLine{538 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{539 }
\DoxyCodeLine{540   \textcolor{keywordflow}{if} (coordinatemode(coord\_mode) == regridding\_slight) \textcolor{keywordflow}{then}}
\DoxyCodeLine{541     \textcolor{comment}{! Set SLight-\/specific regridding parameters.}}
\DoxyCodeLine{542     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SLIGHT\_DZ\_SURFACE"}, dz\_fixed\_sfc, \&}
\DoxyCodeLine{543                  \textcolor{stringliteral}{"The nominal thickness of fixed thickness near-\/surface "}//\&}
\DoxyCodeLine{544                  \textcolor{stringliteral}{"layers with the SLight coordinate."}, units=\textcolor{stringliteral}{"m"}, default=1.0, scale=gv\%m\_to\_H)}
\DoxyCodeLine{545     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SLIGHT\_NZ\_SURFACE\_FIXED"}, nz\_fixed\_sfc, \&}
\DoxyCodeLine{546                  \textcolor{stringliteral}{"The number of fixed-\/depth surface layers with the SLight "}//\&}
\DoxyCodeLine{547                  \textcolor{stringliteral}{"coordinate."}, units=\textcolor{stringliteral}{"nondimensional"}, default=2)}
\DoxyCodeLine{548     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SLIGHT\_SURFACE\_AVG\_DEPTH"}, rho\_avg\_depth, \&}
\DoxyCodeLine{549                  \textcolor{stringliteral}{"The thickness of the surface region over which to average "}//\&}
\DoxyCodeLine{550                  \textcolor{stringliteral}{"when calculating the density to use to define the interior "}//\&}
\DoxyCodeLine{551                  \textcolor{stringliteral}{"with the SLight coordinate."}, units=\textcolor{stringliteral}{"m"}, default=1.0, scale=gv\%m\_to\_H)}
\DoxyCodeLine{552     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SLIGHT\_NLAY\_TO\_INTERIOR"}, nlay\_sfc\_int, \&}
\DoxyCodeLine{553                  \textcolor{stringliteral}{"The number of layers to offset the surface density when "}//\&}
\DoxyCodeLine{554                  \textcolor{stringliteral}{"defining where the interior ocean starts with SLight."}, \&}
\DoxyCodeLine{555                  units=\textcolor{stringliteral}{"nondimensional"}, default=2.0)}
\DoxyCodeLine{556     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SLIGHT\_FIX\_HALOCLINES"}, fix\_haloclines, \&}
\DoxyCodeLine{557                  \textcolor{stringliteral}{"If true, identify regions above the reference pressure "}//\&}
\DoxyCodeLine{558                  \textcolor{stringliteral}{"where the reference pressure systematically underestimates "}//\&}
\DoxyCodeLine{559                  \textcolor{stringliteral}{"the stratification and use this in the definition of the "}//\&}
\DoxyCodeLine{560                  \textcolor{stringliteral}{"interior with the SLight coordinate."}, default=.false.)}
\DoxyCodeLine{561 }
\DoxyCodeLine{562     \textcolor{keyword}{call }set\_regrid\_params(cs, dz\_min\_surface=dz\_fixed\_sfc, \&}
\DoxyCodeLine{563                 nz\_fixed\_surface=nz\_fixed\_sfc, rho\_ml\_avg\_depth=rho\_avg\_depth, \&}
\DoxyCodeLine{564                 nlay\_ml\_to\_interior=nlay\_sfc\_int, fix\_haloclines=fix\_haloclines)}
\DoxyCodeLine{565     \textcolor{keywordflow}{if} (fix\_haloclines) \textcolor{keywordflow}{then}}
\DoxyCodeLine{566       \textcolor{comment}{! Set additional parameters related to SLIGHT\_FIX\_HALOCLINES.}}
\DoxyCodeLine{567       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HALOCLINE\_FILTER\_LENGTH"}, filt\_len, \&}
\DoxyCodeLine{568                  \textcolor{stringliteral}{"A length scale over which to smooth the temperature and "}//\&}
\DoxyCodeLine{569                  \textcolor{stringliteral}{"salinity before identifying erroneously unstable haloclines."}, \&}
\DoxyCodeLine{570                  units=\textcolor{stringliteral}{"m"}, default=2.0, scale=gv\%m\_to\_H)}
\DoxyCodeLine{571       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HALOCLINE\_STRAT\_TOL"}, strat\_tol, \&}
\DoxyCodeLine{572                  \textcolor{stringliteral}{"A tolerance for the ratio of the stratification of the "}//\&}
\DoxyCodeLine{573                  \textcolor{stringliteral}{"apparent coordinate stratification to the actual value "}//\&}
\DoxyCodeLine{574                  \textcolor{stringliteral}{"that is used to identify erroneously unstable haloclines. "}//\&}
\DoxyCodeLine{575                  \textcolor{stringliteral}{"This ratio is 1 when they are equal, and sensible values "}//\&}
\DoxyCodeLine{576                  \textcolor{stringliteral}{"are between 0 and 0.5."}, units=\textcolor{stringliteral}{"nondimensional"}, default=0.2)}
\DoxyCodeLine{577       \textcolor{keyword}{call }set\_regrid\_params(cs, halocline\_filt\_len=filt\_len, \&}
\DoxyCodeLine{578                              halocline\_strat\_tol=strat\_tol)}
\DoxyCodeLine{579 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{580 }
\DoxyCodeLine{581 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{582 }
\DoxyCodeLine{583   \textcolor{keywordflow}{if} (coordinatemode(coord\_mode) == regridding\_adaptive) \textcolor{keywordflow}{then}}
\DoxyCodeLine{584     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_TIME\_RATIO"}, adapttimeratio, \&}
\DoxyCodeLine{585                  \textcolor{stringliteral}{"Ratio of ALE timestep to grid timescale."}, units=\textcolor{stringliteral}{"nondim"}, default=1.0e-\/1)}
\DoxyCodeLine{586     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_ZOOM\_DEPTH"}, adaptzoom, \&}
\DoxyCodeLine{587                  \textcolor{stringliteral}{"Depth of near-\/surface zooming region."}, units=\textcolor{stringliteral}{"m"}, default=200.0, scale=gv\%m\_to\_H)}
\DoxyCodeLine{588     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_ZOOM\_COEFF"}, adaptzoomcoeff, \&}
\DoxyCodeLine{589                  \textcolor{stringliteral}{"Coefficient of near-\/surface zooming diffusivity."}, units=\textcolor{stringliteral}{"nondim"}, default=0.2)}
\DoxyCodeLine{590     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_BUOY\_COEFF"}, adaptbuoycoeff, \&}
\DoxyCodeLine{591                  \textcolor{stringliteral}{"Coefficient of buoyancy diffusivity."}, units=\textcolor{stringliteral}{"nondim"}, default=0.8)}
\DoxyCodeLine{592     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_ALPHA"}, adaptalpha, \&}
\DoxyCodeLine{593                  \textcolor{stringliteral}{"Scaling on optimization tendency."}, units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{594     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_DO\_MIN\_DEPTH"}, tmplogical, \&}
\DoxyCodeLine{595                  \textcolor{stringliteral}{"If true, make a HyCOM-\/like mixed layer by preventing interfaces "}//\&}
\DoxyCodeLine{596                  \textcolor{stringliteral}{"from being shallower than the depths specified by the regridding coordinate."}, \&}
\DoxyCodeLine{597                  default=.false.)}
\DoxyCodeLine{598     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADAPT\_DRHO0"}, adaptdrho0, \&}
\DoxyCodeLine{599                  \textcolor{stringliteral}{"Reference density difference for stratification-\/dependent diffusion."}, \&}
\DoxyCodeLine{600                  units=\textcolor{stringliteral}{"kg m-\/3"}, default=0.5, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{601 }
\DoxyCodeLine{602     \textcolor{keyword}{call }set\_regrid\_params(cs, adapttimeratio=adapttimeratio, adaptzoom=adaptzoom, \&}
\DoxyCodeLine{603          adaptzoomcoeff=adaptzoomcoeff, adaptbuoycoeff=adaptbuoycoeff, adaptalpha=adaptalpha, \&}
\DoxyCodeLine{604          adaptdomin=tmplogical, adaptdrho0=adaptdrho0)}
\DoxyCodeLine{605 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{606 }
\DoxyCodeLine{607   \textcolor{keywordflow}{if} (main\_parameters .and. coord\_is\_state\_dependent) \textcolor{keywordflow}{then}}
\DoxyCodeLine{608     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAXIMUM\_INT\_DEPTH\_CONFIG"}, string, \&}
\DoxyCodeLine{609                  \textcolor{stringliteral}{"Determines how to specify the maximum interface depths.\(\backslash\)n"}//\&}
\DoxyCodeLine{610                  \textcolor{stringliteral}{"Valid options are:\(\backslash\)n"}//\&}
\DoxyCodeLine{611                  \textcolor{stringliteral}{" NONE        -\/ there are no maximum interface depths\(\backslash\)n"}//\&}
\DoxyCodeLine{612                  \textcolor{stringliteral}{" PARAM       -\/ use the vector-\/parameter MAXIMUM\_INTERFACE\_DEPTHS\(\backslash\)n"}//\&}
\DoxyCodeLine{613                  \textcolor{stringliteral}{" FILE:string -\/ read from a file. The string specifies\(\backslash\)n"}//\&}
\DoxyCodeLine{614                  \textcolor{stringliteral}{"               the filename and variable name, separated\(\backslash\)n"}//\&}
\DoxyCodeLine{615                  \textcolor{stringliteral}{"               by a comma or space, e.g. FILE:lev.nc,Z\(\backslash\)n"}//\&}
\DoxyCodeLine{616                  \textcolor{stringliteral}{" FNC1:string -\/ FNC1:dz\_min,H\_total,power,precision"},\&}
\DoxyCodeLine{617                  default=\textcolor{stringliteral}{'NONE'})}
\DoxyCodeLine{618     message = \textcolor{stringliteral}{"The list of maximum depths for each interface."}}
\DoxyCodeLine{619     \textcolor{keyword}{allocate}(z\_max(ke+1))}
\DoxyCodeLine{620     \textcolor{keyword}{allocate}(dz\_max(ke))}
\DoxyCodeLine{621     \textcolor{keywordflow}{if} ( trim(string) == \textcolor{stringliteral}{"NONE"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{622       \textcolor{comment}{! Do nothing.}}
\DoxyCodeLine{623     \textcolor{keywordflow}{elseif} ( trim(string) ==  \textcolor{stringliteral}{"PARAM"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{624       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAXIMUM\_INTERFACE\_DEPTHS"}, z\_max, \&}
\DoxyCodeLine{625                    trim(message), units=\textcolor{stringliteral}{"m"}, scale=gv\%m\_to\_H, fail\_if\_missing=.true.)}
\DoxyCodeLine{626       \textcolor{keyword}{call }set\_regrid\_max\_depths(cs, z\_max)}
\DoxyCodeLine{627     \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'FILE:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{628       \textcolor{keywordflow}{if} (string(6:6)==\textcolor{stringliteral}{'.'} .or. string(6:6)==\textcolor{stringliteral}{'/'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{629         \textcolor{comment}{! If we specified "FILE:./xyz" or "FILE:/xyz" then we have a relative or absolute path}}
\DoxyCodeLine{630         filename = trim( extractword(trim(string(6:80)), 1) )}
\DoxyCodeLine{631       \textcolor{keywordflow}{else}}
\DoxyCodeLine{632         \textcolor{comment}{! Otherwise assume we should look for the file in INPUTDIR}}
\DoxyCodeLine{633         filename = trim(inputdir) // trim( extractword(trim(string(6:80)), 1) )}
\DoxyCodeLine{634 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{635       \textcolor{keywordflow}{if} (.not. file\_exists(filename)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{636         \textcolor{stringliteral}{"Specified file not found: Looking for '"}//trim(filename)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{637 }
\DoxyCodeLine{638       do\_sum = .false.}
\DoxyCodeLine{639       varname = trim( extractword(trim(string(6:)), 2) )}
\DoxyCodeLine{640       \textcolor{keywordflow}{if} (.not. field\_exists(filename,varname)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{641         \textcolor{stringliteral}{"Specified field not found: Looking for '"}//trim(varname)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{642       \textcolor{keywordflow}{if} (len\_trim(varname)==0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{643         \textcolor{keywordflow}{if} (field\_exists(filename,\textcolor{stringliteral}{'z\_max'})) then; varname = \textcolor{stringliteral}{'z\_max'}}
\DoxyCodeLine{644         \textcolor{keywordflow}{elseif} (field\_exists(filename,\textcolor{stringliteral}{'dz'})) then; varname = \textcolor{stringliteral}{'dz'} ; do\_sum = .true.}
\DoxyCodeLine{645         \textcolor{keywordflow}{elseif} (field\_exists(filename,\textcolor{stringliteral}{'dz\_max'})) then; varname = \textcolor{stringliteral}{'dz\_max'} ; do\_sum = .true.}
\DoxyCodeLine{646         \textcolor{keywordflow}{else} ; \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{647           \textcolor{stringliteral}{"MAXIMUM\_INT\_DEPTHS variable not specified and none could be guessed."})}
\DoxyCodeLine{648 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{649 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{650       \textcolor{keywordflow}{if} (do\_sum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{651         \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), dz\_max)}
\DoxyCodeLine{652         z\_max(1) = 0.0 ; \textcolor{keywordflow}{do} k=1,ke ; z\_max(k+1) = z\_max(k) + dz\_max(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{653       \textcolor{keywordflow}{else}}
\DoxyCodeLine{654         \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), z\_max)}
\DoxyCodeLine{655 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{656       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!MAXIMUM\_INT\_DEPTHS"}, z\_max, \&}
\DoxyCodeLine{657                  trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{658       \textcolor{keyword}{call }set\_regrid\_max\_depths(cs, z\_max, gv\%m\_to\_H)}
\DoxyCodeLine{659     \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'FNC1:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{660       \textcolor{keyword}{call }dz\_function1( trim(string(6:)), dz\_max )}
\DoxyCodeLine{661       \textcolor{keywordflow}{if} ((coordinatemode(coord\_mode) == regridding\_slight) .and. \&}
\DoxyCodeLine{662           (dz\_fixed\_sfc > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{663         \textcolor{keywordflow}{do} k=1,nz\_fixed\_sfc ; dz\_max(k) = dz\_fixed\_sfc ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{664 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{665       z\_max(1) = 0.0 ; \textcolor{keywordflow}{do} k=1,ke ; z\_max(k+1) = z\_max(k) + dz\_max(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{666       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!MAXIMUM\_INT\_DEPTHS"}, z\_max, \&}
\DoxyCodeLine{667                  trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{668       \textcolor{keyword}{call }set\_regrid\_max\_depths(cs, z\_max, gv\%m\_to\_H)}
\DoxyCodeLine{669     \textcolor{keywordflow}{else}}
\DoxyCodeLine{670       \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{671         \textcolor{stringliteral}{"Unrecognized MAXIMUM\_INT\_DEPTH\_CONFIG "}//trim(string))}
\DoxyCodeLine{672 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{673     \textcolor{keyword}{deallocate}(z\_max)}
\DoxyCodeLine{674     \textcolor{keyword}{deallocate}(dz\_max)}
\DoxyCodeLine{675 }
\DoxyCodeLine{676     \textcolor{comment}{! Optionally specify maximum thicknesses for each layer, enforced by moving}}
\DoxyCodeLine{677     \textcolor{comment}{! the interface below a layer downward.}}
\DoxyCodeLine{678     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAX\_LAYER\_THICKNESS\_CONFIG"}, string, \&}
\DoxyCodeLine{679                    \textcolor{stringliteral}{"Determines how to specify the maximum layer thicknesses.\(\backslash\)n"}//\&}
\DoxyCodeLine{680                    \textcolor{stringliteral}{"Valid options are:\(\backslash\)n"}//\&}
\DoxyCodeLine{681                    \textcolor{stringliteral}{" NONE        -\/ there are no maximum layer thicknesses\(\backslash\)n"}//\&}
\DoxyCodeLine{682                    \textcolor{stringliteral}{" PARAM       -\/ use the vector-\/parameter MAX\_LAYER\_THICKNESS\(\backslash\)n"}//\&}
\DoxyCodeLine{683                    \textcolor{stringliteral}{" FILE:string -\/ read from a file. The string specifies\(\backslash\)n"}//\&}
\DoxyCodeLine{684                    \textcolor{stringliteral}{"               the filename and variable name, separated\(\backslash\)n"}//\&}
\DoxyCodeLine{685                    \textcolor{stringliteral}{"               by a comma or space, e.g. FILE:lev.nc,Z\(\backslash\)n"}//\&}
\DoxyCodeLine{686                    \textcolor{stringliteral}{" FNC1:string -\/ FNC1:dz\_min,H\_total,power,precision"},\&}
\DoxyCodeLine{687                    default=\textcolor{stringliteral}{'NONE'})}
\DoxyCodeLine{688     message = \textcolor{stringliteral}{"The list of maximum thickness for each layer."}}
\DoxyCodeLine{689     \textcolor{keyword}{allocate}(h\_max(ke))}
\DoxyCodeLine{690     \textcolor{keywordflow}{if} ( trim(string) == \textcolor{stringliteral}{"NONE"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{691       \textcolor{comment}{! Do nothing.}}
\DoxyCodeLine{692     \textcolor{keywordflow}{elseif} ( trim(string) ==  \textcolor{stringliteral}{"PARAM"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{693       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAX\_LAYER\_THICKNESS"}, h\_max, \&}
\DoxyCodeLine{694                    trim(message), units=\textcolor{stringliteral}{"m"}, fail\_if\_missing=.true., scale=gv\%m\_to\_H)}
\DoxyCodeLine{695       \textcolor{keyword}{call }set\_regrid\_max\_thickness(cs, h\_max)}
\DoxyCodeLine{696     \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'FILE:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{697       \textcolor{keywordflow}{if} (string(6:6)==\textcolor{stringliteral}{'.'} .or. string(6:6)==\textcolor{stringliteral}{'/'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{698         \textcolor{comment}{! If we specified "FILE:./xyz" or "FILE:/xyz" then we have a relative or absolute path}}
\DoxyCodeLine{699         filename = trim( extractword(trim(string(6:80)), 1) )}
\DoxyCodeLine{700       \textcolor{keywordflow}{else}}
\DoxyCodeLine{701         \textcolor{comment}{! Otherwise assume we should look for the file in INPUTDIR}}
\DoxyCodeLine{702         filename = trim(inputdir) // trim( extractword(trim(string(6:80)), 1) )}
\DoxyCodeLine{703 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{704       \textcolor{keywordflow}{if} (.not. file\_exists(filename)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{705         \textcolor{stringliteral}{"Specified file not found: Looking for '"}//trim(filename)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{706 }
\DoxyCodeLine{707       varname = trim( extractword(trim(string(6:)), 2) )}
\DoxyCodeLine{708       \textcolor{keywordflow}{if} (.not. field\_exists(filename,varname)) \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{709         \textcolor{stringliteral}{"Specified field not found: Looking for '"}//trim(varname)//\textcolor{stringliteral}{"' ("}//trim(string)//\textcolor{stringliteral}{")"})}
\DoxyCodeLine{710       \textcolor{keywordflow}{if} (len\_trim(varname)==0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{711         \textcolor{keywordflow}{if} (field\_exists(filename,\textcolor{stringliteral}{'h\_max'})) then; varname = \textcolor{stringliteral}{'h\_max'}}
\DoxyCodeLine{712         \textcolor{keywordflow}{elseif} (field\_exists(filename,\textcolor{stringliteral}{'dz\_max'})) then; varname = \textcolor{stringliteral}{'dz\_max'}}
\DoxyCodeLine{713         \textcolor{keywordflow}{else} ; \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{714           \textcolor{stringliteral}{"MAXIMUM\_INT\_DEPTHS variable not specified and none could be guessed."})}
\DoxyCodeLine{715 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{716 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{717       \textcolor{keyword}{call }mom\_read\_data(trim(filename), trim(varname), h\_max)}
\DoxyCodeLine{718       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!MAX\_LAYER\_THICKNESS"}, h\_max, \&}
\DoxyCodeLine{719                  trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{720       \textcolor{keyword}{call }set\_regrid\_max\_thickness(cs, h\_max, gv\%m\_to\_H)}
\DoxyCodeLine{721     \textcolor{keywordflow}{elseif} (index(trim(string),\textcolor{stringliteral}{'FNC1:'})==1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{722       \textcolor{keyword}{call }dz\_function1( trim(string(6:)), h\_max )}
\DoxyCodeLine{723       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!MAX\_LAYER\_THICKNESS"}, h\_max, \&}
\DoxyCodeLine{724                  trim(message), units=coordinateunits(coord\_mode))}
\DoxyCodeLine{725       \textcolor{keyword}{call }set\_regrid\_max\_thickness(cs, h\_max, gv\%m\_to\_H)}
\DoxyCodeLine{726     \textcolor{keywordflow}{else}}
\DoxyCodeLine{727       \textcolor{keyword}{call }mom\_error(fatal,trim(mdl)//\textcolor{stringliteral}{", initialize\_regridding: "}// \&}
\DoxyCodeLine{728         \textcolor{stringliteral}{"Unrecognized MAX\_LAYER\_THICKNESS\_CONFIG "}//trim(string))}
\DoxyCodeLine{729 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{730     \textcolor{keyword}{deallocate}(h\_max)}
\DoxyCodeLine{731 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{732 }
\DoxyCodeLine{733   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(dz)) \textcolor{keyword}{deallocate}(dz)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ab354fe3423a39fef6f2b66f409b1682c}\label{namespacemom__regridding_ab354fe3423a39fef6f2b66f409b1682c}} 
\index{mom\_regridding@{mom\_regridding}!regridding\_main@{regridding\_main}}
\index{regridding\_main@{regridding\_main}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{regridding\_main()}{regridding\_main()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::regridding\+\_\+main (\begin{DoxyParamCaption}\item[{type(remapping\+\_\+cs), intent(in)}]{remap\+CS,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,  gv \%ke), intent(inout)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, cs\%nk), intent(inout)}]{h\+\_\+new,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, cs\%nk+1), intent(inout)}]{dz\+Interface,  }\item[{real, dimension(\+:,\+:), optional, pointer}]{frac\+\_\+shelf\+\_\+h,  }\item[{logical, intent(in), optional}]{conv\+\_\+adjust }\end{DoxyParamCaption})}



Dispatching regridding routine for orchestrating regridding \& remapping. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em remapcs} & Remapping parameters and options \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Current 3D grid obtained after the last time step \\
\hline
\mbox{\texttt{ in,out}}  & {\em tv} & Thermodynamical variables (T, S, ...) \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+new} & New 3D grid consistent with target coordinate \\
\hline
\mbox{\texttt{ in,out}}  & {\em dzinterface} & The change in position of each interface \\
\hline
 & {\em frac\+\_\+shelf\+\_\+h} & Fractional ice shelf coverage \\
\hline
\mbox{\texttt{ in}}  & {\em conv\+\_\+adjust} & If true, do convective adjustment \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{813 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{814 \textcolor{comment}{! This routine takes care of (1) building a new grid and (2) remapping between}}
\DoxyCodeLine{815 \textcolor{comment}{! the old grid and the new grid. The creation of the new grid can be based}}
\DoxyCodeLine{816 \textcolor{comment}{! on z coordinates, target interface densities, sigma coordinates or any}}
\DoxyCodeLine{817 \textcolor{comment}{! arbitrary coordinate system.}}
\DoxyCodeLine{818 \textcolor{comment}{!   The MOM6 interface positions are always calculated from the bottom up by}}
\DoxyCodeLine{819 \textcolor{comment}{! accumulating the layer thicknesses starting at z=-\/G\%bathyT.  z increases}}
\DoxyCodeLine{820 \textcolor{comment}{! upwards (decreasing k-\/index).}}
\DoxyCodeLine{821 \textcolor{comment}{!   The new grid is defined by the change in position of those interfaces in z}}
\DoxyCodeLine{822 \textcolor{comment}{!       dzInterface = zNew -\/ zOld.}}
\DoxyCodeLine{823 \textcolor{comment}{!   Thus, if the regridding inflates the top layer, hNew(1) > hOld(1), then the}}
\DoxyCodeLine{824 \textcolor{comment}{! second interface moves downward, zNew(2) < zOld(2), and dzInterface(2) < 0.}}
\DoxyCodeLine{825 \textcolor{comment}{!       hNew(k) = hOld(k) -\/ dzInterface(k+1) + dzInterface(k)}}
\DoxyCodeLine{826 \textcolor{comment}{! IMPORTANT NOTE:}}
\DoxyCodeLine{827 \textcolor{comment}{!   This is the converse of the sign convention used in the remapping code!}}
\DoxyCodeLine{828 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{829 }
\DoxyCodeLine{830   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{831   \textcolor{keywordtype}{type}(remapping\_CS),                         \textcolor{keywordtype}{intent(in)}    :: remapCS\textcolor{comment}{ !< Remapping parameters and options}}
\DoxyCodeLine{832   \textcolor{keywordtype}{type}(regridding\_CS),                        \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{     !< Regridding control structure}}
\DoxyCodeLine{833   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< Ocean grid structure}}
\DoxyCodeLine{834   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}}
\DoxyCodeLine{835 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(GV))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Current 3D grid obtained after}}
\DoxyCodeLine{836 \textcolor{comment}{                                                                      !! the last time step}}
\DoxyCodeLine{837   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                      \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{     !< Thermodynamical variables (T, S, ...)}}
\DoxyCodeLine{838 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), CS\%nk)},    \textcolor{keywordtype}{intent(inout)} :: h\_new\textcolor{comment}{  !< New 3D grid consistent with target coordinate}}
\DoxyCodeLine{839 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), CS\%nk+1)},  \textcolor{keywordtype}{intent(inout)} :: dzInterface\textcolor{comment}{ !< The change in position of each interface}}
\DoxyCodeLine{840 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: frac\_shelf\_h\textcolor{comment}{ !< Fractional ice shelf coverage}}
\DoxyCodeLine{841   \textcolor{keywordtype}{logical},                          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: conv\_adjust\textcolor{comment}{ !< If true, do convective adjustment}}
\DoxyCodeLine{842   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{843 \textcolor{keywordtype}{  real} :: trickGnuCompiler}
\DoxyCodeLine{844   \textcolor{keywordtype}{logical} :: use\_ice\_shelf}
\DoxyCodeLine{845   \textcolor{keywordtype}{logical} :: do\_convective\_adjustment}
\DoxyCodeLine{846 }
\DoxyCodeLine{847   do\_convective\_adjustment = .true.}
\DoxyCodeLine{848   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(conv\_adjust)) do\_convective\_adjustment = conv\_adjust}
\DoxyCodeLine{849 }
\DoxyCodeLine{850   use\_ice\_shelf = .false.}
\DoxyCodeLine{851   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(frac\_shelf\_h)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{852     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(frac\_shelf\_h)) use\_ice\_shelf = .true.}
\DoxyCodeLine{853 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{854 }
\DoxyCodeLine{855   \textcolor{keywordflow}{select case} ( cs\%regridding\_scheme )}
\DoxyCodeLine{856 }
\DoxyCodeLine{857     \textcolor{keywordflow}{case} ( regridding\_zstar )}
\DoxyCodeLine{858       \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{859         \textcolor{keyword}{call }build\_zstar\_grid( cs, g, gv, h, dzinterface, frac\_shelf\_h )}
\DoxyCodeLine{860       \textcolor{keywordflow}{else}}
\DoxyCodeLine{861         \textcolor{keyword}{call }build\_zstar\_grid( cs, g, gv, h, dzinterface )}
\DoxyCodeLine{862 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{863       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{864 }
\DoxyCodeLine{865     \textcolor{keywordflow}{case} ( regridding\_sigma\_shelf\_zstar)}
\DoxyCodeLine{866       \textcolor{keyword}{call }build\_zstar\_grid( cs, g, gv, h, dzinterface )}
\DoxyCodeLine{867       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{868 }
\DoxyCodeLine{869     \textcolor{keywordflow}{case} ( regridding\_sigma )}
\DoxyCodeLine{870       \textcolor{keyword}{call }build\_sigma\_grid( cs, g, gv, h, dzinterface )}
\DoxyCodeLine{871       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{872 }
\DoxyCodeLine{873     \textcolor{keywordflow}{case} ( regridding\_rho )}
\DoxyCodeLine{874       \textcolor{keywordflow}{if} (do\_convective\_adjustment) \textcolor{keyword}{call }convective\_adjustment(g, gv, h, tv)}
\DoxyCodeLine{875       \textcolor{keyword}{call }build\_rho\_grid( g, gv, g\%US, h, tv, dzinterface, remapcs, cs )}
\DoxyCodeLine{876       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{877 }
\DoxyCodeLine{878     \textcolor{keywordflow}{case} ( regridding\_arbitrary )}
\DoxyCodeLine{879       \textcolor{keyword}{call }build\_grid\_arbitrary( g, gv, h, dzinterface, trickgnucompiler, cs )}
\DoxyCodeLine{880       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{881 }
\DoxyCodeLine{882     \textcolor{keywordflow}{case} ( regridding\_hycom1 )}
\DoxyCodeLine{883       \textcolor{keyword}{call }build\_grid\_hycom1( g, gv, g\%US, h, tv, h\_new, dzinterface, cs )}
\DoxyCodeLine{884 }
\DoxyCodeLine{885     \textcolor{keywordflow}{case} ( regridding\_slight )}
\DoxyCodeLine{886       \textcolor{keyword}{call }build\_grid\_slight( g, gv, g\%US, h, tv, dzinterface, cs )}
\DoxyCodeLine{887       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{888 }
\DoxyCodeLine{889     \textcolor{keywordflow}{case} ( regridding\_adaptive )}
\DoxyCodeLine{890       \textcolor{keyword}{call }build\_grid\_adaptive(g, gv, g\%US, h, tv, dzinterface, remapcs, cs)}
\DoxyCodeLine{891       \textcolor{keyword}{call }calc\_h\_new\_by\_dz(cs, g, gv, h, dzinterface, h\_new)}
\DoxyCodeLine{892 }
\DoxyCodeLine{893 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{894       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, regridding\_main: '}//\&}
\DoxyCodeLine{895                      \textcolor{stringliteral}{'Unknown regridding scheme selected!'})}
\DoxyCodeLine{896 }
\DoxyCodeLine{897 \textcolor{keywordflow}{  end select} \textcolor{comment}{! type of grid}}
\DoxyCodeLine{898 }
\DoxyCodeLine{899 \textcolor{preprocessor}{\#ifdef \_\_DO\_SAFETY\_CHECKS\_\_}}
\DoxyCodeLine{900 \textcolor{preprocessor}{}  \textcolor{keyword}{call }check\_remapping\_grid(g, gv, h, dzinterface,\textcolor{stringliteral}{'in regridding\_main'})}
\DoxyCodeLine{901 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{902 \textcolor{preprocessor}{}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a64758b08fbd1d2a98d4d7de593fb49be}\label{namespacemom__regridding_a64758b08fbd1d2a98d4d7de593fb49be}} 
\index{mom\_regridding@{mom\_regridding}!rho\_function1@{rho\_function1}}
\index{rho\_function1@{rho\_function1}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{rho\_function1()}{rho\_function1()}}
{\footnotesize\ttfamily integer function mom\+\_\+regridding\+::rho\+\_\+function1 (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{string,  }\item[{real, dimension(\+:), intent(inout), allocatable}]{rho\+\_\+target }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parses a string and generates a rho\+\_\+target(\+:) profile with refined resolution downward and returns the number of levels. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em string} & String with list of parameters in form dz\+\_\+min, H\+\_\+total, power, precision \\
\hline
\mbox{\texttt{ in,out}}  & {\em rho\+\_\+target} & Profile of interface densities \mbox{[}kg m-\/3\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2447   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: string\textcolor{comment}{ !< String with list of parameters in form}}
\DoxyCodeLine{2448 \textcolor{comment}{                                              !! dz\_min, H\_total, power, precision}}
\DoxyCodeLine{2449 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{intent(inout)} :: rho\_target\textcolor{comment}{ !< Profile of interface densities [kg m-\/3]}}
\DoxyCodeLine{2450   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2451   \textcolor{keywordtype}{integer} :: nki, k, nk}
\DoxyCodeLine{2452 \textcolor{keywordtype}{  real}    :: ddx, dx, rho\_1, rho\_2, rho\_3, drho, rho\_4, drho\_min}
\DoxyCodeLine{2453 }
\DoxyCodeLine{2454   \textcolor{keyword}{read}( string, *) nk, rho\_1, rho\_2, rho\_3, drho, rho\_4, drho\_min}
\DoxyCodeLine{2455   \textcolor{keyword}{allocate}(rho\_target(nk+1))}
\DoxyCodeLine{2456   nki = nk + 1 -\/ 4 \textcolor{comment}{! Number of interfaces minus 4 specified values}}
\DoxyCodeLine{2457   rho\_target(1) = rho\_1}
\DoxyCodeLine{2458   rho\_target(2) = rho\_2}
\DoxyCodeLine{2459   dx = 0.}
\DoxyCodeLine{2460   \textcolor{keywordflow}{do} k = 0, nki}
\DoxyCodeLine{2461     ddx = max( drho\_min, real(nki-\/k)/real(nki*nki) )}
\DoxyCodeLine{2462     dx = dx + ddx}
\DoxyCodeLine{2463     rho\_target(3+k) = rho\_3 + (2. * drho) * dx}
\DoxyCodeLine{2464 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2465   rho\_target(nki+4) = rho\_4}
\DoxyCodeLine{2466 }
\DoxyCodeLine{2467   rho\_function1 = nk}
\DoxyCodeLine{2468 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_aac547ec199090852d539c7aefc44dfa7}\label{namespacemom__regridding_aac547ec199090852d539c7aefc44dfa7}} 
\index{mom\_regridding@{mom\_regridding}!set\_regrid\_max\_depths@{set\_regrid\_max\_depths}}
\index{set\_regrid\_max\_depths@{set\_regrid\_max\_depths}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{set\_regrid\_max\_depths()}{set\_regrid\_max\_depths()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::set\+\_\+regrid\+\_\+max\+\_\+depths (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{real, dimension(cs\%nk+1), intent(in)}]{max\+\_\+depths,  }\item[{real, intent(in), optional}]{units\+\_\+to\+\_\+H }\end{DoxyParamCaption})}



Set maximum interface depths based on a vector of input values. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+depths} & Maximum interface depths, in arbitrary units \\
\hline
\mbox{\texttt{ in}}  & {\em units\+\_\+to\+\_\+h} & A conversion factor for max\+\_\+depths into H units \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2057   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2058 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \textcolor{keywordtype}{intent(in)}    :: max\_depths\textcolor{comment}{ !< Maximum interface depths, in arbitrary units}}
\DoxyCodeLine{2059 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},           \textcolor{keywordtype}{intent(in)}    :: units\_to\_H\textcolor{comment}{ !< A conversion factor for max\_depths into H units}}
\DoxyCodeLine{2060   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2061 \textcolor{keywordtype}{  real} :: val\_to\_H}
\DoxyCodeLine{2062   \textcolor{keywordtype}{integer} :: K}
\DoxyCodeLine{2063 }
\DoxyCodeLine{2064   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{allocated}(cs\%max\_interface\_depths)) \textcolor{keyword}{allocate}(cs\%max\_interface\_depths(1:cs\%nk+1))}
\DoxyCodeLine{2065 }
\DoxyCodeLine{2066   val\_to\_h = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(units\_to\_h)) val\_to\_h = units\_to\_h}
\DoxyCodeLine{2067   \textcolor{keywordflow}{if} (max\_depths(cs\%nk+1) < max\_depths(1)) val\_to\_h = -\/1.0*val\_to\_h}
\DoxyCodeLine{2068 }
\DoxyCodeLine{2069   \textcolor{comment}{! Check for sign reversals in the depths.}}
\DoxyCodeLine{2070   \textcolor{keywordflow}{if} (max\_depths(cs\%nk+1) < max\_depths(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2071     \textcolor{keywordflow}{do} k=1,cs\%nk ; \textcolor{keywordflow}{if} (max\_depths(k+1) > max\_depths(k)) \&}
\DoxyCodeLine{2072       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Unordered list of maximum depths sent to set\_regrid\_max\_depths!"})}
\DoxyCodeLine{2073 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2074   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2075     \textcolor{keywordflow}{do} k=1,cs\%nk ; \textcolor{keywordflow}{if} (max\_depths(k+1) < max\_depths(k)) \&}
\DoxyCodeLine{2076       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Unordered list of maximum depths sent to set\_regrid\_max\_depths."})}
\DoxyCodeLine{2077 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2078 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2079 }
\DoxyCodeLine{2080   \textcolor{keywordflow}{do} k=1,cs\%nk+1}
\DoxyCodeLine{2081     cs\%max\_interface\_depths(k) = val\_to\_h * max\_depths(k)}
\DoxyCodeLine{2082 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2083 }
\DoxyCodeLine{2084   \textcolor{comment}{! set max depths for coordinate}}
\DoxyCodeLine{2085   \textcolor{keywordflow}{select case} (cs\%regridding\_scheme)}
\DoxyCodeLine{2086   \textcolor{keywordflow}{case} (regridding\_hycom1)}
\DoxyCodeLine{2087     \textcolor{keyword}{call }set\_hycom\_params(cs\%hycom\_CS, max\_interface\_depths=cs\%max\_interface\_depths)}
\DoxyCodeLine{2088   \textcolor{keywordflow}{case} (regridding\_slight)}
\DoxyCodeLine{2089     \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, max\_interface\_depths=cs\%max\_interface\_depths)}
\DoxyCodeLine{2090 \textcolor{keywordflow}{  end select}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ae91ca3f1376b3c72940268b5d9f87bb4}\label{namespacemom__regridding_ae91ca3f1376b3c72940268b5d9f87bb4}} 
\index{mom\_regridding@{mom\_regridding}!set\_regrid\_max\_thickness@{set\_regrid\_max\_thickness}}
\index{set\_regrid\_max\_thickness@{set\_regrid\_max\_thickness}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{set\_regrid\_max\_thickness()}{set\_regrid\_max\_thickness()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::set\+\_\+regrid\+\_\+max\+\_\+thickness (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{real, dimension(cs\%nk+1), intent(in)}]{max\+\_\+h,  }\item[{real, intent(in), optional}]{units\+\_\+to\+\_\+H }\end{DoxyParamCaption})}



Set maximum layer thicknesses based on a vector of input values. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+h} & Maximum interface depths, in arbitrary units \\
\hline
\mbox{\texttt{ in}}  & {\em units\+\_\+to\+\_\+h} & A conversion factor for max\+\_\+h into H units \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2095   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2096 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \textcolor{keywordtype}{intent(in)}    :: max\_h\textcolor{comment}{ !< Maximum interface depths, in arbitrary units}}
\DoxyCodeLine{2097 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},           \textcolor{keywordtype}{intent(in)}    :: units\_to\_H\textcolor{comment}{ !< A conversion factor for max\_h into H units}}
\DoxyCodeLine{2098   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2099 \textcolor{keywordtype}{  real} :: val\_to\_H}
\DoxyCodeLine{2100   \textcolor{keywordtype}{integer} :: K}
\DoxyCodeLine{2101 }
\DoxyCodeLine{2102   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{allocated}(cs\%max\_layer\_thickness)) \textcolor{keyword}{allocate}(cs\%max\_layer\_thickness(1:cs\%nk))}
\DoxyCodeLine{2103 }
\DoxyCodeLine{2104   val\_to\_h = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}( units\_to\_h)) val\_to\_h = units\_to\_h}
\DoxyCodeLine{2105 }
\DoxyCodeLine{2106   \textcolor{keywordflow}{do} k=1,cs\%nk}
\DoxyCodeLine{2107     cs\%max\_layer\_thickness(k) = val\_to\_h * max\_h(k)}
\DoxyCodeLine{2108 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2109 }
\DoxyCodeLine{2110   \textcolor{comment}{! set max thickness for coordinate}}
\DoxyCodeLine{2111   \textcolor{keywordflow}{select case} (cs\%regridding\_scheme)}
\DoxyCodeLine{2112   \textcolor{keywordflow}{case} (regridding\_hycom1)}
\DoxyCodeLine{2113     \textcolor{keyword}{call }set\_hycom\_params(cs\%hycom\_CS, max\_layer\_thickness=cs\%max\_layer\_thickness)}
\DoxyCodeLine{2114   \textcolor{keywordflow}{case} (regridding\_slight)}
\DoxyCodeLine{2115     \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, max\_layer\_thickness=cs\%max\_layer\_thickness)}
\DoxyCodeLine{2116 \textcolor{keywordflow}{  end select}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a88398318fb996137b3f0d79b7fc8c4e9}\label{namespacemom__regridding_a88398318fb996137b3f0d79b7fc8c4e9}} 
\index{mom\_regridding@{mom\_regridding}!set\_regrid\_params@{set\_regrid\_params}}
\index{set\_regrid\_params@{set\_regrid\_params}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{set\_regrid\_params()}{set\_regrid\_params()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::set\+\_\+regrid\+\_\+params (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{logical, intent(in), optional}]{boundary\+\_\+extrapolation,  }\item[{real, intent(in), optional}]{min\+\_\+thickness,  }\item[{real, intent(in), optional}]{old\+\_\+grid\+\_\+weight,  }\item[{character(len=$\ast$), intent(in), optional}]{interp\+\_\+scheme,  }\item[{real, intent(in), optional}]{depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+shallow,  }\item[{real, intent(in), optional}]{depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+deep,  }\item[{real, intent(in), optional}]{compress\+\_\+fraction,  }\item[{real, intent(in), optional}]{ref\+\_\+pressure,  }\item[{real, intent(in), optional}]{dz\+\_\+min\+\_\+surface,  }\item[{integer, intent(in), optional}]{nz\+\_\+fixed\+\_\+surface,  }\item[{real, intent(in), optional}]{Rho\+\_\+\+M\+L\+\_\+avg\+\_\+depth,  }\item[{real, intent(in), optional}]{nlay\+\_\+\+M\+L\+\_\+to\+\_\+interior,  }\item[{logical, intent(in), optional}]{fix\+\_\+haloclines,  }\item[{real, intent(in), optional}]{halocline\+\_\+filt\+\_\+len,  }\item[{real, intent(in), optional}]{halocline\+\_\+strat\+\_\+tol,  }\item[{logical, intent(in), optional}]{integrate\+\_\+downward\+\_\+for\+\_\+e,  }\item[{logical, intent(in), optional}]{remap\+\_\+answers\+\_\+2018,  }\item[{real, intent(in), optional}]{adapt\+Time\+Ratio,  }\item[{real, intent(in), optional}]{adapt\+Zoom,  }\item[{real, intent(in), optional}]{adapt\+Zoom\+Coeff,  }\item[{real, intent(in), optional}]{adapt\+Buoy\+Coeff,  }\item[{real, intent(in), optional}]{adapt\+Alpha,  }\item[{logical, intent(in), optional}]{adapt\+Do\+Min,  }\item[{real, intent(in), optional}]{adapt\+Drho0 }\end{DoxyParamCaption})}



Can be used to set any of the parameters for M\+O\+M\+\_\+regridding. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em boundary\+\_\+extrapolation} & Extrapolate in boundary cells \\
\hline
\mbox{\texttt{ in}}  & {\em min\+\_\+thickness} & Minimum thickness allowed when building the new grid \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em old\+\_\+grid\+\_\+weight} & Weight given to old coordinate when time-\/filtering grid \\
\hline
\mbox{\texttt{ in}}  & {\em interp\+\_\+scheme} & Interpolation method for state-\/dependent coordinates \\
\hline
\mbox{\texttt{ in}}  & {\em depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+shallow} & Depth to start cubic \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+deep} & Depth to end cubic \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em compress\+\_\+fraction} & Fraction of compressibility to add to potential density \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ref\+\_\+pressure} & The reference pressure for density-\/dependent coordinates \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+min\+\_\+surface} & The fixed resolution in the topmost S\+Light\+\_\+nkml\+\_\+min layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nz\+\_\+fixed\+\_\+surface} & The number of fixed-\/thickness layers at the top of the model \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ml\+\_\+avg\+\_\+depth} & Averaging depth over which to determine mixed layer potential density \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nlay\+\_\+ml\+\_\+to\+\_\+interior} & Number of layers to offset the mixed layer density to find resolved stratification \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em fix\+\_\+haloclines} & Detect regions with much weaker stratification in the coordinate \\
\hline
\mbox{\texttt{ in}}  & {\em halocline\+\_\+filt\+\_\+len} & Length scale over which to filter T \& S when looking for spuriously unstable water mass profiles \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em halocline\+\_\+strat\+\_\+tol} & Value of the stratification ratio that defines a problematic halocline region. \\
\hline
\mbox{\texttt{ in}}  & {\em integrate\+\_\+downward\+\_\+for\+\_\+e} & If true, integrate for interface positions downward from the top. \\
\hline
\mbox{\texttt{ in}}  & {\em remap\+\_\+answers\+\_\+2018} & If true, use the order of arithmetic and expressions that recover the remapping answers from 2018. Otherwise use more robust but mathematically equivalent expressions. \\
\hline
\mbox{\texttt{ in}}  & {\em adapttimeratio} & Ratio of the A\+LE timestep to the grid timescale \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em adaptzoom} & Depth of near-\/surface zooming region \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em adaptzoomcoeff} & Coefficient of near-\/surface zooming diffusivity \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em adaptbuoycoeff} & Coefficient of buoyancy diffusivity \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em adaptalpha} & Scaling factor on optimization tendency \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em adaptdomin} & If true, make a Hy\+C\+O\+M-\/like mixed layer by preventing interfaces from being shallower than the depths specified by the regridding coordinate. \\
\hline
\mbox{\texttt{ in}}  & {\em adaptdrho0} & Reference density difference for stratification-\/dependent diffusion. \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2246   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2247   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: boundary\_extrapolation\textcolor{comment}{ !< Extrapolate in boundary cells}}
\DoxyCodeLine{2248 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: min\_thickness\textcolor{comment}{    !< Minimum thickness allowed when building the}}
\DoxyCodeLine{2249 \textcolor{comment}{                                                    !! new grid [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{2250 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: old\_grid\_weight\textcolor{comment}{  !< Weight given to old coordinate when time-\/filtering grid}}
\DoxyCodeLine{2251   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: interp\_scheme\textcolor{comment}{ !< Interpolation method for state-\/dependent coordinates}}
\DoxyCodeLine{2252 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: depth\_of\_time\_filter\_shallow\textcolor{comment}{ !< Depth to start cubic [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{2253 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: depth\_of\_time\_filter\_deep\textcolor{comment}{ !< Depth to end cubic [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{2254 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: compress\_fraction\textcolor{comment}{ !< Fraction of compressibility to add to potential density [nondim]}}
\DoxyCodeLine{2255 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: ref\_pressure\textcolor{comment}{     !< The reference pressure for density-\/dependent}}
\DoxyCodeLine{2256 \textcolor{comment}{                                                    !! coordinates [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{2257 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: dz\_min\_surface\textcolor{comment}{   !< The fixed resolution in the topmost}}
\DoxyCodeLine{2258 \textcolor{comment}{                                                    !! SLight\_nkml\_min layers [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{2259   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: nz\_fixed\_surface\textcolor{comment}{ !< The number of fixed-\/thickness layers at the top of the model}}
\DoxyCodeLine{2260 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: Rho\_ml\_avg\_depth\textcolor{comment}{ !< Averaging depth over which to determine mixed layer potential}}
\DoxyCodeLine{2261 \textcolor{comment}{                                                    !! density [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{2262 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: nlay\_ML\_to\_interior\textcolor{comment}{ !< Number of layers to offset the mixed layer density to find}}
\DoxyCodeLine{2263 \textcolor{comment}{                                                    !! resolved stratification [nondim]}}
\DoxyCodeLine{2264   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: fix\_haloclines\textcolor{comment}{   !< Detect regions with much weaker stratification in the coordinate}}
\DoxyCodeLine{2265 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: halocline\_filt\_len\textcolor{comment}{ !< Length scale over which to filter T \& S when looking for}}
\DoxyCodeLine{2266 \textcolor{comment}{                                                    !! spuriously unstable water mass profiles [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{2267 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: halocline\_strat\_tol\textcolor{comment}{ !< Value of the stratification ratio that defines a problematic}}
\DoxyCodeLine{2268 \textcolor{comment}{                                                    !! halocline region.}}
\DoxyCodeLine{2269   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: integrate\_downward\_for\_e\textcolor{comment}{ !< If true, integrate for interface positions downward}}
\DoxyCodeLine{2270 \textcolor{comment}{                                                    !! from the top.}}
\DoxyCodeLine{2271   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: remap\_answers\_2018\textcolor{comment}{ !< If true, use the order of arithmetic and expressions}}
\DoxyCodeLine{2272 \textcolor{comment}{                                                    !! that recover the remapping answers from 2018.  Otherwise}}
\DoxyCodeLine{2273 \textcolor{comment}{                                                    !! use more robust but mathematically equivalent expressions.}}
\DoxyCodeLine{2274 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptTimeRatio\textcolor{comment}{   !< Ratio of the ALE timestep to the grid timescale [nondim].}}
\DoxyCodeLine{2275 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptZoom\textcolor{comment}{        !< Depth of near-\/surface zooming region [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{2276 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptZoomCoeff\textcolor{comment}{   !< Coefficient of near-\/surface zooming diffusivity [nondim].}}
\DoxyCodeLine{2277 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptBuoyCoeff\textcolor{comment}{   !< Coefficient of buoyancy diffusivity [nondim].}}
\DoxyCodeLine{2278 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptAlpha\textcolor{comment}{       !< Scaling factor on optimization tendency [nondim].}}
\DoxyCodeLine{2279   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptDoMin\textcolor{comment}{       !< If true, make a HyCOM-\/like mixed layer by}}
\DoxyCodeLine{2280 \textcolor{comment}{                                                    !! preventing interfaces from being shallower than}}
\DoxyCodeLine{2281 \textcolor{comment}{                                                    !! the depths specified by the regridding coordinate.}}
\DoxyCodeLine{2282 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adaptDrho0\textcolor{comment}{       !< Reference density difference for stratification-\/dependent}}
\DoxyCodeLine{2283 \textcolor{comment}{                                                    !! diffusion. [R \string~> kg m-\/3]}}
\DoxyCodeLine{2284 }
\DoxyCodeLine{2285   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(interp\_scheme)) \textcolor{keyword}{call }set\_interp\_scheme(cs\%interp\_CS, interp\_scheme)}
\DoxyCodeLine{2286   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(boundary\_extrapolation)) \textcolor{keyword}{call }set\_interp\_extrap(cs\%interp\_CS, boundary\_extrapolation)}
\DoxyCodeLine{2287 }
\DoxyCodeLine{2288   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(old\_grid\_weight)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2289     \textcolor{keywordflow}{if} (old\_grid\_weight<0. .or. old\_grid\_weight>1.) \&}
\DoxyCodeLine{2290       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, set\_regrid\_params: Weight is out side the range 0..1!'})}
\DoxyCodeLine{2291     cs\%old\_grid\_weight = old\_grid\_weight}
\DoxyCodeLine{2292 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2293   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(depth\_of\_time\_filter\_shallow)) cs\%depth\_of\_time\_filter\_shallow = depth\_of\_time\_filter\_shallow}
\DoxyCodeLine{2294   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(depth\_of\_time\_filter\_deep)) cs\%depth\_of\_time\_filter\_deep = depth\_of\_time\_filter\_deep}
\DoxyCodeLine{2295   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(depth\_of\_time\_filter\_shallow) .or. \textcolor{keyword}{present}(depth\_of\_time\_filter\_deep)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2296     \textcolor{keywordflow}{if} (cs\%depth\_of\_time\_filter\_deep<cs\%depth\_of\_time\_filter\_shallow) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, '}//\&}
\DoxyCodeLine{2297                      \textcolor{stringliteral}{'set\_regrid\_params: depth\_of\_time\_filter\_deep<depth\_of\_time\_filter\_shallow!'})}
\DoxyCodeLine{2298 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2299 }
\DoxyCodeLine{2300   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) cs\%min\_thickness = min\_thickness}
\DoxyCodeLine{2301   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(compress\_fraction)) cs\%compressibility\_fraction = compress\_fraction}
\DoxyCodeLine{2302   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ref\_pressure)) cs\%ref\_pressure = ref\_pressure}
\DoxyCodeLine{2303   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(integrate\_downward\_for\_e)) cs\%integrate\_downward\_for\_e = integrate\_downward\_for\_e}
\DoxyCodeLine{2304   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(remap\_answers\_2018)) cs\%remap\_answers\_2018 = remap\_answers\_2018}
\DoxyCodeLine{2305 }
\DoxyCodeLine{2306   \textcolor{keywordflow}{select case} (cs\%regridding\_scheme)}
\DoxyCodeLine{2307   \textcolor{keywordflow}{case} (regridding\_zstar)}
\DoxyCodeLine{2308     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) \textcolor{keyword}{call }set\_zlike\_params(cs\%zlike\_CS, min\_thickness=min\_thickness)}
\DoxyCodeLine{2309   \textcolor{keywordflow}{case} (regridding\_sigma\_shelf\_zstar)}
\DoxyCodeLine{2310     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) \textcolor{keyword}{call }set\_zlike\_params(cs\%zlike\_CS, min\_thickness=min\_thickness)}
\DoxyCodeLine{2311   \textcolor{keywordflow}{case} (regridding\_sigma)}
\DoxyCodeLine{2312     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) \textcolor{keyword}{call }set\_sigma\_params(cs\%sigma\_CS, min\_thickness=min\_thickness)}
\DoxyCodeLine{2313   \textcolor{keywordflow}{case} (regridding\_rho)}
\DoxyCodeLine{2314     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) \textcolor{keyword}{call }set\_rho\_params(cs\%rho\_CS, min\_thickness=min\_thickness)}
\DoxyCodeLine{2315     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(integrate\_downward\_for\_e)) \&}
\DoxyCodeLine{2316       \textcolor{keyword}{call }set\_rho\_params(cs\%rho\_CS, integrate\_downward\_for\_e=integrate\_downward\_for\_e)}
\DoxyCodeLine{2317     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%rho\_CS) .and. (\textcolor{keyword}{present}(interp\_scheme) .or. \textcolor{keyword}{present}(boundary\_extrapolation))) \&}
\DoxyCodeLine{2318       \textcolor{keyword}{call }set\_rho\_params(cs\%rho\_CS, interp\_cs=cs\%interp\_CS)}
\DoxyCodeLine{2319   \textcolor{keywordflow}{case} (regridding\_hycom1)}
\DoxyCodeLine{2320     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%hycom\_CS) .and. (\textcolor{keyword}{present}(interp\_scheme) .or. \textcolor{keyword}{present}(boundary\_extrapolation))) \&}
\DoxyCodeLine{2321       \textcolor{keyword}{call }set\_hycom\_params(cs\%hycom\_CS, interp\_cs=cs\%interp\_CS)}
\DoxyCodeLine{2322   \textcolor{keywordflow}{case} (regridding\_slight)}
\DoxyCodeLine{2323     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness))       \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, min\_thickness=min\_thickness)}
\DoxyCodeLine{2324     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dz\_min\_surface))      \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, dz\_ml\_min=dz\_min\_surface)}
\DoxyCodeLine{2325     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(nz\_fixed\_surface))    \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, nz\_fixed\_surface=nz\_fixed\_surface)}
\DoxyCodeLine{2326     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(rho\_ml\_avg\_depth))    \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, rho\_ml\_avg\_depth=rho\_ml\_avg\_depth)}
\DoxyCodeLine{2327     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(nlay\_ml\_to\_interior)) \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, nlay\_ml\_offset=nlay\_ml\_to\_interior)}
\DoxyCodeLine{2328     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(fix\_haloclines))      \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, fix\_haloclines=fix\_haloclines)}
\DoxyCodeLine{2329     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halocline\_filt\_len))  \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, halocline\_filter\_length=halocline\_filt\_len)}
\DoxyCodeLine{2330     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halocline\_strat\_tol)) \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, halocline\_strat\_tol=halocline\_strat\_tol)}
\DoxyCodeLine{2331     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(compress\_fraction))   \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, compressibility\_fraction=compress\_fraction)}
\DoxyCodeLine{2332     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%slight\_CS) .and. (\textcolor{keyword}{present}(interp\_scheme) .or. \textcolor{keyword}{present}(boundary\_extrapolation))) \&}
\DoxyCodeLine{2333       \textcolor{keyword}{call }set\_slight\_params(cs\%slight\_CS, interp\_cs=cs\%interp\_CS)}
\DoxyCodeLine{2334   \textcolor{keywordflow}{case} (regridding\_adaptive)}
\DoxyCodeLine{2335     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adapttimeratio)) \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adapttimeratio=adapttimeratio)}
\DoxyCodeLine{2336     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adaptzoom))      \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adaptzoom=adaptzoom)}
\DoxyCodeLine{2337     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adaptzoomcoeff)) \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adaptzoomcoeff=adaptzoomcoeff)}
\DoxyCodeLine{2338     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adaptbuoycoeff)) \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adaptbuoycoeff=adaptbuoycoeff)}
\DoxyCodeLine{2339     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adaptalpha))     \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adaptalpha=adaptalpha)}
\DoxyCodeLine{2340     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adaptdomin))     \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adaptdomin=adaptdomin)}
\DoxyCodeLine{2341     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adaptdrho0))     \textcolor{keyword}{call }set\_adapt\_params(cs\%adapt\_CS, adaptdrho0=adaptdrho0)}
\DoxyCodeLine{2342 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{2343 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ae7eade38ab8e2adb0797a7191ddebb18}\label{namespacemom__regridding_ae7eade38ab8e2adb0797a7191ddebb18}} 
\index{mom\_regridding@{mom\_regridding}!set\_target\_densities@{set\_target\_densities}}
\index{set\_target\_densities@{set\_target\_densities}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{set\_target\_densities()}{set\_target\_densities()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::set\+\_\+target\+\_\+densities (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{real, dimension(cs\%nk+1), intent(in)}]{rho\+\_\+int }\end{DoxyParamCaption})}



Set target densities based on vector of interface values. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+int} & Interface densities \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2043   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2044 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \textcolor{keywordtype}{intent(in)}    :: rho\_int\textcolor{comment}{ !< Interface densities [R \string~> kg m-\/3]}}
\DoxyCodeLine{2045 }
\DoxyCodeLine{2046   \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(cs\%target\_density)/=\textcolor{keyword}{size}(rho\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2047     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_target\_densities inconsistent args!"})}
\DoxyCodeLine{2048 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2049 }
\DoxyCodeLine{2050   cs\%target\_density(:) = rho\_int(:)}
\DoxyCodeLine{2051   cs\%target\_density\_set = .true.}
\DoxyCodeLine{2052 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_ab6ada39c6f95e652907bab93f9c5a3f1}\label{namespacemom__regridding_ab6ada39c6f95e652907bab93f9c5a3f1}} 
\index{mom\_regridding@{mom\_regridding}!set\_target\_densities\_from\_gv@{set\_target\_densities\_from\_gv}}
\index{set\_target\_densities\_from\_gv@{set\_target\_densities\_from\_gv}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{set\_target\_densities\_from\_gv()}{set\_target\_densities\_from\_gv()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::set\+\_\+target\+\_\+densities\+\_\+from\+\_\+gv (\begin{DoxyParamCaption}\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})}



Set target densities based on the old Rlay variable. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em gv} & Ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2020   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}}
\DoxyCodeLine{2021   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{2022   \textcolor{keywordtype}{type}(regridding\_CS),     \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2023   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2024   \textcolor{keywordtype}{integer} :: k, nz}
\DoxyCodeLine{2025 }
\DoxyCodeLine{2026   nz = cs\%nk}
\DoxyCodeLine{2027   \textcolor{keywordflow}{if} (nz == 1) \textcolor{keywordflow}{then} \textcolor{comment}{! Set a broad range of bounds.  Regridding may not be meaningful in this case.}}
\DoxyCodeLine{2028     cs\%target\_density(1)    = 0.0}
\DoxyCodeLine{2029     cs\%target\_density(2)    = 2.0*gv\%Rlay(1)}
\DoxyCodeLine{2030   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2031     cs\%target\_density(1)    = (gv\%Rlay(1) + 0.5*(gv\%Rlay(1)-\/gv\%Rlay(2)))}
\DoxyCodeLine{2032     cs\%target\_density(nz+1) = (gv\%Rlay(nz) + 0.5*(gv\%Rlay(nz)-\/gv\%Rlay(nz-\/1)))}
\DoxyCodeLine{2033     \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{2034       cs\%target\_density(k)  = cs\%target\_density(k-\/1) + cs\%coordinateResolution(k)}
\DoxyCodeLine{2035 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2036 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2037   cs\%target\_density\_set = .true.}
\DoxyCodeLine{2038 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a162e9f816bc892550624d781fdddd6ca}\label{namespacemom__regridding_a162e9f816bc892550624d781fdddd6ca}} 
\index{mom\_regridding@{mom\_regridding}!setcoordinateresolution@{setcoordinateresolution}}
\index{setcoordinateresolution@{setcoordinateresolution}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{setcoordinateresolution()}{setcoordinateresolution()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+regridding\+::setcoordinateresolution (\begin{DoxyParamCaption}\item[{real, dimension(\+:), intent(in)}]{dz,  }\item[{type(\mbox{\hyperlink{structmom__regridding_1_1regridding__cs}{regridding\+\_\+cs}}), intent(inout)}]{CS,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})}



Set the fixed resolution data. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em dz} & A vector of vertical grid spacings \\
\hline
\mbox{\texttt{ in,out}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A scaling factor converting dz to coord\+Res \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{2003 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},  \textcolor{keywordtype}{intent(in)}    :: dz\textcolor{comment}{ !< A vector of vertical grid spacings}}
\DoxyCodeLine{2004   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{2005 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{ !< A scaling factor converting dz to coordRes}}
\DoxyCodeLine{2006 }
\DoxyCodeLine{2007   \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(dz)/=cs\%nk) \textcolor{keyword}{call }mom\_error( fatal, \&}
\DoxyCodeLine{2008       \textcolor{stringliteral}{'setCoordinateResolution: inconsistent number of levels'} )}
\DoxyCodeLine{2009 }
\DoxyCodeLine{2010   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2011     cs\%coordinateResolution(:) = scale*dz(:)}
\DoxyCodeLine{2012   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2013     cs\%coordinateResolution(:) = dz(:)}
\DoxyCodeLine{2014 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2015 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__regridding_a8b3b0c1555006f196d9bb1baededd9e6}\label{namespacemom__regridding_a8b3b0c1555006f196d9bb1baededd9e6}} 
\index{mom\_regridding@{mom\_regridding}!uniformresolution@{uniformresolution}}
\index{uniformresolution@{uniformresolution}!mom\_regridding@{mom\_regridding}}
\doxysubsubsection{\texorpdfstring{uniformresolution()}{uniformresolution()}}
{\footnotesize\ttfamily real function, dimension(nk), public mom\+\_\+regridding\+::uniformresolution (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{character(len=$\ast$), intent(in)}]{coord\+Mode,  }\item[{real, intent(in)}]{max\+Depth,  }\item[{real, intent(in)}]{rho\+Light,  }\item[{real, intent(in)}]{rho\+Heavy }\end{DoxyParamCaption})}



Return a uniform resolution vector in the units of the coordinate. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of cells in source grid \\
\hline
\mbox{\texttt{ in}}  & {\em coordmode} & A string indicating the coordinate mode. See the documenttion for \mbox{\hyperlink{namespaceregrid__consts}{regrid\+\_\+consts}} for the recognized values. \\
\hline
\mbox{\texttt{ in}}  & {\em maxdepth} & The range of the grid values in some modes \\
\hline
\mbox{\texttt{ in}}  & {\em rholight} & The minimum value of the grid in R\+HO mode \\
\hline
\mbox{\texttt{ in}}  & {\em rhoheavy} & The maximum value of the grid in R\+HO mode \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The returned uniform resolution grid. 
\end{DoxyReturn}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{1932 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1933 \textcolor{comment}{! Calculate a vector of uniform resolution in the units of the coordinate}}
\DoxyCodeLine{1934 \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1935   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{1936   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{ !< Number of cells in source grid}}
\DoxyCodeLine{1937   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: coordMode\textcolor{comment}{ !< A string indicating the coordinate mode.}}
\DoxyCodeLine{1938 \textcolor{comment}{                                            !! See the documenttion for regrid\_consts}}
\DoxyCodeLine{1939 \textcolor{comment}{                                            !! for the recognized values.}}
\DoxyCodeLine{1940 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: maxDepth\textcolor{comment}{  !< The range of the grid values in some modes}}
\DoxyCodeLine{1941 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: rhoLight\textcolor{comment}{  !< The minimum value of the grid in RHO mode}}
\DoxyCodeLine{1942 \textcolor{keywordtype}{  real},             \textcolor{keywordtype}{intent(in)} :: rhoHeavy\textcolor{comment}{  !< The maximum value of the grid in RHO mode}}
\DoxyCodeLine{1943 }
\DoxyCodeLine{1944 \textcolor{keywordtype}{  real}                         :: uniformResolution(nk)\textcolor{comment}{ !< The returned uniform resolution grid.}}
\DoxyCodeLine{1945 }
\DoxyCodeLine{1946   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1947   \textcolor{keywordtype}{integer} :: scheme}
\DoxyCodeLine{1948 }
\DoxyCodeLine{1949   scheme = coordinatemode(coordmode)}
\DoxyCodeLine{1950   \textcolor{keywordflow}{select case} ( scheme )}
\DoxyCodeLine{1951 }
\DoxyCodeLine{1952     \textcolor{keywordflow}{case} ( regridding\_zstar, regridding\_hycom1, regridding\_slight, regridding\_sigma\_shelf\_zstar, \&}
\DoxyCodeLine{1953            regridding\_adaptive )}
\DoxyCodeLine{1954       uniformresolution(:) = maxdepth / real(nk)}
\DoxyCodeLine{1955 }
\DoxyCodeLine{1956     \textcolor{keywordflow}{case} ( regridding\_rho )}
\DoxyCodeLine{1957       uniformresolution(:) = (rhoheavy -\/ rholight) / real(nk)}
\DoxyCodeLine{1958 }
\DoxyCodeLine{1959     \textcolor{keywordflow}{case} ( regridding\_sigma )}
\DoxyCodeLine{1960       uniformresolution(:) = 1. / real(nk)}
\DoxyCodeLine{1961 }
\DoxyCodeLine{1962 \textcolor{keywordflow}{    case default}}
\DoxyCodeLine{1963       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_regridding, uniformResolution: "}//\&}
\DoxyCodeLine{1964        \textcolor{stringliteral}{"Unrecognized choice for coordinate mode ("}//trim(coordmode)//\textcolor{stringliteral}{")."})}
\DoxyCodeLine{1965 }
\DoxyCodeLine{1966 \textcolor{keywordflow}{  end select} \textcolor{comment}{! type of grid}}
\DoxyCodeLine{1967 }

\end{DoxyCode}
