SUBROUTINE NGERSTA(KOBHDR,KCOUNT,KRSTA)

!**** SUBROUTINE GERSTA - GET REPORT STATUS

!          HEIKKI JARVINEN   ECMWF          15/MAR/1995

!*    PURPOSE
!     -------

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

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

!     ***CALL NGERSTA(KOBHDR,KCOUNT,KRSTA)
!     WHERE KOBHDR  = OBS HEADER REP. STATUS WORD
!           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
!     ------------------------------------------------------------------

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

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KOBHDR 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KCOUNT 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KRSTA(4) 
INTEGER(KIND=JPIM) :: IACT, IBLA, ICMRST, IPAS, IREJ, J
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "fcobs.h"

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

!        1.       INITIALIZE
!                 ----------

IF (LHOOK) CALL DR_HOOK('NGERSTA',0,ZHOOK_HANDLE)
KCOUNT = 0
DO J = 1, 4
  KRSTA(J) = 0
ENDDO
!*
!     ------------------------------------------------------------------

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

ICMRST = KOBHDR
IF(ICMRST == 0) GOTO 3

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(1) = 1

!           2.2   PASSIVE

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

!           2.3   REJECTED

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

!           2.4   BLACKLISTED

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

!           2.5   NUMBER OF STATUSES

KCOUNT = IACT + IPAS + IREJ + IBLA
!*
!     ------------------------------------------------------------------

!        3.       RETURN
!                 ------
3 CONTINUE
IF (LHOOK) CALL DR_HOOK('NGERSTA',1,ZHOOK_HANDLE)
END SUBROUTINE NGERSTA

