SUBROUTINE SUFPWFPDS

! Purpose :
! -------
!   *SUFPWFPDS* : Set Up Weights Full-Pos Descriptors : to initialise
!               control keys for horizontal interpolations.

! Interface :
! ---------
!   None.

! Externals :
! ---------
!   ABOR1

! Method :
! ------
!   To control allocation and use of subsequent arrays.

! Reference :
! ---------
!   Full-Pos documentation.

! Author :
! ------
!   08-Apr-1994 Ryad El Khatib   *METEO-FRANCE*

! Modifications :
! -------------
!   13-Aug-1996 R. El Khatib Cleaning
!   28-Aug-1998 R. El Khatib LFPOSHOR, LFPOSBUF ; no LSM if adiabatic pp
!   26-Jul-1999 D. Giard     add MWSTD4,MWLSM4 for bilinear interp.
!   01-Mar-2000 J.Boutahar   Search of the nearest point as an alternative
!                            Treatment of isolated lakes
!   14-Jun-2001 R. El Khatib LFPLAKE => NFPLAKE
!   01-Oct-2003 M.Hamrud     Cleaning
!   19-May-2005 R. El Khatib Substantial rewrite
! End Modifications
!-----------------------------------------------------------------------------

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

USE YOMLUN    , ONLY : NULOUT
USE YOMFPC    , ONLY : NFP2DF   ,NFPPHY   ,NFPCFU   ,NFPXFU   ,NFP3H    ,&
 & NFP3S    ,NFPINDYN ,NFPINPHY ,NFPLAKE  ,LTRACEFP ,NFPMASK
USE YOMFPG    , ONLY : LFPOSHOR, LFPOSBUF
USE YOEPHY    , ONLY : LEPHYS
USE YOMPHY    , ONLY : LMPHYS
USE YOMWFPDS  , ONLY : LQUAD    ,LWSTD04  ,LWLAN04  ,LWSEA04  ,LWSTD12  ,&
 & LWLAN12  ,LWSEA12  ,LWIC     ,NFPWIDE

IMPLICIT NONE

LOGICAL :: LLSURF, LLSTD00, LLLAN00, LLSEA00

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

IF (LHOOK) CALL DR_HOOK('SUFPWFPDS',0,ZHOOK_HANDLE)


! 1. Surface postprocessing needed
!    -----------------------------

LLSURF = (LMPHYS.OR.LEPHYS) .AND. LFPOSHOR .AND. &
 &       (NFP3H+NFP3S+NFP2DF+NFPPHY+NFPCFU+NFPXFU > 0)


! 2. Weights
!    -------

LLSTD00 = LFPOSBUF .AND. (NFPINPHY ==  0 .OR. NFPINDYN ==  0)
LWSTD04 = LFPOSBUF .AND. (NFPINPHY ==  4 .OR. NFPINDYN ==  4)
LWSTD12 = LFPOSBUF .AND. (NFPINPHY == 12 .OR. NFPINDYN == 12)
LLLAN00 = LFPOSBUF .AND. (NFPMASK >= 1) .AND. (NFPINPHY ==  0) .AND. LLSURF
LWLAN04 = LFPOSBUF .AND. (NFPMASK >= 1) .AND. (NFPINPHY ==  4) .AND. LLSURF
LWLAN12 = LFPOSBUF .AND. (NFPMASK >= 1) .AND. (NFPINPHY == 12) .AND. LLSURF
LLSEA00 = LFPOSBUF .AND. (NFPMASK >= 2) .AND. (NFPINPHY ==  0) .AND. LLSURF
LWSEA04 = LFPOSBUF .AND. (NFPMASK >= 2) .AND. (NFPINPHY ==  4) .AND. LLSURF
LWSEA12 = LFPOSBUF .AND. (NFPMASK >= 2) .AND. (NFPINPHY == 12) .AND. LLSURF

! Special case for nearest point :
! Get one, anyhow (and then the smallest one)
LWSTD04 = LWSTD04 .OR. (LLSTD00 .AND. .NOT.LWSTD12)
LWLAN04 = LWLAN04 .OR. (LLLAN00 .AND. .NOT.LWLAN12)
LWLAN04 = LWLAN04 .OR. (LLSEA00 .AND. .NOT.LWSEA12)


! 3. Halo width
!    ----------

IF (LFPOSBUF) THEN
  NFPWIDE=3
ELSE
  NFPWIDE=0
ENDIF

! 4. Lake/Island index
!    -----------------

LWIC = (NFPLAKE /= 0) .AND. LFPOSHOR
! Computed with quadratic weights, to minimize the number of isolated point
LWLAN12 = LWLAN12 .OR. LWIC
LWSEA12 = LWSEA12 .OR. (LWIC .AND. NFPMASK >= 2)


! 5. Miscellaneous
!    -------------

LQUAD=LWSTD12 .OR. LWLAN12 .OR. LWSEA12


! 6. Print out
!    ---------

IF(LTRACEFP) THEN
  WRITE(UNIT=NULOUT,FMT='('' MODULE YOMWFPDS'')')
  WRITE(UNIT=NULOUT,FMT='('' LWSTD04 = '',L2,'' LWLAN04 = '',L2, &
   & '' LWSEA04 = '',L2)') LWSTD04, LWLAN04, LWSEA04
  WRITE(UNIT=NULOUT,FMT='('' LWSTD12 = '',L2,'' LWLAN12 = '',L2, &
   & '' LWSEA12 = '',L2)') LWSTD12, LWLAN12, LWSEA12
  WRITE(UNIT=NULOUT,FMT='('' LQUAD = '',L2,'' LWIC = '',L2,'' NFPWIDE = '', &
   & I2)') LQUAD, LWIC, NFPWIDE
ENDIF


IF (LHOOK) CALL DR_HOOK('SUFPWFPDS',1,ZHOOK_HANDLE)

END SUBROUTINE SUFPWFPDS
