\hypertarget{namespacemom__isopycnal__slopes}{}\doxysection{mom\+\_\+isopycnal\+\_\+slopes Module Reference}
\label{namespacemom__isopycnal__slopes}\index{mom\_isopycnal\_slopes@{mom\_isopycnal\_slopes}}


\doxysubsection{Detailed Description}
Calculations of isoneutral slopes and stratification. \doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__isopycnal__slopes_a9a4cbf819be46d9babab62f7f09734c8}{calc\+\_\+isoneutral\+\_\+slopes}} (G, GV, US, h, e, tv, dt\+\_\+kappa\+\_\+smooth, slope\+\_\+x, slope\+\_\+y, N2\+\_\+u, N2\+\_\+v, halo, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculate isopycnal slopes, and optionally return N2 used in calculation. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__isopycnal__slopes_a34691482caaff356da3c5182657dba0d}{vert\+\_\+fill\+\_\+ts}} (h, T\+\_\+in, S\+\_\+in, kappa\+\_\+dt, T\+\_\+f, S\+\_\+f, G, GV, halo\+\_\+here, larger\+\_\+h\+\_\+denom)
\begin{DoxyCompactList}\small\item\em Returns tracer arrays (nominally T and S) with massless layers filled with sensible values, by diffusing vertically with a small but constant diffusivity. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__isopycnal__slopes_a9a4cbf819be46d9babab62f7f09734c8}\label{namespacemom__isopycnal__slopes_a9a4cbf819be46d9babab62f7f09734c8}} 
\index{mom\_isopycnal\_slopes@{mom\_isopycnal\_slopes}!calc\_isoneutral\_slopes@{calc\_isoneutral\_slopes}}
\index{calc\_isoneutral\_slopes@{calc\_isoneutral\_slopes}!mom\_isopycnal\_slopes@{mom\_isopycnal\_slopes}}
\doxysubsubsection{\texorpdfstring{calc\_isoneutral\_slopes()}{calc\_isoneutral\_slopes()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+isopycnal\+\_\+slopes\+::calc\+\_\+isoneutral\+\_\+slopes (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{e,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, intent(in)}]{dt\+\_\+kappa\+\_\+smooth,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke+1), intent(inout)}]{slope\+\_\+x,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke+1), intent(inout)}]{slope\+\_\+y,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke+1), intent(inout), optional}]{N2\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke+1), intent(inout), optional}]{N2\+\_\+v,  }\item[{integer, intent(in), optional}]{halo,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})}



Calculate isopycnal slopes, and optionally return N2 used in calculation. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em e} & Interface heights \mbox{[}Z $\sim$$>$ m\mbox{]} or units given by 1/eta\+\_\+to\+\_\+m) \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em dt\+\_\+kappa\+\_\+smooth} & A smoothing vertical diffusivity times a smoothing timescale \mbox{[}Z2 $\sim$$>$ m2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em slope\+\_\+x} & Isopycnal slope in i-\/direction \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em slope\+\_\+y} & Isopycnal slope in j-\/direction \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em n2\+\_\+u} & Brunt-\/\+Vaisala frequency squared at \\
\hline
\mbox{\texttt{ in,out}}  & {\em n2\+\_\+v} & Brunt-\/\+Vaisala frequency squared at \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & Halo width over which to compute \\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 30 of file M\+O\+M\+\_\+isopycnal\+\_\+slopes.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{30   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{31   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{32   \textcolor{keywordtype}{type}(unit\_scale\_type),                       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{33 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},    \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{34 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)},  \textcolor{keywordtype}{intent(in)}    :: e\textcolor{comment}{    !< Interface heights [Z ~> m] or units}}
\DoxyCodeLine{35 \textcolor{comment}{                                                                     !! given by 1/eta\_to\_m)}}
\DoxyCodeLine{36   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                       \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various}}
\DoxyCodeLine{37 \textcolor{comment}{                                                                     !! thermodynamic variables}}
\DoxyCodeLine{38 \textcolor{keywordtype}{  real},                                        \textcolor{keywordtype}{intent(in)}    :: dt\_kappa\_smooth\textcolor{comment}{ !< A smoothing vertical diffusivity}}
\DoxyCodeLine{39 \textcolor{comment}{                                                                     !! times a smoothing timescale [Z2 ~> m2].}}
\DoxyCodeLine{40 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: slope\_x\textcolor{comment}{ !< Isopycnal slope in i-\/direction [nondim]}}
\DoxyCodeLine{41 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: slope\_y\textcolor{comment}{ !< Isopycnal slope in j-\/direction [nondim]}}
\DoxyCodeLine{42 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{43                                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: N2\_u\textcolor{comment}{ !< Brunt-\/Vaisala frequency squared at}}
\DoxyCodeLine{44 \textcolor{comment}{                                                                     !! interfaces between u-\/points [T-\/2 ~> s-\/2]}}
\DoxyCodeLine{45 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{46                                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: N2\_v\textcolor{comment}{ !< Brunt-\/Vaisala frequency squared at}}
\DoxyCodeLine{47 \textcolor{comment}{                                                                     !! interfaces between u-\/points [T-\/2 ~> s-\/2]}}
\DoxyCodeLine{48   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to compute}}
\DoxyCodeLine{49   \textcolor{keywordtype}{type}(ocean\_OBC\_type),              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{  !< Open boundaries control structure.}}
\DoxyCodeLine{50 }
\DoxyCodeLine{51   \textcolor{comment}{! real,                              optional, intent(in)    :: eta\_to\_m !< The conversion factor from the units}}
\DoxyCodeLine{52   \textcolor{comment}{!  (This argument has been tested but for now serves no purpose.)  !! of eta to m; US\%Z\_to\_m by default.}}
\DoxyCodeLine{53   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{54 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G), SZK\_(G))} :: \&}
\DoxyCodeLine{55     T, \&          \textcolor{comment}{! The temperature [degC], with the values in}}
\DoxyCodeLine{56                   \textcolor{comment}{! in massless layers filled vertically by diffusion.}}
\DoxyCodeLine{57     s \textcolor{comment}{!, \&          ! The filled salinity [ppt], with the values in}}
\DoxyCodeLine{58                   \textcolor{comment}{! in massless layers filled vertically by diffusion.}}
\DoxyCodeLine{59 \textcolor{comment}{!    Rho           ! Density itself, when a nonlinear equation of state is not in use [R ~> kg m-\/3].}}
\DoxyCodeLine{60 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G), SZK\_(G)+1)} :: \&}
\DoxyCodeLine{61     pres          \textcolor{comment}{! The pressure at an interface [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{62 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{63     drho\_dT\_u, \&  \textcolor{comment}{! The derivative of density with temperature at u points [R degC-\/1 ~> kg m-\/3 degC-\/1].}}
\DoxyCodeLine{64     drho\_dS\_u     \textcolor{comment}{! The derivative of density with salinity at u points [R ppt-\/1 ~> kg m-\/3 ppt-\/1].}}
\DoxyCodeLine{65 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{66     drho\_dT\_v, \&  \textcolor{comment}{! The derivative of density with temperature at v points [R degC-\/1 ~> kg m-\/3 degC-\/1].}}
\DoxyCodeLine{67     drho\_dS\_v     \textcolor{comment}{! The derivative of density with salinity at v points [R ppt-\/1 ~> kg m-\/3 ppt-\/1].}}
\DoxyCodeLine{68 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{69     T\_u, \&        \textcolor{comment}{! Temperature on the interface at the u-\/point [degC].}}
\DoxyCodeLine{70     S\_u, \&        \textcolor{comment}{! Salinity on the interface at the u-\/point [ppt].}}
\DoxyCodeLine{71     pres\_u        \textcolor{comment}{! Pressure on the interface at the u-\/point [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{72 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{73     T\_v, \&        \textcolor{comment}{! Temperature on the interface at the v-\/point [degC].}}
\DoxyCodeLine{74     S\_v, \&        \textcolor{comment}{! Salinity on the interface at the v-\/point [ppt].}}
\DoxyCodeLine{75     pres\_v        \textcolor{comment}{! Pressure on the interface at the v-\/point [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{76 \textcolor{keywordtype}{  real} :: drdiA, drdiB  \textcolor{comment}{! Along layer zonal-\/ and meridional-\/ potential density}}
\DoxyCodeLine{77 \textcolor{keywordtype}{  real} :: drdjA, drdjB  \textcolor{comment}{! gradients in the layers above (A) and below (B) the}}
\DoxyCodeLine{78                         \textcolor{comment}{! interface times the grid spacing [R ~> kg m-\/3].}}
\DoxyCodeLine{79 \textcolor{keywordtype}{  real} :: drdkL, drdkR  \textcolor{comment}{! Vertical density differences across an interface [R ~> kg m-\/3].}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real} :: hg2A, hg2B    \textcolor{comment}{! Squares of geometric mean thicknesses [H2 ~> m2 or kg2 m-\/4].}}
\DoxyCodeLine{81 \textcolor{keywordtype}{  real} :: hg2L, hg2R    \textcolor{comment}{! Squares of geometric mean thicknesses [H2 ~> m2 or kg2 m-\/4].}}
\DoxyCodeLine{82 \textcolor{keywordtype}{  real} :: haA, haB, haL, haR  \textcolor{comment}{! Arithmetic mean thicknesses [H ~> m or kg m-\/2].}}
\DoxyCodeLine{83 \textcolor{keywordtype}{  real} :: dzaL, dzaR    \textcolor{comment}{! Temporary thicknesses in eta units [Z ~> m].}}
\DoxyCodeLine{84 \textcolor{keywordtype}{  real} :: wtA, wtB, wtL, wtR  \textcolor{comment}{! Unscaled weights, with various units.}}
\DoxyCodeLine{85 \textcolor{keywordtype}{  real} :: drdx, drdy    \textcolor{comment}{! Zonal and meridional density gradients [R L-\/1 ~> kg m-\/4].}}
\DoxyCodeLine{86 \textcolor{keywordtype}{  real} :: drdz          \textcolor{comment}{! Vertical density gradient [R Z-\/1 ~> kg m-\/4].}}
\DoxyCodeLine{87 \textcolor{keywordtype}{  real} :: Slope         \textcolor{comment}{! The slope of density surfaces, calculated in a way}}
\DoxyCodeLine{88                         \textcolor{comment}{! that is always between -\/1 and 1.}}
\DoxyCodeLine{89 \textcolor{keywordtype}{  real} :: mag\_grad2     \textcolor{comment}{! The squared magnitude of the 3-\/d density gradient [R2 L-\/2 ~> kg2 m-\/8].}}
\DoxyCodeLine{90 \textcolor{keywordtype}{  real} :: slope2\_Ratio  \textcolor{comment}{! The ratio of the slope squared to slope\_max squared.}}
\DoxyCodeLine{91 \textcolor{keywordtype}{  real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{92                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-\/2].}}
\DoxyCodeLine{93 \textcolor{keywordtype}{  real} :: h\_neglect2    \textcolor{comment}{! h\_neglect\string^2 [H2 ~> m2 or kg2 m-\/4].}}
\DoxyCodeLine{94 \textcolor{keywordtype}{  real} :: dz\_neglect    \textcolor{comment}{! A change in interface heighs that is so small it is usually lost}}
\DoxyCodeLine{95                         \textcolor{comment}{! in roundoff and can be neglected [Z ~> m].}}
\DoxyCodeLine{96   \textcolor{keywordtype}{logical} :: use\_EOS    \textcolor{comment}{! If true, density is calculated from T \& S using an equation of state.}}
\DoxyCodeLine{97 \textcolor{keywordtype}{  real} :: G\_Rho0        \textcolor{comment}{! The gravitational acceleration divided by density [Z2 T-\/2 R-\/1 ~> m5 kg-\/2 s-\/2]}}
\DoxyCodeLine{98 \textcolor{keywordtype}{  real} :: Z\_to\_L        \textcolor{comment}{! A conversion factor between from units for e to the}}
\DoxyCodeLine{99                         \textcolor{comment}{! units for lateral distances.}}
\DoxyCodeLine{100 \textcolor{keywordtype}{  real} :: L\_to\_Z        \textcolor{comment}{! A conversion factor between from units for lateral distances}}
\DoxyCodeLine{101                         \textcolor{comment}{! to the units for e.}}
\DoxyCodeLine{102 \textcolor{keywordtype}{  real} :: H\_to\_Z        \textcolor{comment}{! A conversion factor from thickness units to the units of e.}}
\DoxyCodeLine{103 }
\DoxyCodeLine{104   \textcolor{keywordtype}{logical} :: present\_N2\_u, present\_N2\_v}
\DoxyCodeLine{105   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom\_u, EOSdom\_v \textcolor{comment}{! Domains for the equation of state calculations at u and v points}}
\DoxyCodeLine{106   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz, IsdB}
\DoxyCodeLine{107   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{108   \textcolor{keywordtype}{integer} :: l\_seg}
\DoxyCodeLine{109   \textcolor{keywordtype}{logical} :: local\_open\_u\_BC, local\_open\_v\_BC}
\DoxyCodeLine{110 }
\DoxyCodeLine{111   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{112     is = g\%isc-\/halo ; ie = g\%iec+halo ; js = g\%jsc-\/halo ; je = g\%jec+halo}
\DoxyCodeLine{113   \textcolor{keywordflow}{else}}
\DoxyCodeLine{114     is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{115 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{116   nz = g\%ke ; isdb = g\%IsdB}
\DoxyCodeLine{117 }
\DoxyCodeLine{118   h\_neglect = gv\%H\_subroundoff ; h\_neglect2 = h\_neglect**2}
\DoxyCodeLine{119   z\_to\_l = us\%Z\_to\_L ; h\_to\_z = gv\%H\_to\_Z}
\DoxyCodeLine{120   \textcolor{comment}{! if (present(eta\_to\_m)) then}}
\DoxyCodeLine{121   \textcolor{comment}{!   Z\_to\_L = eta\_to\_m*US\%m\_to\_L ; H\_to\_Z = GV\%H\_to\_m / eta\_to\_m}}
\DoxyCodeLine{122   \textcolor{comment}{! endif}}
\DoxyCodeLine{123   l\_to\_z = 1.0 / z\_to\_l}
\DoxyCodeLine{124   dz\_neglect = gv\%H\_subroundoff * h\_to\_z}
\DoxyCodeLine{125 }
\DoxyCodeLine{126   local\_open\_u\_bc = .false.}
\DoxyCodeLine{127   local\_open\_v\_bc = .false.}
\DoxyCodeLine{128   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{129     local\_open\_u\_bc = obc\%open\_u\_BCs\_exist\_globally}
\DoxyCodeLine{130     local\_open\_v\_bc = obc\%open\_v\_BCs\_exist\_globally}
\DoxyCodeLine{131 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{132 }
\DoxyCodeLine{133   use\_eos = \textcolor{keyword}{associated}(tv\%eqn\_of\_state)}
\DoxyCodeLine{134 }
\DoxyCodeLine{135   present\_n2\_u = \textcolor{keyword}{PRESENT}(n2\_u)}
\DoxyCodeLine{136   present\_n2\_v = \textcolor{keyword}{PRESENT}(n2\_v)}
\DoxyCodeLine{137   g\_rho0 = (us\%L\_to\_Z*l\_to\_z*gv\%g\_Earth) / gv\%Rho0}
\DoxyCodeLine{138   \textcolor{keywordflow}{if} (present\_n2\_u) \textcolor{keywordflow}{then}}
\DoxyCodeLine{139     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{140       n2\_u(i,j,1) = 0.}
\DoxyCodeLine{141       n2\_u(i,j,nz+1) = 0.}
\DoxyCodeLine{142 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{143 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{144   \textcolor{keywordflow}{if} (present\_n2\_v) \textcolor{keywordflow}{then}}
\DoxyCodeLine{145     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{146       n2\_v(i,j,1) = 0.}
\DoxyCodeLine{147       n2\_v(i,j,nz+1) = 0.}
\DoxyCodeLine{148 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{149 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{150 }
\DoxyCodeLine{151   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{152     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{153       \textcolor{keyword}{call }vert\_fill\_ts(h, tv\%T, tv\%S, dt\_kappa\_smooth, t, s, g, gv, halo+1)}
\DoxyCodeLine{154     \textcolor{keywordflow}{else}}
\DoxyCodeLine{155       \textcolor{keyword}{call }vert\_fill\_ts(h, tv\%T, tv\%S, dt\_kappa\_smooth, t, s, g, gv, 1)}
\DoxyCodeLine{156 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{157 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{158 }
\DoxyCodeLine{159   \textcolor{comment}{! Find the maximum and minimum permitted streamfunction.}}
\DoxyCodeLine{160   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%p\_surf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{161     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{162     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{163       pres(i,j,1) = tv\%p\_surf(i,j)}
\DoxyCodeLine{164 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{165   \textcolor{keywordflow}{else}}
\DoxyCodeLine{166     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{167     \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{168       pres(i,j,1) = 0.0}
\DoxyCodeLine{169 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{170 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{171   \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{172   \textcolor{keywordflow}{do} j=js-\/1,je+1}
\DoxyCodeLine{173     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{174       pres(i,j,k+1) = pres(i,j,k) + gv\%g\_Earth * gv\%H\_to\_RZ * h(i,j,k)}
\DoxyCodeLine{175 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{176 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{177 }
\DoxyCodeLine{178   eosdom\_u(1) = is-\/1 -\/ (g\%IsdB-\/1) ; eosdom\_u(2) = ie -\/ (g\%IsdB-\/1)}
\DoxyCodeLine{179 }
\DoxyCodeLine{180   \textcolor{comment}{!\$OMP parallel do default(none) shared(nz,is,ie,js,je,IsdB,use\_EOS,G,GV,US,pres,T,S,tv,h,e, \&}}
\DoxyCodeLine{181   \textcolor{comment}{!\$OMP                                  h\_neglect,dz\_neglect,Z\_to\_L,L\_to\_Z,H\_to\_Z,h\_neglect2, \&}}
\DoxyCodeLine{182   \textcolor{comment}{!\$OMP                                  present\_N2\_u,G\_Rho0,N2\_u,slope\_x,EOSdom\_u,local\_open\_u\_BC, \&}}
\DoxyCodeLine{183   \textcolor{comment}{!\$OMP                                  OBC) \&}}
\DoxyCodeLine{184   \textcolor{comment}{!\$OMP                          private(drdiA,drdiB,drdkL,drdkR,pres\_u,T\_u,S\_u,      \&}}
\DoxyCodeLine{185   \textcolor{comment}{!\$OMP                                  drho\_dT\_u,drho\_dS\_u,hg2A,hg2B,hg2L,hg2R,haA, \&}}
\DoxyCodeLine{186   \textcolor{comment}{!\$OMP                                  haB,haL,haR,dzaL,dzaR,wtA,wtB,wtL,wtR,drdz,  \&}}
\DoxyCodeLine{187   \textcolor{comment}{!\$OMP                                  drdx,mag\_grad2,Slope,slope2\_Ratio,l\_seg)}}
\DoxyCodeLine{188   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=nz,2,-\/1}
\DoxyCodeLine{189     \textcolor{keywordflow}{if} (.not.(use\_eos)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{190       drdia = 0.0 ; drdib = 0.0}
\DoxyCodeLine{191       drdkl = gv\%Rlay(k)-\/gv\%Rlay(k-\/1) ; drdkr = gv\%Rlay(k)-\/gv\%Rlay(k-\/1)}
\DoxyCodeLine{192 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{193 }
\DoxyCodeLine{194     \textcolor{comment}{! Calculate the zonal isopycnal slope.}}
\DoxyCodeLine{195     \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{196       \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{197         pres\_u(i) = 0.5*(pres(i,j,k) + pres(i+1,j,k))}
\DoxyCodeLine{198         t\_u(i) = 0.25*((t(i,j,k) + t(i+1,j,k)) + (t(i,j,k-\/1) + t(i+1,j,k-\/1)))}
\DoxyCodeLine{199         s\_u(i) = 0.25*((s(i,j,k) + s(i+1,j,k)) + (s(i,j,k-\/1) + s(i+1,j,k-\/1)))}
\DoxyCodeLine{200 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{201       \textcolor{keyword}{call }calculate\_density\_derivs(t\_u, s\_u, pres\_u, drho\_dt\_u, drho\_ds\_u, \&}
\DoxyCodeLine{202                                     tv\%eqn\_of\_state, eosdom\_u)}
\DoxyCodeLine{203 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{204 }
\DoxyCodeLine{205     \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{206       \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{207         \textcolor{comment}{! Estimate the horizontal density gradients along layers.}}
\DoxyCodeLine{208         drdia = drho\_dt\_u(i) * (t(i+1,j,k-\/1)-\/t(i,j,k-\/1)) + \&}
\DoxyCodeLine{209                 drho\_ds\_u(i) * (s(i+1,j,k-\/1)-\/s(i,j,k-\/1))}
\DoxyCodeLine{210         drdib = drho\_dt\_u(i) * (t(i+1,j,k)-\/t(i,j,k)) + \&}
\DoxyCodeLine{211                 drho\_ds\_u(i) * (s(i+1,j,k)-\/s(i,j,k))}
\DoxyCodeLine{212 }
\DoxyCodeLine{213         \textcolor{comment}{! Estimate the vertical density gradients times the grid spacing.}}
\DoxyCodeLine{214         drdkl = (drho\_dt\_u(i) * (t(i,j,k)-\/t(i,j,k-\/1)) + \&}
\DoxyCodeLine{215                  drho\_ds\_u(i) * (s(i,j,k)-\/s(i,j,k-\/1)))}
\DoxyCodeLine{216         drdkr = (drho\_dt\_u(i) * (t(i+1,j,k)-\/t(i+1,j,k-\/1)) + \&}
\DoxyCodeLine{217                  drho\_ds\_u(i) * (s(i+1,j,k)-\/s(i+1,j,k-\/1)))}
\DoxyCodeLine{218 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{219 }
\DoxyCodeLine{220 }
\DoxyCodeLine{221       \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{222         hg2a = h(i,j,k-\/1)*h(i+1,j,k-\/1) + h\_neglect2}
\DoxyCodeLine{223         hg2b = h(i,j,k)*h(i+1,j,k) + h\_neglect2}
\DoxyCodeLine{224         hg2l = h(i,j,k-\/1)*h(i,j,k) + h\_neglect2}
\DoxyCodeLine{225         hg2r = h(i+1,j,k-\/1)*h(i+1,j,k) + h\_neglect2}
\DoxyCodeLine{226         haa = 0.5*(h(i,j,k-\/1) + h(i+1,j,k-\/1))}
\DoxyCodeLine{227         hab = 0.5*(h(i,j,k) + h(i+1,j,k)) + h\_neglect}
\DoxyCodeLine{228         hal = 0.5*(h(i,j,k-\/1) + h(i,j,k)) + h\_neglect}
\DoxyCodeLine{229         har = 0.5*(h(i+1,j,k-\/1) + h(i+1,j,k)) + h\_neglect}
\DoxyCodeLine{230         \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{231           dzal = hal * h\_to\_z ; dzar = har * h\_to\_z}
\DoxyCodeLine{232         \textcolor{keywordflow}{else}}
\DoxyCodeLine{233           dzal = 0.5*(e(i,j,k-\/1) -\/ e(i,j,k+1)) + dz\_neglect}
\DoxyCodeLine{234           dzar = 0.5*(e(i+1,j,k-\/1) -\/ e(i+1,j,k+1)) + dz\_neglect}
\DoxyCodeLine{235 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{236         \textcolor{comment}{! Use the harmonic mean thicknesses to weight the horizontal gradients.}}
\DoxyCodeLine{237         \textcolor{comment}{! These unnormalized weights have been rearranged to minimize divisions.}}
\DoxyCodeLine{238         wta = hg2a*hab ; wtb = hg2b*haa}
\DoxyCodeLine{239         wtl = hg2l*(har*dzar) ; wtr = hg2r*(hal*dzal)}
\DoxyCodeLine{240 }
\DoxyCodeLine{241         drdz = (wtl * drdkl + wtr * drdkr) / (dzal*wtl + dzar*wtr)}
\DoxyCodeLine{242         \textcolor{comment}{! The expression for drdz above is mathematically equivalent to:}}
\DoxyCodeLine{243         \textcolor{comment}{!   drdz = ((hg2L/haL) * drdkL/dzaL + (hg2R/haR) * drdkR/dzaR) / \&}}
\DoxyCodeLine{244         \textcolor{comment}{!          ((hg2L/haL) + (hg2R/haR))}}
\DoxyCodeLine{245         \textcolor{comment}{! This is the gradient of density along geopotentials.}}
\DoxyCodeLine{246         drdx = ((wta * drdia + wtb * drdib) / (wta + wtb) -\/ \&}
\DoxyCodeLine{247                 drdz * (e(i,j,k)-\/e(i+1,j,k))) * g\%IdxCu(i,j)}
\DoxyCodeLine{248 }
\DoxyCodeLine{249         \textcolor{comment}{! This estimate of slope is accurate for small slopes, but bounded}}
\DoxyCodeLine{250         \textcolor{comment}{! to be between -\/1 and 1.}}
\DoxyCodeLine{251         mag\_grad2 = drdx**2 + (l\_to\_z*drdz)**2}
\DoxyCodeLine{252         \textcolor{keywordflow}{if} (mag\_grad2 > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{253           slope\_x(i,j,k) = drdx / sqrt(mag\_grad2)}
\DoxyCodeLine{254         \textcolor{keywordflow}{else} \textcolor{comment}{! Just in case mag\_grad2 = 0 ever.}}
\DoxyCodeLine{255           slope\_x(i,j,k) = 0.0}
\DoxyCodeLine{256 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{257 }
\DoxyCodeLine{258         \textcolor{keywordflow}{if} (present\_n2\_u) n2\_u(i,j,k) = g\_rho0 * drdz * g\%mask2dCu(i,j) \textcolor{comment}{! Square of buoyancy frequency [T-\/2 ~> s-\/2]}}
\DoxyCodeLine{259 }
\DoxyCodeLine{260       \textcolor{keywordflow}{else} \textcolor{comment}{! With .not.use\_EOS, the layers are constant density.}}
\DoxyCodeLine{261         slope\_x(i,j,k) = (z\_to\_l*(e(i,j,k)-\/e(i+1,j,k))) * g\%IdxCu(i,j)}
\DoxyCodeLine{262 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{263       \textcolor{keywordflow}{if} (local\_open\_u\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{264         l\_seg = obc\%segnum\_u(i,j)}
\DoxyCodeLine{265         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{266           \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{267             slope\_x(i,j,k) = 0.}
\DoxyCodeLine{268             \textcolor{comment}{! This and/or the masking code below is to make slopes match inside}}
\DoxyCodeLine{269             \textcolor{comment}{! land mask. Might not be necessary except for DEBUG output.}}
\DoxyCodeLine{270 \textcolor{comment}{!           if (OBC\%segment(OBC\%segnum\_u(I,j))\%direction == OBC\_DIRECTION\_E) then}}
\DoxyCodeLine{271 \textcolor{comment}{!             slope\_x(I+1,j,K) = 0.}}
\DoxyCodeLine{272 \textcolor{comment}{!           else}}
\DoxyCodeLine{273 \textcolor{comment}{!             slope\_x(I-\/1,j,K) = 0.}}
\DoxyCodeLine{274 \textcolor{comment}{!           endif}}
\DoxyCodeLine{275 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{276 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{277         slope\_x(i,j,k) = slope\_x(i,j,k) * max(g\%mask2dT(i,j),g\%mask2dT(i+1,j))}
\DoxyCodeLine{278 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{279 }
\DoxyCodeLine{280 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! I}}
\DoxyCodeLine{281 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! end of j-\/loop}}
\DoxyCodeLine{282 }
\DoxyCodeLine{283   eosdom\_v(1) = is -\/ (g\%isd-\/1) ; eosdom\_v(2) = ie -\/ (g\%isd-\/1)}
\DoxyCodeLine{284 }
\DoxyCodeLine{285   \textcolor{comment}{! Calculate the meridional isopycnal slope.}}
\DoxyCodeLine{286   \textcolor{comment}{!\$OMP parallel do default(none) shared(nz,is,ie,js,je,IsdB,use\_EOS,G,GV,US,pres,T,S,tv, \&}}
\DoxyCodeLine{287   \textcolor{comment}{!\$OMP                                  h,h\_neglect,e,dz\_neglect,Z\_to\_L,L\_to\_Z,H\_to\_Z, \&}}
\DoxyCodeLine{288   \textcolor{comment}{!\$OMP                                  h\_neglect2,present\_N2\_v,G\_Rho0,N2\_v,slope\_y,EOSdom\_v, \&}}
\DoxyCodeLine{289   \textcolor{comment}{!\$OMP                                  local\_open\_v\_BC,OBC) \&}}
\DoxyCodeLine{290   \textcolor{comment}{!\$OMP                          private(drdjA,drdjB,drdkL,drdkR,pres\_v,T\_v,S\_v,      \&}}
\DoxyCodeLine{291   \textcolor{comment}{!\$OMP                                  drho\_dT\_v,drho\_dS\_v,hg2A,hg2B,hg2L,hg2R,haA, \&}}
\DoxyCodeLine{292   \textcolor{comment}{!\$OMP                                  haB,haL,haR,dzaL,dzaR,wtA,wtB,wtL,wtR,drdz,  \&}}
\DoxyCodeLine{293   \textcolor{comment}{!\$OMP                                  drdy,mag\_grad2,Slope,slope2\_Ratio,l\_seg)}}
\DoxyCodeLine{294   \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} k=nz,2,-\/1}
\DoxyCodeLine{295     \textcolor{keywordflow}{if} (.not.(use\_eos)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{296       drdja = 0.0 ; drdjb = 0.0}
\DoxyCodeLine{297       drdkl = gv\%Rlay(k)-\/gv\%Rlay(k-\/1) ; drdkr = gv\%Rlay(k)-\/gv\%Rlay(k-\/1)}
\DoxyCodeLine{298 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{299 }
\DoxyCodeLine{300     \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{301       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{302         pres\_v(i) = 0.5*(pres(i,j,k) + pres(i,j+1,k))}
\DoxyCodeLine{303         t\_v(i) = 0.25*((t(i,j,k) + t(i,j+1,k)) + (t(i,j,k-\/1) + t(i,j+1,k-\/1)))}
\DoxyCodeLine{304         s\_v(i) = 0.25*((s(i,j,k) + s(i,j+1,k)) + (s(i,j,k-\/1) + s(i,j+1,k-\/1)))}
\DoxyCodeLine{305 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{306       \textcolor{keyword}{call }calculate\_density\_derivs(t\_v, s\_v, pres\_v, drho\_dt\_v, drho\_ds\_v, tv\%eqn\_of\_state, \&}
\DoxyCodeLine{307                                     eosdom\_v)}
\DoxyCodeLine{308 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{309     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{310       \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{311         \textcolor{comment}{! Estimate the horizontal density gradients along layers.}}
\DoxyCodeLine{312         drdja = drho\_dt\_v(i) * (t(i,j+1,k-\/1)-\/t(i,j,k-\/1)) + \&}
\DoxyCodeLine{313                 drho\_ds\_v(i) * (s(i,j+1,k-\/1)-\/s(i,j,k-\/1))}
\DoxyCodeLine{314         drdjb = drho\_dt\_v(i) * (t(i,j+1,k)-\/t(i,j,k)) + \&}
\DoxyCodeLine{315                 drho\_ds\_v(i) * (s(i,j+1,k)-\/s(i,j,k))}
\DoxyCodeLine{316 }
\DoxyCodeLine{317         \textcolor{comment}{! Estimate the vertical density gradients times the grid spacing.}}
\DoxyCodeLine{318         drdkl = (drho\_dt\_v(i) * (t(i,j,k)-\/t(i,j,k-\/1)) + \&}
\DoxyCodeLine{319                  drho\_ds\_v(i) * (s(i,j,k)-\/s(i,j,k-\/1)))}
\DoxyCodeLine{320         drdkr = (drho\_dt\_v(i) * (t(i,j+1,k)-\/t(i,j+1,k-\/1)) + \&}
\DoxyCodeLine{321                  drho\_ds\_v(i) * (s(i,j+1,k)-\/s(i,j+1,k-\/1)))}
\DoxyCodeLine{322 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{323 }
\DoxyCodeLine{324       \textcolor{keywordflow}{if} (use\_eos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{325         hg2a = h(i,j,k-\/1)*h(i,j+1,k-\/1) + h\_neglect2}
\DoxyCodeLine{326         hg2b = h(i,j,k)*h(i,j+1,k) + h\_neglect2}
\DoxyCodeLine{327         hg2l = h(i,j,k-\/1)*h(i,j,k) + h\_neglect2}
\DoxyCodeLine{328         hg2r = h(i,j+1,k-\/1)*h(i,j+1,k) + h\_neglect2}
\DoxyCodeLine{329         haa = 0.5*(h(i,j,k-\/1) + h(i,j+1,k-\/1)) + h\_neglect}
\DoxyCodeLine{330         hab = 0.5*(h(i,j,k) + h(i,j+1,k)) + h\_neglect}
\DoxyCodeLine{331         hal = 0.5*(h(i,j,k-\/1) + h(i,j,k)) + h\_neglect}
\DoxyCodeLine{332         har = 0.5*(h(i,j+1,k-\/1) + h(i,j+1,k)) + h\_neglect}
\DoxyCodeLine{333         \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{334           dzal = hal * h\_to\_z ; dzar = har * h\_to\_z}
\DoxyCodeLine{335         \textcolor{keywordflow}{else}}
\DoxyCodeLine{336           dzal = 0.5*(e(i,j,k-\/1) -\/ e(i,j,k+1)) + dz\_neglect}
\DoxyCodeLine{337           dzar = 0.5*(e(i,j+1,k-\/1) -\/ e(i,j+1,k+1)) + dz\_neglect}
\DoxyCodeLine{338 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{339         \textcolor{comment}{! Use the harmonic mean thicknesses to weight the horizontal gradients.}}
\DoxyCodeLine{340         \textcolor{comment}{! These unnormalized weights have been rearranged to minimize divisions.}}
\DoxyCodeLine{341         wta = hg2a*hab ; wtb = hg2b*haa}
\DoxyCodeLine{342         wtl = hg2l*(har*dzar) ; wtr = hg2r*(hal*dzal)}
\DoxyCodeLine{343 }
\DoxyCodeLine{344         drdz = (wtl * drdkl + wtr * drdkr) / (dzal*wtl + dzar*wtr)}
\DoxyCodeLine{345         \textcolor{comment}{! The expression for drdz above is mathematically equivalent to:}}
\DoxyCodeLine{346         \textcolor{comment}{!   drdz = ((hg2L/haL) * drdkL/dzaL + (hg2R/haR) * drdkR/dzaR) / \&}}
\DoxyCodeLine{347         \textcolor{comment}{!          ((hg2L/haL) + (hg2R/haR))}}
\DoxyCodeLine{348         \textcolor{comment}{! This is the gradient of density along geopotentials.}}
\DoxyCodeLine{349         drdy = ((wta * drdja + wtb * drdjb) / (wta + wtb) -\/ \&}
\DoxyCodeLine{350                 drdz * (e(i,j,k)-\/e(i,j+1,k))) * g\%IdyCv(i,j)}
\DoxyCodeLine{351 }
\DoxyCodeLine{352         \textcolor{comment}{! This estimate of slope is accurate for small slopes, but bounded}}
\DoxyCodeLine{353         \textcolor{comment}{! to be between -\/1 and 1.}}
\DoxyCodeLine{354         mag\_grad2 = drdy**2 + (l\_to\_z*drdz)**2}
\DoxyCodeLine{355         \textcolor{keywordflow}{if} (mag\_grad2 > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{356           slope\_y(i,j,k) = drdy / sqrt(mag\_grad2)}
\DoxyCodeLine{357         \textcolor{keywordflow}{else} \textcolor{comment}{! Just in case mag\_grad2 = 0 ever.}}
\DoxyCodeLine{358           slope\_y(i,j,k) = 0.0}
\DoxyCodeLine{359 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{360 }
\DoxyCodeLine{361         \textcolor{keywordflow}{if} (present\_n2\_v) n2\_v(i,j,k) = g\_rho0 * drdz * g\%mask2dCv(i,j) \textcolor{comment}{! Square of buoyancy frequency [T-\/2 ~> s-\/2]}}
\DoxyCodeLine{362 }
\DoxyCodeLine{363       \textcolor{keywordflow}{else} \textcolor{comment}{! With .not.use\_EOS, the layers are constant density.}}
\DoxyCodeLine{364         slope\_y(i,j,k) = (z\_to\_l*(e(i,j,k)-\/e(i,j+1,k))) * g\%IdyCv(i,j)}
\DoxyCodeLine{365 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{366       \textcolor{keywordflow}{if} (local\_open\_v\_bc) \textcolor{keywordflow}{then}}
\DoxyCodeLine{367         l\_seg = obc\%segnum\_v(i,j)}
\DoxyCodeLine{368         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}}
\DoxyCodeLine{369           \textcolor{keywordflow}{if} (obc\%segment(l\_seg)\%open) \textcolor{keywordflow}{then}}
\DoxyCodeLine{370             slope\_y(i,j,k) = 0.}
\DoxyCodeLine{371             \textcolor{comment}{! This and/or the masking code below is to make slopes match inside}}
\DoxyCodeLine{372             \textcolor{comment}{! land mask. Might not be necessary except for DEBUG output.}}
\DoxyCodeLine{373 \textcolor{comment}{!           if (OBC\%segment(OBC\%segnum\_v(i,J))\%direction == OBC\_DIRECTION\_N) then}}
\DoxyCodeLine{374 \textcolor{comment}{!             slope\_y(i,J+1,K) = 0.}}
\DoxyCodeLine{375 \textcolor{comment}{!           else}}
\DoxyCodeLine{376 \textcolor{comment}{!             slope\_y(i,J-\/1,K) = 0.}}
\DoxyCodeLine{377 \textcolor{comment}{!           endif}}
\DoxyCodeLine{378 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{379 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{380         slope\_y(i,j,k) = slope\_y(i,j,k) * max(g\%mask2dT(i,j),g\%mask2dT(i,j+1))}
\DoxyCodeLine{381 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{382 }
\DoxyCodeLine{383 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i}}
\DoxyCodeLine{384 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! end of j-\/loop}}
\DoxyCodeLine{385 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__isopycnal__slopes_a34691482caaff356da3c5182657dba0d}\label{namespacemom__isopycnal__slopes_a34691482caaff356da3c5182657dba0d}} 
\index{mom\_isopycnal\_slopes@{mom\_isopycnal\_slopes}!vert\_fill\_ts@{vert\_fill\_ts}}
\index{vert\_fill\_ts@{vert\_fill\_ts}!mom\_isopycnal\_slopes@{mom\_isopycnal\_slopes}}
\doxysubsubsection{\texorpdfstring{vert\_fill\_ts()}{vert\_fill\_ts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+isopycnal\+\_\+slopes\+::vert\+\_\+fill\+\_\+ts (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{T\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{S\+\_\+in,  }\item[{real, intent(in)}]{kappa\+\_\+dt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{T\+\_\+f,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{S\+\_\+f,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{integer, intent(in), optional}]{halo\+\_\+here,  }\item[{logical, intent(in), optional}]{larger\+\_\+h\+\_\+denom }\end{DoxyParamCaption})}



Returns tracer arrays (nominally T and S) with massless layers filled with sensible values, by diffusing vertically with a small but constant diffusivity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+in} & Input temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+in} & Input salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em kappa\+\_\+dt} & A vertical diffusivity to use for smoothing times a smoothing timescale \mbox{[}Z2 $\sim$$>$ m2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+f} & Filled temperature \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em s\+\_\+f} & Filled salinity \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em halo\+\_\+here} & Number of halo points to work on, 0 by default \\
\hline
\mbox{\texttt{ in}}  & {\em larger\+\_\+h\+\_\+denom} & Present and true, add a large enough minimal thickness in the denominator of the flux calculations so that the fluxes are never so large as eliminate the transmission of information across groups of massless layers. \\
\hline
\end{DoxyParams}


Definition at line 391 of file M\+O\+M\+\_\+isopycnal\+\_\+slopes.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{391   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{392   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{393 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{394 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: T\_in\textcolor{comment}{ !< Input temperature [degC]}}
\DoxyCodeLine{395 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}  :: S\_in\textcolor{comment}{ !< Input salinity [ppt]}}
\DoxyCodeLine{396 \textcolor{keywordtype}{  real},                                     \textcolor{keywordtype}{intent(in)}  :: kappa\_dt\textcolor{comment}{ !< A vertical diffusivity to use for smoothing}}
\DoxyCodeLine{397 \textcolor{comment}{                                                                !! times a smoothing timescale [Z2 ~> m2].}}
\DoxyCodeLine{398 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: T\_f\textcolor{comment}{  !< Filled temperature [degC]}}
\DoxyCodeLine{399 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: S\_f\textcolor{comment}{  !< Filled salinity [ppt]}}
\DoxyCodeLine{400   \textcolor{keywordtype}{integer},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\_here\textcolor{comment}{ !< Number of halo points to work on,}}
\DoxyCodeLine{401 \textcolor{comment}{                                                                !! 0 by default}}
\DoxyCodeLine{402   \textcolor{keywordtype}{logical},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: larger\_h\_denom\textcolor{comment}{ !< Present and true, add a large}}
\DoxyCodeLine{403 \textcolor{comment}{                                                                !! enough minimal thickness in the denominator of}}
\DoxyCodeLine{404 \textcolor{comment}{                                                                !! the flux calculations so that the fluxes are}}
\DoxyCodeLine{405 \textcolor{comment}{                                                                !! never so large as eliminate the transmission}}
\DoxyCodeLine{406 \textcolor{comment}{                                                                !! of information across groups of massless layers.}}
\DoxyCodeLine{407   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{408 \textcolor{keywordtype}{  real} :: ent(SZI\_(G),SZK\_(G)+1)   \textcolor{comment}{! The diffusive entrainment (kappa*dt)/dz}}
\DoxyCodeLine{409                                    \textcolor{comment}{! between layers in a timestep [H ~> m or kg m-\/2].}}
\DoxyCodeLine{410 \textcolor{keywordtype}{  real} :: b1(SZI\_(G)), d1(SZI\_(G)) \textcolor{comment}{! b1, c1, and d1 are variables used by the}}
\DoxyCodeLine{411 \textcolor{keywordtype}{  real} :: c1(SZI\_(G),SZK\_(G))      \textcolor{comment}{! tridiagonal solver.}}
\DoxyCodeLine{412 \textcolor{keywordtype}{  real} :: kap\_dt\_x2                \textcolor{comment}{! The 2*kappa\_dt converted to H units [H2 ~> m2 or kg2 m-\/4].}}
\DoxyCodeLine{413 \textcolor{keywordtype}{  real} :: h\_neglect                \textcolor{comment}{! A negligible thickness [H ~> m or kg m-\/2], to allow for zero thicknesses.}}
\DoxyCodeLine{414 \textcolor{keywordtype}{  real} :: h0                       \textcolor{comment}{! A negligible thickness to allow for zero thickness layers without}}
\DoxyCodeLine{415                                    \textcolor{comment}{! completely decouping groups of layers [H ~> m or kg m-\/2].}}
\DoxyCodeLine{416                                    \textcolor{comment}{! Often 0 < h\_neglect << h0.}}
\DoxyCodeLine{417 \textcolor{keywordtype}{  real} :: h\_tr                     \textcolor{comment}{! h\_tr is h at tracer points with a tiny thickness}}
\DoxyCodeLine{418                                    \textcolor{comment}{! added to ensure positive definiteness [H ~> m or kg m-\/2].}}
\DoxyCodeLine{419   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, halo}
\DoxyCodeLine{420 }
\DoxyCodeLine{421   halo=0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo\_here)) halo = max(halo\_here,0)}
\DoxyCodeLine{422 }
\DoxyCodeLine{423   is = g\%isc-\/halo ; ie = g\%iec+halo ; js = g\%jsc-\/halo ; je = g\%jec+halo ; nz = gv\%ke}
\DoxyCodeLine{424 }
\DoxyCodeLine{425   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{426   kap\_dt\_x2 = (2.0*kappa\_dt)*gv\%Z\_to\_H**2}
\DoxyCodeLine{427   h0 = h\_neglect}
\DoxyCodeLine{428   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(larger\_h\_denom)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{429     \textcolor{keywordflow}{if} (larger\_h\_denom) h0 = 1.0e-\/16*sqrt(kappa\_dt)*gv\%Z\_to\_H}
\DoxyCodeLine{430 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{431 }
\DoxyCodeLine{432   \textcolor{keywordflow}{if} (kap\_dt\_x2 <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{433     \textcolor{comment}{!\$OMP parallel do default(shared)}}
\DoxyCodeLine{434     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{435       t\_f(i,j,k) = t\_in(i,j,k) ; s\_f(i,j,k) = s\_in(i,j,k)}
\DoxyCodeLine{436 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{437   \textcolor{keywordflow}{else}}
\DoxyCodeLine{438    \textcolor{comment}{!\$OMP parallel do default(shared) private(ent,b1,d1,c1,h\_tr)}}
\DoxyCodeLine{439     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{440       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{441         ent(i,2) = kap\_dt\_x2 / ((h(i,j,1)+h(i,j,2)) + h0)}
\DoxyCodeLine{442         h\_tr = h(i,j,1) + h\_neglect}
\DoxyCodeLine{443         b1(i) = 1.0 / (h\_tr + ent(i,2))}
\DoxyCodeLine{444         d1(i) = b1(i) * h\_tr}
\DoxyCodeLine{445         t\_f(i,j,1) = (b1(i)*h\_tr)*t\_in(i,j,1)}
\DoxyCodeLine{446         s\_f(i,j,1) = (b1(i)*h\_tr)*s\_in(i,j,1)}
\DoxyCodeLine{447 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{448       \textcolor{keywordflow}{do} k=2,nz-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{449         ent(i,k+1) = kap\_dt\_x2 / ((h(i,j,k)+h(i,j,k+1)) + h0)}
\DoxyCodeLine{450         h\_tr = h(i,j,k) + h\_neglect}
\DoxyCodeLine{451         c1(i,k) = ent(i,k) * b1(i)}
\DoxyCodeLine{452         b1(i) = 1.0 / ((h\_tr + d1(i)*ent(i,k)) + ent(i,k+1))}
\DoxyCodeLine{453         d1(i) = b1(i) * (h\_tr + d1(i)*ent(i,k))}
\DoxyCodeLine{454         t\_f(i,j,k) = b1(i) * (h\_tr*t\_in(i,j,k) + ent(i,k)*t\_f(i,j,k-\/1))}
\DoxyCodeLine{455         s\_f(i,j,k) = b1(i) * (h\_tr*s\_in(i,j,k) + ent(i,k)*s\_f(i,j,k-\/1))}
\DoxyCodeLine{456 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{457       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{458         c1(i,nz) = ent(i,nz) * b1(i)}
\DoxyCodeLine{459         h\_tr = h(i,j,nz) + h\_neglect}
\DoxyCodeLine{460         b1(i) = 1.0 / (h\_tr + d1(i)*ent(i,nz))}
\DoxyCodeLine{461         t\_f(i,j,nz) = b1(i) * (h\_tr*t\_in(i,j,nz) + ent(i,nz)*t\_f(i,j,nz-\/1))}
\DoxyCodeLine{462         s\_f(i,j,nz) = b1(i) * (h\_tr*s\_in(i,j,nz) + ent(i,nz)*s\_f(i,j,nz-\/1))}
\DoxyCodeLine{463 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{464       \textcolor{keywordflow}{do} k=nz-\/1,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{465         t\_f(i,j,k) = t\_f(i,j,k) + c1(i,k+1)*t\_f(i,j,k+1)}
\DoxyCodeLine{466         s\_f(i,j,k) = s\_f(i,j,k) + c1(i,k+1)*s\_f(i,j,k+1)}
\DoxyCodeLine{467 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{468 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{469 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{470 }

\end{DoxyCode}
