SUBROUTINE SPROTLON(KULOUT,KFIELD,KFLDSUR,&
 & KNSMAX,KASM0,KN,KSPEC2,PC,PS,PSPECI,PSPECF)  

!**** *SPROTLON* - Longitude rotation of spectral arrays
!                for each wave number KN.

!     Purpose.
!     --------

!**   Interface.
!     ----------
!         *CALL* SPROTLON(KULOUT,KFIELD,KFLDSUR,
!                       KNSMAX,KASM0,KN,
!                       PC,PS,PSPECI,PSPECF)

!        Explicit arguments :
!        --------------------

!      KULOUT      - Output logical unit.                             (INPUT)
!      KFIELD      - Number of fields to be transformed.              (INPUT)
!      KFLDSUR     - Odd number above KFIELD for dimensioning.        (INPUT)
!      KNSMAX      - Troncature.                                      (INPUT)
!      KASM0       - KASM0    : Index of the coefficient              (INPUT)
!                    corresponding to the wave number (m=JM,n=JM)
!      KN          - Wave number.                                     (INPUT)
!      PC,PS       - COS(m*longitude), sin(m*longitude).              (INPUT)
!      PSPECI      - Fields before rotation.                          (INPUT)

!      PSPECF      - Fields after rotation.                           (OUTPUT)

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

!     Method.
!     -------

!     Externals:
!     ----------
!        Calls LFILEC, MXMAOP.
!        Called by SPOLTS.

!     Reference.
!     ----------
!        ARPEGE/IFS note number 19 (in French).

!     Author.
!     -------
!        K. YESSAD. (METEO-FRANCE/CNRM/GMAP)

!     Modifications.
!     --------------
!        Original : FEBRUARY 1991
!        Modification (english comments, cleaning) by K. YESSAD: APRIL 1993.
!        Modified by L. Isaksen 95-06-06 : Reordering of spectral arrays
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

IMPLICIT NONE

!     INPUT:

INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDSUR 
INTEGER(KIND=JPIM),INTENT(IN)    :: KNSMAX 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSPEC2 
INTEGER(KIND=JPIM)               :: KULOUT ! Argument NOT used
INTEGER(KIND=JPIM),INTENT(IN)    :: KFIELD 
INTEGER(KIND=JPIM),INTENT(IN)    :: KASM0(0:KNSMAX) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KN 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PC(KNSMAX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PS(KNSMAX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPECI(KFLDSUR,KSPEC2) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSPECF(KFLDSUR,KSPEC2) 
!     OUTPUT:
INTEGER(KIND=JPIM) :: INDM, INDP, JFIELD, JM
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('SPROTLON',0,ZHOOK_HANDLE)
DO JFIELD=1,KFIELD
  PSPECF(JFIELD,KASM0(0)+KN*2)=PSPECI(JFIELD,KASM0(0)+KN*2)
  IF (KN > 0) THEN
!DIR$ IVDEP
!OCL NOVREC
    DO JM=1,KN
      INDM=KASM0(JM)+(KN-JM)*2+1
      INDP=KASM0(JM)+(KN-JM)*2
      PSPECF(JFIELD,INDP)=&
       & PSPECI(JFIELD,INDP)*PC(JM)-PSPECI(JFIELD,INDM)*PS(JM)  
      PSPECF(JFIELD,INDM)=&
       & PSPECI(JFIELD,INDP)*PS(JM)+PSPECI(JFIELD,INDM)*PC(JM)  
    ENDDO
  ENDIF
ENDDO

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

