SUBROUTINE SATOBIN(KSTBP,&
 & KOBTYP,KCDTYP,KOBSQNO,KCDSQNO,&
 & LDMESAGE,LDTAKEN)  

!**** SUBROUTINE SATOBIN - PROCESS INPUT SATOB

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

!     PURPOSE
!     -------

!        PROCESS INPUT SATOB

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

!        CALL SATOBIN(KSTBP,
!                     KOBTYP,KCDTYP,KOBSQNO,KCDSQNO,
!                     LDMESAGE,LDTAKEN)
!     WHERE:
!            KSTBP   = 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  

!        SATOBIN IS CALLED BY SUBROUTINE ????????

!     METHOD
!     ------

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

!        PRLMCHK  - PRELIMINARY CHECKS
!        GETSETE  - GET/SET BODY ENTRY
!        ERRSTAT  - OBS. ERROR
!        SATOBBE  - UPDATE SATOB BODY ENTRY
!        PPVAFL   - PRESSURE/VARIABLE FLAG RESET

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

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

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMDB
USE YOMCMBDY , ONLY : NCMBPFBP ,NCMBVFBP ,NCMBFLBP ,NCMBFLOC
USE YOMANCS  , ONLY : NMDI     ,RMDI     ,RDEGREES ,RADIANS  ,EPSMAC   ,RUPMLIM  ,RDWMLIM  
USE YOMCST   , ONLY : RTT
USE YOMVNMB  , ONLY : NVNUMB
USE YOMNMCOD , ONLY : NPRESVC
USE YOMMKODB , ONLY : LERRPERS, NMKCMVSE ,LTOTREM
USE YOETHF   , ONLY : RTICE    ,RTWAT    ,R2ES     ,R3IES    ,&
 & R3LES    ,R4IES    ,R4LES  
USE YOMLUN   , ONLY : NULOUT
USE LOCAL_TRAFOS

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KSTBP 
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, &
 & IVNM, JDDFF,&
 & ISTID, INSTYP, ISCHAN, ISINS, ISDPT, IREPST, &
 & ISATID, ICOMPMTH, INSDATUIP, IDATPTU, IQI1, IQI2, IQI3  

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) :: JU, IU, &
 & IUUSTAT, IUUEVEN1, IUUEVEN2, IUURDBFL, IUUANFLG, &
 & IUUPFLG, IUUFLG  
INTEGER(KIND=JPIM) :: JV, IV, &
 & IVVSTAT, IVVEVEN1, IVVEVEN2, IVVRDBFL, IVVANFLG, &
 & IVVPFLG, IVVFLG  
INTEGER(KIND=JPIM) :: JT, ITEMP, &
 & ITTSTAT, ITTEVEN1, ITTEVEN2, ITTRDBFL, ITTANFLG, &
 & ITTPFLG, ITTFLG  
INTEGER(KIND=JPIM) :: IAUX, JALL, &
 & IAUSTAT, IAUEVEN1, IAUEVEN2, IAURDBFL, IAUANFLG, &
 & IAUPFLG, IAUFLG  , IAUVERCO  

LOGICAL :: LLFAIL, LLREMOVE

REAL(KIND=JPRB) :: ZLAT, ZLON, &
 & ZTIMDIF, &
 & ZWEIGHT  

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) :: ZT  , ZTTPRES, ZTTPRL, &
 & ZTTPERR, ZTTOERR, ZTTFERR, ZTTRERR, &
 & ZTTFGER, ZTTFGCC1, ZTTFGCC2, &
 & ZTTFGDEP, ZTTANDEP  
REAL(KIND=JPRB) :: ZAU, ZAUPRES, ZAUPRL, &
 & ZAUPERR, ZAUOERR, ZAUFERR, ZAURERR, &
 & ZAUFGER, ZAUFGCC1, ZAUFGCC2, &
 & ZAUFGDEP, ZAUANDEP  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "errstat.intfb.h"
#include "getsete.intfb.h"
#include "obinstp.intfb.h"
#include "ppvafl.intfb.h"
#include "prlmchk.intfb.h"
#include "satobbe.intfb.h"
#include "finoerr.intfb.h"

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

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

!        1.             PRESET
!                       ------

!*          1.1         GET OBS. PARAMETERS FROM "HEADER"

IF (LHOOK) CALL DR_HOOK('SATOBIN',0,ZHOOK_HANDLE)
ZLAT   = ROBHDR(KSTBP,MDBLAT) * RDEGREES
ZLON   = ROBHDR(KSTBP,MDBLON) * RDEGREES
IOBDATE= ROBHDR(KSTBP,MDBDAT)
IOBTIME= ROBHDR(KSTBP,MDBETM)
!CLSTID= TRANSFER(ROBHDR(KSTBP,MDBSID), CLSTID)
!ISTID = 0
!READ(CLSTID(1:8),'(I8)') ISTID
ISTID  = SATHDR(KSTBP,MDB_SATID_AT_SAT)
IREPST = ROBHDR(KSTBP,MDBRST)

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

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

!*          2.1         DEFINE INSTRUMENT TYPE

INSTYP  = 0
ISCHAN  = NMDI
ISINS   = NMDI
ISDPT   = NMDI
CALL OBINSTP(ZLAT,ZLON,ISTID,&
 & KOBTYP,KCDTYP,&
 & INSTYP)  

!*          2.2         SET INSTRUMENT TYPE INTO OBSERVATION
!                       CHARACTERISTICS

ROBHDR(KSTBP,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(KSTBP,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         REPORT EXTRA INFO

!*          3.2.1       SATHDR

!*          3.2.1.1     SAT ID

ISATID   = SATHDR(KSTBP,MDB_SATID_AT_SAT)

!*          3.2.1.2     CLOUD MOTION COMP. METHOD

ICOMPMTH = SATHDR(KSTBP,MDBSBCMM)

!*          3.2.1.3     INSTRUMENT DATA USED IN PROCESSING

INSDATUIP= SATHDR(KSTBP,MDBSBIUP)

!*          3.2.1.4     DATA PROCESSING TECHNIQUE USED

IDATPTU  = SATHDR(KSTBP,MDBSBDPT)

!*          3.2.1.5     QIs

IQI1     = SATHDR(KSTBP,MDBSBQI1)
IQI2     = SATHDR(KSTBP,MDBSBQI2)
IQI3     = SATHDR(KSTBP,MDBSBQI3)

!*          3.3         BODY PARAMETERS

ALL_DATA_LOOP: DO JALL = MLNKH2B(KSTBP),MLNKH2B(KSTBP+1)-1

!*          3.3.1       WE ACCEPT: T, DD, FF, U, V

  IF(ROBODY(JALL  ,MDBVNM) == NVNUMB(  8) .OR. &
   & ROBODY(JALL  ,MDBVNM) == NVNUMB( 48) .OR. &
   & ROBODY(JALL  ,MDBVNM) == NVNUMB( 49) .OR. &
   & ROBODY(JALL  ,MDBVNM) == NVNUMB(  1) .OR. &
   & ROBODY(JALL  ,MDBVNM) == NVNUMB(  2)       ) GO TO 332  

!*          3.3.1.0     UNEXPECTED VARIABLE

  IAUX = JALL
  IVNM = ROBODY(IAUX  ,MDBVNM)
  WRITE(NULOUT,'('' SATOBIN; UNEXPECTED VARIABLE: '',I10)') IVNM
  LDMESAGE = .TRUE.

!*          3.3.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.3.1.2     VARIBLE

  ZAU     = ROBODY(IAUX,MDBVAR)

!*          3.3.1.3     ERROR STATISTICS

!*          3.3.1.4     STATUS, EVENTS, FLAGS

  IAUSTAT = ICHSTAT_REJECT( IAUSTAT )

!*          3.3.1.5     DEPARTURES

!*          3.3.1.6     UPDATE BODY ENTRY

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

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

  332 CONTINUE

!*          3.3.1.1     PRESSURE

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

!*          3.3.1.2     VARIABLE

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

!*          3.3.1.3     ERROR STATISTICS

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

!*          3.3.3       CLOSE ALL DATA LOOP

ENDDO ALL_DATA_LOOP

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

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

ZWEIGHT = 1.0_JPRB

!*          4.1         LOOK FOR WIND DIRECTION/FORCE DATA

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

!*          4.2         WIND DIRECTION

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

!*          4.2.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  = ROBODY(IDD  ,MDBPPP)

    IDDFLG   = IBITS(IDDRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    IDDPFLG  = IBITS(IDDRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)

!*          4.2.2       VARIBLE

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

!*          4.2.3       ERROR STATISTICS

!*          4.2.4       STATUS, EVENTS, FLAGS

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

!*          4.2.5       DEPARTURES

!*          4.2.6       UPDATE BODY ENTRY

    CALL SATOBBE(IDD     ,&
     & IVNM    ,NPRESVC ,ZDDPRES ,ZDDPRL  ,ZDIR    ,&
     & ZDDOERR ,ZDDPERR ,ZDDFERR ,ZDDRERR ,&
     & ZDDFGER ,ZDDFGCC1,ZDDFGCC2,&
     & ZDDFGDEP,ZDDANDEP,&
     & IDDSTAT ,IDDEVEN1,IDDEVEN2,IDDRDBFL,IDDANFLG  )  

!*          4.3         WIND SPEED

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

!*          4.3.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  = ROBODY(IFF  ,MDBPPP)

    IFFFLG   = IBITS(IFFRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    IFFPFLG  = IBITS(IFFRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)

!*          4.3.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.3.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.3.4       STATUS, EVENTS, FLAGS

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

!*          4.3.5       DEPARTURES

!*          4.3.6       UPDATE BODY ENTRY

    CALL SATOBBE(IFF     ,&
     & IVNM    ,NPRESVC ,ZFFPRES ,ZFFPRL  ,ZSPD    ,&
     & ZFFOERR ,ZFFPERR ,ZFFFERR ,ZFFRERR ,&
     & ZFFFGER ,ZFFFGCC1,ZFFFGCC2,&
     & ZFFFGDEP,ZFFANDEP,&
     & IFFSTAT ,IFFEVEN1,IFFEVEN2,IFFRDBFL,IFFANFLG  )  
  ENDIF
ENDDO DDFF_LOOP

!*          4.4         CHECK IF DD, FF AND PRESSURE PRESENT

!*          4.5         U COMPONENT

450 CONTINUE
ZU     = RMDI
U_LOOP: DO JU = MLNKH2B(KSTBP),MLNKH2B(KSTBP+1)-1
  IF(ROBODY(JU,MDBVNM) == NVNUMB(  1)) THEN
    IU    = JU
    IVNM  = NVNUMB(  1)

!*          4.5.0       SET/GET

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

    ZUUPRES  = ROBODY(IU   ,MDBPPP)

    IUUFLG   = IBITS(IUURDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    IUUPFLG  = IBITS(IUURDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)

!*          4.5.1       VERTICAL COORDINATE

    IF(ZDDPRES /= ZFFPRES)   THEN
      IUUSTAT = ICHSTAT_REJECT( IUUSTAT )
    ELSE
      ZUUPRES = ZDDPRES
      IUUPFLG = IDDPFLG  
    ENDIF

    IF(IDDPFLG /= IFFPFLG)   THEN
      IUUSTAT = ICHSTAT_REJECT( IUUSTAT )
    ELSE
      IUUPFLG = IDDPFLG 
    ENDIF

!*          4.5.2       VARIABLE

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

!*          4.5.3       ERROR STATISTICS

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

!*          4.5.4       STATUS, EVENTS, FLAGS

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

!*          4.5.5       DEPARTURES

!*          4.5.6       UPDATE BODY ENTRY

    CALL SATOBBE(IU      ,&
     & IVNM    ,NPRESVC ,ZUUPRES ,ZUUPRL  ,ZU      ,&
     & ZUUOERR ,ZUUPERR ,ZUUFERR ,ZUURERR ,&
     & ZUUFGER ,ZUUFGCC1,ZUUFGCC2,&
     & ZUUFGDEP,ZUUANDEP,&
     & IUUSTAT ,IUUEVEN1,IUUEVEN2,IUURDBFL,IUUANFLG  )  
  ENDIF
ENDDO U_LOOP

!*          4.6         V COMPONENT

460 CONTINUE
ZV     = RMDI
V_LOOP: DO JV = MLNKH2B(KSTBP),MLNKH2B(KSTBP+1)-1
  IF(ROBODY(JV,MDBVNM) == NVNUMB(  2)) THEN
    IV    = JV
    IVNM  = NVNUMB(  2)

!*          4.6.0       SET/GET

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

    ZVVPRES  = ROBODY(IV   ,MDBPPP)

    IVVFLG   = IBITS(IVVRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    IVVPFLG  = IBITS(IVVRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)

!*          4.6.1       VERTICAL COORDINATE

    IF(ZDDPRES /= ZFFPRES)   THEN
      IVVSTAT = ICHSTAT_REJECT( IVVSTAT )
    ELSE
      ZVVPRES = ZDDPRES
    ENDIF

    IF(IDDPFLG /= IFFPFLG)   THEN
      IVVSTAT = ICHSTAT_REJECT( IVVSTAT )
    ELSE
      IVVPFLG = IDDPFLG 
    ENDIF

!*          4.6.2       VARIABLE

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

!*          4.6.3       ERROR STATISTICS

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

!*          4.6.4       STATUS, EVENTS, FLAGS

    IF(NMKCMVSE(  2,KCDSQNO,KOBSQNO) == 0)          THEN
      IVVSTAT = ICHSTAT_REJECT( IVVSTAT )
    ENDIF
    CALL PPVAFL(IVVPFLG,IVVFLG,IVVRDBFL)

!*          4.6.5       DEPARTURES

!*          4.6.6       UPDATE BODY ENTRY

    CALL SATOBBE(IV      ,&
     & IVNM    ,NPRESVC ,ZVVPRES ,ZVVPRL  ,ZV      ,&
     & ZVVOERR ,ZVVPERR ,ZVVFERR ,ZVVRERR ,&
     & ZVVFGER ,ZVVFGCC1,ZVVFGCC2,&
     & ZVVFGDEP,ZVVANDEP,&
     & IVVSTAT ,IVVEVEN1,IVVEVEN2,IVVRDBFL,IVVANFLG  )  
  ENDIF
ENDDO V_LOOP

!*          4.7         TEMPERATURE

470 CONTINUE
T_LOOP: DO JT = MLNKH2B(KSTBP),MLNKH2B(KSTBP+1)-1
  IF(ROBODY(JT,MDBVNM) == NVNUMB(  8)) THEN
    ITEMP = JT
    IVNM  = NVNUMB(  8)

!*          4.7.0       SET/GET

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

    ZTTPRES  = ROBODY(ITEMP,MDBPPP)

    ITTFLG   = IBITS(ITTRDBFL,NCMBVFBP+NCMBFLBP,NCMBFLOC)
    ITTPFLG  = IBITS(ITTRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)

!*          4.7.1       VERTICAL COORDINATE

!*          4.7.2       VARIABLE

    IF(ROBODY(ITEMP,MDBVAR) /= RMDI    )        THEN
      ZT     = ROBODY(ITEMP,MDBVAR)
    ELSE
      ITTSTAT = ICHSTAT_REJECT( ITTSTAT )
    ENDIF

!*          4.7.3       ERROR STATISTICS (DOES NOT EXIST YET)

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

!*          4.7.4       STATUS, EVENTS, FLAGS

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

!*          4.7.5       DEPARTURES

!*          4.7.6       UPDATE BODY ENTRY

    CALL SATOBBE(ITEMP   ,&
     & IVNM    ,NPRESVC ,ZTTPRES ,ZTTPRL  ,ZT      ,&
     & ZTTOERR ,ZTTPERR ,ZTTFERR ,ZTTRERR ,&
     & ZTTFGER ,ZTTFGCC1,ZTTFGCC2,&
     & ZTTFGDEP,ZTTANDEP,&
     & ITTSTAT ,ITTEVEN1,ITTEVEN2,ITTRDBFL,ITTANFLG  )  
  ENDIF
ENDDO T_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
!                       ------

7 CONTINUE
IF (LHOOK) CALL DR_HOOK('SATOBIN',1,ZHOOK_HANDLE)
END SUBROUTINE SATOBIN
