SUBROUTINE SWAP73

!**** *SWAP73* - ROUTINE TO SWAP SP3 AND SP7 SPECTRAL ARRAYS

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

!**   INTERFACE.
!     ----------
!        *CALL* *SWAP73*

!        IMPLICIT ARGUMENTS :  SP7Ax and SPAx
!        --------------------

!     METHOD.
!     -------

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

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

!     AUTHOR.
!     -------
!        W. HECKLEY *ECMWF*  (based on SWAP53)

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 91-11-22
!        Modified : 95-06-06 L. Isaksen - Reordering of spectral arrays
!        Modified : 96-05-05 L. Isaksen - Adapted for Message Passing
!        Modified : 97-05-26 L. Dragulanescu - 3DVAR ALADIN
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        R. El Khatib : 04-04-30 Aladin only
!        B. Chapnik : 22-mar-06 phase w/ 30R2   
!        M. Jidane  : 05-04-2006 - CY31 Phasing
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMDIM   , ONLY : NFLEVL   ,NFLEVG   ,NFD2D    ,NSPEC2   ,NS3D
USE YOMSP    , ONLY : SPA3     ,SPA2     ,SPA1
USE YOMSPJB  , ONLY : SP7A3    ,SP7A2    ,SP7A1
USE YOMCT0   , ONLY : LELAM
USE YOMMP    , ONLY : NPSP

IMPLICIT NONE

REAL(KIND=JPRB) :: ZHOOK_HANDLE
REAL(KIND=JPRB) :: ZZ(NSPEC2)

INTEGER(KIND=JPIM) :: J, JLEV, JVAR

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

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

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

DO JVAR=1,NS3D
    DO JLEV=1,NFLEVL
      ZZ(:)               =SP7A3(JLEV,:,JVAR)
      SP7A3(JLEV,:,JVAR)=SPA3(JLEV,:,JVAR)
      SPA3(JLEV,:,JVAR) =ZZ(:)
    ENDDO
ENDDO

IF (NPSP == 1) THEN
  DO JVAR=1,NFD2D
      ZZ(:)        =SP7A2(:,JVAR)
      SP7A2(:,JVAR)=SPA2(:,JVAR)
      SPA2(:,JVAR)=ZZ(:)
  ENDDO
ENDIF

IF (LELAM) THEN
  DO J=1,2
    DO JLEV=1,NFLEVG
      ZZ(1)           =SP7A1(JLEV,J)
      SP7A1(JLEV,J)   =SPA1(JLEV,J)
      SPA1(JLEV,J)    =ZZ(1)    
    ENDDO
  ENDDO
ENDIF

IF (LHOOK) CALL DR_HOOK('SWAP73',1,ZHOOK_HANDLE)

END SUBROUTINE SWAP73
