SUBROUTINE METARIN(KSYNP,&
 & KOBTYP,KCDTYP,KOBSQNO,KCDSQNO,&
 & LDMESAGE,LDTAKEN)  

!**** SUBROUTINE METARIN - PROCESS INPUT METAR SYNOP

!        D. VASILJEVIC     ECMWF     13/12/00 (original 07/01/04)

!     PURPOSE
!     -------

!        PROCESS INPUT METAR SYNOP

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

!        CALL METARIN(KSYNP,
!                     KOBTYP,KCDTYP,KOBSQNO,KCDSQNO,
!                     LDMESAGE,LDTAKEN)
!     WHERE:
!            KSYNP   = REPORT POINTER
!            KOBTYP  = OBS. TYPE
!            KCDTYP  = CODE TYPE
!            KOBSQNO = OBS. TYPE SQ. NO.
!            KCDSQNO = CODE TYPE SQ. NO.
!            LDMESAGE= OUTPUT MESSAGE SWITCH  
!            LDTAKEN = REPORT TAKEN ("ODB" REPORT UPDATED) SWITCH  

!        METARIN IS CALLED BY SUBROUTINE ????????

!     METHOD
!     ------

!     EXTERNALS
!     ---------

!        PRLMCHK  - PRELIMINARY CHECKS
!        GETSETE  - GET/SET BODY ENTRY
!        ERRSTAT  - OBS. ERROR
!        SYNOPBE  - UPDATE SYNOP BODY ENTRY
!        PPVAFL   - PRESSURE/VARIABLE FLAG RESET
!        OBINSTP  - INTSTRUMENT TYPE

!     MODIFICATIONS
!     -------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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

USE YOMDB
USE YOMCMHDR , ONLY : NALFLBP  ,NFLGBP   ,NFLGOC
USE YOMCMBDY , ONLY :  NCMBVFBP ,NCMBFLBP ,NCMBFLOC
USE YOMANCS  , ONLY : NMDI     ,RMDI     ,RDEGREES ,RADIANS  ,EPSMAC  ,&
 & RTICE    ,RTWAT    ,R2ES     ,R3IES    ,&
 & R3LES    ,R4IES    ,R4LES    ,RTT      ,RUPMLIM  ,RDWMLIM ,RPAPM   
USE YOMVNMB  , ONLY : NVNUMB
USE YOMNMEV  , ONLY : ND2EVENT
USE YOMNMCOD , ONLY : NPRESVC  ,NHEIGVC  ,NPRESCD
USE YOMMKODB , ONLY : LERRPERS ,NMKCMVSE ,&
 & LTOTREM ,&
 & L_METAR_PS_BIAS   
USE YOMCOSJO , ONLY : LHUBERBGQCG
USE YOMLIM   , ONLY :       NFLLIMOP  ,&
 & RRHLIM   ,RRHTLIM  
USE YOMOERR  , ONLY : RHERR1   ,RHERR2   ,RHERR3
USE YOMERR   , ONLY : LRHERRMO
USE YOMCST   , ONLY : RG
USE YOMLUN   , ONLY : NULOUT   
USE LOCAL_TRAFOS

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KSYNP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KOBTYP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KCDTYP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KOBSQNO 
INTEGER(KIND=JPIM),INTENT(IN)    :: KCDSQNO 
LOGICAL           ,INTENT(INOUT) :: LDMESAGE 
LOGICAL           ,INTENT(OUT)   :: LDTAKEN 
!-----------------------------------------------------------------------

INTEGER(KIND=JPIM) :: IOBDATE,&
 & IOBTIME, IPFLG,&
 & IVNM, IVNMZ, IPCODE, &
 & JDDFF, JPs, IPs, IVECFL, IVERCO,&
 & IGFLG, IALFLG, &
 & IGSTLFLG, &
 & IPRESCD, &
 & JDD, JFF, &
 & ISTID, INSTYP, IREPST  
INTEGER(KIND=JPIM) :: IPSTAFLG

INTEGER(KIND=JPIM) :: IDD, &
 & IDDSTAT, IDDEVEN1, IDDEVEN2, IDDRDBFL, IDDANFLG, &
 & IDDPFLG, IDDFLG  
INTEGER(KIND=JPIM) :: IFF, &
 & IFFSTAT, IFFEVEN1, IFFEVEN2, IFFRDBFL, IFFANFLG, &
 & IFFPFLG, IFFFLG  
INTEGER(KIND=JPIM) :: IU10M, JU10M, &
 & IUUSTAT, IUUEVEN1, IUUEVEN2, IUURDBFL, IUUANFLG, &
 & IUUPFLG, IUUFLG  
INTEGER(KIND=JPIM) :: IV10M, JV10M, &
 & IVVSTAT, IVVEVEN1, IVVEVEN2, IVVRDBFL, IVVANFLG, &
 & IVVPFLG, IVVFLG  
INTEGER(KIND=JPIM) :: JT2M, IT2M, &
 & ITTSTAT, ITTEVEN1, ITTEVEN2, ITTRDBFL, ITTANFLG, &
 & ITTPFLG, ITTFLG  
INTEGER(KIND=JPIM) :: IZZSTAT
INTEGER(KIND=JPIM) :: IPSSTAT, IPSEVEN1, IPSEVEN2, IPSRDBFL, IPSANFLG, &
 & IPSPFLG, IPSFLG  
INTEGER(KIND=JPIM) :: JRH2M, IRH2M, &
 & IRHSTAT, IRHEVEN1, IRHEVEN2, IRHRDBFL, IRHANFLG, &
 & IRHPFLG, IRHFLG  
INTEGER(KIND=JPIM) :: JTD2M, ITD2M, &
 & ITDSTAT, ITDEVEN1, ITDEVEN2, ITDRDBFL, ITDANFLG, &
 & ITDPFLG, ITDFLG  
INTEGER(KIND=JPIM) :: IAUX, JALL, &
 & IAUSTAT, IAUEVEN1, IAUEVEN2, IAURDBFL, IAUANFLG, &
 & IAUPFLG, IAUFLG  , IAUVERCO  
INTEGER(KIND=JPIM) :: IDBRDFL

LOGICAL :: LLFAIL, LLREMOVE, LLDONEBCH
LOGICAL :: LLPs, LLT2M, LLTd2M, LLDD, LLFF, LLU10m, LLV10m, LLRH2m

CHARACTER (LEN = 8) :: CLSTID

REAL(KIND=JPRB) ::  &
 & ZLAT, ZLON, &
 & ZPRES, ZTIMDIF, &
 & ZWEIGHT, &
 & ZVERCO, ZPRESAU, ZHEAUX, ZGEOP,  ZGEOPSTL, &
 & ZALT
REAL(KIND=JPRB) :: ZPSTA 
REAL(KIND=JPRB) :: ZDIR, ZDDPRES, ZDDPRL, &
 & ZDDPERR, ZDDOERR, ZDDFERR, ZDDRERR, &
 & ZDDFGER, ZDDFGCC1, ZDDFGCC2, &
 & ZDDFGDEP, ZDDANDEP  
REAL(KIND=JPRB) :: ZSPD, ZFFPRES, ZFFPRL, &
 & ZFFPERR, ZFFOERR, ZFFFERR, ZFFRERR, &
 & ZFFFGER, ZFFFGCC1, ZFFFGCC2, &
 & ZFFFGDEP, ZFFANDEP  
REAL(KIND=JPRB) :: ZU, ZUUPRES, ZUUPRL, &
 & ZUUPERR, ZUUOERR, ZUUFERR, ZUURERR, &
 & ZUUFGER, ZUUFGCC1, ZUUFGCC2, &
 & ZUUFGDEP, ZUUANDEP  
REAL(KIND=JPRB) :: ZV, ZVVPRES, ZVVPRL, &
 & ZVVPERR, ZVVOERR, ZVVFERR, ZVVRERR, &
 & ZVVFGER, ZVVFGCC1, ZVVFGCC2, &
 & ZVVFGDEP, ZVVANDEP  
REAL(KIND=JPRB) :: ZT2M, ZTTPRES, ZTTPRL, &
 & ZTTPERR, ZTTOERR, ZTTFERR, ZTTRERR, &
 & ZTTFGER, ZTTFGCC1, ZTTFGCC2, &
 & ZTTFGDEP, ZTTANDEP  
REAL(KIND=JPRB) :: ZTD2M, ZTDPRES, ZTDPRL, &
 & ZTDPERR, ZTDOERR, ZTDFERR, ZTDRERR, &
 & ZTDFGER, ZTDFGCC1, ZTDFGCC2, &
 & ZTDFGDEP, ZTDANDEP  
REAL(KIND=JPRB) :: ZRH2M, ZRHPRES, ZRHPRL, &
 & ZRHPERR, ZRHOERR, ZRHFERR, ZRHRERR, &
 & ZRHFGER, ZRHFGCC1, ZRHFGCC2, &
 & ZRHFGDEP, ZRHANDEP  
REAL(KIND=JPRB) :: ZPS, ZPSPRES, ZPSPRL, &
 & ZPSPERR, ZPSOERR, ZPSFERR, ZPSRERR, &
 & ZPSFGER, ZPSFGCC1, ZPSFGCC2, &
 & ZPSFGDEP, ZPSANDEP, ZPSBIAS
REAL(KIND=JPRB) :: ZAU, ZAUPRES, ZAUPRL, &
 & ZAUPERR, ZAUOERR, ZAUFERR, ZAURERR, &
 & ZAUFGER, ZAUFGCC1, ZAUFGCC2, &
 & ZAUFGDEP, ZAUANDEP  
REAL(KIND=JPRB) :: ZZZPRL, &
 & ZZZPERR, ZZZOERR, ZZZFERR
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"
#include "errstat.intfb.h"
#include "finoerr.intfb.h"
#include "getsete.intfb.h"
#include "obinstp.intfb.h"
#include "ppvafl.intfb.h"
#include "prlmchk.intfb.h"
#include "synopbe.intfb.h"
#include "z2picao.intfb.h"

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

#include "fcobs.h"
#include "stmfun_ifs.h"
#include "openmp_obs.h"
!*

!        1.             PRESET
!                       ------

IF (LHOOK) CALL DR_HOOK('METARIN',0,ZHOOK_HANDLE)
ZLAT     = ROBHDR(KSYNP,MDBLAT) * RDEGREES
ZLON     = ROBHDR(KSYNP,MDBLON) * RDEGREES
ZALT     = ROBHDR(KSYNP,MDBALT)
IALFLG   = IBITS(INT(ROBHDR(KSYNP,MDBRFL)),NALFLBP+NFLGBP,NFLGOC)
IOBDATE  = ROBHDR(KSYNP,MDBDAT)
IOBTIME  = ROBHDR(KSYNP,MDBETM)
CLSTID   = TRANSFER(ROBHDR(KSYNP,MDBSID), CLSTID)
ISTID    = 0
IREPST   = ROBHDR(KSYNP,MDBRST)

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

!        2.             GENERAL OBSERVATION INFO.
!                       -------------------------

!*          2.1         DEFINE INSTRUMENT TYPE

INSTYP  = 0
CALL OBINSTP(ZLAT,ZLON,ISTID,&
 & KOBTYP,KCDTYP,&
 & INSTYP)  

!*          2.2         SET INSTRUMENT TYPE INTO OBSERVATION
!                       CHARACTERISTICS

ROBHDR(KSYNP,MDB_INSTTYPE_AT_HDR) = INSTYP

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

!        3.             PRELIMINARY CHECKS
!                       ------------------

!*          3.1         REPORT PARAMETERS

LLFAIL   = .FALSE.
LLREMOVE = .FALSE.
CALL PRLMCHK(KOBTYP,KCDTYP,ZLAT,ZLON,IOBDATE,IOBTIME,IREPST,ZTIMDIF,&
 & LDMESAGE,LLFAIL,LLREMOVE)  

!*          3.1.0       UPDATE REPORT STATUS

ROBHDR(KSYNP,MDBRST) = IREPST

!*          3.1.1       FAILED REPORT

IF(LLFAIL  ) THEN
  IF(LTOTREM) GO TO 6
ENDIF

!*          3.1.2       REMOVED REPORT

IF(LLREMOVE) THEN
  IF(LTOTREM) GO TO 6
ENDIF

!*          3.2         BODY PARAMETERS

LLPs   = .FALSE.
LLT2M  = .FALSE.
LLTd2M = .FALSE.
LLDD   = .FALSE.
LLFF   = .FALSE.
LLU10m = .FALSE.
LLV10m = .FALSE.
LLRH2m = .FALSE.
ALL_DATA_LOOP: DO JALL = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1

!*          3.2.1       WE ACCEPT: Ps, T2m, Td2m, DD, FF, U10m, V10m,
!                                   and Rh2m

  IF(     ROBODY(JALL  ,MDBVNM) == NVNUMB( 47)) THEN
    LLPs    = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB( 10)) THEN
    LLT2M   = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB( 11)) THEN
    LLTd2M  = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB( 48)) THEN
    LLDD    = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB( 49)) THEN
    LLFF    = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB( 56)) THEN
    LLU10m  = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB( 57)) THEN
    LLV10m  = .TRUE.
    GO TO 322
  ELSEIF(ROBODY(JALL  ,MDBVNM) == NVNUMB(  7)) THEN
    LLRH2m  = .TRUE.
    GO TO 322
  ELSE
    IAUX = JALL
    IVNM = ROBODY(IAUX  ,MDBVNM)
    WRITE(NULOUT,'('' METARIN; UNEXPECTED VARIABLE: '',I10)') IVNM

!*          3.2.1.0     SET/GET

    CALL GETSETE(IAUX ,&
     & ZAUPRES,ZAUPRL,ZAU ,&
     & ZAUFGER,ZAUFGCC1,ZAUFGCC2,&
     & ZAUPERR,ZAUOERR,ZAUFERR,ZAURERR,&
     & ZAUFGDEP,ZAUANDEP,&
     & IAUSTAT,IAUEVEN1,IAUEVEN2,IAURDBFL,IAUANFLG,&
     & IAUFLG,IAUPFLG)  

    ZAUPRES = ROBODY(IAUX,MDBPPP)
    IAUVERCO= ROBODY(IAUX,MDBVCO)

!*          3.2.1.2     VARIABLE

    ZAU     = ROBODY(IAUX,MDBVAR)

!*          3.2.1.3     ERROR STATISTICS

!*          3.2.1.4     STATUS, EVENTS, FLAGS

    IAUSTAT = ICHSTAT_REJECT( IAUSTAT )

!*          3.2.1.5     DEPARTURES

!*          3.2.1.6     UPDATE BODY ENTRY

    CALL SYNOPBE(IAUX    ,&
     & IVNM    ,IAUVERCO,ZAUPRES ,ZAUPRL  ,ZAU     ,&
     & ZAUOERR ,ZAUPERR ,ZAUFERR ,ZAURERR ,&
     & ZAUFGER ,ZAUFGCC1,ZAUFGCC2,&
     & ZAUFGDEP,ZAUANDEP,&
     & IAUSTAT ,IAUEVEN1,IAUEVEN2,IAURDBFL,IAUANFLG, &
     & IPRESCD                                       )  
  ENDIF

!*          3.2.2       CHECK IF BUFR MISSING IND. FOR:
!                       1. VERTICAL COORDINATE
!                       2. VARIABLE
!                       3. ?

  322 CONTINUE

!*          3.2.2.1     PRESSURE

  3221 CONTINUE
  IF(ROBODY(JALL  ,MDBPPP) /= RMDI ) THEN
    IF(.NOT.(ROBODY(JALL ,MDBPPP) >= RDWMLIM.AND.&
     & ROBODY(JALL ,MDBPPP) <= RUPMLIM     )) GO TO 3222  
    ROBODY(JALL ,MDBPPP ) = RMDI
  ENDIF

!*          3.2.2.2     VARIABLE

  3222 CONTINUE
  IF(ROBODY(JALL  ,MDBVAR) /= RMDI ) THEN
    IF(.NOT.(ROBODY(JALL ,MDBVAR) >= RDWMLIM.AND.&
     & ROBODY(JALL ,MDBVAR) <= RUPMLIM     )) GO TO 3223  
    ROBODY(JALL ,MDBVAR ) = RMDI
  ENDIF

!*          3.2.2.3     ERROR STATISTICS

  3223 CONTINUE
  ROBODY(JALL  ,MDBOER) = RMDI
  ROBODY(JALL  ,MDBRER) = RMDI
  ROBODY(JALL  ,MDBPER) = RMDI
  ROBODY(JALL  ,MDBFGE) = RMDI
  ROBODY(JALL  ,MDBFOE) = RMDI

!*          3.2.3       CLOSE ALL DATA LOOP

ENDDO ALL_DATA_LOOP

!*          3.2.3       CHECK IF ALL PRESENT

IF(LLPs   .AND. &
 & LLT2M  .AND. &
 & LLTd2M .AND. &
 & LLDD   .AND. &
 & LLFF   .AND. &
 & LLU10m .AND. &
 & LLV10m .AND. &
 & LLRH2m         ) GO TO 324  
WRITE(NULOUT,'('' METARIN; '')')
WRITE(NULOUT,'(''          LLPs   :'',L1)') LLPs
WRITE(NULOUT,'(''          LLT2M  :'',L1)') LLT2M
WRITE(NULOUT,'(''          LLTd2M :'',L1)') LLTd2M
WRITE(NULOUT,'(''          LLDD   :'',L1)') LLDD
WRITE(NULOUT,'(''          LLFF   :'',L1)') LLFF
WRITE(NULOUT,'(''          LLU10m :'',L1)') LLU10m
WRITE(NULOUT,'(''          LLV10m :'',L1)') LLV10m
WRITE(NULOUT,'(''          LLRH2m :'',L1)') LLRH2m
324 CONTINUE

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

!        4.             OBSERVATION BODY (OUTPUT TO ODB)
!                       --------------------------------

ZWEIGHT = 1.0_JPRB

!*          4.0         DECIDE ON VERTICAL COORDINATE; 
!                       CHECK IF PRESSURE PRESENT; WIND AND
!                       TEMPERATURE ARE DONE ANYWAY BUT ASSIGN
!                       VERTICAL COOORDINATE AS HEIGHT SET TO 0.

ZPRES      = RMDI
IPFLG      = 0
IPRESCD    = NMDI

ZGEOP      = RMDI
IGFLG      = 0

ZPSTA      = RMDI
IPSTAFLG   = 0

!*          4.0.0       GET PRESSURE

Ps0_LOOP: DO JPs = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JPs  ,MDBVNM) == NVNUMB( 47)) THEN
    IPS     = JPs
    IPCODE = ROBODY(IPS  ,MDBSYPC)

!*          4.0.1.1     STATION LEVEL PRESSURE

    IF(IPCODE == NPRESCD( 2)) THEN
      ZPSTA    = ROBODY(IPS  ,MDBVAR)
      IPSTAFLG = IBITS(INT(ROBODY(IPs  ,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
      ZGEOPSTL = ZALT
      IF(ZGEOPSTL /= RMDI) ZGEOPSTL = ZGEOPSTL * RG
      IGSTLFLG = IALFLG
      IGSTLFLG = MAX(IGSTLFLG,IPSTAFLG)
      ROBODY(IPS,MDBPPP ) = ZGEOPSTL
      ROBODY(IPS,MDBRDFL) = 0
      IDBRDFL = ROBODY(IPS,MDBRDFL)
      CALL PPVAFL(IGSTLFLG,IPSTAFLG,IDBRDFL)
      ROBODY(IPS,MDBRDFL) = IDBRDFL
    ELSE
      WRITE(NULOUT,'('' METARIN; PROBLEM WITH LOW SYNOP P CODE: '')') IPCODE
      CALL ABOR1(' METARIN : ')
    ENDIF

  ENDIF
ENDDO Ps0_LOOP

!*          4.0.4.1     STATION LEVEL PRESSURE

ZPRES = ZPSTA
IPFLG = IPSTAFLG
IPCODE= NPRESCD( 2)
ZGEOP = ZGEOPSTL
IGFLG = IGSTLFLG

!*          4.0.6       CHECK IF ZPRES, ZGEOP AND ZALT PRESENT

IF(ZPRES == RMDI.AND.ZGEOP == RMDI.AND.ZALT  == RMDI     )      THEN
  WRITE(NULOUT,'(''0METARIN; NO PRESSURE, GEOPOTENTIAL AND'',&
   & '' STATION HEIGHT ARE NOT AVAILABLE,'',&
   & '' HENCE REPORT AND BODY ENTRIES REJECTED'')')  
  WRITE(NULOUT,'('' LAT: : '',F10.2)') ZLAT
  WRITE(NULOUT,'('' LON: : '',F10.2)') ZLON
  ROBHDR(KSYNP,MDBRST) = ZCHSTAT_REJECT( ROBHDR(KSYNP,MDBRST) )

!*          4.0.6.0     REJECT ALL BODIES

  ALL_LOOP: DO JALL    = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
    ROBODY(JALL,MDBDSTA) = ZCHSTAT_REJECT( ROBODY(JALL,MDBDSTA) )

!*          4.0.6.1     SET ANY OBS. VALUE TO MISSING
!                       (CURRENT FEEDBACK NEEDS THIS)

    ROBODY(JALL,MDBVAR)  = RMDI
  ENDDO ALL_LOOP 
  GO TO 5
ENDIF

!*          4.0.7       VERTICAL COORDINATE

ZVERCO = ZPRES
IVECFL = IPFLG
IVERCO = NPRESVC
IF(ZPRES  == RMDI)            THEN
  IF(ZGEOP /= RMDI)             THEN
    ZVERCO = ZGEOP
    IVECFL = IGFLG
    IVERCO = NHEIGVC
  ELSE
    IF(ZALT /= RMDI)             THEN
      ZVERCO = ZALT * RG
      IVECFL = IALFLG
      IVERCO = NHEIGVC
    ENDIF
  ENDIF
ENDIF

!*          4.0.8       IF HEIGHT VERTICAL COORDINATE GET A PRESSURE
!                       FOR OBS. ERROR CALCULATIONS

ZPRESAU = ZPRES
IF(IVERCO == NHEIGVC)         THEN
  ZHEAUX  = ZVERCO / RG
  CALL Z2PICAO(ZHEAUX,ZPRESAU)
  ZPRESAU = ZPRESAU * 100._JPRB
ENDIF

!*          4.0.10      GET DD

ZDIR  = RMDI
IDDFLG= 0
DD0_LOOP: DO JDD = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JDD  ,MDBVNM) == NVNUMB( 48)) THEN
    ZDIR    = ROBODY(JDD  ,MDBVAR)
    IDDFLG  = IBITS(INT(ROBODY(JDD  ,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
  ENDIF
ENDDO DD0_LOOP

!*          4.0.11      GET FF

ZSPD  = RMDI
IFFFLG= 0
FF0_LOOP: DO JFF = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JFF  ,MDBVNM) == NVNUMB( 49)) THEN
    ZSPD    = ROBODY(JFF  ,MDBVAR)
    IFFFLG  = IBITS(INT(ROBODY(JFF  ,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
  ENDIF
ENDDO FF0_LOOP

!*          4.2         LOOK FOR WIND DIRECTION/SPEED DATA

420 CONTINUE
ZDIR   = RMDI
ZSPD   = RMDI
IDDFLG = 0
IFFFLG = 0
ZDDPRES= RMDI
ZFFPRES= RMDI
IDDPFLG= 0
IFFPFLG= 0
DDFF_LOOP: DO JDDFF = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1

!*          4.2.1       WIND DIRECTION

  IF(ROBODY(JDDFF,MDBVNM) == NVNUMB( 48)) THEN
    IDD     = JDDFF
    IVNM    = NVNUMB( 48)

!*          4.2.1.0     SET/GET

    CALL GETSETE(IDD,&
     & ZDDPRES,ZDDPRL,ZDIR,&
     & ZDDFGER,ZDDFGCC1,ZDDFGCC2,&
     & ZDDPERR,ZDDOERR,ZDDFERR,ZDDRERR,&
     & ZDDFGDEP,ZDDANDEP,&
     & IDDSTAT,IDDEVEN1,IDDEVEN2,IDDRDBFL,IDDANFLG,&
     & IDDFLG,IDDPFLG)  

    ZDDPRES  = ZVERCO

    IDDPFLG  = IVECFL
 
    IPRESCD  = IPCODE

!*          4.2.1.2     VARIABLE

    IF(ROBODY(IDD  ,MDBVAR) /= RMDI )       THEN
      ZDIR   = ROBODY(IDD  ,MDBVAR)
      IDDFLG = IBITS(IDDRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    ELSE
      IDDSTAT = ICHSTAT_REJECT( IDDSTAT )
    ENDIF

!*          4.2.1.3     ERROR STATISTICS

!*          4.2.1.4     STATUS, EVENTS, FLAGS

    IF(NMKCMVSE( 48,KCDSQNO,KOBSQNO) == 0)  THEN
      IDDSTAT = ICHSTAT_REJECT( IDDSTAT )
    ENDIF
    IDDRDBFL  = 0
    CALL PPVAFL(IDDPFLG,IDDFLG,IDDRDBFL)

!*          4.2.1.5     DEPARTURES

!*          4.2.1.6     UPDATE BODY ENTRY
 
    CALL SYNOPBE(IDD     ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZDDPRL  ,ZDIR    ,&
     & ZDDOERR ,ZDDPERR ,ZDDFERR ,ZDDRERR ,&
     & ZDDFGER ,ZDDFGCC1,ZDDFGCC2,&
     & ZDDFGDEP,ZDDANDEP,&
     & IDDSTAT ,IDDEVEN1,IDDEVEN2,IDDRDBFL,IDDANFLG,&
     & IPRESCD                                       )  

!*          4.2.2       WIND FORCE

  ELSEIF(ROBODY(JDDFF,MDBVNM) == NVNUMB( 49)) THEN
    IFF     = JDDFF
    IVNM    = NVNUMB( 49)

!*          4.2.2.0     SET/GET

    CALL GETSETE(IFF,&
     & ZFFPRES,ZFFPRL,ZSPD,&
     & ZFFFGER,ZFFFGCC1,ZFFFGCC2,&
     & ZFFPERR,ZFFOERR,ZFFFERR,ZFFRERR,&
     & ZFFFGDEP,ZFFANDEP,&
     & IFFSTAT,IFFEVEN1,IFFEVEN2,IFFRDBFL,IFFANFLG,&
     & IFFFLG,IFFPFLG)  

    ZFFPRES  = ZVERCO

    IFFPFLG  = IVECFL
 
    IPRESCD  = IPCODE

!*          4.2.2.2     VARIABLE

    IF(ROBODY(IFF  ,MDBVAR) /= RMDI )        THEN
      ZSPD   = ROBODY(IFF  ,MDBVAR)
      IFFFLG = IBITS(IFFRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    ELSE
      IFFSTAT = ICHSTAT_REJECT( IFFSTAT )
    ENDIF

!*          4.2.2.3     ERROR STATISTICS

    IF(LERRPERS)           THEN
      ZFFPERR  = 1.0_JPRB ! Rough first estimate of persistence error
    ENDIF
    ZFFOERR  = 2.0_JPRB ! Rough first estimate of obs. error =2 m/s
    CALL FINOERR(ZFFPERR,ZFFOERR,ZFFFERR)

!*          4.2.2.4     STATUS, EVENTS, FLAGS

    IF(NMKCMVSE( 49,KCDSQNO,KOBSQNO) == 0)          THEN
      IFFSTAT = ICHSTAT_REJECT( IFFSTAT )
    ENDIF
    IFFRDBFL  = 0
    CALL PPVAFL(IFFPFLG,IFFFLG,IFFRDBFL)

!*          4.2.2.5     DEPARTURES

!*          4.2.2.6     UPDATE BODY ENTRY

    CALL SYNOPBE(IFF     ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZFFPRL  ,ZSPD    ,&
     & ZFFOERR ,ZFFPERR ,ZFFFERR ,ZFFRERR ,&
     & ZFFFGER ,ZFFFGCC1,ZFFFGCC2,&
     & ZFFFGDEP,ZFFANDEP,&
     & IFFSTAT ,IFFEVEN1,IFFEVEN2,IFFRDBFL,IFFANFLG,&
     & IPRESCD                                       )  

  ENDIF
ENDDO DDFF_LOOP

!*          4.2.3       CHECK DD, FF AND PRESSURE

!*          4.2.4       10m(?) U COMPONENT

U10M_LOOP: DO JU10M = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JU10M,MDBVNM) == NVNUMB( 56)) THEN
    IU10M = JU10M
    IVNM  = NVNUMB( 56)

!*          4.2.4.0     SET/GET

    CALL GETSETE(IU10M,&
     & ZUUPRES,ZUUPRL,ZU  ,&
     & ZUUFGER,ZUUFGCC1,ZUUFGCC2,&
     & ZUUPERR,ZUUOERR,ZUUFERR,ZUURERR,&
     & ZUUFGDEP,ZUUANDEP,&
     & IUUSTAT,IUUEVEN1,IUUEVEN2,IUURDBFL,IUUANFLG,&
     & IUUFLG,IUUPFLG)  

    ZUUPRES  = ZVERCO

    IUUPFLG  = IVECFL
 
    IPRESCD  = IPCODE

!*          4.2.4.2     VARIABLE

    IF(ZDIR /= RMDI.AND.ZSPD /= RMDI    )        THEN
      ZU     = UCOM(ZDIR,ZSPD)
      IUUFLG = MAX(IDDFLG,IFFFLG)
    ELSE
      IUUSTAT = ICHSTAT_REJECT( IUUSTAT )
    ENDIF

!*          4.2.4.3     ERROR STATISTICS

    CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
     & IVNM,IUUSTAT,ZPRESAU,ZUUPRL,&
     & ZUUPERR,ZUUOERR,ZUUFERR,ZWEIGHT)  

!*          4.2.4.4     STATUS, EVENTS, FLAGS

    IF(NMKCMVSE( 56,KCDSQNO,KOBSQNO) == 0)          THEN
      IUUSTAT = ICHSTAT_REJECT( IUUSTAT )
    ENDIF
    IUURDBFL  = 0
    CALL PPVAFL(IUUPFLG,IUUFLG,IUURDBFL)

!*          4.2.4.5     DEPARTURES

!*          4.2.4.6     UPDATE BODY ENTRY

    CALL SYNOPBE(IU10M   ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZUUPRL  ,ZU      ,&
     & ZUUOERR ,ZUUPERR ,ZUUFERR ,ZUURERR ,&
     & ZUUFGER ,ZUUFGCC1,ZUUFGCC2,&
     & ZUUFGDEP,ZUUANDEP,&
     & IUUSTAT ,IUUEVEN1,IUUEVEN2,IUURDBFL,IUUANFLG,&
     & IPRESCD                                       )  
  ENDIF
ENDDO U10M_LOOP

!*          4.2.5       10m(?) V COMPONENT

V10M_LOOP: DO JV10M    = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JV10M,MDBVNM) == NVNUMB( 57)) THEN
    IV10M = JV10M
    IVNM  = NVNUMB( 57)

!*          4.2.5.0     SET/GET

    CALL GETSETE(IV10M,&
     & ZVVPRES,ZVVPRL,ZV  ,&
     & ZVVFGER,ZVVFGCC1,ZVVFGCC2,&
     & ZVVPERR,ZVVOERR,ZVVFERR,ZVVRERR,&
     & ZVVFGDEP,ZVVANDEP,&
     & IVVSTAT,IVVEVEN1,IVVEVEN2,IVVRDBFL,IVVANFLG,&
     & IVVFLG,IVVPFLG)  

    ZVVPRES  = ZVERCO

    IVVPFLG  = IVECFL

    IPRESCD  = IPCODE

!*          4.2.5.2     VARIABLE

    IF(ZDIR /= RMDI.AND.ZSPD /= RMDI    )        THEN
      ZV      = VCOM(ZDIR,ZSPD)
      IVVFLG  = MAX(IDDFLG,IFFFLG)
    ELSE
      IVVSTAT = ICHSTAT_REJECT( IVVSTAT )
    ENDIF

!*          4.2.5.3     ERROR STATISTICS

    CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
     & IVNM,IVVSTAT,ZPRESAU,ZVVPRL,&
     & ZVVPERR,ZVVOERR,ZVVFERR,ZWEIGHT)  

!*          4.2.5.4     STATUS, EVENTS, FLAGS
  
    IF(NMKCMVSE( 57,KCDSQNO,KOBSQNO) == 0)          THEN
      IVVSTAT = ICHSTAT_REJECT( IVVSTAT )
    ENDIF
    IVVRDBFL  = 0
    CALL PPVAFL(IVVPFLG,IVVFLG,IVVRDBFL)

!*          4.2.5.5     DEPARTURES

!*          4.2.5.5     UPDATE BODY ENTRY

    CALL SYNOPBE(IV10M   ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZVVPRL  ,ZV      ,&
     & ZVVOERR ,ZVVPERR ,ZVVFERR ,ZVVRERR ,&
     & ZVVFGER ,ZVVFGCC1,ZVVFGCC2,&
     & ZVVFGDEP,ZVVANDEP,&
     & IVVSTAT ,IVVEVEN1,IVVEVEN2,IVVRDBFL,IVVANFLG,&
     & IPRESCD                                       )  
  ENDIF
ENDDO V10M_LOOP

!*          4.3         2m(?) TEMPERATURE

ZT2M     = RMDI
ITTFLG   = 0
ITTPFLG  = IVECFL
T2M_LOOP: DO JT2M = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JT2M ,MDBVNM) == NVNUMB( 10)) THEN
    IT2M = JT2M
    IVNM = NVNUMB( 10)

!*          4.3.0       SET/GET

    CALL GETSETE(IT2M,&
     & ZTTPRES,ZTTPRL,ZT2M,&
     & ZTTFGER,ZTTFGCC1,ZTTFGCC2,&
     & ZTTPERR,ZTTOERR,ZTTFERR,ZTTRERR,&
     & ZTTFGDEP,ZTTANDEP,&
     & ITTSTAT,ITTEVEN1,ITTEVEN2,ITTRDBFL,ITTANFLG,&
     & ITTFLG,ITTPFLG)  

    ZTTPRES  = ZVERCO

    ITTPFLG  = IVECFL

    IPRESCD  = IPCODE

!*          4.3.2       VARIABLE

    IF(ROBODY(IT2M ,MDBVAR) /= RMDI ) THEN
      ZT2M  = ROBODY(IT2M ,MDBVAR)
      ITTFLG= IBITS(ITTRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    ELSE
      ITTSTAT = ICHSTAT_REJECT( ITTSTAT )
    ENDIF

!*          4.3.3       ERROR STATISTICS

    CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
     & IVNM,ITTSTAT,ZPRESAU,ZTTPRL,&
     & ZTTPERR,ZTTOERR,ZTTFERR,ZWEIGHT)  

!*          4.3.4       STATUS, EVENTS, FLAGS

    IF(NMKCMVSE( 10,KCDSQNO,KOBSQNO) == 0)          THEN
      ITTSTAT = ICHSTAT_REJECT( ITTSTAT )
    ENDIF
    ITTRDBFL  = 0
    CALL PPVAFL(ITTPFLG,ITTFLG,ITTRDBFL)

!*          4.3.5       DEPARTURES

!*          4.3.6       UPDATE BODY ENTRY

    CALL SYNOPBE(IT2M    ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZTTPRL  ,ZT2M    ,&
     & ZTTOERR ,ZTTPERR ,ZTTFERR ,ZTTRERR ,&
     & ZTTFGER ,ZTTFGCC1,ZTTFGCC2,&
     & ZTTFGDEP,ZTTANDEP,&
     & ITTSTAT ,ITTEVEN1,ITTEVEN2,ITTRDBFL,ITTANFLG,&
     & IPRESCD                                       )  
  ENDIF
ENDDO T2M_LOOP

!*          4.4         DEW POINT

ZTD2M  = RMDI
ITDFLG = 0
ITDPFLG= IVECFL
DEWPOINT_LOOP: DO JTD2M = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JTD2M,MDBVNM) == NVNUMB( 11)) THEN
    ITD2M = JTD2M
    IVNM = NVNUMB( 11)

!*          4.4.0       SET/GET

    CALL GETSETE(ITD2M,&
     & ZTDPRES,ZTDPRL,ZTD2M,&
     & ZTDFGER,ZTDFGCC1,ZTDFGCC2,&
     & ZTDPERR,ZTDOERR,ZTDFERR,ZTDRERR,&
     & ZTDFGDEP,ZTDANDEP,&
     & ITDSTAT,ITDEVEN1,ITDEVEN2,ITDRDBFL,ITDANFLG,&
     & ITDFLG,ITDPFLG)  

    ZTDPRES  = ZVERCO

    ITDPFLG  = IVECFL

    IPRESCD  = IPCODE

!*          4.4.2       VARIABLE

    IF(ROBODY(ITD2M,MDBVAR) /= RMDI ) THEN
      ZTD2M = ROBODY(ITD2M,MDBVAR)
      ITDFLG= IBITS(ITDRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    ELSE
      ITDSTAT = ICHSTAT_REJECT( ITDSTAT )
    ENDIF

!*          4.4.3       ERROR STATISTICS

!*          4.4.4       STATUS, EVENTS, FLAGS

    IF(NMKCMVSE( 11,KCDSQNO,KOBSQNO) == 0)          THEN
      ITDSTAT = ICHSTAT_REJECT( ITDSTAT )
    ENDIF
    ITDRDBFL  = 0
    CALL PPVAFL(ITDPFLG,ITDFLG,ITDRDBFL)

!*          4.4.5       DEPARTURES

!*          4.4.6       UPDATE BODY ENTRY

    CALL SYNOPBE(ITD2M   ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZTDPRL  ,ZTD2M   ,&
     & ZTDOERR ,ZTDPERR ,ZTDFERR ,ZTDRERR ,&
     & ZTDFGER ,ZTDFGCC1,ZTDFGCC2,&
     & ZTDFGDEP,ZTDANDEP,&
     & ITDSTAT ,ITDEVEN1,ITDEVEN2,ITDRDBFL,ITDANFLG,&
     & IPRESCD                                       )  
  ENDIF
ENDDO DEWPOINT_LOOP

!*          4.5         RELATIVE HUMIDITY

REL_HUMIDITY_DATA_LOOP: DO JRH2M = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JRH2M,MDBVNM) == NVNUMB(  7)) THEN
    IRH2M = JRH2M
    IVNM  = NVNUMB(  7)

!*          4.5.0       SET/GET

    CALL GETSETE(IRH2M,&
     & ZRHPRES,ZRHPRL,ZRH2M,&
     & ZRHFGER,ZRHFGCC1,ZRHFGCC2,&
     & ZRHPERR,ZRHOERR,ZRHFERR,ZRHRERR,&
     & ZRHFGDEP,ZRHANDEP,&
     & IRHSTAT,IRHEVEN1,IRHEVEN2,IRHRDBFL,IRHANFLG,&
     & IRHFLG,IRHPFLG)  

    ZRHPRES  = ZVERCO

    IRHPFLG  = IVECFL

    IPRESCD  = IPCODE

!*          4.5.2       VARIABLE

    IF( ZT2M /= RMDI .AND. ZTD2M /= RMDI ) THEN
      IRHFLG   = MAX(ITTFLG,ITDFLG)
      IF(IRHFLG < NFLLIMOP(2))  THEN
        LLDONEBCH= .FALSE.
        ZRH2M    = FOEEWMO( ZTD2M ) / FOEEWMO( ZT2M )

!*          4.5.3       ERROR STATISTICS

!*          4.5.3.2     OBSERVATION ERROR

        IF(LRHERRMO)       THEN
          ZRHOERR = -0.0015_JPRB * ZT2M + 0.54_JPRB
          ZRHOERR = MIN(0.18_JPRB,MAX(0.06_JPRB,ZRHOERR))
        ELSE
          ZRHOERR = RHERR1
          IF(ZRH2M < RRHLIM )  ZRHOERR = RHERR2
          IF(ZT2M  < RRHTLIM)  ZRHOERR = RHERR3
        ENDIF

!*          4.5.3.3     FINAL OBSERVATION ERROR

        ZRHFERR = ZRHOERR

!*          4.5.3.4     COMBINED FLAG TO HI

      ELSE
        ZRH2M   = RMDI
        IRHSTAT = ICHSTAT_REJECT( IRHSTAT )
      ENDIF

!*          4.5.3.5     NO VARIABLE

    ELSE
      IRHSTAT = ICHSTAT_REJECT( IRHSTAT )
    ENDIF

!*          4.5.4       STATUS, EVENTS, FLAGS

    IF(NMKCMVSE(  7,KCDSQNO,KOBSQNO) == 0)          THEN
      IRHSTAT = ICHSTAT_REJECT( IRHSTAT )
    ENDIF
    IRHRDBFL  = 0
    CALL PPVAFL(IRHPFLG,IRHFLG,IRHRDBFL)

!*          4.4.5       DEPARTURES

!*          4.5.6       UPDATE BODY ENTRY

    CALL SYNOPBE(IRH2M   ,&
     & IVNM    ,IVERCO  ,ZVERCO  ,ZRHPRL  ,ZRH2M   ,&
     & ZRHOERR ,ZRHPERR ,ZRHFERR ,ZRHRERR ,&
     & ZRHFGER ,ZRHFGCC1,ZRHFGCC2,&
     & ZRHFGDEP,ZRHANDEP,&
     & IRHSTAT ,IRHEVEN1,IRHEVEN2,IRHRDBFL,IRHANFLG,&
     & IPRESCD                                       )  
  ENDIF
ENDDO REL_HUMIDITY_DATA_LOOP

!*          4.11        PRESSURE

4110 CONTINUE
Ps_LOOP: DO JPs = MLNKH2B(KSYNP),MLNKH2B(KSYNP+1)-1
  IF(ROBODY(JPs  ,MDBVNM) == NVNUMB( 47)) THEN
    IPS      = JPs
    IVNM     = NVNUMB( 47)
    IPRESCD  = ROBODY(IPS  ,MDBSYPC)

!*          4.11.0      SET/GET

    CALL GETSETE(IPS,&
     & ZPSPRES,ZPSPRL,ZPS ,&
     & ZPSFGER,ZPSFGCC1,ZPSFGCC2,&
     & ZPSPERR,ZPSOERR,ZPSFERR,ZPSRERR,&
     & ZPSFGDEP,ZPSANDEP,&
     & IPSSTAT,IPSEVEN1,IPSEVEN2,IPSRDBFL,IPSANFLG,&
     & IPSFLG,IPSPFLG)  

    ZPSPRES  = ZGEOPSTL
    IPSPFLG  = IGSTLFLG


!*          4.11.2      VARIABLE

    ZPS   = ROBODY(IPS  ,MDBVAR)

!*          4.11.2.1    MISSING PS

    IF(ZPS == RMDI ) THEN
      IPSSTAT = ICHSTAT_REJECT( IPSSTAT )

!*          4.11.2.2    BIAS CORRECTION

    ELSE
      IF(L_METAR_PS_BIAS) THEN
        ZPSBIAS = ROBODY(IPS,MDBTORB)
        IF(ZPSBIAS /= RMDI) THEN
          ZPS      = ZPS - ZPSBIAS
          IPSEVEN2 = ICHEV2(IPSEVEN2,ND2EVENT( 1,KOBTYP))
        ENDIF
      ENDIF
    ENDIF

!*          4.11.3      ERROR STATISTICS

    IF (LHUBERBGQCG) THEN
      IVNMZ = NVNUMB(  3)
!     Note: Calculation of persistence error not possible with the
!         presently used method because no geopotential observation
!         is available for METAR. Usually LERRPERS is .false. so this
!         does not matter. As a safety we set ZPSPERR  = 100. (Pa)
!         The call to ERRSTAT is required to adjust the observation 
!         error.
      ZZZPERR=RMDI  ! To be changed!
      ZZZFERR=RMDI  ! To be changed!
      CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
       & IVNMZ,IZZSTAT,ZPRESAU,ZZZPRL,&
       & ZZZPERR,ZZZOERR,ZZZFERR,ZWEIGHT)
    ENDIF

!*          4.11.3.1    PERSISTENCE ERROR

    IF(LERRPERS)           THEN
!EA   ZPSPERR  = ZZZPERR*RPAPM
      ZPSPERR  = 100.   ! To be changed!
    ENDIF

!*          4.11.3.2    OBSERVATION ERROR

    IF (LHUBERBGQCG) THEN
      IF(ZZZOERR /= RMDI)    THEN
        ZPSOERR  = ZZZOERR*RPAPM
      ELSE
        IPSSTAT = ICHSTAT_REJECT( IPSSTAT )
      ENDIF
    ELSE
!EA   ZPSOERR  = ZZZOERR*RPAPM
      ZPSOERR  =  80.
    ENDIF

!*          4.11.3.3    PRESSURE FINAL OBSERVATION ERROR

    CALL FINOERR(ZPSPERR,ZPSOERR,ZPSFERR)

!*          4.11.4      STATUS, EVENTS, FLAGS

    IF(NMKCMVSE( 47,KCDSQNO,KOBSQNO) == 0)          THEN
      IPSSTAT = ICHSTAT_REJECT( IPSSTAT )
    ENDIF
    IPSRDBFL  = 0
    CALL PPVAFL(IPSPFLG,IPSFLG,IPSRDBFL)

!*          4.11.5      DEPARTURES

!*          4.11.6      UPDATE BODY ENTRY

    CALL SYNOPBE(IPS     ,&
     & IVNM    ,NHEIGVC ,ZPSPRES ,ZPSPRL  ,ZPS     ,&
     & ZPSOERR ,ZPSPERR ,ZPSFERR ,ZPSRERR ,&
     & ZPSFGER ,ZPSFGCC1,ZPSFGCC2,&
     & ZPSFGDEP,ZPSANDEP,&
     & IPSSTAT ,IPSEVEN1,IPSEVEN2,IPSRDBFL,IPSANFLG,&
     & IPRESCD                                       )  
  ENDIF
ENDDO Ps_LOOP
!*
!-----------------------------------------------------------------------

!        5.             FINISH OFF REPORT (re)CREATION
!                       ------------------------------

5 CONTINUE

!*          5.1         UPDATE HEADER PARAMETERS (IF ANY)

!*          5.2         ODB REPORT UPDATED SWITCH

LDTAKEN = .TRUE.
!*
!-----------------------------------------------------------------------

!        6.             IF OUTPUT MESSAGE; PRINT LAT/LON
!                       --------------------------------

6 CONTINUE
IF(LDMESAGE)           THEN
  WRITE(NULOUT,'('' LAT.     :'',F10.2)') ZLAT
  WRITE(NULOUT,'('' LON.     :'',F10.2)') ZLON
  CALL FLUSH(NULOUT)
ENDIF
!*
!-----------------------------------------------------------------------

!        7.             RETURN
!                       ------

IF (LHOOK) CALL DR_HOOK('METARIN',1,ZHOOK_HANDLE)
END SUBROUTINE METARIN
