SUBROUTINE PREINTR(KDLEN,KLEN,KSET,PLS5,PCI5,PAL5,PTS5,PWS5,PSN5)

!****  PREINTR  - PREPARATION FOR THE RADIANCE INTERPOLATION

!     ERIK ANDERSSON          01/04/99       ECMWF

!     PURPOSE
!     -------

!        PREINTR PREPARES INTERPOLATION FOR ONE SET OF OBSERVATIONS.

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

!        CALL PREINTR(KDLEN,KLEN,KSET,PLS5,PCI5,PAL5,PTS5,PWS5,PSN5)

!        Where KDLEN   = First dimension (observations)
!              KLEN    = Actual number of observations
!              KSET    = Number (numero) of the obs set to be treated
!              PLS5    = Land/Sea Mask
!              PCI5    = Sea-ice fraction
!              PAL5    = Albedo
!              PTS5    = Surface skin temperature
!              PWS5    = Soil wetness
!              PSN5    = Snow depth

!        PREINTR IS CALLED FROM HOP

!**   METHOD
!     ------

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

!**   MODIFICATIONS
!     -------------
!     E.Andersson 990104 : Original
!     P.Viterbo   990901 : Sea-ice fraction
!     C.Payan     0505?? : *GOMEC%ECCI controlled by NUSE_ECCI key
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMOBSET , ONLY : MTYPOB
USE YOMVRTL  , ONLY : LTLINT   ,LOBSTL
USE YOMDB
USE GOMS_MIX     , ONLY : YGOMS,YGOMS5,YGOMEC,NUSE_ECCI

IMPLICIT NONE

INTERFACE
#include "surf_inq.h"
END INTERFACE

INTEGER(KIND=JPIM),INTENT(IN)    :: KDLEN
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSET 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLS5(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCI5(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PAL5(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTS5(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWS5(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSN5(KDLEN) 
INTEGER(KIND=JPIM) :: IOBSTYPE,IPOSM,ILEN,JOBS
REAL(KIND=JPRB) :: ZRTFREEZSICE
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "openmp_obs.h"

!*
!        1.       PREPARATION OF INTERPOLATION
!                 ----------------------------

IF (LHOOK) CALL DR_HOOK('PREINTR',0,ZHOOK_HANDLE)
CALL SURF_INQ(PRTFREEZSICE=ZRTFREEZSICE)
ILEN     = KLEN
IOBSTYPE = MOD(MTYPOB(KSET),100)

DO JOBS = 1,ILEN
  IPOSM   = ROBHDR(JOBS,MDB_MAPOMM_AT_INDEX)
  IF(LTLINT .AND. LOBSTL) THEN
    PTS5(JOBS) = YGOMS5(IPOSM)%TS
    PWS5(JOBS) = YGOMS5(IPOSM)%WS/1000._JPRB
    PSN5(JOBS) = YGOMS5(IPOSM)%SN/1000._JPRB
  ELSE
    PTS5(JOBS) = YGOMS(IPOSM)%TS
    PWS5(JOBS) = YGOMS(IPOSM)%WS/1000._JPRB
    PSN5(JOBS) = YGOMS(IPOSM)%SN/1000._JPRB
  ENDIF
  PLS5(JOBS) = YGOMEC(IPOSM)%ECLSMA
  PAL5(JOBS) = YGOMEC(IPOSM)%ECALBE
  IF (NUSE_ECCI == 1) THEN
    PCI5(JOBS)=YGOMEC(IPOSM)%ECCI
  ELSE
    IF (PTS5(JOBS) < ZRTFREEZSICE) THEN
      PCI5(JOBS)=1.
    ELSE
      PCI5(JOBS)=0.
    ENDIF
  ENDIF
ENDDO

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

!        9.       RETURN
!                 ------

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