SUBROUTINE GERSTA_V(POBHDR,KCOUNT,KRSTA)

!**** SUBROUTINE GERSTA - GET REPORT STATUS

!          HEIKKI JARVINEN   ECMWF          15/MAR/1995

!*    PURPOSE
!     -------

!        GET REPORT STATUS: ACTIVE/PASSIVE/REJECTED/BLACKLISTED

!**   INTERFACE
!     ---------

!     ***CALL GERSTA(POBHDR,KCOUNT,KRSTA)
!     WHERE POBHDR  = OBS HEADER REP. STATUS WORD-VECTOR
!           KCOUNT  = NUMBER OF DIFFERENT STATUSES
!           KRSTA   = REPORT STATUS ARRAY

!        NGERSTA IS CALLED BY VARIOUS SUBROUTINES

!*    METHOD
!     ------

!        CRACK THE PACKED REPORT STATUS WORD

!*    EXTERNALS
!     ---------

!**   MODIFICATIONS
!     -------------
!        H. Jarvinen 12 Dec 1996 : A modified subroutine call
!        S. Saarinen 25 Feb 2005 : Modified the subr. args
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMCMHDR , ONLY : NCMRACBP ,NCMRACOC ,NCMRPABP ,NCMRPAOC ,&
 & NCMRREBP ,NCMRREOC ,NCMRBLBP ,NCMRBLOC  

IMPLICIT NONE

REAL(KIND=JPRB),INTENT(IN)       :: POBHDR(:) 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KCOUNT(:) 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KRSTA(:,:) 
INTEGER(KIND=JPIM) :: IACT, IBLA, ICMRST, IPAS, IREJ, JOBS, IOBS
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "fcobs.h"
!*
!     ------------------------------------------------------------------

!        2.       GET REPORT STATUS
!                 -----------------

IF (LHOOK) CALL DR_HOOK('GERSTA_V',0,ZHOOK_HANDLE)
IOBS = SIZE(POBHDR)
DO JOBS=1,IOBS
  KCOUNT(JOBS) = 0
  KRSTA (JOBS,1) = 0
  KRSTA (JOBS,2) = 0
  KRSTA (JOBS,3) = 0
  KRSTA (JOBS,4) = 0

  ICMRST = POBHDR(JOBS)
  IF(ICMRST == 0) CYCLE

  IACT = IBITS(ICMRST, NCMRACBP, NCMRACOC)
  IPAS = IBITS(ICMRST, NCMRPABP, NCMRPAOC)
  IREJ = IBITS(ICMRST, NCMRREBP, NCMRREOC)
  IBLA = IBITS(ICMRST, NCMRBLBP, NCMRBLOC)

!           2.1   ACTIVE

  IF(IACT == 1) KRSTA(JOBS,1) = 1

!           2.2   PASSIVE

  IF(IPAS == 1) KRSTA(JOBS,2) = 1

!           2.3   REJECTED

  IF(IREJ == 1) KRSTA(JOBS,3) = 1

!           2.4   BLACKLISTED

  IF(IBLA == 1) KRSTA(JOBS,4) = 1

!           2.5   NUMBER OF STATUSES

  KCOUNT(JOBS) = IACT + IPAS + IREJ + IBLA
ENDDO
IF (LHOOK) CALL DR_HOOK('GERSTA_V',1,ZHOOK_HANDLE)
!*
!     ------------------------------------------------------------------

END SUBROUTINE GERSTA_V

