\hypertarget{namespacemom__diabatic__aux}{}\doxysection{mom\+\_\+diabatic\+\_\+aux Module Reference}
\label{namespacemom__diabatic__aux}\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}}


\doxysubsection{Detailed Description}
Provides functions for some diabatic processes such as fraxil, brine rejection, tendency due to surface flux divergence. 

This module contains the subroutines that, along with the subroutines that it calls, implements diapycnal mass and momentum fluxes and a bulk mixed layer. The diapycnal diffusion can be used without the bulk mixed layer.

diabatic first determines the (diffusive) diapycnal mass fluxes based on the convergence of the buoyancy fluxes within each layer. The dual-\/stream entrainment scheme of Mac\+Dougall and Dewar (J\+PO, 1997) is used for combined diapycnal advection and diffusion, calculated implicitly and potentially with the Richardson number dependent mixing, as described by Hallberg (M\+WR, 2000). Diapycnal advection is fundamentally the residual of diapycnal diffusion, so the fully implicit upwind differencing scheme that is used is entirely appropriate. The downward buoyancy flux in each layer is determined from an implicit calculation based on the previously calculated flux of the layer above and an estimated flux in the layer below. This flux is subject to the following conditions\+: (1) the flux in the top and bottom layers are set by the boundary conditions, and (2) no layer may be driven below an Angstrom thick-\/ ness. If there is a bulk mixed layer, the buffer layer is treat-\/ ed as a fixed density layer with vanishingly small diffusivity.

diabatic takes 5 arguments\+: the two velocities (u and v), the thicknesses (h), a structure containing the forcing fields, and the length of time over which to act (dt). The velocities and thickness are taken as inputs and modified within the subroutine. There is no limit on the time step. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for diabatic\+\_\+aux. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_adb99fd4e2092c17cd69143945733a6d9}{make\+\_\+frazil}} (h, tv, G, GV, US, CS, p\+\_\+surf, halo)
\begin{DoxyCompactList}\small\item\em Frazil formation keeps the temperature above the freezing point. This subroutine warms any water that is colder than the (currently surface) freezing point up to the freezing point and accumulates the required heat (in \mbox{[}Q R Z $\sim$$>$ J m-\/2\mbox{]}) in tvfrazil. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a0b81bac82b18bd9f1e3e5a3beda78966}{differential\+\_\+diffuse\+\_\+t\+\_\+s}} (h, T, S, Kd\+\_\+T, Kd\+\_\+S, dt, G, GV)
\begin{DoxyCompactList}\small\item\em This subroutine applies double diffusion to T \& S, assuming no diapycal mass fluxes, using a simple triadiagonal solver. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a737df97b7e0205b0680c3b901ff6e2ff}{adjust\+\_\+salt}} (h, tv, G, GV, CS, halo)
\begin{DoxyCompactList}\small\item\em This subroutine keeps salinity from falling below a small but positive threshold. This usually occurs when the ice model attempts to extract more salt then is actually available to it from the ocean. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_acde4c76c9a489b82cba0bac5ec1b1198}{tridiagts}} (G, GV, is, ie, js, je, hold, ea, eb, T, S)
\begin{DoxyCompactList}\small\item\em This is a simple tri-\/diagonal solver for T and S. \char`\"{}\+Simple\char`\"{} means it only uses arrays hold, ea and eb. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a3b3416d0ee87cd1a0d54a910fb681e93}{find\+\_\+uv\+\_\+at\+\_\+h}} (u, v, h, u\+\_\+h, v\+\_\+h, G, GV, US, ea, eb)
\begin{DoxyCompactList}\small\item\em This subroutine calculates u\+\_\+h and v\+\_\+h (velocities at thickness points), optionally using the entrainment amounts passed in as arguments. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_adce369573ff355b820320d9c3b048693}{set\+\_\+pen\+\_\+shortwave}} (optics, fluxes, G, GV, US, CS, opacity\+\_\+\+C\+Sp, tracer\+\_\+flow\+\_\+\+C\+Sp)
\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a43ac98433f0f2f0e6cf4f8a3c9622ec4}{diagnosemldbydensitydifference}} (id\+\_\+\+M\+LD, h, tv, density\+Diff, G, GV, US, diag\+Ptr, id\+\_\+\+N2sub\+ML, id\+\_\+\+M\+L\+Dsq, dz\+\_\+sub\+ML)
\begin{DoxyCompactList}\small\item\em Diagnose a mixed layer depth (M\+LD) determined by a given density difference with the surface. This routine is appropriate in M\+O\+M\+\_\+diabatic\+\_\+driver due to its position within the time stepping. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a695474893b92e3e3418a2bed871a5d7e}{diagnosemldbyenergy}} (id\+\_\+\+M\+LD, h, tv, G, GV, US, Mixing\+\_\+\+Energy, diag\+Ptr)
\begin{DoxyCompactList}\small\item\em Diagnose a mixed layer depth (M\+LD) determined by the depth a given energy value would mix. This routine is appropriate in M\+O\+M\+\_\+diabatic\+\_\+driver due to its position within the time stepping. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_ae7a279c765fa370c302532c13a1adaca}{applyboundaryfluxesinout}} (CS, G, GV, US, dt, fluxes, optics, nsw, h, tv, aggregate\+\_\+\+F\+W\+\_\+forcing, evap\+\_\+\+C\+F\+L\+\_\+limit, minimum\+\_\+forcing\+\_\+depth, c\+T\+KE, d\+S\+V\+\_\+dT, d\+S\+V\+\_\+dS, Skin\+Buoy\+Flux)
\begin{DoxyCompactList}\small\item\em Update the thickness, temperature, and salinity due to thermodynamic boundary forcing (contained in fluxes type) applied to h, tvT and tvS, and calculate the T\+KE implications of this heating. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a967697feb7ea22e1430d2b673ebab544}{diabatic\+\_\+aux\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS, use\+A\+L\+Ealgorithm, use\+\_\+e\+P\+BL)
\begin{DoxyCompactList}\small\item\em This subroutine initializes the parameters and control structure of the diabatic\+\_\+aux module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__diabatic__aux_a071e066ca5ed6619c6a9515fb07f5567}{diabatic\+\_\+aux\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine initializes the control structure and any related memory for the diabatic\+\_\+aux module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__diabatic__aux_a1fffddaa09c8650a74e045c2fe29e256}\label{namespacemom__diabatic__aux_a1fffddaa09c8650a74e045c2fe29e256}} 
integer \mbox{\hyperlink{namespacemom__diabatic__aux_a1fffddaa09c8650a74e045c2fe29e256}{id\+\_\+clock\+\_\+uv\+\_\+at\+\_\+h}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__diabatic__aux_a87671b375428f3a27c18c61d6a93d035}\label{namespacemom__diabatic__aux_a87671b375428f3a27c18c61d6a93d035}} 
integer \mbox{\hyperlink{namespacemom__diabatic__aux_a87671b375428f3a27c18c61d6a93d035}{id\+\_\+clock\+\_\+frazil}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\end{DoxyCompactItemize}



\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a737df97b7e0205b0680c3b901ff6e2ff}\label{namespacemom__diabatic__aux_a737df97b7e0205b0680c3b901ff6e2ff}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!adjust\_salt@{adjust\_salt}}
\index{adjust\_salt@{adjust\_salt}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{adjust\_salt()}{adjust\_salt()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::adjust\+\_\+salt (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in), optional}]{halo }\end{DoxyParamCaption})}



This subroutine keeps salinity from falling below a small but positive threshold. This usually occurs when the ice model attempts to extract more salt then is actually available to it from the ocean. 


\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,out}}  & {\em tv} & Structure containing pointers to any available thermodynamic fields. \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & The control structure returned by a previous call to diabatic\+\_\+aux\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & Halo width over which to work \\
\hline
\end{DoxyParams}


Definition at line 323 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{323   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{324   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{325 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{326                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{327   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{   !< Structure containing pointers to any}}
\DoxyCodeLine{328 \textcolor{comment}{                                                 !! available thermodynamic fields.}}
\DoxyCodeLine{329   \textcolor{keywordtype}{type}(diabatic\_aux\_CS),   \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{   !< The control structure returned by a previous}}
\DoxyCodeLine{330 \textcolor{comment}{                                                 !! call to diabatic\_aux\_init.}}
\DoxyCodeLine{331   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to work}}
\DoxyCodeLine{332 }
\DoxyCodeLine{333   \textcolor{comment}{! local variables}}
\DoxyCodeLine{334 \textcolor{keywordtype}{  real} :: salt\_add\_col(SZI\_(G),SZJ\_(G))\textcolor{comment}{ !< The accumulated salt requirement [ppt R Z ~> gSalt m-\/2]}}
\DoxyCodeLine{335 \textcolor{keywordtype}{  real} :: S\_min\textcolor{comment}{      !< The minimum salinity [ppt].}}
\DoxyCodeLine{336 \textcolor{keywordtype}{  real} :: mc\textcolor{comment}{         !< A layer's mass [R Z ~> kg m-\/2].}}
\DoxyCodeLine{337   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{338 }
\DoxyCodeLine{339   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{340   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{341     is = g\%isc-\/halo ; ie = g\%iec+halo ; js = g\%jsc-\/halo ; je = g\%jec+halo}
\DoxyCodeLine{342 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{343 }
\DoxyCodeLine{344 \textcolor{comment}{!  call cpu\_clock\_begin(id\_clock\_adjust\_salt)}}
\DoxyCodeLine{345 }
\DoxyCodeLine{346   s\_min = tv\%min\_salinity}
\DoxyCodeLine{347 }
\DoxyCodeLine{348   salt\_add\_col(:,:) = 0.0}
\DoxyCodeLine{349 }
\DoxyCodeLine{350   \textcolor{comment}{!\$OMP parallel do default(shared) private(mc)}}
\DoxyCodeLine{351   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{352     \textcolor{keywordflow}{do} k=nz,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{353       \textcolor{keywordflow}{if} ( (g\%mask2dT(i,j) > 0.0) .and. \&}
\DoxyCodeLine{354            ((tv\%S(i,j,k) < s\_min) .or. (salt\_add\_col(i,j) > 0.0)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{355         mc = gv\%H\_to\_RZ * h(i,j,k)}
\DoxyCodeLine{356         \textcolor{keywordflow}{if} (h(i,j,k) <= 10.0*gv\%Angstrom\_H) \textcolor{keywordflow}{then}}
\DoxyCodeLine{357           \textcolor{comment}{! Very thin layers should not be adjusted by the salt flux}}
\DoxyCodeLine{358           \textcolor{keywordflow}{if} (tv\%S(i,j,k) < s\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{359             salt\_add\_col(i,j) = salt\_add\_col(i,j) +  mc * (s\_min -\/ tv\%S(i,j,k))}
\DoxyCodeLine{360             tv\%S(i,j,k) = s\_min}
\DoxyCodeLine{361 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{362         \textcolor{keywordflow}{elseif} (salt\_add\_col(i,j) + mc * (s\_min -\/ tv\%S(i,j,k)) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{363           tv\%S(i,j,k) = tv\%S(i,j,k) -\/ salt\_add\_col(i,j) / mc}
\DoxyCodeLine{364           salt\_add\_col(i,j) = 0.0}
\DoxyCodeLine{365         \textcolor{keywordflow}{else}}
\DoxyCodeLine{366           salt\_add\_col(i,j) = salt\_add\_col(i,j) + mc * (s\_min -\/ tv\%S(i,j,k))}
\DoxyCodeLine{367           tv\%S(i,j,k) = s\_min}
\DoxyCodeLine{368 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{369 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{370 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{371     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{372       tv\%salt\_deficit(i,j) = tv\%salt\_deficit(i,j) + salt\_add\_col(i,j)}
\DoxyCodeLine{373 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{374 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{375 \textcolor{comment}{!  call cpu\_clock\_end(id\_clock\_adjust\_salt)}}
\DoxyCodeLine{376 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_ae7a279c765fa370c302532c13a1adaca}\label{namespacemom__diabatic__aux_ae7a279c765fa370c302532c13a1adaca}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!applyboundaryfluxesinout@{applyboundaryfluxesinout}}
\index{applyboundaryfluxesinout@{applyboundaryfluxesinout}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{applyboundaryfluxesinout()}{applyboundaryfluxesinout()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::applyboundaryfluxesinout (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}), pointer}]{CS,  }\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, intent(in)}]{dt,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(optics\+\_\+type), pointer}]{optics,  }\item[{integer, intent(in)}]{nsw,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{logical, intent(in)}]{aggregate\+\_\+\+F\+W\+\_\+forcing,  }\item[{real, intent(in)}]{evap\+\_\+\+C\+F\+L\+\_\+limit,  }\item[{real, intent(in)}]{minimum\+\_\+forcing\+\_\+depth,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{c\+T\+KE,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{d\+S\+V\+\_\+dT,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{d\+S\+V\+\_\+dS,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out), optional}]{Skin\+Buoy\+Flux }\end{DoxyParamCaption})}



Update the thickness, temperature, and salinity due to thermodynamic boundary forcing (contained in fluxes type) applied to h, tvT and tvS, and calculate the T\+KE implications of this heating. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure for diabatic\+\_\+aux \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time-\/step over which forcing is applied \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & Surface fluxes container \\
\hline
 & {\em optics} & Optical properties container \\
\hline
\mbox{\texttt{ in}}  & {\em nsw} & The number of frequency bands of penetrating shortwave radiation \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em tv} & Structure containing pointers to any available thermodynamic fields. \\
\hline
\mbox{\texttt{ in}}  & {\em aggregate\+\_\+fw\+\_\+forcing} & If False, treat in/out fluxes separately. \\
\hline
\mbox{\texttt{ in}}  & {\em evap\+\_\+cfl\+\_\+limit} & The largest fraction of a layer that can be evaporated in one time-\/step \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em minimum\+\_\+forcing\+\_\+depth} & The smallest depth over which heat and freshwater fluxes is applied \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em ctke} & Turbulent kinetic energy requirement to mix \\
\hline
\mbox{\texttt{ out}}  & {\em dsv\+\_\+dt} & Partial derivative of specific volume with \\
\hline
\mbox{\texttt{ out}}  & {\em dsv\+\_\+ds} & Partial derivative of specific volume with \\
\hline
\mbox{\texttt{ out}}  & {\em skinbuoyflux} & Buoyancy flux at surface \mbox{[}Z2 T-\/3 $\sim$$>$ m2 s-\/3\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 932 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{932   \textcolor{keywordtype}{type}(diabatic\_aux\_CS),   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Control structure for diabatic\_aux}}
\DoxyCodeLine{933   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{934   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{935   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{936 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time-\/step over which forcing is applied [T ~> s]}}
\DoxyCodeLine{937   \textcolor{keywordtype}{type}(forcing),           \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< Surface fluxes container}}
\DoxyCodeLine{938   \textcolor{keywordtype}{type}(optics\_type),       \textcolor{keywordtype}{pointer}       :: optics\textcolor{comment}{ !< Optical properties container}}
\DoxyCodeLine{939   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: nsw\textcolor{comment}{ !< The number of frequency bands of penetrating}}
\DoxyCodeLine{940 \textcolor{comment}{                                                !! shortwave radiation}}
\DoxyCodeLine{941 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{942                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{943   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< Structure containing pointers to any}}
\DoxyCodeLine{944 \textcolor{comment}{                                               !! available thermodynamic fields.}}
\DoxyCodeLine{945   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}    :: aggregate\_FW\_forcing\textcolor{comment}{ !< If False, treat in/out fluxes separately.}}
\DoxyCodeLine{946 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: evap\_CFL\_limit\textcolor{comment}{ !< The largest fraction of a layer that}}
\DoxyCodeLine{947 \textcolor{comment}{                                               !! can be evaporated in one time-\/step [nondim].}}
\DoxyCodeLine{948 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: minimum\_forcing\_depth\textcolor{comment}{ !< The smallest depth over which}}
\DoxyCodeLine{949 \textcolor{comment}{                                               !! heat and freshwater fluxes is applied [H ~> m or kg m-\/2].}}
\DoxyCodeLine{950 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{951                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: cTKE\textcolor{comment}{ !< Turbulent kinetic energy requirement to mix}}
\DoxyCodeLine{952 \textcolor{comment}{                                               !! forcing through each layer [R Z3 T-\/2 ~> J m-\/2]}}
\DoxyCodeLine{953 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{954                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: dSV\_dT\textcolor{comment}{ !< Partial derivative of specific volume with}}
\DoxyCodeLine{955 \textcolor{comment}{                                               !! potential temperature [R-\/1 degC-\/1 ~> m3 kg-\/1 degC-\/1].}}
\DoxyCodeLine{956 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{957                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: dSV\_dS\textcolor{comment}{ !< Partial derivative of specific volume with}}
\DoxyCodeLine{958 \textcolor{comment}{                                               !! salinity [R-\/1 ppt-\/1 ~> m3 kg-\/1 ppt-\/1].}}
\DoxyCodeLine{959 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{960                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: SkinBuoyFlux\textcolor{comment}{ !< Buoyancy flux at surface [Z2 T-\/3 ~> m2 s-\/3].}}
\DoxyCodeLine{961 }
\DoxyCodeLine{962   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{963   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: maxGroundings = 5}
\DoxyCodeLine{964   \textcolor{keywordtype}{integer} :: numberOfGroundings, iGround(maxGroundings), jGround(maxGroundings)}
\DoxyCodeLine{965 \textcolor{keywordtype}{  real} :: H\_limit\_fluxes}
\DoxyCodeLine{966 \textcolor{keywordtype}{  real} :: IforcingDepthScale}
\DoxyCodeLine{967 \textcolor{keywordtype}{  real} :: Idt        \textcolor{comment}{! The inverse of the timestep [T-\/1 ~> s-\/1]}}
\DoxyCodeLine{968 \textcolor{keywordtype}{  real} :: dThickness, dTemp, dSalt}
\DoxyCodeLine{969 \textcolor{keywordtype}{  real} :: fractionOfForcing, hOld, Ithickness}
\DoxyCodeLine{970 \textcolor{keywordtype}{  real} :: RivermixConst  \textcolor{comment}{! A constant used in implementing river mixing [R Z2 T-\/1 ~> Pa s].}}
\DoxyCodeLine{971 }
\DoxyCodeLine{972 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{973     d\_pres,       \&  \textcolor{comment}{! pressure change across a layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{974     p\_lay,        \&  \textcolor{comment}{! average pressure in a layer [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{975     pres,         \&  \textcolor{comment}{! pressure at an interface [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{976     netMassInOut, \&  \textcolor{comment}{! surface water fluxes [H ~> m or kg m-\/2] over time step}}
\DoxyCodeLine{977     netMassIn,    \&  \textcolor{comment}{! mass entering ocean surface [H ~> m or kg m-\/2] over a time step}}
\DoxyCodeLine{978     netMassOut,   \&  \textcolor{comment}{! mass leaving ocean surface [H ~> m or kg m-\/2] over a time step}}
\DoxyCodeLine{979     netHeat,      \&  \textcolor{comment}{! heat via surface fluxes excluding Pen\_SW\_bnd and netMassOut}}
\DoxyCodeLine{980                      \textcolor{comment}{! [degC H ~> degC m or degC kg m-\/2]}}
\DoxyCodeLine{981     netsalt,      \&  \textcolor{comment}{! surface salt flux ( g(salt)/m2 for non-\/Bouss and ppt*H for Bouss )}}
\DoxyCodeLine{982                      \textcolor{comment}{! [ppt H ~> ppt m or ppt kg m-\/2]}}
\DoxyCodeLine{983     nonpensw,     \&  \textcolor{comment}{! non-\/downwelling SW, which is absorbed at ocean surface}}
\DoxyCodeLine{984                      \textcolor{comment}{! [degC H ~> degC m or degC kg m-\/2]}}
\DoxyCodeLine{985     surfpressure, \&  \textcolor{comment}{! Surface pressure (approximated as 0.0) [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{986     drhodt,       \&  \textcolor{comment}{! change in density per change in temperature [R degC-\/1 ~> kg m-\/3 degC-\/1]}}
\DoxyCodeLine{987     drhods,       \&  \textcolor{comment}{! change in density per change in salinity [R ppt-\/1 ~> kg m-\/3 ppt-\/1]}}
\DoxyCodeLine{988     netheat\_rate, \&  \textcolor{comment}{! netheat but for dt=1 [degC H T-\/1 ~> degC m s-\/1 or degC kg m-\/2 s-\/1]}}
\DoxyCodeLine{989     netsalt\_rate, \&  \textcolor{comment}{! netsalt but for dt=1 (e.g. returns a rate)}}
\DoxyCodeLine{990                      \textcolor{comment}{! [ppt H T-\/1 ~> ppt m s-\/1 or ppt kg m-\/2 s-\/1]}}
\DoxyCodeLine{991     netmassinout\_rate\textcolor{comment}{! netmassinout but for dt=1 [H T-\/1 ~> m s-\/1 or kg m-\/2 s-\/1]}}
\DoxyCodeLine{992 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZK\_(G))} :: \&}
\DoxyCodeLine{993     h2d, \&           \textcolor{comment}{! A 2-\/d copy of the thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{994     T2d, \&           \textcolor{comment}{! A 2-\/d copy of the layer temperatures [degC]}}
\DoxyCodeLine{995     pen\_TKE\_2d, \&    \textcolor{comment}{! The TKE required to homogenize the heating by shortwave radiation within}}
\DoxyCodeLine{996                      \textcolor{comment}{! a layer [R Z3 T-\/2 ~> J m-\/2]}}
\DoxyCodeLine{997     dsv\_dt\_2d        \textcolor{comment}{! The partial derivative of specific volume with temperature [R-\/1 degC-\/1 ~> m3 kg-\/1 degC-\/1]}}
\DoxyCodeLine{998 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{999     netPen\_rate      \textcolor{comment}{! The surface penetrative shortwave heating rate summed over all bands}}
\DoxyCodeLine{1000                      \textcolor{comment}{! [degC H T-\/1 ~> degC m s-\/1 or degC kg m-\/2 s-\/1]}}
\DoxyCodeLine{1001 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(max(nsw,1),SZI\_(G))} :: \&}
\DoxyCodeLine{1002     Pen\_SW\_bnd, \&    \textcolor{comment}{! The penetrative shortwave heating integrated over a timestep by band}}
\DoxyCodeLine{1003                      \textcolor{comment}{! [degC H ~> degC m or degC kg m-\/2]}}
\DoxyCodeLine{1004     pen\_sw\_bnd\_rate  \textcolor{comment}{! The penetrative shortwave heating rate by band}}
\DoxyCodeLine{1005                      \textcolor{comment}{! [degC H T-\/1 ~> degC m s-\/1 or degC kg m-\/2 s-\/1]}}
\DoxyCodeLine{1006 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(max(nsw,1),SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{1007     opacityBand      \textcolor{comment}{! The opacity (inverse of the exponential absorption length) of each frequency}}
\DoxyCodeLine{1008                      \textcolor{comment}{! band of shortwave radation in each layer [H-\/1 ~> m-\/1 or m2 kg-\/1]}}
\DoxyCodeLine{1009 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(maxGroundings)} :: hGrounding \textcolor{comment}{! Thickness added by each grounding event [H ~> m or kg m-\/2]}}
\DoxyCodeLine{1010 \textcolor{keywordtype}{  real}    :: Temp\_in, Salin\_in}
\DoxyCodeLine{1011 \textcolor{keywordtype}{  real}    :: g\_Hconv2 \textcolor{comment}{! A conversion factor for use in the TKE calculation}}
\DoxyCodeLine{1012                       \textcolor{comment}{! in units of [Z3 R2 T-\/2 H-\/2 ~> kg2 m-\/5 s-\/2 or m s-\/2].}}
\DoxyCodeLine{1013 \textcolor{keywordtype}{  real}    :: GoRho    \textcolor{comment}{! g\_Earth times a unit conversion factor divided by density}}
\DoxyCodeLine{1014                       \textcolor{comment}{! [Z T-\/2 R-\/1 ~> m4 s-\/2 kg-\/1]}}
\DoxyCodeLine{1015   \textcolor{keywordtype}{logical} :: calculate\_energetics}
\DoxyCodeLine{1016   \textcolor{keywordtype}{logical} :: calculate\_buoyancy}
\DoxyCodeLine{1017   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{1018   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, k, nz, n, nb}
\DoxyCodeLine{1019   \textcolor{keywordtype}{character(len=45)} :: mesg}
\DoxyCodeLine{1020 }
\DoxyCodeLine{1021   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{1022 }
\DoxyCodeLine{1023   idt = 1.0 / dt}
\DoxyCodeLine{1024 }
\DoxyCodeLine{1025   calculate\_energetics = (\textcolor{keyword}{present}(ctke) .and. \textcolor{keyword}{present}(dsv\_dt) .and. \textcolor{keyword}{present}(dsv\_ds))}
\DoxyCodeLine{1026   calculate\_buoyancy = \textcolor{keyword}{present}(skinbuoyflux)}
\DoxyCodeLine{1027   \textcolor{keywordflow}{if} (calculate\_buoyancy) skinbuoyflux(:,:) = 0.0}
\DoxyCodeLine{1028   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ctke)) ctke(:,:,:) = 0.0}
\DoxyCodeLine{1029   g\_hconv2 = (us\%L\_to\_Z**2*gv\%g\_Earth * gv\%H\_to\_RZ) * gv\%H\_to\_RZ}
\DoxyCodeLine{1030   eosdom(:) = eos\_domain(g\%HI)}
\DoxyCodeLine{1031 }
\DoxyCodeLine{1032   \textcolor{comment}{! Only apply forcing if fluxes\%sw is associated.}}
\DoxyCodeLine{1033   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(fluxes\%sw) .and. .not.calculate\_energetics) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1034 }
\DoxyCodeLine{1035   \textcolor{keywordflow}{if} (calculate\_buoyancy) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1036     surfpressure(:) = 0.0}
\DoxyCodeLine{1037     gorho = us\%L\_to\_Z**2*gv\%g\_Earth / gv\%Rho0}
\DoxyCodeLine{1038 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1039 }
\DoxyCodeLine{1040   \textcolor{comment}{! H\_limit\_fluxes is used by extractFluxes1d to scale down fluxes if the total}}
\DoxyCodeLine{1041   \textcolor{comment}{! depth of the ocean is vanishing. It does not (yet) handle a value of zero.}}
\DoxyCodeLine{1042   \textcolor{comment}{! To accommodate vanishing upper layers, we need to allow for an instantaneous}}
\DoxyCodeLine{1043   \textcolor{comment}{! distribution of forcing over some finite vertical extent. The bulk mixed layer}}
\DoxyCodeLine{1044   \textcolor{comment}{! code handles this issue properly.}}
\DoxyCodeLine{1045   h\_limit\_fluxes = max(gv\%Angstrom\_H, 1.e-\/30*gv\%m\_to\_H)}
\DoxyCodeLine{1046 }
\DoxyCodeLine{1047   \textcolor{comment}{! diagnostic to see if need to create mass to avoid grounding}}
\DoxyCodeLine{1048   \textcolor{keywordflow}{if} (cs\%id\_createdH>0) cs\%createdH(:,:) = 0.}
\DoxyCodeLine{1049   numberofgroundings = 0}
\DoxyCodeLine{1050 }
\DoxyCodeLine{1051   \textcolor{comment}{!\$OMP parallel do default(none) shared(is,ie,js,je,nz,h,tv,nsw,G,GV,US,optics,fluxes,    \&}}
\DoxyCodeLine{1052   \textcolor{comment}{!\$OMP                                  H\_limit\_fluxes,numberOfGroundings,iGround,jGround,\&}}
\DoxyCodeLine{1053   \textcolor{comment}{!\$OMP                                  nonPenSW,hGrounding,CS,Idt,aggregate\_FW\_forcing,  \&}}
\DoxyCodeLine{1054   \textcolor{comment}{!\$OMP                                  minimum\_forcing\_depth,evap\_CFL\_limit,dt,EOSdom,   \&}}
\DoxyCodeLine{1055   \textcolor{comment}{!\$OMP                                  calculate\_buoyancy,netPen\_rate,SkinBuoyFlux,GoRho, \&}}
\DoxyCodeLine{1056   \textcolor{comment}{!\$OMP                                  calculate\_energetics,dSV\_dT,dSV\_dS,cTKE,g\_Hconv2) \&}}
\DoxyCodeLine{1057   \textcolor{comment}{!\$OMP                          private(opacityBand,h2d,T2d,netMassInOut,netMassOut,      \&}}
\DoxyCodeLine{1058   \textcolor{comment}{!\$OMP                                  netHeat,netSalt,Pen\_SW\_bnd,fractionOfForcing,     \&}}
\DoxyCodeLine{1059   \textcolor{comment}{!\$OMP                                  IforcingDepthScale,                               \&}}
\DoxyCodeLine{1060   \textcolor{comment}{!\$OMP                                  dThickness,dTemp,dSalt,hOld,Ithickness,           \&}}
\DoxyCodeLine{1061   \textcolor{comment}{!\$OMP                                  netMassIn,pres,d\_pres,p\_lay,dSV\_dT\_2d,            \&}}
\DoxyCodeLine{1062   \textcolor{comment}{!\$OMP                                  netmassinout\_rate,netheat\_rate,netsalt\_rate,      \&}}
\DoxyCodeLine{1063   \textcolor{comment}{!\$OMP                                  drhodt,drhods,pen\_sw\_bnd\_rate,                    \&}}
\DoxyCodeLine{1064   \textcolor{comment}{!\$OMP                                  pen\_TKE\_2d,Temp\_in,Salin\_in,RivermixConst)        \&}}
\DoxyCodeLine{1065   \textcolor{comment}{!\$OMP                     firstprivate(SurfPressure)}}
\DoxyCodeLine{1066   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{1067   \textcolor{comment}{! Work in vertical slices for efficiency}}
\DoxyCodeLine{1068 }
\DoxyCodeLine{1069     \textcolor{comment}{! Copy state into 2D-\/slice arrays}}
\DoxyCodeLine{1070     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1071       h2d(i,k) = h(i,j,k)}
\DoxyCodeLine{1072       t2d(i,k) = tv\%T(i,j,k)}
\DoxyCodeLine{1073 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1074 }
\DoxyCodeLine{1075     \textcolor{keywordflow}{if} (calculate\_energetics) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1076       \textcolor{comment}{! The partial derivatives of specific volume with temperature and}}
\DoxyCodeLine{1077       \textcolor{comment}{! salinity need to be precalculated to avoid having heating of}}
\DoxyCodeLine{1078       \textcolor{comment}{! tiny layers give nonsensical values.}}
\DoxyCodeLine{1079       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%p\_surf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1080         \textcolor{keywordflow}{do} i=is,ie ; pres(i) = tv\%p\_surf(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1081       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1082         \textcolor{keywordflow}{do} i=is,ie ; pres(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1083 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1084       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1085         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1086           d\_pres(i) = (gv\%g\_Earth * gv\%H\_to\_RZ) * h2d(i,k)}
\DoxyCodeLine{1087           p\_lay(i) = pres(i) + 0.5*d\_pres(i)}
\DoxyCodeLine{1088           pres(i) = pres(i) + d\_pres(i)}
\DoxyCodeLine{1089 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{1090         \textcolor{keyword}{call }calculate\_specific\_vol\_derivs(t2d(:,k), tv\%S(:,j,k), p\_lay(:), \&}
\DoxyCodeLine{1091                  dsv\_dt(:,j,k), dsv\_ds(:,j,k), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{1092         \textcolor{keywordflow}{do} i=is,ie ; dsv\_dt\_2d(i,k) = dsv\_dt(i,j,k) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1093 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1094       pen\_tke\_2d(:,:) = 0.0}
\DoxyCodeLine{1095 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1096 }
\DoxyCodeLine{1097     \textcolor{comment}{! Nothing more is done on this j-\/slice if there is no buoyancy forcing.}}
\DoxyCodeLine{1098     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(fluxes\%sw)) cycle}
\DoxyCodeLine{1099 }
\DoxyCodeLine{1100     \textcolor{keywordflow}{if} (nsw>0) \textcolor{keyword}{call }extract\_optics\_slice(optics, j, g, gv, opacity=opacityband, opacity\_scale=(1.0/gv\%m\_to\_H))}
\DoxyCodeLine{1101 }
\DoxyCodeLine{1102     \textcolor{comment}{! The surface forcing is contained in the fluxes type.}}
\DoxyCodeLine{1103     \textcolor{comment}{! We aggregate the thermodynamic forcing for a time step into the following:}}
\DoxyCodeLine{1104     \textcolor{comment}{! netMassInOut = surface water fluxes [H ~> m or kg m-\/2] over time step}}
\DoxyCodeLine{1105     \textcolor{comment}{!              = lprec + fprec + vprec + evap + lrunoff + frunoff}}
\DoxyCodeLine{1106     \textcolor{comment}{!                note that lprec generally has sea ice melt/form included.}}
\DoxyCodeLine{1107     \textcolor{comment}{! netMassOut   = net mass leaving ocean surface [H ~> m or kg m-\/2] over a time step.}}
\DoxyCodeLine{1108     \textcolor{comment}{!                netMassOut < 0 means mass leaves ocean.}}
\DoxyCodeLine{1109     \textcolor{comment}{! netHeat      = heat via surface fluxes [degC H ~> degC m or degC kg m-\/2], excluding the part}}
\DoxyCodeLine{1110     \textcolor{comment}{!                contained in Pen\_SW\_bnd; and excluding heat\_content of netMassOut < 0.}}
\DoxyCodeLine{1111     \textcolor{comment}{! netSalt      = surface salt fluxes [ppt H ~> dppt m or gSalt m-\/2]}}
\DoxyCodeLine{1112     \textcolor{comment}{! Pen\_SW\_bnd   = components to penetrative shortwave radiation split according to bands.}}
\DoxyCodeLine{1113     \textcolor{comment}{!                This field provides that portion of SW from atmosphere that in fact}}
\DoxyCodeLine{1114     \textcolor{comment}{!                enters to the ocean and participates in pentrative SW heating.}}
\DoxyCodeLine{1115     \textcolor{comment}{! nonpenSW     = non-\/downwelling SW flux, which is absorbed in ocean surface}}
\DoxyCodeLine{1116     \textcolor{comment}{!                (in tandem w/ LW,SENS,LAT); saved only for diagnostic purposes.}}
\DoxyCodeLine{1117 }
\DoxyCodeLine{1118     \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1119     \textcolor{comment}{!BGR-\/June 26, 2017\{}}
\DoxyCodeLine{1120     \textcolor{comment}{!Temporary action to preserve answers while fixing a bug.}}
\DoxyCodeLine{1121     \textcolor{comment}{! To fix a bug in a diagnostic calculation, applyboundaryfluxesinout now returns}}
\DoxyCodeLine{1122     \textcolor{comment}{!  the surface buoyancy flux. Previously, extractbuoyancyflux2d was called, meaning}}
\DoxyCodeLine{1123     \textcolor{comment}{!  a second call to extractfluxes1d (causing the diagnostic net\_heat to be incorrect).}}
\DoxyCodeLine{1124     \textcolor{comment}{!  Note that this call to extract buoyancyflux2d was AFTER applyboundaryfluxesinout,}}
\DoxyCodeLine{1125     \textcolor{comment}{!  which means it used the T/S fields after this routine.  Therefore, the surface}}
\DoxyCodeLine{1126     \textcolor{comment}{!  buoyancy flux is computed here at the very end of this routine for legacy reasons.}}
\DoxyCodeLine{1127     \textcolor{comment}{!  A few specific notes follow:}}
\DoxyCodeLine{1128     \textcolor{comment}{!     1) The old method did not included river/calving contributions to heat flux.  This}}
\DoxyCodeLine{1129     \textcolor{comment}{!        is kept consistent here via commenting code in the present extractFluxes1d <\_rate>}}
\DoxyCodeLine{1130     \textcolor{comment}{!        outputs, but we may reconsider this approach.}}
\DoxyCodeLine{1131     \textcolor{comment}{!     2) The old method computed the buoyancy flux rate directly (by setting dt=1), instead}}
\DoxyCodeLine{1132     \textcolor{comment}{!        of computing the integrated value (and dividing by dt). Hence the required}}
\DoxyCodeLine{1133     \textcolor{comment}{!        additional outputs from extractFluxes1d.}}
\DoxyCodeLine{1134     \textcolor{comment}{!          *** This is because: A*dt/dt =/=  A due to round off.}}
\DoxyCodeLine{1135     \textcolor{comment}{!     3) The old method computed buoyancy flux after this routine, meaning the returned}}
\DoxyCodeLine{1136     \textcolor{comment}{!        surface fluxes (from extractfluxes1d) must be recorded for use later in the code.}}
\DoxyCodeLine{1137     \textcolor{comment}{!        We could (and maybe should) move that loop up to before the surface fluxes are}}
\DoxyCodeLine{1138     \textcolor{comment}{!        applied, but this will change answers.}}
\DoxyCodeLine{1139     \textcolor{comment}{!     For all these reasons we compute additional values of <\_rate> which are preserved}}
\DoxyCodeLine{1140     \textcolor{comment}{!     for the buoyancy flux calculation and reproduce the old answers.}}
\DoxyCodeLine{1141     \textcolor{comment}{!   In the future this needs more detailed investigation to make sure everything is}}
\DoxyCodeLine{1142     \textcolor{comment}{!   consistent and correct. These details shouldnt significantly effect climate,}}
\DoxyCodeLine{1143     \textcolor{comment}{!   but do change answers.}}
\DoxyCodeLine{1144     \textcolor{comment}{!-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{1145     \textcolor{keywordflow}{if} (calculate\_buoyancy) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1146       \textcolor{keyword}{call }extractfluxes1d(g, gv, us, fluxes, optics, nsw, j, dt,          \&}
\DoxyCodeLine{1147                   h\_limit\_fluxes, cs\%use\_river\_heat\_content, cs\%use\_calving\_heat\_content, \&}
\DoxyCodeLine{1148                   h2d, t2d, netmassinout, netmassout, netheat, netsalt,                   \&}
\DoxyCodeLine{1149                   pen\_sw\_bnd, tv, aggregate\_fw\_forcing, nonpensw=nonpensw,                \&}
\DoxyCodeLine{1150                   net\_heat\_rate=netheat\_rate, net\_salt\_rate=netsalt\_rate,                 \&}
\DoxyCodeLine{1151                   netmassinout\_rate=netmassinout\_rate, pen\_sw\_bnd\_rate=pen\_sw\_bnd\_rate)}
\DoxyCodeLine{1152     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1153       \textcolor{keyword}{call }extractfluxes1d(g, gv, us, fluxes, optics, nsw, j, dt,          \&}
\DoxyCodeLine{1154                   h\_limit\_fluxes, cs\%use\_river\_heat\_content, cs\%use\_calving\_heat\_content, \&}
\DoxyCodeLine{1155                   h2d, t2d, netmassinout, netmassout, netheat, netsalt,                   \&}
\DoxyCodeLine{1156                   pen\_sw\_bnd, tv, aggregate\_fw\_forcing, nonpensw=nonpensw)}
\DoxyCodeLine{1157 \textcolor{keywordflow}{   endif}}
\DoxyCodeLine{1158     \textcolor{comment}{! ea is for passive tracers}}
\DoxyCodeLine{1159     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1160     \textcolor{comment}{!  ea(i,j,1) = netMassInOut(i)}}
\DoxyCodeLine{1161       \textcolor{keywordflow}{if} (aggregate\_fw\_forcing) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1162         netmassout(i) = netmassinout(i)}
\DoxyCodeLine{1163         netmassin(i) = 0.}
\DoxyCodeLine{1164       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1165         netmassin(i) = netmassinout(i) -\/ netmassout(i)}
\DoxyCodeLine{1166 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1167       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1168         fluxes\%netMassOut(i,j) = netmassout(i)}
\DoxyCodeLine{1169         fluxes\%netMassIn(i,j) = netmassin(i)}
\DoxyCodeLine{1170       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1171         fluxes\%netMassOut(i,j) = 0.0}
\DoxyCodeLine{1172         fluxes\%netMassIn(i,j) = 0.0}
\DoxyCodeLine{1173 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1174 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1175 }
\DoxyCodeLine{1176     \textcolor{comment}{! Apply the surface boundary fluxes in three steps:}}
\DoxyCodeLine{1177     \textcolor{comment}{! A/ update mass, temp, and salinity due to all terms except mass leaving}}
\DoxyCodeLine{1178     \textcolor{comment}{!    ocean (and corresponding outward heat content), and ignoring penetrative SW.}}
\DoxyCodeLine{1179     \textcolor{comment}{! B/ update mass, salt, temp from mass leaving ocean.}}
\DoxyCodeLine{1180     \textcolor{comment}{! C/ update temp due to penetrative SW}}
\DoxyCodeLine{1181     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1182       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1183 }
\DoxyCodeLine{1184         \textcolor{comment}{! A/ Update mass, temp, and salinity due to incoming mass flux.}}
\DoxyCodeLine{1185         \textcolor{keywordflow}{do} k=1,1}
\DoxyCodeLine{1186 }
\DoxyCodeLine{1187           \textcolor{comment}{! Change in state due to forcing}}
\DoxyCodeLine{1188           dthickness = netmassin(i) \textcolor{comment}{! Since we are adding mass, we can use all of it}}
\DoxyCodeLine{1189           dtemp = 0.}
\DoxyCodeLine{1190           dsalt = 0.}
\DoxyCodeLine{1191 }
\DoxyCodeLine{1192           \textcolor{comment}{! Update the forcing by the part to be consumed within the present k-\/layer.}}
\DoxyCodeLine{1193           \textcolor{comment}{! If fractionOfForcing = 1, then updated netMassIn, netHeat, and netSalt vanish.}}
\DoxyCodeLine{1194           netmassin(i) = netmassin(i) -\/ dthickness}
\DoxyCodeLine{1195           \textcolor{comment}{! This line accounts for the temperature of the mass exchange}}
\DoxyCodeLine{1196           temp\_in = t2d(i,k)}
\DoxyCodeLine{1197           salin\_in = 0.0}
\DoxyCodeLine{1198           dtemp = dtemp + dthickness*temp\_in}
\DoxyCodeLine{1199 }
\DoxyCodeLine{1200           \textcolor{comment}{! Diagnostics of heat content associated with mass fluxes}}
\DoxyCodeLine{1201           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%heat\_content\_massin))                             \&}
\DoxyCodeLine{1202             fluxes\%heat\_content\_massin(i,j) = fluxes\%heat\_content\_massin(i,j) +   \&}
\DoxyCodeLine{1203                          t2d(i,k) * max(0.,dthickness) * gv\%H\_to\_RZ * fluxes\%C\_p * idt}
\DoxyCodeLine{1204           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%heat\_content\_massout))                            \&}
\DoxyCodeLine{1205             fluxes\%heat\_content\_massout(i,j) = fluxes\%heat\_content\_massout(i,j) + \&}
\DoxyCodeLine{1206                          t2d(i,k) * min(0.,dthickness) * gv\%H\_to\_RZ * fluxes\%C\_p * idt}
\DoxyCodeLine{1207           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%TempxPmE)) tv\%TempxPmE(i,j) = tv\%TempxPmE(i,j) + \&}
\DoxyCodeLine{1208                          t2d(i,k) * dthickness * gv\%H\_to\_RZ}
\DoxyCodeLine{1209 }
\DoxyCodeLine{1210           \textcolor{comment}{! Determine the energetics of river mixing before updating the state.}}
\DoxyCodeLine{1211           \textcolor{keywordflow}{if} (calculate\_energetics .and. \textcolor{keyword}{associated}(fluxes\%lrunoff) .and. cs\%do\_rivermix) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1212             \textcolor{comment}{! Here we add an additional source of TKE to the mixed layer where river}}
\DoxyCodeLine{1213             \textcolor{comment}{! is present to simulate unresolved estuaries. The TKE input, TKE\_river in}}
\DoxyCodeLine{1214             \textcolor{comment}{! [Z3 T-\/3 ~> m3 s-\/3], is diagnosed as follows:}}
\DoxyCodeLine{1215             \textcolor{comment}{!   TKE\_river = 0.5*rivermix\_depth*g*(1/rho)*drho\_ds*}}
\DoxyCodeLine{1216             \textcolor{comment}{!               River*(Samb -\/ Sriver) = CS\%mstar*U\_star\string^3}}
\DoxyCodeLine{1217             \textcolor{comment}{! where River is in units of [Z T-\/1 ~> m s-\/1].}}
\DoxyCodeLine{1218             \textcolor{comment}{! Samb = Ambient salinity at the mouth of the estuary}}
\DoxyCodeLine{1219             \textcolor{comment}{! rivermix\_depth =  The prescribed depth over which to mix river inflow}}
\DoxyCodeLine{1220             \textcolor{comment}{! drho\_ds = The gradient of density wrt salt at the ambient surface salinity.}}
\DoxyCodeLine{1221             \textcolor{comment}{! Sriver = 0 (i.e. rivers are assumed to be pure freshwater)}}
\DoxyCodeLine{1222             \textcolor{keywordflow}{if} (gv\%Boussinesq) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1223               rivermixconst = -\/0.5*(cs\%rivermix\_depth*dt) * ( us\%L\_to\_Z**2*gv\%g\_Earth ) * gv\%Rho0}
\DoxyCodeLine{1224             \textcolor{keywordflow}{else}}
\DoxyCodeLine{1225               rivermixconst = -\/0.5*(cs\%rivermix\_depth*dt) * gv\%Rho0 * ( us\%L\_to\_Z**2*gv\%g\_Earth )}
\DoxyCodeLine{1226 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1227             ctke(i,j,k) = ctke(i,j,k) + max(0.0, rivermixconst*dsv\_ds(i,j,1) * \&}
\DoxyCodeLine{1228                             (fluxes\%lrunoff(i,j) + fluxes\%frunoff(i,j)) * tv\%S(i,j,1))}
\DoxyCodeLine{1229 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1230 }
\DoxyCodeLine{1231           \textcolor{comment}{! Update state}}
\DoxyCodeLine{1232           hold     = h2d(i,k)               \textcolor{comment}{! Keep original thickness in hand}}
\DoxyCodeLine{1233           h2d(i,k) = h2d(i,k) + dthickness  \textcolor{comment}{! New thickness}}
\DoxyCodeLine{1234           \textcolor{keywordflow}{if} (h2d(i,k) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1235             \textcolor{keywordflow}{if} (calculate\_energetics .and. (dthickness > 0.)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1236               \textcolor{comment}{! Calculate the energy required to mix the newly added water over}}
\DoxyCodeLine{1237               \textcolor{comment}{! the topmost grid cell.}}
\DoxyCodeLine{1238               ctke(i,j,k) = ctke(i,j,k) + 0.5*g\_hconv2*(hold*dthickness) * \&}
\DoxyCodeLine{1239                  ((t2d(i,k) -\/ temp\_in) * dsv\_dt(i,j,k) + (tv\%S(i,j,k) -\/ salin\_in) * dsv\_ds(i,j,k))}
\DoxyCodeLine{1240 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1241             ithickness  = 1.0/h2d(i,k)      \textcolor{comment}{! Inverse new thickness}}
\DoxyCodeLine{1242             \textcolor{comment}{! The "if"s below avoid changing T/S by roundoff unnecessarily}}
\DoxyCodeLine{1243             \textcolor{keywordflow}{if} (dthickness /= 0. .or. dtemp /= 0.) t2d(i,k)    = (hold*t2d(i,k)    + dtemp)*ithickness}
\DoxyCodeLine{1244             \textcolor{keywordflow}{if} (dthickness /= 0. .or. dsalt /= 0.) tv\%S(i,j,k) = (hold*tv\%S(i,j,k) + dsalt)*ithickness}
\DoxyCodeLine{1245 }
\DoxyCodeLine{1246 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1247 }
\DoxyCodeLine{1248 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! k=1,1}}
\DoxyCodeLine{1249 }
\DoxyCodeLine{1250         \textcolor{comment}{! B/ Update mass, salt, temp from mass leaving ocean and other fluxes of heat and salt.}}
\DoxyCodeLine{1251         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{1252 }
\DoxyCodeLine{1253           \textcolor{comment}{! Place forcing into this layer if this layer has nontrivial thickness.}}
\DoxyCodeLine{1254           \textcolor{comment}{! For layers thin relative to 1/IforcingDepthScale, then distribute}}
\DoxyCodeLine{1255           \textcolor{comment}{! forcing into deeper layers.}}
\DoxyCodeLine{1256           iforcingdepthscale = 1. / max(gv\%H\_subroundoff, minimum\_forcing\_depth -\/ netmassout(i) )}
\DoxyCodeLine{1257           \textcolor{comment}{! fractionOfForcing = 1.0, unless h2d is less than IforcingDepthScale.}}
\DoxyCodeLine{1258           fractionofforcing = min(1.0, h2d(i,k)*iforcingdepthscale)}
\DoxyCodeLine{1259 }
\DoxyCodeLine{1260           \textcolor{comment}{! In the case with (-\/1)*netMassOut*fractionOfForcing greater than cfl*h, we}}
\DoxyCodeLine{1261           \textcolor{comment}{! limit the forcing applied to this cell, leaving the remaining forcing to}}
\DoxyCodeLine{1262           \textcolor{comment}{! be distributed downwards.}}
\DoxyCodeLine{1263           \textcolor{keywordflow}{if} (-\/fractionofforcing*netmassout(i) > evap\_cfl\_limit*h2d(i,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1264             fractionofforcing = -\/evap\_cfl\_limit*h2d(i,k)/netmassout(i)}
\DoxyCodeLine{1265 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1266 }
\DoxyCodeLine{1267           \textcolor{comment}{! Change in state due to forcing}}
\DoxyCodeLine{1268 }
\DoxyCodeLine{1269           dthickness = max( fractionofforcing*netmassout(i), -\/h2d(i,k) )}
\DoxyCodeLine{1270           dtemp      = fractionofforcing*netheat(i)}
\DoxyCodeLine{1271           \textcolor{comment}{!   \#\#\# The 0.9999 here should become a run-\/time parameter?}}
\DoxyCodeLine{1272           dsalt = max( fractionofforcing*netsalt(i), -\/0.9999*h2d(i,k)*tv\%S(i,j,k))}
\DoxyCodeLine{1273 }
\DoxyCodeLine{1274           \textcolor{comment}{! Update the forcing by the part to be consumed within the present k-\/layer.}}
\DoxyCodeLine{1275           \textcolor{comment}{! If fractionOfForcing = 1, then new netMassOut vanishes.}}
\DoxyCodeLine{1276           netmassout(i) = netmassout(i) -\/ dthickness}
\DoxyCodeLine{1277           netheat(i) = netheat(i) -\/ dtemp}
\DoxyCodeLine{1278           netsalt(i) = netsalt(i) -\/ dsalt}
\DoxyCodeLine{1279 }
\DoxyCodeLine{1280           \textcolor{comment}{! This line accounts for the temperature of the mass exchange}}
\DoxyCodeLine{1281           dtemp = dtemp + dthickness*t2d(i,k)}
\DoxyCodeLine{1282 }
\DoxyCodeLine{1283           \textcolor{comment}{! Diagnostics of heat content associated with mass fluxes}}
\DoxyCodeLine{1284           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%heat\_content\_massin)) \&}
\DoxyCodeLine{1285             fluxes\%heat\_content\_massin(i,j) = fluxes\%heat\_content\_massin(i,j) + \&}
\DoxyCodeLine{1286                          t2d(i,k) * max(0.,dthickness) * gv\%H\_to\_RZ * fluxes\%C\_p * idt}
\DoxyCodeLine{1287           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes\%heat\_content\_massout)) \&}
\DoxyCodeLine{1288             fluxes\%heat\_content\_massout(i,j) = fluxes\%heat\_content\_massout(i,j) + \&}
\DoxyCodeLine{1289                          t2d(i,k) * min(0.,dthickness) * gv\%H\_to\_RZ * fluxes\%C\_p * idt}
\DoxyCodeLine{1290           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%TempxPmE)) tv\%TempxPmE(i,j) = tv\%TempxPmE(i,j) + \&}
\DoxyCodeLine{1291                          t2d(i,k) * dthickness * gv\%H\_to\_RZ}
\DoxyCodeLine{1292 }
\DoxyCodeLine{1293           \textcolor{comment}{! Update state by the appropriate increment.}}
\DoxyCodeLine{1294           hold     = h2d(i,k)               \textcolor{comment}{! Keep original thickness in hand}}
\DoxyCodeLine{1295           h2d(i,k) = h2d(i,k) + dthickness  \textcolor{comment}{! New thickness}}
\DoxyCodeLine{1296 }
\DoxyCodeLine{1297           \textcolor{keywordflow}{if} (h2d(i,k) > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1298             \textcolor{keywordflow}{if} (calculate\_energetics) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1299               \textcolor{comment}{! Calculate the energy required to mix the newly added water over the topmost grid}}
\DoxyCodeLine{1300               \textcolor{comment}{! cell, assuming that the fluxes of heat and salt and rejected brine are initially}}
\DoxyCodeLine{1301               \textcolor{comment}{! applied in vanishingly thin layers at the top of the layer before being mixed}}
\DoxyCodeLine{1302               \textcolor{comment}{! throughout the layer.  Note that dThickness is always <= 0 here, and that}}
\DoxyCodeLine{1303               \textcolor{comment}{! negative cTKE is a deficit that will need to be filled later.}}
\DoxyCodeLine{1304               ctke(i,j,k) = ctke(i,j,k) -\/ (0.5*h2d(i,k)*g\_hconv2) * \&}
\DoxyCodeLine{1305                             ((dtemp -\/ dthickness*t2d(i,k)) * dsv\_dt(i,j,k) + \&}
\DoxyCodeLine{1306                              (dsalt -\/ dthickness*tv\%S(i,j,k)) * dsv\_ds(i,j,k))}
\DoxyCodeLine{1307 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1308             ithickness  = 1.0/h2d(i,k) \textcolor{comment}{! Inverse of new thickness}}
\DoxyCodeLine{1309             t2d(i,k)    = (hold*t2d(i,k) + dtemp)*ithickness}
\DoxyCodeLine{1310             tv\%S(i,j,k) = (hold*tv\%S(i,j,k) + dsalt)*ithickness}
\DoxyCodeLine{1311           \textcolor{keywordflow}{elseif} (h2d(i,k) < 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! h2d==0 is a special limit that needs no extra handling}}
\DoxyCodeLine{1312             \textcolor{keyword}{call }forcing\_singlepointprint(fluxes,g,i,j,\textcolor{stringliteral}{'applyBoundaryFluxesInOut (h<0)'})}
\DoxyCodeLine{1313             \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'applyBoundaryFluxesInOut(): lon,lat='},g\%geoLonT(i,j),g\%geoLatT(i,j)}
\DoxyCodeLine{1314             \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'applyBoundaryFluxesInOut(): netT,netS,netH='},netheat(i),netsalt(i),netmassinout(i)}
\DoxyCodeLine{1315             \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'applyBoundaryFluxesInOut(): dT,dS,dH='},dtemp,dsalt,dthickness}
\DoxyCodeLine{1316             \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'applyBoundaryFluxesInOut(): h(n),h(n+1),k='},hold,h2d(i,k),k}
\DoxyCodeLine{1317             \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_diabatic\_driver.F90, applyBoundaryFluxesInOut(): "}//\&}
\DoxyCodeLine{1318                            \textcolor{stringliteral}{"Complete mass loss in column!"})}
\DoxyCodeLine{1319 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1320 }
\DoxyCodeLine{1321 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! k}}
\DoxyCodeLine{1322 }
\DoxyCodeLine{1323       \textcolor{comment}{! Check if trying to apply fluxes over land points}}
\DoxyCodeLine{1324       \textcolor{keywordflow}{elseif} ((abs(netheat(i))+abs(netsalt(i))+abs(netmassin(i))+abs(netmassout(i)))>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1325 }
\DoxyCodeLine{1326         \textcolor{keywordflow}{if} (.not. cs\%ignore\_fluxes\_over\_land) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1327            \textcolor{keyword}{call }forcing\_singlepointprint(fluxes,g,i,j,\textcolor{stringliteral}{'applyBoundaryFluxesInOut (land)'})}
\DoxyCodeLine{1328            \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'applyBoundaryFluxesInOut(): lon,lat='},g\%geoLonT(i,j),g\%geoLatT(i,j)}
\DoxyCodeLine{1329            \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'applyBoundaryFluxesInOut(): netHeat,netSalt,netMassIn,netMassOut='},\&}
\DoxyCodeLine{1330                    netheat(i),netsalt(i),netmassin(i),netmassout(i)}
\DoxyCodeLine{1331 }
\DoxyCodeLine{1332            \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_diabatic\_driver.F90, applyBoundaryFluxesInOut(): "}//\&}
\DoxyCodeLine{1333                                  \textcolor{stringliteral}{"Mass loss over land?"})}
\DoxyCodeLine{1334 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1335 }
\DoxyCodeLine{1336 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1337 }
\DoxyCodeLine{1338       \textcolor{comment}{! If anything remains after the k-\/loop, then we have grounded out, which is a problem.}}
\DoxyCodeLine{1339       \textcolor{keywordflow}{if} (netmassin(i)+netmassout(i) /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1340 \textcolor{comment}{!\$OMP critical}}
\DoxyCodeLine{1341         numberofgroundings = numberofgroundings +1}
\DoxyCodeLine{1342         \textcolor{keywordflow}{if} (numberofgroundings<=maxgroundings) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1343           iground(numberofgroundings) = i \textcolor{comment}{! Record i,j location of event for}}
\DoxyCodeLine{1344           jground(numberofgroundings) = j \textcolor{comment}{! warning message}}
\DoxyCodeLine{1345           hgrounding(numberofgroundings) = netmassin(i)+netmassout(i)}
\DoxyCodeLine{1346 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1347 \textcolor{comment}{!\$OMP end critical}}
\DoxyCodeLine{1348         \textcolor{keywordflow}{if} (cs\%id\_createdH>0) cs\%createdH(i,j) = cs\%createdH(i,j) -\/ (netmassin(i)+netmassout(i))/dt}
\DoxyCodeLine{1349 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1350 }
\DoxyCodeLine{1351 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i}}
\DoxyCodeLine{1352 }
\DoxyCodeLine{1353     \textcolor{comment}{! Step C/ in the application of fluxes}}
\DoxyCodeLine{1354     \textcolor{comment}{! Heat by the convergence of penetrating SW.}}
\DoxyCodeLine{1355     \textcolor{comment}{! SW penetrative heating uses the updated thickness from above.}}
\DoxyCodeLine{1356 }
\DoxyCodeLine{1357     \textcolor{comment}{! Save temperature before increment with SW heating}}
\DoxyCodeLine{1358     \textcolor{comment}{! and initialize CS\%penSWflux\_diag to zero.}}
\DoxyCodeLine{1359     \textcolor{keywordflow}{if} (cs\%id\_penSW\_diag > 0 .or. cs\%id\_penSWflux\_diag > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1360       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1361         cs\%penSW\_diag(i,j,k)     = t2d(i,k)}
\DoxyCodeLine{1362         cs\%penSWflux\_diag(i,j,k) = 0.0}
\DoxyCodeLine{1363 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1364       k=nz+1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1365         cs\%penSWflux\_diag(i,j,k) = 0.0}
\DoxyCodeLine{1366 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1367 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1368 }
\DoxyCodeLine{1369     \textcolor{keywordflow}{if} (calculate\_energetics) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1370       \textcolor{keyword}{call }absorbremainingsw(g, gv, us, h2d, opacityband, nsw, optics, j, dt, h\_limit\_fluxes, \&}
\DoxyCodeLine{1371                              .false., .true., t2d, pen\_sw\_bnd, tke=pen\_tke\_2d, dsv\_dt=dsv\_dt\_2d)}
\DoxyCodeLine{1372       k = 1 \textcolor{comment}{! For setting break-\/points.}}
\DoxyCodeLine{1373       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1374         ctke(i,j,k) = ctke(i,j,k) + pen\_tke\_2d(i,k)}
\DoxyCodeLine{1375 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1376     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1377       \textcolor{keyword}{call }absorbremainingsw(g, gv, us, h2d, opacityband, nsw, optics, j, dt, h\_limit\_fluxes, \&}
\DoxyCodeLine{1378                              .false., .true., t2d, pen\_sw\_bnd)}
\DoxyCodeLine{1379 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1380 }
\DoxyCodeLine{1381 }
\DoxyCodeLine{1382     \textcolor{comment}{! Step D/ copy updated thickness and temperature}}
\DoxyCodeLine{1383     \textcolor{comment}{! 2d slice now back into model state.}}
\DoxyCodeLine{1384     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1385       h(i,j,k)    = h2d(i,k)}
\DoxyCodeLine{1386       tv\%T(i,j,k) = t2d(i,k)}
\DoxyCodeLine{1387 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1388 }
\DoxyCodeLine{1389     \textcolor{comment}{! Diagnose heating [Q R Z T-\/1 ~> W m-\/2] applied to a grid cell from SW penetration}}
\DoxyCodeLine{1390     \textcolor{comment}{! Also diagnose the penetrative SW heat flux at base of layer.}}
\DoxyCodeLine{1391     \textcolor{keywordflow}{if} (cs\%id\_penSW\_diag > 0 .or. cs\%id\_penSWflux\_diag > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1392 }
\DoxyCodeLine{1393       \textcolor{comment}{! convergence of SW into a layer}}
\DoxyCodeLine{1394       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1395         cs\%penSW\_diag(i,j,k) = (t2d(i,k)-\/cs\%penSW\_diag(i,j,k))*h(i,j,k) * idt * tv\%C\_p * gv\%H\_to\_RZ}
\DoxyCodeLine{1396 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1397 }
\DoxyCodeLine{1398       \textcolor{comment}{! Perform a cumulative sum upwards from bottom to}}
\DoxyCodeLine{1399       \textcolor{comment}{! diagnose penetrative SW flux at base of tracer cell.}}
\DoxyCodeLine{1400       \textcolor{comment}{! CS\%penSWflux\_diag(i,j,k=1)    is penetrative shortwave at top of ocean.}}
\DoxyCodeLine{1401       \textcolor{comment}{! CS\%penSWflux\_diag(i,j,k=kbot+1) is zero, since assume no SW penetrates rock.}}
\DoxyCodeLine{1402       \textcolor{comment}{! CS\%penSWflux\_diag = rsdo  and CS\%penSW\_diag = rsdoabsorb}}
\DoxyCodeLine{1403       \textcolor{comment}{! rsdoabsorb(k) = rsdo(k) -\/ rsdo(k+1), so that rsdo(k) = rsdo(k+1) + rsdoabsorb(k)}}
\DoxyCodeLine{1404       \textcolor{keywordflow}{if} (cs\%id\_penSWflux\_diag > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1405         \textcolor{keywordflow}{do} k=nz,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1406           cs\%penSWflux\_diag(i,j,k) = cs\%penSW\_diag(i,j,k) + cs\%penSWflux\_diag(i,j,k+1)}
\DoxyCodeLine{1407 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1408 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1409 }
\DoxyCodeLine{1410 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1411 }
\DoxyCodeLine{1412     \textcolor{comment}{! Fill CS\%nonpenSW\_diag}}
\DoxyCodeLine{1413     \textcolor{keywordflow}{if} (cs\%id\_nonpenSW\_diag > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1414       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1415         cs\%nonpenSW\_diag(i,j) = nonpensw(i) * idt * tv\%C\_p * gv\%H\_to\_RZ}
\DoxyCodeLine{1416 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1417 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1418 }
\DoxyCodeLine{1419     \textcolor{comment}{! BGR: Get buoyancy flux to return for ePBL}}
\DoxyCodeLine{1420     \textcolor{comment}{!  We want the rate, so we use the rate values returned from extractfluxes1d.}}
\DoxyCodeLine{1421     \textcolor{comment}{!  Note that the *dt values could be divided by dt here, but}}
\DoxyCodeLine{1422     \textcolor{comment}{!  1) Answers will change due to round-\/off}}
\DoxyCodeLine{1423     \textcolor{comment}{!  2) Be sure to save their values BEFORE fluxes are used.}}
\DoxyCodeLine{1424     \textcolor{keywordflow}{if} (calculate\_buoyancy) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1425       drhodt(:) = 0.0}
\DoxyCodeLine{1426       drhods(:) = 0.0}
\DoxyCodeLine{1427       netpen\_rate(:) = 0.0}
\DoxyCodeLine{1428       \textcolor{comment}{! Sum over bands and attenuate as a function of depth.}}
\DoxyCodeLine{1429       \textcolor{comment}{! netPen\_rate is the netSW as a function of depth, but only the surface value is used here,}}
\DoxyCodeLine{1430       \textcolor{comment}{! in which case the values of dt, h, optics and H\_limit\_fluxes are irrelevant.  Consider}}
\DoxyCodeLine{1431       \textcolor{comment}{! writing a shorter and simpler variant to handle this very limited case.}}
\DoxyCodeLine{1432       \textcolor{comment}{! call sumSWoverBands(G, GV, US, h2d(:,:), optics\_nbands(optics), optics, j, dt, \&}}
\DoxyCodeLine{1433       \textcolor{comment}{!                     H\_limit\_fluxes, .true., pen\_SW\_bnd\_rate, netPen)}}
\DoxyCodeLine{1434       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} nb=1,nsw ; netpen\_rate(i) = netpen\_rate(i) + pen\_sw\_bnd\_rate(nb,i) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1435 }
\DoxyCodeLine{1436       \textcolor{comment}{! Density derivatives}}
\DoxyCodeLine{1437       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%p\_surf)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; surfpressure(i) = tv\%p\_surf(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1438       \textcolor{keyword}{call }calculate\_density\_derivs(t2d(:,1), tv\%S(:,j,1), surfpressure, drhodt, drhods, \&}
\DoxyCodeLine{1439                                     tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{1440       \textcolor{comment}{! 1. Adjust netSalt to reflect dilution effect of FW flux}}
\DoxyCodeLine{1441       \textcolor{comment}{! 2. Add in the SW heating for purposes of calculating the net}}
\DoxyCodeLine{1442       \textcolor{comment}{! surface buoyancy flux affecting the top layer.}}
\DoxyCodeLine{1443       \textcolor{comment}{! 3. Convert to a buoyancy flux, excluding penetrating SW heating}}
\DoxyCodeLine{1444       \textcolor{comment}{!    BGR-\/Jul 5, 2017: The contribution of SW heating here needs investigated for ePBL.}}
\DoxyCodeLine{1445       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{1446         skinbuoyflux(i,j) = -\/ gorho * gv\%H\_to\_Z * \&}
\DoxyCodeLine{1447             (drhods(i) * (netsalt\_rate(i) -\/ tv\%S(i,j,1)*netmassinout\_rate(i)) + \&}
\DoxyCodeLine{1448              drhodt(i) * ( netheat\_rate(i) + netpen\_rate(i)) ) \textcolor{comment}{! [Z2 T-\/3 ~> m2 s-\/3]}}
\DoxyCodeLine{1449 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1450 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1451 }
\DoxyCodeLine{1452 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-\/loop finish}}
\DoxyCodeLine{1453 }
\DoxyCodeLine{1454   \textcolor{comment}{! Post the diagnostics}}
\DoxyCodeLine{1455   \textcolor{keywordflow}{if} (cs\%id\_createdH       > 0) \textcolor{keyword}{call }post\_data(cs\%id\_createdH      , cs\%createdH      , cs\%diag)}
\DoxyCodeLine{1456   \textcolor{keywordflow}{if} (cs\%id\_penSW\_diag     > 0) \textcolor{keyword}{call }post\_data(cs\%id\_penSW\_diag    , cs\%penSW\_diag    , cs\%diag)}
\DoxyCodeLine{1457   \textcolor{keywordflow}{if} (cs\%id\_penSWflux\_diag > 0) \textcolor{keyword}{call }post\_data(cs\%id\_penSWflux\_diag, cs\%penSWflux\_diag, cs\%diag)}
\DoxyCodeLine{1458   \textcolor{keywordflow}{if} (cs\%id\_nonpenSW\_diag  > 0) \textcolor{keyword}{call }post\_data(cs\%id\_nonpenSW\_diag , cs\%nonpenSW\_diag , cs\%diag)}
\DoxyCodeLine{1459 }
\DoxyCodeLine{1460 \textcolor{comment}{! The following check will be ignored if ignore\_fluxes\_over\_land = true}}
\DoxyCodeLine{1461   \textcolor{keywordflow}{if} (numberofgroundings>0 .and. .not. cs\%ignore\_fluxes\_over\_land) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1462     \textcolor{keywordflow}{do} i = 1, min(numberofgroundings, maxgroundings)}
\DoxyCodeLine{1463       \textcolor{keyword}{call }forcing\_singlepointprint(fluxes,g,iground(i),jground(i),\textcolor{stringliteral}{'applyBoundaryFluxesInOut (grounding)'})}
\DoxyCodeLine{1464       \textcolor{keyword}{write}(mesg(1:45),\textcolor{stringliteral}{'(3es15.3)'}) g\%geoLonT( iground(i), jground(i) ), \&}
\DoxyCodeLine{1465                              g\%geoLatT( iground(i), jground(i)), hgrounding(i)*gv\%H\_to\_m}
\DoxyCodeLine{1466       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_diabatic\_driver.F90, applyBoundaryFluxesInOut(): "}//\&}
\DoxyCodeLine{1467                               \textcolor{stringliteral}{"Mass created. x,y,dh= "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{1468 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1469 }
\DoxyCodeLine{1470     \textcolor{keywordflow}{if} (numberofgroundings -\/ maxgroundings > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1471       \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(i4)'}) numberofgroundings -\/ maxgroundings}
\DoxyCodeLine{1472       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_diabatic\_driver:F90, applyBoundaryFluxesInOut(): "}//\&}
\DoxyCodeLine{1473                               trim(mesg) // \textcolor{stringliteral}{" groundings remaining"})}
\DoxyCodeLine{1474 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1475 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1476 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a071e066ca5ed6619c6a9515fb07f5567}\label{namespacemom__diabatic__aux_a071e066ca5ed6619c6a9515fb07f5567}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!diabatic\_aux\_end@{diabatic\_aux\_end}}
\index{diabatic\_aux\_end@{diabatic\_aux\_end}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{diabatic\_aux\_end()}{diabatic\_aux\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::diabatic\+\_\+aux\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine initializes the control structure and any related memory for the diabatic\+\_\+aux module. 


\begin{DoxyParams}{Parameters}
{\em cs} & The control structure returned by a previous call to diabatic\+\_\+aux\+\_\+init; it is deallocated here. \\
\hline
\end{DoxyParams}


Definition at line 1645 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1645   \textcolor{keywordtype}{type}(diabatic\_aux\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous}}
\DoxyCodeLine{1646 \textcolor{comment}{                                       !! call to diabatic\_aux\_init; it is deallocated here.}}
\DoxyCodeLine{1647 }
\DoxyCodeLine{1648   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{1649 }
\DoxyCodeLine{1650   \textcolor{keywordflow}{if} (cs\%id\_createdH       >0) \textcolor{keyword}{deallocate}(cs\%createdH)}
\DoxyCodeLine{1651   \textcolor{keywordflow}{if} (cs\%id\_penSW\_diag     >0) \textcolor{keyword}{deallocate}(cs\%penSW\_diag)}
\DoxyCodeLine{1652   \textcolor{keywordflow}{if} (cs\%id\_penSWflux\_diag >0) \textcolor{keyword}{deallocate}(cs\%penSWflux\_diag)}
\DoxyCodeLine{1653   \textcolor{keywordflow}{if} (cs\%id\_nonpenSW\_diag  >0) \textcolor{keyword}{deallocate}(cs\%nonpenSW\_diag)}
\DoxyCodeLine{1654 }
\DoxyCodeLine{1655   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{1656 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a967697feb7ea22e1430d2b673ebab544}\label{namespacemom__diabatic__aux_a967697feb7ea22e1430d2b673ebab544}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!diabatic\_aux\_init@{diabatic\_aux\_init}}
\index{diabatic\_aux\_init@{diabatic\_aux\_init}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{diabatic\_aux\_init()}{diabatic\_aux\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::diabatic\+\_\+aux\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}), pointer}]{CS,  }\item[{logical, intent(in)}]{use\+A\+L\+Ealgorithm,  }\item[{logical, intent(in)}]{use\+\_\+e\+P\+BL }\end{DoxyParamCaption})}



This subroutine initializes the parameters and control structure of the diabatic\+\_\+aux module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\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 param\+\_\+file} & A structure to parse for run-\/time parameters \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & A structure used to regulate diagnostic output \\
\hline
 & {\em cs} & A pointer to the control structure for the diabatic\+\_\+aux module, which is initialized here. \\
\hline
\mbox{\texttt{ in}}  & {\em usealealgorithm} & If true, use the A\+LE algorithm rather than layered mode. \\
\hline
\mbox{\texttt{ in}}  & {\em use\+\_\+epbl} & If true, use the implicit energetics planetary boundary layer scheme to determine the diffusivity in the surface boundary layer. \\
\hline
\end{DoxyParams}


Definition at line 1481 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1481   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< The current model time.}}
\DoxyCodeLine{1482   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1483   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{1484   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{1485   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-\/time parameters}}
\DoxyCodeLine{1486   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< A structure used to regulate diagnostic output}}
\DoxyCodeLine{1487   \textcolor{keywordtype}{type}(diabatic\_aux\_CS),   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< A pointer to the control structure for the}}
\DoxyCodeLine{1488 \textcolor{comment}{                                                 !! diabatic\_aux module, which is initialized here.}}
\DoxyCodeLine{1489   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}    :: useALEalgorithm\textcolor{comment}{ !< If true, use the ALE algorithm rather}}
\DoxyCodeLine{1490 \textcolor{comment}{                                                 !! than layered mode.}}
\DoxyCodeLine{1491   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}    :: use\_ePBL\textcolor{comment}{ !< If true, use the implicit energetics planetary}}
\DoxyCodeLine{1492 \textcolor{comment}{                                                 !! boundary layer scheme to determine the diffusivity}}
\DoxyCodeLine{1493 \textcolor{comment}{                                                 !! in the surface boundary layer.}}
\DoxyCodeLine{1494 }
\DoxyCodeLine{1495 \textcolor{comment}{! This "include" declares and sets the variable "version".}}
\DoxyCodeLine{1496 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{1497 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl  = \textcolor{stringliteral}{"MOM\_diabatic\_aux"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{1498   \textcolor{keywordtype}{character(len=48)}  :: thickness\_units}
\DoxyCodeLine{1499   \textcolor{keywordtype}{character(len=200)} :: inputdir   \textcolor{comment}{! The directory where NetCDF input files}}
\DoxyCodeLine{1500   \textcolor{keywordtype}{character(len=240)} :: chl\_filename \textcolor{comment}{! A file from which chl\_a concentrations are to be read.}}
\DoxyCodeLine{1501   \textcolor{keywordtype}{character(len=128)} :: chl\_file \textcolor{comment}{! Data containing chl\_a concentrations. Used}}
\DoxyCodeLine{1502                                  \textcolor{comment}{! when var\_pen\_sw is defined and reading from file.}}
\DoxyCodeLine{1503   \textcolor{keywordtype}{character(len=32)}  :: chl\_varname \textcolor{comment}{! Name of chl\_a variable in chl\_file.}}
\DoxyCodeLine{1504   \textcolor{keywordtype}{logical} :: use\_temperature     \textcolor{comment}{! True if thermodynamics are enabled.}}
\DoxyCodeLine{1505   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB, nz, nbands}
\DoxyCodeLine{1506   isd  = g\%isd  ; ied  = g\%ied  ; jsd  = g\%jsd  ; jed  = g\%jed ; nz = g\%ke}
\DoxyCodeLine{1507   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{1508 }
\DoxyCodeLine{1509   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1510     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"diabatic\_aux\_init called with an "}// \&}
\DoxyCodeLine{1511                             \textcolor{stringliteral}{"associated control structure."})}
\DoxyCodeLine{1512     \textcolor{keywordflow}{return}}
\DoxyCodeLine{1513   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1514     \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{1515 \textcolor{keywordflow}{   endif}}
\DoxyCodeLine{1516 }
\DoxyCodeLine{1517   cs\%diag => diag}
\DoxyCodeLine{1518   cs\%Time => time}
\DoxyCodeLine{1519 }
\DoxyCodeLine{1520 \textcolor{comment}{! Set default, read and log parameters}}
\DoxyCodeLine{1521   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \&}
\DoxyCodeLine{1522                    \textcolor{stringliteral}{"The following parameters are used for auxiliary diabatic processes."})}
\DoxyCodeLine{1523 }
\DoxyCodeLine{1524   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, use\_temperature, \&}
\DoxyCodeLine{1525                  \textcolor{stringliteral}{"If true, temperature and salinity are used as state "}//\&}
\DoxyCodeLine{1526                  \textcolor{stringliteral}{"variables."}, default=.true.)}
\DoxyCodeLine{1527 }
\DoxyCodeLine{1528   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RECLAIM\_FRAZIL"}, cs\%reclaim\_frazil, \&}
\DoxyCodeLine{1529                  \textcolor{stringliteral}{"If true, try to use any frazil heat deficit to cool any "}//\&}
\DoxyCodeLine{1530                  \textcolor{stringliteral}{"overlying layers down to the freezing point, thereby "}//\&}
\DoxyCodeLine{1531                  \textcolor{stringliteral}{"avoiding the creation of thin ice when the SST is above "}//\&}
\DoxyCodeLine{1532                  \textcolor{stringliteral}{"the freezing point."}, default=.true.)}
\DoxyCodeLine{1533   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRESSURE\_DEPENDENT\_FRAZIL"}, \&}
\DoxyCodeLine{1534                                 cs\%pressure\_dependent\_frazil, \&}
\DoxyCodeLine{1535                  \textcolor{stringliteral}{"If true, use a pressure dependent freezing temperature "}//\&}
\DoxyCodeLine{1536                  \textcolor{stringliteral}{"when making frazil. The default is false, which will be "}//\&}
\DoxyCodeLine{1537                  \textcolor{stringliteral}{"faster but is inappropriate with ice-\/shelf cavities."}, \&}
\DoxyCodeLine{1538                  default=.false.)}
\DoxyCodeLine{1539 }
\DoxyCodeLine{1540   \textcolor{keywordflow}{if} (use\_epbl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1541     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"IGNORE\_FLUXES\_OVER\_LAND"}, cs\%ignore\_fluxes\_over\_land,\&}
\DoxyCodeLine{1542          \textcolor{stringliteral}{"If true, the model does not check if fluxes are being applied "}//\&}
\DoxyCodeLine{1543          \textcolor{stringliteral}{"over land points. This is needed when the ocean is coupled "}//\&}
\DoxyCodeLine{1544          \textcolor{stringliteral}{"with ice shelves and sea ice, since the sea ice mask needs to "}//\&}
\DoxyCodeLine{1545          \textcolor{stringliteral}{"be different than the ocean mask to avoid sea ice formation "}//\&}
\DoxyCodeLine{1546          \textcolor{stringliteral}{"under ice shelves. This flag only works when use\_ePBL = True."}, default=.false.)}
\DoxyCodeLine{1547     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DO\_RIVERMIX"}, cs\%do\_rivermix, \&}
\DoxyCodeLine{1548                  \textcolor{stringliteral}{"If true, apply additional mixing wherever there is "}//\&}
\DoxyCodeLine{1549                  \textcolor{stringliteral}{"runoff, so that it is mixed down to RIVERMIX\_DEPTH "}//\&}
\DoxyCodeLine{1550                  \textcolor{stringliteral}{"if the ocean is that deep."}, default=.false.)}
\DoxyCodeLine{1551     \textcolor{keywordflow}{if} (cs\%do\_rivermix) \&}
\DoxyCodeLine{1552       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RIVERMIX\_DEPTH"}, cs\%rivermix\_depth, \&}
\DoxyCodeLine{1553                  \textcolor{stringliteral}{"The depth to which rivers are mixed if DO\_RIVERMIX is "}//\&}
\DoxyCodeLine{1554                  \textcolor{stringliteral}{"defined."}, units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us\%m\_to\_Z)}
\DoxyCodeLine{1555   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1556     cs\%do\_rivermix = .false. ; cs\%rivermix\_depth = 0.0 ; cs\%ignore\_fluxes\_over\_land = .false.}
\DoxyCodeLine{1557 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1558 }
\DoxyCodeLine{1559   \textcolor{keywordflow}{if} (gv\%nkml == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1560     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_RIVER\_HEAT\_CONTENT"}, cs\%use\_river\_heat\_content, \&}
\DoxyCodeLine{1561                    \textcolor{stringliteral}{"If true, use the fluxes\%runoff\_Hflx field to set the "}//\&}
\DoxyCodeLine{1562                    \textcolor{stringliteral}{"heat carried by runoff, instead of using SST*CP*liq\_runoff."}, \&}
\DoxyCodeLine{1563                    default=.false.)}
\DoxyCodeLine{1564     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CALVING\_HEAT\_CONTENT"}, cs\%use\_calving\_heat\_content, \&}
\DoxyCodeLine{1565                    \textcolor{stringliteral}{"If true, use the fluxes\%calving\_Hflx field to set the "}//\&}
\DoxyCodeLine{1566                    \textcolor{stringliteral}{"heat carried by runoff, instead of using SST*CP*froz\_runoff."}, \&}
\DoxyCodeLine{1567                    default=.false.)}
\DoxyCodeLine{1568   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1569     cs\%use\_river\_heat\_content = .false.}
\DoxyCodeLine{1570     cs\%use\_calving\_heat\_content = .false.}
\DoxyCodeLine{1571 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1572 }
\DoxyCodeLine{1573   \textcolor{keywordflow}{if} (usealealgorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1574     cs\%id\_createdH = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{"created\_H"},diag\%axesT1, \&}
\DoxyCodeLine{1575         time, \textcolor{stringliteral}{"The volume flux added to stop the ocean from drying out and becoming negative in depth"}, \&}
\DoxyCodeLine{1576         \textcolor{stringliteral}{"m s-\/1"}, conversion=gv\%H\_to\_m*us\%s\_to\_T)}
\DoxyCodeLine{1577     \textcolor{keywordflow}{if} (cs\%id\_createdH>0) \textcolor{keyword}{allocate}(cs\%createdH(isd:ied,jsd:jed))}
\DoxyCodeLine{1578 }
\DoxyCodeLine{1579     \textcolor{comment}{! diagnostic for heating of a grid cell from convergence of SW heat into the cell}}
\DoxyCodeLine{1580     cs\%id\_penSW\_diag = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'rsdoabsorb'},                     \&}
\DoxyCodeLine{1581           diag\%axesTL, time, \textcolor{stringliteral}{'Convergence of Penetrative Shortwave Flux in Sea Water Layer'},\&}
\DoxyCodeLine{1582           \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%QRZ\_T\_to\_W\_m2, \&}
\DoxyCodeLine{1583           standard\_name=\textcolor{stringliteral}{'net\_rate\_of\_absorption\_of\_shortwave\_energy\_in\_ocean\_layer'}, v\_extensive=.true.)}
\DoxyCodeLine{1584 }
\DoxyCodeLine{1585     \textcolor{comment}{! diagnostic for penetrative SW heat flux at top interface of tracer cell (nz+1 interfaces)}}
\DoxyCodeLine{1586     \textcolor{comment}{! k=1 gives penetrative SW at surface; SW(k=nz+1)=0 (no penetration through rock).}}
\DoxyCodeLine{1587     cs\%id\_penSWflux\_diag = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'rsdo'},                               \&}
\DoxyCodeLine{1588           diag\%axesTi, time, \textcolor{stringliteral}{'Downwelling Shortwave Flux in Sea Water at Grid Cell Upper Interface'},\&}
\DoxyCodeLine{1589           \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%QRZ\_T\_to\_W\_m2, standard\_name=\textcolor{stringliteral}{'downwelling\_shortwave\_flux\_in\_sea\_water'})}
\DoxyCodeLine{1590 }
\DoxyCodeLine{1591     \textcolor{comment}{! need both arrays for the SW diagnostics (one for flux, one for convergence)}}
\DoxyCodeLine{1592     \textcolor{keywordflow}{if} (cs\%id\_penSW\_diag>0 .or. cs\%id\_penSWflux\_diag>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1593       \textcolor{keyword}{allocate}(cs\%penSW\_diag(isd:ied,jsd:jed,nz)) ; cs\%penSW\_diag(:,:,:) = 0.0}
\DoxyCodeLine{1594       \textcolor{keyword}{allocate}(cs\%penSWflux\_diag(isd:ied,jsd:jed,nz+1)) ; cs\%penSWflux\_diag(:,:,:) = 0.0}
\DoxyCodeLine{1595 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1596 }
\DoxyCodeLine{1597     \textcolor{comment}{! diagnostic for non-\/downwelling SW radiation (i.e., SW absorbed at ocean surface)}}
\DoxyCodeLine{1598     cs\%id\_nonpenSW\_diag = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'nonpenSW'},                       \&}
\DoxyCodeLine{1599           diag\%axesT1, time,                                                                   \&}
\DoxyCodeLine{1600           \textcolor{stringliteral}{'Non-\/downwelling SW radiation (i.e., SW absorbed in ocean surface with LW,SENS,LAT)'},\&}
\DoxyCodeLine{1601           \textcolor{stringliteral}{'W m-\/2'}, conversion=us\%QRZ\_T\_to\_W\_m2, \&}
\DoxyCodeLine{1602           standard\_name=\textcolor{stringliteral}{'nondownwelling\_shortwave\_flux\_in\_sea\_water'})}
\DoxyCodeLine{1603     \textcolor{keywordflow}{if} (cs\%id\_nonpenSW\_diag > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1604       \textcolor{keyword}{allocate}(cs\%nonpenSW\_diag(isd:ied,jsd:jed)) ; cs\%nonpenSW\_diag(:,:) = 0.0}
\DoxyCodeLine{1605 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1606 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1607 }
\DoxyCodeLine{1608   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1609     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VAR\_PEN\_SW"}, cs\%var\_pen\_sw, \&}
\DoxyCodeLine{1610                    \textcolor{stringliteral}{"If true, use one of the CHL\_A schemes specified by "}//\&}
\DoxyCodeLine{1611                    \textcolor{stringliteral}{"OPACITY\_SCHEME to determine the e-\/folding depth of "}//\&}
\DoxyCodeLine{1612                    \textcolor{stringliteral}{"incoming short wave radiation."}, default=.false.)}
\DoxyCodeLine{1613     \textcolor{keywordflow}{if} (cs\%var\_pen\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1614 }
\DoxyCodeLine{1615       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CHL\_FROM\_FILE"}, cs\%chl\_from\_file, \&}
\DoxyCodeLine{1616                    \textcolor{stringliteral}{"If true, chl\_a is read from a file."}, default=.true.)}
\DoxyCodeLine{1617       \textcolor{keywordflow}{if} (cs\%chl\_from\_file) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1618         \textcolor{keyword}{call }time\_interp\_external\_init()}
\DoxyCodeLine{1619 }
\DoxyCodeLine{1620         \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})}
\DoxyCodeLine{1621         \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CHL\_FILE"}, chl\_file, \&}
\DoxyCodeLine{1622                    \textcolor{stringliteral}{"CHL\_FILE is the file containing chl\_a concentrations in "}//\&}
\DoxyCodeLine{1623                    \textcolor{stringliteral}{"the variable CHL\_A. It is used when VAR\_PEN\_SW and "}//\&}
\DoxyCodeLine{1624                    \textcolor{stringliteral}{"CHL\_FROM\_FILE are true."}, fail\_if\_missing=.true.)}
\DoxyCodeLine{1625         chl\_filename = trim(slasher(inputdir))//trim(chl\_file)}
\DoxyCodeLine{1626         \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/CHL\_FILE"}, chl\_filename)}
\DoxyCodeLine{1627         \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CHL\_VARNAME"}, chl\_varname, \&}
\DoxyCodeLine{1628                    \textcolor{stringliteral}{"Name of CHL\_A variable in CHL\_FILE."}, default=\textcolor{stringliteral}{'CHL\_A'})}
\DoxyCodeLine{1629         cs\%sbc\_chl = init\_external\_field(chl\_filename, trim(chl\_varname), domain=g\%Domain\%mpp\_domain)}
\DoxyCodeLine{1630 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1631 }
\DoxyCodeLine{1632       cs\%id\_chl = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Chl\_opac'}, diag\%axesT1, time, \&}
\DoxyCodeLine{1633           \textcolor{stringliteral}{'Surface chlorophyll A concentration used to find opacity'}, \textcolor{stringliteral}{'mg m-\/3'})}
\DoxyCodeLine{1634 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1635 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1636 }
\DoxyCodeLine{1637   id\_clock\_uv\_at\_h = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean find\_uv\_at\_h)'}, grain=clock\_routine)}
\DoxyCodeLine{1638   id\_clock\_frazil  = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean frazil)'}, grain=clock\_routine)}
\DoxyCodeLine{1639 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a43ac98433f0f2f0e6cf4f8a3c9622ec4}\label{namespacemom__diabatic__aux_a43ac98433f0f2f0e6cf4f8a3c9622ec4}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!diagnosemldbydensitydifference@{diagnosemldbydensitydifference}}
\index{diagnosemldbydensitydifference@{diagnosemldbydensitydifference}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{diagnosemldbydensitydifference()}{diagnosemldbydensitydifference()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::diagnosemldbydensitydifference (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{id\+\_\+\+M\+LD,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, intent(in)}]{density\+Diff,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(diag\+\_\+ctrl), pointer}]{diag\+Ptr,  }\item[{integer, intent(in), optional}]{id\+\_\+\+N2sub\+ML,  }\item[{integer, intent(in), optional}]{id\+\_\+\+M\+L\+Dsq,  }\item[{real, intent(in), optional}]{dz\+\_\+sub\+ML }\end{DoxyParamCaption})}



Diagnose a mixed layer depth (M\+LD) determined by a given density difference with the surface. This routine is appropriate in M\+O\+M\+\_\+diabatic\+\_\+driver due to its position within the time stepping. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid type \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em id\+\_\+mld} & Handle (ID) of M\+LD diagnostic \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Structure containing pointers to any available thermodynamic fields. \\
\hline
\mbox{\texttt{ in}}  & {\em densitydiff} & Density difference to determine M\+LD \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]} \\
\hline
 & {\em diagptr} & Diagnostics structure \\
\hline
\mbox{\texttt{ in}}  & {\em id\+\_\+n2subml} & Optional handle (ID) of sub\+ML stratification \\
\hline
\mbox{\texttt{ in}}  & {\em id\+\_\+mldsq} & Optional handle (ID) of squared M\+LD \\
\hline
\mbox{\texttt{ in}}  & {\em dz\+\_\+subml} & The distance over which to calculate N2sub\+ML or 50 m if missing \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 593 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{593   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{           !< Grid type}}
\DoxyCodeLine{594   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{          !< ocean vertical grid structure}}
\DoxyCodeLine{595   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{          !< A dimensional unit scaling type}}
\DoxyCodeLine{596   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)} :: id\_MLD\textcolor{comment}{      !< Handle (ID) of MLD diagnostic}}
\DoxyCodeLine{597 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{598                            \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{           !< Layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{599   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{          !< Structure containing pointers to any}}
\DoxyCodeLine{600 \textcolor{comment}{                                                     !! available thermodynamic fields.}}
\DoxyCodeLine{601 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)} :: densityDiff\textcolor{comment}{ !< Density difference to determine MLD [R ~> kg m-\/3]}}
\DoxyCodeLine{602   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{pointer}    :: diagPtr\textcolor{comment}{     !< Diagnostics structure}}
\DoxyCodeLine{603   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: id\_N2subML\textcolor{comment}{  !< Optional handle (ID) of subML stratification}}
\DoxyCodeLine{604   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: id\_MLDsq\textcolor{comment}{    !< Optional handle (ID) of squared MLD}}
\DoxyCodeLine{605 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: dz\_subML\textcolor{comment}{    !< The distance over which to calculate N2subML}}
\DoxyCodeLine{606 \textcolor{comment}{                                                     !! or 50 m if missing [Z ~> m]}}
\DoxyCodeLine{607 }
\DoxyCodeLine{608   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{609 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: deltaRhoAtKm1, deltaRhoAtK \textcolor{comment}{! Density differences [R ~> kg m-\/3].}}
\DoxyCodeLine{610 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: pRef\_MLD, pRef\_N2 \textcolor{comment}{! Reference pressures [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{611 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: H\_subML, dH\_N2    \textcolor{comment}{! Summed thicknesses used in N2 calculation [H ~> m].}}
\DoxyCodeLine{612 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: T\_subML, T\_deeper \textcolor{comment}{! Temperatures used in the N2 calculation [degC].}}
\DoxyCodeLine{613 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: S\_subML, S\_deeper \textcolor{comment}{! Salinities used in the N2 calculation [ppt].}}
\DoxyCodeLine{614 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rho\_subML, rho\_deeper \textcolor{comment}{! Densities used in the N2 calculation [R ~> kg m-\/3].}}
\DoxyCodeLine{615 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: dK, dKm1          \textcolor{comment}{! Depths [Z ~> m].}}
\DoxyCodeLine{616 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rhoSurf          \textcolor{comment}{! Density used in finding the mixedlayer depth [R ~> kg m-\/3].}}
\DoxyCodeLine{617 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: MLD     \textcolor{comment}{! Diagnosed mixed layer depth [Z ~> m].}}
\DoxyCodeLine{618 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: subMLN2 \textcolor{comment}{! Diagnosed stratification below ML [T-\/2 ~> s-\/2].}}
\DoxyCodeLine{619 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: MLD2    \textcolor{comment}{! Diagnosed MLD\string^2 [Z2 ~> m2].}}
\DoxyCodeLine{620   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: N2\_region\_set \textcolor{comment}{! If true, all necessary values for calculating N2}}
\DoxyCodeLine{621                                                \textcolor{comment}{! have been stored already.}}
\DoxyCodeLine{622 \textcolor{keywordtype}{  real} :: gE\_Rho0          \textcolor{comment}{! The gravitational acceleration divided by a mean density [Z T-\/2 R-\/1 ~> m4 s-\/2 kg-\/1].}}
\DoxyCodeLine{623 \textcolor{keywordtype}{  real} :: dH\_subML         \textcolor{comment}{! Depth below ML over which to diagnose stratification [H ~> m].}}
\DoxyCodeLine{624 \textcolor{keywordtype}{  real} :: aFac             \textcolor{comment}{! A nondimensional factor [nondim]}}
\DoxyCodeLine{625 \textcolor{keywordtype}{  real} :: ddRho            \textcolor{comment}{! A density difference [R ~> kg m-\/3]}}
\DoxyCodeLine{626   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{627   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, k, nz, id\_N2, id\_SQ}
\DoxyCodeLine{628 }
\DoxyCodeLine{629   id\_n2 = -\/1 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(id\_n2subml)) id\_n2 = id\_n2subml}
\DoxyCodeLine{630 }
\DoxyCodeLine{631   id\_sq = -\/1 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(id\_mldsq)) id\_sq = id\_mldsq}
\DoxyCodeLine{632 }
\DoxyCodeLine{633   ge\_rho0 = us\%L\_to\_Z**2*gv\%g\_Earth / (gv\%Rho0)}
\DoxyCodeLine{634   dh\_subml = 50.*gv\%m\_to\_H  ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(dz\_subml)) dh\_subml = gv\%Z\_to\_H*dz\_subml}
\DoxyCodeLine{635 }
\DoxyCodeLine{636   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{637 }
\DoxyCodeLine{638   pref\_mld(:) = 0.0}
\DoxyCodeLine{639   eosdom(:) = eos\_domain(g\%HI)}
\DoxyCodeLine{640   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{641     \textcolor{keywordflow}{do} i=is,ie ; dk(i) = 0.5 * h(i,j,1) * gv\%H\_to\_Z ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! Depth of center of surface layer}}
\DoxyCodeLine{642     \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,1), tv\%S(:,j,1), pref\_mld, rhosurf, tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{643     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{644       deltarhoatk(i) = 0.}
\DoxyCodeLine{645       mld(i,j) = 0.}
\DoxyCodeLine{646       \textcolor{keywordflow}{if} (id\_n2>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{647         submln2(i,j) = 0.0}
\DoxyCodeLine{648         h\_subml(i) = h(i,j,1) ; dh\_n2(i) = 0.0}
\DoxyCodeLine{649         t\_subml(i) = 0.0  ; s\_subml(i) = 0.0 ; t\_deeper(i) = 0.0 ; s\_deeper(i) = 0.0}
\DoxyCodeLine{650         n2\_region\_set(i) = (g\%mask2dT(i,j)<0.5) \textcolor{comment}{! Only need to work on ocean points.}}
\DoxyCodeLine{651 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{652 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{653     \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{654       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{655         dkm1(i) = dk(i) \textcolor{comment}{! Depth of center of layer K-\/1}}
\DoxyCodeLine{656         dk(i) = dk(i) + 0.5 * ( h(i,j,k) + h(i,j,k-\/1) ) * gv\%H\_to\_Z \textcolor{comment}{! Depth of center of layer K}}
\DoxyCodeLine{657 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{658 }
\DoxyCodeLine{659       \textcolor{comment}{! Prepare to calculate stratification, N2, immediately below the mixed layer by finding}}
\DoxyCodeLine{660       \textcolor{comment}{! the cells that extend over at least dz\_subML.}}
\DoxyCodeLine{661       \textcolor{keywordflow}{if} (id\_n2>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{662          \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{663           \textcolor{keywordflow}{if} (mld(i,j)==0.0) \textcolor{keywordflow}{then}  \textcolor{comment}{! Still in the mixed layer.}}
\DoxyCodeLine{664             h\_subml(i) = h\_subml(i) + h(i,j,k)}
\DoxyCodeLine{665           \textcolor{keywordflow}{elseif} (.not.n2\_region\_set(i)) \textcolor{keywordflow}{then} \textcolor{comment}{! This block is below the mixed layer, but N2 has not been found yet.}}
\DoxyCodeLine{666             \textcolor{keywordflow}{if} (dh\_n2(i)==0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Record the temperature, salinity, pressure, immediately below the ML}}
\DoxyCodeLine{667               t\_subml(i) = tv\%T(i,j,k) ; s\_subml(i) = tv\%S(i,j,k)}
\DoxyCodeLine{668               h\_subml(i) = h\_subml(i) + 0.5 * h(i,j,k) \textcolor{comment}{! Start midway through this layer.}}
\DoxyCodeLine{669               dh\_n2(i) = 0.5 * h(i,j,k)}
\DoxyCodeLine{670             \textcolor{keywordflow}{elseif} (dh\_n2(i) + h(i,j,k) < dh\_subml) \textcolor{keywordflow}{then}}
\DoxyCodeLine{671               dh\_n2(i) = dh\_n2(i) + h(i,j,k)}
\DoxyCodeLine{672             \textcolor{keywordflow}{else}  \textcolor{comment}{! This layer includes the base of the region where N2 is calculated.}}
\DoxyCodeLine{673               t\_deeper(i) = tv\%T(i,j,k) ; s\_deeper(i) = tv\%S(i,j,k)}
\DoxyCodeLine{674               dh\_n2(i) = dh\_n2(i) + 0.5 * h(i,j,k)}
\DoxyCodeLine{675               n2\_region\_set(i) = .true.}
\DoxyCodeLine{676 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{677 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{678 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{679 \textcolor{keywordflow}{      endif} \textcolor{comment}{! id\_N2>0}}
\DoxyCodeLine{680 }
\DoxyCodeLine{681       \textcolor{comment}{! Mixed-\/layer depth, using sigma-\/0 (surface reference pressure)}}
\DoxyCodeLine{682       \textcolor{keywordflow}{do} i=is,ie ; deltarhoatkm1(i) = deltarhoatk(i) ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! Store value from previous iteration of K}}
\DoxyCodeLine{683       \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,k), tv\%S(:,j,k), pref\_mld, deltarhoatk, tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{684       \textcolor{keywordflow}{do} i = is, ie}
\DoxyCodeLine{685         deltarhoatk(i) = deltarhoatk(i) -\/ rhosurf(i) \textcolor{comment}{! Density difference between layer K and surface}}
\DoxyCodeLine{686         ddrho = deltarhoatk(i) -\/ deltarhoatkm1(i)}
\DoxyCodeLine{687         \textcolor{keywordflow}{if} ((mld(i,j)==0.) .and. (ddrho>0.) .and. \&}
\DoxyCodeLine{688             (deltarhoatkm1(i)<densitydiff) .and. (deltarhoatk(i)>=densitydiff)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{689           afac = ( densitydiff -\/ deltarhoatkm1(i) ) / ddrho}
\DoxyCodeLine{690           mld(i,j) = dk(i) * afac + dkm1(i) * (1. -\/ afac)}
\DoxyCodeLine{691 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{692         \textcolor{keywordflow}{if} (id\_sq > 0) mld2(i,j) = mld(i,j)**2}
\DoxyCodeLine{693 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! i-\/loop}}
\DoxyCodeLine{694 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-\/loop}}
\DoxyCodeLine{695     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{696       \textcolor{keywordflow}{if} ((mld(i,j)==0.) .and. (deltarhoatk(i)<densitydiff)) mld(i,j) = dk(i) \textcolor{comment}{! Assume mixing to the bottom}}
\DoxyCodeLine{697 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{698 }
\DoxyCodeLine{699     \textcolor{keywordflow}{if} (id\_n2>0) \textcolor{keywordflow}{then}  \textcolor{comment}{! Now actually calculate stratification, N2, below the mixed layer.}}
\DoxyCodeLine{700       \textcolor{keywordflow}{do} i=is,ie ; pref\_n2(i) = (gv\%g\_Earth * gv\%H\_to\_RZ) * (h\_subml(i) + 0.5*dh\_n2(i)) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{701       \textcolor{comment}{! if ((.not.N2\_region\_set(i)) .and. (dH\_N2(i) > 0.5*dH\_subML)) then}}
\DoxyCodeLine{702       \textcolor{comment}{!    ! Use whatever stratification we can, measured over whatever distance is available?}}
\DoxyCodeLine{703       \textcolor{comment}{!    T\_deeper(i) = tv\%T(i,j,nz) ; S\_deeper(i) = tv\%S(i,j,nz)}}
\DoxyCodeLine{704       \textcolor{comment}{!    N2\_region\_set(i) = .true.}}
\DoxyCodeLine{705       \textcolor{comment}{! endif}}
\DoxyCodeLine{706       \textcolor{keyword}{call }calculate\_density(t\_subml, s\_subml, pref\_n2, rho\_subml, tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{707       \textcolor{keyword}{call }calculate\_density(t\_deeper, s\_deeper, pref\_n2, rho\_deeper, tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{708       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} ((g\%mask2dT(i,j)>0.5) .and. n2\_region\_set(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{709         submln2(i,j) =  ge\_rho0 * (rho\_deeper(i) -\/ rho\_subml(i)) / (gv\%H\_to\_z * dh\_n2(i))}
\DoxyCodeLine{710 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{711 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{712 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-\/loop}}
\DoxyCodeLine{713 }
\DoxyCodeLine{714   \textcolor{keywordflow}{if} (id\_mld > 0) \textcolor{keyword}{call }post\_data(id\_mld, mld, diagptr)}
\DoxyCodeLine{715   \textcolor{keywordflow}{if} (id\_n2 > 0)  \textcolor{keyword}{call }post\_data(id\_n2, submln2, diagptr)}
\DoxyCodeLine{716   \textcolor{keywordflow}{if} (id\_sq > 0)  \textcolor{keyword}{call }post\_data(id\_sq, mld2, diagptr)}
\DoxyCodeLine{717 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a695474893b92e3e3418a2bed871a5d7e}\label{namespacemom__diabatic__aux_a695474893b92e3e3418a2bed871a5d7e}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!diagnosemldbyenergy@{diagnosemldbyenergy}}
\index{diagnosemldbyenergy@{diagnosemldbyenergy}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{diagnosemldbyenergy()}{diagnosemldbyenergy()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::diagnosemldbyenergy (\begin{DoxyParamCaption}\item[{integer, dimension(3), intent(in)}]{id\+\_\+\+M\+LD,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\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(3), intent(in)}]{Mixing\+\_\+\+Energy,  }\item[{type(diag\+\_\+ctrl), pointer}]{diag\+Ptr }\end{DoxyParamCaption})}



Diagnose a mixed layer depth (M\+LD) determined by the depth a given energy value would mix. This routine is appropriate in M\+O\+M\+\_\+diabatic\+\_\+driver due to its position within the time stepping. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em id\+\_\+mld} & Energy output diag I\+Ds \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid type \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em mixing\+\_\+energy} & Energy values for up to 3 M\+L\+Ds \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Structure containing pointers to any available thermodynamic fields. \\
\hline
 & {\em diagptr} & Diagnostics structure \\
\hline
\end{DoxyParams}


Definition at line 723 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{723   \textcolor{comment}{! Author: Brandon Reichl}}
\DoxyCodeLine{724   \textcolor{comment}{! Date: October 2, 2020}}
\DoxyCodeLine{725   \textcolor{comment}{! //}}
\DoxyCodeLine{726   \textcolor{comment}{! *Note that gravity is assumed constant everywhere and divided out of all calculations.}}
\DoxyCodeLine{727   \textcolor{comment}{!}}
\DoxyCodeLine{728   \textcolor{comment}{! This code has been written to step through the columns layer by layer, summing the PE}}
\DoxyCodeLine{729   \textcolor{comment}{! change inferred by mixing the layer with all layers above.  When the change exceeds a}}
\DoxyCodeLine{730   \textcolor{comment}{! threshold (determined by input array Mixing\_Energy), the code needs to solve for how far}}
\DoxyCodeLine{731   \textcolor{comment}{! into this layer the threshold PE change occurs (assuming constant density layers).}}
\DoxyCodeLine{732   \textcolor{comment}{! This is expressed here via solving the function F(X) = 0 where:}}
\DoxyCodeLine{733   \textcolor{comment}{! F(X) = 0.5 * ( Ca*X\string^3/(D1+X) + Cb*X\string^2/(D1+X) + Cc*X/(D1+X) + Dc/(D1+X)}}
\DoxyCodeLine{734   \textcolor{comment}{!                + Ca2*X\string^2 + Cb2*X + Cc2)}}
\DoxyCodeLine{735   \textcolor{comment}{! where all coefficients are determined by the previous mixed layer depth, the}}
\DoxyCodeLine{736   \textcolor{comment}{! density of the previous mixed layer, the present layer thickness, and the present}}
\DoxyCodeLine{737   \textcolor{comment}{! layer density.  This equation is worked out by computing the total PE assuming constant}}
\DoxyCodeLine{738   \textcolor{comment}{! density in the mixed layer as well as in the remaining part of the present layer that is}}
\DoxyCodeLine{739   \textcolor{comment}{! not mixed.}}
\DoxyCodeLine{740   \textcolor{comment}{! To solve for X in this equation a Newton's method iteration is employed, which}}
\DoxyCodeLine{741   \textcolor{comment}{! converges extremely quickly (usually 1 guess) since this equation turns out being rather}}
\DoxyCodeLine{742   \textcolor{comment}{! lienar for PE change with increasing X.}}
\DoxyCodeLine{743   \textcolor{comment}{! Input parameters:}}
\DoxyCodeLine{744   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(3)},   \textcolor{keywordtype}{intent(in)} :: id\_MLD\textcolor{comment}{      !< Energy output diag IDs}}
\DoxyCodeLine{745   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{           !< Grid type}}
\DoxyCodeLine{746   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{          !< ocean vertical grid structure}}
\DoxyCodeLine{747   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{          !< A dimensional unit scaling type}}
\DoxyCodeLine{748 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(3)},      \textcolor{keywordtype}{intent(in)} :: Mixing\_Energy\textcolor{comment}{ !< Energy values for up to 3 MLDs}}
\DoxyCodeLine{749 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{750                            \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{           !< Layer thickness [H ~> m or kg m-\/2]}}
\DoxyCodeLine{751   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{          !< Structure containing pointers to any}}
\DoxyCodeLine{752 \textcolor{comment}{                                                     !! available thermodynamic fields.}}
\DoxyCodeLine{753   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{pointer}    :: diagPtr\textcolor{comment}{     !< Diagnostics structure}}
\DoxyCodeLine{754 }
\DoxyCodeLine{755   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{756 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G),3)} :: MLD     \textcolor{comment}{! Diagnosed mixed layer depth [Z ~> m].}}
\DoxyCodeLine{757 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G))} :: Z\_L, Z\_U, dZ, Rho\_c, pRef\_MLD}
\DoxyCodeLine{758 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(3)} :: PE\_threshold}
\DoxyCodeLine{759 }
\DoxyCodeLine{760 \textcolor{keywordtype}{  real} :: ig, E\_g}
\DoxyCodeLine{761 \textcolor{keywordtype}{  real} :: PE\_Threshold\_fraction, PE, PE\_Mixed, PE\_Mixed\_TST}
\DoxyCodeLine{762 \textcolor{keywordtype}{  real} :: RhoDZ\_ML, H\_ML, RhoDZ\_ML\_TST, H\_ML\_TST}
\DoxyCodeLine{763 \textcolor{keywordtype}{  real} :: Rho\_ML}
\DoxyCodeLine{764 }
\DoxyCodeLine{765 \textcolor{keywordtype}{  real} :: R1, D1, R2, D2}
\DoxyCodeLine{766 \textcolor{keywordtype}{  real} :: Ca, Cb,D ,Cc, Cd, Ca2, Cb2, C, Cc2}
\DoxyCodeLine{767 \textcolor{keywordtype}{  real} :: Gx, Gpx, Hx, iHx, Hpx, Ix, Ipx, Fgx, Fpx, X, X2}
\DoxyCodeLine{768 }
\DoxyCodeLine{769   \textcolor{keywordtype}{integer} :: IT, iM}
\DoxyCodeLine{770   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, k, nz}
\DoxyCodeLine{771 }
\DoxyCodeLine{772   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{773 }
\DoxyCodeLine{774   pref\_mld(:) = 0.0}
\DoxyCodeLine{775   mld(:,:,:) = 0.0}
\DoxyCodeLine{776   pe\_threshold\_fraction = 1.e-\/4 \textcolor{comment}{!Fixed threshold of 0.01\%, could be runtime.}}
\DoxyCodeLine{777 }
\DoxyCodeLine{778   \textcolor{keywordflow}{do} im=1,3}
\DoxyCodeLine{779     pe\_threshold(im) = mixing\_energy(im)/gv\%g\_earth}
\DoxyCodeLine{780 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{781 }
\DoxyCodeLine{782   \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{783     \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{784 }
\DoxyCodeLine{785       \textcolor{keyword}{call }calculate\_density(tv\%T(i,j,:), tv\%S(i,j,:), pref\_mld, rho\_c, 1, nz, \&}
\DoxyCodeLine{786                              tv\%eqn\_of\_state, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{787 }
\DoxyCodeLine{788       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{789         dz(k) = h(i,j,k) * gv\%H\_to\_Z}
\DoxyCodeLine{790 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{791       z\_u(1) = 0.0}
\DoxyCodeLine{792       z\_l(1) = -\/dz(1)}
\DoxyCodeLine{793       \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{794         z\_u(k) = z\_l(k-\/1)}
\DoxyCodeLine{795         z\_l(k) = z\_l(k-\/1)-\/dz(k)}
\DoxyCodeLine{796 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{797 }
\DoxyCodeLine{798       \textcolor{keywordflow}{do} im=1,3}
\DoxyCodeLine{799 }
\DoxyCodeLine{800         \textcolor{comment}{! Initialize these for each column-\/wise calculation}}
\DoxyCodeLine{801         pe = 0.0}
\DoxyCodeLine{802         rhodz\_ml = 0.0}
\DoxyCodeLine{803         h\_ml = 0.0}
\DoxyCodeLine{804         rhodz\_ml\_tst = 0.0}
\DoxyCodeLine{805         h\_ml\_tst = 0.0}
\DoxyCodeLine{806         pe\_mixed = 0.0}
\DoxyCodeLine{807 }
\DoxyCodeLine{808         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{809 }
\DoxyCodeLine{810           \textcolor{comment}{! This is the unmixed PE cumulative sum from top down}}
\DoxyCodeLine{811           pe = pe + 0.5 * rho\_c(k) * (z\_u(k)**2 -\/ z\_l(k)**2)}
\DoxyCodeLine{812 }
\DoxyCodeLine{813           \textcolor{comment}{! This is the depth and integral of density}}
\DoxyCodeLine{814           h\_ml\_tst = h\_ml + dz(k)}
\DoxyCodeLine{815           rhodz\_ml\_tst = rhodz\_ml + rho\_c(k) * dz(k)}
\DoxyCodeLine{816 }
\DoxyCodeLine{817           \textcolor{comment}{! The average density assuming all layers including this were mixed}}
\DoxyCodeLine{818           rho\_ml = rhodz\_ml\_tst/h\_ml\_tst}
\DoxyCodeLine{819 }
\DoxyCodeLine{820           \textcolor{comment}{! The PE assuming all layers including this were mixed}}
\DoxyCodeLine{821           \textcolor{comment}{! Note that 0. could be replaced with "Surface", which doesn't have to be 0}}
\DoxyCodeLine{822           \textcolor{comment}{! but 0 is a good reference value.}}
\DoxyCodeLine{823           pe\_mixed\_tst = 0.5 * rho\_ml * (0.**2 -\/ (0. -\/ h\_ml\_tst)**2)}
\DoxyCodeLine{824 }
\DoxyCodeLine{825           \textcolor{comment}{! Check if we supplied enough energy to mix to this layer}}
\DoxyCodeLine{826           \textcolor{keywordflow}{if} (pe\_mixed\_tst -\/ pe <= pe\_threshold(im)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{827             h\_ml = h\_ml\_tst}
\DoxyCodeLine{828             rhodz\_ml = rhodz\_ml\_tst}
\DoxyCodeLine{829 }
\DoxyCodeLine{830           \textcolor{keywordflow}{else} \textcolor{comment}{! If not, we need to solve where the energy ran out}}
\DoxyCodeLine{831             \textcolor{comment}{! This will be done with a Newton's method iteration:}}
\DoxyCodeLine{832 }
\DoxyCodeLine{833             r1 = rhodz\_ml / h\_ml \textcolor{comment}{! The density of the mixed layer (not including this layer)}}
\DoxyCodeLine{834             d1 = h\_ml \textcolor{comment}{! The thickness of the mixed layer (not including this layer)}}
\DoxyCodeLine{835             r2 = rho\_c(k) \textcolor{comment}{! The density of this layer}}
\DoxyCodeLine{836             d2 = dz(k) \textcolor{comment}{! The thickness of this layer}}
\DoxyCodeLine{837 }
\DoxyCodeLine{838             \textcolor{comment}{! This block could be used to calculate the function coefficients if}}
\DoxyCodeLine{839             \textcolor{comment}{! we don't reference all values to a surface designated as z=0}}
\DoxyCodeLine{840             \textcolor{comment}{! S = Surface}}
\DoxyCodeLine{841             \textcolor{comment}{! Ca  = -\/(R2)}}
\DoxyCodeLine{842             \textcolor{comment}{! Cb  = -\/( (R1*D1) + R2*(2.*D1-\/2.*S) )}}
\DoxyCodeLine{843             \textcolor{comment}{! D   = D1**2. -\/ 2.*D1*S}}
\DoxyCodeLine{844             \textcolor{comment}{! Cc  = -\/( R1*D1*(2.*D1-\/2.*S) + R2*D )}}
\DoxyCodeLine{845             \textcolor{comment}{! Cd  = -\/(R1*D1*D)}}
\DoxyCodeLine{846             \textcolor{comment}{! Ca2 = R2}}
\DoxyCodeLine{847             \textcolor{comment}{! Cb2 = R2*(2*D1-\/2*S)}}
\DoxyCodeLine{848             \textcolor{comment}{! C   = S**2 + D2**2 + D1**2 -\/ 2*D1*S -\/ 2.*D2*S +2.*D1*D2}}
\DoxyCodeLine{849             \textcolor{comment}{! Cc2 = R2*(D+S**2-\/C)}}
\DoxyCodeLine{850             \textcolor{comment}{!}}
\DoxyCodeLine{851             \textcolor{comment}{! If the surface is S = 0, it simplifies to:}}
\DoxyCodeLine{852             ca  = -\/r2}
\DoxyCodeLine{853             cb  = -\/(r1 * d1 + r2 * (2. * d1))}
\DoxyCodeLine{854             d   = d1**2}
\DoxyCodeLine{855             cc  = -\/(r1 * d1 * (2. * d1) + (r2 * d))}
\DoxyCodeLine{856             cd  = -\/r1 * (d1 * d)}
\DoxyCodeLine{857             ca2 = r2}
\DoxyCodeLine{858             cb2 = r2 * (2. * d1)}
\DoxyCodeLine{859             c   = d2**2 + d1**2 + 2. * (d1 * d2)}
\DoxyCodeLine{860             cc2 = r2 * (d -\/ c)}
\DoxyCodeLine{861 }
\DoxyCodeLine{862             \textcolor{comment}{! First guess for an iteration using Newton's method}}
\DoxyCodeLine{863             x = dz(k) * 0.5}
\DoxyCodeLine{864 }
\DoxyCodeLine{865             it=0}
\DoxyCodeLine{866             \textcolor{keywordflow}{do} \textcolor{keywordflow}{while}(it<10)\textcolor{comment}{!We can iterate up to 10 times}}
\DoxyCodeLine{867               \textcolor{comment}{! We are trying to solve the function:}}
\DoxyCodeLine{868               \textcolor{comment}{! F(x) = G(x)/H(x)+I(x)}}
\DoxyCodeLine{869               \textcolor{comment}{! for where F(x) = PE+PE\_threshold, or equivalently for where}}
\DoxyCodeLine{870               \textcolor{comment}{! F(x) = G(x)/H(x)+I(x) -\/ (PE+PE\_threshold) = 0}}
\DoxyCodeLine{871               \textcolor{comment}{! We also need the derivative of this function for the Newton's method iteration}}
\DoxyCodeLine{872               \textcolor{comment}{! F'(x) = (G'(x)H(x)-\/G(x)H'(x))/H(x)\string^2 + I'(x)}}
\DoxyCodeLine{873               \textcolor{comment}{! G and its derivative}}
\DoxyCodeLine{874               gx = 0.5 * (ca * (x*x*x) + cb * x**2 + cc * x + cd)}
\DoxyCodeLine{875               gpx = 0.5 * (3. * (ca * x**2) + 2. * (cb * x) + cc)}
\DoxyCodeLine{876               \textcolor{comment}{! H, its inverse, and its derivative}}
\DoxyCodeLine{877               hx = d1 + x}
\DoxyCodeLine{878               ihx = 1. / hx}
\DoxyCodeLine{879               hpx = 1.}
\DoxyCodeLine{880               \textcolor{comment}{! I and its derivative}}
\DoxyCodeLine{881               ix = 0.5 * (ca2 * x**2 + cb2 * x + cc2)}
\DoxyCodeLine{882               ipx = 0.5 * (2. * ca2 * x + cb2)}
\DoxyCodeLine{883 }
\DoxyCodeLine{884               \textcolor{comment}{! The Function and its derivative:}}
\DoxyCodeLine{885               pe\_mixed = gx * ihx + ix}
\DoxyCodeLine{886               fgx = pe\_mixed -\/ (pe + pe\_threshold(im))}
\DoxyCodeLine{887               fpx = (gpx * hx -\/ hpx * gx) * ihx**2 + ipx}
\DoxyCodeLine{888 }
\DoxyCodeLine{889               \textcolor{comment}{! Check if our solution is within the threshold bounds, if not update}}
\DoxyCodeLine{890               \textcolor{comment}{! using Newton's method.  This appears to converge almost always in}}
\DoxyCodeLine{891               \textcolor{comment}{! one step because the function is very close to linear in most applications.}}
\DoxyCodeLine{892               \textcolor{keywordflow}{if} (abs(fgx) > pe\_threshold(im) * pe\_threshold\_fraction) \textcolor{keywordflow}{then}}
\DoxyCodeLine{893                 x2 = x -\/ fgx / fpx}
\DoxyCodeLine{894                 it = it + 1}
\DoxyCodeLine{895                 \textcolor{keywordflow}{if} (x2 < 0. .or. x2 > dz(k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{896                   \textcolor{comment}{! The iteration seems to be robust, but we need to do something *if*}}
\DoxyCodeLine{897                   \textcolor{comment}{! things go wrong... How should we treat failed iteration?}}
\DoxyCodeLine{898                   \textcolor{comment}{! Present solution: Stop trying to compute and just say we can't mix this layer.}}
\DoxyCodeLine{899                   x=0}
\DoxyCodeLine{900                   \textcolor{keywordflow}{exit}}
\DoxyCodeLine{901                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{902                   x = x2}
\DoxyCodeLine{903 \textcolor{keywordflow}{                endif}}
\DoxyCodeLine{904               \textcolor{keywordflow}{else}}
\DoxyCodeLine{905                 exit\textcolor{comment}{! Quit the iteration}}
\DoxyCodeLine{906 \textcolor{keywordflow}{              endif}}
\DoxyCodeLine{907 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{908             h\_ml = h\_ml + x}
\DoxyCodeLine{909             exit\textcolor{comment}{! Quit looping through the column}}
\DoxyCodeLine{910 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{911 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{912         mld(i,j,im) = h\_ml}
\DoxyCodeLine{913 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{914     \textcolor{keywordflow}{else}}
\DoxyCodeLine{915       mld(i,j,:) = 0.0}
\DoxyCodeLine{916 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{917 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{918 }
\DoxyCodeLine{919   \textcolor{keywordflow}{if} (id\_mld(1) > 0) \textcolor{keyword}{call }post\_data(id\_mld(1), mld(:,:,1), diagptr)}
\DoxyCodeLine{920   \textcolor{keywordflow}{if} (id\_mld(2) > 0) \textcolor{keyword}{call }post\_data(id\_mld(2), mld(:,:,2), diagptr)}
\DoxyCodeLine{921   \textcolor{keywordflow}{if} (id\_mld(3) > 0) \textcolor{keyword}{call }post\_data(id\_mld(3), mld(:,:,3), diagptr)}
\DoxyCodeLine{922 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a0b81bac82b18bd9f1e3e5a3beda78966}\label{namespacemom__diabatic__aux_a0b81bac82b18bd9f1e3e5a3beda78966}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!differential\_diffuse\_t\_s@{differential\_diffuse\_t\_s}}
\index{differential\_diffuse\_t\_s@{differential\_diffuse\_t\_s}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{differential\_diffuse\_t\_s()}{differential\_diffuse\_t\_s()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::differential\+\_\+diffuse\+\_\+t\+\_\+s (\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(inout)}]{T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{S,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(inout)}]{Kd\+\_\+T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{Kd\+\_\+S,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV }\end{DoxyParamCaption})}



This subroutine applies double diffusion to T \& S, assuming no diapycal mass fluxes, using a simple triadiagonal solver. 


\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,out}}  & {\em t} & Potential temperature \mbox{[}degC\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em s} & Salinity \mbox{[}P\+SU\mbox{]} or \mbox{[}g\+Salt/kg\mbox{]}, generically \mbox{[}ppt\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+t} & The extra diffusivity of temperature due to \\
\hline
\mbox{\texttt{ in}}  & {\em kd\+\_\+s} & The extra diffusivity of salinity due to \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 227 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{227   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{228   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{229 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{230                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{231 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{232                            \textcolor{keywordtype}{intent(inout)} :: T\textcolor{comment}{    !< Potential temperature [degC].}}
\DoxyCodeLine{233 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{234                            \textcolor{keywordtype}{intent(inout)} :: S\textcolor{comment}{    !< Salinity [PSU] or [gSalt/kg], generically [ppt].}}
\DoxyCodeLine{235 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{236                            \textcolor{keywordtype}{intent(inout)}    :: Kd\_T\textcolor{comment}{ !< The extra diffusivity of temperature due to}}
\DoxyCodeLine{237 \textcolor{comment}{                                                 !! double diffusion relative to the diffusivity of}}
\DoxyCodeLine{238 \textcolor{comment}{                                                 !! diffusivity of density [Z2 T-\/1 ~> m2 s-\/1].}}
\DoxyCodeLine{239 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{240                            \textcolor{keywordtype}{intent(in)}    :: Kd\_S\textcolor{comment}{ !< The extra diffusivity of salinity due to}}
\DoxyCodeLine{241 \textcolor{comment}{                                                 !! double diffusion relative to the diffusivity of}}
\DoxyCodeLine{242 \textcolor{comment}{                                                 !! diffusivity of density [Z2 T-\/1 ~> m2 s-\/1].}}
\DoxyCodeLine{243 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !<  Time increment [T ~> s].}}
\DoxyCodeLine{244 }
\DoxyCodeLine{245   \textcolor{comment}{! local variables}}
\DoxyCodeLine{246 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{247     b1\_T, b1\_S, \&  \textcolor{comment}{!  Variables used by the tridiagonal solvers of T \& S [H ~> m or kg m-\/2].}}
\DoxyCodeLine{248     d1\_T, d1\_S     \textcolor{comment}{!  Variables used by the tridiagonal solvers [nondim].}}
\DoxyCodeLine{249 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{250     c1\_T, c1\_S     \textcolor{comment}{!  Variables used by the tridiagonal solvers [H ~> m or kg m-\/2].}}
\DoxyCodeLine{251 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)} :: \&}
\DoxyCodeLine{252     mix\_T, mix\_S   \textcolor{comment}{!  Mixing distances in both directions across each interface [H ~> m or kg m-\/2].}}
\DoxyCodeLine{253 \textcolor{keywordtype}{  real} :: h\_tr         \textcolor{comment}{! h\_tr is h at tracer points with a tiny thickness}}
\DoxyCodeLine{254                        \textcolor{comment}{! added to ensure positive definiteness [H ~> m or kg m-\/2].}}
\DoxyCodeLine{255 \textcolor{keywordtype}{  real} :: h\_neglect    \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{256                        \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-\/2].}}
\DoxyCodeLine{257 \textcolor{keywordtype}{  real} :: I\_h\_int      \textcolor{comment}{! The inverse of the thickness associated with an}}
\DoxyCodeLine{258                        \textcolor{comment}{! interface [H-\/1 ~> m-\/1 or m2 kg-\/1].}}
\DoxyCodeLine{259 \textcolor{keywordtype}{  real} :: b\_denom\_T    \textcolor{comment}{! The first term in the denominators for the expressions}}
\DoxyCodeLine{260 \textcolor{keywordtype}{  real} :: b\_denom\_S    \textcolor{comment}{! for b1\_T and b1\_S, both [H ~> m or kg m-\/2].}}
\DoxyCodeLine{261   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{262 }
\DoxyCodeLine{263   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{264   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{265 }
\DoxyCodeLine{266   \textcolor{comment}{!\$OMP parallel do default(private) shared(is,ie,js,je,h,h\_neglect,dt,Kd\_T,Kd\_S,G,GV,T,S,nz)}}
\DoxyCodeLine{267   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{268     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{269       i\_h\_int = 1.0 / (0.5 * (h(i,j,1) + h(i,j,2)) + h\_neglect)}
\DoxyCodeLine{270       mix\_t(i,2) = ((dt * kd\_t(i,j,2)) * gv\%Z\_to\_H**2) * i\_h\_int}
\DoxyCodeLine{271       mix\_s(i,2) = ((dt * kd\_s(i,j,2)) * gv\%Z\_to\_H**2) * i\_h\_int}
\DoxyCodeLine{272 }
\DoxyCodeLine{273       h\_tr = h(i,j,1) + h\_neglect}
\DoxyCodeLine{274       b1\_t(i) = 1.0 / (h\_tr + mix\_t(i,2))}
\DoxyCodeLine{275       b1\_s(i) = 1.0 / (h\_tr + mix\_s(i,2))}
\DoxyCodeLine{276       d1\_t(i) = h\_tr * b1\_t(i)}
\DoxyCodeLine{277       d1\_s(i) = h\_tr * b1\_s(i)}
\DoxyCodeLine{278       t(i,j,1) = (b1\_t(i)*h\_tr)*t(i,j,1)}
\DoxyCodeLine{279       s(i,j,1) = (b1\_s(i)*h\_tr)*s(i,j,1)}
\DoxyCodeLine{280 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{281     \textcolor{keywordflow}{do} k=2,nz-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{282       \textcolor{comment}{! Calculate the mixing across the interface below this layer.}}
\DoxyCodeLine{283       i\_h\_int = 1.0 / (0.5 * (h(i,j,k) + h(i,j,k+1)) + h\_neglect)}
\DoxyCodeLine{284       mix\_t(i,k+1) = ((dt * kd\_t(i,j,k+1)) * gv\%Z\_to\_H**2) * i\_h\_int}
\DoxyCodeLine{285       mix\_s(i,k+1) = ((dt * kd\_s(i,j,k+1)) * gv\%Z\_to\_H**2) * i\_h\_int}
\DoxyCodeLine{286 }
\DoxyCodeLine{287       c1\_t(i,k) = mix\_t(i,k) * b1\_t(i)}
\DoxyCodeLine{288       c1\_s(i,k) = mix\_s(i,k) * b1\_s(i)}
\DoxyCodeLine{289 }
\DoxyCodeLine{290       h\_tr = h(i,j,k) + h\_neglect}
\DoxyCodeLine{291       b\_denom\_t = h\_tr + d1\_t(i)*mix\_t(i,k)}
\DoxyCodeLine{292       b\_denom\_s = h\_tr + d1\_s(i)*mix\_s(i,k)}
\DoxyCodeLine{293       b1\_t(i) = 1.0 / (b\_denom\_t + mix\_t(i,k+1))}
\DoxyCodeLine{294       b1\_s(i) = 1.0 / (b\_denom\_s + mix\_s(i,k+1))}
\DoxyCodeLine{295       d1\_t(i) = b\_denom\_t * b1\_t(i)}
\DoxyCodeLine{296       d1\_s(i) = b\_denom\_s * b1\_s(i)}
\DoxyCodeLine{297 }
\DoxyCodeLine{298       t(i,j,k) = b1\_t(i) * (h\_tr*t(i,j,k) + mix\_t(i,k)*t(i,j,k-\/1))}
\DoxyCodeLine{299       s(i,j,k) = b1\_s(i) * (h\_tr*s(i,j,k) + mix\_s(i,k)*s(i,j,k-\/1))}
\DoxyCodeLine{300 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{301     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{302       c1\_t(i,nz) = mix\_t(i,nz) * b1\_t(i)}
\DoxyCodeLine{303       c1\_s(i,nz) = mix\_s(i,nz) * b1\_s(i)}
\DoxyCodeLine{304 }
\DoxyCodeLine{305       h\_tr = h(i,j,nz) + h\_neglect}
\DoxyCodeLine{306       b1\_t(i) = 1.0 / (h\_tr + d1\_t(i)*mix\_t(i,nz))}
\DoxyCodeLine{307       b1\_s(i) = 1.0 / (h\_tr + d1\_s(i)*mix\_s(i,nz))}
\DoxyCodeLine{308 }
\DoxyCodeLine{309       t(i,j,nz) = b1\_t(i) * (h\_tr*t(i,j,nz) + mix\_t(i,nz)*t(i,j,nz-\/1))}
\DoxyCodeLine{310       s(i,j,nz) = b1\_s(i) * (h\_tr*s(i,j,nz) + mix\_s(i,nz)*s(i,j,nz-\/1))}
\DoxyCodeLine{311 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{312     \textcolor{keywordflow}{do} k=nz-\/1,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{313       t(i,j,k) = t(i,j,k) + c1\_t(i,k+1)*t(i,j,k+1)}
\DoxyCodeLine{314       s(i,j,k) = s(i,j,k) + c1\_s(i,k+1)*s(i,j,k+1)}
\DoxyCodeLine{315 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{316 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_a3b3416d0ee87cd1a0d54a910fb681e93}\label{namespacemom__diabatic__aux_a3b3416d0ee87cd1a0d54a910fb681e93}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!find\_uv\_at\_h@{find\_uv\_at\_h}}
\index{find\_uv\_at\_h@{find\_uv\_at\_h}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{find\_uv\_at\_h()}{find\_uv\_at\_h()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::find\+\_\+uv\+\_\+at\+\_\+h (\begin{DoxyParamCaption}\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{u\+\_\+h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{v\+\_\+h,  }\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(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{ea,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{eb }\end{DoxyParamCaption})}



This subroutine calculates u\+\_\+h and v\+\_\+h (velocities at thickness points), optionally using the entrainment amounts passed in as arguments. 


\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 u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em u\+\_\+h} & Zonal velocity interpolated to h points \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em v\+\_\+h} & Meridional velocity interpolated to h points \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ea} & The amount of fluid entrained from the layer \\
\hline
\mbox{\texttt{ in}}  & {\em eb} & The amount of fluid entrained from the layer \\
\hline
\end{DoxyParams}


Definition at line 431 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{431   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{432   \textcolor{keywordtype}{type}(verticalGrid\_type),   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{433   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{434 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{435                              \textcolor{keywordtype}{intent(in)}  :: u\textcolor{comment}{    !< The zonal velocity [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{436 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{437                              \textcolor{keywordtype}{intent(in)}  :: v\textcolor{comment}{    !< The meridional velocity [L T-\/1 ~> m s-\/1]}}
\DoxyCodeLine{438 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{439                              \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{440 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{441                              \textcolor{keywordtype}{intent(out)}   :: u\_h\textcolor{comment}{ !< Zonal velocity interpolated to h points [L T-\/1 ~> m s-\/1].}}
\DoxyCodeLine{442 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{443                              \textcolor{keywordtype}{intent(out)}   :: v\_h\textcolor{comment}{ !< Meridional velocity interpolated to h points [L T-\/1 ~> m s-\/1].}}
\DoxyCodeLine{444 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{445                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: ea\textcolor{comment}{ !< The amount of fluid entrained from the layer}}
\DoxyCodeLine{446 \textcolor{comment}{                                                 !! above within this time step [H ~> m or kg m-\/2].}}
\DoxyCodeLine{447 \textcolor{comment}{                                                 !! Omitting ea is the same as setting it to 0.}}
\DoxyCodeLine{448 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{449                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: eb\textcolor{comment}{ !< The amount of fluid entrained from the layer}}
\DoxyCodeLine{450 \textcolor{comment}{                                                 !! below within this time step [H ~> m or kg m-\/2].}}
\DoxyCodeLine{451 \textcolor{comment}{                                                 !! Omitting eb is the same as setting it to 0.}}
\DoxyCodeLine{452 }
\DoxyCodeLine{453   \textcolor{comment}{! local variables}}
\DoxyCodeLine{454 \textcolor{keywordtype}{  real} :: b\_denom\_1    \textcolor{comment}{! The first term in the denominator of b1 [H ~> m or kg m-\/2].}}
\DoxyCodeLine{455 \textcolor{keywordtype}{  real} :: h\_neglect    \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{456                        \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-\/2].}}
\DoxyCodeLine{457 \textcolor{keywordtype}{  real} :: b1(SZI\_(G)), d1(SZI\_(G)), c1(SZI\_(G),SZK\_(G))}
\DoxyCodeLine{458 \textcolor{keywordtype}{  real} :: a\_n(SZI\_(G)), a\_s(SZI\_(G))  \textcolor{comment}{! Fractional weights of the neighboring}}
\DoxyCodeLine{459 \textcolor{keywordtype}{  real} :: a\_e(SZI\_(G)), a\_w(SZI\_(G))  \textcolor{comment}{! velocity points, ~1/2 in the open}}
\DoxyCodeLine{460                                       \textcolor{comment}{! ocean, nondimensional.}}
\DoxyCodeLine{461 \textcolor{keywordtype}{  real} :: sum\_area, Idenom}
\DoxyCodeLine{462   \textcolor{keywordtype}{logical} :: mix\_vertically}
\DoxyCodeLine{463   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{464   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{465   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_uv\_at\_h)}
\DoxyCodeLine{466   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{467 }
\DoxyCodeLine{468   mix\_vertically = \textcolor{keyword}{present}(ea)}
\DoxyCodeLine{469   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ea) .neqv. \textcolor{keyword}{present}(eb)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{470       \textcolor{stringliteral}{"find\_uv\_at\_h: Either both ea and eb or neither one must be present "}// \&}
\DoxyCodeLine{471       \textcolor{stringliteral}{"in call to find\_uv\_at\_h."})}
\DoxyCodeLine{472 \textcolor{comment}{!\$OMP parallel do default(none) shared(is,ie,js,je,G,GV,mix\_vertically,h,h\_neglect, \&}}
\DoxyCodeLine{473 \textcolor{comment}{!\$OMP                                  eb,u\_h,u,v\_h,v,nz,ea)                     \&}}
\DoxyCodeLine{474 \textcolor{comment}{!\$OMP                          private(sum\_area,Idenom,a\_w,a\_e,a\_s,a\_n,b\_denom\_1,b1,d1,c1)}}
\DoxyCodeLine{475   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{476     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{477       sum\_area = g\%areaCu(i-\/1,j) + g\%areaCu(i,j)}
\DoxyCodeLine{478       \textcolor{keywordflow}{if} (sum\_area>0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{479         idenom = sqrt(0.5*g\%IareaT(i,j) / sum\_area)}
\DoxyCodeLine{480         a\_w(i) = g\%areaCu(i-\/1,j) * idenom}
\DoxyCodeLine{481         a\_e(i) = g\%areaCu(i,j) * idenom}
\DoxyCodeLine{482       \textcolor{keywordflow}{else}}
\DoxyCodeLine{483         a\_w(i) = 0.0 ; a\_e(i) = 0.0}
\DoxyCodeLine{484 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{485 }
\DoxyCodeLine{486       sum\_area = g\%areaCv(i,j-\/1) + g\%areaCv(i,j)}
\DoxyCodeLine{487       \textcolor{keywordflow}{if} (sum\_area>0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{488         idenom = sqrt(0.5*g\%IareaT(i,j) / sum\_area)}
\DoxyCodeLine{489         a\_s(i) = g\%areaCv(i,j-\/1) * idenom}
\DoxyCodeLine{490         a\_n(i) = g\%areaCv(i,j) * idenom}
\DoxyCodeLine{491       \textcolor{keywordflow}{else}}
\DoxyCodeLine{492         a\_s(i) = 0.0 ; a\_n(i) = 0.0}
\DoxyCodeLine{493 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{494 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{495 }
\DoxyCodeLine{496     \textcolor{keywordflow}{if} (mix\_vertically) \textcolor{keywordflow}{then}}
\DoxyCodeLine{497       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{498         b\_denom\_1 = h(i,j,1) + h\_neglect}
\DoxyCodeLine{499         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,1))}
\DoxyCodeLine{500         d1(i) = b\_denom\_1 * b1(i)}
\DoxyCodeLine{501         u\_h(i,j,1) = (h(i,j,1)*b1(i)) * (a\_e(i)*u(i,j,1) + a\_w(i)*u(i-\/1,j,1))}
\DoxyCodeLine{502         v\_h(i,j,1) = (h(i,j,1)*b1(i)) * (a\_n(i)*v(i,j,1) + a\_s(i)*v(i,j-\/1,1))}
\DoxyCodeLine{503 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{504       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{505         c1(i,k) = eb(i,j,k-\/1) * b1(i)}
\DoxyCodeLine{506         b\_denom\_1 = h(i,j,k) + d1(i)*ea(i,j,k) + h\_neglect}
\DoxyCodeLine{507         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,k))}
\DoxyCodeLine{508         d1(i) = b\_denom\_1 * b1(i)}
\DoxyCodeLine{509         u\_h(i,j,k) = (h(i,j,k) * (a\_e(i)*u(i,j,k) + a\_w(i)*u(i-\/1,j,k)) + \&}
\DoxyCodeLine{510                       ea(i,j,k)*u\_h(i,j,k-\/1))*b1(i)}
\DoxyCodeLine{511         v\_h(i,j,k) = (h(i,j,k) * (a\_n(i)*v(i,j,k) + a\_s(i)*v(i,j-\/1,k)) + \&}
\DoxyCodeLine{512                       ea(i,j,k)*v\_h(i,j,k-\/1))*b1(i)}
\DoxyCodeLine{513 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{514       \textcolor{keywordflow}{do} k=nz-\/1,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{515         u\_h(i,j,k) = u\_h(i,j,k) + c1(i,k+1)*u\_h(i,j,k+1)}
\DoxyCodeLine{516         v\_h(i,j,k) = v\_h(i,j,k) + c1(i,k+1)*v\_h(i,j,k+1)}
\DoxyCodeLine{517 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{518     \textcolor{keywordflow}{else}}
\DoxyCodeLine{519       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{520         u\_h(i,j,k) = a\_e(i)*u(i,j,k) + a\_w(i)*u(i-\/1,j,k)}
\DoxyCodeLine{521         v\_h(i,j,k) = a\_n(i)*v(i,j,k) + a\_s(i)*v(i,j-\/1,k)}
\DoxyCodeLine{522 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{523 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{524 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{525 }
\DoxyCodeLine{526   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_uv\_at\_h)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_adb99fd4e2092c17cd69143945733a6d9}\label{namespacemom__diabatic__aux_adb99fd4e2092c17cd69143945733a6d9}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!make\_frazil@{make\_frazil}}
\index{make\_frazil@{make\_frazil}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{make\_frazil()}{make\_frazil()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::make\+\_\+frazil (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}), intent(in)}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in), optional}]{p\+\_\+surf,  }\item[{integer, intent(in), optional}]{halo }\end{DoxyParamCaption})}



Frazil formation keeps the temperature above the freezing point. This subroutine warms any water that is colder than the (currently surface) freezing point up to the freezing point and accumulates the required heat (in \mbox{[}Q R Z $\sim$$>$ J m-\/2\mbox{]}) in tvfrazil. 


\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,out}}  & {\em tv} & Structure containing pointers to any available thermodynamic fields. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & The control structure returned by a previous call to diabatic\+\_\+aux\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em p\+\_\+surf} & The pressure at the ocean surface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & Halo width over which to calculate frazil \\
\hline
\end{DoxyParams}


Definition at line 104 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{104   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure}}
\DoxyCodeLine{105   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< The ocean's vertical grid structure}}
\DoxyCodeLine{106 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{107                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{108   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< Structure containing pointers to any available}}
\DoxyCodeLine{109 \textcolor{comment}{                                               !! thermodynamic fields.}}
\DoxyCodeLine{110   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{111   \textcolor{keywordtype}{type}(diabatic\_aux\_CS),   \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{ !< The control structure returned by a previous}}
\DoxyCodeLine{112 \textcolor{comment}{                                               !! call to diabatic\_aux\_init.}}
\DoxyCodeLine{113 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{114                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: p\_surf\textcolor{comment}{ !< The pressure at the ocean surface [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{115   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to calculate frazil}}
\DoxyCodeLine{116 }
\DoxyCodeLine{117   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{118 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{119     fraz\_col, \& \textcolor{comment}{! The accumulated heat requirement due to frazil [Q R Z ~> J m-\/2].}}
\DoxyCodeLine{120     T\_freeze, \& \textcolor{comment}{! The freezing potential temperature at the current salinity [degC].}}
\DoxyCodeLine{121     ps          \textcolor{comment}{! Surface pressure [R L2 T-\/2 ~> Pa]}}
\DoxyCodeLine{122 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{123     pressure    \textcolor{comment}{! The pressure at the middle of each layer [R L2 T-\/2 ~> Pa].}}
\DoxyCodeLine{124 \textcolor{keywordtype}{  real} :: H\_to\_RL2\_T2  \textcolor{comment}{! A conversion factor from thicknesses in H to pressure [R L2 T-\/2 H-\/1 ~> Pa m-\/1 or Pa m2 kg-\/1]}}
\DoxyCodeLine{125 \textcolor{keywordtype}{  real} :: hc    \textcolor{comment}{! A layer's heat capacity [Q R Z degC-\/1 ~> J m-\/2 degC-\/1].}}
\DoxyCodeLine{126   \textcolor{keywordtype}{logical} :: T\_fr\_set  \textcolor{comment}{! True if the freezing point has been calculated for a}}
\DoxyCodeLine{127                        \textcolor{comment}{! row of points.}}
\DoxyCodeLine{128   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{129 }
\DoxyCodeLine{130   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{131   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{132     is = g\%isc-\/halo ; ie = g\%iec+halo ; js = g\%jsc-\/halo ; je = g\%jec+halo}
\DoxyCodeLine{133 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{134 }
\DoxyCodeLine{135   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_frazil)}
\DoxyCodeLine{136 }
\DoxyCodeLine{137   \textcolor{keywordflow}{if} (.not.cs\%pressure\_dependent\_frazil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{138     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie ; pressure(i,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{139   \textcolor{keywordflow}{else}}
\DoxyCodeLine{140     h\_to\_rl2\_t2 = gv\%H\_to\_RZ * gv\%g\_Earth}
\DoxyCodeLine{141 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{142   \textcolor{comment}{!\$OMP parallel do default(shared) private(fraz\_col,T\_fr\_set,T\_freeze,hc,ps)  \&}}
\DoxyCodeLine{143   \textcolor{comment}{!\$OMP                             firstprivate(pressure) ! pressure might be set above, so should be firstprivate}}
\DoxyCodeLine{144   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{145     ps(:) = 0.0}
\DoxyCodeLine{146     \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(p\_surf)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{147       ps(i) = p\_surf(i,j)}
\DoxyCodeLine{148 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{149 }
\DoxyCodeLine{150     \textcolor{keywordflow}{do} i=is,ie ; fraz\_col(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{151 }
\DoxyCodeLine{152     \textcolor{keywordflow}{if} (cs\%pressure\_dependent\_frazil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{153       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{154         pressure(i,1) = ps(i) + (0.5*h\_to\_rl2\_t2)*h(i,j,1)}
\DoxyCodeLine{155 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{156       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{157         pressure(i,k) = pressure(i,k-\/1) + \&}
\DoxyCodeLine{158           (0.5*h\_to\_rl2\_t2) * (h(i,j,k) + h(i,j,k-\/1))}
\DoxyCodeLine{159 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{160 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{161 }
\DoxyCodeLine{162     \textcolor{keywordflow}{if} (cs\%reclaim\_frazil) \textcolor{keywordflow}{then}}
\DoxyCodeLine{163       t\_fr\_set = .false.}
\DoxyCodeLine{164       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (tv\%frazil(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{165         \textcolor{keywordflow}{if} (.not.t\_fr\_set) \textcolor{keywordflow}{then}}
\DoxyCodeLine{166           \textcolor{keyword}{call }calculate\_tfreeze(tv\%S(i:,j,1), pressure(i:,1), t\_freeze(i:), \&}
\DoxyCodeLine{167                                  1, ie-\/i+1, tv\%eqn\_of\_state, pres\_scale=us\%RL2\_T2\_to\_Pa)}
\DoxyCodeLine{168           t\_fr\_set = .true.}
\DoxyCodeLine{169 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{170 }
\DoxyCodeLine{171         \textcolor{keywordflow}{if} (tv\%T(i,j,1) > t\_freeze(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{172     \textcolor{comment}{! If frazil had previously been formed, but the surface temperature is now}}
\DoxyCodeLine{173     \textcolor{comment}{! above freezing, cool the surface layer with the frazil heat deficit.}}
\DoxyCodeLine{174           hc = (tv\%C\_p*gv\%H\_to\_RZ) * h(i,j,1)}
\DoxyCodeLine{175           \textcolor{keywordflow}{if} (tv\%frazil(i,j) -\/ hc * (tv\%T(i,j,1) -\/ t\_freeze(i)) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{176             tv\%T(i,j,1) = tv\%T(i,j,1) -\/ tv\%frazil(i,j) / hc}
\DoxyCodeLine{177             tv\%frazil(i,j) = 0.0}
\DoxyCodeLine{178           \textcolor{keywordflow}{else}}
\DoxyCodeLine{179             tv\%frazil(i,j) = tv\%frazil(i,j) -\/ hc * (tv\%T(i,j,1) -\/ t\_freeze(i))}
\DoxyCodeLine{180             tv\%T(i,j,1) = t\_freeze(i)}
\DoxyCodeLine{181 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{182 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{183 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{184 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{185 }
\DoxyCodeLine{186     \textcolor{keywordflow}{do} k=nz,1,-\/1}
\DoxyCodeLine{187       t\_fr\_set = .false.}
\DoxyCodeLine{188       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{189         \textcolor{keywordflow}{if} ((g\%mask2dT(i,j) > 0.0) .and. \&}
\DoxyCodeLine{190             ((tv\%T(i,j,k) < 0.0) .or. (fraz\_col(i) > 0.0))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{191           \textcolor{keywordflow}{if} (.not.t\_fr\_set) \textcolor{keywordflow}{then}}
\DoxyCodeLine{192             \textcolor{keyword}{call }calculate\_tfreeze(tv\%S(i:,j,k), pressure(i:,k), t\_freeze(i:), \&}
\DoxyCodeLine{193                                    1, ie-\/i+1, tv\%eqn\_of\_state, pres\_scale=us\%RL2\_T2\_to\_Pa)}
\DoxyCodeLine{194             t\_fr\_set = .true.}
\DoxyCodeLine{195 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{196 }
\DoxyCodeLine{197           hc = (tv\%C\_p*gv\%H\_to\_RZ) * h(i,j,k)}
\DoxyCodeLine{198           \textcolor{keywordflow}{if} (h(i,j,k) <= 10.0*(gv\%Angstrom\_H + gv\%H\_subroundoff)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{199             \textcolor{comment}{! Very thin layers should not be cooled by the frazil flux.}}
\DoxyCodeLine{200             \textcolor{keywordflow}{if} (tv\%T(i,j,k) < t\_freeze(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{201               fraz\_col(i) = fraz\_col(i) + hc * (t\_freeze(i) -\/ tv\%T(i,j,k))}
\DoxyCodeLine{202               tv\%T(i,j,k) = t\_freeze(i)}
\DoxyCodeLine{203 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{204           \textcolor{keywordflow}{elseif} ((fraz\_col(i) > 0.0) .or. (tv\%T(i,j,k) < t\_freeze(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{205             \textcolor{keywordflow}{if} (fraz\_col(i) + hc * (t\_freeze(i) -\/ tv\%T(i,j,k)) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{206               tv\%T(i,j,k) = tv\%T(i,j,k) -\/ fraz\_col(i) / hc}
\DoxyCodeLine{207               fraz\_col(i) = 0.0}
\DoxyCodeLine{208             \textcolor{keywordflow}{else}}
\DoxyCodeLine{209               fraz\_col(i) = fraz\_col(i) + hc * (t\_freeze(i) -\/ tv\%T(i,j,k))}
\DoxyCodeLine{210               tv\%T(i,j,k) = t\_freeze(i)}
\DoxyCodeLine{211 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{212 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{213 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{214 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{215 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{216     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{217       tv\%frazil(i,j) = tv\%frazil(i,j) + fraz\_col(i)}
\DoxyCodeLine{218 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{219 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{220   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_frazil)}
\DoxyCodeLine{221 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_adce369573ff355b820320d9c3b048693}\label{namespacemom__diabatic__aux_adce369573ff355b820320d9c3b048693}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!set\_pen\_shortwave@{set\_pen\_shortwave}}
\index{set\_pen\_shortwave@{set\_pen\_shortwave}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{set\_pen\_shortwave()}{set\_pen\_shortwave()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::set\+\_\+pen\+\_\+shortwave (\begin{DoxyParamCaption}\item[{type(optics\+\_\+type), pointer}]{optics,  }\item[{type(forcing), intent(inout)}]{fluxes,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__diabatic__aux_1_1diabatic__aux__cs}{diabatic\+\_\+aux\+\_\+cs}}), pointer}]{CS,  }\item[{type(opacity\+\_\+cs), pointer}]{opacity\+\_\+\+C\+Sp,  }\item[{type(tracer\+\_\+flow\+\_\+control\+\_\+cs), pointer}]{tracer\+\_\+flow\+\_\+\+C\+Sp }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
 & {\em optics} & An optics structure that has will contain information about shortwave fluxes and absorption.\\
\hline
\mbox{\texttt{ in,out}}  & {\em fluxes} & points to forcing fields unused fields have N\+U\+LL ptrs\\
\hline
\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
 & {\em cs} & Control structure for diabatic\+\_\+aux\\
\hline
 & {\em opacity\+\_\+csp} & The control structure for the opacity module.\\
\hline
 & {\em tracer\+\_\+flow\+\_\+csp} & A pointer to the control structure organizing the tracer modules. \\
\hline
\end{DoxyParams}


Definition at line 531 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{531   \textcolor{keywordtype}{type}(optics\_type),       \textcolor{keywordtype}{pointer}       :: optics\textcolor{comment}{ !< An optics structure that has will contain}}
\DoxyCodeLine{532 \textcolor{comment}{                                                   !! information about shortwave fluxes and absorption.}}
\DoxyCodeLine{533   \textcolor{keywordtype}{type}(forcing),           \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< points to forcing fields}}
\DoxyCodeLine{534 \textcolor{comment}{                                                   !! unused fields have NULL ptrs}}
\DoxyCodeLine{535   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< The ocean's grid structure.}}
\DoxyCodeLine{536   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< The ocean's vertical grid structure.}}
\DoxyCodeLine{537   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}}
\DoxyCodeLine{538   \textcolor{keywordtype}{type}(diabatic\_aux\_CS),   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Control structure for diabatic\_aux}}
\DoxyCodeLine{539   \textcolor{keywordtype}{type}(opacity\_CS),        \textcolor{keywordtype}{pointer}       :: opacity\_CSp\textcolor{comment}{ !< The control structure for the opacity module.}}
\DoxyCodeLine{540   \textcolor{keywordtype}{type}(tracer\_flow\_control\_CS), \textcolor{keywordtype}{pointer}  :: tracer\_flow\_CSp\textcolor{comment}{ !< A pointer to the control structure}}
\DoxyCodeLine{541 \textcolor{comment}{                                                   !! organizing the tracer modules.}}
\DoxyCodeLine{542 }
\DoxyCodeLine{543   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{544 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}          :: chl\_2d\textcolor{comment}{ !< Vertically uniform chlorophyll-\/A concentractions [mg m-\/3]}}
\DoxyCodeLine{545 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))} :: chl\_3d\textcolor{comment}{ !< The chlorophyll-\/A concentractions of each layer [mg m-\/3]}}
\DoxyCodeLine{546   \textcolor{keywordtype}{character(len=128)} :: mesg}
\DoxyCodeLine{547   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je}
\DoxyCodeLine{548   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{549 }
\DoxyCodeLine{550   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(optics)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{551 }
\DoxyCodeLine{552   \textcolor{keywordflow}{if} (cs\%var\_pen\_sw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{553     \textcolor{keywordflow}{if} (cs\%chl\_from\_file) \textcolor{keywordflow}{then}}
\DoxyCodeLine{554       \textcolor{comment}{! Only the 2-\/d surface chlorophyll can be read in from a file.  The}}
\DoxyCodeLine{555       \textcolor{comment}{! same value is assumed for all layers.}}
\DoxyCodeLine{556       \textcolor{keyword}{call }time\_interp\_external(cs\%sbc\_chl, cs\%Time, chl\_2d)}
\DoxyCodeLine{557       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{558         \textcolor{keywordflow}{if} ((g\%mask2dT(i,j) > 0.5) .and. (chl\_2d(i,j) < 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{559           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'(" Time\_interp negative chl of ",(1pe12.4)," at i,j = ",\&}}
\DoxyCodeLine{560 \textcolor{stringliteral}{}\textcolor{stringliteral}{                    \& 2(i3), "lon/lat = ",(1pe12.4)," E ", (1pe12.4), " N.")'}) \&}
\DoxyCodeLine{561                      chl\_2d(i,j), i, j, g\%geoLonT(i,j), g\%geoLatT(i,j)}
\DoxyCodeLine{562           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_diabatic\_aux set\_pen\_shortwave: "}//trim(mesg))}
\DoxyCodeLine{563 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{564 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{565 }
\DoxyCodeLine{566       \textcolor{keywordflow}{if} (cs\%id\_chl > 0) \textcolor{keyword}{call }post\_data(cs\%id\_chl, chl\_2d, cs\%diag)}
\DoxyCodeLine{567 }
\DoxyCodeLine{568       \textcolor{keyword}{call }set\_opacity(optics, fluxes\%sw, fluxes\%sw\_vis\_dir, fluxes\%sw\_vis\_dif, \&}
\DoxyCodeLine{569                        fluxes\%sw\_nir\_dir, fluxes\%sw\_nir\_dif, g, gv, us, opacity\_csp, chl\_2d=chl\_2d)}
\DoxyCodeLine{570     \textcolor{keywordflow}{else}}
\DoxyCodeLine{571       \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tracer\_flow\_csp)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{572         \textcolor{stringliteral}{"The tracer flow control structure must be associated when the model sets "}//\&}
\DoxyCodeLine{573         \textcolor{stringliteral}{"the chlorophyll internally in set\_pen\_shortwave."})}
\DoxyCodeLine{574       \textcolor{keyword}{call }get\_chl\_from\_model(chl\_3d, g, tracer\_flow\_csp)}
\DoxyCodeLine{575 }
\DoxyCodeLine{576       \textcolor{keywordflow}{if} (cs\%id\_chl > 0) \textcolor{keyword}{call }post\_data(cs\%id\_chl, chl\_3d(:,:,1), cs\%diag)}
\DoxyCodeLine{577 }
\DoxyCodeLine{578       \textcolor{keyword}{call }set\_opacity(optics, fluxes\%sw, fluxes\%sw\_vis\_dir, fluxes\%sw\_vis\_dif, \&}
\DoxyCodeLine{579                        fluxes\%sw\_nir\_dir, fluxes\%sw\_nir\_dif, g, gv, us, opacity\_csp, chl\_3d=chl\_3d)}
\DoxyCodeLine{580 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{581   \textcolor{keywordflow}{else}}
\DoxyCodeLine{582     \textcolor{keyword}{call }set\_opacity(optics, fluxes\%sw, fluxes\%sw\_vis\_dir, fluxes\%sw\_vis\_dif, \&}
\DoxyCodeLine{583                      fluxes\%sw\_nir\_dir, fluxes\%sw\_nir\_dif, g, gv, us, opacity\_csp)}
\DoxyCodeLine{584 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{585 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diabatic__aux_acde4c76c9a489b82cba0bac5ec1b1198}\label{namespacemom__diabatic__aux_acde4c76c9a489b82cba0bac5ec1b1198}} 
\index{mom\_diabatic\_aux@{mom\_diabatic\_aux}!tridiagts@{tridiagts}}
\index{tridiagts@{tridiagts}!mom\_diabatic\_aux@{mom\_diabatic\_aux}}
\doxysubsubsection{\texorpdfstring{tridiagts()}{tridiagts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diabatic\+\_\+aux\+::tridiagts (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{integer, intent(in)}]{is,  }\item[{integer, intent(in)}]{ie,  }\item[{integer, intent(in)}]{js,  }\item[{integer, intent(in)}]{je,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{hold,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{ea,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{eb,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{T,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{S }\end{DoxyParamCaption})}



This is a simple tri-\/diagonal solver for T and S. \char`\"{}\+Simple\char`\"{} means it only uses arrays hold, ea and eb. 


\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 is} & The start i-\/index to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em ie} & The end i-\/index to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em js} & The start j-\/index to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em je} & The end j-\/index to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em hold} & The layer thicknesses before entrainment, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em ea} & The amount of fluid entrained from the layer above within this time step \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em eb} & The amount of fluid entrained from the layer below within this time step \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em t} & Layer potential temperatures \mbox{[}degC\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em s} & Layer salinities \mbox{[}ppt\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 382 of file M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{382   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{383   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{384   \textcolor{keywordtype}{integer},                                  \textcolor{keywordtype}{intent(in)}    :: is\textcolor{comment}{   !< The start i-\/index to work on.}}
\DoxyCodeLine{385   \textcolor{keywordtype}{integer},                                  \textcolor{keywordtype}{intent(in)}    :: ie\textcolor{comment}{   !< The end i-\/index to work on.}}
\DoxyCodeLine{386   \textcolor{keywordtype}{integer},                                  \textcolor{keywordtype}{intent(in)}    :: js\textcolor{comment}{   !< The start j-\/index to work on.}}
\DoxyCodeLine{387   \textcolor{keywordtype}{integer},                                  \textcolor{keywordtype}{intent(in)}    :: je\textcolor{comment}{   !< The end j-\/index to work on.}}
\DoxyCodeLine{388 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: hold\textcolor{comment}{ !< The layer thicknesses before entrainment,}}
\DoxyCodeLine{389 \textcolor{comment}{                                                                  !! [H ~> m or kg m-\/2].}}
\DoxyCodeLine{390 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: ea\textcolor{comment}{ !< The amount of fluid entrained from the layer}}
\DoxyCodeLine{391 \textcolor{comment}{                                                                !! above within this time step [H ~> m or kg m-\/2]}}
\DoxyCodeLine{392 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: eb\textcolor{comment}{ !< The amount of fluid entrained from the layer}}
\DoxyCodeLine{393 \textcolor{comment}{                                                                !! below within this time step [H ~> m or kg m-\/2]}}
\DoxyCodeLine{394 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: T\textcolor{comment}{  !< Layer potential temperatures [degC].}}
\DoxyCodeLine{395 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: S\textcolor{comment}{  !< Layer salinities [ppt].}}
\DoxyCodeLine{396 }
\DoxyCodeLine{397   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{398 \textcolor{keywordtype}{  real} :: b1(SZIB\_(G)), d1(SZIB\_(G)) \textcolor{comment}{! b1, c1, and d1 are variables used by the}}
\DoxyCodeLine{399 \textcolor{keywordtype}{  real} :: c1(SZIB\_(G),SZK\_(G))       \textcolor{comment}{! tridiagonal solver.}}
\DoxyCodeLine{400 \textcolor{keywordtype}{  real} :: h\_tr, b\_denom\_1}
\DoxyCodeLine{401   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{402 }
\DoxyCodeLine{403   \textcolor{comment}{!\$OMP parallel do default(shared) private(h\_tr,b1,d1,c1,b\_denom\_1)}}
\DoxyCodeLine{404   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{405     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{406       h\_tr = hold(i,j,1) + gv\%H\_subroundoff}
\DoxyCodeLine{407       b1(i) = 1.0 / (h\_tr + eb(i,j,1))}
\DoxyCodeLine{408       d1(i) = h\_tr * b1(i)}
\DoxyCodeLine{409       t(i,j,1) = (b1(i)*h\_tr)*t(i,j,1)}
\DoxyCodeLine{410       s(i,j,1) = (b1(i)*h\_tr)*s(i,j,1)}
\DoxyCodeLine{411 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{412     \textcolor{keywordflow}{do} k=2,g\%ke ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{413       c1(i,k) = eb(i,j,k-\/1) * b1(i)}
\DoxyCodeLine{414       h\_tr = hold(i,j,k) + gv\%H\_subroundoff}
\DoxyCodeLine{415       b\_denom\_1 = h\_tr + d1(i)*ea(i,j,k)}
\DoxyCodeLine{416       b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,k))}
\DoxyCodeLine{417       d1(i) = b\_denom\_1 * b1(i)}
\DoxyCodeLine{418       t(i,j,k) = b1(i) * (h\_tr*t(i,j,k) + ea(i,j,k)*t(i,j,k-\/1))}
\DoxyCodeLine{419       s(i,j,k) = b1(i) * (h\_tr*s(i,j,k) + ea(i,j,k)*s(i,j,k-\/1))}
\DoxyCodeLine{420 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{421     \textcolor{keywordflow}{do} k=g\%ke-\/1,1,-\/1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{422       t(i,j,k) = t(i,j,k) + c1(i,k+1)*t(i,j,k+1)}
\DoxyCodeLine{423       s(i,j,k) = s(i,j,k) + c1(i,k+1)*s(i,j,k+1)}
\DoxyCodeLine{424 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{425 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
