SUBROUTINE REDMO(KLEN)

!**** SUBROUTINE REDMO - REDUNDANT MASS OBSERVATION

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

!*    PURPOSE
!     -------

!        IN SYNOP AND PAOB OBSERVATIONS, THERE MAY BE BOTH THE SURFACE
!     PRESSURE AND GEOPOTENTIAL.  ONE OF THESE IS MADE REDUNDANT. (IN THE
!     IFS THE PREFERENCE IS ON SURFACE PRESSURE.)

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

!        CALL REDMO(KLEN)
!     WHERE KLEN    = DB LEN

!        REDMO IS CALLED BY SUBROUTINE REDUN

!*    METHOD
!     ------

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

!        NGEDSTA - GET DATUM STATUS

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

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

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

USE YOMVNMB  , ONLY : NVNUMB
USE YOMNMEV  , ONLY : ND1EVENT
USE YOMDB
USE YOMLUN   , ONLY : NULOUT   
USE YOMSCC   , ONLY : LSCDPR

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLEN 
INTEGER(KIND=JPIM) :: ICOUNT, IIPS,&
 & IIZ, ILEV, JNLV, ILEN, JOBS  
INTEGER(KIND=JPIM) :: IDSTA(4)

LOGICAL :: LLPS, LLZ
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "ngedsta.intfb.h"

#include "fcobs.h"

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

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

IF (LHOOK) CALL DR_HOOK('REDMO',0,ZHOOK_HANDLE)
IF(LSCDPR) WRITE(NULOUT,'(''     REDUNDANT MASS OBS'')')

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

!        2.       USE ONLY ONE MASS OBSERVATION
!                 -----------------------------
!*
!           2.1   LOOP OVER ALL REPORTS

ILEN = KLEN
ALLREP_LOOP: DO JOBS = 1 , ILEN
  LLPS = .FALSE.
  LLZ  = .FALSE.
!*
!           2.1   LOOP OVER THE REPORT

  ONE_REP_LOOP: DO JNLV = MLNKH2B(JOBS),MLNKH2B(JOBS+1)-1
    ILEV = JNLV
!*
!           2.2   ACTIVE GEOPOTENTIAL OBSERVATION

    IF((ROBODY(ILEV,MDBVNM)) == NVNUMB( 3)) THEN
      CALL NGEDSTA(INT(ROBODY(ILEV,MDBDSTA)),ICOUNT,IDSTA)
      IF(IDSTA(2) == 1.OR. IDSTA(3) == 1.OR.&
       & IDSTA(4) == 1                       ) CYCLE ALLREP_LOOP  
      LLZ = .TRUE.
      IIZ = JNLV
!*
!           2.3   ACTIVE SURFACE PRESSURE OBSERVATION

    ELSEIF((ROBODY(ILEV,MDBVNM)) == NVNUMB(47)) THEN
      CALL NGEDSTA(INT(ROBODY(ILEV,MDBDSTA)),ICOUNT,IDSTA)
      IF(IDSTA(2) == 1.OR. IDSTA(3) == 1.OR.&
         & IDSTA(4) == 1                       ) THEN  
        IF(LLPS)  CYCLE ONE_REP_LOOP
      ELSE
        LLPS = .TRUE.
        IIPS = JNLV
      ENDIF
    ENDIF
  ENDDO ONE_REP_LOOP
!*
!           2.4   REJECT ONE MASS OBSERVATION (Z)
  240 CONTINUE
  IF(LLZ) THEN
    IF(LLPS) THEN
      ROBODY(IIZ ,MDBDSTA) = ZCHSTAT_REJECT( ROBODY(IIZ ,MDBDSTA))
      ROBODY(IIZ ,MDBDEV1) = ZCHEV1( ROBODY(IIZ ,MDBDEV1),ND1EVENT(13))
    ENDIF
  ENDIF
ENDDO ALLREP_LOOP
!*
!     ------------------------------------------------------------------

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