  SUBROUTINE cas_advcst

!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE cas_advcst  ***
!&E
!&E ** Purpose : advection of a constant field of salinity and temperature
!&E              by a no-divergent field (Smolarkievicz configuration)
!&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 : Smolarkievicz, P. K. (2006),  Mon. Wea. Rev. 110, 1968-1983
!&E
!&E ** History :
!&E       !  2007-03  (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, &
                          ljmax,ljmaxp1,ljmaxp2,limin,liminm1,liminm2, &
                          limax,limaxp1,limaxp2
   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
   USE comvarp2d, ONLY : ssh,u,v,sal
   USE comvarp3d, ONLY : uz,vz
   USE comvars3d, ONLY : qmaxz,rhoref,saliref,kzinit,nzinit
   USE output,  ONLY : pasor
   USE obccombine, ONLY : l_obc_cycl
   USE comfluxdo,  ONLY : fxeau,fyeau

   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
   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)    :: Lx,Ly,cfl,k1
   REAL(KIND=rsh)    :: z0bottom,z0surface,depthcst
   REAL(KIND=rsh)    :: dxval,dyval
   REAL(KIND=rsh),DIMENSION(imin-1:imax,jmin-1:jmax) :: PSISM

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

   PRINT*, '!!!!!!!!!!!!!!!!!!'
   PRINT*, 'TEST CASE : AdvCst'
   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=   '04/01/1900 11:20:00'  ! time to run a back-forth
   date_start3d=  '01/01/1900 00:00:00'
   date_startagrif='01/01/1900 00:00:00'

   cfl = 0.25_rlg
   dt = 2.0_rlg*cfl*dxval
   dtmin = dt
   dtmax = dt
   halfdt=0.5_rlg*dt

   suffix='AdvCst'

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

! over-assignement
   pasor(1) = 0.5_rlg*dt

   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

! Initialization of the stream function
! -------------------------------------
   Lx = (imax-3.0_rlg)*dxval
   Ly = (jmax-3.0_rlg)*dyval
   k1 = 16.0_rlg*ATAN(1.0_rlg)
   DO j=jmin-1,jmax
   DO i=imin-1,imax
      PSISM(i,j) = (Lx*cfl*dxval/(dt*k1))*SIN(k1*(i*dxval)/Lx)*COS(k1*(j*dyval)/Ly)
   END DO
   END DO

! Initialization of the velocity field
! ------------------------------------

   DO j=ljminm2,ljmaxp2
   DO i=liminm2,limaxp2
      u(i,j) = -(PSISM(i,j)-PSISM(i,j-1))/dyval
      v(i,j) =  (PSISM(i,j)-PSISM(i-1,j))/dxval
   END DO
   END DO

   DO k=1,kmax
     uz(k,liminm2:limaxp2,ljminm2:ljmaxp2) = u(liminm2:limaxp2,ljminm2:ljmaxp2)
     vz(k,liminm2:limaxp2,ljminm2:ljmaxp2) = v(liminm2:limaxp2,ljminm2:ljmaxp2)
   END DO



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

! assignement : input variables for cas_init_subs routine

   nvpc=0; nvp=0; nv_cp=0; nv_ncp=0 ; nv_sorb=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

  END SUBROUTINE cas_advcst
