Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / da / da_geoamv / da_check_max_iv_geoamv.inc
blob53b9579c8df64de79ef8c9c18be6a414ecdaaa43
1 subroutine da_check_max_iv_geoamv(iv, it, num_qcstat_conv)    
3    !-------------------------------------------------------------------------
4    ! Purpose: Innovation vector check for Geo. AMVs               
5    ! Update:
6    !    Removed Outerloop check as it is done in da_get_innov
7    !    Author: Syed RH Rizvi,  MMM/NESL/NCAR,  Date: 07/12/2009
8    !-------------------------------------------------------------------------
10    implicit none
12    type(iv_type), intent(inout) :: iv
13    integer,       intent(in)    :: it      ! Outer iteration
14    integer,       intent(inout) :: num_qcstat_conv(:,:,:,:)
16    integer :: k,n,ipr
17    logical :: failed,failed1,failed2
19    if (trace_use_dull) call da_trace_entry("da_check_max_iv_geoamv")
21    !---------------------------------------------------------------------------
22    ! [1.0] Perform maximum innovation vector check:
23    !---------------------------------------------------------------------------
25    do n=iv%info(geoamv)%n1,iv%info(geoamv)%n2
26       do k = 1, iv%info(geoamv)%levels(n)
27          call da_get_print_lvl(iv%geoamv(n)%p(k),ipr)
29          if(.not. qc_rej_both)then
30             if(wind_sd_geoamv)then
31                failed=.false.
32                if( iv%geoamv(n)%u(k)%qc >= obs_qc_pointer ) then
33                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%u(k), max_error_spd,failed)
34                    if( iv%info(geoamv)%proc_domain(k,n) ) then
35                        num_qcstat_conv(1,geoamv,1,ipr) = num_qcstat_conv(1,geoamv,1,ipr) + 1
36                        if(failed) then
37                           num_qcstat_conv(2,geoamv,1,ipr) = num_qcstat_conv(2,geoamv,1,ipr) + 1
38                           if ( write_rej_obs_conv ) then
39                           write(qcstat_conv_unit,'(2x,a10,2x,a4,3f12.2)')&
40                           'geoamv',ob_vars(1),iv%info(geoamv)%lat(k,n),iv%info(geoamv)%lon(k,n),0.01*iv%geoamv(n)%p(k)
41                           end if
42                        end if
43                    end if
44                 end if
46                 failed=.false.
47                 if( iv%geoamv(n)%v(k)%qc >= obs_qc_pointer ) then
48                     call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%v(k), max_error_dir,failed)
49                     if( iv%info(geoamv)%proc_domain(k,n) ) then
50                         num_qcstat_conv(1,geoamv,2,ipr) = num_qcstat_conv(1,geoamv,2,ipr) + 1
51                         if(failed)then
52                            num_qcstat_conv(2,geoamv,2,ipr) = num_qcstat_conv(2,geoamv,2,ipr) + 1
53                            if ( write_rej_obs_conv ) then
54                            write(qcstat_conv_unit,'(2x,a10,2x,a4,3f12.2)')&
55                            'geoamv',ob_vars(2),iv%info(geoamv)%lat(k,n),iv%info(geoamv)%lon(k,n),0.01*iv%geoamv(n)%p(k)
56                            end if
57                         end if
58                     end if
59                 end if
61             else
63                failed=.false.
64                if( iv%geoamv(n)%u(k)%qc >= obs_qc_pointer ) then
65                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%u(k), max_error_uv,failed)
66                    if( iv%info(geoamv)%proc_domain(k,n) ) then
67                        num_qcstat_conv(1,geoamv,1,ipr) = num_qcstat_conv(1,geoamv,1,ipr) + 1
68                        if(failed) then
69                           num_qcstat_conv(2,geoamv,1,ipr) = num_qcstat_conv(2,geoamv,1,ipr) + 1
70                           if ( write_rej_obs_conv ) then
71                           write(qcstat_conv_unit,'(2x,a10,2x,a4,3f12.2)')&
72                           'geoamv',ob_vars(1),iv%info(geoamv)%lat(k,n),iv%info(geoamv)%lon(k,n),0.01*iv%geoamv(n)%p(k)
73                           end if
74                        end if
75                    end if
76                end if
78                failed=.false.
79                if( iv%geoamv(n)%v(k)%qc >= obs_qc_pointer ) then
80                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%v(k), max_error_uv,failed)
81                    if( iv%info(geoamv)%proc_domain(k,n) ) then
82                        num_qcstat_conv(1,geoamv,2,ipr) = num_qcstat_conv(1,geoamv,2,ipr) + 1
83                        if(failed)then
84                           num_qcstat_conv(2,geoamv,2,ipr) = num_qcstat_conv(2,geoamv,2,ipr) + 1
85                           if ( write_rej_obs_conv ) then
86                           write(qcstat_conv_unit,'(2x,a10,2x,a4,3f12.2)')&
87                           'geoamv',ob_vars(2),iv%info(geoamv)%lat(k,n),iv%info(geoamv)%lon(k,n),0.01*iv%geoamv(n)%p(k)
88                           end if
89                        end if
90                    end if
91                end if
93                if(wind_sd_geoamv)then
94                   if(iv%geoamv(n)%u(k)%qc == fails_error_max .or.  abs(iv%geoamv(n)%u(k)%inv) >= max_omb_spd) then
95                      iv%geoamv(n)%u(k)%qc = fails_error_max
96                      iv%geoamv(n)%u(k)%inv = 0.0
97                   endif
98                   if(iv%geoamv(n)%v(k)%qc == fails_error_max .or.  abs(iv%geoamv(n)%v(k)%inv) >= max_omb_dir) then
99                      iv%geoamv(n)%v(k)%qc = fails_error_max
100                      iv%geoamv(n)%v(k)%inv = 0.0
101                   endif
102                endif
103             endif
104          else
105             failed1=.false.
106             failed2=.false.
108             if( iv%geoamv(n)%v(k)%qc >= obs_qc_pointer .or. iv%geoamv(n)%u(k)%qc >= obs_qc_pointer )  then
109                 if(wind_sd_geoamv)then
110                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%u(k), max_error_spd,failed1)
111                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%v(k), max_error_dir,failed2)
112                 else
113                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%u(k), max_error_uv,failed1)
114                    call da_max_error_qc (it,iv%info(geoamv), n, iv%geoamv(n)%v(k), max_error_uv,failed2)
115                 endif
116             endif
118             if( iv%info(geoamv)%proc_domain(k,n) ) then
119                 num_qcstat_conv(1,geoamv,1,ipr) = num_qcstat_conv(1,geoamv,1,ipr) + 1
120                 num_qcstat_conv(1,geoamv,2,ipr) = num_qcstat_conv(1,geoamv,2,ipr) + 1
122                 if(failed1 .or. failed2) then
123                    num_qcstat_conv(2,geoamv,1,ipr) = num_qcstat_conv(2,geoamv,1,ipr) + 1
124                    if ( write_rej_obs_conv ) then
125                    write(qcstat_conv_unit,'(2x,a10,2x,a4,3f12.2)')&
126                          'geoamv',ob_vars(1),iv%info(geoamv)%lat(k,n),iv%info(geoamv)%lon(k,n),0.01*iv%geoamv(n)%p(k)
127                    end if
128                    num_qcstat_conv(2,geoamv,2,ipr) = num_qcstat_conv(2,geoamv,2,ipr) + 1
129                    if ( write_rej_obs_conv ) then
130                    write(qcstat_conv_unit,'(2x,a10,2x,a4,3f12.2)')&
131                          'geoamv',ob_vars(2),iv%info(geoamv)%lat(k,n),iv%info(geoamv)%lon(k,n),0.01*iv%geoamv(n)%p(k)
132                    end if
133                 endif
134             endif
136             if(wind_sd_geoamv)then
137                if(iv%geoamv(n)%u(k)%qc == fails_error_max .or. iv%geoamv(n)%v(k)%qc == fails_error_max .or. &
138                   abs(iv%geoamv(n)%v(k)%inv) >= max_omb_dir .or. abs(iv%geoamv(n)%u(k)%inv) >= max_omb_spd )then
139                   iv%geoamv(n)%u(k)%qc = fails_error_max
140                   iv%geoamv(n)%v(k)%qc = fails_error_max
141                   iv%geoamv(n)%u(k)%inv = 0.0
142                   iv%geoamv(n)%v(k)%inv = 0.0
143                endif
144             else
145                if(iv%geoamv(n)%u(k)%qc == fails_error_max .or. iv%geoamv(n)%v(k)%qc == fails_error_max ) then
146                   iv%geoamv(n)%u(k)%qc = fails_error_max
147                   iv%geoamv(n)%v(k)%qc = fails_error_max
148                   iv%geoamv(n)%u(k)%inv = 0.0
149                   iv%geoamv(n)%v(k)%inv = 0.0
150                endif
151             endif
152          endif
154       end do
155    end do
157    if (trace_use_dull) call da_trace_exit("da_check_max_iv_geoamv")
159 end subroutine da_check_max_iv_geoamv