SUBROUTINE RDBFLD(KPOS,KRDBMX,KFDPRE,KFDVAR)

!**** SUBROUTINE RDBFLD - GET THE (MAXIMUM) RDB-FLAG FOR DATUM

!          HEIKKI JARVINEN   ECMWF          15/MAR/1995
!          DRASKO VASILJEVIC ECMWF          21/10/1999

!*    PURPOSE
!     -------

!        GET THE (MAXIMUM) RDB-FLAG FOR DATUM

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

!     ***CALL*RDBFLD(KPOS,KRDBMX,KFDPRE,KFDVAR)
!     WHERE KPOS   = POINTER TO THE DATUM IN CMA
!           KRDBMX = MAXIMUM RDB-FLAG FOR DATUM
!           KFDPRE = PRESSURE RDB-FLAG
!           KFDVAR = VARIABLE RDB-FLAG

!        RDBFLD IS CALLED BY SUBROUTINES FLGTST, VERCO

!*    METHOD
!     ------

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

!**   MODIFICATIONS
!     -------------

!     ------------------------------------------------------------------

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

USE YOMCMBDY , ONLY : NCMBPFBP ,NCMBVFBP ,NCMBFLBP ,NCMBFLOC
USE YOMDB

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPOS 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KRDBMX 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KFDPRE 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KFDVAR 
INTEGER(KIND=JPIM) :: ICMRDFL
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "fcobs.h"

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

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

IF (LHOOK) CALL DR_HOOK('RDBFLD',0,ZHOOK_HANDLE)
KRDBMX = 0
!*
!     ------------------------------------------------------------------

!        2.       GET THE (MAXIMUM) RDB-FLAG FOR DATUM
!                 ------------------------------------

!*          2.1   GET THE RDB-FLAG WORD

ICMRDFL = ROBODY(KPOS,MDBRDFL)

!*          2.2   PRESSURE RDB-FLAG

KFDPRE = IBITS(ICMRDFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)
IF(KFDPRE > KRDBMX) KRDBMX = KFDPRE

!*          2.3   VARIABLE RDB-FLAG

KFDVAR = IBITS(ICMRDFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
IF(KFDVAR > KRDBMX) KRDBMX = KFDVAR
!*
!     ------------------------------------------------------------------

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