SUBROUTINE NGEDSTA(KOBODY,KCOUNT,KDSTA)

!**** SUBROUTINE NGEDSTA - GET DATUM STATUS

!          HEIKKI JARVINEN   ECMWF          15/MAR/1995

!*    PURPOSE
!     -------

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

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

!     ***CALL NGEDSTA(PREPORT,KRLN,KSQN,KCOUNT,KDSTA)
!     WHERE PREPORT = THE WHOLE REPORT IN AN REAL ARRAY
!           KRLN    = THE REPORT LENGTH
!           KSQN    = SEQUENCE NUMBER OF THE DATUM
!           KCOUNT  = NUMBER OF DIFFERENT STATUSES
!           KDSTA   = DATUM STATUS ARRAY

!        GEDSTA IS CALLED BY VARIOUS SUBROUTINES

!*    METHOD
!     ------

!        CRACK THE PACKED DATUM 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 YOMCMBDY , ONLY : NCMDACBP ,NCMDACOC ,NCMDPABP ,NCMDPAOC ,&
 & NCMDREBP ,NCMDREOC ,NCMDBLBP ,NCMDBLOC  

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KOBODY 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KCOUNT 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KDSTA(4) 
INTEGER(KIND=JPIM) ::  ICMDSTA
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

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

!*          1.1   VALUES

IF (LHOOK) CALL DR_HOOK('NGEDSTA',0,ZHOOK_HANDLE)

!*
!     ------------------------------------------------------------------

!*       2.       GET DATUM STATUS
!                 ----------------

!*          2.0   INTIALIZE

2 CONTINUE
ICMDSTA = KOBODY
IF (ICMDSTA /= 0) THEN

!*          2.1   ACTIVE

  KDSTA(1) = IBITS(ICMDSTA, NCMDACBP, NCMDACOC)

!*          2.2   PASSIVE

  KDSTA(2) = IBITS(ICMDSTA, NCMDPABP, NCMDPAOC)

!*          2.3   REJECTED

  KDSTA(3) = IBITS(ICMDSTA, NCMDREBP, NCMDREOC)

!*          2.4   BLACKLISTED

  KDSTA(4) = IBITS(ICMDSTA, NCMDBLBP, NCMDBLOC)

!*          2.5   NUMBER OF STATUSES

  KCOUNT = KDSTA(1) + KDSTA(2) + KDSTA(3) + KDSTA(4)

ELSE

  KDSTA(1) = 0
  KDSTA(2) = 0
  KDSTA(3) = 0
  KDSTA(4) = 0
  KCOUNT = 0

ENDIF

!*
!     ------------------------------------------------------------------

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

