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

  SUBROUTINE forcing_Ktest
#ifdef key_castest

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE forcing_Ktest  ***
   !&E
   !&E ** Purpose : forcing which depend on time  in  testcase 
   !&E
   !&E ** Description : 
   !&E
   !&E ** Called by : step3dxy, step3dxy
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !          code issued form initflux.F90
   !&E       !  2005-04  (B.Thouvenin) specific for test cases
   !&E
   !&E---------------------------------------------------------------------

#include "toolcpp.h"

   !! * Modules used

   USE parameters
   USE comfluxdo,    ONLY : phieau,evap,rain
   USE comvars2d,    ONLY : surf,ijour,imois
   USE sflxatm,      ONLY : rad, senslos
   USE cometemp,     ONLY : sflx_solarcst
   USE comvars2d,    ONLY : t,tdeb,dt
   USE comvarp2d,    ONLY : temp
   USE cometdyn    , ONLY : tosx,tosy,wind_veloc,wind_dir
#if defined key_1DV_force_gradssh || defined key_1DV_force_ubarotrope
  USE cometdyn    , ONLY : gradxe_force_1DV_cste, gradxe_force_1DV_ampli,ubaro_force_1DV_cste,  &
                            ubaro_force_1DV_ampli, gradxe_force_1DV, ubaro_force_1DV,  &
                            l_force1DV_variable,modulation_ampli_tide
#endif
   IMPLICIT NONE

   !! * Arguments

   !! * Local declarations
   INTEGER :: i,j
   REAL(kind=rsh)  :: d3
   
  INTEGER,DIMENSION(31)    :: inter_vent
  REAL(kind=rsh)  :: windvit,windvit2,winddir,radpert,sinsais
  REAL(kind=rlg)  :: tdeban
 ! DATA inter_vent /1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,0/
  DATA inter_vent /1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0/
!  DATA inter_vent /1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0/

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


   IF (num_testcase==5) THEN
!$OMP PARALLEL
!$OMP DO SCHEDULE(RUNTIME)
     DO j=ljminp1,ljmax
       DO i = liminp1,limax
         phieau(kmax,i,j) = 0.001_rsh*(rain(i,j)-evap(i,j))*surf(i,j)
       END DO
     END DO
!$OMP END DO
!$OMP END PARALLEL

   ELSE IF (num_testcase == 36 .OR. num_testcase == 37 ) THEN
! cas test 1DV bio
      tdeban=INT((t-tdeb)/31536000.0_rlg)*31536000.0_rlg+tdeb
    ! sflx_solarcst=(200.0_rsh+150.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+21600000.0_rsh)))*max(0.0_rsh,sin(2*pi/86400.0_rsh*(t-tdeb-21600.0_rsh)))
     sflx_solarcst=(200.0_rsh+150.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+21600000.0_rsh)))
     rad(limin:limax,ljmin:ljmax)=sflx_solarcst*max(0.0_rsh,sin(2*pi/86400.0_rsh*(t-tdeb-21600.0_rsh)))
     radpert=-10.0_rsh+80.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeban-24480000.0_rsh))- &
                       260.0_rsh*sin(2.0_rsh*pi*tanh(0.00013_rsh*(t-tdeban-21000000.0_rsh)/3600.0_rsh))
     senslos(limin:limax,ljmin:ljmax)=radpert-sflx_solarcst*0.4_rsh

     windvit2=(wind_veloc*(1.0_rsh+0.4_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb)))*inter_vent(ijour))**2
     winddir=wind_dir+80.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+5356800))
     if(mod(t,43200.0_rlg)<=dt .and.limin==imin .and. ljmin==jmin ) THEN
    !         write(*,*) 'vent : windvit2,winddir',windvit2,winddir
             write(*,*) 't,tdeb,jour,mois',t,tdeb,ijour,imois
             write(*,*) 'solar,rad,senslos,radpert',sflx_solarcst,rad(limin,ljmax),senslos(limin,ljmax),radpert
     endif
     tosx(:,:)=-windvit2*SIN((winddir)*pi/180.0_rsh)
     tosy(:,:)=-windvit2*COS((winddir)*pi/180.0_rsh)


   ELSE IF (num_testcase == 40) THEN
! cas test 1DV  - force par pente de la surface ou par courant barotrope variable
! 
#if defined key_1DV && (defined key_1DV_force_gradssh || defined key_1DV_force_ubarotrope)

    IF(l_force1DV_variable) THEN
    
#if defined key_1DV_force_gradssh
      gradxe_force_1DV= gradxe_force_1DV_cste+gradxe_force_1DV_ampli *sin(2*pi/44700.0_rsh*(t-tdeb))   ! (m /m linear)
      
#elif key_1DV_force_ubarotrope

!  test case with key_biolo with saisonal variation
!  -------------------------------------------------
#if defined key_biolo
! variation saisonniere
      sinsais=sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+1600*3600))
      !sinsais=1.0_rsh
      !ubaro_force_1DV=0.5_rsh+0.4_rsh*sinsais+(0.6_rsh+0.3_rsh*sinsais)*  &
      ubaro_force_1DV=0.5_rsh+0.4_rsh*sinsais+ubaro_force_1DV_ampli*(1+          &
                             modulation_ampli_tide/70._rsh*   &
                            sin(2*pi/44700.0_rsh*(t-tdeb)))   &
                           *sin(2*pi/14.0_rsh/86400.0_rsh*(t-tdeb))   ! (m /s)
                           
!  test case sediment only
!  --------------------------                           
#else
!  depart maree moyenne
      ubaro_force_1DV=ubaro_force_1DV_cste +ubaro_force_1DV_ampli*(1+          &
                             modulation_ampli_tide/70._rsh*sin(2*pi/14.0_rsh/86400.0_rsh*(t-tdeb)))  &
                                   * sin(2*pi/44700.0_rsh*(t-tdeb))
#endif

#endif

!  test case with key_biolo : solar fluxes forced and also wind speed (just for test but not realistic)
!  -------------------------------------------------------------------------------------------------
#if defined key_biolo
      tdeban=INT((t-tdeb)/31536000.0_rlg)*31536000.0_rlg+tdeb
    ! sflx_solarcst=(200.0_rsh+150.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+21600000.0_rsh)))*max(0.0_rsh,sin(2*pi/86400.0_rsh*(t-tdeb-21600.0_rsh)))
     sflx_solarcst=(200.0_rsh+150.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+21600000.0_rsh)))
     rad(limin:limax,ljmin:ljmax)=sflx_solarcst*max(0.0_rsh,sin(2*pi/86400.0_rsh*(t-tdeb-21600.0_rsh)))
     !radpert=-10.0_rsh+80.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeban-24480000.0_rsh))- &
     radpert=-7.0_rsh+80.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeban-24480000.0_rsh))- &
                       260.0_rsh*sin(2.0_rsh*pi*tanh(0.00013_rsh*(t-tdeban-21000000.0_rsh)/3600.0_rsh))
     senslos(limin:limax,ljmin:ljmax)=radpert-sflx_solarcst*0.2_rsh  

     windvit2=(wind_veloc*(1.0_rsh+0.4_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb)))*inter_vent(ijour))**2
     winddir=wind_dir+80.0_rsh*sin(2*pi/365.0_rsh/86400.0_rsh*(t-tdeb+5356800))
     if(mod(t,43200.0_rlg)<=dt .and.limin==imin .and. ljmin==jmin ) THEN
    !         write(*,*) 'vent : windvit2,winddir',windvit2,winddir
             write(*,*) 't,tdeb,jour,mois',t,tdeb,ijour,imois
             write(*,*) 'solar,rad,senslos,radpert',sflx_solarcst,rad(limin,ljmax),senslos(limin,ljmax),radpert
     endif
     tosx(:,:)=-windvit2*SIN((winddir)*pi/180.0_rsh)
     tosy(:,:)=-windvit2*COS((winddir)*pi/180.0_rsh)
#endif
    ENDIF
#endif
   
   END IF

   PRINT_DBG*, 'exit forcing_Ktest routine'
#endif

  END SUBROUTINE forcing_Ktest
