Skip to content

Commit 4d25356

Browse files
committed
Streaming filter
Using non-static-memory allocation for s1 and u1.
1 parent 5b5f260 commit 4d25356

File tree

1 file changed

+15
-43
lines changed

1 file changed

+15
-43
lines changed

src/parameterizations/lateral/MOM_streaming_filter.F90

+15-43
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ module MOM_streaming_filter
1717
real :: a, & !< Parameter that determines the bandwidth [nondim]
1818
om, & !< Target frequency of the filter [T-1 ~> s-1]
1919
old_time = -1.0 !< The time of the previous accumulating step [T ~> s]
20-
real ALLOCABLE_, dimension(NIMEM_,NJMEM_) :: s1_h, & !< Dummy variable on h grid [A]
21-
u1_h !< Filtered data on h grid [A]
22-
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_) :: s1_u, & !< Dummy variable on u grid [A]
23-
u1_u !< Filtered data on u grid [A]
24-
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_) :: s1_v, & !< Dummy variable on v grid [A]
25-
u1_v !< Filtered data on v grid [A]
20+
real, allocatable, dimension(:,:) :: s1, & !< Dummy variable [A]
21+
u1 !< Filtered data [A]
2622
!>@{ Lower and upper bounds of input data
2723
integer :: is, ie, js, je
2824
!>@}
@@ -52,16 +48,16 @@ subroutine Filt_register(a, om, grid, HI, CS)
5248

5349
select case (trim(grid))
5450
case ('h')
55-
ALLOC_(CS%s1_h(isd:ied,jsd:jed)) ; CS%s1_h(:,:) = 0.0
56-
ALLOC_(CS%u1_h(isd:ied,jsd:jed)) ; CS%u1_h(:,:) = 0.0
51+
allocate(CS%s1(isd:ied,jsd:jed)) ; CS%s1(:,:) = 0.0
52+
allocate(CS%u1(isd:ied,jsd:jed)) ; CS%u1(:,:) = 0.0
5753
CS%is = isd ; CS%ie = ied ; CS%js = jsd ; CS%je = jed
5854
case ('u')
59-
ALLOC_(CS%s1_u(IsdB:IedB,jsd:jed)) ; CS%s1_u(:,:) = 0.0
60-
ALLOC_(CS%u1_u(IsdB:IedB,jsd:jed)) ; CS%u1_u(:,:) = 0.0
55+
allocate(CS%s1(IsdB:IedB,jsd:jed)) ; CS%s1(:,:) = 0.0
56+
allocate(CS%u1(IsdB:IedB,jsd:jed)) ; CS%u1(:,:) = 0.0
6157
CS%is = IsdB ; CS%ie = IedB ; CS%js = jsd ; CS%je = jed
6258
case ('v')
63-
ALLOC_(CS%s1_v(isd:ied,JsdB:JedB)) ; CS%s1_v(:,:) = 0.0
64-
ALLOC_(CS%u1_v(isd:ied,JsdB:JedB)) ; CS%u1_v(:,:) = 0.0
59+
allocate(CS%s1(isd:ied,JsdB:JedB)) ; CS%s1(:,:) = 0.0
60+
allocate(CS%u1(isd:ied,JsdB:JedB)) ; CS%u1(:,:) = 0.0
6561
CS%is = isd ; CS%ie = ied ; CS%js = JsdB ; CS%je = JedB
6662
case default
6763
call MOM_error(FATAL, "MOM_streaming_filter: horizontal grid not supported")
@@ -71,9 +67,8 @@ end subroutine Filt_register
7167

7268
!> This subroutine timesteps the filter equations. It takes model output u at the current time step as the input,
7369
!! and returns tidal signal u1 as the output, which is the solution of a set of two ODEs (the filter equations).
74-
subroutine Filt_accum(u, u1, grid, Time, US, CS)
70+
subroutine Filt_accum(u, u1, Time, US, CS)
7571
real, dimension(:,:), pointer, intent(out) :: u1 !< Output of the filter [A]
76-
character(len=*), intent(in) :: grid !< Horizontal grid location: h, u, or v
7772
type(time_type), intent(in) :: Time !< The current model time
7873
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
7974
type(Filter_CS), target, intent(inout) :: CS !< Control structure of the MOM_streaming_filter module
@@ -91,13 +86,7 @@ subroutine Filt_accum(u, u1, grid, Time, US, CS)
9186
! Initialize u1
9287
if (CS%old_time < 0.0) then
9388
CS%old_time = now
94-
95-
select case (trim(grid))
96-
case ('h') ; CS%u1_h(:,:) = u(:,:)
97-
case ('u') ; CS%u1_u(:,:) = u(:,:)
98-
case ('v') ; CS%u1_v(:,:) = u(:,:)
99-
case default ; call MOM_error(FATAL, "MOM_streaming_filter: horizontal grid not supported")
100-
end select
89+
CS%u1(:,:) = u(:,:)
10190
endif
10291

10392
dt = now - CS%old_time
@@ -107,28 +96,11 @@ subroutine Filt_accum(u, u1, grid, Time, US, CS)
10796
c1 = CS%om * dt
10897
c2 = 1.0 - CS%a * c1
10998

110-
select case (trim(grid))
111-
case ('h')
112-
do j=js,je ; do i=is,ie
113-
CS%s1_h(i,j) = c1 * CS%u1_h(i,j) + CS%s1_h(i,j)
114-
CS%u1_h(i,j) = -c1 * (CS%s1_h(i,j) - CS%a * u(i,j)) + c2 * CS%u1_h(i,j)
115-
enddo; enddo
116-
u1 => CS%u1_h
117-
case ('u')
118-
do j=js,je ; do i=is,ie
119-
CS%s1_u(i,j) = c1 * CS%u1_u(i,j) + CS%s1_u(i,j)
120-
CS%u1_u(i,j) = -c1 * (CS%s1_u(i,j) - CS%a * u(i,j)) + c2 * CS%u1_u(i,j)
121-
enddo; enddo
122-
u1 => CS%u1_u
123-
case ('v')
124-
do j=js,je ; do i=is,ie
125-
CS%s1_v(i,j) = c1 * CS%u1_v(i,j) + CS%s1_v(i,j)
126-
CS%u1_v(i,j) = -c1 * (CS%s1_v(i,j) - CS%a * u(i,j)) + c2 * CS%u1_v(i,j)
127-
enddo; enddo
128-
u1 => CS%u1_v
129-
case default
130-
call MOM_error(FATAL, "MOM_streaming_filter: horizontal grid not supported")
131-
end select
99+
do j=js,je ; do i=is,ie
100+
CS%s1(i,j) = c1 * CS%u1(i,j) + CS%s1(i,j)
101+
CS%u1(i,j) = -c1 * (CS%s1(i,j) - CS%a * u(i,j)) + c2 * CS%u1(i,j)
102+
enddo; enddo
103+
u1 => CS%u1
132104

133105
end subroutine Filt_accum
134106

0 commit comments

Comments
 (0)