SUBROUTINE SUHOW2(KDGSA,KDGEN,KFRSTLOFF,PLATIN,&
 & KBINL,KLEN,KLA,&
 & PDLAT,PDLO,PDLO1,PDLO2,PDLO3,&
 & PWXX)  

!**** *SUHOW2* - Compute the weights of nearest points.
!****
!****            No land/sea/ice mask is involved here.

!     Purpose.
!     -------
!       Computes the weights for 12 points interpolations or
!       bilinear interpolations for FULL-POS fields.
!       Numbering of the points (I is the interpolation point):
!                     13       5       6      14

!                      7       1       2       8
!                                 (I)
!                      9       3       4      10

!                     15      11      12      16
!       Points number 1 to 12 are used if 12 points interpolations.
!       Points number 1 to 4 are used if bilinear interpolations.
!       Storage of weights.

!       For distributed memory SUHOW2 is executed locally on each processor
!       (iproca,iprocb).
!       Abbreviation DM-global means 'variable global for all processors'.
!       Abbreviation DM-local means 'variable local for each processor
!        iproca and iprocb'.

!**   Interface.
!**   ---------
!**   CALL SUHOW2(...)
!**
!        Explicit arguments :
!        --------------------

!     INPUT:
!      KDGSA     : Lower DM-locally numbered latitude 'jgl' involved.
!                  (DM-local).
!      KDGEN     : Upper DM-locally numbered latitude 'jgl' involved.
!                  (DM-local).
!      KFRSTLOFF : Difference 'DM-global numbering of latitudes' -
!                  'DM-local numbering of latitudes'
!                  KFRSTLOFF=0 if not distributed memory.
!                  (DM-local).
!      PLATIN    : Gaussian/Lobatto latitudes.
!                  (DM-global, but only elements KDGSA+KFRSTLOFF to
!                  KDGEN+KFRSTLOFF are provided here).
!      KBINL     : Options for choice of interpolations:
!                  = 12 ==> 12 points interpolation
!                  =  4 ==> bilinear interpolation
!                  (DM-global).
!      KLEN      : Length of output vector, to which data are interpolated.
!                  (DM-local). 
!      KLA       : Latitude index of the point numbered 1
!                  (DM-local).
!      PDLAT     : Meridian linear weight.
!                  (DM-local).
!      PDLO      : Zonal linear weight for the latitude of point 5.
!                  (DM-local).
!      PDLO1     : Zonal linear weight for the latitude of point 1.
!                  (DM-local).
!      PDLO2     : Zonal linear weight for the latitude of point 3.
!                  (DM-local).
!      PDLO3     : Zonal linear weight for the latitude of point 11.
!                  (DM-local).

!     OUTPUT:
!      PWXX      : Weights array.
!                  (DM-local).

!        Implicit arguments :
!        --------------------
!        none

!     Method.
!     -------
!        See documentation about FULL-POS.

!     Externals.
!     ----------

!        No external.
!        Called by CPCLIMO and SUFPWFPBUF.

!     Reference.
!     ----------

!     Author.
!     -------
!     Author : K. YESSAD after routines SUHOW and LASCAW.
!     Date   : MARCH 1997.

!     Modifications
!     -------------
!        K.YESSAD : (AUGUST 1997):
!          - cleaning for cy18: corrections of false comments.
!        Modified 98-08-10 by K. YESSAD: removal of LRPOLE option.
!         -> dummy arguments LDPOLMODEL,LDPOLFPOS become always .false. and
!            disappear, dummy argument KDGLG becomes useless and disappears.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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

IMPLICIT NONE

!     DUMMY:
INTEGER(KIND=JPIM),INTENT(IN)    :: KDGSA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDGEN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFRSTLOFF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEN 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLATIN(KDGSA+KFRSTLOFF:KDGEN+KFRSTLOFF) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KBINL 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLA(KLEN) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLAT(KLEN) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO(KLEN) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO1(KLEN) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO2(KLEN) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO3(KLEN) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWXX(KLEN,KBINL) 
INTEGER(KIND=JPIM) :: ILA1G, ILA2G, ILA3G, ILAG, JLEN

REAL(KIND=JPRB) :: ZCXN, ZCXNN, ZCXS, ZCXSS, ZCY, ZDLAT, ZDLO1,&
 & ZDLO2, ZDY, ZDY10, ZDY21, ZDY32, ZWXN, ZWXN0, &
 & ZWXN1, ZWXN2, ZWXN3, ZWXNN, ZWXS, ZWXS0, &
 & ZWXS1, ZWXS2, ZWXS3, ZWXSS, ZWY, ZWY0, ZWY1, &
 & ZWY2, ZWY3  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*       1. WEIGHTS FOR BILINEAR INTERPOLATION.
!           -----------------------------------

IF (LHOOK) CALL DR_HOOK('SUHOW2',0,ZHOOK_HANDLE)
IF (KBINL == 4) THEN

  DO JLEN = 1,KLEN

    ZWY=PDLAT(JLEN)
    ZCY=1.0_JPRB-PDLAT(JLEN)

    ZWXN=PDLO1(JLEN)
    ZCXN=1.0_JPRB-PDLO1(JLEN)

    ZWXS=PDLO2(JLEN)
    ZCXS=1.0_JPRB-PDLO2(JLEN)

    PWXX(JLEN,1) = ZCXN*ZCY
    PWXX(JLEN,2) = ZWXN*ZCY
    PWXX(JLEN,3) = ZCXS*ZWY
    PWXX(JLEN,4) = ZWXS*ZWY

  ENDDO

ENDIF

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

!*       2. WEIGHTS FOR 12 POINTS INTERPOLATION. 
!           ------------------------------------

IF (KBINL == 12) THEN

  DO JLEN = 1,KLEN

    ILA1G=KLA(JLEN)+KFRSTLOFF
    ILAG =ILA1G-1
    ILA2G=ILA1G+1
    ILA3G=ILA1G+2

    ZDLAT = PDLAT(JLEN)
    ZDY   = ZDLAT*(PLATIN(ILA2G)-PLATIN(ILA1G))
    ZDY10 = PLATIN(ILA1G)-PLATIN(ILAG)
    ZDY21 = PLATIN(ILA2G)-PLATIN(ILA1G)
    ZDY32 = PLATIN(ILA3G)-PLATIN(ILA2G)

!*         -- L - polynom in x- direction; northern parallel

    ZDLO1 = PDLO1(JLEN)
    ZWXN3 = ((1.0_JPRB+ZDLO1)*(ZDLO1)*(ZDLO1-1.0_JPRB))/6._JPRB
    ZWXN2 = - ((1.0_JPRB+ZDLO1)*(ZDLO1)*(ZDLO1-2.0_JPRB))/2.0_JPRB
    ZWXN1 = ((1.0_JPRB+ZDLO1)*(ZDLO1-1.0_JPRB)*(ZDLO1-2.0_JPRB))/2.0_JPRB
    ZWXN0 = 1.0_JPRB-ZWXN1-ZWXN2-ZWXN3

!*         -- L - polynom in x- direction; southern parallel

    ZDLO2 = PDLO2(JLEN)
    ZWXS3 = ((1.0_JPRB+ZDLO2)*(ZDLO2)*(ZDLO2-1.0_JPRB))/6._JPRB
    ZWXS2 = - ((1.0_JPRB+ZDLO2)*(ZDLO2)*(ZDLO2-2.0_JPRB))/2.0_JPRB
    ZWXS1 = ((1.0_JPRB+ZDLO2)*(ZDLO2-1.0_JPRB)*(ZDLO2-2.0_JPRB))/2.0_JPRB
    ZWXS0 = 1.0_JPRB-ZWXS1-ZWXS2-ZWXS3

!*         -- L - polynom in y- direction

    ZWY3 = ((ZDY+ZDY10)*(ZDY)*(ZDY-ZDY21))&
     & /((ZDY10+ZDY21+ZDY32)*(ZDY21+ZDY32)*(ZDY32))  
    ZWY2 = ((ZDY+ZDY10)*(ZDY)*(ZDY-ZDY21-ZDY32))&
     & /((ZDY10+ZDY21)*(ZDY21)*(-ZDY32))  
    ZWY1 = ((ZDY+ZDY10)*(ZDY-ZDY21)*(ZDY-ZDY21-ZDY32))&
     & /((ZDY10)*(-ZDY21)*(-ZDY21-ZDY32))  
    ZWY0 = 1.0_JPRB-ZWY1-ZWY2-ZWY3

!*         -- linear parts for extreme rows

    ZWXNN=PDLO(JLEN)
    ZCXNN=1.0_JPRB-PDLO(JLEN)

    ZWXSS=PDLO3(JLEN)
    ZCXSS=1.0_JPRB-PDLO3(JLEN)

!*         -- Weights for 12 points interpolation.

    PWXX(JLEN,1)  = ZWXN1*ZWY1
    PWXX(JLEN,2)  = ZWXN2*ZWY1
    PWXX(JLEN,3)  = ZWXS1*ZWY2
    PWXX(JLEN,4)  = ZWXS2*ZWY2
    PWXX(JLEN,5)  = ZCXNN*ZWY0
    PWXX(JLEN,6)  = ZWXNN*ZWY0
    PWXX(JLEN,7)  = ZWXN0*ZWY1
    PWXX(JLEN,8)  = ZWXN3*ZWY1
    PWXX(JLEN,9)  = ZWXS0*ZWY2
    PWXX(JLEN,10) = ZWXS3*ZWY2
    PWXX(JLEN,11) = ZCXSS*ZWY3
    PWXX(JLEN,12) = ZWXSS*ZWY3

  ENDDO

ENDIF

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

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

