\hypertarget{namespacemom__internal__tides}{}\section{mom\+\_\+internal\+\_\+tides Module Reference}
\label{namespacemom__internal__tides}\index{mom\_internal\_tides@{mom\_internal\_tides}}


\subsection{Detailed Description}
Subroutines that use the ray-\/tracing equations to propagate the internal tide energy density. 

\begin{DoxyAuthor}{Author}
Benjamin Mater \& Robert Hallberg, 2015 
\end{DoxyAuthor}
\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em This control structure has parameters for the M\+O\+M\+\_\+internal\+\_\+tides module. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}
\begin{DoxyCompactList}\small\item\em A structure with the active energy loop bounds. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__internal__tides_aeeeea20ff7fe971846b7539d377f4389}{propagate\+\_\+int\+\_\+tide}} (h, tv, cn, T\+K\+E\+\_\+itidal\+\_\+input, vel\+\_\+bt\+Tide, Nb, dt, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calls subroutines in this file that are needed to refract, propagate, and dissipate energy density of the internal tide. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a9e8e7b153aef9049c2217658821e3178}{sum\+\_\+en}} (G, CS, En, label)
\begin{DoxyCompactList}\small\item\em Checks for energy conservation on computational domain. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a73ad407c5ea74fc20e58810937d2addf}{itidal\+\_\+lowmode\+\_\+loss}} (G, US, CS, Nb, Ub, En, T\+K\+E\+\_\+loss\+\_\+fixed, T\+K\+E\+\_\+loss, dt, full\+\_\+halos)
\begin{DoxyCompactList}\small\item\em Calculates the energy lost from the propagating internal tide due to scattering over small-\/scale roughness along the lines of Jayne \& St. Laurent (2001). \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__internal__tides_aab59eb7eb4e4f422294ed62a97a6a75b}{get\+\_\+lowmode\+\_\+loss}} (i, j, G, CS, mechanism, T\+K\+E\+\_\+loss\+\_\+sum)
\begin{DoxyCompactList}\small\item\em This subroutine extracts the energy lost from the propagating internal which has been summed across all angles, frequencies, and modes for a given mechanism and location. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a0814f61fee53f0941061056641132493}{refract}} (En, cn, freq, dt, G, US, N\+Angle, use\+\_\+\+P\+P\+Mang)
\begin{DoxyCompactList}\small\item\em Implements refraction on the internal waves at a single frequency. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_ae34593443ab6362445946e9d75528155}{ppm\+\_\+angular\+\_\+advect}} (En2d, C\+F\+L\+\_\+ang, Flux\+\_\+\+En, N\+Angle, dt, halo\+\_\+ang)
\begin{DoxyCompactList}\small\item\em This subroutine calculates the 1-\/d flux for advection in angular space using a monotonic piecewise parabolic scheme. This needs to be called from within i and j spatial loops. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_af70118539fe63af49c203de9bdfafe8a}{propagate}} (En, cn, freq, dt, G, US, CS, N\+Angle)
\begin{DoxyCompactList}\small\item\em Propagates internal waves at a single frequency. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a66c9354cfdcde3d06a2ebe8775572d23}{propagate\+\_\+corner\+\_\+spread}} (En, energized\+\_\+wedge, N\+Angle, speed, dt, G, CS, LB)
\begin{DoxyCompactList}\small\item\em This subroutine does first-\/order corner advection. It was written with the hopes of smoothing out the garden sprinkler effect, but is too numerically diffusive to be of much use as of yet. It is not yet compatible with reflection schemes (B\+DM). \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a0b300e27b0ec984bfe8b9afe4e89f8ab}{propagate\+\_\+x}} (En, speed\+\_\+x, Cgx\+\_\+av, d\+Cgx, dt, G, US, Nangle, CS, LB)
\begin{DoxyCompactList}\small\item\em Propagates the internal wave energy in the logical x-\/direction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_ae1a31a7f0db2b05c1d863f022b799c7b}{propagate\+\_\+y}} (En, speed\+\_\+y, Cgy\+\_\+av, d\+Cgy, dt, G, US, Nangle, CS, LB)
\begin{DoxyCompactList}\small\item\em Propagates the internal wave energy in the logical y-\/direction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a5470c5a9a8fea70664dbf793c48cef65}{zonal\+\_\+flux\+\_\+en}} (u, h, hL, hR, uh, dt, G, US, j, ish, ieh, vol\+\_\+\+C\+FL)
\begin{DoxyCompactList}\small\item\em Evaluates the zonal mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_aa1b6ca95d1076457e3b7ca32942be143}{merid\+\_\+flux\+\_\+en}} (v, h, hL, hR, vh, dt, G, US, J, ish, ieh, vol\+\_\+\+C\+FL)
\begin{DoxyCompactList}\small\item\em Evaluates the meridional mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a6c622bfe3863b8fcea98c78104477491}{reflect}} (En, N\+Angle, CS, G, LB)
\begin{DoxyCompactList}\small\item\em Reflection of the internal waves at a single frequency. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a0a20d26531e245a26385d1c056b6a5b6}{teleport}} (En, N\+Angle, CS, G, LB)
\begin{DoxyCompactList}\small\item\em Moves energy across lines of partial reflection to prevent reflection of energy that is supposed to get across. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a6643978290bfd9080c1218c338acd605}{correct\+\_\+halo\+\_\+rotation}} (En, test, G, N\+Angle)
\begin{DoxyCompactList}\small\item\em Rotates points in the halos where required to accommodate changes in grid orientation, such as at the tripolar fold. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_afa863318cc960c0be08672731ce6f225}{ppm\+\_\+reconstruction\+\_\+x}} (h\+\_\+in, h\+\_\+l, h\+\_\+r, G, LB, simple\+\_\+2nd)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge values for P\+PM reconstruction in x-\/direction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a6c3dc6d74dfd6e5b13d5f710899be278}{ppm\+\_\+reconstruction\+\_\+y}} (h\+\_\+in, h\+\_\+l, h\+\_\+r, G, LB, simple\+\_\+2nd)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge valus for P\+PM reconstruction in y-\/direction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__internal__tides_a16dd5b071e0fc87eb04c32f602c08aa5}{ppm\+\_\+limit\+\_\+pos}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, h\+\_\+min, G, iis, iie, jis, jie)
\begin{DoxyCompactList}\small\item\em Limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__internal__tides_a48431ac355c6fa3de7548bfdec620eb0}{internal\+\_\+tides\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em This subroutine initializes the internal tides module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__internal__tides_ad4a7f6d606c46123f12b39dd98f71b37}{internal\+\_\+tides\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates the memory associated with the internal tides control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__internal__tides_a6643978290bfd9080c1218c338acd605}\label{namespacemom__internal__tides_a6643978290bfd9080c1218c338acd605}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!correct\_halo\_rotation@{correct\_halo\_rotation}}
\index{correct\_halo\_rotation@{correct\_halo\_rotation}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{correct\_halo\_rotation()}{correct\_halo\_rotation()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::correct\+\_\+halo\+\_\+rotation (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:,\+:,\+:,\+:), intent(inout)}]{En,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),2), intent(in)}]{test,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{N\+Angle }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Rotates points in the halos where required to accommodate changes in grid orientation, such as at the tripolar fold. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The internal gravity wave energy density as a function of space, angular orientation, frequency, and vertical mode \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em test} & An x-\/unit vector that has been passed through \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\end{DoxyParams}


Definition at line 1812 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1812   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{1813 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:,:,:)}, \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{   !< The internal gravity wave energy density as a}}
\DoxyCodeLine{1814 \textcolor{comment}{                                       !! function of space, angular orientation, frequency,}}
\DoxyCodeLine{1815 \textcolor{comment}{                                       !! and vertical mode [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1816 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),2)}, \&}
\DoxyCodeLine{1817                               \textcolor{keywordtype}{intent(in)}    :: test\textcolor{comment}{ !< An x-unit vector that has been passed through}}
\DoxyCodeLine{1818 \textcolor{comment}{                                       !! the halo updates, to enable the rotation of the}}
\DoxyCodeLine{1819 \textcolor{comment}{                                       !! wave energies in the halo region to be corrected.}}
\DoxyCodeLine{1820   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{1821 \textcolor{comment}{                                                      !! discretized wave energy spectrum.}}
\DoxyCodeLine{1822   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1823 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,NAngle)} :: En2d}
\DoxyCodeLine{1824   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied)} :: a\_shift}
\DoxyCodeLine{1825   \textcolor{keywordtype}{integer} :: i\_first, i\_last, a\_new}
\DoxyCodeLine{1826   \textcolor{keywordtype}{integer} :: a, i, j, isd, ied, jsd, jed, m, fr}
\DoxyCodeLine{1827   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{1828   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{1829 }
\DoxyCodeLine{1830   \textcolor{keywordflow}{do} j=jsd,jed}
\DoxyCodeLine{1831     i\_first = ied+1 ; i\_last = isd-1}
\DoxyCodeLine{1832     \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{1833       a\_shift(i) = 0}
\DoxyCodeLine{1834       \textcolor{keywordflow}{if} (test(i,j,1) /= 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1835         \textcolor{keywordflow}{if} (i<i\_first) i\_first = i}
\DoxyCodeLine{1836         \textcolor{keywordflow}{if} (i>i\_last) i\_last = i}
\DoxyCodeLine{1837 }
\DoxyCodeLine{1838         \textcolor{keywordflow}{if} (test(i,j,1) == -1.0) \textcolor{keywordflow}{then} ; a\_shift(i) = nangle/2}
\DoxyCodeLine{1839         \textcolor{keywordflow}{elseif} (test(i,j,2) == 1.0) \textcolor{keywordflow}{then} ; a\_shift(i) = -nangle/4}
\DoxyCodeLine{1840         \textcolor{keywordflow}{elseif} (test(i,j,2) == -1.0) \textcolor{keywordflow}{then} ; a\_shift(i) = nangle/4}
\DoxyCodeLine{1841         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1842           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Unrecognized rotation test vector ",2ES9.2," at ",F7.2," E, ",\&}}
\DoxyCodeLine{1843 \textcolor{stringliteral}{}\textcolor{stringliteral}{                       \&F7.2," N; i,j=",2i4)'}) \&}
\DoxyCodeLine{1844                 test(i,j,1), test(i,j,2), g\%GeoLonT(i,j), g\%GeoLatT(i,j), i, j}
\DoxyCodeLine{1845           \textcolor{keyword}{call }mom\_error(fatal, mesg)}
\DoxyCodeLine{1846 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1847 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1848 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1849 }
\DoxyCodeLine{1850     \textcolor{keywordflow}{if} (i\_first <= i\_last) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1851       \textcolor{comment}{! At least one point in this row needs to be rotated.}}
\DoxyCodeLine{1852       \textcolor{keywordflow}{do} m=1,\textcolor{keyword}{size}(en,5) ; \textcolor{keywordflow}{do} fr=1,\textcolor{keyword}{size}(en,4)}
\DoxyCodeLine{1853         \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} i=i\_first,i\_last ; \textcolor{keywordflow}{if} (a\_shift(i) /= 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1854           a\_new = a + a\_shift(i)}
\DoxyCodeLine{1855           \textcolor{keywordflow}{if} (a\_new < 1) a\_new = a\_new + nangle}
\DoxyCodeLine{1856           \textcolor{keywordflow}{if} (a\_new > nangle) a\_new = a\_new - nangle}
\DoxyCodeLine{1857           en2d(i,a\_new) = en(i,j,a,fr,m)}
\DoxyCodeLine{1858 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1859         \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} i=i\_first,i\_last ; \textcolor{keywordflow}{if} (a\_shift(i) /= 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1860           en(i,j,a,fr,m) = en2d(i,a)}
\DoxyCodeLine{1861 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1862 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1863 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1864 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_aab59eb7eb4e4f422294ed62a97a6a75b}\label{namespacemom__internal__tides_aab59eb7eb4e4f422294ed62a97a6a75b}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!get\_lowmode\_loss@{get\_lowmode\_loss}}
\index{get\_lowmode\_loss@{get\_lowmode\_loss}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{get\_lowmode\_loss()}{get\_lowmode\_loss()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::get\+\_\+lowmode\+\_\+loss (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{i,  }\item[{integer, intent(in)}]{j,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{mechanism,  }\item[{real, intent(out)}]{T\+K\+E\+\_\+loss\+\_\+sum }\end{DoxyParamCaption})}



This subroutine extracts the energy lost from the propagating internal which has been summed across all angles, frequencies, and modes for a given mechanism and location. 

It can be called from another module to get values from this module\textquotesingle{}s (private) CS. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em i} & The i-\/index of the value to be reported. \\
\hline
\mbox{\texttt{ in}}  & {\em j} & The j-\/index of the value to be reported. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em mechanism} & The named mechanism of loss to return \\
\hline
\mbox{\texttt{ out}}  & {\em tke\+\_\+loss\+\_\+sum} & Total energy loss rate due to specified mechanism \mbox{[}R Z3 T-\/3 $\sim$$>$ W m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 728 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{728   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: i\textcolor{comment}{   !< The i-index of the value to be reported.}}
\DoxyCodeLine{729   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: j\textcolor{comment}{   !< The j-index of the value to be reported.}}
\DoxyCodeLine{730   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{   !< The ocean's grid structure}}
\DoxyCodeLine{731   \textcolor{keywordtype}{type}(int\_tide\_CS),     \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{  !< The control structure returned by a}}
\DoxyCodeLine{732 \textcolor{comment}{                                            !! previous call to int\_tide\_init.}}
\DoxyCodeLine{733   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}  :: mechanism\textcolor{comment}{    !< The named mechanism of loss to return}}
\DoxyCodeLine{734 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(out)} :: TKE\_loss\_sum\textcolor{comment}{ !< Total energy loss rate due to specified}}
\DoxyCodeLine{735 \textcolor{comment}{                                                     !! mechanism [R Z3 T-3 ~> W m-2].}}
\DoxyCodeLine{736 }
\DoxyCodeLine{737   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'LeakDrag'}) tke\_loss\_sum = cs\%tot\_leak\_loss(i,j)   \textcolor{comment}{! not used for mixing yet}}
\DoxyCodeLine{738   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'QuadDrag'}) tke\_loss\_sum = cs\%tot\_quad\_loss(i,j)   \textcolor{comment}{! not used for mixing yet}}
\DoxyCodeLine{739   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'WaveDrag'}) tke\_loss\_sum = cs\%tot\_itidal\_loss(i,j) \textcolor{comment}{! currently used for mixing}}
\DoxyCodeLine{740   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'Froude'})   tke\_loss\_sum = cs\%tot\_Froude\_loss(i,j) \textcolor{comment}{! not used for mixing yet}}
\DoxyCodeLine{741 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_ad4a7f6d606c46123f12b39dd98f71b37}\label{namespacemom__internal__tides_ad4a7f6d606c46123f12b39dd98f71b37}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!internal\_tides\_end@{internal\_tides\_end}}
\index{internal\_tides\_end@{internal\_tides\_end}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{internal\_tides\_end()}{internal\_tides\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::internal\+\_\+tides\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine deallocates the memory associated with the internal tides control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & A pointer to the control structure returned by a previous call to internal\+\_\+tides\+\_\+init, it will be deallocated here. \\
\hline
\end{DoxyParams}


Definition at line 2549 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2549   \textcolor{keywordtype}{type}(int\_tide\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< A pointer to the control structure returned by a previous}}
\DoxyCodeLine{2550 \textcolor{comment}{                                    !! call to internal\_tides\_init, it will be deallocated here.}}
\DoxyCodeLine{2551 }
\DoxyCodeLine{2552   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2553     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%En)) \textcolor{keyword}{deallocate}(cs\%En)}
\DoxyCodeLine{2554     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%frequency)) \textcolor{keyword}{deallocate}(cs\%frequency)}
\DoxyCodeLine{2555     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%id\_En\_mode)) \textcolor{keyword}{deallocate}(cs\%id\_En\_mode)}
\DoxyCodeLine{2556     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%id\_Ub\_mode)) \textcolor{keyword}{deallocate}(cs\%id\_Ub\_mode)}
\DoxyCodeLine{2557     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs\%id\_cp\_mode)) \textcolor{keyword}{deallocate}(cs\%id\_cp\_mode)}
\DoxyCodeLine{2558     \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{2559 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2560   cs => null()}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a48431ac355c6fa3de7548bfdec620eb0}\label{namespacemom__internal__tides_a48431ac355c6fa3de7548bfdec620eb0}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!internal\_tides\_init@{internal\_tides\_init}}
\index{internal\_tides\_init@{internal\_tides\_init}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{internal\_tides\_init()}{internal\_tides\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::internal\+\_\+tides\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{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(in), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine initializes the internal tides module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\mbox{\texttt{ in,out}}  & {\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}}  & {\em diag} & A structure that is used to regulate diagnostic output. \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 2102 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2102   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< The current model time.}}
\DoxyCodeLine{2103   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{2104   \textcolor{keywordtype}{type}(verticalGrid\_type),   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure.}}
\DoxyCodeLine{2105   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{2106   \textcolor{keywordtype}{type}(param\_file\_type),     \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time}}
\DoxyCodeLine{2107 \textcolor{comment}{                                                   !! parameters.}}
\DoxyCodeLine{2108   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(in)}    :: diag\textcolor{comment}{ !< A structure that is used to regulate}}
\DoxyCodeLine{2109 \textcolor{comment}{                                                   !! diagnostic output.}}
\DoxyCodeLine{2110   \textcolor{keywordtype}{type}(int\_tide\_CS),\textcolor{keywordtype}{pointer}                :: CS\textcolor{comment}{   !< A pointer that is set to point to the control}}
\DoxyCodeLine{2111 \textcolor{comment}{                                                   !! structure for this module.}}
\DoxyCodeLine{2112   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2113 \textcolor{keywordtype}{  real}                              :: Angle\_size \textcolor{comment}{! size of wedges, rad}}
\DoxyCodeLine{2114 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}                 :: angles(:)  \textcolor{comment}{! orientations of wedge centers, rad}}
\DoxyCodeLine{2115 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: h2         \textcolor{comment}{! topographic roughness scale, m\string^2}}
\DoxyCodeLine{2116 \textcolor{keywordtype}{  real}                              :: kappa\_itides, kappa\_h2\_factor}
\DoxyCodeLine{2117                                                   \textcolor{comment}{! characteristic topographic wave number}}
\DoxyCodeLine{2118                                                   \textcolor{comment}{! and a scaling factor}}
\DoxyCodeLine{2119 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{allocatable}                 :: ridge\_temp(:,:)}
\DoxyCodeLine{2120                                                   \textcolor{comment}{! array for temporary storage of flags}}
\DoxyCodeLine{2121                                                   \textcolor{comment}{! of cells with double-reflecting ridges}}
\DoxyCodeLine{2122   \textcolor{keywordtype}{logical}                           :: use\_int\_tides, use\_temperature}
\DoxyCodeLine{2123 \textcolor{keywordtype}{  real}    :: period\_1  \textcolor{comment}{! The period of the gravest modeled mode [T ~> s]}}
\DoxyCodeLine{2124   \textcolor{keywordtype}{integer} :: num\_angle, num\_freq, num\_mode, m, fr}
\DoxyCodeLine{2125   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, a, id\_ang, i, j}
\DoxyCodeLine{2126   \textcolor{keywordtype}{type}(axes\_grp) :: axes\_ang}
\DoxyCodeLine{2127   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{2128 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{2129 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_internal\_tides"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{2130   \textcolor{keywordtype}{character(len=16)}, \textcolor{keywordtype}{dimension(8)} :: freq\_name}
\DoxyCodeLine{2131   \textcolor{keywordtype}{character(len=40)}  :: var\_name}
\DoxyCodeLine{2132   \textcolor{keywordtype}{character(len=160)} :: var\_descript}
\DoxyCodeLine{2133   \textcolor{keywordtype}{character(len=200)} :: filename}
\DoxyCodeLine{2134   \textcolor{keywordtype}{character(len=200)} :: refl\_angle\_file, land\_mask\_file}
\DoxyCodeLine{2135   \textcolor{keywordtype}{character(len=200)} :: refl\_pref\_file, refl\_dbl\_file}
\DoxyCodeLine{2136   \textcolor{keywordtype}{character(len=200)} :: dy\_Cu\_file, dx\_Cv\_file}
\DoxyCodeLine{2137   \textcolor{keywordtype}{character(len=200)} :: h2\_file}
\DoxyCodeLine{2138 }
\DoxyCodeLine{2139   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{2140 }
\DoxyCodeLine{2141   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2142     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"internal\_tides\_init called "}//\&}
\DoxyCodeLine{2143                              \textcolor{stringliteral}{"with an associated control structure."})}
\DoxyCodeLine{2144     \textcolor{keywordflow}{return}}
\DoxyCodeLine{2145   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2146     \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{2147 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2148 }
\DoxyCodeLine{2149   use\_int\_tides = .false.}
\DoxyCodeLine{2150   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDES"}, use\_int\_tides)}
\DoxyCodeLine{2151   cs\%do\_int\_tides = use\_int\_tides}
\DoxyCodeLine{2152   \textcolor{keywordflow}{if} (.not.use\_int\_tides) \textcolor{keywordflow}{return}}
\DoxyCodeLine{2153 }
\DoxyCodeLine{2154   use\_temperature = .true.}
\DoxyCodeLine{2155   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, use\_temperature)}
\DoxyCodeLine{2156   \textcolor{keywordflow}{if} (.not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2157     \textcolor{stringliteral}{"register\_int\_tide\_restarts: internal\_tides only works with "}//\&}
\DoxyCodeLine{2158     \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS defined."})}
\DoxyCodeLine{2159 }
\DoxyCodeLine{2160   \textcolor{comment}{! Set number of frequencies, angles, and modes to consider}}
\DoxyCodeLine{2161   num\_freq = 1 ; num\_angle = 24 ; num\_mode = 1}
\DoxyCodeLine{2162   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDE\_FREQS"}, num\_freq)}
\DoxyCodeLine{2163   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDE\_ANGLES"}, num\_angle)}
\DoxyCodeLine{2164   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDE\_MODES"}, num\_mode)}
\DoxyCodeLine{2165   \textcolor{keywordflow}{if} (.not.((num\_freq > 0) .and. (num\_angle > 0) .and. (num\_mode > 0))) \textcolor{keywordflow}{return}}
\DoxyCodeLine{2166   cs\%nFreq = num\_freq ; cs\%nAngle = num\_angle ; cs\%nMode = num\_mode}
\DoxyCodeLine{2167 }
\DoxyCodeLine{2168   \textcolor{comment}{! Allocate energy density array}}
\DoxyCodeLine{2169   \textcolor{keyword}{allocate}(cs\%En(isd:ied, jsd:jed, num\_angle, num\_freq, num\_mode))}
\DoxyCodeLine{2170   cs\%En(:,:,:,:,:) = 0.0}
\DoxyCodeLine{2171 }
\DoxyCodeLine{2172   \textcolor{comment}{! Allocate phase speed array}}
\DoxyCodeLine{2173   \textcolor{keyword}{allocate}(cs\%cp(isd:ied, jsd:jed, num\_freq, num\_mode))}
\DoxyCodeLine{2174   cs\%cp(:,:,:,:) = 0.0}
\DoxyCodeLine{2175 }
\DoxyCodeLine{2176   \textcolor{comment}{! Allocate and populate frequency array (each a multiple of first for now)}}
\DoxyCodeLine{2177   \textcolor{keyword}{allocate}(cs\%frequency(num\_freq))}
\DoxyCodeLine{2178   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FIRST\_MODE\_PERIOD"}, period\_1, units=\textcolor{stringliteral}{"s"}, scale=us\%s\_to\_T)}
\DoxyCodeLine{2179   \textcolor{keywordflow}{do} fr=1,num\_freq}
\DoxyCodeLine{2180     cs\%frequency(fr) = (8.0*atan(1.0) * (real(fr)) / period\_1) \textcolor{comment}{! ADDED BDM}}
\DoxyCodeLine{2181 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2182 }
\DoxyCodeLine{2183   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{2184 }
\DoxyCodeLine{2185   cs\%Time => time \textcolor{comment}{! direct a pointer to the current model time target}}
\DoxyCodeLine{2186 }
\DoxyCodeLine{2187   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, cs\%inputdir, default=\textcolor{stringliteral}{"."})}
\DoxyCodeLine{2188                  cs\%inputdir = slasher(cs\%inputdir)}
\DoxyCodeLine{2189 }
\DoxyCodeLine{2190   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{2191 }
\DoxyCodeLine{2192   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_FREQS"}, num\_freq, \&}
\DoxyCodeLine{2193                  \textcolor{stringliteral}{"The number of distinct internal tide frequency bands "}//\&}
\DoxyCodeLine{2194                  \textcolor{stringliteral}{"that will be calculated."}, default=1)}
\DoxyCodeLine{2195   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_MODES"}, num\_mode, \&}
\DoxyCodeLine{2196                  \textcolor{stringliteral}{"The number of distinct internal tide modes "}//\&}
\DoxyCodeLine{2197                  \textcolor{stringliteral}{"that will be calculated."}, default=1)}
\DoxyCodeLine{2198   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_ANGLES"}, num\_angle, \&}
\DoxyCodeLine{2199                  \textcolor{stringliteral}{"The number of angular resolution bands for the internal "}//\&}
\DoxyCodeLine{2200                  \textcolor{stringliteral}{"tide calculations."}, default=24)}
\DoxyCodeLine{2201 }
\DoxyCodeLine{2202   \textcolor{keywordflow}{if} (use\_int\_tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2203     \textcolor{keywordflow}{if} ((num\_freq <= 0) .and. (num\_mode <= 0) .and. (num\_angle <= 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2204       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Internal tides were enabled, but the number "}//\&}
\DoxyCodeLine{2205              \textcolor{stringliteral}{"of requested frequencies, modes and angles were not all positive."})}
\DoxyCodeLine{2206       \textcolor{keywordflow}{return}}
\DoxyCodeLine{2207 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2208   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2209     \textcolor{keywordflow}{if} ((num\_freq > 0) .and. (num\_mode > 0) .and. (num\_angle > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2210       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Internal tides were not enabled, even though "}//\&}
\DoxyCodeLine{2211              \textcolor{stringliteral}{"the number of requested frequencies, modes and angles were all "}//\&}
\DoxyCodeLine{2212              \textcolor{stringliteral}{"positive."})}
\DoxyCodeLine{2213       \textcolor{keywordflow}{return}}
\DoxyCodeLine{2214 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2215 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2216 }
\DoxyCodeLine{2217   \textcolor{keywordflow}{if} (cs\%NFreq /= num\_freq) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Internal\_tides\_init: "}//\&}
\DoxyCodeLine{2218       \textcolor{stringliteral}{"Inconsistent number of frequencies."})}
\DoxyCodeLine{2219   \textcolor{keywordflow}{if} (cs\%NAngle /= num\_angle) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Internal\_tides\_init: "}//\&}
\DoxyCodeLine{2220       \textcolor{stringliteral}{"Inconsistent number of angles."})}
\DoxyCodeLine{2221   \textcolor{keywordflow}{if} (cs\%NMode /= num\_mode) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Internal\_tides\_init: "}//\&}
\DoxyCodeLine{2222       \textcolor{stringliteral}{"Inconsistent number of modes."})}
\DoxyCodeLine{2223   \textcolor{keywordflow}{if} (4*(num\_angle/4) /= num\_angle) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2224     \textcolor{stringliteral}{"Internal\_tides\_init: INTERNAL\_TIDE\_ANGLES must be a multiple of 4."})}
\DoxyCodeLine{2225 }
\DoxyCodeLine{2226   cs\%diag => diag}
\DoxyCodeLine{2227 }
\DoxyCodeLine{2228   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_DECAY\_RATE"}, cs\%decay\_rate, \&}
\DoxyCodeLine{2229                  \textcolor{stringliteral}{"The rate at which internal tide energy is lost to the "}//\&}
\DoxyCodeLine{2230                  \textcolor{stringliteral}{"interior ocean internal wave field."}, \&}
\DoxyCodeLine{2231                  units=\textcolor{stringliteral}{"s-1"}, default=0.0, scale=us\%T\_to\_s)}
\DoxyCodeLine{2232   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_VOLUME\_BASED\_CFL"}, cs\%vol\_CFL, \&}
\DoxyCodeLine{2233                  \textcolor{stringliteral}{"If true, use the ratio of the open face lengths to the "}//\&}
\DoxyCodeLine{2234                  \textcolor{stringliteral}{"tracer cell areas when estimating CFL numbers in the "}//\&}
\DoxyCodeLine{2235                  \textcolor{stringliteral}{"internal tide code."}, default=.false.)}
\DoxyCodeLine{2236   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_CORNER\_ADVECT"}, cs\%corner\_adv, \&}
\DoxyCodeLine{2237                  \textcolor{stringliteral}{"If true, internal tide ray-tracing advection uses a "}//\&}
\DoxyCodeLine{2238                  \textcolor{stringliteral}{"corner-advection scheme rather than PPM."}, default=.false.)}
\DoxyCodeLine{2239   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_SIMPLE\_2ND\_PPM"}, cs\%simple\_2nd, \&}
\DoxyCodeLine{2240                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM uses a simple 2nd order "}//\&}
\DoxyCodeLine{2241                  \textcolor{stringliteral}{"(arithmetic mean) interpolation of the edge values. "}//\&}
\DoxyCodeLine{2242                  \textcolor{stringliteral}{"This may give better PV conservation properties. While "}//\&}
\DoxyCodeLine{2243                  \textcolor{stringliteral}{"it formally reduces the accuracy of the continuity "}//\&}
\DoxyCodeLine{2244                  \textcolor{stringliteral}{"solver itself in the strongly advective limit, it does "}//\&}
\DoxyCodeLine{2245                  \textcolor{stringliteral}{"not reduce the overall order of accuracy of the dynamic "}//\&}
\DoxyCodeLine{2246                  \textcolor{stringliteral}{"core."}, default=.false.)}
\DoxyCodeLine{2247   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_UPWIND\_1ST"}, cs\%upwind\_1st, \&}
\DoxyCodeLine{2248                  \textcolor{stringliteral}{"If true, the internal tide ray-tracing advection uses "}//\&}
\DoxyCodeLine{2249                  \textcolor{stringliteral}{"1st-order upwind advection.  This scheme is highly "}//\&}
\DoxyCodeLine{2250                  \textcolor{stringliteral}{"continuity solver.  This scheme is highly "}//\&}
\DoxyCodeLine{2251                  \textcolor{stringliteral}{"diffusive but may be useful for debugging."}, default=.false.)}
\DoxyCodeLine{2252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_BACKGROUND\_DRAG"}, \&}
\DoxyCodeLine{2253                  cs\%apply\_background\_drag, \textcolor{stringliteral}{"If true, the internal tide "}//\&}
\DoxyCodeLine{2254                  \textcolor{stringliteral}{"ray-tracing advection uses a background drag term as a sink."},\&}
\DoxyCodeLine{2255                  default=.false.)}
\DoxyCodeLine{2256   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_QUAD\_DRAG"}, cs\%apply\_bottom\_drag, \&}
\DoxyCodeLine{2257                  \textcolor{stringliteral}{"If true, the internal tide ray-tracing advection uses "}//\&}
\DoxyCodeLine{2258                  \textcolor{stringliteral}{"a quadratic bottom drag term as a sink."}, default=.false.)}
\DoxyCodeLine{2259   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_WAVE\_DRAG"}, cs\%apply\_wave\_drag, \&}
\DoxyCodeLine{2260                  \textcolor{stringliteral}{"If true, apply scattering due to small-scale roughness as a sink."}, \&}
\DoxyCodeLine{2261                  default=.false.)}
\DoxyCodeLine{2262   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_FROUDE\_DRAG"}, cs\%apply\_Froude\_drag, \&}
\DoxyCodeLine{2263                  \textcolor{stringliteral}{"If true, apply wave breaking as a sink."}, \&}
\DoxyCodeLine{2264                  default=.false.)}
\DoxyCodeLine{2265   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CDRAG"}, cs\%cdrag, \&}
\DoxyCodeLine{2266                  \textcolor{stringliteral}{"CDRAG is the drag coefficient relating the magnitude of "}//\&}
\DoxyCodeLine{2267                  \textcolor{stringliteral}{"the velocity field to the bottom stress."}, units=\textcolor{stringliteral}{"nondim"}, \&}
\DoxyCodeLine{2268                  default=0.003)}
\DoxyCodeLine{2269   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_ENERGIZED\_ANGLE"}, cs\%energized\_angle, \&}
\DoxyCodeLine{2270                  \textcolor{stringliteral}{"If positive, only one angular band of the internal tides "}//\&}
\DoxyCodeLine{2271                  \textcolor{stringliteral}{"gets all of the energy.  (This is for debugging.)"}, default=-1)}
\DoxyCodeLine{2272   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_PPM\_ANGULAR"}, cs\%use\_PPMang, \&}
\DoxyCodeLine{2273                  \textcolor{stringliteral}{"If true, use PPM for advection of energy in angular space."}, \&}
\DoxyCodeLine{2274                  default=.false.)}
\DoxyCodeLine{2275   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GAMMA\_ITIDES"}, cs\%q\_itides, \&}
\DoxyCodeLine{2276                  \textcolor{stringliteral}{"The fraction of the internal tidal energy that is "}//\&}
\DoxyCodeLine{2277                  \textcolor{stringliteral}{"dissipated locally with INT\_TIDE\_DISSIPATION. "}//\&}
\DoxyCodeLine{2278                  \textcolor{stringliteral}{"THIS NAME COULD BE BETTER."}, \&}
\DoxyCodeLine{2279                  units=\textcolor{stringliteral}{"nondim"}, default=0.3333)}
\DoxyCodeLine{2280   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KAPPA\_ITIDES"}, kappa\_itides, \&}
\DoxyCodeLine{2281                \textcolor{stringliteral}{"A topographic wavenumber used with INT\_TIDE\_DISSIPATION. "}//\&}
\DoxyCodeLine{2282                \textcolor{stringliteral}{"The default is 2pi/10 km, as in St.Laurent et al. 2002."}, \&}
\DoxyCodeLine{2283                units=\textcolor{stringliteral}{"m-1"}, default=8.e-4*atan(1.0), scale=us\%L\_to\_m)}
\DoxyCodeLine{2284   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KAPPA\_H2\_FACTOR"}, kappa\_h2\_factor, \&}
\DoxyCodeLine{2285                \textcolor{stringliteral}{"A scaling factor for the roughness amplitude with n"}//\&}
\DoxyCodeLine{2286                \textcolor{stringliteral}{"INT\_TIDE\_DISSIPATION."},  units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{2287 }
\DoxyCodeLine{2288   \textcolor{comment}{! Allocate various arrays needed for loss rates}}
\DoxyCodeLine{2289   \textcolor{keyword}{allocate}(h2(isd:ied,jsd:jed)) ; h2(:,:) = 0.0}
\DoxyCodeLine{2290   \textcolor{keyword}{allocate}(cs\%TKE\_itidal\_loss\_fixed(isd:ied,jsd:jed))}
\DoxyCodeLine{2291     cs\%TKE\_itidal\_loss\_fixed = 0.0}
\DoxyCodeLine{2292   \textcolor{keyword}{allocate}(cs\%TKE\_leak\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))}
\DoxyCodeLine{2293     cs\%TKE\_leak\_loss(:,:,:,:,:) = 0.0}
\DoxyCodeLine{2294   \textcolor{keyword}{allocate}(cs\%TKE\_quad\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))}
\DoxyCodeLine{2295     cs\%TKE\_quad\_loss(:,:,:,:,:) = 0.0}
\DoxyCodeLine{2296   \textcolor{keyword}{allocate}(cs\%TKE\_itidal\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))}
\DoxyCodeLine{2297     cs\%TKE\_itidal\_loss(:,:,:,:,:) = 0.0}
\DoxyCodeLine{2298   \textcolor{keyword}{allocate}(cs\%TKE\_Froude\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))}
\DoxyCodeLine{2299     cs\%TKE\_Froude\_loss(:,:,:,:,:) = 0.0}
\DoxyCodeLine{2300   \textcolor{keyword}{allocate}(cs\%tot\_leak\_loss(isd:ied,jsd:jed))   ; cs\%tot\_leak\_loss(:,:) = 0.0}
\DoxyCodeLine{2301   \textcolor{keyword}{allocate}(cs\%tot\_quad\_loss(isd:ied,jsd:jed) )  ; cs\%tot\_quad\_loss(:,:) = 0.0}
\DoxyCodeLine{2302   \textcolor{keyword}{allocate}(cs\%tot\_itidal\_loss(isd:ied,jsd:jed)) ; cs\%tot\_itidal\_loss(:,:) = 0.0}
\DoxyCodeLine{2303   \textcolor{keyword}{allocate}(cs\%tot\_Froude\_loss(isd:ied,jsd:jed)) ; cs\%tot\_Froude\_loss(:,:) = 0.0}
\DoxyCodeLine{2304 }
\DoxyCodeLine{2305   \textcolor{comment}{! Compute the fixed part of the bottom drag loss from baroclinic modes}}
\DoxyCodeLine{2306   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"H2\_FILE"}, h2\_file, \&}
\DoxyCodeLine{2307           \textcolor{stringliteral}{"The path to the file containing the sub-grid-scale "}//\&}
\DoxyCodeLine{2308           \textcolor{stringliteral}{"topographic roughness amplitude with INT\_TIDE\_DISSIPATION."}, \&}
\DoxyCodeLine{2309           fail\_if\_missing=.true.)}
\DoxyCodeLine{2310   filename = trim(cs\%inputdir) // trim(h2\_file)}
\DoxyCodeLine{2311   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/H2\_FILE"}, filename)}
\DoxyCodeLine{2312   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'h2'}, h2, g\%domain, timelevel=1, scale=us\%m\_to\_Z)}
\DoxyCodeLine{2313   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{2314     \textcolor{comment}{! Restrict rms topo to 10 percent of column depth.}}
\DoxyCodeLine{2315     h2(i,j) = min(0.01*(g\%bathyT(i,j))**2, h2(i,j))}
\DoxyCodeLine{2316     \textcolor{comment}{! Compute the fixed part; units are [R L-2 Z3 ~> kg m-2] here}}
\DoxyCodeLine{2317     \textcolor{comment}{! will be multiplied by N and the squared near-bottom velocity to get into [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{2318     cs\%TKE\_itidal\_loss\_fixed(i,j) = 0.5*kappa\_h2\_factor*gv\%Rho0 * us\%L\_to\_Z*kappa\_itides * h2(i,j)}
\DoxyCodeLine{2319 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2320 }
\DoxyCodeLine{2321   \textcolor{keyword}{deallocate}(h2)}
\DoxyCodeLine{2322 }
\DoxyCodeLine{2323   \textcolor{comment}{! Read in prescribed coast/ridge/shelf angles from file}}
\DoxyCodeLine{2324   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REFL\_ANGLE\_FILE"}, refl\_angle\_file, \&}
\DoxyCodeLine{2325                \textcolor{stringliteral}{"The path to the file containing the local angle of "}//\&}
\DoxyCodeLine{2326                \textcolor{stringliteral}{"the coastline/ridge/shelf with respect to the equator."}, \&}
\DoxyCodeLine{2327                fail\_if\_missing=.false., default=\textcolor{stringliteral}{''})}
\DoxyCodeLine{2328   filename = trim(cs\%inputdir) // trim(refl\_angle\_file)}
\DoxyCodeLine{2329   \textcolor{keyword}{allocate}(cs\%refl\_angle(isd:ied,jsd:jed)) ; cs\%refl\_angle(:,:) = cs\%nullangle}
\DoxyCodeLine{2330   \textcolor{keywordflow}{if} (file\_exists(filename, g\%domain)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2331     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/REFL\_ANGLE\_FILE"}, filename)}
\DoxyCodeLine{2332     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'refl\_angle'}, cs\%refl\_angle, \&}
\DoxyCodeLine{2333                        g\%domain, timelevel=1)}
\DoxyCodeLine{2334   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2335     \textcolor{keywordflow}{if} (trim(refl\_angle\_file) /= \textcolor{stringliteral}{''} ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2336                                                      \textcolor{stringliteral}{"REFL\_ANGLE\_FILE: "}//trim(filename)//\textcolor{stringliteral}{" not found"})}
\DoxyCodeLine{2337 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2338   \textcolor{comment}{! replace NANs with null value}}
\DoxyCodeLine{2339   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{2340     \textcolor{keywordflow}{if} (is\_nan(cs\%refl\_angle(i,j))) cs\%refl\_angle(i,j) = cs\%nullangle}
\DoxyCodeLine{2341 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2342   \textcolor{keyword}{call }pass\_var(cs\%refl\_angle,g\%domain)}
\DoxyCodeLine{2343 }
\DoxyCodeLine{2344   \textcolor{comment}{! Read in prescribed partial reflection coefficients from file}}
\DoxyCodeLine{2345   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REFL\_PREF\_FILE"}, refl\_pref\_file, \&}
\DoxyCodeLine{2346                \textcolor{stringliteral}{"The path to the file containing the reflection coefficients."}, \&}
\DoxyCodeLine{2347                fail\_if\_missing=.false., default=\textcolor{stringliteral}{''})}
\DoxyCodeLine{2348   filename = trim(cs\%inputdir) // trim(refl\_pref\_file)}
\DoxyCodeLine{2349   \textcolor{keyword}{allocate}(cs\%refl\_pref(isd:ied,jsd:jed)) ; cs\%refl\_pref(:,:) = 1.0}
\DoxyCodeLine{2350   \textcolor{keywordflow}{if} (file\_exists(filename, g\%domain)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2351     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/REFL\_PREF\_FILE"}, filename)}
\DoxyCodeLine{2352     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'refl\_pref'}, cs\%refl\_pref, g\%domain, timelevel=1)}
\DoxyCodeLine{2353   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2354     \textcolor{keywordflow}{if} (trim(refl\_pref\_file) /= \textcolor{stringliteral}{''} ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2355                                                     \textcolor{stringliteral}{"REFL\_PREF\_FILE: "}//trim(filename)//\textcolor{stringliteral}{" not found"})}
\DoxyCodeLine{2356 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2357   \textcolor{comment}{!CS\%refl\_pref = CS\%refl\_pref*1 ! adjust partial reflection if desired}}
\DoxyCodeLine{2358   \textcolor{keyword}{call }pass\_var(cs\%refl\_pref,g\%domain)}
\DoxyCodeLine{2359 }
\DoxyCodeLine{2360   \textcolor{comment}{! Tag reflection cells with partial reflection (done here for speed)}}
\DoxyCodeLine{2361   \textcolor{keyword}{allocate}(cs\%refl\_pref\_logical(isd:ied,jsd:jed)) ; cs\%refl\_pref\_logical(:,:) = .false.}
\DoxyCodeLine{2362   \textcolor{keywordflow}{do} j=jsd,jed}
\DoxyCodeLine{2363     \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{2364       \textcolor{comment}{! flag cells with partial reflection}}
\DoxyCodeLine{2365       \textcolor{keywordflow}{if} (cs\%refl\_angle(i,j) /= cs\%nullangle .and. \&}
\DoxyCodeLine{2366         cs\%refl\_pref(i,j) < 1.0 .and. cs\%refl\_pref(i,j) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2367         cs\%refl\_pref\_logical(i,j) = .true.}
\DoxyCodeLine{2368 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2369 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{2370 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{2371 }
\DoxyCodeLine{2372   \textcolor{comment}{! Read in double-reflective (ridge) tags from file}}
\DoxyCodeLine{2373   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REFL\_DBL\_FILE"}, refl\_dbl\_file, \&}
\DoxyCodeLine{2374                \textcolor{stringliteral}{"The path to the file containing the double-reflective ridge tags."}, \&}
\DoxyCodeLine{2375                fail\_if\_missing=.false., default=\textcolor{stringliteral}{''})}
\DoxyCodeLine{2376   filename = trim(cs\%inputdir) // trim(refl\_dbl\_file)}
\DoxyCodeLine{2377   \textcolor{keyword}{allocate}(ridge\_temp(isd:ied,jsd:jed)) ; ridge\_temp(:,:) = 0.0}
\DoxyCodeLine{2378   \textcolor{keywordflow}{if} (file\_exists(filename, g\%domain)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2379     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/REFL\_DBL\_FILE"}, filename)}
\DoxyCodeLine{2380     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'refl\_dbl'}, ridge\_temp, g\%domain, timelevel=1)}
\DoxyCodeLine{2381   \textcolor{keywordflow}{else}}
\DoxyCodeLine{2382     \textcolor{keywordflow}{if} (trim(refl\_dbl\_file) /= \textcolor{stringliteral}{''} ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{2383                                                    \textcolor{stringliteral}{"REFL\_DBL\_FILE: "}//trim(filename)//\textcolor{stringliteral}{" not found"})}
\DoxyCodeLine{2384 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2385   \textcolor{keyword}{call }pass\_var(ridge\_temp,g\%domain)}
\DoxyCodeLine{2386   \textcolor{keyword}{allocate}(cs\%refl\_dbl(isd:ied,jsd:jed)) ; cs\%refl\_dbl(:,:) = .false.}
\DoxyCodeLine{2387   \textcolor{keywordflow}{do} i=isd,ied; \textcolor{keywordflow}{do} j=jsd,jed}
\DoxyCodeLine{2388     \textcolor{keywordflow}{if} (ridge\_temp(i,j) == 1) then; cs\%refl\_dbl(i,j) = .true.}
\DoxyCodeLine{2389     \textcolor{keywordflow}{else} ; cs\%refl\_dbl(i,j) = .false. ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{2390 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2391 }
\DoxyCodeLine{2392   \textcolor{comment}{! Read in prescribed land mask from file (if overwriting -BDM).}}
\DoxyCodeLine{2393   \textcolor{comment}{! This should be done in MOM\_initialize\_topography subroutine}}
\DoxyCodeLine{2394   \textcolor{comment}{! defined in MOM\_fixed\_initialization.F90 (BDM)}}
\DoxyCodeLine{2395   \textcolor{comment}{!call get\_param(param\_file, mdl, "LAND\_MASK\_FILE", land\_mask\_file, \&}}
\DoxyCodeLine{2396   \textcolor{comment}{!             "The path to the file containing the land mask.", \&}}
\DoxyCodeLine{2397   \textcolor{comment}{!             fail\_if\_missing=.false.)}}
\DoxyCodeLine{2398   \textcolor{comment}{!filename = trim(CS\%inputdir) // trim(land\_mask\_file)}}
\DoxyCodeLine{2399   \textcolor{comment}{!call log\_param(param\_file, mdl, "INPUTDIR/LAND\_MASK\_FILE", filename)}}
\DoxyCodeLine{2400   \textcolor{comment}{!G\%mask2dCu(:,:) = 1 ; G\%mask2dCv(:,:) = 1 ; G\%mask2dT(:,:)  = 1}}
\DoxyCodeLine{2401   \textcolor{comment}{!call MOM\_read\_data(filename, 'land\_mask', G\%mask2dCu, G\%domain, timelevel=1)}}
\DoxyCodeLine{2402   \textcolor{comment}{!call MOM\_read\_data(filename, 'land\_mask', G\%mask2dCv, G\%domain, timelevel=1)}}
\DoxyCodeLine{2403   \textcolor{comment}{!call MOM\_read\_data(filename, 'land\_mask', G\%mask2dT, G\%domain, timelevel=1)}}
\DoxyCodeLine{2404   \textcolor{comment}{!call pass\_vector(G\%mask2dCu, G\%mask2dCv, G\%domain, To\_All+Scalar\_Pair, CGRID\_NE)}}
\DoxyCodeLine{2405   \textcolor{comment}{!call pass\_var(G\%mask2dT,G\%domain)}}
\DoxyCodeLine{2406 }
\DoxyCodeLine{2407   \textcolor{comment}{! Read in prescribed partial east face blockages from file (if overwriting -BDM)}}
\DoxyCodeLine{2408   \textcolor{comment}{!call get\_param(param\_file, mdl, "dy\_Cu\_FILE", dy\_Cu\_file, \&}}
\DoxyCodeLine{2409   \textcolor{comment}{!             "The path to the file containing the east face blockages.", \&}}
\DoxyCodeLine{2410   \textcolor{comment}{!             fail\_if\_missing=.false.)}}
\DoxyCodeLine{2411   \textcolor{comment}{!filename = trim(CS\%inputdir) // trim(dy\_Cu\_file)}}
\DoxyCodeLine{2412   \textcolor{comment}{!call log\_param(param\_file, mdl, "INPUTDIR/dy\_Cu\_FILE", filename)}}
\DoxyCodeLine{2413   \textcolor{comment}{!G\%dy\_Cu(:,:) = 0.0}}
\DoxyCodeLine{2414   \textcolor{comment}{!call MOM\_read\_data(filename, 'dy\_Cu', G\%dy\_Cu, G\%domain, timelevel=1, scale=US\%m\_to\_L)}}
\DoxyCodeLine{2415 }
\DoxyCodeLine{2416   \textcolor{comment}{! Read in prescribed partial north face blockages from file (if overwriting -BDM)}}
\DoxyCodeLine{2417   \textcolor{comment}{!call get\_param(param\_file, mdl, "dx\_Cv\_FILE", dx\_Cv\_file, \&}}
\DoxyCodeLine{2418   \textcolor{comment}{!             "The path to the file containing the north face blockages.", \&}}
\DoxyCodeLine{2419   \textcolor{comment}{!             fail\_if\_missing=.false.)}}
\DoxyCodeLine{2420   \textcolor{comment}{!filename = trim(CS\%inputdir) // trim(dx\_Cv\_file)}}
\DoxyCodeLine{2421   \textcolor{comment}{!call log\_param(param\_file, mdl, "INPUTDIR/dx\_Cv\_FILE", filename)}}
\DoxyCodeLine{2422   \textcolor{comment}{!G\%dx\_Cv(:,:) = 0.0}}
\DoxyCodeLine{2423   \textcolor{comment}{!call MOM\_read\_data(filename, 'dx\_Cv', G\%dx\_Cv, G\%domain, timelevel=1, scale=US\%m\_to\_L)}}
\DoxyCodeLine{2424   \textcolor{comment}{!call pass\_vector(G\%dy\_Cu, G\%dx\_Cv, G\%domain, To\_All+Scalar\_Pair, CGRID\_NE)}}
\DoxyCodeLine{2425 }
\DoxyCodeLine{2426   \textcolor{comment}{! Register maps of reflection parameters}}
\DoxyCodeLine{2427   cs\%id\_refl\_ang = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'refl\_angle'}, diag\%axesT1, \&}
\DoxyCodeLine{2428                  time, \textcolor{stringliteral}{'Local angle of coastline/ridge/shelf with respect to equator'}, \textcolor{stringliteral}{'rad'})}
\DoxyCodeLine{2429   cs\%id\_refl\_pref = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'refl\_pref'}, diag\%axesT1, \&}
\DoxyCodeLine{2430                  time, \textcolor{stringliteral}{'Partial reflection coefficients'}, \textcolor{stringliteral}{''})}
\DoxyCodeLine{2431   cs\%id\_dx\_Cv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dx\_Cv'}, diag\%axesT1, \&}
\DoxyCodeLine{2432                  time, \textcolor{stringliteral}{'North face unblocked width'}, \textcolor{stringliteral}{'m'}, conversion=us\%L\_to\_m)}
\DoxyCodeLine{2433   cs\%id\_dy\_Cu = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dy\_Cu'}, diag\%axesT1, \&}
\DoxyCodeLine{2434                  time, \textcolor{stringliteral}{'East face unblocked width'}, \textcolor{stringliteral}{'m'}, conversion=us\%L\_to\_m)}
\DoxyCodeLine{2435   cs\%id\_land\_mask = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'land\_mask'}, diag\%axesT1, \&}
\DoxyCodeLine{2436                  time, \textcolor{stringliteral}{'Land mask'}, \textcolor{stringliteral}{'logical'})            \textcolor{comment}{! used if overriding (BDM)}}
\DoxyCodeLine{2437   \textcolor{comment}{! Output reflection parameters as diags here (not needed every timestep)}}
\DoxyCodeLine{2438   \textcolor{keywordflow}{if} (cs\%id\_refl\_ang > 0)   \textcolor{keyword}{call }post\_data(cs\%id\_refl\_ang, cs\%refl\_angle, cs\%diag)}
\DoxyCodeLine{2439   \textcolor{keywordflow}{if} (cs\%id\_refl\_pref > 0)  \textcolor{keyword}{call }post\_data(cs\%id\_refl\_pref, cs\%refl\_pref, cs\%diag)}
\DoxyCodeLine{2440   \textcolor{keywordflow}{if} (cs\%id\_dx\_Cv > 0)      \textcolor{keyword}{call }post\_data(cs\%id\_dx\_Cv, g\%dx\_Cv, cs\%diag)}
\DoxyCodeLine{2441   \textcolor{keywordflow}{if} (cs\%id\_dy\_Cu > 0)      \textcolor{keyword}{call }post\_data(cs\%id\_dy\_Cu, g\%dy\_Cu, cs\%diag)}
\DoxyCodeLine{2442   \textcolor{keywordflow}{if} (cs\%id\_land\_mask > 0)  \textcolor{keyword}{call }post\_data(cs\%id\_land\_mask, g\%mask2dT, cs\%diag)}
\DoxyCodeLine{2443 }
\DoxyCodeLine{2444   \textcolor{comment}{! Register 2-D energy density (summed over angles, freq, modes)}}
\DoxyCodeLine{2445   cs\%id\_tot\_En = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_En'}, diag\%axesT1, \&}
\DoxyCodeLine{2446                  time, \textcolor{stringliteral}{'Internal tide total energy density'}, \&}
\DoxyCodeLine{2447                  \textcolor{stringliteral}{'J m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2*us\%T\_to\_s)}
\DoxyCodeLine{2448   \textcolor{comment}{! Register 2-D drag scale used for quadratic bottom drag}}
\DoxyCodeLine{2449   cs\%id\_itide\_drag = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_drag'}, diag\%axesT1, \&}
\DoxyCodeLine{2450                  time, \textcolor{stringliteral}{'Interior and bottom drag internal tide decay timescale'}, \textcolor{stringliteral}{'s-1'}, conversion=us\%s\_to\_T)}
\DoxyCodeLine{2451   \textcolor{comment}{!Register 2-D energy input into internal tides}}
\DoxyCodeLine{2452   cs\%id\_TKE\_itidal\_input = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'TKE\_itidal\_input'}, diag\%axesT1, \&}
\DoxyCodeLine{2453                  time, \textcolor{stringliteral}{'Conversion from barotropic to baroclinic tide, '}//\&}
\DoxyCodeLine{2454                  \textcolor{stringliteral}{'a fraction of which goes into rays'}, \&}
\DoxyCodeLine{2455                  \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2456   \textcolor{comment}{! Register 2-D energy losses (summed over angles, freq, modes)}}
\DoxyCodeLine{2457   cs\%id\_tot\_leak\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_leak\_loss'}, diag\%axesT1, \&}
\DoxyCodeLine{2458                 time, \textcolor{stringliteral}{'Internal tide energy loss to background drag'}, \&}
\DoxyCodeLine{2459                 \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2460   cs\%id\_tot\_quad\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_quad\_loss'}, diag\%axesT1, \&}
\DoxyCodeLine{2461                 time, \textcolor{stringliteral}{'Internal tide energy loss to bottom drag'}, \&}
\DoxyCodeLine{2462                 \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2463   cs\%id\_tot\_itidal\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_itidal\_loss'}, diag\%axesT1, \&}
\DoxyCodeLine{2464                 time, \textcolor{stringliteral}{'Internal tide energy loss to wave drag'}, \&}
\DoxyCodeLine{2465                 \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2466   cs\%id\_tot\_Froude\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_Froude\_loss'}, diag\%axesT1, \&}
\DoxyCodeLine{2467                 time, \textcolor{stringliteral}{'Internal tide energy loss to wave breaking'}, \&}
\DoxyCodeLine{2468                 \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2469   cs\%id\_tot\_allprocesses\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_allprocesses\_loss'}, diag\%axesT1, \&}
\DoxyCodeLine{2470                 time, \textcolor{stringliteral}{'Internal tide energy loss summed over all processes'}, \&}
\DoxyCodeLine{2471                 \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2472 }
\DoxyCodeLine{2473   \textcolor{keyword}{allocate}(cs\%id\_En\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_En\_mode(:,:) = -1}
\DoxyCodeLine{2474   \textcolor{keyword}{allocate}(cs\%id\_En\_ang\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_En\_ang\_mode(:,:) = -1}
\DoxyCodeLine{2475   \textcolor{keyword}{allocate}(cs\%id\_itidal\_loss\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_itidal\_loss\_mode(:,:) = -1}
\DoxyCodeLine{2476   \textcolor{keyword}{allocate}(cs\%id\_allprocesses\_loss\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_allprocesses\_loss\_mode(:,:) = -1}
\DoxyCodeLine{2477   \textcolor{keyword}{allocate}(cs\%id\_itidal\_loss\_ang\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_itidal\_loss\_ang\_mode(:,:) = -1}
\DoxyCodeLine{2478   \textcolor{keyword}{allocate}(cs\%id\_Ub\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_Ub\_mode(:,:) = -1}
\DoxyCodeLine{2479   \textcolor{keyword}{allocate}(cs\%id\_cp\_mode(cs\%nFreq,cs\%nMode)) ; cs\%id\_cp\_mode(:,:) = -1}
\DoxyCodeLine{2480 }
\DoxyCodeLine{2481   \textcolor{keyword}{allocate}(angles(cs\%NAngle)) ; angles(:) = 0.0}
\DoxyCodeLine{2482   angle\_size = (8.0*atan(1.0)) / (real(num\_angle))}
\DoxyCodeLine{2483   \textcolor{keywordflow}{do} a=1,num\_angle ; angles(a) = (real(a) - 1) * angle\_size ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2484 }
\DoxyCodeLine{2485   id\_ang = diag\_axis\_init(\textcolor{stringliteral}{"angle"}, angles, \textcolor{stringliteral}{"Radians"}, \textcolor{stringliteral}{"N"}, \textcolor{stringliteral}{"Angular Orienation of Fluxes"})}
\DoxyCodeLine{2486   \textcolor{keyword}{call }define\_axes\_group(diag, (/ diag\%axesT1\%handles(1), diag\%axesT1\%handles(2), id\_ang /), axes\_ang)}
\DoxyCodeLine{2487 }
\DoxyCodeLine{2488   \textcolor{keywordflow}{do} fr=1,cs\%nFreq ; \textcolor{keyword}{write}(freq\_name(fr), \textcolor{stringliteral}{'("freq",i1)'}) fr ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2489   \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq}
\DoxyCodeLine{2490     \textcolor{comment}{! Register 2-D energy density (summed over angles) for each freq and mode}}
\DoxyCodeLine{2491     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_En\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2492     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy density in frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2493     cs\%id\_En\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2494                  diag\%axesT1, time, var\_descript, \textcolor{stringliteral}{'J m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2*us\%T\_to\_s)}
\DoxyCodeLine{2495     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2496 }
\DoxyCodeLine{2497     \textcolor{comment}{! Register 3-D (i,j,a) energy density for each freq and mode}}
\DoxyCodeLine{2498     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_En\_ang\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2499     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide angular energy density in frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2500     cs\%id\_En\_ang\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2501                  axes\_ang, time, var\_descript, \textcolor{stringliteral}{'J m-2 band-1'}, conversion=us\%RZ3\_T3\_to\_W\_m2*us\%T\_to\_s)}
\DoxyCodeLine{2502     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2503 }
\DoxyCodeLine{2504     \textcolor{comment}{! Register 2-D energy loss (summed over angles) for each freq and mode}}
\DoxyCodeLine{2505     \textcolor{comment}{! wave-drag only}}
\DoxyCodeLine{2506     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_wavedrag\_loss\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2507     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy loss due to wave-drag from frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2508     cs\%id\_itidal\_loss\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2509                  diag\%axesT1, time, var\_descript, \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2510     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2511     \textcolor{comment}{! all loss processes}}
\DoxyCodeLine{2512     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_allprocesses\_loss\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2513     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy loss due to all processes from frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2514     cs\%id\_allprocesses\_loss\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2515                  diag\%axesT1, time, var\_descript, \textcolor{stringliteral}{'W m-2'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2516     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2517 }
\DoxyCodeLine{2518     \textcolor{comment}{! Register 3-D (i,j,a) energy loss for each freq and mode}}
\DoxyCodeLine{2519     \textcolor{comment}{! wave-drag only}}
\DoxyCodeLine{2520     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_wavedrag\_loss\_ang\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2521     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy loss due to wave-drag from frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2522     cs\%id\_itidal\_loss\_ang\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2523                  axes\_ang, time, var\_descript, \textcolor{stringliteral}{'W m-2 band-1'}, conversion=us\%RZ3\_T3\_to\_W\_m2)}
\DoxyCodeLine{2524     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2525 }
\DoxyCodeLine{2526     \textcolor{comment}{! Register 2-D period-averaged near-bottom horizonal velocity for each freq and mode}}
\DoxyCodeLine{2527     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_Ub\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2528     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Near-bottom horizonal velocity for frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2529     cs\%id\_Ub\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2530                  diag\%axesT1, time, var\_descript, \textcolor{stringliteral}{'m s-1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2531     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2532 }
\DoxyCodeLine{2533     \textcolor{comment}{! Register 2-D horizonal phase velocity for each freq and mode}}
\DoxyCodeLine{2534     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_cp\_freq",i1,"\_mode",i1)'}) fr, m}
\DoxyCodeLine{2535     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Horizonal phase velocity for frequency ",i1," mode ",i1)'}) fr, m}
\DoxyCodeLine{2536     cs\%id\_cp\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, \&}
\DoxyCodeLine{2537                  diag\%axesT1, time, var\_descript, \textcolor{stringliteral}{'m s-1'}, conversion=us\%L\_T\_to\_m\_s)}
\DoxyCodeLine{2538     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)}
\DoxyCodeLine{2539 }
\DoxyCodeLine{2540 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2541 }
\DoxyCodeLine{2542   \textcolor{comment}{! Initialize wave\_structure (not sure if this should be here - BDM)}}
\DoxyCodeLine{2543   \textcolor{keyword}{call }wave\_structure\_init(time, g, param\_file, diag, cs\%wave\_structure\_CSp)}
\DoxyCodeLine{2544 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a73ad407c5ea74fc20e58810937d2addf}\label{namespacemom__internal__tides_a73ad407c5ea74fc20e58810937d2addf}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!itidal\_lowmode\_loss@{itidal\_lowmode\_loss}}
\index{itidal\_lowmode\_loss@{itidal\_lowmode\_loss}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{itidal\_lowmode\_loss()}{itidal\_lowmode\_loss()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::itidal\+\_\+lowmode\+\_\+loss (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{Nb,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nfreq,cs\%nmode), intent(inout)}]{Ub,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nangle,cs\%nfreq,cs\%nmode), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{T\+K\+E\+\_\+loss\+\_\+fixed,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nangle,cs\%nfreq,cs\%nmode), intent(out)}]{T\+K\+E\+\_\+loss,  }\item[{real, intent(in)}]{dt,  }\item[{logical, intent(in), optional}]{full\+\_\+halos }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the energy lost from the propagating internal tide due to scattering over small-\/scale roughness along the lines of Jayne \& St. Laurent (2001). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em nb} & Near-\/bottom stratification \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em ub} & R\+MS (over one period) near-\/bottom horizontal \\
\hline
\mbox{\texttt{ in}}  & {\em tke\+\_\+loss\+\_\+fixed} & Fixed part of energy loss \mbox{[}R L-\/2 Z3 $\sim$$>$ kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & Energy density of the internal waves \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em tke\+\_\+loss} & Energy loss rate \mbox{[}R Z3 T-\/3 $\sim$$>$ W m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em full\+\_\+halos} & If true, do the calculation over the entirecomputational domain. \\
\hline
\end{DoxyParams}


Definition at line 636 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{636   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{637   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{638   \textcolor{keywordtype}{type}(int\_tide\_CS),         \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a}}
\DoxyCodeLine{639 \textcolor{comment}{                                                 !! previous call to int\_tide\_init.}}
\DoxyCodeLine{640 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)}, \&}
\DoxyCodeLine{641                              \textcolor{keywordtype}{intent(in)}    :: Nb\textcolor{comment}{ !< Near-bottom stratification [T-1 ~> s-1].}}
\DoxyCodeLine{642 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,CS\%nFreq,CS\%nMode)}, \&}
\DoxyCodeLine{643                              \textcolor{keywordtype}{intent(inout)} :: Ub\textcolor{comment}{ !< RMS (over one period) near-bottom horizontal}}
\DoxyCodeLine{644 \textcolor{comment}{                                                 !! mode velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{645 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)}, \&}
\DoxyCodeLine{646                              \textcolor{keywordtype}{intent(in)} :: TKE\_loss\_fixed\textcolor{comment}{ !< Fixed part of energy loss [R L-2 Z3 ~> kg m-2]}}
\DoxyCodeLine{647 \textcolor{comment}{                                                 !! (rho*kappa*h\string^2).}}
\DoxyCodeLine{648 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,CS\%NAngle,CS\%nFreq,CS\%nMode)}, \&}
\DoxyCodeLine{649                              \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{ !< Energy density of the internal waves [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{650 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,CS\%NAngle,CS\%nFreq,CS\%nMode)}, \&}
\DoxyCodeLine{651                              \textcolor{keywordtype}{intent(out)}   :: TKE\_loss\textcolor{comment}{    !< Energy loss rate [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{652 \textcolor{comment}{                                                 !! (q*rho*kappa*h\string^2*N*U\string^2).}}
\DoxyCodeLine{653 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{654   \textcolor{keywordtype}{logical},\textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: full\_halos\textcolor{comment}{  !< If true, do the calculation over the}}
\DoxyCodeLine{655 \textcolor{comment}{                                                 !! entirecomputational domain.}}
\DoxyCodeLine{656   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{657   \textcolor{keywordtype}{integer} :: j,i,m,fr,a, is, ie, js, je}
\DoxyCodeLine{658 \textcolor{keywordtype}{  real}    :: En\_tot          \textcolor{comment}{! energy for a given mode, frequency, and point summed over angles [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{659 \textcolor{keywordtype}{  real}    :: TKE\_loss\_tot    \textcolor{comment}{! dissipation for a given mode, frequency, and point summed over angles [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{660 \textcolor{keywordtype}{  real}    :: TKE\_sum\_check   \textcolor{comment}{! temporary for check summing}}
\DoxyCodeLine{661 \textcolor{keywordtype}{  real}    :: frac\_per\_sector \textcolor{comment}{! fraction of energy in each wedge}}
\DoxyCodeLine{662 \textcolor{keywordtype}{  real}    :: q\_itides        \textcolor{comment}{! fraction of energy actually lost to mixing (remainder, 1-q, is}}
\DoxyCodeLine{663                              \textcolor{comment}{! assumed to stay in propagating mode for now - BDM)}}
\DoxyCodeLine{664 \textcolor{keywordtype}{  real}    :: loss\_rate       \textcolor{comment}{! approximate loss rate for implicit calc [T-1 ~> s-1]}}
\DoxyCodeLine{665 \textcolor{keywordtype}{  real}    :: En\_negl         \textcolor{comment}{! negilibly small number to prevent division by zero}}
\DoxyCodeLine{666 }
\DoxyCodeLine{667   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{668 }
\DoxyCodeLine{669   q\_itides = cs\%q\_itides}
\DoxyCodeLine{670   en\_negl = 1e-30*us\%kg\_m3\_to\_R*us\%m\_to\_Z**3*us\%T\_to\_s**2}
\DoxyCodeLine{671 }
\DoxyCodeLine{672   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(full\_halos)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (full\_halos) \textcolor{keywordflow}{then}}
\DoxyCodeLine{673     is = g\%isd ; ie = g\%ied ; js = g\%jsd ; je = g\%jed}
\DoxyCodeLine{674 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{675 }
\DoxyCodeLine{676   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq}
\DoxyCodeLine{677 }
\DoxyCodeLine{678     \textcolor{comment}{! Sum energy across angles}}
\DoxyCodeLine{679     en\_tot = 0.0}
\DoxyCodeLine{680     \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{681       en\_tot = en\_tot + en(i,j,a,fr,m)}
\DoxyCodeLine{682 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{683 }
\DoxyCodeLine{684     \textcolor{comment}{! Calculate TKE loss rate; units of [R Z3 T-3 ~> W m-2] here.}}
\DoxyCodeLine{685     tke\_loss\_tot = q\_itides * tke\_loss\_fixed(i,j) * nb(i,j) * ub(i,j,fr,m)**2}
\DoxyCodeLine{686 }
\DoxyCodeLine{687     \textcolor{comment}{! Update energy remaining (this is a pseudo implicit calc)}}
\DoxyCodeLine{688     \textcolor{comment}{! (E(t+1)-E(t))/dt = -TKE\_loss(E(t+1)/E(t)), which goes to zero as E(t+1) goes to zero}}
\DoxyCodeLine{689     \textcolor{keywordflow}{if} (en\_tot > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{690       \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{691         frac\_per\_sector = en(i,j,a,fr,m)/en\_tot}
\DoxyCodeLine{692         tke\_loss(i,j,a,fr,m) = frac\_per\_sector*tke\_loss\_tot           \textcolor{comment}{! Wm-2}}
\DoxyCodeLine{693         loss\_rate = tke\_loss(i,j,a,fr,m) / (en(i,j,a,fr,m) + en\_negl) \textcolor{comment}{! [T-1 ~> s-1]}}
\DoxyCodeLine{694         en(i,j,a,fr,m) = en(i,j,a,fr,m) / (1.0 + dt*loss\_rate)}
\DoxyCodeLine{695 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{696     \textcolor{keywordflow}{else}}
\DoxyCodeLine{697       \textcolor{comment}{! no loss if no energy}}
\DoxyCodeLine{698       tke\_loss(i,j,:,fr,m) = 0.0}
\DoxyCodeLine{699 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{700 }
\DoxyCodeLine{701     \textcolor{comment}{! Update energy remaining (this is the old explicit calc)}}
\DoxyCodeLine{702     \textcolor{comment}{!if (En\_tot > 0.0) then}}
\DoxyCodeLine{703     \textcolor{comment}{!  do a=1,CS\%nAngle}}
\DoxyCodeLine{704     \textcolor{comment}{!    frac\_per\_sector = En(i,j,a,fr,m)/En\_tot}}
\DoxyCodeLine{705     \textcolor{comment}{!    TKE\_loss(i,j,a,fr,m) = frac\_per\_sector*TKE\_loss\_tot}}
\DoxyCodeLine{706     \textcolor{comment}{!    if (TKE\_loss(i,j,a,fr,m)*dt <= En(i,j,a,fr,m))then}}
\DoxyCodeLine{707     \textcolor{comment}{!      En(i,j,a,fr,m) = En(i,j,a,fr,m) - TKE\_loss(i,j,a,fr,m)*dt}}
\DoxyCodeLine{708     \textcolor{comment}{!    else}}
\DoxyCodeLine{709     \textcolor{comment}{!      call MOM\_error(WARNING, "itidal\_lowmode\_loss: energy loss greater than avalable, "// \&}}
\DoxyCodeLine{710     \textcolor{comment}{!                        " setting En to zero.", all\_print=.true.)}}
\DoxyCodeLine{711     \textcolor{comment}{!      En(i,j,a,fr,m) = 0.0}}
\DoxyCodeLine{712     \textcolor{comment}{!    endif}}
\DoxyCodeLine{713     \textcolor{comment}{!  enddo}}
\DoxyCodeLine{714     \textcolor{comment}{!else}}
\DoxyCodeLine{715     \textcolor{comment}{!  ! no loss if no energy}}
\DoxyCodeLine{716     \textcolor{comment}{!  TKE\_loss(i,j,:,fr,m) = 0.0}}
\DoxyCodeLine{717     \textcolor{comment}{!endif}}
\DoxyCodeLine{718 }
\DoxyCodeLine{719 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{720 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_aa1b6ca95d1076457e3b7ca32942be143}\label{namespacemom__internal__tides_aa1b6ca95d1076457e3b7ca32942be143}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!merid\_flux\_en@{merid\_flux\_en}}
\index{merid\_flux\_en@{merid\_flux\_en}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{merid\_flux\_en()}{merid\_flux\_en()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::merid\+\_\+flux\+\_\+en (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{hL,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{hR,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(inout)}]{vh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{J,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the meridional mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Energy density used to calculate the fluxes \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em hl} & Left-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em hr} & Right-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em vh} & The meridional energy transport \mbox{[}R Z3 L2 T-\/3 $\sim$$>$ J s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em j} & The j-\/index to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & The start i-\/index range to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & The end i-\/index range to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
\end{DoxyParams}


Definition at line 1559 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1559   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{1560 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{  !< The meridional velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1561 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Energy density used to calculate the}}
\DoxyCodeLine{1562 \textcolor{comment}{                                                        !! fluxes [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1563 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: hL\textcolor{comment}{ !< Left- Energy densities in the}}
\DoxyCodeLine{1564 \textcolor{comment}{                                                        !! reconstruction [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1565 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: hR\textcolor{comment}{ !< Right- Energy densities in the}}
\DoxyCodeLine{1566 \textcolor{comment}{                                                        !! reconstruction [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1567 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{ !< The meridional energy transport [R Z3 L2 T-3 ~> J s-1].}}
\DoxyCodeLine{1568 \textcolor{keywordtype}{  real},                             \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{1569   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1570   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: J\textcolor{comment}{  !< The j-index to work on.}}
\DoxyCodeLine{1571   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{ !< The start i-index range to work on.}}
\DoxyCodeLine{1572   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{ !< The end i-index range to work on.}}
\DoxyCodeLine{1573   \textcolor{keywordtype}{logical},                          \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{ !< If true, rescale the ratio of face}}
\DoxyCodeLine{1574 \textcolor{comment}{                                                        !! areas to the cell areas when estimating}}
\DoxyCodeLine{1575 \textcolor{comment}{                                                        !! the CFL number.}}
\DoxyCodeLine{1576   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1577 \textcolor{keywordtype}{  real} :: CFL \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim].}}
\DoxyCodeLine{1578 \textcolor{keywordtype}{  real} :: curv\_3 \textcolor{comment}{! A measure of the energy density curvature over a grid length [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{1579   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{1580 }
\DoxyCodeLine{1581   \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1582     \textcolor{keywordflow}{if} (v(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1583       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (v(i) * dt) * (g\%dx\_Cv(i,j) * g\%IareaT(i,j))}
\DoxyCodeLine{1584       \textcolor{keywordflow}{else} ; cfl = v(i) * dt * g\%IdyT(i,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1585       curv\_3 = hl(i,j) + hr(i,j) - 2.0*h(i,j)}
\DoxyCodeLine{1586       vh(i) = g\%dx\_Cv(i,j) * v(i) * ( hr(i,j) + cfl * \&}
\DoxyCodeLine{1587           (0.5*(hl(i,j) - hr(i,j)) + curv\_3*(cfl - 1.5)) )}
\DoxyCodeLine{1588     \textcolor{keywordflow}{elseif} (v(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1589       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-v(i) * dt) * (g\%dx\_Cv(i,j) * g\%IareaT(i,j+1))}
\DoxyCodeLine{1590       \textcolor{keywordflow}{else} ; cfl = -v(i) * dt * g\%IdyT(i,j+1) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1591       curv\_3 = hl(i,j+1) + hr(i,j+1) - 2.0*h(i,j+1)}
\DoxyCodeLine{1592       vh(i) = g\%dx\_Cv(i,j) * v(i) * ( hl(i,j+1) + cfl * \&}
\DoxyCodeLine{1593           (0.5*(hr(i,j+1)-hl(i,j+1)) + curv\_3*(cfl - 1.5)) )}
\DoxyCodeLine{1594     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1595       vh(i) = 0.0}
\DoxyCodeLine{1596 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1597 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_ae34593443ab6362445946e9d75528155}\label{namespacemom__internal__tides_ae34593443ab6362445946e9d75528155}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!ppm\_angular\_advect@{ppm\_angular\_advect}}
\index{ppm\_angular\_advect@{ppm\_angular\_advect}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{ppm\_angular\_advect()}{ppm\_angular\_advect()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+angular\+\_\+advect (\begin{DoxyParamCaption}\item[{real, dimension(1-\/halo\+\_\+ang\+:nangle+halo\+\_\+ang), intent(in)}]{En2d,  }\item[{real, dimension(1-\/halo\+\_\+ang\+:nangle+halo\+\_\+ang), intent(in)}]{C\+F\+L\+\_\+ang,  }\item[{real, dimension(0\+:nangle), intent(out)}]{Flux\+\_\+\+En,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{real, intent(in)}]{dt,  }\item[{integer, intent(in)}]{halo\+\_\+ang }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates the 1-\/d flux for advection in angular space using a monotonic piecewise parabolic scheme. This needs to be called from within i and j spatial loops. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em halo\+\_\+ang} & The halo size in angular space \\
\hline
\mbox{\texttt{ in}}  & {\em en2d} & The internal gravity wave energy density as a \\
\hline
\mbox{\texttt{ in}}  & {\em cfl\+\_\+ang} & The C\+FL number of the energy advection across angles \\
\hline
\mbox{\texttt{ out}}  & {\em flux\+\_\+en} & The time integrated internal wave energy flux across angles \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 876 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{876   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{  !< The number of wave orientations in the}}
\DoxyCodeLine{877 \textcolor{comment}{                                                      !! discretized wave energy spectrum.}}
\DoxyCodeLine{878 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{      !< Time increment [T ~> s].}}
\DoxyCodeLine{879   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: halo\_ang\textcolor{comment}{ !< The halo size in angular space}}
\DoxyCodeLine{880 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1-halo\_ang:NAngle+halo\_ang)},   \&}
\DoxyCodeLine{881                              \textcolor{keywordtype}{intent(in)}    :: En2d\textcolor{comment}{    !< The internal gravity wave energy density as a}}
\DoxyCodeLine{882 \textcolor{comment}{                                                      !! function of angular resolution [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{883 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1-halo\_ang:NAngle+halo\_ang)},   \&}
\DoxyCodeLine{884                              \textcolor{keywordtype}{intent(in)}    :: CFL\_ang\textcolor{comment}{ !< The CFL number of the energy advection across angles}}
\DoxyCodeLine{885 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(0:NAngle)}, \textcolor{keywordtype}{intent(out)}   :: Flux\_En\textcolor{comment}{ !< The time integrated internal wave energy flux}}
\DoxyCodeLine{886 \textcolor{comment}{                                                      !! across angles  [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{887   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{888 \textcolor{keywordtype}{  real} :: flux}
\DoxyCodeLine{889 \textcolor{keywordtype}{  real} :: u\_ang        \textcolor{comment}{! Angular propagation speed [Rad T-1 ~> Rad s-1]}}
\DoxyCodeLine{890 \textcolor{keywordtype}{  real} :: Angle\_size   \textcolor{comment}{! The size of each orientation wedge in radians [Rad]}}
\DoxyCodeLine{891 \textcolor{keywordtype}{  real} :: I\_Angle\_size \textcolor{comment}{! The inverse of the the orientation wedges [Rad-1]}}
\DoxyCodeLine{892 \textcolor{keywordtype}{  real} :: I\_dt         \textcolor{comment}{! The inverse of the timestep [T-1 ~> s-1]}}
\DoxyCodeLine{893 \textcolor{keywordtype}{  real} :: aR, aL       \textcolor{comment}{! Left and right edge estimates of energy density [R Z3 T-2 rad-1 ~> J m-2 rad-1]}}
\DoxyCodeLine{894 \textcolor{keywordtype}{  real} :: dMx, dMn}
\DoxyCodeLine{895 \textcolor{keywordtype}{  real} :: Ep, Ec, Em   \textcolor{comment}{! Mean angular energy density for three successive wedges in angular}}
\DoxyCodeLine{896                        \textcolor{comment}{! orientation [R Z3 T-2 rad-1 ~> J m-2 rad-1]}}
\DoxyCodeLine{897 \textcolor{keywordtype}{  real} :: dA, curv\_3   \textcolor{comment}{! Difference and curvature of energy density [R Z3 T-2 rad-1 ~> J m-2 rad-1]}}
\DoxyCodeLine{898 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1.0/6.0  \textcolor{comment}{! One sixth [nondim]}}
\DoxyCodeLine{899   \textcolor{keywordtype}{integer} :: a}
\DoxyCodeLine{900 }
\DoxyCodeLine{901   i\_dt = 1 / dt}
\DoxyCodeLine{902   angle\_size = (8.0*atan(1.0)) / (real(nangle))}
\DoxyCodeLine{903   i\_angle\_size = 1 / angle\_size}
\DoxyCodeLine{904   flux\_en(:) = 0}
\DoxyCodeLine{905 }
\DoxyCodeLine{906   \textcolor{keywordflow}{do} a=0,nangle}
\DoxyCodeLine{907     u\_ang = cfl\_ang(a)*angle\_size*i\_dt}
\DoxyCodeLine{908     \textcolor{keywordflow}{if} (u\_ang >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{909       \textcolor{comment}{! Implementation of PPM-H3}}
\DoxyCodeLine{910       \textcolor{comment}{! Convert wedge-integrated energy density into angular energy densities for three successive}}
\DoxyCodeLine{911       \textcolor{comment}{! wedges around the source wedge for this flux [R Z3 T-2 rad-1 ~> J m-2 rad-1].}}
\DoxyCodeLine{912       ep = en2d(a+1)*i\_angle\_size}
\DoxyCodeLine{913       ec = en2d(a)  *i\_angle\_size}
\DoxyCodeLine{914       em = en2d(a-1)*i\_angle\_size}
\DoxyCodeLine{915       \textcolor{comment}{! Calculate and bound edge values of energy density.}}
\DoxyCodeLine{916       al = ( 5.*ec + ( 2.*em - ep ) ) * onesixth \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{917       al = max( min(ec,em), al) ; al = min( max(ec,em), al) \textcolor{comment}{! Bound}}
\DoxyCodeLine{918       ar = ( 5.*ec + ( 2.*ep - em ) ) * onesixth \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{919       ar = max( min(ec,ep), ar) ; ar = min( max(ec,ep), ar) \textcolor{comment}{! Bound}}
\DoxyCodeLine{920       da = ar - al}
\DoxyCodeLine{921       \textcolor{keywordflow}{if} ((ep-ec)*(ec-em) <= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{922         al = ec ; ar = ec    \textcolor{comment}{! use PCM for local extremum}}
\DoxyCodeLine{923       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) > (da*da) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{924         al = 3.*ec - 2.*ar   \textcolor{comment}{! Flatten the profile to move the extremum to the left edge}}
\DoxyCodeLine{925       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) < - (da*da) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{926         ar = 3.*ec - 2.*al   \textcolor{comment}{! Flatten the profile to move the extremum to the right edge}}
\DoxyCodeLine{927 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{928       curv\_3 = (ar + al) - 2.0*ec \textcolor{comment}{! Curvature}}
\DoxyCodeLine{929       \textcolor{comment}{! Calculate angular flux rate [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{930       flux = u\_ang*( ar + cfl\_ang(a) * ( 0.5*(al - ar) + curv\_3 * (cfl\_ang(a) - 1.5) ) )}
\DoxyCodeLine{931       \textcolor{comment}{! Calculate amount of energy fluxed between wedges [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{932       flux\_en(a) = dt * flux}
\DoxyCodeLine{933       \textcolor{comment}{!Flux\_En(A) = (dt * I\_Angle\_size) * flux}}
\DoxyCodeLine{934     \textcolor{keywordflow}{else}}
\DoxyCodeLine{935       \textcolor{comment}{! Implementation of PPM-H3}}
\DoxyCodeLine{936       \textcolor{comment}{! Convert wedge-integrated energy density into angular energy densities for three successive}}
\DoxyCodeLine{937       \textcolor{comment}{! wedges around the source wedge for this flux [R Z3 T-2 rad-1 ~> J m-2 rad-1].}}
\DoxyCodeLine{938       ep = en2d(a+2)*i\_angle\_size}
\DoxyCodeLine{939       ec = en2d(a+1)*i\_angle\_size}
\DoxyCodeLine{940       em = en2d(a)  *i\_angle\_size}
\DoxyCodeLine{941       \textcolor{comment}{! Calculate and bound edge values of energy density.}}
\DoxyCodeLine{942       al = ( 5.*ec + ( 2.*em - ep ) ) * onesixth \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{943       al = max( min(ec,em), al) ; al = min( max(ec,em), al) \textcolor{comment}{! Bound}}
\DoxyCodeLine{944       ar = ( 5.*ec + ( 2.*ep - em ) ) * onesixth \textcolor{comment}{! H3 estimate}}
\DoxyCodeLine{945       ar = max( min(ec,ep), ar) ; ar = min( max(ec,ep), ar) \textcolor{comment}{! Bound}}
\DoxyCodeLine{946       da = ar - al}
\DoxyCodeLine{947       \textcolor{keywordflow}{if} ((ep-ec)*(ec-em) <= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{948         al = ec ; ar = ec    \textcolor{comment}{! use PCM for local extremum}}
\DoxyCodeLine{949       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) > (da*da) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{950         al = 3.*ec - 2.*ar   \textcolor{comment}{! Flatten the profile to move the extremum to the left edge}}
\DoxyCodeLine{951       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) < - (da*da) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{952         ar = 3.*ec - 2.*al   \textcolor{comment}{! Flatten the profile to move the extremum to the right edge}}
\DoxyCodeLine{953 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{954       curv\_3 = (ar + al) - 2.0*ec \textcolor{comment}{! Curvature}}
\DoxyCodeLine{955       \textcolor{comment}{! Calculate angular flux rate [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{956       \textcolor{comment}{! Note that CFL\_ang is negative here, so it looks odd compared with equivalent expressions.}}
\DoxyCodeLine{957       flux = u\_ang*( al - cfl\_ang(a) * ( 0.5*(ar - al) + curv\_3 * (-cfl\_ang(a) - 1.5) ) )}
\DoxyCodeLine{958       \textcolor{comment}{! Calculate amount of energy fluxed between wedges [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{959       flux\_en(a) = dt * flux}
\DoxyCodeLine{960       \textcolor{comment}{!Flux\_En(A) = (dt * I\_Angle\_size) * flux}}
\DoxyCodeLine{961 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{962 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a16dd5b071e0fc87eb04c32f602c08aa5}\label{namespacemom__internal__tides_a16dd5b071e0fc87eb04c32f602c08aa5}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!ppm\_limit\_pos@{ppm\_limit\_pos}}
\index{ppm\_limit\_pos@{ppm\_limit\_pos}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{ppm\_limit\_pos()}{ppm\_limit\_pos()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+limit\+\_\+pos (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{h\+\_\+R,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{iis,  }\item[{integer, intent(in)}]{iie,  }\item[{integer, intent(in)}]{jis,  }\item[{integer, intent(in)}]{jie }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Thickness of layer (2D). \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+l} & Left edge value (2D). \\
\hline
\mbox{\texttt{ in,out}}  & {\em h\+\_\+r} & Right edge value (2D). \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit. \\
\hline
\mbox{\texttt{ in}}  & {\em iis} & Start i-\/index for computations \\
\hline
\mbox{\texttt{ in}}  & {\em iie} & End i-\/index for computations \\
\hline
\mbox{\texttt{ in}}  & {\em jis} & Start j-\/index for computations \\
\hline
\mbox{\texttt{ in}}  & {\em jie} & End j-\/index for computations \\
\hline
\end{DoxyParams}


Definition at line 2022 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{2022   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}     :: G\textcolor{comment}{     !< The ocean's grid structure.}}
\DoxyCodeLine{2023 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}     :: h\_in\textcolor{comment}{  !< Thickness of layer (2D).}}
\DoxyCodeLine{2024 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)}  :: h\_L\textcolor{comment}{   !< Left edge value (2D).}}
\DoxyCodeLine{2025 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)}  :: h\_R\textcolor{comment}{   !< Right edge value (2D).}}
\DoxyCodeLine{2026 \textcolor{keywordtype}{  real},                             \textcolor{keywordtype}{intent(in)}     :: h\_min\textcolor{comment}{ !< The minimum thickness that can be}}
\DoxyCodeLine{2027 \textcolor{comment}{                                                            !! obtained by a concave parabolic fit.}}
\DoxyCodeLine{2028   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: iis\textcolor{comment}{   !< Start i-index for computations}}
\DoxyCodeLine{2029   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: iie\textcolor{comment}{   !< End i-index for computations}}
\DoxyCodeLine{2030   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: jis\textcolor{comment}{   !< Start j-index for computations}}
\DoxyCodeLine{2031   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: jie\textcolor{comment}{   !< End j-index for computations}}
\DoxyCodeLine{2032   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{2033 \textcolor{keywordtype}{  real}    :: curv, dh, scale}
\DoxyCodeLine{2034   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{2035   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{2036 }
\DoxyCodeLine{2037   \textcolor{keywordflow}{do} j=jis,jie ; \textcolor{keywordflow}{do} i=iis,iie}
\DoxyCodeLine{2038     \textcolor{comment}{! This limiter prevents undershooting minima within the domain with}}
\DoxyCodeLine{2039     \textcolor{comment}{! values less than h\_min.}}
\DoxyCodeLine{2040     curv = 3.0*(h\_l(i,j) + h\_r(i,j) - 2.0*h\_in(i,j))}
\DoxyCodeLine{2041     \textcolor{keywordflow}{if} (curv > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Only minima are limited.}}
\DoxyCodeLine{2042       dh = h\_r(i,j) - h\_l(i,j)}
\DoxyCodeLine{2043       \textcolor{keywordflow}{if} (abs(dh) < curv) \textcolor{keywordflow}{then} \textcolor{comment}{! The parabola's minimum is within the cell.}}
\DoxyCodeLine{2044         \textcolor{keywordflow}{if} (h\_in(i,j) <= h\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2045           h\_l(i,j) = h\_in(i,j) ; h\_r(i,j) = h\_in(i,j)}
\DoxyCodeLine{2046         \textcolor{keywordflow}{elseif} (12.0*curv*(h\_in(i,j) - h\_min) < (curv**2 + 3.0*dh**2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{2047           \textcolor{comment}{! The minimum value is h\_in - (curv\string^2 + 3*dh\string^2)/(12*curv), and must}}
\DoxyCodeLine{2048           \textcolor{comment}{! be limited in this case.  0 < scale < 1.}}
\DoxyCodeLine{2049           scale = 12.0*curv*(h\_in(i,j) - h\_min) / (curv**2 + 3.0*dh**2)}
\DoxyCodeLine{2050           h\_l(i,j) = h\_in(i,j) + scale*(h\_l(i,j) - h\_in(i,j))}
\DoxyCodeLine{2051           h\_r(i,j) = h\_in(i,j) + scale*(h\_r(i,j) - h\_in(i,j))}
\DoxyCodeLine{2052 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{2053 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2054 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{2055 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_afa863318cc960c0be08672731ce6f225}\label{namespacemom__internal__tides_afa863318cc960c0be08672731ce6f225}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!ppm\_reconstruction\_x@{ppm\_reconstruction\_x}}
\index{ppm\_reconstruction\_x@{ppm\_reconstruction\_x}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{ppm\_reconstruction\_x()}{ppm\_reconstruction\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+reconstruction\+\_\+x (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+l,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+r,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge values for P\+PM reconstruction in x-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Energy density in a sector (2D). \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+l} & Left edge value of reconstruction (2D). \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+r} & Right edge value of reconstruction (2D). \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active loop bounds. \\
\hline
\mbox{\texttt{ in}}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean energy densities as default edge values for a simple 2nd order scheme. \\
\hline
\end{DoxyParams}


Definition at line 1869 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1869   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{1870 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Energy density in a sector (2D).}}
\DoxyCodeLine{1871 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_l\textcolor{comment}{  !< Left edge value of reconstruction (2D).}}
\DoxyCodeLine{1872 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_r\textcolor{comment}{  !< Right edge value of reconstruction (2D).}}
\DoxyCodeLine{1873   \textcolor{keywordtype}{type}(loop\_bounds\_type),           \textcolor{keywordtype}{intent(in)}  :: LB\textcolor{comment}{   !< A structure with the active loop bounds.}}
\DoxyCodeLine{1874   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the arithmetic mean}}
\DoxyCodeLine{1875 \textcolor{comment}{                                                        !! energy densities as default edge values}}
\DoxyCodeLine{1876 \textcolor{comment}{                                                        !! for a simple 2nd order scheme.}}
\DoxyCodeLine{1877   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1878 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}}
\DoxyCodeLine{1879 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1./6.}
\DoxyCodeLine{1880 \textcolor{keywordtype}{  real} :: h\_ip1, h\_im1}
\DoxyCodeLine{1881 \textcolor{keywordtype}{  real} :: dMx, dMn}
\DoxyCodeLine{1882   \textcolor{keywordtype}{logical} :: use\_CW84, use\_2nd}
\DoxyCodeLine{1883   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{1884   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, stencil}
\DoxyCodeLine{1885 }
\DoxyCodeLine{1886   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd}
\DoxyCodeLine{1887   isl = lb\%ish-1 ; iel = lb\%ieh+1 ; jsl = lb\%jsh ; jel = lb\%jeh}
\DoxyCodeLine{1888 }
\DoxyCodeLine{1889   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}}
\DoxyCodeLine{1890   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1}
\DoxyCodeLine{1891 }
\DoxyCodeLine{1892   \textcolor{keywordflow}{if} ((isl-stencil < g\%isd) .or. (iel+stencil > g\%ied)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1893     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_x called with a ", \&}}
\DoxyCodeLine{1894 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "x-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{1895                stencil + max(g\%isd-isl,iel-g\%ied)}
\DoxyCodeLine{1896     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{1897 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1898   \textcolor{keywordflow}{if} ((jsl < g\%jsd) .or. (jel > g\%jed)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1899     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_x called with a ", \&}}
\DoxyCodeLine{1900 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "y-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{1901                max(g\%jsd-jsl,jel-g\%jed)}
\DoxyCodeLine{1902     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{1903 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1904 }
\DoxyCodeLine{1905   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1906     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{1907       h\_im1 = g\%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g\%mask2dT(i-1,j)) * h\_in(i,j)}
\DoxyCodeLine{1908       h\_ip1 = g\%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g\%mask2dT(i+1,j)) * h\_in(i,j)}
\DoxyCodeLine{1909       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) )}
\DoxyCodeLine{1910       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) )}
\DoxyCodeLine{1911 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1912   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1913     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl-1,iel+1}
\DoxyCodeLine{1914       \textcolor{keywordflow}{if} ((g\%mask2dT(i-1,j) * g\%mask2dT(i,j) * g\%mask2dT(i+1,j)) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1915         slp(i,j) = 0.0}
\DoxyCodeLine{1916       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1917         \textcolor{comment}{! This uses a simple 2nd order slope.}}
\DoxyCodeLine{1918         slp(i,j) = 0.5 * (h\_in(i+1,j) - h\_in(i-1,j))}
\DoxyCodeLine{1919         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{1920         dmx = max(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j)) - h\_in(i,j)}
\DoxyCodeLine{1921         dmn = h\_in(i,j) - min(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j))}
\DoxyCodeLine{1922         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))}
\DoxyCodeLine{1923                 \textcolor{comment}{! * (G\%mask2dT(i-1,j) * G\%mask2dT(i,j) * G\%mask2dT(i+1,j))}}
\DoxyCodeLine{1924 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1925 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1926 }
\DoxyCodeLine{1927     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{1928       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}}
\DoxyCodeLine{1929       \textcolor{comment}{! following sets of expressions are equivalent.}}
\DoxyCodeLine{1930     \textcolor{comment}{! h\_im1 = h\_in(i-1,j,k) ; if (G\%mask2dT(i-1,j) < 0.5) h\_im1 = h\_in(i,j)}}
\DoxyCodeLine{1931     \textcolor{comment}{! h\_ip1 = h\_in(i+1,j,k) ; if (G\%mask2dT(i+1,j) < 0.5) h\_ip1 = h\_in(i,j)}}
\DoxyCodeLine{1932       h\_im1 = g\%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g\%mask2dT(i-1,j)) * h\_in(i,j)}
\DoxyCodeLine{1933       h\_ip1 = g\%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g\%mask2dT(i+1,j)) * h\_in(i,j)}
\DoxyCodeLine{1934       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{1935       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) ) + onesixth*( slp(i-1,j) - slp(i,j) )}
\DoxyCodeLine{1936       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i+1,j) )}
\DoxyCodeLine{1937 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1938 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1939 }
\DoxyCodeLine{1940   \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, 0.0, g, isl, iel, jsl, jel)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a6c3dc6d74dfd6e5b13d5f710899be278}\label{namespacemom__internal__tides_a6c3dc6d74dfd6e5b13d5f710899be278}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!ppm\_reconstruction\_y@{ppm\_reconstruction\_y}}
\index{ppm\_reconstruction\_y@{ppm\_reconstruction\_y}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{ppm\_reconstruction\_y()}{ppm\_reconstruction\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+reconstruction\+\_\+y (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+l,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+r,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge valus for P\+PM reconstruction in y-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+in} & Energy density in a sector (2D). \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+l} & Left edge value of reconstruction (2D). \\
\hline
\mbox{\texttt{ out}}  & {\em h\+\_\+r} & Right edge value of reconstruction (2D). \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active loop bounds. \\
\hline
\mbox{\texttt{ in}}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean energy densities as default edge values for a simple 2nd order scheme. \\
\hline
\end{DoxyParams}


Definition at line 1945 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1945   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{1946 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Energy density in a sector (2D).}}
\DoxyCodeLine{1947 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_l\textcolor{comment}{  !< Left edge value of reconstruction (2D).}}
\DoxyCodeLine{1948 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_r\textcolor{comment}{  !< Right edge value of reconstruction (2D).}}
\DoxyCodeLine{1949   \textcolor{keywordtype}{type}(loop\_bounds\_type),           \textcolor{keywordtype}{intent(in)}  :: LB\textcolor{comment}{   !< A structure with the active loop bounds.}}
\DoxyCodeLine{1950   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the arithmetic mean}}
\DoxyCodeLine{1951 \textcolor{comment}{                                                        !! energy densities as default edge values}}
\DoxyCodeLine{1952 \textcolor{comment}{                                                        !! for a simple 2nd order scheme.}}
\DoxyCodeLine{1953   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1954 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}}
\DoxyCodeLine{1955 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1./6.}
\DoxyCodeLine{1956 \textcolor{keywordtype}{  real} :: h\_jp1, h\_jm1}
\DoxyCodeLine{1957 \textcolor{keywordtype}{  real} :: dMx, dMn}
\DoxyCodeLine{1958   \textcolor{keywordtype}{logical} :: use\_2nd}
\DoxyCodeLine{1959   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{1960   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, stencil}
\DoxyCodeLine{1961 }
\DoxyCodeLine{1962   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd}
\DoxyCodeLine{1963   isl = lb\%ish ; iel = lb\%ieh ; jsl = lb\%jsh-1 ; jel = lb\%jeh+1}
\DoxyCodeLine{1964 }
\DoxyCodeLine{1965   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}}
\DoxyCodeLine{1966   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1}
\DoxyCodeLine{1967 }
\DoxyCodeLine{1968   \textcolor{keywordflow}{if} ((isl < g\%isd) .or. (iel > g\%ied)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1969     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_y called with a ", \&}}
\DoxyCodeLine{1970 \textcolor{stringliteral}{}\textcolor{stringliteral}{               \& "x-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{1971                max(g\%isd-isl,iel-g\%ied)}
\DoxyCodeLine{1972     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{1973 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1974   \textcolor{keywordflow}{if} ((jsl-stencil < g\%jsd) .or. (jel+stencil > g\%jed)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1975     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_y called with a ", \&}}
\DoxyCodeLine{1976 \textcolor{stringliteral}{}\textcolor{stringliteral}{                 \& "y-halo that needs to be increased by ",i2,".")'}) \&}
\DoxyCodeLine{1977                  stencil + max(g\%jsd-jsl,jel-g\%jed)}
\DoxyCodeLine{1978     \textcolor{keyword}{call }mom\_error(fatal,mesg)}
\DoxyCodeLine{1979 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1980 }
\DoxyCodeLine{1981   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1982     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{1983       h\_jm1 = g\%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g\%mask2dT(i,j-1)) * h\_in(i,j)}
\DoxyCodeLine{1984       h\_jp1 = g\%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g\%mask2dT(i,j+1)) * h\_in(i,j)}
\DoxyCodeLine{1985       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) )}
\DoxyCodeLine{1986       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) )}
\DoxyCodeLine{1987 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1988   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1989     \textcolor{keywordflow}{do} j=jsl-1,jel+1 ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{1990       \textcolor{keywordflow}{if} ((g\%mask2dT(i,j-1) * g\%mask2dT(i,j) * g\%mask2dT(i,j+1)) == 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1991         slp(i,j) = 0.0}
\DoxyCodeLine{1992       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1993         \textcolor{comment}{! This uses a simple 2nd order slope.}}
\DoxyCodeLine{1994         slp(i,j) = 0.5 * (h\_in(i,j+1) - h\_in(i,j-1))}
\DoxyCodeLine{1995         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{1996         dmx = max(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j)) - h\_in(i,j)}
\DoxyCodeLine{1997         dmn = h\_in(i,j) - min(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j))}
\DoxyCodeLine{1998         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))}
\DoxyCodeLine{1999                 \textcolor{comment}{! * (G\%mask2dT(i,j-1) * G\%mask2dT(i,j) * G\%mask2dT(i,j+1))}}
\DoxyCodeLine{2000 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{2001 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2002 }
\DoxyCodeLine{2003     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel}
\DoxyCodeLine{2004       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}}
\DoxyCodeLine{2005       \textcolor{comment}{! following sets of expressions are equivalent.}}
\DoxyCodeLine{2006       h\_jm1 = g\%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g\%mask2dT(i,j-1)) * h\_in(i,j)}
\DoxyCodeLine{2007       h\_jp1 = g\%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g\%mask2dT(i,j+1)) * h\_in(i,j)}
\DoxyCodeLine{2008       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}}
\DoxyCodeLine{2009       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) ) + onesixth*( slp(i,j-1) - slp(i,j) )}
\DoxyCodeLine{2010       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i,j+1) )}
\DoxyCodeLine{2011 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{2012 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{2013 }
\DoxyCodeLine{2014   \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, 0.0, g, isl, iel, jsl, jel)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_af70118539fe63af49c203de9bdfafe8a}\label{namespacemom__internal__tides_af70118539fe63af49c203de9bdfafe8a}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!propagate@{propagate}}
\index{propagate@{propagate}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{propagate()}{propagate()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{cn,  }\item[{real, intent(in)}]{freq,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{integer, intent(in)}]{N\+Angle }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Propagates internal waves at a single frequency. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The internal gravity wave energy density as a \\
\hline
\mbox{\texttt{ in}}  & {\em cn} & Baroclinic mode speed \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em freq} & Wave frequency \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time step \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 967 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{967   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{968   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{969 \textcolor{comment}{                                               !! discretized wave energy spectrum.}}
\DoxyCodeLine{970 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,NAngle)}, \&}
\DoxyCodeLine{971                          \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{   !< The internal gravity wave energy density as a}}
\DoxyCodeLine{972 \textcolor{comment}{                                               !! function of space and angular resolution,}}
\DoxyCodeLine{973 \textcolor{comment}{                                               !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{974 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)},        \&}
\DoxyCodeLine{975                          \textcolor{keywordtype}{intent(in)}    :: cn\textcolor{comment}{   !< Baroclinic mode speed [L T-1 ~> m s-1].}}
\DoxyCodeLine{976 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: freq\textcolor{comment}{ !< Wave frequency [T-1 ~> s-1].}}
\DoxyCodeLine{977 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time step [T ~> s].}}
\DoxyCodeLine{978   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{979   \textcolor{keywordtype}{type}(int\_tide\_CS),     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< The control structure returned by a}}
\DoxyCodeLine{980 \textcolor{comment}{                                               !! previous call to int\_tide\_init.}}
\DoxyCodeLine{981   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{982 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%JsdB:G\%JedB)} :: \&}
\DoxyCodeLine{983     speed  \textcolor{comment}{! The magnitude of the group velocity at the q points for corner adv [L T-1 ~> m s-1].}}
\DoxyCodeLine{984   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stencil = 2}
\DoxyCodeLine{985 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{986     speed\_x  \textcolor{comment}{! The magnitude of the group velocity at the Cu points [L T-1 ~> m s-1].}}
\DoxyCodeLine{987 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{988     speed\_y  \textcolor{comment}{! The magnitude of the group velocity at the Cv points [L T-1 ~> m s-1].}}
\DoxyCodeLine{989 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(0:NAngle)} :: \&}
\DoxyCodeLine{990     cos\_angle, sin\_angle}
\DoxyCodeLine{991 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(NAngle)} :: \&}
\DoxyCodeLine{992     Cgx\_av, Cgy\_av, dCgx, dCgy}
\DoxyCodeLine{993 \textcolor{keywordtype}{  real} :: f2   \textcolor{comment}{! The squared Coriolis parameter [T-2 ~> s-2].}}
\DoxyCodeLine{994 \textcolor{keywordtype}{  real} :: Angle\_size, I\_Angle\_size, angle}
\DoxyCodeLine{995 \textcolor{keywordtype}{  real} :: Ifreq \textcolor{comment}{! The inverse of the frequency [T ~> s]}}
\DoxyCodeLine{996 \textcolor{keywordtype}{  real} :: freq2 \textcolor{comment}{! The frequency squared [T-2 ~> s-2]}}
\DoxyCodeLine{997   \textcolor{keywordtype}{type}(loop\_bounds\_type) :: LB}
\DoxyCodeLine{998   \textcolor{keywordtype}{integer} :: is, ie, js, je, asd, aed, na}
\DoxyCodeLine{999   \textcolor{keywordtype}{integer} :: ish, ieh, jsh, jeh}
\DoxyCodeLine{1000   \textcolor{keywordtype}{integer} :: i, j, a}
\DoxyCodeLine{1001 }
\DoxyCodeLine{1002   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; na = \textcolor{keyword}{size}(en,3)}
\DoxyCodeLine{1003   asd = 1-stencil ; aed = nangle+stencil}
\DoxyCodeLine{1004 }
\DoxyCodeLine{1005   ifreq = 1.0 / freq}
\DoxyCodeLine{1006   freq2 = freq**2}
\DoxyCodeLine{1007 }
\DoxyCodeLine{1008   \textcolor{comment}{! Define loop bounds: Need extensions on j-loop so propagate\_y}}
\DoxyCodeLine{1009   \textcolor{comment}{! (done after propagate\_x) will have updated values in the halo}}
\DoxyCodeLine{1010   \textcolor{comment}{! for correct PPM reconstruction. Use if no teleporting and}}
\DoxyCodeLine{1011   \textcolor{comment}{! no pass\_var between propagate\_x and propagate\_y.}}
\DoxyCodeLine{1012   \textcolor{comment}{!jsh = js-3 ; jeh = je+3 ; ish = is ; ieh = ie}}
\DoxyCodeLine{1013 }
\DoxyCodeLine{1014   \textcolor{comment}{! Define loop bounds: Need 1-pt extensions on loops because}}
\DoxyCodeLine{1015   \textcolor{comment}{! teleporting eats up a halo point. Use if teleporting.}}
\DoxyCodeLine{1016   \textcolor{comment}{! Also requires pass\_var before propagate\_y.}}
\DoxyCodeLine{1017   jsh = js-1 ; jeh = je+1 ; ish = is-1 ; ieh = ie+1}
\DoxyCodeLine{1018 }
\DoxyCodeLine{1019   angle\_size = (8.0*atan(1.0)) / real(nangle)}
\DoxyCodeLine{1020   i\_angle\_size = 1.0 / angle\_size}
\DoxyCodeLine{1021 }
\DoxyCodeLine{1022   \textcolor{keywordflow}{if} (cs\%corner\_adv) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1023     \textcolor{comment}{! IMPLEMENT CORNER ADVECTION IN HORIZONTAL--------------------}}
\DoxyCodeLine{1024     \textcolor{comment}{! FIND AVERAGE GROUP VELOCITY (SPEED) AT CELL CORNERS}}
\DoxyCodeLine{1025     \textcolor{comment}{! NOTE: THIS HAS NOT BE ADAPTED FOR REFLECTION YET (BDM)!!}}
\DoxyCodeLine{1026     \textcolor{comment}{! Fix indexing here later}}
\DoxyCodeLine{1027     speed(:,:) = 0.0}
\DoxyCodeLine{1028     \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{1029       f2 = g\%CoriolisBu(i,j)**2}
\DoxyCodeLine{1030       speed(i,j) = 0.25*(cn(i,j) + cn(i+1,j) + cn(i+1,j+1) + cn(i,j+1)) * \&}
\DoxyCodeLine{1031                      sqrt(max(freq2 - f2, 0.0)) * ifreq}
\DoxyCodeLine{1032 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1033     \textcolor{keywordflow}{do} a=1,na}
\DoxyCodeLine{1034       \textcolor{comment}{! Apply the propagation WITH CORNER ADVECTION/FINITE VOLUME APPROACH.}}
\DoxyCodeLine{1035       lb\%jsh = js ; lb\%jeh = je ; lb\%ish = is ; lb\%ieh = ie}
\DoxyCodeLine{1036       \textcolor{keyword}{call }propagate\_corner\_spread(en(:,:,a), a, nangle, speed, dt, g, cs, lb)}
\DoxyCodeLine{1037 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! a-loop}}
\DoxyCodeLine{1038   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1039     \textcolor{comment}{! IMPLEMENT PPM ADVECTION IN HORIZONTAL-----------------------}}
\DoxyCodeLine{1040     \textcolor{comment}{! These could be in the control structure, as they do not vary.}}
\DoxyCodeLine{1041     \textcolor{keywordflow}{do} a=0,na}
\DoxyCodeLine{1042       \textcolor{comment}{! These are the angles at the cell edges...}}
\DoxyCodeLine{1043       angle = (real(a) - 0.5) * angle\_size}
\DoxyCodeLine{1044       cos\_angle(a) = cos(angle) ; sin\_angle(a) = sin(angle)}
\DoxyCodeLine{1045 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1046 }
\DoxyCodeLine{1047     \textcolor{keywordflow}{do} a=1,na}
\DoxyCodeLine{1048       cgx\_av(a) = (sin\_angle(a) - sin\_angle(a-1)) * i\_angle\_size}
\DoxyCodeLine{1049       cgy\_av(a) = -(cos\_angle(a) - cos\_angle(a-1)) * i\_angle\_size}
\DoxyCodeLine{1050       dcgx(a) = sqrt(0.5 + 0.5*(sin\_angle(a)*cos\_angle(a) - \&}
\DoxyCodeLine{1051                                 sin\_angle(a-1)*cos\_angle(a-1)) * i\_angle\_size - \&}
\DoxyCodeLine{1052                      cgx\_av(a)**2)}
\DoxyCodeLine{1053       dcgy(a) = sqrt(0.5 - 0.5*(sin\_angle(a)*cos\_angle(a) - \&}
\DoxyCodeLine{1054                                 sin\_angle(a-1)*cos\_angle(a-1)) * i\_angle\_size - \&}
\DoxyCodeLine{1055                      cgy\_av(a)**2)}
\DoxyCodeLine{1056 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1057 }
\DoxyCodeLine{1058     \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{1059       f2 = 0.5 * (g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i,j-1)**2)}
\DoxyCodeLine{1060       speed\_x(i,j) = 0.5*(cn(i,j) + cn(i+1,j)) * g\%mask2dCu(i,j) * \&}
\DoxyCodeLine{1061                      sqrt(max(freq2 - f2, 0.0)) * ifreq}
\DoxyCodeLine{1062 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1063     \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1064       f2 = 0.5 * (g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-1,j)**2)}
\DoxyCodeLine{1065       speed\_y(i,j) = 0.5*(cn(i,j) + cn(i,j+1)) * g\%mask2dCv(i,j) * \&}
\DoxyCodeLine{1066                      sqrt(max(freq2 - f2, 0.0)) * ifreq}
\DoxyCodeLine{1067 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1068 }
\DoxyCodeLine{1069     \textcolor{comment}{! Apply propagation in x-direction (reflection included)}}
\DoxyCodeLine{1070     lb\%jsh = jsh ; lb\%jeh = jeh ; lb\%ish = ish ; lb\%ieh = ieh}
\DoxyCodeLine{1071     \textcolor{keyword}{call }propagate\_x(en, speed\_x, cgx\_av, dcgx, dt, g, us, cs\%nAngle, cs, lb)}
\DoxyCodeLine{1072 }
\DoxyCodeLine{1073     \textcolor{comment}{! Check for energy conservation on computational domain (for debugging)}}
\DoxyCodeLine{1074     \textcolor{comment}{!call sum\_En(G, CS, En, 'post-propagate\_x')}}
\DoxyCodeLine{1075 }
\DoxyCodeLine{1076     \textcolor{comment}{! Update halos}}
\DoxyCodeLine{1077     \textcolor{keyword}{call }pass\_var(en, g\%domain)}
\DoxyCodeLine{1078 }
\DoxyCodeLine{1079     \textcolor{comment}{! Apply propagation in y-direction (reflection included)}}
\DoxyCodeLine{1080     \textcolor{comment}{! LB\%jsh = js ; LB\%jeh = je ; LB\%ish = is ; LB\%ieh = ie ! Use if no teleport}}
\DoxyCodeLine{1081     lb\%jsh = jsh ; lb\%jeh = jeh ; lb\%ish = ish ; lb\%ieh = ieh}
\DoxyCodeLine{1082     \textcolor{keyword}{call }propagate\_y(en, speed\_y, cgy\_av, dcgy, dt, g, us, cs\%nAngle, cs, lb)}
\DoxyCodeLine{1083 }
\DoxyCodeLine{1084     \textcolor{comment}{! Check for energy conservation on computational domain (for debugging)}}
\DoxyCodeLine{1085     \textcolor{comment}{!call sum\_En(G, CS, En, 'post-propagate\_y')}}
\DoxyCodeLine{1086 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1087 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a66c9354cfdcde3d06a2ebe8775572d23}\label{namespacemom__internal__tides_a66c9354cfdcde3d06a2ebe8775572d23}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!propagate\_corner\_spread@{propagate\_corner\_spread}}
\index{propagate\_corner\_spread@{propagate\_corner\_spread}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{propagate\_corner\_spread()}{propagate\_corner\_spread()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+corner\+\_\+spread (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(inout)}]{En,  }\item[{integer, intent(in)}]{energized\+\_\+wedge,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{real, dimension(g\%isdb\+:g\%iedb,g\%jsd\+:g\%jed), intent(in)}]{speed,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does first-\/order corner advection. It was written with the hopes of smoothing out the garden sprinkler effect, but is too numerically diffusive to be of much use as of yet. It is not yet compatible with reflection schemes (B\+DM). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The energy density integrated over an angular \\
\hline
\mbox{\texttt{ in}}  & {\em speed} & The magnitude of the group velocity at the cell \\
\hline
\mbox{\texttt{ in}}  & {\em energized\+\_\+wedge} & Index of current ray direction. \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
 & {\em cs} & The control structure returned by a previous call to continuity\+\_\+\+P\+P\+M\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1094 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1094   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< The ocean's grid structure.}}
\DoxyCodeLine{1095 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)},   \&}
\DoxyCodeLine{1096                           \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{    !< The energy density integrated over an angular}}
\DoxyCodeLine{1097 \textcolor{comment}{                                                 !! band [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1098 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%Jsd:G\%Jed)}, \&}
\DoxyCodeLine{1099                           \textcolor{keywordtype}{intent(in)}    :: speed\textcolor{comment}{ !< The magnitude of the group velocity at the cell}}
\DoxyCodeLine{1100 \textcolor{comment}{                                                 !! corner points [L T-1 ~> m s-1].}}
\DoxyCodeLine{1101   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: energized\_wedge\textcolor{comment}{ !< Index of current ray direction.}}
\DoxyCodeLine{1102   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{1103 \textcolor{comment}{                                                 !! discretized wave energy spectrum.}}
\DoxyCodeLine{1104 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{    !< Time increment [T ~> s].}}
\DoxyCodeLine{1105   \textcolor{keywordtype}{type}(int\_tide\_CS),      \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< The control structure returned by a previous}}
\DoxyCodeLine{1106 \textcolor{comment}{                                                 !! call to continuity\_PPM\_init.}}
\DoxyCodeLine{1107   \textcolor{keywordtype}{type}(loop\_bounds\_type), \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{    !< A structure with the active energy loop bounds.}}
\DoxyCodeLine{1108   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1109   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, m}
\DoxyCodeLine{1110 \textcolor{keywordtype}{  real} :: TwoPi, Angle\_size}
\DoxyCodeLine{1111 \textcolor{keywordtype}{  real} :: energized\_angle \textcolor{comment}{! angle through center of current wedge}}
\DoxyCodeLine{1112 \textcolor{keywordtype}{  real} :: theta \textcolor{comment}{! angle at edge of wedge}}
\DoxyCodeLine{1113 \textcolor{keywordtype}{  real} :: Nsubrays     \textcolor{comment}{! number of sub-rays for averaging}}
\DoxyCodeLine{1114                        \textcolor{comment}{! count includes the two rays that bound the current wedge,}}
\DoxyCodeLine{1115                        \textcolor{comment}{! i.e. those at -dtheta/2 and +dtheta/2 from energized angle}}
\DoxyCodeLine{1116 \textcolor{keywordtype}{  real} :: I\_Nsubwedges \textcolor{comment}{! inverse of number of sub-wedges}}
\DoxyCodeLine{1117 \textcolor{keywordtype}{  real} :: cos\_thetaDT, sin\_thetaDT \textcolor{comment}{! cos(theta)*dt, sin(theta)*dt}}
\DoxyCodeLine{1118 \textcolor{keywordtype}{  real} :: xNE,xNW,xSW,xSE,yNE,yNW,ySW,ySE \textcolor{comment}{! corner point coordinates of advected fluid parcel}}
\DoxyCodeLine{1119 \textcolor{keywordtype}{  real} :: CFL\_xNE,CFL\_xNW,CFL\_xSW,CFL\_xSE,CFL\_yNE,CFL\_yNW,CFL\_ySW,CFL\_ySE,CFL\_max}
\DoxyCodeLine{1120 \textcolor{keywordtype}{  real} :: xN,xS,xE,xW,yN,yS,yE,yW \textcolor{comment}{! intersection point coordinates of parcel edges and grid}}
\DoxyCodeLine{1121 \textcolor{keywordtype}{  real} :: xCrn,yCrn \textcolor{comment}{! grid point contained within advected fluid parcel}}
\DoxyCodeLine{1122 \textcolor{keywordtype}{  real} :: xg,yg \textcolor{comment}{! grid point of interest}}
\DoxyCodeLine{1123 \textcolor{keywordtype}{  real} :: slopeN,slopeW,slopeS,slopeE, bN,bW,bS,bE \textcolor{comment}{! parameters defining parcel sides}}
\DoxyCodeLine{1124 \textcolor{keywordtype}{  real} :: aNE,aN,aNW,aW,aSW,aS,aSE,aE,aC \textcolor{comment}{! sub-areas of advected parcel}}
\DoxyCodeLine{1125 \textcolor{keywordtype}{  real} :: a\_total \textcolor{comment}{! total area of advected parcel}}
\DoxyCodeLine{1126 \textcolor{keywordtype}{  real} :: a1,a2,a3,a4 \textcolor{comment}{! areas used in calculating polygon areas (sub-areas) of advected parcel}}
\DoxyCodeLine{1127 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%Jsd:G\%Jed)} :: x,y \textcolor{comment}{! coordinates of cell corners}}
\DoxyCodeLine{1128 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%Jsd:G\%Jed)} :: Idx,Idy \textcolor{comment}{! inverse of dx,dy at cell corners}}
\DoxyCodeLine{1129 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%Jsd:G\%Jed)} :: dx,dy \textcolor{comment}{! dx,dy at cell corners}}
\DoxyCodeLine{1130 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2)} :: E\_new \textcolor{comment}{! Energy in cell after advection for subray [R Z3 T-2 ~> J m-2]; set size}}
\DoxyCodeLine{1131                               \textcolor{comment}{! here to define Nsubrays - this should be made an input option later!}}
\DoxyCodeLine{1132 }
\DoxyCodeLine{1133   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh}
\DoxyCodeLine{1134   twopi = (8.0*atan(1.0))}
\DoxyCodeLine{1135   nsubrays = real(\textcolor{keyword}{size}(e\_new))}
\DoxyCodeLine{1136   i\_nsubwedges = 1./(nsubrays - 1)}
\DoxyCodeLine{1137 }
\DoxyCodeLine{1138   angle\_size = twopi / real(nangle)}
\DoxyCodeLine{1139   energized\_angle = angle\_size * real(energized\_wedge - 1) \textcolor{comment}{! for a=1 aligned with x-axis}}
\DoxyCodeLine{1140   \textcolor{comment}{!energized\_angle = Angle\_size * real(energized\_wedge - 1) + 2.0*Angle\_size !}}
\DoxyCodeLine{1141   \textcolor{comment}{!energized\_angle = Angle\_size * real(energized\_wedge - 1) + 0.5*Angle\_size !}}
\DoxyCodeLine{1142   \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{1143     \textcolor{comment}{! This will only work for a Cartesian grid for which G\%geoLonBu is in the same units has dx.}}
\DoxyCodeLine{1144     \textcolor{comment}{! This needs to be extensively revised to work for a general grid.}}
\DoxyCodeLine{1145     x(i,j) = g\%US\%m\_to\_L*g\%geoLonBu(i,j)}
\DoxyCodeLine{1146     y(i,j) = g\%US\%m\_to\_L*g\%geoLatBu(i,j)}
\DoxyCodeLine{1147     idx(i,j) = g\%IdxBu(i,j) ; dx(i,j) = g\%dxBu(i,j)}
\DoxyCodeLine{1148     idy(i,j) = g\%IdyBu(i,j) ; dy(i,j) = g\%dyBu(i,j)}
\DoxyCodeLine{1149 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1150 }
\DoxyCodeLine{1151   \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1152     \textcolor{keywordflow}{do} m=1,int(nsubrays)}
\DoxyCodeLine{1153       theta = energized\_angle - 0.5*angle\_size + real(m - 1)*angle\_size*i\_nsubwedges}
\DoxyCodeLine{1154       \textcolor{keywordflow}{if} (theta < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1155         theta = theta + twopi}
\DoxyCodeLine{1156       \textcolor{keywordflow}{elseif} (theta > twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1157         theta = theta - twopi}
\DoxyCodeLine{1158 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1159       cos\_thetadt = cos(theta)*dt}
\DoxyCodeLine{1160       sin\_thetadt = sin(theta)*dt}
\DoxyCodeLine{1161 }
\DoxyCodeLine{1162       \textcolor{comment}{! corner point coordinates of advected fluid parcel ----------}}
\DoxyCodeLine{1163       xg = x(i,j); yg = y(i,j)}
\DoxyCodeLine{1164       xne = xg - speed(i,j)*cos\_thetadt}
\DoxyCodeLine{1165       yne = yg - speed(i,j)*sin\_thetadt}
\DoxyCodeLine{1166       cfl\_xne = (xg-xne)*idx(i,j)}
\DoxyCodeLine{1167       cfl\_yne = (yg-yne)*idy(i,j)}
\DoxyCodeLine{1168 }
\DoxyCodeLine{1169       xg = x(i-1,j); yg = y(i-1,j)}
\DoxyCodeLine{1170       xnw = xg - speed(i-1,j)*cos\_thetadt}
\DoxyCodeLine{1171       ynw = yg - speed(i-1,j)*sin\_thetadt}
\DoxyCodeLine{1172       cfl\_xnw = (xg-xnw)*idx(i-1,j)}
\DoxyCodeLine{1173       cfl\_ynw = (yg-ynw)*idy(i-1,j)}
\DoxyCodeLine{1174 }
\DoxyCodeLine{1175       xg = x(i-1,j-1); yg = y(i-1,j-1)}
\DoxyCodeLine{1176       xsw = xg - speed(i-1,j-1)*cos\_thetadt}
\DoxyCodeLine{1177       ysw = yg - speed(i-1,j-1)*sin\_thetadt}
\DoxyCodeLine{1178       cfl\_xsw = (xg-xsw)*idx(i-1,j-1)}
\DoxyCodeLine{1179       cfl\_ysw = (yg-ysw)*idy(i-1,j-1)}
\DoxyCodeLine{1180 }
\DoxyCodeLine{1181       xg = x(i,j-1); yg = y(i,j-1)}
\DoxyCodeLine{1182       xse = xg - speed(i,j-1)*cos\_thetadt}
\DoxyCodeLine{1183       yse = yg - speed(i,j-1)*sin\_thetadt}
\DoxyCodeLine{1184       cfl\_xse = (xg-xse)*idx(i,j-1)}
\DoxyCodeLine{1185       cfl\_yse = (yg-yse)*idy(i,j-1)}
\DoxyCodeLine{1186 }
\DoxyCodeLine{1187       cfl\_max = max(abs(cfl\_xne),abs(cfl\_xnw),abs(cfl\_xsw), \&}
\DoxyCodeLine{1188                     abs(cfl\_xse),abs(cfl\_yne),abs(cfl\_ynw), \&}
\DoxyCodeLine{1189                     abs(cfl\_ysw),abs(cfl\_yse))}
\DoxyCodeLine{1190       \textcolor{keywordflow}{if} (cfl\_max > 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1191         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_corner\_spread: CFL exceeds 1."}, .true.)}
\DoxyCodeLine{1192 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1193 }
\DoxyCodeLine{1194       \textcolor{comment}{! intersection point coordinates of parcel edges and cell edges ---}}
\DoxyCodeLine{1195       \textcolor{keywordflow}{if} (0.0 <= theta .and. theta < 0.25*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1196           xn = x(i-1,j-1)}
\DoxyCodeLine{1197           yw = y(i-1,j-1)}
\DoxyCodeLine{1198       \textcolor{keywordflow}{elseif} (0.25*twopi <= theta .and. theta < 0.5*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1199           xn = x(i,j-1)}
\DoxyCodeLine{1200           yw = y(i,j-1)}
\DoxyCodeLine{1201       \textcolor{keywordflow}{elseif} (0.5*twopi <= theta .and. theta < 0.75*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1202           xn = x(i,j)}
\DoxyCodeLine{1203           yw = y(i,j)}
\DoxyCodeLine{1204       \textcolor{keywordflow}{elseif} (0.75*twopi <= theta .and. theta <= 1.00*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1205           xn = x(i-1,j)}
\DoxyCodeLine{1206           yw = y(i-1,j)}
\DoxyCodeLine{1207 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1208       xs = xn}
\DoxyCodeLine{1209       ye = yw}
\DoxyCodeLine{1210 }
\DoxyCodeLine{1211       \textcolor{comment}{! north intersection}}
\DoxyCodeLine{1212       slopen = (yne - ynw)/(xne - xnw)}
\DoxyCodeLine{1213       bn = -slopen*xne + yne}
\DoxyCodeLine{1214       yn = slopen*xn + bn}
\DoxyCodeLine{1215       \textcolor{comment}{! west intersection}}
\DoxyCodeLine{1216       \textcolor{keywordflow}{if} (xnw == xsw) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1217         xw = xnw}
\DoxyCodeLine{1218       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1219         slopew = (ynw - ysw)/(xnw - xsw)}
\DoxyCodeLine{1220         bw = -slopew*xnw + ynw}
\DoxyCodeLine{1221         xw = (yw - bw)/slopew}
\DoxyCodeLine{1222 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1223       \textcolor{comment}{! south intersection}}
\DoxyCodeLine{1224       slopes = (ysw - yse)/(xsw - xse)}
\DoxyCodeLine{1225       bs = -slopes*xsw + ysw}
\DoxyCodeLine{1226       ys = slopes*xs + bs}
\DoxyCodeLine{1227       \textcolor{comment}{! east intersection}}
\DoxyCodeLine{1228       \textcolor{keywordflow}{if} (xne == xse) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1229         xe = xne}
\DoxyCodeLine{1230       \textcolor{keywordflow}{else}}
\DoxyCodeLine{1231         slopee = (yse - yne)/(xse - xne)}
\DoxyCodeLine{1232         be = -slopee*xse + yse}
\DoxyCodeLine{1233         xe = (ye - be)/slopee}
\DoxyCodeLine{1234 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1235 }
\DoxyCodeLine{1236       \textcolor{comment}{! areas --------------------------------------------}}
\DoxyCodeLine{1237       ane = 0.0; an = 0.0; anw = 0.0; \textcolor{comment}{! initialize areas}}
\DoxyCodeLine{1238       aw = 0.0; asw = 0.0; as = 0.0; \textcolor{comment}{! initialize areas}}
\DoxyCodeLine{1239       ase = 0.0; ae = 0.0; ac = 0.0; \textcolor{comment}{! initialize areas}}
\DoxyCodeLine{1240       \textcolor{keywordflow}{if} (0.0 <= theta .and. theta < 0.25*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1241           xcrn = x(i-1,j-1); ycrn = y(i-1,j-1)}
\DoxyCodeLine{1242           \textcolor{comment}{! west area}}
\DoxyCodeLine{1243           a1 = (yn - ycrn)*(0.5*(xn + xcrn))}
\DoxyCodeLine{1244           a2 = (ycrn - yw)*(0.5*(xcrn + xw))}
\DoxyCodeLine{1245           a3 = (yw - ynw)*(0.5*(xw + xnw))}
\DoxyCodeLine{1246           a4 = (ynw - yn)*(0.5*(xnw + xn))}
\DoxyCodeLine{1247           aw = a1 + a2 + a3 + a4}
\DoxyCodeLine{1248           \textcolor{comment}{! southwest area}}
\DoxyCodeLine{1249           a1 = (ycrn - ys)*(0.5*(xcrn + xs))}
\DoxyCodeLine{1250           a2 = (ys - ysw)*(0.5*(xs + xsw))}
\DoxyCodeLine{1251           a3 = (ysw - yw)*(0.5*(xsw + xw))}
\DoxyCodeLine{1252           a4 = (yw - ycrn)*(0.5*(xw + xcrn))}
\DoxyCodeLine{1253           asw = a1 + a2 + a3 + a4}
\DoxyCodeLine{1254           \textcolor{comment}{! south area}}
\DoxyCodeLine{1255           a1 = (ye - yse)*(0.5*(xe + xse))}
\DoxyCodeLine{1256           a2 = (yse - ys)*(0.5*(xse + xs))}
\DoxyCodeLine{1257           a3 = (ys - ycrn)*(0.5*(xs + xcrn))}
\DoxyCodeLine{1258           a4 = (ycrn - ye)*(0.5*(xcrn + xe))}
\DoxyCodeLine{1259           as = a1 + a2 + a3 + a4}
\DoxyCodeLine{1260           \textcolor{comment}{! area within cell}}
\DoxyCodeLine{1261           a1 = (yne - ye)*(0.5*(xne + xe))}
\DoxyCodeLine{1262           a2 = (ye - ycrn)*(0.5*(xe + xcrn))}
\DoxyCodeLine{1263           a3 = (ycrn - yn)*(0.5*(xcrn + xn))}
\DoxyCodeLine{1264           a4 = (yn - yne)*(0.5*(xn + xne))}
\DoxyCodeLine{1265           ac = a1 + a2 + a3 + a4}
\DoxyCodeLine{1266       \textcolor{keywordflow}{elseif} (0.25*twopi <= theta .and. theta < 0.5*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1267           xcrn = x(i,j-1); ycrn = y(i,j-1)}
\DoxyCodeLine{1268           \textcolor{comment}{! south area}}
\DoxyCodeLine{1269           a1 = (ycrn - ys)*(0.5*(xcrn + xs))}
\DoxyCodeLine{1270           a2 = (ys - ysw)*(0.5*(xs + xsw))}
\DoxyCodeLine{1271           a3 = (ysw - yw)*(0.5*(xsw + xw))}
\DoxyCodeLine{1272           a4 = (yw - ycrn)*(0.5*(xw + xcrn))}
\DoxyCodeLine{1273           as = a1 + a2 + a3 + a4}
\DoxyCodeLine{1274           \textcolor{comment}{! southeast area}}
\DoxyCodeLine{1275           a1 = (ye - yse)*(0.5*(xe + xse))}
\DoxyCodeLine{1276           a2 = (yse - ys)*(0.5*(xse + xs))}
\DoxyCodeLine{1277           a3 = (ys - ycrn)*(0.5*(xs + xcrn))}
\DoxyCodeLine{1278           a4 = (ycrn - ye)*(0.5*(xcrn + xe))}
\DoxyCodeLine{1279           ase = a1 + a2 + a3 + a4}
\DoxyCodeLine{1280           \textcolor{comment}{! east area}}
\DoxyCodeLine{1281           a1 = (yne - ye)*(0.5*(xne + xe))}
\DoxyCodeLine{1282           a2 = (ye - ycrn)*(0.5*(xe + xcrn))}
\DoxyCodeLine{1283           a3 = (ycrn - yn)*(0.5*(xcrn + xn))}
\DoxyCodeLine{1284           a4 = (yn - yne)*(0.5*(xn + xne))}
\DoxyCodeLine{1285           ae = a1 + a2 + a3 + a4}
\DoxyCodeLine{1286           \textcolor{comment}{! area within cell}}
\DoxyCodeLine{1287           a1 = (yn - ycrn)*(0.5*(xn + xcrn))}
\DoxyCodeLine{1288           a2 = (ycrn - yw)*(0.5*(xcrn + xw))}
\DoxyCodeLine{1289           a3 = (yw - ynw)*(0.5*(xw + xnw))}
\DoxyCodeLine{1290           a4 = (ynw - yn)*(0.5*(xnw + xn))}
\DoxyCodeLine{1291           ac = a1 + a2 + a3 + a4}
\DoxyCodeLine{1292       \textcolor{keywordflow}{elseif} (0.5*twopi <= theta .and. theta < 0.75*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1293           xcrn = x(i,j); ycrn = y(i,j)}
\DoxyCodeLine{1294           \textcolor{comment}{! east area}}
\DoxyCodeLine{1295           a1 = (ye - yse)*(0.5*(xe + xse))}
\DoxyCodeLine{1296           a2 = (yse - ys)*(0.5*(xse + xs))}
\DoxyCodeLine{1297           a3 = (ys - ycrn)*(0.5*(xs + xcrn))}
\DoxyCodeLine{1298           a4 = (ycrn - ye)*(0.5*(xcrn + xe))}
\DoxyCodeLine{1299           ae = a1 + a2 + a3 + a4}
\DoxyCodeLine{1300           \textcolor{comment}{! northeast area}}
\DoxyCodeLine{1301           a1 = (yne - ye)*(0.5*(xne + xe))}
\DoxyCodeLine{1302           a2 = (ye - ycrn)*(0.5*(xe + xcrn))}
\DoxyCodeLine{1303           a3 = (ycrn - yn)*(0.5*(xcrn + xn))}
\DoxyCodeLine{1304           a4 = (yn - yne)*(0.5*(xn + xne))}
\DoxyCodeLine{1305           ane = a1 + a2 + a3 + a4}
\DoxyCodeLine{1306           \textcolor{comment}{! north area}}
\DoxyCodeLine{1307           a1 = (yn - ycrn)*(0.5*(xn + xcrn))}
\DoxyCodeLine{1308           a2 = (ycrn - yw)*(0.5*(xcrn + xw))}
\DoxyCodeLine{1309           a3 = (yw - ynw)*(0.5*(xw + xnw))}
\DoxyCodeLine{1310           a4 = (ynw - yn)*(0.5*(xnw + xn))}
\DoxyCodeLine{1311           an = a1 + a2 + a3 + a4}
\DoxyCodeLine{1312           \textcolor{comment}{! area within cell}}
\DoxyCodeLine{1313           a1 = (ycrn - ys)*(0.5*(xcrn + xs))}
\DoxyCodeLine{1314           a2 = (ys - ysw)*(0.5*(xs + xsw))}
\DoxyCodeLine{1315           a3 = (ysw - yw)*(0.5*(xsw + xw))}
\DoxyCodeLine{1316           a4 = (yw - ycrn)*(0.5*(xw + xcrn))}
\DoxyCodeLine{1317           ac = a1 + a2 + a3 + a4}
\DoxyCodeLine{1318       \textcolor{keywordflow}{elseif} (0.75*twopi <= theta .and. theta <= 1.00*twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1319           xcrn = x(i-1,j); ycrn = y(i-1,j)}
\DoxyCodeLine{1320           \textcolor{comment}{! north area}}
\DoxyCodeLine{1321           a1 = (yne - ye)*(0.5*(xne + xe))}
\DoxyCodeLine{1322           a2 = (ye - ycrn)*(0.5*(xe + xcrn))}
\DoxyCodeLine{1323           a3 = (ycrn - yn)*(0.5*(xcrn + xn))}
\DoxyCodeLine{1324           a4 = (yn - yne)*(0.5*(xn + xne))}
\DoxyCodeLine{1325           an = a1 + a2 + a3 + a4}
\DoxyCodeLine{1326           \textcolor{comment}{! northwest area}}
\DoxyCodeLine{1327           a1 = (yn - ycrn)*(0.5*(xn + xcrn))}
\DoxyCodeLine{1328           a2 = (ycrn - yw)*(0.5*(xcrn + xw))}
\DoxyCodeLine{1329           a3 = (yw - ynw)*(0.5*(xw + xnw))}
\DoxyCodeLine{1330           a4 = (ynw - yn)*(0.5*(xnw + xn))}
\DoxyCodeLine{1331           anw = a1 + a2 + a3 + a4}
\DoxyCodeLine{1332           \textcolor{comment}{! west area}}
\DoxyCodeLine{1333           a1 = (ycrn - ys)*(0.5*(xcrn + xs))}
\DoxyCodeLine{1334           a2 = (ys - ysw)*(0.5*(xs + xsw))}
\DoxyCodeLine{1335           a3 = (ysw - yw)*(0.5*(xsw + xw))}
\DoxyCodeLine{1336           a4 = (yw - ycrn)*(0.5*(xw + xcrn))}
\DoxyCodeLine{1337           aw = a1 + a2 + a3 + a4}
\DoxyCodeLine{1338           \textcolor{comment}{! area within cell}}
\DoxyCodeLine{1339           a1 = (ye - yse)*(0.5*(xe + xse))}
\DoxyCodeLine{1340           a2 = (yse - ys)*(0.5*(xse + xs))}
\DoxyCodeLine{1341           a3 = (ys - ycrn)*(0.5*(xs + xcrn))}
\DoxyCodeLine{1342           a4 = (ycrn - ye)*(0.5*(xcrn + xe))}
\DoxyCodeLine{1343           ac = a1 + a2 + a3 + a4}
\DoxyCodeLine{1344 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{1345 }
\DoxyCodeLine{1346       \textcolor{comment}{! energy weighting ----------------------------------------}}
\DoxyCodeLine{1347       a\_total = ane + an + anw + aw + asw + as + ase + ae + ac}
\DoxyCodeLine{1348       e\_new(m) = (ane*en(i+1,j+1) + an*en(i,j+1) + anw*en(i-1,j+1) + \&}
\DoxyCodeLine{1349                   aw*en(i-1,j) + asw*en(i-1,j-1) + as*en(i,j-1) + \&}
\DoxyCodeLine{1350                   ase*en(i+1,j-1) + ae*en(i+1,j) + ac*en(i,j)) / (dx(i,j)*dy(i,j))}
\DoxyCodeLine{1351 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! m-loop}}
\DoxyCodeLine{1352     \textcolor{comment}{! update energy in cell}}
\DoxyCodeLine{1353     en(i,j) = sum(e\_new)/nsubrays}
\DoxyCodeLine{1354 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_aeeeea20ff7fe971846b7539d377f4389}\label{namespacemom__internal__tides_aeeeea20ff7fe971846b7539d377f4389}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!propagate\_int\_tide@{propagate\_int\_tide}}
\index{propagate\_int\_tide@{propagate\_int\_tide}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{propagate\_int\_tide()}{propagate\_int\_tide()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+int\+\_\+tide (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),cs\%nmode), intent(in)}]{cn,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{T\+K\+E\+\_\+itidal\+\_\+input,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{vel\+\_\+bt\+Tide,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{Nb,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Calls subroutines in this file that are needed to refract, propagate, and dissipate energy density of the internal tide. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Pointer to thermodynamic variables (needed for wave structure). \\
\hline
\mbox{\texttt{ in}}  & {\em tke\+\_\+itidal\+\_\+input} & The energy input to the internal waves \mbox{[}R Z3 T-\/3 $\sim$$>$ W m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em vel\+\_\+bttide} & Barotropic velocity read from file \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em nb} & Near-\/bottom buoyancy frequency \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Length of time over which to advance the internal tides \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em cn} & The internal wave speeds of each \\
\hline
\end{DoxyParams}


Definition at line 154 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{154   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{155   \textcolor{keywordtype}{type}(verticalGrid\_type),          \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< The ocean's vertical grid structure.}}
\DoxyCodeLine{156   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{157 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{158                                     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H ~> m or kg m-2]}}
\DoxyCodeLine{159   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),            \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Pointer to thermodynamic variables}}
\DoxyCodeLine{160 \textcolor{comment}{                                                        !! (needed for wave structure).}}
\DoxyCodeLine{161 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: TKE\_itidal\_input\textcolor{comment}{ !< The energy input to the}}
\DoxyCodeLine{162 \textcolor{comment}{                                                        !! internal waves [R Z3 T-3 ~> W m-2].}}
\DoxyCodeLine{163 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: vel\_btTide\textcolor{comment}{ !< Barotropic velocity read}}
\DoxyCodeLine{164 \textcolor{comment}{                                                        !! from file [L T-1 ~> m s-1].}}
\DoxyCodeLine{165 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: Nb\textcolor{comment}{ !< Near-bottom buoyancy frequency [T-1 ~> s-1].}}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real},                             \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Length of time over which to advance}}
\DoxyCodeLine{167 \textcolor{comment}{                                                        !! the internal tides [T ~> s].}}
\DoxyCodeLine{168   \textcolor{keywordtype}{type}(int\_tide\_CS),                \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a}}
\DoxyCodeLine{169 \textcolor{comment}{                                                        !! previous call to int\_tide\_init.}}
\DoxyCodeLine{170 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS\%nMode)}, \&}
\DoxyCodeLine{171                                     \textcolor{keywordtype}{intent(in)}    :: cn\textcolor{comment}{ !< The internal wave speeds of each}}
\DoxyCodeLine{172 \textcolor{comment}{                                                        !! mode [L T-1 ~> m s-1].}}
\DoxyCodeLine{173   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{174 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),2)} :: \&}
\DoxyCodeLine{175     test}
\DoxyCodeLine{176 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS\%nFreq,CS\%nMode)} :: \&}
\DoxyCodeLine{177     tot\_En\_mode, \& \textcolor{comment}{! energy summed over angles only [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{178     Ub, \&          \textcolor{comment}{! near-bottom horizontal velocity of wave (modal) [L T-1 ~> m s-1]}}
\DoxyCodeLine{179     Umax           \textcolor{comment}{! Maximum horizontal velocity of wave (modal) [L T-1 ~> m s-1]}}
\DoxyCodeLine{180 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{181     flux\_heat\_y, \&}
\DoxyCodeLine{182     flux\_prec\_y}
\DoxyCodeLine{183 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{184     tot\_En, \&      \textcolor{comment}{! energy summed over angles, modes, frequencies [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{185     tot\_leak\_loss, tot\_quad\_loss, tot\_itidal\_loss, tot\_Froude\_loss, tot\_allprocesses\_loss, \&}
\DoxyCodeLine{186                    \textcolor{comment}{! energy loss rates summed over angle, freq, and mode [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{187     drag\_scale, \&  \textcolor{comment}{! bottom drag scale [T-1 ~> s-1]}}
\DoxyCodeLine{188     itidal\_loss\_mode, allprocesses\_loss\_mode}
\DoxyCodeLine{189                    \textcolor{comment}{! energy loss rates for a given mode and frequency (summed over angles) [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{190 \textcolor{keywordtype}{  real} :: frac\_per\_sector, f2, Kmag2}
\DoxyCodeLine{191 \textcolor{keywordtype}{  real} :: I\_D\_here \textcolor{comment}{! The inverse of the local depth [Z-1 ~> m-1]}}
\DoxyCodeLine{192 \textcolor{keywordtype}{  real} :: I\_rho0  \textcolor{comment}{! The inverse fo the Boussinesq density [R-1 ~> m3 kg-1]}}
\DoxyCodeLine{193 \textcolor{keywordtype}{  real} :: freq2 \textcolor{comment}{! The frequency squared [T-2 ~> s-2]}}
\DoxyCodeLine{194 \textcolor{keywordtype}{  real} :: c\_phase \textcolor{comment}{! The phase speed [L T-1 ~> m s-1]}}
\DoxyCodeLine{195 \textcolor{keywordtype}{  real} :: loss\_rate  \textcolor{comment}{! An energy loss rate [T-1 ~> s-1]}}
\DoxyCodeLine{196 \textcolor{keywordtype}{  real} :: Fr2\_max}
\DoxyCodeLine{197 \textcolor{keywordtype}{  real} :: cn\_subRO        \textcolor{comment}{! A tiny wave speed to prevent division by zero [L T-1 ~> m s-1]}}
\DoxyCodeLine{198 \textcolor{keywordtype}{  real} :: En\_new, En\_check                           \textcolor{comment}{! Energies for debugging [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{199 \textcolor{keywordtype}{  real} :: En\_initial, Delta\_E\_check                  \textcolor{comment}{! Energies for debugging [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{200 \textcolor{keywordtype}{  real} :: TKE\_Froude\_loss\_check, TKE\_Froude\_loss\_tot \textcolor{comment}{! Energy losses for debugging [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{201   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{202   \textcolor{keywordtype}{integer} :: a, m, fr, i, j, is, ie, js, je, isd, ied, jsd, jed, nAngle, nzm}
\DoxyCodeLine{203   \textcolor{keywordtype}{integer} :: id\_g, jd\_g         \textcolor{comment}{! global (decomp-invar) indices (for debugging)}}
\DoxyCodeLine{204   \textcolor{keywordtype}{type}(group\_pass\_type), \textcolor{keywordtype}{save} :: pass\_test, pass\_En}
\DoxyCodeLine{205 }
\DoxyCodeLine{206   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{207   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{208   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed ; nangle = cs\%NAngle}
\DoxyCodeLine{209   i\_rho0 = 1.0 / gv\%Rho0}
\DoxyCodeLine{210   cn\_subro = 1e-100*us\%m\_s\_to\_L\_T  \textcolor{comment}{! The hard-coded value here might need to increase.}}
\DoxyCodeLine{211 }
\DoxyCodeLine{212   \textcolor{comment}{! Set the wave speeds for the modes, using cg(n) ~ cg(1)/n.**********************}}
\DoxyCodeLine{213   \textcolor{comment}{! This is wrong, of course, but it works reasonably in some cases.}}
\DoxyCodeLine{214   \textcolor{comment}{! Uncomment if wave\_speed is not used to calculate the true values (BDM).}}
\DoxyCodeLine{215   \textcolor{comment}{!do m=1,CS\%nMode ; do j=jsd,jed ; do i=isd,ied}}
\DoxyCodeLine{216   \textcolor{comment}{!  cn(i,j,m) = cn(i,j,1) / real(m)}}
\DoxyCodeLine{217   \textcolor{comment}{!enddo ; enddo ; enddo}}
\DoxyCodeLine{218 }
\DoxyCodeLine{219   \textcolor{comment}{! Add the forcing.***************************************************************}}
\DoxyCodeLine{220   \textcolor{keywordflow}{if} (cs\%energized\_angle <= 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{221     frac\_per\_sector = 1.0 / real(cs\%nAngle * cs\%nMode * cs\%nFreq)}
\DoxyCodeLine{222     \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{223       f2 = 0.25*((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-1,j-1)**2) + \&}
\DoxyCodeLine{224                  (g\%CoriolisBu(i-1,j)**2 + g\%CoriolisBu(i,j-1)**2))}
\DoxyCodeLine{225       \textcolor{keywordflow}{if} (cs\%frequency(fr)**2 > f2) \&}
\DoxyCodeLine{226         cs\%En(i,j,a,fr,m) = cs\%En(i,j,a,fr,m) + dt*frac\_per\_sector*(1.0-cs\%q\_itides) * \&}
\DoxyCodeLine{227                             tke\_itidal\_input(i,j)}
\DoxyCodeLine{228 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{229   \textcolor{keywordflow}{elseif} (cs\%energized\_angle <= cs\%nAngle) \textcolor{keywordflow}{then}}
\DoxyCodeLine{230     frac\_per\_sector = 1.0 / real(cs\%nMode * cs\%nFreq)}
\DoxyCodeLine{231     a = cs\%energized\_angle}
\DoxyCodeLine{232     \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{233       f2 = 0.25*((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-1,j-1)**2) + \&}
\DoxyCodeLine{234                  (g\%CoriolisBu(i-1,j)**2 + g\%CoriolisBu(i,j-1)**2))}
\DoxyCodeLine{235       \textcolor{keywordflow}{if} (cs\%frequency(fr)**2 > f2) \&}
\DoxyCodeLine{236         cs\%En(i,j,a,fr,m) = cs\%En(i,j,a,fr,m) + dt*frac\_per\_sector*(1.0-cs\%q\_itides) * \&}
\DoxyCodeLine{237                             tke\_itidal\_input(i,j)}
\DoxyCodeLine{238 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{239   \textcolor{keywordflow}{else}}
\DoxyCodeLine{240     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Internal tide energy is being put into a angular "}//\&}
\DoxyCodeLine{241                             \textcolor{stringliteral}{"band that does not exist."})}
\DoxyCodeLine{242 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{243 }
\DoxyCodeLine{244   \textcolor{comment}{! Pass a test vector to check for grid rotation in the halo updates.}}
\DoxyCodeLine{245   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; test(i,j,1) = 1.0 ; test(i,j,2) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{246   \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq}
\DoxyCodeLine{247     \textcolor{keyword}{call }create\_group\_pass(pass\_en, cs\%En(:,:,:,fr,m), g\%domain)}
\DoxyCodeLine{248 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{249   \textcolor{keyword}{call }create\_group\_pass(pass\_test, test(:,:,1), test(:,:,2), g\%domain, stagger=agrid)}
\DoxyCodeLine{250   \textcolor{keyword}{call }start\_group\_pass(pass\_test, g\%domain)}
\DoxyCodeLine{251 }
\DoxyCodeLine{252   \textcolor{comment}{! Apply half the refraction.}}
\DoxyCodeLine{253   \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq}
\DoxyCodeLine{254     \textcolor{keyword}{call }refract(cs\%En(:,:,:,fr,m), cn(:,:,m), cs\%frequency(fr), 0.5*dt, \&}
\DoxyCodeLine{255                  g, us, cs\%nAngle, cs\%use\_PPMang)}
\DoxyCodeLine{256 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{257 }
\DoxyCodeLine{258   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{259   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{260     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{261       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{262         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{263         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After first refraction: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{264                       \textcolor{stringliteral}{'En='},cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{265         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg))}
\DoxyCodeLine{266         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{267 \textcolor{comment}{!        call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{268 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{269 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{270 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{271 }
\DoxyCodeLine{272   \textcolor{keyword}{call }do\_group\_pass(pass\_en, g\%domain)}
\DoxyCodeLine{273 }
\DoxyCodeLine{274   \textcolor{keyword}{call }complete\_group\_pass(pass\_test, g\%domain)}
\DoxyCodeLine{275 }
\DoxyCodeLine{276   \textcolor{comment}{! Rotate points in the halos as necessary.}}
\DoxyCodeLine{277   \textcolor{keyword}{call }correct\_halo\_rotation(cs\%En, test, g, cs\%nAngle)}
\DoxyCodeLine{278 }
\DoxyCodeLine{279   \textcolor{comment}{! Propagate the waves.}}
\DoxyCodeLine{280   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{281     \textcolor{keyword}{call }propagate(cs\%En(:,:,:,fr,m), cn(:,:,m), cs\%frequency(fr), dt, \&}
\DoxyCodeLine{282                    g, us, cs, cs\%NAngle)}
\DoxyCodeLine{283 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{284 }
\DoxyCodeLine{285   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{286   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{287     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{288       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{289         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset}
\DoxyCodeLine{290         \textcolor{keywordflow}{if} (abs(cs\%En(i,j,a,fr,m))>1.0) \textcolor{keywordflow}{then} \textcolor{comment}{! only print if large}}
\DoxyCodeLine{291           \textcolor{keyword}{write}(mesg,*)  \textcolor{stringliteral}{'After propagation: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{292                          \textcolor{stringliteral}{'En='}, cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{293           \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg))}
\DoxyCodeLine{294 \textcolor{comment}{!          call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{295 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{296         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{297 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{298 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{299 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{300 }
\DoxyCodeLine{301   \textcolor{comment}{! Apply the other half of the refraction.}}
\DoxyCodeLine{302   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{303     \textcolor{keyword}{call }refract(cs\%En(:,:,:,fr,m), cn(:,:,m), cs\%frequency(fr), 0.5*dt, \&}
\DoxyCodeLine{304                  g, us, cs\%NAngle, cs\%use\_PPMang)}
\DoxyCodeLine{305 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{306 }
\DoxyCodeLine{307   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{308   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{309     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{310       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{311         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{312         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After second refraction: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{313                       \textcolor{stringliteral}{'En='},cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{314         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg))}
\DoxyCodeLine{315         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{316 \textcolor{comment}{!        call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{317 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{318 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{319 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{320 }
\DoxyCodeLine{321   \textcolor{comment}{! Apply various dissipation mechanisms.}}
\DoxyCodeLine{322   \textcolor{keywordflow}{if} (cs\%apply\_background\_drag .or. cs\%apply\_bottom\_drag \&}
\DoxyCodeLine{323       .or. cs\%apply\_wave\_drag .or. cs\%apply\_Froude\_drag \&}
\DoxyCodeLine{324       .or. (cs\%id\_tot\_En > 0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{325     tot\_en(:,:) = 0.0}
\DoxyCodeLine{326     tot\_en\_mode(:,:,:,:) = 0.0}
\DoxyCodeLine{327     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{328       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{329         tot\_en(i,j) = tot\_en(i,j) + cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{330         tot\_en\_mode(i,j,fr,m) = tot\_en\_mode(i,j,fr,m) + cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{331 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{332 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{333 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{334 }
\DoxyCodeLine{335   \textcolor{comment}{! Extract the energy for mixing due to misc. processes (background leakage)------}}
\DoxyCodeLine{336   \textcolor{keywordflow}{if} (cs\%apply\_background\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{337     \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{338     \textcolor{comment}{! Calculate loss rate and apply loss over the time step ; apply the same drag timescale}}
\DoxyCodeLine{339     \textcolor{comment}{! to each En component (technically not correct; fix later)}}
\DoxyCodeLine{340     cs\%TKE\_leak\_loss(i,j,a,fr,m)  = cs\%En(i,j,a,fr,m) * cs\%decay\_rate \textcolor{comment}{! loss rate [R Z3 T-3 ~> W m-2]}}
\DoxyCodeLine{341     cs\%En(i,j,a,fr,m) = cs\%En(i,j,a,fr,m) / (1.0 + dt * cs\%decay\_rate) \textcolor{comment}{! implicit update}}
\DoxyCodeLine{342 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{343 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{344   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{345   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{346     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{347       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{348         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{349         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After leak loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{350                       \textcolor{stringliteral}{'En='},cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{351         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{352         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{353 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{354 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{355 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{356 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{357 }
\DoxyCodeLine{358   \textcolor{comment}{! Extract the energy for mixing due to bottom drag-------------------------------}}
\DoxyCodeLine{359   \textcolor{keywordflow}{if} (cs\%apply\_bottom\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{360     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{361       \textcolor{comment}{! Note the 1 m dimensional scale here.  Should this be a parameter?}}
\DoxyCodeLine{362       i\_d\_here = 1.0 / (max(g\%bathyT(i,j), 1.0*us\%m\_to\_Z))}
\DoxyCodeLine{363       drag\_scale(i,j) = cs\%cdrag * sqrt(max(0.0, us\%L\_to\_Z**2*vel\_bttide(i,j)**2 + \&}
\DoxyCodeLine{364                         tot\_en(i,j) * i\_rho0 * i\_d\_here)) * i\_d\_here}
\DoxyCodeLine{365 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{366     \textcolor{keywordflow}{do} m=1,cs\%nMode ; \textcolor{keywordflow}{do} fr=1,cs\%nFreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{367       \textcolor{comment}{! Calculate loss rate and apply loss over the time step ; apply the same drag timescale}}
\DoxyCodeLine{368       \textcolor{comment}{! to each En component (technically not correct; fix later)}}
\DoxyCodeLine{369       cs\%TKE\_quad\_loss(i,j,a,fr,m)  = cs\%En(i,j,a,fr,m) * drag\_scale(i,j) \textcolor{comment}{! loss rate}}
\DoxyCodeLine{370       cs\%En(i,j,a,fr,m) = cs\%En(i,j,a,fr,m) / (1.0 + dt * drag\_scale(i,j)) \textcolor{comment}{! implicit update}}
\DoxyCodeLine{371 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{372 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{373   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{374   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{375     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{376       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{377         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{378         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After bottom loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{379                       \textcolor{stringliteral}{'En='},cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{380         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{381         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{382 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{383         \textcolor{comment}{!stop}}
\DoxyCodeLine{384 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{385 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{386 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{387 }
\DoxyCodeLine{388   \textcolor{comment}{! Extract the energy for mixing due to scattering (wave-drag)--------------------}}
\DoxyCodeLine{389   \textcolor{comment}{! still need to allow a portion of the extracted energy to go to higher modes.}}
\DoxyCodeLine{390   \textcolor{comment}{! First, find velocity profiles}}
\DoxyCodeLine{391   \textcolor{keywordflow}{if} (cs\%apply\_wave\_drag .or. cs\%apply\_Froude\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{392     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{393       \textcolor{comment}{! Calculate modal structure for given mode and frequency}}
\DoxyCodeLine{394       \textcolor{keyword}{call }wave\_structure(h, tv, g, gv, us, cn(:,:,m), m, cs\%frequency(fr), \&}
\DoxyCodeLine{395                           cs\%wave\_structure\_CSp, tot\_en\_mode(:,:,fr,m), full\_halos=.true.)}
\DoxyCodeLine{396       \textcolor{comment}{! Pick out near-bottom and max horizontal baroclinic velocity values at each point}}
\DoxyCodeLine{397       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{398         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{399         nzm = cs\%wave\_structure\_CSp\%num\_intfaces(i,j)}
\DoxyCodeLine{400         ub(i,j,fr,m) = cs\%wave\_structure\_CSp\%Uavg\_profile(i,j,nzm)}
\DoxyCodeLine{401         umax(i,j,fr,m) = maxval(cs\%wave\_structure\_CSp\%Uavg\_profile(i,j,1:nzm))}
\DoxyCodeLine{402 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-loop, j-loop}}
\DoxyCodeLine{403 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! fr-loop, m-loop}}
\DoxyCodeLine{404 \textcolor{keywordflow}{  endif} \textcolor{comment}{! apply\_wave or \_Froude\_drag (Ub or Umax needed)}}
\DoxyCodeLine{405   \textcolor{comment}{! Finally, apply loss}}
\DoxyCodeLine{406   \textcolor{keywordflow}{if} (cs\%apply\_wave\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{407     \textcolor{comment}{! Calculate loss rate and apply loss over the time step}}
\DoxyCodeLine{408     \textcolor{keyword}{call }itidal\_lowmode\_loss(g, us, cs, nb, ub, cs\%En, cs\%TKE\_itidal\_loss\_fixed, \&}
\DoxyCodeLine{409                              cs\%TKE\_itidal\_loss, dt, full\_halos=.false.)}
\DoxyCodeLine{410 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{411   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{412   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{413     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{414       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{415         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{416         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After wave drag loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{417                       \textcolor{stringliteral}{'En='},cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{418         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{419         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{420 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{421 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{422 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{423 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{424 }
\DoxyCodeLine{425   \textcolor{comment}{! Extract the energy for mixing due to wave breaking-----------------------------}}
\DoxyCodeLine{426   \textcolor{keywordflow}{if} (cs\%apply\_Froude\_drag) \textcolor{keywordflow}{then}}
\DoxyCodeLine{427     \textcolor{comment}{! Pick out maximum baroclinic velocity values; calculate Fr=max(u)/cg}}
\DoxyCodeLine{428     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{429       freq2 = cs\%frequency(fr)**2}
\DoxyCodeLine{430       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{431         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset \textcolor{comment}{! for debugging}}
\DoxyCodeLine{432         \textcolor{comment}{! Calculate horizontal phase velocity magnitudes}}
\DoxyCodeLine{433         f2 = 0.25*((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-1,j-1)**2) + \&}
\DoxyCodeLine{434                    (g\%CoriolisBu(i-1,j)**2 + g\%CoriolisBu(i,j-1)**2))}
\DoxyCodeLine{435         kmag2 = (freq2 - f2) / (cn(i,j,m)**2 + cn\_subro**2)}
\DoxyCodeLine{436         c\_phase = 0.0}
\DoxyCodeLine{437         \textcolor{keywordflow}{if} (kmag2 > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{438           c\_phase = sqrt(freq2/kmag2)}
\DoxyCodeLine{439           nzm = cs\%wave\_structure\_CSp\%num\_intfaces(i,j)}
\DoxyCodeLine{440           fr2\_max = (umax(i,j,fr,m) / c\_phase)**2}
\DoxyCodeLine{441           \textcolor{comment}{! Dissipate energy if Fr>1; done here with an arbitrary time scale}}
\DoxyCodeLine{442           \textcolor{keywordflow}{if} (fr2\_max > 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{443             en\_initial = sum(cs\%En(i,j,:,fr,m)) \textcolor{comment}{! for debugging}}
\DoxyCodeLine{444             \textcolor{comment}{! Calculate effective decay rate [T-1 ~> s-1] if breaking occurs over a time step}}
\DoxyCodeLine{445             loss\_rate = (1.0 - fr2\_max) / (fr2\_max * dt)}
\DoxyCodeLine{446             \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{447               \textcolor{comment}{! Determine effective dissipation rate (Wm-2)}}
\DoxyCodeLine{448               cs\%TKE\_Froude\_loss(i,j,a,fr,m) = cs\%En(i,j,a,fr,m) * abs(loss\_rate)}
\DoxyCodeLine{449               \textcolor{comment}{! Update energy}}
\DoxyCodeLine{450               en\_new = cs\%En(i,j,a,fr,m)/fr2\_max \textcolor{comment}{! for debugging}}
\DoxyCodeLine{451               en\_check = cs\%En(i,j,a,fr,m) - cs\%TKE\_Froude\_loss(i,j,a,fr,m)*dt \textcolor{comment}{! for debugging}}
\DoxyCodeLine{452               \textcolor{comment}{! Re-scale (reduce) energy due to breaking}}
\DoxyCodeLine{453               cs\%En(i,j,a,fr,m) = cs\%En(i,j,a,fr,m)/fr2\_max}
\DoxyCodeLine{454               \textcolor{comment}{! Check (for debugging only)}}
\DoxyCodeLine{455               \textcolor{keywordflow}{if} (abs(en\_new - en\_check) > 1e-10*us\%kg\_m3\_to\_R*us\%m\_to\_Z**3*us\%T\_to\_s**2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{456                 \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: something is wrong with Fr-breaking."}, \&}
\DoxyCodeLine{457                                all\_print=.true.)}
\DoxyCodeLine{458                 \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"En\_new="}, en\_new , \textcolor{stringliteral}{"En\_check="}, en\_check}
\DoxyCodeLine{459                 \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{460 \textcolor{keywordflow}{              endif}}
\DoxyCodeLine{461 \textcolor{keywordflow}{            enddo}}
\DoxyCodeLine{462             \textcolor{comment}{! Check (for debugging)}}
\DoxyCodeLine{463             delta\_e\_check = en\_initial - sum(cs\%En(i,j,:,fr,m))}
\DoxyCodeLine{464             tke\_froude\_loss\_check = abs(delta\_e\_check)/dt}
\DoxyCodeLine{465             tke\_froude\_loss\_tot = sum(cs\%TKE\_Froude\_loss(i,j,:,fr,m))}
\DoxyCodeLine{466             \textcolor{keywordflow}{if} (abs(tke\_froude\_loss\_check - tke\_froude\_loss\_tot) > 1e-10) \textcolor{keywordflow}{then}}
\DoxyCodeLine{467               \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: something is wrong with Fr energy update."}, \&}
\DoxyCodeLine{468                              all\_print=.true.)}
\DoxyCodeLine{469               \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"TKE\_Froude\_loss\_check="}, tke\_froude\_loss\_check, \&}
\DoxyCodeLine{470                             \textcolor{stringliteral}{"TKE\_Froude\_loss\_tot="}, tke\_froude\_loss\_tot}
\DoxyCodeLine{471               \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{472 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{473 \textcolor{keywordflow}{          endif} \textcolor{comment}{! Fr2>1}}
\DoxyCodeLine{474 \textcolor{keywordflow}{        endif} \textcolor{comment}{! Kmag2>0}}
\DoxyCodeLine{475         cs\%cp(i,j,fr,m) = c\_phase}
\DoxyCodeLine{476 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{477 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{478 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{479   \textcolor{comment}{! Check for En<0 - for debugging, delete later}}
\DoxyCodeLine{480   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{481     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{482       \textcolor{keywordflow}{if} (cs\%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483         id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset}
\DoxyCodeLine{484         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After Froude loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, \&}
\DoxyCodeLine{485                       \textcolor{stringliteral}{'En='},cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{486         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{487         cs\%En(i,j,a,fr,m) = 0.0}
\DoxyCodeLine{488 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}}
\DoxyCodeLine{489         \textcolor{comment}{!stop}}
\DoxyCodeLine{490 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{491 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{492 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{493 }
\DoxyCodeLine{494   \textcolor{comment}{! Check for energy conservation on computational domain.*************************}}
\DoxyCodeLine{495   \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{496     \textcolor{keyword}{call }sum\_en(g,cs,cs\%En(:,:,:,fr,m),\textcolor{stringliteral}{'prop\_int\_tide'})}
\DoxyCodeLine{497 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{498 }
\DoxyCodeLine{499   \textcolor{comment}{! Output diagnostics.************************************************************}}
\DoxyCodeLine{500   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs\%diag)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{501     \textcolor{comment}{! Output two-dimensional diagnostistics}}
\DoxyCodeLine{502     \textcolor{keywordflow}{if} (cs\%id\_tot\_En > 0)     \textcolor{keyword}{call }post\_data(cs\%id\_tot\_En, tot\_en, cs\%diag)}
\DoxyCodeLine{503     \textcolor{keywordflow}{if} (cs\%id\_itide\_drag > 0) \textcolor{keyword}{call }post\_data(cs\%id\_itide\_drag, drag\_scale, cs\%diag)}
\DoxyCodeLine{504     \textcolor{keywordflow}{if} (cs\%id\_TKE\_itidal\_input > 0) \textcolor{keyword}{call }post\_data(cs\%id\_TKE\_itidal\_input, \&}
\DoxyCodeLine{505                                                    tke\_itidal\_input, cs\%diag)}
\DoxyCodeLine{506 }
\DoxyCodeLine{507     \textcolor{comment}{! Output 2-D energy density (summed over angles) for each freq and mode}}
\DoxyCodeLine{508     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{if} (cs\%id\_En\_mode(fr,m) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{509       tot\_en(:,:) = 0.0}
\DoxyCodeLine{510       \textcolor{keywordflow}{do} a=1,cs\%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{511         tot\_en(i,j) = tot\_en(i,j) + cs\%En(i,j,a,fr,m)}
\DoxyCodeLine{512 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{513       \textcolor{keyword}{call }post\_data(cs\%id\_En\_mode(fr,m), tot\_en, cs\%diag)}
\DoxyCodeLine{514 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{515 }
\DoxyCodeLine{516     \textcolor{comment}{! Output 3-D (i,j,a) energy density for each freq and mode}}
\DoxyCodeLine{517     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{if} (cs\%id\_En\_ang\_mode(fr,m) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{518       \textcolor{keyword}{call }post\_data(cs\%id\_En\_ang\_mode(fr,m), cs\%En(:,:,:,fr,m) , cs\%diag)}
\DoxyCodeLine{519 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{520 }
\DoxyCodeLine{521     \textcolor{comment}{! Output 2-D energy loss (summed over angles, freq, modes)}}
\DoxyCodeLine{522     tot\_leak\_loss(:,:)   = 0.0}
\DoxyCodeLine{523     tot\_quad\_loss(:,:)   = 0.0}
\DoxyCodeLine{524     tot\_itidal\_loss(:,:) = 0.0}
\DoxyCodeLine{525     tot\_froude\_loss(:,:) = 0.0}
\DoxyCodeLine{526     tot\_allprocesses\_loss(:,:) = 0.0}
\DoxyCodeLine{527     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{do} a=1,cs\%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{528       tot\_leak\_loss(i,j)   = tot\_leak\_loss(i,j)   + cs\%TKE\_leak\_loss(i,j,a,fr,m)}
\DoxyCodeLine{529       tot\_quad\_loss(i,j)   = tot\_quad\_loss(i,j)   + cs\%TKE\_quad\_loss(i,j,a,fr,m)}
\DoxyCodeLine{530       tot\_itidal\_loss(i,j) = tot\_itidal\_loss(i,j) + cs\%TKE\_itidal\_loss(i,j,a,fr,m)}
\DoxyCodeLine{531       tot\_froude\_loss(i,j) = tot\_froude\_loss(i,j) + cs\%TKE\_Froude\_loss(i,j,a,fr,m)}
\DoxyCodeLine{532 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{533     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{534       tot\_allprocesses\_loss(i,j) = tot\_leak\_loss(i,j) + tot\_quad\_loss(i,j) + \&}
\DoxyCodeLine{535                           tot\_itidal\_loss(i,j) + tot\_froude\_loss(i,j)}
\DoxyCodeLine{536 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{537     cs\%tot\_leak\_loss         = tot\_leak\_loss}
\DoxyCodeLine{538     cs\%tot\_quad\_loss         = tot\_quad\_loss}
\DoxyCodeLine{539     cs\%tot\_itidal\_loss       = tot\_itidal\_loss}
\DoxyCodeLine{540     cs\%tot\_Froude\_loss       = tot\_froude\_loss}
\DoxyCodeLine{541     cs\%tot\_allprocesses\_loss = tot\_allprocesses\_loss}
\DoxyCodeLine{542     \textcolor{keywordflow}{if} (cs\%id\_tot\_leak\_loss > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{543       \textcolor{keyword}{call }post\_data(cs\%id\_tot\_leak\_loss, tot\_leak\_loss, cs\%diag)}
\DoxyCodeLine{544 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{545     \textcolor{keywordflow}{if} (cs\%id\_tot\_quad\_loss > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{546       \textcolor{keyword}{call }post\_data(cs\%id\_tot\_quad\_loss, tot\_quad\_loss, cs\%diag)}
\DoxyCodeLine{547 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{548     \textcolor{keywordflow}{if} (cs\%id\_tot\_itidal\_loss > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{549       \textcolor{keyword}{call }post\_data(cs\%id\_tot\_itidal\_loss, tot\_itidal\_loss, cs\%diag)}
\DoxyCodeLine{550 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{551     \textcolor{keywordflow}{if} (cs\%id\_tot\_Froude\_loss > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{552       \textcolor{keyword}{call }post\_data(cs\%id\_tot\_Froude\_loss, tot\_froude\_loss, cs\%diag)}
\DoxyCodeLine{553 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{554     \textcolor{keywordflow}{if} (cs\%id\_tot\_allprocesses\_loss > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{555       \textcolor{keyword}{call }post\_data(cs\%id\_tot\_allprocesses\_loss, tot\_allprocesses\_loss, cs\%diag)}
\DoxyCodeLine{556 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{557 }
\DoxyCodeLine{558     \textcolor{comment}{! Output 2-D energy loss (summed over angles) for each freq and mode}}
\DoxyCodeLine{559     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq}
\DoxyCodeLine{560     \textcolor{keywordflow}{if} (cs\%id\_itidal\_loss\_mode(fr,m) > 0 .or. cs\%id\_allprocesses\_loss\_mode(fr,m) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{561       itidal\_loss\_mode(:,:) = 0.0 \textcolor{comment}{! wave-drag processes (could do others as well)}}
\DoxyCodeLine{562       allprocesses\_loss\_mode(:,:) = 0.0 \textcolor{comment}{! all processes summed together}}
\DoxyCodeLine{563       \textcolor{keywordflow}{do} a=1,cs\%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{564         itidal\_loss\_mode(i,j)       = itidal\_loss\_mode(i,j) + cs\%TKE\_itidal\_loss(i,j,a,fr,m)}
\DoxyCodeLine{565         allprocesses\_loss\_mode(i,j) = allprocesses\_loss\_mode(i,j) + \&}
\DoxyCodeLine{566                                  cs\%TKE\_leak\_loss(i,j,a,fr,m) + cs\%TKE\_quad\_loss(i,j,a,fr,m) + \&}
\DoxyCodeLine{567                                  cs\%TKE\_itidal\_loss(i,j,a,fr,m) + cs\%TKE\_Froude\_loss(i,j,a,fr,m)}
\DoxyCodeLine{568 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{569       \textcolor{keyword}{call }post\_data(cs\%id\_itidal\_loss\_mode(fr,m), itidal\_loss\_mode, cs\%diag)}
\DoxyCodeLine{570       \textcolor{keyword}{call }post\_data(cs\%id\_allprocesses\_loss\_mode(fr,m), allprocesses\_loss\_mode, cs\%diag)}
\DoxyCodeLine{571 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{572 }
\DoxyCodeLine{573     \textcolor{comment}{! Output 3-D (i,j,a) energy loss for each freq and mode}}
\DoxyCodeLine{574     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{if} (cs\%id\_itidal\_loss\_ang\_mode(fr,m) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{575       \textcolor{keyword}{call }post\_data(cs\%id\_itidal\_loss\_ang\_mode(fr,m), cs\%TKE\_itidal\_loss(:,:,:,fr,m) , cs\%diag)}
\DoxyCodeLine{576 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{577 }
\DoxyCodeLine{578     \textcolor{comment}{! Output 2-D period-averaged horizontal near-bottom mode velocity for each freq and mode}}
\DoxyCodeLine{579     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{if} (cs\%id\_Ub\_mode(fr,m) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{580       \textcolor{keyword}{call }post\_data(cs\%id\_Ub\_mode(fr,m), ub(:,:,fr,m), cs\%diag)}
\DoxyCodeLine{581 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{582 }
\DoxyCodeLine{583     \textcolor{comment}{! Output 2-D horizontal phase velocity for each freq and mode}}
\DoxyCodeLine{584     \textcolor{keywordflow}{do} m=1,cs\%NMode ; \textcolor{keywordflow}{do} fr=1,cs\%Nfreq ; \textcolor{keywordflow}{if} (cs\%id\_cp\_mode(fr,m) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{585       \textcolor{keyword}{call }post\_data(cs\%id\_cp\_mode(fr,m), cs\%cp(:,:,fr,m), cs\%diag)}
\DoxyCodeLine{586 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{587 }
\DoxyCodeLine{588 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{589 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a0b300e27b0ec984bfe8b9afe4e89f8ab}\label{namespacemom__internal__tides_a0b300e27b0ec984bfe8b9afe4e89f8ab}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!propagate\_x@{propagate\_x}}
\index{propagate\_x@{propagate\_x}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{propagate\_x()}{propagate\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+x (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isdb\+:g\%iedb,g\%jsd\+:g\%jed), intent(in)}]{speed\+\_\+x,  }\item[{real, dimension(nangle), intent(in)}]{Cgx\+\_\+av,  }\item[{real, dimension(nangle), intent(in)}]{d\+Cgx,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{Nangle,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Propagates the internal wave energy in the logical x-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The energy density integrated over an angular \\
\hline
\mbox{\texttt{ in}}  & {\em speed\+\_\+x} & The magnitude of the group velocity at the \\
\hline
\mbox{\texttt{ in}}  & {\em cgx\+\_\+av} & The average x-\/projection in each angular band. \\
\hline
\mbox{\texttt{ in}}  & {\em dcgx} & The difference in x-\/projections between the edges of each angular band. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to continuity\+\_\+\+P\+P\+M\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1359 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1359   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{1360   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{1361 \textcolor{comment}{                                               !! discretized wave energy spectrum.}}
\DoxyCodeLine{1362 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,Nangle)},   \&}
\DoxyCodeLine{1363                            \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{ !< The energy density integrated over an angular}}
\DoxyCodeLine{1364 \textcolor{comment}{                                               !! band [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1365 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%jsd:G\%jed)},        \&}
\DoxyCodeLine{1366                            \textcolor{keywordtype}{intent(in)}    :: speed\_x\textcolor{comment}{ !< The magnitude of the group velocity at the}}
\DoxyCodeLine{1367 \textcolor{comment}{                                               !! Cu points [L T-1 ~> m s-1].}}
\DoxyCodeLine{1368 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: Cgx\_av\textcolor{comment}{ !< The average x-projection in each angular band.}}
\DoxyCodeLine{1369 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: dCgx\textcolor{comment}{ !< The difference in x-projections between the}}
\DoxyCodeLine{1370 \textcolor{comment}{                                               !! edges of each angular band.}}
\DoxyCodeLine{1371 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{1372   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1373   \textcolor{keywordtype}{type}(int\_tide\_CS),       \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a previous call}}
\DoxyCodeLine{1374 \textcolor{comment}{                                               !! to continuity\_PPM\_init.}}
\DoxyCodeLine{1375   \textcolor{keywordtype}{type}(loop\_bounds\_type),  \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{ !< A structure with the active energy loop bounds.}}
\DoxyCodeLine{1376   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1377 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{1378     EnL, EnR    \textcolor{comment}{! Left and right face energy densities [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1379 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{1380     flux\_x      \textcolor{comment}{! The internal wave energy flux [J T-1 ~> J s-1].}}
\DoxyCodeLine{1381 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: \&}
\DoxyCodeLine{1382     cg\_p, cg\_m, flux1, flux2}
\DoxyCodeLine{1383   \textcolor{comment}{!real, dimension(SZI\_(G),SZJB\_(G),Nangle) :: En\_m, En\_p}}
\DoxyCodeLine{1384 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),Nangle)} :: \&}
\DoxyCodeLine{1385     Fdt\_m, Fdt\_p\textcolor{comment}{! Left and right energy fluxes [J]}}
\DoxyCodeLine{1386   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, a}
\DoxyCodeLine{1387 }
\DoxyCodeLine{1388   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh}
\DoxyCodeLine{1389   \textcolor{keywordflow}{do} a=1,nangle}
\DoxyCodeLine{1390   \textcolor{comment}{! This sets EnL and EnR.}}
\DoxyCodeLine{1391     \textcolor{keywordflow}{if} (cs\%upwind\_1st) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1392       \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh+1}
\DoxyCodeLine{1393         enl(i,j) = en(i,j,a) ; enr(i,j) = en(i,j,a)}
\DoxyCodeLine{1394 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1395     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1396       \textcolor{keyword}{call }ppm\_reconstruction\_x(en(:,:,a), enl, enr, g, lb, simple\_2nd=cs\%simple\_2nd)}
\DoxyCodeLine{1397 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1398 }
\DoxyCodeLine{1399     \textcolor{keywordflow}{do} j=jsh,jeh}
\DoxyCodeLine{1400       \textcolor{comment}{! This is done once with single speed (GARDEN SPRINKLER EFFECT POSSIBLE)}}
\DoxyCodeLine{1401       \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{1402         cg\_p(i) = speed\_x(i,j) * (cgx\_av(a))}
\DoxyCodeLine{1403 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1404       \textcolor{keyword}{call }zonal\_flux\_en(cg\_p, en(:,j,a), enl(:,j), enr(:,j), flux1, \&}
\DoxyCodeLine{1405                          dt, g, us, j, ish, ieh, cs\%vol\_CFL)}
\DoxyCodeLine{1406       \textcolor{keywordflow}{do} i=ish-1,ieh ; flux\_x(i,j) = flux1(i);\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1407 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1408 }
\DoxyCodeLine{1409     \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1410       fdt\_m(i,j,a) = dt*flux\_x(i-1,j) \textcolor{comment}{! left face influx  (J)}}
\DoxyCodeLine{1411       fdt\_p(i,j,a) = -dt*flux\_x(i,j)  \textcolor{comment}{! right face influx (J)}}
\DoxyCodeLine{1412 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1413 }
\DoxyCodeLine{1414 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! a-loop}}
\DoxyCodeLine{1415 }
\DoxyCodeLine{1416   \textcolor{comment}{! Only reflect newly arrived energy; existing energy in incident wedge is not reflected}}
\DoxyCodeLine{1417   \textcolor{comment}{! and will eventually propagate out of cell. (This code only reflects if En > 0.)}}
\DoxyCodeLine{1418   \textcolor{keyword}{call }reflect(fdt\_m, nangle, cs, g, lb)}
\DoxyCodeLine{1419   \textcolor{keyword}{call }teleport(fdt\_m, nangle, cs, g, lb)}
\DoxyCodeLine{1420   \textcolor{keyword}{call }reflect(fdt\_p, nangle, cs, g, lb)}
\DoxyCodeLine{1421   \textcolor{keyword}{call }teleport(fdt\_p, nangle, cs, g, lb)}
\DoxyCodeLine{1422 }
\DoxyCodeLine{1423   \textcolor{comment}{! Update reflected energy [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{1424   \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1425     \textcolor{comment}{!  if ((En(i,j,a) + G\%IareaT(i,j)*(Fdt\_m(i,j,a) + Fdt\_p(i,j,a))) < 0.0) \& ! for debugging}}
\DoxyCodeLine{1426     \textcolor{comment}{!    call MOM\_error(FATAL, "propagate\_x: OutFlux>Available")}}
\DoxyCodeLine{1427     en(i,j,a) = en(i,j,a) + g\%IareaT(i,j)*(fdt\_m(i,j,a) + fdt\_p(i,j,a))}
\DoxyCodeLine{1428 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1429 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_ae1a31a7f0db2b05c1d863f022b799c7b}\label{namespacemom__internal__tides_ae1a31a7f0db2b05c1d863f022b799c7b}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!propagate\_y@{propagate\_y}}
\index{propagate\_y@{propagate\_y}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{propagate\_y()}{propagate\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+y (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsdb\+:g\%jedb), intent(in)}]{speed\+\_\+y,  }\item[{real, dimension(nangle), intent(in)}]{Cgy\+\_\+av,  }\item[{real, dimension(nangle), intent(in)}]{d\+Cgy,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{Nangle,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Propagates the internal wave energy in the logical y-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The energy density integrated over an angular \\
\hline
\mbox{\texttt{ in}}  & {\em speed\+\_\+y} & The magnitude of the group velocity at the \\
\hline
\mbox{\texttt{ in}}  & {\em cgy\+\_\+av} & The average y-\/projection in each angular band. \\
\hline
\mbox{\texttt{ in}}  & {\em dcgy} & The difference in y-\/projections between the edges of each angular band. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to continuity\+\_\+\+P\+P\+M\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1434 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1434   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{1435   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{1436 \textcolor{comment}{                                               !! discretized wave energy spectrum.}}
\DoxyCodeLine{1437 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,Nangle)}, \&}
\DoxyCodeLine{1438                            \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{ !< The energy density integrated over an angular}}
\DoxyCodeLine{1439 \textcolor{comment}{                                               !! band [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1440 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%JsdB:G\%JedB)},      \&}
\DoxyCodeLine{1441                            \textcolor{keywordtype}{intent(in)}    :: speed\_y\textcolor{comment}{ !< The magnitude of the group velocity at the}}
\DoxyCodeLine{1442 \textcolor{comment}{                                               !! Cv points [L T-1 ~> m s-1].}}
\DoxyCodeLine{1443 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: Cgy\_av\textcolor{comment}{ !< The average y-projection in each angular band.}}
\DoxyCodeLine{1444 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: dCgy\textcolor{comment}{ !< The difference in y-projections between the}}
\DoxyCodeLine{1445 \textcolor{comment}{                                               !! edges of each angular band.}}
\DoxyCodeLine{1446 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{1447   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1448   \textcolor{keywordtype}{type}(int\_tide\_CS),       \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a previous call}}
\DoxyCodeLine{1449 \textcolor{comment}{                                               !! to continuity\_PPM\_init.}}
\DoxyCodeLine{1450   \textcolor{keywordtype}{type}(loop\_bounds\_type),  \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{ !< A structure with the active energy loop bounds.}}
\DoxyCodeLine{1451   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1452 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{1453     EnL, EnR    \textcolor{comment}{! South and north face energy densities [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1454 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{1455     flux\_y      \textcolor{comment}{! The internal wave energy flux [J T-1 ~> J s-1].}}
\DoxyCodeLine{1456 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{1457     cg\_p, cg\_m, flux1, flux2}
\DoxyCodeLine{1458   \textcolor{comment}{!real, dimension(SZI\_(G),SZJB\_(G),Nangle) :: En\_m, En\_p}}
\DoxyCodeLine{1459 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),Nangle)} :: \&}
\DoxyCodeLine{1460     Fdt\_m, Fdt\_p\textcolor{comment}{! South and north energy fluxes [J]}}
\DoxyCodeLine{1461   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{1462   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, a}
\DoxyCodeLine{1463 }
\DoxyCodeLine{1464   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh}
\DoxyCodeLine{1465   \textcolor{keywordflow}{do} a=1,nangle}
\DoxyCodeLine{1466     \textcolor{comment}{! This sets EnL and EnR.}}
\DoxyCodeLine{1467     \textcolor{keywordflow}{if} (cs\%upwind\_1st) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1468       \textcolor{keywordflow}{do} j=jsh-1,jeh+1 ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1469         enl(i,j) = en(i,j,a) ; enr(i,j) = en(i,j,a)}
\DoxyCodeLine{1470 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1471     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1472       \textcolor{keyword}{call }ppm\_reconstruction\_y(en(:,:,a), enl, enr, g, lb, simple\_2nd=cs\%simple\_2nd)}
\DoxyCodeLine{1473 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1474 }
\DoxyCodeLine{1475     \textcolor{keywordflow}{do} j=jsh-1,jeh}
\DoxyCodeLine{1476       \textcolor{comment}{!   This is done once with single speed (GARDEN SPRINKLER EFFECT POSSIBLE)}}
\DoxyCodeLine{1477       \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1478         cg\_p(i) = speed\_y(i,j) * (cgy\_av(a))}
\DoxyCodeLine{1479 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{1480       \textcolor{keyword}{call }merid\_flux\_en(cg\_p, en(:,:,a), enl(:,:), enr(:,:), flux1, \&}
\DoxyCodeLine{1481                          dt, g, us, j, ish, ieh, cs\%vol\_CFL)}
\DoxyCodeLine{1482       \textcolor{keywordflow}{do} i=ish,ieh ; flux\_y(i,j) = flux1(i);\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1483 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{1484 }
\DoxyCodeLine{1485     \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1486       fdt\_m(i,j,a) = dt*flux\_y(i,j-1) \textcolor{comment}{! south face influx (J)}}
\DoxyCodeLine{1487       fdt\_p(i,j,a) = -dt*flux\_y(i,j)  \textcolor{comment}{! north face influx (J)}}
\DoxyCodeLine{1488       \textcolor{comment}{!if ((En(i,j,a) + G\%IareaT(i,j)*(Fdt\_m(i,j,a) + Fdt\_p(i,j,a))) < 0.0) then ! for debugging}}
\DoxyCodeLine{1489       \textcolor{comment}{!  call MOM\_error(WARNING, "propagate\_y: OutFlux>Available prior to reflection", .true.)}}
\DoxyCodeLine{1490       \textcolor{comment}{!  write(mesg,*) "flux\_y\_south=",flux\_y(i,J-1),"flux\_y\_north=",flux\_y(i,J),"En=",En(i,j,a), \&}}
\DoxyCodeLine{1491       \textcolor{comment}{!           "cn\_south=", speed\_y(i,J-1) * (Cgy\_av(a)), "cn\_north=", speed\_y(i,J) * (Cgy\_av(a))}}
\DoxyCodeLine{1492       \textcolor{comment}{!  call MOM\_error(WARNING, mesg, .true.)}}
\DoxyCodeLine{1493       \textcolor{comment}{!endif}}
\DoxyCodeLine{1494 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1495 }
\DoxyCodeLine{1496 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! a-loop}}
\DoxyCodeLine{1497 }
\DoxyCodeLine{1498   \textcolor{comment}{! Only reflect newly arrived energy; existing energy in incident wedge is not reflected}}
\DoxyCodeLine{1499   \textcolor{comment}{! and will eventually propagate out of cell. (This code only reflects if En > 0.)}}
\DoxyCodeLine{1500   \textcolor{keyword}{call }reflect(fdt\_m, nangle, cs, g, lb)}
\DoxyCodeLine{1501   \textcolor{keyword}{call }teleport(fdt\_m, nangle, cs, g, lb)}
\DoxyCodeLine{1502   \textcolor{keyword}{call }reflect(fdt\_p, nangle, cs, g, lb)}
\DoxyCodeLine{1503   \textcolor{keyword}{call }teleport(fdt\_p, nangle, cs, g, lb)}
\DoxyCodeLine{1504 }
\DoxyCodeLine{1505   \textcolor{comment}{! Update reflected energy [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{1506   \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1507     \textcolor{comment}{!  if ((En(i,j,a) + G\%IareaT(i,j)*(Fdt\_m(i,j,a) + Fdt\_p(i,j,a))) < 0.0) \& ! for debugging}}
\DoxyCodeLine{1508     \textcolor{comment}{!    call MOM\_error(FATAL, "propagate\_y: OutFlux>Available", .true.)}}
\DoxyCodeLine{1509     en(i,j,a) = en(i,j,a) + g\%IareaT(i,j)*(fdt\_m(i,j,a) + fdt\_p(i,j,a))}
\DoxyCodeLine{1510 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1511 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a6c622bfe3863b8fcea98c78104477491}\label{namespacemom__internal__tides_a6c622bfe3863b8fcea98c78104477491}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!reflect@{reflect}}
\index{reflect@{reflect}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{reflect()}{reflect()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::reflect (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Reflection of the internal waves at a single frequency. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The internal gravity wave energy density as a \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1602 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1602   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure}}
\DoxyCodeLine{1603   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{1604 \textcolor{comment}{                                              !! discretized wave energy spectrum.}}
\DoxyCodeLine{1605 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,NAngle)}, \&}
\DoxyCodeLine{1606                           \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{ !< The internal gravity wave energy density as a}}
\DoxyCodeLine{1607 \textcolor{comment}{                                              !! function of space and angular resolution}}
\DoxyCodeLine{1608 \textcolor{comment}{                                              !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1609   \textcolor{keywordtype}{type}(int\_tide\_CS),      \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a}}
\DoxyCodeLine{1610 \textcolor{comment}{                                              !! previous call to int\_tide\_init.}}
\DoxyCodeLine{1611   \textcolor{keywordtype}{type}(loop\_bounds\_type), \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{ !< A structure with the active energy loop bounds.}}
\DoxyCodeLine{1612   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1613 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)} :: angle\_c}
\DoxyCodeLine{1614                                            \textcolor{comment}{! angle of boundary wrt equator [rad]}}
\DoxyCodeLine{1615 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)} :: part\_refl}
\DoxyCodeLine{1616                                            \textcolor{comment}{! fraction of wave energy reflected}}
\DoxyCodeLine{1617                                            \textcolor{comment}{! values should collocate with angle\_c [nondim]}}
\DoxyCodeLine{1618   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)} :: ridge}
\DoxyCodeLine{1619                                            \textcolor{comment}{! tags of cells with double reflection}}
\DoxyCodeLine{1620 }
\DoxyCodeLine{1621 \textcolor{keywordtype}{  real}    :: TwoPi                         \textcolor{comment}{! 2*pi = 6.2831853... [nondim]}}
\DoxyCodeLine{1622 \textcolor{keywordtype}{  real}    :: Angle\_size                    \textcolor{comment}{! size of beam wedge [rad]}}
\DoxyCodeLine{1623 \textcolor{keywordtype}{  real}    :: angle\_wall                    \textcolor{comment}{! angle of coast/ridge/shelf wrt equator [rad]}}
\DoxyCodeLine{1624 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1:NAngle)} :: angle\_i     \textcolor{comment}{! angle of incident ray wrt equator [rad]}}
\DoxyCodeLine{1625 \textcolor{keywordtype}{  real}    :: angle\_r                       \textcolor{comment}{! angle of reflected ray wrt equator [rad]}}
\DoxyCodeLine{1626 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1:Nangle)} :: En\_reflected}
\DoxyCodeLine{1627   \textcolor{keywordtype}{integer} :: i, j, a, a\_r, na}
\DoxyCodeLine{1628   \textcolor{comment}{!integer :: isd, ied, jsd, jed   ! start and end local indices on data domain}}
\DoxyCodeLine{1629   \textcolor{comment}{!                                ! (values include halos)}}
\DoxyCodeLine{1630   \textcolor{keywordtype}{integer} :: isc, iec, jsc, jec   \textcolor{comment}{! start and end local indices on PE}}
\DoxyCodeLine{1631                                   \textcolor{comment}{! (values exclude halos)}}
\DoxyCodeLine{1632   \textcolor{keywordtype}{integer} :: ish, ieh, jsh, jeh   \textcolor{comment}{! start and end local indices on data domain}}
\DoxyCodeLine{1633                                   \textcolor{comment}{! leaving out outdated halo points (march in)}}
\DoxyCodeLine{1634 }
\DoxyCodeLine{1635   \textcolor{comment}{!isd = G\%isd  ; ied = G\%ied  ; jsd = G\%jsd  ; jed = G\%jed}}
\DoxyCodeLine{1636   isc = g\%isc  ; iec = g\%iec  ; jsc = g\%jsc  ; jec = g\%jec}
\DoxyCodeLine{1637   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh}
\DoxyCodeLine{1638 }
\DoxyCodeLine{1639   twopi = 8.0*atan(1.0)}
\DoxyCodeLine{1640   angle\_size = twopi / (real(nangle))}
\DoxyCodeLine{1641 }
\DoxyCodeLine{1642   \textcolor{keywordflow}{do} a=1,nangle}
\DoxyCodeLine{1643     \textcolor{comment}{! These are the angles at the cell centers}}
\DoxyCodeLine{1644     \textcolor{comment}{! (should do this elsewhere since doesn't change with time)}}
\DoxyCodeLine{1645     angle\_i(a) = angle\_size * real(a - 1) \textcolor{comment}{! for a=1 aligned with x-axis}}
\DoxyCodeLine{1646 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1647 }
\DoxyCodeLine{1648   angle\_c   = cs\%refl\_angle}
\DoxyCodeLine{1649   part\_refl = cs\%refl\_pref}
\DoxyCodeLine{1650   ridge     = cs\%refl\_dbl}
\DoxyCodeLine{1651   en\_reflected(:) = 0.0}
\DoxyCodeLine{1652 }
\DoxyCodeLine{1653   \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1654     \textcolor{comment}{! redistribute energy in angular space if ray will hit boundary}}
\DoxyCodeLine{1655     \textcolor{comment}{! i.e., if energy is in a reflecting cell}}
\DoxyCodeLine{1656     \textcolor{keywordflow}{if} (angle\_c(i,j) /= cs\%nullangle) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1657       \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{if} (en(i,j,a) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1658         \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_c(i,j)) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1659           \textcolor{comment}{! if ray is incident, keep specified boundary angle}}
\DoxyCodeLine{1660           angle\_wall = angle\_c(i,j)}
\DoxyCodeLine{1661         \textcolor{keywordflow}{elseif} (ridge(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1662          \textcolor{comment}{! if ray is not incident but in ridge cell, use complementary angle}}
\DoxyCodeLine{1663          angle\_wall = angle\_c(i,j) + 0.5*twopi}
\DoxyCodeLine{1664           \textcolor{keywordflow}{if} (angle\_wall > twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1665             angle\_wall = angle\_wall - twopi*floor(abs(angle\_wall)/twopi)}
\DoxyCodeLine{1666           \textcolor{keywordflow}{elseif} (angle\_wall < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1667             angle\_wall = angle\_wall + twopi*ceiling(abs(angle\_wall)/twopi)}
\DoxyCodeLine{1668 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1669         \textcolor{keywordflow}{else}}
\DoxyCodeLine{1670           \textcolor{comment}{! if ray is not incident and not in a ridge cell, keep specified angle}}
\DoxyCodeLine{1671           angle\_wall = angle\_c(i,j)}
\DoxyCodeLine{1672 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1673 }
\DoxyCodeLine{1674         \textcolor{comment}{! do reflection}}
\DoxyCodeLine{1675         \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_wall) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1676           angle\_r = 2.0*angle\_wall - angle\_i(a)}
\DoxyCodeLine{1677           \textcolor{keywordflow}{if} (angle\_r > twopi) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1678             angle\_r = angle\_r - twopi*floor(abs(angle\_r)/twopi)}
\DoxyCodeLine{1679           \textcolor{keywordflow}{elseif} (angle\_r < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1680             angle\_r = angle\_r + twopi*ceiling(abs(angle\_r)/twopi)}
\DoxyCodeLine{1681 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1682           a\_r = nint(angle\_r/angle\_size) + 1}
\DoxyCodeLine{1683           \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (a\_r > nangle) ; a\_r = a\_r - nangle ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1684           \textcolor{keywordflow}{if} (a /= a\_r) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1685             en\_reflected(a\_r) = part\_refl(i,j)*en(i,j,a)}
\DoxyCodeLine{1686             en(i,j,a)   = (1.0-part\_refl(i,j))*en(i,j,a)}
\DoxyCodeLine{1687 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{1688 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{1689 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! a-loop}}
\DoxyCodeLine{1690       \textcolor{keywordflow}{do} a=1,nangle}
\DoxyCodeLine{1691         en(i,j,a) = en(i,j,a) + en\_reflected(a)}
\DoxyCodeLine{1692         en\_reflected(a) = 0.0}
\DoxyCodeLine{1693 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! a-loop}}
\DoxyCodeLine{1694 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1695 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i- and j-loops}}
\DoxyCodeLine{1696 }
\DoxyCodeLine{1697   \textcolor{comment}{! Check to make sure no energy gets onto land (only run for debugging)}}
\DoxyCodeLine{1698   \textcolor{comment}{! do a=1,NAngle ; do j=jsc,jec ; do i=isc,iec}}
\DoxyCodeLine{1699   \textcolor{comment}{!   if (En(i,j,a) > 0.001 .and. G\%mask2dT(i,j) == 0) then}}
\DoxyCodeLine{1700   \textcolor{comment}{!     write (mesg,*) 'En=', En(i,j,a), 'a=', a, 'ig\_g=',i+G\%idg\_offset, 'jg\_g=',j+G\%jdg\_offset}}
\DoxyCodeLine{1701   \textcolor{comment}{!     call MOM\_error(FATAL, "reflect: Energy detected out of bounds: "//trim(mesg), .true.)}}
\DoxyCodeLine{1702   \textcolor{comment}{!   endif}}
\DoxyCodeLine{1703   \textcolor{comment}{! enddo ; enddo ; enddo}}
\DoxyCodeLine{1704 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a0814f61fee53f0941061056641132493}\label{namespacemom__internal__tides_a0814f61fee53f0941061056641132493}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!refract@{refract}}
\index{refract@{refract}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{refract()}{refract()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::refract (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{cn,  }\item[{real, intent(in)}]{freq,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{logical, intent(in)}]{use\+\_\+\+P\+P\+Mang }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Implements refraction on the internal waves at a single frequency. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The internal gravity wave energy density as a \\
\hline
\mbox{\texttt{ in}}  & {\em cn} & Baroclinic mode speed \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em freq} & Wave frequency \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time step \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em use\+\_\+ppmang} & If true, use P\+PM for advection rather than upwind. \\
\hline
\end{DoxyParams}


Definition at line 746 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{746   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{747   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{748 \textcolor{comment}{                                               !! discretized wave energy spectrum.}}
\DoxyCodeLine{749 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,NAngle)}, \&}
\DoxyCodeLine{750                          \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{   !< The internal gravity wave energy density as a}}
\DoxyCodeLine{751 \textcolor{comment}{                                               !! function of space and angular resolution,}}
\DoxyCodeLine{752 \textcolor{comment}{                                               !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{753 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)},        \&}
\DoxyCodeLine{754                          \textcolor{keywordtype}{intent(in)}    :: cn\textcolor{comment}{   !< Baroclinic mode speed [L T-1 ~> m s-1].}}
\DoxyCodeLine{755 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: freq\textcolor{comment}{ !< Wave frequency [T-1 ~> s-1].}}
\DoxyCodeLine{756 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time step [T ~> s].}}
\DoxyCodeLine{757   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{758   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: use\_PPMang\textcolor{comment}{ !< If true, use PPM for advection rather}}
\DoxyCodeLine{759 \textcolor{comment}{                                               !! than upwind.}}
\DoxyCodeLine{760   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{761   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stencil = 2}
\DoxyCodeLine{762 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),1-stencil:NAngle+stencil)} :: \&}
\DoxyCodeLine{763     En2d}
\DoxyCodeLine{764 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1-stencil:NAngle+stencil)} :: \&}
\DoxyCodeLine{765     cos\_angle, sin\_angle}
\DoxyCodeLine{766 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{767     Dk\_Dt\_Kmag, Dl\_Dt\_Kmag}
\DoxyCodeLine{768 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),0:nAngle)} :: \&}
\DoxyCodeLine{769     Flux\_E}
\DoxyCodeLine{770 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),1-stencil:NAngle+stencil)} :: \&}
\DoxyCodeLine{771     CFL\_ang}
\DoxyCodeLine{772 \textcolor{keywordtype}{  real} :: f2              \textcolor{comment}{! The squared Coriolis parameter [T-2 ~> s-2].}}
\DoxyCodeLine{773 \textcolor{keywordtype}{  real} :: favg            \textcolor{comment}{! The average Coriolis parameter at a point [T-1 ~> s-1].}}
\DoxyCodeLine{774 \textcolor{keywordtype}{  real} :: df\_dy, df\_dx    \textcolor{comment}{! The x- and y- gradients of the Coriolis parameter [T-1 L-1 ~> s-1 m-1].}}
\DoxyCodeLine{775 \textcolor{keywordtype}{  real} :: dlnCn\_dx        \textcolor{comment}{! The x-gradient of the wave speed divided by itself [L-1 ~> m-1].}}
\DoxyCodeLine{776 \textcolor{keywordtype}{  real} :: dlnCn\_dy        \textcolor{comment}{! The y-gradient of the wave speed divided by itself [L-1 ~> m-1].}}
\DoxyCodeLine{777 \textcolor{keywordtype}{  real} :: Angle\_size, dt\_Angle\_size, angle}
\DoxyCodeLine{778 \textcolor{keywordtype}{  real} :: Ifreq, Kmag2, I\_Kmag}
\DoxyCodeLine{779 \textcolor{keywordtype}{  real} :: cn\_subRO        \textcolor{comment}{! A tiny wave speed to prevent division by zero [L T-1 ~> m s-1]}}
\DoxyCodeLine{780   \textcolor{keywordtype}{integer} :: is, ie, js, je, asd, aed, na}
\DoxyCodeLine{781   \textcolor{keywordtype}{integer} :: i, j, a}
\DoxyCodeLine{782 }
\DoxyCodeLine{783   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; na = \textcolor{keyword}{size}(en,3)}
\DoxyCodeLine{784   asd = 1-stencil ; aed = nangle+stencil}
\DoxyCodeLine{785 }
\DoxyCodeLine{786   ifreq = 1.0 / freq}
\DoxyCodeLine{787   cn\_subro = 1e-100*us\%m\_s\_to\_L\_T  \textcolor{comment}{! The hard-coded value here might need to increase.}}
\DoxyCodeLine{788   angle\_size = (8.0*atan(1.0)) / (real(nangle))}
\DoxyCodeLine{789   dt\_angle\_size = dt / angle\_size}
\DoxyCodeLine{790 }
\DoxyCodeLine{791   \textcolor{keywordflow}{do} a=asd,aed}
\DoxyCodeLine{792     angle = (real(a) - 0.5) * angle\_size}
\DoxyCodeLine{793     cos\_angle(a) = cos(angle) ; sin\_angle(a) = sin(angle)}
\DoxyCodeLine{794 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{795 }
\DoxyCodeLine{796   \textcolor{comment}{!\#\#\# There should also be refraction due to cn.grad(grid\_orientation).}}
\DoxyCodeLine{797   cfl\_ang(:,:,:) = 0.0}
\DoxyCodeLine{798   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{799   \textcolor{comment}{! Copy En into angle space with halos.}}
\DoxyCodeLine{800     \textcolor{keywordflow}{do} a=1,na ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{801       en2d(i,a) = en(i,j,a)}
\DoxyCodeLine{802 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{803     \textcolor{keywordflow}{do} a=asd,0 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{804       en2d(i,a) = en2d(i,a+nangle)}
\DoxyCodeLine{805       en2d(i,nangle+stencil+a) = en2d(i,stencil+a)}
\DoxyCodeLine{806 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{807 }
\DoxyCodeLine{808   \textcolor{comment}{! Do the refraction.}}
\DoxyCodeLine{809     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{810       f2 = 0.25* ((g\%CoriolisBu(i,j)**2 + g\%CoriolisBu(i-1,j-1)**2) + \&}
\DoxyCodeLine{811                  (g\%CoriolisBu(i,j-1)**2 + g\%CoriolisBu(i-1,j)**2))}
\DoxyCodeLine{812       favg = 0.25*((g\%CoriolisBu(i,j) + g\%CoriolisBu(i-1,j-1)) + \&}
\DoxyCodeLine{813                    (g\%CoriolisBu(i,j-1) + g\%CoriolisBu(i-1,j)))}
\DoxyCodeLine{814       df\_dx = 0.5*((g\%CoriolisBu(i,j) + g\%CoriolisBu(i,j-1)) - \&}
\DoxyCodeLine{815                     (g\%CoriolisBu(i-1,j) + g\%CoriolisBu(i-1,j-1))) * g\%IdxT(i,j)}
\DoxyCodeLine{816       dlncn\_dx = 0.5*( g\%IdxCu(i,j) * (cn(i+1,j) - cn(i,j)) / \&}
\DoxyCodeLine{817                        (0.5*(cn(i+1,j) + cn(i,j)) + cn\_subro) + \&}
\DoxyCodeLine{818                        g\%IdxCu(i-1,j) * (cn(i,j) - cn(i-1,j)) / \&}
\DoxyCodeLine{819                        (0.5*(cn(i,j) + cn(i-1,j)) + cn\_subro) )}
\DoxyCodeLine{820       df\_dy = 0.5*((g\%CoriolisBu(i,j) + g\%CoriolisBu(i-1,j)) - \&}
\DoxyCodeLine{821                    (g\%CoriolisBu(i,j-1) + g\%CoriolisBu(i-1,j-1))) * g\%IdyT(i,j)}
\DoxyCodeLine{822       dlncn\_dy = 0.5*( g\%IdyCv(i,j) * (cn(i,j+1) - cn(i,j)) / \&}
\DoxyCodeLine{823                        (0.5*(cn(i,j+1) + cn(i,j)) + cn\_subro) + \&}
\DoxyCodeLine{824                        g\%IdyCv(i,j-1) * (cn(i,j) - cn(i,j-1)) / \&}
\DoxyCodeLine{825                        (0.5*(cn(i,j) + cn(i,j-1)) + cn\_subro) )}
\DoxyCodeLine{826       kmag2 = (freq**2 - f2) / (cn(i,j)**2 + cn\_subro**2)}
\DoxyCodeLine{827       \textcolor{keywordflow}{if} (kmag2 > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{828         i\_kmag = 1.0 / sqrt(kmag2)}
\DoxyCodeLine{829         dk\_dt\_kmag(i) = -ifreq * (favg*df\_dx + (freq**2 - f2) * dlncn\_dx) * i\_kmag}
\DoxyCodeLine{830         dl\_dt\_kmag(i) = -ifreq * (favg*df\_dy + (freq**2 - f2) * dlncn\_dy) * i\_kmag}
\DoxyCodeLine{831       \textcolor{keywordflow}{else}}
\DoxyCodeLine{832         dk\_dt\_kmag(i) = 0.0}
\DoxyCodeLine{833         dl\_dt\_kmag(i) = 0.0}
\DoxyCodeLine{834 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{835 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{836 }
\DoxyCodeLine{837     \textcolor{comment}{! Determine the energy fluxes in angular orientation space.}}
\DoxyCodeLine{838     \textcolor{keywordflow}{do} a=asd,aed ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{839       cfl\_ang(i,j,a) = (cos\_angle(a) * dl\_dt\_kmag(i) - sin\_angle(a) * dk\_dt\_kmag(i)) * dt\_angle\_size}
\DoxyCodeLine{840       \textcolor{keywordflow}{if} (abs(cfl\_ang(i,j,a)) > 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{841         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"refract: CFL exceeds 1."}, .true.)}
\DoxyCodeLine{842         \textcolor{keywordflow}{if} (cfl\_ang(i,j,a) > 0.0) \textcolor{keywordflow}{then} ; cfl\_ang(i,j,a) = 1.0 ; \textcolor{keywordflow}{else} ; cfl\_ang(i,j,a) = -1.0 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{843 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{844 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{845 }
\DoxyCodeLine{846     \textcolor{comment}{! Advect in angular space}}
\DoxyCodeLine{847     \textcolor{keywordflow}{if} (.not.use\_ppmang) \textcolor{keywordflow}{then}}
\DoxyCodeLine{848       \textcolor{comment}{! Use simple upwind}}
\DoxyCodeLine{849       \textcolor{keywordflow}{do}  a=0,na ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{850         \textcolor{keywordflow}{if} (cfl\_ang(i,j,a) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{851           flux\_e(i,a) = cfl\_ang(i,j,a) * en2d(i,a)}
\DoxyCodeLine{852         \textcolor{keywordflow}{else}}
\DoxyCodeLine{853           flux\_e(i,a) = cfl\_ang(i,j,a) * en2d(i,a+1)}
\DoxyCodeLine{854 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{855 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{856     \textcolor{keywordflow}{else}}
\DoxyCodeLine{857       \textcolor{comment}{! Use PPM}}
\DoxyCodeLine{858       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{859         \textcolor{keyword}{call }ppm\_angular\_advect(en2d(i,:),cfl\_ang(i,j,:),flux\_e(i,:),nangle,dt,stencil)}
\DoxyCodeLine{860 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{861 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{862 }
\DoxyCodeLine{863   \textcolor{comment}{! Update and copy back to En.}}
\DoxyCodeLine{864     \textcolor{keywordflow}{do} a=1,na ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{865       \textcolor{comment}{!if (En2d(i,a)+(Flux\_E(i,A-1)-Flux\_E(i,A)) < 0.0) then ! for debugging}}
\DoxyCodeLine{866       \textcolor{comment}{!  call MOM\_error(FATAL, "refract: OutFlux>Available")}}
\DoxyCodeLine{867       \textcolor{comment}{!endif}}
\DoxyCodeLine{868       en(i,j,a) = en2d(i,a) + (flux\_e(i,a-1) - flux\_e(i,a))}
\DoxyCodeLine{869 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{870 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a9e8e7b153aef9049c2217658821e3178}\label{namespacemom__internal__tides_a9e8e7b153aef9049c2217658821e3178}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!sum\_en@{sum\_en}}
\index{sum\_en@{sum\_en}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{sum\_en()}{sum\_en()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::sum\+\_\+en (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nangle), intent(in)}]{En,  }\item[{character(len=$\ast$), intent(in)}]{label }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Checks for energy conservation on computational domain. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em en} & The energy density of the internal tides \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em label} & A label to use in error messages \\
\hline
\end{DoxyParams}


Definition at line 594 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{594   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{595   \textcolor{keywordtype}{type}(int\_tide\_CS),      \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure returned by a}}
\DoxyCodeLine{596 \textcolor{comment}{                                           !! previous call to int\_tide\_init.}}
\DoxyCodeLine{597 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,CS\%NAngle)}, \&}
\DoxyCodeLine{598                           \textcolor{keywordtype}{intent(in)} :: En\textcolor{comment}{ !< The energy density of the internal tides [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{599   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)} :: label\textcolor{comment}{ !< A label to use in error messages}}
\DoxyCodeLine{600   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{601 \textcolor{keywordtype}{  real} :: En\_sum   \textcolor{comment}{! The total energy [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{602 \textcolor{keywordtype}{  real} :: tmpForSumming}
\DoxyCodeLine{603   \textcolor{keywordtype}{integer} :: m,fr,a}
\DoxyCodeLine{604   \textcolor{comment}{! real :: En\_sum\_diff, En\_sum\_pdiff}}
\DoxyCodeLine{605   \textcolor{comment}{! character(len=160) :: mesg  ! The text of an error message}}
\DoxyCodeLine{606   \textcolor{comment}{! real :: days}}
\DoxyCodeLine{607 }
\DoxyCodeLine{608   en\_sum = 0.0}
\DoxyCodeLine{609   tmpforsumming = 0.0}
\DoxyCodeLine{610   \textcolor{keywordflow}{do} a=1,cs\%nAngle}
\DoxyCodeLine{611     tmpforsumming = global\_area\_mean(en(:,:,a),g)*g\%areaT\_global}
\DoxyCodeLine{612     en\_sum = en\_sum + tmpforsumming}
\DoxyCodeLine{613 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{614   cs\%En\_sum = en\_sum}
\DoxyCodeLine{615   \textcolor{comment}{!En\_sum\_diff = En\_sum - CS\%En\_sum}}
\DoxyCodeLine{616   \textcolor{comment}{!if (CS\%En\_sum /= 0.0) then}}
\DoxyCodeLine{617   \textcolor{comment}{!  En\_sum\_pdiff= (En\_sum\_diff/CS\%En\_sum)*100.0}}
\DoxyCodeLine{618   \textcolor{comment}{!else}}
\DoxyCodeLine{619   \textcolor{comment}{!  En\_sum\_pdiff= 0.0}}
\DoxyCodeLine{620   \textcolor{comment}{!endif}}
\DoxyCodeLine{621   \textcolor{comment}{!! Print to screen}}
\DoxyCodeLine{622   \textcolor{comment}{!if (is\_root\_pe()) then}}
\DoxyCodeLine{623   \textcolor{comment}{!  days = time\_type\_to\_real(CS\%Time) / 86400.0}}
\DoxyCodeLine{624   \textcolor{comment}{!  write(mesg,*) trim(label)//': days =', days, ', En\_sum=', En\_sum, \&}}
\DoxyCodeLine{625   \textcolor{comment}{!                ', En\_sum\_diff=', En\_sum\_diff, ', Percent change=', En\_sum\_pdiff, '\%'}}
\DoxyCodeLine{626   \textcolor{comment}{!  call MOM\_mesg(mesg)}}
\DoxyCodeLine{627   \textcolor{comment}{!if (is\_root\_pe() .and. (abs(En\_sum\_pdiff) > 1.0)) \&}}
\DoxyCodeLine{628   \textcolor{comment}{!  call MOM\_error(FATAL, "Run stopped due to excessive internal tide energy change.")}}
\DoxyCodeLine{629   \textcolor{comment}{!endif}}
\DoxyCodeLine{630 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a0a20d26531e245a26385d1c056b6a5b6}\label{namespacemom__internal__tides_a0a20d26531e245a26385d1c056b6a5b6}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!teleport@{teleport}}
\index{teleport@{teleport}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{teleport()}{teleport()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::teleport (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Moves energy across lines of partial reflection to prevent reflection of energy that is supposed to get across. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\mbox{\texttt{ in,out}}  & {\em en} & The internal gravity wave energy density as a \\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1710 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1710   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{1711   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: NAngle\textcolor{comment}{ !< The number of wave orientations in the}}
\DoxyCodeLine{1712 \textcolor{comment}{                                              !! discretized wave energy spectrum.}}
\DoxyCodeLine{1713 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed,NAngle)}, \&}
\DoxyCodeLine{1714                           \textcolor{keywordtype}{intent(inout)} :: En\textcolor{comment}{ !< The internal gravity wave energy density as a}}
\DoxyCodeLine{1715 \textcolor{comment}{                                              !! function of space and angular resolution}}
\DoxyCodeLine{1716 \textcolor{comment}{                                              !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1717   \textcolor{keywordtype}{type}(int\_tide\_CS),      \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by a}}
\DoxyCodeLine{1718 \textcolor{comment}{                                              !! previous call to int\_tide\_init.}}
\DoxyCodeLine{1719   \textcolor{keywordtype}{type}(loop\_bounds\_type), \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{ !< A structure with the active energy loop bounds.}}
\DoxyCodeLine{1720   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1721 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)}    :: angle\_c}
\DoxyCodeLine{1722                                               \textcolor{comment}{! angle of boundary wrt equator [rad]}}
\DoxyCodeLine{1723 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)}    :: part\_refl}
\DoxyCodeLine{1724                                               \textcolor{comment}{! fraction of wave energy reflected}}
\DoxyCodeLine{1725                                               \textcolor{comment}{! values should collocate with angle\_c [nondim]}}
\DoxyCodeLine{1726   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)} :: pref\_cell}
\DoxyCodeLine{1727                                               \textcolor{comment}{! flag for partial reflection}}
\DoxyCodeLine{1728   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)} :: ridge}
\DoxyCodeLine{1729                                               \textcolor{comment}{! tags of cells with double reflection}}
\DoxyCodeLine{1730 \textcolor{keywordtype}{  real}                        :: TwoPi      \textcolor{comment}{! 2*pi = 6.2831853... [nondim]}}
\DoxyCodeLine{1731 \textcolor{keywordtype}{  real}                        :: Angle\_size \textcolor{comment}{! size of beam wedge [rad]}}
\DoxyCodeLine{1732 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1:NAngle)}   :: angle\_i    \textcolor{comment}{! angle of incident ray wrt equator [rad]}}
\DoxyCodeLine{1733 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(1:NAngle)}   :: cos\_angle, sin\_angle}
\DoxyCodeLine{1734 \textcolor{keywordtype}{  real}                        :: En\_tele    \textcolor{comment}{! energy to be "teleported" [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{1735   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}}
\DoxyCodeLine{1736   \textcolor{keywordtype}{integer} :: i, j, a}
\DoxyCodeLine{1737   \textcolor{comment}{!integer :: isd, ied, jsd, jed    ! start and end local indices on data domain}}
\DoxyCodeLine{1738   \textcolor{comment}{!                                 ! (values include halos)}}
\DoxyCodeLine{1739   \textcolor{comment}{!integer :: isc, iec, jsc, jec    ! start and end local indices on PE}}
\DoxyCodeLine{1740   \textcolor{comment}{!                                 ! (values exclude halos)}}
\DoxyCodeLine{1741   \textcolor{keywordtype}{integer} :: ish, ieh, jsh, jeh     \textcolor{comment}{! start and end local indices on data domain}}
\DoxyCodeLine{1742                                     \textcolor{comment}{! leaving out outdated halo points (march in)}}
\DoxyCodeLine{1743   \textcolor{keywordtype}{integer} :: id\_g, jd\_g             \textcolor{comment}{! global (decomp-invar) indices}}
\DoxyCodeLine{1744   \textcolor{keywordtype}{integer} :: jos, ios               \textcolor{comment}{! offsets}}
\DoxyCodeLine{1745 \textcolor{keywordtype}{  real}    :: cos\_normal, sin\_normal, angle\_wall}
\DoxyCodeLine{1746                                     \textcolor{comment}{! cos/sin of cross-ridge normal, ridge angle}}
\DoxyCodeLine{1747 }
\DoxyCodeLine{1748   \textcolor{comment}{!isd = G\%isd  ; ied = G\%ied  ; jsd = G\%jsd  ; jed = G\%jed}}
\DoxyCodeLine{1749   \textcolor{comment}{!isc = G\%isc  ; iec = G\%iec  ; jsc = G\%jsc  ; jec = G\%jec}}
\DoxyCodeLine{1750   ish = lb\%ish ; ieh = lb\%ieh ; jsh = lb\%jsh ; jeh = lb\%jeh}
\DoxyCodeLine{1751 }
\DoxyCodeLine{1752   twopi = 8.0*atan(1.0)}
\DoxyCodeLine{1753   angle\_size = twopi / (real(nangle))}
\DoxyCodeLine{1754 }
\DoxyCodeLine{1755   \textcolor{keywordflow}{do} a=1,nangle}
\DoxyCodeLine{1756     \textcolor{comment}{! These are the angles at the cell centers}}
\DoxyCodeLine{1757     \textcolor{comment}{! (should do this elsewhere since doesn't change with time)}}
\DoxyCodeLine{1758     angle\_i(a) = angle\_size * real(a - 1) \textcolor{comment}{! for a=1 aligned with x-axis}}
\DoxyCodeLine{1759     cos\_angle(a) = cos(angle\_i(a)) ; sin\_angle(a) = sin(angle\_i(a))}
\DoxyCodeLine{1760 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1761 }
\DoxyCodeLine{1762   angle\_c   = cs\%refl\_angle}
\DoxyCodeLine{1763   part\_refl = cs\%refl\_pref}
\DoxyCodeLine{1764   pref\_cell = cs\%refl\_pref\_logical}
\DoxyCodeLine{1765   ridge     = cs\%refl\_dbl}
\DoxyCodeLine{1766 }
\DoxyCodeLine{1767   \textcolor{keywordflow}{do} j=jsh,jeh}
\DoxyCodeLine{1768     \textcolor{keywordflow}{do} i=ish,ieh}
\DoxyCodeLine{1769       id\_g = i + g\%idg\_offset ; jd\_g = j + g\%jdg\_offset}
\DoxyCodeLine{1770       \textcolor{keywordflow}{if} (pref\_cell(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1771         \textcolor{keywordflow}{do} a=1,nangle}
\DoxyCodeLine{1772           \textcolor{keywordflow}{if} (en(i,j,a) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1773             \textcolor{comment}{! if ray is incident, keep specified boundary angle}}
\DoxyCodeLine{1774             \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_c(i,j)) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1775               angle\_wall = angle\_c(i,j)}
\DoxyCodeLine{1776             \textcolor{comment}{! if ray is not incident but in ridge cell, use complementary angle}}
\DoxyCodeLine{1777             \textcolor{keywordflow}{elseif} (ridge(i,j)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1778               angle\_wall = angle\_c(i,j) + 0.5*twopi}
\DoxyCodeLine{1779             \textcolor{comment}{! if ray is not incident and not in a ridge cell, keep specified angle}}
\DoxyCodeLine{1780             \textcolor{keywordflow}{else}}
\DoxyCodeLine{1781               angle\_wall = angle\_c(i,j)}
\DoxyCodeLine{1782 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{1783             \textcolor{comment}{! teleport if incident}}
\DoxyCodeLine{1784             \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_wall) >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1785               en\_tele = en(i,j,a)}
\DoxyCodeLine{1786               cos\_normal = cos(angle\_wall + 0.25*twopi)}
\DoxyCodeLine{1787               sin\_normal = sin(angle\_wall + 0.25*twopi)}
\DoxyCodeLine{1788               \textcolor{comment}{! find preferred zonal offset based on shelf/ridge angle}}
\DoxyCodeLine{1789               ios = int(sign(1.,cos\_normal))}
\DoxyCodeLine{1790               \textcolor{comment}{! find preferred meridional offset based on shelf/ridge angle}}
\DoxyCodeLine{1791               jos = int(sign(1.,sin\_normal))}
\DoxyCodeLine{1792               \textcolor{comment}{! find receptive ocean cell in direction of offset}}
\DoxyCodeLine{1793               \textcolor{keywordflow}{if} (.not. pref\_cell(i+ios,j+jos)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1794                 en(i,j,a) = en(i,j,a) - en\_tele}
\DoxyCodeLine{1795                 en(i+ios,j+jos,a) = en(i+ios,j+jos,a) + en\_tele}
\DoxyCodeLine{1796               \textcolor{keywordflow}{else}}
\DoxyCodeLine{1797                 \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'idg='},id\_g,\textcolor{stringliteral}{'jd\_g='},jd\_g,\textcolor{stringliteral}{'a='},a}
\DoxyCodeLine{1798                 \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"teleport: no receptive ocean cell at "}//trim(mesg), .true.)}
\DoxyCodeLine{1799 \textcolor{keywordflow}{              endif}}
\DoxyCodeLine{1800 \textcolor{keywordflow}{            endif} \textcolor{comment}{! incidence check}}
\DoxyCodeLine{1801 \textcolor{keywordflow}{          endif} \textcolor{comment}{! energy check}}
\DoxyCodeLine{1802 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! a-loop}}
\DoxyCodeLine{1803 \textcolor{keywordflow}{      endif} \textcolor{comment}{! pref check}}
\DoxyCodeLine{1804 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i-loop}}
\DoxyCodeLine{1805 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}
\DoxyCodeLine{1806 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a5470c5a9a8fea70664dbf793c48cef65}\label{namespacemom__internal__tides_a5470c5a9a8fea70664dbf793c48cef65}} 
\index{mom\_internal\_tides@{mom\_internal\_tides}!zonal\_flux\_en@{zonal\_flux\_en}}
\index{zonal\_flux\_en@{zonal\_flux\_en}!mom\_internal\_tides@{mom\_internal\_tides}}
\subsubsection{\texorpdfstring{zonal\_flux\_en()}{zonal\_flux\_en()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::zonal\+\_\+flux\+\_\+en (\begin{DoxyParamCaption}\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{hL,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{hR,  }\item[{real, dimension(szib\+\_\+(g)), intent(inout)}]{uh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the zonal mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Energy density used to calculate the fluxes \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em hl} & Left-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em hr} & Right-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em uh} & The zonal energy transport \mbox{[}R Z3 L2 T-\/3 $\sim$$>$ J s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em j} & The j-\/index to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em ish} & The start i-\/index range to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em ieh} & The end i-\/index range to work on. \\
\hline
\mbox{\texttt{ in}}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
\end{DoxyParams}


Definition at line 1516 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1516   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{1517 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{  !< The zonal velocity [L T-1 ~> m s-1].}}
\DoxyCodeLine{1518 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Energy density used to calculate the fluxes}}
\DoxyCodeLine{1519 \textcolor{comment}{                                                 !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1520 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: hL\textcolor{comment}{ !< Left- Energy densities in the reconstruction}}
\DoxyCodeLine{1521 \textcolor{comment}{                                                 !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1522 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: hR\textcolor{comment}{ !< Right- Energy densities in the reconstruction}}
\DoxyCodeLine{1523 \textcolor{comment}{                                                 !! [R Z3 T-2 ~> J m-2].}}
\DoxyCodeLine{1524 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{ !< The zonal energy transport [R Z3 L2 T-3 ~> J s-1].}}
\DoxyCodeLine{1525 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{1526   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1527   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{  !< The j-index to work on.}}
\DoxyCodeLine{1528   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{ !< The start i-index range to work on.}}
\DoxyCodeLine{1529   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{ !< The end i-index range to work on.}}
\DoxyCodeLine{1530   \textcolor{keywordtype}{logical},                   \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{ !< If true, rescale the ratio of face areas to}}
\DoxyCodeLine{1531 \textcolor{comment}{                                                 !! the cell areas when estimating the CFL number.}}
\DoxyCodeLine{1532   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1533 \textcolor{keywordtype}{  real} :: CFL  \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim].}}
\DoxyCodeLine{1534 \textcolor{keywordtype}{  real} :: curv\_3 \textcolor{comment}{! A measure of the energy density curvature over a grid length [R Z3 T-2 ~> J m-2]}}
\DoxyCodeLine{1535   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{1536 }
\DoxyCodeLine{1537   \textcolor{keywordflow}{do} i=ish-1,ieh}
\DoxyCodeLine{1538     \textcolor{comment}{! Set new values of uh and duhdu.}}
\DoxyCodeLine{1539     \textcolor{keywordflow}{if} (u(i) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1540       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (u(i) * dt) * (g\%dy\_Cu(i,j) * g\%IareaT(i,j))}
\DoxyCodeLine{1541       \textcolor{keywordflow}{else} ; cfl = u(i) * dt * g\%IdxT(i,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1542       curv\_3 = (hl(i) + hr(i)) - 2.0*h(i)}
\DoxyCodeLine{1543       uh(i) = g\%dy\_Cu(i,j) * u(i) * \&}
\DoxyCodeLine{1544           (hr(i) + cfl * (0.5*(hl(i) - hr(i)) + curv\_3*(cfl - 1.5)))}
\DoxyCodeLine{1545     \textcolor{keywordflow}{elseif} (u(i) < 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1546       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-u(i) * dt) * (g\%dy\_Cu(i,j) * g\%IareaT(i+1,j))}
\DoxyCodeLine{1547       \textcolor{keywordflow}{else} ; cfl = -u(i) * dt * g\%IdxT(i+1,j) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1548       curv\_3 = (hl(i+1) + hr(i+1)) - 2.0*h(i+1)}
\DoxyCodeLine{1549       uh(i) = g\%dy\_Cu(i,j) * u(i) * \&}
\DoxyCodeLine{1550           (hl(i+1) + cfl * (0.5*(hr(i+1)-hl(i+1)) + curv\_3*(cfl - 1.5)))}
\DoxyCodeLine{1551     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1552       uh(i) = 0.0}
\DoxyCodeLine{1553 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1554 \textcolor{keywordflow}{  enddo}}

\end{DoxyCode}
