\hypertarget{namespacecoord__slight}{}\doxysection{coord\+\_\+slight Module Reference}
\label{namespacecoord__slight}\index{coord\_slight@{coord\_slight}}


\doxysubsection{Detailed Description}
Regrid columns for the S\+Light coordinate. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structcoord__slight_1_1slight__cs}{slight\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure containing required parameters for the S\+Light coordinate. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacecoord__slight_afe3fb682e16b96d441d380635a983040}{init\+\_\+coord\+\_\+slight}} (CS, nk, ref\+\_\+pressure, target\+\_\+density, interp\+\_\+\+CS, m\+\_\+to\+\_\+H)
\begin{DoxyCompactList}\small\item\em Initialise a slight\+\_\+\+CS with pointers to parameters. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__slight_af5e8c8c13ad380620be3d8907738ed38}{end\+\_\+coord\+\_\+slight}} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates memory in the control structure for the \mbox{\hyperlink{namespacecoord__slight}{coord\+\_\+slight}} module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__slight_a5ffc8589603f020d1d5af03cfd308154}{set\+\_\+slight\+\_\+params}} (CS, max\+\_\+interface\+\_\+depths, max\+\_\+layer\+\_\+thickness, min\+\_\+thickness, compressibility\+\_\+fraction, dz\+\_\+ml\+\_\+min, nz\+\_\+fixed\+\_\+surface, Rho\+\_\+\+M\+L\+\_\+avg\+\_\+depth, nlay\+\_\+\+M\+L\+\_\+offset, fix\+\_\+haloclines, halocline\+\_\+filter\+\_\+length, halocline\+\_\+strat\+\_\+tol, interp\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em This subroutine can be used to set the parameters for the \mbox{\hyperlink{namespacecoord__slight}{coord\+\_\+slight}} module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacecoord__slight_a5f58a9ec734faa72781a86ff57e482f9}{build\+\_\+slight\+\_\+column}} (CS, eqn\+\_\+of\+\_\+state, H\+\_\+to\+\_\+pres, H\+\_\+subroundoff, nz, depth, h\+\_\+col, T\+\_\+col, S\+\_\+col, p\+\_\+col, z\+\_\+col, z\+\_\+col\+\_\+new, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Build a S\+Light coordinate column. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacecoord__slight_a20af96022abf0d0f4ecb17dde027b2d1}{rho\+\_\+interfaces\+\_\+col}} (rho\+\_\+col, h\+\_\+col, z\+\_\+col, rho\+\_\+tgt, nz, z\+\_\+col\+\_\+new, CS, reliable, debug, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Finds the new interface locations in a column of water that match the prescribed target densities. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacecoord__slight_a5f58a9ec734faa72781a86ff57e482f9}\label{namespacecoord__slight_a5f58a9ec734faa72781a86ff57e482f9}} 
\index{coord\_slight@{coord\_slight}!build\_slight\_column@{build\_slight\_column}}
\index{build\_slight\_column@{build\_slight\_column}!coord\_slight@{coord\_slight}}
\doxysubsubsection{\texorpdfstring{build\_slight\_column()}{build\_slight\_column()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+slight\+::build\+\_\+slight\+\_\+column (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__slight_1_1slight__cs}{slight\+\_\+cs}}), intent(in)}]{CS,  }\item[{type(eos\+\_\+type), pointer}]{eqn\+\_\+of\+\_\+state,  }\item[{real, intent(in)}]{H\+\_\+to\+\_\+pres,  }\item[{real, intent(in)}]{H\+\_\+subroundoff,  }\item[{integer, intent(in)}]{nz,  }\item[{real, intent(in)}]{depth,  }\item[{real, dimension(nz), intent(in)}]{h\+\_\+col,  }\item[{real, dimension(nz), intent(in)}]{T\+\_\+col,  }\item[{real, dimension(nz), intent(in)}]{S\+\_\+col,  }\item[{real, dimension(nz), intent(in)}]{p\+\_\+col,  }\item[{real, dimension(nz+1), intent(in)}]{z\+\_\+col,  }\item[{real, dimension(nz+1), intent(inout)}]{z\+\_\+col\+\_\+new,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Build a S\+Light coordinate column. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em cs} & Coordinate control structure \\
\hline
 & {\em eqn\+\_\+of\+\_\+state} & Equation of state structure \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+to\+\_\+pres} & A conversion factor from thicknesses to scaled pressure \mbox{[}R L2 T-\/2 H-\/1 $\sim$$>$ Pa m-\/1 or Pa m2 kg-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+subroundoff} & GVH\+\_\+subroundoff \\
\hline
\mbox{\texttt{ in}}  & {\em nz} & Number of levels \\
\hline
\mbox{\texttt{ in}}  & {\em depth} & Depth of ocean bottom (positive \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}) \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+col} & T for column \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+col} & S for column \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+col} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+col} & Layer center pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+col} & Interface positions relative to the surface \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em z\+\_\+col\+\_\+new} & Absolute positions of interfaces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\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}


Definition at line 183 of file coord\+\_\+slight.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{183   \textcolor{keywordtype}{type}(slight\_CS),       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{    !< Coordinate control structure}}
\DoxyCodeLine{184   \textcolor{keywordtype}{type}(EOS\_type),        \textcolor{keywordtype}{pointer}       :: eqn\_of\_state\textcolor{comment}{ !< Equation of state structure}}
\DoxyCodeLine{185 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: H\_to\_pres\textcolor{comment}{ !< A conversion factor from thicknesses to}}
\DoxyCodeLine{186 \textcolor{comment}{                                                !! scaled pressure [R L2 T-\/2 H-\/1 ~> Pa m-\/1 or Pa m2 kg-\/1]}}
\DoxyCodeLine{187 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: H\_subroundoff\textcolor{comment}{ !< GV\%H\_subroundoff}}
\DoxyCodeLine{188   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{    !< Number of levels}}
\DoxyCodeLine{189 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{ !< Depth of ocean bottom (positive [H ~> m or kg m-\/2])}}
\DoxyCodeLine{190 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: T\_col\textcolor{comment}{ !< T for column}}
\DoxyCodeLine{191 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: S\_col\textcolor{comment}{ !< S for column}}
\DoxyCodeLine{192 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: h\_col\textcolor{comment}{ !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{193 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: p\_col\textcolor{comment}{ !< Layer center pressure [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{194 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(in)}    :: z\_col\textcolor{comment}{ !< Interface positions relative to the surface [H ~> m or kg m-\/2]}}
\DoxyCodeLine{195 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(inout)} :: z\_col\_new\textcolor{comment}{ !< Absolute positions of interfaces [H ~> m or kg m-\/2]}}
\DoxyCodeLine{196 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the purpose of}}
\DoxyCodeLine{197 \textcolor{comment}{                                                !! cell reconstructions [H ~> m or kg m-\/2].}}
\DoxyCodeLine{198 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width for the purpose}}
\DoxyCodeLine{199 \textcolor{comment}{                                                !! of edge value calculations [H ~> m or kg m-\/2].}}
\DoxyCodeLine{200   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{201 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: rho\_col        \textcolor{comment}{! Layer densities [R ~> kg m-\/3]}}
\DoxyCodeLine{202 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: T\_f, S\_f       \textcolor{comment}{! Filtered layer temperature [degC] and salinity [ppt]}}
\DoxyCodeLine{203   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nz+1)} :: reliable  \textcolor{comment}{! If true, this interface is in a reliable position.}}
\DoxyCodeLine{204 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: T\_int, S\_int \textcolor{comment}{! Temperature [degC] and salinity [ppt] interpolated to interfaces.}}
\DoxyCodeLine{205 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: rho\_tmp      \textcolor{comment}{! A temporary density [R ~> kg m-\/3]}}
\DoxyCodeLine{206 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: drho\_dp      \textcolor{comment}{! The partial derivative of density with pressure [T2 L-\/2 ~> kg m-\/3 Pa-\/1]}}
\DoxyCodeLine{207 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: p\_IS, p\_R    \textcolor{comment}{! Pressures [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{208 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: drhoIS\_dT    \textcolor{comment}{! The partial derivative of in situ density with temperature}}
\DoxyCodeLine{209                                         \textcolor{comment}{! in [R degC-\/1 ~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{210 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: drhoIS\_dS    \textcolor{comment}{! The partial derivative of in situ density with salinity}}
\DoxyCodeLine{211                                         \textcolor{comment}{! in [R ppt-\/1 ~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{212 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: drhoR\_dT     \textcolor{comment}{! The partial derivative of reference density with temperature}}
\DoxyCodeLine{213                                         \textcolor{comment}{! in [R degC-\/1 ~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{214 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: drhoR\_dS     \textcolor{comment}{! The partial derivative of reference density with salinity}}
\DoxyCodeLine{215                                         \textcolor{comment}{! in [R ppt-\/1 ~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{216 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: strat\_rat}
\DoxyCodeLine{217 \textcolor{keywordtype}{  real} :: H\_to\_cPa    \textcolor{comment}{! A conversion factor from thicknesses to the compressibility fraction times}}
\DoxyCodeLine{218                       \textcolor{comment}{! the units of pressure [R L2 T-\/2 H-\/1 ~> Pa m-\/1 or Pa m2 kg-\/1]}}
\DoxyCodeLine{219 \textcolor{keywordtype}{  real} :: drIS, drR   \textcolor{comment}{! In situ and reference density differences [R ~> kg m-\/3]}}
\DoxyCodeLine{220 \textcolor{keywordtype}{  real} :: Fn\_now, I\_HStol, Fn\_zero\_val \textcolor{comment}{! Nondimensional variables [nondim]}}
\DoxyCodeLine{221 \textcolor{keywordtype}{  real} :: z\_int\_unst  \textcolor{comment}{! The depth where the stratification allows the interior grid to start [H ~> m or kg m-\/2]}}
\DoxyCodeLine{222 \textcolor{keywordtype}{  real} :: dz          \textcolor{comment}{! A uniform layer thickness in very shallow water [H ~> m or kg m-\/2].}}
\DoxyCodeLine{223 \textcolor{keywordtype}{  real} :: dz\_ur       \textcolor{comment}{! The total thickness of an unstable region [H ~> m or kg m-\/2].}}
\DoxyCodeLine{224 \textcolor{keywordtype}{  real} :: wgt, cowgt  \textcolor{comment}{! A weight and its complement [nondim].}}
\DoxyCodeLine{225 \textcolor{keywordtype}{  real} :: rho\_ml\_av   \textcolor{comment}{! The average potential density in a near-\/surface region [R ~> kg m-\/3].}}
\DoxyCodeLine{226 \textcolor{keywordtype}{  real} :: H\_ml\_av     \textcolor{comment}{! A thickness to try to use in taking the near-\/surface average [H ~> m or kg m-\/2].}}
\DoxyCodeLine{227 \textcolor{keywordtype}{  real} :: rho\_x\_z     \textcolor{comment}{! A cumulative integral of a density [R H ~> kg m-\/2 or kg2 m-\/5].}}
\DoxyCodeLine{228 \textcolor{keywordtype}{  real} :: z\_wt        \textcolor{comment}{! The thickness actually used in taking the near-\/surface average [H ~> m or kg m-\/2].}}
\DoxyCodeLine{229 \textcolor{keywordtype}{  real} :: k\_interior  \textcolor{comment}{! The (real) value of k where the interior grid starts [nondim].}}
\DoxyCodeLine{230 \textcolor{keywordtype}{  real} :: k\_int2      \textcolor{comment}{! The (real) value of k where the interior grid starts [nondim].}}
\DoxyCodeLine{231 \textcolor{keywordtype}{  real} :: z\_interior  \textcolor{comment}{! The depth where the interior grid starts [H ~> m or kg m-\/2].}}
\DoxyCodeLine{232 \textcolor{keywordtype}{  real} :: z\_ml\_fix    \textcolor{comment}{! The depth at which the fixed-\/thickness near-\/surface layers end [H ~> m or kg m-\/2].}}
\DoxyCodeLine{233 \textcolor{keywordtype}{  real} :: dz\_dk       \textcolor{comment}{! The thickness of layers between the fixed-\/thickness}}
\DoxyCodeLine{234                       \textcolor{comment}{! near-\/surface layars and the interior [H ~> m or kg m-\/2].}}
\DoxyCodeLine{235 \textcolor{keywordtype}{  real} :: Lfilt       \textcolor{comment}{! A filtering lengthscale [H ~> m or kg m-\/2].}}
\DoxyCodeLine{236   \textcolor{keywordtype}{logical} :: maximum\_depths\_set \textcolor{comment}{! If true, the maximum depths of interface have been set.}}
\DoxyCodeLine{237   \textcolor{keywordtype}{logical} :: maximum\_h\_set      \textcolor{comment}{! If true, the maximum layer thicknesses have been set.}}
\DoxyCodeLine{238 \textcolor{keywordtype}{  real} :: k2\_used, k2here, dz\_sum, z\_max}
\DoxyCodeLine{239   \textcolor{keywordtype}{integer} :: k2}
\DoxyCodeLine{240 \textcolor{keywordtype}{  real} :: h\_tr, b\_denom\_1, b1, d1 \textcolor{comment}{! Temporary variables used by the tridiagonal solver.}}
\DoxyCodeLine{241 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)} :: c1  \textcolor{comment}{! Temporary variables used by the tridiagonal solver.}}
\DoxyCodeLine{242   \textcolor{keywordtype}{integer} :: kur1, kur2  \textcolor{comment}{! The indicies at the top and bottom of an unreliable region.}}
\DoxyCodeLine{243   \textcolor{keywordtype}{integer} :: kur\_ss      \textcolor{comment}{! The index to start with in the search for the next unstable region.}}
\DoxyCodeLine{244   \textcolor{keywordtype}{integer} :: i, j, k, nkml}
\DoxyCodeLine{245 }
\DoxyCodeLine{246   maximum\_depths\_set = \textcolor{keyword}{allocated}(cs\%max\_interface\_depths)}
\DoxyCodeLine{247   maximum\_h\_set = \textcolor{keyword}{allocated}(cs\%max\_layer\_thickness)}
\DoxyCodeLine{248 }
\DoxyCodeLine{249   \textcolor{keywordflow}{if} (z\_col(nz+1) -\/ z\_col(1) < nz*cs\%min\_thickness) \textcolor{keywordflow}{then}}
\DoxyCodeLine{250     \textcolor{comment}{! This is a nearly massless total depth, so distribute the water evenly.}}
\DoxyCodeLine{251     dz = (z\_col(nz+1) -\/ z\_col(1)) / real(nz)}
\DoxyCodeLine{252     \textcolor{keywordflow}{do} k=2,nz ; z\_col\_new(k) = z\_col(1) + dz*real(k-\/1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{253   \textcolor{keywordflow}{else}}
\DoxyCodeLine{254     \textcolor{keyword}{call }calculate\_density(t\_col, s\_col, p\_col, rho\_col, eqn\_of\_state)}
\DoxyCodeLine{255 }
\DoxyCodeLine{256     \textcolor{comment}{! Find the locations of the target potential densities, flagging}}
\DoxyCodeLine{257     \textcolor{comment}{! locations in apparently unstable regions as not reliable.}}
\DoxyCodeLine{258     \textcolor{keyword}{call }rho\_interfaces\_col(rho\_col, h\_col, z\_col, cs\%target\_density, nz, \&}
\DoxyCodeLine{259                             z\_col\_new, cs, reliable, debug=.true., \&}
\DoxyCodeLine{260                             h\_neglect=h\_neglect, h\_neglect\_edge=h\_neglect\_edge)}
\DoxyCodeLine{261 }
\DoxyCodeLine{262     \textcolor{comment}{! Ensure that the interfaces are at least CS\%min\_thickness apart.}}
\DoxyCodeLine{263     \textcolor{keywordflow}{if} (cs\%min\_thickness > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{264       \textcolor{comment}{! Move down interfaces below overly thin layers.}}
\DoxyCodeLine{265       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{if} (z\_col\_new(k) < z\_col\_new(k-\/1) + cs\%min\_thickness) \textcolor{keywordflow}{then}}
\DoxyCodeLine{266         z\_col\_new(k) = z\_col\_new(k-\/1) + cs\%min\_thickness}
\DoxyCodeLine{267 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{268       \textcolor{comment}{! Now move up any interfaces that are too close to the bottom.}}
\DoxyCodeLine{269       \textcolor{keywordflow}{do} k=nz,2,-\/1 ; \textcolor{keywordflow}{if} (z\_col\_new(k) > z\_col\_new(k+1) -\/ cs\%min\_thickness) \textcolor{keywordflow}{then}}
\DoxyCodeLine{270         z\_col\_new(k) = z\_col\_new(k+1) -\/ cs\%min\_thickness}
\DoxyCodeLine{271       \textcolor{keywordflow}{else}}
\DoxyCodeLine{272         \textcolor{keywordflow}{exit} \textcolor{comment}{! No more interfaces can be too close to the bottom.}}
\DoxyCodeLine{273 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{274 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{275 }
\DoxyCodeLine{276     \textcolor{comment}{! Fix up the unreliable regions.}}
\DoxyCodeLine{277     kur\_ss = 2 \textcolor{comment}{! reliable(1) and reliable(nz+1) must always be true.}}
\DoxyCodeLine{278     \textcolor{keywordflow}{do}}
\DoxyCodeLine{279       \textcolor{comment}{! Search for the uppermost unreliable interface postion.}}
\DoxyCodeLine{280       kur1 = nz+2}
\DoxyCodeLine{281       \textcolor{keywordflow}{do} k=kur\_ss,nz ; \textcolor{keywordflow}{if} (.not.reliable(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{282         kur1 = k ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{283 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{284       \textcolor{keywordflow}{if} (kur1 > nz) \textcolor{keywordflow}{exit} \textcolor{comment}{! Everything is now reliable.}}
\DoxyCodeLine{285 }
\DoxyCodeLine{286       kur2 = kur1-\/1 \textcolor{comment}{! For error checking.}}
\DoxyCodeLine{287       \textcolor{keywordflow}{do} k=kur1+1,nz+1 ; \textcolor{keywordflow}{if} (reliable(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{288         kur2 = k-\/1 ; kur\_ss = k ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{289 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{290       \textcolor{keywordflow}{if} (kur2 < kur1) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Bad unreliable range."})}
\DoxyCodeLine{291 }
\DoxyCodeLine{292       dz\_ur = z\_col\_new(kur2+1) -\/ z\_col\_new(kur1-\/1)}
\DoxyCodeLine{293   \textcolor{comment}{!        drho = CS\%target\_density(kur2+1) -\/ CS\%target\_density(kur1-\/1)}}
\DoxyCodeLine{294       \textcolor{comment}{! Perhaps reset the wgt and cowgt depending on how bad the old interface}}
\DoxyCodeLine{295       \textcolor{comment}{! locations were.}}
\DoxyCodeLine{296       wgt = 1.0 ; cowgt = 0.0 \textcolor{comment}{! = 1.0-\/wgt}}
\DoxyCodeLine{297       \textcolor{keywordflow}{do} k=kur1,kur2}
\DoxyCodeLine{298         z\_col\_new(k) = cowgt*z\_col\_new(k) + \&}
\DoxyCodeLine{299               wgt * (z\_col\_new(kur1-\/1) + dz\_ur*(k -\/ (kur1-\/1)) / ((kur2 -\/ kur1) + 2))}
\DoxyCodeLine{300 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{301 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{302 }
\DoxyCodeLine{303     \textcolor{comment}{! Determine which interfaces are in the s-\/space region and the depth extent}}
\DoxyCodeLine{304     \textcolor{comment}{! of this region.}}
\DoxyCodeLine{305     z\_wt = 0.0 ; rho\_x\_z = 0.0}
\DoxyCodeLine{306     h\_ml\_av = cs\%Rho\_ml\_avg\_depth}
\DoxyCodeLine{307     \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{308       \textcolor{keywordflow}{if} (z\_wt + h\_col(k) >= h\_ml\_av) \textcolor{keywordflow}{then}}
\DoxyCodeLine{309         rho\_x\_z = rho\_x\_z + rho\_col(k) * (h\_ml\_av -\/ z\_wt)}
\DoxyCodeLine{310         z\_wt = h\_ml\_av}
\DoxyCodeLine{311         \textcolor{keywordflow}{exit}}
\DoxyCodeLine{312       \textcolor{keywordflow}{else}}
\DoxyCodeLine{313         rho\_x\_z =  rho\_x\_z + rho\_col(k) * h\_col(k)}
\DoxyCodeLine{314         z\_wt = z\_wt + h\_col(k)}
\DoxyCodeLine{315 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{316 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{317     \textcolor{keywordflow}{if} (z\_wt > 0.0) rho\_ml\_av = rho\_x\_z / z\_wt}
\DoxyCodeLine{318 }
\DoxyCodeLine{319     nkml = cs\%nz\_fixed\_surface}
\DoxyCodeLine{320     \textcolor{comment}{! Find the interface that matches rho\_ml\_av.}}
\DoxyCodeLine{321     \textcolor{keywordflow}{if} (rho\_ml\_av <= cs\%target\_density(nkml)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{322       k\_interior = cs\%nlay\_ml\_offset + real(nkml)}
\DoxyCodeLine{323     \textcolor{keywordflow}{elseif} (rho\_ml\_av > cs\%target\_density(nz+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{324       k\_interior = real(nz+1)}
\DoxyCodeLine{325     \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=nkml,nz}
\DoxyCodeLine{326       \textcolor{keywordflow}{if} ((rho\_ml\_av >= cs\%target\_density(k)) .and. \&}
\DoxyCodeLine{327           (rho\_ml\_av <  cs\%target\_density(k+1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{328         k\_interior = (cs\%nlay\_ml\_offset + k) + \&}
\DoxyCodeLine{329                 (rho\_ml\_av -\/ cs\%target\_density(k)) / \&}
\DoxyCodeLine{330                 (cs\%target\_density(k+1) -\/ cs\%target\_density(k))}
\DoxyCodeLine{331         \textcolor{keywordflow}{exit}}
\DoxyCodeLine{332 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{333 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{334     \textcolor{keywordflow}{if} (k\_interior > real(nz+1)) k\_interior = real(nz+1)}
\DoxyCodeLine{335 }
\DoxyCodeLine{336     \textcolor{comment}{! Linearly interpolate to find z\_interior.  This could be made more sophisticated.}}
\DoxyCodeLine{337     k = int(ceiling(k\_interior))}
\DoxyCodeLine{338     z\_interior = (k-\/k\_interior)*z\_col\_new(k-\/1) + (1.0+(k\_interior-\/k))*z\_col\_new(k)}
\DoxyCodeLine{339 }
\DoxyCodeLine{340     \textcolor{keywordflow}{if} (cs\%fix\_haloclines) \textcolor{keywordflow}{then}}
\DoxyCodeLine{341   \textcolor{comment}{!       ! Identify regions above the reference pressure where the chosen}}
\DoxyCodeLine{342   \textcolor{comment}{!       ! potential density significantly underestimates the actual}}
\DoxyCodeLine{343   \textcolor{comment}{!       ! stratification, and use these to find a second estimate of}}
\DoxyCodeLine{344   \textcolor{comment}{!       ! z\_int\_unst and k\_interior.}}
\DoxyCodeLine{345 }
\DoxyCodeLine{346       \textcolor{keywordflow}{if} (cs\%halocline\_filter\_length > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{347         lfilt = cs\%halocline\_filter\_length}
\DoxyCodeLine{348 }
\DoxyCodeLine{349         \textcolor{comment}{! Filter the temperature and salnity with a fixed lengthscale.}}
\DoxyCodeLine{350         h\_tr = h\_col(1) + h\_subroundoff}
\DoxyCodeLine{351         b1 = 1.0 / (h\_tr + lfilt) ; d1 = h\_tr * b1}
\DoxyCodeLine{352         t\_f(1) = (b1*h\_tr)*t\_col(1) ;  s\_f(1) = (b1*h\_tr)*s\_col(1)}
\DoxyCodeLine{353         \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{354           c1(k) = lfilt * b1}
\DoxyCodeLine{355           h\_tr = h\_col(k) + h\_subroundoff ; b\_denom\_1 = h\_tr + d1*lfilt}
\DoxyCodeLine{356           b1 = 1.0 / (b\_denom\_1 + lfilt) ; d1 = b\_denom\_1 * b1}
\DoxyCodeLine{357           t\_f(k) = b1 * (h\_tr*t\_col(k) + lfilt*t\_f(k-\/1))}
\DoxyCodeLine{358           s\_f(k) = b1 * (h\_tr*s\_col(k) + lfilt*s\_f(k-\/1))}
\DoxyCodeLine{359 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{360         \textcolor{keywordflow}{do} k=nz-\/1,1,-\/1}
\DoxyCodeLine{361           t\_f(k) = t\_f(k) + c1(k+1)*t\_f(k+1) ; s\_f(k) = s\_f(k) + c1(k+1)*s\_f(k+1)}
\DoxyCodeLine{362 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{363       \textcolor{keywordflow}{else}}
\DoxyCodeLine{364         \textcolor{keywordflow}{do} k=1,nz ; t\_f(k) = t\_col(k) ; s\_f(k) = s\_col(k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{365 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{366 }
\DoxyCodeLine{367       t\_int(1) = t\_f(1) ; s\_int(1) = s\_f(1)}
\DoxyCodeLine{368       \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{369         t\_int(k) = 0.5*(t\_f(k-\/1) + t\_f(k)) ; s\_int(k) = 0.5*(s\_f(k-\/1) + s\_f(k))}
\DoxyCodeLine{370         p\_is(k) = z\_col(k) * h\_to\_pres}
\DoxyCodeLine{371         p\_r(k) = cs\%ref\_pressure + cs\%compressibility\_fraction * ( p\_is(k) -\/ cs\%ref\_pressure )}
\DoxyCodeLine{372 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{373       t\_int(nz+1) = t\_f(nz) ; s\_int(nz+1) = s\_f(nz)}
\DoxyCodeLine{374       p\_is(nz+1) = z\_col(nz+1) * h\_to\_pres}
\DoxyCodeLine{375       \textcolor{keyword}{call }calculate\_density\_derivs(t\_int, s\_int, p\_is, drhois\_dt, drhois\_ds, \&}
\DoxyCodeLine{376                                     eqn\_of\_state, (/2,nz/) )}
\DoxyCodeLine{377       \textcolor{keyword}{call }calculate\_density\_derivs(t\_int, s\_int, p\_r, drhor\_dt, drhor\_ds, \&}
\DoxyCodeLine{378                                     eqn\_of\_state, (/2,nz/) )}
\DoxyCodeLine{379       \textcolor{keywordflow}{if} (cs\%compressibility\_fraction > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{380         \textcolor{keyword}{call }calculate\_compress(t\_int, s\_int, p\_r(:), rho\_tmp, drho\_dp, 2, nz-\/1, eqn\_of\_state)}
\DoxyCodeLine{381       \textcolor{keywordflow}{else}}
\DoxyCodeLine{382         \textcolor{keywordflow}{do} k=2,nz ; drho\_dp(k) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{383 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{384 }
\DoxyCodeLine{385       h\_to\_cpa = cs\%compressibility\_fraction * h\_to\_pres}
\DoxyCodeLine{386       strat\_rat(1) = 1.0}
\DoxyCodeLine{387       \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{388         dris = drhois\_dt(k) * (t\_f(k) -\/ t\_f(k-\/1)) + \&}
\DoxyCodeLine{389                drhois\_ds(k) * (s\_f(k) -\/ s\_f(k-\/1))}
\DoxyCodeLine{390         drr = (drhor\_dt(k) * (t\_f(k) -\/ t\_f(k-\/1)) + \&}
\DoxyCodeLine{391                drhor\_ds(k) * (s\_f(k) -\/ s\_f(k-\/1))) + \&}
\DoxyCodeLine{392               drho\_dp(k) * (h\_to\_cpa*0.5*(h\_col(k) + h\_col(k-\/1)))}
\DoxyCodeLine{393 }
\DoxyCodeLine{394         \textcolor{keywordflow}{if} (dris <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{395           strat\_rat(k) = 2.0 \textcolor{comment}{! Maybe do this? => ; if (drR < 0.0) strat\_rat(K) = -\/2.0}}
\DoxyCodeLine{396         \textcolor{keywordflow}{else}}
\DoxyCodeLine{397           strat\_rat(k) = 2.0*max(drr,0.0) / (dris + abs(drr))}
\DoxyCodeLine{398 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{399 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{400       strat\_rat(nz+1) = 1.0}
\DoxyCodeLine{401 }
\DoxyCodeLine{402       z\_int\_unst = 0.0 ; fn\_now = 0.0}
\DoxyCodeLine{403       fn\_zero\_val = min(2.0*cs\%halocline\_strat\_tol, \&}
\DoxyCodeLine{404                         0.5*(1.0 + cs\%halocline\_strat\_tol))}
\DoxyCodeLine{405       \textcolor{keywordflow}{if} (cs\%halocline\_strat\_tol > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{406         \textcolor{comment}{! Use Adcroft's reciprocal rule.}}
\DoxyCodeLine{407         i\_hstol = 0.0 ; \textcolor{keywordflow}{if} (fn\_zero\_val -\/ cs\%halocline\_strat\_tol > 0.0) \&}
\DoxyCodeLine{408           i\_hstol = 1.0 / (fn\_zero\_val -\/ cs\%halocline\_strat\_tol)}
\DoxyCodeLine{409         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; \textcolor{keywordflow}{if} (cs\%ref\_pressure > p\_is(k+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{410           z\_int\_unst = z\_int\_unst + fn\_now * h\_col(k)}
\DoxyCodeLine{411           \textcolor{keywordflow}{if} (strat\_rat(k) <= fn\_zero\_val) \textcolor{keywordflow}{then}}
\DoxyCodeLine{412             \textcolor{keywordflow}{if} (strat\_rat(k) <= cs\%halocline\_strat\_tol) \textcolor{keywordflow}{then} ; fn\_now = 1.0}
\DoxyCodeLine{413             \textcolor{keywordflow}{else}}
\DoxyCodeLine{414               fn\_now = max(fn\_now, (fn\_zero\_val -\/ strat\_rat(k)) * i\_hstol)}
\DoxyCodeLine{415 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{416 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{417 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{418       \textcolor{keywordflow}{else}}
\DoxyCodeLine{419         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; \textcolor{keywordflow}{if} (cs\%ref\_pressure > p\_is(k+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{420           z\_int\_unst = z\_int\_unst + fn\_now * h\_col(k)}
\DoxyCodeLine{421           \textcolor{keywordflow}{if} (strat\_rat(k) <= cs\%halocline\_strat\_tol) fn\_now = 1.0}
\DoxyCodeLine{422 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{423 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{424 }
\DoxyCodeLine{425       \textcolor{keywordflow}{if} (z\_interior < z\_int\_unst) \textcolor{keywordflow}{then}}
\DoxyCodeLine{426         \textcolor{comment}{! Find a second estimate of the extent of the s-\/coordinate region.}}
\DoxyCodeLine{427         kur1 = max(int(ceiling(k\_interior)),2)}
\DoxyCodeLine{428         \textcolor{keywordflow}{if} (z\_col\_new(kur1-\/1) < z\_interior) \textcolor{keywordflow}{then}}
\DoxyCodeLine{429           k\_int2 = kur1}
\DoxyCodeLine{430           \textcolor{keywordflow}{do} k = kur1,nz+1 ; \textcolor{keywordflow}{if} (z\_col\_new(k) >= z\_int\_unst) \textcolor{keywordflow}{then}}
\DoxyCodeLine{431             \textcolor{comment}{! This is linear interpolation again.}}
\DoxyCodeLine{432             \textcolor{keywordflow}{if} (z\_col\_new(k-\/1) >= z\_int\_unst) \&}
\DoxyCodeLine{433               \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"build\_grid\_SLight, bad halocline structure."})}
\DoxyCodeLine{434             k\_int2 = real(k-\/1) + (z\_int\_unst -\/ z\_col\_new(k-\/1)) / \&}
\DoxyCodeLine{435                                      (z\_col\_new(k) -\/ z\_col\_new(k-\/1))}
\DoxyCodeLine{436             \textcolor{keywordflow}{exit}}
\DoxyCodeLine{437 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{438           \textcolor{keywordflow}{if} (z\_col\_new(nz+1) < z\_int\_unst) \textcolor{keywordflow}{then}}
\DoxyCodeLine{439             \textcolor{comment}{! This should be unnecessary.}}
\DoxyCodeLine{440             z\_int\_unst = z\_col\_new(nz+1) ; k\_int2 = real(nz+1)}
\DoxyCodeLine{441 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{442 }
\DoxyCodeLine{443           \textcolor{comment}{! Now take the larger values.}}
\DoxyCodeLine{444           \textcolor{keywordflow}{if} (k\_int2 > k\_interior) \textcolor{keywordflow}{then}}
\DoxyCodeLine{445             k\_interior = k\_int2 ; z\_interior = z\_int\_unst}
\DoxyCodeLine{446 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{447 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{448 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{449 \textcolor{keywordflow}{    endif}  \textcolor{comment}{! fix\_haloclines}}
\DoxyCodeLine{450 }
\DoxyCodeLine{451     z\_col\_new(1) = 0.0}
\DoxyCodeLine{452     \textcolor{keywordflow}{do} k=2,nkml+1}
\DoxyCodeLine{453       z\_col\_new(k) = min((k-\/1)*cs\%dz\_ml\_min, \&}
\DoxyCodeLine{454                          z\_col\_new(nz+1) -\/ cs\%min\_thickness*(nz+1-\/k))}
\DoxyCodeLine{455 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{456     z\_ml\_fix = z\_col\_new(nkml+1)}
\DoxyCodeLine{457     \textcolor{keywordflow}{if} (z\_interior > z\_ml\_fix) \textcolor{keywordflow}{then}}
\DoxyCodeLine{458       dz\_dk = (z\_interior -\/ z\_ml\_fix) / (k\_interior -\/ (nkml+1))}
\DoxyCodeLine{459       \textcolor{keywordflow}{do} k=nkml+2,int(floor(k\_interior))}
\DoxyCodeLine{460         z\_col\_new(k) = z\_ml\_fix + dz\_dk * (k -\/ (nkml+1))}
\DoxyCodeLine{461 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{462     \textcolor{keywordflow}{else} \textcolor{comment}{! The fixed-\/thickness z-\/region penetrates into the interior.}}
\DoxyCodeLine{463       \textcolor{keywordflow}{do} k=nkml+2,nz}
\DoxyCodeLine{464         \textcolor{keywordflow}{if} (z\_col\_new(k) <= z\_col\_new(cs\%nz\_fixed\_surface+1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{465           z\_col\_new(k) = z\_col\_new(cs\%nz\_fixed\_surface+1)}
\DoxyCodeLine{466         \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{467 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{468 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{469 }
\DoxyCodeLine{470     \textcolor{keywordflow}{if} (maximum\_depths\_set .and. maximum\_h\_set) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{471       \textcolor{comment}{! The loop bounds are 2 \& nz so the top and bottom interfaces do not move.}}
\DoxyCodeLine{472       \textcolor{comment}{! Recall that z\_col\_new is positive downward.}}
\DoxyCodeLine{473       z\_col\_new(k) = min(z\_col\_new(k), cs\%max\_interface\_depths(k), \&}
\DoxyCodeLine{474                          z\_col\_new(k-\/1) + cs\%max\_layer\_thickness(k-\/1))}
\DoxyCodeLine{475 \textcolor{keywordflow}{    enddo} ; \textcolor{keywordflow}{elseif} (maximum\_depths\_set) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{476       z\_col\_new(k) = min(z\_col\_new(k), cs\%max\_interface\_depths(k))}
\DoxyCodeLine{477 \textcolor{keywordflow}{    enddo} ; \textcolor{keywordflow}{elseif} (maximum\_h\_set) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{478       z\_col\_new(k) = min(z\_col\_new(k), z\_col\_new(k-\/1) + cs\%max\_layer\_thickness(k-\/1))}
\DoxyCodeLine{479 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{480 }
\DoxyCodeLine{481 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Total thickness exceeds nz*CS\%min\_thickness.}}
\DoxyCodeLine{482 }

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



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


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


Definition at line 105 of file coord\+\_\+slight.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{105   \textcolor{keywordtype}{type}(slight\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Coordinate control structure}}
\DoxyCodeLine{106 }
\DoxyCodeLine{107   \textcolor{comment}{! nothing to do}}
\DoxyCodeLine{108   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{109   \textcolor{keyword}{deallocate}(cs\%target\_density)}
\DoxyCodeLine{110   \textcolor{keyword}{deallocate}(cs)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__slight_afe3fb682e16b96d441d380635a983040}\label{namespacecoord__slight_afe3fb682e16b96d441d380635a983040}} 
\index{coord\_slight@{coord\_slight}!init\_coord\_slight@{init\_coord\_slight}}
\index{init\_coord\_slight@{init\_coord\_slight}!coord\_slight@{coord\_slight}}
\doxysubsubsection{\texorpdfstring{init\_coord\_slight()}{init\_coord\_slight()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+slight\+::init\+\_\+coord\+\_\+slight (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__slight_1_1slight__cs}{slight\+\_\+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,  }\item[{real, intent(in), optional}]{m\+\_\+to\+\_\+H }\end{DoxyParamCaption})}



Initialise a slight\+\_\+\+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
\mbox{\texttt{ in}}  & {\em m\+\_\+to\+\_\+h} & A conversion factor from m to the units of thicknesses \\
\hline
\end{DoxyParams}


Definition at line 73 of file coord\+\_\+slight.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{73   \textcolor{keywordtype}{type}(slight\_CS),      \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Unassociated pointer to hold the control structure}}
\DoxyCodeLine{74   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{ !< Number of layers in the grid}}
\DoxyCodeLine{75 \textcolor{keywordtype}{  real},                 \textcolor{keywordtype}{intent(in)} :: ref\_pressure\textcolor{comment}{ !< Coordinate reference pressure [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{76 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)} :: target\_density\textcolor{comment}{ !< Nominal density of interfaces [R ~> kg m-\/3]}}
\DoxyCodeLine{77   \textcolor{keywordtype}{type}(interp\_CS\_type), \textcolor{keywordtype}{intent(in)} :: interp\_CS\textcolor{comment}{ !< Controls for interpolation}}
\DoxyCodeLine{78 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: m\_to\_H\textcolor{comment}{ !< A conversion factor from m to the units of thicknesses}}
\DoxyCodeLine{79 }
\DoxyCodeLine{80 \textcolor{keywordtype}{  real} :: m\_to\_H\_rescale  \textcolor{comment}{! A unit conversion factor.}}
\DoxyCodeLine{81 }
\DoxyCodeLine{82   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"init\_coord\_slight: CS already associated!"})}
\DoxyCodeLine{83   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{84   \textcolor{keyword}{allocate}(cs\%target\_density(nk+1))}
\DoxyCodeLine{85 }
\DoxyCodeLine{86   m\_to\_h\_rescale = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(m\_to\_h)) m\_to\_h\_rescale = m\_to\_h}
\DoxyCodeLine{87 }
\DoxyCodeLine{88   cs\%nk                = nk}
\DoxyCodeLine{89   cs\%ref\_pressure      = ref\_pressure}
\DoxyCodeLine{90   cs\%target\_density(:) = target\_density(:)}
\DoxyCodeLine{91   cs\%interp\_CS         = interp\_cs}
\DoxyCodeLine{92 }
\DoxyCodeLine{93   \textcolor{comment}{! Set real parameter default values}}
\DoxyCodeLine{94   cs\%compressibility\_fraction = 0. \textcolor{comment}{! Nondim.}}
\DoxyCodeLine{95   cs\%Rho\_ML\_avg\_depth = 1.0 * m\_to\_h\_rescale}
\DoxyCodeLine{96   cs\%nlay\_ml\_offset = 2.0          \textcolor{comment}{! Nondim.}}
\DoxyCodeLine{97   cs\%dz\_ml\_min = 1.0 * m\_to\_h\_rescale}
\DoxyCodeLine{98   cs\%halocline\_filter\_length = 2.0 * m\_to\_h\_rescale}
\DoxyCodeLine{99   cs\%halocline\_strat\_tol = 0.25    \textcolor{comment}{! Nondim.}}
\DoxyCodeLine{100 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__slight_a20af96022abf0d0f4ecb17dde027b2d1}\label{namespacecoord__slight_a20af96022abf0d0f4ecb17dde027b2d1}} 
\index{coord\_slight@{coord\_slight}!rho\_interfaces\_col@{rho\_interfaces\_col}}
\index{rho\_interfaces\_col@{rho\_interfaces\_col}!coord\_slight@{coord\_slight}}
\doxysubsubsection{\texorpdfstring{rho\_interfaces\_col()}{rho\_interfaces\_col()}}
{\footnotesize\ttfamily subroutine coord\+\_\+slight\+::rho\+\_\+interfaces\+\_\+col (\begin{DoxyParamCaption}\item[{real, dimension(nz), intent(in)}]{rho\+\_\+col,  }\item[{real, dimension(nz), intent(in)}]{h\+\_\+col,  }\item[{real, dimension(nz+1), intent(in)}]{z\+\_\+col,  }\item[{real, dimension(nz+1), intent(in)}]{rho\+\_\+tgt,  }\item[{integer, intent(in)}]{nz,  }\item[{real, dimension(nz+1), intent(inout)}]{z\+\_\+col\+\_\+new,  }\item[{type(\mbox{\hyperlink{structcoord__slight_1_1slight__cs}{slight\+\_\+cs}}), intent(in)}]{CS,  }\item[{logical, dimension(nz+1), intent(inout)}]{reliable,  }\item[{logical, intent(in), optional}]{debug,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Finds the new interface locations in a column of water that match the prescribed target densities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nz} & Number of layers \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+col} & Initial layer reference densities \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+col} & Initial layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em z\+\_\+col} & Initial interface heights \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+tgt} & Interface target densities. \\
\hline
\mbox{\texttt{ in,out}}  & {\em z\+\_\+col\+\_\+new} & New interface heights \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Coordinate control structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em reliable} & If true, the interface positions are well defined from a stable region. \\
\hline
\mbox{\texttt{ in}}  & {\em debug} & If present and true, do debugging checks. \\
\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}


Definition at line 489 of file coord\+\_\+slight.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{489   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{      !< Number of layers}}
\DoxyCodeLine{490 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: rho\_col\textcolor{comment}{ !< Initial layer reference densities [R ~> kg m-\/3].}}
\DoxyCodeLine{491 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: h\_col\textcolor{comment}{   !< Initial layer thicknesses [H ~> m or kg m-\/2].}}
\DoxyCodeLine{492 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(in)}    :: z\_col\textcolor{comment}{   !< Initial interface heights [H ~> m or kg m-\/2].}}
\DoxyCodeLine{493 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(in)}    :: rho\_tgt\textcolor{comment}{ !< Interface target densities.}}
\DoxyCodeLine{494 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(inout)} :: z\_col\_new\textcolor{comment}{ !< New interface heights [H ~> m or kg m-\/2].}}
\DoxyCodeLine{495   \textcolor{keywordtype}{type}(slight\_CS),       \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{      !< Coordinate control structure}}
\DoxyCodeLine{496   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(inout)} :: reliable\textcolor{comment}{ !< If true, the interface positions}}
\DoxyCodeLine{497 \textcolor{comment}{                                                  !! are well defined from a stable region.}}
\DoxyCodeLine{498   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: debug\textcolor{comment}{   !< If present and true, do debugging checks.}}
\DoxyCodeLine{499 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the purpose of}}
\DoxyCodeLine{500 \textcolor{comment}{                                                  !! cell reconstructions [H ~> m or kg m-\/2]}}
\DoxyCodeLine{501 \textcolor{keywordtype}{  real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width for the purpose}}
\DoxyCodeLine{502 \textcolor{comment}{                                                  !! of edge value calculations [H ~> m or kg m-\/2]}}
\DoxyCodeLine{503 }
\DoxyCodeLine{504 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: ru\_max\_int \textcolor{comment}{! The maximum and minimum densities in}}
\DoxyCodeLine{505 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz+1)} :: ru\_min\_int \textcolor{comment}{! an unstable region around an interface [R ~> kg m-\/3].}}
\DoxyCodeLine{506 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)}   :: ru\_max\_lay \textcolor{comment}{! The maximum and minimum densities in}}
\DoxyCodeLine{507 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz)}   :: ru\_min\_lay \textcolor{comment}{! an unstable region containing a layer [R ~> kg m-\/3].}}
\DoxyCodeLine{508 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz,2)} :: ppoly\_i\_E  \textcolor{comment}{! Edge value of polynomial [R ~> kg m-\/3]}}
\DoxyCodeLine{509 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz,2)} :: ppoly\_i\_S  \textcolor{comment}{! Edge slope of polynomial [R H-\/1 ~> kg m-\/4 or m-\/1]}}
\DoxyCodeLine{510 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nz,DEGREE\_MAX+1)} :: ppoly\_i\_coefficients \textcolor{comment}{! Coefficients of polynomial [R ~> kg m-\/3]}}
\DoxyCodeLine{511   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nz)}   :: unstable\_lay \textcolor{comment}{! If true, this layer is in an unstable region.}}
\DoxyCodeLine{512   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(nz+1)} :: unstable\_int \textcolor{comment}{! If true, this interface is in an unstable region.}}
\DoxyCodeLine{513 \textcolor{keywordtype}{  real} :: rt  \textcolor{comment}{! The current target density [R ~> kg m-\/3].}}
\DoxyCodeLine{514 \textcolor{keywordtype}{  real} :: zf  \textcolor{comment}{! The fractional z-\/position within a layer of the target density [nondim].}}
\DoxyCodeLine{515 \textcolor{keywordtype}{  real} :: rfn \textcolor{comment}{! The target density relative to the interpolated density [R ~> kg m-\/3]}}
\DoxyCodeLine{516 \textcolor{keywordtype}{  real} :: a(5) \textcolor{comment}{! Coefficients of a local polynomial minus the target density [R ~> kg m-\/3].}}
\DoxyCodeLine{517 \textcolor{keywordtype}{  real} :: zf1, zf2   \textcolor{comment}{! Two previous estimates of zf [nondim]}}
\DoxyCodeLine{518 \textcolor{keywordtype}{  real} :: rfn1, rfn2 \textcolor{comment}{! Values of rfn at zf1 and zf2 [R ~> kg m-\/3]}}
\DoxyCodeLine{519 \textcolor{keywordtype}{  real} :: drfn\_dzf   \textcolor{comment}{! The partial derivative of rfn with zf [R ~> kg m-\/3]}}
\DoxyCodeLine{520 \textcolor{keywordtype}{  real} :: sgn, delta\_zf, zf\_prev \textcolor{comment}{! [nondim]}}
\DoxyCodeLine{521 \textcolor{keywordtype}{  real} :: tol  \textcolor{comment}{! The tolerance for convergence of zf [nondim]}}
\DoxyCodeLine{522   \textcolor{keywordtype}{logical} :: k\_found \textcolor{comment}{! If true, the position has been found.}}
\DoxyCodeLine{523   \textcolor{keywordtype}{integer} :: k\_layer \textcolor{comment}{! The index of the stable layer containing an interface.}}
\DoxyCodeLine{524   \textcolor{keywordtype}{integer} :: ppoly\_degree}
\DoxyCodeLine{525   \textcolor{keywordtype}{integer} :: k, k1, k1\_min, itt, max\_itt, m}
\DoxyCodeLine{526 }
\DoxyCodeLine{527 \textcolor{keywordtype}{  real} :: z\_sgn  \textcolor{comment}{! 1 or -\/1, depending on whether z increases with increasing K.}}
\DoxyCodeLine{528   \textcolor{keywordtype}{logical} :: debugging}
\DoxyCodeLine{529 }
\DoxyCodeLine{530   debugging = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(debug)) debugging = debug}
\DoxyCodeLine{531   max\_itt = nr\_iterations}
\DoxyCodeLine{532   tol = nr\_tolerance}
\DoxyCodeLine{533 }
\DoxyCodeLine{534   z\_sgn = 1.0 ; \textcolor{keywordflow}{if} ( z\_col(1) > z\_col(nz+1) ) z\_sgn = -\/1.0}
\DoxyCodeLine{535   \textcolor{keywordflow}{if} (debugging) \textcolor{keywordflow}{then}}
\DoxyCodeLine{536     \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{537       \textcolor{keywordflow}{if} (abs((z\_col(k+1) -\/ z\_col(k)) -\/ z\_sgn*h\_col(k)) > \&}
\DoxyCodeLine{538           1.0e-\/14*(abs(z\_col(k+1)) + abs(z\_col(k)) + abs(h\_col(k))) ) \&}
\DoxyCodeLine{539         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"rho\_interfaces\_col: Inconsistent z\_col and h\_col"})}
\DoxyCodeLine{540 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{541 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{542 }
\DoxyCodeLine{543   \textcolor{keywordflow}{if} ( z\_col(1) == z\_col(nz+1) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{544     \textcolor{comment}{! This is a massless column!}}
\DoxyCodeLine{545     \textcolor{keywordflow}{do} k=1,nz+1 ; z\_col\_new(k) = z\_col(1) ; reliable(k) = .true. ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{546     \textcolor{keywordflow}{return}}
\DoxyCodeLine{547 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{548 }
\DoxyCodeLine{549   \textcolor{comment}{! This sets up the piecewise polynomials based on the rho\_col profile.}}
\DoxyCodeLine{550   \textcolor{keyword}{call }regridding\_set\_ppolys(cs\%interp\_CS, rho\_col, nz, h\_col, ppoly\_i\_e, ppoly\_i\_s, \&}
\DoxyCodeLine{551        ppoly\_i\_coefficients, ppoly\_degree, h\_neglect, h\_neglect\_edge)}
\DoxyCodeLine{552 }
\DoxyCodeLine{553   \textcolor{comment}{! Determine the density ranges of unstably stratified segments.}}
\DoxyCodeLine{554   \textcolor{comment}{! Interfaces that start out in an unstably stratified segment can}}
\DoxyCodeLine{555   \textcolor{comment}{! only escape if they are outside of the bounds of that segment, and no}}
\DoxyCodeLine{556   \textcolor{comment}{! interfaces are ever mapped into an unstable segment.}}
\DoxyCodeLine{557   unstable\_int(1) = .false.}
\DoxyCodeLine{558   ru\_max\_int(1) = ppoly\_i\_e(1,1)}
\DoxyCodeLine{559 }
\DoxyCodeLine{560   unstable\_lay(1) = (ppoly\_i\_e(1,1) > ppoly\_i\_e(1,2))}
\DoxyCodeLine{561   ru\_max\_lay(1) = max(ppoly\_i\_e(1,1), ppoly\_i\_e(1,2))}
\DoxyCodeLine{562 }
\DoxyCodeLine{563   \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{564     unstable\_int(k) = (ppoly\_i\_e(k-\/1,2) > ppoly\_i\_e(k,1))}
\DoxyCodeLine{565     ru\_max\_int(k) = max(ppoly\_i\_e(k-\/1,2), ppoly\_i\_e(k,1))}
\DoxyCodeLine{566     ru\_min\_int(k) = min(ppoly\_i\_e(k-\/1,2), ppoly\_i\_e(k,1))}
\DoxyCodeLine{567     \textcolor{keywordflow}{if} (unstable\_int(k) .and. unstable\_lay(k-\/1)) \&}
\DoxyCodeLine{568       ru\_max\_int(k) = max(ru\_max\_lay(k-\/1), ru\_max\_int(k))}
\DoxyCodeLine{569 }
\DoxyCodeLine{570     unstable\_lay(k) = (ppoly\_i\_e(k,1) > ppoly\_i\_e(k,2))}
\DoxyCodeLine{571     ru\_max\_lay(k) = max(ppoly\_i\_e(k,1), ppoly\_i\_e(k,2))}
\DoxyCodeLine{572     ru\_min\_lay(k) = min(ppoly\_i\_e(k,1), ppoly\_i\_e(k,2))}
\DoxyCodeLine{573     \textcolor{keywordflow}{if} (unstable\_lay(k) .and. unstable\_int(k)) \&}
\DoxyCodeLine{574       ru\_max\_lay(k) = max(ru\_max\_int(k), ru\_max\_lay(k))}
\DoxyCodeLine{575 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{576   unstable\_int(nz+1) = .false.}
\DoxyCodeLine{577   ru\_min\_int(nz+1) = ppoly\_i\_e(nz,2)}
\DoxyCodeLine{578 }
\DoxyCodeLine{579   \textcolor{keywordflow}{do} k=nz,1,-\/1}
\DoxyCodeLine{580     \textcolor{keywordflow}{if} (unstable\_lay(k) .and. unstable\_int(k+1)) \&}
\DoxyCodeLine{581       ru\_min\_lay(k) = min(ru\_min\_int(k+1), ru\_min\_lay(k))}
\DoxyCodeLine{582 }
\DoxyCodeLine{583     \textcolor{keywordflow}{if} (unstable\_int(k) .and. unstable\_lay(k)) \&}
\DoxyCodeLine{584       ru\_min\_int(k) = min(ru\_min\_lay(k), ru\_min\_int(k))}
\DoxyCodeLine{585 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{586 }
\DoxyCodeLine{587   z\_col\_new(1) = z\_col(1) ; reliable(1) = .true.}
\DoxyCodeLine{588   k1\_min = 1}
\DoxyCodeLine{589   \textcolor{keywordflow}{do} k=2,nz \textcolor{comment}{! Find the locations of the various target densities for the interfaces.}}
\DoxyCodeLine{590     rt = rho\_tgt(k)}
\DoxyCodeLine{591     k\_layer = -\/1}
\DoxyCodeLine{592     k\_found = .false.}
\DoxyCodeLine{593 }
\DoxyCodeLine{594     \textcolor{comment}{! Many light layers are found at the top, so start there.}}
\DoxyCodeLine{595     \textcolor{keywordflow}{if} (rt <= ppoly\_i\_e(k1\_min,1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{596       z\_col\_new(k) = z\_col(k1\_min)}
\DoxyCodeLine{597       k\_found = .true.}
\DoxyCodeLine{598       \textcolor{comment}{! Do not change k1\_min for the next layer.}}
\DoxyCodeLine{599     \textcolor{keywordflow}{elseif} (k1\_min == nz+1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{600       z\_col\_new(k) = z\_col(nz+1)}
\DoxyCodeLine{601     \textcolor{keywordflow}{else}}
\DoxyCodeLine{602       \textcolor{comment}{! Start with the previous location and search outward.}}
\DoxyCodeLine{603       \textcolor{keywordflow}{if} (unstable\_int(k) .and. (rt >= ru\_min\_int(k)) .and. (rt <= ru\_max\_int(k))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{604         \textcolor{comment}{! This interface started in an unstable region and should not move due to remapping.}}
\DoxyCodeLine{605         z\_col\_new(k) = z\_col(k) ; reliable(k) = .false.}
\DoxyCodeLine{606         k1\_min = k ; k\_found = .true.}
\DoxyCodeLine{607       \textcolor{keywordflow}{elseif} ((rt >= ppoly\_i\_e(k-\/1,2)) .and. (rt <= ppoly\_i\_e(k,1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{608         \textcolor{comment}{! This interface is already in the right place and does not move.}}
\DoxyCodeLine{609         z\_col\_new(k) = z\_col(k) ; reliable(k) = .true.}
\DoxyCodeLine{610         k1\_min = k ; k\_found = .true.}
\DoxyCodeLine{611       \textcolor{keywordflow}{elseif} (rt < ppoly\_i\_e(k-\/1,2)) \textcolor{keywordflow}{then}   \textcolor{comment}{! Search upward}}
\DoxyCodeLine{612         \textcolor{keywordflow}{do} k1=k-\/1,k1\_min,-\/1}
\DoxyCodeLine{613           \textcolor{comment}{! Check whether rt is in layer k.}}
\DoxyCodeLine{614           \textcolor{keywordflow}{if} ((rt < ppoly\_i\_e(k1,2)) .and. (rt > ppoly\_i\_e(k1,1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{615             \textcolor{comment}{! rt is in layer k.}}
\DoxyCodeLine{616             k\_layer = k1}
\DoxyCodeLine{617             k1\_min = k1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{618           \textcolor{keywordflow}{elseif} (unstable\_lay(k1) .and. (rt >= ru\_min\_lay(k1)) .and. (rt <= ru\_max\_lay(k1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{619             \textcolor{comment}{! rt would be found at unstable layer that it can not penetrate.}}
\DoxyCodeLine{620             \textcolor{comment}{!   It is possible that this can never happen?}}
\DoxyCodeLine{621             z\_col\_new(k) = z\_col(k1+1) ; reliable(k) = .false.}
\DoxyCodeLine{622             k1\_min = k1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{623 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{624           \textcolor{comment}{! Check whether rt is at interface K.}}
\DoxyCodeLine{625           \textcolor{keywordflow}{if} (k1 > 1) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} ((rt <= ppoly\_i\_e(k1,1)) .and. (rt >= ppoly\_i\_e(k1-\/1,2))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{626             \textcolor{comment}{! rt is at interface K1}}
\DoxyCodeLine{627             z\_col\_new(k) = z\_col(k1) ; reliable(k) = .true.}
\DoxyCodeLine{628             k1\_min = k1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{629           \textcolor{keywordflow}{elseif} (unstable\_int(k1) .and. (rt >= ru\_min\_int(k1)) .and. (rt <= ru\_max\_int(k1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{630             \textcolor{comment}{! rt would be found at an unstable interface that it can not pass.}}
\DoxyCodeLine{631             \textcolor{comment}{!   It is possible that this can never happen?}}
\DoxyCodeLine{632             z\_col\_new(k) = z\_col(k1) ; reliable(k) = .false.}
\DoxyCodeLine{633             k1\_min = k1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{634 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{635 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{636 }
\DoxyCodeLine{637         \textcolor{keywordflow}{if} (.not.k\_found) \textcolor{keywordflow}{then}}
\DoxyCodeLine{638           \textcolor{comment}{! This should not happen unless k1\_min = 1.}}
\DoxyCodeLine{639           \textcolor{keywordflow}{if} (k1\_min < 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{640             z\_col\_new(k) = z\_col(k1\_min)}
\DoxyCodeLine{641           \textcolor{keywordflow}{else}}
\DoxyCodeLine{642             z\_col\_new(k) = z\_col(k1\_min)}
\DoxyCodeLine{643 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{644 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{645 }
\DoxyCodeLine{646       \textcolor{keywordflow}{else}  \textcolor{comment}{! Search downward}}
\DoxyCodeLine{647         \textcolor{keywordflow}{do} k1=k,nz}
\DoxyCodeLine{648           \textcolor{keywordflow}{if} ((rt < ppoly\_i\_e(k1,2)) .and. (rt > ppoly\_i\_e(k1,1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{649             \textcolor{comment}{! rt is in layer k.}}
\DoxyCodeLine{650             k\_layer = k1}
\DoxyCodeLine{651             k1\_min = k1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{652           \textcolor{keywordflow}{elseif} (unstable\_lay(k1) .and. (rt >= ru\_min\_lay(k1)) .and. (rt <= ru\_max\_lay(k1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{653             \textcolor{comment}{! rt would be found at unstable layer that it can not penetrate.}}
\DoxyCodeLine{654             \textcolor{comment}{!   It is possible that this can never happen?}}
\DoxyCodeLine{655             z\_col\_new(k) = z\_col(k1)}
\DoxyCodeLine{656             reliable(k) = .false.}
\DoxyCodeLine{657             k1\_min = k1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{658 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{659           \textcolor{keywordflow}{if} (k1 < nz) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} ((rt <= ppoly\_i\_e(k1+1,1)) .and. (rt >= ppoly\_i\_e(k1,2))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{660             \textcolor{comment}{! rt is at interface K1+1}}
\DoxyCodeLine{661 }
\DoxyCodeLine{662             z\_col\_new(k) = z\_col(k1+1) ; reliable(k) = .true.}
\DoxyCodeLine{663             k1\_min = k1+1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{664           \textcolor{keywordflow}{elseif} (unstable\_int(k1+1) .and. (rt >= ru\_min\_int(k1+1)) .and. (rt <= ru\_max\_int(k1+1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{665             \textcolor{comment}{! rt would be found at an unstable interface that it can not pass.}}
\DoxyCodeLine{666             \textcolor{comment}{!   It is possible that this can never happen?}}
\DoxyCodeLine{667             z\_col\_new(k) = z\_col(k1+1)}
\DoxyCodeLine{668             reliable(k) = .false.}
\DoxyCodeLine{669             k1\_min = k1+1 ; k\_found = .true. ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{670 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{671 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{672         \textcolor{keywordflow}{if} (.not.k\_found) \textcolor{keywordflow}{then}}
\DoxyCodeLine{673           z\_col\_new(k) = z\_col(nz+1)}
\DoxyCodeLine{674           \textcolor{keywordflow}{if} (rt >= ppoly\_i\_e(nz,2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{675             reliable(k) = .true.}
\DoxyCodeLine{676           \textcolor{keywordflow}{else}}
\DoxyCodeLine{677             reliable(k) = .false.}
\DoxyCodeLine{678 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{679 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{680 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{681 }
\DoxyCodeLine{682       \textcolor{keywordflow}{if} (k\_layer > 0) \textcolor{keywordflow}{then}  \textcolor{comment}{! The new location is inside of layer k\_layer.}}
\DoxyCodeLine{683         \textcolor{comment}{! Note that this is coded assuming that this layer is stably stratified.}}
\DoxyCodeLine{684         \textcolor{keywordflow}{if} (.not.(ppoly\_i\_e(k1,2) > ppoly\_i\_e(k1,1))) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{685           \textcolor{stringliteral}{"build\_grid\_SLight: Erroneously searching for an interface in an unstratified layer."})}
\DoxyCodeLine{686 }
\DoxyCodeLine{687         \textcolor{comment}{! Use the false position method to find the location (degree <= 1) or the first guess.}}
\DoxyCodeLine{688         zf = (rt -\/ ppoly\_i\_e(k1,1)) / (ppoly\_i\_e(k1,2) -\/ ppoly\_i\_e(k1,1))}
\DoxyCodeLine{689 }
\DoxyCodeLine{690         \textcolor{keywordflow}{if} (ppoly\_degree > 1) \textcolor{keywordflow}{then} \textcolor{comment}{! Iterate to find the solution.}}
\DoxyCodeLine{691           a(:) = 0.0 ; a(1) = ppoly\_i\_coefficients(k\_layer,1) -\/ rt}
\DoxyCodeLine{692           \textcolor{keywordflow}{do} m=2,ppoly\_degree+1 ; a(m) = ppoly\_i\_coefficients(k\_layer,m) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{693           \textcolor{comment}{! Bracket the root.}}
\DoxyCodeLine{694           zf1 = 0.0 ; rfn1 = a(1)}
\DoxyCodeLine{695           zf2 = 1.0 ; rfn2 =  a(1) + (a(2) + (a(3) + (a(4) + a(5))))}
\DoxyCodeLine{696           \textcolor{keywordflow}{if} (rfn1 * rfn2 > 0.0) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"build\_grid\_SLight: Bad bracketing."})}
\DoxyCodeLine{697 }
\DoxyCodeLine{698           \textcolor{keywordflow}{do} itt=1,max\_itt}
\DoxyCodeLine{699             rfn = a(1) + zf*(a(2) + zf*(a(3) + zf*(a(4) + zf*a(5))))}
\DoxyCodeLine{700             \textcolor{comment}{! Reset one of the ends of the bracket.}}
\DoxyCodeLine{701             \textcolor{keywordflow}{if} (rfn * rfn1 > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{702               zf1 = zf ; rfn1 = rfn}
\DoxyCodeLine{703             \textcolor{keywordflow}{else}}
\DoxyCodeLine{704               zf2 = zf ; rfn2 = rfn}
\DoxyCodeLine{705 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{706             \textcolor{keywordflow}{if} (rfn1 == rfn2) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{707 }
\DoxyCodeLine{708             drfn\_dzf = (a(2) + zf*(2.0*a(3) + zf*(3.0*a(4) + zf*4.0*a(5))))}
\DoxyCodeLine{709             sgn = 1.0 ; \textcolor{keywordflow}{if} (drfn\_dzf < 0.0) sgn = -\/1.0}
\DoxyCodeLine{710 }
\DoxyCodeLine{711             \textcolor{keywordflow}{if} ((sgn*(zf -\/ rfn) >= zf1 * abs(drfn\_dzf)) .and. \&}
\DoxyCodeLine{712                 (sgn*(zf -\/ rfn) <= zf2 * abs(drfn\_dzf))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{713               delta\_zf = -\/rfn / drfn\_dzf}
\DoxyCodeLine{714               zf = zf + delta\_zf}
\DoxyCodeLine{715             \textcolor{keywordflow}{else} \textcolor{comment}{! Newton's method goes out of bounds, so use a false position method estimate}}
\DoxyCodeLine{716               zf\_prev = zf}
\DoxyCodeLine{717               zf = ( rfn2 * zf1 -\/ rfn1 * zf2 ) / (rfn2 -\/ rfn1)}
\DoxyCodeLine{718               delta\_zf = zf -\/ zf\_prev}
\DoxyCodeLine{719 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{720 }
\DoxyCodeLine{721             \textcolor{keywordflow}{if} (abs(delta\_zf) < tol) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{722 \textcolor{keywordflow}{          enddo}}
\DoxyCodeLine{723 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{724         z\_col\_new(k) = z\_col(k\_layer) + zf * z\_sgn * h\_col(k\_layer)}
\DoxyCodeLine{725         reliable(k) = .true.}
\DoxyCodeLine{726 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{727 }
\DoxyCodeLine{728 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{729 }
\DoxyCodeLine{730 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{731   z\_col\_new(nz+1) = z\_col(nz+1) ; reliable(nz+1) = .true.}
\DoxyCodeLine{732 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__slight_a5ffc8589603f020d1d5af03cfd308154}\label{namespacecoord__slight_a5ffc8589603f020d1d5af03cfd308154}} 
\index{coord\_slight@{coord\_slight}!set\_slight\_params@{set\_slight\_params}}
\index{set\_slight\_params@{set\_slight\_params}!coord\_slight@{coord\_slight}}
\doxysubsubsection{\texorpdfstring{set\_slight\_params()}{set\_slight\_params()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+slight\+::set\+\_\+slight\+\_\+params (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structcoord__slight_1_1slight__cs}{slight\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(\+:), intent(in), optional}]{max\+\_\+interface\+\_\+depths,  }\item[{real, dimension(\+:), intent(in), optional}]{max\+\_\+layer\+\_\+thickness,  }\item[{real, intent(in), optional}]{min\+\_\+thickness,  }\item[{real, intent(in), optional}]{compressibility\+\_\+fraction,  }\item[{real, intent(in), optional}]{dz\+\_\+ml\+\_\+min,  }\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\+\_\+offset,  }\item[{logical, intent(in), optional}]{fix\+\_\+haloclines,  }\item[{real, intent(in), optional}]{halocline\+\_\+filter\+\_\+length,  }\item[{real, intent(in), optional}]{halocline\+\_\+strat\+\_\+tol,  }\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__slight}{coord\+\_\+slight}} module. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Coordinate control structure \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+interface\+\_\+depths} & Maximum depths of interfaces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+layer\+\_\+thickness} & Maximum thicknesses of layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em min\+\_\+thickness} & Minimum thickness allowed when building the new grid through regridding \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em compressibility\+\_\+fraction} & Fraction (between 0 and 1) of compressibility to add to potential density profiles when interpolating for target grid positions. \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+ml\+\_\+min} & The fixed resolution in the topmost S\+Light\+\_\+nkml\+\_\+min layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nz\+\_\+fixed\+\_\+surface} & The number of fixed-\/thickness layers at the top of the model \\
\hline
\mbox{\texttt{ in}}  & {\em rho\+\_\+ml\+\_\+avg\+\_\+depth} & Depth over which to average to determine the mixed layer potential density \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nlay\+\_\+ml\+\_\+offset} & Number of layers to offset the mixed layer density to find resolved stratification \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em fix\+\_\+haloclines} & If true, detect regions with much weaker than based on in-\/situ density, and use a stretched coordinate there. \\
\hline
\mbox{\texttt{ in}}  & {\em halocline\+\_\+filter\+\_\+length} & A length scale over which to filter T \& S when looking for spuriously unstable water mass profiles \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em halocline\+\_\+strat\+\_\+tol} & A value of the stratification ratio that defines a problematic halocline region \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em interp\+\_\+cs} & Controls for interpolation \\
\hline
\end{DoxyParams}


Definition at line 118 of file coord\+\_\+slight.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{118   \textcolor{keywordtype}{type}(slight\_CS),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Coordinate control structure}}
\DoxyCodeLine{119 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \&}
\DoxyCodeLine{120            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: max\_interface\_depths\textcolor{comment}{ !< Maximum depths of interfaces [H ~> m or kg m-\/2]}}
\DoxyCodeLine{121 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \&}
\DoxyCodeLine{122            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: max\_layer\_thickness\textcolor{comment}{  !< Maximum thicknesses of layers [H ~> m or kg m-\/2]}}
\DoxyCodeLine{123 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: min\_thickness\textcolor{comment}{    !< Minimum thickness allowed when building the}}
\DoxyCodeLine{124 \textcolor{comment}{                                      !! new grid through regridding [H ~> m or kg m-\/2]}}
\DoxyCodeLine{125 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: compressibility\_fraction\textcolor{comment}{ !< Fraction (between 0 and 1) of}}
\DoxyCodeLine{126 \textcolor{comment}{                                      !! compressibility to add to potential density profiles when}}
\DoxyCodeLine{127 \textcolor{comment}{                                      !! interpolating for target grid positions. [nondim]}}
\DoxyCodeLine{128 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: dz\_ml\_min\textcolor{comment}{        !< The fixed resolution in the topmost}}
\DoxyCodeLine{129 \textcolor{comment}{                                      !! SLight\_nkml\_min layers [H ~> m or kg m-\/2]}}
\DoxyCodeLine{130   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: nz\_fixed\_surface\textcolor{comment}{ !< The number of fixed-\/thickness layers at the}}
\DoxyCodeLine{131 \textcolor{comment}{                                      !! top of the model}}
\DoxyCodeLine{132 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: Rho\_ML\_avg\_depth\textcolor{comment}{ !< Depth over which to average to determine}}
\DoxyCodeLine{133 \textcolor{comment}{                                      !! the mixed layer potential density [H ~> m or kg m-\/2]}}
\DoxyCodeLine{134 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: nlay\_ML\_offset\textcolor{comment}{   !< Number of layers to offset the mixed layer}}
\DoxyCodeLine{135 \textcolor{comment}{                                      !! density to find resolved stratification [nondim]}}
\DoxyCodeLine{136   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: fix\_haloclines\textcolor{comment}{   !< If true, detect regions with much weaker than}}
\DoxyCodeLine{137 \textcolor{comment}{                                      !! based on in-\/situ density, and use a stretched coordinate there.}}
\DoxyCodeLine{138 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: halocline\_filter\_length\textcolor{comment}{ !< A length scale over which to filter T \& S}}
\DoxyCodeLine{139 \textcolor{comment}{                                      !! when looking for spuriously unstable water mass profiles [H ~> m or kg m-\/2].}}
\DoxyCodeLine{140 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: halocline\_strat\_tol\textcolor{comment}{ !< A value of the stratification ratio that}}
\DoxyCodeLine{141 \textcolor{comment}{                                      !! defines a problematic halocline region [nondim].}}
\DoxyCodeLine{142   \textcolor{keywordtype}{type}(interp\_CS\_type), \&}
\DoxyCodeLine{143            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: interp\_CS\textcolor{comment}{ !< Controls for interpolation}}
\DoxyCodeLine{144 }
\DoxyCodeLine{145   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_slight\_params: CS not associated"})}
\DoxyCodeLine{146 }
\DoxyCodeLine{147   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(max\_interface\_depths)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{148     \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(max\_interface\_depths) /= cs\%nk+1) \&}
\DoxyCodeLine{149       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_slight\_params: max\_interface\_depths inconsistent size"})}
\DoxyCodeLine{150     \textcolor{keyword}{allocate}(cs\%max\_interface\_depths(cs\%nk+1))}
\DoxyCodeLine{151     cs\%max\_interface\_depths(:) = max\_interface\_depths(:)}
\DoxyCodeLine{152 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{153 }
\DoxyCodeLine{154   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(max\_layer\_thickness)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{155     \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(max\_layer\_thickness) /= cs\%nk) \&}
\DoxyCodeLine{156       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_slight\_params: max\_layer\_thickness inconsistent size"})}
\DoxyCodeLine{157     \textcolor{keyword}{allocate}(cs\%max\_layer\_thickness(cs\%nk))}
\DoxyCodeLine{158     cs\%max\_layer\_thickness(:) = max\_layer\_thickness(:)}
\DoxyCodeLine{159 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{160 }
\DoxyCodeLine{161   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) cs\%min\_thickness = min\_thickness}
\DoxyCodeLine{162   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(compressibility\_fraction)) cs\%compressibility\_fraction = compressibility\_fraction}
\DoxyCodeLine{163 }
\DoxyCodeLine{164   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dz\_ml\_min)) cs\%dz\_ml\_min = dz\_ml\_min}
\DoxyCodeLine{165   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(nz\_fixed\_surface)) cs\%nz\_fixed\_surface = nz\_fixed\_surface}
\DoxyCodeLine{166   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(rho\_ml\_avg\_depth)) cs\%Rho\_ML\_avg\_depth = rho\_ml\_avg\_depth}
\DoxyCodeLine{167   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(nlay\_ml\_offset)) cs\%nlay\_ML\_offset = nlay\_ml\_offset}
\DoxyCodeLine{168   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(fix\_haloclines)) cs\%fix\_haloclines = fix\_haloclines}
\DoxyCodeLine{169   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halocline\_filter\_length)) cs\%halocline\_filter\_length = halocline\_filter\_length}
\DoxyCodeLine{170   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halocline\_strat\_tol)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{171     \textcolor{keywordflow}{if} (halocline\_strat\_tol > 1.0) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_slight\_params: "}//\&}
\DoxyCodeLine{172         \textcolor{stringliteral}{"HALOCLINE\_STRAT\_TOL must not exceed 1.0."})}
\DoxyCodeLine{173     cs\%halocline\_strat\_tol = halocline\_strat\_tol}
\DoxyCodeLine{174 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{175 }
\DoxyCodeLine{176   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(interp\_cs)) cs\%interp\_CS = interp\_cs}

\end{DoxyCode}
