  SUBROUTINE cas_advspot

!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE cas_advspot  ***
!&E
!&E ** Purpose : advection of a spot of salinity by a 2D constant
!&E              velocity field u=v=1
!&E
!&E ** Description :
!&E
!&E ** Called by : cas_init
!&E
!&E ** External calls :
!&E
!&E ** Used ij-arrays :
!&E
!&E ** Modified variables :
!&E
!&E ** Reference :
!&E
!&E ** History :
!&E       !  2007-09  (T. Duhaut)  Original code
!&E       !  2008-12  (V. Garnier) shift of sigma values : -1 < sig < 0
!&E
!&E---------------------------------------------------------------------





























































!! * Modules used
   USE parameters, ONLY : rsh,rlg,riolg,imin,imax,jmin,jmax,kmax,      &
                          ljmin,ljminm1,ljminm2,limax,limaxp1,limaxp2, &
                          ljmax,ljmaxp1,ljmaxp2,limin,liminm1,liminm2, &
                          ishift_obc_west,ishift_obc_east,jshift_obc_south,jshift_obc_north
   USE comvars2d, ONLY : fisac,gwac,fu,fv,dtmin,dtmax,dt,suffix,l_maxu, &
                         l_obc_cycl_x,l_obc_cycl_y,l_modele2d,qmax,halfdt, &
                         jh,jb,ig,id
   USE comvarp2d, ONLY : ssh,u,v,sal
   USE comvarp3d, ONLY : uz,vz
   USE comvars3d, ONLY : qmaxz,rhoref,saliref,kzinit,nzinit
   USE output,  ONLY : pasor,l_out_temp
   USE obccombine, ONLY : l_obc_cycl

   USE comsubstance, ONLY : nvpc,nvp,nv_cp,nv_dis,nv_fix,nv_dri,nv_int,nv_sorb,     &
                            name_var,long_name_var,standard_name_var,nv_ncp,        &
                            valid_min_var,valid_max_var,cv_wat,nb_var,date_startsub
   USE casinit,   ONLY : cas_init_subs

   USE toolmpi, ONLY: ex_i_rsh,ex_j_rsh,ex_peri_x_rsh,ex_peri_y_rsh
   USE casinit,   ONLY : cas_init_param,cas_init_grid,cas_init_bathy, &
                         cas_init_io,cas_init_obc,cas_init_meteo,     &
                         cas_init_visc,cas_init_turb,cas_init_tspar,  &
                         cas_init_progvar,cas_init_misc,cas_init_river

   IMPLICIT NONE

!! * Arguments

!! * Local declarations
   CHARACTER(LEN=19) :: date_start,date_end,date_start3d,date_startagrif
   INTEGER           :: i,j,k
   REAL(KIND=rlg)    :: x,y,Lx,Ly
   REAL(KIND=rsh)    :: z0bottom,z0surface,depthcst
   REAL(KIND=rsh)    :: dxval,dyval

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

   PRINT*, '!!!!!!!!!!!!!!!!!!!'
   PRINT*, 'TEST CASE : AdvSpot'
   PRINT*, '!!!!!!!!!!!!!!!!!!!'

! general parametrization (each parameter can be reassigned)
! -----------------------

! dynamics
   CALL cas_init_param

! over-assignement
   l_maxu=.FALSE.

! tracers : among others, saliref=saliref_lin=35.5_rsh, tetaref=tetaref_lin=10.0_rsh
   CALL cas_init_tspar

! over-assignement
   qmax=12.0
   qmaxz=10.0
   rhoref=1000.0_rsh
   saliref=1.0_rsh


! Bathymetry
! ----------

! assignement : input variables for cas_init_bathy routine
   depthcst = 5000.0_rsh

! flat bottom, no wall
   CALL cas_init_bathy(depthcst)


! grid parametrization
! --------------------

! assignement : input variables for cas_init_grid routine
   dxval = 1000.0_rsh
   dyval = 1000.0_rsh
   fisac=1.0_riolg
   gwac=1.0_riolg

   CALL cas_init_grid(dxval,dyval)

! over-assignement
   fu(:,:)=0.0_rsh
   fv(:,:)=0.0_rsh


! IO parametrization
! ------------------

! assignement : input variables for cas_init_io routine
   date_start=   '01/01/1900 00:00:00'
   date_end=   '02/01/1900 03:46:40'   ! to get one full cycle
   date_end=   '11/01/1900 13:46:40'   ! to get ten full cycles
   date_start3d=  '01/01/1900 00:00:00'
   date_startagrif='01/01/1900 00:00:00'

   dtmin=200.0_rlg
   dtmax=200.0_rlg
   dt=200.0_rlg
   halfdt=0.5_rlg*dt

   suffix='AdvSpot'

   CALL cas_init_io(date_start,date_end,date_start3d,date_startagrif,suffix)

! over-assignement
   pasor(1)=20.0_rlg*dt
   l_out_temp(1)=.FALSE.

   IF ((kmax==1) .AND. (l_modele2d.EQV..FALSE.) ) THEN
     l_modele2d=.TRUE.
     PRINT*,'variable l_modele2d should be set to .true. as kmax=1'
     PRINT*,'corrected directly in routine casAdvCst.F90'
   END IF

! open boundaries
! ---------------

! no open boundary
   CALL cas_init_obc

! over-assignement
! used scheme to manage obc
   l_obc_cycl = .TRUE.
   l_obc_cycl_x=.TRUE.
   l_obc_cycl_y=.TRUE.

! viscosity
!-----------
! none
   CALL cas_init_visc


! turbulence
! ----------

   z0bottom   =0.0_rsh
   z0surface  =0.0_rsh
   kzinit=0.0_rsh
   nzinit=0.0_rsh

! Gaspard parametrization
   CALL cas_init_turb(kzinit,nzinit,z0surface,z0bottom)

! over-assignement


! meteorology
! -----------

! no forcing
   CALL cas_init_meteo


! River and outflows
! -------------------

! no river
   CALL cas_init_river


! initialization of the pronostic variables
! -----------------------------------------

! set to 0,tetaref,saliref
   CALL cas_init_progvar

! over-assignement

! velocities
! ----------
   u(:,:)    = 1.0_rsh
   v(:,:)    = 1.0_rsh
   uz(:,:,:) = 1.0_rsh
   vz(:,:,:) = 1.0_rsh

! initialization of the tracers
! -----------------------------

   Lx = (imax-3d0-(ishift_obc_west+ishift_obc_east))*dxval
   Ly = (jmax-3d0-(jshift_obc_south+jshift_obc_north))*dyval
   DO j=ljmin,ljmax
     y = (j-1.5d0-jshift_obc_south)*dyval
     DO i=limin,limax
       x = (i-1.5d0-ishift_obc_west)*dxval
       sal(:,i,j)=saliref + EXP( -( (x-Lx/2.)**2/(2*(Lx/10.)**2) + (y-Ly/2.)**2/(2*(Ly/10.)**2) ) )
     END DO
   END DO

   CALL ex_i_rsh(-1,2,kmax,liminm1,limaxp2,ljminm1,ljmaxp2,sal(:,liminm1:limaxp2,ljminm1:ljmaxp2))
   CALL ex_j_rsh(-1,2,kmax,liminm1,limaxp2,ljminm1,ljmaxp2,sal(:,liminm1:limaxp2,ljminm1:ljmaxp2))




! main initialization relative to the substances
! ----------------------------------------------

! assignement : input variables for cas_init_subs routine

   nvpc=0; nvp=0; nv_cp=0; nv_fix=0; nv_dri=0; nv_int=0;
   nv_dis=1
   name_var(1)='substance'
   date_startsub=date_start

   CALL cas_init_subs(date_start)  ! nvp must be defined before

! over-assignement

! substances
   cv_wat(1,:,liminm1:limaxp2,ljminm1:ljmaxp2) = sal(:,liminm1:limaxp2,ljminm1:ljmaxp2)
   long_name_var(1)='nitrate'
   standard_name_var(1)='mole_concentration_of_nitrate_in_sea_water'
   valid_min_var(:)=-3.4e38
   valid_max_var(:)=3.4e38





! Miscellaneous
! ------------

! Domain of calculation
! Percent of wet surface on each cell
   CALL cas_init_misc

! over-assignement
   id(:)=id(:)-ishift_obc_east
   ig(:)=ig(:)+ishift_obc_west
   jh(:)=jh(:)-jshift_obc_north
   jb(:)=jb(:)+jshift_obc_south

! Periodic conditions use ig,id,jb,jh which are defined in cas_init_misc


   CALL ex_peri_x_rsh(2,kmax,liminm1,limaxp2,ljminm1,ljmaxp2,sal(:,liminm1:limaxp2,ljminm1:ljmaxp2))
   CALL ex_peri_y_rsh(2,kmax,liminm1,limaxp2,ljminm1,ljmaxp2,sal(:,liminm1:limaxp2,ljminm1:ljmaxp2))

   CALL ex_peri_x_rsh(2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(nb_var,:,liminm1:limaxp2,ljminm1:ljmaxp2))
   CALL ex_peri_y_rsh(2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(nb_var,:,liminm1:limaxp2,ljminm1:ljmaxp2))



  END SUBROUTINE cas_advspot
