Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynadv_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynadv_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynadv_tam.F90	(revision 2587)
@@ -547,5 +547,5 @@
       END IF
    END SUBROUTINE dyn_adv_ctl_tam
-
+#if defined key_tst_tlm
    SUBROUTINE dyn_adv_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -580,4 +580,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -641,5 +642,5 @@
 
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  ::  FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -696,9 +697,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_dynadv'
-
       CALL tlm_namrd
       gamma = h_ratio
-
+      file_wop='trj_wop_dynadv'
+      file_xdx='trj_xdx_dynadv'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -741,5 +741,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )      CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -769,16 +769,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL dyn_adv(nit000)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch /= 2 ) CALL dyn_adv(nit000)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------  
-         zua_out  (:,:,:) = ua   (:,:,:)
-         zva_out  (:,:,:) = va   (:,:,:)          
-
+      IF ( tlm_bch == 2 ) THEN        
          !--------------------------------------------------------------------
          ! Initialize the tangent variables 
@@ -812,4 +807,7 @@
          zua_wop  (:,:,:) = ua  (:,:,:)
          zva_wop  (:,:,:) = va  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zua_out  (:,:,:) = ua  (:,:,:)
+         zva_out  (:,:,:) = va  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -944,3 +942,4 @@
    END SUBROUTINE dyn_adv_tlm_tst
 #endif
+#endif
 END MODULE dynadv_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynhpg_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynhpg_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynhpg_tam.F90	(revision 2587)
@@ -109,5 +109,7 @@
    PUBLIC   dyn_hpg_adj    ! routine called by step_tam module
    PUBLIC   dyn_hpg_adj_tst! routine called by test module
+#if defined key_tst_tlm
    PUBLIC   dyn_hpg_tlm_tst! routine called by test module
+#endif
 
    !!* Namelist nam_dynhpg : Choice of horizontal pressure gradient computation
@@ -1059,5 +1061,5 @@
          &              )
    END SUBROUTINE dyn_hpg_adj_tst
-
+#if defined key_tst_tlm
    SUBROUTINE dyn_hpg_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -1089,4 +1091,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -1160,5 +1163,5 @@
          & jk
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  ::  FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -1228,9 +1231,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_dynhpg'
-
       CALL tlm_namrd
       gamma = h_ratio  
-
+      file_wop='trj_wop_dynhpg'
+      file_xdx='trj_xdx_dynhpg'
        !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1262,5 +1264,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )      CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -1296,16 +1298,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL dyn_hpg(nit000)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch /= 2 ) CALL dyn_hpg(nit000)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------  
-         zua_out  (:,:,:) = ua   (:,:,:)
-         zva_out  (:,:,:) = va   (:,:,:)          
-
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables 
@@ -1324,5 +1321,4 @@
          ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
          !--------------------------------------------------------------------
-
          zsp2_1    = DOT_PRODUCT( ua_tl, ua_tl  )
          zsp2_2    = DOT_PRODUCT( va_tl, va_tl  )
@@ -1334,4 +1330,7 @@
          zua_wop  (:,:,:) = ua  (:,:,:)
          zva_wop  (:,:,:) = va  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zua_out  (:,:,:) = ua  (:,:,:)
+         zva_out  (:,:,:) = va  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -1474,3 +1473,4 @@
    !!======================================================================
 #endif
+#endif
 END MODULE dynhpg_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynldf_bilap_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynldf_bilap_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynldf_bilap_tam.F90	(revision 2587)
@@ -471,16 +471,12 @@
             DO jj = jpjm1, 2, -1
                DO ji = fs_jpim1, fs_2, -1   ! vector opt.
-                  rotb_ad (ji  ,jj  ,jk) = rotb_ad (ji  ,jj  ,jk) &
-                                                  & + zlvad(ji,jj,jk) * fse3f(ji,jj  ,jk) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
-                  rotb_ad (ji-1,jj  ,jk) = rotb_ad (ji-1,jj  ,jk) &
-                                                  & - zlvad(ji,jj,jk) * fse3f(ji-1,jj,jk) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+                  zufad   (ji  ,jj  ,jk) = zufad   (ji  ,jj  ,jk) + zlvad(ji  ,jj  ,jk) / ( e1v(ji,jj) * fse3v(ji,jj,jk) ) 
+                  zufad   (ji-1,jj  ,jk) = zufad   (ji-1,jj  ,jk) - zlvad(ji  ,jj  ,jk) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )                   
                   hdivb_ad(ji  ,jj  ,jk) = hdivb_ad(ji  ,jj  ,jk) - zlvad(ji,jj,jk) / e2v(ji,jj)
                   hdivb_ad(ji  ,jj+1,jk) = hdivb_ad(ji  ,jj+1,jk) + zlvad(ji,jj,jk) / e2v(ji,jj)
                   zlvad(ji,jj,jk) = 0.0_wp
 
-                  rotb_ad (ji  ,jj  ,jk) = rotb_ad (ji  ,jj  ,jk) &
-                                                  & - zluad(ji,jj,jk) * fse3f(ji,jj  ,jk) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
-                  rotb_ad (ji  ,jj-1,jk) = rotb_ad (ji  ,jj-1,jk) &
-                                                  & + zluad(ji,jj,jk) * fse3f(ji,jj-1,jk) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+                  zufad   (ji  ,jj  ,jk) = zufad   (ji  ,jj  ,jk) - zluad(ji  ,jj  ,jk) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+                  zufad   (ji  ,jj-1,jk) = zufad   (ji  ,jj-1,jk) + zluad(ji  ,jj  ,jk) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
                   hdivb_ad(ji  ,jj  ,jk) = hdivb_ad(ji  ,jj  ,jk) - zluad(ji,jj,jk) / e1u(ji,jj)
                   hdivb_ad(ji+1,jj  ,jk) = hdivb_ad(ji+1,jj  ,jk) + zluad(ji,jj,jk) / e1u(ji,jj)
@@ -488,10 +484,5 @@
                END DO
             END DO
-!            DO jj = 1, jpj
-!               DO ji = 1, jpi
-!                  rotb_ad(ji,jj,jk) = rotb_ad(ji,jj,jk) + zufad(ji,jj,jk) * fse3f(ji,jj,jk)
-!                  zufad(ji,jj,jk) = 0.0_wp
-!               END DO
-!            END DO
+            rotb_ad(:,:,jk) = rotb_ad(:,:,jk) + zufad(:,:,jk) * fse3f(:,:,jk)
          ELSE                            ! z-coordinate - full step
             DO jj = jpjm1, 2, -1
@@ -501,5 +492,5 @@
                   hdivb_ad(ji  ,jj  ,jk) = hdivb_ad(ji  ,jj  ,jk) - zlvad(ji,jj,jk) / e2v(ji,jj)
                   hdivb_ad(ji  ,jj+1,jk) = hdivb_ad(ji  ,jj+1,jk) + zlvad(ji,jj,jk) / e2v(ji,jj)
-!                  zlvad(ji,jj,jk) = 0.0_wp
+                  zlvad(ji,jj,jk) = 0.0_wp
 
                   rotb_ad (ji  ,jj  ,jk) = rotb_ad (ji  ,jj  ,jk) - zluad(ji,jj,jk) / e2u(ji,jj)
@@ -507,5 +498,5 @@
                   hdivb_ad(ji  ,jj  ,jk) = hdivb_ad(ji  ,jj  ,jk) - zluad(ji,jj,jk) / e1u(ji,jj)
                   hdivb_ad(ji+1,jj  ,jk) = hdivb_ad(ji+1,jj  ,jk) + zluad(ji,jj,jk) / e1u(ji,jj)
-!                  zlvad(ji,jj,jk) = 0.0_wp
+                  zlvad(ji,jj,jk) = 0.0_wp
                END DO  
             END DO  
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynldf_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynldf_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynldf_tam.F90	(revision 2587)
@@ -287,5 +287,6 @@
          & ji,    &        ! dummy loop indices
          & jj,    &        
-         & jk     
+         & jk,    &
+         & jt     
       INTEGER, DIMENSION(jpi,jpj) :: &
          & iseed_2d        ! 2D seed for the random number generator
@@ -341,4 +342,9 @@
          & )
 
+      DO jt = 1, 2
+
+         IF (jt == 1) nldf=0  ! iso-level laplacian
+         IF (jt == 2) nldf=2  ! iso-level bilaplacian
+
       !==================================================================
       ! 1)      dx = ( ua_tl, va_tl, rotb_tl, hdivb_tl ) 
@@ -426,5 +432,6 @@
       va_tl   (:,:,:) = zva_tlin   (:,:,:)
 
-      CALL dyn_ldf_tan ( nit000 )
+         IF (nldf == 0 )  CALL dyn_ldf_lap_tan(   nit000 )
+         IF (nldf == 2 )  CALL dyn_ldf_bilap_tan( nit000 )
 
       zua_tlout(:,:,:) = ua_tl(:,:,:)
@@ -463,5 +470,6 @@
       va_ad(:,:,:) = zva_adin(:,:,:)
 
-      CALL dyn_ldf_adj ( nit000 )
+         IF (nldf == 0 )  CALL dyn_ldf_lap_adj(   nit000 )
+         IF (nldf == 2 )  CALL dyn_ldf_bilap_adj( nit000 )
 
       zua_adout   (:,:,:) = ua_ad   (:,:,:)
@@ -482,6 +490,9 @@
       ! Compare the scalar products
       ! 14 char:'12345678901234'
-      cl_name = 'dyn_ldf_adj   '
+         IF (nldf == 0 )  cl_name = 'dynldf_adj lap'
+         IF (nldf == 2 )  cl_name = 'dynldf_adj blp'
       CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
 
       DEALLOCATE( &
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynspg_flt_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynspg_flt_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynspg_flt_tam.F90	(revision 2587)
@@ -178,4 +178,5 @@
       & stdemp,              &
       & stdssh,              &
+      & stdgc,               &
       & prntst_adj,          &
       & prntst_tlm           
@@ -187,7 +188,8 @@
    PUBLIC dyn_spg_flt_tan,     & ! routine called by step_tan.F90
       &   dyn_spg_flt_adj,     & ! routine called by step_adj.F90
-      &   dyn_spg_flt_adj_tst, & ! routine called by the tst.F90
-      &   dyn_spg_flt_tlm_tst
-
+      &   dyn_spg_flt_adj_tst    ! routine called by the tst.F90
+#if defined key_tst_tlm
+   PUBLIC dyn_spg_flt_tlm_tst
+#endif
    !! * Substitutions
 #  include "domzgr_substitute.h90"
@@ -1395,5 +1397,5 @@
    END SUBROUTINE dyn_spg_flt_adj_tst
 
-
+#if defined key_tst_tlm
    SUBROUTINE dyn_spg_flt_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -1430,4 +1432,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -1438,7 +1441,10 @@
       USE oce       , ONLY: & ! ocean dynamics and tracers variables
         & ua, va, ub, vb,   &
+        & un, vn, &
         & sshb, sshn, wn
       USE sbc_oce   , ONLY: &
         & emp
+      USE sol_oce           , ONLY: & ! ocean dynamics and tracers variables
+        & gcb, gcx
       USE tamctl,         ONLY: & ! Control parameters
        & numtan, numtan_sc
@@ -1469,4 +1475,12 @@
          & zsshn_wop,  &
          & z2r           ! 2D field
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgcb_tlin ,     & ! Tangent input
+         & zgcx_tlin ,     & ! Tangent input
+         & zgcb_out  ,     & ! Direct output
+         & zgcx_out  ,     & ! Direct output
+         & zgcb_wop  ,     & ! Direct output without perturbation
+         & zgcx_wop  ,     & ! Direct output without perturbation
+         & zr             ! 3D random field
       REAL(KIND=wp) :: &
          & zsp1, zsp1_1, zsp1_2, zsp1_3, zsp1_4,  &   ! 
@@ -1475,4 +1489,6 @@
          & zzsp, zzsp_1, zzsp_2, zzsp_3, zzsp_4,  &
          & gamma,                                 &
+         & zsp_5,zsp1_5, zsp2_5, zsp3_5, zsp4_5,  &
+         & zzsp_5, zsp_6, &
          & zgsp1, zgsp2, zgsp3, zgsp4, zgsp5,     &
          & zgsp6, zgsp7
@@ -1485,5 +1501,5 @@
          & jk
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  ::  FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -1492,4 +1508,12 @@
          & zscsshb, zscsshn,    &
          & zscerrsshb, zscerrsshn
+      REAL(KIND=wp), DIMENSION(jpi,jpj) :: &
+         & zerrgcb, zerrgcx
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscgcb,zscgcx,             &
+         & zscerrgcb, zscerrgcx
+      INTEGER, DIMENSION(100):: &
+         & iiposgcb, ijposgcb,          &
+         & iiposgcx, ijposgcx
       INTEGER, DIMENSION(100):: &
          & iipossshb, iipossshn, iiposua, iiposva,   &
@@ -1530,4 +1554,13 @@
          & z2r(jpi,jpj)         &
          & )
+      ALLOCATE( &
+         & zgcb_tlin( jpi,jpj),     &
+         & zgcx_tlin( jpi,jpj),     &
+         & zgcb_out ( jpi,jpj),     &
+         & zgcx_out ( jpi,jpj),     &
+         & zgcb_wop ( jpi,jpj),     &
+         & zgcx_wop ( jpi,jpj),     &
+         & zr(        jpi,jpj)      &
+         & )
       !--------------------------------------------------------------------
       ! Reset variables
@@ -1562,10 +1595,19 @@
       zerrsshb(:,:)    = 0.0_wp
       zerrsshn(:,:)    = 0.0_wp
+
+      zgcb_tlin( :,:) = 0.0_wp
+      zgcx_tlin( :,:) = 0.0_wp
+      zgcb_out ( :,:) = 0.0_wp
+      zgcx_out ( :,:) = 0.0_wp
+      zgcb_wop ( :,:) = 0.0_wp
+      zgcx_wop ( :,:) = 0.0_wp
+      zr(        :,:) = 0.0_wp
       !--------------------------------------------------------------------
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_dynspg'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_dynspg'
+      file_xdx='trj_xdx_dynspg'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1630,4 +1672,16 @@
             END DO
          END DO
+         CALL grid_rd_sd( 596035, zr,  c_solver_pt, 0.0_wp, stdgc)    
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgcb_tlin(ji,jj) = zr(ji,jj)
+            END DO
+         END DO     
+         CALL grid_rd_sd( 264792, zr,  c_solver_pt, 0.0_wp, stdgc)    
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgcx_tlin(ji,jj) = zr(ji,jj)
+            END DO
+         END DO
       ENDIF    
 
@@ -1636,10 +1690,14 @@
       !-------------------------------------------------------------------
       CALL istate_p  
-
       ! *** initialize the reference trajectory
       ! ------------
       CALL  trj_rea( nit000-1, 1 )
       CALL  trj_rea( nit000, 1 )
-
+      ua(:,:,:)=un(:,:,:)
+      va(:,:,:)=vn(:,:,:)
+      ub(:,:,:)=un(:,:,:)
+      vb(:,:,:)=vn(:,:,:)
+      gcx  (:,:) =  ua(:,:,1) / 10.0_wp
+      gcb  (:,:) =  ua(:,:,3) / 10.0_wp
 
       IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
@@ -1667,4 +1725,10 @@
          zsshn_tlin(:,:) = gamma * zsshn_tlin(:,:)
          sshn(:,:)       = sshn(:,:) + zsshn_tlin(:,:)
+
+         zgcb_tlin(:,:) = gamma * zgcb_tlin(:,:)
+         gcb(:,:)       = gcb(:,:) + zgcb_tlin(:,:)
+
+         zgcx_tlin(:,:) = gamma * zgcx_tlin(:,:)
+         gcx(:,:)       = gcx(:,:) + zgcx_tlin(:,:)
       ENDIF
 
@@ -1672,17 +1736,14 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL dyn_spg_flt(nit000, indic)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch /= 2 ) CALL dyn_spg_flt(nit000, indic)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------  
-         zua_out  (:,:,:) = ua   (:,:,:)
-         zva_out  (:,:,:) = va   (:,:,:)
-         zsshb_out(:,:  ) = sshb (:,:  )
-         zsshn_out(:,:  ) = sshn (:,:  )
+      IF ( tlm_bch == 2 ) THEN
+         gcx_tl (:,:) = 0.0_wp
+         gcxb_tl(:,:) = 0.0_wp
+         gcb_tl (:,:) = 0.0_wp
          !--------------------------------------------------------------------
          ! Initialize the tangent variables 
@@ -1698,4 +1759,6 @@
          sshb_tl(:,:  ) = zsshb_tlin(:,:  )
          sshn_tl(:,:  ) = zsshn_tlin(:,:  )
+         gcb_tl  (:,:) = zgcb_tlin  (:,:)
+         gcx_tl  (:,:) = zgcx_tlin  (:,:)
 
          CALL dyn_spg_flt_tan(nit000, indic)
@@ -1708,5 +1771,8 @@
          zsp2_3    = DOT_PRODUCT( sshb_tl, sshb_tl  )
          zsp2_4    = DOT_PRODUCT( sshn_tl, sshn_tl  )
-         zsp2      = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+         zsp_5    = DOT_PRODUCT( gcx_tl, gcx_tl  )
+         zsp_6    = DOT_PRODUCT( gcxb_tl, gcxb_tl  )
+
+         zsp2      = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp_5 + zsp_6
          !--------------------------------------------------------------------
          !  Storing data
@@ -1717,4 +1783,11 @@
          zsshb_wop(:,:) = sshb(:,:)
          zsshn_wop(:,:) = sshn(:,:)
+         zgcx_wop  (:,:) = gcx  (:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zua_out  (:,:,:) = ua  (:,:,:)
+         zva_out  (:,:,:) = va  (:,:,:)
+         zsshb_out(:,:) = sshb(:,:)
+         zsshn_out(:,:) = sshn(:,:)
+         zgcx_out  (:,:) = gcx  (:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -1809,14 +1882,34 @@
             END DO
          END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgcx_out   (ji,jj) = zgcx_out    (ji,jj) - zgcx_wop  (ji,jj)
+               zgcx_wop   (ji,jj) = zgcx_out    (ji,jj) - gcx_tl    (ji,jj)
+               IF (  gcx_tl(ji,jj) .NE. 0.0_wp ) zerrgcx(ji,jj) = zgcx_out(ji,jj)/gcx_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgcx(ii) = ji
+                   ijposgcx(ii) = jj
+                   IF ( INT(tmask(ji,jj,1)) .NE. 0)  THEN
+                      zscgcx (ii)    =  zgcx_wop(ji,jj)
+                      zscerrgcx (ii) =  ( zerrgcx(ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
          zsp1_1    = DOT_PRODUCT( zua_out,   zua_out    )
          zsp1_2    = DOT_PRODUCT( zva_out,   zva_out    )
          zsp1_3    = DOT_PRODUCT( zsshb_out, zsshb_out  )
          zsp1_4    = DOT_PRODUCT( zsshn_out, zsshn_out  )
-         zsp1      = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4
+         zsp1_5   = DOT_PRODUCT( zgcx_out, zgcx_out  )
+         zsp1      = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4 + zsp1_5
          zsp3_1    = DOT_PRODUCT( zua_wop,   zua_wop    )
          zsp3_2    = DOT_PRODUCT( zva_wop,   zva_wop    )
          zsp3_3    = DOT_PRODUCT( zsshb_wop, zsshb_wop  )
          zsp3_4    = DOT_PRODUCT( zsshn_wop, zsshn_wop  )
-         zsp3      = zsp3_1 + zsp3_2 + zsp3_3 + zsp3_4
+         zsp3_5   = DOT_PRODUCT( zgcx_wop, zgcx_wop  )
+         zsp3      = zsp3_1 + zsp3_2 + zsp3_3 + zsp3_4 + zsp3_5
 
          !--------------------------------------------------------------------
@@ -1830,4 +1923,5 @@
          zzsp_3   = SQRT(zsp3_3)
          zzsp_4   = SQRT(zsp3_4)
+         zzsp_5   = SQRT(zsp3_5)
          zgsp5    = zzsp
          CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
@@ -1840,4 +1934,5 @@
          zzsp_3   = SQRT(zsp2_3)
          zzsp_4   = SQRT(zsp2_4)
+         zzsp_5   = SQRT(zsp2_5)
          zgsp4    = zzsp
          cl_name = 'dynspg_tam:Ln2'
@@ -1851,4 +1946,5 @@
          zzsp_3   = SQRT(zsp1_3)
          zzsp_4   = SQRT(zsp1_4)
+         zzsp_5   = SQRT(zsp1_5)
          cl_name  = 'dynspg:Mhdx-Mx'
          CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
@@ -1918,5 +2014,5 @@
    END SUBROUTINE dyn_spg_flt_tlm_tst
 #endif
-
+#endif
 #endif
 END MODULE dynspg_flt_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynspg_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynspg_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynspg_tam.F90	(revision 2587)
@@ -58,6 +58,8 @@
    PUBLIC dyn_spg_tan,     &   ! routine called by steptan module
       &   dyn_spg_adj,     &   ! routine called by stepadj module
-      &   dyn_spg_adj_tst, &   ! routine controlling adjoint tests
-      &   dyn_spg_tlm_tst 
+      &   dyn_spg_adj_tst      ! routine controlling adjoint tests
+#if defined key_tst_tlm
+   PUBLIC dyn_spg_tlm_tst
+#endif 
 
    !! * module variables
@@ -262,5 +264,5 @@
 
    END SUBROUTINE dyn_spg_ctl_tam
-
+#if defined key_tst_tlm
    SUBROUTINE dyn_spg_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -310,3 +312,4 @@
   !!======================================================================
 #endif
+#endif
 END MODULE dynspg_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynvor_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynvor_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynvor_tam.F90	(revision 2587)
@@ -19,4 +19,5 @@
    !!            9.0  !  08-06  (A. Vidard) Skeleton
    !!            9.0  !  09-01  (A. Vidard) TAM of the 06-11 version
+   !!            9.0  !  10-01  (F. Vigilant) Add een TAM option
    !!----------------------------------------------------------------------
 
@@ -68,4 +69,5 @@
       & e3t_0,               &
 #else
+      & e3t,                 &
       & e3u,                 &
       & e3v,                 &
@@ -81,7 +83,10 @@
       & nlej,                &
       & umask,               &
-      & vmask
+      & vmask,               &
+      & tmask
    USE dynadv        , ONLY: &
       & ln_dynadv_vec ! vector form flag
+   USE lbclnk        , ONLY: & ! Lateral boundary conditions
+      & lbc_lnk
    USE in_out_manager, ONLY: & ! I/O manager
       & ctl_stop,            &
@@ -146,12 +151,11 @@
       !
       CASE ( -1 )                                      ! esopa: test all possibility with control print
-!         CALL vor_ene_tan( kt, ntot, ua_tl, va_tl )
+         CALL vor_ene_tan( kt, ntot, ua_tl, va_tl )
          CALL vor_ens_tan( kt, ntot, ua_tl, va_tl )
 !         CALL vor_mix_tan( kt )
-!         CALL vor_een_tan( kt, ntot, ua_tl, va_tl )
+         CALL vor_een_tan( kt, ntot, ua_tl, va_tl )
          !
       CASE ( 0 )                                       ! energy conserving scheme
-         CALL ctl_stop ('vor_ene_tan not available yet')
-!         CALL vor_ene_tan( kt, ntot, ua_tl, va_tl )                ! total vorticity
+         CALL vor_ene_tan( kt, ntot, ua_tl, va_tl )                ! total vorticity
          !
       CASE ( 1 )                                       ! enstrophy conserving scheme
@@ -163,10 +167,151 @@
          !
       CASE ( 3 )                                       ! energy and enstrophy conserving scheme
-         CALL ctl_stop ('vor_een_tan not available yet')
-!         CALL vor_een_tan( kt, ntot, ua_tl, va_tl )                ! total vorticity
+         CALL vor_een_tan( kt, ntot, ua_tl, va_tl )                ! total vorticity
          !
       END SELECT
 
    END SUBROUTINE dyn_vor_tan
+   SUBROUTINE vor_ene_tan( kt, kvor, pua_tl, pva_tl )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE vor_ene  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to 
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time) 
+      !!      and the Sadourny (1975) flux form formulation : conserves the
+      !!      horizontal kinetic energy.
+      !!      The trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivatives:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)/e3f  mi(e1v*e3v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)/e3f  mj(e2u*e3u un) ]
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)  mi(e1v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)  mj(e2u un) ]
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      INTEGER , INTENT(in   )                         ::   kvor   ! =ncor (planetary) ; =ntot (total) ;
+         !                                                        ! =nrvm (relative vorticity or metric)
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua_tl    ! total u-trend
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva_tl    ! total v-trend
+      !!
+      INTEGER  ::   ji, jj, jk         ! dummy loop indices
+      REAL(wp) ::   zx1, zy1, zfact2   ! temporary scalars
+      REAL(wp) ::   zx2, zy2           !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! temporary 2D workspace
+      REAL(wp) ::   zx1tl, zy1tl   ! temporary scalars
+      REAL(wp) ::   zx2tl, zy2tl           !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwxtl, zwytl, zwztl   ! temporary 2D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_ene : vorticity term: energy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      zfact2 = 0.5 * 0.5
+
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwz(:,:) =                  ff(:,:)      ! planetary vorticity (Coriolis)
+         CASE ( 2 )   ;   zwz(:,:) =   rotn(:,:,jk)                ! relative  vorticity
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+               END DO
+            END DO
+         CASE ( 4 )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) )    ! total (relative + planetary vorticity)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ff (ji,jj)                                                                       &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                               &
+                       &       )
+               END DO
+            END DO
+         END SELECT
+         IF( ln_sco ) THEN
+            zwz(:,:) = zwz(:,:) / fse3f(:,:,jk)
+            zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         ELSE
+            zwx(:,:) = e2u(:,:) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * vn(:,:,jk)
+         ENDIF
+
+
+! Tangent counterpart
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwztl(:,:) = 0.      ! planetary vorticity (Coriolis)
+         CASE ( 2 )   ;   zwztl(:,:) =   rotn_tl(:,:,jk)                ! relative  vorticity
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwztl(ji,jj) = (   ( vn_tl(ji+1,jj  ,jk) + vn_tl (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un_tl(ji  ,jj+1,jk) + un_tl (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+               END DO
+            END DO
+         CASE ( 4 )   ;   zwztl(:,:) = rotn_tl(:,:,jk)     ! total (relative + planetary vorticity)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwztl(ji,jj) = (   ( vn_tl(ji+1,jj  ,jk) + vn_tl (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un_tl(ji  ,jj+1,jk) + un_tl(ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                              
+                     
+               END DO
+            END DO
+         END SELECT
+
+         IF( ln_sco ) THEN
+            zwztl(:,:) = zwztl(:,:) / fse3f(:,:,jk)
+            zwxtl(:,:) = e2u(:,:) * fse3u(:,:,jk) * un_tl(:,:,jk)
+            zwytl(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn_tl(:,:,jk)
+         ELSE
+            zwxtl(:,:) = e2u(:,:) * un_tl(:,:,jk)
+            zwytl(:,:) = e1v(:,:) * vn_tl(:,:,jk)
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 = zwy(ji,jj-1) + zwy(ji+1,jj-1)
+               zy2 = zwy(ji,jj  ) + zwy(ji+1,jj  )
+               zx1 = zwx(ji-1,jj) + zwx(ji-1,jj+1)
+               zx2 = zwx(ji  ,jj) + zwx(ji  ,jj+1)
+               zy1tl = zwytl(ji,jj-1) + zwytl(ji+1,jj-1)
+               zy2tl = zwytl(ji,jj  ) + zwytl(ji+1,jj  )
+               zx1tl = zwxtl(ji-1,jj) + zwxtl(ji-1,jj+1)
+               zx2tl = zwxtl(ji  ,jj) + zwxtl(ji  ,jj+1)
+               pua_tl(ji,jj,jk) = pua_tl(ji,jj,jk) + zfact2 / e1u(ji,jj) * ( zwztl(ji  ,jj-1) * zy1 + zwz(ji  ,jj-1) * zy1tl + zwztl(ji,jj) * zy2 + zwz(ji,jj) * zy2tl )
+               pva_tl(ji,jj,jk) = pva_tl(ji,jj,jk) - zfact2 / e2v(ji,jj) * ( zwztl(ji-1,jj  ) * zx1 + zwz(ji-1,jj  ) * zx1tl + zwztl(ji,jj) * zx2 + zwz(ji,jj) * zx2tl ) 
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_ene_tan
    SUBROUTINE vor_ens_tan( kt, kvor, pua_tl, pva_tl )
       !!----------------------------------------------------------------------
@@ -340,4 +485,171 @@
    END SUBROUTINE vor_ens_tan
    
+   SUBROUTINE vor_een_tan( kt, kvor, pua_tl, pva_tl )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE vor_een_tan  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to 
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time) 
+      !!      and the Arakawa and Lamb (19XX) flux form formulation : conserves 
+      !!      both the horizontal kinetic energy and the potential enstrophy
+      !!      when horizontal divergence is zero.
+      !!      The trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivatives:
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      INTEGER , INTENT(in   )                         ::   kvor   ! =ncor (planetary) ; =ntot (total) ;
+         !                                                        ! =nrvm (relative vorticity or metric)
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua_tl ! total u-trend
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva_tl ! total v-trend
+      !!
+      INTEGER ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zfac12, zua, zva   ! temporary scalars
+      REAL(wp) ::   zuatl, zvatl       ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz                    ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnw, ztne, ztsw, ztse           ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwxtl, zwytl, zwztl              ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnwtl, ztnetl, ztswtl, ztsetl   ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk), SAVE ::   ze3f
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_een_tam : vorticity term: energy and enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  ze3f(ji,jj,jk) = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &             + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) ) * 0.25_wp
+                  IF( ze3f(ji,jj,jk) /= 0.0_wp )   ze3f(ji,jj,jk) = 1.0_wp / ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( ze3f, 'F', 1._wp )
+      ENDIF
+
+      ! Local constant initialization
+      zfac12 = 1.0_wp / 12.0_wp
+      
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz, ztnw, ztne, ztsw, ztse )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   
+            zwz(:,:) = ff(:,:)      * ze3f(:,:,jk)   ! planetary vorticity (Coriolis)
+            zwztl(:,:) = 0.0_wp
+         CASE ( 2 )   
+            zwz(:,:) = rotn(:,:,jk) * ze3f(:,:,jk)   ! relative  vorticity
+            zwztl(:,:) = rotn_tl(:,:,jk) * ze3f(:,:,jk)
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwztl(ji,jj) = (   ( vn_tl(ji+1,jj  ,jk) + vn_tl (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un_tl(ji  ,jj+1,jk) + un_tl (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         CASE ( 4 )   
+            zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) ) * ze3f(:,:,jk) ! total (relative + planetary vorticity)
+            zwztl(:,:) = ( rotn_tl(:,:,jk) ) * ze3f(:,:,jk)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ff (ji,jj)                                                                       &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                               &
+                       &       ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwztl(ji,jj) = ( (   ( vn_tl(ji+1,jj  ,jk) + vn_tl (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un_tl(ji  ,jj+1,jk) + un_tl (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                               &
+                       &       ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END SELECT
+
+         zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+         zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+
+         zwxtl(:,:) = e2u(:,:) * fse3u(:,:,jk) * un_tl(:,:,jk)
+         zwytl(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn_tl(:,:,jk)
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         jj=2
+         ztne(1,:)   = 0.0_wp ; ztnw(1,:)   = 0.0_wp ; ztse(1,:)   = 0.0_wp ; ztsw(1,:)   = 0.0_wp
+         ztnetl(1,:) = 0.0_wp ; ztnwtl(1,:) = 0.0_wp ; ztsetl(1,:) = 0.0_wp ; ztswtl(1,:) = 0.0_wp
+         DO ji = 2, jpi   
+               ztne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ztnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ztse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ztsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+
+               ztnetl(ji,jj) = zwztl(ji-1,jj  ) + zwztl(ji  ,jj  ) + zwztl(ji  ,jj-1)
+               ztnwtl(ji,jj) = zwztl(ji-1,jj-1) + zwztl(ji-1,jj  ) + zwztl(ji  ,jj  )
+               ztsetl(ji,jj) = zwztl(ji  ,jj  ) + zwztl(ji  ,jj-1) + zwztl(ji-1,jj-1)
+               ztswtl(ji,jj) = zwztl(ji  ,jj-1) + zwztl(ji-1,jj-1) + zwztl(ji-1,jj  )
+         END DO
+         DO jj = 3, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               ztne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ztnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ztse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ztsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+
+               ztnetl(ji,jj) = zwztl(ji-1,jj  ) + zwztl(ji  ,jj  ) + zwztl(ji  ,jj-1)
+               ztnwtl(ji,jj) = zwztl(ji-1,jj-1) + zwztl(ji-1,jj  ) + zwztl(ji  ,jj  )
+               ztsetl(ji,jj) = zwztl(ji  ,jj  ) + zwztl(ji  ,jj-1) + zwztl(ji-1,jj-1)
+               ztswtl(ji,jj) = zwztl(ji  ,jj-1) + zwztl(ji-1,jj-1) + zwztl(ji-1,jj  )
+            END DO
+         END DO
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zuatl = + zfac12 / e1u(ji,jj) * (  ztnetl(ji,jj  ) * zwy(ji  ,jj  ) + ztne(ji,jj  ) * zwytl(ji  ,jj  )  &
+                  &                             + ztnwtl(ji+1,jj) * zwy(ji+1,jj  ) + ztnw(ji+1,jj) * zwytl(ji+1,jj  )  &
+                  &                             + ztsetl(ji,jj  ) * zwy(ji  ,jj-1) + ztse(ji,jj  ) * zwytl(ji  ,jj-1)    &
+                  &                             + ztswtl(ji+1,jj) * zwy(ji+1,jj-1) + ztsw(ji+1,jj) * zwytl(ji+1,jj-1))
+
+               zvatl = - zfac12 / e2v(ji,jj) * (  ztswtl(ji,jj+1) * zwx(ji-1,jj+1) + ztsw(ji,jj+1) * zwxtl(ji-1,jj+1)  &
+                  &                           +   ztsetl(ji,jj+1) * zwx(ji  ,jj+1) + ztse(ji,jj+1) * zwxtl(ji  ,jj+1)   &
+                  &                           +   ztnwtl(ji,jj  ) * zwx(ji-1,jj  ) + ztnw(ji,jj  ) * zwxtl(ji-1,jj  )   &
+                  &                           +   ztnetl(ji,jj  ) * zwx(ji  ,jj  ) + ztne(ji,jj  ) * zwxtl(ji  ,jj  ) )
+               pua_tl(ji,jj,jk) = pua_tl(ji,jj,jk) + zuatl
+               pva_tl(ji,jj,jk) = pva_tl(ji,jj,jk) + zvatl
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_een_tan
+
+   
    SUBROUTINE dyn_vor_adj( kt )
       !!----------------------------------------------------------------------
@@ -360,5 +672,5 @@
       !
       CASE ( -1 )                                      ! esopa: test all possibility with control print
-!         CALL vor_een_adj( kt, ntot, ua_ad, va_ad )
+         CALL vor_een_adj( kt, ntot, ua_ad, va_ad )
 !         CALL vor_mix_adj( kt )
          CALL vor_ens_adj( kt, ntot, ua_ad, va_ad )
@@ -377,6 +689,5 @@
          !
       CASE ( 3 )                                       ! energy and enstrophy conserving scheme
-         CALL ctl_stop ('vor_een_adj not available yet')
-!         CALL vor_een_adj( kt, ntot, ua_ad, va_ad )                ! total vorticity
+         CALL vor_een_adj( kt, ntot, ua_ad, va_ad )                ! total vorticity
          !
       END SELECT
@@ -417,6 +728,7 @@
       !!
       INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   zfact1, zuav, zvau   ! temporary scalars
+      REAL(wp) ::   zfact1               ! temporary scalars
       REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz         ! temporary 3D workspace
+      REAL(wp) ::   zuav, zvau       ! temporary scalars
       REAL(wp) ::   zuavad, zvauad   ! temporary scalars
       REAL(wp), DIMENSION(jpi,jpj) ::   zwxad, zwyad, zwzad   ! temporary 3D workspace
@@ -581,4 +893,242 @@
    END SUBROUTINE vor_ens_adj
 
+
+   SUBROUTINE vor_een_adj( kt, kvor, pua_ad, pva_ad )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE vor_een_adj  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to 
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time) 
+      !!      and the Arakawa and Lamb (19XX) flux form formulation : conserves 
+      !!      both the horizontal kinetic energy and the potential enstrophy
+      !!      when horizontal divergence is zero.
+      !!      The trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivatives:
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      INTEGER , INTENT(in   )                         ::   kvor   ! =ncor (planetary) ; =ntot (total) ;
+         !                                                        ! =nrvm (relative vorticity or metric)
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua_ad ! total u-trend
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva_ad ! total v-trend
+      !!
+      INTEGER ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zfac12             ! temporary scalars
+      REAL(wp) ::   zuaad, zvaad       ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz                    ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnw, ztne, ztsw, ztse           ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwxad, zwyad, zwzad              ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnwad, ztnead, ztswad, ztsead   ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk), SAVE ::   ze3f
+      !!----------------------------------------------------------------------
+
+      ! local adjoint initailization
+      zuaad = 0.0_wp ; zvaad = 0.0_wp
+      zwxad (:,:) = 0.0_wp ; zwyad (:,:) = 0.0_wp ; zwzad (:,:) = 0.0_wp
+      ztnwad(:,:) = 0.0_wp ; ztnead(:,:) = 0.0_wp ; ztswad(:,:) = 0.0_wp ; ztsead(:,:) = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_een_adj : vorticity term: energy and enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  ze3f(ji,jj,jk) = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &             + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) ) * 0.25_wp
+                  IF( ze3f(ji,jj,jk) /= 0.0_wp )   ze3f(ji,jj,jk) = 1.0_wp / ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( ze3f, 'F', 1._wp )
+      ENDIF
+
+      ! Local constant initialization
+      zfac12 = 1.0_wp / 12.0_wp
+   
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz, ztnw, ztne, ztsw, ztse )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! Potential vorticity and horizontal fluxes  (Direct local variables init)
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwz(:,:) =  ff(:,:) * ze3f(:,:,jk)      ! planetary vorticity (Coriolis)
+         CASE ( 2 )   ;   zwz(:,:) =   rotn(:,:,jk) * ze3f(:,:,jk)                ! relative  vorticity
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )  &
+                       &       - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) ) )&
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         CASE ( 4 )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) ) * ze3f(:,:,jk)    ! total (relative + planetary vorticity)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ff (ji,jj)                         &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )  &
+                       &       ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END SELECT
+
+         zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+         zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         jj=2
+         ztne(1,:)   = 0.0_wp ; ztnw(1,:)   = 0.0_wp ; ztse(1,:)   = 0.0_wp ; ztsw(1,:)   = 0.0_wp
+         DO ji = 2, jpi   
+               ztne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ztnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ztse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ztsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+         END DO
+         DO jj = 3, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               ztne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ztnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ztse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ztsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+            END DO
+         END DO
+
+      ! ===================
+      ! Adjoint counterpart
+      ! ===================
+
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zuaad = zuaad + pua_ad(ji,jj,jk)
+               zvaad = zvaad + pva_ad(ji,jj,jk)
+
+               zvaad = - zvaad * zfac12 / e2v(ji,jj)
+               ztswad(ji  ,jj+1) = ztswad(ji  ,jj+1) + zvaad * zwx (ji-1,jj+1)
+               zwxad (ji-1,jj+1) = zwxad (ji-1,jj+1) + zvaad * ztsw(ji  ,jj+1)
+               ztsead(ji  ,jj+1) = ztsead(ji  ,jj+1) + zvaad * zwx (ji  ,jj+1)
+               zwxad (ji  ,jj+1) = zwxad (ji  ,jj+1) + zvaad * ztse(ji  ,jj+1)
+               ztnwad(ji  ,jj  ) = ztnwad(ji  ,jj  ) + zvaad * zwx (ji-1,jj  )
+               zwxad (ji-1,jj  ) = zwxad (ji-1,jj  ) + zvaad * ztnw(ji  ,jj  )
+               ztnead(ji  ,jj  ) = ztnead(ji  ,jj  ) + zvaad * zwx (ji  ,jj  )
+               zwxad (ji  ,jj  ) = zwxad (ji  ,jj  ) + zvaad * ztne(ji  ,jj  )
+               zvaad = 0.0_wp
+
+               zuaad = zuaad * zfac12 / e1u(ji,jj)
+               ztnead(ji  ,jj  ) = ztnead(ji  ,jj  ) + zuaad * zwy (ji  ,jj  )
+               zwyad (ji  ,jj  ) = zwyad (ji  ,jj  ) + zuaad * ztne(ji  ,jj  )
+               ztnwad(ji+1,jj  ) = ztnwad(ji+1,jj  ) + zuaad * zwy (ji+1,jj  )
+               zwyad (ji+1,jj  ) = zwyad (ji+1,jj  ) + zuaad * ztnw(ji+1,jj  )
+               ztsead(ji  ,jj  ) = ztsead(ji  ,jj  ) + zuaad * zwy (ji  ,jj-1)
+               zwyad (ji  ,jj-1) = zwyad (ji  ,jj-1) + zuaad * ztse(ji  ,jj  )
+               ztswad(ji+1,jj  ) = ztswad(ji+1,jj  ) + zuaad * zwy (ji+1,jj-1)
+               zwyad (ji+1,jj-1) = zwyad (ji+1,jj-1) + zuaad * ztsw(ji+1,jj  )
+               zuaad = 0.0_wp
+            END DO  
+         END DO 
+         DO jj = jpj, 3, -1
+            DO ji = jpi, fs_2, -1   ! vector opt.
+               zwzad (ji  ,jj-1) = zwzad(ji  ,jj-1) + ztswad(ji,jj) 
+               zwzad (ji-1,jj-1) = zwzad(ji-1,jj-1) + ztswad(ji,jj)
+               zwzad (ji-1,jj  ) = zwzad(ji-1,jj  ) + ztswad(ji,jj)
+               ztswad(ji  ,jj  ) = 0.0_wp
+               zwzad (ji  ,jj  ) = zwzad(ji  ,jj  ) + ztsead(ji,jj)
+               zwzad (ji  ,jj-1) = zwzad(ji  ,jj-1) + ztsead(ji,jj)
+               zwzad (ji-1,jj-1) = zwzad(ji-1,jj-1) + ztsead(ji,jj)
+               ztsead(ji,jj)     = 0.0_wp
+               zwzad (ji-1,jj-1) = zwzad(ji-1,jj-1) + ztnwad(ji,jj)
+               zwzad (ji-1,jj  ) = zwzad(ji-1,jj  ) + ztnwad(ji,jj)
+               zwzad (ji  ,jj  ) = zwzad(ji  ,jj  ) + ztnwad(ji,jj)
+               ztnwad(ji  ,jj  ) = 0.0_wp
+               zwzad (ji-1,jj  ) = zwzad(ji-1,jj  ) + ztnead(ji,jj)
+               zwzad (ji  ,jj  ) = zwzad(ji  ,jj  ) + ztnead(ji,jj)
+               zwzad (ji  ,jj-1) = zwzad(ji  ,jj-1) + ztnead(ji,jj)
+               ztnead(ji,jj)     = 0.0_wp
+            END DO
+         END DO
+         jj=2
+         DO ji = jpi, 2, -1   
+               zwzad (ji  ,jj-1) = zwzad(ji  ,jj-1) + ztswad(ji,jj)
+               zwzad (ji-1,jj-1) = zwzad(ji-1,jj-1) + ztswad(ji,jj)
+               zwzad (ji-1,jj  ) = zwzad(ji-1,jj  ) + ztswad(ji,jj)
+               ztswad(ji,jj) = 0.0_wp
+               zwzad (ji  ,jj  ) = zwzad(ji  ,jj  ) + ztsead(ji,jj)
+               zwzad (ji  ,jj-1) = zwzad(ji  ,jj-1) + ztsead(ji,jj)
+               zwzad (ji-1,jj-1) = zwzad(ji-1,jj-1) + ztsead(ji,jj)
+               ztsead(ji  ,jj  ) = 0.0_wp
+               zwzad (ji-1,jj-1) = zwzad(ji-1,jj-1) + ztnwad(ji,jj)
+               zwzad (ji-1,jj  ) = zwzad(ji-1,jj  ) + ztnwad(ji,jj)
+               zwzad (ji  ,jj  ) = zwzad(ji  ,jj  ) + ztnwad(ji,jj)
+               ztnwad(ji  ,jj ) = 0.0_wp
+               zwzad (ji-1,jj  ) = zwzad(ji-1,jj  ) + ztnead(ji,jj)
+               zwzad (ji  ,jj  ) = zwzad(ji  ,jj  ) + ztnead(ji,jj)
+               zwzad (ji  ,jj-1) = zwzad(ji  ,jj-1) + ztnead(ji,jj)
+               ztnead(ji  ,jj  ) = 0.0_wp
+         END DO
+         ztnead(1,:)   = 0.0_wp ; ztnwad(1,:)   = 0.0_wp 
+         ztsead(1,:)   = 0.0_wp ; ztswad(1,:)   = 0.0_wp
+
+         vn_ad(:,:,jk) = vn_ad(:,:,jk) + zwyad(:,:) * e1v(:,:) * fse3v(:,:,jk)
+         un_ad(:,:,jk) = un_ad(:,:,jk) + zwxad(:,:) * e2u(:,:) * fse3u(:,:,jk)
+         zwyad(:,:)    = 0.0_wp
+         zwxad(:,:)    = 0.0_wp
+
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   
+            zwzad(:,:) = 0.0_wp
+         CASE ( 2 )   
+            rotn_ad(:,:,jk) = rotn_ad(:,:,jk) +  zwzad(:,:) * ze3f(:,:,jk)
+            zwzad(:,:)      = 0.0_wp
+         CASE ( 3 )                                                ! metric term
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1, -1   ! vector opt.
+                  zwzad(ji  ,jj     ) = zwzad(ji,jj) * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+                  vn_ad(ji+1,jj  ,jk) =   vn_ad(ji+1,jj  ,jk) + zwzad(ji,jj) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )
+                  vn_ad(ji  ,jj  ,jk) =   vn_ad(ji  ,jj  ,jk) + zwzad(ji,jj) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )
+                  un_ad(ji  ,jj+1,jk) = - un_ad(ji  ,jj+1,jk) + zwzad(ji,jj) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )
+                  un_ad(ji  ,jj  ,jk) = - un_ad(ji  ,jj  ,jk) + zwzad(ji,jj) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )
+                  zwzad(ji  ,jj     ) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 4 )   
+            rotn_ad(:,:,jk) = rotn_ad(:,:,jk) + zwzad(:,:) * ze3f(:,:,jk)
+            zwzad(:,:) = 0.0_wp
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1, -1   ! vector opt.
+                  zwzad(ji  ,jj     ) = zwzad(ji,jj) * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+
+                  vn_ad(ji+1,jj  ,jk) = vn_ad(ji+1,jj  ,jk) + zwzad(ji,jj) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )
+                  vn_tl(ji  ,jj  ,jk) = vn_tl(ji  ,jj  ,jk) + zwzad(ji,jj) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )
+                  un_ad(ji  ,jj+1,jk) = un_ad(ji  ,jj+1,jk) - zwzad(ji,jj) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )
+                  un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) - zwzad(ji,jj) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )
+
+                  zwzad(ji  ,jj     ) = 0.0_wp
+               END DO
+            END DO
+         END SELECT
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_een_adj
+
    SUBROUTINE vor_ctl_tam
       !!---------------------------------------------------------------------
@@ -599,5 +1149,5 @@
          WRITE(numout,*) 'dyn:vor_ctl_tam : vorticity term : read namelist and control the consistency'
          WRITE(numout,*) '~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '        Namelist nam_dynvor : oice of the vorticity term scheme'
+         WRITE(numout,*) '        Namelist nam_dynvor : choice of the vorticity term scheme'
          WRITE(numout,*) '           energy    conserving scheme                ln_dynvor_ene = ', ln_dynvor_ene
          WRITE(numout,*) '           enstrophy conserving scheme                ln_dynvor_ens = ', ln_dynvor_ens
@@ -679,5 +1229,6 @@
          & ji,    &        ! dummy loop indices
          & jj,    &        
-         & jk     
+         & jk,    &
+         & jt     
       INTEGER, DIMENSION(jpi,jpj) :: &
          & iseed_2d        ! 2D seed for the random number generator
@@ -738,4 +1289,11 @@
          & )
 
+      ! init ntot parameter
+      CALL vor_ctl_tam          ! initialisation & control of options
+
+      DO jt = 1, 2
+         IF (jt == 1) nvor=1 ! enstrophy conserving scheme
+         IF (jt == 2) nvor=3 ! energy and enstrophy conserving scheme
+
       ! Initialize rotn
       CALL div_cur ( nit000 )
@@ -816,8 +1374,5 @@
       END DO
       CALL grid_random( iseed_2d, zav, 'V', 0.0_wp, stdv )
-!zun_tlin(:,:,:) = znu(:,:,:) 
-!zvn_tlin(:,:,:) = znv(:,:,:) 
-!zua_tlin(:,:,:) = zau(:,:,:) 
-!zva_tlin(:,:,:) = zav(:,:,:)
+
       DO jk = 1, jpk
          DO jj = nldj, nlej
@@ -837,5 +1392,5 @@
       ! initialize rotn_tl with noise
       CALL div_cur_tan ( nit000 )
-!zrotn_tlin(:,:,:) = rotn_tl(:,:,:)
+
       DO jk = 1, jpk
         DO jj = nldj, nlej
@@ -847,5 +1402,7 @@
       rotn_tl(:,:,:) = zrotn_tlin(:,:,:)
 
-      CALL dyn_vor_tan( nit000 )
+
+         IF (nvor == 1 )  CALL vor_ens_tan( nit000, ntot, ua_tl, va_tl )
+         IF (nvor == 3 )  CALL vor_een_tan( nit000, ntot, ua_tl, va_tl )
       zua_tlout(:,:,:) = ua_tl(:,:,:)
       zva_tlout(:,:,:) = va_tl(:,:,:)
@@ -882,6 +1439,7 @@
       va_ad(:,:,:) = zva_adin(:,:,:)
 
-      CALL dyn_vor_adj ( nitend )
-
+
+         IF (nvor == 1 )  CALL vor_ens_adj( nitend, ntot, ua_ad, va_ad )
+         IF (nvor == 3 )  CALL vor_een_adj( nitend, ntot, ua_ad, va_ad )
       zun_adout(:,:,:)   = un_ad(:,:,:)
       zvn_adout(:,:,:)   = vn_ad(:,:,:)
@@ -900,6 +1458,9 @@
 
       ! 14 char:'12345678901234'
-      cl_name = 'dyn_vor_adj   '
+         IF (nvor == 1 )  cl_name = 'dynvor_adj ens'
+         IF (nvor == 3 )  cl_name = 'dynvor_adj een'
+
       CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+      END DO
 
       DEALLOCATE( &
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzad_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzad_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzad_tam.F90	(revision 2587)
@@ -131,8 +131,8 @@
       DO jj = 2, jpjm1              ! Surface and bottom values set to zero
          DO ji = fs_2, fs_jpim1           ! vector opt.
-            zwuwtl(ji,jj, 1 ) = 0.e0
-            zwvwtl(ji,jj, 1 ) = 0.e0
-            zwuwtl(ji,jj,jpk) = 0.e0
-            zwvwtl(ji,jj,jpk) = 0.e0
+            zwuwtl(ji,jj, 1 ) = 0.0_wp
+            zwvwtl(ji,jj, 1 ) = 0.0_wp
+            zwuwtl(ji,jj,jpk) = 0.0_wp
+            zwvwtl(ji,jj,jpk) = 0.0_wp
          END DO
       END DO
@@ -210,4 +210,12 @@
          END DO
       END DO
+      DO jj = 2, jpjm1              ! Surface and bottom values set to zero
+         DO ji = fs_2, fs_jpim1           ! vector opt.
+            zwuwad(ji,jj, 1 ) = 0.0_wp
+            zwvwad(ji,jj, 1 ) = 0.0_wp
+            zwuwad(ji,jj,jpk) = 0.0_wp
+            zwvwad(ji,jj,jpk) = 0.0_wp
+         END DO
+      END DO
       DO jk = jpkm1, 2, -1             ! Vertical momentum advection at level w and u- and v- vertical
          DO jj = 2, jpj                   ! vertical fluxes 
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzdf_exp_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzdf_exp_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzdf_exp_tam.F90	(revision 2587)
@@ -20,5 +20,46 @@
    !! * Modules used
 
-   USE in_out_manager  ! I/O manager
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpim1,               &
+      & jpjm1,               & 
+      & jpkm1
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers
+      & ub_tl,               &
+      & vb_tl,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & ub_ad,               &
+      & vb_ad,               &
+      & ua_ad,               &
+      & va_ad
+   USE zdf_oce       , ONLY: & ! ocean vertical physics
+      & avmu,                &
+      & avmv,                &
+      & n_zdfexp
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+#if defined key_zco
+      & e3t_0,               &
+      & e3w_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3uw,                &
+      & e3vw,                &
+#endif
+      & umask,               &
+      & vmask
+   USE phycst        , ONLY: & ! physical constants
+      & rau0
+   USE in_out_manager, ONLY: & ! I/O manager
+      & nit000,              &
+      & nitend,              &
+      & numout,              &
+      & lwp,                 &
+      & ctl_stop
    IMPLICIT NONE
    PRIVATE
@@ -59,6 +100,6 @@
       !! * Local declarations
       INTEGER ::   ji, jj, jk, jl                              ! dummy loop indices
-      REAL(wp) ::   zrau0r, zlavmr, zua, zva                   ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpk) ::   zwx, zwy, zwz, zww     ! temporary workspace arrays
+      REAL(wp) ::   zrau0r, zlavmr, zuatl, zvatl                   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpk) ::   zwxtl, zwytl, zwztl, zwwtl     ! temporary workspace arrays
       !!----------------------------------------------------------------------
 
@@ -68,6 +109,58 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~ '
       ENDIF
-
-      CALL ctl_stop ('dyn_zdf_exp_tan not available yet')
+      ! Local constant initialization
+      ! -----------------------------
+      zrau0r = 1. / rau0                                   ! inverse of the reference density
+      zlavmr = 1. / float( n_zdfexp )                      ! inverse of the number of sub time step
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+
+         ! Surface boundary condition
+         DO ji = 2, jpim1
+            zwytl(ji,1) = 0.0_wp
+            zwwtl(ji,1) = 0.0_wp
+         END DO  
+
+         ! Initialization of x, z and contingently trends array
+         DO jk = 1, jpk
+            DO ji = 2, jpim1
+               zwxtl(ji,jk) = ub_tl(ji,jj,jk)
+               zwztl(ji,jk) = vb_tl(ji,jj,jk)
+            END DO  
+         END DO  
+
+         ! Time splitting loop
+         DO jl = 1, n_zdfexp
+
+            ! First vertical derivative
+            DO jk = 2, jpk
+               DO ji = 2, jpim1
+                  zwytl(ji,jk) = avmu(ji,jj,jk) * ( zwxtl(ji,jk-1) - zwxtl(ji,jk) ) / fse3uw(ji,jj,jk) 
+                  zwwtl(ji,jk) = avmv(ji,jj,jk) * ( zwztl(ji,jk-1) - zwztl(ji,jk) ) / fse3vw(ji,jj,jk)
+               END DO  
+            END DO  
+
+            ! Second vertical derivative and trend estimation at kt+l*rdt/n_zdfexp
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  zuatl = zlavmr*( zwytl(ji,jk) - zwytl(ji,jk+1) ) / fse3u(ji,jj,jk)
+                  zvatl = zlavmr*( zwwtl(ji,jk) - zwwtl(ji,jk+1) ) / fse3v(ji,jj,jk)
+                  ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + zuatl
+                  va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + zvatl
+
+                  zwxtl(ji,jk) = zwxtl(ji,jk) + p2dt*zuatl*umask(ji,jj,jk)
+                  zwztl(ji,jk) = zwztl(ji,jk) + p2dt*zvatl*vmask(ji,jj,jk)
+               END DO  
+            END DO  
+
+         END DO  
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+
    END SUBROUTINE dyn_zdf_exp_tan
    SUBROUTINE dyn_zdf_exp_adj( kt, p2dt )
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzdf_imp_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzdf_imp_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/DYN/dynzdf_imp_tam.F90	(revision 2587)
@@ -126,5 +126,5 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                zcoef = - p2dt / fse3u(ji,jj,jk)
-               zwi(ji,jj,jk) = zcoef * avmu(ji,jj,jk  ) / fse3uw(ji,jj,jk  )
+               zwi(ji,jj,jk) = zcoef * avmu(ji,jj,jk  ) / fse3uw(ji,jj,jk  ) * umask(ji,jj,jk)
                zzws          = zcoef * avmu(ji,jj,jk+1) / fse3uw(ji,jj,jk+1)
                zws(ji,jj,jk) = zzws  * umask(ji,jj,jk+1)
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SBC/sbc_oce_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SBC/sbc_oce_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SBC/sbc_oce_tam.F90	(revision 2587)
@@ -28,4 +28,5 @@
    PUBLIC &
       & sbc_oce_tam_init, & !: Initialize the TAM fields
+      & sbc_oce_tam_deallocate, & !: Deallocate the TAM fields
    !!----------------------------------------------------------------------
    !!              Ocean Surface Boundary Condition fields
@@ -295,4 +296,71 @@
 
    END SUBROUTINE sbc_oce_tam_init
+   SUBROUTINE sbc_oce_tam_deallocate( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_oce_tam_init  ***
+      !!
+      !! ** Purpose : Allocate and initialize the tangent linear and 
+      !!              adjoint arrays
+      !!
+      !! ** Method  : kindic = 0  deallocate both tl and ad variables
+      !!              kindic = 1  deallocate only tl variables
+      !!              kindic = 2  deallocate only ad variables
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 2010-06 (A. Vidard) Initial version 
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to deallocate
+
+      !! * Local declarations
+      
+      ! Deallocate tangent linear variable arrays
+      ! ---------------------------------------
+      
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( ALLOCATED(utau_tl) )    DEALLOCATE( utau_tl )
+         IF ( ALLOCATED(vtau_tl) )    DEALLOCATE( vtau_tl )
+         IF ( ALLOCATED(wndm_tl) )    DEALLOCATE( wndm_tl )
+         IF ( ALLOCATED(qns_tl) )     DEALLOCATE( qns_tl )
+         IF ( ALLOCATED(qsr_tl) )     DEALLOCATE( qsr_tl )
+         IF ( ALLOCATED(emp_tl) )     DEALLOCATE( emp_tl )
+         IF ( ALLOCATED(emps_tl) )    DEALLOCATE( emps_tl )
+         IF ( ALLOCATED(fr_i_tl) )    DEALLOCATE( fr_i_tl )
+         IF ( ALLOCATED(ssu_m_tl) )   DEALLOCATE( ssu_m_tl )
+         IF ( ALLOCATED(ssv_m_tl) )   DEALLOCATE( ssv_m_tl )
+         IF ( ALLOCATED(sst_m_tl) )   DEALLOCATE( sst_m_tl )
+         IF ( ALLOCATED(sss_m_tl) )   DEALLOCATE( sss_m_tl )
+
+
+      ENDIF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+
+         ! Deallocate adjoint variable arrays
+         ! --------------------------------
+      
+         IF ( ALLOCATED(utau_ad) )    DEALLOCATE( utau_ad )
+         IF ( ALLOCATED(vtau_ad) )    DEALLOCATE( vtau_ad )
+         IF ( ALLOCATED(wndm_ad) )    DEALLOCATE( wndm_ad )
+         IF ( ALLOCATED(qns_ad) )     DEALLOCATE( qns_ad )
+         IF ( ALLOCATED(qsr_ad) )     DEALLOCATE( qsr_ad )
+         IF ( ALLOCATED(emp_ad) )     DEALLOCATE( emp_ad )
+         IF ( ALLOCATED(emps_ad) )    DEALLOCATE( emps_ad )
+         IF ( ALLOCATED(fr_i_ad) )    DEALLOCATE( fr_i_ad )
+         IF ( ALLOCATED(ssu_m_ad) )   DEALLOCATE( ssu_m_ad )
+         IF ( ALLOCATED(ssv_m_ad) )   DEALLOCATE( ssv_m_ad )
+         IF ( ALLOCATED(sst_m_ad) )   DEALLOCATE( sst_m_ad )
+         IF ( ALLOCATED(sss_m_ad) )   DEALLOCATE( sss_m_ad )
+         
+      ENDIF
+
+   END SUBROUTINE sbc_oce_tam_deallocate
 #endif
 
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SOL/sol_oce_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SOL/sol_oce_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SOL/sol_oce_tam.F90	(revision 2587)
@@ -31,7 +31,10 @@
       & nmax_fs
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   USE sol_oce       , ONLY: &
+      & nmin
+#if defined key_dynspg_flt
    USE solver        , ONLY: & ! Solver
       & solver_init
-
+#endif
    !! * Routine accessibility
    
@@ -41,4 +44,5 @@
    PUBLIC &
       & sol_oce_tam_init, & !: routine called by nemovar.F90
+      & sol_oce_tam_deallocate, &
                     !
       & gcx_tl,   & !: Tangent of now solution of the elliptic equation
@@ -48,6 +52,6 @@
       & gcx_ad,   & !: Adjoint of solution of the elliptic equation
       & gcxb_ad,  & !: Adjoint of before solution of the elliptic equation
-      & gcb_ad      !: Adjoint of 2nd member of barotropic linear system
-
+      & gcb_ad ,  & !: Adjoint of 2nd member of barotropic linear system
+      & nitsor
    !! * Module variables
    INTEGER, DIMENSION(:), ALLOCATABLE :: &
@@ -89,15 +93,16 @@
          & kindic        ! indicate which variables to allocate/initialize
 
+#if defined key_dynspg_flt
       IF ( kindic == 0 .OR. kindic == 1 ) THEN
 
+         IF ( kindic == 0 ) CALL solver_init( nit000 )
+
          IF ( .NOT. ALLOCATED(nitsor) ) THEN
 
             ALLOCATE( nitsor( nitend - nit000 + 1 ) )
-
-         ENDIF
-
-         nitsor(:) = nmax_fs
-
-      IF ( kindic == 0 ) CALL solver_init( nit000 )
+            nitsor(:) = nmin
+
+         ENDIF
+
 
       ENDIF
@@ -162,6 +167,55 @@
 
       ENDIF
-
+#endif
    END SUBROUTINE sol_oce_tam_init
-
+   SUBROUTINE sol_oce_tam_deallocate(kindic)
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sol_oce_tam_deallocate  ***
+      !!
+      !! ** Purpose : 
+      !!
+      !! ** Method  : kindic = 0  deallocate both tl and ad variables
+      !!              kindic = 1  deallocate only tl variables
+      !!              kindic = 2  deallocate only ad variables
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!         ! 2010-06 (A. Vidard) Initial version
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to allocate/initialize
+#if defined key_dynspg_flt
+      IF ( kindic == 0 ) THEN
+         IF ( ALLOCATED(nitsor) )  DEALLOCATE( nitsor )
+      END IF
+
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( ALLOCATED(gcx_tl) )  DEALLOCATE( gcx_tl  )
+
+         IF ( ALLOCATED(gcxb_tl) ) DEALLOCATE( gcxb_tl )
+
+         IF ( ALLOCATED(gcb_tl) )  DEALLOCATE( gcb_tl  )
+
+         IF ( ALLOCATED(gcr_tl) )  DEALLOCATE( gcr_tl  )
+
+      ENDIF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+
+         IF ( ALLOCATED(gcx_ad) )  DEALLOCATE( gcx_ad  )
+
+         IF ( ALLOCATED(gcxb_ad) ) DEALLOCATE( gcxb_ad )
+
+         IF ( ALLOCATED(gcb_ad) )  DEALLOCATE( gcb_ad  )
+
+      ENDIF
+      
+#endif
+   END SUBROUTINE sol_oce_tam_deallocate
 END MODULE sol_oce_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SOL/solsor_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SOL/solsor_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/SOL/solsor_tam.F90	(revision 2587)
@@ -19,5 +19,5 @@
       & jpiglo
    USE in_out_manager, ONLY: & ! I/O manager 
-      & nit000
+      & nit000, lwp
    USE sol_oce       , ONLY: & ! solver variables
       & gcdmat,              &
@@ -71,5 +71,6 @@
    USE tstool_tam    , ONLY: &
       & prntst_adj,          &
-      & stdgc
+      & stdgc,               &
+      & prntst_tlm
    
 
@@ -80,6 +81,8 @@
    PUBLIC sol_sor_adj          ! 
    PUBLIC sol_sor_tan          ! 
-   PUBLIC sol_sor_adj_tst      ! called by tst.F90
-
+   PUBLIC sol_sor_adj_tst      ! called by tamtst.F90
+#if defined key_tst_tlm
+   PUBLIC sol_sor_tlm_tst      ! called by tamtst.F90
+#endif
 
 CONTAINS
@@ -194,5 +197,5 @@
       
          ! test of convergence
-         IF ( jn > nmin .AND. MOD( jn-nmin, nmod ) == 0 ) THEN
+         IF ( (jn > nmin .AND. MOD( jn-nmin, nmod ) == 0) .OR. jn==nmax) THEN
 
             SELECT CASE ( nsol_arp )
@@ -232,4 +235,5 @@
          ENDIF
          ! indicator of non-convergence or explosion
+	     IF( jn == nmax ) nitsor(istp) = jn
          IF( jn == nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2
          IF( ncut == 999 ) GOTO 999
@@ -318,10 +322,9 @@
       ijmppodd  = MOD(nimpp+njmpp+jpr2di+jpr2dj+1,2)
       ijpr2d = MAX(jpr2di,jpr2dj)
-      icount = 0
 
       ! Fixed number of iterations
       istp = kt - nit000 + 1
       iter = nitsor(istp)
-
+      icount = iter * 2
       !  Output in gcx_ad
       !  ----------------
@@ -330,5 +333,5 @@
 
       !                                                    ! ==============
-      DO jn = 1, iter                                      ! Iterative loop 
+      DO jn = iter, 1, -1                                  ! Iterative loop 
          !                                                 ! ==============
          ! Guess red update
@@ -349,6 +352,5 @@
             END DO
          END DO
-         icount = icount + 1 
-         
+	     icount = icount - 1         
          ! applied the lateral boundary conditions
          IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp )   ! Lateral BCs
@@ -375,6 +377,5 @@
          END DO
 
-         icount = icount + 1 
- 
+	     icount = icount - 1 
          ! applied the lateral boundary conditions
          IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp )   ! Lateral BCs
@@ -418,4 +419,5 @@
          & jk,    &        
          & kindic,&        ! flags fo solver convergence
+         & kmod,  &        ! frequency of test for the SOR solver
          & kt              ! number of iteration
       INTEGER, DIMENSION(jpi,jpj) :: &
@@ -465,6 +467,8 @@
 
       kt=nit000
+      kindic=0
+!      kmod = nmod  ! store frequency of test for the SOR solver
+!      nmod = 1     ! force frequency to one (remove adj_tst dependancy to nn_nmin)
          
-
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -491,5 +495,6 @@
          END DO
       END DO
-
+      ncut = 1 ! reinitilize the solver convergence flag
+      gcr_tl(:,:) = 0.0_wp
       gcb_tl(:,:) = zgcb_tlin(:,:)
       gcx_tl(:,:) = zgcx_tlin(:,:)
@@ -502,5 +507,4 @@
       !--------------------------------------------------------------------
 
-      DO jk = 1, jpk
         DO jj = nldj, nlej
            DO ji = nldi, nlei
@@ -510,5 +514,4 @@
             END DO
          END DO
-      END DO
       !--------------------------------------------------------------------
       ! Compute the scalar product: ( L dx )^T W dy
@@ -520,5 +523,5 @@
       ! Call the adjoint routine: dx^* = L^T dy^*
       !--------------------------------------------------------------------
-
+      gcb_ad(:,:) = 0.0_wp
       gcx_ad(:,:) = zgcx_adin(:,:)
       CALL sol_sor_adj(kt, kindic) 
@@ -533,4 +536,6 @@
       cl_name = 'sol_sor_adj   '
       CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+!      nmod = kmod  ! restore initial frequency of test for the SOR solver
 
       DEALLOCATE(      &
@@ -547,4 +552,324 @@
 
    END SUBROUTINE sol_sor_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE sol_sor_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the tangent routine.
+      !!
+      !! ** Method  : Verify the tangent with Taylor expansion 
+      !!           
+      !!                 M(x+hdx) = M(x) + L(hdx) + O(h^2)
+      !!
+      !!              where  L   = tangent routine
+      !!                     M   = direct routine
+      !!                     dx  = input perturbation (random field)
+      !!                     h   = ration on perturbation 
+      !!   
+      !!    In the tangent test we verify that:
+      !!                M(x+h*dx) - M(x)
+      !!        g(h) = ------------------ --->  1    as  h ---> 0
+      !!                    L(h*dx)
+      !!    and
+      !!                g(h) - 1
+      !!        f(h) = ----------         --->  k (costant) as  h ---> 0
+      !!                    p
+      !!                  
+      !! History :
+      !!        ! 10-02 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+#if defined key_tam
+      !! * Modules used
+      USE solsor             ! Red-Black Successive Over-Relaxation solver
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE wzvmod             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE sol_oce           , ONLY: & ! ocean dynamics and tracers variables
+        & gcb, gcx, ncut
+      USE oce       , ONLY: & ! 
+        & ua, ub, un
+      USE opatam_tst_ini, ONLY: &
+       & tlm_namrd
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
    
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &        
+         & kindic,&        ! flags fo solver convergence
+         & kt              ! number of iteration
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) ::   &
+         & zsp1, zsp2, zsp3, & ! scalar product
+         & zsp_gcb, zsp_gcx, &
+         & zsp,         &
+         & gamma,        &
+         & zgsp1,        &
+         & zgsp2,        &
+         & zgsp3,        &
+         & zgsp4,        &
+         & zgsp5,        &
+         & zgsp6,        &
+         & zgsp7
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgcb_tlin ,     & ! Tangent input
+         & zgcx_tlin ,     & ! Tangent input
+         & zgcb_out  ,     & ! Direct output
+         & zgcx_out  ,     & ! Direct output
+         & zgcb_wop  ,     & ! Direct output without perturbation
+         & zgcx_wop  ,     & ! Direct output without perturbation
+         & zr             ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscgcb,zscgcx,             &
+         & zscerrgcb, zscerrgcx
+      INTEGER, DIMENSION(100)::       &
+         & iiposgcb, ijposgcb,          &
+         & iiposgcx, ijposgcx
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj) :: &
+         & zerrgcb, zerrgcx
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zgcb_tlin( jpi,jpj),     &
+         & zgcx_tlin( jpi,jpj),     &
+         & zgcb_out ( jpi,jpj),     &
+         & zgcx_out ( jpi,jpj),     &
+         & zgcb_wop ( jpi,jpj),     &
+         & zgcx_wop ( jpi,jpj),     &
+         & zr(        jpi,jpj)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zgcb_tlin( :,:) = 0.0_wp
+      zgcx_tlin( :,:) = 0.0_wp
+      zgcb_out ( :,:) = 0.0_wp
+      zgcx_out ( :,:) = 0.0_wp
+      zgcb_wop ( :,:) = 0.0_wp
+      zgcx_wop ( :,:) = 0.0_wp
+      zr(        :,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+      CALL tlm_namrd
+      gamma = h_ratio   
+      file_wop='trj_wop_solsor'
+      file_xdx='trj_xdx_solsor'
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, zr,  c_solver_pt, 0.0_wp, stdgc)    
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgcb_tlin(ji,jj) = zr(ji,jj)
+            END DO
+         END DO     
+         CALL grid_rd_sd( 264792, zr,  c_solver_pt, 0.0_wp, stdgc)    
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgcx_tlin(ji,jj) = zr(ji,jj)
+            END DO
+         END DO
+      ENDIF
+
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      CALL istate_p
+
+      ! *** initialize the reference trajectory
+      ! ------------
+
+!      gcx  (:,:) = ( ua(:,:,1) + ub(:,:,1) ) / 10.0_wp
+!      gcb  (:,:) = ( ua(:,:,3) + ub(:,:,3) ) / 10.0_wp
+      CALL  trj_rea( nit000-1, 1 ) 
+      CALL  trj_rea( nit000, 1 )
+      gcx  (:,:) =  un(:,:,1) / 10.0_wp
+      gcb  (:,:) =  un(:,:,3) / 10.0_wp
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zgcb_tlin(:,:) = gamma * zgcb_tlin(:,:)
+         gcb(:,:)       = gcb(:,:) + zgcb_tlin(:,:)
+
+         zgcx_tlin(:,:) = gamma * zgcx_tlin(:,:)
+         gcx(:,:)       = gcx(:,:) + zgcx_tlin(:,:)
+      ENDIF 
+
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      kindic=0
+      ncut=1
+      IF ( tlm_bch /= 2 ) CALL sol_sor(kindic)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
+      !--------------------------------------------------------------------
+      !  Compute the Tangent 
+      !--------------------------------------------------------------------
+      IF ( tlm_bch == 2 ) THEN
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables: dy^* = W dy  
+         !--------------------------------------------------------------------
+         gcr_tl(:,:) = 0.0_wp
+         gcb_tl  (:,:) = zgcb_tlin  (:,:)
+         gcx_tl  (:,:) = zgcx_tlin  (:,:)
+
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !-----------------------------------------------------------------------
+         ncut=1 !reset indicator of solver convergence
+         CALL sol_sor_tan(nit000, kindic)
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+
+         zsp_gcx    = DOT_PRODUCT( gcx_tl, gcx_tl  )
+         zsp2       = zsp_gcx
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zgcx_wop  (:,:) = gcx  (:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zgcx_out  (:,:) = gcx  (:,:)
+         !--------------------------------------------------------------------
+         ! Compute the Linearization Error 
+         ! Nn = M( X0+gamma.dX0, t0,tn) - M(X0, t0,tn)
+         ! and 
+         ! Compute the Linearization Error 
+         ! En = Nn -TL(gamma.dX0, t0,tn)
+         !--------------------------------------------------------------------
+         ! Warning: Here we re-use local variables z()_out and z()_wop
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgcx_out   (ji,jj) = zgcx_out    (ji,jj) - zgcx_wop  (ji,jj)
+               zgcx_wop   (ji,jj) = zgcx_out    (ji,jj) - gcx_tl    (ji,jj)
+               IF (  gcx_tl(ji,jj) .NE. 0.0_wp ) zerrgcx(ji,jj) = zgcx_out(ji,jj)/gcx_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgcx(ii) = ji
+                   ijposgcx(ii) = jj
+                   IF ( INT(tmask(ji,jj,1)) .NE. 0)  THEN
+                      zscgcx (ii)    =  zgcx_wop(ji,jj)
+                      zscerrgcx (ii) =  ( zerrgcx(ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+
+         zsp_gcx   = DOT_PRODUCT( zgcx_out, zgcx_out  )
+
+         zsp1      = zsp_gcx
+
+         zsp_gcx   = DOT_PRODUCT( zgcx_wop, zgcx_wop  )
+
+         zsp3      = zsp_gcx
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'sol_sor: En   '
+         zsp    = SQRT(zsp3)
+         zgsp5   = zsp
+         CALL prntst_tlm( cl_name, kumadt, zsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zsp      = SQRT(zsp2)
+
+         zgsp4    = zsp
+         cl_name  = 'sol_sor: Ln2 '
+         CALL prntst_tlm( cl_name, kumadt, zsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zsp     = SQRT(zsp1)
+
+         cl_name = 'solsor:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zsp, h_ratio )
+
+         zgsp3    = SQRT( zsp3/zsp2 )
+         zgsp7    = zgsp3/gamma
+         zgsp1    = zsp
+         zgsp2    = zgsp1 / zgsp4
+         zgsp6    = (zgsp2 - 1.0_wp)/gamma
+
+         FMT = "(A8,2X,I4.4,2X,E6.1,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13)"
+         WRITE(numtan,FMT) 'solsor  ', cur_loop, h_ratio, zgsp1, zgsp2, zgsp3, zgsp4, zgsp5, zgsp6, zgsp7
+         !--------------------------------------------------------------------
+         ! Unitary calculus
+         !--------------------------------------------------------------------
+         FMT = "(A8,2X,A8,2X,I4.4,2X,E6.1,2X,I4.4,2X,I4.4,2X,I4.4,2X,E20.13,1X)"
+         cl_name ='sol_sor '
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscgcx(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgcx    ', &
+                    & cur_loop, h_ratio, ii, iiposgcx(ii), ijposgcx(ii), zscgcx(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrgcx(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrgcx ', &
+                    & cur_loop, h_ratio, ii, iiposgcx(ii), ijposgcx(ii), zscerrgcx(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(      &
+         & zgcb_tlin,  &
+         & zgcx_tlin,  &
+         & zgcb_out ,  &
+         & zgcx_out ,  &
+         & zgcb_wop ,  &
+         & zgcx_wop ,  &
+         & zr          &
+         & )
+#else
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      ! dummy routine
+#endif
+   END SUBROUTINE sol_sor_tlm_tst
+#endif   
 END MODULE solsor_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TAM/trj_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TAM/trj_tam.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TAM/trj_tam.F90	(revision 2587)
@@ -0,0 +1,929 @@
+MODULE trj_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE trj_tam ***
+   !! NEMOVAR trajectory: Allocate and read the trajectory for linearzation
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   bkg_init : Initialize the background fields from disk
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : & ! Precision variables
+      & wp
+   USE par_oce, ONLY : &  ! Ocean space and time domain variables
+      & jpi, jpj, jpk
+   USE tamtrj             ! Parameters for the assmilation interface
+   USE in_out_manager, ONLY : & ! I/O manager
+      & lwp 
+   USE oce                ! Model variables 
+   USE zdf_oce            ! Vertical mixing variables
+   USE zdfddm             ! Double diffusion mixing parameterization
+   USE ldftra_oce         ! Lateral tracer mixing coefficient defined in memory
+   USE ldfslp             ! Slopes of neutral surfaces
+   USE tradmp             ! Tracer damping
+   USE sbc_oce            ! Ocean surface boundary conditions
+   USE iom                ! Library to read input files
+
+   USE zdfmxl, ONLY : &   ! mixed layer depth
+      & hmlp
+   USE divcur             ! horizontal divergence and relative vorticity
+   USE wzvmod             !  vertical velocity
+  
+   USE oce_tam, ONLY : &      ! Dynamics and active tracers defined in memory
+      & un_tl, vn_tl, tn_tl, &
+      & wn_tl, hdivn_tl, rotn_tl,              &
+#if defined key_dynspg_flt
+      & sshn_tl, &
+#endif
+      & sn_tl
+  
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+   PUBLIC &
+      & trj_rea,     &   !: Read trajectory at time step kstep into now fields
+      & trj_rd_spl,  &   !: Read simple data (without interpolation)
+      & trj_wri_spl, &   !: Write simple data (without interpolation)
+      & tl_trj_wri,  &   !: Write simple linear-tangent data
+      & tl_trj_ini,  &   !: initialize the model-tangent state trajectory
+      & trj_deallocate   !: Deallocate all the saved variable
+
+   LOGICAL, PUBLIC :: & 
+      & ln_trjwri_tan = .FALSE.   !: No output of the state trajectory fields
+
+   CHARACTER (LEN=40), PUBLIC, PARAMETER :: &
+      & c_tantrj = 'tl_trajectory'                !: Filename for storing the 
+                                                   !: linear-tangent trajectory
+   INTEGER, PUBLIC :: &          
+      & nittrjfrq_tan         !: Frequency of trajectory output for linear-tangent
+
+   !! * Module variables
+   LOGICAL, SAVE :: & 
+      & ln_mem = .FALSE.      !: Flag for allocation 
+   INTEGER, SAVE :: inumtrj1 = -1, inumtrj2 = -1
+   REAL(wp), SAVE :: &
+      & stpr1, &
+      & stpr2
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:), SAVE :: &
+      & empr1,    &
+      & empsr1,   &   
+      & empr2,    &
+      & empsr2
+#if defined key_traldf_eiv
+#if defined key_traldf_c3d
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), SAVE :: &
+#elif defined key_traldf_c2d
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:), SAVE :: &
+#elif defined key_traldf_c1d
+   REAL(wp), ALLOCATABLE, DIMENSION(:), SAVE :: &
+#else
+   REAL(wp) ::
+#endif
+      & aeiur1,   &
+      & aeivr1,   &
+      & aeiwr1,   & 
+      & aeiur2,   &
+      & aeivr2,   &
+      & aeiwr2
+#endif
+  REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), SAVE :: &
+      & unr1,     &
+      & vnr1,     &
+      & tnr1,     &
+      & snr1,     &
+      & avmur1,   &
+      & avmvr1,   &
+      & avtr1,    &
+      & uslpr1,   &
+      & vslpr1,   &
+      & wslpir1,  &
+      & wslpjr1,  &
+      & avsr1,    &
+      & tar1,     &
+      & sar1,     &
+      & tbr1,     &
+      & sbr1,     &
+      & unr2,     &
+      & vnr2,     &
+      & tnr2,     &
+      & snr2,     &
+      & avmur2,   &
+      & avmvr2,   &
+      & avtr2,    &
+      & uslpr2,   &
+      & vslpr2,   &
+      & wslpir2,  &
+      & wslpjr2,  &
+      & avsr2,    &
+      & tar2,     &
+      & sar2,     &
+      & tbr2,     &
+      & sbr2
+  REAL(wp), ALLOCATABLE, DIMENSION(:,:), SAVE :: &
+      & hmlp1,    &
+      & hmlp2  
+      
+CONTAINS
+
+   SUBROUTINE tl_trj_ini
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tl_trj_ini ***
+      !!
+      !! ** Purpose : initialize the model-tangent state trajectory 
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 10-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Modules used
+      NAMELIST/namtl_trj/ nittrjfrq_tan, ln_trjwri_tan
+
+      ln_trjwri_tan = .FALSE.
+      nittrjfrq_tan = 1
+
+      REWIND ( numnam )
+      READ   ( numnam, namtl_trj )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tl_trj_ini : Linear-Tagent Trajectory handling:'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namtl_trj : set trajectory parameters'
+         WRITE(numout,*) '             Logical switch for writing out state trajectory         ', &
+            &            ' ln_trjwri_tan = ', ln_trjwri_tan
+         WRITE(numout,*) '             Frequency of trajectory output                          ', &
+            &            ' nittrjfrq_tan = ', nittrjfrq_tan
+      END IF
+   END SUBROUTINE tl_trj_ini
+
+   SUBROUTINE trj_rea( kstp, kdir )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE trj_reat  ***
+      !!
+      !! ** Purpose : Read from file the trjectory from the outer loop
+      !!
+      !! ** Method  : IOM
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 08-05 (K. Mogensen) Initial version
+      !!        ! 09-03 (F.Vigilant) Add reading of hmlp and calls (divcur, wzvmod)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(in) :: &
+         & kstp, &           ! Step for requested trajectory
+         & kdir              ! Direction for stepping (1 forward, -1 backward)
+      !! * Local declarations
+      CHARACTER (LEN=100) :: &
+         & cl_asmtrj
+      INTEGER :: &
+         & inrcm,  &
+         & inrcp,  &
+         & inrc,   &
+         & istpr1, &
+         & istpr2, &
+	 & it
+      REAL(KIND=wp) :: &
+         & zwtr1, &
+         & zwtr2, &
+         & zden,  &
+         & zstp
+
+      ! Initialize data and open file
+      !! if step time is corresponding to a saved state
+      IF ( ( MOD( kstp - nit000 + 1, nittrjfrq ) == 0 )  ) THEN       
+
+         it = kstp - nit000 + 1
+
+         IF ( inumtrj1 == -1 ) THEN
+
+            ! Define the input file 
+            WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', it
+
+            !         WRITE(cl_asmtrj, FMT='(A,".nc")' ) TRIM( c_asmtrj )
+            cl_asmtrj = TRIM( cl_asmtrj )
+
+            IF(lwp) THEN
+
+               WRITE(numout,*)
+               WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
+               WRITE(numout,*)
+
+            ENDIF
+            CALL iom_open( cl_asmtrj, inumtrj1 )     
+            if ( inumtrj1 == -1)  CALL ctl_stop( 'No tam_trajectory cl_amstrj found' )
+   
+            ALLOCATE( &
+               & empr1(jpi,jpj),  &
+               & empsr1(jpi,jpj), &
+               & empr2(jpi,jpj),  &
+               & empsr2(jpi,jpj)  &
+               & )
+
+            ALLOCATE( &
+               & unr1(jpi,jpj,jpk),     &
+               & vnr1(jpi,jpj,jpk),     &
+               & tnr1(jpi,jpj,jpk),     &
+               & snr1(jpi,jpj,jpk),     &
+               & avmur1(jpi,jpj,jpk),   &
+               & avmvr1(jpi,jpj,jpk),   &
+               & avtr1(jpi,jpj,jpk),    &
+               & tar1(jpi,jpj,jpk),     &
+               & sar1(jpi,jpj,jpk),     &
+               & tbr1(jpi,jpj,jpk),     &
+               & sbr1(jpi,jpj,jpk),     &
+               & unr2(jpi,jpj,jpk),     &
+               & vnr2(jpi,jpj,jpk),     &
+               & tnr2(jpi,jpj,jpk),     &
+               & snr2(jpi,jpj,jpk),     &
+               & avmur2(jpi,jpj,jpk),   &
+               & avmvr2(jpi,jpj,jpk),   &
+               & avtr2(jpi,jpj,jpk),    &
+               & tar2(jpi,jpj,jpk),     &
+               & sar2(jpi,jpj,jpk),     &
+               & tbr2(jpi,jpj,jpk),     &
+               & sbr2(jpi,jpj,jpk)      &
+               & )
+
+#if defined key_traldf_eiv
+#if defined key_traldf_c3d
+#elif defined key_traldf_c2d
+            ALLOCATE( &
+               & aeiur1(jpi,jpj), &
+               & aeivr1(jpi,jpj), &
+               & aeiwr1(jpi,jpj), &
+               & aeiur2(jpi,jpj), &
+               & aeivr2(jpi,jpj), &
+               & aeiwr2(jpi,jpj)  &
+               & )
+#elif defined key_traldf_c1d
+#endif
+#endif
+
+#if defined key_ldfslp
+            ALLOCATE( &
+               & uslpr1(jpi,jpj,jpk),   &
+               & vslpr1(jpi,jpj,jpk),   &
+               & wslpir1(jpi,jpj,jpk),  &
+               & wslpjr1(jpi,jpj,jpk),  &
+               & uslpr2(jpi,jpj,jpk),   &
+               & vslpr2(jpi,jpj,jpk),   &
+               & wslpir2(jpi,jpj,jpk),  &
+               & wslpjr2(jpi,jpj,jpk)   &
+               & )
+#endif
+
+#if defined key_zdfddm
+            ALLOCATE( &
+               & avsr1(jpi,jpj,jpk),    &
+               & avsr2(jpi,jpj,jpk)     &
+               & )
+#endif
+
+#if defined key_tradmp
+            ALLOCATE( &
+               & hmlp1(jpi,jpj),    &
+               & hmlp2(jpi,jpj)     &
+               & )
+#endif
+	    ln_mem = .TRUE.
+
+         ENDIF
+
+
+      ! Read records
+
+         inrcm = INT( ( kstp - nit000 + 1 ) / nittrjfrq ) + 1
+
+         ! Copy record 1 into record 2
+
+         IF ( ( kstp /= nitend )         .AND. &
+            & ( kstp - nit000 + 1 /= 0 ) .AND. &
+            & ( kdir == -1 ) ) THEN
+
+            stpr2           = stpr1
+
+            empr2   (:,:)   = empr1   (:,:)
+            empsr2  (:,:)   = empsr1  (:,:)
+
+            unr2    (:,:,:) = unr1    (:,:,:)
+            vnr2    (:,:,:) = vnr1    (:,:,:)
+            tnr2    (:,:,:) = tnr1    (:,:,:)
+            snr2    (:,:,:) = snr1    (:,:,:)
+            avmur2  (:,:,:) = avmur1  (:,:,:)
+            avmvr2  (:,:,:) = avmvr1  (:,:,:)
+            avtr2   (:,:,:) = avtr1   (:,:,:)
+#if defined key_ldfslp
+            uslpr2  (:,:,:) = uslpr1  (:,:,:)
+            vslpr2  (:,:,:) = vslpr1  (:,:,:)
+            wslpir2 (:,:,:) = wslpir1 (:,:,:)
+            wslpjr2 (:,:,:) = wslpjr1 (:,:,:)
+#endif
+#if defined key_zdfddm
+            avsr2   (:,:,:) = avsr1   (:,:,:)
+#endif
+            tar2    (:,:,:) = tar1    (:,:,:)
+            sar2    (:,:,:) = sar1    (:,:,:)
+            tbr2    (:,:,:) = tbr1    (:,:,:)
+            sbr2    (:,:,:) = sbr1    (:,:,:)
+#if defined key_tradmp
+            hmlp1   (:,:)   = hmlp2   (:,:)
+#endif
+#if defined key_traldf_eiv  
+#if defined key_traldf_c3d
+            aeiur2  (:,:,:) = aeiur1  (:,:,:)
+            aeivr2  (:,:,:) = aeivr1  (:,:.:)
+            aeiwr2  (:,:,:) = aeiwr1  (:,:.:)
+#elif defined key_traldf_c2d
+            aeiur2  (:,:)   = aeiur1  (:,:)
+            aeivr2  (:,:)   = aeivr1  (:,:)
+            aeiwr2  (:,:)   = aeiwr1  (:,:)
+#elif defined key_traldf_c1d
+            aeiur2  (:)     = aeiur1  (:)
+            aeivr2  (:)     = aeivr1  (:)
+            aeiwr2  (:)     = aeiwr1  (:)
+#else
+            aeiur2          = aeiur1     
+            aeivr2          = aeivr1     
+            aeiwr2          = aeiwr1     
+#endif
+#endif
+
+            istpr1 = INT( stpr1 )
+
+            IF(lwp) WRITE(numout,*) &
+               &                 '    Trajectory record copy time step = ', istpr1
+
+         ENDIF
+
+         IF ( ( kstp - nit000 + 1 /= 0 ) .AND. ( kdir == -1 ) ) THEN
+            ! We update the input filename 
+            WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', (it-nittrjfrq)
+            cl_asmtrj = TRIM( cl_asmtrj )
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
+               WRITE(numout,*)
+            ENDIF
+         ENDIF
+
+         ! Read record 1
+
+         IF ( ( kstp - nit000 + 1 == 0 ) .AND.( kdir == 1           ) .OR. &
+            & ( kstp - nit000 + 1 /= 0 ) .AND.( kdir == -1          ) ) THEN
+
+            IF ( kdir == -1 ) inrcm = inrcm - 1
+!            inrc = inrcm
+            ! temporary fix: currently, only one field by step time
+            inrc = 1
+            stpr1 = (inrcm - 1) * nittrjfrq
+
+            ! bug fixed to read several time the initial data
+            IF ( ( kstp - nit000 + 1 == 0 ) .AND. ( kdir == 1 ) ) THEN
+               ! Define the input file 
+               WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', it
+
+               cl_asmtrj = TRIM( cl_asmtrj )
+
+               IF(lwp) THEN
+                  WRITE(numout,*)
+                  WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
+                  WRITE(numout,*)
+               ENDIF
+            END IF
+            IF ( inumtrj1 /= -1 )   CALL iom_open( cl_asmtrj, inumtrj1 )
+
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'emp'   , empr1   , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'emps'  , empsr1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'un'    , unr1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'vn'    , vnr1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'tn'    , tnr1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'sn'    , snr1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'avmu'  , avmur1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'avmv'  , avmvr1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'avt'   , avtr1   , inrc )
+#if defined key_ldfslp
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'uslp'  , uslpr1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'vslp'  , vslpr1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'wslpi' , wslpir1 , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'wslpj' , wslpjr1 , inrc )
+#endif
+#if defined key_zdfddm
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'avs'   , avsr1   , inrc )
+#endif
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'ta'    , tar1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'sa'    , sar1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'tb'    , tbr1    , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'sb'    , sbr1    , inrc )
+#if defined key_tradmp
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'hmlp'  , hmlp1   , inrc )
+#endif
+#if defined key_traldf_eiv
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'aeiu'  , aeiur1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'aeiv'  , aeivr1  , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'aeiw'  , aeiwr1  , inrc )
+#endif
+            CALL iom_close( inumtrj1 )
+
+            istpr1 = INT( stpr1 )
+            IF(lwp)WRITE(numout,*) '   trajectory read time step = ', istpr1,&
+               &                   '  record = ', inrc
+
+         ENDIF
+
+
+         ! Copy record 2 into record 1
+
+         IF ( ( kstp - nit000 + 1 /= 0 ) .AND. &
+            & ( kstp /= nitend         ) .AND. &
+            & ( kdir == 1              ) ) THEN
+
+            stpr1           = stpr2
+            empr1   (:,:)   = empr2   (:,:)
+            empsr1  (:,:)   = empsr2  (:,:)
+            unr1    (:,:,:) = unr2    (:,:,:)
+            vnr1    (:,:,:) = vnr2    (:,:,:)
+            tnr1    (:,:,:) = tnr2    (:,:,:)
+            snr1    (:,:,:) = snr2    (:,:,:)
+            avmur1  (:,:,:) = avmur2  (:,:,:)
+            avmvr1  (:,:,:) = avmvr2  (:,:,:)
+            avtr1   (:,:,:) = avtr2   (:,:,:)
+#if defined key_ldfslp
+            uslpr1  (:,:,:) = uslpr2  (:,:,:)
+            vslpr1  (:,:,:) = vslpr2  (:,:,:)
+            wslpir1 (:,:,:) = wslpir2 (:,:,:)
+            wslpjr1 (:,:,:) = wslpjr2 (:,:,:)
+#endif
+#if defined key_zdfddm
+            avsr1   (:,:,:) = avsr2   (:,:,:)
+#endif
+            tar1    (:,:,:) = tar2    (:,:,:)
+            sar1    (:,:,:) = sar2    (:,:,:)
+            tbr1    (:,:,:) = tbr2    (:,:,:)
+            sbr1    (:,:,:) = sbr2    (:,:,:)
+#if defined key_tradmp
+            hmlp1   (:,:)   = hmlp2   (:,:)
+#endif
+#if defined key_traldf_eiv  
+#if defined key_traldf_c3d
+            aeiur1  (:,:,:) = aeiur2  (:,:,:)
+            aeivr1  (:,:,:) = aeivr2  (:,:.:)
+            aeiwr1  (:,:,:) = aeiwr2  (:,:.:)
+#elif defined key_traldf_c2d
+            aeiur1  (:,:)   = aeiur2  (:,:)
+            aeivr1  (:,:)   = aeivr2  (:,:)
+            aeiwr1  (:,:)   = aeiwr2  (:,:)
+#elif defined key_traldf_c1d
+            aeiur1  (:)     = aeiur2  (:)
+            aeivr1  (:)     = aeivr2  (:)
+            aeiwr1  (:)     = aeiwr2  (:)
+#else
+            aeiur1          = aeiur2     
+            aeivr1          = aeivr2     
+            aeiwr1          = aeiwr2     
+#endif
+#endif
+
+            istpr1 = INT( stpr1 )
+            IF(lwp) WRITE(numout,*) &
+               &                 '   Trajectory record copy time step = ', istpr1
+
+         ENDIF
+
+         ! Read record 2
+
+         IF ( ( ( kstp /= nitend ) .AND. ( kdir == 1  )) .OR. &
+            &   ( kstp == nitend ) .AND.(  kdir == -1   ) ) THEN
+
+               ! Define the input file 
+               IF  (  kdir == -1   ) THEN
+                   WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', (it)
+               ELSE      
+                  WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', (it+nittrjfrq)
+               ENDIF
+               cl_asmtrj = TRIM( cl_asmtrj )
+
+               IF(lwp) THEN        
+                  WRITE(numout,*)
+                  WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
+                  WRITE(numout,*)        
+               ENDIF
+
+               CALL iom_open( cl_asmtrj, inumtrj2 ) 
+
+
+            inrcp = inrcm + 1
+            !            inrc  = inrcp
+            inrc = 1  ! temporary  fix
+
+            stpr2 = (inrcp - 1) * nittrjfrq 
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'emp'   , empr2   , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'emps'  , empsr2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'un'    , unr2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'vn'    , vnr2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'tn'    , tnr2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'sn'    , snr2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'avmu'  , avmur2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'avmv'  , avmvr2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'avt'   , avtr2   , inrc )
+#if defined key_ldfslp
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'uslp'  , uslpr2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'vslp'  , vslpr2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'wslpi' , wslpir2 , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'wslpj' , wslpjr2 , inrc )
+#endif
+#if defined key_zdfddm
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'avs'   , avsr2   , inrc )
+#endif
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'ta'    , tar2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'sa'    , sar2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'tb'    , tbr2    , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'sb'    , sbr2    , inrc )
+#if defined key_tradmp
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'hmlp'  , hmlp2   , inrc )
+#endif
+#if defined key_traldf_eiv
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'aeiu'  , aeiur2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'aeiv'  , aeivr2  , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'aeiw'  , aeiwr2  , inrc )
+#endif
+            CALL iom_close( inumtrj2 )
+
+            istpr2 = INT( stpr2 )
+            IF(lwp)WRITE(numout,*) '   trajectory read2 time step = ', istpr2,&
+               &                   '  record = ', inrc
+         ENDIF
+
+      ENDIF
+
+      ! Add warning for user
+      IF ( (kstp == nitend) .AND. ( MOD( kstp - nit000 + 1, nittrjfrq ) /= 0 )  ) THEN
+          IF(lwp) WRITE(numout,*) '   Warning ! nitend (=',nitend, ')', &
+               &                  ' and saving frequency (=',nittrjfrq,') not compatible.'
+      ENDIF
+
+      ! Linear interpolate to the current step
+
+      IF(lwp)WRITE(numout,*) '   linear interpolate to current', &
+         &                   ' time step = ', kstp
+
+      ! Interpolation coefficients
+
+      zstp = kstp - nit000 + 1
+      zden   = 1.0 / ( stpr2 - stpr1 )
+
+      zwtr1  = ( stpr2 - zstp      ) * zden
+      zwtr2  = ( zstp  - stpr1     ) * zden
+
+IF(lwp)WRITE(numout,*) '   linear interpolate coeff.', &
+         &                   '  = ', zwtr1, zwtr2
+
+      emp(:,:)      = zwtr1 * empr1   (:,:)   + zwtr2 * empr2   (:,:)
+      emps(:,:)     = zwtr1 * empsr1  (:,:)   + zwtr2 * empsr2  (:,:)
+      un(:,:,:)     = zwtr1 * unr1    (:,:,:) + zwtr2 * unr2    (:,:,:)
+      vn(:,:,:)     = zwtr1 * vnr1    (:,:,:) + zwtr2 * vnr2    (:,:,:)
+      tn(:,:,:)     = zwtr1 * tnr1    (:,:,:) + zwtr2 * tnr2    (:,:,:)
+      sn(:,:,:)     = zwtr1 * snr1    (:,:,:) + zwtr2 * snr2    (:,:,:)
+      avmu(:,:,:)   = zwtr1 * avmur1  (:,:,:) + zwtr2 * avmur2  (:,:,:)
+      avmv(:,:,:)   = zwtr1 * avmvr1  (:,:,:) + zwtr2 * avmvr2  (:,:,:)
+      avt(:,:,:)    = zwtr1 * avtr1   (:,:,:) + zwtr2 * avtr2   (:,:,:)
+#if defined key_ldfslp
+      uslp(:,:,:)   = zwtr1 * uslpr1  (:,:,:) + zwtr2 * uslpr2  (:,:,:)
+      vslp(:,:,:)   = zwtr1 * vslpr1  (:,:,:) + zwtr2 * vslpr2  (:,:,:)
+      wslpi(:,:,:)  = zwtr1 * wslpir1 (:,:,:) + zwtr2 * wslpir2 (:,:,:)
+      wslpj(:,:,:)  = zwtr1 * wslpjr1 (:,:,:) + zwtr2 * wslpjr2 (:,:,:)
+#endif
+#if defined key_zdfddm
+      avs(:,:,:)    = zwtr1 * avsr1   (:,:,:) + zwtr2 * avsr2   (:,:,:)
+#endif
+      ta(:,:,:)     = zwtr1 * tar1    (:,:,:) + zwtr2 * tar2    (:,:,:)
+      sa(:,:,:)     = zwtr1 * sar1    (:,:,:) + zwtr2 * sar2    (:,:,:)
+      tb(:,:,:)     = zwtr1 * tbr1    (:,:,:) + zwtr2 * tbr2    (:,:,:)
+      sb(:,:,:)     = zwtr1 * sbr1    (:,:,:) + zwtr2 * sbr2    (:,:,:)
+#if defined key_tradmp
+      hmlp(:,:)     = zwtr1 * hmlp1(:,:)    + zwtr2 * hmlp2(:,:)
+#endif
+#if defined key_traldf_eiv  
+#if defined key_traldf_c3d
+      aeiu(:,:,:)   = zwtr1 * aeiur1  (:,:,:) + zwtr2 * aeiur2  (:,:,:)
+      aeiv(:,:,:)   = zwtr1 * aeivr1  (:,:,:) + zwtr2 * aeivr2  (:,:.:)
+      aeiw(:,:,:)   = zwtr1 * aeiwr1  (:,:,:) + zwtr2 * aeiwr2  (:,:.:)
+#elif defined key_traldf_c2d
+      aeiu(:,:)     = zwtr1 * aeiur1  (:,:)   + zwtr2 * aeiur2  (:,:)
+      aeiv(:,:)     = zwtr1 * aeivr1  (:,:)   + zwtr2 * aeivr2  (:,:)
+      aeiw(:,:)     = zwtr1 * aeiwr1  (:,:)   + zwtr2 * aeiwr2  (:,:)
+#elif defined key_traldf_c1d
+      aeiu(:)       = zwtr1 * aeiur1  (:)     + zwtr2 * aeiur2  (:)
+      aeiv(:)       = zwtr1 * aeivr1  (:)     + zwtr2 * aeivr2  (:)
+      aeiw(:)       = zwtr1 * aeiwr1  (:)     + zwtr2 * aeiwr2  (:)
+#else
+      aeiu          = zwtr1 * aeiur1          + zwtr2 * aeiur2     
+      aeiv          = zwtr1 * aeivr1          + zwtr2 * aeivr2     
+      aeiw          = zwtr1 * aeiwr1          + zwtr2 * aeiwr2     
+#endif
+#endif
+
+      CALL div_cur(kstp)
+      CALL wzv(kstp)
+
+   END SUBROUTINE trj_rea
+
+
+   SUBROUTINE trj_wri_spl(filename)
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE trj_wri_spl ***
+      !!
+      !! ** Purpose : Write SimPLe data to file the model state trajectory
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 09-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom  
+      USE sol_oce, ONLY : & ! solver variables
+      & gcb, gcx
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & inum, &                  ! File unit number
+         & fd                       ! field number
+      CHARACTER (LEN=50) :: &
+         & filename      
+
+      fd=1
+      WRITE(filename, FMT='(A,A)' ) TRIM( filename ), '.nc'
+      filename = TRIM( filename )
+      CALL iom_open( filename, inum, ldwrt = .TRUE., kiolib = jprstlib)
+
+      ! Output trajectory fields
+      CALL iom_rstput( fd, fd, inum, 'un'   , un   )
+      CALL iom_rstput( fd, fd, inum, 'vn'   , vn   )
+      CALL iom_rstput( fd, fd, inum, 'tn'   , tn   )
+      CALL iom_rstput( fd, fd, inum, 'sn'   , sn   )
+      CALL iom_rstput( fd, fd, inum, 'sshn' , sshn )
+      CALL iom_rstput( fd, fd, inum, 'wn'   , wn   )
+      CALL iom_rstput( fd, fd, inum, 'tb'   , tb   )
+      CALL iom_rstput( fd, fd, inum, 'sb'   , sb   )
+      CALL iom_rstput( fd, fd, inum, 'ua'   , ua   )
+      CALL iom_rstput( fd, fd, inum, 'va'   , va   )
+      CALL iom_rstput( fd, fd, inum, 'ta'   , ta   )
+      CALL iom_rstput( fd, fd, inum, 'sa'   , sa   )
+      CALL iom_rstput( fd, fd, inum, 'sshb' , sshb )
+      CALL iom_rstput( fd, fd, inum, 'rhd'  , rhd  )
+      CALL iom_rstput( fd, fd, inum, 'rhop' , rhop )
+      CALL iom_rstput( fd, fd, inum, 'gtu'  , gtu  )
+      CALL iom_rstput( fd, fd, inum, 'gsu'  , gsu  )
+      CALL iom_rstput( fd, fd, inum, 'gru'  , gru  )
+      CALL iom_rstput( fd, fd, inum, 'gtv'  , gtv  )
+      CALL iom_rstput( fd, fd, inum, 'gsv'  , gsv  )
+      CALL iom_rstput( fd, fd, inum, 'grv'  , grv  )
+      CALL iom_rstput( fd, fd, inum, 'rn2'  , rn2  )
+      CALL iom_rstput( fd, fd, inum, 'gcb'  , gcb  )
+      CALL iom_rstput( fd, fd, inum, 'gcx'  , gcx  )
+
+      CALL iom_close( inum )
+
+   END SUBROUTINE trj_wri_spl
+
+   SUBROUTINE trj_rd_spl(filename)
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE asm_trj__wop_rd ***
+      !!
+      !! ** Purpose : Read SimPLe data from file the model state trajectory
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 09-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom                 ! I/O module
+      USE sol_oce, ONLY : & ! solver variables
+      & gcb, gcx
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & inum, &                  ! File unit number
+         & fd                       ! field number
+      CHARACTER (LEN=50) :: &
+         & filename
+       
+      fd=1
+      WRITE(filename, FMT='(A,A)' ) TRIM( filename ), '.nc'
+      filename = TRIM( filename )
+      CALL iom_open( filename, inum)
+
+      ! Output trajectory fields
+      CALL iom_get( inum, jpdom_autoglo, 'un'   , un,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'vn'   , vn,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'tn'   , tn,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'sn'   , sn,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'sshn' , sshn, fd )
+      CALL iom_get( inum, jpdom_autoglo, 'wn'   , wn,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'tb'   , tb,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'sb'   , sb,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'ua'   , ua,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'va'   , va,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'ta'   , ta,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'sa'   , sa,   fd )
+      CALL iom_get( inum, jpdom_autoglo, 'sshb' , sshb, fd )
+      CALL iom_get( inum, jpdom_autoglo, 'rhd'  , rhd,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'rhop' , rhop, fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gtu'  , gtu,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gsu'  , gsu,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gru'  , gru,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gtv'  , gtv,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gsv'  , gsv,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'grv'  , grv,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'rn2'  , rn2,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gcb'  , gcb,  fd )
+      CALL iom_get( inum, jpdom_autoglo, 'gcx'  , gcx,  fd )
+
+      CALL iom_close( inum )
+
+   END SUBROUTINE trj_rd_spl
+
+   SUBROUTINE tl_trj_wri(kstp)
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tl_trj_wri ***
+      !!
+      !! ** Purpose : Write SimPLe data to file the model state trajectory
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 10-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom  
+      !! * Arguments
+      INTEGER, INTENT(in) :: &
+         & kstp           ! Step for requested trajectory
+      !! * Local declarations
+      INTEGER :: &
+         & inum           ! File unit number
+      INTEGER :: &
+         & it
+      CHARACTER (LEN=50) :: &
+         & filename
+      CHARACTER (LEN=100) :: &
+         & cl_tantrj      
+
+      ! Initialize data and open file
+      !! if step time is corresponding to a saved state
+      IF ( ( MOD( kstp - nit000 + 1, nittrjfrq_tan ) == 0 )  ) THEN       
+
+         it = kstp - nit000 + 1
+
+            ! Define the input file 
+            WRITE(cl_tantrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_tantrj ), '_', it
+            cl_tantrj = TRIM( cl_tantrj )
+
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*)'Writing linear-tangent fields from : ',TRIM(cl_tantrj)
+               WRITE(numout,*)
+            ENDIF
+
+            CALL iom_open( cl_tantrj, inum, ldwrt = .TRUE., kiolib = jprstlib)
+            
+            ! Output trajectory fields
+            CALL iom_rstput( it, it, inum, 'un_tl'   , un_tl   )
+            CALL iom_rstput( it, it, inum, 'vn_tl'   , vn_tl   )
+            CALL iom_rstput( it, it, inum, 'tn_tl'   , tn_tl   )
+            CALL iom_rstput( it, it, inum, 'sn_tl'   , sn_tl   )
+            CALL iom_rstput( it, it, inum, 'wn_tl'   , wn_tl   )
+            CALL iom_rstput( it, it, inum, 'hdivn_tl', hdivn_tl)
+            CALL iom_rstput( it, it, inum, 'rotn_tl' , rotn_tl )
+#if defined key_dynspg_flt
+            CALL iom_rstput( it, it, inum, 'sshn_tl' , sshn_tl )
+#endif
+            CALL iom_close( inum )
+
+         ENDIF
+
+   END SUBROUTINE tl_trj_wri
+
+
+   SUBROUTINE trj_deallocate
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE trj_deallocate ***
+      !!
+      !! ** Purpose : Deallocate saved trajectory arrays
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 2010-06 (A. Vidard)
+      !!-----------------------------------------------------------------------
+
+         IF ( ln_mem ) THEN
+            DEALLOCATE(  &
+               & empr1,  &
+               & empsr1, &
+               & empr2,  &
+               & empsr2  &
+               & )
+
+            DEALLOCATE(    &
+               & unr1,     &
+               & vnr1,     &
+               & tnr1,     &
+               & snr1,     &
+               & avmur1,   &
+               & avmvr1,   &
+               & avtr1,    &
+               & tar1,     &
+               & sar1,     &
+               & tbr1,     &
+               & sbr1,     &
+               & unr2,     &
+               & vnr2,     &
+               & tnr2,     &
+               & snr2,     &
+               & avmur2,   &
+               & avmvr2,   &
+               & avtr2,    &
+               & tar2,     &
+               & sar2,     &
+               & tbr2,     &
+               & sbr2      &
+               & )
+
+#if defined key_traldf_eiv
+#if defined key_traldf_c3d
+#elif defined key_traldf_c2d
+            DEALLOCATE(  &
+               & aeiur1, &
+               & aeivr1, &
+               & aeiwr1, &
+               & aeiur2, &
+               & aeivr2, &
+               & aeiwr2  &
+               & )
+#elif defined key_traldf_c1d
+#endif
+#endif
+
+#if defined key_ldfslp
+            DEALLOCATE( &
+               & uslpr1,   &
+               & vslpr1,   &
+               & wslpir1,  &
+               & wslpjr1,  &
+               & uslpr2,   &
+               & vslpr2,   &
+               & wslpir2,  &
+               & wslpjr2   &
+               & )
+#endif
+
+#if defined key_zdfddm
+            DEALLOCATE( &
+               & avsr1,    &
+               & avsr2     &
+               & )
+#endif
+
+#if defined key_tradmp
+            DEALLOCATE( &
+               & hmlp1,    &
+               & hmlp2     &
+               & )
+#endif
+	 ENDIF
+     END SUBROUTINE trj_deallocate
+#endif
+END MODULE trj_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_cen2_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_cen2_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_cen2_tam.F90	(revision 2587)
@@ -127,5 +127,7 @@
    PUBLIC   tra_adv_cen2_adj    ! routine called by traadv_tam.F90
    PUBLIC   tra_adv_cen2_adj_tst! routine called by tst.F90
+#if defined key_tst_tlm
    PUBLIC   tra_adv_cen2_tlm_tst! routine called by tamtst.F90
+#endif
 
    REAL(wp), DIMENSION(jpi,jpj) ::  &
@@ -935,5 +937,5 @@
 
    END SUBROUTINE tra_adv_cen2_adj_tst
-
+#if defined key_tst_tlm
 SUBROUTINE tra_adv_cen2_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -968,4 +970,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -1027,5 +1030,5 @@
          & z3r
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  :: FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -1084,7 +1087,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_tradv_cen2'
       CALL tlm_namrd
       gamma = h_ratio     
+      file_wop='trj_wop_tradv_cen2'
+      file_xdx='trj_xdx_tradv_cen2'   
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1151,5 +1155,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 ) CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -1184,16 +1188,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL tra_adv_cen2(nit000, un, vn, wn)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch /= 2 ) CALL tra_adv_cen2(nit000, un, vn, wn)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------    
-         zta_out  (:,:,:) = ta   (:,:,:)
-         zsa_out  (:,:,:) = sa   (:,:,:)          
-
+      IF ( tlm_bch == 2 ) THEN       
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -1214,18 +1213,17 @@
          ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
          !--------------------------------------------------------------------
-
          zsp2_Ta    = DOT_PRODUCT( ta_tl, ta_tl  )
          zsp2_Sa    = DOT_PRODUCT( sa_tl, sa_tl  )
 
          zsp2      = zsp2_Ta + zsp2_Sa
-  
          !--------------------------------------------------------------------
          !  Storing data
          !--------------------------------------------------------------------
          CALL trj_rd_spl(file_wop) 
-
          zta_wop  (:,:,:) = ta  (:,:,:)
          zsa_wop  (:,:,:) = sa  (:,:,:)
-
+         CALL trj_rd_spl(file_xdx) 
+         zta_out  (:,:,:) = ta  (:,:,:)
+         zsa_out  (:,:,:) = sa  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -1372,5 +1370,5 @@
   END SUBROUTINE  tra_adv_cen2_tlm_tst
 #endif
-
+#endif
    !!======================================================================
 END MODULE traadv_cen2_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_eiv_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_eiv_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_eiv_tam.F90	(revision 2587)
@@ -23,7 +23,7 @@
       & wp
    USE par_oce       , ONLY: & ! Ocean space and time domain variables
-      & jpi,                 &
-      & jpj,                 & 
-      & jpk 
+      & jpi, jpj, jpk 
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp, numout              
 
    IMPLICIT NONE
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traadv_tam.F90	(revision 2587)
@@ -43,13 +43,11 @@
       & tra_adv_cen2_tan,     &
       & tra_adv_cen2_adj,     &
-      & tra_adv_cen2_adj_tst, &
-      & tra_adv_cen2_tlm_tst
+#if defined key_tst_tlm
+      & tra_adv_cen2_tlm_tst, &
+#endif
+      & tra_adv_cen2_adj_tst
    USE traadv_eiv_tam, ONLY: & ! advection trend - eddy induced velocity (tra_adv_eiv   routine)
       & tra_adv_eiv_tan,     &
       & tra_adv_eiv_adj
-!   USE in_out_manager, ONLY : & ! I/O manager 
-!      & lwp,                  &
-!      & numout,               &
-!      & nit000
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -62,5 +60,7 @@
    PUBLIC   tra_adv_ctl_tam ! routine called by stepadj module
    PUBLIC   tra_adv_adj_tst ! routine called by tst module
+#if defined key_tst_tlm
    PUBLIC   tra_adv_tlm_tst ! routine called by tst module
+#endif
    !!* Namelist nam_traadv
    LOGICAL, PUBLIC ::   ln_traadv_cen2   = .TRUE.       ! 2nd order centered scheme flag
@@ -305,5 +305,5 @@
       !
    END SUBROUTINE tra_adv_ctl_tam
-
+#if defined key_tst_tlm
 SUBROUTINE tra_adv_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -335,4 +335,5 @@
    END SUBROUTINE tra_adv_tlm_tst
 #endif
+#endif
 
 
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traldf_lap_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traldf_lap_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traldf_lap_tam.F90	(revision 2587)
@@ -106,5 +106,7 @@
    PUBLIC tra_ldf_lap_adj      ! routine called by tradldf_tam.F90
    PUBLIC tra_ldf_lap_adj_tst  ! routine called by tradldf_tam.F90
+#if defined key_tst_tlm
    PUBLIC tra_ldf_lap_tlm_tst  
+#endif
 
    !! * Substitutions
@@ -735,5 +737,5 @@
 
    END SUBROUTINE tra_ldf_lap_adj_tst
-
+#if defined key_tst_tlm
    SUBROUTINE tra_ldf_lap_tlm_tst ( kumadt )
       !!-----------------------------------------------------------------------
@@ -775,8 +777,9 @@
         & lk_c1d
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
       USE istate_mod
-      USE wzvmod             !  vertical velocity
+      USE zpshde
       USE gridrandom, ONLY: &
         & grid_rd_sd
@@ -785,5 +788,5 @@
         & tb, sb, tn, sn, ta,  &
         & sa, gtu, gsu, gtv,   &
-        & gsv
+        & gsv, gru, grv, rhd
       USE traldf_lap          ! lateral mixing                   (tra_ldf routine)
       USE opatam_tst_ini, ONLY: &
@@ -877,5 +880,5 @@
          & z2r               ! 2D random field 
       CHARACTER(LEN=14) ::   cl_name
-      CHARACTER (LEN=128) :: file_out_sc, file_wop, file_out
+      CHARACTER (LEN=128) :: file_out_sc, file_wop, file_out, file_xdx
       CHARACTER (LEN=90) :: &
          & FMT
@@ -972,5 +975,5 @@
       zgtv_wop(:,:)    = 0.0_wp
       zgsv_wop(:,:)    = 0.0_wp
-
+      IF ( tlm_bch == 2 ) THEN      
       tb_tl(:,:,:) = 0.0_wp
       sb_tl(:,:,:) = 0.0_wp
@@ -981,5 +984,5 @@
       gtv_tl(:,:)  = 0.0_wp
       gsv_tl(:,:)  = 0.0_wp
-
+      ENDIF
       zsctb(:)     = 0.0_wp
       zscta(:)     = 0.0_wp
@@ -1002,7 +1005,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_tldf_lap'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_tldf_lap'
+      file_xdx='trj_xdx_tldf_lap'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1069,5 +1073,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )      CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -1076,4 +1080,7 @@
       CALL  trj_rea( nit000, 1 )
 
+      ! Compute  gtu, gsu, gtv, gsv
+      CALL zps_hde(nit000, tn, sn, rhd, gtu, gsu, gru, gtv, gsv, grv)
+
       IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
          ztb_tlin(:,:,:) = gamma * ztb_tlin(:,:,:)
@@ -1101,27 +1108,15 @@
          gsv(:,:)       = gsv(:,:) + zgsv_tlin(:,:)
       ENDIF 
-      IF( .NOT. lk_vvl ) CALL wzv(nit000)
+
       !--------------------------------------------------------------------
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL tra_ldf_lap( nit000 )
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
-
+      IF ( tlm_bch /= 2 )      CALL tra_ldf_lap( nit000 )
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------
-         ztb_out  (:,:,:) = tb   (:,:,:)
-         zsb_out  (:,:,:) = sb   (:,:,:)
-         zta_out  (:,:,:) = ta   (:,:,:)
-         zsa_out  (:,:,:) = sa   (:,:,:)
-         zgtu_out (:,:  ) = gtu  (:,:  )    
-         zgsu_out (:,:  ) = gsu  (:,:  )
-         zgtv_out (:,:  ) = gtv  (:,:  )    
-         zgsv_out (:,:  ) = gsv  (:,:  )      
-
+      IF ( tlm_bch == 2 ) THEN    
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -1171,5 +1166,13 @@
          zgtv_wop (:,:  ) = gtv (:,:  )
          zgsv_wop (:,:  ) = gsv (:,:  )
-
+         CALL trj_rd_spl(file_xdx) 
+         ztb_out  (:,:,:) = tb  (:,:,:)
+         zsb_out  (:,:,:) = sb  (:,:,:)
+         zta_out  (:,:,:) = ta  (:,:,:)
+         zsa_out  (:,:,:) = sa  (:,:,:)
+         zgtu_out (:,:  ) = gtu (:,:  )
+         zgsu_out (:,:  ) = gsu (:,:  )
+         zgtv_out (:,:  ) = gtv (:,:  )
+         zgsv_out (:,:  ) = gsv (:,:  )
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -1628,5 +1631,5 @@
       CALL iom_close( inum )
    END SUBROUTINE asm_trj_wop_rd
-
+#endif
 #endif
    !!==============================================================================
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traldf_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traldf_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traldf_tam.F90	(revision 2587)
@@ -11,4 +11,5 @@
    !!          9.0  ! 08-06 (A. Vidard) Skeleton
    !!          9.0  ! 09-03 (F. Vigilant) adding tra_ldf_lap option
+   !!          9.0  ! 10-06 (P.A. Bouttier) adding tra_ldf_bilap option
    !!----------------------------------------------------------------------
 
@@ -25,6 +26,11 @@
       & tra_ldf_lap_tan,     &
       & tra_ldf_lap_adj,     &
-      & tra_ldf_lap_adj_tst, &
-      & tra_ldf_lap_tlm_tst
+#if defined key_tst_tlm
+      & tra_ldf_lap_tlm_tst, &
+#endif
+      & tra_ldf_lap_adj_tst
+   USE traldf_bilap_tam, ONLY: & !lateral mixing                (tra_ldf_bilap routine)
+      & tra_ldf_bilap_tan,   &
+      & tra_ldf_bilap_adj
    USE in_out_manager, ONLY: & ! I/O manager
       & ctl_stop, nit000, lwp, numout, nitend
@@ -50,5 +56,8 @@
    PUBLIC   tra_ldf_adj     ! called by step_tam.F90 
    PUBLIC   tra_ldf_adj_tst ! called by tamtst.F90 
+#if defined key_tst_tlm
    PUBLIC   tra_ldf_tlm_tst ! called by tamtst.F90 
+#endif
+   PUBLIC   ldf_ctl_tam     ! called by trazdf_imp (init of l_traldf_rot)
 
    INTEGER ::  nldf
@@ -76,4 +85,5 @@
       CASE ( 0 )   ;   CALL tra_ldf_lap_tan   ( kt )      ! iso-level laplacian
       CASE ( 1 )   ;   CALL tra_ldf_iso_tan   ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )   ;   CALL tra_ldf_bilap_tan ( kt )      ! iso-level bilaplacian
       END SELECT
    END SUBROUTINE tra_ldf_tan
@@ -94,4 +104,5 @@
       CASE ( 0 )   ;   CALL tra_ldf_lap_adj   ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
       CASE ( 1 )   ;   CALL tra_ldf_iso_adj   ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )   ;   CALL tra_ldf_bilap_adj ( kt )      ! iso-level bilaplacian
       END SELECT
       !
@@ -206,8 +217,18 @@
 
       IF( ln_traldf_bilap ) THEN      ! bilaplacian operator
-           CALL ctl_stop( '          You shouldn t have seen this error message, ln_trad_bilap option not impemented yet for tam' )
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_traldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_traldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+      ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_traldf_level )   ierr = 1      ! iso-level not allowed 
+            IF ( ln_traldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
       ENDIF
 
       IF( ierr == 1 )   CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
+      IF( ierr == 2 )   CALL ctl_stop( ' isoneutral bilaplacian operator does not exist' )
       IF( lk_traldf_eiv .AND. .NOT.ln_traldf_iso )   &
            CALL ctl_stop( '          eddy induced velocity on tracers',   &
@@ -227,5 +248,5 @@
    END SUBROUTINE ldf_ctl_tam
 
-
+#if defined key_tst_tlm
    SUBROUTINE tra_ldf_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -266,3 +287,4 @@
    !!======================================================================
 #endif
+#endif
 END MODULE traldf_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/tranxt_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/tranxt_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/tranxt_tam.F90	(revision 2587)
@@ -229,5 +229,4 @@
       !
    END SUBROUTINE tra_nxt_tan
-
    SUBROUTINE tra_nxt_adj( kt )
       !!----------------------------------------------------------------------
@@ -476,16 +475,4 @@
       ! Reset the tangent and adjoint variables
       !--------------------------------------------------------------------
-      zsa_tlin(:,:,:) = 0.0_wp 
-      zta_tlin(:,:,:) = 0.0_wp 
-      zsb_tlin(:,:,:) = 0.0_wp 
-      ztb_tlin(:,:,:) = 0.0_wp 
-      zsn_tlin(:,:,:) = 0.0_wp 
-      ztn_tlin(:,:,:) = 0.0_wp 
-      zsa_adin(:,:,:) = 0.0_wp 
-      zta_adin(:,:,:) = 0.0_wp 
-      zsb_adin(:,:,:) = 0.0_wp 
-      ztb_adin(:,:,:) = 0.0_wp 
-      zsn_adin(:,:,:) = 0.0_wp 
-      ztn_adin(:,:,:) = 0.0_wp 
       sb_tl(:,:,:) = 0.0_wp
       tb_tl(:,:,:) = 0.0_wp
@@ -500,4 +487,10 @@
       sn_ad(:,:,:) = 0.0_wp
       tn_ad(:,:,:) = 0.0_wp
+      zsb_tlin(:,:,:) = 0.0_wp
+      ztb_tlin(:,:,:) = 0.0_wp
+      zsa_tlin(:,:,:) = 0.0_wp
+      zta_tlin(:,:,:) = 0.0_wp
+      zsn_tlin(:,:,:) = 0.0_wp
+      ztn_tlin(:,:,:) = 0.0_wp
 
       DO jj = 1, jpj
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90	(revision 2587)
@@ -277,6 +277,5 @@
                   DO ji = fs_2, fs_jpim1   ! vector opt.
                      ! qsr trend
-                     qsr_ad(ji,jj) = qsr_ad(ji,jj) + ta_ad(ji,jj,jk) * zc0   &
-                                   &   * ( gdsr(jk)*tmask(ji,jj,jk) - gdsr(jk+1)*tmask(ji,jj,jk+1) )
+                     qsr_ad(ji,jj) = qsr_ad(ji,jj) + ta_ad(ji,jj,jk) * zc0 * ( gdsr(jk)*tmask(ji,jj,jk) - gdsr(jk+1)*tmask(ji,jj,jk+1) )
                   END DO
                END DO
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trasbc_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trasbc_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trasbc_tam.F90	(revision 2587)
@@ -96,5 +96,7 @@
    PUBLIC   tra_sbc_adj     ! routine called by step_tam.F90
    PUBLIC   tra_sbc_adj_tst ! routine called by tst.F90
+#if defined key_tst_tlm
    PUBLIC   tra_sbc_tlm_tst ! routine calle  by tamtst.F90
+#endif
 
    !! * Substitutions
@@ -579,5 +581,5 @@
    END SUBROUTINE tra_sbc_adj_tst
 
-
+#if defined key_tst_tlm
    SUBROUTINE tra_sbc_tlm_tst ( kumadt ) 
       !!-----------------------------------------------------------------------
@@ -612,4 +614,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -676,5 +679,5 @@
          & zgsp7 
       CHARACTER (LEN=14)  :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  ::  FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -731,7 +734,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_trasbc'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_trasbc'
+      file_xdx='trj_xdx_trasbc'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -778,5 +782,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )      CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -804,18 +808,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL tra_sbc(nit000)
-
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
-
+      IF ( tlm_bch /= 2 ) CALL tra_sbc(nit000)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------  
-         zta_out  (:,:,:) = ta   (:,:,:)
-         zsa_out  (:,:,:) = sa   (:,:,:)          
-
+      IF ( tlm_bch == 2 ) THEN         
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -836,5 +833,4 @@
          ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
          !--------------------------------------------------------------------
-
          zsp2_1    = DOT_PRODUCT( ta_tl, ta_tl  )
          zsp2_2    = DOT_PRODUCT( sa_tl, sa_tl  )
@@ -847,4 +843,7 @@
          zta_wop  (:,:,:) = ta  (:,:,:)
          zsa_wop  (:,:,:) = sa  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zta_out  (:,:,:) = ta  (:,:,:)
+         zsa_out  (:,:,:) = sa  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -981,3 +980,4 @@
 !!======================================================================
 #endif
+#endif
 END MODULE trasbc_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_imp_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_imp_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_imp_tam.F90	(revision 2587)
@@ -74,11 +74,14 @@
       & ahtw,                &
       & aht0
+#if defined key_ldfslp
    USE ldfslp        , ONLY: & ! lateral physics: slope of diffusion
       & wslpi,               & !: i_slope at W-points
       & wslpj                  !: j-slope at W-points
+#endif 
 #if defined key_zdfddm
    USE zdfddm        , ONLY: &
       & avs
 #endif 
+   USE traldf_tam
    USE in_out_manager, ONLY: & ! I/O manager 
       & lwp,          &
@@ -106,5 +109,7 @@
    PUBLIC tra_zdf_imp_adj       !  routine called by tra_zdf_adj.F90
    PUBLIC tra_zdf_imp_adj_tst   !  routine called by tst.F90
+#if defined key_tst_tlm
    PUBLIC tra_zdf_imp_tlm_tst   !  routine called by tamtst.F90 
+#endif
 
    !! * Substitutions
@@ -483,8 +488,9 @@
       !!---------------------------------------------------------------------
 
-      IF( kt == nit000 ) THEN
+      IF( kt == nitend ) THEN
          IF(lwp)WRITE(numout,*)
          IF(lwp)WRITE(numout,*) 'tra_zdf_imp_adj : implicit vertical mixing'
          IF(lwp)WRITE(numout,*) '~~~~~~~~~~~~~~~ '
+         CALL ldf_ctl_tam  ! init of l_traldf_rot
          zavi = 0._wp      ! avoid warning at compilation phase when lk_ldfslp=F
       ENDIF
@@ -985,5 +991,5 @@
 
    END SUBROUTINE tra_zdf_imp_adj_tst
-
+#if defined key_tst_tlm
    SUBROUTINE tra_zdf_imp_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -1019,4 +1025,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -1077,5 +1084,5 @@
       CHARACTER(LEN=14) ::&
          & cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90) :: &
          & FMT
@@ -1126,7 +1133,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_trazdf_imp'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_trazdf_imp'
+      file_xdx='trj_xdx_trazdf_imp'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1169,5 +1177,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )      CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -1192,17 +1200,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL tra_zdf_imp(nit000, rdttra)
-
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
-
+      IF ( tlm_bch /= 2 )  CALL tra_zdf_imp(nit000, rdttra)
+      IF ( tlm_bch == 0 )  CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 )  CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------  
-         zta_out  (:,:,:) = ta   (:,:,:)
-         zsa_out  (:,:,:) = sa   (:,:,:)
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -1235,5 +1237,7 @@
          zta_wop  (:,:,:) = ta  (:,:,:)
          zsa_wop  (:,:,:) = sa  (:,:,:)
-
+         CALL trj_rd_spl(file_xdx) 
+         zta_out  (:,:,:) = ta  (:,:,:)
+         zsa_out  (:,:,:) = sa  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -1378,3 +1382,4 @@
    END SUBROUTINE tra_zdf_imp_tlm_tst
 #endif
+#endif
 END MODULE trazdf_imp_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_tam.F90	(revision 2587)
@@ -46,6 +46,8 @@
       & tra_zdf_imp_tan,     &
       & tra_zdf_imp_adj,     &
-      & tra_zdf_imp_adj_tst, &
-      & tra_zdf_imp_tlm_tst
+#if defined key_tst_tlm
+      & tra_zdf_imp_tlm_tst, &
+#endif
+      & tra_zdf_imp_adj_tst
    USE in_out_manager, ONLY: & ! I/O manager 
       & lwp,                 &
@@ -63,7 +65,8 @@
       & tra_zdf_tan, &
       & tra_zdf_adj         ! routines called by step_tam.F90
-   PUBLIC  &
-      & tra_zdf_adj_tst, &  ! routine called by tst.F90
-      & tra_zdf_tlm_tst     ! routine called by tst.F90 
+   PUBLIC  tra_zdf_adj_tst  ! routine called by tst.F90
+#if defined key_tst_tlm
+   PUBLIC  tra_zdf_tlm_tst     ! routine called by tst.F90 
+#endif
    INTEGER ::   nzdf = 0               ! type vertical diffusion algorithm used
       !                                ! defined from ln_zdf...  namlist logicals)
@@ -247,5 +250,5 @@
 
    END SUBROUTINE zdf_ctl_tam
-
+#if defined key_tst_tlm
    SUBROUTINE tra_zdf_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -282,3 +285,4 @@
    END SUBROUTINE tra_zdf_tlm_tst
 #endif
+#endif
 END MODULE trazdf_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/zpshde_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/zpshde_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/zpshde_tam.F90	(revision 2587)
@@ -78,5 +78,7 @@
    PUBLIC zps_hde_adj      ! routine called by step_tam.F90
    PUBLIC zps_hde_adj_tst  ! routine called by tst.F90
+#if defined key_tst_tlm
    PUBLIC  zps_hde_tlm_tst ! routine called by tamtst.F90
+#endif
 
    !! * module variables
@@ -946,5 +948,5 @@
       
    END SUBROUTINE zps_hde_adj_tst
-
+#if defined key_tst_tlm
    SUBROUTINE zps_hde_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -984,4 +986,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -1049,5 +1052,5 @@
          & zgsp7
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  ::  FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -1104,4 +1107,5 @@
       zgru_out(:,:)   = 0.0_wp    
       zgrv_out(:,:)   = 0.0_wp
+      IF ( tlm_bch == 2 ) THEN
       gtu_tl(:,:)     = 0.0_wp
       gtv_tl(:,:)     = 0.0_wp    
@@ -1110,5 +1114,5 @@
       gru_tl(:,:)     = 0.0_wp    
       grv_tl(:,:)     = 0.0_wp 
-
+      ENDIF
       zscgtu(:)         = 0.0_wp
       zscgtv(:)         = 0.0_wp
@@ -1132,7 +1136,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_zps'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_zps'
+      file_xdx='trj_xdx_zps'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1167,6 +1172,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
-
+      IF ( tlm_bch /= 2 )  CALL istate_p  
       ! *** initialize the reference trajectory
       ! ------------
@@ -1187,22 +1191,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL zps_hde(nit000, tn, sn, rhd, gtu, gsu, gru, gtv, gsv, grv)
-
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
-
+      IF ( tlm_bch /= 2 ) CALL zps_hde(nit000, tn, sn, rhd, gtu, gsu, gru, gtv, gsv, grv)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------  
-         zgtu_out  (:,:) = gtu   (:,:)
-         zgtv_out  (:,:) = gtv   (:,:)  
-         zgsu_out  (:,:) = gsu   (:,:)
-         zgsv_out  (:,:) = gsv   (:,:) 
-         zgru_out  (:,:) = gru   (:,:)
-         zgrv_out  (:,:) = grv   (:,:)         
-
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables:
@@ -1241,4 +1234,11 @@
          zgru_wop  (:,:) = gru  (:,:)
          zgrv_wop  (:,:) = grv  (:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zgtu_out  (:,:) = gtu  (:,:)
+         zgtv_out  (:,:) = gtv  (:,:)
+         zgsu_out  (:,:) = gsu  (:,:)
+         zgsv_out  (:,:) = gsv  (:,:)
+         zgru_out  (:,:) = gru  (:,:)
+         zgrv_out  (:,:) = grv  (:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -1471,3 +1471,4 @@
    !!======================================================================
 #endif
+#endif
 END MODULE zpshde_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/cla_dynspg_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/cla_dynspg_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/cla_dynspg_tam.F90	(revision 2587)
@@ -31,5 +31,6 @@
       & lwp,                 &
       & numout,              &  
-      & nit000
+      & nit000,              &
+      & nitend
    USE dom_oce       , ONLY: & ! Ocean space and time domain
       & mi0,                 &
@@ -330,5 +331,5 @@
       ! Control print
       ! -------------
-      IF( kt == nit000 ) THEN 
+      IF( kt == nitend ) THEN 
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'cla_dynspg_adj : cross land advection on surface '
@@ -486,7 +487,4 @@
       ! we convert in m3
       zempmed = zempmed * 1.e-3_wp
-
-!!!! AW: Adjoint of this????
-      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
 
       ! minus 2 points in Red Sea and 3 in Atlantic 
@@ -504,4 +502,6 @@
       END DO
 
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
       ! compute the emp in Mediterranean Sea
       ij0 =  96   ;   ij1 = 110
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/dotprodfld.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/dotprodfld.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/dotprodfld.F90	(revision 2587)
@@ -10,5 +10,14 @@
    !! * Modules used   
    USE par_kind
-   USE dom_oce
+   USE dom_oce, ONLY :       &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk
+
    USE mppsumtam
 
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/eosbn2_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/eosbn2_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/eosbn2_tam.F90	(revision 2587)
@@ -130,6 +130,8 @@
    PUBLIC eos_adj_tst
    PUBLIC bn2_adj_tst
+#if defined key_tst_tlm
    PUBLIC eos_tlm_tst
    PUBLIC bn2_tlm_tst
+#endif
 #endif
    
@@ -3057,5 +3059,5 @@
 
    END SUBROUTINE bn2_adj_tst
-
+#if defined key_tst_tlm
    SUBROUTINE eos_insitu_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -3091,4 +3093,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -3134,5 +3137,5 @@
          & jk
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out_sc, file_wop, file_out
+      CHARACTER (LEN=128) :: file_out_sc, file_wop, file_out, file_xdx
       CHARACTER (LEN=90)  :: FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -3160,15 +3163,15 @@
       zs_tlin(  :,:,:)   = 0.0_wp
       zrd_out(  :,:,:)   = 0.0_wp 
-      zrd_tl (  :,:,:)   = 0.0_wp
       zrd_wop(  :,:,:)   = 0.0_wp
       zscerrrd(:)        = 0.0_wp
       zscrd(:)           = 0.0_wp
-
+      IF ( tlm_bch == 2 ) zrd_tl (  :,:,:)   = 0.0_wp    
       !--------------------------------------------------------------------
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_eos_insitu'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_eos_insitu'
+      file_xdx='trj_xdx_eos_insitu'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -3196,5 +3199,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )  CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -3213,14 +3216,12 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------      
-      CALL eos(tn, sn, zrd_out)
+      IF ( tlm_bch /= 2 )  CALL eos(tn, sn, zrd_out)
       rhd(:,:,:)= zrd_out(:,:,:)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -3241,5 +3242,6 @@
          CALL trj_rd_spl(file_wop) 
          zrd_wop  (:,:,:) = rhd  (:,:,:)
-
+         CALL trj_rd_spl(file_xdx) 
+         zrd_out  (:,:,:) = rhd  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -3367,4 +3369,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -3416,5 +3419,5 @@
          & jk
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop,file_xdx
       CHARACTER (LEN=90)  :: FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -3447,6 +3450,4 @@
       zrd_out(  :,:,:)   = 0.0_wp
       zrh_out(  :,:,:)   = 0.0_wp 
-      zrd_tl (  :,:,:)   = 0.0_wp
-      zrh_tl (  :,:,:)   = 0.0_wp
       zrd_wop(  :,:,:)   = 0.0_wp
       zrh_wop(  :,:,:)   = 0.0_wp
@@ -3455,11 +3456,15 @@
       zscrd(:)           = 0.0_wp
       zscrh(:)           = 0.0_wp
-
+      IF ( tlm_bch == 2 )  THEN
+         zrd_tl (  :,:,:)   = 0.0_wp
+         zrh_tl (  :,:,:)   = 0.0_wp
+      ENDIF
       !--------------------------------------------------------------------
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_eos_pot'
       CALL tlm_namrd
       gamma = h_ratio 
+      file_wop='trj_wop_eos_pot'
+      file_xdx='trj_xdx_eos_pot'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -3486,5 +3491,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 )  CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -3503,15 +3508,13 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------      
-      CALL eos(tn, sn, zrd_out, zrh_out)
+      IF ( tlm_bch /= 2 )      CALL eos(tn, sn, zrd_out, zrh_out)
       rhd (:,:,:) = zrd_out(:,:,:)
       rhop(:,:,:) = zrh_out(:,:,:)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -3536,5 +3539,7 @@
          zrd_wop  (:,:,:) = rhd  (:,:,:)
          zrh_wop  (:,:,:) = rhop (:,:,:)
-
+         CALL trj_rd_spl(file_xdx) 
+         zrd_out  (:,:,:) = rhd  (:,:,:)
+         zrh_out  (:,:,:) = rhop (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -3695,4 +3700,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -3741,5 +3747,5 @@
          & jj
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  :: FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -3771,16 +3777,15 @@
       zs_tlin(  :,:)   = 0.0_wp
       zrd_out(  :,:)   = 0.0_wp 
-      zrd_tl (  :,:)   = 0.0_wp
       zrd_wop(  :,:)   = 0.0_wp
       zscerrrd( :)     = 0.0_wp
       zscrd(:)         = 0.0_wp
-
+      IF ( tlm_bch == 2 )      zrd_tl (  :,:)   = 0.0_wp
       !--------------------------------------------------------------------
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_eos_2d'
-
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_eos_2d'
+      file_xdx='trj_xdx_eos_2d'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -3804,5 +3809,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 ) CALL istate_p  
       ! *** initialize the reference trajectory
       ! ------------
@@ -3824,14 +3829,12 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------    
-      CALL eos(ztem, zsal, zdep, zrd_out)
+      IF ( tlm_bch /= 2 ) CALL eos(ztem, zsal, zdep, zrd_out)
       rhd (:,:,2) = zrd_out(:,:)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -3854,4 +3857,6 @@
          CALL trj_rd_spl(file_wop) 
          zrd_wop  (:,:) = rhd  (:,:,2)
+         CALL trj_rd_spl(file_xdx) 
+         zrd_out  (:,:) = rhd  (:,:,2)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -3976,4 +3981,5 @@
       USE tamtrj              ! writing out state trajectory
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -4023,5 +4029,5 @@
          & z3r                
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
       CHARACTER (LEN=90)  :: FMT
       REAL(KIND=wp), DIMENSION(100):: &
@@ -4051,8 +4057,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_bn2'
-
       CALL tlm_namrd
       gamma = h_ratio    
+      file_wop='trj_wop_bn2'
+      file_xdx='trj_xdx_bn2'  
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -4079,5 +4085,5 @@
       ! Complete Init for Direct
       !-------------------------------------------------------------------
-      CALL istate_p  
+      IF ( tlm_bch /= 2 ) CALL istate_p  
 
       ! *** initialize the reference trajectory
@@ -4098,15 +4104,11 @@
       !  Compute the direct model F(X0,t=n) = Xn
       !--------------------------------------------------------------------
-      CALL bn2(tn, sn, rn2)
-      IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch /= 2 ) CALL bn2(tn, sn, rn2)
+      IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+      IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
       !--------------------------------------------------------------------
       !  Compute the Tangent 
       !--------------------------------------------------------------------
-      IF ( cur_loop .NE. 0) THEN
-         !--------------------------------------------------------------------
-         !  Storing data
-         !--------------------------------------------------------------------
-         zrn2_out  (:,:,:) = rn2   (:,:,:)         
-
+      IF ( tlm_bch == 2 ) THEN
          !--------------------------------------------------------------------
          ! Initialize the tangent variables: dy^* = W dy  
@@ -4131,5 +4133,6 @@
          CALL trj_rd_spl(file_wop) 
          zrn2_wop  (:,:,:) = rn2  (:,:,:)
-
+         CALL trj_rd_spl(file_xdx) 
+         zrn2_out  (:,:,:) = rn2  (:,:,:)
          !--------------------------------------------------------------------
          ! Compute the Linearization Error 
@@ -4244,4 +4247,5 @@
    END SUBROUTINE eos_tlm_tst
 #endif
+#endif
    !!======================================================================
 END MODULE eosbn2_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/hltinc.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/hltinc.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/hltinc.F90	(revision 2587)
@@ -0,0 +1,766 @@
+MODULE hltinc
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE hltinc  ***
+   !! Linear-Tangent test increment : Apply an increment to the control vect
+   !!                                 Increment is either generated by  
+   !!                                 difference between two states or either
+   !!                                 directly read from an input file
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   'key_asminc' : Switch on the assimilation increment interface
+   !!----------------------------------------------------------------------
+   !!   asm_inc_init : Initialize the increment arrays and IAU weights
+   !!   calc_date    : Compute the calendar date YYYYMMDD on a given step
+   !!   tra_asm_inc  : Apply the tracer (T and S) increments
+   !!   dyn_asm_inc  : Apply the dynamic (u and v) increments
+   !!   ssh_asm_inc  : Apply the SSH increment
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &       ! Precision variables
+      & wp
+   USE in_out_manager, ONLY : & ! I/O manager 
+      & lwp,      &
+      & numnam,   &
+      & numout,   &
+      & ctl_warn, &
+      & ctl_stop, &
+      & nit000,   &
+      & nstop,    &
+      & ln_rstart
+   USE par_oce, ONLY : & ! Ocean space and time domain variables
+      & jpi,  & 
+      & jpj,  &
+      & jpk,  &
+      & jpkm1
+   USE dom_oce, ONLY : & ! Ocean space and time domain
+      & rdt,    &
+      & n_cla,  &
+      & neuler, &
+      & ln_zps, &
+      & tmask,  &
+      & umask,  &
+      & vmask,  &
+      & nldi,   &
+      & nldj,   &
+      & nlei,   &
+      & nlej
+   USE c1d, ONLY : &    ! 1D initialization
+      & lk_c1d
+   USE oce, ONLY : &      ! Dynamics and active tracers defined in memory
+      & ub, un, ua,    &
+      & vb, vn, va,    &
+      & tb, tn, ta,    &
+      & sb, sn, sa,    &
+      & sshb, sshn,    &
+      & rhd, rhop,     &
+      & rotb, rotn,    &
+      & hdivb, hdivn,  &
+      & gtu, gsu, gru, &
+      & gtv, gsv, grv 
+   USE oce_tam, ONLY : &      ! Dynamics and active tracers defined in memory
+      & ub_tl, un_tl, ua_tl,    &
+      & vb_tl, vn_tl, va_tl,    &
+      & tb_tl, tn_tl, ta_tl,    &
+      & sb_tl, sn_tl, sa_tl,    &
+      & sshb_tl, sshn_tl,    &
+      & rhd_tl, rhop_tl,     &
+      & rotb_tl, rotn_tl,    &
+      & hdivb_tl, hdivn_tl,  &
+      & gtu_tl, gsu_tl, gru_tl, &
+      & gtv_tl, gsv_tl, grv_tl
+   USE divcur, ONLY : &   ! Horizontal divergence and relative vorticity
+      & div_cur
+   USE cla_div, ONLY : &  ! Specific update of the horizontal divergence
+      & div_cla           ! (specific to ORCA_R2)
+   USE wzvmod, ONLY : &   ! Vertical velocity
+      & wzv
+   USE eosbn2, ONLY : &   ! Equation of state - in situ and potential density
+      & eos
+   USE zpshde, ONLY : &   ! Partial step : Horizontal Derivative
+      & zps_hde 
+   USE divcur_tam, ONLY : &   ! Horizontal divergence and relative vorticity
+      & div_cur_tan
+   USE cla_div_tam, ONLY : &  ! Specific update of the horizontal divergence
+      & div_cla_tan           ! (specific to ORCA_R2)
+   USE wzvmod_tam, ONLY : &   ! Vertical velocity
+      & wzv_tan
+   USE eosbn2_tam, ONLY : &   ! Equation of state - in situ and potential density
+      & eos_tan
+   USE zpshde_tam, ONLY : &   ! Partial step : Horizontal Derivative
+      & zps_hde_tan
+   USE iom                ! Library to read input files
+   USE par_tlm
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+   PUBLIC hlt_inc_bld      !: Initialize the increment arrays
+
+   !! * Private Module variables
+   REAL(wp), PRIVATE, DIMENSION(:,:,:), ALLOCATABLE :: &
+      & t_hltinc1, &       !: Increment to the background temperature
+      & s_hltinc1, &       !: Increment to the background salinity
+      & u_hltinc1, &       !: Increment to the u-component velocity 
+      & v_hltinc1, &       !: Increment to the v-component velocity 
+      & t_hltinc2, &       !: Increment to the background temperature
+      & s_hltinc2, &       !: Increment to the background salinity
+      & u_hltinc2, &       !: Increment to the u-component velocity 
+      & v_hltinc2          !: Increment to the v-component velocity
+
+#if defined key_dynspg_flt         
+   REAL(wp), PRIVATE, DIMENSION(:,:), ALLOCATABLE :: &
+      & ssh_hltinc1, &     !: Increment to the background sea surface height
+      & ssh_hltinc2        !: Increment to the background sea surface height
+#endif
+   CHARACTER (LEN=40), PRIVATE, PARAMETER :: &
+      & c_hltincwri = 'increments_01'                 !: Filename for storing the 
+                                                   !: hlt increment dX
+
+CONTAINS
+
+   SUBROUTINE hlt_inc_bld ( pstg )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE hlt_inc_bld  ***
+      !!          
+      !! ** Purpose : Initialize the assimilation increment and IAU weights.
+      !!
+      !! ** Method  : Initialize the assimilation increment and IAU weights.
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+      INTEGER, INTENT(IN) :: &
+         & pstg               ! Current stage
+      !! * Modules used
+      !! * Local declarations
+      INTEGER :: &
+         & jk, jj, ji
+      INTEGER :: &
+         & inum
+      REAL(wp), DIMENSION(5) :: &
+         & zvalmax
+      REAL(wp) :: &
+         & zt, zs, zu, zv, zssh, &
+         & znormt, znorms, znormu, znormv, znormssh
+      REAL(wp) :: &
+         & znorm
+      LOGICAL :: &
+         & zlnrm = .FALSE.
+
+      !--------------------------------------------------------------------
+      ! Initialize the Incremental Analysis Updating weighting function
+      !--------------------------------------------------------------------
+
+      IF ( .NOT. ln_incdx ) THEN      ! No increment file defined
+
+         c_hltrst1 = 'restart.nc'
+         c_hltrst2 = 'restart2.nc'
+
+          IF(lwp) THEN
+             WRITE(numout,*)
+             WRITE(numout,*) 'hlt_inc_init : Open restart file 1 ', c_hltrst1
+             WRITE(numout,*) '~~~~~~~~~~~~'
+          ENDIF
+
+          !--------------------------------------------------------------------
+          ! Allocate and initialize the increment arrays 1
+          !--------------------------------------------------------------------
+          ALLOCATE( t_hltinc1(jpi,jpj,jpk) )
+          ALLOCATE( s_hltinc1(jpi,jpj,jpk) )
+          ALLOCATE( u_hltinc1(jpi,jpj,jpk) )
+          ALLOCATE( v_hltinc1(jpi,jpj,jpk) )
+#if defined key_dynspg_flt
+          ALLOCATE( ssh_hltinc1(jpi,jpj  ) )
+#endif
+          t_hltinc1(:,:,:) = 0.0_wp
+          s_hltinc1(:,:,:) = 0.0_wp
+          u_hltinc1(:,:,:) = 0.0_wp
+          v_hltinc1(:,:,:) = 0.0_wp
+#if defined key_dynspg_flt
+          ssh_hltinc1(:,:) = 0.0_wp
+#endif
+         CALL iom_open( c_hltrst1, inum )
+
+         IF ( ln_hltt  )   CALL iom_get( inum, jpdom_autoglo, 'tn',   t_hltinc1 ) 
+         IF ( ln_hlts  )   CALL iom_get( inum, jpdom_autoglo, 'sn',   s_hltinc1 )
+         IF ( ln_hltuv )   CALL iom_get( inum, jpdom_autoglo, 'un',   u_hltinc1 )
+         IF ( ln_hltuv )   CALL iom_get( inum, jpdom_autoglo, 'vn',   v_hltinc1 )
+#if defined key_dynspg_flt
+         IF ( ln_hltuv )   CALL iom_get( inum, jpdom_autoglo, 'sshn', ssh_hltinc1 )
+#endif
+         CALL iom_close( inum )
+
+          IF(lwp) THEN
+             WRITE(numout,*)
+             WRITE(numout,*) 'hlt_inc_init : Open restart file 2 ', c_hltrst2
+             WRITE(numout,*) '~~~~~~~~~~~~'
+          ENDIF
+
+          !--------------------------------------------------------------------
+          ! Allocate and initialize the increment arrays 2
+          !--------------------------------------------------------------------
+          ALLOCATE( t_hltinc2(jpi,jpj,jpk) )
+          ALLOCATE( s_hltinc2(jpi,jpj,jpk) )
+          ALLOCATE( u_hltinc2(jpi,jpj,jpk) )
+          ALLOCATE( v_hltinc2(jpi,jpj,jpk) )
+#if defined key_dynspg_flt
+          ALLOCATE( ssh_hltinc2(jpi,jpj  ) )
+#endif
+          t_hltinc2(:,:,:) = 0.0_wp
+          s_hltinc2(:,:,:) = 0.0_wp
+          u_hltinc2(:,:,:) = 0.0_wp
+          v_hltinc2(:,:,:) = 0.0_wp
+#if defined key_dynspg_flt
+          ssh_hltinc2(:,:) = 0.0_wp
+#endif
+         CALL iom_open( c_hltrst2, inum )
+
+         IF ( ln_hltt  )   CALL iom_get( inum, jpdom_autoglo, 'tn',   t_hltinc2 ) 
+         IF ( ln_hlts  )   CALL iom_get( inum, jpdom_autoglo, 'sn',   s_hltinc2 )
+         IF ( ln_hltuv )   CALL iom_get( inum, jpdom_autoglo, 'un',   u_hltinc2 )
+         IF ( ln_hltuv )   CALL iom_get( inum, jpdom_autoglo, 'vn',   v_hltinc2 )
+#if defined key_dynspg_flt
+         IF ( ln_hltuv )   CALL iom_get( inum, jpdom_autoglo, 'sshn', ssh_hltinc2 )
+#endif
+         CALL iom_close( inum )
+
+          !--------------------------------------------------------------------
+          ! Apply difference restart1 - restart2
+          !--------------------------------------------------------------------
+          t_hltinc1(:,:,:) = t_hltinc1(:,:,:) - t_hltinc2(:,:,:)
+          s_hltinc1(:,:,:) = s_hltinc1(:,:,:) - s_hltinc2(:,:,:)
+          u_hltinc1(:,:,:) = u_hltinc1(:,:,:) - u_hltinc2(:,:,:)
+          v_hltinc1(:,:,:) = v_hltinc1(:,:,:) - v_hltinc2(:,:,:)
+#if defined key_dynspg_flt
+          ssh_hltinc1(:,:) = ssh_hltinc1(:,:) - ssh_hltinc2(:,:)
+#endif
+          !--------------------------------------------------------------------
+          ! Deallocate and initialize the increment arrays 2
+          !--------------------------------------------------------------------
+          DEALLOCATE( t_hltinc2 )
+          DEALLOCATE( s_hltinc2 )
+          DEALLOCATE( u_hltinc2 )
+          DEALLOCATE( v_hltinc2 )
+#if defined key_dynspg_flt
+          DEALLOCATE( ssh_hltinc2 )
+#endif
+      ELSE    ! increment file defined
+
+!          c_hltinc = c_hltincwri
+          WRITE(c_hltinc, FMT='(A,A)' ) TRIM( c_hltincwri ), '.nc'
+          IF(lwp) THEN
+             WRITE(numout,*)
+             WRITE(numout,*) 'hlt_inc_init : Open increment file ', c_hltinc
+             WRITE(numout,*) '~~~~~~~~~~~~'
+          ENDIF
+
+          !--------------------------------------------------------------------
+          ! Allocate and initialize the increment arrays 1
+          !--------------------------------------------------------------------
+          ALLOCATE( t_hltinc1(jpi,jpj,jpk) )
+          ALLOCATE( s_hltinc1(jpi,jpj,jpk) )
+          ALLOCATE( u_hltinc1(jpi,jpj,jpk) )
+          ALLOCATE( v_hltinc1(jpi,jpj,jpk) )
+#if defined key_dynspg_flt
+          ALLOCATE( ssh_hltinc1(jpi,jpj)   )
+#endif
+          t_hltinc1(:,:,:) = 0.0_wp
+          s_hltinc1(:,:,:) = 0.0_wp
+          u_hltinc1(:,:,:) = 0.0_wp
+          v_hltinc1(:,:,:) = 0.0_wp
+          ssh_hltinc1(:,:) = 0.0_wp
+
+         CALL iom_open( c_hltinc, inum )
+
+         IF ( ln_hltt   ) CALL iom_get( inum, jpdom_autoglo, 'bckint',   t_hltinc1 ) 
+         IF ( ln_hlts   ) CALL iom_get( inum, jpdom_autoglo, 'bckins',   s_hltinc1 )
+         IF ( ln_hltuv  ) CALL iom_get( inum, jpdom_autoglo, 'bckinu',   u_hltinc1 )
+         IF ( ln_hltuv  ) CALL iom_get( inum, jpdom_autoglo, 'bckinv',   v_hltinc1 )
+#if defined key_dynspg_flt
+         IF ( ln_hltssh ) CALL iom_get( inum, jpdom_autoglo, 'bckineta', ssh_hltinc1 )
+#endif
+         CALL iom_close( inum )
+         
+      ENDIF
+
+      !--------------------------------------------------------------------
+      ! Check X max value and normalize if needed
+      !--------------------------------------------------------------------
+
+      IF ( ln_hnorm ) THEN
+
+         zvalmax(1) = maxval(ABS(t_hltinc1(:,:,:)))
+         zvalmax(2) = maxval(ABS(s_hltinc1(:,:,:)))
+         zvalmax(3) = maxval(ABS(u_hltinc1(:,:,:)))
+         zvalmax(4) = maxval(ABS(v_hltinc1(:,:,:)))
+#if defined key_dynspg_flt
+         IF ( ln_incdx ) THEN  
+            zvalmax(5) = maxval(ABS(ssh_hltinc1(:,:)))
+         ENDIF
+#endif
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '        Increments max value before normalization'
+            WRITE(numout,*) '        Temperature increment max value         : ', zvalmax(1)
+            WRITE(numout,*) '        Salinity increment max value            : ', zvalmax(2)
+            WRITE(numout,*) '        Horizontal velocity increment max value : ', zvalmax(3)
+            WRITE(numout,*) '        Zonal velocity increment max value      : ', zvalmax(4)
+            IF ( ln_incdx ) THEN
+               WRITE(numout,*) '        Sea Surface increment max value         : ', zvalmax(5)
+            ENDIF
+            WRITE(numout,*) 
+            WRITE(numout,*) '        Normalization bounds:'
+            WRITE(numout,*) '        Temperature rhstdt                      : ',rhstdt
+            WRITE(numout,*) '        Salinity    rhstds                      : ',rhstds
+            WRITE(numout,*) '        Velocity    rhstduv                     : ',rhstduv
+#if defined key_dynspg_flt
+            IF ( ln_incdx ) THEN
+               WRITE(numout,*) '        Sea Surface Height    rhstdssh          : ',rhstdssh
+            ENDIF
+#endif
+         ENDIF
+         
+         IF ( zvalmax(1) > rhstdt )   THEN 
+            zlnrm = .TRUE.
+         ELSE
+            zvalmax(1) = rhstdt
+         ENDIF
+         IF ( zvalmax(2) > rhstds )   THEN 
+            zlnrm = .TRUE.
+         ELSE
+            zvalmax(2) = rhstds
+         ENDIF
+         IF ( zvalmax(3) > rhstduv )   THEN 
+            zlnrm = .TRUE.
+         ELSE
+            zvalmax(3) = rhstduv
+         ENDIF
+         IF ( zvalmax(4) > rhstduv )   THEN 
+            zlnrm = .TRUE.
+         ELSE
+            zvalmax(4) = rhstduv
+         ENDIF
+#if defined key_dynspg_flt
+         IF ( ln_incdx ) THEN
+            IF ( zvalmax(5) > rhstdssh )   THEN 
+               zlnrm = .TRUE.
+            ELSE
+               zvalmax(5) = rhstdssh
+            ENDIF
+         ENDIF
+#endif
+         
+         IF ( zlnrm ) THEN
+!!$         IF ( .NOT. ln_incdx ) THEN
+!!$            znorm = MIN( stdt/zvalmax(1), stds/zvalmax(2), stdu/zvalmax(3), &
+!!$                       & stdv/zvalmax(4), stdssh/zvalmax(5))
+!!$         ELSE
+!!$            znorm = MIN( stdt/zvalmax(1), stds/zvalmax(2), stdu/zvalmax(3), &
+!!$                       & stdv/zvalmax(4))
+!!$
+!!$         ENDIF
+            znormt = rhstdt/zvalmax(1)
+            znorms = rhstds/zvalmax(2)
+            znormu = rhstduv/zvalmax(3)
+            znormv = rhstduv/zvalmax(4)
+#if defined key_dynspg_flt
+            IF ( ln_incdx ) znormssh = rhstdssh/zvalmax(5)
+#endif            
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     t_hltinc1(ji,jj,jk) = t_hltinc1(ji,jj,jk) * znormt
+                  END DO
+               END DO
+            END DO
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     s_hltinc1(ji,jj,jk) = s_hltinc1(ji,jj,jk) * znorms
+                  END DO
+               END DO
+            END DO
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     u_hltinc1(ji,jj,jk) = u_hltinc1(ji,jj,jk) * znormu
+                  END DO
+               END DO
+            END DO
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     v_hltinc1(ji,jj,jk) = v_hltinc1(ji,jj,jk) * znormv
+                  END DO
+               END DO
+            END DO
+#if defined key_dynspg_flt
+            IF ( ln_incdx ) THEN
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     ssh_hltinc1(ji,jj) = ssh_hltinc1(ji,jj) * znormssh
+                  END DO
+               END DO
+            ENDIF
+#endif            
+         ENDIF
+
+      ENDIF
+
+      zt = maxval(ABS(t_hltinc1(:,:,:)))
+      zs = maxval(ABS(s_hltinc1(:,:,:)))
+      zu = maxval(ABS(u_hltinc1(:,:,:)))
+      zv = maxval(ABS(v_hltinc1(:,:,:)))
+#if defined key_dynspg_flt
+        zssh =  maxval(ABS(ssh_hltinc1(:,:)))
+#endif
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '        Increments max value after normalization'
+         WRITE(numout,*) '        Temperature increment max value         : ', zt
+         WRITE(numout,*) '        Salinity increment max value            : ', zs
+         WRITE(numout,*) '        Horizontal velocity increment max value : ', zu
+         WRITE(numout,*) '        Zonal velocity increment max value      : ', zv
+#if defined key_dynspg_flt
+            WRITE(numout,*) '        Sea Surface increment max value         : ', zssh
+#endif
+         WRITE(numout,*) 
+      ENDIF
+
+      SELECT CASE( nstg )
+      CASE ( 1 )                                 ! X = X + dX
+         IF ( .NOT. ln_incdx ) CALL hlt_inc_wri( ln_incdx, nstg)
+                               CALL tra_hlt_inc            ! Tracers
+                               CALL dyn_hlt_inc            ! Dynamics
+#if defined key_dynspg_flt
+         IF ( ln_incdx )       CALL ssh_hlt_inc            ! SSH
+#endif
+      CASE ( 2 )                                 ! X_tl = dX
+         IF ( .NOT. ln_incdx ) CALL hlt_inc_wri( ln_incdx, nstg)
+                               CALL tra_hlt_inc_tan        ! Tracers
+                               CALL dyn_hlt_inc_tan        ! Dynamics
+#if defined key_dynspg_flt
+                               CALL ssh_hlt_inc_tan        ! SSH
+#endif
+      CASE ( 3 )            ! save dX to file if compute from restart
+         IF ( .NOT. ln_incdx ) CALL hlt_inc_wri( ln_incdx, nstg)
+      END SELECT
+
+   END SUBROUTINE hlt_inc_bld
+
+   SUBROUTINE tra_hlt_inc
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE tra_hlt_inc  ***
+      !!          
+      !! ** Purpose : Apply the tracer (T and S)  increments
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      !! * Local declarations
+            
+      neuler = 0  ! Force Euler forward step
+
+      ! Add increment
+      tn(:,:,:) = tn(:,:,:) + t_hltinc1(:,:,:)   
+      sn(:,:,:) = sn(:,:,:) + s_hltinc1(:,:,:)   
+
+      tb(:,:,:) = tn(:,:,:)                        ! Update before fields
+      sb(:,:,:) = sn(:,:,:)
+
+      CALL eos( tb, sb, rhd, rhop )                ! Before potential and in situ densities
+
+      IF( ln_zps .AND. .NOT. lk_c1d ) &
+          &  CALL zps_hde( nit000, tb, sb, rhd,  &  ! Partial steps: before horizontal derivative
+          &                gtu, gsu, gru,        &  ! of T, S, rd at the bottom ocean level
+          &                gtv, gsv, grv )
+
+      DEALLOCATE( t_hltinc1 )
+      DEALLOCATE( s_hltinc1 )
+
+   END SUBROUTINE tra_hlt_inc
+
+   SUBROUTINE dyn_hlt_inc
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dyn_hlt_inc  ***
+      !!          
+      !! ** Purpose : Apply the dynamics (u and v) increments.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & kt
+
+      kt = nit000
+      neuler = 0                    ! Force Euler forward step
+
+      ! Add increment
+      un(:,:,:) = un(:,:,:) + u_hltinc1(:,:,:)
+      vn(:,:,:) = vn(:,:,:) + v_hltinc1(:,:,:)  
+
+      ub(:,:,:) = un(:,:,:)         ! Update before fields
+      vb(:,:,:) = vn(:,:,:)
+ 
+      CALL div_cur( kt )                  ! Compute divergence and curl for now fields
+      IF( n_cla == 1 ) CALL div_cla( kt ) ! Cross Land Advection (Update Hor. divergence)
+
+      rotb (:,:,:) = rotn (:,:,:)   ! Update before fields
+      hdivb(:,:,:) = hdivn(:,:,:)
+
+      CALL wzv( kt )                ! Vertical velocity
+
+      DEALLOCATE( u_hltinc1 )
+      DEALLOCATE( v_hltinc1 )
+
+   END SUBROUTINE dyn_hlt_inc
+
+   SUBROUTINE ssh_hlt_inc
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ssh_hlt_inc  ***
+      !!          
+      !! ** Purpose : Apply the sea surface height increment.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+
+      !! * Local declarations
+      INTEGER :: &
+         & it
+
+      neuler = 0                    ! Force Euler forward step
+
+      ! Add increment
+      sshn(:,:) = sshn(:,:) + ssh_hltinc1(:,:)  
+
+      sshb(:,:) = sshn(:,:)         ! Update before fields
+
+      DEALLOCATE( ssh_hltinc1 )
+
+   END SUBROUTINE ssh_hlt_inc
+
+   SUBROUTINE tra_hlt_inc_tan
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE tra_hlt_inc_tan  ***
+      !!          
+      !! ** Purpose : Apply the tracer (T and S)  increments
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      !! * Local declarations
+            
+      neuler = 0  ! Force Euler forward step
+
+      ! Add increment
+      tn_tl(:,:,:) = t_hltinc1(:,:,:)   
+      sn_tl(:,:,:) = s_hltinc1(:,:,:)   
+
+      CALL lbc_lnk( tn_tl, 'T',  1.0 )
+      CALL lbc_lnk( sn_tl, 'T',  1.0 )
+
+      tb_tl(:,:,:) = tn_tl(:,:,:)                        ! Update before fields
+      sb_tl(:,:,:) = sn_tl(:,:,:)
+
+      CALL eos_tan( tb, sb, tb_tl, sb_tl, rhd_tl, rhop_tl )                ! Before potential and in situ densities
+         
+      IF( ln_zps .AND. .NOT. lk_c1d ) &
+          &  CALL zps_hde_tan( nit000, tb, sb, tb_tl, sb_tl, rhd_tl,  &  ! Partial steps: before horizontal derivative
+          &                gtu_tl, gsu_tl, gru_tl,        &  ! of T, S, rd at the bottom ocean level
+          &                gtv_tl, gsv_tl, grv_tl )
+
+      DEALLOCATE( t_hltinc1 )
+      DEALLOCATE( s_hltinc1 )
+
+   END SUBROUTINE tra_hlt_inc_tan
+
+   SUBROUTINE dyn_hlt_inc_tan
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dyn_hlt_inc_tan  ***
+      !!          
+      !! ** Purpose : Apply the dynamics (u and v) increments.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & kt
+
+      kt = nit000
+      neuler = 0                    ! Force Euler forward step
+
+      ! Add increment
+      un_tl(:,:,:) = u_hltinc1(:,:,:)
+      vn_tl(:,:,:) = v_hltinc1(:,:,:)  
+
+      CALL lbc_lnk( un_tl, 'U', -1.0 )
+      CALL lbc_lnk( vn_tl, 'V', -1.0 )
+ 
+      ub_tl(:,:,:) = un_tl(:,:,:)         ! Update before fields
+      vb_tl(:,:,:) = vn_tl(:,:,:)
+ 
+      CALL div_cur_tan( kt )                  ! Compute divergence and curl for now fields
+      IF( n_cla == 1 ) CALL div_cla_tan( kt ) ! Cross Land Advection (Update Hor. divergence)
+
+      rotb_tl (:,:,:) = rotn_tl (:,:,:)   ! Update before fields
+      hdivb_tl(:,:,:) = hdivn_tl(:,:,:)
+
+      CALL wzv_tan( kt )                ! Vertical velocity
+
+      DEALLOCATE( u_hltinc1 )
+      DEALLOCATE( v_hltinc1 )
+
+   END SUBROUTINE dyn_hlt_inc_tan
+
+   SUBROUTINE ssh_hlt_inc_tan
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ssh_hlt_inc_tan  ***
+      !!          
+      !! ** Purpose : Apply the sea surface height increment.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+
+      !! * Local declarations
+      INTEGER :: &
+         & it
+
+      neuler = 0                    ! Force Euler forward step
+
+      ! Add increment
+      sshn_tl(:,:) = ssh_hltinc1(:,:)  
+
+      sshb_tl(:,:) = sshn_tl(:,:)         ! Update before fields
+
+      DEALLOCATE( ssh_hltinc1 )
+
+   END SUBROUTINE ssh_hlt_inc_tan
+
+   SUBROUTINE hlt_inc_wri ( plrst, pstg ) 
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE hlt_inc_wri  ***
+      !!          
+      !! ** Purpose : Write the  increment.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+
+      !! *Module udes
+      USE iom  
+      !! * Arguments
+      LOGICAL, INTENT(in) :: &
+         & plrst            ! logical to write or not ssh
+      !! * Local declarations
+      INTEGER :: &
+         & inum, &                  ! File unit number
+         & fd                       ! field number
+      INTEGER :: &
+         & it, pstg
+      CHARACTER (LEN=100) :: &
+         & cl_hltinc          
+
+      cl_hltinc = c_hltincwri
+      fd = 1
+
+      WRITE(cl_hltinc, FMT='(A,A)' ) TRIM( cl_hltinc ), '_output.nc'
+!      WRITE(cl_hltinc, FMT='(A)' ) TRIM( cl_hltinc )
+      cl_hltinc = TRIM( cl_hltinc )
+      CALL iom_open( cl_hltinc, inum, ldwrt = .TRUE., kiolib = jprstlib)
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'Writing increment in file : ', c_hltinc
+         WRITE(numout,*)
+      ENDIF
+
+      ! Output increment fields
+      CALL iom_rstput( fd, fd, inum, 'bckinu'   , u_hltinc1   )
+      CALL iom_rstput( fd, fd, inum, 'bkcinv'   , v_hltinc1   )
+      CALL iom_rstput( fd, fd, inum, 'bckint'   , t_hltinc1   )
+      CALL iom_rstput( fd, fd, inum, 'bckins'   , s_hltinc1   )
+#if defined key_dynspg_flt
+      IF ( plrst ) THEN
+         CALL iom_rstput( fd, fd, inum, 'bckineta' , ssh_hltinc1 )
+      ENDIF
+#endif
+      CALL iom_close( inum )
+
+      IF ( pstg == 3 ) THEN
+         DEALLOCATE( t_hltinc1 )
+         DEALLOCATE( s_hltinc1 )
+         DEALLOCATE( u_hltinc1 )
+         DEALLOCATE( v_hltinc1 )
+#if defined key_dynspg_flt
+         IF (  plrst ) THEN
+            DEALLOCATE( ssh_hltinc1 )
+         ENDIF
+#endif
+      ENDIF
+
+   END SUBROUTINE hlt_inc_wri
+#endif
+END MODULE hltinc
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/hlttst.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/hlttst.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/hlttst.F90	(revision 2587)
@@ -0,0 +1,75 @@
+MODULE hlttst
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE hlt_tst  ***
+   !! NEMOTAM    : testing routine of linear-tangent hypothesis
+   !!======================================================================
+   !! History : 
+   !! the direct:      !  10-07  (F. Vigilant)  Original code
+   !!-----------------------------------------------------------------------
+   !! * Module used
+   USE in_out_manager  ! I/O manager
+   USE par_tlm
+   USE opahlt, ONLY: &
+     & opa_hlt
+   USE tanhlt, ONLY: &
+     & tan_hlt
+   USE hltinc
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & hlt_tst 
+
+CONTAINS
+
+   SUBROUTINE hlt_tst
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE hlt_tst  ***
+      !!
+      !! ** Purpose : Validate the linear-tangent hypothesis of the tangent with
+      !!              with respect to the direct model
+      !!
+      !! ** Method  : Build or read a perturbation control vector dX and save
+      !!              M(X, t=tO+p.T), M(X+dX, t=tO+p.T), LT(dX, t=tO+p.T)
+      !!              t0=nit000
+      !!              t = (nit000, nitend)
+      !!              T: saving frequency
+      !!
+      !!              Post treatment need to be done to analyze the RMS of:
+      !!              Y(t) = M(X, t=tO+p.T) - M(X+dX, t=tO+p.T) - LT(dX, t=tO+p.T)
+      !!
+      !!              Then, this routine is run three times
+      !!
+      !! ** Action  : Use 'nstg' swith as follows:
+      !!                     0:  compute M(X, t=tO+p.T)
+      !!                     1:  compute M(X+dX, t=tO+p.T)
+      !!                     2:  compute LT(dX, t=tO+p.T)
+      !!                     3:  compute and save dX only
+      !!                   
+      !! History : 
+      !!        ! 10-07 (F. Vigilant) original code
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      !! * Local declarations
+
+      SELECT CASE( nstg )
+      CASE ( 0, 1, 3)
+         CALL opa_hlt
+      CASE ( 2 )
+         CALL tan_hlt
+      CASE DEFAULT
+         CALL ctl_stop( '       Wrong value for hlt stage nstg. Must be 0, 1 or 2')
+      END SELECT
+
+
+   END SUBROUTINE hlt_tst
+
+#endif
+END MODULE hlttst
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/istate_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/istate_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/istate_tam.F90	(revision 2587)
@@ -45,5 +45,6 @@
 #  endif
 # endif
-      & tmask, umask, vmask
+      & tmask, umask, vmask, &
+      & n_cla
    USE daymod        , ONLY: &
       & day_init
@@ -61,4 +62,8 @@
    USE eosbn2_tam    , ONLY: &
       & eos_tan, eos_adj
+   USE divcur_tam    , ONLY: &
+      & div_cur_tan, div_cur_adj
+   USE cla_div_tam    , ONLY: &
+      & div_cla_tan, div_cla_adj
    USE tstool_tam    , ONLY: &
       & prntst_adj,          &
@@ -119,7 +124,7 @@
       sb_tl   (:,:,:) = sn_tl   (:,:,:)
       sshb_tl (  :,:) = sshn_tl (  :,:)
-      rotb_tl (:,:,:) = rotn_tl (:,:,:)  
+      !
+      rotb_tl (:,:,:) = rotn_tl (:,:,:)   ! Update before fields
       hdivb_tl(:,:,:) = hdivn_tl(:,:,:)  
-      !
 
 
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/model_hlt.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/model_hlt.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/model_hlt.F90	(revision 2587)
@@ -0,0 +1,9 @@
+PROGRAM model_hlt
+#if defined key_tam
+   USE nemotam_hlt
+   IMPLICIT NONE
+   CALL nemotam_hlt_main
+#else
+   WRITE(*,*)'Compile with -Dkey_tam'
+#endif
+END PROGRAM model_hlt
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/mpp_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/mpp_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/mpp_tam.F90	(revision 2587)
@@ -47,5 +47,6 @@
       & mpp_sum_reals,      &
       & mpp_global_or,      &
-      & mpp_global_max_real
+      & mpp_global_max_real, &
+      & mpp_global_max_real2
 
 CONTAINS
@@ -151,5 +152,5 @@
    SUBROUTINE mpp_global_max_real( zin, zout )
       !!----------------------------------------------------------------------
-      !!               ***  ROUTINE mpp_global_or ***
+      !!               ***  ROUTINE mpp_global_max_real ***
       !!          
       !! ** Purpose : Copy a local zin array to a global array and
@@ -213,3 +214,68 @@
    END SUBROUTINE mpp_global_max_real
 
+
+   SUBROUTINE mpp_global_max_real2( zin, zout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_global_max_real2 ***
+      !!          
+      !! ** Purpose : Copy a local zin array to a global array and
+      !!              apply the "max" operation for all elements in
+      !!              a global (jpiglo,jpjglo) array across processors
+      !!
+      !! ** Method  : MPI allreduce
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  08-01  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: &
+         & zin
+      REAL(wp), DIMENSION(jpiglo,jpjglo), INTENT(OUT) :: &
+         & zout
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+#if defined key_mpp_mpi
+#include <mpif.h>
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zcp
+      INTEGER :: &
+         & ji, &
+         & jj
+      
+      ! Copy data for input to MPI
+
+      ALLOCATE( &
+         & zcp(jpiglo,jpjglo) &
+         & )
+      zcp(:,:) = -1e+38
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zcp(mig(ji),mjg(jj)) = zin(ji,jj)
+         ENDDO
+      ENDDO
+
+      ! Call the MPI library to find the coast lines globally
+
+      CALL mpi_allreduce( zcp, zout, jpiglo*jpjglo, mpivar, &
+         &                mpi_max, mpi_comm_opa, ierr )
+
+      DEALLOCATE( &
+         & zcp &
+         & )
+
+#elif defined key_mpp_shmem
+#error "Only MPI support for MPP in NEMOVAR"
+#else
+      zout(:,:) = zin(:,:)
+#endif
+      
+   END SUBROUTINE mpp_global_max_real2
+   
 END MODULE mpp_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/mt19937ar.f90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/mt19937ar.f90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/mt19937ar.f90	(revision 2587)
@@ -0,0 +1,233 @@
+MODULE mt19937ar
+   !!======================================================================
+   !!                       ***  MODULE  mt19937ar ***
+   !! Mersen Twister random generator
+   !!======================================================================
+   !!                 
+   !! ** Purpose :
+   !! ** Method  :  
+   !! References : This a a Fortran90 translation of mt19937ar.c:
+   !! A C-program for MT19937, with initialization improved 2002/1/26.
+   !! Coded by Takuji Nishimura and Makoto Matsumoto.
+   !!
+   !! Before using, initialize the state by using init_genrand(seed)  
+   !! or init_by_array(init_key, key_length).
+   !!
+   !! Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+   !! All rights reserved.                          
+   !!
+   !! Redistribution and use in source and binary forms, with or without
+   !! modification, are permitted provided that the following conditions
+   !! are met:
+   !!
+   !!   1. Redistributions of source code must retain the above copyright
+   !!      notice, this list of conditions and the following disclaimer.
+   !!
+   !!   2. Redistributions in binary form must reproduce the above copyright
+   !!      notice, this list of conditions and the following disclaimer in the
+   !!      documentation and/or other materials provided with the distribution.
+   !!
+   !!   3. The names of its contributors may not be used to endorse or promote 
+   !!      products derived from this software without specific prior written 
+   !!      permission.
+   !!
+   !! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   !! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   !! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   !! A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+   !! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   !! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   !! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   !! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   !! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   !! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   !! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+   !!
+   !!
+   !! Any feedback is very welcome.
+   !! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
+   !! email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
+   !!
+   !! Until 2001/4/6, MT had been distributed under GNU Public License, 
+   !! but after 2001/4/6, we decided to let MT be used for any purpose, 
+   !! including commercial use. 2002-versions mt19937ar.c, mt19937ar-cok.c 
+   !! are considered to be usable freely. 
+   !!      
+   !! History: 
+   !!        !  97 - 02 (Makoto Matsumoto/Takuji Nishimura) original c version
+   !!        !  10-03 (A. Vidard) F90 translation and NEMOTAM adaptation
+   !-----------------------------------------------------------------------!
+   USE par_kind, ONLY : wp
+   PRIVATE
+   INTEGER, PARAMETER :: jpn = 624           ! period parameters
+   INTEGER, PARAMETER :: jpm = 397
+
+   INTEGER*8, PARAMETER :: jpa   = Z'9908b0df' ! constant vector A
+   INTEGER*8, PARAMETER :: jpmsb = Z'80000000' ! most significant w-r bit mask
+   INTEGER*8, PARAMETER :: jplsb = Z'7fffffff' ! least significant r bit mask
+!
+   INTEGER*8, PARAMETER :: jpall = Z'ffffffff' ! all bits mask
+
+   INTEGER*8, PARAMETER :: jptmp1= Z'9d2c5680' ! Tampering paramters
+   INTEGER*8, PARAMETER :: jptmp2= Z'efc60000'
+
+   INTEGER :: mti
+   INTEGER*8, DIMENSION(0:jpn-1) :: mt
+   LOGICAL :: l_mtinit = .FALSE.
+
+   PUBLIC &
+      & l_mtinit,   &
+      & mtrand_int31, &
+      & mtrand_int32, &
+      & mtrand_real1, &
+      & mtrand_real2, &
+      & mtrand_real3, &
+      & mtrand_real53,&
+      & init_by_array,&
+      & init_mtrand
+CONTAINS
+   SUBROUTINE init_mtrand(ks)
+!-----------------------------------------------------------------------
+!!    initialize mt(0:N-1) with a seed
+!-----------------------------------------------------------------------
+      INTEGER :: ks
+      !
+      mt(0) = IAND(INT(ks,kind=8),jpall)
+      DO mti = 1, jpn-1
+         mt(mti) = 1812433253 * IEOR(mt(mti-1),ISHFT(mt(mti-1),-30)) + mti
+         ! See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. 
+         ! In the previous versions, MSBs of the seed affect   
+         ! only MSBs of the array mt[].                        
+         ! modified by Makoto Matsumoto 
+         mt(mti) = IAND(mt(mti),jpall)
+         ! for >32 bit machines
+      END DO
+      l_mtinit = .TRUE.
+!
+   END SUBROUTINE init_mtrand
+   SUBROUTINE init_by_array(kinit_key,key_length)
+!-----------------------------------------------------------------------
+!     initialize by an array with array-length
+!     init_key is the array for initializing keys
+!     key_length is its length
+!-----------------------------------------------------------------------
+      INTEGER :: kinit_key(0:*)
+      INTEGER :: key_length
+      INTEGER :: ji,jj,jk
+!
+      CALL init_mtrand(19650218)
+      ji = 1
+      jj = 0
+      DO jk = MAX(jpn,key_length),1,-1
+         mt(ji) = IEOR(mt(ji),IEOR(mt(ji-1),ISHFT(mt(ji-1),-30)) * 1664525) &
+            &   + kinit_key(jj) + jj
+         mt(ji) = IAND(mt(ji),jpall)
+         ji = ji + 1
+         jj = jj + 1
+         IF (ji .GE. jpn) THEN
+            mt(0) = mt(jpn-1)
+            ji = 1
+         ENDIF
+         IF (jj .GE. key_length) THEN
+            jj = 0
+         ENDIF
+      END DO
+      DO  jk = jpn-1,1,-1
+         mt(ji) = IEOR(mt(ji),IEOR(mt(ji-1),ISHFT(mt(ji-1),-30)) * 1566083941) - ji ! non linear
+         mt(ji) = IAND(mt(ji),jpall) ! for WORDSIZE > 32 machines
+         ji = ji + 1
+         IF (ji .GE. jpn) THEN
+            mt(0) = mt(jpn-1)
+            ji = 1
+         ENDIF
+      END DO
+      mt(0) = jpmsb ! MSB is 1; assuring non-zero initial array
+!
+   END SUBROUTINE init_by_array
+   FUNCTION mtrand_int32()
+!-----------------------------------------------------------------------
+!     generates a random number on [0,0xffffffff]-interval
+!-----------------------------------------------------------------------
+      INTEGER :: mtrand_int32
+      INTEGER :: jk
+      INTEGER*8 :: iy
+      INTEGER*8, DIMENSION(0:1) :: mag01
+!
+      mag01(0)    = 0
+      mag01(1)    = jpa          ! mag01[x] = x * vector A  for x=0,1
+!
+      IF(.NOT. l_mtinit)THEN     ! if init_mtrand() has not been called
+         CALL init_mtrand(5489)  ! a default initial seed is used
+      ENDIF
+!
+      IF (mti .GE. jpn) THEN
+         DO jk = 0,jpn-jpm-1
+            iy     = IOR(IAND(mt(jk),jpmsb),IAND(mt(jk+1),jplsb))
+            mt(jk) = IEOR(IEOR(mt(jk+jpm),ISHFT(iy,-1)),mag01(IAND(iy,1)))
+         END DO
+         DO jk = jpn-jpm,jpn-1-1
+            iy     = IOR(IAND(mt(jk),jpmsb),IAND(mt(jk+1),jplsb))
+            mt(jk) = IEOR(IEOR(mt(jk+(jpm-jpn)),ISHFT(iy,-1)),mag01(IAND(iy,1)))
+         END DO
+         iy     = IOR(IAND(mt(jpn-1),jpmsb),IAND(mt(0),jplsb))
+         mt(jk) = IEOR(IEOR(mt(jpm-1),ISHFT(iy,-1)),mag01(IAND(iy,1)))
+         mti    = 0
+      ENDIF
+!
+      iy  = mt(mti)
+      mti = mti + 1
+!
+      iy = IEOR(iy,ISHFT(iy,-11))
+      iy = IEOR(iy,IAND(ISHFT(iy,7),jptmp1))
+      iy = IEOR(iy,IAND(ISHFT(iy,15),jptmp2))
+      iy = IEOR(iy,ISHFT(iy,-18))
+      !
+      mtrand_int32 = iy
+   END FUNCTION mtrand_int32
+   FUNCTION mtrand_int31()
+!-----------------------------------------------------------------------
+!     generates a random number on [0,0x7fffffff]-interval
+!-----------------------------------------------------------------------
+      INTEGER :: mtrand_int31
+      mtrand_int31 = INT(ISHFT(mtrand_int32(),-1))
+   END FUNCTION mtrand_int31
+   FUNCTION mtrand_real1()
+!-----------------------------------------------------------------------
+!     generates a random number on [0,1]-real-interval
+!-----------------------------------------------------------------------
+      REAL(wp) :: mtrand_real1, zr
+      zr = REAL(mtrand_int32(),wp)
+      IF (zr.LT.0._wp) zr = zr + 2._wp**32
+      mtrand_real1 = zr / 4294967295._wp
+   END FUNCTION mtrand_real1
+   FUNCTION mtrand_real2()
+!-----------------------------------------------------------------------
+!     generates a random number on [0,1)-real-interval
+!-----------------------------------------------------------------------
+      REAL(wp) :: mtrand_real2,zr
+      zr = REAL(mtrand_int32(),wp)
+      IF (zr.LT.0._wp) zr = zr + 2._wp**32
+      mtrand_real2=zr / 4294967296._wp
+   END FUNCTION mtrand_real2
+   FUNCTION mtrand_real3()
+!-----------------------------------------------------------------------
+!     generates a random number on (0,1)-real-interval
+!-----------------------------------------------------------------------
+      REAL(wp) :: mtrand_real3, zr
+      zr = REAL(mtrand_int32(),wp)
+      IF (zr.LT.0._wp) zr = zr + 2._wp**32
+      mtrand_real3 = ( zr + 0.5_wp ) / 4294967296._wp
+   END FUNCTION mtrand_real3
+   FUNCTION mtrand_res53()
+!-----------------------------------------------------------------------
+!     generates a random number on [0,1) with 53-bit resolution
+!-----------------------------------------------------------------------
+      REAL(wp) :: mtrand_res53
+      REAL(wp) :: za,zb
+      za = ISHFT(mtrand_int32(),-5)
+      zb = ISHFT(mtrand_int32(),-6)
+      IF (za.LT.0._wp) za = za + 2._wp**32
+      IF (zb.LT.0._wp) zb = zb + 2._wp**32
+      mtrand_res53 = ( za * 67108864._wp + zb ) / 9007199254740992._wp
+   END FUNCTION mtrand_res53
+END MODULE mt19937ar
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/nemotam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/nemotam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/nemotam.F90	(revision 2587)
@@ -28,4 +28,5 @@
    USE phycst          ! physical constant                  (par_cst routine)
    USE tamtrj          ! handling of the trajectory
+   USE trj_tam         ! handling of the trajectory
    USE tamctl          ! Control parameters
    USE oce_tam         ! TL and adjoint data
@@ -33,5 +34,5 @@
    USE trc_oce_tam     ! Trend tangent and adjoint arrays
    USE sol_oce_tam     ! Solver tangent and adjoint arrays
-   USE tamtst          ! Gradient testing
+   USE tamtst
    ! ocean physics
 #if defined key_tam
@@ -41,4 +42,5 @@
    USE zdfini 
 
+#if defined key_tst_tlm
 #if defined key_tam
    USE opatam_tst_ini, ONLY :  &
@@ -47,4 +49,5 @@
      & opatam_4_tst_ini
 #endif
+#endif
 
    IMPLICIT NONE
@@ -109,5 +112,5 @@
       !! * Local declarations
       CHARACTER (len=128) :: file_out = 'nemovar.output'
-      CHARACTER (len=*), PARAMETER  ::  namelistname = 'namelist.nemovar' 
+      CHARACTER (len=*), PARAMETER  ::  namelistname = 'namelist.nemotam' 
       NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
          &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
@@ -127,7 +130,8 @@
 
       ! Nodes selection
-      narea = mynode()
-      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      nproc = mynode()
+      narea = nproc + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
       lwp   = narea == 1
+      ln_rstart = .FALSE.
 
       ! open additionnal listing
@@ -185,4 +189,5 @@
       CALL     tam_trj_ini
 
+      CALL day_init
       CALL day( nit000 )
 
@@ -204,7 +209,6 @@
 
       !! * Local declarations
-      NAMELIST/namtst/ ln_tst, ln_tst_bkgadj, ln_tst_obsadj, ln_tst_nemotam, &
-         &             ln_tst_grad, ln_tst_cpd_tam, ln_tst_stp_tam, &
-         &             ln_tst_tan_cpd, ln_tst_tan
+      NAMELIST/namtst/ ln_tst_nemotam, ln_tst_cpd_tam, ln_tst_stp_tam, &
+         &             ln_tst_tan_cpd, ln_tst_tan, ln_tst_stop
 
       REAL(wp) :: &
@@ -241,13 +245,10 @@
       i_flag_rc = 0
 
-      ln_tst         = .TRUE.
-      ln_tst_obsadj  = .FALSE.
-      ln_tst_bkgadj  = .FALSE.
       ln_tst_nemotam = .FALSE.
-      ln_tst_grad    = .FALSE.
       ln_tst_cpd_tam = .FALSE.
       ln_tst_stp_tam = .FALSE.
       ln_tst_tan_cpd = .FALSE.
       ln_tst_tan     = .FALSE.
+      ln_tst_stop    = .FALSE.
 
       REWIND( numnam )
@@ -258,9 +259,6 @@
          WRITE(numout,*) ' namtst'
          WRITE(numout,*) ' '
-         WRITE(numout,*) ' master switch for operator tests     ln_tst = ',ln_tst
-         WRITE(numout,*) ' switch for H adjoint tests    ln_tst_obsadj = ',ln_tst_obsadj
-         WRITE(numout,*) ' switch for B adjoint tests    ln_tst_bkgadj = ',ln_tst_bkgadj
          WRITE(numout,*) ' switch for M adjoint tests   ln_tst_nemotam = ',ln_tst_nemotam
-         WRITE(numout,*) ' switch for gradient test        ln_tst_grad = ',ln_tst_grad
+         WRITE(numout,*) ' stop after tests                ln_tst_stop = ',ln_tst_stop
          WRITE(numout,*) ' '
 
@@ -269,5 +267,5 @@
       ! B.4 Tests
 
-      IF ( ln_tst ) CALL tstopt
+      IF ( ln_tst_nemotam ) CALL tsttam
 
    END SUBROUTINE nemotam_sub
@@ -296,4 +294,13 @@
       IF ( lk_mpp ) CALL mppsync
 
+      ! Deallocate variables
+      ! --------------------
+      CALL oce_tam_deallocate ( 0 )
+      CALL sol_oce_tam_deallocate ( 0 )
+#if defined key_tam
+      CALL sbc_oce_tam_deallocate ( 0 )
+      CALL trc_oce_tam_deallocate ( 0 )
+#endif
+      CALL trj_deallocate
       ! Unit close
       ! ----------
@@ -301,5 +308,5 @@
       CLOSE( numnam )       ! namelist
       CLOSE( numout )       ! standard model output file
-      IF ( .NOT. lini ) THEN
+      IF (  lini ) THEN
          CLOSE( numtan_sc )    ! tangent test diagnostic output
          CLOSE( numtan )       ! tangent diagnostic output
@@ -349,19 +356,15 @@
       !!----------------------------------------------------------------------
       !! * Local declarations
-      NAMELIST/namtst/ ln_tst, ln_tst_bkgadj, ln_tst_obsadj, ln_tst_nemotam, &
-         &             ln_tst_grad, ln_tst_cpd_tam, ln_tst_stp_tam, &
-         &             ln_tst_tan_cpd, ln_tst_tan
+      NAMELIST/namtst/ ln_tst_nemotam, ln_tst_cpd_tam, ln_tst_stp_tam, &
+         &             ln_tst_tan_cpd, ln_tst_tan, ln_tst_stop
       CHARACTER (len=*), PARAMETER  ::  namelistname = 'namelist.nemotam'
       !! * Arguments
 
-      ln_tst         = .TRUE.
-      ln_tst_obsadj  = .FALSE.
-      ln_tst_bkgadj  = .FALSE.
       ln_tst_nemotam = .FALSE.
-      ln_tst_grad    = .FALSE.
       ln_tst_cpd_tam = .FALSE.
       ln_tst_stp_tam = .FALSE.
       ln_tst_tan_cpd = .FALSE.
       ln_tst_tan     = .FALSE.
+      ln_tst_stop    = .TRUE.
 
       CALL ctlopn( numnam, namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
@@ -372,6 +375,10 @@
 
       IF ( ln_tst_tan ) THEN
+#if defined key_tst_tlm
          CALL  opa_opatam_ini
          lini = .FALSE.            ! not standard initialisation
+#else
+         CALL ctl_stop( 'Activate key_tst_tlm for ln_tst_tan=.true.' )
+#endif
       ELSE
          CALL nemotam_init
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/nemotam_hlt.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/nemotam_hlt.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/nemotam_hlt.F90	(revision 2587)
@@ -0,0 +1,123 @@
+MODULE nemotam_hlt
+#if defined key_tam
+   !!==========================================================================
+   !!                       ***  MODULE nemotam ***
+   !! NEMOTAM system : Tangent and Adjoint for NEMO.
+   !!==========================================================================
+
+   !!----------------------------------------------------------------------
+   !!   nemotam_main   : Main driver routine for NEMOTAM
+   !!   nemotam_init   : Initialization of NEMOTAM
+   !!   nemotam_final  : Finish up NEMOTAM
+   !!----------------------------------------------------------------------
+   !! History :
+   !!   1.0  !  07-06  (K. Mogensen) Initial version
+   !!        !  09-06  (F. Vigilant)  Modified to split NEMOVAR / NEMOTAM
+   !!                                     module tamctl     i/o varctl
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE hlttst          ! testing routine of linear-tangent hypothesis
+   USE par_tlm
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+
+   !! * Routine accessibility
+
+   PUBLIC &
+      & nemotam_hlt_main  
+
+CONTAINS
+
+   SUBROUTINE nemotam_hlt_main 
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE nemotam_main  ***
+      !!          
+      !! ** Purpose : Main driver routine for NEMOTAM
+      !!
+      !! ** Method  : Nothing yet
+      !!
+      !! ** Action  : Nothing yet
+      !!
+      !! History :
+      !!        !  07-06  (K. Mogensen) Original code
+      !!----------------------------------------------------------------------
+
+      !! * Local declarations
+
+      ! Read namelist for model  
+      CALL hlt_root
+
+      ! Main tst
+      CALL hlt_tst
+
+   END SUBROUTINE nemotam_hlt_main
+
+   SUBROUTINE hlt_root
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE nemovar_root ***
+      !!          
+      !! ** Purpose : Choose which init must be done according to test
+      !!
+      !! ** Method  : Read namelist
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  10-07  (F. Vigilant) Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE par_tlm
+!      USE in_out_manager, ONLY: & ! I/O manager
+!      & numnam, numout
+      !! * Arguments
+
+      !! * Local declarations
+      NAMELIST/namhlt/ nstg, ln_hltt, ln_hlts, ln_hltuv, ln_hltssh, c_hltinc, &
+                     & ln_incdx, ln_hnorm, rhstdt, rhstds, rhstduv, rhstdssh 
+
+      CHARACTER (len=20) ::  namelistname = 'namelist.hlt'
+      CHARACTER (len=28) ::  file_out
+      !! * Arguments
+
+      nstg = 0
+      ln_hltt   = .FALSE.
+      ln_hlts   = .FALSE.
+      ln_hltuv  = .FALSE.
+      ln_hltssh = .FALSE.
+      c_hltinc  = ''
+      ln_incdx  = .FALSE.
+      ln_hnorm  = .FALSE.
+      rhstdt    = 1.0_wp
+      rhstds    = 0.1_wp
+      rhstduv   = 0.01_wp
+      rhstdssh  = 0.01_wp
+
+      file_out = 'nemohlt.output'
+     
+      ! open listing and namelist units
+      CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+         &         'SEQUENTIAL', 1, 6, .FALSE., 1 )
+
+      WRITE(numout,*)
+      WRITE(numout,*) '                 L O D Y C - I P S L'
+      WRITE(numout,*) '                     O P A model'
+      WRITE(numout,*) '            Ocean General Circulation Model'
+      WRITE(numout,*) '               version OPA 9.0  (2005) '
+      WRITE(numout,*)
+      WRITE(numout,*)
+      call flush(numout)
+
+      CALL ctlopn( numnam,namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, .FALSE., 1 )
+
+      REWIND( numnam )
+      READ  ( numnam, namhlt )
+
+   END SUBROUTINE hlt_root
+#endif 
+END MODULE nemotam_hlt
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/oce_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/oce_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/oce_tam.F90	(revision 2587)
@@ -34,4 +34,5 @@
    PUBLIC &
       & oce_tam_init, & !: Initialize the TAM fields
+      & oce_tam_deallocate, &
                     !:
       & ub_tl,    & !: Tangent linear of before u-component velocity
@@ -788,4 +789,222 @@
 
    END SUBROUTINE oce_tam_init
+   SUBROUTINE oce_tam_deallocate ( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE oce_tam_deallocate  ***
+      !!
+      !! ** Purpose : Deallocate the tangent linear and 
+      !!              adjoint arrays
+      !!
+      !! ** Method  : kindic = 0  deallocate both tl and ad variables
+      !!              kindic = 1  deallocate only tl variables
+      !!              kindic = 2  deallocate only ad variables
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 2010-06 (A. Vidard) initial version
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to allocate/initialize
+      
+      !! * Local declarations
+      ! Dellocate tangent linear variable arrays
+      ! ---------------------------------------
+      
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( ALLOCATED(ub_tl) ) DEALLOCATE( ub_tl )
+
+         IF ( ALLOCATED(un_tl) ) DEALLOCATE( un_tl )
+
+         IF ( ALLOCATED(ua_tl) ) DEALLOCATE( ua_tl )
+
+         IF ( ALLOCATED(vb_tl) ) DEALLOCATE( vb_tl )
+
+         IF ( ALLOCATED(vn_tl) ) DEALLOCATE( vn_tl )
+
+         IF ( ALLOCATED(va_tl) ) DEALLOCATE( va_tl )
+
+         IF ( ALLOCATED(wn_tl) ) DEALLOCATE( wn_tl )
+
+         IF ( ALLOCATED(rotb_tl) ) DEALLOCATE( rotb_tl )
+            
+         IF ( ALLOCATED(rotn_tl) ) DEALLOCATE( rotn_tl )
+            
+         IF ( ALLOCATED(hdivb_tl) ) DEALLOCATE( hdivb_tl )
+
+         IF ( ALLOCATED(hdivn_tl) ) DEALLOCATE( hdivn_tl )
+            
+         IF ( ALLOCATED(tb_tl) ) DEALLOCATE( tb_tl )
+            
+         IF ( ALLOCATED(tn_tl) ) DEALLOCATE( tn_tl )
+
+         IF ( ALLOCATED(ta_tl) ) DEALLOCATE( ta_tl )
+            
+         IF ( ALLOCATED(sb_tl) ) DEALLOCATE( sb_tl )
+
+         IF ( ALLOCATED(sn_tl) ) DEALLOCATE( sn_tl )
+
+         IF ( ALLOCATED(sa_tl) ) DEALLOCATE( sa_tl )
+            
+         IF ( ALLOCATED(rhd_tl) ) DEALLOCATE( rhd_tl )
+            
+         IF ( ALLOCATED(rhop_tl) ) DEALLOCATE( rhop_tl )
+
+         IF ( ALLOCATED(rn2_tl) ) DEALLOCATE( rn2_tl )
+
+         IF ( ALLOCATED(spgu_tl) ) DEALLOCATE( spgu_tl )
+            
+         IF ( ALLOCATED(spgv_tl) ) DEALLOCATE( spgv_tl )
+            
+#if defined key_dynspg_rl
+         IF ( ALLOCATED(bsfb_tl) ) DEALLOCATE( bsfb_tl )
+         
+         IF ( ALLOCATED(bsfn_tl) ) DEALLOCATE( bsfn_tl )
+         
+         IF ( ALLOCATED(bsfd_tl) ) DEALLOCATE( bsfd_tl )
+         
+#else
+         IF (ALLOCATED(sshb_tl) ) DEALLOCATE( sshb_tl )
+
+         IF (ALLOCATED(sshn_tl) ) DEALLOCATE( sshn_tl )
+
+         IF (ALLOCATED(ssha_tl) ) DEALLOCATE( ssha_tl )
+
+         IF (ALLOCATED(sshu_tl) ) DEALLOCATE( sshu_tl )
+
+         IF (ALLOCATED(sshv_tl) ) DEALLOCATE( sshv_tl )
+
+         IF (ALLOCATED(sshbb_tl) ) DEALLOCATE( sshbb_tl )
+
+#endif      
+         IF ( ALLOCATED(gtu_tl) ) DEALLOCATE( gtu_tl )
+
+         IF ( ALLOCATED(gtv_tl) ) DEALLOCATE( gtv_tl )
+
+         IF ( ALLOCATED(gsu_tl) ) DEALLOCATE( gsu_tl )
+
+         IF ( ALLOCATED(gsv_tl) ) DEALLOCATE( gsv_tl )
+
+         IF ( ALLOCATED(gru_tl) ) DEALLOCATE( gru_tl )
+
+         IF ( ALLOCATED(grv_tl) ) DEALLOCATE( grv_tl )
+
+
+
+#if defined key_zdfddm
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!!!  AW: The declaration/allocation/initialization of these variables
+!!!!      should be moved to a new module zdf_ddm_tam_init to be consistent
+!!!!      with NEMO.
+         IF ( ALLOCATED(rrau_tl) ) DEALLOCATE( rrau_tl )
+            
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+
+      ENDIF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+
+         ! Allocate adjoint variable arrays
+         ! --------------------------------
+      
+         IF ( ALLOCATED(ub_ad) ) DEALLOCATE( ub_ad )
+
+         IF ( ALLOCATED(un_ad) ) DEALLOCATE( un_ad )
+
+         IF ( ALLOCATED(ua_ad) ) DEALLOCATE( ua_ad )
+
+         IF ( ALLOCATED(vb_ad) ) DEALLOCATE( vb_ad )
+
+         IF ( ALLOCATED(vn_ad) ) DEALLOCATE( vn_ad )
+
+         IF ( ALLOCATED(va_ad) ) DEALLOCATE( va_ad )
+
+         IF ( ALLOCATED(wn_ad) ) DEALLOCATE( wn_ad )
+            
+         IF ( ALLOCATED(rotb_ad) ) DEALLOCATE( rotb_ad )
+
+         IF ( ALLOCATED(rotn_ad) ) DEALLOCATE( rotn_ad )
+
+         IF ( ALLOCATED(hdivb_ad) ) DEALLOCATE( hdivb_ad )
+
+         IF ( ALLOCATED(hdivn_ad) ) DEALLOCATE( hdivn_ad )
+
+         IF ( ALLOCATED(tb_ad) ) DEALLOCATE( tb_ad )
+            
+         IF ( ALLOCATED(tn_ad) ) DEALLOCATE( tn_ad )
+
+         IF ( ALLOCATED(ta_ad) ) DEALLOCATE( ta_ad )
+
+         IF ( ALLOCATED(sb_ad) ) DEALLOCATE( sb_ad )
+            
+         IF ( ALLOCATED(sn_ad) ) DEALLOCATE( sn_ad )
+            
+         IF ( ALLOCATED(sa_ad) ) DEALLOCATE( sa_ad )
+            
+         IF ( ALLOCATED(rhd_ad) ) DEALLOCATE( rhd_ad )
+            
+         IF ( ALLOCATED(rhop_ad) ) DEALLOCATE( rhop_ad )
+            
+         IF ( ALLOCATED(rn2_ad) ) DEALLOCATE( rn2_ad )
+
+         IF ( ALLOCATED(spgu_ad) ) DEALLOCATE( spgu_ad )
+
+         IF ( ALLOCATED(spgv_ad) ) DEALLOCATE( spgv_ad )
+
+#if defined key_dynspg_rl
+         IF ( ALLOCATED(bsfb_ad) ) DEALLOCATE( bsfb_ad )
+         
+         IF ( ALLOCATED(bsfn_ad) ) DEALLOCATE( bsfn_ad )
+
+         IF ( ALLOCATED(bsfd_ad) ) DEALLOCATE( bsfd_ad )
+
+#else
+         IF ( ALLOCATED(sshb_ad) ) DEALLOCATE( sshb_ad )
+
+         IF ( ALLOCATED(sshn_ad) ) DEALLOCATE( sshn_ad )
+
+         IF ( ALLOCATED(ssha_ad) ) DEALLOCATE( ssha_ad )
+
+         IF ( ALLOCATED(sshu_ad) ) DEALLOCATE( sshu_ad )
+
+         IF ( ALLOCATED(sshv_ad) ) DEALLOCATE( sshv_ad )
+
+         IF ( ALLOCATED(sshbb_ad) ) DEALLOCATE( sshbb_ad )
+
+#endif      
+         IF ( ALLOCATED(gtu_ad) ) DEALLOCATE( gtu_ad )
+
+         IF ( ALLOCATED(gtv_ad) ) DEALLOCATE( gtv_ad )
+
+         IF ( ALLOCATED(gsu_ad) ) DEALLOCATE( gsu_ad )
+
+         IF ( ALLOCATED(gsv_ad) ) DEALLOCATE( gsv_ad )
+
+         IF ( ALLOCATED(gru_ad) ) DEALLOCATE( gru_ad )
+
+         IF ( ALLOCATED(grv_ad) ) DEALLOCATE( grv_ad )
+
+
+
+#if defined key_zdfddm
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!!!  AW: The declaration/allocation/initialization of these variables
+!!!!      should be moved to a new module zdf_ddm_tam_init to be consistent
+!!!!      with NEMO.
+         IF ( ALLOCATED(rrau_ad) ) DEALLOCATE( rrau_ad )
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+      ENDIF
+
+   END SUBROUTINE oce_tam_deallocate
       
 END MODULE oce_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opahlt.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opahlt.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opahlt.F90	(revision 2587)
@@ -0,0 +1,449 @@
+MODULE opahlt
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE opa_htl   ***
+   !! Ocean system   : OPA ocean dynamics (including on-line tracers and sea-ice)
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   opa_hlt            : solve ocean dynamics, tracer and/or sea-ice
+   !!   opa_htl_init       : initialization of the opa model 
+   !!   opa_hlt_closefile  : close remaining files
+   !!----------------------------------------------------------------------
+   !! History :
+   !!                  ()  Original code from opa
+   !!        !  10-07  (F. Vigilant) Modification for tangent linear hyp
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! dynamics and tracers variables
+   USE dom_oce         ! ocean space domain variables
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE trdmod_oce      ! ocean variables trends
+   USE daymod          ! calendar
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+   USE obc_par         ! open boundary cond. parameters
+   USE obcini          ! open boundary cond. initialization (obc_ini routine)
+   USE bdy_par         ! unstructured open boundary cond. parameters
+   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
+   USE istate          ! initial state setting          (istate_init routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+
+   ! ocean physics
+   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
+   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
+   USE zdfini
+
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
+
+!   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
+
+   USE asminc          ! assimilation increments       (asm_inc_init routine)
+!   USE asmbkg          ! writing out background state    
+   USE tamtrj          ! writing out state trajectory 
+!   USE bias            ! bias (T,S,SSH)                   (bias_init routine)
+!   USE biaspar         ! bias  parameters
+
+   USE step            ! OPA time-stepping                  (stp     routine)
+   USE dynspg_oce      ! Control choice of surface pressure gradient schemes
+   USE prtctl          ! Print control                 (prt_ctl_init routine)
+   USE c1d             ! 1D configuration
+   USE dyncor_c1d      ! Coriolis factor at T-point
+!   USE step_c1d        ! Time stepping loop for the 1D configuration
+
+   USE trcini          ! Initialization of the passive tracers
+   USE par_tlm
+
+   USE hltinc, ONLY : &
+     & hlt_inc_bld
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   CHARACTER (len=64) ::        &
+      cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+   !! * Routine accessibility
+   PUBLIC opa_hlt        ! called by hlttst.F90
+
+CONTAINS
+
+   SUBROUTINE opa_hlt
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_hlt  ***
+      !!
+      !! ** Purpose :   opa_hlt solves the primitive equations on an orthogonal 
+      !!      curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp routine)
+      !!
+      !! References :
+      !!      Madec, Delecluse,Imbard, and Levy, 1997: reference manual.
+      !!              internal report, IPSL.
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp       ! time step index
+      !!----------------------------------------------------------------------
+
+#if defined key_agrif
+      CALL ctl_stop( '       Agrif not available')
+#endif
+      
+      CALL opa_hlt_init  ! Initializations
+
+      ! check that all process are still there... If some process have an error,
+      ! they will never enter in step and other processes will wait until the end of the cpu time!
+      IF( lk_mpp )   CALL mpp_max( nstop )
+
+      istp = nit000
+      IF( lk_c1d ) THEN                 ! 1D configuration (no AGRIF zoom)
+         CALL ctl_stop( '       lk_c1d not available')
+      ELSE
+
+         istp = nit000 - 1                
+         IF( (nstg == 1) .OR. (nstg == 3) ) CALL hlt_inc_bld( nstg )      ! increment builder
+
+
+IF( nstg .NE. 3 ) THEN
+         istp = nit000
+PRINT*,'STARTING LOOP STP'
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_agrif
+            CALL ctl_stop( '       Agrif not available')
+#else
+            CALL stp( istp )
+#endif
+            istp = istp + 1
+            IF( lk_mpp )   CALL mpp_max( nstop )
+         END DO
+ENDIF
+      ENDIF
+
+      !                                     ! ========= !
+      !                                     !  Job end  !
+      !                                     ! ========= !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
+         WRITE(numout,cform_err)
+         WRITE(numout,*) nstop, ' error have been found' 
+      ENDIF
+
+      CALL opa_hlt_closefile
+
+      IF( lk_mpp )   CALL mppstop                          ! Close all files (mpp)
+      !
+   END SUBROUTINE opa_hlt
+
+   SUBROUTINE opa_hlt_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_init  ***
+      !!
+      !! ** Purpose :   initialization of the opa model
+      !!
+      !!----------------------------------------------------------------------
+#if defined key_coupled
+      INTEGER ::   itro, istp0        ! ???
+#endif
+#if defined key_oasis3 || defined key_oasis4
+      INTEGER :: localComm
+#endif
+!      CHARACTER (len=20) ::   namelistname
+      CHARACTER (len=28) ::   file_out
+      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
+         &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
+      !!----------------------------------------------------------------------
+
+      ! Initializations
+      ! ===============
+
+      file_out = 'nemohlt.output'
+
+      ! Namelist namctl : Control prints & Benchmark
+      REWIND( numnam )
+      READ  ( numnam, namctl )
+
+#if defined key_oasis3 || defined key_oasis4
+      CALL ctl_stop( '       Key_oasis3 and key_oasis4 not available')
+#else
+      ! Nodes selection
+      nproc = mynode()
+#endif
+      narea = nproc + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+
+      ! open additionnal listing
+      IF( ln_ctl )   THEN
+         IF( narea-1 > 0 )   THEN
+            WRITE(file_out,FMT="('nemohlt.output_',I4.4)") narea-1
+            CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+            lwp = .TRUE.
+            !
+            WRITE(numout,*)
+            WRITE(numout,*) '                 L O D Y C - I P S L'
+            WRITE(numout,*) '                     O P A model'
+            WRITE(numout,*) '            Ocean General Circulation Model'
+            WRITE(numout,*) '               version OPA 9.0  (2005) '
+            WRITE(numout,*) '                   MPI Ocean output '
+            WRITE(numout,*)
+            WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '              LINEAR-TANGENT HYPOTHESIS TEST-RUN '
+         WRITE(numout,*) '              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) '       Namelist namhlt'
+         WRITE(numout,*) '             run stage                        nstg       = ', nstg
+         IF( nstg == 1 ) THEN
+            WRITE(numout,*) '             temperature increment switch     ln_hltt    = ', ln_hltt
+            WRITE(numout,*) '             salinity increment switch        ln_hlts    = ', ln_hlts
+            WRITE(numout,*) '             velocity incr. switch            ln_hltuv   = ', ln_hltuv
+            WRITE(numout,*) '             sea surface height incr. switch  ln_hltssh  = ', ln_hltssh
+         ENDIF
+         WRITE(numout,*)
+         WRITE(numout,*)
+      ENDIF
+
+
+      !                                     ! ============================== !
+      !                                     !  Model general initialization  !
+      !                                     ! ============================== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      CALL opa_hlt_flg                          ! Control prints & Benchmark
+
+                                            ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN
+         CALL mpp_init                          ! standard cutting out
+      ELSE
+         CALL mpp_init2                         ! eliminate land processors
+      ENDIF
+      
+      CALL phy_cst                          ! Physical constants
+
+      CALL dom_cfg                          ! Domain configuration
+      
+      CALL dom_init                         ! Domain
+
+      IF( lk_c1d    ) THEN                      ! adaptation for 1D configuration 
+         CALL cor_c1d                                ! redefine Coriolis at T-point
+         umask(:,:,:) = tmask(:,:,:)                 ! U, V and T-points are the same
+         vmask(:,:,:) = tmask(:,:,:)                 ! 
+      ENDIF
+
+      IF( ln_ctl    )   CALL prt_ctl_init   ! Print control
+
+      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
+
+      IF( lk_bdy    )   CALL bdy_init       ! Unstructured open boundaries
+
+      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
+
+      !                                     ! Ocean physics
+
+      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+
+      CALL zdf_init                             ! Vertical ocean physics
+
+      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
+
+
+#if defined key_top
+      CALL ctl_stop( '       Key_top not available')
+#endif
+
+#if defined key_coupled && ! defined key_oasis3 && ! defined key_oasis4
+      CALL ctl_stop( '       Key_coupled not available')
+#endif
+
+#if defined key_oasis3 || defined key_oasis4
+      CALL ctl_stop( '       Key_oasis3 and key_oasis4 not available')
+#endif
+!      IF( lk_diaobs ) THEN
+!         CALL dia_obs_init                  ! Initialize observational data
+!         CALL dia_obs( nit000 - 1 )         ! Observation operator for restart
+!      ENDIF
+
+!      CALL dia_ptr_init                     ! Poleward TRansports initialization
+      IF( lk_asminc ) CALL asm_inc_init     ! Initialize assimilation increments
+      CALL tam_trj_ini
+      IF(lwp) WRITE(numout,*)'Euler time step switch is ', neuler
+
+!      CALL bias_init                        ! Initialize bias options
+      !                                     ! =============== !
+      !                                     !  time stepping  !
+      !                                     ! =============== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+   END SUBROUTINE opa_hlt_init
+
+
+   SUBROUTINE opa_hlt_flg
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   Initialize logical flags that control the choice of
+      !!      some algorithm or control print
+      !!
+      !! ** Method  :    Read in namilist namflg logical flags
+      !!
+      !! History :
+      !!   9.0  !  03-11  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+      NAMELIST/namflg/ ln_dynhpg_imp, nn_dynhpg_rst
+      !!----------------------------------------------------------------------
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '          Namelist namctl'
+         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '             level of print                  nprint    = ', nprint
+         WRITE(numout,*) '             Start i indice for SUM control  nictls    = ', nictls
+         WRITE(numout,*) '             End i indice for SUM control    nictle    = ', nictle
+         WRITE(numout,*) '             Start j indice for SUM control  njctls    = ', njctls
+         WRITE(numout,*) '             End j indice for SUM control    njctle    = ', njctle
+         WRITE(numout,*) '             number of proc. following i     isplt     = ', isplt
+         WRITE(numout,*) '             number of proc. following j     jsplt     = ', jsplt
+         WRITE(numout,*) '             benchmark parameter (0/1)       nbench    = ', nbench
+         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
+      ENDIF
+
+      ! ... Control the sub-domain area indices for the control prints
+      IF( ln_ctl )   THEN
+         IF( lk_mpp )   THEN
+            ! the domain is forced to the real splitted domain in MPI
+            isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj
+         ELSE
+            IF( isplt == 1 .AND. jsplt == 1  ) THEN
+               CALL ctl_warn( '          - isplt & jsplt are equal to 1',   &
+                    &         '          - the print control will be done over the whole domain' )
+            ENDIF
+
+            ! compute the total number of processors ijsplt
+            ijsplt = isplt*jsplt
+         ENDIF
+
+         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
+         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
+
+         ! Control the indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN
+            ! the print control is done over the default area
+            lsp_area = .FALSE.
+         ELSE
+            ! the print control is done over a specific  area
+            lsp_area = .TRUE.
+            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
+               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
+               nictls = 1
+            ENDIF
+
+            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
+               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
+               nictle = jpiglo
+            ENDIF
+
+            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
+               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
+               njctls = 1
+            ENDIF
+
+            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
+               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
+               njctle = jpjglo
+            ENDIF
+
+         ENDIF          ! IF( nictls+nictle+njctls+njctle == 0 )
+       ENDIF            ! IF(ln_ctl)
+
+      IF( nbench == 1 )   THEN
+         SELECT CASE ( cp_cfg )
+         CASE ( 'gyre' )
+            CALL ctl_warn( '          The Benchmark is activated ' )
+         CASE DEFAULT
+            CALL ctl_stop( '          The Benchmark is based on the GYRE configuration: key_gyre must &
+               &                      be used or set nbench = 0' )
+         END SELECT
+      ENDIF
+
+      IF( nbit_cmp == 1 )   THEN
+         CALL ctl_warn( '          Bit comparison enabled. Single and multiple processor results must bit compare', &
+              &         '          WARNING: RESULTS ARE NOT PHYSICAL.' )
+      ENDIF
+
+
+      ! Read Namelist namflg : algorithm FLaG
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namflg )
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg : Hydrostatic pressure gradient algorithm'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist namflg : set algorithm flags'
+         WRITE(numout,*) '             centered (F) or semi-implicit (T)   ln_dynhpg_imp = ', ln_dynhpg_imp
+         WRITE(numout,*) '             hydrostatic pressure gradient'
+         WRITE(numout,*) '             add dynhpg implicit variable        nn_dynhpg_rst = ', nn_dynhpg_rst
+         WRITE(numout,*) '             in restart ot not nn_dynhpg_rst'
+      ENDIF
+      IF( .NOT. ln_dynhpg_imp )   nn_dynhpg_rst = 0      ! force no adding dynhpg implicit variables in restart
+
+   END SUBROUTINE opa_hlt_flg
+
+
+   SUBROUTINE opa_hlt_closefile
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  05-01  (O. Le Galloudec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      !!----------------------------------------------------------------------
+
+      IF ( lk_mpp ) CALL mppsync
+
+      ! 1. Unit close
+      ! -------------
+
+      CLOSE( numnam )           ! namelist
+      CLOSE( numout )           ! standard model output file
+
+      IF(lwp) CLOSE( numstp )   ! time-step file
+      IF(lwp) CLOSE( numsol )
+
+   END SUBROUTINE opa_hlt_closefile
+
+   !!======================================================================
+#endif
+END MODULE opahlt
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opatam_tst_ini.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opatam_tst_ini.F90	(revision 1947)
+++ 	(revision )
@@ -1,605 +1,0 @@
-MODULE opatam_tst_ini
-#if defined key_tam
-   !!==============================================================================
-   !!                       ***  MODULE opatam_tst_init   ***
-   !! Initialization of OPA and OPATAM for Tangent Linear and Adjoint modules
-   !!==============================================================================
-
-   !!----------------------------------------------------------------------
-   !!   opa_4_tst_ini    : initialization of the opa model
-   !!   opatam_4_tst_ini : initalization of the opatam model 
-   !!   opa_hdr_ini      : initialization of the Header Print out file
-   !!----------------------------------------------------------------------
-   !! History :
-   !!   9.0  !  09-06  (F. Vigilant)  Original code
-   !!                                 Mainframe from opa.F90 (07-07)
-   !!----------------------------------------------------------------------
-   !! * Modules used
-   USE oce             ! dynamics and tracers variables
-   USE cpl_oce         ! ocean-atmosphere-sea ice coupled exchanges
-   USE dom_oce         ! ocean space domain variables
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE trdmod_oce      ! ocean variables trends
-   USE daymod          ! calendar
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distributed memory computing
-   USE domcfg          ! domain configuration               (dom_cfg routine)
-   USE mppini          ! shared/distributed memory setting (mpp_init routine)
-   USE domain          ! domain initialization             (dom_init routine)
-   USE obc_par         ! open boundary cond. parameters
-   USE obcini          ! open boundary cond. initialization (obc_ini routine)
-   USE bdy_par         ! unstructured open boundary cond. parameters
-   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
-   USE istate          ! initial state setting          (istate_init routine)
-   USE eosbn2          ! equation of state            (eos bn2 routine)
-   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
-
-   ! ocean physics
-   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
-   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
-   USE zdfini
-
-   USE phycst          ! physical constant                  (par_cst routine)
-   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
-
-   USE diaptr          ! poleward transports           (dia_ptr_init routine)
-
-#if defined key_oasis3
-   USE cpl_oasis3      ! OASIS3 coupling (to ECHAM5)
-#elif defined key_oasis4
-   USE cpl_oasis4      ! OASIS4 coupling (to ECHAM5)
-#endif
-   USE dynspg_oce      ! Control choice of surface pressure gradient schemes
-   USE prtctl          ! Print control                 (prt_ctl_init routine)
-   USE c1d             ! 1D configuration
-   USE dyncor_c1d      ! Coriolis factor at T-point
-#if defined key_top
-   USE trcini          ! Initialization of the passive tracers
-#endif
-   !! * Modules used for TAM
-   USE domcfg          ! domain configuration               (dom_cfg routine)
-   USE tamctl          ! Control parameters
-   USE tamtrj          ! handling of the trajectory
-   USE oce_tam         ! TL and adjoint data
-   USE sbc_oce_tam     ! Surface BCs tangent and adjoint arrays
-   USE trc_oce_tam     ! Trend tangent and adjoint arrays
-   USE sol_oce_tam     ! Solver tangent and adjoint arrays
-   ! ocean physics
-   USE zdfini 
-!   USE nemotam, ONLY: & 
-!      & nemotam_banner  
-   USE opa
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !! * Module variables
-   CHARACTER (len=64) ::        &
-      cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
-   LOGICAL :: ldirinit = .FALSE.            ! flag if initialization of direct is done
-
-   !! * Routine accessibility
-   PUBLIC &
-     & opa_opatam_ini,          &
-     & opa_4_tst_ini,           &
-     & opatam_4_tst_ini,        &
-     & tlm_namrd
-
-
-CONTAINS 
-
-   SUBROUTINE opa_opatam_ini
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE opa_4_tst_ini  ***
-      !!
-      !! ** Purpose :   initialization of the opa+opatam model
-      !!
-      !! History :
-      !!   9.0  !  09-07  (F. Vigilant)  
-      !!                                 
-      !!----------------------------------------------------------------------
-
-!       CALL opa_model
-      CALL  opa_4_tst_ini
-      CALL  opatam_4_tst_ini
-
-   END SUBROUTINE opa_opatam_ini
-
-   SUBROUTINE opa_4_tst_ini
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE opa_4_tst_ini  ***
-      !!
-      !! ** Purpose :   initialization of the opa model
-      !!
-      !! History :
-      !!   9.0  !  09-06  (F. Vigilant)  import from opa_ini
-      !!                                 
-      !!----------------------------------------------------------------------
- 
-#if defined key_coupled
-      INTEGER ::   itro, istp0        ! ???
-#endif
-!!#if defined key_oasis3 || defined key_oasis4
-!!      INTEGER :: localComm
-!!#endif
-!!      CHARACTER (len=20) ::   namelistname
-!!      CHARACTER (len=28) ::   file_out
-!!      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
-!!         &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
-      !!----------------------------------------------------------------------
-
-      ! Initializations
-      ! ===============
-
-      CALL opa_hdr_ini
-
-      !                                     ! ============================== !
-      !                                     !  Model general initialization  !
-      !                                     ! ============================== !
-
-      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
-
-      CALL opa_flg                          ! Control prints & Benchmark
-
-                                            ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN
-         CALL mpp_init                          ! standard cutting out
-      ELSE
-         CALL mpp_init2                         ! eliminate land processors
-      ENDIF
-      
-      CALL phy_cst                          ! Physical constants
-
-      CALL dom_cfg                          ! Domain configuration
-      
-      CALL dom_init                         ! Domain
-
-      IF( lk_c1d    ) THEN                      ! adaptation for 1D configuration 
-         CALL cor_c1d                                ! redefine Coriolis at T-point
-         umask(:,:,:) = tmask(:,:,:)                 ! U, V and T-points are the same
-         vmask(:,:,:) = tmask(:,:,:)                 ! 
-      ENDIF
-
-      IF( ln_ctl    )   CALL prt_ctl_init   ! Print control
-
-      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
-
-      IF( lk_bdy    )   CALL bdy_init       ! Unstructured open boundaries
-
-!      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
-!      CALL istate_p
-      !                                     ! Ocean physics
-
-      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
-
-      CALL ldf_tra_init                         ! Lateral ocean tracer physics
-
-      CALL zdf_init                             ! Vertical ocean physics
-
-      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
-
-#if defined key_top
-      CALL trc_ini                           ! Passive tracers
-#endif
-
-      CALL dia_ptr_init                     ! Poleward Transports initialization
-      IF(lwp) WRITE(numout,*)'Euler time step switch is ', neuler
-      ldirinit = .TRUE.
-
-      CALL     tam_trj_ini
-      !                                     ! =============== !
-      !                                     !  time stepping  !
-      !                                     ! =============== !
-
-      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
-
-   END SUBROUTINE opa_4_tst_ini
-
-   SUBROUTINE opa_hdr_ini
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE opa_hdr_ini  ***
-      !!
-      !! ** Purpose :   initialization of the Header Print out file
-      !!
-      !! History :
-      !!   9.0  !  09-06  (F. Vigilant)  extract from opa_ini
-      !!                                 
-      !!----------------------------------------------------------------------
-
-      ! local declaration
-#if defined key_oasis3 || defined key_oasis4
-      INTEGER :: localComm
-#endif
-      CHARACTER (len=20) ::   namelistname
-      CHARACTER (len=28) ::   file_out
-      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
-         &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
-      ! Initializations
-      ! ===============
-
-      file_out = 'nemotam_tst.output'
-      
-      ! open listing and namelist units
-      CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
-         &         'SEQUENTIAL', 1, 6, .FALSE., 1 )
-
-      WRITE(numout,*)
-      WRITE(numout,*) '                 L O D Y C - I P S L'
-      WRITE(numout,*) '                     O P A model'
-      WRITE(numout,*) '            Ocean General Circulation Model'
-      WRITE(numout,*) '               version OPA 9.0  (2005) '
-      WRITE(numout,*)
-      WRITE(numout,*)
-
-! Already opened in nemotam_root
-!      namelistname = 'namelist.nemovar'
-!      CALL ctlopn( numnam, namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
-!         &         1, numout, .FALSE., 1 )
-
-      ! Namelist namctl : Control prints & Benchmark
-      REWIND( numnam )
-      READ  ( numnam, namctl )
-
-#if defined key_oasis3 || defined key_oasis4
-      call cpl_prism_init(localComm)
-      ! Nodes selection
-      narea = mynode(localComm)
-#else
-      ! Nodes selection
-      narea = mynode()
-#endif
-      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
-      lwp   = narea == 1
-
-      ! open additionnal listing
-!      IF( ln_ctl )   THEN
-         IF( narea-1 > 0 )   THEN
-            WRITE(file_out,FMT="('nemovar.output_',I4.4)") narea-1
-            CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
-               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
-            lwp = .TRUE.
-         ENDIF
-            !
-!      ENDIF
-      IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) '                 L O D Y C - I P S L'
-            WRITE(numout,*) '                     O P A model'
-            WRITE(numout,*) '            Ocean General Circulation Model'
-            WRITE(numout,*) '               version OPA 9.0  (2005) '
-            WRITE(numout,*) '                   MPI Ocean output '
-            WRITE(numout,*)
-            WRITE(numout,*)
-      ENDIF
-
-
-   END SUBROUTINE opa_hdr_ini
-
-   SUBROUTINE opatam_4_tst_ini
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE nemotam_init  ***
-      !!          
-      !! ** Purpose : Initialize grids
-      !!
-      !! ** Method  : Read the namelist and call reading routines
-      !!
-      !! ** Action  : Read the namelist and call reading routines
-      !!
-      !! History :
-      !!        !  09-06  (F. Vigilant) Extract from nemovar_init routine
-      !!----------------------------------------------------------------------
-
-      !! * Local declarations
-      CHARACTER (len=128) :: file_out !!= 'nemovar.output'
-!!      CHARACTER (len=*), PARAMETER  ::  namelistname = 'namelist.nemovar'
-!!      NAMELIST/namctl/ ln_ctl, nprint, nbit_cmp, nabortx, ln_smslabel, &
-!!         &             nn_smsfrq
-
-      ! open listing and namelist units
-!!      CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
-!!         &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
-!!      CALL nemotam_banner( numout )
-
-!!      CALL ctlopn( numnam, namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
-!!         &           1, numout, .FALSE., 1 )
-
-      ! Namelist namctl : Control prints & Benchmark
-!!      REWIND( numnam )
-!!      READ  ( numnam, namctl )
-
-      IF ( .NOT. ldirinit) CALL opa_hdr_ini      ! Initialization
-
-      ! Nodes selection
-      narea = mynode()
-      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
-      lwp   = narea == 1
-
-      ! open additionnal listing
-      IF( narea-1 > 0 )   THEN
-!!         IF ( .NOT. ldirinit) THEN
-!!            WRITE(file_out,FMT="('nemovar.output_',I4.4)") narea-1
-!!            IF( numout /= 0 .AND. numout /= 6 ) THEN 
-!!               CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
-!!               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
-!!            ENDIF
-!         CALL nemotam_banner( numout )
-!!         ENDIF
-         lwp = .TRUE.
-         !
-      ENDIF      
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'nemotam_init: Control prints & Benchmark'
-         WRITE(numout,*) '~~~~~~~~~~~~ '
-         WRITE(numout,*) '          Namelist namctl'
-         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
-         WRITE(numout,*) '             level of print                  nprint    = ', nprint
-         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
-      ENDIF
-
-      IF ( .NOT. ldirinit ) THEN
-        IF( jpni*jpnj == jpnij ) THEN
-           CALL mpp_init                      ! standard cutting out
-        ELSE
-           CALL mpp_init2                     ! eliminate land processors
-        ENDIF
-      ENDIF
-
-      IF (lwp) THEN
-         ! Diagnostic file for tangent test
-!         WRITE(file_out,FMT="('tan_diag.output_',I4.4)") , narea-1
-         CALL ctlopn( numtan, file_out, 'UNKNOWN', 'FORMATTED',   &
-            &         'SEQUENTIAL', 1, numtan, .FALSE., 1 )
-
-         WRITE(numtan,*) 'Routine loop      p      Nn=M(X+dX)-M(X)         En=Nn / L(hdX)       ', &
-              & 'Er = (Nn -L)/L            L                  Nn-L                   (En-1)/p   ', &
-              & '         Er/p'
-         WRITE(numtan,*) ' ---------------------------------------------------------------------',&
-              & '-------------------------------------------------------------------------------',&
-              & '-------------'
-      ENDIF
-
-      IF (lwp) THEN
-         ! Diagnostic file for tangent test (scalar sampling)
-!         WRITE(file_out,FMT="('tan_diag_sc.output_',I4.4)") , narea-1
-         CALL ctlopn( numtan_sc, file_out, 'UNKNOWN', 'FORMATTED',   &
-            &         'SEQUENTIAL', 1, numtan_sc, .FALSE., 1 )
-
-         WRITE(numtan_sc,*) 'Routine  scalar    loop    p     index i_pos. ', &
-              & 'j_pos.       scalar value'
-         WRITE(numtan_sc,*) ' ---------------------------------------------',&
-              & '-------------------------'
-      ENDIF
-
-      IF ( .NOT. ldirinit ) THEN
-         CALL phy_cst                          ! Physical constants
-         CALL dom_cfg                          ! Domain configuration  
-         CALL dom_init                         ! Domain
-
-          ! Ocean physics
-#if defined key_tam
-         CALL ldf_dyn_init                         ! Lateral ocean momentum physics
-         CALL ldf_tra_init                         ! Lateral ocean tracer physics
-#endif
-         CALL zdf_init                             ! Vertical ocean physics
-      ENDIF
-       
-      CALL     oce_tam_init( 1 )            ! OCE TAM field
-      IF ( ldirinit ) THEN
-         CALL sol_oce_tam_init( 1 )            ! Initialize solver tangent variables
-      ELSE
-         CALL sol_oce_tam_init( 0 )            ! Initialize solver tangent variables
-      ENDIF
-      CALL trc_oce_tam_init( 1 )            ! TRC TAM fields
-#if defined key_tam
-      CALL sbc_oce_tam_init( 1 )            ! SBC TAM fields
-#endif
-
-      IF ( .NOT. ldirinit) CALL     tam_trj_ini
-      IF ( .NOT. ldirinit) CALL day( nit000 )
-
-#ifdef EVENTUALLY
-
-#endif
-
-      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
-
-   END SUBROUTINE opatam_4_tst_ini
-
-   SUBROUTINE opa_flg
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE opa  ***
-      !!
-      !! ** Purpose :   Initialize logical flags that control the choice of
-      !!      some algorithm or control print
-      !!
-      !! ** Method  :    Read in namilist namflg logical flags
-      !!
-      !! History :
-      !!   9.0  !  03-11  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Local declarations
-
-      NAMELIST/namflg/ ln_dynhpg_imp, nn_dynhpg_rst
-      !!----------------------------------------------------------------------
-
-      ! Parameter control and print
-      ! ---------------------------
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
-         WRITE(numout,*) '~~~~~~~ '
-         WRITE(numout,*) '          Namelist namctl'
-         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
-         WRITE(numout,*) '             level of print                  nprint    = ', nprint
-         WRITE(numout,*) '             Start i indice for SUM control  nictls    = ', nictls
-         WRITE(numout,*) '             End i indice for SUM control    nictle    = ', nictle
-         WRITE(numout,*) '             Start j indice for SUM control  njctls    = ', njctls
-         WRITE(numout,*) '             End j indice for SUM control    njctle    = ', njctle
-         WRITE(numout,*) '             number of proc. following i     isplt     = ', isplt
-         WRITE(numout,*) '             number of proc. following j     jsplt     = ', jsplt
-         WRITE(numout,*) '             benchmark parameter (0/1)       nbench    = ', nbench
-         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
-      ENDIF
-
-      ! ... Control the sub-domain area indices for the control prints
-      IF( ln_ctl )   THEN
-         IF( lk_mpp )   THEN
-            ! the domain is forced to the real splitted domain in MPI
-            isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj
-         ELSE
-            IF( isplt == 1 .AND. jsplt == 1  ) THEN
-               CALL ctl_warn( '          - isplt & jsplt are equal to 1',   &
-                    &         '          - the print control will be done over the whole domain' )
-            ENDIF
-
-            ! compute the total number of processors ijsplt
-            ijsplt = isplt*jsplt
-         ENDIF
-
-         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
-         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
-
-         ! Control the indices used for the SUM control
-         IF( nictls+nictle+njctls+njctle == 0 )   THEN
-            ! the print control is done over the default area
-            lsp_area = .FALSE.
-         ELSE
-            ! the print control is done over a specific  area
-            lsp_area = .TRUE.
-            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
-               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
-               nictls = 1
-            ENDIF
-
-            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
-               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
-               nictle = jpiglo
-            ENDIF
-
-            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
-               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
-               njctls = 1
-            ENDIF
-
-            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
-               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
-               njctle = jpjglo
-            ENDIF
-
-         ENDIF          ! IF( nictls+nictle+njctls+njctle == 0 )
-       ENDIF            ! IF(ln_ctl)
-
-      IF( nbench == 1 )   THEN
-         SELECT CASE ( cp_cfg )
-         CASE ( 'gyre' )
-            CALL ctl_warn( '          The Benchmark is activated ' )
-         CASE DEFAULT
-            CALL ctl_stop( '          The Benchmark is based on the GYRE configuration: key_gyre must &
-               &                      be used or set nbench = 0' )
-         END SELECT
-      ENDIF
-
-      IF( nbit_cmp == 1 )   THEN
-         CALL ctl_warn( '          Bit comparison enabled. Single and multiple processor results must bit compare', &
-              &         '          WARNING: RESULTS ARE NOT PHYSICAL.' )
-      ENDIF
-
-
-      ! Read Namelist namflg : algorithm FLaG
-      ! --------------------
-      REWIND ( numnam )
-      READ   ( numnam, namflg )
-
-      ! Parameter control and print
-      ! ---------------------------
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'opa_flg : Hydrostatic pressure gradient algorithm'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '          Namelist namflg : set algorithm flags'
-         WRITE(numout,*) '             centered (F) or semi-implicit (T)   ln_dynhpg_imp = ', ln_dynhpg_imp
-         WRITE(numout,*) '             hydrostatic pressure gradient'
-         WRITE(numout,*) '             add dynhpg implicit variable        nn_dynhpg_rst = ', nn_dynhpg_rst
-         WRITE(numout,*) '             in restart ot not nn_dynhpg_rst'
-      ENDIF
-      IF( .NOT. ln_dynhpg_imp )   nn_dynhpg_rst = 0      ! force no adding dynhpg implicit variables in restart
-
-   END SUBROUTINE opa_flg
-
-
-   SUBROUTINE opa_closefile
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE opa_closefile  ***
-      !!
-      !! ** Purpose :   Close the files
-      !!
-      !! ** Method  :
-      !!
-      !! History :
-      !!   9.0  !  05-01  (O. Le Galloudec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE dtatem        ! temperature data
-      USE dtasal        ! salinity data
-      !!----------------------------------------------------------------------
-
-      IF ( lk_mpp ) CALL mppsync
-
-      ! 1. Unit close
-      ! -------------
-
-      CLOSE( numnam )           ! namelist
-      CLOSE( numout )           ! standard model output file
-
-      IF(lwp) CLOSE( numstp )   ! time-step file
-      IF(lwp) CLOSE( numsol )
-
-   END SUBROUTINE opa_closefile
-
-   SUBROUTINE tlm_namrd
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE tlm_namrd  ***
-      !!
-      !! ** Purpose :   Control feature of stp_tlm_tst loops
-      !!
-      !! ** Method  :    Read in namilist namtst_tlm parameters
-      !!
-      !! History :
-      !!   9.0  !  09-07  (F. Vigilant)  Original code
-      !!----------------------------------------------------------------------
-      !! * Module used
-      USE in_out_manager, ONLY: & ! I/O manager
-      & numout,                 &
-      & numnam,                 &
-      & lwp
-      USE par_tlm,    ONLY: &
-        & cur_loop,         &
-        & h_ratio
-      !! * Local declarations
-
-      NAMELIST/namtst_tlm/ cur_loop, h_ratio
-
-      ! Read Namelist namflg : algorithm FLaG
-      ! --------------------
-      REWIND ( numnam )
-      READ   ( numnam, namtst_tlm )
-
-      ! Parameter control and print
-      ! ---------------------------
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'tlm_namrd : Current loop iteration and h_ratio values '
-         WRITE(numout,*) '~~~~~~~~~'
-         WRITE(numout,*) '          Namelist namtst_tlm : set algorithm parameters'
-         WRITE(numout,*) '             current loop iteration  = ' , cur_loop
-         WRITE(numout,*) '             current h_ratio applied = ' , h_ratio
-         WRITE(numout,*) 
-      ENDIF
-
-   END SUBROUTINE tlm_namrd
-
-   !!======================================================================
-#endif
-END MODULE opatam_tst_ini
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opatam_tst_init.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opatam_tst_init.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/opatam_tst_init.F90	(revision 2587)
@@ -0,0 +1,584 @@
+MODULE opatam_tst_ini
+#if defined key_tam
+#if defined key_tst_tlm
+   !!==============================================================================
+   !!                       ***  MODULE opatam_tst_init   ***
+   !! Initialization of OPA and OPATAM for Tangent Linear and Adjoint modules
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   opa_4_tst_ini    : initialization of the opa model
+   !!   opatam_4_tst_ini : initalization of the opatam model 
+   !!   opa_hdr_ini      : initialization of the Header Print out file
+   !!----------------------------------------------------------------------
+   !! History :
+   !!   9.0  !  09-06  (F. Vigilant)  Original code
+   !!                                 Mainframe from opa.F90 (07-07)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! dynamics and tracers variables
+   USE cpl_oce         ! ocean-atmosphere-sea ice coupled exchanges
+   USE dom_oce         ! ocean space domain variables
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE trdmod_oce      ! ocean variables trends
+   USE daymod          ! calendar
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+   USE obc_par         ! open boundary cond. parameters
+   USE obcini          ! open boundary cond. initialization (obc_ini routine)
+   USE bdy_par         ! unstructured open boundary cond. parameters
+   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
+   USE istate          ! initial state setting          (istate_init routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+
+   ! ocean physics
+   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
+   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
+   USE zdfini
+
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
+
+   USE diaptr          ! poleward transports           (dia_ptr_init routine)
+
+#if defined key_oasis3
+   USE cpl_oasis3      ! OASIS3 coupling (to ECHAM5)
+#elif defined key_oasis4
+   USE cpl_oasis4      ! OASIS4 coupling (to ECHAM5)
+#endif
+   USE dynspg_oce      ! Control choice of surface pressure gradient schemes
+   USE prtctl          ! Print control                 (prt_ctl_init routine)
+   USE c1d             ! 1D configuration
+   USE dyncor_c1d      ! Coriolis factor at T-point
+#if defined key_top
+   USE trcini          ! Initialization of the passive tracers
+#endif
+   !! * Modules used for TAM
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE tamctl          ! Control parameters
+   USE tamtrj          ! handling of the trajectory
+   USE oce_tam         ! TL and adjoint data
+   USE sbc_oce_tam     ! Surface BCs tangent and adjoint arrays
+   USE trc_oce_tam     ! Trend tangent and adjoint arrays
+   USE sol_oce_tam     ! Solver tangent and adjoint arrays
+   ! ocean physics
+   USE zdfini 
+   USE opa
+   USE par_tlm
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   CHARACTER (len=64) ::        &
+      cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+   LOGICAL :: ldirinit = .FALSE.            ! flag if initialization of direct is done
+
+   !! * Routine accessibility
+   PUBLIC &
+     & opa_opatam_ini,          &
+     & opa_4_tst_ini,           &
+     & opatam_4_tst_ini,        &
+     & tlm_namrd
+
+
+CONTAINS 
+
+   SUBROUTINE opa_opatam_ini
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_4_tst_ini  ***
+      !!
+      !! ** Purpose :   initialization of the opa+opatam model
+      !!
+      !! History :
+      !!   9.0  !  09-07  (F. Vigilant)  
+      !!                                 
+      !!----------------------------------------------------------------------
+
+      ! Initialization
+      CALL opa_hdr_ini
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+      CALL opa_flg                          ! Control prints & Benchmark
+      CALL tlm_namrd
+
+      SELECT CASE (tlm_bch)
+         CASE ( 0, 1 )
+      CALL  opa_4_tst_ini
+         CASE ( 2 )
+      CALL  opatam_4_tst_ini
+         CASE DEFAULT
+            CALL ctl_stop( '        Wrong Value of tlm_bch')
+      END SELECT
+
+
+   END SUBROUTINE opa_opatam_ini
+
+   SUBROUTINE opa_4_tst_ini
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_4_tst_ini  ***
+      !!
+      !! ** Purpose :   initialization of the opa model
+      !!
+      !! History :
+      !!   9.0  !  09-06  (F. Vigilant)  import from opa_ini
+      !!                                 
+      !!----------------------------------------------------------------------
+ 
+#if defined key_coupled
+      INTEGER ::   itro, istp0        ! ???
+#endif
+
+      ! Initializations
+      ! ===============
+
+      !                                     ! ============================== !
+      !                                     !  Model general initialization  !
+      !                                     ! ============================== !
+
+                                            ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN
+         CALL mpp_init                          ! standard cutting out
+      ELSE
+         CALL mpp_init2                         ! eliminate land processors
+      ENDIF
+      
+      CALL phy_cst                          ! Physical constants
+
+      CALL dom_cfg                          ! Domain configuration
+      
+      CALL dom_init                         ! Domain
+
+      IF( lk_c1d    ) THEN                      ! adaptation for 1D configuration 
+         CALL cor_c1d                                ! redefine Coriolis at T-point
+         umask(:,:,:) = tmask(:,:,:)                 ! U, V and T-points are the same
+         vmask(:,:,:) = tmask(:,:,:)                 ! 
+      ENDIF
+
+      IF( ln_ctl    )   CALL prt_ctl_init   ! Print control
+
+      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
+
+      IF( lk_bdy    )   CALL bdy_init       ! Unstructured open boundaries
+
+!      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
+!      CALL istate_p
+      !                                     ! Ocean physics
+
+      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+
+      CALL zdf_init                             ! Vertical ocean physics
+
+      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
+
+#if defined key_top
+      CALL trc_ini                           ! Passive tracers
+#endif
+
+      IF(lwp) WRITE(numout,*)'Euler time step switch is ', neuler
+      ldirinit = .TRUE.
+
+      CALL     tam_trj_ini
+
+      CALL day_init
+      CALL day(nit000)
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+   END SUBROUTINE opa_4_tst_ini
+
+   SUBROUTINE opa_hdr_ini
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_hdr_ini  ***
+      !!
+      !! ** Purpose :   initialization of the Header Print out file
+      !!
+      !! History :
+      !!   9.0  !  09-06  (F. Vigilant)  extract from opa_ini
+      !!                                 
+      !!----------------------------------------------------------------------
+
+      ! local declaration
+#if defined key_oasis3 || defined key_oasis4
+      INTEGER :: localComm
+#endif
+      CHARACTER (len=20) ::   namelistname
+      CHARACTER (len=28) ::   file_out
+      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
+         &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
+      ! Initializations
+      ! ===============
+
+      file_out = 'nemotam_tst.output'
+      
+      ! open listing and namelist units
+      CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+         &         'SEQUENTIAL', 1, 6, .FALSE., 1 )
+
+      WRITE(numout,*)
+      WRITE(numout,*) '                 L O D Y C - I P S L'
+      WRITE(numout,*) '                     O P A model'
+      WRITE(numout,*) '            Ocean General Circulation Model'
+      WRITE(numout,*) '               version OPA 9.0  (2005) '
+      WRITE(numout,*)
+      WRITE(numout,*)
+
+      ! Namelist namctl : Control prints & Benchmark
+      REWIND( numnam )
+      READ  ( numnam, namctl )
+
+#if defined key_oasis3 || defined key_oasis4
+      call cpl_prism_init(localComm)
+      ! Nodes selection
+      narea = mynode(localComm)
+#else
+      ! Nodes selection
+      nproc = mynode()
+      narea = nproc + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+#endif
+      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+
+      ! open additionnal listing
+!      IF( ln_ctl )   THEN
+         IF( narea-1 > 0 )   THEN
+            WRITE(file_out,FMT="('nemotam_tst.output_',I4.4)") narea-1
+            CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+            lwp = .TRUE.
+         ENDIF
+            !
+!      ENDIF
+      IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '                 L O D Y C - I P S L'
+            WRITE(numout,*) '                     O P A model'
+            WRITE(numout,*) '            Ocean General Circulation Model'
+            WRITE(numout,*) '               version OPA 9.0  (2005) '
+            WRITE(numout,*) '                   MPI Ocean output '
+            WRITE(numout,*)
+            WRITE(numout,*)
+      ENDIF
+
+
+   END SUBROUTINE opa_hdr_ini
+
+   SUBROUTINE opatam_4_tst_ini
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE nemotam_init  ***
+      !!          
+      !! ** Purpose : Initialize grids
+      !!
+      !! ** Method  : Read the namelist and call reading routines
+      !!
+      !! ** Action  : Read the namelist and call reading routines
+      !!
+      !! History :
+      !!        !  09-06  (F. Vigilant) Extract from nemovar_init routine
+      !!----------------------------------------------------------------------
+
+      !! * Local declarations
+      CHARACTER (len=128) :: file_out !!= 'nemovar.output'
+
+
+      ! Nodes selection
+      nproc = mynode()
+      narea = nproc + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+
+      ! open additionnal listing
+      IF( narea-1 > 0 )   THEN
+!!         IF ( .NOT. ldirinit) THEN
+!!            WRITE(file_out,FMT="('nemovar.output_',I4.4)") narea-1
+!!            IF( numout /= 0 .AND. numout /= 6 ) THEN 
+!!               CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+!!               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+!!            ENDIF
+!         CALL nemotam_banner( numout )
+!!         ENDIF
+         lwp = .TRUE.
+         !
+      ENDIF      
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'nemotam_init: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+         WRITE(numout,*) '          Namelist namctl'
+         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '             level of print                  nprint    = ', nprint
+         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
+      ENDIF
+
+      IF ( .NOT. ldirinit ) THEN
+        IF( jpni*jpnj == jpnij ) THEN
+           CALL mpp_init                      ! standard cutting out
+        ELSE
+           CALL mpp_init2                     ! eliminate land processors
+        ENDIF
+      ENDIF
+
+      IF (lwp) THEN
+         ! Diagnostic file for tangent test
+         WRITE(file_out,FMT="('tan_diag.output_',I4.4)") , narea-1
+         CALL ctlopn( numtan, file_out, 'UNKNOWN', 'FORMATTED',   &
+            &         'SEQUENTIAL', 1, numtan, .FALSE., 1 )
+
+         WRITE(numtan,*) 'Routine loop      p      Nn=M(X+dX)-M(X)         En=Nn / L(hdX)       ', &
+              & 'Er = (Nn -L)/L            L                  Nn-L                   (En-1)/p   ', &
+              & '         Er/p'
+         WRITE(numtan,*) ' ---------------------------------------------------------------------',&
+              & '-------------------------------------------------------------------------------',&
+              & '-------------'
+      ENDIF
+
+      IF (lwp) THEN
+         ! Diagnostic file for tangent test (scalar sampling)
+         WRITE(file_out,FMT="('tan_diag_sc.output_',I4.4)") , narea-1
+         CALL ctlopn( numtan_sc, file_out, 'UNKNOWN', 'FORMATTED',   &
+            &         'SEQUENTIAL', 1, numtan_sc, .FALSE., 1 )
+
+         WRITE(numtan_sc,*) 'Routine  scalar    loop    p     index i_pos. ', &
+              & 'j_pos.       scalar value'
+         WRITE(numtan_sc,*) ' ---------------------------------------------',&
+              & '-------------------------'
+      ENDIF
+
+      IF ( .NOT. ldirinit ) THEN
+         CALL phy_cst                          ! Physical constants
+         CALL dom_cfg                          ! Domain configuration  
+         CALL dom_init                         ! Domain
+
+          ! Ocean physics
+#if defined key_tam
+         CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+         CALL ldf_tra_init                         ! Lateral ocean tracer physics
+#endif
+         CALL zdf_init                             ! Vertical ocean physics
+      ENDIF
+       
+      CALL     oce_tam_init( 1 )            ! OCE TAM field
+      IF ( ldirinit ) THEN
+         CALL sol_oce_tam_init( 1 )            ! Initialize solver tangent variables
+      ELSE
+         CALL sol_oce_tam_init( 0 )            ! Initialize solver tangent variables
+      ENDIF
+      CALL trc_oce_tam_init( 1 )            ! TRC TAM fields
+#if defined key_tam
+      CALL sbc_oce_tam_init( 1 )            ! SBC TAM fields
+#endif
+
+      IF ( .NOT. ldirinit) CALL     tam_trj_ini
+
+      CALL day_init
+      IF ( .NOT. ldirinit) CALL day( nit000 )
+
+#ifdef EVENTUALLY
+
+#endif
+      neuler=1
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+   END SUBROUTINE opatam_4_tst_ini
+
+   SUBROUTINE opa_flg
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   Initialize logical flags that control the choice of
+      !!      some algorithm or control print
+      !!
+      !! ** Method  :    Read in namilist namflg logical flags
+      !!
+      !! History :
+      !!   9.0  !  03-11  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+      NAMELIST/namflg/ ln_dynhpg_imp, nn_dynhpg_rst
+      !!----------------------------------------------------------------------
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '          Namelist namctl'
+         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '             level of print                  nprint    = ', nprint
+         WRITE(numout,*) '             Start i indice for SUM control  nictls    = ', nictls
+         WRITE(numout,*) '             End i indice for SUM control    nictle    = ', nictle
+         WRITE(numout,*) '             Start j indice for SUM control  njctls    = ', njctls
+         WRITE(numout,*) '             End j indice for SUM control    njctle    = ', njctle
+         WRITE(numout,*) '             number of proc. following i     isplt     = ', isplt
+         WRITE(numout,*) '             number of proc. following j     jsplt     = ', jsplt
+         WRITE(numout,*) '             benchmark parameter (0/1)       nbench    = ', nbench
+         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
+      ENDIF
+
+      ! ... Control the sub-domain area indices for the control prints
+      IF( ln_ctl )   THEN
+         IF( lk_mpp )   THEN
+            ! the domain is forced to the real splitted domain in MPI
+            isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj
+         ELSE
+            IF( isplt == 1 .AND. jsplt == 1  ) THEN
+               CALL ctl_warn( '          - isplt & jsplt are equal to 1',   &
+                    &         '          - the print control will be done over the whole domain' )
+            ENDIF
+
+            ! compute the total number of processors ijsplt
+            ijsplt = isplt*jsplt
+         ENDIF
+
+         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
+         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
+
+         ! Control the indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN
+            ! the print control is done over the default area
+            lsp_area = .FALSE.
+         ELSE
+            ! the print control is done over a specific  area
+            lsp_area = .TRUE.
+            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
+               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
+               nictls = 1
+            ENDIF
+
+            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
+               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
+               nictle = jpiglo
+            ENDIF
+
+            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
+               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
+               njctls = 1
+            ENDIF
+
+            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
+               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
+               njctle = jpjglo
+            ENDIF
+
+         ENDIF          ! IF( nictls+nictle+njctls+njctle == 0 )
+       ENDIF            ! IF(ln_ctl)
+
+      IF( nbench == 1 )   THEN
+         SELECT CASE ( cp_cfg )
+         CASE ( 'gyre' )
+            CALL ctl_warn( '          The Benchmark is activated ' )
+         CASE DEFAULT
+            CALL ctl_stop( '          The Benchmark is based on the GYRE configuration: key_gyre must &
+               &                      be used or set nbench = 0' )
+         END SELECT
+      ENDIF
+
+      IF( nbit_cmp == 1 )   THEN
+         CALL ctl_warn( '          Bit comparison enabled. Single and multiple processor results must bit compare', &
+              &         '          WARNING: RESULTS ARE NOT PHYSICAL.' )
+      ENDIF
+
+
+      ! Read Namelist namflg : algorithm FLaG
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namflg )
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg : Hydrostatic pressure gradient algorithm'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist namflg : set algorithm flags'
+         WRITE(numout,*) '             centered (F) or semi-implicit (T)   ln_dynhpg_imp = ', ln_dynhpg_imp
+         WRITE(numout,*) '             hydrostatic pressure gradient'
+         WRITE(numout,*) '             add dynhpg implicit variable        nn_dynhpg_rst = ', nn_dynhpg_rst
+         WRITE(numout,*) '             in restart ot not nn_dynhpg_rst'
+      ENDIF
+      IF( .NOT. ln_dynhpg_imp )   nn_dynhpg_rst = 0      ! force no adding dynhpg implicit variables in restart
+
+   END SUBROUTINE opa_flg
+
+
+   SUBROUTINE opa_closefile
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  05-01  (O. Le Galloudec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE dtatem        ! temperature data
+      USE dtasal        ! salinity data
+      !!----------------------------------------------------------------------
+
+      IF ( lk_mpp ) CALL mppsync
+
+      ! 1. Unit close
+      ! -------------
+
+      CLOSE( numnam )           ! namelist
+      CLOSE( numout )           ! standard model output file
+
+      IF(lwp) CLOSE( numstp )   ! time-step file
+      IF(lwp) CLOSE( numsol )
+
+   END SUBROUTINE opa_closefile
+
+   SUBROUTINE tlm_namrd
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE tlm_namrd  ***
+      !!
+      !! ** Purpose :   Control feature of stp_tlm_tst loops
+      !!
+      !! ** Method  :    Read in namilist namtst_tlm parameters
+      !!
+      !! History :
+      !!   9.0  !  09-07  (F. Vigilant)  Original code
+      !!----------------------------------------------------------------------
+      !! * Module used
+      USE in_out_manager, ONLY: & ! I/O manager
+      & numout,                 &
+      & numnam,                 &
+      & lwp
+      !! * Local declarations
+
+      NAMELIST/namtst_tlm/ tlm_bch, cur_loop, h_ratio
+
+      ! Read Namelist namflg : algorithm FLaG
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namtst_tlm )
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tlm_namrd : Current loop iteration and h_ratio values '
+         WRITE(numout,*) '~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namtst_tlm : set algorithm parameters'
+         WRITE(numout,*) '             current branch test     = ' , tlm_bch
+         WRITE(numout,*) '             current loop iteration  = ' , cur_loop
+         WRITE(numout,*) '             current h_ratio applied = ' , h_ratio
+         WRITE(numout,*) 
+      ENDIF
+
+   END SUBROUTINE tlm_namrd
+
+   !!======================================================================
+#endif
+#endif
+END MODULE opatam_tst_ini
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/partlm.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/partlm.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/partlm.F90	(revision 2587)
@@ -0,0 +1,53 @@
+MODULE par_tlm
+   !!======================================================================
+   !!                    ***  MODULE  par_tlm  ***
+   !! Tangent Model Accuracy:  parameters defined in memory 
+   !!=====================================================================
+   !!
+   !! ** Purpose :   Define in memory Tangent Model accuracy parameters
+   !!
+   !! History :
+   !!   9.0  !  07-07  (F. Vigilant)  Original code
+   !!----------------------------------------------------------------------
+
+   !! * Modules used
+   USE par_oce, ONLY:       &  !: ocean parameters
+     & wp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER , PUBLIC ::      & !!: namtst_tlm tangent test parameters
+      tlm_bch,              &  !: branch value (0:M(x); 1:M(x+dx); 2:LT(dx))
+      cur_loop = 1             !: = 1... nmax_loop (=1 means perform only direct 
+                               !                       integration)
+     
+   REAL(wp), PUBLIC ::      & !!: namtst_tlm tangent test parameters
+      h_ratio=  1.0_wp         !: ratio applied to the perturbation dX0
+
+   !! namhlt:  assimilation test parameters
+
+   INTEGER , PUBLIC ::      & !!: namhlt test parameters for tangent-linear hypothesis 
+      nstg                     !: nstg = 0 running M(X)
+
+   LOGICAL, PUBLIC  ::      & ! namhlt test parameters for tangent-linear hypothesis 
+      & ln_hltt,            & ! Switch for temperature increment
+      & ln_hlts,            & ! Switch for salinity increment
+      & ln_hltuv,           & ! Switch for velocity increment
+      & ln_hltssh,          & ! Switch for sea surface height increment
+      & ln_hnorm,	    & ! Swith to apply a normalization on increments
+      & ln_incdx	      ! dx read from file (T) or compute from restart.nc and restart2.nc (F)
+                              ! if (T) filename is increments_dx.nc
+
+   REAL(wp), PUBLIC ::      & ! namhlt test parameters for tangent-linear hypothesis 
+      & rhstdt  =  1.0_wp,  & ! temperature normalization factor
+      & rhstds  =  0.1_wp,  & ! salinity normalization factor
+      & rhstduv =  0.01_wp, & ! velocity normalization factor
+      & rhstdssh=  0.01_wp    ! sea surface height normalization factor
+
+   CHARACTER (LEN=100), PUBLIC :: &
+      & c_hltinc,           & ! file name of increment
+      & c_hltrst1,          & ! file name of restart 1
+      & c_hltrst2             ! file name of restart 2 
+
+END MODULE par_tlm
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/ran_num.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/ran_num.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/ran_num.F90	(revision 2587)
@@ -13,4 +13,7 @@
    USE dom_oce        ! Domain variables
    USE in_out_manager ! I/O stuff
+   USE mt19937ar, ONLY : &
+    & init_mtrand,       &
+    & mtrand_real1
 
    IMPLICIT NONE
@@ -118,43 +121,4 @@
        
    END FUNCTION gausva
-
-   FUNCTION psrandom( kdum ) 
-      !!----------------------------------------------------------------------
-      !!               ***  ROUTINE psrandom ***
-      !!          
-      !! ** Purpose : Pseudo-Random number generator.
-      !!
-      !! ** Method  : Returns a pseudo-random number from a uniform distribution
-      !!              between 0 and 1
-      !!              Call with kdum a negative integer to initialize.
-      !!              Thereafter, do not alter kdum between successive deviates 
-      !!              in sequence.
-      !!
-      !! ** Action  : 
-      !!
-      !! History :
-      !!        !  10-02  (F. Vigilant)  Original code 
-      !!----------------------------------------------------------------------
-      !! * Function return
-      REAL(wp) ::  &
-         & psrandom
-      !! * Arguments
-      INTEGER, INTENT(INOUT) :: &
-         & kdum          ! Seed
-      LOGICAL, SAVE :: &
-         & llinit = .FALSE.
-
-      ! Initialization
-      IF ( .NOT. llinit ) THEN
-         
-         CALL srand( kdum )
-         llinit     = .TRUE.
-         
-      ENDIF
-
-      CALL rand(psrandom) 
-
-   END FUNCTION psrandom
-   
 
    FUNCTION gaustb_2d( ki, kj, kseed, pamp, pmean  )
@@ -241,12 +205,12 @@
       IF ( niset(ki,kj) == 0 ) THEN
 
-         zv1   = 2.0_wp * psrandom_2d( ki, kj, kdum ) - 1.0_wp
-         zv2   = 2.0_wp * psrandom_2d( ki, kj, kdum ) - 1.0_wp
+         zv1   = 2.0_wp * psrandom( kdum(ki,kj) ) - 1.0_wp
+         zv2   = 2.0_wp * psrandom( kdum(ki,kj) ) - 1.0_wp
          zrsq  = zv1**2 + zv2**2
 
          DO WHILE ( ( zrsq >= 1.0_wp ) .OR. ( zrsq == 0.0_wp ) ) 
 
-            zv1   = 2.0_wp * psrandom_2d( ki, kj, kdum ) - 1.0_wp
-            zv2   = 2.0_wp * psrandom_2d( ki, kj, kdum ) - 1.0_wp
+            zv1   = 2.0_wp * psrandom( kdum(ki,kj) ) - 1.0_wp
+            zv2   = 2.0_wp * psrandom( kdum(ki,kj) ) - 1.0_wp
             zrsq  = zv1**2 + zv2**2
 
@@ -267,9 +231,9 @@
    END FUNCTION gausva_2d
 
-   FUNCTION psrandom_2d( ki, kj, kdum ) 
-      !!----------------------------------------------------------------------
-      !!               ***  ROUTINE psrandom_2d ***
-      !!          
-      !! ** Purpose : Random number generator.
+   FUNCTION psrandom( kdum )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE psrandom ***
+      !!          
+      !! ** Purpose : Pseudo-Random number generator.
       !!
       !! ** Method  : Returns a pseudo-random number from a uniform distribution
@@ -286,25 +250,26 @@
       !! * Function return
       REAL(wp) ::  &
-         & psrandom_2d
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & ki, &         ! Indices in seed array
-         & kj
-      INTEGER, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & psrandom
+      !! * Arguments
+      INTEGER, INTENT(INOUT) :: &
          & kdum          ! Seed
       LOGICAL, SAVE :: &
          & llinit = .FALSE.
+      INTEGER :: &
+	& kdum1, &
+	& kdum2
 
       ! Initialization
       IF ( .NOT. llinit ) THEN
-         
-         CALL srand( kdum( ki,kj ) )
+	 kdum2 = 596035
+	 kdum1 = kdum + nproc * kdum2
+         CALL init_mtrand(kdum)
          llinit     = .TRUE.
-         
-      ENDIF
-
-      CALL rand(psrandom_2d)  
+      ENDIF
+
+      psrandom = mtrand_real1()
       
-   END FUNCTION psrandom_2d
+   END FUNCTION psrandom
+
 
 END MODULE ran_num
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_cpd.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_cpd.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_cpd.F90	(revision 2587)
@@ -0,0 +1,411 @@
+MODULE step_cpd
+   !!======================================================================
+   !!                       ***  MODULE step  ***
+   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
+   !!======================================================================
+   !! History :        !  91-03  (G. Madec)  Original code
+   !!                  !  92-06  (M. Imbard)  add a first output record
+   !!                  !  96-04  (G. Madec)  introduction of dynspg
+   !!                  !  96-04  (M.A. Foujols)  introduction of passive tracer
+   !!             8.0  !  97-06  (G. Madec)  new architecture of call
+   !!             8.2  !  97-06  (G. Madec, M. Imbard, G. Roullet)  free surface
+   !!             8.2  !  99-02  (G. Madec, N. Grima)  hpg implicit
+   !!             8.2  !  00-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
+   !!             9.0  !  02-06  (G. Madec)  free form, suppress macro-tasking
+   !!             " "  !  04-08  (C. Talandier) New trends organization
+   !!             " "  !  05-01  (C. Ethe) Add the KPP closure scheme
+   !!             " "  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!             " "  !  05-11  (G. Madec)  Reorganisation of tra and dyn calls
+   !!             " "  !  06-01  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             " "  !  06-07  (S. Masson)  restart using iom
+   !!             " "  !  06-08  (G. Madec)  surface module 
+   !!    "        " "  !  07-04  (K. Mogensen, A. Weaver, M. Martin) Assimilation interface
+   !!             " "  !  07-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   stp            : OPA system time-stepping
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE ldftra_oce      ! ocean tracer   - trends
+   USE ldfdyn_oce      ! ocean dynamics - trends
+   USE cpl_oce         ! coupled ocean-atmosphere variables
+   USE in_out_manager  ! I/O manager
+   USE iom             !
+   USE lbclnk
+
+   USE daymod          ! calendar                         (day     routine)
+
+   USE dtatem          ! ocean temperature data           (dta_tem routine)
+   USE dtasal          ! ocean salinity    data           (dta_sal routine)
+   USE sbcmod          ! surface boundary condition       (sbc     routine)
+   USE sbcrnf          ! surface boundary condition: runoff variables
+
+   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
+
+   USE traqsr          ! solar radiation penetration      (tra_qsr routine)
+   USE trasbc          ! surface boundary condition       (tra_sbc routine)
+   USE trabbc          ! bottom boundary condition        (tra_bbc routine)
+   USE trabbl          ! bottom boundary layer            (tra_bbl routine)
+   USE tradmp          ! internal damping                 (tra_dmp routine)
+   USE traadv          ! advection scheme control     (tra_adv_ctl routine)
+   USE traldf          ! lateral mixing                   (tra_ldf routine)
+   USE cla             ! cross land advection             (tra_cla routine)
+   !   zdfkpp          ! KPP non-local tracer fluxes      (tra_kpp routine)
+   USE trazdf          ! vertical mixing                  (tra_zdf routine)
+   USE tranxt          ! time-stepping                    (tra_nxt routine)
+   USE tranpc          ! non-penetrative convection       (tra_npc routine)
+   USE trachk          ! check values of salinity         (tra_chk routine)
+
+   USE eosbn2          ! equation of state                (eos_bn2 routine)
+
+   USE dynadv          ! advection                        (dyn_adv routine)
+   USE dynvor          ! vorticity term                   (dyn_vor routine)
+   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
+   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+   USE dynspg_oce      ! surface pressure gradient        (dyn_spg routine)
+   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
+   USE dynnxt          ! time-stepping                    (dyn_nxt routine)
+
+   USE obc_par         ! open boundary condition variables
+   USE obcdta          ! open boundary condition data     (obc_dta routine)
+   USE obcrst          ! open boundary cond. restart      (obc_rst routine)
+   USE obcrad          ! open boundary cond. radiation    (obc_rad routine)
+   USE obcspg          ! open boundary cond  spg          (obc_spg routine)
+
+   USE bdy_par         ! unstructured open boundary data variables
+   USE bdydta          ! unstructured open boundary data  (bdy_dta routine)
+
+   USE divcur          ! hor. divergence and curl      (div & cur routines)
+   USE cla_div         ! cross land: hor. divergence      (div_cla routine)
+   USE wzvmod          ! vertical velocity                (wzv     routine)
+
+   USE ldfslp          ! iso-neutral slopes               (ldf_slp routine)
+   USE ldfeiv          ! eddy induced velocity coef.      (ldf_eiv routine)
+
+   USE zdfbfr          ! bottom friction                  (zdf_bfr routine)
+   USE zdftke          ! TKE vertical mixing              (zdf_tke routine)
+   USE zdfkpp          ! KPP vertical mixing              (zdf_kpp routine)
+   USE zdfddm          ! double diffusion mixing          (zdf_ddm routine)
+   USE zdfevd          ! enhanced vertical diffusion      (zdf_evd routine)
+   USE zdfric          ! Richardson vertical mixing       (zdf_ric routine)
+   USE zdfmxl          ! Mixed-layer depth                (zdf_mxl routine)
+
+   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
+   USE ice_oce         ! sea-ice variable
+
+   USE diawri          ! Standard run outputs             (dia_wri routine)
+   USE trdicp          ! Ocean momentum/tracers trends    (trd_wri routine)
+   USE trdmld          ! mixed-layer trends               (trd_mld routine)
+   USE trdmld_rst      ! restart for mixed-layer trends
+   USE trdmod_oce      ! ocean momentum/tracers trends
+   USE trdvor          ! vorticity budget                 (trd_vor routine)
+   USE diagap          ! hor. mean model-data gap         (dia_gap routine)
+   USE diahdy          ! dynamic height                   (dia_hdy routine)
+   USE diaptr          ! poleward transports              (dia_ptr routine)
+   USE diahth          ! thermocline depth                (dia_hth routine)
+   USE diafwb          ! freshwater budget                (dia_fwb routine)
+   USE diaspr          ! suface pressure (rigid-lid)      (dia_spr routine)
+   USE diaobs          ! obs-minus-model (assimilation)   (dia_obs routine)
+   USE flo_oce         ! floats variables
+   USE floats          ! floats computation               (flo_stp routine)
+   USE asminc          ! assimilation increments          
+   USE asmbkg          ! writing out background term    
+   USE tamtrj          ! writing out state trajectory       
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+   USE restart         ! ocean restart                    (rst_wri routine)
+   USE prtctl          ! Print control                    (prt_ctl routine)
+   USE domvvl          ! variable volume                  (dom_vvl routine)
+
+#if defined key_agrif
+   USE agrif_opa_sponge ! Momemtum and tracers sponges
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC stp_cpd            ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_agrif
+   SUBROUTINE stp_cpd( )
+#else
+   SUBROUTINE stp_cpd( kstp )
+#endif
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp  ***
+      !!                      
+      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
+      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
+      !!              - Tme stepping  of TRC (passive tracer eqs.)
+      !! 
+      !! ** Method  : -1- Update forcings and data  
+      !!              -2- Update ocean physics 
+      !!              -3- Compute the t and s trends 
+      !!              -4- Update t and s 
+      !!              -5- Compute the momentum trends
+      !!              -6- Update the horizontal velocity
+      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
+      !!              -8- Outputs and diagnostics
+      !!----------------------------------------------------------------------
+      !! * Arguments
+#if defined key_agrif   
+      INTEGER             ::   kstp   ! ocean time-step index
+#else
+      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
+#endif      
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zta_tmp, zsa_tmp
+      INTEGER ::   jk       ! dummy loop indice
+      INTEGER ::   indic    ! error indicator if < 0
+      !! ---------------------------------------------------------------------
+
+#if defined key_agrif
+      kstp = nit000 + Agrif_Nb_Step()
+!      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
+!      IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp
+#endif   
+      indic = 1                    ! reset to no error condition
+
+      CALL day( kstp )             ! Calendar
+
+      CALL rst_opn( kstp )         ! Open the restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update data, open boundaries, surface boundary condition (including sea-ice)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( lk_dtatem  )   CALL dta_tem( kstp )         ! update 3D temperature data
+      IF( lk_dtasal  )   CALL dta_sal( kstp )         ! update 3D salinity data
+
+                         CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
+
+      IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
+      IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
+
+      IF( lk_bdy     )   CALL bdy_dta( kstp )         ! update dynamic and tracer data at unstructured open boundary
+
+      IF( ninist == 1 ) THEN                       ! Output the initial state and forcings
+                        CALL dia_wri_state( 'output.init' )
+                        ninist = 0
+      ENDIF
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !-----------------------------------------------------------------------
+      !  VERTICAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                        CALL bn2( tb, sb, rn2 )              ! before Brunt-Vaisala frequency
+      
+      !                                                     ! Vertical eddy viscosity and diffusivity coefficients
+      IF( lk_zdfric )   CALL zdf_ric( kstp )                       ! Richardson number dependent Kz
+
+      IF( lk_zdftke )   CALL zdf_tke( kstp )                       ! TKE closure scheme for Kz
+      IF( lk_zdfkpp )   CALL zdf_kpp( kstp )                       ! KPP closure scheme for Kz
+
+      IF( lk_zdfcst )   THEN                                       ! Constant Kz (reset avt, avm[uv] to the background value)
+         avt (:,:,:) = avt0 * tmask(:,:,:)
+         avmu(:,:,:) = avm0 * umask(:,:,:)
+         avmv(:,:,:) = avm0 * vmask(:,:,:)
+      ENDIF
+
+      IF( ln_rnf_mouth ) THEN                                ! increase diffusivity at rivers mouths
+         DO jk = 2, nkrnf   ;   avt(:,:,jk) = avt(:,:,jk) + 2.e0 * rn_avt_rnf * rnfmsk(:,:)   ;   END DO
+      ENDIF
+
+      IF( ln_zdfevd )   CALL zdf_evd( kstp )                 ! enhanced vertical eddy diffusivity
+
+      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   &
+         &              CALL zdf_ddm( kstp )                 ! double diffusive mixing
+
+                        CALL zdf_bfr( kstp )                 ! bottom friction
+
+                        CALL zdf_mxl( kstp )                 ! mixed layer depth
+
+
+      !-----------------------------------------------------------------------
+      !  LATERAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+      IF( lk_ldfslp     )   CALL ldf_slp( kstp, rhd, rn2 )       ! before slope of the lateral mixing
+#if defined key_traldf_c2d
+      IF( lk_traldf_eiv )   CALL ldf_eiv( kstp )                 ! eddy induced velocity coefficient
+#endif
+
+#if defined key_top
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Passive Tracer Model
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+                             CALL trc_stp( kstp, indic )            ! time-stepping
+#endif
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+                             ta(:,:,:) = 0.e0               ! set tracer trends to zero
+                             sa(:,:,:) = 0.e0
+
+      IF(  ln_asmiau .AND. &
+         & ln_trainc     )   CALL tra_asm_inc( kstp )       ! apply tracer assimilation increment
+                             CALL tra_sbc    ( kstp )       ! surface boundary condition
+      IF( ln_traqsr      )   CALL tra_qsr    ( kstp )       ! penetrative solar radiation qsr
+      IF( lk_trabbc      )   CALL tra_bbc    ( kstp )       ! bottom heat flux
+      IF( lk_trabbl_dif  )   CALL tra_bbl_dif( kstp )       ! diffusive bottom boundary layer scheme
+      IF( lk_trabbl_adv  )   CALL tra_bbl_adv( kstp )       ! advective (and/or diffusive) bottom boundary layer scheme
+      IF( lk_tradmp      )   CALL tra_dmp    ( kstp )       ! internal damping trends
+!                             CALL tra_adv    ( kstp )       ! horizontal & vertical advection
+!      IF( n_cla == 1     )   CALL tra_cla    ( kstp )       ! Cross Land Advection (Update Hor. advection)
+      IF( lk_zdfkpp )        CALL tra_kpp    ( kstp )       ! KPP non-local tracer fluxes
+!                             CALL tra_ldf    ( kstp )       ! lateral mixing
+#if defined key_agrif
+      IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_tra          ! tracers sponge
+#endif
+!                             CALL tra_zdf    ( kstp )       ! vertical mixing and after tracer fields
+      IF( ln_zdfnpc      )   CALL tra_npc    ( kstp )       ! update after fields by non-penetrative convection
+!                             CALL tra_nxt    ( kstp )       ! tracer fields at next time step
+      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg
+                               CALL eos( ta, sa, rhd, rhop )          ! Time-filtered in situ density used in dynhpg module
+         IF( ln_zps    )       CALL zps_hde( kstp, ta, sa, rhd,   &   ! Partial steps: time filtered hor. gradient
+            &                                     gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
+            &                                     gtv, gsv, grv )
+      ELSE                                                  ! centered hpg (default case)
+                               CALL eos( tb, sb, rhd, rhop )          ! now (swap=before) in situ density for dynhpg module
+         IF( ln_zps    )       CALL zps_hde( kstp, tb, sb, rhd,   &   ! Partial steps: now horizontal gradient
+            &                                     gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
+            &                                     gtv, gsv, grv )
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! saving ta and sa (temporary fix, please do not remove)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                               zta_tmp(:,:,:) = ta(:,:,:)
+                               zsa_tmp(:,:,:) = sa(:,:,:)
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ta, sa arrays are used as workspace in this section 
+      !-----------------------------------------------------------------------
+                               ua(:,:,:) = 0.e0               ! set dynamics trends to zero
+                               va(:,:,:) = 0.e0
+
+      IF(  ln_asmiau .AND. &
+         & ln_dyninc     )     CALL dyn_asm_inc( kstp )       ! apply dynamics assimilation increment
+
+                               CALL dyn_adv( kstp )           ! advection (vector or flux form)
+                               CALL dyn_vor( kstp )           ! vorticity term including Coriolis
+                               CALL dyn_ldf( kstp )           ! lateral mixing
+#if defined key_agrif
+      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn          ! momemtum sponge
+#endif
+                               CALL dyn_hpg( kstp )           ! horizontal gradient of Hydrostatic pressure
+                               CALL dyn_zdf( kstp )           ! vertical diffusion
+      IF( lk_dynspg_rl ) THEN
+         IF( lk_obc    )       CALL obc_spg( kstp )           ! surface pressure gradient at open boundaries
+      ENDIF
+                               indic=0
+                               CALL dyn_spg( kstp, indic )    ! surface pressure gradient
+                               CALL dyn_nxt( kstp )           ! lateral velocity at next time step
+      IF( lk_vvl )             CALL dom_vvl                   ! vertical mesh at next time step
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Computation of diagnostic variables
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+                       CALL div_cur( kstp )                 ! Horizontal divergence & Relative vorticity
+      IF( n_cla == 1 ) CALL div_cla( kstp )                 ! Cross Land Advection (Update Hor. divergence)
+                       CALL wzv( kstp )                     ! Vertical velocity
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control and restarts
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                                 CALL stp_ctl( kstp, indic )
+      IF( indic < 0          )   CALL ctl_stop( 'step: indic < 0' )
+      IF( kstp == nit000     )   CALL iom_close( numror )             ! close input  ocean restart file
+      IF( lrst_oce           )   CALL rst_write  ( kstp )             ! write output ocean restart file
+      IF( lk_obc             )   CALL obc_rst_write( kstp )           ! write open boundary restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      IF( nstop == 0 ) THEN                                 ! Diagnostics:
+         IF( lk_floats  )   CALL flo_stp( kstp )                 ! drifting Floats
+         IF( lk_trddyn  )   CALL trd_dwr( kstp )                 ! trends: dynamics 
+         IF( lk_trdtra  )   CALL trd_twr( kstp )                 ! trends: active tracers
+         IF( lk_trdmld  )   CALL trd_mld( kstp )                 ! trends: Mixed-layer 
+         IF( lk_trdvor  )   CALL trd_vor( kstp )                 ! trends: vorticity budget
+         IF( lk_diaspr  )   CALL dia_spr( kstp )                 ! Surface pressure diagnostics
+         IF( lk_diahth  )   CALL dia_hth( kstp )                 ! Thermocline depth (20 degres isotherm depth)
+         IF( lk_diagap  )   CALL dia_gap( kstp )                 ! basin averaged diagnostics
+         IF( lk_diahdy  )   CALL dia_hdy( kstp )                 ! dynamical heigh diagnostics
+         IF( lk_diafwb  )   CALL dia_fwb( kstp )                 ! Fresh water budget diagnostics
+         IF( lk_diaobs  )   CALL dia_obs( kstp )                 ! obs-minus-model (assimilation) diagnostics
+         IF( ln_diaptr  )   CALL dia_ptr( kstp )                 ! Poleward TRansports diagnostics
+
+         !                                                 ! Outputs
+ 
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! restoring ta and sa (temporary fix, please do not remove)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                            ta(:,:,:) = zta_tmp(:,:,:)
+                            sa(:,:,:) = zsa_tmp(:,:,:)
+
+         !                                                 ! Outputs
+                            CALL dia_wri    ( kstp, indic )      ! ocean model: outputs
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Assimilation mode
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+         IF( lk_asminc ) THEN
+            IF( ln_bkgwri ) CALL asm_bkg_wri( kstp )       ! Output background fields
+            IF( ln_trjwri ) CALL tam_trj_wri( kstp )       ! Output trajectory fields
+            IF( ln_asmdin ) THEN                           ! Direct initialization
+               IF( ln_trainc ) CALL tra_asm_inc( kstp )        ! Tracers
+               IF( ln_dyninc ) CALL dyn_asm_inc( kstp )        ! Dynamics
+               IF( ln_sshinc ) CALL ssh_asm_inc( kstp )        ! SSH
+            ENDIF
+         ENDIF
+
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Coupled mode
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+#if defined key_oasis3
+      IF( lk_cpl    )   CALL cpl_stp( kstp )                 ! coupled mode : field exchanges
+#endif
+      !
+   END SUBROUTINE stp_cpd
+
+   !!======================================================================
+END MODULE step_cpd
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_tam.F90	(revision 2587)
@@ -43,5 +43,5 @@
       & tb, sb, tn, sn, ta,  &
       & un, vn, sshn, sshb,  &
-      & sa, ub, vb,          &
+      & sa, ub, vb, rn2,     &
       & ln_dynhpg_imp
    USE zdfkpp        , ONLY: &
@@ -76,4 +76,6 @@
       &  ln_traqsr
           ! solar radiation penetration flag
+   USE asminc
+   USE asmbkg
    USE oce_tam       , ONLY: & ! Tangent linear and adjoint variables
       & oce_tam_init,        &
@@ -134,6 +136,13 @@
    USE wzvmod_tam      ! vertical velocity                (adjoint of wzv     routine)
 
-   USE zdfkpp_tam     ! KPP vertical mixing
-
+!!   USE zdfkpp_tam     ! KPP vertical mixing
+   USE zdf_oce, ONLY : lk_zdfcst, avt, avt0, avmu, avmv, avm0, ln_zdfevd         ! KPP vertical mixing
+   USE zdfddm, ONLY  : &            ! double diffusion mixing          (zdf_ddm routine)
+      & lk_zdfddm,     &
+      & zdf_ddm  
+   USE zdfevd, only:zdf_evd         ! double diffusion mixing          (zdf_ddm routine)
+   USE zdfbfr, only:zdf_bfr         ! double diffusion mixing          (zdf_ddm routine)
+   USE zdfmxl, only:zdf_mxl         ! double diffusion mixing          (zdf_ddm routine)
+   USE eosbn2, ONLY: bn2
    USE zpshde_tam      ! partial step: hor. derivative     (adjoint of zps_hde routine)
 
@@ -186,5 +195,7 @@
    PUBLIC stp_tan,      &
       &   stp_adj,      & ! called by simvar.F90
+#if defined key_tst_tlm
       &   stp_tlm_tst,  &
+#endif
       &   stp_adj_tst
 
@@ -257,7 +268,4 @@
       ! Output the initial state and forcings ... not needed in tangent
 
-      ! saving direct variables ua,va, ta, sa before entering in tracer
-      zta_tmp (:,:,:) = ta (:,:,:)
-      zsa_tmp (:,:,:) = sa (:,:,:)
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Ocean physics update
@@ -315,7 +323,4 @@
 
 #endif
-
-      ta (:,:,:) = zta_tmp (:,:,:)
-      sa (:,:,:) = zsa_tmp (:,:,:)
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Active tracers
@@ -1184,5 +1189,5 @@
 
    END SUBROUTINE stp_adj_tst
-
+#if defined key_tst_tlm
    SUBROUTINE stp_tlm_tst( kumadt )
       !!-----------------------------------------------------------------------
@@ -1228,4 +1233,5 @@
         & lk_c1d
       USE par_tlm,    ONLY: &
+        & tlm_bch,          &
         & cur_loop,         &
         & h_ratio
@@ -1262,4 +1268,8 @@
          & zgsp1, zgsp2, zgsp3, zgsp4, zgsp5,     &
          & zgsp6, zgsp7     
+      REAL(KIND=wp) ::       &  
+         & zgsp1_U, zgsp1_V, zgsp1_T, zgsp1_S, zgsp1_SSH,     &
+         & zgsp4_U, zgsp4_V, zgsp4_T, zgsp4_S, zgsp4_SSH,      &
+         & zgsp5_U, zgsp5_V, zgsp5_T, zgsp5_S, zgsp5_SSH     
       REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
          & ta_tmp   ,        &
@@ -1288,5 +1298,5 @@
  
       CHARACTER(LEN=14)   :: cl_name
-      CHARACTER (LEN=128) :: file_out, file_wop, file_wop2
+      CHARACTER (LEN=128) :: file_out, file_wop, file_wop2, file_xdx
       CHARACTER (LEN=90)  :: FMT
 
@@ -1388,7 +1398,8 @@
       ! Output filename Xn=F(X0)
       !--------------------------------------------------------------------
-      file_wop='trj_wop_step'
       CALL tlm_namrd
       gamma = h_ratio
+      file_wop='trj_wop_step'
+      file_xdx='trj_xdx_step'
       !--------------------------------------------------------------------
       ! Initialize the tangent input with random noise: dx
@@ -1450,5 +1461,5 @@
           ENDIF
      ENDIF 
-     CALL istate_p 
+     IF ( tlm_bch /= 2 )  CALL istate_p 
 
          !--------------------------------------------------------------------
@@ -1456,7 +1467,4 @@
          !--------------------------------------------------------------------
 
-     PRINT*,'IN TST_STP h_ratio, cur_loop, gamma', h_ratio, ' ',cur_loop,' ', gamma
-     Call flush(numout)
- 
       ! check that all process are still there... If some process have an error,
       ! they will never enter in step and other processes will wait until the end of the cpu time!
@@ -1464,13 +1472,11 @@
 
         istp = nit000
+        IF ( tlm_bch /= 2 )  THEN
         IF( lk_c1d ) THEN                 ! 1D configuration (no AGRIF zoom)
-        !
            DO WHILE ( istp <= nitend .AND. nstop == 0 )
               CALL stp_c1d( istp )
               istp = istp + 1
            END DO
-        ELSE
-           istp = nit000 - 1                
-           IF( ln_trjwri ) CALL tam_trj_wri( istp )    ! Output trajectory fields
+        ENDIF
         ENDIF
 
@@ -1497,22 +1503,15 @@
         !  Compute the direct model F(X0,t=n) = Xn
         !--------------------------------------------------------------------
+        IF ( tlm_bch /= 2 )  THEN
         DO istp = nit000, nitend, 1
            CALL stp( istp )
         END DO
-        IF ( cur_loop .EQ. 0) CALL trj_wri_spl(file_wop)
-
+        ENDIF
+        IF ( tlm_bch == 0 ) CALL trj_wri_spl(file_wop)
+        IF ( tlm_bch == 1 ) CALL trj_wri_spl(file_xdx)
         !--------------------------------------------------------------------
         !  Compute the Tangent 
         !--------------------------------------------------------------------
-        IF ( cur_loop .NE. 0) THEN
-
-           !--------------------------------------------------------------------
-           !  Storing data
-           !--------------------------------------------------------------------
-           zun_out   (:,:,:) = un   (:,:,:)
-           zvn_out   (:,:,:) = vn   (:,:,:)
-           ztn_out   (:,:,:) = tn   (:,:,:)
-           zsn_out   (:,:,:) = sn   (:,:,:)
-           zsshn_out (:,:  ) = sshn (:,:  )         
+        IF ( tlm_bch == 2 ) THEN        
 
            !--------------------------------------------------------------------
@@ -1520,5 +1519,8 @@
            !--------------------------------------------------------------------
            qrp_tl = 0.0_wp
-
+#if defined key_tradmp
+           strdmp_tl = 0.0_wp
+           ttrdmp_tl = 0.0_wp
+#endif
            a_fwb_tl = 0.0_wp
 
@@ -1535,7 +1537,10 @@
            !  Initialization of the dynamics and tracer fields for the tangent
            !-----------------------------------------------------------------------
+
            CALL istate_init_tan 
+ 
            DO istp = nit000, nitend, 1
               CALL stp_tan( istp )
+              !CALL stp_tan_cpd( istp )
            END DO
        
@@ -1556,5 +1561,4 @@
            !--------------------------------------------------------------------
            CALL trj_rd_spl(file_wop)
-
            zun_wop   (:,:,:) = un   (:,:,:)
            zvn_wop   (:,:,:) = vn   (:,:,:)
@@ -1562,4 +1566,10 @@
            zsn_wop   (:,:,:) = sn   (:,:,:)
            zsshn_wop (:,:  ) = sshn (:,:  )  
+           CALL trj_rd_spl(file_xdx) 
+           zun_out   (:,:,:) = un   (:,:,:)
+           zvn_out   (:,:,:) = vn   (:,:,:)
+           ztn_out   (:,:,:) = tn   (:,:,:)
+           zsn_out   (:,:,:) = sn   (:,:,:)
+           zsshn_out (:,:  ) = sshn (:,:  )
            !--------------------------------------------------------------------
            ! Compute the Linearization Error 
@@ -1711,4 +1721,9 @@
          zzsp_SSH = SQRT(zsp3_SSH)
          zgsp5    = zzsp
+         zgsp5_U=zzsp_U
+         zgsp5_V=zzsp_V
+         zgsp5_T=zzsp_T
+         zgsp5_S=zzsp_S
+         zgsp5_SSH=zzsp_SSH
          CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
 
@@ -1729,4 +1744,9 @@
          zzsp_SSH =  SQRT(zsp2_SSH)
          zgsp4    = zzsp
+         zgsp4_U=zzsp_U
+         zgsp4_V=zzsp_V
+         zgsp4_T=zzsp_T
+         zgsp4_S=zzsp_S
+         zgsp4_SSH=zzsp_SSH
          cl_name = 'step_tam:Ln2  '
          CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
@@ -1761,10 +1781,15 @@
          zgsp7    = zgsp3/gamma
          zgsp1    = zzsp
+         zgsp1_U=zzsp_U
+         zgsp1_V=zzsp_V
+         zgsp1_T=zzsp_T
+         zgsp1_S=zzsp_S
+         zgsp1_SSH=zzsp_SSH
          zgsp2    = zgsp1 / zgsp4
          zgsp6    = (zgsp2 - 1.0_wp)/gamma
 
          FMT = "(A8,2X,I4.4,2X,E6.1,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13,2X,E20.13)"
-         WRITE(numtan,FMT) 'step    ', cur_loop, h_ratio, zgsp1, zgsp2, zgsp3, zgsp4, zgsp5, zgsp6, zgsp7
-
+
+         WRITE(numtan,FMT) 'step    ', cur_loop, h_ratio, zgsp1, zgsp1_T ,zgsp4_T, zgsp5_T,zgsp1_S,zgsp4_S,zgsp5_S!,
          !--------------------------------------------------------------------
          ! Unitary calculus
@@ -1921,3 +1946,4 @@
    !!======================================================================
 #endif
+#endif
 END MODULE step_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_tam_cpd.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_tam_cpd.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/step_tam_cpd.F90	(revision 2587)
@@ -0,0 +1,453 @@
+MODULE step_tam_cpd
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE step_tam  ***
+   !! Time-stepping    : manager of the adjoint ocean time stepping
+   !!                    Tangent and Adjoint module
+   !!======================================================================
+   !! History of 
+   !! the direct:      !  91-03  ()  Original code
+   !!                  !  91-11  (G. Madec)
+   !!                  !  92-06  (M. Imbard)  add a first output record
+   !!                  !  96-04  (G. Madec)  introduction of dynspg
+   !!                  !  96-04  (M.A. Foujols)  introduction of passive tracer
+   !!             8.0  !  97-06  (G. Madec)  new architecture of call
+   !!             8.2  !  97-06  (G. Madec, M. Imbard, G. Roullet)  free surface
+   !!             8.2  !  99-02  (G. Madec, N. Grima)  hpg implicit
+   !!             8.2  !  00-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
+   !!             9.0  !  02-06  (G. Madec)  free form, suppress macro-tasking
+   !!             " "  !  04-08  (C. Talandier) New trends organization
+   !!             " "  !  05-01  (C. Ethe) Add the KPP closure scheme
+   !!             " "  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!             " "  !  05-11  (G. Madec)  Reorganisation of tra and dyn calls
+   !!             " "  !  06-01  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             " "  !  06-07  (S. Masson)  restart using iom
+   !!    "        " "  !  07-04  (K. Mogensen, A. Weaver, M. Martin) Assimilation interface
+   !! History of the TAM
+   !!                  !  08-06  (A. Vidard and A. Weaver) Tangent and Adjoint version of 9.0
+   !!                  !  08-11  (A. Vidard) Nemo v3 update
+   !!                  !  06-09  (F. Vigilant)  Modified to split NEMOVAR / NEMOTAM
+   !!----------------------------------------------------------------------
+   !!   stp_tam        : OPA system time-stepping (tangent linear)
+   !!   stp_adj        : OPA system time-stepping (adjoint)
+   !!----------------------------------------------------------------------
+
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpiglo
+   USE oce           , ONLY: & ! ocean dynamics and tracers variables
+      & tb, sb, tn, sn, ta,  &
+      & un, vn, sshn, sshb,  &
+      & sa, ub, vb,          &
+      & ln_dynhpg_imp
+   USE zdfkpp        , ONLY: &
+      & lk_zdfkpp      ! KPP vertical mixing flag
+   USE dynspg_oce    , ONLY: &
+      &  lk_dynspg_rl  ! Rigid-lid flag
+   USE dom_oce       , ONLY: & ! ocean space and time domain variables 
+      & n_cla, e1u, e2u,     &
+      & e1v, e2v, e1t, e2t,  &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0, e3w_0,        &
+#  else
+      & e3t, e3u, e3v, e3w,  &
+#  endif
+# endif
+      & nldi, nldj, nlei,    &
+      & nlej, lk_vvl, ln_zps,&
+      & narea, mig, mjg,     &
+      & umask, vmask,  tmask
+   USE in_out_manager, ONLY: & ! I/O manager
+      & numout, lwp,         &
+      & nit000, nitend,      &
+      & nstop, ctl_stop
+   USE daymod        , ONLY: &
+      & adatrj
+
+   USE trabbc        , ONLY: &! bottom boundary condition
+      & lk_trabbc
+   USE traqsr        , ONLY: &
+      &  ln_traqsr
+          ! solar radiation penetration flag
+   USE oce_tam       , ONLY: & ! Tangent linear and adjoint variables
+      & oce_tam_init,        &
+      & un_tl, vn_tl, tn_tl, &
+      & sn_tl, ua_tl, va_tl, &
+      & ta_tl, sa_tl, ub_tl, &
+      & vb_tl, tb_tl, sb_tl, & 
+      & un_ad, vn_ad, tn_ad, &
+      & sn_ad, ua_ad, va_ad, &
+      & ta_ad, sa_ad, ub_ad, &
+      & vb_ad, tb_ad, sb_ad, & 
+      & sshn_tl, sshn_ad,    &
+      & rn2_tl, rn2_ad,      &
+      & rhd_tl, rhop_tl,     &
+      & rhd_ad, rhop_ad,     &
+      & gtu_tl, gsu_tl,      &
+      & gru_tl, gtv_tl,      &
+      & gsv_tl, grv_tl,      &
+      & gtu_ad, gsu_ad,      &
+      & gru_ad, gtv_ad,      &
+      & gsv_ad, grv_ad,      &
+      & ssha_tl, sshb_tl
+   USE lbclnk_tam
+   USE daymod_tam      ! calendar                         (adjoint of day     routine)
+   USE sbc_oce_tam
+   USE sbcmod_tam
+   USE traqsr_tam      ! solar radiation penetration      (adjoint of tra_qsr routine)
+   USE trasbc_tam      ! surface boundary condition       (adjoint of tra_sbc routine)
+   USE trabbc_tam      ! bottom boundary condition        (adjoint of tra_bbc routine)
+   USE tradmp_tam      ! internal damping                 (adjoint of tra_dmp routine)
+   USE traadv_tam      ! advection scheme control     (adjoint of tra_adv_ctl routine)
+   USE traldf_tam      ! lateral mixing                   (adjoint of tra_ldf routine)
+   USE cla_tam         ! cross land advection             (adjoint of tra_cla routine)
+   !   zdfkpp          ! KPP non-local tracer fluxes      (adjoint of tra_kpp routine)
+   USE trazdf_tam      ! vertical mixing                  (adjoint of tra_zdf routine)
+   USE tranxt_tam      ! time-stepping                    (adjoint of tra_nxt routine)
+   USE eosbn2_tam      ! equation of state                (adjoint of eos_bn2 routine)
+
+   USE dynadv_tam      ! advection                        (adjoint of dyn_adv routine)
+   USE dynvor_tam      ! vorticity term                   (adjoint of dyn_vor routine)
+   USE dynhpg_tam      ! hydrostatic pressure grad.       (adjoint of dyn_hpg routine)
+   USE dynldf_tam      ! lateral momentum diffusion       (adjoint of dyn_ldf routine)
+   USE dynzdf_tam      ! vertical diffusion               (adjoint of dyn_zdf routine)
+   USE dynspg_tam      ! surface pressure gradient        (adjoint of dyn_spg routine)
+   USE dynnxt_tam      ! time-stepping                    (adjoint of dyn_nxt routine)
+
+!   USE bdy_par_tam
+!   USE bdydta_tam
+
+   USE divcur_tam      ! hor. divergence and curl      (adjoint of div & cur routines)
+   USE cla_div_tam     ! cross land: hor. divergence      (adjoint of div_cla routine)
+   USE wzvmod_tam      ! vertical velocity                (adjoint of wzv     routine)
+
+   USE zdfkpp_tam     ! KPP vertical mixing
+
+   USE zpshde_tam      ! partial step: hor. derivative     (adjoint of zps_hde routine)
+
+!!   USE diaobs_tam      ! obs-minus-model (adjoint of assimilation)   (adjoint of dia_obs routine)
+
+   USE trj_tam
+
+   USE stpctl_tam      ! time stepping control            (adjoint of stp_ctl routine)
+
+   USE gridrandom, ONLY: & 
+                       ! Random Gaussian noise on grids
+      & grid_random, &
+      & grid_rd_sd
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam, ONLY: &
+      & prntst_adj,      & 
+      & prntst_tlm,      &
+      & stdemp,          & 
+      & stdu,stdv,       &
+      & stdt,            &   
+      & stds, stdssh,    &
+      & stdr
+
+   USE paresp, ONLY:     & 
+                       ! Weights for an energy-type scalar product
+      & wesp_t,          & 
+      & wesp_s,          & 
+      & wesp_u,          & 
+      & wesp_ssh           
+
+   USE istate_tam      !: Initial state setting          (istate_init routine)
+   USE sol_oce_tam
+   USE trc_oce_tam
+
+   USE step
+
+#if defined key_agrif
+#error 'agrif not yet implemented in nemotam'
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC stp_tan_cpd
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+
+CONTAINS
+#if defined key_agrif
+   #error 'agrif not yet implemented in nemotam'
+  ! SUBROUTINE stp_tan( )
+#else
+   SUBROUTINE stp_tan_cpd( kstp )
+#endif
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp_tan  ***
+      !!                      
+      !! ** Purpose of the direct routine: 
+      !!              - Time stepping of OPA (momentum and active tracer eqs.)
+      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
+      !!              - Tme stepping  of TRC (passive tracer eqs.)
+      !! 
+      !! ** Method of the direct routine:
+      !!              -1- Update forcings and data  
+      !!              -2- Update ocean physics 
+      !!              -3- Compute the t and s trends 
+      !!              -4- Update t and s 
+      !!              -5- Compute the momentum trends
+      !!              -6- Update the horizontal velocity
+      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
+      !!              -8- Outputs and diagnostics
+      !!----------------------------------------------------------------------
+      !! * Arguments
+#if defined key_agrif   
+      INTEGER               :: kstp   ! ocean time-step index
+#else
+      INTEGER, INTENT( in ) :: kstp   ! ocean time-step index
+#endif      
+
+      !! * local declarations
+      INTEGER ::   indic    ! error indicator if < 0
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zta_tmp, zsa_tmp
+      !! ---------------------------------------------------------------------
+
+
+#if defined key_agrif
+      kstp = nit000 + Agrif_Nb_Step()
+      !      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
+      !      IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp
+#endif   
+      indic = 1                    ! reset to no error condition
+
+      CALL day_tam( kstp, 0 )             ! Calendar
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update data, open boundaries, surface boundary condition (including sea-ice)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! update 3D temperature data ... not needed in tangent
+
+      ! update 3D salinity data ... not needed in tangent (to be investigated, see sbc_ssr)
+
+      CALL sbc_tan ( kstp ) ! Sea boundary condition (including sea-ice) 
+
+      ! update dynamic and tracer data at open boundaries ... not needed for the time being, to investigate whenever we do obc.
+
+      ! compute phase velocities at open boundaries ... not needed for the time being, to investigate whenever we do obc.
+!      IF( lk_bdy     )   CALL bdy_dta_tan( kstp )         ! update dynamic and tracer data at unstructured open boundary
+
+      ! Output the initial state and forcings ... not needed in tangent
+
+      ! saving direct variables ua,va, ta, sa before entering in tracer
+      zta_tmp (:,:,:) = ta (:,:,:)
+      zsa_tmp (:,:,:) = sa (:,:,:)
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !-----------------------------------------------------------------------
+      !  VERTICAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      CALL bn2_tan( tb, sb, tb_tl, sb_tl, rn2_tl )              ! before Brunt-Vaisala frequency
+
+      !                                                     ! Vertical eddy viscosity and diffusivity coefficients
+      ! Richardson number dependent Kz  ... not available
+      ! TKE closure scheme for Kz ... not available
+      ! KPP closure scheme for Kz ... not available
+
+      ! Constant Kz (reset avt, avm[uv] to the background value)... not available
+
+      ! lk_zdfcst_tan:  Constant Kz read from the reference trajectory
+
+
+      ! ! increase diffusivity at rivers mouths... not needed in tangent 
+
+      ! enhanced vertical eddy diffusivity ... not needed in tangent with lk_zdfcst_tan
+
+      ! double diffusive mixing ... not needed in tangent with lk_zdfcst_tan
+
+      ! bottom friction... not needed in tangent with lk_zdfcst_tan
+
+      ! mixed layer depth... not needed in tangent with lk_zdfcst_tan
+
+
+      !-----------------------------------------------------------------------
+      !  LATERAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      ! before slope of the lateral mixing... not needed in tangent with lk_zdfcst_tan
+
+#if defined key_traldf_c2d
+      ! eddy induced velocity coefficient... not needed in tangent with lk_zdfcst_tan
+#endif
+
+
+#if defined key_top
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Passive Tracer Model
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      ! time-stepping... not needed in tangent for the time being
+
+#endif
+
+      ta (:,:,:) = zta_tmp (:,:,:)
+      sa (:,:,:) = zsa_tmp (:,:,:)
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      ta_tl(:,:,:) = 0.e0            ! set tracer trends to zero
+      sa_tl(:,:,:) = 0.e0
+
+      ! apply tracer assimilation increment ... not needed in tangent
+      ! apply bias directly to tn, sn, tb, sb ... not needed in tangent
+      CALL tra_sbc_tan( kstp )       ! surface boundary condition
+
+      IF( ln_traqsr      )   CALL tra_qsr_tan( kstp )       ! penetrative solar radiation qsr
+
+      IF( lk_trabbc      )   CALL tra_bbc_tan( kstp )       ! bottom heat flux
+
+      ! diffusive bottom boundary layer scheme ... currently not available
+      ! advective (and/or diffusive) bottom boundary layer scheme ... currently not available
+
+      IF( lk_tradmp      )   CALL tra_dmp_tan( kstp )       ! internal damping trends
+
+
+!      CALL tra_adv_tan( kstp )       ! horizontal & vertical advection
+
+!      IF( n_cla == 1     )   CALL tra_cla_tan( kstp )       ! Cross Land Advection (Update Hor. advection)
+
+!!      IF( lk_zdfkpp )        CALL tra_kpp_tan( kstp )       ! KPP non-local tracer fluxes
+
+!      CALL tra_ldf_tan( kstp )       ! lateral mixing
+
+#if defined key_agrif
+      ! tracers sponge ... not available
+#endif
+      CALL tra_zdf_tan( kstp )       ! vertical mixing
+
+
+      ! update the new (t,s) fields by non
+      ! penetrative convective adjustment ... not available 
+
+!      CALL tra_nxt_tan( kstp )           ! tracer fields at next time step
+
+
+      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg
+         CALL eos_tan( ta, sa, ta_tl, sa_tl, rhd_tl, rhop_tl )      ! Time-filtered in situ density used in dynhpg module
+         IF( ln_zps    )       CALL zps_hde_tan( kstp, ta, sa, ta_tl, sa_tl, rhd_tl,&   ! Partial steps: time filtered hor. gradient
+            &                                     gtu_tl, gsu_tl, gru_tl,   &   ! of t, s, rd at the bottom ocean level
+            &                                     gtv_tl, gsv_tl, grv_tl )
+      ELSE                                                  ! centered hpg (default case)
+         CALL eos_tan( tb, sb, tb_tl, sb_tl, rhd_tl, rhop_tl )       ! now (swap=before) in situ density for dynhpg module
+         IF( ln_zps    )       CALL zps_hde_tan( kstp, tb, sb, tb_tl, sb_tl, rhd_tl,&   ! Partial steps: now horizontal gradient
+            &                                     gtu_tl, gsu_tl, gru_tl,   &   ! of t, s, rd at the bottom ocean level
+            &                                     gtv_tl, gsv_tl, grv_tl )
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ta, sa arrays are used as workspace in this section 
+      !-----------------------------------------------------------------------
+
+      ua_tl(:,:,:) = 0.e0               ! set dynamics trends to zero
+      va_tl(:,:,:) = 0.e0
+
+      ! apply dynamics assimilation increment ... not needed in tangent
+
+      CALL dyn_adv_tan( kstp )           ! advection (vector or flux form)
+      CALL dyn_vor_tan( kstp )           ! vorticity term including Coriolis
+      CALL dyn_ldf_tan( kstp )           ! lateral mixing
+#if defined key_agrif
+      ! momemtum sponge ... not available
+#endif
+
+      CALL dyn_hpg_tan( kstp )           ! horizontal gradient of Hydrostatic pressure
+
+      CALL dyn_zdf_tan( kstp )           ! vertical diffusion
+
+!PRINT*,'dynspg'
+      IF( lk_dynspg_rl ) THEN
+         ! surface pressure gradient at open boundaries ... not available
+      ENDIF
+      indic=0
+      !i
+      CALL dyn_spg_tan( kstp, indic )    ! surface pressure gradient
+
+      CALL dyn_nxt_tan( kstp )           ! lateral velocity at next time step
+
+      ! vertical mesh at next time step ... not available
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Computation of diagnostic variables
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+      CALL div_cur_tan( kstp )                 ! Horizontal divergence & Relative vorticity
+      IF( n_cla == 1 ) CALL div_cla_tan( kstp )                 ! Cross Land Advection (Update Hor. divergence)
+      CALL wzv_tan( kstp )                     ! Vertical velocity
+
+      CALL trj_rea( kstp, 1) ! ... Read basic state trajectory at end of current step
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control, and restarts
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+      !                                                     ! Time loop: control and print
+      CALL stp_ctl_tan( kstp, indic, 0 )
+      IF( indic < 0          )   CALL ctl_stop( 'step_tan: indic < 0' )
+
+      ! close input  ocean restart file ... not needed in tangent
+      ! write output ocean restart file... not needed in tangent
+      ! write open boundary restart file... not needed in tangent
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      IF ( nstop == 0 ) THEN                                ! Diagnostics
+         ! drifting Floats... not needed in tangent
+         ! trends: dynamics ... not needed in tangent
+         ! trends: active tracers... not needed in tangent
+         ! trends: Mixed-layer ... not needed in tangent
+         ! trends: vorticity budget... not needed in tangent
+         ! Surface pressure diagnostics... not needed in tangent
+         ! Thermocline depth (20 degres isotherm depth)... not needed in tangent
+         ! basin averaged diagnostics... not needed in tangent
+         ! dynamical heigh diagnostics... not needed in tangent
+         ! Fresh water budget diagnostics... not needed in tangent
+!!!         IF( lk_diaobs  )   CALL dia_obs_tan( kstp )                 ! obs-minus-model (assimilation) diagnostics NOTE: may be better off outside this module
+         ! Poleward TRansports diagnostics... not needed in tangent
+
+
+         !                                                 ! Outputs
+         ! ocean model: outputs... not needed in tangent
+
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Coupled mode
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! coupled mode : field exchanges ... not available for the next 20 years
+      !
+   END SUBROUTINE stp_tan_cpd
+
+#endif
+END MODULE step_tam_cpd
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/stpctl_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/stpctl_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/stpctl_tam.F90	(revision 2587)
@@ -161,6 +161,5 @@
          IF(lwp) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
       ENDIF
-!      IF( zumax > 100.) THEN
-      IF( zumax > 500.) THEN
+      IF( zumax > 50.) THEN
          IF( lk_mpp ) THEN
             CALL mpp_maxloc(ABS(un_tl),umask,zumax,ii,ij,ik)
@@ -173,5 +172,5 @@
          IF(lwp) THEN
             WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl_tan: the zonal velocity is larger than 20 m/s'
+            WRITE(numout,*) ' stpctl_tan: the zonal velocity is larger than 50 m/s'
             WRITE(numout,*) ' ========= '
             WRITE(numout,9400) kt, zumax, ii, ij, ik
@@ -197,6 +196,5 @@
          IF(lwp) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(V) max: ', zvmax
       ENDIF
-!      IF( zvmax > 100.) THEN
-      IF( zvmax > 500.) THEN
+      IF( zvmax > 50.) THEN
          IF( lk_mpp ) THEN
             CALL mpp_maxloc(ABS(vn_tl),vmask,zvmax,ii,ij,ik)
@@ -209,5 +207,5 @@
          IF(lwp) THEN
             WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl_tan: the meridional  velocity is larger than 10 m/s'
+            WRITE(numout,*) ' stpctl_tan: the meridional  velocity is larger than 50 m/s'
             WRITE(numout,*) ' ========= '
             WRITE(numout,9410) kt, zvmax, ii, ij, ik
@@ -232,6 +230,5 @@
          IF(lwp) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(T) max: ', zTmax
       ENDIF
-!      IF( ztmax > 300.) THEN
-      IF( ztmax > 600.) THEN
+      IF( ztmax > 80.) THEN
          IF( lk_mpp ) THEN
             CALL mpp_maxloc(ABS(tn_tl),tmask,ztmax,ii,ij,ik)
@@ -244,5 +241,5 @@
          IF(lwp) THEN
             WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl_tan: the temperature is larger than 30 K'
+            WRITE(numout,*) ' stpctl_tan: the temperature is larger than 80 K'
             WRITE(numout,*) ' ========= '
             WRITE(numout,9420) kt, ztmax, ii, ij, ik
@@ -268,6 +265,5 @@
          IF(lwp) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(S) max: ', zsmax
       ENDIF
-!      IF( zsmax > 200.) THEN
-      IF( zsmax > 600.) THEN
+      IF( zsmax > 100.) THEN
          IF( lk_mpp ) THEN
             CALL mpp_maxloc(ABS(sn_tl),tmask,zsmax,ii,ij,ik)
@@ -280,5 +276,5 @@
          IF(lwp) THEN
             WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl_tan: the Salinity is larger than 20 o/oo'
+            WRITE(numout,*) ' stpctl_tan: the Salinity is larger than 100 o/oo'
             WRITE(numout,*) ' ========== '
             WRITE(numout,9430) kt, zsmax, ii, ij, ik
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tamctl.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tamctl.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tamctl.F90	(revision 2587)
@@ -33,13 +33,10 @@
 
    LOGICAL :: &
-      & ln_tst,         & ! Master switch for operator tests
-      & ln_tst_obsadj,  & ! Switch for observation operator adjoint test
-      & ln_tst_bkgadj,  & ! Switch for bkg error covariance operator adjoint test
       & ln_tst_nemotam, & ! Switch for NEMOTAM adjoint tests
-      & ln_tst_grad,    & ! Switch for gradient test
       & ln_tst_cpd_tam, & ! Switch for NEMOTAM adjoint tests (components only)
       & ln_tst_stp_tam, & ! Switch for STEP_TAM adjoint tests
       & ln_tst_tan_cpd, & ! Switch for NEMOTAM tangent components accuracy tests 
-      & ln_tst_tan        ! Switch for NEMOTAM tangent accuracy tests
+      & ln_tst_tan,     & ! Switch for NEMOTAM tangent accuracy tests
+      & ln_tst_stop       ! Stop after tests or not
 
 
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tamtst.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tamtst.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tamtst.F90	(revision 2587)
@@ -54,4 +54,6 @@
 #endif
 
+   USE step_tam_cpd        ! Temporary
+
    IMPLICIT NONE
 
@@ -60,5 +62,5 @@
 
    PUBLIC &
-      & tstopt, &          !: Scalar product test of the adjoint routines
+      & tsttam, &          !: Scalar product test of the adjoint routines
       & numadt             !: File unit number for adjoint test output
 
@@ -69,11 +71,11 @@
 CONTAINS
 
-   SUBROUTINE tstopt
+   SUBROUTINE tsttam
       !!-----------------------------------------------------------------------
       !!
-      !!                  ***  ROUTINE tstopt  ***
+      !!                  ***  ROUTINE tsttam  ***
       !!
-      !! ** Purpose : Apply various tests (linearization, adjoint, gradient)
-      !!              on the NEMOVAR code.
+      !! ** Purpose : Apply various tests (linearization, adjoint)
+      !!              on the NEMOTAM code.
       !!
       !! ** Method  : 
@@ -85,5 +87,5 @@
       !!        ! 07-11 (A. Weaver) Add adjoint tests
       !!        ! 09-03 (I. Mirouze) Filter call depends on type
-      !!        ! 09-08 (F. Vigilant) Add tangent tests
+      !!        ! 09-08 (F. Vigilant) Split TAM and Var and add tangent tests
       !!-----------------------------------------------------------------------
       !! * Modules used
@@ -133,30 +135,12 @@
       CALL par_esp
 
-      ! ---------------------------------------------------------------
-      ! 1) Test the adjoint of the components of B
-      ! ---------------------------------------------------------------
-
-      ! Moved to NEMOVAR
-
-      ! -----------------------------------------------------
-      ! 2) Test the adjoint of H
-      ! -----------------------------------------------------
-
-      ! Moved to NEMOVAR
-
 #if defined key_tam
-      ! -----------------------------------------------------
-      ! 3) Test the adjoint of the simplification operator
-      ! -----------------------------------------------------
-
-      ! Not yet implemented
-
-      ! -----------------------------------------------------
-      ! 4) Test the adjoint of the components of M (NEMOTAM)
-      ! -----------------------------------------------------
 
       IF ( ln_tst_nemotam ) THEN
 
          IF ( ln_tst_cpd_tam ) THEN
+            ! -----------------------------------------------------
+            ! 1) Test the adjoint of the components of M (NEMOTAM)
+            ! -----------------------------------------------------
             ! *** initialize the reference trajectory
             ! ------------
@@ -206,6 +190,5 @@
             IF (lwp) WRITE(numadt,*)
 
-            IF( lk_dynspg_rl ) &
-                & CALL dyn_spg_adj_tst( numadt )    ! Surface pressure gradient
+            CALL dyn_spg_adj_tst( numadt )    ! Surface pressure gradient
 
             IF (lwp) WRITE(numadt,*)
@@ -292,6 +275,7 @@
          ENDIF
 
-         ! *** Time-loop operator
-         ! ----------------------
+         ! -----------------------------------------------------
+         ! 2) Test the adjoint of of M (NEMOTAM)
+         ! -----------------------------------------------------
          IF ( ln_tst_stp_tam ) THEN
 
@@ -303,6 +287,7 @@
 
          ENDIF
-
-         ! *** Tangent accuracy
+#if defined key_tst_tlm
+         ! -----------------------------------------------------
+         ! 3)  Test the Tangent accuracy
          ! ----------------------
          IF ( ln_tst_tan ) THEN     
@@ -310,46 +295,26 @@
             IF (ln_tst_tan_cpd) THEN
 
-               CALL flush(numout)
-
                CALL dyn_hpg_tlm_tst( numadt )
 
-               CALL flush(numout)
-
-               IF( lk_dynspg_rl ) &
-                  & CALL dyn_spg_tlm_tst( numadt )
-
-               CALL flush(numout)
+               CALL dyn_spg_tlm_tst( numadt )
+
+               CALL sol_sor_tlm_tst( numadt )
 
                CALL zps_hde_tlm_tst( numadt )
 
-               CALL flush(numout)
-
                CALL tra_sbc_tlm_tst( numadt )
 
-               CALL flush(numout)
-
                CALL dyn_adv_tlm_tst( numadt )
 
-               CALL flush(numout)
-
                CALL eos_tlm_tst( numadt )
 
-               CALL flush(numout)
-
                CALL bn2_tlm_tst( numadt )
 
-               CALL flush(numout)
-
                CALL tra_zdf_tlm_tst( numadt )
 
-               CALL flush(numout)
-
                CALL tra_adv_tlm_tst( numadt )       
 
-               CALL flush(numout)
-            
                CALL tra_ldf_tlm_tst( numadt ) 
        
-               CALL flush(numout)
             ELSE
 
@@ -363,5 +328,5 @@
 
          ENDIF
-
+#endif
       ENDIF
 #endif
@@ -372,10 +337,10 @@
       IF (lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) ' tstopt: Finished testing operators'
+         WRITE(numout,*) ' tsttam: Finished testing operators'
          WRITE(numout,*) ' ------'
          WRITE(numout,*)
       ENDIF
       CALL flush(numout)
-   END SUBROUTINE tstopt
+   END SUBROUTINE tsttam
 
 END MODULE tamtst
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tanhlt.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tanhlt.F90	(revision 2587)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/tanhlt.F90	(revision 2587)
@@ -0,0 +1,330 @@
+MODULE tanhlt
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE tan_htl   ***
+   !! Ocean system   : TAN ocean dynamics (including on-line tracers and sea-ice)
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   tan_hlt            : solve ocean dynamics, tracer and/or sea-ice
+   !!   tan_htl_init       : initialization of the opa model 
+   !!   tan_hlt_closefile  : close remaining files
+   !!----------------------------------------------------------------------
+   !! History :
+   !!                  ()  Original code from opa
+   !!        !  10-07  (F. Vigilant) Modification for tangent linear hyp
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space domain variables
+   USE lib_mpp         ! distributed memory computing
+   USE daymod          ! Date computations
+   USE in_out_manager  ! I/O manager
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+   USE obc_par
+   USE obcini
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE tamtrj          ! handling of the trajectory
+   USE trj_tam         ! handling of the trajectory
+   USE tamctl          ! Control parameters
+   USE oce_tam         ! TL and adjoint data
+   USE sbc_oce_tam     ! Surface BCs tangent and adjoint arrays
+   USE trc_oce_tam     ! Trend tangent and adjoint arrays
+   USE sol_oce_tam     ! Solver tangent and adjoint arrays
+   USE tamtst          ! Gradient testing
+   ! ocean physics
+#if defined key_tam
+   USE ldfdyn        ! lateral viscosity setting  (ldfdyn_init routine)
+   USE ldftra        ! lateral diffusivity setting (ldftra_init routine)
+#endif
+   USE zdfini
+   USE step_tam
+   USE istate_tam      !: Initial state setting          (istate_init routine)
+   USE par_tlm
+
+   USE hltinc, ONLY : &
+     & hlt_inc_bld
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   CHARACTER (len=64) ::        &
+      cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+   !! * Routine accessibility
+   PUBLIC tan_hlt        ! called by hlttst.F90
+
+CONTAINS
+
+   SUBROUTINE tan_hlt
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE tan_hlt  ***
+      !!
+      !! ** Purpose :   tan_hlt  
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp_tan routine)
+      !!
+      !! References :
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp       ! time step index
+      !!----------------------------------------------------------------------
+
+#if defined key_agrif
+      CALL ctl_stop( '       Agrif not available')
+#endif
+      
+      CALL tan_hlt_init  ! Initializations
+
+      ! check that all process are still there... If some process have an error,
+      ! they will never enter in step and other processes will wait until the end of the cpu time!
+      IF( lk_mpp )   CALL mpp_max( nstop )
+
+      istp = nit000
+!      IF( lk_c1d ) THEN                 ! 1D configuration (no AGRIF zoom)
+!         CALL ctl_stop( '       lk_c1d not available')
+!      ELSE
+
+         istp = nit000 - 1     
+         CALL  trj_rea( istp, 1 )           
+         CALL hlt_inc_bld( nstg )      ! increment builder
+         istp = nit000
+
+         CALL istate_init_tan
+         IF( ln_trjwri_tan ) CALL tl_trj_wri( istp )
+
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_agrif
+            CALL ctl_stop( '       Agrif not available')
+#else
+            CALL stp_tan( istp )
+#endif
+            istp = istp + 1
+            IF( ln_trjwri_tan ) CALL tl_trj_wri( istp )
+            IF( lk_mpp )   CALL mpp_max( nstop )
+         END DO
+
+!      ENDIF
+
+      !                                     ! ========= !
+      !                                     !  Job end  !
+      !                                     ! ========= !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
+         WRITE(numout,cform_err)
+         WRITE(numout,*) nstop, ' error have been found' 
+      ENDIF
+
+      CALL tan_hlt_final
+
+      IF( lk_mpp )   CALL mppstop                          ! Close all files (mpp)
+      !
+   END SUBROUTINE tan_hlt
+
+   SUBROUTINE tan_hlt_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE tan_hlt_init  ***
+      !!
+      !! ** Purpose :   initialization of the tan model
+      !!
+      !!----------------------------------------------------------------------
+#if defined key_coupled
+      INTEGER ::   itro, istp0        ! ???
+#endif
+#if defined key_oasis3 || defined key_oasis4
+      INTEGER :: localComm
+#endif
+      !! * Local declarations
+      CHARACTER (len=128) :: file_out = 'nemohlt.output'
+!      CHARACTER (len=*), PARAMETER   ::  namelistname = 'namelist.hlt' 
+      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
+         &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
+      NAMELIST/namtst/ ln_tst_nemotam, ln_tst_cpd_tam, ln_tst_stp_tam, &
+         &             ln_tst_tan_cpd, ln_tst_tan, ln_tst_stop
+      !!----------------------------------------------------------------------
+
+      ! Initializations
+      ! ===============
+
+      ! Namelist namctl : Control prints & Benchmark
+      REWIND( numnam )
+      READ  ( numnam, namctl )
+
+      ! open additionnal listing
+      IF( ln_ctl )   THEN
+         IF( narea-1 > 0 )   THEN
+            WRITE(file_out,FMT="('nemohlt.output_',I4.4)") narea-1
+            CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+            lwp = .TRUE.
+            !
+            WRITE(numout,*)
+            WRITE(numout,*) '                 L O D Y C - I P S L'
+            WRITE(numout,*) '                     O P A model'
+            WRITE(numout,*) '            Ocean General Circulation Model'
+            WRITE(numout,*) '               version OPA 9.0  (2005) '
+            WRITE(numout,*) '                   MPI Ocean output '
+            WRITE(numout,*)
+            WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '              LINEAR-TANGENT HYPOTHESIS TEST-RUN '
+         WRITE(numout,*) '              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) '       Namelist namhlt'
+         WRITE(numout,*) '             run stage                        nstg       = ', nstg
+         IF( nstg == 1 ) THEN
+            WRITE(numout,*) '             temperature increment switch     ln_hltt    = ', ln_hltt
+            WRITE(numout,*) '             salinity increment switch        ln_hlts    = ', ln_hlts
+            WRITE(numout,*) '             velocity incr. switch            ln_hltuv   = ', ln_hltuv
+            WRITE(numout,*) '             sea surface height incr. switch  ln_hltssh  = ', ln_hltssh
+         ENDIF
+         WRITE(numout,*)
+         WRITE(numout,*)
+      ENDIF
+
+!      CALL ctlopn( numnam, namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+!         &           1, numout, .FALSE., 1 )
+
+      ! Namelist namctl : Control prints & Benchmark
+      REWIND( numnam )
+      READ  ( numnam, namctl )
+
+      ! Nodes selection
+      nproc = mynode()
+      narea = nproc + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+      ln_rstart = .FALSE.
+
+      ! open additionnal listing
+      IF( narea-1 > 0 )   THEN
+         WRITE(file_out,FMT="('nemohlt.output_',I4.4)") narea-1
+         IF( numout /= 0 .AND. numout /= 6 ) THEN 
+            CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+         ENDIF
+         lwp = .TRUE.
+         !
+      ENDIF      
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'nemotam_init: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+         WRITE(numout,*) '          Namelist namctl'
+         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '             level of print                  nprint    = ', nprint
+         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
+      ENDIF
+
+      ln_tst_nemotam = .FALSE.
+      ln_tst_cpd_tam = .FALSE.
+      ln_tst_stp_tam = .FALSE.
+      ln_tst_tan_cpd = .FALSE.
+      ln_tst_tan     = .FALSE.
+      ln_tst_stop    = .FALSE.
+
+      REWIND( numnam )
+      READ  ( numnam, namtst )
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' namtst'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' switch for M adjoint tests   ln_tst_nemotam = ',ln_tst_nemotam
+         WRITE(numout,*) ' stop after tests                ln_tst_stop = ',ln_tst_stop
+         WRITE(numout,*) ' '
+      ENDIF
+
+      IF( jpni*jpnj == jpnij ) THEN
+         CALL mpp_init                      ! standard cutting out
+      ELSE
+         CALL mpp_init2                     ! eliminate land processors
+      ENDIF
+      
+      CALL phy_cst                          ! Physical constants
+
+      CALL dom_cfg                          ! Domain configuration
+      
+      CALL dom_init                         ! Domain
+      
+      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
+
+      !                                     ! Ocean physics
+
+#if defined key_tam
+      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+#endif
+
+      CALL zdf_init                             ! Vertical ocean physics
+
+      CALL     oce_tam_init( 0 )            ! OCE TAM field
+      CALL sol_oce_tam_init( 0 )            ! Initialize elliptic solver
+      CALL trc_oce_tam_init( 0 )            ! TRC TAM fields
+#if defined key_tam
+      CALL sbc_oce_tam_init( 0 )            ! SBC TAM fields
+#endif
+      CALL tam_trj_ini
+      CALL tl_trj_ini
+
+      CALL day_init
+      CALL day( nit000 )
+
+   END SUBROUTINE tan_hlt_init
+
+   SUBROUTINE tan_hlt_final
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  05-01  (O. Le Galloudec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      IF( nstop /= 0 ) THEN                 ! error print
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) nstop, ' error have been found' 
+      ENDIF
+
+      IF ( lk_mpp ) CALL mppsync
+
+      ! Deallocate variables
+      ! --------------------
+      CALL oce_tam_deallocate ( 0 )
+      CALL sol_oce_tam_deallocate ( 0 )
+#if defined key_tam
+      CALL sbc_oce_tam_deallocate ( 0 )
+      CALL trc_oce_tam_deallocate ( 0 )
+#endif
+      CALL trj_deallocate
+      ! Unit close
+      ! ----------
+
+      CLOSE( numnam )       ! namelist
+      CLOSE( numout )       ! standard model output file
+!      CLOSE( numtan_sc )    ! tangent test diagnostic output
+!      CLOSE( numtan )       ! tangent diagnostic output
+
+      IF ( lk_mpp ) CALL mppstop
+
+   END SUBROUTINE tan_hlt_final
+
+   !!======================================================================
+#endif
+END MODULE tanhlt
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/trc_oce_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/trc_oce_tam.F90	(revision 1947)
+++ branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/trc_oce_tam.F90	(revision 2587)
@@ -37,4 +37,5 @@
    PUBLIC &
       & trc_oce_tam_init, & !: Initialize the trend TAM fields
+      & trc_oce_tam_deallocate, & !: Deallocate the trend TAM fields
       & etot3_tl, &
       & etot3_ad
@@ -103,5 +104,47 @@
 
    END SUBROUTINE trc_oce_tam_init
+   SUBROUTINE trc_oce_tam_deallocate( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE trc_oce_tam_deallocate  ***
+      !!
+      !! ** Purpose : Deallocate the tangent linear and
+      !!              adjoint arrays
+      !!
+      !! ** Method  : kindic = 0  deallocate both tl and ad variables
+      !!              kindic = 1  deallocate only tl variables
+      !!              kindic = 2  deallocate only ad variables
+      !!
+      !! ** Action  :
+      !!
+      !! References :
+      !!
+      !! History :
+      !!        ! 2010-06 (A. Vidard) Initial version
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to deallocate
 
+      !! * Local declarations
+      ! Deallocate tangent linear variable arrays
+      ! ---------------------------------------
+
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( ALLOCATED(etot3_tl) ) DEALLOCATE( etot3_tl )
+
+      END IF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+            
+         ! Deallocate adjoint variable arrays
+         ! --------------------------------
+
+         IF ( ALLOCATED(etot3_ad) ) DEALLOCATE( etot3_ad )
+
+      END IF
+
+   END SUBROUTINE trc_oce_tam_deallocate
 #endif
 END MODULE trc_oce_tam
Index: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/trj_tam.F90
===================================================================
--- branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/trj_tam.F90	(revision 1947)
+++ 	(revision )
@@ -1,712 +1,0 @@
-MODULE trj_tam
-#ifdef key_tam
-   !!======================================================================
-   !!                       ***  MODULE trj_tam ***
-   !! NEMOVAR trajectory: Allocate and read the trajectory for linearzation
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   bkg_init : Initialize the background fields from disk
-   !!----------------------------------------------------------------------
-   !! * Modules used   
-   USE par_kind, ONLY : & ! Precision variables
-      & wp
-   USE par_oce, ONLY : &  ! Ocean space and time domain variables
-      & jpi, jpj, jpk
-   USE tamtrj             ! Parameters for the assmilation interface
-   USE in_out_manager, ONLY : & ! I/O manager
-      & lwp 
-   USE oce                ! Model variables 
-   USE zdf_oce            ! Vertical mixing variables
-   USE zdfddm             ! Double diffusion mixing parameterization
-   USE ldftra_oce         ! Lateral tracer mixing coefficient defined in memory
-   USE ldfslp             ! Slopes of neutral surfaces
-   USE tradmp             ! Tracer damping
-   USE sbc_oce            ! Ocean surface boundary conditions
-   USE iom                ! Library to read input files
-
-   USE zdfmxl, ONLY : &   ! mixed layer depth
-      & hmlp
-   USE divcur             ! horizontal divergence and relative vorticity
-   USE wzvmod             !  vertical velocity
-  
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-   PUBLIC &
-      & trj_rea,     &   !: Read trajectory at time step kstep into now fields
-      & trj_rd_spl,  &   !: Read simple data (without interpolation)
-      & trj_wri_spl      !: Write simple data (without interpolation)
-
-   !! * Module variables
-   INTEGER, SAVE :: inumtrj1 = -1, inumtrj2 = -1
-   REAL(wp), SAVE :: &
-      & stpr1, &
-      & stpr2
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:), SAVE :: &
-      & empr1,    &
-      & empsr1,   &   
-      & empr2,    &
-      & empsr2
-#if defined key_traldf_eiv
-#if defined key_traldf_c3d
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), SAVE :: &
-#elif defined key_traldf_c2d
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:), SAVE :: &
-#elif defined key_traldf_c1d
-   REAL(wp), ALLOCATABLE, DIMENSION(:), SAVE :: &
-#else
-   REAL(wp) ::
-#endif
-      & aeiur1,   &
-      & aeivr1,   &
-      & aeiwr1,   & 
-      & aeiur2,   &
-      & aeivr2,   &
-      & aeiwr2
-#endif
-  REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), SAVE :: &
-      & unr1,     &
-      & vnr1,     &
-      & tnr1,     &
-      & snr1,     &
-      & avmur1,   &
-      & avmvr1,   &
-      & avtr1,    &
-      & uslpr1,   &
-      & vslpr1,   &
-      & wslpir1,  &
-      & wslpjr1,  &
-      & avsr1,    &
-      & tar1,     &
-      & sar1,     &
-      & tbr1,     &
-      & sbr1,     &
-      & unr2,     &
-      & vnr2,     &
-      & tnr2,     &
-      & snr2,     &
-      & avmur2,   &
-      & avmvr2,   &
-      & avtr2,    &
-      & uslpr2,   &
-      & vslpr2,   &
-      & wslpir2,  &
-      & wslpjr2,  &
-      & avsr2,    &
-      & tar2,     &
-      & sar2,     &
-      & tbr2,     &
-      & sbr2
-  REAL(wp), ALLOCATABLE, DIMENSION(:,:), SAVE :: &
-      & hmlp1,    &
-      & hmlp2  
-      
-CONTAINS
-
-   SUBROUTINE trj_rea( kstp, kdir )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                  ***  ROUTINE trj_reat  ***
-      !!
-      !! ** Purpose : Read from file the trjectory from the outer loop
-      !!
-      !! ** Method  : IOM
-      !!
-      !! ** Action  :
-      !!                   
-      !! References : 
-      !!
-      !! History :
-      !!        ! 08-05 (K. Mogensen) Initial version
-      !!        ! 09-03 (F.Vigilant) Add reading of hmlp and calls (divcur, wzvmod)
-      !!-----------------------------------------------------------------------
-      !! * Modules used
-      !! * Arguments
-      INTEGER, INTENT(in) :: &
-         & kstp, &           ! Step for requested trajectory
-         & kdir              ! Direction for stepping (1 forward, -1 backward)
-      !! * Local declarations
-      CHARACTER (LEN=100) :: &
-         & cl_asmtrj
-      INTEGER :: &
-         & inrcm,  &
-         & inrcp,  &
-         & inrc,   &
-         & istpr1, &
-         & istpr2, &
-	 & it
-      REAL(KIND=wp) :: &
-         & zwtr1, &
-         & zwtr2, &
-         & zden,  &
-         & zstp
-
-      ! Initialize data and open file
-      !! if step time is corresponding to a saved state
-      IF ( ( MOD( kstp - nit000 + 1, nittrjfrq ) == 0 )  ) THEN       
-
-         it = kstp - nit000 + 1
-
-         IF ( inumtrj1 == -1 ) THEN
-
-            ! Define the input file 
-            WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', it
-
-            !         WRITE(cl_asmtrj, FMT='(A,".nc")' ) TRIM( c_asmtrj )
-            cl_asmtrj = TRIM( cl_asmtrj )
-
-            IF(lwp) THEN
-
-               WRITE(numout,*)
-               WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
-               WRITE(numout,*)
-
-            ENDIF
-            CALL iom_open( cl_asmtrj, inumtrj1 )     
-            if ( inumtrj1 == -1)  CALL ctl_stop( 'No tam_trajectory cl_amstrj found' )
-   
-            ALLOCATE( &
-               & empr1(jpi,jpj),  &
-               & empsr1(jpi,jpj), &
-               & empr2(jpi,jpj),  &
-               & empsr2(jpi,jpj)  &
-               & )
-
-            ALLOCATE( &
-               & unr1(jpi,jpj,jpk),     &
-               & vnr1(jpi,jpj,jpk),     &
-               & tnr1(jpi,jpj,jpk),     &
-               & snr1(jpi,jpj,jpk),     &
-               & avmur1(jpi,jpj,jpk),   &
-               & avmvr1(jpi,jpj,jpk),   &
-               & avtr1(jpi,jpj,jpk),    &
-               & tar1(jpi,jpj,jpk),     &
-               & sar1(jpi,jpj,jpk),     &
-               & tbr1(jpi,jpj,jpk),     &
-               & sbr1(jpi,jpj,jpk),     &
-               & unr2(jpi,jpj,jpk),     &
-               & vnr2(jpi,jpj,jpk),     &
-               & tnr2(jpi,jpj,jpk),     &
-               & snr2(jpi,jpj,jpk),     &
-               & avmur2(jpi,jpj,jpk),   &
-               & avmvr2(jpi,jpj,jpk),   &
-               & avtr2(jpi,jpj,jpk),    &
-               & tar2(jpi,jpj,jpk),     &
-               & sar2(jpi,jpj,jpk),     &
-               & tbr2(jpi,jpj,jpk),     &
-               & sbr2(jpi,jpj,jpk)      &
-               & )
-
-#if defined key_traldf_eiv
-#if defined key_traldf_c3d
-#elif defined key_traldf_c2d
-            ALLOCATE( &
-               & aeiur1(jpi,jpj), &
-               & aeivr1(jpi,jpj), &
-               & aeiwr1(jpi,jpj), &
-               & aeiur2(jpi,jpj), &
-               & aeivr2(jpi,jpj), &
-               & aeiwr2(jpi,jpj)  &
-               & )
-#elif defined key_traldf_c1d
-#endif
-#endif
-
-#if defined key_ldfslp
-            ALLOCATE( &
-               & uslpr1(jpi,jpj,jpk),   &
-               & vslpr1(jpi,jpj,jpk),   &
-               & wslpir1(jpi,jpj,jpk),  &
-               & wslpjr1(jpi,jpj,jpk),  &
-               & uslpr2(jpi,jpj,jpk),   &
-               & vslpr2(jpi,jpj,jpk),   &
-               & wslpir2(jpi,jpj,jpk),  &
-               & wslpjr2(jpi,jpj,jpk)   &
-               & )
-#endif
-
-#if defined key_zdfddm
-            ALLOCATE( &
-               & avsr1(jpi,jpj,jpk),    &
-               & avsr2(jpi,jpj,jpk)     &
-               & )
-#endif
-
-#if defined key_tradmp
-            ALLOCATE( &
-               & hmlp1(jpi,jpj),    &
-               & hmlp2(jpi,jpj)     &
-               & )
-#endif
-
-         ENDIF
-
-
-      ! Read records
-
-         inrcm = INT( ( kstp - nit000 + 1 ) / nittrjfrq ) + 1
-
-         ! Copy record 1 into record 2
-
-         IF ( ( kstp /= nitend )         .AND. &
-            & ( kstp - nit000 + 1 /= 0 ) .AND. &
-            & ( kdir == -1 ) ) THEN
-
-            stpr2           = stpr1
-
-            empr2   (:,:)   = empr1   (:,:)
-            empsr2  (:,:)   = empsr1  (:,:)
-
-            unr2    (:,:,:) = unr1    (:,:,:)
-            vnr2    (:,:,:) = vnr1    (:,:,:)
-            tnr2    (:,:,:) = tnr1    (:,:,:)
-            snr2    (:,:,:) = snr1    (:,:,:)
-            avmur2  (:,:,:) = avmur1  (:,:,:)
-            avmvr2  (:,:,:) = avmvr1  (:,:,:)
-            avtr2   (:,:,:) = avtr1   (:,:,:)
-#if defined key_ldfslp
-            uslpr2  (:,:,:) = uslpr1  (:,:,:)
-            vslpr2  (:,:,:) = vslpr1  (:,:,:)
-            wslpir2 (:,:,:) = wslpir1 (:,:,:)
-            wslpjr2 (:,:,:) = wslpjr1 (:,:,:)
-#endif
-#if defined key_zdfddm
-            avsr2   (:,:,:) = avsr1   (:,:,:)
-#endif
-            tar2    (:,:,:) = tar1    (:,:,:)
-            sar2    (:,:,:) = sar1    (:,:,:)
-            tbr2    (:,:,:) = tbr1    (:,:,:)
-            sbr2    (:,:,:) = sbr1    (:,:,:)
-#if defined key_tradmp
-            hmlp1   (:,:)   = hmlp2   (:,:)
-#endif
-#if defined key_traldf_eiv  
-#if defined key_traldf_c3d
-            aeiur2  (:,:,:) = aeiur1  (:,:,:)
-            aeivr2  (:,:,:) = aeivr1  (:,:.:)
-            aeiwr2  (:,:,:) = aeiwr1  (:,:.:)
-#elif defined key_traldf_c2d
-            aeiur2  (:,:)   = aeiur1  (:,:)
-            aeivr2  (:,:)   = aeivr1  (:,:)
-            aeiwr2  (:,:)   = aeiwr1  (:,:)
-#elif defined key_traldf_c1d
-            aeiur2  (:)     = aeiur1  (:)
-            aeivr2  (:)     = aeivr1  (:)
-            aeiwr2  (:)     = aeiwr1  (:)
-#else
-            aeiur2          = aeiur1     
-            aeivr2          = aeivr1     
-            aeiwr2          = aeiwr1     
-#endif
-#endif
-
-            istpr1 = INT( stpr1 )
-
-            IF(lwp) WRITE(numout,*) &
-               &                 '    Trajectory record copy time step = ', istpr1
-
-         ENDIF
-! added
-         IF ( ( kstp - nit000 + 1 /= 0 ) .AND. ( kdir == -1 ) ) THEN
-            ! We update the input filename 
-            WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', (it-nittrjfrq)
-            cl_asmtrj = TRIM( cl_asmtrj )
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
-               WRITE(numout,*)
-            ENDIF
-         ENDIF
-! end added
-         ! Read record 1
-
-         IF ( ( kstp - nit000 + 1 == 0 ) .AND.( kdir == 1           ) .OR. &
-            & ( kstp - nit000 + 1 /= 0 ) .AND.( kdir == -1          ) ) THEN
-
-            IF ( kdir == -1 ) inrcm = inrcm - 1
-!added
-!            inrc = inrcm
-            ! temporary fix: currently, only one field by step time
-            inrc = 1
-            stpr1 = (inrcm - 1) * nittrjfrq
-!            stpr1 = (inrc - 1) * nittrjfrq 
-!end added
-
-            ! bug fixed to read several time the initial data
-            IF ( ( kstp - nit000 + 1 == 0 ) .AND. ( kdir == 1 ) ) THEN
-               ! Define the input file 
-               WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', it
-
-               cl_asmtrj = TRIM( cl_asmtrj )
-
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
-                  WRITE(numout,*)
-               ENDIF
-            END IF
-            IF ( inumtrj1 /= -1 )   CALL iom_open( cl_asmtrj, inumtrj1 )
-
-            CALL iom_get( inumtrj1, jpdom_data, 'emp'   , empr1   , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'emps'  , empsr1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'un'    , unr1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'vn'    , vnr1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'tn'    , tnr1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'sn'    , snr1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'avmu'  , avmur1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'avmv'  , avmvr1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'avt'   , avtr1   , inrc )
-#if defined key_ldfslp
-            CALL iom_get( inumtrj1, jpdom_data, 'uslp'  , uslpr1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'vslp'  , vslpr1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'wslpi' , wslpir1 , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'wslpj' , wslpjr1 , inrc )
-#endif
-#if defined key_zdfddm
-            CALL iom_get( inumtrj1, jpdom_data, 'avs'   , avsr1   , inrc )
-#endif
-            CALL iom_get( inumtrj1, jpdom_data, 'ta'    , tar1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'sa'    , sar1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'tb'    , tbr1    , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'sb'    , sbr1    , inrc )
-#if defined key_tradmp
-            CALL iom_get( inumtrj1, jpdom_data, 'hmlp'  , hmlp1   , inrc )
-#endif
-#if defined key_traldf_eiv
-            CALL iom_get( inumtrj1, jpdom_data, 'aeiu'  , aeiur1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'aeiv'  , aeivr1  , inrc )
-            CALL iom_get( inumtrj1, jpdom_data, 'aeiw'  , aeiwr1  , inrc )
-#endif
-            CALL iom_close( inumtrj1 )
-
-            istpr1 = INT( stpr1 )
-            IF(lwp)WRITE(numout,*) '   trajectory read time step = ', istpr1,&
-               &                   '  record = ', inrc
-
-         ENDIF
-
-
-         ! Copy record 2 into record 1
-
-         IF ( ( kstp - nit000 + 1 /= 0 ) .AND. &
-            & ( kstp /= nitend         ) .AND. &
-            & ( kdir == 1              ) ) THEN
-
-            stpr1           = stpr2
-            empr1   (:,:)   = empr2   (:,:)
-            empsr1  (:,:)   = empsr2  (:,:)
-            unr1    (:,:,:) = unr2    (:,:,:)
-            vnr1    (:,:,:) = vnr2    (:,:,:)
-            tnr1    (:,:,:) = tnr2    (:,:,:)
-            snr1    (:,:,:) = snr2    (:,:,:)
-            avmur1  (:,:,:) = avmur2  (:,:,:)
-            avmvr1  (:,:,:) = avmvr2  (:,:,:)
-            avtr1   (:,:,:) = avtr2   (:,:,:)
-#if defined key_ldfslp
-            uslpr1  (:,:,:) = uslpr2  (:,:,:)
-            vslpr1  (:,:,:) = vslpr2  (:,:,:)
-            wslpir1 (:,:,:) = wslpir2 (:,:,:)
-            wslpjr1 (:,:,:) = wslpjr2 (:,:,:)
-#endif
-#if defined key_zdfddm
-            avsr1   (:,:,:) = avsr2   (:,:,:)
-#endif
-            tar1    (:,:,:) = tar2    (:,:,:)
-            sar1    (:,:,:) = sar2    (:,:,:)
-            tbr1    (:,:,:) = tbr2    (:,:,:)
-            sbr1    (:,:,:) = sbr2    (:,:,:)
-#if defined key_tradmp
-            hmlp1   (:,:)   = hmlp2   (:,:)
-#endif
-#if defined key_traldf_eiv  
-#if defined key_traldf_c3d
-            aeiur1  (:,:,:) = aeiur2  (:,:,:)
-            aeivr1  (:,:,:) = aeivr2  (:,:.:)
-            aeiwr1  (:,:,:) = aeiwr2  (:,:.:)
-#elif defined key_traldf_c2d
-            aeiur1  (:,:)   = aeiur2  (:,:)
-            aeivr1  (:,:)   = aeivr2  (:,:)
-            aeiwr1  (:,:)   = aeiwr2  (:,:)
-#elif defined key_traldf_c1d
-            aeiur1  (:)     = aeiur2  (:)
-            aeivr1  (:)     = aeivr2  (:)
-            aeiwr1  (:)     = aeiwr2  (:)
-#else
-            aeiur1          = aeiur2     
-            aeivr1          = aeivr2     
-            aeiwr1          = aeiwr2     
-#endif
-#endif
-
-            istpr1 = INT( stpr1 )
-            IF(lwp) WRITE(numout,*) &
-               &                 '   Trajectory record copy time step = ', istpr1
-
-         ENDIF
-
-         ! Read record 2
-
-!!         IF ( ( kstp /= nitend ) .AND. ( kdir == 1  ) .OR. &
-!!            & ( kstp == nitend ) .AND. ( kdir == -1 ) ) THEN    
-! change
-         IF ( ( ( kstp /= nitend ) .AND. ( kdir == 1  )) .OR. &
-            &   ( kstp == nitend ) .AND.(  kdir == -1   ) ) THEN
-! end change
-!added
-!            ! Need to open next saved file when kstp = initial step   
-!            IF  ( kstp - nit000 + 1 == 0 ) THEN     
-            ! Need to open next saved file when kstp = initial step   
-! change     
-!            IF ( ( kstp /= nitend ) .AND. ( kdir == 1 ) ) THEN 
-! end change
-! end added
-               ! Define the input file 
-               IF  (  kdir == -1   ) THEN
-                   WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', (it)
-               ELSE      
-                  WRITE(cl_asmtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( c_asmtrj ), '_', (it+nittrjfrq)
-               ENDIF
-               cl_asmtrj = TRIM( cl_asmtrj )
-
-               IF(lwp) THEN        
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_asmtrj)
-                  WRITE(numout,*)        
-               ENDIF
-
-               CALL iom_open( cl_asmtrj, inumtrj2 ) 
-! change
-!            END IF
-!end change
-
-            inrcp = inrcm + 1
-            !            inrc  = inrcp
-!added
-            inrc = 1  ! temporary  fix
-!end added
-            stpr2 = (inrcp - 1) * nittrjfrq 
-            CALL iom_get( inumtrj2, jpdom_data, 'emp'   , empr2   , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'emps'  , empsr2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'un'    , unr2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'vn'    , vnr2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'tn'    , tnr2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'sn'    , snr2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'avmu'  , avmur2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'avmv'  , avmvr2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'avt'   , avtr2   , inrc )
-#if defined key_ldfslp
-            CALL iom_get( inumtrj2, jpdom_data, 'uslp'  , uslpr2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'vslp'  , vslpr2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'wslpi' , wslpir2 , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'wslpj' , wslpjr2 , inrc )
-#endif
-#if defined key_zdfddm
-            CALL iom_get( inumtrj2, jpdom_data, 'avs'   , avsr2   , inrc )
-#endif
-            CALL iom_get( inumtrj2, jpdom_data, 'ta'    , tar2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'sa'    , sar2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'tb'    , tbr2    , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'sb'    , sbr2    , inrc )
-#if defined key_tradmp
-            CALL iom_get( inumtrj2, jpdom_data, 'hmlp'  , hmlp2   , inrc )
-#endif
-#if defined key_traldf_eiv
-            CALL iom_get( inumtrj2, jpdom_data, 'aeiu'  , aeiur2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'aeiv'  , aeivr2  , inrc )
-            CALL iom_get( inumtrj2, jpdom_data, 'aeiw'  , aeiwr2  , inrc )
-#endif
-            CALL iom_close( inumtrj2 )
-
-            istpr2 = INT( stpr2 )
-            IF(lwp)WRITE(numout,*) '   trajectory read2 time step = ', istpr2,&
-               &                   '  record = ', inrc
-         ENDIF
-
-      ENDIF
-
-      ! Linear interpolate to the current step
-
-      IF(lwp)WRITE(numout,*) '   linear interpolate to current', &
-         &                   ' time step = ', kstp
-
-      ! Interpolation coefficients
-
-      zstp = kstp - nit000 + 1
-      zden   = 1.0 / ( stpr2 - stpr1 )
-
-      zwtr1  = ( stpr2 - zstp      ) * zden
-      zwtr2  = ( zstp  - stpr1     ) * zden
-
-IF(lwp)WRITE(numout,*) '   linear interpolate coeff.', &
-         &                   '  = ', zwtr1, zwtr2
-
-      emp(:,:)      = zwtr1 * empr1   (:,:)   + zwtr2 * empr2   (:,:)
-      emps(:,:)     = zwtr1 * empsr1  (:,:)   + zwtr2 * empsr2  (:,:)
-      un(:,:,:)     = zwtr1 * unr1    (:,:,:) + zwtr2 * unr2    (:,:,:)
-      vn(:,:,:)     = zwtr1 * vnr1    (:,:,:) + zwtr2 * vnr2    (:,:,:)
-      tn(:,:,:)     = zwtr1 * tnr1    (:,:,:) + zwtr2 * tnr2    (:,:,:)
-      sn(:,:,:)     = zwtr1 * snr1    (:,:,:) + zwtr2 * snr2    (:,:,:)
-      avmu(:,:,:)   = zwtr1 * avmur1  (:,:,:) + zwtr2 * avmur2  (:,:,:)
-      avmv(:,:,:)   = zwtr1 * avmvr1  (:,:,:) + zwtr2 * avmvr2  (:,:,:)
-      avt(:,:,:)    = zwtr1 * avtr1   (:,:,:) + zwtr2 * avtr2   (:,:,:)
-#if defined key_ldfslp
-      uslp(:,:,:)   = zwtr1 * uslpr1  (:,:,:) + zwtr2 * uslpr2  (:,:,:)
-      vslp(:,:,:)   = zwtr1 * vslpr1  (:,:,:) + zwtr2 * vslpr2  (:,:,:)
-      wslpi(:,:,:)  = zwtr1 * wslpir1 (:,:,:) + zwtr2 * wslpir2 (:,:,:)
-      wslpj(:,:,:)  = zwtr1 * wslpjr1 (:,:,:) + zwtr2 * wslpjr2 (:,:,:)
-#endif
-#if defined key_zdfddm
-      avs(:,:,:)    = zwtr1 * avsr1   (:,:,:) + zwtr2 * avsr2   (:,:,:)
-#endif
-      ta(:,:,:)     = zwtr1 * tar1    (:,:,:) + zwtr2 * tar2    (:,:,:)
-      sa(:,:,:)     = zwtr1 * sar1    (:,:,:) + zwtr2 * sar2    (:,:,:)
-      tb(:,:,:)     = zwtr1 * tbr1    (:,:,:) + zwtr2 * tbr2    (:,:,:)
-      sb(:,:,:)     = zwtr1 * sbr1    (:,:,:) + zwtr2 * sbr2    (:,:,:)
-#if defined key_tradmp
-      hmlp(:,:)     = zwtr1 * hmlp1(:,:)    + zwtr2 * hmlp2(:,:)
-#endif
-#if defined key_traldf_eiv  
-#if defined key_traldf_c3d
-      aeiu(:,:,:)   = zwtr1 * aeiur1  (:,:,:) + zwtr2 * aeiur2  (:,:,:)
-      aeiv(:,:,:)   = zwtr1 * aeivr1  (:,:,:) + zwtr2 * aeivr2  (:,:.:)
-      aeiw(:,:,:)   = zwtr1 * aeiwr1  (:,:,:) + zwtr2 * aeiwr2  (:,:.:)
-#elif defined key_traldf_c2d
-      aeiu(:,:)     = zwtr1 * aeiur1  (:,:)   + zwtr2 * aeiur2  (:,:)
-      aeiv(:,:)     = zwtr1 * aeivr1  (:,:)   + zwtr2 * aeivr2  (:,:)
-      aeiw(:,:)     = zwtr1 * aeiwr1  (:,:)   + zwtr2 * aeiwr2  (:,:)
-#elif defined key_traldf_c1d
-      aeiu(:)       = zwtr1 * aeiur1  (:)     + zwtr2 * aeiur2  (:)
-      aeiv(:)       = zwtr1 * aeivr1  (:)     + zwtr2 * aeivr2  (:)
-      aeiw(:)       = zwtr1 * aeiwr1  (:)     + zwtr2 * aeiwr2  (:)
-#else
-      aeiu          = zwtr1 * aeiur1          + zwtr2 * aeiur2     
-      aeiv          = zwtr1 * aeivr1          + zwtr2 * aeivr2     
-      aeiw          = zwtr1 * aeiwr1          + zwtr2 * aeiwr2     
-#endif
-#endif
-
-      CALL div_cur(kstp)
-      CALL wzv(kstp)
-
-   END SUBROUTINE trj_rea
-
-
-   SUBROUTINE trj_wri_spl(filename)
-      !!-----------------------------------------------------------------------
-      !!
-      !!                  ***  ROUTINE trj_wri_spl ***
-      !!
-      !! ** Purpose : Write SimPLe data to file the model state trajectory
-      !!
-      !! ** Method  : 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!        ! 09-07 (F. Vigilant) 
-      !!-----------------------------------------------------------------------
-      !! *Module udes
-      USE iom  
-      !! * Arguments
-      !! * Local declarations
-      INTEGER :: &
-         & inum, &                  ! File unit number
-         & fd                       ! field number
-      CHARACTER (LEN=50) :: &
-         & filename      
-
-      fd=1
-      WRITE(filename, FMT='(A,A)' ) TRIM( filename ), '.nc'
-      filename = TRIM( filename )
-      CALL iom_open( filename, inum, ldwrt = .TRUE., kiolib = jprstlib)
-
-      ! Output trajectory fields
-      CALL iom_rstput( fd, fd, inum, 'un'   , un   )
-      CALL iom_rstput( fd, fd, inum, 'vn'   , vn   )
-      CALL iom_rstput( fd, fd, inum, 'tn'   , tn   )
-      CALL iom_rstput( fd, fd, inum, 'sn'   , sn   )
-      CALL iom_rstput( fd, fd, inum, 'sshn' , sshn )
-      CALL iom_rstput( fd, fd, inum, 'wn'   , wn   )
-      CALL iom_rstput( fd, fd, inum, 'tb'   , tb   )
-      CALL iom_rstput( fd, fd, inum, 'sb'   , sb   )
-      CALL iom_rstput( fd, fd, inum, 'ua'   , ua   )
-      CALL iom_rstput( fd, fd, inum, 'va'   , va   )
-      CALL iom_rstput( fd, fd, inum, 'ta'   , ta   )
-      CALL iom_rstput( fd, fd, inum, 'sa'   , sa   )
-      CALL iom_rstput( fd, fd, inum, 'sshb' , sshb )
-      CALL iom_rstput( fd, fd, inum, 'rhd'  , rhd  )
-      CALL iom_rstput( fd, fd, inum, 'rhop' , rhop )
-      CALL iom_rstput( fd, fd, inum, 'gtu'  , gtu  )
-      CALL iom_rstput( fd, fd, inum, 'gsu'  , gsu  )
-      CALL iom_rstput( fd, fd, inum, 'gru'  , gru  )
-      CALL iom_rstput( fd, fd, inum, 'gtv'  , gtv  )
-      CALL iom_rstput( fd, fd, inum, 'gsv'  , gsv  )
-      CALL iom_rstput( fd, fd, inum, 'grv'  , grv  )
-      CALL iom_rstput( fd, fd, inum, 'rn2'  , rn2  )
-
-      CALL iom_close( inum )
-
-   END SUBROUTINE trj_wri_spl
-
-   SUBROUTINE trj_rd_spl(filename)
-      !!-----------------------------------------------------------------------
-      !!
-      !!                  ***  ROUTINE asm_trj__wop_rd ***
-      !!
-      !! ** Purpose : Read SimPLe data from file the model state trajectory
-      !!
-      !! ** Method  : 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!        ! 09-07 (F. Vigilant) 
-      !!-----------------------------------------------------------------------
-      !! *Module udes
-      USE iom                 ! I/O module
-      !! * Arguments
-      !! * Local declarations
-      INTEGER :: &
-         & inum, &                  ! File unit number
-         & fd                       ! field number
-      CHARACTER (LEN=50) :: &
-         & filename
-       
-      fd=1
-      WRITE(filename, FMT='(A,A)' ) TRIM( filename ), '.nc'
-      filename = TRIM( filename )
-      CALL iom_open( filename, inum)
-
-      ! Output trajectory fields
-      CALL iom_get( inum, jpdom_autoglo, 'un'   , un,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'vn'   , vn,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'tn'   , tn,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'sn'   , sn,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'sshn' , sshn, fd )
-      CALL iom_get( inum, jpdom_autoglo, 'wn'   , wn,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'tb'   , tb,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'sb'   , sb,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'ua'   , ua,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'va'   , va,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'ta'   , ta,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'sa'   , sa,   fd )
-      CALL iom_get( inum, jpdom_autoglo, 'sshb' , sshb, fd )
-      CALL iom_get( inum, jpdom_autoglo, 'rhd'  , rhd,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'rhop' , rhop, fd )
-      CALL iom_get( inum, jpdom_autoglo, 'gtu'  , gtu,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'gsu'  , gsu,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'gru'  , gru,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'gtv'  , gtv,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'gsv'  , gsv,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'grv'  , grv,  fd )
-      CALL iom_get( inum, jpdom_autoglo, 'rn2'  , rn2,  fd )
-
-      CALL iom_close( inum )
-
-   END SUBROUTINE trj_rd_spl
-
-#endif
-END MODULE trj_tam
