SUBROUTINE PRSPL2(KN,PA,PB,PS)

!**** *PRSPL2*

!     PURPOSE.
!     --------

!       External of the minimisation routine : calculates the scalar product.

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

!     *CALL* *PRSPL2(KN,PA,PB,PS)*

!         *KN*     - Size of the vectors (input)
!         *PA*     - Vector 1 (input)
!         *PB*     - Vector 2 (input)
!         *PS*     - Value of the scalar product

!     METHOD.
!     -------

!       Sums the spectral coefficients (when n is not 0, multiplication by 2).

!     EXTERNALS.
!     ----------

!           NONE.

!     AUTHOR.
!     -------

!         Y. BOUTELOUP and M. DEQUE   1 FEB 91.

!     MODIFICATIONS.
!     --------------
!         P. Le Moigne : 98-01-22  scalar product in LAM case.
!         P. Le Moigne : 98-09-29  minimization parallelized.
!         F. Taillefer : 05-03-25  back to old formulation (CY15)
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NSMAX
USE YOMCT0   , ONLY : LELAM

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KN 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PA(KN) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB(KN) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PS 

REAL(KIND=JPRB) :: ZHOOK_HANDLE

INTEGER(KIND=JPIM) :: IJ, J

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

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

PS= 0.0_JPRB

IF (.NOT.LELAM) THEN
  DO J=1,KN
    PS= PS + 2.0_JPRB*PA(J)*PB(J)
  ENDDO
  DO J=0,NSMAX
    IJ= 1+J*(J+1)
    PS= PS - PA(IJ)*PB(IJ)
  ENDDO
ELSE
  DO J=1,KN
    PS= PS + PA(J)*PB(J)
  ENDDO
ENDIF

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