This subroutine calls any of the other subroutines in this file that are needed to specify the current surface forcing fields.
93 type(ocean_grid_type),
intent(inout) :: g
94 real,
dimension(SZI_(G),SZJ_(G)),
intent(in) :: sst_anom
96 real,
dimension(SZI_(G),SZJ_(G)),
intent(in) :: sss_anom
98 real,
dimension(SZI_(G),SZJ_(G)),
intent(in) :: sss_mean
100 real,
dimension(SZI_(G),SZJ_(G)),
intent(inout) :: virt_heat
103 real,
dimension(SZI_(G),SZJ_(G)),
intent(inout) :: virt_precip
107 type(time_type),
intent(in) :: day_start
108 real,
intent(in) :: dt
110 type(ctrl_forcing_cs),
pointer :: cs
114 real,
dimension(SZIB_(G),SZJ_(G)) :: &
117 real,
dimension(SZI_(G),SZJB_(G)) :: &
120 type(time_type) :: day_end
122 real :: mr_st, mr_end, mr_mid, mr_prev, mr_next
123 real :: dt_wt, dt_heat_rate, dt_prec_rate
124 real :: dt1_heat_rate, dt1_prec_rate, dt2_heat_rate, dt2_prec_rate
125 real :: wt_per1, wt_st, wt_end, wt_mid
126 integer :: m_st, m_end, m_mid, m_u1, m_u2, m_u3
127 integer :: yr, mon, day, hr, min, sec
128 integer :: i, j, is, ie, js, je
130 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
132 if (.not.
associated(cs))
return 133 if ((cs%num_cycle <= 0) .and. (.not.cs%do_integrated))
return 135 day_end = day_start + set_time(floor(dt+0.5))
137 do j=js,je ;
do i=is,ie
138 virt_heat(i,j) = 0.0 ; virt_precip(i,j) = 0.0
141 if (cs%do_integrated)
then 142 dt_heat_rate = dt * cs%heat_int_rate
143 dt_prec_rate = dt * cs%prec_int_rate
144 call pass_var(cs%heat_0, g%Domain, complete=.false.)
145 call pass_var(cs%precip_0, g%Domain)
147 do j=js,je ;
do i=is-1,ie
148 coef = cs%Len2 * (g%dy_Cu(i,j)*g%IdxCu(i,j))
149 flux_heat_x(i,j) = coef * (cs%heat_0(i,j) - cs%heat_0(i+1,j))
150 flux_prec_x(i,j) = coef * (cs%precip_0(i,j) - cs%precip_0(i+1,j))
152 do j=js-1,je ;
do i=is,ie
153 coef = cs%Len2 * (g%dx_Cv(i,j)*g%IdyCv(i,j))
154 flux_heat_y(i,j) = coef * (cs%heat_0(i,j) - cs%heat_0(i,j+1))
155 flux_prec_y(i,j) = coef * (cs%precip_0(i,j) - cs%precip_0(i,j+1))
157 do j=js,je ;
do i=is,ie
158 cs%heat_0(i,j) = cs%heat_0(i,j) + dt_heat_rate * ( &
159 -cs%lam_heat*g%mask2dT(i,j)*sst_anom(i,j) + &
160 (g%IareaT(i,j) * ((flux_heat_x(i-1,j) - flux_heat_x(i,j)) + &
161 (flux_heat_y(i,j-1) - flux_heat_y(i,j))) ) )
163 cs%precip_0(i,j) = cs%precip_0(i,j) + dt_prec_rate * ( &
164 cs%lam_prec * g%mask2dT(i,j)*(sss_anom(i,j) / sss_mean(i,j)) + &
165 (g%IareaT(i,j) * ((flux_prec_x(i-1,j) - flux_prec_x(i,j)) + &
166 (flux_prec_y(i,j-1) - flux_prec_y(i,j))) ) )
168 virt_heat(i,j) = virt_heat(i,j) + cs%heat_0(i,j)
169 virt_precip(i,j) = virt_precip(i,j) + cs%precip_0(i,j)
173 if (cs%num_cycle > 0)
then 175 call get_date(day_start, yr, mon, day, hr, min, sec)
176 mr_st = cs%num_cycle * (time_type_to_real(day_start - set_date(yr, 1, 1)) / &
177 time_type_to_real(set_date(yr+1, 1, 1) - set_date(yr, 1, 1)))
179 call get_date(day_end, yr, mon, day, hr, min, sec)
180 mr_end = cs%num_cycle * (time_type_to_real(day_end - set_date(yr, 1, 1)) / &
181 time_type_to_real(set_date(yr+1, 1, 1) - set_date(yr, 1, 1)))
189 m_end = periodic_int(
real(ceiling(mr_end)), cs%num_cycle)
190 m_mid = periodic_int(
real(ceiling(mr_st)), cs%num_cycle)
191 m_st = periodic_int(mr_st, cs%num_cycle)
193 mr_st = periodic_real(mr_st, cs%num_cycle)
194 mr_end = periodic_real(mr_end, cs%num_cycle)
196 mr_prev = periodic_real(
real(floor(mr_st)), cs%num_cycle)
197 mr_next = periodic_real(
real(m_end), cs%num_cycle)
198 if (m_mid == m_end)
then ; mr_mid = mr_end
199 else ; mr_mid = periodic_real(
real(m_mid), cs%num_cycle) ; endif
206 if (mr_st < mr_prev) mr_prev = mr_prev - cs%num_cycle
207 if (mr_mid < mr_st) mr_mid = mr_mid + cs%num_cycle
208 if (mr_end < mr_st) mr_end = mr_end + cs%num_cycle
209 if (mr_next < mr_prev) mr_next = mr_next + cs%num_cycle
212 if ((mr_mid < mr_st) .or. (mr_mid > mr_prev + 1.))
call mom_error(fatal, &
213 "apply ctrl_forcing: m_mid interpolation out of bounds; fix the code.")
214 if ((mr_end < mr_st) .or. (mr_end > mr_prev + 2.))
call mom_error(fatal, &
215 "apply ctrl_forcing: m_end interpolation out of bounds; fix the code.")
216 if (mr_end > mr_next)
call mom_error(fatal, &
217 "apply ctrl_forcing: mr_next interpolation out of bounds; fix the code.")
220 if (mr_mid < mr_end) wt_per1 = (mr_mid - mr_st) / (mr_end - mr_st)
223 wt_st = wt_per1 * (1. + (mr_prev - 0.5*(mr_st + mr_mid)))
224 wt_end = (1.0-wt_per1) * (1. + (0.5*(mr_end + mr_mid) - mr_next))
225 wt_mid = 1.0 - (wt_st + wt_end)
226 if ((wt_st < 0.0) .or. (wt_end < 0.0) .or. (wt_mid < 0.0)) &
227 call mom_error(fatal,
"apply_ctrl_forcing: Negative m weights")
228 if ((wt_st > 1.0) .or. (wt_end > 1.0) .or. (wt_mid > 1.0)) &
229 call mom_error(fatal,
"apply_ctrl_forcing: Excessive m weights")
232 do j=js,je ;
do i=is,ie
233 virt_heat(i,j) = virt_heat(i,j) + (wt_st * cs%heat_cyc(i,j,m_st) + &
234 (wt_mid * cs%heat_cyc(i,j,m_mid) + &
235 wt_end * cs%heat_cyc(i,j,m_end)))
236 virt_precip(i,j) = virt_precip(i,j) + (wt_st * cs%precip_cyc(i,j,m_st) + &
237 (wt_mid * cs%precip_cyc(i,j,m_mid) + &
238 wt_end * cs%precip_cyc(i,j,m_end)))
251 if (cs%avg_time(m_end) <= 0.0)
then 252 cs%avg_time(m_end) = 0.0
253 do j=js,je ;
do i=is,ie
254 cs%avg_SST_anom(i,j,m_end) = 0.0
255 cs%avg_SSS_anom(i,j,m_end) = 0.0 ; cs%avg_SSS(i,j,m_end) = 0.0
258 if (cs%avg_time(m_mid) <= 0.0)
then 259 cs%avg_time(m_mid) = 0.0
260 do j=js,je ;
do i=is,ie
261 cs%avg_SST_anom(i,j,m_mid) = 0.0
262 cs%avg_SSS_anom(i,j,m_mid) = 0.0 ; cs%avg_SSS(i,j,m_mid) = 0.0
268 cs%avg_time(m_mid) = cs%avg_time(m_mid) + dt_wt
269 do j=js,je ;
do i=is,ie
270 cs%avg_SST_anom(i,j,m_mid) = cs%avg_SST_anom(i,j,m_mid) + &
271 dt_wt * g%mask2dT(i,j) * sst_anom(i,j)
272 cs%avg_SSS_anom(i,j,m_mid) = cs%avg_SSS_anom(i,j,m_mid) + &
273 dt_wt * g%mask2dT(i,j) * sss_anom(i,j)
274 cs%avg_SSS(i,j,m_mid) = cs%avg_SSS(i,j,m_mid) + dt_wt * sss_mean(i,j)
276 if (wt_per1 < 1.0)
then 277 dt_wt = (1.0-wt_per1) * dt
278 cs%avg_time(m_end) = cs%avg_time(m_end) + dt_wt
279 do j=js,je ;
do i=is,ie
280 cs%avg_SST_anom(i,j,m_end) = cs%avg_SST_anom(i,j,m_end) + &
281 dt_wt * g%mask2dT(i,j) * sst_anom(i,j)
282 cs%avg_SSS_anom(i,j,m_end) = cs%avg_SSS_anom(i,j,m_end) + &
283 dt_wt * g%mask2dT(i,j) * sss_anom(i,j)
284 cs%avg_SSS(i,j,m_end) = cs%avg_SSS(i,j,m_end) + dt_wt * sss_mean(i,j)
289 m_u1 = periodic_int(m_st - 4.0, cs%num_cycle)
290 m_u2 = periodic_int(m_st - 3.0, cs%num_cycle)
291 m_u3 = periodic_int(m_st - 2.0, cs%num_cycle)
293 if (cs%avg_time(m_u1) > 0.0)
then 294 do j=js,je ;
do i=is,ie
295 cs%avg_SST_anom(i,j,m_u1) = cs%avg_SST_anom(i,j,m_u1) / cs%avg_time(m_u1)
296 cs%avg_SSS_anom(i,j,m_u1) = cs%avg_SSS_anom(i,j,m_u1) / cs%avg_time(m_u1)
297 cs%avg_SSS(i,j,m_u1) = cs%avg_SSS(i,j,m_u1) / cs%avg_time(m_u1)
299 cs%avg_time(m_u1) = -1.0
301 if (cs%avg_time(m_u2) > 0.0)
then 302 do j=js,je ;
do i=is,ie
303 cs%avg_SST_anom(i,j,m_u2) = cs%avg_SST_anom(i,j,m_u2) / cs%avg_time(m_u2)
304 cs%avg_SSS_anom(i,j,m_u2) = cs%avg_SSS_anom(i,j,m_u2) / cs%avg_time(m_u2)
305 cs%avg_SSS(i,j,m_u2) = cs%avg_SSS(i,j,m_u2) / cs%avg_time(m_u2)
307 cs%avg_time(m_u2) = -1.0
309 if (cs%avg_time(m_u3) > 0.0)
then 310 do j=js,je ;
do i=is,ie
311 cs%avg_SST_anom(i,j,m_u3) = cs%avg_SST_anom(i,j,m_u3) / cs%avg_time(m_u3)
312 cs%avg_SSS_anom(i,j,m_u3) = cs%avg_SSS_anom(i,j,m_u3) / cs%avg_time(m_u3)
313 cs%avg_SSS(i,j,m_u3) = cs%avg_SSS(i,j,m_u3) / cs%avg_time(m_u3)
315 cs%avg_time(m_u3) = -1.0
318 dt1_heat_rate = wt_per1 * dt * cs%heat_cyc_rate
319 dt1_prec_rate = wt_per1 * dt * cs%prec_cyc_rate
320 dt2_heat_rate = (1.0-wt_per1) * dt * cs%heat_cyc_rate
321 dt2_prec_rate = (1.0-wt_per1) * dt * cs%prec_cyc_rate
323 if (wt_per1 < 1.0)
then 324 call pass_var(cs%heat_cyc(:,:,m_u2), g%Domain, complete=.false.)
325 call pass_var(cs%precip_cyc(:,:,m_u2), g%Domain, complete=.false.)
327 call pass_var(cs%heat_cyc(:,:,m_u1), g%Domain, complete=.false.)
328 call pass_var(cs%precip_cyc(:,:,m_u1), g%Domain)
330 if ((cs%avg_time(m_u1) == -1.0) .and. (cs%avg_time(m_u2) == -1.0))
then 331 do j=js,je ;
do i=is-1,ie
332 coef = cs%Len2 * (g%dy_Cu(i,j)*g%IdxCu(i,j))
333 flux_heat_x(i,j) = coef * (cs%heat_cyc(i,j,m_u1) - cs%heat_cyc(i+1,j,m_u1))
334 flux_prec_x(i,j) = coef * (cs%precip_cyc(i,j,m_u1) - cs%precip_cyc(i+1,j,m_u1))
336 do j=js-1,je ;
do i=is,ie
337 coef = cs%Len2 * (g%dx_Cv(i,j)*g%IdyCv(i,j))
338 flux_heat_y(i,j) = coef * (cs%heat_cyc(i,j,m_u1) - cs%heat_cyc(i,j+1,m_u1))
339 flux_prec_y(i,j) = coef * (cs%precip_cyc(i,j,m_u1) - cs%precip_cyc(i,j+1,m_u1))
341 do j=js,je ;
do i=is,ie
342 cs%heat_cyc(i,j,m_u1) = cs%heat_cyc(i,j,m_u1) + dt1_heat_rate * ( &
343 -cs%lam_cyc_heat*(cs%avg_SST_anom(i,j,m_u2) - cs%avg_SST_anom(i,j,m_u1)) + &
344 (g%IareaT(i,j) * ((flux_heat_x(i-1,j) - flux_heat_x(i,j)) + &
345 (flux_heat_y(i,j-1) - flux_heat_y(i,j))) ) )
347 cs%precip_cyc(i,j,m_u1) = cs%precip_cyc(i,j,m_u1) + dt1_prec_rate * ( &
348 cs%lam_cyc_prec * (cs%avg_SSS_anom(i,j,m_u2) - cs%avg_SSS_anom(i,j,m_u1)) / &
349 (0.5*(cs%avg_SSS(i,j,m_u2) + cs%avg_SSS(i,j,m_u1))) + &
350 (g%IareaT(i,j) * ((flux_prec_x(i-1,j) - flux_prec_x(i,j)) + &
351 (flux_prec_y(i,j-1) - flux_prec_y(i,j))) ) )
355 if ((wt_per1 < 1.0) .and. (cs%avg_time(m_u1) == -1.0) .and. (cs%avg_time(m_u2) == -1.0))
then 356 do j=js,je ;
do i=is-1,ie
357 coef = cs%Len2 * (g%dy_Cu(i,j)*g%IdxCu(i,j))
358 flux_heat_x(i,j) = coef * (cs%heat_cyc(i,j,m_u2) - cs%heat_cyc(i+1,j,m_u2))
359 flux_prec_x(i,j) = coef * (cs%precip_cyc(i,j,m_u2) - cs%precip_cyc(i+1,j,m_u2))
361 do j=js-1,je ;
do i=is,ie
362 coef = cs%Len2 * (g%dx_Cv(i,j)*g%IdyCv(i,j))
363 flux_heat_y(i,j) = coef * (cs%heat_cyc(i,j,m_u2) - cs%heat_cyc(i,j+1,m_u2))
364 flux_prec_y(i,j) = coef * (cs%precip_cyc(i,j,m_u2) - cs%precip_cyc(i,j+1,m_u2))
366 do j=js,je ;
do i=is,ie
367 cs%heat_cyc(i,j,m_u2) = cs%heat_cyc(i,j,m_u2) + dt1_heat_rate * ( &
368 -cs%lam_cyc_heat*(cs%avg_SST_anom(i,j,m_u3) - cs%avg_SST_anom(i,j,m_u2)) + &
369 (g%IareaT(i,j) * ((flux_heat_x(i-1,j) - flux_heat_x(i,j)) + &
370 (flux_heat_y(i,j-1) - flux_heat_y(i,j))) ) )
372 cs%precip_cyc(i,j,m_u2) = cs%precip_cyc(i,j,m_u2) + dt1_prec_rate * ( &
373 cs%lam_cyc_prec * (cs%avg_SSS_anom(i,j,m_u3) - cs%avg_SSS_anom(i,j,m_u2)) / &
374 (0.5*(cs%avg_SSS(i,j,m_u3) + cs%avg_SSS(i,j,m_u2))) + &
375 (g%IareaT(i,j) * ((flux_prec_x(i-1,j) - flux_prec_x(i,j)) + &
376 (flux_prec_y(i,j-1) - flux_prec_y(i,j))) ) )