SUBROUTINE WRSPEC

!**** *WRSPEC*  - write out spectral arrays

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

!**   Interface.
!     ----------
!        *CALL* *WRSPEC

!        Explicit arguments :      None.
!        --------------------

!        Implicit arguments :      None.
!        --------------------

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------

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

!     Author.
!     -------
!        M.Hamrud *ECMWF*

!     Modifications.
!     --------------
!        Original : 93-11-18
!        Modified : 95-06-06 L. Isaksen - Reordering of spectral arrays
!        Modified : 98-30-30 R. El Khatib save aladin mean wind
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      01-Dec-2003 CY28R1 Cleaning
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMLUN   , ONLY : NULOUT
USE YOMCT0   , ONLY : LALLOPR  ,LELAM
USE YOMDIM   , ONLY : NFLSUR   ,NSPEC2   ,NS3D     ,NS2D
USE YOMSP    , ONLY : SPA3     ,SPA2     ,SPA3SAVE ,SPA2SAVE
IMPLICIT NONE


LOGICAL :: LLFIRST
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "euvcopy.intfb.h"

DATA LLFIRST /.TRUE./

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

!*       3.    COPY SPECTRAL DATA
!              ------------------
IF (LHOOK) CALL DR_HOOK('WRSPEC',0,ZHOOK_HANDLE)
IF (.NOT.ALLOCATED(SPA3SAVE)) THEN
  ALLOCATE (SPA3SAVE(NFLSUR,NSPEC2,NS3D))
  IF (LLFIRST.OR.LALLOPR) THEN
    WRITE(NULOUT,9) 'SPA3SAVE ',SIZE(SPA3SAVE ),SHAPE(SPA3SAVE)
  ENDIF
ENDIF
IF (.NOT.ALLOCATED(SPA2SAVE)) THEN
  ALLOCATE(SPA2SAVE(NSPEC2,NS2D))
  IF (LLFIRST.OR.LALLOPR) THEN
    WRITE(NULOUT,9) 'SPA2SAVE ',SIZE(SPA2SAVE ),SHAPE(SPA2SAVE)
    LLFIRST=.FALSE.
  ENDIF
ENDIF

SPA3SAVE(:,:,:)=SPA3(:,:,:)
SPA2SAVE(:,:)=SPA2(:,:)

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

!*       4.    COPY ALADIN MEAN WIND
!              ---------------------

IF (LELAM) THEN
  CALL EUVCOPY(.FALSE.)
ENDIF
!     ------------------------------------------------------------------

9 FORMAT(1X,'ARRAY ',A10,' ALLOCATED ',8I8)

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