\hypertarget{namespacemom__controlled__forcing}{}\section{mom\+\_\+controlled\+\_\+forcing Module Reference}
\label{namespacemom__controlled__forcing}\index{mom\+\_\+controlled\+\_\+forcing@{mom\+\_\+controlled\+\_\+forcing}}


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

\begin{DoxyVerb}                                                               *
\end{DoxyVerb}
 By Robert Hallberg, July 2011 $\ast$
\begin{DoxyItemize}
\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$
\end{DoxyItemize}

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.). \subsection*{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}
\subsection*{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}


\subsection{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}}
\subsubsection{\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(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{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{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em sst\+\_\+anom} & The sea surface temperature anomalies \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sss\+\_\+anom} & The sea surface salinity anomlies \mbox{[}ppt\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sss\+\_\+mean} & The mean sea surface salinity \mbox{[}ppt\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em virt\+\_\+heat} & Virtual (corrective) heat fluxes that are augmented in this subroutine \mbox{[}W m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em virt\+\_\+precip} & Virtual (corrective) precipitation fluxes that are augmented in this subroutine \mbox{[}kg m-\/2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em day\+\_\+start} & Start time of the fluxes.\\
\hline
\mbox{\tt in}  & {\em dt} & Length of time over which these fluxes will be applied \mbox{[}s\mbox{]}.\\
\hline
\mbox{\tt 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 83 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


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


\begin{DoxyCode}
565   \textcolor{keywordtype}{type}(ctrl\_forcing\_CS),    \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< A pointer to the control structure}
566 \textcolor{comment}{                                          !! returned by a previous call to}
567 \textcolor{comment}{                                          !! controlled\_forcing\_init, it will be}
568 \textcolor{comment}{                                          !! deallocated here.}
569 
570   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
571     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%heat\_0))       \textcolor{keyword}{deallocate}(cs%heat\_0)
572     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%precip\_0))     \textcolor{keyword}{deallocate}(cs%precip\_0)
573     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%heat\_cyc))     \textcolor{keyword}{deallocate}(cs%heat\_cyc)
574     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%precip\_cyc))   \textcolor{keyword}{deallocate}(cs%precip\_cyc)
575     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%avg\_SST\_anom)) \textcolor{keyword}{deallocate}(cs%avg\_SST\_anom)
576     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%avg\_SSS\_anom)) \textcolor{keyword}{deallocate}(cs%avg\_SSS\_anom)
577     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%avg\_SSS))      \textcolor{keyword}{deallocate}(cs%avg\_SSS)
578 
579     \textcolor{keyword}{deallocate}(cs)
580 \textcolor{keywordflow}{  endif}
581   cs => null()
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}}
\subsubsection{\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(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(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{\tt in}  & {\em time} & The current model time.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt 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 485 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


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


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


\begin{DoxyCode}
377   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)} :: rval\textcolor{comment}{       !< Input for mapping.}
378   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: num\_period\textcolor{comment}{ !< Maximum output.}
379   \textcolor{keywordtype}{integer}             :: m\textcolor{comment}{          !< Return value.}
380 
381   m = floor(rval)
382   \textcolor{keywordflow}{if} (m <= 0) \textcolor{keywordflow}{then}
383     m = m + num\_period * (1 + (abs(m) / num\_period))
384   \textcolor{keywordflow}{elseif} (m > num\_period) \textcolor{keywordflow}{then}
385     m = m - num\_period * ((m-1) / num\_period)
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}}
\subsubsection{\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{\tt in}  & {\em rval} & Input to be shifted into valid range.\\
\hline
\mbox{\tt in}  & {\em num\+\_\+period} & Maximum valid value.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


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


\begin{DoxyCode}
392   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)} :: rval\textcolor{comment}{       !< Input to be shifted into valid range.}
393   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: num\_period\textcolor{comment}{ !< Maximum valid value.}
394   \textcolor{keywordtype}{real}                :: val\_out\textcolor{comment}{    !< Return value.}
395   \textcolor{keywordtype}{integer} :: nshft
396 
397   \textcolor{keywordflow}{if} (rval < 0) \textcolor{keywordflow}{then} ; nshft = floor(abs(rval) / num\_period) + 1
398   \textcolor{keywordflow}{elseif} (rval < num\_period) \textcolor{keywordflow}{then} ; nshft = 0
399   \textcolor{keywordflow}{else} ; nshft = -1*floor(rval / num\_period) ;\textcolor{keywordflow}{ endif}
400 
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}}
\subsubsection{\texorpdfstring{register\+\_\+ctrl\+\_\+forcing\+\_\+restarts()}{register\_ctrl\_forcing\_restarts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+controlled\+\_\+forcing\+::register\+\_\+ctrl\+\_\+forcing\+\_\+restarts (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{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(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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt 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 408 of file M\+O\+M\+\_\+controlled\+\_\+forcing.\+F90.


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