\hypertarget{namespacecoord__rho}{}\doxysection{coord\+\_\+rho Module Reference}
\label{namespacecoord__rho}\index{coord\_rho@{coord\_rho}}


\doxysubsection{Detailed Description}
Regrid columns for the continuous isopycnal (rho) coordinate. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structcoord__rho_1_1rho__cs}{rho\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure containing required parameters for the rho coordinate. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacecoord__rho_a86640b2be846b291c71f1c38b8ff9878}{init\+\_\+coord\+\_\+rho}} (CS, nk, ref\+\_\+pressure, target\+\_\+density, interp\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Initialise a rho\+\_\+\+CS with pointers to parameters. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__rho_a8e9c666d47d847ab8b64a22c470931d1}{end\+\_\+coord\+\_\+rho}} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates memory in the control structure for the \mbox{\hyperlink{namespacecoord__rho}{coord\+\_\+rho}} module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__rho_a6b2a48523247f59c7b4b5b7941334c25}{set\+\_\+rho\+\_\+params}} (CS, min\+\_\+thickness, integrate\+\_\+downward\+\_\+for\+\_\+e, interp\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em This subroutine can be used to set the parameters for the \mbox{\hyperlink{namespacecoord__rho}{coord\+\_\+rho}} module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__rho_ac3f19bfa0e6b622cdf045c348ec4d183}{build\+\_\+rho\+\_\+column}} (CS, nz, depth, h, T, S, eqn\+\_\+of\+\_\+state, z\+\_\+interface, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Build a rho coordinate column. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacecoord__rho_ad79c2a471c8de0b16f0478813be7c29f}{build\+\_\+rho\+\_\+column\+\_\+iteratively}} (CS, remap\+CS, nz, depth, h, T, S, eqn\+\_\+of\+\_\+state, z\+Interface, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge, dev\+\_\+tol)
\begin{DoxyCompactList}\small\item\em Iteratively build a rho coordinate column. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacecoord__rho_a17064808dccea1f725fe82cd49cd2541}{copy\+\_\+finite\+\_\+thicknesses}} (nk, h\+\_\+in, thresh, nout, h\+\_\+out, mapping)
\begin{DoxyCompactList}\small\item\em Copy column thicknesses with vanished layers removed. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__rho_afbc86f29df8e39eb793d12075d018518}{old\+\_\+inflate\+\_\+layers\+\_\+1d}} (min\+\_\+thickness, nk, h)
\begin{DoxyCompactList}\small\item\em Inflate vanished layers to finite (nonzero) width. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacecoord__rho_ac3f19bfa0e6b622cdf045c348ec4d183}\label{namespacecoord__rho_ac3f19bfa0e6b622cdf045c348ec4d183}} 
\index{coord\_rho@{coord\_rho}!build\_rho\_column@{build\_rho\_column}}
\index{build\_rho\_column@{build\_rho\_column}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{build\_rho\_column()}{build\_rho\_column()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+rho\+::build\+\_\+rho\+\_\+column (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__rho_1_1rho__cs}{rho\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{nz,  }\item[{real, intent(in)}]{depth,  }\item[{real, dimension(nz), intent(in)}]{h,  }\item[{real, dimension(nz), intent(in)}]{T,  }\item[{real, dimension(nz), intent(in)}]{S,  }\item[{type(eos\+\_\+type), pointer}]{eqn\+\_\+of\+\_\+state,  }\item[{real, dimension(cs\%nk+1), intent(inout)}]{z\+\_\+interface,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Build a rho coordinate column. 


\begin{DoxyEnumerate}
\item Density profiles are calculated on the source grid.
\item Positions of target densities (for interfaces) are found by interpolation. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & \mbox{\hyperlink{namespacecoord__rho}{coord\+\_\+rho}} control structure \\
\hline
\mbox{\texttt{ in}}  & {\em nz} & Number of levels on source grid (i.\+e. length of h, T, S) \\
\hline
\mbox{\texttt{ in}}  & {\em depth} & Depth of ocean bottom (positive downward) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t} & Temperature for source column \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & Salinity for source column \mbox{[}ppt\mbox{]} \\
\hline
 & {\em eqn\+\_\+of\+\_\+state} & Equation of state structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em z\+\_\+interface} & Absolute positions of interfaces \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}

\end{DoxyEnumerate}

Definition at line 90 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{92   \textcolor{keywordtype}{type}(rho\_CS),        \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< coord\_rho control structure}}
\DoxyCodeLine{93   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{ !< Number of levels on source grid (i.e. length of  h, T, S)}}
\DoxyCodeLine{94 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{ !< Depth of ocean bottom (positive downward) [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{95 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{96 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)}, \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{  !< Temperature for source column [degC]}}
\DoxyCodeLine{97 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)}, \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{  !< Salinity for source column [ppt]}}
\DoxyCodeLine{98   \textcolor{keywordtype}{type}(EOS\_type),      \textcolor{keywordtype}{pointer}       :: eqn\_of\_state\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{99 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)}, \&}
\DoxyCodeLine{100                        \textcolor{keywordtype}{intent(inout)} :: z\_interface\textcolor{comment}{ !< Absolute positions of interfaces}}
\DoxyCodeLine{101 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the purpose}}
\DoxyCodeLine{102 \textcolor{comment}{                                             !! of cell reconstructions [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{103 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width for the purpose}}
\DoxyCodeLine{104 \textcolor{comment}{                                             !! of edge value calculations [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{105 }
\DoxyCodeLine{106   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{107   \textcolor{keywordtype}{integer} :: k, count\_nonzero\_layers}
\DoxyCodeLine{108   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nz)} :: mapping}
\DoxyCodeLine{109 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: pres     \textcolor{comment}{! Pressures used to calculate density [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{110 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: h\_nv     \textcolor{comment}{! Thicknesses of non-\/vanishing layers [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{111 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: densities \textcolor{comment}{! Layer density [R \string~> kg m-\/3]}}
\DoxyCodeLine{112 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: xTmp   \textcolor{comment}{! Temporary positions [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{113 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk)} :: h\_new \textcolor{comment}{! New thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{114 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(CS\%nk+1)} :: x1  \textcolor{comment}{! Interface heights [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{115 }
\DoxyCodeLine{116   \textcolor{comment}{! Construct source column with vanished layers removed (stored in h\_nv)}}
\DoxyCodeLine{117   \textcolor{keyword}{call }copy\_finite\_thicknesses(nz, h, cs\%min\_thickness, count\_nonzero\_layers, h\_nv, mapping)}
\DoxyCodeLine{118 }
\DoxyCodeLine{119   \textcolor{keywordflow}{if} (count\_nonzero\_layers > 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{120     xtmp(1) = 0.0}
\DoxyCodeLine{121     \textcolor{keywordflow}{do} k = 1,count\_nonzero\_layers}
\DoxyCodeLine{122       xtmp(k+1) = xtmp(k) + h\_nv(k)}
\DoxyCodeLine{123 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{124 }
\DoxyCodeLine{125     \textcolor{comment}{! Compute densities on source column}}
\DoxyCodeLine{126     pres(:) = cs\%ref\_pressure}
\DoxyCodeLine{127     \textcolor{keyword}{call }calculate\_density(t, s, pres, densities, eqn\_of\_state)}
\DoxyCodeLine{128     \textcolor{keywordflow}{do} k = 1,count\_nonzero\_layers}
\DoxyCodeLine{129       densities(k) = densities(mapping(k))}
\DoxyCodeLine{130 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{131 }
\DoxyCodeLine{132     \textcolor{comment}{! Based on source column density profile, interpolate to generate a new grid}}
\DoxyCodeLine{133     \textcolor{keyword}{call }build\_and\_interpolate\_grid(cs\%interp\_CS, densities, count\_nonzero\_layers, \&}
\DoxyCodeLine{134                                     h\_nv, xtmp, cs\%target\_density, cs\%nk, h\_new, \&}
\DoxyCodeLine{135                                     x1, h\_neglect, h\_neglect\_edge)}
\DoxyCodeLine{136 }
\DoxyCodeLine{137     \textcolor{comment}{! Inflate vanished layers}}
\DoxyCodeLine{138     \textcolor{keyword}{call }old\_inflate\_layers\_1d(cs\%min\_thickness, cs\%nk, h\_new)}
\DoxyCodeLine{139 }
\DoxyCodeLine{140     \textcolor{comment}{! Comment: The following adjustment of h\_new, and re-\/calculation of h\_new via x1 needs to be removed}}
\DoxyCodeLine{141     x1(1) = 0.0 ; \textcolor{keywordflow}{do} k = 1,cs\%nk ; x1(k+1) = x1(k) + h\_new(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{142     \textcolor{keywordflow}{do} k = 1,cs\%nk}
\DoxyCodeLine{143       h\_new(k) = x1(k+1) -\/ x1(k)}
\DoxyCodeLine{144 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{145 }
\DoxyCodeLine{146   \textcolor{keywordflow}{else} \textcolor{comment}{! count\_nonzero\_layers <= 1}}
\DoxyCodeLine{147     \textcolor{keywordflow}{if} (nz == cs\%nk) \textcolor{keywordflow}{then}}
\DoxyCodeLine{148       h\_new(:) = h(:) \textcolor{comment}{! This keeps old behavior}}
\DoxyCodeLine{149     \textcolor{keywordflow}{else}}
\DoxyCodeLine{150       h\_new(:) = 0.}
\DoxyCodeLine{151       h\_new(1) = h(1)}
\DoxyCodeLine{152 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{153 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{154 }
\DoxyCodeLine{155   \textcolor{comment}{! Return interface positions}}
\DoxyCodeLine{156   \textcolor{keywordflow}{if} (cs\%integrate\_downward\_for\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{157     \textcolor{comment}{! Remapping is defined integrating from zero}}
\DoxyCodeLine{158     z\_interface(1) = 0.}
\DoxyCodeLine{159     \textcolor{keywordflow}{do} k = 1,cs\%nk}
\DoxyCodeLine{160       z\_interface(k+1) = z\_interface(k) -\/ h\_new(k)}
\DoxyCodeLine{161 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{162   \textcolor{keywordflow}{else}}
\DoxyCodeLine{163     \textcolor{comment}{! The rest of the model defines grids integrating up from the bottom}}
\DoxyCodeLine{164     z\_interface(cs\%nk+1) = -\/depth}
\DoxyCodeLine{165     \textcolor{keywordflow}{do} k = cs\%nk,1,-\/1}
\DoxyCodeLine{166       z\_interface(k) = z\_interface(k+1) + h\_new(k)}
\DoxyCodeLine{167 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{168 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{169 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__rho_ad79c2a471c8de0b16f0478813be7c29f}\label{namespacecoord__rho_ad79c2a471c8de0b16f0478813be7c29f}} 
\index{coord\_rho@{coord\_rho}!build\_rho\_column\_iteratively@{build\_rho\_column\_iteratively}}
\index{build\_rho\_column\_iteratively@{build\_rho\_column\_iteratively}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{build\_rho\_column\_iteratively()}{build\_rho\_column\_iteratively()}}
{\footnotesize\ttfamily subroutine coord\+\_\+rho\+::build\+\_\+rho\+\_\+column\+\_\+iteratively (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__rho_1_1rho__cs}{rho\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(remapping\+\_\+cs), intent(in)}]{remap\+CS,  }\item[{integer, intent(in)}]{nz,  }\item[{real, intent(in)}]{depth,  }\item[{real, dimension(nz), intent(in)}]{h,  }\item[{real, dimension(nz), intent(in)}]{T,  }\item[{real, dimension(nz), intent(in)}]{S,  }\item[{type(eos\+\_\+type), pointer}]{eqn\+\_\+of\+\_\+state,  }\item[{real, dimension(nz+1), intent(inout)}]{z\+Interface,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge,  }\item[{real, intent(in), optional}]{dev\+\_\+tol }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Iteratively build a rho coordinate column. 

The algorithm operates as follows within each column\+:


\begin{DoxyEnumerate}
\item Given T \& S within each layer, the layer densities are computed.
\item Based on these layer densities, a global density profile is reconstructed (this profile is monotonically increasing and may be discontinuous)
\item The new grid interfaces are determined based on the target interface densities.
\item T \& S are remapped onto the new grid.
\item Return to step 1 until convergence or until the maximum number of iterations is reached, whichever comes first. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Regridding control structure \\
\hline
\mbox{\texttt{ in}}  & {\em remapcs} & Remapping parameters and options \\
\hline
\mbox{\texttt{ in}}  & {\em nz} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em depth} & Depth of ocean bottom \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses in Z coordinates \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t} & T for column \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s} & S for column \mbox{[}ppt\mbox{]} \\
\hline
 & {\em eqn\+\_\+of\+\_\+state} & Equation of state structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em zinterface} & Absolute positions of interfaces \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations in the same units as h \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dev\+\_\+tol} & The tolerance for the deviation between successive grids for determining when the iterative solver has converged \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\end{DoxyParams}

\end{DoxyEnumerate}

Definition at line 186 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{188   \textcolor{keywordtype}{type}(rho\_CS),          \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< Regridding control structure}}
\DoxyCodeLine{189   \textcolor{keywordtype}{type}(remapping\_CS),    \textcolor{keywordtype}{intent(in)}    :: remapCS\textcolor{comment}{ !< Remapping parameters and options}}
\DoxyCodeLine{190   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{ !< Number of levels}}
\DoxyCodeLine{191 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{ !< Depth of ocean bottom [Z \string~> m]}}
\DoxyCodeLine{192 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses in Z coordinates [Z \string~> m]}}
\DoxyCodeLine{193 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: T\textcolor{comment}{  !< T for column [degC]}}
\DoxyCodeLine{194 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: S\textcolor{comment}{  !< S for column [ppt]}}
\DoxyCodeLine{195   \textcolor{keywordtype}{type}(EOS\_type),        \textcolor{keywordtype}{pointer}       :: eqn\_of\_state\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{196 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(inout)} :: zInterface\textcolor{comment}{ !< Absolute positions of interfaces}}
\DoxyCodeLine{197 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}}
\DoxyCodeLine{198 \textcolor{comment}{                                             !! purpose of cell reconstructions}}
\DoxyCodeLine{199 \textcolor{comment}{                                             !! in the same units as h [Z \string~> m]}}
\DoxyCodeLine{200 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}}
\DoxyCodeLine{201 \textcolor{comment}{                                             !! for the purpose of edge value calculations}}
\DoxyCodeLine{202 \textcolor{comment}{                                             !! in the same units as h [Z \string~> m]}}
\DoxyCodeLine{203 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: dev\_tol\textcolor{comment}{ !< The tolerance for the deviation between}}
\DoxyCodeLine{204 \textcolor{comment}{                                             !! successive grids for determining when the}}
\DoxyCodeLine{205 \textcolor{comment}{                                             !! iterative solver has converged [Z \string~> m]}}
\DoxyCodeLine{206 }
\DoxyCodeLine{207   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{208 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: x0, x1, xTmp \textcolor{comment}{! Temporary interface heights [Z \string~> m]}}
\DoxyCodeLine{209 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: pres       \textcolor{comment}{! The pressure used in the equation of state [R L2 T-\/2 \string~> Pa].}}
\DoxyCodeLine{210 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: densities  \textcolor{comment}{! Layer densities [R \string~> kg m-\/3]}}
\DoxyCodeLine{211 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: T\_tmp, S\_tmp \textcolor{comment}{! A temporary profile of temperature [degC] and salinity [ppt].}}
\DoxyCodeLine{212 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: Tmp        \textcolor{comment}{! A temporary variable holding a remapped variable.}}
\DoxyCodeLine{213 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: h0, h1, hTmp \textcolor{comment}{! Temporary thicknesses [Z \string~> m]}}
\DoxyCodeLine{214 \textcolor{keywordtype}{  real} :: deviation            \textcolor{comment}{! When iterating to determine the final grid, this is the}}
\DoxyCodeLine{215                                \textcolor{comment}{! deviation between two successive grids [Z \string~> m].}}
\DoxyCodeLine{216 \textcolor{keywordtype}{  real} :: deviation\_tol        \textcolor{comment}{! Deviation tolerance between succesive grids in}}
\DoxyCodeLine{217                                \textcolor{comment}{! regridding iterations [Z \string~> m]}}
\DoxyCodeLine{218 \textcolor{keywordtype}{  real} :: threshold            \textcolor{comment}{! The minimum thickness for a layer to be considered to exist [Z \string~> m]}}
\DoxyCodeLine{219   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nz)} :: mapping \textcolor{comment}{! The indices of the massive layers in the initial column.}}
\DoxyCodeLine{220   \textcolor{keywordtype}{integer} :: k, m, count\_nonzero\_layers}
\DoxyCodeLine{221 }
\DoxyCodeLine{222   \textcolor{comment}{!  Maximum number of regridding iterations}}
\DoxyCodeLine{223   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: NB\_REGRIDDING\_ITERATIONS = 1}
\DoxyCodeLine{224 }
\DoxyCodeLine{225   threshold = cs\%min\_thickness}
\DoxyCodeLine{226   pres(:) = cs\%ref\_pressure}
\DoxyCodeLine{227   t\_tmp(:) = t(:)}
\DoxyCodeLine{228   s\_tmp(:) = s(:)}
\DoxyCodeLine{229   h0(:) = h(:)}
\DoxyCodeLine{230 }
\DoxyCodeLine{231   \textcolor{comment}{! Start iterations to build grid}}
\DoxyCodeLine{232   m = 1}
\DoxyCodeLine{233   deviation\_tol = 1.0e-\/15*depth ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dev\_tol)) deviation\_tol = dev\_tol}
\DoxyCodeLine{234 }
\DoxyCodeLine{235   \textcolor{keywordflow}{do} m=1,nb\_regridding\_iterations}
\DoxyCodeLine{236 }
\DoxyCodeLine{237     \textcolor{comment}{! Construct column with vanished layers removed}}
\DoxyCodeLine{238     \textcolor{keyword}{call }copy\_finite\_thicknesses(nz, h0, threshold, count\_nonzero\_layers, htmp, mapping)}
\DoxyCodeLine{239     \textcolor{keywordflow}{if} ( count\_nonzero\_layers <= 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{240       h1(:) = h0(:)}
\DoxyCodeLine{241       \textcolor{keywordflow}{exit}  \textcolor{comment}{! stop iterations here}}
\DoxyCodeLine{242 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{243 }
\DoxyCodeLine{244     xtmp(1) = 0.0}
\DoxyCodeLine{245     \textcolor{keywordflow}{do} k = 1,count\_nonzero\_layers}
\DoxyCodeLine{246       xtmp(k+1) = xtmp(k) + htmp(k)}
\DoxyCodeLine{247 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{248 }
\DoxyCodeLine{249     \textcolor{comment}{! Compute densities within current water column}}
\DoxyCodeLine{250     \textcolor{keyword}{call }calculate\_density( t\_tmp, s\_tmp, pres, densities, eqn\_of\_state)}
\DoxyCodeLine{251 }
\DoxyCodeLine{252     \textcolor{keywordflow}{do} k = 1,count\_nonzero\_layers}
\DoxyCodeLine{253       densities(k) = densities(mapping(k))}
\DoxyCodeLine{254 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{255 }
\DoxyCodeLine{256     \textcolor{comment}{! One regridding iteration}}
\DoxyCodeLine{257     \textcolor{comment}{! Based on global density profile, interpolate to generate a new grid}}
\DoxyCodeLine{258     \textcolor{keyword}{call }build\_and\_interpolate\_grid(cs\%interp\_CS, densities, count\_nonzero\_layers, \&}
\DoxyCodeLine{259          htmp, xtmp, cs\%target\_density, nz, h1, x1, h\_neglect, h\_neglect\_edge)}
\DoxyCodeLine{260 }
\DoxyCodeLine{261     \textcolor{keyword}{call }old\_inflate\_layers\_1d( cs\%min\_thickness, nz, h1 )}
\DoxyCodeLine{262     x1(1) = 0.0 ; \textcolor{keywordflow}{do} k = 1,nz ; x1(k+1) = x1(k) + h1(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{263 }
\DoxyCodeLine{264     \textcolor{comment}{! Remap T and S from previous grid to new grid}}
\DoxyCodeLine{265     \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{266       h1(k) = x1(k+1) -\/ x1(k)}
\DoxyCodeLine{267 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{268 }
\DoxyCodeLine{269     \textcolor{keyword}{call }remapping\_core\_h(remapcs, nz, h0, s, nz, h1, tmp, h\_neglect, h\_neglect\_edge)}
\DoxyCodeLine{270     s\_tmp(:) = tmp(:)}
\DoxyCodeLine{271 }
\DoxyCodeLine{272     \textcolor{keyword}{call }remapping\_core\_h(remapcs, nz, h0, t, nz, h1, tmp, h\_neglect, h\_neglect\_edge)}
\DoxyCodeLine{273     t\_tmp(:) = tmp(:)}
\DoxyCodeLine{274 }
\DoxyCodeLine{275     \textcolor{comment}{! Compute the deviation between two successive grids}}
\DoxyCodeLine{276     deviation = 0.0}
\DoxyCodeLine{277     x0(1) = 0.0}
\DoxyCodeLine{278     x1(1) = 0.0}
\DoxyCodeLine{279     \textcolor{keywordflow}{do} k = 2,nz}
\DoxyCodeLine{280       x0(k) = x0(k-\/1) + h0(k-\/1)}
\DoxyCodeLine{281       x1(k) = x1(k-\/1) + h1(k-\/1)}
\DoxyCodeLine{282       deviation = deviation + (x0(k)-\/x1(k))**2}
\DoxyCodeLine{283 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{284     deviation = sqrt( deviation / (nz-\/1) )}
\DoxyCodeLine{285 }
\DoxyCodeLine{286     \textcolor{keywordflow}{if} ( deviation <= deviation\_tol ) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{287 }
\DoxyCodeLine{288     \textcolor{comment}{! Copy final grid onto start grid for next iteration}}
\DoxyCodeLine{289     h0(:) = h1(:)}
\DoxyCodeLine{290 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end regridding iterations}}
\DoxyCodeLine{291 }
\DoxyCodeLine{292   \textcolor{keywordflow}{if} (cs\%integrate\_downward\_for\_e) \textcolor{keywordflow}{then}}
\DoxyCodeLine{293     zinterface(1) = 0.}
\DoxyCodeLine{294     \textcolor{keywordflow}{do} k = 1,nz}
\DoxyCodeLine{295       zinterface(k+1) = zinterface(k) -\/ h1(k)}
\DoxyCodeLine{296       \textcolor{comment}{! Adjust interface position to accommodate inflating layers}}
\DoxyCodeLine{297       \textcolor{comment}{! without disturbing the interface above}}
\DoxyCodeLine{298 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{299   \textcolor{keywordflow}{else}}
\DoxyCodeLine{300     \textcolor{comment}{! The rest of the model defines grids integrating up from the bottom}}
\DoxyCodeLine{301     zinterface(nz+1) = -\/depth}
\DoxyCodeLine{302     \textcolor{keywordflow}{do} k = nz,1,-\/1}
\DoxyCodeLine{303       zinterface(k) = zinterface(k+1) + h1(k)}
\DoxyCodeLine{304       \textcolor{comment}{! Adjust interface position to accommodate inflating layers}}
\DoxyCodeLine{305       \textcolor{comment}{! without disturbing the interface above}}
\DoxyCodeLine{306 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{307 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{308 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__rho_a17064808dccea1f725fe82cd49cd2541}\label{namespacecoord__rho_a17064808dccea1f725fe82cd49cd2541}} 
\index{coord\_rho@{coord\_rho}!copy\_finite\_thicknesses@{copy\_finite\_thicknesses}}
\index{copy\_finite\_thicknesses@{copy\_finite\_thicknesses}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{copy\_finite\_thicknesses()}{copy\_finite\_thicknesses()}}
{\footnotesize\ttfamily subroutine coord\+\_\+rho\+::copy\+\_\+finite\+\_\+thicknesses (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{h\+\_\+in,  }\item[{real, intent(in)}]{thresh,  }\item[{integer, intent(out)}]{nout,  }\item[{real, dimension(nk), intent(out)}]{h\+\_\+out,  }\item[{integer, dimension(nk), intent(out)}]{mapping }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Copy column thicknesses with vanished layers removed. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nk} & Number of layer for h\+\_\+in, T\+\_\+in, S\+\_\+in \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Thickness of input column \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} or \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em thresh} & Thickness threshold defining vanished layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} or \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em nout} & Number of non-\/vanished layers \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+out} & Thickness of output column \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} or \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em mapping} & Index of k-\/out corresponding to k-\/in \\
\hline
\end{DoxyParams}


Definition at line 312 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{313   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}  :: nk\textcolor{comment}{      !< Number of layer for h\_in, T\_in, S\_in}}
\DoxyCodeLine{314 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},    \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{    !< Thickness of input column [H \string~> m or kg m-\/2] or [Z \string~> m]}}
\DoxyCodeLine{315 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{intent(in)}  :: thresh\textcolor{comment}{  !< Thickness threshold defining vanished}}
\DoxyCodeLine{316 \textcolor{comment}{                                                 !! layers [H \string~> m or kg m-\/2] or [Z \string~> m]}}
\DoxyCodeLine{317   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(out)} :: nout\textcolor{comment}{    !< Number of non-\/vanished layers}}
\DoxyCodeLine{318 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},    \textcolor{keywordtype}{intent(out)} :: h\_out\textcolor{comment}{   !< Thickness of output column [H \string~> m or kg m-\/2] or [Z \string~> m]}}
\DoxyCodeLine{319   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(out)} :: mapping\textcolor{comment}{ !< Index of k-\/out corresponding to k-\/in}}
\DoxyCodeLine{320   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{321   \textcolor{keywordtype}{integer} :: k, k\_thickest}
\DoxyCodeLine{322 \textcolor{keywordtype}{  real} :: thickness\_in\_vanished \textcolor{comment}{! Summed thicknesses in discarded layers [H \string~> m or kg m-\/2] or [Z \string~> m]}}
\DoxyCodeLine{323 \textcolor{keywordtype}{  real} :: thickest\_h\_out        \textcolor{comment}{! Thickness of the thickest layer [H \string~> m or kg m-\/2] or [Z \string~> m]}}
\DoxyCodeLine{324 }
\DoxyCodeLine{325   \textcolor{comment}{! Build up new grid}}
\DoxyCodeLine{326   nout = 0}
\DoxyCodeLine{327   thickness\_in\_vanished = 0.0}
\DoxyCodeLine{328   thickest\_h\_out = h\_in(1)}
\DoxyCodeLine{329   k\_thickest = 1}
\DoxyCodeLine{330   \textcolor{keywordflow}{do} k = 1, nk}
\DoxyCodeLine{331     mapping(k) = nout \textcolor{comment}{! Note k>=nout always}}
\DoxyCodeLine{332     h\_out(k) = 0.  \textcolor{comment}{! Make sure h\_out is set everywhere}}
\DoxyCodeLine{333     \textcolor{keywordflow}{if} (h\_in(k) > thresh) \textcolor{keywordflow}{then}}
\DoxyCodeLine{334       \textcolor{comment}{! For non-\/vanished layers}}
\DoxyCodeLine{335       nout = nout + 1}
\DoxyCodeLine{336       mapping(nout) = k}
\DoxyCodeLine{337       h\_out(nout) = h\_in(k)}
\DoxyCodeLine{338       \textcolor{keywordflow}{if} (h\_out(nout) > thickest\_h\_out) \textcolor{keywordflow}{then}}
\DoxyCodeLine{339         thickest\_h\_out = h\_out(nout)}
\DoxyCodeLine{340         k\_thickest = nout}
\DoxyCodeLine{341 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{342     \textcolor{keywordflow}{else}}
\DoxyCodeLine{343       \textcolor{comment}{! Add up mass in vanished layers}}
\DoxyCodeLine{344       thickness\_in\_vanished = thickness\_in\_vanished + h\_in(k)}
\DoxyCodeLine{345 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{346 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{347 }
\DoxyCodeLine{348   \textcolor{comment}{! No finite layers}}
\DoxyCodeLine{349   \textcolor{keywordflow}{if} (nout <= 1) \textcolor{keywordflow}{return}}
\DoxyCodeLine{350 }
\DoxyCodeLine{351   \textcolor{comment}{! Adjust for any lost volume in vanished layers}}
\DoxyCodeLine{352   h\_out(k\_thickest) = h\_out(k\_thickest) + thickness\_in\_vanished}
\DoxyCodeLine{353 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__rho_a8e9c666d47d847ab8b64a22c470931d1}\label{namespacecoord__rho_a8e9c666d47d847ab8b64a22c470931d1}} 
\index{coord\_rho@{coord\_rho}!end\_coord\_rho@{end\_coord\_rho}}
\index{end\_coord\_rho@{end\_coord\_rho}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{end\_coord\_rho()}{end\_coord\_rho()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+rho\+::end\+\_\+coord\+\_\+rho (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__rho_1_1rho__cs}{rho\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine deallocates memory in the control structure for the \mbox{\hyperlink{namespacecoord__rho}{coord\+\_\+rho}} module. 


\begin{DoxyParams}{Parameters}
{\em cs} & Coordinate control structure \\
\hline
\end{DoxyParams}


Definition at line 60 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{61   \textcolor{keywordtype}{type}(rho\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Coordinate control structure}}
\DoxyCodeLine{62 }
\DoxyCodeLine{63   \textcolor{comment}{! nothing to do}}
\DoxyCodeLine{64   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{65   \textcolor{keyword}{deallocate}(cs\%target\_density)}
\DoxyCodeLine{66   \textcolor{keyword}{deallocate}(cs)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__rho_a86640b2be846b291c71f1c38b8ff9878}\label{namespacecoord__rho_a86640b2be846b291c71f1c38b8ff9878}} 
\index{coord\_rho@{coord\_rho}!init\_coord\_rho@{init\_coord\_rho}}
\index{init\_coord\_rho@{init\_coord\_rho}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{init\_coord\_rho()}{init\_coord\_rho()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+rho\+::init\+\_\+coord\+\_\+rho (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__rho_1_1rho__cs}{rho\+\_\+cs}}), pointer}]{CS,  }\item[{integer, intent(in)}]{nk,  }\item[{real, intent(in)}]{ref\+\_\+pressure,  }\item[{real, dimension(\+:), intent(in)}]{target\+\_\+density,  }\item[{type(interp\+\_\+cs\+\_\+type), intent(in)}]{interp\+\_\+\+CS }\end{DoxyParamCaption})}



Initialise a rho\+\_\+\+CS with pointers to parameters. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Unassociated pointer to hold the control structure \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers in the grid \\
\hline
\mbox{\texttt{ in}}  & {\em ref\+\_\+pressure} & Coordinate reference pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em target\+\_\+density} & Nominal density of interfaces \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em interp\+\_\+cs} & Controls for interpolation \\
\hline
\end{DoxyParams}


Definition at line 41 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{42   \textcolor{keywordtype}{type}(rho\_CS),         \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Unassociated pointer to hold the control structure}}
\DoxyCodeLine{43   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{ !< Number of layers in the grid}}
\DoxyCodeLine{44 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)} :: ref\_pressure\textcolor{comment}{ !< Coordinate reference pressure [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{45 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)} :: target\_density\textcolor{comment}{ !< Nominal density of interfaces [R \string~> kg m-\/3]}}
\DoxyCodeLine{46   \textcolor{keywordtype}{type}(interp\_CS\_type), \textcolor{keywordtype}{intent(in)} :: interp\_CS\textcolor{comment}{ !< Controls for interpolation}}
\DoxyCodeLine{47 }
\DoxyCodeLine{48   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"init\_coord\_rho: CS already associated!"})}
\DoxyCodeLine{49   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{50   \textcolor{keyword}{allocate}(cs\%target\_density(nk+1))}
\DoxyCodeLine{51 }
\DoxyCodeLine{52   cs\%nk                = nk}
\DoxyCodeLine{53   cs\%ref\_pressure      = ref\_pressure}
\DoxyCodeLine{54   cs\%target\_density(:) = target\_density(:)}
\DoxyCodeLine{55   cs\%interp\_CS         = interp\_cs}
\DoxyCodeLine{56 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__rho_afbc86f29df8e39eb793d12075d018518}\label{namespacecoord__rho_afbc86f29df8e39eb793d12075d018518}} 
\index{coord\_rho@{coord\_rho}!old\_inflate\_layers\_1d@{old\_inflate\_layers\_1d}}
\index{old\_inflate\_layers\_1d@{old\_inflate\_layers\_1d}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{old\_inflate\_layers\_1d()}{old\_inflate\_layers\_1d()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+rho\+::old\+\_\+inflate\+\_\+layers\+\_\+1d (\begin{DoxyParamCaption}\item[{real, intent(in)}]{min\+\_\+thickness,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(\+:), intent(inout)}]{h }\end{DoxyParamCaption})}



Inflate vanished layers to finite (nonzero) width. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em min\+\_\+thickness} & Minimum allowed thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers in the grid \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 358 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{359 }
\DoxyCodeLine{360   \textcolor{comment}{! Argument}}
\DoxyCodeLine{361 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)}    :: min\_thickness\textcolor{comment}{ !< Minimum allowed thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{362   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{  !< Number of layers in the grid}}
\DoxyCodeLine{363 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Layer thicknesses [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{364 }
\DoxyCodeLine{365   \textcolor{comment}{! Local variable}}
\DoxyCodeLine{366   \textcolor{keywordtype}{integer}   :: k}
\DoxyCodeLine{367   \textcolor{keywordtype}{integer}   :: k\_found}
\DoxyCodeLine{368   \textcolor{keywordtype}{integer}   :: count\_nonzero\_layers}
\DoxyCodeLine{369 \textcolor{keywordtype}{  real}      :: delta}
\DoxyCodeLine{370 \textcolor{keywordtype}{  real}      :: correction}
\DoxyCodeLine{371 \textcolor{keywordtype}{  real}      :: maxThickness}
\DoxyCodeLine{372 }
\DoxyCodeLine{373   \textcolor{comment}{! Count number of nonzero layers}}
\DoxyCodeLine{374   count\_nonzero\_layers = 0}
\DoxyCodeLine{375   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{376     \textcolor{keywordflow}{if} ( h(k) > min\_thickness ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{377       count\_nonzero\_layers = count\_nonzero\_layers + 1}
\DoxyCodeLine{378 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{379 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{380 }
\DoxyCodeLine{381   \textcolor{comment}{! If all layer thicknesses are greater than the threshold, exit routine}}
\DoxyCodeLine{382   \textcolor{keywordflow}{if} ( count\_nonzero\_layers == nk ) \textcolor{keywordflow}{return}}
\DoxyCodeLine{383 }
\DoxyCodeLine{384   \textcolor{comment}{! If all thicknesses are zero, inflate them all and exit}}
\DoxyCodeLine{385   \textcolor{keywordflow}{if} ( count\_nonzero\_layers == 0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{386     \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{387       h(k) = min\_thickness}
\DoxyCodeLine{388 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{389     \textcolor{keywordflow}{return}}
\DoxyCodeLine{390 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{391 }
\DoxyCodeLine{392   \textcolor{comment}{! Inflate zero layers}}
\DoxyCodeLine{393   correction = 0.0}
\DoxyCodeLine{394   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{395     \textcolor{keywordflow}{if} ( h(k) <= min\_thickness ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{396       delta = min\_thickness -\/ h(k)}
\DoxyCodeLine{397       correction = correction + delta}
\DoxyCodeLine{398       h(k) = h(k) + delta}
\DoxyCodeLine{399 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{400 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{401 }
\DoxyCodeLine{402   \textcolor{comment}{! Modify thicknesses of nonzero layers to ensure volume conservation}}
\DoxyCodeLine{403   maxthickness = h(1)}
\DoxyCodeLine{404   k\_found = 1}
\DoxyCodeLine{405   \textcolor{keywordflow}{do} k = 1,nk}
\DoxyCodeLine{406     \textcolor{keywordflow}{if} ( h(k) > maxthickness ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{407       maxthickness = h(k)}
\DoxyCodeLine{408       k\_found = k}
\DoxyCodeLine{409 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{410 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{411 }
\DoxyCodeLine{412   h(k\_found) = h(k\_found) -\/ correction}
\DoxyCodeLine{413 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__rho_a6b2a48523247f59c7b4b5b7941334c25}\label{namespacecoord__rho_a6b2a48523247f59c7b4b5b7941334c25}} 
\index{coord\_rho@{coord\_rho}!set\_rho\_params@{set\_rho\_params}}
\index{set\_rho\_params@{set\_rho\_params}!coord\_rho@{coord\_rho}}
\doxysubsubsection{\texorpdfstring{set\_rho\_params()}{set\_rho\_params()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+rho\+::set\+\_\+rho\+\_\+params (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__rho_1_1rho__cs}{rho\+\_\+cs}}), pointer}]{CS,  }\item[{real, intent(in), optional}]{min\+\_\+thickness,  }\item[{logical, intent(in), optional}]{integrate\+\_\+downward\+\_\+for\+\_\+e,  }\item[{type(interp\+\_\+cs\+\_\+type), intent(in), optional}]{interp\+\_\+\+CS }\end{DoxyParamCaption})}



This subroutine can be used to set the parameters for the \mbox{\hyperlink{namespacecoord__rho}{coord\+\_\+rho}} module. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Coordinate control structure \\
\hline
\mbox{\texttt{ in}}  & {\em min\+\_\+thickness} & Minimum allowed thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em integrate\+\_\+downward\+\_\+for\+\_\+e} & If true, integrate for interface positions from the top downward. If false, integrate from the bottom upward, as does the rest of the model. \\
\hline
\mbox{\texttt{ in}}  & {\em interp\+\_\+cs} & Controls for interpolation \\
\hline
\end{DoxyParams}


Definition at line 70 of file coord\+\_\+rho.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{71   \textcolor{keywordtype}{type}(rho\_CS),      \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Coordinate control structure}}
\DoxyCodeLine{72 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: min\_thickness\textcolor{comment}{ !< Minimum allowed thickness [H \string~> m or kg m-\/2]}}
\DoxyCodeLine{73   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: integrate\_downward\_for\_e\textcolor{comment}{ !< If true, integrate for interface}}
\DoxyCodeLine{74 \textcolor{comment}{                                      !! positions from the top downward.  If false, integrate}}
\DoxyCodeLine{75 \textcolor{comment}{                                      !! from the bottom upward, as does the rest of the model.}}
\DoxyCodeLine{76 }
\DoxyCodeLine{77   \textcolor{keywordtype}{type}(interp\_CS\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: interp\_CS\textcolor{comment}{ !< Controls for interpolation}}
\DoxyCodeLine{78 }
\DoxyCodeLine{79   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_rho\_params: CS not associated"})}
\DoxyCodeLine{80 }
\DoxyCodeLine{81   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) cs\%min\_thickness = min\_thickness}
\DoxyCodeLine{82   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(integrate\_downward\_for\_e)) cs\%integrate\_downward\_for\_e = integrate\_downward\_for\_e}
\DoxyCodeLine{83   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(interp\_cs)) cs\%interp\_CS = interp\_cs}

\end{DoxyCode}
