1 | ! $Id: ropp_io_thin_select.f90 1959 2008-11-13 12:15:18Z frhl $
|
---|
2 | !
|
---|
3 | !****s* Thin/ropp_io_thin_select *
|
---|
4 | !
|
---|
5 | ! NAME
|
---|
6 | ! ropp_io_thin_select - select & apply a thinning method
|
---|
7 | !
|
---|
8 | ! SYNOPSIS
|
---|
9 | !
|
---|
10 | ! CALL ropp_io_thin_select ( nLev, Lev, Val, &
|
---|
11 | ! nThinLev, ThinLev, ThinVal, &
|
---|
12 | ! Method, nSampLev, DEBUG, sigma )
|
---|
13 | !
|
---|
14 | ! INPUTS
|
---|
15 | ! nLev int no. of full levels
|
---|
16 | ! nThinLev int (max) no. of thinned levels
|
---|
17 | ! Lev dflt array of full levels
|
---|
18 | ! Val dflt array of full values
|
---|
19 | ! ThinLev dflt array of thinned levels
|
---|
20 | ! (with values set before input for SGLOG,
|
---|
21 | ! SGLIN, ASGLOG, ASGLIN, LOG or LIN only)
|
---|
22 | ! ThinVal dflt array of thinned values
|
---|
23 | ! Method chr Method string. One of: SGLOG, SGLIN,
|
---|
24 | ! ASGLOG, ASGLIN, LOG, LIN, SAMPLE, NONE
|
---|
25 | ! DEBUG log .T. to print diagnostics to stdout
|
---|
26 | ! sigma log .T. indicates error smoothing
|
---|
27 | ! (used for ASG* & SG* methods only)
|
---|
28 | !
|
---|
29 | ! OUTPUTS
|
---|
30 | ! nSampLev int actual no. of thinned levels
|
---|
31 | ! ThinLev dflt array of thinned levels
|
---|
32 | ! (with values set on output for SAMPLE only)
|
---|
33 | ! ThinVal dflt array of thinned values
|
---|
34 | ! Lev dflt array of full levels; on exit first nSamplev elements
|
---|
35 | ! is a copy of ThinLev, remainder are set 'missing'
|
---|
36 | ! Val dflt array of full values; on exit first nSamplev elements
|
---|
37 | ! is a copy of ThinLev, remainder are set 'missing'
|
---|
38 | !
|
---|
39 | ! CALLS
|
---|
40 | ! ropp_io_thin_fixed
|
---|
41 | ! ropp_io_thin_skip
|
---|
42 | ! where
|
---|
43 | !
|
---|
44 | ! CALLED BY
|
---|
45 | ! ropp_io_thin
|
---|
46 | !
|
---|
47 | ! USES
|
---|
48 | ! typesizes
|
---|
49 | ! ropp_io
|
---|
50 | ! ropp_utils
|
---|
51 | !
|
---|
52 | ! DESCRIPTION
|
---|
53 | ! This subroutine selects a thinning method from the input Method
|
---|
54 | ! string and calls the appropriate routine(s) to apply that
|
---|
55 | ! method to the input full levels and required output (thinned)
|
---|
56 | ! levels values to return the thinned values. The supported methods
|
---|
57 | ! include:
|
---|
58 | ! ASGLOG : Adaptive S-G smoothing filter with log interpolation
|
---|
59 | ! to fixed number of thinned levels (see Reference)
|
---|
60 | ! ASGLIN : Adaptive S-G smoothing filter with linear interpolation
|
---|
61 | ! to fixed number of thinned levels (see Reference)
|
---|
62 | ! SGLOG : Savitzky-Golay smoothing filter with log interpolation
|
---|
63 | ! to fixed number of thinned levels (see Reference)
|
---|
64 | ! SGLIN : Savitzky-Golay smoothing filter with linear interpolation
|
---|
65 | ! to fixed number of thinned levels (see Reference)
|
---|
66 | ! LOG : Logarithmic interpolation to fixed levels (no smoothing)
|
---|
67 | ! LIN : Linear interpolation to fixed levels (no smoothing)
|
---|
68 | ! SAMPLE : Simple sub-sampling (select or reject 1-in-N) to no more
|
---|
69 | ! than the array size of the thinned levels.
|
---|
70 | ! NONE : explicitly do nothing.
|
---|
71 | ! The DEBUG logical can be used to write diagnostic information
|
---|
72 | ! to stdout if set .T. This routine is otherwise silent.
|
---|
73 | !
|
---|
74 | ! REFERENCE
|
---|
75 | ! Mono-dimensional data thinning for GPS radio ccultations.
|
---|
76 | ! SAF/GRAS/METO/ALG/ROPP/001
|
---|
77 | !
|
---|
78 | ! AUTHOR
|
---|
79 | ! Met Office, Exeter, UK.
|
---|
80 | ! Any comments on this software should be given via the GRAS SAF
|
---|
81 | ! Helpdesk at http://www.grassaf.org
|
---|
82 | !
|
---|
83 | ! COPYRIGHT
|
---|
84 | ! (c) EUMETSAT. All rights reserved.
|
---|
85 | ! For further details please refer to the file COPYRIGHT
|
---|
86 | ! which you should have received as part of this distribution.
|
---|
87 | !
|
---|
88 | !****
|
---|
89 |
|
---|
90 | SUBROUTINE ropp_io_thin_select ( nLev, Lev, Val, &
|
---|
91 | nThinLev, ThinLev, ThinVal, &
|
---|
92 | Method, nSampLev, DEBUG, &
|
---|
93 | sigma )
|
---|
94 |
|
---|
95 | USE typesizes, ONLY: wp => EightByteReal
|
---|
96 | USE ropp_io, ONLY: ropp_io_thin_fixed, &
|
---|
97 | ropp_io_thin_skip
|
---|
98 | USE ropp_io_types, ONLY: ropp_io_mdfv, &
|
---|
99 | ropp_io_mdtv
|
---|
100 | USE ropp_utils, ONLY: where
|
---|
101 |
|
---|
102 |
|
---|
103 | IMPLICIT NONE
|
---|
104 |
|
---|
105 | ! Argument list parameters
|
---|
106 |
|
---|
107 | CHARACTER (LEN=*), INTENT(IN) :: Method ! thinning method
|
---|
108 | INTEGER, INTENT(IN) :: nLev ! no. full levels
|
---|
109 | INTEGER, INTENT(IN) :: nThinLev ! (max) no thinned levels
|
---|
110 | REAL(wp), INTENT(INOUT) :: Lev(nLev) ! input (full) levels
|
---|
111 | REAL(wp), INTENT(INOUT) :: Val(nLev) ! input (full) values
|
---|
112 | REAL(wp), INTENT(INOUT) :: ThinLev(nThinLev) ! output (thinned) levels
|
---|
113 | REAL(wp), INTENT(OUT) :: ThinVal(nThinLev) ! output (thinned) values
|
---|
114 | INTEGER, INTENT(OUT) :: nSampLev ! actual no. of thinned levels
|
---|
115 | LOGICAL, INTENT(IN) :: DEBUG ! .T. for extra disgnostics
|
---|
116 | LOGICAL, OPTIONAL, INTENT(IN) :: sigma ! .T. smoothing errrors
|
---|
117 |
|
---|
118 | ! Local variables
|
---|
119 |
|
---|
120 | INTEGER :: skip1, skip2 ! Skip factors
|
---|
121 | INTEGER :: i, j ! Loop counters
|
---|
122 | INTEGER :: nGood ! No. of valid values
|
---|
123 | INTEGER, DIMENSION(:), POINTER :: idx => NULL() ! Hold WHERE output
|
---|
124 | REAL(wp) :: LevGood(nLev) ! Valid input levels
|
---|
125 | REAL(wp) :: ValGood(nLev) ! Valid input values
|
---|
126 |
|
---|
127 | ! 1. Check for valid values data
|
---|
128 | ! ------------------------------
|
---|
129 |
|
---|
130 | idx => where ( Val > ropp_io_mdtv , nGood )
|
---|
131 |
|
---|
132 | IF ( nGood > 0 ) THEN
|
---|
133 | LevGood(1:nGood) = Lev(idx)
|
---|
134 | ValGood(1:nGood) = Val(idx)
|
---|
135 | ENDIF
|
---|
136 |
|
---|
137 | ! Thinning by one of several methods
|
---|
138 |
|
---|
139 | ! 2. Interpolation
|
---|
140 | !------------------
|
---|
141 |
|
---|
142 | IF ( INDEX ( Method, "SGLOG" ) == 1 .OR. &
|
---|
143 | INDEX ( Method, "SGLIN" ) == 1 .OR. &
|
---|
144 | INDEX ( Method, "ASGLOG" ) == 1 .OR. &
|
---|
145 | INDEX ( Method, "ASGLIN" ) == 1 .OR. &
|
---|
146 | INDEX ( Method, "LOG" ) == 1 .OR. &
|
---|
147 | INDEX ( Method, "LIN" ) == 1 ) THEN
|
---|
148 |
|
---|
149 | ! Count valid values; only interpolate if at least two good values on
|
---|
150 | ! valid levels, else just return all thinned values as missing on required
|
---|
151 | ! thinned levels. Interpolation routine will handle profiles containing
|
---|
152 | ! some missing data.
|
---|
153 |
|
---|
154 | IF ( nGood >= 2 ) then
|
---|
155 | CALL ropp_io_thin_fixed ( nGood, LevGood(1:nGood), ValGood(1:nGood), &
|
---|
156 | nThinLev, ThinLev, ThinVal, &
|
---|
157 | Method, DEBUG, sigma )
|
---|
158 | ELSE
|
---|
159 | IF ( DEBUG ) WRITE ( *, "(A)" ) " Warning: No valid data, only reducing array"
|
---|
160 | ThinVal(1:nThinLev) = ropp_io_mdfv
|
---|
161 | END IF
|
---|
162 | nSampLev = nThinLev
|
---|
163 |
|
---|
164 | Val(1:nSampLev) = ThinVal(1:nSampLev)
|
---|
165 | Lev(1:nSampLev) = ThinLev(1:nSampLev)
|
---|
166 | Val(nSampLev+1:nlev) = ropp_io_mdfv
|
---|
167 | Lev(nSampLev+1:nlev) = ropp_io_mdfv
|
---|
168 |
|
---|
169 | ! 3. Simple sub-sampling
|
---|
170 | !-----------------------
|
---|
171 |
|
---|
172 | ELSE IF ( INDEX ( Method, "SAMPLE" ) == 1 ) THEN
|
---|
173 |
|
---|
174 | IF ( nGood > nThinLev ) THEN
|
---|
175 | CALL ropp_io_thin_skip ( nGood, nThinLev, &
|
---|
176 | skip1, skip2, nSampLev, &
|
---|
177 | DEBUG )
|
---|
178 | ThinVal(:) = ropp_io_mdfv
|
---|
179 | ThinLev(:) = ropp_io_mdfv
|
---|
180 |
|
---|
181 | j = 0
|
---|
182 | DO i = 1, nGood, skip1 ! select every skip1-th sample
|
---|
183 | IF ( MOD(i,skip2) == 0 ) CYCLE ! reject every skip2-th sample
|
---|
184 | j = j + 1
|
---|
185 | ThinVal(j) = ValGood(i)
|
---|
186 | ThinLev(j) = LevGood(i)
|
---|
187 | END DO
|
---|
188 | nSampLev = j
|
---|
189 |
|
---|
190 | Val(1:nSampLev) = ThinVal(1:nSampLev)
|
---|
191 | Lev(1:nSampLev) = ThinLev(1:nSampLev)
|
---|
192 | Val(nSampLev+1:nLev) = ropp_io_mdfv
|
---|
193 | Lev(nSampLev+1:nLev) = ropp_io_mdfv
|
---|
194 | ELSE
|
---|
195 | IF ( DEBUG ) WRITE ( *, "(A)" ) "** Thinning not required"
|
---|
196 | nSamplev = nLev
|
---|
197 | END IF
|
---|
198 |
|
---|
199 | ! 4. No sampling at all - do nothing
|
---|
200 | !------------------------------------
|
---|
201 |
|
---|
202 | ELSE IF ( INDEX ( Method, "NONE") == 1 ) THEN
|
---|
203 | IF ( DEBUG ) WRITE ( *, "(A)" ) "** Thinning not required"
|
---|
204 | nSampLev = nLev
|
---|
205 |
|
---|
206 | ! 5. Unknown method - ignore
|
---|
207 | !----------------------------
|
---|
208 |
|
---|
209 | ELSE
|
---|
210 | IF ( DEBUG ) WRITE ( *, "(A)" ) "** Thinning method " // &
|
---|
211 | TRIM(Method) // &
|
---|
212 | " not supported"
|
---|
213 | nSampLev = nGood
|
---|
214 |
|
---|
215 | END IF
|
---|
216 |
|
---|
217 | END SUBROUTINE ropp_io_thin_select
|
---|