 MODULE cometdyn

   !!======================================================================
   !!                   ***  MODULE cometdyn   ***
   !! 
   !!======================================================================
   !! * Modules used
   USE parameters

   !! * Public variables
   LOGICAL               :: l_meteo_stat,l_meteo_hom,l_sflx_rfcc,l_sflx_rwind, &
                            l_sflx_rsat,l_sflx_rrh,l_sflx_rpa,l_sflx_rflux
   LOGICAL               :: l_sflx_rsolar,l_rsens,l_rlat,l_sflx_rir,l_sflx_rrain,l_sflx_rath2m
   CHARACTER(len=lchain) :: file_meteo,longitude_name_meteo,latitude_name_meteo
   CHARACTER(len=lchain) :: name_sflx_sat,name_sflx_pa,name_sflx_rh,name_sflx_windx,     &
                            name_sflx_windy,name_sflx_solar,name_sflx_ir,name_sflx_rain, &
                            name_sflx_fcc,name_sflx_wtaux,name_sflx_wtauy,name_sflx_heat, &
                            name_sflx_emp
   INTEGER               :: imet
   INTEGER               :: nvmax,idd,idimt,ilec,ilecmem
   INTEGER               :: imetmin,imetmax,jmetmin,jmetmax
   INTEGER               :: cdf_id
   REAL(kind=rsh)        :: wind_veloc,wind_dir,pair,rhoair,cds,paref
   REAL(kind=rlg)        :: windamp_duration ! after this period, the wind stress gets its maxumum value
   REAL(kind=rsh),DIMENSION(:),ALLOCATABLE   :: uvent,vvent
   INTEGER,       DIMENSION(:,:),ALLOCATABLE :: i1v,j1v,i1u,j1u,i1xe,j1xe
   REAL(kind=rsh),DIMENSION(:,:),ALLOCATABLE :: tosy1,tosx1,tosy2,tosx2,pa1,pa2,pa,&
#ifdef key_sflx_turb_large_later
                                                u10m,v10m,u10m1,v10m1,u10m2,v10m2, &
#endif
                                                tosx,tosy,rad1,rad2,rain1,rain2,   &
                                                irlos1,irlos2,                     &
                                                xdpxe,ydpxe,xdpu,ydpu,xdpv,ydpv
   REAL(kind=rlg)                                :: tnc1,tnc2

#if defined key_1DV
   REAL(kind=rsh)        :: gradxe_force_1DV_cste, gradxe_force_1DV_ampli,ubaro_force_1DV_cste,  &
                            ubaro_force_1DV_ampli, gradxe_force_1DV, ubaro_force_1DV,modulation_ampli_tide
   LOGICAL               :: l_force1DV_variable

#endif
#ifdef key_lagoon
   LOGICAL               :: l_cmeteocte
   LOGICAL               :: l_rainlag
   CHARACTER(len=lchain) :: file_pluie
   !INTEGER               :: i1_pluie,i2_pluie
   REAL(kind=rsh)        :: rhcte,nebcte
   REAL(kind=rsh),DIMENSION(:),allocatable   :: patm,tempair,relh,nebu
   !REAL(kind=rsh),DIMENSION(:),allocatable         :: pluie_s1,pluie_s2,pluie_s3
   REAL(kind=rsh),DIMENSION(:),ALLOCATABLE   :: uvent_abat,vvent_abat
#endif

 CONTAINS

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

  SUBROUTINE alloc_cometdyn

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE alloc_cometdyn  ***
   !&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

   !! * Arguments

   !! * Local declarations

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

   ALLOCATE(tosx(limin:limax,ljmin:ljmax))
   ALLOCATE(tosy(limin:limax,ljmin:ljmax))

   ALLOCATE(tosx1(limin:limax,ljmin:ljmax))
   ALLOCATE(tosy1(limin:limax,ljmin:ljmax))
   ALLOCATE(pa1(limin:limax,ljmin:ljmax))
   ALLOCATE(tosx2(limin:limax,ljmin:ljmax))
   ALLOCATE(tosy2(limin:limax,ljmin:ljmax))
   ALLOCATE(pa2(limin:limax,ljmin:ljmax))
   ALLOCATE(pa(liminm2:limaxp2,ljminm2:ljmaxp2))

   ALLOCATE(xdpxe(limin:limax,ljmin:ljmax))
   ALLOCATE(xdpu(limin:limax,ljmin:ljmax))
   ALLOCATE(xdpv(limin:limax,ljmin:ljmax))
   ALLOCATE(ydpxe(limin:limax,ljmin:ljmax))
   ALLOCATE(ydpu(limin:limax,ljmin:ljmax))
   ALLOCATE(ydpv(limin:limax,ljmin:ljmax))

   ALLOCATE(i1v(limin:limax,ljmin:ljmax))
   ALLOCATE(j1v(limin:limax,ljmin:ljmax))
   ALLOCATE(i1u(limin:limax,ljmin:ljmax))
   ALLOCATE(j1u(limin:limax,ljmin:ljmax))
   ALLOCATE(i1xe(limin:limax,ljmin:ljmax))
   ALLOCATE(j1xe(limin:limax,ljmin:ljmax))

   ALLOCATE(rad1(limin:limax,ljmin:ljmax))
   ALLOCATE(rain1(limin:limax,ljmin:ljmax))
   ALLOCATE(irlos1(limin:limax,ljmin:ljmax))
   ALLOCATE(rad2(limin:limax,ljmin:ljmax))
   ALLOCATE(rain2(limin:limax,ljmin:ljmax))
   ALLOCATE(irlos2(limin:limax,ljmin:ljmax))

   !initialisation for sflxread & tool_interp2d_sflx
   !tool_interp2d_sflx puts value only between ig(j) id(j)
   !but sflxread uses value from imin:imax, thus
   !these values must be initialised as zero.
   pa1(:,:)   =0.0_rsh ; pa2(:,:)   =0.0_rsh
   rad1(:,:)  =0.0_rsh ; rad2(:,:)  =0.0_rsh
   irlos1(:,:)=0.0_rsh ; irlos2(:,:)=0.0_rsh
   rain1(:,:) =0.0_rsh ; rain2(:,:) =0.0_rsh
   tosx1(:,:) =0.0_rsh ; tosx2(:,:) =0.0_rsh
   tosy1(:,:) =0.0_rsh ; tosy2(:,:) =0.0_rsh
   tosx(:,:)  =0.0_rsh ; tosy(:,:) =0.0_rsh
   pa(:,:) = paref

#ifdef key_sflx_turb_large_later
   ALLOCATE(u10m(limin:limax,ljmin:ljmax))
   ALLOCATE(v10m(limin:limax,ljmin:ljmax))
   ALLOCATE(u10m1(limin:limax,ljmin:ljmax))
   ALLOCATE(v10m1(limin:limax,ljmin:ljmax))
   ALLOCATE(u10m2(limin:limax,ljmin:ljmax))
   ALLOCATE(v10m2(limin:limax,ljmin:ljmax))
#endif

  END SUBROUTINE alloc_cometdyn

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

  SUBROUTINE dealloc_cometdyn

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE dealloc_cometdyn  ***
   !&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

   !! * Arguments

   !! * Local declarations

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

   DEALLOCATE(tosy1,tosx1,tosy2,tosx2,pa1,pa2,pa)
   DEALLOCATE(tosx,tosy,rad1,rad2,rain1,rain2,irlos1,irlos2  )
#ifdef key_sflx_turb_large_later
   DEALLOCATE(u10m,v10m,u10m1,v10m1,u10m2,v10m2)
#endif
   DEALLOCATE(xdpxe,ydpxe,xdpu,ydpu,xdpv,ydpv)
   DEALLOCATE(i1v,j1v,i1u,j1u,i1xe,j1xe)

  END SUBROUTINE dealloc_cometdyn

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

 END MODULE cometdyn
