SUBROUTINE SUALDYN

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

USE YOMCT0   , ONLY : NPRINTLEV,LRFRIC   ,LALLOPR  ,LSITRIC  ,LNHDYN
USE YOMLUN   , ONLY : NULOUT
USE YOMDIM   , ONLY : NFLEVG   ,NSMAX
USE YOMDYN   , ONLY : RCORDIT ,RCORDIH ,RCORDIF  ,&
 & RKRF     ,SIALPH   ,SILNPR  ,SIDELP   ,SIRDEL   ,SITLAH   ,&
 & SITLAF   ,SIDPHI   ,SIB     ,SIMO     ,SIMI     ,SIVP     ,&
 & SITRICA  ,SITRICB  ,SITRICC ,SIRUB    ,S2ETA    ,SIFAC    ,SIFACI
USE YOMJG    , ONLY : SIBI

!**** *SUALDYN * - Routine to allocate space for dynamics

!     Purpose.
!     --------
!           Allocate space for the dynamics calc.

!**   Interface.
!     ----------
!        *CALL* *SUALDYN*

!     Explicit arguments :  None
!     --------------------
!        Called by SUALLO

!     Implicit arguments :
!     --------------------
!        Pointers of comdecks

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

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

!     Author.
!     -------
!        Mats Hamrud *ECMWF*

!     Modifications.
!     --------------
!        Original : 95-11-20  From SUALLO
!        K. YESSAD (NOV 1995): removal of HDC horizontal diffusion scheme.
!        M. Hortal: 96-05-16 Terms for new thermodynamic equation
!        C. TEMPERTON (MAY 1996): new semi-implicit solver
!        Modified OCT 1996 by K. YESSAD: removal of variable uncentering.
!        M. TOLSTYKH (OCTOBER 1996): Fourier space horizontal diffusion
!        M. TOLSTYKH (December 1997): Bug correction for Fourier diffusion
!        M. SZCZECH (April 2000): New allocations for hor diffusion of O3
!        M. TOLSTYKH (December 2000):  Vert. dependency for Fourier diffusion
!        Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!        M. TOLSTYKH (Feb 2002): Some optimization for Fourier diffusion
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K. YESSAD (Dec 2003): clean horizontal diffusion scheme.
!        K. YESSAD (Feb 2005): NH in ARPEGE
!     ------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM) :: IU

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

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

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

!*       1.    ALLOCATE SPACE FOR ARRAYS.
!              --------------------------

LLP = NPRINTLEV >= 1.OR. LALLOPR
IU = NULOUT

! * Semi-implicit scheme and normal mode initialisation.
ALLOCATE(SIALPH(NFLEVG))
IF(LLP)WRITE(IU,9) 'SIALPH   ',SIZE(SIALPH),SHAPE(SIALPH)
ALLOCATE(SILNPR(NFLEVG))
IF(LLP)WRITE(IU,9) 'SILNPR   ',SIZE(SILNPR),SHAPE(SILNPR)
ALLOCATE(SIDELP(NFLEVG))
IF(LLP)WRITE(IU,9) 'SIDELP   ',SIZE(SIDELP),SHAPE(SIDELP)
ALLOCATE(SIRDEL(NFLEVG))
IF(LLP)WRITE(IU,9) 'SIRDEL   ',SIZE(SIRDEL),SHAPE(SIRDEL)
ALLOCATE(SITLAH(0:NFLEVG))
IF(LLP)WRITE(IU,9) 'SITLAH   ',SIZE(SITLAH),SHAPE(SITLAH)
ALLOCATE(SITLAF(NFLEVG))
IF(LLP)WRITE(IU,9) 'SITLAF   ',SIZE(SITLAF),SHAPE(SITLAF)
ALLOCATE(SIDPHI(NFLEVG))
IF(LLP)WRITE(IU,9) 'SIDPHI   ',SIZE(SIDPHI),SHAPE(SIDPHI)
ALLOCATE(SIB(NFLEVG,NFLEVG))
IF(LLP)WRITE(IU,9) 'SIB      ',SIZE(SIB),SHAPE(SIB)
ALLOCATE(SIMO(NFLEVG,NFLEVG))
IF(LLP)WRITE(IU,9) 'SIMO     ',SIZE(SIMO),SHAPE(SIMO)
ALLOCATE(SIMI(NFLEVG,NFLEVG))
IF(LLP)WRITE(IU,9) 'SIMI     ',SIZE(SIMI),SHAPE(SIMI)
ALLOCATE(SIVP(NFLEVG))
IF(LLP)WRITE(IU,9) 'SIVP     ',SIZE(SIVP),SHAPE(SIVP)
ALLOCATE(SIRUB(0:NFLEVG))
IF(LLP)WRITE(IU,9) 'SIRUB    ',SIZE(SIRUB),SHAPE(SIRUB)
ALLOCATE(SIBI(NFLEVG,NFLEVG))
IF(LLP)  WRITE(IU,9) 'SIBI     ',SIZE(SIBI),SHAPE(SIBI)
ALLOCATE(S2ETA(NFLEVG))
IF(LLP)WRITE(IU,9) 'S2ETA    ',SIZE(S2ETA),SHAPE(S2ETA)
IF (LSITRIC) THEN
  ALLOCATE(SITRICA(NSMAX,NFLEVG))
  IF(LLP)WRITE(IU,9) 'SITRICA  ',SIZE(SITRICA),SHAPE(SITRICA)
  ALLOCATE(SITRICB(NSMAX,NFLEVG))
  IF(LLP)WRITE(IU,9) 'SITRICB  ',SIZE(SITRICB),SHAPE(SITRICB)
  ALLOCATE(SITRICC(NSMAX,NFLEVG))
  IF(LLP)WRITE(IU,9) 'SITRICC  ',SIZE(SITRICC),SHAPE(SITRICC)
ENDIF
IF (LNHDYN) THEN
  ALLOCATE(SIFAC(NFLEVG,NFLEVG))
  IF(LLP)WRITE(IU,9) 'SIFAC    ',SIZE(SIFAC),SHAPE(SIFAC)
  ALLOCATE(SIFACI(NFLEVG,NFLEVG))
  IF(LLP)WRITE(IU,9) 'SIFACI   ',SIZE(SIFACI),SHAPE(SIFACI)
ENDIF

! * Intermediate arrays to change variable for T-eqn.
ALLOCATE(RCORDIT(NFLEVG))
IF(LLP)WRITE(IU,9) 'RCORDIT  ',SIZE(RCORDIT),SHAPE(RCORDIT)
ALLOCATE(RCORDIH(0:NFLEVG))
IF(LLP)WRITE(IU,9) 'RCORDIH  ',SIZE(RCORDIH),SHAPE(RCORDIH)
ALLOCATE(RCORDIF(NFLEVG))
IF(LLP)WRITE(IU,9) 'RCORDIF  ',SIZE(RCORDIF),SHAPE(RCORDIF)

! * Rayleigh friction.
IF(LRFRIC) THEN
  ALLOCATE(RKRF(NFLEVG))
  IF(LLP)WRITE(IU,9) 'RKRF   ',SIZE(RKRF),SHAPE(RKRF)
ENDIF

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

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