\hypertarget{namespacemom__tidal__forcing}{}\doxysection{mom\+\_\+tidal\+\_\+forcing Module Reference}
\label{namespacemom__tidal__forcing}\index{mom\_tidal\_forcing@{mom\_tidal\_forcing}}


\doxysubsection{Detailed Description}
Tidal contributions to geopotential. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__tidal__forcing_1_1astro__longitudes}{astro\+\_\+longitudes}}
\begin{DoxyCompactList}\small\item\em Simple type to store astronomical longitudes used to calculate tidal phases. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__tidal__forcing_1_1tidal__forcing__cs}{tidal\+\_\+forcing\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em The control structure for the M\+O\+M\+\_\+tidal\+\_\+forcing module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__tidal__forcing_a216df16546377aec2e546a0c26956320}\label{namespacemom__tidal__forcing_a216df16546377aec2e546a0c26956320}} 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__forcing_a216df16546377aec2e546a0c26956320}{astro\+\_\+longitudes\+\_\+init}} (time\+\_\+ref, longitudes)
\begin{DoxyCompactList}\small\item\em Finds astronomical longitudes s, h, p, and N, the mean longitude of the moon, sun, lunar perigee, and ascending node, respectively, at the specified reference time time\+\_\+ref. These formulas were obtained from Kowalik and Luick, \char`\"{}\+Modern Theory and Practice of Tide Analysis and Tidal Power\char`\"{}, 2019 (their Equation I.\+71), which are based on Schureman, 1958. For simplicity, the time associated with time\+\_\+ref should be at midnight. These formulas also only make sense if the calendar is gregorian. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__forcing_a75df5ae8ba197cf0cc5584811a28c8c1}\label{namespacemom__tidal__forcing_a75df5ae8ba197cf0cc5584811a28c8c1}} 
real function, public \mbox{\hyperlink{namespacemom__tidal__forcing_a75df5ae8ba197cf0cc5584811a28c8c1}{eq\+\_\+phase}} (constit, longitudes)
\begin{DoxyCompactList}\small\item\em Calculates the equilibrium phase argument for the given tidal constituent constit and the astronomical longitudes and the reference time. These formulas follow Table I.\+4 of Kowalik and Luick, \char`\"{}\+Modern Theory and Practice of Tide Analysis and Tidal Power\char`\"{}, 2019. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__forcing_a2f0cdbf6e53e72de468abc458b820ae4}\label{namespacemom__tidal__forcing_a2f0cdbf6e53e72de468abc458b820ae4}} 
real function, public \mbox{\hyperlink{namespacemom__tidal__forcing_a2f0cdbf6e53e72de468abc458b820ae4}{tidal\+\_\+frequency}} (constit)
\begin{DoxyCompactList}\small\item\em Looks up angular frequencies for the main tidal constituents. Values used here are from previous versions of M\+OM. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__forcing_a7bec47c17487d1676e6a64b0729c43b4}\label{namespacemom__tidal__forcing_a7bec47c17487d1676e6a64b0729c43b4}} 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__forcing_a7bec47c17487d1676e6a64b0729c43b4}{nodal\+\_\+fu}} (constit, N, fn, un)
\begin{DoxyCompactList}\small\item\em Find amplitude (f) and phase (u) modulation of tidal constituents by the 18.\+6 year nodal cycle. Values here follow Table I.\+6 in Kowalik and Luick, \char`\"{}\+Modern Theory and Practice of Tide Analysis and Tidal Power\char`\"{}, 2019. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__forcing_aee336a2affeebc78b75845bc6f78a320}{tidal\+\_\+forcing\+\_\+init}} (Time, G, param\+\_\+file, CS)
\begin{DoxyCompactList}\small\item\em This subroutine allocates space for the static variables used by this module. The metrics may be effectively 0, 1, or 2-\/D arrays, while fields like the background viscosities are 2-\/D arrays. A\+L\+L\+OC is a macro defined in \mbox{\hyperlink{MOM__memory_8h}{M\+O\+M\+\_\+memory.\+h}} for allocate or nothing with static memory. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__forcing_a5347fc1f0287018220ceb65d46fc89f9}{find\+\_\+in\+\_\+files}} (filenames, varname, array, G)
\begin{DoxyCompactList}\small\item\em This subroutine finds a named variable in a list of files and reads its values into a domain-\/decomposed 2-\/d array. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__forcing_a0a1564c68489a35802c626a07f4629d7}{tidal\+\_\+forcing\+\_\+sensitivity}} (G, CS, deta\+\_\+tidal\+\_\+deta)
\begin{DoxyCompactList}\small\item\em This subroutine calculates returns the partial derivative of the local geopotential height with the input sea surface height due to self-\/attraction and loading. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__forcing_a9614ae35fac1d880d5daacbd60f3d47a}{calc\+\_\+tidal\+\_\+forcing}} (Time, eta, eta\+\_\+tidal, G, CS, deta\+\_\+tidal\+\_\+deta, m\+\_\+to\+\_\+Z)
\begin{DoxyCompactList}\small\item\em This subroutine calculates the geopotential anomalies that drive the tides, including self-\/attraction and loading. Optionally, it also returns the partial derivative of the local geopotential height with the input sea surface height. For now, eta and eta\+\_\+tidal are both geopotential heights in depth units, but probably the input for eta should really be replaced with the column mass anomalies. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__forcing_a317fadb5312795722889e8ec5cec4dcb}{tidal\+\_\+forcing\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates memory associated with the tidal forcing module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__tidal__forcing_a9d0f13c449127ecf48932f449bd4993f}\label{namespacemom__tidal__forcing_a9d0f13c449127ecf48932f449bd4993f}} 
integer, parameter \mbox{\hyperlink{namespacemom__tidal__forcing_a9d0f13c449127ecf48932f449bd4993f}{max\+\_\+constituents}} = 10
\begin{DoxyCompactList}\small\item\em The maximum number of tidal constituents that could be used. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__forcing_a44caffc5bf5443b16b448cc79cb6680b}\label{namespacemom__tidal__forcing_a44caffc5bf5443b16b448cc79cb6680b}} 
integer \mbox{\hyperlink{namespacemom__tidal__forcing_a44caffc5bf5443b16b448cc79cb6680b}{id\+\_\+clock\+\_\+tides}}
\begin{DoxyCompactList}\small\item\em C\+PU clock for tides. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tidal__forcing_a9614ae35fac1d880d5daacbd60f3d47a}\label{namespacemom__tidal__forcing_a9614ae35fac1d880d5daacbd60f3d47a}} 
\index{mom\_tidal\_forcing@{mom\_tidal\_forcing}!calc\_tidal\_forcing@{calc\_tidal\_forcing}}
\index{calc\_tidal\_forcing@{calc\_tidal\_forcing}!mom\_tidal\_forcing@{mom\_tidal\_forcing}}
\doxysubsubsection{\texorpdfstring{calc\_tidal\_forcing()}{calc\_tidal\_forcing()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+forcing\+::calc\+\_\+tidal\+\_\+forcing (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{eta,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{eta\+\_\+tidal,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__tidal__forcing_1_1tidal__forcing__cs}{tidal\+\_\+forcing\+\_\+cs}}), pointer}]{CS,  }\item[{real, intent(out), optional}]{deta\+\_\+tidal\+\_\+deta,  }\item[{real, intent(in), optional}]{m\+\_\+to\+\_\+Z }\end{DoxyParamCaption})}



This subroutine calculates the geopotential anomalies that drive the tides, including self-\/attraction and loading. Optionally, it also returns the partial derivative of the local geopotential height with the input sea surface height. For now, eta and eta\+\_\+tidal are both geopotential heights in depth units, but probably the input for eta should really be replaced with the column mass anomalies. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em time} & The time for the caluculation. \\
\hline
\mbox{\texttt{ in}}  & {\em eta} & The sea surface height anomaly from a time-\/mean geoid \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em eta\+\_\+tidal} & The tidal forcing geopotential height anomalies \mbox{[}Z $\sim$$>$ m\mbox{]}. \\
\hline
 & {\em cs} & The control structure returned by a previous call to tidal\+\_\+forcing\+\_\+init. \\
\hline
\mbox{\texttt{ out}}  & {\em deta\+\_\+tidal\+\_\+deta} & The partial derivative of eta\+\_\+tidal with the local value of eta \mbox{[}nondim\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em m\+\_\+to\+\_\+z} & A scaling factor from m to the units of eta. \\
\hline
\end{DoxyParams}


Definition at line 582 of file M\+O\+M\+\_\+tidal\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{583   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{         !< The ocean's grid structure.}}
\DoxyCodeLine{584   \textcolor{keywordtype}{type}(time\_type),                  \textcolor{keywordtype}{intent(in)}  :: Time\textcolor{comment}{      !< The time for the caluculation.}}
\DoxyCodeLine{585 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: eta\textcolor{comment}{       !< The sea surface height anomaly from}}
\DoxyCodeLine{586 \textcolor{comment}{                                                             !! a time-\/mean geoid [Z \string~> m].}}
\DoxyCodeLine{587 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: eta\_tidal\textcolor{comment}{ !< The tidal forcing geopotential height}}
\DoxyCodeLine{588 \textcolor{comment}{                                                             !! anomalies [Z \string~> m].}}
\DoxyCodeLine{589   \textcolor{keywordtype}{type}(tidal\_forcing\_CS),           \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{        !< The control structure returned by a}}
\DoxyCodeLine{590 \textcolor{comment}{                                                             !! previous call to tidal\_forcing\_init.}}
\DoxyCodeLine{591 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},                   \textcolor{keywordtype}{intent(out)} :: deta\_tidal\_deta\textcolor{comment}{ !< The partial derivative of}}
\DoxyCodeLine{592 \textcolor{comment}{                                                             !! eta\_tidal with the local value of}}
\DoxyCodeLine{593 \textcolor{comment}{                                                             !! eta [nondim].}}
\DoxyCodeLine{594 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},                   \textcolor{keywordtype}{intent(in)}  :: m\_to\_Z\textcolor{comment}{    !< A scaling factor from m to the units of eta.}}
\DoxyCodeLine{595 }
\DoxyCodeLine{596   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{597 \textcolor{keywordtype}{  real} :: now       \textcolor{comment}{! The relative time in seconds.}}
\DoxyCodeLine{598 \textcolor{keywordtype}{  real} :: amp\_cosomegat, amp\_sinomegat}
\DoxyCodeLine{599 \textcolor{keywordtype}{  real} :: cosomegat, sinomegat}
\DoxyCodeLine{600 \textcolor{keywordtype}{  real} :: m\_Z       \textcolor{comment}{! A scaling factor from m to depth units.}}
\DoxyCodeLine{601 \textcolor{keywordtype}{  real} :: eta\_prop  \textcolor{comment}{! The nondimenional constant of proportionality beteen eta and eta\_tidal.}}
\DoxyCodeLine{602   \textcolor{keywordtype}{integer} :: i, j, c, m, is, ie, js, je, Isq, Ieq, Jsq, Jeq}
\DoxyCodeLine{603   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{604   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{605 }
\DoxyCodeLine{606   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{607 }
\DoxyCodeLine{608   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_tides)}
\DoxyCodeLine{609 }
\DoxyCodeLine{610   \textcolor{keywordflow}{if} (cs\%nc == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{611     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1 ; eta\_tidal(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{612     \textcolor{keywordflow}{return}}
\DoxyCodeLine{613 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{614 }
\DoxyCodeLine{615   now = time\_type\_to\_real(time -\/ cs\%time\_ref)}
\DoxyCodeLine{616 }
\DoxyCodeLine{617   \textcolor{keywordflow}{if} (cs\%USE\_SAL\_SCALAR .and. cs\%USE\_PREV\_TIDES) \textcolor{keywordflow}{then}}
\DoxyCodeLine{618     eta\_prop = 2.0*cs\%SAL\_SCALAR}
\DoxyCodeLine{619   \textcolor{keywordflow}{elseif} (cs\%USE\_SAL\_SCALAR .or. cs\%USE\_PREV\_TIDES) \textcolor{keywordflow}{then}}
\DoxyCodeLine{620     eta\_prop = cs\%SAL\_SCALAR}
\DoxyCodeLine{621   \textcolor{keywordflow}{else}}
\DoxyCodeLine{622     eta\_prop = 0.0}
\DoxyCodeLine{623 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{624 }
\DoxyCodeLine{625   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(deta\_tidal\_deta)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{626     deta\_tidal\_deta = eta\_prop}
\DoxyCodeLine{627     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1 ; eta\_tidal(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{628   \textcolor{keywordflow}{else}}
\DoxyCodeLine{629     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{630       eta\_tidal(i,j) = eta\_prop*eta(i,j)}
\DoxyCodeLine{631 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{632 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{633 }
\DoxyCodeLine{634   m\_z = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(m\_to\_z)) m\_z = m\_to\_z}
\DoxyCodeLine{635 }
\DoxyCodeLine{636   \textcolor{keywordflow}{do} c=1,cs\%nc}
\DoxyCodeLine{637     m = cs\%struct(c)}
\DoxyCodeLine{638     amp\_cosomegat = m\_z*cs\%amp(c)*cs\%love\_no(c) * cos(cs\%freq(c)*now + cs\%phase0(c))}
\DoxyCodeLine{639     amp\_sinomegat = m\_z*cs\%amp(c)*cs\%love\_no(c) * sin(cs\%freq(c)*now + cs\%phase0(c))}
\DoxyCodeLine{640     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{641       eta\_tidal(i,j) = eta\_tidal(i,j) + (amp\_cosomegat*cs\%cos\_struct(i,j,m) + \&}
\DoxyCodeLine{642                                          amp\_sinomegat*cs\%sin\_struct(i,j,m))}
\DoxyCodeLine{643 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{644 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{645 }
\DoxyCodeLine{646   \textcolor{keywordflow}{if} (cs\%tidal\_sal\_from\_file) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} c=1,cs\%nc}
\DoxyCodeLine{647     cosomegat = cos(cs\%freq(c)*now)}
\DoxyCodeLine{648     sinomegat = sin(cs\%freq(c)*now)}
\DoxyCodeLine{649     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{650       eta\_tidal(i,j) = eta\_tidal(i,j) + m\_z*cs\%ampsal(i,j,c) * \&}
\DoxyCodeLine{651            (cosomegat*cs\%cosphasesal(i,j,c) + sinomegat*cs\%sinphasesal(i,j,c))}
\DoxyCodeLine{652 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{653 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{654 }
\DoxyCodeLine{655   \textcolor{keywordflow}{if} (cs\%USE\_PREV\_TIDES) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} c=1,cs\%nc}
\DoxyCodeLine{656     cosomegat = cos(cs\%freq(c)*now)}
\DoxyCodeLine{657     sinomegat = sin(cs\%freq(c)*now)}
\DoxyCodeLine{658     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1}
\DoxyCodeLine{659       eta\_tidal(i,j) = eta\_tidal(i,j) -\/ m\_z*cs\%SAL\_SCALAR*cs\%amp\_prev(i,j,c) * \&}
\DoxyCodeLine{660           (cosomegat*cs\%cosphase\_prev(i,j,c) + sinomegat*cs\%sinphase\_prev(i,j,c))}
\DoxyCodeLine{661 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{662 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{663 }
\DoxyCodeLine{664   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_tides)}
\DoxyCodeLine{665 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__forcing_a5347fc1f0287018220ceb65d46fc89f9}\label{namespacemom__tidal__forcing_a5347fc1f0287018220ceb65d46fc89f9}} 
\index{mom\_tidal\_forcing@{mom\_tidal\_forcing}!find\_in\_files@{find\_in\_files}}
\index{find\_in\_files@{find\_in\_files}!mom\_tidal\_forcing@{mom\_tidal\_forcing}}
\doxysubsubsection{\texorpdfstring{find\_in\_files()}{find\_in\_files()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+forcing\+::find\+\_\+in\+\_\+files (\begin{DoxyParamCaption}\item[{character(len=$\ast$), dimension(\+:), intent(in)}]{filenames,  }\item[{character(len=$\ast$), intent(in)}]{varname,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{array,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine finds a named variable in a list of files and reads its values into a domain-\/decomposed 2-\/d array. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em filenames} & The names of the files to search for the named variable \\
\hline
\mbox{\texttt{ in}}  & {\em varname} & The name of the variable to read \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ out}}  & {\em array} & The array to fill with the data \\
\hline
\end{DoxyParams}


Definition at line 529 of file M\+O\+M\+\_\+tidal\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{530   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: filenames\textcolor{comment}{ !< The names of the files to search for the named variable}}
\DoxyCodeLine{531   \textcolor{keywordtype}{character(len=*)},                 \textcolor{keywordtype}{intent(in)}  :: varname\textcolor{comment}{   !< The name of the variable to read}}
\DoxyCodeLine{532   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{         !< The ocean's grid structure}}
\DoxyCodeLine{533 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: array\textcolor{comment}{     !< The array to fill with the data}}
\DoxyCodeLine{534   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{535   \textcolor{keywordtype}{integer} :: nf}
\DoxyCodeLine{536 }
\DoxyCodeLine{537   \textcolor{keywordflow}{do} nf=1,\textcolor{keyword}{size}(filenames)}
\DoxyCodeLine{538     \textcolor{keywordflow}{if} (len\_trim(filenames(nf)) == 0) cycle}
\DoxyCodeLine{539     \textcolor{keywordflow}{if} (field\_exists(filenames(nf), varname, g\%Domain\%mpp\_domain)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{540       \textcolor{keyword}{call }mom\_read\_data(filenames(nf), varname, array, g\%Domain)}
\DoxyCodeLine{541       \textcolor{keywordflow}{return}}
\DoxyCodeLine{542 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{543 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{544 }
\DoxyCodeLine{545   \textcolor{keywordflow}{do} nf=\textcolor{keyword}{size}(filenames),1,-\/1}
\DoxyCodeLine{546     \textcolor{keywordflow}{if} (file\_exists(filenames(nf), g\%Domain)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{547       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tidal\_forcing.F90: Unable to find "}// \&}
\DoxyCodeLine{548          trim(varname)//\textcolor{stringliteral}{" in any of the tidal input files, last tried "}// \&}
\DoxyCodeLine{549          trim(filenames(nf)))}
\DoxyCodeLine{550 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{551 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{552 }
\DoxyCodeLine{553   \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tidal\_forcing.F90: Unable to find any of the "}// \&}
\DoxyCodeLine{554                   \textcolor{stringliteral}{"tidal input files, including "}//trim(filenames(1)))}
\DoxyCodeLine{555 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__forcing_a317fadb5312795722889e8ec5cec4dcb}\label{namespacemom__tidal__forcing_a317fadb5312795722889e8ec5cec4dcb}} 
\index{mom\_tidal\_forcing@{mom\_tidal\_forcing}!tidal\_forcing\_end@{tidal\_forcing\_end}}
\index{tidal\_forcing\_end@{tidal\_forcing\_end}!mom\_tidal\_forcing@{mom\_tidal\_forcing}}
\doxysubsubsection{\texorpdfstring{tidal\_forcing\_end()}{tidal\_forcing\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+forcing\+::tidal\+\_\+forcing\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__tidal__forcing_1_1tidal__forcing__cs}{tidal\+\_\+forcing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine deallocates memory associated with the tidal forcing module. 


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


Definition at line 669 of file M\+O\+M\+\_\+tidal\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{670   \textcolor{keywordtype}{type}(tidal\_forcing\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< The control structure returned by a previous call}}
\DoxyCodeLine{671 \textcolor{comment}{                                        !! to tidal\_forcing\_init; it is deallocated here.}}
\DoxyCodeLine{672 }
\DoxyCodeLine{673   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%sin\_struct)) \textcolor{keyword}{deallocate}(cs\%sin\_struct)}
\DoxyCodeLine{674   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%cos\_struct)) \textcolor{keyword}{deallocate}(cs\%cos\_struct)}
\DoxyCodeLine{675 }
\DoxyCodeLine{676   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%cosphasesal)) \textcolor{keyword}{deallocate}(cs\%cosphasesal)}
\DoxyCodeLine{677   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%sinphasesal)) \textcolor{keyword}{deallocate}(cs\%sinphasesal)}
\DoxyCodeLine{678   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%ampsal))      \textcolor{keyword}{deallocate}(cs\%ampsal)}
\DoxyCodeLine{679 }
\DoxyCodeLine{680   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%cosphase\_prev)) \textcolor{keyword}{deallocate}(cs\%cosphase\_prev)}
\DoxyCodeLine{681   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%sinphase\_prev)) \textcolor{keyword}{deallocate}(cs\%sinphase\_prev)}
\DoxyCodeLine{682   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%amp\_prev))      \textcolor{keyword}{deallocate}(cs\%amp\_prev)}
\DoxyCodeLine{683 }
\DoxyCodeLine{684   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{685 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__forcing_aee336a2affeebc78b75845bc6f78a320}\label{namespacemom__tidal__forcing_aee336a2affeebc78b75845bc6f78a320}} 
\index{mom\_tidal\_forcing@{mom\_tidal\_forcing}!tidal\_forcing\_init@{tidal\_forcing\_init}}
\index{tidal\_forcing\_init@{tidal\_forcing\_init}!mom\_tidal\_forcing@{mom\_tidal\_forcing}}
\doxysubsubsection{\texorpdfstring{tidal\_forcing\_init()}{tidal\_forcing\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+forcing\+::tidal\+\_\+forcing\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__tidal__forcing_1_1tidal__forcing__cs}{tidal\+\_\+forcing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine allocates space for the static variables used by this module. The metrics may be effectively 0, 1, or 2-\/D arrays, while fields like the background viscosities are 2-\/D arrays. A\+L\+L\+OC is a macro defined in \mbox{\hyperlink{MOM__memory_8h}{M\+O\+M\+\_\+memory.\+h}} for allocate or nothing with static memory. 


\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 param\+\_\+file} & A structure to parse for run-\/time parameters. \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 229 of file M\+O\+M\+\_\+tidal\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{230   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< The current model time.}}
\DoxyCodeLine{231   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{232   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-\/time parameters.}}
\DoxyCodeLine{233   \textcolor{keywordtype}{type}(tidal\_forcing\_CS), \textcolor{keywordtype}{pointer}      :: CS\textcolor{comment}{   !< A pointer that is set to point to the control}}
\DoxyCodeLine{234 \textcolor{comment}{                                               !! structure for this module.}}
\DoxyCodeLine{235   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{236 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: \&}
\DoxyCodeLine{237     phase, \&          \textcolor{comment}{! The phase of some tidal constituent.}}
\DoxyCodeLine{238     lat\_rad, lon\_rad  \textcolor{comment}{! Latitudes and longitudes of h-\/points in radians.}}
\DoxyCodeLine{239 \textcolor{keywordtype}{  real} :: deg\_to\_rad}
\DoxyCodeLine{240 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(MAX\_CONSTITUENTS)} :: freq\_def, phase0\_def, amp\_def, love\_def}
\DoxyCodeLine{241   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(3)} :: tide\_ref\_date\textcolor{comment}{ !< Reference date (t = 0) for tidal forcing.}}
\DoxyCodeLine{242   \textcolor{keywordtype}{logical} :: use\_const  \textcolor{comment}{! True if a constituent is being used.}}
\DoxyCodeLine{243   \textcolor{keywordtype}{logical} :: use\_M2, use\_S2, use\_N2, use\_K2, use\_K1, use\_O1, use\_P1, use\_Q1}
\DoxyCodeLine{244   \textcolor{keywordtype}{logical} :: use\_MF, use\_MM}
\DoxyCodeLine{245   \textcolor{keywordtype}{logical} :: tides      \textcolor{comment}{! True if a tidal forcing is to be used.}}
\DoxyCodeLine{246   \textcolor{keywordtype}{logical} :: FAIL\_IF\_MISSING = .true.}
\DoxyCodeLine{247 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{248 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{249 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_tidal\_forcing"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{250   \textcolor{keywordtype}{character(len=128)} :: mesg}
\DoxyCodeLine{251   \textcolor{keywordtype}{character(len=200)} :: tidal\_input\_files(4*MAX\_CONSTITUENTS)}
\DoxyCodeLine{252   \textcolor{keywordtype}{integer} :: i, j, c, is, ie, js, je, isd, ied, jsd, jed, nc}
\DoxyCodeLine{253   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{254   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd; jed = g\%jed}
\DoxyCodeLine{255 }
\DoxyCodeLine{256   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{257     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"tidal\_forcing\_init called with an associated "}// \&}
\DoxyCodeLine{258                             \textcolor{stringliteral}{"control structure."})}
\DoxyCodeLine{259     \textcolor{keywordflow}{return}}
\DoxyCodeLine{260 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{261 }
\DoxyCodeLine{262   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{263   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{264   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDES"}, tides, \&}
\DoxyCodeLine{265                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing."}, default=.false.)}
\DoxyCodeLine{266 }
\DoxyCodeLine{267   \textcolor{keywordflow}{if} (.not.tides) \textcolor{keywordflow}{return}}
\DoxyCodeLine{268 }
\DoxyCodeLine{269   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{270 }
\DoxyCodeLine{271   \textcolor{comment}{! Set up the spatial structure functions for the diurnal, semidiurnal, and}}
\DoxyCodeLine{272   \textcolor{comment}{! low-\/frequency tidal components.}}
\DoxyCodeLine{273   \textcolor{keyword}{allocate}(cs\%sin\_struct(isd:ied,jsd:jed,3)) ; cs\%sin\_struct(:,:,:) = 0.0}
\DoxyCodeLine{274   \textcolor{keyword}{allocate}(cs\%cos\_struct(isd:ied,jsd:jed,3)) ; cs\%cos\_struct(:,:,:) = 0.0}
\DoxyCodeLine{275   deg\_to\_rad = 4.0*atan(1.0)/180.0}
\DoxyCodeLine{276   \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{277     lat\_rad(i,j) = g\%geoLatT(i,j)*deg\_to\_rad}
\DoxyCodeLine{278     lon\_rad(i,j) = g\%geoLonT(i,j)*deg\_to\_rad}
\DoxyCodeLine{279 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{280   \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{281     cs\%sin\_struct(i,j,1) = -\/sin(2.0*lat\_rad(i,j)) * sin(lon\_rad(i,j))}
\DoxyCodeLine{282     cs\%cos\_struct(i,j,1) =  sin(2.0*lat\_rad(i,j)) * cos(lon\_rad(i,j))}
\DoxyCodeLine{283     cs\%sin\_struct(i,j,2) = -\/cos(lat\_rad(i,j))**2 * sin(2.0*lon\_rad(i,j))}
\DoxyCodeLine{284     cs\%cos\_struct(i,j,2) =  cos(lat\_rad(i,j))**2 * cos(2.0*lon\_rad(i,j))}
\DoxyCodeLine{285     cs\%sin\_struct(i,j,3) =  0.0}
\DoxyCodeLine{286     cs\%cos\_struct(i,j,3) = (0.5-\/1.5*sin(lat\_rad(i,j))**2)}
\DoxyCodeLine{287 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{288 }
\DoxyCodeLine{289   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_M2"}, use\_m2, \&}
\DoxyCodeLine{290                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the M2 "}//\&}
\DoxyCodeLine{291                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{292                  default=.false.)}
\DoxyCodeLine{293   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_S2"}, use\_s2, \&}
\DoxyCodeLine{294                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the S2 "}//\&}
\DoxyCodeLine{295                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{296                  default=.false.)}
\DoxyCodeLine{297   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_N2"}, use\_n2, \&}
\DoxyCodeLine{298                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the N2 "}//\&}
\DoxyCodeLine{299                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{300                  default=.false.)}
\DoxyCodeLine{301   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_K2"}, use\_k2, \&}
\DoxyCodeLine{302                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the K2 "}//\&}
\DoxyCodeLine{303                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{304                  default=.false.)}
\DoxyCodeLine{305   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_K1"}, use\_k1, \&}
\DoxyCodeLine{306                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the K1 "}//\&}
\DoxyCodeLine{307                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{308                  default=.false.)}
\DoxyCodeLine{309   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_O1"}, use\_o1, \&}
\DoxyCodeLine{310                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the O1 "}//\&}
\DoxyCodeLine{311                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{312                  default=.false.)}
\DoxyCodeLine{313   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_P1"}, use\_p1, \&}
\DoxyCodeLine{314                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the P1 "}//\&}
\DoxyCodeLine{315                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{316                  default=.false.)}
\DoxyCodeLine{317   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_Q1"}, use\_q1, \&}
\DoxyCodeLine{318                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the Q1 "}//\&}
\DoxyCodeLine{319                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{320                  default=.false.)}
\DoxyCodeLine{321   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_MF"}, use\_mf, \&}
\DoxyCodeLine{322                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the MF "}//\&}
\DoxyCodeLine{323                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{324                  default=.false.)}
\DoxyCodeLine{325   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_MM"}, use\_mm, \&}
\DoxyCodeLine{326                  \textcolor{stringliteral}{"If true, apply tidal momentum forcing at the MM "}//\&}
\DoxyCodeLine{327                  \textcolor{stringliteral}{"frequency. This is only used if TIDES is true."}, \&}
\DoxyCodeLine{328                  default=.false.)}
\DoxyCodeLine{329 }
\DoxyCodeLine{330   \textcolor{comment}{! Determine how many tidal components are to be used.}}
\DoxyCodeLine{331   nc = 0}
\DoxyCodeLine{332   \textcolor{keywordflow}{if} (use\_m2) nc=nc+1 ; \textcolor{keywordflow}{if} (use\_s2) nc=nc+1}
\DoxyCodeLine{333   \textcolor{keywordflow}{if} (use\_n2) nc=nc+1 ; \textcolor{keywordflow}{if} (use\_k2) nc=nc+1}
\DoxyCodeLine{334   \textcolor{keywordflow}{if} (use\_k1) nc=nc+1 ; \textcolor{keywordflow}{if} (use\_o1) nc=nc+1}
\DoxyCodeLine{335   \textcolor{keywordflow}{if} (use\_p1) nc=nc+1 ; \textcolor{keywordflow}{if} (use\_q1) nc=nc+1}
\DoxyCodeLine{336   \textcolor{keywordflow}{if} (use\_mf) nc=nc+1 ; \textcolor{keywordflow}{if} (use\_mm) nc=nc+1}
\DoxyCodeLine{337   cs\%nc = nc}
\DoxyCodeLine{338 }
\DoxyCodeLine{339   \textcolor{keywordflow}{if} (nc == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{340     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_forcing\_init: "}// \&}
\DoxyCodeLine{341         \textcolor{stringliteral}{"TIDES are defined, but no tidal constituents are used."})}
\DoxyCodeLine{342     \textcolor{keywordflow}{return}}
\DoxyCodeLine{343 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{344 }
\DoxyCodeLine{345   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_SAL\_FROM\_FILE"}, cs\%tidal\_sal\_from\_file, \&}
\DoxyCodeLine{346                  \textcolor{stringliteral}{"If true, read the tidal self-\/attraction and loading "}//\&}
\DoxyCodeLine{347                  \textcolor{stringliteral}{"from input files, specified by TIDAL\_INPUT\_FILE. "}//\&}
\DoxyCodeLine{348                  \textcolor{stringliteral}{"This is only used if TIDES is true."}, default=.false.)}
\DoxyCodeLine{349   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_PREVIOUS\_TIDES"}, cs\%use\_prev\_tides, \&}
\DoxyCodeLine{350                  \textcolor{stringliteral}{"If true, use the SAL from the previous iteration of the "}//\&}
\DoxyCodeLine{351                  \textcolor{stringliteral}{"tides to facilitate convergent iteration. "}//\&}
\DoxyCodeLine{352                  \textcolor{stringliteral}{"This is only used if TIDES is true."}, default=.false.)}
\DoxyCodeLine{353   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_USE\_SAL\_SCALAR"}, cs\%use\_sal\_scalar, \&}
\DoxyCodeLine{354                  \textcolor{stringliteral}{"If true and TIDES is true, use the scalar approximation "}//\&}
\DoxyCodeLine{355                  \textcolor{stringliteral}{"when calculating self-\/attraction and loading."}, \&}
\DoxyCodeLine{356                  default=.not.cs\%tidal\_sal\_from\_file)}
\DoxyCodeLine{357   \textcolor{comment}{! If it is being used, sal\_scalar MUST be specified in param\_file.}}
\DoxyCodeLine{358   \textcolor{keywordflow}{if} (cs\%use\_sal\_scalar .or. cs\%use\_prev\_tides) \&}
\DoxyCodeLine{359     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_SAL\_SCALAR\_VALUE"}, cs\%sal\_scalar, \&}
\DoxyCodeLine{360                  \textcolor{stringliteral}{"The constant of proportionality between sea surface "}//\&}
\DoxyCodeLine{361                  \textcolor{stringliteral}{"height (really it should be bottom pressure) anomalies "}//\&}
\DoxyCodeLine{362                  \textcolor{stringliteral}{"and bottom geopotential anomalies. This is only used if "}//\&}
\DoxyCodeLine{363                  \textcolor{stringliteral}{"TIDES and TIDE\_USE\_SAL\_SCALAR are true."}, units=\textcolor{stringliteral}{"m m-\/1"}, \&}
\DoxyCodeLine{364                  fail\_if\_missing=.true.)}
\DoxyCodeLine{365 }
\DoxyCodeLine{366   \textcolor{keywordflow}{if} (nc > max\_constituents) \textcolor{keywordflow}{then}}
\DoxyCodeLine{367     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Increase MAX\_CONSTITUENTS in MOM\_tidal\_forcing.F90 to at least",I3, \&}}
\DoxyCodeLine{368 \textcolor{stringliteral}{}\textcolor{stringliteral}{                \&"to accommodate all the registered tidal constituents.")'}) nc}
\DoxyCodeLine{369     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tidal\_forcing"}//mesg)}
\DoxyCodeLine{370 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{371 }
\DoxyCodeLine{372   \textcolor{keywordflow}{do} c=1,4*max\_constituents ; tidal\_input\_files(c) = \textcolor{stringliteral}{""} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{373 }
\DoxyCodeLine{374   \textcolor{keywordflow}{if} (cs\%tidal\_sal\_from\_file .or. cs\%use\_prev\_tides) \textcolor{keywordflow}{then}}
\DoxyCodeLine{375     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_INPUT\_FILE"}, tidal\_input\_files, \&}
\DoxyCodeLine{376                    \textcolor{stringliteral}{"A list of input files for tidal information."},         \&}
\DoxyCodeLine{377                    default = \textcolor{stringliteral}{""}, fail\_if\_missing=.true.)}
\DoxyCodeLine{378 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{379 }
\DoxyCodeLine{380   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_REF\_DATE"}, tide\_ref\_date, \&}
\DoxyCodeLine{381                  \textcolor{stringliteral}{"Year,month,day to use as reference date for tidal forcing. "}//\&}
\DoxyCodeLine{382                  \textcolor{stringliteral}{"If not specified, defaults to 0."}, \&}
\DoxyCodeLine{383                  default=0)}
\DoxyCodeLine{384 }
\DoxyCodeLine{385   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_USE\_EQ\_PHASE"}, cs\%use\_eq\_phase, \&}
\DoxyCodeLine{386                  \textcolor{stringliteral}{"Correct phases by calculating equilibrium phase arguments for TIDE\_REF\_DATE. "}, \&}
\DoxyCodeLine{387                  default=.false., fail\_if\_missing=.false.)}
\DoxyCodeLine{388 }
\DoxyCodeLine{389   \textcolor{keywordflow}{if} (sum(tide\_ref\_date) == 0) \textcolor{keywordflow}{then}  \textcolor{comment}{! tide\_ref\_date defaults to 0.}}
\DoxyCodeLine{390     cs\%time\_ref = set\_date(1, 1, 1)}
\DoxyCodeLine{391   \textcolor{keywordflow}{else}}
\DoxyCodeLine{392     \textcolor{keywordflow}{if}(.not. cs\%use\_eq\_phase) \textcolor{keywordflow}{then}}
\DoxyCodeLine{393       \textcolor{comment}{! Using a reference date but not using phase relative to equilibrium.}}
\DoxyCodeLine{394       \textcolor{comment}{! This makes sense as long as either phases are overridden, or}}
\DoxyCodeLine{395       \textcolor{comment}{! correctly simulating tidal phases is not desired.}}
\DoxyCodeLine{396       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{'Tidal phases will *not* be corrected with equilibrium arguments.'})}
\DoxyCodeLine{397 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{398     cs\%time\_ref = set\_date(tide\_ref\_date(1), tide\_ref\_date(2), tide\_ref\_date(3))}
\DoxyCodeLine{399 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{400   \textcolor{comment}{! Set the parameters for all components that are in use.}}
\DoxyCodeLine{401   \textcolor{comment}{! Initialize reference time for tides and}}
\DoxyCodeLine{402   \textcolor{comment}{! find relevant lunar and solar longitudes at the reference time.}}
\DoxyCodeLine{403   \textcolor{keywordflow}{if} (cs\%use\_eq\_phase) \textcolor{keyword}{call }astro\_longitudes\_init(cs\%time\_ref, cs\%tidal\_longitudes)}
\DoxyCodeLine{404   c=0}
\DoxyCodeLine{405   \textcolor{keywordflow}{if} (use\_m2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{406     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"M2"} ; cs\%struct(c) = 2}
\DoxyCodeLine{407     cs\%love\_no(c) = 0.693 ; cs\%amp(c) = 0.242334}
\DoxyCodeLine{408 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{409 }
\DoxyCodeLine{410   \textcolor{keywordflow}{if} (use\_s2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{411     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"S2"} ; cs\%struct(c) = 2}
\DoxyCodeLine{412     cs\%love\_no(c) = 0.693 ; cs\%amp(c) = 0.112743}
\DoxyCodeLine{413 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{414 }
\DoxyCodeLine{415   \textcolor{keywordflow}{if} (use\_n2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{416     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"N2"} ; cs\%struct(c) = 2}
\DoxyCodeLine{417     cs\%love\_no(c) = 0.693 ; cs\%amp(c) = 0.046397}
\DoxyCodeLine{418 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{419 }
\DoxyCodeLine{420   \textcolor{keywordflow}{if} (use\_k2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{421     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"K2"} ; cs\%struct(c) = 2}
\DoxyCodeLine{422     cs\%love\_no(c) = 0.693 ; cs\%amp(c) = 0.030684}
\DoxyCodeLine{423 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{424 }
\DoxyCodeLine{425   \textcolor{keywordflow}{if} (use\_k1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{426     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"K1"} ; cs\%struct(c) = 1}
\DoxyCodeLine{427     cs\%love\_no(c) = 0.736 ; cs\%amp(c) = 0.141565}
\DoxyCodeLine{428 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{429 }
\DoxyCodeLine{430   \textcolor{keywordflow}{if} (use\_o1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{431     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"O1"} ; cs\%struct(c) = 1}
\DoxyCodeLine{432     cs\%love\_no(c) = 0.695 ; cs\%amp(c) = 0.100661}
\DoxyCodeLine{433 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{434 }
\DoxyCodeLine{435   \textcolor{keywordflow}{if} (use\_p1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{436     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"P1"} ; cs\%struct(c) = 1}
\DoxyCodeLine{437     cs\%love\_no(c) = 0.706 ; cs\%amp(c) = 0.046848}
\DoxyCodeLine{438 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{439 }
\DoxyCodeLine{440   \textcolor{keywordflow}{if} (use\_q1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{441     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"Q1"} ; cs\%struct(c) = 1}
\DoxyCodeLine{442     cs\%love\_no(c) = 0.695 ; cs\%amp(c) = 0.019273}
\DoxyCodeLine{443 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{444 }
\DoxyCodeLine{445   \textcolor{keywordflow}{if} (use\_mf) \textcolor{keywordflow}{then}}
\DoxyCodeLine{446     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"MF"} ; cs\%struct(c) = 3}
\DoxyCodeLine{447     cs\%love\_no(c) = 0.693 ; cs\%amp(c) = 0.042041}
\DoxyCodeLine{448 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{449 }
\DoxyCodeLine{450   \textcolor{keywordflow}{if} (use\_mm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{451     c=c+1 ; cs\%const\_name(c) = \textcolor{stringliteral}{"MM"} ; cs\%struct(c) = 3}
\DoxyCodeLine{452     cs\%love\_no(c) = 0.693 ; cs\%amp(c) = 0.022191}
\DoxyCodeLine{453 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{454 }
\DoxyCodeLine{455   \textcolor{comment}{! Set defaults for all included constituents}}
\DoxyCodeLine{456   \textcolor{comment}{! and things that can be set by functions}}
\DoxyCodeLine{457   \textcolor{keywordflow}{do} c=1,nc}
\DoxyCodeLine{458     cs\%freq(c) = tidal\_frequency(cs\%const\_name(c))}
\DoxyCodeLine{459     freq\_def(c) = cs\%freq(c)}
\DoxyCodeLine{460     love\_def(c) = cs\%love\_no(c)}
\DoxyCodeLine{461     amp\_def(c) = cs\%amp(c)}
\DoxyCodeLine{462     cs\%phase0(c) = 0.0}
\DoxyCodeLine{463     \textcolor{keywordflow}{if} (cs\%use\_eq\_phase) \textcolor{keywordflow}{then}}
\DoxyCodeLine{464       phase0\_def(c) = eq\_phase(cs\%const\_name(c), cs\%tidal\_longitudes)}
\DoxyCodeLine{465     \textcolor{keywordflow}{else}}
\DoxyCodeLine{466       phase0\_def(c) = 0.0}
\DoxyCodeLine{467 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{468 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{469 }
\DoxyCodeLine{470   \textcolor{comment}{!  Parse the input file to potentially override the default values for the}}
\DoxyCodeLine{471   \textcolor{comment}{! frequency, amplitude and initial phase of each constituent, and log the}}
\DoxyCodeLine{472   \textcolor{comment}{! values that are actually used.}}
\DoxyCodeLine{473   \textcolor{keywordflow}{do} c=1,nc}
\DoxyCodeLine{474     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_"}//trim(cs\%const\_name(c))//\textcolor{stringliteral}{"\_FREQ"}, cs\%freq(c), \&}
\DoxyCodeLine{475                    \textcolor{stringliteral}{"Frequency of the "}//trim(cs\%const\_name(c))//\textcolor{stringliteral}{" tidal constituent. "}//\&}
\DoxyCodeLine{476                    \textcolor{stringliteral}{"This is only used if TIDES and TIDE\_"}//trim(cs\%const\_name(c))// \&}
\DoxyCodeLine{477                    \textcolor{stringliteral}{" are true, or if OBC\_TIDE\_N\_CONSTITUENTS > 0 and "}//trim(cs\%const\_name(c))// \&}
\DoxyCodeLine{478                    \textcolor{stringliteral}{" is in OBC\_TIDE\_CONSTITUENTS."}, units=\textcolor{stringliteral}{"s-\/1"}, default=freq\_def(c))}
\DoxyCodeLine{479     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_"}//trim(cs\%const\_name(c))//\textcolor{stringliteral}{"\_AMP"}, cs\%amp(c), \&}
\DoxyCodeLine{480                    \textcolor{stringliteral}{"Amplitude of the "}//trim(cs\%const\_name(c))//\textcolor{stringliteral}{" tidal constituent. "}//\&}
\DoxyCodeLine{481                    \textcolor{stringliteral}{"This is only used if TIDES and TIDE\_"}//trim(cs\%const\_name(c))// \&}
\DoxyCodeLine{482                    \textcolor{stringliteral}{" are true."}, units=\textcolor{stringliteral}{"m"}, default=amp\_def(c))}
\DoxyCodeLine{483     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_"}//trim(cs\%const\_name(c))//\textcolor{stringliteral}{"\_PHASE\_T0"}, cs\%phase0(c), \&}
\DoxyCodeLine{484                    \textcolor{stringliteral}{"Phase of the "}//trim(cs\%const\_name(c))//\textcolor{stringliteral}{" tidal constituent at time 0. "}//\&}
\DoxyCodeLine{485                    \textcolor{stringliteral}{"This is only used if TIDES and TIDE\_"}//trim(cs\%const\_name(c))// \&}
\DoxyCodeLine{486                    \textcolor{stringliteral}{" are true."}, units=\textcolor{stringliteral}{"radians"}, default=phase0\_def(c))}
\DoxyCodeLine{487 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{488 }
\DoxyCodeLine{489   \textcolor{keywordflow}{if} (cs\%tidal\_sal\_from\_file) \textcolor{keywordflow}{then}}
\DoxyCodeLine{490     \textcolor{keyword}{allocate}(cs\%cosphasesal(isd:ied,jsd:jed,nc))}
\DoxyCodeLine{491     \textcolor{keyword}{allocate}(cs\%sinphasesal(isd:ied,jsd:jed,nc))}
\DoxyCodeLine{492     \textcolor{keyword}{allocate}(cs\%ampsal(isd:ied,jsd:jed,nc))}
\DoxyCodeLine{493     \textcolor{keywordflow}{do} c=1,nc}
\DoxyCodeLine{494       \textcolor{comment}{! Read variables with names like PHASE\_SAL\_M2 and AMP\_SAL\_M2.}}
\DoxyCodeLine{495       \textcolor{keyword}{call }find\_in\_files(tidal\_input\_files,\textcolor{stringliteral}{"PHASE\_SAL\_"}//trim(cs\%const\_name(c)),phase,g)}
\DoxyCodeLine{496       \textcolor{keyword}{call }find\_in\_files(tidal\_input\_files,\textcolor{stringliteral}{"AMP\_SAL\_"}//trim(cs\%const\_name(c)),cs\%ampsal(:,:,c),g)}
\DoxyCodeLine{497       \textcolor{keyword}{call }pass\_var(phase,           g\%domain,complete=.false.)}
\DoxyCodeLine{498       \textcolor{keyword}{call }pass\_var(cs\%ampsal(:,:,c),g\%domain,complete=.true.)}
\DoxyCodeLine{499       \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{500         cs\%cosphasesal(i,j,c) = cos(phase(i,j)*deg\_to\_rad)}
\DoxyCodeLine{501         cs\%sinphasesal(i,j,c) = sin(phase(i,j)*deg\_to\_rad)}
\DoxyCodeLine{502 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{503 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{504 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{505 }
\DoxyCodeLine{506   \textcolor{keywordflow}{if} (cs\%USE\_PREV\_TIDES) \textcolor{keywordflow}{then}}
\DoxyCodeLine{507     \textcolor{keyword}{allocate}(cs\%cosphase\_prev(isd:ied,jsd:jed,nc))}
\DoxyCodeLine{508     \textcolor{keyword}{allocate}(cs\%sinphase\_prev(isd:ied,jsd:jed,nc))}
\DoxyCodeLine{509     \textcolor{keyword}{allocate}(cs\%amp\_prev(isd:ied,jsd:jed,nc))}
\DoxyCodeLine{510     \textcolor{keywordflow}{do} c=1,nc}
\DoxyCodeLine{511       \textcolor{comment}{! Read variables with names like PHASE\_PREV\_M2 and AMP\_PREV\_M2.}}
\DoxyCodeLine{512       \textcolor{keyword}{call }find\_in\_files(tidal\_input\_files,\textcolor{stringliteral}{"PHASE\_PREV\_"}//trim(cs\%const\_name(c)),phase,g)}
\DoxyCodeLine{513       \textcolor{keyword}{call }find\_in\_files(tidal\_input\_files,\textcolor{stringliteral}{"AMP\_PREV\_"}//trim(cs\%const\_name(c)),cs\%amp\_prev(:,:,c),g)}
\DoxyCodeLine{514       \textcolor{keyword}{call }pass\_var(phase,             g\%domain,complete=.false.)}
\DoxyCodeLine{515       \textcolor{keyword}{call }pass\_var(cs\%amp\_prev(:,:,c),g\%domain,complete=.true.)}
\DoxyCodeLine{516       \textcolor{keywordflow}{do} j=js-\/1,je+1 ; \textcolor{keywordflow}{do} i=is-\/1,ie+1}
\DoxyCodeLine{517         cs\%cosphase\_prev(i,j,c) = cos(phase(i,j)*deg\_to\_rad)}
\DoxyCodeLine{518         cs\%sinphase\_prev(i,j,c) = sin(phase(i,j)*deg\_to\_rad)}
\DoxyCodeLine{519 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{520 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{521 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{522 }
\DoxyCodeLine{523   id\_clock\_tides = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tides)'}, grain=clock\_module)}
\DoxyCodeLine{524 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__forcing_a0a1564c68489a35802c626a07f4629d7}\label{namespacemom__tidal__forcing_a0a1564c68489a35802c626a07f4629d7}} 
\index{mom\_tidal\_forcing@{mom\_tidal\_forcing}!tidal\_forcing\_sensitivity@{tidal\_forcing\_sensitivity}}
\index{tidal\_forcing\_sensitivity@{tidal\_forcing\_sensitivity}!mom\_tidal\_forcing@{mom\_tidal\_forcing}}
\doxysubsubsection{\texorpdfstring{tidal\_forcing\_sensitivity()}{tidal\_forcing\_sensitivity()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+forcing\+::tidal\+\_\+forcing\+\_\+sensitivity (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__tidal__forcing_1_1tidal__forcing__cs}{tidal\+\_\+forcing\+\_\+cs}}), pointer}]{CS,  }\item[{real, intent(out)}]{deta\+\_\+tidal\+\_\+deta }\end{DoxyParamCaption})}



This subroutine calculates returns the partial derivative of the local geopotential height with the input sea surface height due to self-\/attraction and loading. 


\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 tidal\+\_\+forcing\+\_\+init. \\
\hline
\mbox{\texttt{ out}}  & {\em deta\+\_\+tidal\+\_\+deta} & The partial derivative of eta\+\_\+tidal with the local value of eta \mbox{[}nondim\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 561 of file M\+O\+M\+\_\+tidal\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{562   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{563   \textcolor{keywordtype}{type}(tidal\_forcing\_CS), \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{ !< The control structure returned by a previous call to tidal\_forcing\_init.}}
\DoxyCodeLine{564 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{intent(out)} :: deta\_tidal\_deta\textcolor{comment}{ !< The partial derivative of eta\_tidal with}}
\DoxyCodeLine{565 \textcolor{comment}{                                            !! the local value of eta [nondim].}}
\DoxyCodeLine{566 }
\DoxyCodeLine{567   \textcolor{keywordflow}{if} (cs\%USE\_SAL\_SCALAR .and. cs\%USE\_PREV\_TIDES) \textcolor{keywordflow}{then}}
\DoxyCodeLine{568     deta\_tidal\_deta = 2.0*cs\%SAL\_SCALAR}
\DoxyCodeLine{569   \textcolor{keywordflow}{elseif} (cs\%USE\_SAL\_SCALAR .or. cs\%USE\_PREV\_TIDES) \textcolor{keywordflow}{then}}
\DoxyCodeLine{570     deta\_tidal\_deta = cs\%SAL\_SCALAR}
\DoxyCodeLine{571   \textcolor{keywordflow}{else}}
\DoxyCodeLine{572     deta\_tidal\_deta = 0.0}
\DoxyCodeLine{573 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
