<HTML> <BODY BGCOLOR=#ccccdd LINK=#0000aa VLINK=#0000ff ALINK=#ff0000 ><BASE TARGET="bottom_target"><PRE>
<A NAME='DA_OI_STATS_PROFILER'><A href='../../html_code/profiler/da_oi_stats_profiler.inc.html#DA_OI_STATS_PROFILER' TARGET='top_target'><IMG SRC="../../gif/bar_red.gif" border=0></A>

subroutine da_oi_stats_profiler (stats_unit, iv, ob) 1,11

   !-----------------------------------------------------------------------
   ! Purpose: TBD
   !-----------------------------------------------------------------------

   implicit none

   integer,        intent (in) :: stats_unit    ! Output unit for stats.
   type (iv_type), intent (in) :: iv            ! OI
   type(y_type),   intent (in) :: ob            ! Observation structure.

   type (stats_profiler_type)  :: stats
   integer                     :: nu, nv
   integer                     :: n, k
   real                        :: u_inv, v_inv, u_obs, v_obs

   if (trace_use_dull) call da_trace_entry("da_oi_stats_profiler")

   nu = 0
   nv = 0
   
   stats%maximum%u = maxmin_type(missing_r, 0, 0)
   stats%maximum%v = maxmin_type(missing_r, 0, 0)
   stats%minimum%u = maxmin_type(-missing_r, 0, 0)
   stats%minimum%v = maxmin_type(-missing_r, 0, 0)

   stats%average = residual_profiler1_type(0.0, 0.0)
   stats%rms_err = stats%average

   do n=1, iv%info(profiler)%nlocal
      if (iv%info(profiler)%proc_domain(1,n)) then
         do k=1, iv%info(profiler)%levels(n)

            u_inv = iv%profiler(n)%u(k)%inv
            v_inv = iv%profiler(n)%v(k)%inv
            u_obs = ob%profiler(n)%u(k)
            v_obs = ob%profiler(n)%v(k)

            if (.not. wind_sd_profiler .and. wind_stats_sd) &amp;
               call da_ffdduv_diagnose(u_obs, u_inv, u_obs, v_obs, v_inv, v_obs, &amp;
                                       iv%profiler(n)%u(k)%qc, iv%profiler(n)%v(k)%qc, convert_uv2fd)
            if (wind_sd_profiler .and. .not. wind_stats_sd) &amp;
               call da_ffdduv_diagnose(u_obs, u_inv, u_obs, v_obs, v_inv, v_obs, &amp;
                                       iv%profiler(n)%u(k)%qc, iv%profiler(n)%v(k)%qc, convert_fd2uv)

            call da_stats_calculate(iv%info(profiler)%obs_global_index(n), &amp;
               k, iv%profiler(n)%u(k)%qc,  &amp;
               u_inv, nu, &amp;
               stats%minimum%u, stats%maximum%u, &amp;
               stats%average%u, stats%rms_err%u)
            call da_stats_calculate(iv%info(profiler)%obs_global_index(n), &amp;
               k, iv%profiler(n)%v(k)%qc, &amp;
               v_inv, nv, &amp;
               stats%minimum%v, stats%maximum%v, &amp;
               stats%average%v, stats%rms_err%v)
         end do
      end if
   end do

   ! Do inter-processor communication to gather statistics.
   call da_proc_sum_int(nu)
   call da_proc_sum_int(nv)
   
   call da_proc_stats_combine(stats%average%u, stats%rms_err%u, &amp;
      stats%minimum%u%value, stats%maximum%u%value, &amp;
      stats%minimum%u%n, stats%maximum%u%n, &amp;
      stats%minimum%u%l, stats%maximum%u%l)
   call da_proc_stats_combine(stats%average%v, stats%rms_err%v, &amp;
      stats%minimum%v%value, stats%maximum%v%value, &amp;
      stats%minimum%v%n, stats%maximum%v%n, &amp;
      stats%minimum%v%l, stats%maximum%v%l)
   
   if (rootproc) then
      if (nu /= 0 .or. nv /= 0) then
         write(unit=stats_unit, fmt='(/a/)') ' Diagnostics of OI for profiler'
         call da_print_stats_profiler(stats_unit, nu, nv, stats)
      end if
   end if

   if (trace_use_dull) call da_trace_exit("da_oi_stats_profiler")

end subroutine da_oi_stats_profiler