 MODULE tssubeqtest
!!======================================================================
!!                   ***  MODULE  tssubeqtest  ***
!! Tracers advection : no dynamics (momentum,continuity)
!!======================================================================





























































!! * Modules used
   USE parameters, ONLY : imin,imax,jmin,jmax,kmax,rsh,        &
                          ljmin,ljmax,ljmaxp1,ljmaxp2,ljminm1, &
                          limin,limax,limaxp1,limaxp2,liminm1, &
                          liminm2,ljminm2

   USE parameters, ONLY : nb_var


   IMPLICIT NONE

   PRIVATE

!! * Accessibility
   PUBLIC tssub_eq_test                 ! routine called by step

!! * Shared or public module variables


!! * Private variables

 CONTAINS
!!======================================================================
 
  SUBROUTINE tssub_eq_test
 
!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE tssub_eq_test  ***
!&E
!&E ** Purpose :
!&E
!&E ** Description :
!&E
!&E ** Called by :
!&E
!&E ** External calls :
!&E
!&E ** Reference :
!&E
!&E ** History :
!&E       !  2008-09  (V. Garnier)  Original code
!&E       !  2010-04  (T. Odaka) MPI2D cyclic
!&E
!&E---------------------------------------------------------------------
!! * Modules used
   USE parameters,ONLY :  ishift_obc_west,ishift_obc_east, &
                          jshift_obc_south,jshift_obc_north
   USE comvarp2d, ONLY : u,v,ssh
   USE comvarp3d, ONLY : uz,vz
   USE comvarp2d, ONLY : sal,temp
   USE comvars2d, ONLY : l_obc_cycl_x,l_obc_cycl_y,l_modele2d,hey,jb,jh,id,ig


   USE comsubstance, ONLY : cv_wat,nv_adv,nvp,nb_ws_max,itypv,iv_ws_max,sv_part,ndt_part

   USE toolmpi,   ONLY : ex_i_rsh,ex_j_rsh,ex_i_rlg,ex_j_rlg ,ex_peri_x_rsh,ex_peri_y_rsh

!! * Declaration function

!! * Arguments

!! * Local declarations
   INTEGER             :: i,j,k


   INTEGER             :: l


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



! advection of tracers
! --------------------


   CALL ex_i_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))
   CALL ex_j_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))

   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))
   CALL ex_i_rsh(-1,2,kmax,liminm1,limaxp2,ljminm1,ljmaxp2,temp(:,liminm1:limaxp2,ljminm1:ljmaxp2))
   CALL ex_j_rsh(-1,2,kmax,liminm1,limaxp2,ljminm1,ljmaxp2,temp(:,liminm1:limaxp2,ljminm1:ljmaxp2))

   IF (l_modele2d) THEN
     CALL tssub2d_eq(                                             &

                     cv_wat,                                      &

                     sal,temp,ssh(limin:limax,ljmin:ljmax),ssh )
   ELSE
     CALL tssub_eq(ssh(limin:limax,ljmin:ljmax),                  &
                   ssh,sal,temp                                   &

                  ,cv_wat                                         &

                  )
! Solve equation of variables with settling velocity

     IF (nvp>0) THEN
       DO l=1,nb_ws_max
! not for gravel
         IF(itypv(iv_ws_max(l,1)) > 1 ) THEN
              CALL parsub_eq(ssh,cv_wat,sv_part(l),ndt_part(l),l)
         ENDIF
       END DO
     END IF

   END IF

! open boundary
! -------------
   IF (l_obc_cycl_x) THEN

!!!#if defined key_tssub_adv_fourthorder  || defined key_tssub_adv_fifthorder

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


!!!#if defined key_tssub_adv_fourthorder  || defined key_tssub_adv_fifthorder

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



   ELSE
     IF (limin==imin) THEN
         temp(:,imin+1+ishift_obc_west,ljmin:ljmax)=temp(:,imin+2+ishift_obc_west,ljmin:ljmax)
         temp(:,imin+ishift_obc_west,ljmin:ljmax)=temp(:,imin+1+ishift_obc_west,ljmin:ljmax)
         sal(:,imin+1+ishift_obc_west,ljmin:ljmax)=sal(:,imin+2+ishift_obc_west,ljmin:ljmax)
         sal(:,imin+ishift_obc_west,ljmin:ljmax)=sal(:,imin+1+ishift_obc_west,ljmin:ljmax)

         cv_wat(:,:,imin+1+ishift_obc_west,ljmin:ljmax)=cv_wat(:,:,imin+2+ishift_obc_west,ljmin:ljmax)
         cv_wat(:,:,imin+ishift_obc_west,ljmin:ljmax)=cv_wat(:,:,imin+1+ishift_obc_west,ljmin:ljmax)

     ENDIF
     IF (limax==imax) THEN
         temp(:,imax-ishift_obc_east,ljmin:ljmax)=temp(:,imax-1-ishift_obc_east,ljmin:ljmax)
         sal(:,imax-ishift_obc_east,ljmin:ljmax)=sal(:,imax-1-ishift_obc_east,ljmin:ljmax)

         cv_wat(:,:,imax-ishift_obc_east,ljmin:ljmax)=cv_wat(:,:,imax-1-ishift_obc_east,ljmin:ljmax)

     ENDIF
   END IF
   IF (l_obc_cycl_y) THEN

!!!#if defined key_tssub_adv_fourthorder  || defined key_tssub_adv_fifthorder

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

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



   ELSE
     IF (ljmin==jmin) THEN
         temp(:,limin:limax,jmin+1+jshift_obc_south)=temp(:,limin:limax,jmin+2+jshift_obc_south)
         temp(:,limin:limax,jmin+jshift_obc_south)=temp(:,limin:limax,jmin+1+jshift_obc_south)
         sal(:,limin:limax,jmin+1+jshift_obc_south)=sal(:,limin:limax,jmin+2+jshift_obc_south)
         sal(:,limin:limax,jmin+jshift_obc_south)=sal(:,limin:limax,jmin+1+jshift_obc_south)

         cv_wat(:,:,limin:limax,jmin+1+jshift_obc_south)=cv_wat(:,:,limin:limax,jmin+2+jshift_obc_south)
         cv_wat(:,:,limin:limax,jmin+jshift_obc_south)=cv_wat(:,:,limin:limax,jmin+1+jshift_obc_south)

     ENDIF
     IF (ljmax==jmax) THEN
         temp(:,limin:limax,jmax-jshift_obc_north)=temp(:,limin:limax,jmax-1-jshift_obc_north)
         sal(:,limin:limax,jmax-jshift_obc_north)=sal(:,limin:limax,jmax-1-jshift_obc_north)

         cv_wat(:,:,limin:limax,jmax-jshift_obc_north)=cv_wat(:,:,limin:limax,jmax-1-jshift_obc_north)

     ENDIF
   END IF

  END SUBROUTINE tssub_eq_test

 END MODULE
