SUBROUTINE SUGMRE(KULOUT,PGMRA0,PGMRA1,PGMRA2,PD,PE,PF)

!**** *SUGMRE*   - Initialisation of coefficients allowing spectral
!                  multiplication by a second-order polynomial of "mu"
!                  (for example (map factor)**2).

!     Purpose.    Initialisation of coefficients PD,PE,PF allowing spectral
!     --------    multiplication by a second order polynomial.

!    ((pgmr )*SPX)(m,n)= PF(m,n-2)*SPX(m,n-2)
!                       +PE(m,n-1)*SPX(m,n-1)
!                       +PD(m,n  )*SPX(m,n  )
!                       +PE(m,n  )*SPX(m,n+1)
!                       +PF(m,n  )*SPX(m,n+2)
!    where:
!         pgmr = a2 mu**2 + a1 mu + a0
!         (mu = sinus of latitude)

!**   Interface.
!     ----------
!        *CALL* *SUGMRE( ... )

!        Explicit arguments :
!        --------------------
!        INPUT:
!         KULOUT:    - Output logical unit.
!         PGMRA0:    - Coefficient a0 of second order polynomial.
!         PGMRA1:    - Coefficient a1 of second order polynomial.
!         PGMRA2:    - Coefficient a2 of second order polynomial.

!        OUTPUT:
!         PD,PE,PF:  - Coefficients to be computed (see above).

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

!     Method.
!     -------
!        See documentation about horizontal diffusion.

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

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     Author.
!     -------
!        K. YESSAD: APRIL 1994.

!     Modifications.
!     --------------
!        K. YESSAD (MARCH 1995):
!              - Use array KSE0.
!              - Set to 0 useless coefficients.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K. Yessad 15-May-2006: memory optimisations for stretched geometry
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NSMAX    ,NSPEC    ,NUMP
USE YOMLAP   , ONLY : MYMS     ,NSE0L

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KULOUT 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGMRA0 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGMRA1 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGMRA2 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PD(NSPEC) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PE(NSPEC) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PF(NSPEC) 

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

REAL(KIND=JPRB) :: ZEE(0:NSMAX+2)

INTEGER(KIND=JPIM) :: ISE, ISE0, JMLOC, IM, JN

REAL(KIND=JPRB) :: ZM2, ZN2
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

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

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

!*       1.    COMPUTATION OF PD,PE,PF.
!              ------------------------

DO JMLOC=1,NUMP
  IM=MYMS(JMLOC)
  ZM2=REAL(IM*IM,JPRB)
  DO JN=IM,NSMAX+2
    ZN2=REAL(JN*JN,JPRB)
    ZEE(JN)=SQRT(MAX(0.0_JPRB,(ZN2-ZM2)/(4._JPRB*ZN2-1.0_JPRB)))
  ENDDO
  ISE0=NSE0L(JMLOC)
  DO JN=IM,NSMAX
    ISE=ISE0+JN+1-IM
    PD(ISE)=PGMRA0+PGMRA2*(ZEE(JN)**2+ZEE(JN+1)**2)
  ENDDO
  DO JN=IM,NSMAX-1
    ISE=ISE0+JN+1-IM
    PE(ISE)=PGMRA1*ZEE(JN+1)
  ENDDO
  ISE=ISE0+NSMAX+1-IM
  PE(ISE)=0.0_JPRB
  DO JN=IM,NSMAX-2
    ISE=ISE0+JN+1-IM
    PF(ISE)=PGMRA2*ZEE(JN+1)*ZEE(JN+2)
  ENDDO
  DO JN=NSMAX-1,NSMAX
    ISE=ISE0+JN+1-IM
    PF(ISE)=0.0_JPRB
  ENDDO
ENDDO

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

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

