FMS 2025.01.02-dev
Flexible Modeling System
All Classes Namespaces Files Functions Variables Modules Pages
fms_diag_input_buffer.inc
1!***********************************************************************
2!* GNU Lesser General Public License
3!*
4!* This file is part of the GFDL Flexible Modeling System (FMS).
5!*
6!* FMS is free software: you can redistribute it and/or modify it under
7!* the terms of the GNU Lesser General Public License as published by
8!* the Free Software Foundation, either version 3 of the License, or (at
9!* your option) any later version.
10!*
11!* FMS is distributed in the hope that it will be useful, but WITHOUT
12!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14!* for more details.
15!*
16!* You should have received a copy of the GNU Lesser General Public
17!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18!***********************************************************************
19
20!> @brief Appends the input_data_buffer and the mask (only when the mask is set to .True.)
21subroutine append_data_buffer_(mask_out, mask_in, data_out, data_in)
22 logical, intent(inout) :: mask_out(:,:,:,:) !< Mask currently in the input_data_buffer
23 logical, intent(in) :: mask_in(:,:,:,:) !< Mask passed in to send_data
24 real(FMS_TRM_KIND_), intent(inout) :: data_out(:,:,:,:) !< Data currently in the input_data_buffer
25 real(FMS_TRM_KIND_), intent(in) :: data_in(:,:,:,:) !< Data passed in to send_data
26
27 integer :: i, j, k, l !< For looping through the input_data_buffer
28
29 do l = 1, size(data_out, 4)
30 do k = 1, size(data_out, 3)
31 do j = 1, size(data_out, 2)
32 do i = 1, size(data_out, 1)
33 if (mask_in(i,j,k,l)) then
34 mask_out(i,j,k,l) = .true.
35 data_out(i,j,k,l) = data_in(i,j,k,l)
36 endif
37 enddo
38 enddo
39 enddo
40 enddo
41
42end subroutine append_data_buffer_
43
44!> @brief Sums the data in the input_data_buffer
45subroutine sum_data_buffer_(mask, data_out, data_in, counter, var_is_masked)
46 logical, intent(in) :: mask(:,:,:,:) !< Mask passed into send_data
47 real(FMS_TRM_KIND_), intent(inout) :: data_out(:,:,:,:) !< Data currently saved in the input_data_buffer
48 real(FMS_TRM_KIND_), intent(in) :: data_in(:,:,:,:) !< Data passed into send_data
49 integer, intent(inout) :: counter(:,:,:,:) !< Number of times data has been summed
50 logical, intent(in) :: var_is_masked !< .True. if the variable is masked
51
52 if (var_is_masked) then
53 where (mask)
54 data_out = data_out + data_in
55 endwhere
56 else
57 data_out = data_out + data_in
58 endif
59
60 counter = counter + 1
61end subroutine SUM_DATA_BUFFER_