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


\subsection{Detailed Description}
Regrid columns for the S\+Light coordinate. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \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}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \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 \hyperlink{namespacecoord__slight_af5e8c8c13ad380620be3d8907738ed38}{end\+\_\+coord\+\_\+slight} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates memory in the control structure for the \hyperlink{namespacecoord__slight}{coord\+\_\+slight} module. \end{DoxyCompactList}\item 
subroutine, public \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 \hyperlink{namespacecoord__slight}{coord\+\_\+slight} module. \end{DoxyCompactList}\item 
subroutine, public \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 \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}


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



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


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Coordinate control structure\\
\hline
\mbox{\tt in}  & {\em max\+\_\+interface\+\_\+depths} & Maximum depths of interfaces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em max\+\_\+layer\+\_\+thickness} & Maximum thicknesses of layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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{\tt 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{\tt 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{\tt in}  & {\em nz\+\_\+fixed\+\_\+surface} & The number of fixed-\/thickness layers at the top of the model\\
\hline
\mbox{\tt in}  & {\em rho\+\_\+ml\+\_\+avg\+\_\+depth} & Depth over which to average to determine the mixed layer potential density \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em nlay\+\_\+ml\+\_\+offset} & Number of layers to offset the mixed layer density to find resolved stratification \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt 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{\tt 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{\tt in}  & {\em halocline\+\_\+strat\+\_\+tol} & A value of the stratification ratio that defines a problematic halocline region \mbox{[}nondim\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em interp\+\_\+cs} & Controls for interpolation \\
\hline
\end{DoxyParams}


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


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