SUBROUTINE TEMPIN(KTEMP,&
 & KOBTYP,KCDTYP,KOBSQNO,KCDSQNO,&
 & LDMESAGE,LDTAKEN)  

!**** SUBROUTINE TEMPIN - PROCESS INPUT TEMP

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

!     PURPOSE
!     -------

!        PROCESS INPUT TEMP

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

!        CALL TEMPIN(KTEMP,
!                    KOBTYP,KCDTYP,KOBSQNO,KCDSQNO,
!                    LDMESAGE,LDTAKEN)
!     WHERE:
!            KTEMP   = REPORT POINTER
!            KOBTYP  = CMA OBS. TYPE
!            KCDTYP  = CMA CODE TYPE
!            KOBSQNO = CMA OBS. TYPE SQ. NO.
!            KCDSQNO = CMA CODE TYPE SQ. NO.
!            LDMESAGE= OUTPUT MESSAGE SWITCH  
!            LDTAKEN = REPORT TAKEN ("CMA" REPORT CREATED) SWITCH  

!        TEMPIN IS CALLED BY SUBROUTINE ????????

!     METHOD
!     ------

!        THE CMA TEMP RECORD IS BUILT UP FROM THE EXPANDED BUFR ARRAYS.

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

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

!     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 ,&
 & NPSURBP  ,NPSUROC  
USE YOMANCS  , ONLY : NMDI     ,RMDI     ,RDEGREES ,RADIANS  ,EPSMAC   ,RPAPM    ,&
 & RTICE    ,RTWAT    ,R2ES     ,R3IES    ,&
 & R3LES    ,R4IES    ,R4LES    ,RTT      ,RUPMLIM  ,RDWMLIM  ,&
 & RSANMOMH ,RSBAROMH  
USE YOMVNMB  , ONLY : NVNUMB
USE YOMMKODB , ONLY : LERRPERS, NMKCMVSE ,&
 & LQERRFP  ,LQERRFRH ,LQERRFT  ,LTOTREM  ,&
 & LBIASCV  ,LTBIASBUFR,LTBIASC ,LHBIASC ,LSTOBIAS ,&
 & L_NEW_T_BIAS,&
 & L_NEW_T_BIAS_SOLAR_vs_all_mean, L_NEW_T_BIAS_SOLAR_vs_day_mean,L_NEW_T_BIAS_SOLAR_vs_night_m,&
 & L_NEW_T_BIAS_ALL_MEAN, L_NEW_T_BIAS_DAY_MEAN, L_NEW_T_BIAS_NIGHT_MEAN,&
 & L_NEW_RH_BIAS,&
 & L_NEW_RH_BIAS_SOLAR_vs_all_mean, L_NEW_RH_BIAS_SOLAR_vs_day_mean, L_NEW_RH_BIAS_SOLAR_vs_night_m,&
 & L_NEW_RH_BIAS_ALL_MEAN, L_NEW_RH_BIAS_DAY_MEAN, L_NEW_RH_BIAS_NIGHT_MEAN
USE YOMLIM   , ONLY :        NFLLIMOP ,&
 & RRHLIM   ,RRHTLIM  
USE YOMNMCOD , ONLY : NPRESVC  
USE YOMOERR  , ONLY : RHERR1   ,RHERR2   ,RHERR3
USE YOMERR   , ONLY : LRHERRMO
USE YOMNMEV  , ONLY : NR1EVENT  ,NR2EVENT ,ND2EVENT
!USE YOETHF   , ONLY : RTICE    ,RTWAT    ,R2ES     ,R3IES    ,&
!            &         R3LES    ,R4IES    ,R4LES
USE YOMLUN   , ONLY : NULOUT    
USE YOMCMA   , ONLY : NMXNVO
USE YOMCOCTP , ONLY : NSHTCD
USE LOCAL_TRAFOS

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KTEMP 
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) :: IDATEV2, IOBDATE, IOBTIME, IVNM, JDF, &
 & ISTART, IEND, ISURF, &
 & ISTID, INSTYP, IYEAR, IMONTH, IDAY, IHOUR, &
 & ITYPESOND, JSLEV, INOBIASCL, ISKIP, JBODE, JBODR, IBODP, &
 & IEVENTNO, IREPST, INOEPLE, INOEPL, JWIND, JLE, JHUM  


INTEGER(KIND=JPIM) :: IDD, &
 & IDDSTAT, IDDEVEN1, IDDEVEN2, IDDRDBFL, IDDANFLG, &
 & IDDPFLG, IDDFLG, IDDVERCO, IDDLEVID, IDDSURF  
INTEGER(KIND=JPIM) :: IFF, &
 & IFFSTAT, IFFEVEN1, IFFEVEN2, IFFRDBFL, IFFANFLG, &
 & IFFPFLG, IFFFLG, IFFVERCO, IFFLEVID, IFFSURF  
INTEGER(KIND=JPIM) :: IU, &
 & IUUSTAT, IUUEVEN1, IUUEVEN2, IUURDBFL, IUUANFLG, &
 & IUUPFLG, IUUFLG, IUUVERCO, IUULEVID  
INTEGER(KIND=JPIM) :: IV, &
 & IVVSTAT, IVVEVEN1, IVVEVEN2, IVVRDBFL, IVVANFLG, &
 & IVVPFLG, IVVFLG, IVVVERCO, IVVLEVID  
INTEGER(KIND=JPIM) :: IZ, JZ, &
 & IZZSTAT, IZZEVEN1, IZZEVEN2, IZZRDBFL, IZZANFLG, &
 & IZZPFLG, IZZFLG, IZZVERCO, IZZLEVID  
INTEGER(KIND=JPIM) :: ITEMP, JT, &
 & ITTSTAT, ITTEVEN1, ITTEVEN2, ITTRDBFL, ITTANFLG, &
 & ITTPFLG, ITTFLG, ITTVERCO, ITTLEVID, ITTSURF  
INTEGER(KIND=JPIM) :: ITD, JTD, &
 & ITDSTAT, ITDEVEN1, ITDEVEN2, ITDRDBFL, ITDANFLG, &
 & ITDPFLG, ITDFLG, ITDVERCO, ITDLEVID, ITDSURF  
INTEGER(KIND=JPIM) :: IRH, &
 & IRHSTAT, IRHEVEN1, IRHEVEN2, IRHRDBFL, IRHANFLG, &
 & IRHPFLG, IRHFLG, IRHVERCO, IRHLEVID  
INTEGER(KIND=JPIM) :: IQ , &
 & IQQSTAT, IQQEVEN1, IQQEVEN2, IQQRDBFL, IQQANFLG, &
 & IQQPFLG, IQQFLG, IQQVERCO, IQQLEVID  
INTEGER(KIND=JPIM) :: IAUX, JALL, &
 & IAUSTAT, IAUEVEN1, IAUEVEN2, IAURDBFL, IAUANFLG, &
 & IAUPFLG, IAUFLG  , IAUVERCO, IAULEVID  

INTEGER(KIND=JPIM) :: IBENTRYP(NMXNVO)
INTEGER(KIND=JPIM) :: ISONDE_DB_ENTRY, ICOUNTRY_DB_ENTRY

LOGICAL :: LLFAIL, LLREMOVE, LLDONEBCH, LLDONEBCT
LOGICAL :: LLDD, LLFF, LLU, LLV, LLZ, LLT, LLTd, LLRh, LLQ
LOGICAL :: LL_SONDE_RH_BIAS_FOUND, LL_COUNTRY_RH_BIAS_FOUND
LOGICAL :: LL_SONDE_T_BIAS_FOUND, LL_COUNTRY_T_BIAS_FOUND

CHARACTER (LEN = 8) :: CLSTID
CHARACTER (LEN =19) :: CL_BIAS_PART
character(len=5), save :: CLera40 = 'UNDEF'

REAL(KIND=JPRB) :: ZLAT, ZLON, ZALT, ZPREFL, ZTIMDIF, &
 & ZWEIGHT, &
 & ZQERRFRH, ZQERRFP, ZQERRFT, &
 & ZDUMMY, ZANMOMH, ZBAROMH, ZSOLAR_ANGLE

REAL(KIND=JPRB) :: ZDDPRES, ZDDPRL, ZDIR, &
 & ZDDPERR, ZDDOERR, ZDDFERR, ZDDRERR, &
 & ZDDFGER, ZDDFGCC1, ZDDFGCC2, &
 & ZDDFGDEP, ZDDANDEP  
REAL(KIND=JPRB) :: ZFFPRES, ZFFPRL, ZSPD, &
 & ZFFPERR, ZFFOERR, ZFFFERR, ZFFRERR, &
 & ZFFFGER, ZFFFGCC1, ZFFFGCC2, &
 & ZFFFGDEP, ZFFANDEP  
REAL(KIND=JPRB) :: ZUUPRES, ZUUPRL, ZU, &
 & ZUUOERR, ZUUPERR, ZUUFERR, ZUURERR, &
 & ZUUFGER, ZUUFGCC1, ZUUFGCC2, &
 & ZUUFGDEP, ZUUANDEP  
REAL(KIND=JPRB) :: ZVVPRES, ZVVPRL, ZV, &
 & ZVVOERR, ZVVPERR, ZVVFERR, ZVVRERR, &
 & ZVVFGER, ZVVFGCC1, ZVVFGCC2, &
 & ZVVFGDEP, ZVVANDEP  
REAL(KIND=JPRB) :: ZZZPRES, ZZZPRL, ZZZ  , &
 & ZZZOERR, ZZZPERR, ZZZFERR, ZZZRERR, &
 & ZZZFGER, ZZZFGCC1, ZZZFGCC2, &
 & ZZZFGDEP, ZZZANDEP  
REAL(KIND=JPRB) :: ZTTPRES, ZTTPRL, ZTT  , &
 & ZTTOERR, ZTTPERR, ZTTFERR, ZTTRERR, &
 & ZTTFGER, ZTTFGCC1, ZTTFGCC2, &
 & ZTTFGDEP, ZTTANDEP, ZTTBIAS_COUNTRY, ZTTBIAS_SONDE
REAL(KIND=JPRB) :: ZTDPRES, ZTDPRL, ZTD  , &
 & ZTDOERR, ZTDPERR, ZTDFERR, ZTDRERR, &
 & ZTDFGER, ZTDFGCC1, ZTDFGCC2, &
 & ZTDFGDEP, ZTDANDEP  
REAL(KIND=JPRB) :: ZRHPRES, ZRHPRL, ZRH  , &
 & ZRHOERR, ZRHPERR, ZRHFERR, ZRHRERR, &
 & ZRHFGER, ZRHFGCC1, ZRHFGCC2, &
 & ZRHFGDEP, ZRHANDEP, ZRHBIAS_COUNTRY, ZRHBIAS_SONDE
REAL(KIND=JPRB) :: ZQQPRES, ZQQPRL, ZQ   , &
 & ZQQOERR, ZQQPERR, ZQQFERR, ZQQRERR, &
 & ZQQFGER, ZQQFGCC1, ZQQFGCC2, &
 & ZQQFGDEP, ZQQANDEP  
REAL(KIND=JPRB) :: ZAU, ZAUPRES, ZAUPRL, &
 & ZAUPERR, ZAUOERR, ZAUFERR, ZAURERR, &
 & ZAUFGER, ZAUFGCC1, ZAUFGCC2, &
 & ZAUFGDEP, ZAUANDEP  
REAL(KIND=JPRB) :: ZPPFERR

REAL(KIND=JPRB) :: ZBIASCP(NMXNVO), ZBIASCTO(NMXNVO),ZBIASCTB(NMXNVO)
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"
#include "errstat.intfb.h"
#include "finoerr.intfb.h"
#include "getsete.intfb.h"
#include "hatbiasc.intfb.h"
#include "obinstp.intfb.h"
#include "ppvafl.intfb.h"
#include "prlmchk.intfb.h"
#include "rh2q.intfb.h"
#include "tempbe.intfb.h"
#include "diurnal.intfb.h"
#include "sonde_country_db_match.intfb.h"
#include "new_rs_trh_bias.intfb.h"

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

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

!        1.             PRESET
!                       ------

IF (LHOOK) CALL DR_HOOK('TEMPIN',0,ZHOOK_HANDLE)
ZLAT      = ROBHDR(KTEMP,MDBLAT) * RDEGREES
ZLON      = ROBHDR(KTEMP,MDBLON) * RDEGREES
ZALT      = ROBHDR(KTEMP,MDBALT)
IOBDATE   = ROBHDR(KTEMP,MDBDAT)
IYEAR     = IOBDATE/10000
IMONTH    = IOBDATE/100 - IYEAR*100
IDAY      = IOBDATE - (IYEAR*10000+IMONTH*100)
IOBTIME   = ROBHDR(KTEMP,MDBETM)
IHOUR     = IOBTIME/10000
CLSTID    = TRANSFER(ROBHDR(KTEMP,MDBSID), CLSTID)
ISTID     = 0
READ(CLSTID(1:8),'(A8)') ISTID
!ITYPESOND = NMDI
ITYPESOND = ROBHDR(KTEMP,MDB_SONDE_TYPE_AT_HDR)
IREPST    = ROBHDR(KTEMP,MDBRST)
INOEPLE   = 9


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

!        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(KTEMP,MDB_INSTTYPE_AT_HDR) = INSTYP

!*          2.3         ANEMOMETER/BAROMETER HEIGHT

ZANMOMH  = RMDI
ZBAROMH  = RMDI
IF(KCDTYP == NSHTCD) then
  ZANMOMH  = RSANMOMH
  ZBAROMH  = RSBAROMH
ENDIF
ROBHDR(KTEMP,MDBHOANT) = ZANMOMH
ROBHDR(KTEMP,MDBHOBAT) = ZBAROMH

!*          2.4         GET SOLAR ANGLE

ZSOLAR_ANGLE = RMDI
IF(L_NEW_T_BIAS.OR.L_NEW_RH_BIAS) THEN
  CALL DIURNAL(IMONTH,IDAY,IHOUR,ZLAT,ZLON,ZSOLAR_ANGLE)
endif

!*          2.4         MATCH SONDE CODE AND COUNTRY

ISONDE_DB_ENTRY   = NMDI
ICOUNTRY_DB_ENTRY = NMDI
IF(L_NEW_T_BIAS.OR.L_NEW_RH_BIAS) THEN
  CALL SONDE_COUNTRY_DB_MATCH(CLSTID,ITYPESOND,KCDTYP,ZLAT,ZLON,&
                             &ISONDE_DB_ENTRY,ICOUNTRY_DB_ENTRY  )
endif
!*
!-----------------------------------------------------------------------

!        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       CHECK FOR MISSING ALTITUTE

IF(ZALT == RMDI) THEN
  ROBHDR(KTEMP,MDBREV1) = ZCHEV1( ROBHDR(KTEMP,MDBREV1),NR1EVENT(13))
ENDIF

!*          3.1.1       UPDATE REPORT STATUS

ROBHDR(KTEMP,MDBRST) = IREPST

!*          3.1.2       FAILED REPORT/REMOVED REPORT

IF((LLFAIL .OR. LLREMOVE) .AND. LTOTREM) THEN
  CONTINUE
ELSE

!*          3.2         BODY PARAMETERS

ALL_DATA_LOOP1: DO JALL = MLNKH2B(KTEMP),MLNKH2B(KTEMP+1)-1,INOEPLE
  INOEPL = 0
  LLDD   = .FALSE.
  LLFF   = .FALSE.
  LLU    = .FALSE.
  LLV    = .FALSE.
  LLZ    = .FALSE.
  LLT    = .FALSE.
  LLTd   = .FALSE.
  LLRh   = .FALSE.
  LLQ    = .FALSE.

!*          3.2.1       WE ACCEPT:
!                       Z, T(2m), Td(2m), RH(2m), DD, FF, U(10m), V(10m), Q

  DO WHILE(INOEPL <= INOEPLE) 
  IF(INOEPL == INOEPLE ) THEN
    IF(LLDD .AND. &
     & LLFF .AND. &
     & LLU  .AND. &
     & LLV  .AND. &
     & LLZ  .AND. &
     & LLT  .AND. &
     & LLTd .AND. &
     & LLRh .AND. &
     & LLQ         ) CYCLE ALL_DATA_LOOP1  

    WRITE(NULOUT,'(''TEMPIN; NO. OF ENTRIES PER LEVEL NOT GOOD: '')')
    WRITE(NULOUT,'(''          LLDD, LLFF, LLU, LLV, LLZ,'',&
     & '' LLT, LLTd, LLRh, LLQ: '',9(L1,1X))') &
     & LLDD, LLFF, LLU, LLV, LLZ, LLT, LLTd, LLRh, LLQ  
    CALL ABOR1(' TEMPIN : TOO MANY/NOT ENOUGH ENTRIES ')
  ELSE
    IF(     ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  3)       ) THEN
      LLZ  = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  8) .OR. &
       & ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 10)       ) THEN  
!*          TEMPORARY SOLUTION
      IF(LLT) THEN
        LLTD = .TRUE.
        ROBODY(JALL+INOEPL,MDBVNM) = NVNUMB(  9)
      ELSE
        IF(LLZ) THEN
          LLT = .TRUE.
        ELSE
          LLZ = .TRUE.
          ROBODY(JALL+INOEPL,MDBVNM) = NVNUMB(  3)
        ENDIF
      ENDIF
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  9) .OR. &
       & ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 11)       ) THEN  
      LLTd = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  5)       ) THEN
      LLRh = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  7)       ) THEN
      LLQ  = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 48)       ) THEN
      LLDD = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 49)       ) THEN
      LLFF = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  1) .OR. &
       & ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 56)       ) THEN  
      LLU  = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB(  2) .OR. &
       & ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 57)       ) THEN  
      LLV  = .TRUE.
    ELSEIF(ROBODY(JALL+INOEPL,MDBVNM) == NVNUMB( 63)       ) THEN
      LLQ  = .TRUE.
    ELSE
      IAUX = JALL + INOEPL
      IVNM = ROBODY(IAUX  ,MDBVNM)
      WRITE(NULOUT,'('' TEMPIN; 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)
      IAULEVID= ROBODY(IAUX,MDBTELID)

!*          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 TEMPBE (IAUX    ,&
       & IVNM    ,IAUVERCO,ZAUPRES ,ZAUPRL  ,ZAU     ,&
       & ZAUOERR ,ZAUPERR ,ZAUFERR ,ZAURERR ,&
       & ZAUFGER ,ZAUFGCC1,ZAUFGCC2,&
       & ZAUFGDEP,ZAUANDEP,&
       & IAUSTAT ,IAUEVEN1,IAUEVEN2,IAURDBFL,IAUANFLG,&
       & IAULEVID                                      )  
    ENDIF
  ENDIF

!*          3.2.1.7     GO CHECK IF LEVEL FINISHED:

  3217 CONTINUE
  INOEPL = INOEPL + 1
  ENDDO 
ENDDO ALL_DATA_LOOP1

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

ALL_DATA_LOOP2: DO JALL = MLNKH2B(KTEMP),MLNKH2B(KTEMP+1)-1

!*          3.2.1.1     VERTICAL COORDINATE

  3211 CONTINUE
  IF(ROBODY(JALL  ,MDBPPP) /= RMDI ) THEN
    IF(.NOT.(ROBODY(JALL ,MDBPPP) >= RDWMLIM.AND.&
     & ROBODY(JALL ,MDBPPP) <= RUPMLIM     )) THEN
     CONTINUE
    ELSE
      ROBODY(JALL ,MDBPPP ) = RMDI
    ENDIF
  ENDIF

!*          3.2.1.2     VARIABLE

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

!*          3.2.1.3     ERRORS

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

!*          3.2.3       CLOSE ALL DATA LOOP

ENDDO ALL_DATA_LOOP2

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

!        4.             OBSERVATION BODY (WIND DIRECTION/FORCE)
!                       ---------------------------------------

ZWEIGHT = 1.0_JPRB
ZPREFL  = RMDI

!*          4.1         LOOK FOR DATA

DDFF_DATA_LOOP: DO JDF   = MLNKH2B(KTEMP) , MLNKH2B(KTEMP+1)-1

!*          4.2         WIND DIRECTION

  IF(ROBODY(JDF  ,MDBVNM) == NVNUMB( 48)) THEN
    IDD     = JDF
    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)  
    
!*          4.2.1       VERTICAL COO.

    ZDDPRES  = ROBODY(IDD,MDBPPP  )
    IDDVERCO = ROBODY(IDD,MDBVCO  )
    IDDLEVID = ROBODY(IDD,MDBTELID)
    IF(ZDDPRES  == RMDI    .OR. &
       & IDDVERCO /= NPRESVC .OR. &
       & IDDLEVID == NMDI          ) THEN  
      IDDSTAT = ICHSTAT_REJECT( IDDSTAT )
    ENDIF

!*          4.2.2       VARIABLE

    IF(ROBODY(IDD  ,MDBVAR) /= RMDI ) THEN
      ZDIR    = ROBODY(IDD  ,MDBVAR  )
    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 TEMPBE (IDD     ,&
     & IVNM    ,IDDVERCO,ZDDPRES ,ZDDPRL  ,ZDIR    ,&
     & ZDDOERR ,ZDDPERR ,ZDDFERR ,ZDDRERR ,&
     & ZDDFGER ,ZDDFGCC1,ZDDFGCC2,&
     & ZDDFGDEP,ZDDANDEP,&
     & IDDSTAT ,IDDEVEN1,IDDEVEN2,IDDRDBFL,IDDANFLG,&
     & IDDLEVID                                      )  

!*          4.3         WIND FORCE

  ELSEIF(ROBODY(JDF  ,MDBVNM) == NVNUMB( 49)) THEN
    IFF     = JDF
    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)  

!*          4.3.1       VERTICAL COO.

    ZFFPRES  = ROBODY(IFF,MDBPPP  )
    IFFVERCO = ROBODY(IFF,MDBVCO  )
    IFFLEVID = ROBODY(IFF,MDBTELID)
    IF(ZFFPRES  == RMDI    .OR. &
       & IFFVERCO /= NPRESVC .OR. &
       & IFFLEVID == NMDI          ) THEN  
      IFFSTAT = ICHSTAT_REJECT( IFFSTAT )
    ENDIF

!*          4.3.2       VARIABLE

    IF(ROBODY(IFF  ,MDBVAR) /= RMDI ) THEN
      ZSPD    = ROBODY(IFF  ,MDBVAR  )
    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,IDDFLG,IFFRDBFL)

!*          4.3.5       DEPARTURES

!*          4.3.6       UPDATE BODY ENTRY

    CALL TEMPBE (IFF     ,&
     & IVNM    ,IFFVERCO,ZFFPRES ,ZFFPRL  ,ZSPD    ,&
     & ZFFOERR ,ZFFPERR ,ZFFFERR ,ZFFRERR ,&
     & ZFFFGER ,ZFFFGCC1,ZFFFGCC2,&
     & ZFFFGDEP,ZFFANDEP,&
     & IFFSTAT ,IFFEVEN1,IFFEVEN2,IFFRDBFL,IFFANFLG,&
     & IFFLEVID                                      )  
  ENDIF
ENDDO DDFF_DATA_LOOP
!*
!-----------------------------------------------------------------------

!        5.             OBSERVATION BODY (HEIGHT)
!                       -------------------------

ZWEIGHT = 1.0_JPRB
ZPREFL  = RMDI

!*          5.1         LOOK FOR DATA

HEIGHT_DATA_LOOP: DO JZ = MLNKH2B(KTEMP),MLNKH2B(KTEMP+1)-1
  IF(ROBODY(JZ   ,MDBVNM) == NVNUMB(  3)) THEN
    IZ   = JZ
    IVNM = NVNUMB(  3)

!*          5.1.0       SET/GET

    CALL GETSETE(IZ ,&
     & ZZZPRES,ZZZPRL,ZZZ ,&
     & ZZZFGER,ZZZFGCC1,ZZZFGCC2,&
     & ZZZPERR,ZZZOERR,ZZZFERR,ZZZRERR,&
     & ZZZFGDEP,ZZZANDEP,&
     & IZZSTAT,IZZEVEN1,IZZEVEN2,IZZRDBFL,IZZANFLG,&
     & IZZFLG,IZZPFLG)  

!*          5.1.0       VERTICAL COORDINATE

    IZZVERCO = ROBODY(IZ,MDBVCO  )
    IZZLEVID = ROBODY(IZ,MDBTELID)
    ZZZPRES  = ROBODY(IZ,MDBPPP  )
    IZZPFLG  = IBITS(IZZRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)
    IF(ZZZPRES == RMDI ) THEN
      IZZSTAT = ICHSTAT_REJECT( IZZSTAT )
    ENDIF

!*          4.5.2       VARIABLE

    ZZZ      = ROBODY(IZ,MDBVAR  )
    IF(ZZZ     == RMDI ) THEN
      IZZSTAT = ICHSTAT_REJECT( IZZSTAT )
    ENDIF

!*          4.5.3       ERROR STATISTICS

    IF(ZZZPRES /= RMDI ) THEN
      CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
       & IVNM,IZZSTAT,ZZZPRES,ZZZPRL,&
       & ZZZPERR,ZZZOERR,ZZZFERR,ZWEIGHT)  
    ENDIF

!*          4.5.4       STATUS, EVENTS, FLAGS

    IF(NMKCMVSE(  3,KCDSQNO,KOBSQNO) == 0)          THEN
      IZZSTAT = ICHSTAT_REJECT( IZZSTAT )
    ENDIF
    CALL PPVAFL(IZZPFLG,IZZFLG,IZZRDBFL)

!*          4.5.5       DEPARTURES

!*          4.5.6       UPDATE BODY ENTRY

    CALL TEMPBE (IZ      ,&
     & IVNM    ,IZZVERCO,ZZZPRES ,ZZZPRL  ,ZZZ     ,&
     & ZZZOERR ,ZZZPERR ,ZZZFERR ,ZZZRERR ,&
     & ZZZFGER ,ZZZFGCC1,ZZZFGCC2,&
     & ZZZFGDEP,ZZZANDEP,&
     & IZZSTAT ,IZZEVEN1,IZZEVEN2,IZZRDBFL,IZZANFLG,&
     & IZZLEVID                                      )  
  ENDIF
ENDDO HEIGHT_DATA_LOOP

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

!        6.             OBSERVATION BODY (TEMPERATURE)
!                       ------------------------------

ZWEIGHT = 1.0_JPRB
ZPREFL  = RMDI

!*          6.1         LOOK FOR DATA

TEMPERATURE_DATA_LOOP: DO JT = MLNKH2B(KTEMP),MLNKH2B(KTEMP+1)-1
  IF(ROBODY(JT,MDBVNM) == NVNUMB(  8) .OR. &
     & ROBODY(JT,MDBVNM) == NVNUMB( 10)       )       THEN  
    ITEMP= JT
    IVNM = NVNUMB(  8)

!*          6.1.0       SET/GET

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

!*          6.1.1       VERTICAL COORDINATE

    ITTVERCO = ROBODY(ITEMP,MDBVCO  )
    ITTLEVID = ROBODY(ITEMP,MDBTELID)
    ISURF    = IBITS(ITTLEVID,NPSURBP,NPSUROC)
    IF(ISURF == 1 ) THEN
      IVNM = NVNUMB( 10)
    ENDIF
    ZTTPRES  = ROBODY(ITEMP,MDBPPP  )
    ITTPFLG  = IBITS(ITTRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)
    IF(ZTTPRES == RMDI ) THEN
      ITTSTAT = ICHSTAT_REJECT( ITTSTAT )
    ENDIF

!*          6.1.2       VARIABLE

    ZTT      = ROBODY(ITEMP,MDBVAR  )

!*          6.1.2.0     SET T2M TO MISSING IF PRESSSURE MISSING
!                       (TO EMULATE MAKECMA)

    IF(IVNM == NVNUMB( 10)) THEN
      IF(ZTTPRES == RMDI) THEN
        ZTT = RMDI
      ENDIF
    ENDIF

!*          6.1.2.1     CHECK THE VALUE

    IF(ZTT     == RMDI ) THEN
      ITTSTAT = ICHSTAT_REJECT( ITTSTAT )
    ENDIF

!*          6.1.3       ERROR STATISTICS

    IF(ZTTPRES /= RMDI ) THEN
      CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
       & IVNM,ITTSTAT,ZTTPRES,ZTTPRL,&
       & ZTTPERR,ZTTOERR,ZTTFERR,ZWEIGHT)  
    ENDIF

!*          6.1.4       STATUS, EVENTS, FLAGS

    IF((IVNM == NVNUMB(  8) .AND.NMKCMVSE(  8,KCDSQNO,KOBSQNO) == 0) &
       & .OR. &
       & (IVNM == NVNUMB( 10) .AND.NMKCMVSE( 10,KCDSQNO,KOBSQNO) == 0)) THEN  
      ITTSTAT = ICHSTAT_REJECT( ITTSTAT )
    ENDIF
    CALL PPVAFL(ITTPFLG,ITTFLG,ITTRDBFL)

!*          6.1.5       DEPARTURES

!*          6.1.6       NEW STYLE BIAS CORRECTION

    IF(L_NEW_T_BIAS) THEN
      IF(IVNM == NVNUMB( 8)) THEN
        IF(ZTTPRES /= RMDI .AND. ZTT /= RMDI) THEN
          LL_SONDE_T_BIAS_FOUND   = .false.
          ZTTBIAS_SONDE  = RMDI
          LL_COUNTRY_T_BIAS_FOUND = .false.
          ZTTBIAS_COUNTRY= RMDI
          CL_BIAS_PART = ' '
          IF(     L_NEW_T_BIAS_SOLAR_vs_all_mean  ) THEN
            CL_BIAS_PART = 'SOLAR_VS_ALL_MEAN'
          elseif(L_NEW_T_BIAS_SOLAR_vs_day_mean  ) then
            CL_BIAS_PART = 'SOLAR_VS_DAY_MEAN'
          elseif(L_NEW_T_BIAS_SOLAR_vs_night_m) then
            CL_BIAS_PART = 'SOLAR_VS_NIGHT_MEAN'
          elseif(L_NEW_T_BIAS_all_mean           ) then
            CL_BIAS_PART = 'MEAN_ALL'
          elseif(L_NEW_T_BIAS_day_mean           ) then
            CL_BIAS_PART = 'MEAN_DAY'
          elseif(L_NEW_T_BIAS_night_mean         ) then
            CL_BIAS_PART = 'MEAN_NIGHT'
          endif
          CALL NEW_RS_TRH_BIAS('T',CL_BIAS_PART,ZSOLAR_ANGLE,ZTTPRES,&
                              &LL_SONDE_T_BIAS_FOUND,ISONDE_DB_ENTRY,&
                              &LL_COUNTRY_T_BIAS_FOUND,ICOUNTRY_DB_ENTRY,&
                              &ZTTBIAS_SONDE,ZTTBIAS_COUNTRY)
          IF(LL_SONDE_T_BIAS_FOUND) THEN
            IF(ZTTBIAS_SONDE /= RMDI) THEN
             ZTT = ZTT - ZTTBIAS_SONDE
              ROBODY(ITEMP,MDBTORB) = ZTTBIAS_SONDE
              IEVENTNO = ND2EVENT( 1,KOBSQNO)
              ITTEVEN2 = ICHEV1(ITTEVEN2,IEVENTNO)
            endif
          ELSEIF(LL_COUNTRY_T_BIAS_FOUND) THEN
            IF(ZTTBIAS_COUNTRY /= RMDI) THEN
              ZTT = ZTT - ZTTBIAS_COUNTRY
              ROBODY(ITEMP,MDBTORB) = ZTTBIAS_COUNTRY
              IEVENTNO = ND2EVENT( 1,KOBSQNO)
              ITTEVEN2 = ICHEV1(ITTEVEN2,IEVENTNO)
            endif
          endif
        endif
      endif
    endif

!*          6.1.7       UPDATE BODY ENTRY

    CALL TEMPBE (ITEMP   ,&
     & IVNM    ,ITTVERCO,ZTTPRES ,ZTTPRL  ,ZTT     ,&
     & ZTTOERR ,ZTTPERR ,ZTTFERR ,ZTTRERR ,&
     & ZTTFGER ,ZTTFGCC1,ZTTFGCC2,&
     & ZTTFGDEP,ZTTANDEP,&
     & ITTSTAT ,ITTEVEN1,ITTEVEN2,ITTRDBFL,ITTANFLG,&
     & ITTLEVID                                      )  
  ENDIF
ENDDO TEMPERATURE_DATA_LOOP

!*          6.1.8       UPDATE REPORT EVENT

IF(L_NEW_T_BIAS) THEN
  IEVENTNO = NR2EVENT( 2,KOBSQNO)
  ROBHDR(KTEMP,MDBREV2) = ZCHEV1(ROBHDR(KTEMP,MDBREV2),IEVENTNO)
endif
 
!           6.2            OLD STYLE TEMPERATURE BIAS CORRECTION

IF(LBIASCV)   THEN

  IF(LTBIASC.AND..NOT.LTBIASBUFR)   THEN

!*          6.2.0       PREPARE

    DO JSLEV = 1 , NMXNVO
      IBENTRYP(JSLEV) = NMDI
      ZBIASCP (JSLEV) = RMDI
      ZBIASCTO(JSLEV) = RMDI
      ZBIASCTB(JSLEV) = RMDI
    ENDDO

!*          6.2.1       EXTRACT NECESSSARY PARAMETERS:
!                       1. PRESSURES
!                       2. TEMPERARTURES

    INOBIASCL = 0
    ISTART    = MLNKH2B(KTEMP)
    IEND      = MLNKH2B(KTEMP+1)-1
    ISKIP     = 1
    DO JBODE  = ISTART,IEND,ISKIP
      IF(ROBODY(JBODE,MDBVNM) == NVNUMB( 8).OR.&
         & ROBODY(JBODE,MDBVNM) == NVNUMB(10)     )  THEN  
        INOBIASCL = INOBIASCL + 1
        IBENTRYP(INOBIASCL) = JBODE
        ZBIASCTO(INOBIASCL) = ROBODY(JBODE,MDBVAR)
        ZBIASCP (INOBIASCL) = ROBODY(JBODE,MDBPPP)
      ENDIF
    ENDDO

!*          6.2.2       BIAS CORRECTION (VIA MET. OPS. INTERFACE)

    LLDONEBCT = .FALSE.
    CALL HATBIASC('TEMPR',&
     & LLDONEBCT,INOBIASCL,ZBIASCP,ZBIASCTO,ZBIASCTB,&
     & CLSTID ,IYEAR,IMONTH,IDAY,IHOUR,ZLAT,ZLON,ZALT,ITYPESOND,&
     & ZDUMMY,ZDUMMY,&
     & NMDI,RMDI)  

!*          6.2.3       SPREAD BIAS CORRECTED VALUES BACK

    IF(LLDONEBCT) THEN
      DO JBODR = 1 , INOBIASCL
        IBODP = IBENTRYP(JBODR)
        IF(ZBIASCTB(JBODR) /= RMDI)     THEN
          ROBODY(IBODP,MDBVAR) = ZBIASCTB(JBODR)
          IF(LSTOBIAS) THEN
            IF(CLera40 == 'UNDEF') call getenv('OBPATH',CLera40)
            if (CLera40 == 'era40') then
              ROBODY(IBODP,MDBRER ) = ZBIASCTB(JBODR) - ZBIASCTO(JBODR)
            ENDIF
            ROBODY(IBODP,MDBTORB) = ZBIASCTB(JBODR) - ZBIASCTO(JBODR)
          ENDIF
          IEVENTNO = ND2EVENT( 1,KOBSQNO)
          ROBODY(IBODP,MDBDEV2) = ZCHEV1(ROBODY(IBODP,MDBDEV2),IEVENTNO)
        ENDIF
      ENDDO
    ENDIF
  ENDIF

!*          6.2.4       UPDATE REPORT EVENT 2 (FOR BIAS CORRECTED
!                       VALUES)

  IEVENTNO = NR2EVENT( 2,KOBSQNO)
  ROBHDR(KTEMP,MDBREV2) = ZCHEV1(ROBHDR(KTEMP,MDBREV2),IEVENTNO)
ENDIF

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

!        7.             OBSERVATION BODY (DEW POINT)
!                       ----------------------------

ZWEIGHT = 1.0_JPRB
ZPREFL  = RMDI

!*          7.1         LOOK FOR DATA

DEWPOINT_DATA_LOOP: DO JTD = MLNKH2B(KTEMP),MLNKH2B(KTEMP+1)-1
  IF(ROBODY(JTD,MDBVNM) == NVNUMB(  9) .OR. &
     & ROBODY(JTD,MDBVNM) == NVNUMB( 11)       )       THEN  
    ITD  = JTD
    IVNM = NVNUMB(  9)

!*          7.1.0       SET/GET

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

!*          7.1.1       VERTICAL COORDINATE

    ITDVERCO = ROBODY(ITD,MDBVCO  )
    ITDLEVID = ROBODY(ITD,MDBTELID)
    ISURF    = IBITS(ITDLEVID,NPSURBP,NPSUROC)
    IF(ISURF == 1 ) THEN
      IVNM = NVNUMB( 11)
    ENDIF
    ZTDPRES  = ROBODY(ITD,MDBPPP  )
    ITDPFLG  = IBITS(ITDRDBFL,NCMBPFBP+NCMBFLBP,NCMBFLOC)
    IF(ZTDPRES == RMDI ) THEN
      ITDSTAT = ICHSTAT_REJECT( ITDSTAT )
    ENDIF

!*          7.1.2       VARIABLE

    ZTD      = ROBODY(ITD,MDBVAR  )

!*          7.1.2.0     SET Td2M TO MISSING IF PRESSSURE MISSING
!                       (TO EMULATE MAKECMA)

    IF(IVNM == NVNUMB( 11)) THEN
      IF(ZTDPRES == RMDI) THEN
        ZTD = RMDI
      ENDIF
    ENDIF

!*          7.1.2.1     CHECK THE VALUE

    IF(ZTD     == RMDI ) THEN
      ITDSTAT = ICHSTAT_REJECT( ITDSTAT )
    ENDIF

!*          7.1.3       ERROR STATISTICS

!*          7.1.4       STATUS, EVENTS, FLAGS

    IF((IVNM == NVNUMB(  9) .AND.NMKCMVSE(  9,KCDSQNO,KOBSQNO) == 0) &
       & .OR. &
       & (IVNM == NVNUMB( 11) .AND.NMKCMVSE( 11,KCDSQNO,KOBSQNO) == 0)) THEN  
      ITDSTAT = ICHSTAT_REJECT( ITDSTAT )
    ENDIF
    CALL PPVAFL(ITDPFLG,ITDFLG,ITDRDBFL)

!*          7.1.5       DEPARTURES

!*          7.1.6       UPDATE BODY ENTRY

    CALL TEMPBE (ITD     ,&
     & IVNM    ,ITTVERCO,ZTDPRES ,ZTDPRL  ,ZTD     ,&
     & ZTDOERR ,ZTDPERR ,ZTDFERR ,ZTDRERR ,&
     & ZTDFGER ,ZTDFGCC1,ZTDFGCC2,&
     & ZTDFGDEP,ZTDANDEP,&
     & ITDSTAT ,ITDEVEN1,ITDEVEN2,ITDRDBFL,ITDANFLG,&
     & ITDLEVID                                      )  
  ENDIF
ENDDO DEWPOINT_DATA_LOOP
!*
!*
!-----------------------------------------------------------------------

!        8.             OBSERVATION BODY (WIND)
!                       -----------------------

ZWEIGHT = 1.0_JPRB
ZPREFL  = RMDI

!*          8.1         U/V

WIND_DATA_LOOP: DO JWIND   = MLNKH2B(KTEMP) , MLNKH2B(KTEMP+1)-1 , INOEPLE

!*          8.1.0       GET/CHECK: POINTERS, CONSISTENCY

  IDD     = NMDI
  IFF     = NMDI
  IU      = NMDI
  IV      = NMDI
  ISTART  = JWIND
  IEND    = ISTART + INOEPLE - 1
  DO JLE = ISTART , IEND
    IF(     ROBODY(JLE,MDBVNM) == NVNUMB( 48))        THEN
      IDD = JLE
    ELSEIF(ROBODY(JLE,MDBVNM) == NVNUMB( 49))        THEN
      IFF = JLE
    ELSEIF(ROBODY(JLE,MDBVNM) == NVNUMB(  1) .OR. &
       & ROBODY(JLE,MDBVNM) == NVNUMB( 56)       ) THEN  
      IU  = JLE
    ELSEIF(ROBODY(JLE,MDBVNM) == NVNUMB(  2) .OR. &
       & ROBODY(JLE,MDBVNM) == NVNUMB( 57)       ) THEN  
      IV  = JLE
    ENDIF
  ENDDO

  IF(IDD == NMDI .OR. &
     & IFF == NMDI .OR. &
     & IU  == NMDI .OR. &
     & IV  == NMDI       )    THEN  
    WRITE(NULOUT,'('' TEMPIN; WIND ENTRY MISSING: '',4(I10,1X))') &
     & IDD,IFF,IU,IV  
    CALL ABOR1(' TEMPIN : WIND ENTRY MISSING ')
  ENDIF
 
  ZDDPRES  = ROBODY(IDD,MDBPPP  )
  IDDPFLG  = IBITS(INT(ROBODY(IDD,MDBRDFL)),NCMBPFBP+NCMBFLBP,NCMBFLOC)
  ZDIR     = ROBODY(IDD,MDBVAR  )
  IDDFLG   = IBITS(INT(ROBODY(IDD,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
  ZFFPRES  = ROBODY(IFF,MDBPPP  )
  IFFPFLG  = IBITS(INT(ROBODY(IFF,MDBRDFL)),NCMBPFBP+NCMBFLBP,NCMBFLOC)
  ZSPD     = ROBODY(IFF,MDBVAR  )
  IFFFLG   = IBITS(INT(ROBODY(IFF,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
  IDDVERCO = ROBODY(IDD,MDBVCO  )
  IFFVERCO = ROBODY(IFF,MDBVCO  )
  IDDLEVID = ROBODY(IDD,MDBTELID)
  IFFLEVID = ROBODY(IFF,MDBTELID)
  IF(ZDDPRES  /= ZFFPRES  .AND. &
     & IDDPFLG  /= IFFPFLG  .AND. &
     & IDDVERCO /= IFFVERCO .AND. &
     & IDDLEVID /= IFFLEVID        ) THEN  
    WRITE(NULOUT,'('' TEMPIN; DD AND FF PPP/LEV ID/VER COO MIXUP '')')
    CALL ABOR1(' TEMPIN : DD AND FF MIXUP ')
  ENDIF
  IDDSURF  = IBITS(IDDLEVID,NPSURBP,NPSUROC)
  IFFSURF  = IBITS(IFFLEVID,NPSURBP,NPSUROC)

!*          8.1.1       U

  IVNM    = NVNUMB(  1)
  IF(IDDSURF == 1 ) IVNM    = NVNUMB(  56)

!*          8.1.1.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  = ZDDPRES
  IUUPFLG  = IDDPFLG
  IUULEVID = IDDLEVID
  IUUVERCO = IDDVERCO
  
!*          8.1.1.1     VERTICAL COORDINATE

  IF(ZUUPRES  == RMDI .OR. &
     & IUULEVID == NMDI .OR. &
     & IUUVERCO == NMDI       ) THEN  
    IUUSTAT = ICHSTAT_REJECT( IUUSTAT )
  ENDIF

!*          8.1.1.2     VARIABLE

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

!*          8.1.1.3     ERROR STATISTICS

  IF(ZUUPRES /= RMDI ) THEN
    CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
     & IVNM,IUUSTAT,ZUUPRES,ZUUPRL,&
     & ZUUPERR,ZUUOERR,ZUUFERR,ZWEIGHT)  
  ENDIF

!*          8.1.1.4     STATUS

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

!*          8.1.1.5     DEPARTURES

!*          8.1.1.6     UPDATE/CREATE BODY ENTRY

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

!*          8.1.2       V

  IVNM    = NVNUMB(  2)
  IF(IDDSURF == 1 ) IVNM    = NVNUMB(  57)

!*          8.1.2.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  = ZDDPRES
  IVVPFLG  = IDDPFLG
  IVVLEVID = IDDLEVID
  IVVVERCO = IDDVERCO
  
!*          8.1.2.1     VERTICAL COORDINATE

  IF(ZVVPRES  == RMDI .OR. &
     & IVVLEVID == NMDI .OR. &
     & IVVVERCO == NMDI       ) THEN  
    IVVSTAT = ICHSTAT_REJECT( IVVSTAT )
  ENDIF

!*          8.1.2.2     VARIABLE

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

!*          8.1.2.3     ERROR STATISTICS

  IF(ZVVPRES /= RMDI ) THEN
    CALL ERRSTAT(KOBTYP,KOBSQNO,KCDTYP,KCDSQNO,ZLAT,ZLON,ZTIMDIF,&
     & IVNM,IVVSTAT,ZVVPRES,ZVVPRL,&
     & ZVVPERR,ZVVOERR,ZVVFERR,ZWEIGHT)  
  ENDIF

!*          8.1.2.4     STATUS

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

!*          8.1.2.5     DEPARTURES

!*          8.1.2.6     UPDATE/CREATE BODY ENTRY

  CALL TEMPBE (IV      ,&
   & IVNM    ,NPRESVC ,ZVVPRES ,ZVVPRL  ,ZV      ,&
   & ZVVOERR ,ZVVPERR ,ZVVFERR ,ZVVRERR ,&
   & ZVVFGER ,ZVVFGCC1,ZVVFGCC2,&
   & ZVVFGDEP,ZVVANDEP,&
   & IVVSTAT ,IVVEVEN1,IVVEVEN2,IVVRDBFL,IVVANFLG,&
   & IVVLEVID                                      )  
ENDDO WIND_DATA_LOOP
!*
!-----------------------------------------------------------------------

!        9.             OBSERVATION BODY (HUMIDITY)
!                       ---------------------------

ZWEIGHT = 1.0_JPRB
ZPREFL  = RMDI

!*          9.1         LOOK FOR HUMIDITY

HUMIDITY_DATA_LOOP: DO JHUM = MLNKH2B(KTEMP) , MLNKH2B(KTEMP+1)-1 , INOEPLE

!*          9.1.0       GET/CHECK: POINTERS, CONSISTENCY

  IRH     = NMDI
  IQ      = NMDI
  IZ      = NMDI
  ITEMP   = NMDI
  ITD     = NMDI
  ISTART  = JHUM
  IEND    = ISTART + INOEPLE - 1
  DO JLE = ISTART , IEND
    IF(ROBODY(JLE,MDBVNM) == NVNUMB( 63))        IQ   = JLE
    IF(ROBODY(JLE,MDBVNM) == NVNUMB(  3))        IZ   = JLE
    IF(ROBODY(JLE,MDBVNM) == NVNUMB(  5) .OR. &
     & ROBODY(JLE,MDBVNM) == NVNUMB(  7)       ) IRH  = JLE  
    IF(ROBODY(JLE,MDBVNM) == NVNUMB(  8) .OR. &
     & ROBODY(JLE,MDBVNM) == NVNUMB( 10)       ) ITEMP= JLE  
    IF(ROBODY(JLE,MDBVNM) == NVNUMB(  9) .OR. &
     & ROBODY(JLE,MDBVNM) == NVNUMB( 11)       ) ITD  = JLE  
  ENDDO

  IF(IQ     == NMDI .OR. &
     & IRH    == NMDI .OR. &
     & ITEMP  == NMDI .OR. &
     & IZ  == NMDI .OR. &
     & ITD == NMDI       )    THEN  
    WRITE(NULOUT,'('' TEMPIN; HUMIDITY ENTRY MISSING: '',5(I10,1X))') &
     & IQ,IRH,ITEMP,ITD,IZ  
    CALL ABOR1(' TEMPIN : HUMIDITY ENTRY MISSING ')
  ENDIF

  ZTTPRES  = ROBODY(ITEMP,MDBPPP  )
  ITTPFLG  = IBITS(INT(ROBODY(ITEMP,MDBRDFL)),NCMBPFBP+NCMBFLBP,NCMBFLOC)
  ZTT      = ROBODY(ITEMP,MDBVAR  )
  ITTFLG   = IBITS(INT(ROBODY(ITEMP,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
  ITTVERCO = ROBODY(ITEMP,MDBVCO  )
  ITTLEVID = ROBODY(ITEMP,MDBTELID)

  ZTDPRES  = ROBODY(ITD,MDBPPP  )
  ITDPFLG  = IBITS(INT(ROBODY(ITD,MDBRDFL)),NCMBPFBP+NCMBFLBP,NCMBFLOC)
  ZTD      = ROBODY(ITD,MDBVAR  )
  ITDFLG   = IBITS(INT(ROBODY(ITD,MDBRDFL)),NCMBVFBP+NCMBFLBP,NCMBFLOC)
  ITDVERCO = ROBODY(ITD,MDBVCO  )
  ITDLEVID = ROBODY(ITD,MDBTELID)

  IF(ZTTPRES  /= ZTDPRES  .AND. &
     & ITTPFLG  /= ITDPFLG  .AND. &
     & ITTVERCO /= ITDVERCO .AND. &
     & ITTLEVID /= ITDLEVID        ) THEN  
    WRITE(NULOUT,'('' TEMPIN; T AND Td PPP/LEV ID/VER COO MIXUP '')')
    CALL ABOR1(' TEMPIN : T AND Td MIXUP ')
  ENDIF
  ITTSURF  = IBITS(ITTLEVID,NPSURBP,NPSUROC)
  ITDSURF  = IBITS(ITDLEVID,NPSURBP,NPSUROC)

!*          9.1.1       RELATIVE HUMIDITY

  IF(ITTSURF == 0 .AND. &
   & ROBODY(ITEMP,MDBVNM) == NVNUMB(  8)) IVNM    = NVNUMB(   5)  
  IF(ITTSURF == 1 .AND. &
   & ROBODY(ITEMP,MDBVNM) == NVNUMB( 10)) IVNM    = NVNUMB(   7)  

!*          9.1.1.0     SET/GET

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

  ZRHPRES  = ZTTPRES
  IRHPFLG  = ITTPFLG
  IRHLEVID = ITTLEVID
  IRHVERCO = ITTVERCO
  IRHFLG   = MAX(ITTFLG,ITDFLG)
  
!*          9.1.1.1     VERTICAL COORDINATE

  IF(ZRHPRES  == RMDI .OR. &
     & IRHLEVID == NMDI .OR. &
     & IRHVERCO == NMDI       ) THEN  
    IRHSTAT = ICHSTAT_REJECT( IRHSTAT )
  ENDIF

!*          9.1.1.2     VARIABLE

  IF(ZTT /= RMDI .AND. ZTD /= RMDI ) THEN
    IF(IRHFLG < NFLLIMOP(2))           THEN
      LLDONEBCH= .FALSE.
      ZRH      = FOEEWMO( ZTD ) / FOEEWMO( ZTT )

!*          9.1.1.2.1   OLD BIAS CORRECTION OF Vaisala RS80A SONDES

      IF(LHBIASC)   THEN
        INOBIASCL= 0
        CALL HATBIASC('HUMID',&
         & LLDONEBCH,INOBIASCL,ZBIASCP,ZBIASCTO,ZBIASCTB,&
         & CLSTID,IYEAR,IMONTH,IDAY,IHOUR,ZLAT,ZLON,ZALT,ITYPESOND,&
         & ZTT ,ZRH,&
         & NMDI,RMDI)  
      ENDIF

!*          9.1.1.2.2   NEW BIAS CORRECTION

      IF(L_NEW_RH_BIAS) THEN
        IF(IVNM == NVNUMB( 5)) THEN
          LL_SONDE_RH_BIAS_FOUND   = .false.
          ZRHBIAS_SONDE  = RMDI
          LL_COUNTRY_RH_BIAS_FOUND = .false.
          ZRHBIAS_COUNTRY= RMDI
          CL_BIAS_PART = ' '
          IF(     L_NEW_RH_BIAS_SOLAR_vs_all_mean  ) THEN
            CL_BIAS_PART = 'SOLAR_VS_ALL_MEAN'
          elseif(L_NEW_RH_BIAS_SOLAR_vs_day_mean  ) THEN
            CL_BIAS_PART = 'SOLAR_VS_DAY_MEAN'
          elseif(L_NEW_RH_BIAS_SOLAR_vs_night_m) THEN
            CL_BIAS_PART = 'SOLAR_VS_NIGHT_MEAN'
          elseif(L_NEW_RH_BIAS_all_mean           ) then
            CL_BIAS_PART = 'MEAN_ALL'
          elseif(L_NEW_RH_BIAS_day_mean           ) then
            CL_BIAS_PART = 'MEAN_DAY'
          elseif(L_NEW_RH_BIAS_night_mean         ) then
            CL_BIAS_PART = 'MEAN_NIGHT'
          endif
          CALL NEW_RS_TRH_BIAS('RH',CL_BIAS_PART,ZSOLAR_ANGLE,ZRHPRES,&
                              &LL_SONDE_RH_BIAS_FOUND,ISONDE_DB_ENTRY,&
                              &LL_COUNTRY_RH_BIAS_FOUND,ICOUNTRY_DB_ENTRY,&
                              &ZRHBIAS_SONDE,ZRHBIAS_COUNTRY)
          IF(LL_SONDE_RH_BIAS_FOUND) THEN
            IF(ZRHBIAS_SONDE /= RMDI) THEN
              ZRH = ZRH - ZRHBIAS_SONDE
              ZRH = MIN(100.0_JPRB,MAX(ZRH,0.0001_JPRB))
              ROBODY(IRH,MDBTORB) = ZRHBIAS_SONDE
              IEVENTNO = ND2EVENT( 1,KOBSQNO)
              IRHEVEN2 = ICHEV1(IRHEVEN2,IEVENTNO)
            ENDIF
          ELSEIF(LL_COUNTRY_RH_BIAS_FOUND) THEN
            IF(ZRHBIAS_COUNTRY /= RMDI) THEN
              ZRH = ZRH - ZRHBIAS_COUNTRY
              ZRH = MIN(100.0_JPRB,MAX(ZRH,0.0001_JPRB))
              ROBODY(IRH,MDBTORB) = ZRHBIAS_COUNTRY
              IEVENTNO = ND2EVENT( 1,KOBSQNO)
              IRHEVEN2 = ICHEV1(IRHEVEN2,IEVENTNO)
            ENDIF
          ENDIF
        ENDIF
      ENDIF

!*          9.1.1.3     ERROR STATISTICS

!*          9.1.1.3.1   PERSISTENCE ERROR (THERE IS NOT ONE)

!*          9.1.1.3.2   OBSERVATION ERROR

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

!*          9.1.1.3.3   FINAL OBSERVATION ERROR

      ZRHFERR = ZRHOERR
    ENDIF
  ENDIF

!*          9.1.1.4     STATUS, EVENTS, FLAGS

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

!*          9.1.1.5     DEPARTURES

!*          9.1.1.6     CREATE BODY ENTRY

  IDATEV2 = 0
  IF(LLDONEBCH) THEN
    IEVENTNO = ND2EVENT( 1,KOBSQNO)
    IDATEV2 = ICHEV1(IDATEV2,IEVENTNO)
  ENDIF
  CALL TEMPBE (IRH     ,&
   & IVNM    ,NPRESVC ,ZRHPRES ,ZRHPRL  ,ZRH     ,&
   & ZRHOERR ,ZRHPERR ,ZRHFERR ,ZRHRERR ,&
   & ZRHFGER ,ZRHFGCC1,ZRHFGCC2,&
   & ZRHFGDEP,ZRHANDEP,&
   & IRHSTAT ,IRHEVEN1,IRHEVEN2,IRHRDBFL,IRHANFLG,&
   & IRHLEVID                                      )  

!*          9.1.2       SPECIFIC HUMIDITY

  IVNM  =  NVNUMB(  63)

!*          9.1.2.0     SET/GET

  CALL GETSETE(IQ   ,&
   & ZQQPRES,ZQQPRL,ZQ   ,&
   & ZQQFGER,ZQQFGCC1,ZQQFGCC2,&
   & ZQQPERR,ZQQOERR,ZQQFERR,ZQQRERR,&
   & ZQQFGDEP,ZQQANDEP,&
   & IQQSTAT,IQQEVEN1,IQQEVEN2,IQQRDBFL,IQQANFLG,&
   & IQQFLG,IQQPFLG)  

  ZQQPRES  = ZRHPRES
  IQQFLG   = MAX(IRHFLG,IRHPFLG)
  IQQPFLG  = IRHPFLG
  IQQLEVID = IRHLEVID
  IQQVERCO = IRHVERCO

  ZZZFERR  = ROBODY(IZ ,MDBFOE)
  IF(ZZZFERR /= RMDI ) THEN
    ZPPFERR = ZZZFERR * RPAPM
  ELSE
    ZPPFERR = RMDI
  ENDIF

  ZQERRFRH = RMDI
  ZQERRFP  = RMDI
  ZQERRFT  = RMDI
  
!*          9.1.2.1     VERTICAL COORDINATE

  IF(ZQQPRES  == RMDI .OR. &
     & IQQLEVID == NMDI .OR. &
     & IQQVERCO == NMDI       ) THEN  
    IQQSTAT = ICHSTAT_REJECT( IQQSTAT )
  ENDIF

!*          9.1.2.2     VARIABLE

  IF(ZQQPRES <= 0.0_JPRB)          THEN
    IQQSTAT = ICHSTAT_REJECT( IQQSTAT )
    CYCLE HUMIDITY_DATA_LOOP
  ENDIF

  IF((ZTT     == RMDI.OR.(LQERRFT .AND.ZTTFERR  == RMDI)) .OR. &
     & (ZRH     == RMDI.OR.(LQERRFRH.AND.ZRHFERR  == RMDI)) .OR. &
     & (ZQQPRES == RMDI.OR.(LQERRFP .AND.ZPPFERR  == RMDI))       ) THEN  
    IQQSTAT = ICHSTAT_REJECT( IQQSTAT )
    CYCLE HUMIDITY_DATA_LOOP
  ENDIF

  CALL RH2Q(ZRH,ZRHFERR ,ZTT     ,ZTTFERR ,ZQQPRES,ZPPFERR,&
   & ZQ ,ZQERRFRH,ZQERRFP,ZQERRFT                    )  

!*          9.1.2.3     ERROR STATISTICS

!*          9.1.2.3.1   PERSISTENCE ERROR (THERE IS NOT ONE)

!*          9.1.2.3.2   OBSERVATION ERROR

  IF(LQERRFRH.OR.LQERRFP .OR.LQERRFT      )                      THEN
    ZQQOERR = 0.0_JPRB
    IF(LQERRFRH)      THEN
      ZQQOERR = ZQQOERR + ZQERRFRH
    ENDIF
    IF(LQERRFP )      THEN
      ZQQOERR = ZQQOERR + ZQERRFP
    ENDIF
    IF(LQERRFT )      THEN
      ZQQOERR = ZQQOERR + ZQERRFT
    ENDIF
  ELSE
    ZQQOERR = RMDI
  ENDIF

!*          9.1.2.3.3   FINAL OBSERVATION ERROR

  ZQQFERR = RMDI
  CALL FINOERR(ZQQPERR,ZQQOERR,ZQQFERR)

!*          9.1.2.4     STATUS, EVENTS, FLAGS

  IF(NMKCMVSE( 63,KCDSQNO,KOBSQNO) == 0)          THEN
    IQQSTAT = ICHSTAT_REJECT( IQQSTAT )
  ENDIF
  CALL PPVAFL(IQQPFLG,IQQFLG,IQQRDBFL)

!*          9.1.2.5     DEPARTURES

!*          9.1.2.6     CREATE BODY ENTRY

  CALL TEMPBE (IQ      ,&
   & IVNM    ,NPRESVC ,ZQQPRES ,ZQQPRL  ,ZQ      ,&
   & ZQQOERR ,ZQQPERR ,ZQQFERR ,ZQQRERR ,&
   & ZQQFGER ,ZQQFGCC1,ZQQFGCC2,&
   & ZQQFGDEP,ZQQANDEP,&
   & IQQSTAT ,IQQEVEN1,IQQEVEN2,IQQRDBFL,IQQANFLG,&
   & IQQLEVID                                      )  
ENDDO HUMIDITY_DATA_LOOP

!*          9.1.3       UPDATE REPORT EVENT

IF(L_NEW_RH_BIAS) THEN
  IEVENTNO = NR2EVENT( 3,KOBSQNO)
  ROBHDR(KTEMP,MDBREV2) = ZCHEV1(ROBHDR(KTEMP,MDBREV2),IEVENTNO)
endif
!*
!-----------------------------------------------------------------------

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

11 CONTINUE

!*          11.1         UPDATE HEADER PARAMETERS (IF ANY)

!*          11.2         CMA REPORT CREATED SWITCH

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

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

ENDIF     !((LLFAIL .OR. LLREMOVE) .AND. LTOTREM)

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

!        13.            RETURN
!                       ------

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