subroutine onedvar_find_satsens( kbufr_id, ksatsens_id, kstream1d)

!**** 1D-Var in clouds/precipitation for SSM/I radiances

! Given a satellite BUFR ID, retrieve information from the onedvar
! satellite lookup table. 

!   KSATSENSID  - The index of this satellite in the table (0 = not found)
!   KSTREAM1D   - The 1DVar stream assigned to this satellite

! 01-Mar-2007  A.Geer      : First implementation
! 06-Nov-2007  S.Saarinen  : Exit search loop when the 1st occurence found

use parkind1, only: jpim, jprb
use yomhook, only: lhook, dr_hook
use yomonedvar, only: onedvar_id, n_satsens

implicit none                         

integer (kind=jpim), intent (in) :: kbufr_id     ! BUFR ID
integer (kind=jpim), intent (out) :: ksatsens_id ! Index to onedvar table
integer (kind=jpim), intent (out), optional :: kstream1d ! 1DVar Stream

integer (kind=jpim) :: jsat
real (kind=jprb) :: zhook_handle

if (lhook) call dr_hook ('ONEDVAR_FIND_SATSENS',0,zhook_handle)
      
ksatsens_id=0
LOOP: do jsat= 1, n_satsens
  if (onedvar_id(jsat)%bufr_id == kbufr_id) then
    ksatsens_id=jsat
    if (present(kstream1d)) then 
      kstream1d = onedvar_id(ksatsens_id)%stream1d
    endif
    exit LOOP
  endif
enddo LOOP

if (lhook) call dr_hook('ONEDVAR_FIND_SATSENS',1,zhook_handle)

end subroutine onedvar_find_satsens
