FV3 Bundle
gsw_add_mean.f90
Go to the documentation of this file.
1 !==========================================================================
2 pure subroutine gsw_add_mean (data_in, data_out)
3 !==========================================================================
4 !
5 ! Replaces NaN's with non-nan mean of the 4 adjacent neighbours
6 !
7 ! data_in : data set of the 4 adjacent neighbours
8 !
9 ! data_out : non-nan mean of the 4 adjacent neighbours [unitless]
10 !--------------------------------------------------------------------------
11 
12 use gsw_mod_kinds
13 
14 implicit none
15 
16 real (r8), intent(in), dimension(4) :: data_in
17 real (r8), intent(out), dimension(4) :: data_out
18 
19 integer :: k, nmean
20 
21 real (r8) :: data_mean
22 
23 nmean = 0
24 data_mean = 0.0_r8
25 
26 do k = 1,4
27  if (abs(data_in(k)).le.100.0_r8) then
28  nmean = nmean + 1
29  data_mean = data_mean + data_in(k)
30  end if
31 end do
32 
33 if(nmean.eq.0)then
34  data_mean = 0.0_r8 !error return
35 else
36  data_mean = data_mean/nmean
37 endif
38 
39 do k = 1,4
40  if(abs(data_in(k)).le.100.0_r8) then
41  data_out(k) = data_in(k)
42  else
43  data_out(k) = data_mean
44  end if
45 end do
46 
47 return
48 end subroutine
49 
50 !--------------------------------------------------------------------------
pure subroutine gsw_add_mean(data_in, data_out)
Definition: gsw_add_mean.f90:3