FMS  2025.04
Flexible Modeling System
horiz_interp_type.inc
1 !***********************************************************************
2 !* Apache License 2.0
3 !*
4 !* This file is part of the GFDL Flexible Modeling System (FMS).
5 !*
6 !* Licensed under the Apache License, Version 2.0 (the "License");
7 !* you may not use this file except in compliance with the License.
8 !* You may obtain a copy of the License at
9 !*
10 !* http://www.apache.org/licenses/LICENSE-2.0
11 !*
12 !* FMS is distributed in the hope that it will be useful, but WITHOUT
13 !* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
14 !* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 !* PARTICULAR PURPOSE. See the License for the specific language
16 !* governing permissions and limitations under the License.
17 !***********************************************************************
18 !> @addtogroup horiz_interp_type_mod
19 !> @{
20 !> @brief This statistics is for bilinear interpolation and spherical regrid.
21  subroutine stats_ ( dat, low, high, avg, miss, missing_value, mask )
22  real(FMS_HI_KIND_), intent(in) :: dat(:,:)
23  real(FMS_HI_KIND_), intent(out) :: low, high, avg
24  integer, intent(out) :: miss
25  real(FMS_HI_KIND_), intent(in), optional :: missing_value
26  real(FMS_HI_KIND_), intent(in), optional :: mask(:,:)
27 
28  real(FMS_HI_KIND_) :: dsum, buffer_real(3)
29  integer :: pe, root_pe, npes, p, buffer_int(2), npts
30  integer, parameter :: kindl = fms_hi_kind_ !< compiled kind size
31 
32  pe = mpp_pe()
33  root_pe = mpp_root_pe()
34  npes = mpp_npes()
35 
36  dsum = 0.0_kindl
37  miss = 0
38 
39  if (present(missing_value)) then
40  miss = count(dat(:,:) == missing_value)
41  low = minval(dat(:,:), dat(:,:) /= missing_value)
42  high = maxval(dat(:,:), dat(:,:) /= missing_value)
43  dsum = sum(dat(:,:), dat(:,:) /= missing_value)
44  else if(present(mask)) then
45  miss = count(mask(:,:) <= 0.5_kindl )
46  low = minval(dat(:,:),mask=mask(:,:) > 0.5_kindl)
47  high = maxval(dat(:,:),mask=mask(:,:) > 0.5_kindl)
48  dsum = sum(dat(:,:), mask=mask(:,:) > 0.5_kindl)
49  else
50  miss = 0
51  low = minval(dat(:,:))
52  high = maxval(dat(:,:))
53  dsum = sum(dat(:,:))
54  endif
55  avg = 0.0_kindl
56 
57  npts = size(dat(:,:)) - miss
58  if(pe == root_pe) then
59  do p = 1, npes - 1 ! root_pe receive data from other pe
60  ! Force use of "scalar", integer pointer mpp interface
61  call mpp_recv(buffer_real(1),glen=3, from_pe=p+root_pe, tag=comm_tag_1)
62  dsum = dsum + buffer_real(1)
63  low = min(low, buffer_real(2))
64  high = max(high, buffer_real(3))
65  call mpp_recv(buffer_int(1), glen=2, from_pe=p+root_pe, tag=comm_tag_2)
66  miss = miss + buffer_int(1)
67  npts = npts + buffer_int(2)
68  enddo
69  if(npts == 0) then
70  print*, 'Warning: no points is valid'
71  else
72  avg = dsum/real(npts, fms_hi_kind_)
73  endif
74  else ! other pe send data to the root_pe.
75  buffer_real(1) = dsum
76  buffer_real(2) = low
77  buffer_real(3) = high
78  ! Force use of "scalar", integer pointer mpp interface
79  call mpp_send(buffer_real(1),plen=3,to_pe=root_pe, tag=comm_tag_1)
80  buffer_int(1) = miss
81  buffer_int(2) = npts
82  call mpp_send(buffer_int(1), plen=2, to_pe=root_pe, tag=comm_tag_2)
83  endif
84 
85  call mpp_sync_self()
86 
87  return
88 
89  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:420
integer function mpp_pe()
Returns processor ID.
Definition: mpp_util.inc:406