FV3 Bundle
gsw_add_barrier.f90
Go to the documentation of this file.
1 !==========================================================================
2 pure subroutine gsw_add_barrier (input_data, long, lat, long_grid, &
3  lat_grid, dlong_grid, dlat_grid, output_data)
4 !==========================================================================
5 !
6 ! Adds a barrier through Central America (Panama) and then averages
7 ! over the appropriate side of the barrier
8 !
9 ! data_in : data [unitless]
10 ! long : Long of data in decimal degs east [ 0 ... +360 ]
11 ! lat : Lat of data in decimal degs north [-90 ... +90 ]
12 ! longs_grid : Long of regular grid in decimal degs east [ 0 ... +360 ]
13 ! lats_grid : Lat of regular grid in decimal degs north [-90 ... +90 ]
14 ! dlongs_grid : Long difference of regular grid in decimal degs [ deg long ]
15 ! dlats_grid : Lat difference of regular grid in decimal degs [ deg lat ]
16 !
17 ! output_data : average of data depending on which side of the
18 ! Panama canal it is on [unitless]
19 !--------------------------------------------------------------------------
20 
22 
24 
25 use gsw_mod_kinds
26 
27 implicit none
28 
29 real (r8), intent(in) :: long, lat, long_grid, lat_grid, dlong_grid
30 real (r8), intent(in) :: dlat_grid
31 real (r8), intent(in), dimension(4) :: input_data
32 real (r8), intent(out), dimension(4) :: output_data
33 
34 integer, dimension(4) :: above_line
35 integer :: k, nmean, above_line0, kk
36 real (r8) :: r, lats_line, data_mean
37 
38 k = gsw_util_indx(longs_pan,long) ! the long/lat point
39 r = (long-longs_pan(k))/(longs_pan(k+1)-longs_pan(k))
40 lats_line = lats_pan(k) + r*(lats_pan(k+1)-lats_pan(k))
41 
42 if (lats_line.le.lat) then
43  above_line0 = 1
44 else
45  above_line0 = 0
46 end if
47 
48 k = gsw_util_indx(longs_pan,long_grid) ! the 1 and 4 long/lat pts
49 r = (long_grid-longs_pan(k))/(longs_pan(k+1)-longs_pan(k))
50 lats_line = lats_pan(k) + r*(lats_pan(k+1)-lats_pan(k))
51 
52 if (lats_line.le.lat_grid) then
53  above_line(1) = 1
54 else
55  above_line(1) = 0
56 end if
57 
58 if (lats_line.le.lat_grid+dlat_grid) then
59  above_line(4) = 1
60 else
61  above_line(4) = 0
62 end if
63 
64 k = gsw_util_indx(longs_pan,long_grid+dlong_grid) ! the 2 & 3 points
65 r = (long_grid+dlong_grid-longs_pan(k))/(longs_pan(k+1)-longs_pan(k))
66 lats_line = lats_pan(k) + r*(lats_pan(k+1)-lats_pan(k))
67 
68 if (lats_line.le.lat_grid) then
69  above_line(2) = 1
70 else
71  above_line(2) = 0
72 end if
73 
74 if (lats_line.le.lat_grid+dlat_grid) then
75  above_line(3) = 1
76 else
77  above_line(3) = 0
78 end if
79 
80 nmean = 0
81 data_mean = 0.0_r8
82 
83 do kk = 1,4
84  if ((abs(input_data(kk)).le.100._r8).and.above_line0.eq.above_line(kk)) then
85  nmean = nmean + 1
86  data_mean = data_mean + input_data(kk)
87  end if
88 end do
89 
90 if (nmean .eq. 0)then
91  data_mean = 0.0_r8 !errorreturn
92 else
93  data_mean = data_mean/nmean
94 endif
95 
96 do kk = 1,4
97  if ((abs(input_data(kk)).ge.1e10_r8).or.above_line0.ne.above_line(kk)) then
98  output_data(kk) = data_mean
99  else
100  output_data(kk) = input_data(kk)
101  end if
102 end do
103 
104 return
105 end subroutine
106 
107 !--------------------------------------------------------------------------
pure subroutine gsw_add_barrier(input_data, long, lat, long_grid, lat_grid, dlong_grid, dlat_grid, output_data)
integer, parameter, public long
Definition: Type_Kinds.f90:76
real(r8), dimension(npan) longs_pan
real(r8), dimension(npan) lats_pan