SUBROUTINE DIFSP(PSPA3,PSPA2,PSPA1,PSPB3,PSPB2,PSPB1,PSPC3,PSPC2,PSPC1)

!     PURPOSE :  Difference between spectral arrays : A <- B-C
!     -------

!     INTERFACE :
!     ---------
!       *CALL* *DIFSP(PSPA3,PSPA2,PSPA1,PSPB3,PSPB2,PSPB1,PSPC3,PSPC2,PSPC1)*

!       Explicit arguments :
!       ------------------
!         PASPx : output (PSPBx-PCSPx)
!         PBSPx, PXSPx : input
!         PSPx3 : 3d fields
!         PSPx2 : 2d dynamical fields
!         PSPx1 : 1d fields (mean U,V)  (for ALADIN)

!       Implicit arguments : YOMCT0 (LELAM)
!       ------------------

!     EXTERNALS : None
!     ----------

!     REFERENCE : ARPEGE/ALADIN documentation
!     ---------

!     AUTHOR : D. Giard  *CNRM/GMAP*
!     ------

!     MODIFICATIONS :
!     -------------
!       Original : 93-07-26
!       Modified 95-06-06 by L.Isaksen : Reordering of spectral arrays
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!------------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NFLEVL   ,NFD2D    ,NFLSUR   ,NSPEC2   ,NS3D
USE YOMCT0   , ONLY : LELAM
USE YOMMP    , ONLY : MYSETV   ,NBSETSP

IMPLICIT NONE

REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSPA3(NFLSUR,NSPEC2,NS3D) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSPA2(NSPEC2,NFD2D) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSPA1(NFLEVL,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPB3(NFLSUR,NSPEC2,NS3D) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPB2(NSPEC2,NFD2D) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPB1(NFLEVL,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPC3(NFLSUR,NSPEC2,NS3D) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPC2(NSPEC2,NFD2D) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPC1(NFLEVL,2) 
INTEGER(KIND=JPIM) :: J, JF, JK
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('DIFSP',0,ZHOOK_HANDLE)
IF (LELAM) THEN
  DO JK=1,NFLEVL
    PSPA1(JK,1) = PSPB1(JK,1) - PSPC1(JK,1)
    PSPA1(JK,2) = PSPB1(JK,2) - PSPC1(JK,2)
  ENDDO
ENDIF

IF (MYSETV  ==  NBSETSP) THEN
  DO JF=1,NFD2D
    DO J=1,NSPEC2
      PSPA2(J,JF)= PSPB2(J,JF) - PSPC2(J,JF)
    ENDDO
  ENDDO
ENDIF

DO JF=1,NS3D
  DO J=1,NSPEC2
    DO JK=1,NFLEVL
      PSPA3(JK,J,JF)= PSPB3(JK,J,JF) - PSPC3(JK,J,JF)
    ENDDO
  ENDDO
ENDDO

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