1 subroutine da_sfc_hori_interp_weights(n, info, sfc_ob, xb, ob_land_type)
5 integer , intent(in) :: n
6 type(infa_type), intent(inout) :: info
7 type(synop_type), intent(inout) :: sfc_ob
8 type(xb_type), intent(in) :: xb
9 integer , intent(in) :: ob_land_type !1:land, 0:water
11 integer :: i, j, iloc, ii, jj
12 integer :: iloc_min_hdiff
13 integer :: landmask(4)
14 real :: dx, dxm, dy, dym
15 real :: hh(4), w(4), hdiff(4)
21 !------------------------------------------------------
23 ! -----------------(i+1,j+1)
33 !--------------------------------------------------------
36 ii = nint(info%x(1,n))
37 jj = nint(info%y(1,n))
46 w(1) = dym*dxm ! weight for point (i, j)
47 w(2) = dym*dx ! weight for point (i+1,j)
48 w(3) = dy *dxm ! weight for point (i, j+1)
49 w(4) = dy *dx ! weight for point (i+1,j+1)
51 ! lowest half model level height
52 hh(1) = xb%h(i, j, kts)
53 hh(2) = xb%h(i+1, j, kts)
54 hh(3) = xb%h(i, j+1, kts)
55 hh(4) = xb%h(i+1, j+1, kts)
57 ! landmask: 1-land, 0-water
58 landmask(1) = int(xb%landmask(i, j))
59 landmask(2) = int(xb%landmask(i+1, j))
60 landmask(3) = int(xb%landmask(i, j+1))
61 landmask(4) = int(xb%landmask(i+1, j+1))
64 hdiff(iloc) = abs(hh(iloc) - sfc_ob%h)
65 if ( landmask(iloc) /= ob_land_type ) then
66 hdiff(iloc) = 8888.0 !set a large value to not use it
69 if ( sum(hdiff)/4.0 == 8888.0 ) then
70 ! do not use the ob, because the model land type is not
71 ! consistent with the ob land type
72 !print*, 'Rejecting ', trim(info%id(n)), ' due to land type mismatch'
73 sfc_ob%p%qc = missing_data
74 sfc_ob%t%qc = missing_data
75 sfc_ob%q%qc = missing_data
76 sfc_ob%u%qc = missing_data
77 sfc_ob%v%qc = missing_data
80 iloc_min_hdiff = 1 !initialize
82 if ( hdiff(iloc) > hdiff(iloc_min_hdiff) ) then
85 if ( hdiff(iloc) < hdiff(iloc_min_hdiff) ) then
88 if ( w(4-iloc+1) < w(4-iloc_min_hdiff+1) ) then
94 select case ( iloc_min_hdiff )
110 if ( ii == i .and. jj == j ) then
115 else if ( ii == i+1 .and. jj == j ) then
120 else if ( ii == i .and. jj == j+1 ) then
125 else if ( ii == i+1 .and. jj == j+1 ) then
132 !print*, 'Resetting i, j for : ', trim(info%id(n)), ii, jj
133 ! re-assign the weights, lowest level only
139 ! call da_detsurtyp ( grid%xb%snow, grid%xb%xice, grid%xb%landmask, &
140 ! grid%xb%ivgtyp, grid%xb%isltyp, &
141 ! ims, ime, jms, jme, &
142 ! i, j, dx, dy, dxm, dym, &
143 ! model_isflg,model_ivgtyp, model_isltyp, &
144 ! Surface(1)%Water_Coverage, Surface(1)%Ice_Coverage, &
145 ! Surface(1)%Land_Coverage, Surface(1)%Snow_Coverage )
147 end subroutine da_sfc_hori_interp_weights