1 subroutine da_read_obs_hdf5amsr2 (iv, infile_tb,infile_clw)
2 !--------------------------------------------------------
3 ! Purpose: read in JAXA AMSR2 Level-1R data in HDF5 format
4 ! and form innovation structure
6 ! METHOD: use F90 sequantial data structure to avoid read the file twice
7 ! 1. read file radiance data in sequential data structure
9 ! 3. assign sequential data structure to innovation structure
10 ! and deallocate sequential data structure
12 ! HISTORY: 2013/10/22 - Creation Syed RH Rizvi, NCAR/NESL/MMM/DAS
13 ! 2014 Modification Chun Yang
14 !------------------------------------------------------------------------------
18 character(len=*), intent(in) :: infile_tb, infile_clw
19 type(iv_type), intent(inout) :: iv
22 ! fixed parameter values
23 integer,parameter::max_scan=2200 ! Maximum allowed NumberOfScans
24 integer,parameter::ovr=20 ! Number of OverlapScans
25 integer,parameter::hi_rez_fov=486 ! high resolution pixel width
26 integer,parameter::lo_rez_fov=243 ! low resolution pixel width
27 integer,parameter::time_dims=6 ! Time dimension
28 integer,parameter::nfile_max = 8 ! each hdf file contains ~50min of data
29 ! at most 8 files for a 6-h time window
31 integer iret ! return status
32 integer(HID_T) fhnd1, fhnd2, fhnd3 ! file handle
33 integer(HID_T) ahnd1, ahnd2, ahnd3 ! attribute handle
34 integer(HID_T) dhnd1, dhnd2, dhnd3 ! dataset handle
35 integer(HID_T) shnd1, shnd2, shnd3 ! dataspace handle
36 integer(HSIZE_T) sz1(3) ! array size 1
37 integer(HSIZE_T) sz2(3) ! array size 2
39 integer(4) :: nscan ! NumberOfScans
40 real(4) :: sca ! ScaleFactor
41 real(8) :: r8d1(max_scan) ! array buffer for real(8) D1
42 integer(4) :: i4d2hi(hi_rez_fov,max_scan) ! array buffer for integer(4) D2 high
44 type AM2_COMMON_SCANTIME
57 type(AM2_COMMON_SCANTIME) st(max_scan) ! scantime
58 real(4) :: lat89ar(hi_rez_fov,max_scan) ! lat for 89a altitude revised
59 real(4) :: latlr(lo_rez_fov,max_scan) ! lat for low resolution
60 real(4) :: lon89ar(hi_rez_fov,max_scan) ! lon for 89a altitude revised
61 real(4) :: lonlr(lo_rez_fov,max_scan) ! lon for low resolution
63 real(4) :: tb89ah(hi_rez_fov,max_scan) ! tb for 89ah
64 real(4) :: tb89av(hi_rez_fov,max_scan) ! tb for 89av
66 integer(4) :: loflo(lo_rez_fov,max_scan*4) ! land ocean flag for low
67 integer(1) :: lof06(lo_rez_fov,max_scan) ! land ocean flag for 06
68 integer(1) :: lof10(lo_rez_fov,max_scan) ! land ocean flag for 10
69 integer(1) :: lof23(lo_rez_fov,max_scan) ! land ocean flag for 23
70 integer(1) :: lof36(lo_rez_fov,max_scan) ! land ocean flag for 36
72 integer(4) :: lofhi(hi_rez_fov,max_scan*2) ! land ocean flag for high
73 integer(1) :: lof89a(hi_rez_fov,max_scan) ! land ocean flag for 89a
74 integer(1) :: lof89b(hi_rez_fov,max_scan) ! land ocean flag for 89b
76 real(4) :: ear_in(lo_rez_fov,max_scan) ! earth incidence
77 real(4) :: ear_az(lo_rez_fov,max_scan) ! earth azimuth
78 real(4) :: clw(lo_rez_fov,max_scan) ! obs retrieved cloud liquid water
80 real(4) :: sun_az(lo_rez_fov,max_scan) ! sun_azimuth
81 real(4) :: sun_el(lo_rez_fov,max_scan) ! sun_elevation
82 real(4) :: sun_zen(lo_rez_fov,max_scan) ! sun_zenith
84 real(r_kind) :: R90 = 90.0_r_kind
85 real(r_kind),parameter :: tbmin = 50._r_kind
86 real(r_kind),parameter :: tbmax = 550._r_kind
88 real(4) :: sat_zenith(lo_rez_fov,max_scan)
89 real(4) :: sat_azimuth(lo_rez_fov,max_scan)
91 real(kind=8) :: obs_time
92 type (datalink_type),pointer :: head, p, current, prev
93 type(info_type) :: info
94 type(model_loc_type) :: loc
96 integer(i_kind) :: idate5(6)
98 integer(i_kind) :: inst,platform_id,satellite_id,sensor_id
99 real(r_kind) :: tb, crit
100 integer(i_kind) :: ifgat, iout, iobs
101 logical :: outside, outside_all, iuse
103 integer :: i,j,k,l,m,n, ifile, landsea_mask
104 logical :: found, head_found, head_allocated
106 ! Other work variables
107 real(r_kind) :: dlon_earth,dlat_earth
108 integer(i_kind) :: num_amsr2_local, num_amsr2_global, num_amsr2_used, num_amsr2_thinned
109 integer(i_kind) :: num_amsr2_used_tmp, num_amsr2_file
110 integer(i_kind) :: num_amsr2_local_local, num_amsr2_global_local, num_amsr2_file_local
111 integer(i_kind) :: itx, itt
112 character(80) :: filename1, filename2
113 integer :: nchan,ifov,iscan,ichannels
115 character(80) :: fname_tb(nfile_max)
116 character(80) :: fname_clw(nfile_max)
117 logical :: fexist, got_clw_file
120 integer(i_kind),allocatable :: ptotal(:)
121 real,allocatable :: in(:), out(:)
122 real(r_kind),allocatable :: data_all(:)
124 real,allocatable :: obstime(:,:)
126 real(r_kind) :: sun_zenith, sun_azimuth
128 integer,parameter :: num_low_freq_chan=12
129 real(4) :: tb_low(lo_rez_fov,max_scan,num_low_freq_chan)
130 character(len=80) tb_low_name(num_low_freq_chan)
131 data tb_low_name/'Brightness Temperature (res06,6.9GHz,V)','Brightness Temperature (res06,6.9GHz,H)',&
132 'Brightness Temperature (res06,7.3GHz,V)','Brightness Temperature (res06,7.3GHz,H)',&
133 'Brightness Temperature (res10,10.7GHz,V)','Brightness Temperature (res10,10.7GHz,H)',&
134 'Brightness Temperature (res23,18.7GHz,V)','Brightness Temperature (res23,18.7GHz,H)',&
135 'Brightness Temperature (res23,23.8GHz,V)','Brightness Temperature (res23,23.8GHz,H)',&
136 'Brightness Temperature (res36,36.5GHz,V)','Brightness Temperature (res36,36.5GHz,H)'/
138 if (trace_use) call da_trace_entry("da_read_obs_hdf5amsr2")
140 ! 0.0 Initialize variables
141 !-----------------------------------
142 head_allocated = .false.
143 platform_id = 29 ! Table-2 Col 1 corresponding to 'gcom-w'
144 satellite_id = 1 ! Table-2 Col 3
145 sensor_id = 63 ! Table-3 Col 2 corresponding to 'amsr2'
147 allocate(ptotal(0:num_fgat_time))
148 ptotal(0:num_fgat_time) = 0
149 iobs = 0 ! for thinning, argument is inout
154 num_amsr2_thinned = 0
156 do i = 1, rtminit_nsensor
157 if (platform_id == rtminit_platform(i) &
158 .and. satellite_id == rtminit_satid(i) &
159 .and. sensor_id == rtminit_sensor(i)) then
165 call da_warning(__FILE__,__LINE__, &
166 (/"The combination of Satellite_Id and Sensor_Id for AMSR-2 is not found"/))
167 if (trace_use) call da_trace_exit("da_read_obs_hdf5amsr2")
171 ! Initialize HDF5 library and Fortran90 interface
174 call da_warning(__FILE__,__LINE__, &
175 (/"Problems in Initializing HDF5 library. Can not read AMSR-2 HDF5 data. "/))
176 if (trace_use) call da_trace_exit("da_read_obs_hdf5amsr2")
180 nchan = iv%instid(inst)%nchan
181 write(unit=stdout,fmt=*)'AMSR2 nchan: ',nchan
182 allocate(data_all(1:nchan))
184 ! 1.0 Assign file names and prepare to read amsr2 files
185 !-------------------------------------------------------------------------
186 nfile = 0 !initialize
187 fname_tb(:) = '' !initialize
188 ! first check if L1SGRTBR.h5 is available
189 filename1 = trim(infile_tb)//'.h5'
190 filename2 = trim(infile_clw)//'.h5'
191 inquire (file=filename1, exist=fexist)
194 fname_tb(nfile) = filename1
195 fname_clw(nfile) = filename2
197 ! check if L1SGRTBR-0x.h5 is available for multiple input files
198 ! here 0x is the input file sequence number
199 ! do not confuse it with fgat time slot index
201 write(filename1,fmt='(A,A,I2.2,A)') trim(infile_tb),'-',i,'.h5'
202 write(filename2,fmt='(A,A,I2.2,A)') trim(infile_clw),'-',i,'.h5'
203 inquire (file=filename1, exist=fexist)
206 fname_tb(nfile) = filename1
207 fname_clw(nfile) = filename2
214 if ( nfile == 0 ) then
215 call da_warning(__FILE__,__LINE__, &
216 (/"No valid AMSR-2 L1SGRTBR.h5 or L1SGRTBR-01.h5 file found."/))
217 if (trace_use) call da_trace_exit("da_read_obs_hdf5amsr2")
221 ! Check to see if leap second file exists for graceful failure
222 inquire( file='leapsec.dat', exist=fexist )
223 if (.not. fexist) call da_error(__FILE__,__LINE__, &
224 (/'Can not find leapsec.dat for AMSR2 data: copy or link from WRFDA/var/run'/))
226 infile_loop: do ifile = 1, nfile
227 num_amsr2_file_local = 0
228 num_amsr2_local_local = 0
229 num_amsr2_global_local = 0
231 ! open HDF5 file for read
232 call H5Fopen_f(fname_tb(ifile),H5F_ACC_RDONLY_F,fhnd1,iret,H5P_DEFAULT_F)
234 call da_warning(__FILE__,__LINE__, &
235 (/"Cannot open HDF5 file "//trim(fname_tb(ifile))/))
238 got_clw_file = .false.
239 call H5Fopen_f(fname_clw(ifile),H5F_ACC_RDONLY_F,fhnd2,iret,H5P_DEFAULT_F)
240 if ( iret == 0 ) then
241 got_clw_file = .true.
243 ! to do: when got_clw_file=.true., need to check GranuleID for consistency
244 ! betweee tb and clw files
246 ! calculate NumberOfScans from array size and OverlapScans
247 call H5Dopen_f(fhnd1,'Scan Time',dhnd1,iret)
248 call H5Dget_space_f(dhnd1,shnd1,iret)
249 call H5Sget_simple_extent_dims_f(shnd1,sz1,sz2,iret)
251 call da_warning(__FILE__,__LINE__, &
252 (/"HDF5 read problem for: Scan Time"/))
254 call H5Sclose_f(shnd1,iret)
255 call H5Dclose_f(dhnd1,iret)
259 write(unit=stdout,fmt=*)'NumberOfScans(RETRIEVE BY ARRAY SIZE): ',nscan
260 write(unit=stdout,fmt=*)'OverlapScans(FIXED VALUE): ',ovr
263 if(nscan.gt.max_scan)then
264 write(unit=stdout,fmt=*)'limit of NumberOfScans = ',max_scan
265 call da_warning(__FILE__,__LINE__, &
266 (/"HDF5 lmit error for: max_scan"/))
269 ! read array: scantime
271 call H5Dopen_f(fhnd1,'Scan Time',dhnd1,iret)
273 call H5Dread_f(dhnd1, &
274 H5T_NATIVE_DOUBLE,r8d1,sz1,iret,H5S_ALL_F,H5S_ALL_F)
276 call da_warning(__FILE__,__LINE__, &
277 (/"HDF5 read error for: Scan Time"/))
279 call H5Dclose_f(dhnd1,iret)
284 do j=nscan+1,max_scan
288 call amsr2time(nscan,r8d1,st)
290 allocate (obstime(1:time_dims,1:nscan)) ! year, month, day, hour, min, sec
292 obstime(1,j) = st(j)%year
293 obstime(2,j) = st(j)%month
294 obstime(3,j) = st(j)%day
295 obstime(4,j) = st(j)%hour
296 obstime(5,j) = st(j)%minute
297 obstime(6,j) = st(j)%second
299 write(unit=stdout,fmt=*)'time(scan=1) year: ',st(1)%year,' month:',st(1)%month,' day: ',st(1)%day,&
300 ' hour: ',st(1)%hour,' minute: ',st(1)%minute,' second: ',st(1)%second
302 ! read array: latlon for 89a altitude revised
304 call H5Dopen_f(fhnd1, &
305 'Latitude of Observation Point for 89A',dhnd1,iret)
308 call H5Dread_f(dhnd1, &
309 H5T_NATIVE_REAL,lat89ar,sz1,iret,H5S_ALL_F,H5S_ALL_F)
311 call da_warning(__FILE__,__LINE__, &
312 (/"HDF5 read error for: Latitude of Observation Point for 89A"/))
314 call H5Dclose_f(dhnd1,iret)
317 call H5Dopen_f(fhnd1, &
318 'Longitude of Observation Point for 89A',dhnd1,iret)
321 call H5Dread_f(dhnd1, &
322 H5T_NATIVE_REAL,lon89ar,sz1,iret,H5S_ALL_F,H5S_ALL_F)
324 call da_warning(__FILE__,__LINE__, &
325 (/"HDF5 read error for: Longitude of Observation Point for 89A"/))
326 call da_trace_exit("da_read_obs_hdf5amsr2")
328 call H5Dclose_f(dhnd1,iret)
332 lat89ar(:,j)=lat89ar(:,j+ovr)
333 lon89ar(:,j)=lon89ar(:,j+ovr)
335 do j=nscan+1,max_scan
340 !write(unit=stdout,fmt=*)'latlon89ar(pixel=1,scan=1): ',lat89ar(1,1),lon89ar(1,1)
342 ! read array: latlon for low resolution
345 latlr(i,j)=lat89ar(i*2-1,j)
346 lonlr(i,j)=lon89ar(i*2-1,j)
350 !write(unit=stdout,fmt=*)&
351 ! 'latlonlr(pixel=1,scan=1): ',latlr(1,1),lonlr(1,1)
353 ! read array: tb for low frequency channels
354 do k=1,num_low_freq_chan
355 call H5Dopen_f(fhnd1,tb_low_name(k),dhnd1,iret)
356 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret)
357 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
358 call H5Aclose_f(ahnd1,iret)
361 call H5Dread_f(dhnd1, &
362 H5T_NATIVE_REAL,tb_low(:,:,k),sz1,iret,H5S_ALL_F,H5S_ALL_F)
364 call da_warning(__FILE__,__LINE__, &
365 (/"HDF5 read error for: Brightness Temperature"/))
367 call H5Dclose_f(dhnd1,iret)
368 ! cutoff overlap & convert to unsignd & change scale
371 tb_low(i,j,k)=tb_low(i,j+ovr,k)
372 if(tb_low(i,j,k).lt.65534)tb_low(i,j,k)=tb_low(i,j,k)*sca
375 do j=nscan+1,max_scan
379 if (print_detail_rad) then
380 write(unit=message(1),fmt='(A,I6,A,F10.4)')&
381 'tb_low(pixel=1,scan=1,chan=',k,'): ',tb_low(1,1,k)
382 call da_message(message(1:1))
386 ! read array: tb for 89ah
388 call H5Dopen_f(fhnd1, &
389 'Brightness Temperature (original,89GHz-A,H)',dhnd1,iret)
390 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret) ! get scale
391 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
392 call H5Aclose_f(ahnd1,iret)
395 call H5Dread_f(dhnd1, &
396 H5T_NATIVE_REAL,tb89ah,sz1,iret,H5S_ALL_F,H5S_ALL_F)
398 call da_warning(__FILE__,__LINE__, &
399 (/"HDF5 read error for: Brightness Temperature (original,89GHz-A,H)"/))
401 call H5Dclose_f(dhnd1,iret)
402 ! cutoff overlap & convert to unsignd & change scale
405 tb89ah(i,j)=tb89ah(i,j+ovr)
406 if(tb89ah(i,j).lt.65534)tb89ah(i,j)=tb89ah(i,j)*sca
409 do j=nscan+1,max_scan
413 if (print_detail_rad) then
414 write(unit=message(1),fmt='(A,F10.4)')&
415 'tb89ah(pixel=1,scan=1): ',tb89ah(1,1)
416 call da_message(message(1:1))
419 ! read array: tb for 89av
421 call H5Dopen_f(fhnd1, &
422 'Brightness Temperature (original,89GHz-A,V)',dhnd1,iret)
423 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret) ! get scale
424 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
425 call H5Aclose_f(ahnd1,iret)
428 call H5Dread_f(dhnd1, &
429 H5T_NATIVE_REAL,tb89av,sz1,iret,H5S_ALL_F,H5S_ALL_F)
431 call da_warning(__FILE__,__LINE__, &
432 (/"HDF5 read error for: Brightness Temperature (original,89GHz-A,V)"/))
434 call H5Dclose_f(dhnd1,iret)
435 ! cutoff overlap & convert to unsignd & change scale
438 tb89av(i,j)=tb89av(i,j+ovr)
439 if(tb89av(i,j).lt.65534)tb89av(i,j)=tb89av(i,j)*sca
442 do j=nscan+1,max_scan
446 if (print_detail_rad) then
447 write(unit=message(1),fmt='(A,F10.4)')&
448 'tb89av(pixel=1,scan=1): ',tb89av(1,1)
449 call da_message(message(1:1))
452 ! read array: land ocean flag for low
454 call H5Dopen_f(fhnd1, &
455 'Land_Ocean Flag 6 to 36',dhnd1,iret)
458 call H5Dread_f(dhnd1, &
459 H5T_NATIVE_INTEGER,loflo,sz1,iret,H5S_ALL_F,H5S_ALL_F)
461 call da_warning(__FILE__,__LINE__, &
462 (/"HDF5 read error for: Land_Ocean Flag 6 to 36"/))
464 call H5Dclose_f(dhnd1,iret)
468 lof06(i,j)=loflo(i,(nscan+ovr*2)*0+j)
469 lof10(i,j)=loflo(i,(nscan+ovr*2)*1+j)
470 lof23(i,j)=loflo(i,(nscan+ovr*2)*2+j)
471 lof36(i,j)=loflo(i,(nscan+ovr*2)*3+j)
477 lof06(i,j)=lof06(i,j+ovr)
478 lof10(i,j)=lof10(i,j+ovr)
479 lof23(i,j)=lof23(i,j+ovr)
480 lof36(i,j)=lof36(i,j+ovr)
483 do j=nscan+1,max_scan
490 !write(unit=stdout,fmt=*)'lof06(pixel=1,scan=1): ',lof06(1,1)
491 !write(unit=stdout,fmt=*)'lof10(pixel=1,scan=1): ',lof10(1,1)
492 !write(unit=stdout,fmt=*)'lof23(pixel=1,scan=1): ',lof23(1,1)
493 !write(unit=stdout,fmt=*)'lof36(pixel=1,scan=1): ',lof36(1,1)
495 ! read array: land ocean flag for high
497 call H5Dopen_f(fhnd1, &
498 'Land_Ocean Flag 89',dhnd1,iret)
501 call H5Dread_f(dhnd1, &
502 H5T_NATIVE_INTEGER,lofhi,sz1,iret,H5S_ALL_F,H5S_ALL_F)
504 call da_warning(__FILE__,__LINE__, &
505 (/"HDF5 read error for: Land_Ocean Flag 89"/))
507 call H5Dclose_f(dhnd1,iret)
511 lof89a(i,j)=lofhi(i,(nscan+ovr*2)*0+j)
512 lof89b(i,j)=lofhi(i,(nscan+ovr*2)*1+j)
517 lof89a(i,j)=lof89a(i,j+ovr)
518 lof89b(i,j)=lof89b(i,j+ovr)
521 do j=nscan+1,max_scan
526 !write(unit=stdout,fmt=*)'lof89a(pixel=1,scan=1): ',lof89a(1,1)
527 !write(unit=stdout,fmt=*)'lof89b(pixel=1,scan=1): ',lof89b(1,1)
529 ! read array: earth incidence
531 call H5Dopen_f(fhnd1, &
532 'Earth Incidence',dhnd1,iret)
533 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret) ! get scale
534 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
535 call H5Aclose_f(ahnd1,iret)
538 call H5Dread_f(dhnd1, &
539 H5T_NATIVE_REAL,ear_in,sz1,iret,H5S_ALL_F,H5S_ALL_F)
541 call da_warning(__FILE__,__LINE__, &
542 (/"HDF5 read error for: Earth Incidence"/))
544 call H5Dclose_f(dhnd1,iret)
545 ! cutoff overlap & change scale
548 ear_in(i,j)=ear_in(i,j+ovr)
549 if(ear_in(i,j).gt.-32767)ear_in(i,j)=ear_in(i,j)*sca
552 do j=nscan+1,max_scan
556 !write(unit=stdout,fmt=*)'ear_in(pixel=1,scan=1): ',ear_in(1,1)
558 ! read array: earth azimuth
560 call H5Dopen_f(fhnd1, &
561 'Earth Azimuth',dhnd1,iret)
562 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret) ! get scale
563 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
564 call H5Aclose_f(ahnd1,iret)
567 call H5Dread_f(dhnd1, &
568 H5T_NATIVE_REAL,ear_az,sz1,iret,H5S_ALL_F,H5S_ALL_F)
570 call da_warning(__FILE__,__LINE__, &
571 (/"HDF5 read error for: Earth Azimuth"/))
573 call H5Dclose_f(dhnd1,iret)
574 ! cutoff overlap & change scale
577 ear_az(i,j)=ear_az(i,j+ovr)
578 if(ear_az(i,j).gt.-32767)ear_az(i,j)=ear_az(i,j)*sca
581 do j=nscan+1,max_scan
585 !write(unit=stdout,fmt=*)'ear_az(pixel=1,scan=1): ',ear_az(1,1)
587 ! read array: sun azimuth
589 call H5Dopen_f(fhnd1, &
590 'Sun Azimuth',dhnd1,iret)
591 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret) ! get scale
592 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
593 call H5Aclose_f(ahnd1,iret)
596 call H5Dread_f(dhnd1, &
597 H5T_NATIVE_REAL,sun_az,sz1,iret,H5S_ALL_F,H5S_ALL_F)
599 call da_warning(__FILE__,__LINE__, &
600 (/"HDF5 read error for: Sun Azimuth"/))
602 call H5Dclose_f(dhnd1,iret)
603 ! cutoff overlap & change scale
606 sun_az(i,j)=sun_az(i,j+ovr)
607 if(sun_az(i,j).gt.-32767)sun_az(i,j)=sun_az(i,j)*sca
610 do j=nscan+1,max_scan
614 !write(unit=stdout,fmt=*)'sun_az(pixel=1,scan=1): ',sun_az(1,1)
616 ! read array: sun elevation
618 call H5Dopen_f(fhnd1, &
619 'Sun Elevation',dhnd1,iret)
620 call H5Aopen_f(dhnd1,'SCALE FACTOR',ahnd1,iret) ! get scale
621 call H5Aread_f(ahnd1,H5T_NATIVE_REAL,sca,sz1,iret)
622 call H5Aclose_f(ahnd1,iret)
625 call H5Dread_f(dhnd1, &
626 H5T_NATIVE_REAL,sun_el,sz1,iret,H5S_ALL_F,H5S_ALL_F)
628 call da_warning(__FILE__,__LINE__, &
629 (/"HDF5 read error for: Sun Elevation"/))
631 call H5Dclose_f(dhnd1,iret)
632 ! cutoff overlap & change scale
635 sun_el(i,j)=sun_el(i,j+ovr)
636 if(sun_el(i,j).gt.-32767)sun_el(i,j)=sun_el(i,j)*sca
639 do j=nscan+1,max_scan
643 !write(unit=stdout,fmt=*)'sun_el(pixel=1,scan=1): ',sun_el(1,1)
644 sun_zen(:,:)=R90-sun_el(:,:)
645 sat_zenith(:,:)=ear_in(:,:)
646 sat_azimuth(:,:)=ear_az(:,:)
648 ! close file and HDF5
649 call H5Fclose_f(fhnd1,iret)
651 if ( got_clw_file ) then
652 ! read CLW from infile_clw:
653 call H5Dopen_f(fhnd2,'Geophysical Data',dhnd2,iret)
654 call H5Aopen_f(dhnd2,'SCALE FACTOR',ahnd2,iret)
655 call H5Aread_f(ahnd2,H5T_NATIVE_REAL,sca,sz1,iret)
656 call H5Aclose_f(ahnd2,iret)
659 call H5Dread_f(dhnd2, &
660 H5T_NATIVE_REAL,clw,sz1,iret,H5S_ALL_F,H5S_ALL_F)
662 call da_warning(__FILE__,__LINE__, &
663 (/"HDF5 read error for: CLW data"/))
665 call H5Dclose_f(dhnd2,iret)
669 if(clw(i,j).gt.-32767)clw(i,j)=clw(i,j)*sca
672 do j=nscan+1,max_scan
676 !write(unit=stdout,fmt=*)'clw(pixel=1,scan=1): ',clw(1,1)
677 ! close file and HDF5
678 call H5Fclose_f(fhnd2,iret)
681 ! 2.0 Loop to read hdf file and assign information to a sequential structure
682 !-------------------------------------------------------------------------
684 ! Allocate arrays to hold data
685 if ( .not. head_allocated ) then
687 nullify ( head % next )
689 head_allocated = .true.
692 scan_loop: do iscan=1, nscan
694 idate5(i)=obstime(i, iscan)
696 call da_get_julian_time(idate5(1),idate5(2),idate5(3),idate5(4),idate5(5),obs_time)
697 if ( obs_time < time_slots(0) .or. &
698 obs_time >= time_slots(num_fgat_time) ) cycle scan_loop
699 do ifgat=1,num_fgat_time
700 if ( obs_time >= time_slots(ifgat-1) .and. &
701 obs_time < time_slots(ifgat) ) exit
705 fov_loop: do ifov=1, lo_rez_fov
706 num_amsr2_file = num_amsr2_file + 1
707 num_amsr2_file_local = num_amsr2_file_local + 1
708 info%lat = latlr(ifov,iscan)
709 info%lon = lonlr(ifov,iscan)
711 call da_llxy (info, loc, outside, outside_all)
712 if (outside_all) cycle fov_loop
714 num_amsr2_global = num_amsr2_global + 1
715 num_amsr2_global_local = num_amsr2_global_local + 1
716 ptotal(ifgat) = ptotal(ifgat) + 1
717 if (outside) cycle fov_loop ! No good for this PE
718 ! Discard data over Land (landmask =0 -->Land =1 -->Sea)
720 if(lof06(ifov,iscan) < 1.0 .and. lof10(ifov,iscan) < 1.0 .and. &
721 lof23(ifov,iscan) < 1.0 .and. lof36(ifov,iscan) < 1.0 .and. &
722 lof89a(2*ifov-1,iscan) < 1.0 ) landsea_mask = 1
723 if( landsea_mask == 0 ) cycle fov_loop
725 num_amsr2_local = num_amsr2_local + 1
726 num_amsr2_local_local = num_amsr2_local_local + 1
727 write(unit=info%date_char, &
728 fmt='(i4.4,a,i2.2,a,i2.2,a,i2.2,a,i2.2,a,i2.2)') &
729 idate5(1), '-', idate5(2), '-', idate5(3), '_', idate5(4), &
730 ':', idate5(5), ':', idate5(6)
734 ! Map obs to thinning grid
735 !-------------------------------------------------------------------
737 dlat_earth = info%lat !degree
738 dlon_earth = info%lon
739 if (dlon_earth<zero) dlon_earth = dlon_earth+r360
740 if (dlon_earth>=r360) dlon_earth = dlon_earth-r360
741 dlat_earth = dlat_earth*deg2rad !radian
742 dlon_earth = dlon_earth*deg2rad
744 call map2grids(inst,ifgat,dlat_earth,dlon_earth,crit,iobs,itx,1,itt,iout,iuse)
746 num_amsr2_thinned = num_amsr2_thinned+1
751 num_amsr2_used = num_amsr2_used + 1
754 do k=1,num_low_freq_chan
755 tb = tb_low(ifov,iscan,k)
756 if( tb < tbmin .or. tb > tbmax ) tb = missing_r
760 tb = tb89av(2*ifov-1,iscan)
761 if( tb < tbmin .or. tb > tbmax ) tb = missing_r
764 tb = tb89ah(2*ifov-1,iscan)
765 if( tb < tbmin .or. tb > tbmax ) tb = missing_r
768 ! 4.0 assign information to sequential radiance structure
769 !--------------------------------------------------------------------------
770 allocate ( p % tb_inv (1:nchan ))
773 p%landsea_mask = landsea_mask
775 p%satzen = sat_zenith(ifov,iscan)
776 p%satazi = sat_azimuth(ifov,iscan)
777 p%solzen = sun_zen(ifov,iscan)
778 p%solazi = sun_az(ifov,iscan)
779 p%clw = clw(ifov,iscan)
780 p%tb_inv(1:nchan) = data_all(1:nchan)
781 p%sensor_index = inst
784 allocate (p%next) ! add next data
793 write(stdout,fmt='(3a,i7)') ' In file: ',trim(fname_tb(ifile)),' got num_amsr2_file : ',num_amsr2_file_local
794 write(stdout,fmt='(3a,i7)') ' In file: ',trim(fname_tb(ifile)),' got num_amsr2_global : ',num_amsr2_global_local
795 write(stdout,fmt='(3a,i7)') ' In file: ',trim(fname_tb(ifile)),' got num_amsr2_local : ',num_amsr2_local_local
800 deallocate(data_all) ! Deallocate data arrays
802 if (thinning .and. num_amsr2_global > 0 ) then
804 ! Get minimum crit and associated processor index.
806 do ifgat = 1, num_fgat_time
807 j = j + thinning_grid(inst,ifgat)%itxmax
813 do ifgat = 1, num_fgat_time
814 do i = 1, thinning_grid(inst,ifgat)%itxmax
816 in(j) = thinning_grid(inst,ifgat)%score_crit(i)
819 call mpi_reduce(in, out, j, true_mpi_real, mpi_min, root, comm, ierr)
821 call wrf_dm_bcast_real (out, j)
824 do ifgat = 1, num_fgat_time
825 do i = 1, thinning_grid(inst,ifgat)%itxmax
827 if ( ABS(out(j)-thinning_grid(inst,ifgat)%score_crit(i)) > 1.0E-10 ) &
828 thinning_grid(inst,ifgat)%ibest_obs(i) = 0
837 ! Delete the nodes which being thinning out
841 num_amsr2_used_tmp = num_amsr2_used
842 do j = 1, num_amsr2_used_tmp
847 do i = 1, thinning_grid(n,ifgat)%itxmax
848 if ( thinning_grid(n,ifgat)%ibest_obs(i) == j .and. thinning_grid(n,ifgat)%score_crit(i) < 9.99e6_r_kind ) then
855 if ( .not. found ) then
858 if ( head_found ) then
864 deallocate ( current % tb_inv )
865 deallocate ( current )
866 num_amsr2_thinned = num_amsr2_thinned + 1
867 num_amsr2_used = num_amsr2_used - 1
871 if ( found .and. head_found ) then
877 if ( found .and. .not. head_found ) then
886 end if ! End of thinning
888 iv%total_rad_pixel = iv%total_rad_pixel + num_amsr2_used
889 iv%total_rad_channel = iv%total_rad_channel + num_amsr2_used*nchan
891 iv%info(radiance)%nlocal = iv%info(radiance)%nlocal + num_amsr2_used
892 iv%info(radiance)%ntotal = iv%info(radiance)%ntotal + num_amsr2_global
894 do i = 1, num_fgat_time
895 ptotal(i) = ptotal(i) + ptotal(i-1)
896 iv%info(radiance)%ptotal(i) = iv%info(radiance)%ptotal(i) + ptotal(i)
898 if ( iv%info(radiance)%ptotal(num_fgat_time) /= iv%info(radiance)%ntotal ) then
899 write(unit=message(1),fmt='(A,I10,A,I10)') &
900 "Number of ntotal:",iv%info(radiance)%ntotal," is different from the sum of ptotal:", iv%info(radiance)%ptotal(num_fgat_time)
901 call da_warning(__FILE__,__LINE__,message(1:1))
904 write(unit=stdout,fmt='(a)') 'AMSR2 data counts: '
905 write(stdout,fmt='(a,i7)') ' In file: ',num_amsr2_file
906 write(stdout,fmt='(a,i7)') ' Global : ',num_amsr2_global
907 write(stdout,fmt='(a,i7)') ' Local : ',num_amsr2_local
908 write(stdout,fmt='(a,i7)') ' Used : ',num_amsr2_used
909 write(stdout,fmt='(a,i7)') ' Thinned: ',num_amsr2_thinned
911 ! 5.0 allocate innovation radiance structure
912 !----------------------------------------------------------------
914 if (num_amsr2_used > 0) then
915 iv%instid(inst)%num_rad = num_amsr2_used
916 iv%instid(inst)%info%nlocal = num_amsr2_used
917 write(UNIT=stdout,FMT='(a,i3,2x,a,3x,i10)') &
918 'Allocating space for radiance innov structure', &
919 inst, iv%instid(inst)%rttovid_string, iv%instid(inst)%num_rad
920 call da_allocate_rad_iv (inst, nchan, iv)
923 ! 6.0 assign sequential structure to innovation structure
924 !-------------------------------------------------------------
927 do n = 1, num_amsr2_used
929 call da_initialize_rad_iv (i, n, iv, p)
933 deallocate ( current % tb_inv )
934 deallocate ( current )
939 if (trace_use) call da_trace_exit("da_read_obs_hdf5amsr2")
941 call da_error(__FILE__,__LINE__,(/"Needs to be compiled with HDF5 library"/))
943 end subroutine da_read_obs_hdf5amsr2