10 integer nargs, iargc, n
11 character*256,
allocatable :: arg(:)
25 logical :: debug = .false.
26 integer :: npred_read = 7
27 logical :: sst_ret = .false.
28 integer :: iversion = -9999
29 logical :: append_txt_suffix = .false.
31 logical :: netcdf = .false.
32 character*256 infn, outfn
36 integer,
parameter :: outlun= 52
37 integer,
parameter :: nllun = 53
40 integer iuse, ich, nch, ipr, counter
42 logical,
dimension(:),
allocatable :: luse
45 real(r_single),
parameter :: missing = -9999.999
46 integer,
parameter :: imissing = -9999
47 integer,
parameter :: nvar = 4
50 real(r_quad),
dimension(:),
allocatable :: nobstotal, nobsassim, tbtotal, tbassim, omf_nbc , omf_bc , sigo, jo
51 real(r_quad),
dimension(:,:),
allocatable :: vomf_nbc, vomf_bc
53 real(r_quad),
dimension(:),
allocatable :: totbias , fixbias
54 real(r_quad),
dimension(:,:),
allocatable :: vtotbias, vfixbias
56 real(r_quad),
dimension(:,:),
allocatable :: biasterms
57 real(r_quad),
dimension(:,:,:),
allocatable :: vbiasterms
73 integer :: inobstotal, inobsassim
74 real(r_single) :: rvomf_nbc, rvomf_bc, rvtotbias, rvfixbias
75 real(r_single),
dimension(:),
allocatable :: rvbiasterms
76 character(len=13),
dimension(:),
allocatable :: chfrwn
78 integer,
parameter :: max_npred = 9
80 character(len=10),
dimension(max_npred) :: biasnames
81 data biasnames /
'bc_const ', &
91 real(r_quad) :: cvar, rch
94 character*80 :: nlfn =
'./gsidiag_bin2txt.nl' 106 append_txt_suffix = .false.
110 call getarg(n,arg(n))
113 if (trim(arg(n)).eq.
'-nc4' ) netcdf=.true.
114 if (trim(arg(n)).eq.
'-debug' ) debug=.true.
115 if (trim(arg(n)).eq.
'-sst_ret' ) sst_ret=.true.
116 if (trim(arg(n)).eq.
'-append_txt') append_txt_suffix=.true.
117 if (trim(arg(n)).eq.
'-npred' )
read ( arg(n+1),* ) npred_read
118 if (trim(arg(n)).eq.
'-iversion' )
read ( arg(n+1),* ) iversion
122 if (debug)
write(*,*)
'Debugging on - Verbose Printing' 129 write(*,*)
'Input diag file: ',trim(infn)
130 inquire(file=trim(infn), exist=linfile)
131 if (.not. linfile)
then 132 write(*,*)trim(infn) //
' does not exist - exiting' 136 if (.not. append_txt_suffix)
then 137 outfn = infn(1:
strlen-3) //
'txt' 139 outfn = infn(1:
strlen) //
'.txt' 143 write(*,*)
'Output text summary: ',trim(outfn)
151 open(inlun,file=infn,form=
'unformatted',convert=
'big_endian')
154 write(*,*)
'File opened on lun=',inlun
157 call read_radiag_header( inlun, npred_read, sst_ret, headfix, headchan, headname, iflag, debug )
163 write(*,*)
'Number of Channels: ',nch
164 write(*,*)
'Number of variationalbc predictors: ',npred_read
165 write(*,*)
' predictors: ',biasnames(1:npred_read)
166 write(*,*)
' iversion=',headfix%iversion
169 if (iversion .gt. 0)
then 170 write(*,*)
'BE AWARE THAT iversion IS BEING OVERRIDEN!' 171 write(*,*)
' iversion diag, override=',headfix%iversion,iversion
172 write(*,*)
' (this was made necessary w/ emis bc...hopefully only temporary)' 173 headfix%iversion = iversion
176 allocate(nobstotal(nch), &
186 allocate(vomf_nbc(nvar,nch), &
188 vtotbias(nvar,nch), &
190 allocate(biasterms(nch,max_npred) )
191 allocate(vbiasterms(nvar,nch,max_npred) )
192 allocate(rvbiasterms(max_npred) )
193 allocate(chfrwn(nch) )
214 luse(ich) = (headchan(ich)%iuse .gt. 0)
215 if (headchan(ich)%wave .gt. 100.0)
then 216 write(chfrwn(ich),fmt=
'(F9.3,A4)')headchan(ich)%wave,
'cm-1' 218 write(chfrwn(ich),fmt=
'(F9.3,A4)')headchan(ich)%freq,
'GHz ' 220 if (debug)
write(*,*)
'ich,chfreq or wn=',ich,chfrwn(ich)
224 do while (iflag .ge. 0)
228 if (iflag .lt. 0) cycle
229 counter = counter + 1
233 lqcpass = luse(ich) .and. datachan(ich)%qcmark .eq. 0
236 if (datachan(ich)%tbobs .gt. 0.0 .and. datachan(ich)%tbobs .lt. 450)
then 239 nobstotal(ich) = nobstotal(ich) + 1
240 if (debug .and. nobstotal(ich) .lt. 15) print *,nobstotal(ich),ich,datachan(ich)%tbobs
242 tbtotal(ich) = tbtotal(ich) + datachan(ich)%tbobs
245 nobsassim(ich) = nobsassim(ich) + 1
246 tbassim(ich) = tbassim(ich) + datachan(ich)%tbobs
247 omf_nbc(ich) = omf_nbc(ich) + datachan(ich)%omgnbc
248 call inc_var(datachan(ich)%omgnbc, vomf_nbc(:,ich))
249 omf_bc(ich) = omf_bc(ich) + datachan(ich)%omgbc
250 call inc_var(datachan(ich)%omgbc, vomf_bc(:,ich))
251 sigo(ich) = sigo(ich) + 1.0 / datachan(ich)%errinv
252 jo(ich) = jo(ich) + (datachan(ich)%omgbc * datachan(ich)%errinv)**2
253 totbias(ich) = totbias(ich) + ( datachan(ich)%omgnbc - datachan(ich)%omgbc )
254 call inc_var(datachan(ich)%omgnbc - datachan(ich)%omgbc, vtotbias(:,ich))
255 fixbias(ich) = fixbias(ich) + datachan(ich)%bifix(1)
256 call inc_var(datachan(ich)%bifix(1), vfixbias(:,ich))
257 biasterms(ich,1) = biasterms(ich,1) + datachan(ich)%bicons
258 call inc_var(datachan(ich)%bicons, vbiasterms(:,ich,1))
259 biasterms(ich,2) = biasterms(ich,2) + datachan(ich)%biang
260 call inc_var(datachan(ich)%biang, vbiasterms(:,ich,2))
261 biasterms(ich,3) = biasterms(ich,3) + datachan(ich)%bilap
262 call inc_var(datachan(ich)%bilap, vbiasterms(:,ich,3))
263 biasterms(ich,4) = biasterms(ich,4) + datachan(ich)%bilap2
264 call inc_var(datachan(ich)%bilap2, vbiasterms(:,ich,4))
265 biasterms(ich,5) = biasterms(ich,5) + datachan(ich)%biclw
266 call inc_var(datachan(ich)%biclw, vbiasterms(:,ich,5))
267 biasterms(ich,6) = biasterms(ich,6) + datachan(ich)%bicos
268 call inc_var(datachan(ich)%bicos, vbiasterms(:,ich,6))
269 biasterms(ich,7) = biasterms(ich,7) + datachan(ich)%bisin
270 call inc_var(datachan(ich)%bisin, vbiasterms(:,ich,7))
271 biasterms(ich,8) = biasterms(ich,8) + datachan(ich)%biemis
272 call inc_var(datachan(ich)%biemis, vbiasterms(:,ich,8))
273 biasterms(ich,9) = biasterms(ich,9) + datachan(ich)%bisst
274 call inc_var(datachan(ich)%bisst, vbiasterms(:,ich,9))
277 omf_nbc(ich) = omf_nbc(ich) + datachan(ich)%omgnbc
278 call inc_var(datachan(ich)%omgnbc, vomf_nbc(:,ich))
286 open(unit=outlun,file=outfn)
290 inobstotal = nobstotal(ich)
291 if (nobstotal(ich) .gt. 1)
then 292 tbtotal(ich) = tbtotal(ich) / nobstotal(ich)
295 inobsassim = nobsassim(ich)
296 if (nobsassim(ich) .gt. 0)
then 297 tbassim(ich) = tbassim(ich) / nobsassim(ich)
298 omf_nbc(ich) = omf_nbc(ich) / nobsassim(ich)
300 omf_bc(ich) = omf_bc(ich) / nobsassim(ich)
302 sigo(ich) = sigo(ich) / nobsassim(ich)
303 jo(ich) = jo(ich) / nobsassim(ich)
304 totbias(ich) = totbias(ich) / nobsassim(ich)
306 fixbias(ich) = fixbias(ich) / nobsassim(ich)
309 biasterms(ich,ipr) = biasterms(ich,ipr) / nobsassim(ich)
310 rvbiasterms(ipr) =
ret_stddev(vbiasterms(:,ich,ipr))
313 tbassim(ich) = missing
314 omf_nbc(ich) = missing
316 omf_bc(ich) = missing
320 totbias(ich) = missing
322 fixbias(ich) = missing
325 biasterms(ich,ipr) = missing
326 rvbiasterms(ipr) = missing
330 inobsassim = imissing
331 tbassim(ich) = missing
332 omf_nbc(ich) = omf_nbc(ich) / nobstotal(ich)
334 omf_bc(ich) = missing
338 totbias(ich) = missing
340 fixbias(ich) = missing
343 biasterms(ich,ipr) = missing
344 rvbiasterms(ipr) = missing
348 tbtotal(ich) = missing
349 inobsassim = imissing
350 tbassim(ich) = missing
351 omf_nbc(ich) = missing
353 omf_bc(ich) = missing
357 totbias(ich) = missing
359 fixbias(ich) = missing
362 biasterms(ich,ipr) = missing
363 rvbiasterms(ipr) = missing
366 if (npred_read .lt. max_npred)
then 367 biasterms(ich,npred_read+1:max_npred) = missing
368 rvbiasterms(npred_read+1:max_npred) = missing
372 write(unit=outlun,fmt=
'(A1,A19,3x,A10,3x,A5)')
'!',
'Satellite/Sensor',
'YYYYMMDDHH',
'#chan' 373 write(unit=outlun,fmt=
'(A20,3x,I10,3x,I5)')trim(headfix%isis), headfix%idate, headfix%nchan
390 real(r_single) ,
intent(in) :: x
391 real(r_quad),
dimension(4),
intent(inout) :: arr
395 arr(3) = arr(3) + arr(2)/arr(1)
396 arr(4) = arr(4) + arr(2)*(x-arr(3))
400 real(r_quad) function ret_var(arr)
403 real(r_quad),
dimension(4),
intent(in) :: arr
412 real(r_quad),
dimension(4),
intent(in) :: arr
420 100
format(
"Usage: ",/,/ &
421 " gsidiag_bin2txt.x <options> <filename>",/,/ &
423 " -nc4 : Read NC4 Diag (instead of binary)",/ &
424 " -debug : Set debug verbosity",/ &
425 " -sst_ret : SST BC term is included (default: not included)",/ &
426 " -npred INT : Number of preductors (default: 7)",/ &
427 " -iversion INT : Override iversion with INT (default: use internal iversion)",/ &
428 " -append_txt : Append .txt suffix, instead of replace last three",/ &
429 " characters (default: replaced)",/ &
430 " Note: The GMAO diag files end with .bin or .nc4,",/ &
431 " which is where fixed 3-char truncation originates",/,/,/ &
433 " gsidiag_bin2txt.x nc_4emily_nc4.diag_airs_aqua_ges.20161202_06z.nc4",/ &
435 " nc_4emily_nc4.diag_airs_aqua_ges.20161202_06z.txt",/ &
subroutine, public read_radiag_header(ftin, npred_radiag, retrieval, header_fix, header_chan, data_name, iflag, lverbose)
integer, parameter, public strlen
real(r_quad) function ret_var(arr)
subroutine, public set_netcdf_read(use_netcdf)
subroutine, public read_radiag_data(ftin, header_fix, retrieval, data_fix, data_chan, data_extra, iflag)
real(r_quad) function ret_stddev(arr)
integer, parameter, public r_quad
subroutine inc_var(x, arr)
integer, parameter, public r_single
subroutine nc_diag_read_init(filename, file_ncdr_id, from_push)