SUBROUTINE SUALLAV(KULOUT)

!**** *SUALLAV*  - allocate tables for avarc gradient                 
!     Purpose.
!     --------
!           Allocate tables for avarc gradients to store them
!           for the adjoint integration

!**   Interface.
!     ----------
!        *CALL* *SUALLAV 

!        Explicit arguments :
!        --------------------
!        KULOUT:  logical unit used for output

!        Implicit arguments :  Common YOMJR
!        --------------------

!     Method.
!     -------

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

!     Reference.
!     ----------

!     Author.
!     -------
!        R. Brozkova   *CNRM/GMAP*

!     Modifications.
!     --------------
!        Original : 01-06-25
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------
USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMDIM  , ONLY:   NFLSUR,NSPEC2
USE YOMJR   , ONLY:  AGRAVOR, AGRADIV, AGRAT, AGRAQ, AGRASP
USE YOMHCP  , ONLY:  NHECP

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KULOUT 
INTEGER(KIND=JPIM) :: ILEN, IEVENT
LOGICAL :: LLALLOC
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('SUALLAV',0,ZHOOK_HANDLE)
WRITE(KULOUT,9000)'SUALLAV- Initialization of the AVARC at level 2'&
 & ,'Memory allocation for the gradients'  
9000 FORMAT(//,8X,A,/,17X,A)

!     1. Memory allocation

IEVENT = NHECP(0)

LLALLOC = ALLOCATED(AGRAVOR )
IF(.NOT.LLALLOC) THEN
  ILEN = NFLSUR*NSPEC2*IEVENT
  WRITE(KULOUT,*)'  SUALLAV-  allocating AGRAVOR. Length = ',ILEN
  ALLOCATE(AGRAVOR(NFLSUR,NSPEC2,IEVENT))
ENDIF
AGRAVOR = 0.0_JPRB

LLALLOC = ALLOCATED(AGRADIV )
IF(.NOT.LLALLOC) THEN
  ILEN = NFLSUR*NSPEC2*IEVENT
  WRITE(KULOUT,*)'  SUALLAV-  allocating AGRADIV. Length = ',ILEN
  ALLOCATE(AGRADIV(NFLSUR,NSPEC2,IEVENT))
ENDIF
AGRADIV = 0.0_JPRB

LLALLOC = ALLOCATED(AGRAT )
IF(.NOT.LLALLOC) THEN
  ILEN = NFLSUR*NSPEC2*IEVENT
  WRITE(KULOUT,*)'  SUALLAV-  allocating AGRAT. Length = ',ILEN
  ALLOCATE(AGRAT(NFLSUR,NSPEC2,IEVENT))
ENDIF
AGRAT = 0.0_JPRB

LLALLOC = ALLOCATED(AGRAQ )
IF(.NOT.LLALLOC) THEN
  ILEN = NFLSUR*NSPEC2*IEVENT
  WRITE(KULOUT,*)'  SUALLAV-  allocating AGRAQ. Length = ',ILEN
  ALLOCATE(AGRAQ(NFLSUR,NSPEC2,IEVENT))
ENDIF
AGRAQ = 0.0_JPRB

LLALLOC = ALLOCATED(AGRASP )
IF(.NOT.LLALLOC) THEN
  ILEN = NSPEC2*IEVENT
  WRITE(KULOUT,*)'  SUALLAV-  allocating AGRASP. Length = ',ILEN
  ALLOCATE(AGRASP(NSPEC2,IEVENT))
ENDIF
AGRASP = 0.0_JPRB

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