FV3 Bundle
read_aod_diag.f90
Go to the documentation of this file.
1 !$$$ subprogram documentation block
2 ! . . . .
3 ! subprogram: read_aoddiag read rad diag file
4 ! prgmmr: tahara org: np20 date: 2003-01-01
5 !
6 ! abstract: This module contains code to process radiance
7 ! diagnostic files. The module defines structures
8 ! to contain information from the radiance
9 ! diagnostic files and then provides two routines
10 ! to access contents of the file.
11 !
12 ! program history log:
13 ! 2005-07-22 treadon - add this doc block
14 ! 2010-10-05 treadon - refactor code to GSI standard
15 ! 2010-10-08 zhu - use data_tmp to handle various npred values
16 ! 2011-02-22 kleist - changes related to memory allocate/deallocate
17 ! 2011-04-08 li - add tref, dtw, dtc to diag_data_fix_list, add tb_tz to diag_data_chan_list
18 ! 2011-07-24 safford - make structure size for reading data_fix data version dependent
19 ! 2013-11-21 todling - revisit how versions are set (add set/get_aoddiag)
20 ! 2014-01-27 todling - add ob sensitivity index
21 ! 2017-07-13 mccarty - incorporate hooks for nc4/binary diag reading
22 ! 2017-11-10 pagowski - converted radiance to aod
23 !
24 ! contains
25 ! read_aoddiag_header - read radiance diagnostic file header
26 ! read_aoddiag_data - read radiance diagnostic file data
27 ! set_netcdf_read - call set_netcdf_read(.true.) to use nc4 hooks, otherwise read file as
28 ! traditional binary format
29 !
30 ! attributes:
31 ! language: f90
32 ! machine: ibm RS/6000 SP
33 !
34 !$$$
35 
37 
38  USE ncd_kinds, ONLY: i_kind,r_single,r_kind
39  USE nc_diag_read_mod, ONLY: nc_diag_read_get_var, nc_diag_read_get_global_attr
41  IMPLICIT NONE
42 
43 ! Declare public and private
44  PRIVATE
45 
46  PUBLIC :: diag_header_fix_list_aod
48  PUBLIC :: diag_data_name_list_aod
49  PUBLIC :: diag_data_fix_list_aod
50  PUBLIC :: diag_data_chan_list_aod
51  PUBLIC :: read_aoddiag_header
52  PUBLIC :: read_aoddiag_data
53  PUBLIC :: set_netcdf_read_aod
54  PUBLIC :: ireal_aod
55  PUBLIC :: ipchan_aod
56  PUBLIC :: set_aoddiag
57  PUBLIC :: get_aoddiag
58  PUBLIC :: read_all_aoddiag
59 
60 
61  INTERFACE set_aoddiag
62  MODULE PROCEDURE set_aoddiag_int_ ! internal procedure for integers
63  END INTERFACE
64  INTERFACE get_aoddiag
65  MODULE PROCEDURE get_aoddiag_int_ ! internal procedure for integers
66  END INTERFACE
67 
68  INTEGER(i_kind),PARAMETER :: ireal_aod = 6 ! number of real entries per spot in aod diagnostic file
69  INTEGER(i_kind),PARAMETER :: ipchan_aod = 4 ! number of entries per channel per spot in aod diagnostic file
70 
71 !@for aod remove npred i/jextra some other terms
72 ! Declare structures for radiance diagnostic file information
74  CHARACTER(len=20) :: isis ! sat and sensor type
75  CHARACTER(len=10) :: id ! sat type
76  CHARACTER(len=10) :: obstype ! observation type
77  INTEGER(i_kind) :: jiter ! outer loop counter
78  INTEGER(i_kind) :: nchan ! number of channels in the sensor
79  INTEGER(i_kind) :: idate ! time (yyyymmddhh)
80  INTEGER(i_kind) :: ireal ! # of real elements in the fix part of a data record
81  INTEGER(i_kind) :: ipchan ! # of elements for each channel except for bias correction terms
82  INTEGER(i_kind) :: nsig ! # of sigma levels (layers?)
83  INTEGER(i_kind) :: isens ! sensitivity index
85 
87  CHARACTER(len=10),DIMENSION(ireal_aod) :: fix
88  CHARACTER(len=10),DIMENSION(:),ALLOCATABLE :: chn
90 
91 
92 !for aod diag_header_chan_list_aod is same as for radiance
94  REAL(r_kind) :: freq ! frequency (Hz)
95  REAL(r_kind) :: polar ! polarization
96  REAL(r_kind) :: wave ! wave number (cm^-1)
97  REAL(r_kind) :: varch ! error variance (or SD error?)
98  REAL(r_kind) :: tlapmean ! mean lapse rate
99  INTEGER(i_kind):: iuse ! use flag
100  INTEGER(i_kind):: nuchan ! sensor relative channel number
101  INTEGER(i_kind):: iochan ! satinfo relative channel number
103 
104 !@some changes
106  REAL(r_kind) :: lat ! latitude (deg)
107  REAL(r_kind) :: lon ! longitude (deg)
108  REAL(r_kind) :: psfc ! psfc (hPa)
109  REAL(r_kind) :: obstime ! observation time relative to analysis
110  REAL(r_kind) :: solzen_ang ! solar zenith angle (deg)
111  REAL(r_kind) :: solazm_ang ! solar azimumth angle (deg)
112  END TYPE diag_data_fix_list_aod
113 
114 !@some changes to aod
116  REAL(r_kind) :: aodobs ! AOD (obs)
117  REAL(r_kind) :: omgaod ! AOD (obs) - AOD (guess)
118  REAL(r_kind) :: errinv ! inverse error (K**(-1))
119  REAL(r_kind) :: qcmark ! quality control mark
120  END TYPE diag_data_chan_list_aod
121 
122  REAL(r_kind),PARAMETER:: rmiss_aoddiag = -9.9e11_r_kind
123 
124  LOGICAL,SAVE :: netcdf = .false.
125  LOGICAL,SAVE :: nc_read = .false.
126  INTEGER,SAVE :: cur_ob_idx = -9999
127  INTEGER,SAVE :: num_records = -9999
128 
129  TYPE(diag_data_fix_list_aod) ,ALLOCATABLE, SAVE :: all_data_fix(:)
130  TYPE(diag_data_chan_list_aod) ,ALLOCATABLE, SAVE :: all_data_chan(:,:)
131 
132 CONTAINS
133 
134  SUBROUTINE set_aoddiag_int_ (what,iv,ier)
135  CHARACTER(len=*),INTENT(in) :: what
136  INTEGER(i_kind),INTENT(in) :: iv
137  INTEGER(i_kind),INTENT(out):: ier
138  ier=0
139  END SUBROUTINE set_aoddiag_int_
140 
141  SUBROUTINE get_aoddiag_int_ (what,iv,ier)
142  CHARACTER(len=*),INTENT(in) :: what
143  INTEGER(i_kind),INTENT(out):: iv
144  INTEGER(i_kind),INTENT(out):: ier
145  ier=0
146  END SUBROUTINE get_aoddiag_int_
147 
148  SUBROUTINE set_netcdf_read_aod(use_netcdf)
149 ! . . . .
150 ! subprogram: read_diag_header_bin read rad diag header
151 ! prgmmr: mccarty org: gmao date: 2015-08-06
152 !
153 ! abstract: This routine sets the routines to read from a netcdf file.
154 ! The default currently is to read binary files
155 !
156 ! program history log:
157 ! 2015-08-06 mccarty - created routine
158 !
159 ! input argument list_aod:
160 ! use_netcdf - logical .true. tells routine to read netcdf diag
161 ! attributes:
162 ! language: f90
163 ! machine: ibm RS/6000 SP
164 !
165 !$$$
166  LOGICAL,INTENT(in) :: use_netcdf
167 
168  netcdf = use_netcdf
169  END SUBROUTINE set_netcdf_read_aod
170 
171 
172  SUBROUTINE read_aoddiag_header(ftin,header_fix,header_chan,data_name,iflag,lverbose)
173 ! . . . .
174 ! subprogram: read_diag_header_bin read rad diag header
175 ! prgmmr: mccarty org: gmao date: 2015-08-06
176 !
177 ! abstract: This routine reads the header record from a radiance
178 ! diagnostic file
179 !
180 ! program history log:
181 ! 2015-08-06 mccarty - created routine w/ fork for ncdiag or binary
182 !
183 ! input argument list_aod:
184 ! ftin - unit number connected to diagnostic file
185 !
186 ! output argument list_aod:
187 ! header_fix - header information structure
188 ! header_chan - channel information structure
189 ! data_name - diag file data names
190 ! iflag - error code
191 ! lverbose - optional flag to turn off default output to standard out
192 !
193 ! attributes:
194 ! language: f90
195 ! machine: ibm RS/6000 SP
196 !
197 !$$$
198 
199 ! Declare passed arguments
200  INTEGER(i_kind),INTENT(in) :: ftin
201  TYPE(diag_header_fix_list_aod ),INTENT(out):: header_fix
202  TYPE(diag_header_chan_list_aod),ALLOCATABLE :: header_chan(:)
203  TYPE(diag_data_name_list_aod) :: data_name
204  INTEGER(i_kind),INTENT(out) :: iflag
205  LOGICAL,OPTIONAL,INTENT(in) :: lverbose
206 
207  iflag = 0
208  IF (netcdf) THEN
209  print *,'netcdf slot'
210  CALL read_aoddiag_header_nc(ftin,header_fix,header_chan,data_name,iflag,lverbose)
211  ELSE
212  CALL read_aoddiag_header_bin(ftin,header_fix,header_chan,data_name,iflag,lverbose)
213  ENDIF
214 
215  END SUBROUTINE read_aoddiag_header
216 
217  SUBROUTINE read_aoddiag_header_nc(ftin,header_fix,header_chan,data_name,iflag,lverbose)
219 !nc not tested
220 ! . . . .
221 ! subprogram: read_diag_header_nc read rad diag header
222 ! prgmmr: mccarty org: gmao date: 2003-01-01
223 !
224 ! abstract: This routine reads the header record from a radiance
225 ! diagnostic file
226 !
227 ! program history log:
228 ! 2015-08-06 mccarty - Created routine for ncdiag header reading
229 !
230 ! input argument list_aod:
231 ! ftin - unit number connected to diagnostic file
232 !
233 ! output argument list_aod:
234 ! header_fix - header information structure
235 ! header_chan - channel information structure
236 ! data_name - diag file data names
237 ! iflag - error code
238 ! lverbose - optional flag to turn off default output to standard out
239 !
240 ! attributes:
241 ! language: f90
242 ! machine: ibm RS/6000 SP
243 !
244 !$$$
245 ! Declare passed arguments
246  INTEGER(i_kind),INTENT(in) :: ftin
247  TYPE(diag_header_fix_list_aod ),INTENT(out):: header_fix
248  TYPE(diag_header_chan_list_aod),ALLOCATABLE :: header_chan(:)
249  TYPE(diag_data_name_list_aod) :: data_name
250  INTEGER(i_kind),INTENT(out) :: iflag
251  LOGICAL,OPTIONAL,INTENT(in) :: lverbose
252 
253 ! local variables
254  INTEGER(i_kind) :: nchan_dim
255  REAL(r_kind),ALLOCATABLE,DIMENSION(:) :: r_var_stor
256  INTEGER(i_kind),ALLOCATABLE,DIMENSION(:) :: i_var_stor
257  CHARACTER(20) :: isis
258  CHARACTER(10) :: id, obstype
259 ! integer(i_kind),dimension(:),allocatable :: jiter, nchan_diag, idate, &
260  INTEGER(i_kind) :: jiter, nchan_diag, idate, &
261  ireal, ipchan, isens
262 
263  iflag = 0
264 ! allocate(nchan_diag(1) )
265  nchan_dim = nc_diag_read_get_dim(ftin,'nchans')
266  header_fix%nchan = nchan_dim
267  WRITE(*,*)'Number of channels=',nchan_dim
268 
269  CALL nc_diag_read_get_global_attr(ftin, "Number_of_channels", nchan_diag)
270 
271  IF (nchan_dim .NE. nchan_diag) THEN
272  WRITE(*,*)'ERROR: Number of channels from dimension do not match those from header, aborting.'
273  CALL abort
274  ENDIF
275 
276  CALL nc_diag_read_get_global_attr(ftin, "Satellite_Sensor", isis) ; header_fix%isis = isis
277  CALL nc_diag_read_get_global_attr(ftin, "Satellite", id) ; header_fix%id = id
278  CALL nc_diag_read_get_global_attr(ftin, "Observation_type", obstype) ; header_fix%obstype = obstype
279  CALL nc_diag_read_get_global_attr(ftin, "Outer_Loop_Iteration", jiter) ; header_fix%jiter = jiter
280  CALL nc_diag_read_get_global_attr(ftin, "date_time", idate) ; header_fix%idate = idate
281  CALL nc_diag_read_get_global_attr(ftin, "ireal_aoddiag", ireal) ; header_fix%ireal = ireal
282  CALL nc_diag_read_get_global_attr(ftin, "ipchan_aoddiag", ipchan) ; header_fix%ipchan = ipchan
283  CALL nc_diag_read_get_global_attr(ftin, "ioff0", isens) ; header_fix%isens = isens
284 
285  ALLOCATE(header_chan(nchan_dim) )
286 
287  ALLOCATE(r_var_stor(nchan_dim), &
288  i_var_stor(nchan_dim) )
289 
290  CALL nc_diag_read_get_var('frequency',r_var_stor) ; header_chan%freq = r_var_stor
291  CALL nc_diag_read_get_var('polarization',r_var_stor) ; header_chan%polar = r_var_stor
292  CALL nc_diag_read_get_var('wavenumber',r_var_stor) ; header_chan%wave = r_var_stor
293  CALL nc_diag_read_get_var('error_variance',r_var_stor) ; header_chan%varch = r_var_stor
294  CALL nc_diag_read_get_var('use_flag',i_var_stor) ; header_chan%iuse = i_var_stor
295  CALL nc_diag_read_get_var('sensor_chan',i_var_stor) ; header_chan%nuchan = i_var_stor
296  CALL nc_diag_read_get_var('satinfo_chan',i_var_stor) ; header_chan%iochan = i_var_stor
297 
298 
299  END SUBROUTINE read_aoddiag_header_nc
300 
301  SUBROUTINE read_aoddiag_header_bin(ftin,header_fix,header_chan,data_name,iflag,lverbose)
302 ! . . . .
303 ! subprogram: read_diag_header_bin read rad diag header
304 ! prgmmr: tahara org: np20 date: 2003-01-01
305 !
306 ! abstract: This routine reads the header record from a radiance
307 ! diagnostic file
308 !
309 ! program history log:
310 ! 2010-10-05 treadon - add this doc block
311 ! 2011-02-22 kleist - changes related to memory allocation and standard output
312 ! 2014-07-25 sienkiewicz - supress warning if npred_aoddiag == 0
313 ! 2017-07-17 mccarty - renamed routine to _bin suffix for ncdiag
314 !
315 ! input argument list_aod:
316 ! ftin - unit number connected to diagnostic file
317 !
318 ! output argument list_aod:
319 ! header_fix - header information structure
320 ! header_chan - channel information structure
321 ! data_name - diag file data names
322 ! iflag - error code
323 ! lverbose - optional flag to turn off default output to standard out
324 !
325 ! attributes:
326 ! language: f90
327 ! machine: ibm RS/6000 SP
328 !
329 !$$$
330 
331 ! Declare passed arguments
332  INTEGER(i_kind),INTENT(in) :: ftin
333  TYPE(diag_header_fix_list_aod ),INTENT(out):: header_fix
334  TYPE(diag_header_chan_list_aod),ALLOCATABLE :: header_chan(:)
335  TYPE(diag_data_name_list_aod) :: data_name
336  INTEGER(i_kind),INTENT(out) :: iflag
337  LOGICAL,OPTIONAL,INTENT(in) :: lverbose
338 
339 ! Declare local variables
340  CHARACTER(len=2):: string
341  CHARACTER(len=10):: satid,sentype
342  CHARACTER(len=20):: sensat
343  INTEGER(i_kind) :: i,ich
344  INTEGER(i_kind):: jiter,nchanl,ianldate,ireal,ipchan,nsig,isens
345  INTEGER(i_kind):: iuse_tmp,nuchan_tmp,iochan_tmp
346  REAL(r_single) :: freq_tmp,polar_tmp,wave_tmp,varch_tmp,tlapmean_tmp
347  LOGICAL loutall
348 
349  loutall=.true.
350  IF(PRESENT(lverbose)) loutall=lverbose
351 
352 ! Read header (fixed_part).
353  READ(ftin,iostat=iflag) sensat,satid,sentype,jiter,nchanl,ianldate,&
354  ireal,ipchan,nsig,isens
355 
356  IF (iflag/=0) THEN
357  WRITE(6,*)'READ_AODDIAG_HEADER: ***ERROR*** Unknown file format. Cannot read'
358  RETURN
359  ENDIF
360 
361  header_fix%isis = sensat
362  header_fix%id = satid
363  header_fix%obstype = sentype
364  header_fix%jiter = jiter
365  header_fix%nchan = nchanl
366  header_fix%idate = ianldate
367  header_fix%ireal = ireal
368  header_fix%ipchan = ipchan
369  header_fix%nsig = nsig
370  header_fix%isens = isens
371 
372  IF (loutall) THEN
373  WRITE(6,*)'READ_AODDIAG_HEADER: isis=',header_fix%isis,&
374  ' nchan=',header_fix%nchan,&
375  ' isens=',header_fix%isens
376  ENDIF
377 
378 ! Allocate and initialize as needed
379  IF (ALLOCATED(header_chan)) DEALLOCATE(header_chan)
380  IF (ALLOCATED(data_name%chn)) DEALLOCATE(data_name%chn)
381 
382  ALLOCATE(header_chan( header_fix%nchan))
383  ALLOCATE(data_name%chn(header_fix%ipchan))
384 
385  data_name%fix(1) ='lat '
386  data_name%fix(2) ='lon '
387  data_name%fix(3) ='psfc '
388  data_name%fix(4) ='obstim '
389  data_name%fix(5) ='solzen '
390  data_name%fix(6) ='solazm '
391  data_name%chn(1)='obs '
392  data_name%chn(2)='omg '
393  data_name%chn(3)='errinv '
394  data_name%chn(4)='qcmark '
395 
396 ! Read header (channel part)
397  DO ich=1, header_fix%nchan
398  READ(ftin,iostat=iflag) freq_tmp,polar_tmp,wave_tmp,varch_tmp,iuse_tmp,nuchan_tmp,iochan_tmp
399 
400  header_chan(ich)%freq = freq_tmp
401  header_chan(ich)%polar = polar_tmp
402  header_chan(ich)%wave = wave_tmp
403  header_chan(ich)%varch = varch_tmp
404  header_chan(ich)%iuse = iuse_tmp
405  header_chan(ich)%nuchan = nuchan_tmp
406  header_chan(ich)%iochan = iochan_tmp
407  IF (iflag/=0) RETURN
408  END DO
409 
410 ! Construct array containing menonics for data record entries
411 
412  END SUBROUTINE read_aoddiag_header_bin
413 
414  SUBROUTINE read_aoddiag_data(ftin,header_fix,data_fix,data_chan,iflag )
415 ! . . . .
416 ! subprogram: read_aoddiag_dat read rad diag data
417 ! prgmmr: tahara org: np20 date: 2003-01-01
418 !
419 ! abstract: This routine reads the data record from a radiance
420 ! diagnostic file
421 !
422 ! program history log:
423 ! 2010-10-05 treadon - add this doc block
424 ! 2011-02-22 kleist - changes related to memory allocation
425 ! 2017-07-17 mccarty - change routine to be generalized for bin/nc4 files
426 !
427 ! input argument list_aod:
428 ! ftin - unit number connected to diagnostic file
429 ! header_fix - header information structure
430 !
431 ! output argument list_aod:
432 ! data_fix - spot header information structure
433 ! data_chan - spot channel information structure
434 ! iflag - error code
435 !
436 ! attributes:
437 ! language: f90
438 ! machine: ibm RS/6000 SP
439 !
440 !$$$
441 
442 
443 ! Declare passed arguments
444  INTEGER(i_kind),INTENT(in) :: ftin
445  TYPE(diag_header_fix_list_aod ),INTENT(in) :: header_fix
446  TYPE(diag_data_fix_list_aod) ,INTENT(out):: data_fix
447  TYPE(diag_data_chan_list_aod) ,ALLOCATABLE :: data_chan(:)
448  INTEGER(i_kind),INTENT(out) :: iflag
449 
450  IF (netcdf) THEN
451  IF (.NOT. nc_read) CALL read_aoddiag_data_nc_init(ftin, header_fix)
452 
453  IF (cur_ob_idx .EQ. num_records ) THEN
454  iflag = 0
455  ELSE IF (cur_ob_idx .GT. num_records) THEN
456  iflag = -1
457  ELSE
458  iflag = 1
459  ENDIF
460 
461  IF (iflag .GE. 0) CALL read_aoddiag_data_nc(ftin,header_fix,data_fix,data_chan,iflag)
462 
463  ELSE
464  CALL read_aoddiag_data_bin(ftin,header_fix,data_fix,data_chan,iflag )
465  ENDIF
466 
467  END SUBROUTINE read_aoddiag_data
468 
469 
470  SUBROUTINE read_all_aoddiag(ftin,header_fix,all_data_fix,all_data_chan,nlocs,iflag)
471 ! . . . .
472 ! subprogram: read_all_aoddiag read read_all_aoddiag
473 ! prgmmr: tahara org: np20 date: 2003-01-01
474 ! mzp based on template
475 !
476 ! abstract: This routine reads the data record from a aod
477 ! diagnostic file
478 !
479 ! program history log:
480 ! 2010-10-05 treadon - add this doc block
481 ! 2011-02-22 kleist - changes related to memory allocation
482 ! 2017-07-17 mccarty - change routine to be generalized for bin/nc4 files
483 !
484 ! input argument list_aod:
485 ! ftin - unit number connected to diagnostic file
486 ! header_fix - header information structure
487 !
488 ! output argument list_aod:
489 ! data_fix - spot header information structure
490 ! data_chan - spot channel information structure
491 ! iflag - error code
492 !
493 ! attributes:
494 ! language: f90
495 ! machine: ibm RS/6000 SP
496 !
497 !$$$
498 
499 
500 ! Declare passed arguments
501  INTEGER(i_kind),INTENT(in) :: ftin
502  TYPE(diag_header_fix_list_aod ),INTENT(in) :: header_fix
503  INTEGER(i_kind),INTENT(out) :: iflag
504  TYPE(diag_data_fix_list_aod), ALLOCATABLE, INTENT(inout) :: all_data_fix(:)
505  TYPE(diag_data_chan_list_aod) ,ALLOCATABLE, INTENT(inout) :: all_data_chan(:,:)
506  INTEGER(i_kind),INTENT(out) :: nlocs
507 
508 !locals
509 
510  REAL(r_kind), ALLOCATABLE, DIMENSION(:) :: latitude, longitude, &
511  &Obs_Time, Psfc, Sol_Zenith_Angle, Sol_Azimuth_Angle,&
512  &Observation, Obs_Minus_Forecast_unadjusted, &
513  &Inverse_Observation_Error, QC_Flag
514 
515  INTEGER(i_kind), ALLOCATABLE, DIMENSION(:) :: channel_index
516 
517  INTEGER(i_kind) :: i,ic,ii,ci,ndatum
518 
519  IF (netcdf) THEN
520 
521  ndatum = nc_diag_read_get_dim(ftin,'nobs')
522  nlocs = ndatum / header_fix%nchan
523 
524  ALLOCATE( &
525  &channel_index(ndatum), latitude(ndatum), longitude(ndatum), &
526  &obs_time(ndatum), psfc(ndatum),&
527  &sol_zenith_angle(ndatum), sol_azimuth_angle(ndatum),&
528  &observation(ndatum), obs_minus_forecast_unadjusted(ndatum),&
529  &inverse_observation_error(ndatum),qc_flag(ndatum))
530 
531  ALLOCATE(all_data_fix(nlocs),all_data_chan(nlocs,header_fix%nchan))
532 
533  CALL nc_diag_read_get_var('Channel_Index', channel_index)
534  CALL nc_diag_read_get_var('Latitude', latitude)
535  CALL nc_diag_read_get_var('Longitude', longitude)
536  CALL nc_diag_read_get_var('Psfc', psfc)
537  CALL nc_diag_read_get_var('Obs_Time', obs_time)
538  CALL nc_diag_read_get_var('Sol_Zenith_Angle', sol_zenith_angle)
539  CALL nc_diag_read_get_var('Sol_Azimuth_Angle', sol_azimuth_angle)
540  CALL nc_diag_read_get_var('Observation', observation)
541  CALL nc_diag_read_get_var('Obs_Minus_Forecast_unadjusted', obs_minus_forecast_unadjusted)
542  CALL nc_diag_read_get_var('Inverse_Observation_Error', inverse_observation_error)
543  CALL nc_diag_read_get_var('QC_Flag', qc_flag)
544 
545  ii=1
546 
547  DO i=1,nlocs
548  all_data_fix(i)%lat = latitude(ii)
549  all_data_fix(i)%lon = longitude(ii)
550  all_data_fix(i)%psfc = psfc(ii)
551  all_data_fix(i)%obstime = obs_time(ii)
552  all_data_fix(i)%solzen_ang = sol_zenith_angle(ii)
553  all_data_fix(i)%solazm_ang = sol_azimuth_angle(ii)
554 
555  DO ic=1,header_fix%nchan
556  ci = channel_index(ii)
557  all_data_chan(i,ci)%aodobs = observation(ii)
558  all_data_chan(i,ci)%omgaod = obs_minus_forecast_unadjusted(ii)
559  all_data_chan(i,ci)%errinv= inverse_observation_error(ii)
560  all_data_chan(i,ci)%qcmark= qc_flag(ii)
561  ii=ii+1
562  ENDDO
563  ENDDO
564 
565  ELSE
566  print *,'read_aod_diag binary not working - stopping'
567  iflag=-1
568  stop
569  ENDIF
570 
571  END SUBROUTINE read_all_aoddiag
572 
573  SUBROUTINE read_aoddiag_data_nc_init(ftin, header_fix)
574 ! . . . .
575 ! subprogram: read_aoddiag_data_nc_init read rad diag data
576 ! prgmmr: mccarty org: np20 date: 2015-08-10
577 !
578 ! abstract: This routine reads the data record from a netcdf radiance
579 ! diagnostic file
580 !
581 ! program history log:
582 ! 2015-06-10 mccarty - create routine
583 !
584 ! input argument list_aod:
585 ! ftin - unit number connected to diagnostic file
586 ! header_fix - header information structure
587 !
588 ! output argument list_aod:
589 ! data_fix - spot header information structure
590 ! data_chan - spot channel information structure
591 ! iflag - error code
592 !
593 ! attributes:
594 ! language: f90
595 ! machine: ibm RS/6000 SP
596 !
597 !$$$
598 
599 ! Declare passed arguments
600  INTEGER(i_kind),INTENT(in) :: ftin
601  TYPE(diag_header_fix_list_aod ),INTENT(in) :: header_fix
602 
603 ! Declare local variables
604  INTEGER(i_kind) :: nrecord, ndatum, nangord
605  INTEGER(i_kind) :: cch, ic, ir, cdatum
606  REAL(r_kind), ALLOCATABLE, DIMENSION(:) :: Latitude, Longitude, &
607  &Obs_Time, Psfc, Sol_Zenith_Angle, Sol_Azimuth_Angle,&
608  &Observation, Obs_Minus_Forecast_unadjusted, &
609  &Inverse_Observation_Error, QC_Flag
610 
611  INTEGER(i_kind), ALLOCATABLE, DIMENSION(:) :: Channel_Index
612 
613  REAL(r_kind) :: clat, clon
614 
615  ndatum = nc_diag_read_get_dim(ftin,'nobs')
616  nrecord = ndatum / header_fix%nchan
617  num_records = nrecord
618 
619  WRITE(*,*)'Reading ndatum, nrecord=',ndatum,nrecord
620 
621  ALLOCATE( &
622  &channel_index(ndatum), latitude(ndatum), longitude(ndatum), &
623  &obs_time(ndatum), psfc(ndatum),&
624  &sol_zenith_angle(ndatum), sol_azimuth_angle(ndatum),&
625  &observation(ndatum), obs_minus_forecast_unadjusted(ndatum),&
626  &inverse_observation_error(ndatum),qc_flag(ndatum))
627 
628  ALLOCATE( all_data_fix(nrecord) )
629  ALLOCATE( all_data_chan(nrecord, header_fix%nchan))
630 
631  CALL nc_diag_read_get_var('Channel_Index', channel_index)
632  CALL nc_diag_read_get_var('Latitude', latitude)
633  CALL nc_diag_read_get_var('Longitude', longitude)
634  CALL nc_diag_read_get_var('Psfc', psfc)
635  CALL nc_diag_read_get_var('Obs_Time', obs_time)
636  CALL nc_diag_read_get_var('Sol_Zenith_Angle', sol_zenith_angle)
637  CALL nc_diag_read_get_var('Sol_Azimuth_Angle', sol_azimuth_angle)
638  CALL nc_diag_read_get_var('Observation', observation)
639  CALL nc_diag_read_get_var('Obs_Minus_Forecast_unadjusted', obs_minus_forecast_unadjusted)
640  CALL nc_diag_read_get_var('Inverse_Observation_Error', inverse_observation_error)
641  CALL nc_diag_read_get_var('QC_Flag', qc_flag)
642  cdatum = 1
643 
644  DO ir=1,nrecord
645  clat = latitude(cdatum)
646  clon = longitude(cdatum)
647  all_data_fix(ir)%lat = latitude(cdatum)
648  all_data_fix(ir)%lon = longitude(cdatum)
649  all_data_fix(ir)%psfc = psfc(cdatum)
650  all_data_fix(ir)%obstime = obs_time(cdatum)
651  all_data_fix(ir)%solzen_ang = sol_zenith_angle(cdatum)
652  all_data_fix(ir)%solazm_ang = sol_azimuth_angle(cdatum)
653 
654  DO ic=1,header_fix%nchan
655  IF (clat .NE. latitude(cdatum) .OR. clon .NE. longitude(cdatum)) THEN
656  WRITE(*,*) 'ERROR: Lats & Lons are mismatched. This is bad'
657  print *,'irecord=',ir
658  print *,'clat,clon=',clat,clon
659  print *,'lat/lon(datum)=',latitude(cdatum), longitude(cdatum)
660  CALL abort
661  ENDIF
662  cch = channel_index(cdatum)
663  all_data_chan(ir,cch)%aodobs = observation(cdatum)
664  all_data_chan(ir,cch)%omgaod = obs_minus_forecast_unadjusted(cdatum)
665  all_data_chan(ir,cch)%errinv= inverse_observation_error(cdatum)
666  all_data_chan(ir,cch)%qcmark= qc_flag(cdatum)
667 
668  cdatum = cdatum + 1
669  ENDDO
670  ENDDO
671 
672  nc_read = .true.
673  cur_ob_idx = 1
674  END SUBROUTINE read_aoddiag_data_nc_init
675 
676  SUBROUTINE read_aoddiag_data_nc(ftin,header_fix,data_fix,data_chan,iflag )
677 ! . . . .
678 ! subprogram: read_aoddiag_dat read rad diag data
679 ! prgmmr: tahara org: np20 date: 2015-08-10
680 !
681 ! abstract: This routine reads the data record from a netcdf radiance
682 ! diagnostic file
683 !
684 ! program history log:
685 ! 2015-08-10 mccarty - create routine
686 !
687 ! input argument list_aod:
688 ! ftin - unit number connected to diagnostic file
689 ! header_fix - header information structure
690 !
691 ! output argument list_aod:
692 ! data_fix - spot header information structure
693 ! data_chan - spot channel information structure
694 ! iflag - error code
695 !
696 ! attributes:
697 ! language: f90
698 ! machine: ibm RS/6000 SP
699 !
700 !$$$
701 
702 ! Declare passed arguments
703  INTEGER(i_kind),INTENT(in) :: ftin
704  TYPE(diag_header_fix_list_aod ),INTENT(in) :: header_fix
705  TYPE(diag_data_fix_list_aod) ,INTENT(out):: data_fix
706  TYPE(diag_data_chan_list_aod) ,ALLOCATABLE :: data_chan(:)
707  INTEGER(i_kind),INTENT(out) :: iflag
708 
709  iflag = 0
710  IF (.NOT. ALLOCATED(data_chan)) ALLOCATE(data_chan(header_fix%nchan) )
711 
712  data_fix = all_data_fix(cur_ob_idx)
713  data_chan(:) = all_data_chan(cur_ob_idx,:)
714 
715  cur_ob_idx = cur_ob_idx + 1
716 
717  END SUBROUTINE read_aoddiag_data_nc
718 
719  SUBROUTINE read_aoddiag_data_bin(ftin,header_fix,data_fix,data_chan,iflag )
720 ! . . . .
721 ! subprogram: read_aoddiag_dat read rad diag data
722 ! prgmmr: tahara org: np20 date: 2003-01-01
723 !
724 ! abstract: This routine reads the data record from a radiance
725 ! diagnostic file
726 !
727 ! program history log:
728 ! 2010-10-05 treadon - add this doc block
729 ! 2011-02-22 kleist - changes related to memory allocation
730 ! 2017-07-17 mccarty - rename binary-specific procedure
731 !
732 ! input argument list_aod:
733 ! ftin - unit number connected to diagnostic file
734 ! header_fix - header information structure
735 !
736 ! output argument list_aod:
737 ! data_fix - spot header information structure
738 ! data_chan - spot channel information structure
739 ! iflag - error code
740 !
741 ! attributes:
742 ! language: f90
743 ! machine: ibm RS/6000 SP
744 !
745 !$$$
746 
747 
748 ! Declare passed arguments
749  INTEGER(i_kind),INTENT(in) :: ftin
750  TYPE(diag_header_fix_list_aod ),INTENT(in) :: header_fix
751  TYPE(diag_data_fix_list_aod) ,INTENT(out):: data_fix
752  TYPE(diag_data_chan_list_aod) ,ALLOCATABLE :: data_chan(:)
753  INTEGER(i_kind),INTENT(out) :: iflag
754 
755  INTEGER(i_kind) :: ich,iang,i,j
756  REAL(r_single),DIMENSION(:,:),ALLOCATABLE :: data_tmp
757  REAL(r_single),DIMENSION(:),ALLOCATABLE :: fix_tmp
758 
759 ! Allocate arrays as needed
760  IF (ALLOCATED(data_chan)) DEALLOCATE(data_chan)
761  ALLOCATE(data_chan(header_fix%nchan))
762 
763 ! Allocate arrays to hold data record
764  ALLOCATE(data_tmp(header_fix%ipchan,header_fix%nchan))
765 
766  ALLOCATE( fix_tmp( ireal_aod ) )
767 
768 ! Read data record
769 
770  READ(ftin,iostat=iflag) fix_tmp, data_tmp
771 
772 ! Transfer fix_tmp record to output structure
773  data_fix%lat = fix_tmp(1)
774  data_fix%lon = fix_tmp(2)
775  data_fix%psfc = fix_tmp(3)
776  data_fix%obstime = fix_tmp(4)
777  data_fix%solzen_ang = fix_tmp(5)
778  data_fix%solazm_ang = fix_tmp(6)
779 
780 ! Transfer data record to output structure
781  DO ich=1,header_fix%nchan
782  data_chan(ich)%aodobs =data_tmp(1,ich)
783  data_chan(ich)%omgaod =data_tmp(2,ich)
784  data_chan(ich)%errinv=data_tmp(3,ich)
785  data_chan(ich)%qcmark=data_tmp(4,ich)
786  ENDDO
787 
788  DEALLOCATE(data_tmp, fix_tmp)
789 
790  END SUBROUTINE read_aoddiag_data_bin
791 
792 END MODULE read_aod_diag
793 
subroutine, public read_aoddiag_data(ftin, header_fix, data_fix, data_chan, iflag)
integer(i_kind), parameter, public ireal_aod
subroutine read_aoddiag_data_bin(ftin, header_fix, data_fix, data_chan, iflag)
integer(i_kind), parameter, public ipchan_aod
subroutine read_aoddiag_data_nc_init(ftin, header_fix)
integer, parameter, public i_kind
Definition: ncd_kinds.F90:71
subroutine set_aoddiag_int_(what, iv, ier)
integer, save num_records
logical, save nc_read
subroutine read_aoddiag_header_nc(ftin, header_fix, header_chan, data_name, iflag, lverbose)
type(diag_data_chan_list_aod), dimension(:,:), allocatable, save all_data_chan
subroutine, public read_all_aoddiag(ftin, header_fix, all_data_fix, all_data_chan, nlocs, iflag)
subroutine read_aoddiag_header_bin(ftin, header_fix, header_chan, data_name, iflag, lverbose)
subroutine read_aoddiag_data_nc(ftin, header_fix, data_fix, data_chan, iflag)
subroutine get_aoddiag_int_(what, iv, ier)
subroutine, public set_netcdf_read_aod(use_netcdf)
subroutine, public read_aoddiag_header(ftin, header_fix, header_chan, data_name, iflag, lverbose)
integer, save cur_ob_idx
type(diag_data_fix_list_aod), dimension(:), allocatable, save all_data_fix
integer, parameter, public r_single
Definition: ncd_kinds.F90:79
logical, save netcdf
integer, parameter, public r_kind
Definition: ncd_kinds.F90:108
real(r_kind), parameter rmiss_aoddiag