SUBROUTINE ALLOC

!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE ALLOC  ***
!&E
!&E ** Purpose :
!&E
!&E ** Description :
!&E
!&E ** Called by :
!&E
!&E ** External calls :
!&E
!&E ** Used ij-arrays :
!&E
!&E ** Modified variables :
!&E
!&E ** Reference :
!&E
!&E ** History :
!&E       ! 2010-02 (G. Simon) add wave module
!&E       ! 2011-11 (V. Garnier) Spatial extension of ssh(liminm2:limaxp2,ljminm2:ljmaxp2)
!&E       ! 2017-09 (F. Ganthy) Turbulence advection (k-epsilon)
!&E
!&E---------------------------------------------------------------------
!! * Modules used
   USE parameters,ONLY : kmax,valmanq,rsh,                    &
                         limin,limax,liminm1,limaxp1,limaxp2, &
                         ljmin,ljmax,ljminm1,ljmaxp1,ljmaxp2, &
                         liminm2,ljminm2,limaxp3,ljmaxp3
   USE comvars2d, ONLY : l_modele2d,alloc_comvars2d,hex,hey,  &
                         htx,hty,l_initfromfile
   USE comfluxdo, ONLY : alloc_comfluxdo,alloc_comfluxdo3d,alloc_fsalxy
   USE comvars3d, ONLY : alloc_comvars3d,wz


   USE cometemp,  ONLY : alloc_cometemp,alloc_ftempxy
   USE sflxatm,   ONLY : alloc_sflxatm
   USE comdem,    ONLY : alloc_comdem
   USE output,    ONLY : output_alloc
   USE cometdyn,  ONLY : alloc_cometdyn
   USE comvarp2d, ONLY : sal,temp,u,v,ssh
   USE comvarp2d, ONLY : sal2,temp2


   USE comvarp2d, ONLY : alloc_comvarp2d

   USE comvarp3d, ONLY : boz,uz,vz,ect,psi,pn2

   USE obccombine,ONLY : alloc_obc
   USE comturb,   ONLY : alloc_comturb
   USE comaree,   ONLY : alloc_comaree

   USE comfluvert,ONLY : alloc_comfluvert



   USE wave,      ONLY : wave_alloc




!! * Arguments

!! * Local declarations

!!----------------------------------------------------------------------
!! * Executable part
   CALL alloc_comvars2d
   CALL output_alloc
   CALL alloc_comdem
   CALL alloc_cometdyn

   CALL wave_alloc

   CALL alloc_cometemp
   CALL alloc_comfluxdo
   CALL alloc_comvars3d
   CALL alloc_sflxatm
   CALL alloc_obc
   CALL alloc_ftempxy
   CALL alloc_fsalxy
! Allocation of variables : eps
   CALL alloc_comturb
! Allocation of variables : potgene
   CALL alloc_comaree
! Allocation of variables : u_vtmp,v_utmp
   CALL alloc_comvarp2d

   CALL alloc_comfluvert

! Allocation of variables of the different terms of the moment equations
! for diagnoses purpose



   IF(.NOT.l_modele2d) CALL alloc_comfluxdo3d

! Allocate dynamics variables


   ALLOCATE( boz(1:kmax,liminm1:limaxp2,ljminm1:ljmaxp2) )
   boz(:,:,:)=valmanq
   ALLOCATE( pn2(1:kmax,limin:limax,ljmin:ljmax) )
   pn2(:,:,:)=0.0_rsh
   ALLOCATE( hex(liminm2:limaxp2,ljmin:ljmax) )
   ALLOCATE( hey(limin:limax,ljminm2:ljmaxp2) )
   hex(:,:)=0.0_rsh
   hey(:,:)=0.0_rsh
!ALLOCATE( htx(liminm1:limax  ,ljminm1:ljmaxp1) )
!ALLOCATE( hty(liminm1:limaxp1,ljminm1:ljmax  ) )
! larger because of interpvit (in avance) in trajectools.F90
   ALLOCATE( htx(liminm2:limaxp2,ljminm2:ljmaxp2) )
   ALLOCATE( hty(liminm2:limaxp2,ljminm2:ljmaxp2) )
   htx(:,:)=0.0_rsh ! to manage with sleeping cpu
   hty(:,:)=0.0_rsh
   ALLOCATE( ect(1:kmax,limin:limax,ljmin:ljmax) )
   ALLOCATE( psi(1:kmax,limin:limax,ljmin:ljmax) )
   ect(:,:,:)=0.0_rsh
   psi(:,:,:)=0.0_rsh


   ALLOCATE( u(liminm2:limaxp2,ljminm2:ljmaxp2) )
   ALLOCATE( v(liminm2:limaxp2,ljminm2:ljmaxp2) )
   u(:,:)=0.0_rsh ! to manage with sleeping cpu
   v(:,:)=0.0_rsh
   ALLOCATE( uz(1:kmax,liminm2:limaxp2,ljminm2:ljmaxp2) )
   ALLOCATE( vz(1:kmax,liminm2:limaxp2,ljminm2:ljmaxp2) )
!ALLOCATE( wz(0:kmax,limin:limaxp1,ljmin:ljmaxp1) )
! larger extension because of traj_3d routine
! might be not sufficient because of the medium location
   ALLOCATE( wz(0:kmax,liminm1:limaxp1,ljminm1:ljmaxp1) )
   wz(:,:,:)=0.0_rsh

   ALLOCATE( ssh(liminm2:limaxp2,ljminm2:ljmaxp2) )
   ssh(:,:)=0.0_rsh
   


! Allocate thermodynamics variables
   ALLOCATE( sal(1:kmax,liminm1:limaxp2,ljminm1:ljmaxp2) )
   ALLOCATE( temp(1:kmax,liminm1:limaxp2,ljminm1:ljmaxp2) )
   ALLOCATE( sal2(1:kmax,liminm1:limaxp2,ljminm1:ljmaxp2) )
   ALLOCATE( temp2(1:kmax,liminm1:limaxp2,ljminm1:ljmaxp2) )
   sal2(:,:,:)=0.0_rsh
   temp2(:,:,:)=0.0_rsh



! Variables relative to generalized vertical coordinates




  END SUBROUTINE ALLOC
