  SUBROUTINE dyn2dx_tls_coef(u,v,xev,ustar,vstar)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE dyn2dx_tls_coef  ***
   !&E
   !&E ** Purpose : Estimate of the coefficients of the tridiagonal
   !&E              linear system and the RHS relative to the
   !&E              momentum and continuity equations
   !&E
   !&E ** Description : estimate along x-direction
   !&E
   !&E ** Called by : dyn2dxy.F90
   !&E
   !&E ** External calls :
   !&E
   !&E ** Used ij-arrays : xev,u,v,ustar,vstar,igdu,hx,htx,hty,dx,dx_u,dx_v,
   !&E                     dy_f,dy_u,fu,hey,hex,surf,phieau,
   !&E                     tfiusr,vis2d,tosx,pa,potgene,buoy2d
   !&E
   !&E ** Modified variables : y2dxe,y2dv,axe,bxe,cxe,cv,bv,av
   !&E
   !&E ** Reference :
   !&E                T. Duhaut, M. Honnorat, L. Debreu, 2008 : Rapport
   !&E                contrat PREVIMER - Ref : 06/2 210 290 (pages 100-125)
   !&E
   !&E ** History :
   !&E        !  2008-07  (L. Debreu, T. Duhaut, M. Honnorat) time scheme
   !&E        !  2009-01  (A. Mano) MPI
   !&E        !  2009-01  (V. Garnier) OMP
   !&E        !  2009-01  (A. Mano T. Odaka) MPI2D
   !&E        !  2009-07  (N. Bruneau F. Dumas) coupling with swan
   !&E        !  2011-11  (V. Garnier) Spatial extension of ssh(liminm2:limaxp2,ljminm2:ljmaxp2)
   !&E        !  2014-07  (F. Ganthy) Obstruction-induced force on momentum
   !&E
   !&E---------------------------------------------------------------------

#include "toolcpp.h"

   !! * Modules used
   USE parameters
   USE comvars2d, ONLY  : botstressmax,tfiusr,ig,id,jb,jh,          &
                          htx,hty,hx,hey,hex,dx,dx_u,dy_f,surf,     &
                          dx_v,dx_f,dy_v,dy_u,fu,vis2d,halfdt,      &
                          hminfrot,dt,icon,h0,hminfrot,hmaxfrot,z0b,&
                          fwet,fwetp,frot_lin
   USE comvarp2d,  ONLY : v_utmp
   USE comfluxdo,  ONLY : nbfl,buoy2d,phieau
   USE comaree,    ONLY : l_genpot,potgene
   USE cometdyn,   ONLY : tosx,pa
   USE comvars3d,  ONLY : rhoref
   USE comcolig2d, ONLY : y2dxe,y2dv,axe,bxe,cxe,cv,bv,av,igdu,mn,ms,whx
#ifdef key_bottom_stress_wave
   USE waveforcing,ONLY : CfH,Orb_u
#endif
#ifdef key_waveforcing
   USE waveforcing,ONLY : Qx,Qy,Jsmith,Dsmith,Qy_u,k_x,k_y,hlim_calc, &
                          l_wave_brgm_phillips,l_wave_brgm_smith,     &
                          Qx_u,Qx_v,Qy_u,Qy_v,temp_radu,temp_radv
   USE_MPI toolmpi,ONLY : ex_i_rsh,ex_j_rsh
#endif
#ifdef key_obstructions
   USE obstructions,      ONLY : obst_fu_e,obst_fu_i
#endif

   IMPLICIT NONE

   !! * Arguments
   REAL(KIND=rsh), DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT(in) :: xev
   REAL(KIND=rsh), DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT(in) :: u,v,ustar,vstar

   !! * Local declarations
   INTEGER                                       :: i,j,k
   REAL(KIND=rlg)                                :: phieautot              !dyn2dx_cty.h
   REAL(KIND=rsh)  :: ft,gdt,vit,factft,vdusdy,vdudy,vdudy2,   &           !dyn2dx_mtm.h
                      udusdx,ududx,ududx2,dusdy,dusdy2,v_utmp2
#if defined key_dyn_adv_quick || defined key_dyn_adv_quickest
   REAL(KIND=rsh)  :: uc,up,um,vp,vm                                       !dyn2dx_mtm.h
#endif

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

   PRINT_DBG*, 'enter DYN2DX_TLS_COEF routine'

#ifdef key_MPI_2D
!$OMP DO SCHEDULE(RUNTIME)
#else
!$OMP DO SCHEDULE(DYNAMIC,5)
#endif
   DO j=ljminp1,ljmax
     DO i =MAX0(ig(j)-1,limin),MIN0(id(j)-1,limax)
       v_utmp(i,j)=0.25_rsh*(v(i,j)+v(i+1,j)+v(i,j-1)+v(i+1,j-1))
     END DO
   END DO
!$OMP END DO

#ifdef key_waveforcing
   CALL_MPI ex_i_rsh(-1,1,1,liminm1,limaxp1,ljminm1,ljmaxp1,v_utmp(liminm1:limaxp1,ljminm1:ljmaxp1))
   CALL_MPI ex_j_rsh(-1,1,1,liminm1,limaxp1,ljminm1,ljmaxp1,v_utmp(liminm1:limaxp1,ljminm1:ljmaxp1))
#endif

#ifdef key_MPI_2D
!$OMP DO SCHEDULE(RUNTIME)
#else
!$OMP DO SCHEDULE(DYNAMIC,5)
#endif
   DO j=ljminp2,ljmaxm1
     DO i =MAX0(ig(j),limin),MIN0(id(j)-1,limax)

#      include "dyn2dx_mtm.h"
#      include "dyn2dx_cty.h"

     END DO
   END DO
!$OMP END DO

   PRINT_DBG*, 'exit DYN2DX_TLS_COEF routine'

  END SUBROUTINE dyn2dx_tls_coef
