22 #define DEBUG_REDUCT .false.
26 subroutine do_time_none_ (data_out, data_in, mask, is_masked, bounds_in, bounds_out, missing_value)
27 real(FMS_TRM_KIND_),
intent(inout) :: data_out(:,:,:,:,:)
28 real(FMS_TRM_KIND_),
intent(in) :: data_in(:,:,:,:)
29 logical,
intent(in) :: mask(:,:,:,:)
30 logical,
intent(in) :: is_masked
31 type(fmsDiagIbounds_type),
intent(in) :: bounds_in
33 type(fmsDiagIbounds_type),
intent(in) :: bounds_out
35 real(FMS_TRM_KIND_),
intent(in) :: missing_value
37 integer :: is_in, ie_in, js_in, je_in, ks_in, ke_in
39 integer :: is_out, ie_out, js_out, je_out, ks_out, ke_out
42 is_out = bounds_out%get_imin()
43 ie_out = bounds_out%get_imax()
44 js_out = bounds_out%get_jmin()
45 je_out = bounds_out%get_jmax()
46 ks_out = bounds_out%get_kmin()
47 ke_out = bounds_out%get_kmax()
49 is_in = bounds_in%get_imin()
50 ie_in = bounds_in%get_imax()
51 js_in = bounds_in%get_jmin()
52 je_in = bounds_in%get_jmax()
53 ks_in = bounds_in%get_kmin()
54 ke_in = bounds_in%get_kmax()
57 where (mask(is_in:ie_in, js_in:je_in, ks_in:ke_in, :))
58 data_out(is_out:ie_out, js_out:je_out, ks_out:ke_out, :, 1) = &
59 data_in(is_in:ie_in, js_in:je_in, ks_in:ke_in, :)
61 data_out(is_out:ie_out, js_out:je_out, ks_out:ke_out, :, 1) = missing_value
64 data_out(is_out:ie_out, js_out:je_out, ks_out:ke_out, :, 1) = &
65 data_in(is_in:ie_in, js_in:je_in, ks_in:ke_in, :)
68 end subroutine do_time_none_
71 subroutine do_time_min_ (data_out, data_in, mask, is_masked, bounds_in, bounds_out, missing_value)
72 real(FMS_TRM_KIND_),
intent(inout) :: data_out(:,:,:,:,:)
73 real(FMS_TRM_KIND_),
intent(in) :: data_in(:,:,:,:)
74 logical,
intent(in) :: mask(:,:,:,:)
75 logical,
intent(in) :: is_masked
76 type(fmsDiagIbounds_type),
intent(in) :: bounds_in
78 type(fmsDiagIbounds_type),
intent(in) :: bounds_out
80 real(FMS_TRM_KIND_),
intent(in) :: missing_value
82 integer :: is_in, ie_in, js_in, je_in, ks_in, ke_in
84 integer :: is_out, ie_out, js_out, je_out, ks_out, ke_out
89 is_out = bounds_out%get_imin()
90 ie_out = bounds_out%get_imax()
91 js_out = bounds_out%get_jmin()
92 je_out = bounds_out%get_jmax()
93 ks_out = bounds_out%get_kmin()
94 ke_out = bounds_out%get_kmax()
96 is_in = bounds_in%get_imin()
97 ie_in = bounds_in%get_imax()
98 js_in = bounds_in%get_jmin()
99 je_in = bounds_in%get_jmax()
100 ks_in = bounds_in%get_kmin()
101 ke_in = bounds_in%get_kmax()
106 do l = 0,
size(data_out, 4) - 1
107 do k = 0, ke_out - ks_out
108 do j = 0, je_out - js_out
109 do i = 0, ie_out - is_out
110 if (mask(is_in + i, js_in + j, ks_in + k, l + 1))
then
111 if (data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) .gt. &
112 data_in(is_in + i, js_in + j, ks_in + k, l + 1) )
then
113 data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) = &
114 data_in(is_in +i, js_in + j, ks_in + k, l + 1)
117 data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) = missing_value
124 do l = 0,
size(data_out, 4) - 1
125 do k = 0, ke_out - ks_out
126 do j = 0, je_out - js_out
127 do i = 0, ie_out - is_out
128 if (data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) .gt. &
129 data_in(is_in + i, js_in + j, ks_in + k, l + 1) )
then
130 data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) = &
131 data_in(is_in +i, js_in + j, ks_in + k, l + 1)
139 end subroutine do_time_min_
142 subroutine do_time_max_ (data_out, data_in, mask, is_masked, bounds_in, bounds_out, missing_value)
143 real(FMS_TRM_KIND_),
intent(inout) :: data_out(:,:,:,:,:)
144 real(FMS_TRM_KIND_),
intent(in) :: data_in(:,:,:,:)
145 logical,
intent(in) :: mask(:,:,:,:)
146 logical,
intent(in) :: is_masked
147 type(fmsDiagIbounds_type),
intent(in) :: bounds_in
149 type(fmsDiagIbounds_type),
intent(in) :: bounds_out
151 real(FMS_TRM_KIND_),
intent(in) :: missing_value
153 integer :: is_in, ie_in, js_in, je_in, ks_in, ke_in
155 integer :: is_out, ie_out, js_out, je_out, ks_out, ke_out
158 integer :: i, j, k, l
160 is_out = bounds_out%get_imin()
161 ie_out = bounds_out%get_imax()
162 js_out = bounds_out%get_jmin()
163 je_out = bounds_out%get_jmax()
164 ks_out = bounds_out%get_kmin()
165 ke_out = bounds_out%get_kmax()
167 is_in = bounds_in%get_imin()
168 ie_in = bounds_in%get_imax()
169 js_in = bounds_in%get_jmin()
170 je_in = bounds_in%get_jmax()
171 ks_in = bounds_in%get_kmin()
172 ke_in = bounds_in%get_kmax()
177 do l = 0,
size(data_out, 4) - 1
178 do k = 0, ke_out - ks_out
179 do j = 0, je_out - js_out
180 do i = 0, ie_out - is_out
181 if (mask(is_in + i, js_in + j, ks_in + k, l + 1))
then
182 if (data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) .lt. &
183 data_in(is_in + i, js_in + j, ks_in + k, l + 1) )
then
184 data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) = &
185 data_in(is_in +i, js_in + j, ks_in + k, l + 1)
188 data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) = missing_value
195 do l = 0,
size(data_out, 4) - 1
196 do k = 0, ke_out - ks_out
197 do j = 0, je_out - js_out
198 do i = 0, ie_out - is_out
199 if (data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) .lt. &
200 data_in(is_in + i, js_in + j, ks_in + k, l + 1) )
then
201 data_out(is_out + i, js_out + j, ks_out + k, l + 1, 1) = &
202 data_in(is_in +i, js_in + j, ks_in + k, l + 1)
209 end subroutine do_time_max_
217 subroutine do_time_sum_update_(data_out, weight_sum, data_in, mask, is_masked, mask_variant, bounds_in, bounds_out, &
218 missing_value, diurnal_section, weight, pow)
219 real(FMS_TRM_KIND_),
intent(inout) :: data_out(:,:,:,:,:)
220 real(r8_kind),
intent(inout) :: weight_sum(:,:,:,:)
221 real(FMS_TRM_KIND_),
intent(in) :: data_in(:,:,:,:)
222 logical,
intent(in) :: mask(:,:,:,:)
223 logical,
intent(in) :: is_masked
224 logical,
intent(in) :: mask_variant
225 type(fmsDiagIbounds_type),
intent(in) :: bounds_in
227 type(fmsDiagIbounds_type),
intent(in) :: bounds_out
229 real(FMS_TRM_KIND_),
intent(in) :: missing_value
230 integer,
intent(in) :: diurnal_section
233 real(r8_kind),
optional,
intent(in) :: weight
235 integer ,
optional,
intent(in) :: pow
238 integer :: is_in, ie_in, js_in, je_in, ks_in, ke_in
240 integer :: is_out, ie_out, js_out, je_out, ks_out, ke_out
242 integer :: i, j, k, l
243 real(FMS_TRM_KIND_) :: weight_scale
245 integer,
parameter :: kindl = fms_trm_kind_
249 if(
present(weight))
then
250 weight_scale = real(weight, kind=kindl)
252 weight_scale = 1.0_kindl
255 if(
present(pow))
then
261 if(diurnal_section .lt. 0)
then
264 diurnal = diurnal_section
267 is_out = bounds_out%get_imin()
268 ie_out = bounds_out%get_imax()
269 js_out = bounds_out%get_jmin()
270 je_out = bounds_out%get_jmax()
271 ks_out = bounds_out%get_kmin()
272 ke_out = bounds_out%get_kmax()
274 is_in = bounds_in%get_imin()
275 ie_in = bounds_in%get_imax()
276 js_in = bounds_in%get_jmin()
277 je_in = bounds_in%get_jmax()
278 ks_in = bounds_in%get_kmin()
279 ke_in = bounds_in%get_kmax()
285 if (mask_variant)
then
287 do k = 0, ke_out - ks_out
288 do j = 0, je_out - js_out
289 do i = 0, ie_out - is_out
290 where (mask(is_in + i, js_in + j, ks_in + k, :))
291 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) = &
292 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) &
293 + (data_in(is_in +i, js_in + j, ks_in + k, :) * weight_scale) ** pow_loc
295 weight_sum(is_out + i, js_out + j, ks_out + k, :) = &
296 weight_sum(is_out + i, js_out + j, ks_out + k, :) + weight_scale
302 weight_sum = weight_sum + weight_scale
303 do k = 0, ke_out - ks_out
304 do j = 0, je_out - js_out
305 do i = 0, ie_out - is_out
306 where (mask(is_in + i, js_in + j, ks_in + k, :))
307 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) = &
308 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) &
309 + (data_in(is_in +i, js_in + j, ks_in + k, :) * weight_scale) ** pow_loc
311 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) = missing_value
318 weight_sum = weight_sum + weight_scale
320 do k = 0, ke_out - ks_out
321 do j = 0, je_out - js_out
322 do i = 0, ie_out - is_out
323 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) = &
324 data_out(is_out + i, js_out + j, ks_out + k, :, diurnal) &
325 + (data_in(is_in +i, js_in + j, ks_in + k, :) * weight_scale) ** pow_loc
330 end subroutine do_time_sum_update_
335 subroutine sum_update_done_(out_buffer_data, weight_sum, reduction_method, missing_val, has_mask, mask_variant, &
337 real(FMS_TRM_KIND_),
intent(inout) :: out_buffer_data(:,:,:,:,:)
339 real(r8_kind),
intent(in) :: weight_sum(:,:,:,:)
341 integer,
intent(in) :: reduction_method
343 real(FMS_TRM_KIND_),
intent(in) :: missing_val
344 logical,
intent(in) :: has_mask
345 logical,
intent(in) :: mask_variant
346 integer,
optional,
intent(in) :: n_diurnal_samples
347 integer,
allocatable :: wsum(:,:,:,:)
352 integer :: i, j, k, l
354 allocate(wsum(
size(weight_sum,1),
size(weight_sum,3),
size(weight_sum,3),
size(weight_sum,4)))
358 if(reduction_method .eq. time_diurnal)
then
359 if(.not.
present(n_diurnal_samples))
call mpp_error(fatal, &
360 "SUM_UPDATE_DONE_ :: reduction method is diurnal but no sample size was given")
361 wsum = weight_sum / n_diurnal_samples
367 if (.not. mask_variant)
then
369 where(out_buffer_data(:,:,:,:,:) .ne. missing_val)
370 out_buffer_data(:,:,:,:,:) = out_buffer_data(:,:,:,:,:) &
375 do l = 1,
size(out_buffer_data, 4)
376 do k = 1,
size(out_buffer_data, 3)
377 do j = 1,
size(out_buffer_data, 2)
378 do i = 1,
size(out_buffer_data, 1)
379 if (wsum(i, j, k, l) .gt. 0)
then
380 out_buffer_data(i,j,k,l,:) = out_buffer_data(i,j,k,l,:)/ wsum(i,j,k,l)
383 out_buffer_data(i,j,k,l,:) = missing_val
392 out_buffer_data(:,:,:,:,:) = out_buffer_data(:,:,:,:,:) &
396 if(reduction_method .eq. time_rms .and. has_mask)
then
397 where(out_buffer_data(:,:,:,:,1) .ne. missing_val)
398 out_buffer_data(:,:,:,:,1) = sqrt(out_buffer_data(:,:,:,:,1))
400 else if(reduction_method .eq. time_rms)
then
401 out_buffer_data(:,:,:,:,1) = sqrt(out_buffer_data(:,:,:,:,1))