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


\subsection{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 \subsection*{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}
\subsection*{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}
\subsection*{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\+L\+M (2nd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} P\+P\+M\+\_\+\+H4 (3rd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} P\+P\+M\+\_\+\+I\+H4 (3rd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{} 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}


\subsection{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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em nk} & Number of layers in h\+\_\+old\\
\hline
\mbox{\tt in}  & {\em h\+\_\+old} & Minium allowed thickness of h \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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 1666 of file M\+O\+M\+\_\+regridding.\+F90.


\begin{DoxyCode}
1666   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}
1667   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{ !< Number of layers in h\_old}
1668   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},      \textcolor{keywordtype}{intent(in)}    :: h\_old\textcolor{comment}{ !< Minium allowed thickness of h [H ~> m or kg m-2]}
1669   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(CS%nk+1)}, \textcolor{keywordtype}{intent(inout)} :: dz\_int\textcolor{comment}{ !< Minium allowed thickness of h [H ~> m or kg m-2]}
1670   \textcolor{comment}{! Local variables}
1671   \textcolor{keywordtype}{integer} :: k
1672   \textcolor{keywordtype}{real} :: h\_new, eps, h\_total, h\_err
1673 
1674   eps = 1. ; eps = epsilon(eps)
1675 
1676   h\_total = 0. ; h\_err = 0.
1677   \textcolor{keywordflow}{do} k = 1, min(cs%nk,nk)
1678     h\_total = h\_total + h\_old(k)
1679     h\_err = h\_err + max( h\_old(k), abs(dz\_int(k)), abs(dz\_int(k+1)) )*eps
1680     h\_new = h\_old(k) + ( dz\_int(k) - dz\_int(k+1) )
1681     \textcolor{keywordflow}{if} (h\_new < -3.0*h\_err) \textcolor{keywordflow}{then}
1682       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'h<0 at k='},k,\textcolor{stringliteral}{'h\_old='},h\_old(k), &
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), &
1684         \textcolor{stringliteral}{'h\_new='},h\_new,\textcolor{stringliteral}{'h\_err='},h\_err
1685       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding: adjust\_interface\_motion() - '}//&
1686                      \textcolor{stringliteral}{'implied h<0 is larger than roundoff!'})
1687 \textcolor{keywordflow}{    endif}
1688 \textcolor{keywordflow}{  enddo}
1689   \textcolor{keywordflow}{if} (cs%nk>nk) \textcolor{keywordflow}{then}
1690     \textcolor{keywordflow}{do} k = nk+1, cs%nk
1691       h\_err = h\_err + max( abs(dz\_int(k)), abs(dz\_int(k+1)) )*eps
1692       h\_new = ( dz\_int(k) - dz\_int(k+1) )
1693       \textcolor{keywordflow}{if} (h\_new < -3.0*h\_err) \textcolor{keywordflow}{then}
1694         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'h<0 at k='},k,\textcolor{stringliteral}{'h\_old was empty'},&
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), &
1696           \textcolor{stringliteral}{'h\_new='},h\_new,\textcolor{stringliteral}{'h\_err='},h\_err
1697         \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding: adjust\_interface\_motion() - '}//&
1698                        \textcolor{stringliteral}{'implied h<0 is larger than roundoff!'})
1699 \textcolor{keywordflow}{      endif}
1700 \textcolor{keywordflow}{    enddo}
1701 \textcolor{keywordflow}{  endif}
1702   \textcolor{keywordflow}{do} k = min(cs%nk,nk),2,-1
1703     h\_new = h\_old(k) + ( dz\_int(k) - dz\_int(k+1) )
1704     \textcolor{keywordflow}{if} (h\_new<cs%min\_thickness) &
1705       dz\_int(k) = ( dz\_int(k+1) - h\_old(k) ) + cs%min\_thickness \textcolor{comment}{! Implies next h\_new = min\_thickness}
1706     h\_new = h\_old(k) + ( dz\_int(k) - dz\_int(k+1) )
1707     \textcolor{keywordflow}{if} (h\_new<0.) &
1708       dz\_int(k) = ( 1. - eps ) * ( dz\_int(k+1) - h\_old(k) ) \textcolor{comment}{! Backup in case min\_thickness==0}
1709     h\_new = h\_old(k) + ( dz\_int(k) - dz\_int(k+1) )
1710     \textcolor{keywordflow}{if} (h\_new<0.) \textcolor{keywordflow}{then}
1711       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'h<0 at k='},k,\textcolor{stringliteral}{'h\_old='},h\_old(k), &
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), &
1713         \textcolor{stringliteral}{'h\_new='},h\_new
1714       stop \textcolor{stringliteral}{'Still did not work!'}
1715       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_regridding: adjust\_interface\_motion() - '}//&
1716                      \textcolor{stringliteral}{'Repeated adjustment for roundoff h<0 failed!'})
1717 \textcolor{keywordflow}{    endif}
1718 \textcolor{keywordflow}{  enddo}
1719  \textcolor{comment}{!if (dz\_int(1)/=0.) stop 'MOM\_regridding: adjust\_interface\_motion() surface moved'}
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables\\
\hline
\mbox{\tt in,out}  & {\em dzinterface} & The change in interface depth \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em remapcs} & The remapping control structure\\
\hline
\mbox{\tt in}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


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


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


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

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


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


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


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


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


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


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


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


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


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


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


\begin{DoxyCode}
907   \textcolor{keywordtype}{type}(regridding\_CS),                       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}
908   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}
909   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}
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)}
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)}
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)}
913   \textcolor{comment}{! Local variables}
914   \textcolor{keywordtype}{integer} :: i, j, k, nki
915 
916   nki = min(cs%nk, gv%ke)
917 
918   \textcolor{comment}{!$OMP parallel do default(shared)}
919   \textcolor{keywordflow}{do} j = g%jsc-1,g%jec+1
920     \textcolor{keywordflow}{do} i = g%isc-1,g%iec+1
921       \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
922         \textcolor{keywordflow}{do} k=1,nki
923           h\_new(i,j,k) = max( 0., h(i,j,k) + ( dzinterface(i,j,k) - dzinterface(i,j,k+1) ) )
924 \textcolor{keywordflow}{        enddo}
925         \textcolor{keywordflow}{if} (cs%nk > gv%ke) \textcolor{keywordflow}{then}
926           \textcolor{keywordflow}{do} k=nki+1, cs%nk
927             h\_new(i,j,k) = max( 0., dzinterface(i,j,k) - dzinterface(i,j,k+1) )
928 \textcolor{keywordflow}{          enddo}
929 \textcolor{keywordflow}{        endif}
930       \textcolor{keywordflow}{else}
931         h\_new(i,j,1:nki) = h(i,j,1:nki)
932         \textcolor{keywordflow}{if} (cs%nk > gv%ke) h\_new(i,j,nki+1:cs%nk) = 0.
933         \textcolor{comment}{! On land points, why are we keeping the original h rather than setting to zero? -AJA}
934 \textcolor{keywordflow}{      endif}
935 \textcolor{keywordflow}{    enddo}
936 \textcolor{keywordflow}{  enddo}
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}}
\subsubsection{\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{\tt in}  & {\em nk} & Number of cells\\
\hline
\mbox{\tt in}  & {\em depth} & Depth of bottom \mbox{[}Z $\sim$$>$ m\mbox{]} or arbitrary units\\
\hline
\mbox{\tt in}  & {\em h} & Cell thicknesses \mbox{[}Z $\sim$$>$ m\mbox{]} or arbitrary units\\
\hline
\mbox{\tt in}  & {\em dzinterface} & Change in interface positions (same units as h)\\
\hline
\mbox{\tt in}  & {\em msg} & Message to append to errors \\
\hline
\end{DoxyParams}


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


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


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


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


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


\begin{DoxyCode}
942   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{   !< Grid structure}
943   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{  !< Ocean vertical grid structure}
944   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))},   \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{   !< Layer thicknesses [H ~> m or kg m-2]}
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}
946 \textcolor{comment}{                                                                 !! [H ~> m or kg m-2]}
947   \textcolor{keywordtype}{character(len=*)},                            \textcolor{keywordtype}{intent(in)} :: msg\textcolor{comment}{ !< Message to append to errors}
948   \textcolor{comment}{! Local variables}
949   \textcolor{keywordtype}{integer} :: i, j
950 
951   \textcolor{comment}{!$OMP parallel do default(shared)}
952   \textcolor{keywordflow}{do} j = g%jsc-1,g%jec+1 ; \textcolor{keywordflow}{do} i = g%isc-1,g%iec+1
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 )
954 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\end{DoxyParams}


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


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


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


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


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


\begin{DoxyCode}
794   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
795 
796   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%zlike\_CS))  \textcolor{keyword}{call }end\_coord\_zlike(cs%zlike\_CS)
797   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%sigma\_CS))  \textcolor{keyword}{call }end\_coord\_sigma(cs%sigma\_CS)
798   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%rho\_CS))    \textcolor{keyword}{call }end\_coord\_rho(cs%rho\_CS)
799   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%hycom\_CS))  \textcolor{keyword}{call }end\_coord\_hycom(cs%hycom\_CS)
800   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%slight\_CS)) \textcolor{keyword}{call }end\_coord\_slight(cs%slight\_CS)
801   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%adapt\_CS))  \textcolor{keyword}{call }end\_coord\_adapt(cs%adapt\_CS)
802 
803   \textcolor{keyword}{deallocate}( cs%coordinateResolution )
804   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%target\_density)) \textcolor{keyword}{deallocate}( cs%target\_density )
805   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%max\_interface\_depths) ) \textcolor{keyword}{deallocate}( cs%max\_interface\_depths )
806   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%max\_layer\_thickness) ) \textcolor{keyword}{deallocate}( cs%max\_layer\_thickness )
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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em nk} & Number of cells in source grid\\
\hline
\mbox{\tt in}  & {\em z\+\_\+old} & Old grid position \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em z\+\_\+new} & New grid position \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em dz\+\_\+g} & Change in interface positions \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


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


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


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


\begin{DoxyCode}
2348   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
2349 
2350   get\_regrid\_size = cs%nk
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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
2372   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}
2373   \textcolor{keywordtype}{type}(rho\_CS) :: get\_rho\_CS
2374 
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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
2364   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}
2365   \textcolor{keywordtype}{type}(sigma\_CS) :: get\_sigma\_CS
2366 
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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
2356   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}
2357   \textcolor{keywordtype}{type}(zlike\_CS) :: get\_zlike\_CS
2358 
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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt 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 2141 of file M\+O\+M\+\_\+regridding.\+F90.


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


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


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


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


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


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


\begin{DoxyCode}
2186   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Regridding control structure}
2187   \textcolor{keywordtype}{character(len=20)}               :: getCoordinateUnits
2188 
2189   \textcolor{keywordflow}{select case} ( cs%regridding\_scheme )
2190     \textcolor{keywordflow}{case} ( regridding\_zstar, regridding\_hycom1, regridding\_slight, regridding\_adaptive )
2191       getcoordinateunits = \textcolor{stringliteral}{'meter'}
2192     \textcolor{keywordflow}{case} ( regridding\_sigma\_shelf\_zstar )
2193       getcoordinateunits = \textcolor{stringliteral}{'meter/fraction'}
2194     \textcolor{keywordflow}{case} ( regridding\_sigma )
2195       getcoordinateunits = \textcolor{stringliteral}{'fraction'}
2196     \textcolor{keywordflow}{case} ( regridding\_rho )
2197       getcoordinateunits = \textcolor{stringliteral}{'kg/m3'}
2198     \textcolor{keywordflow}{case} ( regridding\_arbitrary )
2199       getcoordinateunits = \textcolor{stringliteral}{'unknown'}
2200 \textcolor{keywordflow}{    case default}
2201       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'MOM\_regridding, getCoordinateUnits: '}//&
2202                      \textcolor{stringliteral}{'Unknown regridding scheme selected!'})
2203 \textcolor{keywordflow}{  end select} \textcolor{comment}{! type of grid}
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}}
\subsubsection{\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{\tt in}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em ssh} & The sea surface height, in the same units as depth\\
\hline
\mbox{\tt 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 2381 of file M\+O\+M\+\_\+regridding.\+F90.


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


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


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


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


\begin{DoxyCode}
1973   \textcolor{keywordtype}{type}(regridding\_CS),     \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
1974   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in)}    :: coord\_mode\textcolor{comment}{ !< A string indicating the coordinate mode.}
1975 \textcolor{comment}{                                               !! See the documentation for regrid\_consts}
1976 \textcolor{comment}{                                               !! for the recognized values.}
1977   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}
1978   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
1979 
1980   \textcolor{keywordflow}{select case} (coordinatemode(coord\_mode))
1981   \textcolor{keywordflow}{case} (regridding\_zstar)
1982     \textcolor{keyword}{call }init\_coord\_zlike(cs%zlike\_CS, cs%nk, cs%coordinateResolution)
1983   \textcolor{keywordflow}{case} (regridding\_sigma\_shelf\_zstar)
1984     \textcolor{keyword}{call }init\_coord\_zlike(cs%zlike\_CS, cs%nk, cs%coordinateResolution)
1985   \textcolor{keywordflow}{case} (regridding\_sigma)
1986     \textcolor{keyword}{call }init\_coord\_sigma(cs%sigma\_CS, cs%nk, cs%coordinateResolution)
1987   \textcolor{keywordflow}{case} (regridding\_rho)
1988     \textcolor{keyword}{call }init\_coord\_rho(cs%rho\_CS, cs%nk, cs%ref\_pressure, cs%target\_density, cs%interp\_CS)
1989   \textcolor{keywordflow}{case} (regridding\_hycom1)
1990     \textcolor{keyword}{call }init\_coord\_hycom(cs%hycom\_CS, cs%nk, cs%coordinateResolution, cs%target\_density, &
1991                           cs%interp\_CS)
1992   \textcolor{keywordflow}{case} (regridding\_slight)
1993     \textcolor{keyword}{call }init\_coord\_slight(cs%slight\_CS, cs%nk, cs%ref\_pressure, cs%target\_density, &
1994                            cs%interp\_CS, gv%m\_to\_H)
1995   \textcolor{keywordflow}{case} (regridding\_adaptive)
1996     \textcolor{keyword}{call }init\_coord\_adapt(cs%adapt\_CS, cs%nk, cs%coordinateResolution, gv%m\_to\_H, us%kg\_m3\_to\_R)
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}}
\subsubsection{\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{\tt in,out}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em max\+\_\+depth} & The maximum depth of the ocean \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file\\
\hline
\mbox{\tt in}  & {\em mdl} & Name of calling module.\\
\hline
\mbox{\tt in}  & {\em coord\+\_\+mode} & Coordinate mode\\
\hline
\mbox{\tt in}  & {\em param\+\_\+prefix} & String to prefix to parameter names. If empty, causes main model parameters to be used.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+suffix} & String to append to parameter names. \\
\hline
\end{DoxyParams}


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


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


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


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


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


\begin{DoxyCode}
2447   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: string\textcolor{comment}{ !< String with list of parameters in form}
2448 \textcolor{comment}{                                              !! dz\_min, H\_total, power, precision}
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]}
2450   \textcolor{comment}{! Local variables}
2451   \textcolor{keywordtype}{integer} :: nki, k, nk
2452   \textcolor{keywordtype}{real}    :: ddx, dx, rho\_1, rho\_2, rho\_3, drho, rho\_4, drho\_min
2453 
2454   \textcolor{keyword}{read}( string, *) nk, rho\_1, rho\_2, rho\_3, drho, rho\_4, drho\_min
2455   \textcolor{keyword}{allocate}(rho\_target(nk+1))
2456   nki = nk + 1 - 4 \textcolor{comment}{! Number of interfaces minus 4 specified values}
2457   rho\_target(1) = rho\_1
2458   rho\_target(2) = rho\_2
2459   dx = 0.
2460   \textcolor{keywordflow}{do} k = 0, nki
2461     ddx = max( drho\_min, \textcolor{keywordtype}{real}(nki-k)/\textcolor{keywordtype}{real(nki*nki)} )
2462     dx = dx + ddx
2463     rho\_target(3+k) = rho\_3 + (2. * drho) * dx
2464 \textcolor{keywordflow}{  enddo}
2465   rho\_target(nki+4) = rho\_4
2466 
2467   rho\_function1 = nk
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}}
\subsubsection{\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{\tt in,out}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em max\+\_\+depths} & Maximum interface depths, in arbitrary units\\
\hline
\mbox{\tt in}  & {\em units\+\_\+to\+\_\+h} & A conversion factor for max\+\_\+depths into H units \\
\hline
\end{DoxyParams}


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


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


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


\begin{DoxyCode}
2095   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
2096   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(CS%nk+1)}, \textcolor{keywordtype}{intent(in)}    :: max\_h\textcolor{comment}{ !< Maximum interface depths, in arbitrary units}
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}
2098   \textcolor{comment}{! Local variables}
2099   \textcolor{keywordtype}{real} :: val\_to\_H
2100   \textcolor{keywordtype}{integer} :: K
2101 
2102   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{allocated}(cs%max\_layer\_thickness)) \textcolor{keyword}{allocate}(cs%max\_layer\_thickness(1:cs%nk))
2103 
2104   val\_to\_h = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}( units\_to\_h)) val\_to\_h = units\_to\_h
2105 
2106   \textcolor{keywordflow}{do} k=1,cs%nk
2107     cs%max\_layer\_thickness(k) = val\_to\_h * max\_h(k)
2108 \textcolor{keywordflow}{  enddo}
2109 
2110   \textcolor{comment}{! set max thickness for coordinate}
2111   \textcolor{keywordflow}{select case} (cs%regridding\_scheme)
2112   \textcolor{keywordflow}{case} (regridding\_hycom1)
2113     \textcolor{keyword}{call }set\_hycom\_params(cs%hycom\_CS, max\_layer\_thickness=cs%max\_layer\_thickness)
2114   \textcolor{keywordflow}{case} (regridding\_slight)
2115     \textcolor{keyword}{call }set\_slight\_params(cs%slight\_CS, max\_layer\_thickness=cs%max\_layer\_thickness)
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}}
\subsubsection{\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{\tt in,out}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em boundary\+\_\+extrapolation} & Extrapolate in boundary cells\\
\hline
\mbox{\tt in}  & {\em min\+\_\+thickness} & Minimum thickness allowed when building the new grid \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em old\+\_\+grid\+\_\+weight} & Weight given to old coordinate when time-\/filtering grid\\
\hline
\mbox{\tt in}  & {\em interp\+\_\+scheme} & Interpolation method for state-\/dependent coordinates\\
\hline
\mbox{\tt in}  & {\em depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+shallow} & Depth to start cubic \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em depth\+\_\+of\+\_\+time\+\_\+filter\+\_\+deep} & Depth to end cubic \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em compress\+\_\+fraction} & Fraction of compressibility to add to potential density \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ref\+\_\+pressure} & The reference pressure for density-\/dependent coordinates \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}\\
\hline
\mbox{\tt 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{\tt in}  & {\em nz\+\_\+fixed\+\_\+surface} & The number of fixed-\/thickness layers at the top of the model\\
\hline
\mbox{\tt 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{\tt in}  & {\em nlay\+\_\+ml\+\_\+to\+\_\+interior} & Number of layers to offset the mixed layer density to find resolved stratification \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em fix\+\_\+haloclines} & Detect regions with much weaker stratification in the coordinate\\
\hline
\mbox{\tt 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{\tt in}  & {\em halocline\+\_\+strat\+\_\+tol} & Value of the stratification ratio that defines a problematic halocline region.\\
\hline
\mbox{\tt in}  & {\em integrate\+\_\+downward\+\_\+for\+\_\+e} & If true, integrate for interface positions downward from the top.\\
\hline
\mbox{\tt 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{\tt in}  & {\em adapttimeratio} & Ratio of the A\+LE timestep to the grid timescale \mbox{[}nondim\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em adaptzoom} & Depth of near-\/surface zooming region \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em adaptzoomcoeff} & Coefficient of near-\/surface zooming diffusivity \mbox{[}nondim\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em adaptbuoycoeff} & Coefficient of buoyancy diffusivity \mbox{[}nondim\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em adaptalpha} & Scaling factor on optimization tendency \mbox{[}nondim\mbox{]}.\\
\hline
\mbox{\tt 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{\tt in}  & {\em adaptdrho0} & Reference density difference for stratification-\/dependent diffusion. \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\end{DoxyParams}


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


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


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


\begin{DoxyCode}
2043   \textcolor{keywordtype}{type}(regridding\_CS),      \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
2044   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(CS%nk+1)}, \textcolor{keywordtype}{intent(in)}    :: rho\_int\textcolor{comment}{ !< Interface densities [R ~> kg m-3]}
2045 
2046   \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(cs%target\_density)/=\textcolor{keyword}{size}(rho\_int)) \textcolor{keywordflow}{then}
2047     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_target\_densities inconsistent args!"})
2048 \textcolor{keywordflow}{  endif}
2049 
2050   cs%target\_density(:) = rho\_int(:)
2051   cs%target\_density\_set = .true.
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}}
\subsubsection{\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{\tt in}  & {\em gv} & Ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em cs} & Regridding control structure \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
2020   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Ocean vertical grid structure}
2021   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
2022   \textcolor{keywordtype}{type}(regridding\_CS),     \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
2023   \textcolor{comment}{! Local variables}
2024   \textcolor{keywordtype}{integer} :: k, nz
2025 
2026   nz = cs%nk
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.}
2028     cs%target\_density(1)    = 0.0
2029     cs%target\_density(2)    = 2.0*gv%Rlay(1)
2030   \textcolor{keywordflow}{else}
2031     cs%target\_density(1)    = (gv%Rlay(1) + 0.5*(gv%Rlay(1)-gv%Rlay(2)))
2032     cs%target\_density(nz+1) = (gv%Rlay(nz) + 0.5*(gv%Rlay(nz)-gv%Rlay(nz-1)))
2033     \textcolor{keywordflow}{do} k=2,nz
2034       cs%target\_density(k)  = cs%target\_density(k-1) + cs%coordinateResolution(k)
2035 \textcolor{keywordflow}{    enddo}
2036 \textcolor{keywordflow}{  endif}
2037   cs%target\_density\_set = .true.
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}}
\subsubsection{\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{\tt in}  & {\em dz} & A vector of vertical grid spacings\\
\hline
\mbox{\tt in,out}  & {\em cs} & Regridding control structure\\
\hline
\mbox{\tt in}  & {\em scale} & A scaling factor converting dz to coord\+Res \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
2003   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},  \textcolor{keywordtype}{intent(in)}    :: dz\textcolor{comment}{ !< A vector of vertical grid spacings}
2004   \textcolor{keywordtype}{type}(regridding\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Regridding control structure}
2005   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{ !< A scaling factor converting dz to coordRes}
2006 
2007   \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(dz)/=cs%nk) \textcolor{keyword}{call }mom\_error( fatal, &
2008       \textcolor{stringliteral}{'setCoordinateResolution: inconsistent number of levels'} )
2009 
2010   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) \textcolor{keywordflow}{then}
2011     cs%coordinateResolution(:) = scale*dz(:)
2012   \textcolor{keywordflow}{else}
2013     cs%coordinateResolution(:) = dz(:)
2014 \textcolor{keywordflow}{  endif}
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}}
\subsubsection{\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{\tt in}  & {\em nk} & Number of cells in source grid\\
\hline
\mbox{\tt 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{\tt in}  & {\em maxdepth} & The range of the grid values in some modes\\
\hline
\mbox{\tt in}  & {\em rholight} & The minimum value of the grid in R\+HO mode\\
\hline
\mbox{\tt 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 1932 of file M\+O\+M\+\_\+regridding.\+F90.


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