SUBROUTINE SWAP53

!**** *SWAP53* - ROUTINE TO SWAP SP3 AND SP5 SPECTRAL ARRAYS

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

!**   INTERFACE.
!     ----------
!        *CALL* *SWAP53*

!        IMPLICIT ARGUMENTS :  SP5Ax and SPAx
!        --------------------

!     METHOD.
!     -------

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

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

!     AUTHOR.
!     -------
!        P. COURTIER *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 91-09-24
!        Modified : 95-06-06 L. Isaksen - Reordering of spectral arrays
!        Modified : 96-05-05 L. Isaksen - Adapted for Message Passing
!        Modified : 97-05    L. Dragulanescu - mean wind for ALADIN
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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

USE YOMDIM   , ONLY : NFLEVL   ,NSPEC2   ,NS3D     ,NS2D
USE YOMSP    , ONLY : SPA3     ,SPA2     ,SP5A3    ,SP5A2    ,&
 & SPA1     ,SP5A1  
USE YOMMP    , ONLY : NPSP
USE YOMCT0   , ONLY : LELAM

IMPLICIT NONE

INTEGER(KIND=JPIM) :: JLEV, JVAR,JNM
REAL(KIND=JPRB) :: ZZ
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*    1.    COPY SPAx INTO SP5Ax.
!           ---------------------

IF (LHOOK) CALL DR_HOOK('SWAP53',0,ZHOOK_HANDLE)
DO JVAR=1,NS3D
  DO JNM=1,NSPEC2
    DO JLEV=1,NFLEVL
      ZZ                   = SPA3 (JLEV,JNM,JVAR)
      SPA3 (JLEV,JNM,JVAR) = SP5A3(JLEV,JNM,JVAR)
      SP5A3(JLEV,JNM,JVAR) = ZZ
    ENDDO
  ENDDO
ENDDO

IF (NPSP == 1) THEN
  DO JVAR=1,NS2D
    DO JNM=1,NSPEC2
      ZZ              = SPA2 (JNM,JVAR)
      SPA2 (JNM,JVAR) = SP5A2(JNM,JVAR)
      SP5A2(JNM,JVAR) = ZZ
    ENDDO
  ENDDO
ENDIF

IF (LELAM) THEN
  DO JVAR=1,2
    DO JLEV=1,NFLEVL
      ZZ               = SPA1 (JLEV,JVAR)
      SPA1 (JLEV,JVAR) = SP5A1(JLEV,JVAR)
      SP5A1(JLEV,JVAR) = ZZ
    ENDDO
  ENDDO
ENDIF

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

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