FMS  2025.03
Flexible Modeling System
horiz_interp_type.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 !> @addtogroup horiz_interp_type_mod
20 !> @{
21 !> @brief This statistics is for bilinear interpolation and spherical regrid.
22  subroutine stats_ ( dat, low, high, avg, miss, missing_value, mask )
23  real(FMS_HI_KIND_), intent(in) :: dat(:,:)
24  real(FMS_HI_KIND_), intent(out) :: low, high, avg
25  integer, intent(out) :: miss
26  real(FMS_HI_KIND_), intent(in), optional :: missing_value
27  real(FMS_HI_KIND_), intent(in), optional :: mask(:,:)
28 
29  real(FMS_HI_KIND_) :: dsum, buffer_real(3)
30  integer :: pe, root_pe, npes, p, buffer_int(2), npts
31  integer, parameter :: kindl = fms_hi_kind_ !< compiled kind size
32 
33  pe = mpp_pe()
34  root_pe = mpp_root_pe()
35  npes = mpp_npes()
36 
37  dsum = 0.0_kindl
38  miss = 0
39 
40  if (present(missing_value)) then
41  miss = count(dat(:,:) == missing_value)
42  low = minval(dat(:,:), dat(:,:) /= missing_value)
43  high = maxval(dat(:,:), dat(:,:) /= missing_value)
44  dsum = sum(dat(:,:), dat(:,:) /= missing_value)
45  else if(present(mask)) then
46  miss = count(mask(:,:) <= 0.5_kindl )
47  low = minval(dat(:,:),mask=mask(:,:) > 0.5_kindl)
48  high = maxval(dat(:,:),mask=mask(:,:) > 0.5_kindl)
49  dsum = sum(dat(:,:), mask=mask(:,:) > 0.5_kindl)
50  else
51  miss = 0
52  low = minval(dat(:,:))
53  high = maxval(dat(:,:))
54  dsum = sum(dat(:,:))
55  endif
56  avg = 0.0_kindl
57 
58  npts = size(dat(:,:)) - miss
59  if(pe == root_pe) then
60  do p = 1, npes - 1 ! root_pe receive data from other pe
61  ! Force use of "scalar", integer pointer mpp interface
62  call mpp_recv(buffer_real(1),glen=3, from_pe=p+root_pe, tag=comm_tag_1)
63  dsum = dsum + buffer_real(1)
64  low = min(low, buffer_real(2))
65  high = max(high, buffer_real(3))
66  call mpp_recv(buffer_int(1), glen=2, from_pe=p+root_pe, tag=comm_tag_2)
67  miss = miss + buffer_int(1)
68  npts = npts + buffer_int(2)
69  enddo
70  if(npts == 0) then
71  print*, 'Warning: no points is valid'
72  else
73  avg = dsum/real(npts, fms_hi_kind_)
74  endif
75  else ! other pe send data to the root_pe.
76  buffer_real(1) = dsum
77  buffer_real(2) = low
78  buffer_real(3) = high
79  ! Force use of "scalar", integer pointer mpp interface
80  call mpp_send(buffer_real(1),plen=3,to_pe=root_pe, tag=comm_tag_1)
81  buffer_int(1) = miss
82  buffer_int(2) = npts
83  call mpp_send(buffer_int(1), plen=2, to_pe=root_pe, tag=comm_tag_2)
84  endif
85 
86  call mpp_sync_self()
87 
88  return
89 
90  end subroutine stats_
subroutine stats_(dat, area, asum, dsum, wsum, low, high, miss, mask)
This statistics is for conservative scheme.
subroutine mpp_sync_self(pelist, check, request, msg_size, msg_type)
This is to check if current PE's outstanding puts are complete but we can't use shmem_fence because w...
integer function mpp_npes()
Returns processor count for current pelist.
Definition: mpp_util.inc:421
integer function mpp_pe()
Returns processor ID.
Definition: mpp_util.inc:407