SUBROUTINE PREINTRAD(KDLEN,KLEN,KSET,PTS,PWS,PSN)

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

!     ERIK ANDERSSON          01/04/99       ECMWF

!     PURPOSE
!     -------

!        PREINTRAD PREPARES INTERPOLATION FOR ONE SET OF OBSERVATIONS.

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

!        CALL PREINTRAD(KDLEN,KLEN,KSET,PTS,PWS,PSN)

!        Where KDLEN   = First dimension (observations)
!              KLEN    = Actual number of observations
!              KSET    = Number (numero) of the obs set to be treated
!              PTS    = Surface skin temperature
!              PWS    = Soil wetness
!              PSN    = Snow depth

!        PREINTRAD IS CALLED FROM HOPAD

!**   METHOD
!     ------

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

!**   MODIFICATIONS
!     -------------
!     E.Andersson 990104 : Original
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE GOMS_MIX     , ONLY : YGOMS
USE YOMOBSET , ONLY : MTYPOB
USE YOMDB

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KDLEN
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSET 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTS(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWS(KDLEN) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSN(KDLEN) 
INTEGER(KIND=JPIM) :: IOBSTYPE,IPOSM,ILEN,JOBS
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "openmp_obs.h"

!*
!        1.       PREPARATION OF INTERPOLATION
!                 ----------------------------
IF (LHOOK) CALL DR_HOOK('PREINTRAD',0,ZHOOK_HANDLE)
ILEN     = KLEN
IOBSTYPE = MOD(MTYPOB(KSET),100)

DO JOBS = 1,ILEN
  IPOSM   = ROBHDR(JOBS,MDB_MAPOMM_AT_INDEX)
  YGOMS(IPOSM)%TS = YGOMS(IPOSM)%TS+PTS(JOBS)
  YGOMS(IPOSM)%WS = YGOMS(IPOSM)%WS+PWS(JOBS)/1000._JPRB
  YGOMS(IPOSM)%SN = YGOMS(IPOSM)%SN+PSN(JOBS)/1000._JPRB
  PTS(JOBS) = 0.0_JPRB
  PWS(JOBS) = 0.0_JPRB
  PSN(JOBS) = 0.0_JPRB
ENDDO

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

!        9.       RETURN
!                 ------

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