 MODULE comcolig2d

   !!======================================================================
   !!                   ***  MODULE comcolig2d  ***
   !! 
   !!======================================================================

#include "toolcpp.h"

   !! * Modules used
   USE parameters

   !! * Accessibility

   !! * Shared or public module variables

   !! * Private variables
   INTEGER,ALLOCATABLE,DIMENSION(:,:)        :: igdu_old,igdv_old,igdu,igdv
   INTEGER,ALLOCATABLE,DIMENSION(:,:)        :: ms,mn      ! wall (mur) at the South and North
   INTEGER,ALLOCATABLE,DIMENSION(:,:)        :: me,mo      ! wall (mur) at the East and West
   INTEGER,ALLOCATABLE,DIMENSION(:,:)        :: whx,why    ! wall at locations hx and hy
   REAL(KIND=rlg),ALLOCATABLE,DIMENSION(:,:) :: av,bv,cv,y2dv,axe,bxe,cxe,y2dxe,y2d_expv

 CONTAINS

   !!======================================================================

  SUBROUTINE alloc_comcolig2d

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE alloc_comcolig2d  ***
   !&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       !  
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comvars2d, ONLY : l_modele2d
   IMPLICIT NONE

   !! * Arguments

   !! * Local declarations

   !!----------------------------------------------------------------------
   !! * Executable part

   IF_NOAGRIF (ALLOCATED(av))PRINT*,"error: comcolig2d allocated"
   ALLOCATE(me(liminm1:limaxp1,ljminm1:ljmax  ))  ! larger extension for agrif
   ALLOCATE(mo(liminm1:limax  ,ljmin  :ljmax  ))
   ALLOCATE(mn(liminm1:limax  ,ljminm1:ljmaxp1))  ! larger extension for agrif
   ALLOCATE(ms(limin  :limax  ,ljminm1:ljmax  ))
   me(:,:)=0
   mo(:,:)=0
   mn(:,:)=0
   ms(:,:)=0
#if ! defined key_dbg
   IF(.NOT.l_modele2d) THEN
#endif
     ALLOCATE(igdu_old(limin:limax,ljmin:ljmax))
     ALLOCATE(igdv_old(limin:limax,ljmin:ljmax))
     igdu_old(:,:)=4
     igdv_old(:,:)=4
#if ! defined key_dbg
   ENDIF
#endif
   ALLOCATE(igdu(liminm1:limaxp1,ljminm1:ljmaxp1))
   ALLOCATE(igdv(liminm1:limaxp1,ljminm1:ljmaxp1))
   igdu(:,:)=4
   igdv(:,:)=4
   ALLOCATE(whx(liminm1:limaxp1,ljmin:ljmax))
   ALLOCATE(why(limin:limax,ljminm1:ljmaxp1))
   whx(:,:)=0  ! to manage with sleeping cpus
   why(:,:)=0
   ALLOCATE(av(liminm1:limax,ljminm1:ljmax))
   ALLOCATE(bv(liminm1:limax,ljminm1:ljmax))
   ALLOCATE(cv(liminm1:limax,ljminm1:ljmax))
   ALLOCATE(y2dv(liminm1:limax,ljminm1:ljmax))
   ALLOCATE(axe(limin:limax,ljmin:ljmax))
   ALLOCATE(bxe(limin:limax,ljmin:ljmax))
   ALLOCATE(cxe(limin:limax,ljmin:ljmax))
   ALLOCATE(y2dxe(limin:limax,ljmin:ljmax))
   IF(.NOT.l_modele2d) THEN
     ALLOCATE(y2d_expv(imin:imax,ljmin:ljmax))
   ENDIF
   av(:,:)=0.0_rlg;bv(:,:)=1.0_rlg;cv(:,:)=0.0_rlg;y2dv(:,:)=0.0_rlg
   axe(:,:)=0.0_rlg;bxe(:,:)=1.0_rlg;cxe(:,:)=0.0_rlg;y2dxe(:,:)=valmanq

  END SUBROUTINE alloc_comcolig2d

   !!======================================================================

  SUBROUTINE dealloc_comcolig2d

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE dealloc_comcolig2d  ***
   !&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       !  
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comvars2d, ONLY : l_modele2d
   IMPLICIT NONE

   !! * Arguments

   !! * Local declarations

   !!----------------------------------------------------------------------
   !! * Executable part

   DEALLOCATE(av,bv,cv,y2dv,axe,bxe,cxe,y2dxe,me,mo,mn,ms,whx,why)
   DEALLOCATE(igdu,igdv)
   IF(.NOT.l_modele2d) THEN
     DEALLOCATE(y2d_expv,igdu_old,igdv_old)
   ENDIF

  END SUBROUTINE dealloc_comcolig2d

   !!======================================================================

 END MODULE comcolig2d
