-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_satwnd.f90
1539 lines (1410 loc) · 66.3 KB
/
read_satwnd.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
subroutine read_satwnd(nread,ndata,nodata,infile,obstype,lunout,gstime,twind,sis,&
prsl_full,nobs)
!$$$ subprogram documentation block
! . . . .
! subprogram: read_satwnd read satellite winds
! prgmmr: su, xiujuan org: np23 date: 2010-10-13
!
! abstract: This routine reads satellite winds from satellite wind dump.
! it also has options to thin the data by using conventional
! thinning programs
! When running the gsi in regional mode, the code only
! retains those observations that fall within the regional
! domain
! For the satellite ID type: 240: GOES short wave winds,
! 241: India, 242:JMA Visible,243: EUMETSAT visible,244: AVHRR winds
! 245: GOES IR. 246: GOES WV cloud top, 247: GOES WV deep layer
! 250: JMA WV deep layer. 251:GOES visible, 252: JMA IR winds
! 253: EUMETSAT IR winds, 254: EUMETSAT WV deep layer winds
! 257,258,259: MODIS IR,WV cloud top, WV deep layer winds
! 260: VIIR IR winds
! respectively
! For satellite subtype: 50-80 from EUMETSAT geostationary satellites(METEOSAT)
! 100-199 from JMA geostationary satellites(MTSAT)
! 250-299 from NESDIS geostationary satellites(GOES)
! 700-799 from NASA Terra and Aqua satellites
! <10, 200-223 from NOAA-15, 16, 17, 18, polar
! orbit and EUMESAT MetOp satellites
! The quality mark: QM, the values range from 0 to 15, 0-7 used, 8-15
! monitored, 0 is best, when the value greater than
! 3, the observation error needed to be enflated.
! THe quality markers from producer: qifn: QI values without
! forecast considered, qify: QI values with forecast considered, ee:
! Expected error
! program history log:
! 2010-10-13 su, x.
! 2011-08-09 pondeca - add support for twodvar option
! 2011-08-27 todling - bypass this routine when SATWND from prepbufr are used
! 2011-10-03 su - read AVHRR wind into system and modify satellite id range
! and put subset as screen criterie since AVHRR from
! different satellites
! 2011-10-24 -add reading observation error in this subroutine and stop
! statement if no prepbufr error table available.
! 2011-12-08 Su -modify GOES reading program for new bufrtab.005 new format, reading
! SDM quality mark
! 2011-12-20 Su -modify to read deep layer WV winds as monitor with qm=9,considering short
! wave winds as subset 1 0f 245
! 2012-07-18 Sienkiewicz - fix for infrad IR winds monitoring north of 20N
! 2012-10-13 Su -modify the code to assimilate GOES hourly wind, changed the error and quality control
! 2013-01-26 parrish - change from grdcrd to grdcrd1 (to allow successful debug compile on WCOSS)
! 2013-02-13 parrish - set pflag=0 outside loopd to prevent runtime fatal error in debug mode.
! 2013-08-26 McCarty -modified to remove automatic rejection of AVHRR winds
! 2013-09-20 Su - set satellite ID as satellite wind subtype
! 2014-07-16 Su - read VIIRS winds
! 2014-10-16 Su -add optione for 4d thinning and option to keep thinned data
! 2015-02-23 Rancic/Thomas - add thin4d to time window logical
! 2015-02-26 su - add njqc as an option to choose new non linear qc
! 2015-03-23 Su -fix array size with maximum message and subset number from fixed number to
! dynamic allocated array
! 2015-02-26 Genkova - read GOES-R like winds from ASCII files & apply Sharon Nebuda's changes for GOES-R
! 2015-05-12 Genkova - reading from ASCII files removed, read GOES-R from new BUFR, keep Nebuda's GOES-R related changes
! 2015-03-14 Nebuda - add QC for clear air WV AMV (WVCS) from GOES type 247, removed PCT1 check not applicable to 247
! 2015-10-01 guo - consolidate use of ob location (in deg)
! 2016-03-15 Su - modified the code so that the program won't stop when
! no subtype is found in non linear qc error table and b table ! table
! 2016-05-05 pondeca - add 10-m u-wind and v-wind (uwnd10m, vwnd10m)
! 2016-12-13 Lim - Addition of GOES SWIR, CAWV and VIS winds into HWRF
! 2017-08-22 Genkova - Testing Git / Add Goes-16 and JPSS SatID
! - Read WMO pre-approved new BUFR Goes-16 AMVs (Goes-R)
! 2018-06-13 Genkova - Goes-16 AMVs use ECMWF QC till new HAM late 2018
! and OE/2
!
!
!
! input argument list:
! ithin - flag to thin data
! rmesh - thinning mesh size (km)
! gstime - analysis time in minutes from reference date
! infile - unit from which to read BUFR data
! lunout - unit to which to write data for further processing
! obstype - observation type to process
! twind - input group time window (hours)
! sis - satellite/instrument/sensor indicator
!
! output argument list:
! nread - number of satellite winds read
! ndata - number of satellite winds retained for further processing
! nodata - number of satellite winds retained for further processing
! nobs - array of observations on each subdomain for each processor
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use kinds, only: r_kind,r_double,i_kind,r_single
use gridmod, only: diagnostic_reg,regional,nlon,nlat,nsig,&
tll2xy,txy2ll,rotate_wind_ll2xy,rotate_wind_xy2ll,&
rlats,rlons,twodvar_regional,wrf_nmm_regional
use qcmod, only: errormod,njqc
use convthin, only: make3grids,map3grids,map3grids_m,del3grids,use_all
use convthin_time, only: make3grids_tm,map3grids_tm,map3grids_m_tm,del3grids_tm,use_all_tm
use constants, only: deg2rad,zero,rad2deg,one_tenth,&
tiny_r_kind,huge_r_kind,r60inv,one_tenth,&
one,two,three,four,five,half,quarter,r60inv,r100,r2000
use converr,only: etabl
use converr_uv,only: etabl_uv,isuble_uv,maxsub_uv
use convb_uv,only: btabl_uv
use obsmod, only: perturb_obs,perturb_fact,ran01dom,bmiss
use convinfo, only: nconvtype, &
icuse,ictype,icsubtype,ioctype, &
ithin_conv,rmesh_conv,pmesh_conv,pmot_conv,ptime_conv, &
use_prepb_satwnd, ec_amv_qc
use gsi_4dvar, only: l4dvar,l4densvar,iwinbgn,winlen,time_4dvar,thin4d
use deter_sfc_mod, only: deter_sfc_type,deter_sfc2
use mpimod, only: npe
implicit none
! Declare passed variables
character(len=*) ,intent(in ) :: infile,obstype
character(len=20) ,intent(in ) :: sis
integer(i_kind) ,intent(in ) :: lunout
integer(i_kind) ,intent(inout) :: nread,ndata,nodata
integer(i_kind),dimension(npe) ,intent(inout) :: nobs
real(r_kind) ,intent(in ) :: twind
real(r_kind),dimension(nlat,nlon,nsig),intent(in ) :: prsl_full
! Declare local parameters
real(r_kind),parameter:: r1_2= 1.2_r_kind
real(r_kind),parameter:: r3_33= 3.33_r_kind
real(r_kind),parameter:: r6= 6.0_r_kind
real(r_kind),parameter:: r50= 50.0_r_kind
real(r_kind),parameter:: r80= 80.0_r_kind
real(r_kind),parameter:: r90= 90.0_r_kind
real(r_kind),parameter:: r105= 105.0_r_kind
real(r_kind),parameter:: r110= 110.0_r_kind
real(r_kind),parameter:: r125=125.0_r_kind
real(r_kind),parameter:: r200=200.0_r_kind
real(r_kind),parameter:: r250=250.0_r_kind
real(r_kind),parameter:: r360 = 360.0_r_kind
real(r_kind),parameter:: r600=600.0_r_kind
real(r_kind),parameter:: r700=700.0_r_kind
real(r_kind),parameter:: r850=850.0_r_kind
real(r_kind),parameter:: r199=199.0_r_kind
real(r_kind),parameter:: r299=299.0_r_kind
real(r_kind),parameter:: r799=799.0_r_kind
real(r_kind),parameter:: r1200= 1200.0_r_kind
real(r_kind),parameter:: r10000= 10000.0_r_kind
!hliu---------------------------------------------
real(i_kind),parameter:: nlay=18, nreg=3
! Declare local variables
logical outside,inflate_error
logical luse,ithinp
logical,allocatable,dimension(:,:):: lmsg ! set true when convinfo entry id found in a message
character(70) obstr_v1, obstr_v2,hdrtr_v1,hdrtr_v2
character(50) qcstr
character(8) subset
! character(20) derdwtr,heightr
character(8) c_prvstg,c_sprvstg
character(8) c_station_id,stationid
integer(i_kind) mxtb,nmsgmax
integer(i_kind) ireadmg,ireadsb,iuse
integer(i_kind) i,maxobs,idomsfc,nsattype,ncount
integer(i_kind) nc,nx,isflg,itx,j,nchanl
integer(i_kind) ntb,ntmatch,ncx,ncsave,ntread
integer(i_kind) kk,klon1,klat1,klonp1,klatp1
integer(i_kind) nmind,lunin,idate,ilat,ilon,iret,k
integer(i_kind) nreal,ithin,iout,ntmp,icount,iiout,ii
integer(i_kind) itype,iosub,ixsub,isubsub,iobsub,itypey,ierr
integer(i_kind) qm
integer(i_kind) nlevp ! vertical level for thinning
integer(i_kind) pflag
integer(i_kind) ntest,nvtest
!hliu------------------------------
logical noftc
integer(i_kind) kl,k1,k2, n8, k8, lnd
! integer(i_kind) kl,k1,k2
real(r_kind):: factor
integer(i_kind) nmsg ! message index
integer(i_kind),dimension(nconvtype) :: ntxall
integer(i_kind),dimension(nconvtype+1) :: ntx
integer(i_kind),dimension(5):: idate5
integer(i_kind),allocatable,dimension(:):: nrep,isort,iloc
integer(i_kind),allocatable,dimension(:,:):: tab
integer(i_kind) ntime,itime
real(r_kind) toff,t4dv
real(r_kind) rmesh,ediff,usage,tdiff
real(r_kind) u0,v0,uob,vob,dx,dy,dx1,dy1,w00,w10,w01,w11
real(r_kind) dlnpob,ppb,ppb2,qifn,qify,ee,ree,pct1,experr_norm, ppb00
real(r_kind) woe,dlat,dlon,dlat_earth,dlon_earth
real(r_kind) dlat_earth_deg,dlon_earth_deg
real(r_kind) cdist,disterr,disterrmax,rlon00,rlat00
real(r_kind) vdisterrmax,u00,v00,uob1,vob1
real(r_kind) del,werrmin,obserr,ppb1,var_jb,wjbmin,wjbmax
real(r_kind) tsavg,ff10,sfcr,sstime,gstime,zz
real(r_kind) crit1,timedif,xmesh,pmesh,pmot,ptime
real(r_kind),dimension(nsig):: presl
real(r_double),dimension(13):: hdrdat
real(r_double),dimension(4):: obsdat
real(r_double),dimension(2) :: hdrdat_test
real(r_double),dimension(3,5) :: heightdat
real(r_double),dimension(6,4) :: derdwdat
real(r_double),dimension(3,12) :: qcdat
real(r_double),dimension(1,1):: r_prvstg,r_sprvstg
real(r_kind),allocatable,dimension(:):: presl_thin
real(r_kind),allocatable,dimension(:):: rusage
real(r_kind),allocatable,dimension(:,:):: cdata_all,cdata_out
! GOES-16 new BUFR related variables
real(r_double) :: rep_array
integer(i_kind) :: irep_array
! real(r_double),allocatable,dimension(:,:) :: amvaha ! Alternative height assignment in AMV
! real(r_double),allocatable,dimension(:,:) :: amviii ! Individual images imformation in AMV
! real(r_double),allocatable,dimension(:,:) :: amvcld ! AMV vectors cloud information
real(r_double),allocatable,dimension(:,:) :: amvivr ! Intermediate vectors retrieved in AMV
real(r_double),dimension(2,4) :: amvqic ! AMV quality indicator confidence
real(r_double) rstation_id
!hliu-----------------------------------------------------
! ratio of STDV in O-B (FTC/OPER) definition level
!
real(r_kind) pave(nlay), erradj(nreg, nlay, 240:260), obserr00
data pave /150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 550.0, 600.0, &
650.0, 700.0, 750.0, 800.0, 850.0, 900.0, 950.0, 1000.0/
!hliu---------------------------
! equivalence to handle character names
equivalence(r_prvstg(1,1),c_prvstg)
equivalence(r_sprvstg(1,1),c_sprvstg)
equivalence(rstation_id,c_station_id)
data hdrtr_v1 /'SAID CLAT CLON YEAR MNTH DAYS HOUR MINU SWCM SAZA OGCE SCCF SWQM'/ ! OGCE replaces GCLONG, OGCE exists in old and new BUFR
data hdrtr_v2 /'SAID CLATH CLONH YEAR MNTH DAYS HOUR MINU SWCM SAZA OGCE SCCF SWQM'/ ! OGCE replaces GCLONG, OGCE exists in old and new BUFR
! SWQM doesn't exist in the new BUFR, so qm is initialized to '2' manually
data obstr_v1 /'HAMD PRLC WDIR WSPD'/
data obstr_v2 /'EHAM PRLC WDIR WSPD'/
! data heightr/'MDPT '/
! data derdwtr/'TWIND'/
data qcstr /' OGCE GNAP PCCF'/
data ithin / -9 /
data lunin / 11 /
data rmesh / -99.999_r_kind /
!hliu---------------------------------------------------------------------
open(8888, file='AMV_errratio.dat.dftc2', form='formatted', status='old')
do lnd=1, nreg
do k8 =1, nlay
read(8888, '(21f5.2)') (erradj(lnd, k8, n8), n8=240, 260)
enddo
enddo
close(8888)
do lnd=1, nreg
do k8 =1, nlay
write(*, '(21f5.2)') (erradj(lnd, k8, n8), n8=240, 260)
enddo
enddo
!!hliu--------------------------------------
! ithin_conv = 1
! rmesh_conv = 5000.0
! pmesh_conv = 500.0
!! rmesh= 6000.0
!! pmesh= 500.0
!!hliu---------------------------------------------------------------------
! Return when SATWND are coming from prepbufr file
if(use_prepb_satwnd) return
! read observation error table
disterrmax=zero
vdisterrmax=zero
wjbmin=zero
wjbmax=5.0_r_kind
pflag=0
var_jb=zero
! allocate(etabl(302,33,6)) ! add 2 ObsErr profiles for GOES-R IR(itype=301) and WV(itype=300) (not used yet, 2015-07-08, Genkova)
! Set lower limits for observation errors
werrmin=one
nsattype=0
nreal=25
if(perturb_obs ) nreal=nreal+2
ntread=1
ntmatch=0
ntx(ntread)=0
ntxall=0
do nc=1,nconvtype
if( (trim(ioctype(nc)) == 'uv' .or. trim(ioctype(nc)) == 'wspd10m' .or. trim(ioctype(nc)) == 'uwnd10m' .or. trim(ioctype(nc)) == 'vwnd10m') .and. ictype(nc) >=240 &
.and. ictype(nc) <=265) then
ntmatch=ntmatch+1
ntxall(ntmatch)=nc
ithin=ithin_conv(nc)
if(ithin > 0)then
ntread=ntread+1
ntx(ntread)=nc
end if
end if
end do
if(ntmatch == 0)then
write(6,*) ' READ_SATWND: no matching obstype found in obsinfo ',obstype
return
end if
!! go through the satedump to find out how many subset to process
!! get message and subset counts
call getcount_bufr(infile,nmsgmax,mxtb)
allocate(lmsg(nmsgmax,ntread),tab(mxtb,3),nrep(nmsgmax))
lmsg = .false.
maxobs=0
tab=0
nmsg=0
nrep=0
ntb =0
call closbf(lunin)
open(lunin,file=trim(infile),form='unformatted')
call openbf(lunin,'IN',lunin)
call datelen(10)
msg_report: do while (ireadmg(lunin,subset,idate) == 0)
! if(trim(subset) == 'NC005012') cycle msg_report
! Time offset
if(nmsg == 0) call time_4dvar(idate,toff)
nmsg=nmsg+1
if (nmsg>nmsgmax) then
write(6,*)'READ_SATWND: messages exceed maximum ',nmsgmax
call stop2(49)
endif
loop_report: do while (ireadsb(lunin) == 0)
ntb = ntb+1
maxobs=maxobs+1
nrep(nmsg)=nrep(nmsg)+1
if (ntb>mxtb) then
write(6,*)'READ_SATWND: reports exceed maximum ',mxtb
call stop2(49)
endif
call ufbint(lunin,hdrdat,13,1,iret,hdrtr_v1)
! SWQM doesn't exist for GOES-R/new BUFR/ hence hdrdat(13)=MISSING.
! qm=2, instead of using hdrdat(13)(2015-07-16, Genkova)
iobsub=0
itype=-1
iobsub=int(hdrdat(1))
if(trim(subset) == 'NC005064' .or. trim(subset) == 'NC005065' .or. &
trim(subset) == 'NC005066') then
if( hdrdat(1) <r80 .and. hdrdat(1) >= r50) then !the range of EUMETSAT satellite IDS
if(hdrdat(9) == one) then ! IR winds
itype=253
else if(hdrdat(9) == two) then ! visible winds
itype=243
else if(hdrdat(9) == three) then ! WV cloud top
itype=254
else if(hdrdat(9) >= four) then ! WV deep layer, monitored
itype=254
endif
endif
else if(trim(subset) == 'NC005044' .or. trim(subset) == 'NC005045' .or. &
trim(subset) == 'NC005046') then
if( hdrdat(1) >=r100 .and. hdrdat(1) <=r199 ) then ! the range of JMA satellite IDS
if(hdrdat(9) == one) then ! IR winds
itype=252
else if(hdrdat(9) == two) then ! visible winds
itype=242
else if(hdrdat(9) == three) then ! WV cloud top
itype=250
else if(hdrdat(9) >= four) then ! WV deep layer,monitored
itype=250
endif
endif
else if(trim(subset) == 'NC005010' .or. trim(subset) == 'NC005011' .or. &
trim(subset) == 'NC005012' ) then
if( hdrdat(1) >=r250 .and. hdrdat(1) <=r299 ) then ! the range of NESDIS satellite IDS
if(hdrdat(9) == one) then ! IR winds
if(hdrdat(12) <50000000000000.0_r_kind) then
itype=245
else
itype=240 ! short wave IR winds
endif
else if(hdrdat(9) == two ) then ! visible winds
itype=251
else if(hdrdat(9) == three ) then ! WV cloud top
itype=246
else if(hdrdat(9) >= four ) then ! WV deep layer,monitored
itype=247
endif
endif
else if(trim(subset) == 'NC005070' .or. trim(subset) == 'NC005071' ) then
if( hdrdat(1) >=r700 .and. hdrdat(1) <= r799 ) then ! the range of NASA Terra and Aqua satellite IDs
if(hdrdat(9) == one) then ! IR winds
itype=257
else if(hdrdat(9) == three) then ! WV cloud top
itype=258
else if(hdrdat(9) >= four) then ! WV deep layer
itype=259
endif
endif
else if( trim(subset) == 'NC005080') then
if( hdrdat(1) <10.0_r_kind .or. (hdrdat(1) >= 200.0_r_kind .and. &
hdrdat(1) <=223.0_r_kind) ) then ! the range of EUMETSAT and NOAA polar orbit satellite IDs
if(hdrdat(9) == one) then ! IR winds
itype=244
else
write(6,*) 'READ_SATWND: wrong derived method value'
endif
endif
else if( trim(subset) == 'NC005019') then ! GOES shortwave winds
if(hdrdat(1) >=r250 .and. hdrdat(1) <=r299 ) then ! The range of NESDIS satellite IDS
if(hdrdat(9) == one) then ! short wave IR winds
itype=240
endif
endif
else if( trim(subset) == 'NC005090') then ! VIIRS winds
if(hdrdat(1) >=r200 .and. hdrdat(1) <=r250 ) then ! The range of satellite IDS
if(hdrdat(9) == one) then ! VIIRS IR winds
itype=260
endif
endif
!GOES-R section of the 'if' statement over 'subsets'
else if(trim(subset) == 'NC005030' .or. trim(subset) == 'NC005031' .or. trim(subset) == 'NC005032' .or. &
trim(subset) == 'NC005034' .or. trim(subset) == 'NC005039') then
! Commented out, because we need clarification for SWCM/hdrdat(9) from Yi Song
! NOTE: Once it is confirmed that SWCM values are sensible, apply this logic and replace lines 685-702
! if(hdrdat(9) == one) then
! if(hdrdat(12) <50000000000000.0_r_kind) then
! itype=245 ! GOES-R IR(LW) winds
! else
! itype=240 ! GOES-R IR(SW) winds
! endif
! else if(hdrdat(9) == two ) then
! itype=251 ! GOES-R VIS winds
! else if(hdrdat(9) == three ) then
! itype=246 ! GOES-R CT WV winds
! else if(hdrdat(9) >= four ) then
! itype=247 ! GOES-R CS WV winds
! endif
!Temporary solution replacing the commented code above
if(trim(subset) == 'NC005030') then ! IR LW winds
itype=245
else if(trim(subset) == 'NC005039') then ! IR SW winds
itype=240
else if(trim(subset) == 'NC005032') then ! VIS winds
itype=251
else if(trim(subset) == 'NC005034') then ! WV cloud top
itype=246
else if(trim(subset) == 'NC005031') then ! WV clear sky/deep layer
itype=247
endif
endif
! Match ob to proper convinfo type
ncsave=0
matchloop:do ncx=1,ntmatch
nc=ntxall(ncx)
if (itype /= ictype(nc)) cycle matchloop
! Find convtype which match ob type and subtype
if(icsubtype(nc) == iobsub) then
ncsave=nc
exit matchloop
else
! Find convtype which match ob type and subtype group (isubtype == ?*)
! where ? specifies the group and icsubtype = ?0)
ixsub=icsubtype(nc)/10
iosub=iobsub/10
isubsub=icsubtype(nc)-ixsub*10
if(ixsub == iosub .and. isubsub == 0) then
ncsave=nc
! Find convtype which match ob type and subtype is all remaining
! (icsubtype(nc) = 0)
else if (ncsave == 0 .and. icsubtype(nc) == 0) then
ncsave=nc
end if
end if
end do matchloop
! Save information for next read
if(ncsave /= 0) then
maxobs=maxobs+1
nx=1
if(ithin_conv(ncsave) > 0)then
do ii=2,ntread
if(ntx(ii) == ncsave)nx=ii
end do
end if
tab(ntb,1)=ncsave
tab(ntb,2)=nx
tab(ntb,3)=1
lmsg(nmsg,nx) = .true.
end if
enddo loop_report
enddo msg_report
allocate(cdata_all(nreal,maxobs),isort(maxobs),rusage(maxobs))
isort = 0
cdata_all=zero
nread=0
ntest=0
nvtest=0
nchanl=0
ilon=2
ilat=3
rusage=101.0_r_kind
! Open, then read date from bufr data
!! read satellite winds one type a time
loop_convinfo: do nx=1,ntread
use_all = .true.
use_all_tm = .true.
ithin=0
if(nx >1) then
nc=ntx(nx)
ithin=ithin_conv(nc)
if (ithin > 0 ) then
rmesh=rmesh_conv(nc)
pmesh=pmesh_conv(nc)
pmot=pmot_conv(nc)
ptime=ptime_conv(nc)
if(pmesh > zero) then
pflag=1
nlevp=r1200/pmesh
else
pflag=0
nlevp=nsig
endif
xmesh=rmesh
if( ptime >zero) then
use_all_tm = .false.
ntime=6.0_r_kind/ptime !! 6 hour winddow
call make3grids_tm(xmesh,nlevp,ntime)
else
use_all = .false.
call make3grids(xmesh,nlevp)
endif
if (.not.use_all .or. .not.use_all_tm) then
allocate(presl_thin(nlevp))
if (pflag==1) then
do k=1,nlevp
presl_thin(k)=(r1200-(k-1)*pmesh)*one_tenth
enddo
endif
endif
write(6,'(a52,a16,I5,f10.2,2i5,f10.2,i5,2f10.2)') &
' READ_SATWND: ictype(nc),rmesh,pflag,nlevp,pmesh,nc ', &
ioctype(nc),ictype(nc),rmesh,pflag,nlevp,pmesh,nc,pmot,ptime
endif
endif
call closbf(lunin)
open(lunin,file=trim(infile),form='unformatted')
call openbf(lunin,'IN',lunin)
call datelen(10)
ntb = 0
nmsg = 0
ncount=0
loop_msg: do while(IREADMG(lunin,subset,idate) == 0)
nmsg = nmsg+1
if(.not.lmsg(nmsg,nx)) then
ntb=ntb+nrep(nmsg)
cycle loop_msg ! no useable reports this mesage, skip ahead report count
end if
loop_readsb: do while(ireadsb(lunin) == 0)
ntb = ntb+1
nc=tab(ntb,1)
if(nc <= 0 .or. tab(ntb,2) /= nx) cycle loop_readsb
hdrdat=bmiss
obsdat=bmiss
heightdat=bmiss
derdwdat=bmiss
qcdat=bmiss
iobsub=0
itype=-1
uob=bmiss
vob=bmiss
ppb=bmiss
ppb1=bmiss
ppb2=bmiss
uob1=bmiss
vob1=bmiss
ee=r110
qifn=r110
qify=r110
! Test for BUFR version using lat/lon mnemonics
call ufbint(lunin,hdrdat_test,2,1,iret, 'CLAT CLON')
if ( hdrdat_test(1) > 100000000.0_r_kind .and. hdrdat_test(2) > 100000000.0_r_kind ) then
call ufbint(lunin,hdrdat,13,1,iret,hdrtr_v2)
call ufbint(lunin,obsdat,4,1,iret,obstr_v2)
else
call ufbint(lunin,hdrdat,13,1,iret,hdrtr_v1)
call ufbint(lunin,obsdat,4,1,iret,obstr_v1)
endif
ppb=obsdat(2)
if (ppb > 100000000.0_r_kind .or. &
hdrdat(3) >100000000.0_r_kind .or. &
obsdat(4) > 100000000.0_r_kind) cycle loop_readsb
if(ppb >r10000) ppb=ppb/r100
if (ppb <r125) cycle loop_readsb ! reject data above 125mb
!hliu ----------------------------------------
ppb00 = ppb ! in mb
if(hdrdat(13) == 12.0_r_kind .or. hdrdat(13) == 14.0_r_kind) cycle loop_readsb
if (twodvar_regional .and. ppb <r850) cycle loop_readsb
! reject the data with bad quality mark from SDM
if(hdrdat(13) == 12.0_r_kind .or. hdrdat(13) == 14.0_r_kind) cycle loop_readsb
! Compare relative obs time with window. If obs
! falls outside of window, don't use this obs
idate5(1) = hdrdat(4) !year
idate5(2) = hdrdat(5) ! month
idate5(3) = hdrdat(6) ! day
idate5(4) = hdrdat(7) ! hours
idate5(5) = hdrdat(8) ! minutes
call w3fs21(idate5,nmind)
t4dv = real((nmind-iwinbgn),r_kind)*r60inv
sstime = real(nmind,r_kind)
tdiff=(sstime-gstime)*r60inv
if (l4dvar.or.l4densvar) then
if (t4dv<zero .OR. t4dv>winlen) cycle loop_readsb
else
if (abs(tdiff)>twind) cycle loop_readsb
endif
iosub=0
if(abs(hdrdat(2)) >r90 ) cycle loop_readsb
if( hdrdat(3) <zero) hdrdat(3) = hdrdat(3) + r360
if( hdrdat(3) == r360) hdrdat(3) = hdrdat(3) - r360
if( hdrdat(3) > r360) cycle loop_readsb
qm=2
iobsub=int(hdrdat(1))
write(stationid,'(i3)') iobsub
! assign types and get quality info : start
if(trim(subset) == 'NC005064' .or. trim(subset) == 'NC005065' .or. &
trim(subset) == 'NC005066') then
if( hdrdat(1) <r80 .and. hdrdat(1) >= r50) then ! the range of EUMETSAT satellite IDs
c_prvstg='EUMETSAT'
if(hdrdat(10) >68.0_r_kind) cycle loop_readsb ! reject data zenith angle >68.0 degree
if(hdrdat(9) == one) then ! IR winds
itype=253
c_station_id='IR'//stationid
c_sprvstg='IR'
else if(hdrdat(9) == two) then ! visible winds
itype=243
c_station_id='VI'//stationid
c_sprvstg='VI'
else if(hdrdat(9) == three) then ! WV cloud top, try to assimilate
itype=254
c_station_id='WV'//stationid
c_sprvstg='WV'
else if(hdrdat(9) >= four) then ! WV deep layer,monitoring
itype=254
qm=9 ! quality mark as 9, means the observation error needed to be set
c_station_id='WV'//stationid
c_sprvstg='WV'
endif
! get quality information
call ufbrep(lunin,qcdat,3,12,iret,qcstr)
do j=4,9
if( qify <r105 .and. qifn <r105 .and. ee <r105) exit
if(qcdat(2,j) < r10000 .and. qcdat(3,j) <r10000) then
if(qcdat(2,j) == one .and. qify >r105) then
qify=qcdat(3,j)
else if(qcdat(2,j) == two .and. qifn >r105) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == three .and. ee >r105) then
ee=qcdat(3,j)
endif
endif
enddo
if(qifn <85.0_r_kind ) then ! qifn, QI without forecast
qm=15
endif
endif
else if(trim(subset) == 'NC005044' .or. trim(subset) == 'NC005045' .or. & ! JMA
trim(subset) == 'NC005046') then
if(hdrdat(1) >=r100 .and. hdrdat(1) <=r199 ) then ! the range of JMA satellite IDS
c_prvstg='JMA'
if(hdrdat(10) >68.0_r_kind) cycle loop_readsb ! reject data zenith angle >68.0 degree
if(hdrdat(9) == one) then ! IR winds
itype=252
c_station_id='IR'//stationid
c_sprvstg='IR'
else if(hdrdat(9) == two) then ! visible winds
itype=242
c_station_id='VI'//stationid
c_sprvstg='VI'
else if(hdrdat(9) == three) then ! WV cloud top
itype=250
c_station_id='WV'//stationid
c_sprvstg='WV'
else if(hdrdat(9) >=four) then ! WV deep layer,as monitoring
itype=250
qm=9
c_station_id='WV'//stationid
c_sprvstg='WV'
endif
! get quality information
call ufbrep(lunin,qcdat,3,12,iret,qcstr)
do j=4,9
if( qify <=r105 .and. qifn <r105 .and. ee <r105) exit
if(qcdat(2,j) <= r10000 .and. qcdat(3,j) <r10000) then
if(qcdat(2,j) == 101.0_r_kind .and. qify >r105 ) then
qify=qcdat(3,j)
else if(qcdat(2,j) == 102.0_r_kind .and. qifn >r105 ) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == 103.0_r_kind .and. ee >r105) then
ee=qcdat(3,j)
endif
endif
enddo
if(qifn <85.0_r_kind ) then ! qifn: QI value without forecast
qm=15
endif
endif
else if(trim(subset) == 'NC005010' .or. trim(subset) == 'NC005011' .or. & ! NESDIS GOES
trim(subset) == 'NC005012' ) then
if(hdrdat(1) >=r250 .and. hdrdat(1) <=r299 ) then ! the range of NESDIS satellite IDS
c_prvstg='NESDIS'
if(hdrdat(10) >68.0_r_kind) cycle loop_readsb ! reject data zenith angle >68.0 degree
if(hdrdat(9) == one) then ! IR winds
if(hdrdat(12) <50000000000000.0_r_kind) then ! for channel 4
itype=245
c_station_id='IR'//stationid
c_sprvstg='IR'
else
itype=240 ! short wave winds
c_station_id='IR'//stationid
c_sprvstg='IR'
endif
else if(hdrdat(9) == two ) then ! visible winds
itype=251
c_station_id='VI'//stationid
c_sprvstg='VI'
else if(hdrdat(9) == three) then ! WV cloud top
itype=246
c_station_id='WV'//stationid
c_sprvstg='WV'
else if(hdrdat(9) >= four) then ! WV deep layer.mornitored set in convinfo file
itype=247
c_station_id='WV'//stationid
c_sprvstg='WV'
endif
call ufbrep(lunin,qcdat,3,8,iret,qcstr)
! get quality information
do j=1,8
if( qify <=r105 .and. qifn <r105 .and. ee < r105) exit
if(qcdat(2,j) <= r10000 .and. qcdat(3,j) <r10000) then
if( qcdat(2,j) == one .and. qifn >r105 ) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == three .and. qify >r105) then
qify=qcdat(3,j)
else if( qcdat(2,j) == four .and. ee >r105) then
ee=qcdat(3,j)
endif
endif
enddo
!QI not applied to CAWV for now - may in the future
if(qifn <85.0_r_kind .and. itype /= 247) then
qm=15
endif
if(wrf_nmm_regional) then
! Minimum speed requirement for CAWV of 8m/s for HWRF.
! Tighten QC for 247 winds by removing winds below 450hPa
if(itype == 247 .and. obsdat(4) < 8.0_r_kind .and. ppb > 450.0_r_kind) then
qm=15
! Tighten QC for 240 winds by remove winds above 700hPa
elseif(itype == 240 .and. ppb < 700.0_r_kind) then
qm=15
! Tighten QC for 251 winds by remove winds above 750hPa
elseif(itype == 251 .and. ppb < 750.0_r_kind) then
qm=15
endif
else
! Minimum speed requirement for CAWV of 10m/s
if(itype == 247 .and. obsdat(4) < 10.0_r_kind) then
qm=15
endif
endif
endif
else if(trim(subset) == 'NC005070' .or. trim(subset) == 'NC005071') then ! MODIS
if(hdrdat(1) >=r700 .and. hdrdat(1) <= r799 ) then
c_prvstg='MODIS'
if(hdrdat(9) == one) then ! IR winds
itype=257
c_station_id='IR'//stationid
c_sprvstg='IR'
else if(hdrdat(9) == three) then ! WV cloud top
itype=258
c_station_id='WV'//stationid
c_sprvstg='WVCLOP'
else if(hdrdat(9) >= four) then ! WV deep layer
itype=259
c_station_id='WV'//stationid
c_sprvstg='WVDLAYER'
endif
! get quality information
call ufbrep(lunin,qcdat,3,8,iret,qcstr)
do j=1,8
if( qify <=r105 .and. qifn <r105 .and. ee < r105) exit
if(qcdat(2,j) <= r10000 .and. qcdat(3,j) <r10000) then
if(qcdat(2,j) == one .and. qifn >r105) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == three .and. qify >r105) then
qify=qcdat(3,j)
else if( qcdat(2,j) == four .and. ee >r105 ) then
ee=qcdat(3,j)
endif
endif
enddo
endif
else if( trim(subset) == 'NC005080') then ! AVHRR
if(hdrdat(1) <10.0_r_kind .or. (hdrdat(1) >= 200.0_r_kind .and. &
hdrdat(1) <=223.0_r_kind) ) then
c_prvstg='AVHRR'
if(hdrdat(9) == one) then ! IR winds
itype=244
else
write(6,*) 'READ_SATWND: wrong derived method value'
endif
! get quality information
call ufbrep(lunin,qcdat,3,8,iret,qcstr)
do j=1,6
if( qify <=r105 .and. qifn <r105 .and. ee <r105) exit
if(qcdat(2,j) <= r10000 .and. qcdat(3,j) <r10000 ) then
if(qcdat(2,j) == one .and. qifn >r105) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == three .and. qify >r105) then
qify=qcdat(3,j)
else if( qcdat(2,j) == four .and. ee >r105) then
ee=qcdat(3,j)
endif
endif
enddo
endif
else if( trim(subset) == 'NC005019') then ! GOES shortwave winds
if(hdrdat(1) >=r250 .and. hdrdat(1) <=r299 ) then ! The range of NESDIS satellite IDS
c_prvstg='NESDIS'
if(hdrdat(10) >68.0_r_kind) cycle loop_readsb ! reject data zenith angle >68.0 degree
if(hdrdat(9) == one) then ! short wave IR winds
itype=240
c_station_id='IR'//stationid
c_sprvstg='IR'
endif
! get quality information
call ufbrep(lunin,qcdat,3,8,iret,qcstr)
do j=1,6
if( qify <=r105 .and. qifn <r105 .and. ee <r105) exit
if(qcdat(2,j) <= r10000 .and. qcdat(3,j) <r10000 ) then
if(qcdat(2,j) == one .and. qifn >r105) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == three .and. qify >r105) then
qify=qcdat(3,j)
else if( qcdat(2,j) == four .and. ee >r105) then
ee=qcdat(3,j)
endif
endif
enddo
! Tighten QC for 240 winds by removing winds above 700hPa
if(wrf_nmm_regional) then
if(itype == 240 .and. ppb < 700.0_r_kind) qm=15
endif
endif
else if( trim(subset) == 'NC005090') then ! VIIRS IR winds
if(hdrdat(1) >=r200 .and. hdrdat(1) <=r250 ) then ! The range of satellite IDS
c_prvstg='VIIRS'
if(hdrdat(9) == one) then ! VIIRS IR winds
itype=260
c_station_id='IR'//stationid
c_sprvstg='IR'
endif
! get quality information
call ufbrep(lunin,qcdat,3,8,iret,qcstr)
do j=1,6
if( qify <=r105 .and. qifn <r105 .and. ee <r105) exit
if(qcdat(2,j) <= r10000 .and. qcdat(3,j) <r10000 ) then
if(qcdat(2,j) == one .and. qifn >r105) then
qifn=qcdat(3,j)
else if(qcdat(2,j) == three .and. qify >r105) then
qify=qcdat(3,j)
else if( qcdat(2,j) == four .and. ee >r105) then
ee=qcdat(3,j)
endif
endif
enddo
endif
! Extra block for GOES-R winds: Start
else if(trim(subset) == 'NC005030' .or. trim(subset) == 'NC005031' .or. trim(subset) == 'NC005032' .or. & !IR(LW) / CS WV / VIS GOES-R like winds
trim(subset) == 'NC005034' .or. trim(subset) == 'NC005039' ) then !CT WV / IR(SW) GOES-R like winds
if(hdrdat(1) >=r250 .and. hdrdat(1) <=r299 ) then ! the range of NESDIS satellite IDs
! The sample newBUFR has SAID=259 (GOES-15)
! When GOES-R SAID is assigned, pls check
! if this range is still valid (Genkova))
c_prvstg='NESDIS'
if(hdrdat(10) >68.0_r_kind) cycle loop_readsb ! reject data zenith angle >68.0 degree
if(trim(subset) == 'NC005030') then ! IR LW winds
itype=245
c_station_id='IR'//stationid
c_sprvstg='IR'
!write(6,*)'itype= ',itype
else if(trim(subset) == 'NC005039') then ! IR SW winds
itype=240
c_station_id='IR'//stationid
c_sprvstg='IR'
!write(6,*)'itype= ',itype
else if(trim(subset) == 'NC005032') then ! VIS winds
itype=251
c_station_id='VI'//stationid
c_sprvstg='VI'
!write(6,*)'itype= ',itype
else if(trim(subset) == 'NC005034') then ! WV cloud top
itype=246
c_station_id='WV'//stationid
c_sprvstg='WV'
!write(6,*)'itype= ',itype
else if(trim(subset) == 'NC005031') then ! WV clear sky/deep layer
itype=247
c_station_id='WV'//stationid
c_sprvstg='WV'
!write(6,*)'itype= ',itype
endif
! call ufbint(lunin,rep_array,1,1,iret, '{AMVAHA}')
! irep_array = int(rep_array)
! allocate( amvaha(4,irep_array))
! call ufbint(lunin,amvaha,4,irep_array,iret, 'EHAM PRLC TMDBST HOCT')
! deallocate( amvaha )
!
! call ufbint(lunin,rep_array,1,1,iret, '{AMVIII}')
! irep_array = int(rep_array)
! allocate( amviii(12,irep_array))
! call ufbrep(lunin,amviii,12,irep_array,iret, 'LTDS SCLF SAID SIID CHNM SCCF ORBN SAZA BEARAZ EHAM PRLC TMDBST')
! deallocate( amviii )
call ufbint(lunin,rep_array,1,1,iret, '{AMVIVR}')
irep_array = int(rep_array)
allocate( amvivr(2,irep_array))
call ufbrep(lunin,amvivr,2,irep_array,iret, 'TCOV CVWD')
pct1 = amvivr(2,1) ! use of pct1 (a new variable in the BUFR) is introduced by Nebuda/Genkova
deallocate( amvivr )
! call ufbrep(lunin,rep_array,1,1,iret, '{AMVCLD}')
! irep_array = int(rep_array)
! allocate( amvcld(12,irep_array))
! call ufbrep(lunin,amvcld,12,irep_array,iret, 'FOST CDTP MUCE VSAT TMDBST VSAT CDTP MUCE OECS CDTP HOCT COPT')
! deallocate( amvcld )
call ufbseq(lunin,amvqic,2,4,iret, 'AMVQIC')
qifn = amvqic(2,2) ! QI w/ fcst does not exist in this BUFR
ee = amvqic(2,4) ! NOTE: GOES-R's ee is in [m/s]
! Additional QC introduced by Sharon Nebuda (for GOES-R winds from MSG proxy images)
if (qifn < 80_r_kind .or. qifn > r100 ) qm=15 !reject data with low QI
if (ppb < 125.0_r_kind) qm=15 !reject data above 125hPa: Trop check in setup.f90
experr_norm = 10.0_r_kind - 0.1_r_kind * ee ! introduced by Santek/Nebuda
if (obsdat(4) > 0.1_r_kind) then ! obsdat(4) is the AMV speed
experr_norm = experr_norm/obsdat(4)
else
experr_norm = 100.0_r_kind
end if
if (experr_norm > 0.9_r_kind) qm=15 ! reject data with EE/SPD>0.9
if(wrf_nmm_regional) then
! type 251 has been determine not suitable to be subjected to pct1 range check