Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / da / da_setup_structures / da_setup_obs_structures_radar.inc
blob94991e66645d56f78911eaf110b50ff8f752faae
1 subroutine da_setup_obs_structures_radar( grid, ob, iv )
3    !-------------------------------------------------------------------------
4    ! Purpose: Define, allocate and read radar observation structure.
5    !-------------------------------------------------------------------------
7    implicit none
9    type (y_type),  intent(out)   :: ob  ! Observation structure.
10    type (iv_type), intent(inout) :: iv  ! O-B structure.
11    type (domain),  intent(inout) :: grid  ! First guess structure
13    character(len=filename_len)  :: filename
14    integer                      :: n, i, j, k
15    integer  :: istart,iend,jstart,jend
16    real     :: rlonlat(4)
18    if (trace_use) call da_trace_entry("da_setup_obs_structures_radar")
20    call init_constants_derived
22    !--------------------------------------------------------------------------
23    ! [1.0] Scan RADAR observation header and get number of obs:
24    !--------------------------------------------------------------------------
25    if (num_fgat_time > 1) then
26       do n=1, num_fgat_time
28          iv%time = n
29          filename = ' '
31          ! scan radar observation file
32          write(filename(1:10), fmt='(a, i2.2, a)') 'ob', n,'.radar'
33          call da_scan_obs_radar(iv, filename, grid)
35          iv%info(radar)%plocal(n) = iv%info(radar)%nlocal
36          iv%info(radar)%ptotal(n) = iv%info(radar)%ntotal
37       end do
38    else
39       iv%time = 1
40       ! scan main body of radar observation file
41       call da_scan_obs_radar(iv, 'ob.radar', grid)
42       iv%info(radar)%plocal(iv%time) = iv%info(radar)%nlocal
43       iv%info(radar)%ptotal(iv%time) = iv%info(radar)%ntotal
44    end if
46    !--------------------------------------------------------------------------
47    ! Allocate based on input number of obs:
48    !--------------------------------------------------------------------------
49    ! This logic was originally found in da_allocate_observations; moved here
50    if (iv%info(radar)%nlocal > 0) allocate(iv%radar (1:iv%info(radar)%nlocal))
51    if (iv%info(radar)%nlocal > 0) then
52       allocate (iv%info(radar)%name(iv%info(radar)%nlocal))
53       allocate (iv%info(radar)%platform(iv%info(radar)%nlocal))
54       allocate (iv%info(radar)%id(iv%info(radar)%nlocal))
55       allocate (iv%info(radar)%date_char(iv%info(radar)%nlocal))
56       allocate (iv%info(radar)%levels(iv%info(radar)%nlocal))
57       allocate (iv%info(radar)%lat(iv%info(radar)%max_lev,iv%info(radar)%nlocal))
58       allocate (iv%info(radar)%lon(iv%info(radar)%max_lev,iv%info(radar)%nlocal))
59       allocate (iv%info(radar)%elv(iv%info(radar)%nlocal))
61       allocate (iv%info(radar)%x  (kms:kme,iv%info(radar)%nlocal))
62       allocate (iv%info(radar)%y  (kms:kme,iv%info(radar)%nlocal))
63       allocate (iv%info(radar)%i  (kms:kme,iv%info(radar)%nlocal))
64       allocate (iv%info(radar)%j  (kms:kme,iv%info(radar)%nlocal))
65       allocate (iv%info(radar)%dx (kms:kme,iv%info(radar)%nlocal))
66       allocate (iv%info(radar)%dxm(kms:kme,iv%info(radar)%nlocal))
67       allocate (iv%info(radar)%dy (kms:kme,iv%info(radar)%nlocal))
68       allocate (iv%info(radar)%dym(kms:kme,iv%info(radar)%nlocal))
69       allocate (iv%info(radar)%k  (iv%info(radar)%max_lev,iv%info(radar)%nlocal))
70       allocate (iv%info(radar)%dz (iv%info(radar)%max_lev,iv%info(radar)%nlocal))
71       allocate (iv%info(radar)%dzm(iv%info(radar)%max_lev,iv%info(radar)%nlocal))
72       allocate (iv%info(radar)%zk (iv%info(radar)%max_lev,iv%info(radar)%nlocal))
73       allocate (iv%info(radar)%proc_domain(iv%info(radar)%max_lev,iv%info(radar)%nlocal))
74       allocate (iv%info(radar)%obs_global_index(iv%info(radar)%nlocal))
75       allocate (iv%info(radar)%thinned(iv%info(radar)%max_lev,iv%info(radar)%nlocal))
77       iv%info(radar)%proc_domain(:,:)  = .false.
78       iv%info(radar)%thinned(:,:)      = .false.
79       iv%info(radar)%zk(:,:)           = missing_r
80    end if
82    if (num_fgat_time > 1) then
84       do n=1, num_fgat_time
85          iv%time = n
86          filename = ' '  
88          ! read radar observation file
89          write(filename(1:10), fmt='(a, i2.2, a)') 'ob', n,'.radar'
90          call da_read_obs_radar(iv, filename, grid)
92       end do
93    else
94       iv%time = 1
96       ! read radar observation file
97       call da_read_obs_radar(iv, 'ob.radar', grid)
98    end if
101    ! Calculate DT for RF DA
103    if (use_radar_rf .and. radar_rf_opt==1) then
104       if (.not. DT_cloud_model) then
105          do j = jts,jte
106             do i = its, ite
107                do k = kts, kte
108                    grid%xb%delt(i,j,k) = 0.0
109                end do
110             end do
111          end do
113          do n = 1, iv%info(radar)%nlocal
114             do i=int(iv%info(radar)%i(1,n)), int(iv%info(radar)%i(1,n))+1
115                do j=int(iv%info(radar)%j(1,n)), int(iv%info(radar)%j(1,n))+1
116                   do k=kts, kte
117                      grid%xb%delt(i,j,k) = 1800.0
118                      grid%xb%qrn(i,j,k) = amax1(5.0E-8, grid%xb%qrn(i,j,k))
119                      grid%xb%qcw(i,j,k) = amax1(5.0E-12, grid%xb%qcw(i,j,k))
120                   end do
121                end do
122             end do
123          end do
124       end if
125    end if
127   
128    !--------------------------------------------------------------------------
129    ! [3.0] Calculate innovation vector (O-B) and create (smaller) ob structure:
130    !--------------------------------------------------------------------------
132    call da_fill_obs_structures_radar(iv, ob)
134    iv%time = 1
136    if (trace_use) call da_trace_exit("da_setup_obs_structures_radar")
137 end subroutine da_setup_obs_structures_radar