 MODULE comsiggen
!!======================================================================
!!                   ***  MODULE comsiggen   ***
!!
!!======================================================================





























































!! * Modules used
   USE parameters

!! * Shared or public module variables
   REAL(kind=rsh) :: b_sig,theta_sig,hc
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:)       :: csu_sig,csw_sig,dcusds,dcwsds,dcsigdxy
   REAL(kind=rsh),DIMENSION(imin:imax,jmin:jmax) :: hc_sig_g,hcx_sig_g,hcy_sig_g
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:)     :: hc_sig,hcx_sig,hcy_sig
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)   :: hzex,hzey
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)   :: hzutx,hzuty
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)   :: hzwtx,hzwty

   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)   :: hzdcusds,     &
                                                    hzdcusds_x,   &
                                                    hzdcusds_y
   REAL(kind=rsh),ALLOCATABLE,DIMENSION(:,:,:)   :: hzdcwsds,   &
                                                    hzdcwsds_x, &
                                                    hzdcwsds_y

 CONTAINS

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

  SUBROUTINE alloc_comsiggen

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

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

   IF (ALLOCATED(hzutx)) PRINT*,"error: comsiggen allocated"
   ALLOCATE(hzutx(kmax,limin:limax,ljmin:ljmax) )
   ALLOCATE(hzuty(kmax,limin:limax,ljmin:ljmax) )
   ALLOCATE(hzwtx(kmax-1,limin:limax,ljmin:ljmax) )
   ALLOCATE(hzwty(kmax-1,limin:limax,ljmin:ljmax) )

   ALLOCATE(hzdcusds(kmax,liminm1:limaxp1,ljminm1:ljmaxp1) )    ! larger extension for agrif
   ALLOCATE(hzdcusds_x(kmax,liminm1:limaxp1,ljminm1:ljmaxp1) )  ! larger extension for agrif
   ALLOCATE(hzdcusds_y(kmax,liminm1:limaxp1,ljminm1:ljmaxp1) )  ! larger extension for agrif
   ALLOCATE(hzdcwsds(kmax,limin:limaxp1,ljmin:ljmaxp1) )
   ALLOCATE(hzdcwsds_x(kmax,limin:limaxp1,ljmin:ljmaxp1) )
   ALLOCATE(hzdcwsds_y(kmax,limin:limaxp1,ljmin:ljmaxp1) )

!ALLOCATE(hc_sig(liminm1:limaxp1,ljminm1:ljmaxp1))
! larger extension because of avance routine in trajectools.F90
   ALLOCATE(hc_sig(liminm2:limaxp2,ljminm2:ljmaxp2))
   ALLOCATE(hcx_sig(liminm1:limaxp1,ljminm1:ljmaxp1))  ! larger extension for agrif
   ALLOCATE(hcy_sig(liminm1:limaxp1,ljminm1:ljmaxp1))  ! larger extension for agrif
   IF(.NOT. l_testcase) THEN
     hc_sig(:,:)  = hc_sig_g(liminm2:limaxp2,ljminm2:ljmaxp2)
     hcx_sig(:,:) = hcx_sig_g(liminm1:limaxp1,ljminm1:ljmaxp1)  ! larger extension for agrif
     hcy_sig(:,:) = hcy_sig_g(liminm1:limaxp1,ljminm1:ljmaxp1)  ! larger extension for agrif
   ENDIF
   ALLOCATE(csu_sig(0:kmax+1))
   ALLOCATE(csw_sig(0:kmax+1))
   ALLOCATE(dcusds(kmax))
   ALLOCATE(dcwsds(kmax))
   ALLOCATE(dcsigdxy(0:kmax+1))

  END SUBROUTINE alloc_comsiggen

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

  SUBROUTINE dealloc_comsiggen

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

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

   DEALLOCATE(hzutx,hzuty,hzwtx,hzwty, &

              hzdcusds,hzdcusds_x,hzdcusds_y, &
              hzdcwsds,hzdcwsds_x,hzdcwsds_y, &

              hc_sig,hcx_sig,hcy_sig,csu_sig,csw_sig,dcusds,dcwsds )

  END SUBROUTINE dealloc_comsiggen

 END MODULE comsiggen
