wrf svn trunk commit r4103
[wrffire.git] / wrfv2_fire / var / da / da_recursive_filter / da_recursive_filter_1d.inc
blobaf2f47800a8a72b87e9492f9926a40e49bc68ad0
1 subroutine da_recursive_filter_1d(pass, alpha, field, n)
3    !---------------------------------------------------------------------------
4    ! Purpose: Perform one pass of recursive filter on 1D array.
5    !
6    ! Method:  Perform right-moving filter followed by left-moving filter.
7    !---------------------------------------------------------------------------
9    implicit none
11    integer, intent(in)    :: pass           ! Current pass of filter.
12    real,    intent(in)    :: alpha          ! Alpha coefficient for RF.
13    real,    intent(inout) :: field(:)       ! Array to be filtered.
14    integer, intent(in)    :: n              ! Size of field array.
16    integer :: j              ! Loop counter.
17    real    :: one_alpha      ! 1 - alpha.
18    real    :: a(1:n)         ! Input field.
19    real    :: b(1:n)         ! Field after left-right pass.
20    real    :: c(1:n)         ! Field after right-left pass.
22    if (trace_use_dull) call da_trace_entry("da_recursive_filter_1d")
23    
24    !-------------------------------------------------------------------------
25    ! [1.0] Initialise:
26    !-------------------------------------------------------------------------
28    one_alpha = 1.0 - alpha
29    
30    a(1:n) = field(1:n)
32    !-------------------------------------------------------------------------
33    ! [2.0] Perform right-moving filter:
34    !-------------------------------------------------------------------------
36    ! use turning conditions as in the appendix of Hayden & Purser (1995):
38    if (pass == 1) then
39       b(1) = one_alpha * a(1)
40    else if (pass == 2) then
41       b(1) = a(1) / (1.0 + alpha)
42    else
43       b(1) = one_alpha * (a(1) - alpha**3 * a(2)) / (1.0 - alpha**2)**2
44    end if
46    ! [2.2] Perform pass left to right:
48    do j = 2, n
49       b(j) = alpha * b(j-1) + one_alpha * a(j)
50    end do
52    !-------------------------------------------------------------------------
53    ! [3.0] Perform left-moving filter:
54    !-------------------------------------------------------------------------
56    ! use turning conditions as in the appendix of Hayden & Purser (1995):
58    if (pass == 1) then
59       c(n) = b(n) / (1.0 + alpha)
60    else
61       c(n) = one_alpha * (b(n) - alpha**3 * b(n-1)) / (1.0 - alpha**2)**2
62    end if
64    ! [3.2] Perform pass left to right:
66    do j = n-1, 1, -1
67       c(j) = alpha * c(j+1) + one_alpha * b(j)
68    end do
69         
70    field(1:n) = c(1:n)
72    if (trace_use_dull) call da_trace_exit("da_recursive_filter_1d")
73    
74 end subroutine da_recursive_filter_1d