 MODULE comvarp2d

   !!======================================================================
   !!                   ***  MODULE comvarp2d  ***
   !! 
   !! ** Description :
   !!    u     : zonal component of barotropic velocity (in m/s)
   !!    xeu   : free surface elevation simutaneous with u (in m),
   !!            with respect to the chosen vertical reference
   !!    v     : meridional component of barotropic velocity (in m/s)
   !!    xev   : free surface elevation simutaneous with v (in m),
   !!            with respect to the chosen vertical reference
   !!    u_vtmp: work array for a barotropic component (u or v),
   !!            containing the result of the integration time-step (u if stepu, v if stepv)
   !!    sal   : sea water salinity (in psu)
   !!    temp  : sea water temperature (in degree C)
   !!
   !! ** Reference :
   !!                T. Duhaut, M. Honnorat, L. Debreu, 2008 : Rapport
   !!                contrat PREVIMER - Ref : 06/2 210 290 (pages 100-125)
   !!
   !! ** History :
   !!       !  2008-07  (L. Debreu, M. Honnorat, T. Duhaut) time scheme
   !!
   !!======================================================================

#include "toolcpp.h"

   !! * Modules used
   USE parameters

   IMPLICIT NONE

   !! * Shared or public module variables
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:)                 :: ssh,u,v
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:)                 :: u_vtmp,v_utmp
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)               :: sal,temp
                                  ! intermediate variable (used in UQ macho scheme)
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)               :: sal2,temp2
!#ifdef key_tssub_macho3d
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)               :: sal3,temp3
!#endif
#if defined key_tssub_adv_fifthorder || defined key_tssub_adv_fourthorder
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)               :: sal5,temp5  !VALERIE PROVISOIRE
#endif

   INST_AGRIF REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:)      :: ssh_old

 CONTAINS

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

  SUBROUTINE alloc_comvarp2d

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE alloc_comvarp2d  ***
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used

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

   IF_NOAGRIF (ALLOCATED(u_vtmp)) PRINT*,"error: comvarp2d allocated"
#ifdef key_waveforcing
   ALLOCATE( u_vtmp(liminm1:limaxp1,ljminm1:ljmaxp1) )
   ALLOCATE( v_utmp(liminm1:limaxp1,ljminm1:ljmaxp1) )
   u_vtmp(:,:)=0.0_rsh  ! to manage with sleeping cpus
   v_utmp(:,:)=0.0_rsh
#else
   ALLOCATE( u_vtmp(limin:limax,ljmin:ljmax) )
   ALLOCATE( v_utmp(limin:limax,ljmin:ljmax) )
#endif

  END SUBROUTINE alloc_comvarp2d

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

  SUBROUTINE dealloc_comvarp2d

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE dealloc_comvarp2d  ***
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   !!----------------------------------------------------------------------
   !! * Executable part

   DEALLOCATE(u_vtmp,v_utmp)

  END SUBROUTINE dealloc_comvarp2d

 END MODULE comvarp2d
