SUBROUTINE WRINC

!**** *WRINC*  - writes out the increments x-xb

!     Purpose.
!     --------
!     Write out the increments

!**   Interface.
!     ----------
!        *CALL* *WRINC

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

!        Implicit arguments :      The state varaibles of the model
!        --------------------

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

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

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

!     Author.
!     -------
!        Florence Rabier  from WRTRA *ECMWF*

!     Modifications.
!     --------------
!        Original : 94-07-04
!        Modified : 95-06-06 L. Isaksen - Reordering of spectral arrays
!        Modified : 96-08-01 M. Fisher  - Make I/O optional
!                   99-07-15 M.Hamrud    Remove LIORINC=true
!        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
USE YOMDIM   , ONLY : NFLSUR   ,NSPEC2   ,NS3D     ,NS2D
USE YOMSP    , ONLY : SPA3     ,SPA2
USE YOMRINC  , ONLY : SPA3I    ,SPA2I

IMPLICIT NONE

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

DATA LLFIRST /.TRUE./

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

!*       4.    SAVE INCREMENT IN MEMORY
!              ------------------------

IF (LHOOK) CALL DR_HOOK('WRINC',0,ZHOOK_HANDLE)
IF (.NOT.ALLOCATED(SPA3I)) THEN
  ALLOCATE (SPA3I(NFLSUR,NSPEC2,NS3D))
  IF (LLFIRST.OR.LALLOPR) THEN
    WRITE(NULOUT,9) 'SPA3I ',SIZE(SPA3I ),SHAPE(SPA3I)
  ENDIF
ENDIF
IF (.NOT.ALLOCATED(SPA2I)) THEN
  ALLOCATE(SPA2I(NSPEC2,NS2D))
  IF (LLFIRST.OR.LALLOPR) THEN
    WRITE(NULOUT,9) 'SPA2I ',SIZE(SPA2I ),SHAPE(SPA2I)
    LLFIRST=.FALSE.
  ENDIF
ENDIF

SPA3I(:,:,:) = SPA3(:,:,:)
SPA2I(:,:)   = SPA2(:,:)

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

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

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