\hypertarget{namespacecoord__zlike}{}\section{coord\+\_\+zlike Module Reference}
\label{namespacecoord__zlike}\index{coord\+\_\+zlike@{coord\+\_\+zlike}}


\subsection{Detailed Description}
Regrid columns for a z-\/like coordinate (z-\/star, z-\/level) \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structcoord__zlike_1_1zlike__cs}{zlike\+\_\+cs}
\begin{DoxyCompactList}\small\item\em Control structure containing required parameters for a z-\/like coordinate. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacecoord__zlike_a873f4fca87825e9bb2e216348634f0a7}{init\+\_\+coord\+\_\+zlike} (CS, nk, coordinate\+Resolution)
\begin{DoxyCompactList}\small\item\em Initialise a zlike\+\_\+\+CS with pointers to parameters. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacecoord__zlike_ad51a91fb635a0a5c29fa40bc2534f7b4}{end\+\_\+coord\+\_\+zlike} (CS)
\begin{DoxyCompactList}\small\item\em Deallocates the zlike control structure. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacecoord__zlike_acb2336ed52c2c3ed2509450c61790753}{set\+\_\+zlike\+\_\+params} (CS, min\+\_\+thickness)
\begin{DoxyCompactList}\small\item\em Set parameters in the zlike structure. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacecoord__zlike_af2bdac8481050f2b0ff7c5fc01f26e1c}{build\+\_\+zstar\+\_\+column} (CS, depth, total\+\_\+thickness, z\+Interface, z\+\_\+rigid\+\_\+top, eta\+\_\+orig, z\+Scale)
\begin{DoxyCompactList}\small\item\em Builds a z$\ast$ coordinate with a minimum thickness. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacecoord__zlike_af2bdac8481050f2b0ff7c5fc01f26e1c}\label{namespacecoord__zlike_af2bdac8481050f2b0ff7c5fc01f26e1c}} 
\index{coord\+\_\+zlike@{coord\+\_\+zlike}!build\+\_\+zstar\+\_\+column@{build\+\_\+zstar\+\_\+column}}
\index{build\+\_\+zstar\+\_\+column@{build\+\_\+zstar\+\_\+column}!coord\+\_\+zlike@{coord\+\_\+zlike}}
\subsubsection{\texorpdfstring{build\+\_\+zstar\+\_\+column()}{build\_zstar\_column()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+zlike\+::build\+\_\+zstar\+\_\+column (\begin{DoxyParamCaption}\item[{type(\hyperlink{structcoord__zlike_1_1zlike__cs}{zlike\+\_\+cs}), intent(in)}]{CS,  }\item[{real, intent(in)}]{depth,  }\item[{real, intent(in)}]{total\+\_\+thickness,  }\item[{real, dimension(cs\%nk+1), intent(inout)}]{z\+Interface,  }\item[{real, intent(in), optional}]{z\+\_\+rigid\+\_\+top,  }\item[{real, intent(in), optional}]{eta\+\_\+orig,  }\item[{real, intent(in), optional}]{z\+Scale }\end{DoxyParamCaption})}



Builds a z$\ast$ coordinate with a minimum thickness. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Coordinate control structure\\
\hline
\mbox{\tt in}  & {\em depth} & Depth of ocean bottom (positive downward in the output units), units may be \mbox{[}Z $\sim$$>$ m\mbox{]} or \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em total\+\_\+thickness} & Column thickness (positive definite in the same units as depth) \mbox{[}Z $\sim$$>$ m\mbox{]} or \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em zinterface} & Absolute positions of interfaces\\
\hline
\mbox{\tt in}  & {\em z\+\_\+rigid\+\_\+top} & The height of a rigid top (positive upward in the same units as depth) \mbox{[}Z $\sim$$>$ m\mbox{]} or \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em eta\+\_\+orig} & The actual original height of the top in the same units as depth) \mbox{[}Z $\sim$$>$ m\mbox{]} or \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em zscale} & Scaling factor from the target coordinate resolution in Z to desired units for z\+Interface, perhaps Z\+\_\+to\+\_\+H \\
\hline
\end{DoxyParams}


Definition at line 65 of file coord\+\_\+zlike.\+F90.


\begin{DoxyCode}
65   \textcolor{keywordtype}{type}(zlike\_cs),           \textcolor{keywordtype}{intent(in)}    :: cs\textcolor{comment}{ !< Coordinate control structure}
66   \textcolor{keywordtype}{real},                     \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{ !< Depth of ocean bottom (positive downward in the}
67 \textcolor{comment}{                                                   !! output units), units may be [Z ~> m] or [H ~> m or kg
       m-2]}
68   \textcolor{keywordtype}{real},                     \textcolor{keywordtype}{intent(in)}    :: total\_thickness\textcolor{comment}{ !< Column thickness (positive definite in the
       same}
69 \textcolor{comment}{                                                   !! units as depth) [Z ~> m] or [H ~> m or kg m-2]}
70   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(CS%nk+1)}, \textcolor{keywordtype}{intent(inout)} :: zinterface\textcolor{comment}{ !< Absolute positions of interfaces}
71   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},           \textcolor{keywordtype}{intent(in)}    :: z\_rigid\_top\textcolor{comment}{ !< The height of a rigid top (positive upward in
       the same}
72 \textcolor{comment}{                                                   !! units as depth) [Z ~> m] or [H ~> m or kg m-2]}
73   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},           \textcolor{keywordtype}{intent(in)}    :: eta\_orig\textcolor{comment}{ !< The actual original height of the top in the same}
74 \textcolor{comment}{                                                   !! units as depth) [Z ~> m] or [H ~> m or kg m-2]}
75   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},           \textcolor{keywordtype}{intent(in)}    :: zscale\textcolor{comment}{ !< Scaling factor from the target coordinate resolution}
76 \textcolor{comment}{                                                    !! in Z to desired units for zInterface, perhaps Z\_to\_H}
77   \textcolor{comment}{! Local variables}
78   \textcolor{keywordtype}{real} :: eta   \textcolor{comment}{! Free surface height [Z ~> m] or [H ~> m or kg m-2]}
79   \textcolor{keywordtype}{real} :: stretching \textcolor{comment}{! A stretching factor for the coordinate [nondim]}
80   \textcolor{keywordtype}{real} :: dh, min\_thickness, z0\_top, z\_star, z\_scale \textcolor{comment}{! Thicknesses or heights [Z ~> m] or [H ~> m or kg
       m-2]}
81   \textcolor{keywordtype}{integer} :: k
82   \textcolor{keywordtype}{logical} :: new\_zstar\_def
83 
84   z\_scale = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(zscale)) z\_scale = zscale
85 
86   new\_zstar\_def = .false.
87   min\_thickness = min( cs%min\_thickness, total\_thickness/\textcolor{keywordtype}{real(CS%nk)} )
88   z0\_top = 0.
89   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(z\_rigid\_top)) \textcolor{keywordflow}{then}
90     z0\_top = z\_rigid\_top
91     new\_zstar\_def = .true.
92 \textcolor{keywordflow}{  endif}
93 
94   \textcolor{comment}{! Position of free-surface (or the rigid top, for which eta ~ z0\_top)}
95   eta = total\_thickness - depth
96   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(eta\_orig)) eta = eta\_orig
97 
98   \textcolor{comment}{! Conventional z* coordinate:}
99   \textcolor{comment}{!   z* = (z-eta) / stretching   where stretching = (H+eta)/H}
100   \textcolor{comment}{!   z = eta + stretching * z*}
101   \textcolor{comment}{! The above gives z*(z=eta) = 0, z*(z=-H) = -H.}
102   \textcolor{comment}{! With a rigid top boundary at eta = z0\_top then}
103   \textcolor{comment}{!   z* = z0 + (z-eta) / stretching   where stretching = (H+eta)/(H+z0)}
104   \textcolor{comment}{!   z = eta + stretching * (z*-z0) * stretching}
105   stretching = total\_thickness / ( depth + z0\_top )
106 
107   \textcolor{keywordflow}{if} (new\_zstar\_def) \textcolor{keywordflow}{then}
108     \textcolor{comment}{! z\_star is the notional z* coordinate in absence of upper/lower topography}
109     z\_star = 0. \textcolor{comment}{! z*=0 at the free-surface}
110     zinterface(1) = eta \textcolor{comment}{! The actual position of the top of the column}
111     \textcolor{keywordflow}{do} k = 2,cs%nk
112       z\_star = z\_star - cs%coordinateResolution(k-1)*z\_scale
113       \textcolor{comment}{! This ensures that z is below a rigid upper surface (ice shelf bottom)}
114       zinterface(k) = min( eta + stretching * ( z\_star - z0\_top ), z0\_top )
115       \textcolor{comment}{! This ensures that the layer in inflated}
116       zinterface(k) = min( zinterface(k), zinterface(k-1) - min\_thickness )
117       \textcolor{comment}{! This ensures that z is above or at the topography}
118       zinterface(k) = max( zinterface(k), -depth + \textcolor{keywordtype}{real(CS%nk+1-k)} * min\_thickness )
119 \textcolor{keywordflow}{    enddo}
120     zinterface(cs%nk+1) = -depth
121 
122   \textcolor{keywordflow}{else}
123     \textcolor{comment}{! Integrate down from the top for a notional new grid, ignoring topography}
124     \textcolor{comment}{! The starting position is offset by z0\_top which, if z0\_top<0, will place}
125     \textcolor{comment}{! interfaces above the rigid boundary.}
126     zinterface(1) = eta
127     \textcolor{keywordflow}{do} k = 1,cs%nk
128       dh = stretching * cs%coordinateResolution(k)*z\_scale \textcolor{comment}{! Notional grid spacing}
129       zinterface(k+1) = zinterface(k) - dh
130 \textcolor{keywordflow}{    enddo}
131 
132     \textcolor{comment}{! Integrating up from the bottom adjusting interface position to accommodate}
133     \textcolor{comment}{! inflating layers without disturbing the interface above}
134     zinterface(cs%nk+1) = -depth
135     \textcolor{keywordflow}{do} k = cs%nk,1,-1
136       \textcolor{keywordflow}{if} ( zinterface(k) < (zinterface(k+1) + min\_thickness) ) \textcolor{keywordflow}{then}
137         zinterface(k) = zinterface(k+1) + min\_thickness
138 \textcolor{keywordflow}{      endif}
139 \textcolor{keywordflow}{    enddo}
140 \textcolor{keywordflow}{  endif}
141 
\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__zlike_ad51a91fb635a0a5c29fa40bc2534f7b4}\label{namespacecoord__zlike_ad51a91fb635a0a5c29fa40bc2534f7b4}} 
\index{coord\+\_\+zlike@{coord\+\_\+zlike}!end\+\_\+coord\+\_\+zlike@{end\+\_\+coord\+\_\+zlike}}
\index{end\+\_\+coord\+\_\+zlike@{end\+\_\+coord\+\_\+zlike}!coord\+\_\+zlike@{coord\+\_\+zlike}}
\subsubsection{\texorpdfstring{end\+\_\+coord\+\_\+zlike()}{end\_coord\_zlike()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+zlike\+::end\+\_\+coord\+\_\+zlike (\begin{DoxyParamCaption}\item[{type(\hyperlink{structcoord__zlike_1_1zlike__cs}{zlike\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocates the zlike control structure. 


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


Definition at line 44 of file coord\+\_\+zlike.\+F90.


\begin{DoxyCode}
44   \textcolor{keywordtype}{type}(zlike\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{ !< Coordinate control structure}
45 
46   \textcolor{comment}{! Nothing to do}
47   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
48   \textcolor{keyword}{deallocate}(cs%coordinateResolution)
49   \textcolor{keyword}{deallocate}(cs)
\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__zlike_a873f4fca87825e9bb2e216348634f0a7}\label{namespacecoord__zlike_a873f4fca87825e9bb2e216348634f0a7}} 
\index{coord\+\_\+zlike@{coord\+\_\+zlike}!init\+\_\+coord\+\_\+zlike@{init\+\_\+coord\+\_\+zlike}}
\index{init\+\_\+coord\+\_\+zlike@{init\+\_\+coord\+\_\+zlike}!coord\+\_\+zlike@{coord\+\_\+zlike}}
\subsubsection{\texorpdfstring{init\+\_\+coord\+\_\+zlike()}{init\_coord\_zlike()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+zlike\+::init\+\_\+coord\+\_\+zlike (\begin{DoxyParamCaption}\item[{type(\hyperlink{structcoord__zlike_1_1zlike__cs}{zlike\+\_\+cs}), pointer}]{CS,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(\+:), intent(in)}]{coordinate\+Resolution }\end{DoxyParamCaption})}



Initialise a zlike\+\_\+\+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 levels in the grid\\
\hline
\mbox{\tt in}  & {\em coordinateresolution} & Target coordinate resolution \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 30 of file coord\+\_\+zlike.\+F90.


\begin{DoxyCode}
30   \textcolor{keywordtype}{type}(zlike\_cs),     \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< Unassociated pointer to hold the control structure}
31   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{ !< Number of levels in the grid}
32   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: coordinateresolution\textcolor{comment}{ !< Target coordinate resolution [Z ~> m]}
33 
34   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"init\_coord\_zlike: CS already associated!"})
35   \textcolor{keyword}{allocate}(cs)
36   \textcolor{keyword}{allocate}(cs%coordinateResolution(nk))
37 
38   cs%nk                   = nk
39   cs%coordinateResolution = coordinateresolution
\end{DoxyCode}
\mbox{\Hypertarget{namespacecoord__zlike_acb2336ed52c2c3ed2509450c61790753}\label{namespacecoord__zlike_acb2336ed52c2c3ed2509450c61790753}} 
\index{coord\+\_\+zlike@{coord\+\_\+zlike}!set\+\_\+zlike\+\_\+params@{set\+\_\+zlike\+\_\+params}}
\index{set\+\_\+zlike\+\_\+params@{set\+\_\+zlike\+\_\+params}!coord\+\_\+zlike@{coord\+\_\+zlike}}
\subsubsection{\texorpdfstring{set\+\_\+zlike\+\_\+params()}{set\_zlike\_params()}}
{\footnotesize\ttfamily subroutine, public coord\+\_\+zlike\+::set\+\_\+zlike\+\_\+params (\begin{DoxyParamCaption}\item[{type(\hyperlink{structcoord__zlike_1_1zlike__cs}{zlike\+\_\+cs}), pointer}]{CS,  }\item[{real, intent(in), optional}]{min\+\_\+thickness }\end{DoxyParamCaption})}



Set parameters in the zlike structure. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Coordinate control structure\\
\hline
\mbox{\tt in}  & {\em min\+\_\+thickness} & Minimum allowed thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 54 of file coord\+\_\+zlike.\+F90.


\begin{DoxyCode}
54   \textcolor{keywordtype}{type}(zlike\_cs), \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< Coordinate control structure}
55   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: min\_thickness\textcolor{comment}{ !< Minimum allowed thickness [H ~> m or kg m-2]}
56 
57   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_zlike\_params: CS not associated"})
58 
59   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(min\_thickness)) cs%min\_thickness = min\_thickness
\end{DoxyCode}
