\hypertarget{namespacemom__controlled__forcing}{}\doxysection{mom\+\_\+controlled\+\_\+forcing Module Reference}
\label{namespacemom__controlled__forcing}\index{mom\_controlled\_forcing@{mom\_controlled\_forcing}}


\doxysubsection{Detailed Description}
Use control-\/theory to adjust the surface heat flux and precipitation. 


\begin{DoxyItemize}
\item By Robert Hallberg, July 2011 $\ast$
\item This program contains the subroutines that use control-\/theory $\ast$ to adjust the surface heat flux and precipitation, based on the $\ast$ time-\/mean or periodically (seasonally) varying anomalies from the $\ast$ observed state. The techniques behind this are described in $\ast$ Hallberg and Adcroft (2011, in prep.). $\ast$
\item Macros written all in capital letters are defined in \mbox{\hyperlink{MOM__memory_8h}{M\+O\+M\+\_\+memory.\+h}}. $\ast$
\item A small fragment of the grid is shown below\+: $\ast$
\item j+1 x $^\wedge$ x $^\wedge$ x At x\+: q $\ast$ j+1 $>$ o $>$ o $>$ At $^\wedge$\+: v, tauy $\ast$ j x $^\wedge$ x $^\wedge$ x At $>$\+: u, taux $\ast$ j $>$ o $>$ o $>$ At o\+: h, fluxes. $\ast$ j-\/1 x $^\wedge$ x $^\wedge$ x $\ast$ i-\/1 i i+1 At x \& $^\wedge$\+: $\ast$ i i+1 At $>$ \& o\+: $\ast$
\item The boundaries always run through q grid points (x). $\ast$

Adjustments are based on the time-\/mean or periodically (seasonally) varying anomalies from the observed state.

The techniques behind this are described in Hallberg and Adcroft (2018, in prep.). 
\end{DoxyItemize}\doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__controlled__forcing_1_1ctrl__forcing__cs}{ctrl\+\_\+forcing\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for M\+O\+M\+\_\+controlled\+\_\+forcing. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__controlled__forcing_a3428c4ca0349d4aad6f5523ffa45f39f}{apply\+\_\+ctrl\+\_\+forcing}} (S\+S\+T\+\_\+anom, S\+S\+S\+\_\+anom, S\+S\+S\+\_\+mean, virt\+\_\+heat, virt\+\_\+precip, day\+\_\+start, dt, G, US, CS)
\begin{DoxyCompactList}\small\item\em This subroutine calls any of the other subroutines in this file that are needed to specify the current surface forcing fields. \end{DoxyCompactList}\item 
integer function \mbox{\hyperlink{namespacemom__controlled__forcing_a610583f048e5478ad2cd608dd5de8e00}{periodic\+\_\+int}} (rval, num\+\_\+period)
\begin{DoxyCompactList}\small\item\em This function maps rval into an integer in the range from 1 to num\+\_\+period. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__controlled__forcing_a61d129cf3590af06823330a566d23fd6}{periodic\+\_\+real}} (rval, num\+\_\+period)
\begin{DoxyCompactList}\small\item\em This function shifts rval by an integer multiple of num\+\_\+period so that 0 $<$= val\+\_\+out $<$ num\+\_\+period. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__controlled__forcing_a8bfffde62f6a555439eba94884a1fc2e}{register\+\_\+ctrl\+\_\+forcing\+\_\+restarts}} (G, param\+\_\+file, CS, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em This subroutine is used to allocate and register any fields in this module that should be written to or read from the restart file. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__controlled__forcing_ad6a7f0b55a1a5144ffad5eac879cf72e}{controlled\+\_\+forcing\+\_\+init}} (Time, G, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Set up this modules control structure. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__controlled__forcing_a901171da887e79ad1a1adaff49370193}{controlled\+\_\+forcing\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clean up this modules control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__controlled__forcing_a3428c4ca0349d4aad6f5523ffa45f39f}\label{namespacemom__controlled__forcing_a3428c4ca0349d4aad6f5523ffa45f39f}} 
\index{mom\_controlled\_forcing@{mom\_controlled\_forcing}!apply\_ctrl\_forcing@{apply\_ctrl\_forcing}}
\index{apply\_ctrl\_forcing@{apply\_ctrl\_forcing}!mom\_controlled\_forcing@{mom\_controlled\_forcing}}
\doxysubsubsection{\texorpdfstring{apply\_ctrl\_forcing()}{apply\_ctrl\_forcing()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+controlled\+\_\+forcing\+::apply\+\_\+ctrl\+\_\+forcing (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{S\+S\+T\+\_\+anom,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{S\+S\+S\+\_\+anom,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{S\+S\+S\+\_\+mean,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{virt\+\_\+heat,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{virt\+\_\+precip,  }\item[{type(time\+\_\+type), intent(in)}]{day\+\_\+start,  }\item[{real, intent(in)}]{dt,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__controlled__forcing_1_1ctrl__forcing__cs}{ctrl\+\_\+forcing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine calls any of the other subroutines in this file that are needed to specify the current surface forcing fields. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em sst\+\_\+anom} & The sea surface temperature anomalies \mbox{[}degC\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em sss\+\_\+anom} & The sea surface salinity anomlies \mbox{[}ppt\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em sss\+\_\+mean} & The mean sea surface salinity \mbox{[}ppt\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em virt\+\_\+heat} & Virtual (corrective) heat fluxes that are augmented in this subroutine \mbox{[}W m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em virt\+\_\+precip} & Virtual (corrective) precipitation fluxes that are augmented in this subroutine \mbox{[}kg m-\/2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em day\+\_\+start} & Start time of the fluxes. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Length of time over which these fluxes will be applied \mbox{[}s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & A pointer to the control structure returned by a previous call to ctrl\+\_\+forcing\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 81 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{83   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{                    !< The ocean's grid structure.}}
\DoxyCodeLine{84 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SST\_anom\textcolor{comment}{  !< The sea surface temperature}}
\DoxyCodeLine{85 \textcolor{comment}{                                                               !! anomalies [degC].}}
\DoxyCodeLine{86 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SSS\_anom\textcolor{comment}{  !< The sea surface salinity}}
\DoxyCodeLine{87 \textcolor{comment}{                                                               !! anomlies [ppt].}}
\DoxyCodeLine{88 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SSS\_mean\textcolor{comment}{  !< The mean sea surface}}
\DoxyCodeLine{89 \textcolor{comment}{                                                               !! salinity [ppt].}}
\DoxyCodeLine{90 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: virt\_heat\textcolor{comment}{ !< Virtual (corrective) heat}}
\DoxyCodeLine{91 \textcolor{comment}{                                                               !! fluxes that are augmented}}
\DoxyCodeLine{92 \textcolor{comment}{                                                               !! in this subroutine [W m-\/2].}}
\DoxyCodeLine{93 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: virt\_precip\textcolor{comment}{ !< Virtual (corrective)}}
\DoxyCodeLine{94 \textcolor{comment}{                                                               !! precipitation fluxes that}}
\DoxyCodeLine{95 \textcolor{comment}{                                                               !! are augmented in this}}
\DoxyCodeLine{96 \textcolor{comment}{                                                               !! subroutine [kg m-\/2 s-\/1].}}
\DoxyCodeLine{97   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{intent(in)}    :: day\_start\textcolor{comment}{      !< Start time of the fluxes.}}
\DoxyCodeLine{98 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{             !< Length of time over which these}}
\DoxyCodeLine{99 \textcolor{comment}{                                                         !! fluxes will be applied [s].}}
\DoxyCodeLine{100   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{             !< A dimensional unit scaling type}}
\DoxyCodeLine{101   \textcolor{keywordtype}{type}(ctrl\_forcing\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{             !< A pointer to the control structure}}
\DoxyCodeLine{102 \textcolor{comment}{                                                         !! returned by a previous call to}}
\DoxyCodeLine{103 \textcolor{comment}{                                                         !! ctrl\_forcing\_init.}}
\DoxyCodeLine{104 \textcolor{comment}{!}}
\DoxyCodeLine{105 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{106     flux\_heat\_x, \&}
\DoxyCodeLine{107     flux\_prec\_x}
\DoxyCodeLine{108 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: \&}
\DoxyCodeLine{109     flux\_heat\_y, \&}
\DoxyCodeLine{110     flux\_prec\_y}
\DoxyCodeLine{111   \textcolor{keywordtype}{type}(time\_type) :: day\_end}
\DoxyCodeLine{112 \textcolor{keywordtype}{  real}    :: coef    \textcolor{comment}{! A heat-\/flux coefficient [m2].}}
\DoxyCodeLine{113 \textcolor{keywordtype}{  real}    :: mr\_st, mr\_end, mr\_mid, mr\_prev, mr\_next}
\DoxyCodeLine{114 \textcolor{keywordtype}{  real}    :: dt\_wt, dt\_heat\_rate, dt\_prec\_rate}
\DoxyCodeLine{115 \textcolor{keywordtype}{  real}    :: dt1\_heat\_rate, dt1\_prec\_rate, dt2\_heat\_rate, dt2\_prec\_rate}
\DoxyCodeLine{116 \textcolor{keywordtype}{  real}    :: wt\_per1, wt\_st, wt\_end, wt\_mid}
\DoxyCodeLine{117   \textcolor{keywordtype}{integer} :: m\_st, m\_end, m\_mid, m\_u1, m\_u2, m\_u3}
\DoxyCodeLine{118   \textcolor{keywordtype}{integer} :: yr, mon, day, hr, min, sec}
\DoxyCodeLine{119   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{120 }
\DoxyCodeLine{121   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{122 }
\DoxyCodeLine{123   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{124   \textcolor{keywordflow}{if} ((cs\%num\_cycle <= 0) .and. (.not.cs\%do\_integrated)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{125 }
\DoxyCodeLine{126   day\_end = day\_start + real\_to\_time(dt)}
\DoxyCodeLine{127 }
\DoxyCodeLine{128   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{129     virt\_heat(i,j) = 0.0 ; virt\_precip(i,j) = 0.0}
\DoxyCodeLine{130 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{131 }
\DoxyCodeLine{132   \textcolor{keywordflow}{if} (cs\%do\_integrated) \textcolor{keywordflow}{then}}
\DoxyCodeLine{133     dt\_heat\_rate = dt * cs\%heat\_int\_rate}
\DoxyCodeLine{134     dt\_prec\_rate = dt * cs\%prec\_int\_rate}
\DoxyCodeLine{135     \textcolor{keyword}{call }pass\_var(cs\%heat\_0, g\%Domain, complete=.false.)}
\DoxyCodeLine{136     \textcolor{keyword}{call }pass\_var(cs\%precip\_0, g\%Domain)}
\DoxyCodeLine{137 }
\DoxyCodeLine{138     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{139       coef = cs\%Len2 * (g\%dy\_Cu(i,j)*g\%IdxCu(i,j))}
\DoxyCodeLine{140       flux\_heat\_x(i,j) = coef * (cs\%heat\_0(i,j) -\/ cs\%heat\_0(i+1,j))}
\DoxyCodeLine{141       flux\_prec\_x(i,j) = coef * (cs\%precip\_0(i,j) -\/ cs\%precip\_0(i+1,j))}
\DoxyCodeLine{142 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{143     \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{144       coef = cs\%Len2 * (g\%dx\_Cv(i,j)*g\%IdyCv(i,j))}
\DoxyCodeLine{145       flux\_heat\_y(i,j) = coef * (cs\%heat\_0(i,j) -\/ cs\%heat\_0(i,j+1))}
\DoxyCodeLine{146       flux\_prec\_y(i,j) = coef * (cs\%precip\_0(i,j) -\/ cs\%precip\_0(i,j+1))}
\DoxyCodeLine{147 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{148     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{149       cs\%heat\_0(i,j) = cs\%heat\_0(i,j) + dt\_heat\_rate * ( \&}
\DoxyCodeLine{150          -\/cs\%lam\_heat*g\%mask2dT(i,j)*sst\_anom(i,j) + \&}
\DoxyCodeLine{151         (us\%m\_to\_L**2*g\%IareaT(i,j) * ((flux\_heat\_x(i-\/1,j) -\/ flux\_heat\_x(i,j)) + \&}
\DoxyCodeLine{152                           (flux\_heat\_y(i,j-\/1) -\/ flux\_heat\_y(i,j))) ) )}
\DoxyCodeLine{153 }
\DoxyCodeLine{154       cs\%precip\_0(i,j) = cs\%precip\_0(i,j) + dt\_prec\_rate * ( \&}
\DoxyCodeLine{155          cs\%lam\_prec * g\%mask2dT(i,j)*(sss\_anom(i,j) / sss\_mean(i,j)) + \&}
\DoxyCodeLine{156         (us\%m\_to\_L**2*g\%IareaT(i,j) * ((flux\_prec\_x(i-\/1,j) -\/ flux\_prec\_x(i,j)) + \&}
\DoxyCodeLine{157                           (flux\_prec\_y(i,j-\/1) -\/ flux\_prec\_y(i,j))) ) )}
\DoxyCodeLine{158 }
\DoxyCodeLine{159       virt\_heat(i,j) = virt\_heat(i,j) + cs\%heat\_0(i,j)}
\DoxyCodeLine{160       virt\_precip(i,j) = virt\_precip(i,j) + cs\%precip\_0(i,j)}
\DoxyCodeLine{161 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{162 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{163 }
\DoxyCodeLine{164   \textcolor{keywordflow}{if} (cs\%num\_cycle > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{165     \textcolor{comment}{! Determine the current period, with values that run from 0 to CS\%num\_cycle.}}
\DoxyCodeLine{166     \textcolor{keyword}{call }get\_date(day\_start, yr, mon, day, hr, min, sec)}
\DoxyCodeLine{167     mr\_st = cs\%num\_cycle * (time\_type\_to\_real(day\_start -\/ set\_date(yr, 1, 1)) / \&}
\DoxyCodeLine{168                    time\_type\_to\_real(set\_date(yr+1, 1, 1) -\/ set\_date(yr, 1, 1)))}
\DoxyCodeLine{169 }
\DoxyCodeLine{170     \textcolor{keyword}{call }get\_date(day\_end, yr, mon, day, hr, min, sec)}
\DoxyCodeLine{171     mr\_end = cs\%num\_cycle * (time\_type\_to\_real(day\_end -\/ set\_date(yr, 1, 1)) / \&}
\DoxyCodeLine{172                    time\_type\_to\_real(set\_date(yr+1, 1, 1) -\/ set\_date(yr, 1, 1)))}
\DoxyCodeLine{173 }
\DoxyCodeLine{174     \textcolor{comment}{! The Chapeau functions are centered at whole integer values that are nominally}}
\DoxyCodeLine{175     \textcolor{comment}{! the end of the month to enable simple conversion from the fractional-\/years times}}
\DoxyCodeLine{176     \textcolor{comment}{! CS\%num\_cycle.}}
\DoxyCodeLine{177 }
\DoxyCodeLine{178     \textcolor{comment}{! The month-\/average temperatures have as an index the month number.}}
\DoxyCodeLine{179 }
\DoxyCodeLine{180     m\_end = periodic\_int(real(ceiling(mr\_end)), cs\%num\_cycle)}
\DoxyCodeLine{181     m\_mid = periodic\_int(real(ceiling(mr\_st)), cs\%num\_cycle)}
\DoxyCodeLine{182     m\_st = periodic\_int(mr\_st, cs\%num\_cycle)}
\DoxyCodeLine{183 }
\DoxyCodeLine{184     mr\_st = periodic\_real(mr\_st, cs\%num\_cycle)}
\DoxyCodeLine{185     mr\_end = periodic\_real(mr\_end, cs\%num\_cycle)}
\DoxyCodeLine{186       \textcolor{comment}{!  mr\_mid = periodic\_real(ceiling(mr\_st), CS\%num\_cycle)}}
\DoxyCodeLine{187     mr\_prev = periodic\_real(real(floor(mr\_st)), cs\%num\_cycle)}
\DoxyCodeLine{188     mr\_next = periodic\_real(real(m\_end), cs\%num\_cycle)}
\DoxyCodeLine{189     \textcolor{keywordflow}{if} (m\_mid == m\_end) \textcolor{keywordflow}{then} ; mr\_mid = mr\_end \textcolor{comment}{! There is only one cell.}}
\DoxyCodeLine{190     \textcolor{keywordflow}{else} ; mr\_mid = periodic\_real(real(m\_mid), cs\%num\_cycle) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{191 }
\DoxyCodeLine{192     \textcolor{comment}{! There may be two cells that run from mr\_st to mr\_mid and mr\_mid to mr\_end.}}
\DoxyCodeLine{193 }
\DoxyCodeLine{194     \textcolor{comment}{! The values of m for weights are all calculated relative to mr\_prev, so}}
\DoxyCodeLine{195     \textcolor{comment}{! check whether mr\_mid, etc., need to be shifted by CS\%num\_cycle, so that these}}
\DoxyCodeLine{196     \textcolor{comment}{! values satisfiy  mr\_prev <= mr\_st < mr\_mid <= mr\_end <= mr\_next.}}
\DoxyCodeLine{197     \textcolor{keywordflow}{if} (mr\_st < mr\_prev) mr\_prev = mr\_prev -\/ cs\%num\_cycle}
\DoxyCodeLine{198     \textcolor{keywordflow}{if} (mr\_mid < mr\_st) mr\_mid = mr\_mid + cs\%num\_cycle}
\DoxyCodeLine{199     \textcolor{keywordflow}{if} (mr\_end < mr\_st) mr\_end = mr\_end + cs\%num\_cycle}
\DoxyCodeLine{200     \textcolor{keywordflow}{if} (mr\_next < mr\_prev) mr\_next = mr\_next + cs\%num\_cycle}
\DoxyCodeLine{201 }
\DoxyCodeLine{202     \textcolor{comment}{!\#\#\# These might be removed later -\/ they are to check the coding.}}
\DoxyCodeLine{203     \textcolor{keywordflow}{if} ((mr\_mid < mr\_st) .or. (mr\_mid > mr\_prev + 1.)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{204           \textcolor{stringliteral}{"{}apply ctrl\_forcing: m\_mid interpolation out of bounds; fix the code."{}})}
\DoxyCodeLine{205     \textcolor{keywordflow}{if} ((mr\_end < mr\_st) .or. (mr\_end > mr\_prev + 2.)) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{206           \textcolor{stringliteral}{"{}apply ctrl\_forcing: m\_end interpolation out of bounds; fix the code."{}})}
\DoxyCodeLine{207     \textcolor{keywordflow}{if} (mr\_end > mr\_next) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{208           \textcolor{stringliteral}{"{}apply ctrl\_forcing: mr\_next interpolation out of bounds; fix the code."{}})}
\DoxyCodeLine{209 }
\DoxyCodeLine{210     wt\_per1 = 1.0}
\DoxyCodeLine{211     \textcolor{keywordflow}{if} (mr\_mid < mr\_end) wt\_per1 = (mr\_mid -\/ mr\_st) / (mr\_end -\/ mr\_st)}
\DoxyCodeLine{212 }
\DoxyCodeLine{213     \textcolor{comment}{! Find the 3 Chapeau-\/function weights, bearing in mind that m\_end may be m\_mid.}}
\DoxyCodeLine{214     wt\_st = wt\_per1 * (1. + (mr\_prev -\/ 0.5*(mr\_st + mr\_mid)))}
\DoxyCodeLine{215     wt\_end = (1.0-\/wt\_per1) * (1. + (0.5*(mr\_end + mr\_mid) -\/ mr\_next))}
\DoxyCodeLine{216     wt\_mid = 1.0 -\/ (wt\_st + wt\_end)}
\DoxyCodeLine{217     \textcolor{keywordflow}{if} ((wt\_st < 0.0) .or. (wt\_end < 0.0) .or. (wt\_mid < 0.0)) \&}
\DoxyCodeLine{218       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}apply\_ctrl\_forcing: Negative m weights"{}})}
\DoxyCodeLine{219     \textcolor{keywordflow}{if} ((wt\_st > 1.0) .or. (wt\_end > 1.0) .or. (wt\_mid > 1.0)) \&}
\DoxyCodeLine{220       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}apply\_ctrl\_forcing: Excessive m weights"{}})}
\DoxyCodeLine{221 }
\DoxyCodeLine{222     \textcolor{comment}{! Add to vert\_heat and vert\_precip.}}
\DoxyCodeLine{223     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{224       virt\_heat(i,j) = virt\_heat(i,j) + (wt\_st * cs\%heat\_cyc(i,j,m\_st) + \&}
\DoxyCodeLine{225                         (wt\_mid * cs\%heat\_cyc(i,j,m\_mid) + \&}
\DoxyCodeLine{226                          wt\_end * cs\%heat\_cyc(i,j,m\_end)))}
\DoxyCodeLine{227       virt\_precip(i,j) = virt\_precip(i,j) + (wt\_st * cs\%precip\_cyc(i,j,m\_st) + \&}
\DoxyCodeLine{228                         (wt\_mid * cs\%precip\_cyc(i,j,m\_mid) + \&}
\DoxyCodeLine{229                          wt\_end * cs\%precip\_cyc(i,j,m\_end)))}
\DoxyCodeLine{230 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{231 }
\DoxyCodeLine{232     \textcolor{comment}{! If different from the last period, take the average and determine the}}
\DoxyCodeLine{233     \textcolor{comment}{! chapeau weighting}}
\DoxyCodeLine{234 }
\DoxyCodeLine{235     \textcolor{comment}{! The Chapeau functions are centered at whole integer values that are nominally}}
\DoxyCodeLine{236     \textcolor{comment}{! the end of the month to enable simple conversion from the fractional-\/years times}}
\DoxyCodeLine{237     \textcolor{comment}{! CS\%num\_cycle.}}
\DoxyCodeLine{238 }
\DoxyCodeLine{239     \textcolor{comment}{! The month-\/average temperatures have as an index the month number, so the averages}}
\DoxyCodeLine{240     \textcolor{comment}{! apply to indicies m\_end and m\_mid.}}
\DoxyCodeLine{241 }
\DoxyCodeLine{242     \textcolor{keywordflow}{if} (cs\%avg\_time(m\_end) <= 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! zero out the averages.}}
\DoxyCodeLine{243       cs\%avg\_time(m\_end) = 0.0}
\DoxyCodeLine{244       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{245         cs\%avg\_SST\_anom(i,j,m\_end) = 0.0}
\DoxyCodeLine{246         cs\%avg\_SSS\_anom(i,j,m\_end) = 0.0 ; cs\%avg\_SSS(i,j,m\_end) = 0.0}
\DoxyCodeLine{247 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{248 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{249     \textcolor{keywordflow}{if} (cs\%avg\_time(m\_mid) <= 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! zero out the averages.}}
\DoxyCodeLine{250       cs\%avg\_time(m\_mid) = 0.0}
\DoxyCodeLine{251       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{252         cs\%avg\_SST\_anom(i,j,m\_mid) = 0.0}
\DoxyCodeLine{253         cs\%avg\_SSS\_anom(i,j,m\_mid) = 0.0 ; cs\%avg\_SSS(i,j,m\_mid) = 0.0}
\DoxyCodeLine{254 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{255 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{256 }
\DoxyCodeLine{257     \textcolor{comment}{! Accumulate the average anomalies for this period.}}
\DoxyCodeLine{258     dt\_wt = wt\_per1 * dt}
\DoxyCodeLine{259     cs\%avg\_time(m\_mid) = cs\%avg\_time(m\_mid) + dt\_wt}
\DoxyCodeLine{260     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{261       cs\%avg\_SST\_anom(i,j,m\_mid) = cs\%avg\_SST\_anom(i,j,m\_mid) + \&}
\DoxyCodeLine{262                                    dt\_wt * g\%mask2dT(i,j) * sst\_anom(i,j)}
\DoxyCodeLine{263       cs\%avg\_SSS\_anom(i,j,m\_mid) = cs\%avg\_SSS\_anom(i,j,m\_mid) + \&}
\DoxyCodeLine{264                                    dt\_wt * g\%mask2dT(i,j) * sss\_anom(i,j)}
\DoxyCodeLine{265       cs\%avg\_SSS(i,j,m\_mid) = cs\%avg\_SSS(i,j,m\_mid) + dt\_wt * sss\_mean(i,j)}
\DoxyCodeLine{266 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{267     \textcolor{keywordflow}{if} (wt\_per1 < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{268       dt\_wt = (1.0-\/wt\_per1) * dt}
\DoxyCodeLine{269       cs\%avg\_time(m\_end) = cs\%avg\_time(m\_end) + dt\_wt}
\DoxyCodeLine{270       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{271         cs\%avg\_SST\_anom(i,j,m\_end) = cs\%avg\_SST\_anom(i,j,m\_end) + \&}
\DoxyCodeLine{272                                      dt\_wt * g\%mask2dT(i,j) * sst\_anom(i,j)}
\DoxyCodeLine{273         cs\%avg\_SSS\_anom(i,j,m\_end) = cs\%avg\_SSS\_anom(i,j,m\_end) + \&}
\DoxyCodeLine{274                                      dt\_wt * g\%mask2dT(i,j) * sss\_anom(i,j)}
\DoxyCodeLine{275         cs\%avg\_SSS(i,j,m\_end) = cs\%avg\_SSS(i,j,m\_end) + dt\_wt * sss\_mean(i,j)}
\DoxyCodeLine{276 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{277 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{278 }
\DoxyCodeLine{279     \textcolor{comment}{! Update the Chapeau magnitudes for 4 cycles ago.}}
\DoxyCodeLine{280     m\_u1 = periodic\_int(m\_st -\/ 4.0, cs\%num\_cycle)}
\DoxyCodeLine{281     m\_u2 = periodic\_int(m\_st -\/ 3.0, cs\%num\_cycle)}
\DoxyCodeLine{282     m\_u3 = periodic\_int(m\_st -\/ 2.0, cs\%num\_cycle)}
\DoxyCodeLine{283 }
\DoxyCodeLine{284     \textcolor{keywordflow}{if} (cs\%avg\_time(m\_u1) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{285       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{286         cs\%avg\_SST\_anom(i,j,m\_u1) = cs\%avg\_SST\_anom(i,j,m\_u1) / cs\%avg\_time(m\_u1)}
\DoxyCodeLine{287         cs\%avg\_SSS\_anom(i,j,m\_u1) = cs\%avg\_SSS\_anom(i,j,m\_u1) / cs\%avg\_time(m\_u1)}
\DoxyCodeLine{288         cs\%avg\_SSS(i,j,m\_u1) = cs\%avg\_SSS(i,j,m\_u1) / cs\%avg\_time(m\_u1)}
\DoxyCodeLine{289 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{290       cs\%avg\_time(m\_u1) = -\/1.0}
\DoxyCodeLine{291 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{292     \textcolor{keywordflow}{if} (cs\%avg\_time(m\_u2) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{293       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{294         cs\%avg\_SST\_anom(i,j,m\_u2) = cs\%avg\_SST\_anom(i,j,m\_u2) / cs\%avg\_time(m\_u2)}
\DoxyCodeLine{295         cs\%avg\_SSS\_anom(i,j,m\_u2) = cs\%avg\_SSS\_anom(i,j,m\_u2) / cs\%avg\_time(m\_u2)}
\DoxyCodeLine{296         cs\%avg\_SSS(i,j,m\_u2) = cs\%avg\_SSS(i,j,m\_u2) / cs\%avg\_time(m\_u2)}
\DoxyCodeLine{297 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{298       cs\%avg\_time(m\_u2) = -\/1.0}
\DoxyCodeLine{299 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{300     \textcolor{keywordflow}{if} (cs\%avg\_time(m\_u3) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{301       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{302         cs\%avg\_SST\_anom(i,j,m\_u3) = cs\%avg\_SST\_anom(i,j,m\_u3) / cs\%avg\_time(m\_u3)}
\DoxyCodeLine{303         cs\%avg\_SSS\_anom(i,j,m\_u3) = cs\%avg\_SSS\_anom(i,j,m\_u3) / cs\%avg\_time(m\_u3)}
\DoxyCodeLine{304         cs\%avg\_SSS(i,j,m\_u3) = cs\%avg\_SSS(i,j,m\_u3) / cs\%avg\_time(m\_u3)}
\DoxyCodeLine{305 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{306       cs\%avg\_time(m\_u3) = -\/1.0}
\DoxyCodeLine{307 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{308 }
\DoxyCodeLine{309     dt1\_heat\_rate = wt\_per1 * dt * cs\%heat\_cyc\_rate}
\DoxyCodeLine{310     dt1\_prec\_rate = wt\_per1 * dt * cs\%prec\_cyc\_rate}
\DoxyCodeLine{311     dt2\_heat\_rate = (1.0-\/wt\_per1) * dt * cs\%heat\_cyc\_rate}
\DoxyCodeLine{312     dt2\_prec\_rate = (1.0-\/wt\_per1) * dt * cs\%prec\_cyc\_rate}
\DoxyCodeLine{313 }
\DoxyCodeLine{314     \textcolor{keywordflow}{if} (wt\_per1 < 1.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{315       \textcolor{keyword}{call }pass\_var(cs\%heat\_cyc(:,:,m\_u2), g\%Domain, complete=.false.)}
\DoxyCodeLine{316       \textcolor{keyword}{call }pass\_var(cs\%precip\_cyc(:,:,m\_u2), g\%Domain, complete=.false.)}
\DoxyCodeLine{317 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{318     \textcolor{keyword}{call }pass\_var(cs\%heat\_cyc(:,:,m\_u1), g\%Domain, complete=.false.)}
\DoxyCodeLine{319     \textcolor{keyword}{call }pass\_var(cs\%precip\_cyc(:,:,m\_u1), g\%Domain)}
\DoxyCodeLine{320 }
\DoxyCodeLine{321     \textcolor{keywordflow}{if} ((cs\%avg\_time(m\_u1) == -\/1.0) .and. (cs\%avg\_time(m\_u2) == -\/1.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{322       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{323         coef = cs\%Len2 * (g\%dy\_Cu(i,j)*g\%IdxCu(i,j))}
\DoxyCodeLine{324         flux\_heat\_x(i,j) = coef * (cs\%heat\_cyc(i,j,m\_u1) -\/ cs\%heat\_cyc(i+1,j,m\_u1))}
\DoxyCodeLine{325         flux\_prec\_x(i,j) = coef * (cs\%precip\_cyc(i,j,m\_u1) -\/ cs\%precip\_cyc(i+1,j,m\_u1))}
\DoxyCodeLine{326 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{327       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{328         coef = cs\%Len2 * (g\%dx\_Cv(i,j)*g\%IdyCv(i,j))}
\DoxyCodeLine{329         flux\_heat\_y(i,j) = coef * (cs\%heat\_cyc(i,j,m\_u1) -\/ cs\%heat\_cyc(i,j+1,m\_u1))}
\DoxyCodeLine{330         flux\_prec\_y(i,j) = coef * (cs\%precip\_cyc(i,j,m\_u1) -\/ cs\%precip\_cyc(i,j+1,m\_u1))}
\DoxyCodeLine{331 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{332       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{333         cs\%heat\_cyc(i,j,m\_u1) = cs\%heat\_cyc(i,j,m\_u1) + dt1\_heat\_rate * ( \&}
\DoxyCodeLine{334            -\/cs\%lam\_cyc\_heat*(cs\%avg\_SST\_anom(i,j,m\_u2) -\/ cs\%avg\_SST\_anom(i,j,m\_u1)) + \&}
\DoxyCodeLine{335           (us\%m\_to\_L**2*g\%IareaT(i,j) * ((flux\_heat\_x(i-\/1,j) -\/ flux\_heat\_x(i,j)) + \&}
\DoxyCodeLine{336                             (flux\_heat\_y(i,j-\/1) -\/ flux\_heat\_y(i,j))) ) )}
\DoxyCodeLine{337 }
\DoxyCodeLine{338         cs\%precip\_cyc(i,j,m\_u1) = cs\%precip\_cyc(i,j,m\_u1) + dt1\_prec\_rate * ( \&}
\DoxyCodeLine{339           cs\%lam\_cyc\_prec * (cs\%avg\_SSS\_anom(i,j,m\_u2) -\/ cs\%avg\_SSS\_anom(i,j,m\_u1)) / \&}
\DoxyCodeLine{340                             (0.5*(cs\%avg\_SSS(i,j,m\_u2) + cs\%avg\_SSS(i,j,m\_u1))) + \&}
\DoxyCodeLine{341           (us\%m\_to\_L**2*g\%IareaT(i,j) * ((flux\_prec\_x(i-\/1,j) -\/ flux\_prec\_x(i,j)) + \&}
\DoxyCodeLine{342                             (flux\_prec\_y(i,j-\/1) -\/ flux\_prec\_y(i,j))) ) )}
\DoxyCodeLine{343 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{344 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{345 }
\DoxyCodeLine{346     \textcolor{keywordflow}{if} ((wt\_per1 < 1.0) .and. (cs\%avg\_time(m\_u1) == -\/1.0) .and. (cs\%avg\_time(m\_u2) == -\/1.0))  \textcolor{keywordflow}{then}}
\DoxyCodeLine{347       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-\/1,ie}
\DoxyCodeLine{348         coef = cs\%Len2 * (g\%dy\_Cu(i,j)*g\%IdxCu(i,j))}
\DoxyCodeLine{349         flux\_heat\_x(i,j) = coef * (cs\%heat\_cyc(i,j,m\_u2) -\/ cs\%heat\_cyc(i+1,j,m\_u2))}
\DoxyCodeLine{350         flux\_prec\_x(i,j) = coef * (cs\%precip\_cyc(i,j,m\_u2) -\/ cs\%precip\_cyc(i+1,j,m\_u2))}
\DoxyCodeLine{351 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{352       \textcolor{keywordflow}{do} j=js-\/1,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{353         coef = cs\%Len2 * (g\%dx\_Cv(i,j)*g\%IdyCv(i,j))}
\DoxyCodeLine{354         flux\_heat\_y(i,j) = coef * (cs\%heat\_cyc(i,j,m\_u2) -\/ cs\%heat\_cyc(i,j+1,m\_u2))}
\DoxyCodeLine{355         flux\_prec\_y(i,j) = coef * (cs\%precip\_cyc(i,j,m\_u2) -\/ cs\%precip\_cyc(i,j+1,m\_u2))}
\DoxyCodeLine{356 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{357       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{358         cs\%heat\_cyc(i,j,m\_u2) = cs\%heat\_cyc(i,j,m\_u2) + dt1\_heat\_rate * ( \&}
\DoxyCodeLine{359          -\/cs\%lam\_cyc\_heat*(cs\%avg\_SST\_anom(i,j,m\_u3) -\/ cs\%avg\_SST\_anom(i,j,m\_u2)) + \&}
\DoxyCodeLine{360           (us\%m\_to\_L**2*g\%IareaT(i,j) * ((flux\_heat\_x(i-\/1,j) -\/ flux\_heat\_x(i,j)) + \&}
\DoxyCodeLine{361                             (flux\_heat\_y(i,j-\/1) -\/ flux\_heat\_y(i,j))) ) )}
\DoxyCodeLine{362 }
\DoxyCodeLine{363         cs\%precip\_cyc(i,j,m\_u2) = cs\%precip\_cyc(i,j,m\_u2) + dt1\_prec\_rate * ( \&}
\DoxyCodeLine{364           cs\%lam\_cyc\_prec * (cs\%avg\_SSS\_anom(i,j,m\_u3) -\/ cs\%avg\_SSS\_anom(i,j,m\_u2)) / \&}
\DoxyCodeLine{365                              (0.5*(cs\%avg\_SSS(i,j,m\_u3) + cs\%avg\_SSS(i,j,m\_u2))) + \&}
\DoxyCodeLine{366           (us\%m\_to\_L**2*g\%IareaT(i,j) * ((flux\_prec\_x(i-\/1,j) -\/ flux\_prec\_x(i,j)) + \&}
\DoxyCodeLine{367                             (flux\_prec\_y(i,j-\/1) -\/ flux\_prec\_y(i,j))) ) )}
\DoxyCodeLine{368 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{369 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{370 }
\DoxyCodeLine{371 \textcolor{keywordflow}{  endif} \textcolor{comment}{! (CS\%num\_cycle > 0)}}
\DoxyCodeLine{372 }

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



Clean up this modules control structure. 


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


Definition at line 564 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{565   \textcolor{keywordtype}{type}(ctrl\_forcing\_CS),    \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< A pointer to the control structure}}
\DoxyCodeLine{566 \textcolor{comment}{                                          !! returned by a previous call to}}
\DoxyCodeLine{567 \textcolor{comment}{                                          !! controlled\_forcing\_init, it will be}}
\DoxyCodeLine{568 \textcolor{comment}{                                          !! deallocated here.}}
\DoxyCodeLine{569 }
\DoxyCodeLine{570   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{571     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%heat\_0))       \textcolor{keyword}{deallocate}(cs\%heat\_0)}
\DoxyCodeLine{572     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%precip\_0))     \textcolor{keyword}{deallocate}(cs\%precip\_0)}
\DoxyCodeLine{573     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%heat\_cyc))     \textcolor{keyword}{deallocate}(cs\%heat\_cyc)}
\DoxyCodeLine{574     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%precip\_cyc))   \textcolor{keyword}{deallocate}(cs\%precip\_cyc)}
\DoxyCodeLine{575     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%avg\_SST\_anom)) \textcolor{keyword}{deallocate}(cs\%avg\_SST\_anom)}
\DoxyCodeLine{576     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%avg\_SSS\_anom)) \textcolor{keyword}{deallocate}(cs\%avg\_SSS\_anom)}
\DoxyCodeLine{577     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%avg\_SSS))      \textcolor{keyword}{deallocate}(cs\%avg\_SSS)}
\DoxyCodeLine{578 }
\DoxyCodeLine{579     \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{580 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{581   cs => null()}
\DoxyCodeLine{582 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__controlled__forcing_ad6a7f0b55a1a5144ffad5eac879cf72e}\label{namespacemom__controlled__forcing_ad6a7f0b55a1a5144ffad5eac879cf72e}} 
\index{mom\_controlled\_forcing@{mom\_controlled\_forcing}!controlled\_forcing\_init@{controlled\_forcing\_init}}
\index{controlled\_forcing\_init@{controlled\_forcing\_init}!mom\_controlled\_forcing@{mom\_controlled\_forcing}}
\doxysubsubsection{\texorpdfstring{controlled\_forcing\_init()}{controlled\_forcing\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+controlled\+\_\+forcing\+::controlled\+\_\+forcing\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(in), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__controlled__forcing_1_1ctrl__forcing__cs}{ctrl\+\_\+forcing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Set up this modules control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values. \\
\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 484 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{485   \textcolor{keywordtype}{type}(time\_type),           \textcolor{keywordtype}{intent(in)} :: Time\textcolor{comment}{       !< The current model time.}}
\DoxyCodeLine{486   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{487   \textcolor{keywordtype}{type}(param\_file\_type),     \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure indicating the}}
\DoxyCodeLine{488 \textcolor{comment}{                                                      !! open file to parse for model}}
\DoxyCodeLine{489 \textcolor{comment}{                                                      !! parameter values.}}
\DoxyCodeLine{490   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{       !< A structure that is used to regulate}}
\DoxyCodeLine{491 \textcolor{comment}{                                                      !! diagnostic output.}}
\DoxyCodeLine{492   \textcolor{keywordtype}{type}(ctrl\_forcing\_CS),     \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{         !< A pointer that is set to point to the}}
\DoxyCodeLine{493 \textcolor{comment}{                                                      !! control structure for this module.}}
\DoxyCodeLine{494 \textcolor{keywordtype}{  real} :: smooth\_len}
\DoxyCodeLine{495   \textcolor{keywordtype}{logical} :: do\_integrated}
\DoxyCodeLine{496   \textcolor{keywordtype}{integer} :: num\_cycle}
\DoxyCodeLine{497 \textcolor{comment}{! This include declares and sets the variable "{}version"{}.}}
\DoxyCodeLine{498 \textcolor{preprocessor}{\#include "{}version\_variable.h"{}}}
\DoxyCodeLine{499 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}MOM\_controlled\_forcing"{}} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{500 }
\DoxyCodeLine{501   \textcolor{comment}{! These should have already been called.}}
\DoxyCodeLine{502   \textcolor{comment}{! call read\_param(param\_file, "{}CTRL\_FORCE\_INTEGRATED"{}, CS\%do\_integrated)}}
\DoxyCodeLine{503   \textcolor{comment}{! call read\_param(param\_file, "{}CTRL\_FORCE\_NUM\_CYCLE"{}, CS\%num\_cycle)}}
\DoxyCodeLine{504 }
\DoxyCodeLine{505   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{506     do\_integrated = cs\%do\_integrated ; num\_cycle = cs\%num\_cycle}
\DoxyCodeLine{507   \textcolor{keywordflow}{else}}
\DoxyCodeLine{508     do\_integrated = .false. ; num\_cycle = 0}
\DoxyCodeLine{509 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{510 }
\DoxyCodeLine{511   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{512   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{"{}"{}})}
\DoxyCodeLine{513   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_INTEGRATED"{}}, do\_integrated, \&}
\DoxyCodeLine{514                  \textcolor{stringliteral}{"{}If true, use a PI controller to determine the surface "{}}//\&}
\DoxyCodeLine{515                  \textcolor{stringliteral}{"{}forcing that is consistent with the observed mean properties."{}}, \&}
\DoxyCodeLine{516                  default=.false.)}
\DoxyCodeLine{517   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_NUM\_CYCLE"{}}, num\_cycle, \&}
\DoxyCodeLine{518                  \textcolor{stringliteral}{"{}The number of cycles per year in the controlled forcing, "{}}//\&}
\DoxyCodeLine{519                  \textcolor{stringliteral}{"{}or 0 for no cyclic forcing."{}}, default=0)}
\DoxyCodeLine{520 }
\DoxyCodeLine{521   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{522 }
\DoxyCodeLine{523   cs\%diag => diag}
\DoxyCodeLine{524 }
\DoxyCodeLine{525   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_HEAT\_INT\_RATE"{}}, cs\%heat\_int\_rate, \&}
\DoxyCodeLine{526                  \textcolor{stringliteral}{"{}The integrated rate at which heat flux anomalies are "{}}//\&}
\DoxyCodeLine{527                  \textcolor{stringliteral}{"{}accumulated."{}}, units=\textcolor{stringliteral}{"{}s-\/1"{}}, default=0.0)}
\DoxyCodeLine{528   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_PREC\_INT\_RATE"{}}, cs\%prec\_int\_rate, \&}
\DoxyCodeLine{529                  \textcolor{stringliteral}{"{}The integrated rate at which precipitation anomalies "{}}//\&}
\DoxyCodeLine{530                  \textcolor{stringliteral}{"{}are accumulated."{}}, units=\textcolor{stringliteral}{"{}s-\/1"{}}, default=0.0)}
\DoxyCodeLine{531   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_HEAT\_CYC\_RATE"{}}, cs\%heat\_cyc\_rate, \&}
\DoxyCodeLine{532                  \textcolor{stringliteral}{"{}The integrated rate at which cyclical heat flux "{}}//\&}
\DoxyCodeLine{533                  \textcolor{stringliteral}{"{}anomalies are accumulated."{}}, units=\textcolor{stringliteral}{"{}s-\/1"{}}, default=0.0)}
\DoxyCodeLine{534   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_PREC\_CYC\_RATE"{}}, cs\%prec\_cyc\_rate, \&}
\DoxyCodeLine{535                  \textcolor{stringliteral}{"{}The integrated rate at which cyclical precipitation "{}}//\&}
\DoxyCodeLine{536                  \textcolor{stringliteral}{"{}anomalies are accumulated."{}}, units=\textcolor{stringliteral}{"{}s-\/1"{}}, default=0.0)}
\DoxyCodeLine{537   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_SMOOTH\_LENGTH"{}}, smooth\_len, \&}
\DoxyCodeLine{538                  \textcolor{stringliteral}{"{}The length scales over which controlled forcing "{}}//\&}
\DoxyCodeLine{539                  \textcolor{stringliteral}{"{}anomalies are smoothed."{}}, units=\textcolor{stringliteral}{"{}m"{}}, default=0.0)}
\DoxyCodeLine{540   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_LAMDA\_HEAT"{}}, cs\%lam\_heat, \&}
\DoxyCodeLine{541                  \textcolor{stringliteral}{"{}A constant of proportionality between SST anomalies "{}}//\&}
\DoxyCodeLine{542                  \textcolor{stringliteral}{"{}and controlling heat fluxes"{}}, \textcolor{stringliteral}{"{}W m-\/2 K-\/1"{}}, default=0.0)}
\DoxyCodeLine{543   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_LAMDA\_PREC"{}}, cs\%lam\_prec, \&}
\DoxyCodeLine{544                  \textcolor{stringliteral}{"{}A constant of proportionality between SSS anomalies "{}}//\&}
\DoxyCodeLine{545                  \textcolor{stringliteral}{"{}(normalised by mean SSS) and controlling precipitation."{}}, \&}
\DoxyCodeLine{546                  \textcolor{stringliteral}{"{}kg m-\/2"{}}, default=0.0)}
\DoxyCodeLine{547   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_LAMDA\_CYC\_HEAT"{}}, cs\%lam\_cyc\_heat, \&}
\DoxyCodeLine{548                  \textcolor{stringliteral}{"{}A constant of proportionality between SST anomalies "{}}//\&}
\DoxyCodeLine{549                  \textcolor{stringliteral}{"{}and cyclical controlling heat fluxes"{}}, \textcolor{stringliteral}{"{}W m-\/2 K-\/1"{}}, default=0.0)}
\DoxyCodeLine{550   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}CTRL\_FORCE\_LAMDA\_CYC\_PREC"{}}, cs\%lam\_cyc\_prec, \&}
\DoxyCodeLine{551                  \textcolor{stringliteral}{"{}A constant of proportionality between SSS anomalies "{}}//\&}
\DoxyCodeLine{552                  \textcolor{stringliteral}{"{}(normalised by mean SSS) and cyclical controlling "{}}//\&}
\DoxyCodeLine{553                  \textcolor{stringliteral}{"{}precipitation."{}}, \textcolor{stringliteral}{"{}kg m-\/2"{}}, default=0.0)}
\DoxyCodeLine{554 }
\DoxyCodeLine{555   cs\%Len2 = smooth\_len**2}
\DoxyCodeLine{556 }
\DoxyCodeLine{557 \textcolor{comment}{! \#\#\# REPLACE THIS WITH ANY DIAGNOSTICS FROM THIS MODULE.}}
\DoxyCodeLine{558 \textcolor{comment}{!  CS\%id\_taux = register\_diag\_field('ocean\_model', 'taux', diag\%axesu1, Time, \&}}
\DoxyCodeLine{559 \textcolor{comment}{!        'Zonal Wind Stress', 'Pascal')}}
\DoxyCodeLine{560 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__controlled__forcing_a610583f048e5478ad2cd608dd5de8e00}\label{namespacemom__controlled__forcing_a610583f048e5478ad2cd608dd5de8e00}} 
\index{mom\_controlled\_forcing@{mom\_controlled\_forcing}!periodic\_int@{periodic\_int}}
\index{periodic\_int@{periodic\_int}!mom\_controlled\_forcing@{mom\_controlled\_forcing}}
\doxysubsubsection{\texorpdfstring{periodic\_int()}{periodic\_int()}}
{\footnotesize\ttfamily integer function mom\+\_\+controlled\+\_\+forcing\+::periodic\+\_\+int (\begin{DoxyParamCaption}\item[{real, intent(in)}]{rval,  }\item[{integer, intent(in)}]{num\+\_\+period }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function maps rval into an integer in the range from 1 to num\+\_\+period. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rval} & Input for mapping. \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+period} & Maximum output. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


Definition at line 376 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{377 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: rval\textcolor{comment}{       !< Input for mapping.}}
\DoxyCodeLine{378   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: num\_period\textcolor{comment}{ !< Maximum output.}}
\DoxyCodeLine{379   \textcolor{keywordtype}{integer}             :: m\textcolor{comment}{          !< Return value.}}
\DoxyCodeLine{380 }
\DoxyCodeLine{381   m = floor(rval)}
\DoxyCodeLine{382   \textcolor{keywordflow}{if} (m <= 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{383     m = m + num\_period * (1 + (abs(m) / num\_period))}
\DoxyCodeLine{384   \textcolor{keywordflow}{elseif} (m > num\_period) \textcolor{keywordflow}{then}}
\DoxyCodeLine{385     m = m -\/ num\_period * ((m-\/1) / num\_period)}
\DoxyCodeLine{386 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__controlled__forcing_a61d129cf3590af06823330a566d23fd6}\label{namespacemom__controlled__forcing_a61d129cf3590af06823330a566d23fd6}} 
\index{mom\_controlled\_forcing@{mom\_controlled\_forcing}!periodic\_real@{periodic\_real}}
\index{periodic\_real@{periodic\_real}!mom\_controlled\_forcing@{mom\_controlled\_forcing}}
\doxysubsubsection{\texorpdfstring{periodic\_real()}{periodic\_real()}}
{\footnotesize\ttfamily real function mom\+\_\+controlled\+\_\+forcing\+::periodic\+\_\+real (\begin{DoxyParamCaption}\item[{real, intent(in)}]{rval,  }\item[{integer, intent(in)}]{num\+\_\+period }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function shifts rval by an integer multiple of num\+\_\+period so that 0 $<$= val\+\_\+out $<$ num\+\_\+period. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rval} & Input to be shifted into valid range. \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+period} & Maximum valid value. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


Definition at line 391 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{392 \textcolor{keywordtype}{  real},    \textcolor{keywordtype}{intent(in)} :: rval\textcolor{comment}{       !< Input to be shifted into valid range.}}
\DoxyCodeLine{393   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: num\_period\textcolor{comment}{ !< Maximum valid value.}}
\DoxyCodeLine{394 \textcolor{keywordtype}{  real}                :: val\_out\textcolor{comment}{    !< Return value.}}
\DoxyCodeLine{395   \textcolor{keywordtype}{integer} :: nshft}
\DoxyCodeLine{396 }
\DoxyCodeLine{397   \textcolor{keywordflow}{if} (rval < 0) \textcolor{keywordflow}{then} ; nshft = floor(abs(rval) / num\_period) + 1}
\DoxyCodeLine{398   \textcolor{keywordflow}{elseif} (rval < num\_period) \textcolor{keywordflow}{then} ; nshft = 0}
\DoxyCodeLine{399   \textcolor{keywordflow}{else} ; nshft = -\/1*floor(rval / num\_period) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{400 }
\DoxyCodeLine{401   val\_out = rval + nshft * num\_period}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__controlled__forcing_a8bfffde62f6a555439eba94884a1fc2e}\label{namespacemom__controlled__forcing_a8bfffde62f6a555439eba94884a1fc2e}} 
\index{mom\_controlled\_forcing@{mom\_controlled\_forcing}!register\_ctrl\_forcing\_restarts@{register\_ctrl\_forcing\_restarts}}
\index{register\_ctrl\_forcing\_restarts@{register\_ctrl\_forcing\_restarts}!mom\_controlled\_forcing@{mom\_controlled\_forcing}}
\doxysubsubsection{\texorpdfstring{register\_ctrl\_forcing\_restarts()}{register\_ctrl\_forcing\_restarts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+controlled\+\_\+forcing\+::register\+\_\+ctrl\+\_\+forcing\+\_\+restarts (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__controlled__forcing_1_1ctrl__forcing__cs}{ctrl\+\_\+forcing\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__restart_1_1mom__restart__cs}{mom\+\_\+restart\+\_\+cs}}), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



This subroutine is used to allocate and register any fields in this module that should be written to or read from the restart file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values. \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure. \\
\hline
\end{DoxyParams}


Definition at line 407 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{408   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{409   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure indicating the}}
\DoxyCodeLine{410 \textcolor{comment}{                                                  !! open file to parse for model}}
\DoxyCodeLine{411 \textcolor{comment}{                                                  !! parameter values.}}
\DoxyCodeLine{412   \textcolor{keywordtype}{type}(ctrl\_forcing\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{            !< A pointer that is set to point to the}}
\DoxyCodeLine{413 \textcolor{comment}{                                                  !! control structure for this module.}}
\DoxyCodeLine{414   \textcolor{keywordtype}{type}(MOM\_restart\_CS),  \textcolor{keywordtype}{pointer} :: restart\_CS\textcolor{comment}{    !< A pointer to the restart control structure.}}
\DoxyCodeLine{415 }
\DoxyCodeLine{416   \textcolor{keywordtype}{logical} :: controlled, use\_temperature}
\DoxyCodeLine{417   \textcolor{keywordtype}{character (len=8)} :: period\_str}
\DoxyCodeLine{418   \textcolor{keywordtype}{type}(vardesc) :: vd}
\DoxyCodeLine{419   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{420   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{421   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{422 }
\DoxyCodeLine{423   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{424     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}register\_ctrl\_forcing\_restarts called "{}}//\&}
\DoxyCodeLine{425                              \textcolor{stringliteral}{"{}with an associated control structure."{}})}
\DoxyCodeLine{426     \textcolor{keywordflow}{return}}
\DoxyCodeLine{427 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{428 }
\DoxyCodeLine{429   controlled = .false.}
\DoxyCodeLine{430   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"{}CONTROLLED\_FORCING"{}}, controlled)}
\DoxyCodeLine{431   \textcolor{keywordflow}{if} (.not.controlled) \textcolor{keywordflow}{return}}
\DoxyCodeLine{432 }
\DoxyCodeLine{433   use\_temperature = .true.}
\DoxyCodeLine{434   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"{}ENABLE\_THERMODYNAMICS"{}}, use\_temperature)}
\DoxyCodeLine{435   \textcolor{keywordflow}{if} (.not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{436     \textcolor{stringliteral}{"{}register\_ctrl\_forcing\_restarts: CONTROLLED\_FORCING only works with "{}}//\&}
\DoxyCodeLine{437     \textcolor{stringliteral}{"{}ENABLE\_THERMODYNAMICS defined."{}})}
\DoxyCodeLine{438 }
\DoxyCodeLine{439   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{440 }
\DoxyCodeLine{441   cs\%do\_integrated = .true. ; cs\%num\_cycle = 0}
\DoxyCodeLine{442   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"{}CTRL\_FORCE\_INTEGRATED"{}}, cs\%do\_integrated)}
\DoxyCodeLine{443   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"{}CTRL\_FORCE\_NUM\_CYCLE"{}}, cs\%num\_cycle)}
\DoxyCodeLine{444 }
\DoxyCodeLine{445   \textcolor{keywordflow}{if} (cs\%do\_integrated) \textcolor{keywordflow}{then}}
\DoxyCodeLine{446     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%heat\_0,isd,ied,jsd,jed) ; cs\%heat\_0(:,:) = 0.0}
\DoxyCodeLine{447     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%precip\_0,isd,ied,jsd,jed) ; cs\%precip\_0(:,:) = 0.0}
\DoxyCodeLine{448     vd = var\_desc(\textcolor{stringliteral}{"{}Ctrl\_heat"{}},\textcolor{stringliteral}{"{}W m-\/2"{}},\textcolor{stringliteral}{"{}Control Integrative Heating"{}},z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{449     \textcolor{keyword}{call }register\_restart\_field(cs\%heat\_0, vd, .false., restart\_cs)}
\DoxyCodeLine{450     vd = var\_desc(\textcolor{stringliteral}{"{}Ctrl\_precip"{}},\textcolor{stringliteral}{"{}kg m-\/2 s-\/1"{}},\textcolor{stringliteral}{"{}Control Integrative Precipitation"{}},z\_grid=\textcolor{stringliteral}{'1'})}
\DoxyCodeLine{451     \textcolor{keyword}{call }register\_restart\_field(cs\%precip\_0, vd, .false., restart\_cs)}
\DoxyCodeLine{452 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{453 }
\DoxyCodeLine{454   \textcolor{keywordflow}{if} (cs\%num\_cycle > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{455     \textcolor{keyword}{write} (period\_str, \textcolor{stringliteral}{'(i8)'}) cs\%num\_cycle}
\DoxyCodeLine{456     period\_str = trim(\textcolor{stringliteral}{'p '})//trim(adjustl(period\_str))}
\DoxyCodeLine{457     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%heat\_cyc,isd,ied,jsd,jed,cs\%num\_cycle) ; cs\%heat\_cyc(:,:,:) = 0.0}
\DoxyCodeLine{458     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%precip\_cyc,isd,ied,jsd,jed,cs\%num\_cycle) ; cs\%precip\_cyc(:,:,:) = 0.0}
\DoxyCodeLine{459     vd = var\_desc(\textcolor{stringliteral}{"{}Ctrl\_heat\_cycle"{}}, \textcolor{stringliteral}{"{}W m-\/2"{}},\textcolor{stringliteral}{"{}Cyclical Control Heating"{}},\&}
\DoxyCodeLine{460                   z\_grid=\textcolor{stringliteral}{'1'}, t\_grid=period\_str)}
\DoxyCodeLine{461     \textcolor{keyword}{call }register\_restart\_field(cs\%heat\_cyc, vd, .false., restart\_cs)}
\DoxyCodeLine{462     vd = var\_desc(\textcolor{stringliteral}{"{}Ctrl\_precip\_cycle"{}},\textcolor{stringliteral}{"{}kg m-\/2 s-\/1"{}},\textcolor{stringliteral}{"{}Cyclical Control Precipitation"{}}, \&}
\DoxyCodeLine{463                   z\_grid=\textcolor{stringliteral}{'1'}, t\_grid=period\_str)}
\DoxyCodeLine{464     \textcolor{keyword}{call }register\_restart\_field(cs\%precip\_cyc, vd, .false., restart\_cs)}
\DoxyCodeLine{465 }
\DoxyCodeLine{466     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%avg\_time,cs\%num\_cycle) ; cs\%avg\_time(:) = 0.0}
\DoxyCodeLine{467     vd = var\_desc(\textcolor{stringliteral}{"{}avg\_time"{}},\textcolor{stringliteral}{"{}sec"{}},\textcolor{stringliteral}{"{}Cyclical accumulated averaging time"{}}, \&}
\DoxyCodeLine{468                   \textcolor{stringliteral}{'1'},z\_grid=\textcolor{stringliteral}{'1'},t\_grid=period\_str)}
\DoxyCodeLine{469     \textcolor{keyword}{call }register\_restart\_field(cs\%avg\_time, vd, .false., restart\_cs)}
\DoxyCodeLine{470 }
\DoxyCodeLine{471     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%avg\_SST\_anom,isd,ied,jsd,jed,cs\%num\_cycle) ; cs\%avg\_SST\_anom(:,:,:) = 0.0}
\DoxyCodeLine{472     \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%avg\_SSS\_anom,isd,ied,jsd,jed,cs\%num\_cycle) ; cs\%avg\_SSS\_anom(:,:,:) = 0.0}
\DoxyCodeLine{473     vd = var\_desc(\textcolor{stringliteral}{"{}avg\_SST\_anom"{}},\textcolor{stringliteral}{"{}deg C"{}},\textcolor{stringliteral}{"{}Cyclical average SST Anomaly"{}}, \&}
\DoxyCodeLine{474                   z\_grid=\textcolor{stringliteral}{'1'},t\_grid=period\_str)}
\DoxyCodeLine{475     \textcolor{keyword}{call }register\_restart\_field(cs\%avg\_SST\_anom, vd, .false., restart\_cs)}
\DoxyCodeLine{476     vd = var\_desc(\textcolor{stringliteral}{"{}avg\_SSS\_anom"{}},\textcolor{stringliteral}{"{}g kg-\/1"{}},\textcolor{stringliteral}{"{}Cyclical average SSS Anomaly"{}}, \&}
\DoxyCodeLine{477                   z\_grid=\textcolor{stringliteral}{'1'},t\_grid=period\_str)}
\DoxyCodeLine{478     \textcolor{keyword}{call }register\_restart\_field(cs\%avg\_SSS\_anom, vd, .false., restart\_cs)}
\DoxyCodeLine{479 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{480 }

\end{DoxyCode}
