1 subroutine da_scan_obs_radar (iv, filename, grid)
3 !---------------------------------------------------------------------------
4 ! Purpose: Scan the radar observation file
5 !---------------------------------------------------------------------------
9 type (iv_type), intent(inout) :: iv
10 character(len=*), intent(in) :: filename
11 type(domain), intent(in) :: grid ! first guess state.
13 integer :: i, j, n, iost, nlevels, fm
14 integer :: total_radar
17 type (radar_multi_level_type) :: platform
19 character (LEN = 120) :: char_total_radar
20 character (LEN = 120) :: char_ned
22 logical :: outside, outside_all
23 integer :: n_dup, ndup
26 integer :: iyear, imonth, iday, ihour, imin
29 if (trace_use) call da_trace_entry("da_scan_obs_radar")
34 call da_get_unit(iunit)
36 FILE = trim(filename), &
38 ACCESS = 'SEQUENTIAL', &
43 ! Does not matter of radar file missing
44 call da_warning(__FILE__,__LINE__, &
45 (/"Cannot open radar file "//filename/))
46 call da_free_unit(iunit)
47 if (trace_use) call da_trace_exit("da_scan_obs_radar")
60 read (unit=iunit, fmt = '(A)', iostat = iost) char_total_radar
62 ! Does matter if present and unreadable
63 call da_error(__FILE__,__LINE__, &
64 (/"Cannot read radar file"/))
67 ! 2.3 total radar number
69 read (unit=char_total_radar (15:17),fmt='(I3)', iostat = iost) total_radar
73 read (unit=iunit, fmt = '(A)', iostat = iost)
79 ! 3.1 skip one blank line
81 read (unit=iunit, fmt = '(A)', iostat = iost)
85 read (unit=iunit, fmt = '(A)', iostat = iost) char_ned
87 write(unit=message(1),fmt='(A,I3)')'Error reading header information for station number ',n
88 call da_error(__FILE__,__LINE__,message(1:1))
91 ! 3.3 read header information
93 read (unit=char_ned (69:74), fmt='(I6)', iostat = iost) platform % stn % numobs
95 if(char_ned (1:5).ne."RADAR") then
96 write(unit=message(1),fmt='(A,I3)')'Error reading header information for station number ',n
97 call da_error(__FILE__,__LINE__,message(1:1))
102 read (unit=iunit, fmt = '(A)', iostat = iost)
103 read (unit=iunit, fmt = '(A)', iostat = iost)
105 ! 3.5 loop over records
107 reports: do j = 1, platform % stn % numobs
109 ! 3.5.1 read station general info
111 read (unit = iunit, iostat = iost, &
112 fmt = '(A12,3X,A19,2X,2(F12.3,2X),F8.1,2X,I6)') &
113 platform % info % platform, &
114 platform % info % date_char, &
115 platform % info % lat, &
116 platform % info % lon, &
117 platform % info % elv, &
118 platform % info % levels
121 write(unit=message(1),fmt='(A)')'Error reading next observation for '
122 write(unit=message(2),fmt='(A)')char_ned
123 write(unit=message(3),fmt='(A,I6,A,I6)')'Observation number ',j,' out of ',platform % stn % numobs
124 call da_error(__FILE__,__LINE__,message(1:3))
127 if (platform%info%lon == 180.0 ) platform%info%lon =-180.000
128 ! Fix funny wind direction at Poles
129 if (platform%info%lat < -89.9999 .or. platform%info%lat > 89.9999) then
130 platform%info%lon = 0.0
133 read(unit=platform % info % platform (4:6), fmt='(I3)') fm
135 ! 3.5.2 read each level
137 do i = 1, platform % info % levels
139 platform%each (i) = radar_each_level_type(missing_r, missing, -1.0,&
140 field_type(missing_r, missing, missing_r, missing, missing_r), & ! rv
141 field_type(missing_r, missing, missing_r, missing, missing_r)) ! rf
143 read (unit = iunit, fmt = '(3X, F12.1, 2(F12.3,I4,F12.3,2X))', iostat = iost) &
144 platform % each (i) % height, &
145 platform % each (i) % rv % inv, &
146 platform % each (i) % rv % qc, &
147 platform % each (i) % rv % error, &
148 platform % each (i) % rf % inv, &
149 platform % each (i) % rf % qc, &
150 platform % each (i) % rf % error
153 write(unit=message(1),fmt='(A)')'Error reading next level for '
154 write(unit=message(2),fmt='(A)')char_ned
155 write(unit=message(3),fmt='(A,I6,A,I6)')'Observation number ',j,' out of ',platform % stn % numobs
156 call da_error(__FILE__,__LINE__,message(1:3))
159 if (platform % each (i) % rv % error == 0.0) then
160 platform % each (i) % rv % error = 1.0
163 if (platform % each (i) % rf % error == 0.0) then
164 platform % each (i) % rf % error = 1.0
167 if (platform % each (i) % rv % inv == missing_r .or. &
168 platform % each (i) % rv % error == missing_r) then
169 platform % each (i) % rv % qc = missing_data
172 if (platform % each (i) % rf % inv == missing_r .or. &
173 platform % each (i) % rf % error == missing_r) then
174 platform % each (i) % rf % qc = missing_data
179 ! Check if outside of the time range:
181 read (platform%info%date_char,'(i4,4(1x,i2))', iostat = iost) &
182 iyear, imonth, iday, ihour, imin
184 write(unit=message(1),fmt='(A,A,A)')'Bad date: ',platform % info % date_char,' found for'
185 write(unit=message(2),fmt='(A)')char_ned
186 write(unit=message(3),fmt='(A,I6,A,I6)')'Observation number ',j,' out of ',platform % stn % numobs
187 write(unit=message(4),fmt='(A)')'This is usually due to an incorrect number of vertical levels in the previous observation'
188 call da_error(__FILE__,__LINE__,message(1:4))
190 call da_get_julian_time (iyear,imonth,iday,ihour,imin,obs_time)
191 if ( obs_time < time_slots(0) .or. &
192 obs_time >= time_slots(num_fgat_time) ) then
196 call da_llxy (platform%info, platform%loc, outside, outside_all)
197 if( outside_all .and. multi_inc == 0 ) cycle reports
199 nlevels = platform%info%levels
201 if (nlevels > max_ob_levels) then
202 write(unit=message(1),fmt='(A,2I8)') &
203 ' radar=> nlevels > max_ob_levels:',nlevels, max_ob_levels
204 call da_warning(__FILE__,__LINE__,message(1:1))
206 nlevels = max_ob_levels
207 platform%info%levels = nlevels
208 else if (nlevels < 1) then
213 ! Loop over duplicating obs for global
215 if (global .and. (platform%loc%i == ids .or. platform%loc%i == ide)) n_dup= 2
221 if (.not.use_radarobs .or. iv%info(radar)%ntotal == max_radar_input) cycle reports
222 if (ndup==1) iv%info(radar)%ntotal = iv%info(radar)%ntotal + 1
223 if (outside) cycle reports
224 iv%info(radar)%nlocal = iv%info(radar)%nlocal + 1
227 write(unit=stdout, fmt='(a)') 'Warning: unsaved obs found:'
229 write(unit=stdout, fmt='(2a)') &
230 'platform % info % platform=', platform % info % platform
232 write(unit=stdout, fmt='(a, i3)') &
233 'platform % info % levels=', platform % info % levels
236 iv%info(radar)%max_lev = max(iv%info(radar)%max_lev, platform%info%levels)
237 end do ! loop over duplicate
243 call da_free_unit(iunit)
245 if (trace_use) call da_trace_exit("da_scan_obs_radar")
247 end subroutine da_scan_obs_radar